@interf/compiler 0.9.1 → 0.9.4

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 (251) 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/0fgt_8knmicoz.js → dist/compiler-ui/_next/static/chunks/0d~8t0zm6545p.js} +15 -21
  44. package/dist/compiler-ui/_next/static/chunks/0xnel.ax9a.2c.css +3 -0
  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 +1 -1
  114. package/dist/packages/local-service/action-values.js +1 -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 +540 -974
  120. package/dist/packages/local-service/lib/schema.js +44 -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 +349 -913
  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/apps/compiler-ui/.next/static/chunks/13g~4mamjft.c.css +0 -3
  192. package/builtin-workflows/interf/improve/SKILL.md +0 -18
  193. package/dist/cli/commands/create-workflow-wizard.d.ts +0 -76
  194. package/dist/packages/project-model/compiled-paths.d.ts +0 -1
  195. package/dist/packages/project-model/compiled-paths.js +0 -1
  196. package/dist/packages/project-model/compiled-raw.d.ts +0 -1
  197. package/dist/packages/project-model/compiled-raw.js +0 -1
  198. package/dist/packages/project-model/compiled-reset.d.ts +0 -1
  199. package/dist/packages/project-model/compiled-reset.js +0 -1
  200. package/dist/packages/shared/index.d.ts +0 -7
  201. package/dist/packages/shared/index.js +0 -7
  202. package/dist/packages/shared/util.d.ts +0 -3
  203. package/dist/packages/shared/util.js +0 -3
  204. package/dist/packages/testing/test-matrices.d.ts +0 -90
  205. package/dist/packages/testing/test-matrices.js +0 -96
  206. package/dist/packages/workflow-authoring/index.d.ts +0 -4
  207. package/dist/packages/workflow-authoring/index.js +0 -4
  208. package/dist/packages/workflow-authoring/workflow-authoring.d.ts +0 -24
  209. package/dist/packages/workflow-authoring/workflow-authoring.js +0 -82
  210. package/dist/packages/workflow-authoring/workflow-edit-session.d.ts +0 -18
  211. package/dist/packages/workflow-authoring/workflow-edit-session.js +0 -91
  212. package/dist/packages/workflow-authoring/workflow-improvement.d.ts +0 -23
  213. package/dist/packages/workflow-package/index.d.ts +0 -11
  214. package/dist/packages/workflow-package/index.js +0 -11
  215. package/dist/packages/workflow-package/interf-workflow-package.d.ts +0 -31
  216. package/dist/packages/workflow-package/local-workflows.d.ts +0 -64
  217. package/dist/packages/workflow-package/local-workflows.js +0 -457
  218. package/dist/packages/workflow-package/workflow-definitions.d.ts +0 -82
  219. package/dist/packages/workflow-package/workflow-definitions.js +0 -211
  220. package/dist/packages/workflow-package/workflow-review-paths.d.ts +0 -10
  221. /package/{builtin-workflows/interf → builtin-methods/interf-default}/compile/stages/shape/SKILL.md +0 -0
  222. /package/{builtin-workflows/interf → builtin-methods/interf-default}/compile/stages/structure/SKILL.md +0 -0
  223. /package/{builtin-workflows/interf → builtin-methods/interf-default}/compile/stages/summarize/SKILL.md +0 -0
  224. /package/{builtin-workflows/interf → builtin-methods/interf-default}/use/query/SKILL.md +0 -0
  225. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/03~yq9q893hmn.js +0 -0
  226. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/06z~l3kwb891e.js +0 -0
  227. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/08g7lvje.te.u.js +0 -0
  228. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/08m7vf5asqlsm.js +0 -0
  229. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0_i-3_5l9t2qe.js +0 -0
  230. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0b-ywny_j0g~0.js +0 -0
  231. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0b52v41o1gixx.js +0 -0
  232. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0gpzgsv0w.q~m.js +0 -0
  233. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0ilwfezfvu6~-.js +0 -0
  234. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0n51hrfoufc7g.js +0 -0
  235. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0xxmf45eskdt~.css +0 -0
  236. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/0y5z3t-z1c8ks.js.map +0 -0
  237. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/14wtz~vq25~qq.js +0 -0
  238. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/turbopack-10e~t1yzi4svj.js +0 -0
  239. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/chunks/turbopack-worker-0sjn--fhq~1cg.js +0 -0
  240. /package/{apps/compiler-ui/.next/static/XWKL548yXD_UOG4ID9G3J → dist/compiler-ui/_next/static/j7pdoqWrl4YJrJUVnksbl}/_buildManifest.js +0 -0
  241. /package/{apps/compiler-ui/.next/static/XWKL548yXD_UOG4ID9G3J → dist/compiler-ui/_next/static/j7pdoqWrl4YJrJUVnksbl}/_clientMiddlewareManifest.js +0 -0
  242. /package/{apps/compiler-ui/.next/static/XWKL548yXD_UOG4ID9G3J → dist/compiler-ui/_next/static/j7pdoqWrl4YJrJUVnksbl}/_ssgManifest.js +0 -0
  243. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/media/GeistMono_Variable.p.17jn9btb_52pq.woff2 +0 -0
  244. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/media/Geist_Variable-s.p.0-te~ja_gpvcf.woff2 +0 -0
  245. /package/{apps/compiler-ui/.next → dist/compiler-ui/_next}/static/media/worker.102zas1s52_pf.js +0 -0
  246. /package/dist/packages/compiler/{workflow-primitives.d.ts → method-primitives.d.ts} +0 -0
  247. /package/dist/packages/compiler/{workflow-primitives.js → method-primitives.js} +0 -0
  248. /package/dist/packages/{workflow-authoring/lib/workflow-edit-utils.js → method-authoring/lib/method-edit-utils.js} +0 -0
  249. /package/dist/packages/{workflow-package → method-package}/lib/package-root.d.ts +0 -0
  250. /package/dist/packages/{workflow-package/workflow-stage-policy.d.ts → method-package/method-stage-policy.d.ts} +0 -0
  251. /package/dist/packages/{workflow-package/workflow-stage-policy.js → method-package/method-stage-policy.js} +0 -0
