@microvac/adapter-codex-local 0.0.0-stage → 0.1.0-rc.14

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 (300) hide show
  1. package/dist/cli/format-event.d.ts +2 -0
  2. package/dist/cli/format-event.d.ts.map +1 -0
  3. package/dist/cli/format-event.js +218 -0
  4. package/dist/cli/format-event.js.map +1 -0
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +2 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/cli/quota-probe.d.ts +3 -0
  10. package/dist/cli/quota-probe.d.ts.map +1 -0
  11. package/dist/cli/quota-probe.js +104 -0
  12. package/dist/cli/quota-probe.js.map +1 -0
  13. package/dist/index.d.ts +41 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +268 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/index.test.d.ts +2 -0
  18. package/dist/index.test.d.ts.map +1 -0
  19. package/dist/index.test.js +125 -0
  20. package/dist/index.test.js.map +1 -0
  21. package/dist/server/acp.cli-version.test.d.ts +2 -0
  22. package/dist/server/acp.cli-version.test.d.ts.map +1 -0
  23. package/dist/server/acp.cli-version.test.js +151 -0
  24. package/dist/server/acp.cli-version.test.js.map +1 -0
  25. package/dist/server/acp.d.ts +31 -0
  26. package/dist/server/acp.d.ts.map +1 -0
  27. package/dist/server/acp.js +608 -0
  28. package/dist/server/acp.js.map +1 -0
  29. package/dist/server/acp.quota.test.d.ts +2 -0
  30. package/dist/server/acp.quota.test.d.ts.map +1 -0
  31. package/dist/server/acp.quota.test.js +176 -0
  32. package/dist/server/acp.quota.test.js.map +1 -0
  33. package/dist/server/acp.test.d.ts +2 -0
  34. package/dist/server/acp.test.d.ts.map +1 -0
  35. package/dist/server/acp.test.js +1263 -0
  36. package/dist/server/acp.test.js.map +1 -0
  37. package/dist/server/adapter-auth-promotion.d.ts +102 -0
  38. package/dist/server/adapter-auth-promotion.d.ts.map +1 -0
  39. package/dist/server/adapter-auth-promotion.js +210 -0
  40. package/dist/server/adapter-auth-promotion.js.map +1 -0
  41. package/dist/server/adapter-auth-promotion.test.d.ts +2 -0
  42. package/dist/server/adapter-auth-promotion.test.d.ts.map +1 -0
  43. package/dist/server/adapter-auth-promotion.test.js +615 -0
  44. package/dist/server/adapter-auth-promotion.test.js.map +1 -0
  45. package/dist/server/auth-check.d.ts +8 -0
  46. package/dist/server/auth-check.d.ts.map +1 -0
  47. package/dist/server/auth-check.js +8 -0
  48. package/dist/server/auth-check.js.map +1 -0
  49. package/dist/server/auth-precedence.d.ts +16 -0
  50. package/dist/server/auth-precedence.d.ts.map +1 -0
  51. package/dist/server/auth-precedence.js +20 -0
  52. package/dist/server/auth-precedence.js.map +1 -0
  53. package/dist/server/auth-precedence.test.d.ts +2 -0
  54. package/dist/server/auth-precedence.test.d.ts.map +1 -0
  55. package/dist/server/auth-precedence.test.js +100 -0
  56. package/dist/server/auth-precedence.test.js.map +1 -0
  57. package/dist/server/cli-version.d.ts +45 -0
  58. package/dist/server/cli-version.d.ts.map +1 -0
  59. package/dist/server/cli-version.js +95 -0
  60. package/dist/server/cli-version.js.map +1 -0
  61. package/dist/server/codex-args.d.ts +13 -0
  62. package/dist/server/codex-args.d.ts.map +1 -0
  63. package/dist/server/codex-args.js +64 -0
  64. package/dist/server/codex-args.js.map +1 -0
  65. package/dist/server/codex-args.test.d.ts +2 -0
  66. package/dist/server/codex-args.test.d.ts.map +1 -0
  67. package/dist/server/codex-args.test.js +257 -0
  68. package/dist/server/codex-args.test.js.map +1 -0
  69. package/dist/server/codex-auth-cache.d.ts +179 -0
  70. package/dist/server/codex-auth-cache.d.ts.map +1 -0
  71. package/dist/server/codex-auth-cache.js +520 -0
  72. package/dist/server/codex-auth-cache.js.map +1 -0
  73. package/dist/server/codex-auth-cache.test.d.ts +2 -0
  74. package/dist/server/codex-auth-cache.test.d.ts.map +1 -0
  75. package/dist/server/codex-auth-cache.test.js +530 -0
  76. package/dist/server/codex-auth-cache.test.js.map +1 -0
  77. package/dist/server/codex-auth-copyback.d.ts +53 -0
  78. package/dist/server/codex-auth-copyback.d.ts.map +1 -0
  79. package/dist/server/codex-auth-copyback.js +123 -0
  80. package/dist/server/codex-auth-copyback.js.map +1 -0
  81. package/dist/server/codex-auth-copyback.test.d.ts +2 -0
  82. package/dist/server/codex-auth-copyback.test.d.ts.map +1 -0
  83. package/dist/server/codex-auth-copyback.test.js +507 -0
  84. package/dist/server/codex-auth-copyback.test.js.map +1 -0
  85. package/dist/server/codex-auth-merge-decision.cjs +170 -0
  86. package/dist/server/codex-auth-merge-decision.d.ts +22 -0
  87. package/dist/server/codex-auth-merge-decision.d.ts.map +1 -0
  88. package/dist/server/codex-auth-merge-decision.js +58 -0
  89. package/dist/server/codex-auth-merge-decision.js.map +1 -0
  90. package/dist/server/codex-auth-merge-decision.test.d.ts +2 -0
  91. package/dist/server/codex-auth-merge-decision.test.d.ts.map +1 -0
  92. package/dist/server/codex-auth-merge-decision.test.js +215 -0
  93. package/dist/server/codex-auth-merge-decision.test.js.map +1 -0
  94. package/dist/server/codex-auth-merge-extract.sh +73 -0
  95. package/dist/server/codex-auth-merge-scripts.d.ts +21 -0
  96. package/dist/server/codex-auth-merge-scripts.d.ts.map +1 -0
  97. package/dist/server/codex-auth-merge-scripts.js +40 -0
  98. package/dist/server/codex-auth-merge-scripts.js.map +1 -0
  99. package/dist/server/codex-auth-merge.test.d.ts +2 -0
  100. package/dist/server/codex-auth-merge.test.d.ts.map +1 -0
  101. package/dist/server/codex-auth-merge.test.js +714 -0
  102. package/dist/server/codex-auth-merge.test.js.map +1 -0
  103. package/dist/server/codex-auth-seed-write.d.ts +30 -0
  104. package/dist/server/codex-auth-seed-write.d.ts.map +1 -0
  105. package/dist/server/codex-auth-seed-write.js +41 -0
  106. package/dist/server/codex-auth-seed-write.js.map +1 -0
  107. package/dist/server/codex-home.d.ts +169 -0
  108. package/dist/server/codex-home.d.ts.map +1 -0
  109. package/dist/server/codex-home.js +822 -0
  110. package/dist/server/codex-home.js.map +1 -0
  111. package/dist/server/codex-home.test.d.ts +2 -0
  112. package/dist/server/codex-home.test.d.ts.map +1 -0
  113. package/dist/server/codex-home.test.js +1287 -0
  114. package/dist/server/codex-home.test.js.map +1 -0
  115. package/dist/server/config-schema.d.ts +3 -0
  116. package/dist/server/config-schema.d.ts.map +1 -0
  117. package/dist/server/config-schema.js +67 -0
  118. package/dist/server/config-schema.js.map +1 -0
  119. package/dist/server/device-login-export.d.ts +56 -0
  120. package/dist/server/device-login-export.d.ts.map +1 -0
  121. package/dist/server/device-login-export.js +230 -0
  122. package/dist/server/device-login-export.js.map +1 -0
  123. package/dist/server/device-login-export.test.d.ts +2 -0
  124. package/dist/server/device-login-export.test.d.ts.map +1 -0
  125. package/dist/server/device-login-export.test.js +245 -0
  126. package/dist/server/device-login-export.test.js.map +1 -0
  127. package/dist/server/device-login-parse.d.ts +20 -0
  128. package/dist/server/device-login-parse.d.ts.map +1 -0
  129. package/dist/server/device-login-parse.js +155 -0
  130. package/dist/server/device-login-parse.js.map +1 -0
  131. package/dist/server/device-login-parse.test.d.ts +2 -0
  132. package/dist/server/device-login-parse.test.d.ts.map +1 -0
  133. package/dist/server/device-login-parse.test.js +269 -0
  134. package/dist/server/device-login-parse.test.js.map +1 -0
  135. package/dist/server/device-login-runner.d.ts +69 -0
  136. package/dist/server/device-login-runner.d.ts.map +1 -0
  137. package/dist/server/device-login-runner.js +110 -0
  138. package/dist/server/device-login-runner.js.map +1 -0
  139. package/dist/server/device-login-runner.test.d.ts +2 -0
  140. package/dist/server/device-login-runner.test.d.ts.map +1 -0
  141. package/dist/server/device-login-runner.test.js +201 -0
  142. package/dist/server/device-login-runner.test.js.map +1 -0
  143. package/dist/server/engine-availability.test.d.ts +2 -0
  144. package/dist/server/engine-availability.test.d.ts.map +1 -0
  145. package/dist/server/engine-availability.test.js +41 -0
  146. package/dist/server/engine-availability.test.js.map +1 -0
  147. package/dist/server/execute.acp-fallback.test.d.ts +2 -0
  148. package/dist/server/execute.acp-fallback.test.d.ts.map +1 -0
  149. package/dist/server/execute.acp-fallback.test.js +123 -0
  150. package/dist/server/execute.acp-fallback.test.js.map +1 -0
  151. package/dist/server/execute.auth-precedence.test.d.ts +2 -0
  152. package/dist/server/execute.auth-precedence.test.d.ts.map +1 -0
  153. package/dist/server/execute.auth-precedence.test.js +137 -0
  154. package/dist/server/execute.auth-precedence.test.js.map +1 -0
  155. package/dist/server/execute.auth.test.d.ts +2 -0
  156. package/dist/server/execute.auth.test.d.ts.map +1 -0
  157. package/dist/server/execute.auth.test.js +197 -0
  158. package/dist/server/execute.auth.test.js.map +1 -0
  159. package/dist/server/execute.d.ts +40 -0
  160. package/dist/server/execute.d.ts.map +1 -0
  161. package/dist/server/execute.js +1485 -0
  162. package/dist/server/execute.js.map +1 -0
  163. package/dist/server/execute.remote.test.d.ts +2 -0
  164. package/dist/server/execute.remote.test.d.ts.map +1 -0
  165. package/dist/server/execute.remote.test.js +851 -0
  166. package/dist/server/execute.remote.test.js.map +1 -0
  167. package/dist/server/execute.ssh-host-auth.test.d.ts +2 -0
  168. package/dist/server/execute.ssh-host-auth.test.d.ts.map +1 -0
  169. package/dist/server/execute.ssh-host-auth.test.js +214 -0
  170. package/dist/server/execute.ssh-host-auth.test.js.map +1 -0
  171. package/dist/server/execute.stderr-error.test.d.ts +2 -0
  172. package/dist/server/execute.stderr-error.test.d.ts.map +1 -0
  173. package/dist/server/execute.stderr-error.test.js +142 -0
  174. package/dist/server/execute.stderr-error.test.js.map +1 -0
  175. package/dist/server/execute.test.d.ts +2 -0
  176. package/dist/server/execute.test.d.ts.map +1 -0
  177. package/dist/server/execute.test.js +300 -0
  178. package/dist/server/execute.test.js.map +1 -0
  179. package/dist/server/index.d.ts +18 -0
  180. package/dist/server/index.d.ts.map +1 -0
  181. package/dist/server/index.js +84 -0
  182. package/dist/server/index.js.map +1 -0
  183. package/dist/server/output-inactivity-monitor.d.ts +62 -0
  184. package/dist/server/output-inactivity-monitor.d.ts.map +1 -0
  185. package/dist/server/output-inactivity-monitor.integration.test.d.ts +2 -0
  186. package/dist/server/output-inactivity-monitor.integration.test.d.ts.map +1 -0
  187. package/dist/server/output-inactivity-monitor.integration.test.js +136 -0
  188. package/dist/server/output-inactivity-monitor.integration.test.js.map +1 -0
  189. package/dist/server/output-inactivity-monitor.js +112 -0
  190. package/dist/server/output-inactivity-monitor.js.map +1 -0
  191. package/dist/server/output-inactivity-monitor.test.d.ts +2 -0
  192. package/dist/server/output-inactivity-monitor.test.d.ts.map +1 -0
  193. package/dist/server/output-inactivity-monitor.test.js +284 -0
  194. package/dist/server/output-inactivity-monitor.test.js.map +1 -0
  195. package/dist/server/parse.d.ts +69 -0
  196. package/dist/server/parse.d.ts.map +1 -0
  197. package/dist/server/parse.js +278 -0
  198. package/dist/server/parse.js.map +1 -0
  199. package/dist/server/parse.test.d.ts +2 -0
  200. package/dist/server/parse.test.d.ts.map +1 -0
  201. package/dist/server/parse.test.js +203 -0
  202. package/dist/server/parse.test.js.map +1 -0
  203. package/dist/server/process-activity-monitor.d.ts +21 -0
  204. package/dist/server/process-activity-monitor.d.ts.map +1 -0
  205. package/dist/server/process-activity-monitor.js +103 -0
  206. package/dist/server/process-activity-monitor.js.map +1 -0
  207. package/dist/server/process-activity-monitor.test.d.ts +2 -0
  208. package/dist/server/process-activity-monitor.test.d.ts.map +1 -0
  209. package/dist/server/process-activity-monitor.test.js +82 -0
  210. package/dist/server/process-activity-monitor.test.js.map +1 -0
  211. package/dist/server/quota-spawn-error.test.d.ts +2 -0
  212. package/dist/server/quota-spawn-error.test.d.ts.map +1 -0
  213. package/dist/server/quota-spawn-error.test.js +343 -0
  214. package/dist/server/quota-spawn-error.test.js.map +1 -0
  215. package/dist/server/quota.d.ts +66 -0
  216. package/dist/server/quota.d.ts.map +1 -0
  217. package/dist/server/quota.js +577 -0
  218. package/dist/server/quota.js.map +1 -0
  219. package/dist/server/runtime-config.d.ts +11 -0
  220. package/dist/server/runtime-config.d.ts.map +1 -0
  221. package/dist/server/runtime-config.js +389 -0
  222. package/dist/server/runtime-config.js.map +1 -0
  223. package/dist/server/runtime-config.test.d.ts +2 -0
  224. package/dist/server/runtime-config.test.d.ts.map +1 -0
  225. package/dist/server/runtime-config.test.js +389 -0
  226. package/dist/server/runtime-config.test.js.map +1 -0
  227. package/dist/server/skills.d.ts +8 -0
  228. package/dist/server/skills.d.ts.map +1 -0
  229. package/dist/server/skills.js +26 -0
  230. package/dist/server/skills.js.map +1 -0
  231. package/dist/server/ssh-host-runtime.d.ts +24 -0
  232. package/dist/server/ssh-host-runtime.d.ts.map +1 -0
  233. package/dist/server/ssh-host-runtime.js +84 -0
  234. package/dist/server/ssh-host-runtime.js.map +1 -0
  235. package/dist/server/ssh-session-state.d.ts +18 -0
  236. package/dist/server/ssh-session-state.d.ts.map +1 -0
  237. package/dist/server/ssh-session-state.js +11 -0
  238. package/dist/server/ssh-session-state.js.map +1 -0
  239. package/dist/server/test.d.ts +3 -0
  240. package/dist/server/test.d.ts.map +1 -0
  241. package/dist/server/test.js +531 -0
  242. package/dist/server/test.js.map +1 -0
  243. package/dist/server/test.remote.test.d.ts +2 -0
  244. package/dist/server/test.remote.test.d.ts.map +1 -0
  245. package/dist/server/test.remote.test.js +596 -0
  246. package/dist/server/test.remote.test.js.map +1 -0
  247. package/dist/ui/build-config.d.ts +10 -0
  248. package/dist/ui/build-config.d.ts.map +1 -0
  249. package/dist/ui/build-config.js +284 -0
  250. package/dist/ui/build-config.js.map +1 -0
  251. package/dist/ui/build-config.test.d.ts +2 -0
  252. package/dist/ui/build-config.test.d.ts.map +1 -0
  253. package/dist/ui/build-config.test.js +367 -0
  254. package/dist/ui/build-config.test.js.map +1 -0
  255. package/dist/ui/index.d.ts +4 -0
  256. package/dist/ui/index.d.ts.map +1 -0
  257. package/dist/ui/index.js +8 -0
  258. package/dist/ui/index.js.map +1 -0
  259. package/dist/ui/parse-stdout.d.ts +3 -0
  260. package/dist/ui/parse-stdout.d.ts.map +1 -0
  261. package/dist/ui/parse-stdout.js +265 -0
  262. package/dist/ui/parse-stdout.js.map +1 -0
  263. package/dist/ui/parse-stdout.test.d.ts +2 -0
  264. package/dist/ui/parse-stdout.test.d.ts.map +1 -0
  265. package/dist/ui/parse-stdout.test.js +77 -0
  266. package/dist/ui/parse-stdout.test.js.map +1 -0
  267. package/package.json +55 -4
  268. package/skills/agentmail/SKILL.md +70 -0
  269. package/skills/complain/LICENSE +27 -0
  270. package/skills/complain/SKILL.md +68 -0
  271. package/skills/paperclip/SKILL.md +864 -0
  272. package/skills/paperclip/references/api-reference.md +1814 -0
  273. package/skills/paperclip/references/artifacts.md +163 -0
  274. package/skills/paperclip/references/cases.md +570 -0
  275. package/skills/paperclip/references/company-skills.md +266 -0
  276. package/skills/paperclip/references/issue-documents.md +58 -0
  277. package/skills/paperclip/references/issue-workspaces.md +94 -0
  278. package/skills/paperclip/references/routines.md +249 -0
  279. package/skills/paperclip/references/run-diagnostics.md +28 -0
  280. package/skills/paperclip/references/workflows.md +141 -0
  281. package/skills/paperclip/scripts/paperclip-issue-update.sh +166 -0
  282. package/skills/paperclip/scripts/paperclip-upload-artifact.sh +603 -0
  283. package/skills/paperclip/scripts/submit-agent-commentary.mjs +52 -0
  284. package/skills/paperclip-board/SKILL.md +633 -0
  285. package/skills/paperclip-converting-plans-to-tasks/SKILL.md +28 -0
  286. package/skills/paperclip-create-agent/SKILL.md +213 -0
  287. package/skills/paperclip-create-agent/references/agent-instruction-templates.md +24 -0
  288. package/skills/paperclip-create-agent/references/agents/coder.md +18 -0
  289. package/skills/paperclip-create-agent/references/agents/qa.md +18 -0
  290. package/skills/paperclip-create-agent/references/agents/securityengineer.md +26 -0
  291. package/skills/paperclip-create-agent/references/agents/uxdesigner.md +18 -0
  292. package/skills/paperclip-create-agent/references/api-reference.md +110 -0
  293. package/skills/paperclip-create-agent/references/baseline-role-guide.md +22 -0
  294. package/skills/paperclip-create-agent/references/draft-review-checklist.md +29 -0
  295. package/skills/para-memory-files/SKILL.md +100 -0
  296. package/skills/para-memory-files/references/schemas.md +35 -0
  297. package/skills/slack/SKILL.md +92 -0
  298. package/skills/suggestion-box/LICENSE +27 -0
  299. package/skills/suggestion-box/SKILL.md +77 -0
  300. package/README.md +0 -3
