codymaster 4.6.0 → 5.2.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 (161) hide show
  1. package/CHANGELOG.md +74 -8
  2. package/README.md +192 -95
  3. package/dist/advisory-handoff.js +89 -0
  4. package/dist/advisory-report.js +105 -0
  5. package/dist/browse-server.js +251 -0
  6. package/dist/cli/command-registry.js +34 -0
  7. package/dist/cli/commands/agent.js +120 -0
  8. package/dist/cli/commands/bench.js +69 -0
  9. package/dist/cli/commands/brain.js +108 -0
  10. package/dist/cli/commands/dashboard.js +93 -0
  11. package/dist/cli/commands/design-studio.js +111 -0
  12. package/dist/cli/commands/distro.js +25 -0
  13. package/dist/cli/commands/engineering.js +596 -0
  14. package/dist/cli/commands/evolve.js +123 -0
  15. package/dist/cli/commands/mcp-serve.js +104 -0
  16. package/dist/cli/commands/project.js +324 -0
  17. package/dist/cli/commands/skill-chain.js +269 -0
  18. package/dist/cli/commands/system.js +89 -0
  19. package/dist/cli/commands/task.js +254 -0
  20. package/dist/cli/update-check.js +83 -0
  21. package/dist/cm-config.js +92 -0
  22. package/dist/cm-suggest.js +77 -0
  23. package/dist/codybench/judges/automated.js +31 -0
  24. package/dist/codybench/runners/claude-code.js +32 -0
  25. package/dist/codybench/suites/memory-retention.js +85 -0
  26. package/dist/codybench/suites/tdd-regression.js +35 -0
  27. package/dist/codybench/suites/token-efficiency.js +55 -0
  28. package/dist/codybench/types.js +2 -0
  29. package/dist/context-db.js +157 -0
  30. package/dist/continuity.js +2 -6
  31. package/dist/distro-validate.js +54 -0
  32. package/dist/execution-analyzer.js +138 -0
  33. package/dist/guardian-core.js +74 -0
  34. package/dist/index.js +36 -2759
  35. package/dist/indexer/skills-lib.js +533 -0
  36. package/dist/indexer/skills-map.js +1374 -0
  37. package/dist/indexer/skills.js +16 -0
  38. package/dist/learning-promoter.js +246 -0
  39. package/dist/mcp-context-server.js +289 -1
  40. package/dist/mcp-skills-tools.js +81 -0
  41. package/dist/retro-summary.js +70 -0
  42. package/dist/second-opinion-providers.js +79 -0
  43. package/dist/skill-chain.js +63 -1
  44. package/dist/skill-evolver.js +456 -0
  45. package/dist/skill-execution-cache.js +254 -0
  46. package/dist/smart-brain-router.js +184 -0
  47. package/dist/sprint-pipeline.js +228 -0
  48. package/dist/storage-backend.js +14 -67
  49. package/dist/token-budget.js +88 -0
  50. package/dist/utils/cli-utils.js +76 -0
  51. package/dist/utils/skill-utils.js +32 -0
  52. package/package.json +17 -7
  53. package/scripts/build-skills.mjs +51 -0
  54. package/scripts/gate-0-repo-hygiene.js +75 -0
  55. package/scripts/postinstall.js +34 -28
  56. package/scripts/security-scan.js +1 -1
  57. package/scripts/validate-skills.mjs +42 -0
  58. package/skills/CLAUDE.md +2 -7
  59. package/skills/_shared/helpers.md +2 -8
  60. package/skills/cm-ads-tracker/SKILL.md +3 -6
  61. package/skills/cm-browse/SKILL.md +34 -0
  62. package/skills/cm-conductor-worktrees/SKILL.md +28 -0
  63. package/skills/cm-content-factory/SKILL.md +1 -1
  64. package/skills/cm-content-factory/landing/docs/content/changelog.md +36 -0
  65. package/skills/cm-content-factory/landing/docs/content/deployment.md +46 -0
  66. package/skills/cm-content-factory/landing/docs/content/execution-flow.md +67 -0
  67. package/skills/cm-content-factory/landing/docs/content/memory-system.md +38 -0
  68. package/skills/cm-content-factory/landing/docs/content/openspace.md +27 -0
  69. package/skills/cm-content-factory/landing/docs/content/use-cases.md +26 -0
  70. package/skills/cm-content-factory/landing/docs/content/v5-intro.md +28 -0
  71. package/skills/cm-content-factory/landing/docs/index.html +240 -0
  72. package/skills/cm-content-factory/landing/index.html +100 -100
  73. package/skills/cm-content-factory/landing/script.js +42 -0
  74. package/skills/cm-content-factory/landing/translations.js +400 -400
  75. package/skills/cm-continuity/SKILL.md +32 -33
  76. package/skills/cm-design-studio/SKILL.md +34 -0
  77. package/skills/cm-ecosystem-roadmap/SKILL.md +15 -0
  78. package/skills/cm-engineering-meta/SKILL.md +73 -0
  79. package/skills/cm-growth-hacking/SKILL.md +1 -12
  80. package/skills/cm-guardian-runtime/SKILL.md +26 -0
  81. package/skills/cm-mcp-engineering/SKILL.md +22 -0
  82. package/skills/cm-notebooklm/SKILL.md +1 -17
  83. package/skills/cm-post-deploy-canary/SKILL.md +22 -0
  84. package/skills/cm-project-bootstrap/SKILL.md +11 -0
  85. package/skills/cm-qa-visual-cli/SKILL.md +22 -0
  86. package/skills/cm-retro-cli/SKILL.md +23 -0
  87. package/skills/cm-second-opinion-cli/SKILL.md +23 -0
  88. package/skills/cm-secret-shield/SKILL.md +2 -2
  89. package/skills/cm-security-gate/SKILL.md +1 -0
  90. package/skills/cm-skill-chain/SKILL.md +25 -4
  91. package/skills/cm-skill-evolution/SKILL.md +83 -0
  92. package/skills/cm-skill-health/SKILL.md +83 -0
  93. package/skills/cm-skill-index/SKILL.md +11 -3
  94. package/skills/cm-skill-search/SKILL.md +49 -0
  95. package/skills/cm-skill-share/SKILL.md +58 -0
  96. package/skills/cm-sprint-bus/SKILL.md +33 -0
  97. package/skills/cm-start/SKILL.md +0 -10
  98. package/skills/cm-tdd/SKILL.md +59 -72
  99. package/skills/profiles/README.md +21 -0
  100. package/skills/profiles/core.txt +23 -0
  101. package/skills/profiles/design.txt +6 -0
  102. package/skills/profiles/full.txt +62 -0
  103. package/skills/profiles/growth.txt +10 -0
  104. package/skills/profiles/knowledge.txt +7 -0
  105. package/install.sh +0 -901
  106. package/scripts/test-gemini.js +0 -13
  107. package/skills/cm-frappe-agent/SKILL.md +0 -134
  108. package/skills/cm-frappe-agent/agents/doctype-architect.md +0 -596
  109. package/skills/cm-frappe-agent/agents/erpnext-customizer.md +0 -643
  110. package/skills/cm-frappe-agent/agents/frappe-backend.md +0 -814
  111. package/skills/cm-frappe-agent/agents/frappe-custom-frontend.md +0 -557
  112. package/skills/cm-frappe-agent/agents/frappe-debugger.md +0 -625
  113. package/skills/cm-frappe-agent/agents/frappe-fixer.md +0 -275
  114. package/skills/cm-frappe-agent/agents/frappe-frontend.md +0 -660
  115. package/skills/cm-frappe-agent/agents/frappe-installer.md +0 -158
  116. package/skills/cm-frappe-agent/agents/frappe-performance.md +0 -307
  117. package/skills/cm-frappe-agent/agents/frappe-planner.md +0 -419
  118. package/skills/cm-frappe-agent/agents/frappe-remote-ops.md +0 -153
  119. package/skills/cm-frappe-agent/agents/github-workflow.md +0 -286
  120. package/skills/cm-frappe-agent/commands/frappe-app.md +0 -351
  121. package/skills/cm-frappe-agent/commands/frappe-backend.md +0 -162
  122. package/skills/cm-frappe-agent/commands/frappe-bench.md +0 -254
  123. package/skills/cm-frappe-agent/commands/frappe-debug.md +0 -263
  124. package/skills/cm-frappe-agent/commands/frappe-doctype-create.md +0 -272
  125. package/skills/cm-frappe-agent/commands/frappe-doctype-field.md +0 -310
  126. package/skills/cm-frappe-agent/commands/frappe-erpnext.md +0 -210
  127. package/skills/cm-frappe-agent/commands/frappe-fix.md +0 -59
  128. package/skills/cm-frappe-agent/commands/frappe-frontend.md +0 -210
  129. package/skills/cm-frappe-agent/commands/frappe-fullstack.md +0 -243
  130. package/skills/cm-frappe-agent/commands/frappe-github.md +0 -57
  131. package/skills/cm-frappe-agent/commands/frappe-install.md +0 -52
  132. package/skills/cm-frappe-agent/commands/frappe-plan.md +0 -442
  133. package/skills/cm-frappe-agent/commands/frappe-remote.md +0 -58
  134. package/skills/cm-frappe-agent/commands/frappe-test.md +0 -356
  135. package/skills/cm-frappe-agent/docs/README.md +0 -51
  136. package/skills/cm-frappe-agent/docs/agents-catalog.md +0 -113
  137. package/skills/cm-frappe-agent/docs/architecture.md +0 -149
  138. package/skills/cm-frappe-agent/docs/commands-catalog.md +0 -82
  139. package/skills/cm-frappe-agent/docs/resources-catalog.md +0 -66
  140. package/skills/cm-frappe-agent/docs/sitemap-urls.txt +0 -52
  141. package/skills/cm-frappe-agent/docs/sitemap.md +0 -81
  142. package/skills/cm-frappe-agent/docs/sop/user-guide.md +0 -178
  143. package/skills/cm-frappe-agent/docs/sop/vibe-coding-guide.md +0 -122
  144. package/skills/cm-frappe-agent/resources/7-layer-architecture.md +0 -985
  145. package/skills/cm-frappe-agent/resources/bench_commands.md +0 -73
  146. package/skills/cm-frappe-agent/resources/code-patterns-guide.md +0 -948
  147. package/skills/cm-frappe-agent/resources/common_pitfalls.md +0 -266
  148. package/skills/cm-frappe-agent/resources/doctype-registry.md +0 -158
  149. package/skills/cm-frappe-agent/resources/installation-guide.md +0 -289
  150. package/skills/cm-frappe-agent/resources/rest-api-patterns.md +0 -182
  151. package/skills/cm-frappe-agent/resources/scaffold_checklist.md +0 -82
  152. package/skills/cm-frappe-agent/resources/upgrade_patterns.md +0 -113
  153. package/skills/cm-frappe-agent/resources/web-form-patterns.md +0 -252
  154. package/skills/cm-frappe-agent/skills/bench-commands/SKILL.md +0 -621
  155. package/skills/cm-frappe-agent/skills/client-scripts/SKILL.md +0 -642
  156. package/skills/cm-frappe-agent/skills/doctype-patterns/SKILL.md +0 -576
  157. package/skills/cm-frappe-agent/skills/frappe-api/SKILL.md +0 -740
  158. package/skills/cm-frappe-agent/skills/remote-operations/SKILL.md +0 -47
  159. package/skills/cm-frappe-agent/skills/server-scripts/SKILL.md +0 -608
  160. package/skills/cm-frappe-agent/skills/web-forms/SKILL.md +0 -46
  161. package/skills/frappe-app-builder.zip +0 -0
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateProjectSkillsIndex = generateProjectSkillsIndex;
4
+ const skills_lib_1 = require("./skills-lib");
5
+ /**
6
+ * Parses the project directory to detect the tech stack (using deterministic config file checks)
7
+ * and returns a miniaturized list of recommended AI skills.
8
+ */
9
+ function generateProjectSkillsIndex(projectDir) {
10
+ const { detected, isFrontend, combos } = (0, skills_lib_1.detectTechnologies)(projectDir);
11
+ const skills = (0, skills_lib_1.collectSkills)({ detected, isFrontend, combos });
12
+ return {
13
+ detectedTechnologies: detected.map((tech) => tech.name),
14
+ recommendedSkills: skills.map((s) => s.skill),
15
+ };
16
+ }
@@ -0,0 +1,246 @@
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.LearningPromoter = void 0;
7
+ exports.formatPromotionCandidates = formatPromotionCandidates;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const storage_backend_1 = require("./storage-backend");
11
+ // ─── Constants ──────────────────────────────────────────────────────────────
12
+ const MIN_REINFORCEMENT = 3; // Minimum times a learning must be reinforced
13
+ const MIN_PROMOTION_SCORE = 0.50; // Minimum score to qualify for promotion
14
+ const PROMOTION_LOG = '.cm/evolution/promotions.jsonl';
15
+ // ─── Learning Promoter ──────────────────────────────────────────────────────
16
+ // TRIZ #22 "Blessing in Disguise" — failures become reusable knowledge
17
+ /**
18
+ * LearningPromoter — Promotes mature learnings into reusable skills.
19
+ *
20
+ * When a learning has been reinforced enough times (appearing in multiple
21
+ * execution analyses or being manually confirmed), it graduates from
22
+ * ephemeral memory into a permanent skill entry.
23
+ *
24
+ * Flow:
25
+ * 1. Scan learnings in SQLite for candidates with high reinforcement
26
+ * 2. Score each candidate based on: reinforcement count, recency, category
27
+ * 3. Generate a minimal SKILL.md from the learning content
28
+ * 4. Save to skills/ directory
29
+ */
30
+ class LearningPromoter {
31
+ constructor(projectPath, backend) {
32
+ this.projectPath = projectPath;
33
+ this.backend = backend !== null && backend !== void 0 ? backend : (0, storage_backend_1.getBackend)(projectPath);
34
+ this.backend.initialize();
35
+ this.skillsDir = this.findSkillsDir();
36
+ }
37
+ /**
38
+ * Find learnings that qualify for promotion.
39
+ */
40
+ findCandidates(limit = 10) {
41
+ var _a;
42
+ // Query all learnings and count reinforcement (same what_failed pattern)
43
+ const allLearnings = this.backend.queryLearnings('', undefined, 200);
44
+ const patternCounts = new Map();
45
+ for (const learning of allLearnings) {
46
+ const pattern = this.normalizePattern(learning.what_failed);
47
+ const existing = (_a = patternCounts.get(pattern)) !== null && _a !== void 0 ? _a : { count: 0, learnings: [] };
48
+ existing.count++;
49
+ existing.learnings.push(learning);
50
+ patternCounts.set(pattern, existing);
51
+ }
52
+ const candidates = [];
53
+ for (const [_pattern, { count, learnings }] of patternCounts) {
54
+ if (count < MIN_REINFORCEMENT)
55
+ continue;
56
+ // Use the most recent learning as the representative
57
+ const representative = learnings.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())[0];
58
+ const score = this.calculateScore(count, representative);
59
+ if (score >= MIN_PROMOTION_SCORE) {
60
+ candidates.push({
61
+ learning: representative,
62
+ reinforcementCount: count,
63
+ score,
64
+ reason: `Reinforced ${count}x, score ${(score * 100).toFixed(0)}%`,
65
+ });
66
+ }
67
+ }
68
+ return candidates
69
+ .sort((a, b) => b.score - a.score)
70
+ .slice(0, limit);
71
+ }
72
+ /**
73
+ * Promote a specific learning to a skill.
74
+ */
75
+ promote(learningId) {
76
+ const learning = this.backend.getLearningById(learningId);
77
+ if (!learning) {
78
+ return {
79
+ promoted: false,
80
+ skillName: '',
81
+ skillPath: '',
82
+ learningId,
83
+ reason: `Learning ${learningId} not found.`,
84
+ };
85
+ }
86
+ // Generate skill name from the learning content
87
+ const skillName = this.generateSkillName(learning);
88
+ const skillDir = path_1.default.join(this.skillsDir, skillName);
89
+ if (fs_1.default.existsSync(skillDir)) {
90
+ return {
91
+ promoted: false,
92
+ skillName,
93
+ skillPath: skillDir,
94
+ learningId,
95
+ reason: `Skill ${skillName} already exists.`,
96
+ };
97
+ }
98
+ // Generate the SKILL.md content
99
+ const skillContent = this.generateSkillContent(learning, skillName);
100
+ // Create the skill
101
+ fs_1.default.mkdirSync(skillDir, { recursive: true });
102
+ const skillPath = path_1.default.join(skillDir, 'SKILL.md');
103
+ fs_1.default.writeFileSync(skillPath, skillContent, 'utf-8');
104
+ // Log the promotion
105
+ this.logPromotion(learningId, skillName, skillPath);
106
+ return {
107
+ promoted: true,
108
+ skillName,
109
+ skillPath,
110
+ learningId,
111
+ reason: `Learning promoted to skill: ${skillName}`,
112
+ };
113
+ }
114
+ /**
115
+ * Auto-promote: find candidates and promote the top one.
116
+ */
117
+ autoPromote() {
118
+ const candidates = this.findCandidates(1);
119
+ if (candidates.length === 0)
120
+ return null;
121
+ return this.promote(candidates[0].learning.id);
122
+ }
123
+ /**
124
+ * Get promotion history.
125
+ */
126
+ getPromotionHistory(limit = 20) {
127
+ const logPath = path_1.default.join(this.projectPath, PROMOTION_LOG);
128
+ if (!fs_1.default.existsSync(logPath))
129
+ return [];
130
+ const lines = fs_1.default.readFileSync(logPath, 'utf-8').trim().split('\n').filter(Boolean);
131
+ const entries = [];
132
+ for (const line of lines) {
133
+ try {
134
+ entries.push(JSON.parse(line));
135
+ }
136
+ catch ( /* skip */_a) { /* skip */ }
137
+ }
138
+ return entries.slice(-limit).reverse();
139
+ }
140
+ // ─── Private Helpers ────────────────────────────────────────────────────
141
+ findSkillsDir() {
142
+ const candidates = [
143
+ path_1.default.join(this.projectPath, 'skills'),
144
+ path_1.default.join(this.projectPath, '.agent', 'skills'),
145
+ ];
146
+ for (const dir of candidates) {
147
+ if (fs_1.default.existsSync(dir))
148
+ return dir;
149
+ }
150
+ return path_1.default.join(this.projectPath, 'skills');
151
+ }
152
+ normalizePattern(text) {
153
+ return text
154
+ .toLowerCase()
155
+ .replace(/[^\w\s]/g, '')
156
+ .replace(/\s+/g, ' ')
157
+ .trim()
158
+ .split(' ')
159
+ .sort()
160
+ .join(' ');
161
+ }
162
+ calculateScore(reinforcementCount, learning) {
163
+ // Reinforcement factor (0-0.5): more reinforcement = higher score
164
+ const reinforcementFactor = Math.min(0.5, reinforcementCount / 10);
165
+ // Recency factor (0-0.3): newer learnings score higher
166
+ const daysSince = (Date.now() - new Date(learning.created_at).getTime()) / (1000 * 60 * 60 * 24);
167
+ const recencyFactor = Math.max(0, 0.3 - (daysSince / 365) * 0.3);
168
+ // Content quality factor (0-0.2): longer, more detailed = better
169
+ const contentLength = (learning.what_failed.length + learning.how_to_prevent.length);
170
+ const qualityFactor = Math.min(0.2, contentLength / 500 * 0.2);
171
+ return reinforcementFactor + recencyFactor + qualityFactor;
172
+ }
173
+ generateSkillName(learning) {
174
+ const words = learning.what_failed
175
+ .toLowerCase()
176
+ .replace(/[^\w\s]/g, '')
177
+ .split(/\s+/)
178
+ .filter(w => w.length > 3)
179
+ .slice(0, 3);
180
+ const base = words.length > 0 ? words.join('-') : 'promoted';
181
+ return `cm-learned-${base}`;
182
+ }
183
+ generateSkillContent(learning, skillName) {
184
+ return [
185
+ '---',
186
+ `name: ${skillName}`,
187
+ `description: Auto-promoted from reinforced learning`,
188
+ '---',
189
+ '',
190
+ `# ${skillName}`,
191
+ '',
192
+ `> 🎓 Auto-promoted from learning on ${new Date().toISOString().split('T')[0]}`,
193
+ `> Original module: ${learning.module}`,
194
+ `> Agent: ${learning.agent}`,
195
+ '',
196
+ '## Problem Pattern',
197
+ '',
198
+ learning.what_failed,
199
+ '',
200
+ '## Root Cause',
201
+ '',
202
+ learning.why_failed,
203
+ '',
204
+ '## Prevention / Solution',
205
+ '',
206
+ learning.how_to_prevent,
207
+ '',
208
+ '## When to Apply',
209
+ '',
210
+ `Apply this skill when encountering patterns similar to: "${learning.what_failed.slice(0, 100)}"`,
211
+ '',
212
+ '## Steps',
213
+ '',
214
+ `1. Recognize the problem pattern described above`,
215
+ `2. Apply the prevention strategy: ${learning.how_to_prevent.slice(0, 100)}`,
216
+ `3. Verify the fix resolves the root cause`,
217
+ '',
218
+ ].join('\n');
219
+ }
220
+ logPromotion(learningId, skillName, skillPath) {
221
+ const logPath = path_1.default.join(this.projectPath, PROMOTION_LOG);
222
+ const dir = path_1.default.dirname(logPath);
223
+ if (!fs_1.default.existsSync(dir))
224
+ fs_1.default.mkdirSync(dir, { recursive: true });
225
+ const entry = { learningId, skillName, skillPath, promotedAt: new Date().toISOString() };
226
+ fs_1.default.appendFileSync(logPath, JSON.stringify(entry) + '\n');
227
+ }
228
+ }
229
+ exports.LearningPromoter = LearningPromoter;
230
+ // ─── Display Helpers ─────────────────────────────────────────────────────────
231
+ function formatPromotionCandidates(candidates) {
232
+ if (candidates.length === 0)
233
+ return 'No learnings qualify for promotion yet. Need ≥3 reinforcements.';
234
+ const lines = [
235
+ '🎓 Learning → Skill Promotion Candidates',
236
+ '─'.repeat(70),
237
+ `${'Score'.padEnd(8)} ${'Reinf'.padEnd(8)} Pattern`,
238
+ '─'.repeat(70),
239
+ ];
240
+ for (const c of candidates) {
241
+ const score = (c.score * 100).toFixed(0) + '%';
242
+ const pattern = c.learning.what_failed.slice(0, 50);
243
+ lines.push(`${score.padEnd(8)} ${(c.reinforcementCount + 'x').padEnd(8)} ${pattern}`);
244
+ }
245
+ return lines.join('\n');
246
+ }
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * CodyMaster MCP Context Server
5
5
  *
