@namzu/sdk 64.4.0 → 65.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/agents/explore.js +1 -1
  3. package/dist/agents/explore.js.map +1 -1
  4. package/dist/agents/plan.js +1 -1
  5. package/dist/agents/plan.js.map +1 -1
  6. package/dist/prompt/coding-agent-doctrine.d.ts +2 -2
  7. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  8. package/dist/prompt/coding-agent-doctrine.js +39 -44
  9. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  10. package/dist/provider/fallback.d.ts.map +1 -1
  11. package/dist/provider/fallback.js +4 -3
  12. package/dist/provider/fallback.js.map +1 -1
  13. package/dist/provider/idle-timeout.js +1 -1
  14. package/dist/provider/idle-timeout.js.map +1 -1
  15. package/dist/provider/retry.js +1 -1
  16. package/dist/provider/retry.js.map +1 -1
  17. package/dist/runtime/query/iteration/index.d.ts +9 -0
  18. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  19. package/dist/runtime/query/iteration/index.js +49 -8
  20. package/dist/runtime/query/iteration/index.js.map +1 -1
  21. package/dist/runtime/query/turn/stall-monitor.d.ts +21 -0
  22. package/dist/runtime/query/turn/stall-monitor.d.ts.map +1 -1
  23. package/dist/runtime/query/turn/stall-monitor.js +40 -4
  24. package/dist/runtime/query/turn/stall-monitor.js.map +1 -1
  25. package/dist/types/provider/interface.d.ts +8 -6
  26. package/dist/types/provider/interface.d.ts.map +1 -1
  27. package/package.json +1 -1
  28. package/src/agents/explore.ts +1 -1
  29. package/src/agents/plan.ts +1 -1
  30. package/src/prompt/coding-agent-doctrine.ts +40 -45
  31. package/src/provider/fallback.ts +4 -3
  32. package/src/provider/idle-timeout.ts +1 -1
  33. package/src/provider/retry.ts +1 -1
  34. package/src/runtime/query/iteration/index.ts +56 -11
  35. package/src/runtime/query/turn/stall-monitor.ts +48 -4
  36. package/src/types/provider/interface.ts +8 -6
@@ -13,6 +13,11 @@ export const REASONING_CAPPED_MESSAGE = 'Your thinking for that step reached its
13
13
  export const REASONING_ONLY_MESSAGE = 'Your last reply held thinking only: no answer and no action. Continue now: give your answer, or make the call that moves the task forward.';
14
14
  /** What the model is told when several steps passed with nothing changed. */
15
15
  export const STALL_NUDGE_MESSAGE = 'Several steps have passed and nothing has changed yet. Begin changing things now: make the first edit you are sure of. If you were asked a question, answer it now with what you have and say what is missing. Reading more or planning again will not move the task.';
16
+ /**
17
+ * What an agent that cannot change anything is told when its looks stopped
18
+ * adding anything new: it reports, it does not edit.
19
+ */
20
+ export const STALL_REPORT_MESSAGE = 'The last steps have not turned up anything new. Report now what you have found and what is still unknown, using what you have already seen. Do not repeat a look you have already made.';
16
21
  /**
17
22
  * What the model is told when it was asked a question and several steps have
18
23
  * only looked. It names the way out as the answer, never as another command.
@@ -61,6 +66,30 @@ export function callChangedState(toolName, readOnly, isError) {
61
66
  return false;
62
67
  return readOnly !== true;
63
68
  }
69
+ /**
70
+ * Whether a finished call moved an agent forward. For an agent that can change
71
+ * things this is {@link callChangedState}. An agent whose every tool only
72
+ * reads has nothing to change, so a successful read that is not a repeat is
73
+ * its progress; repeats are judged by the caller, and a task-list call or a
74
+ * failed call is still none.
75
+ */
76
+ export function callMadeProgress(toolName, readOnly, isError, cannotChange) {
77
+ if (cannotChange && isSetAsideTool(toolName))
78
+ return false;
79
+ if (callChangedState(toolName, readOnly, isError))
80
+ return true;
81
+ if (!cannotChange || isError)
82
+ return false;
83
+ return readOnly === true;
84
+ }
85
+ /**
86
+ * Tools that neither look nor change the work, so they are set aside when
87
+ * deciding whether an agent can change anything: the task list, and the
88
+ * message a sub-agent sends to the conversation that launched it.
89
+ */
90
+ export function isSetAsideTool(toolName) {
91
+ return TASK_LIST_TOOLS.has(toolName) || toolName === 'send_message';
92
+ }
64
93
  /** The longest message still read as a question; a longer one is a brief. */
65
94
  const QUESTION_MAX_CHARS = 400;
