@sleep2agi/agent-network 2.3.0-preview.4 → 2.3.0-preview.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -324
- package/dist/bin/anet.cjs +101 -0
- package/dist/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +20 -1
- package/dist/bin/goal-wake-log-render.d.ts +31 -0
- package/dist/src/batch-workdir.d.ts +9 -0
- package/dist/src/bootstrap-password-db.d.ts +13 -0
- package/dist/src/channel-attachments.d.ts +29 -0
- package/dist/src/channel-task-trace.d.ts +10 -0
- package/dist/src/claude-vendor-env.d.ts +28 -0
- package/dist/src/cli-args.d.ts +8 -0
- package/dist/src/client-task-trace.d.ts +9 -0
- package/dist/src/client.js +1 -1
- package/dist/src/codex-copresence-preflight.d.ts +65 -0
- package/dist/src/codex-copresence-profile.d.ts +68 -0
- package/dist/src/codex-model-default.d.ts +6 -0
- package/dist/src/controlled-upload.d.ts +83 -0
- package/dist/src/copresence-deps.d.ts +20 -0
- package/dist/src/copresence-identity.d.ts +339 -0
- package/dist/src/dashboard-managed-process.d.ts +35 -0
- package/dist/src/environ-alias.d.ts +14 -0
- package/dist/src/grok-attach-client.d.ts +115 -0
- package/dist/src/grok-copresence-disclosure.d.ts +11 -0
- package/dist/src/grok-copresence-profile.d.ts +65 -0
- package/dist/src/im/feishu/adapter.d.ts +149 -1
- package/dist/src/im/feishu/bridge.d.ts +9 -0
- package/dist/src/im/feishu/config.d.ts +31 -0
- package/dist/src/im/feishu/hub-upload.d.ts +88 -0
- package/dist/src/im/feishu/markdown-image-renderer.d.ts +61 -0
- package/dist/src/im/feishu/outbound-marker.d.ts +140 -0
- package/dist/src/im/feishu/outbound-paths.d.ts +50 -0
- package/dist/src/im/feishu/outbound-route.d.ts +62 -0
- package/dist/src/im/feishu/worker-lifecycle.d.ts +13 -0
- package/dist/src/im/feishu/worker.js +391 -16
- package/dist/src/im/types.d.ts +38 -1
- package/dist/src/locale-diagnostic.d.ts +12 -0
- package/dist/src/mock-llm.d.ts +12 -0
- package/dist/src/node-server.js +7 -1
- package/dist/src/normalize-runtime.d.ts +14 -2
- package/dist/src/opencode-agent-node-pair.d.ts +14 -0
- package/dist/src/opencode-auth-login.d.ts +43 -0
- package/dist/src/opencode-launch-env.d.ts +13 -0
- package/dist/src/opencode-owner-mode.d.ts +6 -0
- package/dist/src/opencode-package-binary.d.ts +21 -0
- package/dist/src/opencode-pin.d.ts +44 -0
- package/dist/src/opencode-preset.d.ts +73 -0
- package/dist/src/opencode-runtime-binding.d.ts +30 -0
- package/dist/src/opencode-safe-root.d.ts +27 -0
- package/dist/src/opencode-smoke-env.d.ts +1 -0
- package/dist/src/outbound-tool-names.d.ts +1 -0
- package/dist/src/owner-env-file.d.ts +2 -0
- package/dist/src/package-mode-preflight.d.ts +31 -0
- package/dist/src/primary-network.d.ts +23 -0
- package/dist/src/private-state.d.ts +10 -0
- package/dist/src/project-key.d.ts +1 -0
- package/dist/src/secret-shell-guidance.d.ts +3 -0
- package/dist/src/task-trace.d.ts +33 -0
- package/dist/src/tmux-attach.d.ts +8 -0
- package/dist/src/tmux-capability.d.ts +58 -0
- package/dist/src/tmux-exact-target.d.ts +34 -0
- package/dist/src/tmux-pane-prompt.d.ts +22 -0
- package/dist/src/token-cli.d.ts +13 -0
- package/dist/src/unsafe-package-path-reason.d.ts +17 -0
- package/package.json +10 -6
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
export interface SessionInfo {
|
|
2
|
+
tmux: string;
|
|
3
|
+
pid: number;
|
|
4
|
+
pgid: number;
|
|
5
|
+
starttime_jiffies: number;
|
|
6
|
+
}
|
|
7
|
+
export interface CopresenceMarker {
|
|
8
|
+
marker: string;
|
|
9
|
+
boot_id: string;
|
|
10
|
+
started_at_epoch_ms: number;
|
|
11
|
+
owner_uid: number;
|
|
12
|
+
sessions: {
|
|
13
|
+
appsrv?: SessionInfo;
|
|
14
|
+
bridge?: SessionInfo;
|
|
15
|
+
tui?: SessionInfo;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export type RefuseCause = "MISSING" | "SYMLINK" | "NOT_REGULAR" | "WRONG_MODE" | "OWNER_MISMATCH" | "PARSE_ERROR" | "SCHEMA_INVALID" | "STALE_BOOT_ID" | "PLATFORM_UNSUPPORTED";
|
|
19
|
+
export type ReadMarkerResult = {
|
|
20
|
+
kind: "ok";
|
|
21
|
+
marker: CopresenceMarker;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "refuse";
|
|
24
|
+
cause: RefuseCause;
|
|
25
|
+
detail: string;
|
|
26
|
+
};
|
|
27
|
+
export interface ProcStat {
|
|
28
|
+
pgid: number;
|
|
29
|
+
starttime_jiffies: number;
|
|
30
|
+
ppid: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Injectable primitive for /proc access. Real impl reads the filesystem;
|
|
34
|
+
* unit tests inject a mock so /proc-based logic is deterministically testable.
|
|
35
|
+
*
|
|
36
|
+
* Contract:
|
|
37
|
+
* - listAllPids: read /proc directory and return numeric-name entries.
|
|
38
|
+
* Throws on unrecoverable errors (permission denied on /proc itself).
|
|
39
|
+
* - readEnviron: read /proc/<pid>/environ as a raw string. Returns null
|
|
40
|
+
* if the pid has vanished (ENOENT) — that's a normal race, not a failure.
|
|
41
|
+
* Throws for permission errors etc.
|
|
42
|
+
* - readStat: read /proc/<pid>/stat and extract (pgid, starttime, ppid).
|
|
43
|
+
* Returns null on ENOENT (pid gone). Throws on other errors.
|
|
44
|
+
*/
|
|
45
|
+
export interface ProcessEnumerator {
|
|
46
|
+
listAllPids(): number[];
|
|
47
|
+
readEnviron(pid: number): string | null;
|
|
48
|
+
readStat(pid: number): ProcStat | null;
|
|
49
|
+
/**
|
|
50
|
+
* REAL uid of the process itself (`Uid:` line of /proc/<pid>/status,
|
|
51
|
+
* field 0). Used by the environ-EACCES discriminator to tell
|
|
52
|
+
* "other-user process (expected EACCES)" from "our own process we could
|
|
53
|
+
* not inspect (must be accounted for)".
|
|
54
|
+
*
|
|
55
|
+
* MUST NOT be implemented as `statSync('/proc/<pid>/environ').uid`.
|
|
56
|
+
* A process that called prctl(PR_SET_DUMPABLE, 0) keeps its real uid but
|
|
57
|
+
* its /proc/<pid>/{environ,mem,...} nodes flip to root:root 0400 (see
|
|
58
|
+
* proc(5) / kernel `task_dump_owner`). Deriving ownership from the
|
|
59
|
+
* environ inode therefore reports uid 0 for our OWN non-dumpable
|
|
60
|
+
* children, which made them invisible to the scan: not in `hits`, not in
|
|
61
|
+
* the unreadable list, so teardown reported success and deleted the
|
|
62
|
+
* marker while the orphan lived on (Defect A).
|
|
63
|
+
*
|
|
64
|
+
* Returns null if the pid is gone (ENOENT) or if even /proc/<pid>/status
|
|
65
|
+
* is blocked (hidepid / LSM) — in that case the process cannot be ours
|
|
66
|
+
* to reason about and is skipped.
|
|
67
|
+
*/
|
|
68
|
+
readOwnerUid(pid: number): number | null;
|
|
69
|
+
/**
|
|
70
|
+
* Single-character process state from /proc/<pid>/status (R/S/D/Z/T/...).
|
|
71
|
+
* `Z` means zombie — mm freed, environ returns EACCES even to owner, but
|
|
72
|
+
* the pid is going away shortly. Skip zombies during environ scan.
|
|
73
|
+
* Returns null if the pid is gone (ENOENT).
|
|
74
|
+
*/
|
|
75
|
+
readState(pid: number): string | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Injectable primitive for sending signals. Real impl uses process.kill;
|
|
79
|
+
* tests inject a mock.
|
|
80
|
+
*/
|
|
81
|
+
export interface KillPrimitive {
|
|
82
|
+
killPgroup(pgid: number, signal: "TERM" | "KILL"): void;
|
|
83
|
+
/** Returns true if ANY process in the pgroup is still alive. */
|
|
84
|
+
pgroupAlive(pgid: number): boolean;
|
|
85
|
+
}
|
|
86
|
+
export declare function markerFilePath(nodesDir: string, nodeId: string): string;
|
|
87
|
+
export declare function readBootId(): string;
|
|
88
|
+
/**
|
|
89
|
+
* Write the marker file atomically.
|
|
90
|
+
*
|
|
91
|
+
* IMPORTANT (Blocker 1 fix): the uuid parameter is the SINGLE SOURCE OF
|
|
92
|
+
* TRUTH. Caller is expected to inject this same uuid into every tmux
|
|
93
|
+
* session's ANET_NODE_MARKER env var. writeMarker does NOT generate its
|
|
94
|
+
* own uuid — that was the exact bug in 9f2ec282.
|
|
95
|
+
*/
|
|
96
|
+
export declare function writeMarker(nodesDir: string, nodeId: string, uuid: string, sessions: CopresenceMarker["sessions"]): CopresenceMarker;
|
|
97
|
+
/**
|
|
98
|
+
* Read the marker file with structured fail-closed refuses.
|
|
99
|
+
*
|
|
100
|
+
* Never throws for expected refuse causes. Only throws if the OS itself
|
|
101
|
+
* is broken (e.g. EIO). Malformed JSON, wrong types, null bodies etc.
|
|
102
|
+
* all return { kind: "refuse", cause, detail }.
|
|
103
|
+
*/
|
|
104
|
+
export declare function readMarker(nodesDir: string, nodeId: string): ReadMarkerResult;
|
|
105
|
+
export declare function removeMarker(nodesDir: string, nodeId: string): void;
|
|
106
|
+
export declare function realEnumerator(): ProcessEnumerator;
|
|
107
|
+
export declare function realKiller(): KillPrimitive;
|
|
108
|
+
/**
|
|
109
|
+
* Scan /proc for all pids whose environ contains ANET_NODE_MARKER=<uuid>.
|
|
110
|
+
* This is the authoritative identity source — NOT the marker file's stored
|
|
111
|
+
* pids, which may be stale (main died, workers survived under new pgids).
|
|
112
|
+
*
|
|
113
|
+
* Bytes format of /proc/PID/environ: NUL-separated key=value pairs.
|
|
114
|
+
*
|
|
115
|
+
* Blocker 1 fix (independent audit 92d53c8f, 2026-07-29): /proc/<pid>/environ
|
|
116
|
+
* is 0400 owner-only. Blindly reading it will hit EACCES on every other-user
|
|
117
|
+
* process (pid 1 is systemd/root → guaranteed EACCES). The naive fix — wrap
|
|
118
|
+
* in try/catch and continue — would silently miss marker-carrying processes
|
|
119
|
+
* whose environ we can't read for some other reason, recreating Defect A
|
|
120
|
+
* ("nothing killed but report success"). Right fix:
|
|
121
|
+
*
|
|
122
|
+
* 1. Try readEnviron.
|
|
123
|
+
* 2. On EACCES, discriminate via readOwnerUid + readState:
|
|
124
|
+
* - Owner uid != ours → EXPECTED skip (can't be one of our procs).
|
|
125
|
+
* - Own uid, state = Z → EXPECTED skip (zombie, mm freed).
|
|
126
|
+
* - Own uid, not zombie → FAIL-CLOSED (unexplained EACCES on our own
|
|
127
|
+
* live process is a real problem, must throw).
|
|
128
|
+
*/
|
|
129
|
+
export interface ScanResult {
|
|
130
|
+
/** Pids whose environ we successfully read and matched the marker uuid. */
|
|
131
|
+
hits: number[];
|
|
132
|
+
/**
|
|
133
|
+
* Own-uid, live, environ-unreadable pids that are PLAUSIBLY PART OF THE
|
|
134
|
+
* COPRESENCE TREE (invariant 11 scope test). These might be marker-
|
|
135
|
+
* carrying without us being able to prove it, so the reap flow REFUSES
|
|
136
|
+
* marker removal while this list is non-empty — defense against Defect A
|
|
137
|
+
* (silently missing a marker-carrying process, then deleting the marker
|
|
138
|
+
* as if teardown had succeeded).
|
|
139
|
+
*/
|
|
140
|
+
unreadableOwnUid: number[];
|
|
141
|
+
/**
|
|
142
|
+
* Own-uid, live, environ-unreadable pids that failed the scope test:
|
|
143
|
+
* their pgid belongs to no marker-carrying group and their ppid chain
|
|
144
|
+
* reaches no marker carrier / validated marker-file session pid.
|
|
145
|
+
*
|
|
146
|
+
* INFORMATIONAL ONLY — never fail-closed. A machine routinely has such
|
|
147
|
+
* processes (a same-uid process whose primary GID differs from ours fails
|
|
148
|
+
* the kernel's __ptrace_may_access gid check and EACCESes on environ even
|
|
149
|
+
* though its real uid matches). v2 lumped these into unreadableOwnUid,
|
|
150
|
+
* which made reapMarkerGroups structurally unable to return success on
|
|
151
|
+
* any such host.
|
|
152
|
+
*
|
|
153
|
+
* KNOWN RESIDUAL GAP (stated rather than papered over): a marker-carrying
|
|
154
|
+
* process that is BOTH non-dumpable (environ unreadable) AND fully
|
|
155
|
+
* detached (setsid'd into its own pgroup with ppid=1, no live recorded
|
|
156
|
+
* session pid above it) lands here and is therefore not reaped and does
|
|
157
|
+
* not block marker removal. Nothing in /proc exposes the environment of a
|
|
158
|
+
* non-dumpable task to a non-root reader, so no scope widening can
|
|
159
|
+
* recover it — only running teardown as root could. Widening scope to
|
|
160
|
+
* "every same-uid unreadable process" is NOT an acceptable trade: that is
|
|
161
|
+
* exactly the v2 behaviour that made teardown never succeed. The
|
|
162
|
+
* realistic copresence shape (child of a recorded pane pid, or sharing a
|
|
163
|
+
* marker carrier's pgroup) IS covered — see the real-/proc test.
|
|
164
|
+
*/
|
|
165
|
+
unreadableOutOfScope: number[];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Marker-file session records used to anchor the invariant-11 scope test.
|
|
169
|
+
* Each entry must be re-validated (pid alive AND same starttime) before it
|
|
170
|
+
* is trusted — see validateAnchors.
|
|
171
|
+
*/
|
|
172
|
+
export interface ScanAnchors {
|
|
173
|
+
sessions?: Array<{
|
|
174
|
+
pid: number;
|
|
175
|
+
starttime_jiffies: number;
|
|
176
|
+
}>;
|
|
177
|
+
}
|
|
178
|
+
export declare function anchorsFromMarker(marker: CopresenceMarker): ScanAnchors;
|
|
179
|
+
/**
|
|
180
|
+
* Invariant 11 scope test: is `pid` plausibly part of the copresence tree?
|
|
181
|
+
*
|
|
182
|
+
* True when the pid IS an anchor, when its pgid belongs to a marker-carrying
|
|
183
|
+
* group (or a validated anchor's group), or when walking its ppid chain
|
|
184
|
+
* reaches an anchor / marker carrier / a pid inside a relevant pgroup.
|
|
185
|
+
*
|
|
186
|
+
* Everything else is out of scope and must not participate in a fail-closed
|
|
187
|
+
* decision, no matter how unreadable it is.
|
|
188
|
+
*/
|
|
189
|
+
export declare function isInCopresenceScope(enumer: ProcessEnumerator, pid: number, relevantPids: Set<number>, relevantPgids: Set<number>): boolean;
|
|
190
|
+
export declare function scanEnvironForMarker(enumer: ProcessEnumerator, markerUuid: string): number[];
|
|
191
|
+
export declare function scanEnvironForMarkerFull(enumer: ProcessEnumerator, markerUuid: string, anchors?: ScanAnchors): ScanResult;
|
|
192
|
+
export declare function groupPidsByPgid(enumer: ProcessEnumerator, pids: number[]): Map<number, number[]>;
|
|
193
|
+
export type HomogeneityResult = {
|
|
194
|
+
ok: true;
|
|
195
|
+
members: number[];
|
|
196
|
+
} | {
|
|
197
|
+
ok: false;
|
|
198
|
+
cause: "FOREIGN_MEMBER" | "ENUM_ERROR" | "EMPTY_GROUP";
|
|
199
|
+
foreignPids: number[];
|
|
200
|
+
unreadablePids: number[];
|
|
201
|
+
detail: string;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Verify that EVERY live member of `pgid` carries the marker.
|
|
205
|
+
*
|
|
206
|
+
* Blocker 2 fix: enumeration errors surface as ENUM_ERROR (fail-closed),
|
|
207
|
+
* never as an empty-list judged "safe". Any unreadable member also
|
|
208
|
+
* fails-closed. Empty group (no live members at all) also refuses — killing
|
|
209
|
+
* an empty pgroup can't be right and empty-list judged "ok" recreates the
|
|
210
|
+
* exact defect shape (independent audit 92d53c8f finding #6).
|
|
211
|
+
*
|
|
212
|
+
* Blocker 2 second half (zombie): a zombie same-uid process's environ
|
|
213
|
+
* returns EACCES even to owner (mm freed), but stat still exists with
|
|
214
|
+
* original pgid. Without discrimination, the zombie would be treated as
|
|
215
|
+
* "unreadable member" → ENUM_ERROR → entire group SKIPPED. Since re-verify
|
|
216
|
+
* happens post-SIGTERM (when zombies are most numerous), teardown would
|
|
217
|
+
* never escalate. Fix: apply the same owner-uid + state=Z discriminator as
|
|
218
|
+
* scanEnvironForMarker.
|
|
219
|
+
*
|
|
220
|
+
* Algorithm:
|
|
221
|
+
* 1. Enumerate all pids on the system.
|
|
222
|
+
* 2. Filter to pids whose /proc/PID/stat pgid == target pgid.
|
|
223
|
+
* 3. For each such pid, check its environ with EACCES discrimination:
|
|
224
|
+
* - Other-user EACCES → skip (can't be ours anyway).
|
|
225
|
+
* - Own-uid zombie → skip (expected, dying).
|
|
226
|
+
* - Own-uid live EACCES → truly unreadable → fail-closed.
|
|
227
|
+
* - Missing marker → foreign member → fail-closed.
|
|
228
|
+
*/
|
|
229
|
+
export declare function verifyGroupHomogeneity(enumer: ProcessEnumerator, pgid: number, markerUuid: string): HomogeneityResult;
|
|
230
|
+
/**
|
|
231
|
+
* Walk the caller's ancestry (self → PPID → grandparent → ...) and check
|
|
232
|
+
* whether any ancestor carries the target marker. If yes → caller is
|
|
233
|
+
* running inside the copresence tree we're about to kill, and would take
|
|
234
|
+
* itself down.
|
|
235
|
+
*/
|
|
236
|
+
export declare function callerCarriesMarker(enumer: ProcessEnumerator, markerUuid: string): {
|
|
237
|
+
self: boolean;
|
|
238
|
+
ancestorPid?: number;
|
|
239
|
+
};
|
|
240
|
+
export type ReapResult = {
|
|
241
|
+
kind: "success";
|
|
242
|
+
killedPgids: number[];
|
|
243
|
+
residualPids: number[];
|
|
244
|
+
unreadableOwnUid?: number[];
|
|
245
|
+
} | {
|
|
246
|
+
kind: "failed";
|
|
247
|
+
killedPgids: number[];
|
|
248
|
+
residualPids: number[];
|
|
249
|
+
skippedGroups: Array<{
|
|
250
|
+
pgid: number;
|
|
251
|
+
reason: string;
|
|
252
|
+
}>;
|
|
253
|
+
detail: string;
|
|
254
|
+
unreadableOwnUid?: number[];
|
|
255
|
+
};
|
|
256
|
+
export interface ReapOptions {
|
|
257
|
+
graceMs: number;
|
|
258
|
+
logger: (msg: string) => void;
|
|
259
|
+
/**
|
|
260
|
+
* Sleep primitive (grace period). Real code uses setTimeout; tests inject
|
|
261
|
+
* a fast/deterministic sleep so grace paths are actually covered. Prior
|
|
262
|
+
* impl was a busy-wait `while (Date.now() < end) {}` — audit 92d53c8f
|
|
263
|
+
* finding #3 flagged that as pinning one CPU core for graceMs and blocking
|
|
264
|
+
* the event loop; test coverage missed it because tests passed graceMs=0.
|
|
265
|
+
*/
|
|
266
|
+
sleep?: (ms: number) => Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Invariant-11 scope anchors, normally `anchorsFromMarker(marker)`.
|
|
269
|
+
*
|
|
270
|
+
* Without them the only anchors are the marker carriers the scan itself
|
|
271
|
+
* found, so a marker-carrying process we cannot READ (non-dumpable) but
|
|
272
|
+
* whose parent IS a recorded session pid would be judged out of scope and
|
|
273
|
+
* silently dropped. Passing the marker's recorded session pids closes that
|
|
274
|
+
* hole; each one is re-validated (alive + same starttime) before it can
|
|
275
|
+
* widen scope, so a stale/recycled pid cannot.
|
|
276
|
+
*/
|
|
277
|
+
anchors?: ScanAnchors;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Full reap flow with TOCTOU re-verification.
|
|
281
|
+
*
|
|
282
|
+
* Sequence:
|
|
283
|
+
* 1. Environ scan for marker → get all live pids carrying it.
|
|
284
|
+
* 2. Group by current PGID.
|
|
285
|
+
* 3. For each group: verify homogeneity. Skip on foreign/unreadable.
|
|
286
|
+
* 4. For each verified group: send SIGTERM to pgroup.
|
|
287
|
+
* 5. Wait grace.
|
|
288
|
+
* 6. Re-verify each group (marker still there, no new foreign) before SIGKILL.
|
|
289
|
+
* 7. Send SIGKILL to any group still alive.
|
|
290
|
+
* 8. Post-rescan: if any marker-carrying pid alive → preserve marker.
|
|
291
|
+
*/
|
|
292
|
+
export declare function reapMarkerGroups(enumer: ProcessEnumerator, killer: KillPrimitive, markerUuid: string, opts: ReapOptions): Promise<ReapResult>;
|
|
293
|
+
export interface PrepareStartDeps {
|
|
294
|
+
/** Usually () => readMarker(nodesDir, nodeId). */
|
|
295
|
+
readMarker(): ReadMarkerResult;
|
|
296
|
+
/** Usually (uuid, anchors) => reapMarkerGroups(realEnumerator(), realKiller(), uuid, {...anchors}). */
|
|
297
|
+
reap(uuid: string, anchors: ScanAnchors): Promise<ReapResult>;
|
|
298
|
+
/** Usually () => removeMarker(nodesDir, nodeId). */
|
|
299
|
+
removeMarker(): void;
|
|
300
|
+
/** Usually (uuid, sessions) => writeMarker(nodesDir, nodeId, uuid, sessions). */
|
|
301
|
+
writeMarker(uuid: string, sessions: CopresenceMarker["sessions"]): void;
|
|
302
|
+
logger(msg: string): void;
|
|
303
|
+
}
|
|
304
|
+
export type PrepareStartResult = {
|
|
305
|
+
kind: "ok";
|
|
306
|
+
reclaimedUuid?: string;
|
|
307
|
+
} | {
|
|
308
|
+
kind: "blocked";
|
|
309
|
+
cause: "STALE_TREE_ALIVE" | "UNUSABLE_MARKER";
|
|
310
|
+
detail: string;
|
|
311
|
+
remedy: string;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Everything that must happen BEFORE the first `tmux new-session` of a
|
|
315
|
+
* copresence start. Extracted out of cli.ts so both blockers below are
|
|
316
|
+
* actually reachable by tests — the audit's point that the two fatal
|
|
317
|
+
* defects of the previous rounds both lived in an untested cli.ts seam.
|
|
318
|
+
*
|
|
319
|
+
* Blocker 5 — marker-before-tmux ordering.
|
|
320
|
+
* v2 wrote the marker only after the app-server had bound its port, i.e.
|
|
321
|
+
* after a 25s wait and after several `process.exit(1)` paths. A start that
|
|
322
|
+
* died in that window left a live, marker-carrying tmux session behind
|
|
323
|
+
* with NO marker file on disk: the exact unreclaimable-ghost this feature
|
|
324
|
+
* exists to prevent. The marker is now written here, before any session is
|
|
325
|
+
* created, with an empty `sessions` object — reap identity has always been
|
|
326
|
+
* the environ uuid, never the recorded pids, so an empty sessions object
|
|
327
|
+
* loses nothing but observability hints (which the start path fills in
|
|
328
|
+
* later, best-effort).
|
|
329
|
+
*
|
|
330
|
+
* Blocker 6 — never overwrite a preserved marker.
|
|
331
|
+
* A failed stop deliberately PRESERVES the marker so the next stop can
|
|
332
|
+
* retry idempotently. v2's start then overwrote it with a fresh uuid while
|
|
333
|
+
* only killing tmux sessions BY NAME, so the still-running subprocesses of
|
|
334
|
+
* the previous instance became permanently unreclaimable: their uuid was
|
|
335
|
+
* gone from disk forever. Now the old identity is reaped FIRST; if that
|
|
336
|
+
* reap does not fully succeed we refuse to start rather than destroy the
|
|
337
|
+
* only handle on those processes.
|
|
338
|
+
*/
|
|
339
|
+
export declare function prepareIdentityForStart(newUuid: string, deps: PrepareStartDeps): Promise<PrepareStartResult>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type DashboardLaunchSource = "npx" | "global";
|
|
2
|
+
export interface DashboardLaunchRecord {
|
|
3
|
+
schema: 1;
|
|
4
|
+
port: number;
|
|
5
|
+
listener_pid: number;
|
|
6
|
+
listener_birth: string;
|
|
7
|
+
source: DashboardLaunchSource;
|
|
8
|
+
source_key: string;
|
|
9
|
+
recorded_at: string;
|
|
10
|
+
}
|
|
11
|
+
export type DashboardListenerDecision = {
|
|
12
|
+
action: "start";
|
|
13
|
+
} | {
|
|
14
|
+
action: "already_running";
|
|
15
|
+
pid: number;
|
|
16
|
+
} | {
|
|
17
|
+
action: "terminate_owned_stale";
|
|
18
|
+
pid: number;
|
|
19
|
+
reason: "unhealthy" | "version_changed";
|
|
20
|
+
} | {
|
|
21
|
+
action: "refuse";
|
|
22
|
+
reason: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function isDashboardProcessCommand(command: string): boolean;
|
|
25
|
+
export declare function decideDashboardListener(input: {
|
|
26
|
+
port: number;
|
|
27
|
+
listenerPids: number[];
|
|
28
|
+
record: DashboardLaunchRecord | null;
|
|
29
|
+
listenerBirth: string | null;
|
|
30
|
+
listenerCommand: string | null;
|
|
31
|
+
desiredSource: DashboardLaunchSource;
|
|
32
|
+
desiredSourceKey: string;
|
|
33
|
+
healthy: boolean;
|
|
34
|
+
}): DashboardListenerDecision;
|
|
35
|
+
export declare function parseDashboardLaunchRecord(value: unknown): DashboardLaunchRecord | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Parse the environ blob (NUL-separated key=val) and return the
|
|
2
|
+
* COMMHUB_ALIAS value if present, else null. Exported for testing. */
|
|
3
|
+
export declare function parseEnvironAlias(environBlob: string): string | null;
|
|
4
|
+
/** Read /proc/<pid>/environ and return the COMMHUB_ALIAS value.
|
|
5
|
+
* Any file-read error (not-a-Linux, permission denied, race with
|
|
6
|
+
* process exit) returns null — caller must not fail-closed on that
|
|
7
|
+
* (the process is stale/gone/inaccessible, not our problem). */
|
|
8
|
+
export declare function readEnvironAlias(pid: number): string | null;
|
|
9
|
+
/** Scan /proc for pids whose COMMHUB_ALIAS env matches any of the
|
|
10
|
+
* target aliases. Linux-only (procfs); returns null on non-Linux or
|
|
11
|
+
* when /proc is unreadable — caller MUST fail-closed on null per
|
|
12
|
+
* the same #180 R2 fail-closed contract as findNodeProcessesByAlias.
|
|
13
|
+
* Self-pid + init (PID 1) are excluded. */
|
|
14
|
+
export declare function findEnvironAliasMatches(aliases: Iterable<string>, selfPid: number): number[] | null;
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
export type GrokAttachClientFrame = GrokAttachInputFrame | GrokAttachResizeFrame | GrokAttachDetachFrame;
|
|
49
|
+
export interface GrokAttachInputSource {
|
|
50
|
+
on(event: "data", listener: (chunk: unknown) => void): unknown;
|
|
51
|
+
on(event: "end", listener: () => void): unknown;
|
|
52
|
+
off?(event: "data" | "end", listener: (...args: any[]) => void): unknown;
|
|
53
|
+
removeListener?(event: "data" | "end", listener: (...args: any[]) => void): unknown;
|
|
54
|
+
pause?(): unknown;
|
|
55
|
+
resume?(): unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface GrokAttachOutputSink {
|
|
58
|
+
write(chunk: Uint8Array): boolean | void;
|
|
59
|
+
columns?: number;
|
|
60
|
+
rows?: number;
|
|
61
|
+
once?(event: "drain", listener: () => void): unknown;
|
|
62
|
+
}
|
|
63
|
+
export interface GrokAttachSignalSource {
|
|
64
|
+
on(event: "SIGWINCH", listener: () => void): unknown;
|
|
65
|
+
off?(event: "SIGWINCH", listener: () => void): unknown;
|
|
66
|
+
removeListener?(event: "SIGWINCH", listener: () => void): unknown;
|
|
67
|
+
}
|
|
68
|
+
export interface GrokAttachSocketStat {
|
|
69
|
+
uid: number;
|
|
70
|
+
isSocket(): boolean;
|
|
71
|
+
isSymbolicLink(): boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface GrokAttachDependencies {
|
|
74
|
+
lstat?: (socketPath: string) => Promise<GrokAttachSocketStat>;
|
|
75
|
+
getuid?: () => number | undefined;
|
|
76
|
+
connect?: (socketPath: string) => Duplex;
|
|
77
|
+
}
|
|
78
|
+
export interface GrokAttachClientOptions {
|
|
79
|
+
socketPath: string;
|
|
80
|
+
input: GrokAttachInputSource;
|
|
81
|
+
output: GrokAttachOutputSink;
|
|
82
|
+
signalSource?: GrokAttachSignalSource;
|
|
83
|
+
terminalSize?: () => {
|
|
84
|
+
cols: number | undefined;
|
|
85
|
+
rows: number | undefined;
|
|
86
|
+
};
|
|
87
|
+
maxFrameBytes?: number;
|
|
88
|
+
maxBufferBytes?: number;
|
|
89
|
+
handshakeTimeoutMs?: number;
|
|
90
|
+
closeTimeoutMs?: number;
|
|
91
|
+
detachOnInputEnd?: boolean;
|
|
92
|
+
onHello?: (frame: GrokAttachHelloFrame) => void;
|
|
93
|
+
onStatus?: (frame: GrokAttachStatusFrame) => void;
|
|
94
|
+
onError?: (error: Error, frame?: GrokAttachErrorFrame) => void;
|
|
95
|
+
onDetach?: (frame: GrokAttachDetachFrame) => void;
|
|
96
|
+
dependencies?: GrokAttachDependencies;
|
|
97
|
+
}
|
|
98
|
+
export type GrokAttachCloseReason = "local-detach" | "input-end" | "remote-detach" | "socket-close" | "socket-error" | "protocol-error";
|
|
99
|
+
export interface GrokAttachCloseInfo {
|
|
100
|
+
reason: GrokAttachCloseReason;
|
|
101
|
+
error?: Error;
|
|
102
|
+
}
|
|
103
|
+
export interface GrokAttachSession {
|
|
104
|
+
readonly socketPath: string;
|
|
105
|
+
readonly closed: Promise<GrokAttachCloseInfo>;
|
|
106
|
+
detach(): void;
|
|
107
|
+
resize(cols?: number, rows?: number): void;
|
|
108
|
+
}
|
|
109
|
+
export declare class GrokAttachRemoteError extends Error {
|
|
110
|
+
readonly code: string;
|
|
111
|
+
readonly fatal: boolean;
|
|
112
|
+
constructor(frame: GrokAttachErrorFrame);
|
|
113
|
+
}
|
|
114
|
+
export declare function validateGrokAttachSocket(socketPath: string, dependencies?: GrokAttachDependencies): Promise<void>;
|
|
115
|
+
export declare function connectGrokAttach(options: GrokAttachClientOptions): Promise<GrokAttachSession>;
|
|
@@ -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,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>;
|