@interf/compiler 0.9.1 → 0.9.3

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 (250) hide show
  1. package/README.md +9 -9
  2. package/agent-skills/interf-actions/SKILL.md +3 -0
  3. package/agent-skills/interf-actions/references/cli.md +13 -13
  4. package/{builtin-workflows/interf → builtin-methods/interf-default}/README.md +2 -2
  5. package/builtin-methods/interf-default/improve/SKILL.md +18 -0
  6. package/{builtin-workflows/interf/workflow.json → builtin-methods/interf-default/method.json} +4 -4
  7. package/{builtin-workflows/interf/workflow.schema.json → builtin-methods/interf-default/method.schema.json} +2 -2
  8. package/dist/cli/commands/check-draft.d.ts +6 -6
  9. package/dist/cli/commands/check-draft.js +5 -5
  10. package/dist/cli/commands/compile-controller.d.ts +7 -7
  11. package/dist/cli/commands/compile-controller.js +35 -38
  12. package/dist/cli/commands/compile.d.ts +3 -3
  13. package/dist/cli/commands/compile.js +23 -21
  14. package/dist/cli/commands/compiled-flow.d.ts +11 -11
  15. package/dist/cli/commands/compiled-flow.js +33 -30
  16. package/dist/cli/commands/create-method-wizard.d.ts +76 -0
  17. package/dist/cli/commands/{create-workflow-wizard.js → create-method-wizard.js} +153 -163
  18. package/dist/cli/commands/create.d.ts +3 -3
  19. package/dist/cli/commands/create.js +44 -45
  20. package/dist/cli/commands/default.js +1 -1
  21. package/dist/cli/commands/executor-flow.d.ts +6 -6
  22. package/dist/cli/commands/executor-flow.js +1 -1
  23. package/dist/cli/commands/init.d.ts +2 -2
  24. package/dist/cli/commands/init.js +139 -118
  25. package/dist/cli/commands/list.js +11 -10
  26. package/dist/cli/commands/preparation-selection.d.ts +3 -3
  27. package/dist/cli/commands/source-config-wizard.d.ts +9 -9
  28. package/dist/cli/commands/source-config-wizard.js +43 -43
  29. package/dist/cli/commands/status.js +36 -9
  30. package/dist/cli/commands/test-flow.d.ts +15 -15
  31. package/dist/cli/commands/test-flow.js +29 -219
  32. package/dist/cli/commands/test.d.ts +2 -2
  33. package/dist/cli/commands/test.js +50 -51
  34. package/dist/cli/commands/verify.js +7 -7
  35. package/dist/cli/commands/web.js +41 -28
  36. package/dist/compiler-ui/404.html +1 -0
  37. package/dist/compiler-ui/__next.__PAGE__.txt +10 -0
  38. package/dist/compiler-ui/__next._full.txt +20 -0
  39. package/dist/compiler-ui/__next._head.txt +5 -0
  40. package/dist/compiler-ui/__next._index.txt +5 -0
  41. package/dist/compiler-ui/__next._tree.txt +5 -0
  42. package/dist/compiler-ui/_next/static/chunks/06yhdspx~ca5-.js +5 -0
  43. package/{apps/compiler-ui/.next/static/chunks/13g~4mamjft.c.css → dist/compiler-ui/_next/static/chunks/0c9mu7yldxyyg.css} +1 -1
  44. package/{apps/compiler-ui/.next/static/chunks/0fgt_8knmicoz.js → dist/compiler-ui/_next/static/chunks/15mks7ry_cupt.js} +15 -21
  45. package/{apps/compiler-ui/.next/static/chunks/turbopack-109rtik40vwh5.js → dist/compiler-ui/_next/static/chunks/turbopack-0.uq1k8c0j4s..js} +1 -1
  46. package/dist/compiler-ui/_not-found/__next._full.txt +15 -0
  47. package/dist/compiler-ui/_not-found/__next._head.txt +5 -0
  48. package/dist/compiler-ui/_not-found/__next._index.txt +5 -0
  49. package/dist/compiler-ui/_not-found/__next._not-found.__PAGE__.txt +5 -0
  50. package/dist/compiler-ui/_not-found/__next._not-found.txt +5 -0
  51. package/dist/compiler-ui/_not-found/__next._tree.txt +2 -0
  52. package/dist/compiler-ui/_not-found.html +1 -0
  53. package/dist/compiler-ui/_not-found.txt +15 -0
  54. package/{apps/compiler-ui/.next/server/app → dist/compiler-ui}/index.html +1 -1
  55. package/dist/compiler-ui/index.txt +20 -0
  56. package/dist/index.d.ts +8 -6
  57. package/dist/index.js +5 -3
  58. package/dist/packages/agents/index.d.ts +1 -1
  59. package/dist/packages/agents/lib/args.d.ts +2 -2
  60. package/dist/packages/agents/lib/compiled-bootstrap.js +7 -6
  61. package/dist/packages/agents/lib/execution-profile.d.ts +5 -5
  62. package/dist/packages/agents/lib/execution-profile.js +7 -6
  63. package/dist/packages/agents/lib/executors.d.ts +13 -13
  64. package/dist/packages/agents/lib/preflight.d.ts +1 -0
  65. package/dist/packages/agents/lib/preflight.js +32 -9
  66. package/dist/packages/agents/lib/shells.d.ts +25 -24
  67. package/dist/packages/agents/lib/shells.js +161 -154
  68. package/dist/packages/agents/lib/types.d.ts +2 -2
  69. package/dist/packages/compiler/artifact-counts.d.ts +1 -0
  70. package/dist/packages/compiler/artifact-counts.js +30 -0
  71. package/dist/packages/compiler/compiled-paths.d.ts +4 -7
  72. package/dist/packages/compiler/compiled-paths.js +9 -15
  73. package/dist/packages/compiler/compiled-pipeline.d.ts +11 -12
  74. package/dist/packages/compiler/compiled-pipeline.js +22 -22
  75. package/dist/packages/compiler/compiled-schema.d.ts +20 -20
  76. package/dist/packages/compiler/compiled-schema.js +29 -29
  77. package/dist/packages/compiler/compiled-stage-plan.d.ts +4 -4
  78. package/dist/packages/compiler/compiled-stage-plan.js +8 -8
  79. package/dist/packages/compiler/compiled-stage-runner.d.ts +5 -5
  80. package/dist/packages/compiler/compiled-stage-runner.js +7 -7
  81. package/dist/packages/compiler/compiled-target.d.ts +5 -5
  82. package/dist/packages/compiler/compiled-target.js +5 -5
  83. package/dist/packages/compiler/index.d.ts +3 -3
  84. package/dist/packages/compiler/index.js +2 -2
  85. package/dist/packages/compiler/lib/schema.d.ts +62 -247
  86. package/dist/packages/compiler/lib/schema.js +56 -174
  87. package/dist/packages/compiler/{workflows.d.ts → method-runs.d.ts} +4 -4
  88. package/dist/packages/compiler/{workflows.js → method-runs.js} +4 -3
  89. package/dist/packages/compiler/raw-snapshot.d.ts +0 -7
  90. package/dist/packages/compiler/raw-snapshot.js +0 -1
  91. package/dist/packages/compiler/reset.js +3 -3
  92. package/dist/packages/compiler/runtime-acceptance.js +9 -16
  93. package/dist/packages/compiler/runtime-contracts.js +9 -9
  94. package/dist/packages/compiler/runtime-prompt.js +4 -4
  95. package/dist/packages/compiler/runtime-reconcile.d.ts +2 -2
  96. package/dist/packages/compiler/runtime-reconcile.js +3 -3
  97. package/dist/packages/compiler/runtime-runs.js +9 -9
  98. package/dist/packages/compiler/runtime-types.d.ts +8 -7
  99. package/dist/packages/compiler/state-health.js +26 -35
  100. package/dist/packages/compiler/state-view.js +6 -6
  101. package/dist/packages/compiler/validate-compiled.d.ts +5 -5
  102. package/dist/packages/compiler/validate-compiled.js +56 -64
  103. package/dist/packages/compiler/validate.d.ts +2 -2
  104. package/dist/packages/compiler/validate.js +22 -14
  105. package/dist/packages/contracts/index.d.ts +2 -0
  106. package/dist/packages/contracts/index.js +1 -0
  107. package/dist/packages/contracts/lib/schema.d.ts +205 -0
  108. package/dist/packages/contracts/lib/schema.js +101 -0
  109. package/dist/packages/execution/index.d.ts +2 -2
  110. package/dist/packages/execution/index.js +1 -1
  111. package/dist/packages/execution/lib/schema.d.ts +80 -83
  112. package/dist/packages/execution/lib/schema.js +25 -48
  113. package/dist/packages/local-service/action-values.d.ts +0 -1
  114. package/dist/packages/local-service/action-values.js +0 -1
  115. package/dist/packages/local-service/client.d.ts +4 -4
  116. package/dist/packages/local-service/client.js +4 -4
  117. package/dist/packages/local-service/index.d.ts +3 -3
  118. package/dist/packages/local-service/index.js +2 -2
  119. package/dist/packages/local-service/lib/schema.d.ts +536 -974
  120. package/dist/packages/local-service/lib/schema.js +43 -160
  121. package/dist/packages/local-service/run-observability.d.ts +6 -0
  122. package/dist/packages/local-service/run-observability.js +592 -0
  123. package/dist/packages/local-service/runtime.d.ts +19 -23
  124. package/dist/packages/local-service/runtime.js +302 -880
  125. package/dist/packages/local-service/server.d.ts +1 -0
  126. package/dist/packages/local-service/server.js +25 -20
  127. package/dist/packages/method-authoring/index.d.ts +4 -0
  128. package/dist/packages/method-authoring/index.js +4 -0
  129. package/dist/packages/{workflow-authoring/lib/workflow-edit-utils.d.ts → method-authoring/lib/method-edit-utils.d.ts} +3 -3
  130. package/dist/packages/method-authoring/method-authoring.d.ts +24 -0
  131. package/dist/packages/method-authoring/method-authoring.js +116 -0
  132. package/dist/packages/method-authoring/method-edit-session.d.ts +18 -0
  133. package/dist/packages/method-authoring/method-edit-session.js +125 -0
  134. package/dist/packages/method-authoring/method-improvement.d.ts +23 -0
  135. package/dist/packages/{workflow-authoring/workflow-improvement.js → method-authoring/method-improvement.js} +63 -63
  136. package/dist/packages/{workflow-package/builtin-compiled-workflow.d.ts → method-package/builtin-compiled-method.d.ts} +1 -1
  137. package/dist/packages/{workflow-package/builtin-compiled-workflow.js → method-package/builtin-compiled-method.js} +17 -17
  138. package/dist/packages/{workflow-package → method-package}/context-interface.d.ts +12 -12
  139. package/dist/packages/{workflow-package → method-package}/context-interface.js +19 -19
  140. package/dist/packages/method-package/index.d.ts +11 -0
  141. package/dist/packages/method-package/index.js +11 -0
  142. package/dist/packages/method-package/interf-method-package.d.ts +31 -0
  143. package/dist/packages/{workflow-package/interf-workflow-package.js → method-package/interf-method-package.js} +145 -145
  144. package/dist/packages/{workflow-package → method-package}/lib/package-root.js +1 -1
  145. package/dist/packages/method-package/local-methods.d.ts +64 -0
  146. package/dist/packages/method-package/local-methods.js +466 -0
  147. package/dist/packages/method-package/method-definitions.d.ts +83 -0
  148. package/dist/packages/method-package/method-definitions.js +205 -0
  149. package/dist/packages/{workflow-package/workflow-helpers.d.ts → method-package/method-helpers.d.ts} +10 -10
  150. package/dist/packages/{workflow-package/workflow-helpers.js → method-package/method-helpers.js} +22 -26
  151. package/dist/packages/method-package/method-review-paths.d.ts +10 -0
  152. package/dist/packages/{workflow-package/workflow-review-paths.js → method-package/method-review-paths.js} +4 -4
  153. package/dist/packages/{workflow-package/workflow-stage-runner.d.ts → method-package/method-stage-runner.d.ts} +12 -11
  154. package/dist/packages/{workflow-package/workflow-stage-runner.js → method-package/method-stage-runner.js} +6 -6
  155. package/dist/packages/methods/index.d.ts +2 -0
  156. package/dist/packages/methods/index.js +2 -0
  157. package/dist/packages/methods/method-resolution.d.ts +6 -0
  158. package/dist/packages/methods/method-resolution.js +7 -0
  159. package/dist/packages/project-model/index.d.ts +1 -4
  160. package/dist/packages/project-model/index.js +0 -3
  161. package/dist/packages/project-model/interf-detect.d.ts +1 -5
  162. package/dist/packages/project-model/interf-detect.js +7 -18
  163. package/dist/packages/project-model/interf-scaffold.d.ts +2 -2
  164. package/dist/packages/project-model/interf-scaffold.js +38 -39
  165. package/dist/packages/project-model/interf.d.ts +1 -2
  166. package/dist/packages/project-model/interf.js +1 -2
  167. package/dist/packages/project-model/lib/schema.d.ts +2 -66
  168. package/dist/packages/project-model/lib/schema.js +5 -23
  169. package/dist/packages/project-model/project-paths.d.ts +9 -10
  170. package/dist/packages/project-model/project-paths.js +14 -17
  171. package/dist/packages/project-model/source-config.d.ts +11 -18
  172. package/dist/packages/project-model/source-config.js +42 -60
  173. package/dist/packages/project-model/source-folders.d.ts +4 -4
  174. package/dist/packages/project-model/source-folders.js +10 -10
  175. package/dist/packages/testing/index.d.ts +2 -2
  176. package/dist/packages/testing/index.js +1 -1
  177. package/dist/packages/testing/lib/schema.d.ts +11 -11
  178. package/dist/packages/testing/lib/schema.js +8 -9
  179. package/dist/packages/testing/readiness-check-run.d.ts +67 -0
  180. package/dist/packages/testing/readiness-check-run.js +258 -0
  181. package/dist/packages/testing/test-execution.d.ts +3 -3
  182. package/dist/packages/testing/test-execution.js +5 -5
  183. package/dist/packages/testing/test-paths.js +6 -6
  184. package/dist/packages/testing/test-profile-presets.js +2 -2
  185. package/dist/packages/testing/test-sandbox.js +10 -11
  186. package/dist/packages/testing/test-targets.d.ts +1 -1
  187. package/dist/packages/testing/test-targets.js +8 -7
  188. package/dist/packages/testing/test-types.d.ts +1 -1
  189. package/package.json +16 -33
  190. package/apps/compiler-ui/.next/static/chunks/0ti_66mx7~w2-.js +0 -5
  191. package/builtin-workflows/interf/improve/SKILL.md +0 -18
  192. package/dist/cli/commands/create-workflow-wizard.d.ts +0 -76
  193. package/dist/packages/project-model/compiled-paths.d.ts +0 -1
  194. package/dist/packages/project-model/compiled-paths.js +0 -1
  195. package/dist/packages/project-model/compiled-raw.d.ts +0 -1
  196. package/dist/packages/project-model/compiled-raw.js +0 -1
  197. package/dist/packages/project-model/compiled-reset.d.ts +0 -1
  198. package/dist/packages/project-model/compiled-reset.js +0 -1
  199. package/dist/packages/shared/index.d.ts +0 -7
  200. package/dist/packages/shared/index.js +0 -7
  201. package/dist/packages/shared/util.d.ts +0 -3
  202. package/dist/packages/shared/util.js +0 -3
  203. package/dist/packages/testing/test-matrices.d.ts +0 -90
  204. package/dist/packages/testing/test-matrices.js +0 -96
  205. package/dist/packages/workflow-authoring/index.d.ts +0 -4
  206. package/dist/packages/workflow-authoring/index.js +0 -4
  207. package/dist/packages/workflow-authoring/workflow-authoring.d.ts +0 -24
  208. package/dist/packages/workflow-authoring/workflow-authoring.js +0 -82
  209. package/dist/packages/workflow-authoring/workflow-edit-session.d.ts +0 -18
  210. package/dist/packages/workflow-authoring/workflow-edit-session.js +0 -91
  211. package/dist/packages/workflow-authoring/workflow-improvement.d.ts +0 -23
  212. package/dist/packages/workflow-package/index.d.ts +0 -11
  213. package/dist/packages/workflow-package/index.js +0 -11
  214. package/dist/packages/workflow-package/interf-workflow-package.d.ts +0 -31
  215. package/dist/packages/workflow-package/local-workflows.d.ts +0 -64
  216. package/dist/packages/workflow-package/local-workflows.js +0 -457
  217. package/dist/packages/workflow-package/workflow-definitions.d.ts +0 -82
  218. package/dist/packages/workflow-package/workflow-definitions.js +0 -211
  219. package/dist/packages/workflow-package/workflow-review-paths.d.ts +0 -10
  220. /package/{builtin-workflows/interf → builtin-methods/interf-default}/compile/stages/shape/SKILL.md +0 -0
  221. /package/{builtin-workflows/interf → builtin-methods/interf-default}/compile/stages/structure/SKILL.md +0 -0
  222. /package/{builtin-workflows/interf → builtin-methods/interf-default}/compile/stages/summarize/SKILL.md +0 -0
  223. /package/{builtin-workflows/interf → builtin-methods/interf-default}/use/query/SKILL.md +0 -0
  224. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/03~yq9q893hmn.js +0 -0
  225. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/06z~l3kwb891e.js +0 -0
  226. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/08g7lvje.te.u.js +0 -0
  227. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/08m7vf5asqlsm.js +0 -0
  228. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0_i-3_5l9t2qe.js +0 -0
  229. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0b-ywny_j0g~0.js +0 -0
  230. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0b52v41o1gixx.js +0 -0
  231. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0gpzgsv0w.q~m.js +0 -0
  232. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0ilwfezfvu6~-.js +0 -0
  233. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0n51hrfoufc7g.js +0 -0
  234. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0xxmf45eskdt~.css +0 -0
  235. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0y5z3t-z1c8ks.js.map +0 -0
  236. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/14wtz~vq25~qq.js +0 -0
  237. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/turbopack-10e~t1yzi4svj.js +0 -0
  238. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/turbopack-worker-0sjn--fhq~1cg.js +0 -0
  239. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/media/GeistMono_Variable.p.17jn9btb_52pq.woff2 +0 -0
  240. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/media/Geist_Variable-s.p.0-te~ja_gpvcf.woff2 +0 -0
  241. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/media/worker.102zas1s52_pf.js +0 -0
  242. /package/{apps/compiler-ui/.next/static/XWKL548yXD_UOG4ID9G3J → dist/compiler-ui/_next/static/pIZnDsV3Je6hdC3cOsGdK}/_buildManifest.js +0 -0
  243. /package/{apps/compiler-ui/.next/static/XWKL548yXD_UOG4ID9G3J → dist/compiler-ui/_next/static/pIZnDsV3Je6hdC3cOsGdK}/_clientMiddlewareManifest.js +0 -0
  244. /package/{apps/compiler-ui/.next/static/XWKL548yXD_UOG4ID9G3J → dist/compiler-ui/_next/static/pIZnDsV3Je6hdC3cOsGdK}/_ssgManifest.js +0 -0
  245. /package/dist/packages/compiler/{workflow-primitives.d.ts → method-primitives.d.ts} +0 -0
  246. /package/dist/packages/compiler/{workflow-primitives.js → method-primitives.js} +0 -0
  247. /package/dist/packages/{workflow-authoring/lib/workflow-edit-utils.js → method-authoring/lib/method-edit-utils.js} +0 -0
  248. /package/dist/packages/{workflow-package → method-package}/lib/package-root.d.ts +0 -0
  249. /package/dist/packages/{workflow-package/workflow-stage-policy.d.ts → method-package/method-stage-policy.d.ts} +0 -0
  250. /package/dist/packages/{workflow-package/workflow-stage-policy.js → method-package/method-stage-policy.js} +0 -0
