self-evolving-workflow 0.0.0-stage → 0.1.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 (375) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +195 -2
  3. package/dist/agent-memory-prompts.d.ts +13 -0
  4. package/dist/agent-memory-prompts.js +55 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +6 -0
  7. package/dist/closeout.d.ts +105 -0
  8. package/dist/closeout.js +473 -0
  9. package/dist/code.d.ts +39 -0
  10. package/dist/code.js +124 -0
  11. package/dist/codex-memory.d.ts +24 -0
  12. package/dist/codex-memory.js +217 -0
  13. package/dist/common.d.ts +16 -0
  14. package/dist/common.js +52 -0
  15. package/dist/context-envelope.d.ts +59 -0
  16. package/dist/context-envelope.js +23 -0
  17. package/dist/host-adapters.d.ts +34 -0
  18. package/dist/host-adapters.js +151 -0
  19. package/dist/http.d.ts +3 -0
  20. package/dist/http.js +90 -0
  21. package/dist/index.d.ts +16 -0
  22. package/dist/index.js +13 -0
  23. package/dist/knowledge-cli.d.ts +198 -0
  24. package/dist/knowledge-cli.js +761 -0
  25. package/dist/knowledge-reads.d.ts +72 -0
  26. package/dist/knowledge-reads.js +201 -0
  27. package/dist/memory-config.d.ts +44 -0
  28. package/dist/memory-config.js +204 -0
  29. package/dist/memory-evidence.d.ts +13 -0
  30. package/dist/memory-evidence.js +40 -0
  31. package/dist/memory-history.d.ts +46 -0
  32. package/dist/memory-history.js +432 -0
  33. package/dist/memory.d.ts +96 -0
  34. package/dist/memory.js +362 -0
  35. package/dist/retrospective.d.ts +57 -0
  36. package/dist/retrospective.js +240 -0
  37. package/dist/search.d.ts +36 -0
  38. package/dist/search.js +112 -0
  39. package/dist/skill-addition.d.ts +25 -0
  40. package/dist/skill-addition.js +89 -0
  41. package/dist/skill-design.d.ts +96 -0
  42. package/dist/skill-design.js +226 -0
  43. package/dist/skill-replay.d.ts +55 -0
  44. package/dist/skill-replay.js +448 -0
  45. package/dist/skill-route.d.ts +30 -0
  46. package/dist/skill-route.js +75 -0
  47. package/dist/transcript-evidence.d.ts +3 -0
  48. package/dist/transcript-evidence.js +58 -0
  49. package/dist/upstream/chunker.d.ts +24 -0
  50. package/dist/upstream/chunker.js +96 -0
  51. package/dist/upstream/file-protocol.d.ts +45 -0
  52. package/dist/upstream/file-protocol.js +117 -0
  53. package/dist/upstream/frontmatter.d.ts +47 -0
  54. package/dist/upstream/frontmatter.js +86 -0
  55. package/dist/upstream/graph-search.d.ts +33 -0
  56. package/dist/upstream/graph-search.js +67 -0
  57. package/dist/upstream/l1-extraction.d.ts +26 -0
  58. package/dist/upstream/l1-extraction.js +405 -0
  59. package/dist/upstream/llm.d.ts +8 -0
  60. package/dist/upstream/llm.js +1 -0
  61. package/dist/upstream/merge.d.ts +50 -0
  62. package/dist/upstream/merge.js +153 -0
  63. package/dist/upstream/prompts.d.ts +53 -0
  64. package/dist/upstream/prompts.js +181 -0
  65. package/dist/upstream/search-utils.d.ts +34 -0
  66. package/dist/upstream/search-utils.js +55 -0
  67. package/dist/upstream/slug.d.ts +26 -0
  68. package/dist/upstream/slug.js +103 -0
  69. package/dist/upstream/template.d.ts +29 -0
  70. package/dist/upstream/template.js +80 -0
  71. package/dist/upstream/tokenize.d.ts +4 -0
  72. package/dist/upstream/tokenize.js +29 -0
  73. package/dist/wiki-change.d.ts +76 -0
  74. package/dist/wiki-change.js +299 -0
  75. package/dist/wiki-entry.d.ts +26 -0
  76. package/dist/wiki-entry.js +93 -0
  77. package/dist/wiki-ingest.d.ts +12 -0
  78. package/dist/wiki-ingest.js +126 -0
  79. package/dist/wiki-migration.d.ts +16 -0
  80. package/dist/wiki-migration.js +268 -0
  81. package/dist/wiki-tokens.d.ts +1 -0
  82. package/dist/wiki-tokens.js +46 -0
  83. package/dist/wiki.d.ts +103 -0
  84. package/dist/wiki.js +330 -0
  85. package/dist/workflow-cli.d.ts +2 -0
  86. package/dist/workflow-cli.js +319 -0
  87. package/dist/workflow-install.d.ts +37 -0
  88. package/dist/workflow-install.js +148 -0
  89. package/dist/workflow-knowledge.d.ts +18 -0
  90. package/dist/workflow-knowledge.js +32 -0
  91. package/dist/workflow-mcp.d.ts +2 -0
  92. package/dist/workflow-mcp.js +137 -0
  93. package/dist/workflow-names.d.ts +4 -0
  94. package/dist/workflow-names.js +31 -0
  95. package/dist/workflow-runtime.d.ts +735 -0
  96. package/dist/workflow-runtime.js +747 -0
  97. package/dist/workflow-skills.d.ts +48 -0
  98. package/dist/workflow-skills.js +141 -0
  99. package/docs/images/impeccable-skill.png +0 -0
  100. package/docs/images/workflow-overview.png +0 -0
  101. package/docs/images/workflow-skills.png +0 -0
  102. package/package.json +77 -4
  103. package/skills/ew-impeccable/LICENSE +191 -0
  104. package/skills/ew-impeccable/NOTICE.md +19 -0
  105. package/skills/ew-impeccable/SKILL.md +91 -0
  106. package/skills/ew-impeccable/UPSTREAM.md +23 -0
  107. package/skills/ew-impeccable/reference/adapt.md +314 -0
  108. package/skills/ew-impeccable/reference/adapt.native.md +60 -0
  109. package/skills/ew-impeccable/reference/android.md +46 -0
  110. package/skills/ew-impeccable/reference/animate.md +91 -0
  111. package/skills/ew-impeccable/reference/audit.md +138 -0
  112. package/skills/ew-impeccable/reference/audit.native.md +141 -0
  113. package/skills/ew-impeccable/reference/bolder.md +35 -0
  114. package/skills/ew-impeccable/reference/clarify.md +96 -0
  115. package/skills/ew-impeccable/reference/colorize.md +88 -0
  116. package/skills/ew-impeccable/reference/craft-floor.md +44 -0
  117. package/skills/ew-impeccable/reference/craft.md +5 -0
  118. package/skills/ew-impeccable/reference/critique.md +808 -0
  119. package/skills/ew-impeccable/reference/degraded/asset-producer.md +36 -0
  120. package/skills/ew-impeccable/reference/degraded/documenter.md +23 -0
  121. package/skills/ew-impeccable/reference/degraded/finish-reviewer.md +72 -0
  122. package/skills/ew-impeccable/reference/degraded/manual-edit-applier.md +91 -0
  123. package/skills/ew-impeccable/reference/delight.md +72 -0
  124. package/skills/ew-impeccable/reference/distill.md +113 -0
  125. package/skills/ew-impeccable/reference/doctor.md +56 -0
  126. package/skills/ew-impeccable/reference/document.md +418 -0
  127. package/skills/ew-impeccable/reference/extract.md +68 -0
  128. package/skills/ew-impeccable/reference/harden.md +338 -0
  129. package/skills/ew-impeccable/reference/hooks.md +113 -0
  130. package/skills/ew-impeccable/reference/init.md +133 -0
  131. package/skills/ew-impeccable/reference/ios.md +51 -0
  132. package/skills/ew-impeccable/reference/layout.md +86 -0
  133. package/skills/ew-impeccable/reference/live-setup.md +102 -0
  134. package/skills/ew-impeccable/reference/live.md +326 -0
  135. package/skills/ew-impeccable/reference/new-work.md +209 -0
  136. package/skills/ew-impeccable/reference/onboard.md +236 -0
  137. package/skills/ew-impeccable/reference/operate.md +61 -0
  138. package/skills/ew-impeccable/reference/optimize.md +260 -0
  139. package/skills/ew-impeccable/reference/overdrive.md +127 -0
  140. package/skills/ew-impeccable/reference/polish.md +105 -0
  141. package/skills/ew-impeccable/reference/quieter.md +101 -0
  142. package/skills/ew-impeccable/reference/routing.md +20 -0
  143. package/skills/ew-impeccable/reference/shape.md +59 -0
  144. package/skills/ew-impeccable/reference/typeset.md +82 -0
  145. package/skills/ew-impeccable/reference/visualize.md +46 -0
  146. package/skills/ew-impeccable/scripts/build-phase.mjs +1022 -0
  147. package/skills/ew-impeccable/scripts/command-metadata.json +94 -0
  148. package/skills/ew-impeccable/scripts/comp-diff.mjs +391 -0
  149. package/skills/ew-impeccable/scripts/comp-spec.mjs +513 -0
  150. package/skills/ew-impeccable/scripts/concept-seed.mjs +814 -0
  151. package/skills/ew-impeccable/scripts/context-signals.mjs +325 -0
  152. package/skills/ew-impeccable/scripts/context.mjs +1521 -0
  153. package/skills/ew-impeccable/scripts/critique-storage.mjs +473 -0
  154. package/skills/ew-impeccable/scripts/data/font-index-failures.json +121 -0
  155. package/skills/ew-impeccable/scripts/data/font-index.json +1 -0
  156. package/skills/ew-impeccable/scripts/detect-csp.mjs +246 -0
  157. package/skills/ew-impeccable/scripts/detect.mjs +30 -0
  158. package/skills/ew-impeccable/scripts/detector/browser/injected/index.mjs +2580 -0
  159. package/skills/ew-impeccable/scripts/detector/cli/main.mjs +498 -0
  160. package/skills/ew-impeccable/scripts/detector/design-system.mjs +1311 -0
  161. package/skills/ew-impeccable/scripts/detector/detect-antipatterns-browser.js +9486 -0
  162. package/skills/ew-impeccable/scripts/detector/detect-antipatterns.mjs +51 -0
  163. package/skills/ew-impeccable/scripts/detector/engines/browser/detect-url.mjs +434 -0
  164. package/skills/ew-impeccable/scripts/detector/engines/regex/detect-text.mjs +1439 -0
  165. package/skills/ew-impeccable/scripts/detector/engines/static-html/css-cascade.mjs +1242 -0
  166. package/skills/ew-impeccable/scripts/detector/engines/static-html/detect-html.mjs +263 -0
  167. package/skills/ew-impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +189 -0
  168. package/skills/ew-impeccable/scripts/detector/findings.mjs +23 -0
  169. package/skills/ew-impeccable/scripts/detector/node/file-system.mjs +225 -0
  170. package/skills/ew-impeccable/scripts/detector/profile/profiler.mjs +166 -0
  171. package/skills/ew-impeccable/scripts/detector/registry/antipatterns.mjs +636 -0
  172. package/skills/ew-impeccable/scripts/detector/rules/checks.mjs +5750 -0
  173. package/skills/ew-impeccable/scripts/detector/shared/color.mjs +596 -0
  174. package/skills/ew-impeccable/scripts/detector/shared/constants.mjs +127 -0
  175. package/skills/ew-impeccable/scripts/detector/shared/fonts.mjs +30 -0
  176. package/skills/ew-impeccable/scripts/detector/shared/inline-ignores.mjs +148 -0
  177. package/skills/ew-impeccable/scripts/detector/shared/page.mjs +7 -0
  178. package/skills/ew-impeccable/scripts/detector/vendor/MDN-DATA-LICENSE +116 -0
  179. package/skills/ew-impeccable/scripts/detector/vendor/THIRD_PARTY_LICENSES.md +227 -0
  180. package/skills/ew-impeccable/scripts/detector/vendor/static-html-parser.build-entry.txt +11 -0
  181. package/skills/ew-impeccable/scripts/detector/vendor/static-html-parser.bundle.mjs +9121 -0
  182. package/skills/ew-impeccable/scripts/doctor.mjs +330 -0
  183. package/skills/ew-impeccable/scripts/embed-prompt.mjs +166 -0
  184. package/skills/ew-impeccable/scripts/font-match.mjs +457 -0
  185. package/skills/ew-impeccable/scripts/generate-image.mjs +447 -0
  186. package/skills/ew-impeccable/scripts/hook-admin.mjs +829 -0
  187. package/skills/ew-impeccable/scripts/hook-before-edit.mjs +538 -0
  188. package/skills/ew-impeccable/scripts/hook-lib.mjs +2493 -0
  189. package/skills/ew-impeccable/scripts/hook.mjs +79 -0
  190. package/skills/ew-impeccable/scripts/lib/artifact-schema.mjs +93 -0
  191. package/skills/ew-impeccable/scripts/lib/composition-catalog.mjs +200 -0
  192. package/skills/ew-impeccable/scripts/lib/concept-catalog.mjs +395 -0
  193. package/skills/ew-impeccable/scripts/lib/design-parser.mjs +880 -0
  194. package/skills/ew-impeccable/scripts/lib/font-fingerprint.mjs +564 -0
  195. package/skills/ew-impeccable/scripts/lib/font-index.mjs +130 -0
  196. package/skills/ew-impeccable/scripts/lib/hero-checks.mjs +246 -0
  197. package/skills/ew-impeccable/scripts/lib/image-metrics.mjs +306 -0
  198. package/skills/ew-impeccable/scripts/lib/impeccable-config.mjs +640 -0
  199. package/skills/ew-impeccable/scripts/lib/impeccable-paths.mjs +137 -0
  200. package/skills/ew-impeccable/scripts/lib/is-generated.mjs +72 -0
  201. package/skills/ew-impeccable/scripts/lib/live-path-globs.mjs +37 -0
  202. package/skills/ew-impeccable/scripts/lib/open-system-browser.mjs +26 -0
  203. package/skills/ew-impeccable/scripts/lib/png.mjs +281 -0
  204. package/skills/ew-impeccable/scripts/lib/provider.mjs +5 -0
  205. package/skills/ew-impeccable/scripts/lib/raster.mjs +194 -0
  206. package/skills/ew-impeccable/scripts/lib/roll-selection.mjs +369 -0
  207. package/skills/ew-impeccable/scripts/lib/staleness-deep.mjs +491 -0
  208. package/skills/ew-impeccable/scripts/lib/staleness-notice.mjs +169 -0
  209. package/skills/ew-impeccable/scripts/lib/staleness.mjs +532 -0
  210. package/skills/ew-impeccable/scripts/lib/surface-briefs.mjs +149 -0
  211. package/skills/ew-impeccable/scripts/lib/target-args.mjs +42 -0
  212. package/skills/ew-impeccable/scripts/lib/target-slug.mjs +33 -0
  213. package/skills/ew-impeccable/scripts/lib/template-extensions.mjs +146 -0
  214. package/skills/ew-impeccable/scripts/live/accept-css.mjs +617 -0
  215. package/skills/ew-impeccable/scripts/live/accept-verify.mjs +60 -0
  216. package/skills/ew-impeccable/scripts/live/browser-script-parts.mjs +84 -0
  217. package/skills/ew-impeccable/scripts/live/completion.mjs +28 -0
  218. package/skills/ew-impeccable/scripts/live/event-validation.mjs +199 -0
  219. package/skills/ew-impeccable/scripts/live/frameworks/astro.mjs +47 -0
  220. package/skills/ew-impeccable/scripts/live/frameworks/detect-utils.mjs +73 -0
  221. package/skills/ew-impeccable/scripts/live/frameworks/index.mjs +143 -0
  222. package/skills/ew-impeccable/scripts/live/frameworks/journal.mjs +197 -0
  223. package/skills/ew-impeccable/scripts/live/frameworks/nextjs.mjs +49 -0
  224. package/skills/ew-impeccable/scripts/live/frameworks/nuxt.mjs +161 -0
  225. package/skills/ew-impeccable/scripts/live/frameworks/script-src.mjs +17 -0
  226. package/skills/ew-impeccable/scripts/live/frameworks/static-html.mjs +26 -0
  227. package/skills/ew-impeccable/scripts/live/frameworks/sveltekit.mjs +71 -0
  228. package/skills/ew-impeccable/scripts/live/frameworks/tag-strategy.mjs +247 -0
  229. package/skills/ew-impeccable/scripts/live/frameworks/tanstack-start.mjs +70 -0
  230. package/skills/ew-impeccable/scripts/live/frameworks/vite-generic.mjs +42 -0
  231. package/skills/ew-impeccable/scripts/live/generation-preflight.mjs +149 -0
  232. package/skills/ew-impeccable/scripts/live/insert-ui.mjs +458 -0
  233. package/skills/ew-impeccable/scripts/live/instructions.mjs +142 -0
  234. package/skills/ew-impeccable/scripts/live/manual-apply.mjs +939 -0
  235. package/skills/ew-impeccable/scripts/live/manual-edit-routes.mjs +357 -0
  236. package/skills/ew-impeccable/scripts/live/manual-edits-buffer.mjs +152 -0
  237. package/skills/ew-impeccable/scripts/live/poll-lanes.mjs +14 -0
  238. package/skills/ew-impeccable/scripts/live/project-ignores.mjs +139 -0
  239. package/skills/ew-impeccable/scripts/live/roots.mjs +508 -0
  240. package/skills/ew-impeccable/scripts/live/session-store.mjs +563 -0
  241. package/skills/ew-impeccable/scripts/live/source-lock.mjs +105 -0
  242. package/skills/ew-impeccable/scripts/live/source-search.mjs +105 -0
  243. package/skills/ew-impeccable/scripts/live/svelte-ast.mjs +969 -0
  244. package/skills/ew-impeccable/scripts/live/svelte-component.mjs +1366 -0
  245. package/skills/ew-impeccable/scripts/live/sveltekit-adapter.mjs +304 -0
  246. package/skills/ew-impeccable/scripts/live/tanstack-adapter.mjs +259 -0
  247. package/skills/ew-impeccable/scripts/live/ui-surfaces.mjs +75 -0
  248. package/skills/ew-impeccable/scripts/live/vocabulary.mjs +171 -0
  249. package/skills/ew-impeccable/scripts/live-accept.mjs +938 -0
  250. package/skills/ew-impeccable/scripts/live-browser-dom.js +167 -0
  251. package/skills/ew-impeccable/scripts/live-browser-ignores.js +242 -0
  252. package/skills/ew-impeccable/scripts/live-browser-session.js +144 -0
  253. package/skills/ew-impeccable/scripts/live-browser.js +12851 -0
  254. package/skills/ew-impeccable/scripts/live-commit-manual-edits.mjs +1200 -0
  255. package/skills/ew-impeccable/scripts/live-complete.mjs +107 -0
  256. package/skills/ew-impeccable/scripts/live-copy-edit-agent.mjs +800 -0
  257. package/skills/ew-impeccable/scripts/live-discard-manual-edits.mjs +51 -0
  258. package/skills/ew-impeccable/scripts/live-inject.mjs +463 -0
  259. package/skills/ew-impeccable/scripts/live-insert.mjs +292 -0
  260. package/skills/ew-impeccable/scripts/live-manual-edit-evidence.mjs +368 -0
  261. package/skills/ew-impeccable/scripts/live-poll.mjs +430 -0
  262. package/skills/ew-impeccable/scripts/live-resume.mjs +123 -0
  263. package/skills/ew-impeccable/scripts/live-server.mjs +1698 -0
  264. package/skills/ew-impeccable/scripts/live-status.mjs +71 -0
  265. package/skills/ew-impeccable/scripts/live-target.mjs +30 -0
  266. package/skills/ew-impeccable/scripts/live-wrap.mjs +927 -0
  267. package/skills/ew-impeccable/scripts/live.mjs +334 -0
  268. package/skills/ew-impeccable/scripts/modern-screenshot.umd.js +14 -0
  269. package/skills/ew-impeccable/scripts/palette.mjs +628 -0
  270. package/skills/ew-impeccable/scripts/pin.mjs +352 -0
  271. package/skills/ew-impeccable/scripts/serve-question.mjs +1783 -0
  272. package/skills/ew-impeccable/scripts/surface-brief.mjs +74 -0
  273. package/skills/ew-knowledge/SKILL.md +35 -0
  274. package/skills/ew-knowledge/references/closeout-protocol.md +68 -0
  275. package/skills/ew-knowledge/references/knowledge-route.md +73 -0
  276. package/skills/ew-knowledge/references/wiki-maintenance.md +27 -0
  277. package/skills/ew-odyssey/SKILL.md +106 -0
  278. package/skills/ew-odyssey/references/audit-artifacts.md +7 -0
  279. package/skills/ew-odyssey/references/odyssey-base.md +104 -0
  280. package/skills/ew-odyssey/references/odyssey-debug.md +264 -0
  281. package/skills/ew-odyssey/references/odyssey-defensive.md +351 -0
  282. package/skills/ew-odyssey/references/odyssey-improve.md +230 -0
  283. package/skills/ew-odyssey/references/odyssey-planex.md +294 -0
  284. package/skills/ew-odyssey/references/odyssey-review.md +233 -0
  285. package/skills/ew-odyssey/references/odyssey-security.md +231 -0
  286. package/skills/ew-odyssey/references/odyssey-ui.md +232 -0
  287. package/skills/ew-odyssey/references/prepare/odyssey-debug.md +102 -0
  288. package/skills/ew-odyssey/references/prepare/odyssey-defensive.md +117 -0
  289. package/skills/ew-odyssey/references/prepare/odyssey-improve.md +95 -0
  290. package/skills/ew-odyssey/references/prepare/odyssey-planex.md +105 -0
  291. package/skills/ew-odyssey/references/prepare/odyssey-review.md +105 -0
  292. package/skills/ew-odyssey/references/prepare/odyssey-security.md +91 -0
  293. package/skills/ew-odyssey/references/prepare/odyssey-ui.md +88 -0
  294. package/skills/ew-odyssey/references/runtime-adapters.md +31 -0
  295. package/skills/ew-orchestrate/SKILL.md +89 -0
  296. package/skills/ew-orchestrate/references/auto-policy.md +66 -0
  297. package/skills/ew-orchestrate/references/boundary-grill.md +51 -0
  298. package/skills/ew-orchestrate/references/companion-route.md +40 -0
  299. package/skills/ew-orchestrate/references/ew-orchestrate.md +44 -0
  300. package/skills/ew-orchestrate/references/goal.md +51 -0
  301. package/skills/ew-orchestrate/references/orchestrator-run-loop.md +33 -0
  302. package/skills/ew-orchestrate/references/planning.md +54 -0
  303. package/skills/ew-orchestrate/steps/ew-analyze/SKILL.md +70 -0
  304. package/skills/ew-orchestrate/steps/ew-analyze/references/issue-gaps-analyze.md +24 -0
  305. package/skills/ew-orchestrate/steps/ew-analyze/references/prepare.md +8 -0
  306. package/skills/ew-orchestrate/steps/ew-analyze/references/workflow.md +138 -0
  307. package/skills/ew-orchestrate/steps/ew-auto-test/SKILL.md +80 -0
  308. package/skills/ew-orchestrate/steps/ew-auto-test/references/prepare.md +23 -0
  309. package/skills/ew-orchestrate/steps/ew-auto-test/references/workflow.md +31 -0
  310. package/skills/ew-orchestrate/steps/ew-blueprint/SKILL.md +122 -0
  311. package/skills/ew-orchestrate/steps/ew-blueprint/references/prepare.md +21 -0
  312. package/skills/ew-orchestrate/steps/ew-blueprint/references/workflow.md +28 -0
  313. package/skills/ew-orchestrate/steps/ew-brainstorm/SKILL.md +49 -0
  314. package/skills/ew-orchestrate/steps/ew-companion/SKILL.md +50 -0
  315. package/skills/ew-orchestrate/steps/ew-debug/SKILL.md +85 -0
  316. package/skills/ew-orchestrate/steps/ew-debug/references/prepare.md +27 -0
  317. package/skills/ew-orchestrate/steps/ew-debug/references/workflow.md +31 -0
  318. package/skills/ew-orchestrate/steps/ew-execute/SKILL.md +74 -0
  319. package/skills/ew-orchestrate/steps/ew-execute/references/prepare.md +27 -0
  320. package/skills/ew-orchestrate/steps/ew-execute/references/workflow.md +87 -0
  321. package/skills/ew-orchestrate/steps/ew-grill/SKILL.md +62 -0
  322. package/skills/ew-orchestrate/steps/ew-grill/references/prepare.md +26 -0
  323. package/skills/ew-orchestrate/steps/ew-grill/references/workflow.md +31 -0
  324. package/skills/ew-orchestrate/steps/ew-init/SKILL.md +56 -0
  325. package/skills/ew-orchestrate/steps/ew-init/references/prepare.md +25 -0
  326. package/skills/ew-orchestrate/steps/ew-init/references/workflow.md +28 -0
  327. package/skills/ew-orchestrate/steps/ew-plan/SKILL.md +131 -0
  328. package/skills/ew-orchestrate/steps/ew-plan/references/prepare.md +8 -0
  329. package/skills/ew-orchestrate/steps/ew-plan/references/tdd.md +53 -0
  330. package/skills/ew-orchestrate/steps/ew-plan/references/workflow.md +100 -0
  331. package/skills/ew-orchestrate/steps/ew-retrospective/SKILL.md +68 -0
  332. package/skills/ew-orchestrate/steps/ew-retrospective/references/prepare.md +18 -0
  333. package/skills/ew-orchestrate/steps/ew-retrospective/references/workflow.md +34 -0
  334. package/skills/ew-orchestrate/steps/ew-review/SKILL.md +45 -0
  335. package/skills/ew-orchestrate/steps/ew-review/references/prepare.md +17 -0
  336. package/skills/ew-orchestrate/steps/ew-review/references/workflow.md +116 -0
  337. package/skills/ew-orchestrate/steps/ew-roadmap/SKILL.md +62 -0
  338. package/skills/ew-orchestrate/steps/ew-roadmap/references/prepare.md +27 -0
  339. package/skills/ew-orchestrate/steps/ew-roadmap/references/workflow.md +28 -0
  340. package/skills/ew-orchestrate/steps/ew-test/SKILL.md +99 -0
  341. package/skills/ew-orchestrate/steps/ew-test/references/prepare.md +23 -0
  342. package/skills/ew-orchestrate/steps/ew-test/references/workflow.md +23 -0
  343. package/skills/ew-orchestrate/steps/ew-verify/SKILL.md +73 -0
  344. package/skills/ew-orchestrate/steps/ew-verify/references/prepare.md +21 -0
  345. package/skills/ew-orchestrate/steps/ew-verify/references/workflow.md +29 -0
  346. package/skills/ew-skill-design/SKILL.md +30 -0
  347. package/skills/ew-skill-design/references/package-contract.md +40 -0
  348. package/skills/ew-skill-design/references/validation.md +21 -0
  349. package/skills/team-swarm/SKILL.md +68 -0
  350. package/skills/team-swarm/references/mcp-coordination.md +14 -0
  351. package/skills/team-swarm/roles/analyst/role.md +181 -0
  352. package/skills/team-swarm/roles/ant/role.md +149 -0
  353. package/skills/team-swarm/roles/coordinator/commands/converge.md +112 -0
  354. package/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  355. package/skills/team-swarm/roles/coordinator/commands/iterate.md +171 -0
  356. package/skills/team-swarm/roles/coordinator/role.md +170 -0
  357. package/skills/team-swarm/roles/scorer/role.md +150 -0
  358. package/skills/team-swarm/scripts/aco.py +646 -0
  359. package/skills/team-swarm/scripts/pheromone.py +144 -0
  360. package/skills/team-swarm/scripts/scoring.py +111 -0
  361. package/skills/team-swarm/scripts/test_aco.py +606 -0
  362. package/skills/team-swarm/specs/ant-output-schema.md +127 -0
  363. package/skills/team-swarm/specs/convergence-criteria.md +108 -0
  364. package/skills/team-swarm/specs/pheromone-schema.md +125 -0
  365. package/skills/team-swarm/specs/swarm-config-template.json +71 -0
  366. package/skills/team-swarm/specs/swarm-protocol.md +119 -0
  367. package/skills/workflow-evolve/SKILL.md +64 -0
  368. package/skills/workflow-evolve/references/agy-gate.md +27 -0
  369. package/skills/workflow-evolve/references/auto-loop.md +23 -0
  370. package/skills/workflow-evolve/references/history-review.md +15 -0
  371. package/skills/workflow-evolve/scripts/codex-memory-replay.mjs +86 -0
  372. package/skills/workflow-evolve/scripts/codex-replay.mjs +1 -0
  373. package/skills/workflow-evolve/scripts/evolve-loop.mjs +260 -0
  374. package/skills/workflow-evolve/scripts/memory-codex-mcp.mjs +124 -0
  375. package/workflows/index.json +33 -0
