@sleep2agi/agent-network 2.3.0-preview.18 → 2.3.0-preview.180

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 (193) hide show
  1. package/README.md +35 -324
  2. package/dist/bin/anet.cjs +101 -0
  3. package/dist/bin/cli.d.ts +1 -0
  4. package/dist/bin/cli.js +20 -1
  5. package/dist/src/active-network-task.d.ts +28 -0
  6. package/dist/src/batch-workdir.d.ts +9 -0
  7. package/dist/src/bootstrap-password-db.d.ts +13 -0
  8. package/dist/src/channel-attachments.d.ts +29 -0
  9. package/dist/src/channel-inbox-wake.d.ts +21 -0
  10. package/dist/src/channel-meta.d.ts +10 -0
  11. package/dist/src/channel-peer-reply.d.ts +41 -0
  12. package/dist/src/channel-task-trace.d.ts +14 -0
  13. package/dist/src/claude-vendor-env.d.ts +28 -0
  14. package/dist/src/cli-args.d.ts +8 -0
  15. package/dist/src/cli-auth-session.d.ts +47 -0
  16. package/dist/src/cli-errors.d.ts +41 -0
  17. package/dist/src/cli-exit.d.ts +11 -0
  18. package/dist/src/cli-help.d.ts +10 -0
  19. package/dist/src/cli-version-display.d.ts +16 -0
  20. package/dist/src/client-task-trace.d.ts +9 -0
  21. package/dist/src/client.js +1 -1
  22. package/dist/src/codex-adopt.d.ts +46 -0
  23. package/dist/src/codex-auth-fingerprint.d.ts +211 -0
  24. package/dist/src/codex-bin-pin.d.ts +23 -0
  25. package/dist/src/codex-commhub-mcp.d.ts +22 -0
  26. package/dist/src/codex-copresence-bridge-log.d.ts +44 -0
  27. package/dist/src/codex-copresence-env.d.ts +5 -0
  28. package/dist/src/codex-copresence-login-gate.d.ts +18 -0
  29. package/dist/src/codex-copresence-model.d.ts +23 -0
  30. package/dist/src/codex-copresence-preflight.d.ts +78 -0
  31. package/dist/src/codex-copresence-profile.d.ts +126 -0
  32. package/dist/src/codex-copresence-recovery.d.ts +70 -0
  33. package/dist/src/codex-copresence-resume-timeout.d.ts +28 -0
  34. package/dist/src/codex-copresence-rollout-guard.d.ts +36 -0
  35. package/dist/src/codex-copresence-rpc.d.ts +17 -0
  36. package/dist/src/codex-copresence-thread.d.ts +13 -0
  37. package/dist/src/codex-copresence-yolo.d.ts +16 -0
  38. package/dist/src/codex-external-appserver.d.ts +130 -0
  39. package/dist/src/codex-fork-recovery.d.ts +52 -0
  40. package/dist/src/codex-home-enforce.d.ts +88 -0
  41. package/dist/src/codex-lifecycle-account.d.ts +104 -0
  42. package/dist/src/codex-lifecycle-canary.d.ts +20 -0
  43. package/dist/src/codex-lifecycle-facts.d.ts +53 -0
  44. package/dist/src/codex-lifecycle-fork.d.ts +91 -0
  45. package/dist/src/codex-lifecycle-preflight.d.ts +79 -0
  46. package/dist/src/codex-lifecycle-receipt.d.ts +53 -0
  47. package/dist/src/codex-lifecycle-restart.d.ts +88 -0
  48. package/dist/src/codex-login-share-guard.d.ts +146 -0
  49. package/dist/src/codex-menu.d.ts +99 -0
  50. package/dist/src/codex-model-default.d.ts +6 -0
  51. package/dist/src/codex-node-login.d.ts +98 -0
  52. package/dist/src/codex-pending-thread-restart.d.ts +69 -0
  53. package/dist/src/codex-reasoning-effort.d.ts +17 -0
  54. package/dist/src/codex-recovery-lease.d.ts +39 -0
  55. package/dist/src/codex-recovery-resource-gate.d.ts +15 -0
  56. package/dist/src/codex-resume.d.ts +89 -0
  57. package/dist/src/codex-rollout-history-guard.d.ts +84 -0
  58. package/dist/src/codex-tui-client-health.d.ts +30 -0
  59. package/dist/src/commhub-response.d.ts +1 -0
  60. package/dist/src/controlled-upload.d.ts +83 -0
  61. package/dist/src/copresence-deps.d.ts +22 -0
  62. package/dist/src/copresence-identity.d.ts +363 -0
  63. package/dist/src/copresence-startup-diagnosis.d.ts +17 -0
  64. package/dist/src/daemon-adopt.d.ts +14 -0
  65. package/dist/src/daemon-anet-bin.d.ts +32 -0
  66. package/dist/src/daemon-capability-display.d.ts +110 -0
  67. package/dist/src/daemon-capability-display.js +21 -0
  68. package/dist/src/daemon-codex-inventory.d.ts +65 -0
  69. package/dist/src/daemon-inherited-env.d.ts +9 -0
  70. package/dist/src/daemon-provider-account-custody.d.ts +28 -0
  71. package/dist/src/daemon-provider-account-readback.d.ts +3 -0
  72. package/dist/src/daemon-provider-application.d.ts +36 -0
  73. package/dist/src/daemon-provider-apply-command.d.ts +9 -0
  74. package/dist/src/daemon-provider-collect.d.ts +29 -0
  75. package/dist/src/daemon-provider-command.d.ts +7 -0
  76. package/dist/src/daemon-provider-initialize.d.ts +27 -0
  77. package/dist/src/daemon-provider-lifecycle.d.ts +4 -0
  78. package/dist/src/daemon-provider-store.d.ts +104 -0
  79. package/dist/src/daemon-runtime-path-preflight.d.ts +22 -0
  80. package/dist/src/daemon-runtime-staleness.d.ts +13 -0
  81. package/dist/src/dashboard-managed-process.d.ts +35 -0
  82. package/dist/src/display-width.d.ts +27 -0
  83. package/dist/src/doctor-node-count.d.ts +28 -0
  84. package/dist/src/grok-attach-client.d.ts +129 -0
  85. package/dist/src/grok-build-drift.d.ts +15 -0
  86. package/dist/src/grok-copresence-disclosure.d.ts +11 -0
  87. package/dist/src/grok-copresence-orchestration.d.ts +75 -0
  88. package/dist/src/grok-copresence-profile.d.ts +65 -0
  89. package/dist/src/grok-create-mode.d.ts +19 -0
  90. package/dist/src/host-telemetry.d.ts +14 -0
  91. package/dist/src/hub-health-timeout.d.ts +4 -0
  92. package/dist/src/hub-server-version.d.ts +64 -0
  93. package/dist/src/hub-stop.d.ts +74 -0
  94. package/dist/src/hub-time-display.d.ts +20 -0
  95. package/dist/src/hub-version-skew.d.ts +19 -0
  96. package/dist/src/im/correlation-store.d.ts +34 -0
  97. package/dist/src/im/feishu/adapter.d.ts +43 -0
  98. package/dist/src/im/feishu/bridge.d.ts +78 -14
  99. package/dist/src/im/feishu/hub-upload.d.ts +1 -1
  100. package/dist/src/im/feishu/worker-lifecycle.d.ts +13 -0
  101. package/dist/src/im/feishu/worker.js +174 -161
  102. package/dist/src/inbox-drain.d.ts +20 -0
  103. package/dist/src/local-process-state.d.ts +12 -0
  104. package/dist/src/locale-diagnostic.d.ts +12 -0
  105. package/dist/src/login-client-label.d.ts +6 -0
  106. package/dist/src/ls-columns.d.ts +15 -0
  107. package/dist/src/mock-llm.d.ts +12 -0
  108. package/dist/src/node-activity-log.d.ts +4 -0
  109. package/dist/src/node-clone.d.ts +134 -0
  110. package/dist/src/node-delete-hub.d.ts +42 -0
  111. package/dist/src/node-files.d.ts +62 -0
  112. package/dist/src/node-locate.d.ts +60 -0
  113. package/dist/src/node-ls-all.d.ts +80 -0
  114. package/dist/src/node-menu.d.ts +40 -0
  115. package/dist/src/node-not-found.d.ts +1 -0
  116. package/dist/src/node-remote.d.ts +180 -0
  117. package/dist/src/node-running-guard.d.ts +9 -0
  118. package/dist/src/node-server-identity.d.ts +35 -0
  119. package/dist/src/node-server-payload.d.ts +66 -0
  120. package/dist/src/node-server-rules-file.d.ts +14 -0
  121. package/dist/src/node-server-version.d.ts +39 -0
  122. package/dist/src/node-server.js +8 -1
  123. package/dist/src/node-skills.d.ts +57 -0
  124. package/dist/src/normalize-runtime.d.ts +29 -2
  125. package/dist/src/offline-age.d.ts +29 -0
  126. package/dist/src/one-line-cell.d.ts +20 -0
  127. package/dist/src/opencode-agent-node-pair.d.ts +28 -0
  128. package/dist/src/opencode-auth-login.d.ts +43 -0
  129. package/dist/src/opencode-free-tier.d.ts +27 -0
  130. package/dist/src/opencode-generation-create.d.ts +27 -0
  131. package/dist/src/opencode-generation-record.d.ts +24 -0
  132. package/dist/src/opencode-launch-env.d.ts +13 -0
  133. package/dist/src/opencode-owner-mode.d.ts +6 -0
  134. package/dist/src/opencode-package-binary.d.ts +44 -0
  135. package/dist/src/opencode-pin.d.ts +61 -0
  136. package/dist/src/opencode-preset.d.ts +77 -0
  137. package/dist/src/opencode-runtime-binding.d.ts +30 -0
  138. package/dist/src/opencode-safe-root.d.ts +36 -0
  139. package/dist/src/opencode-shared-server-create.d.ts +5 -0
  140. package/dist/src/opencode-smoke-env.d.ts +1 -0
  141. package/dist/src/opencode-start-mode.d.ts +8 -0
  142. package/dist/src/opencode-v2-configured-model.d.ts +34 -0
  143. package/dist/src/opencode-v2-create-align.d.ts +18 -0
  144. package/dist/src/opencode-versions.d.ts +44 -0
  145. package/dist/src/outbound-attachments.d.ts +60 -0
  146. package/dist/src/outbound-tool-names.d.ts +1 -0
  147. package/dist/src/owned-roots.d.ts +58 -0
  148. package/dist/src/owner-env-file.d.ts +2 -0
  149. package/dist/src/package-mode-preflight.d.ts +41 -0
  150. package/dist/src/posix-codex-copresence.d.ts +33 -0
  151. package/dist/src/posix-modes.d.ts +36 -0
  152. package/dist/src/primary-network.d.ts +23 -0
  153. package/dist/src/private-state.d.ts +10 -0
  154. package/dist/src/process-telemetry.d.ts +12 -0
  155. package/dist/src/profile-serialize.d.ts +1 -0
  156. package/dist/src/project-key.d.ts +1 -0
  157. package/dist/src/provider-application-contract.d.ts +11 -0
  158. package/dist/src/provider-apply.d.ts +28 -0
  159. package/dist/src/provider-presets.d.ts +76 -0
  160. package/dist/src/reply-local-links.d.ts +47 -0
  161. package/dist/src/reply-originator.d.ts +20 -0
  162. package/dist/src/resume-runtime-infer.d.ts +18 -0
  163. package/dist/src/rules-file.d.ts +53 -0
  164. package/dist/src/scoped-secrets.d.ts +33 -0
  165. package/dist/src/secret-shell-guidance.d.ts +4 -0
  166. package/dist/src/session-status-class.d.ts +48 -0
  167. package/dist/src/shared/opencode-borrowed-launch-health.d.ts +29 -0
  168. package/dist/src/shared/provider-collection.d.ts +9 -0
  169. package/dist/src/shared/provider-initialization.d.ts +7 -0
  170. package/dist/src/shared/reserved-env.d.ts +3 -0
  171. package/dist/src/shared/scoped-secret-contract.d.ts +1 -0
  172. package/dist/src/shared/scoped-secret-env.d.ts +3 -0
  173. package/dist/src/sibling-agent-node.d.ts +23 -0
  174. package/dist/src/stale-socket.d.ts +118 -0
  175. package/dist/src/standalone-bin.d.ts +101 -0
  176. package/dist/src/standalone-build-stamp.d.ts +33 -0
  177. package/dist/src/start-resource-gate.d.ts +146 -0
  178. package/dist/src/stopped-receipt.d.ts +8 -0
  179. package/dist/src/subcommand-redirect.d.ts +26 -0
  180. package/dist/src/task-trace.d.ts +33 -0
  181. package/dist/src/tmux-attach.d.ts +11 -0
  182. package/dist/src/tmux-capability.d.ts +58 -0
  183. package/dist/src/tmux-exact-target.d.ts +36 -0
  184. package/dist/src/tmux-format.d.ts +20 -0
  185. package/dist/src/tmux-pane-prompt.d.ts +22 -0
  186. package/dist/src/tmux.d.ts +44 -0
  187. package/dist/src/token-cli.d.ts +13 -0
  188. package/dist/src/tool-allowlist.d.ts +28 -0
  189. package/dist/src/unsafe-package-path-reason.d.ts +31 -0
  190. package/dist/src/upgrade-channel.d.ts +31 -0
  191. package/dist/src/win-launcher.d.ts +20 -0
  192. package/dist/src/windows-codex-copresence.d.ts +60 -0
  193. package/package.json +15 -7
