@straiffi/archon 1.10.12 → 1.11.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.
Files changed (199) hide show
  1. package/README.md +9 -2
  2. package/dist/client/assets/{ActivityView-BFn_Nhj4.js → ActivityView-BvXSn9Jw.js} +1 -1
  3. package/dist/client/assets/{GitHubActionsDialog-iZD86Yju.js → GitHubActionsDialog-BPZg_Wy3.js} +1 -1
  4. package/dist/client/assets/{VerificationDialog-CqKE8t1d.js → VerificationDialog-D3mOY3z9.js} +1 -1
  5. package/dist/client/assets/{architectureDiagram-3BPJPVTR-C8KefY67.js → architectureDiagram-3BPJPVTR-Bj7m5nzx.js} +1 -1
  6. package/dist/client/assets/{blockDiagram-GPEHLZMM-BO2Q_Osr.js → blockDiagram-GPEHLZMM-Dv4SrhZg.js} +1 -1
  7. package/dist/client/assets/{c4Diagram-AAUBKEIU-DGPkhbrK.js → c4Diagram-AAUBKEIU-BKGsMo_n.js} +1 -1
  8. package/dist/client/assets/channel-DmiHuOD2.js +1 -0
  9. package/dist/client/assets/{chunk-2J33WTMH-Dtb7Xu8C.js → chunk-2J33WTMH-oppoEflV.js} +1 -1
  10. package/dist/client/assets/{chunk-3OPIFGDE-Bnf4GbOF.js → chunk-3OPIFGDE-FoeHxEDL.js} +1 -1
  11. package/dist/client/assets/{chunk-5ZQYHXKU-BWGid3g7.js → chunk-5ZQYHXKU-DFo7Hn8f.js} +1 -1
  12. package/dist/client/assets/{chunk-727SXJPM-ScA8IRGP.js → chunk-727SXJPM-BbM0ijwZ.js} +1 -1
  13. package/dist/client/assets/{chunk-AQP2D5EJ-Bygg04Ip.js → chunk-AQP2D5EJ-hGswj21x.js} +1 -1
  14. package/dist/client/assets/{chunk-CSCIHK7Q-CxdDDtfN.js → chunk-CSCIHK7Q-k3Y3HBPl.js} +1 -1
  15. package/dist/client/assets/{chunk-KSCS5N6A-BgpZFsB5.js → chunk-KSCS5N6A-D-fMWFHX.js} +1 -1
  16. package/dist/client/assets/{chunk-L5ZTLDWV-CKSew0OL.js → chunk-L5ZTLDWV-Cp8034Xo.js} +1 -1
  17. package/dist/client/assets/{chunk-LZXEDZCA-DVG9Rx0K.js → chunk-LZXEDZCA-DCmWwuZY.js} +2 -2
  18. package/dist/client/assets/{chunk-ND2GUHAM-CHBqNmuF.js → chunk-ND2GUHAM-CPxoYLrb.js} +1 -1
  19. package/dist/client/assets/{chunk-NZK2D7GU-DvZYWn7V.js → chunk-NZK2D7GU-B1xsQ-Ge.js} +1 -1
  20. package/dist/client/assets/{chunk-O5CBEL6O-BL7lRTSe.js → chunk-O5CBEL6O-CP_QLulv.js} +1 -1
  21. package/dist/client/assets/{chunk-WU5MYG2G-C-il2wHZ.js → chunk-WU5MYG2G-CqDmmASz.js} +1 -1
  22. package/dist/client/assets/classDiagram-4FO5ZUOK-GuChK9KD.js +1 -0
  23. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-ezsQe4jc.js +1 -0
  24. package/dist/client/assets/{dagre-BM42HDAG-B00l5tLi.js → dagre-BM42HDAG-I60HgRr5.js} +1 -1
  25. package/dist/client/assets/{diagram-2AECGRRQ-Tum6g1_5.js → diagram-2AECGRRQ-DH7489lu.js} +1 -1
  26. package/dist/client/assets/{diagram-5GNKFQAL-BK1GX5jc.js → diagram-5GNKFQAL-UG5kJveS.js} +1 -1
  27. package/dist/client/assets/{diagram-KO2AKTUF-BrzmD5NB.js → diagram-KO2AKTUF-DLPd9cl-.js} +1 -1
  28. package/dist/client/assets/{diagram-LMA3HP47-BhrlgXiJ.js → diagram-LMA3HP47-gfoMHIE-.js} +1 -1
  29. package/dist/client/assets/{diagram-OG6HWLK6-K-fWsJ3a.js → diagram-OG6HWLK6-D7zejHzo.js} +1 -1
  30. package/dist/client/assets/{erDiagram-TEJ5UH35-Der6PjHE.js → erDiagram-TEJ5UH35-DB1R9rUd.js} +1 -1
  31. package/dist/client/assets/{flowDiagram-I6XJVG4X-BVWgGhXe.js → flowDiagram-I6XJVG4X-rSasRun9.js} +1 -1
  32. package/dist/client/assets/{ganttDiagram-6RSMTGT7-DcoZ5ggj.js → ganttDiagram-6RSMTGT7-ickt48MT.js} +1 -1
  33. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-BhhbMTBu.js → gitGraphDiagram-PVQCEYII-B2MWuej-.js} +1 -1
  34. package/dist/client/assets/index-4RQBXPuO.css +2 -0
  35. package/dist/client/assets/index-BN2UMUYo.js +276 -0
  36. package/dist/client/assets/{infoDiagram-5YYISTIA-Lwc-agyc.js → infoDiagram-5YYISTIA-ClB9-yBC.js} +1 -1
  37. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-B95U1Xcl.js → ishikawaDiagram-YF4QCWOH-CyUX0IyE.js} +1 -1
  38. package/dist/client/assets/{journeyDiagram-JHISSGLW-xFpigy5D.js → journeyDiagram-JHISSGLW-CvZv1SZ7.js} +1 -1
  39. package/dist/client/assets/{kanban-definition-UN3LZRKU-D3mudQnR.js → kanban-definition-UN3LZRKU-C3MgzQMY.js} +1 -1
  40. package/dist/client/assets/{line-DtTL3ZI2.js → line-Dpj7mkeR.js} +1 -1
  41. package/dist/client/assets/{mermaid-parser.core-Dau7K6zV.js → mermaid-parser.core-Ezn4UHHp.js} +1 -1
  42. package/dist/client/assets/{mermaid.core-B8qtvATu.js → mermaid.core-GVI7XZqR.js} +3 -3
  43. package/dist/client/assets/{mindmap-definition-RKZ34NQL-Cus04Yq3.js → mindmap-definition-RKZ34NQL-Bu2cgOo4.js} +1 -1
  44. package/dist/client/assets/{pieDiagram-4H26LBE5-BCMGpBnn.js → pieDiagram-4H26LBE5-_WS41t2_.js} +1 -1
  45. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-CAmOr-PJ.js → quadrantDiagram-W4KKPZXB-Urvq-XqI.js} +1 -1
  46. package/dist/client/assets/{requirementDiagram-4Y6WPE33-kisD3jc4.js → requirementDiagram-4Y6WPE33-bkmWG0rM.js} +1 -1
  47. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-CsCedmM0.js → sankeyDiagram-5OEKKPKP-DI0SArVz.js} +1 -1
  48. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-B-dAi954.js → sequenceDiagram-3UESZ5HK-n7PKrHd3.js} +1 -1
  49. package/dist/client/assets/{stateDiagram-AJRCARHV-X0BnedIW.js → stateDiagram-AJRCARHV-CxnEzrQA.js} +1 -1
  50. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-DXTMu4iJ.js +1 -0
  51. package/dist/client/assets/{timeline-definition-PNZ67QCA-DfFoSjhr.js → timeline-definition-PNZ67QCA-BFr88_A9.js} +1 -1
  52. package/dist/client/assets/{vennDiagram-CIIHVFJN-CKSCBwhG.js → vennDiagram-CIIHVFJN-BNYs6tfr.js} +1 -1
  53. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-DNIBQmHO.js → wardleyDiagram-YWT4CUSO-CaGZd3fe.js} +1 -1
  54. package/dist/client/assets/{xychartDiagram-2RQKCTM6-FvB55TQN.js → xychartDiagram-2RQKCTM6-CMyDrx2a.js} +1 -1
  55. package/dist/client/index.html +2 -2
  56. package/dist/server/db.js +153 -26
  57. package/dist/server/db.js.map +1 -1
  58. package/dist/server/index.js +93 -36
  59. package/dist/server/index.js.map +1 -1
  60. package/dist/server/lib/activeTool.js +23 -0
  61. package/dist/server/lib/activeTool.js.map +1 -0
  62. package/dist/server/lib/agent.js +291 -67
  63. package/dist/server/lib/agent.js.map +1 -1
  64. package/dist/server/lib/agentCatalog.js +92 -4
  65. package/dist/server/lib/agentCatalog.js.map +1 -1
  66. package/dist/server/lib/agentProvider.js +8 -11
  67. package/dist/server/lib/agentProvider.js.map +1 -1
  68. package/dist/server/lib/agentRuns.js +26 -2
  69. package/dist/server/lib/agentRuns.js.map +1 -1
  70. package/dist/server/lib/automationCheckGate.js +6 -0
  71. package/dist/server/lib/automationCheckGate.js.map +1 -1
  72. package/dist/server/lib/buildExecutionEnvironment.js +82 -29
  73. package/dist/server/lib/buildExecutionEnvironment.js.map +1 -1
  74. package/dist/server/lib/buildFlow.js +5 -4
  75. package/dist/server/lib/buildFlow.js.map +1 -1
  76. package/dist/server/lib/buildSequences.js +7 -29
  77. package/dist/server/lib/buildSequences.js.map +1 -1
  78. package/dist/server/lib/buildTicketCommit.js +82 -11
  79. package/dist/server/lib/buildTicketCommit.js.map +1 -1
  80. package/dist/server/lib/bundleReviewOperations.js +6 -0
  81. package/dist/server/lib/bundleReviewOperations.js.map +1 -1
  82. package/dist/server/lib/chatOperations.js +109 -93
  83. package/dist/server/lib/chatOperations.js.map +1 -1
  84. package/dist/server/lib/chatSessionTitle.js +66 -0
  85. package/dist/server/lib/chatSessionTitle.js.map +1 -0
  86. package/dist/server/lib/chats.js +20 -4
  87. package/dist/server/lib/chats.js.map +1 -1
  88. package/dist/server/lib/checkAutoFix.js +65 -61
  89. package/dist/server/lib/checkAutoFix.js.map +1 -1
  90. package/dist/server/lib/codexAgentProvider.js +320 -0
  91. package/dist/server/lib/codexAgentProvider.js.map +1 -0
  92. package/dist/server/lib/codexAppServer.js +678 -0
  93. package/dist/server/lib/codexAppServer.js.map +1 -0
  94. package/dist/server/lib/codexCatalogDiscoveryExecutionEnvironment.js +302 -0
  95. package/dist/server/lib/codexCatalogDiscoveryExecutionEnvironment.js.map +1 -0
  96. package/dist/server/lib/codexDiscovery.js +137 -0
  97. package/dist/server/lib/codexDiscovery.js.map +1 -0
  98. package/dist/server/lib/config.js.map +1 -1
  99. package/dist/server/lib/dockerSandboxEnvironmentOperations.js +2 -2
  100. package/dist/server/lib/dockerSandboxEnvironmentOperations.js.map +1 -1
  101. package/dist/server/lib/dockerSandboxExecutionEnvironment.js +39 -10
  102. package/dist/server/lib/dockerSandboxExecutionEnvironment.js.map +1 -1
  103. package/dist/server/lib/dockerSandboxExecutionProvider.js +3 -1
  104. package/dist/server/lib/dockerSandboxExecutionProvider.js.map +1 -1
  105. package/dist/server/lib/dockerSandboxReleaseProfiles.js +8 -0
  106. package/dist/server/lib/dockerSandboxReleaseProfiles.js.map +1 -1
  107. package/dist/server/lib/executionCredentialCapabilities.js +39 -14
  108. package/dist/server/lib/executionCredentialCapabilities.js.map +1 -1
  109. package/dist/server/lib/executionEnvironment.js.map +1 -1
  110. package/dist/server/lib/executionEnvironmentContexts.js +1 -1
  111. package/dist/server/lib/executionEnvironmentContexts.js.map +1 -1
  112. package/dist/server/lib/executionEnvironmentLifecycle.js +1 -1
  113. package/dist/server/lib/executionEnvironmentLifecycle.js.map +1 -1
  114. package/dist/server/lib/executionEnvironmentReconciliation.js +7 -7
  115. package/dist/server/lib/executionEnvironmentReconciliation.js.map +1 -1
  116. package/dist/server/lib/executionEnvironmentRoutes.js +29 -25
  117. package/dist/server/lib/executionEnvironmentRoutes.js.map +1 -1
  118. package/dist/server/lib/executionEnvironmentValidation.js +205 -20
  119. package/dist/server/lib/executionEnvironmentValidation.js.map +1 -1
  120. package/dist/server/lib/executionEnvironmentValidationOperations.js +34 -29
  121. package/dist/server/lib/executionEnvironmentValidationOperations.js.map +1 -1
  122. package/dist/server/lib/executionEnvironments.js +59 -1
  123. package/dist/server/lib/executionEnvironments.js.map +1 -1
  124. package/dist/server/lib/executionProfiles.js +6 -3
  125. package/dist/server/lib/executionProfiles.js.map +1 -1
  126. package/dist/server/lib/executionRetryPredicates.js +2 -1
  127. package/dist/server/lib/executionRetryPredicates.js.map +1 -1
  128. package/dist/server/lib/executionRunAuthority.js +6 -1
  129. package/dist/server/lib/executionRunAuthority.js.map +1 -1
  130. package/dist/server/lib/genericToolCall.js +131 -9
  131. package/dist/server/lib/genericToolCall.js.map +1 -1
  132. package/dist/server/lib/hostExecutionEnvironment.js +5 -0
  133. package/dist/server/lib/hostExecutionEnvironment.js.map +1 -1
  134. package/dist/server/lib/lightweightPrompt.js +258 -18
  135. package/dist/server/lib/lightweightPrompt.js.map +1 -1
  136. package/dist/server/lib/mobileAccess.js +21 -13
  137. package/dist/server/lib/mobileAccess.js.map +1 -1
  138. package/dist/server/lib/modelResolutionErrors.js +4 -2
  139. package/dist/server/lib/modelResolutionErrors.js.map +1 -1
  140. package/dist/server/lib/models.js +15 -2
  141. package/dist/server/lib/models.js.map +1 -1
  142. package/dist/server/lib/oneShotAgent.js +11 -0
  143. package/dist/server/lib/oneShotAgent.js.map +1 -0
  144. package/dist/server/lib/projectAutoConfig.js +11 -5
  145. package/dist/server/lib/projectAutoConfig.js.map +1 -1
  146. package/dist/server/lib/projectMemory.js +3 -1
  147. package/dist/server/lib/projectMemory.js.map +1 -1
  148. package/dist/server/lib/projectMemoryScan.js +13 -3
  149. package/dist/server/lib/projectMemoryScan.js.map +1 -1
  150. package/dist/server/lib/projectMemoryTransfer.js +5 -2
  151. package/dist/server/lib/projectMemoryTransfer.js.map +1 -1
  152. package/dist/server/lib/promptSkills.js +1 -1
  153. package/dist/server/lib/promptSkills.js.map +1 -1
  154. package/dist/server/lib/run.js +2 -0
  155. package/dist/server/lib/run.js.map +1 -1
  156. package/dist/server/lib/skills.js +21 -4
  157. package/dist/server/lib/skills.js.map +1 -1
  158. package/dist/server/lib/specOperations.js +14 -10
  159. package/dist/server/lib/specOperations.js.map +1 -1
  160. package/dist/server/lib/specReviewOperations.js +20 -11
  161. package/dist/server/lib/specReviewOperations.js.map +1 -1
  162. package/dist/server/lib/specs.js +14 -4
  163. package/dist/server/lib/specs.js.map +1 -1
  164. package/dist/server/lib/ticketAutomationCommit.js +23 -7
  165. package/dist/server/lib/ticketAutomationCommit.js.map +1 -1
  166. package/dist/server/lib/ticketFollowUpOperations.js +7 -0
  167. package/dist/server/lib/ticketFollowUpOperations.js.map +1 -1
  168. package/dist/server/lib/ticketRunOperations.js +11 -1
  169. package/dist/server/lib/ticketRunOperations.js.map +1 -1
  170. package/dist/server/lib/ticketSettingsOperations.js +4 -1
  171. package/dist/server/lib/ticketSettingsOperations.js.map +1 -1
  172. package/dist/server/lib/toolUpgrade.js +1 -0
  173. package/dist/server/lib/toolUpgrade.js.map +1 -1
  174. package/dist/server/lib/transcriptRuns.js +4 -1
  175. package/dist/server/lib/transcriptRuns.js.map +1 -1
  176. package/dist/server/lib/types.js.map +1 -1
  177. package/dist/server/workers/build.js +9 -4
  178. package/dist/server/workers/build.js.map +1 -1
  179. package/dist/server/workers/chat.js +55 -11
  180. package/dist/server/workers/chat.js.map +1 -1
  181. package/dist/server/workers/followUp.js +6 -1
  182. package/dist/server/workers/followUp.js.map +1 -1
  183. package/dist/server/workers/plan.js +235 -68
  184. package/dist/server/workers/plan.js.map +1 -1
  185. package/dist/server/workers/planFollowUp.js +11 -4
  186. package/dist/server/workers/planFollowUp.js.map +1 -1
  187. package/dist/server/workers/review.js +15 -18
  188. package/dist/server/workers/review.js.map +1 -1
  189. package/dist/server/workers/specReview.js +7 -7
  190. package/dist/server/workers/specReview.js.map +1 -1
  191. package/dist/server/workers/specSession.js +8 -12
  192. package/dist/server/workers/specSession.js.map +1 -1
  193. package/package.json +1 -1
  194. package/dist/client/assets/channel-DXKn3TOv.js +0 -1
  195. package/dist/client/assets/classDiagram-4FO5ZUOK-U0fU20hT.js +0 -1
  196. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-C6bQNSxL.js +0 -1
  197. package/dist/client/assets/index-B6BltHSr.css +0 -2
  198. package/dist/client/assets/index-CFOYm3j9.js +0 -276
  199. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-6B8YH8Y2.js +0 -1
