@interf/compiler 0.9.4 → 0.13.0

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 (222) hide show
  1. package/README.md +96 -91
  2. package/TRADEMARKS.md +2 -13
  3. package/agent-skills/interf-actions/SKILL.md +97 -32
  4. package/agent-skills/interf-actions/references/cli.md +124 -71
  5. package/builtin-methods/interf-default/README.md +3 -4
  6. package/builtin-methods/interf-default/compile/stages/shape/SKILL.md +2 -2
  7. package/builtin-methods/interf-default/compile/stages/summarize/SKILL.md +2 -1
  8. package/builtin-methods/interf-default/improve/SKILL.md +1 -1
  9. package/builtin-methods/interf-default/method.json +10 -4
  10. package/builtin-methods/interf-default/method.schema.json +0 -9
  11. package/builtin-methods/interf-default/use/query/SKILL.md +5 -5
  12. package/dist/cli/commands/compile.d.ts +9 -31
  13. package/dist/cli/commands/compile.js +75 -388
  14. package/dist/cli/commands/doctor.js +1 -1
  15. package/dist/cli/commands/login.d.ts +7 -0
  16. package/dist/cli/commands/login.js +39 -0
  17. package/dist/cli/commands/logout.d.ts +2 -0
  18. package/dist/cli/commands/logout.js +16 -0
  19. package/dist/cli/commands/method.d.ts +2 -0
  20. package/dist/cli/commands/method.js +113 -0
  21. package/dist/cli/commands/prep.d.ts +2 -0
  22. package/dist/cli/commands/prep.js +134 -0
  23. package/dist/cli/commands/reset.d.ts +8 -1
  24. package/dist/cli/commands/reset.js +47 -15
  25. package/dist/cli/commands/runs.d.ts +2 -0
  26. package/dist/cli/commands/runs.js +120 -0
  27. package/dist/cli/commands/status.d.ts +6 -1
  28. package/dist/cli/commands/status.js +61 -220
  29. package/dist/cli/commands/test.d.ts +6 -15
  30. package/dist/cli/commands/test.js +63 -342
  31. package/dist/cli/commands/web.d.ts +0 -9
  32. package/dist/cli/commands/web.js +140 -367
  33. package/dist/cli/commands/wizard.d.ts +9 -0
  34. package/dist/cli/commands/wizard.js +442 -0
  35. package/dist/cli/index.d.ts +7 -6
  36. package/dist/cli/index.js +13 -10
  37. package/dist/compiler-ui/404.html +1 -1
  38. package/dist/compiler-ui/__next.__PAGE__.txt +2 -2
  39. package/dist/compiler-ui/__next._full.txt +3 -3
  40. package/dist/compiler-ui/__next._head.txt +1 -1
  41. package/dist/compiler-ui/__next._index.txt +2 -2
  42. package/dist/compiler-ui/__next._tree.txt +2 -2
  43. package/dist/compiler-ui/_next/static/chunks/045gole2ojo3g.css +3 -0
  44. package/dist/compiler-ui/_next/static/chunks/17t-lulmyawg5.js +89 -0
  45. package/dist/compiler-ui/_not-found/__next._full.txt +2 -2
  46. package/dist/compiler-ui/_not-found/__next._head.txt +1 -1
  47. package/dist/compiler-ui/_not-found/__next._index.txt +2 -2
  48. package/dist/compiler-ui/_not-found/__next._not-found.__PAGE__.txt +1 -1
  49. package/dist/compiler-ui/_not-found/__next._not-found.txt +1 -1
  50. package/dist/compiler-ui/_not-found/__next._tree.txt +2 -2
  51. package/dist/compiler-ui/_not-found.html +1 -1
  52. package/dist/compiler-ui/_not-found.txt +2 -2
  53. package/dist/compiler-ui/index.html +1 -1
  54. package/dist/compiler-ui/index.txt +3 -3
  55. package/dist/index.d.ts +0 -23
  56. package/dist/index.js +0 -16
  57. package/dist/packages/agents/lib/shells.d.ts +1 -1
  58. package/dist/packages/agents/lib/shells.js +113 -54
  59. package/dist/packages/agents/lib/user-config.d.ts +4 -2
  60. package/dist/packages/agents/lib/user-config.js +15 -7
  61. package/dist/packages/compiler/compiled-paths.d.ts +9 -2
  62. package/dist/packages/compiler/compiled-paths.js +30 -15
  63. package/dist/packages/compiler/compiled-pipeline.js +23 -3
  64. package/dist/packages/compiler/compiled-stage-plan.js +4 -0
  65. package/dist/packages/compiler/compiled-target.d.ts +1 -1
  66. package/dist/packages/compiler/compiled-target.js +1 -1
  67. package/dist/packages/compiler/index.d.ts +1 -0
  68. package/dist/packages/compiler/index.js +1 -0
  69. package/dist/packages/compiler/lib/schema.d.ts +27 -32
  70. package/dist/packages/compiler/lib/schema.js +2 -13
  71. package/dist/packages/compiler/method-runs.d.ts +2 -3
  72. package/dist/packages/compiler/method-runs.js +2 -3
  73. package/dist/packages/compiler/reset.js +3 -1
  74. package/dist/packages/compiler/runtime-contracts.js +0 -3
  75. package/dist/packages/compiler/runtime-prompt.js +1 -1
  76. package/dist/packages/compiler/source-files.d.ts +46 -0
  77. package/dist/packages/compiler/source-files.js +149 -0
  78. package/dist/packages/compiler/state-artifacts.d.ts +3 -2
  79. package/dist/packages/compiler/state-artifacts.js +4 -3
  80. package/dist/packages/compiler/state-io.d.ts +3 -2
  81. package/dist/packages/compiler/state-io.js +11 -5
  82. package/dist/packages/compiler/state-paths.d.ts +2 -1
  83. package/dist/packages/compiler/state-paths.js +6 -3
  84. package/dist/packages/compiler/state-view.d.ts +3 -2
  85. package/dist/packages/compiler/state-view.js +18 -28
  86. package/dist/packages/compiler/state.d.ts +4 -4
  87. package/dist/packages/compiler/state.js +3 -3
  88. package/dist/packages/contracts/index.d.ts +1 -1
  89. package/dist/packages/contracts/lib/preparation-paths.d.ts +117 -0
  90. package/dist/packages/contracts/lib/preparation-paths.js +177 -0
  91. package/dist/packages/contracts/lib/schema.d.ts +85 -6
  92. package/dist/packages/contracts/lib/schema.js +46 -2
  93. package/dist/packages/execution/lib/schema.d.ts +50 -57
  94. package/dist/packages/execution/lib/schema.js +1 -2
  95. package/dist/packages/local-service/action-definitions.d.ts +246 -0
  96. package/dist/packages/local-service/action-definitions.js +1147 -0
  97. package/dist/packages/local-service/action-planner.d.ts +9 -0
  98. package/dist/packages/local-service/action-planner.js +135 -0
  99. package/dist/packages/local-service/action-values.d.ts +1 -23
  100. package/dist/packages/local-service/action-values.js +1 -31
  101. package/dist/packages/local-service/client.d.ts +76 -46
  102. package/dist/packages/local-service/client.js +184 -149
  103. package/dist/packages/local-service/connection-config.d.ts +38 -0
  104. package/dist/packages/local-service/connection-config.js +75 -0
  105. package/dist/packages/local-service/index.d.ts +14 -7
  106. package/dist/packages/local-service/index.js +8 -4
  107. package/dist/packages/local-service/instance-paths.d.ts +100 -0
  108. package/dist/packages/local-service/instance-paths.js +165 -0
  109. package/dist/packages/local-service/lib/schema.d.ts +689 -2575
  110. package/dist/packages/local-service/lib/schema.js +260 -101
  111. package/dist/packages/local-service/native-run-handlers.d.ts +23 -0
  112. package/dist/{cli/commands/compile-controller.js → packages/local-service/native-run-handlers.js} +204 -20
  113. package/dist/packages/local-service/preparation-store.d.ts +92 -0
  114. package/dist/packages/local-service/preparation-store.js +171 -0
  115. package/dist/{cli/commands/check-draft.d.ts → packages/local-service/readiness-check-draft.d.ts} +2 -2
  116. package/dist/packages/local-service/routes.d.ts +33 -11
  117. package/dist/packages/local-service/routes.js +44 -15
  118. package/dist/packages/local-service/run-observability.js +25 -27
  119. package/dist/packages/local-service/runtime-caches.d.ts +76 -0
  120. package/dist/packages/local-service/runtime-caches.js +191 -0
  121. package/dist/packages/local-service/runtime-event-applier.d.ts +12 -0
  122. package/dist/packages/local-service/runtime-event-applier.js +177 -0
  123. package/dist/packages/local-service/runtime-persistence.d.ts +47 -0
  124. package/dist/packages/local-service/runtime-persistence.js +137 -0
  125. package/dist/packages/local-service/runtime-proposal-helpers.d.ts +35 -0
  126. package/dist/packages/local-service/runtime-proposal-helpers.js +251 -0
  127. package/dist/packages/local-service/runtime-resource-builders.d.ts +52 -0
  128. package/dist/packages/local-service/runtime-resource-builders.js +149 -0
  129. package/dist/packages/local-service/runtime.d.ts +201 -44
  130. package/dist/packages/local-service/runtime.js +1062 -1106
  131. package/dist/packages/local-service/server.d.ts +15 -0
  132. package/dist/packages/local-service/server.js +651 -233
  133. package/dist/packages/local-service/service-registry.d.ts +47 -0
  134. package/dist/packages/local-service/service-registry.js +137 -0
  135. package/dist/packages/method-authoring/method-authoring.d.ts +1 -1
  136. package/dist/packages/method-authoring/method-authoring.js +2 -2
  137. package/dist/packages/method-authoring/method-improvement.js +1 -1
  138. package/dist/packages/method-package/builtin-compiled-method.d.ts +4 -5
  139. package/dist/packages/method-package/builtin-compiled-method.js +8 -14
  140. package/dist/packages/method-package/context-interface.d.ts +4 -40
  141. package/dist/packages/method-package/context-interface.js +1 -23
  142. package/dist/packages/method-package/interf-method-package.d.ts +4 -4
  143. package/dist/packages/method-package/interf-method-package.js +21 -33
  144. package/dist/packages/method-package/local-methods.d.ts +10 -6
  145. package/dist/packages/method-package/local-methods.js +57 -39
  146. package/dist/packages/method-package/method-definitions.d.ts +8 -34
  147. package/dist/packages/method-package/method-definitions.js +49 -37
  148. package/dist/packages/method-package/method-helpers.d.ts +1 -13
  149. package/dist/packages/method-package/method-helpers.js +8 -42
  150. package/dist/packages/method-package/method-review-paths.d.ts +1 -1
  151. package/dist/packages/method-package/method-review-paths.js +5 -5
  152. package/dist/packages/method-package/method-stage-runner.js +2 -2
  153. package/dist/packages/method-package/user-methods.d.ts +17 -0
  154. package/dist/packages/method-package/user-methods.js +77 -0
  155. package/dist/packages/project-model/index.d.ts +1 -1
  156. package/dist/packages/project-model/index.js +1 -1
  157. package/dist/packages/project-model/interf-detect.d.ts +8 -3
  158. package/dist/packages/project-model/interf-detect.js +34 -34
  159. package/dist/packages/project-model/interf-scaffold.d.ts +3 -3
  160. package/dist/packages/project-model/interf-scaffold.js +23 -32
  161. package/dist/packages/project-model/lib/schema.js +38 -1
  162. package/dist/packages/project-model/preparation-entries.d.ts +11 -0
  163. package/dist/packages/project-model/preparation-entries.js +49 -0
  164. package/dist/packages/project-model/source-config.d.ts +11 -10
  165. package/dist/packages/project-model/source-config.js +83 -44
  166. package/dist/packages/project-model/source-folders.d.ts +5 -5
  167. package/dist/packages/project-model/source-folders.js +14 -14
  168. package/dist/packages/shared/filesystem.d.ts +7 -0
  169. package/dist/packages/shared/filesystem.js +97 -10
  170. package/dist/packages/testing/lib/schema.d.ts +12 -13
  171. package/dist/packages/testing/lib/schema.js +4 -5
  172. package/dist/packages/testing/readiness-check-run.d.ts +7 -7
  173. package/dist/packages/testing/readiness-check-run.js +46 -51
  174. package/dist/packages/testing/test-execution.js +6 -6
  175. package/dist/packages/testing/test-paths.js +4 -3
  176. package/dist/packages/testing/test-sandbox.d.ts +0 -1
  177. package/dist/packages/testing/test-sandbox.js +14 -30
  178. package/dist/packages/testing/test-targets.d.ts +1 -1
  179. package/dist/packages/testing/test-targets.js +6 -6
  180. package/dist/packages/testing/test.d.ts +1 -1
  181. package/dist/packages/testing/test.js +1 -1
  182. package/package.json +6 -26
  183. package/LICENSE +0 -183
  184. package/dist/cli/commands/compile-controller.d.ts +0 -17
  185. package/dist/cli/commands/compiled-flow.d.ts +0 -25
  186. package/dist/cli/commands/compiled-flow.js +0 -112
  187. package/dist/cli/commands/control-path.d.ts +0 -11
  188. package/dist/cli/commands/control-path.js +0 -72
  189. package/dist/cli/commands/create-method-wizard.d.ts +0 -76
  190. package/dist/cli/commands/create-method-wizard.js +0 -465
  191. package/dist/cli/commands/create.d.ts +0 -8
  192. package/dist/cli/commands/create.js +0 -189
  193. package/dist/cli/commands/default.d.ts +0 -2
  194. package/dist/cli/commands/default.js +0 -39
  195. package/dist/cli/commands/executor-flow.d.ts +0 -29
  196. package/dist/cli/commands/executor-flow.js +0 -163
  197. package/dist/cli/commands/init.d.ts +0 -11
  198. package/dist/cli/commands/init.js +0 -784
  199. package/dist/cli/commands/list.d.ts +0 -2
  200. package/dist/cli/commands/list.js +0 -30
  201. package/dist/cli/commands/preparation-selection.d.ts +0 -6
  202. package/dist/cli/commands/preparation-selection.js +0 -11
  203. package/dist/cli/commands/source-config-wizard.d.ts +0 -52
  204. package/dist/cli/commands/source-config-wizard.js +0 -680
  205. package/dist/cli/commands/test-flow.d.ts +0 -58
  206. package/dist/cli/commands/test-flow.js +0 -231
  207. package/dist/cli/commands/verify.d.ts +0 -2
  208. package/dist/cli/commands/verify.js +0 -94
  209. package/dist/compiler-ui/_next/static/chunks/0d~8t0zm6545p.js +0 -118
  210. package/dist/compiler-ui/_next/static/chunks/0xnel.ax9a.2c.css +0 -3
  211. package/dist/packages/compiler/raw-snapshot.d.ts +0 -49
  212. package/dist/packages/compiler/raw-snapshot.js +0 -101
  213. package/dist/packages/method-package/index.d.ts +0 -11
  214. package/dist/packages/method-package/index.js +0 -11
  215. package/dist/packages/method-package/method-stage-policy.d.ts +0 -5
  216. package/dist/packages/method-package/method-stage-policy.js +0 -31
  217. package/dist/packages/project-model/project-paths.d.ts +0 -12
  218. package/dist/packages/project-model/project-paths.js +0 -33
  219. /package/dist/compiler-ui/_next/static/{j7pdoqWrl4YJrJUVnksbl → C6vVfy3aeYuIO3d2AoNvC}/_buildManifest.js +0 -0
  220. /package/dist/compiler-ui/_next/static/{j7pdoqWrl4YJrJUVnksbl → C6vVfy3aeYuIO3d2AoNvC}/_clientMiddlewareManifest.js +0 -0
  221. /package/dist/compiler-ui/_next/static/{j7pdoqWrl4YJrJUVnksbl → C6vVfy3aeYuIO3d2AoNvC}/_ssgManifest.js +0 -0
  222. /package/dist/{cli/commands/check-draft.js → packages/local-service/readiness-check-draft.js} +0 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Pure shaping helpers used by the runtime to assemble resource payloads
