aiwg 2026.3.1 → 2026.3.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/bin/aiwg.mjs CHANGED
@@ -43,7 +43,9 @@ async function main() {
43
43
 
44
44
  if (args[0] === '--use-dev') {
45
45
  const { switchToDev } = await import('../src/channel/manager.mjs');
46
- await switchToDev(packageRoot);
46
+ // Accept optional path argument, default to cwd
47
+ const devPath = args[1] || process.cwd();
48
+ await switchToDev(devPath);
47
49
  return;
48
50
  }
49
51
 
@@ -58,10 +60,25 @@ async function main() {
58
60
  // Silently ignore update check failures
59
61
  });
60
62
 
63
+ // Dev mode: delegate to the dev repo's CLI facade so all code runs from
64
+ // the local build (not just framework content). This ensures commands like
65
+ // `aiwg index stats` use the locally compiled TypeScript.
66
+ const { loadConfig } = await import('../src/channel/manager.mjs');
67
+ const config = await loadConfig();
68
+ if (config.devMode && config.edgePath && config.edgePath !== packageRoot) {
69
+ const devFacade = path.join(config.edgePath, 'src', 'cli', 'facade.mjs');
70
+ try {
71
+ const { run: devRun } = await import(devFacade);
72
+ await devRun(args, { cwd: process.cwd() });
73
+ return;
74
+ } catch (err) {
75
+ console.error(`Dev mode: failed to load facade from ${config.edgePath}`);
76
+ console.error(` ${err.message}`);
77
+ console.error('Falling back to installed version.');
78
+ }
79
+ }
80
+
61
81
  // Run the CLI via facade (supports both legacy and new routers)
62
- // The facade will determine which router to use based on:
63
- // - AIWG_USE_NEW_ROUTER environment variable
64
- // - --experimental-router or --legacy-router flags
65
82
  await run(args, { cwd: process.cwd() });
66
83
  }
67
84
 
@@ -1657,7 +1657,17 @@ aiwg sdlc-accelerate --auto "Quick prototype"
1657
1657
 
1658
1658
  ## Index Commands
1659
1659
 
1660
- Commands for building and querying the artifact index. The index provides structured, pre-computed metadata about `.aiwg/` artifacts, enabling agents and developers to discover, search, and navigate project artifacts without manual file searching.
1660
+ Commands for building and querying the artifact index. The index provides structured, pre-computed metadata about project artifacts, enabling agents and developers to discover, search, and navigate artifacts without manual file searching.
1661
+
1662
+ The index uses a **multi-graph architecture** with three built-in graph types:
1663
+
1664
+ | Graph | Scans | Storage | Built by default |
1665
+ |-------|-------|---------|-----------------|
1666
+ | `project` | `.aiwg/` artifacts | `.aiwg/.index/project/` | Yes |
1667
+ | `codebase` | `src/`, `test/`, `tools/` | `.aiwg/.index/codebase/` | Yes |
1668
+ | `framework` | `agentic/code/`, `docs/` | `.aiwg/.index/framework/` | No (use `--graph framework`) |
1669
+
1670
+ All commands without `--graph` operate across all available project-local graphs (`project` + `codebase`). Use `--graph <name>` to target a specific graph.
1661
1671
 
1662
1672
  ### index
1663
1673
 
@@ -1673,6 +1683,9 @@ aiwg index <subcommand> [options]
1673
1683
  - `deps` - Show artifact dependency graph
1674
1684
  - `stats` - Show index statistics
1675
1685
 
1686
+ **Global option (all subcommands):**
1687
+ - `--graph <type>` - Target a specific graph: `project`, `codebase`, or `framework`
1688
+
1676
1689
  **Capabilities:** cli, index, artifacts, search, dependencies
1677
1690
  **Platforms:** All
1678
1691
  **Tools:** Read, Glob, Grep
@@ -1681,7 +1694,7 @@ aiwg index <subcommand> [options]
1681
1694
 