6
- * Exposes 7 tools over JSON-RPC 2.0 / stdio (Content-Length framing):
6
+ * Exposes 18 tools over JSON-RPC 2.0 / stdio (Content-Length framing):
7
7
  * cm_query — FTS5 search across learnings + decisions
8
8
  * cm_resolve — resolve a cm:// URI at L0/L1/L2
9
9
  * cm_bus_read — read context bus state
@@ -11,6 +11,8 @@
11
11
  * cm_budget_check — check token budget for a category
12
12
  * cm_memory_decay — TTL cleanup for learnings
13
13
  * cm_index_refresh — regenerate L0 indexes
14
+ * cm_advisory_report / cm_advisory_metrics / cm_advisory_handoff — advisory loop JSON surfaces
15
+ * cm_plan / cm_review / cm_qa / cm_deploy / cm_search / cm_memory_query — engineering kit bridge
14
16
  *
15
17
  * Usage (stdio MCP):
16
18
  * node dist/mcp-context-server.js --project /path/to/project
@@ -38,12 +40,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
40
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
41
  };
40
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.cmAdvisoryReport = cmAdvisoryReport;
44
+ exports.cmAdvisoryMetrics = cmAdvisoryMetrics;
45
+ exports.cmAdvisoryHandoff = cmAdvisoryHandoff;
41
46
  const path_1 = __importDefault(require("path"));
