@dungle-scrubs/harness-cli-normalizer 0.3.0 → 0.4.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 +70 -86
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +23 -5
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config.d.ts +25 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +139 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +25 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/inspect.d.ts.map +1 -1
- package/dist/cli/inspect.js +35 -1
- package/dist/cli/inspect.js.map +1 -1
- package/dist/cli/render.d.ts.map +1 -1
- package/dist/cli/render.js +10 -1
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +134 -4
- package/dist/cli/run.js.map +1 -1
- package/dist/cli.js +2 -1
- package/dist/execution/failure.d.ts +21 -4
- package/dist/execution/failure.d.ts.map +1 -1
- package/dist/execution/failure.js +26 -3
- package/dist/execution/failure.js.map +1 -1
- package/dist/execution/stream-turn.d.ts +7 -1
- package/dist/execution/stream-turn.d.ts.map +1 -1
- package/dist/execution/stream-turn.js +43 -20
- package/dist/execution/stream-turn.js.map +1 -1
- package/dist/interpretation/argv.d.ts +1 -0
- package/dist/interpretation/argv.d.ts.map +1 -1
- package/dist/interpretation/argv.js +13 -19
- package/dist/interpretation/argv.js.map +1 -1
- package/dist/interpretation/hints.d.ts +22 -0
- package/dist/interpretation/hints.d.ts.map +1 -0
- package/dist/interpretation/hints.js +59 -0
- package/dist/interpretation/hints.js.map +1 -0
- package/dist/interpretation/refusal.d.ts +25 -4
- package/dist/interpretation/refusal.d.ts.map +1 -1
- package/dist/interpretation/refusal.js +16 -0
- package/dist/interpretation/refusal.js.map +1 -1
- package/dist/interpretation/resolve-options.d.ts +42 -0
- package/dist/interpretation/resolve-options.d.ts.map +1 -0
- package/dist/interpretation/resolve-options.js +140 -0
- package/dist/interpretation/resolve-options.js.map +1 -0
- package/dist/interpretation/store.js +1 -1
- package/dist/interpretation/support.d.ts +32 -0
- package/dist/interpretation/support.d.ts.map +1 -0
- package/dist/interpretation/support.js +107 -0
- package/dist/interpretation/support.js.map +1 -0
- package/dist/interpretation/tool-selection.d.ts +29 -0
- package/dist/interpretation/tool-selection.d.ts.map +1 -0
- package/dist/interpretation/tool-selection.js +122 -0
- package/dist/interpretation/tool-selection.js.map +1 -0
- package/dist/interpretation/turn-options.d.ts.map +1 -1
- package/dist/interpretation/turn-options.js +4 -0
- package/dist/interpretation/turn-options.js.map +1 -1
- package/dist/knowledge/claude-code.d.ts +2 -2
- package/dist/knowledge/claude-code.d.ts.map +1 -1
- package/dist/knowledge/claude-code.js +37 -4
- package/dist/knowledge/claude-code.js.map +1 -1
- package/dist/knowledge/codex.d.ts.map +1 -1
- package/dist/knowledge/codex.js +19 -0
- package/dist/knowledge/codex.js.map +1 -1
- package/dist/knowledge/descriptor.d.ts +32 -0
- package/dist/knowledge/descriptor.d.ts.map +1 -1
- package/dist/knowledge/muse.d.ts.map +1 -1
- package/dist/knowledge/muse.js +22 -0
- package/dist/knowledge/muse.js.map +1 -1
- package/dist/knowledge/pi.d.ts +1 -1
- package/dist/knowledge/pi.d.ts.map +1 -1
- package/dist/knowledge/pi.js +29 -6
- package/dist/knowledge/pi.js.map +1 -1
- package/dist/knowledge/profile.d.ts +13 -0
- package/dist/knowledge/profile.d.ts.map +1 -0
- package/dist/knowledge/profile.js +31 -0
- package/dist/knowledge/profile.js.map +1 -0
- package/package.json +2 -23
- package/src/cli/args.ts +31 -1
- package/src/cli/config.ts +166 -0
- package/src/cli/index.ts +25 -12
- package/src/cli/inspect.ts +34 -1
- package/src/cli/render.ts +10 -1
- package/src/cli/run.ts +161 -5
- package/src/execution/failure.ts +44 -5
- package/src/execution/stream-turn.ts +43 -14
- package/src/interpretation/argv.ts +14 -19
- package/src/interpretation/hints.ts +99 -0
- package/src/interpretation/refusal.ts +32 -3
- package/src/interpretation/resolve-options.ts +190 -0
- package/src/interpretation/store.ts +1 -1
- package/src/interpretation/support.ts +119 -0
- package/src/interpretation/tool-selection.ts +161 -0
- package/src/interpretation/turn-options.ts +4 -0
- package/src/knowledge/claude-code.ts +37 -4
- package/src/knowledge/codex.ts +19 -0
- package/src/knowledge/descriptor.ts +32 -0
- package/src/knowledge/muse.ts +22 -0
- package/src/knowledge/pi.ts +29 -6
- package/src/knowledge/profile.ts +33 -0
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -1
- package/src/index.ts +0 -7
|
@@ -28,6 +28,7 @@ import type { FailureSummary } from "./failure.js";
|
|
|
28
28
|
import {
|
|
29
29
|
failureFromAuth,
|
|
30
30
|
failureFromLimit,
|
|
31
|
+
failureFromNative,
|
|
31
32
|
failureFromRejected,
|
|
32
33
|
failureFromTransport,
|
|
33
34
|
reduceFailures,
|
|
@@ -55,13 +56,18 @@ const SECRETISH = /(sk-[A-Za-z0-9_-]{8,}|(?:token|key|secret|password)=\S+)/i;
|
|
|
55
56
|
|
|
56
57
|
/** Redact by POSITION, not shape: the prompt is a known argv slot and is
|
|
57
58
|
* masked wholesale (content never reaches a log line - v1 D-005); every
|
|
58
|
-
* other token is kept unless it is secret-shaped.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
* other token is kept unless it is secret-shaped. Only the prompt's
|
|
60
|
+
* positional slot is masked, so a one-word prompt that equals a flag
|
|
61
|
+
* value does not cause that flag value to be masked. */
|
|
62
|
+
export const redactArgv = (argv: readonly string[], prompt?: string): string[] => {
|
|
63
|
+
const promptIndex = prompt !== undefined ? argv.lastIndexOf(prompt) : -1;
|
|
64
|
+
const promptLabel = prompt !== undefined ? `[prompt:${prompt.length}ch]` : "";
|
|
65
|
+
return argv.map((token, index) => {
|
|
66
|
+
if (index === promptIndex) return promptLabel;
|
|
62
67
|
if (SECRETISH.test(token)) return "[redacted]";
|
|
63
68
|
return token;
|
|
64
69
|
});
|
|
70
|
+
};
|
|
65
71
|
|
|
66
72
|
/** Bounded tail of unmatched stderr - the crash context a nonzero exit is
|
|
67
73
|
* explained by (v1 kept the turn's output slice for exactly this). Shared
|
|
@@ -91,6 +97,10 @@ export interface TurnRunOptions extends LaunchOptions {
|
|
|
91
97
|
readonly cwd?: string;
|
|
92
98
|
/** Per-call environment, merged over parent; "" deletes. */
|
|
93
99
|
readonly env?: Readonly<Record<string, string>>;
|
|
100
|
+
/** D6 passthrough: raw harness tokens appended verbatim after the
|
|
101
|
+
* normalized argv. Wrong-harness flags here fail in the harness itself
|
|
102
|
+
* and surface as native errors - hcn never validates them. */
|
|
103
|
+
readonly passthrough?: readonly string[];
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
export async function* streamTurn(
|
|
@@ -139,6 +149,9 @@ export async function* streamTurn(
|
|
|
139
149
|
opts.resume === undefined
|
|
140
150
|
? buildLaunchArgv(h, opts)
|
|
141
151
|
: buildResumeArgv(h, { ...opts, sessionId: opts.resume });
|
|
152
|
+
if (opts.passthrough !== undefined && opts.passthrough.length > 0) {
|
|
153
|
+
argv = [...argv, "--", ...opts.passthrough];
|
|
154
|
+
}
|
|
142
155
|
granularity = streamingGranularityOf(h, argv);
|
|
143
156
|
} catch (e) {
|
|
144
157
|
if (e instanceof ArgvRefusalError) {
|
|
@@ -147,6 +160,8 @@ export async function* streamTurn(
|
|
|
147
160
|
option: e.option,
|
|
148
161
|
facet: e.facet,
|
|
149
162
|
supported: e.supported,
|
|
163
|
+
supportedBy: e.supportedBy,
|
|
164
|
+
hint: e.hint,
|
|
150
165
|
detail: e.message,
|
|
151
166
|
});
|
|
152
167
|
// No process spawned on a refusal - log rejected instead of spawn
|
|
@@ -356,8 +371,7 @@ export async function* streamTurn(
|
|
|
356
371
|
if (auth !== null) {
|
|
357
372
|
const failure = failureFromAuth(auth);
|
|
358
373
|
await pushFailure(failure);
|
|
359
|
-
//
|
|
360
|
-
// Keep error for 0.1.3 compat as well
|
|
374
|
+
// Emit error alongside failure for 0.1.3 compat
|
|
361
375
|
await queue.push({ kind: "error", message: `auth wall: ${auth}` });
|
|
362
376
|
continue;
|
|
363
377
|
}
|
|
@@ -396,7 +410,12 @@ export async function* streamTurn(
|
|
|
396
410
|
try {
|
|
397
411
|
for await (const event of queue) yield event;
|
|
398
412
|
|
|
399
|
-
// Post-queue failure sources
|
|
413
|
+
// Post-queue failure sources. Nonzero exit with no other failure and a
|
|
414
|
+
// non-empty stderr tail is a NATIVE failure (D6): the harness rejected
|
|
415
|
+
// its own arguments or crashed on them - verbatim stderr, native exit
|
|
416
|
+
// code as data, hcn exit 1. Without a stderr tail it stays transport
|
|
417
|
+
// (a silent nonzero exit reads as an environment problem, not a
|
|
418
|
+
// harness judgment).
|
|
400
419
|
if (
|
|
401
420
|
failures.length === 0 &&
|
|
402
421
|
exitCode !== 0 &&
|
|
@@ -404,7 +423,11 @@ export async function* streamTurn(
|
|
|
404
423
|
!killedByWatchdog &&
|
|
405
424
|
!state.limitSeen
|
|
406
425
|
) {
|
|
407
|
-
const
|
|
426
|
+
const tailForNative = stderrTail.snapshot();
|
|
427
|
+
const f =
|
|
428
|
+
tailForNative.length > 0
|
|
429
|
+
? failureFromNative(exitCode, tailForNative)
|
|
430
|
+
: failureFromTransport(`nonzero exit ${exitCode}`);
|
|
408
431
|
failures.push(f);
|
|
409
432
|
// Need to emit this failure before done, even though queue is closed
|
|
410
433
|
yield { kind: "failure", ...f };
|
|
@@ -427,11 +450,6 @@ export async function* streamTurn(
|
|
|
427
450
|
: "crash";
|
|
428
451
|
const reduced = reduceFailures(failures);
|
|
429
452
|
if (reduced && cause === "clean") cause = "failed";
|
|
430
|
-
// Also handle pi stopReason error at exit 0 yielding failed - if we have a failure and exit 0, ensure cause is failed
|
|
431
|
-
if (reduced && exitCode === 0 && cause !== "limit" && cause !== "stall") {
|
|
432
|
-
// If we have any failure at exit 0, the cause should be failed, not clean
|
|
433
|
-
if (cause === "clean") cause = "failed";
|
|
434
|
-
}
|
|
435
453
|
const tail = stderrTail.snapshot();
|
|
436
454
|
log({
|
|
437
455
|
event: "exit",
|
|
@@ -452,7 +470,18 @@ export async function* streamTurn(
|
|
|
452
470
|
yield { kind: "error", message: tail.join("\n").slice(0, 4096) };
|
|
453
471
|
}
|
|
454
472
|
terminalEventReached = true;
|
|
455
|
-
|
|
473
|
+
// D6: when the failure is native, the harness's own exit convention is
|
|
474
|
+
// DATA (nativeExitCode on the failure), not the done event's contract -
|
|
475
|
+
// hcn owns the process exit code (1 for any native failure) because
|
|
476
|
+
// harness conventions collide with hcn's (codex usage errors exit 2,
|
|
477
|
+
// which hcn reserves for refusals).
|
|
478
|
+
const nativeReduced = reduced?.class === "native";
|
|
479
|
+
yield {
|
|
480
|
+
kind: "done",
|
|
481
|
+
exitCode: nativeReduced ? null : exitCode,
|
|
482
|
+
cause,
|
|
483
|
+
...(reduced ? { failure: reduced } : {}),
|
|
484
|
+
};
|
|
456
485
|
} finally {
|
|
457
486
|
const abandoned = !terminalEventReached;
|
|
458
487
|
cancelled = true;
|
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* no caller re-derives them.
|
|
6
6
|
*/
|
|
7
7
|
import type { HarnessDescriptor, StreamingGranularity } from "../knowledge/descriptor.js";
|
|
8
|
+
import { defaultDescriptors } from "../knowledge/overrides.js";
|
|
8
9
|
import { ArgvRefusalError } from "./refusal.js";
|
|
9
10
|
import { assertUsableSessionId } from "./session-id.js";
|
|
11
|
+
import { supportedBy } from "./support.js";
|
|
12
|
+
import { renderToolSelection } from "./tool-selection.js";
|
|
10
13
|
import { renderTurnOptions } from "./turn-options.js";
|
|
11
14
|
import { validateModel } from "./vocabulary.js";
|
|
12
15
|
|
|
@@ -50,6 +53,7 @@ export interface DiscoveryOptions {
|
|
|
50
53
|
export interface TurnOptions {
|
|
51
54
|
readonly prompt: string;
|
|
52
55
|
readonly tools?: readonly string[];
|
|
56
|
+
readonly excludeTools?: readonly string[];
|
|
53
57
|
readonly model?: string;
|
|
54
58
|
readonly autonomy?: boolean;
|
|
55
59
|
readonly effort?: string;
|
|
@@ -90,32 +94,23 @@ const turnTail = (h: HarnessDescriptor, opts: TurnOptions): string[] => {
|
|
|
90
94
|
}
|
|
91
95
|
if (opts.autonomy === true) {
|
|
92
96
|
if (h.autonomy === null) {
|
|
97
|
+
const by = supportedBy(defaultDescriptors(), "autonomy");
|
|
93
98
|
throw new ArgvRefusalError({
|
|
94
99
|
issue: "no-autonomy-mode",
|
|
95
100
|
harness: h.name,
|
|
96
|
-
supported:
|
|
101
|
+
supported: by.map((e) => `${e.harness} ${e.spelling}`),
|
|
102
|
+
supportedBy: by,
|
|
103
|
+
hint: "pi has no unattended-run flag; approximate with a per-tool allowlist (--tools read,bash) if you need unattended behavior on pi",
|
|
97
104
|
});
|
|
98
105
|
}
|
|
99
106
|
tail.push(h.autonomy.flag);
|
|
100
107
|
}
|
|
101
|
-
if (opts.tools !== undefined) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
detail: "tools",
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (opts.tools.length === 0 || opts.tools.some((t) => t.trim() === "" || t.includes(","))) {
|
|
111
|
-
throw new ArgvRefusalError({
|
|
112
|
-
issue: "invalid-tool-grant",
|
|
113
|
-
harness: h.name,
|
|
114
|
-
supported: ["non-empty, comma-free tool names"],
|
|
115
|
-
detail: `tools=${JSON.stringify(opts.tools)}`,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
tail.push(h.launch.toolsFlag, opts.tools.join(","));
|
|
108
|
+
if (opts.tools !== undefined || opts.excludeTools !== undefined) {
|
|
109
|
+
const rendered = renderToolSelection(h, {
|
|
110
|
+
include: opts.tools,
|
|
111
|
+
exclude: opts.excludeTools,
|
|
112
|
+
});
|
|
113
|
+
tail.push(...rendered.tokens);
|
|
119
114
|
}
|
|
120
115
|
return tail;
|
|
121
116
|
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated refusal hints (D8), confirmed in review 2026-08-18
|
|
3
|
+
* (test/fixtures/phase0/hints-confirmed.md is the durable record). A hint
|
|
4
|
+
* is the nearest-alternative control for the CURRENT harness, shown before
|
|
5
|
+
* the cross-harness support list so a scanning caller meets the
|
|
6
|
+
* stay-on-harness suggestion first. Wording is locked verbatim; unit tests
|
|
7
|
+
* pin every string.
|
|
8
|
+
*/
|
|
9
|
+
import type { HarnessDescriptor } from "../knowledge/descriptor.js";
|
|
10
|
+
import type { RefusalOption } from "./refusal.js";
|
|
11
|
+
|
|
12
|
+
const HINTS: Readonly<Record<string, Readonly<Record<string, string>>>> = deepFreezeSafe({
|
|
13
|
+
claude: {
|
|
14
|
+
sandbox:
|
|
15
|
+
"claude has no sandbox modes; approximate with a per-tool allowlist (--tools Read,Bash) or --disallowedTools to keep tools out, and run untrusted work in a disposable directory or container",
|
|
16
|
+
write:
|
|
17
|
+
"claude has no write toggle; keep the Write tool out with --tools that omits it, or --disallowedTools Write for the deny-complement spelling",
|
|
18
|
+
shell:
|
|
19
|
+
"claude has no shell toggle; disallow the Bash tool (--tools without Bash, or --disallowedTools Bash) and note Monitor can still run commands in headless runs",
|
|
20
|
+
maxSteps:
|
|
21
|
+
"claude has no step cap flag; bound the work in the prompt (task size, 'stop after N operations') or impose a wall-clock timeout at the caller",
|
|
22
|
+
provider:
|
|
23
|
+
"claude routes models through Anthropic only (Bedrock/Vertex via settings); use --model to pick within it - there is no separate provider selector",
|
|
24
|
+
"discovery.tools":
|
|
25
|
+
"claude has no tools-discovery toggle (tools are always compiled in); shape the tool set with --tools/--disallowedTools instead",
|
|
26
|
+
"discovery.instructionFiles":
|
|
27
|
+
"claude has no isolated instruction-file toggle; --setting-sources project isolates from user-level settings but also skips hooks, LSP and keychain reads - weigh that before using it as an approximation",
|
|
28
|
+
},
|
|
29
|
+
codex: {
|
|
30
|
+
write:
|
|
31
|
+
"codex has no write toggle; use --sandbox read-only (config: sandbox_mode) so shell commands cannot write either",
|
|
32
|
+
shell:
|
|
33
|
+
"codex has no shell toggle; disable the shell tool via config (-c features.shell_tool=false) or use --sandbox read-only",
|
|
34
|
+
maxSteps:
|
|
35
|
+
"codex has no step cap flag; bound via sandbox policy and a caller-side timeout, or prompt-level limits",
|
|
36
|
+
provider:
|
|
37
|
+
"codex routes models through OpenAI (or --oss for local); use --model to pick within it - there is no separate provider selector",
|
|
38
|
+
"discovery.tools":
|
|
39
|
+
"codex has no tools-discovery toggle; disable tool classes via config keys (features.shell_tool, web_search) instead",
|
|
40
|
+
"discovery.instructionFiles":
|
|
41
|
+
"codex always loads AGENTS.md hierarchy; no per-call toggle exists - keep the files out of the tree or work from a directory without them",
|
|
42
|
+
"discovery.extensions":
|
|
43
|
+
"codex loads MCP servers and plugins from config; disable per-server with -c or codex mcp remove rather than a call-time toggle",
|
|
44
|
+
"discovery.skills":
|
|
45
|
+
"codex discovers skills from its skills directory; no call-time toggle - remove or move the skill files instead",
|
|
46
|
+
},
|
|
47
|
+
pi: {
|
|
48
|
+
sandbox:
|
|
49
|
+
"pi has no sandbox dimension; approximate with a minimal tool grant (--tools read,grep,find,ls) so the run cannot write or execute, or sandbox the process yourself (container, VM)",
|
|
50
|
+
write:
|
|
51
|
+
"pi has no write toggle; grant without the write tool (--tools read,bash,edit) or use --exclude-tools write",
|
|
52
|
+
shell:
|
|
53
|
+
"pi has no shell toggle; grant without the bash tool (--tools read,edit,write) or use --exclude-tools bash",
|
|
54
|
+
maxSteps:
|
|
55
|
+
"pi has no step cap flag; bound the work in the prompt or impose a wall-clock timeout at the caller",
|
|
56
|
+
},
|
|
57
|
+
muse: {
|
|
58
|
+
sandbox:
|
|
59
|
+
"muse's sandbox is on by default and not selectable per-call; --disable-sandbox exists to turn it OFF, and exposure can be tuned with --disable-write, --disable-shell, --disable-web-tools - there is no mode selector",
|
|
60
|
+
provider:
|
|
61
|
+
"muse routes models through its own API; use --model to pick within it - there is no separate provider selector",
|
|
62
|
+
"discovery.tools":
|
|
63
|
+
"muse has no tools-discovery toggle; gate execution with --disable-write/--disable-shell/--disable-web-tools",
|
|
64
|
+
"discovery.instructionFiles":
|
|
65
|
+
"muse loads rules per workspace trust; --no-foreign-personal-context excludes foreign personal rules, and withholding --trust-workspace keeps workspace rules unloaded",
|
|
66
|
+
"discovery.skills":
|
|
67
|
+
"muse scopes skills by trust like rules; --no-foreign-personal-context drops foreign skills and untrusted workspaces stay unloaded - there is no unconditional skills-off switch",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/** deepFreeze without importing the descriptor's (which carries extra
|
|
72
|
+
* machinery); structure is plain JSON so Object.freeze all the way down. */
|
|
73
|
+
function deepFreezeSafe<T>(value: T): T {
|
|
74
|
+
if (typeof value === "object" && value !== null) {
|
|
75
|
+
for (const v of Object.values(value as Record<string, unknown>)) deepFreezeSafe(v);
|
|
76
|
+
Object.freeze(value);
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The confirmed hint for a refused option on a harness, or undefined. */
|
|
82
|
+
export const hintFor = (harness: string, option: RefusalOption): string | undefined =>
|
|
83
|
+
HINTS[harness]?.[option];
|
|
84
|
+
|
|
85
|
+
/** All hints - for the unit test that pins every string against the
|
|
86
|
+
* evidence file's count. */
|
|
87
|
+
export const allHints = (): ReadonlyArray<{ harness: string; option: string; text: string }> => {
|
|
88
|
+
const out: { harness: string; option: string; text: string }[] = [];
|
|
89
|
+
for (const [harness, table] of Object.entries(HINTS)) {
|
|
90
|
+
for (const [option, text] of Object.entries(table)) out.push({ harness, option, text });
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** Convenience for raise sites that already hold the descriptor. */
|
|
96
|
+
export const hintForDescriptor = (
|
|
97
|
+
h: HarnessDescriptor,
|
|
98
|
+
option: RefusalOption,
|
|
99
|
+
): string | undefined => hintFor(h.name, option);
|
|
@@ -17,19 +17,32 @@ export const REFUSAL_ISSUES = deepFreeze([
|
|
|
17
17
|
"unknown-model",
|
|
18
18
|
"invalid-env",
|
|
19
19
|
"invalid-tool-grant",
|
|
20
|
+
"unknown-tool-name",
|
|
21
|
+
"mutually-exclusive-options",
|
|
20
22
|
"prompt-flag-injection",
|
|
21
23
|
"no-autonomy-mode",
|
|
22
24
|
"no-session-mode",
|
|
23
25
|
] as const);
|
|
24
26
|
export type RefusalIssue = (typeof REFUSAL_ISSUES)[number];
|
|
25
27
|
|
|
28
|
+
/** The option a refusal names: turn-option spec keys (descriptor tables)
|
|
29
|
+
* plus the tool-list dimensions and autonomy, which render via dedicated
|
|
30
|
+
* descriptor fields rather than a spec table. Kept closed so consumers can
|
|
31
|
+
* branch on it without a default arm. */
|
|
32
|
+
export type RefusalOption =
|
|
33
|
+
| TurnOptionKey
|
|
34
|
+
| "tools"
|
|
35
|
+
| "excludeTools"
|
|
36
|
+
| "autonomy"
|
|
37
|
+
| `discovery.${string}`;
|
|
38
|
+
|
|
26
39
|
/** One helper builds the message from the structured fields so message and
|
|
27
40
|
* fields cannot drift. Every message names an alternative, not only a
|
|
28
41
|
* negation, so an agent can pivot without reading the descriptor. */
|
|
29
42
|
export const buildRefusalMessage = (
|
|
30
43
|
issue: RefusalIssue,
|
|
31
44
|
harness: HarnessName,
|
|
32
|
-
option?:
|
|
45
|
+
option?: RefusalOption,
|
|
33
46
|
facet?: DiscoveryFacet,
|
|
34
47
|
supported: readonly string[] = [],
|
|
35
48
|
detail?: string,
|
|
@@ -66,6 +79,10 @@ export const buildRefusalMessage = (
|
|
|
66
79
|
return `invalid env key or value for ${harness}${detailSuffix}; ${supportedStr} - keys must match ^[A-Za-z_][A-Za-z0-9_]*$ and contain no NUL`;
|
|
67
80
|
case "invalid-tool-grant":
|
|
68
81
|
return `tool grant for ${harness} contains an empty entry or a comma; a blank tool flag value grants nothing detectable, and a comma inside one name silently splits the grant; ${supportedStr} - provide comma-free, non-empty tool names as separate entries`;
|
|
82
|
+
case "unknown-tool-name":
|
|
83
|
+
return `${harness} cannot compute a tool complement around an unknown name${detailSuffix}; ${supportedStr} - exclude only curated names, or pass the unknown name through an include list instead`;
|
|
84
|
+
case "mutually-exclusive-options":
|
|
85
|
+
return `${harness} cannot combine${optionPart}${detailSuffix}; ${supportedStr} - pass exactly one of them`;
|
|
69
86
|
case "prompt-flag-injection":
|
|
70
87
|
return `positional prompt may not start with '-'; it would be parsed as a flag by ${harness}${detailSuffix}; ${supportedStr} - remove leading '-' or prefix with a space`;
|
|
71
88
|
case "no-autonomy-mode":
|
|
@@ -83,15 +100,25 @@ export const buildRefusalMessage = (
|
|
|
83
100
|
export class ArgvRefusalError extends Error {
|
|
84
101
|
readonly issue: RefusalIssue;
|
|
85
102
|
readonly harness: HarnessName;
|
|
86
|
-
readonly option?:
|
|
103
|
+
readonly option?: RefusalOption;
|
|
87
104
|
readonly facet?: DiscoveryFacet;
|
|
88
105
|
readonly supported: readonly string[];
|
|
106
|
+
/** D7: which harnesses DO express the refused option, native spellings
|
|
107
|
+
* included. Derived by the raise site from descriptors - absent when the
|
|
108
|
+
* refusing layer has no descriptor set in scope. */
|
|
109
|
+
readonly supportedBy?: ReadonlyArray<{ harness: string; spelling: string }>;
|
|
110
|
+
/** D8: nearest-alternative suggestion for the CURRENT harness - keeps a
|
|
111
|
+
* scanning agent on its chosen harness instead of switching. Curatorial
|
|
112
|
+
* data set at the raise site; absent when no hint exists. */
|
|
113
|
+
readonly hint?: string;
|
|
89
114
|
constructor(args: {
|
|
90
115
|
readonly issue: RefusalIssue;
|
|
91
116
|
readonly harness: HarnessName;
|
|
92
|
-
readonly option?:
|
|
117
|
+
readonly option?: RefusalOption;
|
|
93
118
|
readonly facet?: DiscoveryFacet;
|
|
94
119
|
readonly supported?: readonly string[];
|
|
120
|
+
readonly supportedBy?: ReadonlyArray<{ harness: string; spelling: string }>;
|
|
121
|
+
readonly hint?: string;
|
|
95
122
|
readonly detail?: string;
|
|
96
123
|
readonly message?: string;
|
|
97
124
|
}) {
|
|
@@ -112,5 +139,7 @@ export class ArgvRefusalError extends Error {
|
|
|
112
139
|
this.option = args.option;
|
|
113
140
|
this.facet = args.facet;
|
|
114
141
|
this.supported = args.supported ?? [];
|
|
142
|
+
this.supportedBy = args.supportedBy;
|
|
143
|
+
this.hint = args.hint;
|
|
115
144
|
}
|
|
116
145
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Option resolution: the precedence chain args > user config > built-in
|
|
3
|
+
* profile, plus provenance. Pure - the config FILE is read by the CLI layer
|
|
4
|
+
* and passed in as data; this layer only decides what wins.
|
|
5
|
+
*
|
|
6
|
+
* Launch-only: callers apply resolved options on launch, never resume (a
|
|
7
|
+
* resumed session keeps its session's settings - same rule the codex
|
|
8
|
+
* sandbox default already follows).
|
|
9
|
+
*/
|
|
10
|
+
import type { HarnessDescriptor } from "../knowledge/descriptor.js";
|
|
11
|
+
import { DEFAULT_TURN_PROFILE, type ProfileKey } from "../knowledge/profile.js";
|
|
12
|
+
import type { TurnOptions } from "./argv.js";
|
|
13
|
+
|
|
14
|
+
export type ProvenanceTier = "arg" | "project-config" | "user-config" | "profile" | "harness";
|
|
15
|
+
|
|
16
|
+
export interface ProvenanceEntry {
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly value: unknown;
|
|
19
|
+
readonly tier: ProvenanceTier;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** D5: the project floor caps arg grants; exceeding it refuses naming both
|
|
23
|
+
* sets. Structured-first: fields, not prose parsing. */
|
|
24
|
+
export class FloorExceededError extends Error {
|
|
25
|
+
readonly harness: string;
|
|
26
|
+
readonly excess: readonly string[];
|
|
27
|
+
readonly floor: readonly string[];
|
|
28
|
+
constructor(harness: string, excess: readonly string[], floor: readonly string[]) {
|
|
29
|
+
super(
|
|
30
|
+
`tool grant exceeds the project floor: ${JSON.stringify(excess)} not in floor ${JSON.stringify(floor)} - request a grant within the floor or raise the floor in the project config`,
|
|
31
|
+
);
|
|
32
|
+
this.name = "FloorExceededError";
|
|
33
|
+
this.harness = harness;
|
|
34
|
+
this.excess = excess;
|
|
35
|
+
this.floor = floor;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ResolvedOptions {
|
|
40
|
+
readonly options: TurnOptions;
|
|
41
|
+
readonly provenance: readonly ProvenanceEntry[];
|
|
42
|
+
/** Profile dimensions this harness cannot express (skip-and-report,
|
|
43
|
+
* never refuse): rendered as divergence, not failure. */
|
|
44
|
+
readonly unrenderable: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Expressibility per profile dimension. Dimensions whose "on" state is
|
|
48
|
+
* the harness's own default (discovery all-on) or whose "off" state emits
|
|
49
|
+
* nothing (autonomy false) are expressible EVERYWHERE - the profile value
|
|
50
|
+
* resolves to "emit nothing," which every harness can do. Divergence is
|
|
51
|
+
* reserved for dimensions that would emit a flag the harness lacks. */
|
|
52
|
+
const EXPRESSIBLE: Readonly<Record<ProfileKey, (h: HarnessDescriptor) => boolean>> = {
|
|
53
|
+
effort: (h) => h.turnOptions.effort !== undefined,
|
|
54
|
+
sandbox: (h) => h.turnOptions.sandbox !== undefined,
|
|
55
|
+
discovery: () => true,
|
|
56
|
+
autonomy: () => true,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export interface ConfigTiers {
|
|
60
|
+
/** ~/.config/hcn/config.json (XDG) - machine-wide defaults. */
|
|
61
|
+
readonly user?: Readonly<Partial<TurnOptions>>;
|
|
62
|
+
/** <git-root>/.hcn/config.json - auto-discovered (ratified A), the ALL-
|
|
63
|
+
* OFF tier; its `tools` key is both the default grant and the FLOOR: an
|
|
64
|
+
* arg grant exceeding it refuses, naming both sets (D5). */
|
|
65
|
+
readonly project?: Readonly<Partial<TurnOptions>>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Merge semantics (gap 1, resolved): config keys are scalars and lists in
|
|
69
|
+
* schema v1 - there is nothing to deep-merge INTO - so precedence is whole-
|
|
70
|
+
* key replacement: arg > project > user > profile. A future nested key
|
|
71
|
+
* (per-harness sections) ships with schema v2 and its own merge rule. */
|
|
72
|
+
const effectiveConfig = (tiers: ConfigTiers): Readonly<Partial<TurnOptions>> => ({
|
|
73
|
+
...(tiers.user ?? {}),
|
|
74
|
+
...(tiers.project ?? {}),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/** Resolve the effective options for a LAUNCH. `args` is what the caller
|
|
78
|
+
* passed explicitly (highest tier); `userConfig` the parsed config file;
|
|
79
|
+
* the profile is the floor. Keys absent everywhere defer to the harness
|
|
80
|
+
* and are reported with tier "harness" only when something (config or
|
|
81
|
+
* profile) attempted them - a truly untouched dimension is nobody's
|
|
82
|
+
* business and appears in provenance as tier "harness" with no value. */
|
|
83
|
+
/** A discovery value emits nothing when every facet is true (on). */
|
|
84
|
+
const emitsNothing = (value: unknown): boolean =>
|
|
85
|
+
typeof value === "object" &&
|
|
86
|
+
value !== null &&
|
|
87
|
+
Object.values(value as Record<string, unknown>).every((v) => v === true);
|
|
88
|
+
|
|
89
|
+
export const resolveEffectiveOptions = (
|
|
90
|
+
h: HarnessDescriptor,
|
|
91
|
+
args: TurnOptions,
|
|
92
|
+
tiers: ConfigTiers = {},
|
|
93
|
+
): ResolvedOptions => {
|
|
94
|
+
const provenance: ProvenanceEntry[] = [];
|
|
95
|
+
const unrenderable: string[] = [];
|
|
96
|
+
const config = effectiveConfig(tiers);
|
|
97
|
+
const sourceTier = (key: string): ProvenanceTier | undefined => {
|
|
98
|
+
if (tiers.project?.[key as keyof TurnOptions] !== undefined) return "project-config";
|
|
99
|
+
if (tiers.user?.[key as keyof TurnOptions] !== undefined) return "user-config";
|
|
100
|
+
return undefined;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// D5 toolset expansion: a bare --tools name matching a configured
|
|
104
|
+
// toolset resolves to its list BEFORE the floor check, so a named set
|
|
105
|
+
// within the floor passes and one exceeding it refuses naming the set's
|
|
106
|
+
// members. Project toolsets win name collisions over user toolsets.
|
|
107
|
+
const toolsets = {
|
|
108
|
+
...((tiers.user as { toolsets?: Record<string, string[]> } | undefined)?.toolsets ?? {}),
|
|
109
|
+
...((tiers.project as { toolsets?: Record<string, string[]> } | undefined)?.toolsets ?? {}),
|
|
110
|
+
};
|
|
111
|
+
let effectiveArgs = args;
|
|
112
|
+
if (
|
|
113
|
+
args.tools !== undefined &&
|
|
114
|
+
args.tools.length === 1 &&
|
|
115
|
+
toolsets[args.tools[0] as string] !== undefined
|
|
116
|
+
) {
|
|
117
|
+
effectiveArgs = { ...args, tools: toolsets[args.tools[0] as string] };
|
|
118
|
+
provenance.push({
|
|
119
|
+
key: "tools",
|
|
120
|
+
value: effectiveArgs.tools,
|
|
121
|
+
tier: "arg",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const resolved: Record<string, unknown> = { ...effectiveArgs };
|
|
125
|
+
|
|
126
|
+
// D5 floor: a project toolset floor caps any arg grant; exceeding it is
|
|
127
|
+
// a structured refusal naming both sets - never a silent clamp.
|
|
128
|
+
const floor = tiers.project?.tools;
|
|
129
|
+
if (floor !== undefined && effectiveArgs.tools !== undefined) {
|
|
130
|
+
const floorSet = new Set(floor);
|
|
131
|
+
const excess = effectiveArgs.tools.filter((t) => !floorSet.has(t));
|
|
132
|
+
if (excess.length > 0) {
|
|
133
|
+
throw new FloorExceededError(h.name, excess, [...floor]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Profile is the floor: apply only where nothing above it set the key.
|
|
138
|
+
for (const [key, value] of Object.entries(DEFAULT_TURN_PROFILE)) {
|
|
139
|
+
const argsSet = effectiveArgs[key as keyof TurnOptions] !== undefined;
|
|
140
|
+
const tier = sourceTier(key);
|
|
141
|
+
if (argsSet) {
|
|
142
|
+
provenance.push({ key, value: effectiveArgs[key as keyof TurnOptions], tier: "arg" });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (tier !== undefined) {
|
|
146
|
+
provenance.push({ key, value: config[key as keyof TurnOptions], tier });
|
|
147
|
+
resolved[key] = config[key as keyof TurnOptions];
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const expressible = EXPRESSIBLE[key as ProfileKey]?.(h) ?? false;
|
|
151
|
+
if (!expressible) {
|
|
152
|
+
// Skip-and-report: a profile default this harness cannot express is
|
|
153
|
+
// reported divergence, never a refusal and never silence.
|
|
154
|
+
unrenderable.push(key);
|
|
155
|
+
provenance.push({ key, value, tier: "harness" });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
// Dimensions whose value reduces to "emit nothing" (autonomy false,
|
|
159
|
+
// discovery all-on) stay ABSENT from the resolved options - the
|
|
160
|
+
// harness's default already satisfies the profile, and emitting
|
|
161
|
+
// explicit on-flags would change resume grammar and add breakage
|
|
162
|
+
// surface for no semantic gain. Provenance still records the tier.
|
|
163
|
+
if ((key === "autonomy" && value === false) || (key === "discovery" && emitsNothing(value))) {
|
|
164
|
+
provenance.push({ key, value, tier: "profile" });
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
resolved[key] = value;
|
|
168
|
+
provenance.push({ key, value, tier: "profile" });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Config keys outside the profile surface pass through at their own tier
|
|
172
|
+
// (validated later by the same renderers as args).
|
|
173
|
+
for (const [key, value] of Object.entries(config)) {
|
|
174
|
+
if (key === "toolsets") continue; // expanded into args above, never a turn option
|
|
175
|
+
if (key in DEFAULT_TURN_PROFILE) continue;
|
|
176
|
+
if (effectiveArgs[key as keyof TurnOptions] !== undefined) {
|
|
177
|
+
provenance.push({ key, value: effectiveArgs[key as keyof TurnOptions], tier: "arg" });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
resolved[key] = value;
|
|
181
|
+
const tier = sourceTier(key) ?? "user-config";
|
|
182
|
+
provenance.push({ key, value, tier });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
options: resolved as unknown as TurnOptions,
|
|
187
|
+
provenance,
|
|
188
|
+
unrenderable,
|
|
189
|
+
};
|
|
190
|
+
};
|
|
@@ -21,7 +21,7 @@ const slugFor = (h: HarnessDescriptor, cwd: string): string => {
|
|
|
21
21
|
case "dash-separators":
|
|
22
22
|
return normalized.replace(/[/.]/g, "-");
|
|
23
23
|
case "pi-dash-wrapped":
|
|
24
|
-
// pi 0.84.
|
|
24
|
+
// pi 0.84.2, verified on-disk: leading slash stripped, '/' -> '-',
|
|
25
25
|
// dots preserved, wrapped in double dashes:
|
|
26
26
|
// /Users/kevin/dev/x -> --Users-kevin-dev-x--
|
|
27
27
|
return `--${normalized.replace(/^\//, "").replace(/\//g, "-")}--`;
|