@@ -4,22 +4,24 @@ import { CompileRunSchema, } from "../execution/lib/schema.js";
4
4
  import { createRunEventId, createRunEventTimestamp, } from "../execution/events.js";
5
5
  import { compiledRuntimeRunHistoryPath, compiledRuntimeRoot, testRootForCompiled, } from "../compiler/compiled-paths.js";
6
6
  import { loadState, } from "../compiler/state.js";
7
- import { ReadinessStateSchema, RuntimeRunSchema, } from "../compiler/lib/schema.js";
7
+ import { RuntimeRunSchema, } from "../compiler/lib/schema.js";
8
+ import { ReadinessStateSchema, } from "../contracts/lib/schema.js";
8
9
  import { discoverSourceFiles, } from "../compiler/discovery.js";
9
10
  import { ensurePortableContextScaffold, readInterfConfig, } from "../project-model/interf.js";
10
- import { findSourceDatasetConfig, fingerprintReadinessChecks, listSourceDatasetConfigs, loadSourceFolderConfig, methodIdForSourcePreparationConfig, resolveConfiguredSourceFolderPath, resolveSourceDatasetPath, syncCompiledInterfConfigFromSourceDatasetConfig, upsertSourceDatasetConfig, } from "../project-model/source-config.js";
11
- import { defaultDatasetNameForPath, listSourceFolderChoices, normalizeSourceDatasetPathForConfig, } from "../project-model/source-folders.js";
12
- import { datasetLatestTestStatePath, portableContextPath, } from "../project-model/project-paths.js";
13
- import { getCompiledWorkflow, listCompiledWorkflowChoices, } from "../workflow-package/workflow-definitions.js";
14
- import { resolveWorkflowPackageSourcePath, } from "../workflow-package/local-workflows.js";
11
+ import { findSourcePreparationConfig, fingerprintReadinessChecks, listSourcePreparationConfigs, loadSourceFolderConfig, DEFAULT_METHOD_ID, methodIdForSourcePreparationConfig, resolveConfiguredSourceFolderPath, resolveSourcePreparationPath, syncCompiledInterfConfigFromSourcePreparationConfig, upsertSourcePreparationConfig, } from "../project-model/source-config.js";
12
+ import { defaultPreparationNameForPath, listSourceFolderChoices, normalizeSourcePreparationPathForConfig, } from "../project-model/source-folders.js";
13
+ import { portableContextPath, } from "../project-model/project-paths.js";
14
+ import { getCompiledMethod, listCompiledMethodChoices, } from "../method-package/method-definitions.js";
15
+ import { resolveMethodPackageSourcePath, } from "../method-package/local-methods.js";
15
16
  import { resolveAgent, detectAgents, supportsAutomatedRuns, } from "../agents/lib/detection.js";
16
17
  import { AGENTS, } from "../agents/lib/constants.js";
17
18
  import { loadUserConfig, saveUserConfig, } from "../agents/lib/user-config.js";
18
- import { TestRunComparisonSchema, } from "../testing/lib/schema.js";
19
+ import { readSavedReadinessCheckRun, } from "../testing/readiness-check-run.js";
19
20
  import { createCompiledTestTarget, } from "../testing/test-targets.js";
20
- import { ActionProposalApprovalRequestSchema, ActionProposalCreateRequestSchema, ActionProposalPlanSchema, ActionProposalResourceSchema, CompileRunCreateRequestSchema, CompileRunResourceSchema, DatasetSetupCreateRequestSchema, DatasetResourceSchema, MethodResourceSchema, LocalExecutorStatusSchema, LocalExecutorSelectRequestSchema, LocalServiceHealthSchema, PreparationReadinessStateSchema, LocalRunHandlerResultSchema, LocalJobEventAppendRequestSchema, LocalJobRunCreateRequestSchema, LocalJobRunResourceSchema, SourceFileResourceSchema, WorkspaceFileResourceSchema, PortableContextResourceSchema, PreparationResourceSchema, ReadinessCheckDraftCreateRequestSchema, ReadinessCheckDraftResultSchema, RunObservabilityResourceSchema, TestRunCreateRequestSchema, TestRunResourceSchema, WorkflowAuthoringCreateRequestSchema, WorkflowAuthoringResultSchema, WorkflowPackageResourceSchema, } from "./lib/schema.js";
21
+ import { ActionProposalApprovalRequestSchema, ActionProposalCreateRequestSchema, ActionProposalPlanSchema, ActionProposalResourceSchema, CompileRunCreateRequestSchema, CompileRunResourceSchema, MethodResourceSchema, LocalExecutorStatusSchema, LocalExecutorSelectRequestSchema, LocalServiceHealthSchema, PreparationReadinessStateSchema, LocalRunHandlerResultSchema, LocalJobEventAppendRequestSchema, LocalJobRunCreateRequestSchema, LocalJobRunResourceSchema, SourceFileResourceSchema, WorkspaceFileResourceSchema, PortableContextResourceSchema, PreparationSetupCreateRequestSchema, PreparationResourceSchema, ReadinessCheckDraftCreateRequestSchema, ReadinessCheckDraftResultSchema, TestRunCreateRequestSchema, TestRunResourceSchema, MethodAuthoringCreateRequestSchema, MethodAuthoringResultSchema, } from "./lib/schema.js";
21
22
  import { buildLocalServiceUrl, } from "./routes.js";
22
23
  import { methodAuthoringTaskPrompt, MethodAuthoringActionValuesSchema, PreparationSetupActionValuesSchema, } from "./action-values.js";
24
+ import { compileRunToObservability, jobRunToObservability, testRunToObservability, uniqueArtifacts, } from "./run-observability.js";
23
25
  function createRunId(prefix) {
24
26
  return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
25
27
  }
@@ -39,6 +41,22 @@ function writeJsonFile(filePath, value) {
39
41
  mkdirSync(dirname(filePath), { recursive: true });
40
42
  writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
41
43
  }
44
+ function sanitizeActionProposalPlan(value) {
45
+ if (!value || typeof value !== "object" || Array.isArray(value))
46
+ return value;
47
+ const plan = { ...value };
48
+ for (const key of ["preparation", "method", "title", "summary", "assistant_message", "command_preview"]) {
49
+ const current = plan[key];
50
+ if (current === null || current === undefined) {
51
+ delete plan[key];
52
+ continue;
53
+ }
54
+ if (typeof current === "string" && current.trim().length === 0) {
55
+ delete plan[key];
56
+ }
57
+ }
58
+ return plan;
59
+ }
42
60
  function compileRunsRoot(compiledPath) {
43
61
  return join(compiledRuntimeRoot(compiledPath), "compile-runs");
44
62
  }
@@ -152,110 +170,6 @@ function detectedExecutorOptions(currentAgentName) {
152
170
  current: agent.name === currentAgentName,
153
171
  }));
154
172
  }
