ds-harness-remote 0.4.1 → 0.4.3

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 (70) hide show
  1. package/README.md +35 -11
  2. package/cordis.patch.yml +3 -0
  3. package/dist/client-runtime.d.ts +28 -0
  4. package/dist/client-runtime.d.ts.map +1 -1
  5. package/dist/client-runtime.js +327 -5
  6. package/dist/client-runtime.js.map +1 -1
  7. package/dist/client-secure-transport.d.ts.map +1 -1
  8. package/dist/client-secure-transport.js +9 -2
  9. package/dist/client-secure-transport.js.map +1 -1
  10. package/dist/client.github.js +167 -48
  11. package/dist/client.js +167 -48
  12. package/dist/client.js.map +1 -1
  13. package/dist/codex/app-server.d.ts +71 -0
  14. package/dist/codex/app-server.d.ts.map +1 -0
  15. package/dist/codex/app-server.js +268 -0
  16. package/dist/codex/app-server.js.map +1 -0
  17. package/dist/codex/domain.d.ts +82 -0
  18. package/dist/codex/domain.d.ts.map +1 -0
  19. package/dist/codex/domain.js +893 -0
  20. package/dist/codex/domain.js.map +1 -0
  21. package/dist/codex/method-policy.d.ts +297 -0
  22. package/dist/codex/method-policy.d.ts.map +1 -0
  23. package/dist/codex/method-policy.js +103 -0
  24. package/dist/codex/method-policy.js.map +1 -0
  25. package/dist/codex/peer-bridge.d.ts +57 -0
  26. package/dist/codex/peer-bridge.d.ts.map +1 -0
  27. package/dist/codex/peer-bridge.js +300 -0
  28. package/dist/codex/peer-bridge.js.map +1 -0
  29. package/dist/codex/virtual-harness.d.ts +178 -0
  30. package/dist/codex/virtual-harness.d.ts.map +1 -0
  31. package/dist/codex/virtual-harness.js +2515 -0
  32. package/dist/codex/virtual-harness.js.map +1 -0
  33. package/dist/config.d.ts +10 -0
  34. package/dist/config.d.ts.map +1 -1
  35. package/dist/config.js +12 -0
  36. package/dist/config.js.map +1 -1
  37. package/dist/control-runtime.d.ts +1 -0
  38. package/dist/control-runtime.d.ts.map +1 -1
  39. package/dist/control-runtime.js +22 -0
  40. package/dist/control-runtime.js.map +1 -1
  41. package/dist/harness-remote-bridge.d.ts +2 -2
  42. package/dist/harness-remote-bridge.d.ts.map +1 -1
  43. package/dist/harness-remote-bridge.js +2 -2
  44. package/dist/harness-remote-bridge.js.map +1 -1
  45. package/dist/index.d.ts +11 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +8550 -3884
  48. package/dist/index.js.map +4 -4
  49. package/dist/remote-typert-gateway.d.ts +1 -1
  50. package/dist/remote-typert-gateway.d.ts.map +1 -1
  51. package/dist/remote-typert-gateway.js +9 -2
  52. package/dist/remote-typert-gateway.js.map +1 -1
  53. package/dist/rpc-router.d.ts +5 -2
  54. package/dist/rpc-router.d.ts.map +1 -1
  55. package/dist/rpc-router.js +30 -1
  56. package/dist/rpc-router.js.map +1 -1
  57. package/dist/server-connection.d.ts +1 -0
  58. package/dist/server-connection.d.ts.map +1 -1
  59. package/dist/server-connection.js +69 -22
  60. package/dist/server-connection.js.map +1 -1
  61. package/dist/service.d.ts +20 -0
  62. package/dist/service.d.ts.map +1 -1
  63. package/dist/service.js +58 -2
  64. package/dist/service.js.map +1 -1
  65. package/dist/typert-gateway-contract.d.ts +2 -2
  66. package/dist/typert-gateway-contract.d.ts.map +1 -1
  67. package/dist/version.d.ts +1 -1
  68. package/dist/version.js +1 -1
  69. package/package.json +19 -23
  70. package/public.d.ts +4 -0
