Skip to content

Commit 7a7eeab

Browse files
committed
elaborate: add jq/yq dependency management and parse library design
- Use mikefarah/yq (Go) for native --front-matter YAML parsing - Add deps.sh unit for install-time dependency checking - Add parse.sh library design with frontmatter operations - Detect wrong yq variant (kislyuk vs mikefarah) - Platform-specific install instructions (brew, snap, go, choco) https://claude.ai/code/session_01DzBkZ55Ls5oxB3RfJML4WT
1 parent 42171dd commit 7a7eeab

File tree

1 file changed

+65
-12
lines changed
  • .ai-dlc/remove-hankeep-improve-state

1 file changed

+65
-12
lines changed

.ai-dlc/remove-hankeep-improve-state/intent.md

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,40 @@ Replace `han parse` with lightweight alternatives:
117117
- **JSON-set:** Use `jq` for JSON manipulation
118118
- **YAML-set:** Use `sed` for simple frontmatter updates (already partially done in `dag.sh`)
119119

120+
### Dependency Management: `jq` and `yq` (Go)
121+
122+
The `han` CLI bundled both parsing utilities and state storage in one tool. Replacing it means the plugin now depends on two standard CLI tools:
123+
124+
- **`jq`** (v1.7+) — JSON parsing and manipulation
125+
- **`yq`** (mikefarah/yq, Go version, v4+) — YAML parsing with native `--front-matter` support
126+
127+
**Why Go `yq` specifically:** The Go version (`mikefarah/yq`) has a `--front-matter` flag that can extract/modify YAML frontmatter from markdown files directly — exactly what `han parse yaml-set` did for `unit-*.md` and `intent.md` files. The Python `yq` (kislyuk/yq) is just a jq wrapper and lacks this.
128+
129+
**Install check at plugin load time:**
130+
131+
Create `plugin/lib/deps.sh` that runs during plugin initialization (e.g., from `inject-context.sh`) and:
132+
133+
1. Checks for `jq` and `yq` (Go variant) in `$PATH`
134+
2. Validates the `yq` variant is mikefarah's (via `yq --version` output containing `mikefarah`)
135+
3. If missing, emits a clear error message with install instructions:
136+
```
137+
AI-DLC requires jq and yq (mikefarah/yq). Missing: yq
138+
Install with:
139+
brew install yq # macOS
140+
sudo snap install yq # Ubuntu/Debian
141+
go install github.com/mikefarah/yq/v4@latest # Go
142+
choco install yq # Windows
143+
```
144+
4. Optionally: if running in a CI/cloud environment (detected via `CI=true` or similar), auto-install via the appropriate package manager
145+
146+
This replaces the implicit `han` dependency with explicit, well-known tools that most developers already have.
147+
120148
### State Management Helper Library
121149

122150
Create a new `plugin/lib/state.sh` that provides a clean API matching the current `han keep` interface but using files:
123151

124152
```bash
125-
# Save state (writes file, auto-commits if in git)
153+
# Save state (writes file)
126154
dlc_state_save <key> <content> [--scope intent|unit] [--unit <unit-slug>]
127155

128156
# Load state (reads file)
@@ -138,6 +166,28 @@ dlc_state_list [--scope intent|unit] [--unit <unit-slug>]
138166
dlc_state_clear [--scope intent|unit] [--unit <unit-slug>]
139167
```
140168

169+
### Parse Helper Library
170+
171+
Create `plugin/lib/parse.sh` replacing all `han parse` commands:
172+
173+
```bash
174+
# JSON operations (thin wrappers around jq)
175+
dlc_json_get <field> [-r] # → jq -r '.<field>'
176+
dlc_json_set <field> <value> # → jq '.<field> = <value>'
177+
dlc_json_validate [--schema <s>] # → jq validation
178+
179+
# YAML operations (using yq Go)
180+
dlc_yaml_get <field> [-r] # → yq '.<field>'
181+
dlc_yaml_set <field> <value> # → yq '.<field> = <value>' -i
182+
dlc_yaml_to_json # → yq -o=json
183+
184+
# Frontmatter operations (yq's killer feature)
185+
dlc_frontmatter_get <field> <file> # → yq --front-matter=extract '.<field>' <file>
186+
dlc_frontmatter_set <field> <val> <file> # → yq --front-matter=process '.<field> = <val>' -i <file>
187+
```
188+
189+
This directly replaces `han parse yaml-set` which is used in `dag.sh:update_unit_status` and several skills.
190+
141191
---
142192

143193
## Improvement Opportunities for Intent State Management
@@ -219,29 +269,32 @@ eval "$(echo "$ITERATION_JSON" | jq -r '@sh "
219269

220270
## Units
221271

222-
### Unit 1: Create `state.sh` Library
272+
### Unit 1: Create `deps.sh` — Dependency Check & Install
273+
Build `plugin/lib/deps.sh` that validates `jq` (v1.7+) and `yq` (mikefarah/yq v4+) are installed. Provide clear install instructions per platform. Detect wrong `yq` variant (kislyuk vs mikefarah). Run at plugin initialization.
274+
275+
### Unit 2: Create `state.sh` Library
223276
Build `plugin/lib/state.sh` with file-based state management functions that mirror `han keep` semantics but use `.ai-dlc/{slug}/state/` files.
224277

225-
### Unit 2: Create `parse.sh` Library
226-
Build `plugin/lib/parse.sh` with JSON/YAML parsing utilities that replace `han parse` using `jq`, `sed`, and existing `_yaml_get_simple` patterns.
278+
### Unit 3: Create `parse.sh` Library
279+
Build `plugin/lib/parse.sh` with JSON/YAML parsing utilities that replace `han parse` using `jq` and `yq` (mikefarah/Go). Include frontmatter operations using `yq --front-matter`.
227280

228-
### Unit 3: Migrate Hooks
281+
### Unit 4: Migrate Hooks
229282
Update `inject-context.sh`, `enforce-iteration.sh`, and `subagent-context.sh` to use `state.sh` and `parse.sh` instead of `han keep` and `han parse`.
230283

231-
### Unit 4: Migrate Skills
232-
Update all 10 skills that use `han keep` (advance, blockers, completion-criteria, construct, elaborate, execute, fail, operate, reflect, refine, reset, resume) to use the new libraries.
284+
### Unit 5: Migrate Skills
285+
Update all skills that use `han keep` (advance, blockers, completion-criteria, construct, elaborate, execute, fail, operate, reflect, refine, reset, resume) to use the new libraries.
233286

234-
### Unit 5: Migrate Hat Documentation
287+
### Unit 6: Migrate Hat Documentation
235288
Update references in hat markdown files (builder, experimenter, observer, planner, red-team).
236289

237-
### Unit 6: Migrate Config Libraries
290+
### Unit 7: Migrate Config Libraries
238291
Update `config.sh` and `config.ts` to remove `han keep`/`han parse` dependencies.
239292

240-
### Unit 7: Simplify iteration.json
293+
### Unit 8: Simplify iteration.json
241294
Remove redundant `unitStates` field, add formal phase enum, reduce parsing overhead.
242295

243-
### Unit 8: Update Documentation
244-
Update README.md, website docs, paper references to reflect the removal of the `han` dependency.
296+
### Unit 9: Update Documentation
297+
Update README.md, website docs, paper references to reflect the removal of the `han` dependency and addition of `jq`/`yq` requirements.
245298

246299
---
247300

0 commit comments

Comments
 (0)