@nextsparkjs/ai-workflow 0.1.0-beta.86

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 (271) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -0
  3. package/claude/_docs/workflows-optimizations.md +359 -0
  4. package/claude/agents/api-tester.md +636 -0
  5. package/claude/agents/architecture-supervisor.md +1381 -0
  6. package/claude/agents/backend-developer.md +1021 -0
  7. package/claude/agents/backend-validator.md +417 -0
  8. package/claude/agents/bdd-docs-writer.md +737 -0
  9. package/claude/agents/block-developer.md +677 -0
  10. package/claude/agents/code-reviewer.md +1460 -0
  11. package/claude/agents/db-developer.md +721 -0
  12. package/claude/agents/db-validator.md +407 -0
  13. package/claude/agents/demo-video-generator.md +493 -0
  14. package/claude/agents/documentation-writer.md +1291 -0
  15. package/claude/agents/frontend-developer.md +1259 -0
  16. package/claude/agents/frontend-validator.md +777 -0
  17. package/claude/agents/functional-validator.md +630 -0
  18. package/claude/agents/mock-analyst.md +387 -0
  19. package/claude/agents/product-manager.md +971 -0
  20. package/claude/agents/qa-automation.md +1762 -0
  21. package/claude/agents/release-manager.md +634 -0
  22. package/claude/agents/selectors-translator.md +262 -0
  23. package/claude/agents/unit-test-writer.md +785 -0
  24. package/claude/agents/visual-comparator.md +329 -0
  25. package/claude/agents/workflow-maintainer.md +373 -0
  26. package/claude/commands/do/README.md +88 -0
  27. package/claude/commands/do/create-api.md +64 -0
  28. package/claude/commands/do/create-entity.md +66 -0
  29. package/claude/commands/do/create-migration.md +64 -0
  30. package/claude/commands/do/create-plugin.md +56 -0
  31. package/claude/commands/do/create-theme.md +70 -0
  32. package/claude/commands/do/mock-data.md +67 -0
  33. package/claude/commands/do/reset-db.md +71 -0
  34. package/claude/commands/do/setup-scheduled-action.md +75 -0
  35. package/claude/commands/do/sync-code-review.md +117 -0
  36. package/claude/commands/do/update-selectors.md +112 -0
  37. package/claude/commands/do/use-skills.md +90 -0
  38. package/claude/commands/do/validate-blocks.md +69 -0
  39. package/claude/commands/how-to/README.md +261 -0
  40. package/claude/commands/how-to/add-metadata.md +692 -0
  41. package/claude/commands/how-to/add-taxonomies.md +806 -0
  42. package/claude/commands/how-to/add-translations.md +571 -0
  43. package/claude/commands/how-to/create-api.md +577 -0
  44. package/claude/commands/how-to/create-block.md +575 -0
  45. package/claude/commands/how-to/create-child-entities.md +771 -0
  46. package/claude/commands/how-to/create-entity.md +597 -0
  47. package/claude/commands/how-to/create-migrations.md +605 -0
  48. package/claude/commands/how-to/create-plugin.md +654 -0
  49. package/claude/commands/how-to/customize-app.md +481 -0
  50. package/claude/commands/how-to/customize-dashboard.md +553 -0
  51. package/claude/commands/how-to/customize-theme.md +438 -0
  52. package/claude/commands/how-to/define-features-flows.md +632 -0
  53. package/claude/commands/how-to/deploy.md +507 -0
  54. package/claude/commands/how-to/handle-file-uploads.md +681 -0
  55. package/claude/commands/how-to/implement-search.md +1001 -0
  56. package/claude/commands/how-to/install-plugins.md +352 -0
  57. package/claude/commands/how-to/manage-test-coverage.md +984 -0
  58. package/claude/commands/how-to/run-tests.md +400 -0
  59. package/claude/commands/how-to/set-app-languages.md +601 -0
  60. package/claude/commands/how-to/set-plans-and-permissions.md +575 -0
  61. package/claude/commands/how-to/set-scheduled-actions.md +527 -0
  62. package/claude/commands/how-to/set-user-roles-and-permissions.md +550 -0
  63. package/claude/commands/how-to/setup-authentication.md +388 -0
  64. package/claude/commands/how-to/setup-claude-code.md +512 -0
  65. package/claude/commands/how-to/setup-database.md +274 -0
  66. package/claude/commands/how-to/setup-email-providers.md +598 -0
  67. package/claude/commands/how-to/setup-mobile-dev.md +627 -0
  68. package/claude/commands/how-to/start.md +455 -0
  69. package/claude/commands/how-to/use-devtools.md +639 -0
  70. package/claude/commands/how-to/use-superadmin.md +622 -0
  71. package/claude/commands/session/README.md +193 -0
  72. package/claude/commands/session/block-create.md +190 -0
  73. package/claude/commands/session/block-list.md +203 -0
  74. package/claude/commands/session/block-update.md +192 -0
  75. package/claude/commands/session/block-validate.md +218 -0
  76. package/claude/commands/session/close.md +146 -0
  77. package/claude/commands/session/commit.md +174 -0
  78. package/claude/commands/session/db-entity.md +206 -0
  79. package/claude/commands/session/db-fix.md +212 -0
  80. package/claude/commands/session/db-sample.md +206 -0
  81. package/claude/commands/session/demo.md +178 -0
  82. package/claude/commands/session/doc-bdd.md +207 -0
  83. package/claude/commands/session/doc-feature.md +218 -0
  84. package/claude/commands/session/doc-read.md +225 -0
  85. package/claude/commands/session/execute.md +204 -0
  86. package/claude/commands/session/explain.md +202 -0
  87. package/claude/commands/session/fix-bug.md +210 -0
  88. package/claude/commands/session/fix-build.md +182 -0
  89. package/claude/commands/session/fix-test.md +189 -0
  90. package/claude/commands/session/pending.md +232 -0
  91. package/claude/commands/session/refine.md +188 -0
  92. package/claude/commands/session/resume.md +192 -0
  93. package/claude/commands/session/review.md +192 -0
  94. package/claude/commands/session/scope-change.md +181 -0
  95. package/claude/commands/session/start-blocks.md +347 -0
  96. package/claude/commands/session/start.md +476 -0
  97. package/claude/commands/session/status.md +169 -0
  98. package/claude/commands/session/test-fix.md +221 -0
  99. package/claude/commands/session/test-run.md +203 -0
  100. package/claude/commands/session/test-write.md +242 -0
  101. package/claude/commands/session/validate.md +162 -0
  102. package/claude/config/context.json +54 -0
  103. package/claude/config/github.json +69 -0
  104. package/claude/config/github.schema.json +106 -0
  105. package/claude/config/team.json +46 -0
  106. package/claude/config/team.schema.json +106 -0
  107. package/claude/config/workspace.json +49 -0
  108. package/claude/config/workspace.schema.json +64 -0
  109. package/claude/scripts/.gitkeep +0 -0
  110. package/claude/sessions/.gitkeep +0 -0
  111. package/claude/skills/README.md +228 -0
  112. package/claude/skills/accessibility/SKILL.md +573 -0
  113. package/claude/skills/api-bypass-layers/SKILL.md +550 -0
  114. package/claude/skills/asana-integration/SKILL.md +499 -0
  115. package/claude/skills/better-auth/SKILL.md +666 -0
  116. package/claude/skills/billing-subscriptions/SKILL.md +660 -0
  117. package/claude/skills/block-decision-matrix/SKILL.md +359 -0
  118. package/claude/skills/clickup-integration/SKILL.md +434 -0
  119. package/claude/skills/core-theme-responsibilities/SKILL.md +485 -0
  120. package/claude/skills/create-plugin/SKILL.md +425 -0
  121. package/claude/skills/create-theme/SKILL.md +331 -0
  122. package/claude/skills/cypress-api/SKILL.md +511 -0
  123. package/claude/skills/cypress-api/scripts/generate-api-controller.py +329 -0
  124. package/claude/skills/cypress-api/scripts/generate-api-test.py +930 -0
  125. package/claude/skills/cypress-e2e/SKILL.md +526 -0
  126. package/claude/skills/cypress-e2e/scripts/extract-selectors.py +383 -0
  127. package/claude/skills/cypress-e2e/scripts/generate-uat-test.py +788 -0
  128. package/claude/skills/cypress-selectors/SKILL.md +309 -0
  129. package/claude/skills/cypress-selectors/scripts/extract-missing.py +243 -0
  130. package/claude/skills/cypress-selectors/scripts/generate-block-selectors.py +283 -0
  131. package/claude/skills/cypress-selectors/scripts/validate-selectors.py +145 -0
  132. package/claude/skills/database-migrations/SKILL.md +335 -0
  133. package/claude/skills/database-migrations/scripts/generate-sample-data.py +284 -0
  134. package/claude/skills/database-migrations/scripts/validate-migration.py +323 -0
  135. package/claude/skills/design-system/SKILL.md +682 -0
  136. package/claude/skills/documentation/SKILL.md +540 -0
  137. package/claude/skills/entity-api/SKILL.md +482 -0
  138. package/claude/skills/entity-system/SKILL.md +635 -0
  139. package/claude/skills/entity-system/scripts/generate-child-migration.py +298 -0
  140. package/claude/skills/entity-system/scripts/generate-metas-migration.py +233 -0
  141. package/claude/skills/entity-system/scripts/generate-migration.py +382 -0
  142. package/claude/skills/entity-system/scripts/generate-sample-data.py +418 -0
  143. package/claude/skills/entity-system/scripts/scaffold-entity.py +661 -0
  144. package/claude/skills/github/SKILL.md +467 -0
  145. package/claude/skills/i18n-nextintl/SKILL.md +302 -0
  146. package/claude/skills/i18n-nextintl/scripts/add-translation.py +243 -0
  147. package/claude/skills/i18n-nextintl/scripts/extract-hardcoded.py +246 -0
  148. package/claude/skills/i18n-nextintl/scripts/validate-translations.py +260 -0
  149. package/claude/skills/impact-analysis/SKILL.md +203 -0
  150. package/claude/skills/jest-unit/SKILL.md +306 -0
  151. package/claude/skills/jest-unit/references/component-testing.md +371 -0
  152. package/claude/skills/jest-unit/references/mocking-patterns.md +380 -0
  153. package/claude/skills/jest-unit/references/service-hook-testing.md +454 -0
  154. package/claude/skills/jira-integration/SKILL.md +539 -0
  155. package/claude/skills/mock-analysis/SKILL.md +276 -0
  156. package/claude/skills/monorepo-architecture/SKILL.md +162 -0
  157. package/claude/skills/nextjs-api-development/SKILL.md +364 -0
  158. package/claude/skills/nextjs-api-development/scripts/generate-crud-tests.py +456 -0
  159. package/claude/skills/nextjs-api-development/scripts/scaffold-endpoint.py +481 -0
  160. package/claude/skills/nextjs-api-development/scripts/validate-api.py +283 -0
  161. package/claude/skills/notion-integration/SKILL.md +641 -0
  162. package/claude/skills/npm-development-workflow/SKILL.md +480 -0
  163. package/claude/skills/page-builder-blocks/SKILL.md +483 -0
  164. package/claude/skills/page-builder-blocks/scripts/scaffold-block.py +444 -0
  165. package/claude/skills/permissions-system/SKILL.md +619 -0
  166. package/claude/skills/plugins/SKILL.md +340 -0
  167. package/claude/skills/plugins/references/plugin-templates.md +414 -0
  168. package/claude/skills/plugins/references/plugin-testing.md +353 -0
  169. package/claude/skills/plugins/references/plugin-types.md +198 -0
  170. package/claude/skills/plugins/scripts/scaffold-plugin.py +443 -0
  171. package/claude/skills/pom-patterns/SKILL.md +452 -0
  172. package/claude/skills/pom-patterns/scripts/generate-pom.py +392 -0
  173. package/claude/skills/rate-limiting/SKILL.md +342 -0
  174. package/claude/skills/react-best-practices/AGENTS.md +2410 -0
  175. package/claude/skills/react-best-practices/README.md +123 -0
  176. package/claude/skills/react-best-practices/SKILL.md +125 -0
  177. package/claude/skills/react-best-practices/metadata.json +15 -0
  178. package/claude/skills/react-best-practices/rules/_sections.md +46 -0
  179. package/claude/skills/react-best-practices/rules/_template.md +28 -0
  180. package/claude/skills/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  181. package/claude/skills/react-best-practices/rules/advanced-use-latest.md +49 -0
  182. package/claude/skills/react-best-practices/rules/async-api-routes.md +38 -0
  183. package/claude/skills/react-best-practices/rules/async-defer-await.md +80 -0
  184. package/claude/skills/react-best-practices/rules/async-dependencies.md +36 -0
  185. package/claude/skills/react-best-practices/rules/async-parallel.md +28 -0
  186. package/claude/skills/react-best-practices/rules/async-suspense-boundaries.md +99 -0
  187. package/claude/skills/react-best-practices/rules/bundle-barrel-imports.md +59 -0
  188. package/claude/skills/react-best-practices/rules/bundle-conditional.md +31 -0
  189. package/claude/skills/react-best-practices/rules/bundle-defer-third-party.md +49 -0
  190. package/claude/skills/react-best-practices/rules/bundle-dynamic-imports.md +35 -0
  191. package/claude/skills/react-best-practices/rules/bundle-preload.md +50 -0
  192. package/claude/skills/react-best-practices/rules/client-event-listeners.md +74 -0
  193. package/claude/skills/react-best-practices/rules/client-localstorage-schema.md +71 -0
  194. package/claude/skills/react-best-practices/rules/client-passive-event-listeners.md +48 -0
  195. package/claude/skills/react-best-practices/rules/client-swr-dedup.md +56 -0
  196. package/claude/skills/react-best-practices/rules/js-batch-dom-css.md +82 -0
  197. package/claude/skills/react-best-practices/rules/js-cache-function-results.md +80 -0
  198. package/claude/skills/react-best-practices/rules/js-cache-property-access.md +28 -0
  199. package/claude/skills/react-best-practices/rules/js-cache-storage.md +70 -0
  200. package/claude/skills/react-best-practices/rules/js-combine-iterations.md +32 -0
  201. package/claude/skills/react-best-practices/rules/js-early-exit.md +50 -0
  202. package/claude/skills/react-best-practices/rules/js-hoist-regexp.md +45 -0
  203. package/claude/skills/react-best-practices/rules/js-index-maps.md +37 -0
  204. package/claude/skills/react-best-practices/rules/js-length-check-first.md +49 -0
  205. package/claude/skills/react-best-practices/rules/js-min-max-loop.md +82 -0
  206. package/claude/skills/react-best-practices/rules/js-set-map-lookups.md +24 -0
  207. package/claude/skills/react-best-practices/rules/js-tosorted-immutable.md +57 -0
  208. package/claude/skills/react-best-practices/rules/rendering-activity.md +26 -0
  209. package/claude/skills/react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
  210. package/claude/skills/react-best-practices/rules/rendering-conditional-render.md +40 -0
  211. package/claude/skills/react-best-practices/rules/rendering-content-visibility.md +38 -0
  212. package/claude/skills/react-best-practices/rules/rendering-hoist-jsx.md +46 -0
  213. package/claude/skills/react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
  214. package/claude/skills/react-best-practices/rules/rendering-svg-precision.md +28 -0
  215. package/claude/skills/react-best-practices/rules/rerender-defer-reads.md +39 -0
  216. package/claude/skills/react-best-practices/rules/rerender-dependencies.md +45 -0
  217. package/claude/skills/react-best-practices/rules/rerender-derived-state.md +29 -0
  218. package/claude/skills/react-best-practices/rules/rerender-functional-setstate.md +74 -0
  219. package/claude/skills/react-best-practices/rules/rerender-lazy-state-init.md +58 -0
  220. package/claude/skills/react-best-practices/rules/rerender-memo.md +44 -0
  221. package/claude/skills/react-best-practices/rules/rerender-transitions.md +40 -0
  222. package/claude/skills/react-best-practices/rules/server-after-nonblocking.md +73 -0
  223. package/claude/skills/react-best-practices/rules/server-cache-lru.md +41 -0
  224. package/claude/skills/react-best-practices/rules/server-cache-react.md +76 -0
  225. package/claude/skills/react-best-practices/rules/server-parallel-fetching.md +83 -0
  226. package/claude/skills/react-best-practices/rules/server-serialization.md +38 -0
  227. package/claude/skills/react-patterns/SKILL.md +677 -0
  228. package/claude/skills/registry-system/SKILL.md +331 -0
  229. package/claude/skills/scheduled-actions/SKILL.md +431 -0
  230. package/claude/skills/scope-enforcement/SKILL.md +542 -0
  231. package/claude/skills/scope-enforcement/scripts/validate-scope.py +357 -0
  232. package/claude/skills/server-actions/SKILL.md +493 -0
  233. package/claude/skills/service-layer/SKILL.md +587 -0
  234. package/claude/skills/session-management/SKILL.md +266 -0
  235. package/claude/skills/session-management/scripts/create-session.py +166 -0
  236. package/claude/skills/session-management/scripts/iteration-close.sh +105 -0
  237. package/claude/skills/session-management/scripts/iteration-init.sh +180 -0
  238. package/claude/skills/session-management/scripts/session-archive.sh +87 -0
  239. package/claude/skills/session-management/scripts/session-close.sh +133 -0
  240. package/claude/skills/session-management/scripts/session-init.sh +225 -0
  241. package/claude/skills/session-management/scripts/session-list.sh +163 -0
  242. package/claude/skills/session-management/scripts/split-plan.sh +116 -0
  243. package/claude/skills/shadcn-components/SKILL.md +586 -0
  244. package/claude/skills/shadcn-theming/SKILL.md +446 -0
  245. package/claude/skills/suspense-loading/SKILL.md +280 -0
  246. package/claude/skills/tailwind-theming/SKILL.md +479 -0
  247. package/claude/skills/tanstack-query/SKILL.md +608 -0
  248. package/claude/skills/test-coverage/SKILL.md +239 -0
  249. package/claude/skills/web-design-guidelines/SKILL.md +39 -0
  250. package/claude/skills/zod-validation/SKILL.md +537 -0
  251. package/claude/templates/blocks/progress.md +86 -0
  252. package/claude/templates/iteration/changes.md +61 -0
  253. package/claude/templates/iteration/progress.md +55 -0
  254. package/claude/templates/log.md +31 -0
  255. package/claude/templates/story/context.md +77 -0
  256. package/claude/templates/story/pendings.md +37 -0
  257. package/claude/templates/story/plan.md +299 -0
  258. package/claude/templates/story/requirements.md +109 -0
  259. package/claude/templates/story/scope.json +10 -0
  260. package/claude/templates/story/tests.md +91 -0
  261. package/claude/templates/task/progress.md +58 -0
  262. package/claude/templates/task/requirements.md +54 -0
  263. package/claude/workflows/README.md +154 -0
  264. package/claude/workflows/blocks.md +614 -0
  265. package/claude/workflows/story.md +1207 -0
  266. package/claude/workflows/task.md +927 -0
  267. package/claude/workflows/tweak.md +527 -0
  268. package/cursor/.gitkeep +0 -0
  269. package/package.json +34 -0
  270. package/scripts/setup.mjs +282 -0
  271. package/scripts/sync.mjs +209 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 NextSpark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @nextsparkjs/ai-workflow