1682
1695
  ### index build
1683
1696
 
1684
- Build or rebuild the artifact index by scanning `.aiwg/` directories.
1697
+ Build or rebuild the artifact index.
1685
1698
 
1686
1699
  ```bash
1687
1700
  aiwg index build [options]
@@ -1691,20 +1704,16 @@ aiwg index build [options]
1691
1704
  - `--force` - Full rebuild (ignore checksums, re-index everything)
1692
1705
  - `--verbose` - Show detailed progress during indexing
1693
1706
  - `--scope <dir>` - Limit scan to a specific subdirectory
1707
+ - `--graph <type>` - Build a single graph only (`project`, `codebase`, `framework`)
1694
1708
 
1695
- **Behavior:**
1696
- - Scans `.aiwg/` for `.md`, `.yaml`, and `.json` files
1697
- - Extracts YAML frontmatter metadata (title, type, phase, tags)
1698
- - Computes SHA-256 checksums for incremental indexing
1699
- - Extracts @-mention dependencies from file content
1700
- - Writes index files to `.aiwg/.index/`
1709
+ **Default behavior** (no `--graph`): Builds `project` + `codebase` graphs only. The `framework` graph covers the AIWG framework source (`agentic/code/`, `docs/`) and must be built explicitly with `--graph framework`.
1701
1710
 
1702
- **Incremental mode** (default): Only re-indexes files whose checksum has changed since the last build. Use `--force` for a full rebuild.
1711
+ **Incremental mode** (default): Only re-indexes files whose checksum has changed. Use `--force` for a full rebuild.
1703
1712
 
1704
1713
  **Examples:**
1705
1714
 
1706
1715
  ```bash
1707
- # Incremental build (fast - skips unchanged files)
1716
+ # Build project + codebase (default)
1708
1717
  aiwg index build
1709
1718
 
1710
1719
  # Full rebuild
@@ -1713,15 +1722,27 @@ aiwg index build --force
1713
1722
  # Verbose output
1714
1723
  aiwg index build --verbose
1715
1724
 
1716
- # Scope to requirements only
1717
- aiwg index build --scope requirements
1725
+ # Build framework graph (agentic/code/ + docs/)
1726
+ aiwg index build --graph framework
1727
+
1728
+ # Build a single graph
1729
+ aiwg index build --graph project
1718
1730
  ```
1719
1731
 
1720
- **Output files:**
1721
- - `.aiwg/.index/metadata.json` - Artifact metadata entries
1722
- - `.aiwg/.index/tags.json` - Tag index
1723
- - `.aiwg/.index/deps.json` - Dependency graph
1724
- - `.aiwg/.index/stats.json` - Index statistics
1732
+ **Output structure:**
1733
+ ```
1734
+ .aiwg/.index/
1735
+ ├── project/ # .aiwg/ artifacts
1736
+ │ ├── metadata.json
1737
+ │ ├── tags.json
1738
+ │ ├── dependencies.json
1739
+ │ └── stats.json
1740
+ └── codebase/ # src/, test/, tools/
1741
+ ├── metadata.json
1742
+ ├── tags.json
1743
+ ├── dependencies.json
1744
+ └── stats.json
1745
+ ```
1725
1746
 
1726
1747
  ---
1727
1748
 
@@ -1742,29 +1763,29 @@ aiwg index query [search-text] [options]
1742
1763
  - `--tags <tag1,tag2>` - Filter by tags (AND logic — all tags must match)
1743
1764
  - `--path <glob>` - Filter by file path glob pattern
1744
1765
  - `--updated-after <date>` - Filter by last-modified date
1745
- - `--limit <n>` - Maximum number of results
1766
+ - `--limit <n>` - Maximum number of results (default: 20)
1767
+ - `--graph <type>` - Search a specific graph only
1746
1768
  - `--json` - Output as JSON (recommended for agents)
1747
1769
 
1770
+ **Default behavior** (no `--graph`): Searches across `project` + `codebase` graphs combined.
1771
+
1748
1772
  **Examples:**
1749
1773
 
1750
1774
  ```bash
