Skip to content

Commit 81c332f

Browse files
committed
fix: close round-2 plan-vs-implementation gaps (A, B, C)
Gap A — SessionStart Tier 1 missing PROJECT-TOC.md content hooks/session-start now extracts the ## Files section of PROJECT-TOC.md and injects it as a <project-toc> block between the <harness-anchor-state> block and the meta-skill body. Per plan §1, this restores the original Progressive Disclosure design: agents see a project index at session start without needing an explicit Read. Token budget rebalanced: banner kept full, then TOC truncated first if needed, then skill body. 200-char buffer reserved for truncation markers. Final safety cap re-applied. Verified: cmake fixture session yields a 4018-char banner with TOC entries visible, well under 8000-char cap. Gap B — Context7/WebSearch callouts missing from 9/11 skills Added a "Looking up …" subsection to each skill (cpp-build-systems, cpp-static-analysis, cpp-sanitizers, cpp-formatting, init-verification, anti-hallucination-gates, project-indexing, feature-state-keeper, context-budget-discipline) directing agents to Context7 first, WebSearch as fallback, for unfamiliar tool errors / check names / API references. using-harness-anchor adds a meta rule: "When stuck, search docs first." Gap C — Skill descriptions exceeded plan §7 attention-table ≤150-char ideal Rewrote all 11 frontmatter descriptions, front-loading trigger keywords per learn-harness gotchas #12 (skill listing budget). Lengths now 129-150 chars (was 181-281). validate-anchor.sh ≤500 check still passes. Verification: validate-anchor.sh: 51/51 pass post-edit-warn contract test: 5/5 pass description length ≤150: all 11 OK Context7 coverage: 11/11 HAS SessionStart on CMake fixture: <project-toc> block present, entries visible Skipped Gap D (.harness-anchor/last-error.log for index-builder crashes) — rare failure path; stderr already captures errors; old TOC naturally preserved when index-builder exits before write.
1 parent f099f6c commit 81c332f

12 files changed

Lines changed: 148 additions & 23 deletions

File tree

hooks/session-start

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,77 @@ banner="${banner}
134134
135135
"
136136

137-
# ---- 6. Read meta-skill body ----
137+
# ---- 6. Read PROJECT-TOC.md "## Files" section (Tier 1 navigation index) ----
138+
# Per plan §1: Tier 1 should include "PROJECT-TOC.md 前 N 行(每文件一行,N 动态调整使总和 < 上限)"
139+
toc_block=""
140+
toc_files_section=""
141+
if [ -f "$toc_file" ]; then
142+
# Extract lines between "## Files" header and the next "## " header (or EOF).
143+
toc_files_section=$(awk '/^## Files/{flag=1; next} /^## /{flag=0} flag' "$toc_file" 2>/dev/null || true)
144+
# Strip leading/trailing blank lines
145+
toc_files_section=$(printf '%s' "$toc_files_section" | awk 'NF{p=1} p' | awk 'BEGIN{lines=""} {lines=lines $0 "\n"} END{sub(/\n+$/, "", lines); print lines}')
146+
if [ -n "$toc_files_section" ]; then
147+
toc_block="<project-toc>
148+
${toc_files_section}
149+
</project-toc>
150+
151+
"
152+
fi
153+
fi
154+
155+
# ---- 7. Read meta-skill body ----
138156
skill_content=""
139157
if [ -f "$SKILL_FILE" ]; then
140158
skill_content="$(cat "$SKILL_FILE")"
141159
else
142160
skill_content="(using-harness-anchor SKILL.md missing — plugin install incomplete)"
143161
fi
144162

