@namzu/cli 27.0.0 → 28.1.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 (149) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +24 -18
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +122 -12
  6. package/dist/cli.js.map +1 -1
  7. package/dist/commands/drain.js +2 -2
  8. package/dist/commands/drain.js.map +1 -1
  9. package/dist/commands/{run-flags.d.ts → exec-flags.d.ts} +29 -21
  10. package/dist/commands/exec-flags.d.ts.map +1 -0
  11. package/dist/commands/{run-flags.js → exec-flags.js} +31 -23
  12. package/dist/commands/exec-flags.js.map +1 -0
  13. package/dist/commands/{run-stream.d.ts → exec-json.d.ts} +20 -14
  14. package/dist/commands/exec-json.d.ts.map +1 -0
  15. package/dist/commands/exec-json.js +473 -0
  16. package/dist/commands/exec-json.js.map +1 -0
  17. package/dist/commands/{run.d.ts → exec.d.ts} +14 -13
  18. package/dist/commands/exec.d.ts.map +1 -0
  19. package/dist/commands/exec.js +683 -0
  20. package/dist/commands/exec.js.map +1 -0
  21. package/dist/commands/host-queries.d.ts +12 -0
  22. package/dist/commands/host-queries.d.ts.map +1 -0
  23. package/dist/commands/host-queries.js +149 -0
  24. package/dist/commands/host-queries.js.map +1 -0
  25. package/dist/commands/prior-messages.js +1 -1
  26. package/dist/commands/prior-messages.js.map +1 -1
  27. package/dist/commands/registry.d.ts.map +1 -1
  28. package/dist/commands/registry.js +2 -0
  29. package/dist/commands/registry.js.map +1 -1
  30. package/dist/commands/resident-flags.d.ts +2 -2
  31. package/dist/commands/resident-flags.d.ts.map +1 -1
  32. package/dist/commands/resident-flags.js +4 -2
  33. package/dist/commands/resident-flags.js.map +1 -1
  34. package/dist/commands/resident-learning.js +1 -1
  35. package/dist/commands/resident-learning.js.map +1 -1
  36. package/dist/commands/resident.js +1 -1
  37. package/dist/commands/resident.js.map +1 -1
  38. package/dist/commands/skills.js +1 -1
  39. package/dist/commands/skills.js.map +1 -1
  40. package/dist/commands/stdin.d.ts +5 -5
  41. package/dist/commands/stdin.js +5 -5
  42. package/dist/commands/types.d.ts +2 -0
  43. package/dist/commands/types.d.ts.map +1 -1
  44. package/dist/config/load.d.ts.map +1 -1
  45. package/dist/config/load.js +19 -0
  46. package/dist/config/load.js.map +1 -1
  47. package/dist/config/schema.d.ts +18 -4
  48. package/dist/config/schema.d.ts.map +1 -1
  49. package/dist/config/schema.js.map +1 -1
  50. package/dist/config/{run-limits.d.ts → turn-guards.d.ts} +1 -1
  51. package/dist/config/turn-guards.d.ts.map +1 -0
  52. package/dist/config/{run-limits.js → turn-guards.js} +1 -1
  53. package/dist/config/turn-guards.js.map +1 -0
  54. package/dist/context/project.d.ts +1 -1
  55. package/dist/context/project.js +1 -1
  56. package/dist/doctor/checks/chain.js +2 -2
  57. package/dist/doctor/checks/chain.js.map +1 -1
  58. package/dist/integrations/providers/access.d.ts +4 -1
  59. package/dist/integrations/providers/access.d.ts.map +1 -1
  60. package/dist/integrations/providers/access.js +6 -3
  61. package/dist/integrations/providers/access.js.map +1 -1
  62. package/dist/integrations/providers/zen-catalogue.d.ts +100 -0
  63. package/dist/integrations/providers/zen-catalogue.d.ts.map +1 -0
  64. package/dist/integrations/providers/zen-catalogue.js +196 -0
  65. package/dist/integrations/providers/zen-catalogue.js.map +1 -0
  66. package/dist/integrations/resident/runner-launch.d.ts +3 -3
  67. package/dist/integrations/resident/runner-launch.d.ts.map +1 -1
  68. package/dist/integrations/resident/runner-worker.js +22 -0
  69. package/dist/integrations/resident/runner-worker.js.map +1 -1
  70. package/dist/integrations/resident/session-step.d.ts +2 -2
  71. package/dist/integrations/resident/session-step.d.ts.map +1 -1
  72. package/dist/integrations/resident/session-step.js +1 -1
  73. package/dist/integrations/resident/session-step.js.map +1 -1
  74. package/dist/integrations/sessions/transcript-export.js +3 -1
  75. package/dist/integrations/sessions/transcript-export.js.map +1 -1
  76. package/dist/integrations/subagents/runtime.d.ts.map +1 -1
  77. package/dist/integrations/subagents/runtime.js +1 -1
  78. package/dist/integrations/subagents/runtime.js.map +1 -1
  79. package/dist/integrations/web/search.d.ts +1 -1
  80. package/dist/logging.d.ts +5 -5
  81. package/dist/logging.js +6 -6
  82. package/dist/permissions/headless-trust.d.ts +2 -2
  83. package/dist/permissions/headless-trust.js +3 -3
  84. package/dist/permissions/headless-trust.js.map +1 -1
  85. package/dist/permissions/live-mode.d.ts +73 -0
  86. package/dist/permissions/live-mode.d.ts.map +1 -0
  87. package/dist/permissions/live-mode.js +62 -0
  88. package/dist/permissions/live-mode.js.map +1 -0
  89. package/dist/termination.d.ts +1 -1
  90. package/dist/termination.js +1 -1
  91. package/dist/tui/App.d.ts.map +1 -1
  92. package/dist/tui/App.js +181 -79
  93. package/dist/tui/App.js.map +1 -1
  94. package/dist/tui/Checklist.d.ts +56 -0
  95. package/dist/tui/Checklist.d.ts.map +1 -0
  96. package/dist/tui/Checklist.js +90 -0
  97. package/dist/tui/Checklist.js.map +1 -0
  98. package/dist/tui/StatusBar.d.ts +10 -0
  99. package/dist/tui/StatusBar.d.ts.map +1 -1
  100. package/dist/tui/StatusBar.js +8 -1
  101. package/dist/tui/StatusBar.js.map +1 -1
  102. package/dist/tui/TaskList.d.ts +18 -25
  103. package/dist/tui/TaskList.d.ts.map +1 -1
  104. package/dist/tui/TaskList.js +34 -58
  105. package/dist/tui/TaskList.js.map +1 -1
  106. package/dist/tui/Transcript.d.ts.map +1 -1
  107. package/dist/tui/Transcript.js +8 -1
  108. package/dist/tui/Transcript.js.map +1 -1
  109. package/dist/tui/agent.d.ts +33 -7
  110. package/dist/tui/agent.d.ts.map +1 -1
  111. package/dist/tui/agent.js +51 -9
  112. package/dist/tui/agent.js.map +1 -1
  113. package/dist/tui/live-window.d.ts +22 -0
  114. package/dist/tui/live-window.d.ts.map +1 -1
  115. package/dist/tui/live-window.js +34 -0
  116. package/dist/tui/live-window.js.map +1 -1
  117. package/dist/tui/notices.d.ts +27 -0
  118. package/dist/tui/notices.d.ts.map +1 -0
  119. package/dist/tui/notices.js +27 -0
  120. package/dist/tui/notices.js.map +1 -0
  121. package/dist/tui/slashCommands.d.ts +1 -1
  122. package/dist/tui/slashCommands.js +5 -5
  123. package/dist/tui/slashCommands.js.map +1 -1
  124. package/dist/tui/status-panel-layout.js +1 -1
  125. package/dist/tui/status-panel-layout.js.map +1 -1
  126. package/dist/tui/task-activity.d.ts +71 -0
  127. package/dist/tui/task-activity.d.ts.map +1 -0
  128. package/dist/tui/task-activity.js +157 -0
  129. package/dist/tui/task-activity.js.map +1 -0
  130. package/dist/tui/turn-limits-settings.d.ts +1 -1
  131. package/dist/tui/turn-limits-settings.d.ts.map +1 -1
  132. package/dist/tui/turn-limits-settings.js +1 -1
  133. package/dist/tui/turn-limits-settings.js.map +1 -1
  134. package/dist/tui/types.d.ts +13 -0
  135. package/dist/tui/types.d.ts.map +1 -1
  136. package/dist/user-commands/store.d.ts +3 -3
  137. package/dist/user-commands/store.js +4 -4
  138. package/dist/user-commands/store.js.map +1 -1
  139. package/package.json +6 -6
  140. package/dist/commands/run-flags.d.ts.map +0 -1
  141. package/dist/commands/run-flags.js.map +0 -1
  142. package/dist/commands/run-stream.d.ts.map +0 -1
  143. package/dist/commands/run-stream.js +0 -647
  144. package/dist/commands/run-stream.js.map +0 -1
  145. package/dist/commands/run.d.ts.map +0 -1
  146. package/dist/commands/run.js +0 -617
  147. package/dist/commands/run.js.map +0 -1
  148. package/dist/config/run-limits.d.ts.map +0 -1
  149. package/dist/config/run-limits.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-stream.js","sourceRoot":"","sources":["../../src/commands/run-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAEH,OAAO,EAGN,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV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OAAO,CAAC,CAAA;IACT,CAAC;CACD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAmCH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrE;AAoCD,eAAO,MAAM,UAAU,EAAE,UAuiBxB,CAAA"}