42
47
  const context_db_1 = require("./context-db");
43
48
  const uri_resolver_1 = require("./uri-resolver");
44
49
  const context_bus_1 = require("./context-bus");
45
50
  const token_budget_1 = require("./token-budget");
46
51
  const l0_indexer_1 = require("./l0-indexer");
52
+ const mcp_skills_tools_1 = require("./mcp-skills-tools");
53
+ const storage_backend_1 = require("./storage-backend");
54
+ const advisory_report_1 = require("./advisory-report");
55
+ const advisory_handoff_1 = require("./advisory-handoff");
47
56
  // ─── Config ──────────────────────────────────────────────────────────────────
48
57
  const SERVER_NAME = 'cm-context';
49
58
  const SERVER_VERSION = '1.0.0';
@@ -130,6 +139,84 @@ function cmBudgetCheck(args) {
130
139
  suggestion: check.suggestion,
131
140
  };
132
141
  }
142
+ function autoDetectCategory(content) {
143
+ const c = content.toLowerCase();
144
+ if (/\b(decided|architecture|we chose|design decision|chose to)\b/.test(c))
145
+ return 'arch_decision';
146
+ if (/\b(bug|fixed|caused by|root cause|crash)\b/.test(c))
147
+ return 'bug_fix';
148
+ if (/\b(prefer|always use|never use|avoid|convention|standard)\b/.test(c))
149
+ return 'user_pref';
150
+ if (/\b(function|pattern|approach|method|implementation)\b/.test(c))
151
+ return 'code_pattern';
152
+ return 'context';
153
+ }
154
+ function cmMemoryWrite(args) {
155
+ var _a;
156
+ const { content, scope = 'project', category, ttl_days, importance = 'medium' } = args;
157
+ if (!(content === null || content === void 0 ? void 0 : content.trim()))
158
+ throw new Error('content is required');
159
+ const detectedCategory = category || autoDetectCategory(content);
160
+ const defaultTtl = { session: 30, project: 90, global: 365 };
161
+ const ttl = (_a = ttl_days !== null && ttl_days !== void 0 ? ttl_days : defaultTtl[scope]) !== null && _a !== void 0 ? _a : 90;
162
+ const now = new Date().toISOString();
163
+ const id = `nli-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`;
164
+ const dbPath = (0, context_db_1.getDbPath)(PROJECT_PATH);
165
+ (0, context_db_1.insertLearning)(dbPath, {
166
+ id,
167
+ what_failed: content,
168
+ why_failed: detectedCategory,
169
+ how_to_prevent: `importance:${importance}`,
170
+ scope,
171
+ ttl,
172
+ reinforce_count: 0,
173
+ status: 'active',
174
+ created_at: now,
175
+ updated_at: now,
176
+ agent: 'cm_natural',
177
+ });
178
+ return { ok: true, id, content, category: detectedCategory, scope, ttl_days: ttl, importance };
179
+ }
180
+ const NLI_PATTERNS = [
181
+ { pattern: /\b(remember|save|note)\s+that\s+/i, action: 'write', scope: 'project' },
182
+ { pattern: /\b(remember|save)\s+this[:\s]/i, action: 'write', scope: 'project' },
183
+ { pattern: /\bimportant[:\s]+/i, action: 'write', scope: 'project', importance: 'high' },
184
+ { pattern: /\b(forget|remove|ignore)\s+(about\s+)?/i, action: 'decay' },
185
+ { pattern: /\bwhat\s+did\s+we\s+(learn|know)\b/i, action: 'query' },
186
+ { pattern: /\bwhat\s+do\s+we\s+know\b/i, action: 'query' },
187
+ { pattern: /\blessons?\s+learned\b/i, action: 'query' },
188
+ { pattern: /\b(search|find|look\s+up)\b/i, action: 'query' },
189
+ ];
190
+ function cmNatural(args) {
191
+ var _a, _b, _c;
192
+ const { text } = args;
193
+ if (!(text === null || text === void 0 ? void 0 : text.trim()))
194
+ throw new Error('text is required');
195
+ for (const rule of NLI_PATTERNS) {
196
+ const match = text.match(rule.pattern);
197
+ if (!match)
198
+ continue;
199
+ const extracted = text.slice(((_a = match.index) !== null && _a !== void 0 ? _a : 0) + match[0].length).trim();
200
+ if (rule.action === 'write') {
201
+ const result = cmMemoryWrite({
202
+ content: extracted || text,
203
+ scope: (_b = rule.scope) !== null && _b !== void 0 ? _b : 'project',
204
+ importance: (_c = rule.importance) !== null && _c !== void 0 ? _c : 'medium',
205
+ });
206
+ return Object.assign(Object.assign({}, result), { matched_pattern: rule.pattern.source, routed_to: 'cm_memory_write' });
207
+ }
208
+ if (rule.action === 'decay') {
209
+ const result = cmMemoryDecay({ dry_run: false });
210
+ return Object.assign(Object.assign({}, result), { matched_pattern: rule.pattern.source, routed_to: 'cm_memory_decay' });
211
+ }
212
+ // query / search
213
+ const result = cmQuery({ query: extracted || text, scope: 'all', limit: 10 });
214
+ return Object.assign(Object.assign({}, result), { matched_pattern: rule.pattern.source, routed_to: 'cm_query' });
215
+ }
216
+ // No pattern matched — default to search
217
+ const result = cmQuery({ query: text, scope: 'all', limit: 10 });
218
+ return Object.assign(Object.assign({}, result), { matched_pattern: null, routed_to: 'cm_query (default)' });
219
+ }
133
220
  function cmMemoryDecay(args) {
134
221
  const { dry_run = false } = args;
135
222
  const dbPath = (0, context_db_1.getDbPath)(PROJECT_PATH);
@@ -186,6 +273,55 @@ function cmIndexRefresh(args) {
186
273
  }
187
274
  throw new Error(`Unknown target: ${target}. Valid: learnings, skeleton, all`);
188
275
  }
