@staix/agent-hub 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +10 -4
- package/docs/adding-an-ai-tool.md +1 -0
- package/docs/agent-notes/adapters.md +33 -4
- package/docs/agent-notes/budget.md +2 -1
- package/docs/agent-notes/daemon.md +5 -1
- package/docs/agent-notes/security-review.md +3 -2
- package/docs/agent-notes/tasks.md +3 -1
- package/docs/agent-notes/tests.md +1 -1
- package/docs/design/adapters.md +16 -0
- package/docs/design/agent-hub-architecture.md +12 -0
- package/docs/design/cli-output.md +2 -0
- package/docs/design/roadmap.md +86 -5
- package/docs/design/task-board.md +2 -2
- package/docs/dogfood.md +15 -0
- package/docs/events.md +2 -2
- package/docs/operations.md +102 -20
- package/docs/quickstart.md +9 -3
- package/docs/security.md +7 -5
- package/docs/smoke.md +1 -1
- package/docs/verification/2026-11-05-hardcoded-values-classification-rules.md +28 -0
- package/docs/verification/2026-11-22-agy-1.5.14.md +27 -0
- package/docs/verification/2026-11-22-claude-instruction-hook.md +35 -0
- package/docs/verification/2026-11-22-instructed-ipc.md +9 -0
- package/docs/verification/2026-11-22-jcode-1.0.3.md +71 -0
- package/docs/verification/2026-11-22-jcode-separate-home.md +14 -0
- package/docs/verification/2026-11-22-qwen-0283-acp.md +28 -0
- package/docs/verification/2026-11-22-qwen-0283-dual-output.md +33 -0
- package/docs/verification/2026-11-22-roadmap-r5-view-receipt.md +63 -0
- package/docs/verification/2026-11-23-0.46.0.md +44 -0
- package/docs/verification/assets/1483-r5-detail-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-detail-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-light.png +0 -0
- package/docs/verified.json +23 -23
- package/package.json +3 -2
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +5951 -5499
- package/plugins/agent-hub/server.js +1136 -1015
- package/plugins/agent-hub/skills/ahub/SKILL.md +17 -0
- package/plugins/agent-hub/skills/ahub-manage/SKILL.md +37 -0
- package/plugins/agent-hub/skills/ahub-status/SKILL.md +14 -0
- package/plugins/agent-hub/skills/ahub-use/SKILL.md +12 -0
- package/src/adapters/claude-channel.ts +2 -1
- package/src/adapters/compat.ts +12 -11
- package/src/adapters/definitions/native-cli-claude-setup.ts +9 -1
- package/src/adapters/definitions/native-cli-doctor.ts +8 -5
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +158 -0
- package/src/adapters/definitions/native-cli-jcode-home.ts +72 -0
- package/src/adapters/definitions/native-cli-jcode-mcp.ts +20 -0
- package/src/adapters/definitions/native-cli-skills.ts +29 -0
- package/src/cli/claude-profile-hook.ts +40 -3
- package/src/cli/console-state.ts +55 -26
- package/src/cli/console-usage.ts +5 -3
- package/src/cli/console.ts +35 -4
- package/src/cli/help.ts +15 -10
- package/src/cli/identity.ts +2 -1
- package/src/cli/instruction-hook.ts +28 -0
- package/src/cli/jcode-mcp.ts +2 -1
- package/src/cli/main.js +8 -0
- package/src/cli/main.ts +138 -18
- package/src/cli/output-standard.ts +3 -55
- package/src/cli/output.ts +8 -2
- package/src/cli/recovery-package.ts +47 -11
- package/src/cli/roadmap.ts +37 -3
- package/src/cli/setup-homes.ts +1 -0
- package/src/cli/setup.ts +1 -1
- package/src/cli/skills-install.ts +463 -0
- package/src/cli/task-output.ts +1 -1
- package/src/cli/upgrade-presentation-flags.ts +1 -1
- package/src/hub/board.ts +42 -4
- package/src/hub/budget-projection.ts +99 -0
- package/src/hub/claude-launch-proof.ts +5 -1
- package/src/hub/conductor.ts +8 -3
- package/src/hub/config-apply.ts +3 -2
- package/src/hub/config-tier.ts +1 -1
- package/src/hub/config-trust.ts +1 -1
- package/src/hub/control-client.ts +9 -2
- package/src/hub/daemon.ts +457 -26
- package/src/hub/events.ts +1 -1
- package/src/hub/execution-budget.ts +29 -8
- package/src/hub/hub-tools.ts +2 -2
- package/src/hub/inference.ts +1 -1
- package/src/hub/instances.ts +10 -1
- package/src/hub/instructed-exact.ts +95 -0
- package/src/hub/instructed-intent.ts +64 -0
- package/src/hub/instructed-ipc.ts +33 -0
- package/src/hub/instructed-runtime.ts +19 -0
- package/src/hub/instruction-receipt.ts +218 -0
- package/src/hub/manager.ts +46 -3
- package/src/hub/registry.ts +1 -1
- package/src/hub/roadmap-decompose.ts +60 -1
- package/src/hub/roadmap-sync.ts +2 -2
- package/src/hub/roadmap.ts +19 -1
- package/src/hub/routing.ts +18 -1
- package/src/hub/runtime-capture-prune.ts +2 -1
- package/src/hub/settings.ts +2 -1
- package/src/hub/tasks.ts +194 -12
- package/src/hub/ui.ts +6 -2
- package/src/hub/usage-rollup.ts +42 -2
- package/src/ui/index.html +342 -8
- package/src/ui/plugin.ts +6 -2
- package/src/ui/roadmap-model.ts +70 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ahub
|
|
3
|
+
description: Carry out the person's supported hub instruction, or prepare their person step when it cannot be admitted.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Person control
|
|
8
|
+
|
|
9
|
+
The person's prompt is exact when its arguments begin with `run`: the rest is the exact `ahub` command without the `ahub` word. Otherwise it is an intent prompt: choose only supported commands that carry out what the person actually asked. Do not infer additional work. Inspect `ahub help <command>` and current public state as needed to identify prior state and an undo command. Do not guess a prior value or identifier.
|
|
10
|
+
|
|
11
|
+
For an exact prompt, run `ahub instructed run` once in this Claude session without additional arguments. Never replace or reinterpret that command. For an intent prompt, pass the selected `ahub` command and its arguments after `ahub instructed run`; the daemon confirms the person's receipt and admits only its closed intent list. A person verdict requires the item's literal id in the person's prompt. Spending settings, permission, trust, machine-local paths, irreversible deletion, release, merge, identity and private work stay closed. If the mode, receipt, command or runtime cannot admit an operation, prepare the person's command as a person step instead; never impersonate the person.
|
|
12
|
+
|
|
13
|
+
Only text the person typed in an exact command can be published through the screened creation and planning forms. For a successful exact local title change, use the returned previous title as the person-run undo. Never author public text from an intent prompt; ask the person to run the command in a terminal when the requested creation form is not admitted.
|
|
14
|
+
|
|
15
|
+
The admitted intent forms are `task assign`, `backlog pull` and `return`, `stop`, `model set` and `clear`, `results`, `capabilities`, `learn list`, `learn accept` and `reject`, a user-reviewer `review`, `roadmap state <id> done` or `dropped` (a final verdict: the milestone id literally in the prompt, no undo), and `task claim` without a manifest. A claim verdict requires both the task id and claim slot literally in the person's prompt. Ask the daemon rather than guessing whether an operation is admitted; retain its refusal as the person's next step.
|
|
16
|
+
|
|
17
|
+
End the turn with each instructed operation and its undo. For a person verdict, say "no undo"; do not invent one. If any other undo cannot be established, say so without inventing one. For each person step, give one line explaining what the command does and why the person runs it; then its complete command in its own code block, starting with `cd` to the quoted absolute project directory and including every flag and actual id; then one line describing success. Number multiple steps in execution order. Never print placeholders, partial commands or guessed identifiers. Preserve any exact command supplied by a hub refusal.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ahub-manage
|
|
3
|
+
description: Diagnose and maintain agent-hub setup, upgrades, peers, queues and stalled work within existing authority.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Hub management
|
|
7
|
+
|
|
8
|
+
Use `ahub help` for exact current forms and hub tool descriptions for tool authority. Identify the selected project and inspect state before a write. Labels below do not grant authority; honor refusals and required confirmations.
|
|
9
|
+
|
|
10
|
+
## Setup and doctor
|
|
11
|
+
|
|
12
|
+
1. Any agent: read `ahub doctor --json` and the latest setup output. Inspect each finding and its complete suggested command. For `jcode MCP servers`, inspect the named configuration sources and their server names; never remove a server without the person's decision.
|
|
13
|
+
2. Any agent: read `ahub agents --json` for a version-refused CLI. Person: if they decide to trust the actual installed version, run `ahub agents trust <id> <version>`; obtain both values from the reading and explain that runtime proofs still apply.
|
|
14
|
+
3. Person: run `ahub setup` when the findings require plugin or hook installation, then any agent reruns `ahub doctor --json` to verify. Setup writes configuration; do not run it merely to read findings.
|
|
15
|
+
|
|
16
|
+
## Upgrade and restart
|
|
17
|
+
|
|
18
|
+
1. Any agent: inspect `ahub upgrade --dry-run` or `ahub restart --dry-run` and resolve blockers; check `ahub status --full` and recovery status before acting.
|
|
19
|
+
2. Person: run the appropriate interactive `ahub upgrade` or `ahub restart`. A configured conductor may use `ahub upgrade --to <version> --yes` or `ahub restart --yes` only with the required same-project continuation proof; otherwise the person runs it. Check status and recovery afterward.
|
|
20
|
+
|
|
21
|
+
## Roster and pauses
|
|
22
|
+
|
|
23
|
+
1. Any agent: inspect `ahub roster --json` and `ahub status --full` for participation, pause and retained work.
|
|
24
|
+
2. Conductor or person: for a delivery pause, use `ahub resume <peer>` after identifying the actual peer. Use `ahub roster add <peer>` or `ahub roster remove <peer>` only after inspecting retained work and the preview; removal with `--now` can stop busy work. Budget pauses have separate `ahub budget resume <peer>` authority and semantics; check help first.
|
|
25
|
+
|
|
26
|
+
## Queue repair
|
|
27
|
+
|
|
28
|
+
1. Any agent: read `ahub queue list --all --json` for full delivery IDs and state.
|
|
29
|
+
2. Conductor or person: inspect the exact item with `ahub queue show <delivery-id> --json`, including its revision. Decide the disposition from evidence, then use `ahub queue resolve <delivery-id> --action completed|retry|discard --reason <text> --revision <N>` with actual values. Never guess or retry blindly.
|
|
30
|
+
|
|
31
|
+
## Stalled tasks and sessions
|
|
32
|
+
|
|
33
|
+
1. Any agent: inspect `ahub task show <id>` and `ahub route explain <id>` for dependencies, reservation, eligibility and decline history. For no eligible peer report the named reason; do not assume availability.
|
|
34
|
+
2. Person: if a declined peer should be assigned again, run `ahub task assign <id> <peer>` using the actual task and peer; verify with `ahub task show <id>`. Respect the board's revision and authority refusals.
|
|
35
|
+
3. Any agent: use `ahub-status` to distinguish the installed plugin from the server each session actually runs. Person: restart a stale Claude session through the hub launcher after checking its retained work and recovery instructions; verify its version on reconnect.
|
|
36
|
+
|
|
37
|
+
When a person must run a step, output one line explaining what the command does and why the person runs it, a separate code block with the complete command beginning with `cd` to the quoted absolute project directory and all flags and actual IDs, and one line describing success. Number multiple steps in order. Read unknown values first; never print placeholders or shortened commands. Respect any refusal's exact command.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ahub-status
|
|
3
|
+
description: Inspect agent-hub versions, running sessions, health and peers without changing state.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Hub status
|
|
7
|
+
|
|
8
|
+
Work read-only in the selected project. Run `ahub version`, `ahub status --json`, `ahub doctor --json`, `ahub roster --json`, and `claude plugin list --json`. Compare the CLI version, daemon `version` in `ahub status --json`, installed user plugin version and each connected Claude client's reported version. Identify peers and their states; report unavailable or absent version evidence as unknown.
|
|
9
|
+
|
|
10
|
+
List all `ahub` executables on PATH and resolve their paths, then inspect their package versions without executing an untrusted alternate. Inspect the process table for each open Claude session and its agent-hub `server.js` child and parent. For a session attached to this hub, read `peerVersions.<peer>.ahubTools` in `ahub status --json` for the connected tools client's version. Match the peer and session; if multiple versions prevent a match, report unknown. For any other session, compare the server process start time with the installation time of the directory its path currently resolves to. If the process started earlier, it runs an older build; identify that build only when the previous installation can be established, otherwise report its version unknown. A current symlink's manifest cannot establish a surviving process's loaded version. Report mismatches, unknowns and doctor findings separately.
|
|
11
|
+
|
|
12
|
+
For a stale session, give the person a step to restart that Claude session with the hub launcher: inspect `ahub help claude`, retained work and any recovery state first, then produce the actual launcher or resume command for that session. The person runs it because restarting their session is an operator action. Success is a reattached session whose reported tools version matches the intended installation; if that cannot be observed, say unknown.
|
|
13
|
+
|
|
14
|
+
For a repair, do not run it here. Give the person one line saying what it does and why they must run it, then a separate code block with the complete command starting with `cd` to the quoted absolute project directory, all flags and actual IDs, then one line describing success. Resolve every value from current evidence; never output placeholders. If a value is unknown, find it or state what is missing instead of giving a command. Use the repair printed by doctor, and verify its applicability before presenting it.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ahub-use
|
|
3
|
+
description: Use the agent-hub board, handoffs, evidence, memory and review workflow.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Use the hub
|
|
7
|
+
|
|
8
|
+
Read the project AGENTS.md and your assigned roles. Inspect the board before accepting assigned work or proposing a claim; include the paths and concrete plan. Follow the task's spec and worktree rules. File completion with the exact full head and verification evidence; inspect and address review threads first. Review only when assigned and within the recorded scope.
|
|
9
|
+
|
|
10
|
+
Use `hub_task_handoff` for work belonging to another hub project, with a spec issue for behavior changes. Use `hub_ask` for an evidence-backed answer and verify cited ids; do not treat model answers as evidence. Use `hub_remember` for durable decisions or failures when permitted, and respect private-turn restrictions. Consult the tool descriptions and `ahub help <command>` for current authority and forms.
|
|
11
|
+
|
|
12
|
+
If a person must run a step, give one line explaining what it does and why the person runs it, a separate code block beginning with `cd` to the quoted absolute project directory and containing the complete command with actual ids and flags, and one line stating the success result. Number multiple steps. Find missing values first; never print placeholders or shortened commands. Pass a refusal's command exactly as printed.
|
|
@@ -259,7 +259,8 @@ async function withPendingHint<T>(result: T, recommendInbox = true): Promise<T>
|
|
|
259
259
|
async function push(envs: Envelope[], deliveryId?: string, generation?: string): Promise<void> {
|
|
260
260
|
const parent = replyParent(envs); // reply_to on this id keeps the hop count honest
|
|
261
261
|
const single = envs.length === 1;
|
|
262
|
-
const
|
|
262
|
+
const channelBody = (body: string) => { const safe = sanitize(body); return safe.startsWith("/") ? `\\${safe}` : safe; };
|
|
263
|
+
const content = single ? channelBody(parent.body) : envs.map((e) => `--- from ${e.from} (id ${e.id}, kind ${e.kind}) ---\n${channelBody(e.body)}`).join("\n\n");
|
|
263
264
|
const meta = {
|
|
264
265
|
source: single ? parent.from : "hub-digest",
|
|
265
266
|
...(single ? {} : { sources: [...new Set(envs.map((e) => e.from))].join(",") }),
|
package/src/adapters/compat.ts
CHANGED
|
@@ -54,24 +54,25 @@ export const COMPAT = {
|
|
|
54
54
|
parse: out => plain(out.trim()),
|
|
55
55
|
trustNote: "Only 2.5.2 has a live receipt for turn.prompt/turn.ended/prompt completion rows, background task inventory and launcher-bound plugin hooks. Another version keeps completion receipts disabled.",
|
|
56
56
|
receipt: "docs/verification/2026-11-08-kimi-tui-completion-1282.md" },
|
|
57
|
-
jcode: { label: "Jcode", verified: ["0.98.1", "0.99.0", "0.99.1"], line: { min: "0.98.0", below: "1.
|
|
57
|
+
jcode: { label: "Jcode", verified: ["0.98.1", "0.99.0", "0.99.1", "1.0.3"], line: { min: "0.98.0", below: "1.1.0" }, gate: "contract", probe: ["jcode", "--quiet", "version", "--json"], config: "jcode_cmd",
|
|
58
58
|
parse: out => { try { const v = JSON.parse(out).semver; return typeof v === "string" ? plain(v) : undefined; } catch { return undefined; } },
|
|
59
|
-
trustNote: "The ACP, serve and MCP contract was verified on 0.98.1
|
|
60
|
-
receipt: "docs/verification/2026-
|
|
59
|
+
trustNote: "The ACP, serve and MCP contract was verified on 0.98.1, 0.99.1 and 1.0.3, steering on 0.99.0, 0.99.1 and 1.0.3, and a hub delivery was acknowledged on 1.0.3; an untested version inside the line may change them. A real account, provider or model, the TUI form and Linux builds stay unverified.",
|
|
60
|
+
receipt: "docs/verification/2026-11-22-jcode-1.0.3.md" },
|
|
61
61
|
agy: { label: "agy", verified: ["1.4.2", "1.4.7", "1.4.12", "1.5.3"], line: { min: "1.4.0", below: "1.5.0" }, gate: "contract", probe: ["agy", "--version"],
|
|
62
62
|
parse: out => plain(out.trim()),
|
|
63
63
|
trustNote: "Exact 1.5.3 repeats the account-free CLI/plugin MCP, hooks, normal close and actual-launcher nonce legs; existing 1.4.x verified receipts remain unchanged. Other 1.5.x versions, real model/account behavior, headless ACP and native permission mappings remain unverified.",
|
|
64
64
|
receipt: "docs/verification/2026-11-08-agy-1.5.3.md" },
|
|
65
|
-
|
|
65
|
+
// Receipt: docs/verification/2026-11-22-qwen-0283-acp.md (0.27.1 and 0.28.3).
|
|
66
|
+
qwen: { label: "Qwen Code", verified: ["0.25.0", "0.26.0", "0.26.1", "0.26.4", "0.26.5", "0.26.8", "0.26.9", "0.27.0", "0.27.1", "0.28.3"], gate: "contract", probe: ["qwen", "--version"], config: "qwen_cmd",
|
|
66
67
|
parse: out => plain(out.trim()),
|
|
67
|
-
trustNote: "Native ACP identity, mode ids and permission callbacks were re-checked without inference on 0.26.4, 0.26.5 and 0.26.8 (macOS arm64 and Linux x86_64); exact 0.26.9
|
|
68
|
-
receipt: "docs/verification/2026-11-
|
|
69
|
-
// Receipt: docs/verification/2026-11-
|
|
70
|
-
// the ACP receipts of the headless `qwen` entry say nothing about it, so
|
|
71
|
-
"qwen-dual": { label: "Qwen Code dual-output TUI", verified: ["0.26.1", "0.27.0", "0.27.1"], gate: "contract", probe: ["qwen", "--version"], config: "qwen_cmd",
|
|
68
|
+
trustNote: "Native ACP identity, mode ids and permission callbacks were re-checked without inference on 0.26.4, 0.26.5 and 0.26.8 (macOS arm64 and Linux x86_64); exact 0.26.9, 0.27.0, 0.27.1 and 0.28.3 repeat those account-free probes on macOS arm64. Real model turns and Linux repetition of those versions remain unverified. The historical A/B/B setter result did not identify the third request's purpose. Exact 0.26.9 and 0.27.0 pass isolated suggestions-off A/B/clear/A probes; production live-setter admission stays unavailable pending a separate decision. Another version may change those contracts.",
|
|
69
|
+
receipt: "docs/verification/2026-11-22-qwen-0283-acp.md" },
|
|
70
|
+
// Receipt: docs/verification/2026-11-22-qwen-0283-dual-output.md. The dual-output contract (input file, event file, can_use_tool control requests) is its own entry:
|
|
71
|
+
// the ACP receipts of the headless `qwen` entry say nothing about it, so this entry carries its own exact versions and no `line`.
|
|
72
|
+
"qwen-dual": { label: "Qwen Code dual-output TUI", verified: ["0.26.1", "0.27.0", "0.27.1", "0.28.3"], gate: "contract", probe: ["qwen", "--version"], config: "qwen_cmd",
|
|
72
73
|
parse: out => plain(out.trim()),
|
|
73
|
-
trustNote: "Exact 0.27.0
|
|
74
|
-
receipt: "docs/verification/2026-11-
|
|
74
|
+
trustNote: "Exact 0.27.0, 0.27.1 and 0.28.3 each repeat normal-Bus Q2 and account-free normal-mode Q3/Q5/Q6/Q7 on macOS arm64 against a matched control. Existing deny and external-stop limits remain. Real model/account turns, Linux and lifetime containment remain unverified; direct busy-submit characterization is separate from normal-Bus Q2.",
|
|
75
|
+
receipt: "docs/verification/2026-11-22-qwen-0283-dual-output.md" },
|
|
75
76
|
} as const satisfies Record<string, CompatPolicy>;
|
|
76
77
|
export type CompatId = keyof typeof COMPAT;
|
|
77
78
|
type CommandConfig = { codex_bin: string; jcode_cmd: string[]; qwen_cmd: string[]; pi?: { cmd: string[] } };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { stablePackageRoot } from "../../cli/install-paths.ts";
|
|
@@ -6,6 +6,14 @@ import { realPath } from "../../hub/project.ts";
|
|
|
6
6
|
import { VERSION } from "../../version.ts";
|
|
7
7
|
|
|
8
8
|
export const PLUGIN = "agent-hub@agent-hub";
|
|
9
|
+
export const HUB_SKILL_NAMES = ["ahub-status", "ahub-manage", "ahub-use", "ahub"] as const;
|
|
10
|
+
|
|
11
|
+
export function hubSkillsPresent(plugins: InstalledPlugin[]): boolean {
|
|
12
|
+
const installed = plugins.find(plugin => plugin.id === PLUGIN && plugin.scope === "user");
|
|
13
|
+
return !!installed?.installPath && HUB_SKILL_NAMES.every(name =>
|
|
14
|
+
existsSync(join(installed.installPath!, "skills", name, "SKILL.md")));
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
export const CLAUDE_PLUGIN_INVENTORY = Object.freeze({
|
|
10
18
|
plugins: Object.freeze(["claude", "plugin", "list", "--json"]),
|
|
11
19
|
marketplaces: Object.freeze(["claude", "plugin", "marketplace", "list", "--json"]),
|
|
@@ -63,21 +63,24 @@ export function nativeDoctorRecoveryIdentity(peer: { id: string; state: string;
|
|
|
63
63
|
|
|
64
64
|
export type NativeDoctorOptionalProbe =
|
|
65
65
|
| { kind: "source-identity"; name: string; command: string[]; detail: string }
|
|
66
|
-
| { kind: "jcode-mcp"; name: string; home: string }
|
|
66
|
+
| { kind: "jcode-mcp"; name: string; home: string; allow?: string[] }
|
|
67
67
|
| { kind: "pinned-version"; name: string; command: string[]; compat: CompatId; confirmed: string; unconfirmed: string };
|
|
68
68
|
|
|
69
|
+
/** The allowlist rides on the probe only when the person set one (#1621). */
|
|
70
|
+
const allowField = (allow: readonly string[] | undefined): { allow?: string[] } => allow?.length ? { allow: [...allow] } : {};
|
|
71
|
+
|
|
69
72
|
/** The host runs these existing checks in order; no process, filesystem or caller callback enters this planner. */
|
|
70
|
-
export function nativeDoctorOptionalProbes(config: { roster: Readonly<Record<string, boolean | undefined>>; jcode_cmd: string[]; qwen_cmd: string[]; jcode_home?: string;
|
|
73
|
+
export function nativeDoctorOptionalProbes(config: { roster: Readonly<Record<string, boolean | undefined>>; jcode_cmd: string[]; qwen_cmd: string[]; jcode_home?: string; jcode_mcp_allow?: string[];
|
|
71
74
|
/** Declared extra instances (#685): a rostered Jcode instance's own home is inventoried like the base home. */
|
|
72
|
-
instances?: Readonly<Record<string, { kind: string; jcode_home?: string }>> }): NativeDoctorOptionalProbe[] {
|
|
75
|
+
instances?: Readonly<Record<string, { kind: string; jcode_home?: string; jcode_mcp_allow?: string[] }>> }): NativeDoctorOptionalProbe[] {
|
|
73
76
|
const probes: NativeDoctorOptionalProbe[] = [];
|
|
74
77
|
if (config.roster.jcode === true) probes.push({ kind: "source-identity", name: "jcode", command: config.jcode_cmd,
|
|
75
78
|
detail: "CLI/source identity only; provider, project MCP and native teardown require separate receipts; native policy unmanaged" });
|
|
76
79
|
// #572 AC4: jcode cannot be told which MCP servers to load, so the host lists the ones its config files name.
|
|
77
|
-
if (config.roster.jcode === true && config.jcode_home) probes.push({ kind: "jcode-mcp", name: "jcode MCP servers", home: config.jcode_home });
|
|
80
|
+
if (config.roster.jcode === true && config.jcode_home) probes.push({ kind: "jcode-mcp", name: "jcode MCP servers", home: config.jcode_home, ...allowField(config.jcode_mcp_allow) });
|
|
78
81
|
// #685: each extra instance has its own home, hence its own inventory. Names and homes only: no model source, URL or token.
|
|
79
82
|
for (const [id, declaration] of Object.entries(config.instances ?? {})) {
|
|
80
|
-
if (declaration.kind === "jcode" && declaration.jcode_home && config.roster[id] === true) probes.push({ kind: "jcode-mcp", name: `${id} MCP servers`, home: declaration.jcode_home });
|
|
83
|
+
if (declaration.kind === "jcode" && declaration.jcode_home && config.roster[id] === true) probes.push({ kind: "jcode-mcp", name: `${id} MCP servers`, home: declaration.jcode_home, ...allowField(declaration.jcode_mcp_allow ?? config.jcode_mcp_allow) });
|
|
81
84
|
}
|
|
82
85
|
if (config.roster.qwen === true) probes.push({ kind: "pinned-version", name: "qwen", command: config.qwen_cmd, compat: "qwen",
|
|
83
86
|
confirmed: "CLI version verified; native ACP identity/modes and provider access require a separate live check",
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { assessVersion, COMPAT, configuredCommands, isCompatId, type CompatId } from "../compat.ts";
|
|
5
|
+
import { applyJcodeHome, hubJcodeHomePath, jcodeLoginCommand, jcodeOwnHome, planJcodeHome, sameJcodeHome, type JcodeHomePlan } from "./native-cli-jcode-home.ts";
|
|
6
|
+
import { jcodeExtraMcpServers, splitJcodeMcpServers } from "./native-cli-jcode-mcp.ts";
|
|
7
|
+
import { agentVersions } from "../../cli/agents.ts";
|
|
8
|
+
import { editJsonText } from "../../cli/init-settings.ts";
|
|
9
|
+
import { applySkillPlan, applySkillUndo, skillHostStates, skillInstallPlan, skillUndoPlan, type SkillEntry, type SkillHostState } from "../../cli/skills-install.ts";
|
|
10
|
+
import { configRefusal } from "../../hub/config-trust.ts";
|
|
11
|
+
import { idFor } from "../../hub/registry.ts";
|
|
12
|
+
import { projectRoot } from "../../hub/project.ts";
|
|
13
|
+
import { startModeOf } from "../../hub/start-mode.ts";
|
|
14
|
+
import type { HubConfig } from "../../hub/daemon.ts";
|
|
15
|
+
import { shellQuote } from "../../cli/shell-quote.ts";
|
|
16
|
+
|
|
17
|
+
/** Whether init should offer the hub-owned home: jcode is installed or rostered, and `jcode_home` is unset or the person's own. */
|
|
18
|
+
export function jcodeHomeApplicable(config: Pick<HubConfig, "jcode_home" | "roster" | "jcode_cmd">, env: NodeJS.ProcessEnv, installed: boolean, user = homedir()): boolean {
|
|
19
|
+
if (!installed && config.roster.jcode !== true) return false;
|
|
20
|
+
return sameJcodeHome(config.jcode_home, jcodeOwnHome(env, user));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface JcodeHomeInit { applicable: boolean; plan?: JcodeHomePlan; lines: string[]; /** Write `jcode_home` now: the hub-owned home exists, holds a login, and the project still points at the person's own home. */ switchHome?: boolean }
|
|
24
|
+
|
|
25
|
+
/** What `ahub init` would do for the hub-owned jcode home. Reads only; never writes the person's home. */
|
|
26
|
+
export function planJcodeHomeInit(input: { cwd: string; stateDir: string; bundle: string; hubHome: string; config: HubConfig; env: NodeJS.ProcessEnv; installed: boolean; user?: string }): JcodeHomeInit {
|
|
27
|
+
const { cwd, stateDir, bundle, hubHome, config, env, installed } = input, user = input.user ?? homedir();
|
|
28
|
+
const own = jcodeOwnHome(env, user);
|
|
29
|
+
const configured = !sameJcodeHome(config.jcode_home, own);
|
|
30
|
+
// A project that already names a separate home keeps it: init checks that home for drift and creates nothing.
|
|
31
|
+
if (!configured && !jcodeHomeApplicable(config, env, installed, user)) return { applicable: false, lines: [] };
|
|
32
|
+
const home = configured ? config.jcode_home : hubJcodeHomePath(hubHome, idFor(projectRoot(cwd)));
|
|
33
|
+
const plan = planJcodeHome({ home, own, cwd, stateDir, bundle, allow: config.jcode_mcp_allow ?? [] });
|
|
34
|
+
const lines: string[] = [];
|
|
35
|
+
const loggedIn = !!lstatSync(join(home, "auth.json"), { throwIfNoEntry: false });
|
|
36
|
+
const switchHome = plan.exists && !configured && loggedIn;
|
|
37
|
+
if (plan.exists) {
|
|
38
|
+
lines.push(`jcode home ${home}: ${plan.drift.length ? "drift" : "up to date"}`);
|
|
39
|
+
for (const drift of plan.drift) lines.push(` ${drift}`);
|
|
40
|
+
if (switchHome) lines.push(` modify .agenthub/config.local.json: jcode_home -> ${home} (it now holds a login)`);
|
|
41
|
+
else if (!configured) lines.push(` jcode_home stays your own home until ${home} holds a login; then run: cd ${shellQuote(cwd)} && ahub init`);
|
|
42
|
+
} else {
|
|
43
|
+
lines.push(`create ${home}: hub-owned jcode home (mcp.json with agent-hub-jcode${Object.keys(plan.servers).length > 1 ? ` and ${Object.keys(plan.servers).filter(name => name !== "agent-hub-jcode").join(", ")}` : ""}; no sessions, history or login copied)`);
|
|
44
|
+
if (plan.absentAllowed.length) lines.push(` jcode_mcp_allow names ${plan.absentAllowed.join(", ")}, which ${join(own, "mcp.json")} does not define: nothing to copy`);
|
|
45
|
+
lines.push(` jcode_home is left unchanged: a new home has no login, and switching would break a working jcode`);
|
|
46
|
+
lines.push(` person steps: ${jcodeLoginCommand(home)} then: cd ${shellQuote(cwd)} && ahub init`);
|
|
47
|
+
lines.push(` provider and model defaults live in your own config.toml ([provider], [providers.*]); they are not copied, so set them in ${join(home, "config.toml")} or pass --provider-profile`);
|
|
48
|
+
}
|
|
49
|
+
return { applicable: true, plan, lines, switchHome };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Set `jcode_home` in the untracked local config, keeping every other byte. Refuses a tracked or unreadable file. */
|
|
53
|
+
export function writeJcodeHomeConfig(cwd: string, home: string): void {
|
|
54
|
+
const file = join(cwd, ".agenthub", "config.local.json");
|
|
55
|
+
const refusal = configRefusal(cwd, "config.local.json");
|
|
56
|
+
if (refusal) throw new Error(`jcode_home was not written: ${refusal}; move it to an untracked .agenthub/config.local.json`);
|
|
57
|
+
const text = existsSync(file) ? readFileSync(file, "utf8") : "{}\n";
|
|
58
|
+
const next = editJsonText(text, ["jcode_home"], home);
|
|
59
|
+
if (next === text) return;
|
|
60
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
61
|
+
try { writeFileSync(temporary, next, { mode: 0o600, flag: "wx" }); renameSync(temporary, file); }
|
|
62
|
+
finally { if (existsSync(temporary)) unlinkSync(temporary); }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Install the hub skills into one jcode home, under the marker contract; only the jcode host is touched. */
|
|
66
|
+
export function installSkillsInJcodeHome(source: string, home: string): SkillEntry[] {
|
|
67
|
+
const paths = { home: homedir(), env: { ...process.env, JCODE_HOME: home } };
|
|
68
|
+
const plan = skillInstallPlan(source, paths).filter(entry => entry.host === "jcode");
|
|
69
|
+
return applySkillPlan(source, plan).filter(entry => entry.host === "jcode");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Every jcode home the hub owns besides the person's: the configured `jcode_home` and each instance's. */
|
|
73
|
+
export function jcodeSkillHomes(config: Pick<HubConfig, "jcode_home" | "instances">, env: NodeJS.ProcessEnv, user = homedir()): string[] {
|
|
74
|
+
const own = jcodeOwnHome(env, user), homes = new Set<string>();
|
|
75
|
+
if (!sameJcodeHome(config.jcode_home, own)) homes.add(config.jcode_home);
|
|
76
|
+
for (const declaration of Object.values(config.instances ?? {})) if (declaration.kind === "jcode" && declaration.jcode_home) homes.add(declaration.jcode_home);
|
|
77
|
+
return [...homes];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* `ahub setup`'s skill step for the hub-owned jcode homes (#1627 AC1b): the same marker contract as the other hosts, only the jcode host, one home at a time.
|
|
82
|
+
* A tree the person edited, a foreign tree and a link are reported and left alone, exactly as for the shell's home.
|
|
83
|
+
*/
|
|
84
|
+
export async function installHubSkillsInJcodeHomes(options: { source?: string; homes: readonly string[]; undo?: boolean; yes: boolean; ask?: (prompt: string) => Promise<string | null>; print: (line: string) => void }): Promise<void> {
|
|
85
|
+
for (const home of options.homes) {
|
|
86
|
+
const paths = { home: homedir(), env: { ...process.env, JCODE_HOME: home } };
|
|
87
|
+
const label = `hub skills (hub-owned jcode home ${home})`;
|
|
88
|
+
const asked = async (prompt: string): Promise<boolean> => {
|
|
89
|
+
if (options.yes) return true;
|
|
90
|
+
const answer = options.ask ? await options.ask(prompt) : null;
|
|
91
|
+
return typeof answer === "string" && /^y(es)?$/i.test(answer.trim());
|
|
92
|
+
};
|
|
93
|
+
if (options.undo) {
|
|
94
|
+
const plan = skillUndoPlan(paths).filter(entry => entry.host === "jcode"), removable = plan.filter(entry => entry.action === "remove");
|
|
95
|
+
if (!removable.length) { options.print(`${label}: nothing to remove`); continue; }
|
|
96
|
+
if (!(await asked(`Remove ${removable.length} hub skill tree(s) from ${home}? [y/N] `))) { options.print(`${label}: nothing removed; rerun with --yes`); continue; }
|
|
97
|
+
const done = applySkillUndo(plan).filter(entry => entry.host === "jcode");
|
|
98
|
+
options.print(`${label}: ${done.filter(entry => entry.action === "removed").length} removed, ${done.filter(entry => entry.action === "failed").length} failed`);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (!options.source) continue;
|
|
102
|
+
let plan: SkillEntry[];
|
|
103
|
+
try { plan = skillInstallPlan(options.source, paths).filter(entry => entry.host === "jcode"); }
|
|
104
|
+
catch (error) { options.print(`${label}: skipped (${(error as Error).message})`); continue; }
|
|
105
|
+
const hostLevel = plan.find(entry => !entry.skill);
|
|
106
|
+
if (hostLevel) { options.print(`${label}: ${hostLevel.action} (${hostLevel.detail})`); continue; }
|
|
107
|
+
const writable = plan.filter(entry => entry.action === "install" || entry.action === "replace");
|
|
108
|
+
if (!writable.length) { options.print(`${label}: up to date${plan.some(entry => ["modified", "foreign", "linked", "failed"].includes(entry.action)) ? "; some trees are left untouched" : ""}`); continue; }
|
|
109
|
+
if (!(await asked(`Install hub skills into ${home}? [y/N] `))) { options.print(`${label}: nothing written; rerun with --yes`); continue; }
|
|
110
|
+
const done = applySkillPlan(options.source, plan);
|
|
111
|
+
options.print(`${label}: ${done.filter(entry => entry.action === "install").length} installed, ${done.filter(entry => entry.action === "replace").length} replaced, ${done.filter(entry => entry.action === "failed").length} failed`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The doctor's read of the hub skills in the hub-owned homes, one state per home, nothing written. */
|
|
116
|
+
export function jcodeHomeSkillStates(homes: readonly string[], expected: readonly string[]): (SkillHostState & { home: string })[] {
|
|
117
|
+
return homes.map(home => ({ home, ...skillHostStates({ home: homedir(), env: { ...process.env, JCODE_HOME: home } }, expected).find(state => state.host === "jcode")! }));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface RosterFinding { text: string; fix?: string }
|
|
121
|
+
/** The preflight `ahub roster add` prints for every kind (#1627 B): CLI path and version, start mode, and the kind's own checks, each with a complete fix. */
|
|
122
|
+
export function rosterPreflight(peer: string, kind: string, cwd: string, config: HubConfig, env: NodeJS.ProcessEnv, user = homedir()): RosterFinding[] {
|
|
123
|
+
const out: RosterFinding[] = [];
|
|
124
|
+
const cd = `cd ${shellQuote(cwd)}`;
|
|
125
|
+
if (isCompatId(kind)) {
|
|
126
|
+
const id: CompatId = kind;
|
|
127
|
+
const row = agentVersions(configuredCommands(config)).find(candidate => candidate.id === id);
|
|
128
|
+
if (!row?.executable) out.push({ text: `${COMPAT[id].label} CLI: not found on PATH`, fix: `install ${COMPAT[id].label}, or set its command in .agenthub/config.local.json` });
|
|
129
|
+
else {
|
|
130
|
+
const verdict = row.verdict;
|
|
131
|
+
out.push(verdict.ok && verdict.state === "verified" ? { text: `${COMPAT[id].label} CLI: ${row.executable}, version verified` }
|
|
132
|
+
: verdict.ok ? { text: `${COMPAT[id].label} CLI: ${row.executable}, ${verdict.note ?? verdict.state}` }
|
|
133
|
+
: { text: `${COMPAT[id].label} CLI: ${row.executable}, version not accepted (${verdict.reason})`, fix: `ahub agents` });
|
|
134
|
+
}
|
|
135
|
+
} else out.push({ text: `${kind}: no CLI version gate` });
|
|
136
|
+
let mode = "n/a";
|
|
137
|
+
try { mode = startModeOf(config.peers, peer) ?? "n/a"; } catch { /* a peer without a start mode */ }
|
|
138
|
+
out.push({ text: `start mode: ${mode}` });
|
|
139
|
+
if (kind === "jcode") {
|
|
140
|
+
const instance = config.instances?.[peer];
|
|
141
|
+
const home = instance?.jcode_home ?? config.jcode_home, own = jcodeOwnHome(env, user);
|
|
142
|
+
if (sameJcodeHome(home, own)) out.push({ text: `jcode home ${home} is your own: every MCP server and config change you make there reaches the hub-owned jcode`, fix: `${cd} && ahub init` });
|
|
143
|
+
else out.push({ text: `jcode home ${home} is separate from your own (${own})` });
|
|
144
|
+
const found = jcodeExtraMcpServers(cwd, home);
|
|
145
|
+
const { allowed, refused } = splitJcodeMcpServers(found.servers, instance?.jcode_mcp_allow ?? config.jcode_mcp_allow ?? []);
|
|
146
|
+
if (allowed.length) out.push({ text: `MCP servers allowed by you: ${allowed.join(", ")}` });
|
|
147
|
+
if (refused.length) out.push({ text: `MCP servers that would load and are not allowed: ${refused.join(", ")}`, fix: `remove them from ${join(home, "mcp.json")}, or allow them by adding "jcode_mcp_allow": [${refused.map(name => JSON.stringify(name)).join(", ")}] to ${join(cwd, ".agenthub", "config.local.json")}` });
|
|
148
|
+
if (found.unreadable.length) out.push({ text: `unreadable or unsafe MCP files: ${found.unreadable.join(", ")}`, fix: "fix them in your editor" });
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const rosterPreflightLines = (peer: string, findings: readonly RosterFinding[]): string[] =>
|
|
154
|
+
[`preflight for ${peer}:`, ...findings.flatMap(finding => [` ${finding.text}`, ...(finding.fix ? [` fix: ${finding.fix}`] : [])])];
|
|
155
|
+
|
|
156
|
+
/** Whether a symlink or non-directory sits where init would create the home. */
|
|
157
|
+
export const jcodeHomeBlocked = (home: string): boolean => { const info = lstatSync(home, { throwIfNoEntry: false }); return !!info && (info.isSymbolicLink() || !info.isDirectory()); };
|
|
158
|
+
export { applyJcodeHome };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { closeSync, existsSync, lstatSync, mkdirSync, openSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { realPath } from "../../hub/project.ts";
|
|
6
|
+
import { JCODE_MCP_NAME, jcodeMcpEntry, readJcodeMcpServers } from "./native-cli-jcode-mcp.ts";
|
|
7
|
+
|
|
8
|
+
/** The person's own jcode data home: `$JCODE_HOME`, else `~/.jcode` (the same default `jcode_home` starts from). */
|
|
9
|
+
export function jcodeOwnHome(env: NodeJS.ProcessEnv = process.env, user: string = homedir()): string {
|
|
10
|
+
return env.JCODE_HOME?.trim() || join(user, ".jcode");
|
|
11
|
+
}
|
|
12
|
+
const canonical = (path: string): string => { try { return realPath(path); } catch { return resolve(path); } };
|
|
13
|
+
/** Whether two jcode homes are the same directory, however each is spelled (a link or a system alias resolves). */
|
|
14
|
+
export function sameJcodeHome(a: string, b: string): boolean { return canonical(a) === canonical(b); }
|
|
15
|
+
/** Where init puts a project's hub-owned jcode home (#1627): machine-local, outside the repository. */
|
|
16
|
+
export const hubJcodeHomePath = (hub: string, projectId: string): string => join(hub, "jcode", projectId);
|
|
17
|
+
|
|
18
|
+
const quoted = (value: string): string => `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
19
|
+
/** The person's step to log in inside a separate home: complete, with `JCODE_HOME` set. */
|
|
20
|
+
export const jcodeLoginCommand = (target: string): string => `JCODE_HOME=${quoted(target)} jcode login`;
|
|
21
|
+
|
|
22
|
+
export interface JcodeHomePlan {
|
|
23
|
+
home: string;
|
|
24
|
+
own: string;
|
|
25
|
+
/** The home is already there: nothing is written, only `drift` is reported. */
|
|
26
|
+
exists: boolean;
|
|
27
|
+
/** What a new home's mcp.json holds: the hub's own entry plus the allowed servers found in the person's mcp.json. */
|
|
28
|
+
servers: Record<string, unknown>;
|
|
29
|
+
/** Allowed names the person's own mcp.json does not define, so there is nothing to copy. */
|
|
30
|
+
absentAllowed: string[];
|
|
31
|
+
/** For an existing home: what is missing, each with its fix. */
|
|
32
|
+
drift: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Plan the hub-owned jcode home (#1627). Reads the person's own `mcp.json` (the allowed entries only) and never writes it.
|
|
37
|
+
* Auth is never copied or linked: a second home needs its own login (docs/verification/2026-11-22-jcode-separate-home.md), so the plan names that person step.
|
|
38
|
+
* ponytail: an allowed entry is copied whole, so an environment value in it goes with it into a 0600 file in the hub-owned home. Upgrade path: copy by reference once jcode can read an include.
|
|
39
|
+
*/
|
|
40
|
+
export function planJcodeHome(input: { home: string; own: string; cwd: string; stateDir: string; bundle: string; allow: readonly string[] }): JcodeHomePlan {
|
|
41
|
+
const { home, own, cwd, stateDir, bundle, allow } = input;
|
|
42
|
+
const ownServers = readJcodeMcpServers(own).servers;
|
|
43
|
+
const copied = Object.fromEntries(allow.filter(name => name !== JCODE_MCP_NAME && name in ownServers).map(name => [name, structuredClone(ownServers[name])]));
|
|
44
|
+
const servers: Record<string, unknown> = { [JCODE_MCP_NAME]: jcodeMcpEntry(cwd, stateDir, bundle), ...copied };
|
|
45
|
+
const absentAllowed = allow.filter(name => name !== JCODE_MCP_NAME && !(name in copied));
|
|
46
|
+
const exists = lstatSync(home, { throwIfNoEntry: false }) !== undefined;
|
|
47
|
+
const drift: string[] = [];
|
|
48
|
+
if (exists) {
|
|
49
|
+
const held = readJcodeMcpServers(home);
|
|
50
|
+
const file = join(home, "mcp.json");
|
|
51
|
+
if (held.unreadable) drift.push(`${file} is unreadable or unsafe; fix it in your editor`);
|
|
52
|
+
else if (!held.present) drift.push(`${file} is missing; fix: add the hub entry with cd ${quoted(cwd)} && ahub jcode, and the allowed servers from ${join(own, "mcp.json")}`);
|
|
53
|
+
else {
|
|
54
|
+
const missing = Object.keys(servers).filter(name => !(name in held.servers));
|
|
55
|
+
if (missing.length) drift.push(`${file} lacks ${missing.join(", ")}; fix: add ${missing.length === 1 ? "it" : "them"} from ${join(own, "mcp.json")}${missing.includes(JCODE_MCP_NAME) ? ` (the hub entry: cd ${quoted(cwd)} && ahub jcode)` : ""}`);
|
|
56
|
+
}
|
|
57
|
+
if (!lstatSync(join(home, "auth.json"), { throwIfNoEntry: false })) drift.push(`no jcode login in ${home}; person step: ${jcodeLoginCommand(home)}`);
|
|
58
|
+
}
|
|
59
|
+
return { home, own, exists, servers, absentAllowed, drift };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Create a new hub-owned home with only its mcp.json (0700 directory, 0600 file). An existing home is never written. */
|
|
63
|
+
export function applyJcodeHome(plan: JcodeHomePlan): void {
|
|
64
|
+
if (plan.exists) return;
|
|
65
|
+
mkdirSync(plan.home, { recursive: true, mode: 0o700 });
|
|
66
|
+
const file = join(plan.home, "mcp.json"), temporary = `${file}.${randomUUID()}.tmp`;
|
|
67
|
+
try {
|
|
68
|
+
const fd = openSync(temporary, "wx", 0o600);
|
|
69
|
+
try { writeFileSync(fd, `${JSON.stringify({ servers: plan.servers }, null, 2)}\n`); } finally { closeSync(fd); }
|
|
70
|
+
renameSync(temporary, file);
|
|
71
|
+
} finally { if (existsSync(temporary)) unlinkSync(temporary); }
|
|
72
|
+
}
|
|
@@ -115,6 +115,17 @@ function readBoundedJson(root: string, parts: string[]): unknown | undefined {
|
|
|
115
115
|
} finally { closeSync(fd); }
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
/** One `mcp.json` in a jcode home: its server map (entries included), whether the file exists, and whether it was unreadable or unsafe. Used by init's home plan, never by doctor's names-only listing. */
|
|
119
|
+
export function readJcodeMcpServers(home: string): { servers: Record<string, unknown>; present: boolean; unreadable: boolean } {
|
|
120
|
+
try {
|
|
121
|
+
const doc = readBoundedJson(home, ["mcp.json"]);
|
|
122
|
+
if (doc === undefined) return { servers: {}, present: false, unreadable: false };
|
|
123
|
+
const servers = object(doc) ? (doc.mcpServers ?? doc.servers) : undefined;
|
|
124
|
+
if (!object(doc) || (servers !== undefined && !object(servers))) return { servers: {}, present: true, unreadable: true };
|
|
125
|
+
return { servers: { ...servers }, present: true, unreadable: false };
|
|
126
|
+
} catch { return { servers: {}, present: true, unreadable: true }; }
|
|
127
|
+
}
|
|
128
|
+
|
|
118
129
|
export function jcodeExtraMcpServers(cwd: string, home: string): { servers: string[]; unreadable: string[] } {
|
|
119
130
|
const sources: [label: string, root: string, parts: string[]][] = [
|
|
120
131
|
["mcp.json (JCODE_HOME)", home, ["mcp.json"]], [JCODE_MCP_FILE, cwd, [".jcode", "mcp.json"]],
|
|
@@ -132,3 +143,12 @@ export function jcodeExtraMcpServers(cwd: string, home: string): { servers: stri
|
|
|
132
143
|
}
|
|
133
144
|
return { servers: [...names].sort(), unreadable };
|
|
134
145
|
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Split the extra servers by the person's machine-local allowlist (#1621). Doctor policy only: launch is unchanged.
|
|
149
|
+
* ponytail: matching is by name only (the doctor contract reads names, never a command or args), so a different server registered under an allowed name also passes. Upgrade path: compare a command fingerprint once the inventory carries one.
|
|
150
|
+
*/
|
|
151
|
+
export function splitJcodeMcpServers(servers: readonly string[], allow: readonly string[]): { allowed: string[]; refused: string[] } {
|
|
152
|
+
const ok = new Set(allow);
|
|
153
|
+
return { allowed: servers.filter(name => ok.has(name)), refused: servers.filter(name => !ok.has(name)) };
|
|
154
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The user skill directory each native host reads (#1622).
|
|
3
|
+
*
|
|
4
|
+
* `ahub setup` installs the hub's own skills into these directories, so the per-host knowledge lives here, with the
|
|
5
|
+
* other native facts, and `src/cli/skills-install.ts` carries no host name of its own. Each entry is from that host's
|
|
6
|
+
* own source or help output (docs/agent-notes/adapters.md): Codex `_codex_home()/skills`, Kimi
|
|
7
|
+
* `$KIMI_CODE_HOME/skills`, Qwen `getGlobalQwenDir()/skills`, Jcode the global `~/.jcode/skills`, Pi the global agent
|
|
8
|
+
* dir's `skills`, agy `~/.gemini/config/skills`.
|
|
9
|
+
*
|
|
10
|
+
* Claude Code is absent on purpose: it reads the skills from the installed plugin, never from a user skill directory.
|
|
11
|
+
* The hub's own local worker is absent too, because it receives the hub tools directly.
|
|
12
|
+
*/
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
|
|
15
|
+
export const SKILL_HOSTS = ["codex", "kimi", "qwen", "jcode", "pi", "agy"] as const;
|
|
16
|
+
export type SkillHost = (typeof SKILL_HOSTS)[number];
|
|
17
|
+
|
|
18
|
+
export function hostSkillDir(host: SkillHost, home: string, env: NodeJS.ProcessEnv = process.env): string {
|
|
19
|
+
const base = env.HOME?.trim() || home;
|
|
20
|
+
const skills = (...segments: string[]) => join(...segments, "skills");
|
|
21
|
+
switch (host) {
|
|
22
|
+
case "codex": return skills(env.CODEX_HOME?.trim() || join(base, ".codex"));
|
|
23
|
+
case "kimi": return skills(env.KIMI_CODE_HOME?.trim() || join(base, ".kimi-code"));
|
|
24
|
+
case "qwen": return skills(env.QWEN_HOME?.trim() || join(base, ".qwen"));
|
|
25
|
+
case "jcode": return skills(env.JCODE_HOME?.trim() || join(base, ".jcode"));
|
|
26
|
+
case "pi": return skills(env.PI_CODING_AGENT_DIR?.trim() || join(base, ".pi", "agent"));
|
|
27
|
+
case "agy": return skills(base, ".gemini", "config");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -6,7 +6,7 @@ import { shellQuote } from "./shell-quote.ts";
|
|
|
6
6
|
import { stableBunRuntime, stablePackageRoot } from "./install-paths.ts";
|
|
7
7
|
import type { ClaudeHome } from "./claude-homes.ts";
|
|
8
8
|
|
|
9
|
-
export interface ClaudeProfileHookOptions { script?: string; runtime?: string }
|
|
9
|
+
export interface ClaudeProfileHookOptions { script?: string; runtime?: string; instruction?: boolean }
|
|
10
10
|
export interface ClaudeProfileHookCheck { state: "installed" | "missing" | "refused"; reason: string }
|
|
11
11
|
export interface ClaudeProfileHookInstall extends ClaudeProfileHookCheck { changed: boolean }
|
|
12
12
|
const MAX_SETTINGS_BYTES = 1024 * 1024;
|
|
@@ -30,6 +30,23 @@ function hookEntry(options: ClaudeProfileHookOptions): Record<string, unknown> {
|
|
|
30
30
|
return { matcher: "*", hooks: [{ type: "command", command: `${shellQuote(runtime)} ${shellQuote(script)} --run`, timeout: 5 }] };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function instructionEntry(options: ClaudeProfileHookOptions): Record<string, unknown> {
|
|
34
|
+
const script = join(stablePackageRoot(join(import.meta.dir, "../..")), "src/cli/main.js"), runtime = options.runtime ?? stableBunRuntime();
|
|
35
|
+
if (!validPath(script) || !validPath(runtime)) throw new Error("invalid instruction hook command");
|
|
36
|
+
return { hooks: [{ type: "command", command: `${shellQuote(runtime)} ${shellQuote(script)} instruction-hook`, timeout: 5 }] };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function managedInstructionHook(candidate: unknown): ManagedProfileHook | undefined {
|
|
40
|
+
if (!object(candidate) || !Array.isArray(candidate.hooks) || candidate.hooks.length !== 1) return;
|
|
41
|
+
const hook = candidate.hooks[0];
|
|
42
|
+
if (!object(hook) || hook.type !== "command" || typeof hook.command !== "string") return;
|
|
43
|
+
const match = /^'((?:[^']|'\\'')*)' '((?:[^']|'\\'')*)' instruction-hook$/.exec(hook.command);
|
|
44
|
+
if (!match) return;
|
|
45
|
+
const runtime = match[1]!.replace(/'\\''/g, "'"), script = match[2]!.replace(/'\\''/g, "'");
|
|
46
|
+
if (!validPath(runtime) || !validPath(script) || !script.endsWith("/src/cli/main.js") || hook.command !== `${shellQuote(runtime)} ${shellQuote(script)} instruction-hook`) return;
|
|
47
|
+
return { entry: candidate, hook, runtime, script };
|
|
48
|
+
}
|
|
49
|
+
|
|
33
50
|
interface ManagedProfileHook { entry: Record<string, unknown>; hook: Record<string, unknown>; runtime: string; script: string }
|
|
34
51
|
/** Own only the generated command grammar; matcher, timeout and caller metadata remain theirs. */
|
|
35
52
|
function managedProfileHook(candidate: unknown): ManagedProfileHook | undefined {
|
|
@@ -96,13 +113,33 @@ function planClaudeProfileHook(home: ClaudeHome, options: ClaudeProfileHookOptio
|
|
|
96
113
|
return owned === first ? [{ ...owned.entry, hooks: [{ ...owned.hook, command: expectedCommand }] }] : [];
|
|
97
114
|
});
|
|
98
115
|
if (!first) normalized.push(entry);
|
|
99
|
-
const
|
|
116
|
+
const nextHooks: Record<string, unknown> = { ...hooks, PreToolUse: normalized };
|
|
117
|
+
let instructionConfigured = true;
|
|
118
|
+
if (options.instruction) {
|
|
119
|
+
const entry = instructionEntry(options), expected = (entry.hooks as { command: string }[])[0]!.command;
|
|
120
|
+
for (const event of ["UserPromptSubmit", "Stop"]) {
|
|
121
|
+
const list = hooks[event] ?? [];
|
|
122
|
+
if (!Array.isArray(list)) return refuse(`Claude's ${event} hook list is malformed.`);
|
|
123
|
+
const managed = list.map(managedInstructionHook), first = managed.find(candidate => candidate !== undefined);
|
|
124
|
+
const count = managed.filter(candidate => candidate !== undefined).length;
|
|
125
|
+
const current = count === 1 && first?.hook.command === expected && hookPathPresent(first.runtime) && hookPathPresent(first.script);
|
|
126
|
+
if (!current) instructionConfigured = false;
|
|
127
|
+
const rewritten = list.flatMap((candidate, index) => {
|
|
128
|
+
const owned = managed[index];
|
|
129
|
+
if (!owned) return [candidate];
|
|
130
|
+
return owned === first ? [{ ...owned.entry, hooks: [{ ...owned.hook, command: expected }] }] : [];
|
|
131
|
+
});
|
|
132
|
+
if (!first) rewritten.push(entry);
|
|
133
|
+
nextHooks[event] = rewritten;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const next = configured && instructionConfigured ? undefined : `${JSON.stringify({ ...value, hooks: nextHooks }, null, 2)}\n`;
|
|
100
137
|
if (next !== undefined && Buffer.byteLength(next, "utf8") > MAX_SETTINGS_BYTES) return refuse("Claude's settings would exceed the bounded profile settings size.");
|
|
101
138
|
let reason = "The project-neutral profile hook is not configured for this install; run ahub setup.";
|
|
102
139
|
if (count > 1) reason = "Duplicate managed profile hooks need normalization; run ahub setup.";
|
|
103
140
|
if (stale) reason = "A managed profile hook script or runtime is missing; run ahub setup to refresh the selected home's hook.";
|
|
104
141
|
if (configured) reason = "The project-neutral profile hook is configured; this does not prove live permission enforcement.";
|
|
105
|
-
return { file, home: directory, parent, source, next, check: { state: configured ? "installed" : "missing", reason } };
|
|
142
|
+
return { file, home: directory, parent, source, next, check: { state: configured && instructionConfigured ? "installed" : "missing", reason } };
|
|
106
143
|
} catch { return refuse("Claude profile settings could not be safely inspected; no settings were changed."); }
|
|
107
144
|
}
|
|
108
145
|
|