@christang/keel 5.178.0 → 5.180.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/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +162 -6
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -1
- package/scripts/await_registry.js +72 -0
- package/scripts/validate_plugin.py +384 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.180.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
package/README.md
CHANGED
|
@@ -1003,7 +1003,7 @@ keel --init [--target <t>] [--dry-run] [--force-template-update]
|
|
|
1003
1003
|
keel --install [--target <t>] [--dry-run] [--force-template-update] [--with-git-hooks]
|
|
1004
1004
|
keel --check | --doctor [--target <t>]
|
|
1005
1005
|
keel --uninstall | --clear [--target <t>] [--dry-run] # --clear is the same removal
|
|
1006
|
-
keel --update [--dry-run] [--source <npm package or git spec>]
|
|
1006
|
+
keel --update [--dry-run] [--source <npm package or git spec>] [--adopt] # --adopt: restart idle background sessions on the new plugin
|
|
1007
1007
|
keel --version | --help
|
|
1008
1008
|
|
|
1009
1009
|
# OpenSpec, through the CLI Keel bundles
|
package/README.zh-CN.md
CHANGED
|
@@ -846,7 +846,7 @@ keel --init [--target <t>] [--dry-run] [--force-template-update]
|
|
|
846
846
|
keel --install [--target <t>] [--dry-run] [--force-template-update] [--with-git-hooks]
|
|
847
847
|
keel --check | --doctor [--target <t>]
|
|
848
848
|
keel --uninstall | --clear [--target <t>] [--dry-run] # --clear 是同一种移除
|
|
849
|
-
keel --update [--dry-run] [--source <npm package or git spec>]
|
|
849
|
+
keel --update [--dry-run] [--source <npm package or git spec>] [--adopt] # --adopt:让空闲的后台会话重启到新插件上
|
|
850
850
|
keel --version | --help
|
|
851
851
|
|
|
852
852
|
# OpenSpec,通过 Keel 捆绑的 CLI 运行
|
package/bin/keel.js
CHANGED
|
@@ -106,7 +106,7 @@ Usage:
|
|
|
106
106
|
keel --install [repo] [--target claude|codex|opencode] [--dry-run] [--force-template-update] [--with-git-hooks]
|
|
107
107
|
keel --clear [repo] [--target claude|codex|opencode] [--dry-run]
|
|
108
108
|
keel --uninstall [repo] [--target claude|codex|opencode] [--dry-run]
|
|
109
|
-
keel --update [--dry-run] [--source npm-package-or-git-spec]
|
|
109
|
+
keel --update [--dry-run] [--source npm-package-or-git-spec] [--adopt]
|
|
110
110
|
keel --check [repo] [--target claude|codex|opencode]
|
|
111
111
|
keel --doctor [repo] [--target claude|codex|opencode]
|
|
112
112
|
keel --version
|
|
@@ -179,6 +179,7 @@ function parseArgs(argv) {
|
|
|
179
179
|
forceTemplateUpdate: false,
|
|
180
180
|
withGitHooks: false,
|
|
181
181
|
updateSource: null,
|
|
182
|
+
adopt: false,
|
|
182
183
|
help: false,
|
|
183
184
|
version: false,
|
|
184
185
|
change: null,
|
|
@@ -355,6 +356,10 @@ function parseArgs(argv) {
|
|
|
355
356
|
parsed.withGitHooks = true;
|
|
356
357
|
continue;
|
|
357
358
|
}
|
|
359
|
+
if (arg === "--adopt") {
|
|
360
|
+
parsed.adopt = true;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
358
363
|
if (arg === "--target") {
|
|
359
364
|
index += 1;
|
|
360
365
|
if (index >= argv.length) {
|
|
@@ -987,7 +992,12 @@ function claudeKeel(executable) {
|
|
|
987
992
|
const entry = (Array.isArray(listed) ? listed : [])
|
|
988
993
|
.find((item) => item && typeof item.id === "string" && item.id.startsWith("keel@"));
|
|
989
994
|
if (!entry) return null;
|
|
990
|
-
return {
|
|
995
|
+
return {
|
|
996
|
+
id: entry.id,
|
|
997
|
+
market: entry.id.slice("keel@".length),
|
|
998
|
+
version: entry.version || null,
|
|
999
|
+
lastUpdated: entry.lastUpdated || null,
|
|
1000
|
+
};
|
|
991
1001
|
}
|
|
992
1002
|
|
|
993
1003
|
// The Codex marketplace needs only its catalog and the plugin it names; a
|
|
@@ -1050,7 +1060,28 @@ function versionChange(before, after) {
|
|
|
1050
1060
|
return before && after && before !== after ? `updated ${before} -> ${after}` : `current ${after || before || "unknown"}`;
|
|
1051
1061
|
}
|
|
1052
1062
|
|
|
1053
|
-
|
|
1063
|
+
// Right after a release the Claude marketplace, read from Git, names a version
|
|
1064
|
+
// the npm registry this machine reaches does not serve yet, and the plugin
|
|
1065
|
+
// update exits with npm's E404; a rerun minutes later succeeds (#421). That is
|
|
1066
|
+
// read as lag only when the registry's own latest is older than the version
|
|
1067
|
+
// asked for; an E404 the registry cannot explain stays a failure.
|
|
1068
|
+
function registryLag(result, npm) {
|
|
1069
|
+
const said = `${result.stdout || ""}\n${result.stderr || ""}`;
|
|
1070
|
+
const match = /E404 No match found for version (\d+\.\d+\.\d+[^\s'"]*)/.exec(said);
|
|
1071
|
+
if (!match) return null;
|
|
1072
|
+
const limit = Number(process.env.KEEL_UPDATE_QUERY_TIMEOUT_MS) || 30 * 1000;
|
|
1073
|
+
const view = spawnSync(npm, ["view", PACKAGE_JSON.name, "version", "--prefer-online"], {
|
|
1074
|
+
encoding: "utf8",
|
|
1075
|
+
shell: process.platform === "win32",
|
|
1076
|
+
timeout: limit,
|
|
1077
|
+
});
|
|
1078
|
+
if (view.error || view.status !== 0) return null;
|
|
1079
|
+
const latest = String(view.stdout || "").trim();
|
|
1080
|
+
if (!/^\d+\.\d+\.\d+/.test(latest) || compareVersions(match[1], latest) <= 0) return null;
|
|
1081
|
+
return { wanted: match[1], latest };
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function updateClaudePlugin(options, npm) {
|
|
1054
1085
|
const component = "claude plugin";
|
|
1055
1086
|
const executable = process.env.KEEL_UPDATE_CLAUDE || "claude";
|
|
1056
1087
|
const queried = claudeKeel(executable);
|
|
@@ -1078,7 +1109,21 @@ function updateClaudePlugin(options) {
|
|
|
1078
1109
|
updateLine(component, "failed", `\`claude ${steps[0].join(" ")}\` failed twice; ${hostFailure(refreshed)}`);
|
|
1079
1110
|
return false;
|
|
1080
1111
|
}
|
|
1081
|
-
|
|
1112
|
+
const updated = hostRun(executable, steps[1]);
|
|
1113
|
+
if (updated.error || updated.status !== 0) {
|
|
1114
|
+
const lag = registryLag(updated, npm);
|
|
1115
|
+
if (lag) {
|
|
1116
|
+
updateLine(
|
|
1117
|
+
component,
|
|
1118
|
+
"pending",
|
|
1119
|
+
`the npm registry here does not serve ${lag.wanted} yet (its latest is ${lag.latest}); `
|
|
1120
|
+
+ "rerun keel --update in a few minutes"
|
|
1121
|
+
);
|
|
1122
|
+
return true;
|
|
1123
|
+
}
|
|
1124
|
+
updateLine(component, "failed", `\`claude ${steps[1].join(" ")}\` ${hostFailure(updated)}`);
|
|
1125
|
+
return false;
|
|
1126
|
+
}
|
|
1082
1127
|
const after = claudeKeel(executable);
|
|
1083
1128
|
if (after && after.failed) {
|
|
1084
1129
|
updateLine(component, "failed", `${after.failed} after the update, so its result is unverified`);
|
|
@@ -1303,7 +1348,17 @@ function updateGlobalCli(options, npm, source) {
|
|
|
1303
1348
|
return false;
|
|
1304
1349
|
}
|
|
1305
1350
|
const packed = /-(\d+\.\d+\.\d+[^/]*?)\.tgz$/.exec(path.basename(tarball));
|
|
1306
|
-
|
|
1351
|
+
// From the default source the packed version is the registry's latest as
|
|
1352
|
+
// this machine sees it, which is what `current` means right after a
|
|
1353
|
+
// release whose version has not reached that registry yet (#421).
|
|
1354
|
+
const latest = packed && source === DEFAULT_UPDATE_SOURCE
|
|
1355
|
+
? `the npm registry's latest here is ${packed[1]}; `
|
|
1356
|
+
: "";
|
|
1357
|
+
updateLine(
|
|
1358
|
+
"cli",
|
|
1359
|
+
versionChange(PACKAGE_JSON.version, packed ? packed[1] : null),
|
|
1360
|
+
`${latest}applies to the next command that runs keel`
|
|
1361
|
+
);
|
|
1307
1362
|
return true;
|
|
1308
1363
|
} catch (error) {
|
|
1309
1364
|
updateLine("cli", "failed", error.message);
|
|
@@ -1332,12 +1387,107 @@ function runGlobalUpdate(options) {
|
|
|
1332
1387
|
// leaves the others to report, and any failure fails the command.
|
|
1333
1388
|
const results = [
|
|
1334
1389
|
updateGlobalCli(options, npm, source),
|
|
1335
|
-
updateClaudePlugin(options),
|
|
1390
|
+
updateClaudePlugin(options, npm),
|
|
1391
|
+
adoptClaudeSessions(options),
|
|
1336
1392
|
updateCodexPlugin(options),
|
|
1337
1393
|
];
|
|
1338
1394
|
return results.every(Boolean) ? 0 : 1;
|
|
1339
1395
|
}
|
|
1340
1396
|
|
|
1397
|
+
function waitForExit(pid, limitMs) {
|
|
1398
|
+
if (!Number.isInteger(pid) || pid <= 0) return true;
|
|
1399
|
+
const deadline = Date.now() + limitMs;
|
|
1400
|
+
for (;;) {
|
|
1401
|
+
try {
|
|
1402
|
+
process.kill(pid, 0);
|
|
1403
|
+
} catch {
|
|
1404
|
+
return true;
|
|
1405
|
+
}
|
|
1406
|
+
if (Date.now() >= deadline) return false;
|
|
1407
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
// A Claude background session keeps the plugin it loaded (#424). A hand-over
|
|
1412
|
+
// adopts the update, because it starts a new process; a session that does not
|
|
1413
|
+
// change shift stays on the old one. Each running background session started
|
|
1414
|
+
// before the installed plugin's `lastUpdated` is named, and with --adopt each
|
|
1415
|
+
// idle one is restarted: `claude stop`, a wait for its process to exit (a
|
|
1416
|
+
// resume before that starts a copy, #395), then `claude --bg --resume <id>`
|
|
1417
|
+
// with no prompt and no flag, which keeps its id and runs no turn (measured
|
|
1418
|
+
// 2026-10-21, Claude Code 2.1.304). A busy or waiting session, one under a
|
|
1419
|
+
// task's write guard, and the session running this are left.
|
|
1420
|
+
function adoptClaudeSessions(options) {
|
|
1421
|
+
const component = "claude sessions";
|
|
1422
|
+
const executable = process.env.KEEL_UPDATE_CLAUDE || "claude";
|
|
1423
|
+
if (options.dryRun) {
|
|
1424
|
+
if (options.adopt) {
|
|
1425
|
+
process.stdout.write("keel: would restart each idle background session started before the installed plugin: "
|
|
1426
|
+
+ "claude stop <id>, then claude --bg --resume <session id>\n");
|
|
1427
|
+
}
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
const plugin = claudeKeel(executable);
|
|
1431
|
+
const updatedAt = Date.parse((plugin && plugin.lastUpdated) || "");
|
|
1432
|
+
if (!plugin || plugin.failed || !Number.isFinite(updatedAt)) return true;
|
|
1433
|
+
const listed = hostQuery(executable, ["agents", "--json"]);
|
|
1434
|
+
const rows = !listed.failed && Array.isArray(listed.json) ? listed.json : null;
|
|
1435
|
+
if (!rows) {
|
|
1436
|
+
if (!options.adopt) return true;
|
|
1437
|
+
updateLine(component, "failed", `\`claude agents --json\` ${listed.failed || "listed no sessions"}, so none was adopted`);
|
|
1438
|
+
return false;
|
|
1439
|
+
}
|
|
1440
|
+
const own = process.env.CLAUDE_CODE_SESSION_ID || "";
|
|
1441
|
+
const older = rows.filter((row) => row && row.kind === "background" && row.status && row.sessionId
|
|
1442
|
+
&& row.sessionId !== own && Number(row.startedAt) < updatedAt);
|
|
1443
|
+
if (older.length === 0) return true;
|
|
1444
|
+
const named = (row) => `${row.name || row.sessionId.slice(0, 8)} (${row.id || row.sessionId.slice(0, 8)})`;
|
|
1445
|
+
if (!options.adopt) {
|
|
1446
|
+
updateLine(component, "manual", `${older.length} started before the plugin was installed and still run the skills they loaded: `
|
|
1447
|
+
+ `${older.map(named).join(", ")}; \`keel --update --adopt\` restarts the idle ones, and a shift change starts its new session on the installed plugin`);
|
|
1448
|
+
return true;
|
|
1449
|
+
}
|
|
1450
|
+
const adopted = [];
|
|
1451
|
+
const left = [];
|
|
1452
|
+
const failed = [];
|
|
1453
|
+
for (const row of older) {
|
|
1454
|
+
if (row.status !== "idle") {
|
|
1455
|
+
left.push(`${named(row)}, ${row.status}`);
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
if (row.cwd && fs.existsSync(path.join(row.cwd, "keel", "guard.json"))) {
|
|
1459
|
+
left.push(`${named(row)}, under a task's write guard`);
|
|
1460
|
+
continue;
|
|
1461
|
+
}
|
|
1462
|
+
const stopped = hostRun(executable, ["stop", row.id || row.sessionId.slice(0, 8)]);
|
|
1463
|
+
if (stopped.error || stopped.status !== 0) {
|
|
1464
|
+
failed.push(`${named(row)}: \`claude stop\` ${hostFailure(stopped)}`);
|
|
1465
|
+
continue;
|
|
1466
|
+
}
|
|
1467
|
+
if (!waitForExit(Number(row.pid), 15 * 1000)) {
|
|
1468
|
+
failed.push(`${named(row)}: its process ${row.pid} was still running 15 s after \`claude stop\``);
|
|
1469
|
+
continue;
|
|
1470
|
+
}
|
|
1471
|
+
const resumed = spawnSync(executable, ["--bg", "--resume", row.sessionId], {
|
|
1472
|
+
encoding: "utf8",
|
|
1473
|
+
cwd: row.cwd && fs.existsSync(row.cwd) ? row.cwd : undefined,
|
|
1474
|
+
shell: process.platform === "win32",
|
|
1475
|
+
timeout: 60 * 1000,
|
|
1476
|
+
});
|
|
1477
|
+
if (resumed.error || resumed.status !== 0) {
|
|
1478
|
+
failed.push(`${named(row)}: \`claude --bg --resume\` ${hostFailure(resumed)}; \`claude attach ${row.id || row.sessionId.slice(0, 8)}\` reopens it`);
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
adopted.push(named(row));
|
|
1482
|
+
}
|
|
1483
|
+
const parts = [];
|
|
1484
|
+
if (adopted.length) parts.push(`adopted ${adopted.join(", ")} — restarted on the installed plugin, same session, no turn run`);
|
|
1485
|
+
if (left.length) parts.push(`left ${left.join("; ")} — each adopts at its next shift change or another --adopt`);
|
|
1486
|
+
if (failed.length) parts.push(`could not adopt ${failed.join("; ")}`);
|
|
1487
|
+
updateLine(component, failed.length ? "failed" : "updated", parts.join("; "));
|
|
1488
|
+
return failed.length === 0;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1341
1491
|
function runPython(script, args) {
|
|
1342
1492
|
if (!fs.existsSync(script)) {
|
|
1343
1493
|
process.stderr.write(`keel: missing packaged script: ${script}\n`);
|
|
@@ -2713,6 +2863,9 @@ function runAction(options) {
|
|
|
2713
2863
|
if (options.withGitHooks && options.action !== "install") {
|
|
2714
2864
|
fail("--with-git-hooks only applies to --install");
|
|
2715
2865
|
}
|
|
2866
|
+
if (options.adopt && options.action !== "update") {
|
|
2867
|
+
fail("--adopt only applies to --update");
|
|
2868
|
+
}
|
|
2716
2869
|
|
|
2717
2870
|
if (options.action === "openspec") {
|
|
2718
2871
|
const openspec = findOpenSpecCommand();
|
|
@@ -2995,6 +3148,9 @@ function main() {
|
|
|
2995
3148
|
return require("../src/core/agents").runAgents(process.argv.slice(3));
|
|
2996
3149
|
}
|
|
2997
3150
|
const options = parseArgs(process.argv.slice(2));
|
|
3151
|
+
if (options.adopt && options.action !== "update") {
|
|
3152
|
+
fail("--adopt only applies to --update");
|
|
3153
|
+
}
|
|
2998
3154
|
if (options.help || (!options.action && !options.version)) {
|
|
2999
3155
|
printHelp();
|
|
3000
3156
|
return 0;
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.180.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@christang/keel",
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.180.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fission-ai/openspec": "^1.4.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.180.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.180.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// Waits until the npm registry serves a published version (#421).
|
|
5
|
+
//
|
|
6
|
+
// `npm publish` returning is the write side saying the version exists; the
|
|
7
|
+
// read side that `npm install` and `claude plugin update` resolve against has
|
|
8
|
+
// lagged it by minutes (#153, #421). The publish job runs this between the
|
|
9
|
+
// publish and the release, so a release announces a version the registry
|
|
10
|
+
// already serves. A nonzero `npm view` is npm's E404 for a version it cannot
|
|
11
|
+
// see yet, and counts as not served. Mirrors and proxies may lag further;
|
|
12
|
+
// `keel --update` reports that case as `pending`.
|
|
13
|
+
//
|
|
14
|
+
// Usage:
|
|
15
|
+
// node scripts/await_registry.js <package> <version> [--interval-seconds N] [--timeout-seconds N]
|
|
16
|
+
//
|
|
17
|
+
// KEEL_AWAIT_NPM names the npm executable (default `npm`).
|
|
18
|
+
|
|
19
|
+
const { spawnSync } = require("child_process");
|
|
20
|
+
|
|
21
|
+
function fail(message) {
|
|
22
|
+
process.stderr.write(`await_registry: ${message}\n`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function option(args, name, fallback) {
|
|
27
|
+
const index = args.indexOf(name);
|
|
28
|
+
if (index < 0) return fallback;
|
|
29
|
+
const value = Number(args[index + 1]);
|
|
30
|
+
if (!Number.isFinite(value) || value < 0) fail(`${name} needs a number of seconds`);
|
|
31
|
+
args.splice(index, 2);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function served(npm, spec, version) {
|
|
36
|
+
const result = spawnSync(npm, ["view", spec, "version", "--prefer-online"], {
|
|
37
|
+
encoding: "utf8",
|
|
38
|
+
shell: process.platform === "win32",
|
|
39
|
+
timeout: 60 * 1000,
|
|
40
|
+
});
|
|
41
|
+
return !result.error && result.status === 0 && String(result.stdout || "").trim() === version;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function sleep(seconds) {
|
|
45
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, seconds * 1000);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function main() {
|
|
49
|
+
const args = process.argv.slice(2);
|
|
50
|
+
const interval = option(args, "--interval-seconds", 15);
|
|
51
|
+
const limit = option(args, "--timeout-seconds", 15 * 60);
|
|
52
|
+
if (args.length !== 2) {
|
|
53
|
+
fail("usage: node scripts/await_registry.js <package> <version> [--interval-seconds N] [--timeout-seconds N]");
|
|
54
|
+
}
|
|
55
|
+
const [name, version] = args;
|
|
56
|
+
const spec = `${name}@${version}`;
|
|
57
|
+
const npm = process.env.KEEL_AWAIT_NPM || "npm";
|
|
58
|
+
const started = Date.now();
|
|
59
|
+
for (let polls = 1; ; polls += 1) {
|
|
60
|
+
if (served(npm, spec, version)) {
|
|
61
|
+
const seconds = Math.round((Date.now() - started) / 1000);
|
|
62
|
+
process.stdout.write(`await_registry: the registry serves ${spec} after ${seconds} s and ${polls} poll(s)\n`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if ((Date.now() - started) / 1000 + interval > limit) {
|
|
66
|
+
fail(`the registry did not serve ${spec} within ${limit} s (${polls} poll(s)); re-run the job to wait again`);
|
|
67
|
+
}
|
|
68
|
+
sleep(interval);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
main();
|
|
@@ -51,8 +51,8 @@ REQUIRED_SCRIPTS = [
|
|
|
51
51
|
"scripts/validate_plugin.py",
|
|
52
52
|
]
|
|
53
53
|
|
|
54
|
-
PACKAGE_VERSION = "5.
|
|
55
|
-
PROTOCOL_VERSION = "5.
|
|
54
|
+
PACKAGE_VERSION = "5.180.0"
|
|
55
|
+
PROTOCOL_VERSION = "5.180.0"
|
|
56
56
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
57
57
|
OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
|
|
58
58
|
# Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
|
|
@@ -25267,7 +25267,10 @@ if (failOn && args.join(" ").includes(failOn)) {
|
|
|
25267
25267
|
if (failed < failTimes) {
|
|
25268
25268
|
state.failed = { ...(state.failed || {}), [host]: failed + 1 };
|
|
25269
25269
|
save();
|
|
25270
|
-
|
|
25270
|
+
// FAKE_FAIL_STDERR_<HOST> replaces the refusal's last line, as a host's own
|
|
25271
|
+
// error text would read (#421).
|
|
25272
|
+
const said = process.env[`FAKE_FAIL_STDERR_${host.toUpperCase()}`] || `fake ${host}: refused ${args.join(" ")}`;
|
|
25273
|
+
process.stderr.write(`fake ${host}: warming up\n${said}\n`);
|
|
25271
25274
|
process.exit(1);
|
|
25272
25275
|
}
|
|
25273
25276
|
}
|
|
@@ -25277,6 +25280,15 @@ if (host === "npm") {
|
|
|
25277
25280
|
fs.writeFileSync(path.join(dest, "christang-keel-5.1.0.tgz"), "");
|
|
25278
25281
|
process.stdout.write(JSON.stringify([{ filename: "christang-keel-5.1.0.tgz" }]));
|
|
25279
25282
|
}
|
|
25283
|
+
// FAKE_NPM_LATEST is what `npm view <package> version` prints, and
|
|
25284
|
+
// FAKE_NPM_VIEW_EXIT makes it exit with that status instead (#421).
|
|
25285
|
+
if (args[0] === "view") {
|
|
25286
|
+
if (process.env.FAKE_NPM_VIEW_EXIT) {
|
|
25287
|
+
process.stderr.write("npm error code E404\n");
|
|
25288
|
+
process.exit(Number(process.env.FAKE_NPM_VIEW_EXIT));
|
|
25289
|
+
}
|
|
25290
|
+
process.stdout.write(`${process.env.FAKE_NPM_LATEST || "5.1.0"}\n`);
|
|
25291
|
+
}
|
|
25280
25292
|
process.exit(0);
|
|
25281
25293
|
}
|
|
25282
25294
|
const joined = args.join(" ");
|
|
@@ -25311,6 +25323,162 @@ process.exit(0);
|
|
|
25311
25323
|
"""
|
|
25312
25324
|
|
|
25313
25325
|
|
|
25326
|
+
# A claude for #424: the Keel plugin, the background sessions `agents --json`
|
|
25327
|
+
# lists, `stop` (which kills the row's process, as the host does a moment after
|
|
25328
|
+
# returning), and `--bg --resume`, which records whether the old process was
|
|
25329
|
+
# still alive when it ran.
|
|
25330
|
+
ADOPT_FAKE_CLAUDE = r"""const fs = require("fs");
|
|
25331
|
+
const args = process.argv.slice(2);
|
|
25332
|
+
const joined = args.join(" ");
|
|
25333
|
+
const statePath = process.env.FAKE_STATE;
|
|
25334
|
+
const state = JSON.parse(fs.readFileSync(statePath, "utf8"));
|
|
25335
|
+
const save = () => fs.writeFileSync(statePath, JSON.stringify(state));
|
|
25336
|
+
fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify({ args, cwd: process.cwd() }) + "\n");
|
|
25337
|
+
const alive = (pid) => { try { process.kill(pid, 0); return true; } catch { return false; } };
|
|
25338
|
+
if (joined === "plugin list --json") {
|
|
25339
|
+
process.stdout.write(JSON.stringify([{ id: "keel@keel-marketplace", version: state.version,
|
|
25340
|
+
lastUpdated: state.lastUpdated }]));
|
|
25341
|
+
} else if (joined === "plugin update keel@keel-marketplace") {
|
|
25342
|
+
state.version = "5.1.0";
|
|
25343
|
+
save();
|
|
25344
|
+
} else if (joined === "agents --json") {
|
|
25345
|
+
process.stdout.write(JSON.stringify(state.rows));
|
|
25346
|
+
} else if (args[0] === "stop") {
|
|
25347
|
+
const row = state.rows.find((item) => item.id === args[1]);
|
|
25348
|
+
if (row) {
|
|
25349
|
+
setTimeout(() => { try { process.kill(row.pid, "SIGKILL"); } catch {} }, 300);
|
|
25350
|
+
delete row.status;
|
|
25351
|
+
save();
|
|
25352
|
+
}
|
|
25353
|
+
process.stdout.write(`stopped ${args[1]}\n`);
|
|
25354
|
+
setTimeout(() => process.exit(0), 400);
|
|
25355
|
+
return;
|
|
25356
|
+
} else if (args[0] === "--bg" && args[1] === "--resume") {
|
|
25357
|
+
const row = state.rows.find((item) => item.sessionId === args[2]);
|
|
25358
|
+
fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify({ resumed: args[2], oldAlive: row ? alive(row.pid) : null }) + "\n");
|
|
25359
|
+
if (row) { row.status = "idle"; row.startedAt = Date.now(); save(); }
|
|
25360
|
+
process.stdout.write(`backgrounded · ${args[2].slice(0, 8)} · resumed\n`);
|
|
25361
|
+
}
|
|
25362
|
+
process.exit(0);
|
|
25363
|
+
"""
|
|
25364
|
+
|
|
25365
|
+
|
|
25366
|
+
def validate_update_adopts_idle_sessions_scenario() -> int:
|
|
25367
|
+
"""Issue #424: a release reaches the running background sessions on request.
|
|
25368
|
+
|
|
25369
|
+
Each Claude background session keeps the plugin it loaded. A hand-over starts
|
|
25370
|
+
a new process, so it adopts the update; a session that does not change shift
|
|
25371
|
+
stays on the old one. Measured on 2026-10-21 (Claude Code 2.1.304), stop and
|
|
25372
|
+
resume with no prompt restarts it on the installed plugin without a turn.
|
|
25373
|
+
`--adopt` does that for the idle sessions started before the update, and
|
|
25374
|
+
leaves busy, guarded, and its own session alone.
|
|
25375
|
+
"""
|
|
25376
|
+
label = "update-adopts-idle-sessions:"
|
|
25377
|
+
t0 = 1792540800000 # 2026-10-21T00:00:00Z, the update's lastUpdated
|
|
25378
|
+
with tempfile.TemporaryDirectory(prefix="keel-adopt-424-", ignore_cleanup_errors=True) as raw:
|
|
25379
|
+
tmp = Path(raw)
|
|
25380
|
+
fake = tmp / "fake-claude.js"
|
|
25381
|
+
write_text(fake, ADOPT_FAKE_CLAUDE)
|
|
25382
|
+
launcher = tmp / "fake-claude"
|
|
25383
|
+
write_text(launcher, f'#!/bin/sh\nexec node "{fake}" "$@"\n')
|
|
25384
|
+
launcher.chmod(0o755)
|
|
25385
|
+
npm_fake = tmp / "fake-npm.js"
|
|
25386
|
+
write_text(npm_fake, UPDATE_FAKE)
|
|
25387
|
+
npm = tmp / "fake-npm"
|
|
25388
|
+
write_text(npm, f'#!/bin/sh\nFAKE_HOST=npm exec node "{npm_fake}" "$@"\n')
|
|
25389
|
+
npm.chmod(0o755)
|
|
25390
|
+
guarded = tmp / "guarded"
|
|
25391
|
+
write_text(guarded / "keel" / "guard.json", "{}\n")
|
|
25392
|
+
sleepers: list[int] = []
|
|
25393
|
+
|
|
25394
|
+
def row(name: str, sid: str, status: str, started: int, cwd: Path) -> dict:
|
|
25395
|
+
# Not this process's child: a killed child stays a zombie until reaped,
|
|
25396
|
+
# and a zombie still answers kill(pid, 0), which a host process never does.
|
|
25397
|
+
pid = int(subprocess.run(["sh", "-c", "sleep 300 >/dev/null 2>&1 & echo $!"], text=True,
|
|
25398
|
+
capture_output=True, check=True).stdout.strip())
|
|
25399
|
+
sleepers.append(pid)
|
|
25400
|
+
return {"kind": "background", "name": name, "sessionId": sid, "id": sid[:8], "status": status,
|
|
25401
|
+
"state": "working", "pid": pid, "cwd": str(cwd), "startedAt": started}
|
|
25402
|
+
|
|
25403
|
+
def run(*extra: str) -> tuple[subprocess.CompletedProcess, list[dict]]:
|
|
25404
|
+
log = tmp / "log.jsonl"
|
|
25405
|
+
log.write_text("")
|
|
25406
|
+
rows = [
|
|
25407
|
+
row("lead · old idle", "aaaaaaaa-0000-0000-0000-000000000001", "idle", t0 - 3600000, tmp),
|
|
25408
|
+
row("verify · old busy", "bbbbbbbb-0000-0000-0000-000000000002", "busy", t0 - 3600000, tmp),
|
|
25409
|
+
row("rtl · old guarded", "cccccccc-0000-0000-0000-000000000003", "idle", t0 - 3600000, guarded),
|
|
25410
|
+
row("pm · fresh idle", "dddddddd-0000-0000-0000-000000000004", "idle", t0 + 3600000, tmp),
|
|
25411
|
+
row("maint · this session", "eeeeeeee-0000-0000-0000-000000000005", "busy", t0 - 3600000, tmp),
|
|
25412
|
+
]
|
|
25413
|
+
(tmp / "state.json").write_text(json.dumps({"version": "5.0.0", "lastUpdated": "2026-10-21T00:00:00.000Z", "rows": rows}))
|
|
25414
|
+
env = dict(os.environ)
|
|
25415
|
+
env.update({"KEEL_UPDATE_NPM": str(npm), "KEEL_UPDATE_CLAUDE": str(launcher),
|
|
25416
|
+
"KEEL_UPDATE_CODEX": str(tmp / "no-codex"), "FAKE_LOG": str(log),
|
|
25417
|
+
"FAKE_STATE": str(tmp / "state.json"), "CLAUDE_CODE_SESSION_ID": rows[4]["sessionId"]})
|
|
25418
|
+
env.pop("KEEL_UPDATE_SOURCE", None)
|
|
25419
|
+
result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update", *extra], cwd=tmp, env=env,
|
|
25420
|
+
text=True, capture_output=True, check=False, timeout=90)
|
|
25421
|
+
# The npm fake logs arrays to the same file; the claude fake logs objects.
|
|
25422
|
+
entries = [json.loads(line) for line in log.read_text().splitlines() if line.strip()]
|
|
25423
|
+
return result, [entry for entry in entries if isinstance(entry, dict)]
|
|
25424
|
+
|
|
25425
|
+
try:
|
|
25426
|
+
adopted, calls = run("--adopt")
|
|
25427
|
+
stops = [c["args"][1] for c in calls if c.get("args", [None])[0] == "stop"]
|
|
25428
|
+
resumes = [c for c in calls if c.get("args", [None])[:2] == ["--bg", "--resume"]]
|
|
25429
|
+
witnessed = [c for c in calls if "resumed" in c]
|
|
25430
|
+
line = next((l for l in adopted.stdout.splitlines() if l.startswith("keel update: claude sessions:")), "")
|
|
25431
|
+
if adopted.returncode != 0:
|
|
25432
|
+
report(f"{label} keel --update --adopt exited {adopted.returncode}: {adopted.stdout!r} {adopted.stderr!r}")
|
|
25433
|
+
return 1
|
|
25434
|
+
if stops != ["aaaaaaaa"]:
|
|
25435
|
+
report(f"{label} --adopt stopped {stops!r}, not only the idle session started before the update.")
|
|
25436
|
+
return 1
|
|
25437
|
+
if len(resumes) != 1 or resumes[0]["args"] != ["--bg", "--resume", "aaaaaaaa-0000-0000-0000-000000000001"]:
|
|
25438
|
+
report(f"{label} --adopt did not resume the stopped session with exactly `--bg --resume <id>`: {resumes!r}")
|
|
25439
|
+
return 1
|
|
25440
|
+
if resumes[0]["cwd"] != os.path.realpath(tmp) and resumes[0]["cwd"] != str(tmp):
|
|
25441
|
+
report(f"{label} the resume ran in {resumes[0]['cwd']!r}, not the session's worktree {str(tmp)!r}.")
|
|
25442
|
+
return 1
|
|
25443
|
+
if not witnessed or witnessed[0]["oldAlive"]:
|
|
25444
|
+
report(f"{label} the resume ran while the stopped session's process was still alive: {witnessed!r}")
|
|
25445
|
+
return 1
|
|
25446
|
+
for needle in ("adopted", "lead · old idle", "verify · old busy", "rtl · old guarded"):
|
|
25447
|
+
if needle not in line:
|
|
25448
|
+
report(f"{label} the claude sessions line does not name {needle!r}: {line!r}")
|
|
25449
|
+
return 1
|
|
25450
|
+
for absent in ("pm · fresh idle", "maint · this session"):
|
|
25451
|
+
if absent in line:
|
|
25452
|
+
report(f"{label} the claude sessions line names {absent!r}, which is not on an older plugin or is this session: {line!r}")
|
|
25453
|
+
return 1
|
|
25454
|
+
|
|
25455
|
+
named, calls = run()
|
|
25456
|
+
line = next((l for l in named.stdout.splitlines() if l.startswith("keel update: claude sessions:")), "")
|
|
25457
|
+
if any(c.get("args", [None])[0] == "stop" or c.get("args", [None])[:2] == ["--bg", "--resume"] for c in calls):
|
|
25458
|
+
report(f"{label} keel --update without --adopt stopped or resumed a session: {calls!r}")
|
|
25459
|
+
return 1
|
|
25460
|
+
for needle in ("lead · old idle", "verify · old busy", "rtl · old guarded", "keel --update --adopt"):
|
|
25461
|
+
if needle not in line:
|
|
25462
|
+
report(f"{label} without --adopt the claude sessions line does not name {needle!r}: {line!r}")
|
|
25463
|
+
return 1
|
|
25464
|
+
finally:
|
|
25465
|
+
for pid in sleepers:
|
|
25466
|
+
try:
|
|
25467
|
+
os.kill(pid, signal.SIGKILL)
|
|
25468
|
+
except ProcessLookupError:
|
|
25469
|
+
pass
|
|
25470
|
+
refused = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--adopt"], cwd=ROOT, text=True,
|
|
25471
|
+
capture_output=True, check=False)
|
|
25472
|
+
if refused.returncode != 2:
|
|
25473
|
+
report(f"{label} --adopt outside --update exited {refused.returncode}, not 2: {refused.stderr!r}")
|
|
25474
|
+
return 1
|
|
25475
|
+
if label.rstrip(":") not in {name for name, _ in SCENARIOS}:
|
|
25476
|
+
report(f"{label} the scenario registry does not include it.")
|
|
25477
|
+
return 1
|
|
25478
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
25479
|
+
return 0
|
|
25480
|
+
|
|
25481
|
+
|
|
25314
25482
|
def validate_update_covers_installed_hosts_scenario() -> int:
|
|
25315
25483
|
"""Issue #204: one owner-run `keel --update` covers every installed component.
|
|
25316
25484
|
|
|
@@ -25455,6 +25623,101 @@ def validate_update_covers_installed_hosts_scenario() -> int:
|
|
|
25455
25623
|
return 0
|
|
25456
25624
|
|
|
25457
25625
|
|
|
25626
|
+
def validate_update_registry_lag_scenario() -> int:
|
|
25627
|
+
"""Issue #421: a version the registry does not serve yet is `pending`.
|
|
25628
|
+
|
|
25629
|
+
Right after a release, the Claude marketplace names the new version while
|
|
25630
|
+
the npm registry the machine reaches still serves the old one, and
|
|
25631
|
+
`claude plugin update` exits 1 with `E404 No match found for version`.
|
|
25632
|
+
A rerun minutes later succeeds, so that is not a failure; any E404 the
|
|
25633
|
+
registry's own answer does not explain still is.
|
|
25634
|
+
"""
|
|
25635
|
+
label = "update-registry-lag:"
|
|
25636
|
+
e404 = ('✘ Failed to update plugin "keel@keel-marketplace": Could not resolve @christang/keel@5.2.0 '
|
|
25637
|
+
"from the npm registry: E404 No match found for version 5.2.0")
|
|
25638
|
+
with tempfile.TemporaryDirectory(prefix="keel-update-421-", ignore_cleanup_errors=True) as raw:
|
|
25639
|
+
tmp = Path(raw)
|
|
25640
|
+
fake = tmp / "fake.js"
|
|
25641
|
+
write_text(fake, UPDATE_FAKE)
|
|
25642
|
+
launchers = {}
|
|
25643
|
+
for host in ("npm", "claude", "codex"):
|
|
25644
|
+
launcher = tmp / f"fake-{host}"
|
|
25645
|
+
write_text(launcher, f'#!/bin/sh\nFAKE_HOST={host} exec node "{fake}" "$@"\n')
|
|
25646
|
+
launcher.chmod(0o755)
|
|
25647
|
+
launchers[host] = launcher
|
|
25648
|
+
source = tmp / "codex-source"
|
|
25649
|
+
write_text(source / "hooks/codex.json", "{}\n")
|
|
25650
|
+
|
|
25651
|
+
def update(env_extra: dict[str, str]):
|
|
25652
|
+
log = tmp / "log.jsonl"
|
|
25653
|
+
state = tmp / "state.json"
|
|
25654
|
+
for stale in (log, state):
|
|
25655
|
+
if stale.exists():
|
|
25656
|
+
stale.unlink()
|
|
25657
|
+
log.write_text("")
|
|
25658
|
+
env = dict(os.environ)
|
|
25659
|
+
env.update({
|
|
25660
|
+
"KEEL_UPDATE_NPM": str(launchers["npm"]),
|
|
25661
|
+
"KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
|
|
25662
|
+
"KEEL_UPDATE_CODEX": str(launchers["codex"]),
|
|
25663
|
+
"CODEX_HOME": str(tmp / "codex-home"),
|
|
25664
|
+
"FAKE_LOG": str(log), "FAKE_STATE": str(state),
|
|
25665
|
+
"FAKE_CODEX_SOURCE": str(source),
|
|
25666
|
+
"FAKE_FAIL_CLAUDE": "plugin update keel", "FAKE_FAIL_STDERR_CLAUDE": e404,
|
|
25667
|
+
})
|
|
25668
|
+
env.pop("KEEL_UPDATE_SOURCE", None)
|
|
25669
|
+
env.update(env_extra)
|
|
25670
|
+
result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update"], cwd=tmp, env=env,
|
|
25671
|
+
text=True, capture_output=True, check=False, timeout=60)
|
|
25672
|
+
lines = {}
|
|
25673
|
+
for component in ("cli", "claude plugin", "codex plugin"):
|
|
25674
|
+
found = [l for l in result.stdout.splitlines() if l.startswith(f"keel update: {component}:")]
|
|
25675
|
+
lines[component] = found[0] if len(found) == 1 else ""
|
|
25676
|
+
return result, lines
|
|
25677
|
+
|
|
25678
|
+
result, lines = update({"FAKE_NPM_LATEST": "5.1.0"})
|
|
25679
|
+
claude = lines["claude plugin"]
|
|
25680
|
+
if not claude.startswith("keel update: claude plugin: pending"):
|
|
25681
|
+
report(f"{label} a version the registry does not serve yet was not reported pending: {claude!r}")
|
|
25682
|
+
return 1
|
|
25683
|
+
for needle in ("5.2.0", "5.1.0", "rerun keel --update", "few minutes"):
|
|
25684
|
+
if needle not in claude:
|
|
25685
|
+
report(f"{label} the pending Claude line does not name {needle!r}: {claude!r}")
|
|
25686
|
+
return 1
|
|
25687
|
+
if "failed" in claude:
|
|
25688
|
+
report(f"{label} the pending Claude line still reads failed: {claude!r}")
|
|
25689
|
+
return 1
|
|
25690
|
+
if "registry's latest here is 5.1.0" not in lines["cli"]:
|
|
25691
|
+
report(f"{label} the CLI line does not name 5.1.0 as the registry's latest: {lines['cli']!r}")
|
|
25692
|
+
return 1
|
|
25693
|
+
if "5.0.0 -> 5.1.0" not in lines["codex plugin"]:
|
|
25694
|
+
report(f"{label} the Codex line did not still update: {lines['codex plugin']!r}")
|
|
25695
|
+
return 1
|
|
25696
|
+
if result.returncode != 0:
|
|
25697
|
+
report(f"{label} a pending Claude plugin failed the update: exit={result.returncode} {result.stdout!r}")
|
|
25698
|
+
return 1
|
|
25699
|
+
|
|
25700
|
+
for case, env_extra in (("the registry serves 5.2.0", {"FAKE_NPM_LATEST": "5.2.0"}),
|
|
25701
|
+
("npm view exits 1", {"FAKE_NPM_VIEW_EXIT": "1"})):
|
|
25702
|
+
result, lines = update(env_extra)
|
|
25703
|
+
claude = lines["claude plugin"]
|
|
25704
|
+
if not claude.startswith("keel update: claude plugin: failed"):
|
|
25705
|
+
report(f"{label} when {case}, the Claude line does not read failed: {claude!r}")
|
|
25706
|
+
return 1
|
|
25707
|
+
if "E404 No match found" not in claude:
|
|
25708
|
+
report(f"{label} when {case}, the failed Claude line does not carry the host's E404: {claude!r}")
|
|
25709
|
+
return 1
|
|
25710
|
+
if result.returncode == 0:
|
|
25711
|
+
report(f"{label} when {case}, the update exited 0: {result.stdout!r}")
|
|
25712
|
+
return 1
|
|
25713
|
+
|
|
25714
|
+
if "update-registry-lag" not in {name for name, _ in SCENARIOS}:
|
|
25715
|
+
report(f"{label} scenario is not registered.")
|
|
25716
|
+
return 1
|
|
25717
|
+
report("update-registry-lag scenario passed.")
|
|
25718
|
+
return 0
|
|
25719
|
+
|
|
25720
|
+
|
|
25458
25721
|
OVERLAY_START_RE = re.compile(r"<!--\s*keel:openspec-surface-overlay version=([^ ]+) -->")
|
|
25459
25722
|
OVERLAY_BLOCK_RE = re.compile(
|
|
25460
25723
|
r"<!--\s*keel:openspec-surface-overlay(?:\s+[^>]*)?\s*-->[\s\S]*?"
|
|
@@ -40505,6 +40768,121 @@ def workflow_job_block(workflow: str, job: str) -> str:
|
|
|
40505
40768
|
return match.group(1) if match else ""
|
|
40506
40769
|
|
|
40507
40770
|
|
|
40771
|
+
def registry_wait_problem(workflow: str) -> str | None:
|
|
40772
|
+
"""Return why `publish.yml` would release before the registry serves it, or None.
|
|
40773
|
+
|
|
40774
|
+
Takes text so a planted copy can prove the rule fires (#421).
|
|
40775
|
+
"""
|
|
40776
|
+
publish = workflow_job_block(workflow, "publish")
|
|
40777
|
+
steps = re.split(r"\n(?= - name: )", publish)
|
|
40778
|
+
names = [re.match(r"\s*- name: ([^\n]*)", step).group(1).strip() if re.match(r"\s*- name: ", step) else ""
|
|
40779
|
+
for step in steps]
|
|
40780
|
+
waits = [i for i, step in enumerate(steps) if "scripts/await_registry.js" in step]
|
|
40781
|
+
if not waits:
|
|
40782
|
+
return f"releases before the registry serves the version — {PUBLISH_WORKFLOW} never runs scripts/await_registry.js."
|
|
40783
|
+
if "Publish" not in names or "Tag and release the landed version" not in names:
|
|
40784
|
+
return f"{PUBLISH_WORKFLOW} has no `Publish` or no `Tag and release the landed version` step to order the wait between."
|
|
40785
|
+
wait = waits[0]
|
|
40786
|
+
if not names.index("Publish") < wait < names.index("Tag and release the landed version"):
|
|
40787
|
+
return ("releases before the registry serves the version — the scripts/await_registry.js step is not "
|
|
40788
|
+
"between `Publish` and `Tag and release the landed version`.")
|
|
40789
|
+
condition = re.search(r"^\s*if: ([^\n]*)", steps[names.index("Publish")], re.M)
|
|
40790
|
+
if not condition or f"if: {condition.group(1)}" not in steps[wait]:
|
|
40791
|
+
return "the registry wait does not share the `Publish` step's skip condition."
|
|
40792
|
+
if "steps.plan.outputs.version" not in steps[wait]:
|
|
40793
|
+
return "the registry wait does not wait for the planned version."
|
|
40794
|
+
return None
|
|
40795
|
+
|
|
40796
|
+
|
|
40797
|
+
AWAIT_NPM_FAKE = r"""const fs = require("fs");
|
|
40798
|
+
const count = process.env.FAKE_COUNT;
|
|
40799
|
+
const calls = (fs.existsSync(count) ? Number(fs.readFileSync(count, "utf8")) : 0) + 1;
|
|
40800
|
+
fs.writeFileSync(count, String(calls));
|
|
40801
|
+
fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify(process.argv.slice(2)) + "\n");
|
|
40802
|
+
const after = process.env.FAKE_SERVE_AFTER;
|
|
40803
|
+
if (after === "never" || calls <= Number(after)) {
|
|
40804
|
+
process.stderr.write("npm error code E404\nnpm error 404 No match found for version 5.2.0\n");
|
|
40805
|
+
process.exit(1);
|
|
40806
|
+
}
|
|
40807
|
+
process.stdout.write("5.2.0\n");
|
|
40808
|
+
"""
|
|
40809
|
+
|
|
40810
|
+
|
|
40811
|
+
def validate_publish_awaits_registry_scenario() -> int:
|
|
40812
|
+
"""Issue #421: a release is created only once the registry serves it.
|
|
40813
|
+
|
|
40814
|
+
The release used to announce a version the registry's read side would not
|
|
40815
|
+
serve for minutes, and the first `keel --update` after it failed.
|
|
40816
|
+
"""
|
|
40817
|
+
label = "publish-awaits-registry:"
|
|
40818
|
+
script = ROOT / "scripts/await_registry.js"
|
|
40819
|
+
if not script.is_file():
|
|
40820
|
+
report(f"{label} scripts/await_registry.js is missing.")
|
|
40821
|
+
return 1
|
|
40822
|
+
with tempfile.TemporaryDirectory(prefix="keel-await-421-", ignore_cleanup_errors=True) as raw:
|
|
40823
|
+
tmp = Path(raw)
|
|
40824
|
+
fake = tmp / "fake-npm.js"
|
|
40825
|
+
write_text(fake, AWAIT_NPM_FAKE)
|
|
40826
|
+
launcher = tmp / "fake-npm"
|
|
40827
|
+
write_text(launcher, f'#!/bin/sh\nexec node "{fake}" "$@"\n')
|
|
40828
|
+
launcher.chmod(0o755)
|
|
40829
|
+
|
|
40830
|
+
def wait(serve_after: str, *extra: str):
|
|
40831
|
+
count, log = tmp / "count", tmp / "log.jsonl"
|
|
40832
|
+
for stale in (count, log):
|
|
40833
|
+
if stale.exists():
|
|
40834
|
+
stale.unlink()
|
|
40835
|
+
log.write_text("")
|
|
40836
|
+
env = dict(os.environ)
|
|
40837
|
+
env.update({"KEEL_AWAIT_NPM": str(launcher), "FAKE_COUNT": str(count), "FAKE_LOG": str(log),
|
|
40838
|
+
"FAKE_SERVE_AFTER": serve_after})
|
|
40839
|
+
result = subprocess.run(["node", str(script), "@christang/keel", "5.2.0", "--interval-seconds", "0", *extra],
|
|
40840
|
+
cwd=tmp, env=env, text=True, capture_output=True, check=False, timeout=60)
|
|
40841
|
+
calls = [json.loads(line) for line in log.read_text().splitlines() if line.strip()]
|
|
40842
|
+
return result, calls
|
|
40843
|
+
|
|
40844
|
+
result, calls = wait("2")
|
|
40845
|
+
if result.returncode != 0 or len(calls) != 3:
|
|
40846
|
+
report(f"{label} a version served on the third poll did not end the wait after 3 polls with exit 0: "
|
|
40847
|
+
f"exit={result.returncode} polls={len(calls)} {result.stdout!r} {result.stderr!r}")
|
|
40848
|
+
return 1
|
|
40849
|
+
if calls[0][:3] != ["view", "@christang/keel@5.2.0", "version"]:
|
|
40850
|
+
report(f"{label} the wait did not ask npm for the exact version: {calls[0]!r}")
|
|
40851
|
+
return 1
|
|
40852
|
+
|
|
40853
|
+
result, calls = wait("never", "--timeout-seconds", "1")
|
|
40854
|
+
said = result.stdout + result.stderr
|
|
40855
|
+
if result.returncode == 0:
|
|
40856
|
+
report(f"{label} a version never served ended the wait with exit 0: {said!r}")
|
|
40857
|
+
return 1
|
|
40858
|
+
for needle in ("5.2.0", "1 s"):
|
|
40859
|
+
if needle not in said:
|
|
40860
|
+
report(f"{label} the timed-out wait does not name {needle!r}: {said!r}")
|
|
40861
|
+
return 1
|
|
40862
|
+
|
|
40863
|
+
workflow = (ROOT / PUBLISH_WORKFLOW).read_text(encoding="utf-8")
|
|
40864
|
+
problem = registry_wait_problem(workflow)
|
|
40865
|
+
if problem:
|
|
40866
|
+
report(f"{label} {problem}")
|
|
40867
|
+
return 1
|
|
40868
|
+
tag_step = workflow.find(" - name: Tag and release the landed version")
|
|
40869
|
+
wait_start = workflow.rfind(" - name: ", 0, workflow.find("scripts/await_registry.js"))
|
|
40870
|
+
wait_end = workflow.find("\n - name: ", wait_start + 1) + 1
|
|
40871
|
+
moved = workflow[:wait_start] + workflow[wait_end:] + workflow[wait_start:wait_end]
|
|
40872
|
+
if tag_step < 0:
|
|
40873
|
+
report(f"{label} {PUBLISH_WORKFLOW} has no `Tag and release the landed version` step to plant a copy against.")
|
|
40874
|
+
return 1
|
|
40875
|
+
if not registry_wait_problem(moved):
|
|
40876
|
+
report(f"{label} a planted copy with the wait moved after the tag step was not refused.")
|
|
40877
|
+
return 1
|
|
40878
|
+
|
|
40879
|
+
if "publish-awaits-registry" not in {name for name, _ in SCENARIOS}:
|
|
40880
|
+
report(f"{label} scenario is not registered.")
|
|
40881
|
+
return 1
|
|
40882
|
+
report("publish-awaits-registry scenario passed.")
|
|
40883
|
+
return 0
|
|
40884
|
+
|
|
40885
|
+
|
|
40508
40886
|
def landing_problem(workflow: str) -> str | None:
|
|
40509
40887
|
"""Return the problem the landing path in `publish.yml` has, or None.
|
|
40510
40888
|
|
|
@@ -41550,9 +41928,12 @@ SCENARIOS: tuple = (
|
|
|
41550
41928
|
("update-claude-refresh-retry", validate_update_claude_refresh_retry_scenario),
|
|
41551
41929
|
("update-host-query-timeout", validate_update_host_query_timeout_scenario),
|
|
41552
41930
|
("update-codex-from-disk", validate_update_codex_from_disk_scenario),
|
|
41931
|
+
("update-registry-lag", validate_update_registry_lag_scenario),
|
|
41932
|
+
("update-adopts-idle-sessions", validate_update_adopts_idle_sessions_scenario),
|
|
41553
41933
|
("refresh-covers-every-target", validate_refresh_covers_every_target_scenario),
|
|
41554
41934
|
("directory-branch-advances", validate_directory_branch_advances_scenario),
|
|
41555
41935
|
("release-notes-name-the-directory-branch", validate_release_notes_name_the_directory_branch_scenario),
|
|
41936
|
+
("publish-awaits-registry", validate_publish_awaits_registry_scenario),
|
|
41556
41937
|
("directory-tree-is-the-package-renamed", validate_directory_tree_is_the_package_renamed_scenario),
|
|
41557
41938
|
("init-declares-plugin-auto-update", validate_init_declares_plugin_auto_update_scenario),
|
|
41558
41939
|
("context-names-the-protocol-refresh", validate_context_names_the_protocol_refresh_scenario),
|