Skip to content

Commit ad4c8db

Browse files
committed
elaborate: fix hook exit behavior and update parse replacement strategy
- Use exit 2 + stderr (not exit 0) for missing deps in Claude Code hooks - exit 0 injects stdout as context; exit 2 discards stdout, shows stderr - Update han parse replacement to use jq + yq (Go) exclusively - Remove stale sed/Python fallback references https://claude.ai/code/session_01DzBkZ55Ls5oxB3RfJML4WT
1 parent 7a7eeab commit ad4c8db

File tree

1 file changed

+37
-23
lines changed
  • .ai-dlc/remove-hankeep-improve-state

1 file changed

+37
-23
lines changed

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

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,13 @@ Since state files are in the working tree, they get committed with normal `git a
108108
- No special tooling needed to read/write state
109109
- State merge conflicts are possible but manageable (JSON/MD files)
110110

111-
**3. `han parse` replacement**
111+
**3. `han parse` replacement`jq` + `yq` (Go)**
112112

113-
Replace `han parse` with lightweight alternatives:
114-
- **JSON parsing:** Use `jq` (already used in `config.sh`) or a small built-in shell function
115-
- **YAML parsing:** Use the existing `_yaml_get_simple` / `_yaml_get_array` functions from `dag.sh` (already working, no external dep)
116-
- **YAML-to-JSON:** Use `python3 -c 'import yaml, json, sys; ...'` or `yq` as optional
117-
- **JSON-set:** Use `jq` for JSON manipulation
118-
- **YAML-set:** Use `sed` for simple frontmatter updates (already partially done in `dag.sh`)
113+
Replace all `han parse` commands with:
114+
- **JSON read/write:** `jq` (already used in `config.sh`)
115+
- **YAML read/write:** `yq` (mikefarah/yq, Go version)
116+
- **Frontmatter read/write:** `yq --front-matter=extract` / `yq --front-matter=process` — directly replaces `han parse yaml-set` for `unit-*.md` and `intent.md` files
117+
- **YAML-to-JSON:** `yq -o=json`
119118

120119
### Dependency Management: `jq` and `yq` (Go)
121120

@@ -126,22 +125,37 @@ The `han` CLI bundled both parsing utilities and state storage in one tool. Repl
126125

127126
**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.
128127

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
128+
**Install check at plugin load time (SessionStart hook):**
129+
130+
Create `plugin/lib/deps.sh` sourced by `inject-context.sh` (and other hooks). Each hook calls `dlc_check_deps` early — replacing the current `command -v han` check.
131+
132+
On failure: **`exit 2` with install instructions on stderr**. In Claude Code hooks, `exit 0` means stdout gets injected as context; `exit 2` means stdout is discarded and only stderr is shown to the user. This is the correct way to signal a missing dependency without polluting Claude's context.
133+
134+
```bash
135+
dlc_check_deps() {
136+
local missing=()
137+
command -v jq &>/dev/null || missing+=("jq")
138+
139+
if command -v yq &>/dev/null; then
140+
if ! yq --version 2>&1 | grep -q "mikefarah"; then
141+
echo "AI-DLC requires mikefarah/yq (Go), but kislyuk/yq (Python) is installed." >&2
142+
echo "Install: https://github.com/mikefarah/yq#install" >&2
143+
exit 2
144+
fi
145+
else
146+
missing+=("yq")
147+
fi
148+
149+
if [ ${#missing[@]} -gt 0 ]; then
150+
echo "AI-DLC requires: ${missing[*]}" >&2
151+
echo "Install with:" >&2
152+
echo " brew install ${missing[*]} # macOS" >&2
153+
echo " sudo snap install ${missing[*]} # Ubuntu/Debian" >&2
154+
echo " go install github.com/mikefarah/yq/v4@latest # Go (yq only)" >&2
155+
exit 2
156+
fi
157+
}
158+
```
145159

146160
This replaces the implicit `han` dependency with explicit, well-known tools that most developers already have.
147161

0 commit comments

Comments
 (0)