@myagentroam/node 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/capabilities.d.ts +5 -0
- package/dist/capabilities.js +23 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/claude-agent-sdk.d.ts +101 -0
- package/dist/claude-agent-sdk.js +341 -0
- package/dist/claude-agent-sdk.js.map +1 -0
- package/dist/claude-channel.d.ts +28 -0
- package/dist/claude-channel.js +45 -0
- package/dist/claude-channel.js.map +1 -0
- package/dist/codex-app-server.d.ts +96 -0
- package/dist/codex-app-server.js +361 -0
- package/dist/codex-app-server.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +51 -0
- package/dist/config.js.map +1 -0
- package/dist/connector.d.ts +343 -0
- package/dist/connector.js +5525 -0
- package/dist/connector.js.map +1 -0
- package/dist/database.d.ts +282 -0
- package/dist/database.js +1347 -0
- package/dist/database.js.map +1 -0
- package/dist/event-buffer.d.ts +12 -0
- package/dist/event-buffer.js +29 -0
- package/dist/event-buffer.js.map +1 -0
- package/dist/fake-runner.d.ts +42 -0
- package/dist/fake-runner.js +130 -0
- package/dist/fake-runner.js.map +1 -0
- package/dist/health.d.ts +4 -0
- package/dist/health.js +4 -0
- package/dist/health.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +47 -0
- package/dist/main.js.map +1 -0
- package/dist/native-session-history.d.ts +72 -0
- package/dist/native-session-history.js +647 -0
- package/dist/native-session-history.js.map +1 -0
- package/dist/operational.d.ts +30 -0
- package/dist/operational.js +82 -0
- package/dist/operational.js.map +1 -0
- package/dist/process-tree.d.ts +9 -0
- package/dist/process-tree.js +19 -0
- package/dist/process-tree.js.map +1 -0
- package/dist/runner-command-engine.d.ts +19 -0
- package/dist/runner-command-engine.js +47 -0
- package/dist/runner-command-engine.js.map +1 -0
- package/dist/runner-profiles.d.ts +11 -0
- package/dist/runner-profiles.js +138 -0
- package/dist/runner-profiles.js.map +1 -0
- package/dist/runner-usage.d.ts +33 -0
- package/dist/runner-usage.js +193 -0
- package/dist/runner-usage.js.map +1 -0
- package/dist/runtime-state.d.ts +174 -0
- package/dist/runtime-state.js +957 -0
- package/dist/runtime-state.js.map +1 -0
- package/dist/service.d.ts +4 -0
- package/dist/service.js +39 -0
- package/dist/service.js.map +1 -0
- package/dist/storage.d.ts +2 -0
- package/dist/storage.js +33 -0
- package/dist/storage.js.map +1 -0
- package/dist/terminal.d.ts +132 -0
- package/dist/terminal.js +417 -0
- package/dist/terminal.js.map +1 -0
- package/dist/workspace.d.ts +116 -0
- package/dist/workspace.js +732 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { type NodeCapabilities } from '@myagentroam/protocol';
|
|
2
|
+
import { type NodeConfig } from './config.js';
|
|
3
|
+
import { FakeRunner, type FakeRunnerStep } from './fake-runner.js';
|
|
4
|
+
import { CodexAppServerClient } from './codex-app-server.js';
|
|
5
|
+
import { ClaudeAgentSdkAdapter } from './claude-agent-sdk.js';
|
|
6
|
+
import { NodeDatabase } from './database.js';
|
|
7
|
+
import { TerminalManager } from './terminal.js';
|
|
8
|
+
import { RunnerUsageReader } from './runner-usage.js';
|
|
9
|
+
export declare function nextReconnectDelay(attempt: number): number;
|
|
10
|
+
export interface NodeConnectorOptions {
|
|
11
|
+
readonly configPath?: string;
|
|
12
|
+
readonly config?: NodeConfig;
|
|
13
|
+
readonly capabilities?: NodeCapabilities;
|
|
14
|
+
readonly reconnect?: boolean;
|
|
15
|
+
/** Test injection only; production capability reporting remains unchanged. */
|
|
16
|
+
readonly fakeRunner?: FakeRunner;
|
|
17
|
+
readonly fakeScript?: (input: unknown, runId: string) => readonly FakeRunnerStep[];
|
|
18
|
+
readonly codexClient?: CodexAppServerClient;
|
|
19
|
+
/** Test injection only; the default uses the official Claude Agent SDK. */
|
|
20
|
+
readonly claudeClient?: ClaudeAgentSdkAdapter;
|
|
21
|
+
/** Test injection; production opens the SQLite path from NodeConfig. */
|
|
22
|
+
readonly database?: NodeDatabase;
|
|
23
|
+
/** Test-only override. Production approvals always have a ten-minute expiry. */
|
|
24
|
+
readonly claudeApprovalTimeoutMs?: number;
|
|
25
|
+
/** Test injection; production uses node-pty/ConPTY through TerminalManager. */
|
|
26
|
+
readonly terminalManager?: TerminalManager;
|
|
27
|
+
/** Test injection; production reads OAuth credentials only on the local Node. */
|
|
28
|
+
readonly runnerUsageReader?: RunnerUsageReader;
|
|
29
|
+
}
|
|
30
|
+
export declare class NodeConnector {
|
|
31
|
+
private socket;
|
|
32
|
+
private terminalSocket;
|
|
33
|
+
private heartbeat;
|
|
34
|
+
private reconnectTimer;
|
|
35
|
+
private terminalReconnectTimer;
|
|
36
|
+
private attempts;
|
|
37
|
+
private stopped;
|
|
38
|
+
private config;
|
|
39
|
+
private readonly capabilities;
|
|
40
|
+
private readonly configPath;
|
|
41
|
+
private readonly reconnect;
|
|
42
|
+
private readonly claudeApprovalTimeoutMs;
|
|
43
|
+
private readonly eventBuffer;
|
|
44
|
+
/** A global sequence lets one Admin page merge every business callback. */
|
|
45
|
+
private workbenchEventSequence;
|
|
46
|
+
/** Bounded process-local history used only to bridge a browser reconnect. */
|
|
47
|
+
private readonly workbenchEvents;
|
|
48
|
+
private readonly fakeRunner;
|
|
49
|
+
private readonly fakeScript;
|
|
50
|
+
private readonly runSequences;
|
|
51
|
+
/** Coalesce token-sized assistant deltas before persisting and relaying them. */
|
|
52
|
+
private readonly pendingTextDeltas;
|
|
53
|
+
private readonly activeRuns;
|
|
54
|
+
private readonly interruptRequestedRuns;
|
|
55
|
+
/** Pending turn inputs are memory-only, as are the queue records themselves. */
|
|
56
|
+
private readonly queuedRunStarts;
|
|
57
|
+
/** Bootstrap IDs never cross HTTP or Workbench event boundaries. */
|
|
58
|
+
private readonly bootstrapSessionIds;
|
|
59
|
+
private readonly nativeSessionIdentityWaiters;
|
|
60
|
+
private readonly nativeSessionStarts;
|
|
61
|
+
/** One background Claude control probe per native session; never persisted. */
|
|
62
|
+
private readonly pendingClaudeContextReads;
|
|
63
|
+
/** A completed probe is kept briefly so the next polling request can render it. */
|
|
64
|
+
private readonly completedClaudeContextReads;
|
|
65
|
+
/** Session-scoped second-stop windows; sessions in one Workspace are independent. */
|
|
66
|
+
private readonly queuePauseWindows;
|
|
67
|
+
/** Ephemeral Codex localImage files; never persisted with a Session or Workspace. */
|
|
68
|
+
private readonly runAttachmentDirectories;
|
|
69
|
+
private readonly codexClient;
|
|
70
|
+
private readonly codexRuns;
|
|
71
|
+
/** App Server turn ID → current-process managed Run; never persisted. */
|
|
72
|
+
private readonly managedCodexTurns;
|
|
73
|
+
private readonly codexApprovals;
|
|
74
|
+
private readonly codexUserInputs;
|
|
75
|
+
private readonly claudeClient;
|
|
76
|
+
private readonly claudeRuns;
|
|
77
|
+
/** Native IDs currently associated with a process-local managed Claude session. */
|
|
78
|
+
private readonly managedClaudeSessions;
|
|
79
|
+
/** Native IDs observed from an SDK-resumed Claude stream, kept process-local. */
|
|
80
|
+
private readonly managedClaudeSessionByNativeId;
|
|
81
|
+
/** Read-only native discovery cache; never persisted to SQLite. */
|
|
82
|
+
private readonly directNativeSessions;
|
|
83
|
+
/** Official Codex thread status, refreshed only in process and never persisted. */
|
|
84
|
+
private readonly codexExternalActivity;
|
|
85
|
+
/** Browser-renewed read-only native-session watches; never persisted. */
|
|
86
|
+
private readonly sessionWatches;
|
|
87
|
+
/** Maps a direct external projection to its process-local resumed session for message retries. */
|
|
88
|
+
private readonly resumedSessionByDirectId;
|
|
89
|
+
/** Last rejected explicit takeover reason for an external direct projection. */
|
|
90
|
+
private readonly externalResumeFailures;
|
|
91
|
+
/** Bounded Runner diagnostic paired with a fixed external resume reason code. */
|
|
92
|
+
private readonly externalResumeFailureDetails;
|
|
93
|
+
private readonly claudeApprovals;
|
|
94
|
+
private readonly commandStates;
|
|
95
|
+
private readonly runnerUsageReader;
|
|
96
|
+
private codexFastEnabled;
|
|
97
|
+
private readonly terminalManager;
|
|
98
|
+
private readonly terminalAttachments;
|
|
99
|
+
/** Uploads are process-local like runs; Node restart intentionally cancels them. */
|
|
100
|
+
private readonly workspaceUploads;
|
|
101
|
+
/** Completed Composer files are process-local references, never SQLite state. */
|
|
102
|
+
private readonly composerAttachments;
|
|
103
|
+
/** Identical refreshes share one Git scan; separate Workspaces use bounded parallelism. */
|
|
104
|
+
private readonly workspaceChangesReads;
|
|
105
|
+
private readonly workspaceChangesLimiter;
|
|
106
|
+
private database;
|
|
107
|
+
/** Runtime/session state is intentionally not persisted to Node SQLite. */
|
|
108
|
+
private readonly runtime;
|
|
109
|
+
private readonly metrics;
|
|
110
|
+
constructor(options?: NodeConnectorOptions);
|
|
111
|
+
start(): Promise<void>;
|
|
112
|
+
stop(): void;
|
|
113
|
+
private connect;
|
|
114
|
+
private scheduleReconnect;
|
|
115
|
+
/**
|
|
116
|
+
* Terminal bytes never share the control socket. This connection has a
|
|
117
|
+
* deliberately tiny local envelope and can only authenticate, bind an
|
|
118
|
+
* attachment already authorized on the control channel, or carry terminal
|
|
119
|
+
* frames for that binding.
|
|
120
|
+
*/
|
|
121
|
+
private connectTerminal;
|
|
122
|
+
private scheduleTerminalReconnect;
|
|
123
|
+
private handleTerminalMessage;
|
|
124
|
+
private publishTerminalFrame;
|
|
125
|
+
private sendTerminalFrame;
|
|
126
|
+
private sendTerminal;
|
|
127
|
+
private handleMessage;
|
|
128
|
+
private connected;
|
|
129
|
+
/** Executes only the closed Admin-facing operation set forwarded by Server. */
|
|
130
|
+
private handleNodeRequest;
|
|
131
|
+
private executeNodeOperation;
|
|
132
|
+
private requireWorkspace;
|
|
133
|
+
private fileAccessOptions;
|
|
134
|
+
private listFilesForWorkspace;
|
|
135
|
+
private readFileForWorkspace;
|
|
136
|
+
private searchFilesForWorkspace;
|
|
137
|
+
private preflightWorkspaceUploads;
|
|
138
|
+
private createWorkspaceUpload;
|
|
139
|
+
private writeWorkspaceUploadChunk;
|
|
140
|
+
private workspaceUploadStatus;
|
|
141
|
+
private completeWorkspaceUpload;
|
|
142
|
+
private cancelWorkspaceUpload;
|
|
143
|
+
private requireWorkspaceUpload;
|
|
144
|
+
private removeWorkspaceUpload;
|
|
145
|
+
private composerAttachmentTarget;
|
|
146
|
+
private resolveComposerAttachments;
|
|
147
|
+
private currentChangesForWorkspace;
|
|
148
|
+
private persistTerminalSession;
|
|
149
|
+
/**
|
|
150
|
+
* Discovers only the Codex sources that App Server itself identifies as CLI
|
|
151
|
+
* or VS Code. Discovery reads native history but never copies it into MAR's
|
|
152
|
+
* message table and never grants write control.
|
|
153
|
+
*/
|
|
154
|
+
private discoverCodexSessions;
|
|
155
|
+
private directClaudeSessions;
|
|
156
|
+
private listDirectNativeSessions;
|
|
157
|
+
private resolveDirectNativeSession;
|
|
158
|
+
/**
|
|
159
|
+
* A rename is Node-local metadata, so an external transcript receives a
|
|
160
|
+
* process-local projection without resuming or taking control of its Runner.
|
|
161
|
+
*/
|
|
162
|
+
private createMetadataProjection;
|
|
163
|
+
/**
|
|
164
|
+
* Native Runner history does not reliably expose the Composer settings that
|
|
165
|
+
* should govern MAR's next Turn. A resumed projection therefore keeps an
|
|
166
|
+
* already-valid local choice, otherwise takes this Runner's saved Node
|
|
167
|
+
* default. Defaults never cross Runner boundaries.
|
|
168
|
+
*/
|
|
169
|
+
private resumedSessionConfiguration;
|
|
170
|
+
private ensureResumedSessionConfiguration;
|
|
171
|
+
private rememberDirectNativeSessions;
|
|
172
|
+
/** Returns exact native IDs of a managed Session, including verified Claude aliases only. */
|
|
173
|
+
private nativeSessionIdsForProjection;
|
|
174
|
+
/** Clears only projections proven to represent the just-deleted native transcripts. */
|
|
175
|
+
private forgetNativeSessionProjection;
|
|
176
|
+
private readDirectNativeHistory;
|
|
177
|
+
private readConversationHistoryPage;
|
|
178
|
+
private conversationHistoryPage;
|
|
179
|
+
private readOfficialCodexConversation;
|
|
180
|
+
private managedCodexTurn;
|
|
181
|
+
private refreshCodexExternalActivity;
|
|
182
|
+
private watchNativeSession;
|
|
183
|
+
private stopNativeSessionWatch;
|
|
184
|
+
private refreshWatchedSession;
|
|
185
|
+
private performWatchedSessionRefresh;
|
|
186
|
+
/**
|
|
187
|
+
* Resumes only an externally idle Codex thread. The final official read is
|
|
188
|
+
* intentionally adjacent to resume so an external active turn can never be
|
|
189
|
+
* raced into a MAR-controlled message.
|
|
190
|
+
*/
|
|
191
|
+
private resumeExternalCodexSession;
|
|
192
|
+
/**
|
|
193
|
+
* Claude's SDK has no cross-process activity status. A visible CLI history
|
|
194
|
+
* is therefore resumable on first message, but only after `sessionInfo`
|
|
195
|
+
* verifies the exact native ID and cwd. The map makes retries idempotently
|
|
196
|
+
* target the same process-local managed projection.
|
|
197
|
+
*/
|
|
198
|
+
private resumeExternalClaudeSession;
|
|
199
|
+
private clearExternalResumeFailure;
|
|
200
|
+
private setExternalResumeFailure;
|
|
201
|
+
private externalResumeFailure;
|
|
202
|
+
private resolveSessionForMessage;
|
|
203
|
+
private directNativeSession;
|
|
204
|
+
/** DB caches confirmed Codex names and shields a pending rename from stale discovery results. */
|
|
205
|
+
private nativeSessionRunnerTitle;
|
|
206
|
+
/** Runner-specific title persistence: Codex owns its thread name; Claude metadata is Node-local. */
|
|
207
|
+
private renameRunnerSession;
|
|
208
|
+
/**
|
|
209
|
+
* External sessions are followed from their append-only local transcript.
|
|
210
|
+
* A managed active Run is intentionally excluded: its durable projection is
|
|
211
|
+
* fed by the Runner event stream and is therefore the live authority.
|
|
212
|
+
*/
|
|
213
|
+
private hasManagedActiveRun;
|
|
214
|
+
private syncExternalTranscript;
|
|
215
|
+
private startFakeRun;
|
|
216
|
+
private startCodexRun;
|
|
217
|
+
private startClaudeRun;
|
|
218
|
+
private deliverClaudeChannelMessage;
|
|
219
|
+
/**
|
|
220
|
+
* `STEERED` means that the SDK AsyncIterable consumed the message, rather
|
|
221
|
+
* than merely accepting it into a Node-side queue. Reusing a client message
|
|
222
|
+
* ID is idempotent and never writes a second input to Claude.
|
|
223
|
+
*/
|
|
224
|
+
private deliverClaudeChannel;
|
|
225
|
+
private cancelCodexTurn;
|
|
226
|
+
private respondCodexUserInput;
|
|
227
|
+
/** Returns true when cancellation already made this Run terminal. */
|
|
228
|
+
private completeCancelledRun;
|
|
229
|
+
private presentSession;
|
|
230
|
+
/**
|
|
231
|
+
* Discovery always keeps the native record in the local cache so a stale
|
|
232
|
+
* direct ID remains readable, but the response must not reintroduce it in
|
|
233
|
+
* the Workbench once this process has already resumed that native session.
|
|
234
|
+
*/
|
|
235
|
+
private presentDiscoveredSessions;
|
|
236
|
+
/**
|
|
237
|
+
* Claude can report a native session ID distinct from the ID used to start
|
|
238
|
+
* a verified resume. Keep that observed ID as a process-local alias of the
|
|
239
|
+
* same managed projection, without treating a `conversation_reset` ID as
|
|
240
|
+
* an alias.
|
|
241
|
+
*/
|
|
242
|
+
private rememberManagedClaudeNativeSession;
|
|
243
|
+
/**
|
|
244
|
+
* Refresh the title once this Claude Session's own turn has flushed its
|
|
245
|
+
* native transcript. `externalSessionId` originates from that managed
|
|
246
|
+
* stream, never from a title-based discovery match.
|
|
247
|
+
*/
|
|
248
|
+
private syncManagedClaudeRunnerTitle;
|
|
249
|
+
/**
|
|
250
|
+
* Resolves a native discovery record only to its exact managed projection:
|
|
251
|
+
* same runner, same Workspace and same native Session ID. Claude's only
|
|
252
|
+
* exception is a Session ID observed from that managed SDK resume stream.
|
|
253
|
+
* A title is never an identity or matching input.
|
|
254
|
+
*/
|
|
255
|
+
private managedSessionForNativeRecord;
|
|
256
|
+
/**
|
|
257
|
+
* A custom-title projection can be external, but must still match the same
|
|
258
|
+
* native identity so session polling neither restores the old title nor
|
|
259
|
+
* inserts a duplicate direct record.
|
|
260
|
+
*/
|
|
261
|
+
private sessionProjectionForNativeRecord;
|
|
262
|
+
private isManagedProjectionForNativeRecord;
|
|
263
|
+
/**
|
|
264
|
+
* Context occupancy is an observed Runner fact. Codex persists its latest
|
|
265
|
+
* prompt/window pair in the native transcript; Claude exposes it through
|
|
266
|
+
* the official SDK control channel. Neither path estimates tokens in MAR.
|
|
267
|
+
*/
|
|
268
|
+
private readSessionContextUsage;
|
|
269
|
+
private probeClaudeContextUsage;
|
|
270
|
+
/** Executes only Node-declared interactions; the browser never supplies behavior. */
|
|
271
|
+
private executeRunnerCommand;
|
|
272
|
+
/** Claude `/compact` is a native SDK command, represented as a Run but never as a user bubble. */
|
|
273
|
+
private startClaudeCompaction;
|
|
274
|
+
/** Compaction is an App Server Turn, so keep a normal Run lifecycle for the Web spinner. */
|
|
275
|
+
private startCodexCompaction;
|
|
276
|
+
private runnerProfiles;
|
|
277
|
+
private workbenchManifest;
|
|
278
|
+
private resumeDelivery;
|
|
279
|
+
private requestClaudeApproval;
|
|
280
|
+
/**
|
|
281
|
+
* An approval is an individual Runner callback. Keep its exact payload in
|
|
282
|
+
* the process-local snapshot and emit a Run event so an already open
|
|
283
|
+
* Workbench refreshes immediately instead of waiting for a page reload.
|
|
284
|
+
*/
|
|
285
|
+
private publishApprovalRequest;
|
|
286
|
+
private emitRunEvent;
|
|
287
|
+
private enqueueTextDelta;
|
|
288
|
+
private flushTextDelta;
|
|
289
|
+
private emitRunEventNow;
|
|
290
|
+
/**
|
|
291
|
+
* Browser callbacks are multiplexed on one Admin Workbench connection. The
|
|
292
|
+
* Server adds the Node identity and never interprets this business payload.
|
|
293
|
+
*/
|
|
294
|
+
private emitWorkbenchEvent;
|
|
295
|
+
private workbenchPayloadSessionId;
|
|
296
|
+
private emitWorkspaceQueue;
|
|
297
|
+
/** Promote every Connector-owned Session key together with Runtime state. */
|
|
298
|
+
private promoteManagedSessionIdentity;
|
|
299
|
+
private waitForNativeSessionIdentity;
|
|
300
|
+
private rejectBootstrapSessionIdentity;
|
|
301
|
+
/**
|
|
302
|
+
* Shared replacement primitive for Ctrl+Enter and queue "execute now".
|
|
303
|
+
* The queued Run remains authoritative until the interrupted Run emits its
|
|
304
|
+
* terminal event and releases the Session lease.
|
|
305
|
+
*/
|
|
306
|
+
private replaceCurrentRunWithQueued;
|
|
307
|
+
private dispatchSessionQueue;
|
|
308
|
+
/** Let the operation response leave the Node before Runner callbacks can close or flood the socket. */
|
|
309
|
+
private scheduleSessionQueueDispatch;
|
|
310
|
+
private presentWorkspaceQueue;
|
|
311
|
+
private openQueuePauseWindow;
|
|
312
|
+
private clearQueuePauseWindow;
|
|
313
|
+
private materializeCodexAttachments;
|
|
314
|
+
/**
|
|
315
|
+
* Non-image Composer files are intentionally Workspace-visible so both
|
|
316
|
+
* runners can read the exact bytes with their normal file tools. Unlike
|
|
317
|
+
* Codex localImage files, these are not deleted on Run completion.
|
|
318
|
+
*/
|
|
319
|
+
private persistNonImageAttachments;
|
|
320
|
+
private cleanupRunAttachments;
|
|
321
|
+
/** Image bytes never enter conversation history. Keep them Node-local for one hour after Run end. */
|
|
322
|
+
private readonly runImageCache;
|
|
323
|
+
private cacheRunImages;
|
|
324
|
+
private readRunImage;
|
|
325
|
+
private expireRunImageCacheAfterTtl;
|
|
326
|
+
private clearRunImageCache;
|
|
327
|
+
/**
|
|
328
|
+
* Only send a bounded, user-readable projection. Raw SDK/JSON-RPC records
|
|
329
|
+
* and hidden reasoning must never cross this boundary into the Workbench.
|
|
330
|
+
*/
|
|
331
|
+
private emitConversationItem;
|
|
332
|
+
private handleCodexNotification;
|
|
333
|
+
private reconcileRuns;
|
|
334
|
+
/** A process restart cannot safely reattach a native in-flight SDK stream. */
|
|
335
|
+
private reconcilePersistedRuns;
|
|
336
|
+
private inspectWorkspace;
|
|
337
|
+
private captureRunSnapshot;
|
|
338
|
+
private send;
|
|
339
|
+
private sendEnvelope;
|
|
340
|
+
}
|
|
341
|
+
export declare function validatedCapabilities(value: unknown): NodeCapabilities;
|
|
342
|
+
export declare function nodeConnectEndpoint(serverUrl: string): string;
|
|
343
|
+
export declare function nodeTerminalConnectEndpoint(serverUrl: string): string;
|