architecture-harness 0.25.0 → 0.26.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/package.json +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +53 -0
- package/src/plugin.test.mjs +3 -2
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
|
@@ -48,6 +48,33 @@ export function readRequests(file) {
|
|
|
48
48
|
return requests;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** Pipeline: explicit hook attachment timings, including cancelled hooks, once per record id. */
|
|
52
|
+
export function readHookTimings(file) {
|
|
53
|
+
let text;
|
|
54
|
+
try {
|
|
55
|
+
text = readFileSync(file, "utf8");
|
|
56
|
+
} catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
const timings = [];
|
|
61
|
+
for (const line of text.split(/\r?\n/)) {
|
|
62
|
+
let record;
|
|
63
|
+
try {
|
|
64
|
+
record = JSON.parse(line);
|
|
65
|
+
} catch {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const hook = record?.attachment;
|
|
69
|
+
if (record?.type !== "attachment" || typeof hook?.type !== "string" || !hook.type.startsWith("hook_") || typeof hook.hookName !== "string"
|
|
70
|
+
|| !hook.hookName || !Number.isFinite(hook.durationMs) || hook.durationMs < 0) continue;
|
|
71
|
+
if (record.uuid && seen.has(record.uuid)) continue;
|
|
72
|
+
if (record.uuid) seen.add(record.uuid);
|
|
73
|
+
timings.push({ hook: hook.hookName, event: hook.hookEvent ?? "unknown", durationMs: hook.durationMs });
|
|
74
|
+
}
|
|
75
|
+
return timings;
|
|
76
|
+
}
|
|
77
|
+
|
|
51
78
|
/** The whole lines of one window at the head or the tail of a file, or [] when it does not read. */
|
|
52
79
|
function windowLines(file, fromEnd, bytes) {
|
|
53
80
|
let fd;
|
|
@@ -3,6 +3,7 @@ import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "nod
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
+
|
|
6
7
|
import {
|
|
7
8
|
agentTranscriptOf,
|
|
8
9
|
agentTypeOf,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
firstUsage,
|
|
12
13
|
lastUsage,
|
|
13
14
|
readRequests,
|
|
15
|
+
readHookTimings,
|
|
14
16
|
requestOf,
|
|
15
17
|
subagentTranscriptOf,
|
|
16
18
|
toolCallsIn,
|
|
@@ -41,6 +43,38 @@ function write(file, records) {
|
|
|
41
43
|
return file;
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
test("requestOf discards tool lists and message text", () => {
|
|
47
|
+
const record = { type: "assistant", message: { id: "tools", model: "m", usage: { input_tokens: 1 },
|
|
48
|
+
tools: [{ name: "Read" }, { name: "Skill" }], content: "private" } };
|
|
49
|
+
assert.equal(Object.hasOwn(requestOf(JSON.stringify(record)), "tools"), false);
|
|
50
|
+
assert.equal(Object.hasOwn(requestOf(JSON.stringify(record)), "content"), false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("readRequests ignores system tool-list snapshots", (t) => {
|
|
54
|
+
const base = folder(t);
|
|
55
|
+
const file = write(path.join(base, "tools.jsonl"), [
|
|
56
|
+
{ type: "system", subtype: "init", tools: ["Read"] }, assistant("one", usage(800)),
|
|
57
|
+
{ type: "system", tools: ["Read", "Skill"] }, assistant("two", usage(0, 1000)),
|
|
58
|
+
]);
|
|
59
|
+
assert.deepEqual(readRequests(file).map((request) => Object.hasOwn(request, "tools")), [false, false]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("hook timings read explicit attachment durations, deduplicate ids, and ignore other durations", (t) => {
|
|
63
|
+
const base = folder(t);
|
|
64
|
+
const hook = { type: "attachment", uuid: "h1", attachment: {
|
|
65
|
+
type: "hook_cancelled", hookName: "SessionStart:startup", hookEvent: "SessionStart", durationMs: 12,
|
|
66
|
+
} };
|
|
67
|
+
const file = write(path.join(base, "hooks.jsonl"), [hook, hook, "broken", { type: "system", durationMs: 400 },
|
|
68
|
+
{ ...hook, uuid: "invalid-type", attachment: { ...hook.attachment, type: 42 } },
|
|
69
|
+
{ ...hook, uuid: "bad", attachment: { ...hook.attachment, durationMs: -1 } },
|
|
70
|
+
{ ...hook, uuid: "h2", attachment: { ...hook.attachment, type: "hook_success", durationMs: 0 } }]);
|
|
71
|
+
assert.deepEqual(readHookTimings(file), [
|
|
72
|
+
{ hook: "SessionStart:startup", event: "SessionStart", durationMs: 12 },
|
|
73
|
+
{ hook: "SessionStart:startup", event: "SessionStart", durationMs: 0 },
|
|
74
|
+
]);
|
|
75
|
+
assert.deepEqual(readHookTimings(path.join(base, "absent")), []);
|
|
76
|
+
});
|
|
77
|
+
|
|
44
78
|
test("contextOf adds fresh input, cache reads, and cache writes, and a missing usage is zero", () => {
|
|
45
79
|
assert.equal(contextOf(usage(100, 20, 3)), 123);
|
|
46
80
|
assert.equal(contextOf(null), 0);
|
|
@@ -5,7 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
7
7
|
export function packageUserConfig(source, target) {
|
|
8
|
-
for (const file of ["claude/statusline.js", "claude/settings.shared.json", "codex/config.shared.toml"]) {
|
|
8
|
+
for (const file of ["claude/CLAUDE.core.md", "claude/statusline.js", "claude/settings.shared.json", "codex/config.shared.toml"]) {
|
|
9
9
|
mkdirSync(path.dirname(path.join(target, file)), { recursive: true });
|
|
10
10
|
copyFileSync(path.join(source, file), path.join(target, file));
|
|
11
11
|
}
|
|
@@ -11,7 +11,7 @@ function unquote(value) {
|
|
|
11
11
|
return value;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function scanValue(text, start) {
|
|
14
|
+
function scanValue(text, start, inline = false) {
|
|
15
15
|
let quote = "";
|
|
16
16
|
let depth = 0;
|
|
17
17
|
for (let i = start; i < text.length; i += 1) {
|
|
@@ -24,7 +24,8 @@ function scanValue(text, start) {
|
|
|
24
24
|
if (char === '"' || char === "'") {
|
|
25
25
|
quote = text.startsWith(char.repeat(3), i) ? char.repeat(3) : char;
|
|
26
26
|
i += quote.length - 1;
|
|
27
|
-
} else if (char === "
|
|
27
|
+
} else if (inline && depth === 0 && (char === "," || char === "}")) return { end: i, next: i + 1 };
|
|
28
|
+
else if (char === "[" || char === "{") depth += 1;
|
|
28
29
|
else if (char === "]" || char === "}") depth -= 1;
|
|
29
30
|
else if (char === "#") {
|
|
30
31
|
if (depth === 0) return { end: i, next: text.indexOf("\n", i) < 0 ? text.length : text.indexOf("\n", i) + 1 };
|
|
@@ -59,7 +60,7 @@ function documentOf(text) {
|
|
|
59
60
|
const value = scanValue(text, start);
|
|
60
61
|
const raw = text.slice(start, value.end).trimEnd();
|
|
61
62
|
if (section.fields.has(key)) throw new Error(`Duplicate TOML key: ${key}`);
|
|
62
|
-
section.fields.set(key, { start, end: start + raw.length, raw });
|
|
63
|
+
section.fields.set(key, { start, end: start + raw.length, raw, parts: keyParts(`${assignment[1]}${assignment[2]}`) });
|
|
63
64
|
offset = value.next;
|
|
64
65
|
continue;
|
|
65
66
|
}
|
|
@@ -69,6 +70,43 @@ function documentOf(text) {
|
|
|
69
70
|
return sections;
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
function keyParts(key) {
|
|
74
|
+
return [...key.matchAll(/"(?:[^"\\]|\\.)*"|'[^']*'|[\w-]+/g)].map(([part]) => unquote(part));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// A fragment that locates plugin fields in dotted assignments and inline tables.
|
|
78
|
+
function pluginTarget(section, parts, text, form = "dotted plugin assignment") {
|
|
79
|
+
if (!parts.length) return { ...section, fields: new Map([...section.fields].map(([key, field]) => [field.parts?.[0] ?? key, field])), prefix: [] };
|
|
80
|
+
const fields = new Map();
|
|
81
|
+
for (const [key, field] of section.fields) {
|
|
82
|
+
const path = field.parts ?? keyParts(key);
|
|
83
|
+
const common = Math.min(path.length, parts.length);
|
|
84
|
+
if (!path.slice(0, common).every((part, i) => part === parts[i])) continue;
|
|
85
|
+
if (path.length <= parts.length) {
|
|
86
|
+
const kind = form === "[plugins] table" ? form : path.length === 1 ? "top-level inline plugins table" : "dotted inline plugin table";
|
|
87
|
+
const line = text.slice(0, field.start).split("\n").length;
|
|
88
|
+
if (!field.raw.startsWith("{")) throw new Error(`Cannot merge ${kind} at line ${line}: expected an inline table.`);
|
|
89
|
+
const nested = { fields: new Map(), end: field.end - 1, inline: true };
|
|
90
|
+
let offset = field.start + 1;
|
|
91
|
+
while (offset < nested.end) {
|
|
92
|
+
const assignment = /^\s*("(?:[^"\\]|\\.)*"|'[^']*'|[\w-]+)((?:\s*\.\s*(?:"(?:[^"\\]|\\.)*"|'[^']*'|[\w-]+))*)\s*=\s*/.exec(text.slice(offset, nested.end));
|
|
93
|
+
if (!assignment) break;
|
|
94
|
+
const start = offset + assignment[0].length;
|
|
95
|
+
const value = scanValue(text, start, true);
|
|
96
|
+
const raw = text.slice(start, value.end).trimEnd();
|
|
97
|
+
const name = `${assignment[1]}${assignment[2]}`;
|
|
98
|
+
nested.fields.set(name, { start, end: start + raw.length, raw, parts: keyParts(name) });
|
|
99
|
+
offset = value.next;
|
|
100
|
+
}
|
|
101
|
+
return pluginTarget(nested, parts.slice(path.length), text, kind)
|
|
102
|
+
?? { ...nested, prefix: parts.slice(path.length) };
|
|
103
|
+
}
|
|
104
|
+
if (path.length === parts.length + 1) fields.set(path.at(-1), field);
|
|
105
|
+
else throw new Error(`Cannot merge ${form} at line ${text.slice(0, field.start).split("\n").length}: expected a plugin field.`);
|
|
106
|
+
}
|
|
107
|
+
return fields.size ? { ...section, fields, prefix: parts } : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
72
110
|
function sharedFields(text) {
|
|
73
111
|
const sections = documentOf(text);
|
|
74
112
|
const top = new Map([...sections[0].fields].filter(([key]) => CODEX_KEYS.includes(key)));
|
|
@@ -99,12 +137,10 @@ export function captureCodexConfig(text) {
|
|
|
99
137
|
|
|
100
138
|
export function mergeCodexConfig(local, shared) {
|
|
101
139
|
const sections = documentOf(local);
|
|
102
|
-
if (sections[0].fields.get("plugins")?.raw.startsWith("{")) {
|
|
103
|
-
throw new Error('Inline TOML plugins tables are unsupported; use [plugins."name"] tables.');
|
|
104
|
-
}
|
|
105
140
|
const desired = sharedFields(shared);
|
|
106
141
|
const edits = [];
|
|
107
142
|
const additions = new Map();
|
|
143
|
+
const inlineAdditions = new Map();
|
|
108
144
|
const newTables = [];
|
|
109
145
|
const changed = [];
|
|
110
146
|
const eol = local.includes("\r\n") ? "\r\n" : "\n";
|
|
@@ -117,7 +153,14 @@ export function mergeCodexConfig(local, shared) {
|
|
|
117
153
|
if (previous && unquote(previous.raw) === unquote(value.raw)) continue;
|
|
118
154
|
changed.push(`${label}${key}`);
|
|
119
155
|
if (previous) edits.push({ start: previous.start, end: previous.end, text: value.raw });
|
|
120
|
-
else
|
|
156
|
+
else {
|
|
157
|
+
const name = [...(section.prefix ?? []), key].map((part) => JSON.stringify(part)).join(".");
|
|
158
|
+
if (section.inline) {
|
|
159
|
+
const entry = inlineAdditions.get(section.end) ?? { populated: section.fields.size > 0, lines: [] };
|
|
160
|
+
entry.lines.push(`${name} = ${value.raw}`);
|
|
161
|
+
inlineAdditions.set(section.end, entry);
|
|
162
|
+
} else add(section, `${section.prefix ? name : key} = ${value.raw}`);
|
|
163
|
+
}
|
|
121
164
|
}
|
|
122
165
|
}
|
|
123
166
|
merge(sections[0], desired.top, "");
|
|
@@ -126,12 +169,25 @@ export function mergeCodexConfig(local, shared) {
|
|
|
126
169
|
if (matches.length > 1) throw new Error(`Duplicate plugin table: ${plugin.plugin}`);
|
|
127
170
|
if (matches.length) merge(matches[0], plugin.fields, `plugins.${plugin.plugin}.`);
|
|
128
171
|
else {
|
|
172
|
+
const parent = sections.find((s) => /^\[\s*(?:plugins|"plugins"|'plugins')\s*\]$/.test(s.name));
|
|
173
|
+
const target = pluginTarget(sections[0], ["plugins", plugin.plugin], local)
|
|
174
|
+
?? (parent && (pluginTarget(parent, [plugin.plugin], local, "[plugins] table") ?? { ...parent, prefix: [plugin.plugin] }));
|
|
175
|
+
if (target) {
|
|
176
|
+
merge(target, plugin.fields, `plugins.${plugin.plugin}.`);
|
|
177
|
+
const lines = additions.get(target);
|
|
178
|
+
if (lines) edits.push({ start: target.end, end: target.end,
|
|
179
|
+
text: `${target.end && local[target.end - 1] !== "\n" ? eol : ""}${lines.join(eol)}${eol}` });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
129
182
|
const section = { fields: new Map() };
|
|
130
183
|
newTables.push(section);
|
|
131
184
|
add(section, `[plugins.${JSON.stringify(plugin.plugin)}]`);
|
|
132
185
|
merge(section, plugin.fields, `plugins.${plugin.plugin}.`);
|
|
133
186
|
}
|
|
134
187
|
}
|
|
188
|
+
for (const [end, entry] of inlineAdditions) {
|
|
189
|
+
edits.push({ start: end, end, text: `${entry.populated ? ", " : ""}${entry.lines.join(", ")} ` });
|
|
190
|
+
}
|
|
135
191
|
for (const section of sections) {
|
|
136
192
|
const lines = additions.get(section);
|
|
137
193
|
if (lines) edits.push({ start: section.end, end: section.end,
|
package/src/cli/user-config.mjs
CHANGED
|
@@ -12,19 +12,20 @@ import { captureCodexConfig, mergeCodexConfig } from "./user-config-toml.mjs";
|
|
|
12
12
|
export { captureCodexConfig, mergeCodexConfig } from "./user-config-toml.mjs";
|
|
13
13
|
|
|
14
14
|
export const CLAUDE_KEYS = Object.freeze([
|
|
15
|
-
"cleanupPeriodDays", "syncClaudeAiPlugins", "env", "permissions", "model", "skillOverrides",
|
|
15
|
+
"cleanupPeriodDays", "syncClaudeAiPlugins", "env", "permissions", "autoMode", "model", "skillOverrides",
|
|
16
16
|
"statusLine", "enabledPlugins", "extraKnownMarketplaces", "effortLevel", "modelSettings",
|
|
17
17
|
"awaySummaryEnabled", "autoUpdatesChannel", "tui", "skipWorkflowUsageWarning", "theme",
|
|
18
18
|
"autoCompactEnabled", "autoContinueAtUsageLimit", "agentPushNotifEnabled", "skipAutoPermissionPrompt",
|
|
19
19
|
]);
|
|
20
20
|
const ENV_KEYS = ["CLAUDE_CODE_DISABLE_MOUSE", "CLAUDE_CODE_DISABLE_BG_SHELL_PRESSURE_REAP"];
|
|
21
|
+
const AUTO_MODE_KEYS = ["environment", "allow", "soft_deny", "hard_deny"];
|
|
21
22
|
const MAP_KEYS = ["enabledPlugins", "extraKnownMarketplaces", "env"];
|
|
22
23
|
const STATUS_COMMAND = 'node "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/statusline.js"';
|
|
23
24
|
const USAGE = "qc user-config apply|check|capture [--dry-run] [--kit-dir <path>] [--claude-dir <path>] [--codex-dir <path>]";
|
|
24
25
|
|
|
25
26
|
export function assertSafePath(file) {
|
|
26
27
|
const name = file.replaceAll("\\", "/").split("/").at(-1).toLowerCase();
|
|
27
|
-
if ([".claude.json", ".credentials.json", "auth.json"].includes(name) || /token|secret|credential|auth/i.test(name)) {
|
|
28
|
+
if ([".claude.json", ".credentials.json", "auth.json"].includes(name) || /token|secret|credential|auth(?!or(?:$|[^a-z0-9]))/i.test(name)) {
|
|
28
29
|
throw new Error(`Refusing credential file: ${file}`);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -54,7 +55,8 @@ function sharedClaude(text) {
|
|
|
54
55
|
const source = objectOf(text);
|
|
55
56
|
const shared = Object.fromEntries(CLAUDE_KEYS.filter((key) => Object.hasOwn(source, key)).map((key) => [key, source[key]]));
|
|
56
57
|
if (shared.env) shared.env = Object.fromEntries(ENV_KEYS.filter((key) => Object.hasOwn(shared.env, key)).map((key) => [key, shared.env[key]]));
|
|
57
|
-
if (shared.permissions) shared.permissions = Object.fromEntries(["defaultMode"].filter((key) => Object.hasOwn(shared.permissions, key)).map((key) => [key, shared.permissions[key]]));
|
|
58
|
+
if (shared.permissions) shared.permissions = Object.fromEntries(["defaultMode", "allow", "deny"].filter((key) => Object.hasOwn(shared.permissions, key)).map((key) => [key, shared.permissions[key]]));
|
|
59
|
+
if (shared.autoMode) shared.autoMode = Object.fromEntries(AUTO_MODE_KEYS.filter((key) => Object.hasOwn(shared.autoMode, key)).map((key) => [key, shared.autoMode[key]]));
|
|
58
60
|
if (shared.statusLine) shared.statusLine = { type: "command", command: STATUS_COMMAND };
|
|
59
61
|
const local = new Set(["skills-dir"]);
|
|
60
62
|
if (shared.extraKnownMarketplaces) {
|
|
@@ -68,16 +70,47 @@ function sharedClaude(text) {
|
|
|
68
70
|
return shared;
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
/** Fragment: merges environment lines by their bold label, preserving local order. */
|
|
74
|
+
function mergeEnvironment(local, shared) {
|
|
75
|
+
const labelOf = (line) => /^\*\*([^*]+)\*\*:/.exec(line)?.[1];
|
|
76
|
+
const lines = [...new Set(local)];
|
|
77
|
+
for (const line of shared) {
|
|
78
|
+
const label = labelOf(line);
|
|
79
|
+
const index = label === undefined ? -1 : lines.findIndex((entry) => labelOf(entry) === label);
|
|
80
|
+
if (index >= 0) lines[index] = line;
|
|
81
|
+
else if (!lines.includes(line)) lines.push(line);
|
|
82
|
+
}
|
|
83
|
+
const seenLabels = new Set();
|
|
84
|
+
const seenLines = new Set();
|
|
85
|
+
return lines.filter((line) => {
|
|
86
|
+
const label = labelOf(line);
|
|
87
|
+
if (seenLines.has(line) || (label !== undefined && seenLabels.has(label))) return false;
|
|
88
|
+
seenLines.add(line);
|
|
89
|
+
if (label !== undefined) seenLabels.add(label);
|
|
90
|
+
return true;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Fragment: selects the merge rule for a shared settings entry. */
|
|
95
|
+
function mergeEntry(key, name, local, shared) {
|
|
96
|
+
if (key === "autoMode" && name === "environment") return mergeEnvironment(local ?? [], shared);
|
|
97
|
+
if (key === "autoMode" || (key === "permissions" && ["allow", "deny"].includes(name))) {
|
|
98
|
+
return [...new Set([...(local ?? []), ...shared])];
|
|
99
|
+
}
|
|
100
|
+
return shared;
|
|
101
|
+
}
|
|
102
|
+
|
|
71
103
|
export function mergeClaudeSettings(local, shared) {
|
|
72
104
|
const target = objectOf(local);
|
|
73
105
|
const source = sharedClaude(shared);
|
|
74
106
|
const changed = [];
|
|
75
107
|
for (const [key, value] of Object.entries(source)) {
|
|
76
|
-
if ([...MAP_KEYS, "permissions"].includes(key)) {
|
|
108
|
+
if ([...MAP_KEYS, "permissions", "autoMode"].includes(key)) {
|
|
77
109
|
const before = target[key] ?? {};
|
|
78
110
|
const merged = { ...before };
|
|
79
111
|
for (const [name, entry] of Object.entries(value)) {
|
|
80
|
-
|
|
112
|
+
const next = mergeEntry(key, name, before[name], entry);
|
|
113
|
+
if (!isDeepStrictEqual(before[name], next)) { changed.push(`${key}.${name}`); Object.defineProperty(merged, name, { value: next, enumerable: true, writable: true, configurable: true }); }
|
|
81
114
|
}
|
|
82
115
|
target[key] = merged;
|
|
83
116
|
} else if (!isDeepStrictEqual(target[key], value)) { changed.push(key); target[key] = value; }
|
|
@@ -104,7 +137,7 @@ function stamp(now) {
|
|
|
104
137
|
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
105
138
|
}
|
|
106
139
|
|
|
107
|
-
function backupFile(file, now) {
|
|
140
|
+
export function backupFile(file, now) {
|
|
108
141
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
109
142
|
if (existsSync(file)) copyFileSync(file, `${file}.bak-${stamp(now)}`, constants.COPYFILE_EXCL);
|
|
110
143
|
}
|
|
@@ -146,7 +179,6 @@ export async function runUserConfig(args, options = {}) {
|
|
|
146
179
|
for (const plan of changes) writeFileSync(plan.target, plan.text, { mode: 0o600 });
|
|
147
180
|
}
|
|
148
181
|
const drift = plans.some((plan) => plan.changed.length);
|
|
149
|
-
if (!drift) log("Shared user configuration matches.");
|
|
150
182
|
return verb === "check" && drift ? 1 : 0;
|
|
151
183
|
} catch (error) {
|
|
152
184
|
(options.log ?? console.error)(`qc user-config: ${error.message}`);
|
|
@@ -16,11 +16,65 @@ function fixture(t) {
|
|
|
16
16
|
for (const dir of ["claude", "codex"]) mkdirSync(path.join(kitDir, dir), { recursive: true });
|
|
17
17
|
writeFileSync(path.join(kitDir, "claude/settings.shared.json"), '{"model":"opus","enabledPlugins":{"kit@remote":true}}\n');
|
|
18
18
|
writeFileSync(path.join(kitDir, "claude/statusline.js"), "console.log('status');\n");
|
|
19
|
+
writeFileSync(path.join(kitDir, "claude/CLAUDE.core.md"), "core\n");
|
|
19
20
|
writeFileSync(path.join(kitDir, "codex/config.shared.toml"), 'model = "shared"\n[plugins."kit@remote"]\nenabled = true\n');
|
|
20
21
|
const lines = [];
|
|
21
22
|
return { root, kitDir, home: path.join(root, "home"), env: {}, log: (line) => lines.push(line), lines, now: new Date(2026, 0, 2, 3, 4, 5) };
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
const SECRET_READ_DENIES = [
|
|
26
|
+
...[".env", ".env.local", ".env.*.local", ".env.production", "*.pem", "*.key", "id_rsa*", "id_ed25519*"]
|
|
27
|
+
.map((pattern) => `Read(**/${pattern})`),
|
|
28
|
+
"Read(~/.ssh/**)",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const PROCESS_ALLOWS = [
|
|
32
|
+
'Bash(powershell -Command "Stop-Process -Id *)',
|
|
33
|
+
'Bash(powershell -NoProfile -Command "Stop-Process -Id *)',
|
|
34
|
+
];
|
|
35
|
+
const GIT_AND_INFRA_DENIES = [
|
|
36
|
+
"Bash(git checkout*)", "Bash(git -C * checkout*)", "Bash(git switch*)", "Bash(git -C * switch*)",
|
|
37
|
+
"Bash(git reset*)", "Bash(git -C * reset*)", "Bash(git stash*)", "Bash(git -C * stash*)",
|
|
38
|
+
"Bash(git push --force*)", "Bash(git push -f*)", "Bash(git push --force-with-lease*)",
|
|
39
|
+
"Bash(git worktree prune*)", "Bash(terraform apply*)",
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
test("shared permissions deny secret reads in the working directory and ~/.ssh while examples stay readable", () => {
|
|
43
|
+
const shared = readFileSync(new URL("../../../../user-config/claude/settings.shared.json", import.meta.url), "utf8");
|
|
44
|
+
assert.deepEqual(JSON.parse(shared).permissions.deny, [...SECRET_READ_DENIES, ...GIT_AND_INFRA_DENIES]);
|
|
45
|
+
const local = { permissions: { allow: ["Read(**/.env.example)"], deny: ["Bash(rm *)"] } };
|
|
46
|
+
const merged = mergeClaudeSettings(JSON.stringify(local), shared);
|
|
47
|
+
const permissions = JSON.parse(merged.text).permissions;
|
|
48
|
+
assert.deepEqual(permissions.deny, ["Bash(rm *)", ...SECRET_READ_DENIES, ...GIT_AND_INFRA_DENIES]);
|
|
49
|
+
assert.deepEqual(permissions.allow, [...local.permissions.allow, ...PROCESS_ALLOWS]);
|
|
50
|
+
assert.ok(merged.changed.includes("permissions.deny"));
|
|
51
|
+
assert.deepEqual(mergeClaudeSettings(merged.text, shared).changed, []);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("shared autoMode trusts every repository under GitHub and its worktrees", () => {
|
|
55
|
+
const shared = JSON.parse(readFileSync(new URL("../../../../user-config/claude/settings.shared.json", import.meta.url), "utf8"));
|
|
56
|
+
assert.deepEqual(shared.autoMode.environment.filter((line) => line.startsWith("**Trusted repo**:")), [
|
|
57
|
+
"**Trusted repo**: Every git repository under `~/Documents/GitHub/`, with its worktrees under `.worktree/` and `.claude/worktrees/`",
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("user-config check reports secret deny drift and becomes silent after apply", async (t) => {
|
|
62
|
+
const f = fixture(t);
|
|
63
|
+
writeFileSync(path.join(f.kitDir, "claude/settings.shared.json"), JSON.stringify({ permissions: { deny: SECRET_READ_DENIES } }));
|
|
64
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
65
|
+
const file = configPaths(f.home, f.env).claude;
|
|
66
|
+
const settings = JSON.parse(readFileSync(file, "utf8"));
|
|
67
|
+
settings.permissions.deny.pop();
|
|
68
|
+
writeFileSync(file, JSON.stringify(settings));
|
|
69
|
+
f.lines.length = 0;
|
|
70
|
+
assert.equal(await runUserConfig(["check"], f), 1);
|
|
71
|
+
assert.match(f.lines.join("\n"), /permissions.deny/);
|
|
72
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
73
|
+
f.lines.length = 0;
|
|
74
|
+
assert.equal(await runUserConfig(["check"], f), 0);
|
|
75
|
+
assert.deepEqual(f.lines, []);
|
|
76
|
+
});
|
|
77
|
+
|
|
24
78
|
test("JSON merges listed plugin and marketplace keys, preserving local keys and omitted shared keys", () => {
|
|
25
79
|
const local = { model: "old", effortLevel: "high", local: 7, enabledPlugins: { local: true, kit: false }, extraKnownMarketplaces: { local: {} } };
|
|
26
80
|
const shared = { model: "opus", local: 9, enabledPlugins: { kit: true }, extraKnownMarketplaces: { remote: { source: { source: "github", repo: "a/b" } } } };
|
|
@@ -30,6 +84,92 @@ test("JSON merges listed plugin and marketplace keys, preserving local keys and
|
|
|
30
84
|
assert.deepEqual(mergeClaudeSettings(result.text, JSON.stringify(shared)).changed, []);
|
|
31
85
|
});
|
|
32
86
|
|
|
87
|
+
test("permissions allow and autoMode lists merge in machine order and stay idempotent", () => {
|
|
88
|
+
const local = { permissions: { allow: ["local", "both"] }, autoMode: { localOnly: true } };
|
|
89
|
+
const shared = { permissions: { allow: ["both", "kit"] }, autoMode: { unknown: ["ignored"] } };
|
|
90
|
+
for (const key of ["allow", "soft_deny", "hard_deny"]) {
|
|
91
|
+
local.autoMode[key] = ["local", "both"];
|
|
92
|
+
shared.autoMode[key] = ["both", "kit"];
|
|
93
|
+
}
|
|
94
|
+
const result = mergeClaudeSettings(JSON.stringify(local), JSON.stringify(shared));
|
|
95
|
+
const merged = JSON.parse(result.text);
|
|
96
|
+
assert.deepEqual(merged.permissions.allow, ["local", "both", "kit"]);
|
|
97
|
+
assert.ok(result.changed.includes("permissions.allow"));
|
|
98
|
+
for (const key of ["allow", "soft_deny", "hard_deny"]) {
|
|
99
|
+
assert.deepEqual(merged.autoMode[key], ["local", "both", "kit"]);
|
|
100
|
+
assert.ok(result.changed.includes(`autoMode.${key}`));
|
|
101
|
+
}
|
|
102
|
+
assert.equal(merged.autoMode.localOnly, true);
|
|
103
|
+
assert.equal(merged.autoMode.unknown, undefined);
|
|
104
|
+
assert.deepEqual(mergeClaudeSettings(result.text, JSON.stringify(shared)).changed, []);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("autoMode environment replaces matching labels in place and preserves local lines", () => {
|
|
108
|
+
const local = { autoMode: { environment: ["**Machine**: old", "**Organization**: local", "### heading", "unlabeled", "### heading"] } };
|
|
109
|
+
const shared = { autoMode: { environment: ["**Machine**: shared", "### heading", "unlabeled", "**New**: appended", "new text"] } };
|
|
110
|
+
const result = mergeClaudeSettings(JSON.stringify(local), JSON.stringify(shared));
|
|
111
|
+
assert.deepEqual(JSON.parse(result.text).autoMode.environment, [
|
|
112
|
+
"**Machine**: shared", "**Organization**: local", "### heading", "unlabeled", "**New**: appended", "new text",
|
|
113
|
+
]);
|
|
114
|
+
assert.deepEqual(result.changed, ["autoMode.environment"]);
|
|
115
|
+
assert.deepEqual(mergeClaudeSettings(result.text, JSON.stringify(shared)).changed, []);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("autoMode environment deduplicates labels after replacement and stays idempotent", () => {
|
|
119
|
+
for (const environment of [
|
|
120
|
+
["**Machine**: old", "**Machine**: kit"],
|
|
121
|
+
["**Machine**: old", "**Machine**: other"],
|
|
122
|
+
]) {
|
|
123
|
+
const shared = JSON.stringify({ autoMode: { environment: ["**Machine**: kit"] } });
|
|
124
|
+
const result = mergeClaudeSettings(JSON.stringify({ autoMode: { environment } }), shared);
|
|
125
|
+
assert.deepEqual(JSON.parse(result.text).autoMode.environment, ["**Machine**: kit"]);
|
|
126
|
+
const second = mergeClaudeSettings(result.text, shared);
|
|
127
|
+
assert.deepEqual(second.changed, []);
|
|
128
|
+
assert.equal(second.text, result.text);
|
|
129
|
+
}
|
|
130
|
+
const local = { autoMode: { environment: ["**Local**: first", "plain", "**Local**: second", "plain"] } };
|
|
131
|
+
const shared = JSON.stringify({ autoMode: { environment: [] } });
|
|
132
|
+
const result = mergeClaudeSettings(JSON.stringify(local), shared);
|
|
133
|
+
assert.deepEqual(JSON.parse(result.text).autoMode.environment, ["**Local**: first", "plain"]);
|
|
134
|
+
assert.deepEqual(mergeClaudeSettings(result.text, shared).changed, []);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("check reports changed environment labels and a second apply changes nothing", async (t) => {
|
|
138
|
+
const f = fixture(t);
|
|
139
|
+
const shared = { autoMode: { environment: ["**Machine**: shared"], allow: ["$defaults"] }, permissions: { allow: ["shared"] } };
|
|
140
|
+
writeFileSync(path.join(f.kitDir, "claude/settings.shared.json"), JSON.stringify(shared));
|
|
141
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
142
|
+
const file = configPaths(f.home, f.env).claude;
|
|
143
|
+
const local = JSON.parse(readFileSync(file, "utf8"));
|
|
144
|
+
local.autoMode.environment = ["**Machine**: changed", "**Organization**: local"];
|
|
145
|
+
writeFileSync(file, JSON.stringify(local));
|
|
146
|
+
f.lines.length = 0;
|
|
147
|
+
assert.equal(await runUserConfig(["check"], f), 1);
|
|
148
|
+
assert.equal(f.lines.length, 1);
|
|
149
|
+
assert.match(f.lines[0], /autoMode.environment/);
|
|
150
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
151
|
+
f.lines.length = 0;
|
|
152
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
153
|
+
assert.deepEqual(f.lines, []);
|
|
154
|
+
assert.equal(await runUserConfig(["check"], f), 0);
|
|
155
|
+
assert.deepEqual(f.lines, []);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("capture keeps every environment line and filters unsupported autoMode keys", async (t) => {
|
|
159
|
+
const f = fixture(t);
|
|
160
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
161
|
+
const file = configPaths(f.home, f.env).claude;
|
|
162
|
+
const local = JSON.parse(readFileSync(file, "utf8"));
|
|
163
|
+
local.autoMode = { environment: ["**Organization**: local", "### heading"], allow: ["local"], soft_deny: ["soft"], hard_deny: ["hard"], unsupported: true };
|
|
164
|
+
local.permissions = { allow: ["local"], deny: ["deny"], defaultMode: "auto", localOnly: true };
|
|
165
|
+
writeFileSync(file, JSON.stringify(local));
|
|
166
|
+
assert.equal(await runUserConfig(["capture"], f), 0);
|
|
167
|
+
const captured = JSON.parse(readFileSync(path.join(f.kitDir, "claude/settings.shared.json"), "utf8"));
|
|
168
|
+
const { unsupported, ...expected } = local.autoMode;
|
|
169
|
+
assert.deepEqual(captured.autoMode, expected);
|
|
170
|
+
assert.deepEqual(captured.permissions, { allow: ["local"], deny: ["deny"], defaultMode: "auto" });
|
|
171
|
+
});
|
|
172
|
+
|
|
33
173
|
test("TOML merges top-level keys and plugin fields while preserving comments and unrelated lines", () => {
|
|
34
174
|
const local = '# keep\r\nmodel = "old" # model comment\r\nnotify = ["local"]\r\n\r\n[desktop]\r\nmodel = "desktop"\r\n[plugins."kit@remote"] # plugin comment\r\nenabled = false # enabled comment\r\nlocal = 42\r\n[plugins."local@private"]\r\nenabled = true\r\n';
|
|
35
175
|
const shared = 'model = "new"\nservice_tier = "default"\nnotify = ["wrong"]\n[desktop]\nmodel = "wrong"\n[plugins."kit@remote"]\nenabled = true\n[plugins."new@remote"]\nenabled = false\n';
|
|
@@ -83,13 +223,105 @@ test("TOML fills existing plugin sections before appending new tables", () => {
|
|
|
83
223
|
}
|
|
84
224
|
});
|
|
85
225
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
226
|
+
const tomlTests = {
|
|
227
|
+
skip: spawnSync("python", ["-c", "import tomllib"], { stdio: "ignore", timeout: 5_000 }).status === 0 ? false : "Python tomllib is unavailable",
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
function parseTomlFile(file) {
|
|
231
|
+
const result = spawnSync("python", ["-c", "import json,sys,tomllib; print(json.dumps(tomllib.load(open(sys.argv[1], 'rb'))))", file], { encoding: "utf8" });
|
|
232
|
+
assert.equal(result.status, 0, result.stderr);
|
|
233
|
+
return JSON.parse(result.stdout);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
for (const [form, local] of [
|
|
237
|
+
["top-level inline", 'plugins = { "kit@remote" = { enabled = false, local = 42 } }\n'],
|
|
238
|
+
["dotted inline", 'plugins."kit@remote" = { enabled = false, local = 42 }\n'],
|
|
239
|
+
["dotted field", 'plugins."kit@remote".enabled = false\nplugins."kit@remote".local = 42\n'],
|
|
240
|
+
["plugins table", '[plugins]\n"kit@remote" = { enabled = false, local = 42 }\n'],
|
|
241
|
+
]) {
|
|
242
|
+
test(`apply merges the ${form} plugin form into valid TOML`, tomlTests, async (t) => {
|
|
243
|
+
const f = fixture(t);
|
|
244
|
+
writeFileSync(path.join(f.kitDir, "codex/config.shared.toml"), '[plugins."kit@remote"]\nenabled = true\n');
|
|
245
|
+
const file = configPaths(f.home, f.env).codex;
|
|
246
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
247
|
+
writeFileSync(file, local);
|
|
248
|
+
assert.equal(await runUserConfig(["apply"], f), 0, f.lines.join("\n"));
|
|
249
|
+
assert.deepEqual(parseTomlFile(file).plugins["kit@remote"], { enabled: true, local: 42 });
|
|
250
|
+
assert.equal(readFileSync(file, "utf8"), local.replace("false", "true"));
|
|
251
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
test("plugin forms add missing fields and plugins without duplicate tables", tomlTests, async (t) => {
|
|
256
|
+
for (const local of [
|
|
257
|
+
'"plugins" = { "kit@remote" = { local = { x = 42 } } }\n',
|
|
258
|
+
"'plugins'.'kit@remote' = { local = { x = 42 } }\n",
|
|
259
|
+
'plugins."kit@remote".local = { x = 42 }\n',
|
|
260
|
+
'[plugins]\n"kit@remote" = { local = { x = 42 } }\n',
|
|
261
|
+
]) {
|
|
262
|
+
const f = fixture(t);
|
|
263
|
+
writeFileSync(path.join(f.kitDir, "codex/config.shared.toml"), '[plugins."kit@remote"]\nenabled = true\n[plugins."new@remote"]\nenabled = false\n');
|
|
264
|
+
const file = configPaths(f.home, f.env).codex;
|
|
265
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
266
|
+
writeFileSync(file, local);
|
|
267
|
+
assert.equal(await runUserConfig(["apply"], f), 0, f.lines.join("\n"));
|
|
268
|
+
assert.deepEqual(parseTomlFile(file).plugins, {
|
|
269
|
+
"kit@remote": { local: { x: 42 }, enabled: true }, "new@remote": { enabled: false },
|
|
270
|
+
});
|
|
271
|
+
assert.deepEqual(mergeCodexConfig(readFileSync(file, "utf8"), readFileSync(path.join(f.kitDir, "codex/config.shared.toml"), "utf8")).changed, []);
|
|
90
272
|
}
|
|
91
273
|
});
|
|
92
274
|
|
|
275
|
+
test("incompatible plugin values name the form and line before any write", tomlTests, async (t) => {
|
|
276
|
+
for (const [form, local] of [
|
|
277
|
+
["top-level inline plugins table", '# keep\nplugins = false\n'],
|
|
278
|
+
["dotted inline plugin table", '# keep\nplugins."kit@remote" = false\n'],
|
|
279
|
+
["[plugins] table", '# keep\n[plugins]\n"kit@remote" = false\n'],
|
|
280
|
+
]) {
|
|
281
|
+
const f = fixture(t);
|
|
282
|
+
const file = configPaths(f.home, f.env).codex;
|
|
283
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
284
|
+
writeFileSync(file, local);
|
|
285
|
+
assert.equal(await runUserConfig(["apply"], f), 2);
|
|
286
|
+
assert.ok(f.lines.at(-1).includes(form), f.lines.join("\n"));
|
|
287
|
+
assert.match(f.lines.at(-1), /line [23]/);
|
|
288
|
+
assert.equal(readFileSync(file, "utf8"), local);
|
|
289
|
+
parseTomlFile(file);
|
|
290
|
+
assert.equal(readdirSync(path.dirname(file)).length, 1);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("an empty inline plugins table accepts several plugins as valid TOML", tomlTests, async (t) => {
|
|
295
|
+
const f = fixture(t);
|
|
296
|
+
writeFileSync(path.join(f.kitDir, "codex/config.shared.toml"), '[plugins."kit@remote"]\nenabled = true\n[plugins."new@remote"]\nenabled = false\n');
|
|
297
|
+
const file = configPaths(f.home, f.env).codex;
|
|
298
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
299
|
+
writeFileSync(file, "plugins = {}\n");
|
|
300
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
301
|
+
assert.deepEqual(parseTomlFile(file).plugins, { "kit@remote": { enabled: true }, "new@remote": { enabled: false } });
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
for (const name of ["secrets.json", "tokens.json", "apitoken.txt", "accesstoken.json", "mycredentials.txt", "authentication.json"]) {
|
|
305
|
+
test(`credential paths refuse ${name}`, () => {
|
|
306
|
+
assert.throws(() => assertSafePath(name), /credential/i);
|
|
307
|
+
assert.throws(() => assertSafePath(`C:\\settings\\${name.toUpperCase()}`), /credential/i);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
test("author remains a safe config name without Python", () => {
|
|
312
|
+
assert.doesNotThrow(() => assertSafePath("author"));
|
|
313
|
+
assert.doesNotThrow(() => assertSafePath("author.toml"));
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("credential names allow author", tomlTests, async (t) => {
|
|
317
|
+
const f = fixture(t);
|
|
318
|
+
f.env.CODEX_HOME = path.join(f.root, "author");
|
|
319
|
+
assert.doesNotThrow(() => assertSafePath("author.toml"));
|
|
320
|
+
assert.throws(() => assertSafePath("auth_token.toml"), /credential/i);
|
|
321
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
322
|
+
assert.equal(parseTomlFile(configPaths(f.home, f.env).codex).model, "shared");
|
|
323
|
+
});
|
|
324
|
+
|
|
93
325
|
test("malformed shared configuration fails before any target changes", async (t) => {
|
|
94
326
|
const f = fixture(t);
|
|
95
327
|
writeFileSync(path.join(f.kitDir, "codex/config.shared.toml"), 'model = "unterminated');
|
|
@@ -232,10 +464,11 @@ test("CLI check returns drift, matching, and error exit codes", (t) => {
|
|
|
232
464
|
assert.equal(run().status, 2);
|
|
233
465
|
});
|
|
234
466
|
|
|
235
|
-
test("package staging includes all
|
|
467
|
+
test("package staging includes all shared files and resolves them outside the checkout", async (t) => {
|
|
236
468
|
const f = fixture(t);
|
|
237
469
|
const target = path.join(f.root, "node_modules/architecture-harness/user-config");
|
|
238
470
|
packageUserConfig(f.kitDir, target);
|
|
471
|
+
assert.equal(readFileSync(path.join(target, "claude/CLAUDE.core.md"), "utf8"), "core\n");
|
|
239
472
|
assert.equal(readFileSync(path.join(target, "claude/statusline.js"), "utf8"), "console.log('status');\n");
|
|
240
473
|
assert.equal(readFileSync(path.join(target, "codex/config.shared.toml"), "utf8"), readFileSync(path.join(f.kitDir, "codex/config.shared.toml"), "utf8"));
|
|
241
474
|
assert.equal(readFileSync(path.join(target, "claude/settings.shared.json"), "utf8"), readFileSync(path.join(f.kitDir, "claude/settings.shared.json"), "utf8"));
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The SessionStart trigger tells the orchestrator to arm event watches and an hourly check.
|
|
3
|
+
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { dispatchSettingsAt } from "./dispatch.mjs";
|
|
6
|
+
|
|
7
|
+
export const ARM_NOTE =
|
|
8
|
+
"Event waits: for each pending item (an open PR, a Codex job, a workflow run), start one background " +
|
|
9
|
+
"`qc watch --pr <n> --codex <wrapper.log> --run <workflow>@<branch>`, and re-arm it after each EVENT line. " +
|
|
10
|
+
"A hook cannot create a cron, so create one hourly dead-man check yourself: it lists the pending items " +
|
|
11
|
+
"and re-arms every watch that ended with no EVENT line.";
|
|
12
|
+
|
|
13
|
+
export function decide(call, env = process.env) {
|
|
14
|
+
if (env.QC_ROLE === "implementer") return null;
|
|
15
|
+
try {
|
|
16
|
+
if (!dispatchSettingsAt(call.cwd ?? process.cwd())) return null;
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return { hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: ARM_NOTE } };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function readStdin() {
|
|
24
|
+
let data = "";
|
|
25
|
+
for await (const chunk of process.stdin) data += chunk;
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const isEntryPoint = process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1];
|
|
30
|
+
if (isEntryPoint) {
|
|
31
|
+
let call = null;
|
|
32
|
+
try {
|
|
33
|
+
call = JSON.parse(await readStdin());
|
|
34
|
+
} catch {
|
|
35
|
+
// Invalid hook input carries no checkout to inspect.
|
|
36
|
+
}
|
|
37
|
+
const result = call ? decide(call) : null;
|
|
38
|
+
if (result) process.stdout.write(JSON.stringify(result));
|
|
39
|
+
}
|