Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/node/enter-spec-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
const tempDir = await realpath(
await mkdtemp(join(tmpdir(), 'droid-sdk-enter-spec-'))
);
const outputPath = join(tempDir, 'hello.txt');
const outputPath = join(tempDir, 'hello.md');

/** True when a tool call only writes the file that the prompt asks for. */
function writesOnlyOutputFile(details: ToolConfirmationDetails): boolean {
Expand Down Expand Up @@ -100,7 +100,8 @@ try {

// The handler cancels shell commands, so the prompt asks for a file tool.
for await (const message of session.stream(
`Create ${outputPath} containing "hello". Write it with a file editing tool, not a shell command.`
`Create ${outputPath}, a short Markdown note that says hello. ` +
'Write it with a file editing tool, not a shell command.'
)) {
if (message.type === DroidMessageType.Result && !message.success) {
throw new Error(
Expand All @@ -112,7 +113,7 @@ try {
await session.close();
}

console.log(await readFile(outputPath, 'utf8'));
console.log(`\nhello.md:\n${await readFile(outputPath, 'utf8')}`);
} finally {
await rm(tempDir, { recursive: true, force: true });
}
4 changes: 2 additions & 2 deletions examples/node/spec-mode-new-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
const tempDir = await realpath(
await mkdtemp(join(tmpdir(), 'droid-sdk-spec-'))
);
const outputPath = join(tempDir, 'hello.txt');
const outputPath = join(tempDir, 'hello.md');

/** True when a tool call only writes the file that the prompt asks for. */
function writesOnlyOutputFile(details: ToolConfirmationDetails): boolean {
Expand Down Expand Up @@ -115,7 +115,7 @@ try {
try {
// The handler cancels shell commands, so the prompt asks for a file tool.
for await (const message of session.stream(
`Plan then create ${outputPath} containing "Hello from Droid". ` +
`Plan then create ${outputPath}, a short Markdown note titled "Hello from Droid". ` +
'Write it with a file editing tool, not a shell command.'
)) {
if (message.type === DroidMessageType.Result && !message.success) {
Expand Down
4 changes: 2 additions & 2 deletions examples/node/spec-mode-same-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
const tempDir = await realpath(
await mkdtemp(join(tmpdir(), 'droid-sdk-spec-'))
);
const outputPath = join(tempDir, 'hello.txt');
const outputPath = join(tempDir, 'hello.md');

/** True when a tool call only writes the file that the prompt asks for. */
function writesOnlyOutputFile(details: ToolConfirmationDetails): boolean {
Expand Down Expand Up @@ -115,7 +115,7 @@ try {
try {
// The handler cancels shell commands, so the prompt asks for a file tool.
for await (const message of session.stream(
`Plan then create ${outputPath} containing "Hello from Droid". ` +
`Plan then create ${outputPath}, a short Markdown note titled "Hello from Droid". ` +
'Write it with a file editing tool, not a shell command.'
)) {
if (message.type === DroidMessageType.Result && !message.success) {
Expand Down
16 changes: 11 additions & 5 deletions scripts/run-examples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,17 @@ export const EXAMPLES = {
timeoutSec: 420,
checks: [
exitZero(),
custom('file contains hello', (ctx) => ({
ok: /^\s*"?hello"?\s*$/im.test(
ctx.stdout.trim().split('\n').pop() ?? ''
),
})),
// The proposed plan is printed first and may mention hello too, so check
// only the note printed after the last marker.
custom('the note says hello', (ctx) => {
const marker = '\nhello.md:\n';
const index = ctx.stdout.lastIndexOf(marker);
return {
ok:
index !== -1 &&
containsAnyWord(ctx.stdout.slice(index + marker.length), ['hello']),
};
}),
sessionFilesContain(
'ExitSpecMode',
'Droid proposed a spec (ExitSpecMode)'
Expand Down
Loading