remcodex 0.1.0-beta.1

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +331 -0
  3. package/dist/server/src/app.js +186 -0
  4. package/dist/server/src/cli.js +270 -0
  5. package/dist/server/src/controllers/codex-options.controller.js +199 -0
  6. package/dist/server/src/controllers/message.controller.js +21 -0
  7. package/dist/server/src/controllers/project.controller.js +44 -0
  8. package/dist/server/src/controllers/session.controller.js +175 -0
  9. package/dist/server/src/db/client.js +10 -0
  10. package/dist/server/src/db/migrations.js +32 -0
  11. package/dist/server/src/gateways/ws.gateway.js +60 -0
  12. package/dist/server/src/services/codex-app-server-runner.js +363 -0
  13. package/dist/server/src/services/codex-exec-runner.js +147 -0
  14. package/dist/server/src/services/codex-rollout-sync.js +977 -0
  15. package/dist/server/src/services/codex-runner.js +11 -0
  16. package/dist/server/src/services/codex-stream-events.js +478 -0
  17. package/dist/server/src/services/event-store.js +328 -0
  18. package/dist/server/src/services/project-manager.js +130 -0
  19. package/dist/server/src/services/pty-runner.js +72 -0
  20. package/dist/server/src/services/session-manager.js +1586 -0
  21. package/dist/server/src/services/session-timeline-service.js +181 -0
  22. package/dist/server/src/types/codex-launch.js +2 -0
  23. package/dist/server/src/types/models.js +37 -0
  24. package/dist/server/src/utils/ansi.js +143 -0
  25. package/dist/server/src/utils/codex-launch.js +102 -0
  26. package/dist/server/src/utils/codex-quota.js +179 -0
  27. package/dist/server/src/utils/codex-status.js +163 -0
  28. package/dist/server/src/utils/codex-ui-options.js +114 -0
  29. package/dist/server/src/utils/command.js +46 -0
  30. package/dist/server/src/utils/errors.js +16 -0
  31. package/dist/server/src/utils/ids.js +7 -0
  32. package/dist/server/src/utils/node-pty.js +29 -0
  33. package/package.json +36 -0
  34. package/scripts/fix-node-pty-helper.js +36 -0
  35. package/web/api.js +175 -0
  36. package/web/app.js +8082 -0
  37. package/web/components/composer.js +627 -0
  38. package/web/components/session-workbench.js +173 -0
  39. package/web/i18n/index.js +171 -0
  40. package/web/i18n/locales/de.js +50 -0
  41. package/web/i18n/locales/en.js +320 -0
  42. package/web/i18n/locales/es.js +50 -0
  43. package/web/i18n/locales/fr.js +50 -0
  44. package/web/i18n/locales/ja.js +50 -0
  45. package/web/i18n/locales/ko.js +50 -0
  46. package/web/i18n/locales/pt-BR.js +50 -0
  47. package/web/i18n/locales/ru.js +50 -0
  48. package/web/i18n/locales/zh-CN.js +320 -0
  49. package/web/i18n/locales/zh-Hant.js +53 -0
  50. package/web/index.html +23 -0
  51. package/web/message-rich-text.js +218 -0
  52. package/web/session-command-activity.js +980 -0
  53. package/web/session-event-adapter.js +826 -0
  54. package/web/session-timeline-reducer.js +728 -0
  55. package/web/session-timeline-renderer.js +656 -0
  56. package/web/session-ws.js +31 -0
  57. package/web/styles.css +5665 -0
  58. package/web/vendor/markdown-it.js +6969 -0
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCodexRunner = createCodexRunner;
4
+ const codex_app_server_runner_1 = require("./codex-app-server-runner");
5
+ const codex_exec_runner_1 = require("./codex-exec-runner");
6
+ function createCodexRunner(mode, command, cwd) {
7
+ if (mode === "app-server") {
8
+ return new codex_app_server_runner_1.CodexAppServerRunner(command, cwd);
9
+ }
10
+ return new codex_exec_runner_1.CodexExecRunner(command, cwd);
11
+ }
@@ -0,0 +1,478 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCodexLegacyEvent = isCodexLegacyEvent;
4
+ exports.isCodexEnvelopeEvent = isCodexEnvelopeEvent;
5
+ exports.isCodexAppServerMessage = isCodexAppServerMessage;
6
+ exports.translateCodexAppServerMessage = translateCodexAppServerMessage;
7
+ const LEGACY_EVENT_TYPES = new Set([
8
+ "thread.started",
9
+ "item.started",
10
+ "item.completed",
11
+ "turn.completed",
12
+ ]);
13
+ const APPROVAL_METHODS = new Set([
14
+ "item/commandExecution/requestApproval",
15
+ "item/fileChange/requestApproval",
16
+ "item/permissions/requestApproval",
17
+ "execCommandApproval",
18
+ "applyPatchApproval",
19
+ ]);
20
+ function readString(value) {
21
+ return typeof value === "string" && value.trim() ? value.trim() : null;
22
+ }
23
+ function readRawText(value) {
24
+ return typeof value === "string" ? value : null;
25
+ }
26
+ function readNumber(value) {
27
+ if (typeof value === "number" && Number.isFinite(value)) {
28
+ return value;
29
+ }
30
+ if (typeof value === "string" && value.trim()) {
31
+ const parsed = Number.parseFloat(value);
32
+ return Number.isFinite(parsed) ? parsed : null;
33
+ }
34
+ return null;
35
+ }
36
+ function asRecord(value) {
37
+ return value && typeof value === "object" ? value : null;
38
+ }
39
+ function readTurnId(params) {
40
+ return (readString(params?.turnId) ||
41
+ readString(asRecord(params?.turn)?.id) ||
42
+ readString(params?.turn_id) ||
43
+ null);
44
+ }
45
+ function readItem(params) {
46
+ return asRecord(params?.item);
47
+ }
48
+ function normalizePhase(value) {
49
+ return value === "commentary" || value === "final_answer" ? value : null;
50
+ }
51
+ function readMessageId(params) {
52
+ const item = readItem(params);
53
+ return (readString(params?.messageId) ||
54
+ readString(params?.message_id) ||
55
+ readString(params?.itemId) ||
56
+ readString(item?.id) ||
57
+ null);
58
+ }
59
+ function readCallId(params) {
60
+ const item = readItem(params);
61
+ return (readString(params?.callId) ||
62
+ readString(params?.call_id) ||
63
+ readString(params?.itemId) ||
64
+ readString(item?.callId) ||
65
+ readString(item?.call_id) ||
66
+ readString(item?.id) ||
67
+ null);
68
+ }
69
+ function readIoStream(value) {
70
+ return value === "stderr" ? "stderr" : value === "stdout" ? "stdout" : null;
71
+ }
72
+ function readItemType(params) {
73
+ const item = readItem(params);
74
+ return readString(item?.type);
75
+ }
76
+ function isPatchItemType(type) {
77
+ return type === "fileChange" || type === "patch" || type === "applyPatch";
78
+ }
79
+ function readMessageText(item) {
80
+ const direct = readString(item?.text);
81
+ if (direct) {
82
+ return direct;
83
+ }
84
+ const content = Array.isArray(item?.content) ? item?.content : [];
85
+ const text = content
86
+ .map((entry) => {
87
+ const record = asRecord(entry);
88
+ return readString(record?.text) || "";
89
+ })
90
+ .filter(Boolean)
91
+ .join("\n");
92
+ return text || null;
93
+ }
94
+ function isCodexLegacyEvent(raw) {
95
+ if (!raw || typeof raw !== "object") {
96
+ return false;
97
+ }
98
+ const type = raw.type;
99
+ return typeof type === "string" && LEGACY_EVENT_TYPES.has(type);
100
+ }
101
+ function isCodexEnvelopeEvent(raw) {
102
+ if (!raw || typeof raw !== "object") {
103
+ return false;
104
+ }
105
+ const type = raw.type;
106
+ return type === "response_item" || type === "event_msg";
107
+ }
108
+ function isCodexAppServerMessage(raw) {
109
+ if (!raw || typeof raw !== "object") {
110
+ return false;
111
+ }
112
+ const method = raw.method;
113
+ return typeof method === "string";
114
+ }
115
+ function translateCodexAppServerMessage(raw) {
116
+ const params = asRecord(raw.params);
117
+ const turnId = readTurnId(params);
118
+ const signals = [];
119
+ if (raw.method === "thread/started") {
120
+ const thread = asRecord(params?.thread);
121
+ const threadId = readString(thread?.id);
122
+ if (threadId) {
123
+ signals.push({
124
+ kind: "thread_started",
125
+ threadId,
126
+ });
127
+ }
128
+ return signals;
129
+ }
130
+ if (APPROVAL_METHODS.has(raw.method) && typeof raw.id === "number") {
131
+ signals.push({
132
+ kind: "approval_request",
133
+ requestId: raw.id,
134
+ method: raw.method,
135
+ params: params ?? {},
136
+ turnId,
137
+ callId: readCallId(params),
138
+ });
139
+ return signals;
140
+ }
141
+ if (raw.method === "thread/tokenUsage/updated") {
142
+ const tokenUsage = asRecord(params?.tokenUsage);
143
+ signals.push({
144
+ kind: "event",
145
+ event: {
146
+ type: "token_count",
147
+ turnId,
148
+ payload: {
149
+ rateLimits: asRecord(params?.rateLimits) ||
150
+ asRecord(params?.rate_limits) ||
151
+ asRecord(tokenUsage?.rateLimits) ||
152
+ {},
153
+ totalTokenUsage: asRecord(tokenUsage?.total) ||
154
+ asRecord(tokenUsage?.totalTokenUsage) ||
155
+ undefined,
156
+ lastTokenUsage: asRecord(tokenUsage?.last) ||
157
+ asRecord(tokenUsage?.lastTokenUsage) ||
158
+ undefined,
159
+ modelContextWindow: readNumber(params?.modelContextWindow) ??
160
+ readNumber(tokenUsage?.modelContextWindow) ??
161
+ undefined,
162
+ receivedAt: new Date().toISOString(),
163
+ rawPayload: params ?? {},
164
+ source: "live",
165
+ },
166
+ },
167
+ });
168
+ return signals;
169
+ }
170
+ if (raw.method === "turn/started") {
171
+ signals.push({
172
+ kind: "event",
173
+ event: {
174
+ type: "turn.started",
175
+ turnId,
176
+ payload: {
177
+ createdAt: new Date().toISOString(),
178
+ },
179
+ },
180
+ });
181
+ return signals;
182
+ }
183
+ if (raw.method === "turn/completed") {
184
+ const turn = asRecord(params?.turn);
185
+ const status = readString(turn?.status) || "completed";
186
+ const error = asRecord(turn?.error);
187
+ if (error && readString(error.message)) {
188
+ signals.push({
189
+ kind: "event",
190
+ event: {
191
+ type: "error",
192
+ turnId,
193
+ payload: {
194
+ message: readString(error.message) || "Turn failed.",
195
+ code: readString(error.code),
196
+ details: error,
197
+ },
198
+ },
199
+ });
200
+ }
201
+ signals.push({
202
+ kind: "event",
203
+ event: {
204
+ type: status === "cancelled" || status === "aborted" || status === "failed"
205
+ ? "turn.aborted"
206
+ : "turn.completed",
207
+ turnId,
208
+ payload: status === "cancelled" || status === "aborted" || status === "failed"
209
+ ? {
210
+ abortedAt: new Date().toISOString(),
211
+ reason: readString(error?.message) || status,
212
+ }
213
+ : {
214
+ completedAt: new Date().toISOString(),
215
+ },
216
+ },
217
+ });
218
+ return signals;
219
+ }
220
+ if (raw.method === "error") {
221
+ const error = asRecord(params?.error);
222
+ signals.push({
223
+ kind: "event",
224
+ event: {
225
+ type: "error",
226
+ turnId,
227
+ payload: {
228
+ message: readString(error?.message) || "Codex app-server reported an error.",
229
+ code: readString(error?.code),
230
+ details: {
231
+ ...(error ?? {}),
232
+ willRetry: params?.willRetry ?? null,
233
+ },
234
+ },
235
+ },
236
+ });
237
+ return signals;
238
+ }
239
+ if (raw.method === "item/agentMessage/delta") {
240
+ signals.push({
241
+ kind: "event",
242
+ event: {
243
+ type: "message.assistant.delta",
244
+ turnId,
245
+ messageId: readMessageId(params),
246
+ phase: normalizePhase(params?.phase) ||
247
+ normalizePhase(readItem(params)?.phase) ||
248
+ "final_answer",
249
+ payload: {
250
+ textDelta: readRawText(params?.delta) || "",
251
+ },
252
+ },
253
+ });
254
+ return signals;
255
+ }
256
+ if (raw.method === "item/updated" || raw.method === "item/agentMessage/updated") {
257
+ const item = readItem(params) || params;
258
+ const itemType = readItemType(params) ||
259
+ readString(item?.type) ||
260
+ readString(params?.type);
261
+ if (itemType === "agentMessage") {
262
+ signals.push({
263
+ kind: "event",
264
+ event: {
265
+ type: "message.assistant.delta",
266
+ turnId,
267
+ messageId: readMessageId(params),
268
+ phase: normalizePhase(params?.phase) ||
269
+ normalizePhase(item?.phase) ||
270
+ "final_answer",
271
+ payload: {
272
+ text: readMessageText(item) || "",
273
+ },
274
+ },
275
+ });
276
+ return signals;
277
+ }
278
+ if (itemType === "reasoning") {
279
+ const summary = readString(item?.summary) || "";
280
+ signals.push({
281
+ kind: "event",
282
+ event: {
283
+ type: "reasoning.delta",
284
+ turnId,
285
+ messageId: readMessageId(params),
286
+ payload: {
287
+ text: summary,
288
+ summary,
289
+ },
290
+ },
291
+ });
292
+ return signals;
293
+ }
294
+ }
295
+ if (raw.method === "item/reasoning/delta" || raw.method === "item/reasoningSummary/delta") {
296
+ signals.push({
297
+ kind: "event",
298
+ event: {
299
+ type: "reasoning.delta",
300
+ turnId,
301
+ messageId: readMessageId(params),
302
+ payload: {
303
+ textDelta: readRawText(params?.delta) || readRawText(params?.summary) || "",
304
+ summary: readString(params?.summary),
305
+ },
306
+ },
307
+ });
308
+ return signals;
309
+ }
310
+ if (raw.method === "item/commandExecution/outputDelta") {
311
+ signals.push({
312
+ kind: "event",
313
+ event: {
314
+ type: "command.output.delta",
315
+ turnId,
316
+ callId: readCallId(params),
317
+ stream: readIoStream(params?.stream) || "stdout",
318
+ payload: {
319
+ stream: readIoStream(params?.stream) || "stdout",
320
+ textDelta: readRawText(params?.delta) || "",
321
+ },
322
+ },
323
+ });
324
+ return signals;
325
+ }
326
+ if (raw.method === "item/fileChange/outputDelta" || raw.method === "item/patch/outputDelta") {
327
+ signals.push({
328
+ kind: "event",
329
+ event: {
330
+ type: "patch.output.delta",
331
+ turnId,
332
+ callId: readCallId(params),
333
+ payload: {
334
+ textDelta: readRawText(params?.delta) || "",
335
+ },
336
+ },
337
+ });
338
+ return signals;
339
+ }
340
+ if (raw.method === "item/started") {
341
+ const item = readItem(params);
342
+ const itemType = readItemType(params);
343
+ if (itemType === "agentMessage") {
344
+ signals.push({
345
+ kind: "event",
346
+ event: {
347
+ type: "message.assistant.start",
348
+ turnId,
349
+ messageId: readMessageId(params),
350
+ phase: normalizePhase(item?.phase) || "final_answer",
351
+ payload: {
352
+ text: readMessageText(item) || "",
353
+ },
354
+ },
355
+ });
356
+ return signals;
357
+ }
358
+ if (itemType === "reasoning") {
359
+ signals.push({
360
+ kind: "event",
361
+ event: {
362
+ type: "reasoning.start",
363
+ turnId,
364
+ messageId: readMessageId(params),
365
+ payload: {
366
+ summary: readString(item?.summary),
367
+ },
368
+ },
369
+ });
370
+ return signals;
371
+ }
372
+ if (itemType === "commandExecution") {
373
+ signals.push({
374
+ kind: "event",
375
+ event: {
376
+ type: "command.start",
377
+ turnId,
378
+ callId: readCallId(params),
379
+ payload: {
380
+ command: readString(item?.command) || "",
381
+ cwd: readString(item?.cwd),
382
+ justification: readString(item?.justification),
383
+ sandboxMode: readString(item?.sandbox) || readString(item?.sandboxMode),
384
+ approvalRequired: Boolean(item?.approvalRequired ?? false),
385
+ grantRoot: readString(item?.grantRoot),
386
+ },
387
+ },
388
+ });
389
+ return signals;
390
+ }
391
+ if (isPatchItemType(itemType)) {
392
+ signals.push({
393
+ kind: "event",
394
+ event: {
395
+ type: "patch.start",
396
+ turnId,
397
+ callId: readCallId(params),
398
+ payload: {
399
+ summary: readString(item?.summary),
400
+ target: readString(item?.target),
401
+ },
402
+ },
403
+ });
404
+ return signals;
405
+ }
406
+ }
407
+ if (raw.method === "item/completed") {
408
+ const item = readItem(params);
409
+ const itemType = readItemType(params);
410
+ if (itemType === "agentMessage") {
411
+ signals.push({
412
+ kind: "event",
413
+ event: {
414
+ type: "message.assistant.end",
415
+ turnId,
416
+ messageId: readMessageId(params),
417
+ phase: normalizePhase(item?.phase) || "final_answer",
418
+ payload: {
419
+ text: readMessageText(item) || "",
420
+ finishReason: readString(item?.finishReason) || readString(item?.finish_reason),
421
+ },
422
+ },
423
+ });
424
+ return signals;
425
+ }
426
+ if (itemType === "reasoning") {
427
+ signals.push({
428
+ kind: "event",
429
+ event: {
430
+ type: "reasoning.end",
431
+ turnId,
432
+ messageId: readMessageId(params),
433
+ payload: {
434
+ summary: readString(item?.summary),
435
+ },
436
+ },
437
+ });
438
+ return signals;
439
+ }
440
+ if (itemType === "commandExecution") {
441
+ signals.push({
442
+ kind: "event",
443
+ event: {
444
+ type: "command.end",
445
+ turnId,
446
+ callId: readCallId(params),
447
+ payload: {
448
+ command: readString(item?.command),
449
+ cwd: readString(item?.cwd),
450
+ status: readString(item?.status),
451
+ exitCode: readNumber(item?.exitCode),
452
+ durationMs: readNumber(item?.durationMs) ?? readNumber(item?.duration_ms),
453
+ rejected: item?.rejected === true,
454
+ },
455
+ },
456
+ });
457
+ return signals;
458
+ }
459
+ if (isPatchItemType(itemType)) {
460
+ signals.push({
461
+ kind: "event",
462
+ event: {
463
+ type: "patch.end",
464
+ turnId,
465
+ callId: readCallId(params),
466
+ payload: {
467
+ status: readString(item?.status),
468
+ durationMs: readNumber(item?.durationMs) ?? readNumber(item?.duration_ms),
469
+ success: typeof item?.success === "boolean" ? item.success : null,
470
+ rejected: item?.rejected === true,
471
+ },
472
+ },
473
+ });
474
+ return signals;
475
+ }
476
+ }
477
+ return signals;
478
+ }