1751
- # Keyword search
1775
+ # Search all project-local graphs
1752
1776
  aiwg index query "authentication"
1753
1777
 
1778
+ # Search framework source only
1779
+ aiwg index query "artifact discovery" --graph framework
1780
+
1754
1781
  # Filter by type
1755
1782
  aiwg index query --type use-case
1756
1783
 
1757
- # Filter by phase
1758
- aiwg index query --phase testing
1759
-
1760
1784
  # Combined filters
1761
1785
  aiwg index query "login" --type use-case --phase requirements
1762
1786
 
1763
1787
  # JSON output for agents
1764
1788
  aiwg index query "auth" --json
1765
-
1766
- # Limit results
1767
- aiwg index query --tags security --limit 5
1768
1789
  ```
1769
1790
 
1770
1791
  ---
@@ -1783,6 +1804,7 @@ aiwg index deps <path> [options]
1783
1804
  **Options:**
1784
1805
  - `--direction <dir>` - Direction: `upstream`, `downstream`, or `both` (default: `both`)
1785
1806
  - `--depth <n>` - Maximum traversal depth (default: 3)
1807
+ - `--graph <type>` - Use a specific graph's dependency data
1786
1808
  - `--json` - Output as JSON (recommended for agents)
1787
1809
 
1788
1810
  **Behavior:**
@@ -1790,6 +1812,8 @@ aiwg index deps <path> [options]
1790
1812
  - `downstream` - What depends on this artifact (mentions it)
1791
1813
  - `both` - Both directions
1792
1814
 
1815
+ **Default behavior** (no `--graph`): Merges dependency data from `project` + `codebase` graphs.
1816
+
1793
1817
  **Examples:**
1794
1818
 
1795
1819
  ```bash
@@ -1801,6 +1825,9 @@ aiwg index deps .aiwg/requirements/UC-001.md --direction downstream
1801
1825
 
1802
1826
  # JSON output with limited depth
1803
1827
  aiwg index deps .aiwg/architecture/adr-001.md --depth 2 --json
1828
+
1829
+ # Deps within framework source
1830
+ aiwg index deps agentic/code/frameworks/sdlc-complete/rules/artifact-discovery.md --graph framework
1804
1831
  ```
1805
1832
 
1806
1833
  ---
@@ -1814,8 +1841,13 @@ aiwg index stats [options]
1814
1841
  ```
1815
1842
 
1816
1843
  **Options:**
1844
+ - `--graph <type>` - Show stats for a specific graph only
1817
1845
  - `--json` - Output as JSON (recommended for agents)
1818
1846
 
1847
+ **Default behavior** (no `--graph`):
1848
+ - Human-readable: shows each available graph with a section header
1849
+ - JSON: returns an object keyed by graph name with all stats
1850
+
1819
1851
  **Reports:**
1820
1852
  - Artifact counts by SDLC phase and type
1821
1853
  - Tag distribution
@@ -1825,11 +1857,17 @@ aiwg index stats [options]
1825
1857
  **Examples:**
1826
1858
 
1827
1859
  ```bash
1828
- # Human-readable stats
1860
+ # Show all project-local graphs
1829
1861
  aiwg index stats
1830
1862
 
1831
- # JSON output for agents
1863
+ # JSON output (aggregated, keyed by graph name)
1832
1864
  aiwg index stats --json
1865
+
1866
+ # Single graph
1867
+ aiwg index stats --graph project --json
1868
+
1869
+ # Framework graph stats
1870
+ aiwg index stats --graph framework
1833
1871
  ```
1834
1872
 
1835
1873
  ---
@@ -100,22 +100,39 @@ Do not place framework components (schemas, templates, agent definitions) in `.a
100
100
  agentic/code/addons/voice-framework/skills/my-skill/SKILL.md
101
101
  ```