276
+ function cmAdvisoryReport(args) {
277
+ var _a;
278
+ const backend = (0, storage_backend_1.getBackend)(PROJECT_PATH);
279
+ backend.initialize();
280
+ try {
281
+ const limit = Math.max(1, (_a = args.limit) !== null && _a !== void 0 ? _a : 10);
282
+ const analyses = (0, advisory_report_1.buildAdvisoryReportData)(backend, { limit });
283
+ return {
284
+ count: analyses.length,
285
+ analyses,
286
+ generated_at: new Date().toISOString(),
287
+ };
288
+ }
289
+ finally {
290
+ backend.close();
291
+ }
292
+ }
293
+ function cmAdvisoryMetrics(args) {
294
+ var _a;
295
+ const backend = (0, storage_backend_1.getBackend)(PROJECT_PATH);
296
+ backend.initialize();
297
+ try {
298
+ const limit = Math.max(1, (_a = args.limit) !== null && _a !== void 0 ? _a : 10);
299
+ const metrics = (0, advisory_report_1.buildAdvisoryMetricsData)(backend, { limit });
300
+ return {
301
+ count: metrics.length,
302
+ metrics,
303
+ generated_at: new Date().toISOString(),
304
+ };
305
+ }
306
+ finally {
307
+ backend.close();
308
+ }
309
+ }
310
+ function cmAdvisoryHandoff(args) {
311
+ const backend = (0, storage_backend_1.getBackend)(PROJECT_PATH);
312
+ backend.initialize();
313
+ try {
314
+ return (0, advisory_handoff_1.buildAdvisoryHandoff)(backend, {
315
+ consumer: args.consumer,
316
+ analysisId: args.analysis_id,
317
+ skill: args.skill,
318
+ searchLimit: args.limit,
319
+ });
320
+ }
321
+ finally {
322
+ backend.close();
323
+ }
324
+ }
189
325
  // ─── Tool Registry ─────────────────────────────────────────────────────────────
