@interf/compiler 0.16.0 → 0.21.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 (203) hide show
  1. package/LICENSE.md +1 -0
  2. package/README.md +90 -73
  3. package/TRADEMARKS.md +4 -4
  4. package/dist/cli/commands/mcp.d.ts +0 -34
  5. package/dist/cli/commands/mcp.js +246 -45
  6. package/dist/cli/commands/method.js +261 -15
  7. package/dist/cli/commands/prep.js +116 -15
  8. package/dist/cli/commands/runs.js +103 -9
  9. package/dist/cli/commands/status.js +4 -2
  10. package/dist/cli/commands/test.d.ts +10 -0
  11. package/dist/cli/commands/{verify.js → test.js} +24 -17
  12. package/dist/cli/commands/web.js +82 -8
  13. package/dist/cli/commands/wizard.js +158 -51
  14. package/dist/cli/index.d.ts +2 -2
  15. package/dist/cli/index.js +3 -3
  16. package/dist/compiler-ui/404.html +1 -1
  17. package/dist/compiler-ui/__next.__PAGE__.txt +5 -5
  18. package/dist/compiler-ui/__next._full.txt +13 -12
  19. package/dist/compiler-ui/__next._head.txt +3 -3
  20. package/dist/compiler-ui/__next._index.txt +5 -4
  21. package/dist/compiler-ui/__next._tree.txt +4 -3
  22. package/dist/compiler-ui/_next/static/chunks/01646j7yi.w5a.css +1 -0
  23. package/dist/compiler-ui/_next/static/chunks/{0n51hrfoufc7g.js → 02f_.8.ebn556.js} +1 -1
  24. package/dist/compiler-ui/_next/static/chunks/02r7siaw-_p5w.js +1 -0
  25. package/dist/compiler-ui/_next/static/chunks/{08m7vf5asqlsm.js → 04d0ly-7xb~-j.js} +10 -10
  26. package/dist/compiler-ui/_next/static/chunks/0fhs9psnxqd8s.js +1 -0
  27. package/dist/compiler-ui/_next/static/chunks/0mssmhpbifj15.css +2 -0
  28. package/dist/compiler-ui/_next/static/chunks/0nypu~ddwxari.js +116 -0
  29. package/dist/compiler-ui/_next/static/chunks/0p3s8iyhgcww2.js +31 -0
  30. package/dist/compiler-ui/_next/static/chunks/0tjf-vu_rz8s0.css +1 -0
  31. package/dist/compiler-ui/_next/static/chunks/0u6p3fpbbfgtl.js +1 -0
  32. package/dist/compiler-ui/_next/static/chunks/0wpx5..8dnh0w.js +1 -0
  33. package/dist/compiler-ui/_next/static/chunks/0y0uj160p0ts~.js +1 -0
  34. package/dist/compiler-ui/_next/static/chunks/10t8l~_oenf.c.js +1 -0
  35. package/dist/compiler-ui/_next/static/chunks/13gz9e7z~imx1.js +5 -0
  36. package/dist/compiler-ui/_next/static/chunks/156xed-b6czaw.js +1 -0
  37. package/dist/compiler-ui/_next/static/chunks/{turbopack-0.uq1k8c0j4s..js → turbopack-02-3e_c-yz~5g.js} +1 -1
  38. package/dist/compiler-ui/_next/static/chunks/{turbopack-10e~t1yzi4svj.js → turbopack-0apv8vb-nczuy.js} +1 -1
  39. package/dist/compiler-ui/_not-found/__next._full.txt +10 -9
  40. package/dist/compiler-ui/_not-found/__next._head.txt +3 -3
  41. package/dist/compiler-ui/_not-found/__next._index.txt +5 -4
  42. package/dist/compiler-ui/_not-found/__next._not-found.__PAGE__.txt +2 -2
  43. package/dist/compiler-ui/_not-found/__next._not-found.txt +3 -3
  44. package/dist/compiler-ui/_not-found/__next._tree.txt +3 -2
  45. package/dist/compiler-ui/_not-found.html +1 -1
  46. package/dist/compiler-ui/_not-found.txt +10 -9
  47. package/dist/compiler-ui/index.html +1 -1
  48. package/dist/compiler-ui/index.txt +13 -12
  49. package/dist/packages/contracts/index.d.ts +2 -2
  50. package/dist/packages/contracts/index.js +1 -1
  51. package/dist/packages/contracts/lib/schema.d.ts +275 -72
  52. package/dist/packages/contracts/lib/schema.js +244 -83
  53. package/dist/packages/engine/action-definitions.d.ts +174 -13
  54. package/dist/packages/engine/action-definitions.js +125 -122
  55. package/dist/packages/engine/action-planner.js +4 -11
  56. package/dist/packages/engine/agents/lib/shells.d.ts +15 -5
  57. package/dist/packages/engine/agents/lib/shells.js +134 -123
  58. package/dist/packages/engine/agents/role-executors.js +1 -1
  59. package/dist/packages/engine/cloud-seams.d.ts +115 -0
  60. package/dist/packages/engine/cloud-seams.js +84 -0
  61. package/dist/packages/engine/compile/artifact-counts.d.ts +1 -1
  62. package/dist/packages/engine/compile/artifact-counts.js +3 -3
  63. package/dist/packages/engine/compile/artifact-status.d.ts +41 -0
  64. package/dist/packages/engine/compile/artifact-status.js +166 -0
  65. package/dist/packages/engine/compile/billing-events.d.ts +89 -0
  66. package/dist/packages/engine/compile/billing-events.js +74 -0
  67. package/dist/packages/engine/compile/check-evaluator.d.ts +66 -0
  68. package/dist/packages/engine/compile/check-evaluator.js +298 -0
  69. package/dist/packages/engine/compile/compiled-paths.js +6 -6
  70. package/dist/packages/engine/compile/compiled-schema.d.ts +7 -17
  71. package/dist/packages/engine/compile/compiled-schema.js +55 -70
  72. package/dist/packages/engine/compile/compiled-stage-plan.d.ts +1 -0
  73. package/dist/packages/engine/compile/compiled-stage-plan.js +32 -15
  74. package/dist/packages/engine/compile/compiled-stage-runner.js +1 -1
  75. package/dist/packages/engine/compile/index.d.ts +0 -1
  76. package/dist/packages/engine/compile/index.js +0 -1
  77. package/dist/packages/engine/compile/lib/schema.d.ts +111 -92
  78. package/dist/packages/engine/compile/lib/schema.js +35 -39
  79. package/dist/packages/engine/compile/method-primitives.d.ts +2 -2
  80. package/dist/packages/engine/compile/method-primitives.js +1 -1
  81. package/dist/packages/engine/compile/reset.js +4 -4
  82. package/dist/packages/engine/compile/runtime-contracts.js +2 -1
  83. package/dist/packages/engine/compile/runtime-prompt.js +3 -2
  84. package/dist/packages/engine/compile/runtime-reconcile.js +35 -35
  85. package/dist/packages/engine/compile/runtime-runs.js +0 -1
  86. package/dist/packages/engine/compile/runtime-types.d.ts +7 -8
  87. package/dist/packages/engine/compile/runtime.d.ts +1 -2
  88. package/dist/packages/engine/compile/runtime.js +0 -1
  89. package/dist/packages/engine/compile/state-health.js +6 -6
  90. package/dist/packages/engine/compile/state-view.js +7 -6
  91. package/dist/packages/engine/compile/validate-compiled.js +61 -30
  92. package/dist/packages/engine/compile/validate.js +26 -24
  93. package/dist/packages/engine/connection-config.js +1 -1
  94. package/dist/packages/engine/execution/lib/schema.d.ts +89 -33
  95. package/dist/packages/engine/execution/lib/schema.js +13 -5
  96. package/dist/packages/engine/index.d.ts +2 -2
  97. package/dist/packages/engine/index.js +1 -1
  98. package/dist/packages/engine/instance-paths.d.ts +15 -9
  99. package/dist/packages/engine/instance-paths.js +15 -9
  100. package/dist/packages/engine/lib/schema.d.ts +1316 -351
  101. package/dist/packages/engine/lib/schema.js +99 -36
  102. package/dist/packages/engine/native-run-handlers.js +25 -15
  103. package/dist/packages/engine/preparation-store.d.ts +9 -7
  104. package/dist/packages/engine/preparation-store.js +20 -0
  105. package/dist/packages/engine/requested-artifacts.d.ts +5 -0
  106. package/dist/packages/engine/requested-artifacts.js +36 -0
  107. package/dist/packages/engine/routes.d.ts +7 -1
  108. package/dist/packages/engine/routes.js +7 -1
  109. package/dist/packages/engine/run-observability.js +4 -4
  110. package/dist/packages/engine/runtime-event-applier.js +7 -0
  111. package/dist/packages/engine/runtime-proposal-helpers.d.ts +2 -2
  112. package/dist/packages/engine/runtime-proposal-helpers.js +6 -8
  113. package/dist/packages/engine/runtime-resource-builders.d.ts +11 -6
  114. package/dist/packages/engine/runtime-resource-builders.js +18 -6
  115. package/dist/packages/engine/runtime.d.ts +70 -8
  116. package/dist/packages/engine/runtime.js +304 -49
  117. package/dist/packages/engine/server.d.ts +25 -0
  118. package/dist/packages/engine/server.js +161 -50
  119. package/dist/packages/engine/verify/index.d.ts +10 -10
  120. package/dist/packages/engine/verify/index.js +8 -8
  121. package/dist/packages/engine/verify/readiness-check-run.d.ts +27 -4
  122. package/dist/packages/engine/verify/readiness-check-run.js +92 -24
  123. package/dist/packages/engine/verify/{test-execution.d.ts → verify-execution.d.ts} +2 -2
  124. package/dist/packages/engine/verify/{test-execution.js → verify-execution.js} +3 -3
  125. package/dist/packages/engine/verify/{test-paths.d.ts → verify-paths.d.ts} +1 -1
  126. package/dist/packages/engine/verify/{test-sandbox.d.ts → verify-sandbox.d.ts} +1 -1
  127. package/dist/packages/engine/verify/{test-specs.d.ts → verify-specs.d.ts} +1 -1
  128. package/dist/packages/engine/verify/{test-specs.js → verify-specs.js} +1 -1
  129. package/dist/packages/engine/verify/{test-targets.d.ts → verify-targets.d.ts} +1 -1
  130. package/dist/packages/engine/verify/{test.d.ts → verify.d.ts} +4 -4
  131. package/dist/packages/engine/verify/{test.js → verify.js} +3 -3
  132. package/dist/packages/engine/wire-schemas.d.ts +549 -0
  133. package/dist/packages/engine/wire-schemas.js +59 -0
  134. package/dist/packages/methods/authoring/method-authoring.d.ts +5 -1
  135. package/dist/packages/methods/authoring/method-authoring.js +68 -18
  136. package/dist/packages/methods/authoring/method-edit-session.js +5 -5
  137. package/dist/packages/methods/authoring/method-improvement.js +1 -1
  138. package/dist/packages/methods/package/builtin-compiled-method.d.ts +12 -12
  139. package/dist/packages/methods/package/builtin-compiled-method.js +26 -23
  140. package/dist/packages/methods/package/context-interface.d.ts +39 -26
  141. package/dist/packages/methods/package/context-interface.js +48 -39
  142. package/dist/packages/methods/package/interf-method-package.js +28 -47
  143. package/dist/packages/methods/package/local-methods.d.ts +4 -4
  144. package/dist/packages/methods/package/local-methods.js +53 -66
  145. package/dist/packages/methods/package/method-definitions.d.ts +4 -6
  146. package/dist/packages/methods/package/method-definitions.js +1 -5
  147. package/dist/packages/methods/package/method-helpers.d.ts +0 -2
  148. package/dist/packages/methods/package/method-helpers.js +0 -4
  149. package/dist/packages/project/interf-detect.js +6 -6
  150. package/dist/packages/project/interf-scaffold.js +12 -12
  151. package/dist/packages/project/lib/schema.d.ts +193 -0
  152. package/dist/packages/project/lib/schema.js +46 -1
  153. package/dist/packages/project/source-config.js +6 -1
  154. package/dist/packages/project/source-folders.js +1 -1
  155. package/package.json +12 -23
  156. package/public-repo/CONTRIBUTING.md +47 -0
  157. package/public-repo/LICENSE.md +1 -0
  158. package/public-repo/README.md +325 -0
  159. package/public-repo/SECURITY.md +67 -0
  160. package/public-repo/TRADEMARKS.md +8 -0
  161. package/{builtin-methods → public-repo/methods}/interf-default/README.md +10 -7
  162. package/{builtin-methods → public-repo/methods}/interf-default/compile/stages/shape/SKILL.md +4 -8
  163. package/{builtin-methods → public-repo/methods}/interf-default/method.json +8 -69
  164. package/public-repo/methods/interf-default/method.schema.json +75 -0
  165. package/public-repo/methods/interf-default/use/query/SKILL.md +23 -0
  166. package/public-repo/plugins/README.md +9 -0
  167. package/public-repo/plugins/interf/.claude-plugin/plugin.json +21 -0
  168. package/public-repo/plugins/interf/.mcp.json +12 -0
  169. package/public-repo/plugins/interf/README.md +29 -0
  170. package/public-repo/plugins/interf/skills/interf/SKILL.md +477 -0
  171. package/public-repo/skills/interf/SKILL.md +477 -0
  172. package/agent-skills/interf-actions/SKILL.md +0 -185
  173. package/agent-skills/interf-actions/references/cli.md +0 -243
  174. package/builtin-methods/interf-default/method.schema.json +0 -73
  175. package/builtin-methods/interf-default/use/query/SKILL.md +0 -28
  176. package/dist/cli/commands/verify.d.ts +0 -8
  177. package/dist/compiler-ui/_next/static/chunks/06yhdspx~ca5-.js +0 -5
  178. package/dist/compiler-ui/_next/static/chunks/06z~l3kwb891e.js +0 -1
  179. package/dist/compiler-ui/_next/static/chunks/08g7lvje.te.u.js +0 -1
  180. package/dist/compiler-ui/_next/static/chunks/0_i-3_5l9t2qe.js +0 -1
  181. package/dist/compiler-ui/_next/static/chunks/0b-ywny_j0g~0.js +0 -1
  182. package/dist/compiler-ui/_next/static/chunks/0b52v41o1gixx.js +0 -1
  183. package/dist/compiler-ui/_next/static/chunks/0gpzgsv0w.q~m.js +0 -31
  184. package/dist/compiler-ui/_next/static/chunks/0ilwfezfvu6~-.js +0 -1
  185. package/dist/compiler-ui/_next/static/chunks/0jipmpez3_ehh.js +0 -89
  186. package/dist/compiler-ui/_next/static/chunks/0xxmf45eskdt~.css +0 -1
  187. package/dist/compiler-ui/_next/static/chunks/13awzu4tooflw.css +0 -3
  188. package/dist/compiler-ui/_next/static/chunks/14wtz~vq25~qq.js +0 -1
  189. package/dist/packages/engine/compile/runtime-acceptance.d.ts +0 -9
  190. package/dist/packages/engine/compile/runtime-acceptance.js +0 -265
  191. /package/dist/compiler-ui/_next/static/{a3UiUF0DiMEbfWy_0gihg → tYHMLL9oKds1yDoNYgkPV}/_buildManifest.js +0 -0
  192. /package/dist/compiler-ui/_next/static/{a3UiUF0DiMEbfWy_0gihg → tYHMLL9oKds1yDoNYgkPV}/_clientMiddlewareManifest.js +0 -0
  193. /package/dist/compiler-ui/_next/static/{a3UiUF0DiMEbfWy_0gihg → tYHMLL9oKds1yDoNYgkPV}/_ssgManifest.js +0 -0
  194. /package/dist/packages/engine/verify/{test-paths.js → verify-paths.js} +0 -0
  195. /package/dist/packages/engine/verify/{test-profile-presets.d.ts → verify-profile-presets.d.ts} +0 -0
  196. /package/dist/packages/engine/verify/{test-profile-presets.js → verify-profile-presets.js} +0 -0
  197. /package/dist/packages/engine/verify/{test-sandbox.js → verify-sandbox.js} +0 -0
  198. /package/dist/packages/engine/verify/{test-targets.js → verify-targets.js} +0 -0
  199. /package/dist/packages/engine/verify/{test-types.d.ts → verify-types.d.ts} +0 -0
  200. /package/dist/packages/engine/verify/{test-types.js → verify-types.js} +0 -0
  201. /package/{builtin-methods → public-repo/methods}/interf-default/compile/stages/structure/SKILL.md +0 -0
  202. /package/{builtin-methods → public-repo/methods}/interf-default/compile/stages/summarize/SKILL.md +0 -0
  203. /package/{builtin-methods → public-repo/methods}/interf-default/improve/SKILL.md +0 -0
