@aiti-ai/ext-shared 0.0.0-stage → 0.1.11

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.
Files changed (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -2
  3. package/agent-accounts.test.mjs +227 -0
  4. package/agent-accounts.ts +324 -0
  5. package/agent-capability-contract.test.mjs +129 -0
  6. package/agent-interaction.test.mjs +194 -0
  7. package/agent-interaction.ts +340 -0
  8. package/agent-launch.test.mjs +262 -0
  9. package/agent-spawn-env.test.mjs +169 -0
  10. package/agent-spawn-env.ts +548 -0
  11. package/aiti-editor-inject.mjs +49 -0
  12. package/backend-queue.test.mjs +336 -0
  13. package/backend-queue.ts +469 -0
  14. package/blob-save-route.ts +128 -0
  15. package/cbc-model-catalog.ts +86 -0
  16. package/check-client.mjs +273 -0
  17. package/check-ext-globals.mjs +144 -0
  18. package/controlled-login-dialog.mjs +270 -0
  19. package/controlled-login.mjs +398 -0
  20. package/controlled-login.test.mjs +466 -0
  21. package/convert-saveas.test.mjs +39 -0
  22. package/convert-saveas.ts +170 -0
  23. package/copy-client-bundle.mjs +39 -0
  24. package/cursor-cli-store.ts +377 -0
  25. package/dedupe-fetch.test.mjs +71 -0
  26. package/dedupe-fetch.ts +58 -0
  27. package/deploy-commit.mjs +52 -0
  28. package/dev-pack.mjs +246 -0
  29. package/dock-icons.ts +127 -0
  30. package/esbuild-bin.test.mjs +53 -0
  31. package/esbuild-bin.ts +66 -0
  32. package/exec-async.test.mjs +86 -0
  33. package/exec-async.ts +179 -0
  34. package/ext-display-names.ts +91 -0
  35. package/ext-entry-contracts.test.mjs +131 -0
  36. package/ext-float-dock-core.test.mjs +348 -0
  37. package/ext-float-dock-core.ts +783 -0
  38. package/ext-float-dock-lite.ts +52 -0
  39. package/ext-float-dock.test.mjs +286 -0
  40. package/ext-float-dock.ts +740 -0
  41. package/ext-icons-deploy.mjs +24 -0
  42. package/ext-lazy.test.mjs +186 -0
  43. package/ext-lazy.tsx +183 -0
  44. package/ext-model-state.test.mjs +272 -0
  45. package/ext-model-state.ts +324 -0
  46. package/ext-protocol.mjs +113 -0
  47. package/ext-protocol.test.mjs +88 -0
  48. package/ext-session-usage.test.mjs +219 -0
  49. package/ext-session-usage.ts +507 -0
  50. package/external-cli-governance.ts +153 -0
  51. package/git-ops-client/api.mjs +56 -0
  52. package/git-ops-client/branch-panel.tsx +987 -0
  53. package/git-ops-client/i18n.mjs +328 -0
  54. package/host-tools-allow.test.mjs +46 -0
  55. package/host-tools-allow.ts +84 -0
  56. package/icons/alert.svg +1 -0
  57. package/icons/bookmark.svg +1 -0
  58. package/icons/bot.svg +1 -0
  59. package/icons/chart-column.svg +1 -0
  60. package/icons/check-circle.svg +1 -0
  61. package/icons/clipboard-list.svg +1 -0
  62. package/icons/clock.svg +1 -0
  63. package/icons/coffee.svg +1 -0
  64. package/icons/edit.svg +1 -0
  65. package/icons/eye.svg +1 -0
  66. package/icons/git-branch.svg +1 -0
  67. package/icons/git-commit-horizontal.svg +1 -0
  68. package/icons/globe.svg +1 -0
  69. package/icons/history.svg +1 -0
  70. package/icons/import.svg +1 -0
  71. package/icons/inbox.svg +1 -0
  72. package/icons/key-round.svg +1 -0
  73. package/icons/layout-grid.svg +1 -0
  74. package/icons/mail.svg +1 -0
  75. package/icons/message-circle.svg +1 -0
  76. package/icons/message-square.svg +1 -0
  77. package/icons/meter-vertical.svg +1 -0
  78. package/icons/mic.svg +1 -0
  79. package/icons/monitor.svg +1 -0
  80. package/icons/pen-line.svg +1 -0
  81. package/icons/plug.svg +1 -0
  82. package/icons/radio-dot.svg +1 -0
  83. package/icons/radio.svg +1 -0
  84. package/icons/refresh.svg +1 -0
  85. package/icons/rocket.svg +1 -0
  86. package/icons/search.svg +1 -0
  87. package/icons/shield.svg +1 -0
  88. package/icons/sparkles.svg +1 -0
  89. package/icons/square-kanban.svg +1 -0
  90. package/icons/terminal.svg +1 -0
  91. package/icons/users.svg +1 -0
  92. package/icons/volume-2.svg +1 -0
  93. package/icons/wand.svg +1 -0
  94. package/icons/wrench.svg +1 -0
  95. package/icons/x-circle.svg +1 -0
  96. package/icons/x.svg +1 -0
  97. package/ignore-semantics.ts +76 -0
  98. package/lazy-loading-metrics.mjs +61 -0
  99. package/new-session-cwd.test.mjs +389 -0
  100. package/new-session-cwd.ts +253 -0
  101. package/open-viewer-window.ts +65 -0
  102. package/overlay-back-client.test.mjs +123 -0
  103. package/overlay-back-client.ts +87 -0
  104. package/package.json +65 -4
  105. package/pi-fork-rpc/README.md +12 -0
  106. package/pi-fork-rpc/cli-resolve.test.mjs +42 -0
  107. package/pi-fork-rpc/cli-resolve.ts +79 -0
  108. package/pi-fork-rpc/remote-queue.test.mjs +100 -0
  109. package/pi-fork-rpc/remote-queue.ts +140 -0
  110. package/pi-fork-rpc/spec.ts +106 -0
  111. package/pi-fork-rpc/wire.test.mjs +260 -0
  112. package/pi-fork-rpc/wire.ts +367 -0
  113. package/popup-anchor.ts +45 -0
  114. package/provider-priority-contract.test.mjs +55 -0
  115. package/reconcile-deps.mjs +41 -0
  116. package/reload-instances.mjs +60 -0
  117. package/seed-tool.test.mjs +95 -0
  118. package/seed-tool.ts +88 -0
  119. package/session-recycle.ts +109 -0
  120. package/shared-copy-sync.test.mjs +115 -0
  121. package/soffice-locate.ts +171 -0
  122. package/soffice-panel.ts +239 -0
  123. package/sync-dir.mjs +91 -0
  124. package/sync-dir.test.mjs +101 -0
  125. package/sync-gate.test.mjs +93 -0
  126. package/sync-mirror.test.mjs +85 -0
  127. package/task-list.test.mjs +91 -0
  128. package/task-list.ts +118 -0
  129. package/test-rm-rf.mjs +33 -0
  130. package/ui-dialogs.test.mjs +198 -0
  131. package/ui-dialogs.ts +310 -0
@@ -0,0 +1,79 @@
1
+ /**
2
+ * cli-resolve.ts — fork CLI 解析(载体无关)。
3
+ * 拆自 aiti-pi-agent 的 pi-rpc-spawn.ts:resolveForkCli / resolveBun / which。
4
+ */
5
+
6
+ import { existsSync, statSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import type { PiForkSpec } from "./spec.ts";
9
+
10
+ export interface ResolvedForkCli {
11
+ /** 实际执行的解释器(node / bun)。 */
12
+ runner: string;
13
+ /** 解释器参数(通常 [cliPath];PATH 可执行直跑时 [])。 */
14
+ args: string[];
15
+ /** 人类可读的解析来源(日志/报错用)。 */
16
+ origin: string;
17
+ }
18
+
19
+ /**
20
+ * 解析 fork CLI。解析顺序:
21
+ * 1) spec.cliEnvVar 显式指定(绝对路径,交给 runtime 解释)
22
+ * 2) spec.bundledCli()(pi:pi-web 包内 SDK cli.js,node 解释)
23
+ * 3) PATH 上的 spec.pathBin(绝对路径 → runtime 解释;找不到 → null)
24
+ *
25
+ * fork 未装时返回 null:provider 照常注册,createSession 报清晰错误(不阻塞列表)。
26
+ */
27
+ export function resolveForkCli(spec: PiForkSpec): ResolvedForkCli | null {
28
+ const explicit = process.env[spec.cliEnvVar];
29
+ if (explicit && existsSync(explicit)) {
30
+ return { runner: spec.runtime === "bun" ? resolveBun() : process.execPath, args: [explicit], origin: `env ${spec.cliEnvVar}` };
31
+ }
32
+ const bundled = spec.bundledCli?.();
33
+ if (bundled) {
34
+ return { runner: process.execPath, args: [bundled], origin: "bundled SDK" };
35
+ }
36
+ const onPath = which(spec.pathBin);
37
+ if (onPath) {
38
+ return { runner: spec.runtime === "bun" ? resolveBun() : process.execPath, args: [onPath], origin: `PATH ${spec.pathBin}` };
39
+ }
40
+ // 兜底:bun 全局安装目录(systemd 等服务进程 PATH 通常不含 ~/.bun/bin)
41
+ const bunGlobalBin = join(process.env.HOME || "", ".bun", "bin", spec.pathBin);
42
+ if (spec.runtime === "bun" && existsSync(bunGlobalBin)) {
43
+ return { runner: resolveBun(), args: [bunGlobalBin], origin: "~/.bun/bin" };
44
+ }
45
+ return null;
46
+ }
47
+
48
+ /** bun 解释器解析:env BUN → PATH bun。找不到返回 "bun"(让 spawn 报 ENOENT,fail loud)。 */
49
+ export function resolveBun(): string {
50
+ return process.env.BUN || "bun";
51
+ }
52
+
53
+ /** PATH 查找可执行文件(同步;Windows 兼容:`;` 分隔 + PATHEXT 后缀 + isFile 校验;
54
+ * POSIX 额外要求可执行位)。找不到返回 undefined。 */
55
+ export function which(bin: string): string | undefined {
56
+ const isWin = process.platform === "win32";
57
+ const pathDirs = (process.env.PATH ?? "").split(isWin ? ";" : ":").filter(Boolean);
58
+ // Windows 还要试 PATHEXT 后缀(pi.cmd / pi.exe …);首项空串 = 精确名优先
59
+ const exts = isWin ? ["", ...(process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";")] : [""];
60
+ for (const dir of pathDirs) {
61
+ for (const ext of exts) {
62
+ const candidate = join(dir, bin + ext);
63
+ if (isExecutableFile(candidate)) return candidate;
64
+ }
65
+ }
66
+ return undefined;
67
+ }
68
+
69
+ /** 候选必须是文件(目录命名的同名项不算)且可执行(POSIX 查可执行位)。 */
70
+ function isExecutableFile(path: string): boolean {
71
+ let st;
72
+ try {
73
+ st = statSync(path);
74
+ } catch {
75
+ return false;
76
+ }
77
+ if (!st.isFile()) return false;
78
+ return process.platform === "win32" || (st.mode & 0o111) !== 0;
79
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * remote-queue 共享层测试(docs/aiti-remote-queue-and-sidecar-plan.md §2)。
3
+ * 镜像维护 / list / clear 返回清空前文本 / move·remove·requeue·convert 的
4
+ * clear+重注入策略 / 索越界人话错误。
5
+ *
6
+ * Run: node --test pi-web-ext/_shared/pi-fork-rpc/remote-queue.test.mjs
7
+ */
8
+ import assert from "node:assert/strict";
9
+ import test from "node:test";
10
+
11
+ const modPath = new URL("./remote-queue.ts", import.meta.url).pathname;
12
+ const { createRemotePiQueueSupport } = await import(modPath);
13
+
14
+ /** 台架:可编程 clearRemote 返回 + 记录重注入调用。 */
15
+ function rig() {
16
+ const clears = [];
17
+ const reinjections = [];
18
+ const support = createRemotePiQueueSupport({
19
+ clearRemote: async () => {
20
+ clears.push(1);
21
+ // 语义:清空返回「清空前」的内容——用当前重注入目标队列模拟不现实,测试只断言调用次数,
22
+ // 文本返回值由用例自定义(见 clearRemoteResult 覆写)。
23
+ return rigClearResult;
24
+ },
25
+ reinject: async (text, kind) => { reinjections.push({ text, kind }); },
26
+ });
27
+ let rigClearResult = { steering: [], followUp: [] };
28
+ return {
29
+ support,
30
+ reinjections,
31
+ clearCount: () => clears.length,
32
+ setClearResult: (r) => { rigClearResult = r; },
33
+ feed(steering, followUp) { support.observeFrame({ type: "queue_update", steering, followUp }); },
34
+ };
35
+ }
36
+
37
+ test("镜像:observeFrame 只认 queue_update,快照返回拷贝", () => {
38
+ const t = rig();
39
+ t.feed(["s1"], ["f1", "f2"]);
40
+ assert.deepEqual(t.support.snapshot(), { steering: ["s1"], followUp: ["f1", "f2"] });
41
+ t.support.observeFrame({ type: "message_update" });
42
+ t.support.observeFrame({ type: "queue_update" });
43
+ assert.deepEqual(t.support.snapshot(), { steering: [], followUp: [] }, "缺数组按空归一");
44
+ const snap = t.support.snapshot();
45
+ snap.followUp.push("mutated");
46
+ assert.deepEqual(t.support.snapshot().followUp, [], "快照须是拷贝");
47
+ });
48
+
49
+ test("clear:远端权威清空 + 返回清空前文本 + 镜像复位", async () => {
50
+ const t = rig();
51
+ t.feed([], ["a", "b"]);
52
+ t.setClearResult({ steering: [], followUp: ["a", "b"] });
53
+ const r = await t.support.queueManage({ action: "clear" });
54
+ assert.equal(t.clearCount(), 1);
55
+ assert.deepEqual(r.followUp, ["a", "b"], "clear 返回清空前文本(recallAll 契约)");
56
+ assert.deepEqual(t.support.snapshot().followUp, []);
57
+ assert.deepEqual(t.reinjections, [], "clear 不重注入");
58
+ });
59
+
60
+ test("move:镜像算新序 → clear + 按新序全量重注入", async () => {
61
+ const t = rig();
62
+ t.feed([], ["a", "b", "c"]);
63
+ const r = await t.support.queueManage({ action: "move", from: 0, to: 2 });
64
+ assert.equal(t.clearCount(), 1);
65
+ assert.deepEqual(r.followUp, ["b", "c", "a"]);
66
+ assert.deepEqual(t.reinjections, [
67
+ { text: "b", kind: "followUp" }, { text: "c", kind: "followUp" }, { text: "a", kind: "followUp" },
68
+ ]);
69
+ });
70
+
71
+ test("remove/recall:返回取回条目;requeue 插入;convert 跨组移动", async () => {
72
+ const t = rig();
73
+ t.feed(["s0"], ["a"]);
74
+ const rm = await t.support.queueManage({ action: "remove", index: 0 });
75
+ assert.equal(rm.removed.text, "a");
76
+ assert.deepEqual(rm.entry.text, "a");
77
+
78
+ const rq = await t.support.queueManage({ action: "requeue", index: 0, text: "back" });
79
+ assert.deepEqual(rq.followUp, ["back"]);
80
+ assert.deepEqual(t.reinjections.at(-1), { text: "back", kind: "followUp" });
81
+ assert.deepEqual(t.reinjections.at(-2), { text: "s0", kind: "steer" }, "steer 组须一并重注入");
82
+
83
+ t.feed(["s1"], []);
84
+ const cv = await t.support.queueManage({ action: "convert", kind: "steer", targetKind: "followUp", index: 0 });
85
+ assert.equal(cv.entry.text, "s1");
86
+ assert.deepEqual(cv.followUp, ["s1"]);
87
+ assert.deepEqual(t.reinjections.at(-1), { text: "s1", kind: "followUp" });
88
+
89
+ const rc = await t.support.queueManage({ action: "recall", kind: "followUp", index: 0 });
90
+ assert.equal(rc.entry.text, "s1");
91
+ });
92
+
93
+ test("越界 / 未知 action / convert 同组 → 人话错误", async () => {
94
+ const t = rig();
95
+ t.feed([], ["a"]);
96
+ await assert.rejects(() => t.support.queueManage({ action: "remove", index: 5 }), /越界/);
97
+ await assert.rejects(() => t.support.queueManage({ action: "requeue", index: 0, text: " " }), /非空/);
98
+ await assert.rejects(() => t.support.queueManage({ action: "convert", kind: "steer", targetKind: "steer", index: 0 }), /targetKind/);
99
+ await assert.rejects(() => t.support.queueManage({ action: "nope" }), /未知 action/);
100
+ });
@@ -0,0 +1,140 @@
1
+ /**
2
+ * remote-queue — 远端 pi 协议队列的 queueManage 适配层(共享层,副本随扩展部署——改动须双向同步;
3
+ * docs/aiti-remote-queue-and-sidecar-plan.md §2)。
4
+ *
5
+ * 适用形态:pi RPC 子进程(aiti-pi-agent)与其超集 fork omp(aiti-omp-agent)——队列由
6
+ * 子进程持有,协议原生支持 clear_queue(返回清空前文本,与 pi-web core clearQueue 同契约)
7
+ * 与 steer/follow_up 重注入;子进程经 RPC 流转发 queue_update 帧(含完整文本数组)。
8
+ *
9
+ * 镜像正确性:handle 生命周期 == 子进程生命周期,双方同起点(皆空),无重连缺口——
10
+ * 镜像只从 observeFrame 喂入的 queue_update 帧维护。get_state 仅有 pendingMessageCount
11
+ * (无文本),不存在「拉全量」原语,重连场景不在本层适配范围。
12
+ *
13
+ * 变更类操作语义(与 pi-web core rpc-manager move_queue 同款):镜像算出新序 →
14
+ * clear_queue 全量清空 → 按新序重注入。运行中 steer 重注入可能被立即消费的竞态
15
+ * 为该策略既有语义(clear+re-enqueue 在单请求内原子性足够)。
16
+ */
17
+
18
+ export interface RemoteQueueManageReq {
19
+ action: "list" | "clear" | "move" | "convert" | "remove" | "recall" | "requeue";
20
+ kind?: "steer" | "followUp";
21
+ from?: number;
22
+ to?: number;
23
+ index?: number;
24
+ targetKind?: "steer" | "followUp";
25
+ text?: string;
26
+ }
27
+
28
+ export interface RemoteQueueManageResult {
29
+ steering: string[];
30
+ followUp: string[];
31
+ entry?: { text: string };
32
+ /** remove 时返回(对齐 backend-queue / pi-web core QueueTrashItem 的文本字段)。 */
33
+ removed?: { text: string };
34
+ }
35
+
36
+ export interface RemotePiQueue {
37
+ /** handle.onFrame 里喂入子进程帧;只消费 queue_update(镜像维护,不重复广播——原帧由 handle 照常 emit)。 */
38
+ observeFrame(msg: Record<string, unknown>): void;
39
+ /** SessionHandle.queueManage 直转发。 */
40
+ queueManage(req: RemoteQueueManageReq): Promise<RemoteQueueManageResult>;
41
+ /** 当前镜像快照(steer/followUp 两组文本)。 */
42
+ snapshot(): { steering: string[]; followUp: string[] };
43
+ }
44
+
45
+ export function createRemotePiQueueSupport(opts: {
46
+ /** 子进程 clear_queue 请求(返回清空前文本;上游不支持时 fail-loud 由调用方人话化)。 */
47
+ clearRemote(): Promise<{ steering?: string[]; followUp?: string[] }>;
48
+ /** 重注入单条(kind=steer → steer 命令;followUp → follow_up 命令)。 */
49
+ reinject(text: string, kind: "steer" | "followUp"): Promise<void>;
50
+ }): RemotePiQueue {
51
+ let mirror: { steering: string[]; followUp: string[] } = { steering: [], followUp: [] };
52
+
53
+ const snapshot = () => ({ steering: [...mirror.steering], followUp: [...mirror.followUp] });
54
+
55
+ const observeFrame = (msg: Record<string, unknown>): void => {
56
+ if (msg.type !== "queue_update") return;
57
+ mirror = {
58
+ steering: Array.isArray(msg.steering) ? (msg.steering as string[]).map(String) : [],
59
+ followUp: Array.isArray(msg.followUp) ? (msg.followUp as string[]).map(String) : [],
60
+ };
61
+ };
62
+
63
+ /** 变更类共用骨架:对镜像副本计算新序 → 远端全量清空 → 按新序重注入 → 镜像落为新序。 */
64
+ const mutate = async (
65
+ plan: (cur: { steering: string[]; followUp: string[] }) => { steering: string[]; followUp: string[] },
66
+ ): Promise<void> => {
67
+ const next = plan(snapshot());
68
+ await opts.clearRemote();
69
+ for (const text of next.steering) await opts.reinject(text, "steer");
70
+ for (const text of next.followUp) await opts.reinject(text, "followUp");
71
+ mirror = { steering: [...next.steering], followUp: [...next.followUp] };
72
+ };
73
+
74
+ const at = (arr: string[], i: number | undefined): number => {
75
+ const n = Number(i);
76
+ if (!Number.isInteger(n) || n < 0 || n >= arr.length) throw new Error("队列索引越界");
77
+ return n;
78
+ };
79
+
80
+ const queueManage = async (req: RemoteQueueManageReq): Promise<RemoteQueueManageResult> => {
81
+ if (req.action === "list") return { ...snapshot() };
82
+ switch (req.action) {
83
+ case "clear": {
84
+ // 远端权威清空:返回值 = 清空前文本(即「清掉了什么」,snapshot 语义不适用)
85
+ const cleared = await opts.clearRemote();
86
+ mirror = { steering: [], followUp: [] };
87
+ return { steering: (cleared.steering ?? []).map(String), followUp: (cleared.followUp ?? []).map(String) };
88
+ }
89
+ case "remove":
90
+ case "recall": {
91
+ const cur = snapshot();
92
+ const group = req.kind === "steer" ? cur.steering : cur.followUp;
93
+ const [picked] = group.splice(at(group, req.index), 1);
94
+ await mutate(() => cur);
95
+ return {
96
+ steering: cur.steering,
97
+ followUp: cur.followUp,
98
+ entry: { text: picked },
99
+ ...(req.action === "remove" ? { removed: { text: picked } } : {}),
100
+ };
101
+ }
102
+ case "move": {
103
+ const cur = snapshot();
104
+ const group = req.kind === "steer" ? cur.steering : cur.followUp;
105
+ // 两个索引都在删除前对原长度校验(pi-web core move_queue 同款语义)
106
+ const from = at(group, req.from);
107
+ const to = at(group, req.to);
108
+ const [moved] = group.splice(from, 1);
109
+ group.splice(to, 0, moved);
110
+ await mutate(() => cur);
111
+ return { steering: cur.steering, followUp: cur.followUp };
112
+ }
113
+ case "requeue": {
114
+ const cur = snapshot();
115
+ const group = req.kind === "steer" ? cur.steering : cur.followUp;
116
+ const i = Number(req.index);
117
+ const text = String(req.text ?? "");
118
+ if (!Number.isInteger(i) || i < 0 || i > group.length) throw new Error("队列索引越界");
119
+ if (!text.trim()) throw new Error("requeue 需要非空文本");
120
+ group.splice(i, 0, text);
121
+ await mutate(() => cur);
122
+ return { steering: cur.steering, followUp: cur.followUp };
123
+ }
124
+ case "convert": {
125
+ const target = req.targetKind === "followUp" ? "followUp" : "steer";
126
+ const kind = req.kind === "steer" ? "steer" : "followUp";
127
+ if (target === kind) throw new Error("convert 需要不同于当前的 targetKind");
128
+ const cur = snapshot();
129
+ const [picked] = (kind === "steer" ? cur.steering : cur.followUp).splice(at(kind === "steer" ? cur.steering : cur.followUp, req.index), 1);
130
+ (target === "steer" ? cur.steering : cur.followUp).push(picked);
131
+ await mutate(() => cur);
132
+ return { steering: cur.steering, followUp: cur.followUp, entry: { text: picked } };
133
+ }
134
+ default:
135
+ throw new Error(`queueManage: 未知 action "${String(req.action)}"`);
136
+ }
137
+ };
138
+
139
+ return { observeFrame, queueManage, snapshot };
140
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * spec.ts — pi 系 fork 家族的类型与能力声明(载体无关,无 fork 语义之外的逻辑)。
3
+ * 拆自 aiti-pi-agent 的 pi-rpc-spawn.ts:类型/常量原样迁移;registerFork/listForks
4
+ * (家族注册机制)随拆分退役——每个扩展各自声明自己的 spec。
5
+ */
6
+
7
+ // ============================================================================
8
+ // 家族差异声明
9
+ // ============================================================================
10
+
11
+ export interface PiForkCommands {
12
+ /** fork 元语命令名:pi=fork;omp=branch。 */
13
+ fork: "fork" | "branch";
14
+ /** fork 消息查询命令名(本引擎暂未消费,声明给后续 viewer 用)。 */
15
+ getForkMessages: "get_fork_messages" | "get_branch_messages";
16
+ /** 命令清单查询命令名:pi=get_commands;omp=get_available_commands。 */
17
+ getCommands: "get_commands" | "get_available_commands";
18
+ /** 是否支持 get_entries(pi true;omp false → 走 get_messages)。 */
19
+ hasGetEntries: boolean;
20
+ /** 是否有启动 ready 握手帧(omp true;pi 无 → 300ms sleep 兜底)。 */
21
+ hasReadyFrame: boolean;
22
+ /** get_state 是否含 contextUsage(omp true)。 */
23
+ hasContextUsage: boolean;
24
+ /** get_state 是否含 dumpTools(omp true)。 */
25
+ hasDumpTools: boolean;
26
+ /** 是否支持宿主工具注入(omp set_host_tools / host_tool_call|result|cancel)。 */
27
+ hasHostTools: boolean;
28
+ /** 是否支持 OAuth 登录 RPC(omp get_login_providers/login → open_url 帧;pi 无)。 */
29
+ hasLogin: boolean;
30
+ /** A09:subagent RPC 面(omp get_subagents/set_subagent_subscription/get_subagent_messages;pi 无)。 */
31
+ hasSubagents: boolean;
32
+ }
33
+
34
+ export interface PiForkSpec {
35
+ /** 家族成员 id(= provider type 后缀:spawn / omp-spawn)。 */
36
+ id: string;
37
+ /** Backend 下拉 UI label。 */
38
+ label: string;
39
+ /** Backend 下拉位次(SessionProvider.order)。 */
40
+ order: number;
41
+ /** agentKey(all-sessions 认领键;omp 会话落 ~/.omp,不认领 pi 历史)。 */
42
+ agentKey?: string;
43
+ /** 执行运行时:node → 显式 process.execPath 解释 cli.js;bun → 显式 bun 解释。 */
44
+ runtime: "node" | "bun";
45
+ /** PATH 上的 CLI 名(pi / omp)。 */
46
+ pathBin: string;
47
+ /** 显式 CLI 覆盖 env 变量名(如 OMP_CLI)。 */
48
+ cliEnvVar: string;
49
+ /** 包内自带 SDK cli.js 路径(pi 专用:PI_WEB_PKG_DIR);无则不启用该解析层。 */
50
+ bundledCli?(): string | undefined;
51
+ commands: PiForkCommands;
52
+ }
53
+
54
+ /**
55
+ * 宿主工具定义(omp host tools):宿主注入给 fork 子进程的工具;agent 调用时经
56
+ * `host_tool_call` 帧回传宿主执行,宿主以 `host_tool_result` 应答(omp 独有能力)。
57
+ */
58
+ export interface HostToolDefinition {
59
+ name: string;
60
+ label?: string;
61
+ description: string;
62
+ /** JSON Schema(omp RpcHostToolDefinition.parameters)。 */
63
+ parameters: Record<string, unknown>;
64
+ /** 宿主执行体:返回文本结果;抛错 → isError 结果帧。 */
65
+ execute(args: Record<string, unknown>, signal: AbortSignal): Promise<string>;
66
+ }
67
+
68
+ /** Handle 能力位(SessionCapabilities 的 fork 家族子集,前端据此渲染操作面)。 */
69
+ export interface ForkCapabilities extends Record<string, boolean> {}
70
+
71
+ /** 由 spec.commands 派生能力位(pi/omp 各扩展以此声明 maxCapabilities)。 */
72
+ export function capabilitiesFor(spec: PiForkSpec): ForkCapabilities {
73
+ return {
74
+ steer: true,
75
+ followUp: true,
76
+ // 队列 keeper 全 CRUD(remote-queue 共享层:clear_queue 原生 + clear/重注入变更策略,
77
+ // docs/aiti-remote-queue-and-sidecar-plan.md §2)
78
+ queueManage: true,
79
+ // steering 条目同样可撤回/移动/转换(变更即 clear+重注入)——宿主据此放开队列面板
80
+ // steer 行的行级操作;zcode 那类「已注入对端进程、协议收不回」的后端不声明
81
+ steerQueueManage: true,
82
+ getMessages: true,
83
+ contextUsage: spec.commands.hasContextUsage, // omp get_state.contextUsage;pi RPC 无
84
+ setModel: true,
85
+ setThinkingLevel: true,
86
+ fork: true,
87
+ renameSession: true,
88
+ compact: true,
89
+ executeBash: true,
90
+ setActiveTools: false, // 两系 RPC 均无(待实测协议面,见拆分计划 B5)
91
+ navigateTree: false,
92
+ deleteSession: false,
93
+ getCommands: true,
94
+ listModels: true,
95
+ listTools: spec.commands.hasDumpTools, // omp get_state.dumpTools;pi RPC 无(待实测)
96
+ // 进阶能力(2026-09-14 拆分时盘点):respondInteraction 已实现,补声明;
97
+ // respondPermission/getUsage/fileAttachments 待实测协议面后补(B5)。
98
+ respondInteraction: true,
99
+ subagents: spec.commands.hasSubagents,
100
+ respondPermission: false,
101
+ getUsage: false,
102
+ fileAttachments: false,
103
+ respondProviderHeaders: false, // zcode 专属
104
+ setPermissionMode: false, // cc-connect 专属
105
+ };
106
+ }