ai-spector 0.8.1 → 0.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-spector",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Cursor-first documentation workflow: traceability graph, SRS/basic/detail design templates, and ai-spector CLI",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,51 +1,64 @@
1
1
  # AI Spector — Claude Agent Rules
2
2
 
3
- You are working in an **AI Spector** managed project. The agent workflow is: read skills, run `npx ai-spector` CLI, report results. You do not write doc content from scratch — CLI + skills do the work.
3
+ You are working in an **AI Spector** managed project. The agent workflow is: read skills, call **MCP tools** (preferred) or `npx ai-spector` CLI (fallback), report results. You do not write doc content from scratch — MCP tools / CLI + skills do the work.
4
4
 
5
5
  Enable all skills under `.claude/skills/` before starting.
6
6
 
7
7
  ## Mandatory Rules
8
8
 
9
- ### 1. Refresh index before any staleness check
9
+ ### 1. MCP first, CLI fallback
10
+
11
+ When the `ai-spector` MCP server is available, **call the MCP tool** instead of shelling out to `npx ai-spector`.
12
+
13
+ | Operation | MCP tool | CLI fallback |
14
+ |-----------|----------|--------------|
15
+ | Re-index project | `index({})` | `npx ai-spector index` |
16
+ | Merge knowledge → graph | `graph_merge({ fromKnowledge: true })` | `npx ai-spector graph merge --from-knowledge` |
17
+ | Validate graph | `graph_validate({})` | `npx ai-spector graph validate` |
18
+ | Impact analysis | `graph_impact({ originId, change })` | `npx ai-spector graph impact …` |
19
+ | Walk graph from node | `graph_query({ id })` | `npx ai-spector graph query <id> --json` |
20
+ | **Analyze data-source** | *(CLI only — no MCP tool)* | `npx ai-spector analyze` |
21
+
22
+ ### 2. Refresh index before any staleness check
10
23
 
11
24
  Before checking translation status, pending queue, or "what's outdated":
12
25
 
13
- ```bash
14
- npx ai-spector index
26
+ ```
27
+ index({}) # MCP preferred
28
+ npx ai-spector index # CLI fallback
15
29
  ```
16
30
 
17
31
  Then read the queue. **Never read `.ai-spector/.docflow/translation-queue/pending.json` without running index first** — the queue is only accurate after indexing.
18
32
 
19
- ### 2. Check impact before finishing any doc edit
33
+ ### 3. Check impact before finishing any doc edit
20
34
 
21
35
  After editing any file under `docs/srs/`, `docs/basic-design/`, or `docs/detail-design/`, run impact before closing the task:
22
36
 
23
- ```bash
24
- npx ai-spector graph impact --git --change content_change --json
37
+ ```
38
+ graph_impact({ git: true, change: "content_change" }) # MCP preferred
39
+ npx ai-spector graph impact --git --change content_change --json # CLI fallback
25
40
  ```
26
41
 
27
- Then run index to refresh the translation queue:
42
+ Then refresh index:
28
43
 