@@ -0,0 +1,678 @@
1
+ const DEFAULT_MAX_FRAME_BYTES = 32 * 1024 * 1024;
2
+ const DEFAULT_REQUEST_TIMEOUT_MS = 15_000;
3
+ const INTERRUPT_REQUEST_TIMEOUT_MS = 1_000;
4
+ export class CodexAppServerError extends Error {
5
+ code;
6
+ constructor(message, code = null) {
7
+ super(message);
8
+ this.name = 'CodexAppServerError';
9
+ this.code = code;
10
+ }
11
+ }
12
+ const isObject = (value) => (typeof value === 'object' && value !== null && !Array.isArray(value));
13
+ const asString = (value) => typeof value === 'string' && value.trim() ? value : null;
14
+ const asText = (value) => typeof value === 'string' && value.length > 0 ? value : null;
15
+ const asNumber = (value) => typeof value === 'number' && Number.isFinite(value) ? value : null;
16
+ const asMessagePhase = (value) => value === 'commentary' || value === 'final_answer' ? value : null;
17
+ const asHttpUrl = (value) => {
18
+ const text = asString(value);
19
+ if (!text) {
20
+ return null;
21
+ }
22
+ try {
23
+ const url = new URL(text);
24
+ return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : null;
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ };
30
+ export const redactCodexDiagnostic = (value) => value
31
+ .replace(/(\bauthorization\b\s*[:=]\s*["']?)(?:bearer|basic|token|apikey)\s+[^\s,"'};]+/gi, '$1[REDACTED]')
32
+ .replace(/(\b(?:bearer|basic|token|apikey)\s+)[A-Za-z0-9._~+/=-]+/gi, '$1[REDACTED]')
33
+ .replace(/(["']?\b(?:[a-z][a-z0-9]*_)*(?:api[_-]?key|client[_-]?secret|secret[_-]?access[_-]?key|authorization|auth[_-]?token|access[_-]?token|refresh[_-]?token|id[_-]?token)["']?\s*[:=]\s*)(["'])[^"']*\2/gi, '$1$2[REDACTED]$2')
34
+ .replace(/(["']?\b(?:[a-z][a-z0-9]*_)*(?:api[_-]?key|client[_-]?secret|secret[_-]?access[_-]?key|authorization|auth[_-]?token|access[_-]?token|refresh[_-]?token|id[_-]?token)["']?\s*[:=]\s*)[^\s,;}]+/gi, '$1[REDACTED]')
35
+ .replace(/\b(?:sk|sess|pat|key)-[A-Za-z0-9_-]{8,}\b/gi, '[REDACTED]')
36
+ .replace(/\b(?:github_pat_[A-Za-z0-9_]{20,}|gh[pousr]_[A-Za-z0-9]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}|npm_[A-Za-z0-9]{20,}|AIza[A-Za-z0-9_-]{20,}|(?:AKIA|ASIA)[A-Z0-9]{16})\b/g, '[REDACTED]')
37
+ .replace(/\b(?:[sr]k_(?:live|test)_[A-Za-z0-9]{12,}|SG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,})\b/g, '[REDACTED]')
38
+ .replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, '[REDACTED]')
39
+ .replace(/\bsynthetic-[A-Za-z0-9_-]*?(?:secret|token|key)[A-Za-z0-9_-]*-canary\b/gi, '[REDACTED]');
40
+ const getObject = (value, key) => {
41
+ if (!isObject(value)) {
42
+ return null;
43
+ }
44
+ const nested = value[key];
45
+ return isObject(nested) ? nested : null;
46
+ };
47
+ const getTurnError = (turn) => {
48
+ const error = getObject(turn, 'error');
49
+ return asString(error?.message) ?? asString(error?.additionalDetails);
50
+ };
51
+ const summarizeTool = (item) => {
52
+ const itemType = asString(item.type) ?? 'tool';
53
+ if (itemType === 'commandExecution') {
54
+ return { name: 'command', input: { command: asString(item.command) ?? '', cwd: asString(item.cwd) ?? '' } };
55
+ }
56
+ if (itemType === 'fileChange') {
57
+ return { name: 'fileChange', input: { changes: Array.isArray(item.changes) ? item.changes : [] } };
58
+ }
59
+ if (itemType === 'webSearch') {
60
+ const action = isObject(item.action) ? item.action : null;
61
+ const actionType = asString(action?.type);
62
+ const operation = actionType === 'openPage' || actionType === 'open_page'
63
+ ? 'open_page'
64
+ : actionType === 'findInPage' || actionType === 'find_in_page'
65
+ ? 'find_in_page'
66
+ : actionType === 'search' ? 'search' : null;
67
+ const actionQueries = Array.isArray(action?.queries)
68
+ ? action.queries.flatMap(query => asString(query) ?? [])
69
+ : [];
70
+ const actionQuery = asString(action?.query);
71
+ const itemQuery = asString(item.query);
72
+ const queries = [...new Set([
73
+ ...actionQueries,
74
+ ...(actionQuery ? [actionQuery] : []),
75
+ ...(itemQuery ? [itemQuery] : []),
76
+ ])];
77
+ const results = Array.isArray(item.results) ? item.results.flatMap(result => {
78
+ if (!isObject(result)) {
79
+ return [];
80
+ }
81
+ const url = asHttpUrl(result.url);
82
+ if (!url) {
83
+ return [];
84
+ }
85
+ const refId = asString(result.ref_id) ?? asString(result.refId);
86
+ return [{ url, ...(refId ? { refId } : {}) }];
87
+ }) : [];
88
+ const url = asHttpUrl(action?.url);
89
+ return {
90
+ name: 'webSearch',
91
+ input: {
92
+ ...(operation ? { operation } : {}),
93
+ ...(queries.length === 1 ? { query: queries[0] } : {}),
94
+ ...(queries.length > 1 ? { queries } : {}),
95
+ ...(url ? { url } : {}),
96
+ ...(asString(action?.pattern) ? { pattern: asString(action?.pattern) } : {}),
97
+ ...(results.length > 0 ? { results } : {}),
98
+ },
99
+ };
100
+ }
101
+ if (itemType === 'mcpToolCall' || itemType === 'dynamicToolCall') {
102
+ return {
103
+ name: asString(item.tool) ?? itemType,
104
+ input: isObject(item.arguments) ? item.arguments : {},
105
+ };
106
+ }
107
+ return { name: itemType, input: {} };
108
+ };
109
+ const summarizeToolOutput = (item) => {
110
+ return asString(item.aggregatedOutput)
111
+ ?? asString(item.error)
112
+ ?? (item.result === undefined ? '' : JSON.stringify(item.result));
113
+ };
114
+ const getSubagentStatus = (value) => {
115
+ if (value === 'completed') {
116
+ return 'done';
117
+ }
118
+ if (value === 'failed') {
119
+ return 'error';
120
+ }
121
+ if (value === 'interrupted') {
122
+ return 'stopped';
123
+ }
124
+ return 'running';
125
+ };
126
+ export class CodexAppServer {
127
+ child;
128
+ input;
129
+ output;
130
+ maxFrameBytes;
131
+ requestTimeoutMs;
132
+ onEvent;
133
+ pending = new Map();
134
+ nextId = 1;
135
+ frameChunks = [];
136
+ frameBytes = 0;
137
+ closed = false;
138
+ initialized = false;
139
+ threadId = null;
140
+ turnId = null;
141
+ messageItems = new Map();
142
+ planItems = new Map();
143
+ pendingTurnCompletion = null;
144
+ terminal = null;
145
+ resolveOutcome = null;
146
+ outcomePromise;
147
+ constructor(child, options = {}) {
148
+ if (!child.stdin || !child.stdout) {
149
+ throw new CodexAppServerError('Codex app-server requires piped stdin and stdout.');
150
+ }
151
+ this.child = child;
152
+ this.input = child.stdin;
153
+ this.output = child.stdout;
154
+ this.maxFrameBytes = options.maxFrameBytes ?? DEFAULT_MAX_FRAME_BYTES;
155
+ this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
156
+ this.onEvent = options.onEvent ?? (() => { });
157
+ this.outcomePromise = new Promise(resolve => {
158
+ this.resolveOutcome = resolve;
159
+ });
160
+ this.output.on('data', this.handleData);
161
+ this.input.on('error', this.handleInputError);
162
+ child.once('close', this.handleClose);
163
+ child.once('error', this.handleProcessError);
164
+ }
165
+ handleData = (chunk) => {
166
+ if (this.closed) {
167
+ return;
168
+ }
169
+ const data = Buffer.from(chunk);
170
+ let offset = 0;
171
+ while (offset < data.length) {
172
+ const newline = data.indexOf(0x0a, offset);
173
+ const end = newline === -1 ? data.length : newline;
174
+ const segment = data.subarray(offset, end);
175
+ if (this.frameBytes + segment.length > this.maxFrameBytes) {
176
+ this.failTransport(this.createFrameLimitError());
177
+ return;
178
+ }
179
+ if (segment.length > 0) {
180
+ this.frameChunks.push(segment);
181
+ this.frameBytes += segment.length;
182
+ }
183
+ if (newline === -1) {
184
+ return;
185
+ }
186
+ const frame = this.frameChunks.length === 1
187
+ ? this.frameChunks[0]
188
+ : Buffer.concat(this.frameChunks, this.frameBytes);
189
+ this.frameChunks = [];
190
+ this.frameBytes = 0;
191
+ offset = newline + 1;
192
+ if (frame.length > 0) {
193
+ this.handleFrame(frame.toString('utf8'));
194
+ if (this.closed) {
195
+ return;
196
+ }
197
+ }
198
+ }
199
+ };
200
+ createFrameLimitError() {
201
+ const methods = [...new Set([...this.pending.values()].map(request => request.method))];
202
+ const operation = methods.length === 1 ? ` while awaiting \"${methods[0]}\"` : '';
203
+ return new CodexAppServerError(`Codex app-server frame exceeded ${this.maxFrameBytes} bytes${operation}.`);
204
+ }
205
+ handleFrame(frame) {
206
+ let message;
207
+ try {
208
+ message = JSON.parse(frame);
209
+ }
210
+ catch {
211
+ this.failTransport(new CodexAppServerError('Codex app-server returned malformed JSON.'));
212
+ return;
213
+ }
214
+ if (!isObject(message)) {
215
+ this.failTransport(new CodexAppServerError('Codex app-server returned a non-object frame.'));
216
+ return;
217
+ }
218
+ if ((typeof message.id === 'string' || typeof message.id === 'number') && !asString(message.method)) {
219
+ this.handleResponse(message.id, message);
220
+ return;
221
+ }
222
+ const method = asString(message.method);
223
+ if (!method) {
224
+ return;
225
+ }
226
+ if (typeof message.id === 'string' || typeof message.id === 'number') {
227
+ this.handleServerRequest(message.id, method, isObject(message.params) ? message.params : {});
228
+ return;
229
+ }
230
+ this.handleNotification(method, isObject(message.params) ? message.params : {});
231
+ }
232
+ handleResponse(id, message) {
233
+ const request = this.pending.get(id);
234
+ if (!request) {
235
+ return;
236
+ }
237
+ this.pending.delete(id);
238
+ clearTimeout(request.timer);
239
+ const error = getObject(message, 'error');
240
+ if (error) {
241
+ request.reject(new CodexAppServerError(redactCodexDiagnostic(asString(error.message) ?? 'Codex app-server request failed.'), asNumber(error.code)));
242
+ return;
243
+ }
244
+ if (request.method === 'thread/start' || request.method === 'thread/resume') {
245
+ const threadId = asString(getObject(message.result, 'thread')?.id);
246
+ if (threadId) {
247
+ this.threadId = threadId;
248
+ }
249
+ }
250
+ else if (request.method === 'turn/start') {
251
+ const turnId = asString(getObject(message.result, 'turn')?.id);
252
+ if (turnId) {
253
+ this.turnId = turnId;
254
+ }
255
+ }
256
+ request.resolve(message.result);
257
+ if (request.method === 'turn/start' && this.pendingTurnCompletion) {
258
+ const pendingTurnCompletion = this.pendingTurnCompletion;
259
+ this.pendingTurnCompletion = null;
260
+ this.handleNotification('turn/completed', pendingTurnCompletion);
261
+ }
262
+ }
263
+ handleServerRequest(id, method, params) {
264
+ if (method === 'item/commandExecution/requestApproval' || method === 'item/fileChange/requestApproval') {
265
+ this.send({ id, result: { decision: 'decline' } });
266
+ return;
267
+ }
268
+ if (method === 'mcpServer/elicitation/request') {
269
+ this.send({ id, result: { action: 'decline', content: null, _meta: null } });
270
+ return;
271
+ }
272
+ if (method === 'item/tool/requestUserInput') {
273
+ const questions = Array.isArray(params.questions)
274
+ ? params.questions.flatMap(question => {
275
+ if (!isObject(question)) {
276
+ return [];
277
+ }
278
+ const questionId = asString(question.id);
279
+ const questionText = asString(question.question);
280
+ if (!questionId || !questionText) {
281
+ return [];
282
+ }
283
+ const options = Array.isArray(question.options)
284
+ ? question.options.flatMap(option => isObject(option) && asString(option.label) ? [asString(option.label)] : [])
285
+ : [];
286
+ return [{ id: questionId, question: questionText, suggestions: options }];
287
+ })
288
+ : [];
289
+ if (questions.length > 0) {
290
+ this.onEvent({ type: 'clarification', questions });
291
+ }
292
+ this.send({ id, result: { answers: {} } });
293
+ return;
294
+ }
295
+ if (method === 'item/permissions/requestApproval' || method === 'account/chatgptAuthTokens/refresh') {
296
+ this.send({ id, error: { code: -32601, message: 'Archon does not support this Codex request.' } });
297
+ return;
298
+ }
299
+ this.send({ id, error: { code: -32601, message: 'Unsupported Codex app-server request.' } });
300
+ }
301
+ handleNotification(method, params) {
302
+ if (this.terminal) {
303
+ return;
304
+ }
305
+ if (this.threadId && asString(params.threadId) && params.threadId !== this.threadId) {
306
+ return;
307
+ }
308
+ if (this.turnId && asString(params.turnId) && params.turnId !== this.turnId) {
309
+ return;
310
+ }
311
+ if (method === 'item/agentMessage/delta' || method === 'item/plan/delta') {
312
+ const text = asText(params.delta);
313
+ if (text) {
314
+ const itemId = asString(params.itemId);
315
+ if (method === 'item/plan/delta') {
316
+ if (itemId) {
317
+ this.planItems.set(itemId, `${this.planItems.get(itemId) ?? ''}${text}`);
318
+ }
319
+ this.onEvent({ type: 'plan-update', itemId, text });
320
+ }
321
+ else {
322
+ const item = itemId ? this.messageItems.get(itemId) : null;
323
+ if (itemId) {
324
+ this.messageItems.set(itemId, { phase: item?.phase ?? null, text: `${item?.text ?? ''}${text}` });
325
+ }
326
+ this.onEvent({ type: 'agent-message-delta', itemId, text, phase: item?.phase ?? null });
327
+ }
328
+ }
329
+ return;
330
+ }
331
+ if (method === 'item/reasoning/summaryTextDelta' || method === 'item/reasoning/textDelta') {
332
+ const text = asText(params.delta);
333
+ if (text) {
334
+ const summaryIndex = method === 'item/reasoning/summaryTextDelta'
335
+ ? asNumber(params.summaryIndex)
336
+ : null;
337
+ this.onEvent({
338
+ type: 'reasoning-delta',
339
+ itemId: asString(params.itemId),
340
+ text,
341
+ ...(summaryIndex !== null ? { summaryIndex } : {}),
342
+ });
343
+ }
344
+ return;
345
+ }
346
+ if (method === 'thread/tokenUsage/updated') {
347
+ const tokenUsage = getObject(params, 'tokenUsage');
348
+ const latest = getObject(tokenUsage, 'last');
349
+ this.onEvent({
350
+ type: 'usage',
351
+ latestTotalTokens: asNumber(latest?.totalTokens),
352
+ latestInputTokens: asNumber(latest?.inputTokens),
353
+ latestOutputTokens: asNumber(latest?.outputTokens),
354
+ latestCachedInputTokens: asNumber(latest?.cachedInputTokens),
355
+ latestReasoningTokens: asNumber(latest?.reasoningOutputTokens),
356
+ contextWindow: asNumber(tokenUsage?.modelContextWindow),
357
+ });
358
+ return;
359
+ }
360
+ if (method === 'item/started' || method === 'item/completed') {
361
+ const item = getObject(params, 'item');
362
+ const id = asString(item?.id);
363
+ const itemType = asString(item?.type);
364
+ if (!item || !id || !itemType) {
365
+ return;
366
+ }
367
+ if (itemType === 'agentMessage' || itemType === 'plan') {
368
+ if (itemType === 'agentMessage') {
369
+ const phase = asMessagePhase(item.phase);
370
+ const streamed = this.messageItems.get(id);
371
+ if (method === 'item/started') {
372
+ this.messageItems.set(id, { phase, text: streamed?.text ?? '' });
373
+ }
374
+ else if (!streamed?.text) {
375
+ const text = asText(item.text);
376
+ if (text) {
377
+ this.onEvent({ type: 'agent-message-delta', itemId: id, text, phase });
378
+ }
379
+ }
380
+ }
381
+ else if (method === 'item/completed') {
382
+ const text = asText(item.text);
383
+ const streamedText = this.planItems.get(id) ?? '';
384
+ if (text && text !== streamedText) {
385
+ this.onEvent({ type: 'plan-update', itemId: id, text, snapshot: streamedText.length > 0 });
386
+ }
387
+ }
388
+ return;
389
+ }
390
+ if (itemType === 'reasoning' || itemType === 'userMessage') {
391
+ return;
392
+ }
393
+ if (itemType === 'collabToolCall' || itemType === 'collabAgentToolCall' || itemType === 'subAgentActivity') {
394
+ const receiverIds = Array.isArray(item.receiverThreadIds) ? item.receiverThreadIds : [];
395
+ this.onEvent({
396
+ type: 'subagent',
397
+ id,
398
+ threadId: asString(item.newThreadId) ?? asString(item.receiverThreadId) ?? asString(item.agentThreadId) ?? asString(receiverIds[0]),
399
+ label: asString(item.prompt) ?? asString(item.tool) ?? 'Subagent',
400
+ status: method === 'item/started' ? 'running' : getSubagentStatus(item.status ?? item.kind),
401
+ output: method === 'item/completed' ? summarizeToolOutput(item) || null : null,
402
+ });
403
+ return;
404
+ }
405
+ const tool = summarizeTool(item);
406
+ if (method === 'item/started') {
407
+ this.onEvent({ type: 'tool-started', id, name: tool.name, input: tool.input });
408
+ }
409
+ else {
410
+ this.onEvent({
411
+ type: 'tool-completed',
412
+ id,
413
+ name: tool.name,
414
+ input: tool.input,
415
+ output: summarizeToolOutput(item),
416
+ failed: item.status === 'failed' || item.status === 'declined',
417
+ });
418
+ }
419
+ return;
420
+ }
421
+ if (method === 'turn/completed') {
422
+ const turn = getObject(params, 'turn');
423
+ const turnId = asString(turn?.id);
424
+ const status = asString(turn?.status);
425
+ if (turnId && !this.turnId && [...this.pending.values()].some(request => request.method === 'turn/start')) {
426
+ this.pendingTurnCompletion = params;
427
+ return;
428
+ }
429
+ if (!turn || !turnId || turnId !== this.turnId || !status) {
430
+ return;
431
+ }
432
+ const outcomeStatus = status === 'completed' || status === 'interrupted' || status === 'failed'
433
+ ? status
434
+ : 'failed';
435
+ this.finish({
436
+ status: outcomeStatus,
437
+ threadId: this.threadId ?? '',
438
+ turnId,
439
+ error: getTurnError(turn),
440
+ });
441
+ }
442
+ }
443
+ handleClose = () => {
444
+ this.closed = true;
445
+ const error = new CodexAppServerError('Codex app-server disconnected before the active turn completed.');
446
+ this.rejectPending(error);
447
+ if (this.threadId && this.turnId && !this.terminal) {
448
+ this.finish({ status: 'disconnected', threadId: this.threadId, turnId: this.turnId, error: error.message });
449
+ }
450
+ };
451
+ handleProcessError = (error) => {
452
+ this.failTransport(error);
453
+ };
454
+ handleInputError = (error) => {
455
+ this.failTransport(error);
456
+ };
457
+ failTransport(error) {
458
+ if (this.closed) {
459
+ return;
460
+ }
461
+ this.closed = true;
462
+ this.frameChunks = [];
463
+ this.frameBytes = 0;
464
+ this.output.off('data', this.handleData);
465
+ this.rejectPending(error);
466
+ if (this.threadId && this.turnId && !this.terminal) {
467
+ this.finish({ status: 'disconnected', threadId: this.threadId, turnId: this.turnId, error: error.message });
468
+ }
469
+ this.input.destroy();
470
+ }
471
+ rejectPending(error) {
472
+ for (const pending of this.pending.values()) {
473
+ clearTimeout(pending.timer);
474
+ pending.reject(error);
475
+ }
476
+ this.pending.clear();
477
+ }
478
+ finish(outcome) {
479
+ if (this.terminal) {
480
+ return;
481
+ }
482
+ this.terminal = outcome;
483
+ this.resolveOutcome?.(outcome);
484
+ }
485
+ send(message) {
486
+ if (this.closed || this.input.destroyed) {
487
+ throw new CodexAppServerError('Codex app-server is not connected.');
488
+ }
489
+ this.input.write(`${JSON.stringify(message)}\n`);
490
+ }
491
+ request(method, params = {}, timeoutMs = this.requestTimeoutMs) {
492
+ const id = this.nextId++;
493
+ return new Promise((resolve, reject) => {
494
+ const timer = setTimeout(() => {
495
+ this.pending.delete(id);
496
+ reject(new CodexAppServerError(`Codex app-server request "${method}" timed out.`));
497
+ }, timeoutMs);
498
+ timer.unref?.();
499
+ this.pending.set(id, { method, resolve, reject, timer });
500
+ try {
501
+ this.send({ method, id, params });
502
+ }
503
+ catch (error) {
504
+ clearTimeout(timer);
505
+ this.pending.delete(id);
506
+ reject(error);
507
+ }
508
+ });
509
+ }
510
+ notify(method, params = {}) {
511
+ this.send({ method, params });
512
+ }
513
+ async initialize() {
514
+ if (this.initialized) {
515
+ return;
516
+ }
517
+ await this.request('initialize', {
518
+ clientInfo: { name: 'archon', title: 'Archon', version: '1.0.0' },
519
+ });
520
+ this.notify('initialized');
521
+ this.initialized = true;
522
+ }
523
+ async readAccount() {
524
+ const result = await this.request('account/read', { refreshToken: false });
525
+ const account = getObject(result, 'account');
526
+ const requiresOpenaiAuth = isObject(result) && result.requiresOpenaiAuth === true;
527
+ if (!account) {
528
+ if (requiresOpenaiAuth) {
529
+ return { status: 'reauthentication-required', type: null, accountId: null };
530
+ }
531
+ return { status: 'reauthentication-required', type: null, accountId: null };
532
+ }
533
+ const type = asString(account.type);
534
+ if (type !== 'chatgpt' && type !== 'apiKey' && type !== 'amazonBedrock') {
535
+ return { status: 'reauthentication-required', type: null, accountId: null };
536
+ }
537
+ return {
538
+ status: 'authenticated',
539
+ type,
540
+ accountId: type === 'chatgpt' ? asString(account.email) : null,
541
+ };
542
+ }
543
+ async listModels() {
544
+ const models = [];
545
+ let cursor = null;
546
+ do {
547
+ const result = await this.request('model/list', {
548
+ limit: 100,
549
+ includeHidden: false,
550
+ ...(cursor ? { cursor } : {}),
551
+ });
552
+ const page = isObject(result) ? result : null;
553
+ for (const entry of Array.isArray(page?.data) ? page.data : []) {
554
+ if (!isObject(entry)) {
555
+ continue;
556
+ }
557
+ const id = asString(entry.id) ?? asString(entry.model);
558
+ if (!id || /[\s/]/.test(id)) {
559
+ continue;
560
+ }
561
+ const supportedReasoningEfforts = Array.isArray(entry.supportedReasoningEfforts)
562
+ ? entry.supportedReasoningEfforts.flatMap(option => {
563
+ const effort = isObject(option) ? asString(option.reasoningEffort) : asString(option);
564
+ return effort && !/[\s/]/.test(effort) ? [effort] : [];
565
+ })
566
+ : [];
567
+ const defaultReasoningEffort = asString(entry.defaultReasoningEffort);
568
+ const inputModalities = Array.isArray(entry.inputModalities)
569
+ ? entry.inputModalities.flatMap(modality => asString(modality) ?? [])
570
+ : [];
571
+ models.push({
572
+ id,
573
+ displayName: asString(entry.displayName) ?? id,
574
+ supportedReasoningEfforts: [...new Set(supportedReasoningEfforts)],
575
+ defaultReasoningEffort: defaultReasoningEffort && supportedReasoningEfforts.includes(defaultReasoningEffort)
576
+ ? defaultReasoningEffort
577
+ : null,
578
+ inputModalities: [...new Set(inputModalities)],
579
+ });
580
+ }
581
+ cursor = asString(page?.nextCursor);
582
+ } while (cursor);
583
+ return models;
584
+ }
585
+ async listSkills(cwd) {
586
+ const result = await this.request('skills/list', { cwds: [cwd], forceReload: false });
587
+ const page = isObject(result) ? result : null;
588
+ const containers = Array.isArray(page?.data) ? page.data : [];
589
+ const skills = [];
590
+ for (const container of containers) {
591
+ const entries = isObject(container) && Array.isArray(container.skills)
592
+ ? container.skills
593
+ : isObject(container) ? [container] : [];
594
+ for (const entry of entries) {
595
+ if (!isObject(entry) || entry.enabled === false) {
596
+ continue;
597
+ }
598
+ const name = asString(entry.name);
599
+ const description = asString(entry.description) ?? asString(entry.shortDescription);
600
+ const path = asString(entry.path);
601
+ if (name && description && path) {
602
+ skills.push({ name, description, path });
603
+ }
604
+ }
605
+ }
606
+ return skills;
607
+ }
608
+ async startThread(options) {
609
+ const params = {
610
+ ...(options.resumeThreadId ? { threadId: options.resumeThreadId } : {}),
611
+ ...(options.model ? { model: options.model } : {}),
612
+ cwd: options.cwd,
613
+ approvalPolicy: 'never',
614
+ sandbox: options.mode === 'plan' ? 'read-only' : 'workspace-write',
615
+ serviceName: 'archon',
616
+ };
617
+ const result = await this.request(options.resumeThreadId ? 'thread/resume' : 'thread/start', params);
618
+ const thread = getObject(result, 'thread');
619
+ const threadId = asString(thread?.id);
620
+ if (!threadId || (options.resumeThreadId && threadId !== options.resumeThreadId)) {
621
+ throw new CodexAppServerError('Codex did not establish the requested thread identity.');
622
+ }
623
+ this.threadId = threadId;
624
+ return threadId;
625
+ }
626
+ async startTurn(options) {
627
+ if (!this.threadId) {
628
+ throw new CodexAppServerError('Codex thread must be established before starting a turn.');
629
+ }
630
+ const input = [{ type: 'text', text: options.prompt }];
631
+ for (const file of options.files ?? []) {
632
+ input.push({ type: 'localImage', path: file });
633
+ }
634
+ for (const skill of options.skills ?? []) {
635
+ input.push({ type: 'skill', name: skill.name, path: skill.path });
636
+ }
637
+ const sandboxPolicy = options.mode === 'plan'
638
+ ? { type: 'readOnly', access: { type: 'fullAccess' } }
639
+ : { type: 'workspaceWrite', writableRoots: [options.cwd], networkAccess: true };
640
+ const reasoningEffort = options.reasoningEffort;
641
+ if (reasoningEffort && options.supportedReasoningEfforts && !options.supportedReasoningEfforts.includes(reasoningEffort)) {
642
+ throw new CodexAppServerError(`Reasoning effort "${reasoningEffort}" is not supported by the selected Codex model.`);
643
+ }
644
+ const result = await this.request('turn/start', {
645
+ threadId: this.threadId,
646
+ input,
647
+ cwd: options.cwd,
648
+ approvalPolicy: 'never',
649
+ sandboxPolicy,
650
+ ...(options.model ? { model: options.model } : {}),
651
+ ...(reasoningEffort ? { effort: reasoningEffort } : {}),
652
+ summary: 'concise',
653
+ });
654
+ const turn = getObject(result, 'turn');
655
+ const turnId = asString(turn?.id);
656
+ if (!turnId) {
657
+ throw new CodexAppServerError('Codex did not return a turn identity.');
658
+ }
659
+ this.turnId = turnId;
660
+ return turnId;
661
+ }
662
+ waitForTurn() {
663
+ return this.outcomePromise;
664
+ }
665
+ async interruptTurn() {
666
+ if (!this.threadId || !this.turnId || this.terminal) {
667
+ return false;
668
+ }
669
+ await this.request('turn/interrupt', { threadId: this.threadId, turnId: this.turnId }, INTERRUPT_REQUEST_TIMEOUT_MS);
670
+ return true;
671
+ }
672
+ closeInput() {
673
+ if (!this.input.destroyed) {
674
+ this.input.end();
675
+ }
676
+ }
677
+ }
678
+ //# sourceMappingURL=codexAppServer.js.map