moflo 4.0.1 → 4.0.2

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.
@@ -47,19 +47,25 @@ Use results with score > 0.3. If no good results, fall back to reading project g
47
47
 
48
48
  ---
49
49
 
50
- ## 2. Check Project Guidance
50
+ ## 2. Check Project-Specific Bootstrap
51
51
 
52
- If memory search doesn't return useful results, look for project-level guidance:
52
+ **After reading this file, check for a project-specific bootstrap:**
53
53
 
54
54
  ```bash
55
- # Check if project has guidance docs
56
- ls .claude/guidance/ 2>/dev/null
55
+ # Project-specific bootstrap (has domain rules, patterns, templates)
56
+ cat .claude/guidance/agent-bootstrap.md 2>/dev/null | head -10
57
+ ```
58
+
59
+ If `.claude/guidance/agent-bootstrap.md` exists, **read it next**. It contains project-specific rules (entity patterns, multi-tenancy, tech stack conventions) that override generic guidance.
57
60
 
58
- # Check if project has a core index
61
+ If no project bootstrap exists, look for general project guidance:
62
+
63
+ ```bash
64
+ ls .claude/guidance/ 2>/dev/null
59
65
  cat .claude/guidance/core.md 2>/dev/null | head -50
60
66
  ```
61
67
 
62
- Project guidance takes precedence over generic patterns.
68
+ Project guidance always takes precedence over generic patterns.
63
69
 
64
70
  ---
