@wrenai/genbi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +141 -0
  3. package/bin/genbi.mjs +31 -0
  4. package/dist/assets/echarts-LTFC-ysd.js +40 -0
  5. package/dist/assets/index-Bo--QMUN.js +441 -0
  6. package/dist/assets/index-Xs4q7pNo.css +1 -0
  7. package/dist/index.html +14 -0
  8. package/dist/wrenai_logo.png +0 -0
  9. package/dist/wrenai_logo_white.png +0 -0
  10. package/dist-server/harness/auth/detect.d.ts +18 -0
  11. package/dist-server/harness/auth/detect.js +37 -0
  12. package/dist-server/harness/auth/index.d.ts +4 -0
  13. package/dist-server/harness/auth/index.js +2 -0
  14. package/dist-server/harness/auth/probe.d.ts +18 -0
  15. package/dist-server/harness/auth/probe.js +52 -0
  16. package/dist-server/harness/auth/types.d.ts +42 -0
  17. package/dist-server/harness/auth/types.js +9 -0
  18. package/dist-server/harness/bundle/loader.d.ts +32 -0
  19. package/dist-server/harness/bundle/loader.js +43 -0
  20. package/dist-server/harness/bundle/schema.d.ts +199 -0
  21. package/dist-server/harness/bundle/schema.js +127 -0
  22. package/dist-server/harness/bundle/version.d.ts +10 -0
  23. package/dist-server/harness/bundle/version.js +43 -0
  24. package/dist-server/harness/capability/gate.d.ts +6 -0
  25. package/dist-server/harness/capability/gate.js +29 -0
  26. package/dist-server/harness/capability/registry.d.ts +6 -0
  27. package/dist-server/harness/capability/registry.js +17 -0
  28. package/dist-server/harness/cli-args.d.ts +123 -0
  29. package/dist-server/harness/cli-args.js +247 -0
  30. package/dist-server/harness/cli.d.ts +2 -0
  31. package/dist-server/harness/cli.js +151 -0
  32. package/dist-server/harness/compile/cache.d.ts +23 -0
  33. package/dist-server/harness/compile/cache.js +109 -0
  34. package/dist-server/harness/compile/compose-profile.d.ts +34 -0
  35. package/dist-server/harness/compile/compose-profile.js +95 -0
  36. package/dist-server/harness/compile/errors.d.ts +22 -0
  37. package/dist-server/harness/compile/errors.js +41 -0
  38. package/dist-server/harness/compile/fingerprint.d.ts +22 -0
  39. package/dist-server/harness/compile/fingerprint.js +84 -0
  40. package/dist-server/harness/compile/index.d.ts +8 -0
  41. package/dist-server/harness/compile/index.js +7 -0
  42. package/dist-server/harness/compile/pipeline.d.ts +66 -0
  43. package/dist-server/harness/compile/pipeline.js +176 -0
  44. package/dist-server/harness/compile/resolve-binary.d.ts +55 -0
  45. package/dist-server/harness/compile/resolve-binary.js +133 -0
  46. package/dist-server/harness/compile/types.d.ts +107 -0
  47. package/dist-server/harness/compile/types.js +1 -0
  48. package/dist-server/harness/compile/warble-identity.d.ts +12 -0
  49. package/dist-server/harness/compile/warble-identity.js +33 -0
  50. package/dist-server/harness/compliance/gate.d.ts +35 -0
  51. package/dist-server/harness/compliance/gate.js +48 -0
  52. package/dist-server/harness/compliance/index.d.ts +2 -0
  53. package/dist-server/harness/compliance/index.js +1 -0
  54. package/dist-server/harness/compliance/types.d.ts +16 -0
  55. package/dist-server/harness/compliance/types.js +1 -0
  56. package/dist-server/harness/events/emitter.d.ts +34 -0
  57. package/dist-server/harness/events/emitter.js +25 -0
  58. package/dist-server/harness/events/index.d.ts +4 -0
  59. package/dist-server/harness/events/index.js +2 -0
  60. package/dist-server/harness/events/sse.d.ts +20 -0
  61. package/dist-server/harness/events/sse.js +48 -0
  62. package/dist-server/harness/events/types.d.ts +131 -0
  63. package/dist-server/harness/events/types.js +1 -0
  64. package/dist-server/harness/exec/errors.d.ts +16 -0
  65. package/dist-server/harness/exec/errors.js +29 -0
  66. package/dist-server/harness/exec/index.d.ts +5 -0
  67. package/dist-server/harness/exec/index.js +2 -0
  68. package/dist-server/harness/exec/local.d.ts +32 -0
  69. package/dist-server/harness/exec/local.js +134 -0
  70. package/dist-server/harness/exec/policy.d.ts +12 -0
  71. package/dist-server/harness/exec/policy.js +1 -0
  72. package/dist-server/harness/exec/types.d.ts +63 -0
  73. package/dist-server/harness/exec/types.js +1 -0
  74. package/dist-server/harness/guardrails/index.d.ts +2 -0
  75. package/dist-server/harness/guardrails/index.js +1 -0
  76. package/dist-server/harness/guardrails/policy.d.ts +45 -0
  77. package/dist-server/harness/guardrails/policy.js +57 -0
  78. package/dist-server/harness/index.d.ts +37 -0
  79. package/dist-server/harness/index.js +19 -0
  80. package/dist-server/harness/loop/errors.d.ts +53 -0
  81. package/dist-server/harness/loop/errors.js +72 -0
  82. package/dist-server/harness/loop/executor.d.ts +123 -0
  83. package/dist-server/harness/loop/executor.js +380 -0
  84. package/dist-server/harness/loop/guard.d.ts +16 -0
  85. package/dist-server/harness/loop/guard.js +1 -0
  86. package/dist-server/harness/loop/index.d.ts +5 -0
  87. package/dist-server/harness/loop/index.js +3 -0
  88. package/dist-server/harness/native-producer/index.d.ts +109 -0
  89. package/dist-server/harness/native-producer/index.js +302 -0
  90. package/dist-server/harness/npm-package-resolve.d.ts +28 -0
  91. package/dist-server/harness/npm-package-resolve.js +47 -0
  92. package/dist-server/harness/providers/adapters/anthropic.d.ts +7 -0
  93. package/dist-server/harness/providers/adapters/anthropic.js +6 -0
  94. package/dist-server/harness/providers/adapters/mock.d.ts +4 -0
  95. package/dist-server/harness/providers/adapters/mock.js +5 -0
  96. package/dist-server/harness/providers/adapters/openai-compatible.d.ts +10 -0
  97. package/dist-server/harness/providers/adapters/openai-compatible.js +10 -0
  98. package/dist-server/harness/providers/binding.d.ts +23 -0
  99. package/dist-server/harness/providers/binding.js +13 -0
  100. package/dist-server/harness/providers/errors.d.ts +6 -0
  101. package/dist-server/harness/providers/errors.js +12 -0
  102. package/dist-server/harness/providers/index.d.ts +18 -0
  103. package/dist-server/harness/providers/index.js +22 -0
  104. package/dist-server/harness/providers/registry.d.ts +16 -0
  105. package/dist-server/harness/providers/registry.js +24 -0
  106. package/dist-server/harness/render/envelope.d.ts +145 -0
  107. package/dist-server/harness/render/envelope.js +428 -0
  108. package/dist-server/harness/render/errors.d.ts +33 -0
  109. package/dist-server/harness/render/errors.js +46 -0
  110. package/dist-server/harness/render/index.d.ts +5 -0
  111. package/dist-server/harness/render/index.js +3 -0
  112. package/dist-server/harness/render/validate.d.ts +13 -0
  113. package/dist-server/harness/render/validate.js +88 -0
  114. package/dist-server/harness/route/adapter-spec.d.ts +40 -0
  115. package/dist-server/harness/route/adapter-spec.js +61 -0
  116. package/dist-server/harness/route/agent-sdk-cli.d.ts +30 -0
  117. package/dist-server/harness/route/agent-sdk-cli.js +86 -0
  118. package/dist-server/harness/route/agent-sdk-manifest.d.ts +31 -0
  119. package/dist-server/harness/route/agent-sdk-manifest.js +56 -0
  120. package/dist-server/harness/route/artifact-content.d.ts +53 -0
  121. package/dist-server/harness/route/artifact-content.js +83 -0
  122. package/dist-server/harness/route/chat-event-mapper.d.ts +95 -0
  123. package/dist-server/harness/route/chat-event-mapper.js +164 -0
  124. package/dist-server/harness/route/codex-ask-events.d.ts +25 -0
  125. package/dist-server/harness/route/codex-ask-events.js +395 -0
  126. package/dist-server/harness/route/codex-ask.d.ts +15 -0
  127. package/dist-server/harness/route/codex-ask.js +242 -0
  128. package/dist-server/harness/route/codex-local-cli.d.ts +20 -0
  129. package/dist-server/harness/route/codex-local-cli.js +78 -0
  130. package/dist-server/harness/route/codex-local-manifest.d.ts +22 -0
  131. package/dist-server/harness/route/codex-local-manifest.js +180 -0
  132. package/dist-server/harness/route/describe.d.ts +54 -0
  133. package/dist-server/harness/route/describe.js +84 -0
  134. package/dist-server/harness/route/dispatched.d.ts +138 -0
  135. package/dist-server/harness/route/dispatched.js +339 -0
  136. package/dist-server/harness/route/in-process.d.ts +43 -0
  137. package/dist-server/harness/route/in-process.js +106 -0
  138. package/dist-server/harness/route/index.d.ts +19 -0
  139. package/dist-server/harness/route/index.js +12 -0
  140. package/dist-server/harness/route/profile-source.d.ts +37 -0
  141. package/dist-server/harness/route/profile-source.js +76 -0
  142. package/dist-server/harness/route/route.d.ts +33 -0
  143. package/dist-server/harness/route/route.js +114 -0
  144. package/dist-server/harness/route/tier-binding.d.ts +36 -0
  145. package/dist-server/harness/route/tier-binding.js +63 -0
  146. package/dist-server/harness/route/types.d.ts +286 -0
  147. package/dist-server/harness/route/types.js +1 -0
  148. package/dist-server/harness/session/errors.d.ts +4 -0
  149. package/dist-server/harness/session/errors.js +7 -0
  150. package/dist-server/harness/session/gate.d.ts +11 -0
  151. package/dist-server/harness/session/gate.js +13 -0
  152. package/dist-server/harness/session/index.d.ts +5 -0
  153. package/dist-server/harness/session/index.js +3 -0
  154. package/dist-server/harness/session/run.d.ts +60 -0
  155. package/dist-server/harness/session/run.js +333 -0
  156. package/dist-server/harness/session/types.d.ts +29 -0
  157. package/dist-server/harness/session/types.js +1 -0
  158. package/dist-server/harness/setup/codex-events.d.ts +12 -0
  159. package/dist-server/harness/setup/codex-events.js +108 -0
  160. package/dist-server/harness/setup/runner.d.ts +497 -0
  161. package/dist-server/harness/setup/runner.js +1314 -0
  162. package/dist-server/harness/tools/errors.d.ts +107 -0
  163. package/dist-server/harness/tools/errors.js +141 -0
  164. package/dist-server/harness/tools/index.d.ts +13 -0
  165. package/dist-server/harness/tools/index.js +8 -0
  166. package/dist-server/harness/tools/mcp.d.ts +26 -0
  167. package/dist-server/harness/tools/mcp.js +15 -0
  168. package/dist-server/harness/tools/native.d.ts +179 -0
  169. package/dist-server/harness/tools/native.js +322 -0
  170. package/dist-server/harness/tools/parse.d.ts +14 -0
  171. package/dist-server/harness/tools/parse.js +18 -0
  172. package/dist-server/harness/tools/resolve-wren-binary.d.ts +12 -0
  173. package/dist-server/harness/tools/resolve-wren-binary.js +21 -0
  174. package/dist-server/harness/tools/resolve.d.ts +51 -0
  175. package/dist-server/harness/tools/resolve.js +79 -0
  176. package/dist-server/harness/tools/setup-native.d.ts +84 -0
  177. package/dist-server/harness/tools/setup-native.js +353 -0
  178. package/dist-server/harness/tools/wiring.d.ts +10 -0
  179. package/dist-server/harness/tools/wiring.js +16 -0
  180. package/dist-server/providers/setup.provider.yaml +31 -0
  181. package/dist-server/providers/wren.provider.yaml +33 -0
  182. package/dist-server/server/adopt.d.ts +87 -0
  183. package/dist-server/server/adopt.js +263 -0
  184. package/dist-server/server/app.d.ts +6 -0
  185. package/dist-server/server/app.js +2521 -0
  186. package/dist-server/server/auth-choice.d.ts +16 -0
  187. package/dist-server/server/auth-choice.js +36 -0
  188. package/dist-server/server/bin.d.ts +2 -0
  189. package/dist-server/server/bin.js +601 -0
  190. package/dist-server/server/bootstrap-project-binding.d.ts +31 -0
  191. package/dist-server/server/bootstrap-project-binding.js +71 -0
  192. package/dist-server/server/clarify.d.ts +10 -0
  193. package/dist-server/server/clarify.js +17 -0
  194. package/dist-server/server/codex-setup-mcp.d.ts +2 -0
  195. package/dist-server/server/codex-setup-mcp.js +147 -0
  196. package/dist-server/server/compose.d.ts +89 -0
  197. package/dist-server/server/compose.js +271 -0
  198. package/dist-server/server/conn-config.d.ts +30 -0
  199. package/dist-server/server/conn-config.js +253 -0
  200. package/dist-server/server/context-files.d.ts +12 -0
  201. package/dist-server/server/context-files.js +117 -0
  202. package/dist-server/server/context-map.d.ts +30 -0
  203. package/dist-server/server/context-map.js +95 -0
  204. package/dist-server/server/context-source.d.ts +68 -0
  205. package/dist-server/server/context-source.js +85 -0
  206. package/dist-server/server/db.d.ts +862 -0
  207. package/dist-server/server/db.js +1839 -0
  208. package/dist-server/server/enrichment-runner.d.ts +184 -0
  209. package/dist-server/server/enrichment-runner.js +213 -0
  210. package/dist-server/server/enrichment-verify.d.ts +73 -0
  211. package/dist-server/server/enrichment-verify.js +290 -0
  212. package/dist-server/server/enrichment.d.ts +232 -0
  213. package/dist-server/server/enrichment.js +199 -0
  214. package/dist-server/server/env-detect.d.ts +8 -0
  215. package/dist-server/server/env-detect.js +17 -0
  216. package/dist-server/server/env-field-hints.d.ts +46 -0
  217. package/dist-server/server/env-field-hints.js +48 -0
  218. package/dist-server/server/fold.d.ts +133 -0
  219. package/dist-server/server/fold.js +407 -0
  220. package/dist-server/server/harness-profile-sources.d.ts +3 -0
  221. package/dist-server/server/harness-profile-sources.js +24 -0
  222. package/dist-server/server/harness.d.ts +19 -0
  223. package/dist-server/server/harness.js +439 -0
  224. package/dist-server/server/impact.d.ts +18 -0
  225. package/dist-server/server/impact.js +85 -0
  226. package/dist-server/server/interactive-terminal.d.ts +175 -0
  227. package/dist-server/server/interactive-terminal.js +336 -0
  228. package/dist-server/server/native-artifacts.d.ts +1004 -0
  229. package/dist-server/server/native-artifacts.js +564 -0
  230. package/dist-server/server/native-dispatch-registry.d.ts +42 -0
  231. package/dist-server/server/native-dispatch-registry.js +45 -0
  232. package/dist-server/server/native-producer-fence.d.ts +14 -0
  233. package/dist-server/server/native-producer-fence.js +48 -0
  234. package/dist-server/server/native-session-resume.d.ts +6 -0
  235. package/dist-server/server/native-session-resume.js +103 -0
  236. package/dist-server/server/native-session-workspace.d.ts +40 -0
  237. package/dist-server/server/native-session-workspace.js +175 -0
  238. package/dist-server/server/native-sessions.d.ts +374 -0
  239. package/dist-server/server/native-sessions.js +1517 -0
  240. package/dist-server/server/native-wren-runtime.d.ts +20 -0
  241. package/dist-server/server/native-wren-runtime.js +259 -0
  242. package/dist-server/server/node-pty-host.d.ts +31 -0
  243. package/dist-server/server/node-pty-host.js +100 -0
  244. package/dist-server/server/route-intent.d.ts +40 -0
  245. package/dist-server/server/route-intent.js +23 -0
  246. package/dist-server/server/runtime-binding.d.ts +52 -0
  247. package/dist-server/server/runtime-binding.js +258 -0
  248. package/dist-server/server/source-catalog.d.ts +84 -0
  249. package/dist-server/server/source-catalog.js +221 -0
  250. package/dist-server/server/source-driver.d.ts +35 -0
  251. package/dist-server/server/source-driver.js +124 -0
  252. package/dist-server/server/spa.d.ts +2 -0
  253. package/dist-server/server/spa.js +51 -0
  254. package/dist-server/server/subscription-model-catalog.d.ts +27 -0
  255. package/dist-server/server/subscription-model-catalog.js +203 -0
  256. package/dist-server/server/turn.d.ts +249 -0
  257. package/dist-server/server/turn.js +1074 -0
  258. package/dist-server/server/wire-types.d.ts +799 -0
  259. package/dist-server/server/wire-types.js +1 -0
  260. package/dist-server/server/wren-home.d.ts +19 -0
  261. package/dist-server/server/wren-home.js +33 -0
  262. package/dist-server/server/wren-profiles.d.ts +43 -0
  263. package/dist-server/server/wren-profiles.js +123 -0
  264. package/package.json +93 -0
  265. package/profiles/genbi-default/context/binding.yml +9 -0
  266. package/profiles/genbi-default/ir.golden.json +506 -0
  267. package/profiles/genbi-default/profile.yml +16 -0
  268. package/profiles/genbi-enrich-context/components/apply_enrichment/component.yml +42 -0
  269. package/profiles/genbi-enrich-context/components/draft_enrichment/component.yml +30 -0
  270. package/profiles/genbi-enrich-context/components/draft_enrichment/steps/draft.md +34 -0
  271. package/profiles/genbi-enrich-context/components/inspect_context/component.yml +32 -0
  272. package/profiles/genbi-enrich-context/components/inspect_context/steps/inspect.md +13 -0
  273. package/profiles/genbi-enrich-context/context/binding.yml +4 -0
  274. package/profiles/genbi-enrich-context/ir.golden.json +302 -0
  275. package/profiles/genbi-enrich-context/profile.yml +15 -0
  276. package/profiles/genbi-monitor/context/binding.yml +7 -0
  277. package/profiles/genbi-monitor/ir.golden.json +188 -0
  278. package/profiles/genbi-monitor/profile.yml +27 -0
  279. package/profiles/genbi-setup/components/build_context/component.yml +44 -0
  280. package/profiles/genbi-setup/components/build_context/steps/build.md +14 -0
  281. package/profiles/genbi-setup/components/connect_source/component.yml +51 -0
  282. package/profiles/genbi-setup/components/connect_source/steps/connect.md +23 -0
  283. package/profiles/genbi-setup/context/binding.yml +8 -0
  284. package/profiles/genbi-setup/ir.golden.json +140 -0
  285. package/profiles/genbi-setup/profile.yml +18 -0
  286. package/profiles/genbi-setup/raw/schema.json +5 -0