102
102
 
103
- 2. **Deploy to `.claude/` for testing**:
103
+ 2. **Activate dev mode** (one-time setup — points the CLI at your local repo):
104
104
  ```bash
105
- aiwg --use-dev # Point at local repo (one-time)
106
- aiwg use sdlc # Redeploy from local source
105
+ aiwg --use-dev /path/to/ai-writing-guide
106
+ # From inside the repo directory:
107
+ aiwg --use-dev .
107
108
  ```
108
109
 
109
- 3. **Test** the skill/agent is now live in your Claude Code session.
110
+ Dev mode makes the `aiwg` command delegate **all** subcommands to your
111
+ local `src/cli/facade.mjs`, so changes to CLI code take effect after
112
+ `npm run build` without reinstalling the package.
110
113
 
111
- 4. **Commit** only the framework source (`agentic/code/`) goes into git.
114
+ 3. **Build and deploy**:
115
+ ```bash
116
+ npm run build # Compile TypeScript changes
117
+ aiwg use sdlc # Redeploy framework content from local source
118
+ ```
119
+
120
+ 4. **Test** — the skill/agent is now live in your Claude Code session. CLI
121
+ commands like `aiwg index stats` also run from your local build.
122
+
123
+ 5. **Commit** — only the framework source (`agentic/code/`) goes into git.
124
+
125
+ 6. **Switch back when done**:
126
+ ```bash
127
+ aiwg --use-stable
128
+ ```
112
129
 
113
130
  **Common Mistake**: Writing ONLY to `.claude/skills/my-skill/` without creating the source in `agentic/code/`. The skill works locally but never ships to users and disappears on next `aiwg use`.
114
131
 
115
132
  **For AI Agents**: When creating new skills, agents, commands, or rules, you MUST:
116
133
  1. Create the artifact in the correct `agentic/code/` source location
117
134
  2. Update the relevant manifest (`manifest.json`) if one exists
118
- 3. Run `aiwg --use-dev && aiwg use <framework>` or manually copy to `.claude/`
135
+ 3. Run `aiwg --use-dev . && npm run build && aiwg use <framework>`
119
136
  4. Verify the artifact works from `.claude/`
120
137
  5. Only commit changes under `agentic/code/`
121
138
 
