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,385 @@
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.getCmDir = getCmDir;
7
+ exports.ensureCmDir = ensureCmDir;
8
+ exports.readContinuityState = readContinuityState;
9
+ exports.writeContinuityMd = writeContinuityMd;
10
+ exports.addLearning = addLearning;
11
+ exports.getLearnings = getLearnings;
12
+ exports.deleteLearning = deleteLearning;
13
+ exports.addDecision = addDecision;
14
+ exports.getDecisions = getDecisions;
15
+ exports.deleteDecision = deleteDecision;
16
+ exports.getContinuityStatus = getContinuityStatus;
17
+ exports.resetContinuity = resetContinuity;
18
+ exports.hasCmDir = hasCmDir;
19
+ const fs_1 = __importDefault(require("fs"));
20
+ const path_1 = __importDefault(require("path"));
21
+ const crypto_1 = __importDefault(require("crypto"));
22
+ // ─── Constants ──────────────────────────────────────────────────────────────
23
+ const CM_DIR = '.cm';
24
+ const CONTINUITY_FILE = 'CONTINUITY.md';
25
+ const LEARNINGS_FILE = 'memory/learnings.json';
26
+ const DECISIONS_FILE = 'memory/decisions.json';
27
+ const CONFIG_FILE = 'config.yaml';
28
+ // ─── Directory Management ───────────────────────────────────────────────────
29
+ function getCmDir(projectPath) {
30
+ return path_1.default.join(projectPath, CM_DIR);
31
+ }
32
+ function ensureCmDir(projectPath) {
33
+ const cmDir = getCmDir(projectPath);
34
+ const memoryDir = path_1.default.join(cmDir, 'memory');
35
+ if (!fs_1.default.existsSync(cmDir)) {
36
+ fs_1.default.mkdirSync(cmDir, { recursive: true });
37
+ }
38
+ if (!fs_1.default.existsSync(memoryDir)) {
39
+ fs_1.default.mkdirSync(memoryDir, { recursive: true });
40
+ }
41
+ // Initialize files if they don't exist
42
+ const continuityPath = path_1.default.join(cmDir, CONTINUITY_FILE);
43
+ if (!fs_1.default.existsSync(continuityPath)) {
44
+ writeContinuityMd(projectPath, createDefaultState(path_1.default.basename(projectPath)));
45
+ }
46
+ const learningsPath = path_1.default.join(cmDir, LEARNINGS_FILE);
47
+ if (!fs_1.default.existsSync(learningsPath)) {
48
+ fs_1.default.writeFileSync(learningsPath, JSON.stringify([], null, 2));
49
+ }
50
+ const decisionsPath = path_1.default.join(cmDir, DECISIONS_FILE);
51
+ if (!fs_1.default.existsSync(decisionsPath)) {
52
+ fs_1.default.writeFileSync(decisionsPath, JSON.stringify([], null, 2));
53
+ }
54
+ const configPath = path_1.default.join(cmDir, CONFIG_FILE);
55
+ if (!fs_1.default.existsSync(configPath)) {
56
+ fs_1.default.writeFileSync(configPath, generateDefaultConfig());
57
+ }
58
+ // Add .cm to .gitignore if not already there
59
+ const gitignorePath = path_1.default.join(projectPath, '.gitignore');
60
+ if (fs_1.default.existsSync(gitignorePath)) {
61
+ const content = fs_1.default.readFileSync(gitignorePath, 'utf-8');
62
+ if (!content.includes('.cm/')) {
63
+ fs_1.default.appendFileSync(gitignorePath, '\n# CodyMaster working memory\n.cm/\n');
64
+ }
65
+ }
66
+ }
67
+ // ─── Default State ──────────────────────────────────────────────────────────
68
+ function createDefaultState(projectName) {
69
+ return {
70
+ lastUpdated: new Date().toISOString(),
71
+ currentPhase: 'idle',
72
+ currentIteration: 0,
73
+ project: projectName,
74
+ activeGoal: '',
75
+ currentTask: null,
76
+ justCompleted: [],
77
+ nextActions: [],
78
+ activeBlockers: [],
79
+ keyDecisions: [],
80
+ learnings: [],
81
+ workingContext: '',
82
+ filesModified: [],
83
+ };
84
+ }
85
+ function generateDefaultConfig() {
86
+ return `# CodyMaster Working Memory Configuration
87
+ # Inspired by Loki Mode (autonomi.dev)
88
+
89
+ rarv:
90
+ max_retries: 3 # Max retry per task before marking blocked
91
+ pre_act_attention: true # Enable goal alignment check before every action
92
+ self_correction: true # Enable self-correction loop on verify failure
93
+
94
+ memory:
95
+ max_learnings: 50 # Max learnings to keep in CONTINUITY.md (rotate to learnings.json)
96
+ max_just_completed: 5 # Max recent completions to show
97
+ max_decisions: 20 # Max decisions before archiving
98
+
99
+ quality:
100
+ velocity_quality_tracking: true # Track warnings/complexity over time
101
+ blind_review: false # Enable blind code review (Phase 2)
102
+ anti_sycophancy: false # Enable anti-sycophancy check (Phase 2)
103
+ `;
104
+ }
105
+ // ─── CONTINUITY.md Read/Write ───────────────────────────────────────────────
106
+ function readContinuityState(projectPath) {
107
+ const filePath = path_1.default.join(getCmDir(projectPath), CONTINUITY_FILE);
108
+ if (!fs_1.default.existsSync(filePath))
109
+ return null;
110
+ try {
111
+ const content = fs_1.default.readFileSync(filePath, 'utf-8');
112
+ return parseContinuityMd(content);
113
+ }
114
+ catch (_a) {
115
+ return null;
116
+ }
117
+ }
118
+ function parseContinuityMd(content) {
119
+ const state = createDefaultState('');
120
+ // Parse Last Updated
121
+ const updatedMatch = content.match(/Last Updated:\s*(.+)/);
122
+ if (updatedMatch)
123
+ state.lastUpdated = updatedMatch[1].trim();
124
+ // Parse Current Phase
125
+ const phaseMatch = content.match(/Current Phase:\s*(.+)/);
126
+ if (phaseMatch)
127
+ state.currentPhase = phaseMatch[1].trim();
128
+ // Parse Current Iteration
129
+ const iterMatch = content.match(/Current Iteration:\s*(\d+)/);
130
+ if (iterMatch)
131
+ state.currentIteration = parseInt(iterMatch[1]);
132
+ // Parse Project
133
+ const projMatch = content.match(/Project:\s*(.+)/);
134
+ if (projMatch)
135
+ state.project = projMatch[1].trim();
136
+ // Parse Active Goal
137
+ const goalSection = extractSection(content, 'Active Goal');
138
+ if (goalSection)
139
+ state.activeGoal = goalSection.trim();
140
+ // Parse Just Completed
141
+ const completedSection = extractSection(content, 'Just Completed');
142
+ if (completedSection) {
143
+ state.justCompleted = completedSection.split('\n')
144
+ .map(l => l.replace(/^[-*]\s*/, '').trim())
145
+ .filter(l => l.length > 0);
146
+ }
147
+ // Parse Next Actions
148
+ const nextSection = extractSection(content, 'Next Actions');
149
+ if (nextSection) {
150
+ state.nextActions = nextSection.split('\n')
151
+ .map(l => l.replace(/^\d+\.\s*/, '').trim())
152
+ .filter(l => l.length > 0);
153
+ }
154
+ // Parse Active Blockers
155
+ const blockersSection = extractSection(content, 'Active Blockers');
156
+ if (blockersSection) {
157
+ state.activeBlockers = blockersSection.split('\n')
158
+ .map(l => l.replace(/^[-*]\s*/, '').trim())
159
+ .filter(l => l.length > 0);
160
+ }
161
+ // Parse Working Context
162
+ const contextSection = extractSection(content, 'Working Context');
163
+ if (contextSection)
164
+ state.workingContext = contextSection.trim();
165
+ return state;
166
+ }
167
+ function extractSection(content, heading) {
168
+ const regex = new RegExp(`## ${heading}[^\\n]*\\n([\\s\\S]*?)(?=\\n## |$)`);
169
+ const match = content.match(regex);
170
+ return match ? match[1].trim() : null;
171
+ }
172
+ function writeContinuityMd(projectPath, state) {
173
+ const filePath = path_1.default.join(getCmDir(projectPath), CONTINUITY_FILE);
174
+ state.lastUpdated = new Date().toISOString();
175
+ const content = `# CodyMaster Working Memory
176
+ Last Updated: ${state.lastUpdated}
177
+ Current Phase: ${state.currentPhase}
178
+ Current Iteration: ${state.currentIteration}
179
+ Project: ${state.project}
180
+
181
+ ## Active Goal
182
+ ${state.activeGoal || '[No active goal set]'}
183
+
184
+ ## Current Task
185
+ ${state.currentTask
186
+ ? `- ID: ${state.currentTask.id}\n- Title: ${state.currentTask.title}\n- Status: ${state.currentTask.status}\n- Skill: ${state.currentTask.skill}\n- Started: ${state.currentTask.started}`
187
+ : '[No active task]'}
188
+
189
+ ## Just Completed
190
+ ${state.justCompleted.length > 0
191
+ ? state.justCompleted.map(c => `- ${c}`).join('\n')
192
+ : '- [Nothing yet]'}
193
+
194
+ ## Next Actions (Priority Order)
195
+ ${state.nextActions.length > 0
196
+ ? state.nextActions.map((a, i) => `${i + 1}. ${a}`).join('\n')
197
+ : '1. [No actions planned]'}
198
+
199
+ ## Active Blockers
200
+ ${state.activeBlockers.length > 0
201
+ ? state.activeBlockers.map(b => `- ${b}`).join('\n')
202
+ : '- [No blockers]'}
203
+
204
+ ## Key Decisions This Session
205
+ ${state.keyDecisions.length > 0
206
+ ? state.keyDecisions.map(d => `- ${d.decision}: ${d.rationale} — ${d.timestamp}`).join('\n')
207
+ : '- [No decisions recorded]'}
208
+
209
+ ## Mistakes & Learnings
210
+ ${state.learnings.length > 0
211
+ ? state.learnings.map(l => `
212
+ ### ${l.whatFailed}
213
+ - **What Failed:** ${l.whatFailed}
214
+ - **Why It Failed:** ${l.whyFailed}
215
+ - **How to Prevent:** ${l.howToPrevent}
216
+ - **Timestamp:** ${l.timestamp}
217
+ - **Agent:** ${l.agent}
218
+ - **Task:** ${l.taskId}
219
+ `).join('\n')
220
+ : '[No learnings yet — this is good!]'}
221
+
222
+ ## Working Context
223
+ ${state.workingContext || '[No additional context]'}
224
+
225
+ ## Files Currently Being Modified
226
+ ${state.filesModified.length > 0
227
+ ? state.filesModified.map(f => `- ${f.path}: ${f.change}`).join('\n')
228
+ : '- [No files being modified]'}
229
+ `;
230
+ fs_1.default.writeFileSync(filePath, content, 'utf-8');
231
+ }
232
+ // ─── Learnings Management ───────────────────────────────────────────────────
233
+ function addLearning(projectPath, learning) {
234
+ const fullLearning = Object.assign(Object.assign({}, learning), { id: crypto_1.default.randomUUID() });
235
+ // Add to CONTINUITY.md
236
+ const state = readContinuityState(projectPath);
237
+ if (state) {
238
+ state.learnings.push(fullLearning);
239
+ // Keep max 10 in CONTINUITY.md (rotate old to learnings.json)
240
+ if (state.learnings.length > 10) {
241
+ const archived = state.learnings.splice(0, state.learnings.length - 10);
242
+ archiveLearnings(projectPath, archived);
243
+ }
244
+ writeContinuityMd(projectPath, state);
245
+ }
246
+ // Also add to persistent learnings.json
247
+ const learningsPath = path_1.default.join(getCmDir(projectPath), LEARNINGS_FILE);
248
+ let learnings = [];
249
+ try {
250
+ learnings = JSON.parse(fs_1.default.readFileSync(learningsPath, 'utf-8'));
251
+ }
252
+ catch ( /* empty */_a) { /* empty */ }
253
+ learnings.push(fullLearning);
254
+ fs_1.default.writeFileSync(learningsPath, JSON.stringify(learnings, null, 2));
255
+ return fullLearning;
256
+ }
257
+ function archiveLearnings(projectPath, learnings) {
258
+ const learningsPath = path_1.default.join(getCmDir(projectPath), LEARNINGS_FILE);
259
+ let existing = [];
260
+ try {
261
+ existing = JSON.parse(fs_1.default.readFileSync(learningsPath, 'utf-8'));
262
+ }
263
+ catch ( /* empty */_a) { /* empty */ }
264
+ existing.push(...learnings);
265
+ // Keep max 200 archived learnings
266
+ if (existing.length > 200) {
267
+ existing = existing.slice(existing.length - 200);
268
+ }
269
+ fs_1.default.writeFileSync(learningsPath, JSON.stringify(existing, null, 2));
270
+ }
271
+ function getLearnings(projectPath) {
272
+ const learningsPath = path_1.default.join(getCmDir(projectPath), LEARNINGS_FILE);
273
+ try {
274
+ return JSON.parse(fs_1.default.readFileSync(learningsPath, 'utf-8'));
275
+ }
276
+ catch (_a) {
277
+ return [];
278
+ }
279
+ }
280
+ function deleteLearning(projectPath, learningId) {
281
+ const learningsPath = path_1.default.join(getCmDir(projectPath), LEARNINGS_FILE);
282
+ try {
283
+ const learnings = JSON.parse(fs_1.default.readFileSync(learningsPath, 'utf-8'));
284
+ const idx = learnings.findIndex(l => l.id === learningId);
285
+ if (idx === -1)
286
+ return false;
287
+ learnings.splice(idx, 1);
288
+ fs_1.default.writeFileSync(learningsPath, JSON.stringify(learnings, null, 2));
289
+ return true;
290
+ }
291
+ catch (_a) {
292
+ return false;
293
+ }
294
+ }
295
+ // ─── Decisions Management ───────────────────────────────────────────────────
296
+ function addDecision(projectPath, decision) {
297
+ const fullDecision = Object.assign(Object.assign({}, decision), { id: crypto_1.default.randomUUID() });
298
+ const decisionsPath = path_1.default.join(getCmDir(projectPath), DECISIONS_FILE);
299
+ let decisions = [];
300
+ try {
301
+ decisions = JSON.parse(fs_1.default.readFileSync(decisionsPath, 'utf-8'));
302
+ }
303
+ catch ( /* empty */_a) { /* empty */ }
304
+ decisions.push(fullDecision);
305
+ fs_1.default.writeFileSync(decisionsPath, JSON.stringify(decisions, null, 2));
306
+ // Also update CONTINUITY.md
307
+ const state = readContinuityState(projectPath);
308
+ if (state) {
309
+ state.keyDecisions.push(fullDecision);
310
+ if (state.keyDecisions.length > 20) {
311
+ state.keyDecisions = state.keyDecisions.slice(-20);
312
+ }
313
+ writeContinuityMd(projectPath, state);
314
+ }
315
+ return fullDecision;
316
+ }
317
+ function getDecisions(projectPath) {
318
+ const decisionsPath = path_1.default.join(getCmDir(projectPath), DECISIONS_FILE);
319
+ try {
320
+ return JSON.parse(fs_1.default.readFileSync(decisionsPath, 'utf-8'));
321
+ }
322
+ catch (_a) {
323
+ return [];
324
+ }
325
+ }
326
+ function deleteDecision(projectPath, decisionId) {
327
+ const decisionsPath = path_1.default.join(getCmDir(projectPath), DECISIONS_FILE);
328
+ try {
329
+ const decisions = JSON.parse(fs_1.default.readFileSync(decisionsPath, 'utf-8'));
330
+ const idx = decisions.findIndex(d => d.id === decisionId);
331
+ if (idx === -1)
332
+ return false;
333
+ decisions.splice(idx, 1);
334
+ fs_1.default.writeFileSync(decisionsPath, JSON.stringify(decisions, null, 2));
335
+ return true;
336
+ }
337
+ catch (_a) {
338
+ return false;
339
+ }
340
+ }
341
+ function getContinuityStatus(projectPath) {
342
+ var _a;
343
+ const cmDir = getCmDir(projectPath);
344
+ const initialized = fs_1.default.existsSync(path_1.default.join(cmDir, CONTINUITY_FILE));
345
+ if (!initialized) {
346
+ return {
347
+ initialized: false,
348
+ phase: 'not initialized',
349
+ iteration: 0,
350
+ project: path_1.default.basename(projectPath),
351
+ activeGoal: '',
352
+ currentTask: null,
353
+ completedCount: 0,
354
+ blockerCount: 0,
355
+ learningCount: 0,
356
+ decisionCount: 0,
357
+ lastUpdated: '',
358
+ };
359
+ }
360
+ const state = readContinuityState(projectPath);
361
+ const learnings = getLearnings(projectPath);
362
+ const decisions = getDecisions(projectPath);
363
+ return {
364
+ initialized: true,
365
+ phase: (state === null || state === void 0 ? void 0 : state.currentPhase) || 'idle',
366
+ iteration: (state === null || state === void 0 ? void 0 : state.currentIteration) || 0,
367
+ project: (state === null || state === void 0 ? void 0 : state.project) || path_1.default.basename(projectPath),
368
+ activeGoal: (state === null || state === void 0 ? void 0 : state.activeGoal) || '',
369
+ currentTask: ((_a = state === null || state === void 0 ? void 0 : state.currentTask) === null || _a === void 0 ? void 0 : _a.title) || null,
370
+ completedCount: (state === null || state === void 0 ? void 0 : state.justCompleted.length) || 0,
371
+ blockerCount: (state === null || state === void 0 ? void 0 : state.activeBlockers.length) || 0,
372
+ learningCount: learnings.length,
373
+ decisionCount: decisions.length,
374
+ lastUpdated: (state === null || state === void 0 ? void 0 : state.lastUpdated) || '',
375
+ };
376
+ }
377
+ // ─── Reset ──────────────────────────────────────────────────────────────────
378
+ function resetContinuity(projectPath) {
379
+ const state = createDefaultState(path_1.default.basename(projectPath));
380
+ writeContinuityMd(projectPath, state);
381
+ }
382
+ // ─── Has CM Directory ───────────────────────────────────────────────────────
383
+ function hasCmDir(projectPath) {
384
+ return fs_1.default.existsSync(getCmDir(projectPath));
385
+ }