65
71
 
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MoFlo Project Setup
4
+ *
5
+ * Copies the agent-bootstrap guidance into the consuming project and
6
+ * adds a CLAUDE.md section so subagents automatically follow the protocol.
7
+ *
8
+ * Usage:
9
+ * npx moflo-setup # First-time setup
10
+ * npx moflo-setup --update # Refresh bootstrap file after moflo upgrade
11
+ * npx moflo-setup --check # Check if setup is current
12
+ *
13
+ * What it does:
14
+ * 1. Copies .claude/guidance/agent-bootstrap.md → project's .claude/guidance/moflo-bootstrap.md
15
+ * 2. Appends a subagent protocol section to CLAUDE.md (idempotent, with markers)
16
+ *
17
+ * The project can layer its own .claude/guidance/agent-bootstrap.md on top for
18
+ * project-specific rules (companyId, entity templates, etc.).
19
+ */
20
+
21
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from 'node:fs';
22
+ import { dirname, resolve, join } from 'node:path';
23
+ import { fileURLToPath } from 'node:url';
24
+
25
+ const __dirname = dirname(fileURLToPath(import.meta.url));
26
+ const mofloRoot = resolve(__dirname, '..');
27
+
28
+ const args = process.argv.slice(2);
29
+ const updateOnly = args.includes('--update');
30
+ const checkOnly = args.includes('--check');
31
+
32
+ // Markers for idempotent CLAUDE.md updates
33
+ const MARKER_START = '<!-- MOFLO:SUBAGENT-PROTOCOL:START -->';
34
+ const MARKER_END = '<!-- MOFLO:SUBAGENT-PROTOCOL:END -->';
35
+
36
+ const CLAUDE_MD_SECTION = `${MARKER_START}
37
+ ## Subagent Protocol (MoFlo)
38
+
39
+ All subagents MUST read \`.claude/guidance/moflo-bootstrap.md\` before starting any work.
40
+ It contains the memory-first protocol, discovery storage rules, and universal conventions.
41
+
42
+ If \`.claude/guidance/agent-bootstrap.md\` also exists, read it next for project-specific rules.
43
+ ${MARKER_END}`;
44
+
45
+ function log(msg) {
46
+ console.log(`[moflo-setup] ${msg}`);
47
+ }
48
+
49
+ function findProjectRoot() {
50
+ // Walk up from cwd looking for package.json that depends on moflo
51
+ let dir = process.cwd();
52
+ const root = resolve(dir, '/');
53
+
54
+ while (dir !== root) {
55
+ const pkgPath = join(dir, 'package.json');
56
+ if (existsSync(pkgPath)) {
57
+ try {
58
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
59
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
60
+ if (deps && deps.moflo) {
61
+ return dir;
62
+ }
63
+ } catch { /* ignore parse errors */ }
64
+ }
65
+ dir = dirname(dir);
66
+ }
67
+
68
+ // Fallback: use cwd if it has a package.json
69
+ if (existsSync(join(process.cwd(), 'package.json'))) {
70
+ return process.cwd();
71
+ }
72
+
73
+ return null;
74
+ }
75
+
76
+ function copyBootstrap(projectRoot) {
77
+ const source = join(mofloRoot, '.claude', 'guidance', 'agent-bootstrap.md');
78
+ const targetDir = join(projectRoot, '.claude', 'guidance');
79
+ const target = join(targetDir, 'moflo-bootstrap.md');
80
+
81
+ if (!existsSync(source)) {
82
+ log('❌ Source bootstrap not found in moflo package');
83
+ return false;
84
+ }
85
+
86
+ // Read source content and prepend auto-generated notice
87
+ const content = readFileSync(source, 'utf-8');
88
+ const header = `<!-- AUTO-GENERATED by moflo-setup. Do not edit — changes will be overwritten. -->
89
+ <!-- Source: node_modules/moflo/.claude/guidance/agent-bootstrap.md -->
90
+ <!-- To customize, create .claude/guidance/agent-bootstrap.md for project-specific rules. -->
91
+
92
+ `;
93
+
94
+ mkdirSync(targetDir, { recursive: true });
95
+
96
+ // Check if file exists and is current
97
+ if (existsSync(target)) {
98
+ const existing = readFileSync(target, 'utf-8');
99
+ const newContent = header + content;
100
+ if (existing === newContent) {
101
+ log('✅ moflo-bootstrap.md is current');
102
+ return true;
103
+ }
104
+ log('📝 Updating moflo-bootstrap.md');
105
+ } else {
106
+ log('📝 Creating .claude/guidance/moflo-bootstrap.md');
107
+ }
108
+
109
+ if (!checkOnly) {
110
+ writeFileSync(target, header + content, 'utf-8');
111
+ }
112
+ return true;
113
+ }
114
+
115
+ function updateClaudeMd(projectRoot) {
116
+ const claudeMdPath = join(projectRoot, 'CLAUDE.md');
117
+
118
+ if (!existsSync(claudeMdPath)) {
119
+ if (checkOnly) {
120
+ log('⚠️ No CLAUDE.md found');
121
+ return false;
122
+ }
123
+ log('📝 Creating CLAUDE.md with subagent protocol section');
124
+ writeFileSync(claudeMdPath, `# Project Configuration\n\n${CLAUDE_MD_SECTION}\n`, 'utf-8');
125
+ return true;
126
+ }
127
+
128
+ const content = readFileSync(claudeMdPath, 'utf-8');
129
+
130
+ // Check if markers already exist
131
+ if (content.includes(MARKER_START)) {
132
+ // Extract existing section and compare
133
+ const startIdx = content.indexOf(MARKER_START);
134
+ const endIdx = content.indexOf(MARKER_END);
135
+
136
+ if (endIdx > startIdx) {
137
+ const existingSection = content.substring(startIdx, endIdx + MARKER_END.length);
138
+ if (existingSection === CLAUDE_MD_SECTION) {
139
+ log('✅ CLAUDE.md subagent section is current');
140
+ return true;
141
+ }
142
+
143
+ // Update existing section
144
+ if (!checkOnly) {
145
+ const updated = content.substring(0, startIdx) + CLAUDE_MD_SECTION + content.substring(endIdx + MARKER_END.length);
146
+ writeFileSync(claudeMdPath, updated, 'utf-8');
147
+ log('📝 Updated CLAUDE.md subagent protocol section');
148
+ } else {
149
+ log('⚠️ CLAUDE.md subagent section needs update');
150
+ }
151
+ return true;
152
+ }
153
+ }
154
+
155
+ if (updateOnly) {
156
+ log('⚠️ CLAUDE.md has no moflo section (run without --update to add)');
157
+ return false;
158
+ }
159
+
160
+ if (checkOnly) {
161
+ log('⚠️ CLAUDE.md missing subagent protocol section');
162
+ return false;
163
+ }
164
+
165
+ // Append section to end of CLAUDE.md
166
+ const separator = content.endsWith('\n') ? '\n' : '\n\n';
167
+ writeFileSync(claudeMdPath, content + separator + CLAUDE_MD_SECTION + '\n', 'utf-8');
168
+ log('📝 Added subagent protocol section to CLAUDE.md');
169
+ return true;
170
+ }
171
+
172
+ function main() {
173
+ console.log('');
174
+ console.log('MoFlo Project Setup');
175
+ console.log('───────────────────');
176
+
177
+ const projectRoot = findProjectRoot();
178
+ if (!projectRoot) {
179
+ log('❌ Could not find project root (no package.json with moflo dependency)');
180
+ process.exit(1);
181
+ }
182
+
183
+ log(`Project: ${projectRoot}`);
184
+ console.log('');
185
+
186
+ // Step 1: Copy bootstrap file
187
+ const bootstrapOk = copyBootstrap(projectRoot);
188
+
189
+ // Step 2: Update CLAUDE.md (skip on --update, only refresh the file)
190
+ const claudeOk = updateOnly ? true : updateClaudeMd(projectRoot);
191
+
192
+ console.log('');
193
+ if (checkOnly) {
194
+ log(bootstrapOk && claudeOk ? '✅ Setup is current' : '⚠️ Setup needs attention');
195
+ } else {
196
+ log('✅ Done. Subagents will now follow the MoFlo bootstrap protocol.');
197
+ }
198
+ console.log('');
199
+ }
200
+
201
+ main();
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "moflo",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "MoFlo — AI agent orchestration for Claude Code. Forked from ruflo/claude-flow with patches applied to source, plus feature-level orchestration.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "moflo": "./bin/cli.js",
9
+ "moflo-setup": "./bin/setup-project.mjs",
9
10
  "claude-flow": "./bin/cli.js"
10
11
  },
11
12
  "homepage": "https://github.com/eric-cielo/moflo#readme",