preflight-mcp 0.1.2 → 0.1.4
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/README.md +49 -142
- package/README.zh-CN.md +141 -124
- package/dist/ast/treeSitter.js +588 -0
- package/dist/bundle/analysis.js +47 -0
- package/dist/bundle/context7.js +65 -36
- package/dist/bundle/facts.js +829 -0
- package/dist/bundle/github.js +34 -3
- package/dist/bundle/githubArchive.js +102 -29
- package/dist/bundle/overview.js +226 -48
- package/dist/bundle/service.js +250 -130
- package/dist/config.js +30 -3
- package/dist/context7/client.js +5 -2
- package/dist/evidence/dependencyGraph.js +1136 -0
- package/dist/http/server.js +109 -0
- package/dist/jobs/progressTracker.js +191 -0
- package/dist/search/sqliteFts.js +150 -10
- package/dist/server.js +340 -326
- package/dist/trace/service.js +108 -0
- package/dist/trace/store.js +170 -0
- package/package.json +4 -2
- package/dist/bundle/deepwiki.js +0 -206
package/README.md
CHANGED
|
@@ -15,12 +15,15 @@ Each bundle contains:
|
|
|
15
15
|
|
|
16
16
|
## Features
|
|
17
17
|
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
18
|
+
- **13 MCP tools** to create/update/repair/search/read bundles, generate evidence graphs, and manage trace links
|
|
19
|
+
- **Progress tracking**: Real-time progress reporting for long-running operations (create/update bundles)
|
|
20
|
+
- **Bundle integrity check**: Prevents operations on incomplete bundles with helpful error messages
|
|
21
|
+
- **De-duplication with in-progress lock**: Prevent duplicate bundle creation even during MCP timeouts
|
|
22
|
+
- **Global dependency graph**: Generate project-wide import relationship graphs
|
|
23
|
+
- **Batch file reading**: Read all key bundle files in a single call
|
|
20
24
|
- **Resilient GitHub fetching**: configurable git clone timeout + GitHub archive (zipball) fallback
|
|
21
25
|
- **Offline repair**: rebuild missing/empty derived artifacts (index/guides/overview) without re-fetching
|
|
22
26
|
- **Static facts extraction** via `analysis/FACTS.json` (non-LLM)
|
|
23
|
-
- **Evidence-based verification** to reduce hallucinations
|
|
24
27
|
- **Resources** to read bundle files via `preflight://...` URIs
|
|
25
28
|
- **Multi-path mirror backup** for cloud storage redundancy
|
|
26
29
|
- **Resilient storage** with automatic failover when mounts are unavailable
|
|
@@ -28,75 +31,6 @@ Each bundle contains:
|
|
|
28
31
|
- **Fast background deletion** with 100-300x performance improvement
|
|
29
32
|
- **Auto-cleanup** on startup for historical orphan bundles
|
|
30
33
|
|
|
31
|
-
## Architecture Improvements (v0.1.2)
|
|
32
|
-
|
|
33
|
-
### 🚀 Atomic Bundle Creation
|
|
34
|
-
**Problem**: Bundle creation failures could leave incomplete orphan directories.
|
|
35
|
-
|
|
36
|
-
**Solution**: Temporary directory + atomic rename pattern:
|
|
37
|
-
1. Create bundle in `tmpDir/bundles-wip/` (invisible to list)
|
|
38
|
-
2. Validate completeness before making visible
|
|
39
|
-
3. Atomic rename/move to final location
|
|
40
|
-
4. Automatic cleanup on any failure
|
|
41
|
-
|
|
42
|
-
**Benefits**:
|
|
43
|
-
- ✅ Zero orphan bundles
|
|
44
|
-
- 🔒 Crash-safe (temp dirs auto-cleaned)
|
|
45
|
-
- 📏 Validation before visibility
|
|
46
|
-
- 🔄 Cross-filesystem fallback
|
|
47
|
-
|
|
48
|
-
### ⚡ Fast Background Deletion
|
|
49
|
-
**Problem**: Deleting large bundles could timeout (10+ seconds).
|
|
50
|
-
|
|
51
|
-
**Solution**: Rename + background deletion:
|
|
52
|
-
1. Instant rename to `.deleting.{timestamp}` (<100ms)
|
|
53
|
-
2. Background deletion (fire-and-forget)
|
|
54
|
-
3. Automatic cleanup of `.deleting` dirs on startup
|
|
55
|
-
|
|
56
|
-
**Benefits**:
|
|
57
|
-
- ⚡ 100-300x faster response (<100ms)
|
|
58
|
-
- 🔄 No blocking operations
|
|
59
|
-
- 👁️ Invisible to list (non-UUID format)
|
|
60
|
-
- 🛡️ Fallback to direct delete on rename failure
|
|
61
|
-
|
|
62
|
-
### 🔧 Auto-Cleanup on Startup
|
|
63
|
-
**Problem**: Historical orphan bundles need manual cleanup.
|
|
64
|
-
|
|
65
|
-
**Solution**: Automatic cleanup on MCP server startup:
|
|
66
|
-
1. Scans storage directories for invalid bundles
|
|
67
|
-
2. Checks manifest.json validity
|
|
68
|
-
3. Deletes orphans older than 1 hour (safety margin)
|
|
69
|
-
4. Cleans `.deleting` residues
|
|
70
|
-
|
|
71
|
-
**Benefits**:
|
|
72
|
-
- 🤖 Fully automatic
|
|
73
|
-
- 🛡️ Safe with 1-hour age threshold
|
|
74
|
-
- ⚡ Fast when no orphans (<10ms)
|
|
75
|
-
- 🚫 Non-blocking background execution
|
|
76
|
-
|
|
77
|
-
### 🧹 Manual Cleanup Tool
|
|
78
|
-
**New Tool**: `preflight_cleanup_orphans`
|
|
79
|
-
|
|
80
|
-
Manually trigger orphan cleanup with full control:
|
|
81
|
-
```json
|
|
82
|
-
{
|
|
83
|
-
"dryRun": true, // Only report, don't delete
|
|
84
|
-
"minAgeHours": 1 // Age threshold
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### 🔍 UUID Validation
|
|
89
|
-
List and cleanup now strictly filter by UUID format:
|
|
90
|
-
- ✅ Only valid UUID v4 bundle IDs
|
|
91
|
-
- 🚫 Filters out system directories (`#recycle`, `tmp`)
|
|
92
|
-
- 🚫 Filters out `.deleting` directories
|
|
93
|
-
- 🛡️ Protects user custom directories
|
|
94
|
-
|
|
95
|
-
For technical details, see:
|
|
96
|
-
- [ISSUES_ANALYSIS.md](./ISSUES_ANALYSIS.md) - Root cause analysis
|
|
97
|
-
- [IMPLEMENTATION_SUMMARY.md](./IMPLEMENTATION_SUMMARY.md) - Implementation details
|
|
98
|
-
- [CLEANUP_STRATEGY.md](./CLEANUP_STRATEGY.md) - MCP-specific cleanup design
|
|
99
|
-
|
|
100
34
|
## Table of Contents
|
|
101
35
|
|
|
102
36
|
- [Requirements](#requirements)
|
|
@@ -187,21 +121,6 @@ Run end-to-end smoke test:
|
|
|
187
121
|
npm run smoke
|
|
188
122
|
```
|
|
189
123
|
|
|
190
|
-
This will test bundle creation, search, and update operations.
|
|
191
|
-
|
|
192
|
-
## Smoke test
|
|
193
|
-
Runs an end-to-end stdio client that:
|
|
194
|
-
- spawns the server
|
|
195
|
-
- calls `preflight_create_bundle`
|
|
196
|
-
- reads `preflight://bundles` and `START_HERE.md`
|
|
197
|
-
- searches the bundle
|
|
198
|
-
- calls `preflight_update_bundle`
|
|
199
|
-
|
|
200
|
-
Command:
|
|
201
|
-
- `npm run smoke`
|
|
202
|
-
|
|
203
|
-
Note: the smoke test clones `octocat/Hello-World` from GitHub, so it needs internet access.
|
|
204
|
-
|
|
205
124
|
## Tools (13 total)
|
|
206
125
|
|
|
207
126
|
### `preflight_list_bundles`
|
|
@@ -209,7 +128,7 @@ List bundle IDs in storage.
|
|
|
209
128
|
- Triggers: "show bundles", "查看bundle", "有哪些bundle"
|
|
210
129
|
|
|
211
130
|
### `preflight_create_bundle`
|
|
212
|
-
Create a new bundle from
|
|
131
|
+
Create a new bundle from GitHub repos or local directories.
|
|
213
132
|
- Triggers: "index this repo", "学习这个项目", "创建bundle"
|
|
214
133
|
|
|
215
134
|
Key semantics:
|
|
@@ -220,21 +139,22 @@ Key semantics:
|
|
|
220
139
|
- `updateExisting`: update the existing bundle then return it
|
|
221
140
|
- `createNew`: bypass de-duplication
|
|
222
141
|
- GitHub ingest uses **shallow clone**; if `git clone` fails, it will fall back to **GitHub archive (zipball)**.
|
|
223
|
-
- Supports `repos.kind: "local"` to ingest from a local directory
|
|
142
|
+
- Supports `repos.kind: "local"` to ingest from a local directory.
|
|
224
143
|
|
|
225
144
|
Input (example):
|
|
226
|
-
- `repos`: `[{ kind: "github", repo: "owner/repo" }, { kind: "local", repo: "owner/repo", path: "/path/to/dir" }
|
|
145
|
+
- `repos`: `[{ kind: "github", repo: "owner/repo" }, { kind: "local", repo: "owner/repo", path: "/path/to/dir" }]`
|
|
227
146
|
- `libraries`: `["nextjs", "react"]` (Context7; optional)
|
|
228
147
|
- `topics`: `["routing", "api"]` (Context7 topic filter; optional)
|
|
229
148
|
- `ifExists`: `"error" | "returnExisting" | "updateExisting" | "createNew"`
|
|
230
149
|
|
|
231
|
-
|
|
232
|
-
Read a file from bundle (OVERVIEW.md, START_HERE.md, AGENTS.md, or any repo file).
|
|
233
|
-
- Triggers: "查看概览", "项目概览", "看README"
|
|
150
|
+
**Note**: If the bundle contains code files, consider using `preflight_evidence_dependency_graph` for dependency analysis or `preflight_trace_upsert` for trace links.
|
|
234
151
|
|
|
235
|
-
### `
|
|
236
|
-
|
|
237
|
-
-
|
|
152
|
+
### `preflight_read_file`
|
|
153
|
+
Read file(s) from bundle. Two modes:
|
|
154
|
+
- **Batch mode** (omit `file`): Returns ALL key files (OVERVIEW.md, START_HERE.md, AGENTS.md, manifest.json, repo READMEs) in one call
|
|
155
|
+
- **Single file mode** (provide `file`): Returns that specific file
|
|
156
|
+
- Triggers: "查看bundle", "bundle概览", "项目信息", "show bundle"
|
|
157
|
+
- Use `file: "manifest.json"` to get bundle metadata (repos, timestamps, tags, etc.)
|
|
238
158
|
|
|
239
159
|
### `preflight_delete_bundle`
|
|
240
160
|
Delete/remove a bundle permanently.
|
|
@@ -248,14 +168,6 @@ Optional parameters:
|
|
|
248
168
|
- `checkOnly`: If true, only check for updates without applying.
|
|
249
169
|
- `force`: If true, force rebuild even if no changes detected.
|
|
250
170
|
|
|
251
|
-
### `preflight_update_all_bundles`
|
|
252
|
-
Batch update all bundles at once.
|
|
253
|
-
- Triggers: "批量更新", "全部刷新"
|
|
254
|
-
|
|
255
|
-
### `preflight_find_bundle`
|
|
256
|
-
Check whether a bundle already exists for the given inputs (no fetching, no changes).
|
|
257
|
-
- Use when your UI/agent wants to decide whether to create/update.
|
|
258
|
-
|
|
259
171
|
### `preflight_repair_bundle`
|
|
260
172
|
Offline repair for a bundle (no fetching): rebuild missing/empty derived artifacts.
|
|
261
173
|
- Rebuilds `indexes/search.sqlite3`, `START_HERE.md`, `AGENTS.md`, `OVERVIEW.md` when missing/empty.
|
|
@@ -266,13 +178,12 @@ Full-text search across ingested docs/code (line-based SQLite FTS5).
|
|
|
266
178
|
- Triggers: "搜索bundle", "在仓库中查找", "搜代码"
|
|
267
179
|
|
|
268
180
|
Important: **this tool is strictly read-only**.
|
|
269
|
-
- `ensureFresh` / `maxAgeHours` are **deprecated** and will error if provided.
|
|
270
181
|
- To update: call `preflight_update_bundle`, then search again.
|
|
271
182
|
- To repair: call `preflight_repair_bundle`, then search again.
|
|
272
183
|
|
|
273
184
|
### `preflight_search_by_tags`
|
|
274
185
|
Search across multiple bundles filtered by tags (line-based SQLite FTS5).
|
|
275
|
-
- Triggers: "search in MCP bundles", "
|
|
186
|
+
- Triggers: "search in MCP bundles", "在MCP项目中搜索", "搜索所有agent"
|
|
276
187
|
|
|
277
188
|
Notes:
|
|
278
189
|
- This tool is read-only and **does not auto-repair**.
|
|
@@ -283,18 +194,19 @@ Optional parameters:
|
|
|
283
194
|
- `scope`: Search scope (`docs`, `code`, or `all`)
|
|
284
195
|
- `limit`: Max total hits across all bundles
|
|
285
196
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
-
|
|
197
|
+
### `preflight_evidence_dependency_graph`
|
|
198
|
+
Generate an evidence-based dependency graph. Two modes:
|
|
199
|
+
- **Target mode** (provide `target.file`): Analyze a specific file's imports and callers
|
|
200
|
+
- **Global mode** (omit `target`): Generate project-wide import graph of all code files
|
|
201
|
+
- Deterministic output with source ranges for edges.
|
|
202
|
+
- Uses Tree-sitter parsing when `PREFLIGHT_AST_ENGINE=wasm`; falls back to regex extraction otherwise.
|
|
203
|
+
- Emits `imports` edges (file → module) and `imports_resolved` edges (file → internal file).
|
|
289
204
|
|
|
290
|
-
### `
|
|
291
|
-
|
|
292
|
-
- Triggers: "验证说法", "找证据", "这个对吗"
|
|
205
|
+
### `preflight_trace_upsert`
|
|
206
|
+
Upsert traceability links (commit↔ticket, symbol↔test, code↔doc, etc.) for a bundle.
|
|
293
207
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
- To update: call `preflight_update_bundle`, then verify again.
|
|
297
|
-
- To repair: call `preflight_repair_bundle`, then verify again.
|
|
208
|
+
### `preflight_trace_query`
|
|
209
|
+
Query traceability links (fast when `bundleId` is provided; can scan across bundles when omitted).
|
|
298
210
|
|
|
299
211
|
### `preflight_cleanup_orphans`
|
|
300
212
|
Remove incomplete or corrupted bundles (bundles without valid manifest.json).
|
|
@@ -304,14 +216,16 @@ Parameters:
|
|
|
304
216
|
- `dryRun` (default: true): Only report orphans without deleting
|
|
305
217
|
- `minAgeHours` (default: 1): Only clean bundles older than N hours
|
|
306
218
|
|
|
307
|
-
Output:
|
|
308
|
-
- `totalFound`: Number of orphan bundles found
|
|
309
|
-
- `totalCleaned`: Number of orphan bundles deleted
|
|
310
|
-
- `details`: Per-directory breakdown
|
|
311
|
-
|
|
312
219
|
Note: This is also automatically executed on server startup (background, non-blocking).
|
|
313
220
|
|
|
221
|
+
### `preflight_get_task_status`
|
|
222
|
+
Check status of bundle creation/update tasks (progress tracking).
|
|
223
|
+
- Triggers: "check progress", "what is the status", "查看任务状态", "下载进度"
|
|
224
|
+
- Query by `taskId` (from error), `fingerprint`, or `repos`
|
|
225
|
+
- Shows: phase, progress percentage, message, elapsed time
|
|
226
|
+
|
|
314
227
|
## Resources
|
|
228
|
+
|
|
315
229
|
### `preflight://bundles`
|
|
316
230
|
Static JSON listing of bundles and their main entry files.
|
|
317
231
|
|
|
@@ -323,6 +237,7 @@ Examples:
|
|
|
323
237
|
- `preflight://bundle/<id>/file/repos%2Fowner%2Frepo%2Fnorm%2FREADME.md`
|
|
324
238
|
|
|
325
239
|
## Error semantics (stable, UI-friendly)
|
|
240
|
+
|
|
326
241
|
Most tool errors are wrapped with a stable, machine-parseable prefix:
|
|
327
242
|
- `[preflight_error kind=<kind>] <message>`
|
|
328
243
|
|
|
@@ -332,7 +247,6 @@ Common kinds:
|
|
|
332
247
|
- `invalid_path` (unsafe path traversal attempt)
|
|
333
248
|
- `permission_denied`
|
|
334
249
|
- `index_missing_or_corrupt`
|
|
335
|
-
- `deprecated_parameter`
|
|
336
250
|
- `unknown`
|
|
337
251
|
|
|
338
252
|
This is designed so UIs/agents can reliably decide whether to:
|
|
@@ -341,6 +255,7 @@ This is designed so UIs/agents can reliably decide whether to:
|
|
|
341
255
|
- prompt the user for a different bundleId/path
|
|
342
256
|
|
|
343
257
|
## Environment variables
|
|
258
|
+
|
|
344
259
|
### Storage
|
|
345
260
|
- `PREFLIGHT_STORAGE_DIR`: bundle storage dir (default: `~/.preflight-mcp/bundles`)
|
|
346
261
|
- `PREFLIGHT_STORAGE_DIRS`: **multi-path mirror backup** (semicolon-separated, e.g., `D:\cloud1\preflight;E:\cloud2\preflight`)
|
|
@@ -348,8 +263,14 @@ This is designed so UIs/agents can reliably decide whether to:
|
|
|
348
263
|
- `PREFLIGHT_MAX_FILE_BYTES`: max bytes per file (default: 512 KiB)
|
|
349
264
|
- `PREFLIGHT_MAX_TOTAL_BYTES`: max bytes per repo ingest (default: 50 MiB)
|
|
350
265
|
|
|
351
|
-
### Analysis
|
|
352
|
-
- `PREFLIGHT_ANALYSIS_MODE`: Static analysis mode - `none`
|
|
266
|
+
### Analysis & evidence
|
|
267
|
+
- `PREFLIGHT_ANALYSIS_MODE`: Static analysis mode - `none` | `quick` | `full` (default: `full`). Controls generation of `analysis/FACTS.json`.
|
|
268
|
+
- `PREFLIGHT_AST_ENGINE`: AST engine used by some evidence tools - `wasm` (default) or `native`.
|
|
269
|
+
|
|
270
|
+
### Built-in HTTP API
|
|
271
|
+
- `PREFLIGHT_HTTP_ENABLED`: enable/disable REST API (default: true)
|
|
272
|
+
- `PREFLIGHT_HTTP_HOST`: REST listen host (default: 127.0.0.1)
|
|
273
|
+
- `PREFLIGHT_HTTP_PORT`: REST listen port (default: 37123)
|
|
353
274
|
|
|
354
275
|
### GitHub & Context7
|
|
355
276
|
- `GITHUB_TOKEN`: optional; used for GitHub API/auth patterns and GitHub archive fallback (public repos usually work without it)
|
|
@@ -358,19 +279,19 @@ This is designed so UIs/agents can reliably decide whether to:
|
|
|
358
279
|
- `CONTEXT7_MCP_URL`: optional; defaults to Context7 MCP endpoint
|
|
359
280
|
|
|
360
281
|
## Bundle layout (on disk)
|
|
282
|
+
|
|
361
283
|
Inside a bundle directory:
|
|
362
284
|
- `manifest.json` (includes `fingerprint`, `displayName`, `tags`, and per-repo `source`)
|
|
363
285
|
- `START_HERE.md`
|
|
364
286
|
- `AGENTS.md`
|
|
365
287
|
- `OVERVIEW.md`
|
|
366
288
|
- `indexes/search.sqlite3`
|
|
367
|
-
-
|
|
289
|
+
- `analysis/FACTS.json` (static analysis)
|
|
290
|
+
- `trace/trace.sqlite3` (traceability links; created on demand)
|
|
368
291
|
- `repos/<owner>/<repo>/raw/...`
|
|
369
292
|
- `repos/<owner>/<repo>/norm/...` (GitHub/local snapshots)
|
|
370
|
-
- `deepwiki/<owner>/<repo>/norm/index.md` (DeepWiki sources)
|
|
371
|
-
- `deepwiki/<owner>/<repo>/meta.json`
|
|
372
293
|
- `libraries/context7/<...>/meta.json`
|
|
373
|
-
- `libraries/context7/<...>/docs-page-1.md`
|
|
294
|
+
- `libraries/context7/<...>/docs-page-1.md`
|
|
374
295
|
|
|
375
296
|
## Multi-device sync & mirror backup
|
|
376
297
|
|
|
@@ -444,20 +365,6 @@ If you encounter any issues or have questions:
|
|
|
444
365
|
|
|
445
366
|
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
446
367
|
|
|
447
|
-
The MIT License allows you to:
|
|
448
|
-
- Use commercially
|
|
449
|
-
- Modify
|
|
450
|
-
- Distribute
|
|
451
|
-
- Use privately
|
|
452
|
-
|
|
453
|
-
With the only requirement being to include the original copyright and license notice.
|
|
454
|
-
|
|
455
|
-
## Acknowledgments
|
|
456
|
-
|
|
457
|
-
- Built on the [Model Context Protocol](https://modelcontextprotocol.io/)
|
|
458
|
-
- Uses SQLite FTS5 for efficient full-text search
|
|
459
|
-
- Inspired by the need for evidence-based AI assistance
|
|
460
|
-
|
|
461
368
|
---
|
|
462
369
|
|
|
463
370
|
Made with ❤️ for the AI developer community
|