@sleep2agi/agent-network 2.3.0-preview.9 → 2.3.0-preview.90

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 (113) 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/bin/goal-wake-log-render.d.ts +31 -0
  6. package/dist/src/active-network-task.d.ts +28 -0
  7. package/dist/src/batch-workdir.d.ts +9 -0
  8. package/dist/src/bootstrap-password-db.d.ts +13 -0
  9. package/dist/src/channel-attachments.d.ts +29 -0
  10. package/dist/src/channel-meta.d.ts +10 -0
  11. package/dist/src/channel-task-trace.d.ts +14 -0
  12. package/dist/src/claude-vendor-env.d.ts +28 -0
  13. package/dist/src/cli-args.d.ts +8 -0
  14. package/dist/src/cli-version-display.d.ts +16 -0
  15. package/dist/src/client-task-trace.d.ts +9 -0
  16. package/dist/src/client.js +1 -1
  17. package/dist/src/codex-copresence-preflight.d.ts +65 -0
  18. package/dist/src/codex-copresence-profile.d.ts +125 -0
  19. package/dist/src/codex-copresence-recovery.d.ts +43 -0
  20. package/dist/src/codex-copresence-thread.d.ts +13 -0
  21. package/dist/src/codex-lifecycle-account.d.ts +104 -0
  22. package/dist/src/codex-lifecycle-canary.d.ts +20 -0
  23. package/dist/src/codex-lifecycle-facts.d.ts +53 -0
  24. package/dist/src/codex-lifecycle-fork.d.ts +53 -0
  25. package/dist/src/codex-lifecycle-preflight.d.ts +77 -0
  26. package/dist/src/codex-lifecycle-receipt.d.ts +44 -0
  27. package/dist/src/codex-lifecycle-restart.d.ts +86 -0
  28. package/dist/src/codex-model-default.d.ts +6 -0
  29. package/dist/src/codex-tui-client-health.d.ts +17 -0
  30. package/dist/src/commhub-response.d.ts +1 -0
  31. package/dist/src/controlled-upload.d.ts +83 -0
  32. package/dist/src/copresence-deps.d.ts +22 -0
  33. package/dist/src/copresence-identity.d.ts +339 -0
  34. package/dist/src/copresence-startup-diagnosis.d.ts +17 -0
  35. package/dist/src/daemon-capability-display.d.ts +110 -0
  36. package/dist/src/daemon-capability-display.js +21 -0
  37. package/dist/src/daemon-runtime-path-preflight.d.ts +22 -0
  38. package/dist/src/daemon-runtime-staleness.d.ts +13 -0
  39. package/dist/src/dashboard-managed-process.d.ts +35 -0
  40. package/dist/src/display-width.d.ts +27 -0
  41. package/dist/src/doctor-node-count.d.ts +28 -0
  42. package/dist/src/environ-alias.d.ts +14 -0
  43. package/dist/src/grok-attach-client.d.ts +129 -0
  44. package/dist/src/grok-build-drift.d.ts +15 -0
  45. package/dist/src/grok-copresence-disclosure.d.ts +11 -0
  46. package/dist/src/grok-copresence-orchestration.d.ts +75 -0
  47. package/dist/src/grok-copresence-profile.d.ts +65 -0
  48. package/dist/src/host-telemetry.d.ts +14 -0
  49. package/dist/src/hub-time-display.d.ts +20 -0
  50. package/dist/src/hub-version-skew.d.ts +19 -0
  51. package/dist/src/im/correlation-store.d.ts +34 -0
  52. package/dist/src/im/feishu/adapter.d.ts +80 -0
  53. package/dist/src/im/feishu/bridge.d.ts +85 -14
  54. package/dist/src/im/feishu/config.d.ts +31 -0
  55. package/dist/src/im/feishu/hub-upload.d.ts +88 -0
  56. package/dist/src/im/feishu/outbound-marker.d.ts +24 -19
  57. package/dist/src/im/feishu/outbound-paths.d.ts +50 -0
  58. package/dist/src/im/feishu/outbound-route.d.ts +62 -0
  59. package/dist/src/im/feishu/worker-lifecycle.d.ts +13 -0
  60. package/dist/src/im/feishu/worker.js +187 -144
  61. package/dist/src/im/types.d.ts +38 -1
  62. package/dist/src/local-process-state.d.ts +12 -0
  63. package/dist/src/locale-diagnostic.d.ts +12 -0
  64. package/dist/src/ls-columns.d.ts +15 -0
  65. package/dist/src/mock-llm.d.ts +12 -0
  66. package/dist/src/node-activity-log.d.ts +4 -0
  67. package/dist/src/node-not-found.d.ts +1 -0
  68. package/dist/src/node-running-guard.d.ts +9 -0
  69. package/dist/src/node-server-payload.d.ts +66 -0
  70. package/dist/src/node-server.js +7 -1
  71. package/dist/src/normalize-runtime.d.ts +29 -2
  72. package/dist/src/offline-age.d.ts +29 -0
  73. package/dist/src/one-line-cell.d.ts +20 -0
  74. package/dist/src/opencode-agent-node-pair.d.ts +25 -0
  75. package/dist/src/opencode-auth-login.d.ts +43 -0
  76. package/dist/src/opencode-launch-env.d.ts +13 -0
  77. package/dist/src/opencode-owner-mode.d.ts +6 -0
  78. package/dist/src/opencode-package-binary.d.ts +26 -0
  79. package/dist/src/opencode-pin.d.ts +44 -0
  80. package/dist/src/opencode-preset.d.ts +73 -0
  81. package/dist/src/opencode-runtime-binding.d.ts +30 -0
  82. package/dist/src/opencode-safe-root.d.ts +36 -0
  83. package/dist/src/opencode-smoke-env.d.ts +1 -0
  84. package/dist/src/outbound-attachments.d.ts +57 -0
  85. package/dist/src/outbound-tool-names.d.ts +1 -0
  86. package/dist/src/owned-roots.d.ts +58 -0
  87. package/dist/src/owner-env-file.d.ts +2 -0
  88. package/dist/src/package-mode-preflight.d.ts +41 -0
  89. package/dist/src/posix-codex-copresence.d.ts +8 -0
  90. package/dist/src/posix-modes.d.ts +36 -0
  91. package/dist/src/primary-network.d.ts +23 -0
  92. package/dist/src/private-state.d.ts +10 -0
  93. package/dist/src/process-telemetry.d.ts +12 -0
  94. package/dist/src/profile-serialize.d.ts +1 -0
  95. package/dist/src/project-key.d.ts +1 -0
  96. package/dist/src/reply-originator.d.ts +20 -0
  97. package/dist/src/resume-runtime-infer.d.ts +18 -0
  98. package/dist/src/secret-shell-guidance.d.ts +3 -0
  99. package/dist/src/session-status-class.d.ts +48 -0
  100. package/dist/src/sibling-agent-node.d.ts +23 -0
  101. package/dist/src/stale-socket.d.ts +118 -0
  102. package/dist/src/subcommand-redirect.d.ts +26 -0
  103. package/dist/src/task-trace.d.ts +33 -0
  104. package/dist/src/tmux-attach.d.ts +8 -0
  105. package/dist/src/tmux-capability.d.ts +58 -0
  106. package/dist/src/tmux-exact-target.d.ts +34 -0
  107. package/dist/src/tmux-pane-prompt.d.ts +22 -0
  108. package/dist/src/token-cli.d.ts +13 -0
  109. package/dist/src/tool-allowlist.d.ts +28 -0
  110. package/dist/src/unsafe-package-path-reason.d.ts +17 -0
  111. package/dist/src/win-launcher.d.ts +20 -0
  112. package/dist/src/windows-codex-copresence.d.ts +60 -0
  113. package/package.json +10 -5