@@ -0,0 +1,286 @@
1
+ import type { AuthChoice } from "../auth/index.js";
2
+ import type { Bundle } from "../bundle/schema.js";
3
+ import type { Deployment } from "../compliance/index.js";
4
+ import type { AgentEvent } from "../events/index.js";
5
+ import type { AdapterSpec } from "../providers/index.js";
6
+ import type { RunAgentResult } from "../session/index.js";
7
+ import type { McpServerConfigMap } from "../tools/index.js";
8
+ import type { ResolvedCli } from "./agent-sdk-cli.js";
9
+ import type { CodexManifestModels } from "./codex-local-manifest.js";
10
+ /**
11
+ * In-process ("api-key" | "local" | "gateway"): compile the profile to a vercel
12
+ * bundle and run it in-process via `runAgent`. `bundle`/`mcpServers` are
13
+ * test-only overrides — production callers leave them unset and let
14
+ * `runInProcessDefault` compile+load the bundle itself and resolve the `query`
15
+ * tool through the real `wren` CLI (native tools) against `userProject`.
16
+ */
17
+ export interface InProcessOptions {
18
+ readonly authChoice: Extract<AuthChoice, {
19
+ mode: "api-key" | "local" | "gateway";
20
+ }>;
21
+ readonly profileSource: string;
22
+ readonly userProject: string;
23
+ readonly question: string;
24
+ /**
25
+ * Only consulted when `authChoice.mode === "local"` — `LocalAuthChoice` has
26
+ * no `model` field of its own, but the `openai-compatible` adapter it maps to
27
+ * requires one. See `DEFAULT_LOCAL_MODEL`.
28
+ */
29
+ readonly model?: string;
30
+ readonly warbleBin?: string;
31
+ readonly workDir?: string;
32
+ /**
33
+ * Base directory the native `write_artifact` tool's scoped
34
+ * workspace (`createLocalExecutionEnv({ rootDir })`) resolves under.
35
+ * Independent of `userProject` — that only governs the `query` tool's
36
+ * exec cwd (see `createWrenQueryTool`), never artifact writes. Defaults
37
+ * to `WREN_HARNESS_ARTIFACTS_DIR` (env var) or a fixed `os.tmpdir()`
38
+ * path when unset; see `resolveArtifactsDir` in `in-process.ts`. Never
39
+ * `process.cwd()` — that was the bug this option fixes.
40
+ */
41
+ readonly outDir?: string;
42
+ /** Test-only: skip `compileProfile`/`loadBundle` and run this bundle directly. */
43
+ readonly bundle?: Bundle;
44
+ /** Test-only: route the `query` tool through an injected MCP server instead of the real `wren` CLI. */
45
+ readonly mcpServers?: McpServerConfigMap;
46
+ /**
47
+ * The "hybrid" per-tier override: a NON-uniform map from tier name to its
48
+ * own `AdapterSpec`, e.g. `{ cheap: <local endpoint>, strong: <cloud
49
+ * adapter> }`. When set, `runInProcessDefault` binds via
50
+ * `buildHybridTierBinding` (which validates every tier the compiled
51
+ * `answer_query` agent uses is covered, and rejects unknown tier names)
52
+ * instead of `buildUniformTierBinding`'s single-adapter-for-every-tier
53
+ * default; `authChoice`/`model` are then only consulted for anything
54
+ * `tierBinding` doesn't already cover — today that's nothing, since
55
+ * coverage is total-or-loud-fail.
56
+ */
57
+ readonly tierBinding?: Readonly<Record<string, AdapterSpec>>;
58
+ /** Live-event layer: forwarded to `RunAgentContext.onEvent`. See that field's doc comment. */
59
+ readonly onEvent?: (event: AgentEvent) => void;
60
+ /**
61
+ * Intent routing: which compiled agent to run `question` against.
62
+ * Defaults to `ANSWER_QUERY_AGENT_ID` (`"answer_query"`) when unset — the
63
+ * original default from before intent routing existed. Callers (the BFF's `server/turn.ts`) resolve this via
64
+ * `server/route-intent.ts`'s deterministic `classifyIntent` before
65
+ * invoking `route()`; `runInProcessDefault` itself does no classification of
66
+ * its own.
67
+ */
68
+ readonly agentId?: string;
69
+ }
70
+ export type InProcessExecutor = (options: InProcessOptions) => Promise<RunAgentResult>;
71
+ /**
72
+ * Dispatched ("subscription"): compile the profile to IR only, then shell the
73
+ * warble `claude-agent-sdk` dispatcher's `chat` subcommand to answer via a
74
+ * Dispatched component (`options.agentId`, defaulting to `"answer_query"`).
75
+ */
76
+ export interface DispatchedOptions {
77
+ readonly authChoice: Extract<AuthChoice, {
78
+ mode: "subscription";
79
+ }>;
80
+ readonly profileSource: string;
81
+ readonly userProject: string;
82
+ readonly question: string;
83
+ /**
84
+ * Belt gate: deployment context for `runDispatchedDefault`'s own
85
+ * `enforceCompliance` call, independent of whatever gate the caller (e.g.
86
+ * `route()` or the CLI) already ran before reaching here. Defaults to
87
+ * `"personal"` — an embedder that imports `runDispatchedDefault` directly
88
+ * (bypassing `route()` entirely) still gets the real compliance decision
89
+ * rather than an implicit, ungated `"personal"` assumption with no check
90
+ * at all.
91
+ */
92
+ readonly deployment?: Deployment;
93
+ readonly warbleBin?: string;
94
+ /** Explicit override for resolving the warble-agent-sdk CLI. See `resolveAgentSdkCli`. */
95
+ readonly agentSdkBin?: string;
96
+ /** Run output directory the CLI writes into. Defaults to a fresh `os.tmpdir()` mkdtemp. */
97
+ readonly outDir?: string;
98
+ readonly workDir?: string;
99
+ /**
100
+ * The "hybrid" passthrough: an explicit path to a `warble-agent-sdk`
101
+ * `--models-config <yaml>` file, forwarded verbatim to the `chat`
102
+ * invocation (see `ModelConfig.fromYaml`, warble's `dispatcher/
103
+ * claude-agent-sdk/src/models.ts`). This is pure argv plumbing — the
104
+ * harness never parses or validates the YAML itself; that per-step
105
+ * provider routing (subscription main loop + one non-Anthropic step) is
106
+ * entirely warble's own mechanism. See known limitations in `route/dispatched.ts`.
107
+ */
108
+ readonly modelsConfig?: string;
109
+ /**
110
+ * Which warble component dispatched dispatches, forwarded
111
+ * as `--component <agentId>` to `warble-agent-sdk chat` (see
112
+ * `buildAgentSdkChatArgs`). Defaults to `"answer_query"` when unset — the
113
+ * original default, unblocking later work that dispatches a
114
+ * `connect_source`/`build_context` component via dispatched instead. Named
115
+ * `agentId` to match `InProcessOptions.agentId` (intent routing).
116
+ */
117
+ readonly agentId?: string;
118
+ /**
119
+ * Live-event layer: dispatched only emits `run.start`/`answer`/
120
+ * `run.finish`/`error` — it shells `warble-agent-sdk chat` as a single-shot
121
+ * subprocess and reads only its final stdout text, so there is no live
122
+ * step/tool/artifact visibility into the dispatcher's own internals from
123
+ * this harness (a documented gap, not a wiring bug — see `runDispatchedDefault`'s
124
+ * doc comment).
125
+ */
126
+ readonly onEvent?: (event: AgentEvent) => void;
127
+ /**
128
+ * Setup-flow bypass: an explicit path to an already-compiled IR file to
129
+ * dispatch directly, skipping `compileProfile` entirely. Mirrors
130
+ * `InProcessOptions.bundle`'s test-only override pattern, but this one is a
131
+ * real (non-test) production path — the setup wizard's `connect_source`
132
+ * dispatch runs against a fixed, warble-committed IR
133
+ * (`profiles/genbi-setup/ir.golden.json`), not a profile compiled from the
134
+ * bound wren project (there is no bound project yet during setup). When
135
+ * unset, behavior is unchanged: `runDispatchedDefault` compiles `profileSource`
136
+ * itself. See `harness/setup/runner.ts`'s `DispatchedSetupRunner`.
137
+ */
138
+ readonly irPath?: string;
139
+ /**
140
+ * Overrides `spawnChat`'s default `CHAT_TIMEOUT_MS` guard (10 minutes) for
141
+ * this dispatch. A cold Ask turn against a freshly-onboarded project can
142
+ * legitimately take longer than a warm one — the default is a hang guard,
143
+ * not a target latency, so callers with a slower expected cold start (e.g.
144
+ * the BFF's Ask route right after setup) can raise it instead of the turn
145
+ * being killed and reported as a timeout. See `spawnChat` in `dispatched.ts`.
146
+ */
147
+ readonly chatTimeoutMs?: number;
148
+ /**
149
+ * Forwarded verbatim as `warble-agent-sdk chat --max-turns <n>`, capping the
150
+ * dispatcher's agent loop. Omitted when unset, so warble's own default
151
+ * (currently 40) applies. Raised by the setup wizard's `DispatchedSetupRunner`
152
+ * because `build_context` (agentically generating an MDL) needs far more than
153
+ * 40 tool-call turns and otherwise dies with `error_max_turns`.
154
+ */
155
+ readonly maxTurns?: number;
156
+ /**
157
+ * Session resume: an SDK session id captured from an earlier `chat` invocation (either its
158
+ * `DispatchedResult.sessionId` on success, or the session id a failed/`error_max_turns` turn still
159
+ * carried — see `spawnChat`'s `DispatchedSessionError`). When set, forwarded as
160
+ * `warble-agent-sdk chat --resume <id>` so the dispatcher resumes the SAME agent-sdk
161
+ * conversation instead of starting a fresh one — the agent keeps whatever it already read/
162
+ * listed/fetched this session, rather than re-orienting from scratch. Ignored (no `--resume`
163
+ * flag) when unset, which is the pre-existing behavior.
164
+ */
165
+ readonly resumeSessionId?: string;
166
+ /** Cancels the owned dispatcher process without falling back to another vendor. */
167
+ readonly signal?: AbortSignal;
168
+ }
169
+ export interface DispatchedResult {
170
+ /** The dispatcher's final answer text for the turn (its `${turn.finalText}` stdout line). */
171
+ readonly finalText: string;
172
+ /**
173
+ * The SDK session id this turn ran under (the dispatcher's `{t:"session",id}` NDJSON line),
174
+ * forwarded so a caller can resume it on a later turn via `DispatchedOptions.resumeSessionId`.
175
+ * `undefined` when the dispatcher's output never carried a session line at all (e.g. an older
176
+ * warble build without the `session` event); `null` when the dispatcher emitted the line but
177
+ * the SDK itself never produced a session id to report.
178
+ */
179
+ readonly sessionId?: string | null;
180
+ }
181
+ export type DispatchedExecutor = (options: DispatchedOptions) => Promise<DispatchedResult>;
182
+ /** Codex subscription Ask runs through warble-codex-local, never the Claude dispatched dispatcher. */
183
+ export interface CodexAskOptions {
184
+ readonly authChoice: Extract<AuthChoice, {
185
+ mode: "subscription";
186
+ }> & {
187
+ readonly provider: "codex";
188
+ };
189
+ readonly profileSource: string;
190
+ readonly userProject: string;
191
+ readonly question: string;
192
+ readonly deployment?: Deployment;
193
+ readonly warbleBin?: string;
194
+ readonly workDir?: string;
195
+ /** Test/integration override for an already-compiled native IR. */
196
+ readonly irPath?: string;
197
+ readonly agentId?: string;
198
+ readonly onEvent?: (event: AgentEvent) => void;
199
+ readonly codexModels?: CodexManifestModels | (() => CodexManifestModels);
200
+ readonly codexHome?: string;
201
+ readonly codexLocalBin?: string;
202
+ readonly codexLocalCli?: ResolvedCli;
203
+ readonly codexBin?: string;
204
+ readonly mcpServer?: ResolvedCli;
205
+ readonly timeoutMs?: number;
206
+ /** Test-only outer subprocess watchdog override; production is dispatcher timeout plus cleanup grace. */
207
+ readonly processTimeoutMs?: number;
208
+ readonly signal?: AbortSignal;
209
+ }
210
+ export interface CodexAskResult {
211
+ readonly finalText: string;
212
+ }
213
+ export type CodexAskExecutor = (options: CodexAskOptions) => Promise<CodexAskResult>;
214
+ /**
215
+ * Options for the `route()` seam. `inProcess`/`dispatched` are injectable executors —
216
+ * omit them to use the real default back-ends (`runInProcessDefault`/
217
+ * `runDispatchedDefault`), or inject stubs for testing/future gating (compliance
218
+ * checks, hybrid dispatch) without touching either mode's internals.
219
+ */
220
+ export interface RouteOptions {
221
+ readonly authChoice: AuthChoice;
222
+ readonly profileSource: string;
223
+ readonly userProject: string;
224
+ readonly question: string;
225
+ /**
226
+ * Explicit deployment-context declaration for the compliance gate
227
+ * (see `enforceCompliance`). Defaults to `"personal"` — the harness has
228
+ * no way to detect multi-tenancy on its own, so a `"hosted"` (multi-
229
+ * tenant / shared / always-on-server) deployment must be declared by the
230
+ * caller.
231
+ */
232
+ readonly deployment?: Deployment;
233
+ readonly inProcess?: InProcessExecutor;
234
+ readonly dispatched?: DispatchedExecutor;
235
+ readonly codexAsk?: CodexAskExecutor;
236
+ /** Passed through to the default in-process executor; see `InProcessOptions.model`. */
237
+ readonly model?: string;
238
+ readonly warbleBin?: string;
239
+ readonly agentSdkBin?: string;
240
+ readonly workDir?: string;
241
+ readonly outDir?: string;
242
+ readonly bundle?: Bundle;
243
+ readonly mcpServers?: McpServerConfigMap;
244
+ /** In-process only (hybrid mode); see `InProcessOptions.tierBinding`. `route()` rejects this alongside a `subscription` authChoice. */
245
+ readonly tierBinding?: Readonly<Record<string, AdapterSpec>>;
246
+ /** Dispatched only (hybrid mode); see `DispatchedOptions.modelsConfig`. `route()` rejects this alongside a non-`subscription` authChoice. */
247
+ readonly modelsConfig?: string;
248
+ /** Live-event layer: forwarded to whichever mode executor runs. See `InProcessOptions.onEvent`/`DispatchedOptions.onEvent`. */
249
+ readonly onEvent?: (event: AgentEvent) => void;
250
+ /**
251
+ * Intent routing (in-process) / component dispatch (dispatched): which
252
+ * compiled agent (in-process) or dispatched warble component (dispatched) to run
253
+ * `question` against. Forwarded to whichever mode executor runs; see
254
+ * `InProcessOptions.agentId` / `DispatchedOptions.agentId`. Defaults to
255
+ * `"answer_query"` in both modes when unset.
256
+ */
257
+ readonly agentId?: string;
258
+ /** Subscription subprocess timeout: Claude chat or Codex Ask. Ignored by in-process. */
259
+ readonly chatTimeoutMs?: number;
260
+ /** Codex subscription Ask-only configuration. */
261
+ readonly codexModels?: CodexManifestModels | (() => CodexManifestModels);
262
+ readonly codexHome?: string;
263
+ readonly codexLocalBin?: string;
264
+ readonly codexLocalCli?: ResolvedCli;
265
+ readonly codexBin?: string;
266
+ readonly codexMcpServer?: ResolvedCli;
267
+ readonly signal?: AbortSignal;
268
+ }
269
+ /**
270
+ * `route()`'s result, tagged with which back-end actually served the
271
+ * question. `warnings` surfaces the compliance gate's `enforceCompliance`
272
+ * warnings (e.g. `SUBSCRIPTION_TOS_WARNING`) to programmatic callers of
273
+ * `route()` — previously these were computed and discarded inside `route()`,
274
+ * visible only to the CLI (which runs its own, separate `enforceCompliance`
275
+ * call and prints to stderr). Empty for any non-`subscription` `authChoice`.
276
+ */
277
+ export type RouteResult = ({
278
+ readonly backend: "agent";
279
+ readonly warnings: readonly string[];
280
+ } & RunAgentResult) | ({
281
+ readonly backend: "agent-sdk";
282
+ readonly warnings: readonly string[];
283
+ } & DispatchedResult) | ({
284
+ readonly backend: "codex-local";
285
+ readonly warnings: readonly string[];
286
+ } & CodexAskResult);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /** Thrown by `runAgent` when `agentId` doesn't name any agent in the bundle. */
2
+ export declare class UnknownAgentError extends Error {
3
+ constructor(agentId: string);
4
+ }
@@ -0,0 +1,7 @@
1
+ /** Thrown by `runAgent` when `agentId` doesn't name any agent in the bundle. */
2
+ export class UnknownAgentError extends Error {
3
+ constructor(agentId) {
4
+ super(`no agent with id "${agentId}" in this bundle`);
5
+ this.name = "UnknownAgentError";
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ import type { Agent, Guardrail } from "../bundle/schema.js";
2
+ /**
3
+ * Finds a `locked` guardrail whose `enforcement` is `gated_check`, if the
4
+ * agent declares one. This is what gives `gated_check` real teeth: enforcement lives
5
+ * here as a code-level check on the rendered envelope's `verified` field —
6
+ * not as prose in a prompt the model may or may not follow. The golden
7
+ * `answer_query` agent's `deterministic_gate` guardrail
8
+ * (`{enforcement: "gated_check", locked: true}`) is exactly what this
9
+ * matches on.
10
+ */
11
+ export declare function findLockedGatedCheck(agent: Agent): Guardrail | undefined;
@@ -0,0 +1,13 @@
1
+ const GATED_CHECK_ENFORCEMENT = "gated_check";
2
+ /**
3
+ * Finds a `locked` guardrail whose `enforcement` is `gated_check`, if the
4
+ * agent declares one. This is what gives `gated_check` real teeth: enforcement lives
5
+ * here as a code-level check on the rendered envelope's `verified` field —
6
+ * not as prose in a prompt the model may or may not follow. The golden
7
+ * `answer_query` agent's `deterministic_gate` guardrail
8
+ * (`{enforcement: "gated_check", locked: true}`) is exactly what this
9
+ * matches on.
10
+ */
11
+ export function findLockedGatedCheck(agent) {
12
+ return Object.values(agent.guardrails).find((guardrail) => guardrail.enforcement === GATED_CHECK_ENFORCEMENT && guardrail.locked === true);
13
+ }
@@ -0,0 +1,5 @@
1
+ export { runAgent } from "./run.js";
2
+ export type { RunAgentContext } from "./run.js";
3
+ export { UnknownAgentError } from "./errors.js";
4
+ export { findLockedGatedCheck } from "./gate.js";
5
+ export type { AnswerResult, RefusalResult, RunAgentResult } from "./types.js";
@@ -0,0 +1,3 @@
1
+ export { runAgent } from "./run.js";
2
+ export { UnknownAgentError } from "./errors.js";
3
+ export { findLockedGatedCheck } from "./gate.js";
@@ -0,0 +1,60 @@
1
+ import type { Bundle } from "../bundle/schema.js";
2
+ import type { CapabilityRegistry } from "../capability/registry.js";
3
+ import type { AgentEvent } from "../events/index.js";
4
+ import { type ExecutionEnv } from "../exec/index.js";
5
+ import type { GuardEvaluator } from "../loop/index.js";
6
+ import type { ProviderRegistry, TierBinding } from "../providers/index.js";
7
+ import type { McpServerConfigMap, NativeToolRegistry } from "../tools/index.js";
8
+ import type { RunAgentResult } from "./types.js";
9
+ export interface RunAgentContext {
10
+ readonly binding: TierBinding;
11
+ readonly registry: ProviderRegistry;
12
+ readonly capabilityRegistry: CapabilityRegistry;
13
+ /** Runtime-injected MCP server connection config, keyed by server id. Defaults to `{}`. */
14
+ readonly mcpServers?: McpServerConfigMap;
15
+ readonly nativeTools?: NativeToolRegistry;
16
+ /**
17
+ * Backend native tools (e.g. `write_artifact`) execute side effects
18
+ * through. Defaults to `createLocalExecutionEnv()` — the only backend
19
+ * this milestone ships (no microVM/delegated/egress-proxy backend).
20
+ */
21
+ readonly executionEnv?: ExecutionEnv;
22
+ /**
23
+ * Egress allowlist merged into the guardrail-derived `EnforcementPolicy`
24
+ * before it reaches `executionEnv`. The bundle format has no egress
25
+ * guardrail in v1, so this is the only way to grant `fetch` access.
26
+ * Defaults to no hosts allowed.
27
+ */
28
+ readonly allowedHosts?: readonly string[];
29
+ /** Guard-eval seam threaded through to `executeAgent`. */
30
+ readonly evaluateGuard?: GuardEvaluator;
31
+ /** Overrides the render envelope stage's default tier selection (see `renderEnvelope`). */
32
+ readonly renderTier?: string;
33
+ /**
34
+ * Live-event layer: optional sink for the run's `AgentEvent`s
35
+ * (`run.start`/`step.*`/`tool.*`/`artifact`/`answer`/`refusal`/
36
+ * `run.finish`/`error`). `runAgent` is the sole owner of `runId`/`seq`
37
+ * bookkeeping for the run (via `createAgentEventEmitter`) — this callback
38
+ * always receives fully-stamped events, exactly the contract's literal
39
+ * `(e: AgentEvent) => void` shape. Omit to opt out of live events
40
+ * entirely; the FLOOR `StepTrace` (`AnswerResult.trace`/
41
+ * `RefusalResult.trace`) is always accumulated regardless.
42
+ */
43
+ readonly onEvent?: (event: AgentEvent) => void;
44
+ }
45
+ /**
46
+ * The full `answer_query` walking-skeleton entry point: capability gate
47
+ * (whole-bundle) -> resolve `agentId`'s tools -> run its dataflow
48
+ * steps with repair-fold -> synthesize the two-stage render
49
+ * envelope -> enforce any locked `gated_check` guardrail -> an
50
+ * explicit `AnswerResult | RefusalResult`.
51
+ *
52
+ * MCP clients opened while resolving `agentId`'s tools are always torn down
53
+ * (`withResolvedTools`'s `finally`), whether the run succeeds, the loop
54
+ * throws (e.g. `RepairExhaustedError`), or the render stage throws (e.g. a
55
+ * malformed model response failing `output_schema` validation) — in every
56
+ * failure case the error propagates out of `runAgent` rather than being
57
+ * swallowed into a refusal; only a *rendered but unverified* envelope
58
+ * becomes a `RefusalResult`.
59
+ */
60
+ export declare function runAgent(bundle: Bundle, agentId: string, userInput: string, ctx: RunAgentContext): Promise<RunAgentResult>;