moflo 4.0.0 → 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.
@@ -0,0 +1,122 @@
1
+ # MoFlo Agent Bootstrap Guide
2
+
3
+ **Purpose:** Quick-start reference for subagents spawned by coordinators. Every subagent should follow this protocol before doing any work.
4
+
5
+ ---
6
+
7
+ ## 1. Search Memory FIRST
8
+
9
+ **Before reading any files or exploring code, search memory for guidance relevant to your task.**
10
+
11
+ ### Two namespaces to search:
12
+
13
+ | Namespace | When to search | What it returns |
14
+ |-----------|---------------|-----------------|
15
+ | `guidance` | Understanding patterns, rules, conventions | Guidance docs, coding rules, domain context |
16
+ | `code-map` | Finding where code lives (files, types, services) | Project overviews, directory contents, type locations |
17
+
18
+ **Search `code-map` BEFORE using Glob/Grep for navigation.** It's faster and returns structured results.
19
+
20
+ ### Option A: MCP Tools (Preferred)
21
+
22
+ If you have MCP tools available (check for `mcp__claude-flow__*`), use them directly:
23
+
24
+ | Tool | Purpose |
25
+ |------|---------|
26
+ | `mcp__claude-flow__memory_search` | Semantic search with domain-aware embeddings |
27
+ | `mcp__claude-flow__memory_store` | Store patterns with auto-vectorization |
28
+ | `mcp__claude-flow__hooks_route` | Get agent routing suggestions |
29
+
30
+ ### Option B: CLI via Bash
31
+
32
+ ```bash
33
+ npx moflo memory search --query "[describe your task]" --namespace guidance --limit 5
34
+ ```
35
+
36
+ | Your task involves... | Search namespace | Example query |
37
+ |-----------------------|------------------|---------------|
38
+ | Database/entities | `guidance` | `"database entity migration"` |
39
+ | Frontend components | `guidance` | `"React frontend component"` |
40
+ | API endpoints | `guidance` | `"API route endpoint pattern"` |
41
+ | Authentication | `guidance` | `"auth middleware JWT"` |
42
+ | Unit tests | `guidance` | `"test mock vitest"` |
43
+ | Where is a file/type? | `code-map` | `"service entity location"` |
44
+ | What's in a directory? | `code-map` | `"back-office api routes"` |
45
+
46
+ Use results with score > 0.3. If no good results, fall back to reading project guidance docs.
47
+
48
+ ---
49
+
50
+ ## 2. Check Project-Specific Bootstrap
51
+
52
+ **After reading this file, check for a project-specific bootstrap:**
53
+
54
+ ```bash
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.
60
+
61
+ If no project bootstrap exists, look for general project guidance:
62
+
63
+ ```bash
64
+ ls .claude/guidance/ 2>/dev/null
65
+ cat .claude/guidance/core.md 2>/dev/null | head -50
66
+ ```
67
+
68
+ Project guidance always takes precedence over generic patterns.
69
+
70
+ ---
71
+
72
+ ## 3. Universal Rules
73
+
74
+ ### Memory Protocol
75
+ - Search memory before exploring files
76
+ - Store discoveries back to memory when done
77
+ - Use `patterns` namespace for solutions and gotchas
78
+ - Use `decisions` namespace for architectural choices
79
+
80
+ ### Git/Branches
81
+ - Use conventional commit prefixes: `feat:`, `fix:`, `refactor:`, `test:`, `chore:`
82
+ - Use branch prefixes: `feature/`, `fix/`, `refactor/`
83
+ - Use kebab-case for branch names
84
+
85
+ ### File Organization
86
+ - Never save working files to repository root
87
+ - Keep changes focused (3-10 files)
88
+ - Stay within feature scope
89
+
90
+ ### Build & Test
91
+ - Build and test after code changes
92
+ - Never leave failing tests
93
+
94
+ ---
95
+
96
+ ## 4. Store Discoveries
97
+
98
+ If you discover something new (pattern, solution, gotcha), store it:
99
+
100
+ ### MCP (Preferred):
101
+ ```
102
+ mcp__claude-flow__memory_store
103
+ namespace: "patterns"
104
+ key: "brief-descriptive-key"
105
+ value: "1-2 sentence insight"
106
+ ```
107
+
108
+ ### CLI Fallback:
109
+ ```bash
110
+ npx moflo memory store --namespace patterns --key "brief-descriptive-key" --value "1-2 sentence insight"
111
+ ```
112
+
113
+ **Store:** Solutions to tricky bugs, patterns that worked, gotchas, workarounds
114
+ **Skip:** Summaries of retrieved guidance, general rules, file locations
115
+
116
+ ---
117
+
118
+ ## 5. When Complete
119
+
120
+ 1. Report findings to coordinator
121
+ 2. Store learnings if you discovered something new
122
+ 3. Coordinator will mark your task as completed
@@ -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.0",
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",