@mod-computer/cli 0.1.0

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.
Files changed (56) hide show
  1. package/README.md +125 -0
  2. package/commands/execute.md +156 -0
  3. package/commands/overview.md +233 -0
  4. package/commands/review.md +151 -0
  5. package/commands/spec.md +169 -0
  6. package/dist/app.js +227 -0
  7. package/dist/cli.bundle.js +25824 -0
  8. package/dist/cli.bundle.js.map +7 -0
  9. package/dist/cli.js +121 -0
  10. package/dist/commands/agents-run.js +71 -0
  11. package/dist/commands/auth.js +151 -0
  12. package/dist/commands/branch.js +1411 -0
  13. package/dist/commands/claude-sync.js +772 -0
  14. package/dist/commands/index.js +43 -0
  15. package/dist/commands/init.js +378 -0
  16. package/dist/commands/recover.js +207 -0
  17. package/dist/commands/spec.js +386 -0
  18. package/dist/commands/status.js +329 -0
  19. package/dist/commands/sync.js +95 -0
  20. package/dist/commands/workspace.js +423 -0
  21. package/dist/components/conflict-resolution-ui.js +120 -0
  22. package/dist/components/messages.js +5 -0
  23. package/dist/components/thread.js +8 -0
  24. package/dist/config/features.js +72 -0
  25. package/dist/config/release-profiles/development.json +11 -0
  26. package/dist/config/release-profiles/mvp.json +12 -0
  27. package/dist/config/release-profiles/v0.1.json +11 -0
  28. package/dist/config/release-profiles/v0.2.json +11 -0
  29. package/dist/containers/branches-container.js +140 -0
  30. package/dist/containers/directory-container.js +92 -0
  31. package/dist/containers/thread-container.js +214 -0
  32. package/dist/containers/threads-container.js +27 -0
  33. package/dist/containers/workspaces-container.js +27 -0
  34. package/dist/daemon-worker.js +257 -0
  35. package/dist/lib/auth-server.js +153 -0
  36. package/dist/lib/browser.js +35 -0
  37. package/dist/lib/storage.js +203 -0
  38. package/dist/services/automatic-file-tracker.js +303 -0
  39. package/dist/services/cli-orchestrator.js +227 -0
  40. package/dist/services/feature-flags.js +187 -0
  41. package/dist/services/file-import-service.js +283 -0
  42. package/dist/services/file-transformation-service.js +218 -0
  43. package/dist/services/logger.js +44 -0
  44. package/dist/services/mod-config.js +61 -0
  45. package/dist/services/modignore-service.js +326 -0
  46. package/dist/services/sync-daemon.js +244 -0
  47. package/dist/services/thread-notification-service.js +50 -0
  48. package/dist/services/thread-service.js +147 -0
  49. package/dist/stores/use-directory-store.js +96 -0
  50. package/dist/stores/use-threads-store.js +46 -0
  51. package/dist/stores/use-workspaces-store.js +32 -0
  52. package/dist/types/config.js +16 -0
  53. package/dist/types/index.js +2 -0
  54. package/dist/types/workspace-connection.js +2 -0
  55. package/dist/types.js +1 -0
  56. package/package.json +67 -0
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # mod-cli
2
+
3
+ ## Intro
4
+
5
+ mod-cli is the local sync agent for Mod, a collaboration layer for teams working with coding agents.
6
+
7
+ Coding agents operate on local filesystems. They read specs, write code, and generate metadata (traces, reasoning, todos). But collaboration happens elsewhere: in GitHub PRs, Notion docs, Slack threads. The result: context lives in silos. Agents can't access specs being discussed in the browser. Teammates can't see agent reasoning. Reviews happen without the full picture.
8
+
9
+ mod-cli bridges local and collaborative workflows. It syncs the local filesystem to Mod workspaces in real-time, making local changes visible to collaborators and remote edits available to agents. The CLI turns a directory into a distributed, collaborative filesystem.
10
+
11
+ ## Conceptual Overview
12
+
13
+ **Workspaces**: A workspace is a container for files, branches, and metadata. Create workspaces with `mod workspace create`, list them with `mod workspace list`, switch with `mod workspace switch`. Each workspace has its own history, collaborators, and sync state. A directory connects to one workspace at a time.
14
+
15
+ **Local-First Sync**: `mod sync start` launches a daemon that watches the local directory and syncs to the connected workspace. File edits, new files, deletions propagate automatically. Remote changes from collaborators sync back to local files. The daemon runs in the background; coding agents work locally as normal. Multiple collaborators can sync to the same workspace from different machines.
16
+
17
+ **Branching**: Mod branches are lightweight isolation scopes for work-in-progress. Unlike git branches, they don't require commits or staging. Create a branch, start working, and all changes are tracked automatically. When integrated with git, Mod branches map to git branches. Without git, Mod branches provide standalone isolation.
18
+
19
+ **Changelog**: Every file change on a branch is recorded automatically with timestamp, diff, and context. No manual commits required. The changelog captures what changed, when, and alongside what other activity (agent conversations, spec edits, collaborator comments). View at branch level or filter to a specific file.
20
+
21
+ **Reversion**: Restore to any point in the changelog. Revert an entire branch to a previous state, or revert a single file while keeping other files at their current state. Fine-grained reversion without needing explicit commits as restore points.
22
+
23
+ **Merge**: Combine branches by merging their changes. Mod detects conflicts at the file level and surfaces them for resolution. Metadata (comments, traces) merges automatically. After merge, the target branch contains changes from both branches with full history preserved.
24
+
25
+ **Git Integration**: In git repositories, sync respects git branch scope. Changes on a git branch sync to the corresponding Mod branch. Switching git branches switches sync context automatically. For non-git directories, Mod branches work independently. The CLI integrates with git workflows but doesn't require git.
26
+
27
+ **Metadata Layer**: Workspaces and files carry metadata: comments, notes, and traces. The CLI provides commands to read and write metadata locally. Agents can query file context before making changes and write traces linking code to requirements. Teams see the same metadata in the web app. This shared context layer makes agent reasoning visible and lets teams annotate code without changing source files.
28
+
29
+ **File Import**: For existing projects, `mod sync import` brings current files into the workspace. In git repos, import can pull from git history. Preview first with `--preview` to see what will sync. After import, changes sync automatically.
30
+
31
+ ## Example
32
+
33
+ A developer is implementing an authentication feature using Claude Code.
34
+
35
+ **1. Initialize**: The developer runs `mod init` in their project directory. They sign in (or are prompted to create an account), then select an existing workspace or create a new one. The directory is now connected to the workspace.
36
+
37
+ **2. Start sync**: They run `mod sync start`. The daemon launches in the background, watching for file changes and syncing to the workspace.
38
+
39
+ **3. Create branch**: They run `mod branch create add-auth`. A new branch is created. The spec file `specs/auth.md` was collaboratively edited in the web app and is already synced locally.
40
+
41
+ **4. Work with agent**: They prompt Claude Code to implement the spec. Claude reads `specs/auth.md` from the filesystem, checks existing comments with `mod comment list`, implements the requirements, and adds traces with `mod trace add src/auth.ts REQ-AUTH-1`. Every file change and metadata update syncs automatically.
42
+
43
+ **5. Review changelog**: Running `mod changelog` shows all file changes with timestamps and diffs. The developer sees implementation progress alongside agent conversation context.
44
+
45
+ **6. Collaborate**: A teammate edits the spec in the web app, adding a section on rate limiting. The edit syncs to the local file. The developer prompts Claude again, and new changes sync back.
46
+
47
+ **7. Ready for review**: Running `mod branch status` shows all changed files. The developer opens the web app to the review view, where teammates see file changes alongside traces and agent reasoning.
48
+
49
+ ## How It Works
50
+
51
+ **Sync Daemon**: `mod sync start` launches a background daemon that watches the directory. File system events trigger sync operations. The daemon maintains a WebSocket connection to the sync server for real-time updates.
52
+
53
+ **Automerge Storage**: Local workspace state uses Automerge, a CRDT library for conflict-free replication. Changes merge automatically without coordination. The CLI stores Automerge documents in `~/.mod/` at the device root, shared across all connected repos.
54
+
55
+ **Bidirectional Sync**: Local file changes update Automerge documents and propagate to the server. Server changes (from collaborators or the web app) update local Automerge state and write back to files. The sync is continuous and automatic.
56
+
57
+ **Branch State**: Each branch maintains independent file states in Automerge. Switching branches updates local files to match. Branch metadata and change history sync alongside file content.
58
+
59
+ **Changelog**: The CLI records every file change with timestamp, diff, and surrounding context. The changelog is queryable and connects code changes to concurrent activity like agent conversations and collaborator edits.
60
+
61
+ ## Commands Reference
62
+
63
+ ### Core Commands
64
+
65
+ ```bash
66
+ mod init # Initialize workspace and install Claude commands
67
+ mod sync start # Start background sync daemon
68
+ mod sync stop # Stop sync daemon
69
+ mod sync status # Show sync health and connection status
70
+ mod sync import # Import existing files to workspace
71
+ ```
72
+
73
+ ### Branch Management
74
+
75
+ ```bash
76
+ mod branch create <name> # Create new branch
77
+ mod branch switch <name> # Switch to branch
78
+ mod branch list # List all branches
79
+ mod branch status # Show current branch and changes
80
+ mod branch changelog # Show automatic changelog
81
+ mod branch tree # Display directory tree
82
+ ```
83
+
84
+ ### Workspace Management
85
+
86
+ ```bash
87
+ mod workspace create <name> # Create new workspace
88
+ mod workspace list # List workspaces
89
+ mod workspace switch <name> # Switch active workspace
90
+ mod workspace info # Show workspace details
91
+ ```
92
+
93
+ ### Metadata
94
+
95
+ ```bash
96
+ mod comment add <file> <text> # Add comment to file
97
+ mod comment list [file] # List comments (all or per file)
98
+ mod note set <file> <text> # Set note on file
99
+ mod note get <file> # Get note for file
100
+ mod trace add <file> <req-id> # Add trace linking file to requirement
101
+ mod trace list [file] # List traces (all or per file)
102
+ ```
103
+
104
+ ## Development
105
+
106
+ ```bash
107
+ pnpm install # Install dependencies
108
+ pnpm build # Build CLI
109
+ pnpm dev # Watch mode
110
+ pnpm test # Run tests
111
+ ```
112
+
113
+ ## Thoughts
114
+
115
+ **Daemon architecture**: The sync daemon runs as a background process rather than requiring an active terminal. This lets developers work normally while sync happens invisibly. The daemon writes logs to `~/.mod/logs/sync.log` for debugging.
116
+
117
+ **CRDT trade-offs**: Automerge handles conflicts automatically, but the resulting merges aren't always what users expect for text files. Currently optimizing for metadata sync; file content sync may need smarter merge strategies.
118
+
119
+ **Git integration**: In git repos, sync is branch-aware: git branch switches trigger Mod branch switches. Mod adds real-time collaboration and agent context on top of git. In non-git directories, Mod provides standalone change tracking and sync.
120
+
121
+ **Device-level storage**: All state lives in `~/.mod/` at the device root rather than per-repo. Sign in once, use across all repos. Single daemon can sync multiple connected directories. No per-repo config to gitignore.
122
+
123
+ **Metadata commands**: Specific commands for comments, notes, and traces rather than a generic `mod meta` interface. Agents benefit from semantic clarity. Each metadata type has different workflows: comments are threaded, notes are single per file, traces link to requirement IDs. Keeping them separate makes intent clear for both agents and humans.
124
+
125
+ **Offline handling**: The daemon queues changes when offline and syncs when reconnected. Local edits always work; sync catches up when possible. Conflict resolution happens through Automerge's CRDT properties.
@@ -0,0 +1,156 @@
1
+ ---
2
+ version: 2.0.0
3
+ updated: 2026-01-03
4
+ description: Execute specification with complete traceability implementation
5
+ ---
6
+
7
+ # Specification Execution with Complete Traceability
8
+
9
+ Given this specification file: ".mod/specs/<optional-folder>/$ARGUMENTS"
10
+
11
+ ## Branch Context and Specification Setup
12
+
13
+ **Automatic Branch Detection and Context Gathering:**
14
+
15
+ **If no specification argument provided:**
16
+ 1. **Check active branch** for linked specification:
17
+ ```bash
18
+ mod branch status
19
+ # Should show active branch and linked specification
20
+ ```
21
+ 2. **Error handling** for lightweight branches:
22
+ ```bash
23
+ # If current branch has no specification:
24
+ # > Current branch "fix-auth-timeout" is a lightweight branch with no specification
25
+ # > Options:
26
+ # > 1. Link specification: mod branch spec-link <spec-file>
27
+ # > 2. Create specification branch: mod branch create feature-<name> --spec <spec-file>
28
+ # > 3. Switch to specification branch: mod branch switch <spec-branch>
29
+ ```
30
+
31
+ **If specification argument provided (e.g., `branching-cli.spec.md`):**
32
+ 1. **Auto-switch to specification branch**:
33
+ ```bash
34
+ # Check if corresponding branch exists
35
+ mod branch list | grep "feature-.*branching-cli"
36
+
37
+ # If exists, switch to it
38
+ mod branch switch feature-mod-cli-branching-cli
39
+
40
+ # If doesn't exist, create it
41
+ mod branch create feature-mod-cli-branching-cli --spec mod-cli/branching-cli.spec.md
42
+ ```
43
+ 2. **Verify branch setup**:
44
+ ```bash
45
+ mod branch status
46
+ # Should confirm specification branch is active and linked
47
+ ```
48
+
49
+ **Context Gathering (Automatic):**
50
+ 1. **Implementation Progress**: `mod branch status` shows current implementation changes
51
+ 2. **Specification Requirements**: `mod status <spec-name>.spec.md` shows requirements and traceability
52
+ 3. **Coverage Analysis**: `glassware` shows which code has implementation traces
53
+
54
+ ## Pre-Execution Analysis
55
+
56
+ **BEFORE implementation:**
57
+ 1. Read and fully understand the complete specification, including all sub-requirements
58
+ 2. Parse all ARCH-*, BEH-*, DATA-*, and TEST-* requirements for dependency analysis
59
+ 3. Identify numbered sub-requirements (e.g., BEH-AUTH-1.1, BEH-AUTH-1.2) for granular execution
60
+ 4. Create implementation plan prioritizing ARCH → DATA → BEH → TEST requirements
61
+
62
+ **Understanding existing code changes:**
63
+ 5. Use `mod branch status` to see what code changes have already been made on this branch
64
+ 6. Run `glassware` to understand spec traceability coverage of existing code on branch
65
+
66
+ ## Mandatory Traceability Implementation
67
+
68
+ **CRITICAL: Use glassware annotations for all traceability**
69
+
70
+ ### Glassware Annotation Format
71
+
72
+ **In Markdown specs/requirements:**
73
+ ```markdown
74
+ The system must validate user credentials. <glassware type="requirement" id="REQ-AUTH-1" />
75
+ ```
76
+
77
+ **In TypeScript implementations:**
78
+ ```typescript
79
+ // glassware[type=implementation, id=unique-impl-id, requirements=REQ-ID]
80
+ ```
81
+
82
+ ### Complexity-Based Traceability Standards
83
+ - **Method-Level (Default)**: Single glassware comment for simple functions (<10 lines, no branching)
84
+ - **Line-Level (Complex)**: Detailed glassware comments for complex logic (>10 lines, branching, error handling)
85
+ - **Business Logic Priority**: Always use line-level traces for business logic patterns regardless of complexity
86
+
87
+ ### Granularity Decision Rules
88
+ **For each function, analyze and apply:**
89
+
90
+ 1. **Business Logic Check** - Does function name/purpose include: validate, auth, pay, charge, encrypt, save, persist?
91
+ → If YES: Always use **line-level** traces
92
+
93
+ 2. **Complexity Check** - Count lines of actual code (exclude comments/whitespace):
94
+ → If >10 lines OR has conditionals (if/switch/try/for/while): Use **line-level** traces
95
+ → If ≤10 lines AND no conditionals: Use **method-level** traces
96
+
97
+ 3. **Error Handling Check** - Does function have try-catch or multiple return paths?
98
+ → If YES: Use **line-level** traces
99
+
100
+ ### Method-Level Example (Simple Function)
101
+ ```typescript
102
+ // glassware[type=implementation, id=validate-user, requirements=REQ-AUTH-1]
103
+ function validateUser(email: string, password: string): boolean {
104
+ return bcrypt.compare(password, getStoredHash(email));
105
+ }
106
+ ```
107
+
108
+ ### Line-Level Example (Complex Function)
109
+ ```typescript
110
+ function processPayment(order: Order, card: CreditCard): PaymentResult {
111
+ // glassware[type=implementation, id=validate-order, requirements=REQ-PAY-1]
112
+ if (order.amount <= 0 || !SUPPORTED_CURRENCIES.includes(order.currency)) {
113
+ throw new ValidationError("Invalid order parameters");
114
+ }
115
+
116
+ // glassware[type=implementation, id=fraud-check, requirements=REQ-PAY-2]
117
+ const fraudScore = await fraudDetection.analyze(card, order);
118
+ if (fraudScore > FRAUD_THRESHOLD) {
119
+ // glassware[type=implementation, id=fraud-logging, requirements=REQ-PAY-3]
120
+ await auditLog.record('fraud_detected', { order: order.id, score: fraudScore });
121
+ throw new FraudError("Transaction blocked by fraud detection");
122
+ }
123
+
124
+ // glassware[type=implementation, id=process-charge, requirements=REQ-PAY-4]
125
+ return await paymentGateway.charge(card, order.amount);
126
+ }
127
+ ```
128
+
129
+ ## Execution Workflow
130
+
131
+ **For each implementation cycle, MUST apply this process:**
132
+ 1. **Analyze Complexity**: Count lines, branches, and business logic patterns
133
+ 2. **Apply Granularity Rules**: Use method-level for simple functions, line-level for complex
134
+ 3. **Business Logic Override**: Always apply line-level traces for business logic patterns
135
+ 4. **Embed During Generation**: Add glassware traces as code is generated, not afterward
136
+ 5. **Test Progress**: Run `glassware` to verify traceability coverage
137
+ 6. **Iterate**: Continue implementing and tracing until all requirements show as implemented
138
+
139
+ ## Real-Time Quality Gates
140
+
141
+ **Execution agents MUST enforce these standards:**
142
+ - **Specification Coverage**: ≥90% of sub-requirements implemented
143
+ - **Appropriate Granularity**: Complex functions have line-level traces, simple functions have method-level
144
+ - **Business Logic Traceability**: All business logic has detailed line-level glassware traces
145
+ - **Invalid References**: 0 glassware comments pointing to non-existent requirements
146
+
147
+ ## Success Criteria
148
+
149
+ ✅ **Complete Implementation**: All numbered sub-requirements implemented and working
150
+ ✅ **Full Traceability**: Every implementation decision traced to specific sub-requirement
151
+ ✅ **Status Verification**: `glassware` shows all requirements as implemented
152
+ ✅ **Quality Gates Passed**: Coverage and traceability thresholds met
153
+ ✅ **Test Coverage**: All TEST-* requirements implemented with glassware traces
154
+ ✅ **Zero Orphaned Code**: All new code has valid glassware requirement references
155
+
156
+ **CRITICAL**: Run `glassware` before and after each implementation phase to verify progress. Additionally, use `mod branch status` to understand what code changes were made for the spec. Do not mark tasks complete until glassware shows all requirements implemented.
@@ -0,0 +1,233 @@
1
+ ---
2
+ version: 2.0.0
3
+ updated: 2026-01-03
4
+ description: Generate workspace specification scaffolding and overview
5
+ ---
6
+
7
+ # Workspace Specification Scaffolding
8
+
9
+ ## Command Modes
10
+
11
+ **Two-Step Process:**
12
+
13
+ 1. **Overview Mode** (no arguments): `workspace-spec`
14
+ - Performs full codebase analysis
15
+ - Generates overview of current architecture
16
+ - Plans specification structure
17
+ - Outputs proposed organization without creating files
18
+
19
+ 2. **Implementation Mode** (with argument): `workspace-spec <workspace-name>` or `workspace-spec overview.spec.md`
20
+ - Creates the planned specification directory structure
21
+ - Generates template files based on analysis from overview mode
22
+ - Implements the full scaffolding process
23
+
24
+ ---
25
+
26
+ ### Overview Mode (No Arguments)
27
+
28
+ When no arguments are provided, perform analysis and planning only:
29
+
30
+ **ANALYSIS TASKS:**
31
+ 1. Analyze existing codebase architecture and component organization
32
+ 2. Scan `.mod/specs/` (or existing spec directories) for current specification structure and patterns
33
+ 3. Identify feature domains from component names and folder hierarchy
34
+ 4. Detect specification gaps where components exist but specifications are missing
35
+ 5. Generate hierarchical specification organization plan
36
+
37
+ **OUTPUT OVERVIEW:**
38
+ - Current codebase architecture summary
39
+ - Identified components and their organization
40
+ - Existing specification coverage analysis
41
+ - Project directory hierarchy map with key ownership notes
42
+ - Recommendation for workspace name and organization
43
+
44
+ **NO FILES CREATED** - This mode only analyzes and plans.
45
+
46
+ ---
47
+
48
+ ### Implementation Mode (With Arguments)
49
+
50
+ When arguments are provided (`workspace-spec <workspace-name>` or `workspace-spec overview.spec.md`):
51
+
52
+ **Argument Handling:**
53
+ - If argument is "overview.spec.md" → Use default workspace name based on project directory
54
+ - If argument is a custom name → Use provided workspace name: "$ARGUMENTS"
55
+ - Both cases proceed with full scaffolding implementation
56
+
57
+ ## Workspace Scaffolding Process
58
+
59
+ ### 1. Codebase Architecture Discovery
60
+
61
+ **Project Structure Analysis**:
62
+ - Scan project directory for all components/modules and their organization
63
+ - Identify core components (main application logic, shared libraries)
64
+ - Categorize feature components (domain-specific functionality, user-facing features)
65
+ - Discover infrastructure components (utilities, services, configuration, deployment)
66
+
67
+ **Existing Specification Audit**:
68
+ - List all current `.mod/specs/` folders and specification files (or detect existing spec directories)
69
+ - Identify coverage gaps where components have no specifications
70
+ - Analyze specification quality and completion status
71
+ - Map specification relationships and dependencies
72
+
73
+ ### 2. Project Hierarchy Mapping
74
+
75
+ **Project Organization Deliverable**:
76
+ - Enumerate the actual workspace directories (packages, apps, services, docs, tooling)
77
+ - Highlight the major subdirectories under the focus package (e.g., `source/commands`, `source/services`, `tests/containers`)
78
+ - Note ownership and responsibility per directory so downstream specs know where behavior lives
79
+
80
+ **Suggested Output Format**:
81
+ ```
82
+ packages/
83
+ └── [workspace-name]/
84
+ ├── source/
85
+ │ ├── app.tsx
86
+ │ ├── cli.tsx
87
+ │ ├── commands/ # Headless commands
88
+ │ ├── containers/ # Ink UI views
89
+ │ ├── services/ # Shared domain logic
90
+ │ ├── components/ # Reusable Ink components
91
+ │ ├── stores/ # Zustand state
92
+ │ └── shims/ # Polyfills/adapters
93
+ ├── tests/
94
+ │ ├── services/
95
+ │ ├── containers/
96
+ │ └── _harness/
97
+ ├── docs/
98
+ ├── dist/
99
+ ├── README.md
100
+ ├── package.json
101
+ └── vitest.config.ts
102
+ ```
103
+
104
+ Use this hierarchy to anchor the overview narrative, tie directories to functionality, and call out gaps (e.g., missing tests folder, duplicated services). This replaces the previous "proposed spec tree" so the overview focuses on the real project layout before any scaffolding occurs.
105
+
106
+ ### 3. Template Population System
107
+
108
+ **Generic Specification Template Structure for Each Specification**:
109
+ ```markdown
110
+ ---
111
+ title: [feature-name]
112
+ type: specification
113
+ ---
114
+ # [Feature Name] Specification
115
+
116
+ ## Abstract
117
+ [One-sentence system summary with key capabilities and scale targets]
118
+
119
+ ## Motivation
120
+ ### Current Problems
121
+ - [Specific problem this feature solves]
122
+
123
+ ### Business Impact
124
+ - [Value delivered and success metrics]
125
+
126
+ ## Approach
127
+ [High-level solution architecture and key technical decisions]
128
+
129
+ ## UX Requirements (UX-*)
130
+ [UI components, user flows, and accessibility]
131
+
132
+ ## Application Requirements (APP-*)
133
+ [Business logic, workflows, and validation rules]
134
+
135
+ ## Integration Requirements (INT-*)
136
+ [APIs, external services, and data exchange]
137
+
138
+ ## Infrastructure Requirements (INFRA-*)
139
+ [System architecture, deployment, and scaling]
140
+
141
+ ## Quality Requirements (QUAL-*)
142
+ [Testing, performance, and security criteria]
143
+
144
+ ## Expected Glassware Trace Formats
145
+ **Method-Level**: `// glassware[type=implementation, id=unique-id, requirements=REQ-CATEGORY-N]`
146
+ **Line-Level**: Same format, placed above specific logic blocks
147
+ ```
148
+
149
+ ### 4. Intelligent Content Generation
150
+
151
+ **For Each Component**:
152
+ 1. **Analyze project files** (package.json, pyproject.toml, Cargo.toml, etc.) for dependencies and scripts to understand functionality
153
+ 2. **Scan source code** for main classes, services, and architectural patterns
154
+ 3. **Identify integration points** through import analysis and API usage
155
+ 4. **Generate initial requirements** based on discovered functionality patterns
156
+ 5. **Create placeholder specifications** with discovered structure and TODO sections
157
+
158
+ **Business Logic Pattern Detection**:
159
+ - Authentication/authorization functions → Security specification requirements
160
+ - Data persistence operations → Data management specification requirements
161
+ - External API integrations → Integration specification requirements
162
+ - UI components and workflows → UX specification requirements
163
+
164
+ ### 5. Cross-Component Dependency Mapping
165
+
166
+ **Integration Analysis**:
167
+ - Map import relationships between components to identify integration specifications needed
168
+ - Identify shared types and interfaces requiring API contract specifications
169
+ - Discover common patterns requiring cross-cutting concern specifications
170
+ - Generate integration requirement matrix for multi-component features
171
+
172
+ **Dependency Documentation**:
173
+ - Create visual dependency graph in `requirements-matrix.md`
174
+ - Document shared service contracts in `integration-points.md`
175
+ - Identify specification completion priorities based on dependency criticality
176
+
177
+ ## Scaffolding Execution Workflow
178
+
179
+ ### Phase 1: Discovery and Planning
180
+ 1. Run codebase analysis to understand current architecture
181
+ 2. Generate proposed specification folder structure
182
+ 3. Display plan to user with component coverage analysis
183
+ 4. Identify critical specification gaps requiring immediate attention
184
+
185
+ ### Phase 2: Structure Creation
186
+ 1. Detect existing specification directory structure (`.mod/specs/`) or create `.mod/specs/` if none exists
187
+ 2. Create hierarchical folder structure within the specification directory
188
+ 3. Generate template specification files with component-specific content
189
+ 4. Populate initial requirements based on code analysis
190
+ 5. Create cross-reference documentation and dependency matrix
191
+
192
+ ### Phase 3: Integration Setup
193
+ 1. Update existing specifications with cross-component integration requirements
194
+ 2. Generate shared specification files for cross-cutting concerns
195
+ 3. Create workspace overview documentation linking all specifications
196
+ 4. Establish specification completion roadmap with priorities
197
+
198
+ ### Phase 4: Validation and Reporting
199
+ 1. Validate all generated specification files for template compliance
200
+ 2. Check cross-reference integrity between specifications
201
+ 3. Generate workspace specification summary report
202
+ 4. Provide next steps for specification completion and implementation
203
+
204
+ ## Quality Standards
205
+
206
+ **Template Compliance**:
207
+ - All specifications include complete template structure with all required sections
208
+ - Requirement numbering follows category prefix standards (UX-*, APP-*, INT-*, INFRA-*, QUAL-*)
209
+ - Expected glassware trace formats defined for optimal traceability integration
210
+ - Cross-component dependencies properly documented and referenced
211
+
212
+ **Scaffolding Completeness**:
213
+ - 100% component coverage - every significant component has at least one specification
214
+ - Critical integration points identified and documented
215
+ - Shared concerns extracted into cross-cutting specifications
216
+ - Specification priorities established based on dependency analysis
217
+
218
+ **Integration Readiness**:
219
+ - Generated specifications ready for `/execute` command implementation
220
+ - Clear requirement traceability paths established
221
+ - Component boundaries and contracts clearly defined
222
+ - Cross-component workflows properly specified
223
+
224
+ ## Success Criteria
225
+
226
+ ✅ **Complete Component Coverage**: Every significant component in workspace has specification structure
227
+ ✅ **Hierarchical Organization**: Logical folder structure mirrors codebase architecture
228
+ ✅ **Template Consistency**: All specifications follow generic template standards
229
+ ✅ **Integration Documentation**: Cross-component dependencies and contracts specified
230
+ ✅ **Implementation Ready**: Generated specifications contain actionable requirements ready for `/execute`
231
+ ✅ **Quality Foundation**: Specification quality standards established for workspace
232
+
233
+ **Result**: Complete workspace specification scaffolding with hierarchical organization, template consistency, and integration documentation ready for systematic implementation via `/execute` commands.
@@ -0,0 +1,151 @@
1
+ ---
2
+ version: 2.0.0
3
+ updated: 2026-01-03
4
+ description: Review specification and add traceability comments
5
+ ---
6
+
7
+ # Specification Review & Traceability Agent
8
+
9
+ Given this specification file: ".mod/specs/<optional-folder>/$ARGUMENTS"
10
+
11
+ ## Branch Context and Specification Setup
12
+
13
+ **Automatic Branch Detection and Context Gathering:**
14
+
15
+ **If no specification argument provided:**
16
+ 1. **Check active branch** for linked specification:
17
+ ```bash
18
+ mod branch status
19
+ # Should show active branch and linked specification
20
+ ```
21
+ 2. **Error handling** for lightweight branches:
22
+ ```bash
23
+ # If current branch has no specification:
24
+ # > Current branch "fix-auth-timeout" is a lightweight branch with no specification
25
+ # > Options:
26
+ # > 1. Link specification: mod branch spec-link <spec-file>
27
+ # > 2. Create specification branch: mod branch create feature-<name> --spec <spec-file>
28
+ # > 3. Switch to specification branch: mod branch switch <spec-branch>
29
+ ```
30
+
31
+ **If specification argument provided (e.g., `branching-cli.spec.md`):**
32
+ 1. **Auto-switch to specification branch**:
33
+ ```bash
34
+ # Check if corresponding branch exists
35
+ mod branch list | grep "feature-.*branching-cli"
36
+
37
+ # If exists, switch to it
38
+ mod branch switch feature-mod-cli-branching-cli
39
+
40
+ # If doesn't exist, create it
41
+ mod branch create feature-mod-cli-branching-cli --spec mod-cli/branching-cli.spec.md
42
+ ```
43
+ 2. **Verify branch setup**:
44
+ ```bash
45
+ mod branch status
46
+ # Should confirm specification branch is active and linked
47
+ ```
48
+
49
+ **Review Context Gathering (Automatic):**
50
+ 1. **Implementation Progress**: `mod branch status` shows current implementation changes
51
+ 2. **Specification Requirements**: `mod status <spec-name>.spec.md` shows requirements and traceability
52
+ 3. **Coverage Analysis**: `glassware` shows detailed traceability information
53
+ 4. **Code Structure**: Analyzes functions, classes, and existing glassware traces per file
54
+
55
+ ### Trace Writing Instructions
56
+ - Use **glassware annotations** for all traceability
57
+ - Every implementation trace must use: `// glassware[type=implementation, id=unique-id, requirements=REQ-ID]`
58
+ - Add traces directly in the implementation files that satisfy the requirement
59
+ - Do **not** invent requirement IDs; only use ones defined in the provided spec
60
+ - Each implementation must have a unique `id` attribute
61
+
62
+ ## Review Process
63
+
64
+ **Automated review agent that analyzes implementation against specification:**
65
+
66
+ 1. **Read and parse the complete specification** including all requirements
67
+ 2. **Run initial status check**: `glassware` to assess current traceability
68
+ 3. **Understand branch changes**: Use `mod branch status` to see what code changes exist on this branch
69
+ 4. **Scan all implementation files** in the codebase for related code
70
+ 5. **Add missing glassware traces** where implementation matches requirements
71
+ 6. **Update specification** where implementation has diverged but makes sense
72
+ 7. **Verify progress**: Re-run `glassware` to confirm improvements
73
+ 8. **Leave untraced code** that doesn't match any requirements (for IDE flagging)
74
+
75
+ ## Primary Tasks
76
+
77
+ ### 1. Audit Spec Coverage Granularity
78
+ - **Analyze function complexity** using automated detection (lines, conditionals, business logic patterns)
79
+ - **Flag under-specified complex functions** that need line-level traces but only have method-level
80
+ - **Flag over-specified simple functions** that have line-level traces when method-level is appropriate
81
+ - **Verify business logic traceability** - ensure all business logic has detailed line-level traces
82
+
83
+ ### 2. Add Missing Traceability
84
+ - **Scan implementation files** for code that fulfills spec requirements but lacks glassware traces
85
+ - **Add appropriate glassware references** with correct granularity based on complexity analysis
86
+ - **Use confidence thresholds** - only add traces where match is ≥95% certain
87
+
88
+ ### 3. Specification Updates
89
+ - **Identify implementation patterns** that extend beyond original requirements
90
+ - **Update specifications** to include discovered functionality that makes sense (including if implementation means parts of spec are no longer relevant)
91
+ - **Add new sub-requirements** (e.g., BEH-AUTH-1.1a) for legitimate extensions
92
+ - **Document rationale** for each specification update
93
+
94
+ ### 4. Flag Non-Compliant Code
95
+ - **Leave code without glassware traces** when it doesn't match any requirement
96
+ - **Identify implementation gaps** where spec requirements have no code
97
+ - **Report architectural violations** where code contradicts spec patterns
98
+
99
+ ## Output Actions
100
+
101
+ **File Updates:**
102
+ - **Implementation files**: Add glassware traces with appropriate granularity where code matches requirements
103
+ - **Specification files**: Update specs to reflect legitimate implementation extensions
104
+ - **Summary report**: List of granularity improvements, changes made, and issues flagged
105
+
106
+ **Quality Standards:**
107
+ - **Appropriate Granularity**: Apply method-level traces to simple functions, line-level to complex functions
108
+ - **Business Logic Priority**: Always ensure business logic has detailed line-level traceability
109
+ - **Conservative tracing**: Only add glassware traces with high confidence
110
+ - **Sensible spec updates**: Only update specs for logical extensions, not violations
111
+ - **Clear flagging**: Leave obvious gaps and violations untraced for developer attention
112
+
113
+ ### Spec Granularity Review Rules
114
+ **For each function, assess current glassware traces:**
115
+
116
+ 1. **Count Current Traces**:
117
+ - 1 glassware comment = method-level coverage
118
+ - 2+ glassware comments = line-level coverage
119
+
120
+ 2. **Apply Complexity Rules**:
121
+ - **Business Logic** (validate/auth/pay/charge/encrypt/save/persist): MUST have line-level traces
122
+ - **Complex Functions** (>10 lines OR conditionals): SHOULD have line-level traces
123
+ - **Simple Functions** (≤10 lines, no conditionals): Method-level traces OK
124
+
125
+ 3. **Review Actions**:
126
+ - **Under-specified**: Complex function with only method-level trace → Add line-level traces
127
+ - **Over-specified**: Simple function with line-level traces → Consider consolidating to method-level
128
+ - **Missing Business Logic**: Business function without detailed traces → Flag as critical gap
129
+
130
+ ### Glassware Format Reference
131
+
132
+ **In Markdown specs (requirements):**
133
+ ```markdown
134
+ The system must validate user credentials. <glassware type="requirement" id="REQ-AUTH-1" />
135
+ ```
136
+
137
+ **In TypeScript (implementations):**
138
+ ```typescript
139
+ // glassware[type=implementation, id=auth-login, requirements=REQ-AUTH-1]
140
+ export function login(email: string, password: string) { ... }
141
+ ```
142
+
143
+ ## Review Completion Validation
144
+
145
+ **Before completing review, run final verification:**
146
+ - Execute `glassware` to verify improved traceability coverage
147
+ - Use `mod branch status` to verify what code changes exist on branch
148
+ - Ensure all requirements show as "implemented" when code is properly traced
149
+ - Document coverage improvements achieved
150
+
151
+ **Result**: Complete bidirectional traceability with updated specifications that reflect actual implementation while flagging non-compliant code.