@staix/agent-hub 0.38.0 → 0.40.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 +84 -0
- package/README.md +28 -12
- package/docs/adding-an-ai-tool.md +7 -5
- package/docs/agent-notes/README.md +23 -0
- package/docs/agent-notes/adapters.md +9 -5
- package/docs/agent-notes/benchmarks.md +2 -0
- package/docs/agent-notes/budget.md +9 -0
- package/docs/agent-notes/bus.md +1 -0
- package/docs/agent-notes/daemon.md +21 -9
- package/docs/agent-notes/local-worker.md +4 -2
- package/docs/agent-notes/security-review.md +56 -0
- package/docs/agent-notes/tasks.md +22 -6
- package/docs/agent-notes/tests.md +10 -9
- package/docs/contracts/companion-cli-v1.json +4 -0
- package/docs/design/adapters.md +142 -0
- package/docs/design/agent-hub-architecture.md +46 -1
- package/docs/design/agent-hub.md +10 -0
- package/docs/design/bus.md +7 -0
- package/docs/design/cli-output.md +183 -0
- package/docs/design/execution-reference.md +6 -1
- package/docs/design/roadmap.md +191 -0
- package/docs/design/task-board.md +185 -5
- package/docs/dogfood.md +30 -9
- package/docs/events.md +7 -7
- package/docs/memory.md +5 -5
- package/docs/operations.md +315 -54
- package/docs/profiles.md +101 -8
- package/docs/quickstart.md +47 -6
- package/docs/research.md +6 -3
- package/docs/roles.md +52 -0
- package/docs/sdlc.md +190 -2
- package/docs/security.md +90 -15
- package/docs/text-projection.md +1 -0
- package/docs/verification/2026-11-13-claude-implementer-2.1.323.md +59 -0
- package/docs/verification/2026-11-13-codex-01672-reviewer-isolation.md +69 -0
- package/docs/verification/2026-11-14-0.39.0.md +51 -0
- package/docs/verification/2026-11-14-codex-0169-reviewer-isolation.md +70 -0
- package/docs/verification/2026-11-14-codex-0169-reviewer-tool-call.md +48 -0
- package/docs/verification/2026-11-14-pi-152-compat.md +45 -0
- package/docs/verification/2026-11-15-0.40.0.md +39 -0
- package/docs/verification/2026-11-16-pi-loopback-1447.md +39 -0
- package/docs/verification/pi-152-model-free.ts +57 -0
- package/docs/verification/pi-152-native.mjs +21 -0
- package/docs/verified.json +48 -25
- package/package.json +4 -4
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +2266 -530
- package/plugins/agent-hub/kimi-review-policy-worker.js +16 -11
- package/plugins/agent-hub/server.js +2423 -645
- package/src/adapters/acp-model-policy.ts +1 -1
- package/src/adapters/acp-session-model.ts +35 -0
- package/src/adapters/acp.ts +14 -0
- package/src/adapters/agy/definition.ts +2 -2
- package/src/adapters/agy/hooks.ts +7 -0
- package/src/adapters/claude-channel.ts +1 -1
- package/src/adapters/claude-implementer.ts +8 -0
- package/src/adapters/claude-print-child.ts +26 -2
- package/src/adapters/claude-print.ts +4 -0
- package/src/adapters/codex-appserver.ts +90 -16
- package/src/adapters/codex-review-isolation.ts +63 -17
- package/src/adapters/compat.ts +10 -10
- package/src/adapters/conformance/fakes/acp-server.ts +11 -2
- package/src/adapters/conformance/fakes/app-server.ts +5 -1
- package/src/adapters/conformance/fakes/pi-rpc.ts +1 -1
- package/src/adapters/definitions/builtin-metadata.ts +12 -12
- package/src/adapters/definitions/native-cli-jcode-mcp.ts +18 -3
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/definitions/native-config-policy.ts +1 -1
- package/src/adapters/definitions/native-quota.ts +122 -0
- package/src/adapters/definitions/native-recovery.ts +3 -0
- package/src/adapters/definitions/qwen.ts +2 -2
- package/src/adapters/kimi-review.ts +23 -0
- package/src/adapters/kimi-wire-usage.ts +39 -16
- package/src/adapters/local-worker.ts +9 -4
- package/src/adapters/pi-state-model.ts +12 -0
- package/src/adapters/pi.ts +76 -11
- package/src/adapters/print-result-model.ts +24 -0
- package/src/adapters/registry-types.ts +12 -2
- package/src/adapters/registry.ts +19 -2
- package/src/adapters/reviewer-print.ts +132 -16
- package/src/adapters/role-eligibility.ts +99 -0
- package/src/adapters/same-directory.ts +16 -0
- package/src/cli/agy-mcp.ts +18 -7
- package/src/cli/answer-args.ts +11 -3
- package/src/cli/console-question.ts +1 -1
- package/src/cli/console-state.ts +98 -11
- package/src/cli/console.ts +6 -2
- package/src/cli/error-format.ts +19 -0
- package/src/cli/free-text.ts +20 -0
- package/src/cli/handoff-args.ts +1 -1
- package/src/cli/help.ts +350 -30
- package/src/cli/identity-audit.ts +8 -7
- package/src/cli/identity.ts +27 -4
- package/src/cli/init-prompt.ts +31 -2
- package/src/cli/init-roles.ts +156 -0
- package/src/cli/init-settings.ts +24 -2
- package/src/cli/init.ts +232 -17
- package/src/cli/main.js +2 -2
- package/src/cli/main.ts +250 -69
- package/src/cli/model.ts +1 -1
- package/src/cli/output-standard.ts +56 -0
- package/src/cli/output.ts +199 -9
- package/src/cli/preview.ts +1 -1
- package/src/cli/recovery-launch.ts +114 -0
- package/src/cli/recovery-package.ts +14 -7
- package/src/cli/recovery-version-preflight.ts +104 -0
- package/src/cli/roadmap.ts +215 -0
- package/src/cli/role-doctor.ts +39 -0
- package/src/cli/sdlc-output.ts +66 -1
- package/src/cli/smoke-pty-bridge.ts +7 -24
- package/src/cli/study-output.ts +54 -0
- package/src/cli/study.ts +14 -1
- package/src/cli/task-output.ts +3 -1
- package/src/cli/terminal-recovery.ts +14 -0
- package/src/cli/upgrade-presentation-flags.ts +2 -2
- package/src/cli/upgrade-presentation.ts +4 -0
- package/src/cli/upgrade-restore-state.ts +12 -3
- package/src/cli/upgrade-runtime.ts +40 -2
- package/src/cli/upgrade.ts +8 -4
- package/src/hub/advisor-survey.ts +139 -0
- package/src/hub/audit-source.ts +66 -0
- package/src/hub/board.ts +677 -15
- package/src/hub/budget.ts +54 -4
- package/src/hub/bus.ts +9 -0
- package/src/hub/check-runner.ts +3 -4
- package/src/hub/ci-watch.ts +19 -4
- package/src/hub/conductor.ts +14 -8
- package/src/hub/config-apply.ts +2 -1
- package/src/hub/config-edit-host.ts +77 -5
- package/src/hub/considered-findings.ts +47 -0
- package/src/hub/control-client.ts +1 -1
- package/src/hub/daemon.ts +585 -98
- package/src/hub/deliverable-files.ts +17 -1
- package/src/hub/dogfood-profile.ts +3 -2
- package/src/hub/events.ts +25 -4
- package/src/hub/execution-reference.ts +1 -1
- package/src/hub/folder-trigger.ts +11 -4
- package/src/hub/github-import.ts +81 -0
- package/src/hub/hub-tools.ts +117 -20
- package/src/hub/install-policy.ts +23 -0
- package/src/hub/kimi-usage.ts +34 -2
- package/src/hub/lifecycle-schema.ts +3 -3
- package/src/hub/memory-profile.ts +9 -1
- package/src/hub/memory-sync-state.ts +1 -0
- package/src/hub/model-overrides.ts +2 -1
- package/src/hub/no-writes.ts +5 -0
- package/src/hub/operational-authority.ts +8 -1
- package/src/hub/operational-view.ts +6 -2
- package/src/hub/peers.ts +2 -0
- package/src/hub/pi-failure.ts +7 -0
- package/src/hub/plan-conformance.ts +20 -2
- package/src/hub/question-desk.ts +26 -7
- package/src/hub/questions.ts +33 -5
- package/src/hub/quota-account.ts +34 -0
- package/src/hub/recovery-policy.ts +18 -4
- package/src/hub/research-evidence.ts +51 -3
- package/src/hub/research.ts +77 -13
- package/src/hub/restart.ts +21 -0
- package/src/hub/review-budget.ts +88 -0
- package/src/hub/review-findings.ts +93 -12
- package/src/hub/reviewer-pool-config.ts +6 -2
- package/src/hub/reviewer-pool.ts +39 -6
- package/src/hub/roadmap-triage.ts +86 -0
- package/src/hub/roadmap-unplaced.ts +169 -0
- package/src/hub/roadmap-view.ts +83 -0
- package/src/hub/roadmap.ts +127 -0
- package/src/hub/routing.ts +7 -3
- package/src/hub/sdlc-merge.ts +6 -5
- package/src/hub/sdlc-queue.ts +17 -7
- package/src/hub/sdlc-release.ts +1 -1
- package/src/hub/sdlc.ts +47 -8
- package/src/hub/security-audit.ts +178 -0
- package/src/hub/security-pass.ts +115 -0
- package/src/hub/settings.ts +11 -5
- package/src/hub/source-read.ts +80 -2
- package/src/hub/sources.ts +57 -9
- package/src/hub/specs-task.ts +7 -0
- package/src/hub/startup-event-seeds.ts +5 -3
- package/src/hub/startup-timing.ts +1 -0
- package/src/hub/synthesis-readiness.ts +279 -0
- package/src/hub/task-sweep.ts +29 -2
- package/src/hub/task-worktree.ts +37 -0
- package/src/hub/tasks.ts +1464 -76
- package/src/hub/text-projection.ts +11 -1
- package/src/memory/capture.ts +2 -1
- package/src/pi/dependency-publish.ts +50 -0
- package/src/pi/extension.ts +1 -1
- package/src/pi/launch.ts +1 -1
- package/src/pi/task-dependencies.ts +249 -0
- package/src/ui/index.html +56 -13
- package/src/ui/office-model.ts +11 -3
- package/src/ui/office-space.ts +50 -30
- package/src/ui/plugin-questions.ts +5 -0
- package/src/ui/plugin.ts +27 -12
- package/templates/config.json +1 -1
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { cliCommandLabel } from "./identity.ts";
|
|
4
4
|
|
|
5
5
|
export interface CliAudit {
|
|
6
|
-
v: 1; id: string; at: number; peer: string; command: string; outcome: "run" | "refused" | "invalid" | "delegated";
|
|
6
|
+
v: 1; id: string; at: number; peer: string; command: string; outcome: "run" | "refused" | "invalid" | "delegated"; instructed?: true;
|
|
7
7
|
}
|
|
8
8
|
const MAX_FILES = 256;
|
|
9
9
|
const MAX_BYTES = 64 * 1024;
|
|
@@ -14,7 +14,8 @@ const valid = (row: any): row is CliAudit => row?.v === 1 && typeof row.id === "
|
|
|
14
14
|
&& typeof row.at === "number" && Number.isFinite(row.at) && row.at > 0
|
|
15
15
|
&& typeof row.peer === "string" && /^[a-z][a-z0-9-]{0,31}$/.test(row.peer) && !/\s/.test(row.peer)
|
|
16
16
|
&& typeof row.command === "string" && row.command.length <= 64 && row.command === cliCommandLabel(...splitLabel(row.command))
|
|
17
|
-
&& ["run", "refused", "invalid", "delegated"].includes(row.outcome)
|
|
17
|
+
&& ["run", "refused", "invalid", "delegated"].includes(row.outcome)
|
|
18
|
+
&& (row.instructed === undefined || row.instructed === true && row.command === "answer");
|
|
18
19
|
const splitLabel = (label: string): [string, string[]] => { const [command = "unknown", ...args] = label.split(" "); return [command, args]; };
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -22,8 +23,8 @@ const splitLabel = (label: string): [string, string[]] => { const [command = "un
|
|
|
22
23
|
* the checked 256-file / 64 KiB ceiling by at most one bounded row per concurrent writer.
|
|
23
24
|
* Unpublished temp files count against the ceiling, so a crashed writer cannot grow the spool forever.
|
|
24
25
|
*/
|
|
25
|
-
function reserveCliAudit(stateDir: string, peer: string, command: string, outcome: CliAudit["outcome"]) {
|
|
26
|
-
const row: CliAudit = { v: 1, id: crypto.randomUUID(), at: Date.now(), peer, command, outcome };
|
|
26
|
+
function reserveCliAudit(stateDir: string, peer: string, command: string, outcome: CliAudit["outcome"], instructed = false) {
|
|
27
|
+
const row: CliAudit = { v: 1, id: crypto.randomUUID(), at: Date.now(), peer, command, outcome, ...(instructed ? { instructed: true } : {}) };
|
|
27
28
|
if (!valid(row)) throw new Error("invalid CLI audit identifiers");
|
|
28
29
|
const dir = join(stateDir, "cli-audit");
|
|
29
30
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
@@ -49,8 +50,8 @@ function reserveCliAudit(stateDir: string, peer: string, command: string, outcom
|
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
export function recordCliAudit(stateDir: string, peer: string, command: string, outcome: CliAudit["outcome"]): void {
|
|
53
|
-
const pending = reserveCliAudit(stateDir, peer, command, outcome);
|
|
53
|
+
export function recordCliAudit(stateDir: string, peer: string, command: string, outcome: CliAudit["outcome"], instructed = false): void {
|
|
54
|
+
const pending = reserveCliAudit(stateDir, peer, command, outcome, instructed);
|
|
54
55
|
try { pending.commit(outcome); }
|
|
55
56
|
finally { pending.close(); }
|
|
56
57
|
}
|
|
@@ -83,7 +84,7 @@ export function drainCliAudits(stateDir: string): CliAudit[] {
|
|
|
83
84
|
try {
|
|
84
85
|
if (statSync(path).size <= MAX_ROW_BYTES) {
|
|
85
86
|
const parsed: unknown = JSON.parse(readFileSync(path, "utf8"));
|
|
86
|
-
if (valid(parsed) && `${parsed.id}.json` === name) rows.push({ v: 1, id: parsed.id, at: parsed.at, peer: parsed.peer, command: parsed.command, outcome: parsed.outcome });
|
|
87
|
+
if (valid(parsed) && `${parsed.id}.json` === name) rows.push({ v: 1, id: parsed.id, at: parsed.at, peer: parsed.peer, command: parsed.command, outcome: parsed.outcome, ...(parsed.instructed ? { instructed: true } : {}) });
|
|
87
88
|
}
|
|
88
89
|
} catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT" && !(error instanceof SyntaxError)) throw error; }
|
|
89
90
|
try { unlinkSync(path); } catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
package/src/cli/identity.ts
CHANGED
|
@@ -15,8 +15,14 @@ export const LIVE_TEST_PERSON_REFUSAL = "live-test cannot write person-attribute
|
|
|
15
15
|
|
|
16
16
|
/** Person verdicts and user-authored workflow content are never delegated. */
|
|
17
17
|
export function liveTestRefusal(command: string, args: readonly string[], context: { repairedFresh?: boolean } = {}): boolean {
|
|
18
|
+
if (command === "roadmap" && ![undefined, "list", "show", "--json"].includes(args[0])) return true;
|
|
19
|
+
if (command === "roadmap" && args[0] === "--json" && ![undefined, "list", "show"].includes(args[1])) return true;
|
|
20
|
+
if (command === "sdlc" && args[0] === "configure") return true;
|
|
18
21
|
if (command === "lineage" && args[0] === "link") return true;
|
|
19
22
|
if (command === "guidance" && ["create", "withdraw"].includes(args[0] ?? "")) return true;
|
|
23
|
+
if (command === "sdlc" && args[0] === "survey" && args[1] !== "show") return true;
|
|
24
|
+
// #1403 A4: starting a security audit files a task; only `show` stays a live-test read.
|
|
25
|
+
if (command === "sdlc" && args[0] === "audit" && args[1] !== "show") return true;
|
|
20
26
|
if (command === "model") return true; // #1317: even listing runtime overrides is person-only, never live-test delegated.
|
|
21
27
|
if (command === "sdlc" && (args[0] === "authorize-release" || args[0] === "plan-review" || args[0] === "release-assign" || args[0] === "merge" || args[0] === "train" && args[1] !== "report")) return true;
|
|
22
28
|
if (args.some(arg => arg === "--as-user" || arg.startsWith("--as-user="))) return true;
|
|
@@ -97,12 +103,14 @@ const peerReadForms: Readonly<Record<string, Readonly<Record<string, PeerReadFor
|
|
|
97
103
|
room: { list: { displayFlags: ["--json"] }, status: { positional: 1, displayFlags: ["--json"] } },
|
|
98
104
|
queue: { list: { valueFlags: ["--peer"], displayFlags: [...publicReadDisplayFlags, "--all"] } },
|
|
99
105
|
roster: { "": { displayFlags: publicReadDisplayFlags } },
|
|
106
|
+
// #1411 T2: who holds which flow role, read from the running hub; nothing else takes this command.
|
|
107
|
+
roles: { "": { displayFlags: sdlcReadDisplayFlags } },
|
|
100
108
|
settings: { "": { displayFlags: ["--json"] }, list: { displayFlags: ["--json"] }, get: { positional: 1, minimum: 1, displayFlags: ["--json"] } },
|
|
101
109
|
// #814 renders these reads for people and keeps JSON as an explicit data format.
|
|
102
110
|
sdlc: { status: { positional: 1, displayFlags: sdlcReadDisplayFlags }, explain: { positional: 1, displayFlags: sdlcReadDisplayFlags }, queue: { positional: 1, minimum: 1, displayFlags: sdlcReadDisplayFlags }, release: { positional: 33, minimum: 1, displayFlags: sdlcReadDisplayFlags } },
|
|
103
111
|
release: { show: { positional: 1, minimum: 1, displayFlags: [] } },
|
|
104
112
|
// #601: reading a campaign is harmless for any agent (the hub stubs a private one); draft, revise, approve and close fall to `console`.
|
|
105
|
-
study: { show: { positional: 1, valueFlags: ["--after"], displayFlags: sdlcReadDisplayFlags }, experiments: { valueFlags: ["--campaign", "--attempt", "--after", "--events-after", "--plan", "--baseline", "--variant"], displayFlags: sdlcReadDisplayFlags } },
|
|
113
|
+
study: { evidence: { positional: 1, minimum: 1, valueFlags: ["--revision"], displayFlags: sdlcReadDisplayFlags }, show: { positional: 1, valueFlags: ["--after"], displayFlags: sdlcReadDisplayFlags }, experiments: { valueFlags: ["--campaign", "--attempt", "--after", "--events-after", "--plan", "--baseline", "--variant"], displayFlags: sdlcReadDisplayFlags } },
|
|
106
114
|
projects: { "": {} },
|
|
107
115
|
models: { status: {} },
|
|
108
116
|
recovery: { status: { positional: 1 } },
|
|
@@ -152,12 +160,20 @@ export function classifyPeerCommand(command: string, args: readonly string[], ca
|
|
|
152
160
|
if (native?.cli.personOnlyFlags?.some(flag => args.includes(flag))) return "console";
|
|
153
161
|
if (command === "permission" || command === "watch") return "console";
|
|
154
162
|
if (args.some((arg) => arg === "--as-user" || arg.startsWith("--as-user="))) return "console";
|
|
163
|
+
if (command === "roadmap") {
|
|
164
|
+
const sub = args[0] === "--json" ? args[1] : args[0];
|
|
165
|
+
if (sub === "state" && ["done", "dropped"].includes(args[2] ?? "")) return "console";
|
|
166
|
+
// R3 (#1481): importing GitHub milestones is the person's alone, a dry run included; triage, accept and reject are the planner's own tools.
|
|
167
|
+
if (sub === "import-github") return "console";
|
|
168
|
+
return "allowed";
|
|
169
|
+
}
|
|
170
|
+
if (command === "answer" && args.includes("--instructed")) return "conductor";
|
|
155
171
|
if (command === "pet" && (args.includes("--window") || args.includes("--palette"))) return "allowed";
|
|
156
172
|
if (conductorOperation(command,args)) return "conductor";
|
|
157
173
|
if (command === "stop") return "console";
|
|
158
174
|
if (command === "sdlc" && ["release-guard", "release-guard-hook"].includes(args[0] ?? "")) return "allowed";
|
|
159
175
|
// #786, #1063, #1328: guarded merge, merge adoption and explicitly instructed release consent admit the person or unique configured conductor; the daemon checks the role.
|
|
160
|
-
if (command === "sdlc" && ["merge", "authorize-release", "adopt-merge"].includes(args[0] ?? "")) return "conductor";
|
|
176
|
+
if (command === "sdlc" && ["merge", "authorize-release", "adopt-merge", "configure"].includes(args[0] ?? "")) return "conductor";
|
|
161
177
|
if (command === "role") return ["list", "show"].includes(args[0] ?? "") ? "allowed" : "console";
|
|
162
178
|
// The original tools identity reaches Tasks for read visibility or task-scoped link admission.
|
|
163
179
|
if (command === "lineage") return ["show", "link"].includes(args[0] ?? "") ? "allowed" : "console";
|
|
@@ -201,6 +217,13 @@ export function classifyPeerCommand(command: string, args: readonly string[], ca
|
|
|
201
217
|
|
|
202
218
|
/** No argument text is included: notices and refusal logs must not copy task text or credentials. */
|
|
203
219
|
export function cliCommandLabel(command: string, args: readonly string[], catalog?: ProjectAdapterCatalog): string {
|
|
220
|
+
if (command === "roadmap") {
|
|
221
|
+
const sub = args[0] === "--json" ? args[1] : args[0];
|
|
222
|
+
return ["list", "show", "new", "edit", "link", "unlink", "order", "state", "unplaced", "triage", "accept", "reject", "import-github"].includes(sub ?? "") ? `roadmap ${sub}` : "roadmap";
|
|
223
|
+
}
|
|
224
|
+
if (command === "sdlc" && args[0] === "configure") return "sdlc configure";
|
|
225
|
+
if (command === "sdlc" && args[0] === "survey") return ["start", "show"].includes(args[1] ?? "") ? `sdlc survey ${args[1]}` : "sdlc survey";
|
|
226
|
+
if (command === "sdlc" && args[0] === "audit") return ["start", "show"].includes(args[1] ?? "") ? `sdlc audit ${args[1]}` : "sdlc audit";
|
|
204
227
|
if (command === "lineage") return ["show", "link"].includes(args[0] ?? "") ? `lineage ${args[0]}` : "lineage";
|
|
205
228
|
if (command === "guidance") return ["create", "list", "show", "withdraw"].includes(args[0] ?? "") ? `guidance ${args[0]}` : "guidance";
|
|
206
229
|
if (command === "model") return ["list", "set", "clear"].includes(args[0] ?? "") ? `model ${args[0]}` : "model";
|
|
@@ -221,7 +244,7 @@ export function cliCommandLabel(command: string, args: readonly string[], catalo
|
|
|
221
244
|
if (command === "learn") return ["list", "accept", "reject"].includes(args.find(arg => arg !== "--json") ?? "") ? `learn ${args.find(arg => arg !== "--json")}` : "learn";
|
|
222
245
|
if (command === "source") return ["add", "list"].includes(args.find(arg => arg !== "--json") ?? "") ? `source ${args.find(arg => arg !== "--json")}` : "source";
|
|
223
246
|
// #601: a campaign id and a contract path are text the person chose, so the audit names the subcommand only.
|
|
224
|
-
if (command === "study") return ["draft", "revise", "approve", "close", "show", "experiments"].includes(args[0] ?? "") ? `study ${args[0]}` : "study";
|
|
247
|
+
if (command === "study") return ["draft", "revise", "approve", "close", "show", "experiments", "evidence", "check"].includes(args[0] ?? "") ? `study ${args[0]}` : "study";
|
|
225
248
|
if (command === "release") return ["new", "list", "show", "plan", "activate", "freeze", "ship", "drop"].includes(args[0] ?? "") ? `release ${args[0]}` : "release";
|
|
226
249
|
// #1084: `autonomy`, `deliverables` and `usage` were missing from the table below, so a refusal and its audit line named them "unknown". Operands (a flag value, a task id) never reach the label.
|
|
227
250
|
if (command === "autonomy") { const sub = args.find(arg => !arg.startsWith("--")); return sub !== undefined && ["on", "off", "status"].includes(sub) ? `autonomy ${sub}` : "autonomy"; }
|
|
@@ -233,7 +256,7 @@ export function cliCommandLabel(command: string, args: readonly string[], catalo
|
|
|
233
256
|
if (command === "specs") return ["list", "check", "covers", "stamp"].includes(args[0] ?? "") ? `specs ${args[0]}` : "specs";
|
|
234
257
|
// #1057: the audit names the subcommand and whether it confirms, never a path, a branch or a fingerprint.
|
|
235
258
|
if (command === "worktrees") return args[0] === "tidy" ? (args.some(arg => arg === "--confirm" || arg.startsWith("--confirm=")) ? "worktrees tidy confirm" : "worktrees tidy") : "worktrees";
|
|
236
|
-
if (!(catalog?.definitionOf(command) ?? definitionOf(command)) && !["upgrade", "restart", "recovery", "recovery-run", "help", "--help", "--version", "version", "completion", "projects", "ui", "manager", "setup", "init", "daemon", "up", "console", "stop", "models", "say", "queue", "tail", "watch", "budget", "board", "task", "review", "remember", "ask", "route", "pause", "resume", "permit", "answer", "permission", "results", "settings", "roster", "status", "pet", "logs", "export", "report", "research", "memory", "goal", "bench", "sdlc", "role", "facts", "check-path", "turns", "undo", "kill", "down", "reset", "doctor", "agents", "source", "broker", "schedule", "intake", "learn", "study"].includes(command)) return "unknown";
|
|
259
|
+
if (!(catalog?.definitionOf(command) ?? definitionOf(command)) && !["upgrade", "restart", "recovery", "recovery-run", "help", "--help", "--version", "version", "completion", "projects", "ui", "manager", "setup", "init", "daemon", "up", "console", "stop", "roles", "models", "say", "queue", "tail", "watch", "budget", "board", "task", "review", "remember", "ask", "route", "pause", "resume", "permit", "answer", "permission", "results", "settings", "roster", "status", "pet", "logs", "export", "report", "research", "memory", "goal", "bench", "sdlc", "role", "facts", "check-path", "turns", "undo", "kill", "down", "reset", "doctor", "agents", "source", "broker", "schedule", "intake", "learn", "study"].includes(command)) return "unknown";
|
|
237
260
|
if (["task", "queue", "budget", "route", "recovery", "models", "projects", "research", "memory", "goal", "bench", "agents", "roster", "settings"].includes(command)) {
|
|
238
261
|
const sub = command === "bench" || command === "memory" || command === "goal" ? args.find((arg) => arg !== "--json") : args[0];
|
|
239
262
|
if (sub && ["propose", "show", "assign", "unassign", "escalate", "cancel", "claim", "label", "list", "add", "resolve", "resume", "set", "execution", "explain", "status", "abort", "dispose", "reattach", "setup", "start", "stop", "remove", "discard", "export", "backfill", "addons", "run", "report", "compare", "search", "graph", "promote", "demote", "forget", "supersede", "dedupe", "decay", "rebuild", "sync", "machine", "import", "suggestions", "confirm", "reject", "new", "link", "state", "done", "take", "trust"].includes(sub)) return `${command} ${sub}`;
|
package/src/cli/init-prompt.ts
CHANGED
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
* Who is offered it is decided by `promptGate`: a person at a terminal, on a new project, with no setting flag and no `--yes`. A delegated peer, a live test and any run without a
|
|
11
11
|
* terminal never reach `runInitPrompt` and get defaults plus their flags (AC5).
|
|
12
12
|
*/
|
|
13
|
-
import { INIT_SETTINGS, SDLC_MODES, SPEC_REVIEW_MODES, COORDINATION_MODES, AUTONOMY_CHOICES, type InitSettingRow, type InitSettingsRequest } from "./init-settings.ts";
|
|
13
|
+
import { INIT_SETTINGS, TRACK_CONFIG, SDLC_MODES, SPEC_REVIEW_MODES, COORDINATION_MODES, AUTONOMY_CHOICES, type InitSettingRow, type InitSettingsRequest } from "./init-settings.ts";
|
|
14
14
|
import { readFileSync } from "node:fs";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import { PROFILE_NAMES } from "../hub/profiles.ts";
|
|
17
17
|
import { DEFAULT_CONFIG } from "../hub/daemon.ts";
|
|
18
18
|
import { DEFAULT_SPECS_CONFIG } from "../hub/specs-config.ts";
|
|
19
19
|
import { START_AGENTS_ALLOWED, START_AGENTS_DEFAULT } from "../hub/start-agents.ts";
|
|
20
|
+
import { NO_CONDUCTOR, PERSON_REVIEWS, ROLE_FLAGS, eligiblePeers, parseRoleFlag, roleKeyOf, type RoleFlag } from "./init-roles.ts";
|
|
20
21
|
|
|
21
22
|
/** What a prompt needs from its surroundings. `ask` resolves to `null` at the end of input and after Ctrl-C (the caller turns both into `null`); it never throws for either. */
|
|
22
23
|
export interface InitPromptPorts {
|
|
@@ -31,7 +32,7 @@ export interface InitAnswers { request: InitSettingsRequest; profile?: string; s
|
|
|
31
32
|
export type InitPromptResult = { ok: true; answers: InitAnswers } | { ok: false; reason: "declined" | "interrupted" | "refused"; message: string };
|
|
32
33
|
|
|
33
34
|
/** The four questions that are choices of `ahub init` but not rows of the settings table. */
|
|
34
|
-
const NOT_ROWS: ReadonlySet<string> = new Set(["profile", "autonomy", "release-guard", "shadow"]);
|
|
35
|
+
const NOT_ROWS: ReadonlySet<string> = new Set(["profile", TRACK_CONFIG, "autonomy", "release-guard", "shadow", ...Object.values(ROLE_FLAGS).map(roleKeyOf)]);
|
|
35
36
|
const MAX_TRIES = 3;
|
|
36
37
|
const NOTHING = "nothing was written";
|
|
37
38
|
const yes = (text: string) => /^(y|yes)$/i.test(text.trim());
|
|
@@ -92,6 +93,8 @@ export interface InitQuestionContext {
|
|
|
92
93
|
discoverChecks?: () => Promise<readonly string[]>;
|
|
93
94
|
/** Shadow history is offered only for a folder with no Git work tree. */
|
|
94
95
|
shadowAvailable?: boolean;
|
|
96
|
+
/** The peers whose agent CLI is on this machine, offered first in the role questions (#1408). */
|
|
97
|
+
installedPeers?: readonly string[];
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
/**
|
|
@@ -109,10 +112,29 @@ export function initQuestions(context: InitQuestionContext = {}): InitQuestion[]
|
|
|
109
112
|
id: "start.agents", label: "Agents ahub up starts", choices: `${START_AGENTS_ALLOWED.join(",")} as a comma list, or none`, shown: (context.machineAgents ?? START_AGENTS_DEFAULT).join(", ") || "none",
|
|
110
113
|
read: text => INIT_SETTINGS.find(row => row.id === "start.agents")!.parse(text.trim().toLowerCase()),
|
|
111
114
|
};
|
|
115
|
+
// #1408 T2: one question per role, with only the peers that can hold it (a new project has no start modes yet, so each kind is judged in its own default form). Installed agents come first.
|
|
116
|
+
const roleQuestion = (flag: RoleFlag): InitQuestion => {
|
|
117
|
+
const role = ROLE_FLAGS[flag], peers = eligiblePeers(role, () => undefined, context.installedPeers ?? []);
|
|
118
|
+
const shown = shippedHolders(role);
|
|
119
|
+
return {
|
|
120
|
+
id: roleKeyOf(role), label: role === "conductor" ? "Conductor (reports to you, asks for your decisions; needs an interactive peer)" : role === "planner" ? "Planner" : "Reviewer",
|
|
121
|
+
choices: role === "conductor" ? [...peers, NO_CONDUCTOR].join("|") : role === "reviewer" ? `${peers.join(",")} as a comma list, or ${PERSON_REVIEWS}` : `${peers.join(",")} as a comma list`, shown,
|
|
122
|
+
read: text => {
|
|
123
|
+
const choice = parseRoleFlag(flag, text.trim().toLowerCase());
|
|
124
|
+
const named = choice === NO_CONDUCTOR || choice === PERSON_REVIEWS ? [] : Array.isArray(choice) ? choice : [choice];
|
|
125
|
+
const refused = named.find(peer => !peers.includes(peer));
|
|
126
|
+
if (refused !== undefined) throw new Error(`${refused} cannot be ${role} here; answer ${role === "conductor" ? [...peers, NO_CONDUCTOR].join(", ") : peers.join(", ")}`);
|
|
127
|
+
return choice;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
};
|
|
112
131
|
const switches = INIT_SETTINGS.filter(row => row.id.endsWith(".enabled") && !["specs.enabled", "memory.enabled", "research.enabled", "snapshots.enabled"].includes(row.id));
|
|
113
132
|
const all: InitQuestion[] = [
|
|
114
133
|
profile,
|
|
115
134
|
agents,
|
|
135
|
+
roleQuestion("--conductor"), roleQuestion("--planner"), roleQuestion("--reviewer"),
|
|
136
|
+
// #1411: Enter leaves the choice out, so .gitignore stays as git has it today and the block follows that.
|
|
137
|
+
{ ...onOff(TRACK_CONFIG, "Commit the shared hub config (config.json, routing.toml, sdlc.toml) to git", "off"), shown: "as .gitignore has it" },
|
|
116
138
|
onOff("specs.enabled", "Design specs and their freshness checks", shownDefault("specs.enabled") as "on" | "off"),
|
|
117
139
|
oneOf("specs.review", "Spec review mode", SPEC_REVIEW_MODES, shownDefault("specs.review")),
|
|
118
140
|
oneOf("sdlc.mode", "SDLC mode", SDLC_MODES, shownDefault("sdlc.mode")),
|
|
@@ -129,6 +151,13 @@ export function initQuestions(context: InitQuestionContext = {}): InitQuestion[]
|
|
|
129
151
|
return all.filter(question => NOT_ROWS.has(question.id) || ids.has(question.id));
|
|
130
152
|
}
|
|
131
153
|
|
|
154
|
+
/** Who holds `role` in the shipped `templates/config.json` (what Enter keeps), or `none` when nobody does: read from the template so the bracket cannot drift from what is written. */
|
|
155
|
+
function shippedHolders(role: "conductor" | "planner" | "reviewer"): string {
|
|
156
|
+
const roles = at(TEMPLATE, ["roles"]);
|
|
157
|
+
const holders = roles && typeof roles === "object" ? Object.entries(roles as Record<string, unknown>).filter(([, list]) => Array.isArray(list) && list.includes(role)).map(([peer]) => peer) : [];
|
|
158
|
+
return holders.join(", ") || (role === "reviewer" ? PERSON_REVIEWS : "none");
|
|
159
|
+
}
|
|
160
|
+
|
|
132
161
|
/** The question line: `label (a|b|c) [default]: `. */
|
|
133
162
|
export const questionLine = (question: InitQuestion): string => `${question.label} (${question.choices}) [${question.shown}]: `;
|
|
134
163
|
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1408 T2 (R3): who conducts, plans and reviews, chosen at `ahub init`. Three independent choices, each one flag and one guided question:
|
|
3
|
+
*
|
|
4
|
+
* --conductor <peer>|none --planner <peer>[,<peer>...] --reviewer <peer>[,<peer>...]|person
|
|
5
|
+
*
|
|
6
|
+
* Pure: no file is read or written. `parseRoleFlag` checks a flag's shape; `planRoles` takes the parsed shared and local config and returns the `roles` entries that change, or throws the
|
|
7
|
+
* refusal (the reason from `roleEligibility` and the eligible alternatives) before anything is written. Only conductor, planner and reviewer move: implementer, verifier and every catalog
|
|
8
|
+
* role stay as they are. A peer whose roles change is written as one explicit list, including the peer that loses a role, because `roles` merges per peer and a missing entry keeps the default.
|
|
9
|
+
*/
|
|
10
|
+
import { SUPPORTED_PEERS, defaultPeerRoles, definitionOf } from "../adapters/registry.ts";
|
|
11
|
+
import { roleEligibility, type EligibleRole } from "../adapters/role-eligibility.ts";
|
|
12
|
+
import { START_MODES, type StartMode } from "../hub/start-mode.ts";
|
|
13
|
+
|
|
14
|
+
export const ROLE_FLAGS = { "--conductor": "conductor", "--planner": "planner", "--reviewer": "reviewer" } as const satisfies Record<string, EligibleRole>;
|
|
15
|
+
export type RoleFlag = keyof typeof ROLE_FLAGS;
|
|
16
|
+
/** The request keys the three choices use in `InitSettingsRequest.values`. */
|
|
17
|
+
export const ROLE_KEYS = ["roles.conductor", "roles.planner", "roles.reviewer"] as const;
|
|
18
|
+
export type RoleKey = typeof ROLE_KEYS[number];
|
|
19
|
+
export const roleKeyOf = (role: EligibleRole): RoleKey => `roles.${role}`;
|
|
20
|
+
|
|
21
|
+
/** `none` as the conductor and `person` as the reviewer are choices, not peers: the person conducts from `ahub console`, and reviews go to the person. */
|
|
22
|
+
export const NO_CONDUCTOR = "none", PERSON_REVIEWS = "person";
|
|
23
|
+
/** The value of a choice: a peer or `none` (conductor), a list of peers (planner), a list of peers or `person` (reviewer). */
|
|
24
|
+
export type RoleChoice = string | string[];
|
|
25
|
+
|
|
26
|
+
/** The most planners a project can name; the loader refuses a longer `planner` list. */
|
|
27
|
+
const MAX_PLANNERS = 8;
|
|
28
|
+
/** What a flag accepts, for a refusal and for help. */
|
|
29
|
+
export const ROLE_ALLOWED: Record<RoleFlag, string> = {
|
|
30
|
+
"--conductor": "a peer or none",
|
|
31
|
+
"--planner": "a peer, or a comma-separated list of peers",
|
|
32
|
+
"--reviewer": "a peer, a comma-separated list of peers, or person",
|
|
33
|
+
};
|
|
34
|
+
const CANONICAL = ["planner", "implementer", "verifier", "reviewer", "conductor"] as const;
|
|
35
|
+
const nothing = "nothing was written";
|
|
36
|
+
|
|
37
|
+
const isPeer = (word: string) => (SUPPORTED_PEERS as readonly string[]).includes(word);
|
|
38
|
+
const clip = (text: string) => JSON.stringify(text.slice(0, 48));
|
|
39
|
+
|
|
40
|
+
/** A flag's text into its choice, or a refusal that names what is accepted. The eligibility of a peer is judged by `planRoles`, which sees the files. */
|
|
41
|
+
export function parseRoleFlag(flag: RoleFlag, text: string): RoleChoice {
|
|
42
|
+
const words = text.split(/[\s,]+/).map(word => word.trim().toLowerCase()).filter(Boolean);
|
|
43
|
+
const allowed = `${flag} takes ${ROLE_ALLOWED[flag]}; peers are ${SUPPORTED_PEERS.join(", ")}`;
|
|
44
|
+
if (!words.length) throw new Error(`${flag} needs a value: ${allowed}; ${nothing}`);
|
|
45
|
+
if (flag === "--conductor") {
|
|
46
|
+
if (words.length !== 1) throw new Error(`${flag}: at most one conductor; ${allowed}; ${nothing}`);
|
|
47
|
+
if (words[0] === NO_CONDUCTOR || isPeer(words[0]!)) return words[0]!;
|
|
48
|
+
throw new Error(`${flag}: ${clip(text)} is not a peer or none; ${allowed}; ${nothing}`);
|
|
49
|
+
}
|
|
50
|
+
if (flag === "--reviewer" && words.includes(PERSON_REVIEWS)) {
|
|
51
|
+
if (words.length !== 1) throw new Error(`${flag}: person stands alone (reviews go to the person); name peers or person, not both; ${nothing}`);
|
|
52
|
+
return PERSON_REVIEWS;
|
|
53
|
+
}
|
|
54
|
+
const unknown = words.find(word => !isPeer(word));
|
|
55
|
+
if (unknown !== undefined) throw new Error(`${flag}: ${clip(unknown)} is not a peer; ${allowed}; ${nothing}`);
|
|
56
|
+
if (new Set(words).size !== words.length) throw new Error(`${flag}: a peer is named twice; ${nothing}`);
|
|
57
|
+
if (flag === "--planner" && words.length > MAX_PLANNERS) throw new Error(`${flag}: at most ${MAX_PLANNERS} planners; ${nothing}`);
|
|
58
|
+
return words;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The peers `role` may go to, given each peer's start mode (`undefined`: the kind's own default form). Installed agents come first, each group in registry order. */
|
|
62
|
+
export function eligiblePeers(role: EligibleRole, startMode: (peer: string) => StartMode | undefined = () => undefined, installed: readonly string[] = []): string[] {
|
|
63
|
+
const ok = SUPPORTED_PEERS.filter(peer => roleEligibility(peer, role, startMode(peer)).eligible);
|
|
64
|
+
return [...ok.filter(peer => installed.includes(peer)), ...ok.filter(peer => !installed.includes(peer))];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The peers whose agent CLI is on PATH, by the command each adapter definition names. A hub-owned peer (the local worker, `trust.onPrem`) runs inside the hub and needs no CLI. */
|
|
68
|
+
export function installedPeers(which: (binary: string) => string | null | undefined = binary => Bun.which(binary)): string[] {
|
|
69
|
+
return SUPPORTED_PEERS.filter(peer => {
|
|
70
|
+
const definition = definitionOf(peer);
|
|
71
|
+
return definition?.trust.onPrem === true || (!!definition && !!which(definition.cli.command));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const isObject = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
|
|
76
|
+
const listOf = (value: unknown): string[] | undefined => Array.isArray(value) && value.every(item => typeof item === "string") ? [...value] : undefined;
|
|
77
|
+
/** The effective start mode of a peer in the two files: `config.local.json` wins over the shared file, as the loader reads them. */
|
|
78
|
+
export function startModeIn(peer: string, shared: Record<string, unknown>, local: Record<string, unknown>): StartMode | undefined {
|
|
79
|
+
for (const doc of [local, shared]) {
|
|
80
|
+
const mode = isObject(doc.peers) && isObject(doc.peers[peer]) ? (doc.peers[peer] as { start_mode?: unknown }).start_mode : undefined;
|
|
81
|
+
if ((START_MODES as readonly unknown[]).includes(mode)) return mode as StartMode;
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
/** The roles a peer holds now: its entry in the shared file, else the adapter default (a peer left out of `roles` keeps its default). */
|
|
86
|
+
export function effectiveRoles(peer: string, shared: Record<string, unknown>): string[] {
|
|
87
|
+
return (isObject(shared.roles) ? listOf(shared.roles[peer]) : undefined) ?? defaultPeerRoles(true)[peer] ?? [];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface RoleChange { peer: string; from: string[]; to: string[] }
|
|
91
|
+
|
|
92
|
+
/** The refusal for a peer that cannot take the role: the reason and fix from `roleEligibility`, and who can. */
|
|
93
|
+
function refusal(flag: RoleFlag, peer: string, role: EligibleRole, startMode: StartMode | undefined, alternatives: readonly string[]): Error {
|
|
94
|
+
const verdict = roleEligibility(peer, role, startMode);
|
|
95
|
+
const others = alternatives.length ? `eligible: ${alternatives.join(", ")}` : `no peer can hold ${role} here`;
|
|
96
|
+
return new Error(`${flag} ${peer}: ${verdict.reason}; ${verdict.fix}; ${others}; ${nothing}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The `roles` entries the choices change, given the parsed shared and local config. A choice that is not given changes nothing; one that already holds changes nothing. Refuses, before any write:
|
|
101
|
+
* a peer that cannot hold the role (its reason, its fix and the eligible peers), a peer whose roles `config.local.json` overrides (the shared write would not take effect), and a planner choice
|
|
102
|
+
* while a `planner` setting is present (it outranks the roles).
|
|
103
|
+
*/
|
|
104
|
+
export function planRoles(choices: Partial<Record<RoleKey, unknown>>, shared: Record<string, unknown>, local: Record<string, unknown>): RoleChange[] {
|
|
105
|
+
const startMode = (peer: string) => startModeIn(peer, shared, local);
|
|
106
|
+
const peers = new Set<string>([...SUPPORTED_PEERS, ...(isObject(shared.roles) ? Object.keys(shared.roles) : [])]);
|
|
107
|
+
const held = new Map<string, Set<string>>([...peers].map(peer => [peer, new Set(effectiveRoles(peer, shared))]));
|
|
108
|
+
const give = (role: EligibleRole, to: readonly string[]) => {
|
|
109
|
+
for (const roles of held.values()) roles.delete(role);
|
|
110
|
+
for (const peer of to) (held.get(peer) ?? held.set(peer, new Set()).get(peer)!).add(role);
|
|
111
|
+
};
|
|
112
|
+
const check = (flag: RoleFlag, role: EligibleRole, named: readonly string[]) => {
|
|
113
|
+
for (const peer of named) if (!roleEligibility(peer, role, startMode(peer)).eligible) throw refusal(flag, peer, role, startMode(peer), eligiblePeers(role, startMode));
|
|
114
|
+
};
|
|
115
|
+
const conductor = choices["roles.conductor"], planner = choices["roles.planner"], reviewer = choices["roles.reviewer"];
|
|
116
|
+
if (conductor !== undefined) {
|
|
117
|
+
const named = conductor === NO_CONDUCTOR ? [] : [String(conductor)];
|
|
118
|
+
check("--conductor", "conductor", named);
|
|
119
|
+
give("conductor", named);
|
|
120
|
+
}
|
|
121
|
+
if (planner !== undefined) {
|
|
122
|
+
const named = planner as string[];
|
|
123
|
+
check("--planner", "planner", named);
|
|
124
|
+
if (shared.planner !== undefined || local.planner !== undefined) throw new Error(`--planner: a planner setting is present in .agenthub/config.json or config.local.json and outranks roles; remove that key (or set it with ahub settings set planner), then run ahub init again; ${nothing}`);
|
|
125
|
+
give("planner", named);
|
|
126
|
+
}
|
|
127
|
+
if (reviewer !== undefined) {
|
|
128
|
+
const named = reviewer === PERSON_REVIEWS ? [] : reviewer as string[];
|
|
129
|
+
check("--reviewer", "reviewer", named);
|
|
130
|
+
give("reviewer", named);
|
|
131
|
+
}
|
|
132
|
+
const rank = (role: string) => { const at = CANONICAL.indexOf(role as typeof CANONICAL[number]); return at === -1 ? CANONICAL.length : at; };
|
|
133
|
+
const changes: RoleChange[] = [];
|
|
134
|
+
for (const [peer, roles] of held) {
|
|
135
|
+
const from = effectiveRoles(peer, shared);
|
|
136
|
+
// The roles the peer keeps stay in the order the file has them; a role it gains follows, in the canonical order.
|
|
137
|
+
const to = [...from.filter(role => roles.has(role)), ...[...roles].filter(role => !from.includes(role)).sort((a, b) => rank(a) - rank(b))];
|
|
138
|
+
if (to.length === from.length && to.every(role => from.includes(role))) continue;
|
|
139
|
+
changes.push({ peer, from, to });
|
|
140
|
+
}
|
|
141
|
+
const overridden = isObject(local.roles) ? changes.filter(change => Object.hasOwn(local.roles as object, change.peer)) : [];
|
|
142
|
+
if (overridden.length) throw new Error(`config.local.json roles.${overridden[0]!.peer} overrides the shared roles for ${overridden[0]!.peer}, so the choice would not take effect; change it there (or remove that entry), then run ahub init again; ${nothing}`);
|
|
143
|
+
return changes;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** What each choice means, in the words of the init summary. Printed after the writes, and for a choice that changed nothing too. */
|
|
147
|
+
export function roleSummaryLines(choices: Partial<Record<RoleKey, unknown>>): string[] {
|
|
148
|
+
const lines: string[] = [];
|
|
149
|
+
const conductor = choices["roles.conductor"], planner = choices["roles.planner"], reviewer = choices["roles.reviewer"];
|
|
150
|
+
if (conductor === NO_CONDUCTOR) lines.push("- Conductor: none. You conduct from ahub console.");
|
|
151
|
+
else if (typeof conductor === "string") lines.push(`- Conductor: ${conductor}. It must run interactively; ahub doctor shows who holds each role.`);
|
|
152
|
+
if (Array.isArray(planner)) lines.push(`- Planner: ${planner.join(", ")}.`);
|
|
153
|
+
if (reviewer === PERSON_REVIEWS) lines.push("- Reviewer: person. No peer holds the reviewer role, so reviews go to you.");
|
|
154
|
+
else if (Array.isArray(reviewer)) lines.push(`- Reviewer: ${reviewer.join(", ")}.`);
|
|
155
|
+
return lines;
|
|
156
|
+
}
|
package/src/cli/init-settings.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { checkStartAgents, START_AGENTS_ALLOWED } from "../hub/start-agents.ts";
|
|
10
10
|
import { editSdlcText } from "../hub/config-edit.ts";
|
|
11
11
|
import { ADAPTERS } from "../adapters/registry.ts";
|
|
12
|
+
import { ROLE_ALLOWED, ROLE_FLAGS, ROLE_KEYS, parseRoleFlag, planRoles, roleKeyOf, type RoleFlag } from "./init-roles.ts";
|
|
12
13
|
|
|
13
14
|
export type InitSettingFile = "config.json" | "config.local.json" | "sdlc.toml";
|
|
14
15
|
export const SDLC_MODES = ["off", "advise", "enforce"] as const;
|
|
@@ -76,10 +77,12 @@ export interface InitSettingsRequest {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/** The usage line `ahub init` prints for a bad argument; help.ts shows the same flags. */
|
|
79
|
-
export const INIT_USAGE = "usage: ahub init [--profile dev|research|writing|general|<pack>] [--agents <a,b,...|none>] [--sdlc off|advise|enforce] [--required-checks <a,b,...>] [--coordination advisory|turn-free] [--memory|--no-memory] [--research|--no-research] [--snapshots|--no-snapshots] [--pi|--no-pi] [--specs|--no-specs] [--spec-review off|report|require] [--autonomy inherit|off] [--shadow] [--release-guard] [--yes] [--dry-run --json]";
|
|
80
|
+
export const INIT_USAGE = "usage: ahub init [--profile dev|research|writing|general|<pack>] [--agents <a,b,...|none>] [--sdlc off|advise|enforce] [--required-checks <a,b,...>] [--coordination advisory|turn-free] [--memory|--no-memory] [--research|--no-research] [--snapshots|--no-snapshots] [--pi|--no-pi] [--specs|--no-specs] [--spec-review off|report|require] [--conductor <peer>|none] [--planner <a,b,...>] [--reviewer <a,b,...>|person] [--track-config|--no-track-config] [--autonomy inherit|off] [--shadow] [--release-guard] [--yes] [--dry-run --json]";
|
|
80
81
|
|
|
81
82
|
/** Every flag the table and the two non-key choices own, for the caller's own argument loop and for help. */
|
|
82
|
-
export const INIT_SETTING_FLAGS: readonly string[] = [...INIT_SETTINGS.flatMap(row => row.flags.map(flag => flag.flag)), "--autonomy"];
|
|
83
|
+
export const INIT_SETTING_FLAGS: readonly string[] = [...INIT_SETTINGS.flatMap(row => row.flags.map(flag => flag.flag)), "--track-config", "--no-track-config", "--autonomy", ...Object.keys(ROLE_FLAGS)];
|
|
84
|
+
/** #1411: the request key of `--track-config` / `--no-track-config` (true / false); absent keeps what git says today. */
|
|
85
|
+
export const TRACK_CONFIG = "track-config";
|
|
83
86
|
|
|
84
87
|
/**
|
|
85
88
|
* Separates the setting flags from the rest of an `ahub init` argv. A value flag takes the next word; a switch takes none. A flag given twice with different
|
|
@@ -102,6 +105,16 @@ export function parseInitSettings(args: readonly string[]): { request: InitSetti
|
|
|
102
105
|
request.autonomy = text as typeof AUTONOMY_CHOICES[number];
|
|
103
106
|
continue;
|
|
104
107
|
}
|
|
108
|
+
// #1411: whether the repository commits its hub config. Not a config key (init.ts reads it for .gitignore and the block's role sentence), but it rides in `values` so every
|
|
109
|
+
// caller that asks "was a setting given" sees it.
|
|
110
|
+
if (arg === "--track-config" || arg === "--no-track-config") { set(TRACK_CONFIG, arg, arg === "--track-config"); continue; }
|
|
111
|
+
// #1408 T2: who conducts, plans and reviews. Each is one request key; init-roles.ts judges eligibility against the files when the plan is made.
|
|
112
|
+
if (Object.hasOwn(ROLE_FLAGS, arg)) {
|
|
113
|
+
const text = args[++i];
|
|
114
|
+
if (text === undefined) throw new Error(`${arg} needs a value: ${ROLE_ALLOWED[arg as RoleFlag]}; nothing was written`);
|
|
115
|
+
set(roleKeyOf(ROLE_FLAGS[arg as RoleFlag]), arg, parseRoleFlag(arg as RoleFlag, text));
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
105
118
|
const row = INIT_SETTINGS.find(def => def.flags.some(flag => flag.flag === arg));
|
|
106
119
|
if (!row) { rest.push(arg); continue; }
|
|
107
120
|
const flag = row.flags.find(entry => entry.flag === arg)!;
|
|
@@ -231,5 +244,14 @@ export function planInitSettings(request: InitSettingsRequest, texts: InitSettin
|
|
|
231
244
|
next[file] = current[file]!;
|
|
232
245
|
rows.push({ key: row.id, file, ...(held === undefined ? {} : { from: held }), to } as InitSettingRow);
|
|
233
246
|
}
|
|
247
|
+
// #1408 T2: the role choices, judged against the config.json this plan produces and the local file; each peer whose roles change is written as one explicit list.
|
|
248
|
+
if (ROLE_KEYS.some(key => Object.hasOwn(request.values, key))) {
|
|
249
|
+
const changes = planRoles(request.values, parsed("config.json"), parsed("config.local.json"));
|
|
250
|
+
for (const change of changes) {
|
|
251
|
+
current["config.json"] = editJsonText(current["config.json"] ?? "{}\n", ["roles", change.peer], change.to);
|
|
252
|
+
rows.push({ key: `roles.${change.peer}`, file: "config.json", from: change.from, to: change.to });
|
|
253
|
+
}
|
|
254
|
+
if (changes.length) next["config.json"] = current["config.json"]!;
|
|
255
|
+
}
|
|
234
256
|
return { rows, next };
|
|
235
257
|
}
|