@@ -1,5 +1,7 @@
1
1
  import { type Server } from "node:http";
2
2
  import { type LocalServiceRunHandlers, type LocalServiceRuntime } from "./runtime.js";
3
+ import type { IdempotencyStore, RunLeaseStore, TokenValidator } from "./cloud-seams.js";
4
+ import type { BillingEventSink } from "./compile/billing-events.js";
3
5
  /** Generate a fresh per-instance bearer token. */
4
6
  export declare function createLocalServiceAuthToken(): string;
5
7
  export interface StartLocalServiceOptions {
@@ -21,6 +23,29 @@ export interface StartLocalServiceOptions {
21
23
  * and any caller that explicitly opts in).
22
24
  */
23
25
  authToken?: string | null | "auto";
26
+ /**
27
+ * 0.17 — cloud-variant auth seam (B4.3). When provided, every
28
+ * mutating request runs through this validator instead of the local
29
+ * constant-time bearer check, and the resulting `account_id` is
30
+ * stashed on the runtime context for billing-event attribution.
31
+ * Local default: `undefined` — fall back to `runtime.authToken`
32
+ * comparison.
33
+ */
34
+ tokenValidator?: TokenValidator;
35
+ /**
36
+ * 0.17 — cloud-variant interface seams forwarded to
37
+ * `LocalServiceRuntime`. Local default: in-process `Map`s on the
38
+ * runtime. Cloud variants pass shared implementations (Redis,
39
+ * Cassandra, etc.) so multi-replica engines coordinate. See
40
+ * `cloud-seams.ts` for the contracts.
41
+ */
42
+ idempotencyStore?: IdempotencyStore;
43
+ runLeaseStore?: RunLeaseStore;
44
+ /**
45
+ * 0.17 — billing event sink. Local default writes per-run JSONL.
46
+ * Cloud variants inject a Metronome HTTP sender once 0.18+ ships.
47
+ */
48
+ billingEventSink?: BillingEventSink;
24
49
  }