@@ -0,0 +1,104 @@
1
+ # AIWG v2026.3.2 — Service Release
2
+
3
+ **Release date:** 2026-03-04
4
+ **Type:** Service release (bug fixes + dev workflow improvements)
5
+
6
+ ## Summary
7
+
8
+ This service release fixes three bugs in the `aiwg index` multi-graph subsystem introduced in v2026.3.1, and upgrades `--use-dev` so it now delegates the full CLI to your local build — not just framework content deployment.
9
+
10
+ ## What's Fixed
11
+
12
+ ### `aiwg index` without `--graph` now works
13
+
14
+ `stats`, `query`, and `deps` all failed with "No artifact index found" when called without `--graph`. The root cause was the same in all three: they checked for `.aiwg/.index/metadata.json` (the legacy pre-multi-graph path), which no longer exists. The index now lives in graph subdirectories:
15
+
16
+ ```
17
+ .aiwg/.index/
18
+ ├── project/ ← .aiwg/ artifacts
19
+ └── codebase/ ← src/, test/, tools/
20
+ ```
21
+
22
+ All three commands now check graph subdirectories first, then fall back to the legacy root for backward compatibility.
23
+
24
+ **Before:**
25
+ ```
26
+ $ aiwg index stats --json
27
+ Error: No artifact index found.
28
+ Run 'aiwg index build' first to create the index.
29
+ ```
30
+
31
+ **After:**
32
+ ```json
33
+ {
34
+ "project": { "totalArtifacts": 495, "coverage": { "percentage": 100 } },
35
+ "codebase": { "totalArtifacts": 496, "coverage": { "percentage": 100 } }
36
+ }
37
+ ```
38
+
39
+ ### `--use-dev` now delegates the full CLI
40
+
41
+ Previously `--use-dev` only changed where `aiwg use` read framework content from. The CLI binary itself still ran the npm-installed code, so changes to TypeScript files like `src/artifacts/stats.ts` had no effect until you ran `npm install -g .`.
42
+
43
+ Now when dev mode is active, the `aiwg` entry point dynamically imports `src/cli/facade.mjs` from your dev repo, making all commands run your local build:
44
+
45
+ ```bash
46
+ # One-time setup (point at your local repo)
47
+ aiwg --use-dev /path/to/ai-writing-guide
48
+ # or from inside the repo:
49
+ aiwg --use-dev .
50
+
51
+ # Make changes, build, test immediately
52
+ npm run build
53
+ aiwg index stats # runs local code
54
+ aiwg use sdlc # deploys from local source
55
+
56
+ # Switch back
57
+ aiwg --use-stable
58
+ ```
59
+
60
+ Also fixed: `--use-dev` previously hardcoded the npm package root as the dev path. It now accepts an explicit path argument.
61
+
62
+ ## What's New
63
+
64
+ ### Framework graph
65
+
66
+ You can now index the AIWG framework source (`agentic/code/`, `docs/`):
67
+
68
+ ```bash
69
+ aiwg index build --graph framework
70
+ # Indexed 1,625 artifacts in 669ms
71
+
72
+ aiwg index stats --graph framework --json
73
+ # { "totalArtifacts": 1625, "graphMetrics": { "totalEdges": 890 } }
74
+
75
+ aiwg index query "artifact discovery" --graph framework --json
76
+ ```
77
+
78
+ The framework graph is intentionally excluded from the default `aiwg index build` since it covers shared/global content. Build it explicitly when you need to navigate the framework source.
79
+
80
+ ### Multi-graph architecture documented
81
+
82
+ `docs/cli-reference.md` now covers the full multi-graph architecture:
83
+ - Graph types table (project, codebase, framework)
84
+ - `--graph` flag on all index subcommands
85
+ - Updated output structure paths
86
+ - Cross-graph default behavior for each command
87
+
88
+ ## Upgrade
89
+
90
+ ```bash
91
+ npm update -g aiwg
92
+ aiwg version
93
+ # 2026.3.2
94
+ ```
95
+
96
+ ## References
97
+
98
+ - Fixes #425 — `aiwg index stats` no-graph failure
99
+ - Issue #426 — Extensible graph types (future work)
100
+ - `src/artifacts/stats.ts` — multi-graph stats aggregation
101
+ - `src/artifacts/query-engine.ts` — cross-graph search
102
+ - `src/artifacts/dep-graph.ts` — merged dependency traversal
103
+ - `bin/aiwg.mjs` — dev mode CLI delegation
104
+ - `src/channel/manager.mjs` — `switchToDev()` path handling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiwg",
3
- "version": "2026.3.1",
3
+ "version": "2026.3.2",
4
4
  "description": "Cognitive architecture for AI-augmented software development with structured memory, ensemble validation, and closed-loop correction. FAIR-aligned artifacts, 84% cost reduction via human-in-the-loop, standards adopted by 100+ organizations.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -107,7 +107,7 @@ async function handleBuild(args: string[]): Promise<void> {
107
107
  // Build a specific graph
108
108
  await buildIndex(cwd, { force, verbose, scope, graph });
109
109
  } else {
110
- // Default: build project + codebase (framework is built via `aiwg use`)
110
+ // Default: build project-local graphs only
111
111
  await buildIndex(cwd, { force, verbose, scope, graph: 'project' });
112
112
  await buildIndex(cwd, { force, verbose, graph: 'codebase' });
113
113
  }
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  import type { DependencyGraph, GraphType } from './types.js';
13
- import { loadDependencyGraph, indexExists, loadGraphIndexFile } from './index-reader.js';
13
+ import { loadDependencyGraph, loadGraphIndexFile } from './index-reader.js';
14
14
 
