@clagentic/console 1.9.0 → 1.10.0-beta.2
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/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +9 -3
- package/bin/cli.js +40 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/audit.js +3 -2
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +25 -22
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/codex-defaults.js +8 -2
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +57 -0
- package/lib/daemon.js +288 -205
- package/lib/drain.js +74 -17
- package/lib/env-compat.js +61 -0
- package/lib/extension-commands.js +45 -0
- package/lib/history-visibility.js +4 -0
- package/lib/idle-adapter-reaper.js +71 -0
- package/lib/link-trap.js +78 -0
- package/lib/mcp-local.js +8 -6
- package/lib/mcp-tool-input.js +116 -0
- package/lib/mcp-tool-schema.js +179 -0
- package/lib/memory-limits.js +61 -5
- package/lib/memory-setting-validate.js +65 -0
- package/lib/memory-shed.js +13 -32
- package/lib/new-work-gate.js +47 -0
- package/lib/os-users.js +5 -3
- package/lib/project-access.js +139 -0
- package/lib/project-connection.js +37 -22
- package/lib/project-external-trigger.js +166 -105
- package/lib/project-file-scope.js +172 -0
- package/lib/project-file-watch.js +86 -61
- package/lib/project-filesystem.js +144 -128
- package/lib/project-git.js +119 -0
- package/lib/project-http.js +44 -28
- package/lib/project-loop.js +17 -9
- package/lib/project-mcp.js +53 -72
- package/lib/project-message-gate.js +70 -0
- package/lib/project-notifications.js +31 -4
- package/lib/project-prompt-responses.js +217 -0
- package/lib/project-sessions.js +192 -355
- package/lib/project-user-message.js +27 -15
- package/lib/project.js +212 -147
- package/lib/projects-dir.js +90 -0
- package/lib/prompt-access.js +22 -0
- package/lib/prompt-kinds/answer-limits.js +15 -0
- package/lib/prompt-kinds/ask-user.js +58 -0
- package/lib/prompt-kinds/codecs.js +97 -0
- package/lib/prompt-kinds/elicitation.js +77 -0
- package/lib/prompt-kinds/extension.js +39 -0
- package/lib/prompt-kinds/index.js +68 -0
- package/lib/prompt-kinds/permission.js +114 -0
- package/lib/prompt-kinds/plan.js +79 -0
- package/lib/prompt-kinds/tool-call.js +38 -0
- package/lib/prompt-registry.js +680 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +80 -0
- package/lib/public/css/input.css +17 -3
- package/lib/public/css/menus.css +10 -0
- package/lib/public/css/messages.css +5 -0
- package/lib/public/css/rewind.css +22 -0
- package/lib/public/index.html +4 -12
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +52 -47
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -59
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +170 -20
- package/lib/public/modules/filebrowser.js +18 -16
- package/lib/public/modules/history-visibility.js +4 -0
- package/lib/public/modules/mention.js +3 -2
- package/lib/public/modules/mode-options.js +38 -0
- package/lib/public/modules/project-settings.js +19 -8
- package/lib/public/modules/prompt-banner.js +78 -0
- package/lib/public/modules/prompt-card.js +201 -0
- package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
- package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
- package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
- package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
- package/lib/public/modules/prompt-kinds/index.js +18 -0
- package/lib/public/modules/prompt-kinds/own-key.js +29 -0
- package/lib/public/modules/prompt-kinds/package.json +3 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
- package/lib/public/modules/prompt-kinds/permission.js +209 -0
- package/lib/public/modules/prompt-kinds/plan.js +102 -0
- package/lib/public/modules/prompt-state.js +142 -0
- package/lib/public/modules/prompts.js +134 -0
- package/lib/public/modules/rewind.js +4 -1
- package/lib/public/modules/server-settings.js +2 -4
- package/lib/public/modules/sidebar-mobile.js +19 -9
- package/lib/public/modules/sidebar-sessions.js +21 -14
- package/lib/public/modules/sticky-notes.js +3 -2
- package/lib/public/modules/team-panel.js +5 -4
- package/lib/public/modules/tools.js +81 -906
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +142 -0
- package/lib/public/sw.js +3 -1
- package/lib/rc-migrate.js +44 -0
- package/lib/runtime-env-keys.js +109 -0
- package/lib/runtime-env.js +236 -0
- package/lib/sdk-bridge.js +348 -284
- package/lib/sdk-message-processor.js +117 -146
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +156 -115
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +379 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +61 -30
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/users-permissions.js +9 -6
- package/lib/users.js +9 -0
- package/lib/utils.js +4 -2
- package/lib/vendor-auth.js +22 -0
- package/lib/vendor-registry-message.js +66 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +36 -23
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +34 -0
- package/lib/yoke/adapters/claude-worker.js +57 -87
- package/lib/yoke/adapters/claude.js +182 -88
- package/lib/yoke/adapters/codex-capabilities.js +40 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +462 -211
- package/lib/yoke/adapters/effort-control.js +34 -0
- package/lib/yoke/adapters/permission-relay.js +58 -0
- package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
- package/lib/yoke/auth-checks.js +91 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +30 -56
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +84 -174
- package/lib/yoke/install-probe.js +136 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +206 -4
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +377 -0
- package/package.json +12 -9
- package/scripts/check-sdk-lock-drift.js +160 -0
- package/scripts/check-test-count.js +76 -1
- package/scripts/postinstall.js +218 -136
- package/scripts/prompt-harness-history.js +202 -0
- package/scripts/verify-installed-build.js +59 -17
- package/scripts/verify-installed.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// Runs the prompt invariant harness's named regression scenarios
|
|
4
|
+
// (test/prompt-invariants.test.js) against the lib/ of the commits before
|
|
5
|
+
// and after each past fix, and against this checkout, and prints which
|
|
6
|
+
// invariants each run violated. A scenario that fails before its fix and
|
|
7
|
+
// passes after it shows the harness would have caught that defect.
|
|
8
|
+
//
|
|
9
|
+
// A commit just after one fix can still carry defects fixed later (the
|
|
10
|
+
// banner that outlived its prompt, fixed after most of these), so the
|
|
11
|
+
// scenario as a whole may still fail there. What must hold is narrower and
|
|
12
|
+
// exact: the violation the defect causes (its signature) appears before the
|
|
13
|
+
// fix and is gone after it, and the scenario passes outright on this
|
|
14
|
+
// checkout. The run exits non-zero when any of that does not hold, or when
|
|
15
|
+
// a run fails without naming an invariant (it crashed).
|
|
16
|
+
//
|
|
17
|
+
// npm run test:prompt-history [-- --scenario <scenario-label>]
|
|
18
|
+
//
|
|
19
|
+
// Each commit's lib/ is extracted with `git archive` into a temporary
|
|
20
|
+
// directory that borrows this checkout's node_modules; nothing in the
|
|
21
|
+
// repository is modified.
|
|
22
|
+
|
|
23
|
+
var fs = require("fs");
|
|
24
|
+
var os = require("os");
|
|
25
|
+
var path = require("path");
|
|
26
|
+
var { spawnSync, execFileSync } = require("child_process");
|
|
27
|
+
|
|
28
|
+
var REPO = path.join(__dirname, "..");
|
|
29
|
+
var HARNESS = path.join(REPO, "test", "prompt-invariants.test.js");
|
|
30
|
+
|
|
31
|
+
// scenario label (as passed to scenario() in the harness) -> its test title,
|
|
32
|
+
// the defect it reproduces, the violation that defect produces in the
|
|
33
|
+
// harness's report, and the commits just before and just after its fix.
|
|
34
|
+
var MATRIX = [
|
|
35
|
+
{
|
|
36
|
+
scenario: "grant-across-restart",
|
|
37
|
+
title: "Allow for Session survives a daemon restart",
|
|
38
|
+
defect: "an Allow for Session grant was lost on daemon restart",
|
|
39
|
+
signature: /was granted for the session but prompted again \(I7\)/,
|
|
40
|
+
before: "a31b2f4", after: "0ffb16f",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
scenario: "subagent-vs-parent-result",
|
|
44
|
+
title: "a sub-agent's request survives its parent's turn result",
|
|
45
|
+
defect: "the parent turn's result dropped a sub-agent's pending request",
|
|
46
|
+
signature: /is still awaiting the operator but the server no longer offers it \(I1\)|did not settle it \(I4\)/,
|
|
47
|
+
before: "c886cf0", after: "ac18d9f",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
scenario: "skill-grant-scope",
|
|
51
|
+
title: "Allow for Session on one skill does not approve another",
|
|
52
|
+
defect: "a Skill grant was keyed on the bare tool name",
|
|
53
|
+
signature: /did not open exactly one prompt \(I7\)|was granted for the session but/,
|
|
54
|
+
before: "270f0ee", after: "e8e8bfa",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
scenario: "task-notification-before-answer",
|
|
58
|
+
title: "a Task's completion before the operator answers keeps its request answerable",
|
|
59
|
+
defect: "task_notification released half of the ownership guard",
|
|
60
|
+
signature: /the request ended before the operator answered \(I6\)/,
|
|
61
|
+
before: "b4811a2", after: "68aa87d",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
scenario: "late-second-response",
|
|
65
|
+
title: "a second client's late response is answered and every banner retires",
|
|
66
|
+
defect: "a late second response got no answer and the banner stayed",
|
|
67
|
+
signature: /is over but its notification still offers buttons \(I2\)|got no reply \(I4\)/,
|
|
68
|
+
before: "349dbc2", after: "e49bd48",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
scenario: "pending-across-restart",
|
|
72
|
+
title: "a request open across a daemon restart is not offered afterwards",
|
|
73
|
+
defect: "a request open at restart was still offered as pending",
|
|
74
|
+
signature: /still sees \S+ as pending after it ended \(I2\)/,
|
|
75
|
+
before: "e49bd48", after: "4015dbc",
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
function parseArgs(argv) {
|
|
80
|
+
var out = { scenario: null };
|
|
81
|
+
for (var i = 0; i < argv.length; i++) {
|
|
82
|
+
if (argv[i] === "--scenario") out.scenario = argv[++i];
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function escapeRegExp(s) {
|
|
88
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// A directory holding <commit>'s lib/ and a link to this checkout's
|
|
92
|
+
// node_modules, so the old modules resolve their dependencies.
|
|
93
|
+
function materializeLib(commit, root) {
|
|
94
|
+
var dir = path.join(root, commit);
|
|
95
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
96
|
+
var archive = spawnSync("git", ["-C", REPO, "archive", "--format=tar", commit, "lib"], { maxBuffer: 512 * 1024 * 1024 });
|
|
97
|
+
if (archive.status !== 0) throw new Error("git archive " + commit + " failed: " + String(archive.stderr));
|
|
98
|
+
var untar = spawnSync("tar", ["-x", "-C", dir], { input: archive.stdout });
|
|
99
|
+
if (untar.status !== 0) throw new Error("tar for " + commit + " failed: " + String(untar.stderr));
|
|
100
|
+
fs.symlinkSync(path.join(REPO, "node_modules"), path.join(dir, "node_modules"), "dir");
|
|
101
|
+
return path.join(dir, "lib");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Environment for one harness run. The un-scoped name is cleared as well as the
|
|
105
|
+
// scoped one: an inherited value of either must not steer a HEAD (libDir-less)
|
|
106
|
+
// run at an older checkout.
|
|
107
|
+
function harnessEnv(baseEnv, libDir) {
|
|
108
|
+
var env = Object.assign({}, baseEnv);
|
|
109
|
+
delete env.CLAGENTIC_PROMPT_HARNESS_LIB;
|
|
110
|
+
if (libDir) env.CLAGENTIC_CONSOLE_PROMPT_HARNESS_LIB = libDir;
|
|
111
|
+
else delete env.CLAGENTIC_CONSOLE_PROMPT_HARNESS_LIB;
|
|
112
|
+
return env;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The invariants a run violated, e.g. ["I2", "I8"], or [] for a pass.
|
|
116
|
+
function runScenario(row, libDir) {
|
|
117
|
+
var env = harnessEnv(process.env, libDir);
|
|
118
|
+
var res = spawnSync(process.execPath, [
|
|
119
|
+
"--test", "--test-reporter=tap", "--test-name-pattern=^" + escapeRegExp(row.title) + "$", HARNESS,
|
|
120
|
+
], { env: env, encoding: "utf8", maxBuffer: 256 * 1024 * 1024 });
|
|
121
|
+
var output = (res.stdout || "") + (res.stderr || "");
|
|
122
|
+
var codes = {};
|
|
123
|
+
var re = /\((I\d)(?:\/(I\d))?\)/g;
|
|
124
|
+
var m;
|
|
125
|
+
while ((m = re.exec(output)) !== null) {
|
|
126
|
+
codes[m[1]] = true;
|
|
127
|
+
if (m[2]) codes[m[2]] = true;
|
|
128
|
+
}
|
|
129
|
+
var passed = res.status === 0;
|
|
130
|
+
if (!passed && Object.keys(codes).length === 0) codes.error = true;
|
|
131
|
+
return { passed: passed, codes: Object.keys(codes).sort(), output: output };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function shows(row, result) {
|
|
135
|
+
return !result.passed && row.signature.test(result.output);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function crashed(result) {
|
|
139
|
+
return !result.passed && result.codes.indexOf("error") !== -1;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function describe(row, result) {
|
|
143
|
+
if (result.passed) return "pass";
|
|
144
|
+
return "FAIL " + result.codes.join(",") + (shows(row, result) ? "" : " (not this defect)");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* What is wrong with one scenario's three runs: before its fix the run
|
|
149
|
+
* must show the defect's own violation (else the harness does not
|
|
150
|
+
* reproduce it); after the fix that violation must be gone and the run must
|
|
151
|
+
* not have crashed (else the fix did not hold, or nothing was checked); on
|
|
152
|
+
* this checkout the scenario must pass outright.
|
|
153
|
+
* @returns {string[]} one line per problem; [] when the row holds.
|
|
154
|
+
*/
|
|
155
|
+
function rowProblems(row, before, after, now) {
|
|
156
|
+
var out = [];
|
|
157
|
+
if (!shows(row, before)) out.push(row.scenario + " does not show its defect before its fix (" + row.before + "): the harness does not reproduce it\n" + before.output);
|
|
158
|
+
if (shows(row, after) || crashed(after)) out.push(row.scenario + " still fails with its defect after its fix (" + row.after + "):\n" + after.output);
|
|
159
|
+
if (!now.passed) out.push(row.scenario + " fails on this checkout:\n" + now.output);
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function main() {
|
|
164
|
+
var args = parseArgs(process.argv.slice(2));
|
|
165
|
+
var rows = MATRIX.filter(function (r) { return !args.scenario || r.scenario === args.scenario; });
|
|
166
|
+
if (rows.length === 0) {
|
|
167
|
+
console.error("no scenario named " + args.scenario + "; known: " + MATRIX.map(function (r) { return r.scenario; }).join(", "));
|
|
168
|
+
process.exitCode = 1;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// Commits must exist locally; a shallow clone cannot reproduce history.
|
|
172
|
+
rows.forEach(function (r) {
|
|
173
|
+
[r.before, r.after].forEach(function (c) { execFileSync("git", ["-C", REPO, "cat-file", "-e", c + "^{commit}"]); });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
var root = fs.mkdtempSync(path.join(os.tmpdir(), "prompt-harness-history-"));
|
|
177
|
+
var libs = {};
|
|
178
|
+
var unexpected = [];
|
|
179
|
+
try {
|
|
180
|
+
console.log("scenario | defect | before fix | after fix | this checkout");
|
|
181
|
+
console.log("---|---|---|---|---");
|
|
182
|
+
rows.forEach(function (r) {
|
|
183
|
+
[r.before, r.after].forEach(function (c) { if (!libs[c]) libs[c] = materializeLib(c, root); });
|
|
184
|
+
var before = runScenario(r, libs[r.before]);
|
|
185
|
+
var after = runScenario(r, libs[r.after]);
|
|
186
|
+
var now = runScenario(r, null);
|
|
187
|
+
console.log([r.scenario, r.defect,
|
|
188
|
+
r.before + ": " + describe(r, before), r.after + ": " + describe(r, after), describe(r, now)].join(" | "));
|
|
189
|
+
unexpected = unexpected.concat(rowProblems(r, before, after, now));
|
|
190
|
+
});
|
|
191
|
+
} finally {
|
|
192
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
193
|
+
}
|
|
194
|
+
if (unexpected.length) {
|
|
195
|
+
console.error("\n" + unexpected.join("\n\n"));
|
|
196
|
+
process.exitCode = 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (require.main === module) main();
|
|
201
|
+
|
|
202
|
+
module.exports = { MATRIX: MATRIX, rowProblems: rowProblems, harnessEnv: harnessEnv };
|
|
@@ -73,10 +73,22 @@
|
|
|
73
73
|
// upstream (NAOMI's post-merge report, HOLDEN's operator relay) as if it
|
|
74
74
|
// meant the running service was fixed.
|
|
75
75
|
//
|
|
76
|
+
// The process leg reports exactly one of three verdicts:
|
|
77
|
+
// adopted — the daemon loaded merged HEAD AND says the installed files
|
|
78
|
+
// are the ones it loaded (sha plus content hash). An identical
|
|
79
|
+
// reinstall over a running daemon (install:local-test, a
|
|
80
|
+
// post-merge reinstall) is adopted: its "(deleted)" mappings
|
|
81
|
+
// (staleInodes) are reported but do not decide it.
|
|
82
|
+
// stale — the daemon loaded a different build than the installed one;
|
|
83
|
+
// both shas are printed. Exit 1.
|
|
84
|
+
// inconclusive — the check cannot say (no daemon, a daemon that predates
|
|
85
|
+
// the status query or the content comparison); the reason is
|
|
86
|
+
// printed. Exit 0, and never read as adopted.
|
|
87
|
+
//
|
|
76
88
|
// Exit codes:
|
|
77
|
-
// 0 — ARTIFACT_AND_PROCESS_VERIFIED: installed build-sha.json
|
|
78
|
-
// merged HEAD AND the running daemon
|
|
79
|
-
//
|
|
89
|
+
// 0 — ARTIFACT_AND_PROCESS_VERIFIED (adopted): installed build-sha.json
|
|
90
|
+
// matches merged HEAD AND the running daemon loaded that same SHA and
|
|
91
|
+
// reports the installed files are the ones it loaded.
|
|
80
92
|
// — ARTIFACT_VERIFIED_NO_PROCESS: installed build-sha.json matches
|
|
81
93
|
// merged HEAD and no daemon is currently running, so the PROCESS
|
|
82
94
|
// CHECK DID NOT RUN. The service's build status is UNKNOWN, not
|
|
@@ -85,9 +97,9 @@
|
|
|
85
97
|
// never be read as "the service is fine".
|
|
86
98
|
// 1 — ARTIFACT_MISMATCH: installed build-sha.json does not match merged
|
|
87
99
|
// HEAD (PART 1's original failure mode, unchanged).
|
|
88
|
-
// — PROCESS_MISMATCH: the artifact matches, but the running
|
|
89
|
-
// loaded SHA differs from merged HEAD, or the daemon itself
|
|
90
|
-
//
|
|
100
|
+
// — PROCESS_MISMATCH (stale): the artifact matches, but the running
|
|
101
|
+
// daemon's loaded SHA differs from merged HEAD, or the daemon itself
|
|
102
|
+
// reports the installed build differs from the one it loaded. THIS is
|
|
91
103
|
// the failure mode that would have caught 2026-08-25 at 01:48 — see
|
|
92
104
|
// test/verify-installed-build-lr-dc9a3b.test.js for the
|
|
93
105
|
// demonstrated-failure-before-fix simulation.
|
|
@@ -116,6 +128,11 @@ const fs = require('fs');
|
|
|
116
128
|
const path = require('path');
|
|
117
129
|
const { execFileSync } = require('child_process');
|
|
118
130
|
|
|
131
|
+
// Never done by this check (see the NON-GOAL in the header comment).
|
|
132
|
+
const APPLY_IS_THE_OPERATORS =
|
|
133
|
+
'The artifact on disk is correct; the SERVICE is still serving the old build. Applying it is the ' +
|
|
134
|
+
'operator\'s decision: the "Restart to apply update" action in the Clagentic: Console UI offers it.';
|
|
135
|
+
|
|
119
136
|
function resolveHeadSha() {
|
|
120
137
|
return execFileSync('git', ['rev-parse', 'HEAD'], {
|
|
121
138
|
cwd: path.join(__dirname, '..'),
|
|
@@ -208,6 +225,13 @@ function resolveProcessBuildStatus(cliBin) {
|
|
|
208
225
|
return {
|
|
209
226
|
running: true,
|
|
210
227
|
loadedBuildSha: parsed.loadedBuildSha,
|
|
228
|
+
// The daemon's own verdict (adopted | stale | inconclusive) on whether
|
|
229
|
+
// the installed build is the one it loaded: sha plus a content hash of
|
|
230
|
+
// the installed files. Absent from a daemon that predates it.
|
|
231
|
+
installedBuildSha: parsed.installedBuildSha,
|
|
232
|
+
state: parsed.state,
|
|
233
|
+
reason: parsed.reason,
|
|
234
|
+
detail: parsed.detail,
|
|
211
235
|
staleInodes: !!parsed.staleInodes,
|
|
212
236
|
pid: parsed.pid,
|
|
213
237
|
};
|
|
@@ -254,7 +278,7 @@ function main() {
|
|
|
254
278
|
|
|
255
279
|
if (!processStatus.running) {
|
|
256
280
|
console.log(
|
|
257
|
-
'[verify-installed-build] ARTIFACT_VERIFIED_NO_PROCESS:
|
|
281
|
+
'[verify-installed-build] ARTIFACT_VERIFIED_NO_PROCESS: inconclusive. Artifact matches merged HEAD ' +
|
|
258
282
|
`(${headSha}); no daemon is running, so the PROCESS CHECK DID NOT RUN and the process ` +
|
|
259
283
|
'build status is UNKNOWN -- do not read this as the process/service being verified. ' +
|
|
260
284
|
'Not a failure: there is no running process to compare against yet.'
|
|
@@ -270,7 +294,7 @@ function main() {
|
|
|
270
294
|
// transport error). This is NOT read as "verified": the build status of
|
|
271
295
|
// the running process is explicitly UNKNOWN pending a restart.
|
|
272
296
|
console.log(
|
|
273
|
-
'[verify-installed-build] STALE_PROCESS:
|
|
297
|
+
'[verify-installed-build] STALE_PROCESS: inconclusive. Artifact matches merged HEAD ' +
|
|
274
298
|
`(${headSha}); the running daemon does not recognize the get_build_status query, ` +
|
|
275
299
|
'meaning it predates that handler and has not picked up any build since. The PROCESS build ' +
|
|
276
300
|
'status is UNKNOWN, NOT VERIFIED (PROCESS check inconclusive) -- restart the daemon to ' +
|
|
@@ -281,22 +305,40 @@ function main() {
|
|
|
281
305
|
return;
|
|
282
306
|
}
|
|
283
307
|
|
|
308
|
+
// stale: the process loaded a different build than the one installed, or the
|
|
309
|
+
// daemon itself says the installed files differ from what it loaded.
|
|
310
|
+
// staleInodes does not decide this: an identical reinstall (install:local-test,
|
|
311
|
+
// a post-merge reinstall) unlinks files the daemon keeps mapped without
|
|
312
|
+
// changing anything it runs.
|
|
284
313
|
const processMismatch = processStatus.loadedBuildSha !== headSha;
|
|
285
|
-
if (processMismatch || processStatus.
|
|
314
|
+
if (processMismatch || processStatus.state === 'stale') {
|
|
315
|
+
const daemonStale = processStatus.state === 'stale';
|
|
316
|
+
const installedSha = (daemonStale && processStatus.installedBuildSha) || headSha;
|
|
317
|
+
const why = daemonStale && processStatus.detail ? ` (${processStatus.detail})` : '';
|
|
286
318
|
console.error(
|
|
287
|
-
`[verify-installed-build] PROCESS_MISMATCH:
|
|
288
|
-
`
|
|
289
|
-
`
|
|
290
|
-
`The artifact on disk is correct; the SERVICE is still serving the old build. ` +
|
|
291
|
-
`Restart the daemon to load the new build: systemctl restart clagentic-console ` +
|
|
292
|
-
`(NOT done automatically by this check -- see this script's header comment for why).`
|
|
319
|
+
`[verify-installed-build] PROCESS_MISMATCH: stale. The RUNNING daemon (PID ${processStatus.pid}) has NOT ` +
|
|
320
|
+
`loaded the installed build. loadedBuildSha=${processStatus.loadedBuildSha || '(none)'} ` +
|
|
321
|
+
`installedBuildSha=${installedSha}${why}. ${APPLY_IS_THE_OPERATORS}`
|
|
293
322
|
);
|
|
294
323
|
process.exit(1);
|
|
295
324
|
}
|
|
296
325
|
|
|
326
|
+
if (processStatus.state !== 'adopted') {
|
|
327
|
+
// The shas agree but the daemon did not say the installed files are the
|
|
328
|
+
// ones it loaded (it predates that comparison, or could not read them).
|
|
329
|
+
console.log(
|
|
330
|
+
`[verify-installed-build] PROCESS_INCONCLUSIVE: inconclusive. The running daemon (PID ${processStatus.pid}) ` +
|
|
331
|
+
`loaded merged HEAD (${headSha}), but the PROCESS check cannot confirm it adopted the installed files: ` +
|
|
332
|
+
`${processStatus.detail || 'the daemon predates the content comparison'}. ` +
|
|
333
|
+
`Process build status is UNKNOWN, NOT VERIFIED. Not a failure.`
|
|
334
|
+
);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
297
338
|
console.log(
|
|
298
|
-
`[verify-installed-build] ARTIFACT_AND_PROCESS_VERIFIED: installed build-sha.json AND the ` +
|
|
299
|
-
`running daemon (PID ${processStatus.pid}) both match merged HEAD (${headSha}),
|
|
339
|
+
`[verify-installed-build] ARTIFACT_AND_PROCESS_VERIFIED: adopted. The installed build-sha.json AND the ` +
|
|
340
|
+
`running daemon (PID ${processStatus.pid}) both match merged HEAD (${headSha}), and the installed files ` +
|
|
341
|
+
`are the ones the daemon loaded (staleInodes=${processStatus.staleInodes} is informational).`
|
|
300
342
|
);
|
|
301
343
|
}
|
|
302
344
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// verify-installed.js — entry point of `npm run verify:installed-build`.
|
|
5
|
+
//
|
|
6
|
+
// Runs the two independent post-merge checks and reports each result:
|
|
7
|
+
// installed-build scripts/verify-installed-build.js (installed files + running process vs merged HEAD)
|
|
8
|
+
// sdk-lock-drift scripts/check-sdk-lock-drift.js (installed SDK versions vs the lock)
|
|
9
|
+
//
|
|
10
|
+
// They were chained with `&&`, so verify-installed-build's PROCESS_MISMATCH —
|
|
11
|
+
// expected after every merge until the daemon restarts — stopped the drift check
|
|
12
|
+
// from ever running. Neither result says anything about the other, so both always
|
|
13
|
+
// run, each result is printed, and the exit code is non-zero if either failed.
|
|
14
|
+
//
|
|
15
|
+
// TOOL CONSIDERED: `a; b` / `a || true` in the npm script. A shell separator
|
|
16
|
+
// would run both but lose each exit status (or need extra shell to recover it),
|
|
17
|
+
// and loadout-merge rejects shell operator tokens in post_merge_steps commands.
|
|
18
|
+
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const { spawnSync } = require('child_process');
|
|
21
|
+
|
|
22
|
+
const CHECKS = [
|
|
23
|
+
{ name: 'installed-build', script: 'verify-installed-build.js' },
|
|
24
|
+
{ name: 'sdk-lock-drift', script: 'check-sdk-lock-drift.js' },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const TAG = '[verify:installed-build]';
|
|
28
|
+
|
|
29
|
+
function spawnScript(scriptPath) {
|
|
30
|
+
const res = spawnSync(process.execPath, [scriptPath], { stdio: 'inherit' });
|
|
31
|
+
if (res.error) return { status: 1, error: res.error.message };
|
|
32
|
+
return { status: res.status === null ? 1 : res.status, signal: res.signal };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {object} [opts]
|
|
37
|
+
* @param {Array<{name:string, script:string}>} [opts.checks]
|
|
38
|
+
* @param {string} [opts.scriptsDir]
|
|
39
|
+
* @param {function} [opts.runScript] (absPath) => {status, error?}; for tests.
|
|
40
|
+
* @param {function} [opts.log]
|
|
41
|
+
* @returns {{ok: boolean, results: Array<{name:string, status:number}>}}
|
|
42
|
+
*/
|
|
43
|
+
function runAll(opts) {
|
|
44
|
+
opts = opts || {};
|
|
45
|
+
const checks = opts.checks || CHECKS;
|
|
46
|
+
const scriptsDir = opts.scriptsDir || __dirname;
|
|
47
|
+
const runScript = opts.runScript || spawnScript;
|
|
48
|
+
const log = opts.log || ((m) => console.log(m));
|
|
49
|
+
|
|
50
|
+
const results = [];
|
|
51
|
+
for (const check of checks) {
|
|
52
|
+
const res = runScript(path.join(scriptsDir, check.script));
|
|
53
|
+
const status = res.status;
|
|
54
|
+
results.push({ name: check.name, status });
|
|
55
|
+
log(`${TAG} ${check.name}: ${status === 0 ? 'PASS' : 'FAIL'} (exit ${status}${res.error ? `: ${res.error}` : ''})`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const failed = results.filter((r) => r.status !== 0);
|
|
59
|
+
log(`${TAG} ${failed.length === 0 ? 'all checks passed' : `FAILED: ${failed.map((r) => r.name).join(', ')}`}`);
|
|
60
|
+
return { ok: failed.length === 0, results };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { runAll, CHECKS };
|
|
64
|
+
|
|
65
|
+
if (require.main === module) {
|
|
66
|
+
process.exit(runAll().ok ? 0 : 1);
|
|
67
|
+
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
// lr-9d4b: Shared keep-vs-clear decision for session.pendingPermissions /
|
|
2
|
-
// activeTaskToolIds / taskIdMap at turn-boundary cleanup sites.
|
|
3
|
-
//
|
|
4
|
-
// Two call sites reset this same state at the end of a turn:
|
|
5
|
-
// - sdk-message-processor.js: the 'result' message handler
|
|
6
|
-
// - sdk-bridge.js: processQueryStream's finally block (normal, non-
|
|
7
|
-
// superseded completion)
|
|
8
|
-
// Both used to unconditionally wipe session.pendingPermissions, which
|
|
9
|
-
// destroys a backgrounded sub-agent's still-open permission resolver if the
|
|
10
|
-
// sub-agent's own tool call (e.g. Bash) is still awaiting the operator's
|
|
11
|
-
// approval when the parent turn ends. The permission card stays on the UI,
|
|
12
|
-
// but the resolver is gone, so the sub-agent's canUseTool Promise (no
|
|
13
|
-
// timeout on the in-process path) hangs forever (lr-9d4b root cause).
|
|
14
|
-
//
|
|
15
|
-
// This module computes which entries are owned by a still-active
|
|
16
|
-
// backgrounded sub-agent (via session.subagentToolOwners, recorded in
|
|
17
|
-
// processSubagentMessage) so both cleanup sites can preserve them instead of
|
|
18
|
-
// wiping them, mirroring the existing _keepAskUser preservation pattern for
|
|
19
|
-
// session.pendingAskUser (mcp-mode entries survive the same cleanup sites).
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Partition session.pendingPermissions into entries to keep (owned by a
|
|
23
|
-
* still-active backgrounded sub-agent) vs. the rest (top-level, or a
|
|
24
|
-
* sub-agent whose owning Task has already finished) — the latter are
|
|
25
|
-
* cleared exactly as before.
|
|
26
|
-
*
|
|
27
|
-
* @param {object} session - session object with pendingPermissions,
|
|
28
|
-
* subagentToolOwners, activeTaskToolIds.
|
|
29
|
-
* @returns {{keptPermissions: object, preservedTaskIds: object}}
|
|
30
|
-
* keptPermissions: requestId -> pending entry, to become the new
|
|
31
|
-
* session.pendingPermissions.
|
|
32
|
-
* preservedTaskIds: Task tool-use id -> true, for the caller to also keep
|
|
33
|
-
* the corresponding activeTaskToolIds/taskIdMap entries (the sub-agent's
|
|
34
|
-
* bookkeeping must survive alongside its pending permission).
|
|
35
|
-
*/
|
|
36
|
-
function partitionSubagentOwnedPermissions(session) {
|
|
37
|
-
var keptPermissions = {};
|
|
38
|
-
var pendingPermissions = session.pendingPermissions || {};
|
|
39
|
-
var subagentToolOwners = session.subagentToolOwners || {};
|
|
40
|
-
var activeTaskToolIds = session.activeTaskToolIds || {};
|
|
41
|
-
|
|
42
|
-
var permissionIds = Object.keys(pendingPermissions);
|
|
43
|
-
for (var i = 0; i < permissionIds.length; i++) {
|
|
44
|
-
var pid = permissionIds[i];
|
|
45
|
-
var pentry = pendingPermissions[pid];
|
|
46
|
-
var owningTaskId = pentry && pentry.toolUseId ? subagentToolOwners[pentry.toolUseId] : null;
|
|
47
|
-
if (owningTaskId && activeTaskToolIds[owningTaskId]) {
|
|
48
|
-
keptPermissions[pid] = pentry;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
var preservedTaskIds = {};
|
|
53
|
-
for (var kpid in keptPermissions) {
|
|
54
|
-
var kpTaskId = subagentToolOwners[keptPermissions[kpid].toolUseId];
|
|
55
|
-
preservedTaskIds[kpTaskId] = true;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return { keptPermissions: keptPermissions, preservedTaskIds: preservedTaskIds };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// lr-f940 (N3, top-3): sm.permissionRequestIndex[requestId] -> session.localId
|
|
62
|
-
// is written once per permission request (sdk-bridge.js handleCanUseTool) and
|
|
63
|
-
// is normally deleted in exactly two places: the user-driven permission_response
|
|
64
|
-
// handler (project-sessions.js) and the opts.signal "abort" listener
|
|
65
|
-
// (sdk-bridge.js). Both turn-boundary cleanup sites that call
|
|
66
|
-
// partitionSubagentOwnedPermissions() (the 'result' message handler in
|
|
67
|
-
// sdk-message-processor.js, and processQueryStream's finally block in
|
|
68
|
-
// sdk-bridge.js) drop entries from session.pendingPermissions wholesale
|
|
69
|
-
// (everything not in keptPermissions) without ever touching
|
|
70
|
-
// sm.permissionRequestIndex, so the dropped requestIds' index entries persist
|
|
71
|
-
// for the life of the daemon. On the WORKER path this is the ONLY cleanup that
|
|
72
|
-
// ever runs for those entries: the worker's canUseTool bridge (yoke/adapters/
|
|
73
|
-
// claude.js) passes a fake `signal: { addEventListener: function() {} }` to
|
|
74
|
-
// the in-process canUseTool, so the abort-listener deletion path is a no-op —
|
|
75
|
-
// the index entry is orphaned unconditionally once the turn ends.
|
|
76
|
-
//
|
|
77
|
-
// Call this immediately after reassigning session.pendingPermissions to
|
|
78
|
-
// keptPermissions, passing the PRE-reassignment map, so every entry that was
|
|
79
|
-
// dropped (i.e. not preserved for a still-active backgrounded sub-agent) is
|
|
80
|
-
// swept from sm.permissionRequestIndex and its orphaned resolver is settled
|
|
81
|
-
// with a deny — an SDK canUseTool Promise left unresolved forever is itself a
|
|
82
|
-
// (smaller) leak on top of the index leak.
|
|
83
|
-
//
|
|
84
|
-
// @param {object} sm - the session manager (owns permissionRequestIndex).
|
|
85
|
-
// @param {object} prevPendingPermissions - session.pendingPermissions as it
|
|
86
|
-
// was BEFORE this cleanup pass reassigned it to keptPermissions.
|
|
87
|
-
// @param {object} keptPermissions - the entries being preserved (from
|
|
88
|
-
// partitionSubagentOwnedPermissions's return value).
|
|
89
|
-
function sweepClearedPermissionIndex(sm, prevPendingPermissions, keptPermissions) {
|
|
90
|
-
// Production sm always carries permissionRequestIndex (lib/sessions.js
|
|
91
|
-
// initializes it unconditionally) — this guard exists only so a caller
|
|
92
|
-
// without one (e.g. a minimal test double predating this sweep) is a
|
|
93
|
-
// no-op, matching its pre-existing behavior exactly rather than gaining a
|
|
94
|
-
// new side effect it never asked for.
|
|
95
|
-
if (!sm || !sm.permissionRequestIndex) return;
|
|
96
|
-
var prevIds = Object.keys(prevPendingPermissions || {});
|
|
97
|
-
for (var i = 0; i < prevIds.length; i++) {
|
|
98
|
-
var pid = prevIds[i];
|
|
99
|
-
if (keptPermissions && keptPermissions[pid]) continue; // still owned, not dropped
|
|
100
|
-
delete sm.permissionRequestIndex[pid];
|
|
101
|
-
// Settle the orphaned resolver too — an abandoned canUseTool Promise is
|
|
102
|
-
// itself a (smaller) leak on top of the index leak (lr-f940).
|
|
103
|
-
var droppedEntry = prevPendingPermissions[pid];
|
|
104
|
-
if (droppedEntry && typeof droppedEntry.resolve === "function") {
|
|
105
|
-
try { droppedEntry.resolve({ behavior: "deny", message: "Session turn ended" }); }
|
|
106
|
-
catch (e) { /* resolver already settled or threw — nothing further to do */ }
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Apply the partition result to activeTaskToolIds/taskIdMap, keeping only
|
|
113
|
-
* entries for Task ids whose permission was just preserved.
|
|
114
|
-
*
|
|
115
|
-
* @param {object} session
|
|
116
|
-
* @param {object} preservedTaskIds - from partitionSubagentOwnedPermissions.
|
|
117
|
-
*/
|
|
118
|
-
function retainPreservedTaskBookkeeping(session, preservedTaskIds) {
|
|
119
|
-
var nextActiveTaskToolIds = {};
|
|
120
|
-
for (var atk in (session.activeTaskToolIds || {})) {
|
|
121
|
-
if (preservedTaskIds[atk]) nextActiveTaskToolIds[atk] = session.activeTaskToolIds[atk];
|
|
122
|
-
}
|
|
123
|
-
session.activeTaskToolIds = nextActiveTaskToolIds;
|
|
124
|
-
|
|
125
|
-
var nextTaskIdMap = {};
|
|
126
|
-
for (var tik in (session.taskIdMap || {})) {
|
|
127
|
-
if (preservedTaskIds[tik]) nextTaskIdMap[tik] = session.taskIdMap[tik];
|
|
128
|
-
}
|
|
129
|
-
session.taskIdMap = nextTaskIdMap;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
module.exports = {
|
|
133
|
-
partitionSubagentOwnedPermissions: partitionSubagentOwnedPermissions,
|
|
134
|
-
retainPreservedTaskBookkeeping: retainPreservedTaskBookkeeping,
|
|
135
|
-
sweepClearedPermissionIndex: sweepClearedPermissionIndex,
|
|
136
|
-
};
|