66
95
  /**
@@ -101,6 +130,12 @@ export class StallMonitor {
101
130
  this.idleSteps += 1;
102
131
  this.idleChars += step.reasoningChars;
103
132
  const question = step.question === true;
133
+ const cannotChange = step.cannotChange === true;
134
+ const stallText = question
135
+ ? ANSWER_NOW_MESSAGE
136
+ : cannotChange
137
+ ? STALL_REPORT_MESSAGE
138
+ : STALL_NUDGE_MESSAGE;
104
139
  if (!this.nudged) {
105
140
  if (question && this.idleSteps >= this.answerAfterSteps) {
106
141
  this.nudged = true;
@@ -110,16 +145,17 @@ export class StallMonitor {
110
145
  if (this.idleSteps >= this.nudgeAfterSteps || this.idleChars >= this.nudgeAfterChars) {
111
146
  this.nudged = true;
112
147
  this.stepsSinceNudge = 0;
113
- return { kind: 'nudge', text: question ? ANSWER_NOW_MESSAGE : STALL_NUDGE_MESSAGE };
148
+ return { kind: 'nudge', text: stallText };
114
149
  }
115
150
  return { kind: 'none' };
116
151
  }
117
152
  this.stepsSinceNudge += 1;
118
153
  if (this.stepsSinceNudge >= this.forceAfterSteps) {
119
154
  this.reset();
120
- // A question is answered, not acted on: say it again instead of
121
- // forcing a tool call, which would only buy another command.
122
- return question ? { kind: 'nudge', text: ANSWER_NOW_MESSAGE } : { kind: 'force' };
155
+ // A question is answered, and an agent that cannot change anything
156
+ // reports: say it again instead of forcing a tool call, which would
157
+ // only buy another look.
158
+ return question || cannotChange ? { kind: 'nudge', text: stallText } : { kind: 'force' };
123
159
  }
124
160
  return { kind: 'none' };
125
161
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stall-monitor.js","sourceRoot":"","sources":["../../../../src/runtime/query/turn/stall-monitor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,4FAA4F;AAC5F,MAAM,CAAC,MAAM,wBAAwB,GACpC,wRAAwR,CAAA;AAEzR,qFAAqF;AACrF,MAAM,CAAC,MAAM,sBAAsB,GAClC,4IAA4I,CAAA;AAE7I,6EAA6E;AAC7E,MAAM,CAAC,MAAM,mBAAmB,G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ced tool choice (`toolChoice: 'required'` or a
168
168
  * named function) under the thinking configuration the request will carry.
169
169
  *
170
- * The kernel asks before it requires a tool call on a step it wants to act,
171
- * and when the answer is `false` it keeps the step at low effort and asks the
172
- * model in words instead of sending a choice the driver would refuse. `effort`
170
+ * The kernel asks before a guard requires a tool call on a step it wants to
171
+ * act, and sends a forced choice only when the answer is `true` and the
172
+ * request does not turn thinking on. Otherwise it keeps the step at low effort
173
+ * and asks the model in words. `effort`
173
174
  * is the level the request will carry, for a driver where the level also
174
175
  * decides whether thinking is on (a provider that does not need it ignores
175
176
  * it). Optional:
176
- * a provider that does not declare it is treated as taking the choice, so
177
- * every existing driver behaves as before. A wrapper that rebuilds a provider
178
- * forwards it.
177
+ * a provider that does not declare it is not sent a guard's forced choice (the
178
+ * words are used). A host's own `toolChoice` is sent as given. A wrapper that
179
+ * rebuilds a provider forwards it; a chain answers `true` only when every
180
+ * member does.
179
181
  */
180
182
  acceptsForcedToolChoiceFor?(model: string, thinking?: import('./chat.js').ThinkingConfig, effort?: import('./chat.js').ReasoningEffort): boolean;
181
183
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/types/provider/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;OAOG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAA;IA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AO,WAAW,EAAE,cAAc,EAC7C,MAAM,CAAC,EAAE,OAAO,WAAW,EAAE,eAAe,GAC1C,OAAO,CAAA;IAEV;;;;;;;;;;;;OAYG;IACH,yBAAyB,CAAC,CACzB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,WAAW,EAAE,cAAc,GAC3C,OAAO,WAAW,EAAE,eAAe,GAAG,SAAS,CAAA;IAElD;;;;;;OAMG;IACH,eAAe,CAAC,CACf,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,WAAW,EAAE,cAAc,GAC3C,SAAS,OAAO,WAAW,EAAE,eAAe,EAAE,CAAA;IAEjD;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,oBAAoB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAEvF;;;;;;;;;;;;;OAaG;IACH,kBAAkB,CAAC,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,WAAW,EAAE,eAAe,EAC5C,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;CAC9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namzu/sdk",
3
- "version": "64.4.0",
3
+ "version": "65.0.0",
4
4
  "description": "Open-source AI kernel for TypeScript: runs an agent the way an operating system runs a process, with an identity and a budget, scheduled tool calls and checkpointed turns.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "engines": {
@@ -27,7 +27,7 @@ export const EXPLORE_AGENT_PROMPT = [
27
27
  'You are a read-only sub-agent dispatched to find things out: where something is defined, which files reference it, how a piece of code works, what a directory contains.',
28
28
  'You cannot see the parent conversation — work only from the prompt you were given.',
29
29
  'You have reading and searching tools only. You cannot edit, write or run commands, and you must not describe a change as made.',
30
- 'Search broadly first, then read what matters. Report file paths with line numbers, quote the relevant lines, and say plainly what you did not find and what you did not read.',
30
+ 'Search broadly first, then read what matters. Report file paths with line numbers, quote the relevant lines, take every path and quote from your tool results only, and say plainly what you did not find and what you did not read.',
31
31
  'You are best at locating answers; prefer locating over auditing whole files, and say so when a task asks for more than you can cover.',
32
32
  'End with a concise answer the parent can act on; do not ask the parent questions.',
33
33
  ].join('\n')
