Skip to content

feat: Add structural health checks to internal-skill-optimize#439

Merged
sahil-noon merged 2 commits into
mainfrom
skill-maintenance-toc-depth
Jun 20, 2026
Merged

feat: Add structural health checks to internal-skill-optimize#439
sahil-noon merged 2 commits into
mainfrom
skill-maintenance-toc-depth

Conversation

@sahil-noon

Copy link
Copy Markdown
Collaborator

Summary

Extends /internal-skill-optimize beyond content trimming with two structural health checks, encoding skill-maintenance best practices into the tool itself (so they're repeatable, not one-off).

New structural checks — run on all skill files including _*.md partials (unlike content optimization, which skips partials):

  • TOC check — flag/insert a ## Contents block on any file over 100 lines. Per Anthropic's skill-authoring guidance, long files need a table of contents so a partial read (head -100) still reveals the full scope.
  • Reference-depth checkreport (never auto-fix) reference chains deeper than one level from a skill (SKILL → A → B), which cause Claude to partial-read nested files and miss content.

Unchanged: content optimization still skips _*.md partials and files under 80 lines. The structural checks carve out the sole partial-touching exception (a TOC insert / depth report never trims a partial's prose), and the depth check is report-only because flattening a chain moves content — out of scope for an automatic write.

Notes

  • Dogfooded: the skill's own ## Contents block was added under its new rule (it's now 116 lines).
  • SPEC mirror docs/specs/skills/SPEC-internal-skill-optimize.md updated in lockstep (constitution requirement).
  • Skill-prose + SPEC only — no Go, no CLI, no migration.

Follow-ups (not in this PR)

  • Run /internal-skill-optimize batch mode to apply the new checks across all skills (TOC sweep on 24 files >100 lines; content trim on the big skills like fab-operator/fab-setup; depth-chain report).
  • Split _cli-fab.md (778 lines) by command-family — a separate change, since it moves content (which this skill deliberately does not do).

🤖 Generated with Claude Code

Extends the skill beyond content trimming with two structural checks that
run on ALL files including _*.md partials (unlike content optimization,
which skips partials):

- TOC check: flag/insert a ## Contents block on any file over 100 lines
  (Anthropic guidance — long files need a TOC so partial reads see full scope)
- Reference-depth check: report (never auto-fix) reference chains deeper than
  one level from a skill (SKILL → A → B), which cause partial-read misses

Content optimization is unchanged (still skips partials, still skips <80-line
files). Structural checks carve out the sole partial-touching exception and
the depth check is report-only (flattening moves content — out of scope).
Dogfooded the skill's own TOC. SPEC mirror updated in lockstep.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds structural “health checks” to the /internal-skill-optimize skill (TOC insertion for long files and a reference-depth audit) and updates the corresponding SPEC mirror to reflect the new behavior and scoping rules.

Changes:

  • Expanded /internal-skill-optimize to include two structural checks (TOC for files >100 lines; report-only reference-depth chains >1).
  • Clarified differing scoping rules between content trimming (skips _*.md and <80 lines) vs structural checks (runs on all files, including partials).
  • Updated SPEC-internal-skill-optimize.md to mirror the new flow/output fields.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/kit/skills/internal-skill-optimize.md Documents new structural checks, adds a ## Contents section, and updates execution/constraints to reflect expanded behavior.
docs/specs/skills/SPEC-internal-skill-optimize.md Mirrors the updated skill behavior, flow, and constraints in the SPEC.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/kit/skills/internal-skill-optimize.md

| Signal | What to look for | Fix |
|--------|-----------------|-----|
| **Missing table of contents** | A file **over 100 lines** with no `## Contents` (or `## Table of Contents`) block near the top. Anthropic's guidance: long files need a TOC so a partial read (`head -100`) still reveals the full scope. | Insert a `## Contents` bullet list of the file's `##`-level section headings, immediately after the H1 (and after the `_preamble.md` blockquote / frontmatter if present). List section titles only — no prose. |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5f7c2389 — the placement guidance now states explicit document order: frontmatter → H1 → _preamble.md blockquote (if present) → ## Contents → first section.

- If a skill is already under 80 lines, report it as "Already lean — skipped" and move on
- **Content optimization** DO NOT touch any `_*.md` partial — every `_*.md` file is a shared partial: the reference, not the target. **Structural checks are the sole exception**: a TOC insertion may add a `## Contents` block to a partial, and the depth check may *report* on a partial — neither trims a partial's prose.
- The reference-depth check is **report-only** — it never restructures or moves content (flattening a deep chain is a separate, content-moving change).
- If a skill is already under 80 lines, report it as "Already lean — skipped" for **content** optimization — but still run the **structural** checks on it (a 90-line file can still need a TOC if it crosses 100 lines later; the depth check applies regardless of length).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5f7c2389 — rephrased to make it explicit that the TOC check is a no-op below 100 lines, while the depth check applies at any length (so a sub-80-line file is only ever flagged for a deep reference chain, never a missing TOC).

Comment thread docs/specs/skills/SPEC-internal-skill-optimize.md Outdated
Comment thread docs/specs/skills/SPEC-internal-skill-optimize.md Outdated
@sahil-noon
sahil-noon marked this pull request as ready for review June 20, 2026 12:45
Five precision/consistency fixes from Copilot review (PR #439):
- Contents TOC bullets stripped to section titles only (was carrying prose,
  violating the skill's own 'titles only' rule)
- TOC placement guidance now states explicit document order
  (frontmatter → H1 → preamble blockquote → Contents → first section)
- Rephrased the contradictory sub-80-line parenthetical: TOC check is a no-op
  below 100 lines; depth check applies at any length
- Aligned both SPEC 'Already lean' strings to the skill's 'Already lean — skipped'
@sahil-noon
sahil-noon merged commit 8a0c260 into main Jun 20, 2026
3 checks passed
@sahil-noon
sahil-noon deleted the skill-maintenance-toc-depth branch June 20, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants