@wrenai/genbi 0.0.4 → 0.0.6

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 (234) hide show
  1. package/README.md +65 -3
  2. package/dist/assets/{echarts-LTFC-ysd.js → echarts-DYM4hjvk.js} +2 -2
  3. package/dist/assets/index-A_Wrq7Ey.css +1 -0
  4. package/dist/assets/{index-Bo--QMUN.js → index-DsH129tV.js} +18 -17
  5. package/dist/index.html +2 -2
  6. package/dist-server/harness/bundle/schema.d.ts +38 -0
  7. package/dist-server/harness/bundle/schema.js +18 -10
  8. package/dist-server/harness/bundle/version.js +1 -1
  9. package/dist-server/harness/cli-args.d.ts +10 -2
  10. package/dist-server/harness/cli-args.js +24 -8
  11. package/dist-server/harness/cli.js +75 -9
  12. package/dist-server/harness/compile/cache.js +4 -4
  13. package/dist-server/harness/compile/compose-profile.d.ts +51 -14
  14. package/dist-server/harness/compile/compose-profile.js +85 -19
  15. package/dist-server/harness/compile/context-loader.d.ts +56 -0
  16. package/dist-server/harness/compile/context-loader.js +237 -0
  17. package/dist-server/harness/compile/errors.d.ts +19 -0
  18. package/dist-server/harness/compile/errors.js +35 -0
  19. package/dist-server/harness/compile/index.d.ts +4 -3
  20. package/dist-server/harness/compile/index.js +4 -3
  21. package/dist-server/harness/compile/pipeline.d.ts +15 -7
  22. package/dist-server/harness/compile/pipeline.js +62 -14
  23. package/dist-server/harness/compile/resolve-binary.d.ts +2 -2
  24. package/dist-server/harness/compile/resolve-binary.js +3 -3
  25. package/dist-server/harness/compile/types.d.ts +29 -0
  26. package/dist-server/harness/compile/warble-identity.d.ts +11 -0
  27. package/dist-server/harness/compile/warble-identity.js +13 -0
  28. package/dist-server/harness/components/ai-step.d.ts +4 -0
  29. package/dist-server/harness/components/ai-step.js +40 -0
  30. package/dist-server/harness/components/broker.d.ts +60 -0
  31. package/dist-server/harness/components/broker.js +117 -0
  32. package/dist-server/harness/components/capability-card.d.ts +98 -0
  33. package/dist-server/harness/components/capability-card.js +169 -0
  34. package/dist-server/harness/components/context.d.ts +2 -0
  35. package/dist-server/harness/components/context.js +30 -0
  36. package/dist-server/harness/components/display.d.ts +6 -0
  37. package/dist-server/harness/components/display.js +29 -0
  38. package/dist-server/harness/components/egress-judge.d.ts +12 -0
  39. package/dist-server/harness/components/egress-judge.js +27 -0
  40. package/dist-server/harness/components/egress.d.ts +142 -0
  41. package/dist-server/harness/components/egress.js +469 -0
  42. package/dist-server/harness/components/in-process.d.ts +7 -0
  43. package/dist-server/harness/components/in-process.js +245 -0
  44. package/dist-server/harness/components/normalize.d.ts +35 -0
  45. package/dist-server/harness/components/normalize.js +245 -0
  46. package/dist-server/harness/components/plan.d.ts +31 -0
  47. package/dist-server/harness/components/plan.js +184 -0
  48. package/dist-server/harness/components/report.d.ts +207 -0
  49. package/dist-server/harness/components/report.js +309 -0
  50. package/dist-server/harness/components/runner.d.ts +193 -0
  51. package/dist-server/harness/components/runner.js +492 -0
  52. package/dist-server/harness/components/semantic-guards.d.ts +20 -0
  53. package/dist-server/harness/components/semantic-guards.js +42 -0
  54. package/dist-server/harness/components/terminal-json.d.ts +18 -0
  55. package/dist-server/harness/components/terminal-json.js +82 -0
  56. package/dist-server/harness/components/usage.d.ts +14 -0
  57. package/dist-server/harness/components/usage.js +19 -0
  58. package/dist-server/harness/components/wren-access.d.ts +29 -0
  59. package/dist-server/harness/components/wren-access.js +233 -0
  60. package/dist-server/harness/components/zone-dry-run.d.ts +43 -0
  61. package/dist-server/harness/components/zone-dry-run.js +107 -0
  62. package/dist-server/harness/components/zone-gate.d.ts +76 -0
  63. package/dist-server/harness/components/zone-gate.js +144 -0
  64. package/dist-server/harness/events/index.d.ts +1 -1
  65. package/dist-server/harness/events/types.d.ts +52 -0
  66. package/dist-server/harness/index.d.ts +9 -2
  67. package/dist-server/harness/index.js +5 -1
  68. package/dist-server/harness/loop/executor.d.ts +1 -0
  69. package/dist-server/harness/loop/executor.js +37 -15
  70. package/dist-server/harness/npm-package-resolve.d.ts +2 -0
  71. package/dist-server/harness/npm-package-resolve.js +16 -4
  72. package/dist-server/harness/providers/adapters/openai-compatible.d.ts +13 -0
  73. package/dist-server/harness/providers/adapters/openai-compatible.js +17 -0
  74. package/dist-server/harness/providers/adapters/openai.d.ts +7 -0
  75. package/dist-server/harness/providers/adapters/openai.js +6 -0
  76. package/dist-server/harness/providers/adapters/pi-ai.d.ts +48 -0
  77. package/dist-server/harness/providers/adapters/pi-ai.js +518 -0
  78. package/dist-server/harness/providers/binding.d.ts +45 -4
  79. package/dist-server/harness/providers/binding.js +44 -8
  80. package/dist-server/harness/providers/index.d.ts +9 -3
  81. package/dist-server/harness/providers/index.js +10 -3
  82. package/dist-server/harness/providers/zone.d.ts +96 -0
  83. package/dist-server/harness/providers/zone.js +112 -0
  84. package/dist-server/harness/render/answering-query.d.ts +29 -0
  85. package/dist-server/harness/render/answering-query.js +62 -0
  86. package/dist-server/harness/render/envelope.d.ts +6 -0
  87. package/dist-server/harness/render/envelope.js +10 -3
  88. package/dist-server/harness/route/adapter-spec.d.ts +8 -9
  89. package/dist-server/harness/route/adapter-spec.js +13 -14
  90. package/dist-server/harness/route/codex-ask-events.js +2 -1
  91. package/dist-server/harness/route/codex-ask.d.ts +4 -0
  92. package/dist-server/harness/route/codex-ask.js +43 -45
  93. package/dist-server/harness/route/codex-local-manifest.d.ts +9 -1
  94. package/dist-server/harness/route/codex-local-manifest.js +96 -15
  95. package/dist-server/harness/route/describe.js +45 -6
  96. package/dist-server/harness/route/dispatched.d.ts +20 -0
  97. package/dist-server/harness/route/dispatched.js +122 -24
  98. package/dist-server/harness/route/host-query.d.ts +93 -0
  99. package/dist-server/harness/route/host-query.js +257 -0
  100. package/dist-server/harness/route/in-process.d.ts +22 -1
  101. package/dist-server/harness/route/in-process.js +54 -4
  102. package/dist-server/harness/route/route.js +8 -2
  103. package/dist-server/harness/route/types.d.ts +47 -1
  104. package/dist-server/harness/route/wren-host-proxy.d.ts +33 -0
  105. package/dist-server/harness/route/wren-host-proxy.js +228 -0
  106. package/dist-server/harness/session/run.js +30 -10
  107. package/dist-server/harness/setup/runner.d.ts +17 -3
  108. package/dist-server/harness/setup/runner.js +272 -89
  109. package/dist-server/harness/setup/yaml-scalar.d.ts +23 -0
  110. package/dist-server/harness/setup/yaml-scalar.js +62 -0
  111. package/dist-server/harness/tools/setup-native.d.ts +7 -0
  112. package/dist-server/harness/tools/setup-native.js +7 -4
  113. package/dist-server/server/adopt.js +1 -17
  114. package/dist-server/server/app.d.ts +1 -0
  115. package/dist-server/server/app.js +175 -17
  116. package/dist-server/server/auth-choice.d.ts +13 -1
  117. package/dist-server/server/auth-choice.js +66 -1
  118. package/dist-server/server/bin.js +185 -25
  119. package/dist-server/server/codex-native-session.d.ts +25 -0
  120. package/dist-server/server/codex-native-session.js +1 -0
  121. package/dist-server/server/codex-runtime-composition.d.ts +34 -0
  122. package/dist-server/server/codex-runtime-composition.js +250 -0
  123. package/dist-server/server/codex-structured-ask.d.ts +23 -0
  124. package/dist-server/server/codex-structured-ask.js +102 -0
  125. package/dist-server/server/conn-config.js +4 -16
  126. package/dist-server/server/conversation-socket.d.ts +16 -0
  127. package/dist-server/server/conversation-socket.js +65 -0
  128. package/dist-server/server/db.d.ts +46 -0
  129. package/dist-server/server/db.js +88 -9
  130. package/dist-server/server/env-detect.d.ts +6 -0
  131. package/dist-server/server/env-detect.js +7 -0
  132. package/dist-server/server/fold.d.ts +23 -4
  133. package/dist-server/server/fold.js +42 -5
  134. package/dist-server/server/harness.d.ts +2 -2
  135. package/dist-server/server/harness.js +33 -7
  136. package/dist-server/server/host-evidence-grounding.d.ts +21 -0
  137. package/dist-server/server/host-evidence-grounding.js +93 -0
  138. package/dist-server/server/interactive-terminal.d.ts +10 -6
  139. package/dist-server/server/interactive-terminal.js +33 -8
  140. package/dist-server/server/managed-wren-runtime.d.ts +116 -0
  141. package/dist-server/server/managed-wren-runtime.js +670 -0
  142. package/dist-server/server/native-artifacts.d.ts +112 -7
  143. package/dist-server/server/native-artifacts.js +194 -14
  144. package/dist-server/server/native-component-context.d.ts +19 -0
  145. package/dist-server/server/native-component-context.js +76 -0
  146. package/dist-server/server/native-component-preparation.d.ts +20 -0
  147. package/dist-server/server/native-component-preparation.js +129 -0
  148. package/dist-server/server/native-component-runtime.d.ts +36 -0
  149. package/dist-server/server/native-component-runtime.js +92 -0
  150. package/dist-server/server/native-components.d.ts +84 -0
  151. package/dist-server/server/native-components.js +160 -0
  152. package/dist-server/server/native-dispatch-process.d.ts +8 -0
  153. package/dist-server/server/native-dispatch-process.js +65 -0
  154. package/dist-server/server/native-runtime-spec.d.ts +89 -0
  155. package/dist-server/server/native-runtime-spec.js +169 -0
  156. package/dist-server/server/native-sessions.d.ts +172 -19
  157. package/dist-server/server/native-sessions.js +839 -244
  158. package/dist-server/server/native-shutdown.d.ts +6 -0
  159. package/dist-server/server/native-shutdown.js +28 -0
  160. package/dist-server/server/native-wren-home.d.ts +18 -0
  161. package/dist-server/server/native-wren-home.js +262 -0
  162. package/dist-server/server/node-pty-host.d.ts +2 -1
  163. package/dist-server/server/node-pty-host.js +3 -2
  164. package/dist-server/server/profile-registry.d.ts +139 -0
  165. package/dist-server/server/profile-registry.js +620 -0
  166. package/dist-server/server/runtime-binding.d.ts +4 -1
  167. package/dist-server/server/runtime-binding.js +50 -2
  168. package/dist-server/server/runtime-host/claude-component-step.d.ts +25 -0
  169. package/dist-server/server/runtime-host/claude-component-step.js +186 -0
  170. package/dist-server/server/runtime-host/codex-app-server.d.ts +75 -0
  171. package/dist-server/server/runtime-host/codex-app-server.js +239 -0
  172. package/dist-server/server/runtime-host/codex-compatibility.d.ts +110 -0
  173. package/dist-server/server/runtime-host/codex-compatibility.js +162 -0
  174. package/dist-server/server/runtime-host/codex-component-step.d.ts +19 -0
  175. package/dist-server/server/runtime-host/codex-component-step.js +308 -0
  176. package/dist-server/server/runtime-host/codex-conversation.d.ts +109 -0
  177. package/dist-server/server/runtime-host/codex-conversation.js +295 -0
  178. package/dist-server/server/runtime-host/codex-direct-tools.d.ts +23 -0
  179. package/dist-server/server/runtime-host/codex-direct-tools.js +59 -0
  180. package/dist-server/server/runtime-host/codex-events.d.ts +647 -0
  181. package/dist-server/server/runtime-host/codex-events.js +66 -0
  182. package/dist-server/server/runtime-host/codex-policy.d.ts +16 -0
  183. package/dist-server/server/runtime-host/codex-policy.js +151 -0
  184. package/dist-server/server/runtime-host/codex-process.d.ts +8 -0
  185. package/dist-server/server/runtime-host/codex-process.js +96 -0
  186. package/dist-server/server/runtime-host/codex-rpc.d.ts +47 -0
  187. package/dist-server/server/runtime-host/codex-rpc.js +182 -0
  188. package/dist-server/server/runtime-host/codex-session.d.ts +74 -0
  189. package/dist-server/server/runtime-host/codex-session.js +492 -0
  190. package/dist-server/server/runtime-host/codex-terminal-protocol.d.ts +35 -0
  191. package/dist-server/server/runtime-host/codex-terminal-protocol.js +243 -0
  192. package/dist-server/server/runtime-host/codex-terminal.d.ts +16 -0
  193. package/dist-server/server/runtime-host/codex-terminal.js +120 -0
  194. package/dist-server/server/runtime-host/index.d.ts +5 -0
  195. package/dist-server/server/runtime-host/index.js +3 -0
  196. package/dist-server/server/runtime-host/local.d.ts +29 -0
  197. package/dist-server/server/runtime-host/local.js +90 -0
  198. package/dist-server/server/runtime-host/policy.d.ts +8 -0
  199. package/dist-server/server/runtime-host/policy.js +78 -0
  200. package/dist-server/server/runtime-host/types.d.ts +52 -0
  201. package/dist-server/server/runtime-host/types.js +62 -0
  202. package/dist-server/server/structured-query-evidence.d.ts +7 -0
  203. package/dist-server/server/structured-query-evidence.js +47 -0
  204. package/dist-server/server/structured-runtime.d.ts +52 -0
  205. package/dist-server/server/structured-runtime.js +130 -0
  206. package/dist-server/server/structured-scope.d.ts +4 -0
  207. package/dist-server/server/structured-scope.js +12 -0
  208. package/dist-server/server/turn.d.ts +6 -1
  209. package/dist-server/server/turn.js +86 -26
  210. package/dist-server/server/wire-types.d.ts +67 -3
  211. package/dist-server/server/wren-profiles.js +1 -1
  212. package/managed-wren/README.md +60 -0
  213. package/managed-wren/dependency-wheels.json +282 -0
  214. package/managed-wren/manifest.json +373 -0
  215. package/managed-wren/release-inputs.json +45 -0
  216. package/managed-wren/runtime-tree.cjs +115 -0
  217. package/managed-wren/source-inputs.json +40 -0
  218. package/package.json +15 -6
  219. package/profiles/genbi-default/context/binding.yml +17 -7
  220. package/profiles/genbi-default/context/context.json +146 -0
  221. package/profiles/genbi-default/ir.golden.json +39 -43
  222. package/profiles/genbi-default/profile.yml +31 -0
  223. package/profiles/genbi-enrich-context/context/binding.yml +14 -3
  224. package/profiles/genbi-enrich-context/context/context.json +146 -0
  225. package/profiles/genbi-enrich-context/ir.golden.json +4 -5
  226. package/profiles/genbi-monitor/context/binding.yml +13 -5
  227. package/profiles/genbi-monitor/context/context.json +146 -0
  228. package/profiles/genbi-monitor/ir.golden.json +13 -7
  229. package/profiles/genbi-report/context/binding.yml +19 -0
  230. package/profiles/genbi-report/context/context.json +223 -0
  231. package/profiles/genbi-report/ir.golden.json +328 -0
  232. package/profiles/genbi-report/profile.yml +38 -0
  233. package/profiles/genbi-setup/ir.golden.json +3 -1
  234. package/dist/assets/index-Xs4q7pNo.css +0 -1
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import { createCodexRuntimeComposition, readCodexBootConfiguration } from "./codex-runtime-composition.js";
3
+ import { createCodexStructuredAdapter } from "./codex-structured-ask.js";
4
+ import { StructuredRuntime } from "./structured-runtime.js";
5
+ import { shutdownNativeResources } from "./native-shutdown.js";
2
6
  /**
3
7
  * The BFF's process entrypoint. This is the ONLY file
4
8
  * in `server/` that wires real production values (env vars, a real `Store`
@@ -30,15 +34,21 @@
30
34
  * clear 500 at dispatch time instead.
31
35
  * WREN_HARNESS_PROFILE profileSource; default resolveDefaultProfileSource()
32
36
  * WREN_HARNESS_MODE subscription|api-key|local|gateway (auth mode)
33
- * WREN_HARNESS_PROVIDER subscription provider: claude|codex
37
+ * WREN_HARNESS_PROVIDER subscription provider: claude|codex; gateway mode: pi-ai provider id
34
38
  * WREN_HARNESS_ADAPTER api-key adapter name
35
39
  * WREN_HARNESS_API_KEY api-key credential
36
40
  * WREN_HARNESS_MODEL model override
37
- * WREN_HARNESS_ENDPOINT local/gateway endpoint URL
41
+ * WREN_HARNESS_ENDPOINT local endpoint URL; gateway mode: optional custom base URL
42
+ * GENBI_GATEWAY_API_KEY gateway-mode credential for the selected pi-ai provider. Read by
43
+ * the BFF and passed per request; never persisted, and pi-ai's own
44
+ * provider env vars / credential files are never consulted
38
45
  * WREN_HARNESS_WARBLE_BIN path to the warble CLI binary
39
- * WREN_HARNESS_WREN_SHIM optional absolute server-owned Wren shim for
40
- * native Codex runtime permissions; defaults to
41
- * the fixed local installation when unset
46
+ * WREN_HARNESS_CONTEXT_LOADER_BIN
47
+ * path to the wren-context-loader binary, which renders the bound
48
+ * wren project into the prepared-context document a `kind: prepared`
49
+ * binding reads. Falls back to this repo's own Rust build; resolution
50
+ * loud-fails rather than degrading to Warble's built-in MDL adapter
51
+ * (see harness/compile/context-loader.ts)
42
52
  * WREN_HARNESS_AGENT_SDK_BIN path to the agent-sdk CLI binary (dispatched)
43
53
  * WREN_HARNESS_CODEX_LOCAL_BIN path to the warble-codex-local dispatcher CLI
44
54
  * WREN_HARNESS_CODEX_BIN optional path to the Codex CLI used by that dispatcher
@@ -95,7 +105,8 @@
95
105
  */
96
106
  import { serve } from "@hono/node-server";
97
107
  import { createRequire } from "node:module";
98
- import { existsSync } from "node:fs";
108
+ import { existsSync, realpathSync } from "node:fs";
109
+ import os from "node:os";
99
110
  import path from "node:path";
100
111
  import { fileURLToPath } from "node:url";
101
112
  import { WebSocketServer } from "ws";
@@ -104,16 +115,23 @@ import { buildTierBindingFromFlags, parseChatTimeoutMs, parseSetupMaxTurns, reso
104
115
  import { createApp } from "./app.js";
105
116
  import { recoverBootstrapProjectBinding } from "./bootstrap-project-binding.js";
106
117
  import { createHarnessProfileSources } from "./harness-profile-sources.js";
118
+ import { ProfileRegistry } from "./profile-registry.js";
119
+ import { getWarbleIdentity } from "../harness/compile/warble-identity.js";
107
120
  import { compileProfile, compileRawProfile } from "../harness/compile/index.js";
108
121
  import { resolveWarbleBinary } from "../harness/compile/resolve-binary.js";
109
122
  import { toAuthChoiceFromRuntimeSettings } from "./auth-choice.js";
110
123
  import { Store } from "./db.js";
111
124
  import { resolveEnrichmentBinding, resolveProjectIdentity } from "./enrichment.js";
125
+ import { hashDirectory } from "../harness/compile/fingerprint.js";
126
+ import { openWrenComponentAccess } from "../harness/components/wren-access.js";
112
127
  import { createDispatchedEnrichmentDraftRunner } from "./enrichment-runner.js";
113
128
  import { dispatchInteractiveArtifacts, getInteractiveTerminalReadiness, InteractiveLaunchError, InteractiveTerminalManager, prepareInteractiveHandoff, unavailableInteractiveReadiness } from "./interactive-terminal.js";
114
129
  import { createProbedPtyFactory, ensureDarwinNodePtySpawnHelper } from "./node-pty-host.js";
115
130
  import { NativeSessionService } from "./native-sessions.js";
116
131
  import { NativeArtifactService } from "./native-artifacts.js";
132
+ import { RuntimeHost } from "./runtime-host/local.js";
133
+ import { resolveManagedWrenRuntime } from "./managed-wren-runtime.js";
134
+ import { assertNativeExecutableIdentity, assertNativeRuntimeSpec, attestNativeExecutable, buildNativeChildEnvironment, buildNativeRuntimeSpec, resolveNativeExecutable } from "./native-runtime-spec.js";
117
135
  import { initializeNativeSessionStateBase, legacyInteractiveWorkspace, validateLegacyInteractiveWorkspace } from "./native-session-workspace.js";
118
136
  import { codexModelsForRuntime, compileUnboundProfileTierNames, effectiveTierModel, materializeRuntimeRouteOptions, } from "./runtime-binding.js";
119
137
  import { invalidateBundleAgentIdsCache } from "./turn.js";
@@ -187,6 +205,26 @@ async function main() {
187
205
  return undefined;
188
206
  });
189
207
  const warbleBinOption = resolvedWarbleBin !== undefined ? { warbleBin: resolvedWarbleBin } : {};
208
+ const nativeHome = realpathSync(os.homedir());
209
+ const nodeExecutable = attestNativeExecutable("node", process.execPath);
210
+ const producerExecutable = resolvedWarbleBin ? attestNativeExecutable("producer", resolvedWarbleBin) : undefined;
211
+ const bootPath = process.env["PATH"];
212
+ const claudeExecutable = resolveNativeExecutable("vendor", "claude", bootPath);
213
+ const codexExecutable = resolveNativeExecutable("vendor", "codex", bootPath);
214
+ const vendorExecutables = Object.freeze({
215
+ ...(claudeExecutable ? { claude: claudeExecutable } : {}),
216
+ ...(codexExecutable ? { codex: codexExecutable } : {}),
217
+ });
218
+ const nativeWrenExecutable = resolveNativeExecutable("wren", "wren", bootPath);
219
+ const nativeToolDirectories = Object.freeze([...new Set([
220
+ path.dirname(nodeExecutable.executable),
221
+ // Native auth and CLI tools need fixed OS utilities, even with a sanitized PATH.
222
+ ...(["darwin", "linux"].includes(process.platform) ? ["/usr/bin", "/bin", "/usr/sbin", "/sbin"].map((directory) => realpathSync(directory)) : []),
223
+ ...(nativeWrenExecutable ? [path.dirname(nativeWrenExecutable.executable)] : []),
224
+ ...Object.values(vendorExecutables).filter((value) => value !== undefined).map((value) => path.dirname(value.executable)),
225
+ ...(producerExecutable ? [path.dirname(producerExecutable.executable)] : []),
226
+ ])]);
227
+ const nativeHostEnvironment = buildNativeChildEnvironment({ toolDirectories: nativeToolDirectories, home: nativeHome });
190
228
  const profileSource = flags.profile ?? resolveDefaultProfileSource();
191
229
  // Frozen at boot: GET /api/harness accepts only a purpose and must never
192
230
  // inherit a caller-supplied RouteOptions.profileSource.
@@ -203,6 +241,19 @@ async function main() {
203
241
  // Initialization creates the fixed private namespaces once at startup.
204
242
  const nativeMaterializationState = initializeNativeSessionStateBase(dbPath);
205
243
  const store = new Store(dbPath);
244
+ // Conversation profiles a session may start inside: the shipped ones under this package's
245
+ // `profiles/` plus any the operator adds under the workspace. Registration compiles each one, so
246
+ // it runs in the background; the first `/api/profiles` request awaits the same promise.
247
+ const profileRegistry = new ProfileRegistry({
248
+ store,
249
+ builtinProfilesDir: path.dirname(harnessProfileSources.analysis),
250
+ userProfilesDir: path.join(workspaceRoot, "profiles"),
251
+ compileRaw: (source) => compileRawProfile({ profileSource: source, mode: "native", ...warbleBinOption }),
252
+ warbleIdentity: async () => (resolvedWarbleBin !== undefined ? getWarbleIdentity(resolvedWarbleBin) : "warble:unresolved"),
253
+ });
254
+ void profileRegistry.ensureReady().catch((error) => {
255
+ process.stderr.write(`warning: profile registry failed to initialize: ${error instanceof Error ? error.message : String(error)}\n`);
256
+ });
206
257
  const getCodexModels = () => codexModelsForRuntime(store.getRuntimeSettings());
207
258
  const getRuntimeTierNames = () => compileUnboundProfileTierNames({
208
259
  profileSource,
@@ -260,9 +311,11 @@ async function main() {
260
311
  boundProject = identity.path;
261
312
  const { revokedNativeSessionIds } = store.activateEnrichmentBindingAndRevokeBoundNativeSessions(identity);
262
313
  nativeSessions.revokeBindingCapabilities(revokedNativeSessionIds);
314
+ deps?.structuredRuntime?.revoke();
263
315
  invalidateBundleAgentIdsCache(deps);
264
316
  }
265
317
  function unbindProject() {
318
+ deps?.structuredRuntime?.revoke();
266
319
  boundProject = undefined;
267
320
  invalidateBundleAgentIdsCache(deps);
268
321
  }
@@ -291,6 +344,10 @@ async function main() {
291
344
  // a reset) later in the same boot. The actual logic lives in `./wren-home.js` so it's directly
292
345
  // unit-testable without going through a mocked `TurnDeps`.
293
346
  const originalWrenHome = process.env["WREN_HOME"];
347
+ const operatorWrenHome = originalWrenHome?.trim() || path.join(nativeHome, ".wren");
348
+ const nativeSourceWrenHome = () => store.getSetupMode() === "create"
349
+ ? path.join(workspaceRoot, ".wren")
350
+ : operatorWrenHome;
294
351
  const setWrenHomeForSetupMode = createSetWrenHomeForSetupMode(workspaceRoot, originalWrenHome);
295
352
  // Mutable auth-choice binding — the auth-choice mirror of boundProject above. Starts at the
296
353
  // boot-resolved `authChoice` and can be rebound later by PUT /api/config/runtime
@@ -453,7 +510,12 @@ async function main() {
453
510
  try {
454
511
  const require = createRequire(import.meta.url);
455
512
  ensureDarwinNodePtySpawnHelper(require.resolve("node-pty"));
456
- return await createProbedPtyFactory(await import("node-pty"));
513
+ assertNativeExecutableIdentity(nodeExecutable);
514
+ return await createProbedPtyFactory(await import("node-pty"), {
515
+ cwd: nativeMaterializationState.root,
516
+ env: nativeHostEnvironment,
517
+ probeExecutable: nodeExecutable.executable,
518
+ });
457
519
  }
458
520
  catch {
459
521
  throw new InteractiveLaunchError("interactive terminal host cannot spawn local processes on this machine");
@@ -470,14 +532,24 @@ async function main() {
470
532
  async function prepareInteractiveTerminal(target, binding) {
471
533
  if (enrichIrPath === undefined)
472
534
  throw new InteractiveLaunchError("interactive enrichment artifacts are not configured");
535
+ if (producerExecutable === undefined)
536
+ throw new InteractiveLaunchError("interactive enrichment materialization failed");
473
537
  const artifactRoot = legacyInteractiveWorkspace(nativeMaterializationState, binding.path, target);
538
+ const dispatchEnvironment = buildNativeChildEnvironment({
539
+ toolDirectories: nativeToolDirectories,
540
+ home: nativeHome,
541
+ projectPath: binding.path,
542
+ });
474
543
  return prepareInteractiveHandoff({
475
544
  target,
476
545
  binding,
477
546
  artifactRoot,
478
547
  materializationState: nativeMaterializationState,
479
- materialize: () => dispatchInteractiveArtifacts({ warbleBin: resolvedWarbleBin ?? "warble", irPath: enrichIrPath, target, cwd: artifactRoot, boundProject: binding.path, materializationState: nativeMaterializationState }),
480
- }, { getCurrentBinding: currentInteractiveBinding });
548
+ materialize: () => dispatchInteractiveArtifacts({ producer: producerExecutable, irPath: enrichIrPath, target, cwd: artifactRoot, env: dispatchEnvironment, boundProject: binding.path, materializationState: nativeMaterializationState }),
549
+ }, {
550
+ getCurrentBinding: currentInteractiveBinding,
551
+ resolveExecutable: (executable) => executable === "claude" ? vendorExecutables.claude : vendorExecutables.codex,
552
+ });
481
553
  }
482
554
  const nativeMcpUrl = `http://127.0.0.1:${port}/api/native-sessions/mcp`;
483
555
  const nativeArtifacts = new NativeArtifactService({
@@ -486,6 +558,33 @@ async function main() {
486
558
  expectedMcpUrl: nativeMcpUrl,
487
559
  mcpUrl: process.env["WREN_HARNESS_NATIVE_MCP_URL"] ?? nativeMcpUrl,
488
560
  getBinding: currentInteractiveBinding,
561
+ // The session `query` tool runs through the same `wren` native sessions are given.
562
+ ...(nativeWrenExecutable ? {
563
+ openQueryAccess: async (binding, signal) => openWrenComponentAccess({
564
+ executable: nativeWrenExecutable.executable, project: binding.path, fingerprint: await hashDirectory(binding.path), signal,
565
+ }),
566
+ } : {}),
567
+ });
568
+ const nativeTerminalHostAvailable = async () => {
569
+ try {
570
+ await loadPty();
571
+ return true;
572
+ }
573
+ catch {
574
+ return false;
575
+ }
576
+ };
577
+ // This is the sole production composition of the Phase-1 policy. Browser
578
+ // requests never reach this selection or its executable/policy inputs.
579
+ const codexConfiguration = readCodexBootConfiguration(process.env);
580
+ const codexComposition = createCodexRuntimeComposition({ configuration: codexConfiguration, packageRoot,
581
+ producerBinary: producerExecutable?.executable ?? "", profileSource: harnessProfileSources.analysis, store,
582
+ getBinding: currentInteractiveBinding, sourceWrenHome: nativeSourceWrenHome, artifacts: nativeArtifacts });
583
+ const nativeRuntimeHost = new RuntimeHost({
584
+ selected: codexConfiguration.selected,
585
+ deployment: process.env["NODE_ENV"] === "production" ? "production" : "development",
586
+ localAvailable: () => codexConfiguration.allowLocal ? nativeTerminalHostAvailable() : false,
587
+ vendorProbes: { "codex-app-server": codexComposition.probe },
489
588
  });
490
589
  const nativeSessions = new NativeSessionService({
491
590
  store,
@@ -503,32 +602,56 @@ async function main() {
503
602
  // Setup has no binding by definition, so it compiles the profile's authored
504
603
  // context with no user project composed in; its golden resolves nothing
505
604
  // either, which is why Setup never showed this symptom.
506
- resolveDispatchIr: async (purpose, binding) => {
507
- const profileSource = harnessProfileSources[purpose];
605
+ resolveDispatchIr: async (purpose, binding, selectedProfileSource) => {
606
+ // A selected conversation profile compiles from the registry's copy; everything else from the
607
+ // boot-time source for its purpose.
608
+ const profileSource = selectedProfileSource ?? harnessProfileSources[purpose];
508
609
  const compiled = purpose === "setup" || binding === undefined
509
610
  ? await compileRawProfile({ profileSource, mode: "native", ...warbleBinOption })
510
611
  : await compileProfile({ profileSource, userProject: binding.path, mode: "native", ...warbleBinOption });
511
612
  return compiled.irPath;
512
613
  },
614
+ resolveConversationProfile: async (id) => {
615
+ const { row, sourceDir } = await profileRegistry.resolveConversationProfileSource(id);
616
+ return { id: row.id, sourceDir, entry: row.entryKind === "agent" && row.entryVerb !== null ? { kind: "agent", verb: row.entryVerb } : { kind: "scope" } };
617
+ },
618
+ listConversationProfiles: async () => (await profileRegistry.list())
619
+ .filter((row) => row.role === "conversation")
620
+ .map((row) => ({
621
+ id: row.id,
622
+ selectable: row.admissionStatus === "admitted",
623
+ ...(row.admissionReason !== null ? { reason: row.admissionReason } : {}),
624
+ ...(row.entryKind !== null ? { entryKind: row.entryKind } : {}),
625
+ ...(row.entryVerb !== null ? { entryVerb: row.entryVerb } : {}),
626
+ })),
513
627
  // The service's option is a required string; when resolution failed the bare
514
628
  // name is what the preflight will report as unresolvable, with its reason.
515
- warbleBin: resolvedWarbleBin ?? "warble",
516
- ...(process.env["WREN_HARNESS_WREN_SHIM"] !== undefined ? { wrenShim: process.env["WREN_HARNESS_WREN_SHIM"] } : {}),
517
- terminalHostAvailable: async () => {
518
- try {
519
- await loadPty();
520
- return true;
521
- }
522
- catch {
523
- return false;
524
- }
525
- },
629
+ warbleBin: producerExecutable?.executable ?? "warble",
630
+ terminalHostAvailable: nativeTerminalHostAvailable,
631
+ runtimeHost: nativeRuntimeHost,
632
+ directCodex: codexComposition.native,
633
+ resolveManagedCodexWrenRuntime: () => resolveManagedWrenRuntime({ packageRoot }),
634
+ nativeHome,
635
+ sourceWrenHome: nativeSourceWrenHome,
636
+ ...(baseRouteOptions.codexHome ? { codexHome: baseRouteOptions.codexHome } : {}),
637
+ vendorExecutables,
638
+ nodeExecutable,
639
+ childToolDirectories: nativeToolDirectories,
640
+ ...(bootPath !== undefined ? { pathValue: bootPath } : {}),
526
641
  artifactService: nativeArtifacts,
527
642
  });
643
+ // Explicit opt-in remains behind the packaged exact-version certification gate.
644
+ const structuredRuntime = new StructuredRuntime({
645
+ selected: { codex: codexConfiguration.selected, claude: "local" }, allowLocal: codexConfiguration.allowLocal, deployment,
646
+ adapters: { codex: createCodexStructuredAdapter(codexComposition.structured) },
647
+ localRoute: route, localSetupFor: (choice) => setupRunnerFor?.(choice) ?? setupRunner,
648
+ });
528
649
  deps = {
529
650
  store,
651
+ structuredRuntime,
530
652
  nativeSessions,
531
653
  nativeArtifacts,
654
+ profileRegistry,
532
655
  route,
533
656
  baseRouteOptions,
534
657
  describeBundle: (options) => {
@@ -540,8 +663,8 @@ async function main() {
540
663
  : {}),
541
664
  });
542
665
  },
543
- describeHarnessBundle: (purpose, options) => {
544
- const profileSource = harnessProfileSources[purpose];
666
+ describeHarnessBundle: (purpose, options, selectedProfileSource) => {
667
+ const profileSource = selectedProfileSource ?? harnessProfileSources[purpose];
545
668
  const common = {
546
669
  ...options,
547
670
  profileSource,
@@ -570,7 +693,24 @@ async function main() {
570
693
  const { spec } = await prepareInteractiveTerminal(target, binding);
571
694
  const manager = await terminalManager();
572
695
  validateLegacyInteractiveWorkspace(nativeMaterializationState, binding.path, spec.cwd);
573
- return manager.start(spec, undefined, { ...process.env, WREN_PROJECT_HOME: binding.path });
696
+ if (producerExecutable === undefined || spec.hostExecutable === undefined)
697
+ throw new InteractiveLaunchError("interactive enrichment materialization failed");
698
+ const runtimeSpec = buildNativeRuntimeSpec({
699
+ backend: "local",
700
+ vendor: target === "claude-code:interactive" ? "claude" : "codex",
701
+ executables: [
702
+ nodeExecutable,
703
+ producerExecutable,
704
+ attestNativeExecutable("vendor", spec.hostExecutable),
705
+ ],
706
+ toolDirectories: nativeToolDirectories,
707
+ workspace: spec.cwd,
708
+ home: nativeHome,
709
+ binding,
710
+ ...(target === "codex:interactive" && baseRouteOptions.codexHome ? { codexHome: baseRouteOptions.codexHome } : {}),
711
+ });
712
+ assertNativeRuntimeSpec(runtimeSpec);
713
+ return manager.start(spec, undefined, runtimeSpec.childEnvironment);
574
714
  },
575
715
  prepareInteractiveTerminal: async ({ target, binding }) => {
576
716
  return (await prepareInteractiveTerminal(target, binding)).handoff;
@@ -592,6 +732,7 @@ async function main() {
592
732
  return false;
593
733
  }
594
734
  },
735
+ resolveExecutable: (executable) => executable === "claude" ? vendorExecutables.claude : vendorExecutables.codex,
595
736
  });
596
737
  },
597
738
  workspaceRoot,
@@ -605,6 +746,25 @@ async function main() {
605
746
  const server = serve({ fetch: app.fetch, websocket: { server: websocket }, hostname: "127.0.0.1", port }, (info) => {
606
747
  process.stdout.write(`wren-harness BFF listening on http://127.0.0.1:${info.port} (db: ${dbPath})\n`);
607
748
  });
749
+ const shutdown = () => {
750
+ const deadline = setTimeout(() => process.exit(1), 12_000);
751
+ void shutdownNativeResources({
752
+ shutdownSessions: async () => {
753
+ const results = await Promise.allSettled([nativeSessions.shutdown(), structuredRuntime.shutdown(), codexComposition.shutdown()]);
754
+ if (results.some((result) => result.status === "rejected"))
755
+ throw new Error("Session cleanup failed");
756
+ },
757
+ closeTerminals: () => interactiveTerminal?.closeAll(),
758
+ closeServer: () => { server.close(); },
759
+ }).then((code) => {
760
+ if (code)
761
+ process.stderr.write("error: native session cleanup did not complete\n");
762
+ clearTimeout(deadline);
763
+ process.exit(code);
764
+ });
765
+ };
766
+ process.once("SIGTERM", shutdown);
767
+ process.once("SIGINT", shutdown);
608
768
  // Without this, a port that is already taken surfaces as an unhandled 'error' event and a raw
609
769
  // Node stack trace -- the first thing a new user is likely to hit, and the least readable.
610
770
  server.on("error", (error) => {
@@ -0,0 +1,25 @@
1
+ import type { CodexAppServerBackend, CodexLaunchPermit } from "./runtime-host/codex-app-server.js";
2
+ import type { CodexSessionTools } from "./runtime-host/codex-direct-tools.js";
3
+ import type { EnrichmentBinding } from "./enrichment.js";
4
+ import type { NativeSessionRow } from "./db.js";
5
+ /** Server-only provisioner. A ready probe alone never authorizes materialization. */
6
+ export interface DirectCodexProvisioner {
7
+ /** Official remote CLI renderer; the host still owns the governed thread. */
8
+ readonly terminal?: boolean;
9
+ readonly terminalCertified?: (entry: string) => boolean;
10
+ readonly backend: Pick<CodexAppServerBackend, "prepareLaunch" | "open">;
11
+ /** Own and clean partial allocations on failure. Never receives browser paths or credentials. */
12
+ prepare(input: {
13
+ readonly session: NativeSessionRow;
14
+ readonly binding: EnrichmentBinding;
15
+ readonly permit: CodexLaunchPermit;
16
+ readonly signal: AbortSignal;
17
+ readonly assertActive: () => void;
18
+ }): Promise<{
19
+ readonly input: Omit<Parameters<CodexAppServerBackend["open"]>[1], "onEvent" | "tools"> & {
20
+ readonly tools: CodexSessionTools;
21
+ };
22
+ /** Runs after the conversation and scoped tools have closed. */
23
+ dispose(): Promise<void>;
24
+ }>;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { Store } from "./db.js";
2
+ import type { EnrichmentBinding } from "./enrichment.js";
3
+ import type { NativeArtifactService } from "./native-artifacts.js";
4
+ import type { RuntimeBackendProbeResult } from "./runtime-host/types.js";
5
+ import type { DirectCodexProvisioner } from "./codex-native-session.js";
6
+ import type { CodexStructuredProvisioner } from "./codex-structured-ask.js";
7
+ export interface CodexBootConfiguration {
8
+ readonly selected: "local" | "codex-app-server";
9
+ readonly allowLocal: boolean;
10
+ readonly executable?: string;
11
+ readonly source?: string;
12
+ readonly loginHome?: string;
13
+ readonly accountEmail?: string;
14
+ }
15
+ /** Read once at composition. No browser values, PATH discovery or credential copying. */
16
+ export declare function readCodexBootConfiguration(env: NodeJS.ProcessEnv): CodexBootConfiguration;
17
+ interface Options {
18
+ readonly configuration: CodexBootConfiguration;
19
+ readonly packageRoot: string;
20
+ readonly producerBinary: string;
21
+ readonly profileSource: string;
22
+ readonly store: Store;
23
+ readonly getBinding: () => EnrichmentBinding | undefined;
24
+ readonly sourceWrenHome: () => string;
25
+ readonly artifacts: NativeArtifactService;
26
+ }
27
+ /** Real composition for both entry surfaces; certification is enforced by the packaged backend. */
28
+ export declare function createCodexRuntimeComposition(options: Options): {
29
+ probe: () => Promise<RuntimeBackendProbeResult<"codex-app-server">>;
30
+ native: DirectCodexProvisioner;
31
+ structured: CodexStructuredProvisioner;
32
+ shutdown: () => Promise<void>;
33
+ };
34
+ export {};