codymaster 4.1.0

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 (193) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +285 -0
  3. package/adapters/antigravity.js +15 -0
  4. package/adapters/claude-code.js +17 -0
  5. package/adapters/cursor.js +16 -0
  6. package/commands/bootstrap.md +49 -0
  7. package/commands/build.md +48 -0
  8. package/commands/content.md +48 -0
  9. package/commands/continuity.md +60 -0
  10. package/commands/debug.md +51 -0
  11. package/commands/demo.md +96 -0
  12. package/commands/deploy.md +51 -0
  13. package/commands/plan.md +42 -0
  14. package/commands/review.md +55 -0
  15. package/commands/track.md +46 -0
  16. package/commands/ux.md +46 -0
  17. package/dist/agent-dispatch.js +161 -0
  18. package/dist/chains/builtin.js +85 -0
  19. package/dist/continuity.js +385 -0
  20. package/dist/dashboard.js +926 -0
  21. package/dist/data.js +122 -0
  22. package/dist/index.js +2434 -0
  23. package/dist/judge.js +252 -0
  24. package/dist/parallel-dispatch.js +359 -0
  25. package/dist/parallel-quality.js +172 -0
  26. package/dist/skill-chain.js +258 -0
  27. package/install.sh +513 -0
  28. package/package.json +79 -0
  29. package/skills/.content-factory-state.json +132 -0
  30. package/skills/.git 2/logs/refs/heads/main +1 -0
  31. package/skills/.git 2/logs/refs/remotes/origin/main +1 -0
  32. package/skills/.git 2/objects/02/fb0956734b5f8ba3f918b7defd04a89cfe0076 +0 -0
  33. package/skills/.git 2/objects/08/1e129d75dc6feac6c02037272e6bd1a04e3324 +0 -0
  34. package/skills/.git 2/objects/0c/5393416f3c5e01c9a655a802bff0dd52f76f0a +0 -0
  35. package/skills/.git 2/objects/10/0b9be46978a946a77188f68be725098a122001 +0 -0
  36. package/skills/.git 2/objects/10/cf041167fc9843610eb3d90259ef3396315fdc +0 -0
  37. package/skills/.git 2/objects/12/5e19538dd6e1338ffe74f6c4c165b00435bf48 +0 -0
  38. package/skills/.git 2/objects/16/a9b9d0088d5c1347628b45a2620b479d8ad57c +0 -0
  39. package/skills/.git 2/objects/17/8c2a9ef93c33ae4eec9d58e82321f9229843a1 +0 -0
  40. package/skills/.git 2/objects/25/397ae41d09104d763bdcac2695209d85cdea89 +0 -0
  41. package/skills/.git 2/objects/2f/a836b7947f2d458e1f639788bf4bb0983a3305 +0 -0
  42. package/skills/.git 2/objects/3a/baaaf0a1c0909c0828335791557125fba911e0 +0 -0
  43. package/skills/.git 2/objects/42/2924221b81f5ce3c4e4daac9a64a24f9b01f9a +0 -0
  44. package/skills/.git 2/objects/42/ec0ce707447dc11446a34c9995fb8533801731 +0 -0
  45. package/skills/.git 2/objects/46/e43ce92866d56ce74b1d750db307cfe6154a15 +0 -0
  46. package/skills/.git 2/objects/48/5e41b633c63f55b8277bcc59f44f67681f671a +0 -0
  47. package/skills/.git 2/objects/49/49c596a3a89fa240642acd95dd3258e261eb09 +0 -0
  48. package/skills/.git 2/objects/50/9d42d8412ef8eaf7f7e138476bac2e4d10ce60 +0 -0
  49. package/skills/.git 2/objects/55/0c8c389d981b463ef849aeb792d8be3ccb6ec8 +0 -0
  50. package/skills/.git 2/objects/5d/82d3b18410cdda3ace3677436f0cb599dbe2d2 +0 -0
  51. package/skills/.git 2/objects/60/0617c58e871a38b33bf29e282d132bb3c381ad +0 -0
  52. package/skills/.git 2/objects/6a/8369a99c687b7245c92ffaf0e0f0dab9014504 +0 -0
  53. package/skills/.git 2/objects/79/bea435d40ab531c1aaf6be0432c6a5b7aaed21 +0 -0
  54. package/skills/.git 2/objects/7e/5ebd79251c2f14e4aceb86c74b6b6daae6b500 +0 -0
  55. package/skills/.git 2/objects/81/98a822a60178d6d5023ddb3e222cddf048742e +0 -0
  56. package/skills/.git 2/objects/86/0a0e1943dfe53411d2e499a1f16f46a96ef758 +0 -0
  57. package/skills/.git 2/objects/86/971fb55fdc081fdbae52376f0f13e57a4e9b04 +0 -0
  58. package/skills/.git 2/objects/88/b89dd609a0a03f8d4fe8bfde20d5b8fc1d326d +0 -0
  59. package/skills/.git 2/objects/90/8737edb6b7809e32cc01590b4e08ba42a9d40d +0 -0
  60. package/skills/.git 2/objects/93/d5a8a9a7d4fb7f11491cb596a6880528725118 +0 -0
  61. package/skills/.git 2/objects/98/46a2ab81d0c3b3eb00ef88fc56989aa7e9f316 +0 -0
  62. package/skills/.git 2/objects/9b/d8dd1e49cf274eaf9c555f3ab39dce7af5715e +0 -0
  63. package/skills/.git 2/objects/a1/13329fb0cec96ae78b222d33a24c3b5bc7fa1f +0 -0
  64. package/skills/.git 2/objects/a9/e6effe626e8a3aea3a8fc3364b492191c6e7d0 +0 -0
  65. package/skills/.git 2/objects/ad/6de7e48d9782cca9353d1ff0aa1aab7fe1df85 +0 -0
  66. package/skills/.git 2/objects/af/54ae316f771ff692e299ffcd8bf2f06b413b59 +0 -0
  67. package/skills/.git 2/objects/b0/4cb8b0b00dad633e731c1472161419e738d674 +0 -0
  68. package/skills/.git 2/objects/b3/094abb0b9ed46419b269e4a4e36a459690e3b0 +0 -0
  69. package/skills/.git 2/objects/b9/435c5d4baac2cfc5c83009ddd27b46b60db5f1 +0 -0
  70. package/skills/.git 2/objects/ba/5da17dbaec5ec2dcfdfd126aead518d1171d5c +0 -0
  71. package/skills/.git 2/objects/c0/bf58703aa258ba5dd63083bebaec8f223d844c +0 -0
  72. package/skills/.git 2/objects/c4/701a34edf1fc1bad58ccc57bd03f9426acb59a +0 -0
  73. package/skills/.git 2/objects/c7/5ccce9a4e5cc74d9b3174550cf6d993ca43638 +0 -0
  74. package/skills/.git 2/objects/c7/710d59b5a35b0f1f0a0399386643a0bd94c929 +0 -0
  75. package/skills/.git 2/objects/d1/fe58237112e953e5fec52da22cf38e08be3df9 +5 -0
  76. package/skills/.git 2/objects/d2/2bbe9fd2f74c95bc5583e803f5e435f1e2cd86 +0 -0
  77. package/skills/.git 2/objects/d7/e72852ea2bff74581dbf247d400120086229f4 +0 -0
  78. package/skills/.git 2/objects/d8/d4c3b5553e4fd72807e1d4b49ef07d9ef3ac35 +0 -0
  79. package/skills/.git 2/objects/dc/75050c2876f6a02ae2a53a3c886f395b622977 +0 -0
  80. package/skills/.git 2/objects/ee/e8546f95acec500187c08a28a8b9ee02db0dec +0 -0
  81. package/skills/.git 2/objects/ef/263c059208b416c2146434f10cb2b9fabcba16 +0 -0
  82. package/skills/.git 2/objects/f3/ae597e84d9a59b88acd21c99bde2eaf686d785 +0 -0
  83. package/skills/.git 2/objects/f3/f6f5673c821d3d8e76fa267a9e882e7a5387ea +0 -0
  84. package/skills/.git 2/objects/f9/6e6d0ad02624dd11d5848594d056caef7a5e8b +0 -0
  85. package/skills/.git 2/objects/ff/278988fc1edf0db3abcf18de795f4cc0b4f3e1 +0 -0
  86. package/skills/.git 2/refs/heads/main +1 -0
  87. package/skills/.git 2/refs/remotes/origin/main +1 -0
  88. package/skills/.pytest_cache 2/v/cache/nodeids +76 -0
  89. package/skills/.pytest_cache 2/v/cache/stepwise +1 -0
  90. package/skills/_shared/helpers.md +123 -0
  91. package/skills/_shared/outputs-convention.md +24 -0
  92. package/skills/cm-ads-tracker/SKILL.md +109 -0
  93. package/skills/cm-ads-tracker/evals/evals.json +55 -0
  94. package/skills/cm-ads-tracker/references/gtm-architecture.md +321 -0
  95. package/skills/cm-ads-tracker/references/industry-events.md +294 -0
  96. package/skills/cm-ads-tracker/references/platforms-api.md +238 -0
  97. package/skills/cm-ads-tracker/templates/capi-payload.md +79 -0
  98. package/skills/cm-ads-tracker/templates/datalayer-push.js +104 -0
  99. package/skills/cm-ads-tracker/templates/gtm-variables.js +56 -0
  100. package/skills/cm-brainstorm-idea/SKILL.md +423 -0
  101. package/skills/cm-code-review/SKILL.md +151 -0
  102. package/skills/cm-content-factory/SKILL.md +416 -0
  103. package/skills/cm-continuity/SKILL.md +399 -0
  104. package/skills/cm-dashboard/SKILL.md +533 -0
  105. package/skills/cm-dashboard/ui/app.js +1270 -0
  106. package/skills/cm-dashboard/ui/index.html +206 -0
  107. package/skills/cm-dashboard/ui/style.css +440 -0
  108. package/skills/cm-debugging/SKILL.md +412 -0
  109. package/skills/cm-deep-search/SKILL.md +242 -0
  110. package/skills/cm-design-system/SKILL.md +97 -0
  111. package/skills/cm-design-system/resources/halo-modern.md +40 -0
  112. package/skills/cm-design-system/resources/lunaris-advanced.md +40 -0
  113. package/skills/cm-design-system/resources/nitro-enterprise.md +39 -0
  114. package/skills/cm-design-system/resources/shadcn-default.md +37 -0
  115. package/skills/cm-dockit/README.md +100 -0
  116. package/skills/cm-dockit/SKILL.md +302 -0
  117. package/skills/cm-dockit/index.html +443 -0
  118. package/skills/cm-dockit/package-lock.json +1850 -0
  119. package/skills/cm-dockit/package.json +14 -0
  120. package/skills/cm-dockit/prompts/analysis.md +34 -0
  121. package/skills/cm-dockit/prompts/api-reference.md +24 -0
  122. package/skills/cm-dockit/prompts/architecture.md +21 -0
  123. package/skills/cm-dockit/prompts/data-flow.md +20 -0
  124. package/skills/cm-dockit/prompts/database.md +21 -0
  125. package/skills/cm-dockit/prompts/deployment.md +22 -0
  126. package/skills/cm-dockit/prompts/flows.md +21 -0
  127. package/skills/cm-dockit/prompts/jtbd.md +20 -0
  128. package/skills/cm-dockit/prompts/personas.md +24 -0
  129. package/skills/cm-dockit/prompts/sop-modules.md +40 -0
  130. package/skills/cm-dockit/scripts/doc-gen.sh +121 -0
  131. package/skills/cm-dockit/scripts/dockit-dashboard.sh +142 -0
  132. package/skills/cm-dockit/scripts/dockit-runner.sh +607 -0
  133. package/skills/cm-dockit/scripts/dockit-task.sh +166 -0
  134. package/skills/cm-dockit/skills/analyze-codebase.md +174 -0
  135. package/skills/cm-dockit/skills/api-reference.md +237 -0
  136. package/skills/cm-dockit/skills/changelog-guide.md +195 -0
  137. package/skills/cm-dockit/skills/content-guidelines.md +190 -0
  138. package/skills/cm-dockit/skills/sop-guide.md +184 -0
  139. package/skills/cm-dockit/skills/tech-docs.md +287 -0
  140. package/skills/cm-dockit/templates/markdown/structure.md +60 -0
  141. package/skills/cm-dockit/templates/vitepress-premium/.vitepress/config.mts +110 -0
  142. package/skills/cm-dockit/templates/vitepress-premium/.vitepress/theme/custom.css +189 -0
  143. package/skills/cm-dockit/templates/vitepress-premium/.vitepress/theme/index.ts +4 -0
  144. package/skills/cm-dockit/templates/vitepress-premium/package.json +19 -0
  145. package/skills/cm-dockit/templates/vitepress-premium/tests/frontend.test.ts +45 -0
  146. package/skills/cm-dockit/tests/runner.test.ts +66 -0
  147. package/skills/cm-dockit/workflows/export-markdown.md +82 -0
  148. package/skills/cm-dockit/workflows/generate-docs.md +68 -0
  149. package/skills/cm-dockit/workflows/setup-vitepress.md +181 -0
  150. package/skills/cm-example/SKILL.md +26 -0
  151. package/skills/cm-execution/SKILL.md +268 -0
  152. package/skills/cm-git-worktrees/SKILL.md +164 -0
  153. package/skills/cm-how-it-work/SKILL.md +189 -0
  154. package/skills/cm-identity-guard/SKILL.md +412 -0
  155. package/skills/cm-jtbd/SKILL.md +98 -0
  156. package/skills/cm-planning/SKILL.md +130 -0
  157. package/skills/cm-project-bootstrap/SKILL.md +161 -0
  158. package/skills/cm-project-bootstrap/templates/AGENTS.md +42 -0
  159. package/skills/cm-project-bootstrap/templates/frontend-safety.test.js +51 -0
  160. package/skills/cm-project-bootstrap/templates/i18n-sync.test.js +38 -0
  161. package/skills/cm-project-bootstrap/templates/pr-template.md +12 -0
  162. package/skills/cm-project-bootstrap/templates/project-identity.json +29 -0
  163. package/skills/cm-project-bootstrap/templates/vitest.config.js +10 -0
  164. package/skills/cm-quality-gate/SKILL.md +218 -0
  165. package/skills/cm-readit/SKILL.md +289 -0
  166. package/skills/cm-readit/audio-player.md +206 -0
  167. package/skills/cm-readit/examples/blog-reader.js +352 -0
  168. package/skills/cm-readit/examples/voice-cro.js +390 -0
  169. package/skills/cm-readit/tts-engine.md +262 -0
  170. package/skills/cm-readit/ui-patterns.md +362 -0
  171. package/skills/cm-readit/voice-cro.md +223 -0
  172. package/skills/cm-safe-deploy/SKILL.md +120 -0
  173. package/skills/cm-safe-deploy/templates/deploy.sh +89 -0
  174. package/skills/cm-safe-i18n/SKILL.md +473 -0
  175. package/skills/cm-secret-shield/SKILL.md +580 -0
  176. package/skills/cm-skill-chain/SKILL.md +78 -0
  177. package/skills/cm-skill-index/SKILL.md +318 -0
  178. package/skills/cm-skill-mastery/SKILL.md +169 -0
  179. package/skills/cm-start/SKILL.md +65 -0
  180. package/skills/cm-status/SKILL.md +12 -0
  181. package/skills/cm-tdd/SKILL.md +370 -0
  182. package/skills/cm-terminal/SKILL.md +177 -0
  183. package/skills/cm-test-gate/SKILL.md +242 -0
  184. package/skills/cm-ui-preview/SKILL.md +291 -0
  185. package/skills/cm-ux-master/DESIGN_STANDARD_TEMPLATE.md +54 -0
  186. package/skills/cm-ux-master/SKILL.md +114 -0
  187. package/skills/cro-methodology/SKILL.md +98 -0
  188. package/skills/cro-methodology/references/COPYWRITING.md +178 -0
  189. package/skills/cro-methodology/references/OBJECTIONS.md +135 -0
  190. package/skills/cro-methodology/references/PERSUASION.md +158 -0
  191. package/skills/cro-methodology/references/RESEARCH.md +220 -0
  192. package/skills/cro-methodology/references/funnel-analysis.md +365 -0
  193. package/skills/cro-methodology/references/testing-methodology.md +330 -0
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateMiniGatePrompt = generateMiniGatePrompt;
4
+ exports.compositeAgentPrompt = compositeAgentPrompt;
5
+ exports.getQualityContractForTask = getQualityContractForTask;
6
+ exports.validateAgentReport = validateAgentReport;
7
+ // ─── TRIZ #3: Local Quality — Per-Agent Mini Gate ──────────────────────────
8
+ /**
9
+ * Generates a lightweight quality gate prompt that each agent must run
10
+ * on its own modified files. Only checks syntax (Layer 1) and business
11
+ * logic (Layer 3) — skips full suite for speed.
12
+ *
13
+ * TRIZ Principle #3 (Local Quality): Each part of the system should
14
+ * perform the function that is most useful locally.
15
+ */
16
+ function generateMiniGatePrompt(task, contract) {
17
+ const checks = [];
18
+ if (contract.mustPassSyntax) {
19
+ checks.push(`1. **Syntax Validation**: Ensure all modified files parse without errors.
20
+ For TypeScript/JavaScript files, run: \`npx tsc --noEmit\` or use acorn parser.
21
+ Modified files to check: ${task.affectedFiles.join(', ') || 'all changed files'}`);
22
+ }
23
+ if (contract.mustPassTests) {
24
+ checks.push(`2. **Test Execution**: Run tests relevant to your changes.
25
+ Command: \`npm run test:gate\` OR run only tests related to modified files.
26
+ If you created new functionality, write at least 1 test for it.`);
27
+ }
28
+ if (contract.mustSelfReview) {
29
+ checks.push(`3. **Self-Review Checklist**:
30
+ - [ ] No console.log/debug statements left
31
+ - [ ] No hardcoded values that should be configurable
32
+ - [ ] No TODO comments without associated task IDs
33
+ - [ ] Error handling is present for all async operations
34
+ - [ ] Types are properly defined (no \`any\` unless justified)`);
35
+ }
36
+ return `
37
+ ## ⚡ Quality Contract (TRIZ #3 Local Quality)
38
+
39
+ Before reporting task completion, you MUST pass these quality checks:
40
+
41
+ ${checks.join('\n\n')}
42
+
43
+ ### Constraints
44
+ - Maximum modified files: ${contract.maxModifiedFiles}
45
+ - Timeout: ${Math.round(contract.timeoutMs / 1000)}s
46
+
47
+ ### Report Format
48
+ After completing quality checks, report:
49
+ \`\`\`json
50
+ {
51
+ "taskId": "${task.id}",
52
+ "passed": true/false,
53
+ "modifiedFiles": ["file1.ts", "file2.ts"],
54
+ "testsPassed": 0,
55
+ "testsFailed": 0,
56
+ "issues": []
57
+ }
58
+ \`\`\`
59
+ `;
60
+ }
61
+ // ─── TRIZ #40: Composite — Agent = Implementer + Tester + Reviewer ────────
62
+ /**
63
+ * Generates a composite agent prompt that instructs the agent to perform
64
+ * all three roles: implement, test, and review.
65
+ *
66
+ * TRIZ Principle #40 (Composite Materials): Change from uniform to composite.
67
+ * Each agent is not just an implementer — it's a composite of three roles.
68
+ */
69
+ function compositeAgentPrompt(task, project, batchInfo) {
70
+ const qualityGate = generateMiniGatePrompt(task, task.qualityContract);
71
+ return `# Parallel Task: ${task.title}
72
+
73
+ ## 🔧 Context
74
+ | Field | Value |
75
+ |-------|-------|
76
+ | Project | ${project.name} |
77
+ | Workspace | \`${project.path}\` |
78
+ | Batch | ${batchInfo.batchId} (task ${batchInfo.position + 1}/${batchInfo.batchSize}) |
79
+ | Skill | ${task.skill || 'None'} |
80
+ | Priority | ${task.priority} |
81
+
82
+ ## 📝 Description
83
+
84
+ ${task.description || 'No additional description provided.'}
85
+
86
+ ## 🎭 Your Three Roles (TRIZ #40 Composite)
87
+
88
+ ### Role 1: IMPLEMENTER
89
+ Implement the task as described above. Follow existing code patterns and conventions.
90
+ ${task.skill ? `Use skill \`${task.skill}\` for guidance.` : ''}
91
+
92
+ ### Role 2: TESTER
93
+ After implementing, write or update tests for your changes:
94
+ - At minimum, 1 test per new function
95
+ - Run existing tests to ensure no regressions
96
+ - If TDD applies, write tests FIRST (cm-tdd)
97
+
98
+ ### Role 3: REVIEWER
99
+ Before reporting completion, review your own work:
100
+ - Read your diff critically
101
+ - Check for edge cases you may have missed
102
+ - Verify error handling completeness
103
+
104
+ ${qualityGate}
105
+
106
+ ## ⚠️ Parallel Execution Rules
107
+
108
+ 1. **ONLY modify these files**: ${task.affectedFiles.length > 0 ? task.affectedFiles.map(f => `\`${f}\``).join(', ') : 'Files as needed for this task'}
109
+ 2. **DO NOT modify files outside your scope** — other agents are working in parallel
110
+ 3. **Report your actual modified files** after completion for conflict detection
111
+ 4. **If you need to modify a shared file**, STOP and report the conflict instead of proceeding
112
+ `;
113
+ }
114
+ // ─── Quality Contract Presets ───────────────────────────────────────────────
115
+ /**
116
+ * Returns a quality contract tuned for the task type.
117
+ */
118
+ function getQualityContractForTask(task) {
119
+ // High-priority or urgent tasks get stricter contracts
120
+ if (task.priority === 'urgent' || task.priority === 'high') {
121
+ return {
122
+ mustPassSyntax: true,
123
+ mustPassTests: true,
124
+ mustSelfReview: true,
125
+ maxModifiedFiles: 5,
126
+ timeoutMs: 180000, // 3 min — tighter deadline
127
+ };
128
+ }
129
+ // Standard contract
130
+ return {
131
+ mustPassSyntax: true,
132
+ mustPassTests: true,
133
+ mustSelfReview: true,
134
+ maxModifiedFiles: 10,
135
+ timeoutMs: 300000, // 5 min
136
+ };
137
+ }
138
+ // ─── Validate Agent Report ──────────────────────────────────────────────────
139
+ /**
140
+ * Validates an agent's self-reported quality gate result.
141
+ * Returns a structured result with pass/fail details.
142
+ */
143
+ function validateAgentReport(report, contract) {
144
+ const checks = [];
145
+ // Check file count constraint
146
+ checks.push({
147
+ name: 'Modified files within limit',
148
+ passed: report.modifiedFiles.length <= contract.maxModifiedFiles,
149
+ details: `${report.modifiedFiles.length}/${contract.maxModifiedFiles} files`,
150
+ });
151
+ // Check test results
152
+ if (contract.mustPassTests) {
153
+ checks.push({
154
+ name: 'Tests passing',
155
+ passed: report.testsFailed === 0,
156
+ details: `${report.testsPassed} passed, ${report.testsFailed} failed`,
157
+ });
158
+ }
159
+ // Check self-reported pass status
160
+ checks.push({
161
+ name: 'Agent self-assessment',
162
+ passed: report.passed,
163
+ details: report.issues.length > 0 ? report.issues.join('; ') : 'No issues reported',
164
+ });
165
+ const allPassed = checks.every(c => c.passed);
166
+ return {
167
+ passed: allPassed,
168
+ taskId: report.taskId,
169
+ checks,
170
+ timestamp: new Date().toISOString(),
171
+ };
172
+ }
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.matchChain = matchChain;
7
+ exports.listChains = listChains;
8
+ exports.findChain = findChain;
9
+ exports.createChainExecution = createChainExecution;
10
+ exports.advanceChain = advanceChain;
11
+ exports.skipChainStep = skipChainStep;
12
+ exports.abortChain = abortChain;
13
+ exports.failChainStep = failChainStep;
14
+ exports.formatChainProgress = formatChainProgress;
15
+ exports.formatChainProgressBar = formatChainProgressBar;
16
+ exports.getCurrentSkill = getCurrentSkill;
17
+ const crypto_1 = __importDefault(require("crypto"));
18
+ const builtin_1 = require("./chains/builtin");
19
+ // ─── Chain Matching ─────────────────────────────────────────────────────────
20
+ // TRIZ #10: Preliminary Action — analyze task BEFORE dispatching
21
+ /**
22
+ * Auto-detect the best chain for a task title using keyword matching.
23
+ * Returns the best matching chain, or undefined if no match.
24
+ */
25
+ function matchChain(taskTitle) {
26
+ const title = taskTitle.toLowerCase();
27
+ const chains = (0, builtin_1.getBuiltinChains)();
28
+ let bestMatch;
29
+ let bestScore = 0;
30
+ for (const chain of chains) {
31
+ let score = 0;
32
+ for (const trigger of chain.triggers) {
33
+ if (title.includes(trigger.toLowerCase())) {
34
+ // Longer triggers get higher scores (more specific = better match)
35
+ score += trigger.length;
36
+ }
37
+ }
38
+ if (score > bestScore) {
39
+ bestScore = score;
40
+ bestMatch = chain;
41
+ }
42
+ }
43
+ return bestMatch;
44
+ }
45
+ /**
46
+ * List all available chains (built-in + user-defined in the future).
47
+ */
48
+ function listChains() {
49
+ return (0, builtin_1.getBuiltinChains)();
50
+ }
51
+ /**
52
+ * Find a chain by ID.
53
+ */
54
+ function findChain(chainId) {
55
+ return (0, builtin_1.getChainById)(chainId);
56
+ }
57
+ // ─── Chain Execution Management ─────────────────────────────────────────────
58
+ // TRIZ #40: Composite Materials — skills compose into pipelines
59
+ /**
60
+ * Create a new chain execution from a chain definition.
61
+ */
62
+ function createChainExecution(chain, projectId, taskTitle, agent) {
63
+ const now = new Date().toISOString();
64
+ const steps = chain.steps.map((step, index) => ({
65
+ index,
66
+ skill: step.skill,
67
+ description: step.description,
68
+ condition: step.condition,
69
+ optional: step.optional || false,
70
+ status: 'pending',
71
+ }));
72
+ // First step starts immediately
73
+ if (steps.length > 0) {
74
+ steps[0].status = 'running';
75
+ steps[0].startedAt = now;
76
+ }
77
+ return {
78
+ id: crypto_1.default.randomUUID(),
79
+ chainId: chain.id,
80
+ chainName: chain.name,
81
+ projectId,
82
+ taskTitle,
83
+ agent,
84
+ status: 'running',
85
+ currentStepIndex: 0,
86
+ steps,
87
+ startedAt: now,
88
+ updatedAt: now,
89
+ };
90
+ }
91
+ /**
92
+ * Advance the chain to the next step. Marks current step as completed.
93
+ * Returns the next step's skill name, or null if chain is complete.
94
+ */
95
+ function advanceChain(execution, output) {
96
+ const now = new Date().toISOString();
97
+ const currentStep = execution.steps[execution.currentStepIndex];
98
+ if (!currentStep) {
99
+ return { nextSkill: null, completed: true };
100
+ }
101
+ // Mark current step as completed
102
+ currentStep.status = 'completed';
103
+ currentStep.completedAt = now;
104
+ if (output)
105
+ currentStep.output = output;
106
+ execution.updatedAt = now;
107
+ // Find next non-skipped step
108
+ let nextIndex = execution.currentStepIndex + 1;
109
+ while (nextIndex < execution.steps.length) {
110
+ const nextStep = execution.steps[nextIndex];
111
+ // Skip optional steps with conditions that aren't met
112
+ if (nextStep.optional && nextStep.condition !== 'always') {
113
+ nextStep.status = 'skipped';
114
+ nextStep.completedAt = now;
115
+ nextIndex++;
116
+ continue;
117
+ }
118
+ break;
119
+ }
120
+ if (nextIndex >= execution.steps.length) {
121
+ // Chain completed!
122
+ execution.status = 'completed';
123
+ execution.completedAt = now;
124
+ execution.currentStepIndex = execution.steps.length;
125
+ return { nextSkill: null, completed: true };
126
+ }
127
+ // Start next step
128
+ execution.currentStepIndex = nextIndex;
129
+ const nextStep = execution.steps[nextIndex];
130
+ nextStep.status = 'running';
131
+ nextStep.startedAt = now;
132
+ return { nextSkill: nextStep.skill, completed: false };
133
+ }
134
+ /**
135
+ * Skip the current step in the chain.
136
+ */
137
+ function skipChainStep(execution, reason) {
138
+ const now = new Date().toISOString();
139
+ const currentStep = execution.steps[execution.currentStepIndex];
140
+ if (!currentStep) {
141
+ return { nextSkill: null, completed: true };
142
+ }
143
+ currentStep.status = 'skipped';
144
+ currentStep.completedAt = now;
145
+ if (reason)
146
+ currentStep.output = `Skipped: ${reason}`;
147
+ execution.updatedAt = now;
148
+ // Find next step
149
+ let nextIndex = execution.currentStepIndex + 1;
150
+ if (nextIndex >= execution.steps.length) {
151
+ execution.status = 'completed';
152
+ execution.completedAt = now;
153
+ execution.currentStepIndex = execution.steps.length;
154
+ return { nextSkill: null, completed: true };
155
+ }
156
+ execution.currentStepIndex = nextIndex;
157
+ const nextStep = execution.steps[nextIndex];
158
+ nextStep.status = 'running';
159
+ nextStep.startedAt = now;
160
+ return { nextSkill: nextStep.skill, completed: false };
161
+ }
162
+ /**
163
+ * Abort the entire chain.
164
+ */
165
+ function abortChain(execution, reason) {
166
+ const now = new Date().toISOString();
167
+ execution.status = 'aborted';
168
+ execution.completedAt = now;
169
+ execution.updatedAt = now;
170
+ // Mark remaining pending steps as skipped
171
+ for (const step of execution.steps) {
172
+ if (step.status === 'pending' || step.status === 'running') {
173
+ step.status = 'skipped';
174
+ step.completedAt = now;
175
+ if (reason)
176
+ step.output = `Aborted: ${reason}`;
177
+ }
178
+ }
179
+ }
180
+ /**
181
+ * Mark the current step as failed.
182
+ */
183
+ function failChainStep(execution, error) {
184
+ const now = new Date().toISOString();
185
+ const currentStep = execution.steps[execution.currentStepIndex];
186
+ if (currentStep) {
187
+ currentStep.status = 'failed';
188
+ currentStep.completedAt = now;
189
+ currentStep.error = error;
190
+ }
191
+ execution.status = 'failed';
192
+ execution.updatedAt = now;
193
+ }
194
+ // ─── Display Helpers ────────────────────────────────────────────────────────
195
+ const STEP_ICONS = {
196
+ pending: '⚪',
197
+ running: '🔵',
198
+ skipped: '⏭️',
199
+ completed: '✅',
200
+ failed: '❌',
201
+ };
202
+ const STATUS_ICONS = {
203
+ pending: '⚪',
204
+ running: '🔵',
205
+ paused: '⏸️',
206
+ completed: '✅',
207
+ failed: '❌',
208
+ aborted: '🛑',
209
+ };
210
+ /**
211
+ * Format chain progress for CLI display.
212
+ */
213
+ function formatChainProgress(execution) {
214
+ const lines = [];
215
+ const statusIcon = STATUS_ICONS[execution.status] || '❓';
216
+ lines.push(`${statusIcon} Chain: ${execution.chainName} — "${execution.taskTitle}"`);
217
+ lines.push(` Status: ${execution.status} | Agent: ${execution.agent}`);
218
+ lines.push(` Progress: ${getCompletedCount(execution)}/${execution.steps.length} steps`);
219
+ lines.push('');
220
+ for (const step of execution.steps) {
221
+ const icon = STEP_ICONS[step.status] || '❓';
222
+ const current = step.index === execution.currentStepIndex && execution.status === 'running' ? ' ◄ CURRENT' : '';
223
+ lines.push(` ${icon} ${step.index + 1}. ${step.skill} — ${step.description}${current}`);
224
+ if (step.error)
225
+ lines.push(` ⚠️ Error: ${step.error}`);
226
+ if (step.output && step.status !== 'skipped')
227
+ lines.push(` 📝 ${step.output}`);
228
+ }
229
+ return lines.join('\n');
230
+ }
231
+ /**
232
+ * Format a compact chain progress bar.
233
+ */
234
+ function formatChainProgressBar(execution) {
235
+ const parts = execution.steps.map(step => {
236
+ switch (step.status) {
237
+ case 'completed': return '█';
238
+ case 'running': return '▓';
239
+ case 'skipped': return '░';
240
+ case 'failed': return '✗';
241
+ default: return '░';
242
+ }
243
+ });
244
+ const pct = Math.round((getCompletedCount(execution) / execution.steps.length) * 100);
245
+ return `[${parts.join('')}] ${pct}%`;
246
+ }
247
+ function getCompletedCount(execution) {
248
+ return execution.steps.filter(s => s.status === 'completed' || s.status === 'skipped').length;
249
+ }
250
+ /**
251
+ * Get the current step's skill name.
252
+ */
253
+ function getCurrentSkill(execution) {
254
+ var _a;
255
+ if (execution.currentStepIndex >= execution.steps.length)
256
+ return null;
257
+ return ((_a = execution.steps[execution.currentStepIndex]) === null || _a === void 0 ? void 0 : _a.skill) || null;
258
+ }