190
326
  const TOOLS = [
191
327
  {
@@ -295,6 +431,136 @@ const TOOLS = [
295
431
  },
296
432
  },
297
433
  },
434
+ {
435
+ name: 'cm_advisory_report',
436
+ description: 'Return recent advisory analyses as structured JSON for agent consumption.',
437
+ inputSchema: {
438
+ type: 'object',
439
+ properties: {
440
+ limit: { type: 'number', description: 'Max analyses to return (default: 10)' },
441
+ },
442
+ },
443
+ },
444
+ {
445
+ name: 'cm_advisory_metrics',
446
+ description: 'Return aggregated skill metrics and quality weights as structured JSON.',
447
+ inputSchema: {
448
+ type: 'object',
449
+ properties: {
450
+ limit: { type: 'number', description: 'Max skills to return (default: 10)' },
451
+ },
452
+ },
453
+ },
454
+ {
455
+ name: 'cm_advisory_handoff',
456
+ description: 'Build a structured advisory handoff for cm-skill-health or cm-skill-evolution.',
457
+ inputSchema: {
458
+ type: 'object',
459
+ properties: {
460
+ consumer: {
461
+ type: 'string',
462
+ enum: ['cm-skill-health', 'cm-skill-evolution'],
463
+ description: 'Which self-healing skill should consume the handoff',
464
+ },
465
+ analysis_id: {
466
+ type: 'string',
467
+ description: 'Optional analysis id prefix (defaults to latest advisory analysis)',
468
+ },
469
+ skill: {
470
+ type: 'string',
471
+ description: 'Optional skill override when the target skill should be forced',
472
+ },
473
+ limit: {
474
+ type: 'number',
475
+ description: 'How many recent analyses to search while resolving analysis_id (default: 50)',
476
+ },
477
+ },
478
+ required: ['consumer'],
479
+ },
480
+ },
481
+ {
482
+ name: 'cm_plan',
483
+ description: 'Sprint + context bus snapshot: pipeline state, next skill hint, artifact paths.',
484
+ inputSchema: { type: 'object', properties: {} },
485
+ },
486
+ {
487
+ name: 'cm_review',
488
+ description: 'Read sprint review artifact preview if present; points to cm-code-review workflow.',
489
+ inputSchema: { type: 'object', properties: {} },
490
+ },
491
+ {
492
+ name: 'cm_qa',
493
+ description: 'QA hints: browse daemon, visual QA CLI, quality gates.',
494
+ inputSchema: { type: 'object', properties: {} },
495
+ },
496
+ {
497
+ name: 'cm_deploy',
498
+ description: 'Deploy workflow hints (cm-safe-deploy, canary).',
499
+ inputSchema: { type: 'object', properties: {} },
500
+ },
501
+ {
502
+ name: 'cm_search',
503
+ description: 'Search learnings + decisions (same backing store as cm_query).',
504
+ inputSchema: {
505
+ type: 'object',
506
+ properties: {
507
+ query: { type: 'string' },
508
+ scope: { type: 'string', enum: ['learnings', 'decisions', 'all'] },
509
+ limit: { type: 'number' },
510
+ },
511
+ required: ['query'],
512
+ },
513
+ },
514
+ {
515
+ name: 'cm_memory_query',
516
+ description: 'Alias-style memory search across learnings and decisions.',
517
+ inputSchema: {
518
+ type: 'object',
519
+ properties: {
520
+ query: { type: 'string' },
521
+ limit: { type: 'number' },
522
+ },
523
+ required: ['query'],
524
+ },
525
+ },
526
+ {
527
+ name: 'cm_memory_write',
528
+ description: 'Write a new memory/learning to persistent storage. Use to save knowledge, decisions, preferences, or patterns for future sessions.',
529
+ inputSchema: {
530
+ type: 'object',
531
+ properties: {
532
+ content: { type: 'string', description: 'What to remember (the memory content)' },
533
+ scope: {
534
+ type: 'string',
535
+ enum: ['session', 'project', 'global'],
536
+ description: 'Memory scope: session=30d, project=90d, global=365d (default: project)',
537
+ },
538
+ category: {
539
+ type: 'string',
540
+ enum: ['code_pattern', 'arch_decision', 'bug_fix', 'user_pref', 'context'],
541
+ description: 'Category (auto-detected from content if omitted)',
542
+ },
543
+ ttl_days: { type: 'number', description: 'Override TTL in days' },
544
+ importance: {
545
+ type: 'string',
546
+ enum: ['low', 'medium', 'high'],
547
+ description: 'Importance level (default: medium)',
548
+ },
549
+ },
550
+ required: ['content'],
551
+ },
552
+ },
553
+ {
554
+ name: 'cm_natural',
555
+ description: 'Natural language memory interface. Understands "remember that...", "forget about...", "what did we learn about...", "find...". Routes to appropriate memory operation automatically.',
556
+ inputSchema: {
557
+ type: 'object',
558
+ properties: {
559
+ text: { type: 'string', description: 'Freeform natural language instruction or question' },
560
+ },
561
+ required: ['text'],
562
+ },
563
+ },
298
564
  ];
