Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Close ways around the read-only command grant (PRD-8028) (#4971)
Abrahama46f21cabb8b
diff --git a/.changeset/prd-8028-git-listing-options.md b/.changeset/prd-8028-git-listing-options.mdnew file mode 100644index 000000000..df49b063f--- /dev/null+++ b/.changeset/prd-8028-git-listing-options.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Under the read-only command grant in agent chats, commands that only looked read-only now prompt, including `git branch` and `git tag` with anything but listing options, git formats that run a signature check, `printf`, abbreviated refused options, and arguments hidden behind a redirection.diff --git a/docs/content/features/editor.mdx b/docs/content/features/editor.mdxindex 74720e8d8..d48f899ea 100644--- a/docs/content/features/editor.mdx+++ b/docs/content/features/editor.mdx@@ -285,7 +285,7 @@ Turn it off in **Settings → Terminal → “Let agents use OpenKnowledge withoIn-app agent chats in the Agents panel follow the same rule and the same setting: OpenKnowledge tools other than those five run without a prompt, the five still ask, and turning the setting off makes every OpenKnowledge tool ask again.-Shell commands in an in-app chat still prompt one at a time. When the command an agent asks to run is read-only (listing, reading, and searching files, `git status`, `log`, `diff` and other read-only git subcommands, and plain `curl` GET probes), the prompt adds **Allow read-only commands while this chat is open**. Choosing it approves that command and every later read-only command in the same chat without a prompt; anything the classifier cannot prove read-only, including redirections, pipes into other programs, command substitution, or an expansion in the arguments, keeps prompting. The grant shows as **Read-only allowed** on the agent settings trigger, lasts while the chat stays open (a restarted server prompts again), and **Ask again before read-only commands** in that menu revokes it.+Shell commands in an in-app chat still prompt one at a time. When the command an agent asks to run is read-only (listing, reading, and searching files, `git status`, `log`, `diff` and other read-only git subcommands, and plain `curl` GET probes), the prompt adds **Allow read-only commands while this chat is open**. Choosing it approves that command and every later read-only command in the same chat without a prompt. A pipeline or compound command counts as read-only only when every stage does, and output can go only to `/dev/null` or into another stream (`2>&1`). Globs and variables are fine in the arguments of commands that cannot change anything, such as `cat`, `ls`, `grep` and `echo`, but `git`, `curl`, `find`, `sort` and the other commands whose options the classifier checks prompt when handed one. Command substitution, and anything else the classifier cannot prove read-only, keeps prompting. The grant shows as **Read-only allowed** on the agent settings trigger, lasts while the chat stays open (a restarted server prompts again), and **Ask again before read-only commands** in that menu revokes it.## Tabs and split panesdiff --git a/packages/server/src/acp/read-only-shell.test.ts b/packages/server/src/acp/read-only-shell.test.tsindex 04eb52c8e..7b912ef26 100644--- a/packages/server/src/acp/read-only-shell.test.ts+++ b/packages/server/src/acp/read-only-shell.test.ts@@ -34,8 +34,11 @@ describe('isReadOnlyShellCommand', () => {'git --no-pager diff HEAD~1 -- README.md','git branch --show-current','git branch -r',+ 'git branch -avv --no-color',+ "git branch --sort=-committerdate --format='%(refname:short)'",'git tag --list','git tag -l',+ 'git tag -n3 --sort=version:refname','git remote -v','git stash list','git config --get remote.origin.url',@@ -48,7 +51,7 @@ describe('isReadOnlyShellCommand', () => {'echo $HOME; pwd',`echo "${DOLLAR_BRACE}HOME}/.ok" | wc -c`,'which node || command -v node',- "printf '%s\\n' \"$PATH\" | tr ':' '\\n'",+ "echo \"$PATH\" | tr ':' '\\n'",'du -sh .ok 2>/dev/null','test -f .ok/local/server.lock && echo locked','/bin/ls -la',@@ -78,8 +81,15 @@ describe('isReadOnlyShellCommand', () => {'git branch -D feature','git branch new-branch','git branch --set-upstream-to=origin/main',+ 'git branch --set-upstream-t=origin/main',+ 'git branch --unset-up',+ 'git branch -uorigin/main',+ 'git branch -vuorigin/main','git branch --track=inherit',+ 'git branch --rem','git tag --force=v1',+ 'git tag -a v1',+ 'git tag -d v1','git tag v1.0.0','git remote add origin x','git stash pop',@@ -194,6 +204,200 @@ describe('isReadOnlyShellCommand', () => {);});+ test("an input redirection's target is never read as one of the program's arguments", () => {+ expectReadOnly(+ [+ 'git <-C branch log -D feature',+ 'git < -C branch status --set-upstream-to=origin/main',+ "git <'-C' branch log -D feature",+ 'git 0<-C branch log -D feature',+ 'curl <-A -o/tmp/x https://example.com/x',+ 'cat <$FILE',+ 'cat <*.md',+ 'cat <>notes.md',+ 'cat <',+ 'cat < ; ls',+ "git branch '2'>/dev/null",+ "git branch ''7<README.md",+ 'git branch "3"<notes.md',+ 'git branch \\2>/dev/null',+ "uniq README.md '2'>/dev/null",+ 'git branch 12>/dev/null',+ 'git tag 10>/dev/null',+ 'git branch 34<notes.md',+ 'uniq notes.md 56>/dev/null',+ 'git -C 12>/dev/null log branch -D feature',+ 'ls >&1x',+ 'ls 2>&12',+ "ls >/dev/null'x'",+ 'echo x &>/dev/null touch pwned',+ 'ls &>/dev/null',+ 'echo payload >>&1',+ 'ls 2>>&1',+ 'ls >|&1',+ ],+ false,+ );+ expectReadOnly(+ [+ 'cat <notes.md',+ 'wc -l < "notes.md"',+ 'wc -l 0<notes.md',+ "wc -l <'notes.md' 2>/dev/null",+ 'sort < names.txt | uniq -c',+ 'ls 2>/dev/null|head',+ 'ls 2>&1;pwd',+ 'ls 2>/dev/null&&pwd',+ 'ls >/dev/null 2>&1',+ 'ls 2>&-',+ ],+ true,+ );+ });++ test('an abbreviated spelling of an option git refuses in full is refused too', () => {+ expectReadOnly(+ [+ 'git grep --op needle',+ 'git grep --open-files=sh needle',+ 'git grep --open-files-in-p=sh needle',+ 'git cat-file --textc HEAD:README.md',+ 'git cat-file --filters HEAD:README.md',+ 'git grep --textc needle',+ ],+ false,+ );+ expectReadOnly(+ [+ 'git grep -n pattern',+ 'git grep -e a --or -e b',+ 'git grep --text needle',+ 'git cat-file -p HEAD:README.md',+ ],+ true,+ );+ });++ test('printf always prompts, and sort or date may not use an abbreviated refused option', () => {+ expectReadOnly(+ [+ 'printf -v PATH %s bin; git status',+ 'printf -vX %s y',+ 'printf $FMT x',+ 'printf %n PATH; git status',+ 'printf "ab%n" V',+ 'printf %5n X',+ "printf '%1$n' X",+ 'printf "%hn" X',+ 'printf "%jn" X',+ 'printf "%ln" X',+ 'printf "%Ln" X',+ 'printf "%qn" X',+ 'printf "%tn" X',+ 'printf "%zn" X',+ 'printf "%%%n" X',+ "printf '%\\156' PATH; git status",+ "printf '%\\x6e' X",+ "printf '\\x25n' X",+ "printf '%\\u006e' X",+ 'printf "%s\\n" hello',+ 'printf "%s" "$HOME"',+ "printf '%%n is a literal'",+ "printf 'tab\\there\\n'",+ 'printf',+ 'sort --o=README.md README.md',+ 'sort --outp=out.txt names.txt',+ 'sort -S1 --co=./x big.txt',+ 'sort --c=./x big.txt',+ 'sort --t=/tmp names.txt',+ 'date --s="2026-01-01"',+ 'date --se "2026-01-01"',+ ],+ false,+ );+ expectReadOnly(['sort --check names.txt', 'sort -rn counts.txt', 'date --utc'], true);+ });++ test('inside double quotes a backslash escapes only $, a backtick, a double quote, a backslash or a newline', () => {+ expectReadOnly(+ [+ 'git branch "-\\v"',+ 'git tag "-\\l" "v*"',+ 'git grep "--open-files-in-pa\\\nger=./evil" pattern',+ 'git grep --open-files-in-pa\\\nger=./evil pattern',+ ],+ false,+ );+ expectReadOnly(+ [+ 'git branch "-v"',+ 'echo "cost: \\$5"',+ 'echo "say \\"hi\\""',+ 'echo "a\\\\b"',+ 'echo "one\\\ntwo"',+ ],+ true,+ );+ });++ test('a command word that names a built-in object member is not a policy', () => {+ expectReadOnly(+ [+ 'git toString x',+ 'git constructor --x',+ 'git __proto__ a',+ 'constructor x',+ 'toString',+ 'hasOwnProperty x',+ ],+ false,+ );+ });++ test('a git format or sort that runs the signature check is not read-only', () => {+ expectReadOnly(+ [+ "git branch --format='%(signature)'",+ "git branch --format='%(refname:short) %(*signature:grade)'",+ 'git branch --sort=signature:key',+ 'git tag -l --sort=-signature',+ "git tag -l --sort='*signature'",+ 'git log --format=%GG',+ "git log --pretty='format:%h %G?'",+ 'git show --format=%GS HEAD',+ "git for-each-ref --format '%(signature)'",+ "git for-each-ref --form='%(signature)'",+ "git for-each-ref --fo '%(signature)'",+ 'git for-each-ref --so=signature',+ "git for-each-ref --f='%(signature:grade)'",+ 'git shortlog -s --group=format:%GG',+ 'git shortlog --group format:%G?',+ 'git shortlog --gr=format:%GS',+ 'git log --format=%+GG',+ "git log '--format=% GS'",+ 'git log --format=%-GK',+ 'git log --format=%Gx',+ 'git log --format=%G',+ 'git log --format=%GF',+ 'git log --format=%GP',+ 'git log --format=%GT',+ 'git log --show-signature',+ ],+ false,+ );+ expectReadOnly(+ [+ "git log --format='%h %s'",+ "git log --date=format:'%G-%V' -1",+ "git for-each-ref --format='%(refname)'",+ "git for-each-ref --sort=-committerdate --format='%(refname:short)'",+ 'git shortlog -sn --group=author',+ 'ls 2>/dev/null',+ ],+ true,+ );+ });+test('curl admits GET probes only, and never a file-reading or body-sending option', () => {expectReadOnly([diff --git a/packages/server/src/acp/read-only-shell.ts b/packages/server/src/acp/read-only-shell.tsindex 96a25ed83..a2153fccd 100644--- a/packages/server/src/acp/read-only-shell.ts+++ b/packages/server/src/acp/read-only-shell.ts@@ -40,7 +40,6 @@ const READ_ONLY_WITH_ANY_ARGUMENTS: ReadonlySet<string> = new Set(['nl','od','pgrep',- 'printf','ps','pwd','readlink',@@ -88,6 +87,8 @@ const FD_DIGITS = /^[0-9]+$/;const DEV_NULL = '/dev/null';+const DOUBLE_QUOTE_ESCAPABLE: ReadonlySet<string> = new Set(['$', '`', '"', '\\', '\n']);+const WORD_TERMINATORS: ReadonlySet<string> = new Set([' ','\t',@@ -104,6 +105,17 @@ const WORD_TERMINATORS: ReadonlySet<string> = new Set(["'",]);+const REDIRECT_TARGET_ENDS: ReadonlySet<string> = new Set([+ ' ',+ '\t',+ '\n',+ ';',+ '|',+ '&',+ '<',+ '>',+]);+const FIND_MUTATORS: ReadonlySet<string> = new Set(['-delete','-exec',@@ -142,46 +154,78 @@ const GIT_READ_SUBCOMMANDS: ReadonlySet<string> = new Set([const GIT_REJECTED_ARGUMENTS: ReadonlySet<string> = new Set(['--ext-diff',- '--open-files-in-pager','--output',- '--show-signature','--textconv',]);-const GIT_REJECTED_PREFIXES = ['--output=', '--open-files-in-pager='];+const GIT_ABBREVIABLE_REJECTS: ReadonlyMap<+ string,+ readonly (readonly [option: string, shortest: string])[]+> = new Map([+ [+ 'cat-file',+ [+ ['--filters', '--f'],+ ['--textconv', '--t'],+ ],+ ],+ [+ 'grep',+ [+ ['--open-files-in-pager', '--o'],+ ['--textconv', '--textc'],+ ],+ ],+]);-const GIT_BRANCH_MUTATORS: ReadonlySet<string> = new Set([- '-c',- '-C',- '-d',- '-D',- '-f',- '-m',- '-M',- '-u',- '--copy',- '--delete',- '--edit-description',- '--force',- '--move',- '--set-upstream-to',- '--track',- '--no-track',- '--unset-upstream',+const GIT_FORMAT_OPTIONS = ['--format', '--group', '--pretty', '--sort'];++const SIGNATURE_CHECK_FORMAT = /signature|%[-+ ]?G/;++const GIT_REJECTED_PREFIXES = ['--output='];++const GIT_BRANCH_LISTING_OPTIONS: ReadonlySet<string> = new Set([+ '--abbrev',+ '--all',+ '--color',+ '--column',+ '--contains',+ '--format',+ '--ignore-case',+ '--list',+ '--merged',+ '--no-abbrev',+ '--no-color',+ '--no-column',+ '--no-contains',+ '--no-merged',+ '--points-at',+ '--remotes',+ '--show-current',+ '--sort',+ '--verbose',]);-const GIT_TAG_MUTATORS: ReadonlySet<string> = new Set([- '-a',- '-d',- '-f',- '-F',- '-m',- '-s',- '-u',- '--delete',- '--force',+const GIT_BRANCH_LISTING_LETTERS = 'arvli';++const GIT_TAG_LISTING_OPTIONS: ReadonlySet<string> = new Set([+ '--color',+ '--column',+ '--contains',+ '--format',+ '--ignore-case',+ '--list',+ '--merged',+ '--no-color',+ '--no-column',+ '--no-contains',+ '--no-merged',+ '--points-at',+ '--sort',]);+const GIT_TAG_LISTING_LETTERS = 'lni0123456789';+const HOSTNAME_FLAGS: ReadonlySet<string> = new Set(['-A','-d',@@ -283,8 +327,11 @@ function splitStatements(command: string): Word[][] | null {let words: Word[] = [];let text = '';let literal = true;+ let plain = true;let inWord = false;let quote: '"' | "'" | null = null;+ let redirectTarget = false;+ let invalidRedirect = false;const append = (part: string, isLiteral: boolean): void => {text += part;inWord = true;@@ -292,23 +339,32 @@ function splitStatements(command: string): Word[][] | null {};const endWord = (): void => {if (!inWord) return;- words.push({ text, literal });+ if (redirectTarget) {+ redirectTarget = false;+ if (!literal) invalidRedirect = true;+ } else {+ words.push({ text, literal });+ }text = '';literal = true;+ plain = true;inWord = false;};const endStatement = (): void => {endWord();+ if (redirectTarget) invalidRedirect = true;if (words.length > 0) statements.push(words);words = [];};- const dropFdPrefix = (): void => {- if (inWord && literal && FD_DIGITS.test(text)) {+ const dropFdPrefix = (): boolean => {+ if (inWord && literal && plain && FD_DIGITS.test(text)) {+ if (text.length > 1) return false;text = '';inWord = false;- } else {- endWord();+ return true;}+ endWord();+ return true;};let i = 0;while (i < chars.length) {@@ -333,8 +389,8 @@ function splitStatements(command: string): Word[][] | null {i = after;continue;}- if (c === '\\' && next !== undefined) {- append(next, true);+ if (c === '\\' && next !== undefined && DOUBLE_QUOTE_ESCAPABLE.has(next)) {+ if (next !== '\n') append(next, true);i += 2;continue;}@@ -345,12 +401,16 @@ function splitStatements(command: string): Word[][] | null {if (c === "'" || c === '"') {quote = c;inWord = true;+ plain = false;i += 1;continue;}if (c === '\\') {if (next === undefined) return null;- if (next !== '\n') append(next, true);+ if (next !== '\n') {+ append(next, true);+ plain = false;+ }i += 2;continue;}@@ -386,33 +446,27 @@ function splitStatements(command: string): Word[][] | null {i += 2;continue;}- if (next === '>') {- endWord();- const after = readDevNullTarget(chars, i + 2);- if (after === null) return null;- i = after;- continue;- }return null;}if (c === '>') {- dropFdPrefix();- let j = i + 1;- if (chars[j] === '>' || chars[j] === '|') j += 1;- if (chars[j] === '&') {- const after = readFdDuplicate(chars, j + 1);+ if (!dropFdPrefix() || redirectTarget) return null;+ if (next === '&') {+ const after = readFdDuplicate(chars, i + 2);if (after === null) return null;i = after;continue;}+ let j = i + 1;+ if (chars[j] === '>' || chars[j] === '|') j += 1;const after = readDevNullTarget(chars, j);if (after === null) return null;i = after;continue;}if (c === '<') {- if (next === '<' || next === '(' || next === '&') return null;- dropFdPrefix();+ if (next === '<' || next === '(' || next === '&' || next === '>') return null;+ if (!dropFdPrefix() || redirectTarget) return null;+ redirectTarget = true;i += 1;continue;}@@ -426,7 +480,7 @@ function splitStatements(command: string): Word[][] | null {}if (quote !== null) return null;endStatement();- return statements;+ return invalidRedirect ? null : statements;}function readParameter(@@ -469,11 +523,15 @@ function readParameter(return start + 1;}+function endsRedirectTarget(chars: readonly string[], index: number): boolean {+ const next = chars[index];+ return next === undefined || REDIRECT_TARGET_ENDS.has(next);+}+function readFdDuplicate(chars: readonly string[], start: number): number | null {- if (chars[start] === '-') return start + 1;- let i = start;- while (i < chars.length && FD_DIGITS.test(chars[i] ?? '')) i += 1;- return i === start ? null : i;+ const target = chars[start] ?? '';+ if (target !== '-' && !FD_DIGITS.test(target)) return null;+ return endsRedirectTarget(chars, start + 1) ? start + 1 : null;}function readDevNullTarget(chars: readonly string[], start: number): number | null {@@ -484,7 +542,7 @@ function readDevNullTarget(chars: readonly string[], start: number): number | nutarget += chars[i];i += 1;}- return target === DEV_NULL ? i : null;+ return target === DEV_NULL && endsRedirectTarget(chars, i) ? i : null;}function isReadOnlySimpleCommand(statement: readonly Word[]): boolean {@@ -501,7 +559,7 @@ function isReadOnlySimpleCommand(statement: readonly Word[]): boolean {const program = programName(head.text);if (program === null) return false;if (READ_ONLY_WITH_ANY_ARGUMENTS.has(program)) return true;- const policy = RESTRICTED_PROGRAMS[program];+ const policy = RESTRICTED_PROGRAMS.get(program);if (policy === undefined) return false;const args = words.slice(1);if (!args.every((word) => word.literal)) return false;@@ -529,24 +587,58 @@ function optionName(arg: string): string {return arg.split('=', 1)[0] ?? arg;}-const RESTRICTED_PROGRAMS: Readonly<Record<string, ArgumentPolicy>> = {- command: (args) => (args[0] === '-v' || args[0] === '-V') && args.length > 1,- curl: isReadOnlyCurl,- date: (args) => !args.some((arg) => arg.startsWith('--set') || shortClusterHas(arg, 's')),- find: (args) => !args.some((arg) => FIND_MUTATORS.has(arg)),- git: isReadOnlyGit,- hostname: (args) => args.every((arg) => HOSTNAME_FLAGS.has(arg)),- sort: (args) =>- !args.some(- (arg) =>- arg.startsWith('--output') ||- arg.startsWith('--temporary-directory') ||- arg.startsWith('--compress-program') ||- shortClusterHas(arg, 'oT'),- ),- tree: (args) => !args.some((arg) => shortClusterHas(arg, 'o')),- uniq: (args) => args.filter(isOperand).length <= 1,-};+function abbreviates(arg: string, option: string, shortest: string): boolean {+ if (!arg.startsWith('--')) return false;+ const name = optionName(arg);+ return name.startsWith(shortest) && option.startsWith(name);+}++function requestsSignatureCheck(args: readonly string[]): boolean {+ return args.some((arg, index) => {+ if (arg === '--show-signature') return true;+ if (!GIT_FORMAT_OPTIONS.some((option) => abbreviates(arg, option, option.slice(0, 3)))) {+ return false;+ }+ const name = optionName(arg);+ const value = name === arg ? (args[index + 1] ?? '') : arg.slice(name.length + 1);+ return SIGNATURE_CHECK_FORMAT.test(value);+ });+}++function isListingOption(+ arg: string,+ longOptions: ReadonlySet<string>,+ shortLetters: string,+): boolean {+ if (arg.startsWith('--')) return longOptions.has(optionName(arg));+ if (!arg.startsWith('-') || arg.length < 2) return false;+ return Array.from(arg.slice(1)).every((letter) => shortLetters.includes(letter));+}++const RESTRICTED_PROGRAMS: ReadonlyMap<string, ArgumentPolicy> = new Map<string, ArgumentPolicy>([+ ['command', (args) => (args[0] === '-v' || args[0] === '-V') && args.length > 1],+ ['curl', isReadOnlyCurl],+ [+ 'date',+ (args) => !args.some((arg) => abbreviates(arg, '--set', '--s') || shortClusterHas(arg, 's')),+ ],+ ['find', (args) => !args.some((arg) => FIND_MUTATORS.has(arg))],+ ['git', isReadOnlyGit],+ ['hostname', (args) => args.every((arg) => HOSTNAME_FLAGS.has(arg))],+ [+ 'sort',+ (args) =>+ !args.some(+ (arg) =>+ abbreviates(arg, '--output', '--o') ||+ abbreviates(arg, '--temporary-directory', '--t') ||+ abbreviates(arg, '--compress-program', '--c') ||+ shortClusterHas(arg, 'oT'),+ ),+ ],+ ['tree', (args) => !args.some((arg) => shortClusterHas(arg, 'o'))],+ ['uniq', (args) => args.filter(isOperand).length <= 1],+]);function isReadOnlyGit(args: readonly string[]): boolean {let i = 0;@@ -565,11 +657,14 @@ function isReadOnlyGit(args: readonly string[]): boolean {const subcommand = args[i];if (subcommand === undefined) return false;const rest = args.slice(i + 1);+ const abbreviableRejects = GIT_ABBREVIABLE_REJECTS.get(subcommand) ?? [];if (+ requestsSignatureCheck(rest) ||rest.some((arg) =>GIT_REJECTED_ARGUMENTS.has(arg) ||GIT_REJECTED_PREFIXES.some((prefix) => arg.startsWith(prefix)) ||+ abbreviableRejects.some(([option, shortest]) => abbreviates(arg, option, shortest)) ||shortClusterHas(arg, 'O'),)) {@@ -578,9 +673,13 @@ function isReadOnlyGit(args: readonly string[]): boolean {if (GIT_READ_SUBCOMMANDS.has(subcommand)) return true;switch (subcommand) {case 'branch':- return rest.every((arg) => arg.startsWith('-') && !GIT_BRANCH_MUTATORS.has(optionName(arg)));+ return rest.every((arg) =>+ isListingOption(arg, GIT_BRANCH_LISTING_OPTIONS, GIT_BRANCH_LISTING_LETTERS),+ );case 'tag':- return rest.every((arg) => arg.startsWith('-') && !GIT_TAG_MUTATORS.has(optionName(arg)));+ return rest.every((arg) =>+ isListingOption(arg, GIT_TAG_LISTING_OPTIONS, GIT_TAG_LISTING_LETTERS),+ );case 'remote':return (rest.every((arg) => arg === '-v' || arg === '--verbose') ||diff --git a/packages/server/src/acp/thread-manager.integration.test.ts b/packages/server/src/acp/thread-manager.integration.test.tsindex 74b28c901..1afb06f14 100644--- a/packages/server/src/acp/thread-manager.integration.test.ts+++ b/packages/server/src/acp/thread-manager.integration.test.ts@@ -7075,6 +7075,12 @@ function logCount(warn: ReturnType<typeof vi.spyOn>, message: string): number {return warn.mock.calls.filter((call) => call[1] === message).length;}+function hasLaunchFailureEntry(logPath: string, threadId: string): boolean {+ if (!existsSync(logPath)) return false;+ const text = readFileSync(logPath, 'utf8');+ return text.includes(`thread=${threadId}`) && text.endsWith('\n\n');+}+async function withNpxLaunchFixture(mode: NpxEnoentMode,run: (fixture: {@@ -7177,7 +7183,11 @@ describe('launch failure diagnostics and npx cache recovery', () => {const statuses = await statusesOf(manager, info.threadId);expect(statuses.filter((status) => status === 'error')).toHaveLength(1);const logPath = join(localDir, ACP_LAUNCH_FAILURE_LOG);- await waitUntil(() => existsSync(logPath), 5_000, 'launch failure log');+ await waitUntil(+ () => hasLaunchFailureEntry(logPath, info.threadId),+ 5_000,+ 'launch failure log entry',+ );const logText = readFileSync(logPath, 'utf8');expect(logText.match(/=== acp launch failure /g)).toHaveLength(1);expect(logText).toContain(@@ -7279,7 +7289,11 @@ describe('launch failure diagnostics and npx cache recovery', () => {expect(existsSync(entryDir)).toBe(true);expect(logCount(warn, NPX_RELAUNCH_LOG)).toBe(0);const logPath = join(localDir, ACP_LAUNCH_FAILURE_LOG);- await waitUntil(() => existsSync(logPath), 5_000, 'launch failure log');+ await waitUntil(+ () => hasLaunchFailureEntry(logPath, info.threadId),+ 5_000,+ 'launch failure log entry',+ );const logText = readFileSync(logPath, 'utf8');expect(logText).toContain(`thread=${info.threadId} agent=npx-cache source=custom reason=connect ===`,@@ -7303,7 +7317,11 @@ describe('launch failure diagnostics and npx cache recovery', () => {'session setup failure',);const logPath = join(localDir, ACP_LAUNCH_FAILURE_LOG);- await waitUntil(() => existsSync(logPath), 5_000, 'launch failure log');+ await waitUntil(+ () => hasLaunchFailureEntry(logPath, info.threadId),+ 5_000,+ 'launch failure log entry',+ );const logText = readFileSync(logPath, 'utf8');expect(logText).toContain(`thread=${info.threadId} agent=broken-agent source=custom reason=session-setup ===\nsession setup failed: Failed to initialize session services`,