@@ -0,0 +1,129 @@
1
+ import type { Duplex } from "node:stream";
2
+ export declare const GROK_ATTACH_PROTOCOL = "anet-grok-copresence-attach";
3
+ export declare const GROK_ATTACH_PROTOCOL_VERSION = 1;
4
+ export declare const GROK_ATTACH_DEFAULT_MAX_FRAME_BYTES: number;
5
+ export declare const GROK_ATTACH_DEFAULT_MAX_BUFFER_BYTES: number;
6
+ export declare const GROK_ATTACH_DEFAULT_HANDSHAKE_TIMEOUT_MS = 5000;
7
+ export declare const GROK_ATTACH_DEFAULT_CLOSE_TIMEOUT_MS = 1000;
8
+ export type GrokAttachJsonValue = null | boolean | number | string | GrokAttachJsonValue[] | {
9
+ [key: string]: GrokAttachJsonValue;
10
+ };
11
+ export interface GrokAttachHelloFrame {
12
+ type: "hello";
13
+ protocol: typeof GROK_ATTACH_PROTOCOL;
14
+ version: typeof GROK_ATTACH_PROTOCOL_VERSION;
15
+ alias: string;
16
+ sessionId: string;
17
+ [key: string]: unknown;
18
+ }
19
+ export interface GrokAttachOutputFrame {
20
+ type: "output";
21
+ data: string;
22
+ encoding: "base64";
23
+ }
24
+ export interface GrokAttachStatusFrame {
25
+ type: "status";
26
+ status: GrokAttachJsonValue;
27
+ }
28
+ export interface GrokAttachErrorFrame {
29
+ type: "error";
30
+ code: string;
31
+ message: string;
32
+ fatal: boolean;
33
+ }
34
+ export interface GrokAttachDetachFrame {
35
+ type: "detach";
36
+ }
37
+ export type GrokAttachServerFrame = GrokAttachHelloFrame | GrokAttachOutputFrame | GrokAttachStatusFrame | GrokAttachErrorFrame | GrokAttachDetachFrame;
38
+ export interface GrokAttachInputFrame {
39
+ type: "input";
40
+ data: string;
41
+ encoding: "base64";
42
+ }
43
+ export interface GrokAttachResizeFrame {
44
+ type: "resize";
45
+ cols: number;
46
+ rows: number;
47
+ }
48
+ /** Asks the node to switch models (issue #879); allowed on control connections. */
49
+ export interface GrokAttachSetModelFrame {
50
+ type: "set-model";
51
+ model: string;
52
+ }
53
+ export type GrokAttachClientFrame = GrokAttachInputFrame | GrokAttachResizeFrame | GrokAttachSetModelFrame | GrokAttachDetachFrame;
54
+ export interface GrokAttachInputSource {
55
+ on(event: "data", listener: (chunk: unknown) => void): unknown;
56
+ on(event: "end", listener: () => void): unknown;
57
+ off?(event: "data" | "end", listener: (...args: any[]) => void): unknown;
58
+ removeListener?(event: "data" | "end", listener: (...args: any[]) => void): unknown;
59
+ pause?(): unknown;
60
+ resume?(): unknown;
61
+ }
62
+ export interface GrokAttachOutputSink {
63
+ write(chunk: Uint8Array): boolean | void;
64
+ columns?: number;
65
+ rows?: number;
66
+ once?(event: "drain", listener: () => void): unknown;
67
+ }
68
+ export interface GrokAttachSignalSource {
69
+ on(event: "SIGWINCH", listener: () => void): unknown;
70
+ off?(event: "SIGWINCH", listener: () => void): unknown;
71
+ removeListener?(event: "SIGWINCH", listener: () => void): unknown;
72
+ }
73
+ export interface GrokAttachSocketStat {
74
+ uid: number;
75
+ isSocket(): boolean;
76
+ isSymbolicLink(): boolean;
77
+ }
78
+ export interface GrokAttachDependencies {
79
+ lstat?: (socketPath: string) => Promise<GrokAttachSocketStat>;
80
+ getuid?: () => number | undefined;
81
+ connect?: (socketPath: string) => Duplex;
82
+ }
83
+ export interface GrokAttachClientOptions {
84
+ socketPath: string;
85
+ input: GrokAttachInputSource;
86
+ output: GrokAttachOutputSink;
87
+ signalSource?: GrokAttachSignalSource;
88
+ terminalSize?: () => {
89
+ cols: number | undefined;
90
+ rows: number | undefined;
91
+ };
92
+ maxFrameBytes?: number;
93
+ maxBufferBytes?: number;
94
+ handshakeTimeoutMs?: number;
95
+ closeTimeoutMs?: number;
96
+ detachOnInputEnd?: boolean;
97
+ onHello?: (frame: GrokAttachHelloFrame) => void;
98
+ onStatus?: (frame: GrokAttachStatusFrame) => void;
99
+ onError?: (error: Error, frame?: GrokAttachErrorFrame) => void;
100
+ onDetach?: (frame: GrokAttachDetachFrame) => void;
101
+ dependencies?: GrokAttachDependencies;
102
+ }
103
+ export type GrokAttachCloseReason = "local-detach" | "input-end" | "remote-detach" | "socket-close" | "socket-error" | "protocol-error";
104
+ export interface GrokAttachCloseInfo {
105
+ reason: GrokAttachCloseReason;
106
+ error?: Error;
107
+ }
108
+ export interface GrokAttachSession {
109
+ readonly socketPath: string;
110
+ readonly closed: Promise<GrokAttachCloseInfo>;
111
+ detach(): void;
112
+ resize(cols?: number, rows?: number): void;
113
+ /**
114
+ * Ask the node to switch models (issue #879).
115
+ *
116
+ * The outcome does not come back from this call — it arrives as a `status`
117
+ * frame carrying `modelSwitch`, because the node may accept, refuse
118
+ * (busy / unchanged / invalid), or fail while re-spawning. Callers read it
119
+ * through `onStatus`.
120
+ */
121
+ setModel(model: string): void;
122
+ }
123
+ export declare class GrokAttachRemoteError extends Error {
124
+ readonly code: string;
125
+ readonly fatal: boolean;
126
+ constructor(frame: GrokAttachErrorFrame);
127
+ }
128
+ export declare function validateGrokAttachSocket(socketPath: string, dependencies?: GrokAttachDependencies): Promise<void>;
129
+ export declare function connectGrokAttach(options: GrokAttachClientOptions): Promise<GrokAttachSession>;
@@ -0,0 +1,15 @@
1
+ /** 从一段日志文本里取出**最后一次**出现的 grok 版本串。
2
+ * 🔴 取最后一次,不是第一次:日志按时间追加,最后一次才是这个进程最近一次
3
+ * 启动时用的那个。取第一次会在日志轮转/多次重启后指向历史。 */
4
+ export declare function parseGrokBuildFromLog(text: string): string | undefined;
5
+ /** 从 `grok --version` 的输出里取版本串(同一形状)。 */
6
+ export declare function parseGrokBuildFromVersionOutput(out: string): string | undefined;
7
+ export type GrokBuildDriftKind = "match" | "drift" | "unknown-current" | "unknown-started";
8
+ export interface GrokBuildDrift {
9
+ readonly kind: GrokBuildDriftKind;
10
+ readonly started?: string;
11
+ readonly current?: string;
12
+ /** 一句人读的话。四种 kind 四句不同的话 —— 含糊化等于把这一格的功能删掉。 */
13
+ readonly line: string;
14
+ }
15
+ export declare function describeGrokBuildDrift(started: string | undefined, current: string | undefined): GrokBuildDrift;
@@ -0,0 +1,11 @@
1
+ export type GrokCopresenceSessionDisclosure = "configured" | "new" | "resume";
2
+ export type GrokCopresenceDisclosure = {
3
+ profile: "commhub-only" | "x-search" | "repo-read" | "invalid";
4
+ lines: readonly string[];
5
+ };
6
+ /**
7
+ * Describe only the exact tool profiles accepted by the pinned Grok TUI
8
+ * runtime. This is deliberately exact: a near-miss must never be presented as
9
+ * either reviewed capability set.
10
+ */
11
+ export declare function grokCopresenceDisclosure(tools: unknown, session?: GrokCopresenceSessionDisclosure): GrokCopresenceDisclosure;
@@ -0,0 +1,75 @@
1
+ /** tmux session names. The attachable TUI owns the bare alias so that
2
+ * `tmux attach -t '=<alias>'` lands a human on the TUI, matching the codex
3
+ * lane exactly — an operator should not have to remember which runtime a node
4
+ * uses in order to know where to attach. */
5
+ export declare function grokCopresenceSessions(displayName: string): {
6
+ node: string;
7
+ tui: string;
8
+ };
9
+ export type GrokAttachSocketState = "missing" | "not_a_socket" | "ready";
10
+ /** Readiness is "the attach socket exists AND is a socket", never "the child
11
+ * process started". A grok leader that dies during startup leaves either no
12
+ * socket at all or a stale regular file from an aborted run; both used to read
13
+ * as ready because nothing looked. */
14
+ export declare function grokAttachSocketState(entry: {
15
+ isSocket(): boolean;
16
+ } | null | undefined): GrokAttachSocketState;
17
+ /** Set on the node child so that `anet node start` inside the tmux session does
18
+ * not re-enter this orchestration and fork bomb. The codex lane guards on the
19
+ * same variable (cli.ts: `process.env.ANET_COPRESENCE_BRIDGE !== "1"`); using a
20
+ * second name would leave two guards that must be kept in sync by hand. */
21
+ export declare const GROK_COPRESENCE_CHILD_ENV = "ANET_COPRESENCE_BRIDGE";
22
+ export interface GrokCopresenceDiagnosis {
23
+ readonly ok: boolean;
24
+ readonly lines: readonly string[];
25
+ /** #1768 —— 非阻断提示:平台能跑,但 agent-node 的能力表说它少了内核层保证。
26
+ * ok=true 时也可能非空;调用方打印它,不退出。 */
27
+ readonly notices: readonly string[];
28
+ }
29
+ /** One block naming every reason this node cannot run the shared TUI, not one
30
+ * exit per reason. A node that is both the wrong runtime AND missing its
31
+ * attach socket should learn both in one run. */
32
+ /** Platforms whose PTY / IPC / isolation primitives the grok co-presence lane
33
+ * has actually been validated on. agent-node refuses anywhere else, and it does
34
+ * so only after the node has been created and started once:
35
+ *
36
+ * [agent-node] grok-build-cli co-presence 无法在 darwin 上运行,缺少:
37
+ * 平台 darwin 尚未验证过共存所需的 PTY / IPC / 隔离原语
38
+ *
39
+ * Learned the expensive way on a Mac mini: install anet, install agent-node,
40
+ * create the node, start it — and only then find out the platform is refused.
41
+ * A one-command launcher that lets someone get that far has not saved them
42
+ * anything, so say it in the same breath as every other gap. */
43
+ export declare const GROK_COPRESENCE_PLATFORMS: readonly NodeJS.Platform[];
44
+ /** 能跑但没有内核层强制的平台 —— agent-node 启动时逐条打印 reducedGuarantees,这里只提前说一句。 */
45
+ export declare const GROK_COPRESENCE_REDUCED_GUARANTEE_PLATFORMS: readonly NodeJS.Platform[];
46
+ export declare function diagnoseGrokCopresence(input: {
47
+ runtime: string;
48
+ displayName: string;
49
+ grokCopresence?: boolean;
50
+ grokAttachSocket?: string;
51
+ platform?: NodeJS.Platform;
52
+ }): GrokCopresenceDiagnosis;
53
+ /** True when a plain `anet node start <name>` (no flag) should bring the shared
54
+ * TUI up by itself.
55
+ *
56
+ * 🔴 Deliberately NOT keyed on `grokCopresence`. That field is set to true at
57
+ * CREATE time for every grok-build-cli node, so reading it here would silently
58
+ * change what `anet node start` does for every grok node that already exists —
59
+ * they would stop running in the foreground and fork into tmux, unasked. Caught
60
+ * exactly that way: a start without the flag entered the orchestration.
61
+ *
62
+ * The codex lane looks the same but is not: `codexCopresence` is written only
63
+ * when the operator passes the flag. So grok needs its own record of the
64
+ * operator's choice, and `grokCopresenceAuto` is it. */
65
+ export declare function grokCopresenceRequested(flagPassed: boolean, profile: {
66
+ runtime?: unknown;
67
+ grokCopresence?: unknown;
68
+ grokCopresenceAuto?: unknown;
69
+ }): boolean;
70
+ /** Record the operator's opt-in so the NEXT start needs no flag — and only then.
71
+ * Never infer it from `grokCopresence`, which create sets by default. */
72
+ export declare function shouldPersistGrokCopresence(flagPassed: boolean, profile: {
73
+ runtime?: unknown;
74
+ grokCopresenceAuto?: unknown;
75
+ }): boolean;
@@ -0,0 +1,65 @@
1
+ export declare const GROK_UNIX_SOCKET_PATH_MAX_BYTES = 100;
2
+ export declare const GROK_COPRESENCE_CAPABILITY_MARKER = "ANET_CAPABILITY_GROK_COPRESENCE_V2";
3
+ export declare const GROK_PREVIEW_RESOLVER_INHERITED_ENV_KEYS: readonly ["PATH", "TMPDIR", "TMP", "TEMP", "LANG", "LC_ALL", "LC_CTYPE", "TZ"];
4
+ export declare const GROK_AGENT_NODE_INHERITED_ENV_KEYS: readonly ["PATH", "HOME", "TMPDIR", "TMP", "TEMP", "LANG", "LC_ALL", "LC_CTYPE", "TZ", "SHELL", "USER", "LOGNAME", "TERM", "COLORTERM", "NO_COLOR"];
5
+ export declare const GROK_AGENT_NODE_OPTIONAL_ENV_KEYS: readonly ["GROK_BINARY", "GROK_HOME", "FLOCK_BINARY", "SETPRIV_BINARY", "UNSHARE_BINARY", "GROK_CLI_TIMEOUT_MS", "GROK_HANDSHAKE_TIMEOUT_MS", "LOG_LEVEL", "ANET_GOAL_TICK_MS", "COMMHUB_MAX_GOALS_PER_NODE"];
6
+ /** Exact environment for the long-lived agent-node parent of the Grok TUI. */
7
+ export declare function buildGrokAgentNodeEnv(parentEnv: NodeJS.ProcessEnv): Record<string, string>;
8
+ export declare function grokPreviewResolverConfigPaths(home: string): {
9
+ directory: string;
10
+ userConfig: string;
11
+ globalConfig: string;
12
+ };
13
+ /**
14
+ * npm rejects loading the same file as both user and global config. Prepare
15
+ * two distinct, empty, owner-only files without following a final symlink so
16
+ * the resolver cannot inherit a user's ordinary npmrc credentials.
17
+ */
18
+ export declare function prepareGrokPreviewResolverConfigs(home: string): void;
19
+ /** Exact environment for the short-lived npm resolver and capability probe. */
20
+ export declare function buildGrokPreviewResolverEnv(parentEnv: NodeJS.ProcessEnv, home: string): Record<string, string>;
21
+ /** Old headless-only agent-node builds already advertised grok-build-cli. */
22
+ export declare function agentNodeHelpSupportsGrokCopresence(help: string): boolean;
23
+ export interface GrokCopresenceProfileFields {
24
+ grokCopresence: boolean;
25
+ grokLeaderSocket?: string;
26
+ grokAttachSocket?: string;
27
+ }
28
+ export interface GrokSocketPathOptions {
29
+ cwd?: string;
30
+ home?: string;
31
+ xdgRuntimeDir?: string;
32
+ uid?: number;
33
+ platform?: NodeJS.Platform;
34
+ }
35
+ /**
36
+ * Allocate deterministic Unix socket paths without creating anything.
37
+ *
38
+ * Grok's workspace sandbox does not admit an otherwise owner-controlled
39
+ * XDG_RUNTIME_DIR such as /run/user/<uid>. Keep the primary sockets under the
40
+ * node's owner-bound state home, which the runtime already admits, and use a
41
+ * short private tmp path only when the Unix socket length limit requires it.
42
+ * The runtime owns directory creation and permissions; `anet node create`
43
+ * only persists the identity of the two sockets.
44
+ */
45
+ export declare function grokCopresenceSocketPaths(nodeId: string, options?: GrokSocketPathOptions): {
46
+ leaderSocket: string;
47
+ attachSocket: string;
48
+ };
49
+ export type GrokAttachTarget = {
50
+ ok: true;
51
+ socketPath: string;
52
+ } | {
53
+ ok: false;
54
+ reason: "not_grok_build_cli" | "headless" | "missing_attach_socket";
55
+ };
56
+ /**
57
+ * `anet grok attach` eligibility. The CLI is the only human join path;
58
+ * this is the shipped decision so tests can drive it without a TTY.
59
+ */
60
+ export declare function resolveGrokAttachTarget(input: {
61
+ runtime: string;
62
+ grokCopresence?: unknown;
63
+ grokAttachSocket?: unknown;
64
+ }): GrokAttachTarget;
65
+ export declare function grokBuildCliCreationFields(runtime: string, nodeId: string, headless?: boolean, options?: GrokSocketPathOptions): GrokCopresenceProfileFields | Record<string, never>;
@@ -0,0 +1,14 @@
1
+ export interface HostTelemetry {
2
+ hostname: string;
3
+ ip: string | null;
4
+ cpu_load_1min: number | null;
5
+ cpu_cores: number | null;
6
+ mem_total_gb: number | null;
7
+ mem_used_gb: number | null;
8
+ mem_avail_gb: number | null;
9
+ disk_total_gb: number | null;
10
+ disk_used_gb: number | null;
11
+ disk_avail_gb: number | null;
12
+ }
13
+ export declare function getHostTelemetry(): HostTelemetry;
14
+ export declare function _clearHostTelemetryCache(): void;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 把 hub 的 TEXT 时间戳显示给人看。
3
+ *
4
+ * 🔴 原先是**原样打印**:
5
+ *
6
+ * updated: 2026-08-31 00:20:11
7
+ *
8
+ * 那是 UTC,**没有任何时区标记**。同一时刻本地是 `08:22:41 CST` ——
9
+ * 于是一个 **2 分钟前**刚心跳过的节点,在 UTC+8 的用户眼里像是 **8 小时前**的。
10
+ *
11
+ * 这不是假想:2026-08-31 我自己就这么读错过一次,据此差点报出「舰队心跳陈旧
12
+ * 8.3 小时」。**CLI 在主动制造这个误读。**
13
+ *
14
+ * 所以显示两样东西:
15
+ * - **相对时长**(人真正想知道的那个)
16
+ * - 绝对值,并**显式标 UTC**(便于和日志、issue 里的时间对齐)
17
+ */
18
+ export declare function formatHubTime(raw: unknown, nowMs?: number): string;
19
+ /** 人读的时长。负数(时钟偏差/未来时间)如实说,不折成 0。 */
20
+ export declare function formatAgo(deltaMs: number): string;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * #1595 —— `anet doctor` 原先只印 hub 自报的版本:
3
+ *
4
+ * ✅ CommHub reachable (http://127.0.0.1:9200 v0.9.0-preview.38)
5
+ *
6
+ * 读的人**看不到自己这台 CLI 钉的是哪个**。实测(2026-08-31):生产 hub 在
7
+ * `.38`,而 `anet hub start` 的 `PINNED_SERVER_VERSION` 是 `.44` —— 两个数
8
+ * 差 6 个版本,而屏幕上只有一个。今天有一整条排查(agent→用户消息为什么
9
+ * 验不了端到端)就卡在这个差上:`.44` 之前 `send_desktop_message` 是
10
+ * fire-and-forget 且仍返回 `ok:true`,所以在 `.38` 上拿到的 `ok:true`
11
+ * 不是「用户看到了」的证据。
12
+ *
13
+ * 🔴 **只并排摆出两个数,不判断谁对、不给阈值、不发警告。**
14
+ * hub 比 CLI 的 pin 老或新都可能完全合理 —— 连的是别人运维的 hub、
15
+ * 本机 hub 还没重启、或者故意钉在旧版。给一个猜出来的「应该一致」
16
+ * 判据,会在这些正常情况下变成误报,而一个会误报的检查第一周就会被关掉。
17
+ * 让读的人自己看见差在哪,是这一格能诚实做到的全部。
18
+ */
19
+ export declare function formatHubVersionDetail(hubUrl: string, hubVersion: unknown, pinnedVersion: string): string;
@@ -0,0 +1,34 @@
1
+ import type { IMCorrelationStore, IMTaskCorrelation } from "./types";
2
+ export interface JsonIMCorrelationStoreOptions {
3
+ now?: () => number;
4
+ /** How long idempotency keys remain valid. Defaults to 24h. */
5
+ seenTtlMs?: number;
6
+ /** How long terminal correlations remain queryable. Defaults to 24h. */
7
+ terminalTtlMs?: number;
8
+ }
9
+ /**
10
+ * Small durable store for RFC-020 §2.9④ / §4.4 correlation state.
11
+ *
12
+ * The first gateway PR needs this as a standalone data structure before the
13
+ * bridge is rewired: idempotency keys survive process restart, and task replies
14
+ * can be routed back to their originating IM conversation.
15
+ */
16
+ export declare class JsonIMCorrelationStore implements IMCorrelationStore {
17
+ private readonly path;
18
+ private readonly now;
19
+ private readonly seenTtlMs;
20
+ private readonly terminalTtlMs;
21
+ constructor(path: string, options?: JsonIMCorrelationStoreOptions);
22
+ hasSeen(idempotencyKey: string): Promise<string | null>;
23
+ recordSeen(idempotencyKey: string, taskId: string): Promise<void>;
24
+ getCorrelation(taskId: string): Promise<IMTaskCorrelation | null>;
25
+ putCorrelation(taskId: string, correlation: IMTaskCorrelation): Promise<void>;
26
+ updateStatus(taskId: string, status: IMTaskCorrelation["status"]): Promise<void>;
27
+ gc(now: number): Promise<{
28
+ removed: number;
29
+ }>;
30
+ private isExpired;
31
+ private load;
32
+ private save;
33
+ }
34
+ export declare function createJsonIMCorrelationStore(path: string, options?: JsonIMCorrelationStoreOptions): IMCorrelationStore;
@@ -1,5 +1,40 @@
1
+ /**
2
+ * RFC-020 §3.1 — Feishu (Lark) adapter for the IM compatibility layer.
3
+ *
4
+ * Uses `@larksuiteoapi/node-sdk` in WebSocket long-connection mode (WSClient).
5
+ * No public IP / no domain verification / no webhook signature decryption —
6
+ * the three biggest 飞书 接入 risks all live in the HTTP event-callback path,
7
+ * not in WSClient mode.
8
+ *
9
+ * Milestones:
10
+ * M1: contract scaffold.
11
+ * M2 (this file): WSClient init + EventDispatcher for `im.message.receive_v1`
12
+ * + event normalization + access whitelist gate + audit log.
13
+ * M3: outbound `im.message.create` (text), edit support (≤20/msg).
14
+ * M5: image upload / download (`im.image.create` / `im.messageResource.get`)
15
+ * + group @bot detection refined to match the bot's own open_id.
16
+ */
17
+ import * as lark from "@larksuiteoapi/node-sdk";
1
18
  import type { IMAdapter, IMAdapterHealth, IMChannelConfig, IMConversationRef, IMIngressMode, NormalizedIMEvent, NormalizedIMMessage } from "../types.js";
2
19
  type OnEventHandler = (event: NormalizedIMEvent) => Promise<void>;
20
+ export type FeishuWsClientLike = Pick<lark.WSClient, "start" | "close">;
21
+ export type FeishuWsClientFactory = (params: ConstructorParameters<typeof lark.WSClient>[0]) => FeishuWsClientLike;
22
+ type FeishuInboundHandler = (rawEvent: unknown) => Promise<unknown>;
23
+ export interface FeishuEventDispatcherLike {
24
+ register(handlers: Record<string, FeishuInboundHandler>): unknown;
25
+ }
26
+ export interface FeishuAdapterOptions {
27
+ /** @internal Avoids real bot-info HTTP calls in lifecycle tests. */
28
+ createClient?: (params: ConstructorParameters<typeof lark.Client>[0]) => lark.Client;
29
+ /** @internal Test seam; production uses the pinned Lark SDK WSClient. */
30
+ createWsClient?: FeishuWsClientFactory;
31
+ /** @internal Test seam; production uses the pinned Lark SDK dispatcher. */
32
+ createEventDispatcher?: () => FeishuEventDispatcherLike;
33
+ /** Independent outer bound in case the SDK promise/callback path stalls. */
34
+ wsReadyTimeoutMs?: number;
35
+ /** Called once when an already-ready socket exhausts reconnect attempts. */
36
+ onTerminalError?: (error: Error) => void;
37
+ }
3
38
  export declare class FeishuAdapter implements IMAdapter {
4
39
  readonly platform = "feishu";
5
40
  readonly ingressMode: IMIngressMode;
@@ -7,6 +42,8 @@ export declare class FeishuAdapter implements IMAdapter {
7
42
  private connectionName_;
8
43
  private client;
9
44
  private wsClient;
45
+ private lifecycleGeneration;
46
+ private readonly options;
10
47
  /**
11
48
  * The bot's own open_id, resolved at init() via /open-apis/bot/v3/info.
12
49
  * Used to detect real @bot mentions (vs any mention) in group messages.
@@ -17,6 +54,7 @@ export declare class FeishuAdapter implements IMAdapter {
17
54
  /** Where to persist downloaded inbound media (M5c). */
18
55
  private mediaDir;
19
56
  private health_;
57
+ constructor(options?: FeishuAdapterOptions);
20
58
  /**
21
59
  * Snapshot of the current `access.allowFrom` list (from access.json).
22
60
  * Used by the bridge's rate-limiter to exempt operator-vouched explicit
@@ -94,4 +132,46 @@ export declare function parsePostContent(rawJson: string): string;
94
132
  * @internal exported for unit tests.
95
133
  */
96
134
  export declare function extractPostImageKeys(rawJson: string): string[];
135
+ /**
136
+ * Sanitize a Feishu-supplied `file_name` so it's safe to append to a
137
+ * filesystem path. Strips `/`, `\`, `..`, control characters, and NUL
138
+ * bytes. Empty / all-stripped input falls back to a placeholder that
139
+ * uses the message id, so a hostile client can never write outside the
140
+ * conversation's `<mediaDir>/<convKey>/` directory.
141
+ *
142
+ * NOT a full display-safety pass — the LLM still sees the sanitized
143
+ * bytes and shouldn't render them as HTML/etc. That's a Layer above.
144
+ */
145
+ export declare function sanitizeFileName(raw: string, fallback: string): string;
146
+ /**
147
+ * Feishu text-message practical chunk threshold (RFC-020 §16).
148
+ *
149
+ * The official `im.message.create`/`reply` content limit for
150
+ * `msg_type:text` is ~30 KB JSON-encoded (`{"text":"..."}`), comfortably
151
+ * under what any reasonable bot reply produces. We chunk below that
152
+ * limit at 4000 CHARACTERS — gives a roomy safety margin for multi-byte
153
+ * UTF-8 and lets us split at paragraph boundaries cleanly. Chosen
154
+ * conservatively after Vincent 2026-06-30 ask "issue 发文字" (i.e.
155
+ * never silently fall back to PNG for "long" plain-text replies — they
156
+ * just chunk into multiple messages).
157
+ *
158
+ * Single-message ceiling, NOT a per-second rate limit (that's separate;
159
+ * RFC-020 §4.4).
160
+ */
161
+ export declare const FEISHU_TEXT_SINGLE_LIMIT = 4000;
162
+ /**
163
+ * Split a long text into chunks ≤ `maxChars`. Tries paragraph boundaries
164
+ * (`\n\n`), then line boundaries (`\n`), then word boundaries (space),
165
+ * then hard byte split. Output preserves the original text content
166
+ * (sum of chunks == original, modulo the boundary character that gets
167
+ * consumed by the split).
168
+ *
169
+ * If the input is already short enough, returns a single-element array.
170
+ */
171
+ export declare function splitTextForFeishu(text: string, maxChars: number): string[];
172
+ /**
173
+ * Lark errors may echo request/config values. Keep worker logs actionable while
174
+ * ensuring credentials and multiline payloads never cross the process boundary.
175
+ */
176
+ export declare function sanitizeFeishuWsError(rawError: unknown, appId: string, appSecret: string): Error;
97
177
  export {};
@@ -2,22 +2,36 @@
2
2
  * RFC-020 §2.5 / RFC-002 §2.2 — Feishu bridge worker.
3
3
  *
4
4
  * Entry point spawned by agent-node when a node profile has `channels.feishu`
5
- * enabled. Per Vincent 2026-06-24 decision, the first-cut is the simplified
6
- * "agent-node direct bridge" model, not the full commhub-gateway:
5
+ * enabled. This worker owns the FeishuAdapter and its WSClient connection.
7
6
  *
8
- * - This worker owns the FeishuAdapter and its WSClient connection.
9
- * - Inbound IM event → access whitelist gate → forward to agent-node's main
10
- * `think()` via parent IPC.
11
- * - think() result → adapter.send() back to the originating conversation.
7
+ * 🔴 There are TWO outbound paths, and which one runs is decided at line ~445:
12
8
  *
13
- * Differences vs RFC-020 §2.5 full commhub-gateway path:
9
+ * const client = commhubClient ?? createEnvCommHubClient();
10
+ * if (client) return createCommHubEventHandler(...); // (A)
11
+ * if (typeof process.send === "function") ... // (B)
12
+ *
13
+ * (A) CommHub task dispatch — **the default on any real node.**
14
+ * `createEnvCommHubClient()` returns null only when neither COMMHUB_URL
15
+ * nor ANET_HUB_URL is set, and every provisioned node has one. Replies
16
+ * carry `in_reply_to`, and the correlation store tracks task status.
17
+ * (B) parent IPC → agent-node's `think()` — the fallback when there is no
18
+ * hub URL in env (standalone / test harness).
19
+ *
20
+ * Both paths end at adapter.send() back to the originating conversation.
21
+ *
22
+ * 🔴 This block used to say the opposite —— verbatim:
23
+ * "IM messages do NOT pass through commhub task dispatch."
24
+ * That was true of the 2026-06-24 first cut, and stayed in the file after
25
+ * the commhub path landed (#1252, merged 2026-08-27). It is the first thing
26
+ * anyone reads in this file, so it mis-answered the question "does Feishu go
27
+ * through CommHub" for at least one reader before being caught. If you change
28
+ * which path is default, change these lines in the same commit.
29
+ *
30
+ * Still true of both paths (unchanged from the first cut):
14
31
  * - No separate gateway ntok_ / dedicated commhub alias.
15
- * - IM messages do NOT pass through commhub task dispatch.
16
- * - Feishu messages do NOT appear in Dashboard topology / Chat.
17
32
  *
18
- * The full §2.9 path (meta_json columns, SSE passthrough, persisted
19
- * IMCorrelationStore) lands as the follow-up PR after this demo ships
20
- * — tracked in #182.
33
+ * The remaining §2.9 work (meta_json columns, SSE passthrough, Dashboard
34
+ * topology / Chat visibility for Feishu conversations) is tracked in #182.
21
35
  *
22
36
  * Milestones:
23
37
  * M1: worker entry scaffold.
@@ -29,8 +43,29 @@
29
43
  * M4: agent-node spawn integration (fork(this) wired by agent-node).
30
44
  * M5: group @bot trigger refinement, image up/down, Docker smoke.
31
45
  */
32
- import type { NormalizedIMEvent } from "../types.js";
46
+ import type { IMCorrelationStore, NormalizedIMEvent } from "../types.js";
33
47
  import { FeishuAdapter } from "./adapter.js";
48
+ export type IMBridgeCommHubInboxMessage = {
49
+ id: string;
50
+ type?: string;
51
+ content: string;
52
+ from_session?: string;
53
+ in_reply_to?: string;
54
+ meta?: unknown;
55
+ };
56
+ export interface IMBridgeCommHubClient {
57
+ sendTask(args: {
58
+ alias: string;
59
+ task: string;
60
+ priority?: "high" | "normal" | "low";
61
+ ttlSeconds?: number;
62
+ meta?: unknown;
63
+ }): Promise<{
64
+ taskId: string;
65
+ }>;
66
+ getInbox(alias: string): Promise<IMBridgeCommHubInboxMessage[]>;
67
+ ackInbox(alias: string, messageId: string): Promise<void>;
68
+ }
34
69
  export interface FeishuBridgeOptions {
35
70
  /** Absolute path to `.anet/nodes/<node>/channels/feishu/`. */
36
71
  channelDir: string;
@@ -44,11 +79,28 @@ export interface FeishuBridgeOptions {
44
79
  * - stderr logger otherwise (standalone smoke debugging).
45
80
  */
46
81
  onEvent?: (event: NormalizedIMEvent) => Promise<void>;
82
+ /** Fatal WS failure after initial readiness (for worker lifecycle ownership). */
83
+ onTerminalError?: (error: Error) => void;
84
+ /** Persistent task/message correlation state. Defaults to channelDir/state.json. */
85
+ correlationStore?: IMCorrelationStore;
86
+ /** CommHub task transport. Defaults to COMMHUB_URL/COMMHUB_TOKEN when available. */
87
+ commhubClient?: IMBridgeCommHubClient;
88
+ /** Poll interval for CommHub replies. Defaults to 1500ms. */
89
+ commhubPollMs?: number;
90
+ /** 出站传输模式。省略时按 ANET_FEISHU_BRIDGE_MODE,再省略则 "direct"。 */
91
+ bridgeMode?: FeishuBridgeMode;
47
92
  }
48
93
  /** Bridge → parent: inbound IM event ready for think(). */
49
94
  export interface BridgeIncomingEnvelope {
50
95
  type: "event";
51
96
  event: NormalizedIMEvent;
97
+ /** Canonical outbound directory for this conversation (RFC-020 §15.1).
98
+ * Single source of truth — the agent-node injects this verbatim into
99
+ * the system prompt's "save files here" instruction, and the bridge
100
+ * whitelist accepts files only under this directory. Computed by the
101
+ * bridge from `event.conversation.conversationId` + `adapter
102
+ * .connectionName`. Trailing slash included. */
103
+ outboundDir?: string;
52
104
  }
53
105
  /** Parent → bridge: agent reply text for a previously-forwarded event. */
54
106
  export interface BridgeReplyEnvelope {
@@ -94,6 +146,24 @@ export type WithRateLimitHandle = {
94
146
  floodKeyCount: number;
95
147
  };
96
148
  };
149
+ /**
150
+ * 出站传输模式。**显式声明,不靠环境变量在场与否去猜。**
151
+ *
152
+ * direct — parent IPC → agent-node 的 think()。**默认。**
153
+ * 2026-06-24 的第一版路径,飞书消息不进 CommHub 任务分发,
154
+ * 也不出现在 Dashboard 拓扑 / Chat 里。
155
+ * commhub — 入站事件变成一个 CommHub task,回复带 in_reply_to,
156
+ * correlation store 跟踪状态。**必须显式打开。**
157
+ *
158
+ * 🔴 为什么要显式:在此之前是 `commhubClient ?? createEnvCommHubClient()` ——
159
+ * 有 COMMHUB_URL 就走 commhub、没有就悄悄回落 IPC。两条路径的可观测性、
160
+ * Dashboard 可见性、失败语义完全不同,而**运维看不出自己在哪条上**,
161
+ * 文件头注释也因此和代码说了相反的话长达一次发布。
162
+ */
163
+ export type FeishuBridgeMode = "commhub" | "direct";
164
+ export declare const DEFAULT_FEISHU_BRIDGE_MODE: FeishuBridgeMode;
165
+ /** 解析模式。优先级:显式入参 > 环境变量 > 默认。非法值直接抛,不静默取默认。 */
166
+ export declare function resolveFeishuBridgeMode(explicit?: FeishuBridgeMode, env?: NodeJS.ProcessEnv): FeishuBridgeMode;
97
167
  /**
98
168
  * IPC handler — forwards inbound events to the parent agent-node and routes
99
169
  * the parent's reply back to Feishu via the adapter. The parent contract is
@@ -118,7 +188,8 @@ export type WithRateLimitHandle = {
118
188
  * the agent-node.log (closes the prior silent-success blindspot).
119
189
  */
120
190
  /** @internal exported for test harness; not intended for production callers. */
121
- export declare function createIPCEventHandler(adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean): (event: NormalizedIMEvent) => Promise<void>;
191
+ export declare function createIPCEventHandler(adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean, correlationStore?: IMCorrelationStore): (event: NormalizedIMEvent) => Promise<void>;
192
+ export declare function createCommHubEventHandler(nodeAlias: string, adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean, correlationStore: IMCorrelationStore | undefined, commhubClient: IMBridgeCommHubClient, pollMs?: number): (event: NormalizedIMEvent) => Promise<void>;
122
193
  export { FeishuAdapter } from "./adapter.js";
123
194
  export { loadFeishuChannelConfig } from "./config.js";
124
195
  export type { FeishuAccessList, FeishuChannelConfig, FeishuChannelEnv, } from "./config.js";