25
50
  export interface StartedLocalService {
26
51
  runtime: LocalServiceRuntime;
@@ -4,7 +4,7 @@ import { randomBytes } from "node:crypto";
4
4
  import { existsSync, statSync, readFileSync } from "node:fs";
5
5
  import { dirname, extname, join, normalize, resolve, sep } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
- import { LOCAL_SERVICE_LOOPBACK_HOSTS, LocalServiceConfigSchema, LocalServiceDiscoverySchema, LocalServiceErrorSchema, OpenPathRequestSchema, ServiceRegistryEntrySchema, } from "./lib/schema.js";
7
+ import { LOCAL_SERVICE_LOOPBACK_HOSTS, LocalServiceConfigSchema, LocalServiceDiscoverySchema, LocalServiceErrorSchema, OpenPathRequestSchema, PreparationCreateRequestSchema, PreparationUpdateRequestSchema, ServiceRegistryEntrySchema, } from "./lib/schema.js";
8
8
  import { assertPathWithinRoot, } from "../contracts/utils/path-guards.js";
9
9
  import { createLocalServiceRuntime, } from "./runtime.js";
10
10
  import { buildLocalServiceUrl, LOCAL_SERVICE_DEFAULT_HOST, LOCAL_SERVICE_DEFAULT_PORT, LOCAL_SERVICE_ROUTES, PREPARATION_SUBRESOURCES, } from "./routes.js";
@@ -124,7 +124,7 @@ function packageRoot() {
124
124
  }
125
125
  export function resolveCompilerUiStaticRoot(rootPath = packageRoot()) {
126
126
  const distRoot = join(rootPath, "dist", "compiler-ui");
127
- const sourceExportRoot = join(rootPath, "apps", "compiler-ui", "out");
127
+ const sourceExportRoot = join(rootPath, "src", "apps", "compiler-ui", "out");
128
128
  if (existsSync(join(distRoot, "index.html")))
129
129
  return distRoot;
130
130
  if (existsSync(join(sourceExportRoot, "index.html")))
@@ -309,9 +309,18 @@ function sendFile(res, filePath) {
309
309
  try {
310
310
  if (!statSync(filePath).isFile())
311
311
  return false;
312
- writeHeaders(res, 200, {
313
- "content-type": contentType(filePath),
314
- });
312
+ const type = contentType(filePath);
313
+ const headers = { "content-type": type };
314
+ // 0.17 — never cache HTML responses. UI deploys ship a fresh
315
+ // dist via `npm run web:build` and a restart; without `no-store`,
316
+ // a browser sitting on a stale `index.html` would keep loading
317
+ // hashed asset paths that no longer exist. Hashed Next.js bundles
318
+ // under `_next/static/<hash>/` keep the default long-cache
319
+ // because the filename itself changes when content changes.
320
+ if (type.startsWith("text/html")) {
321
+ headers["cache-control"] = "no-store";
322
+ }
323
+ writeHeaders(res, 200, headers);
315
324
  res.end(readFileSync(filePath));
316
325
  return true;
317
326
  }
@@ -375,6 +384,78 @@ async function routeApi(req, res, runtime) {
375
384
  const method = req.method ?? "GET";
376
385
  const origin = originHeaderValue(req);
377
386
  const allowed = buildAllowedOrigins(runtime.host, runtime.port);
387
+ const prepDataDirsForInstance = () => {
388
+ const dirs = listStoredPreparations().map((prep) => prep.prepDataDir);
389
+ return dirs.length > 0 ? dirs : [runtime.rootPath];
390
+ };
391
+ const listInstanceRuns = () => {
392
+ return prepDataDirsForInstance()
393
+ .flatMap((prepDataDir) => runtime.listRunObservability(prepDataDir))
394
+ .sort((left, right) => {
395
+ const leftMs = Date.parse(left.started_at ?? left.created_at ?? left.finished_at ?? "");
396
+ const rightMs = Date.parse(right.started_at ?? right.created_at ?? right.finished_at ?? "");
397
+ return (Number.isFinite(rightMs) ? rightMs : 0) - (Number.isFinite(leftMs) ? leftMs : 0);
398
+ });
399
+ };
400
+ const findInstanceRun = (runId) => {
401
+ for (const prepDataDir of prepDataDirsForInstance()) {
402
+ const run = runtime.getRunObservability(prepDataDir, runId);
403
+ if (run)
404
+ return run;
405
+ }
406
+ return null;
407
+ };
408
+ const findInstanceJob = (runId) => {
409
+ for (const prepDataDir of prepDataDirsForInstance()) {
410
+ const job = runtime.getJob(prepDataDir, runId);
411
+ if (job)
412
+ return { job, prepDataDir };
413
+ }
414
+ return null;
415
+ };
416
+ const listInstanceMethods = () => {
417
+ const byId = new Map();
418
+ for (const prepDataDir of prepDataDirsForInstance()) {
419
+ for (const methodResource of runtime.listMethods(prepDataDir)) {
420
+ const existing = byId.get(methodResource.id);
421
+ if (!existing) {
422
+ byId.set(methodResource.id, methodResource);
423
+ continue;
424
+ }
425
+ const preferred = existing.built_in && !methodResource.built_in
426
+ ? methodResource
427
+ : existing;
428
+ byId.set(methodResource.id, {
429
+ ...preferred,
430
+ active_for_preparations: Array.from(new Set([
431
+ ...existing.active_for_preparations,
432
+ ...methodResource.active_for_preparations,
433
+ ])).sort(),
434
+ });
435
+ }
436
+ }
437
+ return [...byId.values()].sort((left, right) => left.id.localeCompare(right.id));
438
+ };
439
+ const findInstanceMethod = (methodId) => {
440
+ return listInstanceMethods().find((methodResource) => methodResource.id === methodId) ?? null;
441
+ };
442
+ const listInstanceMethodRuns = (methodId) => {
443
+ return prepDataDirsForInstance()
444
+ .flatMap((prepDataDir) => runtime.listMethodRuns(prepDataDir, methodId))
445
+ .sort((left, right) => {
446
+ const leftMs = Date.parse(left.started_at ?? left.created_at ?? left.finished_at ?? "");
447
+ const rightMs = Date.parse(right.started_at ?? right.created_at ?? right.finished_at ?? "");
448
+ return (Number.isFinite(rightMs) ? rightMs : 0) - (Number.isFinite(leftMs) ? leftMs : 0);
449
+ });
450
+ };
451
+ const resolveInstanceMethodPackageRoot = (methodId) => {
452
+ for (const prepDataDir of prepDataDirsForInstance()) {
453
+ const localPath = methodDefinitionPath(prepDataDir, methodId);
454
+ if (existsSync(join(localPath, "method.json")))
455
+ return localPath;
456
+ }
457
+ return resolveMethodPackageRoot(methodId);
458
+ };
378
459
  // CORS preflight — answered for allowed origins, refused otherwise.
379
460
  if (method === "OPTIONS") {
380
461
  if (!isOriginAllowed(origin, allowed)) {
@@ -480,21 +561,15 @@ async function routeApi(req, res, runtime) {
480
561
  // POST /v1/preparations — create a new preparation.
481
562
  if (method === "POST" && path === LOCAL_SERVICE_ROUTES.preparations) {
482
563
  try {
483
- const body = (await readJsonBody(req));
484
- if (!body || typeof body !== "object") {
485
- sendError(res, 400, "Request body must be a JSON object.");
486
- return true;
487
- }
488
- if (!body.id || typeof body.id !== "string") {
489
- sendError(res, 400, "Missing required field: id");
490
- return true;
491
- }
492
- if (!body.method_id || typeof body.method_id !== "string") {
493
- sendError(res, 400, "Missing required field: method_id");
494
- return true;
495
- }
496
- if (!body.source || typeof body.source !== "object" || !body.source.locator) {
497
- sendError(res, 400, "Missing required field: source.locator");
564
+ const body = PreparationCreateRequestSchema.parse(await readJsonBody(req));
565
+ // TODO(cloud): activate remote-folder validator branch when the
566
+ // cloud variant lands. The local binary only knows how to read
567
+ // bytes from a local path; a `remote-folder` binding requires
568
+ // the cloud variant's per-account object-storage mount layer.
569
+ // Until then, reject any kind other than `local-folder` so the
570
+ // wire shape and runtime stay consistent.
571
+ if (body.source.kind !== "local-folder") {
572
+ sendError(res, 400, `Unsupported source kind: ${body.source.kind}. The local engine only accepts local-folder bindings; remote-folder requires the cloud variant.`);
498
573
  return true;
499
574
  }
500
575
  const stored = createStoredPreparation(runtime, {
@@ -502,6 +577,8 @@ async function routeApi(req, res, runtime) {
502
577
  source: { kind: "local-folder", locator: body.source.locator },
503
578
  method_id: body.method_id,
504
579
  about: body.about,
580
+ requested_artifacts: body.requested_artifacts,
581
+ source_profile: body.source_profile,
505
582
  checks: body.checks,
506
583
  max_attempts: body.max_attempts,
507
584
  max_loops: body.max_loops,
@@ -531,19 +608,26 @@ async function routeApi(req, res, runtime) {
531
608
  if (subPath === "") {
532
609
  // Bare /v1/preparations/{id}
533
610
  if (method === "GET") {
534
- sendJson(res, 200, preparationWireShape(storedPrep));
611
+ const preparation = runtime.getPreparation(storedPrep.prepDataDir, storedPrep.id);
612
+ sendJson(res, 200, preparation
613
+ ? {
614
+ ...preparation,
615
+ source: storedPrep.source,
616
+ about: storedPrep.about,
617
+ config_path: storedPrep.configPath,
618
+ }
619
+ : preparationWireShape(storedPrep));
535
620
  return true;
536
621
  }
537
622
  if (method === "PATCH") {
538
623
  try {
539
- const body = (await readJsonBody(req));
540
- if (!body || typeof body !== "object") {
541
- sendError(res, 400, "Request body must be a JSON object.");
542
- return true;
543
- }
624
+ const body = PreparationUpdateRequestSchema.parse(await readJsonBody(req));
544
625
  const updated = updateStoredPreparation(decodedPrepId, {
545
626
  method_id: body.method_id,
546
627
  about: body.about,
628
+ ...(body.checks !== undefined ? { checks: body.checks } : {}),
629
+ ...(body.requested_artifacts !== undefined ? { requested_artifacts: body.requested_artifacts } : {}),
630
+ ...(body.source_profile !== undefined ? { source_profile: body.source_profile } : {}),
547
631
  });
548
632
  sendJson(res, 200, preparationWireShape(updated));
549
633
  }
@@ -561,7 +645,7 @@ async function routeApi(req, res, runtime) {
561
645
  else if (subPath === PREPARATION_SUBRESOURCES.compileRuns) {
562
646
  if (method === "POST") {
563
647
  if (!storedPrep.methodId) {
564
- sendError(res, 400, `Preparation ${storedPrep.id} has no method bound. Set one via PATCH /v1/preparations/${storedPrep.id} { "method_id": "<id>" } before compiling.`);
648
+ sendError(res, 400, `Preparation ${storedPrep.id} has no Build Plan selected. Select one via PATCH /v1/preparations/${storedPrep.id} { "method_id": "<id>" } before compiling.`);
565
649
  return true;
566
650
  }
567
651
  try {
@@ -597,7 +681,7 @@ async function routeApi(req, res, runtime) {
597
681
  else if (subPath === PREPARATION_SUBRESOURCES.verifyRuns) {
598
682
  if (method === "POST") {
599
683
  if (!storedPrep.methodId) {
600
- sendError(res, 400, `Preparation ${storedPrep.id} has no method bound. Set one via PATCH /v1/preparations/${storedPrep.id} { "method_id": "<id>" } before verifying.`);
684
+ sendError(res, 400, `Preparation ${storedPrep.id} has no Build Plan selected. Select one via PATCH /v1/preparations/${storedPrep.id} { "method_id": "<id>" } before verifying.`);
601
685
  return true;
602
686
  }
603
687
  try {
@@ -738,6 +822,29 @@ async function routeApi(req, res, runtime) {
738
822
  return true;
739
823
  }
740
824
  }
825
+ else if (subPath.startsWith(`${PREPARATION_SUBRESOURCES.artifacts}/`)) {
826
+ // GET /v1/preparations/<id>/artifacts/<artifact-id> — per-Artifact
827
+ // status from the latest compile run. 0.17.
828
+ if (method === "GET") {
829
+ const rawArtifactId = subPath.slice(PREPARATION_SUBRESOURCES.artifacts.length + 1);
830
+ let artifactId;
831
+ try {
832
+ artifactId = decodeURIComponent(rawArtifactId);
833
+ }
834
+ catch {
835
+ sendError(res, 400, "Artifact id is not valid URI-encoded UTF-8.");
836
+ return true;
837
+ }
838
+ const preparation = runtime.getPreparation(storedPrep.prepDataDir, storedPrep.id);
839
+ const status = preparation?.artifacts.find((entry) => entry.artifact_id === artifactId);
840
+ if (!status) {
841
+ sendError(res, 404, `Artifact not found: ${artifactId}`);
842
+ return true;
843
+ }
844
+ sendJson(res, 200, status);
845
+ return true;
846
+ }
847
+ }
741
848
  sendError(res, 404, `Unknown preparation sub-route: ${subPath}`);
742
849
  return true;
743
850
  }
@@ -745,17 +852,12 @@ async function routeApi(req, res, runtime) {
745
852
  // Method resources — preparation-independent (workspace draft + user lib + bundled).
746
853
  // ─────────────────────────────────────────────────────────────────────────
747
854
  if (method === "GET" && path === LOCAL_SERVICE_ROUTES.methods) {
748
- // The runtime needs SOME prep data dir to discover preparation-draft methods.
749
- // Fall back to the first registered preparation (if any) so user-library
750
- // and bundled methods still surface even when no preparation has drafts.
751
- const firstPrep = listStoredPreparations()[0];
752
- sendJson(res, 200, { methods: runtime.listMethods(firstPrep?.prepDataDir ?? runtime.rootPath) });
855
+ sendJson(res, 200, { methods: listInstanceMethods() });
753
856
  return true;
754
857
  }
755
858
  const methodMatch = path.match(/^\/v1\/methods\/([^/]+)$/);
756
859
  if (method === "GET" && methodMatch?.[1]) {
757
- const firstPrep = listStoredPreparations()[0];
758
- const methodResource = runtime.getMethod(firstPrep?.prepDataDir ?? runtime.rootPath, decodeURIComponent(methodMatch[1]));
860
+ const methodResource = findInstanceMethod(decodeURIComponent(methodMatch[1]));
759
861
  if (!methodResource)
760
862
  sendError(res, 404, "Method not found.");
761
863
  else
@@ -764,8 +866,7 @@ async function routeApi(req, res, runtime) {
764
866
  }
765
867
  const methodRunsMatch = path.match(/^\/v1\/methods\/([^/]+)\/runs$/);
766
868
  if (method === "GET" && methodRunsMatch?.[1]) {
767
- const firstPrep = listStoredPreparations()[0];
768
- const runs = runtime.listMethodRuns(firstPrep?.prepDataDir ?? runtime.rootPath, decodeURIComponent(methodRunsMatch[1]));
869
+ const runs = listInstanceMethodRuns(decodeURIComponent(methodRunsMatch[1]));
769
870
  sendJson(res, 200, { runs });
770
871
  return true;
771
872
  }
@@ -790,8 +891,7 @@ async function routeApi(req, res, runtime) {
790
891
  sendError(res, 400, "File path escapes method root.");
791
892
  return true;
792
893
  }
793
- const firstPrep = listStoredPreparations()[0];
794
- const root = resolveMethodPackageRoot(methodId, firstPrep?.prepDataDir);
894
+ const root = resolveInstanceMethodPackageRoot(methodId);
795
895
  if (!root) {
796
896
  sendError(res, 404, `Method not found: ${methodId}`);
797
897
  return true;
@@ -811,14 +911,12 @@ async function routeApi(req, res, runtime) {
811
911
  // so the runtime takes a "first prep" hint to scan registered preparations.
812
912
  // ─────────────────────────────────────────────────────────────────────────
813
913
  if (method === "GET" && path === LOCAL_SERVICE_ROUTES.runs) {
814
- const firstPrep = listStoredPreparations()[0];
815
- sendJson(res, 200, { runs: runtime.listRunObservability(firstPrep?.prepDataDir ?? runtime.rootPath) });
914
+ sendJson(res, 200, { runs: listInstanceRuns() });
816
915
  return true;
817
916
  }
818
917
  const observableRunMatch = path.match(/^\/v1\/runs\/([^/]+)$/);
819
918
  if (method === "GET" && observableRunMatch?.[1]) {
820
- const firstPrep = listStoredPreparations()[0];
821
- const run = runtime.getRunObservability(firstPrep?.prepDataDir ?? runtime.rootPath, decodeURIComponent(observableRunMatch[1]));
919
+ const run = findInstanceRun(decodeURIComponent(observableRunMatch[1]));
822
920
  if (!run)
823
921
  sendError(res, 404, "Run not found.");
824
922
  else
@@ -931,18 +1029,16 @@ async function routeApi(req, res, runtime) {
931
1029
  if (jobMatch?.[1]) {
932
1030
  const runId = decodeURIComponent(jobMatch[1]);
933
1031
  const child = jobMatch[2];
934
- const firstPrep = listStoredPreparations()[0];
935
- const prepDataDir = firstPrep?.prepDataDir ?? runtime.rootPath;
1032
+ const found = findInstanceJob(runId);
936
1033
  if (method === "GET" && !child) {
937
- const job = runtime.getJob(prepDataDir, runId);
938
- if (!job)
1034
+ if (!found)
939
1035
  sendError(res, 404, "Job run not found.");
940
1036
  else
941
- sendJson(res, 200, job);
1037
+ sendJson(res, 200, found.job);
942
1038
  return true;
943
1039
  }
944
1040
  if (method === "GET" && child === "events") {
945
- const events = runtime.getJobEvents(prepDataDir, runId);
1041
+ const events = found ? runtime.getJobEvents(found.prepDataDir, runId) : null;
946
1042
  if (!events)
947
1043
  sendError(res, 404, "Job run not found.");
948
1044
  else
@@ -1074,7 +1170,7 @@ async function routeApi(req, res, runtime) {
1074
1170
  allowedRoots.push(stored.source.locator);
1075
1171
  }
1076
1172
  allowedRoots.push(userMethodsRoot());
1077
- allowedRoots.push(packageRoot()); // covers <pkg>/builtin-methods/...
1173
+ allowedRoots.push(packageRoot()); // covers <pkg>/public-repo/methods/...
1078
1174
  const openedPath = await openLocalPath(allowedRoots, body.path);
1079
1175
  sendJson(res, 202, { opened: true, path: openedPath });
1080
1176
  return true;
@@ -1181,7 +1277,22 @@ export async function startLocalService(options = {}) {
1181
1277
  packageVersion: options.packageVersion,
1182
1278
  handlers: options.handlers,
1183
1279
  ...(authToken ? { authToken } : {}),
1280
+ // 0.17 — forward cloud-variant injection points. Local default
1281
+ // ignores idempotencyStore / runLeaseStore (the runtime's
1282
+ // in-process maps stay authoritative); they're accepted on the
1283
+ // options surface so cloud forks have a stable target.
1284
+ ...(options.billingEventSink ? { billingEventSink: options.billingEventSink } : {}),
1285
+ ...(options.idempotencyStore ? { idempotencyStore: options.idempotencyStore } : {}),
1286
+ ...(options.runLeaseStore ? { runLeaseStore: options.runLeaseStore } : {}),
1184
1287
  });
1288
+ // 0.17 — token validator (B4.3). Local default: undefined. Cloud
1289
+ // variants pass an async per-account validator. Stashed on the
1290
+ // runtime via `setTokenValidator` so `isAuthorizedMutation` can
1291
+ // pick it up; the local engine ignores it (the static bearer
1292
+ // check still runs).
1293
+ if (options.tokenValidator) {
1294
+ runtime.setTokenValidator(options.tokenValidator);
1295
+ }
1185
1296
  // Rehydrate 0.13 preparations as synthetic workspaces so subsequent
1186
1297
  // compile / test / readiness calls find them after a service restart.
1187
1298
  try {
@@ -1,13 +1,13 @@
1
1
  export * as schema from "./lib/schema.js";
2
- export * as test from "./test.js";
3
- export * as execution from "./test-execution.js";
4
- export * as paths from "./test-paths.js";
5
- export * as profilePresets from "./test-profile-presets.js";
2
+ export * as verify from "./verify.js";
3
+ export * as execution from "./verify-execution.js";
4
+ export * as paths from "./verify-paths.js";
5
+ export * as profilePresets from "./verify-profile-presets.js";
6
6
  export * as readinessCheckRun from "./readiness-check-run.js";
7
- export * as sandbox from "./test-sandbox.js";
8
- export * as specs from "./test-specs.js";
9
- export * as targets from "./test-targets.js";
10
- export * as types from "./test-types.js";
7
+ export * as sandbox from "./verify-sandbox.js";
8
+ export * as specs from "./verify-specs.js";
9
+ export * as targets from "./verify-targets.js";
10
+ export * as types from "./verify-types.js";
11
11
  export type { TestCase, TestCaseExpect, TestCheckResult, TestCaseResult, TestSpec, TestTargetResult, TestTargetRun, ReadinessCheckRun, TestTargetType, } from "./lib/schema.js";
12
- export type { LoadedTestSpec, TestTargetCandidate, } from "./test-types.js";
13
- export type { TestSandboxRetentionMode, } from "./test-sandbox.js";
12
+ export type { LoadedTestSpec, TestTargetCandidate, } from "./verify-types.js";
13
+ export type { TestSandboxRetentionMode, } from "./verify-sandbox.js";
@@ -1,10 +1,10 @@
1
1
  export * as schema from "./lib/schema.js";
2
- export * as test from "./test.js";
3
- export * as execution from "./test-execution.js";
4
- export * as paths from "./test-paths.js";
5
- export * as profilePresets from "./test-profile-presets.js";
2
+ export * as verify from "./verify.js";
3
+ export * as execution from "./verify-execution.js";
4
+ export * as paths from "./verify-paths.js";
5
+ export * as profilePresets from "./verify-profile-presets.js";
6
6
  export * as readinessCheckRun from "./readiness-check-run.js";
7
- export * as sandbox from "./test-sandbox.js";
8
- export * as specs from "./test-specs.js";
9
- export * as targets from "./test-targets.js";
10
- export * as types from "./test-types.js";
7
+ export * as sandbox from "./verify-sandbox.js";
8
+ export * as specs from "./verify-specs.js";
9
+ export * as targets from "./verify-targets.js";
10
+ export * as types from "./verify-types.js";
@@ -1,7 +1,8 @@
1
1
  import type { MethodExecutor } from "../agents/lib/executors.js";
2
2
  import type { SourcePreparationConfig } from "../../project/lib/schema.js";
3
- import { type TestTargetCandidate, type TestTargetResult } from "./test.js";
4
- import type { TestSandboxRetentionMode } from "./test-sandbox.js";
3
+ import type { TestTargetType } from "../../contracts/lib/schema.js";
4
+ import { type TestTargetCandidate, type TestTargetResult } from "./verify.js";
5
+ import type { TestSandboxRetentionMode } from "./verify-sandbox.js";
5
6
  import { type ReadinessCheckRun } from "./lib/schema.js";
6
7
  export interface SavedReadinessCheckOutcome {
7
8
  runPath: string;
@@ -14,8 +15,9 @@ export interface ReadinessCheckRunResult {
14
15
  preparationConfig: SourcePreparationConfig;
15
16
  portableContextPath: string | null;
16
17
  /**
17
- * 0.15`sourceFilesOutcome` is always `null`. Kept on the type so
18
- * older readers parse cleanly during the rollout; remove in 0.16+.
18
+ * 0.17restored. Populated when the verify run targets
19
+ * `source-files`; null when targeting `compiled`. Aggregates back
20
+ * onto the saved `ReadinessCheckRun` payload's `source_files` field.
19
21
  */
20
22
  sourceFilesOutcome: SavedReadinessCheckOutcome | null;
21
23
  compiledOutcome: SavedReadinessCheckOutcome | null;
@@ -39,6 +41,7 @@ export declare function saveReadinessCheckRun(options: {
39
41
  portableContextPath: string | null;
40
42
  preparationName: string;
41
43
  checksFingerprint: string;
44
+ sourceFilesOutcome?: SavedReadinessCheckOutcome | null;
42
45
  compiledOutcome: SavedReadinessCheckOutcome | null;
43
46
  }): string;
44
47
  export declare function runSavedPortableContextCheck(options: {
@@ -49,6 +52,20 @@ export declare function runSavedPortableContextCheck(options: {
49
52
  preserveSandboxes?: TestSandboxRetentionMode;
50
53
  runSuffix?: string | null;
51
54
  }): Promise<SavedReadinessCheckOutcome | null>;
55
+ /**
56
+ * 0.17 — restored. Runs the saved readiness checks against the source
57
+ * folder baseline (no portable-context indirection) so users can see how
58
+ * much value the Method actually adds. The lower-level `verify-execution`
59
+ * + `verify-sandbox` source-files paths have stayed in tree since 0.13;
60
+ * this is the orchestrator hook that was missing.
61
+ */
62
+ export declare function runSavedSourceFilesCheck(options: {
63
+ sourcePath: string;
64
+ preparationConfig: SourcePreparationConfig;
65
+ executor?: MethodExecutor | null;
66
+ preserveSandboxes?: TestSandboxRetentionMode;
67
+ runSuffix?: string | null;
68
+ }): Promise<SavedReadinessCheckOutcome | null>;
52
69
  export declare function runReadinessChecksForExecutor(options: {
53
70
  sourcePath: string;
54
71
  preparationConfig: SourcePreparationConfig;
@@ -57,4 +74,10 @@ export declare function runReadinessChecksForExecutor(options: {
57
74
  preserveSandboxes?: TestSandboxRetentionMode;
58
75
  runSuffix?: string | null;
59
76
  saveLatest?: boolean;
77
+ /**
78
+ * 0.17 — selects which target the readiness checks judge against.
79
+ * Defaults to `compiled` for backward compatibility with existing
80
+ * callers.
81
+ */
82
+ target?: TestTargetType;
60
83
  }): Promise<ReadinessCheckRunResult>;