@@ -0,0 +1,268 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { Buffer } from 'node:buffer';
3
+ import { PLUGIN_VERSION } from '../version.js';
4
+ const APP_SERVER_REQUEST_TIMEOUT_MS = 60_000;
5
+ const APP_SERVER_START_TIMEOUT_MS = 15_000;
6
+ const MAX_APP_SERVER_LINE_BYTES = 288 * 1024 * 1024;
7
+ const MAX_STDERR_CAPTURE_BYTES = 4 * 1024;
8
+ export class CodexAppServerError extends Error {
9
+ code;
10
+ constructor(code, message, options) {
11
+ super(message, options);
12
+ this.code = code;
13
+ this.name = 'CodexAppServerError';
14
+ }
15
+ }
16
+ /**
17
+ * Host-local stdio client for one Codex App Server process. This class knows
18
+ * JSON-RPC correlation only; Remote authorization and method policy live in
19
+ * the surrounding Codex domain.
20
+ */
21
+ export class CodexAppServerClient {
22
+ binary;
23
+ logger;
24
+ spawnAppServer;
25
+ process;
26
+ nextId = 1;
27
+ pending = new Map();
28
+ inboundHandlers = new Set();
29
+ unavailableHandlers = new Set();
30
+ stdoutBuffer = Buffer.alloc(0);
31
+ stderrBytes = 0;
32
+ ready = false;
33
+ closed = false;
34
+ failureNotified = false;
35
+ startPromise;
36
+ constructor(binary, logger, spawnAppServer = binary => spawn(binary, ['app-server'], {
37
+ stdio: ['pipe', 'pipe', 'pipe'],
38
+ windowsHide: true,
39
+ })) {
40
+ this.binary = binary;
41
+ this.logger = logger;
42
+ this.spawnAppServer = spawnAppServer;
43
+ }
44
+ start() {
45
+ if (this.closed)
46
+ return Promise.reject(new CodexAppServerError('CODEX_CLOSED', 'The Codex domain is closed.'));
47
+ if (this.ready)
48
+ return Promise.resolve();
49
+ this.startPromise ??= this.startOnce().finally(() => { this.startPromise = undefined; });
50
+ return this.startPromise;
51
+ }
52
+ isReady() { return this.ready; }
53
+ async call(method, params, timeoutMs = APP_SERVER_REQUEST_TIMEOUT_MS) {
54
+ if (!this.ready)
55
+ throw new CodexAppServerError('CODEX_UNAVAILABLE', 'Codex App Server is not ready.');
56
+ return this.request(method, params, timeoutMs);
57
+ }
58
+ async respond(id, result) {
59
+ this.write({ id, result });
60
+ }
61
+ async respondError(id, code, message) {
62
+ this.write({ id, error: { code, message } });
63
+ }
64
+ onInbound(handler) {
65
+ this.inboundHandlers.add(handler);
66
+ return () => this.inboundHandlers.delete(handler);
67
+ }
68
+ onUnavailable(handler) {
69
+ this.unavailableHandlers.add(handler);
70
+ return () => this.unavailableHandlers.delete(handler);
71
+ }
72
+ async close() {
73
+ if (this.closed)
74
+ return;
75
+ this.closed = true;
76
+ this.ready = false;
77
+ this.failPending(new CodexAppServerError('CODEX_CLOSED', 'Codex App Server was closed.'));
78
+ const child = this.process;
79
+ this.process = undefined;
80
+ if (child === undefined || child.exitCode !== null || child.killed)
81
+ return;
82
+ await new Promise(resolve => {
83
+ const timer = setTimeout(() => {
84
+ child.kill('SIGKILL');
85
+ resolve();
86
+ }, 2_000);
87
+ timer.unref?.();
88
+ child.once('exit', () => {
89
+ clearTimeout(timer);
90
+ resolve();
91
+ });
92
+ child.kill('SIGTERM');
93
+ });
94
+ }
95
+ async startOnce() {
96
+ if (this.process !== undefined) {
97
+ throw new CodexAppServerError('CODEX_STARTING', 'Codex App Server is already starting.');
98
+ }
99
+ const child = this.spawnAppServer(this.binary);
100
+ this.process = child;
101
+ this.failureNotified = false;
102
+ this.stdoutBuffer = Buffer.alloc(0);
103
+ this.stderrBytes = 0;
104
+ child.stdout.on('data', chunk => this.consumeStdout(Buffer.from(chunk)));
105
+ child.stderr.on('data', chunk => {
106
+ // Always drain stderr, but never log Codex payloads or paths.
107
+ this.stderrBytes = Math.min(MAX_STDERR_CAPTURE_BYTES, this.stderrBytes + Buffer.byteLength(chunk));
108
+ });
109
+ child.on('error', error => this.handleProcessFailure('CODEX_BINARY_UNAVAILABLE', error));
110
+ child.on('exit', (code, signal) => {
111
+ if (this.process !== child)
112
+ return;
113
+ this.process = undefined;
114
+ this.ready = false;
115
+ this.failPending(new CodexAppServerError('CODEX_APP_SERVER_EXITED', 'Codex App Server exited unexpectedly.'));
116
+ if (!this.closed) {
117
+ this.logger?.warn('Codex App Server exited', {
118
+ code: code ?? 'none',
119
+ signal: signal ?? 'none',
120
+ stderrBytes: this.stderrBytes,
121
+ });
122
+ this.notifyUnavailable('CODEX_APP_SERVER_EXITED');
123
+ }
124
+ });
125
+ try {
126
+ await this.request('initialize', {
127
+ clientInfo: {
128
+ name: 'deepseek_harness_remote',
129
+ title: 'DeepSeek Harness Remote',
130
+ version: PLUGIN_VERSION,
131
+ },
132
+ capabilities: {
133
+ experimentalApi: true,
134
+ mcpServerOpenaiFormElicitation: false,
135
+ },
136
+ }, APP_SERVER_START_TIMEOUT_MS);
137
+ this.write({ method: 'initialized', params: {} });
138
+ this.ready = true;
139
+ this.logger?.info('Codex App Server ready');
140
+ }
141
+ catch (error) {
142
+ child.kill('SIGTERM');
143
+ if (error instanceof CodexAppServerError)
144
+ throw error;
145
+ throw new CodexAppServerError('CODEX_INITIALIZE_FAILED', 'Codex App Server initialization failed.', { cause: error });
146
+ }
147
+ }
148
+ request(method, params, timeoutMs) {
149
+ const id = this.nextId++;
150
+ const result = new Promise((resolve, reject) => {
151
+ const timer = setTimeout(() => {
152
+ this.pending.delete(id);
153
+ reject(new CodexAppServerError('CODEX_REQUEST_TIMEOUT', 'Codex App Server request timed out.'));
154
+ }, timeoutMs);
155
+ timer.unref?.();
156
+ this.pending.set(id, { resolve, reject, timer });
157
+ });
158
+ try {
159
+ this.write({ id, method, params });
160
+ }
161
+ catch (error) {
162
+ const pending = this.takePending(id);
163
+ pending?.reject(error instanceof Error ? error : new Error('Codex App Server write failed.'));
164
+ }
165
+ return result;
166
+ }
167
+ write(message) {
168
+ const child = this.process;
169
+ if (child === undefined || child.stdin.destroyed || !child.stdin.writable) {
170
+ throw new CodexAppServerError('CODEX_UNAVAILABLE', 'Codex App Server is not available.');
171
+ }
172
+ child.stdin.write(`${JSON.stringify(message)}\n`);
173
+ }
174
+ consumeStdout(chunk) {
175
+ this.stdoutBuffer = this.stdoutBuffer.length === 0 ? chunk : Buffer.concat([this.stdoutBuffer, chunk]);
176
+ if (this.stdoutBuffer.length > MAX_APP_SERVER_LINE_BYTES) {
177
+ this.handleProcessFailure('CODEX_RESPONSE_TOO_LARGE', new Error('Codex App Server emitted an oversized JSONL message.'));
178
+ return;
179
+ }
180
+ let newline = this.stdoutBuffer.indexOf(0x0a);
181
+ while (newline >= 0) {
182
+ const line = this.stdoutBuffer.subarray(0, newline);
183
+ this.stdoutBuffer = this.stdoutBuffer.subarray(newline + 1);
184
+ if (line.length > 0)
185
+ this.handleLine(line);
186
+ newline = this.stdoutBuffer.indexOf(0x0a);
187
+ }
188
+ }
189
+ handleLine(line) {
190
+ let value;
191
+ try {
192
+ value = JSON.parse(line.toString('utf8'));
193
+ }
194
+ catch {
195
+ this.handleProcessFailure('CODEX_INVALID_RESPONSE', new Error('Codex App Server emitted invalid JSON.'));
196
+ return;
197
+ }
198
+ if (!isRecord(value)) {
199
+ this.handleProcessFailure('CODEX_INVALID_RESPONSE', new Error('Codex App Server emitted an invalid message.'));
200
+ return;
201
+ }
202
+ if ((typeof value.id === 'number' || typeof value.id === 'string') && ('result' in value || 'error' in value)) {
203
+ const pending = this.takePending(value.id);
204
+ if (pending === undefined)
205
+ return;
206
+ if ('error' in value && value.error !== undefined) {
207
+ pending.reject(new CodexAppServerError('CODEX_UPSTREAM_ERROR', safeUpstreamError(value.error)));
208
+ }
209
+ else {
210
+ pending.resolve(value.result);
211
+ }
212
+ return;
213
+ }
214
+ if (typeof value.method !== 'string' || value.method.length === 0 || value.method.length > 160)
215
+ return;
216
+ const params = value.params ?? {};
217
+ const inbound = typeof value.id === 'string' || typeof value.id === 'number'
218
+ ? { kind: 'request', id: value.id, method: value.method, params }
219
+ : { kind: 'notification', method: value.method, params };
220
+ for (const handler of this.inboundHandlers)
221
+ handler(inbound);
222
+ }
223
+ handleProcessFailure(code, cause) {
224
+ this.ready = false;
225
+ this.failPending(new CodexAppServerError(code, 'Codex App Server communication failed.', { cause }));
226
+ const child = this.process;
227
+ this.process = undefined;
228
+ child?.kill('SIGTERM');
229
+ this.logger?.warn('Codex App Server communication failed', { code });
230
+ if (!this.closed)
231
+ this.notifyUnavailable(code);
232
+ }
233
+ notifyUnavailable(code) {
234
+ if (this.failureNotified)
235
+ return;
236
+ this.failureNotified = true;
237
+ for (const handler of this.unavailableHandlers)
238
+ handler(code);
239
+ }
240
+ takePending(id) {
241
+ const pending = this.pending.get(id);
242
+ if (pending === undefined)
243
+ return undefined;
244
+ this.pending.delete(id);
245
+ clearTimeout(pending.timer);
246
+ return pending;
247
+ }
248
+ failPending(error) {
249
+ for (const id of [...this.pending.keys()])
250
+ this.takePending(id)?.reject(error);
251
+ }
252
+ }
253
+ function safeUpstreamError(value) {
254
+ if (!isRecord(value) || typeof value.message !== 'string')
255
+ return 'Codex App Server rejected the request.';
256
+ // Upstream messages may contain paths or prompt fragments. Only retain a
257
+ // short generic category for the Remote boundary.
258
+ const message = value.message.toLowerCase();
259
+ if (message.includes('active writer'))
260
+ return 'Codex thread already has an active writer.';
261
+ return message.includes('not initialized')
262
+ ? 'Codex App Server is not initialized.'
263
+ : 'Codex App Server rejected the request.';
264
+ }
265
+ function isRecord(value) {
266
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
267
+ }
268
+ //# sourceMappingURL=app-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-server.js","sourceRoot":"","sources":["../../src/codex/app-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAA;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,6BAA6B,GAAG,MAAM,CAAA;AAC5C,MAAM,2BAA2B,GAAG,MAAM,CAAA;AAC1C,MAAM,yBAAyB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA;AACnD,MAAM,wBAAwB,GAAG,CAAC,GAAG,IAAI,CAAA;AAqCzC,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACvB;IAArB,YAAqB,IAAY,EAAE,OAAe,EAAE,OAAsB;QACxE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QADJ,SAAI,GAAJ,IAAI,CAAQ;QAE/B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAcZ;IACA;IACA;IAfX,OAAO,CAAiC;IACxC,MAAM,GAAG,CAAC,CA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AO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC"}
@@ -0,0 +1,82 @@
1
+ import type { CodexAppFrameData, CodexAppStreamClosedData } from '@dsh-remote/protocol';
2
+ import type { ResolvedCodexConfig } from '../config.js';
3
+ import type { PeerConnectionContext } from '../connection-controller.js';
4
+ import type { SafeLogger } from '../logging.js';
5
+ import { type CodexAppServerLike } from './app-server.js';
6
+ import { CodexPeerBridge, type PublishCodexFrame } from './peer-bridge.js';
7
+ type AppServerFactory = (binary: string, logger: SafeLogger) => CodexAppServerLike;
8
+ /**
9
+ * Optional Codex business domain inside the existing Remote Plugin. It shares
10
+ * Remote identity/transport with Harness, but owns its App Server process,
11
+ * method policy, subscriptions, leases, and approval handles.
12
+ */
13
+ export declare class CodexRemoteDomain {
14
+ readonly config: ResolvedCodexConfig;
15
+ private readonly logger;
16
+ private readonly createAppServer;
17
+ private readonly restartDelaysMs;
18
+ private appServer?;
19
+ private unsubscribeInbound?;
20
+ private unsubscribeUnavailable?;
21
+ private readonly peers;
22
+ private readonly turnOwners;
23
+ private readonly approvals;
24
+ private approvalExpiryTimer?;
25
+ private restartTimer?;
26
+ private restartAttempt;
27
+ private available;
28
+ private closed;
29
+ private state;
30
+ private unavailableCode?;
31
+ constructor(config: ResolvedCodexConfig, logger: SafeLogger, createAppServer?: AppServerFactory, restartDelaysMs?: readonly number[]);
32
+ start(): Promise<void>;
33
+ isAvailable(): boolean;
34
+ status(): {
35
+ enabled: boolean;
36
+ available: boolean;
37
+ state: 'disabled' | 'starting' | 'ready' | 'restarting' | 'unavailable';
38
+ restartAttempt: number;
39
+ error?: string;
40
+ };
41
+ createPeer(context: PeerConnectionContext, publish: PublishCodexFrame): CodexPeerBridge | undefined;
42
+ call(connectionId: string, input: unknown): Promise<unknown>;
43
+ respond(connectionId: string, input: unknown): Promise<{
44
+ resolved: true;
45
+ }>;
46
+ detachPeer(connectionId: string): Promise<void>;
47
+ close(): Promise<void>;
48
+ private launchAppServer;
49
+ private launchAppServerCandidate;
50
+ private handleAppServerUnavailable;
51
+ private scheduleRestart;
52
+ private restartAfterFailure;
53
+ private disposeAppServer;
54
+ private handleInbound;
55
+ private handleServerRequest;
56
+ private readKnownThread;
57
+ private readThreadForHistory;
58
+ private readThreadTurns;
59
+ private readThreadItems;
60
+ private logHistoryFallback;
61
+ private assertResultThreadAllowed;
62
+ private claimTurn;
63
+ private hasSubscriber;
64
+ private resolveUpstreamApproval;
65
+ private expireApprovals;
66
+ private scheduleApprovalExpiry;
67
+ private requireAppServer;
68
+ private callUpstream;
69
+ private readProjectAuthority;
70
+ private findKnownThreadInList;
71
+ private requireCodexWorkspacePath;
72
+ private listCodexProjectWorkspacePaths;
73
+ }
74
+ export type CodexDomainFrame = CodexAppFrameData | CodexAppStreamClosedData;
75
+ /**
76
+ * Prefer Codex bundled with the current ChatGPT desktop app on macOS when the
77
+ * user kept the default command. Explicit binary configuration is never
78
+ * rewritten or supplemented.
79
+ */
80
+ export declare function codexBinaryCandidates(configured: string, hostPlatform?: NodeJS.Platform, userHome?: string): string[];
81
+ export {};
82
+ //# sourceMappingURL=domain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/codex/domain.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AACvF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAA;AAOxB,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAsB1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