29
- ```bash
30
- npx ai-spector index
44
+ ```
45
+ index({})
31
46
  ```
32
47
 
33
48
  Skip only when the user explicitly says it was a typo-only fix with no traceability concern.
34
49
 
35
- ### 3. Use CLI and graph — not file search
36
-
37
- When you need to find, query, or understand the project graph:
50
+ ### 4. Use MCP/graph — not file search
38
51
 
39
- | Need | Use |
40
- |------|-----|
41
- | Find what needs regeneration | `npx ai-spector graph impact` |
42
- | Find doc/section/node by exact ID | `npx ai-spector graph query <id> --json` |
43
- | Find doc/section/node by concept | `graph_query_fuzzy(query: "…")` (MCP) — requires CocoIndex |
44
- | Search docs by meaning | `docs_search(query: "…")` (MCP) — requires CocoIndex |
45
- | Check graph health | `npx ai-spector graph validate` |
46
- | See pending translations | `npx ai-spector lang queue pending --json` (after index) |
52
+ | Need | MCP (preferred) | CLI fallback |
53
+ |------|-----------------|--------------|
54
+ | Find what needs regeneration | `graph_impact({ git: true, change: "content_change" })` | `npx ai-spector graph impact --git --json` |
55
+ | Find node by exact ID | `graph_query({ id: "…" })` | `npx ai-spector graph query <id> --json` |
56
+ | Find node by concept | `graph_query_fuzzy(query: "…")` — requires CocoIndex | — |
57
+ | Search docs by meaning | `docs_search(query: "…")` — requires CocoIndex | — |
58
+ | Check graph health | `graph_validate({})` | `npx ai-spector graph validate` |
59
+ | See pending translations | *(CLI only)* | `npx ai-spector lang queue pending --json` (after index) |
47
60
 
48
- **Only fall back to `grep` or `Read` when the CLI returns no results or you need raw file content for editing.**
61
+ **Only fall back to `grep` or `Read` when the tool returns no results or you need raw file content for editing.**
49
62
 
50
63
  ## Skill → task mapping
51
64
 
@@ -64,13 +77,25 @@ When you need to find, query, or understand the project graph:
64
77
  | Resolve translations | `ai-spector-resolve-translation` |
65
78
  | Resolve comments | `ai-spector-resolve-comments` |
66
79
 
67
- ## CLI quick reference
80
+ ## Quick reference
81
+
82
+ ### MCP tools (prefer these)
83
+
84
+ | Tool | Purpose |
85
+ |------|---------|
86
+ | `index({})` | Refresh fingerprints + translation queue |
87
+ | `graph_merge({ fromKnowledge: true })` | Merge knowledge.json into graph |
88
+ | `graph_validate({})` | Check graph integrity |
89
+ | `graph_impact({ git: true, change: "content_change" })` | Impact of current git diff |
90
+ | `graph_query({ id: "…" })` | Walk graph from a node |
91
+
92
+ ### CLI (fallback / MCP-unavailable or no tool equivalent)
68
93
 
69
94
  ```bash
70
- npx ai-spector analyze # ingest data-source, build graph
71
- npx ai-spector index # refresh fingerprints + translation queue
72
- npx ai-spector graph validate # check graph integrity
73
- npx ai-spector graph impact --git --json # impact of current git diff (+ semantic suggestions if CocoIndex configured)
95
+ npx ai-spector analyze # ingest data-source, build graph (no MCP equivalent)
96
+ npx ai-spector index # fallback for index({})
97
+ npx ai-spector graph validate # fallback for graph_validate({})
98
+ npx ai-spector graph impact --git --json # fallback for graph_impact({ git: true })
74
99
  npx ai-spector lang queue pending --json # pending translation jobs
75
100
  npx ai-spector setup --check # audit project setup
76
101
  npx ai-spector template list # list installed packs + active
@@ -81,11 +106,9 @@ npx ai-spector template use <name> # switch active pack (use "builtin" to rever
81
106
  # CocoIndex (opt-in — requires Python 3.11+)
82
107
  npx ai-spector cocoindex setup # scaffold pipeline into project
83
108
  npx ai-spector cocoindex index # run pipeline (update embeddings)