299
565
  // ─── MCP stdio protocol (JSON-RPC 2.0, Content-Length framing) ───────────────
300
566
  function sendMessage(msg) {
@@ -344,6 +610,28 @@ function handleRequest(msg) {
344
610
  result = cmMemoryDecay(a);
345
611
  else if (name === 'cm_index_refresh')
346
612
  result = cmIndexRefresh(a);
613
+ else if (name === 'cm_advisory_report')
614
+ result = cmAdvisoryReport(a);
615
+ else if (name === 'cm_advisory_metrics')
616
+ result = cmAdvisoryMetrics(a);
617
+ else if (name === 'cm_advisory_handoff')
618
+ result = cmAdvisoryHandoff(a);
619
+ else if (name === 'cm_plan')
620
+ result = (0, mcp_skills_tools_1.cmPlanTool)(PROJECT_PATH);
621
+ else if (name === 'cm_review')
622
+ result = (0, mcp_skills_tools_1.cmReviewTool)(PROJECT_PATH);
623
+ else if (name === 'cm_qa')
624
+ result = (0, mcp_skills_tools_1.cmQaTool)(PROJECT_PATH);
625
+ else if (name === 'cm_deploy')
626
+ result = (0, mcp_skills_tools_1.cmDeployTool)(PROJECT_PATH);
627
+ else if (name === 'cm_search')
628
+ result = (0, mcp_skills_tools_1.cmSearchTool)(PROJECT_PATH, a);
629
+ else if (name === 'cm_memory_query')
630
+ result = (0, mcp_skills_tools_1.cmMemoryQueryTool)(PROJECT_PATH, a);
631
+ else if (name === 'cm_memory_write')
632
+ result = cmMemoryWrite(a);
633
+ else if (name === 'cm_natural')
634
+ result = cmNatural(a);
347
635
  else
348
636
  throw new Error(`Unknown tool: ${name}`);
349
637
  respond(id, {
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Extra MCP tool handlers: plan/review/qa/deploy/search — bridge to sprint + memory.
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.cmPlanTool = cmPlanTool;
10
+ exports.cmReviewTool = cmReviewTool;
11
+ exports.cmQaTool = cmQaTool;
12
+ exports.cmDeployTool = cmDeployTool;
13
+ exports.cmSearchTool = cmSearchTool;
14
+ exports.cmMemoryQueryTool = cmMemoryQueryTool;
15
+ const fs_1 = __importDefault(require("fs"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const context_bus_1 = require("./context-bus");
18
+ const sprint_pipeline_1 = require("./sprint-pipeline");
19
+ const context_db_1 = require("./context-db");
20
+ function cmPlanTool(projectPath) {
21
+ const sprint = (0, sprint_pipeline_1.readSprintState)(projectPath);
22
+ const bus = (0, context_bus_1.readBus)(projectPath);
23
+ const preview = (0, sprint_pipeline_1.sprintArtifactPreviewFromDisk)(projectPath);
24
+ return {
25
+ sprint_active: !!sprint,
26
+ sprint: sprint !== null && sprint !== void 0 ? sprint : null,
27
+ context_bus: bus,
28
+ default_pipeline: sprint_pipeline_1.SPRINT_STEPS,
29
+ next_skill_hint: sprint
30
+ ? sprint.current_index >= sprint.pipeline.length
31
+ ? '(sprint complete — run cm-retro)'
32
+ : (0, sprint_pipeline_1.skillMappingForStep)(sprint.pipeline[sprint.current_index])
33
+ : 'cm-planning',
34
+ artifact_paths: preview.artifacts,
35
+ };
36
+ }
37
+ function cmReviewTool(projectPath) {
38
+ const artDir = path_1.default.join(projectPath, '.cm', 'sprint', 'artifacts', 'review.md');
39
+ let review = '';
40
+ if (fs_1.default.existsSync(artDir))
41
+ review = fs_1.default.readFileSync(artDir, 'utf8');
42
+ return {
43
+ review_artifact: artDir,
44
+ has_content: review.length > 0,
45
+ preview: review.slice(0, 4000),
46
+ hint: 'Use cm-code-review skill for full checklist; paste diff + requirements.',
47
+ };
48
+ }
49
+ function cmQaTool(projectPath) {
50
+ return {
51
+ browse_daemon: 'Run: cm browse start --token <secret> then POST /session/start',
52
+ visual: 'cm qa-visual --url http://localhost:3000',
53
+ gates: ['cm-quality-gate', 'cm-test-gate'],
54
+ };
55
+ }
56
+ function cmDeployTool(projectPath) {
57
+ return {
58
+ hint: 'Use cm-safe-deploy skill; after ship run cm canary --url <prod>',
59
+ project: projectPath,
60
+ };
61
+ }
62
+ function cmSearchTool(projectPath, args) {
63
+ const { query, scope = 'all', limit = 10 } = args;
64
+ const dbPath = (0, context_db_1.getDbPath)(projectPath);
65
+ (0, context_db_1.openDb)(dbPath);
66
+ const results = [];
67
+ if (scope === 'all' || scope === 'learnings') {
68
+ for (const l of (0, context_db_1.queryLearnings)(dbPath, query, undefined, limit)) {
69
+ results.push(Object.assign({ type: 'learning' }, l));
70
+ }
71
+ }
72
+ if (scope === 'all' || scope === 'decisions') {
73
+ for (const d of (0, context_db_1.queryDecisions)(dbPath, query, limit)) {
74
+ results.push(Object.assign({ type: 'decision' }, d));
75
+ }
76
+ }
77
+ return { query, scope, count: results.length, results };
78
+ }
79
+ function cmMemoryQueryTool(projectPath, args) {
80
+ return cmSearchTool(projectPath, Object.assign(Object.assign({}, args), { scope: 'all' }));
81
+ }