15
15
  export interface DepsOptions {
16
16
  direction?: 'upstream' | 'downstream' | 'both';
@@ -95,18 +95,35 @@ export async function showDeps(
95
95
  ): Promise<void> {
96
96
  const { direction = 'both', depth = 3, json = false, graph: graphType } = options;
97
97
 
98
- if (!graphType && !indexExists(cwd)) {
99
- console.error('Error: No artifact index found.');
100
- console.log("Run 'aiwg index build' first to create the index.");
101
- process.exit(1);
102
- }
98
+ let depGraph: DependencyGraph | null = null;
103
99
 
104
- const depGraph = graphType
105
- ? loadGraphIndexFile<DependencyGraph>(cwd, 'dependencies.json', graphType)
106
- : loadDependencyGraph(cwd);
107
- if (!depGraph) {
108
- console.error('Error: Failed to load dependency graph.');
109
- process.exit(1);
100
+ if (graphType) {
101
+ depGraph = loadGraphIndexFile<DependencyGraph>(cwd, 'dependencies.json', graphType);
102
+ if (!depGraph) {
103
+ console.error(`Error: No artifact index found for graph '${graphType}'.`);
104
+ console.log("Run 'aiwg index build' first to create the index.");
105
+ process.exit(1);
106
+ }
107
+ } else {
108
+ // Merge dependency graphs from project-local graphs
109
+ const graphTypes: GraphType[] = ['project', 'codebase'];
110
+ const merged: DependencyGraph = {};
111
+ for (const g of graphTypes) {
112
+ const partial = loadGraphIndexFile<DependencyGraph>(cwd, 'dependencies.json', g);
113
+ if (partial) Object.assign(merged, partial);
114
+ }
115
+
116
+ if (Object.keys(merged).length > 0) {
117
+ depGraph = merged;
118
+ } else {
119
+ // Legacy fallback
120
+ depGraph = loadDependencyGraph(cwd);
121
+ if (!depGraph) {
122
+ console.error('Error: No artifact index found.');
123
+ console.log("Run 'aiwg index build' first to create the index.");
124
+ process.exit(1);
125
+ }
126
+ }
110
127
  }
111
128
 
112
129
  if (!depGraph[artifactPath]) {
@@ -11,7 +11,7 @@
11
11
 
12
12
  import { minimatch } from 'minimatch';
13
13
  import type { QueryParams, QueryResult, MetadataEntry, GraphType, ArtifactIndex } from './types.js';
14
- import { loadMetadataIndex, indexExists, loadGraphIndexFile } from './index-reader.js';
14
+ import { loadMetadataIndex, loadGraphIndexFile } from './index-reader.js';
15
15
 
16
16
  export interface QueryOptions {
17
17
  json?: boolean;
@@ -66,23 +66,41 @@ export async function queryIndex(
66
66
  options: QueryOptions = {}
67
67
  ): Promise<void> {
68
68
  const { graph } = options;
69
+ const startTime = Date.now();
69
70
 
70
- if (!graph && !indexExists(cwd)) {
71
- console.error('Error: No artifact index found.');
72
- console.log("Run 'aiwg index build' first to create the index.");
73
- process.exit(1);
74
- }
71
+ let candidates: MetadataEntry[];
75
72
 
76
- const startTime = Date.now();
77
- const index = graph
78
- ? loadGraphIndexFile<ArtifactIndex>(cwd, 'metadata.json', graph)
79
- : loadMetadataIndex(cwd);
80
- if (!index) {
81
- console.error('Error: Failed to load artifact index.');
82
- process.exit(1);
83
- }
73
+ if (graph) {
74
+ // Single graph mode
75
+ const index = loadGraphIndexFile<ArtifactIndex>(cwd, 'metadata.json', graph);
76
+ if (!index) {
77
+ console.error(`Error: No artifact index found for graph '${graph}'.`);
78
+ console.log("Run 'aiwg index build' first to create the index.");
79
+ process.exit(1);
80
+ }
81
+ candidates = Object.values(index.entries);
82
+ } else {
83
+ // No graph specified: search across all project-local graphs
84
+ const graphTypes: GraphType[] = ['project', 'codebase'];
85
+ const allEntries: MetadataEntry[] = [];
86
+ for (const g of graphTypes) {
87
+ const idx = loadGraphIndexFile<ArtifactIndex>(cwd, 'metadata.json', g);
88
+ if (idx) allEntries.push(...Object.values(idx.entries));
89
+ }
84
90
 
85
- let candidates = Object.values(index.entries);
91
+ // Fall back to legacy root index
92
+ if (allEntries.length === 0) {
93
+ const legacy = loadMetadataIndex(cwd);
94
+ if (!legacy) {
95
+ console.error('Error: No artifact index found.');
96
+ console.log("Run 'aiwg index build' first to create the index.");
97
+ process.exit(1);
98
+ }
99
+ allEntries.push(...Object.values(legacy.entries));
100
+ }
101
+
102
+ candidates = allEntries;
103
+ }
86
104
 
87
105
  // Apply filters
88
106
  if (params.type) {
@@ -12,7 +12,7 @@ import fs from 'fs';
12
12
  import path from 'path';
13
13
  import type { GraphType, IndexStats } from './types.js';
14
14
  import { GRAPH_CONFIGS } from './types.js';
15
- import { loadIndexStats, indexExists, loadGraphIndexFile } from './index-reader.js';
15
+ import { loadIndexStats, loadGraphIndexFile } from './index-reader.js';
16
16
 
17
17
  export interface StatsOptions {
18
18
  json?: boolean;
@@ -60,23 +60,74 @@ export async function showStats(
60
60
  ): Promise<void> {
61
61
  const { graph } = options;
62
62
 
63
- if (!graph && !indexExists(cwd)) {
64
- console.error('Error: No artifact index found.');
65
- console.log("Run 'aiwg index build' first to create the index.");
66
- process.exit(1);
63
+ if (graph) {
64
+ // Single graph mode
65
+ const stats = loadGraphIndexFile<IndexStats>(cwd, 'stats.json', graph);
66
+ if (!stats) {
67
+ console.error(`Error: No artifact index found for graph '${graph}'.`);
68
+ console.log("Run 'aiwg index build' first to create the index.");
69
+ process.exit(1);
70
+ }
71
+ await renderStats(cwd, stats, options, graph);
72
+ return;
73
+ }
74
+
75
+ // No graph specified: show per-project graphs (framework is global, use --graph framework)
76
+ const graphTypes: GraphType[] = ['project', 'codebase'];
77
+ const availableGraphs: { type: GraphType; stats: IndexStats }[] = [];
78
+ for (const g of graphTypes) {
79
+ const s = loadGraphIndexFile<IndexStats>(cwd, 'stats.json', g);
80
+ if (s) availableGraphs.push({ type: g, stats: s });
81
+ }
82
+
83
+ // Fall back to legacy root index
84
+ if (availableGraphs.length === 0) {
85
+ const legacyStats = loadIndexStats(cwd);
86
+ if (!legacyStats) {
87
+ console.error('Error: No artifact index found.');
88
+ console.log("Run 'aiwg index build' first to create the index.");
89
+ process.exit(1);
90
+ }
91
+ await renderStats(cwd, legacyStats, options);
92
+ return;
93
+ }
94
+
95
+ if (options.json) {
96
+ // JSON mode: aggregate all graphs into one response
97
+ const combined: Record<string, unknown> = {};
98
+ for (const { type, stats: s } of availableGraphs) {
99
+ const totalFiles = countArtifactFiles(cwd, type);
100
+ combined[type] = {
101
+ ...s,
102
+ coverage: {
103
+ indexed: s.totalArtifacts,
104
+ totalFiles,
105
+ percentage: totalFiles > 0 ? Math.round((s.totalArtifacts / totalFiles) * 100) : 100,
106
+ },
107
+ };
108
+ }
109
+ console.log(JSON.stringify(combined, null, 2));
110
+ return;
67
111
  }
68
112
 
69
- const stats = graph
70
- ? loadGraphIndexFile<IndexStats>(cwd, 'stats.json', graph)
71
- : loadIndexStats(cwd);
72
- if (!stats) {
73
- console.error('Error: Failed to load index statistics.');
74
- process.exit(1);
113
+ // Human-readable: show each graph
114
+ for (const { type, stats: s } of availableGraphs) {
115
+ console.log(`\n[${ type.toUpperCase() } GRAPH]`);
116
+ await renderStats(cwd, s, { ...options, json: false }, type);
75
117
  }
118
+ }
76
119
 
120
+ /**
121
+ * Render stats for a single graph (JSON or human-readable)
122
+ */
123
+ async function renderStats(
124
+ cwd: string,
125
+ stats: IndexStats,
126
+ options: StatsOptions,
127
+ graphType?: GraphType
128
+ ): Promise<void> {
77
129
  if (options.json) {
78
- // Add coverage info
79
- const totalFiles = countArtifactFiles(cwd, graph);
130
+ const totalFiles = countArtifactFiles(cwd, graphType);
80
131
  console.log(JSON.stringify({
81
132
  ...stats,
82
133
  coverage: {
@@ -133,7 +184,7 @@ export async function showStats(
133
184
  console.log('');
134
185
 
135
186
  // Coverage
136
- const totalFiles = countArtifactFiles(cwd, graph);
187
+ const totalFiles = countArtifactFiles(cwd, graphType);
137
188
  const coverage = totalFiles > 0
138
189
  ? Math.round((stats.totalArtifacts / totalFiles) * 100)
139
190
  : 100;
@@ -169,7 +169,12 @@ export async function switchToEdge() {
169
169
  }
170
170
 
171
171
  /**
172
- * Switch to dev mode (use local repo as framework source)
172
+ * Switch to dev mode (use local repo as both framework source and CLI)
173
+ *
174
+ * In dev mode, the CLI entry point delegates to the dev repo's facade,
175
+ * so all code (including `aiwg index`, `aiwg use`, etc.) runs from the
176
+ * local build rather than the npm-installed package.
177
+ *
173
178
  * @param {string} devPath - Path to the local development repository
174
179
  */
175
180
  export async function switchToDev(devPath) {
@@ -189,13 +194,26 @@ export async function switchToDev(devPath) {
189
194
  process.exit(1);
190
195
  }
191
196
 
197
+ // Verify CLI facade exists (needed for delegation)
198
+ try {
199
+ await fs.access(path.join(resolvedPath, 'src', 'cli', 'facade.mjs'));
200
+ } catch {
201
+ console.error(`Error: ${resolvedPath}/src/cli/facade.mjs not found.`);
202
+ console.error('Dev mode requires the source CLI facade. Is this the right repo?');
203
+ process.exit(1);
204
+ }
205
+
192
206
  config.channel = 'edge';
193
207
  config.edgePath = resolvedPath;
194
208
  config.devMode = true;
195
209
  await saveConfig(config);
196
210
 
197
211
  console.log('Switched to dev mode.');
198
- console.log(`Framework source: ${resolvedPath}`);
212
+ console.log(`Dev repo: ${resolvedPath}`);
213
+ console.log(`CLI source: ${resolvedPath}/src/cli/facade.mjs`);
214
+ console.log('');
215
+ console.log('The aiwg command now runs code from your local repo.');
216
+ console.log('After making changes, run: npm run build');
199
217
  console.log('');
200
218
  console.log('Commands:');
201
219
  console.log(' aiwg use all Deploy from local source');