@excitedjs/agent-runtime-codex 0.2.0-alpha.g0ddd418597ca
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/approval.d.ts +30 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +42 -0
- package/dist/approval.js.map +1 -0
- package/dist/args.d.ts +55 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +113 -0
- package/dist/args.js.map +1 -0
- package/dist/bin.d.ts +14 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +18 -0
- package/dist/bin.js.map +1 -0
- package/dist/codex-home.d.ts +42 -0
- package/dist/codex-home.d.ts.map +1 -0
- package/dist/codex-home.js +112 -0
- package/dist/codex-home.js.map +1 -0
- package/dist/config.d.ts +76 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +106 -0
- package/dist/config.js.map +1 -0
- package/dist/diagnostic.d.ts +14 -0
- package/dist/diagnostic.d.ts.map +1 -0
- package/dist/diagnostic.js +58 -0
- package/dist/diagnostic.js.map +1 -0
- package/dist/events.d.ts +88 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +225 -0
- package/dist/events.js.map +1 -0
- package/dist/handshake.d.ts +44 -0
- package/dist/handshake.d.ts.map +1 -0
- package/dist/handshake.js +85 -0
- package/dist/handshake.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/completion-body.d.ts +38 -0
- package/dist/internal/completion-body.d.ts.map +1 -0
- package/dist/internal/completion-body.js +62 -0
- package/dist/internal/completion-body.js.map +1 -0
- package/dist/internal/config-validate.d.ts +23 -0
- package/dist/internal/config-validate.d.ts.map +1 -0
- package/dist/internal/config-validate.js +122 -0
- package/dist/internal/config-validate.js.map +1 -0
- package/dist/internal/os.d.ts +30 -0
- package/dist/internal/os.d.ts.map +1 -0
- package/dist/internal/os.js +81 -0
- package/dist/internal/os.js.map +1 -0
- package/dist/internal/socket.d.ts +23 -0
- package/dist/internal/socket.d.ts.map +1 -0
- package/dist/internal/socket.js +74 -0
- package/dist/internal/socket.js.map +1 -0
- package/dist/internal/turn-render.d.ts +22 -0
- package/dist/internal/turn-render.d.ts.map +1 -0
- package/dist/internal/turn-render.js +40 -0
- package/dist/internal/turn-render.js.map +1 -0
- package/dist/mcp-config.d.ts +9 -0
- package/dist/mcp-config.d.ts.map +1 -0
- package/dist/mcp-config.js +21 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/paths.d.ts +7 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +26 -0
- package/dist/paths.js.map +1 -0
- package/dist/provider-ref.d.ts +8 -0
- package/dist/provider-ref.d.ts.map +1 -0
- package/dist/provider-ref.js +8 -0
- package/dist/provider-ref.js.map +1 -0
- package/dist/provider.d.ts +71 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +137 -0
- package/dist/provider.js.map +1 -0
- package/dist/rpc.d.ts +65 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +200 -0
- package/dist/rpc.js.map +1 -0
- package/dist/runtime-support.d.ts +27 -0
- package/dist/runtime-support.d.ts.map +1 -0
- package/dist/runtime-support.js +57 -0
- package/dist/runtime-support.js.map +1 -0
- package/dist/runtime.d.ts +246 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +648 -0
- package/dist/runtime.js.map +1 -0
- package/dist/supervisor.d.ts +55 -0
- package/dist/supervisor.d.ts.map +1 -0
- package/dist/supervisor.js +183 -0
- package/dist/supervisor.js.map +1 -0
- package/dist/turn-manager.d.ts +92 -0
- package/dist/turn-manager.d.ts.map +1 -0
- package/dist/turn-manager.js +271 -0
- package/dist/turn-manager.js.map +1 -0
- package/dist/types.d.ts +143 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +16 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +33 -0
- package/dist/version.js.map +1 -0
- package/package.json +56 -0
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex app-server WebSocket JSON-RPC client.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from claudemux's `plugins/claudemux/core/src/engines/codex/rpc.ts`
|
|
5
|
+
* (excitedjs/dreamux#2 §"关键代码复用结论"). Two differences:
|
|
6
|
+
* - uses the public `ws` npm package instead of the vendored `#ws`;
|
|
7
|
+
* - replaces the `codex-protocol` import with the in-tree `./types.ts`.
|
|
8
|
+
*
|
|
9
|
+
* The wire envelope codex emits is *not* strict JSON-RPC 2.0 — the
|
|
10
|
+
* `jsonrpc` version field is omitted. Frame routing is by structural probe:
|
|
11
|
+
* - method + id + params → request
|
|
12
|
+
* - method + params → notification
|
|
13
|
+
* - id + result|error → response
|
|
14
|
+
*/
|
|
15
|
+
import WebSocket from 'ws';
|
|
16
|
+
/**
|
|
17
|
+
* A long-running WebSocket connection to one codex app-server daemon.
|
|
18
|
+
* One instance per Dispatcher; lifetime matches the dispatcher runtime.
|
|
19
|
+
*/
|
|
20
|
+
export class CodexWsClient {
|
|
21
|
+
ws;
|
|
22
|
+
pending = new Map();
|
|
23
|
+
notifHandlers = [];
|
|
24
|
+
closeHandlers = [];
|
|
25
|
+
serverReqHandler = async () => {
|
|
26
|
+
throw new Error('codex sent a server-request but no handler is installed. ' +
|
|
27
|
+
'Install one via setServerRequestHandler() before driving turns. ' +
|
|
28
|
+
'See issue #2 §"信任模型" — approval handlers must fail loudly, not return null.');
|
|
29
|
+
};
|
|
30
|
+
nextId = 1;
|
|
31
|
+
opened;
|
|
32
|
+
closed = false;
|
|
33
|
+
closeReason = null;
|
|
34
|
+
constructor(opts) {
|
|
35
|
+
// `perMessageDeflate: false` is load-bearing — the codex app-server's
|
|
36
|
+
// WebSocket upgrade is strict about Sec-WebSocket-Extensions and would
|
|
37
|
+
// reject the `ws` package's default permessage-deflate proposal.
|
|
38
|
+
// Verified empirically against codex 0.133.0 by claudemux.
|
|
39
|
+
const wsOpts = { perMessageDeflate: false };
|
|
40
|
+
if (opts.socketPath !== undefined) {
|
|
41
|
+
this.ws = new WebSocket(`ws+unix://${opts.socketPath}`, wsOpts);
|
|
42
|
+
}
|
|
43
|
+
else if (opts.url !== undefined) {
|
|
44
|
+
this.ws = new WebSocket(opts.url, wsOpts);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new Error('CodexWsClient: socketPath or url required');
|
|
48
|
+
}
|
|
49
|
+
this.opened = new Promise((res, rej) => {
|
|
50
|
+
this.ws.once('open', () => res());
|
|
51
|
+
this.ws.once('error', (e) => rej(e instanceof Error ? e : new Error(String(e))));
|
|
52
|
+
});
|
|
53
|
+
this.ws.on('message', (data) => this.onFrame(data));
|
|
54
|
+
this.ws.on('close', () => this.tearDown(new Error('codex daemon closed the connection')));
|
|
55
|
+
this.ws.on('error', (e) => this.tearDown(e instanceof Error ? e : new Error(String(e))));
|
|
56
|
+
}
|
|
57
|
+
ready() {
|
|
58
|
+
return this.opened;
|
|
59
|
+
}
|
|
60
|
+
onNotification(handler) {
|
|
61
|
+
this.notifHandlers.push(handler);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Install handler for server→client requests (approval, attestation, etc).
|
|
65
|
+
* The handler's return value becomes the response `result`; a throw becomes
|
|
66
|
+
* the response `error.message`.
|
|
67
|
+
*
|
|
68
|
+
* For dreamux MVP this should fail-fast on any approval request — see
|
|
69
|
+
* issue #2 §"信任模型" (approval-policy=never + fail-fast handler).
|
|
70
|
+
*/
|
|
71
|
+
setServerRequestHandler(handler) {
|
|
72
|
+
this.serverReqHandler = handler;
|
|
73
|
+
}
|
|
74
|
+
onClose(handler) {
|
|
75
|
+
if (this.closed) {
|
|
76
|
+
handler(this.closeReason ?? new Error('codex client closed'));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this.closeHandlers.push(handler);
|
|
80
|
+
}
|
|
81
|
+
request(method, params) {
|
|
82
|
+
if (this.closed) {
|
|
83
|
+
return Promise.reject(this.closeReason ?? new Error('codex client closed'));
|
|
84
|
+
}
|
|
85
|
+
const id = this.nextId++;
|
|
86
|
+
const envelope = { method, id, params };
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
this.pending.set(id, {
|
|
89
|
+
resolve: resolve,
|
|
90
|
+
reject,
|
|
91
|
+
});
|
|
92
|
+
try {
|
|
93
|
+
this.ws.send(JSON.stringify(envelope));
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
this.pending.delete(id);
|
|
97
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Send a JSON-RPC notification (no `id`, no response expected). codex 0.134+
|
|
103
|
+
* uses these for the `initialized` handshake confirmation, among others.
|
|
104
|
+
*/
|
|
105
|
+
notify(method, params) {
|
|
106
|
+
if (this.closed) {
|
|
107
|
+
throw this.closeReason ?? new Error('codex client closed');
|
|
108
|
+
}
|
|
109
|
+
const envelope = { method, params };
|
|
110
|
+
this.ws.send(JSON.stringify(envelope));
|
|
111
|
+
}
|
|
112
|
+
close() {
|
|
113
|
+
this.tearDown(new Error('codex client closed by caller'));
|
|
114
|
+
this.ws.terminate();
|
|
115
|
+
}
|
|
116
|
+
onFrame(data) {
|
|
117
|
+
let parsed;
|
|
118
|
+
try {
|
|
119
|
+
const text = typeof data === 'string' ? data : data.toString('utf8');
|
|
120
|
+
parsed = JSON.parse(text);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
this.tearDown(new Error(`codex daemon sent a non-JSON frame: ${e.message}`));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
127
|
+
this.tearDown(new Error('codex daemon sent a non-object envelope'));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const env = parsed;
|
|
131
|
+
const hasMethod = typeof env['method'] === 'string';
|
|
132
|
+
const hasId = typeof env['id'] === 'number';
|
|
133
|
+
const hasResult = 'result' in env;
|
|
134
|
+
const hasError = 'error' in env;
|
|
135
|
+
if (hasMethod && hasId) {
|
|
136
|
+
this.handleServerRequest(env).catch((err) => this.tearDown(err instanceof Error ? err : new Error(String(err))));
|
|
137
|
+
}
|
|
138
|
+
else if (hasMethod) {
|
|
139
|
+
this.dispatchNotification(env);
|
|
140
|
+
}
|
|
141
|
+
else if (hasId && (hasResult || hasError)) {
|
|
142
|
+
this.handleResponse(env);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.tearDown(new Error('codex daemon sent envelope with neither id nor method'));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
handleResponse(env) {
|
|
149
|
+
const pending = this.pending.get(env.id);
|
|
150
|
+
if (pending === undefined)
|
|
151
|
+
return;
|
|
152
|
+
this.pending.delete(env.id);
|
|
153
|
+
if ('error' in env) {
|
|
154
|
+
pending.reject(new Error(env.error.message));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
pending.resolve(env.result);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
dispatchNotification(notif) {
|
|
161
|
+
for (const h of this.notifHandlers) {
|
|
162
|
+
try {
|
|
163
|
+
h(notif);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Handler throws must not poison the dispatch loop.
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async handleServerRequest(env) {
|
|
171
|
+
try {
|
|
172
|
+
const result = await this.serverReqHandler(env);
|
|
173
|
+
const reply = { id: env.id, result };
|
|
174
|
+
this.ws.send(JSON.stringify(reply));
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
178
|
+
const reply = { id: env.id, error: { message } };
|
|
179
|
+
this.ws.send(JSON.stringify(reply));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
tearDown(reason) {
|
|
183
|
+
if (this.closed)
|
|
184
|
+
return;
|
|
185
|
+
this.closed = true;
|
|
186
|
+
this.closeReason = reason;
|
|
187
|
+
for (const { reject } of this.pending.values())
|
|
188
|
+
reject(reason);
|
|
189
|
+
this.pending.clear();
|
|
190
|
+
for (const handler of this.closeHandlers) {
|
|
191
|
+
try {
|
|
192
|
+
handler(reason);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Close observers are cleanup hooks; one throw must not mask teardown.
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=rpc.js.map
|
package/dist/rpc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,SAA2B,MAAM,IAAI,CAAC;AAsB7C;;;GAGG;AACH,MAAM,OAAO,aAAa;IACP,EAAE,CAAY;IACd,OAAO,GAAG,IAAI,GAAG,EAG/B,CAAC;IACa,aAAa,GAA0B,EAAE,CAAC;IAC1C,aAAa,GAAmB,EAAE,CAAC;IAC5C,gBAAgB,GAAyB,KAAK,IAAI,EAAE;QAC1D,MAAM,IAAI,KAAK,CACb,2DAA2D;YACzD,kEAAkE;YAClE,6EAA6E,CAChF,CAAC;IACJ,CAAC,CAAC;IACM,MAAM,GAAG,CAAC,CAAC;IACF,MAAM,CAAgB;IAC/B,MAAM,GAAG,KAAK,CAAC;IACf,WAAW,GAAiB,IAAI,CAAC;IAEzC,YAAY,IAA0B;QACpC,sEAAsE;QACtE,uEAAuE;QACvE,iEAAiE;QACjE,2DAA2D;QAC3D,MAAM,MAAM,GAAG,EAAE,iBAAiB,EAA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CAAC;IACH,CAAC;IAEO,QAAQ,CAAC,MAAa;QAC5B,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACzC,IAAI,CAAC;gBACH,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC;YAAC,MAAM,CAAC;gBACP,uEAAuE;YACzE,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CompletionEnvelope } from '@excitedjs/dreamux-types';
|
|
2
|
+
/**
|
|
3
|
+
* Build the process env for a Codex app-server child. The neutral env boundary
|
|
4
|
+
* (issue #209 cleanup) is `{ ...process.env, ...injectEnv, ...extraEnv }`:
|
|
5
|
+
* - `injectEnv` is the host's optional neutral env-injection seam from the
|
|
6
|
+
* create context (empty today); core owns what it injects.
|
|
7
|
+
* - `extraEnv` is THIS provider's own `config.extra_env`, merged last so a
|
|
8
|
+
* dispatcher can override an injected value.
|
|
9
|
+
* The child inherits the operator's ambient `CODEX_HOME` like a vanilla
|
|
10
|
+
* `codex` invocation — Dreamux creates no dispatcher-private Codex home (MVP),
|
|
11
|
+
* so there is nothing to strip.
|
|
12
|
+
*/
|
|
13
|
+
export declare function codexProcessEnv(injectEnv?: Record<string, string>, extraEnv?: Record<string, string>): NodeJS.ProcessEnv;
|
|
14
|
+
/**
|
|
15
|
+
* Build the raw Responses API item injected into the dispatcher thread's
|
|
16
|
+
* model-visible history via `thread/inject_items`. A `message` item with role
|
|
17
|
+
* `developer` carries the completion as system-injected context — codex appends
|
|
18
|
+
* it to history without starting a user turn.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildCodexCompletionItem(completion: CompletionEnvelope, spillDir: string): Promise<Record<string, unknown>>;
|
|
21
|
+
/**
|
|
22
|
+
* Minimal user-turn text that wakes the idle dispatcher after a completion is
|
|
23
|
+
* injected. The injected developer item carries the actual result; this turn
|
|
24
|
+
* only triggers the model to read the just-injected notification and act.
|
|
25
|
+
*/
|
|
26
|
+
export declare const CODEX_COMPLETION_TRIGGER_TEXT: string;
|
|
27
|
+
//# sourceMappingURL=runtime-support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-support.d.ts","sourceRoot":"","sources":["../src/runtime-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAOnE;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACtC,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,MAAM,CAAC,UAAU,CAEnB;AA0BD;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,kBAAkB,EAC9B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAOlC;AAED;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QAG4B,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { resolveCompletionBody, } from '@excitedjs/dreamux-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Build the process env for a Codex app-server child. The neutral env boundary
|
|
4
|
+
* (issue #209 cleanup) is `{ ...process.env, ...injectEnv, ...extraEnv }`:
|
|
5
|
+
* - `injectEnv` is the host's optional neutral env-injection seam from the
|
|
6
|
+
* create context (empty today); core owns what it injects.
|
|
7
|
+
* - `extraEnv` is THIS provider's own `config.extra_env`, merged last so a
|
|
8
|
+
* dispatcher can override an injected value.
|
|
9
|
+
* The child inherits the operator's ambient `CODEX_HOME` like a vanilla
|
|
10
|
+
* `codex` invocation — Dreamux creates no dispatcher-private Codex home (MVP),
|
|
11
|
+
* so there is nothing to strip.
|
|
12
|
+
*/
|
|
13
|
+
export function codexProcessEnv(injectEnv = {}, extraEnv = {}) {
|
|
14
|
+
return { ...globalThis.process.env, ...injectEnv, ...extraEnv };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Frame a TeamMate completion as recognizable notification text. Delivered as
|
|
18
|
+
* the body of a developer-role history item (not a fake user turn), so codex
|
|
19
|
+
* treats it as injected context rather than user intent.
|
|
20
|
+
*
|
|
21
|
+
* Pure: the spill decision is made upstream and the resolved body is passed in,
|
|
22
|
+
* so this function performs no IO.
|
|
23
|
+
*/
|
|
24
|
+
function frameCodexCompletion(completion, body) {
|
|
25
|
+
const inner = body.kind === 'inline'
|
|
26
|
+
? body.text
|
|
27
|
+
: `The output is too long, so the full result was saved to a file: ${body.path}`;
|
|
28
|
+
return [
|
|
29
|
+
`<teammate_session_completion source="${completion.source}" ` +
|
|
30
|
+
`id="${completion.id}" status="${completion.status}">`,
|
|
31
|
+
inner,
|
|
32
|
+
'</teammate_session_completion>',
|
|
33
|
+
].join('\n');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build the raw Responses API item injected into the dispatcher thread's
|
|
37
|
+
* model-visible history via `thread/inject_items`. A `message` item with role
|
|
38
|
+
* `developer` carries the completion as system-injected context — codex appends
|
|
39
|
+
* it to history without starting a user turn.
|
|
40
|
+
*/
|
|
41
|
+
export async function buildCodexCompletionItem(completion, spillDir) {
|
|
42
|
+
const body = await resolveCompletionBody(completion, spillDir);
|
|
43
|
+
return {
|
|
44
|
+
type: 'message',
|
|
45
|
+
role: 'developer',
|
|
46
|
+
content: [{ type: 'input_text', text: frameCodexCompletion(completion, body) }],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Minimal user-turn text that wakes the idle dispatcher after a completion is
|
|
51
|
+
* injected. The injected developer item carries the actual result; this turn
|
|
52
|
+
* only triggers the model to read the just-injected notification and act.
|
|
53
|
+
*/
|
|
54
|
+
export const CODEX_COMPLETION_TRIGGER_TEXT = 'A TeamMate session you dispatched has settled. Its outcome was just delivered ' +
|
|
55
|
+
'into your context as a <teammate_session_completion> item. Review it and take ' +
|
|
56
|
+
'any needed follow-up; if nothing is needed, you may end this turn.';
|
|
57
|
+
//# sourceMappingURL=runtime-support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-support.js","sourceRoot":"","sources":["../src/runtime-support.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,GAEtB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAC7B,YAAoC,EAAE,EACtC,WAAmC,EAAE;IAErC,OAAO,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,QAAQ,EAAE,CAAC;AAClE,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,UAA8B,EAC9B,IAA4B;IAE5B,MAAM,KAAK,GACT,IAAI,CAAC,IAAI,KAAK,QAAQ;QACpB,CAAC,CAAC,IAAI,CAAC,IAAI;QACX,CAAC,CAAC,mEAAmE,IAAI,CAAC,IAAI,EAAE,CAAC;IACrF,OAAO;QACL,wCAAwC,UAAU,CAAC,MAAM,IAAI;YAC3D,OAAO,UAAU,CAAC,EAAE,aAAa,UAAU,CAAC,MAAM,IAAI;QACxD,KAAK;QACL,gCAAgC;KACjC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,UAA8B,EAC9B,QAAgB;IAEhB,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC/D,OAAO;QACL,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,oBAAoB,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC;KAChF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GACxC,gFAAgF;IAChF,gFAAgF;IAChF,oEAAoE,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodexRuntime — one running Codex-backed AgentRuntime instance.
|
|
3
|
+
*
|
|
4
|
+
* Owns:
|
|
5
|
+
* - CodexProcess (child app-server)
|
|
6
|
+
* - CodexWsClient (WS connection)
|
|
7
|
+
* - thread_id (lazily created via thread/start or resumed)
|
|
8
|
+
* - TurnManager (FIFO worker for this dispatcher)
|
|
9
|
+
*
|
|
10
|
+
* Lifecycle: declared → starting → ready → (degraded) → stopping → stopped.
|
|
11
|
+
*
|
|
12
|
+
* Current MVP:
|
|
13
|
+
* - accepted inbound work is process-local and is dropped on restart;
|
|
14
|
+
* - thread/resume failure does not degrade the whole dispatcher; we
|
|
15
|
+
* start a fresh thread, record the lost one in last_lost_thread_id,
|
|
16
|
+
* and post a visible warning to the next source chat.
|
|
17
|
+
*/
|
|
18
|
+
import { CodexProcess, type CodexProcessOptions } from './supervisor.js';
|
|
19
|
+
import { CodexWsClient } from './rpc.js';
|
|
20
|
+
import type { AgentRuntime, AgentRuntimeCapabilities, AgentRuntimeIdentity, AgentRuntimeLastResult, AgentRuntimePathContext, AgentRuntimeResumeInput, AgentRuntimeSkillSource, AgentRuntimeStateCallbacks, AgentRuntimeStatus, AgentRuntimeSystemInput, AgentRuntimeTurnResult, CompletionEnvelope, DreamuxLogger, InboundDeliveryHooks, InboundTurnInput, TeamMateCompletionDeliveryResult, TurnSettledSignal } from '@excitedjs/dreamux-types';
|
|
21
|
+
export interface CodexRuntimeDeps {
|
|
22
|
+
/** Working directory the codex app-server runs in (required launch param). */
|
|
23
|
+
cwd: string;
|
|
24
|
+
/**
|
|
25
|
+
* Launcher-supplied system-prompt content used as codex `baseInstructions`
|
|
26
|
+
* (codex applies it as a REPLACE per its `systemPrompt` capability). Omitted
|
|
27
|
+
* for launches that supply none (e.g. teammates).
|
|
28
|
+
*/
|
|
29
|
+
systemPromptContent?: string;
|
|
30
|
+
/** Neutral state sink the host adapts from its dispatcher store. */
|
|
31
|
+
state: AgentRuntimeStateCallbacks;
|
|
32
|
+
/** Host-supplied per-dispatcher path context (logs/spill live in the host tree). */
|
|
33
|
+
paths: AgentRuntimePathContext;
|
|
34
|
+
/**
|
|
35
|
+
* Allocate a fresh volatile rendezvous socket path for one app-server start.
|
|
36
|
+
* Host-supplied: the socket root is a Dreamux runtime contract this package
|
|
37
|
+
* must not reconstruct.
|
|
38
|
+
*/
|
|
39
|
+
allocateSocketPath: (id: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Role-gated bundled skill sources core selected for this runtime (issue #209
|
|
42
|
+
* slice 6). Applied via the app-server `skills/extraRoots/set` RPC after
|
|
43
|
+
* initialize and before thread start/resume, and reapplied after every
|
|
44
|
+
* app-server restart. Empty/omitted means no roots are set (the default for
|
|
45
|
+
* teammates and any role core does not gate skills for).
|
|
46
|
+
*/
|
|
47
|
+
skillSources?: readonly AgentRuntimeSkillSource[];
|
|
48
|
+
/**
|
|
49
|
+
* The host's neutral env-injection entries from the create context, merged
|
|
50
|
+
* into the child env before this provider's own `extraEnv`. Empty/omitted
|
|
51
|
+
* means inject nothing (the common case).
|
|
52
|
+
*/
|
|
53
|
+
injectEnv?: Record<string, string>;
|
|
54
|
+
/** Optional bin path override for tests. */
|
|
55
|
+
codexBinPath?: string;
|
|
56
|
+
/** Override process construction for tests. */
|
|
57
|
+
codexProcessFactory?: (opts: CodexProcessOptions) => CodexProcess;
|
|
58
|
+
/** Override WS client factory for tests. */
|
|
59
|
+
codexClientFactory?: (socketPath: string) => CodexWsClient;
|
|
60
|
+
/**
|
|
61
|
+
* Optional host-owned Codex home/auth pre-start check, invoked before the
|
|
62
|
+
* child spawns with the runtime id and cwd. The host owns its path/socket
|
|
63
|
+
* inputs and builds its own validation context from these.
|
|
64
|
+
*/
|
|
65
|
+
codexHomeDoctor?: (info: {
|
|
66
|
+
runtimeId: string;
|
|
67
|
+
cwd: string;
|
|
68
|
+
}) => void | Promise<void>;
|
|
69
|
+
/** Codex extraArgs (parsed from dispatcher.codex_args_json). */
|
|
70
|
+
resolveExtraArgs?: () => string[];
|
|
71
|
+
/**
|
|
72
|
+
* Codex initialize handshake timeout (ms). From this dispatcher's
|
|
73
|
+
* `dispatchers[].runtime.config.initialize_timeout_ms` (default 10000).
|
|
74
|
+
*/
|
|
75
|
+
handshakeTimeoutMs?: number;
|
|
76
|
+
/** Per-dispatcher environment overrides from config. */
|
|
77
|
+
extraEnv?: Record<string, string>;
|
|
78
|
+
/** Codex child/WS restart backoff base (tests may override). */
|
|
79
|
+
restartBackoffBaseMs?: number;
|
|
80
|
+
/** Codex child/WS restart backoff cap (tests may override). */
|
|
81
|
+
restartBackoffMaxMs?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Fired each time a delivered turn reaches a terminal state. Supplied by the
|
|
84
|
+
* launcher (teammate service) and omitted for dispatcher launches.
|
|
85
|
+
*/
|
|
86
|
+
onTurnSettled?: (settled: TurnSettledSignal) => void;
|
|
87
|
+
/** Neutral logger the host passes in; a console fallback is used when absent. */
|
|
88
|
+
logger?: DreamuxLogger;
|
|
89
|
+
}
|
|
90
|
+
export declare class CodexRuntime implements AgentRuntime {
|
|
91
|
+
readonly identity: AgentRuntimeIdentity;
|
|
92
|
+
private readonly deps;
|
|
93
|
+
readonly providerRef = "builtin:codex";
|
|
94
|
+
private process;
|
|
95
|
+
private client;
|
|
96
|
+
private turnManager;
|
|
97
|
+
private threadId;
|
|
98
|
+
/**
|
|
99
|
+
* Whether the most recent thread resolution resumed an existing Codex thread
|
|
100
|
+
* (true) rather than starting a fresh one or recovering from a failed resume.
|
|
101
|
+
* Consulted by the server right after the slot is ready to decide whether a
|
|
102
|
+
* `daemon restart` notice should be injected (issue #78).
|
|
103
|
+
*/
|
|
104
|
+
private threadResumed;
|
|
105
|
+
private status;
|
|
106
|
+
/** Monotonic per-attempt suffix for TeamMate delivery turn dedup ids (#110 PR8). */
|
|
107
|
+
private teammateDeliverySeq;
|
|
108
|
+
/**
|
|
109
|
+
* Completion deliveries currently being processed. Duplicate settled events can
|
|
110
|
+
* race into `completionInput`; coalescing by completion id keeps one logical
|
|
111
|
+
* completion from injecting or triggering more than once concurrently.
|
|
112
|
+
*/
|
|
113
|
+
private readonly inFlightCompletionDeliveries;
|
|
114
|
+
/**
|
|
115
|
+
* Completion ids whose trigger turn has already been accepted. A later replay
|
|
116
|
+
* of the same settled teammate turn is an idempotent success, not a new wake-up.
|
|
117
|
+
*/
|
|
118
|
+
private readonly acceptedCompletionIds;
|
|
119
|
+
private readonly acceptedCompletionOrder;
|
|
120
|
+
/**
|
|
121
|
+
* Completion ids whose item has already been injected into the thread. The
|
|
122
|
+
* Dispatcher Service retries `completionInput` on `failed`; if the inject
|
|
123
|
+
* succeeded but the trigger turn failed, the retry must NOT re-inject the same
|
|
124
|
+
* item (that would persist a duplicate completion to the rollout). Bounded so
|
|
125
|
+
* a long-lived dispatcher does not grow this set without limit.
|
|
126
|
+
*/
|
|
127
|
+
private readonly injectedCompletionIds;
|
|
128
|
+
private readonly injectedCompletionOrder;
|
|
129
|
+
private readonly log;
|
|
130
|
+
private stopping;
|
|
131
|
+
private restarting;
|
|
132
|
+
private restartAttempts;
|
|
133
|
+
private restartTimer;
|
|
134
|
+
private lastResult;
|
|
135
|
+
private readonly state;
|
|
136
|
+
private readonly paths;
|
|
137
|
+
constructor(identity: AgentRuntimeIdentity, deps: CodexRuntimeDeps);
|
|
138
|
+
get dispatcherId(): string;
|
|
139
|
+
getStatus(): AgentRuntimeStatus;
|
|
140
|
+
getCapabilities(): AgentRuntimeCapabilities;
|
|
141
|
+
getThreadId(): string | null;
|
|
142
|
+
/** True when the live thread was resumed (not freshly started/recovered). */
|
|
143
|
+
wasThreadResumed(): boolean;
|
|
144
|
+
getLast(): Promise<AgentRuntimeLastResult | null>;
|
|
145
|
+
getContext(): Promise<null>;
|
|
146
|
+
resume(input?: AgentRuntimeResumeInput): Promise<void>;
|
|
147
|
+
private submitRestartNotice;
|
|
148
|
+
/**
|
|
149
|
+
* Bring the dispatcher up. Order:
|
|
150
|
+
* 1. spawn codex app-server child
|
|
151
|
+
* 2. open WS client
|
|
152
|
+
* 3. install fail-fast approval handler
|
|
153
|
+
* 4. thread/start (new) or thread/resume (existing)
|
|
154
|
+
* 5. install turn manager
|
|
155
|
+
* 6. status = ready
|
|
156
|
+
*/
|
|
157
|
+
start(): Promise<void>;
|
|
158
|
+
private startCodexRuntime;
|
|
159
|
+
/**
|
|
160
|
+
* Apply the role-gated bundled skill sources to the live app-server via
|
|
161
|
+
* `skills/extraRoots/set`. Codex treats each extra root as a directory whose
|
|
162
|
+
* immediate children are skill dirs, so a `skill-dir` source maps to the
|
|
163
|
+
* *parent* of its own directory; roots are deduped (the bundled Dreamux skills
|
|
164
|
+
* share one parent). Empty input skips the RPC entirely (a fresh per-runtime
|
|
165
|
+
* app-server starts with no extra roots, so nothing to clear).
|
|
166
|
+
*
|
|
167
|
+
* Error handling distinguishes two failure modes (issue #209 slice 6 repair):
|
|
168
|
+
* 1. The app-server does not implement `skills/extraRoots/set` at all — a
|
|
169
|
+
* capability/version skew against an older codex backend (it answers with
|
|
170
|
+
* an `unknown variant`/method-not-found error). This is NOT a real
|
|
171
|
+
* failure: fail open, warn, and continue skill-blind rather than bricking
|
|
172
|
+
* startup against every backend that predates the RPC.
|
|
173
|
+
* 2. The RPC exists but applying the given roots genuinely failed — fail
|
|
174
|
+
* loud, exactly as before, so real misconfiguration is not masked.
|
|
175
|
+
*/
|
|
176
|
+
private applySkillExtraRoots;
|
|
177
|
+
private resolveThread;
|
|
178
|
+
/**
|
|
179
|
+
* Submit any accepted inbound message arriving for this dispatcher. Called by
|
|
180
|
+
* the Feishu inbound layer.
|
|
181
|
+
*/
|
|
182
|
+
channelInput(input: InboundTurnInput, hooks?: InboundDeliveryHooks): Promise<AgentRuntimeTurnResult>;
|
|
183
|
+
/** Inject a system-originated notice (e.g. a restart notice). */
|
|
184
|
+
systemInput(notice: AgentRuntimeSystemInput): Promise<AgentRuntimeTurnResult>;
|
|
185
|
+
/**
|
|
186
|
+
* Codex TeamMate completion delivery — the native inbox-then-trigger idiom.
|
|
187
|
+
*
|
|
188
|
+
* Two steps, in order:
|
|
189
|
+
* 1. `thread/inject_items` appends the completion to the dispatcher thread's
|
|
190
|
+
* model-visible history as a developer-role message (no fake user turn).
|
|
191
|
+
* codex folds the item onto the active turn when one is running and never
|
|
192
|
+
* rejects on a busy thread, so a failure here is a genuine RPC error.
|
|
193
|
+
* 2. a minimal trigger turn through the public `channelInput` seam wakes the
|
|
194
|
+
* idle dispatcher so it reads the just-injected notification and acts.
|
|
195
|
+
*
|
|
196
|
+
* The trigger turn uses a fresh, non-routable source id per attempt. The turn
|
|
197
|
+
* manager commits its dedup id before `turn/start` and does not roll it back
|
|
198
|
+
* on failure, so a retry that reused one id would come back `duplicate` and be
|
|
199
|
+
* mis-counted as delivered when nothing was submitted. The Dispatcher Service
|
|
200
|
+
* only retries on `failed` (definitely not submitted), so a unique id per
|
|
201
|
+
* attempt re-submits the trigger safely.
|
|
202
|
+
*/
|
|
203
|
+
completionInput(completion: CompletionEnvelope): Promise<TeamMateCompletionDeliveryResult>;
|
|
204
|
+
private deliverCompletionInput;
|
|
205
|
+
/** Graceful stop: stop accepting work, reap codex child. */
|
|
206
|
+
stop(): Promise<void>;
|
|
207
|
+
private cleanupOnFailure;
|
|
208
|
+
private teardownCodexRuntime;
|
|
209
|
+
private handleChildExit;
|
|
210
|
+
private handleClientClose;
|
|
211
|
+
private scheduleRestart;
|
|
212
|
+
private restartCodexRuntime;
|
|
213
|
+
private restartDelayMs;
|
|
214
|
+
private clearRestartTimer;
|
|
215
|
+
private markReady;
|
|
216
|
+
private recordCollectedTurn;
|
|
217
|
+
/** Record a completion id as injected, evicting the oldest past a small cap. */
|
|
218
|
+
private rememberInjectedCompletion;
|
|
219
|
+
/** Record a completion id as fully accepted, evicting the oldest past a cap. */
|
|
220
|
+
private rememberAcceptedCompletion;
|
|
221
|
+
private setStatus;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Classify an RPC rejection as a capability/version gap — the app-server does
|
|
225
|
+
* not implement the requested method at all — rather than a genuine failure of
|
|
226
|
+
* an existing method.
|
|
227
|
+
*
|
|
228
|
+
* The rpc layer collapses codex's structured error to `Error(message)` (it
|
|
229
|
+
* drops the JSON-RPC error code), so the *message* is all we have. codex
|
|
230
|
+
* surfaces an unimplemented method as a serde enum-deserialization failure of
|
|
231
|
+
* the request's `method` field — `unknown variant \`<method>\`, expected one of
|
|
232
|
+
* …` — while a spec-compliant JSON-RPC peer answers method-not-found (-32601).
|
|
233
|
+
* We match those canonical phrasings only; the test stays deliberately narrow
|
|
234
|
+
* so a real error from an *existing* method (a bad root path, a permission
|
|
235
|
+
* failure) is NOT swallowed and still fails loud.
|
|
236
|
+
*
|
|
237
|
+
* The match is message-based by necessity: the rpc layer drops the structured
|
|
238
|
+
* JSON-RPC error code, so the message is all we have. The one residual
|
|
239
|
+
* false-positive is a server that *implements* the method but rejects a bad
|
|
240
|
+
* *param value* with an "unknown variant `<value>`" serde error. That is safe
|
|
241
|
+
* for our sole caller — `skills/extraRoots/set` takes a `string[]` of paths,
|
|
242
|
+
* which codex never enum-rejects — but a future caller passing an enum-typed
|
|
243
|
+
* param should not reuse this classifier blindly.
|
|
244
|
+
*/
|
|
245
|
+
export declare function isUnsupportedRpcMethodError(err: unknown): boolean;
|
|
246
|
+
//# sourceMappingURL=runtime.d.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