From 6f499f72380cf4fd90ebadb20a9eda07a7d61d22 Mon Sep 17 00:00:00 2001 From: "Factory: remote-delegations" <138933559+factory-droid[bot]@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:51:38 +0000 Subject: [PATCH 1/2] fix: tell spec-mode examples a trailing newline is fine The spec-mode examples asked for a file "containing \"hello\"". Droid often read that as exact bytes with no trailing newline, which the file tools cannot write. It then asked the user (AskUser) or checked the bytes with a shell command. The examples cancel both, which ends the turn as interrupted and fails the nightly Examples run. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- examples/node/enter-spec-mode.ts | 7 ++++++- examples/node/spec-mode-new-session.ts | 6 +++++- examples/node/spec-mode-same-session.ts | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/node/enter-spec-mode.ts b/examples/node/enter-spec-mode.ts index ad1c269..ae05349 100644 --- a/examples/node/enter-spec-mode.ts +++ b/examples/node/enter-spec-mode.ts @@ -99,8 +99,13 @@ try { await session.enterSpecMode(); // The handler cancels shell commands, so the prompt asks for a file tool. + // File tools end the file with a newline. Without the second sentence, + // Droid may read the text as exact bytes, then ask the user or check the + // bytes with a shell command. Both get cancelled, which ends the turn. for await (const message of session.stream( - `Create ${outputPath} containing "hello". Write it with a file editing tool, not a shell command.` + `Create ${outputPath} with one line of text: hello. ` + + 'A trailing newline is fine. ' + + 'Write it with a file editing tool, not a shell command.' )) { if (message.type === DroidMessageType.Result && !message.success) { throw new Error( diff --git a/examples/node/spec-mode-new-session.ts b/examples/node/spec-mode-new-session.ts index ccfb2e1..79627ce 100644 --- a/examples/node/spec-mode-new-session.ts +++ b/examples/node/spec-mode-new-session.ts @@ -114,8 +114,12 @@ try { try { // The handler cancels shell commands, so the prompt asks for a file tool. + // File tools end the file with a newline. Without the second sentence, + // Droid may read the text as exact bytes, then ask the user or check the + // bytes with a shell command. Both get cancelled, which ends the turn. for await (const message of session.stream( - `Plan then create ${outputPath} containing "Hello from Droid". ` + + `Plan then create ${outputPath} with one line of text: Hello from Droid. ` + + 'A trailing newline is fine. ' + 'Write it with a file editing tool, not a shell command.' )) { if (message.type === DroidMessageType.Result && !message.success) { diff --git a/examples/node/spec-mode-same-session.ts b/examples/node/spec-mode-same-session.ts index 580d7fb..c38c458 100644 --- a/examples/node/spec-mode-same-session.ts +++ b/examples/node/spec-mode-same-session.ts @@ -114,8 +114,12 @@ try { try { // The handler cancels shell commands, so the prompt asks for a file tool. + // File tools end the file with a newline. Without the second sentence, + // Droid may read the text as exact bytes, then ask the user or check the + // bytes with a shell command. Both get cancelled, which ends the turn. for await (const message of session.stream( - `Plan then create ${outputPath} containing "Hello from Droid". ` + + `Plan then create ${outputPath} with one line of text: Hello from Droid. ` + + 'A trailing newline is fine. ' + 'Write it with a file editing tool, not a shell command.' )) { if (message.type === DroidMessageType.Result && !message.success) { From eb0ce02abe2b3e67d9c2444b54edd9cf5b50cd56 Mon Sep 17 00:00:00 2001 From: "Factory: remote-delegations" <138933559+factory-droid[bot]@users.noreply.github.com> Date: Sat, 28 Nov 2026 20:23:25 +0000 Subject: [PATCH 2/2] fix: give the spec-mode examples a realistic task Ask for a short Markdown note instead of a file "containing" an exact string. The exact-string wording made Droid try to strip the newline that file tools add, through shell commands or AskUser, which the examples cancel, ending the turn. Drop the earlier trailing-newline prompt text. The enter-spec-mode check now looks for hello in the printed note. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- examples/node/enter-spec-mode.ts | 10 +++------- examples/node/spec-mode-new-session.ts | 8 ++------ examples/node/spec-mode-same-session.ts | 8 ++------ scripts/run-examples.mjs | 16 +++++++++++----- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/examples/node/enter-spec-mode.ts b/examples/node/enter-spec-mode.ts index ae05349..b145273 100644 --- a/examples/node/enter-spec-mode.ts +++ b/examples/node/enter-spec-mode.ts @@ -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 { @@ -99,12 +99,8 @@ try { await session.enterSpecMode(); // The handler cancels shell commands, so the prompt asks for a file tool. - // File tools end the file with a newline. Without the second sentence, - // Droid may read the text as exact bytes, then ask the user or check the - // bytes with a shell command. Both get cancelled, which ends the turn. for await (const message of session.stream( - `Create ${outputPath} with one line of text: hello. ` + - 'A trailing newline is fine. ' + + `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) { @@ -117,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 }); } diff --git a/examples/node/spec-mode-new-session.ts b/examples/node/spec-mode-new-session.ts index 79627ce..82da7c3 100644 --- a/examples/node/spec-mode-new-session.ts +++ b/examples/node/spec-mode-new-session.ts @@ -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 { @@ -114,12 +114,8 @@ try { try { // The handler cancels shell commands, so the prompt asks for a file tool. - // File tools end the file with a newline. Without the second sentence, - // Droid may read the text as exact bytes, then ask the user or check the - // bytes with a shell command. Both get cancelled, which ends the turn. for await (const message of session.stream( - `Plan then create ${outputPath} with one line of text: Hello from Droid. ` + - 'A trailing newline is fine. ' + + `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) { diff --git a/examples/node/spec-mode-same-session.ts b/examples/node/spec-mode-same-session.ts index c38c458..01040e9 100644 --- a/examples/node/spec-mode-same-session.ts +++ b/examples/node/spec-mode-same-session.ts @@ -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 { @@ -114,12 +114,8 @@ try { try { // The handler cancels shell commands, so the prompt asks for a file tool. - // File tools end the file with a newline. Without the second sentence, - // Droid may read the text as exact bytes, then ask the user or check the - // bytes with a shell command. Both get cancelled, which ends the turn. for await (const message of session.stream( - `Plan then create ${outputPath} with one line of text: Hello from Droid. ` + - 'A trailing newline is fine. ' + + `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) { diff --git a/scripts/run-examples.mjs b/scripts/run-examples.mjs index 4c9227d..e760579 100644 --- a/scripts/run-examples.mjs +++ b/scripts/run-examples.mjs @@ -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)'