84
- npx ai-spector cocoindex search --query "login flow" # semantic search
85
- npx ai-spector cocoindex query-fuzzy --query "login" # natural language → graph node + subgraph
86
109
  ```
87
110
 
88
- On CLI failure: show the output, offer fix / workaround / pause. Do not invent results.
111
+ On MCP tool or CLI failure: show the output, offer fix / workaround / pause. Do not invent results.
89
112
 
90
113
  ## Pipeline order
91
114
 
@@ -12,6 +12,21 @@ description: >-
12
12
 
13
13
  **Workflow:** [../../WORKFLOW.md](../../WORKFLOW.md) · **Router:** [_skill-router.md](../_skill-router.md)
14
14
 
15
+ ## Invocation rule — MCP first, CLI fallback
16
+
17
+ When the `ai-spector` MCP server is enabled (`.cursor/mcp.json` or `.mcp.json` lists it), **call the MCP tool** instead of shelling out to `npx ai-spector`. MCP returns structured JSON, avoids spawning a Node process, and is the preferred channel for agents.
18
+
19
+ | Operation | MCP tool | CLI fallback |
20
+ |-----------|----------|--------------|
21
+ | Re-index project | `index({})` | `npx ai-spector index` |
22
+ | Merge knowledge → graph | `graph_merge({ fromKnowledge: true })` | `npx ai-spector graph merge --from-knowledge` |
23
+ | Validate graph | `graph_validate({})` | `npx ai-spector graph validate` |
24
+ | Impact analysis | `graph_impact({ originId, change })` | `npx ai-spector graph impact …` |
25
+ | Walk graph from node | `graph_query({ id, … })` | `npx ai-spector graph query <id> --json` |
26
+ | **Analyze data-source** | *(no MCP tool — CLI only)* | `npx ai-spector analyze` |
27
+
28
+ Use CLI **only** when: MCP server is not configured, the tool errors and MCP is unavailable, or the operation has no MCP equivalent (e.g. `analyze`).
29
+
15
30
  ## CLI and tool failure (non-negotiable)
16
31
 
17
32
  When `npx ai-spector` exits non-zero, required `--json` is invalid, or a required MCP/terminal step fails:
@@ -27,7 +42,7 @@ When `npx ai-spector` exits non-zero, required `--json` is invalid, or a require
27
42
  |------|------|
28
43
  | Config (languages, paths) | `.ai-spector/docflow.config.json` |
29
44
  | Graph | `.ai-spector/graph/traceability.graph.json` |
30
- | Query | `npx ai-spector graph query <id> --json` |
45
+ | Query | `graph_query({ id })` MCP · fallback: `npx ai-spector graph query <id> --json` |
31
46
  | Templates | `.ai-spector/templates/` |
32
47
  | Doc output | `docs/srs/{lang.code}/` · `docs/basic-design/{lang.code}/` |
33
48
 
@@ -36,7 +36,7 @@ Read **one** runbook under `references/` for the user’s intent, then execute i
36
36
 
37
37
  ```
38
38
  - [ ] Matched runbook read completely
39
- - [ ] CLI from project root (npx ai-spector)
39
+ - [ ] MCP first (ai-spector server) → CLI fallback (npx ai-spector) — see ai-spector/SKILL.md#invocation-rule
40
40
  - [ ] On failure: pause; offer fix / workaround / pause per ai-spector/references/cli-failures.md
41
41
  ```
42
42
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Ingest `docs/data-source/` and commit knowledge into the traceability graph.
4
4
 
5
- The agent runs all CLI steps belowsee [WORKFLOW.md](../../WORKFLOW.md).
5
+ Step 0 (`npx ai-spector analyze`) is **CLI-only**no MCP equivalent. Steps B (merge, validate) use **MCP when available**.
6
6
 
7
7
  ## Usage
8
8
 
@@ -48,6 +48,15 @@ Creates section/document nodes from templates. Do not ask the user to run this s
48
48
 
49
49
  ### B. Commit to graph
50
50
 
51
+ **MCP (preferred when ai-spector server is configured):**
52
+
53
+ ```
54
+ graph_merge({ fromKnowledge: true })
55
+ graph_validate({})
56
+ ```
57
+
58
+ **CLI fallback:**
59
+
51
60
  ```bash
52
61
  npx ai-spector graph merge --from-knowledge
53
62
  npx ai-spector graph validate
@@ -69,13 +78,13 @@ Update `state.json`: `analysis.lastRunAt`, `analysis.dataSource`, scope hash. Me
69
78
  - `knowledge.json` mirrors extract; graph is authoritative for `/generate-srs`.
70
79
  - Gaps recorded in `gaps.json`.
71
80
 
72
- ## CLI steps — stop on first failure
81
+ ## Steps — stop on first failure
73
82
 
74
- | Step | Command |
75
- |------|---------|
76
- | 0 | `npx ai-spector analyze` |
77
- | B | `npx ai-spector graph merge --from-knowledge` |
78
- | B | `npx ai-spector graph validate` |
83
+ | Step | MCP (preferred) | CLI fallback |
84
+ |------|-----------------|--------------|
85
+ | 0 | *(CLI only — no MCP tool)* | `npx ai-spector analyze` |
86
+ | B merge | `graph_merge({ fromKnowledge: true })` | `npx ai-spector graph merge --from-knowledge` |
87
+ | B validate | `graph_validate({})` | `npx ai-spector graph validate` |
79
88
 
80
89
  If any step fails, **pause** and use [cli-failures.md](../../ai-spector/references/cli-failures.md). Do not skip to generate SRS without user choice.
81
90
 
@@ -58,15 +58,17 @@ Map regions with the same rules as below (`resolveImpactOrigins` / graph JSON).
58
58
 
59
59
  ### 3. Run impact per seed, unify report
60
60
 