@@ -0,0 +1,592 @@
1
+ import { createRunEventTimestamp, } from "../execution/events.js";
2
+ import { RunObservabilityResourceSchema, } from "./lib/schema.js";
3
+ export function uniqueArtifacts(artifacts) {
4
+ const seen = new Set();
5
+ const result = [];
6
+ for (const artifact of artifacts) {
7
+ const key = `${artifact.role}:${artifact.stage_id ?? ""}:${artifact.path}`;
8
+ if (seen.has(key))
9
+ continue;
10
+ seen.add(key);
11
+ result.push(artifact);
12
+ }
13
+ return result;
14
+ }
15
+ function observableRunStatus(status) {
16
+ if (status === "queued" || status === "pending")
17
+ return "queued";
18
+ if (status === "running")
19
+ return "running";
20
+ if (status === "failed")
21
+ return "failed";
22
+ if (status === "cancelled")
23
+ return "cancelled";
24
+ return "succeeded";
25
+ }
26
+ function methodTraceRunStatus(status) {
27
+ if (status === "queued" || status === "pending")
28
+ return "pending";
29
+ if (status === "running")
30
+ return "running";
31
+ if (status === "failed")
32
+ return "failed";
33
+ if (status === "cancelled")
34
+ return "cancelled";
35
+ return "completed";
36
+ }
37
+ function safeMethodNamePart(value) {
38
+ return value
39
+ .replace(/[^a-zA-Z0-9._/-]+/g, "-")
40
+ .replace(/\/+/g, "/")
41
+ .replace(/^-+|-+$/g, "")
42
+ || "run";
43
+ }
44
+ function methodTraceName(runType, name) {
45
+ return `workflow//./interf/${runType}//${safeMethodNamePart(name)}`;
46
+ }
47
+ function methodStepName(runType, label) {
48
+ return `step//./interf/${runType}//${safeMethodNamePart(label)}`;
49
+ }
50
+ function structuredMethodError(message) {
51
+ return {
52
+ message: message || "Run failed.",
53
+ code: "INTERF_RUN_ERROR",
54
+ };
55
+ }
56
+ function traceEvent(runId, eventType, createdAt, index, eventData, correlationId) {
57
+ return {
58
+ runId,
59
+ eventId: `${runId}:event:${index}`,
60
+ eventType,
61
+ specVersion: 1,
62
+ createdAt: createdAt ?? createRunEventTimestamp(),
63
+ ...(correlationId ? { correlationId } : {}),
64
+ ...(eventData === undefined ? {} : { eventData }),
65
+ };
66
+ }
67
+ function traceStreamChunk(runId, index, createdAt, text, data) {
68
+ return {
69
+ streamId: `${runId}:events`,
70
+ chunkId: `${runId}:events:${index}`,
71
+ index,
72
+ createdAt: createdAt ?? createRunEventTimestamp(),
73
+ text,
74
+ ...(data === undefined ? {} : { data }),
75
+ };
76
+ }
77
+ function buildTraceStreamChunks(runId, events) {
78
+ return events.map((event, index) => traceStreamChunk(runId, index, event.timestamp, JSON.stringify({
79
+ time: event.timestamp ?? null,
80
+ type: event.type,
81
+ scope: event.stage_id ?? event.step_id ?? event.type,
82
+ message: event.message ?? event.summary ?? event.error ?? event.type,
83
+ }), event));
84
+ }
85
+ function proofChecksForCompileRun(run) {
86
+ return run.stages.flatMap((stage) => (stage.latest_proof?.checks ?? []).map((check) => ({
87
+ ...check,
88
+ detail: check.detail ?? `${stage.stage_label ?? stage.stage_id} / ${stage.status}`,
89
+ })));
90
+ }
91
+ function agentLabelForJob(job) {
92
+ return job.agent?.display_name ?? job.agent?.name ?? null;
93
+ }
94
+ function jobTypeLabelForMetric(type) {
95
+ if (type === "readiness-check-draft")
96
+ return "Readiness-check draft";
97
+ if (type === "method-authoring")
98
+ return "Method draft";
99
+ if (type === "method-improvement")
100
+ return "Method improvement";
101
+ if (type === "compile")
102
+ return "Compile";
103
+ if (type === "test")
104
+ return "Readiness check";
105
+ return "Local job";
106
+ }
107
+ function stageTracePayload(stage) {
108
+ return {
109
+ status: stage.status,
110
+ ...(stage.summary ? { summary: stage.summary } : {}),
111
+ ...(stage.artifacts.length > 0 ? { artifacts: stage.artifacts } : {}),
112
+ ...(stage.logs ? { logs: stage.logs } : {}),
113
+ ...(stage.latest_proof ? { proof: stage.latest_proof } : {}),
114
+ };
115
+ }
116
+ export function compileRunToObservability(run) {
117
+ const artifacts = uniqueArtifacts(run.stages.flatMap((stage) => stage.artifacts));
118
+ const proof = proofChecksForCompileRun(run);
119
+ const executor = run.stages.find((stage) => stage.executor)?.executor ?? null;
120
+ const traceStatus = methodTraceRunStatus(run.status);
121
+ const methodName = methodTraceName("compile", `Prepare ${run.preparation}`);
122
+ const completedAt = run.finished_at ?? (traceStatus === "completed" || traceStatus === "failed" || traceStatus === "cancelled"
123
+ ? run.started_at ?? run.created_at
124
+ : undefined);
125
+ let eventIndex = 0;
126
+ const events = [
127
+ traceEvent(run.run_id, "run_created", run.created_at, eventIndex++, {
128
+ deploymentId: "local-interf",
129
+ methodName,
130
+ input: {
131
+ kind: "compile",
132
+ preparation: run.preparation,
133
+ method: run.method,
134
+ source_path: run.source_path,
135
+ },
136
+ executionContext: {
137
+ backend: run.backend,
138
+ executor,
139
+ },
140
+ }),
141
+ ];
142
+ if (run.started_at) {
143
+ events.push(traceEvent(run.run_id, "run_started", run.started_at, eventIndex++, {
144
+ methodName,
145
+ input: {
146
+ preparation: run.preparation,
147
+ method: run.method,
148
+ },
149
+ executionContext: {
150
+ backend: run.backend,
151
+ executor,
152
+ },
153
+ }));
154
+ }
155
+ for (const stage of run.stages) {
156
+ if (stage.status === "queued")
157
+ continue;
158
+ const stepName = methodStepName("compile", stage.stage_label ?? stage.stage_id);
159
+ const stepCreatedAt = stage.started_at ?? run.started_at ?? run.created_at;
160
+ const stepStartedAt = stage.started_at ?? stepCreatedAt;
161
+ const stepCompletedAt = stage.finished_at ?? run.finished_at ?? completedAt ?? stepCreatedAt;
162
+ events.push(traceEvent(run.run_id, "step_created", stepCreatedAt, eventIndex++, {
163
+ stepName,
164
+ input: {
165
+ stage_id: stage.stage_id,
166
+ stage_label: stage.stage_label ?? null,
167
+ stage_index: stage.stage_index ?? null,
168
+ stage_total: stage.stage_total ?? null,
169
+ reads: stage.contract?.reads ?? [],
170
+ writes: stage.contract?.writes ?? [],
171
+ acceptance: stage.contract?.acceptance ?? null,
172
+ executor: stage.executor ?? null,
173
+ },
174
+ }, stage.stage_id));
175
+ events.push(traceEvent(run.run_id, "step_started", stepStartedAt, eventIndex++, {
176
+ attempt: 1,
177
+ }, stage.stage_id));
178
+ if (stage.status === "failed") {
179
+ events.push(traceEvent(run.run_id, "step_failed", stepCompletedAt, eventIndex++, {
180
+ error: structuredMethodError(stage.failure ?? stage.summary),
181
+ output: stageTracePayload(stage),
182
+ }, stage.stage_id));
183
+ }
184
+ else if (stage.status === "succeeded") {
185
+ events.push(traceEvent(run.run_id, "step_completed", stepCompletedAt, eventIndex++, {
186
+ result: stageTracePayload(stage),
187
+ }, stage.stage_id));
188
+ }
189
+ }
190
+ if (traceStatus === "completed") {
191
+ events.push(traceEvent(run.run_id, "run_completed", completedAt, eventIndex++, {
192
+ output: {
193
+ portable_context_path: run.portable_context_path,
194
+ artifacts,
195
+ proof,
196
+ latest_proof: run.latest_proof ?? null,
197
+ },
198
+ }));
199
+ }
200
+ else if (traceStatus === "failed") {
201
+ events.push(traceEvent(run.run_id, "run_failed", completedAt, eventIndex++, {
202
+ error: structuredMethodError(run.stages.find((stage) => stage.failure)?.failure ?? run.latest_proof?.summary),
203
+ }));
204
+ }
205
+ else if (traceStatus === "cancelled") {
206
+ events.push(traceEvent(run.run_id, "run_cancelled", completedAt, eventIndex++));
207
+ }
208
+ return RunObservabilityResourceSchema.parse({
209
+ kind: "interf-run-observability",
210
+ version: 1,
211
+ run_id: run.run_id,
212
+ run_type: "compile",
213
+ title: `Prepare ${run.preparation}`,
214
+ status: observableRunStatus(run.status),
215
+ preparation: run.preparation,
216
+ method: run.method,
217
+ source_path: run.source_path,
218
+ output_path: run.portable_context_path,
219
+ executor,
220
+ agent_label: executor?.display_name ?? run.backend,
221
+ created_at: run.created_at,
222
+ started_at: run.started_at ?? null,
223
+ finished_at: run.finished_at ?? null,
224
+ metrics: [
225
+ { label: "Preparation", value: run.preparation },
226
+ { label: "Method", value: run.method },
227
+ { label: "Executor", value: executor?.display_name ?? run.backend },
228
+ { label: "Stages", value: `${run.stages.filter((stage) => stage.status === "succeeded").length}/${run.stages.length}` },
229
+ { label: "Proof", value: `${proof.filter((check) => check.ok).length}/${proof.length}` },
230
+ { label: "Artifacts", value: String(artifacts.length) },
231
+ ],
232
+ artifacts,
233
+ proof,
234
+ trace: {
235
+ run: {
236
+ runId: run.run_id,
237
+ status: traceStatus,
238
+ deploymentId: "local-interf",
239
+ methodName,
240
+ specVersion: 1,
241
+ executionContext: {
242
+ product: "Interf",
243
+ run_type: "compile",
244
+ preparation: run.preparation,
245
+ method: run.method,
246
+ backend: run.backend,
247
+ executor,
248
+ },
249
+ input: {
250
+ preparation: run.preparation,
251
+ method: run.method,
252
+ source_path: run.source_path,
253
+ },
254
+ ...(traceStatus === "completed"
255
+ ? {
256
+ output: {
257
+ portable_context_path: run.portable_context_path,
258
+ artifacts,
259
+ proof,
260
+ },
261
+ }
262
+ : {}),
263
+ ...(traceStatus === "failed" ? { error: structuredMethodError(run.stages.find((stage) => stage.failure)?.failure) } : {}),
264
+ ...(run.started_at ? { startedAt: run.started_at } : {}),
265
+ ...(completedAt ? { completedAt } : {}),
266
+ createdAt: run.created_at,
267
+ updatedAt: completedAt ?? run.started_at ?? run.created_at,
268
+ },
269
+ events,
270
+ streams: buildTraceStreamChunks(run.run_id, run.events),
271
+ },
272
+ });
273
+ }
274
+ export function testRunToObservability(run) {
275
+ const traceStatus = methodTraceRunStatus(run.status);
276
+ const title = `Check readiness ${run.preparation}`;
277
+ const methodName = methodTraceName("test", title);
278
+ const completedAt = run.finished_at ?? (traceStatus === "completed" || traceStatus === "failed" || traceStatus === "cancelled"
279
+ ? run.started_at ?? new Date().toISOString()
280
+ : undefined);
281
+ const raw = run.comparison?.raw ?? null;
282
+ const compiled = run.comparison?.compiled ?? null;
283
+ const proofCandidates = [
284
+ raw
285
+ ? {
286
+ id: `${run.run_id}-source-files`,
287
+ label: "source files baseline",
288
+ ok: raw.ok ?? raw.passed_cases === raw.total_cases,
289
+ detail: `${raw.passed_cases}/${raw.total_cases} checks`,
290
+ }
291
+ : null,
292
+ compiled
293
+ ? {
294
+ id: `${run.run_id}-portable-context`,
295
+ label: "portable context",
296
+ ok: compiled.ok ?? compiled.passed_cases === compiled.total_cases,
297
+ detail: `${compiled.passed_cases}/${compiled.total_cases} checks`,
298
+ }
299
+ : null,
300
+ ];
301
+ const proof = proofCandidates.filter((value) => value !== null);
302
+ const artifacts = uniqueArtifacts([
303
+ ...(raw?.run_path ? [{ path: raw.run_path, role: "test", label: "source files readiness run" }] : []),
304
+ ...(compiled?.run_path ? [{ path: compiled.run_path, role: "test", label: "portable context readiness run" }] : []),
305
+ ]);
306
+ let eventIndex = 0;
307
+ const events = [
308
+ traceEvent(run.run_id, "run_created", run.started_at, eventIndex++, {
309
+ deploymentId: "local-interf",
310
+ methodName,
311
+ input: {
312
+ kind: "test",
313
+ preparation: run.preparation,
314
+ mode: run.mode,
315
+ },
316
+ }),
317
+ ];
318
+ if (run.started_at) {
319
+ events.push(traceEvent(run.run_id, "run_started", run.started_at, eventIndex++, {
320
+ methodName,
321
+ input: {
322
+ preparation: run.preparation,
323
+ mode: run.mode,
324
+ },
325
+ }));
326
+ }
327
+ const targetStepCandidates = [
328
+ raw
329
+ ? {
330
+ id: "source-files-baseline",
331
+ label: "Source files baseline",
332
+ status: raw.ok ?? raw.passed_cases === raw.total_cases ? "succeeded" : "failed",
333
+ input: raw.target ?? { type: "source-files", path: run.source_path ?? null },
334
+ output: raw,
335
+ }
336
+ : null,
337
+ compiled
338
+ ? {
339
+ id: "portable-context-check",
340
+ label: "Portable context",
341
+ status: compiled.ok ?? compiled.passed_cases === compiled.total_cases ? "succeeded" : "failed",
342
+ input: compiled.target ?? { type: "portable-context", path: run.portable_context_path ?? null },
343
+ output: compiled,
344
+ }
345
+ : null,
346
+ ];
347
+ const targetSteps = targetStepCandidates.filter((value) => value !== null);
348
+ if (targetSteps.length === 0) {
349
+ targetSteps.push({
350
+ id: "check-readiness",
351
+ label: "Run readiness checks",
352
+ status: run.status === "failed" ? "failed" : "succeeded",
353
+ input: {
354
+ preparation: run.preparation,
355
+ mode: run.mode,
356
+ },
357
+ output: run.comparison ?? null,
358
+ });
359
+ }
360
+ for (const step of targetSteps) {
361
+ const timestamp = run.started_at ?? run.finished_at ?? new Date().toISOString();
362
+ events.push(traceEvent(run.run_id, "step_created", timestamp, eventIndex++, {
363
+ stepName: methodStepName("test", step.label),
364
+ input: step.input,
365
+ }, step.id));
366
+ events.push(traceEvent(run.run_id, "step_started", timestamp, eventIndex++, {
367
+ attempt: 1,
368
+ }, step.id));
369
+ events.push(traceEvent(run.run_id, step.status === "failed" ? "step_failed" : "step_completed", run.finished_at ?? timestamp, eventIndex++, step.status === "failed"
370
+ ? { error: structuredMethodError(run.error ?? `${step.label} did not pass.`), output: step.output }
371
+ : { result: step.output }, step.id));
372
+ }
373
+ if (traceStatus === "completed") {
374
+ events.push(traceEvent(run.run_id, "run_completed", completedAt, eventIndex++, {
375
+ output: {
376
+ comparison: run.comparison,
377
+ proof,
378
+ },
379
+ }));
380
+ }
381
+ else if (traceStatus === "failed") {
382
+ events.push(traceEvent(run.run_id, "run_failed", completedAt, eventIndex++, {
383
+ error: structuredMethodError(run.error),
384
+ }));
385
+ }
386
+ else if (traceStatus === "cancelled") {
387
+ events.push(traceEvent(run.run_id, "run_cancelled", completedAt, eventIndex++));
388
+ }
389
+ return RunObservabilityResourceSchema.parse({
390
+ kind: "interf-run-observability",
391
+ version: 1,
392
+ run_id: run.run_id,
393
+ run_type: "test",
394
+ title,
395
+ status: observableRunStatus(run.status),
396
+ preparation: run.preparation,
397
+ method: compiled?.target?.method ?? null,
398
+ source_path: run.source_path ?? null,
399
+ output_path: run.portable_context_path ?? null,
400
+ created_at: run.started_at ?? completedAt ?? new Date().toISOString(),
401
+ started_at: run.started_at ?? null,
402
+ finished_at: run.finished_at ?? null,
403
+ metrics: [
404
+ { label: "Preparation", value: run.preparation },
405
+ { label: "Mode", value: run.mode },
406
+ { label: "Readiness checks", value: compiled ? `${compiled.passed_cases}/${compiled.total_cases}` : raw ? `${raw.passed_cases}/${raw.total_cases}` : "0/0" },
407
+ { label: "Source files", value: raw ? `${raw.passed_cases}/${raw.total_cases}` : "-" },
408
+ { label: "Portable context", value: compiled ? `${compiled.passed_cases}/${compiled.total_cases}` : "-" },
409
+ ],
410
+ artifacts,
411
+ proof,
412
+ trace: {
413
+ run: {
414
+ runId: run.run_id,
415
+ status: traceStatus,
416
+ deploymentId: "local-interf",
417
+ methodName,
418
+ specVersion: 1,
419
+ executionContext: {
420
+ product: "Interf",
421
+ run_type: "test",
422
+ preparation: run.preparation,
423
+ mode: run.mode,
424
+ },
425
+ input: {
426
+ preparation: run.preparation,
427
+ mode: run.mode,
428
+ source_path: run.source_path ?? null,
429
+ portable_context_path: run.portable_context_path ?? null,
430
+ },
431
+ ...(traceStatus === "completed" ? { output: { comparison: run.comparison, proof } } : {}),
432
+ ...(traceStatus === "failed" ? { error: structuredMethodError(run.error) } : {}),
433
+ ...(run.started_at ? { startedAt: run.started_at } : {}),
434
+ ...(completedAt ? { completedAt } : {}),
435
+ createdAt: run.started_at ?? completedAt ?? new Date().toISOString(),
436
+ updatedAt: completedAt ?? run.started_at ?? new Date().toISOString(),
437
+ },
438
+ events,
439
+ streams: buildTraceStreamChunks(run.run_id, run.events ?? []),
440
+ },
441
+ });
442
+ }
443
+ export function jobRunToObservability(job) {
444
+ const runType = (job.job_type === "preparation-setup" ||
445
+ job.job_type === "readiness-check-draft" ||
446
+ job.job_type === "method-authoring" ||
447
+ job.job_type === "method-improvement"
448
+ ? job.job_type
449
+ : "job");
450
+ const executor = job.agent
451
+ ? {
452
+ kind: "local-agent",
453
+ name: job.agent.name,
454
+ display_name: job.agent.display_name,
455
+ command: job.agent.command ?? null,
456
+ }
457
+ : null;
458
+ const traceStatus = methodTraceRunStatus(job.status);
459
+ const methodName = methodTraceName(runType, job.title);
460
+ const completedAt = job.finished_at ?? (traceStatus === "completed" || traceStatus === "failed" || traceStatus === "cancelled"
461
+ ? job.started_at ?? job.created_at
462
+ : undefined);
463
+ let eventIndex = 0;
464
+ const events = [
465
+ traceEvent(job.run_id, "run_created", job.created_at, eventIndex++, {
466
+ deploymentId: "local-interf",
467
+ methodName,
468
+ input: {
469
+ job_type: job.job_type,
470
+ preparation: job.preparation ?? null,
471
+ method: job.method ?? null,
472
+ },
473
+ executionContext: {
474
+ executor,
475
+ },
476
+ }),
477
+ ];
478
+ if (job.started_at) {
479
+ events.push(traceEvent(job.run_id, "run_started", job.started_at, eventIndex++, {
480
+ methodName,
481
+ input: {
482
+ job_type: job.job_type,
483
+ preparation: job.preparation ?? null,
484
+ },
485
+ executionContext: {
486
+ executor,
487
+ },
488
+ }));
489
+ }
490
+ for (const step of job.steps) {
491
+ const timestamp = step.started_at ?? job.started_at ?? job.created_at;
492
+ events.push(traceEvent(job.run_id, "step_created", timestamp, eventIndex++, {
493
+ stepName: methodStepName(runType, step.label),
494
+ input: step.input ?? {
495
+ step_id: step.id,
496
+ label: step.label,
497
+ },
498
+ }, step.id));
499
+ if (step.started_at || step.status !== "queued") {
500
+ events.push(traceEvent(job.run_id, "step_started", step.started_at ?? timestamp, eventIndex++, {
501
+ attempt: 1,
502
+ }, step.id));
503
+ }
504
+ if (step.status === "failed") {
505
+ events.push(traceEvent(job.run_id, "step_failed", step.finished_at ?? completedAt ?? timestamp, eventIndex++, {
506
+ error: structuredMethodError(step.summary ?? job.error),
507
+ output: step.output ?? null,
508
+ }, step.id));
509
+ }
510
+ else if (step.status === "succeeded") {
511
+ events.push(traceEvent(job.run_id, "step_completed", step.finished_at ?? completedAt ?? timestamp, eventIndex++, {
512
+ result: step.output ?? {
513
+ summary: step.summary ?? null,
514
+ },
515
+ }, step.id));
516
+ }
517
+ }
518
+ if (traceStatus === "completed") {
519
+ events.push(traceEvent(job.run_id, "run_completed", completedAt, eventIndex++, {
520
+ output: job.result ?? {
521
+ output_path: job.output_path ?? null,
522
+ },
523
+ }));
524
+ }
525
+ else if (traceStatus === "failed") {
526
+ events.push(traceEvent(job.run_id, "run_failed", completedAt, eventIndex++, {
527
+ error: structuredMethodError(job.error),
528
+ }));
529
+ }
530
+ else if (traceStatus === "cancelled") {
531
+ events.push(traceEvent(job.run_id, "run_cancelled", completedAt, eventIndex++));
532
+ }
533
+ const outputPath = job.output_path ?? (typeof job.result?.path === "string" ? job.result.path : null);
534
+ const artifacts = uniqueArtifacts(outputPath ? [{ path: outputPath, role: "output" }] : []);
535
+ return RunObservabilityResourceSchema.parse({
536
+ kind: "interf-run-observability",
537
+ version: 1,
538
+ run_id: job.run_id,
539
+ run_type: runType,
540
+ title: job.title,
541
+ status: observableRunStatus(job.status),
542
+ preparation: job.preparation ?? null,
543
+ method: job.method ?? null,
544
+ source_path: job.source_path ?? null,
545
+ output_path: outputPath,
546
+ executor,
547
+ agent_label: agentLabelForJob(job),
548
+ created_at: job.created_at,
549
+ started_at: job.started_at ?? null,
550
+ finished_at: job.finished_at ?? null,
551
+ metrics: [
552
+ { label: "Kind", value: jobTypeLabelForMetric(job.job_type) },
553
+ { label: "Executor", value: agentLabelForJob(job) ?? "local executor" },
554
+ { label: "Phases", value: `${job.steps.filter((step) => step.status === "succeeded").length}/${job.steps.length}` },
555
+ { label: "Preparation", value: job.preparation ?? "-" },
556
+ { label: "Method", value: job.method ?? "-" },
557
+ ],
558
+ artifacts,
559
+ proof: [],
560
+ trace: {
561
+ run: {
562
+ runId: job.run_id,
563
+ status: traceStatus,
564
+ deploymentId: "local-interf",
565
+ methodName,
566
+ specVersion: 1,
567
+ executionContext: {
568
+ product: "Interf",
569
+ run_type: runType,
570
+ job_type: job.job_type,
571
+ preparation: job.preparation ?? null,
572
+ method: job.method ?? null,
573
+ executor,
574
+ },
575
+ input: {
576
+ job_type: job.job_type,
577
+ preparation: job.preparation ?? null,
578
+ method: job.method ?? null,
579
+ source_path: job.source_path ?? null,
580
+ },
581
+ ...(traceStatus === "completed" ? { output: job.result ?? { output_path: outputPath } } : {}),
582
+ ...(traceStatus === "failed" ? { error: structuredMethodError(job.error) } : {}),
583
+ ...(job.started_at ? { startedAt: job.started_at } : {}),
584
+ ...(completedAt ? { completedAt } : {}),
585
+ createdAt: job.created_at,
586
+ updatedAt: completedAt ?? job.started_at ?? job.created_at,
587
+ },
588
+ events,
589
+ streams: buildTraceStreamChunks(job.run_id, job.events),
590
+ },
591
+ });
592
+ }