monomind 1.18.13 → 1.18.15

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 (44) hide show
  1. package/.claude/commands/mastermind/_repeat.md +22 -3
  2. package/.claude/commands/mastermind/architect.md +1 -1
  3. package/.claude/commands/mastermind/autodev.md +1 -1
  4. package/.claude/commands/mastermind/build.md +1 -1
  5. package/.claude/commands/mastermind/code-review.md +1 -1
  6. package/.claude/commands/mastermind/debug.md +1 -1
  7. package/.claude/commands/mastermind/idea.md +1 -1
  8. package/.claude/commands/mastermind/improve.md +1 -1
  9. package/.claude/commands/mastermind/plan.md +1 -1
  10. package/.claude/commands/mastermind/research.md +1 -1
  11. package/.claude/commands/mastermind/review.md +12 -1
  12. package/.claude/commands/mastermind/runorg.md +1 -1
  13. package/.claude/commands/mastermind/taskdev.md +1 -1
  14. package/.claude/commands/mastermind/tdd.md +1 -1
  15. package/.claude/commands/mastermind/verify.md +1 -1
  16. package/.claude/helpers/graphify-freshen.cjs +16 -20
  17. package/.claude/helpers/handlers/route-handler.cjs +6 -9
  18. package/.claude/helpers/utils/monograph.cjs +37 -20
  19. package/.claude/skills/mastermind-skills/_repeat.md +29 -4
  20. package/.claude/skills/mastermind-skills/review.md +17 -6
  21. package/package.json +1 -1
  22. package/packages/@monomind/cli/.claude/commands/mastermind/_repeat.md +22 -3
  23. package/packages/@monomind/cli/.claude/commands/mastermind/architect.md +1 -1
  24. package/packages/@monomind/cli/.claude/commands/mastermind/autodev.md +1 -1
  25. package/packages/@monomind/cli/.claude/commands/mastermind/build.md +1 -1
  26. package/packages/@monomind/cli/.claude/commands/mastermind/code-review.md +1 -1
  27. package/packages/@monomind/cli/.claude/commands/mastermind/debug.md +1 -1
  28. package/packages/@monomind/cli/.claude/commands/mastermind/idea.md +1 -1
  29. package/packages/@monomind/cli/.claude/commands/mastermind/improve.md +1 -1
  30. package/packages/@monomind/cli/.claude/commands/mastermind/plan.md +1 -1
  31. package/packages/@monomind/cli/.claude/commands/mastermind/research.md +1 -1
  32. package/packages/@monomind/cli/.claude/commands/mastermind/review.md +12 -1
  33. package/packages/@monomind/cli/.claude/commands/mastermind/runorg.md +1 -1
  34. package/packages/@monomind/cli/.claude/commands/mastermind/taskdev.md +1 -1
  35. package/packages/@monomind/cli/.claude/commands/mastermind/tdd.md +1 -1
  36. package/packages/@monomind/cli/.claude/commands/mastermind/verify.md +1 -1
  37. package/packages/@monomind/cli/.claude/helpers/graphify-freshen.cjs +16 -20
  38. package/packages/@monomind/cli/.claude/helpers/handlers/route-handler.cjs +6 -9
  39. package/packages/@monomind/cli/.claude/helpers/utils/monograph.cjs +37 -20
  40. package/packages/@monomind/cli/.claude/skills/mastermind-skills/_repeat.md +29 -4
  41. package/packages/@monomind/cli/.claude/skills/mastermind-skills/review.md +17 -6
  42. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +29 -1
  43. package/packages/@monomind/cli/package.json +1 -1
  44. package/packages/@monomind/guidance/README.md +49 -1153
@@ -20,4 +20,4 @@ Invoke `Skill("mastermind-skills:taskdev")` passing: brain_context, plan_file, p
20
20
 
21
21
  After skill returns: follow `_protocol.md` Brain Write Procedure.
22
22
 
23
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
23
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -16,4 +16,4 @@ Invoke `Skill("mastermind-skills:tdd")` passing: brain_context, feature_or_bug,
16
16
 
17
17
  After skill returns: follow `_protocol.md` Brain Write Procedure for domain `tdd`.
18
18
 
19
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
19
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -16,4 +16,4 @@ Invoke `Skill("mastermind-skills:verify")` passing: brain_context, claim_or_task
16
16
 
17
17
  After skill returns: follow `_protocol.md` Brain Write Procedure for domain `verify`.
18
18
 