145-
# ---- 7. Combine + token budget hard cap (≤ ~2000 tokens ≈ 8000 chars) ----
146-
combined="${banner}${skill_content}"
163+
# ---- 8. Combine + token budget hard cap (≤ ~2000 tokens ≈ 8000 chars) ----
164+
# Priority for truncation: banner (always full) → skill body → toc head (drop first).
147165
MAX_CHARS=8000
166+
banner_len=${#banner}
167+
skill_len=${#skill_content}
168+
169+
# Compute budget for TOC = remaining after banner + skill + 200-char buffer for markers
170+
toc_budget=$((MAX_CHARS - banner_len - skill_len - 200))
171+
172+
if [ -n "$toc_block" ]; then
173+
if [ "$toc_budget" -lt 250 ]; then
174+
# Not enough room for meaningful TOC head; drop it.
175+
toc_block=""
176+
elif [ "${#toc_block}" -gt "$toc_budget" ]; then
177+
# Truncate TOC content to fit budget; preserve block wrapper + add pointer.
178+
truncated_files="${toc_files_section:0:$toc_budget}"
179+
# Trim to last complete line so we don't cut mid-entry
180+
truncated_files="${truncated_files%$'\n'*}"
181+
toc_block="<project-toc>
182+
${truncated_files}
183+
<see PROJECT-TOC.md for full index>
184+
</project-toc>
185+
186+
"
187+
fi
188+
fi
189+
190+
combined="${banner}${toc_block}${skill_content}"
191+
192+
# Final safety: if skill body itself is enormous, truncate it.
148193
if [ "${#combined}" -gt "$MAX_CHARS" ]; then
149-
# Banner is small and authoritative; truncate the skill body to fit.
150-
banner_len=${#banner}
151194
marker="
152195
153196
<truncated — see ${SKILL_FILE} for full content>"
154197
marker_len=${#marker}
155-
skill_budget=$((MAX_CHARS - banner_len - marker_len))
156-
if [ "$skill_budget" -lt 0 ]; then
157-
# Banner alone exceeds budget — emit it raw, drop skill body.
158-
combined="${combined:0:$MAX_CHARS}"
198+
skill_budget=$((MAX_CHARS - banner_len - ${#toc_block} - marker_len))
199+
if [ "$skill_budget" -gt 0 ]; then
200+
combined="${banner}${toc_block}${skill_content:0:$skill_budget}${marker}"
159201
else
160-
combined="${banner}${skill_content:0:$skill_budget}${marker}"
202+
# Worst-case: even banner+TOC alone exceeds cap. Emit raw cap.
203+
combined="${combined:0:$MAX_CHARS}"
161204
fi
162205
fi
163206

164-
# ---- 8. JSON-escape (pure bash, no jq dependency) ----
207+
# ---- 9. JSON-escape (pure bash, no jq dependency) ----
165208
escape_for_json() {
166209
local s="$1"
167210
s="${s//\\/\\\\}"
@@ -174,7 +217,7 @@ escape_for_json() {
174217

175218
context="$(escape_for_json "$combined")"
176219

177-
# ---- 9. Emit Claude Code SessionStart JSON (silently injected as additionalContext) ----
220+
# ---- 10. Emit Claude Code SessionStart JSON (silently injected as additionalContext) ----
178221
printf '{\n "hookSpecificOutput": {\n "hookEventName": "SessionStart",\n "additionalContext": "%s"\n }\n}\n' "$context"
179222

180223
exit 0

skills/anti-hallucination-gates/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: anti-hallucination-gates
3-
description: Use before claiming a feature/fix/task is "done", "fixed", "complete", "working", "passing". Enforces Default-FAIL contract — every done criterion needs concrete evidence path. Express calibrated uncertainty when evidence is missing.
3+
description: Use before claiming "done", "fixed", "complete", "passing". Default-FAIL contract — every criterion needs evidence; express uncertainty if missing.
44
---
55

66
# Anti-Hallucination Gates
@@ -104,6 +104,15 @@ If any box is unchecked: state uncertainty explicitly, do NOT flip status to `pa
104104
- You're about to say "the fix should work"
105105
- The PostToolUse hook injected warnings — do NOT silently ignore them; surface and address per `self-correction-loop`
106106

107+
## Looking up evidence commands for unfamiliar frameworks
108+
109+
When the project uses a test/lint framework you don't have committed to memory (Catch2, doctest, ruff, deno test, etc.):
110+
111+
- **Context7** — fetch the framework's canonical CLI reference
112+
- **WebSearch** — "framework + test runner output format" usually surfaces what counts as evidence
113+
114+
Bluffing the command and not actually running it is the anti-pattern this skill exists to prevent.
115+
107116
## Related
108117

109118
- `feature-state-keeper` — actual writes to feature_list.json

skills/context-budget-discipline/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: context-budget-discipline
3-
description: Use when sessions run long, when adding subagents, when the agent fetches large files, or when planning context-heavy work. Applies SELECT / WRITE / COMPRESS / ISOLATE operations from 2026 context engineering practice. Prevents lost-in-the-middle and reduces token cost.
3+
description: Use when sessions run long, adding subagents, fetching large files, or planning context-heavy work. SELECT/WRITE/COMPRESS/ISOLATE discipline.
44
---
55

66
# Context Budget Discipline
@@ -88,6 +88,15 @@ You can roughly estimate context use by:
8888

8989
When the user asks "how much room do we have?", be honest about the estimate.
9090

91+
## Looking up context engineering research
92+
93+
For specific patterns (e.g., compaction algorithms, attention windowing, RAG indexing strategies):
94+
95+
- **Context7** — Anthropic / OpenAI engineering blog references on harnesses
96+
- **WebSearch** — "context engineering 2026" surfaces recent practitioner reports
97+
98+
Pattern names evolve fast in this area; don't rely on memory.
99+
91100
## Related
92101

93102
- `using-harness-anchor` — Tier 1 injection budget reference

skills/cpp-build-systems/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: cpp-build-systems
3-
description: Use in C/C++ projects when configuring builds, fixing build/configure errors, generating compile_commands.json, or selecting CMake/Meson/Make/Bazel commands. Always export compile_commands.json — it's required for static analysis and language tooling.
3+
description: Use in C/C++ projects for build configure/errors, compile_commands.json generation, or selecting CMake/Meson/Make/Bazel commands.
44
---
55

66
# C/C++ Build Systems
@@ -111,3 +111,12 @@ Run `bash ${CLAUDE_PLUGIN_ROOT}/scripts/cpp-detect.sh --target .` to get a JSON
111111
If you propose a build fix you haven't verified by running the build:
112112

113113
> "I believe the fix is `<change>`. Please run `cmake -S . -B .build && cmake --build .build` and share the output before we mark this resolved."
114+
115+
## Looking up tool errors
116+
117+
Unfamiliar CMake/Meson/Bazel error or missing-package message? Don't guess:
118+
119+
- **Context7** — query `cmake docs`, `meson docs`, `bazel docs` for canonical reference (structured, reliable)
120+
- **WebSearch** — the exact error string often surfaces a Stack Overflow / GitHub issue with the fix (fallback)
121+
122+
Prefer Context7 first; only fall back to WebSearch for recent ecosystem changes.

skills/cpp-formatting/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: cpp-formatting
3-
description: Use in C/C++ projects to apply clang-format consistently. Run on changed lines only, never reformat unchanged code mid-feature. Use .clang-format from project root or LLVM baseline.
3+
description: Use in C/C++ projects for clang-format. Changed-lines-only; never reformat unchanged code mid-feature. .clang-format from root or LLVM baseline.
44
---
55

66
# C/C++ Formatting (clang-format)
@@ -74,3 +74,12 @@ git diff --stat # should show only changed lines' format
7474
```
7575

7676
If clang-format touched files you didn't change, your `.clang-format` may have drifted between machines (different versions produce different output). Pin clang-format major version in CI.
77+
78+
## Looking up clang-format options
79+
80+
For an unfamiliar `.clang-format` key (e.g. `PenaltyExcessCharacter`, `BreakInheritanceList`):
81+
82+
- **Context7** — fetch the official clang-format options reference
83+
- **WebSearch** — search "clang-format <option-name>" for usage examples
84+
85+
Prefer Context7 for canonical documentation.

skills/cpp-sanitizers/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: cpp-sanitizers
3-
description: Use in C/C++ projects when debugging crashes, hangs, undefined behavior, data races, or memory errors. ASan/UBSan/TSan are runtime checkers — they catch what static analysis misses. Build sanitizer config separately; don't mix with release config.
3+
description: Use in C/C++ projects for crashes, hangs, UB, data races, memory errors. ASan/UBSan/TSan runtime checks. Build sanitizer config separately.
44
---
55

66
# C/C++ Sanitizers — Runtime Bug Catchers
@@ -104,3 +104,12 @@ Run: `ASAN_OPTIONS=suppressions=asan-suppressions.txt ./your_test`
104104
- Before any release / merge to main → run full ASan+UBSan suite
105105

106106
## See `ub-failure-patterns.md` for common UBSan signatures and their fixes.
107+
108+
## Looking up unfamiliar signatures
109+
110+
When a sanitizer report uses an error class outside `ub-failure-patterns.md`:
111+
112+
- **Context7** — query `clang sanitizers` or `address sanitizer` for canonical docs
113+
- **WebSearch** — search the exact error string for community reports
114+
115+
Prefer Context7; WebSearch is best for recent regressions or platform-specific issues.

skills/cpp-static-analysis/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: cpp-static-analysis
3-
description: Use in C/C++ projects when reviewing changed code, before claiming a feature done, or when investigating bugs. Runs clang-tidy / cppcheck / include-what-you-use (IWYU). Requires compile_commands.json. Surface warnings on changed lines only — don't dump the world.
3+
description: Use in C/C++ projects when reviewing changes or hunting bugs. Runs clang-tidy/cppcheck/IWYU. Needs compile_commands.json. Changed lines only.
44
---
55

66
# C/C++ Static Analysis
@@ -100,6 +100,15 @@ If a warning is wrong (false positive), file a one-line `// NOLINT(check-name)
100100

101101
If a warning is in code you didn't change (legacy area) and not a regression risk, defer it: note in `progress.md`, don't fix in this session. Scope discipline.
102102

103+
## Looking up unfamiliar checks
104+
105+
When you encounter a clang-tidy check name you don't recognize (e.g. `bugprone-suspicious-enum-usage`, `cert-err58-cpp`):
106+
107+
- **Context7** — fetch canonical clang-tidy check documentation
108+
- **WebSearch** — search "clang-tidy <check-name>" for discussions on false positives / edge cases
109+
110+
Same for cppcheck IDs and IWYU pragmas. Prefer Context7; WebSearch as fallback.
111+
103112
## Templates
104113

105114
- `.clang-tidy` baseline config: `templates/cpp/.clang-tidy.tpl` (copied by `/cpp-init`)

skills/feature-state-keeper/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: feature-state-keeper
3-
description: Use when starting, advancing, finishing, or blocking a feature. Manages feature_list.json scope record and progress.md/session-handoff.md state files. Enforces Default-FAIL: status='pass' requires non-null evidence.
3+
description: Use when starting, advancing, finishing, or blocking a feature. Manages feature_list.json + progress.md + session-handoff.md. Default-FAIL enforced.
44
---
55

66
# Feature State Keeper
@@ -112,6 +112,15 @@ Aim for ≤ 300 words. The next session should be able to resume from this alone
112112

113113
If the schema file is present, an external validator (e.g. `ajv-cli`) can verify. The agent need not run it — write valid JSON the first time by following the shape above.
114114

115+
## Looking up JSON Schema constraints
116+
117+
For non-trivial schema constructs (`allOf`, `oneOf`, `if/then`, regex patterns):
118+
119+
- **Context7**`json schema` for the canonical draft-07 / draft-2020-12 spec
120+
- **WebSearch** — specific keyword + "json schema" for examples
121+
122+
Don't guess schema syntax — `feature_list.schema.json` validation must stay correct.
123+
115124
## Related
116125

117126
- For evidence-gathering procedure → `anti-hallucination-gates` skill

skills/init-verification/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: init-verification
3-
description: Use at the start of work in a project, after any environment change (deps, branch switch, OS update), or when something "used to work" stops working. Runs init.sh health check; treats failures as blocking. Implements Anthropic's "verify environment before agent does work" pattern.
3+
description: Use at start of work, after env changes (deps/branch/OS), or when something stops working. Runs init.sh health check; treats failures as blocking.
44
---
55

66
# Init Verification
@@ -77,6 +77,15 @@ When it fails, list the specific failed step, not "init failed" alone.
7777
- Inside a subagent that was already given verified-healthy context
7878
- For trivial single-file edits where build/test aren't needed (rare; usually init still cheap enough to run)
7979

80+
## Looking up toolchain errors
81+
82+
When `init.sh` fails with a cryptic toolchain message (e.g., CMake "could not find compiler", npm `ENOENT`, cargo "linker not found"):
83+
84+
- **Context7** — fetch the tool's canonical docs (`cmake docs`, `npm docs`, `cargo book`)
85+
- **WebSearch** — the exact error string usually surfaces a known fix
86+
87+
Prefer Context7 for stable behavior; WebSearch for recent platform-specific changes.
88+
8089
## Related
8190

8291
- `/anchor` — scaffolds the initial `init.sh`

skills/project-indexing/SKILL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: project-indexing
3-
description: Use when locating files, understanding project structure, or before reaching for Glob/find. Consults PROJECT-TOC.md (one-line index of every git-tracked file). Detects staleness via git commit anchor.
3+
description: Use when locating files or understanding structure. Consults PROJECT-TOC.md (one-line index per file). Staleness via git commit anchor.
44
---
55

66
# Project Indexing
@@ -73,6 +73,15 @@ The `## Decisions` section is human-edited (long-lived architectural notes). The
7373

7474
`PROJECT-TOC.md` typically fits within a few thousand tokens even for medium projects. The SessionStart hook injects **only the first N lines** that fit the Tier 1 budget; the rest is read on demand. Don't ask the user to load the full TOC unless the budget allows.
7575

76+
## Looking up indexing techniques
77+
78+
For deeper context-engineering / progressive-disclosure indexing approaches not covered here:
79+
80+
- **Context7** — search "progressive disclosure llm agent" for harness research
81+
- **WebSearch** — recent agent harness blog posts and patterns
82+
83+
The current TOC algorithm is intentionally minimal; refinements (semantic chunks, embeddings) belong in a separate skill.
84+
7685
## Related
7786

7887
- `using-harness-anchor` — overall navigation, points here when files are sought

0 commit comments

Comments
 (0)