anvil-dev-framework 0.1.6

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 (190) hide show
  1. package/README.md +719 -0
  2. package/VERSION +1 -0
  3. package/docs/ANVIL-REPO-IMPLEMENTATION-PLAN.md +441 -0
  4. package/docs/FIRST-SKILL-TUTORIAL.md +408 -0
  5. package/docs/INSTALLATION-RETRO-NOTES.md +458 -0
  6. package/docs/INSTALLATION.md +984 -0
  7. package/docs/anvil-hud.md +469 -0
  8. package/docs/anvil-init.md +255 -0
  9. package/docs/anvil-state.md +210 -0
  10. package/docs/boris-cherny-ralph-wiggum-insights.md +608 -0
  11. package/docs/command-reference.md +2022 -0
  12. package/docs/hooks-tts.md +368 -0
  13. package/docs/implementation-guide.md +810 -0
  14. package/docs/linear-github-integration.md +247 -0
  15. package/docs/local-issues.md +677 -0
  16. package/docs/patterns/README.md +419 -0
  17. package/docs/planning-responsibilities.md +139 -0
  18. package/docs/session-workflow.md +573 -0
  19. package/docs/simplification-plan-template.md +297 -0
  20. package/docs/simplification-principles.md +129 -0
  21. package/docs/specifications/CCS-RALPH-INTEGRATION-DESIGN.md +633 -0
  22. package/docs/specifications/CCS-RESEARCH-REPORT.md +169 -0
  23. package/docs/specifications/PLAN-ANV-verification-ralph-wiggum.md +403 -0
  24. package/docs/specifications/PLAN-parallel-tracks-anvil-memory-ccs.md +494 -0
  25. package/docs/specifications/SPEC-ANV-VRW/component-01-verify.md +208 -0
  26. package/docs/specifications/SPEC-ANV-VRW/component-02-stop-gate.md +226 -0
  27. package/docs/specifications/SPEC-ANV-VRW/component-03-posttooluse.md +209 -0
  28. package/docs/specifications/SPEC-ANV-VRW/component-04-ralph-wiggum.md +604 -0
  29. package/docs/specifications/SPEC-ANV-VRW/component-05-atomic-actions.md +311 -0
  30. package/docs/specifications/SPEC-ANV-VRW/component-06-verify-subagent.md +264 -0
  31. package/docs/specifications/SPEC-ANV-VRW/component-07-claude-md.md +363 -0
  32. package/docs/specifications/SPEC-ANV-VRW/index.md +182 -0
  33. package/docs/specifications/SPEC-ANV-anvil-memory.md +573 -0
  34. package/docs/specifications/SPEC-ANV-context-checkpoints.md +781 -0
  35. package/docs/specifications/SPEC-ANV-verification-ralph-wiggum.md +789 -0
  36. package/docs/sync.md +122 -0
  37. package/global/CLAUDE.md +140 -0
  38. package/global/agents/verify-app.md +164 -0
  39. package/global/commands/anvil-settings.md +527 -0
  40. package/global/commands/anvil-sync.md +121 -0
  41. package/global/commands/change.md +197 -0
  42. package/global/commands/clarify.md +252 -0
  43. package/global/commands/cleanup.md +292 -0
  44. package/global/commands/commit-push-pr.md +207 -0
  45. package/global/commands/decay-review.md +127 -0
  46. package/global/commands/discover.md +158 -0
  47. package/global/commands/doc-coverage.md +122 -0
  48. package/global/commands/evidence.md +307 -0
  49. package/global/commands/explore.md +121 -0
  50. package/global/commands/force-exit.md +135 -0
  51. package/global/commands/handoff.md +191 -0
  52. package/global/commands/healthcheck.md +302 -0
  53. package/global/commands/hud.md +84 -0
  54. package/global/commands/insights.md +319 -0
  55. package/global/commands/linear-setup.md +184 -0
  56. package/global/commands/lint-fix.md +198 -0
  57. package/global/commands/orient.md +510 -0
  58. package/global/commands/plan.md +228 -0
  59. package/global/commands/ralph.md +346 -0
  60. package/global/commands/ready.md +182 -0
  61. package/global/commands/release.md +305 -0
  62. package/global/commands/retro.md +96 -0
  63. package/global/commands/shard.md +166 -0
  64. package/global/commands/spec.md +227 -0
  65. package/global/commands/sprint.md +184 -0
  66. package/global/commands/tasks.md +228 -0
  67. package/global/commands/test-and-commit.md +151 -0
  68. package/global/commands/validate.md +132 -0
  69. package/global/commands/verify.md +251 -0
  70. package/global/commands/weekly-review.md +156 -0
  71. package/global/hooks/__pycache__/ralph_context_monitor.cpython-314.pyc +0 -0
  72. package/global/hooks/__pycache__/statusline_agent_sync.cpython-314.pyc +0 -0
  73. package/global/hooks/anvil_memory_observe.ts +322 -0
  74. package/global/hooks/anvil_memory_session.ts +166 -0
  75. package/global/hooks/anvil_memory_stop.ts +187 -0
  76. package/global/hooks/parse_transcript.py +116 -0
  77. package/global/hooks/post_merge_cleanup.sh +132 -0
  78. package/global/hooks/post_tool_format.sh +215 -0
  79. package/global/hooks/ralph_context_monitor.py +240 -0
  80. package/global/hooks/ralph_stop.sh +502 -0
  81. package/global/hooks/statusline.sh +1110 -0
  82. package/global/hooks/statusline_agent_sync.py +224 -0
  83. package/global/hooks/stop_gate.sh +250 -0
  84. package/global/lib/.claude/anvil-state.json +21 -0
  85. package/global/lib/__pycache__/agent_registry.cpython-314.pyc +0 -0
  86. package/global/lib/__pycache__/claim_service.cpython-314.pyc +0 -0
  87. package/global/lib/__pycache__/coderabbit_service.cpython-314.pyc +0 -0
  88. package/global/lib/__pycache__/config_service.cpython-314.pyc +0 -0
  89. package/global/lib/__pycache__/coordination_service.cpython-314.pyc +0 -0
  90. package/global/lib/__pycache__/doc_coverage_service.cpython-314.pyc +0 -0
  91. package/global/lib/__pycache__/gate_logger.cpython-314.pyc +0 -0
  92. package/global/lib/__pycache__/github_service.cpython-314.pyc +0 -0
  93. package/global/lib/__pycache__/hygiene_service.cpython-314.pyc +0 -0
  94. package/global/lib/__pycache__/issue_models.cpython-314.pyc +0 -0
  95. package/global/lib/__pycache__/issue_provider.cpython-314.pyc +0 -0
  96. package/global/lib/__pycache__/linear_data_service.cpython-314.pyc +0 -0
  97. package/global/lib/__pycache__/linear_provider.cpython-314.pyc +0 -0
  98. package/global/lib/__pycache__/local_provider.cpython-314.pyc +0 -0
  99. package/global/lib/__pycache__/quality_service.cpython-314.pyc +0 -0
  100. package/global/lib/__pycache__/ralph_state.cpython-314.pyc +0 -0
  101. package/global/lib/__pycache__/state_manager.cpython-314.pyc +0 -0
  102. package/global/lib/__pycache__/transcript_parser.cpython-314.pyc +0 -0
  103. package/global/lib/__pycache__/verification_runner.cpython-314.pyc +0 -0
  104. package/global/lib/__pycache__/verify_iteration.cpython-314.pyc +0 -0
  105. package/global/lib/__pycache__/verify_subagent.cpython-314.pyc +0 -0
  106. package/global/lib/agent_registry.py +995 -0
  107. package/global/lib/anvil-state.sh +435 -0
  108. package/global/lib/claim_service.py +515 -0
  109. package/global/lib/coderabbit_service.py +314 -0
  110. package/global/lib/config_service.py +423 -0
  111. package/global/lib/coordination_service.py +331 -0
  112. package/global/lib/doc_coverage_service.py +1305 -0
  113. package/global/lib/gate_logger.py +316 -0
  114. package/global/lib/github_service.py +310 -0
  115. package/global/lib/handoff_generator.py +775 -0
  116. package/global/lib/hygiene_service.py +712 -0
  117. package/global/lib/issue_models.py +257 -0
  118. package/global/lib/issue_provider.py +339 -0
  119. package/global/lib/linear_data_service.py +210 -0
  120. package/global/lib/linear_provider.py +987 -0
  121. package/global/lib/linear_provider.py.backup +671 -0
  122. package/global/lib/local_provider.py +486 -0
  123. package/global/lib/orient_fast.py +457 -0
  124. package/global/lib/quality_service.py +470 -0
  125. package/global/lib/ralph_prompt_generator.py +563 -0
  126. package/global/lib/ralph_state.py +1202 -0
  127. package/global/lib/state_manager.py +417 -0
  128. package/global/lib/transcript_parser.py +597 -0
  129. package/global/lib/verification_runner.py +557 -0
  130. package/global/lib/verify_iteration.py +490 -0
  131. package/global/lib/verify_subagent.py +250 -0
  132. package/global/skills/README.md +155 -0
  133. package/global/skills/quality-gates/SKILL.md +252 -0
  134. package/global/skills/skill-template/SKILL.md +109 -0
  135. package/global/skills/testing-strategies/SKILL.md +337 -0
  136. package/global/templates/CHANGE-template.md +105 -0
  137. package/global/templates/HANDOFF-template.md +63 -0
  138. package/global/templates/PLAN-template.md +111 -0
  139. package/global/templates/SPEC-template.md +93 -0
  140. package/global/templates/ralph/PROMPT.md.template +89 -0
  141. package/global/templates/ralph/fix_plan.md.template +31 -0
  142. package/global/templates/ralph/progress.txt.template +23 -0
  143. package/global/tests/__pycache__/test_doc_coverage.cpython-314.pyc +0 -0
  144. package/global/tests/test_doc_coverage.py +520 -0
  145. package/global/tests/test_issue_models.py +299 -0
  146. package/global/tests/test_local_provider.py +323 -0
  147. package/global/tools/README.md +178 -0
  148. package/global/tools/__pycache__/anvil-hud.cpython-314.pyc +0 -0
  149. package/global/tools/anvil-hud.py +3622 -0
  150. package/global/tools/anvil-hud.py.bak +3318 -0
  151. package/global/tools/anvil-issue.py +432 -0
  152. package/global/tools/anvil-memory/CLAUDE.md +49 -0
  153. package/global/tools/anvil-memory/README.md +42 -0
  154. package/global/tools/anvil-memory/bun.lock +25 -0
  155. package/global/tools/anvil-memory/bunfig.toml +9 -0
  156. package/global/tools/anvil-memory/package.json +23 -0
  157. package/global/tools/anvil-memory/src/__tests__/ccs/context-monitor.test.ts +535 -0
  158. package/global/tools/anvil-memory/src/__tests__/ccs/edge-cases.test.ts +645 -0
  159. package/global/tools/anvil-memory/src/__tests__/ccs/fixtures.ts +363 -0
  160. package/global/tools/anvil-memory/src/__tests__/ccs/index.ts +8 -0
  161. package/global/tools/anvil-memory/src/__tests__/ccs/integration.test.ts +417 -0
  162. package/global/tools/anvil-memory/src/__tests__/ccs/prompt-generator.test.ts +571 -0
  163. package/global/tools/anvil-memory/src/__tests__/ccs/ralph-stop.test.ts +440 -0
  164. package/global/tools/anvil-memory/src/__tests__/ccs/test-utils.ts +252 -0
  165. package/global/tools/anvil-memory/src/__tests__/commands.test.ts +657 -0
  166. package/global/tools/anvil-memory/src/__tests__/db.test.ts +641 -0
  167. package/global/tools/anvil-memory/src/__tests__/hooks.test.ts +272 -0
  168. package/global/tools/anvil-memory/src/__tests__/performance.test.ts +427 -0
  169. package/global/tools/anvil-memory/src/__tests__/test-utils.ts +113 -0
  170. package/global/tools/anvil-memory/src/commands/checkpoint.ts +197 -0
  171. package/global/tools/anvil-memory/src/commands/get.ts +115 -0
  172. package/global/tools/anvil-memory/src/commands/init.ts +94 -0
  173. package/global/tools/anvil-memory/src/commands/observe.ts +163 -0
  174. package/global/tools/anvil-memory/src/commands/search.ts +112 -0
  175. package/global/tools/anvil-memory/src/db.ts +638 -0
  176. package/global/tools/anvil-memory/src/index.ts +205 -0
  177. package/global/tools/anvil-memory/src/types.ts +122 -0
  178. package/global/tools/anvil-memory/tsconfig.json +29 -0
  179. package/global/tools/ralph-loop.sh +359 -0
  180. package/package.json +45 -0
  181. package/scripts/anvil +822 -0
  182. package/scripts/extract_patterns.py +222 -0
  183. package/scripts/init-project.sh +541 -0
  184. package/scripts/install.sh +229 -0
  185. package/scripts/postinstall.js +41 -0
  186. package/scripts/rollback.sh +188 -0
  187. package/scripts/sync.sh +623 -0
  188. package/scripts/test-statusline.sh +248 -0
  189. package/scripts/update_claude_md.py +224 -0
  190. package/scripts/verify.sh +255 -0