61
- For each file/region, pick the **most specific** seed (`section` > domain > `document`). Dedupe seeds by id, then:
61
+ For each file/region, pick the **most specific** seed (`section` > domain > `document`). Dedupe seeds by id, then run impact (MCP preferred, CLI fallback):
62
62
 
63
- ```bash
64
- npx ai-spector graph impact <originId> --change content_change --json
65
63
  ```
66
-
67
- Or once for all seeds:
64
+ graph_impact({ originId: "<id>", change: "content_change" })
65
+ # or for all git seeds at once:
66
+ graph_impact({ git: true, change: "content_change" })
67
+ ```
68
68
 
69
69
  ```bash
70
+ # CLI fallback:
71
+ npx ai-spector graph impact <originId> --change content_change --json
70
72
  npx ai-spector graph impact --git --change content_change --json
71
73
  ```
72
74
 
@@ -89,25 +91,27 @@ Gather context from the message (priority order):
89
91
 
90
92
  If several nodes match, pick the **most specific** seed: `section` > domain (`useCase`, `feature`, …) > `document`. If still ambiguous, ask **one** short clarifying question (never ask for raw node id format).
91
93
 
92
- ## Run impact (CLI)
94
+ ## Run impact
93
95
 
94
- After resolving `originId` (one primary seed per region; run again for unrelated regions if needed):
96
+ **Use MCP when the `ai-spector` server is configured. Fall back to CLI otherwise.**
95
97
 
96
- ```bash
97
- npx ai-spector graph impact <originId> --change content_change --json
98
+ ### MCP (preferred)
99
+
100
+ ```
101
+ graph_impact({ originId: "<id>", change: "content_change" })
102
+ graph_impact({ git: true, change: "content_change" })
103
+ graph_impact({ file: "docs/srs/3-use-cases.md", heading: "3.2 List Use Case", change: "content_change" })
98
104
  ```
99
105
 
100
- Or resolver flags (optional verification):
106
+ ### CLI fallback
101
107
 
102
108
  ```bash
109
+ npx ai-spector graph impact <originId> --change content_change --json
110
+ npx ai-spector graph impact --git --change content_change --json
103
111
  npx ai-spector graph impact --file docs/srs/3-use-cases.md --heading "3.2 List Use Case" --json
104
112
  ```
105
113
 
106
- Optional report file:
107
-
108
- ```bash
109
- npx ai-spector graph impact <originId> --json -o .ai-spector/views/impact-<timestamp>.json
110
- ```
114
+ After resolving `originId` (one primary seed per region; run again for unrelated regions if needed):
111
115
 
112
116
  1. Parse JSON output:
113
117
  - `regenerate` / `review` arrays — traceability impact buckets
@@ -115,7 +119,7 @@ npx ai-spector graph impact <originId> --json -o .ai-spector/views/impact-<times
115
119
  - `truncated: true` — BFS hit the propagation cap; warn the user results may be incomplete
116
120
  - `resolvedFrom` / `gitSeeds` — which file/heading each seed came from (present with `--file` / `--heading` / `--git`)
117
121
  2. Present a table with `projectionPath` per entry.
118
- 3. For each **regenerate** id, suggest `/generate-srs` or `/generate-basic-design` using:
122
+ 3. For each **regenerate** id, suggest `/generate-srs` or `/generate-basic-design` using MCP `graph_query({ id: "<thatId>" })` or CLI:
119
123
 
120
124
  ```bash
121
125
  npx ai-spector graph query <thatId> --json
@@ -6,8 +6,8 @@ Rebuild **graph**, re-merge **knowledge** staging, and update **document indexes
6
6
 
7
7
  ## Usage
8
8
 
9
- - `/index` — full CLI refresh (agent runs commands below)
10
- - User may run: `npx ai-spector index` with flags (see README)
9
+ - `/index` — full refresh via MCP (preferred) or CLI fallback
10
+ - User may run: `npx ai-spector index` with flags (see README) when MCP is unavailable
11
11
 
12
12
  ## When to use
13
13
 
@@ -19,43 +19,34 @@ Rebuild **graph**, re-merge **knowledge** staging, and update **document indexes
19
19
 
20
20
  **Still requires `/analyze` for:** full knowledge extraction → `knowledge.json` (NFRs, data model, rich descriptions). Index re-merges existing `knowledge.json` when present; warns if SRS changed but knowledge is stale.
21
21
 
22
- ## Required Behavior (agent runs CLI)
22
+ ## Required Behavior
23
23
 
24
- ```bash
25
- npx ai-spector index
24
+ **Use the MCP tool when the `ai-spector` server is configured. Fall back to CLI only when MCP is unavailable.**
25
+
26
+ ### MCP (preferred)
27
+
28
+ ```
29
+ index({}) # full refresh
30
+ index({ graphOnly: true }) # structure + knowledge merge only
31
+ index({ docsOnly: true }) # doc indexes only
32
+ index({ skipMerge: true }) # skip knowledge.json merge
33
+ index({ skipDocSemantics: true }) # skip UC/F body parsing
26
34
  ```