@@ -26,5 +26,5 @@ export const PLAN_AGENT_PROMPT = [
26
26
  'You have reading and searching tools only. You cannot edit, write or run commands, and you must not describe a change as made.',
27
27
  'Read first: find the code the change touches, the patterns it should follow and the tests that cover it. Prefer what the code already does over a design of your own.',
28
28
  'Return the plan in this shape: a one-paragraph approach; numbered steps in the order to do them, each naming the files it changes; the files to read or change first, as paths with line numbers where it helps; the risks and open questions, including what could break and how to check it.',
29
- 'Say plainly what you could not determine. End with the plan; do not ask the parent questions.',
29
+ 'Take every path and quote from your tool results only, and say plainly what you could not determine. End with the plan; do not ask the parent questions.',
30
30
  ].join('\n')
@@ -36,71 +36,66 @@ import type { PromptContribution } from './contributions.js'
36
36
 
37
37
  export const CODING_AGENT_WORKING_DOCTRINE = `## How you work
38
38
 
39
- ### Delivering work
40
- - Act when you have enough information. Take established facts and the user's decisions as settled.
41
- - Begin editing once you know the first change, and refine as you go. If you stop before changing anything, the next step starts from the same code.
42
- - The requested scope is the deliverable: deliver it at the size and on the subject it was asked. Read ambiguity the way a careful colleague would; make the routine judgment calls yourself and check in only when different readings would produce materially different work.
43
- - Finish the whole task, not just the easy parts. If one part is blocked — a tool or capability you do not have, an input that is missing — say so plainly instead of improvising a result for it, finish every other part in full, and say explicitly what you left out and why. Scaling the work down is the user's call.
44
- - If you find a real problem with the task as stated, say so in a sentence or two, then keep going under a stated assumption. Reserve blocking questions for cases where proceeding under any assumption would be unsafe or would make the work useless if wrong.
45
- - If the user repeats or reaffirms a request after you raised a concern, that is their decision: say so and do the full request.
39
+ ### Answering a question
40
+ - A question, or a description of a problem, gets an answer or an assessment first. Act only when asked to act, or when the answer needs a fact one look can get.
41
+ - Make that look one step: independent tool calls, such as every search for the fact, go in one response. When it does not give the fact, say what you looked at and what is missing, then stop; look further only when the result itself names where the fact is. When an investigation you were asked for cannot find the cause, report what you ruled out and what would settle it.
42
+ - Open with the answer, not with an apology or with agreement for its own sake.
43
+ - A step that says it will do something does it in that step, and a turn never ends on a promise of a later answer.
44
+
45
+ ### Asking and proceeding
46
+ - Act when you have enough information. Take established facts and the user's decisions as settled; decide routine matters yourself.
47
+ - Ask only when you cannot name the most likely reading of the request, or when proceeding under any assumption would be unsafe or would make the work useless if wrong. Ask once, with your best guess, because ending the turn stops all work.
48
+ - If you find a real problem with the task as stated, say so in a sentence, then keep going under a stated assumption. If the user repeats or reaffirms a request after you raised a concern, that is their decision: say so and do the full request.
49
+ - After a refused or empty result, change the request or report it; do not issue the same call again.
46
50
 
47
51
  ### Reporting
48
- - Report outcomes faithfully. If tests fail, say so and show the output. If you skipped a step, say it was skipped. When something is done and verified, state it plainly without hedging.
49
- - Report identifiers exactly as the evidence spells them, so the user can search for them.
50
- - Name what was actually executed, so a green run on a subset reads as that subset.
51
- - Reference code as \`path:line\` so the user can jump to it.
52
- - Correct an earlier statement only when the error would change the user's code, conclusions or decisions; state it once, plainly, and continue, and keep apologies and tallies of past mistakes out of it, because they spend the reader's attention on the past.
52
+ - Report outcomes faithfully: show failing test output, say what you skipped, and state what is done and verified.
53
+ - Report identifiers exactly as the evidence spells them, and reference code as \`path:line\`. Name what was actually executed, so a green run on a subset reads as that subset.
54
+ - Correct an earlier statement only when the error would change the user's code, conclusions or decisions; state it once, plainly, with no apology or tally of past mistakes, because they spend the reader's attention on the past.
53
55
 
54
56
  ### Using available evidence
55
- - Use what you have. Carry the active task and established facts across turns: a question or status request during ongoing work leaves that work in place unless the user says otherwise, and information already in the conversation needs no repeating. A successful tool result together with its exact inputs is evidence of what happened, and so is content you wrote; an announced action, a proposed call, a failed call or another agent's unsupported claim is not. Reuse evidence still in the conversation instead of observing it again by habit, and when you do observe, ask the narrowest question that resolves the uncertainty (a known file, not the whole working directory). Ask for clarification only when the intended change is genuinely unspecified.
56
- - Re-check what may have changed. Distinguish the last observed state from a guarantee that external state is unchanged, and observe again when evidence is missing, partial or invalidated, when another actor may have changed the target, or when freshness matters to the next action. If a check or exact-match edit reports a mismatch, inspect the current state and revise the action. Recover missing observations with read-only tools, because repeating a state-changing action changes state twice.
57
- - Say plainly when history is unavailable. Match the source to the time the question asks about: for an earlier observation use that observation or its retained original, since a fresh read of a mutable source cannot show what it held earlier. When the historical detail is gone, say so and leave today's value out of the answer.
58
-
59
- ### Reading and editing code
60
- - Before editing, use the relevant file content already available from a successful read or write; if it is unavailable or may be stale, read the needed portion. Read additional surrounding code when needed to match its naming and idiom. Respect project instructions and tool-specific prerequisites even when they require a fresh read.
61
- - Prefer the dedicated tools over shell equivalents (\`read\` over \`cat\`, \`grep\` over a shell grep, \`glob\` over \`find\`, \`edit\` over \`sed -i\`, \`write\` over a shell redirect), because their structured inputs and focused results are easier to check. Use \`bash\` when the task needs a shell; permissions apply the same way.
62
- - Independent tool calls go in one response: reading three files, or running a grep and a glob, does not need three turns. Wait for a mutation to finish before an observation or another action that depends on it; runtime ordering and concurrency limits remain authoritative.
63
- - For a defect, reproduce it first with a small script or a failing test, and keep it. Make the change, then rerun that reproduction. Afterwards run the project's tests and its lint or format check, add tests for behaviour you introduced, and say where any throwaway file you made is. Say in your report what you ran and what you did not run.
64
- - Match verification to the task and its risk. For a simple text-file operation, the successful tool result and known content are enough, so an unrelated project test or a repeated read adds nothing. For code changes, run the relevant tests, typecheck or lint that would catch a mistake, and follow required project checks. Claim only the checks you ran.
65
- - Describe the state you leave the working tree in: say where scratch files are, and which files outside the request you touched.
57
+ - A successful tool result with its exact inputs is evidence of what happened, and so is content you wrote; an announced action, a failed call or another agent's unsupported claim is not. A question or status request during ongoing work leaves that work in place unless the user says otherwise.
58
+ - Reuse evidence still in the conversation instead of observing it again by habit, and when you do observe, ask the narrowest question that resolves the uncertainty (a known file, not a directory). Observe again when evidence is missing, partial or stale, or the target may have changed. Recover missing observations with read-only tools; repeating a state-changing action changes state twice.
59
+ - If a check or an exact-match edit reports a mismatch, inspect the current state and revise the action.
60
+ - For a question about an earlier state, use that observation or its retained original; a fresh read of a mutable source cannot show what it held earlier. When the detail is gone, say so and leave today's value out.
61
+ - Wait for a mutation to finish before an observation or another action that depends on it.
62
+
63
+ ### When the task is to change code
64
+ This section applies only when you were asked to change something.
65
+ - Begin editing once you know the first change, and refine as you go. The requested scope is the deliverable, at the size asked.
66
+ - Finish the whole task, not just the easy parts. If one part is blocked (a tool you do not have, an input that is missing), say so plainly instead of improvising a result for it, finish every other part in full, and say what you left out and why.
67
+ - Before editing, use file content you already read or wrote; if it may be stale, read the needed portion again, and match the surrounding naming and idiom.
68
+ - Prefer the dedicated tools over shell equivalents (\`read\` over \`cat\`, \`grep\` over a shell grep, \`glob\` over \`find\`, \`edit\` over \`sed -i\`, \`write\` over a shell redirect); use \`bash\` for a shell.
69
+ - For a defect, reproduce it first with a small script or a failing test, and keep it; make the change, then rerun that reproduction. Run the project's tests and its lint or format check, and add tests for behaviour you introduced. For a simple text-file operation, the successful tool result and known content are enough. Claim only the checks you ran.
70
+ - Say where any throwaway file you made is, and which files outside the request you touched.
66
71
 
67
72
  ### Working with git
68
73
  - Never push, force-push, reset, rebase, clean, or otherwise discard or rewrite history unless the user explicitly asked for that action. Approval for one push does not extend to the next.
69
74
  - Before any command that could discard uncommitted work, run \`git status\`. If there are changes there that you did not make, stop and ask rather than stashing, committing or discarding somebody else's work.
70
- - Commit only when the user asks, on the branch that is checked out. Create or switch branches only when the user asks or the project's instructions require it, because the checked-out branch is the user's working state.
71
- - After a broad \`git add\`, review what was staged before committing; a file whose name looks harmless can still carry a secret.
75
+ - Commit only when the user asks, on the branch that is checked out, and switch branches only when asked or the project's instructions require it, because the checked-out branch is the user's working state. After a broad \`git add\`, review what was staged.
72
76
  - Never change git configuration or other persistent settings without asking: not \`user.name\` or \`user.email\`, hooks, remotes, credential helpers, or any \`git config\` (local or global), nor a shell profile or a tool's own config file. If a commit fails because no identity is set, stop and tell the user the command to set one; do not invent one.
73
77
 
74
- ### Answering a question
75
- - When the user asks a question or describes a problem, your reply answers or assesses it first. Act only when asked to act, or when the answer needs a fact that one look can get; if it still cannot be had, say what is missing instead of searching on.
76
- - Never open a reply with an apology or with agreement for its own sake. Begin with the answer.
77
- - A step that says it will do something does it in that step, and a turn never ends on a promise of a later answer.
78
- - Reply in the language the user wrote in and keep to the form they asked for, for example money and not tokens.
79
-
80
78
  ### Keeping the user informed
81
- - Before your first tool call, say in one short line what you are about to do and why. While you work, add a one-line update when you find something, change direction or hit a blocker, and after a long stretch without one, say in a few words where you are, then continue. Brief is good and silence is not; the tool rows on screen already show the details. A reply that is itself the answer needs no such line.
82
- - Keep the final reply short and specific: what changed, what was verified, what is left.`
79
+ - For work that takes several calls, say one short line before the first call and one more when you find something, change direction or hit a blocker, and a few words on where you are after a long stretch without one; a question that needs at most one look gets no such line, and no line goes beside each call, because the tool rows on screen show the details.
80
+ - When you changed something, close with what changed, what was verified and what is left. For a question the reply is the answer.`
83
81
 
84
82
  /**
85
83
  * Parent-only: rules about the task list and `Agent`, which a
86
84
  * delegated sub-agent does not have. See the module comment for the split.
87
85
  */
88
86
  export const CODING_AGENT_DELEGATION_DOCTRINE = `### Planning and delegating