@@ -0,0 +1,4 @@
1
+ export declare function formatSecretAssignment(platform: string, name: string, value: string): string;
2
+ export declare function secretPersistenceHeading(platform: string): string;
3
+ export declare function secretShellAction(platform: string): "set" | "export";
4
+ export declare function formatSecretLoadCommand(platform: string, name: string, dotenvPath: string): string;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `anet status` 的会话状态分类。
3
+ *
4
+ * 🔴 为什么单独成文件:原先它是 statusCommand 里的一个闭包,没有任何测试碰得到它 ——
5
+ * 而它决定了运维看到的那三个数字。一个把「卡住」算成「在干活」的分类器,
6
+ * 和一个正确的分类器,在输出上长得一模一样(都是一个数)。
7
+ *
8
+ * 🔴 改了什么:`blocked` / `error` 原先被折进 `working`。
9
+ * 它们的含义是**需要人看一眼**,不是**正在推进**。
10
+ * 运维看到「5 working」会认为一切正常,而其中可能有几个卡了很久 ——
11
+ * #1548 已经证明 `blocked` 是一个**没有出口**的状态:
12
+ * 只有 report_completion 能把它拉回 idle,所以一个 agent 可以永远停在那里。
13
+ *
14
+ * `waiting_input` 保留在 working 里:它是一个**进行中的回合**在等人,
15
+ * 与 blocked/error 不同 —— 那是回合本身出了问题。
16
+ */
17
+ export type SessionClass = "idle" | "working" | "attention" | "offline";
18
+ export declare function classifySessionStatus(raw: unknown): SessionClass;
19
+ /**
20
+ * `anet status` 顶部那三/四个数字。
21
+ *
22
+ * 🔴 为什么它必须和上面的分类器用同一套判据(#1625):
23
+ * 原先 `cli.ts` 是 `statusRes.summary || sessions.reduce(…)`,而
24
+ * `/api/status` **总是**返回 summary ⇒ 右边那支从不执行,屏幕上的数字
25
+ * 来自**服务端**一份还停在 #1548 之前的分类(它把 `blocked`/`error`
26
+ * 折进 `working`)。于是一个 blocked 节点同时出现在 `working` 和
27
+ * `needs attention` 两格里,四个数加起来比总数多一个。
28
+ *
29
+ * 🔴 为什么本地算是安全的:`/api/status` 只加 `addNetworkScope`,没有任何
30
+ * 状态/别名过滤,而它的 summary 就是从**同一个 sessions 数组** reduce 出来的
31
+ * —— 两者范围逐字相同。(这一点对 MCP 的 `get_all_status` **不成立**:
32
+ * 那边 summary 走独立的 `GROUP BY status` 查询、无视 filter,所以别照搬。)
33
+ *
34
+ * 🔴 `attention` 必须显式初始化为 0。原来的累加器只有
35
+ * `{idle, working, offline, total}`,`acc["attention"]++` 会得到 **NaN**,
36
+ * 而 `summary.attention ?? attention.length` 里的 `??` **不接 NaN**,
37
+ * 屏幕会印 `NaN needs attention`。那一支从不执行,所以从没人见过。
38
+ */
39
+ export type SessionSummary = {
40
+ idle: number;
41
+ working: number;
42
+ attention: number;
43
+ offline: number;
44
+ total: number;
45
+ };
46
+ export declare function summarizeSessions(sessions: Array<{
47
+ status?: unknown;
48
+ }>): SessionSummary;
@@ -0,0 +1,29 @@
1
+ export declare const BORROWED_LAUNCH_HEALTH = "opencode-borrowed-v1-launch.json";
2
+ export declare function hasBorrowedV1Intent(dir: string, config: any): boolean;
3
+ /** Read-only preflight. Runtime admission still validates the independent Host,
4
+ * binary, original credentials, native directory/session and cooperative lease. */
5
+ export declare function readBorrowedLaunchConfig(configPath: string, cwd?: string): {
6
+ selection: any;
7
+ alias: any;
8
+ model: any;
9
+ stamp: number[];
10
+ };
11
+ export declare function publishBorrowedLaunchHealth(configPath: string, nonce: string): () => void;
12
+ export declare function inspectBorrowedLaunchHealth(configPath: string, launchedAt: number, nonce?: string): {
13
+ ok: true;
14
+ bridgePid: number;
15
+ reason?: undefined;
16
+ } | {
17
+ ok: false;
18
+ reason: string;
19
+ bridgePid?: undefined;
20
+ };
21
+ export declare function waitForBorrowedLaunchHealth(configPath: string, launchedAt: number, deadline: number, nonce?: string): Promise<{
22
+ ok: true;
23
+ bridgePid: number;
24
+ reason?: undefined;
25
+ } | {
26
+ ok: false;
27
+ reason: string;
28
+ bridgePid?: undefined;
29
+ }>;
@@ -0,0 +1,9 @@
1
+ export type ProviderCollection = {
2
+ node_id: string;
3
+ alias: string;
4
+ node_revision: string;
5
+ provider_id: string;
6
+ auth_id: string;
7
+ label: string;
8
+ };
9
+ export declare function validProviderCollection(v: any): v is ProviderCollection;
@@ -0,0 +1,7 @@
1
+ export type ProviderInitialization = {
2
+ revision: number;
3
+ provider_id: string;
4
+ auth_id: string;
5
+ model: string;
6
+ };
7
+ export declare function validProviderInitialization(value: any): value is ProviderInitialization;
@@ -0,0 +1,3 @@
1
+ export declare const RESERVED_ENV_KEYS_EXACT: Set<string>;
2
+ export declare const RESERVED_ENV_PREFIXES: ReadonlyArray<string>;
3
+ export declare function isReservedEnvKey(k: string): boolean;
@@ -0,0 +1 @@
1
+ export declare const validScopedSecretKey: (key: unknown) => key is string;
@@ -0,0 +1,3 @@
1
+ export declare function scopedSecretJson(path: string): any;
2
+ export declare function readIndependentNodeEnv(nodeDir: string): Record<string, string>;
3
+ export declare function readScopedNodeEnv(nodeDir: string): Record<string, string>;
@@ -0,0 +1,23 @@
1
+ export interface SiblingAgentNode {
2
+ /** 直接可 `node <entrypoint>` 的文件。 */
3
+ entrypoint: string;
4
+ packageDir: string;
5
+ version: string | null;
6
+ }
7
+ export interface SiblingFs {
8
+ exists(path: string): boolean;
9
+ readJson(path: string): unknown;
10
+ /**
11
+ * #1832 —— npm -g / --prefix 布局下 process.argv[1] 是 `<prefix>/bin/anet` 符号链接,真实文件在
12
+ * `<prefix>/lib/node_modules/@sleep2agi/agent-network/…`;不解析就从 `<prefix>/bin` 往上找不到
13
+ * node_modules,旁边的 agent-node 永远命不中。可选:不提供或抛错时按传入路径原样找。
14
+ */
15
+ realpath?(path: string): string;
16
+ }
17
+ /** 入口路径先走 realpath(符号链接 → 真实文件);失败(不存在 / 无权限)退回原路径。 */
18
+ export declare function resolveCliEntry(cliEntry: string, fs: SiblingFs): string;
19
+ /** 从 anet 入口文件路径往上,返回最近的 `…/node_modules` 目录;找不到返回 null。 */
20
+ export declare function nearestNodeModules(cliEntry: string): string | null;
21
+ /** package.json 的 bin 可以是字符串或 { name: path };只认名为 agent-node 的那条。 */
22
+ export declare function binEntryFromPackageJson(pkg: unknown): string | null;
23
+ export declare function siblingAgentNodeEntrypoint(cliEntry: string, fs: SiblingFs): SiblingAgentNode | null;
@@ -0,0 +1,118 @@
1
+ export interface StaleSocketProbes {
2
+ /** 读 /proc/net/unix 全文;读不到就 throw(调用方按 fail-closed 处理)。 */
3
+ procNetUnix(): string;
4
+ /** 路径不存在返回 null。 */
5
+ lstat(path: string): {
6
+ dev: number;
7
+ ino: number;
8
+ uid: number;
9
+ isSocket: boolean;
10
+ } | null;
11
+ unlink(path: string): void;
12
+ /** 当前进程 uid —— 只回收自己拥有的 socket。 */
13
+ currentUid(): number;
14
+ }
15
+ export interface ReapScope {
16
+ /**
17
+ * 只允许回收这个目录**之下**的路径。
18
+ * 🔴 这一格防的不是文件系统竞态,是**被污染的 identity**:socket 路径来自
19
+ * profile,如果 profile 被写坏成 `/run/systemd/private` 之类,前面所有
20
+ * "无监听者"检查都会照常通过,然后 unlink 掉一个不属于这个节点的东西。
21
+ * 删除不可逆,所以范围校验必须在**所有**其它检查之前。
22
+ */
23
+ allowedRoot: string;
24
+ }
25
+ export type ReapOutcome =
26
+ /** 路径已经不在了 —— 正常的成功拆卸,无事可做。 */
27
+ {
28
+ kind: "absent";
29
+ }
30
+ /** 确认无人引用,已删除。 */
31
+ | {
32
+ kind: "removed";
33
+ }
34
+ /** /proc/net/unix 里仍能找到这个路径 ⇒ 有人在用,**不删**,调用方应判红。 */
35
+ | {
36
+ kind: "in-use";
37
+ }
38
+ /** /proc/net/unix 读不到 ⇒ fail-closed,不删。 */
39
+ | {
40
+ kind: "unreadable";
41
+ detail: string;
42
+ }
43
+ /** 检查与删除之间文件身份变了(dev/ino/uid),或已不是 socket ⇒ 不删。 */
44
+ | {
45
+ kind: "changed";
46
+ }
47
+ /** 路径不在该节点自己的 runtime 目录之下 ⇒ 一律不删。 */
48
+ | {
49
+ kind: "out-of-scope";
50
+ detail: string;
51
+ };
52
+ /**
53
+ * `/proc/net/unix` 的每一行以路径结尾(没有绑定路径的行就没有这一列)。
54
+ * 这里只问「这个路径出现过没有」,不解释 flags/type/state。
55
+ */
56
+ export declare function unixSocketPathInUse(procNetUnix: string, path: string): boolean;
57
+ /**
58
+ * 属主进程**已被证明消失之后**,回收一个陈旧的 socket 路径名。
59
+ * 任何一种不确定都不删 —— 删文件不可逆,而留下一个 socket 只是让 stop 判红,
60
+ * 那正是本函数之前的行为。
61
+ */
62
+ export declare function reapStaleSocket(path: string, probes: StaleSocketProbes, scope: ReapScope): ReapOutcome;
63
+ /**
64
+ * 从「本次 stop 看到的残留路径」里挑出**允许回收**的那些。
65
+ *
66
+ * 🔴 判据是「与重新算出来的规范路径**完全相等**」,不是前缀、不是包含。
67
+ * profile 里存的 socket 路径是**被写坏就会跟着坏**的数据;
68
+ * grokCopresenceSocketPaths 是纯函数,同样的 nodeId + home 永远算出同一个值。
69
+ * 所以这里不问「这条路径看起来对不对」,只问「它是不是我自己算出来的那两个之一」。
70
+ * ——一个被污染的 profile 因此一条都带不进来。
71
+ */
72
+ export declare function planReapableSockets(canonical: {
73
+ leaderSocket: string;
74
+ attachSocket: string;
75
+ }, residualPaths: readonly (string | undefined)[]): string[];
76
+ export interface CanonicalSocketProfile {
77
+ node_id?: string;
78
+ grokLeaderSocket?: string;
79
+ grokAttachSocket?: string;
80
+ }
81
+ export type CanonicalSocketsOutcome = {
82
+ kind: "ok";
83
+ leaderSocket: string;
84
+ attachSocket: string;
85
+ }
86
+ /** profile 里没有 node_id —— 算不出来,不动手。 */
87
+ | {
88
+ kind: "no-node-id";
89
+ }
90
+ /** 重新算出来的与 profile 存的不一致 —— profile 被写坏、HOME 变了、或**调用方喂错了 id**。 */
91
+ | {
92
+ kind: "mismatch";
93
+ recomputedLeader: string;
94
+ storedLeader: string;
95
+ }
96
+ /** 路径算不出来(grokCopresenceSocketPaths 抛错)—— 不动手,但也不该把 stop 整个弄失败。 */
97
+ | {
98
+ kind: "uncomputable";
99
+ detail: string;
100
+ };
101
+ /**
102
+ * 从 profile 推出规范 socket 路径,并**与 profile 里存的那份交叉校验**。
103
+ *
104
+ * 🔴 这个交叉校验是一次真实缺陷催生的,不是补全性写的:
105
+ * 我第一版在 cli.ts 里写的是 `grokCopresenceSocketPaths(resolved.id)`,而
106
+ * `resolveNodeRef` 返回的 `id` 是**目录名(别名)**,socket 路径却是
107
+ * `anet node create` 用 **node_id** 算的。两者哈希不同 ⇒ 算出的路径永远对不上 ⇒
108
+ * 可回收集合恒为空 ⇒ **一条都回收不了,而且完全静默**(循环体一次都不进)。
109
+ * 12 轮验收里 4 次红、0 次回收,红话与修复前逐字相同 —— 从外面看,
110
+ * 「守卫拒绝了一切」和「这个修复不存在」是同一个样子。
111
+ *
112
+ * 所以判据不能只是「算一个路径出来」,必须是「算出来的和存着的对得上」。
113
+ * 对不上就说出来,别静默跳过。
114
+ */
115
+ export declare function canonicalSocketsForProfile(profile: CanonicalSocketProfile, compute: (nodeId: string) => {
116
+ leaderSocket: string;
117
+ attachSocket: string;
118
+ }): CanonicalSocketsOutcome;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Pure helpers for the standalone `anet` executable (`bun build --compile`).
3
+ *
4
+ * npm/node keeps today's behavior: these functions are identity transforms
5
+ * when `stamp.standalone` is false. The compiled binary sets the stamp at
6
+ * build time (`scripts/build-anet-bin.mjs`) and routes Hub / agent-node
7
+ * through internal argv (`__hub` / `__node`) because `process.execPath` is
8
+ * the `anet` binary itself, not bun or node.
9
+ */
10
+ import { STANDALONE_BUILD_STAMP, type StandaloneBuildStamp, type StandalonePackageVersions } from "./standalone-build-stamp";
11
+ export type { StandaloneBuildStamp, StandalonePackageVersions };
12
+ export { STANDALONE_BUILD_STAMP };
13
+ /** Internal argv. Not user-facing commands; the unified entry strips them. */
14
+ export declare const STANDALONE_HUB_ARG = "__hub";
15
+ export declare const STANDALONE_NODE_ARG = "__node";
16
+ export declare const STANDALONE_PRINT_CONFIG_TOKEN_ARG = "__print-config-token";
17
+ export type StandaloneDispatchKind = "cli" | "hub" | "node" | "print-config-token";
18
+ export interface StandaloneDispatch {
19
+ kind: StandaloneDispatchKind;
20
+ /** Args after the internal selector. CLI kind keeps the full user argv. */
21
+ argv: string[];
22
+ }
23
+ export interface DetectedPackageLike {
24
+ name: string;
25
+ displayName: string;
26
+ version: string | null;
27
+ state: "ok" | "unknown" | "not-installed";
28
+ source?: string;
29
+ }
30
+ /**
31
+ * True when `arg` is the script slot bun/node inserts at argv[1]
32
+ * (`bun bin/anet-bin.ts`, or a compiled binary's `/$bunfs/...` path).
33
+ * A user argument that merely ends in `.ts` is not a script slot.
34
+ */
35
+ export declare function isBundlerScriptSlot(arg: string): boolean;
36
+ /** User args, whether argv is Node-shaped (script at [1]) or a raw executable. */
37
+ export declare function standaloneUserArgs(argv: readonly string[]): string[];
38
+ export declare function dispatchStandalone(userArgs: readonly string[]): StandaloneDispatch;
39
+ /**
40
+ * `cli.ts`, `commhub.ts`, and `agent-node`'s CLI all read `process.argv.slice(2)`.
41
+ * Force that shape so the same entries work under bun, node, and `bun build --compile`
42
+ * (compiled argv may or may not keep a virtual script path at [1]).
43
+ */
44
+ export declare function nodeStyleArgv(execPath: string, userArgs: readonly string[]): string[];
45
+ export declare function isStandaloneBuild(stamp: StandaloneBuildStamp): boolean;
46
+ export declare function anetVersionFromStamp(stamp: StandaloneBuildStamp): string | null;
47
+ export declare function standaloneBundleVersion(stamp: StandaloneBuildStamp): string | null;
48
+ /** Bytes of the `anet --version` header. No bundle line unless the stamp has one. */
49
+ export declare function formatAnetVersionBanner(anetVersion: string, bundle: string | null): string;
50
+ export declare function standaloneNodeServerJs(stamp: StandaloneBuildStamp): string | null;
51
+ export declare function applyStandaloneDetectedVersions<T extends {
52
+ anet: {
53
+ version: string;
54
+ };
55
+ agentNode: DetectedPackageLike;
56
+ commhubServer: DetectedPackageLike;
57
+ bun?: DetectedPackageLike;
58
+ }>(versions: T, stamp: StandaloneBuildStamp): T;
59
+ export interface CliReinvokeInput {
60
+ standalone: boolean;
61
+ execArgv: readonly string[];
62
+ /** `process.argv[1]` for npm/node. Ignored when `standalone` is true. */
63
+ scriptPath: string;
64
+ cliArgs: readonly string[];
65
+ /** Match call sites that already forward `process.execArgv` (tsx loaders). */
66
+ includeExecArgv: boolean;
67
+ }
68
+ /**
69
+ * Argv after `process.execPath` when re-invoking this CLI.
70
+ * npm/node: `[script, ...cliArgs]` or `[...execArgv, script, ...cliArgs]`.
71
+ * standalone: just `cliArgs` — the binary is already `anet`.
72
+ */
73
+ export declare function cliReinvokeArgs(input: CliReinvokeInput): string[];
74
+ export declare function cliReinvokeShell(input: CliReinvokeInput & {
75
+ execPath: string;
76
+ quote: (value: string) => string;
77
+ }): string;
78
+ export interface StandaloneHubLaunchInput {
79
+ /** `--version` / `--hub-version` value, or null when the user did not pass one. */
80
+ explicitVersion: string | null;
81
+ port: string;
82
+ host: string;
83
+ devOpen: boolean;
84
+ }
85
+ export type StandaloneHubLaunch = {
86
+ ok: true;
87
+ version: string;
88
+ origin: string;
89
+ warnings: string[];
90
+ args: string[];
91
+ } | {
92
+ ok: false;
93
+ message: string;
94
+ };
95
+ /**
96
+ * Argv for the embedded Hub. The standalone binary cannot `bunx` a registry
97
+ * package; a requested version other than the embedded one is refused.
98
+ */
99
+ export declare function standaloneHubLaunch(stamp: StandaloneBuildStamp, input: StandaloneHubLaunchInput): StandaloneHubLaunch;
100
+ /** Argv after `process.execPath` when launching the embedded agent-node. */
101
+ export declare function standaloneNodeArgs(agentArgs: readonly string[]): string[];
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Build stamp for the standalone `anet` executable.
3
+ *
4
+ * The committed value is inactive. `scripts/build-anet-bin.mjs` rewrites this
5
+ * file only for the duration of `bun build --compile`, then restores it.
6
+ * npm/node runs of `bin/cli.ts` must keep seeing `standalone: false`.
7
+ *
8
+ * Versions are read from each package's package.json at binary-build time.
9
+ * Do not hard-code release versions here — those constants belong to the
10
+ * packages (and to the in-flight release that owns them).
11
+ */
12
+ export interface StandalonePackageVersions {
13
+ /** `@sleep2agi/agent-network` package.json version. */
14
+ anet: string;
15
+ /** `@sleep2agi/agent-node` package.json version. */
16
+ agentNode: string;
17
+ /** `@sleep2agi/commhub-server` package.json version. */
18
+ commhubServer: string;
19
+ /** Release label of this executable (`cli-bin-v<bundle>`). */
20
+ bundle: string;
21
+ }
22
+ export interface StandaloneBuildStamp {
23
+ standalone: boolean;
24
+ versions: StandalonePackageVersions | null;
25
+ /**
26
+ * Prebundled `.anet/node-server.js` payload (target node, version marker
27
+ * already stamped). Null outside the standalone binary. The compiled
28
+ * executable has no real package layout, so the CLI cannot find
29
+ * `node-server.js` via `import.meta.url`.
30
+ */
31
+ nodeServerJs: string | null;
32
+ }
33
+ export declare const STANDALONE_BUILD_STAMP: StandaloneBuildStamp;
@@ -0,0 +1,146 @@
1
+ export declare const START_GATE_DEFAULT_MIN_MEM_MB = 4096;
2
+ export declare const START_GATE_DEFAULT_MEM_FRACTION = 0.15;
3
+ export declare const START_GATE_DEFAULT_MAX_LOAD_PER_CPU = 4;
4
+ export declare const START_GATE_DEFAULT_MAX_WAIT_SEC = 600;
5
+ export declare const START_GATE_DEFAULT_MAX_CONCURRENT = 2;
6
+ export declare const START_GATE_SINGLE_LANE_CONCURRENT = 1;
7
+ export declare const START_GATE_RECHECK_MS = 15000;
8
+ /** Jitter added to each re-check while still inside the max wait: uniform [0, RECHECK_JITTER_MS). */
9
+ export declare const START_GATE_RECHECK_JITTER_MS = 5000;
10
+ export declare const START_GATE_WAITING_MEMORY_STATUS = "\u7B49\u5F85\u5185\u5B58";
11
+ export declare const START_GATE_WAITING_LOAD_STATUS = "\u7B49\u5F85\u8D1F\u8F7D";
12
+ export declare const START_GATE_WAITING_BOTH_STATUS = "\u7B49\u5F85\u5185\u5B58\u548C\u8D1F\u8F7D";
13
+ export declare const START_GATE_WAITING_PROBE_STATUS = "\u7B49\u5F85\u8D44\u6E90\u63A2\u6D4B";
14
+ /** #686 compatibility alias for callers that used the original memory-only status. */
15
+ export declare const START_GATE_WAITING_STATUS = "\u7B49\u5F85\u5185\u5B58";
16
+ export declare const START_GATE_SINGLE_LANE_STATUS = "\u5DF2\u8D85\u65F6\uFF0C\u6309\u5355\u8DEF\u653E\u884C";
17
+ /** Logged when one waiter atomically replaces a stuck lease. The wait cap must not admit without this. */
18
+ export declare const START_GATE_TAKEOVER_STATUS = "\u63A5\u7BA1\u5361\u6B7B\u79DF\u7EA6";
19
+ /** Startup leases older than this are not live. ANET_START_LEASE_TTL_SEC overrides it. */
20
+ export declare const START_GATE_LEASE_TTL_MS: number;
21
+ /** A healthy holder renews well before the default lease expiry. */
22
+ export declare const START_GATE_LEASE_HEARTBEAT_MS = 30000;
23
+ /** An empty or unreadable lock younger than this is still being published, not dead. */
24
+ export declare const START_GATE_LOCK_STALE_MS = 30000;
25
+ /**
26
+ * A live matching lock is an orphan when the monotonic timestamp stored in
27
+ * the lock is older than this. Legacy locks with no stamp still use wall
28
+ * mtime, which a clock step can age out. The critical section only renames
29
+ * and writes a few files, so a live holder past this window is stuck.
30
+ */
31
+ export declare const START_GATE_LOCK_ORPHAN_MS = 60000;
32
+ export interface StartGateDeps {
33
+ env?: NodeJS.ProcessEnv;
34
+ platform?: string;
35
+ /** Returns file contents, or null when unreadable. */
36
+ readFile?: (path: string) => string | null;
37
+ cpuCount?: () => number;
38
+ sleep?: (ms: number) => Promise<void>;
39
+ now?: () => number;
40
+ random?: () => number;
41
+ log?: (msg: string) => void;
42
+ warn?: (msg: string) => void;
43
+ /** Hub/task text. Errors are swallowed so a report failure cannot block a start. */
44
+ report?: (text: string) => void;
45
+ /** Host lease directory. Tests must inject this; the default is ~/.anet/run/start-slots. */
46
+ slotsDir?: string;
47
+ /** Lease key. Alias is not unique across workspaces; pass the node id. */
48
+ nodeId?: string;
49
+ /** Pid written into the lease. Default: this process. */
50
+ holderPid?: number;
51
+ /** ESRCH = dead, EPERM = alive. Injected so tests never signal a real pid. */
52
+ isPidAlive?: (pid: number) => boolean;
53
+ /** /proc/<pid>/stat field 22. null means unknown — do not treat that as a mismatch. */
54
+ readProcessStartTicks?: (pid: number) => string | null;
55
+ /** Override the 15s re-check. With jitterMs 0 the single-lane retry uses this as-is. */
56
+ recheckMs?: number;
57
+ /** Override the 0–5s jitter span. 0 keeps the sleep exactly recheckMs. */
58
+ jitterMs?: number;
59
+ /** Lease lifetime. Default 10 minutes, or ANET_START_LEASE_TTL_SEC. */
60
+ leaseTtlMs?: number;
61
+ /** @internal deterministic short-TTL seam. Defaults to min(30s, TTL/3). */
62
+ leaseHeartbeatMs?: number;
63
+ /** Empty/unreadable locks younger than this are held, not dead. */
64
+ lockStaleMs?: number;
65
+ /** A live matching lock older than this is an orphan. Default 60s. */
66
+ lockOrphanMs?: number;
67
+ /**
68
+ * Monotonic milliseconds shared by every process on this host.
69
+ * Default reads /proc/uptime. null means unknown: a stamped lock is kept.
70
+ */
71
+ monotonicNow?: () => number | null;
72
+ }
73
+ export type StartGateOutcome = "disabled" | "unsupported" | "ok" | "waited" | "single-lane";
74
+ export interface StartGateResult {
75
+ outcome: StartGateOutcome;
76
+ waitedMs: number;
77
+ checks: number;
78
+ /** Always callable and idempotent. Drops the lease only if this call created it. */
79
+ release: () => void;
80
+ }
81
+ export interface HostSample {
82
+ /** Effective free MiB: min(MemAvailable, cgroup free) when a real cgroup limit exists. */
83
+ memAvailableMb: number;
84
+ /** /proc MemAvailable, before the cgroup min. */
85
+ procAvailableMb: number;
86
+ /** Cgroup free MiB, or null when there is no real limit. */
87
+ cgroupFreeMb: number | null;
88
+ /** Cgroup limit MiB, or null when there is no real limit. The floor uses this, not the host alone. */
89
+ cgroupLimitMb: number | null;
90
+ /** 0 when MemTotal could not be read (the floor then falls back to 4096). */
91
+ memTotalMb: number;
92
+ load1: number;
93
+ cpuCount: number;
94
+ }
95
+ export interface StartGateStatusSnapshot {
96
+ status: string;
97
+ task?: string;
98
+ }
99
+ /** True only for blocked text owned by this gate, including single-lane wait. */
100
+ export declare function isStartGateBlockedStatus(task: string | undefined): boolean;
101
+ /**
102
+ * Once admission returns, restore the pre-gate status only if the live status
103
+ * is still ours. A concurrent task/status update must win over stale restore.
104
+ */
105
+ export declare function startGateStatusToRestore(live: StartGateStatusSnapshot, previous: StartGateStatusSnapshot): StartGateStatusSnapshot | null;
106
+ /** MemAvailable in MiB from /proc/meminfo text, or null. */
107
+ export declare function parseMemAvailableMb(meminfo: string): number | null;
108
+ /** MemTotal in MiB from /proc/meminfo text, or null. */
109
+ export declare function parseMemTotalMb(meminfo: string): number | null;
110
+ /** 1-minute load average from /proc/loadavg text, or null. */
111
+ export declare function parseLoad1(loadavg: string): number | null;
112
+ /**
113
+ * Field 22 of /proc/<pid>/stat (starttime, clock ticks since boot).
114
+ * The comm field is in parentheses and may contain spaces; everything after the
115
+ * last ")" is field 3 onward, so field 22 is index 19 of that tail.
116
+ */
117
+ export declare function parseProcStartTicks(statText: string): string | null;
118
+ /**
119
+ * Default free-memory floor. A fixed 4 GiB is too high for a small machine
120
+ * or a small container, so the floor is min(4 GiB, 15% of the effective total).
121
+ * The effective total is min(MemTotal, cgroup limit) when a real cgroup limit
122
+ * exists — a container must not be judged against the host's MemTotal.
123
+ * Missing/invalid numbers fall back to 4 GiB. ANET_START_MIN_MEM_MB replaces
124
+ * this when set.
125
+ */
126
+ export declare function defaultStartMinMemMb(memTotalMb: number, cgroupLimitMb?: number | null): number;
127
+ /** Reasons the host is too busy to start, empty when it is fine. */
128
+ export declare function startGateReasons(s: HostSample, minMemMb: number, maxLoadPerCpu: number): string[];
129
+ /** User-facing blocked status. Keep this structured instead of parsing the diagnostic reasons. */
130
+ export declare function startGateWaitingStatus(s: HostSample | null, minMemMb: number, maxLoadPerCpu: number): string | null;
131
+ /**
132
+ * Free MiB inside a real cgroup limit, or null when the limit is missing/unlimited.
133
+ * `memory.current` counts page cache; inactive_file (v1: total_inactive_file) is subtracted.
134
+ * statText null keeps the old arithmetic so existing fixtures stay valid.
135
+ */
136
+ export declare function cgroupFreeMb(maxText: string, currentText: string, memTotalMb: number, statText?: string | null, v1?: boolean): number | null;
137
+ /** Real cgroup limit in MiB, or null when the limit is missing/unlimited. */
138
+ export declare function cgroupLimitMb(maxText: string, memTotalMb: number): number | null;
139
+ /**
140
+ * Block until this host may start one heavy process.
141
+ * Returns a release() the caller must invoke once that process is up or has failed.
142
+ * Never throws (except when the injected sleep rejects — tests use that to stop a wait).
143
+ */
144
+ export declare function waitForStartResources(label: string, deps?: StartGateDeps): Promise<StartGateResult>;
145
+ /** Run `fn` while holding one start lease. Release runs on success and on failure. */
146
+ export declare function withHeavyStartAdmission<T>(label: string, deps: StartGateDeps, fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,8 @@
1
+ /** Capture BEFORE asynchronous manual start. Successful start supersedes only
2
+ * this exact receipt, without unlinking it: check-then-unlink would race another
3
+ * process writing a new stop. A late certificate can never supersede that new
4
+ * receipt, even if its JSON is identical (inode/ctime are part of identity). */
5
+ export declare function stoppedReceiptAtStart(nodeDir: string, nodeId: unknown): () => void;
6
+ /** Missing stop => runnable. Unreadable/unsafe/legacy stop => stay stopped.
7
+ * Keep the fleet boot probe's wire format in sync (Docker parity test). */
8
+ export declare function isHubStopped(nodeDir: string, nodeId: unknown): boolean;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `anet daemon <sub>` 认不出子命令时,原先只走 `suggestSimilar`,而它的候选集
3
+ * 是 `["init","start","restart","up","list"]` —— **全是会改变状态的命令**。
4
+ *
5
+ * 🔴 实测(用仓里那个 `suggestSimilar` 本身跑的,不是推的):
6
+ *
7
+ * anet daemon rm → 建议 "up" 想删,被指去「创建 + 启动」
8
+ * anet daemon state → 建议 "start" 想看状态,被指去「启动」
9
+ * anet daemon stat → 建议 "start" 同上
10
+ * anet daemon stop → 建议 null (levenshtein("stop","start") = 3)
11
+ *
12
+ * 一个「你是不是想 X」的提示,把只读/销毁意图导向一个会动世界的命令,
13
+ * 比不给提示更贵。
14
+ *
15
+ * 而这些动作**本来就有**:daemon 就是一个 role=host_supervisor 的 agent-node,
16
+ * `anet daemon restart` 内部调的正是 `anet node stop` 用的那个 stopCommand()。
17
+ * 缺的从来不是功能,是**可发现性**。
18
+ */
19
+ /** 这些是 `anet daemon` 自己的子命令 —— 它们**会改变状态**,所以任何
20
+ * 只读/销毁意图都不该被导向它们。测试用它做对照。 */
21
+ export declare const DAEMON_STATE_CHANGING: readonly ["init", "start", "restart", "up"];
22
+ export declare const PROJECT_STATE_CHANGING: readonly ["up", "restart"];
23
+ export declare const NODE_STATE_CHANGING: readonly ["create", "start", "restart", "resume", "rename", "loop"];
24
+ export declare const daemonSubcommandRedirect: (sub: unknown, name?: unknown) => string[] | null;
25
+ export declare const projectSubcommandRedirect: (sub: unknown, name?: unknown) => string[] | null;
26
+ export declare const nodeSubcommandRedirect: (sub: unknown, name?: unknown) => string[] | null;
@@ -0,0 +1,33 @@
1
+ export type TaskTraceTransport = "mcp_http" | "sdk_mcp_proxy" | "channel_mcp_proxy";
2
+ export type TaskTraceStatus = "sending" | "delivered" | "failed" | "acked" | "started" | "replied" | "expired";
3
+ export interface TaskTraceEvent {
4
+ event: string;
5
+ from_alias: string;
6
+ to_alias: string;
7
+ task_id: string | null;
8
+ parent_task_id: string | null;
9
+ network_id: string | null;
10
+ transport: TaskTraceTransport;
11
+ status: TaskTraceStatus;
12
+ duration_ms: number;
13
+ lifecycle_tracking: "tracked" | "not_tracked";
14
+ error_code?: string;
15
+ error_message?: string;
16
+ }
17
+ export declare function safeTaskTraceError(value: unknown): string;
18
+ export declare function renderTaskTrace(event: TaskTraceEvent, json?: boolean): string;
19
+ export declare function taskTraceEvent(input: Omit<TaskTraceEvent, "event">): TaskTraceEvent;
20
+ export interface SendTaskTraceInput {
21
+ fromAlias: string;
22
+ toAlias: string;
23
+ parentTaskId: string | null;
24
+ networkId: string | null;
25
+ transport: TaskTraceTransport;
26
+ lifecycleTracking: "tracked" | "not_tracked";
27
+ }
28
+ export interface SendTaskTraceDependencies {
29
+ send: () => Promise<any>;
30
+ log: (line: string) => void;
31
+ now?: () => number;
32
+ }
33
+ export declare function sendTaskWithTrace(input: SendTaskTraceInput, dependencies: SendTaskTraceDependencies): Promise<any>;
@@ -0,0 +1,11 @@
1
+ export type TmuxSession = {
2
+ id: string;
3
+ name: string;
4
+ };
5
+ /** argv for `execTmux`: `-u list-sessions -F '#{session_id}|ANETSEP|#{session_name}'` (#533). */
6
+ export declare const SESSION_LIST_ARGS: readonly string[];
7
+ /** Parse SESSION_LIST_ARGS output (legacy `id\tname` rows still accepted). */
8
+ export declare function parseTmuxSessions(output: string): TmuxSession[];
9
+ /** Resolve by exact decoded session name, then attach by tmux's opaque ID.
10
+ * This avoids tmux target prefix matching and works for Unicode names. */
11
+ export declare function findExactTmuxSession(output: string, expectedName: string): TmuxSession | null;