@@ -0,0 +1,747 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { InputError, openDb, requireText, transaction } from './common.js';
5
+ import { contentSha256, KnowledgeReads, validateKnowledgeReads } from './knowledge-reads.js';
6
+ import { Wiki } from './wiki.js';
7
+ import { buildWikiPrior, wikiLookupScope } from './workflow-knowledge.js';
8
+ import { workflowName } from './workflow-names.js';
9
+ import { bindWorkflowSkill, readWorkflowLink, readWorkflowMarkdown, workflowBlob, workflowHash, workflowHeader, workflowMeta, workflowPath, workflowRecord, } from './workflow-skills.js';
10
+ const maxArtifactBytes = 5 * 1024 * 1024;
11
+ export function workflowId(value, label) {
12
+ const id = requireText(value, label);
13
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/.test(id) ||
14
+ /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9]|constructor|prototype)$/i.test(id)) {
15
+ throw new InputError('Invalid ' + label + ': ' + id);
16
+ }
17
+ return id;
18
+ }
19
+ function changed(id, expected, actual) {
20
+ if (expected !== actual)
21
+ throw new InputError('REVISION_CONFLICT ' + id + ': expected ' + expected + ', current ' + actual);
22
+ }
23
+ function findRun(session, runId) {
24
+ const run = session.runs.find(item => item.id === runId);
25
+ if (!run)
26
+ throw new InputError('Run not found: ' + runId);
27
+ return run;
28
+ }
29
+ function findStep(session, id) {
30
+ const step = session.steps.find(item => item.id === id);
31
+ if (!step)
32
+ throw new InputError('Step not found: ' + id);
33
+ return step;
34
+ }
35
+ function isDecisionOnlyStep(step) {
36
+ return step.kind === 'decision' || (!step.command && Boolean(step.decision_ref));
37
+ }
38
+ function activeDecision(session) {
39
+ const gated = session.steps.find(step => step.status === 'completed' && step.decision_ref &&
40
+ (step.decision === undefined || step.decision === 'escalate'));
41
+ if (gated)
42
+ return gated;
43
+ const firstPending = session.steps.find(step => step.status === 'pending');
44
+ return firstPending && isDecisionOnlyStep(firstPending) ? firstPending : undefined;
45
+ }
46
+ function nextAction(session) {
47
+ const authority = session.policy?.auto_mode ? 'automatic' : 'manual';
48
+ const active = session.runs.find(run => run.status === 'running' || run.status === 'blocked');
49
+ const decision = activeDecision(session);
50
+ if (session.status === 'completed')
51
+ return { action: 'end', authority };
52
+ if (active)
53
+ return { action: active.status === 'running' ? 'execute' : 'recover', run_id: active.id, authority };
54
+ if (decision)
55
+ return { action: 'decide', decision_ref: decision.decision_ref, authority };
56
+ if (session.steps.some(step => step.status === 'pending'))
57
+ return { action: 'next', authority };
58
+ return { action: 'complete', authority };
59
+ }
60
+ function safeFile(root, path) {
61
+ let file = root;
62
+ for (const part of workflowPath(path).split('/')) {
63
+ file = join(file, part);
64
+ const info = lstatSync(file, { throwIfNoEntry: false });
65
+ if (!info)
66
+ return;
67
+ if (info.isSymbolicLink())
68
+ throw new InputError('Workflow files must be regular entries: ' + path);
69
+ }
70
+ const info = lstatSync(file);
71
+ if (!info.isFile() || info.size > maxArtifactBytes)
72
+ throw new InputError('Expected a regular file at most 5 MiB: ' + path);
73
+ const bytes = readFileSync(file);
74
+ if (bytes.length > maxArtifactBytes)
75
+ throw new InputError('Workflow file exceeds 5 MiB: ' + path);
76
+ return bytes;
77
+ }
78
+ function expandSlot(directory, slot) {
79
+ if (!slot.includes('{'))
80
+ return [slot];
81
+ const parent = slot.slice(0, slot.lastIndexOf('/'));
82
+ const dir = join(directory, workflowPath(parent));
83
+ const info = lstatSync(dir, { throwIfNoEntry: false });
84
+ if (!info)
85
+ return [];
86
+ if (!info.isDirectory())
87
+ throw new InputError('Invalid output directory: ' + parent);
88
+ const pattern = slot.slice(parent.length + 1).split(/(\{[a-zA-Z_]+\})/).map(part => part.startsWith('{') ? '[A-Za-z0-9_-]+' : part.replace(/[.*+?^$(){}|[\]\\]/g, '\\$&')).join('');
89
+ return readdirSync(dir).filter(path => new RegExp('^' + pattern + '$').test(path)).map(path => parent + '/' + path);
90
+ }
91
+ function artifactMetadata(path, bytes) {
92
+ const text = bytes.toString('utf8').replace(/^\uFEFF/, '');
93
+ if (path.endsWith('.json') || path.endsWith('.ndjson')) {
94
+ const records = path.endsWith('.ndjson') ? text.trim().split(/\r?\n/).map(line => JSON.parse(line)) : [JSON.parse(text)];
95
+ return workflowMeta(workflowRecord(records[0], 'artifact body')._meta);
96
+ }
97
+ return workflowMeta(workflowHeader(text));
98
+ }
99
+ export function workflowDbPath(root) {
100
+ return join(root, '.agent-memory', 'workflow.db');
101
+ }
102
+ export function readEvolveSessions(root, id) {
103
+ const path = workflowDbPath(root);
104
+ if (!existsSync(path))
105
+ return [];
106
+ const db = openDb(path, true);
107
+ try {
108
+ const rows = id ? db.prepare('SELECT body FROM sessions WHERE id = ?').all(id)
109
+ : db.prepare('SELECT body FROM sessions ORDER BY id').all();
110
+ return rows.map(row => JSON.parse(String(row.body)));
111
+ }
112
+ finally {
113
+ db.close();
114
+ }
115
+ }
116
+ export function evolveSessionReceipt(session) {
117
+ if (session.status !== 'completed' || !session.completed_at) {
118
+ throw new InputError('Complete the Evolve Session before harvesting its evidence');
119
+ }
120
+ return {
121
+ schema_version: 'evolve-session-completion/1.0',
122
+ id: workflowHash(JSON.stringify([session.id, session.created_at, session.completed_at, session.revision])).slice(7),
123
+ session_id: session.id,
124
+ recorded_at: session.completed_at,
125
+ messages: session.runs.flatMap(run => {
126
+ const timestamp = run.finished_at ?? session.completed_at;
127
+ return [
128
+ { id: run.id + ':outcome', role: 'tool', timestamp,
129
+ content: [run.task.command + ' ' + run.status, run.summary, run.retry_of_run_id && 'retries ' + run.retry_of_run_id]
130
+ .filter(Boolean).join('. ') },
131
+ ...(run.knowledge_reads ? [{ id: run.id + ':knowledge-reads', role: 'tool', timestamp,
132
+ content: JSON.stringify(run.knowledge_reads) }] : []),
133
+ ];
134
+ }),
135
+ };
136
+ }
137
+ export class WorkflowStore {
138
+ root;
139
+ db;
140
+ constructor(root) {
141
+ this.root = root;
142
+ const path = workflowDbPath(root);
143
+ mkdirSync(dirname(path), { recursive: true });
144
+ this.db = openDb(path);
145
+ this.db.exec('PRAGMA foreign_keys = ON');
146
+ this.db.exec([
147
+ 'CREATE TABLE IF NOT EXISTS sessions (id TEXT PRIMARY KEY, body TEXT NOT NULL) STRICT;',
148
+ 'CREATE TABLE IF NOT EXISTS requests (session TEXT NOT NULL, id TEXT NOT NULL, fingerprint TEXT NOT NULL, receipt TEXT NOT NULL, PRIMARY KEY (session, id), FOREIGN KEY (session) REFERENCES sessions(id)) STRICT;',
149
+ 'CREATE TABLE IF NOT EXISTS artifacts (session TEXT NOT NULL, id TEXT NOT NULL, body BLOB NOT NULL, PRIMARY KEY (session, id), FOREIGN KEY (session) REFERENCES sessions(id)) STRICT;',
150
+ ].join('\n'));
151
+ }
152
+ close() { this.db.close(); }
153
+ find(id) {
154
+ const row = this.db.prepare('SELECT body FROM sessions WHERE id = ?').get(id);
155
+ return row ? JSON.parse(String(row.body)) : undefined;
156
+ }
157
+ status(id) {
158
+ const session = this.find(id);
159
+ if (!session) {
160
+ if (existsSync(join(this.root, '.workflow', 'sessions', workflowId(id, 'Session ID')))) {
161
+ throw new InputError('Historical Session: use evolve session review or evolve closeout session to inspect pre-Evolve Sessions');
162
+ }
163
+ throw new InputError('Evolve Session not found: ' + id);
164
+ }
165
+ return { ...session, orchestration_revision: session.revision, continuation: nextAction(session) };
166
+ }
167
+ list(filter) {
168
+ const query = filter?.query?.trim().toLowerCase();
169
+ return this.db.prepare('SELECT body FROM sessions ORDER BY id').all().map(row => {
170
+ const session = JSON.parse(String(row.body));
171
+ return { id: session.id, objective: session.objective, status: session.status,
172
+ orchestration_revision: session.revision, steps: session.steps,
173
+ ...(session.goals ? { goals: session.goals } : {}),
174
+ ...(session.policy ? { policy: session.policy } : {}),
175
+ continuation: nextAction(session) };
176
+ }).filter(item => (!filter?.status || item.status === filter.status) &&
177
+ (!query || item.id.toLowerCase().includes(query) || item.objective.toLowerCase().includes(query)));
178
+ }
179
+ save(session) {
180
+ this.db.prepare('INSERT INTO sessions VALUES (?, ?) ON CONFLICT(id) DO UPDATE SET body=excluded.body')
181
+ .run(session.id, JSON.stringify(session));
182
+ }
183
+ change(id, operation, mutation, input, apply) {
184
+ const actor = workflowId(mutation.actor, 'actor');
185
+ const fingerprint = workflowHash(JSON.stringify([operation, actor, mutation.revision, mutation.runRevision, mutation.evidence, mutation.reason, input]));
186
+ const requestId = mutation.requestId ? workflowId(mutation.requestId, 'request ID') : fingerprint.slice(7);
187
+ return transaction(this.db, () => {
188
+ const saved = this.db.prepare('SELECT fingerprint, receipt FROM requests WHERE session = ? AND id = ?').get(id, requestId);
189
+ if (saved) {
190
+ if (saved.fingerprint !== fingerprint)
191
+ throw new InputError('IDEMPOTENCY_PAYLOAD_MISMATCH ' + requestId);
192
+ return JSON.parse(String(saved.receipt));
193
+ }
194
+ const receipt = { ...apply(), receipt: { request_id: requestId, action: operation, actor,
195
+ recorded_at: new Date().toISOString(), evidence: mutation.evidence ?? [], reason: mutation.reason } };
196
+ this.db.prepare('INSERT INTO requests VALUES (?, ?, ?, ?)').run(id, requestId, fingerprint, JSON.stringify(receipt));
197
+ return receipt;
198
+ });
199
+ }
200
+ mutate(id, operation, change, input, apply) {
201
+ return this.change(id, operation, change, input, () => {
202
+ const session = this.status(id);
203
+ if (session.status !== 'open')
204
+ throw new InputError('Session is completed: ' + id);
205
+ changed(id, change.revision, session.revision);
206
+ const result = apply(session);
207
+ session.revision++;
208
+ // 续步由已持久化的状态计算。
209
+ const { continuation: _continuation, orchestration_revision: _revision, ...saved } = session;
210
+ this.save(saved);
211
+ return { ...result, session_id: id, orchestration_revision: session.revision, continuation: nextAction(session) };
212
+ });
213
+ }
214
+ open(id, objective, definition, steps, change, options) {
215
+ workflowId(id, 'Session ID');
216
+ return this.change(id, 'session.open', change, { objective, definition, steps, ...options }, () => {
217
+ if (this.find(id) || existsSync(join(this.root, '.workflow', 'sessions', id)))
218
+ throw new InputError('Session ID already exists: ' + id);
219
+ const existing = new Set();
220
+ const chain = steps.map(step => {
221
+ this.validateStep(step);
222
+ if (existing.has(step.id) || (step.decision_ref && steps.filter(item => item.decision_ref === step.decision_ref).length > 1)) {
223
+ throw new InputError('Duplicate chain step or decision: ' + step.id);
224
+ }
225
+ existing.add(step.id);
226
+ return { ...step, command: step.command ? workflowName(step.command) : '', status: 'pending' };
227
+ });
228
+ const session = {
229
+ schema_version: 'evolve-session/1.0', id, objective: requireText(objective, 'objective'), definition_of_done: definition,
230
+ ...(options?.boundaryContract ? { boundary_contract: options.boundaryContract } : {}),
231
+ ...(options?.goals ? { goals: options.goals } : {}),
232
+ ...(options?.policy ? { policy: options.policy } : {}),
233
+ created_at: new Date().toISOString(), revision: 0, status: 'open', steps: chain, runs: [], aliases: {}, artifacts: {},
234
+ };
235
+ this.save(session);
236
+ return { session_id: id, status: 'open', orchestration_revision: 0, continuation: nextAction(session) };
237
+ });
238
+ }
239
+ validateStep(step) {
240
+ workflowId(step.id, 'step ID');
241
+ if (step.decision_ref)
242
+ workflowId(step.decision_ref, 'decision ID');
243
+ if (step.retry_max !== undefined && (!Number.isSafeInteger(step.retry_max) || step.retry_max < 1)) {
244
+ throw new InputError('retry_max must be a positive integer');
245
+ }
246
+ if (isDecisionOnlyStep(step)) {
247
+ if (!step.decision_ref)
248
+ throw new InputError('Decision-only steps require a decision ID');
249
+ if (step.command)
250
+ throw new InputError('Decision-only steps cannot bind a Skill command');
251
+ return;
252
+ }
253
+ bindWorkflowSkill(this.root, step.command);
254
+ if (/^ew-odyssey-(security|defensive)$/.test(workflowName(step.command)) && step.args.includes('--fix')) {
255
+ throw new InputError('This Odyssey mode uses a read-only audit');
256
+ }
257
+ }
258
+ amend(id, objective, definition, change) {
259
+ return this.mutate(id, 'session.amend', change, { objective, definition }, session => {
260
+ if (session.runs.some(run => run.status === 'blocked' || run.status === 'running')) {
261
+ throw new InputError('Resolve the active Run before amending the Session');
262
+ }
263
+ if (!change.evidence?.length)
264
+ throw new InputError('Supply evidence for the approved amendment');
265
+ const previous = session.objective;
266
+ session.objective = requireText(objective, 'amended objective');
267
+ if (definition !== undefined)
268
+ session.definition_of_done = requireText(definition, 'definition of done');
269
+ const amendments = (session.amendments ??= []);
270
+ const amendment = {
271
+ id: 'CHG-' + String(amendments.length + 1).padStart(3, '0'),
272
+ recorded_at: new Date().toISOString(), previous_objective: previous, objective: session.objective,
273
+ ...(definition !== undefined ? { definition_of_done: session.definition_of_done } : {}),
274
+ evidence: change.evidence, ...(change.reason ? { reason: change.reason } : {}),
275
+ };
276
+ amendments.push(amendment);
277
+ return { amendment_id: amendment.id, previous_objective: previous, objective: session.objective, definition_of_done: session.definition_of_done };
278
+ });
279
+ }
280
+ chain(id, action, step, after, change) {
281
+ return this.mutate(id, 'chain.' + action, change, { step, after }, session => {
282
+ const current = session.steps.findIndex(item => item.id === step.id);
283
+ if (action === 'insert') {
284
+ if (current >= 0)
285
+ throw new InputError('Step already exists: ' + step.id);
286
+ this.validateStep(step);
287
+ if (step.decision_ref && session.steps.some(item => item.decision_ref === step.decision_ref))
288
+ throw new InputError('Decision already exists');
289
+ const index = after ? session.steps.findIndex(item => item.id === after) + 1 : session.steps.length;
290
+ const firstPending = session.steps.findIndex(item => item.status === 'pending');
291
+ if ((after && index === 0) || index < (firstPending < 0 ? session.steps.length : firstPending)) {
292
+ throw new InputError('Insert the step in the pending chain');
293
+ }
294
+ session.steps.splice(index, 0, { ...step, command: step.command ? workflowName(step.command) : '', status: 'pending' });
295
+ }
296
+ else {
297
+ const original = findStep(session, step.id);
298
+ if (original.status !== 'pending')
299
+ throw new InputError('Select a pending step');
300
+ if (action === 'replace') {
301
+ const replacement = { ...original, ...step, decision_ref: step.decision_ref ?? original.decision_ref };
302
+ this.validateStep(replacement);
303
+ if (replacement.decision_ref && session.steps.some(item => item.id !== step.id && item.decision_ref === replacement.decision_ref)) {
304
+ throw new InputError('Decision already exists');
305
+ }
306
+ session.steps[current] = { ...replacement, command: replacement.command ? workflowName(replacement.command) : '' };
307
+ }
308
+ else {
309
+ if (!change.evidence?.length)
310
+ throw new InputError('Supply evidence for a skipped step');
311
+ original.status = 'skipped';
312
+ }
313
+ }
314
+ return { step_id: step.id, status: action === 'skip' ? 'skipped' : 'pending' };
315
+ });
316
+ }
317
+ runDir(id, runId) {
318
+ return join(this.root, '.agent-memory', 'workflow', 'runs', id, runId);
319
+ }
320
+ packet(session, run) {
321
+ return {
322
+ session_id: session.id, run_id: run.id, run_dir: this.runDir(session.id, run.id),
323
+ status: run.status, revision: run.revision, orchestration_revision: session.revision,
324
+ task: { ...run.task, input_refs: run.inputs },
325
+ skill_ref: run.skill, gates: run.skill.gates, upstream_aliases: run.input_aliases,
326
+ upstream: Object.fromEntries(run.inputs.map(id => [id, session.artifacts[id]])),
327
+ skill_reads: this.readProof(run), retry_of_run_id: run.retry_of_run_id,
328
+ ...(session.boundary_contract ? { boundary_contract: session.boundary_contract } : {}),
329
+ ...(session.goals ? { goals: session.goals } : {}),
330
+ ...(session.amendments ? { amendments: session.amendments } : {}),
331
+ ...(session.policy ? { policy: session.policy } : {}),
332
+ ...(run.knowledge_reads ? { knowledge_reads: run.knowledge_reads } : {}),
333
+ };
334
+ }
335
+ next(id, change, gates = [], stepId) {
336
+ const packet = this.mutate(id, 'run.next', change, { gates, stepId }, session => {
337
+ if (nextAction(session).action !== 'next')
338
+ throw new InputError('Workflow continuation does not dispatch a Run');
339
+ const step = session.steps.find(item => item.status === 'pending');
340
+ if (stepId && step.id !== stepId)
341
+ throw new InputError('Run creation must follow the pending chain');
342
+ const attempts = session.runs.filter(item => item.step_id === step.id && item.status !== 'running').length;
343
+ if (step.retry_max !== undefined && attempts >= step.retry_max) {
344
+ throw new InputError('Retry limit exceeded for step: ' + step.id);
345
+ }
346
+ const command = workflowName(step.command);
347
+ const skill = bindWorkflowSkill(this.root, command);
348
+ const missing = skill.gates.entry.filter(gate => !gates.includes(gate));
349
+ if (missing.length)
350
+ throw new InputError('Missing entry gates: ' + missing.join(', '));
351
+ const args = step.args.map(arg => arg.replaceAll('{session}', session.id).replaceAll('{intent}', session.objective));
352
+ const run = {
353
+ id: 'run-' + randomUUID(), owner: change.actor, step_id: step.id, status: 'running', revision: 0, skill,
354
+ task: { command, args, goal: session.objective },
355
+ inputs: [], input_aliases: {}, reads: {},
356
+ ...(step.run_id ? { retry_of_run_id: step.run_id } : {}),
357
+ };
358
+ for (const slot of skill.consumes) {
359
+ const artifact = slot.alias ? session.artifacts[session.aliases[slot.alias]] :
360
+ Object.values(session.artifacts).findLast(item => item.kind === slot.kind && item.schema === slot.schema && item.role === slot.role);
361
+ if (!artifact || artifact.kind !== slot.kind || artifact.schema !== slot.schema || artifact.role !== slot.role ||
362
+ (!slot.accepts_negative_evidence && findRun(session, artifact.run_id).verdict === 'done_with_concerns')) {
363
+ if (slot.required)
364
+ throw new InputError('Required upstream artifact: ' + (slot.alias ?? slot.kind));
365
+ continue;
366
+ }
367
+ run.inputs.push(artifact.id);
368
+ if (slot.alias)
369
+ run.input_aliases[slot.alias] = artifact.id;
370
+ if (slot.role === 'primary') {
371
+ run.inputs.push(...Object.values(session.artifacts)
372
+ .filter(item => item.run_id === artifact.run_id && (item.role === 'attachment' || item.role === 'evidence'))
373
+ .map(item => item.id));
374
+ }
375
+ }
376
+ run.inputs = [...new Set(run.inputs)];
377
+ session.runs.push(run);
378
+ step.status = 'running';
379
+ step.run_id = run.id;
380
+ return this.packet(session, run);
381
+ });
382
+ mkdirSync(join(packet.run_dir, 'outputs'), { recursive: true });
383
+ return packet;
384
+ }
385
+ brief(id, runId) {
386
+ const session = this.status(id);
387
+ const packet = this.packet(session, findRun(session, runId));
388
+ if (packet.status !== 'sealed')
389
+ mkdirSync(join(packet.run_dir, 'outputs'), { recursive: true });
390
+ return { ...packet, continuation: nextAction(session) };
391
+ }
392
+ readSkill(id, runId, from, destination) {
393
+ return transaction(this.db, () => {
394
+ const session = this.find(id);
395
+ if (!session)
396
+ throw new InputError('Evolve Session not found: ' + id);
397
+ const run = findRun(session, runId);
398
+ if ((from === undefined) !== (destination === undefined))
399
+ throw new InputError('Supply both --from and a Markdown destination');
400
+ if (from && !Object.hasOwn(run.reads, from))
401
+ throw new InputError('Read the source document first: ' + from);
402
+ const read = from && destination ? readWorkflowLink(this.root, run.skill, from, destination)
403
+ : readWorkflowMarkdown(this.root, run.skill, run.skill.entry);
404
+ if (run.status === 'running' || run.status === 'blocked') {
405
+ run.reads[read.path] = read.sha256;
406
+ this.save(session);
407
+ }
408
+ return { ...read, recorded: Object.hasOwn(run.reads, read.path) };
409
+ });
410
+ }
411
+ readArtifact(id, runId, artifactId, scope = {}) {
412
+ const session = this.status(id);
413
+ const run = findRun(session, runId);
414
+ const resolved = run.input_aliases[artifactId] ?? artifactId;
415
+ if (!run.inputs.includes(resolved))
416
+ throw new InputError('Artifact is outside the Run input binding: ' + artifactId);
417
+ const artifact = session.artifacts[resolved];
418
+ const bytes = this.db.prepare('SELECT body FROM artifacts WHERE session = ? AND id = ?').get(id, resolved)?.body;
419
+ if (!(bytes instanceof Uint8Array) || workflowHash(Buffer.from(bytes)) !== artifact.sha256) {
420
+ throw new InputError('Sealed artifact bytes are unavailable or changed: ' + resolved);
421
+ }
422
+ const content = Buffer.from(bytes).toString('utf8');
423
+ if (artifact.wiki_priors) {
424
+ const scopes = workflowRecord(JSON.parse(content), 'session-priors').lookup_scopes;
425
+ const expected = JSON.stringify(wikiLookupScope(scope));
426
+ if (!Array.isArray(scopes) || !scopes.some(item => JSON.stringify(wikiLookupScope(item)) === expected)) {
427
+ throw new InputError('Wiki scope is outside session-priors; use wiki_context in this Run');
428
+ }
429
+ transaction(this.db, () => {
430
+ const latest = this.status(id);
431
+ const consumer = findRun(latest, runId);
432
+ if (consumer.status !== 'running' || consumer.priors_reuse?.some(item => item.artifact_id === artifact.id))
433
+ return;
434
+ (consumer.priors_reuse ??= []).push({ artifact_id: artifact.id, producer_run_id: artifact.run_id, content_sha256: artifact.sha256 });
435
+ const { continuation: _continuation, orchestration_revision: _revision, ...saved } = latest;
436
+ this.save(saved);
437
+ });
438
+ }
439
+ return { ...artifact, content };
440
+ }
441
+ readProof(run) {
442
+ return {
443
+ reference: run.skill, reads: Object.entries(run.reads).map(([path, sha256]) => ({ path, sha256 })),
444
+ missing: run.skill.required_links.filter(path => !Object.hasOwn(run.reads, path)),
445
+ };
446
+ }
447
+ cliWikiPriors(knowledge) {
448
+ if (!knowledge || (!knowledge.constraints_bound.length && !knowledge.reads.some(item => item.kind === 'wiki')))
449
+ return;
450
+ if (!existsSync(join(this.root, 'wiki')))
451
+ return;
452
+ const wiki = new Wiki(this.root);
453
+ const priors = [];
454
+ for (const bound of knowledge.constraints_bound) {
455
+ const page = wiki.getEntry(bound.knowledge_id);
456
+ if (page && contentSha256(page.body) === bound.content_sha256) {
457
+ priors.push(buildWikiPrior(page, 'constraint', {}, ''));
458
+ }
459
+ }
460
+ for (const read of knowledge.reads) {
461
+ if (read.kind !== 'wiki' || priors.some(item => item.id === read.id))
462
+ continue;
463
+ const page = wiki.getEntry(read.id);
464
+ if (!page)
465
+ continue;
466
+ const search = knowledge.searches.find(item => item.search_id === read.from_search_id);
467
+ const lookupScope = wikiLookupScope(search?.filters ?? {});
468
+ priors.push(buildWikiPrior(page, page.entry?.mode === 'constraint' ? 'constraint' : 'reference', lookupScope, read.from_search_id ?? ''));
469
+ }
470
+ return priors.length ? priors : undefined;
471
+ }
472
+ outputs(session, run, gates) {
473
+ const directory = this.runDir(session.id, run.id);
474
+ const errors = this.readProof(run).missing.map(path => 'Required Skill read: ' + path);
475
+ errors.push(...run.skill.gates.exit.filter(gate => !gates.includes(gate)).map(gate => 'Required exit gate: ' + gate));
476
+ if (run.status !== 'running')
477
+ errors.push('Complete a running Run');
478
+ for (const item of Object.values(run.assignments ?? {})) {
479
+ if (item.cancellation)
480
+ continue;
481
+ const bytes = item.result && safeFile(directory, item.path);
482
+ if (!item.result || !bytes || workflowHash(bytes) !== item.result.sha256)
483
+ errors.push('Swarm assignment evidence: ' + item.id);
484
+ }
485
+ const trace = safeFile(directory, 'knowledge-reads.json');
486
+ if (trace && run.knowledge_reads)
487
+ errors.push('Select a single Run knowledge receipt source');
488
+ const knowledge = trace ? validateKnowledgeReads(JSON.parse(trace.toString('utf8'))) : run.knowledge_reads;
489
+ if (trace && knowledge?.priors_reuse)
490
+ errors.push('Run reuse evidence comes from bound artifact reads');
491
+ const receipt = run.priors_reuse?.length
492
+ ? { ...(knowledge ?? new KnowledgeReads().toJSON()), priors_reuse: run.priors_reuse } : knowledge;
493
+ const reportBytes = safeFile(directory, 'report.md');
494
+ if (reportBytes) {
495
+ const reportMeta = workflowHeader(reportBytes.toString('utf8'));
496
+ if (Array.isArray(reportMeta.next)) {
497
+ for (const item of reportMeta.next) {
498
+ if (item && typeof item === 'object' && typeof item.command === 'string') {
499
+ const cmd = item.command;
500
+ try {
501
+ bindWorkflowSkill(this.root, cmd);
502
+ }
503
+ catch {
504
+ errors.push('Invalid report.md next command: ' + cmd);
505
+ }
506
+ }
507
+ }
508
+ }
509
+ }
510
+ const publications = [];
511
+ for (const slot of run.skill.produces) {
512
+ const isPriorsSlot = slot.alias === 'session-priors' && slot.kind === 'priors' && slot.schema === 'priors/1.0'
513
+ && slot.path === 'outputs/priors.json';
514
+ const priors = isPriorsSlot ? (run.wiki_priors?.length ? run.wiki_priors : this.cliWikiPriors(knowledge)) : undefined;
515
+ const generated = priors?.length ? Buffer.from(JSON.stringify({
516
+ _meta: { alias: slot.alias, kind: slot.kind, schema: slot.schema, role: slot.role },
517
+ source_run_id: run.id,
518
+ lookup_scopes: [...new Map(priors.map(item => [JSON.stringify(item.lookup_scope), item.lookup_scope])).values()],
519
+ wiki: priors,
520
+ })) : undefined;
521
+ let discovered = 0;
522
+ for (const path of generated ? [slot.path] : expandSlot(directory, slot.path)) {
523
+ const bytes = generated ?? safeFile(directory, path);
524
+ if (!bytes)
525
+ continue;
526
+ discovered++;
527
+ if (bytes.length > maxArtifactBytes)
528
+ errors.push('Artifact exceeds the size limit: ' + path);
529
+ const meta = artifactMetadata(path, bytes);
530
+ if (meta.kind !== slot.kind || meta.schema !== slot.schema || meta.role !== slot.role || meta.alias !== slot.alias) {
531
+ errors.push('Artifact metadata does not match the Skill contract: ' + path);
532
+ }
533
+ if (workflowName(run.task.command).startsWith('ew-odyssey-') && path === 'outputs/session.json' &&
534
+ workflowRecord(JSON.parse(bytes.toString('utf8').replace(/^\uFEFF/, '')), 'Odyssey checkpoint').current_state !== 'END') {
535
+ errors.push('Finish the Odyssey domain checkpoint before sealing');
536
+ }
537
+ const artifact = { ...meta, id: 'art-' + randomUUID(), path, run_id: run.id,
538
+ sha256: workflowHash(bytes), derived_from: run.inputs, status: 'sealed', ...(generated ? { wiki_priors: true } : {}) };
539
+ publications.push({ artifact, bytes });
540
+ }
541
+ if (!discovered && slot.required)
542
+ errors.push('Required artifact: ' + slot.path);
543
+ }
544
+ return { errors, publications, knowledge: receipt };
545
+ }
546
+ check(id, runId, gates) {
547
+ const session = this.status(id);
548
+ const run = findRun(session, runId);
549
+ if (run.status === 'sealed')
550
+ return {
551
+ ...this.packet(session, run), completion_preflight: { ready: false, errors: ['Run is sealed'] },
552
+ knowledge_reads: run.knowledge_reads,
553
+ };
554
+ const { errors, knowledge } = this.outputs(session, run, gates);
555
+ return { ...this.packet(session, run), completion_preflight: { ready: errors.length === 0, errors }, knowledge_reads: knowledge };
556
+ }
557
+ completeRun(id, runId, summary, verdict, gates, change) {
558
+ return this.mutate(id, 'run.complete', change, { runId, summary, verdict, gates }, session => {
559
+ const run = findRun(session, runId);
560
+ changed(runId, change.runRevision, run.revision);
561
+ const { errors, publications, knowledge } = this.outputs(session, run, gates);
562
+ if (errors.length)
563
+ throw new InputError(errors.join('\n'));
564
+ const artifacts = {};
565
+ const aliases = {};
566
+ for (const { artifact, bytes } of publications) {
567
+ this.db.prepare('INSERT INTO artifacts VALUES (?, ?, ?)').run(id, artifact.id, bytes);
568
+ artifacts[artifact.id] = artifact;
569
+ if (artifact.alias)
570
+ aliases[artifact.alias] = artifact.id;
571
+ }
572
+ Object.assign(session.artifacts, artifacts);
573
+ session.aliases = { ...session.aliases, ...aliases };
574
+ run.status = 'sealed';
575
+ run.revision++;
576
+ run.finished_at = new Date().toISOString();
577
+ run.verdict = verdict;
578
+ run.summary = requireText(summary, 'Run summary');
579
+ run.knowledge_reads = knowledge;
580
+ delete run.wiki_priors;
581
+ delete run.priors_reuse;
582
+ findStep(session, run.step_id).status = 'completed';
583
+ return { ...this.packet(session, run), artifact_publication: { artifacts, aliases }, knowledge_reads: knowledge };
584
+ });
585
+ }
586
+ transition(id, runId, status, reason, change) {
587
+ return this.mutate(id, 'run.transition', change, { runId, status, reason }, session => {
588
+ const run = findRun(session, runId);
589
+ changed(runId, change.runRevision, run.revision);
590
+ if ((run.status !== 'blocked' && run.status !== 'running') || run.status === status)
591
+ throw new InputError('Invalid Run transition');
592
+ run.status = status;
593
+ run.revision++;
594
+ run.summary = requireText(reason, 'transition reason');
595
+ if (status === 'failed' || status === 'cancelled') {
596
+ run.finished_at = new Date().toISOString();
597
+ findStep(session, run.step_id).status = 'pending';
598
+ }
599
+ return this.packet(session, run);
600
+ });
601
+ }
602
+ decide(id, decisionId, verdict, summary, change, options) {
603
+ return this.mutate(id, 'run.decide', change, { decisionId, verdict, summary, ...options }, session => {
604
+ const step = activeDecision(session);
605
+ if (step?.decision_ref !== decisionId)
606
+ throw new InputError('Select the pending decision');
607
+ if (options?.confidence !== undefined && (options.confidence < 0 || options.confidence > 100 || !Number.isFinite(options.confidence))) {
608
+ throw new InputError('Confidence score must be between 0 and 100');
609
+ }
610
+ if (session.policy?.auto_mode && verdict === 'proceed' && options?.confidence !== undefined && options.confidence < 60 && !change.evidence?.length) {
611
+ throw new InputError('Confidence below 60 requires explicit evidence or escalation');
612
+ }
613
+ if (verdict === 'fix' && step.command && /^ew-odyssey-(security|defensive)$/.test(workflowName(step.command))) {
614
+ throw new InputError('Route read-only audit findings to a separate remediation step');
615
+ }
616
+ step.decision = verdict;
617
+ if (options?.confidence !== undefined)
618
+ step.confidence = options.confidence;
619
+ if (verdict === 'proceed' && isDecisionOnlyStep(step)) {
620
+ step.status = 'completed';
621
+ }
622
+ else if (verdict === 'escalate' && isDecisionOnlyStep(step)) {
623
+ step.status = 'completed';
624
+ }
625
+ else if (verdict === 'fix') {
626
+ const decisionIdx = session.steps.indexOf(step);
627
+ if (options?.targetStepId) {
628
+ const targetIdx = session.steps.findIndex(item => item.id === options.targetStepId);
629
+ if (targetIdx < 0 || targetIdx > decisionIdx || isDecisionOnlyStep(session.steps[targetIdx])) {
630
+ throw new InputError('Select a prior executable step to reopen for fixes: ' + options.targetStepId);
631
+ }
632
+ for (let i = targetIdx; i <= decisionIdx; i++) {
633
+ session.steps[i].status = 'pending';
634
+ delete session.steps[i].decision;
635
+ }
636
+ }
637
+ else {
638
+ if (isDecisionOnlyStep(step)) {
639
+ throw new InputError('Specify --target-step <step-id> when returning fix from a decision-only step');
640
+ }
641
+ step.status = 'pending';
642
+ delete step.decision;
643
+ }
644
+ }
645
+ return { decision_ref: decisionId, verdict, summary, ...(options?.confidence !== undefined ? { confidence: options.confidence } : {}) };
646
+ });
647
+ }
648
+ completeSession(id, change) {
649
+ return this.mutate(id, 'session.complete', change, {}, session => {
650
+ if (!session.steps.length || nextAction(session).action !== 'complete')
651
+ throw new InputError('Resolve pending workflow steps and decisions');
652
+ session.status = 'completed';
653
+ session.completed_at = new Date().toISOString();
654
+ const completion = evolveSessionReceipt({ ...session, revision: session.revision + 1 });
655
+ return { status: session.status, completed_at: session.completed_at, completion_id: completion.id };
656
+ });
657
+ }
658
+ team(id, runId, action, assignment, change) {
659
+ return this.mutate(id, 'team.' + action, change, { runId, assignment }, session => {
660
+ const run = findRun(session, runId);
661
+ if (run.skill.skill_id !== 'team-swarm' || run.status !== 'running')
662
+ throw new InputError('Select a running Swarm Run');
663
+ if (action !== 'report' && run.owner !== change.actor)
664
+ throw new InputError('Use the Swarm coordinator identity');
665
+ const taskId = workflowId(assignment.id, 'assignment ID');
666
+ const roster = run.assignments ??= {};
667
+ if (action === 'assign') {
668
+ if (Object.hasOwn(roster, taskId))
669
+ throw new InputError('Assignment already exists: ' + taskId);
670
+ workflowPath(assignment.path, '.json');
671
+ if (!assignment.path.startsWith('outputs/') && !assignment.path.startsWith('work/team/scores/')) {
672
+ throw new InputError('Assignment output belongs under outputs/ or work/team/scores/');
673
+ }
674
+ if (Object.values(roster).some(item => item.path === assignment.path && !item.cancellation))
675
+ throw new InputError('Another assignment owns this output');
676
+ roster[taskId] = assignment;
677
+ }
678
+ else {
679
+ const task = roster[taskId];
680
+ if (!Object.hasOwn(roster, taskId) || task.result || task.cancellation)
681
+ throw new InputError('Select an outstanding assignment');
682
+ if (action === 'cancel') {
683
+ task.cancellation = requireText(change.reason, 'assignment cancellation reason');
684
+ }
685
+ else {
686
+ if (task.role !== change.actor)
687
+ throw new InputError('Use the assigned worker identity');
688
+ const bytes = safeFile(this.runDir(id, runId), task.path);
689
+ if (!bytes)
690
+ throw new InputError('Assignment artifact is required: ' + task.path);
691
+ JSON.parse(bytes.toString('utf8'));
692
+ task.result = { summary: requireText(assignment.result?.summary, 'assignment summary'), sha256: workflowHash(bytes) };
693
+ }
694
+ }
695
+ return { run_id: run.id, assignment: roster[taskId] };
696
+ });
697
+ }
698
+ teamList(id, runId) {
699
+ return Object.values(findRun(this.status(id), runId).assignments ?? {});
700
+ }
701
+ swarmController(id, runId) {
702
+ const run = this.brief(id, runId);
703
+ if (run.skill_ref.skill_id !== 'team-swarm' || run.status !== 'running')
704
+ throw new InputError('Select a running Swarm Run');
705
+ const work = join(run.run_dir, 'work');
706
+ const target = join(work, 'controller');
707
+ mkdirSync(target, { recursive: true });
708
+ for (const source of ['scripts/aco.py', 'scripts/pheromone.py', 'scripts/scoring.py', 'specs/swarm-config-template.json']) {
709
+ const bytes = workflowBlob(this.root, run.skill_ref.commit, run.skill_ref.package_path + '/' + source);
710
+ const name = source.split('/').at(-1);
711
+ const existing = safeFile(run.run_dir, 'work/controller/' + name);
712
+ if (existing && !existing.equals(bytes))
713
+ throw new InputError('Controller file changed: ' + name);
714
+ if (!existing)
715
+ writeFileSync(join(target, name), bytes, { flag: 'wx' });
716
+ }
717
+ return { controller_dir: target, script: join(target, 'aco.py'), config_template: join(target, 'swarm-config-template.json') };
718
+ }
719
+ recordKnowledge(id, runId, update) {
720
+ return transaction(this.db, () => {
721
+ const session = this.status(id);
722
+ const run = findRun(session, runId);
723
+ if (run.status !== 'running')
724
+ throw new InputError('Select a running Run for knowledge reads');
725
+ const trace = new KnowledgeReads(run.knowledge_reads);
726
+ update(trace, prior => {
727
+ const hash = contentSha256(prior.content);
728
+ const snapshots = (run.wiki_priors ??= []);
729
+ const existing = snapshots.find(item => item.id === prior.id);
730
+ if (existing && (existing.content_sha256 !== hash || JSON.stringify([existing.mode, existing.scope, existing.categories, existing.repositories]) !==
731
+ JSON.stringify([prior.mode, prior.scope, prior.categories, prior.repositories]))) {
732
+ throw new InputError('Wiki evidence changed during this Run: ' + prior.id);
733
+ }
734
+ if (!snapshots.some(item => item.id === prior.id && JSON.stringify(item.lookup_scope) === JSON.stringify(prior.lookup_scope))) {
735
+ snapshots.push({ ...prior, content_sha256: hash });
736
+ }
737
+ });
738
+ if (run.wiki_priors && Buffer.byteLength(JSON.stringify(run.wiki_priors)) > maxArtifactBytes) {
739
+ throw new InputError('Wiki snapshot exceeds the Run artifact size limit');
740
+ }
741
+ run.knowledge_reads = trace.toJSON();
742
+ const { continuation: _continuation, orchestration_revision: _revision, ...saved } = session;
743
+ this.save(saved);
744
+ return run.knowledge_reads;
745
+ });
746
+ }
747
+ }