@caupulican/pi-adaptative 0.90.11 → 0.91.2

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 (291) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +8 -10
  3. package/dist/bundled-resources/skills/icm-architect/LICENSE +21 -0
  4. package/dist/bundled-resources/skills/icm-architect/SKILL.md +112 -0
  5. package/dist/bundled-resources/skills/icm-architect/assets/templates/CLAUDE.md +27 -0
  6. package/dist/bundled-resources/skills/icm-architect/assets/templates/CONTEXT.md +14 -0
  7. package/dist/bundled-resources/skills/icm-architect/assets/templates/node.md +29 -0
  8. package/dist/bundled-resources/skills/icm-architect/assets/templates/object.md +43 -0
  9. package/dist/bundled-resources/skills/icm-architect/assets/templates/process.md +38 -0
  10. package/dist/bundled-resources/skills/icm-architect/assets/templates/questionnaire.md +9 -0
  11. package/dist/bundled-resources/skills/icm-architect/assets/templates/schema.md +24 -0
  12. package/dist/bundled-resources/skills/icm-architect/assets/templates/stage-CONTEXT.md +21 -0
  13. package/dist/bundled-resources/skills/icm-architect/references/core.md +92 -0
  14. package/dist/bundled-resources/skills/icm-architect/references/forms.md +182 -0
  15. package/dist/bundled-resources/skills/icm-architect/references/system-map.md +122 -0
  16. package/dist/cli/args.d.ts.map +1 -1
  17. package/dist/cli/args.js +2 -1
  18. package/dist/cli/args.js.map +1 -1
  19. package/dist/core/agent-paths.d.ts +2 -2
  20. package/dist/core/agent-paths.d.ts.map +1 -1
  21. package/dist/core/agent-paths.js +1 -0
  22. package/dist/core/agent-paths.js.map +1 -1
  23. package/dist/core/agent-session.d.ts +12 -0
  24. package/dist/core/agent-session.d.ts.map +1 -1
  25. package/dist/core/agent-session.js +44 -11
  26. package/dist/core/agent-session.js.map +1 -1
  27. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  28. package/dist/core/autonomy/lane-tool-surface.js +2 -0
  29. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  30. package/dist/core/background-tool-task-controller.d.ts +9 -0
  31. package/dist/core/background-tool-task-controller.d.ts.map +1 -1
  32. package/dist/core/background-tool-task-controller.js +23 -0
  33. package/dist/core/background-tool-task-controller.js.map +1 -1
  34. package/dist/core/bash-executor.js +3 -3
  35. package/dist/core/bash-executor.js.map +1 -1
  36. package/dist/core/context/local-graph-memory-provider.d.ts +9 -0
  37. package/dist/core/context/local-graph-memory-provider.d.ts.map +1 -0
  38. package/dist/core/context/local-graph-memory-provider.js +122 -0
  39. package/dist/core/context/local-graph-memory-provider.js.map +1 -0
  40. package/dist/core/context/tool-output-packer.d.ts +2 -2
  41. package/dist/core/context/tool-output-packer.d.ts.map +1 -1
  42. package/dist/core/context/tool-output-packer.js +3 -3
  43. package/dist/core/context/tool-output-packer.js.map +1 -1
  44. package/dist/core/context-gc.d.ts.map +1 -1
  45. package/dist/core/context-gc.js +2 -0
  46. package/dist/core/context-gc.js.map +1 -1
  47. package/dist/core/default-tool-surface.d.ts.map +1 -1
  48. package/dist/core/default-tool-surface.js +5 -0
  49. package/dist/core/default-tool-surface.js.map +1 -1
  50. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +1 -0
  51. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  52. package/dist/core/delegation/worker-agent-control-coordinator.js +16 -8
  53. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  54. package/dist/core/delegation/worker-agent-control.d.ts +2 -0
  55. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  56. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  57. package/dist/core/delegation/worker-context-inheritance-policy.d.ts +3 -3
  58. package/dist/core/delegation/worker-context-inheritance-policy.js +4 -4
  59. package/dist/core/delegation/worker-context-inheritance-policy.js.map +1 -1
  60. package/dist/core/delegation/worker-delegation-controller.d.ts +1 -5
  61. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  62. package/dist/core/delegation/worker-delegation-controller.js +19 -9
  63. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  64. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +2 -0
  65. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
  66. package/dist/core/delegation/worker-tree-budget-coordinator.js +6 -0
  67. package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
  68. package/dist/core/extensions/extension-session-scope.d.ts +17 -0
  69. package/dist/core/extensions/extension-session-scope.d.ts.map +1 -0
  70. package/dist/core/extensions/extension-session-scope.js +135 -0
  71. package/dist/core/extensions/extension-session-scope.js.map +1 -0
  72. package/dist/core/extensions/index.d.ts +1 -0
  73. package/dist/core/extensions/index.d.ts.map +1 -1
  74. package/dist/core/extensions/index.js +1 -0
  75. package/dist/core/extensions/index.js.map +1 -1
  76. package/dist/core/extensions/runner.d.ts.map +1 -1
  77. package/dist/core/extensions/runner.js +1 -0
  78. package/dist/core/extensions/runner.js.map +1 -1
  79. package/dist/core/extensions/wrapper.d.ts +2 -1
  80. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  81. package/dist/core/extensions/wrapper.js +10 -4
  82. package/dist/core/extensions/wrapper.js.map +1 -1
  83. package/dist/core/foreground-terminal-handoff-controller.d.ts +0 -1
  84. package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
  85. package/dist/core/foreground-terminal-handoff-controller.js +1 -2
  86. package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
  87. package/dist/core/goals/goal-continuation-controller.d.ts +7 -1
  88. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  89. package/dist/core/goals/goal-continuation-controller.js +16 -0
  90. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  91. package/dist/core/goals/goal-runtime-snapshot.d.ts +3 -0
  92. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  93. package/dist/core/goals/goal-runtime-snapshot.js +8 -1
  94. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  95. package/dist/core/goals/goal-session-controller.d.ts +2 -0
  96. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  97. package/dist/core/goals/goal-session-controller.js +1 -0
  98. package/dist/core/goals/goal-session-controller.js.map +1 -1
  99. package/dist/core/goals/goal-tool-core.d.ts +18 -0
  100. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  101. package/dist/core/goals/goal-tool-core.js +62 -0
  102. package/dist/core/goals/goal-tool-core.js.map +1 -1
  103. package/dist/core/goals/natural-language-goal.d.ts.map +1 -1
  104. package/dist/core/goals/natural-language-goal.js +4 -2
  105. package/dist/core/goals/natural-language-goal.js.map +1 -1
  106. package/dist/core/human-input-controller.d.ts +3 -34
  107. package/dist/core/human-input-controller.d.ts.map +1 -1
  108. package/dist/core/human-input-controller.js +3 -161
  109. package/dist/core/human-input-controller.js.map +1 -1
  110. package/dist/core/keybindings.d.ts +5 -0
  111. package/dist/core/keybindings.d.ts.map +1 -1
  112. package/dist/core/keybindings.js +2 -0
  113. package/dist/core/keybindings.js.map +1 -1
  114. package/dist/core/learning/reflection-turn-analysis.d.ts.map +1 -1
  115. package/dist/core/learning/reflection-turn-analysis.js +10 -1
  116. package/dist/core/learning/reflection-turn-analysis.js.map +1 -1
  117. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  118. package/dist/core/memory/providers/file-store.js +4 -0
  119. package/dist/core/memory/providers/file-store.js.map +1 -1
  120. package/dist/core/memory-controller.d.ts +3 -0
  121. package/dist/core/memory-controller.d.ts.map +1 -1
  122. package/dist/core/memory-controller.js +18 -0
  123. package/dist/core/memory-controller.js.map +1 -1
  124. package/dist/core/model-capability.d.ts.map +1 -1
  125. package/dist/core/model-capability.js +1 -0
  126. package/dist/core/model-capability.js.map +1 -1
  127. package/dist/core/orchestration/work-state-projection.d.ts +4 -0
  128. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
  129. package/dist/core/orchestration/work-state-projection.js +11 -0
  130. package/dist/core/orchestration/work-state-projection.js.map +1 -1
  131. package/dist/core/pipelines/context.d.ts +6 -0
  132. package/dist/core/pipelines/context.d.ts.map +1 -0
  133. package/dist/core/pipelines/context.js +102 -0
  134. package/dist/core/pipelines/context.js.map +1 -0
  135. package/dist/core/pipelines/discover.d.ts +11 -0
  136. package/dist/core/pipelines/discover.d.ts.map +1 -0
  137. package/dist/core/pipelines/discover.js +147 -0
  138. package/dist/core/pipelines/discover.js.map +1 -0
  139. package/dist/core/pipelines/increment.d.ts +24 -0
  140. package/dist/core/pipelines/increment.d.ts.map +1 -0
  141. package/dist/core/pipelines/increment.js +121 -0
  142. package/dist/core/pipelines/increment.js.map +1 -0
  143. package/dist/core/pipelines/index.d.ts +8 -0
  144. package/dist/core/pipelines/index.d.ts.map +1 -0
  145. package/dist/core/pipelines/index.js +8 -0
  146. package/dist/core/pipelines/index.js.map +1 -0
  147. package/dist/core/pipelines/parse-contract.d.ts +10 -0
  148. package/dist/core/pipelines/parse-contract.d.ts.map +1 -0
  149. package/dist/core/pipelines/parse-contract.js +105 -0
  150. package/dist/core/pipelines/parse-contract.js.map +1 -0
  151. package/dist/core/pipelines/run-state.d.ts +26 -0
  152. package/dist/core/pipelines/run-state.d.ts.map +1 -0
  153. package/dist/core/pipelines/run-state.js +135 -0
  154. package/dist/core/pipelines/run-state.js.map +1 -0
  155. package/dist/core/pipelines/session-pipeline-run.d.ts +6 -0
  156. package/dist/core/pipelines/session-pipeline-run.d.ts.map +1 -0
  157. package/dist/core/pipelines/session-pipeline-run.js +18 -0
  158. package/dist/core/pipelines/session-pipeline-run.js.map +1 -0
  159. package/dist/core/pipelines/types.d.ts +91 -0
  160. package/dist/core/pipelines/types.d.ts.map +1 -0
  161. package/dist/core/pipelines/types.js +44 -0
  162. package/dist/core/pipelines/types.js.map +1 -0
  163. package/dist/core/reflection-controller.d.ts +2 -0
  164. package/dist/core/reflection-controller.d.ts.map +1 -1
  165. package/dist/core/reflection-controller.js +53 -30
  166. package/dist/core/reflection-controller.js.map +1 -1
  167. package/dist/core/resource-loader.d.ts +21 -0
  168. package/dist/core/resource-loader.d.ts.map +1 -1
  169. package/dist/core/resource-loader.js +45 -18
  170. package/dist/core/resource-loader.js.map +1 -1
  171. package/dist/core/runtime-builder.d.ts +3 -0
  172. package/dist/core/runtime-builder.d.ts.map +1 -1
  173. package/dist/core/runtime-builder.js +49 -1
  174. package/dist/core/runtime-builder.js.map +1 -1
  175. package/dist/core/sdk.d.ts.map +1 -1
  176. package/dist/core/sdk.js +3 -0
  177. package/dist/core/sdk.js.map +1 -1
  178. package/dist/core/session-role.d.ts.map +1 -1
  179. package/dist/core/session-role.js +2 -0
  180. package/dist/core/session-role.js.map +1 -1
  181. package/dist/core/settings-manager.d.ts +12 -0
  182. package/dist/core/settings-manager.d.ts.map +1 -1
  183. package/dist/core/settings-manager.js +43 -9
  184. package/dist/core/settings-manager.js.map +1 -1
  185. package/dist/core/system-prompt-builder.js +1 -1
  186. package/dist/core/system-prompt-builder.js.map +1 -1
  187. package/dist/core/system-prompt.d.ts +1 -1
  188. package/dist/core/system-prompt.d.ts.map +1 -1
  189. package/dist/core/system-prompt.js +30 -22
  190. package/dist/core/system-prompt.js.map +1 -1
  191. package/dist/core/tasks/task-projection.d.ts +2 -0
  192. package/dist/core/tasks/task-projection.d.ts.map +1 -1
  193. package/dist/core/tasks/task-projection.js +1 -0
  194. package/dist/core/tasks/task-projection.js.map +1 -1
  195. package/dist/core/tasks/task-state.d.ts +1 -1
  196. package/dist/core/tasks/task-state.d.ts.map +1 -1
  197. package/dist/core/tasks/task-state.js +10 -3
  198. package/dist/core/tasks/task-state.js.map +1 -1
  199. package/dist/core/tools/bash.d.ts.map +1 -1
  200. package/dist/core/tools/bash.js +11 -3
  201. package/dist/core/tools/bash.js.map +1 -1
  202. package/dist/core/tools/delegate.d.ts.map +1 -1
  203. package/dist/core/tools/delegate.js +9 -3
  204. package/dist/core/tools/delegate.js.map +1 -1
  205. package/dist/core/tools/edit.d.ts.map +1 -1
  206. package/dist/core/tools/edit.js +47 -5
  207. package/dist/core/tools/edit.js.map +1 -1
  208. package/dist/core/tools/goal.d.ts +16 -1
  209. package/dist/core/tools/goal.d.ts.map +1 -1
  210. package/dist/core/tools/goal.js +14 -2
  211. package/dist/core/tools/goal.js.map +1 -1
  212. package/dist/core/tools/index.d.ts +1 -1
  213. package/dist/core/tools/index.d.ts.map +1 -1
  214. package/dist/core/tools/index.js +1 -1
  215. package/dist/core/tools/index.js.map +1 -1
  216. package/dist/core/tools/output-accumulator.d.ts +5 -0
  217. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  218. package/dist/core/tools/output-accumulator.js +33 -2
  219. package/dist/core/tools/output-accumulator.js.map +1 -1
  220. package/dist/core/tools/pipeline.d.ts +35 -0
  221. package/dist/core/tools/pipeline.d.ts.map +1 -0
  222. package/dist/core/tools/pipeline.js +203 -0
  223. package/dist/core/tools/pipeline.js.map +1 -0
  224. package/dist/core/tools/skill-audit.d.ts.map +1 -1
  225. package/dist/core/tools/skill-audit.js +2 -1
  226. package/dist/core/tools/skill-audit.js.map +1 -1
  227. package/dist/core/tools/skill.d.ts.map +1 -1
  228. package/dist/core/tools/skill.js +2 -1
  229. package/dist/core/tools/skill.js.map +1 -1
  230. package/dist/core/tools/skillify.d.ts.map +1 -1
  231. package/dist/core/tools/skillify.js +3 -1
  232. package/dist/core/tools/skillify.js.map +1 -1
  233. package/dist/core/tools/task-steps.d.ts +1 -1
  234. package/dist/core/tools/task-steps.d.ts.map +1 -1
  235. package/dist/core/tools/task-steps.js +9 -0
  236. package/dist/core/tools/task-steps.js.map +1 -1
  237. package/dist/core/tools/tool-task.d.ts.map +1 -1
  238. package/dist/core/tools/tool-task.js +5 -1
  239. package/dist/core/tools/tool-task.js.map +1 -1
  240. package/dist/core/tools/write.d.ts.map +1 -1
  241. package/dist/core/tools/write.js +1 -0
  242. package/dist/core/tools/write.js.map +1 -1
  243. package/dist/index.d.ts +1 -1
  244. package/dist/index.d.ts.map +1 -1
  245. package/dist/index.js +1 -1
  246. package/dist/index.js.map +1 -1
  247. package/dist/modes/interactive/components/settings-selector.d.ts +3 -0
  248. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  249. package/dist/modes/interactive/components/settings-selector.js +66 -0
  250. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  251. package/dist/modes/interactive/components/skill-invocation-message.js +1 -1
  252. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  253. package/dist/modes/interactive/components/tool-execution.d.ts +6 -1
  254. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  255. package/dist/modes/interactive/components/tool-execution.js +20 -1
  256. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  257. package/dist/modes/interactive/components/tool-group.d.ts +4 -0
  258. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  259. package/dist/modes/interactive/components/tool-group.js +96 -7
  260. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  261. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  262. package/dist/modes/interactive/interactive-mode.js +8 -10
  263. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  264. package/dist/modes/interactive/key-handlers.d.ts +1 -0
  265. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  266. package/dist/modes/interactive/key-handlers.js +2 -1
  267. package/dist/modes/interactive/key-handlers.js.map +1 -1
  268. package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
  269. package/dist/modes/interactive/settings-selector-flow.js +12 -0
  270. package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
  271. package/docs/extensions.md +8 -5
  272. package/docs/harness-architecture.md +3 -4
  273. package/docs/keybindings.md +3 -2
  274. package/docs/quickstart.md +4 -4
  275. package/docs/sdk.md +3 -1
  276. package/docs/settings.md +16 -2
  277. package/docs/task-steps.md +1 -0
  278. package/docs/usage.md +6 -7
  279. package/docs/worker-profiles.md +1 -1
  280. package/docs/worktree-sync.md +1 -1
  281. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  282. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  283. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  284. package/examples/extensions/minimal-mode.ts +1 -1
  285. package/examples/extensions/sandbox/package-lock.json +2 -2
  286. package/examples/extensions/sandbox/package.json +1 -1
  287. package/examples/extensions/with-deps/package-lock.json +2 -2
  288. package/examples/extensions/with-deps/package.json +1 -1
  289. package/examples/sdk/07-context-files.ts +5 -2
  290. package/npm-shrinkwrap.json +12 -12
  291. package/package.json +4 -4