3
+ * (preparations, methods, proofs, log paths, readiness summaries) from
4
+ * raw state/run records. No I/O, no `this` — every input is passed in.
5
+ *
6
+ * Splitting these out keeps the runtime coordinator focused on
7
+ * orchestration rather than payload formatting.
8
+ */
9
+ import { type ArtifactRef, type ProofRecord } from "../execution/lib/schema.js";
10
+ import { type CompiledState } from "../compiler/state.js";
11
+ import { type RuntimeRun } from "../compiler/lib/schema.js";
12
+ import { type ReadinessState, type ReadinessTargetResult } from "../contracts/lib/schema.js";
13
+ import { type TestRunTargetSummary } from "../testing/lib/schema.js";
14
+ import { type SourcePreparationConfig } from "../project-model/lib/schema.js";
15
+ import { type MethodResource, type PreparationResource } from "./lib/schema.js";
16
+ export declare function createRunId(prefix: "compile" | "test" | "job"): string;
17
+ export declare function stageArtifactRefs(stageId: string, artifacts: string[] | undefined): ArtifactRef[];
18
+ export declare function proofForStage(options: {
19
+ runId: string;
20
+ stageId: string;
21
+ summary?: string | null;
22
+ stageState: NonNullable<CompiledState["stages"]>[string];
23
+ artifacts: ArtifactRef[];
24
+ }): ProofRecord;
25
+ export declare function logsForStageRun(stageState: NonNullable<CompiledState["stages"]>[string] | undefined): {
26
+ prompt_path: string;
27
+ event_stream_path: string;
28
+ status_path: string;
29
+ contract_path: string;
30
+ } | undefined;
31
+ export declare function logsForRuntimeRun(run: RuntimeRun | undefined): {
32
+ contract_path: string;
33
+ status_path?: string | undefined;
34
+ event_stream_path?: string | undefined;
35
+ prompt_path?: string | undefined;
36
+ } | undefined;
37
+ export declare function passRate(passed: number, total: number): number | null;
38
+ export declare function readinessTargetResult(summary: TestRunTargetSummary | null | undefined, currentFingerprint: string | null, readinessRunFingerprint: string | null | undefined): ReadinessTargetResult | null;
39
+ export declare function readinessSummaryForStatus(status: ReadinessState["status"]): string;
40
+ export declare function readinessStateToPreparationReadiness(readiness: ReadinessState): ReadinessState;
41
+ export declare function buildPreparationResource(rootPath: string, preparation: SourcePreparationConfig, readiness: ReadinessState, latestCompileRunId: string | null, latestTestRunId: string | null): PreparationResource;
42
+ export declare function buildMethodResource(resource: {
43
+ id: string;
44
+ path: string;
45
+ label?: string;
46
+ hint?: string;
47
+ source_kind: "builtin" | "local";
48
+ built_in: boolean;
49
+ active_for_preparations: string[];
50
+ output_paths: string[];
51
+ stages: MethodResource["stages"];
52
+ }): MethodResource;
@@ -0,0 +1,149 @@
1
+ import { ReadinessStateSchema, } from "../contracts/lib/schema.js";
2
+ import { methodIdForSourcePreparationConfig, resolveSourcePreparationPath, } from "../project-model/source-config.js";
3
+ import { MethodResourceSchema, PreparationResourceSchema, } from "./lib/schema.js";
4
+ export function createRunId(prefix) {
5
+ return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
6
+ }
7
+ export function stageArtifactRefs(stageId, artifacts) {
8
+ return (artifacts ?? []).map((path) => ({
9
+ path,
10
+ role: "output",
11
+ stage_id: stageId,
12
+ label: path,
13
+ }));
14
+ }
15
+ export function proofForStage(options) {
16
+ return {
17
+ id: `${options.runId}-${options.stageId}-proof`,
18
+ run_id: options.runId,
19
+ stage_id: options.stageId,
20
+ generated_at: options.stageState.finished_at ?? new Date().toISOString(),
21
+ summary: options.summary ?? `${options.stageId} produced stage evidence.`,
22
+ files_processed: options.stageState.counts?.source_total,
23
+ artifacts: options.artifacts,
24
+ checks: [
25
+ {
26
+ id: `${options.stageId}-status`,
27
+ label: "stage completed",
28
+ ok: options.stageState.status === "succeeded",
29
+ ...(options.stageState.status === "succeeded"
30
+ ? {}
31
+ : { detail: options.stageState.summary ?? "Stage did not complete successfully." }),
32
+ },
33
+ {
34
+ id: `${options.stageId}-artifacts`,
35
+ label: "artifacts recorded",
36
+ ok: options.artifacts.length > 0,
37
+ ...(options.artifacts.length > 0
38
+ ? {}
39
+ : { detail: "No stage artifacts were recorded." }),
40
+ },
41
+ ],
42
+ };
43
+ }
44
+ export function logsForStageRun(stageState) {
45
+ const runId = stageState?.run_id;
46
+ if (!runId)
47
+ return undefined;
48
+ return {
49
+ prompt_path: `.interf/runtime/logs/${runId}.prompt.txt`,
50
+ event_stream_path: `.interf/runtime/logs/${runId}.events.ndjson`,
51
+ status_path: `.interf/runtime/logs/${runId}.status.log`,
52
+ contract_path: `.interf/runtime/logs/${runId}.stage-contract.json`,
53
+ };
54
+ }
55
+ export function logsForRuntimeRun(run) {
56
+ if (!run)
57
+ return undefined;
58
+ return {
59
+ ...(run.logs?.prompt_path ? { prompt_path: run.logs.prompt_path } : {}),
60
+ ...(run.logs?.event_stream_path ? { event_stream_path: run.logs.event_stream_path } : {}),
61
+ ...(run.logs?.status_path ? { status_path: run.logs.status_path } : {}),
62
+ contract_path: run.contract_path,
63
+ };
64
+ }
65
+ export function passRate(passed, total) {
66
+ if (total <= 0)
67
+ return null;
68
+ return Math.round((passed / total) * 100);
69
+ }
70
+ export function readinessTargetResult(summary, currentFingerprint, readinessRunFingerprint) {
71
+ if (!summary)
72
+ return null;
73
+ const resultFingerprint = readinessRunFingerprint ?? null;
74
+ return {
75
+ passed: summary.passed_cases,
76
+ total: summary.total_cases,
77
+ pass_rate: passRate(summary.passed_cases, summary.total_cases),
78
+ checks_fingerprint: resultFingerprint,
79
+ stale: Boolean(currentFingerprint && resultFingerprint && currentFingerprint !== resultFingerprint),
80
+ run_id: null,
81
+ run_path: summary.run_path,
82
+ };
83
+ }
84
+ export function readinessSummaryForStatus(status) {
85
+ if (status === "ready")
86
+ return "Ready for agent work.";
87
+ if (status === "not-ready")
88
+ return "Readiness checks did not pass.";
89
+ if (status === "stale")
90
+ return "Readiness checks are stale for the current saved checks.";
91
+ if (status === "checking")
92
+ return "Readiness checks are running.";
93
+ if (status === "building")
94
+ return "Portable context is building.";
95
+ if (status === "built")
96
+ return "Portable context is built; readiness has not been proven yet.";
97
+ if (status === "not-built")
98
+ return "Portable context has not been built yet.";
99
+ if (status === "not-configured")
100
+ return "No readiness checks are configured.";
101
+ return "Latest preparation failed.";
102
+ }
103
+ export function readinessStateToPreparationReadiness(readiness) {
104
+ return ReadinessStateSchema.parse({
105
+ ...readiness,
106
+ checks: readiness.checks.map((check) => ({ ...check })),
107
+ });
108
+ }
109
+ export function buildPreparationResource(rootPath, preparation, readiness, latestCompileRunId, latestTestRunId) {
110
+ const methodId = methodIdForSourcePreparationConfig(preparation);
111
+ return PreparationResourceSchema.parse({
112
+ id: preparation.name,
113
+ name: preparation.name,
114
+ preparation,
115
+ source_path: resolveSourcePreparationPath(rootPath, preparation),
116
+ method_id: methodId,
117
+ checks: preparation.checks,
118
+ portable_context: {
119
+ preparation: preparation.name,
120
+ path: readiness.portable_context_path,
121
+ exists: readiness.portable_context_path !== null,
122
+ method_id: methodId,
123
+ latest_compile_run_id: latestCompileRunId,
124
+ latest_test_run_id: latestTestRunId,
125
+ },
126
+ portable_context_path: readiness.portable_context_path,
127
+ readiness: readinessStateToPreparationReadiness(readiness),
128
+ runs: {
129
+ latest_compile_run_id: latestCompileRunId,
130
+ latest_test_run_id: latestTestRunId,
131
+ },
132
+ latest_compile_run_id: latestCompileRunId,
133
+ latest_test_run_id: latestTestRunId,
134
+ });
135
+ }
136
+ export function buildMethodResource(resource) {
137
+ return MethodResourceSchema.parse({
138
+ id: resource.id,
139
+ method_id: resource.id,
140
+ path: resource.path,
141
+ ...(resource.label ? { label: resource.label } : {}),
142
+ ...(resource.hint ? { hint: resource.hint } : {}),
143
+ source_kind: resource.source_kind,
144
+ built_in: resource.built_in,
145
+ active_for_preparations: resource.active_for_preparations,
146
+ output_paths: resource.output_paths,
147
+ stages: resource.stages,
148
+ });
149
+ }
@@ -2,7 +2,7 @@ import { type ArtifactRef, type CompileRun, type InterfRunEvent, type ProofRecor
2
2
  import { type RunEventSink } from "../execution/events.js";
3
3
  import { type ReadinessState } from "../contracts/lib/schema.js";
4
4
  import type { SourcePreparationConfig } from "../project-model/lib/schema.js";
5
- import { type ActionProposalCreateRequest, type ActionProposalPlan, type ActionProposalResource, type CompileRunCreateRequest, type CompileRunResource, type MethodResource, type LocalServiceHealth, type LocalJobEvent, type LocalJobEventAppendRequest, type LocalExecutorStatus, type LocalJobRunResource, type LocalRunHandlerResult, type PortableContextResource, type PreparationReadinessState, type PreparationResource, type ReadinessCheckDraftCreateRequest, type ReadinessCheckDraftResult, type RunObservabilityResource, type SourceFileResource, type WorkspaceFileResource, type TestRunCreateRequest, type TestRunResource, type MethodAuthoringCreateRequest, type MethodAuthoringResult } from "./lib/schema.js";
5
+ import { type ActionProposalCreateRequest, type ActionProposalPlan, type ActionProposalResource, type CompileRunCreateRequest, type CompileRunResource, type MethodResource, type LocalServiceHealth, type LocalJobEvent, type LocalJobEventAppendRequest, type LocalExecutorStatus, type LocalJobRunResource, type LocalRunHandlerResult, type PortableContextResource, type PreparationResource, type ReadinessCheckDraftCreateRequest, type ReadinessCheckDraftResult, type RunObservabilityResource, type ServiceRegistryWorkspace, type SourceFileResource, type WorkspaceFileResource, type TestRunCreateRequest, type TestRunResource, type MethodAuthoringCreateRequest, type MethodAuthoringResult, type MethodChangeResult, type PreparationChangeResult, type PreparationSetupResult, type WorkspaceBootstrapResult, type ResetResult } from "./lib/schema.js";
6
6
  export interface LocalServiceCompileRunContext {
7
7
  runId: string;
8
8
  sourcePath: string;
@@ -52,64 +52,221 @@ export interface LocalServiceRuntimeOptions {
52
52
  packageVersion?: string;
53
53
  startedAt?: string;
54
54
  handlers?: Partial<LocalServiceRunHandlers>;
55
+ /**
56
+ * Per-instance bearer token. The server requires it on mutating
57
+ * requests. Optional only so test code that does not exercise auth can
58
+ * skip generating one; production startup always provides a token.
59
+ */
60
+ authToken?: string;
61
+ }
62
+ /**
63
+ * Per-workspace context tracked by the runtime. Multiple workspaces can be
64
+ * registered against one running service; each one owns its rootPath and
65
+ * activity timestamps. Routes pass the workspace explicitly to every
66
+ * runtime method that needs one, so there is no swap-state to manage.
67
+ */
68
+ export interface PreparationContext {
69
+ rootPath: string;
70
+ startedAt: string;
71
+ lastActivity: string;
55
72
  }
56
73
  export declare class LocalServiceRuntime {
57
- readonly rootPath: string;
58
74
  readonly host: string;
59
- readonly port: number;
75
+ port: number;
60
76
  readonly startedAt: string;
61
77
  readonly packageVersion?: string;
62
78
  readonly handlers: Partial<LocalServiceRunHandlers>;
79
+ /**
80
+ * The seed root path the runtime was constructed with. Used as a
81
+ * non-preparation fallback when a preparation-independent route
82
+ * (methods, action proposals, runs listings) needs an anchor to load
83
+ * shared state (user-library methods, bundled methods, etc).
84
+ */
85
+ readonly rootPath: string;
86
+ /**
87
+ * Per-instance bearer token. Mutating routes require this on the
88
+ * Authorization header. `null` means token-less mode (test harness).
89
+ */
90
+ readonly authToken: string | null;
91
+ /** Map of prepDataDir -> PreparationContext. */
92
+ private workspaces;
93
+ /** Hook called whenever a workspace is registered or deregistered. */
94
+ private onRegistryChanged;
95
+ /** In-flight runs across all workspaces. Used for `idle_for_seconds`. */
96
+ private activeRunCount;
97
+ /**
98
+ * Active compile-run cancellation handles, keyed by run id. Populated
99
+ * when a compile run is launched and cleared once the run reaches a
100
+ * terminal state. Each entry remembers where the persisted record lives
101
+ * so cancel can mark it without re-resolving the Preparation.
102
+ */
103
+ private activeCompileRuns;
104
+ /**
105
+ * Idempotency-key cache for `POST /v1/compile-runs`. Outer key is the
106
+ * resolved workspace root; inner key is the client-supplied idempotency
107
+ * value. Namespacing per workspace prevents key collisions across
108
+ * tenants on the same engine (CSO finding: a malicious workspace could
109
+ * otherwise hijack another workspace's run id by reusing its key).
110
+ * Entries expire after `IDEMPOTENCY_TTL_MS`.
111
+ */
112
+ private idempotencyKeyCache;
113
+ /**
114
+ * Read-side caches. Polling clients (Compiler UI, CLI status loops)
115
+ * hit list/get endpoints multiple times per second; without these,
116
+ * every request re-walks the filesystem and re-parses every JSON
117
+ * record through Zod. The runtime invalidates each cache on the
118
+ * matching write path. See {@link runtime-caches} for design notes.
119
+ */
120
+ private readonly compileRunCache;
121
+ private readonly testRunCache;
122
+ private readonly readinessCache;
123
+ private readonly sourceFilesCache;
124
+ private readonly methodListingCache;
63
125
  constructor(options: LocalServiceRuntimeOptions);
64
- health(): LocalServiceHealth;
65
- listPreparations(): PreparationResource[];
66
- getPreparation(preparationName: string): PreparationResource | null;
67
- listPreparationReadiness(): PreparationReadinessState[];
68
- getPreparationReadiness(preparationName: string): PreparationReadinessState | null;
69
- listReadiness(): ReadinessState[];
70
- getReadiness(preparationName: string): ReadinessState | null;
71
- computePreparationReadiness(preparation: SourcePreparationConfig): ReadinessState;
72
- listSourceFiles(preparationName?: string | null): SourceFileResource[];
73
- listWorkspaceFiles(): WorkspaceFileResource[];
74
- listMethods(): MethodResource[];
75
- getMethod(methodId: string): MethodResource | null;
76
- listJobs(): LocalJobRunResource[];
77
- getJob(runId: string): LocalJobRunResource | null;
78
- getJobEvents(runId: string): LocalJobEvent[] | null;
126
+ setBoundPort(port: number): void;
127
+ /** Set a hook that fires whenever the registered workspaces change. */
128
+ setOnRegistryChanged(handler: (() => void) | null): void;
129
+ /**
130
+ * Register a workspace with this runtime. Returns the PreparationContext.
131
+ * Idempotent: re-registering an existing workspace updates `lastActivity`.
132
+ */
133
+ registerPreparation(prepDataDir: string): PreparationContext;
134
+ /**
135
+ * Remove a workspace from the runtime. Returns true if a workspace was
136
+ * removed.
137
+ */
138
+ deregisterPreparation(prepDataDir: string): boolean;
139
+ /**
140
+ * Most recently active workspace, or the first registered if none has
141
+ * activity yet. Server code uses this as the fallback when a request
142
+ * omits the workspace header. Throws if no workspace is registered.
143
+ */
144
+ defaultPreparationDataDir(): string;
145
+ /** Look up a workspace context by rootPath. */
146
+ getPreparationContext(prepDataDir: string): PreparationContext | null;
147
+ /** All registered workspaces, ordered by registration time. */
148
+ listRegisteredPreparations(): PreparationContext[];
149
+ /** True when no workspaces are registered. */
150
+ hasNoWorkspaces(): boolean;
151
+ /** Number of registered workspaces. */
152
+ registeredPreparationCount(): number;
153
+ /** Increment in-flight run counter. Call when a long-running run starts. */
154
+ beginActiveRun(): void;
155
+ /** Decrement in-flight run counter. Pair with `beginActiveRun`. */
156
+ endActiveRun(): void;
157
+ /** Sum of in-flight runs across all workspaces. */
158
+ activeRuns(): number;
159
+ /**
160
+ * Mark the workspace as recently active. Routes call this on entry so
161
+ * `idleForSeconds` and the registry snapshots stay in sync with the
162
+ * actual request cadence.
163
+ */
164
+ touchPreparation(prepDataDir: string): void;
165
+ /** Snapshot of registered workspaces for the registry / status output. */
166
+ registeredPreparationSnapshots(): ServiceRegistryWorkspace[];
167
+ /** Seconds since the most recent workspace activity (0 if active). */
168
+ idleForSeconds(): number;
169
+ health(prepDataDir?: string): LocalServiceHealth;
170
+ listPreparations(prepDataDir: string): PreparationResource[];
171
+ getPreparation(prepDataDir: string, preparationName: string): PreparationResource | null;
172
+ listPreparationReadiness(prepDataDir: string): ReadinessState[];
173
+ getPreparationReadiness(prepDataDir: string, preparationName: string): ReadinessState | null;
174
+ listReadiness(prepDataDir: string): ReadinessState[];
175
+ getReadiness(prepDataDir: string, preparationName: string): ReadinessState | null;
176
+ computePreparationReadiness(prepDataDir: string, preparation: SourcePreparationConfig): ReadinessState;
177
+ private computePreparationReadinessUncached;
178
+ listSourceFiles(prepDataDir: string, preparationName?: string | null): SourceFileResource[];
179
+ listWorkspaceFiles(prepDataDir: string): WorkspaceFileResource[];
180
+ listMethods(prepDataDir: string): MethodResource[];
181
+ getMethod(prepDataDir: string, methodId: string): MethodResource | null;
182
+ listJobs(prepDataDir: string): LocalJobRunResource[];
183
+ getJob(prepDataDir: string, runId: string): LocalJobRunResource | null;
184
+ getJobEvents(prepDataDir: string, runId: string): LocalJobEvent[] | null;
79
185
  getExecutorStatus(): LocalExecutorStatus;
80
186
  selectExecutor(requestValue: unknown): LocalExecutorStatus;
81
- listActionProposals(): ActionProposalResource[];
82
- getActionProposal(proposalId: string): ActionProposalResource | null;
83
- createActionProposal(requestValue: unknown): Promise<ActionProposalResource>;
84
- decideActionProposal(proposalId: string, requestValue: unknown): Promise<ActionProposalResource | null>;
85
- listRunObservability(): RunObservabilityResource[];
86
- getRunObservability(runId: string): RunObservabilityResource | null;
87
- createJobRun(requestValue: unknown): LocalJobRunResource;
88
- appendJobRunEvent(runId: string, requestValue: unknown): LocalJobRunResource | null;
89
- createReadinessCheckDraftRun(requestValue: unknown): Promise<LocalJobRunResource>;
90
- createPreparationSetupRun(requestValue: unknown): Promise<LocalJobRunResource>;
91
- createMethodAuthoringRun(requestValue: unknown): Promise<LocalJobRunResource>;
92
- listPortableContexts(): PortableContextResource[];
93
- getPortableContext(preparationName: string): PortableContextResource | null;
94
- listCompileRuns(): CompileRunResource[];
95
- listCompileRunsForPreparation(preparationName: string): CompileRun[];
96
- getCompileRun(runId: string): CompileRunResource | null;
97
- getCompileRunEvents(runId: string): InterfRunEvent[] | null;
98
- getCompileRunProof(runId: string): ProofRecord[] | null;
99
- getCompileRunArtifacts(runId: string): ArtifactRef[] | null;
100
- createCompileRun(requestValue: unknown): Promise<CompileRunResource>;
101
- listTestRuns(): TestRunResource[];
102
- listTestRunsForPreparation(preparationName: string): TestRunResource[];
103
- getTestRun(runId: string): TestRunResource | null;
104
- createTestRun(requestValue: unknown): Promise<TestRunResource>;
187
+ listActionProposals(prepDataDir: string): ActionProposalResource[];
188
+ getActionProposal(prepDataDir: string, proposalId: string): ActionProposalResource | null;
189
+ createActionProposal(prepDataDir: string, requestValue: unknown): Promise<ActionProposalResource>;
190
+ decideActionProposal(prepDataDir: string, proposalId: string, requestValue: unknown): Promise<ActionProposalResource | null>;
191
+ listRunObservability(prepDataDir: string): RunObservabilityResource[];
192
+ getRunObservability(prepDataDir: string, runId: string): RunObservabilityResource | null;
193
+ private createJobRun;
194
+ private appendJobRunEvent;
195
+ createReadinessCheckDraftRun(prepDataDir: string, requestValue: unknown): Promise<LocalJobRunResource>;
196
+ applyMethodChange(prepDataDir: string, requestValue: unknown): MethodChangeResult;
197
+ /**
198
+ * Bootstrap the workspace's source-folder binding and seed the default
199
+ * Method. Idempotent: re-running with the same source folder preserves
200
+ * existing preparations and reports `changed: false`.
201
+ *
202
+ * The CLI calls this in place of writing `interf.json` directly, so the
203
+ * operation is recorded by the service (and visible to other clients).
204
+ */
205
+ bootstrapWorkspace(prepDataDir: string, requestValue: unknown): WorkspaceBootstrapResult;
206
+ applyPreparationSetup(prepDataDir: string, requestValue: unknown): PreparationSetupResult;
207
+ applyPreparationChange(prepDataDir: string, requestValue: unknown): PreparationChangeResult;
208
+ applyReset(prepDataDir: string, requestValue: unknown): ResetResult;
209
+ createMethodAuthoringRun(prepDataDir: string, requestValue: unknown, jobType?: "method-authoring" | "method-improvement"): Promise<LocalJobRunResource>;
210
+ listPortableContexts(prepDataDir: string): PortableContextResource[];
211
+ getPortableContext(prepDataDir: string, preparationName: string): PortableContextResource | null;
212
+ listCompileRuns(prepDataDir: string): CompileRunResource[];
213
+ listCompileRunsForPreparation(prepDataDir: string, preparationName: string): CompileRun[];
214
+ getCompileRun(prepDataDir: string, runId: string): CompileRunResource | null;
215
+ getCompileRunEvents(prepDataDir: string, runId: string): InterfRunEvent[] | null;
216
+ getCompileRunProof(prepDataDir: string, runId: string): ProofRecord[] | null;
217
+ getCompileRunArtifacts(prepDataDir: string, runId: string): ArtifactRef[] | null;
218
+ createCompileRun(prepDataDir: string, requestValue: unknown): Promise<CompileRunResource>;
219
+ /**
220
+ * Cancel an in-flight compile run. Marks the persisted record as
221
+ * `cancelled`, emits a `run.failed` event to capture the cancellation in
222
+ * the run timeline, and clears the active handle so retries may start a
223
+ * fresh run. If the run already finished, returns
224
+ * `{ cancelled: false, reason: "already finished" }` and persists nothing.
225
+ */
226
+ cancelCompileRun(runId: string): {
227
+ cancelled: boolean;
228
+ reason?: string;
229
+ };
230
+ /**
231
+ * Look up the run id previously associated with this idempotency key in
232
+ * `prepDataDir`. Returns null when the key is unknown or its TTL has
233
+ * elapsed. The workspace argument is required so that the same key in
234
+ * two different workspaces always returns two different runs.
235
+ */
236
+ findIdempotentCompileRun(prepDataDir: string, key: string): string | null;
237
+ /**
238
+ * Cache the run id created (or returned) for this idempotency key in
239
+ * `prepDataDir`. Entries expire after `IDEMPOTENCY_TTL_MS`. Pruning
240
+ * is opportunistic: the previous implementation walked every entry on
241
+ * every read AND write, which was O(N) per request. Now we only sweep
242
+ * when the cache grows past {@link IDEMPOTENCY_PRUNE_THRESHOLD}.
243
+ */
244
+ recordIdempotentCompileRun(prepDataDir: string, key: string, runId: string): void;
245
+ /** Total cached idempotency entries across all workspaces. */
246
+ private totalIdempotencyEntries;
247
+ private pruneIdempotencyKeyCache;
248
+ /**
249
+ * Test seam: force the cached entry for `key` in `prepDataDir` to be
250
+ * expired so the next lookup returns null. Returns true when an entry was
251
+ * found and expired. Tests use this in place of fake timers because the
252
+ * idempotency TTL is one hour and faking `Date.now()` would destabilize
253
+ * unrelated runtime state.
254
+ */
255
+ expireIdempotencyKeyForTesting(prepDataDir: string, key: string): boolean;
256
+ listTestRuns(prepDataDir: string): TestRunResource[];
257
+ listTestRunsForPreparation(prepDataDir: string, preparationName: string): TestRunResource[];
258
+ getTestRun(prepDataDir: string, runId: string): TestRunResource | null;
259
+ createTestRun(prepDataDir: string, requestValue: unknown): Promise<TestRunResource>;
105
260
  private runCompileInBackground;
106
261
  private runTestInBackground;
107
262
  private runReadinessCheckDraftInBackground;
263
+ private runReadinessCheckDraftInBackgroundInner;
108
264
  private runMethodAuthoringInBackground;
265
+ private runMethodAuthoringInBackgroundInner;
109
266
  private jobRunContext;
110
267
  private defaultPreparationName;
111
268
  private planActionProposal;
112
- private buildPreparationSetupRequest;
269
+ private directServiceActionClarification;
113
270
  private buildActionProposal;
114
271
  private submitActionProposal;
115
272
  private resolvePreparationConfig;
@@ -122,7 +279,7 @@ export declare class LocalServiceRuntime {
122
279
  private recordCompileRunEvent;
123
280
  private refreshCompileRunFromRuntime;
124
281
  private emitRuntimeDerivedEvents;
125
- private readLatestComparison;
282
+ private readLatestReadinessRun;
126
283
  private checksEvaluatedEvent;
127
284
  private readinessUpdatedEvent;
128
285
  private writeTestRun;