@staix/agent-hub 0.44.0 → 0.45.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 +40 -0
- package/README.md +3 -8
- package/docs/agent-notes/adapters.md +2 -2
- package/docs/agent-notes/daemon.md +1 -1
- package/docs/agent-notes/local-worker.md +1 -1
- package/docs/agent-notes/security-review.md +1 -1
- package/docs/agent-notes/tasks.md +3 -1
- package/docs/agent-notes/tests.md +3 -2
- package/docs/design/adapters.md +4 -2
- package/docs/design/agent-hub.md +1 -1
- package/docs/design/roadmap.md +75 -2
- package/docs/design/supervision.md +21 -1
- package/docs/design/task-board.md +30 -2
- package/docs/dogfood.md +13 -4
- package/docs/events.md +5 -1
- package/docs/influences.md +7 -0
- package/docs/memory.md +4 -4
- package/docs/operations.md +51 -18
- package/docs/quickstart.md +8 -2
- 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 +3 -3
- 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-codex-0171-reviewer-isolation.md +47 -0
- package/docs/verified.json +32 -26
- package/package.json +2 -2
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +472 -229
- package/plugins/agent-hub/kimi-review-policy-worker.js +5 -5
- package/plugins/agent-hub/server.js +513 -258
- package/scripts/check-docs.mjs +9 -1
- package/src/adapters/acp.ts +11 -1
- package/src/adapters/compat.ts +3 -3
- package/src/adapters/definitions/builtin-metadata.ts +2 -2
- 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/console-state.ts +3 -1
- package/src/cli/help.ts +3 -1
- package/src/cli/identity.ts +2 -1
- package/src/cli/main.ts +11 -5
- package/src/cli/recovery-package.ts +16 -3
- package/src/cli/roadmap-write.ts +59 -0
- package/src/cli/roadmap.ts +81 -4
- package/src/cli/sdlc-output.ts +4 -0
- package/src/cli/upgrade-runtime.ts +10 -6
- package/src/hub/agent-mem-range.ts +43 -0
- package/src/hub/board.ts +102 -1
- package/src/hub/check-runner.ts +25 -1
- package/src/hub/config-apply.ts +4 -2
- package/src/hub/config-trust.ts +1 -1
- package/src/hub/context-window.ts +1 -1
- package/src/hub/cost-governance.ts +11 -7
- package/src/hub/daemon.ts +253 -30
- package/src/hub/dogfood-read.ts +4 -2
- package/src/hub/edit-guard.ts +100 -0
- package/src/hub/events.ts +79 -8
- package/src/hub/facts.ts +57 -4
- package/src/hub/hub-tools.ts +2 -0
- package/src/hub/lifecycle.ts +6 -1
- package/src/hub/log-rotation.ts +130 -0
- 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/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 +80 -0
- package/src/hub/roadmap-export.ts +27 -0
- package/src/hub/roadmap-sync.ts +97 -0
- package/src/hub/roadmap.ts +40 -0
- 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 +1 -0
- 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 +502 -34
- package/src/hub/usage-rollup.ts +35 -20
- 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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SdlcGh } from "./sdlc.ts";
|
|
2
|
+
import { GITHUB_PAGE_SIZE, GITHUB_READ_DEADLINE_MS } from "./github-import.ts";
|
|
3
|
+
|
|
4
|
+
/** Create or recover one PR for a previously pushed, host-verified managed branch. */
|
|
5
|
+
export async function managedTaskPullRequest(input: { repo: string; branch: string; commit: string; task: number; title?: string; issue?: number; current: () => void }, run: SdlcGh): Promise<number> {
|
|
6
|
+
const { repo, branch, commit, task, title, issue, current } = input;
|
|
7
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9_.-]{1,100}$/.test(repo) || !Number.isSafeInteger(task) || task < 1 || !/^task\/[1-9][0-9]*-[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/.test(branch) || !branch.startsWith(`task/${task}-`) || !/^[a-f0-9]{40}$/.test(commit) || issue !== undefined && (!Number.isSafeInteger(issue) || issue < 1)) throw new Error("managed PR identity is invalid; inspect the task and retry");
|
|
8
|
+
const target = `github.com/${repo}`;
|
|
9
|
+
const deadline = performance.now() + GITHUB_READ_DEADLINE_MS;
|
|
10
|
+
const call: SdlcGh = async (args, timeout, cwd, cap) => {
|
|
11
|
+
current(); const remaining = deadline - performance.now();
|
|
12
|
+
if (remaining <= 0) throw new Error("managed PR operation timed out; inspect GitHub before retrying hub_task_done");
|
|
13
|
+
const result = await run(args, Math.min(timeout ?? remaining, remaining), cwd, cap); current();
|
|
14
|
+
if (performance.now() > deadline) throw new Error("managed PR operation timed out; inspect GitHub before retrying hub_task_done");
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
const lookup = async (): Promise<{ number: number; draft: boolean } | undefined> => {
|
|
18
|
+
const reply = await call(["pr", "list", "--repo", target, "--state", "open", "--head", branch, "--limit", String(GITHUB_PAGE_SIZE), "--json", "number,headRefName,headRefOid,headRepository,isCrossRepository,isDraft,state"], 10_000, undefined, 256 * 1024);
|
|
19
|
+
if (reply.code !== 0) throw new Error("managed PR lookup unavailable; inspect GitHub and retry hub_task_done");
|
|
20
|
+
let rows: unknown; try { rows = JSON.parse(reply.stdout); } catch { throw new Error("managed PR lookup malformed; inspect GitHub and retry hub_task_done"); }
|
|
21
|
+
if (!Array.isArray(rows) || rows.length >= GITHUB_PAGE_SIZE) throw new Error("managed PR lookup incomplete; inspect GitHub and retry hub_task_done");
|
|
22
|
+
if (!rows.length) return undefined;
|
|
23
|
+
if (rows.length !== 1) throw new Error("managed branch has multiple open PRs; inspect GitHub before retrying");
|
|
24
|
+
const row = rows[0];
|
|
25
|
+
const name = (value: unknown) => value && typeof value === "object" && typeof (value as { nameWithOwner?: unknown }).nameWithOwner === "string" ? (value as { nameWithOwner: string }).nameWithOwner.toLowerCase() : undefined;
|
|
26
|
+
if (!Number.isSafeInteger(row?.number) || row.number < 1 || row.state !== "OPEN" || row.headRefName !== branch || row.headRefOid !== commit || typeof row.isDraft !== "boolean" || row.isCrossRepository !== false || name(row.headRepository) !== repo.toLowerCase()) throw new Error("managed PR identity or head is unavailable; inspect GitHub before retrying");
|
|
27
|
+
return { number: row.number, draft: row.isDraft };
|
|
28
|
+
};
|
|
29
|
+
let found = await lookup();
|
|
30
|
+
if (!found) {
|
|
31
|
+
const meta = await call(["api", `repos/${repo}`, "--hostname", "github.com", "--jq", ".default_branch"], 10_000, undefined, 4096);
|
|
32
|
+
const base = meta.stdout.trim();
|
|
33
|
+
if (meta.code !== 0 || !/^[A-Za-z0-9][A-Za-z0-9._/-]{0,199}$/.test(base) || base.includes("..") || base.endsWith("/")) throw new Error("managed PR base branch unavailable; inspect GitHub before retrying");
|
|
34
|
+
const body = [`hub task ${task}`, ...(issue === undefined ? [] : [`Refs #${issue}`])].join("\n\n");
|
|
35
|
+
const created = await call(["pr", "create", "--repo", target, "--head", branch, "--base", base, "--title", title || `hub task ${task}`, "--body", body, "--draft"], 10_000, undefined, 4096);
|
|
36
|
+
if (created.code !== 0) throw new Error("managed PR creation was not confirmed; inspect GitHub before retrying hub_task_done");
|
|
37
|
+
found = await lookup();
|
|
38
|
+
if (!found) throw new Error("managed PR creation was not found; inspect GitHub before retrying hub_task_done");
|
|
39
|
+
}
|
|
40
|
+
if (found.draft) {
|
|
41
|
+
const ready = await call(["pr", "ready", String(found.number), "--repo", target], 10_000, undefined, 4096);
|
|
42
|
+
if (ready.code !== 0) throw new Error("managed PR readiness was not confirmed; inspect GitHub before retrying hub_task_done");
|
|
43
|
+
const verified = await lookup();
|
|
44
|
+
if (!verified || verified.number !== found.number || verified.draft) throw new Error("managed PR readiness or head changed; inspect GitHub before retrying hub_task_done");
|
|
45
|
+
}
|
|
46
|
+
return found.number;
|
|
47
|
+
}
|
package/src/hub/task-worktree.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { DependencyPreparation } from "../pi/task-dependencies.ts";
|
|
|
13
13
|
/**
|
|
14
14
|
* #1115: a hub-sandboxed peer (Pi, the local worker) cannot run `git worktree add` or commit, because its profile refuses `.git` writes that
|
|
15
15
|
* matter (#270). The hub makes the task worktree for it at the fixed root `.worktrees/<peer>-<task>`, the peer edits files there, and the hub
|
|
16
|
-
* stages, commits and pushes at `hub_task_done
|
|
16
|
+
* stages, commits and pushes at `hub_task_done` or before an isolated check. The sandbox profile is NOT changed. It already lets a sandboxed command write
|
|
17
17
|
* `.git/worktrees/<name>/{HEAD,index}` and `.git/refs/heads` (#864 only closes config, hooks, commondir and packs), so this module never trusts
|
|
18
18
|
* what the peer could have written there: the base commit is recorded at creation, and a hub commit needs the worktree still registered at
|
|
19
19
|
* its path, HEAD still the task branch, and the branch tip still the recorded base (or the hub's own previous commit).
|
|
@@ -31,7 +31,7 @@ export const taskWorktreeBranch = (peer: PeerId, task: number): string => `task/
|
|
|
31
31
|
export interface TaskWorktreeEntry { peer: string; task: number; path: string; branch: string; base: string; /** The hub's own last commit on the branch, once it made one. */ head?: string }
|
|
32
32
|
export type TaskWorktreeAvailability = { ok: true } | { ok: false; reason: string; next: string };
|
|
33
33
|
export type TaskWorktreeResult = { ok: true; path: string; branch: string; base: string; created: boolean } | { ok: false; reason: string };
|
|
34
|
-
export type TaskWorktreeCommit = { ok: true; commit: string; branch: string; pushed: boolean; note?: string } | { ok: false; reason: string; commit?: string };
|
|
34
|
+
export type TaskWorktreeCommit = { ok: true; commit: string; branch: string; pushed: boolean; note?: string } | { ok: false; reason: string; commit?: string; uncertain?: true };
|
|
35
35
|
export interface TaskWorktreeRemoval { removed: boolean; branchDeleted: boolean; kept?: string }
|
|
36
36
|
|
|
37
37
|
export interface TaskWorktreePort {
|
|
@@ -43,7 +43,7 @@ export interface TaskWorktreePort {
|
|
|
43
43
|
prepareDependencies?(input: { peer: PeerId; task: number; current: () => boolean }): Promise<void>;
|
|
44
44
|
preparesDependencies?(peer: PeerId): boolean;
|
|
45
45
|
dependencyState?(peer: PeerId, task: number): DependencyPreparation | undefined;
|
|
46
|
-
commitAndPush(input: { peer: PeerId; task: number; title: string }): Promise<TaskWorktreeCommit>;
|
|
46
|
+
commitAndPush(input: { peer: PeerId; task: number; title: string; current?: () => boolean }): Promise<TaskWorktreeCommit>;
|
|
47
47
|
remove(input: { peer: PeerId; task: number }): TaskWorktreeRemoval;
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -255,16 +255,19 @@ export class TaskWorktrees implements TaskWorktreePort {
|
|
|
255
255
|
return { ok: true, path, branch, base, created: true };
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
/** One hub commit at a time per worktree: a repeated or parallel `hub_task_done` queues behind the first. */
|
|
259
|
-
commitAndPush(input: { peer: PeerId; task: number; title: string }): Promise<TaskWorktreeCommit> {
|
|
258
|
+
/** One hub commit at a time per worktree: a repeated or parallel check or `hub_task_done` queues behind the first. */
|
|
259
|
+
commitAndPush(input: { peer: PeerId; task: number; title: string; current?: () => boolean }): Promise<TaskWorktreeCommit> {
|
|
260
260
|
const next = this.chain.then(() => this.commit(input), () => this.commit(input));
|
|
261
261
|
this.chain = next.catch(() => undefined);
|
|
262
262
|
return next;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
private async commit(input: { peer: PeerId; task: number; title: string }): Promise<TaskWorktreeCommit> {
|
|
265
|
+
private async commit(input: { peer: PeerId; task: number; title: string; current?: () => boolean }): Promise<TaskWorktreeCommit> {
|
|
266
266
|
const { peer, task } = input;
|
|
267
|
-
const
|
|
267
|
+
const current = () => !input.current || input.current();
|
|
268
|
+
let uncertain = false;
|
|
269
|
+
const fail = (reason: string, commit?: string): TaskWorktreeCommit => ({ ok: false, reason, ...(commit ? { commit } : {}), ...(uncertain ? { uncertain: true as const } : {}) });
|
|
270
|
+
if (!current()) return fail("task authority changed before the worktree commit");
|
|
268
271
|
let records: Record<string, TaskWorktreeEntry>;
|
|
269
272
|
try { records = this.readRecords(); } catch (error) { return fail((error as Error).message); }
|
|
270
273
|
const entry = records[this.key(peer, task)];
|
|
@@ -296,8 +299,9 @@ export class TaskWorktrees implements TaskWorktreePort {
|
|
|
296
299
|
if (raw.status !== 0) return fail("the staged change could not be listed");
|
|
297
300
|
const parts = raw.stdout.split("\0").filter(Boolean), changed: { mode: string; path: string }[] = [];
|
|
298
301
|
for (let i = 0; i + 1 < parts.length; i += 2) { const meta = /^:(\d{6}) (\d{6}) /.exec(parts[i]!); if (!meta) return fail("the staged change has an unreadable entry"); changed.push({ mode: meta[2]!, path: parts[i + 1]! }); }
|
|
302
|
+
if (!current()) return fail("task authority changed before the worktree commit");
|
|
299
303
|
// Nothing new since the hub's own commit: this is a retry after a failed push, so push the commit it already made.
|
|
300
|
-
if (!changed.length && entry.head) return this.push(path, branch, entry.head, peer);
|
|
304
|
+
if (!changed.length && entry.head) return this.push(path, branch, entry.head, peer, current);
|
|
301
305
|
if (!changed.length) return fail(`no changes under ${path}: edit files there, then call hub_task_done again`);
|
|
302
306
|
if (changed.length > MAX_PATHS) return fail(`${changed.length} paths changed, more than the ${MAX_PATHS} the hub commits for a sandboxed peer; split the work into smaller tasks`);
|
|
303
307
|
// 3. The same path policy a person's grant uses: the denylist, the agent and hub write names, and (when the policy is on) the instruction files.
|
|
@@ -305,8 +309,10 @@ export class TaskWorktrees implements TaskWorktreePort {
|
|
|
305
309
|
const refused = changed.filter(c => c.mode === "160000" || isDenied(c.path, deny) || !grantablePath(path, join(path, c.path), c.path, protect));
|
|
306
310
|
if (refused.length) return fail(`the hub will not commit ${refused.length} changed path${refused.length === 1 ? "" : "s"} (${refused.slice(0, 3).map(c => shown(c.path, 60)).join(", ")}): a secret, a git or hub or agent configuration name, a protected instruction file or a submodule. Revert ${refused.length === 1 ? "it" : "them"} in the worktree and call hub_task_done again`);
|
|
307
311
|
this.o.beforeCommit?.();
|
|
312
|
+
if (!current()) return fail("task authority changed before the worktree commit");
|
|
308
313
|
// 4. The commit object is made from the validated tree by the hub (no hook, no signing, no index read), and the branch moves to it only if it still sits at the recorded tip.
|
|
309
314
|
const title = shown(input.title, 200) || `task ${task}`;
|
|
315
|
+
uncertain = true; // Git may have written an object or moved the branch even if a later step fails.
|
|
310
316
|
const made = this.git(["-c", `user.name=${peer}`, "-c", `user.email=${peer}@agent-hub.invalid`, "-c", "commit.gpgSign=false", "commit-tree", tree, "-p", expectedTip, "-m", title, "-m", `Task #${task} by ${peer}. Committed by the hub for a sandboxed peer.`], path), commit = made.stdout.trim();
|
|
311
317
|
if (made.status !== 0 || !SHA.test(commit)) return fail(`git commit-tree failed: ${shown(made.stderr)}`);
|
|
312
318
|
if (this.git(["update-ref", `refs/heads/${branch}`, commit, expectedTip], path).status !== 0) return fail(`${branch} moved while the hub was committing; nothing was kept. Decline the task so the hub clears it`);
|
|
@@ -315,13 +321,14 @@ export class TaskWorktrees implements TaskWorktreePort {
|
|
|
315
321
|
// there is clean and `remove` can tell finished work from uncommitted work. Nothing is ever committed from it.
|
|
316
322
|
this.git(["read-tree", commit], path); this.git(["update-index", "-q", "--refresh"], path);
|
|
317
323
|
try { this.mutate(current => { current[this.key(peer, task)] = { ...(current[this.key(peer, task)] ?? entry), head: commit }; }); } catch { return fail("the commit was made but the hub could not record it; call hub_task_done again", commit); }
|
|
318
|
-
return this.push(path, branch, commit, peer);
|
|
324
|
+
return this.push(path, branch, commit, peer, current);
|
|
319
325
|
} finally { rmSync(index, { force: true }); }
|
|
320
326
|
}
|
|
321
327
|
|
|
322
328
|
/** 5. One explicit refspec for this branch, only to an origin that is this project's repository. */
|
|
323
|
-
private async push(path: string, branch: string, commit: string, _peer: PeerId): Promise<TaskWorktreeCommit> {
|
|
324
|
-
const fail = (reason: string, sha?: string): TaskWorktreeCommit => ({ ok: false, reason, ...(sha ? { commit: sha } : {}) });
|
|
329
|
+
private async push(path: string, branch: string, commit: string, _peer: PeerId, current: () => boolean): Promise<TaskWorktreeCommit> {
|
|
330
|
+
const fail = (reason: string, sha?: string): TaskWorktreeCommit => ({ ok: false, reason, ...(sha ? { commit: sha } : {}), uncertain: true });
|
|
331
|
+
if (!current()) return fail("task authority changed after the worktree commit; the commit was kept", commit);
|
|
325
332
|
if (this.tip(branch) !== commit) return fail(`${branch} no longer points at the hub's commit ${commit.slice(0, 12)}; the hub will not push it. Decline the task so the hub clears it`);
|
|
326
333
|
const urls = [...this.git(["remote", "get-url", "--push", "--all", "origin"], path).stdout.trim().split("\n"), ...this.git(["remote", "get-url", "--all", "origin"], path).stdout.trim().split("\n")].filter(Boolean);
|
|
327
334
|
const verdict = this.o.pushAllowed?.(urls);
|