@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
package/src/cli/init.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { initShadow, repoOf } from "../hub/snapshots.ts";
|
|
|
3
3
|
import { PROFILE_NAMES, profileName, projectProfile, resolveProfile, mergeProfileOverrides, type ProfileName } from "../hub/profiles.ts";
|
|
4
4
|
import { canonicalJson, loadPacks, packOverrides, type DomainPack } from "../hub/packs.ts";
|
|
5
5
|
import { JCODE_MCP_FILE } from "./jcode-mcp.ts";
|
|
6
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync, statSync, unlinkSync, writeFileSync, renameSync } from "node:fs";
|
|
6
|
+
import { closeSync, constants, fstatSync, openSync, readSync, existsSync, lstatSync, mkdirSync, mkdtempSync, rmSync, readFileSync, statSync, unlinkSync, writeFileSync, renameSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
7
8
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
8
9
|
import { spawnSync } from "node:child_process";
|
|
9
10
|
import type { Stats } from "node:fs";
|
|
@@ -11,12 +12,14 @@ import { realPath } from "../hub/project.ts";
|
|
|
11
12
|
import { hubGitArgv, hubGitEnv, hubGitSync } from "../hub/git.ts";
|
|
12
13
|
import { KIMI_MCP_FILE } from "./kimi-mcp.ts";
|
|
13
14
|
import { AGY_PLUGIN_FILES } from "./agy-mcp.ts";
|
|
14
|
-
import { loadConfig } from "../hub/daemon.ts";
|
|
15
|
+
import { DEFAULT_CONFIG, loadConfig } from "../hub/daemon.ts";
|
|
16
|
+
import { ALL_MACHINE_LOCAL } from "../hub/config-trust.ts";
|
|
15
17
|
import { requiredChecksFor } from "../hub/sdlc-merge.ts";
|
|
16
18
|
import { githubOriginRepository } from "../hub/task-repository.ts";
|
|
17
19
|
import { loadSdlc, sdlcConfig } from "../hub/sdlc.ts";
|
|
18
20
|
import { VERSION } from "../version.ts";
|
|
19
|
-
import {
|
|
21
|
+
import { roleSummaryLines } from "./init-roles.ts";
|
|
22
|
+
import { planInitSettings, TRACK_CONFIG, type InitSettingFile, type InitSettingRow, type InitSettingsRequest } from "./init-settings.ts";
|
|
20
23
|
|
|
21
24
|
const TEMPLATES = join(import.meta.dir, "..", "..", "templates");
|
|
22
25
|
const BEGIN = "<!-- AGENT_HUB:BEGIN (managed by `ahub init`, edits inside are overwritten) -->";
|
|
@@ -40,6 +43,139 @@ export function removeBlock(existing: string): string {
|
|
|
40
43
|
return rest && `${rest}\n`;
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
/** #1411: the files a repository either commits (the team shares roles and defaults) or keeps per checkout. */
|
|
47
|
+
const SHARED_CONFIG = ["config.json", "routing.toml", "sdlc.toml"] as const;
|
|
48
|
+
/** #1411: the managed block's role sentence, one per choice. The tracked one is the template's own text. */
|
|
49
|
+
export const ROLES_TRACKED = "`.agenthub/config.json` `roles` says who plans, implements, verifies and reviews.";
|
|
50
|
+
export const ROLES_UNTRACKED = "Roles are held by this checkout's hub, not by a file in the repository: `ahub roles` prints who plans, implements, verifies, reviews and conducts; your own roles are in your session instructions.";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* #1411: git's own verdict on whether its ignore rules (the repository's, `.git/info/exclude` and the person's global file) ignore `path`, tracked or not: the rule as
|
|
54
|
+
* `source:line:pattern`, `null` when no rule ignores it, `undefined` when git cannot say (no repository). `-v` also reports a `!` rule that re-includes the path, with
|
|
55
|
+
* exit 0, so the pattern decides.
|
|
56
|
+
*/
|
|
57
|
+
export function ignoreRule(cwd: string, path: string): string | null | undefined {
|
|
58
|
+
const r = hubGitSync(["check-ignore", "-v", "-z", "--no-index", "--stdin"], { cwd, encoding: "utf8", timeout: 3000, input: `${path}\0` });
|
|
59
|
+
if (r.status === 1) return null;
|
|
60
|
+
if (r.status !== 0) return undefined;
|
|
61
|
+
const [source, line, pattern] = r.stdout.split("\0");
|
|
62
|
+
return pattern === undefined || pattern.startsWith("!") ? null : `${source}:${line}:${pattern}`;
|
|
63
|
+
}
|
|
64
|
+
const SHARED_IGNORE_BEGIN = "# agent-hub shared config (managed by ahub init)";
|
|
65
|
+
const SHARED_IGNORE_END = "# end agent-hub shared config";
|
|
66
|
+
/** One exact-line parser for replacement and removal; malformed ownership is never guessed. */
|
|
67
|
+
function sharedIgnoreBlock(text: string): { start: number; end: number; eol: string; newline: boolean } | undefined {
|
|
68
|
+
let start: number | undefined, end: number | undefined, offset = 0;
|
|
69
|
+
let eol = "\n", newline = false;
|
|
70
|
+
const malformed = () => new Error("--track-config: incomplete or duplicate managed shared-config ignore markers; repair the marker pair in the project .gitignore and retry ahub init; nothing was written");
|
|
71
|
+
for (const line of text.match(/[^\n]*(?:\n|$)/g) ?? []) {
|
|
72
|
+
const value = line.replace(/\r?\n$/, "");
|
|
73
|
+
if (value === SHARED_IGNORE_BEGIN) {
|
|
74
|
+
if (start !== undefined) throw malformed();
|
|
75
|
+
start = offset; eol = line.endsWith("\r\n") ? "\r\n" : "\n";
|
|
76
|
+
} else if (value === SHARED_IGNORE_END) {
|
|
77
|
+
if (start === undefined || end !== undefined) throw malformed();
|
|
78
|
+
end = offset + line.length; newline = line.endsWith("\n");
|
|
79
|
+
}
|
|
80
|
+
offset += line.length;
|
|
81
|
+
}
|
|
82
|
+
if ((start === undefined) !== (end === undefined)) throw malformed();
|
|
83
|
+
return start === undefined || end === undefined ? undefined : { start, end, eol, newline };
|
|
84
|
+
}
|
|
85
|
+
function sharedIgnoreRepository(cwd: string, unknown = false): { gitDir: string; root: string } | undefined {
|
|
86
|
+
const git = hubGitSync(["rev-parse", "--absolute-git-dir", "--show-toplevel"], { cwd, env: { ...process.env, LC_ALL: "C" }, encoding: "utf8", timeout: 3000 });
|
|
87
|
+
if (git.status !== 0 && git.stderr?.startsWith("fatal: not a git repository")) return;
|
|
88
|
+
if (git.status !== 0 || unknown) throw new Error("--track-config: git could not determine repository ignore rules; run git status and retry ahub init; nothing was written");
|
|
89
|
+
const [gitDir, root] = git.stdout.trim().split("\n");
|
|
90
|
+
if (!gitDir || !root) throw new Error("--track-config: git did not identify the repository paths; run git status and retry ahub init; nothing was written");
|
|
91
|
+
return { gitDir, root: realPath(root) };
|
|
92
|
+
}
|
|
93
|
+
/** Git evaluates planned project rules in a disposable worktree; the real index/config are never written. */
|
|
94
|
+
function verifySharedIgnores(cwd: string, text: string, tracked: readonly string[], repository: ReturnType<typeof sharedIgnoreRepository>): void {
|
|
95
|
+
if (!repository || repository.root !== realPath(cwd)) return;
|
|
96
|
+
const { gitDir } = repository;
|
|
97
|
+
const excludes = hubGitSync(["config", "--path", "--get", "core.excludesFile"], { cwd, encoding: "utf8", timeout: 3000 });
|
|
98
|
+
if (excludes.status !== 0 && excludes.status !== 1) throw new Error("--track-config: git could not read the excludes-file setting; run git config --get core.excludesFile and retry ahub init; nothing was written");
|
|
99
|
+
const excludeArgs = excludes.status === 0 ? ["-c", `core.excludesFile=${resolve(cwd, excludes.stdout.trim())}`] : [];
|
|
100
|
+
let scratch: string | undefined;
|
|
101
|
+
try {
|
|
102
|
+
scratch = mkdtempSync(join(tmpdir(), "ahub-init-ignore-"));
|
|
103
|
+
scratch = realPath(scratch);
|
|
104
|
+
writeFileSync(join(scratch, ".gitignore"), text);
|
|
105
|
+
mkdirSync(join(scratch, ".agenthub"));
|
|
106
|
+
const nested = join(cwd, ".agenthub", ".gitignore");
|
|
107
|
+
if (existsSync(nested)) writeFileSync(join(scratch, ".agenthub", ".gitignore"), readFileSync(nested, "utf8"));
|
|
108
|
+
const protectedPaths = [".agenthub/state/", ".agenthub/config.local.json", ".agenthub/routing.local.toml", ...SHARED_CONFIG.filter(name => !tracked.includes(name)).map(name => `.agenthub/${name}`)];
|
|
109
|
+
for (const path of [...tracked.map(name => `.agenthub/${name}`), ...protectedPaths]) {
|
|
110
|
+
const verdict = hubGitSync([...excludeArgs, `--git-dir=${gitDir}`, `--work-tree=${scratch}`, "check-ignore", "-v", "-z", "--no-index", "--stdin"], { cwd: scratch, encoding: "utf8", timeout: 3000, input: `${path}\0` });
|
|
111
|
+
if (verdict.status !== 0 && verdict.status !== 1) throw new Error("git could not evaluate the planned ignore rules; run git status and retry ahub init");
|
|
112
|
+
const [source, line, pattern] = verdict.stdout.split("\0");
|
|
113
|
+
const ignored = verdict.status === 0 && pattern !== undefined && !pattern.startsWith("!");
|
|
114
|
+
if (tracked.includes(path.slice(".agenthub/".length)) ? ignored : !ignored)
|
|
115
|
+
throw new Error(`${path} ${ignored ? `is ignored by ${source}:${line}:${pattern}` : "would be exposed by the planned rules"}; change the project ignore rule and retry ahub init`);
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
// File/read errors may contain private paths; only git verdicts above expose the existing rule location.
|
|
119
|
+
if (error instanceof Error && (error.message.startsWith(".agenthub/") || error.message.startsWith("git could not"))) throw new Error(`--track-config: ${error.message}; nothing was written`);
|
|
120
|
+
throw new Error("--track-config: could not prepare the disposable ignore preview; check temporary-directory and project ignore-file permissions, then retry ahub init; nothing was written");
|
|
121
|
+
} finally {
|
|
122
|
+
if (scratch) try { rmSync(scratch, { recursive: true, force: true }); }
|
|
123
|
+
catch { throw new Error("--track-config: could not remove the disposable ignore preview; check temporary-directory permissions before retrying ahub init; nothing was written"); }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** #1411 (owner comment): `hub_routes` keys that name this machine's endpoints; routing.local.toml cannot hold them yet, so a routing.toml that sets one stays untracked. */
|
|
127
|
+
function routingMachineKeys(cwd: string): string[] {
|
|
128
|
+
const path = join(cwd, ".agenthub", "routing.toml");
|
|
129
|
+
if (!existsSync(path)) return [];
|
|
130
|
+
let routes: unknown;
|
|
131
|
+
try { routes = (Bun.TOML.parse(readFileSync(path, "utf8")) as Record<string, unknown>).hub_routes; } catch { return []; } // the routing loader reports a bad file itself
|
|
132
|
+
if (!routes || typeof routes !== "object") return [];
|
|
133
|
+
return Object.entries(routes as Record<string, unknown>).filter(([, route]) => route && typeof route === "object" && Object.hasOwn(route, "adec_endpoint")).map(([id]) => `hub_routes."${id}".adec_endpoint`);
|
|
134
|
+
}
|
|
135
|
+
/** #1411: machine-local fields a committed config.json would set; the loader ignores them there, so they belong in config.local.json. */
|
|
136
|
+
function personalValues(cwd: string): string[] {
|
|
137
|
+
const path = join(cwd, ".agenthub", "config.json");
|
|
138
|
+
if (!existsSync(path)) return [];
|
|
139
|
+
let file: unknown;
|
|
140
|
+
try { file = JSON.parse(readFileSync(path, "utf8")); } catch { return []; }
|
|
141
|
+
const at = (doc: unknown, key: string) => key.split(".").reduce<unknown>((node, part) => node && typeof node === "object" ? (node as Record<string, unknown>)[part] : undefined, doc);
|
|
142
|
+
const empty = (value: unknown) => value === undefined || value === null || value === "" || Array.isArray(value) && !value.length;
|
|
143
|
+
return ALL_MACHINE_LOCAL.filter(key => !empty(at(file, key)) && JSON.stringify(at(file, key)) !== JSON.stringify(at(DEFAULT_CONFIG, key)));
|
|
144
|
+
}
|
|
145
|
+
/** #1411: whether the block should say the config is tracked. A choice wins; without one an existing block keeps its sentence (AC2), and a new block follows what git says today. */
|
|
146
|
+
function rolesTracked(cwd: string, existing: string, settings: InitSettingsRequest | undefined): boolean {
|
|
147
|
+
const choice = settings?.values[TRACK_CONFIG];
|
|
148
|
+
if (typeof choice === "boolean") return choice;
|
|
149
|
+
if (existing.includes(ROLES_UNTRACKED)) return false;
|
|
150
|
+
if (existing.includes("<!-- AGENT_HUB:BEGIN")) return true;
|
|
151
|
+
return !ignoreRule(cwd, ".agenthub/config.json");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* #1411 T2: doctor's `shared config` row. Whether `.agenthub/config.json` is committed agrees with the managed block's role sentence: `ok` true for both deliberate
|
|
156
|
+
* states, `undefined` (a warning) for a mismatch or a git state it cannot read, with the command that fixes it; `null` when there is no block sentence or no config to compare.
|
|
157
|
+
*/
|
|
158
|
+
export function sharedConfigRow(cwd: string): { ok: true | undefined; detail: string } | null {
|
|
159
|
+
const agents = join(cwd, "AGENTS.md"), file = ".agenthub/config.json";
|
|
160
|
+
if (!existsSync(agents) || !existsSync(join(cwd, file))) return null;
|
|
161
|
+
const block = readFileSync(agents, "utf8");
|
|
162
|
+
const saysTracked = block.includes(ROLES_TRACKED), saysUntracked = block.includes(ROLES_UNTRACKED);
|
|
163
|
+
if (saysTracked === saysUntracked) return null; // no managed sentence (an older block): the hub instructions row says to refresh it
|
|
164
|
+
const listed = hubGitSync(["ls-files", "--error-unmatch", "--", file], { cwd, encoding: "utf8", timeout: 3000 }).status;
|
|
165
|
+
const rule = ignoreRule(cwd, file);
|
|
166
|
+
if (listed !== 0 && listed !== 1 || rule === undefined) return { ok: undefined, detail: `git could not say whether ${file} is committed; check with: cd ${cwd} && git ls-files ${file}` };
|
|
167
|
+
const committed = listed === 0, toUntracked = `cd ${cwd} && ahub init --no-track-config --yes`;
|
|
168
|
+
if (saysUntracked) return committed
|
|
169
|
+
? { ok: undefined, detail: `the AGENTS block says roles are per checkout, but ${file} is committed; share it: cd ${cwd} && ahub init --track-config --yes; or stop tracking it: cd ${cwd} && git rm --cached ${file}, then commit` }
|
|
170
|
+
: { ok: true, detail: "untracked (by choice): each checkout holds its own roles; ahub roles prints them" };
|
|
171
|
+
if (!committed) return { ok: undefined, detail: rule
|
|
172
|
+
? `the AGENTS block points at ${file}, which ${rule} ignores; keep it per checkout: ${toUntracked}; or remove that rule and commit the file`
|
|
173
|
+
: `the AGENTS block points at ${file}, which is not committed; commit it: cd ${cwd} && git add ${file} && git commit; or keep it per checkout: ${toUntracked}` };
|
|
174
|
+
return rule
|
|
175
|
+
? { ok: undefined, detail: `${file} is committed but ${rule} ignores it, so a re-added copy is skipped; remove that rule, or stop tracking it: ${toUntracked} && git rm --cached ${file}` }
|
|
176
|
+
: { ok: true, detail: `tracked: ${file} is committed and the AGENTS block points at it` };
|
|
177
|
+
}
|
|
178
|
+
|
|
43
179
|
export interface InitChange {
|
|
44
180
|
action: "create" | "modify" | "delete";
|
|
45
181
|
path: string;
|
|
@@ -213,7 +349,8 @@ function changes(cwd: string, requestedName?: string, shadow = false, releaseGua
|
|
|
213
349
|
const agents = join(cwd, "AGENTS.md");
|
|
214
350
|
const existing = existsSync(agents) ? readFileSync(agents, "utf8") : "";
|
|
215
351
|
// #1399: one source for the block. A shipped profile's `agents` is only its addition, appended to the template; a project's own `profile_overrides.agents` still replaces the whole block.
|
|
216
|
-
const
|
|
352
|
+
const shipped = readFileSync(join(TEMPLATES, "AGENTS.block.md"), "utf8");
|
|
353
|
+
const template = rolesTracked(cwd, existing, settings) ? shipped : shipped.replace(ROLES_TRACKED, ROLES_UNTRACKED);
|
|
217
354
|
const hubBlock = upsertBlock(existing, overrides && Object.hasOwn(overrides as object, "agents") ? profile.agents : profile.agents ? `${template.trim()}\n\n${profile.agents}` : template);
|
|
218
355
|
const instructions = specsBlock(hubBlock, specsEnabled(cwd, settings)); // #1064 T3: a project that turned specs off keeps no block
|
|
219
356
|
write(agents, guarded ? releaseBlock(instructions) : instructions, "refresh hub instructions; preserve surrounding text", existing.includes("<!-- AGENT_HUB:BEGIN") ? "replace" : "insert");
|
|
@@ -229,18 +366,59 @@ function changes(cwd: string, requestedName?: string, shadow = false, releaseGua
|
|
|
229
366
|
}
|
|
230
367
|
const ignore = join(cwd, ".gitignore");
|
|
231
368
|
let lines = existsSync(ignore) ? readFileSync(ignore, "utf8") : "";
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
369
|
+
// #1411 AC6: git decides whether a path is already ignored (a broader rule, .git/info/exclude, the person's global file); the line check covers no repository and lines added in this run.
|
|
370
|
+
const add = (entry: string) => {
|
|
371
|
+
if (lines.split("\n").includes(entry) || ignoreRule(cwd, entry)) return;
|
|
372
|
+
lines = `${lines}${lines && !lines.endsWith("\n") ? "\n" : ""}${entry}\n`;
|
|
373
|
+
};
|
|
374
|
+
for (const entry of [".agenthub/state/", ".agenthub/config.local.json", ".agenthub/routing.local.toml", ...(shadow ? [".agenthub/shadow.git/"] : [])]) add(entry);
|
|
375
|
+
if (existsSync(join(cwd, KIMI_MCP_FILE)) && hubGitSync(["ls-files", "--error-unmatch", "--", KIMI_MCP_FILE], { cwd, encoding: "utf8", timeout: 3000 }).status !== 0) add(KIMI_MCP_FILE);
|
|
236
376
|
const agyPlugin = ".agents/plugins/agent-hub/";
|
|
237
377
|
if (existsSync(join(cwd, agyPlugin))) {
|
|
238
378
|
const tracked = new Set(hubGitSync(["ls-files", "--", agyPlugin], { cwd, encoding: "utf8", timeout: 3000 }).stdout.trim().split("\n").filter(Boolean));
|
|
239
|
-
const
|
|
240
|
-
for (const entry of entries) if (!lines.split("\n").includes(entry)) lines = `${lines}${lines && !lines.endsWith("\n") ? "\n" : ""}${entry}\n`;
|
|
379
|
+
for (const entry of tracked.size ? AGY_PLUGIN_FILES.filter(file => !tracked.has(file)) : [agyPlugin]) add(entry);
|
|
241
380
|
}
|
|
242
|
-
if (existsSync(join(cwd, JCODE_MCP_FILE)) && hubGitSync(["ls-files", "--error-unmatch", "--", JCODE_MCP_FILE], { cwd, encoding: "utf8", timeout: 3000 }).status !== 0
|
|
243
|
-
|
|
381
|
+
if (existsSync(join(cwd, JCODE_MCP_FILE)) && hubGitSync(["ls-files", "--error-unmatch", "--", JCODE_MCP_FILE], { cwd, encoding: "utf8", timeout: 3000 }).status !== 0) add(JCODE_MCP_FILE);
|
|
382
|
+
// #1496: append owned re-inclusions instead of changing project or outside ignore rules.
|
|
383
|
+
const track = settings?.values[TRACK_CONFIG];
|
|
384
|
+
let ignoreReason = track === false ? "ignore runtime state, machine-local configuration and the per-checkout hub config" : "ignore runtime state and machine-local configuration";
|
|
385
|
+
if (track === true) {
|
|
386
|
+
const tracked = SHARED_CONFIG.filter(name => !(name === "routing.toml" && routingMachineKeys(cwd).length));
|
|
387
|
+
const rules = tracked.map(name => ignoreRule(cwd, `.agenthub/${name}`));
|
|
388
|
+
const repository = sharedIgnoreRepository(cwd, rules.some(rule => rule === undefined));
|
|
389
|
+
if (repository && repository.root !== realPath(cwd)) {
|
|
390
|
+
for (const [index, rule] of rules.entries()) if (rule) {
|
|
391
|
+
const path = `.agenthub/${tracked[index]}`;
|
|
392
|
+
throw new Error(`--track-config: ${path} is ignored by ${rule}; change that line so git sees the file (after a directory rule such as .agenthub/, add !/.agenthub/, /.agenthub/* and !/${path}), then run ahub init again; nothing was written`);
|
|
393
|
+
}
|
|
394
|
+
if (routingMachineKeys(cwd).length) add(".agenthub/routing.toml");
|
|
395
|
+
} else {
|
|
396
|
+
const owned = sharedIgnoreBlock(lines);
|
|
397
|
+
if (rules.some(Boolean) || owned) {
|
|
398
|
+
const entries = ["!/.agenthub/", "/.agenthub/*", ...tracked.map(name => `!/.agenthub/${name}`)];
|
|
399
|
+
const eol = owned?.eol ?? (lines.includes("\r\n") ? "\r\n" : "\n");
|
|
400
|
+
const block = [SHARED_IGNORE_BEGIN, ...entries, SHARED_IGNORE_END].join(eol);
|
|
401
|
+
lines = owned
|
|
402
|
+
? lines.slice(0, owned.start) + block + (owned.newline ? eol : "") + lines.slice(owned.end)
|
|
403
|
+
: `${lines}${lines && !lines.endsWith("\n") ? eol : ""}${block}${eol}`;
|
|
404
|
+
const ruleClass = rules.some(rule => rule?.includes("/info/exclude:")) ? "repository info/exclude"
|
|
405
|
+
: rules.some(rule => rule && !rule.startsWith(".gitignore:") && !rule.startsWith(".agenthub/")) ? "global excludes" : "project ignore";
|
|
406
|
+
ignoreReason = `re-include shared config over ${ruleClass} rules in project .gitignore: ${entries.join(", ")}`;
|
|
407
|
+
} else if (routingMachineKeys(cwd).length) add(".agenthub/routing.toml");
|
|
408
|
+
verifySharedIgnores(cwd, lines, tracked, repository);
|
|
409
|
+
}
|
|
410
|
+
} else if (track === false) {
|
|
411
|
+
const owned = sharedIgnoreBlock(lines);
|
|
412
|
+
if (owned) lines = lines.slice(0, owned.start) + lines.slice(owned.end);
|
|
413
|
+
for (const name of SHARED_CONFIG) {
|
|
414
|
+
const entry = `.agenthub/${name}`;
|
|
415
|
+
// Existing owned negations must not suppress a new ignore line before the block is removed.
|
|
416
|
+
if (owned && !lines.split("\n").includes(entry)) lines += `${lines && !lines.endsWith("\n") ? "\n" : ""}${entry}\n`;
|
|
417
|
+
else add(entry);
|
|
418
|
+
}
|
|
419
|
+
if (owned) verifySharedIgnores(cwd, lines, [], sharedIgnoreRepository(cwd));
|
|
420
|
+
}
|
|
421
|
+
if (lines || existsSync(ignore)) write(ignore, lines, ignoreReason);
|
|
244
422
|
// #1065 T1: the settings table. config.json is the text it will have after the template and pack writes above; the rest is what is on disk.
|
|
245
423
|
let settingRows: InitSettingRow[] = [];
|
|
246
424
|
if (settings && (Object.keys(settings.values).length)) {
|
|
@@ -319,19 +497,56 @@ export function withInitResearch(cwd: string, request: InitSettingsRequest, mach
|
|
|
319
497
|
if (existsSync(join(cwd, ".agenthub", "config.json")) || Object.hasOwn(request.values, "research.enabled") || !initResearchDefault(cwd, machineValue)) return request;
|
|
320
498
|
return { ...request, values: { ...request.values, "research.enabled": true } };
|
|
321
499
|
}
|
|
500
|
+
/** Read only the bounded frontmatter prefix; a GSD archive is evidence, never an init input to execute or rewrite. */
|
|
501
|
+
function gsdPlanningState(cwd: string): boolean {
|
|
502
|
+
let fd: number | undefined;
|
|
503
|
+
try {
|
|
504
|
+
if (!lstatSync(join(cwd, ".planning")).isDirectory()) return false;
|
|
505
|
+
fd = openSync(join(cwd, ".planning", "STATE.md"), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
506
|
+
if (!fstatSync(fd).isFile()) return false;
|
|
507
|
+
const prefix = Buffer.alloc(4096), size = readSync(fd, prefix, 0, prefix.length, 0);
|
|
508
|
+
const header = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(prefix.toString("utf8", 0, size));
|
|
509
|
+
return !!header && /^gsd_state_version:[ \t]*["']?[0-9]+(?:\.[0-9]+)*["']?[ \t]*(?:#.*)?$/m.test(header[1]!);
|
|
510
|
+
} catch { return false; }
|
|
511
|
+
finally { if (fd !== undefined) closeSync(fd); }
|
|
512
|
+
}
|
|
322
513
|
/** Prepare person guidance before writes; the CLI prints it only after successful apply. Creates no lifecycle evidence or acceptance. */
|
|
323
514
|
export function initNextSteps(cwd: string, settings?: InitSettingsRequest): string[] {
|
|
324
|
-
const
|
|
325
|
-
"Next steps:",
|
|
326
|
-
"- Review and commit AGENTS.md, .agenthub/config.json and other shared init changes; keep config.local.json untracked.",
|
|
327
|
-
"- Start with ahub up or ahub claude; sessions started otherwise miss hub pushes.",
|
|
328
|
-
];
|
|
515
|
+
const track = settings?.values[TRACK_CONFIG];
|
|
329
516
|
const mode = settings?.values["sdlc.mode"] ?? loadSdlc(cwd, VERSION).mode;
|
|
517
|
+
const lines = ["Next steps:"];
|
|
518
|
+
// An ignore line does not untrack a file git already has: name the command that does.
|
|
519
|
+
const committed = (names: readonly string[]) => names.map(name => `.agenthub/${name}`).filter(path => hubGitSync(["ls-files", "--error-unmatch", "--", path], { cwd, encoding: "utf8", timeout: 3000 }).status === 0);
|
|
520
|
+
const untrack = (paths: string[]) => { if (paths.length) lines.push(`- ${paths.join(", ")} ${paths.length === 1 ? "is" : "are"} still committed: run git rm --cached ${paths.join(" ")} and commit, or git keeps tracking ${paths.length === 1 ? "it" : "them"}.`); };
|
|
521
|
+
const agentsPath = join(cwd, "AGENTS.md");
|
|
522
|
+
// The words follow the block's role sentence, so the next steps never contradict it (a project with neither flag whose config git ignores gets the untracked sentence).
|
|
523
|
+
if (track === false || track === undefined && !rolesTracked(cwd, existsSync(agentsPath) ? readFileSync(agentsPath, "utf8") : "", settings)) {
|
|
524
|
+
lines.push("- Review and commit AGENTS.md. .agenthub/config.json, routing.toml and sdlc.toml stay untracked: each checkout and each machine holds its own roles.");
|
|
525
|
+
untrack(committed(SHARED_CONFIG));
|
|
526
|
+
} else if (track === true) {
|
|
527
|
+
// #1411: the files to commit, and what must not go in with them.
|
|
528
|
+
const ignorePlan = planInit(cwd, undefined, false, false, settings).find(change => change.path === join(cwd, ".gitignore") && change.reason.startsWith("re-include"));
|
|
529
|
+
if (ignorePlan) lines.push(`- ${ignorePlan.reason}.`);
|
|
530
|
+
const endpoints = routingMachineKeys(cwd);
|
|
531
|
+
const files = SHARED_CONFIG.filter(name => !(name === "routing.toml" && endpoints.length) && (name !== "sdlc.toml" || existsSync(join(cwd, ".agenthub", name)) || mode !== "off"));
|
|
532
|
+
lines.push(`- Review and commit AGENTS.md and ${files.map(name => `.agenthub/${name}`).join(", ")}; keep config.local.json untracked.`);
|
|
533
|
+
if (endpoints.length) { lines.push(`- .agenthub/routing.toml stays untracked: ${endpoints.join(", ")} names this machine's endpoint, and routing.local.toml cannot hold it yet.`); untrack(committed(["routing.toml"])); }
|
|
534
|
+
const personal = personalValues(cwd);
|
|
535
|
+
if (personal.length) lines.push(`- Before the first commit, move ${personal.join(", ")} from .agenthub/config.json to .agenthub/config.local.json: they are this machine's values, and the hub ignores them in a committed config.json.`);
|
|
536
|
+
} else lines.push("- Review and commit AGENTS.md, .agenthub/config.json and other shared init changes; keep config.local.json untracked.");
|
|
537
|
+
lines.push(
|
|
538
|
+
"- Your own settings go in .agenthub/config.local.json; it wins over config.json key by key.",
|
|
539
|
+
"- Start with ahub up or ahub claude; sessions started otherwise miss hub pushes.",
|
|
540
|
+
);
|
|
541
|
+
// #1408 T2: what each role choice means, for a choice that changed nothing too (AC5: `none` and `person` are described, not only accepted).
|
|
542
|
+
lines.push(...roleSummaryLines(settings?.values ?? {}));
|
|
330
543
|
if (mode !== "off") lines.push(
|
|
331
544
|
`- SDLC ${mode}: accept the planner-recorded spec with ahub sdlc accept <task> --issue <n>.`,
|
|
332
545
|
"- When a plan departure needs your consent: ahub sdlc accept-departure <task> <head> <reason...>.",
|
|
333
546
|
"- After hub_task_done on the open PR, reviewer approval and green exact-head CI, use guarded merge: ahub sdlc merge <task>.",
|
|
334
547
|
);
|
|
548
|
+
if (["advise", "enforce"].includes(String(settings?.values["sdlc.mode"])) && gsdPlanningState(cwd))
|
|
549
|
+
lines.push("- GSD planning state found: see docs/sdlc.md#moving-from-gsd before migrating; archive .planning/ and retain its evidence.");
|
|
335
550
|
return lines;
|
|
336
551
|
}
|
|
337
552
|
/** Returns the paths it changed, applying the same plan as the preview. */
|
package/src/cli/main.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// Keep this entrypoint plain JavaScript: Node must fail before loading TypeScript or bun:sqlite.
|
|
3
3
|
const version = /^(\d+)\.(\d+)\.(\d+)$/.exec(process.versions.bun ?? "");
|
|
4
|
-
if (!version || !(Number(version[1]) > 1 || (Number(version[1]) === 1 && (Number(version[2]) > 4 || (Number(version[2]) === 4 && Number(version[3]) >=
|
|
5
|
-
console.error("ahub: Bun >=1.4.
|
|
4
|
+
if (!version || !(Number(version[1]) > 1 || (Number(version[1]) === 1 && (Number(version[2]) > 4 || (Number(version[2]) === 4 && Number(version[3]) >= 4))))) {
|
|
5
|
+
console.error("ahub: Bun >=1.4.4 is required. Install Bun: https://bun.sh");
|
|
6
6
|
process.exit(1);
|
|
7
7
|
}
|
|
8
8
|
|