@namzu/cli 11.0.0 → 12.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.
- package/README.md +390 -46
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +132 -4
- package/dist/cli.js.map +1 -1
- package/dist/commands/acp.d.ts +29 -0
- package/dist/commands/acp.d.ts.map +1 -0
- package/dist/commands/acp.js +156 -0
- package/dist/commands/acp.js.map +1 -0
- package/dist/commands/doctor.d.ts +12 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +18 -2
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/drain.d.ts +2 -2
- package/dist/commands/drain.d.ts.map +1 -1
- package/dist/commands/drain.js +31 -8
- package/dist/commands/drain.js.map +1 -1
- package/dist/commands/run-flags.d.ts.map +1 -1
- package/dist/commands/run-flags.js +33 -0
- package/dist/commands/run-flags.js.map +1 -1
- package/dist/commands/run-stream.d.ts +3 -3
- package/dist/commands/run-stream.d.ts.map +1 -1
- package/dist/commands/run-stream.js +27 -10
- package/dist/commands/run-stream.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +50 -4
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/types.d.ts +10 -0
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/config/load.d.ts +64 -0
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +137 -20
- package/dist/config/load.js.map +1 -1
- package/dist/config/schema.d.ts +51 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/context/capabilities.d.ts +88 -0
- package/dist/context/capabilities.d.ts.map +1 -0
- package/dist/context/capabilities.js +160 -0
- package/dist/context/capabilities.js.map +1 -0
- package/dist/context/sandbox.d.ts +13 -0
- package/dist/context/sandbox.d.ts.map +1 -1
- package/dist/context/sandbox.js +15 -0
- package/dist/context/sandbox.js.map +1 -1
- package/dist/doctor/checks/index.d.ts +6 -1
- package/dist/doctor/checks/index.d.ts.map +1 -1
- package/dist/doctor/checks/index.js +45 -2
- package/dist/doctor/checks/index.js.map +1 -1
- package/dist/doctor/checks/invariants.d.ts +23 -0
- package/dist/doctor/checks/invariants.d.ts.map +1 -0
- package/dist/doctor/checks/invariants.js +79 -0
- package/dist/doctor/checks/invariants.js.map +1 -0
- package/dist/doctor/checks/logging.d.ts +10 -0
- package/dist/doctor/checks/logging.d.ts.map +1 -0
- package/dist/doctor/checks/logging.js +69 -0
- package/dist/doctor/checks/logging.js.map +1 -0
- package/dist/doctor/checks/session-export.d.ts +21 -0
- package/dist/doctor/checks/session-export.d.ts.map +1 -0
- package/dist/doctor/checks/session-export.js +62 -0
- package/dist/doctor/checks/session-export.js.map +1 -0
- package/dist/doctor/checks/telemetry.d.ts +15 -28
- package/dist/doctor/checks/telemetry.d.ts.map +1 -1
- package/dist/doctor/checks/telemetry.js +34 -54
- package/dist/doctor/checks/telemetry.js.map +1 -1
- package/dist/doctor/checks/vault.d.ts +4 -20
- package/dist/doctor/checks/vault.d.ts.map +1 -1
- package/dist/doctor/checks/vault.js +58 -19
- package/dist/doctor/checks/vault.js.map +1 -1
- package/dist/doctor/registry.d.ts.map +1 -1
- package/dist/doctor/registry.js +13 -6
- package/dist/doctor/registry.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/files/attachment-store.d.ts +44 -0
- package/dist/integrations/files/attachment-store.d.ts.map +1 -0
- package/dist/integrations/files/attachment-store.js +86 -0
- package/dist/integrations/files/attachment-store.js.map +1 -0
- package/dist/integrations/providers/credential-provider.d.ts +39 -0
- package/dist/integrations/providers/credential-provider.d.ts.map +1 -0
- package/dist/integrations/providers/credential-provider.js +74 -0
- package/dist/integrations/providers/credential-provider.js.map +1 -0
- package/dist/integrations/providers/discover.d.ts.map +1 -1
- package/dist/integrations/providers/discover.js +15 -3
- package/dist/integrations/providers/discover.js.map +1 -1
- package/dist/integrations/providers/oauth.d.ts.map +1 -1
- package/dist/integrations/providers/oauth.js +24 -1
- package/dist/integrations/providers/oauth.js.map +1 -1
- package/dist/integrations/sessions/store.d.ts +2 -2
- package/dist/integrations/sessions/store.d.ts.map +1 -1
- package/dist/integrations/sessions/store.js +21 -9
- package/dist/integrations/sessions/store.js.map +1 -1
- package/dist/integrations/subagents/runtime.d.ts +3 -3
- package/dist/integrations/subagents/runtime.d.ts.map +1 -1
- package/dist/integrations/subagents/runtime.js +11 -11
- package/dist/integrations/subagents/runtime.js.map +1 -1
- package/dist/integrations/telemetry/session-export.d.ts +99 -0
- package/dist/integrations/telemetry/session-export.d.ts.map +1 -0
- package/dist/integrations/telemetry/session-export.js +119 -0
- package/dist/integrations/telemetry/session-export.js.map +1 -0
- package/dist/logging.d.ts +79 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +67 -0
- package/dist/logging.js.map +1 -0
- package/dist/permissions/rules.d.ts +3 -3
- package/dist/permissions/rules.d.ts.map +1 -1
- package/dist/permissions/rules.js +1 -1
- package/dist/permissions/rules.js.map +1 -1
- package/dist/skills/store.d.ts +1 -1
- package/dist/skills/store.js +1 -1
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/App.js +92 -6
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/StatusBar.d.ts +1 -1
- package/dist/tui/StatusBar.d.ts.map +1 -1
- package/dist/tui/agent.d.ts +54 -24
- package/dist/tui/agent.d.ts.map +1 -1
- package/dist/tui/agent.js +327 -124
- package/dist/tui/agent.js.map +1 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +17 -6
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/log-pane.d.ts +48 -0
- package/dist/tui/log-pane.d.ts.map +1 -0
- package/dist/tui/log-pane.js +106 -0
- package/dist/tui/log-pane.js.map +1 -0
- package/dist/tui/slashCommands.d.ts +134 -11
- package/dist/tui/slashCommands.d.ts.map +1 -1
- package/dist/tui/slashCommands.js +169 -15
- package/dist/tui/slashCommands.js.map +1 -1
- package/dist/tui/types.d.ts +11 -2
- package/dist/tui/types.d.ts.map +1 -1
- package/package.json +8 -6
package/dist/cli.js
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
import { readFileSync } from 'node:fs';
|
|
10
10
|
import { dirname, join } from 'node:path';
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
|
-
import { Command, CommanderError } from 'commander';
|
|
12
|
+
import { Command, CommanderError, Option } from 'commander';
|
|
13
|
+
import { BOOT_EVENT_NAMES, EVENT_NAME_ATTRIBUTE, VERSION as SDK_VERSION, getRootLogger, installProcessSink, } from '@namzu/sdk';
|
|
14
|
+
import { acpCommand } from './commands/acp.js';
|
|
13
15
|
import { doctorCommand } from './commands/doctor.js';
|
|
14
16
|
import { drainCommand } from './commands/drain.js';
|
|
15
17
|
import { evalCommand } from './commands/eval.js';
|
|
@@ -18,8 +20,9 @@ import { registerAll } from './commands/registry.js';
|
|
|
18
20
|
import { historyCommand, providersJSONCommand, runStreamCommand, skillsJSONCommand, } from './commands/run-stream.js';
|
|
19
21
|
import { runCommand } from './commands/run.js';
|
|
20
22
|
import { stubCommands } from './commands/stubs.js';
|
|
21
|
-
import { ConfigLoadError,
|
|
23
|
+
import { ConfigLoadError, loadConfigWithProvenance, } from './config/load.js';
|
|
22
24
|
import { EXIT_BAD_CONFIG, EXIT_INTERNAL_ERROR } from './exit-codes.js';
|
|
25
|
+
import { createStderrSink, resolveLogFormat, resolveLogLevel } from './logging.js';
|
|
23
26
|
import { createFormatter, isFormatName } from './output/index.js';
|
|
24
27
|
import { compilePermissions } from './permissions/rules.js';
|
|
25
28
|
/** sysexits EX_USAGE — command-line argument error. */
|
|
@@ -50,7 +53,9 @@ export async function runCli(opts) {
|
|
|
50
53
|
.description('Operator CLI for the Namzu agent platform')
|
|
51
54
|
.version(CLI_VERSION, '-V, --version', 'Print version and exit')
|
|
52
55
|
.option('-f, --format <type>', 'Output format: text, json, yaml')
|
|
53
|
-
.option('-q, --quiet', 'Suppress non-essential output')
|
|
56
|
+
.option('-q, --quiet', 'Suppress non-essential output; also raises the log floor to warn')
|
|
57
|
+
.addOption(new Option('-v, --verbose', 'Emit debug-level log records to stderr').conflicts('quiet'))
|
|
58
|
+
.addOption(new Option('--log-format <format>', 'Log record format for run/drain/TUI-flush output: pretty (default) or json. namzu run-stream always writes json, regardless of this flag.').choices(['pretty', 'json']))
|
|
54
59
|
.option('--dangerously-skip-permissions', 'Run tools without asking for approval (no permission prompts). Only use in a sandbox or a folder you fully trust.')
|
|
55
60
|
.option('--yolo', 'Alias of --dangerously-skip-permissions.')
|
|
56
61
|
// Required by Commander 14 so subcommands (doctor) can opt into
|
|
@@ -63,18 +68,43 @@ export async function runCli(opts) {
|
|
|
63
68
|
if (ctx)
|
|
64
69
|
return ctx;
|
|
65
70
|
const globalOpts = program.opts();
|
|
66
|
-
const fileConfig =
|
|
71
|
+
const { config: fileConfig, provenance } = loadConfigWithProvenance();
|
|
67
72
|
const format = globalOpts.format && isFormatName(globalOpts.format)
|
|
68
73
|
? globalOpts.format
|
|
69
74
|
: (fileConfig.format ?? 'text');
|
|
70
75
|
const quiet = globalOpts.quiet ?? fileConfig.quiet ?? false;
|
|
76
|
+
// Resolved from the ACTUAL parsed flags, not `quiet` above — that value
|
|
77
|
+
// already folds in NAMZU_QUIET and a config file's `quiet: true`.
|
|
78
|
+
// "Flag beats env" (LOG-05) means the literal --verbose/--quiet on THIS
|
|
79
|
+
// command line beats NAMZU_LOG_LEVEL; widening it to every source that
|
|
80
|
+
// can produce `quiet: true` would let NAMZU_QUIET silently override an
|
|
81
|
+
// operator's own NAMZU_LOG_LEVEL, which neither variable promises.
|
|
82
|
+
const logging = {
|
|
83
|
+
level: resolveLogLevel({ verbose: globalOpts.verbose, quiet: globalOpts.quiet }),
|
|
84
|
+
format: resolveLogFormat({ logFormat: globalOpts.logFormat }),
|
|
85
|
+
};
|
|
86
|
+
// The process's log destination, claimed HERE — the first point ANY
|
|
87
|
+
// invocation has resolved a level/format — rather than left for
|
|
88
|
+
// whichever subcommand happens to reach `createAgentSession`. `doctor`
|
|
89
|
+
// and `login` never call that function at all; without this line, a
|
|
90
|
+
// debug-level `namzu.config.resolved` row would be unreachable under
|
|
91
|
+
// `--verbose` for either of them. `{ replace: true }` for the same
|
|
92
|
+
// reason every other call site takes it (`commands/run.ts`): a
|
|
93
|
+
// subcommand installs its OWN sink moments later, computed from the
|
|
94
|
+
// SAME `logging` this line just resolved, or a deliberately different
|
|
95
|
+
// one (the TUI's ring buffer) — never a second party fighting this one
|
|
96
|
+
// for the destination.
|
|
97
|
+
installProcessSink(createStderrSink(logging.format), logging.level, { replace: true });
|
|
98
|
+
emitBootNarrative(provenance, fileConfig);
|
|
71
99
|
ctx = {
|
|
72
100
|
formatter: createFormatter(format, { quiet }),
|
|
73
101
|
config: { ...fileConfig, format, quiet },
|
|
102
|
+
logging,
|
|
74
103
|
};
|
|
75
104
|
return ctx;
|
|
76
105
|
};
|
|
77
106
|
registerAll(program, [
|
|
107
|
+
acpCommand,
|
|
78
108
|
doctorCommand,
|
|
79
109
|
runCommand,
|
|
80
110
|
loginCommand,
|
|
@@ -113,6 +143,7 @@ export async function runCli(opts) {
|
|
|
113
143
|
version: CLI_VERSION,
|
|
114
144
|
skipPermissions,
|
|
115
145
|
rules: permissions.rules,
|
|
146
|
+
logging: tuiCtx.logging,
|
|
116
147
|
...(tuiCtx.config.mcpServers ? { mcpServers: tuiCtx.config.mcpServers } : {}),
|
|
117
148
|
...(tuiCtx.config.sandbox ? { sandbox: tuiCtx.config.sandbox } : {}),
|
|
118
149
|
});
|
|
@@ -141,6 +172,102 @@ export async function runCli(opts) {
|
|
|
141
172
|
return EXIT_INTERNAL_ERROR;
|
|
142
173
|
}
|
|
143
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* The CLI-process third of the boot narrative — the two other thirds
|
|
177
|
+
* (`namzu.sandbox.resolved`/`.provider.resolved`/`.capability.*`/
|
|
178
|
+
* `.discovery.completed`/`.boot.ready`, and the SDK's own
|
|
179
|
+
* `namzu.migration.completed`) belong to `createAgentSession`
|
|
180
|
+
* (`tui/agent.ts`) and `query()` respectively, because they describe facts
|
|
181
|
+
* an agent session resolves — `doctor` and `login` never reach either.
|
|
182
|
+
*
|
|
183
|
+
* Exported (not re-exported from `./index.ts`) so `__tests__/` can drive it
|
|
184
|
+
* directly with a hand-built `ConfigProvenance` and a capturing sink,
|
|
185
|
+
* without needing a live Commander parse or a real config cascade on disk.
|
|
186
|
+
*/
|
|
187
|
+
export function emitBootNarrative(provenance, config) {
|
|
188
|
+
const log = getRootLogger();
|
|
189
|
+
log.info('namzu starting', {
|
|
190
|
+
[EVENT_NAME_ATTRIBUTE]: BOOT_EVENT_NAMES.BOOT_START,
|
|
191
|
+
'namzu.boot.cli_version': CLI_VERSION,
|
|
192
|
+
'namzu.boot.sdk_version': SDK_VERSION,
|
|
193
|
+
'namzu.boot.node_version': process.version,
|
|
194
|
+
'namzu.boot.platform': `${process.platform}-${process.arch}`,
|
|
195
|
+
});
|
|
196
|
+
const counts = {
|
|
197
|
+
default: 0,
|
|
198
|
+
'user-file': 0,
|
|
199
|
+
'project-file': 0,
|
|
200
|
+
env: 0,
|
|
201
|
+
};
|
|
202
|
+
for (const source of Object.values(provenance)) {
|
|
203
|
+
if (source)
|
|
204
|
+
counts[source.kind]++;
|
|
205
|
+
}
|
|
206
|
+
const keyCount = Object.keys(provenance).length;
|
|
207
|
+
log.info('Configuration resolved', {
|
|
208
|
+
[EVENT_NAME_ATTRIBUTE]: BOOT_EVENT_NAMES.CONFIG_RESOLVED,
|
|
209
|
+
'namzu.config.key_count': keyCount,
|
|
210
|
+
'namzu.config.default_count': counts.default,
|
|
211
|
+
'namzu.config.user_file_count': counts['user-file'],
|
|
212
|
+
'namzu.config.project_file_count': counts['project-file'],
|
|
213
|
+
'namzu.config.env_count': counts.env,
|
|
214
|
+
});
|
|
215
|
+
// Per-key debug rows. The value is handed to the logger as JSON text, not
|
|
216
|
+
// hand-masked by key name and not omitted — the record-boundary
|
|
217
|
+
// redaction scan every sink sits behind
|
|
218
|
+
// (`packages/sdk/src/utils/log/redact.ts`) already screens every
|
|
219
|
+
// attribute value for a secret shape, the SAME defence `namzu run`'s
|
|
220
|
+
// stderr gets. A second, bespoke "these key names are secret" table
|
|
221
|
+
// here would duplicate that control and go stale the day a
|
|
222
|
+
// secret-shaped value arrives under a key nobody added to it — exactly
|
|
223
|
+
// the empty, undriven masking table this session already struck once.
|
|
224
|
+
for (const key of Object.keys(provenance)) {
|
|
225
|
+
const source = provenance[key];
|
|
226
|
+
if (!source)
|
|
227
|
+
continue;
|
|
228
|
+
log.debug('config key resolved', {
|
|
229
|
+
[EVENT_NAME_ATTRIBUTE]: BOOT_EVENT_NAMES.CONFIG_RESOLVED,
|
|
230
|
+
'namzu.config.key': key,
|
|
231
|
+
'namzu.config.value': JSON.stringify(config[key]),
|
|
232
|
+
'namzu.config.source': describeConfigSource(source),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// The CLI never calls `registerTelemetry()` on any path today — this is
|
|
236
|
+
// therefore not a probe, it is the honest constant truth of the process
|
|
237
|
+
// that is running. §3.3's falsifiable claim ("every record inside an
|
|
238
|
+
// active span carries traceId/spanId") is what this line resolves the
|
|
239
|
+
// ambiguity for: absence of a trace id reads as "off", stated here,
|
|
240
|
+
// never silently as "dropped".
|
|
241
|
+
log.info('no LoggerProvider/TracerProvider registered; trace_id will be absent from every record this process emits', {
|
|
242
|
+
[EVENT_NAME_ATTRIBUTE]: BOOT_EVENT_NAMES.TELEMETRY_STATUS,
|
|
243
|
+
'namzu.telemetry.registered': false,
|
|
244
|
+
// Session CONTENT export, which is a different question from whether
|
|
245
|
+
// a tracer is registered and is the one an end user cares about: this
|
|
246
|
+
// is the flag that says whether their conversation leaves the machine.
|
|
247
|
+
// Always present, so "off" is a stated fact rather than the absence
|
|
248
|
+
// of a claim.
|
|
249
|
+
//
|
|
250
|
+
// The BOOLEAN only. The disclosure sentence is emitted by `run` at the
|
|
251
|
+
// moment export is actually attached, under this same event name,
|
|
252
|
+
// because that sentence describes what was BUILT — the destination
|
|
253
|
+
// that resolved, the redactors that loaded — and this function is
|
|
254
|
+
// synchronous by design: `doctor` and `login` call it before anything
|
|
255
|
+
// async has happened, and neither of them attaches an export at all.
|
|
256
|
+
'namzu.telemetry.session_export': config.telemetry?.sessionExport !== undefined,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function describeConfigSource(source) {
|
|
260
|
+
switch (source.kind) {
|
|
261
|
+
case 'default':
|
|
262
|
+
return 'default';
|
|
263
|
+
case 'user-file':
|
|
264
|
+
return `user-file ${source.path}`;
|
|
265
|
+
case 'project-file':
|
|
266
|
+
return `project-file ${source.path}`;
|
|
267
|
+
case 'env':
|
|
268
|
+
return `env ${source.variable}`;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
144
271
|
function mapCommanderError(err) {
|
|
145
272
|
switch (err.code) {
|
|
146
273
|
case 'commander.helpDisplayed':
|
|
@@ -154,6 +281,7 @@ function mapCommanderError(err) {
|
|
|
154
281
|
case 'commander.invalidArgument':
|
|
155
282
|
case 'commander.invalidOptionArgument':
|
|
156
283
|
case 'commander.excessArguments':
|
|
284
|
+
case 'commander.conflictingOption':
|
|
157
285
|
return EX_USAGE;
|
|
158
286
|
default:
|
|
159
287
|
return EXIT_INTERNAL_ERROR;
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AA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
|
+
/**
|
|
3
|
+
* `namzu acp` — the agent-client protocol over this process's stdio.
|
|
4
|
+
*
|
|
5
|
+
* This command exists in the same change as the bridge it drives, and that
|
|
6
|
+
* is the point rather than a convenience. `MCPServer` and
|
|
7
|
+
* `ServerStdioTransport` are both exported from this SDK and nothing in the
|
|
8
|
+
* tree ever constructed an `MCPServer`: a complete protocol server with no
|
|
9
|
+
* driver, which reads as a supported feature and is not one. A subprocess
|
|
10
|
+
* test spawns this binary, so removing the registration below fails a test
|
|
11
|
+
* rather than quietly shipping the same shape twice.
|
|
12
|
+
*
|
|
13
|
+
* **stdout belongs to the protocol.** Everything this command prints for a
|
|
14
|
+
* human goes to stderr. The SDK's logger already writes there; what this
|
|
15
|
+
* file must not do is `console.log`, and a test asserts zero non-JSON bytes
|
|
16
|
+
* on the child's stdout under info-level logging.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Bridges the SDK session to the one verb the protocol server needs.
|
|
20
|
+
*
|
|
21
|
+
* `onRunEvent` is a session-level hook and the gateway is per-prompt, so the
|
|
22
|
+
* dispatcher is swapped for the duration of each turn rather than the
|
|
23
|
+
* session being rebuilt. A run event arriving between turns — a late tool
|
|
24
|
+
* result, a background job settling — reaches no client, which is correct:
|
|
25
|
+
* there is no prompt for it to belong to.
|
|
26
|
+
*/
|
|
27
|
+
export declare function runAcpCommand(cwd: string): Promise<number>;
|
|
28
|
+
export declare const acpCommand: CommandDef;
|
|
29
|
+
//# sourceMappingURL=acp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.d.ts","sourceRoot":"","sources":["../../src/commands/acp.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAsB5C;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiHhE;AAED,eAAO,MAAM,UAAU,EAAE,UAIxB,CAAA"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ACPServer, HostCommandRegistry, ServerStdioTransport, ToolRegistry, createToolPresenter, createUserMessage, } from '@namzu/sdk';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { createAgentSession, probeAgentSession } from '../tui/agent.js';
|
|
6
|
+
/** Same read as `cli.ts`'s `--version`: the manifest, never a second copy. */
|
|
7
|
+
function readPackageVersion() {
|
|
8
|
+
try {
|
|
9
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const pkg = JSON.parse(readFileSync(join(here, '..', '..', 'package.json'), 'utf8'));
|
|
11
|
+
return typeof pkg.version === 'string' ? pkg.version : '0.0.0';
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return '0.0.0';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function defaultPrefs(detected) {
|
|
18
|
+
const first = detected[0];
|
|
19
|
+
return first
|
|
20
|
+
? { version: 3, providers: [{ id: first.entry.id }], subagents: { active: [] } }
|
|
21
|
+
: null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `namzu acp` — the agent-client protocol over this process's stdio.
|
|
25
|
+
*
|
|
26
|
+
* This command exists in the same change as the bridge it drives, and that
|
|
27
|
+
* is the point rather than a convenience. `MCPServer` and
|
|
28
|
+
* `ServerStdioTransport` are both exported from this SDK and nothing in the
|
|
29
|
+
* tree ever constructed an `MCPServer`: a complete protocol server with no
|
|
30
|
+
* driver, which reads as a supported feature and is not one. A subprocess
|
|
31
|
+
* test spawns this binary, so removing the registration below fails a test
|
|
32
|
+
* rather than quietly shipping the same shape twice.
|
|
33
|
+
*
|
|
34
|
+
* **stdout belongs to the protocol.** Everything this command prints for a
|
|
35
|
+
* human goes to stderr. The SDK's logger already writes there; what this
|
|
36
|
+
* file must not do is `console.log`, and a test asserts zero non-JSON bytes
|
|
37
|
+
* on the child's stdout under info-level logging.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Bridges the SDK session to the one verb the protocol server needs.
|
|
41
|
+
*
|
|
42
|
+
* `onRunEvent` is a session-level hook and the gateway is per-prompt, so the
|
|
43
|
+
* dispatcher is swapped for the duration of each turn rather than the
|
|
44
|
+
* session being rebuilt. A run event arriving between turns — a late tool
|
|
45
|
+
* result, a background job settling — reaches no client, which is correct:
|
|
46
|
+
* there is no prompt for it to belong to.
|
|
47
|
+
*/
|
|
48
|
+
export async function runAcpCommand(cwd) {
|
|
49
|
+
// The session is built LAZILY, at the first prompt.
|
|
50
|
+
//
|
|
51
|
+
// `initialize` and `session/new` are how a client discovers what this
|
|
52
|
+
// agent is and what it requires, and neither needs a model. Building the
|
|
53
|
+
// session up front made a namzu with no configured credential answer a
|
|
54
|
+
// connection attempt by exiting — an editor extension saw a pipe that
|
|
55
|
+
// closed, with the reason on a stderr nobody was reading. Now it gets a
|
|
56
|
+
// working handshake and a refusal naming the missing credential at the
|
|
57
|
+
// moment it actually matters, which is the first prompt.
|
|
58
|
+
let session;
|
|
59
|
+
let route;
|
|
60
|
+
const ensureSession = async () => {
|
|
61
|
+
if (session)
|
|
62
|
+
return session;
|
|
63
|
+
const probe = await probeAgentSession();
|
|
64
|
+
const prefs = probe.preferences ?? defaultPrefs(probe.detected);
|
|
65
|
+
if (!prefs) {
|
|
66
|
+
throw new Error('No LLM provider is available on this machine: set a credential in the environment, or run `namzu` interactively to pick one. The protocol handshake succeeded; there is nothing to run a prompt with.');
|
|
67
|
+
}
|
|
68
|
+
session = await createAgentSession(prefs, probe.detected, {
|
|
69
|
+
cwd,
|
|
70
|
+
onRunEvent: (event) => route?.(event),
|
|
71
|
+
});
|
|
72
|
+
if (!session.hasProvider) {
|
|
73
|
+
const hint = session.errorHint ?? 'agent is not ready';
|
|
74
|
+
await session.close();
|
|
75
|
+
session = undefined;
|
|
76
|
+
throw new Error(hint);
|
|
77
|
+
}
|
|
78
|
+
return session;
|
|
79
|
+
};
|
|
80
|
+
const gateway = {
|
|
81
|
+
prompt: async ({ prompt, onEvent, signal, ask, history }) => {
|
|
82
|
+
const live = await ensureSession();
|
|
83
|
+
route = onEvent;
|
|
84
|
+
try {
|
|
85
|
+
let stopReason;
|
|
86
|
+
// The client's human, adapted to this session's own permission
|
|
87
|
+
// shape. The mapping is a rename, and it is written out rather
|
|
88
|
+
// than cast so a third outcome added on either side stops
|
|
89
|
+
// compiling here instead of silently becoming an approval.
|
|
90
|
+
const onPermission = async (request) => {
|
|
91
|
+
const outcome = await ask({
|
|
92
|
+
sessionId: 'acp',
|
|
93
|
+
toolCalls: request.toolCalls.map((call) => ({
|
|
94
|
+
id: call.id,
|
|
95
|
+
name: call.name,
|
|
96
|
+
input: call.summary,
|
|
97
|
+
isDestructive: call.isDestructive,
|
|
98
|
+
})),
|
|
99
|
+
});
|
|
100
|
+
switch (outcome.kind) {
|
|
101
|
+
case 'approve':
|
|
102
|
+
return { kind: 'approve' };
|
|
103
|
+
case 'approve_all':
|
|
104
|
+
return { kind: 'approve-all' };
|
|
105
|
+
case 'reject':
|
|
106
|
+
return {
|
|
107
|
+
kind: 'reject',
|
|
108
|
+
...(outcome.feedback ? { feedback: outcome.feedback } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
// Prior turns first, so a resumed session answers with the
|
|
113
|
+
// conversation it actually had rather than as if it were new.
|
|
114
|
+
const messages = [...history, createUserMessage(prompt)];
|
|
115
|
+
for await (const event of live.send(messages, { signal, onPermission })) {
|
|
116
|
+
if (event.kind === 'done')
|
|
117
|
+
stopReason = event.stopReason;
|
|
118
|
+
// An `error` event is a run that FAILED, and the protocol's word
|
|
119
|
+
// for that is a stop reason rather than a JSON-RPC error: the
|
|
120
|
+
// call itself succeeded, and the turn is what went wrong.
|
|
121
|
+
else if (event.kind === 'error')
|
|
122
|
+
stopReason = 'error';
|
|
123
|
+
}
|
|
124
|
+
return stopReason === undefined ? {} : { stopReason };
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
route = undefined;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
const server = new ACPServer({
|
|
132
|
+
transport: new ServerStdioTransport(),
|
|
133
|
+
gateway,
|
|
134
|
+
// The registry, not a list. A host that registers a command later still
|
|
135
|
+
// has it appear, and this file has no place to hard-code one.
|
|
136
|
+
commands: new HostCommandRegistry(),
|
|
137
|
+
presenter: createToolPresenter(new ToolRegistry()),
|
|
138
|
+
agentInfo: { name: 'namzu', version: readPackageVersion() },
|
|
139
|
+
});
|
|
140
|
+
await server.start();
|
|
141
|
+
// Held open until stdin ends. The client owns the lifetime — it spawned
|
|
142
|
+
// this process — so there is no idle timeout to get wrong.
|
|
143
|
+
await new Promise((resolve) => {
|
|
144
|
+
process.stdin.on('end', resolve);
|
|
145
|
+
process.stdin.on('close', resolve);
|
|
146
|
+
});
|
|
147
|
+
await server.stop();
|
|
148
|
+
await session?.close();
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
export const acpCommand = {
|
|
152
|
+
name: 'acp',
|
|
153
|
+
description: "Speak the agent-client protocol over this process's stdio",
|
|
154
|
+
handler: async () => runAcpCommand(process.cwd()),
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=acp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.js","sourceRoot":"","sources":["../../src/commands/acp.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EAET,mBAAmB,EAGnB,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GACjB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,E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oBAAS,CAAC;gBACV,KAAK,GAAG,SAAS,CAAA;YAClB,CAAC;QACF,CAAC;KACD,CAAA;IAED,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC5B,SAAS,EAAE,IAAI,oBAAoB,EAAE;QACrC,OAAO;QACP,wEAAwE;QACxE,8DAA8D;QAC9D,QAAQ,EAAE,IAAI,mBAAmB,EAAE;QACnC,SAAS,EAAE,mBAAmB,CAAC,IAAI,YAAY,EAAE,CAAC;QAClD,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,EAAE;KAC3D,CAAC,CAAA;IAEF,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IAEpB,wEAAwE;IACxE,2DAA2D;IAC3D,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAChC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IACnB,MAAM,OAAO,EAAE,KAAK,EAAE,CAAA;IACtB,OAAO,CAAC,CAAA;AACT,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAe;IACrC,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,2DAA2D;IACxE,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;CACjD,CAAA"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
import type { NamzuCliConfig } from '../config/schema.js';
|
|
1
2
|
import type { CommandDef } from './types.js';
|
|
2
|
-
export declare function runDoctorCommand(args: readonly string[]
|
|
3
|
+
export declare function runDoctorCommand(args: readonly string[],
|
|
4
|
+
/**
|
|
5
|
+
* The invocation's resolved config, for the checks that report on it.
|
|
6
|
+
*
|
|
7
|
+
* Optional so every existing caller and test keeps its one-argument
|
|
8
|
+
* shape; absent means "no config was resolved", which
|
|
9
|
+
* `sessionExportCheck` reads as export being off — the same answer an
|
|
10
|
+
* empty config gives, and the true one for a `doctor` run that never
|
|
11
|
+
* loaded a file.
|
|
12
|
+
*/
|
|
13
|
+
config?: NamzuCliConfig): Promise<number>;
|
|
3
14
|
/**
|
|
4
15
|
* CommandDef adapter for the global registry. Preserves the legacy
|
|
5
16
|
* `runDoctorCommand(args)` signature by forwarding raw arguments unparsed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAKzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAiO5C,wBAAsB,gBAAgB,CACrC,IAAI,EAAE,SAAS,MAAM,EAAE;AACvB;;;;;;;;GAQG;AACH,MAAM,GAAE,cAAmB,GACzB,OAAO,CAAC,MAAM,CAAC,CAsCjB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,UAK3B,CAAA"}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { builtInDoctorChecks } from '../doctor/checks/index.js';
|
|
2
|
+
import { sessionExportCheck } from '../doctor/checks/session-export.js';
|
|
2
3
|
import { createDoctorRegistry, runDoctor } from '../doctor/registry.js';
|
|
3
4
|
import { EXIT_USAGE } from '../exit-codes.js';
|
|
4
5
|
const VALID_CATEGORIES = [
|
|
@@ -205,7 +206,17 @@ function formatHumanReport(report, verbose) {
|
|
|
205
206
|
}
|
|
206
207
|
return lines.join('\n');
|
|
207
208
|
}
|
|
208
|
-
export async function runDoctorCommand(args
|
|
209
|
+
export async function runDoctorCommand(args,
|
|
210
|
+
/**
|
|
211
|
+
* The invocation's resolved config, for the checks that report on it.
|
|
212
|
+
*
|
|
213
|
+
* Optional so every existing caller and test keeps its one-argument
|
|
214
|
+
* shape; absent means "no config was resolved", which
|
|
215
|
+
* `sessionExportCheck` reads as export being off — the same answer an
|
|
216
|
+
* empty config gives, and the true one for a `doctor` run that never
|
|
217
|
+
* loaded a file.
|
|
218
|
+
*/
|
|
219
|
+
config = {}) {
|
|
209
220
|
const parsed = parseArgs(args);
|
|
210
221
|
if (parsed.error) {
|
|
211
222
|
process.stderr.write(`Error: ${parsed.error}\n\n${HELP}\n`);
|
|
@@ -221,6 +232,11 @@ export async function runDoctorCommand(args) {
|
|
|
221
232
|
const registry = createDoctorRegistry();
|
|
222
233
|
for (const check of builtInDoctorChecks)
|
|
223
234
|
registry.register(check);
|
|
235
|
+
// Config-dependent, so it is constructed here rather than sitting in
|
|
236
|
+
// `builtInDoctorChecks`: what it reports is a property of THIS
|
|
237
|
+
// invocation's resolved config, and a check registered without one could
|
|
238
|
+
// only report "unknown", which is the answer nobody runs `doctor` for.
|
|
239
|
+
registry.register(sessionExportCheck(config));
|
|
224
240
|
const opts = {
|
|
225
241
|
registry,
|
|
226
242
|
categories: parsed.categories,
|
|
@@ -244,6 +260,6 @@ export const doctorCommand = {
|
|
|
244
260
|
name: 'doctor',
|
|
245
261
|
description: 'Run health checks against the local Namzu environment',
|
|
246
262
|
passThrough: true,
|
|
247
|
-
handler: async ({ rawArgs }) => runDoctorCommand(rawArgs),
|
|
263
|
+
handler: async ({ rawArgs, ctx }) => runDoctorCommand(rawArgs, ctx.config),
|
|
248
264
|
};
|
|
249
265
|
//# sourceMappingURL=doctor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.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AK,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACvE,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAA;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAe;IACxC,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,uDAAuD;IACpE,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC;CAC1E,CAAA"}
|
package/dist/commands/drain.d.ts
CHANGED
|
@@ -50,8 +50,8 @@ export declare function resolveDrainScope(flags: Pick<DrainFlags, 'tenant' | 'pr
|
|
|
50
50
|
readonly error: string;
|
|
51
51
|
} | {
|
|
52
52
|
readonly tenantId: TenantId;
|
|
53
|
-
readonly projectId
|
|
54
|
-
readonly sessionId
|
|
53
|
+
readonly projectId: ProjectId;
|
|
54
|
+
readonly sessionId: SessionId;
|
|
55
55
|
};
|
|
56
56
|
/** A per-process holder when the operator names none. */
|
|
57
57
|
export declare function defaultHolder(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drain.d.ts","sourceRoot":"","sources":["../../src/commands/drain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;
|
|
1
|
+
{"version":3,"file":"drain.d.ts","sourceRoot":"","sources":["../../src/commands/drain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAWH,OAAO,KAAK,EAAmB,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAOjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAK5C,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,EAAE,CAAA;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAgEtE;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC,GACxF;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1B;IAGA,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;CAC5B,CAoCH;AAED,yDAAyD;AACzD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAcD,eAAO,MAAM,YAAY,EAAE,UA8K1B,CAAA"}
|
package/dist/commands/drain.js
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
* the reading that makes an empty queue indistinguishable from a missing
|
|
22
22
|
* one.
|
|
23
23
|
*/
|
|
24
|
-
import { DiskCheckpointStore, drainRuns } from '@namzu/sdk';
|
|
25
|
-
import { configureLogger } from '@namzu/sdk';
|
|
24
|
+
import { DiskCheckpointStore, InvalidIdError, asProjectId, asSessionId, asTenantId, drainRuns, installProcessSink, } from '@namzu/sdk';
|
|
26
25
|
import { EXIT_UNTRUSTED, EXIT_USAGE } from '../exit-codes.js';
|
|
26
|
+
import { contextLogging, createStderrSink } from '../logging.js';
|
|
27
27
|
import { decideHeadlessTrust } from '../permissions/headless-trust.js';
|
|
28
28
|
import { applyProviderFlags, resolveWorkingDirectory } from './run-flags.js';
|
|
29
29
|
/** Lease length when the operator names none. Long enough for a real turn. */
|
|
@@ -117,11 +117,27 @@ export function resolveDrainScope(flags) {
|
|
|
117
117
|
error: '--project and --session are both required for a disk store: its layout carries no attribution, so it cannot say which project and session the runs it finds belong to.',
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
// Prefix-checked, and refused in THIS function's shape rather than by
|
|
121
|
+
// throwing. Every other bad flag here produces an operator-readable
|
|
122
|
+
// sentence; an `InvalidIdError` escaping to the top level would be the one
|
|
123
|
+
// that arrives as a stack trace. A typo'd `--tenant prj_x` previously
|
|
124
|
+
// reached the store as a TenantId and listed nothing, which reads as "no
|
|
125
|
+
// runs" rather than "wrong flag".
|
|
126
|
+
try {
|
|
127
|
+
return {
|
|
128
|
+
tenantId: asTenantId(flags.tenant),
|
|
129
|
+
projectId: asProjectId(flags.project),
|
|
130
|
+
sessionId: asSessionId(flags.session),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
if (err instanceof InvalidIdError) {
|
|
135
|
+
return {
|
|
136
|
+
error: `${err.message} Check --tenant, --project and --session.`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
125
141
|
}
|
|
126
142
|
/** A per-process holder when the operator names none. */
|
|
127
143
|
export function defaultHolder() {
|
|
@@ -200,7 +216,14 @@ export const drainCommand = {
|
|
|
200
216
|
ctx.formatter.error({ message: trust.message ?? 'folder not trusted' });
|
|
201
217
|
return EXIT_UNTRUSTED;
|
|
202
218
|
}
|
|
203
|
-
|
|
219
|
+
// The CLI owns stderr, not the kernel it drives (LOG-05) — a live sink
|
|
220
|
+
// at the level --verbose/--quiet/NAMZU_LOG_LEVEL named, instead of
|
|
221
|
+
// forcing the level to `silent` via `configureLogger`. `{ replace:
|
|
222
|
+
// true }`: see the identical comment in `run.ts` — a real invocation
|
|
223
|
+
// calls this once, this package's own tests call a handler's more
|
|
224
|
+
// than once per process.
|
|
225
|
+
const logging = contextLogging(ctx);
|
|
226
|
+
installProcessSink(createStderrSink(logging.format), logging.level, { replace: true });
|
|
204
227
|
const { probeAgentSession, createAgentSession } = await import('../tui/agent.js');
|
|
205
228
|
const probe = await probeAgentSession();
|
|
206
229
|
let prefs = probe.preferences ?? defaultPrefs(probe.detected);
|