@staix/agent-hub 0.44.0 → 0.46.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/CHANGELOG.md +66 -0
- package/README.md +12 -11
- package/docs/adding-an-ai-tool.md +1 -0
- package/docs/agent-notes/adapters.md +35 -6
- package/docs/agent-notes/budget.md +2 -1
- package/docs/agent-notes/daemon.md +5 -1
- package/docs/agent-notes/local-worker.md +1 -1
- package/docs/agent-notes/security-review.md +3 -2
- package/docs/agent-notes/tasks.md +6 -2
- package/docs/agent-notes/tests.md +4 -3
- package/docs/design/adapters.md +20 -2
- package/docs/design/agent-hub-architecture.md +12 -0
- package/docs/design/agent-hub.md +1 -1
- package/docs/design/cli-output.md +2 -0
- package/docs/design/roadmap.md +158 -4
- package/docs/design/supervision.md +21 -1
- package/docs/design/task-board.md +32 -4
- package/docs/dogfood.md +28 -4
- package/docs/events.md +7 -3
- package/docs/influences.md +7 -0
- package/docs/memory.md +4 -4
- package/docs/operations.md +151 -36
- package/docs/quickstart.md +16 -4
- package/docs/research.md +16 -0
- package/docs/roadmap.json +4 -0
- package/docs/roadmap.md +9 -0
- package/docs/sdlc.md +15 -3
- package/docs/security.md +9 -7
- package/docs/smoke.md +1 -1
- package/docs/verification/2026-11-05-hardcoded-values-classification-rules.md +28 -0
- package/docs/verification/2026-11-19-claude-implementer-2.1.328.md +49 -0
- package/docs/verification/2026-11-20-claude-implementer-2.1.329.md +49 -0
- package/docs/verification/2026-11-20-sdlc-metrics-diagnosis.md +7 -0
- package/docs/verification/2026-11-21-0.45.0.md +69 -0
- package/docs/verification/2026-11-22-agy-1.5.14.md +27 -0
- package/docs/verification/2026-11-22-claude-instruction-hook.md +35 -0
- package/docs/verification/2026-11-22-codex-0171-reviewer-isolation.md +47 -0
- package/docs/verification/2026-11-22-instructed-ipc.md +9 -0
- package/docs/verification/2026-11-22-jcode-1.0.3.md +71 -0
- package/docs/verification/2026-11-22-jcode-separate-home.md +14 -0
- package/docs/verification/2026-11-22-qwen-0283-acp.md +28 -0
- package/docs/verification/2026-11-22-qwen-0283-dual-output.md +33 -0
- package/docs/verification/2026-11-22-roadmap-r5-view-receipt.md +63 -0
- package/docs/verification/2026-11-23-0.46.0.md +44 -0
- package/docs/verification/assets/1483-r5-detail-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-detail-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-light.png +0 -0
- package/docs/verified.json +33 -27
- package/package.json +3 -2
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +4743 -4048
- package/plugins/agent-hub/kimi-review-policy-worker.js +5 -5
- package/plugins/agent-hub/server.js +1641 -1265
- package/plugins/agent-hub/skills/ahub/SKILL.md +17 -0
- package/plugins/agent-hub/skills/ahub-manage/SKILL.md +37 -0
- package/plugins/agent-hub/skills/ahub-status/SKILL.md +14 -0
- package/plugins/agent-hub/skills/ahub-use/SKILL.md +12 -0
- package/scripts/check-docs.mjs +9 -1
- package/src/adapters/acp.ts +11 -1
- package/src/adapters/claude-channel.ts +2 -1
- package/src/adapters/compat.ts +15 -14
- package/src/adapters/definitions/builtin-metadata.ts +2 -2
- package/src/adapters/definitions/native-cli-claude-setup.ts +9 -1
- package/src/adapters/definitions/native-cli-doctor.ts +8 -5
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +158 -0
- package/src/adapters/definitions/native-cli-jcode-home.ts +72 -0
- package/src/adapters/definitions/native-cli-jcode-mcp.ts +20 -0
- package/src/adapters/definitions/native-cli-skills.ts +29 -0
- package/src/adapters/definitions/native-context.ts +10 -0
- package/src/adapters/jcode.ts +10 -0
- package/src/adapters/local-worker.ts +3 -2
- package/src/adapters/pi.ts +15 -4
- package/src/cli/claude-profile-hook.ts +40 -3
- package/src/cli/console-state.ts +58 -27
- package/src/cli/console-usage.ts +5 -3
- package/src/cli/console.ts +35 -4
- package/src/cli/help.ts +17 -10
- package/src/cli/identity.ts +4 -2
- package/src/cli/instruction-hook.ts +28 -0
- package/src/cli/jcode-mcp.ts +2 -1
- package/src/cli/main.js +8 -0
- package/src/cli/main.ts +149 -23
- package/src/cli/output-standard.ts +3 -55
- package/src/cli/output.ts +8 -2
- package/src/cli/recovery-package.ts +62 -13
- package/src/cli/roadmap-write.ts +59 -0
- package/src/cli/roadmap.ts +115 -4
- package/src/cli/sdlc-output.ts +4 -0
- package/src/cli/setup-homes.ts +1 -0
- package/src/cli/setup.ts +1 -1
- package/src/cli/skills-install.ts +463 -0
- package/src/cli/task-output.ts +1 -1
- package/src/cli/upgrade-presentation-flags.ts +1 -1
- package/src/cli/upgrade-runtime.ts +10 -6
- package/src/hub/agent-mem-range.ts +43 -0
- package/src/hub/board.ts +144 -5
- package/src/hub/budget-projection.ts +99 -0
- package/src/hub/check-runner.ts +25 -1
- package/src/hub/claude-launch-proof.ts +5 -1
- package/src/hub/conductor.ts +8 -3
- package/src/hub/config-apply.ts +6 -3
- package/src/hub/config-tier.ts +1 -1
- package/src/hub/config-trust.ts +1 -1
- package/src/hub/context-window.ts +1 -1
- package/src/hub/control-client.ts +9 -2
- package/src/hub/cost-governance.ts +11 -7
- package/src/hub/daemon.ts +707 -53
- package/src/hub/dogfood-read.ts +4 -2
- package/src/hub/edit-guard.ts +100 -0
- package/src/hub/events.ts +80 -9
- package/src/hub/execution-budget.ts +29 -8
- package/src/hub/facts.ts +57 -4
- package/src/hub/hub-tools.ts +3 -1
- package/src/hub/inference.ts +1 -1
- package/src/hub/instances.ts +10 -1
- package/src/hub/instructed-exact.ts +95 -0
- package/src/hub/instructed-intent.ts +64 -0
- package/src/hub/instructed-ipc.ts +33 -0
- package/src/hub/instructed-runtime.ts +19 -0
- package/src/hub/instruction-receipt.ts +218 -0
- package/src/hub/lifecycle.ts +6 -1
- package/src/hub/log-rotation.ts +130 -0
- package/src/hub/manager.ts +46 -3
- package/src/hub/memory-profile.ts +137 -21
- package/src/hub/no-writes.ts +1 -0
- package/src/hub/operational-authority.ts +3 -2
- package/src/hub/operational-settings.ts +2 -2
- package/src/hub/recovery-store.ts +49 -21
- package/src/hub/registry.ts +1 -1
- package/src/hub/research-experiments.ts +132 -0
- package/src/hub/research-quality.ts +8 -2
- package/src/hub/research-record.ts +35 -0
- package/src/hub/research.ts +128 -28
- package/src/hub/roadmap-check.ts +65 -0
- package/src/hub/roadmap-decompose.ts +139 -0
- package/src/hub/roadmap-export.ts +27 -0
- package/src/hub/roadmap-sync.ts +97 -0
- package/src/hub/roadmap.ts +59 -1
- package/src/hub/routing.ts +18 -1
- package/src/hub/runtime-capture-prune.ts +2 -1
- package/src/hub/sdlc-branch-ci.ts +128 -0
- package/src/hub/sdlc-merge.ts +6 -3
- package/src/hub/sdlc-metrics.ts +19 -5
- package/src/hub/sdlc.ts +73 -5
- package/src/hub/settings.ts +3 -1
- package/src/hub/snapshots.ts +13 -1
- package/src/hub/startup-event-seeds.ts +21 -15
- package/src/hub/startup-timing.ts +3 -1
- package/src/hub/supervision-proposals.ts +10 -2
- package/src/hub/supervision-rules.ts +26 -3
- package/src/hub/supervision.ts +7 -0
- package/src/hub/task-pr.ts +47 -0
- package/src/hub/task-worktree.ts +18 -11
- package/src/hub/tasks.ts +694 -44
- package/src/hub/ui.ts +6 -2
- package/src/hub/usage-rollup.ts +77 -22
- package/src/local/tools.ts +13 -1
- package/src/memory/client.ts +3 -2
- package/src/pi/extension.ts +15 -3
- package/src/pi/tool-receipts.ts +26 -0
- package/src/ui/index.html +342 -8
- package/src/ui/plugin.ts +6 -2
- package/src/ui/roadmap-model.ts +70 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hub skills for the agent hosts other than Claude Code (#1622).
|
|
3
|
+
*
|
|
4
|
+
* The Claude plugin carries the skills itself; every other host reads its own user skill directory, so `ahub setup`
|
|
5
|
+
* writes one tree per skill there. Each tree carries an `.ahub-skill.json` marker and is replaced only while it still
|
|
6
|
+
* holds exactly the digest the hub wrote. A tree the person edited, a tree another tool installed and a link are
|
|
7
|
+
* reported and left alone; `ahub setup --undo` removes only the hub's own unmodified trees. Other skills in the same
|
|
8
|
+
* host directory are never read, written or reported.
|
|
9
|
+
*/
|
|
10
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
11
|
+
import { lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { hostSkillDir, SKILL_HOSTS, type SkillHost } from "../adapters/definitions/native-cli-skills.ts";
|
|
15
|
+
import { realPath } from "../hub/project.ts";
|
|
16
|
+
import { VERSION } from "../version.ts";
|
|
17
|
+
|
|
18
|
+
export { hostSkillDir, SKILL_HOSTS, type SkillHost };
|
|
19
|
+
|
|
20
|
+
export const SKILL_MARKER = ".ahub-skill.json";
|
|
21
|
+
export const SKILL_TOOL = "agent-hub";
|
|
22
|
+
|
|
23
|
+
const SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
24
|
+
const MAX_FILES = 256;
|
|
25
|
+
const MAX_FILE_BYTES = 1024 * 1024;
|
|
26
|
+
const MAX_TREE_BYTES = 8 * 1024 * 1024;
|
|
27
|
+
|
|
28
|
+
export class SkillsInstallError extends Error {}
|
|
29
|
+
|
|
30
|
+
interface TreeFile { path: string; bytes: Buffer }
|
|
31
|
+
interface Tree { files: TreeFile[]; digest: string }
|
|
32
|
+
interface Marker { tool: string; version: string; sha256: string }
|
|
33
|
+
interface SourceSkill { name: string; tree: Tree }
|
|
34
|
+
|
|
35
|
+
export type SkillAction =
|
|
36
|
+
| "install" | "replace" | "unchanged" // a run that writes
|
|
37
|
+
| "modified" | "foreign" | "linked" | "failed" // a tree the hub does not own or cannot read
|
|
38
|
+
| "absent" | "missing" // no host on this machine, or no tree where the host is installed
|
|
39
|
+
| "remove" | "removed"; // the undo path
|
|
40
|
+
|
|
41
|
+
export interface SkillEntry {
|
|
42
|
+
host: SkillHost;
|
|
43
|
+
/** The skill directory name; empty for a host-level entry (no host, no directory). */
|
|
44
|
+
skill: string;
|
|
45
|
+
dir: string;
|
|
46
|
+
action: SkillAction;
|
|
47
|
+
detail: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type SkillState = "installed" | "stale" | "modified" | "foreign" | "linked" | "missing" | "absent" | "failed";
|
|
51
|
+
export interface SkillHostState {
|
|
52
|
+
host: SkillHost;
|
|
53
|
+
/** The host's skills directory (the parent of the installed trees). */
|
|
54
|
+
dir: string;
|
|
55
|
+
state: SkillState;
|
|
56
|
+
detail: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SkillPaths {
|
|
60
|
+
home?: string;
|
|
61
|
+
env?: NodeJS.ProcessEnv;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function digest(files: TreeFile[]): string {
|
|
65
|
+
const hash = createHash("sha256");
|
|
66
|
+
for (const file of [...files].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))) {
|
|
67
|
+
hash.update(file.path);
|
|
68
|
+
hash.update("\0");
|
|
69
|
+
hash.update(createHash("sha256").update(file.bytes).digest("hex"));
|
|
70
|
+
hash.update("\n");
|
|
71
|
+
}
|
|
72
|
+
return hash.digest("hex");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function lstat(path: string): ReturnType<typeof lstatSync> | undefined {
|
|
76
|
+
try { return lstatSync(path); } catch { return undefined; }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Read one skill tree: regular files only, no link followed, bounded count and size. */
|
|
80
|
+
function readTree(dir: string): Tree {
|
|
81
|
+
let root: ReturnType<typeof lstatSync>;
|
|
82
|
+
try { root = lstatSync(dir); } catch (error) {
|
|
83
|
+
throw new SkillsInstallError(`cannot read ${dir}: ${(error as Error).message}`);
|
|
84
|
+
}
|
|
85
|
+
if (root.isSymbolicLink()) throw new SkillsInstallError(`refused a link: ${dir}`);
|
|
86
|
+
if (!root.isDirectory()) throw new SkillsInstallError(`not a directory: ${dir}`);
|
|
87
|
+
const files: TreeFile[] = [];
|
|
88
|
+
let total = 0;
|
|
89
|
+
const walk = (abs: string, rel: string): void => {
|
|
90
|
+
const stat = lstatSync(abs);
|
|
91
|
+
if (stat.isSymbolicLink()) throw new SkillsInstallError(`refused a link: ${abs}`);
|
|
92
|
+
if (stat.isDirectory()) {
|
|
93
|
+
for (const name of readdirSync(abs).sort()) {
|
|
94
|
+
if (name === SKILL_MARKER) continue;
|
|
95
|
+
walk(join(abs, name), rel ? `${rel}/${name}` : name);
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!stat.isFile()) throw new SkillsInstallError(`not a regular file: ${abs}`);
|
|
100
|
+
if (stat.size > MAX_FILE_BYTES) throw new SkillsInstallError(`file too large (limit ${MAX_FILE_BYTES} bytes): ${abs}`);
|
|
101
|
+
if (files.length >= MAX_FILES) throw new SkillsInstallError(`too many files under ${dir} (limit ${MAX_FILES})`);
|
|
102
|
+
total += stat.size;
|
|
103
|
+
if (total > MAX_TREE_BYTES) throw new SkillsInstallError(`tree too large under ${dir} (limit ${MAX_TREE_BYTES} bytes)`);
|
|
104
|
+
files.push({ path: rel, bytes: readFileSync(abs) });
|
|
105
|
+
};
|
|
106
|
+
walk(dir, "");
|
|
107
|
+
return { files, digest: digest(files) };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function readSource(source: string): SourceSkill[] {
|
|
111
|
+
const root = lstat(source);
|
|
112
|
+
if (!root) throw new SkillsInstallError(`cannot read the hub skill source ${source}`);
|
|
113
|
+
if (root.isSymbolicLink() || !root.isDirectory()) throw new SkillsInstallError(`the hub skill source is not a directory: ${source}`);
|
|
114
|
+
const skills: SourceSkill[] = [];
|
|
115
|
+
for (const name of readdirSync(source).sort()) {
|
|
116
|
+
if (name.startsWith(".")) continue;
|
|
117
|
+
const abs = join(source, name);
|
|
118
|
+
const stat = lstat(abs);
|
|
119
|
+
if (!stat) throw new SkillsInstallError(`cannot read ${abs}`);
|
|
120
|
+
if (stat.isSymbolicLink()) throw new SkillsInstallError(`refused a link in the hub skill source: ${abs}`);
|
|
121
|
+
if (!stat.isDirectory()) continue;
|
|
122
|
+
if (!SKILL_NAME.test(name)) throw new SkillsInstallError(`not a usable skill name: ${name}`);
|
|
123
|
+
skills.push({ name, tree: readTree(abs) });
|
|
124
|
+
}
|
|
125
|
+
if (!skills.length) throw new SkillsInstallError(`no skills under ${source}`);
|
|
126
|
+
return skills;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function readMarker(dir: string): Marker | "missing" | "foreign" {
|
|
130
|
+
let text: string;
|
|
131
|
+
try { text = readFileSync(join(dir, SKILL_MARKER), "utf8"); } catch { return "missing"; }
|
|
132
|
+
try {
|
|
133
|
+
const value = JSON.parse(text) as Partial<Marker>;
|
|
134
|
+
if (value.tool === SKILL_TOOL && typeof value.version === "string" && typeof value.sha256 === "string") {
|
|
135
|
+
return { tool: value.tool, version: value.version, sha256: value.sha256 };
|
|
136
|
+
}
|
|
137
|
+
} catch { /* a malformed marker is not the hub's */ }
|
|
138
|
+
return "foreign";
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Resolve the host's config home and skill directory without following a link in the skill trees. A symlinked config
|
|
143
|
+
* home is the host's own choice and is resolved with `realPath`; a symlinked skills directory is refused.
|
|
144
|
+
*/
|
|
145
|
+
function locate(host: SkillHost, paths: SkillPaths): { dir: string } | { action: "absent" | "failed" | "linked" | "foreign"; dir: string; detail: string } {
|
|
146
|
+
const lexical = hostSkillDir(host, paths.home ?? homedir(), paths.env ?? process.env);
|
|
147
|
+
const configHome = dirname(lexical);
|
|
148
|
+
const config = lstat(configHome);
|
|
149
|
+
if (!config) return { action: "absent", dir: lexical, detail: `host not installed: no ${configHome}` };
|
|
150
|
+
if (!config.isSymbolicLink() && !config.isDirectory()) return { action: "failed", dir: lexical, detail: `${configHome} is not a directory` };
|
|
151
|
+
let resolved: string;
|
|
152
|
+
try { resolved = realPath(configHome); } catch (error) { return { action: "failed", dir: lexical, detail: `${configHome}: ${(error as Error).message}` }; }
|
|
153
|
+
// The config home link is the host's own choice and has been resolved above; a linked skills directory is not.
|
|
154
|
+
const dir = join(resolved, "skills");
|
|
155
|
+
const stat = lstat(dir);
|
|
156
|
+
if (stat?.isSymbolicLink()) return { action: "linked", dir, detail: "the skills directory is a link; left untouched" };
|
|
157
|
+
if (stat && !stat.isDirectory()) return { action: "foreign", dir, detail: "the skills path is not a directory; left untouched" };
|
|
158
|
+
return { dir };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** What one skill tree would become, without writing anything. */
|
|
162
|
+
function inspectSkill(host: SkillHost, skill: SourceSkill, base: string): SkillEntry {
|
|
163
|
+
const dir = join(base, skill.name);
|
|
164
|
+
const entry = (action: SkillAction, detail: string): SkillEntry => ({ host, skill: skill.name, dir, action, detail });
|
|
165
|
+
const stat = lstat(dir);
|
|
166
|
+
if (!stat) return entry("install", "not installed");
|
|
167
|
+
if (stat.isSymbolicLink()) return entry("linked", "the skill directory is a link; left untouched");
|
|
168
|
+
if (!stat.isDirectory()) return entry("foreign", "not a directory; left untouched");
|
|
169
|
+
const marker = readMarker(dir);
|
|
170
|
+
if (marker === "missing") return entry("foreign", `no ${SKILL_MARKER}; left untouched`);
|
|
171
|
+
if (marker === "foreign") return entry("foreign", `${SKILL_MARKER} is not the hub's; left untouched`);
|
|
172
|
+
let installed: Tree;
|
|
173
|
+
try { installed = readTree(dir); } catch (error) { return entry("failed", (error as Error).message); }
|
|
174
|
+
if (installed.digest !== marker.sha256) return entry("modified", "edited since the hub wrote it; left untouched");
|
|
175
|
+
if (marker.version !== VERSION) return entry("replace", `stale ${marker.version} -> ${VERSION}`);
|
|
176
|
+
if (installed.digest !== skill.tree.digest) return entry("replace", "the hub's files changed at the same version");
|
|
177
|
+
return entry("unchanged", VERSION);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Plan the install for every host, from a source tree in this package. Throws when the source is unreadable. */
|
|
181
|
+
export function skillInstallPlan(source: string, paths: SkillPaths = {}): SkillEntry[] {
|
|
182
|
+
const skills = readSource(source);
|
|
183
|
+
const plan: SkillEntry[] = [];
|
|
184
|
+
for (const host of SKILL_HOSTS) {
|
|
185
|
+
const found = locate(host, paths);
|
|
186
|
+
if ("action" in found) { plan.push({ host, skill: "", dir: found.dir, action: found.action, detail: found.detail }); continue; }
|
|
187
|
+
for (const skill of skills) plan.push(inspectSkill(host, skill, found.dir));
|
|
188
|
+
}
|
|
189
|
+
return plan;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Plan the undo: only a tree the hub wrote and nobody edited is marked for removal. Other skills are not listed. */
|
|
193
|
+
export function skillUndoPlan(paths: SkillPaths = {}): SkillEntry[] {
|
|
194
|
+
const plan: SkillEntry[] = [];
|
|
195
|
+
for (const host of SKILL_HOSTS) {
|
|
196
|
+
const found = locate(host, paths);
|
|
197
|
+
if ("action" in found) { plan.push({ host, skill: "", dir: found.dir, action: found.action, detail: found.detail }); continue; }
|
|
198
|
+
const stat = lstat(found.dir);
|
|
199
|
+
if (!stat) { plan.push({ host, skill: "", dir: found.dir, action: "absent", detail: "not installed" }); continue; }
|
|
200
|
+
if (stat.isSymbolicLink()) { plan.push({ host, skill: "", dir: found.dir, action: "linked", detail: "the skill directory is a link; left untouched" }); continue; }
|
|
201
|
+
if (!stat.isDirectory()) { plan.push({ host, skill: "", dir: found.dir, action: "foreign", detail: "not a directory; left untouched" }); continue; }
|
|
202
|
+
let names: string[];
|
|
203
|
+
try { names = readdirSync(found.dir).sort(); } catch (error) { plan.push({ host, skill: "", dir: found.dir, action: "failed", detail: (error as Error).message }); continue; }
|
|
204
|
+
let seen = 0;
|
|
205
|
+
for (const name of names) {
|
|
206
|
+
if (name.startsWith(".")) continue;
|
|
207
|
+
const dir = join(found.dir, name);
|
|
208
|
+
const child = lstat(dir);
|
|
209
|
+
if (!child || child.isSymbolicLink() || !child.isDirectory()) continue;
|
|
210
|
+
const marker = readMarker(dir);
|
|
211
|
+
if (marker === "missing" || marker === "foreign") continue; // another tool's skill is not the hub's
|
|
212
|
+
seen += 1;
|
|
213
|
+
let installed: Tree;
|
|
214
|
+
try { installed = readTree(dir); } catch (error) { plan.push({ host, skill: name, dir, action: "failed", detail: (error as Error).message }); continue; }
|
|
215
|
+
if (installed.digest !== marker.sha256) { plan.push({ host, skill: name, dir, action: "modified", detail: "edited since the hub wrote it; left untouched" }); continue; }
|
|
216
|
+
plan.push({ host, skill: name, dir, action: "remove", detail: `the hub's ${marker.version} tree` });
|
|
217
|
+
}
|
|
218
|
+
if (!seen) plan.push({ host, skill: "", dir: found.dir, action: "absent", detail: "no hub skill tree" });
|
|
219
|
+
}
|
|
220
|
+
return plan;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Write one tree beside its target and rename it into place; the marker lands with the files, never before them. */
|
|
224
|
+
function writeTree(target: string, tree: Tree): void {
|
|
225
|
+
const parent = dirname(target);
|
|
226
|
+
mkdirSync(parent, { recursive: true, mode: 0o755 });
|
|
227
|
+
const temp = `${target}.ahub-tmp-${process.pid}-${randomUUID()}`;
|
|
228
|
+
let previous: string | undefined;
|
|
229
|
+
try {
|
|
230
|
+
mkdirSync(temp, { mode: 0o755 });
|
|
231
|
+
for (const file of tree.files) {
|
|
232
|
+
const dest = join(temp, ...file.path.split("/"));
|
|
233
|
+
mkdirSync(dirname(dest), { recursive: true, mode: 0o755 });
|
|
234
|
+
writeFileSync(dest, file.bytes, { flag: "wx", mode: 0o644 });
|
|
235
|
+
}
|
|
236
|
+
const marker = JSON.stringify({ tool: SKILL_TOOL, version: VERSION, sha256: tree.digest }, null, 2) + "\n";
|
|
237
|
+
writeFileSync(join(temp, SKILL_MARKER), marker, { flag: "wx", mode: 0o644 });
|
|
238
|
+
if (lstat(target)) {
|
|
239
|
+
previous = `${target}.ahub-old-${process.pid}-${randomUUID()}`;
|
|
240
|
+
renameSync(target, previous);
|
|
241
|
+
}
|
|
242
|
+
try { renameSync(temp, target); }
|
|
243
|
+
catch (error) {
|
|
244
|
+
if (previous) {
|
|
245
|
+
try { renameSync(previous, target); } catch { /* the old tree keeps its temporary name and is named in the error */ }
|
|
246
|
+
}
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
if (previous) rmSync(previous, { recursive: true, force: true });
|
|
250
|
+
} catch (error) {
|
|
251
|
+
rmSync(temp, { recursive: true, force: true });
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** True when the directory a tree lives in became a link after the plan; writing through it would land outside. */
|
|
257
|
+
function hostDirLinked(dir: string): boolean {
|
|
258
|
+
return lstat(dirname(dir))?.isSymbolicLink() ?? false;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Apply the entries that write. A host that cannot be written is reported, never thrown, so other hosts still install. */
|
|
262
|
+
export function applySkillPlan(source: string, plan: SkillEntry[]): SkillEntry[] {
|
|
263
|
+
const skills = new Map(readSource(source).map(skill => [skill.name, skill]));
|
|
264
|
+
return plan.map(entry => {
|
|
265
|
+
if (entry.action !== "install" && entry.action !== "replace") return entry;
|
|
266
|
+
const skill = skills.get(entry.skill);
|
|
267
|
+
if (!skill) return { ...entry, action: "failed", detail: `no source for ${entry.skill}` };
|
|
268
|
+
// The plan was made before the question; a tree or a skills directory that changed while it was open is kept.
|
|
269
|
+
if (hostDirLinked(entry.dir)) return { ...entry, action: "linked", detail: "the skills directory became a link; left untouched" };
|
|
270
|
+
const fresh = inspectSkill(entry.host, skill, dirname(entry.dir));
|
|
271
|
+
if (fresh.action === "unchanged") return fresh;
|
|
272
|
+
if (fresh.action !== "install" && fresh.action !== "replace") {
|
|
273
|
+
return { ...fresh, detail: `${fresh.detail} (changed since the plan; left untouched)` };
|
|
274
|
+
}
|
|
275
|
+
try { writeTree(entry.dir, skill.tree); return { ...entry, detail: entry.action === "replace" ? entry.detail : VERSION }; }
|
|
276
|
+
catch (error) { return { ...entry, action: "failed", detail: (error as Error).message }; }
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Apply the undo. The marker and digest are checked again here, so a tree edited after the plan is not removed. */
|
|
281
|
+
export function applySkillUndo(plan: SkillEntry[]): SkillEntry[] {
|
|
282
|
+
return plan.map(entry => {
|
|
283
|
+
if (entry.action !== "remove") return entry;
|
|
284
|
+
if (hostDirLinked(entry.dir)) return { ...entry, action: "linked", detail: "the skills directory became a link; left untouched" };
|
|
285
|
+
const stat = lstat(entry.dir);
|
|
286
|
+
if (!stat || stat.isSymbolicLink() || !stat.isDirectory()) return { ...entry, action: "foreign", detail: "changed since the plan; left untouched" };
|
|
287
|
+
const marker = readMarker(entry.dir);
|
|
288
|
+
if (marker === "missing" || marker === "foreign") return { ...entry, action: "foreign", detail: "changed since the plan; left untouched" };
|
|
289
|
+
let installed: Tree;
|
|
290
|
+
try { installed = readTree(entry.dir); } catch (error) { return { ...entry, action: "failed", detail: (error as Error).message }; }
|
|
291
|
+
if (installed.digest !== marker.sha256) return { ...entry, action: "modified", detail: "edited since the plan; left untouched" };
|
|
292
|
+
try { rmSync(entry.dir, { recursive: true, force: false }); return { ...entry, action: "removed", detail: entry.detail }; }
|
|
293
|
+
catch (error) { return { ...entry, action: "failed", detail: (error as Error).message }; }
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function skillState(dir: string): { state: SkillState; detail: string } {
|
|
298
|
+
const stat = lstat(dir);
|
|
299
|
+
if (!stat) return { state: "missing", detail: "not installed" };
|
|
300
|
+
if (stat.isSymbolicLink()) return { state: "linked", detail: "the skill directory is a link" };
|
|
301
|
+
if (!stat.isDirectory()) return { state: "foreign", detail: "not a directory" };
|
|
302
|
+
const marker = readMarker(dir);
|
|
303
|
+
if (marker === "missing") return { state: "foreign", detail: `no ${SKILL_MARKER}` };
|
|
304
|
+
if (marker === "foreign") return { state: "foreign", detail: `${SKILL_MARKER} is not the hub's` };
|
|
305
|
+
let installed: Tree;
|
|
306
|
+
try { installed = readTree(dir); } catch (error) { return { state: "failed", detail: (error as Error).message }; }
|
|
307
|
+
if (installed.digest !== marker.sha256) return { state: "modified", detail: "edited since the hub wrote it" };
|
|
308
|
+
if (marker.version !== VERSION) return { state: "stale", detail: `${marker.version} -> ${VERSION}` };
|
|
309
|
+
return { state: "installed", detail: VERSION };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const STATE_ORDER: readonly SkillState[] = ["failed", "linked", "foreign", "modified", "stale", "missing", "installed"];
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* What the doctor reads: one state per host, without writing anything. `expected` names the skills this package ships,
|
|
316
|
+
* so a tree the hub wrote and no longer ships is not read as a missing skill.
|
|
317
|
+
*/
|
|
318
|
+
export function skillHostStates(paths: SkillPaths, expected: readonly string[]): SkillHostState[] {
|
|
319
|
+
return SKILL_HOSTS.map(host => {
|
|
320
|
+
const found = locate(host, paths);
|
|
321
|
+
if ("action" in found) return { host, dir: found.dir, state: found.action, detail: found.detail };
|
|
322
|
+
const stat = lstat(found.dir);
|
|
323
|
+
if (!stat) return { host, dir: found.dir, state: "missing", detail: "not installed" };
|
|
324
|
+
if (stat.isSymbolicLink()) return { host, dir: found.dir, state: "linked", detail: "the skills directory is a link" };
|
|
325
|
+
if (!stat.isDirectory()) return { host, dir: found.dir, state: "foreign", detail: "not a directory" };
|
|
326
|
+
const problems = [...expected].map(name => ({ name, ...skillState(join(found.dir, name)) })).filter(item => item.state !== "installed");
|
|
327
|
+
const state = STATE_ORDER.find(candidate => problems.some(problem => problem.state === candidate)) ?? "installed";
|
|
328
|
+
return {
|
|
329
|
+
host, dir: found.dir, state,
|
|
330
|
+
detail: problems.length ? problems.map(problem => `${problem.name} ${problem.state}`).join(", ") : `${expected.length} installed`,
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** One doctor row for every selected host. `undefined` is a warning: a tree the hub will not touch is not a failure. */
|
|
336
|
+
export function skillStateRow(states: SkillHostState[]): { ok: boolean | undefined; detail: string } {
|
|
337
|
+
const selected = states.filter(state => state.state !== "absent");
|
|
338
|
+
if (!selected.length) return { ok: true, detail: "no other agent host installed on this machine" };
|
|
339
|
+
const needsSetup = selected.some(state => state.state === "missing" || state.state === "stale" || state.state === "failed");
|
|
340
|
+
const warning = selected.some(state => state.state === "modified" || state.state === "foreign" || state.state === "linked");
|
|
341
|
+
return {
|
|
342
|
+
ok: needsSetup ? false : warning ? undefined : true,
|
|
343
|
+
detail: selected.map(state => `${state.host} ${state.state}`).join("; "),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface SkillInstallOptions extends SkillPaths {
|
|
348
|
+
/** The package's skill directory. Required for an install, unused by `undo`. */
|
|
349
|
+
source?: string;
|
|
350
|
+
undo?: boolean;
|
|
351
|
+
yes: boolean;
|
|
352
|
+
ask?: (prompt: string) => Promise<string | null>;
|
|
353
|
+
print: (line: string) => void;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function hostEntries(plan: SkillEntry[], host: SkillHost): SkillEntry[] {
|
|
357
|
+
return plan.filter(entry => entry.host === host);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function absentLine(entry: SkillEntry): string {
|
|
361
|
+
if (entry.action === "absent") return `${entry.host} not installed (${entry.detail})`;
|
|
362
|
+
if (entry.action === "linked") return `${entry.host} link; left untouched (${entry.dir})`;
|
|
363
|
+
if (entry.action === "foreign") return `${entry.host} foreign tree; left untouched (${entry.dir})`;
|
|
364
|
+
return `${entry.host} cannot be read: ${entry.detail}`;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function skillNames(entries: SkillEntry[], actions: readonly SkillAction[]): string {
|
|
368
|
+
const names = entries.filter(entry => entry.skill && actions.includes(entry.action)).map(entry => entry.skill);
|
|
369
|
+
return names.length ? ` (${names.join(", ")} left untouched)` : "";
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function hostSummary(entries: SkillEntry[], done: boolean, undo: boolean): string {
|
|
373
|
+
const count = (action: SkillAction) => entries.filter(entry => entry.action === action).length;
|
|
374
|
+
const parts: string[] = [];
|
|
375
|
+
const push = (n: number, text: string) => { if (n) parts.push(text); };
|
|
376
|
+
if (undo) {
|
|
377
|
+
push(count("remove"), `${count("remove")} would remove`);
|
|
378
|
+
push(count("removed"), `${count("removed")} removed`);
|
|
379
|
+
} else if (done) {
|
|
380
|
+
push(count("install"), `${count("install")} installed`);
|
|
381
|
+
push(count("replace"), `${count("replace")} replaced`);
|
|
382
|
+
} else {
|
|
383
|
+
push(count("install"), `${count("install")} would install`);
|
|
384
|
+
push(count("replace"), `${count("replace")} would replace`);
|
|
385
|
+
}
|
|
386
|
+
push(count("unchanged"), `${count("unchanged")} up to date`);
|
|
387
|
+
push(count("modified"), `${count("modified")} modified`);
|
|
388
|
+
push(count("foreign"), `${count("foreign")} foreign`);
|
|
389
|
+
push(count("linked"), `${count("linked")} linked`);
|
|
390
|
+
push(count("failed"), `${count("failed")} unreadable`);
|
|
391
|
+
return parts.join(", ") || "nothing to do";
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function printHosts(plan: SkillEntry[], options: SkillInstallOptions, done: boolean, undo: boolean): void {
|
|
395
|
+
for (const host of SKILL_HOSTS) {
|
|
396
|
+
const entries = hostEntries(plan, host);
|
|
397
|
+
const hostLevel = entries.find(entry => !entry.skill);
|
|
398
|
+
if (hostLevel) { options.print(`hub skills: ${absentLine(hostLevel)}`); continue; }
|
|
399
|
+
const left = skillNames(entries, ["modified", "foreign", "linked"]);
|
|
400
|
+
options.print(`hub skills: ${host} ${hostSummary(entries, done, undo)}${left}`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
async function confirm(options: SkillInstallOptions, prompt: string): Promise<boolean> {
|
|
405
|
+
if (options.yes) return true;
|
|
406
|
+
if (!options.ask) return false;
|
|
407
|
+
const answer = await options.ask(prompt);
|
|
408
|
+
return typeof answer === "string" && /^y(es)?$/i.test(answer.trim());
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function tally(entries: SkillEntry[], action: SkillAction): number {
|
|
412
|
+
return entries.filter(entry => entry.action === action).length;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function finishLine(entries: SkillEntry[]): string {
|
|
416
|
+
const installed = tally(entries, "install"), replaced = tally(entries, "replace"), removed = tally(entries, "removed"), failed = tally(entries, "failed");
|
|
417
|
+
const changed = installed + replaced + removed;
|
|
418
|
+
return `hub skills: ${installed} installed, ${replaced} replaced, ${removed} removed, ${failed} failed, ${entries.length - changed - failed} left`;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* `ahub setup`'s skill step: print what would happen, ask once (unless `--yes`), then write or remove. Everything the
|
|
423
|
+
* hub does not own is reported and left alone. Never throws for a missing source: setup reports it and keeps going.
|
|
424
|
+
*/
|
|
425
|
+
export async function installHubSkills(options: SkillInstallOptions): Promise<void> {
|
|
426
|
+
if (options.undo) {
|
|
427
|
+
const plan = skillUndoPlan(options);
|
|
428
|
+
printHosts(plan, options, false, true);
|
|
429
|
+
const removable = plan.filter(entry => entry.action === "remove");
|
|
430
|
+
if (!removable.length) { options.print("hub skills: nothing to remove"); return; }
|
|
431
|
+
if (!(await confirm(options, `Remove ${removable.length} hub skill ${removable.length === 1 ? "tree" : "trees"}? [y/N] `))) {
|
|
432
|
+
options.print("hub skills: nothing removed; rerun with --yes");
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const done = applySkillUndo(plan);
|
|
436
|
+
printHosts(done, options, true, true);
|
|
437
|
+
options.print(finishLine(done));
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (!options.source) throw new SkillsInstallError("the hub skill source directory is missing");
|
|
441
|
+
let plan: SkillEntry[];
|
|
442
|
+
try { plan = skillInstallPlan(options.source, options); }
|
|
443
|
+
catch (error) {
|
|
444
|
+
options.print(`hub skills: skipped (${(error as Error).message})`);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
printHosts(plan, options, false, false);
|
|
448
|
+
const writable = plan.filter(entry => entry.action === "install" || entry.action === "replace");
|
|
449
|
+
if (!writable.length) { options.print("hub skills: up to date; nothing written"); return; }
|
|
450
|
+
const hosts = [...new Set(writable.map(entry => entry.host))];
|
|
451
|
+
if (!(await confirm(options, `Install hub skills for ${hosts.join(", ")}? [y/N] `))) {
|
|
452
|
+
options.print("hub skills: nothing written; rerun with --yes");
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
let done: SkillEntry[];
|
|
456
|
+
try { done = applySkillPlan(options.source, plan); }
|
|
457
|
+
catch (error) {
|
|
458
|
+
options.print(`hub skills: write failed (${(error as Error).message})`);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
printHosts(done, options, true, false);
|
|
462
|
+
options.print(finishLine(done));
|
|
463
|
+
}
|
package/src/cli/task-output.ts
CHANGED
|
@@ -93,7 +93,7 @@ const planBlock = (plan: any, columns: number | undefined): Line[] => {
|
|
|
93
93
|
const keys = ["paths", "symbols", "signatures", "insertion_points", "sections", "sources", "claims"];
|
|
94
94
|
return keys.flatMap(key => bullets(key.replace("_", " "), list(plan?.[key]), columns, undefined, " "));
|
|
95
95
|
};
|
|
96
|
-
const historyRows = (history: any[], now: number): Span[][] => history.map(entry => [s(when(entry.at, now), "muted"), s(entry.by ?? "-"), s(entry.event ?? "-", entry.event === "approved" ? "success" : entry.event === "changes_requested" ? "attention" : undefined), s(dash(entry.note))]);
|
|
96
|
+
const historyRows = (history: any[], now: number): Span[][] => history.map(entry => [s(when(entry.at, now), "muted"), s(entry.instructed && entry.instructedPeer ? `${entry.by ?? "user"} via ${entry.instructedPeer}` : entry.by ?? "-"), s(entry.event ?? "-", entry.event === "approved" ? "success" : entry.event === "changes_requested" ? "attention" : undefined), s(dash(entry.note))]);
|
|
97
97
|
|
|
98
98
|
/** The one task block: identity, who holds it, what it waits for, then plan, receipt and history. */
|
|
99
99
|
function taskBlock(task: any, columns: number | undefined, now: number, detail: boolean): Line[] {
|
|
@@ -24,7 +24,7 @@ export function readRecoveryPresentationFlags(
|
|
|
24
24
|
else if (flag?.kind === "verbose") { verbose = true; flags.push(arg); }
|
|
25
25
|
else args.push(arg);
|
|
26
26
|
}
|
|
27
|
-
const resolved = resolveColor(color, terminal);
|
|
27
|
+
const resolved = resolveColor(color, terminal, "ahub");
|
|
28
28
|
if (resolved instanceof Error) throw resolved;
|
|
29
29
|
const columns = terminal.columns !== undefined && Number.isFinite(terminal.columns) && terminal.columns > 0 ? Math.floor(terminal.columns) : 80;
|
|
30
30
|
return { args, flags, json, options: { columns, color: resolved, verbose, now } };
|
|
@@ -485,7 +485,8 @@ export function preserveSource(plan: UpgradePlan, home = hubHome()): string {
|
|
|
485
485
|
|
|
486
486
|
const unboundRecoveryInspection = inspectRecovery;
|
|
487
487
|
|
|
488
|
-
|
|
488
|
+
/** `clock.waitSliceMs` (#1578) is forwarded to the attachment wait as its poll slice, so a test can poll coarser; production passes nothing and keeps 1 s. */
|
|
489
|
+
export function makeRecoveryDriver(run: RunCommand = runCommand, liveTestPeer?: string, clock?: Pick<RecoveryDriver, "now" | "sleep"> & { waitSliceMs?: number }, conductorPeer?: string): RecoveryDriver {
|
|
489
490
|
let authorizedOperation: RecoveryOperation | undefined;
|
|
490
491
|
const recoveryCurrent = async () => { if (conductorPeer) { if (!authorizedOperation) throw new FinalRefusal("conductor recovery authority unavailable"); await authorizeConductorOperation(authorizedOperation, conductorPeer); } };
|
|
491
492
|
const inspectRecovery = (project: Project, features?: readonly string[], purpose?: "cleanup") => unboundRecoveryInspection(project, features, purpose, conductorPeer);
|
|
@@ -640,8 +641,11 @@ export function makeRecoveryDriver(run: RunCommand = runCommand, liveTestPeer?:
|
|
|
640
641
|
if (result.manualRequired) throw new Error(`${peer}: closing terminal ${retired.handle} of the stopped target's session was not verified; manual-required`);
|
|
641
642
|
progress.terminals[key] = true; save();
|
|
642
643
|
};
|
|
643
|
-
/** #414: an idle terminal is not an authenticated peer. Keep its receipt while waiting, including on resume.
|
|
644
|
-
|
|
644
|
+
/** #414: an idle terminal is not an authenticated peer. Keep its receipt while waiting, including on resume.
|
|
645
|
+
* #1578: `waitSliceMs` is the poll slice, 1 s in production. It is a parameter with a default, not the enclosing `clock`, because
|
|
646
|
+
* `test/upgrade-timing-failure.test.ts` runs this closure's own source in a sandbox that provides only named ports. Only a test
|
|
647
|
+
* passes a larger slice, so a 600 s deadline costs fewer polls; the last slice is still clamped to the remaining time. */
|
|
648
|
+
const awaitAttachment = async (planned: PlannedProject, progress: ProjectProgress, op: RecoveryOperation, waiting: Extract<RestoreReceipt, { state: "waiting" }>, save: () => void, expectedSession: string | null = waiting.binding.sessionId, waitSliceMs = 1000): Promise<string> => {
|
|
645
649
|
const saveTiming = () => {
|
|
646
650
|
try { save(); }
|
|
647
651
|
catch { console.warn("Recovery timing observation could not be saved; recovery continues"); }
|
|
@@ -686,7 +690,7 @@ export function makeRecoveryDriver(run: RunCommand = runCommand, liveTestPeer?:
|
|
|
686
690
|
else { launchState = "older-instance"; olderHandle = evidence.handle; }
|
|
687
691
|
} else if (evidence.state === "live" && evidence.session) {
|
|
688
692
|
if (now() >= deadline) break;
|
|
689
|
-
await sleep(Math.min(
|
|
693
|
+
await sleep(Math.min(waitSliceMs, deadline - now()));
|
|
690
694
|
continue;
|
|
691
695
|
}
|
|
692
696
|
}
|
|
@@ -704,7 +708,7 @@ export function makeRecoveryDriver(run: RunCommand = runCommand, liveTestPeer?:
|
|
|
704
708
|
throw nativeFailure(planned, binding.peer, "launcher_unverified", `${binding.peer}: the chosen restoration launcher's identity cannot be verified (${launchState}); saved terminal retained; no terminal was created`, { handle: binding.handle, launcherState: launchState });
|
|
705
709
|
}
|
|
706
710
|
if (now() >= deadline) break;
|
|
707
|
-
await sleep(Math.min(
|
|
711
|
+
await sleep(Math.min(waitSliceMs, deadline - now()));
|
|
708
712
|
}
|
|
709
713
|
const terminal: NonNullable<ProjectProgress["attachmentTimeouts"]>[string]["terminal"] = { handle: binding.handle, incarnationId: binding.incarnationId, state: "unknown" };
|
|
710
714
|
try {
|
|
@@ -973,7 +977,7 @@ export function makeRecoveryDriver(run: RunCommand = runCommand, liveTestPeer?:
|
|
|
973
977
|
function awaitBound(waiting: Extract<RestoreReceipt, { state: "waiting" }> & { origin: "pending" }, expected: string | null): Promise<string>;
|
|
974
978
|
function awaitBound(waiting: Extract<RestoreReceipt, { state: "waiting" }>, expected: string | null): Promise<string | undefined>;
|
|
975
979
|
async function awaitBound(waiting: Extract<RestoreReceipt, { state: "waiting" }>, expected: string | null): Promise<string | undefined> {
|
|
976
|
-
try { return await awaitAttachment(planned, progress, op, waiting, save, expected); }
|
|
980
|
+
try { return await awaitAttachment(planned, progress, op, waiting, save, expected, clock?.waitSliceMs); }
|
|
977
981
|
catch (error) {
|
|
978
982
|
if (!(error instanceof AttachmentLauncherGone)) throw error;
|
|
979
983
|
progress.terminals[key] = error.transition.next; save();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import packageJson from "../../package.json";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #1611: the first-party memory core is declared as `>=X.Y.Z <M.0.0` (X.Y.Z at or above 0.33.0, M the next major), so a new minor
|
|
5
|
+
* reaches users without a hub release; the host API range below, not the version number, decides whether it is compatible.
|
|
6
|
+
* Legacy `~X.Y.Z` (#1605) declarations still verify in an older recovery package.
|
|
7
|
+
*/
|
|
8
|
+
export const AGENT_MEM_RANGE: string = packageJson.dependencies["@staix/agent-mem"];
|
|
9
|
+
/** The agent-mem host API versions this hub supports, inclusive: [min, max]. A new major host API is a reviewed hub change. */
|
|
10
|
+
export const AGENT_MEM_HOST_API_RANGE: readonly [number, number] = [1, 1];
|
|
11
|
+
/**
|
|
12
|
+
* #1611: the declared form `>=X.Y.Z <M.0.0` with X.Y.Z at or above 0.33.0 and M the next major.
|
|
13
|
+
* ponytail: a copy of scripts/lib/agent-mem-range.mjs, because a preserved source holds no scripts/ directory (the import failed in recovery); test/npm-pin.test.ts pins both to the same answers. Upgrade path: one shared file under src/ that the scripts import.
|
|
14
|
+
*/
|
|
15
|
+
export function isAgentMemFloorRange(value: unknown): boolean {
|
|
16
|
+
const match = /^>=(\d+)\.(\d+)\.(\d+) <(\d+)\.0\.0$/.exec(typeof value === "string" ? value : "");
|
|
17
|
+
if (!match) return false;
|
|
18
|
+
const major = Number(match[1]), minor = Number(match[2]);
|
|
19
|
+
return Number(match[4]) === major + 1 && (major > 0 || minor >= 33);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The host API constants a staged package's src/memory/platform.ts exports, as numbers (undefined when absent). */
|
|
23
|
+
export function readHostApiConstants(source: string): { min: number | undefined; version: number | undefined } {
|
|
24
|
+
const read = (name: string): number | undefined => { const text = new RegExp(`export const ${name} = (\\d+)`).exec(source)?.[1]; return text === undefined ? undefined : Number(text); };
|
|
25
|
+
return { min: read("HOST_API_MIN"), version: read("HOST_API_VERSION") };
|
|
26
|
+
}
|
|
27
|
+
const PATCH_RANGE = /^~\d+\.\d+\.\d+$/;
|
|
28
|
+
const PLAIN_RELEASE = /^\d+\.\d+\.\d+$/;
|
|
29
|
+
|
|
30
|
+
/** Whether `version` is a plain release (no prerelease or build suffix) that satisfies the declared range (floor form, or legacy patch form). */
|
|
31
|
+
export function agentMemVersionInRange(version: unknown, range: string = AGENT_MEM_RANGE): boolean {
|
|
32
|
+
if (typeof version !== "string" || !PLAIN_RELEASE.test(version)) return false;
|
|
33
|
+
if (!PATCH_RANGE.test(range) && !isAgentMemFloorRange(range)) return false;
|
|
34
|
+
return Bun.semver.satisfies(version, range);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const positive = (value: unknown): value is number => typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
38
|
+
|
|
39
|
+
/** Whether the package's host API constants are valid positive integers (MIN <= VERSION) and their range intersects the supported one. */
|
|
40
|
+
export function agentMemHostApiOk(min: unknown, version: unknown, supported: readonly [number, number] = AGENT_MEM_HOST_API_RANGE): boolean {
|
|
41
|
+
const [lowest, highest] = supported;
|
|
42
|
+
return positive(min) && positive(version) && min <= version && min <= highest && version >= lowest;
|
|
43
|
+
}
|