moflo 4.9.20 → 4.9.21
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.
- package/.claude/commands/{simplify.md → flo-simplify.md} +4 -4
- package/.claude/guidance/shipped/moflo-agent-rules.md +172 -0
- package/.claude/guidance/shipped/moflo-claude-swarm-cohesion.md +73 -265
- package/.claude/guidance/shipped/moflo-cli-reference.md +6 -6
- package/.claude/guidance/shipped/moflo-core-guidance.md +66 -184
- package/.claude/guidance/shipped/moflo-cross-platform.md +1 -1
- package/.claude/guidance/shipped/moflo-error-handling.md +3 -3
- package/.claude/guidance/shipped/moflo-guidance-rules.md +17 -7
- package/.claude/guidance/shipped/moflo-memory-strategy.md +76 -182
- package/.claude/guidance/shipped/moflo-memorydb-maintenance.md +6 -8
- package/.claude/guidance/shipped/moflo-settings-injection.md +7 -9
- package/.claude/guidance/shipped/moflo-source-hygiene.md +5 -5
- package/.claude/guidance/shipped/moflo-spell-connectors.md +3 -4
- package/.claude/guidance/shipped/moflo-spell-custom-steps.md +3 -4
- package/.claude/guidance/shipped/moflo-spell-engine.md +40 -162
- package/.claude/guidance/shipped/moflo-spell-runner.md +134 -0
- package/.claude/guidance/shipped/moflo-spell-sandboxing.md +10 -57
- package/.claude/guidance/shipped/moflo-spell-troubleshooting.md +149 -0
- package/.claude/guidance/shipped/moflo-subagents.md +43 -114
- package/.claude/guidance/shipped/moflo-task-icons.md +4 -4
- package/.claude/guidance/shipped/moflo-user-facing-language.md +3 -3
- package/.claude/guidance/shipped/moflo-verbose-command-filtering.md +3 -3
- package/.claude/guidance/shipped/moflo-yaml-reference.md +4 -5
- package/.claude/helpers/gate.cjs +124 -14
- package/.claude/helpers/prompt-hook.mjs +4 -38
- package/.claude/helpers/simplify-classify.cjs +32 -11
- package/.claude/helpers/subagent-bootstrap.json +1 -1
- package/.claude/helpers/subagent-start.cjs +1 -1
- package/.claude/skills/connector-builder/SKILL.md +42 -429
- package/.claude/skills/connector-builder/templates/connector.md +189 -0
- package/.claude/skills/connector-builder/templates/step-command.md +176 -0
- package/.claude/skills/eldar/SKILL.md +7 -7
- package/.claude/skills/fl/SKILL.md +3 -3
- package/.claude/skills/fl/execution-modes.md +3 -3
- package/.claude/skills/fl/phases.md +3 -3
- package/.claude/skills/{simplify → flo-simplify}/SKILL.md +11 -11
- package/.claude/skills/guidance/SKILL.md +17 -9
- package/.claude/skills/memory-patterns/SKILL.md +1 -1
- package/.claude/skills/publish/SKILL.md +121 -36
- package/.claude/skills/reset-epic/SKILL.md +2 -2
- package/.claude/skills/spell-builder/SKILL.md +39 -226
- package/.claude/skills/spell-builder/architecture.md +1 -1
- package/.claude/skills/spell-builder/permissions.md +107 -0
- package/.claude/skills/spell-builder/preflight.md +101 -0
- package/.claude/skills/spell-schedule/SKILL.md +2 -3
- package/bin/gate.cjs +124 -14
- package/bin/prompt-hook.mjs +4 -38
- package/bin/session-start-launcher.mjs +19 -1
- package/bin/setup-project.mjs +63 -69
- package/bin/simplify-classify.cjs +32 -11
- package/dist/src/cli/commands/doctor-checks-deep.js +4 -0
- package/dist/src/cli/init/claudemd-generator.js +30 -33
- package/dist/src/cli/init/executor.js +28 -16
- package/dist/src/cli/init/helpers-generator.js +101 -51
- package/dist/src/cli/init/moflo-init.js +41 -114
- package/dist/src/cli/init/settings-generator.js +32 -14
- package/dist/src/cli/services/hook-block-hash.js +7 -2
- package/dist/src/cli/services/hook-wiring.js +86 -3
- package/dist/src/cli/services/subagent-bootstrap.js +1 -1
- package/dist/src/cli/version.js +1 -1
- package/package.json +2 -2
- package/scripts/post-install-bootstrap.mjs +19 -0
- package/.claude/guidance/shipped/moflo-session-start.md +0 -154
- package/.claude/guidance/shipped/moflo-spell-engine-architecture.md +0 -145
- package/.claude/skills/browser/SKILL.md +0 -204
- package/.claude/skills/github-code-review/SKILL.md +0 -1140
- package/.claude/skills/github-multi-repo/SKILL.md +0 -866
- package/.claude/skills/github-project-management/SKILL.md +0 -1272
- package/.claude/skills/github-release-management/SKILL.md +0 -1074
- package/.claude/skills/github-workflow-automation/SKILL.md +0 -1060
- package/.claude/skills/hive-mind-advanced/SKILL.md +0 -712
- package/.claude/skills/hooks-automation/SKILL.md +0 -1193
- package/.claude/skills/pair-programming/SKILL.md +0 -1202
- package/.claude/skills/performance-analysis/SKILL.md +0 -563
- package/.claude/skills/skill-builder/SKILL.md +0 -910
- package/.claude/skills/sparc-methodology/SKILL.md +0 -904
- package/.claude/skills/stream-chain/SKILL.md +0 -563
- package/.claude/skills/swarm-advanced/SKILL.md +0 -811
- package/.claude/skills/swarm-orchestration/SKILL.md +0 -179
- package/.claude/skills/verification-quality/SKILL.md +0 -649
- package/.claude/skills/worker-benchmarks/skill.md +0 -135
- package/.claude/skills/worker-integration/skill.md +0 -154
|
@@ -1,57 +1,28 @@
|
|
|
1
1
|
# Memory & Semantic Search Strategy
|
|
2
2
|
|
|
3
|
-
**Purpose:** How memory, embeddings, and semantic search work in moflo. Reference when
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Problem Statement
|
|
8
|
-
|
|
9
|
-
Claude Code agents need project-specific knowledge — coding rules, architecture patterns, entity templates, testing conventions — delivered at the right moment. Without a retrieval system, agents either miss critical rules or require massive CLAUDE.md files that waste context window tokens.
|
|
10
|
-
|
|
11
|
-
**Goals:**
|
|
12
|
-
- Agents find relevant guidance automatically via semantic search
|
|
13
|
-
- Subagents spawned by the coordinator inherit memory access
|
|
14
|
-
- Search quality is high enough that agents don't need to read whole files
|
|
15
|
-
- The system survives `npm install` (indexing runs on session start)
|
|
3
|
+
**Purpose:** How memory, embeddings, and semantic search work in moflo. Reference when debugging search quality, configuring memory for a project, or extending the indexing pipeline. Authoring rules for guidance docs themselves live in `.claude/guidance/moflo-guidance-rules.md` — read those first.
|
|
16
4
|
|
|
17
5
|
---
|
|
18
6
|
|
|
19
7
|
## Architecture Overview
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
Source Files (.claude/guidance/*.md, docs/*.md)
|
|
23
|
-
|
|
|
24
|
-
v
|
|
25
|
-
index-guidance.mjs --- Chunk on ## headers, build RAG links
|
|
26
|
-
| (prev/next, siblings, parent/child, context overlap)
|
|
27
|
-
v
|
|
28
|
-
.swarm/memory.db ----- SQLite (entries + metadata + embedding vectors)
|
|
29
|
-
|
|
|
30
|
-
v
|
|
31
|
-
build-embeddings.mjs - Generate 384-dim vectors per entry
|
|
32
|
-
| (Xenova/all-MiniLM-L6-v2 neural, or domain-aware hash fallback)
|
|
33
|
-
v
|
|
34
|
-
HNSW index ----------- Approximate nearest-neighbor search
|
|
35
|
-
v
|
|
36
|
-
Search layer ---------- Three access paths:
|
|
37
|
-
1. MCP tools (mcp__moflo__memory_search) -- preferred
|
|
38
|
-
2. CLI (npx flo memory search) -- fallback
|
|
39
|
-
3. Script (semantic-search.mjs) -- detailed output
|
|
40
|
-
```
|
|
9
|
+
Source files (`.claude/guidance/*.md`, `docs/**/*.md`, code, tests) flow through four stages:
|
|
41
10
|
|
|
42
|
-
**
|
|
11
|
+
1. **Index** — `bin/index-*.mjs` chunks markdown on `##` headers and walks code/tests for structural facts
|
|
12
|
+
2. **Store** — entries land in `.moflo/moflo.db` (SQLite via sql.js) with metadata + RAG links
|
|
13
|
+
3. **Embed** — `bin/build-embeddings.mjs` generates 384-dim vectors via `fastembed` (mandatory, see ADR-EMB-001)
|
|
14
|
+
4. **Search** — `mcp__moflo__memory_search` (preferred), `npx flo memory search` (fallback), or `npx flo-search` (verbose) hit an HNSW index for nearest-neighbor lookup
|
|
43
15
|
|
|
44
16
|
| File | Purpose |
|
|
45
17
|
|------|---------|
|
|
46
|
-
| `.
|
|
47
|
-
| `.swarm/code-map-hash.txt` | SHA-256 hash for incremental code map skip |
|
|
18
|
+
| `.moflo/moflo.db` | SQLite DB — entries, embeddings, metadata |
|
|
48
19
|
| `.moflo/neural/patterns.json` | ReasoningBank learned patterns |
|
|
49
|
-
| `bin/
|
|
50
|
-
| `bin/
|
|
51
|
-
| `bin/
|
|
52
|
-
| `bin/index-
|
|
53
|
-
| `bin/index-
|
|
54
|
-
| `bin/
|
|
20
|
+
| `bin/index-guidance.mjs` | Indexes guidance with RAG linking |
|
|
21
|
+
| `bin/generate-code-map.mjs` | Structural code map (projects, dirs, types) |
|
|
22
|
+
| `bin/index-patterns.mjs` | Per-file code patterns |
|
|
23
|
+
| `bin/index-tests.mjs` | Test structure |
|
|
24
|
+
| `bin/index-all.mjs` | Runs the full chain sequentially |
|
|
25
|
+
| `bin/build-embeddings.mjs` | Generates 384-dim vectors |
|
|
55
26
|
|
|
56
27
|
---
|
|
57
28
|
|
|
@@ -59,104 +30,44 @@ Search layer ---------- Three access paths:
|
|
|
59
30
|
|
|
60
31
|
| Namespace | Content | Indexed By |
|
|
61
32
|
|-----------|---------|------------|
|
|
62
|
-
| `guidance` |
|
|
63
|
-
| `code-map` | Structural codebase index (projects,
|
|
64
|
-
| `patterns` | Per-file code patterns (services, routes,
|
|
33
|
+
| `guidance` | Markdown guidance and docs | `index-guidance.mjs` |
|
|
34
|
+
| `code-map` | Structural codebase index (projects, dirs, types, interfaces) | `generate-code-map.mjs` |
|
|
35
|
+
| `patterns` | Per-file code patterns (services, routes, exports) | `index-patterns.mjs` |
|
|
65
36
|
| `tests` | Test structure and patterns | `index-tests.mjs` |
|
|
37
|
+
| `learnings` | User-stored patterns from work sessions | `mcp__moflo__memory_store` |
|
|
66
38
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## Guidance Document Optimization Rules
|
|
70
|
-
|
|
71
|
-
These rules determine how well your guidance documents retrieve via semantic search:
|
|
72
|
-
|
|
73
|
-
### 1. Every file needs a Purpose line
|
|
74
|
-
|
|
75
|
-
Add `**Purpose:**` as the first meaningful line after the title. Claude checks this first for relevance scoring. Without it, the chunk has no summary signal.
|
|
76
|
-
|
|
77
|
-
### 2. H2 headings are the primary retrieval signal
|
|
78
|
-
|
|
79
|
-
The indexer splits on `##`. Each heading becomes the chunk title, prepended to searchable content. Domain-specific keywords in headings dramatically improve recall.
|
|
80
|
-
|
|
81
|
-
**Bad:** `## Overview`, `## Rules`, `## Pattern`
|
|
82
|
-
**Good:** `## Soft Delete Rules`, `## JWT Authentication Pattern`, `## Database Entity Migration`
|
|
83
|
-
|
|
84
|
-
### 3. Ideal chunk size: 1000-4000 characters
|
|
85
|
-
|
|
86
|
-
Below 50 chars the chunk is dropped. Above 6000 the indexer force-splits on paragraphs, which breaks mid-thought. The sweet spot produces focused embeddings.
|
|
87
|
-
|
|
88
|
-
### 4. Self-contained chunks
|
|
89
|
-
|
|
90
|
-
Each H2 section must answer a question without needing the rest of the document. Include: the rule, a code example, and a cross-reference.
|
|
91
|
-
|
|
92
|
-
### 5. Tables over prose
|
|
93
|
-
|
|
94
|
-
Claude parses structured data more accurately than paragraphs. DO/DON'T tables, field reference tables, and command tables all retrieve better.
|
|
95
|
-
|
|
96
|
-
### 6. Cross-references create a navigation graph
|
|
97
|
-
|
|
98
|
-
The RAG indexer stores `prevChunk`/`nextChunk`/`siblings` metadata. Cross-references between documents let Claude follow chains: `core.md -> coding-rules.md -> database.md`.
|
|
99
|
-
|
|
100
|
-
### 7. No decorative formatting
|
|
101
|
-
|
|
102
|
-
ASCII boxes, excessive emoji, rhetorical questions, and motivational text all waste tokens without improving retrieval or comprehension.
|
|
39
|
+
Namespaces are independent indexes. Search defaults to `all`; pass `namespace: "guidance"` to target one.
|
|
103
40
|
|
|
104
41
|
---
|
|
105
42
|
|
|
106
43
|
## Embedding Strategy
|
|
107
44
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
| Model | Runtime | Speed | Notes |
|
|
111
|
-
|-------|---------|-------|-------|
|
|
112
|
-
| `fast-all-MiniLM-L6-v2` | `fastembed` (native ONNX + Rust tokenizer) | ~3s for 1000 entries | The only supported model — neural embeddings are mandatory (ADR-EMB-001) |
|
|
113
|
-
|
|
114
|
-
**Neural embeddings (fast-all-MiniLM-L6-v2):**
|
|
115
|
-
- Uses the `fastembed` npm package (Qdrant's embeddings-only ONNX client)
|
|
116
|
-
- 384-dimensional vectors, L2-normalized
|
|
117
|
-
- True semantic understanding — "soft delete" matches "mark as deleted" without keyword overlap
|
|
118
|
-
- Model auto-downloads to `~/.cache/fastembed` on first use; cached for subsequent queries
|
|
119
|
-
- For offline / air-gapped / sandboxed runs, pre-populate the cache or set `FASTEMBED_CACHE` — see `docs/modules/embeddings.md` "Sandbox & air-gapped first-run"
|
|
120
|
-
|
|
121
|
-
**Legacy-compatible model names:** Entries embedded by earlier moflo versions may be tagged `Xenova/all-MiniLM-L6-v2` or `onnx`. These share the same vector space as `fast-all-MiniLM-L6-v2`, so search treats them as compatible (`semantic-search.mjs` `COMPATIBLE_MODELS`).
|
|
122
|
-
|
|
123
|
-
**No hash fallback.** Epic #527 removed every hash-embedding path. If the `fastembed` model cannot load, memory operations fail loudly rather than silently degrading to FNV-1a pseudo-vectors. See [ADR-EMB-001](../../../docs/adr/ADR-EMB-001-neural-embeddings-mandatory.md).
|
|
45
|
+
**Model:** `fast-all-MiniLM-L6-v2` via `fastembed` (Qdrant's ONNX client). 384-dim, L2-normalized vectors. ~3 s for 1000 entries.
|
|
124
46
|
|
|
125
|
-
|
|
47
|
+
**Mandatory.** Hash-based fallback was removed (ADR-EMB-001) — if `fastembed` cannot load, memory operations fail loudly rather than silently degrading. Model auto-downloads to `~/.cache/fastembed` on first use; for offline / sandboxed runs pre-populate the cache or set `FASTEMBED_CACHE`.
|
|
126
48
|
|
|
127
|
-
**
|
|
49
|
+
**Legacy aliases.** Entries embedded by earlier moflo versions may be tagged `Xenova/all-MiniLM-L6-v2` or `onnx`. They share the same vector space and are treated as compatible at search time (`semantic-search.mjs` `COMPATIBLE_MODELS`).
|
|
128
50
|
|
|
129
|
-
Both the search scripts and the MCP memory tools use `fastembed` for
|
|
51
|
+
**Embedding alignment is critical.** Query embeddings MUST match stored embeddings — cosine similarity across model families produces meaningless scores. Both the search scripts and the MCP memory tools use `fastembed` for queries and filter stored entries by `embedding_model`.
|
|
130
52
|
|
|
131
53
|
---
|
|
132
54
|
|
|
133
55
|
## RAG Indexing Pipeline
|
|
134
56
|
|
|
135
|
-
|
|
57
|
+
`index-guidance.mjs`:
|
|
136
58
|
|
|
137
|
-
1.
|
|
138
|
-
2.
|
|
139
|
-
3.
|
|
140
|
-
4.
|
|
141
|
-
5.
|
|
142
|
-
6.
|
|
143
|
-
7.
|
|
59
|
+
1. Scan configured directories for `.md` files
|
|
60
|
+
2. Hash check — skip files whose content hash hasn't changed (`--force` overrides)
|
|
61
|
+
3. Store the full document as `doc-{prefix}-{name}` for complete retrieval
|
|
62
|
+
4. Chunk on `##` headers — each H2 becomes a separate entry
|
|
63
|
+
5. H3 subsections become child chunks with the parent H2 as context prefix
|
|
64
|
+
6. Force-split sections over 4000 chars on paragraph boundaries
|
|
65
|
+
7. Build RAG metadata (`parentDoc`, `prevChunk`, `nextChunk`, `siblings`, `hierarchicalParent/Children`, `contextBefore/After`)
|
|
66
|
+
8. Prepend 20% overlapping context from neighbors
|
|
67
|
+
9. Stale-cleanup pass — drop entries for files no longer on disk
|
|
68
|
+
10. Spawn `build-embeddings.mjs` to vectorize new entries
|
|
144
69
|
|
|
145
|
-
|
|
146
|
-
|---------------|---------|
|
|
147
|
-
| `parentDoc` | Link back to full document |
|
|
148
|
-
| `prevChunk` / `nextChunk` | Sequential navigation |
|
|
149
|
-
| `siblings` | All chunk keys from same document |
|
|
150
|
-
| `hierarchicalParent` / `hierarchicalChildren` | H2->H3 relationships |
|
|
151
|
-
| `contextBefore` / `contextAfter` | 20% overlapping text from adjacent chunks |
|
|
152
|
-
|
|
153
|
-
8. **Prepend context** — Each chunk's searchable content includes overlap from neighbors
|
|
154
|
-
9. **Stale cleanup** — After indexing, remove entries for files that no longer exist on disk
|
|
155
|
-
10. **Background embedding** — Spawn `build-embeddings.mjs` to generate vectors
|
|
156
|
-
|
|
157
|
-
### Configuring Indexed Directories
|
|
158
|
-
|
|
159
|
-
In `moflo.yaml`:
|
|
70
|
+
**Configuration in `moflo.yaml`:**
|
|
160
71
|
|
|
161
72
|
```yaml
|
|
162
73
|
guidance:
|
|
@@ -165,80 +76,62 @@ guidance:
|
|
|
165
76
|
- docs/guides
|
|
166
77
|
```
|
|
167
78
|
|
|
168
|
-
Default
|
|
169
|
-
|
|
170
|
-
Moflo also automatically indexes its own bundled guidance from `node_modules/moflo/.claude/guidance/` when installed as a dependency.
|
|
79
|
+
Default (when no config): `.claude/guidance`, `docs/guides`. Moflo also auto-indexes its own bundled guidance from `node_modules/moflo/.claude/guidance/` when installed as a dependency.
|
|
171
80
|
|
|
172
81
|
---
|
|
173
82
|
|
|
174
83
|
## Search Commands
|
|
175
84
|
|
|
176
|
-
All
|
|
85
|
+
All entry points auto-detect the stored model and generate matching query vectors.
|
|
177
86
|
|
|
178
|
-
**MCP (
|
|
87
|
+
**MCP (preferred):** `mcp__moflo__memory_search` — `query`, `namespace`, `limit`, `threshold`.
|
|
179
88
|
|
|
180
|
-
**CLI (
|
|
89
|
+
**CLI (fallback):**
|
|
181
90
|
```bash
|
|
182
|
-
npx flo memory search --query "your query" --namespace guidance
|
|
91
|
+
npx flo memory search --query "your query" --namespace guidance --limit 5 --threshold 0.3
|
|
183
92
|
```
|
|
184
93
|
|
|
185
|
-
**
|
|
186
|
-
|
|
187
|
-
| Flag | Default | Purpose |
|
|
188
|
-
|------|---------|---------|
|
|
189
|
-
| `--namespace` | all | Filter to specific namespace |
|
|
190
|
-
| `--limit` | 5 | Number of results |
|
|
191
|
-
| `--threshold` | 0.3 | Minimum similarity score |
|
|
192
|
-
| `--json` | false | Output as JSON |
|
|
94
|
+
**Code map search.** When you need to find where a type, service, entity, or component lives, search `code-map` BEFORE Glob/Grep:
|
|
193
95
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
When you need to find where a type, service, entity, or component lives — search `code-map` BEFORE using Glob/Grep:
|
|
197
|
-
|
|
198
|
-
**MCP:** `mcp__moflo__memory_search` — `query: "payment service", namespace: "code-map"`
|
|
199
|
-
|
|
200
|
-
**What code-map contains:**
|
|
201
|
-
|
|
202
|
-
| Chunk prefix | What it answers |
|
|
203
|
-
|--------------|-----------------|
|
|
96
|
+
| Chunk prefix | Answers |
|
|
97
|
+
|--------------|---------|
|
|
204
98
|
| `project:` | "What's in the api project?" |
|
|
205
|
-
| `dir:` | "What types are in
|
|
99
|
+
| `dir:` | "What types are in entities/?" |
|
|
206
100
|
| `iface-map:` | "What implements IPaymentService?" |
|
|
207
101
|
| `type-index:` | "Where is Service defined?" |
|
|
208
102
|
|
|
103
|
+
Use `mcp__moflo__memory_search` with `namespace: "code-map"`.
|
|
104
|
+
|
|
209
105
|
---
|
|
210
106
|
|
|
211
107
|
## Session Start Indexing
|
|
212
108
|
|
|
213
|
-
On every session start, `hooks.mjs` spawns `index-all.mjs
|
|
214
|
-
|
|
215
|
-
| Indexer | Namespace | What it does |
|
|
216
|
-
|---------|-----------|--------------|
|
|
217
|
-
| `index-guidance.mjs` | `guidance` | Chunks markdown, builds RAG links |
|
|
218
|
-
| `generate-code-map.mjs` | `code-map` | Scans source for types, interfaces, directories |
|
|
219
|
-
| `index-tests.mjs` | `tests` | Indexes test structure |
|
|
220
|
-
| `index-patterns.mjs` | `patterns` | Extracts per-file code patterns |
|
|
221
|
-
| `build-embeddings.mjs` | all | Generates vectors for any unembedded entries |
|
|
109
|
+
On every session start, `hooks.mjs` spawns `index-all.mjs`, which runs the full chain incrementally — files whose hash hasn't changed are skipped. Use `--force` to reindex everything.
|
|
222
110
|
|
|
223
|
-
|
|
111
|
+
| Indexer | Namespace |
|
|
112
|
+
|---------|-----------|
|
|
113
|
+
| `index-guidance.mjs` | `guidance` |
|
|
114
|
+
| `generate-code-map.mjs` | `code-map` |
|
|
115
|
+
| `index-tests.mjs` | `tests` |
|
|
116
|
+
| `index-patterns.mjs` | `patterns` |
|
|
117
|
+
| `build-embeddings.mjs` | (generates vectors for any unembedded entries) |
|
|
224
118
|
|
|
225
119
|
---
|
|
226
120
|
|
|
227
|
-
##
|
|
121
|
+
## Writing Guidance That Indexes Well
|
|
228
122
|
|
|
229
|
-
|
|
123
|
+
Authoring rules — Purpose line, imperative voice, 5–30-line H2 sections, decision tables, no decorative headings, See Also block — live in `.claude/guidance/moflo-guidance-rules.md`. Follow that file when writing or editing any guidance.
|
|
230
124
|
|
|
231
|
-
|
|
232
|
-
npm install moflo
|
|
233
|
-
npx flo init
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
Create `.claude/guidance/` with markdown files following the optimization rules above, then:
|
|
125
|
+
The retrieval-specific rules below only apply to docs you want surfaced via `memory_search`:
|
|
237
126
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
127
|
+
| Signal | Why it matters |
|
|
128
|
+
|--------|----------------|
|
|
129
|
+
| `**Purpose:**` line after H1 | First chunk of every doc; primary relevance signal |
|
|
130
|
+
| Domain-specific H2 headings (`## JWT Authentication Pattern`, not `## Pattern`) | Heading text is the chunk's embedding anchor |
|
|
131
|
+
| 1000–4000 char H2 sections | Below 50 chars chunks are dropped; above 6000 chars get force-split mid-thought |
|
|
132
|
+
| Self-contained H2 sections | Each chunk must answer a question without the surrounding doc |
|
|
133
|
+
| Tables over prose for decisions | Structured data parses more reliably than paragraphs |
|
|
134
|
+
| Cross-references in See Also | Builds the navigation graph (`prevChunk`/`nextChunk`/`siblings`) |
|
|
242
135
|
|
|
243
136
|
---
|
|
244
137
|
|
|
@@ -246,19 +139,20 @@ npx flo memory search --query "your domain query" --namespace guidance # Verify
|
|
|
246
139
|
|
|
247
140
|
| Symptom | Cause | Fix |
|
|
248
141
|
|---------|-------|-----|
|
|
249
|
-
| Search returns irrelevant results | Query/stored embedding model mismatch | Auto-detected
|
|
250
|
-
| Low similarity scores | Query
|
|
251
|
-
| "Vector: No" in
|
|
252
|
-
| Entries not found after
|
|
253
|
-
| Bundled moflo guidance not indexed |
|
|
254
|
-
| Empty namespace | Indexer never ran or DB was purged | See
|
|
142
|
+
| Search returns irrelevant results | Query/stored embedding model mismatch (legacy entry) | Auto-detected; verify with `npx flo-search --verbose` |
|
|
143
|
+
| Low similarity scores | Query missing domain terms | Include domain keywords in the query |
|
|
144
|
+
| `"Vector: No"` in `memory_list` | Entry lacks embedding | Run `node bin/build-embeddings.mjs` |
|
|
145
|
+
| Entries not found after editing a file | Indexer hasn't run yet | Restart session or `node bin/index-all.mjs` |
|
|
146
|
+
| Bundled moflo guidance not indexed | Running inside the moflo repo (same dir) | Bundled guidance only indexes when installed as a dependency |
|
|
147
|
+
| Empty namespace | Indexer never ran or DB was purged | See `.claude/guidance/moflo-memorydb-maintenance.md` |
|
|
148
|
+
| Embeddings fail offline | `fastembed` model cache missing | Pre-populate `~/.cache/fastembed` or set `FASTEMBED_CACHE` (see `docs/modules/embeddings.md`) |
|
|
255
149
|
|
|
256
150
|
---
|
|
257
151
|
|
|
258
152
|
## See Also
|
|
259
153
|
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
-
|
|
263
|
-
-
|
|
264
|
-
-
|
|
154
|
+
- `.claude/guidance/moflo-memorydb-maintenance.md` — Database location, schema, purge/reindex procedures
|
|
155
|
+
- `.claude/guidance/moflo-guidance-rules.md` — Universal authoring rules every guidance doc must follow
|
|
156
|
+
- `.claude/guidance/moflo-subagents.md` — Memory-first subagent protocol that uses these search paths
|
|
157
|
+
- `.claude/guidance/moflo-claude-swarm-cohesion.md` — Task & swarm coordination layered on top of memory
|
|
158
|
+
- `.claude/guidance/moflo-core-guidance.md` — Full CLI/MCP reference and Auto-Learning protocol
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
## Database Location
|
|
8
8
|
|
|
9
|
-
- **Path:** `.moflo/moflo.db` — canonical
|
|
9
|
+
- **Path:** `.moflo/moflo.db` — canonical location
|
|
10
10
|
- **Engine:** sql.js (WASM-based SQLite — no native binaries needed)
|
|
11
11
|
- **Single table:** `memory_entries` — stores content, embeddings, and metadata in one table
|
|
12
|
-
- **Legacy path:** `.swarm/memory.db` —
|
|
12
|
+
- **Legacy path:** `.swarm/memory.db` — older consumers may still have this. The launcher migrates it to `.moflo/moflo.db` automatically on session start. After migration the legacy file is renamed `.swarm/memory.db.bak` and is safe to delete once you've verified the canonical DB is healthy (`flo doctor`).
|
|
13
13
|
|
|
14
14
|
## Schema
|
|
15
15
|
|
|
@@ -109,7 +109,7 @@ node bin/build-embeddings.mjs
|
|
|
109
109
|
|
|
110
110
|
## Auto-Reindex on Session Start
|
|
111
111
|
|
|
112
|
-
`hooks.mjs` spawns `index-all.mjs` on session start, which runs the full chain.
|
|
112
|
+
`hooks.mjs` spawns `index-all.mjs` on session start, which runs the full chain. The session-start launcher syncs the indexer scripts into `.claude/scripts/` on every version change so the chain always points at current code.
|
|
113
113
|
|
|
114
114
|
## Recovering From a Legacy DB
|
|
115
115
|
|
|
@@ -131,8 +131,6 @@ flo memory restore-learnings --from .swarm/memory.db.bak
|
|
|
131
131
|
|
|
132
132
|
## See Also
|
|
133
133
|
|
|
134
|
-
- `.claude/guidance/
|
|
135
|
-
- `.claude/guidance/
|
|
136
|
-
- `.claude/guidance/
|
|
137
|
-
- `.claude/guidance/shipped/moflo-subagents.md` — Memory-first protocol that depends on these indexes being healthy
|
|
138
|
-
- `.claude/guidance/internal/guidance-sync.md` — Internal: how guidance content actually flows from `shipped/` into the DB and out to search (three-layer pipeline + cleanup paths)
|
|
134
|
+
- `.claude/guidance/moflo-memory-strategy.md` — When to use which namespace; semantic search query patterns
|
|
135
|
+
- `.claude/guidance/moflo-core-guidance.md` — `flo memory` CLI subcommands and `flo doctor` output
|
|
136
|
+
- `.claude/guidance/moflo-subagents.md` — Memory-first protocol that depends on these indexes being healthy
|
|
@@ -66,7 +66,7 @@ A rewrite rule looks like:
|
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
68
|
{
|
|
69
|
-
name: '
|
|
69
|
+
name: 'record-memory-searched → gate-hook.mjs',
|
|
70
70
|
from: 'node "$CLAUDE_PROJECT_DIR/.claude/helpers/gate.cjs" record-memory-searched',
|
|
71
71
|
to: 'node "$CLAUDE_PROJECT_DIR/.claude/helpers/gate-hook.mjs" record-memory-searched',
|
|
72
72
|
}
|
|
@@ -100,25 +100,23 @@ Failures land on stderr and similarly surface to the agent. If something silentl
|
|
|
100
100
|
| Customise a hook command moflo doesn't manage | Add it to a separate matcher block in `.claude/settings.json` — surgical rewrites only touch the specific `from` strings on the rule list |
|
|
101
101
|
| Disable a moflo gate | Edit the matching block in `moflo.yaml` (e.g., `gates.memory_first: false`); the gate scripts honor these flags |
|
|
102
102
|
|
|
103
|
-
Future versions may add hook-block-level locking to suppress drift detection wholesale
|
|
103
|
+
Future versions may add hook-block-level locking to suppress drift detection wholesale.
|
|
104
104
|
|
|
105
105
|
---
|
|
106
106
|
|
|
107
107
|
## Troubleshooting
|
|
108
108
|
|
|
109
|
-
**"My `.claude/settings.json` was modified after a session restart."** — Look at the launcher's stdout in the session-start additionalContext. The line beginning `moflo: updated .claude/settings.json` lists every change in plain English. If you don't recognise a rewrite,
|
|
109
|
+
**"My `.claude/settings.json` was modified after a session restart."** — Look at the launcher's stdout in the session-start additionalContext. The line beginning `moflo: updated .claude/settings.json` lists every change in plain English. If you don't recognise a rewrite, the rule name in the launcher source (`HOOK_REWRITE_RULES`) describes what each fix does.
|
|
110
110
|
|
|
111
111
|
**"Helper scripts disappeared from `.claude/helpers/`."** — The launcher tracks installed files via `.moflo/installed-files.json` and re-syncs missing ones on every start. Open and close a Claude Code session; if the file doesn't come back, check `.moflo/manifest` write permissions or run `flo doctor --fix`.
|
|
112
112
|
|
|
113
|
-
**"Hooks ran but the gate isn't reset on new prompts."** — Verify `UserPromptSubmit` includes a hook calling `gate-hook.mjs prompt-reminder`. If missing, `repairHookWiring()` adds it on next session start. If still missing after restart, the gate may be running through `gate.cjs` directly —
|
|
113
|
+
**"Hooks ran but the gate isn't reset on new prompts."** — Verify `UserPromptSubmit` includes a hook calling `gate-hook.mjs prompt-reminder`. If missing, `repairHookWiring()` adds it on next session start. If still missing after restart, the gate may be running through `gate.cjs` directly — `gate-hook.mjs` is the wrapper that adds prompt-submit reset behavior; `gate.cjs` direct calls bypass it.
|
|
114
114
|
|
|
115
|
-
**"I want to inspect what would be rewritten without actually changing my settings."** — The current launcher applies rewrites on every start.
|
|
115
|
+
**"I want to inspect what would be rewritten without actually changing my settings."** — The current launcher applies rewrites on every start. A manual dry-run mode is planned but not yet exposed.
|
|
116
116
|
|
|
117
117
|
---
|
|
118
118
|
|
|
119
119
|
## See Also
|
|
120
120
|
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
- Internal-only: `internal/upgrade-contract.md` documents the contract from a moflo-developer perspective, including the historical violations (sandbox, settings.json drift) that motivated the self-heal mechanism.
|
|
124
|
-
- Internal-only: `internal/guidance-sync.md` — Sibling self-heal mechanism for shipped guidance content (this doc covers settings.json; that one covers the guidance pipeline).
|
|
121
|
+
- `.claude/guidance/moflo-core-guidance.md` — Session-start cost expectations and what the launcher syncs into `.claude/`.
|
|
122
|
+
- `.claude/guidance/moflo-cross-platform.md` — Why hook commands always use `node "$CLAUDE_PROJECT_DIR/..."` paths.
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
|
|
21
21
|
## Single Source Tree Under `src/cli/`
|
|
22
22
|
|
|
23
|
-
**The entire moflo source lives at `src/cli/`** after the workspace-collapse
|
|
23
|
+
**The entire moflo source lives at `src/cli/`** after the workspace-collapse refactor (ADR-0001). There is no longer a `src/modules/<pkg>/` workspace tree, no per-package `tsconfig.json`/`package.json`, and no `@moflo/<pkg>` workspace-package specifiers.
|
|
24
24
|
|
|
25
25
|
| Pattern | Status |
|
|
26
26
|
|---------|--------|
|
|
27
27
|
| `import { Foo } from '../bar.js'` | CORRECT — same-tree relative import |
|
|
28
28
|
| `import { Foo } from '@moflo/neural'` | WRONG — that workspace package no longer exists |
|
|
29
29
|
| `import { Foo } from '../../../../modules/<pkg>/...'` | WRONG — fixed-depth pre-collapse paths (banned by ESLint per [feedback_no_fixed_depth_paths.md](../../docs/adr/0001-collapse-moflo-workspace-packages.md)) |
|
|
30
|
-
| `import { Foo } from 'src/modules/...'` | WRONG — that tree was deleted
|
|
30
|
+
| `import { Foo } from 'src/modules/...'` | WRONG — that tree was deleted during the workspace collapse |
|
|
31
31
|
|
|
32
32
|
The drift guard at `src/cli/__tests__/services/published-package-drift-guard.test.ts` enforces that no `@moflo/*` bare specifiers reappear in source.
|
|
33
33
|
|
|
@@ -70,13 +70,13 @@ Compiled output is generated by `npm run build` (single `tsc` run from repo root
|
|
|
70
70
|
|
|
71
71
|
## Async-Eligible Operations Must Be Async By Default
|
|
72
72
|
|
|
73
|
-
**Use the async API for any operation that has one, unless a documented reason forces sync.** Sync IO and busy-waits block the event loop — on a hot path that pins a CPU core, stalls timers, and turns a "best-effort" failure into a hang.
|
|
73
|
+
**Use the async API for any operation that has one, unless a documented reason forces sync.** Sync IO and busy-waits block the event loop — on a hot path that pins a CPU core, stalls timers, and turns a "best-effort" failure into a hang. A representative incident burned ~5s of CPU per session to a `while (Date.now() < end)` busy-wait that had been pasted into an already-async launcher.
|
|
74
74
|
|
|
75
75
|
| Operation | Use | Avoid |
|
|
76
76
|
|-----------|-----|-------|
|
|
77
77
|
| File IO inside an `async` function | `fs/promises` (`readFile`, `copyFile`, `mkdir`) | `*Sync` variants |
|
|
78
78
|
| Delays | `await new Promise(r => setTimeout(r, ms))` | `while (Date.now() < end)` busy-wait |
|
|
79
|
-
| Spawning long-running children | `await new Promise` around `spawn`/`execFile` | `execFileSync`/`spawnSync` (Windows timeouts orphan
|
|
79
|
+
| Spawning long-running children | `await new Promise` around `spawn`/`execFile` | `execFileSync`/`spawnSync` (on Windows, timeouts orphan child processes) |
|
|
80
80
|
|
|
81
81
|
**Sync is OK only when:** the function cannot be `async` (top-level config reader before any await; certain CommonJS hooks); the IO is microscopic on a known-fast path (one `existsSync` probe, one tiny `readFileSync`); or conversion churn outweighs the benefit. Document the reason in a one-line comment.
|
|
82
82
|
|
|
@@ -98,6 +98,6 @@ Before creating any new source file, verify:
|
|
|
98
98
|
## See Also
|
|
99
99
|
|
|
100
100
|
- `CLAUDE.md` — Project-wide rules, consumer project checklist
|
|
101
|
-
- `.claude/guidance/
|
|
101
|
+
- `.claude/guidance/moflo-guidance-rules.md` — Rules for writing guidance docs
|
|
102
102
|
- `docs/BUILD.md` — Build and publish process
|
|
103
103
|
- `docs/adr/0001-collapse-moflo-workspace-packages.md` — The ADR that documents the collapse
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
**Do NOT create a connector for each external service.** Instead, compose the built-in connectors in spell steps. A Slack integration is an `http` connector call with the Slack API URL and token — not a `slack` connector.
|
|
18
18
|
|
|
19
|
-
This design
|
|
19
|
+
This design replaced an earlier per-service connector approach (Slack, OneDrive, Gmail, Google Drive) with generalized wrappers backed by capability enforcement.
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
@@ -128,6 +128,5 @@ If you do need one:
|
|
|
128
128
|
|
|
129
129
|
## See Also
|
|
130
130
|
|
|
131
|
-
- `.claude/guidance/
|
|
132
|
-
- `.claude/guidance/
|
|
133
|
-
- `.claude/guidance/shipped/moflo-spell-engine-architecture.md` — Architecture decisions
|
|
131
|
+
- `.claude/guidance/moflo-spell-sandboxing.md` — CapabilityGateway and enforcement rules
|
|
132
|
+
- `.claude/guidance/moflo-spell-engine.md` — Running spells, step command types
|
|
@@ -120,7 +120,6 @@ const runner = createRunner({
|
|
|
120
120
|
|
|
121
121
|
## See Also
|
|
122
122
|
|
|
123
|
-
- `.claude/guidance/
|
|
124
|
-
- `.claude/guidance/
|
|
125
|
-
- `.claude/guidance/
|
|
126
|
-
- `.claude/guidance/shipped/moflo-spell-engine-architecture.md` — Architecture decisions for the pluggable step loader
|
|
123
|
+
- `.claude/guidance/moflo-spell-engine.md` — Built-in step types, spell definition format, runner lifecycle, error codes
|
|
124
|
+
- `.claude/guidance/moflo-spell-sandboxing.md` — Capability declarations a custom step must include and how the sandbox enforces them
|
|
125
|
+
- `.claude/guidance/moflo-spell-connectors.md` — When to write a connector instead of a custom step (resource-shaped vs. action-shaped extension)
|