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,72 @@
1
+ export declare const KNOWLEDGE_READS_VERSION = "knowledge-reads/1.0";
2
+ export type KnowledgeSearchSource = 'code' | 'wiki' | 'wiki_references' | 'memory' | 'context';
3
+ export type KnowledgeReadKind = 'code' | 'wiki' | 'memory';
4
+ export interface KnowledgeSearchRecord {
5
+ search_id: string;
6
+ source: KnowledgeSearchSource;
7
+ query: string;
8
+ filters?: Record<string, unknown>;
9
+ returned_ids: string[];
10
+ total_hits: number;
11
+ }
12
+ export interface KnowledgeReadRecord {
13
+ kind: KnowledgeReadKind;
14
+ id: string;
15
+ from_search_id?: string;
16
+ content_sha256?: string;
17
+ version?: number;
18
+ }
19
+ export interface KnowledgeConstraintRecord {
20
+ knowledge_id: string;
21
+ content_sha256?: string;
22
+ scope: string[];
23
+ categories?: string[];
24
+ }
25
+ export interface KnowledgePriorReuse {
26
+ artifact_id: string;
27
+ producer_run_id: string;
28
+ content_sha256: string;
29
+ }
30
+ export interface KnowledgeReadsReceipt {
31
+ schema_version: typeof KNOWLEDGE_READS_VERSION;
32
+ searches: KnowledgeSearchRecord[];
33
+ reads: KnowledgeReadRecord[];
34
+ constraints_bound: KnowledgeConstraintRecord[];
35
+ priors_reuse?: KnowledgePriorReuse[];
36
+ }
37
+ export interface KnowledgeSearchInput {
38
+ source: KnowledgeSearchSource;
39
+ query: string;
40
+ filters?: Record<string, unknown>;
41
+ returnedIds: string[];
42
+ }
43
+ export interface KnowledgeReadInput {
44
+ kind: KnowledgeReadKind;
45
+ id: string;
46
+ fromSearchId?: string;
47
+ content?: string;
48
+ contentSha256?: string;
49
+ version?: number;
50
+ }
51
+ export interface KnowledgeConstraintInput {
52
+ knowledgeId: string;
53
+ scope: string[];
54
+ categories?: string[];
55
+ content?: string;
56
+ contentSha256?: string;
57
+ }
58
+ export declare function contentSha256(content: string): string;
59
+ export declare function validateKnowledgeReads(value: unknown): KnowledgeReadsReceipt;
60
+ export declare class KnowledgeReads {
61
+ private sequence;
62
+ private readonly searches;
63
+ private readonly reads;
64
+ private readonly constraints;
65
+ private readonly priorReuse?;
66
+ constructor(initial?: KnowledgeReadsReceipt);
67
+ recordSearch(input: KnowledgeSearchInput): string;
68
+ recordRead(input: KnowledgeReadInput): void;
69
+ bindConstraint(input: KnowledgeConstraintInput): void;
70
+ toJSON(): KnowledgeReadsReceipt;
71
+ }
72
+ export declare function formatKnowledgeReadsMessage(receipt: KnowledgeReadsReceipt): string;
@@ -0,0 +1,201 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { InputError, requireText } from './common.js';
3
+ export const KNOWLEDGE_READS_VERSION = 'knowledge-reads/1.0';
4
+ export function contentSha256(content) {
5
+ return `sha256:${createHash('sha256').update(content).digest('hex')}`;
6
+ }
7
+ function stringList(value, field) {
8
+ if (!Array.isArray(value) || value.some(item => typeof item !== 'string' || !item.trim())) {
9
+ throw new InputError(`Invalid knowledge read ${field}`);
10
+ }
11
+ return [...new Set(value.map(item => item.trim()))];
12
+ }
13
+ function optionalSha(value, field) {
14
+ if (value === undefined)
15
+ return undefined;
16
+ if (typeof value !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(value)) {
17
+ throw new InputError(`Invalid knowledge read ${field}`);
18
+ }
19
+ return value;
20
+ }
21
+ function record(value, field) {
22
+ if (!value || typeof value !== 'object' || Array.isArray(value))
23
+ throw new InputError(`Invalid knowledge read ${field}`);
24
+ return value;
25
+ }
26
+ function source(value, field) {
27
+ if (value !== 'code' && value !== 'wiki' && value !== 'wiki_references' && value !== 'memory' && value !== 'context') {
28
+ throw new InputError(`Invalid knowledge read ${field}`);
29
+ }
30
+ return value;
31
+ }
32
+ function kind(value, field) {
33
+ if (value !== 'code' && value !== 'wiki' && value !== 'memory')
34
+ throw new InputError(`Invalid knowledge read ${field}`);
35
+ return value;
36
+ }
37
+ function parseSearch(value, index) {
38
+ const item = record(value, `search ${index}`);
39
+ const total = item.total_hits;
40
+ if (!Number.isSafeInteger(total) || total < 0)
41
+ throw new InputError(`Invalid knowledge read search total ${index}`);
42
+ return {
43
+ search_id: requireText(item.search_id, `knowledge search ID ${index}`),
44
+ source: source(item.source, `search source ${index}`),
45
+ query: requireText(item.query, `knowledge search query ${index}`),
46
+ ...(item.filters === undefined ? {} : { filters: record(item.filters, `search filters ${index}`) }),
47
+ returned_ids: stringList(item.returned_ids, `search returned IDs ${index}`),
48
+ total_hits: total,
49
+ };
50
+ }
51
+ function parseRead(value, index) {
52
+ const item = record(value, `read ${index}`);
53
+ const version = item.version;
54
+ if (version !== undefined && (!Number.isSafeInteger(version) || version < 1)) {
55
+ throw new InputError(`Invalid knowledge read version ${index}`);
56
+ }
57
+ return {
58
+ kind: kind(item.kind, `read kind ${index}`),
59
+ id: requireText(item.id, `knowledge read ID ${index}`),
60
+ ...(item.from_search_id === undefined ? {} : { from_search_id: requireText(item.from_search_id, `knowledge read source ${index}`) }),
61
+ ...(item.content_sha256 === undefined ? {} : { content_sha256: optionalSha(item.content_sha256, `content hash ${index}`) }),
62
+ ...(version === undefined ? {} : { version: version }),
63
+ };
64
+ }
65
+ function parseConstraint(value, index) {
66
+ const item = record(value, `constraint ${index}`);
67
+ return {
68
+ knowledge_id: requireText(item.knowledge_id, `constraint ID ${index}`),
69
+ ...(item.content_sha256 === undefined ? {} : { content_sha256: optionalSha(item.content_sha256, `constraint hash ${index}`) }),
70
+ scope: stringList(item.scope, `constraint scope ${index}`),
71
+ ...(item.categories === undefined ? {} : { categories: stringList(item.categories, `constraint categories ${index}`) }),
72
+ };
73
+ }
74
+ function parsePriorReuse(value) {
75
+ const item = record(value, 'priors reuse');
76
+ const hash = optionalSha(item.content_sha256, 'priors content hash');
77
+ if (!hash)
78
+ throw new InputError('Missing priors content hash');
79
+ return {
80
+ artifact_id: requireText(item.artifact_id, 'priors artifact ID'),
81
+ producer_run_id: requireText(item.producer_run_id, 'priors producer Run ID'),
82
+ content_sha256: hash,
83
+ };
84
+ }
85
+ export function validateKnowledgeReads(value) {
86
+ const input = record(value, 'receipt');
87
+ if (input.schema_version !== KNOWLEDGE_READS_VERSION || !Array.isArray(input.searches) ||
88
+ !Array.isArray(input.reads) || !Array.isArray(input.constraints_bound)) {
89
+ throw new InputError('Invalid knowledge reads receipt');
90
+ }
91
+ const searches = input.searches.map(parseSearch);
92
+ const searchIds = new Set(searches.map(item => item.search_id));
93
+ if (searchIds.size !== searches.length)
94
+ throw new InputError('Duplicate knowledge search ID');
95
+ const reads = input.reads.map(parseRead);
96
+ for (const item of reads) {
97
+ if (item.from_search_id && !searchIds.has(item.from_search_id) && item.from_search_id !== 'priors') {
98
+ throw new InputError(`Unknown knowledge search ID: ${item.from_search_id}`);
99
+ }
100
+ }
101
+ if (input.priors_reuse !== undefined && !Array.isArray(input.priors_reuse))
102
+ throw new InputError('Invalid priors reuse receipt');
103
+ return {
104
+ schema_version: KNOWLEDGE_READS_VERSION,
105
+ searches,
106
+ reads,
107
+ constraints_bound: input.constraints_bound.map(parseConstraint),
108
+ ...(input.priors_reuse === undefined ? {} : { priors_reuse: input.priors_reuse.map(parsePriorReuse) }),
109
+ };
110
+ }
111
+ export class KnowledgeReads {
112
+ sequence = 0;
113
+ searches = [];
114
+ reads = [];
115
+ constraints = [];
116
+ priorReuse;
117
+ constructor(initial) {
118
+ if (!initial)
119
+ return;
120
+ const receipt = validateKnowledgeReads(initial);
121
+ this.searches.push(...receipt.searches);
122
+ this.reads.push(...receipt.reads);
123
+ this.constraints.push(...receipt.constraints_bound);
124
+ this.priorReuse = receipt.priors_reuse;
125
+ for (const search of this.searches) {
126
+ const match = /^search-(\d+)$/.exec(search.search_id);
127
+ if (match)
128
+ this.sequence = Math.max(this.sequence, Number(match[1]));
129
+ }
130
+ }
131
+ recordSearch(input) {
132
+ let searchId;
133
+ do {
134
+ searchId = `search-${++this.sequence}`;
135
+ } while (this.searches.some(search => search.search_id === searchId));
136
+ const query = requireText(input.query, 'knowledge search query');
137
+ const returnedIds = stringList(input.returnedIds, 'knowledge search returned IDs');
138
+ this.searches.push({
139
+ search_id: searchId,
140
+ source: input.source,
141
+ query,
142
+ ...(input.filters ? { filters: { ...input.filters } } : {}),
143
+ returned_ids: returnedIds,
144
+ total_hits: returnedIds.length,
145
+ });
146
+ return searchId;
147
+ }
148
+ recordRead(input) {
149
+ const id = requireText(input.id, 'knowledge read ID');
150
+ const fromSearchId = input.fromSearchId === undefined ? undefined : requireText(input.fromSearchId, 'knowledge read search ID');
151
+ if (fromSearchId && fromSearchId !== 'priors' && !this.searches.some(search => search.search_id === fromSearchId)) {
152
+ throw new InputError(`Unknown knowledge search ID: ${fromSearchId}`);
153
+ }
154
+ const contentHash = input.contentSha256 ?? (input.content === undefined ? undefined : contentSha256(input.content));
155
+ if (contentHash !== undefined)
156
+ optionalSha(contentHash, 'content hash');
157
+ if (input.version !== undefined && (!Number.isSafeInteger(input.version) || input.version < 1)) {
158
+ throw new InputError('Knowledge read version must be a positive integer');
159
+ }
160
+ if (this.reads.some(read => read.kind === input.kind && read.id === id && read.from_search_id === fromSearchId))
161
+ return;
162
+ this.reads.push({
163
+ kind: input.kind,
164
+ id,
165
+ ...(fromSearchId ? { from_search_id: fromSearchId } : {}),
166
+ ...(contentHash ? { content_sha256: contentHash } : {}),
167
+ ...(input.version === undefined ? {} : { version: input.version }),
168
+ });
169
+ }
170
+ bindConstraint(input) {
171
+ const id = requireText(input.knowledgeId, 'knowledge constraint ID');
172
+ const hash = input.contentSha256 ?? (input.content === undefined ? undefined : contentSha256(input.content));
173
+ if (hash !== undefined)
174
+ optionalSha(hash, 'constraint hash');
175
+ if (this.constraints.some(item => item.knowledge_id === id))
176
+ return;
177
+ this.constraints.push({
178
+ knowledge_id: id,
179
+ ...(hash ? { content_sha256: hash } : {}),
180
+ scope: stringList(input.scope, 'knowledge constraint scope'),
181
+ ...(input.categories ? { categories: stringList(input.categories, 'knowledge constraint categories') } : {}),
182
+ });
183
+ }
184
+ toJSON() {
185
+ return validateKnowledgeReads({
186
+ schema_version: KNOWLEDGE_READS_VERSION,
187
+ searches: this.searches,
188
+ reads: this.reads,
189
+ constraints_bound: this.constraints,
190
+ ...(this.priorReuse ? { priors_reuse: this.priorReuse } : {}),
191
+ });
192
+ }
193
+ }
194
+ export function formatKnowledgeReadsMessage(receipt) {
195
+ const searches = receipt.searches.map(search => `${search.search_id} ${search.source} "${search.query}" (${search.total_hits} hits: ${search.returned_ids.join(', ') || 'none'})`).join('; ');
196
+ const reads = receipt.reads.map(read => `${read.kind}:${read.id}${read.from_search_id ? ` from ${read.from_search_id}` : ''}`).join(', ') || 'none';
197
+ const constraints = receipt.constraints_bound.map(item => item.knowledge_id).join(', ') || 'none';
198
+ const reuse = receipt.priors_reuse?.map(item => `${item.artifact_id} from ${item.producer_run_id} (${item.content_sha256})`).join(', ');
199
+ return `Knowledge searches: ${searches || 'none'}. Knowledge reads: ${reads}. Bound constraints: ${constraints}.` +
200
+ (reuse ? ` Reused session priors: ${reuse}.` : '');
201
+ }
@@ -0,0 +1,44 @@
1
+ declare const hosts: {
2
+ readonly codex: {
3
+ readonly label: "Codex";
4
+ readonly file: readonly [".codex", "hooks.json"];
5
+ };
6
+ readonly claude: {
7
+ readonly label: "Claude Code";
8
+ readonly file: readonly [".claude", "settings.local.json"];
9
+ };
10
+ readonly agy: {
11
+ readonly label: "Antigravity CLI";
12
+ readonly file: readonly [".agents", "hooks.json"];
13
+ };
14
+ };
15
+ export type MemoryHost = keyof typeof hosts;
16
+ export declare const memoryHosts: MemoryHost[];
17
+ export declare function installCodexMemoryHook(root: string): {
18
+ path: string;
19
+ changed: boolean;
20
+ };
21
+ export declare function memoryModelSettings(root: string): {
22
+ baseUrl: string | undefined;
23
+ model: string | undefined;
24
+ };
25
+ export declare function parseMemoryHosts(value: string, allowNone?: boolean): MemoryHost[];
26
+ interface ConfigOptions {
27
+ host?: string;
28
+ baseUrl?: string;
29
+ model?: string;
30
+ yes?: boolean;
31
+ }
32
+ export declare function configureMemory(root: string, options: ConfigOptions): Promise<{
33
+ status: string;
34
+ } | {
35
+ codex?: string | undefined;
36
+ status: string;
37
+ hosts: {
38
+ host: "codex" | "claude" | "agy";
39
+ configured: boolean;
40
+ path: string;
41
+ }[];
42
+ model_configured: boolean;
43
+ }>;
44
+ export {};
@@ -0,0 +1,204 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { createInterface } from 'node:readline/promises';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { InputError } from './common.js';
7
+ const hosts = {
8
+ codex: { label: 'Codex', file: ['.codex', 'hooks.json'] },
9
+ claude: { label: 'Claude Code', file: ['.claude', 'settings.local.json'] },
10
+ agy: { label: 'Antigravity CLI', file: ['.agents', 'hooks.json'] },
11
+ };
12
+ export const memoryHosts = Object.keys(hosts);
13
+ const agyHookName = 'evolve-agent-memory';
14
+ const codexStatus = 'Extracting Agent Memory from Codex';
15
+ function object(value) {
16
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
17
+ }
18
+ function readJson(path) {
19
+ const previous = existsSync(path) ? readFileSync(path, 'utf8') : undefined;
20
+ if (previous === undefined)
21
+ return { path, content: {} };
22
+ let content;
23
+ try {
24
+ content = object(JSON.parse(previous.replace(/^\uFEFF/, '')));
25
+ }
26
+ catch {
27
+ throw new InputError(`Invalid JSON in ${path}`);
28
+ }
29
+ if (!content)
30
+ throw new InputError(`Expected a JSON object in ${path}`);
31
+ return { path, previous, content };
32
+ }
33
+ function replaceJson({ path, previous, content }) {
34
+ const result = JSON.stringify(content, null, 2) + '\n';
35
+ mkdirSync(dirname(path), { recursive: true });
36
+ const temporary = join(dirname(path), `.${randomUUID()}.tmp`);
37
+ try {
38
+ writeFileSync(temporary, result, { flag: 'wx' });
39
+ if ((existsSync(path) ? readFileSync(path, 'utf8') : undefined) !== previous) {
40
+ throw new InputError(`Configuration changed while saving ${path}`);
41
+ }
42
+ renameSync(temporary, path);
43
+ }
44
+ finally {
45
+ rmSync(temporary, { force: true });
46
+ }
47
+ }
48
+ function quoteCommand(args) {
49
+ if (process.platform === 'win32') {
50
+ return '& ' + args.map(arg => `'${arg.replaceAll("'", "''")}'`).join(' ');
51
+ }
52
+ return args.map(arg => `'${arg.replaceAll("'", "'\\''")}'`).join(' ');
53
+ }
54
+ const agyWindowsHook = ' memory host-hook --host agy';
55
+ function agyWindowsCommand(entry, root) {
56
+ // Agy 在 Windows 启动 Hook 时直接保留 Node 的标准输入,路径以 base64url 跨过宿主命令解析。
57
+ const script = "const entry = Buffer.from(process.argv[1], 'base64url').toString(); " +
58
+ "const root = Buffer.from(process.argv[2], 'base64url').toString(); " +
59
+ "process.argv.splice(1, 2, entry); process.argv.push('--root', root); import(require('node:url').pathToFileURL(entry));";
60
+ return `node --input-type=commonjs -e "${script}" ${Buffer.from(entry).toString('base64url')} ${Buffer.from(root).toString('base64url')}${agyWindowsHook}`;
61
+ }
62
+ function memoryHandler(host, root) {
63
+ const args = host === 'codex' ? ['codex-hook'] : ['host-hook', '--host', host];
64
+ const entry = fileURLToPath(new URL('./cli.js', import.meta.url));
65
+ const command = host === 'agy' && process.platform === 'win32' ? agyWindowsCommand(entry, root)
66
+ : quoteCommand([process.execPath, entry, 'memory', ...args, '--root', root]);
67
+ return { type: 'command', command, timeout: 150,
68
+ ...(host === 'codex' ? { statusMessage: codexStatus } : {}),
69
+ ...(host === 'claude' && process.platform === 'win32' ? { shell: 'powershell' } : {}),
70
+ };
71
+ }
72
+ function ownsHandler(host, value) {
73
+ const hook = object(value);
74
+ if (typeof hook?.command !== 'string')
75
+ return false;
76
+ if (host === 'codex')
77
+ return hook.statusMessage === codexStatus && hook.command.includes('codex-hook');
78
+ if (host === 'agy' && hook.command.startsWith('node --input-type=commonjs -e ') && hook.command.endsWith(agyWindowsHook))
79
+ return true;
80
+ return hook.command.includes(`'memory' 'host-hook' '--host' '${host}' '--root'`);
81
+ }
82
+ function hookFile(root, host) {
83
+ const file = readJson(join(root, ...hosts[host].file));
84
+ if (host === 'agy') {
85
+ const own = object(file.content[agyHookName]);
86
+ if (file.content[agyHookName] !== undefined &&
87
+ (!Array.isArray(own?.Stop) || own.Stop.length !== 1 || !ownsHandler(host, own.Stop[0]))) {
88
+ throw new InputError(`Conflicting hook ${agyHookName} in ${file.path}`);
89
+ }
90
+ return { file, configured: !!own && own.enabled !== false, update(enable) {
91
+ if (!enable && !own)
92
+ return;
93
+ const { [agyHookName]: previousHook, ...other } = file.content;
94
+ const next = enable ? { ...own, enabled: true, Stop: [memoryHandler(host, root)] } : undefined;
95
+ if (JSON.stringify(next) === JSON.stringify(previousHook))
96
+ return;
97
+ return { ...file, content: next ? { ...other, [agyHookName]: next } : other };
98
+ } };
99
+ }
100
+ const hooks = file.content.hooks === undefined ? {} : object(file.content.hooks);
101
+ const stop = hooks?.Stop ?? [];
102
+ if (!hooks || !Array.isArray(stop))
103
+ throw new InputError(`Invalid Stop hooks in ${file.path}`);
104
+ const own = stop.flatMap(group => Array.isArray(group?.hooks) ? group.hooks.filter((hook) => ownsHandler(host, hook)) : []);
105
+ return { file, configured: own.length > 0, update(enable) {
106
+ if (!enable && !own.length)
107
+ return;
108
+ const entry = memoryHandler(host, root);
109
+ if (enable && own.length === 1 && JSON.stringify(own[0]) === JSON.stringify(entry))
110
+ return;
111
+ const otherGroups = stop.flatMap(group => {
112
+ if (!Array.isArray(group?.hooks) || !group.hooks.some((hook) => ownsHandler(host, hook)))
113
+ return [group];
114
+ const remaining = group.hooks.filter((hook) => !ownsHandler(host, hook));
115
+ return remaining.length ? [{ ...group, hooks: remaining }] : [];
116
+ });
117
+ const content = { ...file.content, hooks: { ...hooks, Stop: enable ? [...otherGroups, { hooks: [entry] }] : otherGroups } };
118
+ return { ...file, content };
119
+ } };
120
+ }
121
+ export function installCodexMemoryHook(root) {
122
+ const hook = hookFile(root, 'codex');
123
+ const updated = hook.update(true);
124
+ if (updated)
125
+ replaceJson(updated);
126
+ return { path: hook.file.path, changed: !!updated };
127
+ }
128
+ function settingsFile(root) {
129
+ return readJson(join(root, '.agent-memory', 'config.json'));
130
+ }
131
+ function setting(file, field) {
132
+ const value = file.content[field];
133
+ if (value !== undefined && typeof value !== 'string')
134
+ throw new InputError(`Invalid ${field} in ${file.path}`);
135
+ return value;
136
+ }
137
+ export function memoryModelSettings(root) {
138
+ const { AGENT_MEMORY_LLM_BASE_URL: baseUrl, AGENT_MEMORY_LLM_MODEL: model } = process.env;
139
+ if (baseUrl && model)
140
+ return { baseUrl, model };
141
+ const file = settingsFile(root);
142
+ return {
143
+ baseUrl: baseUrl || setting(file, 'baseUrl'),
144
+ model: model || setting(file, 'model'),
145
+ };
146
+ }
147
+ export function parseMemoryHosts(value, allowNone = false) {
148
+ if (value.toLowerCase() === 'all')
149
+ return memoryHosts;
150
+ if (allowNone && value.toLowerCase() === 'off')
151
+ return [];
152
+ const selected = value.toLowerCase().split(',').map(item => item.trim());
153
+ if (selected.some(host => !memoryHosts.includes(host))) {
154
+ throw new InputError(`Choose ${memoryHosts.join(', ')} or all${allowNone ? ' or off' : ''}`);
155
+ }
156
+ return memoryHosts.filter(host => selected.includes(host));
157
+ }
158
+ export async function configureMemory(root, options) {
159
+ const file = settingsFile(root);
160
+ const hooks = memoryHosts.map(host => ({ host, ...hookFile(root, host) }));
161
+ const currentHosts = hooks.filter(hook => hook.configured).map(hook => hook.host);
162
+ let selected = options.host;
163
+ let baseUrl = options.baseUrl ?? setting(file, 'baseUrl');
164
+ let model = options.model ?? setting(file, 'model');
165
+ if (!options.yes) {
166
+ if (!process.stdin.isTTY || !process.stdout.isTTY)
167
+ throw new InputError('Use an interactive terminal or pass --yes');
168
+ const ui = createInterface({ input: process.stdin, output: process.stdout });
169
+ try {
170
+ process.stdout.write(`\nAgent Memory\n${root}\n\nAutomatic extraction\n`);
171
+ for (const { host, configured } of hooks) {
172
+ process.stdout.write(` ${configured ? '[x]' : '[ ]'} ${host.padEnd(7)} ${hosts[host].label}\n`);
173
+ }
174
+ selected ??= (await ui.question('Host names, all, or off [keep current]: ')).trim() || undefined;
175
+ if (selected !== undefined)
176
+ parseMemoryHosts(selected, true);
177
+ process.stdout.write('\nExtraction model (AGENT_MEMORY_LLM_* environment variables take precedence)\n');
178
+ baseUrl = (await ui.question(`Base URL${baseUrl ? ` [${baseUrl}]` : ' [environment]'}: `)).trim() || baseUrl;
179
+ model = (await ui.question(`Model${model ? ` [${model}]` : ' [environment]'}: `)).trim() || model;
180
+ if (!/^y(?:es)?$/i.test((await ui.question('Save project settings? [y/N] ')).trim()))
181
+ return { status: 'cancelled' };
182
+ }
183
+ finally {
184
+ ui.close();
185
+ }
186
+ }
187
+ if (baseUrl !== undefined) {
188
+ if (!URL.canParse(baseUrl) || !['http:', 'https:'].includes(new URL(baseUrl).protocol)) {
189
+ throw new InputError('Base URL must start with http:// or https://');
190
+ }
191
+ }
192
+ const enabled = selected === undefined ? currentHosts : parseMemoryHosts(selected, true);
193
+ const updates = hooks.map(hook => hook.update(enabled.includes(hook.host)));
194
+ const content = { ...file.content, ...(baseUrl === undefined ? {} : { baseUrl }), ...(model === undefined ? {} : { model }) };
195
+ if (JSON.stringify(content) !== JSON.stringify(file.content))
196
+ replaceJson({ ...file, content });
197
+ for (const update of updates)
198
+ if (update)
199
+ replaceJson(update);
200
+ return { status: 'configured', hosts: hooks.map(({ host, file }) => ({ host, configured: enabled.includes(host), path: file.path })),
201
+ model_configured: !!(process.env.AGENT_MEMORY_LLM_MODEL || model) && !!(process.env.AGENT_MEMORY_LLM_BASE_URL || baseUrl),
202
+ ...(enabled.includes('codex') ? { codex: 'Review and trust the hook in Codex with /hooks.' } : {}),
203
+ };
204
+ }
@@ -0,0 +1,13 @@
1
+ import type { ConversationMessage, MemoryInput } from './memory.js';
2
+ export interface MemorySource extends ConversationMessage {
3
+ session: string;
4
+ }
5
+ export interface GroundedMemory extends MemoryInput {
6
+ evidence: {
7
+ messages: ConversationMessage[];
8
+ scope: 'messages' | 'turn';
9
+ };
10
+ }
11
+ export declare function extractedMemoryId(session: string | undefined, type: string | undefined, content: string, sourceMessageIds: string[]): string;
12
+ export declare function exactMemoryValues(text: string): string[];
13
+ export declare function groundMemories(inputs: MemoryInput[], messages: ConversationMessage[]): GroundedMemory[];
@@ -0,0 +1,40 @@
1
+ import { createHash } from 'node:crypto';
2
+ export function extractedMemoryId(session, type, content, sourceMessageIds) {
3
+ return createHash('sha256').update(JSON.stringify([session, type, content, sourceMessageIds])).digest('hex');
4
+ }
5
+ // 保留大小写、前导零、符号和连接符,避免把两个不同的机器标识归并成同一个词。
6
+ export function exactMemoryValues(text) {
7
+ const values = new Set();
8
+ for (const { 0: token } of text.matchAll(/[+-]?[A-Za-z0-9]+(?:[._:/+-][A-Za-z0-9]+|,\d{3}(?!\d))*%?/g)) {
9
+ if (/\d/.test(token) || /^[a-f]{7,}$/i.test(token) || token.length >= 20 ||
10
+ (token.length >= 12 && /[_:/.-]/.test(token)))
11
+ values.add(token);
12
+ }
13
+ return [...values];
14
+ }
15
+ export function groundMemories(inputs, messages) {
16
+ const byId = new Map(messages.map(message => [message.id, message]));
17
+ const users = messages.filter(message => message.role === 'user');
18
+ const userValues = users.filter(message => exactMemoryValues(message.content).length);
19
+ const grounded = new Map();
20
+ for (const input of inputs) {
21
+ const cited = (input.sourceMessageIds ?? []).flatMap(id => {
22
+ const message = byId.get(id);
23
+ return message ? [message] : [];
24
+ });
25
+ // 有原始用户标识的消息也需保留,哪怕模型只引用了没有复述标识的助手回复。
26
+ const sources = cited.length ? [...new Set([...cited, ...userValues])] : userValues.length ? users : messages;
27
+ const exact = new Set(sources.flatMap(message => exactMemoryValues(message.content)));
28
+ const unverified = exactMemoryValues(input.content).some(value => !exact.has(value));
29
+ const quotes = sources.filter(message => message.role === 'user');
30
+ const content = unverified ? (quotes.length ? quotes : sources).map(message => message.content).join('\n\n') : input.content;
31
+ const sourceMessageIds = sources.map(message => message.id).sort();
32
+ // 相同摘要来自不同回合时独立入库,防止新的来源覆盖旧标识。
33
+ const id = extractedMemoryId(input.session, input.type, content, sourceMessageIds);
34
+ if (!grounded.has(id))
35
+ grounded.set(id, { ...input, id, content, sourceMessageIds,
36
+ evidence: { messages: sources, scope: cited.length === sources.length ? 'messages' : 'turn' },
37
+ });
38
+ }
39
+ return [...grounded.values()];
40
+ }
@@ -0,0 +1,46 @@
1
+ import { type MemoryHost } from './memory-config.js';
2
+ import type { ConversationMessage, MemoryStore } from './memory.js';
3
+ import type { LlmClient } from './upstream/llm.js';
4
+ interface ImportOptions {
5
+ root: string;
6
+ memory: MemoryStore;
7
+ model: () => LlmClient;
8
+ }
9
+ export declare function handleMemoryHook(host: MemoryHost, input: unknown, options: ImportOptions): Promise<{
10
+ decision: string;
11
+ } | {
12
+ decision?: undefined;
13
+ }>;
14
+ interface ConversationOptions {
15
+ root: string;
16
+ memory: MemoryStore;
17
+ host?: MemoryHost;
18
+ page?: number;
19
+ limit?: number;
20
+ }
21
+ export declare function readMemoryConversation(target: string, options: ConversationOptions): Promise<{
22
+ pagination: {
23
+ page: number;
24
+ limit: number;
25
+ previousPage: number | null;
26
+ nextPage: number | null;
27
+ };
28
+ messages: ConversationMessage[];
29
+ anchor?: {
30
+ messageId: string;
31
+ page: number | null;
32
+ } | undefined;
33
+ memoryId?: string | undefined;
34
+ host: "codex" | "claude" | "agy";
35
+ session: string;
36
+ }>;
37
+ export declare function syncMemoryHost(host: MemoryHost, options: ImportOptions, session?: string): Promise<{
38
+ sessions: number;
39
+ processed: number;
40
+ remembered: number;
41
+ failures: {
42
+ path: string;
43
+ error: string;
44
+ }[];
45
+ }>;
46
+ export {};