19
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
19
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -70,27 +70,23 @@ if (!entryPoint) {
70
70
  const dbPath = path.join(projectDir, '.monomind', 'monograph.db');
71
71
  if (fs.existsSync(dbPath)) {
72
72
  try {
73
- const mod = (() => {
74
- try { return require(path.join(projectDir, 'packages', '@monomind', 'monograph', 'dist', 'src', 'index.js')); } catch {}
75
- try { return require('@monoes/monograph'); } catch {}
76
- return null;
77
- })();
78
- if (mod && mod.openDb) {
79
- const db = mod.openDb(dbPath);
80
- try {
81
- const row = db.prepare("SELECT value FROM index_meta WHERE key='last_commit_hash'").get();
82
- if (row && row.value) {
83
- const { execSync } = require('child_process');
84
- const behind = parseInt(execSync('git rev-list --count ' + row.value + '..HEAD 2>/dev/null', {
85
- cwd: projectDir, encoding: 'utf-8', timeout: 2000
86
- }).trim(), 10) || 0;
87
- if (behind === 0) {
88
- console.log('[graph] index is fresh — skipping rebuild');
89
- process.exit(0);
90
- }
73
+ const Database = require(require.resolve('better-sqlite3', { paths: [path.dirname(entryPoint)] }));
74
+ const db = new Database(dbPath, { readonly: true, timeout: 5000 });
75
+ try {
76
+ const row = db.prepare("SELECT value FROM index_meta WHERE key='last_commit_hash'").get();
77
+ if (row && row.value && /^[0-9a-f]{7,40}$/i.test(row.value)) {
78
+ const { execFileSync } = require('child_process');
79
+ const out = execFileSync('git', ['rev-list', '--count', row.value + '..HEAD'], {
80
+ cwd: projectDir, encoding: 'utf-8', timeout: 2000, stdio: ['pipe', 'pipe', 'pipe']
81
+ }).trim();
82
+ const behind = parseInt(out, 10);
83
+ if (behind === 0) {
84
+ console.log('[graph] index is fresh skipping rebuild');
85
+ db.close();
86
+ process.exit(0);
91
87
  }
92
- } finally { mod.closeDb(db); }
93
- }
88
+ }
89
+ } finally { try { db.close(); } catch {} }
94
90
  } catch { /* can't check — proceed with build */ }
95
91
  }
96
92
 
@@ -361,17 +361,14 @@ module.exports = {
361
361
  // Source of truth is .monomind/monograph.db (SQLite). Legacy stats.json
362
362
  // is no longer written by the build, so it is checked only as a fallback.
363
363
  try {
364
- var monographDb = path.join(CWD, '.monomind', 'monograph.db');
365
364
  var legacyStats = path.join(CWD, '.monomind', 'graph', 'stats.json');
366
365
  var nodeCount = 0;
367
- if (fs.existsSync(monographDb)) {
368
- try {
369
- var hintDb = hCtx._openMonographDb();
370
- if (hintDb) {
371
- nodeCount = hintDb.prepare('SELECT COUNT(*) AS c FROM nodes').get().c;
372
- }
373
- } catch (e) { /* ignore — fall back to legacy */ }
374
- }
366
+ try {
367
+ var hintDb = hCtx._openMonographDb();
368
+ if (hintDb) {
369
+ nodeCount = hintDb.prepare('SELECT COUNT(*) AS c FROM nodes').get().c;
370
+ }
371
+ } catch (e) { /* ignore — fall back to legacy */ }
375
372
  if (nodeCount === 0 && fs.existsSync(legacyStats)) {
376
373
  try {
377
374
  var legacyStatsSt = fs.statSync(legacyStats);
@@ -49,11 +49,28 @@ function _suggestCacheSet(key, value) {
49
49
  }
50
50
  _suggestCache._map[key] = value;
51
51
  }
52
+ function _isValidDb(p) {
53
+ try { return fs.statSync(p).size >= 100; } catch (_) { return false; }
54
+ }
55
+
56
+ function _resolveDbPath() {
57
+ // monolean: try CWD first, then git root, so hooks work from any subdirectory
58
+ var candidate = path.join(CWD, '.monomind', 'monograph.db');
59
+ if (_isValidDb(candidate)) return candidate;
60
+ try {
61
+ var { execSync } = require('child_process');
62
+ var root = execSync('git rev-parse --show-toplevel', { cwd: CWD, encoding: 'utf-8', timeout: 2000 }).trim();
63
+ candidate = path.join(root, '.monomind', 'monograph.db');
64
+ if (_isValidDb(candidate)) return candidate;
65
+ } catch (_) {}
66
+ return null;
67
+ }
68
+
52
69
  function _openMonographDb() {
53
70
  if (_cachedMonographDb !== undefined) return _cachedMonographDb;
54
71
  try {
55
- var dbPath = path.join(CWD, '.monomind', 'monograph.db');
56
- if (!fs.existsSync(dbPath)) { _cachedMonographDb = null; return null; }
72
+ var dbPath = _resolveDbPath();
73
+ if (!dbPath) { _cachedMonographDb = null; return null; }
57
74
  var mod = _requireMonograph();
58
75
  if (!mod || !mod.openDb) { _cachedMonographDb = null; return null; }
59
76
  _cachedMonographDb = mod.openDb(dbPath);
@@ -189,27 +206,30 @@ function _isGraphFresh() {
189
206
  if (_graphFreshnessCache !== undefined) return _graphFreshnessCache;
190
207
  try {
191
208
  var db = _openMonographDb();
192
- if (!db) { _graphFreshnessCache = true; return true; }
209
+ if (!db) { _graphFreshnessCache = false; return false; }
193
210
  var row = null;
194
211
  try {
195
212
  row = db.prepare("SELECT value FROM index_meta WHERE key='last_commit_hash'").get() ||
196
213
  db.prepare("SELECT value FROM index_meta WHERE key='lastCommit'").get();
197
214
  } catch (_) {}
198
215
  if (!row || !row.value) {
199
- // No commit hash → can't check staleness, but DB may still have useful data
200
- var nodeCount = 0;
201
- try { nodeCount = db.prepare('SELECT COUNT(*) AS c FROM nodes').get().c; } catch (_) {}
202
- _graphFreshnessCache = nodeCount > 0;
203
- return _graphFreshnessCache;
216
+ _graphFreshnessCache = false;
217
+ return false;
204
218
  }
205
- var { execSync } = require('child_process');
206
- var out = execSync('git rev-list --count ' + row.value + '..HEAD 2>/dev/null', {
207
- encoding: 'utf-8', timeout: 1500, stdio: ['pipe', 'pipe', 'pipe']
219
+ if (!/^[0-9a-f]{7,40}$/i.test(row.value)) {
220
+ _graphFreshnessCache = false;
221
+ return false;
222
+ }
223
+ var { execFileSync } = require('child_process');
224
+ var out = execFileSync('git', ['rev-list', '--count', row.value + '..HEAD'], {
225
+ encoding: 'utf-8', timeout: 1500, stdio: ['pipe', 'pipe', 'pipe'], cwd: CWD
208
226
  }).trim();
209
- var behind = parseInt(out, 10) || 0;
227
+ var behind = parseInt(out, 10);
228
+ if (isNaN(behind)) { _graphFreshnessCache = false; return false; }
210
229
  _graphFreshnessCache = behind <= 50;
211
230
  } catch(e) {
212
- _graphFreshnessCache = true; // can't check assume fresh
231
+ // Don't cache transient errors — let next call retry
232
+ return false;
213
233
  }
214
234
  return _graphFreshnessCache;
215
235
  }
@@ -369,21 +389,18 @@ function injectGodNodesContext(CWD) {
369
389
  // Precompute degree via indexed edge lookups to avoid O(N) correlated subquery
370
390
  var godNodes = db.prepare(
371
391
  "WITH deg AS (" +
372
- " SELECT id, cnt FROM (" +
392
+ " SELECT id, SUM(cnt) AS deg FROM (" +
373
393
  " SELECT source_id AS id, COUNT(*) AS cnt FROM edges GROUP BY source_id " +
374
394
  " UNION ALL " +
375
395
  " SELECT target_id AS id, COUNT(*) AS cnt FROM edges GROUP BY target_id" +
376
396
  " ) GROUP BY id" +
377
- " HAVING SUM(cnt) > 0" +
378
- "), ranked AS (" +
379
- " SELECT d.id, SUM(d.cnt) AS deg FROM deg d GROUP BY d.id ORDER BY deg DESC LIMIT 50" +
380
397
  ") " +
381
- "SELECT n.name, n.label, n.file_path, r.deg " +
382
- "FROM ranked r JOIN nodes n ON n.id = r.id " +
398
+ "SELECT n.name, n.label, n.file_path, d.deg " +
399
+ "FROM deg d JOIN nodes n ON n.id = d.id " +
383
400
  "WHERE n.label NOT IN ('Concept') " +
384
401
  "AND n.file_path IS NOT NULL AND n.file_path != '' " +
385
402
  "AND n.file_path NOT LIKE '%/node_modules/%' AND n.file_path NOT LIKE '%node_modules%' " +
386
- "ORDER BY r.deg DESC LIMIT 12"
403
+ "ORDER BY d.deg DESC LIMIT 12"
387
404
  ).all();
388
405
 
389
406
  // Staleness indicator: compare stored commit hash with current HEAD.
@@ -6,6 +6,21 @@ type: protocol-skill
6
6
 
7
7
  # REPEAT POSTAMBLE
8
8
 
9
+ <EXTREMELY-IMPORTANT>
10
+ ## MANDATORY EXECUTION — READ THIS FIRST
11
+
12
+ This postamble is **not optional**. You MUST execute every step below. You MUST call ScheduleWakeup unless a legitimate stop condition is met (stop file, empty round confirmed by git, or count reached).
13
+
14
+ **Anti-rationalization rules:**
15
+ - "I think the work is done" is NOT a reason to stop. Only the checks below decide.
16
+ - "The skill already handled everything" is NOT a reason to skip this postamble.
17
+ - "There's nothing more to do" is NOT your decision — the tillend check decides.
18
+ - For `--repeat N`: you MUST run all N iterations. The count is non-negotiable. You cannot stop at run 3 of 5 because you think 3 was enough.
19
+ - For `--tillend`: you MUST continue until git AND your assessment BOTH confirm an empty round. Your feeling that "it's probably clean" is not evidence.
20
+
21
+ If you are about to end your response without calling ScheduleWakeup and you have not hit a legitimate stop condition, **YOU ARE MAKING AN ERROR. Go back and call ScheduleWakeup.**
22
+ </EXTREMELY-IMPORTANT>
23
+
9
24
  **If neither `tillend_mode = true` nor `repeat_count ≥ 2` was active in this invocation, stop immediately — this skill is a no-op.**
10
25
 
11
26
  Otherwise execute all steps below before ending the response.
@@ -29,12 +44,22 @@ If the stop file exists:
29
44
 
30
45
  **`LOOP_ASYNC_PENDING` escape hatch:** If the calling skill set `LOOP_ASYNC_PENDING=true` before invoking this postamble (because it spawned background agents whose results have not yet arrived), skip the empty-round check and go directly to Step 4 to schedule the next run. Output: `[tillend] Async work in flight — deferring empty-round check to run <next_rep>.`
31
46
 
32
- Evaluate now whether this run produced **zero findings AND zero actions**:
47
+ **Step 2a Machine verification (REQUIRED before any self-assessment):**
48
+
49
+ Run this command to get an objective signal of whether files changed during this run:
50
+
51
+ ```bash
52
+ GIT_CHANGES=$(git diff --stat HEAD 2>/dev/null; git diff --cached --stat 2>/dev/null; git status --porcelain 2>/dev/null | grep -v '^\?\?' | head -20)
53
+ echo "GIT_CHANGES_DURING_RUN: ${GIT_CHANGES:-NONE}"
54
+ ```
55
+
56
+ If `GIT_CHANGES` is non-empty, files were modified — `TILLEND_EMPTY=false` regardless of your self-assessment. Skip to "Otherwise" below.
57
+
58
+ **Step 2b — Self-assessment (only if git shows no changes):**
33
59
 
34
- - **Findings**: issues found, problems detected, items flagged, security vulnerabilities, tasks discovered, errors reported
35
- - **Actions**: files edited, code fixed, commits made, tasks created, configs changed, content written
60
+ Only if `GIT_CHANGES` was empty, evaluate whether this run produced findings (issues identified, problems flagged) or actions (tasks created, content written, configs changed — anything not captured by git diff).
36
61
 
37
- Set `TILLEND_EMPTY=true` **only if BOTH are zero for this round**.
62
+ Set `TILLEND_EMPTY=true` **only if git shows no changes AND your self-assessment confirms zero findings and zero actions**.
38
63
 
39
64
  **Important**: If this round found things AND fixed them, `TILLEND_EMPTY=false` — the loop must continue to verify the fixes didn't introduce new issues.
40
65
 
@@ -171,8 +171,15 @@ Step 4 — Report:
171
171
 
172
172
  Also run /mastermind:do --board <board_id> to track execution.
173
173
 
174
- STEP 4 — COLLECT AND RETURN
175
- Synthesize all review findings. Return to caller:
174
+ STEP 4 — AUTO-FIX (mode = auto only, skip for mode = confirm)
175
+ When mode is auto: for each fixable finding from the review (code bugs, style issues, security vulnerabilities with clear fixes), apply the fix directly by editing the file. Do NOT ask the user for permission — auto mode means fix without asking. After fixing, output:
176
+ [review] Auto-fixed N issues. M issues remain (require manual intervention or are architectural).
177
+ Non-fixable findings (design questions, trade-offs, architectural concerns) are reported but left untouched.
178
+
179
+ When --tillend is active, this step is critical: without auto-fixing, the loop either finds the same issues every round (infinite loop) or falsely declares empty round. The tillend contract is: find → fix → verify (next round) → stop when clean.
180
+
181
+ STEP 5 — COLLECT AND RETURN
182
+ Synthesize all review findings and fixes applied. Return to caller:
176
183
 
177
184
  domain: review
178
185
  status: complete | partial | blocked
@@ -183,12 +190,14 @@ decisions:
183
190
  - what: [critical findings and recommended actions]
184
191
  why: [evidence from review]
185
192
  confidence: [0.0-1.0]
186
- outcome: pending
193
+ outcome: fixed | pending | manual
187
194
  lessons:
188
195
  - what_worked: [which review angles surfaced the most value]
189
196
  - what_didnt: [gaps in review coverage]
197
+ fixes_applied: [count of auto-fixed issues]
198
+ fixes_remaining: [count of issues needing manual intervention]
190
199
  next_actions:
191
- - [e.g. "run mastermind:build to fix critical issues found"]
200
+ - [e.g. "re-run review to verify fixes" if tillend is active]
192
201
  - [e.g. "run mastermind:release after fixes are confirmed"]
193
202
  board_url: monotask://<project_name>/review
194
203
  run_id: <ISO8601-timestamp>`,
@@ -203,8 +212,10 @@ run_id: <ISO8601-timestamp>`,
203
212
  For simple tasks (single reviewer, single artifact):
204
213
 
205
214
  1. Spawn one Task agent with the review request as a self-contained briefing
206
- 2. Collect output
207
- 3. Return unified output schema with `status: complete`
215
+ 2. Collect findings
216
+ 3. **If mode = auto**: apply fixes for all fixable findings directly (do NOT ask the user). Output: `[review] Auto-fixed N issues.`
217
+ 4. **If mode = confirm**: present findings and ask which to fix
218
+ 5. Return unified output schema with `status: complete`
208
219
 
209
220
  ---
210
221
 
@@ -5,9 +5,37 @@
5
5
  * All monograph_* tools are backed by @monoes/monograph package.
6
6
  */
7
7
  import { join, resolve, sep } from 'path';
8
+ import { execSync } from 'child_process';
9
+ import { statSync } from 'fs';
8
10
  import { getProjectCwd } from './types.js';
11
+ let _cachedDbPath;
12
+ function _isValidDb(p) {
13
+ try {
14
+ return statSync(p).size >= 100;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
9
20
  function getDbPath() {
10
- return join(getProjectCwd(), '.monomind', 'monograph.db');
21
+ if (_cachedDbPath !== undefined)
22
+ return _cachedDbPath ?? join(getProjectCwd(), '.monomind', 'monograph.db');
23
+ const direct = join(getProjectCwd(), '.monomind', 'monograph.db');
24
+ if (_isValidDb(direct)) {
25
+ _cachedDbPath = direct;
26
+ return direct;
27
+ }
28
+ try {
29
+ const root = execSync('git rev-parse --show-toplevel', { cwd: getProjectCwd(), encoding: 'utf8' }).trim();
30
+ const candidate = join(root, '.monomind', 'monograph.db');
31
+ if (_isValidDb(candidate)) {
32
+ _cachedDbPath = candidate;
33
+ return candidate;
34
+ }
35
+ }
36
+ catch { /* not in a git repo */ }
37
+ _cachedDbPath = null;
38
+ return direct;
11
39
  }
12
40
  function text(t) {
13
41
  return { content: [{ type: 'text', text: t }] };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoes/monomindcli",
3
- "version": "1.18.13",
3
+ "version": "1.18.15",
4
4
  "type": "module",
5
5
  "description": "Monomind CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",