155
- function uniqueArtifacts(artifacts) {
156
- const seen = new Set();
157
- const result = [];
158
- for (const artifact of artifacts) {
159
- const key = `${artifact.role}:${artifact.stage_id ?? ""}:${artifact.path}`;
160
- if (seen.has(key))
161
- continue;
162
- seen.add(key);
163
- result.push(artifact);
164
- }
165
- return result;
166
- }
167
- function observableRunStatus(status) {
168
- if (status === "queued" || status === "pending")
169
- return "queued";
170
- if (status === "running")
171
- return "running";
172
- if (status === "failed")
173
- return "failed";
174
- if (status === "cancelled")
175
- return "cancelled";
176
- return "succeeded";
177
- }
178
- function workflowTraceRunStatus(status) {
179
- if (status === "queued" || status === "pending")
180
- return "pending";
181
- if (status === "running")
182
- return "running";
183
- if (status === "failed")
184
- return "failed";
185
- if (status === "cancelled")
186
- return "cancelled";
187
- return "completed";
188
- }
189
- function safeWorkflowNamePart(value) {
190
- return value
191
- .replace(/[^a-zA-Z0-9._/-]+/g, "-")
192
- .replace(/\/+/g, "/")
193
- .replace(/^-+|-+$/g, "")
194
- || "run";
195
- }
196
- function workflowTraceName(runType, name) {
197
- return `workflow//./interf/${runType}//${safeWorkflowNamePart(name)}`;
198
- }
199
- function workflowStepName(runType, label) {
200
- return `step//./interf/${runType}//${safeWorkflowNamePart(label)}`;
201
- }
202
- function structuredWorkflowError(message) {
203
- return {
204
- message: message || "Run failed.",
205
- code: "INTERF_RUN_ERROR",
206
- };
207
- }
208
- function traceEvent(runId, eventType, createdAt, index, eventData, correlationId) {
209
- return {
210
- runId,
211
- eventId: `${runId}:event:${index}`,
212
- eventType,
213
- specVersion: 1,
214
- createdAt: createdAt ?? createRunEventTimestamp(),
215
- ...(correlationId ? { correlationId } : {}),
216
- ...(eventData === undefined ? {} : { eventData }),
217
- };
218
- }
219
- function traceStreamChunk(runId, index, createdAt, text, data) {
220
- return {
221
- streamId: `${runId}:events`,
222
- chunkId: `${runId}:events:${index}`,
223
- index,
224
- createdAt: createdAt ?? createRunEventTimestamp(),
225
- text,
226
- ...(data === undefined ? {} : { data }),
227
- };
228
- }
229
- function buildTraceStreamChunks(runId, events) {
230
- return events.map((event, index) => traceStreamChunk(runId, index, event.timestamp, JSON.stringify({
231
- time: event.timestamp ?? null,
232
- type: event.type,
233
- scope: event.stage_id ?? event.step_id ?? event.type,
234
- message: event.message ?? event.summary ?? event.error ?? event.type,
235
- }), event));
236
- }
237
- function proofChecksForCompileRun(run) {
238
- return run.stages.flatMap((stage) => (stage.latest_proof?.checks ?? []).map((check) => ({
239
- ...check,
240
- detail: check.detail ?? `${stage.stage_label ?? stage.stage_id} / ${stage.status}`,
241
- })));
242
- }
243
- function agentLabelForJob(job) {
244
- return job.agent?.display_name ?? job.agent?.name ?? null;
245
- }
246
- function jobTypeLabelForMetric(type) {
247
- if (type === "readiness-check-draft")
248
- return "Readiness-check draft";
249
- if (type === "method-authoring")
250
- return "Method draft";
251
- if (type === "method-improvement")
252
- return "Method improvement";
253
- if (type === "compile")
254
- return "Compile";
255
- if (type === "test")
256
- return "Readiness check";
257
- return "Local job";
258
- }
259
173
  function stageArtifactRefs(stageId, artifacts) {
260
174
  return (artifacts ?? []).map((path) => ({
261
175
  path,
@@ -314,15 +228,6 @@ function logsForRuntimeRun(run) {
314
228
  contract_path: run.contract_path,
315
229
  };
316
230
  }
317
- function stageTracePayload(stage) {
318
- return {
319
- status: stage.status,
320
- ...(stage.summary ? { summary: stage.summary } : {}),
321
- ...(stage.artifacts.length > 0 ? { artifacts: stage.artifacts } : {}),
322
- ...(stage.logs ? { logs: stage.logs } : {}),
323
- ...(stage.latest_proof ? { proof: stage.latest_proof } : {}),
324
- };
325
- }
326
231
  function timestampKey(value) {
327
232
  const parsed = Date.parse(value ?? "");
328
233
  return Number.isFinite(parsed) ? parsed : 0;
@@ -495,481 +400,6 @@ function applyEventToLocalJob(run, event) {
495
400
  events: [...run.events, event],
496
401
  };
497
402
  }
498
- function compileRunToObservability(run) {
499
- const artifacts = uniqueArtifacts(run.stages.flatMap((stage) => stage.artifacts));
500
- const proof = proofChecksForCompileRun(run);
501
- const executor = run.stages.find((stage) => stage.executor)?.executor ?? null;
502
- const traceStatus = workflowTraceRunStatus(run.status);
503
- const workflowName = workflowTraceName("compile", run.method);
504
- const completedAt = run.finished_at ?? (traceStatus === "completed" || traceStatus === "failed" || traceStatus === "cancelled"
505
- ? run.started_at ?? run.created_at
506
- : undefined);
507
- let eventIndex = 0;
508
- const events = [
509
- traceEvent(run.run_id, "run_created", run.created_at, eventIndex++, {
510
- deploymentId: "local-interf",
511
- workflowName,
512
- input: {
513
- kind: "compile",
514
- preparation: run.preparation,
515
- method: run.method,
516
- source_path: run.source_path,
517
- },
518
- executionContext: {
519
- backend: run.backend,
520
- executor,
521
- },
522
- }),
523
- ];
524
- if (run.started_at) {
525
- events.push(traceEvent(run.run_id, "run_started", run.started_at, eventIndex++, {
526
- workflowName,
527
- input: {
528
- preparation: run.preparation,
529
- method: run.method,
530
- },
531
- executionContext: {
532
- backend: run.backend,
533
- executor,
534
- },
535
- }));
536
- }
537
- for (const stage of run.stages) {
538
- const stepName = workflowStepName("compile", stage.stage_label ?? stage.stage_id);
539
- const stepCreatedAt = stage.started_at ?? run.started_at ?? run.created_at;
540
- events.push(traceEvent(run.run_id, "step_created", stepCreatedAt, eventIndex++, {
541
- stepName,
542
- input: {
543
- stage_id: stage.stage_id,
544
- stage_label: stage.stage_label ?? null,
545
- stage_index: stage.stage_index ?? null,
546
- stage_total: stage.stage_total ?? null,
547
- reads: stage.contract?.reads ?? [],
548
- writes: stage.contract?.writes ?? [],
549
- acceptance: stage.contract?.acceptance ?? null,
550
- executor: stage.executor ?? null,
551
- },
552
- }, stage.stage_id));
553
- if (stage.started_at || stage.status !== "queued") {
554
- events.push(traceEvent(run.run_id, "step_started", stage.started_at ?? stepCreatedAt, eventIndex++, {
555
- attempt: 1,
556
- }, stage.stage_id));
557
- }
558
- if (stage.status === "failed") {
559
- events.push(traceEvent(run.run_id, "step_failed", stage.finished_at ?? run.finished_at ?? stepCreatedAt, eventIndex++, {
560
- error: structuredWorkflowError(stage.failure ?? stage.summary),
561
- output: stageTracePayload(stage),
562
- }, stage.stage_id));
563
- }
564
- else if (stage.status === "succeeded" || stage.status === "skipped") {
565
- events.push(traceEvent(run.run_id, "step_completed", stage.finished_at ?? run.finished_at ?? stepCreatedAt, eventIndex++, {
566
- result: stageTracePayload(stage),
567
- }, stage.stage_id));
568
- }
569
- }
570
- if (traceStatus === "completed") {
571
- events.push(traceEvent(run.run_id, "run_completed", completedAt, eventIndex++, {
572
- output: {
573
- portable_context_path: run.portable_context_path,
574
- artifacts,
575
- proof,
576
- latest_proof: run.latest_proof ?? null,
577
- },
578
- }));
579
- }
580
- else if (traceStatus === "failed") {
581
- events.push(traceEvent(run.run_id, "run_failed", completedAt, eventIndex++, {
582
- error: structuredWorkflowError(run.stages.find((stage) => stage.failure)?.failure ?? run.latest_proof?.summary),
583
- }));
584
- }
585
- else if (traceStatus === "cancelled") {
586
- events.push(traceEvent(run.run_id, "run_cancelled", completedAt, eventIndex++));
587
- }
588
- return RunObservabilityResourceSchema.parse({
589
- kind: "interf-run-observability",
590
- version: 1,
591
- run_id: run.run_id,
592
- run_type: "compile",
593
- title: `Prepare ${run.preparation}`,
594
- status: observableRunStatus(run.status),
595
- preparation: run.preparation,
596
- method: run.method,
597
- source_path: run.source_path,
598
- output_path: run.portable_context_path,
599
- executor,
600
- agent_label: executor?.display_name ?? run.backend,
601
- created_at: run.created_at,
602
- started_at: run.started_at ?? null,
603
- finished_at: run.finished_at ?? null,
604
- metrics: [
605
- { label: "Preparation", value: run.preparation },
606
- { label: "Method", value: run.method },
607
- { label: "Executor", value: executor?.display_name ?? run.backend },
608
- { label: "Stages", value: `${run.stages.filter((stage) => stage.status === "succeeded").length}/${run.stages.length}` },
609
- { label: "Proof", value: `${proof.filter((check) => check.ok).length}/${proof.length}` },
610
- { label: "Artifacts", value: String(artifacts.length) },
611
- ],
612
- artifacts,
613
- proof,
614
- trace: {
615
- run: {
616
- runId: run.run_id,
617
- status: traceStatus,
618
- deploymentId: "local-interf",
619
- workflowName,
620
- specVersion: 1,
621
- executionContext: {
622
- product: "Interf",
623
- run_type: "compile",
624
- preparation: run.preparation,
625
- method: run.method,
626
- backend: run.backend,
627
- executor,
628
- },
629
- input: {
630
- preparation: run.preparation,
631
- method: run.method,
632
- source_path: run.source_path,
633
- },
634
- ...(traceStatus === "completed"
635
- ? {
636
- output: {
637
- portable_context_path: run.portable_context_path,
638
- artifacts,
639
- proof,
640
- },
641
- }
642
- : {}),
643
- ...(traceStatus === "failed" ? { error: structuredWorkflowError(run.stages.find((stage) => stage.failure)?.failure) } : {}),
644
- ...(run.started_at ? { startedAt: run.started_at } : {}),
645
- ...(completedAt ? { completedAt } : {}),
646
- createdAt: run.created_at,
647
- updatedAt: completedAt ?? run.started_at ?? run.created_at,
648
- },
649
- events,
650
- streams: buildTraceStreamChunks(run.run_id, run.events),
651
- },
652
- });
653
- }
654
- function testRunToObservability(run) {
655
- const traceStatus = workflowTraceRunStatus(run.status);
656
- const title = `Check readiness ${run.preparation}`;
657
- const workflowName = workflowTraceName("test", title);
658
- const completedAt = run.finished_at ?? (traceStatus === "completed" || traceStatus === "failed" || traceStatus === "cancelled"
659
- ? run.started_at ?? new Date().toISOString()
660
- : undefined);
661
- const raw = run.comparison?.raw ?? null;
662
- const compiled = run.comparison?.compiled ?? null;
663
- const proofCandidates = [
664
- raw
665
- ? {
666
- id: `${run.run_id}-source-files`,
667
- label: "source files baseline",
668
- ok: raw.ok ?? raw.passed_cases === raw.total_cases,
669
- detail: `${raw.passed_cases}/${raw.total_cases} checks`,
670
- }
671
- : null,
672
- compiled
673
- ? {
674
- id: `${run.run_id}-portable-context`,
675
- label: "portable context",
676
- ok: compiled.ok ?? compiled.passed_cases === compiled.total_cases,
677
- detail: `${compiled.passed_cases}/${compiled.total_cases} checks`,
678
- }
679
- : null,
680
- ];
681
- const proof = proofCandidates.filter((value) => value !== null);
682
- const artifacts = uniqueArtifacts([
683
- ...(raw?.run_path ? [{ path: raw.run_path, role: "test", label: "source files readiness run" }] : []),
684
- ...(compiled?.run_path ? [{ path: compiled.run_path, role: "test", label: "portable context readiness run" }] : []),
685
- ]);
686
- let eventIndex = 0;
687
- const events = [
688
- traceEvent(run.run_id, "run_created", run.started_at, eventIndex++, {
689
- deploymentId: "local-interf",
690
- workflowName,
691
- input: {
692
- kind: "test",
693
- preparation: run.preparation,
694
- mode: run.mode,
695
- },
696
- }),
697
- ];
698
- if (run.started_at) {
699
- events.push(traceEvent(run.run_id, "run_started", run.started_at, eventIndex++, {
700
- workflowName,
701
- input: {
702
- preparation: run.preparation,
703
- mode: run.mode,
704
- },
705
- }));
706
- }
707
- const targetStepCandidates = [
708
- raw
709
- ? {
710
- id: "source-files-baseline",
711
- label: "Source files baseline",
712
- status: raw.ok ?? raw.passed_cases === raw.total_cases ? "succeeded" : "failed",
713
- input: raw.target ?? { type: "source-files", path: run.source_path ?? null },
714
- output: raw,
715
- }
716
- : null,
717
- compiled
718
- ? {
719
- id: "portable-context-check",
720
- label: "Portable context",
721
- status: compiled.ok ?? compiled.passed_cases === compiled.total_cases ? "succeeded" : "failed",
722
- input: compiled.target ?? { type: "portable-context", path: run.portable_context_path ?? null },
723
- output: compiled,
724
- }
725
- : null,
726
- ];
727
- const targetSteps = targetStepCandidates.filter((value) => value !== null);
728
- if (targetSteps.length === 0) {
729
- targetSteps.push({
730
- id: "check-readiness",
731
- label: "Run readiness checks",
732
- status: run.status === "failed" ? "failed" : "succeeded",
733
- input: {
734
- preparation: run.preparation,
735
- mode: run.mode,
736
- },
737
- output: run.comparison ?? null,
738
- });
739
- }
740
- for (const step of targetSteps) {
741
- const timestamp = run.started_at ?? run.finished_at ?? new Date().toISOString();
742
- events.push(traceEvent(run.run_id, "step_created", timestamp, eventIndex++, {
743
- stepName: workflowStepName("test", step.label),
744
- input: step.input,
745
- }, step.id));
746
- events.push(traceEvent(run.run_id, "step_started", timestamp, eventIndex++, {
747
- attempt: 1,
748
- }, step.id));
749
- events.push(traceEvent(run.run_id, step.status === "failed" ? "step_failed" : "step_completed", run.finished_at ?? timestamp, eventIndex++, step.status === "failed"
750
- ? { error: structuredWorkflowError(run.error ?? `${step.label} did not pass.`), output: step.output }
751
- : { result: step.output }, step.id));
752
- }
753
- if (traceStatus === "completed") {
754
- events.push(traceEvent(run.run_id, "run_completed", completedAt, eventIndex++, {
755
- output: {
756
- comparison: run.comparison,
757
- proof,
758
- },
759
- }));
760
- }
761
- else if (traceStatus === "failed") {
762
- events.push(traceEvent(run.run_id, "run_failed", completedAt, eventIndex++, {
763
- error: structuredWorkflowError(run.error),
764
- }));
765
- }
766
- else if (traceStatus === "cancelled") {
767
- events.push(traceEvent(run.run_id, "run_cancelled", completedAt, eventIndex++));
768
- }
769
- return RunObservabilityResourceSchema.parse({
770
- kind: "interf-run-observability",
771
- version: 1,
772
- run_id: run.run_id,
773
- run_type: "test",
774
- title,
775
- status: observableRunStatus(run.status),
776
- preparation: run.preparation,
777
- method: compiled?.target?.workflow ?? null,
778
- source_path: run.source_path ?? null,
779
- output_path: run.portable_context_path ?? null,
780
- created_at: run.started_at ?? completedAt ?? new Date().toISOString(),
781
- started_at: run.started_at ?? null,
782
- finished_at: run.finished_at ?? null,
783
- metrics: [
784
- { label: "Preparation", value: run.preparation },
785
- { label: "Mode", value: run.mode },
786
- { label: "Readiness checks", value: compiled ? `${compiled.passed_cases}/${compiled.total_cases}` : raw ? `${raw.passed_cases}/${raw.total_cases}` : "0/0" },
787
- { label: "Source files", value: raw ? `${raw.passed_cases}/${raw.total_cases}` : "-" },
788
- { label: "Portable context", value: compiled ? `${compiled.passed_cases}/${compiled.total_cases}` : "-" },
789
- ],
790
- artifacts,
791
- proof,
792
- trace: {
793
- run: {
794
- runId: run.run_id,
795
- status: traceStatus,
796
- deploymentId: "local-interf",
797
- workflowName,
798
- specVersion: 1,
799
- executionContext: {
800
- product: "Interf",
801
- run_type: "test",
802
- preparation: run.preparation,
803
- mode: run.mode,
804
- },
805
- input: {
806
- preparation: run.preparation,
807
- mode: run.mode,
808
- source_path: run.source_path ?? null,
809
- portable_context_path: run.portable_context_path ?? null,
810
- },
811
- ...(traceStatus === "completed" ? { output: { comparison: run.comparison, proof } } : {}),
812
- ...(traceStatus === "failed" ? { error: structuredWorkflowError(run.error) } : {}),
813
- ...(run.started_at ? { startedAt: run.started_at } : {}),
814
- ...(completedAt ? { completedAt } : {}),
815
- createdAt: run.started_at ?? completedAt ?? new Date().toISOString(),
816
- updatedAt: completedAt ?? run.started_at ?? new Date().toISOString(),
817
- },
818
- events,
819
- streams: buildTraceStreamChunks(run.run_id, run.events ?? []),
820
- },
821
- });
822
- }
823
- function jobRunToObservability(job) {
824
- const runType = (job.job_type === "preparation-setup" ||
825
- job.job_type === "readiness-check-draft" ||
826
- job.job_type === "method-authoring" ||
827
- job.job_type === "method-improvement"
828
- ? job.job_type
829
- : "job");
830
- const executor = job.agent
831
- ? {
832
- kind: "local-agent",
833
- name: job.agent.name,
834
- display_name: job.agent.display_name,
835
- command: job.agent.command ?? null,
836
- }
837
- : null;
838
- const traceStatus = workflowTraceRunStatus(job.status);
839
- const workflowName = workflowTraceName(runType, job.title);
840
- const completedAt = job.finished_at ?? (traceStatus === "completed" || traceStatus === "failed" || traceStatus === "cancelled"
841
- ? job.started_at ?? job.created_at
842
- : undefined);
843
- let eventIndex = 0;
844
- const events = [
845
- traceEvent(job.run_id, "run_created", job.created_at, eventIndex++, {
846
- deploymentId: "local-interf",
847
- workflowName,
848
- input: {
849
- job_type: job.job_type,
850
- preparation: job.preparation ?? null,
851
- method: job.method ?? null,
852
- },
853
- executionContext: {
854
- executor,
855
- },
856
- }),
857
- ];
858
- if (job.started_at) {
859
- events.push(traceEvent(job.run_id, "run_started", job.started_at, eventIndex++, {
860
- workflowName,
861
- input: {
862
- job_type: job.job_type,
863
- preparation: job.preparation ?? null,
864
- },
865
- executionContext: {
866
- executor,
867
- },
868
- }));
869
- }
870
- for (const step of job.steps) {
871
- const timestamp = step.started_at ?? job.started_at ?? job.created_at;
872
- events.push(traceEvent(job.run_id, "step_created", timestamp, eventIndex++, {
873
- stepName: workflowStepName(runType, step.label),
874
- input: step.input ?? {
875
- step_id: step.id,
876
- label: step.label,
877
- },
878
- }, step.id));
879
- if (step.started_at || step.status !== "queued") {
880
- events.push(traceEvent(job.run_id, "step_started", step.started_at ?? timestamp, eventIndex++, {
881
- attempt: 1,
882
- }, step.id));
883
- }
884
- if (step.status === "failed") {
885
- events.push(traceEvent(job.run_id, "step_failed", step.finished_at ?? completedAt ?? timestamp, eventIndex++, {
886
- error: structuredWorkflowError(step.summary ?? job.error),
887
- output: step.output ?? null,
888
- }, step.id));
889
- }
890
- else if (step.status === "succeeded") {
891
- events.push(traceEvent(job.run_id, "step_completed", step.finished_at ?? completedAt ?? timestamp, eventIndex++, {
892
- result: step.output ?? {
893
- summary: step.summary ?? null,
894
- },
895
- }, step.id));
896
- }
897
- }
898
- if (traceStatus === "completed") {
899
- events.push(traceEvent(job.run_id, "run_completed", completedAt, eventIndex++, {
900
- output: job.result ?? {
901
- output_path: job.output_path ?? null,
902
- },
903
- }));
904
- }
905
- else if (traceStatus === "failed") {
906
- events.push(traceEvent(job.run_id, "run_failed", completedAt, eventIndex++, {
907
- error: structuredWorkflowError(job.error),
908
- }));
909
- }
910
- else if (traceStatus === "cancelled") {
911
- events.push(traceEvent(job.run_id, "run_cancelled", completedAt, eventIndex++));
912
- }
913
- const outputPath = job.output_path ?? (typeof job.result?.path === "string" ? job.result.path : null);
914
- const artifacts = uniqueArtifacts(outputPath ? [{ path: outputPath, role: "output" }] : []);
915
- return RunObservabilityResourceSchema.parse({
916
- kind: "interf-run-observability",
917
- version: 1,
918
- run_id: job.run_id,
919
- run_type: runType,
920
- title: job.title,
921
- status: observableRunStatus(job.status),
922
- preparation: job.preparation ?? null,
923
- method: job.method ?? null,
924
- source_path: job.source_path ?? null,
925
- output_path: outputPath,
926
- executor,
927
- agent_label: agentLabelForJob(job),
928
- created_at: job.created_at,
929
- started_at: job.started_at ?? null,
930
- finished_at: job.finished_at ?? null,
931
- metrics: [
932
- { label: "Kind", value: jobTypeLabelForMetric(job.job_type) },
933
- { label: "Executor", value: agentLabelForJob(job) ?? "local executor" },
934
- { label: "Phases", value: `${job.steps.filter((step) => step.status === "succeeded").length}/${job.steps.length}` },
935
- { label: "Preparation", value: job.preparation ?? "-" },
936
- { label: "Method", value: job.method ?? "-" },
937
- ],
938
- artifacts,
939
- proof: [],
940
- trace: {
941
- run: {
942
- runId: job.run_id,
943
- status: traceStatus,
944
- deploymentId: "local-interf",
945
- workflowName,
946
- specVersion: 1,
947
- executionContext: {
948
- product: "Interf",
949
- run_type: runType,
950
- job_type: job.job_type,
951
- preparation: job.preparation ?? null,
952
- method: job.method ?? null,
953
- executor,
954
- },
955
- input: {
956
- job_type: job.job_type,
957
- preparation: job.preparation ?? null,
958
- method: job.method ?? null,
959
- source_path: job.source_path ?? null,
960
- },
961
- ...(traceStatus === "completed" ? { output: job.result ?? { output_path: outputPath } } : {}),
962
- ...(traceStatus === "failed" ? { error: structuredWorkflowError(job.error) } : {}),
963
- ...(job.started_at ? { startedAt: job.started_at } : {}),
964
- ...(completedAt ? { completedAt } : {}),
965
- createdAt: job.created_at,
966
- updatedAt: completedAt ?? job.started_at ?? job.created_at,
967
- },
968
- events,
969
- streams: buildTraceStreamChunks(job.run_id, job.events),
970
- },
971
- });
972
- }
973
403
  function slugFromText(value) {
974
404
  const slug = value
975
405
  .toLowerCase()
@@ -989,12 +419,23 @@ function numberValue(values, key) {
989
419
  }
990
420
  function testModeFromValues(values) {
991
421
  const value = stringValue(values, "mode") ?? stringValue(values, "target");
422
+ if (value === "source-files")
423
+ return "raw";
424
+ if (value === "portable-context")
425
+ return "compiled";
992
426
  return value === "raw" || value === "compiled" || value === "both" ? value : null;
993
427
  }
994
428
  function testModeValue(values, defaultMode = "both") {
995
429
  return testModeFromValues(values) ?? defaultMode;
996
430
  }
997
- function workflowIdForProposal(message, values) {
431
+ function testModeCliTarget(mode) {
432
+ if (mode === "raw")
433
+ return "source-files";
434
+ if (mode === "compiled")
435
+ return "portable-context";
436
+ return "both";
437
+ }
438
+ function methodIdForProposal(message, values) {
998
439
  const explicit = stringValue(values, "method_id") ??
999
440
  stringValue(values, "method");
1000
441
  return explicit ?? `custom-${slugFromText(message)}`;
@@ -1003,35 +444,35 @@ function actionValueMethodTaskPrompt(values) {
1003
444
  const parsed = MethodAuthoringActionValuesSchema.safeParse(values);
1004
445
  return parsed.success ? methodAuthoringTaskPrompt(parsed.data) : null;
1005
446
  }
1006
- function datasetSetupPathValue(values) {
447
+ function preparationSetupPathValue(values) {
1007
448
  return stringValue(values, "path") ??
1008
449
  stringValue(values, "source_folder_path") ??
1009
450
  stringValue(values, "source_path") ??
1010
451
  stringValue(values, "source_folder") ??
1011
452
  stringValue(values, "folder");
1012
453
  }
1013
- function datasetSetupNameValue(values) {
454
+ function preparationSetupNameValue(values) {
1014
455
  const parsed = PreparationSetupActionValuesSchema.safeParse(values);
1015
456
  return parsed.success ? parsed.data.name : stringValue(values, "name") ??
1016
457
  stringValue(values, "preparation") ??
1017
458
  stringValue(values, "preparation_name");
1018
459
  }
1019
- function actionCommandPreview(actionType, datasetName, workflowId, values) {
460
+ function actionCommandPreview(actionType, preparationName, methodId, values) {
1020
461
  if (actionType === "preparation-setup") {
1021
- const datasetPart = datasetName ? ` # Preparation: ${datasetName}` : "";
1022
- const pathPart = datasetSetupPathValue(values);
1023
- return pathPart ? `interf init # source: ${pathPart}${datasetPart}` : `interf init${datasetPart}`;
462
+ const preparationPart = preparationName ? ` # Preparation: ${preparationName}` : "";
463
+ const pathPart = preparationSetupPathValue(values);
464
+ return pathPart ? `interf init # source: ${pathPart}${preparationPart}` : `interf init${preparationPart}`;
1024
465
  }
1025
466
  if (actionType === "compile") {
1026
- const workflowSuffix = workflowId ? ` # Method: ${workflowId}` : "";
1027
- return datasetName
1028
- ? `interf compile --preparation ${datasetName}${workflowSuffix}`
1029
- : `interf compile${workflowSuffix}`;
467
+ const methodSuffix = methodId ? ` # Method: ${methodId}` : "";
468
+ return preparationName
469
+ ? `interf compile --preparation ${preparationName}${methodSuffix}`
470
+ : `interf compile${methodSuffix}`;
1030
471
  }
1031
472
  if (actionType === "test") {
1032
- const mode = testModeValue(values);
1033
- return datasetName
1034
- ? `interf test --preparation ${datasetName} --target ${mode}`
473
+ const mode = testModeCliTarget(testModeValue(values));
474
+ return preparationName
475
+ ? `interf test --preparation ${preparationName} --target ${mode}`
1035
476
  : `interf test --target ${mode}`;
1036
477
  }
1037
478
  if (actionType === "readiness-check-draft") {
@@ -1042,28 +483,28 @@ function actionCommandPreview(actionType, datasetName, workflowId, values) {
1042
483
  }
1043
484
  return "Try: create a Preparation, prepare, check readiness, draft readiness checks, or draft a Method.";
1044
485
  }
1045
- function hasCompiledTestTarget(sourcePath, datasetConfig) {
1046
- const compiledPath = portableContextPath(sourcePath, datasetConfig.name);
486
+ function hasCompiledTestTarget(sourcePath, preparationConfig) {
487
+ const compiledPath = portableContextPath(sourcePath, preparationConfig.name);
1047
488
  if (!existsSync(compiledPath))
1048
489
  return false;
1049
- return createCompiledTestTarget(compiledPath, datasetConfig.name, methodIdForSourcePreparationConfig(datasetConfig) ?? "interf").eligible;
490
+ return createCompiledTestTarget(compiledPath, preparationConfig.name, methodIdForSourcePreparationConfig(preparationConfig) ?? DEFAULT_METHOD_ID).eligible;
1050
491
  }
1051
- function actionAssistantMessage(actionType, datasetName, commandPreview) {
1052
- const datasetSuffix = datasetName ? ` for Preparation "${datasetName}"` : "";
492
+ function actionAssistantMessage(actionType, preparationName, commandPreview) {
493
+ const preparationSuffix = preparationName ? ` for Preparation "${preparationName}"` : "";
1053
494
  if (actionType === "preparation-setup") {
1054
- return `Interf prepared a Preparation setup proposal${datasetSuffix}. Approve to save the source folder and create the portable-context scaffold. CLI equivalent: ${commandPreview}`;
495
+ return `Interf prepared a Preparation setup proposal${preparationSuffix}. Approve to save the source folder and create the portable-context scaffold. CLI equivalent: ${commandPreview}`;
1055
496
  }
1056
497
  if (actionType === "compile") {
1057
- return `Interf prepared a prepare-run proposal${datasetSuffix}. Approve to submit it through the local Interf service and watch the run in Interf. CLI equivalent: ${commandPreview}`;
498
+ return `Interf prepared a prepare-run proposal${preparationSuffix}. Approve to submit it through the local Interf service and watch the run in Interf. CLI equivalent: ${commandPreview}`;
1058
499
  }
1059
500
  if (actionType === "test") {
1060
- return `Interf prepared a readiness-check proposal${datasetSuffix}. Approve to run the requested target against saved readiness checks. CLI equivalent: ${commandPreview}`;
501
+ return `Interf prepared a readiness-check proposal${preparationSuffix}. Approve to run the requested target against saved readiness checks. CLI equivalent: ${commandPreview}`;
1061
502
  }
1062
503
  if (actionType === "readiness-check-draft") {
1063
- return `Interf prepared a readiness-check draft proposal${datasetSuffix}. Approve to ask the configured local executor to draft checks as a visible run. CLI equivalent: ${commandPreview}`;
504
+ return `Interf prepared a readiness-check draft proposal${preparationSuffix}. Approve to ask the configured local executor to draft checks as a visible run. CLI equivalent: ${commandPreview}`;
1064
505
  }
1065
506
  if (actionType === "method-authoring" || actionType === "method-improvement") {
1066
- return `Interf prepared a Method draft proposal${datasetSuffix}. Approve to draft a reusable local Method as a visible run. CLI equivalent: ${commandPreview}`;
507
+ return `Interf prepared a Method draft proposal${preparationSuffix}. Approve to draft a reusable local Method as a visible run. CLI equivalent: ${commandPreview}`;
1067
508
  }
1068
509
  return "I could not map that to a safe Interf action. Ask for one action in plain English, such as create a Preparation, prepare the data, check readiness, draft readiness checks, or draft a Method.";
1069
510
  }
@@ -1111,27 +552,25 @@ function readinessStateToPreparationReadiness(readiness) {
1111
552
  checks: readiness.checks.map((check) => ({ ...check })),
1112
553
  });
1113
554
  }
1114
- function datasetResourceToPreparationResource(rootPath, resource) {
1115
- const latestCompileRunId = resource.latest_compile_run_id ?? null;
1116
- const latestTestRunId = resource.latest_test_run_id ?? null;
1117
- const methodId = methodIdForSourcePreparationConfig(resource.dataset);
555
+ function buildPreparationResource(rootPath, preparation, readiness, latestCompileRunId, latestTestRunId) {
556
+ const methodId = methodIdForSourcePreparationConfig(preparation);
1118
557
  return PreparationResourceSchema.parse({
1119
- id: resource.dataset.name,
1120
- name: resource.dataset.name,
1121
- preparation: resource.dataset,
1122
- source_path: resolveSourceDatasetPath(rootPath, resource.dataset),
558
+ id: preparation.name,
559
+ name: preparation.name,
560
+ preparation,
561
+ source_path: resolveSourcePreparationPath(rootPath, preparation),
1123
562
  method_id: methodId,
1124
- checks: resource.dataset.checks,
563
+ checks: preparation.checks,
1125
564
  portable_context: {
1126
- preparation: resource.dataset.name,
1127
- path: resource.portable_context_path,
1128
- exists: resource.portable_context_path !== null,
565
+ preparation: preparation.name,
566
+ path: readiness.portable_context_path,
567
+ exists: readiness.portable_context_path !== null,
1129
568
  method_id: methodId,
1130
569
  latest_compile_run_id: latestCompileRunId,
1131
570
  latest_test_run_id: latestTestRunId,
1132
571
  },
1133
- portable_context_path: resource.portable_context_path,
1134
- readiness: readinessStateToPreparationReadiness(resource.readiness),
572
+ portable_context_path: readiness.portable_context_path,
573
+ readiness: readinessStateToPreparationReadiness(readiness),
1135
574
  runs: {
1136
575
  latest_compile_run_id: latestCompileRunId,
1137
576
  latest_test_run_id: latestTestRunId,
@@ -1140,7 +579,7 @@ function datasetResourceToPreparationResource(rootPath, resource) {
1140
579
  latest_test_run_id: latestTestRunId,
1141
580
  });
1142
581
  }
1143
- function workflowPackageResourceToMethodResource(resource) {
582
+ function buildMethodResource(resource) {
1144
583
  return MethodResourceSchema.parse({
1145
584
  id: resource.id,
1146
585
  method_id: resource.id,
@@ -1149,7 +588,7 @@ function workflowPackageResourceToMethodResource(resource) {
1149
588
  ...(resource.hint ? { hint: resource.hint } : {}),
1150
589
  source_kind: resource.source_kind,
1151
590
  built_in: resource.built_in,
1152
- active_for_preparations: resource.active_for_datasets,
591
+ active_for_preparations: resource.active_for_preparations,
1153
592
  stages: resource.stages,
1154
593
  });
1155
594
  }
@@ -1183,31 +622,17 @@ export class LocalServiceRuntime {
1183
622
  ...(this.packageVersion ? { package_version: this.packageVersion } : {}),
1184
623
  });
1185
624
  }
1186
- listDatasets() {
625
+ listPreparations() {
1187
626
  const config = loadSourceFolderConfig(this.rootPath);
1188
- return listSourceDatasetConfigs(config).map((dataset) => {
1189
- const compileRuns = this.listCompileRunsForDataset(dataset.name);
1190
- const testRuns = this.listTestRunsForDataset(dataset.name);
1191
- const path = portableContextPath(this.rootPath, dataset.name);
1192
- const readiness = this.computeDatasetReadiness(dataset);
1193
- return DatasetResourceSchema.parse({
1194
- dataset,
1195
- portable_context_path: existsSync(path) ? path : null,
1196
- readiness,
1197
- latest_compile_run_id: compileRuns[0]?.run_id ?? null,
1198
- latest_test_run_id: testRuns[0]?.run_id ?? null,
1199
- });
627
+ return listSourcePreparationConfigs(config).map((preparation) => {
628
+ const compileRuns = this.listCompileRunsForPreparation(preparation.name);
629
+ const testRuns = this.listTestRunsForPreparation(preparation.name);
630
+ const readiness = this.computePreparationReadiness(preparation);
631
+ return buildPreparationResource(this.rootPath, preparation, readiness, compileRuns[0]?.run_id ?? null, testRuns[0]?.run_id ?? null);
1200
632
  });
1201
633
  }
1202
- getDataset(datasetName) {
1203
- return this.listDatasets().find((dataset) => dataset.dataset.name === datasetName) ?? null;
1204
- }
1205
- listPreparations() {
1206
- return this.listDatasets().map((resource) => datasetResourceToPreparationResource(this.rootPath, resource));
1207
- }
1208
634
  getPreparation(preparationName) {
1209
- const dataset = this.getDataset(preparationName);
1210
- return dataset ? datasetResourceToPreparationResource(this.rootPath, dataset) : null;
635
+ return this.listPreparations().find((preparation) => preparation.name === preparationName) ?? null;
1211
636
  }
1212
637
  listPreparationReadiness() {
1213
638
  return this.listReadiness().map(readinessStateToPreparationReadiness);
@@ -1218,21 +643,23 @@ export class LocalServiceRuntime {
1218
643
  }
1219
644
  listReadiness() {
1220
645
  const config = loadSourceFolderConfig(this.rootPath);
1221
- return listSourceDatasetConfigs(config).map((dataset) => this.computeDatasetReadiness(dataset));
646
+ return listSourcePreparationConfigs(config).map((preparation) => this.computePreparationReadiness(preparation));
1222
647
  }
1223
- getReadiness(datasetName) {
1224
- const dataset = findSourceDatasetConfig(loadSourceFolderConfig(this.rootPath), datasetName);
1225
- return dataset ? this.computeDatasetReadiness(dataset) : null;
648
+ getReadiness(preparationName) {
649
+ const preparation = findSourcePreparationConfig(loadSourceFolderConfig(this.rootPath), preparationName);
650
+ return preparation ? this.computePreparationReadiness(preparation) : null;
1226
651
  }
1227
- computeDatasetReadiness(dataset) {
652
+ computePreparationReadiness(preparation) {
1228
653
  const generatedAt = new Date().toISOString();
1229
- const compiledPath = portableContextPath(this.rootPath, dataset.name);
654
+ const compiledPath = portableContextPath(this.rootPath, preparation.name);
1230
655
  const contextExists = existsSync(compiledPath);
1231
- const compileRun = this.listCompileRunsForDataset(dataset.name)[0] ?? null;
1232
- const testRun = this.listTestRunsForDataset(dataset.name)[0] ?? null;
1233
- const comparison = testRun?.comparison ?? this.readLatestComparison(dataset.name);
1234
- const configuredChecks = dataset.checks.length;
1235
- const currentFingerprint = configuredChecks > 0 ? fingerprintReadinessChecks(dataset.checks) : null;
656
+ const compiledTarget = createCompiledTestTarget(compiledPath, preparation.name, methodIdForSourcePreparationConfig(preparation) ?? DEFAULT_METHOD_ID);
657
+ const contextReady = compiledTarget.eligible;
658
+ const compileRun = this.listCompileRunsForPreparation(preparation.name)[0] ?? null;
659
+ const testRun = this.listTestRunsForPreparation(preparation.name)[0] ?? null;
660
+ const comparison = this.readLatestComparison(preparation.name);
661
+ const configuredChecks = preparation.checks.length;
662
+ const currentFingerprint = configuredChecks > 0 ? fingerprintReadinessChecks(preparation.checks) : null;
1236
663
  const comparisonFingerprint = comparison?.checks_fingerprint ?? null;
1237
664
  const sourceResult = readinessTargetResult(comparison?.raw, currentFingerprint, comparisonFingerprint);
1238
665
  const contextResult = readinessTargetResult(comparison?.compiled, currentFingerprint, comparisonFingerprint);
@@ -1244,19 +671,19 @@ export class LocalServiceRuntime {
1244
671
  ok: false,
1245
672
  status: "not-built",
1246
673
  summary: "No compile run has built portable context yet.",
1247
- artifact_path: contextExists ? compiledPath : null,
674
+ artifact_path: contextReady ? compiledPath : null,
1248
675
  };
1249
676
  }
1250
677
  if (compileRun.status === "succeeded") {
1251
678
  return {
1252
679
  gate: "compile-run",
1253
- ok: contextExists,
1254
- status: contextExists ? "built" : "failed",
1255
- summary: contextExists
680
+ ok: contextReady,
681
+ status: contextReady ? "built" : "failed",
682
+ summary: contextReady
1256
683
  ? "Latest compile run built portable context."
1257
684
  : "Latest compile run finished, but portable context is missing.",
1258
685
  run_id: compileRun.run_id,
1259
- artifact_path: contextExists ? compiledPath : null,
686
+ artifact_path: contextReady ? compiledPath : null,
1260
687
  };
1261
688
  }
1262
689
  if (compileRun.status === "queued" || compileRun.status === "running") {
@@ -1277,7 +704,7 @@ export class LocalServiceRuntime {
1277
704
  ? "Latest compile run was cancelled."
1278
705
  : "Latest compile run failed.",
1279
706
  run_id: compileRun.run_id,
1280
- artifact_path: contextExists ? compiledPath : null,
707
+ artifact_path: contextReady ? compiledPath : null,
1281
708
  };
1282
709
  })();
1283
710
  const checks = [
@@ -1288,12 +715,12 @@ export class LocalServiceRuntime {
1288
715
  },
1289
716
  {
1290
717
  gate: "portable-context",
1291
- ok: contextExists,
1292
- status: contextExists ? "built" : "not-built",
1293
- summary: contextExists
1294
- ? "Portable context folder exists."
1295
- : "Portable context folder has not been created.",
1296
- artifact_path: contextExists ? compiledPath : null,
718
+ ok: contextReady,
719
+ status: contextReady ? "built" : "not-built",
720
+ summary: contextReady
721
+ ? "Portable context is built."
722
+ : "Portable context has not been built.",
723
+ artifact_path: contextReady ? compiledPath : null,
1297
724
  },
1298
725
  compileCheck,
1299
726
  {
@@ -1320,7 +747,7 @@ export class LocalServiceRuntime {
1320
747
  return "checking";
1321
748
  if (compileRun?.status === "failed" || compileRun?.status === "cancelled")
1322
749
  return "failed";
1323
- if (!compileRun || !contextExists)
750
+ if (!compileRun || !contextReady)
1324
751
  return "not-built";
1325
752
  if (configuredChecks === 0)
1326
753
  return "not-configured";
@@ -1335,11 +762,11 @@ export class LocalServiceRuntime {
1335
762
  kind: "interf-readiness-state",
1336
763
  version: 1,
1337
764
  generated_at: generatedAt,
1338
- preparation: dataset.name,
765
+ preparation: preparation.name,
1339
766
  status,
1340
767
  ready,
1341
768
  summary: readinessSummaryForStatus(status),
1342
- portable_context_path: contextExists ? compiledPath : null,
769
+ portable_context_path: contextReady ? compiledPath : null,
1343
770
  latest_compile_run_id: compileRun?.run_id ?? null,
1344
771
  latest_test_run_id: testRun?.run_id ?? null,
1345
772
  compile: compileCheck,
@@ -1353,12 +780,12 @@ export class LocalServiceRuntime {
1353
780
  checks,
1354
781
  });
1355
782
  }
1356
- listSourceFiles(datasetName) {
1357
- const datasets = listSourceDatasetConfigs(loadSourceFolderConfig(this.rootPath))
1358
- .filter((dataset) => !datasetName || dataset.name === datasetName);
1359
- return datasets.flatMap((dataset) => {
1360
- const sourceFolderPath = resolveSourceDatasetPath(this.rootPath, dataset);
1361
- const compiledPath = portableContextPath(this.rootPath, dataset.name);
783
+ listSourceFiles(preparationName) {
784
+ const preparations = listSourcePreparationConfigs(loadSourceFolderConfig(this.rootPath))
785
+ .filter((preparation) => !preparationName || preparation.name === preparationName);
786
+ return preparations.flatMap((preparation) => {
787
+ const sourceFolderPath = resolveSourcePreparationPath(this.rootPath, preparation);
788
+ const compiledPath = portableContextPath(this.rootPath, preparation.name);
1362
789
  return discoverSourceFiles(sourceFolderPath, compiledPath).sourceFiles.map((relativePath) => {
1363
790
  const absolutePath = join(sourceFolderPath, relativePath);
1364
791
  let sizeBytes = 0;
@@ -1373,7 +800,7 @@ export class LocalServiceRuntime {
1373
800
  modifiedAt = null;
1374
801
  }
1375
802
  return SourceFileResourceSchema.parse({
1376
- preparation: dataset.name,
803
+ preparation: preparation.name,
1377
804
  path: relativePath,
1378
805
  absolute_path: absolutePath,
1379
806
  size_bytes: sizeBytes,
@@ -1406,24 +833,22 @@ export class LocalServiceRuntime {
1406
833
  });
1407
834
  });
1408
835
  }
1409
- listWorkflowPackages() {
1410
- const datasets = listSourceDatasetConfigs(loadSourceFolderConfig(this.rootPath));
1411
- const choices = listCompiledWorkflowChoices(this.rootPath);
1412
- const hasLocalDefault = choices.some((workflow) => workflow.scope === "local" && workflow.id === "interf-default");
1413
- const implicitDefaultWorkflowId = hasLocalDefault ? "interf-default" : "interf";
1414
- return choices.filter((workflow) => !(hasLocalDefault && workflow.scope === "builtin" && workflow.id === "interf")).map((workflow) => {
1415
- const activeForDatasets = datasets
1416
- .filter((dataset) => (methodIdForSourcePreparationConfig(dataset) ?? implicitDefaultWorkflowId) === workflow.id)
1417
- .map((dataset) => dataset.name);
1418
- return WorkflowPackageResourceSchema.parse({
1419
- id: workflow.id,
1420
- path: resolveWorkflowPackageSourcePath(this.rootPath, workflow.id) ?? workflow.id,
1421
- label: workflow.label,
1422
- hint: workflow.hint,
1423
- source_kind: workflow.scope === "builtin" ? "builtin" : "local",
1424
- built_in: workflow.scope === "builtin",
1425
- active_for_datasets: activeForDatasets,
1426
- stages: workflow.stages.map((stage) => ({
836
+ listMethods() {
837
+ const preparations = listSourcePreparationConfigs(loadSourceFolderConfig(this.rootPath));
838
+ const choices = listCompiledMethodChoices(this.rootPath);
839
+ return choices.map((method) => {
840
+ const activeForPreparations = preparations
841
+ .filter((preparation) => (methodIdForSourcePreparationConfig(preparation) ?? DEFAULT_METHOD_ID) === method.id)
842
+ .map((preparation) => preparation.name);
843
+ return buildMethodResource({
844
+ id: method.id,
845
+ path: resolveMethodPackageSourcePath(this.rootPath, method.id) ?? method.id,
846
+ label: method.label,
847
+ hint: method.hint,
848
+ source_kind: method.scope === "builtin" ? "builtin" : "local",
849
+ built_in: method.scope === "builtin",
850
+ active_for_preparations: activeForPreparations,
851
+ stages: method.stages.map((stage) => ({
1427
852
  id: stage.id,
1428
853
  label: stage.label,
1429
854
  description: stage.description,
@@ -1436,15 +861,8 @@ export class LocalServiceRuntime {
1436
861
  });
1437
862
  });
1438
863
  }
1439
- getWorkflowPackage(workflowId) {
1440
- return this.listWorkflowPackages().find((workflow) => workflow.id === workflowId) ?? null;
1441
- }
1442
- listMethods() {
1443
- return this.listWorkflowPackages().map(workflowPackageResourceToMethodResource);
1444
- }
1445
864
  getMethod(methodId) {
1446
- const workflowPackage = this.getWorkflowPackage(methodId);
1447
- return workflowPackage ? workflowPackageResourceToMethodResource(workflowPackage) : null;
865
+ return this.listMethods().find((method) => method.id === methodId) ?? null;
1448
866
  }
1449
867
  listJobs() {
1450
868
  return newestJobFirst(listJsonFiles(localJobsRoot(this.rootPath))
@@ -1713,16 +1131,20 @@ export class LocalServiceRuntime {
1713
1131
  void this.runReadinessCheckDraftInBackground(request, job.run_id);
1714
1132
  return this.getJob(job.run_id) ?? job;
1715
1133
  }
1716
- async createDatasetSetupRun(requestValue) {
1717
- const request = DatasetSetupCreateRequestSchema.parse(requestValue);
1718
- const datasetConfig = request.preparation;
1719
- const methodId = methodIdForSourcePreparationConfig(datasetConfig) ?? "interf-default";
1720
- const sourceFolderPath = resolveSourceDatasetPath(this.rootPath, datasetConfig);
1721
- const outputPath = portableContextPath(this.rootPath, datasetConfig.name);
1134
+ async createPreparationSetupRun(requestValue) {
1135
+ const request = PreparationSetupCreateRequestSchema.parse(requestValue);
1136
+ const preparationConfig = request.preparation;
1137
+ const methodId = methodIdForSourcePreparationConfig(preparationConfig) ?? "interf-default";
1138
+ const normalizedPreparationConfig = {
1139
+ ...preparationConfig,
1140
+ method: methodId,
1141
+ };
1142
+ const sourceFolderPath = resolveSourcePreparationPath(this.rootPath, preparationConfig);
1143
+ const outputPath = portableContextPath(this.rootPath, preparationConfig.name);
1722
1144
  const job = this.createJobRun({
1723
1145
  job_type: "preparation-setup",
1724
- title: `Create Preparation ${datasetConfig.name}`,
1725
- preparation: datasetConfig.name,
1146
+ title: `Create Preparation ${preparationConfig.name}`,
1147
+ preparation: preparationConfig.name,
1726
1148
  method: methodId,
1727
1149
  source_path: sourceFolderPath,
1728
1150
  output_path: outputPath,
@@ -1732,8 +1154,8 @@ export class LocalServiceRuntime {
1732
1154
  id: "validate-source",
1733
1155
  label: "Validate source folder",
1734
1156
  input: {
1735
- preparation: datasetConfig.name,
1736
- path: datasetConfig.path,
1157
+ preparation: preparationConfig.name,
1158
+ path: preparationConfig.path,
1737
1159
  },
1738
1160
  },
1739
1161
  {
@@ -1760,12 +1182,12 @@ export class LocalServiceRuntime {
1760
1182
  step_id: "validate-source",
1761
1183
  message: "Validating source folder.",
1762
1184
  input: {
1763
- path: datasetConfig.path,
1185
+ path: preparationConfig.path,
1764
1186
  source_folder_path: sourceFolderPath,
1765
1187
  },
1766
1188
  });
1767
1189
  if (!existsSync(sourceFolderPath) || !statSync(sourceFolderPath).isDirectory()) {
1768
- throw new Error(`Source folder "${datasetConfig.path}" is not available.`);
1190
+ throw new Error(`Source folder "${preparationConfig.path}" is not available.`);
1769
1191
  }
1770
1192
  this.appendJobRunEvent(job.run_id, {
1771
1193
  type: "step.completed",
@@ -1781,18 +1203,18 @@ export class LocalServiceRuntime {
1781
1203
  step_id: "write-config",
1782
1204
  message: "Saving Preparation in the control plane config.",
1783
1205
  input: {
1784
- preparation: datasetConfig.name,
1785
- path: datasetConfig.path,
1206
+ preparation: preparationConfig.name,
1207
+ path: preparationConfig.path,
1786
1208
  },
1787
1209
  });
1788
- upsertSourceDatasetConfig(this.rootPath, datasetConfig);
1210
+ upsertSourcePreparationConfig(this.rootPath, normalizedPreparationConfig);
1789
1211
  this.appendJobRunEvent(job.run_id, {
1790
1212
  type: "step.completed",
1791
1213
  step_id: "write-config",
1792
1214
  message: "Preparation config saved.",
1793
1215
  output: {
1794
1216
  config_path: join(this.rootPath, "interf", "interf.json"),
1795
- preparation: datasetConfig.name,
1217
+ preparation: preparationConfig.name,
1796
1218
  },
1797
1219
  });
1798
1220
  activeStep = "prepare-scaffold";
@@ -1805,8 +1227,8 @@ export class LocalServiceRuntime {
1805
1227
  method: methodId,
1806
1228
  },
1807
1229
  });
1808
- const compiledPath = ensurePortableContextScaffold(this.rootPath, datasetConfig.name, methodId);
1809
- syncCompiledInterfConfigFromSourceDatasetConfig(compiledPath, datasetConfig);
1230
+ const compiledPath = ensurePortableContextScaffold(this.rootPath, normalizedPreparationConfig.name, methodId);
1231
+ syncCompiledInterfConfigFromSourcePreparationConfig(compiledPath, normalizedPreparationConfig);
1810
1232
  this.appendJobRunEvent(job.run_id, {
1811
1233
  type: "step.completed",
1812
1234
  step_id: "prepare-scaffold",
@@ -1816,13 +1238,13 @@ export class LocalServiceRuntime {
1816
1238
  },
1817
1239
  });
1818
1240
  this.setJobRunResult(job.run_id, {
1819
- preparation: datasetConfig,
1241
+ preparation: normalizedPreparationConfig,
1820
1242
  source_folder_path: sourceFolderPath,
1821
1243
  portable_context_path: compiledPath,
1822
1244
  });
1823
1245
  this.appendJobRunEvent(job.run_id, {
1824
1246
  type: "job.completed",
1825
- message: `Preparation ${datasetConfig.name} is ready for Interf runs.`,
1247
+ message: `Preparation ${preparationConfig.name} is ready for Interf runs.`,
1826
1248
  });
1827
1249
  }
1828
1250
  catch (error) {
@@ -1842,8 +1264,8 @@ export class LocalServiceRuntime {
1842
1264
  }
1843
1265
  return this.getJob(job.run_id) ?? job;
1844
1266
  }
1845
- async createWorkflowAuthoringRun(requestValue) {
1846
- const request = WorkflowAuthoringCreateRequestSchema.parse(requestValue);
1267
+ async createMethodAuthoringRun(requestValue) {
1268
+ const request = MethodAuthoringCreateRequestSchema.parse(requestValue);
1847
1269
  const job = this.createJobRun({
1848
1270
  job_type: "method-authoring",
1849
1271
  title: `Draft Method ${request.method_id}`,
@@ -1908,25 +1330,26 @@ export class LocalServiceRuntime {
1908
1330
  task_prompt: request.task_prompt,
1909
1331
  },
1910
1332
  });
1911
- void this.runWorkflowAuthoringInBackground(request, job.run_id);
1333
+ void this.runMethodAuthoringInBackground(request, job.run_id);
1912
1334
  return this.getJob(job.run_id) ?? job;
1913
1335
  }
1914
1336
  listPortableContexts() {
1915
- return this.listDatasets().map((dataset) => this.getPortableContext(dataset.dataset.name))
1337
+ return listSourcePreparationConfigs(loadSourceFolderConfig(this.rootPath))
1338
+ .map((preparation) => this.getPortableContext(preparation.name))
1916
1339
  .filter((context) => context !== null);
1917
1340
  }
1918
- getPortableContext(datasetName) {
1919
- const dataset = findSourceDatasetConfig(loadSourceFolderConfig(this.rootPath), datasetName);
1920
- if (!dataset)
1341
+ getPortableContext(preparationName) {
1342
+ const preparation = findSourcePreparationConfig(loadSourceFolderConfig(this.rootPath), preparationName);
1343
+ if (!preparation)
1921
1344
  return null;
1922
- const path = portableContextPath(this.rootPath, dataset.name);
1345
+ const path = portableContextPath(this.rootPath, preparation.name);
1923
1346
  const config = readInterfConfig(path);
1924
- const compileRuns = this.listCompileRunsForDataset(dataset.name);
1925
- const testRuns = this.listTestRunsForDataset(dataset.name);
1926
- const readiness = this.computeDatasetReadiness(dataset);
1927
- const method = config?.method ?? config?.workflow ?? methodIdForSourcePreparationConfig(dataset);
1347
+ const compileRuns = this.listCompileRunsForPreparation(preparation.name);
1348
+ const testRuns = this.listTestRunsForPreparation(preparation.name);
1349
+ const readiness = this.computePreparationReadiness(preparation);
1350
+ const method = config?.method ?? methodIdForSourcePreparationConfig(preparation);
1928
1351
  return PortableContextResourceSchema.parse({
1929
- preparation: dataset.name,
1352
+ preparation: preparation.name,
1930
1353
  path,
1931
1354
  exists: existsSync(path),
1932
1355
  readiness,
@@ -1937,10 +1360,11 @@ export class LocalServiceRuntime {
1937
1360
  });
1938
1361
  }
1939
1362
  listCompileRuns() {
1940
- return newestCompileFirst(this.listDatasets().flatMap((dataset) => this.listCompileRunsForDataset(dataset.dataset.name))).map((run) => CompileRunResourceSchema.parse({ run }));
1363
+ return newestCompileFirst(listSourcePreparationConfigs(loadSourceFolderConfig(this.rootPath))
1364
+ .flatMap((preparation) => this.listCompileRunsForPreparation(preparation.name))).map((run) => CompileRunResourceSchema.parse({ run }));
1941
1365
  }
1942
- listCompileRunsForDataset(datasetName) {
1943
- const compiledPath = portableContextPath(this.rootPath, datasetName);
1366
+ listCompileRunsForPreparation(preparationName) {
1367
+ const compiledPath = portableContextPath(this.rootPath, preparationName);
1944
1368
  return newestCompileFirst(listJsonFiles(compileRunsRoot(compiledPath))
1945
1369
  .map(readCompileRunAt)
1946
1370
  .filter((run) => run !== null));
@@ -1971,47 +1395,50 @@ export class LocalServiceRuntime {
1971
1395
  }
1972
1396
  async createCompileRun(requestValue) {
1973
1397
  const request = CompileRunCreateRequestSchema.parse(requestValue);
1974
- const datasetConfig = this.resolveDatasetConfig(request.preparation, {
1398
+ const preparationConfig = this.resolvePreparationConfig(request.preparation, {
1975
1399
  method: request.method,
1976
1400
  max_attempts: request.max_attempts,
1977
1401
  max_loops: request.max_loops,
1978
1402
  });
1979
- const compiledPath = this.ensureCompiledForRun(datasetConfig);
1403
+ const compiledPath = this.ensureCompiledForRun(preparationConfig);
1980
1404
  const runId = createRunId("compile");
1981
1405
  const now = new Date().toISOString();
1982
- const workflow = getCompiledWorkflow(methodIdForSourcePreparationConfig(datasetConfig) ?? "interf", {
1406
+ const method = getCompiledMethod(methodIdForSourcePreparationConfig(preparationConfig) ?? DEFAULT_METHOD_ID, {
1983
1407
  sourcePath: this.rootPath,
1984
1408
  });
1985
- const stageTotal = workflow.stages.length;
1409
+ const stageTotal = method.stages.length;
1986
1410
  const run = CompileRunSchema.parse({
1987
1411
  kind: "interf-compile-run",
1988
1412
  version: 1,
1989
1413
  run_id: runId,
1990
1414
  status: "running",
1991
- preparation: datasetConfig.name,
1992
- method: workflow.id,
1415
+ preparation: preparationConfig.name,
1416
+ method: method.id,
1993
1417
  backend: "native",
1994
- source_path: resolveSourceDatasetPath(this.rootPath, datasetConfig),
1418
+ source_path: resolveSourcePreparationPath(this.rootPath, preparationConfig),
1995
1419
  portable_context_path: compiledPath,
1996
1420
  created_at: now,
1997
1421
  started_at: now,
1998
- stages: workflow.stages.map((stage, index) => ({
1999
- run_id: runId,
2000
- stage_id: stage.id,
2001
- stage_label: stage.label,
2002
- stage_index: index,
2003
- stage_total: stageTotal,
2004
- status: "queued",
2005
- contract: {
1422
+ stages: method.stages
1423
+ .map((stage, index) => {
1424
+ return {
1425
+ run_id: runId,
1426
+ stage_id: stage.id,
2006
1427
  stage_label: stage.label,
2007
1428
  stage_index: index,
2008
1429
  stage_total: stageTotal,
2009
- reads: stage.reads,
2010
- writes: stage.writes,
2011
- ...(stage.acceptance ? { acceptance: stage.acceptance } : {}),
2012
- },
2013
- artifacts: [],
2014
- })),
1430
+ status: "queued",
1431
+ contract: {
1432
+ stage_label: stage.label,
1433
+ stage_index: index,
1434
+ stage_total: stageTotal,
1435
+ reads: stage.reads,
1436
+ writes: stage.writes,
1437
+ ...(stage.acceptance ? { acceptance: stage.acceptance } : {}),
1438
+ },
1439
+ artifacts: [],
1440
+ };
1441
+ }),
2015
1442
  events: [],
2016
1443
  });
2017
1444
  this.writeCompileRun(compiledPath, run);
@@ -2020,8 +1447,8 @@ export class LocalServiceRuntime {
2020
1447
  event_id: createRunEventId("event"),
2021
1448
  run_id: runId,
2022
1449
  timestamp: now,
2023
- preparation: datasetConfig.name,
2024
- method: workflow.id,
1450
+ preparation: preparationConfig.name,
1451
+ method: method.id,
2025
1452
  portable_context_path: compiledPath,
2026
1453
  backend: "native",
2027
1454
  });
@@ -2032,17 +1459,18 @@ export class LocalServiceRuntime {
2032
1459
  runId,
2033
1460
  sourcePath: this.rootPath,
2034
1461
  compiledPath,
2035
- datasetConfig,
1462
+ preparationConfig,
2036
1463
  events: sink,
2037
1464
  });
2038
1465
  const saved = this.readCompileRun(compiledPath, runId) ?? run;
2039
1466
  return CompileRunResourceSchema.parse({ run: saved });
2040
1467
  }
2041
1468
  listTestRuns() {
2042
- return newestFirst(this.listDatasets().flatMap((dataset) => this.listTestRunsForDataset(dataset.dataset.name)));
1469
+ return newestFirst(listSourcePreparationConfigs(loadSourceFolderConfig(this.rootPath))
1470
+ .flatMap((preparation) => this.listTestRunsForPreparation(preparation.name)));
2043
1471
  }
2044
- listTestRunsForDataset(datasetName) {
2045
- const compiledPath = portableContextPath(this.rootPath, datasetName);
1472
+ listTestRunsForPreparation(preparationName) {
1473
+ const compiledPath = portableContextPath(this.rootPath, preparationName);
2046
1474
  return newestFirst(listJsonFiles(testRunsRoot(compiledPath))
2047
1475
  .map(readTestRunAt)
2048
1476
  .filter((run) => run !== null));
@@ -2052,15 +1480,15 @@ export class LocalServiceRuntime {
2052
1480
  }
2053
1481
  async createTestRun(requestValue) {
2054
1482
  const request = TestRunCreateRequestSchema.parse(requestValue);
2055
- const datasetConfig = this.resolveDatasetConfig(request.preparation);
2056
- const compiledPath = portableContextPath(this.rootPath, datasetConfig.name);
2057
- const compiledTarget = createCompiledTestTarget(compiledPath, datasetConfig.name, methodIdForSourcePreparationConfig(datasetConfig) ?? "interf");
1483
+ const preparationConfig = this.resolvePreparationConfig(request.preparation);
1484
+ const compiledPath = portableContextPath(this.rootPath, preparationConfig.name);
1485
+ const compiledTarget = createCompiledTestTarget(compiledPath, preparationConfig.name, methodIdForSourcePreparationConfig(preparationConfig) ?? DEFAULT_METHOD_ID);
2058
1486
  const runId = createRunId("test");
2059
1487
  const now = new Date().toISOString();
2060
1488
  const initial = TestRunResourceSchema.parse({
2061
1489
  run_id: runId,
2062
1490
  status: "running",
2063
- preparation: datasetConfig.name,
1491
+ preparation: preparationConfig.name,
2064
1492
  mode: request.mode,
2065
1493
  source_path: this.rootPath,
2066
1494
  portable_context_path: compiledTarget.eligible ? compiledPath : null,
@@ -2073,7 +1501,7 @@ export class LocalServiceRuntime {
2073
1501
  runId,
2074
1502
  sourcePath: this.rootPath,
2075
1503
  compiledPath,
2076
- datasetConfig,
1504
+ preparationConfig,
2077
1505
  }, initial);
2078
1506
  return initial;
2079
1507
  }
@@ -2120,7 +1548,7 @@ export class LocalServiceRuntime {
2120
1548
  throw new Error("No test-run handler is configured for this local service.");
2121
1549
  }
2122
1550
  const result = LocalRunHandlerResultSchema.parse(await this.handlers.createTestRun(request, context));
2123
- const comparison = this.readLatestComparison(context.datasetConfig.name);
1551
+ const comparison = result.comparison ?? this.readLatestComparison(context.preparationConfig.name);
2124
1552
  const resultEvent = comparison
2125
1553
  ? this.checksEvaluatedEvent(context.runId, comparison)
2126
1554
  : null;
@@ -2133,13 +1561,13 @@ export class LocalServiceRuntime {
2133
1561
  ...(!result.ok ? { error: result.error ?? "Readiness check failed." } : {}),
2134
1562
  });
2135
1563
  this.writeTestRun(context.compiledPath, nextWithoutReadiness);
2136
- const readiness = this.computeDatasetReadiness(context.datasetConfig);
1564
+ const readiness = this.computePreparationReadiness(context.preparationConfig);
2137
1565
  const next = TestRunResourceSchema.parse({
2138
1566
  ...nextWithoutReadiness,
2139
1567
  readiness,
2140
1568
  events: [
2141
1569
  ...nextWithoutReadiness.events,
2142
- this.readinessUpdatedEvent(context.runId, context.datasetConfig.name, readiness),
1570
+ this.readinessUpdatedEvent(context.runId, context.preparationConfig.name, readiness),
2143
1571
  ],
2144
1572
  });
2145
1573
  this.writeTestRun(context.compiledPath, next);
@@ -2152,11 +1580,11 @@ export class LocalServiceRuntime {
2152
1580
  error: error instanceof Error ? error.message : String(error),
2153
1581
  });
2154
1582
  this.writeTestRun(context.compiledPath, failedWithoutReadiness);
2155
- const readiness = this.computeDatasetReadiness(context.datasetConfig);
1583
+ const readiness = this.computePreparationReadiness(context.preparationConfig);
2156
1584
  const next = TestRunResourceSchema.parse({
2157
1585
  ...failedWithoutReadiness,
2158
1586
  readiness,
2159
- events: [this.readinessUpdatedEvent(context.runId, context.datasetConfig.name, readiness)],
1587
+ events: [this.readinessUpdatedEvent(context.runId, context.preparationConfig.name, readiness)],
2160
1588
  });
2161
1589
  this.writeTestRun(context.compiledPath, next);
2162
1590
  }
@@ -2213,12 +1641,12 @@ export class LocalServiceRuntime {
2213
1641
  });
2214
1642
  }
2215
1643
  }
2216
- async runWorkflowAuthoringInBackground(request, runId) {
1644
+ async runMethodAuthoringInBackground(request, runId) {
2217
1645
  try {
2218
- if (!this.handlers.createWorkflowAuthoringRun) {
1646
+ if (!this.handlers.createMethodAuthoringRun) {
2219
1647
  throw new Error("No Method-authoring handler is configured for this local service.");
2220
1648
  }
2221
- const result = WorkflowAuthoringResultSchema.parse(await this.handlers.createWorkflowAuthoringRun(request, this.jobRunContext(runId)));
1649
+ const result = MethodAuthoringResultSchema.parse(await this.handlers.createMethodAuthoringRun(request, this.jobRunContext(runId)));
2222
1650
  this.setJobRunResult(runId, result);
2223
1651
  this.appendJobRunEvent(runId, {
2224
1652
  type: result.status === "executor-failed" ? "step.failed" : "step.completed",
@@ -2295,12 +1723,12 @@ export class LocalServiceRuntime {
2295
1723
  },
2296
1724
  };
2297
1725
  }
2298
- defaultDatasetName() {
2299
- const dataset = listSourceDatasetConfigs(loadSourceFolderConfig(this.rootPath))[0];
2300
- if (!dataset) {
1726
+ defaultPreparationName() {
1727
+ const preparation = listSourcePreparationConfigs(loadSourceFolderConfig(this.rootPath))[0];
1728
+ if (!preparation) {
2301
1729
  throw new Error("No Preparation is saved in this control plane folder.");
2302
1730
  }
2303
- return dataset.name;
1731
+ return preparation.name;
2304
1732
  }
2305
1733
  async planActionProposal(request) {
2306
1734
  if (!this.handlers.planActionProposal) {
@@ -2310,17 +1738,17 @@ export class LocalServiceRuntime {
2310
1738
  assistant_message: "No local action planner is configured for this Interf Workspace.",
2311
1739
  });
2312
1740
  }
2313
- const datasets = listSourceDatasetConfigs(loadSourceFolderConfig(this.rootPath));
1741
+ const preparations = listSourcePreparationConfigs(loadSourceFolderConfig(this.rootPath));
2314
1742
  let rawPlan;
2315
1743
  try {
2316
1744
  rawPlan = await this.handlers.planActionProposal(request, {
2317
1745
  sourcePath: this.rootPath,
2318
- datasets,
2319
- preparationHealth: datasets.map((dataset) => {
2320
- const readinessChecks = dataset.checks?.length ?? 0;
2321
- const portableContextReady = hasCompiledTestTarget(this.rootPath, dataset);
1746
+ preparations,
1747
+ preparationHealth: preparations.map((preparation) => {
1748
+ const readinessChecks = preparation.checks?.length ?? 0;
1749
+ const portableContextReady = hasCompiledTestTarget(this.rootPath, preparation);
2322
1750
  return {
2323
- name: dataset.name,
1751
+ name: preparation.name,
2324
1752
  readiness_checks: readinessChecks,
2325
1753
  portable_context_ready: portableContextReady,
2326
1754
  can_check_readiness: readinessChecks > 0 && portableContextReady,
@@ -2342,7 +1770,7 @@ export class LocalServiceRuntime {
2342
1770
  assistant_message: ACTION_PLANNER_CLARIFICATION_MESSAGE,
2343
1771
  });
2344
1772
  }
2345
- const parsed = ActionProposalPlanSchema.safeParse(rawPlan);
1773
+ const parsed = ActionProposalPlanSchema.safeParse(sanitizeActionProposalPlan(rawPlan));
2346
1774
  if (parsed.success)
2347
1775
  return parsed.data;
2348
1776
  return ActionProposalPlanSchema.parse({
@@ -2351,9 +1779,9 @@ export class LocalServiceRuntime {
2351
1779
  assistant_message: ACTION_PLANNER_CLARIFICATION_MESSAGE,
2352
1780
  });
2353
1781
  }
2354
- buildDatasetSetupRequest(request, plan, values) {
1782
+ buildPreparationSetupRequest(request, plan, values) {
2355
1783
  const sourceFolderChoices = listSourceFolderChoices(this.rootPath);
2356
- const selectedPath = datasetSetupPathValue(values) ??
1784
+ const selectedPath = preparationSetupPathValue(values) ??
2357
1785
  (sourceFolderChoices.length === 1 ? sourceFolderChoices[0].value : null);
2358
1786
  if (!selectedPath) {
2359
1787
  return {
@@ -2362,30 +1790,30 @@ export class LocalServiceRuntime {
2362
1790
  }
2363
1791
  let normalizedPath;
2364
1792
  try {
2365
- normalizedPath = normalizeSourceDatasetPathForConfig(this.rootPath, selectedPath);
1793
+ normalizedPath = normalizeSourcePreparationPathForConfig(this.rootPath, selectedPath);
2366
1794
  }
2367
1795
  catch (error) {
2368
1796
  return {
2369
1797
  error: error instanceof Error ? error.message : String(error),
2370
1798
  };
2371
1799
  }
2372
- const explicitName = datasetSetupNameValue(values) ?? plan.preparation ?? request.preparation;
2373
- const datasetName = explicitName
1800
+ const explicitName = preparationSetupNameValue(values) ?? plan.preparation ?? request.preparation;
1801
+ const preparationName = explicitName
2374
1802
  ? slugFromText(explicitName)
2375
- : defaultDatasetNameForPath(normalizedPath);
2376
- const requestWorkflowId = stringValue(request.values, "method") ?? stringValue(request.values, "workflow");
2377
- const valueWorkflowId = stringValue(values, "method") ?? stringValue(values, "workflow");
2378
- const workflowId = requestWorkflowId ?? plan.method ?? valueWorkflowId ?? "interf-default";
1803
+ : defaultPreparationNameForPath(normalizedPath);
1804
+ const requestMethodId = stringValue(request.values, "method");
1805
+ const valueMethodId = stringValue(values, "method");
1806
+ const methodId = requestMethodId ?? plan.method ?? valueMethodId ?? "interf-default";
2379
1807
  try {
2380
1808
  return {
2381
- datasetName,
2382
- workflowId,
2383
- request: DatasetSetupCreateRequestSchema.parse({
1809
+ preparationName,
1810
+ methodId,
1811
+ request: PreparationSetupCreateRequestSchema.parse({
2384
1812
  preparation: {
2385
- name: datasetName,
1813
+ name: preparationName,
2386
1814
  path: normalizedPath,
2387
1815
  about: stringValue(values, "about") ?? stringValue(values, "task_prompt") ?? request.message,
2388
- method: workflowId,
1816
+ method: methodId,
2389
1817
  checks: [],
2390
1818
  },
2391
1819
  }),
@@ -2433,7 +1861,7 @@ export class LocalServiceRuntime {
2433
1861
  ...(request.values ?? {}),
2434
1862
  };
2435
1863
  if (actionType === "preparation-setup") {
2436
- const setup = this.buildDatasetSetupRequest(request, plan, proposalValues);
1864
+ const setup = this.buildPreparationSetupRequest(request, plan, proposalValues);
2437
1865
  if ("error" in setup) {
2438
1866
  return ActionProposalResourceSchema.parse({
2439
1867
  kind: "interf-action-proposal",
@@ -2461,7 +1889,7 @@ export class LocalServiceRuntime {
2461
1889
  });
2462
1890
  }
2463
1891
  const commandPreview = plan.command_preview ??
2464
- actionCommandPreview(actionType, setup.datasetName, setup.workflowId, {
1892
+ actionCommandPreview(actionType, setup.preparationName, setup.methodId, {
2465
1893
  ...proposalValues,
2466
1894
  path: setup.request.preparation.path,
2467
1895
  });
@@ -2471,13 +1899,13 @@ export class LocalServiceRuntime {
2471
1899
  proposal_id: createActionProposalId(),
2472
1900
  status: "awaiting_approval",
2473
1901
  action_type: actionType,
2474
- title: plan.title ?? `Create Preparation ${setup.datasetName}`,
1902
+ title: plan.title ?? `Create Preparation ${setup.preparationName}`,
2475
1903
  summary: plan.summary ?? "Save this source folder as an Interf Preparation.",
2476
- assistant_message: plan.assistant_message ?? actionAssistantMessage(actionType, setup.datasetName, commandPreview),
1904
+ assistant_message: plan.assistant_message ?? actionAssistantMessage(actionType, setup.preparationName, commandPreview),
2477
1905
  command_preview: commandPreview,
2478
1906
  message: request.message,
2479
- preparation: setup.datasetName,
2480
- method: setup.workflowId,
1907
+ preparation: setup.preparationName,
1908
+ method: setup.methodId,
2481
1909
  request: setup.request,
2482
1910
  created_at: now,
2483
1911
  updated_at: now,
@@ -2488,18 +1916,16 @@ export class LocalServiceRuntime {
2488
1916
  error: null,
2489
1917
  });
2490
1918
  }
2491
- const datasetConfig = this.resolveDatasetConfig(plan.preparation ?? request.preparation ?? this.defaultDatasetName());
2492
- const datasetPath = resolveSourceDatasetPath(this.rootPath, datasetConfig);
2493
- const requestedWorkflowId = stringValue(request.values, "method_id") ??
2494
- stringValue(request.values, "method") ??
2495
- stringValue(request.values, "workflow");
2496
- const plannedWorkflowId = plan.method ??
1919
+ const preparationConfig = this.resolvePreparationConfig(plan.preparation ?? request.preparation ?? this.defaultPreparationName());
1920
+ const preparationPath = resolveSourcePreparationPath(this.rootPath, preparationConfig);
1921
+ const requestedMethodId = stringValue(request.values, "method_id") ??
1922
+ stringValue(request.values, "method");
1923
+ const plannedMethodId = plan.method ??
2497
1924
  stringValue(plan.values, "method_id") ??
2498
- stringValue(plan.values, "method") ??
2499
- stringValue(plan.values, "workflow");
2500
- const workflowId = actionType === "method-authoring"
2501
- ? requestedWorkflowId ?? plannedWorkflowId ?? workflowIdForProposal(request.message, proposalValues)
2502
- : requestedWorkflowId ?? plannedWorkflowId ?? methodIdForSourcePreparationConfig(datasetConfig);
1925
+ stringValue(plan.values, "method");
1926
+ const methodId = actionType === "method-authoring"
1927
+ ? requestedMethodId ?? plannedMethodId ?? methodIdForProposal(request.message, proposalValues)
1928
+ : requestedMethodId ?? plannedMethodId ?? methodIdForSourcePreparationConfig(preparationConfig);
2503
1929
  const clarifyResolvedAction = (options) => ActionProposalResourceSchema.parse({
2504
1930
  kind: "interf-action-proposal",
2505
1931
  version: 1,
@@ -2510,8 +1936,8 @@ export class LocalServiceRuntime {
2510
1936
  summary: options.summary,
2511
1937
  assistant_message: options.assistantMessage,
2512
1938
  message: request.message,
2513
- preparation: datasetConfig.name,
2514
- method: workflowId ?? null,
1939
+ preparation: preparationConfig.name,
1940
+ method: methodId ?? null,
2515
1941
  request: {
2516
1942
  message: request.message,
2517
1943
  ...(proposalValues ? { values: proposalValues } : {}),
@@ -2526,65 +1952,65 @@ export class LocalServiceRuntime {
2526
1952
  });
2527
1953
  if (actionType === "test") {
2528
1954
  const requestedMode = testModeFromValues(proposalValues);
2529
- const hasReadinessChecks = (datasetConfig.checks ?? []).length > 0;
2530
- const portableContextReady = hasCompiledTestTarget(this.rootPath, datasetConfig);
1955
+ const hasReadinessChecks = (preparationConfig.checks ?? []).length > 0;
1956
+ const portableContextReady = hasCompiledTestTarget(this.rootPath, preparationConfig);
2531
1957
  if (!hasReadinessChecks) {
2532
1958
  return clarifyResolvedAction({
2533
- title: `Add readiness checks for ${datasetConfig.name}`,
1959
+ title: `Add readiness checks for ${preparationConfig.name}`,
2534
1960
  summary: "Readiness cannot be checked until this Preparation has saved checks.",
2535
- assistantMessage: `Preparation "${datasetConfig.name}" does not have saved readiness checks yet. Ask me to draft readiness checks after the Source Folder is prepared, or add readiness guidance first.`,
1961
+ assistantMessage: `Preparation "${preparationConfig.name}" does not have saved readiness checks yet. Ask me to draft readiness checks after the Source Folder is prepared, or add readiness guidance first.`,
2536
1962
  });
2537
1963
  }
2538
1964
  if (!portableContextReady && requestedMode !== "raw") {
2539
1965
  return clarifyResolvedAction({
2540
- title: `Prepare ${datasetConfig.name} first`,
1966
+ title: `Prepare ${preparationConfig.name} first`,
2541
1967
  summary: "Readiness checks need portable context unless you explicitly ask for a source-files-only baseline.",
2542
- assistantMessage: `Preparation "${datasetConfig.name}" has no prepared portable context yet. Prepare it first; after that Interf can check readiness. If you specifically want a source-files-only baseline, ask for source files only.`,
1968
+ assistantMessage: `Preparation "${preparationConfig.name}" has no prepared portable context yet. Prepare it first; after that Interf can check readiness. If you specifically want a source-files-only baseline, ask for source files only.`,
2543
1969
  });
2544
1970
  }
2545
1971
  }
2546
1972
  const actionRequest = (() => {
2547
1973
  if (actionType === "compile") {
2548
1974
  return {
2549
- preparation: datasetConfig.name,
2550
- ...(workflowId ? { method: workflowId } : {}),
1975
+ preparation: preparationConfig.name,
1976
+ ...(methodId ? { method: methodId } : {}),
2551
1977
  };
2552
1978
  }
2553
1979
  if (actionType === "test") {
2554
- const defaultMode = hasCompiledTestTarget(this.rootPath, datasetConfig) ? "both" : "raw";
1980
+ const defaultMode = hasCompiledTestTarget(this.rootPath, preparationConfig) ? "both" : "raw";
2555
1981
  return {
2556
- preparation: datasetConfig.name,
1982
+ preparation: preparationConfig.name,
2557
1983
  mode: testModeValue(proposalValues, defaultMode),
2558
1984
  };
2559
1985
  }
2560
1986
  if (actionType === "readiness-check-draft") {
2561
1987
  return {
2562
- preparation: datasetConfig.name,
2563
- source_folder_path: datasetPath,
2564
- about: stringValue(proposalValues, "about") ?? datasetConfig.about ?? request.message,
1988
+ preparation: preparationConfig.name,
1989
+ source_folder_path: preparationPath,
1990
+ about: stringValue(proposalValues, "about") ?? preparationConfig.about ?? request.message,
2565
1991
  target_count: Math.max(1, Math.min(8, Math.round(numberValue(proposalValues, "target_count") ?? 4))),
2566
1992
  };
2567
1993
  }
2568
1994
  return {
2569
- preparation: datasetConfig.name,
2570
- source_folder_path: datasetPath,
2571
- method_id: workflowId,
2572
- label: stringValue(proposalValues, "label") ?? `Custom ${datasetConfig.name}`,
1995
+ preparation: preparationConfig.name,
1996
+ source_folder_path: preparationPath,
1997
+ method_id: methodId,
1998
+ label: stringValue(proposalValues, "label") ?? `Custom ${preparationConfig.name}`,
2573
1999
  hint: stringValue(proposalValues, "hint") ?? request.message,
2574
2000
  task_prompt: actionValueMethodTaskPrompt(proposalValues) ?? stringValue(proposalValues, "task_prompt") ?? request.message,
2575
- checks: datasetConfig.checks ?? [],
2001
+ checks: preparationConfig.checks ?? [],
2576
2002
  };
2577
2003
  })();
2578
2004
  const title = (() => {
2579
2005
  if (plan.title)
2580
2006
  return plan.title;
2581
2007
  if (actionType === "compile")
2582
- return `Prepare ${datasetConfig.name}`;
2008
+ return `Prepare ${preparationConfig.name}`;
2583
2009
  if (actionType === "test")
2584
- return `Check readiness for ${datasetConfig.name}`;
2010
+ return `Check readiness for ${preparationConfig.name}`;
2585
2011
  if (actionType === "readiness-check-draft")
2586
- return `Draft readiness checks for ${datasetConfig.name}`;
2587
- return `Draft Method ${workflowId}`;
2012
+ return `Draft readiness checks for ${preparationConfig.name}`;
2013
+ return `Draft Method ${methodId}`;
2588
2014
  })();
2589
2015
  const summary = (() => {
2590
2016
  if (plan.summary)
@@ -2600,7 +2026,7 @@ export class LocalServiceRuntime {
2600
2026
  const previewValues = actionType === "test"
2601
2027
  ? { mode: actionRequest.mode }
2602
2028
  : proposalValues;
2603
- const commandPreview = plan.command_preview ?? actionCommandPreview(actionType, datasetConfig.name, workflowId, previewValues);
2029
+ const commandPreview = plan.command_preview ?? actionCommandPreview(actionType, preparationConfig.name, methodId, previewValues);
2604
2030
  return ActionProposalResourceSchema.parse({
2605
2031
  kind: "interf-action-proposal",
2606
2032
  version: 1,
@@ -2609,11 +2035,11 @@ export class LocalServiceRuntime {
2609
2035
  action_type: actionType,
2610
2036
  title,
2611
2037
  summary,
2612
- assistant_message: plan.assistant_message ?? actionAssistantMessage(actionType, datasetConfig.name, commandPreview),
2038
+ assistant_message: plan.assistant_message ?? actionAssistantMessage(actionType, preparationConfig.name, commandPreview),
2613
2039
  command_preview: commandPreview,
2614
2040
  message: request.message,
2615
- preparation: datasetConfig.name,
2616
- method: workflowId,
2041
+ preparation: preparationConfig.name,
2042
+ method: methodId,
2617
2043
  request: actionRequest,
2618
2044
  created_at: now,
2619
2045
  updated_at: now,
@@ -2643,7 +2069,7 @@ export class LocalServiceRuntime {
2643
2069
  };
2644
2070
  }
2645
2071
  if (proposal.action_type === "preparation-setup") {
2646
- const job = await this.createDatasetSetupRun(proposal.request);
2072
+ const job = await this.createPreparationSetupRun(proposal.request);
2647
2073
  return {
2648
2074
  runId: job.run_id,
2649
2075
  runType: "job-run",
@@ -2656,29 +2082,29 @@ export class LocalServiceRuntime {
2656
2082
  runType: "job-run",
2657
2083
  };
2658
2084
  }
2659
- const job = await this.createWorkflowAuthoringRun(proposal.request);
2085
+ const job = await this.createMethodAuthoringRun(proposal.request);
2660
2086
  return {
2661
2087
  runId: job.run_id,
2662
2088
  runType: "job-run",
2663
2089
  };
2664
2090
  }
2665
- resolveDatasetConfig(datasetName, overrides = {}) {
2666
- const dataset = findSourceDatasetConfig(loadSourceFolderConfig(this.rootPath), datasetName);
2667
- if (!dataset) {
2668
- throw new Error(`Preparation "${datasetName}" is not saved in this control plane folder.`);
2091
+ resolvePreparationConfig(preparationName, overrides = {}) {
2092
+ const preparation = findSourcePreparationConfig(loadSourceFolderConfig(this.rootPath), preparationName);
2093
+ if (!preparation) {
2094
+ throw new Error(`Preparation "${preparationName}" is not saved in this control plane folder.`);
2669
2095
  }
2670
- const method = overrides.method ?? overrides.workflow ?? methodIdForSourcePreparationConfig(dataset) ?? undefined;
2096
+ const method = overrides.method ?? methodIdForSourcePreparationConfig(preparation) ?? undefined;
2671
2097
  return {
2672
- ...dataset,
2098
+ ...preparation,
2673
2099
  ...(method ? { method } : {}),
2674
2100
  ...(typeof overrides.max_attempts === "number" ? { max_attempts: overrides.max_attempts } : {}),
2675
2101
  ...(typeof overrides.max_loops === "number" ? { max_loops: overrides.max_loops } : {}),
2676
2102
  };
2677
2103
  }
2678
- ensureCompiledForRun(datasetConfig) {
2679
- const workflowId = methodIdForSourcePreparationConfig(datasetConfig) ?? "interf";
2680
- const compiledPath = ensurePortableContextScaffold(this.rootPath, datasetConfig.name, workflowId);
2681
- syncCompiledInterfConfigFromSourceDatasetConfig(compiledPath, datasetConfig);
2104
+ ensureCompiledForRun(preparationConfig) {
2105
+ const methodId = methodIdForSourcePreparationConfig(preparationConfig) ?? DEFAULT_METHOD_ID;
2106
+ const compiledPath = ensurePortableContextScaffold(this.rootPath, preparationConfig.name, methodId);
2107
+ syncCompiledInterfConfigFromSourcePreparationConfig(compiledPath, preparationConfig);
2682
2108
  return compiledPath;
2683
2109
  }
2684
2110
  readCompileRun(compiledPath, runId) {
@@ -2802,12 +2228,8 @@ export class LocalServiceRuntime {
2802
2228
  });
2803
2229
  }
2804
2230
  }
2805
- readLatestComparison(datasetName) {
2806
- const latestPath = datasetLatestTestStatePath(this.rootPath, datasetName);
2807
- if (!existsSync(latestPath))
2808
- return null;
2809
- const parsed = TestRunComparisonSchema.safeParse(readJsonFile(latestPath));
2810
- return parsed.success ? parsed.data : null;
2231
+ readLatestComparison(preparationName) {
2232
+ return readSavedReadinessCheckRun(this.rootPath, preparationName);
2811
2233
  }
2812
2234
  checksEvaluatedEvent(runId, comparison) {
2813
2235
  const target = comparison.compiled ?? comparison.raw;