@@ -0,0 +1,31 @@
1
+ import type { AdapterBillingType, AdapterEnvironmentTestContext, AdapterEnvironmentTestResult, AdapterExecutionContext, AdapterExecutionResult } from "@paperclipai/adapter-utils";
2
+ import type { AcpxEngineExecutorOptions, AcpxTerminalFailureClassification, AcpxTerminalSessionFailure } from "@paperclipai/adapter-utils/acpx-engine/execute";
3
+ export type CodexExecutionEngine = "cli" | "acp";
4
+ export interface CodexEngineSelection {
5
+ engine: CodexExecutionEngine;
6
+ explicit: boolean;
7
+ unavailableReason?: string;
8
+ }
9
+ type CodexEngineResolutionInput = Pick<AdapterExecutionContext, "config"> & Partial<Pick<AdapterExecutionContext, "executionTarget" | "executionTransport">>;
10
+ type CodexAcpExecutorOptions = Omit<AcpxEngineExecutorOptions, "adapterType" | "moduleDir" | "packageRootDir">;
11
+ type CodexAcpExecutor = (ctx: AdapterExecutionContext) => Promise<AdapterExecutionResult>;
12
+ export declare function resolveCodexExecutionEngine(config: Record<string, unknown>): CodexEngineSelection;
13
+ export declare function resolveCodexExecutionEngineForRun(input: CodexEngineResolutionInput): Promise<CodexEngineSelection>;
14
+ export declare function buildCodexAcpConfig(config: Record<string, unknown>): Record<string, unknown>;
15
+ export declare function classifyCodexTerminalSessionFailure(failure: AcpxTerminalSessionFailure, now: Date): AcpxTerminalFailureClassification | null;
16
+ /**
17
+ * Classify billing the same way the Codex CLI lane does so ACP runs land in
18
+ * the cost ledger with a real provider/billingType instead of acpx/unknown.
19
+ * Host env only counts for local execution targets; remote targets see just
20
+ * the adapter-config env.
21
+ */
22
+ export declare function resolveCodexAcpBillingIdentity(ctx: Pick<AdapterExecutionContext, "config"> & Partial<Pick<AdapterExecutionContext, "executionTarget" | "executionTransport">>): {
23
+ provider: string;
24
+ biller: string;
25
+ billingType: AdapterBillingType;
26
+ };
27
+ export declare function createCodexAcpExecutor(options?: CodexAcpExecutorOptions): CodexAcpExecutor;
28
+ export declare function nodeVersionMeetsCodexAcpMinimum(version?: string): boolean;
29
+ export declare function testCodexAcpEnvironment(ctx: AdapterEnvironmentTestContext): Promise<AdapterEnvironmentTestResult>;
30
+ export {};
31
+ //# sourceMappingURL=acp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp.d.ts","sourceRoot":"","sources":["../../src/server/acp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAElB,6BAA6B,EAC7B,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAiBpC,OAAO,KAAK,EACV,yBAAyB,EAGzB,iCAAiC,EACjC,0BAA0B,EAC3B,MAAM,gDAAgD,CAAC;AAwBxD,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,KAAK,CAAC;AAEjD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,KAAK,0BAA0B,GAC7B,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,GACvC,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,iBAAiB,GAAG,oBAAoB,CAAC,CAAC,CAAC;AAEnF,KAAK,uBAAuB,GAAG,IAAI,CACjC,yBAAyB,EACzB,aAAa,GAAG,WAAW,GAAG,gBAAgB,CAC/C,CAAC;AAEF,KAAK,gBAAgB,GAAG,CAAC,GAAG,EAAE,uBAAuB,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAS1F,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,oBAAoB,CAEjG;AAED,wBAAsB,iCAAiC,CACrD,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,oBAAoB,CAAC,CAuB/B;AAWD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwC5F;AAwHD,wBAAgB,mCAAmC,CACjD,OAAO,EAAE,0BAA0B,EACnC,GAAG,EAAE,IAAI,GACR,iCAAiC,GAAG,IAAI,CAyB1C;AAqCD;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,GAC1C,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,iBAAiB,GAAG,oBAAoB,CAAC,CAAC,GACjF;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,kBAAkB,CAAA;CAAE,CAyBvE;AAED,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAe9F;AAQD,wBAAgB,+BAA+B,CAAC,OAAO,SAAkB,GAAG,OAAO,CAMlF;AA4HD,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,6BAA6B,GACjC,OAAO,CAAC,4BAA4B,CAAC,CAuLvC"}
@@ -0,0 +1,608 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { parseLocalProcessFilesystemScope, parseLocalProcessNetworkScope, } from "@paperclipai/adapter-utils/local-process-sandbox";
5
+ import { inferOpenAiCompatibleBiller, resolveManagedOpenAiBilling } from "@paperclipai/adapter-utils";
6
+ import { ensureAdapterExecutionTargetCommandResolvable, readAdapterExecutionTarget, resolveAdapterExecutionTargetCwd, } from "@paperclipai/adapter-utils/execution-target";
7
+ import { DEFAULT_ACP_ENGINE_MODE, DEFAULT_ACP_ENGINE_NON_INTERACTIVE_PERMISSIONS, DEFAULT_ACP_ENGINE_PERMISSION_MODE, DEFAULT_ACP_ENGINE_WARM_HANDLE_IDLE_MS, } from "@paperclipai/adapter-utils/acpx-engine/constants";
8
+ import { asNumber, asString, asStringArray, parseObject, } from "@paperclipai/adapter-utils/server-utils";
9
+ import { createWorkspaceRestoreTeardown } from "@paperclipai/adapter-utils/workspace-restore-teardown";
10
+ import { normalizeCodexModel } from "../index.js";
11
+ import { classifyCodexAuthRefreshFailure, extractCodexRetryNotBefore } from "./parse.js";
12
+ import { copyBackCodexAuth } from "./codex-auth-copyback.js";
13
+ import { buildCodexHomeRefreshProvision, evaluateCodexCredentialReadiness, resolveSharedCodexHomeDir, stageCodexHomeForSync, } from "./codex-home.js";
14
+ import { ADAPTER_AUTH_MISSING_CHECK_CODE } from "./auth-check.js";
15
+ import { checkCodexCliVersionForModel } from "./cli-version.js";
16
+ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
17
+ const packageRootDir = path.resolve(moduleDir, "../..");
18
+ const MIN_ACP_NODE_VERSION = "24.11.0";
19
+ function normalizeEngine(value) {
20
+ const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
21
+ if (raw === "acp")
22
+ return { engine: "acp", explicit: true };
23
+ if (raw === "cli")
24
+ return { engine: "cli", explicit: true };
25
+ return { engine: "acp", explicit: false };
26
+ }
27
+ export function resolveCodexExecutionEngine(config) {
28
+ return normalizeEngine(config.engine);
29
+ }
30
+ export async function resolveCodexExecutionEngineForRun(input) {
31
+ const selection = normalizeEngine(input.config.engine);
32
+ // Engine availability must never change the agent's execution or permission contract.
33
+ if (selection.engine === "cli")
34
+ return selection;
35
+ const unavailable = (reason) => ({
36
+ ...selection,
37
+ unavailableReason: `${reason} Repair the ACP setup, or explicitly set engine=cli to use the CLI engine.`,
38
+ });
39
+ const target = readAdapterExecutionTarget({
40
+ executionTarget: input.executionTarget,
41
+ legacyRemoteExecution: input.executionTransport?.remoteExecution,
42
+ });
43
+ if (target?.workspaceRealization?.mode === "in_place" && !(target.kind === "remote" && target.transport === "ssh")) {
44
+ return unavailable("In-place workspace realization requires the Codex CLI engine; ACP archive staging is not supported.");
45
+ }
46
+ const filesystemScope = parseLocalProcessFilesystemScope(input.config.filesystemScope);
47
+ const networkScope = parseLocalProcessNetworkScope(input.config.networkScope);
48
+ if (filesystemScope || networkScope) {
49
+ return unavailable("Local filesystem/network confinement requires the Codex CLI engine; ACP confinement is not supported.");
50
+ }
51
+ const reason = await codexAcpUnavailableReason(input);
52
+ return reason ? unavailable(reason) : selection;
53
+ }
54
+ function firstNonEmptyString(...values) {
55
+ for (const value of values) {
56
+ if (typeof value !== "string")
57
+ continue;
58
+ const trimmed = value.trim();
59
+ if (trimmed.length > 0)
60
+ return trimmed;
61
+ }
62
+ return undefined;
63
+ }
64
+ export function buildCodexAcpConfig(config) {
65
+ const agentCommand = firstNonEmptyString(config.agentCommand, config.acpAgentCommand);
66
+ const stateDir = firstNonEmptyString(config.stateDir, config.acpStateDir);
67
+ const mode = firstNonEmptyString(config.mode, config.acpMode) ?? DEFAULT_ACP_ENGINE_MODE;
68
+ const permissionMode = firstNonEmptyString(config.permissionMode, config.acpPermissionMode) ??
69
+ DEFAULT_ACP_ENGINE_PERMISSION_MODE;
70
+ const nonInteractivePermissions = firstNonEmptyString(config.nonInteractivePermissions, config.acpNonInteractivePermissions) ??
71
+ DEFAULT_ACP_ENGINE_NON_INTERACTIVE_PERMISSIONS;
72
+ const warmHandleIdleMs = config.warmHandleIdleMs ??
73
+ config.acpWarmHandleIdleMs ??
74
+ DEFAULT_ACP_ENGINE_WARM_HANDLE_IDLE_MS;
75
+ // Rewrite legacy model aliases (e.g. bare gpt-5.6) to the concrete slug Codex has metadata for,
76
+ // so the ACP session config matches the CLI lane and avoids the fallback-metadata warning.
77
+ const normalizedModel = normalizeCodexModel(typeof config.model === "string" ? config.model : "");
78
+ const env = parseObject(config.env);
79
+ let networkAccess = env.PAPERCLIP_CODEX_ACP_NETWORK_ACCESS !== "false";
80
+ const extraArgs = asStringArray(config.extraArgs);
81
+ for (const arg of extraArgs.length > 0 ? extraArgs : asStringArray(config.args)) {
82
+ const match = /^(?:(?:--config=|-c=?)\s*)?sandbox_workspace_write\.network_access\s*=\s*(true|false)\s*$/.exec(arg);
83
+ if (match)
84
+ networkAccess = match[1] === "true";
85
+ }
86
+ return {
87
+ ...config,
88
+ env: { ...env, PAPERCLIP_CODEX_ACP_NETWORK_ACCESS: String(networkAccess) },
89
+ agent: "codex",
90
+ mode,
91
+ permissionMode,
92
+ nonInteractivePermissions,
93
+ warmHandleIdleMs,
94
+ ...(normalizedModel ? { model: normalizedModel } : {}),
95
+ ...(agentCommand ? { agentCommand } : {}),
96
+ ...(stateDir ? { stateDir } : {}),
97
+ };
98
+ }
99
+ /**
100
+ * Codex remote managed-home seed + auth copy-back for the runner-backed remote
101
+ * sandbox ACP lane. Mirrors the codex CLI lane (`codex-local/execute.ts`): stage
102
+ * the managed `CODEX_HOME` (auth.json + config.toml + skills) into the sandbox
103
+ * as the `home` asset, then repoint `CODEX_HOME` onto the in-sandbox
104
+ * `assetDirs.home` path. Subscription runs also use inbound auth merge and
105
+ * outbound copy-back through `restoreWorkspace()` at teardown.
106
+ *
107
+ * The engine already resolved+seeded the host managed Codex home and set
108
+ * `env.CODEX_HOME` to it (a HOST path) before this seam runs, so `env.CODEX_HOME`
109
+ * is exactly the home to stage. Subscription auth merge and copy-back stay
110
+ * paired: Codex refresh tokens are single-use, so a refreshed sandbox token
111
+ * that is never copied back would spend the host's token. API-key runs skip
112
+ * both auth seams and never touch the shared subscription credential.
113
+ */
114
+ async function prepareCodexRemoteManagedHome(input) {
115
+ const { env, runId, onLog } = input;
116
+ // The host managed Codex home the engine seeded and set on env.CODEX_HOME.
117
+ let effectiveCodexHome = env.CODEX_HOME;
118
+ let currentLog = onLog;
119
+ const copybackLog = (stream, chunk) => currentLog(stream, chunk);
120
+ if (!effectiveCodexHome) {
121
+ // No managed home resolved (e.g. custom CODEX_HOME cleared) — stage the
122
+ // workspace with no home asset, identical to the no-seam fallback.
123
+ return { stagedRuntime: await input.stage([]) };
124
+ }
125
+ // API-key runs do not rotate a subscription refresh token. Keep their
126
+ // sandbox auth out of the shared subscription copy-back path altogether.
127
+ const apiKeyAuth = Boolean(env.OPENAI_API_KEY?.trim() || env.CODEX_API_KEY?.trim()
128
+ || (!input.config.managedAiConnection && (process.env.OPENAI_API_KEY?.trim() || process.env.CODEX_API_KEY?.trim())));
129
+ // Curated allowlist temp dir (auth/config/skills only); caller owns cleanup.
130
+ const stagedCodexHomeDir = await stageCodexHomeForSync(effectiveCodexHome, { runId });
131
+ let stagedRuntime;
132
+ try {
133
+ stagedRuntime = await input.stage([
134
+ {
135
+ key: "home",
136
+ localDir: stagedCodexHomeDir,
137
+ followSymlinks: true,
138
+ // Refresh managed config/auth while retaining remote conversation files.
139
+ provision: buildCodexHomeRefreshProvision({ mergeAuth: !apiKeyAuth }),
140
+ // Subscription-only outbound copy-back at teardown, under the same
141
+ // direction-agnostic decision predicate + directory merge-lock +
142
+ // atomic-rename + 0600 guard. Target is the SHARED host auth.json
143
+ // (the symlink source managed homes point at), never an in-sandbox copy.
144
+ restore: apiKeyAuth ? undefined : async ({ assetDir, readFile }) => void (await copyBackCodexAuth({
145
+ readSandboxAuth: () => readFile(path.posix.join(assetDir, "auth.json")),
146
+ hostAuthPath: path.join(input.config.managedAiConnection ? effectiveCodexHome : resolveSharedCodexHomeDir(process.env), "auth.json"),
147
+ log: (line) => copybackLog("stdout", `${line}\n`),
148
+ })),
149
+ },
150
+ ]);
151
+ }
152
+ catch (err) {
153
+ await fs.rm(stagedCodexHomeDir, { recursive: true, force: true }).catch(() => { });
154
+ throw err;
155
+ }
156
+ // Repoint CODEX_HOME from the HOST path onto the seeded in-sandbox home.
157
+ env.CODEX_HOME =
158
+ stagedRuntime.assetDirs.home ??
159
+ path.posix.join(stagedRuntime.runtimeRootDir ?? "", "home");
160
+ return {
161
+ stagedRuntime,
162
+ rebindRun: binding => {
163
+ if (input.config.managedAiConnection) {
164
+ if (!binding.env.CODEX_HOME)
165
+ throw new Error("Managed Codex copyback requires the current account home");
166
+ effectiveCodexHome = binding.env.CODEX_HOME;
167
+ }
168
+ currentLog = binding.onLog;
169
+ },
170
+ // Subscription copy-back fires on EVERY run's teardown (including a compatible
171
+ // resume that reuses this staged runtime). It reads the sandbox auth.json /
172
+ // workspace live and copies back to the host; it does NOT remove the staged
173
+ // in-sandbox home, so re-running it across resumes can't leave a later run
174
+ // without its staged home. Host staged-temp removal is deliberately NOT here
175
+ // — see `disposeStaged` — so caching this runtime for reuse never destroys
176
+ // resources the next resume needs.
177
+ // Fail-soft: a teardown copy-back miss loses this rotation and surfaces
178
+ // loudly as refresh_token_reused on the next host Codex use (re-auth
179
+ // recovers) — never silent host-credential corruption, so it must not
180
+ // mask the run result.
181
+ teardown: createWorkspaceRestoreTeardown({
182
+ stagedRuntime,
183
+ onLog: copybackLog,
184
+ startMessage: apiKeyAuth
185
+ ? "[paperclip] Restoring workspace changes from the sandbox.\n"
186
+ : "[paperclip] Restoring workspace changes and Codex auth from the sandbox.\n",
187
+ failurePrefix: "[paperclip] Codex ACP teardown restore/copy-back failed",
188
+ }),
189
+ // One-time cleanup of the HOST staged home temp dir. Fired ONLY when the
190
+ // staged runtime is dropped (failed/cancelled/timed-out turn, incompatible
191
+ // re-stage, idle eviction) — never on a clean turn that keeps the runtime
192
+ // warm — so it can't remove the staged home while a reuse still depends on
193
+ // it. Idempotent: `force: true` no-ops if it was already removed.
194
+ disposeStaged: async () => {
195
+ await fs.rm(stagedCodexHomeDir, { recursive: true, force: true }).catch(async (error) => {
196
+ await onLog("stderr", `[paperclip] Failed to remove staged Codex home "${stagedCodexHomeDir}": ${error instanceof Error ? error.message : String(error)}\n`);
197
+ });
198
+ },
199
+ };
200
+ }
201
+ const CODEX_MODEL_CAPACITY_RE = /\b(?:selected model is at capacity|model is at capacity|at capacity for this model|serverOverloaded|server overloaded)\b/i;
202
+ const CODEX_PROVIDER_AUTH_RE = /\b(?:401 unauthorized|invalid_api_key|(?:incorrect|invalid) api key)\b/i;
203
+ export function classifyCodexTerminalSessionFailure(failure, now) {
204
+ if (failure.category === "access") {
205
+ const text = [failure.title, failure.details].filter(Boolean).join("\n");
206
+ return CODEX_PROVIDER_AUTH_RE.test(text) ? { errorCode: "acpx_auth_required" } : null;
207
+ }
208
+ if (failure.category === "service") {
209
+ const text = [failure.title, failure.details].filter(Boolean).join("\n");
210
+ return CODEX_MODEL_CAPACITY_RE.test(text)
211
+ ? { errorCode: "codex_transient_upstream", errorFamily: "transient_upstream" }
212
+ : null;
213
+ }
214
+ // ACP's `limit` also covers context, turn, rate and configured budget limits.
215
+ // Require explicit usage exhaustion; the CLI's broader capacity matcher would
216
+ // also match a context/storage capacity limit and defer the wrong failure.
217
+ if (failure.category !== "limit")
218
+ return null;
219
+ const surface = { errorMessage: [failure.title, failure.details].filter(Boolean).join("\n") };
220
+ if (!/\b(?:you(?:'|’)ve hit your usage limit|usage limit (?:reached|exceeded))\b/i.test(surface.errorMessage)) {
221
+ return null;
222
+ }
223
+ const retryNotBefore = extractCodexRetryNotBefore(surface, now)?.toISOString();
224
+ return {
225
+ errorCode: "provider_quota",
226
+ errorFamily: "provider_quota",
227
+ ...(retryNotBefore ? { retryNotBefore } : {}),
228
+ };
229
+ }
230
+ function withCodexAcpDefaults(options) {
231
+ return {
232
+ resolveBillingIdentity: resolveCodexAcpBillingIdentity,
233
+ prepareRemoteManagedHome: prepareCodexRemoteManagedHome,
234
+ classifyTerminalSessionFailure: classifyCodexTerminalSessionFailure,
235
+ ...options,
236
+ adapterType: "codex_local",
237
+ moduleDir,
238
+ packageRootDir,
239
+ };
240
+ }
241
+ function withCodexAuthRefreshFailureClassification(result) {
242
+ if ((result.exitCode ?? 0) === 0)
243
+ return result;
244
+ const resultJson = parseObject(result.resultJson);
245
+ const stopReason = asString(resultJson.stopReason, "");
246
+ const authFailure = classifyCodexAuthRefreshFailure({
247
+ errorMessage: [result.errorMessage ?? "", result.summary ?? "", stopReason]
248
+ .map((line) => line.trim())
249
+ .filter(Boolean)
250
+ .join("\n"),
251
+ });
252
+ if (!authFailure)
253
+ return result;
254
+ return {
255
+ ...result,
256
+ errorCode: authFailure,
257
+ errorFamily: authFailure,
258
+ resultJson: {
259
+ ...(result.resultJson ?? {}),
260
+ errorFamily: authFailure,
261
+ },
262
+ };
263
+ }
264
+ /**
265
+ * Classify billing the same way the Codex CLI lane does so ACP runs land in
266
+ * the cost ledger with a real provider/billingType instead of acpx/unknown.
267
+ * Host env only counts for local execution targets; remote targets see just
268
+ * the adapter-config env.
269
+ */
270
+ export function resolveCodexAcpBillingIdentity(ctx) {
271
+ const managedBilling = resolveManagedOpenAiBilling(ctx.config.managedAiRouting);
272
+ if (managedBilling)
273
+ return managedBilling;
274
+ const envConfig = parseObject(parseObject(ctx.config).env);
275
+ const target = readAdapterExecutionTarget({
276
+ executionTarget: ctx.executionTarget,
277
+ legacyRemoteExecution: ctx.executionTransport?.remoteExecution,
278
+ });
279
+ const considerHostEnv = target?.kind !== "remote";
280
+ const mergedEnv = {
281
+ ...(considerHostEnv ? process.env : {}),
282
+ ...Object.fromEntries(Object.entries(envConfig).filter((entry) => typeof entry[1] === "string")),
283
+ };
284
+ const apiKey = typeof mergedEnv.OPENAI_API_KEY === "string" && mergedEnv.OPENAI_API_KEY.trim().length > 0;
285
+ const billingType = apiKey ? "api" : "subscription";
286
+ const openAiCompatibleBiller = inferOpenAiCompatibleBiller(mergedEnv, "openai");
287
+ const biller = openAiCompatibleBiller === "openrouter"
288
+ ? "openrouter"
289
+ : billingType === "subscription"
290
+ ? "chatgpt"
291
+ : openAiCompatibleBiller ?? "openai";
292
+ return { provider: "openai", biller, billingType };
293
+ }
294
+ export function createCodexAcpExecutor(options = {}) {
295
+ let executor = null;
296
+ return async (ctx) => {
297
+ let currentExecutor = executor;
298
+ if (!currentExecutor) {
299
+ const { createAcpxEngineExecutor } = await import("@paperclipai/adapter-utils/acpx-engine/execute");
300
+ currentExecutor = createAcpxEngineExecutor(withCodexAcpDefaults(options));
301
+ executor = currentExecutor;
302
+ }
303
+ const result = await currentExecutor({
304
+ ...ctx,
305
+ config: buildCodexAcpConfig(ctx.config),
306
+ });
307
+ return withCodexAuthRefreshFailureClassification(result);
308
+ };
309
+ }
310
+ function parseVersion(version) {
311
+ const match = version.match(/^v?(\d+)\.(\d+)\.(\d+)/);
312
+ if (!match)
313
+ return [0, 0, 0];
314
+ return [Number(match[1]), Number(match[2]), Number(match[3])];
315
+ }
316
+ export function nodeVersionMeetsCodexAcpMinimum(version = process.version) {
317
+ const [major, minor, patch] = parseVersion(version);
318
+ const [minMajor, minMinor, minPatch] = parseVersion(MIN_ACP_NODE_VERSION);
319
+ if (major !== minMajor)
320
+ return major > minMajor;
321
+ if (minor !== minMinor)
322
+ return minor > minMinor;
323
+ return patch >= minPatch;
324
+ }
325
+ async function pathExists(candidate) {
326
+ return fs.access(candidate).then(() => true).catch(() => false);
327
+ }
328
+ function hasPathSeparator(command) {
329
+ return command.includes("/") || command.includes("\\");
330
+ }
331
+ function looksLikeShellCommand(command) {
332
+ return /\s/.test(command.trim());
333
+ }
334
+ async function findCommandOnPath(binName) {
335
+ const pathValue = process.env.PATH ?? "";
336
+ for (const segment of pathValue.split(path.delimiter)) {
337
+ if (!segment)
338
+ continue;
339
+ const candidate = path.join(segment, binName);
340
+ if (await pathExists(candidate))
341
+ return candidate;
342
+ }
343
+ return null;
344
+ }
345
+ async function findAncestorBin(startDir, binName) {
346
+ let current = path.resolve(startDir);
347
+ while (true) {
348
+ const candidate = path.join(current, "node_modules", ".bin", binName);
349
+ if (await pathExists(candidate))
350
+ return candidate;
351
+ const parent = path.dirname(current);
352
+ if (parent === current)
353
+ return null;
354
+ current = parent;
355
+ }
356
+ }
357
+ async function commandIsResolvable(command, input) {
358
+ const trimmed = command.trim();
359
+ if (!trimmed)
360
+ return false;
361
+ if (looksLikeShellCommand(trimmed))
362
+ return true;
363
+ const target = readAdapterExecutionTarget({
364
+ executionTarget: input?.executionTarget,
365
+ legacyRemoteExecution: input?.executionTransport?.remoteExecution,
366
+ });
367
+ if (target?.kind === "remote") {
368
+ try {
369
+ await ensureAdapterExecutionTargetCommandResolvable(trimmed, target, resolveAdapterExecutionTargetCwd(target, asString(input?.config.cwd, ""), process.cwd()), target.transport === "ssh" ? { PATH: process.env.PATH } : process.env);
370
+ return true;
371
+ }
372
+ catch {
373
+ return false;
374
+ }
375
+ }
376
+ if (path.isAbsolute(trimmed) || hasPathSeparator(trimmed))
377
+ return pathExists(trimmed);
378
+ return (await findCommandOnPath(trimmed)) !== null;
379
+ }
380
+ async function resolveCodexAcpCommand(config) {
381
+ const configured = firstNonEmptyString(config.agentCommand, config.acpAgentCommand);
382
+ if (configured)
383
+ return configured;
384
+ return ((await findAncestorBin(packageRootDir, "codex-acp")) ??
385
+ (await findCommandOnPath("codex-acp")) ??
386
+ path.join(packageRootDir, "node_modules", ".bin", "codex-acp"));
387
+ }
388
+ function sandboxTargetHasProcessSessionBridge(target) {
389
+ return target?.kind === "remote" && target.transport === "sandbox" && Boolean(target.runner);
390
+ }
391
+ async function resolveCodexAcpCommandForTarget(config, target) {
392
+ const configured = firstNonEmptyString(config.agentCommand, config.acpAgentCommand);
393
+ if (configured)
394
+ return configured;
395
+ if (target?.kind === "remote")
396
+ return "codex-acp";
397
+ return resolveCodexAcpCommand(config);
398
+ }
399
+ async function codexAcpUnavailableReason(input) {
400
+ const target = readAdapterExecutionTarget({
401
+ executionTarget: input.executionTarget,
402
+ legacyRemoteExecution: input.executionTransport?.remoteExecution,
403
+ });
404
+ const managedSsh = target?.kind === "remote" && target.transport === "ssh"
405
+ && target.spec.useHostAuth === false && Boolean(input.config.managedAiConnection);
406
+ if (target?.kind === "remote" && !sandboxTargetHasProcessSessionBridge(target) && !managedSsh) {
407
+ if (target.transport === "sandbox") {
408
+ return "Codex ACP requires a bidirectional remote process target; this sandbox exposes only one-shot command execution.";
409
+ }
410
+ return "Codex ACP requires an agent-managed SSH account; host authentication is supported by the CLI engine.";
411
+ }
412
+ if (!nodeVersionMeetsCodexAcpMinimum()) {
413
+ return `Node ${process.version} (${process.execPath}) does not satisfy Codex ACP's Node >=${MIN_ACP_NODE_VERSION} prerequisite.`;
414
+ }
415
+ const command = await resolveCodexAcpCommandForTarget(input.config, target);
416
+ if (!(await commandIsResolvable(command, input))) {
417
+ return `Codex ACP server command is not available: ${command}.`;
418
+ }
419
+ return null;
420
+ }
421
+ function summarizeStatus(checks) {
422
+ if (checks.some((check) => check.level === "error"))
423
+ return "fail";
424
+ if (checks.some((check) => check.level === "warn"))
425
+ return "warn";
426
+ return "pass";
427
+ }
428
+ function isNonEmpty(value) {
429
+ return typeof value === "string" && value.trim().length > 0;
430
+ }
431
+ export async function testCodexAcpEnvironment(ctx) {
432
+ const checks = [];
433
+ const config = parseObject(ctx.config);
434
+ const target = ctx.executionTarget ?? null;
435
+ const targetIsRemote = target?.kind === "remote";
436
+ const targetIsSandbox = target?.kind === "remote" && target.transport === "sandbox";
437
+ checks.push({
438
+ code: "codex_engine_selected",
439
+ level: "info",
440
+ message: "Execution engine selected: ACP.",
441
+ hint: "Set engine=cli to use the existing Codex CLI lane.",
442
+ });
443
+ if (targetIsRemote) {
444
+ checks.push({
445
+ code: "codex_acp_remote_target",
446
+ level: "info",
447
+ message: "Codex ACP will run against the remote execution environment.",
448
+ hint: "Remote ACP requires a bidirectional process target such as SSH or Paperclip's sandbox process-session bridge.",
449
+ });
450
+ }
451
+ const cwd = asString(config.cwd, process.cwd());
452
+ try {
453
+ await fs.mkdir(cwd, { recursive: true });
454
+ checks.push({
455
+ code: "codex_acp_cwd_valid",
456
+ level: "info",
457
+ message: `Working directory is valid: ${cwd}`,
458
+ });
459
+ }
460
+ catch (err) {
461
+ checks.push({
462
+ code: "codex_acp_cwd_invalid",
463
+ level: "error",
464
+ message: err instanceof Error ? err.message : "Invalid working directory",
465
+ detail: cwd,
466
+ });
467
+ }
468
+ checks.push({
469
+ code: nodeVersionMeetsCodexAcpMinimum() ? "codex_acp_node_supported" : "codex_acp_node_unsupported",
470
+ level: nodeVersionMeetsCodexAcpMinimum() ? "info" : "error",
471
+ message: nodeVersionMeetsCodexAcpMinimum()
472
+ ? `Node ${process.version} satisfies ACP runtime requirements.`
473
+ : `Node ${process.version} (${process.execPath}) does not satisfy ACP runtime requirements.`,
474
+ hint: nodeVersionMeetsCodexAcpMinimum()
475
+ ? undefined
476
+ : `Run Codex ACP with Node >=${MIN_ACP_NODE_VERSION} or switch engine=cli.`,
477
+ });
478
+ const command = await resolveCodexAcpCommandForTarget(config, target);
479
+ const commandResolvable = await commandIsResolvable(command, {
480
+ config,
481
+ executionTarget: ctx.executionTarget,
482
+ });
483
+ checks.push({
484
+ code: commandResolvable ? "codex_acp_command_resolvable" : "codex_acp_command_missing",
485
+ level: commandResolvable ? "info" : "error",
486
+ message: commandResolvable
487
+ ? `Codex ACP server command is executable: ${command}`
488
+ : `Codex ACP server command is not available: ${command}`,
489
+ hint: commandResolvable
490
+ ? undefined
491
+ : "Install dependencies so @agentclientprotocol/codex-acp is present, or set agentCommand to a valid Codex ACP server command.",
492
+ });
493
+ const envConfig = parseObject(config.env);
494
+ if (!targetIsRemote) {
495
+ const configApiKey = isNonEmpty(envConfig.OPENAI_API_KEY) ? envConfig.OPENAI_API_KEY : null;
496
+ const hostApiKey = Object.prototype.hasOwnProperty.call(envConfig, "OPENAI_API_KEY")
497
+ ? null
498
+ : isNonEmpty(process.env.OPENAI_API_KEY)
499
+ ? process.env.OPENAI_API_KEY
500
+ : null;
501
+ const configuredApiKey = configApiKey ?? hostApiKey;
502
+ const configuredCodexHome = isNonEmpty(envConfig.CODEX_HOME) ? envConfig.CODEX_HOME : null;
503
+ const credentialReadiness = await evaluateCodexCredentialReadiness({
504
+ env: process.env,
505
+ companyId: ctx.companyId,
506
+ configuredCodexHome,
507
+ configuredApiKey,
508
+ });
509
+ if (credentialReadiness.ready && credentialReadiness.authMode === "api") {
510
+ checks.push({
511
+ code: "codex_acp_openai_api_key_detected",
512
+ level: "info",
513
+ message: "OPENAI_API_KEY is set for Codex ACP authentication.",
514
+ detail: `Detected in ${configApiKey ? "adapter config env" : "server environment"}.`,
515
+ });
516
+ }
517
+ else if (credentialReadiness.ready && !credentialReadiness.managed) {
518
+ checks.push({
519
+ code: "codex_acp_external_home_configured",
520
+ level: "info",
521
+ message: "Codex ACP will use an externally managed CODEX_HOME.",
522
+ detail: credentialReadiness.effectiveHome,
523
+ });
524
+ }
525
+ else if (credentialReadiness.ready) {
526
+ checks.push({
527
+ code: "codex_acp_native_auth_detected",
528
+ level: "info",
529
+ message: "Codex ACP can use Codex native authentication.",
530
+ detail: `Credentials are available through ${credentialReadiness.effectiveHome} or shared source ${credentialReadiness.sharedSourceHome}.`,
531
+ });
532
+ }
533
+ else {
534
+ checks.push({
535
+ code: "codex_acp_credentials_missing",
536
+ level: "warn",
537
+ message: "No Codex ACP credentials visible to the Paperclip server were detected.",
538
+ hint: "Set OPENAI_API_KEY in the agent adapter env, set it in the Paperclip server environment, or run `codex login` for the same OS user that runs the Paperclip server before starting a Codex ACP agent. A `/login` in a separate Codex/chat session does not authenticate the server.",
539
+ });
540
+ }
541
+ }
542
+ else if (targetIsSandbox) {
543
+ // The ACP Test does not probe the sandbox, so it predicts readiness from the
544
+ // credentials the Paperclip server can seed into the sandbox. The host
545
+ // environment is not seeded, so only the adapter config key counts here.
546
+ const configApiKey = isNonEmpty(envConfig.OPENAI_API_KEY) ? envConfig.OPENAI_API_KEY : null;
547
+ const configuredCodexHome = isNonEmpty(envConfig.CODEX_HOME) ? envConfig.CODEX_HOME : null;
548
+ const credentialReadiness = await evaluateCodexCredentialReadiness({
549
+ env: process.env,
550
+ companyId: ctx.companyId,
551
+ configuredCodexHome,
552
+ configuredApiKey: configApiKey,
553
+ });
554
+ if (!credentialReadiness.ready) {
555
+ // Emit the neutral canonical check so the user interface can decide login
556
+ // eligibility from a stable code. The user interface does not read the
557
+ // message text or the top-level status.
558
+ checks.push({
559
+ code: ADAPTER_AUTH_MISSING_CHECK_CODE,
560
+ level: "warn",
561
+ message: "This environment has no ready authentication for this adapter.",
562
+ hint: "Provide credentials for this adapter, or start login in the environment.",
563
+ });
564
+ }
565
+ }
566
+ if (targetIsRemote && commandResolvable) {
567
+ // The ACP server spawns the shared `codex` installed in the environment.
568
+ // Models with a verified CLI floor are checked against that executable so
569
+ // a stale sandbox image is named here, before a run fails on every turn
570
+ // with the backend's "not supported when using Codex with a ChatGPT
571
+ // account" rejection. Models without a floor skip the probe.
572
+ //
573
+ // Remote ACP runs receive the adapter's string-valued env entries (see
574
+ // buildCodexAcpConfig), so the probe gets the same ones. An agent that
575
+ // selects its Codex install through PATH is then measured against that
576
+ // install rather than the image default.
577
+ const probeEnv = {};
578
+ for (const [key, value] of Object.entries(envConfig)) {
579
+ if (typeof value === "string")
580
+ probeEnv[key] = value;
581
+ }
582
+ const versionCheck = await checkCodexCliVersionForModel({
583
+ runId: `codex-acp-envtest-${Date.now()}-${Math.random().toString(16).slice(2)}`,
584
+ model: asString(config.model, ""),
585
+ command: "codex",
586
+ target,
587
+ cwd: resolveAdapterExecutionTargetCwd(target, asString(config.cwd, ""), process.cwd()),
588
+ env: probeEnv,
589
+ });
590
+ if (versionCheck)
591
+ checks.push(versionCheck.check);
592
+ }
593
+ const mode = firstNonEmptyString(config.mode, config.acpMode) ?? DEFAULT_ACP_ENGINE_MODE;
594
+ const warmHandleIdleMs = asNumber(config.warmHandleIdleMs ?? config.acpWarmHandleIdleMs, DEFAULT_ACP_ENGINE_WARM_HANDLE_IDLE_MS);
595
+ checks.push({
596
+ code: "codex_acp_runtime_scaffold",
597
+ level: "info",
598
+ message: "Codex ACP runtime execution is available through the shared ACP engine.",
599
+ detail: `mode=${mode}; warmHandleIdleMs=${warmHandleIdleMs}`,
600
+ });
601
+ return {
602
+ adapterType: ctx.adapterType,
603
+ status: summarizeStatus(checks),
604
+ checks,
605
+ testedAt: new Date().toISOString(),
606
+ };
607
+ }
608
+ //# sourceMappingURL=acp.js.map