Repository navigation
refactor(security-and-hardening): move code patterns into a skill-local reference (-40% tokens per load) - #579
Conversation
…into a skill-local reference SKILL.md loaded ~5.3k tokens on every activation, 30% of it inline TypeScript examples that an agent only needs when it reaches that code. docs/skill-anatomy.md already asks for SKILL.md under 500 lines with reference material in supporting files; this skill was at 524. Move the OWASP prevention patterns, input-validation and upload code, SSRF check, destructive-path discussion, dependency-audit decision tree, rate-limiting and secrets snippets, data-classification table, and LLM output example verbatim into references/hardening-patterns.md (same convention as constraint-driven-development/references/floor-guard.md). SKILL.md keeps the workflow: threat model, three-tier boundaries, and a condensed "Hardening Controls" section stating each rule with a deep link to its pattern. Frontmatter, Process, Rationalizations, Red Flags, and Verification are byte-identical to before. The skill's own review checklist duplicated references/security-checklist.md; replace it with a pointer and add its three privacy items to the shared checklist so nothing is lost. SKILL.md: 524 -> 216 lines, 4096 -> 2449 words (~-40% tokens per load). Routing unchanged: run-evals rank-1 stays 100%, no description edits. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Related: #571 adds a |
abhisheksharma2411
left a comment
There was a problem hiding this comment.
This is the right fix for the largest skill in the catalog, and I checked the thing that matters most for a 394-line deletion — whether anything was lost. Nothing was.
skills/security-and-hardening/SKILL.md 524 → 216 lines
new skill-local reference 324 lines
validate-skills.js 25 skills, 0 errors, 0 warnings
validate-reference-links.js 25 skills, 0 errors
Every section survives; they were renamed and regrouped, not dropped. I diffed the heading sets and chased each of the 14 that looked absent — Data Privacy & Compliance → Personal data and privacy + Data Classification, Securing AI / LLM Features → AI / LLM features + LLM Output Handling, Triaging Dependency Audit Results → Dependencies and supply chain + Dependency Audit Triage, and so on. The 37 → 40 heading count is reorganisation, not loss.
The one that needed real checking was the checklist, because it goes from 28 inline items to a single pointer. I walked all 28 against references/security-checklist.md and every one has a counterpart — "Users can only access their own resources" → Every resource access checks ownership/role (prevents IDOR) (L49), the reachability/install-script items → L178 and L186, error-internals → the Error Handling section, and so on. The shared file carries 49 items, so this is strictly more coverage than the inline copy, not less.
And the three items you added to the shared checklist are exactly the ones that had no counterpart — data classification/purpose/minimisation, retention plus a working deletion path including backups and indexes, and data-subject export/delete with third-party consent. That's the part that makes this a safe deduplication rather than a lossy one, and it's easy to skip.
Two things I'd call out as done right:
The reference is skill-local. skills/security-and-hardening/references/hardening-patterns.md, not repo-root references/ — matching skill-anatomy.md L125 ("material used by exactly one skill is a supporting file inside that skill's directory"). Nothing else in skills/ links it, so that's the correct side of the rule.
The inline checklist was duplicating the shared one. That duplication is the underlying problem, and the two copies had already drifted — the inline version was missing the privacy items the shared one now carries. Replacing a drifting copy with a pointer is better than keeping both in sync by hand.
For what it's worth, this closes the live violation of the documented 500-line Context Efficiency budget that security-and-hardening was the only skill breaching. I'd flagged that file on a validator PR and explicitly declined to do the content fix myself on the grounds that which material to move is an editorial judgement about the skill — this is that judgement, made by someone who knows the content, and it lands better than a mechanical split would have.
|
Thank you for such a careful review — walking all 28 inline checklist items against You called out the two decisions I was least sure about:
Thanks also for the context on the 500-line budget and #571 — that was the motivation here, and I agree the split should be an editorial call by whoever knows the content, not a mechanical one. #580 applies the same approach to |
addyosmani
left a comment
There was a problem hiding this comment.
Verified this end to end and it's a clean lossless split: all 15 code blocks moved byte-identical into hardening-patterns.md, nothing dropped, the inline checklist correctly points to the shared security-checklist.md (which already covers all of it plus the 3 privacy items you added), and every anchor resolves. It takes SKILL.md from 524 lines to 216, which is a real win. Smaller always-on context is exactly the direction I want given the Claude 5 feedback in #433. abhisheksharma2411 independently verified nothing was lost too. Merging, thank you.
`scripts/lib/skill-lint-test.js` was the only conflict: addyosmani#579 added the fenced-block stripping suite while this branch added the layout and context-budget suites, both at the end of the file. Resolved as a union — every test name from both sides survives (24 tests: 15 from main + 17 here, 8 shared with the merge base). Verified by name rather than by eyeballing the diff, after a first naive splice produced a file that parsed as `SyntaxError: Unexpected end of input`.
… in #579 #579 moved the code patterns verbatim, but three prose sections (supply chain, privacy, LLM) and the cookie bullet were rewritten rather than moved, and some rules ended up in none of SKILL.md, the reference, or the shared checklist. Restores them inline: the sameSite value and its CSRF reason, why forced audit fixes are dangerous, the audit signatures commands and "not automatic proof of compromise", the retention TTL, auditable consent, the (2025) on the OWASP LLM list, and "the full system prompt" plus "validate every tool argument" in the LLM rule. Red Flags already audits the system-prompt item, so the rule and its audit agree again. Same 216 lines, +55 words.
chore: sync fork with upstream — restore the security rules addyosmani#579 dropped
…skill-local reference
SKILL.md loaded ~4.3k tokens on every activation at 496 lines, just
under the 500-line budget in docs/skill-anatomy.md, with Step 3 ("Fix
Common Anti-Patterns") alone at ~1,800 words of worked TypeScript, SQL,
HTML, and TSX that an agent only needs once Step 2 has named the
bottleneck.
Move Step 3's body verbatim into references/optimization-patterns.md
(same convention as constraint-driven-development/references/floor-guard.md
and #579), promoting its #### headings to ## so the file stands alone.
SKILL.md keeps the workflow and replaces Step 3 with a condensed list:
each anti-pattern's rule and recognizable signature, with a deep link to
its worked fix. Every rule the Red Flags, Rationalizations, and
Verification sections rely on (read the plan before indexing, cache key
includes the viewer, bigger pool is not faster, neutral is a revert) is
still stated in SKILL.md.
Lines 1-120 (frontmatter through the Step 2 tables) and Step 4 onward
are byte-identical to before, so the two hunks in #492 still apply.
SKILL.md: 496 -> 267 lines, 3314 -> 2488 words (~-25% tokens per load).
Routing unchanged: run-evals rank-1 stays 100%, no description edits.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Why
security-and-hardening/SKILL.mdwas the largest skill in the catalog: 524 lines / 4,096 words (~5.3k tokens), loaded in full every time the skill activates. About 30% of those words were inline TypeScript examples (OWASP patterns, zod schema, SSRF check, rate limiter, LLM output handling) that an agent only needs at the moment it writes that specific code.docs/skill-anatomy.md already sets the rule: keep
SKILL.mdunder 500 lines, move reference material into supporting files, and prefer progressive disclosure because inline code is paid for on every load. This PR brings the skill in line with that rule without changing what it tells the agent to do.What changed
skills/security-and-hardening/SKILL.md— 524 → 216 lines, 4,096 → 2,449 wordsmain. No description edit, so routing is untouched.references/security-checklist.md; it is now a one-paragraph pointer.skills/security-and-hardening/references/hardening-patterns.md(new, 324 lines)sed, then verified by script that each block string appears unchanged). The 16th is the review checklist replaced by the pointer above.constraint-driven-development/references/floor-guard.md(feat(skills): add constraint-driven-development #472, merged), and skill-anatomy's "material used by exactly one skill is a supporting file inside that skill's directory".../../../references/depth.references/security-checklist.md— +3 linesVerification
node scripts/validate-skills.js— 25 skills, 0 errors, 0 warningsnode scripts/validate-reference-links.js— passnode scripts/run-evals.js --min-rank1 95— rank-1 100% (88/88), no collision warnings#anchorlinks from SKILL.md resolve to headings in the new file; no unlinked headings in the new filereferences/security-checklist.md;evals/skill-impact.mdhas no rejected entry for itScope
Deliberately one skill, content moved not rewritten, so the diff can be reviewed as a relocation. If the approach is welcome, the same treatment applies to
performance-optimization(4.3k tokens) andcode-review-and-quality(4.2k tokens) as follow-up PRs.🤖 Generated with Claude Code