27
35
 
28
- After **`/generate-srs`** (recommended):
36
+ ### CLI fallback
29
37
 
30
38
  ```bash
31
39
  npx ai-spector index
40
+ npx ai-spector index --graph-only
41
+ npx ai-spector index --docs-only
32
42
  ```
33
43
 
34
44
  Index steps (default): registry/bootstrap → knowledge merge → **SRS/docs body extract** → **source hub** → **provenance (`derivedFrom`)** → **business hub** → validate → doc indexes.
35
45
 
36
- **CLI alone is not full semantics:** Index builds structure + parseable meaning. For cross-hub evidence links (`relatesTo`), run **`/link-graph`** after index, then `npx ai-spector graph merge --semantic`. Check gaps with `npx ai-spector graph report --json`.
46
+ **CLI alone is not full semantics:** Index builds structure + parseable meaning. For cross-hub evidence links (`relatesTo`), run **`/link-graph`** after index, then `graph_merge({ semantic: true })` (MCP) or `npx ai-spector graph merge --semantic`. Check gaps with `npx ai-spector graph report --json`.
37
47
 
38
48
  **Provenance:** UC/F/requirement/actor nodes get **`derivedFrom`** edges to `docs/data-source/**` paths (from `knowledge.json` `sourceRef` / `sourceRefs` / `derivedFrom`, SRS detail `Source:` lines, or inline `docs/data-source/…` mentions). No evidence → no edge.
39
49
 
40
- Flags:
41
-
42
- | Flag | Effect |
43
- |------|--------|
44
- | `--skip-doc-semantics` | Skip UC/F parsing from `docs/srs` and `docs/basic-design` |
45
- | `--skip-merge` | Skip `knowledge.json` merge |
46
-
47
- Structure + merge only:
48
-
49
- ```bash
50
- npx ai-spector index --graph-only
51
- ```
52
-
53
- Doc indexes only:
54
-
55
- ```bash
56
- npx ai-spector index --docs-only
57
- ```
58
-
59
50
  ## Stop on failure
60
51
 
61
52
  Follow [cli-failures.md](../../ai-spector/references/cli-failures.md). Do not hand-edit `traceability.graph.json` to "fix" validate errors.
@@ -8,12 +8,20 @@ Gate before generation. **User runs this command;** agent runs the CLI.
8
8
 
9
9
  ## Required Behavior
10
10
 
11
+ **MCP (preferred when ai-spector server is configured):**
12
+
13
+ ```
14
+ graph_validate({})
15
+ ```
16
+
17
+ **CLI fallback:**
18
+
11
19
  ```bash
12
20
  npx ai-spector graph validate
13
21
  ```
14
22
 
15
- - **Exit 0** → tell the user OK; if domain nodes exist, suggest `/generate-srs`; if only section shells, explain they need `/analyze` first.
16
- - **Non-zero** → **stop**. Use [cli-failures.md](../../ai-spector/references/cli-failures.md): paste every `[ERROR]` line, explain each, give fix steps (usually re-run `/analyze` or fix one node then re-validate).
23
+ - **Success / exit 0** → tell the user OK; if domain nodes exist, suggest `/generate-srs`; if only section shells, explain they need `/analyze` first.
24
+ - **Failure / non-zero** → **stop**. Use [cli-failures.md](../../ai-spector/references/cli-failures.md): paste every `[ERROR]` line, explain each, give fix steps (usually re-run `/analyze` or fix one node then re-validate).
17
25
 
18
26
  **Do not:** guess validation in the agent, hand-fix the whole graph without showing the user, or proceed to `/generate-srs`.
19
27