@@ -0,0 +1,255 @@
1
+ # Anvil Init Command
2
+
3
+ > Initialize Anvil Development Framework in any project directory.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Initialize current directory with defaults
9
+ anvil init
10
+
11
+ # Initialize with all features
12
+ anvil init --template nextjs --with-hooks --with-linear
13
+
14
+ # Preview what would happen (dry run)
15
+ anvil init --dry-run
16
+ ```
17
+
18
+ ## Installation
19
+
20
+ ### Adding Anvil to PATH
21
+
22
+ Add this to your shell configuration (`~/.zshrc` or `~/.bashrc`):
23
+
24
+ ```bash
25
+ export PATH="$HOME/Projects/anvil-dev-framework/scripts:$PATH"
26
+
27
+ # Create alias for convenience
28
+ alias anvil="init-project.sh"
29
+ ```
30
+
31
+ Then reload your shell:
32
+ ```bash
33
+ source ~/.zshrc # or source ~/.bashrc
34
+ ```
35
+
36
+ ### Direct Script Usage
37
+
38
+ Alternatively, run the script directly:
39
+
40
+ ```bash
41
+ bash /path/to/anvil-dev-framework/scripts/init-project.sh [options]
42
+ ```
43
+
44
+ ## Command Reference
45
+
46
+ ```
47
+ anvil init [directory] [options]
48
+ ```
49
+
50
+ ### Arguments
51
+
52
+ | Argument | Description | Default |
53
+ |----------|-------------|---------|
54
+ | `directory` | Target directory to initialize | Current directory |
55
+
56
+ ### Options
57
+
58
+ | Option | Description |
59
+ |--------|-------------|
60
+ | `--template <type>` | Use a project template: `generic`, `nextjs`, `python`, `saas` |
61
+ | `--with-hooks` | Create symlinks to framework hooks and commands |
62
+ | `--with-linear` | Enable Linear integration (prompts for setup) |
63
+ | `--force` | Overwrite existing files (creates backups first) |
64
+ | `--dry-run` | Show what would be done without making changes |
65
+ | `--help` | Display help message |
66
+
67
+ ## Templates
68
+
69
+ ### Generic (Default)
70
+
71
+ Basic template suitable for any project type.
72
+
73
+ ```bash
74
+ anvil init --template generic
75
+ ```
76
+
77
+ ### Next.js
78
+
79
+ Pre-configured for Next.js + TypeScript + Supabase + Tailwind CSS projects.
80
+
81
+ ```bash
82
+ anvil init --template nextjs
83
+ ```
84
+
85
+ ### Python
86
+
87
+ Pre-configured for Python + FastAPI + SQLAlchemy projects.
88
+
89
+ ```bash
90
+ anvil init --template python
91
+ ```
92
+
93
+ ### SaaS
94
+
95
+ Full SaaS application template (Next.js based).
96
+
97
+ ```bash
98
+ anvil init --template saas
99
+ ```
100
+
101
+ ## Directory Structure
102
+
103
+ After initialization, your project will have:
104
+
105
+ ```
106
+ your-project/
107
+ ├── .claude/
108
+ │ ├── CLAUDE.md # Project-specific AI instructions
109
+ │ ├── constitution.md # Project principles
110
+ │ ├── product.md # Product definition
111
+ │ ├── linear.yaml # Linear team configuration
112
+ │ ├── commands/ # Skill commands (copied or symlinked)
113
+ │ ├── examples/ # Code convention examples
114
+ │ ├── handoffs/ # Session continuity documents
115
+ │ ├── hooks/ # Hook scripts (with --with-hooks)
116
+ │ ├── lib/ # Library modules (with --with-hooks)
117
+ │ └── specs/
118
+ │ ├── current/ # Active specifications
119
+ │ └── archive/ # Completed specifications
120
+ ├── .coderabbit.yaml # CodeRabbit configuration
121
+ ├── .pre-commit-config.yaml # Pre-commit hooks
122
+ └── .semgrep/
123
+ └── rules/ # Semgrep rules
124
+ ```
125
+
126
+ ## Examples
127
+
128
+ ### Basic Initialization
129
+
130
+ Initialize current directory with defaults:
131
+
132
+ ```bash
133
+ cd my-project
134
+ anvil init
135
+ ```
136
+
137
+ ### New Project Setup
138
+
139
+ Create and initialize a new directory:
140
+
141
+ ```bash
142
+ mkdir my-app && cd my-app
143
+ git init
144
+ anvil init --template nextjs
145
+ ```
146
+
147
+ ### Full Setup with All Features
148
+
149
+ ```bash
150
+ anvil init --template saas --with-hooks --with-linear
151
+ ```
152
+
153
+ This will:
154
+ 1. Copy SaaS template files
155
+ 2. Create symlinks to framework hooks and commands
156
+ 3. Prompt you to run `/linear-setup` for Linear integration
157
+
158
+ ### Preview Changes (Dry Run)
159
+
160
+ ```bash
161
+ anvil init --template python --with-hooks --dry-run
162
+ ```
163
+
164
+ Output shows what would be created without making changes.
165
+
166
+ ### Force Overwrite with Backup
167
+
168
+ ```bash
169
+ anvil init --force
170
+ ```
171
+
172
+ Existing files are backed up to `.claude/.backup/<timestamp>/` before overwriting.
173
+
174
+ ## The --with-hooks Option
175
+
176
+ The `--with-hooks` flag creates symlinks from your project to the central Anvil framework:
177
+
178
+ ### Symlinked Directories
179
+
180
+ | Project Path | Links To |
181
+ |--------------|----------|
182
+ | `.claude/hooks/` | `global/hooks/` |
183
+ | `.claude/commands/` | `global/commands/` |
184
+ | `.claude/lib/` | `global/lib/` |
185
+
186
+ ### Benefits
187
+
188
+ 1. **Automatic Updates**: Changes to global hooks apply to all projects
189
+ 2. **Consistency**: Same commands available everywhere
190
+ 3. **Reduced Duplication**: No need to copy files to each project
191
+
192
+ ### When to Use
193
+
194
+ - **With Hooks**: When you want the latest framework features
195
+ - **Without Hooks**: When you need isolated, project-specific commands
196
+
197
+ ## The --with-linear Option
198
+
199
+ Enables Linear integration for issue tracking:
200
+
201
+ ```bash
202
+ anvil init --with-linear
203
+ ```
204
+
205
+ After initialization, run `/linear-setup` in Claude Code to:
206
+ 1. Select your Linear team
207
+ 2. Configure team key mapping
208
+ 3. Enable workflow commands
209
+
210
+ ## Post-Initialization
211
+
212
+ After running `anvil init`:
213
+
214
+ 1. **Edit `.claude/CLAUDE.md`**: Add project-specific details
215
+ 2. **Review `.claude/constitution.md`**: Adjust principles for your project
216
+ 3. **Fill out `.claude/product.md`**: Define your product
217
+ 4. **Run `/linear-setup`**: If you used `--with-linear`
218
+
219
+ Then start using Anvil:
220
+
221
+ ```bash
222
+ # Open Claude Code
223
+ claude
224
+
225
+ # Run orientation
226
+ /orient
227
+ ```
228
+
229
+ ## Troubleshooting
230
+
231
+ ### Permission Denied
232
+
233
+ Ensure the script is executable:
234
+ ```bash
235
+ chmod +x /path/to/anvil-dev-framework/scripts/init-project.sh
236
+ ```
237
+
238
+ ### Pre-commit Not Found
239
+
240
+ Install pre-commit if missing:
241
+ ```bash
242
+ pip install pre-commit
243
+ # or
244
+ brew install pre-commit
245
+ ```
246
+
247
+ ### Symlinks Not Working on Windows
248
+
249
+ Windows requires administrator privileges for symlinks. Consider using Git Bash with elevated permissions or WSL.
250
+
251
+ ## See Also
252
+
253
+ - [Installation Guide](./INSTALLATION.md) - Complete Anvil setup
254
+ - [Session Workflow](./session-workflow.md) - How to use Anvil in sessions
255
+ - [Command Reference](./command-reference.md) - All available commands
@@ -0,0 +1,210 @@
1
+ # Anvil Session State System
2
+
3
+ The Anvil session state system tracks workflow context across sessions using a local JSON file (`.claude/anvil-state.json`). This enables the statusline to display current phase, active issues, and other context without requiring API calls.
4
+
5
+ ## Overview
6
+
7
+ The state file persists:
8
+ - **Workflow phase** (orient, explore, spec, plan, tasks, implement, verify, handoff)
9
+ - **Active spec/plan IDs** for current work
10
+ - **Active Linear issue key** being worked on
11
+ - **Last command executed** and timestamp
12
+ - **Cached git information** with TTL for performance
13
+
14
+ ## State File Location
15
+
16
+ ```
17
+ .claude/anvil-state.json
18
+ ```
19
+
20
+ **Important**: Add this file to your `.gitignore` — it contains session-specific state that shouldn't be committed.
21
+
22
+ ## State File Schema
23
+
24
+ ```json
25
+ {
26
+ "version": "1.0",
27
+ "session": {
28
+ "phase": "implement",
29
+ "activeSpec": "SPEC-ANV-22",
30
+ "activePlan": "PLAN-ANV-22",
31
+ "activeIssue": "ANV-42",
32
+ "lastCommand": "/plan",
33
+ "lastCommandAt": "2025-12-26T14:30:00Z"
34
+ },
35
+ "cache": {
36
+ "git": {
37
+ "branch": "feature/ANV-42",
38
+ "dirty": false,
39
+ "cachedAt": "2025-12-26T14:30:00Z",
40
+ "ttlSeconds": 5
41
+ }
42
+ },
43
+ "meta": {
44
+ "createdAt": "2025-12-26T14:00:00Z",
45
+ "updatedAt": "2025-12-26T14:30:00Z"
46
+ }
47
+ }
48
+ ```
49
+
50
+ ## Using the State Library
51
+
52
+ ### Sourcing the Library
53
+
54
+ ```bash
55
+ source "path/to/global/lib/anvil-state.sh"
56
+ ```
57
+
58
+ ### Basic Operations
59
+
60
+ ```bash
61
+ # Initialize state file (creates if missing)
62
+ anvil_state_init
63
+
64
+ # Set workflow phase
65
+ anvil_state_set_phase "implement"
66
+
67
+ # Set active spec/plan/issue
68
+ anvil_state_set_spec "SPEC-ANV-22"
69
+ anvil_state_set_plan "PLAN-ANV-22"
70
+ anvil_state_set_issue "ANV-42"
71
+
72
+ # Record command execution
73
+ anvil_state_set_command "/plan"
74
+
75
+ # Get a specific field
76
+ phase=$(anvil_state_get "session.phase")
77
+ issue=$(anvil_state_get "session.activeIssue")
78
+
79
+ # Update multiple fields at once
80
+ anvil_state_update "implement" "SPEC-001" "PLAN-001" "ANV-42" "/tasks"
81
+ ```
82
+
83
+ ### Git Cache
84
+
85
+ The library caches git information to avoid repeated git calls:
86
+
87
+ ```bash
88
+ # Get branch (uses cache if valid, otherwise fetches fresh)
89
+ branch=$(anvil_git_branch)
90
+
91
+ # Force cache update
92
+ anvil_git_cache_update
93
+
94
+ # Check if cache is still valid
95
+ if anvil_git_cache_valid; then
96
+ echo "Cache is fresh"
97
+ fi
98
+ ```
99
+
100
+ Default TTL is 5 seconds, configurable via `ANVIL_GIT_CACHE_TTL` environment variable.
101
+
102
+ ### Session Management
103
+
104
+ ```bash
105
+ # Clear session state (useful for /orient reset)
106
+ anvil_state_clear_session
107
+
108
+ # Debug: print current state
109
+ anvil_state_debug
110
+
111
+ # Check if state file exists and is valid JSON
112
+ if anvil_state_valid; then
113
+ echo "State is valid"
114
+ fi
115
+
116
+ # Repair corrupted state file
117
+ anvil_state_repair
118
+ ```
119
+
120
+ ## Function Reference
121
+
122
+ ### Core Functions
123
+
124
+ | Function | Description |
125
+ |----------|-------------|
126
+ | `anvil_check_jq` | Verify jq is installed, show install instructions if not |
127
+ | `anvil_state_path` | Get state file path, create directory if needed |
128
+ | `anvil_state_init` | Initialize state file with defaults |
129
+ | `anvil_state_read` | Read entire state as JSON |
130
+ | `anvil_state_get <field>` | Get specific field (dot notation) |
131
+ | `anvil_state_set <field> <value>` | Set specific field |
132
+ | `anvil_state_update <phase> <spec> <plan> <issue> <cmd>` | Update multiple fields |
133
+
134
+ ### Convenience Setters
135
+
136
+ | Function | Description |
137
+ |----------|-------------|
138
+ | `anvil_state_set_phase <phase>` | Set workflow phase |
139
+ | `anvil_state_set_spec <spec_id>` | Set active spec ID |
140
+ | `anvil_state_set_plan <plan_id>` | Set active plan ID |
141
+ | `anvil_state_set_issue <issue_key>` | Set active issue key |
142
+ | `anvil_state_set_command <command>` | Record command with timestamp |
143
+ | `anvil_state_clear_session` | Clear all session fields |
144
+
145
+ ### Git Cache Functions
146
+
147
+ | Function | Description |
148
+ |----------|-------------|
149
+ | `anvil_git_branch` | Get branch (cached) |
150
+ | `anvil_git_cache_update [branch]` | Update git cache |
151
+ | `anvil_git_cache_valid` | Check if cache is within TTL |
152
+
153
+ ### Utility Functions
154
+
155
+ | Function | Description |
156
+ |----------|-------------|
157
+ | `anvil_state_debug` | Pretty-print current state |
158
+ | `anvil_state_valid` | Check if state file exists and is valid JSON |
159
+ | `anvil_state_repair` | Backup corrupt file and recreate fresh |
160
+
161
+ ## Configuration
162
+
163
+ | Variable | Default | Description |
164
+ |----------|---------|-------------|
165
+ | `ANVIL_STATE_FILE` | `.claude/anvil-state.json` | State file path |
166
+ | `ANVIL_GIT_CACHE_TTL` | `5` | Git cache TTL in seconds |
167
+ | `ANVIL_STATE_VERSION` | `1.0` | State schema version |
168
+
169
+ ## Dependencies
170
+
171
+ - **jq**: Required for JSON parsing
172
+ - macOS: `brew install jq`
173
+ - Ubuntu: `sudo apt-get install jq`
174
+ - Fedora: `sudo dnf install jq`
175
+
176
+ ## Integration with Commands
177
+
178
+ Anvil workflow commands update the state file automatically:
179
+
180
+ | Command | Phase Set | Additional State |
181
+ |---------|-----------|------------------|
182
+ | `/orient` | `orient` | Clears activeSpec, activePlan |
183
+ | `/explore` | `explore` | — |
184
+ | `/spec` | `spec` | Sets activeSpec |
185
+ | `/plan` | `plan` | Sets activePlan |
186
+ | `/tasks` | `tasks` | — |
187
+ | `/evidence` | `verify` | — |
188
+ | `/handoff` | `handoff` | — |
189
+
190
+ ## Troubleshooting
191
+
192
+ ### State file not updating
193
+ 1. Check jq is installed: `which jq`
194
+ 2. Check file permissions on `.claude/` directory
195
+ 3. Run `anvil_state_debug` to see current state
196
+
197
+ ### Corrupted state file
198
+ ```bash
199
+ source global/lib/anvil-state.sh
200
+ anvil_state_repair
201
+ ```
202
+
203
+ ### Performance issues
204
+ - Increase `ANVIL_GIT_CACHE_TTL` if git operations are slow
205
+ - State operations should complete in <10ms
206
+
207
+ ## Related Documentation
208
+
209
+ - [SPEC-ANV-22: Statusline & Session State System](/.claude/specs/current/SPEC-ANV-22-statusline-session-state.md)
210
+ - [Statusline Configuration](./statusline.md) (coming soon)