@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,862 @@
1
+ import type { ArtifactKind, BlastRadius, ComponentScore, ContextFileNode, EvalRun, KnowledgeStatus, PublishScope, RuntimeSettings, SemanticMeasure, SemanticModel, SemanticRelationship, SessionEvent, SetupMode, SetupStep, SetupStatusEvent } from "./wire-types.js";
2
+ import type { EnrichmentApprovalAttestation, EnrichmentBinding, EnrichmentMode, EnrichmentOperation, EnrichmentOperationState, EnrichmentRunStatus, ProjectIdentity, UnversionedEnrichmentBinding } from "./enrichment.js";
3
+ import type { NativeRuntimeBinding } from "./native-dispatch-registry.js";
4
+ export declare function newId(prefix: string): string;
5
+ export type SessionStatus = "active" | "awaiting_clarify" | "streaming" | "awaiting_decision";
6
+ export type TurnResultKind = "clarify" | "answer" | "refusal" | "error";
7
+ export type SetupContextLifecyclePrefix = "none" | "discovery" | "validate" | "build";
8
+ /**
9
+ * Opaque, non-secret evidence retained only while a context step is being
10
+ * corrected. `identityFingerprint` binds it to the canonical project and its
11
+ * selected/profile source declaration; no project path or credentials are
12
+ * persisted here.
13
+ */
14
+ export interface SetupContextLifecycleEvidence {
15
+ readonly sessionId: string;
16
+ readonly identityFingerprint: string;
17
+ readonly completed: SetupContextLifecyclePrefix;
18
+ }
19
+ /** Deliberately separate from Ask's `sessions` table and wire contract. */
20
+ export type NativeSessionStatus = "creating" | "running" | "detached" | "exited" | "stopped" | "interrupted" | "failed" | "stale";
21
+ export type NativeSessionPurpose = "analysis" | "setup" | "context_enrichment";
22
+ export type NativeSessionVendor = "claude" | "codex";
23
+ export type NativeSessionScopeKind = "bootstrap" | "bound_project";
24
+ export type NativeSetupRecoveryPhase = "connect" | "context";
25
+ export type NativeSetupRecoveryState = "working" | "needs_input" | "needs_decision" | "retryable_failure" | "reported_complete";
26
+ export type NativeSetupRecoveryCode = "in_progress" | "user_action_required" | "continue_or_stop" | "retryable" | "completion_reported";
27
+ export interface NativeSessionRow {
28
+ readonly id: string;
29
+ readonly purpose: NativeSessionPurpose;
30
+ readonly vendor: NativeSessionVendor;
31
+ readonly agent: string;
32
+ readonly scopeKind: NativeSessionScopeKind;
33
+ readonly scopeId: string;
34
+ readonly projectIdentity: string | null;
35
+ readonly bindingGeneration: number | null;
36
+ readonly projectRevision: string | null;
37
+ readonly dispatchProfile: string | null;
38
+ readonly dispatchTarget: string | null;
39
+ readonly runtimeGeneration: number | null;
40
+ readonly status: NativeSessionStatus;
41
+ readonly createdAt: string;
42
+ readonly updatedAt: string;
43
+ readonly startedAt: string | null;
44
+ readonly endedAt: string | null;
45
+ readonly exitCode: number | null;
46
+ readonly failure: string | null;
47
+ }
48
+ /**
49
+ * Opaque, sealed provider continuation material. The handle is never joined
50
+ * into a browser-facing native-session row.
51
+ */
52
+ export interface NativeSessionResumeHandle {
53
+ readonly sessionId: string;
54
+ readonly provider: NativeSessionVendor;
55
+ readonly sealedHandle: string;
56
+ readonly consumedAt: string | null;
57
+ }
58
+ /** Durable idempotency fence for a provider continuation attempt. */
59
+ export interface NativeSessionResumeAction {
60
+ readonly sourceSessionId: string;
61
+ readonly idempotencyKey: string;
62
+ readonly scopeFingerprint: string;
63
+ readonly resumedSessionId: string;
64
+ }
65
+ /**
66
+ * Session-scoped, typed answer material retained for native follow-up tools.
67
+ * `envelopeJson` is limited by the native-artifact contract to table and
68
+ * definition blocks; it deliberately never contains terminal bytes or a
69
+ * driver/subagent transcript.
70
+ */
71
+ export interface NativeStructuredAnswerRow {
72
+ readonly id: string;
73
+ readonly nativeSessionId: string;
74
+ /** Caller retry authority only; canonical answer provenance is host-minted. */
75
+ readonly idempotencyKey: string;
76
+ readonly envelopeJson: string;
77
+ readonly digest: string;
78
+ readonly createdAt: string;
79
+ }
80
+ /** Retained answers are intentionally bounded without a global cleanup job. */
81
+ export declare const MAX_NATIVE_STRUCTURED_ANSWERS_PER_SESSION = 32;
82
+ /** Durable, redacted projection of the producer-owned Setup recovery report. */
83
+ export interface NativeSetupRecoveryRow {
84
+ readonly sessionId: string;
85
+ readonly phase: NativeSetupRecoveryPhase;
86
+ readonly state: NativeSetupRecoveryState;
87
+ readonly code: NativeSetupRecoveryCode;
88
+ readonly sequence: number;
89
+ readonly decision: "continue_or_stop" | null;
90
+ /** Host-owned completion result; never inferred from a report or PTY exit. */
91
+ readonly completionValidated: boolean;
92
+ /** Monotonic compare-and-swap token for browser recovery actions. */
93
+ readonly version: number;
94
+ readonly createdAt: string;
95
+ readonly updatedAt: string;
96
+ }
97
+ export interface SessionRow {
98
+ readonly id: string;
99
+ readonly title: string;
100
+ readonly createdAt: string;
101
+ readonly updatedAt: string;
102
+ readonly status: SessionStatus;
103
+ readonly pendingQuestion: string | null;
104
+ /** JSON-serialized `PendingDecisionPayload`, set alongside `status: "awaiting_decision"` — mirrors `pendingQuestion`'s `awaiting_clarify` pairing. */
105
+ readonly pendingDecision: string | null;
106
+ }
107
+ /**
108
+ * JSON-serialized shape of `SessionRow.pendingDecision`, one variant per
109
+ * decision `kind` this BFF knows how to resume (see `wire-types.ts`'s
110
+ * `SetupDecision.kind`, which is the UI-facing side of the same checkpoint —
111
+ * this is the BFF-internal "how to resume" half). `POST /api/setup/decision`
112
+ * reads this back out to know which action to drive for a given `choiceId`.
113
+ */
114
+ export type PendingDecisionPayload = {
115
+ readonly kind: "max_turns_continue";
116
+ readonly stepKey: "context";
117
+ /**
118
+ * Plan A session resume: the SDK session id the failed turn ran under (captured from a
119
+ * `DispatchedSessionError`, `harness/route/dispatched.ts`), if the runner reported one. When present,
120
+ * `POST /api/setup/decision`'s "continue" branch resumes this SAME agent-sdk conversation
121
+ * instead of recomposing a disk-state prompt (`composeSetupPrompt`'s `resumeFromDisk`).
122
+ * `undefined` for decisions recorded before this field existed, or when the runner never
123
+ * reported a session id at all; `null` when the runner reported the line but the SDK itself
124
+ * produced no session id to resume.
125
+ */
126
+ readonly sessionId?: string | null;
127
+ /** Server-only origin identity; both fields are required to resume. */
128
+ readonly sessionProvider?: string;
129
+ readonly sessionRunner?: string;
130
+ /** Preserves an adopted context turn's cwd across the decision. */
131
+ readonly workspaceRoot?: string;
132
+ } | {
133
+ /** One explicit recovery from a terminal context turn with no successful schema discovery. */
134
+ readonly kind: "schema_discovery_retry";
135
+ readonly stepKey: "context";
136
+ /** Captured from the completed Mode-B turn when available, so retry can continue the same conversation. */
137
+ readonly sessionId?: string | null;
138
+ /** Server-only origin identity; both fields are required to resume. */
139
+ readonly sessionProvider?: string;
140
+ readonly sessionRunner?: string;
141
+ /** Carries an adopted project's dirname across the decision, when this was not the bootstrap workspace root. */
142
+ readonly workspaceRoot?: string;
143
+ } | {
144
+ readonly kind: "name_conflict";
145
+ readonly projectName: string;
146
+ readonly sourceType: string;
147
+ /** The chosen connection shape, so "clean" rebuilds the same one the user picked. */
148
+ readonly variant?: string;
149
+ } | {
150
+ readonly kind: "build_context";
151
+ /** Absolute path to the adopted project (see `SetupAdoptRequest.projectPath`) — reconstructed into `{workspaceRoot: dirname, projectName: basename}` for `composeSetupPrompt`/the resumed turn's `TurnRow.workspaceRoot`. */
152
+ readonly projectPath: string;
153
+ readonly sourceType: string;
154
+ };
155
+ export interface StoredEvent {
156
+ readonly id: string;
157
+ readonly sessionId: string;
158
+ readonly seq: number;
159
+ readonly kind: SessionEvent["kind"];
160
+ readonly payload: SessionEvent;
161
+ readonly createdAt: string;
162
+ readonly turnId: string | null;
163
+ }
164
+ export interface TurnRow {
165
+ readonly id: string;
166
+ readonly sessionId: string;
167
+ readonly question: string;
168
+ readonly composedInput: string | null;
169
+ readonly backend: string | null;
170
+ readonly resultKind: TurnResultKind | null;
171
+ readonly answerSummary: string | null;
172
+ readonly traceJson: string | null;
173
+ readonly errorMessage: string | null;
174
+ readonly createdAt: string;
175
+ /** The intent router's chosen agent id for this turn (see `classifyIntent`). NULL for rows created before intent routing existed. */
176
+ readonly agentId: string | null;
177
+ /**
178
+ * Marks this turn as a step of the agentic setup/connect flow (`"connect"`
179
+ * | `"connect_resume"`, see `server/compose.ts`'s `SetupStepKey`) rather
180
+ * than a normal Ask turn. NULL for every non-setup turn (the overwhelming
181
+ * majority). `executeTurn` (`server/turn.ts`) branches on this being
182
+ * non-null to dispatch via `SetupStepRunner` instead of `deps.route(...)`.
183
+ */
184
+ readonly setupStepKey: string | null;
185
+ /**
186
+ * Plan A session resume: an SDK session id this turn should resume (forwarded to
187
+ * `SetupStepRunOptions.resumeSessionId`, `harness/setup/runner.ts`) instead of dispatching a fresh
188
+ * agent-sdk conversation. Set only on a turn created by `POST /api/setup/decision`'s
189
+ * "continue" branch when the prior failed turn reported a resumable session id. NULL for every
190
+ * other turn, and for turns created before this column existed.
191
+ */
192
+ readonly resumeSessionId: string | null;
193
+ /** Subscription provider that created `resumeSessionId`; required before an explicit retry may reuse it. */
194
+ readonly resumeSessionProvider: string | null;
195
+ /** Canonical selected setup-runner identity that created `resumeSessionId` (for example `subscription:claude`). */
196
+ readonly resumeRunner: string | null;
197
+ /**
198
+ * A bounded setup workflow recovery already consumed by this turn. NULL for
199
+ * ordinary setup/Ask turns. "lifecycle" marks a retained-proof corrective
200
+ * turn; "schema_discovery" additionally prevents that bounded retry from
201
+ * offering the same retry or a chained max-turn continuation again.
202
+ */
203
+ readonly contextRecovery: string | null;
204
+ /**
205
+ * Per-turn override for `TurnDeps.workspaceRoot`, used ONLY by the adopt
206
+ * flow's `build_context` decision resolution (`POST /api/setup/decision`,
207
+ * `server/app.ts`): an adopted project can live anywhere on disk, not just
208
+ * under the BFF's configured bootstrap `workspaceRoot`, so its context-step
209
+ * turn carries its own root (`path.dirname(<adopted project path>)`) rather
210
+ * than relying on the process-wide config. `executeSetupTurn`
211
+ * (`server/turn.ts`) resolves `turn.workspaceRoot ?? deps.workspaceRoot` so
212
+ * every pre-existing create-flow turn (this column NULL) is unaffected.
213
+ */
214
+ readonly workspaceRoot: string | null;
215
+ }
216
+ export interface ArtifactRow {
217
+ readonly id: string;
218
+ readonly sessionId: string;
219
+ readonly name: string;
220
+ readonly kind: ArtifactKind;
221
+ readonly location: string;
222
+ readonly verified: boolean;
223
+ readonly createdAt: string;
224
+ /**
225
+ * Set when the user explicitly saved this artifact to the Artifacts
226
+ * page (`Store.saveArtifact`), else `null`. Auto-created artifacts (Mode
227
+ * A/B) always start with this unset — only `listArtifacts()` filters on
228
+ * it; `getArtifact()` stays unfiltered so the content read-back route
229
+ * and the save endpoint itself can still reach an unsaved row.
230
+ */
231
+ readonly savedAt: string | null;
232
+ /** Native-session provenance is additive; legacy Ask artifacts leave these null. */
233
+ readonly nativeSessionId: string | null;
234
+ readonly projectIdentity: string | null;
235
+ readonly bindingGeneration: number | null;
236
+ readonly projectRevision: string | null;
237
+ readonly nativeVendor: NativeSessionVendor | null;
238
+ readonly nativeAgent: string | null;
239
+ readonly contentDigest: string | null;
240
+ /** Opaque retry key, never returned on an artifact DTO. */
241
+ readonly idempotencyKey: string | null;
242
+ /** Source provenance for a reference-backed native save; legacy/payload saves leave these null. */
243
+ readonly sourceAnswerId: string | null;
244
+ }
245
+ export interface PublicationRow {
246
+ readonly artifactId: string;
247
+ readonly link: string;
248
+ readonly scope: PublishScope;
249
+ readonly createdAt: string;
250
+ }
251
+ export interface EvalRunWithScores extends EvalRun {
252
+ readonly componentScores: readonly ComponentScore[];
253
+ }
254
+ export interface PriorTurn {
255
+ readonly question: string;
256
+ readonly answerSummary: string | undefined;
257
+ }
258
+ export interface EnrichmentRunRow {
259
+ readonly id: string;
260
+ readonly mode: EnrichmentMode;
261
+ readonly projectPath: string;
262
+ readonly projectIdentity: string;
263
+ readonly projectRevision: string;
264
+ readonly proposalId: string;
265
+ readonly proposalHash: string;
266
+ readonly status: EnrichmentRunStatus;
267
+ readonly createdAt: string;
268
+ readonly updatedAt: string;
269
+ readonly validationDigest: string | null;
270
+ readonly buildDigest: string | null;
271
+ readonly errorMessage: string | null;
272
+ readonly bindingGeneration: number;
273
+ /** Monotonic optimistic-concurrency token; never use `updatedAt` as authority. */
274
+ readonly version: number;
275
+ }
276
+ export interface EnrichmentOperationRow extends EnrichmentOperation {
277
+ readonly decision: "accept" | "edit" | "skip" | null;
278
+ readonly completed: boolean;
279
+ readonly state: import("./enrichment.js").EnrichmentOperationState;
280
+ readonly attempt: number;
281
+ readonly leaseToken: string | null;
282
+ readonly leaseExpiresAt: string | null;
283
+ readonly idempotencyKey: string;
284
+ }
285
+ export interface EnrichmentEventRow {
286
+ readonly id: string;
287
+ readonly runId: string;
288
+ readonly kind: string;
289
+ readonly message: string;
290
+ readonly createdAt: string;
291
+ }
292
+ /** A single optimistic, binding-fenced metadata mutation for a run. */
293
+ export interface EnrichmentMetadataTransition {
294
+ readonly runId: string;
295
+ readonly expectedVersion: number;
296
+ readonly binding: EnrichmentBinding;
297
+ readonly operation?: {
298
+ readonly id: string;
299
+ readonly expectedState: EnrichmentOperationState;
300
+ readonly expectedDecision?: "accept" | "edit" | "skip" | null;
301
+ readonly decision?: "accept" | "edit" | "skip";
302
+ readonly nextState: EnrichmentOperationState;
303
+ };
304
+ readonly status?: EnrichmentRunStatus;
305
+ readonly errorMessage?: string | null;
306
+ /** A callback-minted record; browser input can never supply this object. */
307
+ readonly attestation?: EnrichmentApprovalAttestation;
308
+ readonly event?: {
309
+ readonly kind: string;
310
+ readonly message: string;
311
+ };
312
+ /** Additional events share this exact operation/run/version transaction. */
313
+ readonly additionalEvents?: readonly {
314
+ readonly kind: string;
315
+ readonly message: string;
316
+ }[];
317
+ }
318
+ /** The authoritative transaction for every apply/reconcile/lease mutation. */
319
+ export interface EnrichmentExecutionTransition {
320
+ readonly runId: string;
321
+ readonly expectedVersion: number;
322
+ readonly binding: EnrichmentBinding;
323
+ readonly operationId: string;
324
+ readonly expectedStates: readonly EnrichmentOperationState[];
325
+ readonly expectedAttempt?: number;
326
+ readonly expectedLeaseToken?: string | null;
327
+ readonly nextState: EnrichmentOperationState;
328
+ readonly nextAttempt?: number;
329
+ readonly leaseToken?: string | null;
330
+ readonly leaseExpiresAt?: string | null;
331
+ readonly completed?: boolean;
332
+ readonly status: EnrichmentRunStatus;
333
+ readonly validationDigest?: string | null;
334
+ readonly buildDigest?: string | null;
335
+ readonly errorMessage?: string | null;
336
+ readonly event: {
337
+ readonly kind: string;
338
+ readonly message: string;
339
+ };
340
+ }
341
+ /**
342
+ * Replaces a browser-edited draft only after the host has canonicalized it.
343
+ * This keeps the operation, proposal hash, run version, and audit event in
344
+ * one binding-fenced transaction.
345
+ */
346
+ export interface EnrichmentEditTransition {
347
+ readonly runId: string;
348
+ readonly expectedVersion: number;
349
+ readonly binding: EnrichmentBinding;
350
+ readonly operationId: string;
351
+ readonly operation: EnrichmentOperation;
352
+ readonly proposalId: string;
353
+ readonly proposalHash: string;
354
+ readonly event: {
355
+ readonly kind: string;
356
+ readonly message: string;
357
+ };
358
+ }
359
+ export interface StoreOptions {
360
+ /**
361
+ * Test-only fault seam for the atomic context-success transaction. It runs
362
+ * after the named write while the SQLite transaction is still open, so a
363
+ * thrown error verifies that every preceding write is rolled back too.
364
+ */
365
+ readonly onContextSuccessWrite?: (phase: "after_steps" | "after_event" | "after_turn") => void;
366
+ /** Test-only fault seam for enrichment's run/op/event CAS transaction. */
367
+ readonly onEnrichmentTransitionWrite?: (phase: "after_operation" | "after_run" | "after_event") => void;
368
+ /** Test-only fault seam for atomic enrichment-run creation. */
369
+ readonly onEnrichmentCreationWrite?: (phase: "after_run" | "after_operations" | "after_event") => void;
370
+ /** Test-only clock so lease-expiry behavior is deterministic. */
371
+ readonly now?: () => Date;
372
+ }
373
+ export interface ContextSetupSuccessPersistence {
374
+ readonly sessionId: string;
375
+ readonly turnId: string;
376
+ readonly steps: SetupStep[];
377
+ readonly statusEvent: SetupStatusEvent;
378
+ readonly backend: string | null;
379
+ readonly answerSummary: string | null;
380
+ readonly traceJson: string | null;
381
+ readonly errorMessage: string | null;
382
+ }
383
+ export declare class Store {
384
+ private readonly db;
385
+ private readonly onContextSuccessWrite;
386
+ private readonly onEnrichmentTransitionWrite;
387
+ private readonly onEnrichmentCreationWrite;
388
+ private readonly now;
389
+ constructor(path: string, options?: StoreOptions);
390
+ /**
391
+ * A setup turn is executed only by the owning BFF process. If that process
392
+ * exits, a NULL result cannot still represent running work after restart.
393
+ * Convert only setup turns (never ordinary Ask turns) to a bounded, public
394
+ * recovery error. The old trace is deliberately discarded: it may predate
395
+ * the setup-boundary redaction rules and must not be replayed to the UI.
396
+ */
397
+ private reconcileOrphanedSetupTurns;
398
+ /**
399
+ * An enrichment draft is executed only by the owning BFF process. If that
400
+ * process exits mid-draft, a 'drafting' row cannot still represent running
401
+ * work after restart -- convert it to a terminal, classifiable state
402
+ * (mirrors `reconcileOrphanedSetupTurns` above) so the UI never shows a
403
+ * run stuck at "in progress" forever after a crash or redeploy.
404
+ */
405
+ private reconcileOrphanedEnrichmentRuns;
406
+ /** A PTY belongs to this BFF process, so it cannot survive a restart. */
407
+ private reconcileOrphanedNativeSessions;
408
+ /**
409
+ * Additive, idempotent migrations for columns added after a DB file may
410
+ * already exist on disk. `CREATE TABLE IF NOT EXISTS` above only defines
411
+ * the schema for a BRAND NEW file — an existing sqlite file's `turns`
412
+ * table predates `agent_id` and needs it added explicitly. Guarded by a
413
+ * `PRAGMA table_info` check so re-running this on an already-migrated (or
414
+ * brand-new, already-current) file is a no-op rather than an error.
415
+ */
416
+ private migrateSchema;
417
+ private addColumnIfMissing;
418
+ close(): void;
419
+ createSession(title: string): SessionRow;
420
+ createNativeSession(params: {
421
+ id: string;
422
+ purpose: NativeSessionPurpose;
423
+ vendor: NativeSessionVendor;
424
+ agent: string;
425
+ scopeKind: NativeSessionScopeKind;
426
+ scopeId: string;
427
+ projectIdentity?: string;
428
+ bindingGeneration?: number;
429
+ projectRevision?: string;
430
+ dispatchProfile?: string;
431
+ dispatchTarget?: string;
432
+ runtimeGeneration?: number;
433
+ }): NativeSessionRow;
434
+ /** Stores a sealed provider handle only; callers must never pass plaintext. */
435
+ saveNativeSessionResumeHandle(sessionId: string, provider: NativeSessionVendor, sealedHandle: string): void;
436
+ getNativeSessionResumeHandle(sessionId: string): NativeSessionResumeHandle | undefined;
437
+ /** Browser-safe availability bit; the opaque sealed value never leaves Store. */
438
+ hasAvailableNativeSessionResume(sessionId: string, provider: NativeSessionVendor): boolean;
439
+ getNativeSessionResumeAction(sourceSessionId: string, idempotencyKey: string): NativeSessionResumeAction | undefined;
440
+ invalidateNativeSessionResume(sessionId: string): void;
441
+ /**
442
+ * Atomically consumes a source conversation authority and creates its child
443
+ * process row. A duplicate action returns its original child, while another
444
+ * click can never fork the same provider conversation.
445
+ */
446
+ reserveNativeSessionResume(params: {
447
+ readonly sourceSessionId: string;
448
+ readonly idempotencyKey: string;
449
+ readonly scopeFingerprint: string;
450
+ readonly child: {
451
+ readonly id: string;
452
+ readonly purpose: NativeSessionPurpose;
453
+ readonly vendor: NativeSessionVendor;
454
+ readonly agent: string;
455
+ readonly scopeKind: NativeSessionScopeKind;
456
+ readonly scopeId: string;
457
+ readonly projectIdentity?: string;
458
+ readonly bindingGeneration?: number;
459
+ readonly projectRevision?: string;
460
+ readonly dispatchProfile?: string;
461
+ readonly dispatchTarget?: string;
462
+ readonly runtimeGeneration?: number;
463
+ };
464
+ readonly sealedHandle: string;
465
+ }): {
466
+ readonly row: NativeSessionRow;
467
+ readonly created: boolean;
468
+ } | undefined;
469
+ getNativeSession(id: string): NativeSessionRow | undefined;
470
+ createNativeStructuredAnswer(params: {
471
+ readonly id: string;
472
+ readonly nativeSessionId: string;
473
+ readonly idempotencyKey: string;
474
+ readonly envelopeJson: string;
475
+ readonly digest: string;
476
+ }): {
477
+ readonly row: NativeStructuredAnswerRow;
478
+ readonly created: boolean;
479
+ };
480
+ getNativeStructuredAnswer(id: string): NativeStructuredAnswerRow | undefined;
481
+ getNativeStructuredAnswerByIdempotency(nativeSessionId: string, idempotencyKey: string): NativeStructuredAnswerRow | undefined;
482
+ getLatestNativeStructuredAnswer(nativeSessionId: string): NativeStructuredAnswerRow | undefined;
483
+ listNativeSessions(): NativeSessionRow[];
484
+ transitionNativeSession(id: string, status: NativeSessionStatus, patch?: {
485
+ exitCode?: number | null;
486
+ failure?: string | null;
487
+ started?: boolean;
488
+ ended?: boolean;
489
+ }): NativeSessionRow | undefined;
490
+ getNativeSetupRecovery(sessionId: string): NativeSetupRecoveryRow | undefined;
491
+ /**
492
+ * Accepts one already-validated closed v1 report when its producer sequence
493
+ * moves forward. An identical producer replay at the current sequence is an
494
+ * idempotent acknowledgement; any other replay or stale report fails closed.
495
+ */
496
+ recordNativeSetupRecovery(input: {
497
+ readonly sessionId: string;
498
+ readonly phase: NativeSetupRecoveryPhase;
499
+ readonly state: NativeSetupRecoveryState;
500
+ readonly code: NativeSetupRecoveryCode;
501
+ readonly sequence: number;
502
+ readonly decision: "continue_or_stop" | null;
503
+ readonly completionValidated: boolean;
504
+ }): NativeSetupRecoveryRow | undefined;
505
+ /** Creates a restart-safe, browser-held action secret without persisting it raw. */
506
+ issueNativeSetupRecoveryAction(sessionId: string, capability: string): void;
507
+ /**
508
+ * Claims one recovery action atomically after checking its salted verifier
509
+ * and the browser's exact recovery version. A missing report has version 0
510
+ * so a BFF-restart interruption can still be retried honestly.
511
+ */
512
+ claimNativeSetupRecoveryAction(sessionId: string, capability: string, expectedVersion: number): boolean;
513
+ /** Releases a failed launch claim so the same browser-held secret can retry. */
514
+ releaseNativeSetupRecoveryAction(sessionId: string): void;
515
+ /** Atomically make a native row stopped and consume any durable recovery verifier. */
516
+ stopNativeSessionAndRevokeRecoveryAction(id: string, patch?: {
517
+ failure?: string | null;
518
+ }): NativeSessionRow | undefined;
519
+ listSessions(): SessionRow[];
520
+ getSession(id: string): SessionRow | undefined;
521
+ updateSessionStatus(id: string, status: SessionStatus, pendingQuestion: string | null): void;
522
+ /** Mirrors `updateSessionStatus`, but for the `pendingDecision` column (`status: "awaiting_decision"` checkpoints) — kept as a separate method/column so a pending clarify and a pending decision can never silently clobber each other. */
523
+ updateSessionDecision(id: string, status: SessionStatus, pendingDecision: string | null): void;
524
+ touchSession(id: string): void;
525
+ /**
526
+ * Deletes a session row along with everything scoped to it — turns, events, artifacts, and any
527
+ * publications for those artifacts — so no dangling rows survive the session itself. No FK
528
+ * cascade is configured on this schema (see SCHEMA_SQL above), so each child table needs its
529
+ * own explicit DELETE. Used by `resetSetup()` to remove an orphaned tracked setup session
530
+ * rather than merely forgetting its id.
531
+ */
532
+ deleteSession(id: string): void;
533
+ nextSeq(sessionId: string): number;
534
+ insertEvent(params: {
535
+ sessionId: string;
536
+ kind: SessionEvent["kind"];
537
+ payload: SessionEvent;
538
+ turnId: string | null;
539
+ }): StoredEvent;
540
+ listEventsForSession(sessionId: string): StoredEvent[];
541
+ listEventsForTurn(turnId: string): StoredEvent[];
542
+ createTurn(params: {
543
+ id: string;
544
+ sessionId: string;
545
+ question: string;
546
+ composedInput: string | null;
547
+ agentId?: string | null;
548
+ /** Pre-seed the work log with the turn's decision entries (Route, and Clarify for a clarify turn), so they persist and replay. */
549
+ traceJson?: string | null;
550
+ /** Marks this as a setup-wizard turn (see `TurnRow.setupStepKey`). Undefined/null for a normal Ask turn. */
551
+ setupStepKey?: string | null;
552
+ /** Plan A session resume anchor for this turn (see `TurnRow.resumeSessionId`). Undefined/null when the turn should dispatch fresh. */
553
+ resumeSessionId?: string | null;
554
+ /** Provider/runner identity that created `resumeSessionId`; retained only for an explicit same-backend retry. */
555
+ resumeSessionProvider?: string | null;
556
+ resumeRunner?: string | null;
557
+ /** Bounded context workflow recovery marker. */
558
+ contextRecovery?: "lifecycle" | "schema_discovery" | null;
559
+ /** Per-turn workspace root override for the adopt flow (see `TurnRow.workspaceRoot`). Undefined/null for every non-adopt turn — falls back to `TurnDeps.workspaceRoot`. */
560
+ workspaceRoot?: string | null;
561
+ }): TurnRow;
562
+ /**
563
+ * Atomically coalesces duplicate setup dispatches for one session/step.
564
+ * A second tab can attach to the same pending turn, but cannot create a
565
+ * competing mutation of the project.
566
+ */
567
+ createOrGetActiveSetupTurn(params: {
568
+ id: string;
569
+ sessionId: string;
570
+ question: string;
571
+ composedInput: string | null;
572
+ agentId?: string | null;
573
+ traceJson?: string | null;
574
+ setupStepKey: string;
575
+ resumeSessionId?: string | null;
576
+ resumeSessionProvider?: string | null;
577
+ resumeRunner?: string | null;
578
+ contextRecovery?: "lifecycle" | "schema_discovery" | null;
579
+ workspaceRoot?: string | null;
580
+ }): {
581
+ readonly turn: TurnRow;
582
+ readonly created: boolean;
583
+ };
584
+ getTurn(id: string): TurnRow | undefined;
585
+ resolveTurn(id: string, patch: {
586
+ backend: string | null;
587
+ resultKind: TurnResultKind;
588
+ answerSummary: string | null;
589
+ traceJson: string | null;
590
+ errorMessage: string | null;
591
+ }): void;
592
+ /**
593
+ * Retains the dispatcher session anchor after a completed setup turn's
594
+ * host-contract recovery ultimately fails. A later explicit retry can use
595
+ * this durable anchor; it is never sent over the REST/SSE wire.
596
+ */
597
+ setTurnResumeAnchor(id: string, anchor: {
598
+ readonly sessionId: string;
599
+ readonly provider: string;
600
+ readonly runner: string;
601
+ }): void;
602
+ markTurnClarify(id: string): void;
603
+ /** Most recent turn (any result kind) for a session — drives the Ask page's current work log. */
604
+ getLatestTurn(sessionId: string): TurnRow | undefined;
605
+ /** Resolved turns newest-first, used to recover an earlier safe setup pause after a later retry fails. */
606
+ listTurnsForSession(sessionId: string): TurnRow[];
607
+ /** D3 context composition source: last `limit` resolved (answer/refusal) turns, chronological ascending. */
608
+ listRecentResolvedTurns(sessionId: string, limit: number): PriorTurn[];
609
+ createArtifact(params: {
610
+ sessionId: string;
611
+ name: string;
612
+ kind: ArtifactKind;
613
+ location: string;
614
+ verified: boolean;
615
+ }): ArtifactRow;
616
+ /**
617
+ * Inserts a host-persisted native artifact as already Saved. The unique
618
+ * native-session/idempotency pair is the retry authority; callers receive
619
+ * the original row when another request won the race.
620
+ */
621
+ createNativeArtifact(params: {
622
+ id: string;
623
+ sessionId: string;
624
+ nativeSessionId: string;
625
+ name: string;
626
+ location: string;
627
+ projectIdentity: string;
628
+ bindingGeneration: number;
629
+ projectRevision: string;
630
+ vendor: NativeSessionVendor;
631
+ agent: string;
632
+ digest: string;
633
+ idempotencyKey: string;
634
+ sourceAnswerId?: string;
635
+ }): {
636
+ readonly row: ArtifactRow;
637
+ readonly created: boolean;
638
+ };
639
+ getNativeArtifactByIdempotency(nativeSessionId: string, idempotencyKey: string): ArtifactRow | undefined;
640
+ getArtifact(id: string): ArtifactRow | undefined;
641
+ /** Only artifacts the user explicitly saved — see `saveArtifact`. Auto-created (in-process/B) rows stay off the Artifacts page until saved. `getArtifact` stays unfiltered for direct-id lookups (content route, save route). */
642
+ listArtifacts(): ArtifactRow[];
643
+ /**
644
+ * Marks an artifact saved (visible via `listArtifacts()`). Idempotent: a
645
+ * repeat call on an already-saved artifact is a no-op that returns the
646
+ * existing row unchanged — it never overwrites the original `saved_at`.
647
+ * Returns `undefined` if the artifact doesn't exist.
648
+ */
649
+ saveArtifact(artifactId: string): ArtifactRow | undefined;
650
+ /**
651
+ * The mirror of `saveArtifact`: clears `saved_at` back to
652
+ * `null`, removing the artifact from `listArtifacts()` while leaving its
653
+ * row and envelope file untouched (Unpin is fully reversible — see
654
+ * `unsaveArtifactForSession`). Idempotent: a repeat call on an
655
+ * already-unsaved artifact is a no-op that returns the existing row
656
+ * unchanged. Returns `undefined` if the artifact doesn't exist.
657
+ */
658
+ unsaveArtifact(artifactId: string): ArtifactRow | undefined;
659
+ publishArtifact(artifactId: string, link: string, scope: PublishScope): PublicationRow;
660
+ getPublication(artifactId: string): PublicationRow | undefined;
661
+ listEvalRuns(): EvalRun[];
662
+ getEvalRun(id: string): EvalRunWithScores | undefined;
663
+ getConfigJson<T>(key: string): T | undefined;
664
+ setConfigJson(key: string, value: unknown): void;
665
+ /** Removes a config key entirely (so its getter falls back to `undefined`). Used by `resetSetup`. */
666
+ deleteConfig(key: string): void;
667
+ getRuntimeSettings(): RuntimeSettings;
668
+ /**
669
+ * Persists a user-validated runtime choice. The separate marker matters:
670
+ * seeded display defaults are not authority to replace environment/CLI boot
671
+ * routing. Only a successful PUT (or an explicit programmatic equivalent)
672
+ * may supersede those boot flags.
673
+ */
674
+ setRuntimeSettings(settings: RuntimeSettings, explicit?: boolean): void;
675
+ getRuntimeGeneration(): number;
676
+ getNativeRuntimeBinding(): NativeRuntimeBinding;
677
+ /** Atomically persist a new runtime fence and stop every incompatible live row. */
678
+ setRuntimeSettingsAndRevokeIncompatibleNativeSessions(settings: RuntimeSettings, explicit?: boolean): readonly string[];
679
+ /** Whether runtime.settings came from an explicit validated save, not seed data. */
680
+ hasExplicitRuntimeSettings(): boolean;
681
+ getSetupSteps(): SetupStep[];
682
+ setSetupSteps(steps: SetupStep[]): void;
683
+ /**
684
+ * Commits the context foundation's accepted lifecycle as one SQLite unit.
685
+ * The caller has already completed parser/artifact/compile gates; this
686
+ * method makes its visible success state reload-safe by never exposing a
687
+ * partial step/event/turn/session transition.
688
+ */
689
+ completeContextSetupSuccess(params: ContextSetupSuccessPersistence): void;
690
+ /**
691
+ * Which of the wizard's two entry paths the user picked (`SetupMode`,
692
+ * `POST /api/setup/mode`) — `undefined` before they've picked either,
693
+ * which the frontend reads as "show the create-vs-adopt choice screen"
694
+ * (see `GET /api/setup/mode`). Not seeded (no `SEED_*` constant): a fresh
695
+ * DB simply has no value here until the user chooses.
696
+ */
697
+ getSetupMode(): SetupMode | undefined;
698
+ setSetupMode(mode: SetupMode): void;
699
+ getVerifyGatePassed(): boolean;
700
+ setVerifyGatePassed(value: boolean): void;
701
+ /**
702
+ * The single dedicated session the setup wizard's connect/resume turns run
703
+ * in (get-or-create — see `POST /api/setup/connect`). Kept separate from
704
+ * the Ask page's session list so setup dispatches never appear there.
705
+ *
706
+ * Single-bootstrap-per-process assumption: this is a process-wide singleton
707
+ * (one row in config), not scoped per browser tab/user — fine for the
708
+ * one-BFF-per-project bootstrap flow, but would need to become session- or
709
+ * request-scoped if this BFF ever serves multiple concurrent setup wizards.
710
+ */
711
+ getSetupSessionId(): string | undefined;
712
+ setSetupSessionId(id: string): void;
713
+ /**
714
+ * The connect form's structured values (project name + source type),
715
+ * persisted at `POST /api/setup/connect` time so the `connect_resume` turn
716
+ * doesn't require the frontend to resend them, and so `executeSetupTurn`
717
+ * (`server/turn.ts`) has the `{root, name}` context `parseSetupTerminal`
718
+ * needs without having to parse it back out of `composedInput` prose.
719
+ */
720
+ getSetupConnectForm(): {
721
+ projectName: string;
722
+ sourceType: string;
723
+ variant?: string;
724
+ } | undefined;
725
+ setSetupConnectForm(form: {
726
+ projectName: string;
727
+ sourceType: string;
728
+ variant?: string;
729
+ }): void;
730
+ getSetupContextLifecycleEvidence(sessionId: string, identityFingerprint: string): SetupContextLifecycleEvidence | undefined;
731
+ mergeSetupContextLifecycleEvidence(input: SetupContextLifecycleEvidence): SetupContextLifecycleEvidence;
732
+ clearSetupContextLifecycleEvidence(): void;
733
+ getContextModels(): SemanticModel[];
734
+ getContextRelationships(): SemanticRelationship[];
735
+ getContextMeasures(): SemanticMeasure[];
736
+ getContextKnowledge(): KnowledgeStatus;
737
+ getContextFiles(): ContextFileNode[];
738
+ getBlastRadius(entityKey: string): BlastRadius | undefined;
739
+ getVerifiedPairs(): {
740
+ question: string;
741
+ refs: string[];
742
+ }[];
743
+ /**
744
+ * Persists a run BEFORE any model turn is dispatched, in a running
745
+ * ('drafting') state, with the bound revision and generation locked for
746
+ * the lifetime of the draft. This is the enrichment analogue of
747
+ * `postTurn` creating a turn row (`resultKind: null`) ahead of `route()`:
748
+ * the row -- and therefore `GET /api/context/enrichment`'s visibility of
749
+ * it -- exists for the entire ~minutes-long dispatch, not only after it
750
+ * resolves. Every exit path from that dispatch must resolve this row to a
751
+ * terminal status via `finalizeEnrichmentDraft` or `failEnrichmentRun`
752
+ * (or, after a process restart, `reconcileOrphanedEnrichmentRuns`).
753
+ */
754
+ createDraftingEnrichmentRun(params: {
755
+ readonly id: string;
756
+ readonly mode: EnrichmentMode;
757
+ readonly binding: EnrichmentBinding;
758
+ }): EnrichmentRunRow;
759
+ /**
760
+ * Transitions a 'drafting' run to 'awaiting_decision' once the draft
761
+ * callback has resolved AND been independently canonicalized by the host.
762
+ * Fenced on `status = 'drafting'` plus the CAS version, so a run that a
763
+ * restart already reconciled to 'failed' (or that was somehow already
764
+ * finalized) cannot be resurrected by a late completion.
765
+ */
766
+ finalizeEnrichmentDraft(params: {
767
+ readonly runId: string;
768
+ readonly expectedVersion: number;
769
+ readonly proposalId: string;
770
+ readonly proposalHash: string;
771
+ readonly operations: readonly EnrichmentOperation[];
772
+ readonly validationDigest?: string;
773
+ readonly buildDigest?: string;
774
+ }): boolean;
775
+ /**
776
+ * Resolves a 'drafting' run to the terminal 'failed' status -- the
777
+ * enrichment analogue of `resolveTurn(..., { resultKind: "error" })` in
778
+ * every catch clause of `executeTurn`. Called on a thrown draft/contract
779
+ * error, a stale post-draft binding, or (via
780
+ * `reconcileOrphanedEnrichmentRuns`) a BFF restart. Fenced on
781
+ * `status = 'drafting'` so it can never clobber a run that already
782
+ * finalized.
783
+ */
784
+ failEnrichmentRun(params: {
785
+ readonly runId: string;
786
+ readonly expectedVersion: number;
787
+ readonly message: string;
788
+ }): boolean;
789
+ createEnrichmentRun(params: {
790
+ readonly id: string;
791
+ readonly mode: EnrichmentMode;
792
+ readonly binding: EnrichmentBinding;
793
+ readonly proposalId: string;
794
+ readonly proposalHash: string;
795
+ readonly operations: readonly EnrichmentOperation[];
796
+ readonly validationDigest?: string;
797
+ readonly buildDigest?: string;
798
+ }): EnrichmentRunRow;
799
+ /**
800
+ * Every bind, including the same canonical directory, creates a new
801
+ * generation. `bindProject` (the foundation path) never has a built
802
+ * project's revision to offer — binding must succeed for an unbuilt
803
+ * project — so it activates identity alone; the stored placeholder
804
+ * revision is never read as a trusted value. Every consumer re-resolves
805
+ * the revision fresh from disk before treating a binding as current (see
806
+ * `currentEnrichmentBinding` in app.ts), so a placeholder here cannot
807
+ * leak into a fencing decision.
808
+ */
809
+ activateEnrichmentBinding(binding: UnversionedEnrichmentBinding | ProjectIdentity): EnrichmentBinding;
810
+ /**
811
+ * Advances the project binding and stops every live project-scoped native
812
+ * session in one transaction. The caller must immediately discard the
813
+ * corresponding in-memory PTY and MCP capabilities using the returned ids.
814
+ * Bootstrap Setup sessions deliberately remain outside this project fence.
815
+ */
816
+ activateEnrichmentBindingAndRevokeBoundNativeSessions(binding: UnversionedEnrichmentBinding | ProjectIdentity): {
817
+ readonly binding: EnrichmentBinding;
818
+ readonly revokedNativeSessionIds: readonly string[];
819
+ };
820
+ getEnrichmentBinding(): EnrichmentBinding | undefined;
821
+ getEnrichmentRun(id: string): EnrichmentRunRow | undefined;
822
+ getLatestEnrichmentRun(): EnrichmentRunRow | undefined;
823
+ listEnrichmentOperations(runId: string): EnrichmentOperationRow[];
824
+ getEnrichmentOperation(runId: string, operationId: string): EnrichmentOperationRow | undefined;
825
+ appendEnrichmentEvent(runId: string, kind: string, message: string): void;
826
+ listEnrichmentEvents(runId: string): EnrichmentEventRow[];
827
+ /**
828
+ * The authority for non-lease enrichment mutations. It checks both the
829
+ * caller's snapshot and the DB version before making *any* write; operation,
830
+ * attestation, run metadata and event then commit or roll back together.
831
+ */
832
+ transitionEnrichmentMetadata(params: EnrichmentMetadataTransition): boolean;
833
+ transitionEnrichmentEdit(params: EnrichmentEditTransition): boolean;
834
+ transitionEnrichmentExecution(params: EnrichmentExecutionTransition): boolean;
835
+ hasExactEnrichmentAttestation(runId: string, operationId: string): boolean;
836
+ private seedIfEmpty;
837
+ /**
838
+ * Restores the setup wizard to its first-run state (for the "Reset setup"
839
+ * action): steps back to step 1, runtime settings back to defaults, verify
840
+ * gate off, and the connect form + setup session cleared. Non-destructive —
841
+ * this only touches wizard STATE; it never deletes scaffolded project files
842
+ * on disk (the caller unbinds the bootstrap project separately). Leaves the
843
+ * seeded eval/context fixtures alone (they aren't part of the wizard).
844
+ *
845
+ * Clearing `setup.sessionId` used to leave the tracked
846
+ * setup session's ROW behind. `GET /api/sessions` filters the list by id
847
+ * against `getSetupSessionId()`, so once the id was forgotten that row
848
+ * matched nothing and leaked back into the Ask sidebar as an orphaned
849
+ * "Setup: <name>" session. Delete the row (and its turns/events/artifacts)
850
+ * BEFORE forgetting the id, so no orphan is ever left behind.
851
+ */
852
+ resetSetup(): readonly string[];
853
+ private seedEvalRuns;
854
+ /**
855
+ * Fixture data: two `BlastRadius` seeds (`customers`, `products`) and
856
+ * three verified Q-SQL pairs whose `refs` deliberately intersect one seed's
857
+ * downstream set and miss the other's, so `server/impact.ts`'s live join
858
+ * (see that file's doc comment) is actually exercised both ways — not
859
+ * vacuously "always non-empty".
860
+ */
861
+ private seedContext;
862
+ }