@@ -0,0 +1,147 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { basename, join } from "node:path";
3
+ import { parseStageContract, parseWorkspaceFrontmatter } from "./parse-contract.js";
4
+ import { MAX_PIPELINE_NAME_LENGTH, MAX_PIPELINE_STAGES, PIPELINE_STAGE_FOLDER_RE, } from "./types.js";
5
+ const ENTRY_FILES = ["AGENTS.md", "CLAUDE.md"];
6
+ const ROUTING_FILE = "CONTEXT.md";
7
+ const CONTRACT_FILE = "CONTEXT.md";
8
+ const FACTORY_DIRS = ["_shared", "references"];
9
+ export function projectPipelinesDir(cwd) {
10
+ return join(cwd, ".pi", "pipelines");
11
+ }
12
+ export function projectPipelineRunsDir(cwd) {
13
+ return join(cwd, ".pi", "pipeline-runs");
14
+ }
15
+ function readText(path) {
16
+ try {
17
+ return readFileSync(path, "utf8");
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ }
23
+ function isDir(path) {
24
+ try {
25
+ return statSync(path).isDirectory();
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
31
+ function listDirs(path) {
32
+ if (!isDir(path))
33
+ return [];
34
+ try {
35
+ return readdirSync(path, { withFileTypes: true })
36
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
37
+ .map((entry) => entry.name)
38
+ .sort();
39
+ }
40
+ catch {
41
+ return [];
42
+ }
43
+ }
44
+ function pickEntryFile(rootDir) {
45
+ for (const name of ENTRY_FILES) {
46
+ const path = join(rootDir, name);
47
+ if (existsSync(path))
48
+ return path;
49
+ }
50
+ return undefined;
51
+ }
52
+ function pickFactoryDir(rootDir) {
53
+ for (const name of FACTORY_DIRS) {
54
+ const path = join(rootDir, name);
55
+ if (isDir(path))
56
+ return path;
57
+ }
58
+ return join(rootDir, "_shared");
59
+ }
60
+ function parseStageFolder(name) {
61
+ const match = name.match(PIPELINE_STAGE_FOLDER_RE);
62
+ if (!match)
63
+ return undefined;
64
+ return { ordinal: Number(match[1]), slug: match[2] };
65
+ }
66
+ function loadStage(stagesDir, folderName) {
67
+ const parsed = parseStageFolder(folderName);
68
+ if (!parsed)
69
+ return undefined;
70
+ const contractPath = join(stagesDir, folderName, CONTRACT_FILE);
71
+ const content = readText(contractPath);
72
+ if (content === undefined)
73
+ return undefined;
74
+ const contract = parseStageContract(content);
75
+ return {
76
+ id: `${String(parsed.ordinal).padStart(2, "0")}_${parsed.slug}`,
77
+ ordinal: parsed.ordinal,
78
+ slug: parsed.slug,
79
+ folderName,
80
+ contractPath,
81
+ outputDir: join(stagesDir, folderName, "output"),
82
+ contract,
83
+ };
84
+ }
85
+ function collectStages(rootDir) {
86
+ const nested = join(rootDir, "stages");
87
+ const stagesDir = isDir(nested) && listDirs(nested).some((name) => PIPELINE_STAGE_FOLDER_RE.test(name)) ? nested : rootDir;
88
+ const stages = [];
89
+ for (const name of listDirs(stagesDir)) {
90
+ const stage = loadStage(stagesDir, name);
91
+ if (stage)
92
+ stages.push(stage);
93
+ if (stages.length >= MAX_PIPELINE_STAGES)
94
+ break;
95
+ }
96
+ stages.sort((left, right) => left.ordinal - right.ordinal || left.slug.localeCompare(right.slug));
97
+ return { stagesDir, stages };
98
+ }
99
+ export function loadPipelineDefinition(rootDir) {
100
+ if (!isDir(rootDir))
101
+ return undefined;
102
+ const { stagesDir, stages } = collectStages(rootDir);
103
+ if (stages.length === 0)
104
+ return undefined;
105
+ const routingPath = join(rootDir, ROUTING_FILE);
106
+ const routing = readText(routingPath);
107
+ const parsed = routing !== undefined ? parseWorkspaceFrontmatter(routing) : undefined;
108
+ const folderName = basename(rootDir).slice(0, MAX_PIPELINE_NAME_LENGTH);
109
+ const name = (parsed?.name || folderName).slice(0, MAX_PIPELINE_NAME_LENGTH);
110
+ const entryFile = pickEntryFile(rootDir) ?? routingPath;
111
+ return {
112
+ name,
113
+ description: parsed?.description ?? "",
114
+ form: parsed?.form ?? "pipeline",
115
+ rootDir,
116
+ entryFile,
117
+ routingPath: existsSync(routingPath) ? routingPath : entryFile,
118
+ factoryDir: pickFactoryDir(rootDir),
119
+ stagesDir,
120
+ stages,
121
+ };
122
+ }
123
+ export function discoverPipelineDefinitions(options) {
124
+ const roots = [options.agentPipelinesDir, projectPipelinesDir(options.cwd)];
125
+ const seen = new Set();
126
+ const definitions = [];
127
+ for (const root of roots) {
128
+ for (const name of listDirs(root)) {
129
+ const path = join(root, name);
130
+ if (seen.has(path))
131
+ continue;
132
+ const definition = loadPipelineDefinition(path);
133
+ if (!definition)
134
+ continue;
135
+ seen.add(path);
136
+ definitions.push(definition);
137
+ }
138
+ }
139
+ return definitions;
140
+ }
141
+ export function findPipelineDefinition(options, name) {
142
+ const wanted = name.trim().toLocaleLowerCase();
143
+ if (!wanted)
144
+ return undefined;
145
+ return discoverPipelineDefinitions(options).find((definition) => definition.name.toLocaleLowerCase() === wanted);
146
+ }
147
+ //# sourceMappingURL=discover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discover.js","sourceRoot":"","sources":["../../../src/core/pipelines/discover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EACN,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,GAGxB,MAAM,YAAY,CAAC;A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CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5E,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,WAAW,GAAyB,EAAE,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC9B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,SAAS;YAC7B,MAAM,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;YAChD,IAAI,CAAC,UAAU;gBAAE,SAAS;YAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACf,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IACD,OAAO,WAAW,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAE,IAAY;IACpF,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,iBAAiB,EAAE,CAAC;IAC/C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,2BAA2B,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,MAAM,CAAC,CAAC;AAClH,CAAC","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport { parseStageContract, parseWorkspaceFrontmatter } from \"./parse-contract.ts\";\nimport {\n\tMAX_PIPELINE_NAME_LENGTH,\n\tMAX_PIPELINE_STAGES,\n\tPIPELINE_STAGE_FOLDER_RE,\n\ttype PipelineDefinition,\n\ttype PipelineStage,\n} from \"./types.ts\";\n\nconst ENTRY_FILES = [\"AGENTS.md\", \"CLAUDE.md\"] as const;\nconst ROUTING_FILE = \"CONTEXT.md\";\nconst CONTRACT_FILE = \"CONTEXT.md\";\nconst FACTORY_DIRS = [\"_shared\", \"references\"] as const;\n\nexport function projectPipelinesDir(cwd: string): string {\n\treturn join(cwd, \".pi\", \"pipelines\");\n}\n\nexport function projectPipelineRunsDir(cwd: string): string {\n\treturn join(cwd, \".pi\", \"pipeline-runs\");\n}\n\nexport interface DiscoverPipelineOptions {\n\tagentPipelinesDir: string;\n\tcwd: string;\n}\n\nfunction readText(path: string): string | undefined {\n\ttry {\n\t\treturn readFileSync(path, \"utf8\");\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction isDir(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction listDirs(path: string): string[] {\n\tif (!isDir(path)) return [];\n\ttry {\n\t\treturn readdirSync(path, { withFileTypes: true })\n\t\t\t.filter((entry) => entry.isDirectory() && !entry.name.startsWith(\".\"))\n\t\t\t.map((entry) => entry.name)\n\t\t\t.sort();\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nfunction pickEntryFile(rootDir: string): string | undefined {\n\tfor (const name of ENTRY_FILES) {\n\t\tconst path = join(rootDir, name);\n\t\tif (existsSync(path)) return path;\n\t}\n\treturn undefined;\n}\n\nfunction pickFactoryDir(rootDir: string): string {\n\tfor (const name of FACTORY_DIRS) {\n\t\tconst path = join(rootDir, name);\n\t\tif (isDir(path)) return path;\n\t}\n\treturn join(rootDir, \"_shared\");\n}\n\nfunction parseStageFolder(name: string): { ordinal: number; slug: string } | undefined {\n\tconst match = name.match(PIPELINE_STAGE_FOLDER_RE);\n\tif (!match) return undefined;\n\treturn { ordinal: Number(match[1]), slug: match[2] };\n}\n\nfunction loadStage(stagesDir: string, folderName: string): PipelineStage | undefined {\n\tconst parsed = parseStageFolder(folderName);\n\tif (!parsed) return undefined;\n\tconst contractPath = join(stagesDir, folderName, CONTRACT_FILE);\n\tconst content = readText(contractPath);\n\tif (content === undefined) return undefined;\n\tconst contract = parseStageContract(content);\n\treturn {\n\t\tid: `${String(parsed.ordinal).padStart(2, \"0\")}_${parsed.slug}`,\n\t\tordinal: parsed.ordinal,\n\t\tslug: parsed.slug,\n\t\tfolderName,\n\t\tcontractPath,\n\t\toutputDir: join(stagesDir, folderName, \"output\"),\n\t\tcontract,\n\t};\n}\n\nfunction collectStages(rootDir: string): { stagesDir: string; stages: PipelineStage[] } {\n\tconst nested = join(rootDir, \"stages\");\n\tconst stagesDir =\n\t\tisDir(nested) && listDirs(nested).some((name) => PIPELINE_STAGE_FOLDER_RE.test(name)) ? nested : rootDir;\n\tconst stages: PipelineStage[] = [];\n\tfor (const name of listDirs(stagesDir)) {\n\t\tconst stage = loadStage(stagesDir, name);\n\t\tif (stage) stages.push(stage);\n\t\tif (stages.length >= MAX_PIPELINE_STAGES) break;\n\t}\n\tstages.sort((left, right) => left.ordinal - right.ordinal || left.slug.localeCompare(right.slug));\n\treturn { stagesDir, stages };\n}\n\nexport function loadPipelineDefinition(rootDir: string): PipelineDefinition | undefined {\n\tif (!isDir(rootDir)) return undefined;\n\tconst { stagesDir, stages } = collectStages(rootDir);\n\tif (stages.length === 0) return undefined;\n\tconst routingPath = join(rootDir, ROUTING_FILE);\n\tconst routing = readText(routingPath);\n\tconst parsed = routing !== undefined ? parseWorkspaceFrontmatter(routing) : undefined;\n\tconst folderName = basename(rootDir).slice(0, MAX_PIPELINE_NAME_LENGTH);\n\tconst name = (parsed?.name || folderName).slice(0, MAX_PIPELINE_NAME_LENGTH);\n\tconst entryFile = pickEntryFile(rootDir) ?? routingPath;\n\treturn {\n\t\tname,\n\t\tdescription: parsed?.description ?? \"\",\n\t\tform: parsed?.form ?? \"pipeline\",\n\t\trootDir,\n\t\tentryFile,\n\t\troutingPath: existsSync(routingPath) ? routingPath : entryFile,\n\t\tfactoryDir: pickFactoryDir(rootDir),\n\t\tstagesDir,\n\t\tstages,\n\t};\n}\n\nexport function discoverPipelineDefinitions(options: DiscoverPipelineOptions): PipelineDefinition[] {\n\tconst roots = [options.agentPipelinesDir, projectPipelinesDir(options.cwd)];\n\tconst seen = new Set<string>();\n\tconst definitions: PipelineDefinition[] = [];\n\tfor (const root of roots) {\n\t\tfor (const name of listDirs(root)) {\n\t\t\tconst path = join(root, name);\n\t\t\tif (seen.has(path)) continue;\n\t\t\tconst definition = loadPipelineDefinition(path);\n\t\t\tif (!definition) continue;\n\t\t\tseen.add(path);\n\t\t\tdefinitions.push(definition);\n\t\t}\n\t}\n\treturn definitions;\n}\n\nexport function findPipelineDefinition(options: DiscoverPipelineOptions, name: string): PipelineDefinition | undefined {\n\tconst wanted = name.trim().toLocaleLowerCase();\n\tif (!wanted) return undefined;\n\treturn discoverPipelineDefinitions(options).find((definition) => definition.name.toLocaleLowerCase() === wanted);\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import type { BackgroundToolTaskRef } from "../background-tool-task-controller.ts";
2
+ import type { GoalState } from "../goals/goal-state.ts";
3
+ import type { OpenTaskStepRef } from "../goals/goal-tool-core.ts";
4
+ import { type TaskStep, type TaskStepsState } from "../tasks/task-state.ts";
5
+ import { type IncrementResult, type PipelineDefinition, type PipelineRun } from "./types.ts";
6
+ export interface PipelineIncrementJoin {
7
+ goal?: GoalState;
8
+ openTaskSteps?: readonly OpenTaskStepRef[];
9
+ backgroundToolTasks?: readonly BackgroundToolTaskRef[];
10
+ }
11
+ export declare class PipelineIncrementError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ export declare function incrementPipelineRun(definition: PipelineDefinition, run: PipelineRun, now: string, join?: PipelineIncrementJoin): {
15
+ run: PipelineRun;
16
+ result: IncrementResult;
17
+ };
18
+ export declare function abandonPipelineRun(run: PipelineRun, now: string): PipelineRun;
19
+ export declare function advanceTaskSteps(state: TaskStepsState, now: string): {
20
+ state: TaskStepsState;
21
+ result: IncrementResult;
22
+ };
23
+ export declare function currentOpenTaskStep(steps: readonly TaskStep[]): TaskStep | undefined;
24
+ //# sourceMappingURL=increment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"increment.d.ts","sourceRoot":"","sources":["../../../src/core/pipelines/increment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAkB,MAAM,wBAAwB,CAAC;AAG5F,OAAO,EAAE,KAAK,eAAe,EAAuB,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAElH,MAAM,WAAW,qBAAqB;IACrC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IAC3C,mBAAmB,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACvD;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAeD,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,kBAAkB,EAC9B,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,qBAA0B,GAC9B;IAAE,GAAG,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAmD/C;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAG7E;AAED,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,cAAc,EACrB,GAAG,EAAE,MAAM,GACT;IACF,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,eAAe,CAAC;CACxB,CA2CA;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,GAAG,SAAS,CAEpF"}
@@ -0,0 +1,121 @@
1
+ import { taskStepReferencesRequirement } from "../tasks/task-projection.js";
2
+ import { updateTaskStep } from "../tasks/task-state.js";
3
+ import { currentPipelineStage } from "./context.js";
4
+ import { persistPipelineRun, scanStageOutput, stageOutputDir } from "./run-state.js";
5
+ import { isPipelineRunActive } from "./types.js";
6
+ export class PipelineIncrementError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "PipelineIncrementError";
10
+ }
11
+ }
12
+ function inFlightToolTasks(tasks) {
13
+ if (!tasks)
14
+ return [];
15
+ return tasks.filter((task) => task.status === "running").map((task) => task.taskId);
16
+ }
17
+ function linkedOpenStepIds(join, run) {
18
+ if (!run.goalId || !join.goal || join.goal.goalId !== run.goalId)
19
+ return [];
20
+ if (!join.openTaskSteps || join.openTaskSteps.length === 0)
21
+ return [];
22
+ return join.openTaskSteps
23
+ .filter((step) => join.goal.requirements.some((requirement) => taskStepReferencesRequirement(step, requirement)))
24
+ .map((step) => step.id);
25
+ }
26
+ export function incrementPipelineRun(definition, run, now, join = {}) {
27
+ if (!isPipelineRunActive(run)) {
28
+ throw new PipelineIncrementError(`Pipeline run '${run.runId}' is ${run.status}.`);
29
+ }
30
+ const linked = linkedOpenStepIds(join, run);
31
+ if (linked.length > 0) {
32
+ throw new PipelineIncrementError(`Cannot increment pipeline: open task_steps still reference the linked goal (${linked.join(", ")}).`);
33
+ }
34
+ const running = inFlightToolTasks(join.backgroundToolTasks);
35
+ if (running.length > 0) {
36
+ throw new PipelineIncrementError(`Cannot increment pipeline: tool_task(s) still running (${running.join(", ")}). Wait once via tool_task.`);
37
+ }
38
+ const stage = currentPipelineStage(definition, run);
39
+ if (!stage) {
40
+ throw new PipelineIncrementError(`Current stage '${run.currentStageId}' is missing from the definition.`);
41
+ }
42
+ const scanned = scanStageOutput(stageOutputDir(run.runRoot, stage));
43
+ if (scanned.status !== "complete") {
44
+ throw new PipelineIncrementError(`Cannot increment pipeline: stage '${stage.id}' output/ has no files yet. Write the stage outputs first.`);
45
+ }
46
+ const currentIndex = definition.stages.findIndex((candidate) => candidate.id === stage.id);
47
+ const next = definition.stages[currentIndex + 1];
48
+ if (!next) {
49
+ const completed = persistPipelineRun({ ...run, status: "completed" }, now);
50
+ return {
51
+ run: completed,
52
+ result: {
53
+ surface: "pipeline",
54
+ from: stage.id,
55
+ completed: true,
56
+ detail: `Completed final stage '${stage.id}'. Pipeline run '${run.runId}' is done.`,
57
+ },
58
+ };
59
+ }
60
+ const advanced = persistPipelineRun({ ...run, currentStageId: next.id }, now);
61
+ return {
62
+ run: advanced,
63
+ result: {
64
+ surface: "pipeline",
65
+ from: stage.id,
66
+ to: next.id,
67
+ completed: false,
68
+ detail: `Completed '${stage.id}', started '${next.id}'. ${next.contract.oneJob || next.contract.title}`,
69
+ },
70
+ };
71
+ }
72
+ export function abandonPipelineRun(run, now) {
73
+ if (!isPipelineRunActive(run))
74
+ return run;
75
+ return persistPipelineRun({ ...run, status: "abandoned" }, now);
76
+ }
77
+ export function advanceTaskSteps(state, now) {
78
+ const current = state.steps.find((step) => step.status === "in_progress") ??
79
+ state.steps.find((step) => step.status === "pending");
80
+ if (!current) {
81
+ return {
82
+ state,
83
+ result: {
84
+ surface: "task_steps",
85
+ completed: true,
86
+ detail: "No open task steps remain.",
87
+ },
88
+ };
89
+ }
90
+ let nextState = state;
91
+ if (current.status !== "completed") {
92
+ nextState = updateTaskStep(nextState, current.id, { status: "completed" }, now);
93
+ }
94
+ const following = nextState.steps.find((step) => step.id !== current.id && (step.status === "pending" || step.status === "blocked"));
95
+ if (following && following.status === "pending") {
96
+ nextState = updateTaskStep(nextState, following.id, { status: "in_progress" }, now);
97
+ return {
98
+ state: nextState,
99
+ result: {
100
+ surface: "task_steps",
101
+ from: current.id,
102
+ to: following.id,
103
+ completed: false,
104
+ detail: `Completed ${current.id}, started ${following.id}.`,
105
+ },
106
+ };
107
+ }
108
+ return {
109
+ state: nextState,
110
+ result: {
111
+ surface: "task_steps",
112
+ from: current.id,
113
+ completed: true,
114
+ detail: `Completed ${current.id}. No further pending steps.`,
115
+ },
116
+ };
117
+ }
118
+ export function currentOpenTaskStep(steps) {
119
+ return steps.find((step) => step.status === "in_progress") ?? steps.find((step) => step.status === "pending");
120
+ }
121
+ //# sourceMappingURL=increment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"increment.js","sourceRoot":"","sources":["../../../src/core/pipelines/increment.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAsC,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAwB,mBAAmB,EAA6C,MAAM,YAAY,CAAC;AAQlH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAChD,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACtC,CAAC;CACD;AAED,SAAS,iBAAiB,CAAC,KAAmD;IAC7E,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACrF,CAAC;AAED,SAAS,iBAAiB,CAAC,IAA2B,EAAE,GAAgB;IACvE,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;I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C,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAC5F,CAAC;IACF,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACjD,SAAS,GAAG,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,GAAG,CAAC,CAAC;QACpF,OAAO;YACN,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE;gBACP,OAAO,EAAE,YAAY;gBACrB,IAAI,EAAE,OAAO,CAAC,EAAE;gBAChB,EAAE,EAAE,SAAS,CAAC,EAAE;gBAChB,SAAS,EAAE,KAAK;gBAChB,MAAM,EAAE,aAAa,OAAO,CAAC,EAAE,aAAa,SAAS,CAAC,EAAE,GAAG;aAC3D;SACD,CAAC;IACH,CAAC;IACD,OAAO;QACN,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE;YACP,OAAO,EAAE,YAAY;YACrB,IAAI,EAAE,OAAO,CAAC,EAAE;YAChB,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,aAAa,OAAO,CAAC,EAAE,6BAA6B;SAC5D;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAA0B;IAC7D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;AAC/G,CAAC","sourcesContent":["import type { BackgroundToolTaskRef } from \"../background-tool-task-controller.ts\";\nimport type { GoalState } from \"../goals/goal-state.ts\";\nimport type { OpenTaskStepRef } from \"../goals/goal-tool-core.ts\";\nimport { taskStepReferencesRequirement } from \"../tasks/task-projection.ts\";\nimport { type TaskStep, type TaskStepsState, updateTaskStep } from \"../tasks/task-state.ts\";\nimport { currentPipelineStage } from \"./context.ts\";\nimport { persistPipelineRun, scanStageOutput, stageOutputDir } from \"./run-state.ts\";\nimport { type IncrementResult, isPipelineRunActive, type PipelineDefinition, type PipelineRun } from \"./types.ts\";\n\nexport interface PipelineIncrementJoin {\n\tgoal?: GoalState;\n\topenTaskSteps?: readonly OpenTaskStepRef[];\n\tbackgroundToolTasks?: readonly BackgroundToolTaskRef[];\n}\n\nexport class PipelineIncrementError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"PipelineIncrementError\";\n\t}\n}\n\nfunction inFlightToolTasks(tasks: readonly BackgroundToolTaskRef[] | undefined): string[] {\n\tif (!tasks) return [];\n\treturn tasks.filter((task) => task.status === \"running\").map((task) => task.taskId);\n}\n\nfunction linkedOpenStepIds(join: PipelineIncrementJoin, run: PipelineRun): string[] {\n\tif (!run.goalId || !join.goal || join.goal.goalId !== run.goalId) return [];\n\tif (!join.openTaskSteps || join.openTaskSteps.length === 0) return [];\n\treturn join.openTaskSteps\n\t\t.filter((step) => join.goal!.requirements.some((requirement) => taskStepReferencesRequirement(step, requirement)))\n\t\t.map((step) => step.id);\n}\n\nexport function incrementPipelineRun(\n\tdefinition: PipelineDefinition,\n\trun: PipelineRun,\n\tnow: string,\n\tjoin: PipelineIncrementJoin = {},\n): { run: PipelineRun; result: IncrementResult } {\n\tif (!isPipelineRunActive(run)) {\n\t\tthrow new PipelineIncrementError(`Pipeline run '${run.runId}' is ${run.status}.`);\n\t}\n\tconst linked = linkedOpenStepIds(join, run);\n\tif (linked.length > 0) {\n\t\tthrow new PipelineIncrementError(\n\t\t\t`Cannot increment pipeline: open task_steps still reference the linked goal (${linked.join(\", \")}).`,\n\t\t);\n\t}\n\tconst running = inFlightToolTasks(join.backgroundToolTasks);\n\tif (running.length > 0) {\n\t\tthrow new PipelineIncrementError(\n\t\t\t`Cannot increment pipeline: tool_task(s) still running (${running.join(\", \")}). Wait once via tool_task.`,\n\t\t);\n\t}\n\tconst stage = currentPipelineStage(definition, run);\n\tif (!stage) {\n\t\tthrow new PipelineIncrementError(`Current stage '${run.currentStageId}' is missing from the definition.`);\n\t}\n\tconst scanned = scanStageOutput(stageOutputDir(run.runRoot, stage));\n\tif (scanned.status !== \"complete\") {\n\t\tthrow new PipelineIncrementError(\n\t\t\t`Cannot increment pipeline: stage '${stage.id}' output/ has no files yet. Write the stage outputs first.`,\n\t\t);\n\t}\n\tconst currentIndex = definition.stages.findIndex((candidate) => candidate.id === stage.id);\n\tconst next = definition.stages[currentIndex + 1];\n\tif (!next) {\n\t\tconst completed = persistPipelineRun({ ...run, status: \"completed\" }, now);\n\t\treturn {\n\t\t\trun: completed,\n\t\t\tresult: {\n\t\t\t\tsurface: \"pipeline\",\n\t\t\t\tfrom: stage.id,\n\t\t\t\tcompleted: true,\n\t\t\t\tdetail: `Completed final stage '${stage.id}'. Pipeline run '${run.runId}' is done.`,\n\t\t\t},\n\t\t};\n\t}\n\tconst advanced = persistPipelineRun({ ...run, currentStageId: next.id }, now);\n\treturn {\n\t\trun: advanced,\n\t\tresult: {\n\t\t\tsurface: \"pipeline\",\n\t\t\tfrom: stage.id,\n\t\t\tto: next.id,\n\t\t\tcompleted: false,\n\t\t\tdetail: `Completed '${stage.id}', started '${next.id}'. ${next.contract.oneJob || next.contract.title}`,\n\t\t},\n\t};\n}\n\nexport function abandonPipelineRun(run: PipelineRun, now: string): PipelineRun {\n\tif (!isPipelineRunActive(run)) return run;\n\treturn persistPipelineRun({ ...run, status: \"abandoned\" }, now);\n}\n\nexport function advanceTaskSteps(\n\tstate: TaskStepsState,\n\tnow: string,\n): {\n\tstate: TaskStepsState;\n\tresult: IncrementResult;\n} {\n\tconst current =\n\t\tstate.steps.find((step) => step.status === \"in_progress\") ??\n\t\tstate.steps.find((step) => step.status === \"pending\");\n\tif (!current) {\n\t\treturn {\n\t\t\tstate,\n\t\t\tresult: {\n\t\t\t\tsurface: \"task_steps\",\n\t\t\t\tcompleted: true,\n\t\t\t\tdetail: \"No open task steps remain.\",\n\t\t\t},\n\t\t};\n\t}\n\tlet nextState = state;\n\tif (current.status !== \"completed\") {\n\t\tnextState = updateTaskStep(nextState, current.id, { status: \"completed\" }, now);\n\t}\n\tconst following = nextState.steps.find(\n\t\t(step) => step.id !== current.id && (step.status === \"pending\" || step.status === \"blocked\"),\n\t);\n\tif (following && following.status === \"pending\") {\n\t\tnextState = updateTaskStep(nextState, following.id, { status: \"in_progress\" }, now);\n\t\treturn {\n\t\t\tstate: nextState,\n\t\t\tresult: {\n\t\t\t\tsurface: \"task_steps\",\n\t\t\t\tfrom: current.id,\n\t\t\t\tto: following.id,\n\t\t\t\tcompleted: false,\n\t\t\t\tdetail: `Completed ${current.id}, started ${following.id}.`,\n\t\t\t},\n\t\t};\n\t}\n\treturn {\n\t\tstate: nextState,\n\t\tresult: {\n\t\t\tsurface: \"task_steps\",\n\t\t\tfrom: current.id,\n\t\t\tcompleted: true,\n\t\t\tdetail: `Completed ${current.id}. No further pending steps.`,\n\t\t},\n\t};\n}\n\nexport function currentOpenTaskStep(steps: readonly TaskStep[]): TaskStep | undefined {\n\treturn steps.find((step) => step.status === \"in_progress\") ?? steps.find((step) => step.status === \"pending\");\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export { assembleStageContext, currentPipelineStage, formatActivePipelineContext, formatPipelineContext, } from "./context.ts";
2
+ export { discoverPipelineDefinitions, findPipelineDefinition, loadPipelineDefinition, projectPipelineRunsDir, projectPipelinesDir, } from "./discover.ts";
3
+ export { abandonPipelineRun, advanceTaskSteps, currentOpenTaskStep, incrementPipelineRun, PipelineIncrementError, type PipelineIncrementJoin, } from "./increment.ts";
4
+ export { parseStageContract, parseWorkspaceFrontmatter } from "./parse-contract.ts";
5
+ export { createPipelineRunRoot, findActivePipelineRun, instantiatePipelineRun, loadPipelineRunById, persistPipelineRun, readPipelineRun, scanPipelineRun, scanStageOutput, stageOutputDir, writePipelineRun, } from "./run-state.ts";
6
+ export { appendPipelineRunSnapshot, decodePipelineRunSnapshotPayload, getLatestPipelineRunSnapshot, } from "./session-pipeline-run.ts";
7
+ export { type AssembledStageContext, clonePipelineRun, type IncrementResult, isPipelineRun, isPipelineRunActive, PIPELINE_CONTEXT_MARKER, PIPELINE_RUN_CUSTOM_TYPE, PIPELINE_STAGE_FOLDER_RE, type PipelineDefinition, type PipelineForm, type PipelineRun, type PipelineStage, type StageContract, type StageScan, } from "./types.ts";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/pipelines/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,qBAAqB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,gBAAgB,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,yBAAyB,EACzB,gCAAgC,EAChC,4BAA4B,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,KAAK,qBAAqB,EAC1B,gBAAgB,EAChB,KAAK,eAAe,EACpB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,GACd,MAAM,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { assembleStageContext, currentPipelineStage, formatActivePipelineContext, formatPipelineContext, } from "./context.js";
2
+ export { discoverPipelineDefinitions, findPipelineDefinition, loadPipelineDefinition, projectPipelineRunsDir, projectPipelinesDir, } from "./discover.js";
3
+ export { abandonPipelineRun, advanceTaskSteps, currentOpenTaskStep, incrementPipelineRun, PipelineIncrementError, } from "./increment.js";
4
+ export { parseStageContract, parseWorkspaceFrontmatter } from "./parse-contract.js";
5
+ export { createPipelineRunRoot, findActivePipelineRun, instantiatePipelineRun, loadPipelineRunById, persistPipelineRun, readPipelineRun, scanPipelineRun, scanStageOutput, stageOutputDir, writePipelineRun, } from "./run-state.js";
6
+ export { appendPipelineRunSnapshot, decodePipelineRunSnapshotPayload, getLatestPipelineRunSnapshot, } from "./session-pipeline-run.js";
7
+ export { clonePipelineRun, isPipelineRun, isPipelineRunActive, PIPELINE_CONTEXT_MARKER, PIPELINE_RUN_CUSTOM_TYPE, PIPELINE_STAGE_FOLDER_RE, } from "./types.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/pipelines/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,GAEtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,gBAAgB,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,yBAAyB,EACzB,gCAAgC,EAChC,4BAA4B,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEN,gBAAgB,EAEhB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,GAOxB,MAAM,YAAY,CAAC","sourcesContent":["export {\n\tassembleStageContext,\n\tcurrentPipelineStage,\n\tformatActivePipelineContext,\n\tformatPipelineContext,\n} from \"./context.ts\";\nexport {\n\tdiscoverPipelineDefinitions,\n\tfindPipelineDefinition,\n\tloadPipelineDefinition,\n\tprojectPipelineRunsDir,\n\tprojectPipelinesDir,\n} from \"./discover.ts\";\nexport {\n\tabandonPipelineRun,\n\tadvanceTaskSteps,\n\tcurrentOpenTaskStep,\n\tincrementPipelineRun,\n\tPipelineIncrementError,\n\ttype PipelineIncrementJoin,\n} from \"./increment.ts\";\nexport { parseStageContract, parseWorkspaceFrontmatter } from \"./parse-contract.ts\";\nexport {\n\tcreatePipelineRunRoot,\n\tfindActivePipelineRun,\n\tinstantiatePipelineRun,\n\tloadPipelineRunById,\n\tpersistPipelineRun,\n\treadPipelineRun,\n\tscanPipelineRun,\n\tscanStageOutput,\n\tstageOutputDir,\n\twritePipelineRun,\n} from \"./run-state.ts\";\nexport {\n\tappendPipelineRunSnapshot,\n\tdecodePipelineRunSnapshotPayload,\n\tgetLatestPipelineRunSnapshot,\n} from \"./session-pipeline-run.ts\";\nexport {\n\ttype AssembledStageContext,\n\tclonePipelineRun,\n\ttype IncrementResult,\n\tisPipelineRun,\n\tisPipelineRunActive,\n\tPIPELINE_CONTEXT_MARKER,\n\tPIPELINE_RUN_CUSTOM_TYPE,\n\tPIPELINE_STAGE_FOLDER_RE,\n\ttype PipelineDefinition,\n\ttype PipelineForm,\n\ttype PipelineRun,\n\ttype PipelineStage,\n\ttype StageContract,\n\ttype StageScan,\n} from \"./types.ts\";\n"]}
@@ -0,0 +1,10 @@
1
+ import { type PipelineForm, type StageContract } from "./types.ts";
2
+ export interface ParsedWorkspaceContract {
3
+ name?: string;
4
+ description?: string;
5
+ form: PipelineForm;
6
+ body: string;
7
+ }
8
+ export declare function parseWorkspaceFrontmatter(content: string): ParsedWorkspaceContract;
9
+ export declare function parseStageContract(content: string): StageContract;
10
+ //# sourceMappingURL=parse-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-contract.d.ts","sourceRoot":"","sources":["../../../src/core/pipelines/parse-contract.ts"],"names":[],"mappings":"AAEA,OAAO,EAIN,KAAK,YAAY,EAEjB,KAAK,aAAa,EAClB,MAAM,YAAY,CAAC;AAWpB,MAAM,WAAW,uBAAuB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAkCD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAWlF;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CA2CjE"}
@@ -0,0 +1,105 @@
1
+ import { parseFrontmatter } from "../../utils/frontmatter.js";
2
+ import { isPlainRecord } from "../util/value-guards.js";
3
+ import { MAX_CONTRACT_PROCESS_CHARS, MAX_HUMAN_CHECK_CHARS, MAX_PIPELINE_NAME_LENGTH, } from "./types.js";
4
+ const FORMS = [
5
+ "pipeline",
6
+ "umbrella",
7
+ "record-library",
8
+ "knowledge-bundle",
9
+ "context-map",
10
+ "system-map",
11
+ ];
12
+ function section(body, heading) {
13
+ const pattern = new RegExp(`^##\\s+${heading}\\s*$`, "im");
14
+ const start = body.search(pattern);
15
+ if (start === -1)
16
+ return "";
17
+ const after = body.slice(start).split("\n").slice(1);
18
+ const lines = [];
19
+ for (const line of after) {
20
+ if (/^##\s+/.test(line))
21
+ break;
22
+ lines.push(line);
23
+ }
24
+ return lines.join("\n").trim();
25
+ }
26
+ function listLines(text) {
27
+ const items = [];
28
+ for (const raw of text.split("\n")) {
29
+ const match = raw.match(/^\s*(?:[-*]|\d+\.)\s+(.+)$/);
30
+ if (match)
31
+ items.push(match[1].trim());
32
+ }
33
+ return items;
34
+ }
35
+ function classifyInput(line) {
36
+ const working = line.match(/^(?:Working(?:\s+\(this run\))?|4|Layer\s*4)\s*:\s*(.+)$/i);
37
+ if (working)
38
+ return { kind: "working", path: working[1].trim() };
39
+ const reference = line.match(/^(?:Reference(?:\s+\(every run\))?|3|Layer\s*3)\s*:\s*(.+)$/i);
40
+ if (reference)
41
+ return { kind: "reference", path: reference[1].trim() };
42
+ const numbered = line.match(/^([34])\s*:\s*(.+)$/);
43
+ if (numbered)
44
+ return { kind: numbered[1] === "3" ? "reference" : "working", path: numbered[2].trim() };
45
+ return undefined;
46
+ }
47
+ export function parseWorkspaceFrontmatter(content) {
48
+ const parsed = parseFrontmatter(content);
49
+ const fm = isPlainRecord(parsed.frontmatter) ? parsed.frontmatter : {};
50
+ const name = typeof fm.name === "string" ? fm.name.trim() : undefined;
51
+ const description = typeof fm.description === "string" ? fm.description.trim() : undefined;
52
+ const formRaw = typeof fm.form === "string" ? fm.form.trim() : "pipeline";
53
+ const form = FORMS.includes(formRaw) ? formRaw : "pipeline";
54
+ if (name && name.length > MAX_PIPELINE_NAME_LENGTH) {
55
+ throw new Error(`Pipeline name exceeds ${MAX_PIPELINE_NAME_LENGTH} characters.`);
56
+ }
57
+ return { name, description, form, body: parsed.body };
58
+ }
59
+ export function parseStageContract(content) {
60
+ const { body } = parseFrontmatter(content);
61
+ const titleLine = body.split("\n").find((line) => line.startsWith("# ")) ?? "";
62
+ const title = titleLine.replace(/^#\s+/, "").trim();
63
+ const oneJobMatch = body.match(/^One job:\s*(.+)$/im);
64
+ const inputsSection = section(body, "Inputs");
65
+ const processSection = section(body, "Process");
66
+ const outputsSection = section(body, "Outputs");
67
+ const humanSection = section(body, "Human check");
68
+ const doNot = [];
69
+ const inputs = [];
70
+ for (const raw of inputsSection.split("\n")) {
71
+ const trimmed = raw.trim();
72
+ if (!trimmed)
73
+ continue;
74
+ const doNotLine = trimmed.match(/^do not load:?\s*(.+)$/i);
75
+ if (doNotLine) {
76
+ doNot.push(doNotLine[1].trim());
77
+ continue;
78
+ }
79
+ const listed = trimmed.match(/^(?:[-*]|\d+\.)\s+(.+)$/);
80
+ const line = listed ? listed[1].trim() : trimmed;
81
+ if (/^do not load/i.test(line)) {
82
+ doNot.push(line.replace(/^do not load:?\s*/i, "").trim());
83
+ continue;
84
+ }
85
+ const input = classifyInput(line);
86
+ if (input)
87
+ inputs.push(input);
88
+ }
89
+ const process = listLines(processSection);
90
+ if (process.join("\n").length > MAX_CONTRACT_PROCESS_CHARS) {
91
+ throw new Error(`Stage process exceeds ${MAX_CONTRACT_PROCESS_CHARS} characters.`);
92
+ }
93
+ const outputs = listLines(outputsSection).map((line) => line.replace(/\s*→\s*output\/?\s*$/i, "").trim());
94
+ const humanCheck = humanSection.slice(0, MAX_HUMAN_CHECK_CHARS);
95
+ return {
96
+ title,
97
+ oneJob: (oneJobMatch?.[1] ?? "").trim(),
98
+ inputs,
99
+ doNotLoad: doNot,
100
+ process,
101
+ outputs,
102
+ humanCheck,
103
+ };
104
+ }
105
+ //# sourceMappingURL=parse-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-contract.js","sourceRoot":"","sources":["../../../src/core/pipelines/parse-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACN,0BAA0B,EAC1B,qBAAqB,EACrB,wBAAwB,GAIxB,MAAM,YAAY,CA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C,uBAAuB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1G,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAChE,OAAO;QACN,KAAK;QACL,MAAM,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QACvC,MAAM;QACN,SAAS,EAAE,KAAK;QAChB,OAAO;QACP,OAAO;QACP,UAAU;KACV,CAAC;AACH,CAAC","sourcesContent":["import { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport {\n\tMAX_CONTRACT_PROCESS_CHARS,\n\tMAX_HUMAN_CHECK_CHARS,\n\tMAX_PIPELINE_NAME_LENGTH,\n\ttype PipelineForm,\n\ttype PipelineInputRef,\n\ttype StageContract,\n} from \"./types.ts\";\n\nconst FORMS: readonly PipelineForm[] = [\n\t\"pipeline\",\n\t\"umbrella\",\n\t\"record-library\",\n\t\"knowledge-bundle\",\n\t\"context-map\",\n\t\"system-map\",\n];\n\nexport interface ParsedWorkspaceContract {\n\tname?: string;\n\tdescription?: string;\n\tform: PipelineForm;\n\tbody: string;\n}\n\nfunction section(body: string, heading: string): string {\n\tconst pattern = new RegExp(`^##\\\\s+${heading}\\\\s*$`, \"im\");\n\tconst start = body.search(pattern);\n\tif (start === -1) return \"\";\n\tconst after = body.slice(start).split(\"\\n\").slice(1);\n\tconst lines: string[] = [];\n\tfor (const line of after) {\n\t\tif (/^##\\s+/.test(line)) break;\n\t\tlines.push(line);\n\t}\n\treturn lines.join(\"\\n\").trim();\n}\n\nfunction listLines(text: string): string[] {\n\tconst items: string[] = [];\n\tfor (const raw of text.split(\"\\n\")) {\n\t\tconst match = raw.match(/^\\s*(?:[-*]|\\d+\\.)\\s+(.+)$/);\n\t\tif (match) items.push(match[1].trim());\n\t}\n\treturn items;\n}\n\nfunction classifyInput(line: string): PipelineInputRef | undefined {\n\tconst working = line.match(/^(?:Working(?:\\s+\\(this run\\))?|4|Layer\\s*4)\\s*:\\s*(.+)$/i);\n\tif (working) return { kind: \"working\", path: working[1].trim() };\n\tconst reference = line.match(/^(?:Reference(?:\\s+\\(every run\\))?|3|Layer\\s*3)\\s*:\\s*(.+)$/i);\n\tif (reference) return { kind: \"reference\", path: reference[1].trim() };\n\tconst numbered = line.match(/^([34])\\s*:\\s*(.+)$/);\n\tif (numbered) return { kind: numbered[1] === \"3\" ? \"reference\" : \"working\", path: numbered[2].trim() };\n\treturn undefined;\n}\n\nexport function parseWorkspaceFrontmatter(content: string): ParsedWorkspaceContract {\n\tconst parsed = parseFrontmatter<Record<string, unknown>>(content);\n\tconst fm = isPlainRecord(parsed.frontmatter) ? parsed.frontmatter : {};\n\tconst name = typeof fm.name === \"string\" ? fm.name.trim() : undefined;\n\tconst description = typeof fm.description === \"string\" ? fm.description.trim() : undefined;\n\tconst formRaw = typeof fm.form === \"string\" ? fm.form.trim() : \"pipeline\";\n\tconst form = FORMS.includes(formRaw as PipelineForm) ? (formRaw as PipelineForm) : \"pipeline\";\n\tif (name && name.length > MAX_PIPELINE_NAME_LENGTH) {\n\t\tthrow new Error(`Pipeline name exceeds ${MAX_PIPELINE_NAME_LENGTH} characters.`);\n\t}\n\treturn { name, description, form, body: parsed.body };\n}\n\nexport function parseStageContract(content: string): StageContract {\n\tconst { body } = parseFrontmatter(content);\n\tconst titleLine = body.split(\"\\n\").find((line) => line.startsWith(\"# \")) ?? \"\";\n\tconst title = titleLine.replace(/^#\\s+/, \"\").trim();\n\tconst oneJobMatch = body.match(/^One job:\\s*(.+)$/im);\n\tconst inputsSection = section(body, \"Inputs\");\n\tconst processSection = section(body, \"Process\");\n\tconst outputsSection = section(body, \"Outputs\");\n\tconst humanSection = section(body, \"Human check\");\n\tconst doNot: string[] = [];\n\tconst inputs: PipelineInputRef[] = [];\n\tfor (const raw of inputsSection.split(\"\\n\")) {\n\t\tconst trimmed = raw.trim();\n\t\tif (!trimmed) continue;\n\t\tconst doNotLine = trimmed.match(/^do not load:?\\s*(.+)$/i);\n\t\tif (doNotLine) {\n\t\t\tdoNot.push(doNotLine[1].trim());\n\t\t\tcontinue;\n\t\t}\n\t\tconst listed = trimmed.match(/^(?:[-*]|\\d+\\.)\\s+(.+)$/);\n\t\tconst line = listed ? listed[1].trim() : trimmed;\n\t\tif (/^do not load/i.test(line)) {\n\t\t\tdoNot.push(line.replace(/^do not load:?\\s*/i, \"\").trim());\n\t\t\tcontinue;\n\t\t}\n\t\tconst input = classifyInput(line);\n\t\tif (input) inputs.push(input);\n\t}\n\tconst process = listLines(processSection);\n\tif (process.join(\"\\n\").length > MAX_CONTRACT_PROCESS_CHARS) {\n\t\tthrow new Error(`Stage process exceeds ${MAX_CONTRACT_PROCESS_CHARS} characters.`);\n\t}\n\tconst outputs = listLines(outputsSection).map((line) => line.replace(/\\s*→\\s*output\\/?\\s*$/i, \"\").trim());\n\tconst humanCheck = humanSection.slice(0, MAX_HUMAN_CHECK_CHARS);\n\treturn {\n\t\ttitle,\n\t\toneJob: (oneJobMatch?.[1] ?? \"\").trim(),\n\t\tinputs,\n\t\tdoNotLoad: doNot,\n\t\tprocess,\n\t\toutputs,\n\t\thumanCheck,\n\t};\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { type PipelineDefinition, type PipelineRun, type PipelineStage, type StageDiskStatus, type StageScan } from "./types.ts";
2
+ export declare const RUN_MANIFEST_NAME = "run.json";
3
+ export declare function scanStageOutput(outputDir: string): {
4
+ status: StageDiskStatus;
5
+ outputFiles: string[];
6
+ };
7
+ export declare function stageOutputDir(runRoot: string, stage: PipelineStage): string;
8
+ export declare function scanPipelineRun(definition: PipelineDefinition, run: PipelineRun): readonly StageScan[];
9
+ export declare function runManifestPath(runRoot: string): string;
10
+ export declare function parsePipelineRun(value: unknown): PipelineRun | undefined;
11
+ export declare function readPipelineRun(runRoot: string): PipelineRun | undefined;
12
+ export declare function writePipelineRun(run: PipelineRun): void;
13
+ export declare function createPipelineRunRoot(cwd: string, runId: string): string;
14
+ export declare function instantiatePipelineRun(args: {
15
+ definition: PipelineDefinition;
16
+ runId: string;
17
+ runRoot: string;
18
+ goalId?: string;
19
+ now: string;
20
+ }): PipelineRun;
21
+ export declare function persistPipelineRun(run: PipelineRun, now: string): PipelineRun;
22
+ export declare function findActivePipelineRun(cwd: string): PipelineRun | undefined;
23
+ export declare function loadPipelineRunById(cwd: string, runId: string): PipelineRun | undefined;
24
+ export declare function decodePipelineRunPayload(data: unknown): PipelineRun | undefined;
25
+ export declare function pipelineRunParentDir(runRoot: string): string;
26
+ //# sourceMappingURL=run-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-state.d.ts","sourceRoot":"","sources":["../../../src/core/pipelines/run-state.ts"],"names":[],"mappings":"AAKA,OAAO,EAGN,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAM5C,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAiBrG;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,CAE5E;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,kBAAkB,EAAE,GAAG,EAAE,WAAW,GAAG,SAAS,SAAS,EAAE,CAKtG;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAGxE;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CASxE;AAED,wBAAgB,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