2
+
3
+ AI workflow templates for NextSpark applications. Provides agents, commands, skills, and configuration for AI-assisted development with multiple editor support.
4
+
5
+ ## Supported Editors
6
+
7
+ | Editor | Status | Directory |
8
+ |--------|--------|-----------|
9
+ | Claude Code | Active | `claude/` |
10
+ | Cursor | Planned | `cursor/` |
11
+ | Antigravity | Planned | `antigravity/` |
12
+
13
+ ## Setup
14
+
15
+ ### Via CLI (recommended)
16
+
17
+ ```bash
18
+ nextspark setup:ai
19
+ ```
20
+
21
+ ### Manual
22
+
23
+ ```bash
24
+ node node_modules/@nextsparkjs/ai-workflow/scripts/setup.mjs [editor]
25
+ ```
26
+
27
+ **Editor options:** `claude` (default), `cursor` (coming soon), `antigravity` (coming soon), `all`
28
+
29
+ ### During project init
30
+
31
+ The `nextspark init` wizard includes an optional AI workflow setup step at the end.
32
+
33
+ ## What Gets Copied
34
+
35
+ When you run setup, files are copied **individually** to your project. User-created files are never deleted.
36
+
37
+ ### Overwritten (framework-managed)
38
+
39
+ | Directory | Description |
40
+ |-----------|-------------|
41
+ | `agents/*.md` | Agent definitions (22+ agents) |
42
+ | `commands/**/*.md` | Slash commands and how-to guides |
43
+ | `skills/**/*` | Skill definitions |
44
+ | `templates/**/*` | Session file templates |
45
+ | `workflows/**/*` | Workflow definitions |
46
+ | `_docs/**/*` | Internal documentation |
47
+ | `config/*.schema.json` | JSON schemas (always updated) |
48
+
49
+ ### Preserved (user-owned)
50
+
51
+ | Path | Description |
52
+ |------|-------------|
53
+ | `config/context.json` | Project context config |
54
+ | `config/workspace.json` | Workspace preferences |
55
+ | `config/team.json` | Team member config |
56
+ | `config/github.json` | GitHub workflow config |
57
+ | `sessions/` | Session data (never touched) |
58
+ | Custom files in any directory | Your files are never deleted |
59
+
60
+ ## Structure
61
+
62
+ ```
63
+ claude/
64
+ ├── agents/ # Agent definitions (26+ agents)
65
+ ├── commands/ # Slash commands and how-to guides
66
+ ├── config/ # Configuration files + schemas
67
+ ├── skills/ # Skill definitions
68
+ ├── templates/ # Session file templates
69
+ ├── workflows/ # Workflow definitions
70
+ ├── _docs/ # Internal documentation
71
+ └── sessions/ # Created on setup (empty)
72
+ ```
73
+
74
+ ## For Monorepo Contributors
75
+
76
+ If you're developing the NextSpark framework itself, use the sync script to copy your working `.claude/` directory into this package before publishing:
77
+
78
+ ```bash
79
+ node packages/ai-workflow/scripts/sync.mjs
80
+ ```
81
+
82
+ This syncs agents, commands, skills, templates, workflows, docs, and schemas while preserving the consumer config templates (context.json, workspace.json, team.json, github.json).
83
+
84
+ ## Versioning
85
+
86
+ This package versions independently from `@nextsparkjs/core`. Agent, command, and skill updates ship here without requiring a core release.
@@ -0,0 +1,359 @@
1
+ # Token Optimization System for STORY Workflow
2
+
3
+ This document explains the token optimization strategy implemented in the STORY workflow to reduce context window consumption by developer agents.
4
+
5
+ ---
6
+
7
+ ## Quick Reference
8
+
9
+ ```bash
10
+ # After Arc creates plan.md, run:
11
+ ./skills/session-management/scripts/split-plan.sh stories/YYYY-MM-DD-name/
12
+
13
+ # Verify:
14
+ ls stories/YYYY-MM-DD-name/phases/
15
+ ```
16
+
17
+ **Result:** ~76% token reduction (62,400 → 15,000 tokens)
18
+
19
+ ---
20
+
21
+ ## Problem Statement
22
+
23
+ ### How Subagent Context Windows Work
24
+
25
+ Each time a subagent is invoked, it starts with a **fresh context window**. Unlike the orchestrator (main Claude instance), subagents do not inherit the conversation history. They only receive:
26
+
27
+ 1. The prompt provided by the orchestrator
28
+ 2. Any files they explicitly read during execution
29
+
30
+ This means that if 8 developer agents each need to understand the requirements and technical plan, each agent must read the source files independently.
31
+
32
+ ### The Cost Without Optimization
33
+
34
+ In a typical STORY workflow:
35
+ - `requirements.md`: ~5,000 tokens
36
+ - `plan.md`: ~2,800 tokens
37
+ - **Per agent cost**: ~7,800 tokens
38
+
39
+ With 8 developer agents (db-entity, backend, frontend, validators, etc.):
40
+ - **Total: 8 × 7,800 = 62,400 tokens**
41
+
42
+ This is pure overhead - the same information read 8 times.
43
+
44
+ ---
45
+
46
+ ## Why Briefings Don't Work
47
+
48
+ An initial proposal was to have the orchestrator create a "briefing" file for each agent:
49
+
50
+ ```
51
+ For each phase:
52
+ 1. Orchestrator reads requirements.md + plan.md
53
+ 2. Orchestrator creates briefing-phase-X.md
54
+ 3. Agent reads briefing-phase-X.md
55
+ ```
56
+
57
+ **Problem:** This just moves the token cost around. The orchestrator must re-read requirements.md and plan.md before each phase to create the briefing. The total tokens consumed remain the same (or increase slightly due to write operations).
58
+
59
+ ---
60
+
61
+ ## The Pre-Split Solution
62
+
63
+ ### Core Idea
64
+
65
+ Front-load all context extraction to a single agent (Arc), then use a **zero-cost script** to split the output into phase-specific files.
66
+
67
+ ### How It Works
68
+
69
+ ```
70
+ ┌─────────────────────────────────────────────────────────────────┐
71
+ │ ONE-TIME COST (Arc - Phase 2) │
72
+ ├─────────────────────────────────────────────────────────────────┤
73
+ │ │
74
+ │ 1. Arc reads requirements.md (~5,000 tokens) │
75
+ │ 2. Arc creates plan.md with phase markers (~7,000 tokens) │
76
+ │ └── Each phase section is self-contained (~800 tokens) │
77
+ │ └── ACs are extracted per phase (not "see requirements") │
78
+ │ │
79
+ │ Arc's total overhead: ~7,000 tokens (ONE TIME) │
80
+ │ │
81
+ └─────────────────────────────────────────────────────────────────┘
82
+
83
+
84
+ ┌─────────────────────────────────────────────────────────────────┐
85
+ │ ZERO-COST OPERATION (Bash Script) │
86
+ ├─────────────────────────────────────────────────────────────────┤
87
+ │ │
88
+ │ ./skills/session-management/scripts/split-plan.sh \ │
89
+ │ stories/2026-01-12-products/ │
90
+ │ │
91
+ │ Extracts phase sections using grep/sed: │
92
+ │ - phase-03-db-entity-developer.md │
93
+ │ - phase-05-backend-developer.md │
94
+ │ - phase-07-mock-analyzer.md (if mock exists) │
95
+ │ - phase-08-frontend-developer.md │
96
+ │ - ... │
97
+ │ │
98
+ │ Token cost: 0 (pure text manipulation) │
99
+ │ │
100
+ └─────────────────────────────────────────────────────────────────┘
101
+
102
+
103
+ ┌─────────────────────────────────────────────────────────────────┐
104
+ │ PER-AGENT COST (Developer Agents) │
105
+ ├─────────────────────────────────────────────────────────────────┤
106
+ │ │
107
+ │ Each agent reads ONLY: │
108
+ │ - phases/phase-XX-name.md (~800 tokens) │
109
+ │ - progress.md (~200 tokens) │
110
+ │ │
111
+ │ Per agent cost: ~1,000 tokens (instead of ~7,800) │
112
+ │ 8 agents × 1,000 = 8,000 tokens │
113
+ │ │
114
+ └─────────────────────────────────────────────────────────────────┘
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Token Comparison
120
+
121
+ | Approach | Arc Cost | Per Agent | 8 Agents | Total | Savings |
122
+ |----------|----------|-----------|----------|-------|---------|
123
+ | **No optimization** | 0 | 7,800 | 62,400 | **62,400** | - |
124
+ | **Pre-split phases** | 7,000 | 1,000 | 8,000 | **15,000** | 47,400 (76%) |
125
+
126
+ ### Notes
127
+
128
+ - "Arc Cost" includes reading requirements.md and creating comprehensive plan.md
129
+ - "Per Agent" includes phase file + progress.md
130
+ - Actual savings may vary based on feature complexity
131
+ - Not all 8 phases run every time (some are CONDITIONAL/OPTIONAL)
132
+ - Larger features see greater absolute savings
133
+
134
+ ---
135
+
136
+ ## Phase Coverage
137
+
138
+ The system creates phase files for developer agents, NOT for validators or orchestrator phases:
139
+
140
+ | Phase | Agent | Marker? | Type | Reason |
141
+ |-------|-------|---------|------|--------|
142
+ | 03 | db-entity-developer | ✅ | SUBAGENT | Needs context to create DB/entity |
143
+ | 04 | db-entity-validator | ❌ | GATE | Validates, doesn't write code |
144
+ | 05 | backend-developer | ✅ | SUBAGENT | Needs context to create API |
145
+ | 06 | backend-validator | ❌ | GATE | Validates, doesn't write code |
146
+ | 07 | mock-analyzer | ✅ | CONDITIONAL | Needs context if mock exists |
147
+ | 08 | frontend-developer | ✅ | SUBAGENT | Needs context to create UI |
148
+ | 09 | frontend-validator | ❌ | GATE | Validates, doesn't write code |
149
+ | 10 | code-reviewer | ✅ | SUBAGENT | Needs context to review code |
150
+ | 11 | qa-manual | ❌ | ORCHESTRATOR | Has full context already |
151
+ | 12 | qa-automation | ✅ | OPTIONAL | Needs context if automation required |
152
+ | 13 | documentation-writer | ✅ | CONDITIONAL | Needs context if docs required |
153
+ | 14 | unit-test-writer | ✅ | OPTIONAL | Needs context if coverage needed |
154
+
155
+ **Total:** 8 phases with markers, 4 without (GATEs + ORCHESTRATOR)
156
+
157
+ ---
158
+
159
+ ## Phase Marker Format
160
+
161
+ Arc creates `plan.md` with HTML comment markers that enable script extraction:
162
+
163
+ ```markdown
164
+ <!-- PHASE:03:START -->
165
+ ## Phase 3: DB Entity Developer
166
+
167
+ ### Objective
168
+ Create database migrations and entity configuration files for Products.
169
+
170
+ ### Relevant ACs
171
+ - AC1: Products table with name, price, description fields
172
+ - AC2: Category relation (many-to-one)
173
+ - AC3: Sample data for testing (20+ products)
174
+
175
+ ### Prerequisites
176
+ - None (first development phase)
177
+
178
+ ### Files to Create
179
+ - `migrations/0001_create_products.sql` - Main table + indexes
180
+ - `core/entities/products/products.config.ts` - Entity config
181
+ - `core/entities/products/products.fields.ts` - Field definitions
182
+ - `core/entities/products/products.types.ts` - TypeScript types
183
+ - `core/entities/products/products.service.ts` - Service layer
184
+
185
+ ### Implementation Notes
186
+ - Use TIMESTAMPTZ for all date fields
187
+ - Include RLS policies for team isolation
188
+ - Sample data should have varied prices ($10-$500)
189
+ <!-- PHASE:03:END -->
190
+ ```
191
+
192
+ ### Key Constraints
193
+
194
+ 1. **~800 tokens maximum per phase** - Enough for context, not overwhelming
195
+ 2. **Self-contained** - No "see requirements.md" references
196
+ 3. **ACs extracted** - Only relevant ACs included, not AC references
197
+ 4. **Prerequisites explicit** - What must exist before this phase runs
198
+
199
+ ---
200
+
201
+ ## Script Location
202
+
203
+ The split script is part of the session-management skill:
204
+
205
+ ```
206
+ skills/session-management/scripts/split-plan.sh
207
+ ```
208
+
209
+ ### Usage
210
+
211
+ ```bash
212
+ # From project root
213
+ ./skills/session-management/scripts/split-plan.sh <session_path>
214
+
215
+ # Example
216
+ ./skills/session-management/scripts/split-plan.sh stories/2026-01-12-products/
217
+
218
+ # Output
219
+ Found 8 phase markers in plan.md
220
+ Created: phase-03-db-entity-developer.md
221
+ Created: phase-05-backend-developer.md
222
+ Created: phase-07-mock-analyzer.md
223
+ Created: phase-08-frontend-developer.md
224
+ Created: phase-10-code-reviewer.md
225
+ Created: phase-12-qa-automation.md
226
+ Created: phase-13-documentation-writer.md
227
+ Created: phase-14-unit-test-writer.md
228
+
229
+ ✓ Split complete: 8 phase files created in stories/2026-01-12-products/phases
230
+ ```
231
+
232
+ ### Output Structure
233
+
234
+ ```
235
+ stories/2026-01-12-products/
236
+ ├── requirements.md
237
+ ├── plan.md # Full plan with markers
238
+ ├── phases/ # Split phase files (auto-generated)
239
+ │ ├── phase-03-db-entity-developer.md
240
+ │ ├── phase-05-backend-developer.md
241
+ │ ├── phase-07-mock-analyzer.md
242
+ │ ├── phase-08-frontend-developer.md
243
+ │ ├── phase-10-code-reviewer.md
244
+ │ ├── phase-12-qa-automation.md
245
+ │ ├── phase-13-documentation-writer.md
246
+ │ └── phase-14-unit-test-writer.md
247
+ ├── progress.md
248
+ └── ...
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Agent Instructions Update
254
+
255
+ ### Old Pattern (High Token Cost)
256
+
257
+ ```
258
+ Agent Responsibilities:
259
+ ├── Read requirements.md (5,000 tokens)
260
+ ├── Read plan.md (2,800 tokens)
261
+ └── Implement feature...
262
+ ```
263
+
264
+ ### New Pattern (Optimized)
265
+
266
+ ```
267
+ Agent Responsibilities:
268
+ ├── Read phases/phase-XX-name.md (800 tokens)
269
+ │ └── Contains: Objective, Relevant ACs, Prerequisites, Files
270
+ ├── Read progress.md (200 tokens)
271
+ └── Implement feature...
272
+ ```
273
+
274
+ ---
275
+
276
+ ## When This Optimization Applies
277
+
278
+ | Workflow | Applies? | Reason |
279
+ |----------|----------|--------|
280
+ | **TWEAK** | No | No subagents, Claude implements directly |
281
+ | **TASK** | Partial | Fewer agents, lower overhead |
282
+ | **STORY** | Yes | 8+ agents, maximum benefit |
283
+
284
+ ---
285
+
286
+ ## Verification
287
+
288
+ After Arc creates plan.md:
289
+
290
+ ```bash
291
+ # Check markers exist
292
+ grep -c "PHASE:.*:START" plan.md
293
+ # Expected: 8 markers (phases 03, 05, 07, 08, 10, 12, 13, 14)
294
+
295
+ # Run split
296
+ ./skills/session-management/scripts/split-plan.sh stories/current-session/
297
+
298
+ # Verify files
299
+ ls -la stories/current-session/phases/
300
+ # Should show 8 phase files
301
+ ```
302
+
303
+ ---
304
+
305
+ ## Troubleshooting
306
+
307
+ ### No phase markers found
308
+
309
+ ```
310
+ Warning: No phase markers found in plan.md
311
+ ```
312
+
313
+ **Cause:** Arc didn't create plan.md with the required markers.
314
+
315
+ **Fix:** Ensure Arc (architecture-supervisor) is using the correct template. Check `templates/story/plan.md` for the marker format.
316
+
317
+ ### Phase file is empty
318
+
319
+ **Cause:** Marker format incorrect (missing space, wrong phase number).
320
+
321
+ **Fix:** Check plan.md for exact format:
322
+ ```markdown
323
+ <!-- PHASE:XX:START -->
324
+ content here
325
+ <!-- PHASE:XX:END -->
326
+ ```
327
+
328
+ ### Script not found
329
+
330
+ ```
331
+ bash: ./split-plan.sh: No such file or directory
332
+ ```
333
+
334
+ **Fix:** Run from project root with full path:
335
+ ```bash
336
+ ./skills/session-management/scripts/split-plan.sh stories/...
337
+ ```
338
+
339
+ ### Permission denied
340
+
341
+ ```bash
342
+ chmod +x ./skills/session-management/scripts/split-plan.sh
343
+ ```
344
+
345
+ ---
346
+
347
+ ## Related Documentation
348
+
349
+ - `workflows/story.md` - STORY workflow details
350
+ - `templates/story/plan.md` - Plan template with markers
351
+ - `skills/session-management/SKILL.md` - Session management skill
352
+
353
+ ---
354
+
355
+ ## Version History
356
+
357
+ | Version | Date | Changes |
358
+ |---------|------|---------|
359
+ | 1.0 | 2026-01 | Initial implementation with 8 phase markers |