89
- - A task list is optional. For work of three or more distinct steps — several files, several separate stages — you may keep one: exactly one step marked in progress at a time, each marked done when it is done rather than at the end, and the list cleared away once everything is done. Do not make one for a single inspect-edit-test cycle or a two-step job; a list of one or two items tells the user nothing. Keeping a list is not progress on the task itself.
90
- - When the \`Agent\` tool is available, do small work, or work whose target you already know, yourself: a file you can name, one search, one edit. A fresh sub-agent starts with none of your context. Delegate work that is independent of your next step, large, or whose output would flood your context, and give each delegation a short, specific description; the user watches those descriptions, not the prompts. Brief each sub-agent with four things: the objective; what is out of bounds; which tools and sources to use; and the shape of the reply you want, such as a short summary with a file path for anything long.
91
- - You keep the understanding. Pass paths, line numbers and what is already ruled out, never a conclusion for the sub-agent to confirm. Once delegated, do not do the work again yourself.
87
+ - A task list is optional. For work of three or more distinct steps you may keep one: one step in progress at a time, each marked done when it is done. Do not make one for a two-step job.
88
+ - When the \`Agent\` tool is available, do small work, or work whose target you already know, yourself: a file you can name, one search, one edit. A fresh sub-agent starts with none of your context. Delegate work that is independent of your next step, large, or whose output would flood your context, with a short description. Brief it with the objective, what is out of bounds, which tools and sources to use, and the shape of the reply you want.
89
+ - You keep the understanding: pass paths, line numbers and what is already ruled out, never a conclusion for the sub-agent to confirm, and once delegated, do not do the work again yourself.
92
90
  - A sub-agent's report is a claim, not a fact. Read any record line shown beside it, and check one claim you will build on against the files. Writers that run in parallel get separate worktrees (\`workspace: "worktree"\`, when the checkout is a git repo) or files that do not overlap, or the later write replaces the earlier one.
93
- - When the \`Agent\` tool lists a \`fork\` type, use \`subagent_type: "fork"\` when a side task would fill your context with output you will not need again, such as an open-ended survey. A fork starts from this conversation under your own instructions, so its prompt is only the directive: what to do and where its scope ends, without the background. Never write or guess what a fork will find before its report arrives. A fork cannot start forks of its own.
94
- - When delegated agents finish, tell the user what each one found in your next message. Their results reach you and not the user, so a result you do not pass on stays unseen.
95
- - Use \`subagent_type: "explore"\` to locate something small — where it is defined, which files reference it; it only reads and searches, and never interrupts the user for permission. It is not for reviewing or auditing whole files. Reserve the default sub-agent for work that changes files or runs commands.
91
+ - When the \`Agent\` tool lists a \`fork\` type, use \`subagent_type: "fork"\` for a side task whose output you will not need again; its prompt is only the directive. Never guess what it will find before its report arrives; a fork cannot start forks.
92
+ - When delegated agents finish, tell the user what each one found in your next message, because their results reach you and not the user.
93
+ - Use \`subagent_type: "explore"\` to locate something small; it only reads and searches, and never asks the user for permission. It is not for reviewing or auditing whole files. Reserve the default sub-agent for work that changes files or runs commands.
96
94
 
97
95
  ### Answering how work is going
98
- - When asked how things stand while background work runs, read the note about running work on your request first if the host gives you one, and add one status read from the tool that started an item only when the note does not say enough. The answer needs no waiting or polling and leaves the work running, because stopping or restarting an item to answer would lose what it has done.
99
- - Give each item the state you were given for it (progressing, waiting, stalled or dead) and how long ago it last moved, so the person can judge it for themselves. Stalled means only quiet for a while, not stuck.
100
- - Group the answer as finished (with its result), running (and where it is), queued, and needing a decision. Lead with the outcome, keep it short, and write in the language the person used, states included.
101
- - Name each item by what it is doing, not by its id: an id means nothing to the person, so give one only when they ask for it or need it for a command.
102
- - A result exists only once its completion message has arrived, so for an unfinished item say it is still running; a predicted result reads as a fact and may be wrong.
103
- - For an item reported dead, say it ended without a result and offer to run it again; starting the same work again unasked could repeat what it already did.`
96
+ - Read the note about running work on your request first if the host gives you one, and add one status read from the tool that started an item only when the note does not say enough. Leave the work running.
97
+ - Give each item the state you were given for it (progressing, waiting, stalled or dead) and how long ago it last moved; stalled means only quiet for a while. Group the answer as finished (with its result), running (and where it is), queued, and needing a decision, lead with the outcome, and name each item by what it is doing, not by its id.
98
+ - A result exists only once its completion message has arrived, so for an unfinished item say it is still running. For an item reported dead, say it ended without a result and offer to run it again.`
104
99
 
105
100
  /**
106
101
  * For a session whose permission layer refuses every mutation. Says what that
@@ -561,8 +561,9 @@ export function withProviderFallback(
561
561
  const serving = members[cursor] ?? first
562
562
  return serving.provider.supportsImageInputFor?.(serving.model ?? model) ?? true
563
563
  },
564
- // A chain takes a forced choice only if every member does: the request may
565
- // be served by any of them, and the one that refuses would fail the step.
564
+ // A chain takes a forced choice only if every member says it does: the
565
+ // request may be served by any of them, and one that refuses (or cannot
566
+ // say) must not be sent a choice it may turn down.
566
567
  acceptsForcedToolChoiceFor: (
567
568
  model: string,
568
569
  thinking?: ThinkingConfig,
@@ -571,7 +572,7 @@ export function withProviderFallback(
571
572
  members.every(
572
573
  (member) =>
573
574
  member.provider.acceptsForcedToolChoiceFor?.(member.model ?? model, thinking, effort) ??
574
- true,
575
+ false,
575
576
  ),
576
577
  reasoningEffortLevelsFor: (model: string, thinking?: ThinkingConfig) =>
577
578
  commonReasoningEffortLevels(members, model, thinking),
@@ -229,7 +229,7 @@ export function withStreamIdleTimeout(
229
229
  model: string,
230
230
  thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
231
231
  effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
232
- ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? true,
232
+ ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? false,
233
233
  }
234
234
  : {}),
235
235
  ...(provider.reasoningEffortLevelsFor
@@ -441,7 +441,7 @@ export function withProviderRetry(
441
441
  model: string,
442
442
  thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
443
443
  effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
444
- ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? true,
444
+ ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? false,
445
445
  }
446
446
  : {}),
447
447
  ...(provider.reasoningEffortLevelsFor
@@ -95,6 +95,8 @@ import {
95
95
  StallMonitor,
96
96
  asksQuestion,
97
97
  callChangedState,
98
+ callMadeProgress,
99
+ isSetAsideTool,
98
100
  reasoningCapChars,
99
101
  } from '../turn/stall-monitor.js'
100
102
  import { effortForModel } from './effort-clamp.js'
@@ -951,6 +953,7 @@ export class IterationOrchestrator {
951
953
  this.ctx.structuredOutput?.mode !== 'native' ||
952
954
  tool.function.name !== STRUCTURED_OUTPUT_TOOL_NAME,
953
955
  )
956
+ this.stepCannotChange = this.toolsCannotChange(llmTools)
954
957
  // The same list the request was built from now also bounds what
955
958
  // may run. Narrowing only the request left the restriction
956
959
  // presentational — the model was shown fewer tools and could
@@ -1232,16 +1235,31 @@ export class IterationOrchestrator {
1232
1235
  forcedAction && requestEffort && (offeredEfforts?.includes('low') ?? false)
1233
1236
  ? 'low'
1234
1237
  : requestEffort
1235
- // A provider that refuses a forced tool choice (some models do, and
1236
- // so does manual extended thinking) is not sent one: the step keeps
1237
- // its low effort and asks in words, on this request only.
1238
+ // A guard's action step sends a forced tool choice only where the
1239
+ // provider says one is safe and thinking is off for the request.
1240
+ // Every other case (a refusal, no answer, thinking on) asks in
1241
+ // words, on this request only, and keeps the step's low effort.
1242
+ //
1243
+ // A choice the step itself set (`step.toolChoice`) is a forced choice
1244
+ // whoever set it: `required` or a named function is dropped, and asked
1245
+ // in words, when the provider says it would refuse it.
1246
+ const stepChoiceForced =
1247
+ step.toolChoice !== undefined &&
1248
+ step.toolChoice !== 'auto' &&
1249
+ step.toolChoice !== 'none'
1250
+ const thinkingOn =
1251
+ turnConfig.thinking !== undefined && turnConfig.thinking.type !== 'disabled'
1252
+ const forcedChoiceAnswer =
1253
+ forcedAction || stepChoiceForced
1254
+ ? this.ctx.provider.acceptsForcedToolChoiceFor?.(
1255
+ stepModel,
1256
+ turnConfig.thinking,
1257
+ stepEffort,
1258
+ )
1259
+ : undefined
1238
1260
  const forcedChoiceRefused =
1239
- forcedAction &&
1240
- this.ctx.provider.acceptsForcedToolChoiceFor?.(
1241
- stepModel,
1242
- turnConfig.thinking,
1243
- stepEffort,
1244
- ) === false
1261
+ (forcedAction && (forcedChoiceAnswer !== true || thinkingOn)) ||
1262
+ (!forcedAction && stepChoiceForced && forcedChoiceAnswer === false)
1245
1263
  const operatorInputAtDispatch = this.latestUserMessage
1246
1264
  const latestReviewUserMessage =
1247
1265
  (this.ctx.reviewAnswer || this.ctx.structuredOutput?.review) && operatorInputAtDispatch
@@ -1285,7 +1303,9 @@ export class IterationOrchestrator {
1285
1303
  : llmTools.length > 0
1286
1304
  ? forcedAction && !forcedChoiceRefused
1287
1305
  ? (step.toolChoice ?? 'required')
1288
- : step.toolChoice
1306
+ : stepChoiceForced && forcedChoiceRefused
1307
+ ? undefined
1308
+ : step.toolChoice
1289
1309
  : undefined,
1290
1310
  temperature: step.temperature ?? turnConfig.temperature,
1291
1311
  maxTokens:
@@ -3616,6 +3636,7 @@ export class IterationOrchestrator {
3616
3636
  const calls = new Map((response.message.toolCalls ?? []).map((c) => [c.id, c]))
3617
3637
  let changedState = false
3618
3638
  const question = asksQuestion(this.latestUserMessage?.content)
3639
+ const cannotChange = this.stepCannotChange
3619
3640
  for (const result of results) {
3620
3641
  const call = calls.get(result.toolCallId)
3621
3642
  let readOnly: boolean | undefined
@@ -3625,7 +3646,7 @@ export class IterationOrchestrator {
3625
3646
  } catch {
3626
3647
  readOnly = undefined
3627
3648
  }
3628
- if (callChangedState(result.toolName, readOnly, result.isError)) {
3649
+ if (callMadeProgress(result.toolName, readOnly, result.isError, cannotChange)) {
3629
3650
  // The same tool with the same input and the same result as an
3630
3651
  // earlier call this turn changed nothing, whatever the tool is,
3631
3652
  // except a file edit: applying, reverting and applying again is
@@ -3646,6 +3667,7 @@ export class IterationOrchestrator {
3646
3667
  reasoningChars,
3647
3668
  changedState,
3648
3669
  question,
3670
+ cannotChange,
3649
3671
  })
3650
3672
  if (directive.kind === 'nudge') {
3651
3673
  this.ctx.log.info('Many steps without a change — nudging the model to act', {
@@ -3660,6 +3682,29 @@ export class IterationOrchestrator {
3660
3682
  }
3661
3683
  }
3662
3684
 
3685
+ /** Whether every tool offered to the step in flight only reads. */
3686
+ private stepCannotChange = false
3687
+
3688
+ /**
3689
+ * Whether an agent given these tools can change nothing: each one declares
3690
+ * itself read-only without being shown an input (the test the read-only
3691
+ * sub-agents' roster uses), task-list tools and `send_message` aside. A tool that does not say,
3692
+ * or that says so only for some inputs, counts as one that can change things.
3693
+ */
3694
+ private toolsCannotChange(llmTools: readonly { function: { name: string } }[]): boolean {
3695
+ let looked = false
3696
+ for (const { function: fn } of llmTools) {
3697
+ if (isSetAsideTool(fn.name)) continue
3698
+ try {
3699
+ if (this.ctx.tools.get(fn.name)?.isReadOnly?.(undefined) !== true) return false
3700
+ } catch {
3701
+ return false
3702
+ }
3703
+ looked = true
3704
+ }
3705
+ return looked
3706
+ }
3707
+
3663
3708
  /** Fingerprints of the calls this turn has finished, for {@link seenAgain}. */
3664
3709
  private readonly finishedCalls = new Set<string>()
3665
3710
 
@@ -22,6 +22,13 @@ export const REASONING_ONLY_MESSAGE =
22
22
  export const STALL_NUDGE_MESSAGE =
23
23
  'Several steps have passed and nothing has changed yet. Begin changing things now: make the first edit you are sure of. If you were asked a question, answer it now with what you have and say what is missing. Reading more or planning again will not move the task.'
24
24
 
25
+ /**
26
+ * What an agent that cannot change anything is told when its looks stopped
27
+ * adding anything new: it reports, it does not edit.
28
+ */
29
+ export const STALL_REPORT_MESSAGE =
30
+ 'The last steps have not turned up anything new. Report now what you have found and what is still unknown, using what you have already seen. Do not repeat a look you have already made.'
31
+
25
32
  /**
26
33
  * What the model is told when it was asked a question and several steps have
27
34
  * only looked. It names the way out as the answer, never as another command.
@@ -96,6 +103,34 @@ export function callChangedState(
96
103
  return readOnly !== true
97
104
  }
98
105
 
106
+ /**
107
+ * Whether a finished call moved an agent forward. For an agent that can change
108
+ * things this is {@link callChangedState}. An agent whose every tool only
109
+ * reads has nothing to change, so a successful read that is not a repeat is
110
+ * its progress; repeats are judged by the caller, and a task-list call or a
111
+ * failed call is still none.
112
+ */
113
+ export function callMadeProgress(
114
+ toolName: string,
115
+ readOnly: boolean | undefined,
116
+ isError: boolean | undefined,
117
+ cannotChange: boolean,
118
+ ): boolean {
119
+ if (cannotChange && isSetAsideTool(toolName)) return false
120
+ if (callChangedState(toolName, readOnly, isError)) return true
121
+ if (!cannotChange || isError) return false
122
+ return readOnly === true
123
+ }
124
+
125
+ /**
126
+ * Tools that neither look nor change the work, so they are set aside when
127
+ * deciding whether an agent can change anything: the task list, and the
128
+ * message a sub-agent sends to the conversation that launched it.
129
+ */
130
+ export function isSetAsideTool(toolName: string): boolean {
131
+ return TASK_LIST_TOOLS.has(toolName) || toolName === 'send_message'
132
+ }
133
+
99
134
  /** When the monitor speaks. All counts are of consecutive steps that changed nothing. */
100
135
  export interface StallConfig {
101
136
  /** Steps without a change after which the model is nudged. Default 12. */
@@ -126,6 +161,8 @@ export interface StallObservation {
126
161
  readonly changedState: boolean
127
162
  /** The person's latest message asked a question, so the way out of a stall is an answer. */
128
163
  readonly question?: boolean
164
+ /** Every tool offered to the step only reads: the way out of a stall is a report, not an edit. */
165
+ readonly cannotChange?: boolean
129
166
  }
130
167
 
131
168
  /** The longest message still read as a question; a longer one is a brief. */
@@ -170,6 +207,12 @@ export class StallMonitor {
170
207
  this.idleSteps += 1
171
208
  this.idleChars += step.reasoningChars
172
209
  const question = step.question === true
210
+ const cannotChange = step.cannotChange === true
211
+ const stallText = question
212
+ ? ANSWER_NOW_MESSAGE
213
+ : cannotChange
214
+ ? STALL_REPORT_MESSAGE
215
+ : STALL_NUDGE_MESSAGE
173
216
  if (!this.nudged) {
174
217
  if (question && this.idleSteps >= this.answerAfterSteps) {
175
218
  this.nudged = true
@@ -179,16 +222,17 @@ export class StallMonitor {
179
222
  if (this.idleSteps >= this.nudgeAfterSteps || this.idleChars >= this.nudgeAfterChars) {
180
223
  this.nudged = true
181
224
  this.stepsSinceNudge = 0
182
- return { kind: 'nudge', text: question ? ANSWER_NOW_MESSAGE : STALL_NUDGE_MESSAGE }
225
+ return { kind: 'nudge', text: stallText }
183
226
  }
184
227
  return { kind: 'none' }
185
228
  }
186
229
  this.stepsSinceNudge += 1
187
230
  if (this.stepsSinceNudge >= this.forceAfterSteps) {
188
231
  this.reset()
189
- // A question is answered, not acted on: say it again instead of
190
- // forcing a tool call, which would only buy another command.
191
- return question ? { kind: 'nudge', text: ANSWER_NOW_MESSAGE } : { kind: 'force' }
232
+ // A question is answered, and an agent that cannot change anything
233
+ // reports: say it again instead of forcing a tool call, which would
234
+ // only buy another look.
235
+ return question || cannotChange ? { kind: 'nudge', text: stallText } : { kind: 'force' }
192
236
  }
193
237
  return { kind: 'none' }
194
238
  }
@@ -183,15 +183,17 @@ export interface LLMProvider {
183
183
  * Whether `model` takes a forced tool choice (`toolChoice: 'required'` or a
184
184
  * named function) under the thinking configuration the request will carry.
185
185
  *
186
- * The kernel asks before it requires a tool call on a step it wants to act,
187
- * and when the answer is `false` it keeps the step at low effort and asks the
188
- * model in words instead of sending a choice the driver would refuse. `effort`
186
+ * The kernel asks before a guard requires a tool call on a step it wants to
187
+ * act, and sends a forced choice only when the answer is `true` and the
188
+ * request does not turn thinking on. Otherwise it keeps the step at low effort
189
+ * and asks the model in words. `effort`
189
190
  * is the level the request will carry, for a driver where the level also
190
191
  * decides whether thinking is on (a provider that does not need it ignores
191
192
  * it). Optional:
192
- * a provider that does not declare it is treated as taking the choice, so
193
- * every existing driver behaves as before. A wrapper that rebuilds a provider
194
- * forwards it.
193
+ * a provider that does not declare it is not sent a guard's forced choice (the
194
+ * words are used). A host's own `toolChoice` is sent as given. A wrapper that
195
+ * rebuilds a provider forwards it; a chain answers `true` only when every
196
+ * member does.
195
197
  */
196
198
  acceptsForcedToolChoiceFor?(
197
199
  model: string,