@staix/agent-hub 0.50.0 → 0.51.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 +16 -0
- package/README.md +1 -1
- package/docs/adding-an-ai-tool.md +2 -2
- package/docs/agent-notes/README.md +1 -0
- package/docs/agent-notes/adapters.md +3 -3
- package/docs/agent-notes/daemon.md +1 -1
- package/docs/agent-notes/local-worker.md +3 -3
- package/docs/agent-notes/tasks.md +5 -1
- package/docs/design/adapters.md +17 -0
- package/docs/design/cli-output-inventory.md +22 -17
- package/docs/design/roadmap.md +1 -1
- package/docs/design/task-board.md +34 -0
- package/docs/dogfood.md +7 -3
- package/docs/operations.md +49 -3
- package/docs/quickstart.md +18 -1
- package/docs/roadmap.json +20 -20
- package/docs/roadmap.md +2 -2
- package/docs/sdlc.md +3 -2
- package/docs/specs/2026-09-19-agent-hub-design.md +1 -0
- package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
- package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
- package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
- package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
- package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
- package/docs/verification/2026-11-30-0.51.0.md +91 -0
- package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
- package/docs/verified.json +31 -27
- package/package.json +1 -1
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +1329 -24654
- package/plugins/agent-hub/server.js +612 -413
- package/scripts/check-docs.mjs +1 -1
- package/src/adapters/acp.ts +13 -13
- package/src/adapters/agy/definition.ts +2 -2
- package/src/adapters/agy/entry.ts +2 -0
- package/src/adapters/claude-channel-evidence.ts +7 -3
- package/src/adapters/compat.ts +4 -3
- package/src/adapters/definitions/builtin-metadata.ts +2 -2
- package/src/adapters/definitions/native-cli-claude-launch.ts +3 -1
- package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
- package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-jcode.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-types.ts +3 -1
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
- package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/jcode.ts +16 -0
- package/src/adapters/native-facts-hooks.ts +12 -0
- package/src/cli/autonomy-offline.ts +1 -1
- package/src/cli/bench.ts +1 -1
- package/src/cli/claude-profile-hook.ts +31 -11
- package/src/cli/commands/releases.ts +82 -0
- package/src/cli/conductor-recovery.ts +1 -1
- package/src/cli/facts-hook.ts +11 -4
- package/src/cli/help.ts +8 -6
- package/src/cli/identity.ts +5 -1
- package/src/cli/init-prompt.ts +1 -1
- package/src/cli/init-settings.ts +4 -35
- package/src/cli/init.ts +1 -1
- package/src/cli/json-text-spans.ts +57 -0
- package/src/cli/launch-check.ts +157 -0
- package/src/cli/launch.ts +19 -1
- package/src/cli/main.ts +44 -3
- package/src/cli/memory.ts +1 -1
- package/src/cli/output.ts +14 -1
- package/src/cli/preview.ts +1 -1
- package/src/cli/recovery-launch.ts +1 -1
- package/src/cli/setup-homes.ts +2 -2
- package/src/cli/start-agents-run.ts +85 -7
- package/src/cli/start-check.ts +28 -0
- package/src/cli/upgrade-runtime.ts +1 -1
- package/src/cli/warn-line.ts +1 -1
- package/src/hub/ci-watch.ts +311 -79
- package/src/hub/config-apply.ts +1 -1
- package/src/hub/config.ts +518 -0
- package/src/hub/control-client.ts +1 -1
- package/src/hub/daemon.ts +76 -513
- package/src/hub/delivery-public.ts +11 -0
- package/src/hub/hub-check.ts +125 -0
- package/src/hub/path-policy.ts +1 -1
- package/src/hub/permission-mode.ts +3 -40
- package/src/hub/permission-paths.ts +41 -0
- package/src/hub/recovery-policy.ts +1 -1
- package/src/hub/releases-inventory.ts +198 -0
- package/src/hub/runtime-capture-prune.ts +25 -3
- package/src/hub/runtime-prune-health.ts +8 -1
- package/src/hub/sdlc-release-authorization.ts +42 -21
- package/src/hub/sdlc-release-diagnostics.ts +5 -0
- package/src/hub/sdlc-release-policy.ts +21 -7
- package/src/hub/sdlc-release.ts +80 -20
- package/src/hub/sdlc.ts +7 -3
- package/src/hub/tasks.ts +138 -36
- package/src/ui/plugin.ts +1 -1
|
@@ -754,12 +754,12 @@ var init_compat = __esm(() => {
|
|
|
754
754
|
},
|
|
755
755
|
"kimi-review": {
|
|
756
756
|
label: "Kimi reviewer (kimi-code)",
|
|
757
|
-
verified: ["2.2.0", "2.3.0", "2.3.1", "2.3.2", "2.4.1", "2.5.1", "2.7.2"],
|
|
757
|
+
verified: ["2.2.0", "2.3.0", "2.3.1", "2.3.2", "2.4.1", "2.5.1", "2.7.2", "2.8.1"],
|
|
758
758
|
gate: "isolation",
|
|
759
759
|
probe: ["kimi", "--version"],
|
|
760
760
|
parse: (out) => plain(out.trim()),
|
|
761
761
|
trustNote: "Every launch still builds the private config, exact two-tool agent file and task-bound MCP; the native tool allowlist behaviour of an untested version is not re-proven.",
|
|
762
|
-
receipt: "docs/verification/2026-11-
|
|
762
|
+
receipt: "docs/verification/2026-11-29-kimi-281-reviewer-compat.md"
|
|
763
763
|
},
|
|
764
764
|
"kimi-tui": {
|
|
765
765
|
label: "Kimi TUI completion facts",
|
|
@@ -835,6 +835,181 @@ function bundleInStatus(status) {
|
|
|
835
835
|
return typeof value === "string" && value.startsWith("/") && /[\\/]plugins[\\/]agent-hub[\\/]server\.js$/.test(value) ? value : undefined;
|
|
836
836
|
}
|
|
837
837
|
|
|
838
|
+
// src/hub/hub-check.ts
|
|
839
|
+
function expectedHubLink(definition, form) {
|
|
840
|
+
return definition?.transport === "ws-pull" || form !== undefined && definition?.attach?.pullOnlyForms?.includes(form) ? "pull" : "push";
|
|
841
|
+
}
|
|
842
|
+
function renderHubCheck(check, only) {
|
|
843
|
+
const rows = only ? check.peers.filter((peer) => only.includes(peer.id)) : check.peers.filter((peer) => peer.observed !== "offline" || !peer.ok);
|
|
844
|
+
const lines = [`Hub check (agent-hub ${check.version}, control port ${check.controlPort})`];
|
|
845
|
+
for (const peer of rows) {
|
|
846
|
+
if (peer.ok && peer.observed !== "offline") {
|
|
847
|
+
lines.push(` \u2713 ${peer.id}: ${peer.observed}${peer.queued ? `, ${peer.queued} queued` : ""}`);
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
lines.push(` \u26A0 ${peer.id}: ${peer.observed}${peer.cause ? `, ${peer.cause}` : ""}${peer.queued ? `, ${peer.queued} queued` : ""}${peer.nextStep ? `; next: ${peer.nextStep}` : ""}`);
|
|
851
|
+
}
|
|
852
|
+
if (rows.length === 0)
|
|
853
|
+
lines.push(" no agents attached");
|
|
854
|
+
return lines;
|
|
855
|
+
}
|
|
856
|
+
function renderHubCheckUnavailable(result = HUB_CHECK_UNAVAILABLE) {
|
|
857
|
+
return [`Hub check: \u26A0 ${result.cause}; next: ${result.nextStep}`];
|
|
858
|
+
}
|
|
859
|
+
var UNVERIFIED, HUB_CHECK_UNAVAILABLE;
|
|
860
|
+
var init_hub_check = __esm(() => {
|
|
861
|
+
UNVERIFIED = new Set(["launch-unverified", "unknown", "unreported"]);
|
|
862
|
+
HUB_CHECK_UNAVAILABLE = { unavailable: true, cause: "the hub check could not be read from the hub", nextStep: "ahub status" };
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
// node_modules/@staix/cli-output/src/index.ts
|
|
866
|
+
function terminalText(value, options = {}) {
|
|
867
|
+
const text = String(value ?? "").replace(/\r\n?/g, `
|
|
868
|
+
`).replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/g, "").replace(/\x1b[P_X^][\s\S]*?(?:\x1b\\|$)/g, "").replace(/(?:\x1b\[|\x9b)[0-?]*[ -/]*(?:[@-~]|(?=\n|$))/g, "").replace(/\x1b[^\n]?/g, "");
|
|
869
|
+
return options.singleLine ? text.replace(/[\x00-\x1f\x7f-\x9f]/g, " ") : text.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
870
|
+
}
|
|
871
|
+
function paint(spans, color, styles = {}) {
|
|
872
|
+
return spans.map((span) => {
|
|
873
|
+
const text = terminalText(span.text);
|
|
874
|
+
const role = span.role && Object.hasOwn(ROLE_SGR, span.role) ? ROLE_SGR[span.role] : undefined;
|
|
875
|
+
const custom = span.style && Object.hasOwn(styles, span.style) ? styles[span.style] : undefined;
|
|
876
|
+
if (custom && !/^\x1b\[[0-9;]+m$/.test(custom))
|
|
877
|
+
throw new Error(`invalid SGR for style ${span.style}`);
|
|
878
|
+
const sgr = role !== undefined ? role : custom;
|
|
879
|
+
return color && sgr && text ? sgr + text + SGR_RESET : text;
|
|
880
|
+
}).join("");
|
|
881
|
+
}
|
|
882
|
+
var SGR_RESET = "\x1B[0m", ROLE_SGR, MARKERS, EXIT;
|
|
883
|
+
var init_src = __esm(() => {
|
|
884
|
+
ROLE_SGR = Object.freeze({
|
|
885
|
+
header: "\x1B[1;34m",
|
|
886
|
+
section: "\x1B[1;35m",
|
|
887
|
+
key: "\x1B[34m",
|
|
888
|
+
value: "",
|
|
889
|
+
success: "\x1B[1;32m",
|
|
890
|
+
warning: "\x1B[1;33m",
|
|
891
|
+
error: "\x1B[1;31m",
|
|
892
|
+
hint: "\x1B[90m",
|
|
893
|
+
accent: "\x1B[36m"
|
|
894
|
+
});
|
|
895
|
+
MARKERS = Object.freeze({
|
|
896
|
+
ok: { glyph: "\u2713", ascii: "ok", role: "success" },
|
|
897
|
+
fail: { glyph: "\u2717", ascii: "x", role: "error" },
|
|
898
|
+
warn: { glyph: "\u26A0", ascii: "!", role: "warning" },
|
|
899
|
+
absent: { glyph: "-", ascii: "-", role: "hint" },
|
|
900
|
+
unknown: { glyph: "?", ascii: "?", role: "hint" },
|
|
901
|
+
pending: { glyph: "~", ascii: "~", role: "hint" },
|
|
902
|
+
active: { glyph: "*", ascii: "*", role: "success" },
|
|
903
|
+
next: { glyph: "\u2192", ascii: "->", role: "accent" }
|
|
904
|
+
});
|
|
905
|
+
EXIT = Object.freeze({ ok: 0, fail: 1, usage: 2, tempfail: 75 });
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
// src/cli/output-standard.ts
|
|
909
|
+
var TONE_SGR;
|
|
910
|
+
var init_output_standard = __esm(() => {
|
|
911
|
+
init_src();
|
|
912
|
+
TONE_SGR = Object.freeze({ strong: "\x1B[1;36m", failure: "\x1B[31m", number: "\x1B[1m", issueRef: "\x1B[4m", taskRef: "\x1B[4;35m" });
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
// src/cli/warn-line.ts
|
|
916
|
+
var plain2 = (text) => text.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/g, "").replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
917
|
+
var init_warn_line = __esm(() => {
|
|
918
|
+
init_output_standard();
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
// src/cli/launch-check.ts
|
|
922
|
+
async function readLaunchCheck(connectOnce, totalMs = LAUNCH_CHECK_TOTAL_MS) {
|
|
923
|
+
const deadline = Date.now() + totalMs;
|
|
924
|
+
let expired = false;
|
|
925
|
+
let open;
|
|
926
|
+
let timer;
|
|
927
|
+
const closeOpen = () => {
|
|
928
|
+
const client = open;
|
|
929
|
+
open = undefined;
|
|
930
|
+
try {
|
|
931
|
+
client?.close();
|
|
932
|
+
} catch {}
|
|
933
|
+
};
|
|
934
|
+
const attempt = (async () => {
|
|
935
|
+
const client = await connectOnce(Math.max(1, deadline - Date.now()));
|
|
936
|
+
if (expired) {
|
|
937
|
+
try {
|
|
938
|
+
client.close();
|
|
939
|
+
} catch {}
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
open = client;
|
|
943
|
+
const reply = await client.request({ t: "status" }, Math.max(1, deadline - Date.now()));
|
|
944
|
+
const check = reply?.status?.hubCheck;
|
|
945
|
+
return check && Array.isArray(check.peers) ? check : undefined;
|
|
946
|
+
})().catch(() => {
|
|
947
|
+
return;
|
|
948
|
+
});
|
|
949
|
+
try {
|
|
950
|
+
return await Promise.race([attempt, new Promise((resolve) => {
|
|
951
|
+
timer = setTimeout(() => {
|
|
952
|
+
expired = true;
|
|
953
|
+
closeOpen();
|
|
954
|
+
resolve(undefined);
|
|
955
|
+
}, totalMs);
|
|
956
|
+
})]);
|
|
957
|
+
} catch {
|
|
958
|
+
return;
|
|
959
|
+
} finally {
|
|
960
|
+
if (timer)
|
|
961
|
+
clearTimeout(timer);
|
|
962
|
+
closeOpen();
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
function cleanLine(line) {
|
|
966
|
+
return plain2(line.replace(/[\r\n]+/g, " "));
|
|
967
|
+
}
|
|
968
|
+
function renderLaunchCheck(check, peer, definition, form) {
|
|
969
|
+
if (!check)
|
|
970
|
+
return renderHubCheckUnavailable(HUB_CHECK_UNAVAILABLE);
|
|
971
|
+
const row = check.peers.find((item) => item.id === peer);
|
|
972
|
+
const expected = row?.expected ?? expectedHubLink(definition, form);
|
|
973
|
+
const lines = [renderHubCheck(check, [])[0], ` ${peer}: starting, expected link ${expected}, ${row ? `${row.queued} queued` : "queue unknown"}; check again after it starts: ahub status`];
|
|
974
|
+
if (row && row.observed !== "offline")
|
|
975
|
+
lines.push(` state before this launch: ${row.observed}${row.cause ? `, ${row.cause}` : ""}`);
|
|
976
|
+
return lines;
|
|
977
|
+
}
|
|
978
|
+
function fixedName(token) {
|
|
979
|
+
if (token === undefined)
|
|
980
|
+
return;
|
|
981
|
+
if (token.startsWith("-p"))
|
|
982
|
+
return "-p";
|
|
983
|
+
for (const flag of ["--print", "--output-format", "--dangerously-load-development-channels"])
|
|
984
|
+
if (token.startsWith(flag))
|
|
985
|
+
return flag;
|
|
986
|
+
return FIXED_WORDS.has(token) ? token : undefined;
|
|
987
|
+
}
|
|
988
|
+
function claudeArgvNextStep(command, position) {
|
|
989
|
+
if (position === undefined)
|
|
990
|
+
return "Shorten the arguments passed to ahub claude (long command lines and control characters are not attested), then run it again.";
|
|
991
|
+
if (position <= 2)
|
|
992
|
+
return `Try ahub claude --session-id "$(uuidgen | tr 'A-Z' 'a-z')" and report it on #1798`;
|
|
993
|
+
const name = fixedName(command.trim().split(/\s+/)[position]);
|
|
994
|
+
if (name === undefined)
|
|
995
|
+
return "Remove the argument at that position, or start ahub claude without your prompt and type it in the session; the channel is not attested while it is there.";
|
|
996
|
+
return `${name} runs Claude without its channel or changes which channels load, so no hub link can attach; start without ${name}, and if it is a word in your prompt, start ahub claude without the prompt and type it in the session.`;
|
|
997
|
+
}
|
|
998
|
+
function printLaunchCheck(snapshot, peer, definition, form = "tui") {
|
|
999
|
+
if (process.stderr.isTTY !== true)
|
|
1000
|
+
return;
|
|
1001
|
+
const candidate = snapshot?.hubCheck;
|
|
1002
|
+
const check = candidate && Array.isArray(candidate.peers) ? candidate : undefined;
|
|
1003
|
+
for (const line of renderLaunchCheck(check, peer, definition, form))
|
|
1004
|
+
console.error(cleanLine(line));
|
|
1005
|
+
}
|
|
1006
|
+
var LAUNCH_CHECK_TOTAL_MS = 3000, FIXED_WORDS, START_HOOK_TIMEOUT_S = 5;
|
|
1007
|
+
var init_launch_check = __esm(() => {
|
|
1008
|
+
init_hub_check();
|
|
1009
|
+
init_warn_line();
|
|
1010
|
+
FIXED_WORDS = new Set(["--background", "--detach", "--daemon", "daemon", "bg", "bg-spare"]);
|
|
1011
|
+
});
|
|
1012
|
+
|
|
838
1013
|
// src/adapters/same-directory.ts
|
|
839
1014
|
function sameDirectory(named, directory) {
|
|
840
1015
|
if (typeof named !== "string" || !named || named.length > 4096 || /[\u0000-\u001f\u007f]/.test(named))
|
|
@@ -1613,6 +1788,7 @@ async function runAgyEntry(ctx) {
|
|
|
1613
1788
|
const status = (await hub.request({ t: "status" })).status;
|
|
1614
1789
|
if (rosterInStatus(status, "agy") !== true)
|
|
1615
1790
|
fail("agy is off roster; add it with ahub roster add agy");
|
|
1791
|
+
printLaunchCheck(status, "agy", ctx.definition, "tui");
|
|
1616
1792
|
const admitted = await hub.request({ t: "native_hook_launch", op: "begin", peer: "agy" });
|
|
1617
1793
|
if (!admitted.ok || typeof admitted.launchId !== "string" || typeof admitted.instanceId !== "string")
|
|
1618
1794
|
fail(admitted.error ?? "native hook launch was not admitted");
|
|
@@ -1646,6 +1822,7 @@ async function runAgyEntry(ctx) {
|
|
|
1646
1822
|
var AGY_LAUNCH_NOTICE = "Antigravity: pull-only TUI; native permissions unmanaged, no hub sandbox; hub tools appear from the second turn (send any first prompt, then ask for hub work)";
|
|
1647
1823
|
var init_entry = __esm(() => {
|
|
1648
1824
|
init_compat();
|
|
1825
|
+
init_launch_check();
|
|
1649
1826
|
init_agy_mcp();
|
|
1650
1827
|
init_child_process();
|
|
1651
1828
|
});
|
|
@@ -5840,7 +6017,7 @@ var init_acp = __esm(() => {
|
|
|
5840
6017
|
} catch (error) {
|
|
5841
6018
|
if (error instanceof RpcTimeoutError && current()) {
|
|
5842
6019
|
if (this.activeDeliveryId)
|
|
5843
|
-
this.delivery({ id: this.activeDeliveryId, state: "failed_safe", reason: "ACP model acknowledgement timed out before a prompt was sent; restart this peer before retrying" });
|
|
6020
|
+
this.delivery({ id: this.activeDeliveryId, state: "failed_safe", reason: "ACP model acknowledgement timed out before a prompt was sent; restart this peer before retrying", failureCause: "timeout" });
|
|
5844
6021
|
this.activeDeliveryId = undefined;
|
|
5845
6022
|
this.activeLegacy = undefined;
|
|
5846
6023
|
this.modelUnknown = true;
|
|
@@ -5924,7 +6101,7 @@ var init_acp = __esm(() => {
|
|
|
5924
6101
|
if (reason !== undefined)
|
|
5925
6102
|
this.turn++;
|
|
5926
6103
|
if (this.activeDeliveryId)
|
|
5927
|
-
this.delivery({ id: this.activeDeliveryId, state: "needs_review", reason: reason ?? "ACP session stopped before settlement" });
|
|
6104
|
+
this.delivery({ id: this.activeDeliveryId, state: "needs_review", reason: reason ?? "ACP session stopped before settlement", failureCause: "turn aborted" });
|
|
5928
6105
|
this.settleSteers("needs_review", reason ?? "ACP session stopped before settlement");
|
|
5929
6106
|
this.activeDeliveryId = undefined;
|
|
5930
6107
|
const proc = this.proc;
|
|
@@ -5956,7 +6133,7 @@ var init_acp = __esm(() => {
|
|
|
5956
6133
|
async deliver(envs, deliveryId) {
|
|
5957
6134
|
if (this.state !== "idle" || this.stopping) {
|
|
5958
6135
|
if (deliveryId)
|
|
5959
|
-
this.delivery({ id: deliveryId, state: "failed_safe", reason: `${this.id} is ${this.state}
|
|
6136
|
+
this.delivery({ id: deliveryId, state: "failed_safe", reason: `${this.id} is ${this.state}`, failureCause: this.state === "offline" ? "peer offline" : "adapter refused" });
|
|
5960
6137
|
throw new Error(`${this.id} is ${this.state}`);
|
|
5961
6138
|
}
|
|
5962
6139
|
let selection;
|
|
@@ -5964,14 +6141,14 @@ var init_acp = __esm(() => {
|
|
|
5964
6141
|
selection = this.opts.getModelOverride?.();
|
|
5965
6142
|
} catch {
|
|
5966
6143
|
if (deliveryId)
|
|
5967
|
-
this.delivery({ id: deliveryId, state: "failed_safe", reason: "ACP retained model selection is unavailable; inspect model status, clear the override or restart before retrying" });
|
|
6144
|
+
this.delivery({ id: deliveryId, state: "failed_safe", reason: "ACP retained model selection is unavailable; inspect model status, clear the override or restart before retrying", failureCause: "adapter refused" });
|
|
5968
6145
|
throw new Error("ACP retained model selection is unavailable; inspect model status, clear the override or restart before retrying");
|
|
5969
6146
|
}
|
|
5970
6147
|
const target = selection?.model ?? this.modelBaseline;
|
|
5971
6148
|
if (selection && (!target || !this.acceptsModelOverride(target))) {
|
|
5972
6149
|
selection.rejected?.();
|
|
5973
6150
|
if (deliveryId)
|
|
5974
|
-
this.delivery({ id: deliveryId, state: "failed_safe", reason: "ACP model is not advertised by this verified session; inspect model status and retry" });
|
|
6151
|
+
this.delivery({ id: deliveryId, state: "failed_safe", reason: "ACP model is not advertised by this verified session; inspect model status and retry", failureCause: "adapter refused" });
|
|
5975
6152
|
throw new Error("ACP model is not advertised by this verified session; inspect model status and retry");
|
|
5976
6153
|
}
|
|
5977
6154
|
const turn = ++this.turn;
|
|
@@ -6004,7 +6181,7 @@ var init_acp = __esm(() => {
|
|
|
6004
6181
|
if (turn === this.turn && !this.modelTurn?.sent) {
|
|
6005
6182
|
selection.rejected?.();
|
|
6006
6183
|
if (deliveryId && this.activeDeliveryId === deliveryId)
|
|
6007
|
-
this.delivery({ id: deliveryId, state: "failed_safe", reason: "ACP model change did not admit a prompt; inspect status and retry" });
|
|
6184
|
+
this.delivery({ id: deliveryId, state: "failed_safe", reason: "ACP model change did not admit a prompt; inspect status and retry", failureCause: "adapter refused" });
|
|
6008
6185
|
this.activeDeliveryId = undefined;
|
|
6009
6186
|
this.activeLegacy = undefined;
|
|
6010
6187
|
this.modelTurn = undefined;
|
|
@@ -6050,9 +6227,9 @@ ${renderDigest(envs, this.primed)}` : renderDigest(envs, this.primed) }] });
|
|
|
6050
6227
|
this.reportTurnFailure(envs, `ACP prompt ended without normal completion (${String(result?.stopReason ?? "unknown")})`);
|
|
6051
6228
|
if (deliveryId && this.activeDeliveryId === deliveryId) {
|
|
6052
6229
|
this.acceptDelivery();
|
|
6053
|
-
this.delivery({ id: deliveryId, state: result?.stopReason === "end_turn" ? "completed" : "needs_review", ...result?.stopReason === "end_turn" ? {} : { reason: "ACP prompt ended without normal completion" } });
|
|
6230
|
+
this.delivery({ id: deliveryId, state: result?.stopReason === "end_turn" ? "completed" : "needs_review", ...result?.stopReason === "end_turn" ? {} : { reason: "ACP prompt ended without normal completion", failureCause: "turn aborted" } });
|
|
6054
6231
|
}
|
|
6055
|
-
this.settleSteers(result?.stopReason === "end_turn" ? "completed" : "needs_review", "ACP prompt ended without normal completion");
|
|
6232
|
+
this.settleSteers(result?.stopReason === "end_turn" ? "completed" : "needs_review", "ACP prompt ended without normal completion", "turn aborted");
|
|
6056
6233
|
}).catch((e) => {
|
|
6057
6234
|
if (turn !== this.turn) {
|
|
6058
6235
|
if (this.cancelWait?.turn === turn)
|
|
@@ -6063,7 +6240,7 @@ ${renderDigest(envs, this.primed)}` : renderDigest(envs, this.primed) }] });
|
|
|
6063
6240
|
this.modelTurn?.selection.rejected?.();
|
|
6064
6241
|
this.endActivity("failed", true);
|
|
6065
6242
|
const reason = this.nativePolicy !== undefined || this.opts.requireOwnedGroup ? "Configured ACP prompt failed" : sanitize(e.message);
|
|
6066
|
-
this.settleSteers("needs_review", reason);
|
|
6243
|
+
this.settleSteers("needs_review", reason, "push error");
|
|
6067
6244
|
this.opts.log?.(this.nativePolicy !== undefined || this.opts.requireOwnedGroup ? "Configured ACP prompt failed; native details withheld" : `[${this.id}] prompt failed: ${reason}`);
|
|
6068
6245
|
const quota = !this.stopping && this.kimiAgent ? acpQuotaRefusal(e.message) : undefined;
|
|
6069
6246
|
if (quota) {
|
|
@@ -6075,7 +6252,7 @@ ${renderDigest(envs, this.primed)}` : renderDigest(envs, this.primed) }] });
|
|
|
6075
6252
|
}
|
|
6076
6253
|
const safe = paused && !this.deliveryAccepted && !this.promptActivity;
|
|
6077
6254
|
if (deliveryId && this.activeDeliveryId === deliveryId)
|
|
6078
|
-
this.delivery({ id: deliveryId, state: safe ? "failed_safe" : "needs_review", reason, ...safe ? { quota: true } : {} });
|
|
6255
|
+
this.delivery({ id: deliveryId, state: safe ? "failed_safe" : "needs_review", reason, failureCause: safe ? "adapter refused" : "push error", ...safe ? { quota: true } : {} });
|
|
6079
6256
|
else if (!deliveryId && this.activeLegacy?.turn === turn) {
|
|
6080
6257
|
this.activeLegacy = undefined;
|
|
6081
6258
|
this.onFailed?.(envs, safe ? { quota: true } : undefined);
|
|
@@ -6084,7 +6261,7 @@ ${renderDigest(envs, this.primed)}` : renderDigest(envs, this.primed) }] });
|
|
|
6084
6261
|
}
|
|
6085
6262
|
this.reportTurnFailure(envs, reason);
|
|
6086
6263
|
if (deliveryId && this.activeDeliveryId === deliveryId)
|
|
6087
|
-
this.delivery({ id: deliveryId, state: "needs_review", reason });
|
|
6264
|
+
this.delivery({ id: deliveryId, state: "needs_review", reason, failureCause: "push error" });
|
|
6088
6265
|
else if (!deliveryId && this.activeLegacy?.turn === turn) {
|
|
6089
6266
|
this.activeLegacy = undefined;
|
|
6090
6267
|
this.onFailed?.(envs);
|
|
@@ -6225,8 +6402,8 @@ ${renderDigest(envs, this.primed)}` : renderDigest(envs, this.primed) }] });
|
|
|
6225
6402
|
p.reject(new Error(reason));
|
|
6226
6403
|
this.pending.clear();
|
|
6227
6404
|
if (this.activeDeliveryId)
|
|
6228
|
-
this.delivery({ id: this.activeDeliveryId, state: "needs_review", reason });
|
|
6229
|
-
this.settleSteers("needs_review", reason);
|
|
6405
|
+
this.delivery({ id: this.activeDeliveryId, state: "needs_review", reason, failureCause: "push error" });
|
|
6406
|
+
this.settleSteers("needs_review", reason, "push error");
|
|
6230
6407
|
this.activeDeliveryId = undefined;
|
|
6231
6408
|
this.setState("offline");
|
|
6232
6409
|
}
|
|
@@ -9219,7 +9396,7 @@ var init_session = __esm(() => {
|
|
|
9219
9396
|
};
|
|
9220
9397
|
});
|
|
9221
9398
|
|
|
9222
|
-
// src/hub/permission-
|
|
9399
|
+
// src/hub/permission-paths.ts
|
|
9223
9400
|
import { lstatSync as lstatSync12 } from "fs";
|
|
9224
9401
|
function hardLinked(path) {
|
|
9225
9402
|
try {
|
|
@@ -9230,10 +9407,7 @@ function hardLinked(path) {
|
|
|
9230
9407
|
}
|
|
9231
9408
|
}
|
|
9232
9409
|
var PERMISSION_MODES, isPermissionMode = (value) => typeof value === "string" && PERMISSION_MODES.includes(value), PI_EDIT_TOOLS, AGENT_CONFIG_SEGMENTS, INSTRUCTION_FILES, isInstructionPath = (path) => path.split(/[\\/]/).some((segment) => INSTRUCTION_FILES.has(foldSegment(segment))), foldSegment = (segment) => segment.normalize("NFKC").replace(/\p{Default_Ignorable_Code_Point}/gu, "").toLowerCase().toUpperCase().toLowerCase(), HUB_WRITE_SEGMENTS, isHubWritePath = (path) => path.split(/[\\/]/).some((segment) => HUB_WRITE_SEGMENTS.has(foldSegment(segment))), isAgentConfigPath = (path) => path.split(/[\\/]/).some((segment) => AGENT_CONFIG_SEGMENTS.has(foldSegment(segment)));
|
|
9233
|
-
var
|
|
9234
|
-
init_registry();
|
|
9235
|
-
init_kimi_native();
|
|
9236
|
-
init_qwen_native();
|
|
9410
|
+
var init_permission_paths = __esm(() => {
|
|
9237
9411
|
PERMISSION_MODES = ["ask", "ask-when-needed", "never-ask"];
|
|
9238
9412
|
PI_EDIT_TOOLS = new Set(["edit", "write"]);
|
|
9239
9413
|
AGENT_CONFIG_SEGMENTS = new Set([".claude", ".codex", ".qwen", ".kimi", ".kimi-code", ".jcode", ".pi", ".mcp.json", ".agents", ".agent", "_agents", "_agent", ".gemini", ".grok", ".claude.json"]);
|
|
@@ -9241,6 +9415,15 @@ var init_permission_mode = __esm(() => {
|
|
|
9241
9415
|
HUB_WRITE_SEGMENTS = new Set([".git", ".agenthub"]);
|
|
9242
9416
|
});
|
|
9243
9417
|
|
|
9418
|
+
// src/hub/permission-mode.ts
|
|
9419
|
+
var init_permission_mode = __esm(() => {
|
|
9420
|
+
init_registry();
|
|
9421
|
+
init_permission_paths();
|
|
9422
|
+
init_kimi_native();
|
|
9423
|
+
init_qwen_native();
|
|
9424
|
+
init_permission_paths();
|
|
9425
|
+
});
|
|
9426
|
+
|
|
9244
9427
|
// src/hub/path-policy.ts
|
|
9245
9428
|
import { accessSync, constants as constants5, lstatSync as lstatSync13, opendirSync, readlinkSync, statSync as statSync3 } from "fs";
|
|
9246
9429
|
import { dirname as dirname8, isAbsolute as isAbsolute5, join as join13, relative as relative3, resolve as resolve9, sep as sep3 } from "path";
|
|
@@ -9457,7 +9640,7 @@ function matchesPolicy(cwd, path, paths, includeParents = false, options = {}) {
|
|
|
9457
9640
|
var insideRoot = (rel) => rel !== ".." && !rel.startsWith(`..${sep3}`) && !isAbsolute5(rel), within = (path, root) => path === root || path.startsWith(root.endsWith(sep3) ? root : root + sep3), beneath = (path, root) => within(path.toLowerCase(), root.toLowerCase()) || within(foldSegment(path), foldSegment(root)), lowerBeneath = (path, root) => within(path.toLowerCase(), root.toLowerCase());
|
|
9458
9641
|
var init_path_policy = __esm(() => {
|
|
9459
9642
|
init_project();
|
|
9460
|
-
|
|
9643
|
+
init_permission_paths();
|
|
9461
9644
|
});
|
|
9462
9645
|
|
|
9463
9646
|
// src/local/deny.ts
|
|
@@ -14799,7 +14982,7 @@ var package_default;
|
|
|
14799
14982
|
var init_package = __esm(() => {
|
|
14800
14983
|
package_default = {
|
|
14801
14984
|
name: "@staix/agent-hub",
|
|
14802
|
-
version: "0.
|
|
14985
|
+
version: "0.51.0",
|
|
14803
14986
|
description: "Native multi-agent hub: Claude Code, Codex, Kimi Code, Pi and local inference as peers in one project",
|
|
14804
14987
|
license: "MIT",
|
|
14805
14988
|
type: "module",
|
|
@@ -15993,49 +16176,6 @@ var init_capacity = __esm(() => {
|
|
|
15993
16176
|
init_capture();
|
|
15994
16177
|
});
|
|
15995
16178
|
|
|
15996
|
-
// node_modules/@staix/cli-output/src/index.ts
|
|
15997
|
-
function terminalText(value, options = {}) {
|
|
15998
|
-
const text = String(value ?? "").replace(/\r\n?/g, `
|
|
15999
|
-
`).replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/g, "").replace(/\x1b[P_X^][\s\S]*?(?:\x1b\\|$)/g, "").replace(/(?:\x1b\[|\x9b)[0-?]*[ -/]*(?:[@-~]|(?=\n|$))/g, "").replace(/\x1b[^\n]?/g, "");
|
|
16000
|
-
return options.singleLine ? text.replace(/[\x00-\x1f\x7f-\x9f]/g, " ") : text.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
16001
|
-
}
|
|
16002
|
-
function paint(spans, color, styles = {}) {
|
|
16003
|
-
return spans.map((span) => {
|
|
16004
|
-
const text = terminalText(span.text);
|
|
16005
|
-
const role = span.role && Object.hasOwn(ROLE_SGR, span.role) ? ROLE_SGR[span.role] : undefined;
|
|
16006
|
-
const custom = span.style && Object.hasOwn(styles, span.style) ? styles[span.style] : undefined;
|
|
16007
|
-
if (custom && !/^\x1b\[[0-9;]+m$/.test(custom))
|
|
16008
|
-
throw new Error(`invalid SGR for style ${span.style}`);
|
|
16009
|
-
const sgr = role !== undefined ? role : custom;
|
|
16010
|
-
return color && sgr && text ? sgr + text + SGR_RESET : text;
|
|
16011
|
-
}).join("");
|
|
16012
|
-
}
|
|
16013
|
-
var SGR_RESET = "\x1B[0m", ROLE_SGR, MARKERS, EXIT;
|
|
16014
|
-
var init_src = __esm(() => {
|
|
16015
|
-
ROLE_SGR = Object.freeze({
|
|
16016
|
-
header: "\x1B[1;34m",
|
|
16017
|
-
section: "\x1B[1;35m",
|
|
16018
|
-
key: "\x1B[34m",
|
|
16019
|
-
value: "",
|
|
16020
|
-
success: "\x1B[1;32m",
|
|
16021
|
-
warning: "\x1B[1;33m",
|
|
16022
|
-
error: "\x1B[1;31m",
|
|
16023
|
-
hint: "\x1B[90m",
|
|
16024
|
-
accent: "\x1B[36m"
|
|
16025
|
-
});
|
|
16026
|
-
MARKERS = Object.freeze({
|
|
16027
|
-
ok: { glyph: "\u2713", ascii: "ok", role: "success" },
|
|
16028
|
-
fail: { glyph: "\u2717", ascii: "x", role: "error" },
|
|
16029
|
-
warn: { glyph: "\u26A0", ascii: "!", role: "warning" },
|
|
16030
|
-
absent: { glyph: "-", ascii: "-", role: "hint" },
|
|
16031
|
-
unknown: { glyph: "?", ascii: "?", role: "hint" },
|
|
16032
|
-
pending: { glyph: "~", ascii: "~", role: "hint" },
|
|
16033
|
-
active: { glyph: "*", ascii: "*", role: "success" },
|
|
16034
|
-
next: { glyph: "\u2192", ascii: "->", role: "accent" }
|
|
16035
|
-
});
|
|
16036
|
-
EXIT = Object.freeze({ ok: 0, fail: 1, usage: 2, tempfail: 75 });
|
|
16037
|
-
});
|
|
16038
|
-
|
|
16039
16179
|
// node_modules/@staix/agent-mem/src/memory/style.ts
|
|
16040
16180
|
function style(color, ascii = true) {
|
|
16041
16181
|
return {
|
|
@@ -19028,7 +19168,7 @@ function own3(value, key) {
|
|
|
19028
19168
|
throw unavailable2;
|
|
19029
19169
|
return descriptor?.value;
|
|
19030
19170
|
}
|
|
19031
|
-
function
|
|
19171
|
+
function plain3(value) {
|
|
19032
19172
|
return !!value && typeof value === "object" && !types6.isProxy(value) && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
19033
19173
|
}
|
|
19034
19174
|
function dataArray(value) {
|
|
@@ -19037,7 +19177,7 @@ function dataArray(value) {
|
|
|
19037
19177
|
function command(argumentsText) {
|
|
19038
19178
|
try {
|
|
19039
19179
|
const args = JSON.parse(argumentsText);
|
|
19040
|
-
if (!
|
|
19180
|
+
if (!plain3(args))
|
|
19041
19181
|
return { explicit: true };
|
|
19042
19182
|
const value = own3(args, "command");
|
|
19043
19183
|
return { explicit: Object.hasOwn(args, "command"), ...typeof value === "string" ? { value } : {} };
|
|
@@ -19138,7 +19278,7 @@ function projectOutcomeWithContext(assistant, tools, prior = []) {
|
|
|
19138
19278
|
if (!dataArray(tools) || tools.length > WIRE_BYTES2 / 20 || !dataArray(prior) || prior.length > WIRE_BYTES2 / 20)
|
|
19139
19279
|
return;
|
|
19140
19280
|
for (const entry of prior) {
|
|
19141
|
-
if (!
|
|
19281
|
+
if (!plain3(entry) || Object.keys(entry).some((key) => key !== "digest" && key !== "operation") || typeof own3(entry, "digest") !== "string" || !/^[a-f0-9]{64}$/.test(own3(entry, "digest")))
|
|
19142
19282
|
return;
|
|
19143
19283
|
if (Object.hasOwn(entry, "operation")) {
|
|
19144
19284
|
const name = own3(entry, "operation");
|
|
@@ -21080,18 +21220,6 @@ function kimiAcpCommand(command, model) {
|
|
|
21080
21220
|
return [cmd, ...model ? ["--model", model, ...args] : args];
|
|
21081
21221
|
}
|
|
21082
21222
|
|
|
21083
|
-
// src/cli/output-standard.ts
|
|
21084
|
-
var TONE_SGR;
|
|
21085
|
-
var init_output_standard = __esm(() => {
|
|
21086
|
-
init_src();
|
|
21087
|
-
TONE_SGR = Object.freeze({ strong: "\x1B[1;36m", failure: "\x1B[31m", number: "\x1B[1m", issueRef: "\x1B[4m", taskRef: "\x1B[4;35m" });
|
|
21088
|
-
});
|
|
21089
|
-
|
|
21090
|
-
// src/cli/warn-line.ts
|
|
21091
|
-
var init_warn_line = __esm(() => {
|
|
21092
|
-
init_output_standard();
|
|
21093
|
-
});
|
|
21094
|
-
|
|
21095
21223
|
// src/adapters/definitions/native-cli-retained.ts
|
|
21096
21224
|
function retainedLaunchWarning(status, peer, definition) {
|
|
21097
21225
|
const keys = definition.cli.launchConfigKeys;
|
|
@@ -21121,6 +21249,11 @@ function sessionSettings(tee, facts) {
|
|
|
21121
21249
|
if (facts.observeNative)
|
|
21122
21250
|
Object.assign(settings.hooks, { SessionStart: [{ matcher: "*", hooks }], UserPromptSubmit: [{ hooks }] });
|
|
21123
21251
|
}
|
|
21252
|
+
if (facts?.startCheck) {
|
|
21253
|
+
const check = { type: "command", command: `AGENTHUB_STATE_DIR=${sh(facts.stateDir)} AGENTHUB_HOOK_PURPOSE='start-check' bun ${sh(facts.script)}`, timeout: START_HOOK_TIMEOUT_S };
|
|
21254
|
+
const hooks = settings.hooks ?? (settings.hooks = {});
|
|
21255
|
+
hooks.SessionStart = [...hooks.SessionStart ?? [], { matcher: "startup|resume", hooks: [check] }];
|
|
21256
|
+
}
|
|
21124
21257
|
return JSON.stringify(settings);
|
|
21125
21258
|
}
|
|
21126
21259
|
var CLAUDE_CHANNEL = "plugin:agent-hub@agent-hub", UNATTENDED_WARNING = "WARNING: --unattended disables permission prompts. Other agents' messages are untrusted input and this agent will act on its own judgment without asking you.", sh = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
@@ -21131,6 +21264,7 @@ var init_launch2 = __esm(() => {
|
|
|
21131
21264
|
init_project();
|
|
21132
21265
|
init_child_process();
|
|
21133
21266
|
init_registry();
|
|
21267
|
+
init_launch_check();
|
|
21134
21268
|
init_warn_line();
|
|
21135
21269
|
init_qwen_native();
|
|
21136
21270
|
});
|
|
@@ -22097,6 +22231,214 @@ var init_hooks2 = __esm(() => {
|
|
|
22097
22231
|
AGY_FACTS_HOOK = { decode: decodeAgyHook, encode: encodeAgyHook, read: readAgyTranscript };
|
|
22098
22232
|
});
|
|
22099
22233
|
|
|
22234
|
+
// src/adapters/kimi-tui-facts.ts
|
|
22235
|
+
import { closeSync as closeSync14, constants as constants11, fstatSync as fstatSync13, lstatSync as lstatSync24, openSync as openSync14, readSync as readSync11, readdirSync as readdirSync5 } from "fs";
|
|
22236
|
+
import { createHash as createHash13 } from "crypto";
|
|
22237
|
+
import { basename as basename6, dirname as dirname15, isAbsolute as isAbsolute8, join as join24, relative as relative6 } from "path";
|
|
22238
|
+
import { homedir as homedir6 } from "os";
|
|
22239
|
+
function decodeKimiTuiHook(event, value) {
|
|
22240
|
+
if (!EVENTS3.includes(event) || !record7(value) || value.hook_event_name !== event || value.client_type !== "kimi_code_cli" || typeof value.session_id !== "string" || !SESSION.test(value.session_id) || typeof value.cwd !== "string" || !isAbsolute8(value.cwd) || value.cwd.length > 4096)
|
|
22241
|
+
return;
|
|
22242
|
+
if ((event === "TurnStarted" || event === "Interrupt") && !integer2(value.turn_id))
|
|
22243
|
+
return;
|
|
22244
|
+
if (event === "TaskStarted" && (typeof value.task_id !== "string" || !TASK.test(value.task_id)))
|
|
22245
|
+
return;
|
|
22246
|
+
const home = process.env.KIMI_CODE_HOME ?? join24(process.env.HOME ?? homedir6(), ".kimi-code");
|
|
22247
|
+
const transcriptPath = value.agentHubTranscriptPath ?? join24(home, "session_index.jsonl");
|
|
22248
|
+
if (typeof transcriptPath !== "string" || !isAbsolute8(transcriptPath) || transcriptPath.length > 4096)
|
|
22249
|
+
return;
|
|
22250
|
+
const phase = { TurnStarted: "start", Stop: "stop", StopFailure: "stop", Interrupt: "stop", SessionEnd: "session", TaskStarted: "pre", Notification: "post" }[event];
|
|
22251
|
+
return { event, phase, sessionId: value.session_id, transcriptPath, workspacePaths: [value.cwd], tool: "", input: {} };
|
|
22252
|
+
}
|
|
22253
|
+
function encodeKimiTuiHook() {
|
|
22254
|
+
return;
|
|
22255
|
+
}
|
|
22256
|
+
function readBytes(path, cap, tail = false) {
|
|
22257
|
+
const link = lstatSync24(path);
|
|
22258
|
+
if (!link.isFile() || link.isSymbolicLink() || link.nlink !== 1)
|
|
22259
|
+
throw new Error("not a regular file");
|
|
22260
|
+
const fd = openSync14(path, constants11.O_RDONLY | constants11.O_NOFOLLOW);
|
|
22261
|
+
try {
|
|
22262
|
+
const stat = fstatSync13(fd);
|
|
22263
|
+
if (!stat.isFile() || stat.nlink !== 1 || !tail && stat.size > cap)
|
|
22264
|
+
throw new Error("invalid file");
|
|
22265
|
+
const length = Math.min(stat.size, cap), start = tail ? stat.size - length : 0;
|
|
22266
|
+
const bytes = Buffer.alloc(length);
|
|
22267
|
+
let offset = 0;
|
|
22268
|
+
while (offset < length) {
|
|
22269
|
+
const count = readSync11(fd, bytes, offset, length - offset, start + offset);
|
|
22270
|
+
if (count <= 0)
|
|
22271
|
+
throw new Error("short read");
|
|
22272
|
+
offset += count;
|
|
22273
|
+
}
|
|
22274
|
+
return bytes;
|
|
22275
|
+
} finally {
|
|
22276
|
+
closeSync14(fd);
|
|
22277
|
+
}
|
|
22278
|
+
}
|
|
22279
|
+
function sessionDirectory(index, session) {
|
|
22280
|
+
const home = dirname15(index), sessions = realPath(join24(home, "sessions"));
|
|
22281
|
+
let listed;
|
|
22282
|
+
for (const line of readBytes(index, INDEX_CAP2).toString("utf8").split(`
|
|
22283
|
+
`)) {
|
|
22284
|
+
if (!line.includes(session))
|
|
22285
|
+
continue;
|
|
22286
|
+
let row;
|
|
22287
|
+
try {
|
|
22288
|
+
row = JSON.parse(line);
|
|
22289
|
+
} catch {
|
|
22290
|
+
continue;
|
|
22291
|
+
}
|
|
22292
|
+
if (record7(row) && row.sessionId === session && typeof row.sessionDir === "string") {
|
|
22293
|
+
if (listed)
|
|
22294
|
+
throw new Error("duplicate session");
|
|
22295
|
+
listed = row.sessionDir;
|
|
22296
|
+
}
|
|
22297
|
+
}
|
|
22298
|
+
if (!listed)
|
|
22299
|
+
throw new Error("session not indexed");
|
|
22300
|
+
const directory = realPath(listed);
|
|
22301
|
+
if (!inside3(sessions, directory))
|
|
22302
|
+
throw new Error("session outside home");
|
|
22303
|
+
return directory;
|
|
22304
|
+
}
|
|
22305
|
+
function taskInventory(agents) {
|
|
22306
|
+
let active = 0;
|
|
22307
|
+
const names = readdirSync5(agents, { withFileTypes: true });
|
|
22308
|
+
if (names.length > MAX_AGENTS2)
|
|
22309
|
+
throw new Error("too many agents");
|
|
22310
|
+
for (const entry of names) {
|
|
22311
|
+
if (!AGENT.test(entry.name))
|
|
22312
|
+
continue;
|
|
22313
|
+
if (!entry.isDirectory())
|
|
22314
|
+
continue;
|
|
22315
|
+
const tasks = join24(agents, entry.name, "tasks");
|
|
22316
|
+
const dir = lstatSync24(tasks, { throwIfNoEntry: false });
|
|
22317
|
+
if (!dir)
|
|
22318
|
+
continue;
|
|
22319
|
+
if (!dir.isDirectory() || dir.isSymbolicLink())
|
|
22320
|
+
throw new Error("invalid task directory");
|
|
22321
|
+
const files = readdirSync5(tasks).filter((name) => name.endsWith(".json")).sort();
|
|
22322
|
+
if (files.length > MAX_TASKS)
|
|
22323
|
+
throw new Error("too many tasks");
|
|
22324
|
+
for (const name of files) {
|
|
22325
|
+
if (!TASK.test(name.slice(0, -5)))
|
|
22326
|
+
throw new Error("invalid task name");
|
|
22327
|
+
const row = JSON.parse(readBytes(join24(tasks, name), TASK_CAP).toString("utf8"));
|
|
22328
|
+
if (!record7(row) || row.taskId !== name.slice(0, -5) || typeof row.status !== "string")
|
|
22329
|
+
throw new Error("invalid task");
|
|
22330
|
+
if (row.status === "running" && row.endedAt === null) {
|
|
22331
|
+
active++;
|
|
22332
|
+
continue;
|
|
22333
|
+
}
|
|
22334
|
+
const terminal = ["completed", "failed", "cancelled"].includes(row.status) && integer2(row.endedAt);
|
|
22335
|
+
if (!terminal)
|
|
22336
|
+
throw new Error("unknown task state");
|
|
22337
|
+
}
|
|
22338
|
+
}
|
|
22339
|
+
return active;
|
|
22340
|
+
}
|
|
22341
|
+
function readKimiTuiTranscript(session, index) {
|
|
22342
|
+
if (!SESSION.test(session) || basename6(index) !== "session_index.jsonl" || !isAbsolute8(index))
|
|
22343
|
+
return empty();
|
|
22344
|
+
try {
|
|
22345
|
+
const directory = sessionDirectory(index, session);
|
|
22346
|
+
const wire = join24(directory, "agents", "main", "wire.jsonl");
|
|
22347
|
+
if (!inside3(directory, realPath(wire)))
|
|
22348
|
+
return empty();
|
|
22349
|
+
const bytes = readBytes(wire, WIRE_CAP, true);
|
|
22350
|
+
if (bytes.length === 0 || bytes[bytes.length - 1] !== 10)
|
|
22351
|
+
return empty();
|
|
22352
|
+
const lines = bytes.toString("utf8").split(`
|
|
22353
|
+
`);
|
|
22354
|
+
if (bytes.length === WIRE_CAP && !lines[0]?.startsWith('{"type":"metadata"'))
|
|
22355
|
+
lines.shift();
|
|
22356
|
+
const prompts = new Map;
|
|
22357
|
+
const ends = new Map;
|
|
22358
|
+
const promptEnds = new Map;
|
|
22359
|
+
const promptEndTurnIds = new Map;
|
|
22360
|
+
let started;
|
|
22361
|
+
for (const line of lines) {
|
|
22362
|
+
if (!line || !/"(?:turn\.prompt|turn\.ended|prompt\.completed|prompt\.aborted)"/.test(line))
|
|
22363
|
+
continue;
|
|
22364
|
+
let row;
|
|
22365
|
+
try {
|
|
22366
|
+
row = JSON.parse(line);
|
|
22367
|
+
} catch {
|
|
22368
|
+
return empty();
|
|
22369
|
+
}
|
|
22370
|
+
if (!record7(row))
|
|
22371
|
+
return empty();
|
|
22372
|
+
if (row.type === "turn.prompt" && integer2(row.turnId) && record7(row.origin) && typeof row.origin.kind === "string") {
|
|
22373
|
+
const turn = row.turnId, id = typeof row.promptId === "string" ? row.promptId : typeof row.origin.notificationId === "string" ? row.origin.notificationId : `turn-${turn}`;
|
|
22374
|
+
const prompt = { turn, id, origin: row.origin.kind };
|
|
22375
|
+
prompts.set(turn, prompt);
|
|
22376
|
+
started = prompt;
|
|
22377
|
+
} else if (row.type === "turn.ended" && integer2(row.turnId) && ["completed", "failed", "cancelled"].includes(String(row.reason))) {
|
|
22378
|
+
const turn = row.turnId;
|
|
22379
|
+
ends.set(turn, { turn, reason: row.reason });
|
|
22380
|
+
} else if (row.type === "prompt.completed" && typeof row.promptId === "string" && ["completed", "failed"].includes(String(row.reason))) {
|
|
22381
|
+
promptEnds.set(row.promptId, row.reason);
|
|
22382
|
+
if (integer2(row.turnId))
|
|
22383
|
+
promptEndTurnIds.set(row.turnId, row.promptId);
|
|
22384
|
+
} else if (row.type === "prompt.aborted" && typeof row.promptId === "string") {
|
|
22385
|
+
promptEnds.set(row.promptId, "cancelled");
|
|
22386
|
+
if (integer2(row.turnId))
|
|
22387
|
+
promptEndTurnIds.set(row.turnId, row.promptId);
|
|
22388
|
+
} else if (row.type === "turn.prompt" || row.type === "turn.ended")
|
|
22389
|
+
return empty();
|
|
22390
|
+
}
|
|
22391
|
+
let completion;
|
|
22392
|
+
for (const [turn, end] of ends) {
|
|
22393
|
+
const prompt = prompts.get(turn), promptReason = prompt ? promptEnds.get(prompt.id) : undefined, turnPromptId = promptEndTurnIds.get(turn);
|
|
22394
|
+
if (!prompt || promptReason !== undefined && promptReason !== end.reason || turnPromptId !== undefined && turnPromptId !== prompt.id)
|
|
22395
|
+
continue;
|
|
22396
|
+
completion = { id: createHash13("sha256").update(`${session}:${turn}:${prompt.id}:${end.reason}`).digest("hex"), index: turn, reason: end.reason };
|
|
22397
|
+
}
|
|
22398
|
+
let background;
|
|
22399
|
+
try {
|
|
22400
|
+
background = taskInventory(join24(directory, "agents"));
|
|
22401
|
+
} catch {}
|
|
22402
|
+
return {
|
|
22403
|
+
factIds: [],
|
|
22404
|
+
...completion ? { completion } : {},
|
|
22405
|
+
...started ? { started: { id: createHash13("sha256").update(`${session}:${started.turn}:${started.id}`).digest("hex"), index: started.turn, origin: started.origin } } : {},
|
|
22406
|
+
...background === undefined ? {} : { background }
|
|
22407
|
+
};
|
|
22408
|
+
} catch {
|
|
22409
|
+
return empty();
|
|
22410
|
+
}
|
|
22411
|
+
}
|
|
22412
|
+
var EVENTS3, SESSION, AGENT, TASK, INDEX_CAP2, WIRE_CAP, TASK_CAP, MAX_AGENTS2 = 256, MAX_TASKS = 256, record7 = (value) => !!value && typeof value === "object" && !Array.isArray(value), integer2 = (value) => Number.isSafeInteger(value) && value >= 0, inside3 = (root, path) => {
|
|
22413
|
+
const rel = relative6(root, path);
|
|
22414
|
+
return rel !== "" && rel !== ".." && !rel.startsWith("../") && !isAbsolute8(rel);
|
|
22415
|
+
}, empty = () => ({ factIds: [] }), KIMI_TUI_FACTS_HOOK;
|
|
22416
|
+
var init_kimi_tui_facts = __esm(() => {
|
|
22417
|
+
init_project();
|
|
22418
|
+
EVENTS3 = ["TurnStarted", "Stop", "StopFailure", "Interrupt", "SessionEnd", "TaskStarted", "Notification"];
|
|
22419
|
+
SESSION = /^session_[A-Za-z0-9_-]{1,120}$/;
|
|
22420
|
+
AGENT = /^[A-Za-z0-9._-]{1,64}$/;
|
|
22421
|
+
TASK = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
22422
|
+
INDEX_CAP2 = 16 * 1024 * 1024;
|
|
22423
|
+
WIRE_CAP = 8 * 1024 * 1024;
|
|
22424
|
+
TASK_CAP = 64 * 1024;
|
|
22425
|
+
KIMI_TUI_FACTS_HOOK = { decode: decodeKimiTuiHook, encode: encodeKimiTuiHook, read: readKimiTuiTranscript };
|
|
22426
|
+
});
|
|
22427
|
+
|
|
22428
|
+
// src/adapters/native-facts-hooks.ts
|
|
22429
|
+
function nativeFactsHook(peer) {
|
|
22430
|
+
return Object.hasOwn(NATIVE_FACTS_HOOKS, peer) ? NATIVE_FACTS_HOOKS[peer] : undefined;
|
|
22431
|
+
}
|
|
22432
|
+
var NATIVE_FACTS_HOOKS;
|
|
22433
|
+
var init_native_facts_hooks = __esm(() => {
|
|
22434
|
+
init_hooks2();
|
|
22435
|
+
init_kimi_tui_facts();
|
|
22436
|
+
NATIVE_FACTS_HOOKS = Object.freeze({
|
|
22437
|
+
agy: AGY_FACTS_HOOK,
|
|
22438
|
+
kimi: KIMI_TUI_FACTS_HOOK
|
|
22439
|
+
});
|
|
22440
|
+
});
|
|
22441
|
+
|
|
22100
22442
|
// src/adapters/agy/definition.ts
|
|
22101
22443
|
function agyLaunch(ctx) {
|
|
22102
22444
|
const argv = ["agy", ...ctx.userArgs], command = argv.map(shellQuote2).join(" ");
|
|
@@ -22107,7 +22449,7 @@ var DISPLAY, shellQuote2 = (value) => `'${value.replace(/'/g, `'\\''`)}'`, AGY_D
|
|
|
22107
22449
|
var init_definition = __esm(() => {
|
|
22108
22450
|
init_entry();
|
|
22109
22451
|
init_reviewer_variants();
|
|
22110
|
-
|
|
22452
|
+
init_native_facts_hooks();
|
|
22111
22453
|
DISPLAY = { palette: { fg: "#6558a6", bg: "#f1effa" } };
|
|
22112
22454
|
AGY_DEFINITION = {
|
|
22113
22455
|
api: 1,
|
|
@@ -22156,7 +22498,7 @@ var init_definition = __esm(() => {
|
|
|
22156
22498
|
routing: { allowedRoles: ["implementer", "verifier"] },
|
|
22157
22499
|
reviewer: { defaultPool: false, declaration: "automatic", unavailable: "agy is an implementer peer (#485)" },
|
|
22158
22500
|
reviewerVariant: AGY_REVIEWER_VARIANT,
|
|
22159
|
-
hooks: { factsHook:
|
|
22501
|
+
hooks: { factsHook: NATIVE_FACTS_HOOKS.agy }
|
|
22160
22502
|
};
|
|
22161
22503
|
});
|
|
22162
22504
|
|
|
@@ -22164,9 +22506,71 @@ var init_definition = __esm(() => {
|
|
|
22164
22506
|
function builtinCliEntries(definitions) {
|
|
22165
22507
|
return Object.freeze(definitions.flatMap((definition) => definition.cli.entry ? [Object.freeze({ ...definition.cli.entry, command: definition.cli.command })] : []));
|
|
22166
22508
|
}
|
|
22509
|
+
// src/adapters/claude-channel-evidence.ts
|
|
22510
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
22511
|
+
function classifyClaudeParentCommand(command, rejectedArgument) {
|
|
22512
|
+
if (!command || command.length > 4096 || /[\n\r\0]/.test(command))
|
|
22513
|
+
return "launch-unverified";
|
|
22514
|
+
const argv = command.trim().split(/\s+/);
|
|
22515
|
+
const executable = argv[0]?.split("/").at(-1);
|
|
22516
|
+
const reject = (position) => {
|
|
22517
|
+
rejectedArgument?.(position);
|
|
22518
|
+
return "launch-unverified";
|
|
22519
|
+
};
|
|
22520
|
+
if (executable !== "claude")
|
|
22521
|
+
return reject(0);
|
|
22522
|
+
if (argv[1] !== "--dangerously-load-development-channels")
|
|
22523
|
+
return reject(1);
|
|
22524
|
+
if (argv.length < 3 || !TARGETS.has(argv[2]))
|
|
22525
|
+
return reject(2);
|
|
22526
|
+
const rejected = argv.slice(3).findIndex((arg) => DISABLING.has(arg) || arg.startsWith("--print=") || arg.startsWith("--output-format=") || arg.startsWith("-p") || arg === "--dangerously-load-development-channels" || arg.startsWith("--dangerously-load-development-channels="));
|
|
22527
|
+
if (rejected >= 0)
|
|
22528
|
+
return reject(rejected + 3);
|
|
22529
|
+
return "development-channel-launch";
|
|
22530
|
+
}
|
|
22531
|
+
function readClaudeParentCommand(ppid) {
|
|
22532
|
+
try {
|
|
22533
|
+
const result = spawnSync4("/bin/ps", ["-ww", "-p", String(ppid), "-o", "command="], {
|
|
22534
|
+
encoding: "utf8",
|
|
22535
|
+
timeout: 1500,
|
|
22536
|
+
maxBuffer: 4096,
|
|
22537
|
+
env: { PATH: "/usr/bin:/bin", LC_ALL: "C" }
|
|
22538
|
+
});
|
|
22539
|
+
if (result.error || result.status !== 0 || typeof result.stdout !== "string" || !result.stdout.trim() || result.stdout.trim().includes(`
|
|
22540
|
+
`))
|
|
22541
|
+
return;
|
|
22542
|
+
return result.stdout.trim();
|
|
22543
|
+
} catch {
|
|
22544
|
+
return;
|
|
22545
|
+
}
|
|
22546
|
+
}
|
|
22547
|
+
function claudeChannelEvidence(env = process.env, ppid = process.ppid, read = claudeParentCommandPort.read) {
|
|
22548
|
+
if (env.AGENTHUB_CHANNEL !== "1")
|
|
22549
|
+
return "unknown";
|
|
22550
|
+
if (!Number.isSafeInteger(ppid) || ppid <= 1)
|
|
22551
|
+
return "unknown";
|
|
22552
|
+
try {
|
|
22553
|
+
const command = read(ppid);
|
|
22554
|
+
if (!command || process.ppid !== ppid)
|
|
22555
|
+
return "unknown";
|
|
22556
|
+
return classifyClaudeParentCommand(command);
|
|
22557
|
+
} catch {
|
|
22558
|
+
return "unknown";
|
|
22559
|
+
}
|
|
22560
|
+
}
|
|
22561
|
+
function currentClaudeChannelEvidence() {
|
|
22562
|
+
return claudeChannelEvidence();
|
|
22563
|
+
}
|
|
22564
|
+
var claudeParentCommandPort, TARGETS, DISABLING;
|
|
22565
|
+
var init_claude_channel_evidence = __esm(() => {
|
|
22566
|
+
claudeParentCommandPort = { read: readClaudeParentCommand };
|
|
22567
|
+
TARGETS = new Set(["plugin:agent-hub@agent-hub", "server:agent-hub"]);
|
|
22568
|
+
DISABLING = new Set(["-p", "--print", "--output-format", "--background", "--detach", "--daemon", "daemon", "bg", "bg-spare"]);
|
|
22569
|
+
});
|
|
22570
|
+
|
|
22167
22571
|
// src/adapters/definitions/native-cli-entry-claude.ts
|
|
22168
22572
|
import { readFileSync as readFileSync11 } from "fs";
|
|
22169
|
-
import { join as
|
|
22573
|
+
import { join as join25 } from "path";
|
|
22170
22574
|
import { randomUUID as randomUUID10 } from "crypto";
|
|
22171
22575
|
function managedSession(nativeArgs) {
|
|
22172
22576
|
const separator = nativeArgs.indexOf("--");
|
|
@@ -22186,7 +22590,7 @@ function managedSession(nativeArgs) {
|
|
|
22186
22590
|
if (resume.length)
|
|
22187
22591
|
return resume.length === 1 && isClaudeSessionUuid(resume[0]) ? resume[0] : undefined;
|
|
22188
22592
|
const id = randomUUID10();
|
|
22189
|
-
nativeArgs.
|
|
22593
|
+
nativeArgs.splice(options.length, 0, "--session-id", id);
|
|
22190
22594
|
return id;
|
|
22191
22595
|
}
|
|
22192
22596
|
async function runClaudeEntry(ctx) {
|
|
@@ -22238,17 +22642,19 @@ async function runClaudeEntry(ctx) {
|
|
|
22238
22642
|
}
|
|
22239
22643
|
}
|
|
22240
22644
|
let original;
|
|
22241
|
-
for (const file of [
|
|
22645
|
+
for (const file of [join25(executionCwd, ".claude", "settings.local.json"), join25(executionCwd, ".claude", "settings.json"), join25(process.env.HOME ?? "", ".claude", "settings.json")]) {
|
|
22242
22646
|
try {
|
|
22243
22647
|
original ??= JSON.parse(readFileSync11(file, "utf8")).statusLine;
|
|
22244
22648
|
} catch {}
|
|
22245
22649
|
}
|
|
22246
|
-
const facts = claudeObservationHooks(projectConfig(), { script:
|
|
22650
|
+
const facts = claudeObservationHooks(projectConfig(), { script: join25(cliDir, "facts-hook.ts"), stateDir });
|
|
22651
|
+
if (facts)
|
|
22652
|
+
facts.startCheck = true;
|
|
22247
22653
|
let previousLaunch;
|
|
22248
22654
|
try {
|
|
22249
|
-
previousLaunch = JSON.parse(readFileSync11(
|
|
22655
|
+
previousLaunch = JSON.parse(readFileSync11(join25(stateDir, claudeStateFile("claude-launch", peer)), "utf8"));
|
|
22250
22656
|
} catch {}
|
|
22251
|
-
const launch = buildLaunch("claude", args, { unattended: unattendedEnv, statusLine: { script:
|
|
22657
|
+
const launch = buildLaunch("claude", args, { unattended: unattendedEnv, statusLine: { script: join25(cliDir, "statusline-tee.ts"), stateDir, ...original ? { original } : {} }, ...facts ? { facts } : {} });
|
|
22252
22658
|
let result;
|
|
22253
22659
|
try {
|
|
22254
22660
|
let launchRecord;
|
|
@@ -22260,12 +22666,25 @@ async function runClaudeEntry(ctx) {
|
|
|
22260
22666
|
recordClaudeLaunch(stateDir, launchRecord);
|
|
22261
22667
|
cleanupStaleClaudeSettings(stateDir, previousLaunch);
|
|
22262
22668
|
}
|
|
22669
|
+
let rejectedPosition;
|
|
22670
|
+
const evidence = classifyClaudeParentCommand([launch.cmd, ...launch.args].join(" "), (position) => {
|
|
22671
|
+
rejectedPosition = position;
|
|
22672
|
+
});
|
|
22673
|
+
if (evidence !== "development-channel-launch") {
|
|
22674
|
+
const cause = rejectedPosition === undefined ? "command length or control characters" : `argv[${rejectedPosition}]`;
|
|
22675
|
+
console.error(`Hub check failed for Claude channel (${evidence} at ${cause}). ${claudeArgvNextStep([launch.cmd, ...launch.args].join(" "), rejectedPosition)}`);
|
|
22676
|
+
}
|
|
22263
22677
|
if (launch.warning)
|
|
22264
22678
|
console.error(launch.warning);
|
|
22679
|
+
const beforeSpawn = async () => {
|
|
22680
|
+
if (process.stderr.isTTY !== true)
|
|
22681
|
+
return;
|
|
22682
|
+
printLaunchCheck({ hubCheck: await readLaunchCheck((timeoutMs) => ctx.connectOnce(timeoutMs)) }, peer, ctx.definition, "tui");
|
|
22683
|
+
};
|
|
22265
22684
|
const env = nativeLaunchEnv("claude", childEnv());
|
|
22266
22685
|
if (ctx.instance)
|
|
22267
22686
|
env.AGENTHUB_PEER_ID = peer;
|
|
22268
|
-
result = await runClaudeLaunch(launch, { cwd: executionCwd, stateDir, env: { ...env, AGENTHUB_STATE_DIR: stateDir, AGENTHUB_PROJECT_DIR: cwd }, ...launchRecord ? { record: launchRecord } : {} });
|
|
22687
|
+
result = await runClaudeLaunch(launch, { cwd: executionCwd, stateDir, env: { ...env, AGENTHUB_STATE_DIR: stateDir, AGENTHUB_PROJECT_DIR: cwd }, ...launchRecord ? { record: launchRecord } : {}, beforeSpawn });
|
|
22269
22688
|
} finally {
|
|
22270
22689
|
cleanupClaudeSettings(stateDir, launch.settingsFile);
|
|
22271
22690
|
}
|
|
@@ -22274,7 +22693,9 @@ async function runClaudeEntry(ctx) {
|
|
|
22274
22693
|
process.exit(result.status ?? 1);
|
|
22275
22694
|
}
|
|
22276
22695
|
var init_native_cli_entry_claude = __esm(() => {
|
|
22696
|
+
init_claude_channel_evidence();
|
|
22277
22697
|
init_claude_state();
|
|
22698
|
+
init_launch_check();
|
|
22278
22699
|
});
|
|
22279
22700
|
|
|
22280
22701
|
// src/adapters/definitions/native-cli-entry-codex.ts
|
|
@@ -22312,6 +22733,7 @@ async function runCodexEntry(ctx) {
|
|
|
22312
22733
|
const warning = retainedLaunchWarning(snapshot, peer, ctx.definition);
|
|
22313
22734
|
if (warning)
|
|
22314
22735
|
console.error(warning);
|
|
22736
|
+
printLaunchCheck(snapshot, peer, ctx.definition, "tui");
|
|
22315
22737
|
const res = await hub.request({ t: "start", peer, args: { unattended: launch0.unattended === true }, operationId: process.env.AGENTHUB_RECOVERY_OPERATION });
|
|
22316
22738
|
if (!res.ok) {
|
|
22317
22739
|
hub.close();
|
|
@@ -22341,14 +22763,16 @@ async function runCodexEntry(ctx) {
|
|
|
22341
22763
|
console.error(launch0.warning);
|
|
22342
22764
|
exec(launch.cmd, launch.args, "codex");
|
|
22343
22765
|
}
|
|
22344
|
-
var init_native_cli_entry_codex = () => {
|
|
22766
|
+
var init_native_cli_entry_codex = __esm(() => {
|
|
22767
|
+
init_launch_check();
|
|
22768
|
+
});
|
|
22345
22769
|
|
|
22346
22770
|
// src/cli/kimi-plugin.ts
|
|
22347
22771
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
22348
|
-
import { closeSync as
|
|
22349
|
-
import { dirname as
|
|
22772
|
+
import { closeSync as closeSync15, lstatSync as lstatSync25, mkdirSync as mkdirSync12, openSync as openSync15, readFileSync as readFileSync12, renameSync as renameSync6, rmdirSync as rmdirSync4, unlinkSync as unlinkSync4, writeFileSync as writeFileSync10 } from "fs";
|
|
22773
|
+
import { dirname as dirname16, isAbsolute as isAbsolute9, join as join26 } from "path";
|
|
22350
22774
|
function file(path, cap) {
|
|
22351
|
-
const stat =
|
|
22775
|
+
const stat = lstatSync25(path, { throwIfNoEntry: false });
|
|
22352
22776
|
if (!stat)
|
|
22353
22777
|
return;
|
|
22354
22778
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size > cap)
|
|
@@ -22368,33 +22792,33 @@ function parse2(value, name) {
|
|
|
22368
22792
|
}
|
|
22369
22793
|
}
|
|
22370
22794
|
function atomic(path, bytes, before) {
|
|
22371
|
-
const current =
|
|
22795
|
+
const current = lstatSync25(path, { throwIfNoEntry: false });
|
|
22372
22796
|
if (before ? !current || current.dev !== before.dev || current.ino !== before.ino : current)
|
|
22373
22797
|
throw new Error(`${path} changed before its managed write`);
|
|
22374
22798
|
const temporary = `${path}.${randomUUID11()}.tmp`;
|
|
22375
22799
|
let fd;
|
|
22376
22800
|
try {
|
|
22377
|
-
fd =
|
|
22801
|
+
fd = openSync15(temporary, "wx", 384);
|
|
22378
22802
|
writeFileSync10(fd, bytes);
|
|
22379
|
-
|
|
22803
|
+
closeSync15(fd);
|
|
22380
22804
|
fd = undefined;
|
|
22381
22805
|
renameSync6(temporary, path);
|
|
22382
22806
|
} finally {
|
|
22383
22807
|
if (fd !== undefined)
|
|
22384
|
-
|
|
22808
|
+
closeSync15(fd);
|
|
22385
22809
|
try {
|
|
22386
22810
|
unlinkSync4(temporary);
|
|
22387
22811
|
} catch {}
|
|
22388
22812
|
}
|
|
22389
22813
|
}
|
|
22390
22814
|
function removeFile(path, expected) {
|
|
22391
|
-
const current =
|
|
22815
|
+
const current = lstatSync25(path, { throwIfNoEntry: false });
|
|
22392
22816
|
if (!current || !current.isFile() || current.isSymbolicLink() || current.nlink !== 1 || !readFileSync12(path).equals(expected))
|
|
22393
22817
|
return;
|
|
22394
22818
|
unlinkSync4(path);
|
|
22395
22819
|
}
|
|
22396
22820
|
function manifest() {
|
|
22397
|
-
return { name: ID2, version: "1.0.0", description: "Managed by the ahub kimi launcher for this launch only.", hooks:
|
|
22821
|
+
return { name: ID2, version: "1.0.0", description: "Managed by the ahub kimi launcher for this launch only.", hooks: EVENTS4.map((event) => ({ event, command: `bun ./kimi-hook.js ${event}`, timeout: 5 })) };
|
|
22398
22822
|
}
|
|
22399
22823
|
function ownerProof(options) {
|
|
22400
22824
|
const pid = options.ownerPid ?? process.pid, signature = options.ownerSignature ?? processSignature(pid);
|
|
@@ -22413,13 +22837,13 @@ function staleOwner(record, options) {
|
|
|
22413
22837
|
}
|
|
22414
22838
|
}
|
|
22415
22839
|
function plan2(options) {
|
|
22416
|
-
if (!
|
|
22840
|
+
if (!isAbsolute9(options.home) || !isAbsolute9(options.hookScript) || !/^[A-Za-z0-9._:-]{1,128}$/.test(options.launchId))
|
|
22417
22841
|
throw new Error("Kimi home, hook bundle and launch identity must be valid");
|
|
22418
22842
|
directory(options.home);
|
|
22419
22843
|
const hook = file(options.hookScript, MAX_HOOK);
|
|
22420
22844
|
if (!hook)
|
|
22421
22845
|
throw new Error("Kimi hook bundle is missing");
|
|
22422
|
-
const root =
|
|
22846
|
+
const root = join26(options.home, "plugins"), managed = join26(root, "managed", ID2), installed = join26(root, "installed.json");
|
|
22423
22847
|
const installedBefore = file(installed, MAX_INSTALLED), document = parse2(installedBefore, installed);
|
|
22424
22848
|
if (document && (document.version !== 1 || !Array.isArray(document.plugins)))
|
|
22425
22849
|
throw new Error(`${installed} has an unsupported shape`);
|
|
@@ -22432,11 +22856,11 @@ function plan2(options) {
|
|
|
22432
22856
|
if (record && (record.root !== managed || record.source !== "local-path" || record.origin !== "custom" || record.enabled !== true || typeof record.originalSource !== "string" || record.agentHubLaunch !== options.launchId && options.replaceStale !== true)) {
|
|
22433
22857
|
throw new Error("Kimi's agent-hub plugin belongs to another launch or is disabled; it was not changed");
|
|
22434
22858
|
}
|
|
22435
|
-
const manifestBefore = file(
|
|
22859
|
+
const manifestBefore = file(join26(managed, "kimi.plugin.json"), MAX_INSTALLED), hookBefore = file(join26(managed, "kimi-hook.js"), MAX_HOOK);
|
|
22436
22860
|
const nextManifest = Buffer.from(`${JSON.stringify(manifest(), null, 2)}
|
|
22437
22861
|
`);
|
|
22438
22862
|
const now = new Date(options.now ?? Date.now()).toISOString();
|
|
22439
|
-
const changed = !record || record.agentHubLaunch !== options.launchId || !record.agentHubOwner || !manifestBefore?.bytes.equals(nextManifest) || !hookBefore?.bytes.equals(hook.bytes) || record.originalSource !==
|
|
22863
|
+
const changed = !record || record.agentHubLaunch !== options.launchId || !record.agentHubOwner || !manifestBefore?.bytes.equals(nextManifest) || !hookBefore?.bytes.equals(hook.bytes) || record.originalSource !== dirname16(options.hookScript);
|
|
22440
22864
|
const nextRecord = {
|
|
22441
22865
|
id: ID2,
|
|
22442
22866
|
root: managed,
|
|
@@ -22445,7 +22869,7 @@ function plan2(options) {
|
|
|
22445
22869
|
enabled: true,
|
|
22446
22870
|
installedAt: typeof record?.installedAt === "string" ? record.installedAt : now,
|
|
22447
22871
|
updatedAt: changed ? now : typeof record?.updatedAt === "string" ? record.updatedAt : now,
|
|
22448
|
-
originalSource:
|
|
22872
|
+
originalSource: dirname16(options.hookScript),
|
|
22449
22873
|
agentHubLaunch: options.launchId,
|
|
22450
22874
|
agentHubOwner: record && record.agentHubLaunch === options.launchId && record.agentHubOwner ? record.agentHubOwner : ownerProof(options)
|
|
22451
22875
|
};
|
|
@@ -22457,36 +22881,36 @@ function plan2(options) {
|
|
|
22457
22881
|
...record ? { record } : {},
|
|
22458
22882
|
changed,
|
|
22459
22883
|
targets: [
|
|
22460
|
-
{ path:
|
|
22461
|
-
{ path:
|
|
22884
|
+
{ path: join26(managed, "kimi.plugin.json"), next: nextManifest, ...manifestBefore ? { before: manifestBefore } : {} },
|
|
22885
|
+
{ path: join26(managed, "kimi-hook.js"), next: hook.bytes, ...hookBefore ? { before: hookBefore } : {} },
|
|
22462
22886
|
{ path: installed, next: Buffer.from(`${JSON.stringify(nextDocument, null, 2)}
|
|
22463
22887
|
`), ...installedBefore ? { before: installedBefore } : {} }
|
|
22464
22888
|
]
|
|
22465
22889
|
};
|
|
22466
22890
|
}
|
|
22467
22891
|
function kimiPluginPreview(home, hookScript) {
|
|
22468
|
-
if (!
|
|
22892
|
+
if (!isAbsolute9(home) || !isAbsolute9(hookScript))
|
|
22469
22893
|
throw new Error("Kimi home and hook bundle must be absolute paths");
|
|
22470
22894
|
directory(home, false);
|
|
22471
22895
|
if (!file(hookScript, MAX_HOOK))
|
|
22472
22896
|
throw new Error("Kimi hook bundle is missing");
|
|
22473
|
-
return { file:
|
|
22897
|
+
return { file: join26(home, "plugins", "managed", ID2), changed: true, action: "only after Kimi 2.5.2 is confirmed, install the launch-scoped completion plugin and remove it on exit; other versions keep the existing TUI with no plugin" };
|
|
22474
22898
|
}
|
|
22475
22899
|
function locked(options, run) {
|
|
22476
|
-
if (!
|
|
22900
|
+
if (!isAbsolute9(options.home))
|
|
22477
22901
|
throw new Error("Kimi home must be an absolute path");
|
|
22478
22902
|
directory(options.home);
|
|
22479
|
-
const path =
|
|
22903
|
+
const path = join26(options.home, "agent-hub-plugin.lock");
|
|
22480
22904
|
let fd;
|
|
22481
22905
|
try {
|
|
22482
|
-
fd =
|
|
22906
|
+
fd = openSync15(path, "wx", 384);
|
|
22483
22907
|
} catch {
|
|
22484
22908
|
throw new Error(`Another Kimi plugin replacement is active or left a stale lock; retry after it exits or inspect ${path}`);
|
|
22485
22909
|
}
|
|
22486
22910
|
try {
|
|
22487
22911
|
return run();
|
|
22488
22912
|
} finally {
|
|
22489
|
-
|
|
22913
|
+
closeSync15(fd);
|
|
22490
22914
|
unlinkSync4(path);
|
|
22491
22915
|
}
|
|
22492
22916
|
}
|
|
@@ -22495,7 +22919,7 @@ function ensureKimiPlugin(options) {
|
|
|
22495
22919
|
const current = plan2(options);
|
|
22496
22920
|
if (!current.changed)
|
|
22497
22921
|
return { changed: false };
|
|
22498
|
-
for (const path of [
|
|
22922
|
+
for (const path of [join26(options.home, "plugins"), join26(options.home, "plugins", "managed"), current.managed]) {
|
|
22499
22923
|
if (!directory(path, false))
|
|
22500
22924
|
mkdirSync12(path, { mode: 448 });
|
|
22501
22925
|
}
|
|
@@ -22520,15 +22944,15 @@ function cleanupKimiPlugin(options) {
|
|
|
22520
22944
|
atomic(current.installed, Buffer.from(`${JSON.stringify(next, null, 2)}
|
|
22521
22945
|
`), installedBefore?.stat);
|
|
22522
22946
|
const [manifestTarget, hookTarget] = current.targets;
|
|
22523
|
-
removeFile(
|
|
22524
|
-
removeFile(
|
|
22947
|
+
removeFile(join26(current.managed, "kimi.plugin.json"), manifestTarget.next);
|
|
22948
|
+
removeFile(join26(current.managed, "kimi-hook.js"), hookTarget.next);
|
|
22525
22949
|
try {
|
|
22526
22950
|
rmdirSync4(current.managed);
|
|
22527
22951
|
} catch {}
|
|
22528
22952
|
});
|
|
22529
22953
|
}
|
|
22530
|
-
var
|
|
22531
|
-
const stat =
|
|
22954
|
+
var EVENTS4, ID2 = "agent-hub", MAX_INSTALLED, MAX_HOOK, object8 = (value) => !!value && typeof value === "object" && !Array.isArray(value), directory = (path, required = true) => {
|
|
22955
|
+
const stat = lstatSync25(path, { throwIfNoEntry: false });
|
|
22532
22956
|
if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
|
|
22533
22957
|
throw new Error(`${path} must be a plain directory`);
|
|
22534
22958
|
if (!stat && required)
|
|
@@ -22537,15 +22961,15 @@ var EVENTS3, ID2 = "agent-hub", MAX_INSTALLED, MAX_HOOK, object8 = (value) => !!
|
|
|
22537
22961
|
};
|
|
22538
22962
|
var init_kimi_plugin = __esm(() => {
|
|
22539
22963
|
init_process_signature();
|
|
22540
|
-
|
|
22964
|
+
EVENTS4 = ["TurnStarted", "Stop", "StopFailure", "Interrupt", "SessionEnd", "TaskStarted", "Notification"];
|
|
22541
22965
|
MAX_INSTALLED = 1024 * 1024;
|
|
22542
22966
|
MAX_HOOK = 8 * 1024 * 1024;
|
|
22543
22967
|
});
|
|
22544
22968
|
|
|
22545
22969
|
// src/adapters/definitions/native-cli-entry-kimi.ts
|
|
22546
|
-
import { join as
|
|
22547
|
-
import { homedir as
|
|
22548
|
-
import { spawn as spawn10, spawnSync as
|
|
22970
|
+
import { join as join27, resolve as resolve14 } from "path";
|
|
22971
|
+
import { homedir as homedir7 } from "os";
|
|
22972
|
+
import { spawn as spawn10, spawnSync as spawnSync5 } from "child_process";
|
|
22549
22973
|
import { mkdirSync as mkdirSync13 } from "fs";
|
|
22550
22974
|
function kimiTuiVersionGate(stdout) {
|
|
22551
22975
|
const verdict = assessVersion("kimi-tui", COMPAT["kimi-tui"].parse(stdout));
|
|
@@ -22635,6 +23059,7 @@ async function runKimiEntry(ctx) {
|
|
|
22635
23059
|
const warning = retainedLaunchWarning(snapshot, peer, ctx.definition);
|
|
22636
23060
|
if (warning)
|
|
22637
23061
|
console.error(warning);
|
|
23062
|
+
printLaunchCheck(snapshot, peer, ctx.definition, "tui");
|
|
22638
23063
|
const owner = snapshot?.peers?.[peer];
|
|
22639
23064
|
if (owner && !["offline"].includes(owner.state) && !owner.pullOnly)
|
|
22640
23065
|
fail("Kimi is running headless; run ahub stop kimi before starting its TUI");
|
|
@@ -22653,7 +23078,7 @@ async function runKimiEntry(ctx) {
|
|
|
22653
23078
|
throw running ? new Error(`${error.message} (the command is the running hub's kimi_cmd: the value in the config file is retained until ahub settings reload)`) : error;
|
|
22654
23079
|
}
|
|
22655
23080
|
const probe = kimiTuiVersionProbe(buildKimiTuiLaunch(command));
|
|
22656
|
-
const version =
|
|
23081
|
+
const version = spawnSync5(probe.cmd, probe.args, { encoding: "utf8", timeout: 5000, maxBuffer: 4096, env: nativeLaunchEnv("kimi", childEnv()) });
|
|
22657
23082
|
const gate = kimiTuiVersionGate(version.status === 0 ? version.stdout : "");
|
|
22658
23083
|
if (version.status === 0 && version.stdout.trim() && gate.message)
|
|
22659
23084
|
console.error(`${gate.message}. Completion receipts are off; the TUI launches as before.`);
|
|
@@ -22665,7 +23090,7 @@ async function runKimiEntry(ctx) {
|
|
|
22665
23090
|
if (!gate.ok) {
|
|
22666
23091
|
result = await runKimiTui(launch.cmd, launch.args, cwd, nativeEnv);
|
|
22667
23092
|
} else {
|
|
22668
|
-
const nativeHome = nativeEnv.KIMI_CODE_HOME ??
|
|
23093
|
+
const nativeHome = nativeEnv.KIMI_CODE_HOME ?? join27(nativeEnv.HOME ?? homedir7(), ".kimi-code");
|
|
22669
23094
|
let nativeLaunchId, completionEnv, plugin;
|
|
22670
23095
|
try {
|
|
22671
23096
|
mkdirSync13(nativeHome, { recursive: true, mode: 448 });
|
|
@@ -22674,7 +23099,7 @@ async function runKimiEntry(ctx) {
|
|
|
22674
23099
|
throw new Error(native.error ?? "native hook launch was not admitted");
|
|
22675
23100
|
nativeLaunchId = native.launchId;
|
|
22676
23101
|
plugin = { home: nativeHome, hookScript: resolve14(serverBundle, "../kimi-hook.js"), launchId: native.launchId, replaceStale: true };
|
|
22677
|
-
console.error(`Kimi TUI completion facts: installing a launch-scoped native plugin under ${
|
|
23102
|
+
console.error(`Kimi TUI completion facts: installing a launch-scoped native plugin under ${join27(nativeHome, "plugins", "managed", "agent-hub")}; it will be removed after this TUI exits`);
|
|
22678
23103
|
ensureKimiPlugin(plugin);
|
|
22679
23104
|
completionEnv = { ...nativeEnv, AGENTHUB_INSTANCE_ID: native.instanceId, AGENTHUB_LAUNCH_ID: native.launchId, AGENTHUB_HOOK_PURPOSE: "facts" };
|
|
22680
23105
|
} catch (error) {
|
|
@@ -22685,7 +23110,7 @@ async function runKimiEntry(ctx) {
|
|
|
22685
23110
|
try {
|
|
22686
23111
|
cleanupKimiPlugin(plugin);
|
|
22687
23112
|
} catch {
|
|
22688
|
-
console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${
|
|
23113
|
+
console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${join27(nativeHome, "plugins", "managed", "agent-hub")} before removing it`);
|
|
22689
23114
|
}
|
|
22690
23115
|
}
|
|
22691
23116
|
if (completionEnv) {
|
|
@@ -22698,7 +23123,7 @@ async function runKimiEntry(ctx) {
|
|
|
22698
23123
|
try {
|
|
22699
23124
|
cleanupKimiPlugin(plugin);
|
|
22700
23125
|
} catch {
|
|
22701
|
-
console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${
|
|
23126
|
+
console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${join27(nativeHome, "plugins", "managed", "agent-hub")} before removing it`);
|
|
22702
23127
|
}
|
|
22703
23128
|
}
|
|
22704
23129
|
} else {
|
|
@@ -22731,6 +23156,7 @@ async function runKimiEntry(ctx) {
|
|
|
22731
23156
|
}
|
|
22732
23157
|
}
|
|
22733
23158
|
var init_native_cli_entry_kimi = __esm(() => {
|
|
23159
|
+
init_launch_check();
|
|
22734
23160
|
init_compat();
|
|
22735
23161
|
init_kimi_plugin();
|
|
22736
23162
|
});
|
|
@@ -22819,6 +23245,8 @@ async function runPiEntry(ctx) {
|
|
|
22819
23245
|
const warning = retainedLaunchWarning(snapshot, peer, ctx.definition);
|
|
22820
23246
|
if (warning)
|
|
22821
23247
|
console.error(warning);
|
|
23248
|
+
if (options.mode === "tui")
|
|
23249
|
+
printLaunchCheck(snapshot, peer, ctx.definition, "tui");
|
|
22822
23250
|
const res = await hub.request({ t: "start", peer, args: options, operationId: process.env.AGENTHUB_RECOVERY_OPERATION });
|
|
22823
23251
|
hub.close();
|
|
22824
23252
|
if (!res.ok)
|
|
@@ -22846,7 +23274,9 @@ async function runPiEntry(ctx) {
|
|
|
22846
23274
|
}
|
|
22847
23275
|
console.log(res.already ? `${peer} is already attached` : `${peer} attached (headless). Talk to it with: ahub say @${peer} "..."`);
|
|
22848
23276
|
}
|
|
22849
|
-
var init_native_cli_entry_pi = () => {
|
|
23277
|
+
var init_native_cli_entry_pi = __esm(() => {
|
|
23278
|
+
init_launch_check();
|
|
23279
|
+
});
|
|
22850
23280
|
|
|
22851
23281
|
// src/adapters/definitions/native-cli-entry-local.ts
|
|
22852
23282
|
async function runLocalEntry(ctx) {
|
|
@@ -23008,6 +23438,8 @@ async function runJcodeEntry(ctx) {
|
|
|
23008
23438
|
const warning = retainedLaunchWarning(snapshot, peer, ctx.definition);
|
|
23009
23439
|
if (warning)
|
|
23010
23440
|
console.error(warning);
|
|
23441
|
+
if (mode === "tui" && !print)
|
|
23442
|
+
printLaunchCheck(snapshot, peer, ctx.definition, "tui");
|
|
23011
23443
|
const options = { model: one["--model"], providerProfile: one["--provider-profile"], sessionId: one["--session-id"] };
|
|
23012
23444
|
if (print) {
|
|
23013
23445
|
if (!hub.features.includes("native_tui_launch") || mode !== "tui")
|
|
@@ -23062,12 +23494,13 @@ async function runJcodeEntry(ctx) {
|
|
|
23062
23494
|
}
|
|
23063
23495
|
var WAITING = "jcode's TUI opens after its first hub turn; send it work, or Ctrl-C";
|
|
23064
23496
|
var init_native_cli_entry_jcode = __esm(() => {
|
|
23497
|
+
init_launch_check();
|
|
23065
23498
|
init_jcode();
|
|
23066
23499
|
});
|
|
23067
23500
|
|
|
23068
23501
|
// src/adapters/definitions/native-cli-preview-claude.ts
|
|
23069
23502
|
import { readFileSync as readFileSync13 } from "fs";
|
|
23070
|
-
import { join as
|
|
23503
|
+
import { join as join28 } from "path";
|
|
23071
23504
|
function previewClaude(ctx) {
|
|
23072
23505
|
const { args, cwd, stateDir, cliDir, unattended, config } = ctx;
|
|
23073
23506
|
const { buildLaunch, claudeObservationHooks } = ctx.helpers;
|
|
@@ -23075,13 +23508,13 @@ function previewClaude(ctx) {
|
|
|
23075
23508
|
let envNames = state.envNames;
|
|
23076
23509
|
let launch;
|
|
23077
23510
|
let original;
|
|
23078
|
-
for (const file of [
|
|
23511
|
+
for (const file of [join28(cwd, ".claude/settings.local.json"), join28(cwd, ".claude/settings.json"), join28(process.env.HOME ?? "", ".claude/settings.json")]) {
|
|
23079
23512
|
try {
|
|
23080
23513
|
original ??= JSON.parse(readFileSync13(file, "utf8")).statusLine;
|
|
23081
23514
|
} catch {}
|
|
23082
23515
|
}
|
|
23083
|
-
const facts = claudeObservationHooks(config, { script:
|
|
23084
|
-
launch = buildLaunch("claude", args, { preview: true, unattended, statusLine: { script:
|
|
23516
|
+
const facts = claudeObservationHooks(config, { script: join28(cliDir, "facts-hook.ts"), stateDir });
|
|
23517
|
+
launch = buildLaunch("claude", args, { preview: true, unattended, statusLine: { script: join28(cliDir, "statusline-tee.ts"), stateDir, ...original ? { original: { command: original.command ? REDACTED : "", ...typeof original.refreshInterval === "number" && Number.isFinite(original.refreshInterval) ? { refreshInterval: original.refreshInterval } : {}, ...typeof original.padding === "number" && Number.isFinite(original.padding) ? { padding: original.padding } : {} } } : {} }, ...facts ? { facts } : {} });
|
|
23085
23518
|
const safeArgs = args.map((arg, i) => {
|
|
23086
23519
|
if (args[i - 1] === "--settings")
|
|
23087
23520
|
return "{}";
|
|
@@ -23092,7 +23525,7 @@ function previewClaude(ctx) {
|
|
|
23092
23525
|
return publicArg(arg);
|
|
23093
23526
|
});
|
|
23094
23527
|
const publicLaunch = buildLaunch("claude", safeArgs, { preview: true, unattended, statusLine: {
|
|
23095
|
-
script:
|
|
23528
|
+
script: join28(cliDir, "statusline-tee.ts"),
|
|
23096
23529
|
stateDir,
|
|
23097
23530
|
...original ? { original: { command: original.command ? REDACTED : "", ...typeof original.refreshInterval === "number" && Number.isFinite(original.refreshInterval) ? { refreshInterval: original.refreshInterval } : {}, ...typeof original.padding === "number" && Number.isFinite(original.padding) ? { padding: original.padding } : {} } } : {}
|
|
23098
23531
|
}, facts });
|
|
@@ -23125,8 +23558,8 @@ function previewCodex(ctx) {
|
|
|
23125
23558
|
var init_native_cli_preview_codex = () => {};
|
|
23126
23559
|
|
|
23127
23560
|
// src/adapters/definitions/native-cli-preview-kimi.ts
|
|
23128
|
-
import { join as
|
|
23129
|
-
import { homedir as
|
|
23561
|
+
import { join as join29 } from "path";
|
|
23562
|
+
import { homedir as homedir8 } from "os";
|
|
23130
23563
|
function previewKimi(ctx) {
|
|
23131
23564
|
const { args, cwd, stateDir, cliDir, config } = ctx;
|
|
23132
23565
|
const { childEnv, startModeOf, buildKimiLaunch, buildKimiTuiLaunch, nativeLaunchEnv, kimiMcpPlan } = ctx.helpers;
|
|
@@ -23151,10 +23584,10 @@ function previewKimi(ctx) {
|
|
|
23151
23584
|
const nativeEnv = nativeLaunchEnv("kimi", childEnv());
|
|
23152
23585
|
envNames = Object.keys(nativeEnv).concat(["AGENTHUB_STATE_DIR", "AGENTHUB_PROJECT_DIR", "AGENTHUB_INSTANCE_ID", "AGENTHUB_LAUNCH_ID", "AGENTHUB_HOOK_PURPOSE"]);
|
|
23153
23586
|
unresolved.push({ field: "nativeLaunchId", reason: "native completion facts bind to the launch admitted by the running hub" });
|
|
23154
|
-
const home = nativeEnv.KIMI_CODE_HOME ??
|
|
23155
|
-
completionPlugin = kimiPluginPreview(home,
|
|
23587
|
+
const home = nativeEnv.KIMI_CODE_HOME ?? join29(nativeEnv.HOME ?? homedir8(), ".kimi-code");
|
|
23588
|
+
completionPlugin = kimiPluginPreview(home, join29(cliDir, "../../plugins/agent-hub/kimi-hook.js"));
|
|
23156
23589
|
}
|
|
23157
|
-
const { file, action, changed, tracked } = kimiMcpPlan(cwd, stateDir,
|
|
23590
|
+
const { file, action, changed, tracked } = kimiMcpPlan(cwd, stateDir, join29(cliDir, "../../plugins/agent-hub/server.js"), mode);
|
|
23158
23591
|
kimiMetadata = { mode, mcp: { file, action, changed, tracked }, ...completionPlugin ? { completionPlugin } : {} };
|
|
23159
23592
|
return finishPreview(ctx, launch, envNames, unresolved, kimiMetadata);
|
|
23160
23593
|
}
|
|
@@ -23163,7 +23596,7 @@ var init_native_cli_preview_kimi = __esm(() => {
|
|
|
23163
23596
|
});
|
|
23164
23597
|
|
|
23165
23598
|
// src/adapters/definitions/native-cli-preview-pi.ts
|
|
23166
|
-
import { join as
|
|
23599
|
+
import { join as join30, resolve as resolve16 } from "path";
|
|
23167
23600
|
function previewPi(ctx) {
|
|
23168
23601
|
const { args, stateDir, cliDir, config } = ctx;
|
|
23169
23602
|
const { relayModelIds, buildPiLaunch, startModeOf } = ctx.helpers;
|
|
@@ -23198,7 +23631,7 @@ function previewPi(ctx) {
|
|
|
23198
23631
|
tools: [],
|
|
23199
23632
|
preamble: REDACTED,
|
|
23200
23633
|
maxSteps: config.pi.max_steps
|
|
23201
|
-
}, {}, resolve16(
|
|
23634
|
+
}, {}, resolve16(join30(cliDir, "../pi/extension.ts")), UNRESOLVED, UNRESOLVED);
|
|
23202
23635
|
launch = pi;
|
|
23203
23636
|
envNames = Object.keys(pi.env).concat(["PATH", "HOME", "USER", "SHELL", "TMPDIR", "TERM", "TERM_PROGRAM", "LANG", "LC_ALL", "LC_CTYPE", "NO_COLOR", "CODEX_HOME"].filter((key) => process.env[key] !== undefined));
|
|
23204
23637
|
if (mode === "tui")
|
|
@@ -23288,8 +23721,8 @@ var init_native_config_policy = __esm(() => {
|
|
|
23288
23721
|
});
|
|
23289
23722
|
|
|
23290
23723
|
// src/adapters/definitions/native-policy-aux.ts
|
|
23291
|
-
import { closeSync as
|
|
23292
|
-
import { isAbsolute as
|
|
23724
|
+
import { closeSync as closeSync16, constants as constants12, fstatSync as fstatSync14, openSync as openSync16, readdirSync as readdirSync6, readFileSync as readFileSync14 } from "fs";
|
|
23725
|
+
import { isAbsolute as isAbsolute10, join as join31, normalize } from "path";
|
|
23293
23726
|
function claudeCrashPlan(_meta) {
|
|
23294
23727
|
return { how: "claude: the Claude Code plugin reconnects by itself while that session is still open" };
|
|
23295
23728
|
}
|
|
@@ -23334,13 +23767,13 @@ function localCrashPlan(meta) {
|
|
|
23334
23767
|
}
|
|
23335
23768
|
function claudePlugins(root, cwd) {
|
|
23336
23769
|
const enabled = new Map;
|
|
23337
|
-
for (const file of [
|
|
23770
|
+
for (const file of [join31(root, "settings.json"), ...cwd ? [join31(cwd, ".claude", "settings.json"), join31(cwd, ".claude", "settings.local.json")] : []]) {
|
|
23338
23771
|
const map = json(file)?.enabledPlugins;
|
|
23339
23772
|
if (map && typeof map === "object")
|
|
23340
23773
|
for (const [key, on] of Object.entries(map))
|
|
23341
23774
|
enabled.set(key, on === true);
|
|
23342
23775
|
}
|
|
23343
|
-
const installed = json(
|
|
23776
|
+
const installed = json(join31(root, "plugins", "installed_plugins.json"))?.plugins ?? {};
|
|
23344
23777
|
const out = [];
|
|
23345
23778
|
for (const [key, on] of enabled) {
|
|
23346
23779
|
if (!on)
|
|
@@ -23354,7 +23787,7 @@ function claudePlugins(root, cwd) {
|
|
|
23354
23787
|
return out;
|
|
23355
23788
|
}
|
|
23356
23789
|
function codexPlugins(root) {
|
|
23357
|
-
const config = text2(
|
|
23790
|
+
const config = text2(join31(root, "config.toml"));
|
|
23358
23791
|
if (config === undefined)
|
|
23359
23792
|
return [];
|
|
23360
23793
|
const found = new Map, disabled = new Set;
|
|
@@ -23373,7 +23806,7 @@ function codexPlugins(root) {
|
|
|
23373
23806
|
continue;
|
|
23374
23807
|
let versions = [];
|
|
23375
23808
|
try {
|
|
23376
|
-
versions =
|
|
23809
|
+
versions = readdirSync6(join31(root, "plugins", "cache", market, plugin));
|
|
23377
23810
|
} catch {}
|
|
23378
23811
|
out.push({ name, version: versions.length === 1 ? version2(versions[0]) : null });
|
|
23379
23812
|
}
|
|
@@ -23388,13 +23821,13 @@ function parsePiContinuity(value) {
|
|
|
23388
23821
|
return { sessionId: value.sessionId, ...value.sessionFile === undefined ? {} : { sessionFile: value.sessionFile }, ...value.backend === undefined ? {} : { backend: value.backend }, ...value.model === undefined ? {} : { model: value.model } };
|
|
23389
23822
|
}
|
|
23390
23823
|
function absoluteContinuityPath(value) {
|
|
23391
|
-
return typeof value === "string" && value.length > 0 && value.length <= 4096 && !/[\x00-\x1f\x7f]/.test(value) &&
|
|
23824
|
+
return typeof value === "string" && value.length > 0 && value.length <= 4096 && !/[\x00-\x1f\x7f]/.test(value) && isAbsolute10(value) && normalize(value) === value;
|
|
23392
23825
|
}
|
|
23393
23826
|
var str3 = (value) => typeof value === "string" && value ? value : undefined, PLUGINS, CLAUDE_ONLY, text2 = (file) => {
|
|
23394
23827
|
let fd;
|
|
23395
23828
|
try {
|
|
23396
|
-
fd =
|
|
23397
|
-
const st =
|
|
23829
|
+
fd = openSync16(file, constants12.O_RDONLY | constants12.O_NONBLOCK);
|
|
23830
|
+
const st = fstatSync14(fd);
|
|
23398
23831
|
if (!st.isFile() || st.size > 1024 * 1024)
|
|
23399
23832
|
return;
|
|
23400
23833
|
return readFileSync14(fd, "utf8");
|
|
@@ -23402,7 +23835,7 @@ var str3 = (value) => typeof value === "string" && value ? value : undefined, PL
|
|
|
23402
23835
|
return;
|
|
23403
23836
|
} finally {
|
|
23404
23837
|
if (fd !== undefined)
|
|
23405
|
-
|
|
23838
|
+
closeSync16(fd);
|
|
23406
23839
|
}
|
|
23407
23840
|
}, json = (file) => {
|
|
23408
23841
|
try {
|
|
@@ -23411,7 +23844,7 @@ var str3 = (value) => typeof value === "string" && value ? value : undefined, PL
|
|
|
23411
23844
|
} catch {
|
|
23412
23845
|
return;
|
|
23413
23846
|
}
|
|
23414
|
-
}, version2 = (v) => typeof v === "string" && /^[0-9A-Za-z.+_-]{1,40}$/.test(v) ? v : null, claudePluginInventory = (ctx) => claudePlugins(ctx.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
23847
|
+
}, version2 = (v) => typeof v === "string" && /^[0-9A-Za-z.+_-]{1,40}$/.test(v) ? v : null, claudePluginInventory = (ctx) => claudePlugins(ctx.env.CLAUDE_CONFIG_DIR?.trim() || join31(ctx.home, ".claude"), ctx.cwd), codexPluginInventory = (ctx) => codexPlugins(ctx.env.CODEX_HOME?.trim() || join31(ctx.home, ".codex")), codexToolSemantic = (name, _command) => name.toLowerCase() === "filechange" ? "edit" : undefined;
|
|
23415
23848
|
var init_native_policy_aux = __esm(() => {
|
|
23416
23849
|
PLUGINS = new Map([["claude-mem", "claude-mem"], ["ponytail", "ponytail"], ["open-code-review", "open-code-review"]]);
|
|
23417
23850
|
CLAUDE_ONLY = new Map([["codex@openai-codex", "codex-plugin"]]);
|
|
@@ -23456,7 +23889,7 @@ var init_native_cli_launch_common = __esm(() => {
|
|
|
23456
23889
|
// src/adapters/definitions/native-cli-claude-launch.ts
|
|
23457
23890
|
import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync11, renameSync as renameSync7, unlinkSync as unlinkSync5, readFileSync as readFileSync15 } from "fs";
|
|
23458
23891
|
import { randomUUID as randomUUID12 } from "crypto";
|
|
23459
|
-
import { resolve as resolve17, join as
|
|
23892
|
+
import { resolve as resolve17, join as join32 } from "path";
|
|
23460
23893
|
function claudeChannel(userArgs) {
|
|
23461
23894
|
const bundle = resolve17(import.meta.dir, "../../../plugins/agent-hub/server.js");
|
|
23462
23895
|
for (let i = 0;i < userArgs.length; i++) {
|
|
@@ -23472,7 +23905,8 @@ function claudeChannel(userArgs) {
|
|
|
23472
23905
|
}
|
|
23473
23906
|
return CLAUDE_CHANNEL;
|
|
23474
23907
|
}
|
|
23475
|
-
function claudeNativeLaunch(
|
|
23908
|
+
function claudeNativeLaunch(input) {
|
|
23909
|
+
const ctx = input.preview && input.facts ? { ...input, facts: { ...input.facts, startCheck: true } } : input;
|
|
23476
23910
|
const { passthrough, unattended } = nativeLaunchArguments("claude", ctx, CLAUDE_LAUNCH_POLICY);
|
|
23477
23911
|
const build = () => {
|
|
23478
23912
|
const own = passthrough.some((a) => a === "--settings" || a.startsWith("--settings="));
|
|
@@ -23518,7 +23952,7 @@ function claudeNativeLaunch(ctx) {
|
|
|
23518
23952
|
const stateDir = ctx.facts?.stateDir ?? ctx.statusLine?.stateDir;
|
|
23519
23953
|
if (!stateDir)
|
|
23520
23954
|
throw new Error("Claude session settings require the hub state directory");
|
|
23521
|
-
const file =
|
|
23955
|
+
const file = join32(stateDir, `claude-settings-${randomUUID12()}.json`);
|
|
23522
23956
|
try {
|
|
23523
23957
|
mkdirSync14(stateDir, { recursive: true, mode: 448 });
|
|
23524
23958
|
writeFileSync11(`${file}.tmp`, settingsArgs[1], { mode: 384, flag: "wx" });
|
|
@@ -23576,14 +24010,14 @@ var init_native_cli_codex_launch = __esm(() => {
|
|
|
23576
24010
|
|
|
23577
24011
|
// src/cli/recovery-session-file.ts
|
|
23578
24012
|
import { statSync as statSync6 } from "fs";
|
|
23579
|
-
import { homedir as
|
|
23580
|
-
import { join as
|
|
24013
|
+
import { homedir as homedir9 } from "os";
|
|
24014
|
+
import { join as join33 } from "path";
|
|
23581
24015
|
function checkedSessionPath(binding, kind) {
|
|
23582
24016
|
if (kind === "rollout")
|
|
23583
|
-
return
|
|
23584
|
-
const config = binding.launch.env.CLAUDE_CONFIG_DIR ??
|
|
24017
|
+
return join33(binding.launch.env.CODEX_HOME ?? join33(homedir9(), ".codex"), "sessions");
|
|
24018
|
+
const config = binding.launch.env.CLAUDE_CONFIG_DIR ?? join33(homedir9(), ".claude");
|
|
23585
24019
|
const slug = binding.projectRoot.replace(/[^a-zA-Z0-9]/g, "-");
|
|
23586
|
-
return
|
|
24020
|
+
return join33(config, "projects", slug, `${binding.sessionId}.jsonl`);
|
|
23587
24021
|
}
|
|
23588
24022
|
function recordedFileState(file) {
|
|
23589
24023
|
try {
|
|
@@ -23595,11 +24029,11 @@ function recordedFileState(file) {
|
|
|
23595
24029
|
var init_recovery_session_file = () => {};
|
|
23596
24030
|
|
|
23597
24031
|
// src/adapters/definitions/native-recovery.ts
|
|
23598
|
-
import { readdirSync as
|
|
23599
|
-
import { basename as
|
|
24032
|
+
import { readdirSync as readdirSync7 } from "fs";
|
|
24033
|
+
import { basename as basename7, join as join34 } from "path";
|
|
23600
24034
|
var rolloutState = (binding) => {
|
|
23601
24035
|
try {
|
|
23602
|
-
return
|
|
24036
|
+
return readdirSync7(checkedSessionPath(binding, "rollout"), { recursive: true }).some((name) => String(name).endsWith(".jsonl") && basename7(String(name)).includes(binding.sessionId));
|
|
23603
24037
|
} catch (error) {
|
|
23604
24038
|
return error.code === "ENOENT" ? false : "unknown";
|
|
23605
24039
|
}
|
|
@@ -23620,7 +24054,7 @@ var init_native_recovery = __esm(() => {
|
|
|
23620
24054
|
if (phase !== "plan")
|
|
23621
24055
|
return false;
|
|
23622
24056
|
let current, started = false, turned = false;
|
|
23623
|
-
for (const e of readEvents(
|
|
24057
|
+
for (const e of readEvents(join34(stateDir, "events.jsonl"))) {
|
|
23624
24058
|
if (e.type === "native_thread" && e.peer === binding.peer) {
|
|
23625
24059
|
current = e.thread;
|
|
23626
24060
|
if (e.thread === binding.sessionId && e.fresh)
|
|
@@ -23696,200 +24130,6 @@ var init_native_recovery = __esm(() => {
|
|
|
23696
24130
|
};
|
|
23697
24131
|
});
|
|
23698
24132
|
|
|
23699
|
-
// src/adapters/kimi-tui-facts.ts
|
|
23700
|
-
import { closeSync as closeSync16, constants as constants12, fstatSync as fstatSync14, lstatSync as lstatSync25, openSync as openSync16, readSync as readSync11, readdirSync as readdirSync7 } from "fs";
|
|
23701
|
-
import { createHash as createHash13 } from "crypto";
|
|
23702
|
-
import { basename as basename7, dirname as dirname16, isAbsolute as isAbsolute10, join as join34, relative as relative6 } from "path";
|
|
23703
|
-
import { homedir as homedir9 } from "os";
|
|
23704
|
-
function decodeKimiTuiHook(event, value) {
|
|
23705
|
-
if (!EVENTS4.includes(event) || !record7(value) || value.hook_event_name !== event || value.client_type !== "kimi_code_cli" || typeof value.session_id !== "string" || !SESSION.test(value.session_id) || typeof value.cwd !== "string" || !isAbsolute10(value.cwd) || value.cwd.length > 4096)
|
|
23706
|
-
return;
|
|
23707
|
-
if ((event === "TurnStarted" || event === "Interrupt") && !integer2(value.turn_id))
|
|
23708
|
-
return;
|
|
23709
|
-
if (event === "TaskStarted" && (typeof value.task_id !== "string" || !TASK.test(value.task_id)))
|
|
23710
|
-
return;
|
|
23711
|
-
const home = process.env.KIMI_CODE_HOME ?? join34(process.env.HOME ?? homedir9(), ".kimi-code");
|
|
23712
|
-
const transcriptPath = value.agentHubTranscriptPath ?? join34(home, "session_index.jsonl");
|
|
23713
|
-
if (typeof transcriptPath !== "string" || !isAbsolute10(transcriptPath) || transcriptPath.length > 4096)
|
|
23714
|
-
return;
|
|
23715
|
-
const phase = { TurnStarted: "start", Stop: "stop", StopFailure: "stop", Interrupt: "stop", SessionEnd: "session", TaskStarted: "pre", Notification: "post" }[event];
|
|
23716
|
-
return { event, phase, sessionId: value.session_id, transcriptPath, workspacePaths: [value.cwd], tool: "", input: {} };
|
|
23717
|
-
}
|
|
23718
|
-
function encodeKimiTuiHook() {
|
|
23719
|
-
return;
|
|
23720
|
-
}
|
|
23721
|
-
function readBytes(path, cap, tail = false) {
|
|
23722
|
-
const link = lstatSync25(path);
|
|
23723
|
-
if (!link.isFile() || link.isSymbolicLink() || link.nlink !== 1)
|
|
23724
|
-
throw new Error("not a regular file");
|
|
23725
|
-
const fd = openSync16(path, constants12.O_RDONLY | constants12.O_NOFOLLOW);
|
|
23726
|
-
try {
|
|
23727
|
-
const stat = fstatSync14(fd);
|
|
23728
|
-
if (!stat.isFile() || stat.nlink !== 1 || !tail && stat.size > cap)
|
|
23729
|
-
throw new Error("invalid file");
|
|
23730
|
-
const length = Math.min(stat.size, cap), start = tail ? stat.size - length : 0;
|
|
23731
|
-
const bytes = Buffer.alloc(length);
|
|
23732
|
-
let offset = 0;
|
|
23733
|
-
while (offset < length) {
|
|
23734
|
-
const count = readSync11(fd, bytes, offset, length - offset, start + offset);
|
|
23735
|
-
if (count <= 0)
|
|
23736
|
-
throw new Error("short read");
|
|
23737
|
-
offset += count;
|
|
23738
|
-
}
|
|
23739
|
-
return bytes;
|
|
23740
|
-
} finally {
|
|
23741
|
-
closeSync16(fd);
|
|
23742
|
-
}
|
|
23743
|
-
}
|
|
23744
|
-
function sessionDirectory(index, session) {
|
|
23745
|
-
const home = dirname16(index), sessions = realPath(join34(home, "sessions"));
|
|
23746
|
-
let listed;
|
|
23747
|
-
for (const line of readBytes(index, INDEX_CAP2).toString("utf8").split(`
|
|
23748
|
-
`)) {
|
|
23749
|
-
if (!line.includes(session))
|
|
23750
|
-
continue;
|
|
23751
|
-
let row;
|
|
23752
|
-
try {
|
|
23753
|
-
row = JSON.parse(line);
|
|
23754
|
-
} catch {
|
|
23755
|
-
continue;
|
|
23756
|
-
}
|
|
23757
|
-
if (record7(row) && row.sessionId === session && typeof row.sessionDir === "string") {
|
|
23758
|
-
if (listed)
|
|
23759
|
-
throw new Error("duplicate session");
|
|
23760
|
-
listed = row.sessionDir;
|
|
23761
|
-
}
|
|
23762
|
-
}
|
|
23763
|
-
if (!listed)
|
|
23764
|
-
throw new Error("session not indexed");
|
|
23765
|
-
const directory = realPath(listed);
|
|
23766
|
-
if (!inside3(sessions, directory))
|
|
23767
|
-
throw new Error("session outside home");
|
|
23768
|
-
return directory;
|
|
23769
|
-
}
|
|
23770
|
-
function taskInventory(agents) {
|
|
23771
|
-
let active = 0;
|
|
23772
|
-
const names = readdirSync7(agents, { withFileTypes: true });
|
|
23773
|
-
if (names.length > MAX_AGENTS2)
|
|
23774
|
-
throw new Error("too many agents");
|
|
23775
|
-
for (const entry of names) {
|
|
23776
|
-
if (!AGENT.test(entry.name))
|
|
23777
|
-
continue;
|
|
23778
|
-
if (!entry.isDirectory())
|
|
23779
|
-
continue;
|
|
23780
|
-
const tasks = join34(agents, entry.name, "tasks");
|
|
23781
|
-
const dir = lstatSync25(tasks, { throwIfNoEntry: false });
|
|
23782
|
-
if (!dir)
|
|
23783
|
-
continue;
|
|
23784
|
-
if (!dir.isDirectory() || dir.isSymbolicLink())
|
|
23785
|
-
throw new Error("invalid task directory");
|
|
23786
|
-
const files = readdirSync7(tasks).filter((name) => name.endsWith(".json")).sort();
|
|
23787
|
-
if (files.length > MAX_TASKS)
|
|
23788
|
-
throw new Error("too many tasks");
|
|
23789
|
-
for (const name of files) {
|
|
23790
|
-
if (!TASK.test(name.slice(0, -5)))
|
|
23791
|
-
throw new Error("invalid task name");
|
|
23792
|
-
const row = JSON.parse(readBytes(join34(tasks, name), TASK_CAP).toString("utf8"));
|
|
23793
|
-
if (!record7(row) || row.taskId !== name.slice(0, -5) || typeof row.status !== "string")
|
|
23794
|
-
throw new Error("invalid task");
|
|
23795
|
-
if (row.status === "running" && row.endedAt === null) {
|
|
23796
|
-
active++;
|
|
23797
|
-
continue;
|
|
23798
|
-
}
|
|
23799
|
-
const terminal = ["completed", "failed", "cancelled"].includes(row.status) && integer2(row.endedAt);
|
|
23800
|
-
if (!terminal)
|
|
23801
|
-
throw new Error("unknown task state");
|
|
23802
|
-
}
|
|
23803
|
-
}
|
|
23804
|
-
return active;
|
|
23805
|
-
}
|
|
23806
|
-
function readKimiTuiTranscript(session, index) {
|
|
23807
|
-
if (!SESSION.test(session) || basename7(index) !== "session_index.jsonl" || !isAbsolute10(index))
|
|
23808
|
-
return empty();
|
|
23809
|
-
try {
|
|
23810
|
-
const directory = sessionDirectory(index, session);
|
|
23811
|
-
const wire = join34(directory, "agents", "main", "wire.jsonl");
|
|
23812
|
-
if (!inside3(directory, realPath(wire)))
|
|
23813
|
-
return empty();
|
|
23814
|
-
const bytes = readBytes(wire, WIRE_CAP, true);
|
|
23815
|
-
if (bytes.length === 0 || bytes[bytes.length - 1] !== 10)
|
|
23816
|
-
return empty();
|
|
23817
|
-
const lines = bytes.toString("utf8").split(`
|
|
23818
|
-
`);
|
|
23819
|
-
if (bytes.length === WIRE_CAP && !lines[0]?.startsWith('{"type":"metadata"'))
|
|
23820
|
-
lines.shift();
|
|
23821
|
-
const prompts = new Map;
|
|
23822
|
-
const ends = new Map;
|
|
23823
|
-
const promptEnds = new Map;
|
|
23824
|
-
const promptEndTurnIds = new Map;
|
|
23825
|
-
let started;
|
|
23826
|
-
for (const line of lines) {
|
|
23827
|
-
if (!line || !/"(?:turn\.prompt|turn\.ended|prompt\.completed|prompt\.aborted)"/.test(line))
|
|
23828
|
-
continue;
|
|
23829
|
-
let row;
|
|
23830
|
-
try {
|
|
23831
|
-
row = JSON.parse(line);
|
|
23832
|
-
} catch {
|
|
23833
|
-
return empty();
|
|
23834
|
-
}
|
|
23835
|
-
if (!record7(row))
|
|
23836
|
-
return empty();
|
|
23837
|
-
if (row.type === "turn.prompt" && integer2(row.turnId) && record7(row.origin) && typeof row.origin.kind === "string") {
|
|
23838
|
-
const turn = row.turnId, id = typeof row.promptId === "string" ? row.promptId : typeof row.origin.notificationId === "string" ? row.origin.notificationId : `turn-${turn}`;
|
|
23839
|
-
const prompt = { turn, id, origin: row.origin.kind };
|
|
23840
|
-
prompts.set(turn, prompt);
|
|
23841
|
-
started = prompt;
|
|
23842
|
-
} else if (row.type === "turn.ended" && integer2(row.turnId) && ["completed", "failed", "cancelled"].includes(String(row.reason))) {
|
|
23843
|
-
const turn = row.turnId;
|
|
23844
|
-
ends.set(turn, { turn, reason: row.reason });
|
|
23845
|
-
} else if (row.type === "prompt.completed" && typeof row.promptId === "string" && ["completed", "failed"].includes(String(row.reason))) {
|
|
23846
|
-
promptEnds.set(row.promptId, row.reason);
|
|
23847
|
-
if (integer2(row.turnId))
|
|
23848
|
-
promptEndTurnIds.set(row.turnId, row.promptId);
|
|
23849
|
-
} else if (row.type === "prompt.aborted" && typeof row.promptId === "string") {
|
|
23850
|
-
promptEnds.set(row.promptId, "cancelled");
|
|
23851
|
-
if (integer2(row.turnId))
|
|
23852
|
-
promptEndTurnIds.set(row.turnId, row.promptId);
|
|
23853
|
-
} else if (row.type === "turn.prompt" || row.type === "turn.ended")
|
|
23854
|
-
return empty();
|
|
23855
|
-
}
|
|
23856
|
-
let completion;
|
|
23857
|
-
for (const [turn, end] of ends) {
|
|
23858
|
-
const prompt = prompts.get(turn), promptReason = prompt ? promptEnds.get(prompt.id) : undefined, turnPromptId = promptEndTurnIds.get(turn);
|
|
23859
|
-
if (!prompt || promptReason !== undefined && promptReason !== end.reason || turnPromptId !== undefined && turnPromptId !== prompt.id)
|
|
23860
|
-
continue;
|
|
23861
|
-
completion = { id: createHash13("sha256").update(`${session}:${turn}:${prompt.id}:${end.reason}`).digest("hex"), index: turn, reason: end.reason };
|
|
23862
|
-
}
|
|
23863
|
-
let background;
|
|
23864
|
-
try {
|
|
23865
|
-
background = taskInventory(join34(directory, "agents"));
|
|
23866
|
-
} catch {}
|
|
23867
|
-
return {
|
|
23868
|
-
factIds: [],
|
|
23869
|
-
...completion ? { completion } : {},
|
|
23870
|
-
...started ? { started: { id: createHash13("sha256").update(`${session}:${started.turn}:${started.id}`).digest("hex"), index: started.turn, origin: started.origin } } : {},
|
|
23871
|
-
...background === undefined ? {} : { background }
|
|
23872
|
-
};
|
|
23873
|
-
} catch {
|
|
23874
|
-
return empty();
|
|
23875
|
-
}
|
|
23876
|
-
}
|
|
23877
|
-
var EVENTS4, SESSION, AGENT, TASK, INDEX_CAP2, WIRE_CAP, TASK_CAP, MAX_AGENTS2 = 256, MAX_TASKS = 256, record7 = (value) => !!value && typeof value === "object" && !Array.isArray(value), integer2 = (value) => Number.isSafeInteger(value) && value >= 0, inside3 = (root, path) => {
|
|
23878
|
-
const rel = relative6(root, path);
|
|
23879
|
-
return rel !== "" && rel !== ".." && !rel.startsWith("../") && !isAbsolute10(rel);
|
|
23880
|
-
}, empty = () => ({ factIds: [] }), KIMI_TUI_FACTS_HOOK;
|
|
23881
|
-
var init_kimi_tui_facts = __esm(() => {
|
|
23882
|
-
init_project();
|
|
23883
|
-
EVENTS4 = ["TurnStarted", "Stop", "StopFailure", "Interrupt", "SessionEnd", "TaskStarted", "Notification"];
|
|
23884
|
-
SESSION = /^session_[A-Za-z0-9_-]{1,120}$/;
|
|
23885
|
-
AGENT = /^[A-Za-z0-9._-]{1,64}$/;
|
|
23886
|
-
TASK = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
23887
|
-
INDEX_CAP2 = 16 * 1024 * 1024;
|
|
23888
|
-
WIRE_CAP = 8 * 1024 * 1024;
|
|
23889
|
-
TASK_CAP = 64 * 1024;
|
|
23890
|
-
KIMI_TUI_FACTS_HOOK = { decode: decodeKimiTuiHook, encode: encodeKimiTuiHook, read: readKimiTuiTranscript };
|
|
23891
|
-
});
|
|
23892
|
-
|
|
23893
24133
|
// src/adapters/definitions/builtin-metadata.ts
|
|
23894
24134
|
function sessionId(field) {
|
|
23895
24135
|
return (peer) => {
|
|
@@ -23919,7 +24159,7 @@ var init_builtin_metadata = __esm(() => {
|
|
|
23919
24159
|
init_native_display();
|
|
23920
24160
|
init_native_recovery();
|
|
23921
24161
|
init_native_quota();
|
|
23922
|
-
|
|
24162
|
+
init_native_facts_hooks();
|
|
23923
24163
|
switches = Object.freeze(["--unattended", "--safe", "--new"]);
|
|
23924
24164
|
implementerRoles = Object.freeze(["implementer", "verifier"]);
|
|
23925
24165
|
dualForms = Object.freeze(["tui", "headless"]);
|
|
@@ -24093,7 +24333,7 @@ var init_builtin_metadata = __esm(() => {
|
|
|
24093
24333
|
settle: { signal: "prompt-response" },
|
|
24094
24334
|
budget: { account: "kimi", resetSoftTokensOnResume: true, context: { source: "acp_usage_update", read: acpContextValue } },
|
|
24095
24335
|
capabilities: { watch: true },
|
|
24096
|
-
hooks: { factsHook:
|
|
24336
|
+
hooks: { factsHook: NATIVE_FACTS_HOOKS.kimi, recallPlatform: "kimi", recallSource: "kimi" },
|
|
24097
24337
|
cli: { command: "kimi", entry: { lifecycleAdmission: true, execute: runKimiEntry }, preview: previewKimi, usage: [["ahub kimi [--print-command] [--mode tui|headless] [--model <alias>]", "default: Kimi's own TUI, pull-only via hub_inbox; no push, steer, watchdog, console approvals or automatic quota handoff. Select headless for ACP", "start Kimi in its own TUI, or headless over ACP"]], launchConfigKeys: ["kimi_cmd", "peers.kimi.start_mode"], stopNotice: (form) => form === "tui" ? "Kimi belongs to its own TUI terminal; end it in that terminal" : "", startWords: (form) => ["kimi", "--mode", form] },
|
|
24098
24338
|
display: KIMI_DISPLAY
|
|
24099
24339
|
},
|
|
@@ -24220,6 +24460,8 @@ async function runQwenEntry(ctx) {
|
|
|
24220
24460
|
const warning = retainedLaunchWarning(snapshot, peer, ctx.definition);
|
|
24221
24461
|
if (warning)
|
|
24222
24462
|
console.error(warning);
|
|
24463
|
+
if (mode === "tui")
|
|
24464
|
+
printLaunchCheck(snapshot, peer, ctx.definition, "tui");
|
|
24223
24465
|
const reply = await hub.request({ t: "start", peer, args: { mode, ...one["--model"] ? { model: one["--model"] } : {}, ...one["--session-id"] ? { sessionId: one["--session-id"] } : {} }, operationId: process.env.AGENTHUB_RECOVERY_OPERATION }, 35000);
|
|
24224
24466
|
if (!reply.ok)
|
|
24225
24467
|
fail(reply.error);
|
|
@@ -24248,6 +24490,7 @@ async function runQwenEntry(ctx) {
|
|
|
24248
24490
|
}
|
|
24249
24491
|
var init_native_cli_entry_qwen = __esm(() => {
|
|
24250
24492
|
init_child_process();
|
|
24493
|
+
init_launch_check();
|
|
24251
24494
|
});
|
|
24252
24495
|
|
|
24253
24496
|
// src/adapters/definitions/native-cli-preview-qwen.ts
|
|
@@ -25077,6 +25320,12 @@ var init_registry = __esm(() => {
|
|
|
25077
25320
|
}));
|
|
25078
25321
|
});
|
|
25079
25322
|
|
|
25323
|
+
// src/hub/peer-doing.ts
|
|
25324
|
+
var TITLE_READ_MAX, TITLE_LINE_MAX;
|
|
25325
|
+
var init_peer_doing = __esm(() => {
|
|
25326
|
+
TITLE_READ_MAX = 1024 * 1024;
|
|
25327
|
+
TITLE_LINE_MAX = 64 * 1024;
|
|
25328
|
+
});
|
|
25080
25329
|
// node_modules/ajv/dist/compile/codegen/code.js
|
|
25081
25330
|
var require_code = __commonJS(function(exports) {
|
|
25082
25331
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -32576,7 +32825,7 @@ class ControlClient {
|
|
|
32576
32825
|
client.pending.delete(msg.rid);
|
|
32577
32826
|
done(msg);
|
|
32578
32827
|
};
|
|
32579
|
-
ws.onopen = () => void client.request({ t: "hello", token: control.token, ...hello, ...expected, clientVersion: VERSION, v: selected, vMin: remote?.vMin === undefined ? selected : Math.max(local.vMin, remote.vMin) }, timeoutMs).then((reply) => {
|
|
32828
|
+
ws.onopen = () => void client.request({ t: "hello", token: control.token, ...hello.role === "tools" && hello.clientPid === undefined ? { clientPid: process.pid } : {}, ...hello, ...expected, clientVersion: VERSION, v: selected, vMin: remote?.vMin === undefined ? selected : Math.max(local.vMin, remote.vMin) }, timeoutMs).then((reply) => {
|
|
32580
32829
|
if (reply.t !== "welcome" || reply.ok === false)
|
|
32581
32830
|
return refuse(new Error(reply.error ?? "hub refused handshake"));
|
|
32582
32831
|
if (expected.projectId && reply.projectId !== expected.projectId || expected.instanceId && reply.instanceId !== expected.instanceId || expected.projectRoot && reply.cwd !== expected.projectRoot) {
|
|
@@ -32823,6 +33072,7 @@ init_plan_conformance();
|
|
|
32823
33072
|
// src/hub/sdlc-release.ts
|
|
32824
33073
|
init_child_process();
|
|
32825
33074
|
init_git();
|
|
33075
|
+
init_project();
|
|
32826
33076
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
32827
33077
|
var CHECKER_PATH = fileURLToPath2(new URL("../../scripts/check-docs.mjs", import.meta.url));
|
|
32828
33078
|
|
|
@@ -33034,6 +33284,7 @@ var GROOMING_CODES = new Set(["tests", "spec", "roster", "pull-only", "not-attac
|
|
|
33034
33284
|
// src/hub/ci-watch.ts
|
|
33035
33285
|
init_sdlc();
|
|
33036
33286
|
var CI_WATCH_DEADLINE_MS = 45 * 60000;
|
|
33287
|
+
var CI_MISSING_RUN_MS = 10 * 60000;
|
|
33037
33288
|
|
|
33038
33289
|
// src/hub/tasks.ts
|
|
33039
33290
|
init_sdlc();
|
|
@@ -33057,10 +33308,7 @@ var MANAGED_HANDOFF = Symbol("managed worktree handoff");
|
|
|
33057
33308
|
|
|
33058
33309
|
// src/hub/conductor.ts
|
|
33059
33310
|
init_tool_refusal();
|
|
33060
|
-
|
|
33061
|
-
// src/hub/peer-doing.ts
|
|
33062
|
-
var TITLE_READ_MAX = 1024 * 1024;
|
|
33063
|
-
var TITLE_LINE_MAX = 64 * 1024;
|
|
33311
|
+
init_peer_doing();
|
|
33064
33312
|
|
|
33065
33313
|
// src/hub/instances.ts
|
|
33066
33314
|
import { types as types10 } from "util";
|
|
@@ -41900,57 +42148,8 @@ function buildNativePermissionProbe(request) {
|
|
|
41900
42148
|
}
|
|
41901
42149
|
}
|
|
41902
42150
|
|
|
41903
|
-
// src/adapters/claude-channel-evidence.ts
|
|
41904
|
-
import { spawnSync as spawnSync5 } from "child_process";
|
|
41905
|
-
var claudeParentCommandPort = { read: readClaudeParentCommand };
|
|
41906
|
-
var TARGETS = new Set(["plugin:agent-hub@agent-hub", "server:agent-hub"]);
|
|
41907
|
-
var DISABLING = new Set(["-p", "--print", "--output-format", "--background", "--detach", "--daemon", "daemon", "bg", "bg-spare"]);
|
|
41908
|
-
function classifyClaudeParentCommand(command) {
|
|
41909
|
-
if (!command || command.length > 4096 || /[\n\r\0]/.test(command))
|
|
41910
|
-
return "launch-unverified";
|
|
41911
|
-
const argv = command.trim().split(/\s+/);
|
|
41912
|
-
const executable = argv[0]?.split("/").at(-1);
|
|
41913
|
-
if (executable !== "claude" || argv.length < 3 || argv[1] !== "--dangerously-load-development-channels" || !TARGETS.has(argv[2]))
|
|
41914
|
-
return "launch-unverified";
|
|
41915
|
-
if (argv.slice(3).some((arg) => DISABLING.has(arg) || arg.startsWith("--print=") || arg.startsWith("--output-format=") || arg.startsWith("-p") || arg === "--dangerously-load-development-channels" || arg.startsWith("--dangerously-load-development-channels=")))
|
|
41916
|
-
return "launch-unverified";
|
|
41917
|
-
return "development-channel-launch";
|
|
41918
|
-
}
|
|
41919
|
-
function readClaudeParentCommand(ppid) {
|
|
41920
|
-
try {
|
|
41921
|
-
const result = spawnSync5("/bin/ps", ["-ww", "-p", String(ppid), "-o", "command="], {
|
|
41922
|
-
encoding: "utf8",
|
|
41923
|
-
timeout: 1500,
|
|
41924
|
-
maxBuffer: 4096,
|
|
41925
|
-
env: { PATH: "/usr/bin:/bin", LC_ALL: "C" }
|
|
41926
|
-
});
|
|
41927
|
-
if (result.error || result.status !== 0 || typeof result.stdout !== "string" || !result.stdout.trim() || result.stdout.trim().includes(`
|
|
41928
|
-
`))
|
|
41929
|
-
return;
|
|
41930
|
-
return result.stdout.trim();
|
|
41931
|
-
} catch {
|
|
41932
|
-
return;
|
|
41933
|
-
}
|
|
41934
|
-
}
|
|
41935
|
-
function claudeChannelEvidence(env = process.env, ppid = process.ppid, read = claudeParentCommandPort.read) {
|
|
41936
|
-
if (env.AGENTHUB_CHANNEL !== "1")
|
|
41937
|
-
return "unknown";
|
|
41938
|
-
if (!Number.isSafeInteger(ppid) || ppid <= 1)
|
|
41939
|
-
return "unknown";
|
|
41940
|
-
try {
|
|
41941
|
-
const command = read(ppid);
|
|
41942
|
-
if (!command || process.ppid !== ppid)
|
|
41943
|
-
return "unknown";
|
|
41944
|
-
return classifyClaudeParentCommand(command);
|
|
41945
|
-
} catch {
|
|
41946
|
-
return "unknown";
|
|
41947
|
-
}
|
|
41948
|
-
}
|
|
41949
|
-
function currentClaudeChannelEvidence() {
|
|
41950
|
-
return claudeChannelEvidence();
|
|
41951
|
-
}
|
|
41952
|
-
|
|
41953
42151
|
// src/adapters/claude-channel.ts
|
|
42152
|
+
init_claude_channel_evidence();
|
|
41954
42153
|
var own5 = channelProject(process.cwd(), process.env, (root) => {
|
|
41955
42154
|
const read = (name) => {
|
|
41956
42155
|
try {
|