@@ -1,617 +0,0 @@
1
- /**
2
- * `namzu run "<prompt>"` — headless one-shot. Runs a single prompt through
3
- * the same agent the TUI uses and prints the reply to stdout, for scripts
4
- * and CI. The prompt comes from
5
- * the arguments, or from stdin when piped. Status lines go to stderr (info,
6
- * suppressed by `--quiet`); only the answer hits stdout.
7
- *
8
- * Non-interactive, so there's no approval prompt — tools auto-run, but the
9
- * safety gate still hard-denies catastrophic commands. A one-shot is a
10
- * conversation like any other: its session log is kept under the project in
11
- * `NAMZU_HOME`, so `--continue` picks it up and `namzu drain` can finish a
12
- * turn it parked.
13
- *
14
- * Options are parsed, not spoken: this command joined every argument into the
15
- * prompt, so the flags its streaming sibling accepts — `--cwd` above all —
16
- * were read aloud to the model while the turn used this directory anyway. Both
17
- * commands now share one parser (`./run-flags.js`), because they are the same
18
- * one-shot differing only in how they print.
19
- */
20
- import { relative } from 'node:path';
21
- import { BOOT_EVENT_NAMES, EVENT_NAME_ATTRIBUTE, TurnCancelled, asSessionId } from '@namzu/sdk';
22
- import { resolveTrustedProjectContext } from '../config/trusted-project-context.js';
23
- import { EXIT_UNTRUSTED, EXIT_USAGE } from '../exit-codes.js';
24
- import { closeSessions, openSessions, startConversation } from '../integrations/sessions/store.js';
25
- import { attachSessionExport, } from '../integrations/telemetry/session-export.js';
26
- import { cliLogger, contextLogging, createStderrSink, installCliLogging } from '../logging.js';
27
- import { decideHeadlessTrust } from '../permissions/headless-trust.js';
28
- import { resolvePermissionMode } from '../permissions/mode.js';
29
- import { compilePermissions } from '../permissions/rules.js';
30
- import { withTerminationHandling } from '../termination.js';
31
- import { hostCommandNames } from '../tui/slashCommands.js';
32
- import { describeTurnInterruption, retryAfterMs } from '../tui/turn-interruption.js';
33
- import { expandHeadlessCommand } from '../user-commands/store.js';
34
- import { duration, pauseWait } from './provider-wait.js';
35
- import { resolveResume } from './resume.js';
36
- import { applyProviderFlags, buildGate, loadSkillsContext, parseRunFlags, resolveWorkingDirectory, unknownOptionMessage, } from './run-flags.js';
37
- import { readStdin } from './stdin.js';
38
- /**
39
- * The prompt, from the arguments and the pipe together.
40
- *
41
- * Piped input used to be read only when there was no argument prompt, so
42
- *
43
- * cat notes.txt | namzu run "summarise this"
44
- *
45
- * sent the model three words and silently dropped the file. Nothing reported
46
- * it: the turn succeeded, and the answer was about nothing. A pipe and a
47
- * question are the ordinary way to ask about a document, and taking only one
48
- * of the two is the worst reading of that command.
49
- *
50
- * The piped text is fenced in a tag so the model can tell the instruction from
51
- * the material it is about — without a boundary, a long paste runs into the
52
- * question and the last line of a file reads as part of the request.
53
- *
54
- * Pure so it can be tested without a pipe; the reading happens in the handler.
55
- */
56
- export function composePrompt(fromArgs, piped) {
57
- const question = fromArgs.trim();
58
- const material = piped.trim();
59
- if (!question)
60
- return material;
61
- if (!material)
62
- return question;
63
- return `${question}\n\n<stdin>\n${material}\n</stdin>`;
64
- }
65
- function defaultPrefs(detected) {
66
- const first = detected[0];
67
- return first
68
- ? {
69
- version: 3,
70
- providers: [{ id: first.entry.id }],
71
- subagents: { active: [] },
72
- }
73
- : null;
74
- }
75
- /**
76
- * What `run` prints on stderr when a termination signal stops it, worded from
77
- * where the signal found the turn (`termination.ts` has already given the
78
- * conversation's lease back).
79
- */
80
- function stoppedBy(signal, sessionId, phase, paused) {
81
- switch (phase) {
82
- case 'running':
83
- return `stopped by ${signal}: the turn in conversation ${sessionId} was left interrupted — close it with /abandon in the TUI, or continue it with /resume or \`namzu drain\``;
84
- case 'paused':
85
- return `stopped by ${signal} while the turn was paused: it keeps checkpoint ${paused?.checkpointId ?? '(unknown)'} in conversation ${sessionId} — continue it with /resume or \`namzu drain\`, or close it with /abandon in the TUI`;
86
- case 'ended':
87
- return `stopped by ${signal} after the turn ended; it is recorded in conversation ${sessionId}, and nothing is left to close`;
88
- case 'not-started':
89
- return `stopped by ${signal}; no turn was started in conversation ${sessionId}`;
90
- }
91
- }
92
- export const runCommand = {
93
- name: 'run',
94
- description: 'Run a single prompt headlessly and print the reply (for scripts/CI)',
95
- passThrough: true,
96
- help: [
97
- 'Usage: namzu run [options] <prompt...>',
98
- ' echo "<prompt>" | namzu run',
99
- ' cat file.txt | namzu run "summarise this"',
100
- '',
101
- 'Run a single prompt headlessly and print the reply. Everything that is',
102
- 'not an option is the prompt.',
103
- '',
104
- 'Piped input is used too, not discarded: with no prompt argument it IS',
105
- 'the prompt, and alongside one it is appended as material the question',
106
- 'is about. `namzu run -` reads the prompt from stdin explicitly.',
107
- '',
108
- 'Options (the same ones run-stream takes):',
109
- ' --cwd <path> Directory the agent works in (default: this one)',
110
- ' --provider <id> Provider to answer with',
111
- ' --model <id> Model to answer with',
112
- ' --skills <a,b,c> Load these skills as context for the turn',
113
- ' --continue, -c Resume the most recent conversation here',
114
- ' --resume <id> Resume that conversation, and no other',
115
- ' --gate <command> Verify proposed answers with this command; repeatable',
116
- ' --gate-retries <n> Fix attempts a failing gate allows (default 3)',
117
- ' --max-iterations <n> Main-loop iteration limit (default 50; 0 unlimited)',
118
- ' --token-budget <n> Tree token limit (default unlimited; 0 removes a configured cap)',
119
- ' --effort <level> Explicit reasoning effort (supported levels depend on the model)',
120
- ' --wait-for-provider <d> Wait out provider pauses (a rate limit, an outage)',
121
- ' for up to this long in total — 90s, 30m, 2h — resuming',
122
- ' from the checkpoint each time (default: none; exit 75)',
123
- ' --permission-mode <m> prompt | accept-edits | auto | strict | plan —',
124
- ' what happens to a call no [permissions] rule',
125
- ' decided (default: auto)',
126
- ' --trust Accept this folder for THIS turn',
127
- ' -- End of options; the rest is the prompt verbatim',
128
- '',
129
- 'A folder has to be trusted before namzu will work in it, because namzu',
130
- 'reads its files, runs commands in it and executes its code. Run `namzu`',
131
- 'here once and accept the prompt to trust it permanently, or pass --trust',
132
- 'to accept it for one turn. --trust does not remember; that is the point.',
133
- '',
134
- '--yolo does NOT imply --trust: one is about which tools may run inside a',
135
- 'folder, the other about the folder.',
136
- '',
137
- 'By default tools run without asking, because there is nobody to ask, and',
138
- 'the safety gate still refuses catastrophic commands. Use --permission-mode',
139
- 'strict for an unattended turn that must refuse anything no rule allowed.',
140
- '',
141
- 'A mode only decides calls no rule decided: it can never reopen a deny.',
142
- '',
143
- '--gate checks proposed answers with operator-supplied commands. Every',
144
- 'command must complete successfully; a failure returns diagnostics to the',
145
- 'model for correction. Repeat the flag to check several commands in order.',
146
- 'Budget exhaustion or cancellation may stop a turn before verification.',
147
- '',
148
- 'A failed gate may skip a retry when its Git change detector is unchanged.',
149
- 'The attempt still counts. Exhausted review attempts stop the turn with',
150
- 'answer_rejected and a non-zero exit.',
151
- '',
152
- "The working directory's AGENTS.md files — that directory and every one up",
153
- 'to the repository root — are loaded as standing instructions for the turn,',
154
- 'and the ones that were loaded are named on stderr.',
155
- '',
156
- '--continue and --resume refuse when the conversation cannot be reopened,',
157
- 'and say why. Neither ever falls back to starting a new one: run with no',
158
- 'flag if that is what you want.',
159
- '',
160
- 'Needs a provider. Set a credential in the environment, or run namzu',
161
- 'once to pick one interactively.',
162
- '',
163
- 'A run the provider pauses keeps a checkpoint. Without --wait-for-provider',
164
- 'it exits 75 at once and a wrapper decides when to run again; with it, the',
165
- "run waits the provider's own delay when it named one (otherwise a minute,",
166
- 'doubling, at most fifteen) and resumes from the checkpoint in this process,',
167
- 'until the budget is spent. The `limits.waitForProviderMs` config key sets',
168
- 'the same budget for every turn in the folder.',
169
- '',
170
- 'Exit codes: 0 on a reply, 1 on a failed or unfinished turn, 2 when no',
171
- 'prompt was supplied, 64 when an argument is wrong, 75 when the provider',
172
- 'paused the turn (a rate limit or an outage) and a checkpoint was kept —',
173
- 'wait, then run again — or when the conversation already has an active',
174
- 'turn (a paused one: finish it with `namzu drain`, or abandon it in the',
175
- 'TUI with /abandon), and 77 when the folder has not been trusted and',
176
- 'nothing ran.',
177
- ].join('\n'),
178
- handler: withTerminationHandling(async ({ ctx: bootstrapCtx, rawArgs }, termination) => {
179
- let ctx = bootstrapCtx;
180
- const flags = parseRunFlags(rawArgs);
181
- // The turn's leash: the config file's limits, with a flag overriding each.
182
- const limitsFromFlags = {
183
- ...(flags.maxIterations !== null ? { maxIterations: flags.maxIterations } : {}),
184
- ...(flags.tokenBudget !== null ? { tokenBudget: flags.tokenBudget } : {}),
185
- };
186
- if (flags.unknown.length > 0) {
187
- // A shell caller learns about a bad argument from `$?`, so this is 64
188
- // rather than the in-band error event the streaming sibling emits.
189
- ctx.formatter.error({ message: unknownOptionMessage(flags.unknown) });
190
- return EXIT_USAGE;
191
- }
192
- // `-` on its own means "the prompt is on stdin", the usual spelling for
193
- // it. Before, it was sent to the model as a one-character question.
194
- const fromArgs = flags.rest.join(' ').trim() === '-' ? '' : flags.rest.join(' ').trim();
195
- // With no prompt argument, piped input IS the prompt and is waited for
196
- // as long as it takes — that is the existing contract for `echo … |
197
- // namzu run` and for the `-` sentinel. Alongside a prompt it is extra
198
- // material, so it gets the first-byte deadline instead: a caller who
199
- // asked a complete question should never be left waiting on a pipe
200
- // they did not mean to open.
201
- const piped = await readStdin({ deadline: Boolean(fromArgs) });
202
- const prompt = composePrompt(fromArgs, piped);
203
- if (!prompt) {
204
- ctx.formatter.error({
205
- message: 'no prompt — pass it as an argument or pipe it via stdin',
206
- });
207
- return 2;
208
- }
209
- const resolved = resolveWorkingDirectory(flags.cwd);
210
- if ('error' in resolved) {
211
- ctx.formatter.error({ message: resolved.error });
212
- return EXIT_USAGE;
213
- }
214
- // Before anything is read, run or constructed in that directory. The
215
- // order is the gate: a check that happens after the session is built has
216
- // already opened stores and walked the tree it was meant to protect.
217
- const trust = decideHeadlessTrust({
218
- cwd: resolved.cwd,
219
- trustFlag: flags.trust,
220
- });
221
- if (!trust.allowed) {
222
- ctx.formatter.error({ message: trust.message ?? 'folder not trusted' });
223
- return EXIT_UNTRUSTED;
224
- }
225
- const cwd = trust.cwd;
226
- ctx = resolveTrustedProjectContext(bootstrapCtx, cwd);
227
- // Project commands are code-like launch authority: discover and expand
228
- // them only after the target folder has crossed the same trust boundary
229
- // as its config and instructions.
230
- const expansion = expandHeadlessCommand(prompt, {
231
- cwd,
232
- builtins: hostCommandNames(),
233
- });
234
- if (expansion.kind === 'refused') {
235
- ctx.formatter.error({ message: expansion.reason });
236
- return EXIT_USAGE;
237
- }
238
- const finalPrompt = expansion.kind === 'expanded' ? expansion.prompt : prompt;
239
- // The CLI owns stderr, not the kernel it drives (LOG-05) — a live sink
240
- // at the level --verbose/--quiet/NAMZU_LOG_LEVEL named, instead of
241
- // forcing the level to `silent` via `configureLogger`, which threw
242
- // every diagnostic away regardless of what anyone asked for.
243
- // `{ replace: true }`: a real invocation calls this once, but this
244
- // package's own test suite calls a command's handler more than once
245
- // per process, which a refusing second install would break for
246
- // reasons that have nothing to do with what those tests are about.
247
- const logging = contextLogging(ctx);
248
- installCliLogging(createStderrSink(logging.format), logging.level);
249
- const { probeAgentSession, createAgentSession } = await import('../tui/agent.js');
250
- const probe = await probeAgentSession();
251
- let prefs = probe.preferences ?? defaultPrefs(probe.detected);
252
- if (!prefs) {
253
- ctx.formatter.error({
254
- message: 'no LLM provider available — set a credential (e.g. ANTHROPIC_API_KEY) or run `namzu` to pick one',
255
- });
256
- return 1;
257
- }
258
- prefs = applyProviderFlags(prefs, flags);
259
- // A permission the operator wrote and which was silently dropped is the
260
- // worst outcome available here: they believe a control is in force and it
261
- // is not. So a bad line is reported and the rest still load.
262
- const modeResult = resolvePermissionMode({
263
- flag: flags.permissionMode,
264
- skipPermissions: flags.skipPermissions,
265
- // A headless run has nobody to ask, so `prompt` here would silently
266
- // become `auto`. Resolving it as `auto` says so instead.
267
- interactive: false,
268
- });
269
- if ('error' in modeResult) {
270
- ctx.formatter.error({ message: modeResult.error });
271
- return EXIT_USAGE;
272
- }
273
- const permissions = compilePermissions(ctx.config.permissions, ctx.config.permissionChecks);
274
- for (const d of permissions.diagnostics) {
275
- const where = d.pattern ? `permissions.${d.tool}."${d.pattern}"` : `permissions.${d.tool}`;
276
- ctx.formatter.error({ message: `${where}: ${d.message}` });
277
- }
278
- const gate = buildGate(flags, cwd);
279
- // Attached BEFORE the session, and its failure is fatal. An operator who
280
- // configured `telemetry.sessionExport` asked for this turn to be
281
- // recorded; continuing without it means the turn happens and the record
282
- // they were counting on does not exist, which is a failure they only
283
- // discover when they go looking for a session that was never written.
284
- let sessionExport;
285
- if (ctx.config.telemetry?.sessionExport) {
286
- try {
287
- sessionExport = await attachSessionExport({
288
- config: ctx.config.telemetry.sessionExport,
289
- });
290
- // Under the same event name the boot narrative used for the
291
- // boolean. This is the half that names the destination and the
292
- // redactors, and it is emitted HERE because it describes what
293
- // actually resolved rather than what was configured.
294
- cliLogger().info(sessionExport.disclosure, {
295
- [EVENT_NAME_ATTRIBUTE]: BOOT_EVENT_NAMES.TELEMETRY_STATUS,
296
- 'namzu.telemetry.session_export': true,
297
- });
298
- }
299
- catch (err) {
300
- ctx.formatter.error({
301
- message: err instanceof Error ? err.message : String(err),
302
- });
303
- return 1;
304
- }
305
- }
306
- let sessions;
307
- try {
308
- sessions = await openSessions(cwd);
309
- }
310
- catch (error) {
311
- await sessionExport?.shutdown();
312
- ctx.formatter.error({
313
- message: `workspace state is unavailable: ${error instanceof Error ? error.message : String(error)}`,
314
- });
315
- return 1;
316
- }
317
- const resume = await resolveResume(sessions, { continueLast: flags.continueLast, sessionId: flags.resume }, cwd);
318
- if (resume.kind === 'error') {
319
- ctx.formatter.error({ message: resume.message });
320
- await sessionExport?.shutdown();
321
- return EXIT_USAGE;
322
- }
323
- const prior = resume.kind === 'resumed' ? resume.messages : [];
324
- // A new one-shot is a new conversation: its log starts here, so the turn
325
- // the kernel records has somewhere to go and `--continue` can find it.
326
- let sessionId;
327
- try {
328
- sessionId =
329
- resume.kind === 'resumed'
330
- ? asSessionId(resume.sessionId)
331
- : await startConversation(sessions);
332
- }
333
- catch (error) {
334
- closeSessions(sessions);
335
- await sessionExport?.shutdown();
336
- ctx.formatter.error({
337
- message: `could not start a conversation: ${error instanceof Error ? error.message : String(error)}`,
338
- });
339
- return 1;
340
- }
341
- const session = await createAgentSession(prefs, probe.detected, {
342
- cwd,
343
- scope: {
344
- sessionId,
345
- topicId: sessions.topicId,
346
- projectId: sessions.projectId,
347
- tenantId: sessions.tenantId,
348
- },
349
- stateRoot: sessions.root,
350
- conversationSessions: sessions,
351
- rules: permissions.rules,
352
- ...(sessionExport ? { onSessionEvent: sessionExport.listener } : {}),
353
- // The operator's --gate commands, as a standing condition on the
354
- // answer. Spread rather than passed as undefined so a turn without
355
- // gates is byte-identical to the one that shipped before them.
356
- ...(gate ?? {}),
357
- permissionMode: modeResult.mode,
358
- ...(ctx.config.mcpServers ? { mcpServers: ctx.config.mcpServers } : {}),
359
- ...(ctx.config.plugins ? { plugins: ctx.config.plugins } : {}),
360
- ...(ctx.config.web ? { web: ctx.config.web } : {}),
361
- ...(ctx.config.hooks ? { hooks: ctx.config.hooks } : {}),
362
- ...(ctx.config.compaction ? { compaction: ctx.config.compaction } : {}),
363
- ...(ctx.config.memory ? { memory: ctx.config.memory } : {}),
364
- ...(Object.keys({ ...ctx.config.limits, ...limitsFromFlags }).length > 0
365
- ? { limits: { ...ctx.config.limits, ...limitsFromFlags } }
366
- : {}),
367
- ...(ctx.config.sandbox ? { sandbox: ctx.config.sandbox } : {}),
368
- // `!== undefined`, not truthiness: an empty list is the operator
369
- // turning the default screen OFF, and a falsy check would drop it.
370
- ...(ctx.config.toolResultScreens !== undefined
371
- ? { toolResultScreens: ctx.config.toolResultScreens }
372
- : {}),
373
- });
374
- if (!session.hasProvider) {
375
- await session.close();
376
- closeSessions(sessions);
377
- await sessionExport?.shutdown();
378
- ctx.formatter.error({
379
- message: session.errorHint ?? 'agent is not ready',
380
- });
381
- return 1;
382
- }
383
- // A configured tool server that is not here means the turn cannot do what
384
- // the operator set it up to do, and there is nobody watching to notice.
385
- // The TUI reports and carries on, because a person can read the line and
386
- // decide; a script has no such reader, so it refuses. Same principle as
387
- // the permission mode resolving differently when `interactive` is false.
388
- if (session.mcpFailed.length > 0) {
389
- for (const f of session.mcpFailed) {
390
- ctx.formatter.error({
391
- message: `tool server "${f.name}" is not available: ${f.reason}`,
392
- });
393
- }
394
- await session.close();
395
- closeSessions(sessions);
396
- await sessionExport?.shutdown();
397
- return 1;
398
- }
399
- // "Printed on every launch" has to mean every launch, not every launch of
400
- // the TUI. A scripted run under an accepted capability limitation is
401
- // exactly the case where nobody is watching, so the line has to be in the
402
- // output the script keeps.
403
- for (const notice of session.configNotices) {
404
- ctx.formatter.info(notice);
405
- }
406
- for (const s of session.mcpConnected) {
407
- ctx.formatter.info(`tool server ${s.name} · ${s.toolCount} tools`);
408
- }
409
- ctx.formatter.info(`namzu · ${session.providerSummary}${session.modelSummary ? ` · ${session.modelSummary}` : ''}`);
410
- // stderr like every other status line, so a caller piping the answer is
411
- // unaffected and a person watching can still tell which instructions the
412
- // run is bound by. A script that reads AGENTS.md aloud is not a script
413
- // whose output changed.
414
- if (session.instructionFiles.length > 0) {
415
- ctx.formatter.info(`project instructions: ${session.instructionFiles
416
- .map((p) => relative(cwd, p) || p)
417
- .join(', ')}`);
418
- }
419
- // A refusal that says nothing is indistinguishable from a project that
420
- // declared nothing, and the two want opposite responses from the reader.
421
- for (const skip of session.skippedInstructionFiles) {
422
- ctx.formatter.error({
423
- message: `skipped ${relative(cwd, skip.path) || skip.path}: ${skip.reason}`,
424
- });
425
- }
426
- const extraSystem = await loadSkillsContext(cwd, flags.skills);
427
- if (resume.kind === 'resumed') {
428
- ctx.formatter.info(`resuming ${resume.sessionId} · ${prior.length} messages`);
429
- }
430
- let text = '';
431
- const measured = {};
432
- const jsonResult = (value) => ({
433
- text: value,
434
- ...(measured.usage
435
- ? {
436
- usage: {
437
- totalTokens: measured.usage.totalTokens,
438
- cost: measured.usage.cost,
439
- },
440
- }
441
- : {}),
442
- ...(measured.budget ? { budget: measured.budget } : {}),
443
- });
444
- let stopReason;
445
- // Written from inside `consume`, so held on an object: a `let` assigned
446
- // only in a closure is `null` as far as the type checker can see, and
447
- // every read after the loop would narrow it to `never`.
448
- const stop = {
449
- failed: null,
450
- paused: null,
451
- busy: false,
452
- };
453
- // Stopped from outside (SIGTERM, SIGHUP, Ctrl+C): the conversation's
454
- // lease is already given back when this runs (`termination.ts`). Stop the
455
- // turn, so its tools' processes go with it, and release what the session
456
- // holds. What the operator is told depends on where the signal found the
457
- // turn: mid-flight it is left interrupted; waiting out a provider pause it
458
- // keeps its checkpoint; after it settled (the session still closing, a
459
- // slow `session_end` hook) it is recorded, and there is nothing to close.
460
- const turnAbort = new AbortController();
461
- let stopped = false;
462
- let phase = 'running';
463
- const afterPhase = () => {
464
- phase = stop.busy ? 'not-started' : stop.paused ? 'paused' : 'ended';
465
- };
466
- termination.onTerminate(async (signal) => {
467
- stopped = true;
468
- ctx.formatter.error({ message: stoppedBy(signal, sessionId, phase, stop.paused) });
469
- turnAbort.abort(new TurnCancelled('user'));
470
- await session.close();
471
- closeSessions(sessions);
472
- await sessionExport?.shutdown();
473
- });
474
- const consume = async (stream) => {
475
- stop.failed = null;
476
- stop.paused = null;
477
- for await (const event of stream) {
478
- if (event.kind === 'delta')
479
- text += event.text;
480
- else if (event.kind === 'tool-start')
481
- ctx.formatter.info(`⏺ ${event.toolName} ${event.summary}`);
482
- // stderr, like every other status line, so it reaches a person
483
- // watching without contaminating the answer a caller piped.
484
- else if (event.kind === 'context')
485
- ctx.formatter.info(event.text);
486
- else if (event.kind === 'error' || event.kind === 'paused') {
487
- if (event.budget)
488
- measured.budget = event.budget;
489
- stop.failed = describeTurnInterruption(event);
490
- if (event.kind === 'error' && event.turnInProgress) {
491
- stop.busy = true;
492
- stop.failed = `conversation ${event.turnInProgress.sessionId} already has a ${event.turnInProgress.state} turn ${event.turnInProgress.activeTurnId}; nothing was started. Finish it with \`namzu drain\`, or abandon it with /abandon in the TUI.`;
493
- }
494
- if (event.kind === 'paused')
495
- stop.paused = event;
496
- }
497
- else if (event.kind === 'usage') {
498
- measured.usage = event;
499
- if (event.budget)
500
- measured.budget = event.budget;
501
- }
502
- else if (event.kind === 'done') {
503
- // Deltas include preliminary and rejected answers. Settlement
504
- // supplies the final result after review and output guardrails;
505
- // an explicit empty result must also replace earlier text.
506
- if (event.text !== undefined)
507
- text = event.text;
508
- stopReason = event.stopReason;
509
- if (event.budget)
510
- measured.budget = event.budget;
511
- }
512
- }
513
- };
514
- await consume(session.send([...prior, { role: 'user', content: finalPrompt, timestamp: Date.now() }], {
515
- signal: turnAbort.signal,
516
- ...(extraSystem ? { extraSystem } : {}),
517
- ...(flags.effort !== null ? { effort: flags.effort } : {}),
518
- }));
519
- afterPhase();
520
- // A provider pause is answered by waiting, when the caller gave time to
521
- // wait with. The kernel kept a checkpoint; the turn resumes from it in
522
- // this process, with its own context, rather than being re-prompted from
523
- // notes by a wrapper that saw exit 75. A pause with no provider behind
524
- // it is not waited on: that is a turn parked on something else.
525
- const waitBudgetMs = flags.waitForProviderMs ?? ctx.config.limits?.waitForProviderMs ?? 0;
526
- let waits = 0;
527
- let waitedMs = 0;
528
- while (!stopped &&
529
- stop.paused &&
530
- waitBudgetMs > 0 &&
531
- (stop.paused.providerError || stop.paused.failure)) {
532
- const paused = stop.paused;
533
- const asked = retryAfterMs(paused);
534
- const decision = pauseWait({
535
- waited: waits,
536
- ...(asked !== undefined ? { retryAfterMs: asked } : {}),
537
- waitedMs,
538
- budgetMs: waitBudgetMs,
539
- });
540
- if (decision.kind === 'stop') {
541
- stop.failed = `${stop.failed}\nNot resumed: ${decision.reason}.`;
542
- break;
543
- }
544
- waits += 1;
545
- ctx.formatter.info(`provider paused the turn: waiting ${duration(decision.delayMs)}, then resuming from ${paused.checkpointId} (wait ${waits}, ${duration(waitedMs)} of ${duration(waitBudgetMs)} spent)`);
546
- await new Promise((resolve) => setTimeout(resolve, decision.delayMs));
547
- // A signal during the wait: the process is on its way out, and the
548
- // turn keeps its checkpoint for whoever resumes it next.
549
- if (stopped)
550
- break;
551
- waitedMs += decision.delayMs;
552
- phase = 'running';
553
- await consume(session.resumePaused({
554
- turnId: paused.turnId,
555
- checkpointId: paused.checkpointId,
556
- signal: turnAbort.signal,
557
- }));
558
- afterPhase();
559
- }
560
- // The signal handler closes the session and ends the process.
561
- if (stopped)
562
- return 1;
563
- const failed = stop.failed;
564
- // 75 (EX_TEMPFAIL) for both: a provider pause kept a checkpoint, and a
565
- // conversation busy with another turn refused to start one. Either way
566
- // running again later is the remedy, not a different invocation.
567
- const paused = stop.paused !== null || stop.busy;
568
- // Every exit below this point releases the session first. A stdio tool
569
- // server is a child process, and a `run` that returns without closing
570
- // leaves it behind.
571
- await session.close();
572
- closeSessions(sessions);
573
- // Drained with the session, not at process exit: a buffering sink that
574
- // only flushed on `beforeExit` loses its tail whenever the CLI is
575
- // interrupted, which is exactly the turn somebody wanted the record of.
576
- await sessionExport?.shutdown();
577
- if (measured.budget) {
578
- ctx.formatter.info(`Tokens: ${measured.budget.ownTokens} own · ${measured.budget.treeTokens} including descendants`);
579
- }
580
- if (failed) {
581
- // A provider can pause or fail after producing useful text. The TUI
582
- // keeps that partial answer and a shell caller deserves the same bytes;
583
- // the non-zero verdict is what prevents it being mistaken for complete.
584
- const partial = text.trim();
585
- if (partial) {
586
- ctx.formatter.print(ctx.formatter.name === 'json' ? jsonResult(partial) : partial);
587
- }
588
- ctx.formatter.error({
589
- message: `${failed}${partial ? ' — the output above is partial' : ''}`,
590
- });
591
- // A pause is not a failure: the provider said "not now" (a rate
592
- // limit, an outage) and the kernel kept a checkpoint. A wrapper that
593
- // re-runs on 1 would hammer a limited provider and give up on a
594
- // finished-looking failure alike; 75 (EX_TEMPFAIL, the sysexits
595
- // convention for "try again later") lets it back off instead.
596
- return paused ? 75 : 1;
597
- }
598
- // The text prints either way. Partial output is real output, and a
599
- // caller who piped it wants what there is — but `$?` has to be able to
600
- // tell them it is partial, which it could not: `turn_failed` is emitted
601
- // only from the throw path, so a turn stopped by its token budget, its
602
- // timeout, its iteration cap, a cancellation, or a blocking output
603
- // guardrail all arrived as `turn_completed` and exited 0. Measured: a
604
- // `max_iterations` stop reports `status: 'completed'`. The sharp case is
605
- // the guardrail — a REFUSED answer exited 0 with empty text, so
606
- // `namzu run … > out.txt && deploy` proceeded on the empty file.
607
- ctx.formatter.print(ctx.formatter.name === 'json' ? jsonResult(text.trim()) : text.trim());
608
- if (stopReason && stopReason !== 'end_turn') {
609
- ctx.formatter.error({
610
- message: `turn did not finish normally: ${stopReason}${text.trim() ? ' — the output above is partial' : ''}`,
611
- });
612
- return 1;
613
- }
614
- return 0;
615
- }),
616
- };
617
- //# sourceMappingURL=run.js.map