@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,466 @@
1
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from "node:fs";
2
+ import { dirname, join, relative } from "node:path";
3
+ import { z } from "zod";
4
+ import { listFilesRecursive } from "../shared/filesystem.js";
5
+ import { warnInterf } from "../shared/logger.js";
6
+ import { readJsonFileUnchecked, readJsonFileWithSchema } from "../shared/parse.js";
7
+ import { isMarkdownFile } from "../shared/file-types.js";
8
+ import { MethodCompilerApiSchema, RuntimeStageAcceptanceSchema, MethodPurposeSchema, MethodStageZoneAccessSchema, } from "../compiler/lib/schema.js";
9
+ import { RuntimeContractTypeSchema, InterfIdPattern, } from "../contracts/lib/schema.js";
10
+ import { listBuiltinCompiledZoneSpecs, } from "./builtin-compiled-method.js";
11
+ import { CONTEXT_INTERFACE_FILE, ContextInterfaceSchema, contextInterfaceExists, contextInterfaceFilePath, readContextInterface, MethodInputSpecSchema, writeContextInterface, } from "./context-interface.js";
12
+ import { PACKAGE_ROOT } from "./lib/package-root.js";
13
+ import { mergeStagePolicyNotesForStages } from "./method-stage-policy.js";
14
+ const LocalMethodStageDefinitionSchema = z.object({
15
+ id: z.string().regex(InterfIdPattern),
16
+ label: z.string().min(1),
17
+ contract_type: RuntimeContractTypeSchema,
18
+ skill_dir: z.string().regex(InterfIdPattern).optional(),
19
+ description: z.string().min(1).optional(),
20
+ reads: MethodStageZoneAccessSchema,
21
+ writes: MethodStageZoneAccessSchema,
22
+ acceptance: RuntimeStageAcceptanceSchema.optional(),
23
+ });
24
+ const LocalMethodDefinitionSchema = z.object({
25
+ id: z.string().regex(InterfIdPattern),
26
+ type: z.literal("compiled"),
27
+ compiler_api: MethodCompilerApiSchema.optional(),
28
+ purpose: MethodPurposeSchema.optional(),
29
+ inputs: z.array(MethodInputSpecSchema).min(1).optional(),
30
+ label: z.string().min(1),
31
+ hint: z.string().min(1),
32
+ stages: z.array(LocalMethodStageDefinitionSchema).min(1).optional(),
33
+ stage_policy_notes: z.record(z.string(), z.array(z.string())).optional(),
34
+ });
35
+ function methodRootPath(sourcePath) {
36
+ return join(sourcePath, "interf", "methods");
37
+ }
38
+ function builtinMethodRootPath(methodId) {
39
+ return join(PACKAGE_ROOT, "builtin-methods", methodId);
40
+ }
41
+ export function methodDefinitionPath(sourcePath, id) {
42
+ return join(methodRootPath(sourcePath), id);
43
+ }
44
+ function isSupportedMethodStarterDocPath(relativePath) {
45
+ if (relativePath === "README.md")
46
+ return true;
47
+ if (relativePath.startsWith("improve/"))
48
+ return true;
49
+ if (relativePath.startsWith("use/query/"))
50
+ return true;
51
+ if (relativePath.startsWith("compile/stages/"))
52
+ return true;
53
+ return false;
54
+ }
55
+ function collectStarterDocs(dirPath) {
56
+ return listFilesRecursive(dirPath, isMarkdownFile)
57
+ .map((filePath) => relative(dirPath, filePath).replaceAll("\\", "/"))
58
+ .filter((relativePath) => isSupportedMethodStarterDocPath(relativePath))
59
+ .map((relativePath) => ({
60
+ relativePath,
61
+ content: readFileSync(join(dirPath, relativePath), "utf8"),
62
+ }))
63
+ .sort((a, b) => a.relativePath.localeCompare(b.relativePath));
64
+ }
65
+ function methodPackageCopyPaths(dirPath) {
66
+ return [
67
+ "method.json",
68
+ CONTEXT_INTERFACE_FILE,
69
+ ...collectStarterDocs(dirPath).map((doc) => doc.relativePath),
70
+ ];
71
+ }
72
+ function copyRelativeFile(sourceRoot, targetRoot, relativePath) {
73
+ const sourcePath = join(sourceRoot, relativePath);
74
+ if (!existsSync(sourcePath))
75
+ return;
76
+ const targetPath = join(targetRoot, relativePath);
77
+ mkdirSync(dirname(targetPath), { recursive: true });
78
+ cpSync(sourcePath, targetPath, { force: true });
79
+ }
80
+ function copyMethodPackageFiles(sourceMethodPath, targetMethodPath) {
81
+ rmSync(targetMethodPath, { recursive: true, force: true });
82
+ mkdirSync(targetMethodPath, { recursive: true });
83
+ for (const relativePath of methodPackageCopyPaths(sourceMethodPath)) {
84
+ copyRelativeFile(sourceMethodPath, targetMethodPath, relativePath);
85
+ }
86
+ }
87
+ export function loadMethodDefinitionFromDir(dirPath) {
88
+ const methodPath = existsSync(join(dirPath, "method.json"))
89
+ ? join(dirPath, "method.json")
90
+ : null;
91
+ if (!methodPath)
92
+ return null;
93
+ const definition = readJsonFileWithSchema(methodPath, "local Method definition", LocalMethodDefinitionSchema);
94
+ if (!definition)
95
+ return null;
96
+ const methodSchema = readContextInterface(dirPath);
97
+ if (!methodSchema)
98
+ return null;
99
+ if (definition.type !== "compiled") {
100
+ warnInterf(`Warning: local Method definition at ${methodPath} has unexpected type "${definition.type}".`);
101
+ return null;
102
+ }
103
+ return {
104
+ ...definition,
105
+ method_schema: methodSchema,
106
+ starter_docs: collectStarterDocs(dirPath),
107
+ directoryPath: dirPath,
108
+ methodPath,
109
+ methodSchemaPath: contextInterfaceFilePath(dirPath),
110
+ };
111
+ }
112
+ export function listLocalMethodDefinitions(sourcePath) {
113
+ const definitions = new Map();
114
+ const root = methodRootPath(sourcePath);
115
+ if (existsSync(root)) {
116
+ for (const entryPath of readdirSync(root).map((entry) => join(root, entry))) {
117
+ try {
118
+ if (!statSync(entryPath).isDirectory())
119
+ continue;
120
+ }
121
+ catch {
122
+ continue;
123
+ }
124
+ const definition = loadMethodDefinitionFromDir(entryPath);
125
+ if (definition)
126
+ definitions.set(definition.id, definition);
127
+ }
128
+ }
129
+ return [...definitions.values()].sort((a, b) => a.label.localeCompare(b.label));
130
+ }
131
+ export function loadLocalMethodDefinition(sourcePath, id) {
132
+ return loadMethodDefinitionFromDir(methodDefinitionPath(sourcePath, id));
133
+ }
134
+ export function resolveMethodPackageSourcePath(sourcePath, methodId) {
135
+ const localPath = methodDefinitionPath(sourcePath, methodId);
136
+ if (loadMethodDefinitionFromDir(localPath))
137
+ return localPath;
138
+ const builtinPath = builtinMethodRootPath(methodId);
139
+ if (loadMethodDefinitionFromDir(builtinPath))
140
+ return builtinPath;
141
+ return null;
142
+ }
143
+ export function seedLocalDefaultMethod(options) {
144
+ const methodId = "interf-default";
145
+ const targetPath = methodDefinitionPath(options.sourcePath, methodId);
146
+ if (existsSync(join(targetPath, "method.json"))) {
147
+ return { methodId, targetPath, alreadyExisted: true };
148
+ }
149
+ const builtinInterfPath = builtinMethodRootPath(methodId);
150
+ if (!existsSync(join(builtinInterfPath, "method.json"))) {
151
+ throw new Error(`Built-in "${methodId}" Method package not found at ${builtinInterfPath}.`);
152
+ }
153
+ copyMethodPackageDirectory(builtinInterfPath, targetPath);
154
+ patchMethodPackageMetadata(targetPath, {
155
+ id: methodId,
156
+ label: "Built-in Interf Method",
157
+ hint: "Built-in file-processing Method: summarize source-grounded evidence, structure cross-file connections, and shape portable context around the saved readiness checks.",
158
+ });
159
+ return { methodId, targetPath, alreadyExisted: false };
160
+ }
161
+ export function isMethodId(value) {
162
+ return InterfIdPattern.test(value);
163
+ }
164
+ function readMethodJsonObject(dirPath) {
165
+ const methodPath = join(dirPath, "method.json");
166
+ const raw = readJsonFileUnchecked(methodPath, "Method package");
167
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
168
+ throw new Error(`Method package at ${dirPath} is missing a valid method.json.`);
169
+ }
170
+ return { ...raw };
171
+ }
172
+ export function patchMethodPackageMetadata(dirPath, options = {}) {
173
+ const methodPath = join(dirPath, "method.json");
174
+ const methodJson = readMethodJsonObject(dirPath);
175
+ const normalizedStages = Array.isArray(methodJson.stages) && methodJson.stages.length > 0
176
+ ? methodJson.stages
177
+ : null;
178
+ if (!normalizedStages) {
179
+ throw new Error(`Cannot patch Method package at ${dirPath}: method.json must declare explicit stages before it can be copied or rewritten.`);
180
+ }
181
+ const nextMethodJson = {
182
+ ...methodJson,
183
+ type: "compiled",
184
+ compiler_api: methodJson.compiler_api ?? {
185
+ kind: "compiled",
186
+ version: 1,
187
+ },
188
+ stages: normalizedStages,
189
+ ...(options.id ? { id: options.id } : {}),
190
+ ...(options.inputs && options.inputs.length > 0 ? { inputs: options.inputs } : {}),
191
+ ...(options.label ? { label: options.label } : {}),
192
+ ...(options.hint ? { hint: options.hint } : {}),
193
+ };
194
+ const mergedStagePolicyNotes = mergeStagePolicyNotesForStages(normalizedStages, methodJson.stage_policy_notes, options.stagePolicyNotes);
195
+ if (mergedStagePolicyNotes) {
196
+ nextMethodJson.stage_policy_notes = mergedStagePolicyNotes;
197
+ }
198
+ else {
199
+ delete nextMethodJson.stage_policy_notes;
200
+ }
201
+ writeFileSync(methodPath, JSON.stringify(nextMethodJson, null, 2) + "\n");
202
+ const schemaLabel = `${String(nextMethodJson.label ?? methodJson.label ?? options.id ?? "Method")} Method schema`;
203
+ const existingSchema = readContextInterface(dirPath);
204
+ if (!existingSchema) {
205
+ throw new Error(`Cannot patch Method package at ${dirPath}: missing ${CONTEXT_INTERFACE_FILE}. Restore or reseed the package instead of regenerating a schema from method.json.`);
206
+ }
207
+ writeContextInterface(dirPath, {
208
+ ...existingSchema,
209
+ label: schemaLabel,
210
+ });
211
+ }
212
+ function collectMethodPackageStructureIssues(dirPath, stages) {
213
+ const issues = [];
214
+ const methodPath = join(dirPath, "method.json");
215
+ if (!existsSync(methodPath))
216
+ issues.push("missing method.json");
217
+ if (!contextInterfaceExists(dirPath))
218
+ issues.push("missing method.schema.json");
219
+ if (!existsSync(join(dirPath, "README.md")))
220
+ issues.push("missing README.md");
221
+ if (!existsSync(join(dirPath, "improve", "SKILL.md")))
222
+ issues.push("missing improve/SKILL.md");
223
+ if (!existsSync(join(dirPath, "use", "query", "SKILL.md")))
224
+ issues.push("missing use/query/SKILL.md");
225
+ if (!stages)
226
+ return issues;
227
+ for (const stage of stages) {
228
+ const skillDir = typeof stage.skill_dir === "string" && stage.skill_dir.trim().length > 0
229
+ ? stage.skill_dir
230
+ : stage.id;
231
+ if (!existsSync(join(dirPath, "compile", "stages", skillDir, "SKILL.md"))) {
232
+ issues.push(`missing compile/stages/${skillDir}/SKILL.md`);
233
+ }
234
+ }
235
+ return issues;
236
+ }
237
+ function collectMethodStageSkillIssues(dirPath, stages) {
238
+ if (!stages)
239
+ return [];
240
+ const issues = [];
241
+ for (const stage of stages) {
242
+ const skillDir = typeof stage.skill_dir === "string" && stage.skill_dir.trim().length > 0
243
+ ? stage.skill_dir
244
+ : stage.id;
245
+ if (!existsSync(join(dirPath, "compile", "stages", skillDir, "SKILL.md"))) {
246
+ issues.push(`missing compile/stages/${skillDir}/SKILL.md`);
247
+ }
248
+ }
249
+ return issues;
250
+ }
251
+ export function describeMethodPackagePortability(dirPath) {
252
+ const issues = collectMethodPackageStructureIssues(dirPath, null);
253
+ if (issues.length > 0)
254
+ return issues;
255
+ let methodJson;
256
+ try {
257
+ methodJson = readMethodJsonObject(dirPath);
258
+ }
259
+ catch (error) {
260
+ issues.push(error instanceof Error ? error.message : String(error));
261
+ return issues;
262
+ }
263
+ const parsed = LocalMethodDefinitionSchema.safeParse(methodJson);
264
+ if (!parsed.success) {
265
+ issues.push(...parsed.error.issues.map((issue) => issue.path.length > 0
266
+ ? `method.json ${issue.path.join(".")}: ${issue.message}`
267
+ : `method.json: ${issue.message}`));
268
+ return issues;
269
+ }
270
+ if (!parsed.data.stages || parsed.data.stages.length === 0) {
271
+ issues.push("method.json must declare explicit stages for a portable Method package");
272
+ return issues;
273
+ }
274
+ return [
275
+ ...issues,
276
+ ...collectMethodStageSkillIssues(dirPath, parsed.data.stages ?? null),
277
+ ];
278
+ }
279
+ export function isPortableMethodPackage(dirPath) {
280
+ return describeMethodPackagePortability(dirPath).length === 0;
281
+ }
282
+ export function copyMethodPackageDirectory(sourceMethodPath, targetMethodPath) {
283
+ const portabilityIssues = describeMethodPackagePortability(sourceMethodPath);
284
+ if (portabilityIssues.length > 0) {
285
+ throw new Error(`Method package at ${sourceMethodPath} is not directly copyable: ${portabilityIssues.join("; ")}.`);
286
+ }
287
+ mkdirSync(dirname(targetMethodPath), { recursive: true });
288
+ copyMethodPackageFiles(sourceMethodPath, targetMethodPath);
289
+ }
290
+ export function validateMethodPackage(dirPath) {
291
+ const methodPath = join(dirPath, "method.json");
292
+ if (!existsSync(methodPath)) {
293
+ return {
294
+ ok: false,
295
+ summary: `No method.json found at ${dirPath}`,
296
+ errors: ["Missing method.json"],
297
+ counts: {},
298
+ };
299
+ }
300
+ const raw = readJsonFileUnchecked(methodPath, "Method package");
301
+ if (!raw) {
302
+ return {
303
+ ok: false,
304
+ summary: `Failed to parse method.json at ${methodPath}`,
305
+ errors: ["Invalid JSON in method.json"],
306
+ counts: {},
307
+ };
308
+ }
309
+ const parsed = LocalMethodDefinitionSchema.safeParse(raw);
310
+ if (!parsed.success) {
311
+ const issues = parsed.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`);
312
+ return {
313
+ ok: false,
314
+ summary: `method.json failed validation: ${issues.length} issue(s)`,
315
+ errors: issues,
316
+ counts: {},
317
+ };
318
+ }
319
+ const def = parsed.data;
320
+ const errors = [];
321
+ if (!def.stages || def.stages.length === 0) {
322
+ errors.push("method.json must declare explicit stages.");
323
+ }
324
+ if (def.stage_policy_notes && def.stages) {
325
+ const stageIds = new Set(def.stages.map((stage) => stage.id));
326
+ for (const stageId of Object.keys(def.stage_policy_notes)) {
327
+ if (!stageIds.has(stageId)) {
328
+ errors.push(`method.json stage_policy_notes references unknown stage "${stageId}".`);
329
+ }
330
+ }
331
+ }
332
+ for (const issue of collectMethodPackageStructureIssues(dirPath, def.stages ?? null)) {
333
+ const formatted = issue.startsWith("missing ")
334
+ ? `Missing ${issue.slice("missing ".length)}.`
335
+ : issue;
336
+ errors.push(formatted);
337
+ }
338
+ const methodSchema = readContextInterface(dirPath);
339
+ if (!methodSchema) {
340
+ errors.push(...describeContextInterfaceValidationIssues(dirPath));
341
+ }
342
+ if (methodSchema) {
343
+ const stages = def.stages ?? [];
344
+ const stageIds = new Set(stages.map((stage) => stage.id));
345
+ const seenPaths = new Map();
346
+ const seenZoneIds = new Set();
347
+ const zoneById = new Map(methodSchema.zones.map((zone) => [zone.id, zone]));
348
+ const normalizedParts = (value) => value.replaceAll("\\", "/").split("/").filter(Boolean);
349
+ const hasOverlappingPath = (value, other) => {
350
+ const a = normalizedParts(value);
351
+ const b = normalizedParts(other);
352
+ const shorter = a.length <= b.length ? a : b;
353
+ const longer = a.length <= b.length ? b : a;
354
+ return shorter.every((part, index) => longer[index] === part);
355
+ };
356
+ for (const zone of methodSchema.zones) {
357
+ if (seenZoneIds.has(zone.id)) {
358
+ errors.push(`method.schema.json repeats zone id "${zone.id}".`);
359
+ }
360
+ seenZoneIds.add(zone.id);
361
+ const existingPathOwner = seenPaths.get(zone.path);
362
+ if (existingPathOwner) {
363
+ errors.push(`method.schema.json repeats zone path "${zone.path}".`);
364
+ }
365
+ for (const [existingPath, existingZoneId] of seenPaths.entries()) {
366
+ if (existingPath === zone.path)
367
+ continue;
368
+ if (hasOverlappingPath(zone.path, existingPath)) {
369
+ errors.push(`method.schema.json zones "${zone.id}" and "${existingZoneId}" overlap on path "${zone.path}" / "${existingPath}".`);
370
+ }
371
+ }
372
+ seenPaths.set(zone.path, zone.id);
373
+ if ((zone.role === "input" || zone.role === "runtime") && zone.owned_by.length > 0) {
374
+ errors.push(`method.schema.json zone "${zone.id}" cannot declare owners because its role is "${zone.role}".`);
375
+ }
376
+ for (const owner of zone.owned_by) {
377
+ if (!stageIds.has(owner)) {
378
+ errors.push(`method.schema.json references unknown stage "${owner}" for zone "${zone.path}".`);
379
+ }
380
+ }
381
+ }
382
+ for (const stage of stages) {
383
+ for (const zoneId of stage.reads) {
384
+ if (!zoneById.has(zoneId)) {
385
+ errors.push(`Stage "${stage.id}" reads unknown zone "${zoneId}".`);
386
+ }
387
+ }
388
+ for (const zoneId of stage.writes) {
389
+ const zone = zoneById.get(zoneId);
390
+ if (!zone) {
391
+ errors.push(`Stage "${stage.id}" writes unknown zone "${zoneId}".`);
392
+ continue;
393
+ }
394
+ if (zone.role === "input" || zone.role === "runtime") {
395
+ errors.push(`Stage "${stage.id}" writes zone "${zoneId}" but zones with role "${zone.role}" are engine-owned inputs, not writable stage outputs.`);
396
+ }
397
+ if (!zone.owned_by.includes(stage.id)) {
398
+ errors.push(`Stage "${stage.id}" writes zone "${zoneId}" but that zone is not owned by the stage in method.schema.json.`);
399
+ }
400
+ }
401
+ for (const artifactPath of Object.keys(stage.acceptance?.artifacts_must_not_contain ?? {})) {
402
+ const normalizedArtifactPath = artifactPath.replaceAll("\\", "/");
403
+ const artifactParts = normalizedArtifactPath.split("/").filter(Boolean);
404
+ if (artifactPath.startsWith("/") ||
405
+ artifactPath.startsWith("\\") ||
406
+ artifactParts.some((part) => part === "..")) {
407
+ errors.push(`Stage "${stage.id}" artifacts_must_not_contain key "${artifactPath}" must be a portable-context relative artifact path.`);
408
+ continue;
409
+ }
410
+ const matchingZone = zoneById.get(artifactPath);
411
+ if (matchingZone) {
412
+ errors.push(`Stage "${stage.id}" artifacts_must_not_contain key "${artifactPath}" is a zone id. Use the zone path "${matchingZone.path}" instead.`);
413
+ }
414
+ }
415
+ }
416
+ for (const requiredZone of listBuiltinCompiledZoneSpecs().filter((zone) => zone.id === "raw" || zone.id === "runtime")) {
417
+ const match = zoneById.get(requiredZone.id);
418
+ if (!match) {
419
+ errors.push(`method.schema.json is missing required zone "${requiredZone.id}".`);
420
+ continue;
421
+ }
422
+ if (match.kind !== requiredZone.kind) {
423
+ errors.push(`method.schema.json zone "${requiredZone.id}" should be kind "${requiredZone.kind}".`);
424
+ }
425
+ if (match.role !== requiredZone.role) {
426
+ errors.push(`method.schema.json zone "${requiredZone.id}" should have role "${requiredZone.role}".`);
427
+ }
428
+ }
429
+ }
430
+ const stageDirs = existsSync(join(dirPath, "compile", "stages"))
431
+ ? listFilesRecursive(join(dirPath, "compile", "stages"), (filePath) => basename(filePath) === "SKILL.md")
432
+ : [];
433
+ const counts = {
434
+ starter_docs: collectStarterDocs(dirPath).length,
435
+ compile_stage_docs: stageDirs.length,
436
+ compiled_zones: methodSchema?.zones.length ?? 0,
437
+ method_zones: methodSchema?.zones.length ?? 0,
438
+ };
439
+ return {
440
+ ok: errors.length === 0,
441
+ summary: errors.length === 0 ? "Method package is valid." : `Method package has ${errors.length} issue(s).`,
442
+ errors,
443
+ counts,
444
+ };
445
+ }
446
+ function describeContextInterfaceValidationIssues(dirPath) {
447
+ const methodSchemaPath = contextInterfaceFilePath(dirPath);
448
+ if (!existsSync(methodSchemaPath)) {
449
+ return ["method.schema.json is missing."];
450
+ }
451
+ const raw = readJsonFileUnchecked(methodSchemaPath, "Method context interface");
452
+ if (raw === null) {
453
+ return ["method.schema.json is invalid JSON."];
454
+ }
455
+ const parsed = ContextInterfaceSchema.safeParse(raw);
456
+ if (parsed.success) {
457
+ return ["method.schema.json is missing or invalid."];
458
+ }
459
+ return parsed.error.issues.map((issue) => {
460
+ const path = issue.path.length > 0 ? issue.path.join(".") : "<root>";
461
+ return `method.schema.json ${path}: ${issue.message}`;
462
+ });
463
+ }
464
+ function basename(filePath) {
465
+ return filePath.split(/[\\/]/).pop() ?? filePath;
466
+ }
@@ -0,0 +1,83 @@
1
+ import type { RuntimeStageAcceptance, MethodCompilerApi } from "../compiler/lib/schema.js";
2
+ import type { MethodId, RuntimeContractType } from "../contracts/lib/schema.js";
3
+ import { type ContextInterface, type ContextInterfaceZoneId, type MethodInputSpec } from "./context-interface.js";
4
+ export interface MethodStarterDoc {
5
+ relativePath: string;
6
+ content: string;
7
+ }
8
+ export interface MethodStageDefinition {
9
+ id: string;
10
+ label: string;
11
+ description: string;
12
+ contractType: RuntimeContractType;
13
+ skillDir: string;
14
+ reads: ContextInterfaceZoneId[];
15
+ writes: ContextInterfaceZoneId[];
16
+ acceptance?: RuntimeStageAcceptance;
17
+ }
18
+ export interface MethodDefinition<TId extends string> {
19
+ id: TId;
20
+ compilerApi?: MethodCompilerApi;
21
+ purpose?: {
22
+ label: string;
23
+ taskHint: string;
24
+ };
25
+ inputs?: MethodInputSpec[];
26
+ label: string;
27
+ hint: string;
28
+ recommended?: boolean;
29
+ contextInterface?: ContextInterface;
30
+ schema?: ContextInterface;
31
+ stages: MethodStageDefinition[];
32
+ stagePolicyNotes?: Record<string, string[]>;
33
+ starterDocs?: MethodStarterDoc[];
34
+ scope?: "builtin" | "local";
35
+ }
36
+ export type CompiledMethodId = string;
37
+ export declare function standaloneMethodDefinitionFromLocalPackage(local: {
38
+ id: string;
39
+ compiler_api?: MethodCompilerApi;
40
+ purpose?: {
41
+ label: string;
42
+ task_hint: string;
43
+ };
44
+ inputs?: MethodInputSpec[];
45
+ label: string;
46
+ hint: string;
47
+ stages?: Array<{
48
+ id: string;
49
+ label: string;
50
+ description?: string;
51
+ contract_type: RuntimeContractType;
52
+ skill_dir?: string;
53
+ reads: ContextInterfaceZoneId[];
54
+ writes: ContextInterfaceZoneId[];
55
+ acceptance?: RuntimeStageAcceptance;
56
+ }>;
57
+ stage_policy_notes?: Record<string, string[]>;
58
+ method_schema?: ContextInterface;
59
+ starter_docs: MethodStarterDoc[];
60
+ }): MethodDefinition<string>;
61
+ export declare function listCompiledMethodChoices(sourcePath?: string): MethodDefinition<string>[];
62
+ export declare function getCompiledMethod(methodId: CompiledMethodId, options?: {
63
+ sourcePath?: string;
64
+ }): MethodDefinition<string>;
65
+ export declare function getActiveCompiledMethod(compiledPath: string): MethodDefinition<string>;
66
+ export declare function resolveCompiledMethodId(value: unknown): CompiledMethodId | null;
67
+ export declare function resolveCompiledMethodFromConfig(config: unknown): CompiledMethodId | null;
68
+ export declare function resolveRequiredCompiledMethodFromConfig(config: unknown, label?: string): CompiledMethodId;
69
+ export declare function formatCompiledMethodStageStep(methodId: CompiledMethodId, stage: string, options?: {
70
+ sourcePath?: string;
71
+ }): string;
72
+ export declare function getMethodStageDefinition(methodId: MethodId, stage: string, sourcePath?: string): MethodStageDefinition | null;
73
+ export declare function getMethodStagePosition(methodId: MethodId, stage: string, sourcePath?: string): {
74
+ stageIndex: number;
75
+ stageTotal: number;
76
+ stages: string[];
77
+ } | null;
78
+ export declare function getMethodStages(methodId: MethodId, sourcePath?: string): string[];
79
+ export declare function getActiveCompiledStages(compiledPath: string): string[];
80
+ export declare function getMethodStagePolicyNotes(methodId: MethodId, stage: string, sourcePath?: string): string[];
81
+ export declare function getActiveCompiledStagePolicyNotes(compiledPath: string, stage: string): string[];
82
+ export declare function resolveActiveCompiledStageAcceptance(compiledPath: string, stage: string): MethodStageDefinition["acceptance"] | undefined;
83
+ export declare function formatActiveCompiledMethodStageStep(compiledPath: string, stage: string): string;