Skip to content

refactor: overhead-aware budgets, drop deps, limit tags#44

Merged
harlan-zw merged 3 commits intomainfrom
refactor/skill-md-tags
Mar 24, 2026
Merged

refactor: overhead-aware budgets, drop deps, limit tags#44
harlan-zw merged 3 commits intomainfrom
refactor/skill-md-tags

Conversation

@harlan-zw
Copy link
Copy Markdown
Collaborator

@harlan-zw harlan-zw commented Mar 24, 2026

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Cleans up generated SKILL.md content and makes section budgets adaptive.

SKILL.md cleanup:

  • Removes the **Deps:** line entirely (duplicates node_modules/<pkg>/package.json)
  • Limits **Tags:** to the 3 most recently released dist-tags, sorted by releasedAt

Overhead-aware budgets:

  • Section budgets now account for actual SKILL.md overhead (frontmatter, header, search block, footer) by counting lines of the base SKILL.md before LLM sections run
  • Total target raised from ~300 to 500 lines since we now subtract real overhead
  • Per-section limits bumped proportionally: best-practices 100/250 lines with 6/15 items, api-changes 60/130 lines with 8/18 items

Summary by CodeRabbit

  • Updates
    • Removed dependency information from generated skill headers.
    • Simplified search command guidance in generated documentation.
    • Distribution tags now sorted by release date and limited to the top 3 entries.
    • Improved content budgeting for documentation sections to better account for document overhead and optimize line allocation across sections.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

Removed dependency rendering from SKILL.md generation and added an overheadLines metric that is computed from generated SKILL.md and threaded through sync/install flows, prompt builders, and LLM optimization; several prompt sections' line budgets and signatures were updated to account for overhead. Search block and tag rendering were simplified/limited.

Changes

Cohort / File(s) Summary
Prompt core & skill output
src/agent/prompts/skill.ts
Removed dependencies from SkillOptions; simplified generateSearchBlock to accept only name; changed dist-tag sorting to descending releasedAt and limited rendered tags to the top 3.
Sync / Install callers
src/commands/install.ts, src/commands/sync.ts, src/commands/sync-parallel.ts, src/commands/sync-shared.ts
Stopped extracting/passing dependencies into generateSkillMd; compute overheadLines (SKILL.md line count) after base write and propagate it into BaseSkillData, writePromptFiles, and optimizeDocs/LLM flows.
CLI / optimize entrypoints
src/agent/clis/index.ts, src/agent/clis/types.ts
Added optional overheadLines to OptimizeDocsOptions; optimizeDocs now forwards overheadLines into prompt building.
Prompt building & section contracts
src/agent/prompts/prompt.ts, src/agent/prompts/optional/types.ts
Added overheadLines to BuildSkillPromptOptions and SectionContext; buildSectionPrompt includes overheadLines in per-section context and passes it to customSection.
Per-section budget & validators
src/agent/prompts/optional/budget.ts, src/agent/prompts/optional/api-changes.ts, src/agent/prompts/optional/best-practices.ts, src/agent/prompts/optional/custom.ts
Line-budget model changed to subtract SKILL.md overhead from total target and cap per-section allocations; several sections now accept overheadLines and have increased line/item limits.

Sequence Diagram(s)

sequenceDiagram
  participant Sync as Sync Command
  participant Gen as generateSkillMd
  participant FS as FileSystem / BaseSkillData
  participant Writer as writePromptFiles
  participant Optimize as optimizeDocs / LLM
  participant Sections as buildAllSectionPrompts

  Sync->>Gen: request SKILL.md (no dependencies)
  Gen-->>Sync: return SKILL.md
  Sync->>FS: write SKILL.md and compute overheadLines = countLines(SKILL.md)
  Sync->>Writer: write prompt files (include overheadLines)
  Writer->>Optimize: optimizeDocs(overheadLines)
  Optimize->>Sections: buildAllSectionPrompts(overheadLines)
  Sections-->>Optimize: section prompts (budgets adjusted by overhead)
  Optimize-->>Sync: optimized content / updates
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through files with careful bounds,
Trimmed dependency traces from the grounds,
Counted lines and tucked them neat,
Tags trimmed to three, search made sweet,
A carrot for prompts and clearer rounds. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: overhead-aware budgets, drop deps, limit tags' directly and accurately summarizes the three main changes: overhead-aware budgeting, removal of dependencies line, and tag limiting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/skill-md-tags

Comment @coderabbitai help to get the list of available commands and usage tips.

@harlan-zw harlan-zw changed the title refactor: drop deps from SKILL.md, limit tags to 3 most recent refactor: overhead-aware budgets, drop deps, limit tags Mar 24, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/agent/clis/index.ts (1)

563-585: ⚠️ Potential issue | 🟠 Major

Budget-aware prompts need budget-aware section cache keys.

overheadLines now changes the prompt content and section cap, but the reusable readCachedSection() / writeSections() path is still keyed only by packageName + version + outputFile. A section cached from a slimmer base SKILL.md will be reused for a larger-overhead skill and skip regeneration, so the new line budgeting silently stops applying. The prompt-hash cache is safe here; the version cache needs the same budget signature or it should be bypassed for overhead-aware runs.

Also applies to: 600-623, 725-733

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/agent/clis/index.ts` around lines 563 - 585, The cached section
lookup/playback must include the budget signature so overheadLines changes
invalidate or bypass the version cache: update the cache key construction used
by readCachedSection and writeSections (and any version-based cache path in
optimizeDocs) to incorporate overheadLines (or a derived budget hash) and ensure
buildAllSectionPrompts/section prompt generation uses the same signature;
alternatively, when overheadLines is present and non-default, bypass the version
cache path in optimizeDocs so sections are regenerated using the new line
budget.
src/commands/sync.ts (1)

1039-1054: ⚠️ Potential issue | 🟡 Minor

Portable prompt export still uses the fixed default overhead.

In exportPortablePrompts(), prompt budgets are computed before the base SKILL.md exists, so buildAllSectionPrompts() never receives the real overheadLines and falls back to DEFAULT_OVERHEAD. That makes the no-agent / portable path diverge from the sync flows updated in this PR. Precompute the base skill header/footer lines here too and pass them into the prompt builder.

Also applies to: 1068-1089

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/sync.ts` around lines 1039 - 1054, The portable-export path
computes prompt budgets before the base SKILL.md is created so
buildAllSectionPrompts() receives DEFAULT_OVERHEAD instead of the real
overheadLines; update exportPortablePrompts() to precompute the base skill
header/footer line counts (the same way the sync flow does) and pass the
resulting overheadLines into buildAllSectionPrompts() (and any other
buildAllSectionPrompts() calls in this block, e.g., the calls around the
1068-1089 region) so prompt budgets match the non-portable sync flow rather than
using DEFAULT_OVERHEAD.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/agent/prompts/optional/budget.ts`:
- Around line 12-21: maxLines currently uses remainingLines() as a global cap
for each section, allowing the sum of per-section caps to exceed the actual body
allowance; update maxLines to compute a per-section share of the remaining
budget instead of using the full remaining for every section — e.g., calculate
remaining = remainingLines(overheadLines), derive a divisor from sectionCount
(use Math.max(1, sectionCount ?? 1)) or compute weights from
budgetScale(sectionCount) and the sum of scales, then clamp each section’s cap
to Math.min(Math.round(max * scale), Math.floor(remaining / divisor)) (or a
proportional share based on weights) so the combined caps cannot exceed
TOTAL_TARGET - overhead; retain references to remainingLines, maxLines,
budgetScale, TOTAL_TARGET and DEFAULT_OVERHEAD when making the change.

---

Outside diff comments:
In `@src/agent/clis/index.ts`:
- Around line 563-585: The cached section lookup/playback must include the
budget signature so overheadLines changes invalidate or bypass the version
cache: update the cache key construction used by readCachedSection and
writeSections (and any version-based cache path in optimizeDocs) to incorporate
overheadLines (or a derived budget hash) and ensure
buildAllSectionPrompts/section prompt generation uses the same signature;
alternatively, when overheadLines is present and non-default, bypass the version
cache path in optimizeDocs so sections are regenerated using the new line
budget.

In `@src/commands/sync.ts`:
- Around line 1039-1054: The portable-export path computes prompt budgets before
the base SKILL.md is created so buildAllSectionPrompts() receives
DEFAULT_OVERHEAD instead of the real overheadLines; update
exportPortablePrompts() to precompute the base skill header/footer line counts
(the same way the sync flow does) and pass the resulting overheadLines into
buildAllSectionPrompts() (and any other buildAllSectionPrompts() calls in this
block, e.g., the calls around the 1068-1089 region) so prompt budgets match the
non-portable sync flow rather than using DEFAULT_OVERHEAD.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d98aa5c2-0b44-46c6-ad7e-d63355f3cf62

📥 Commits

Reviewing files that changed from the base of the PR and between 5b5a901 and 153b18e.

📒 Files selected for processing (11)
  • src/agent/clis/index.ts
  • src/agent/clis/types.ts
  • src/agent/prompts/optional/api-changes.ts
  • src/agent/prompts/optional/best-practices.ts
  • src/agent/prompts/optional/budget.ts
  • src/agent/prompts/optional/custom.ts
  • src/agent/prompts/optional/types.ts
  • src/agent/prompts/prompt.ts
  • src/commands/sync-parallel.ts
  • src/commands/sync-shared.ts
  • src/commands/sync.ts
✅ Files skipped from review due to trivial changes (2)
  • src/agent/clis/types.ts
  • src/agent/prompts/optional/types.ts

Comment thread src/agent/prompts/optional/budget.ts Outdated
@harlan-zw harlan-zw force-pushed the refactor/skill-md-tags branch from 153b18e to 0620c5d Compare March 24, 2026 04:36
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/commands/sync-parallel.ts (1)

337-356: ⚠️ Potential issue | 🟠 Major

Use the resolved package name in phase 2.

pkg is still the raw CLI spec here. For inputs like vue@beta, prompt generation and the enhanceWithLLM(...) call below end up targeting vue@beta instead of the resolved package name that phase 1 used for the skill dir, references, and version state. Please switch these phase-2 calls to data.resolved.name (or the parsed package name) so dist-tag syncs keep pointing at the correct package.

Also applies to: 367-370

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/sync-parallel.ts` around lines 337 - 356, The loop over
uncachedPkgs uses the raw CLI spec variable pkg when calling writePromptFiles
and later enhanceWithLLM, causing phase-2 operations to target the un-resolved
name (e.g., "vue@beta"); update these calls to use the resolved package
identifier from skillData (data.resolved.name or parsed package name) instead of
pkg, e.g., pass data.resolved.name for packageName and any other package-name
arguments in writePromptFiles and enhanceWithLLM so prompts, versions, and
dist-tag syncs reference the same resolved package used to build skillDir and
version state.
src/commands/sync.ts (1)

1084-1103: ⚠️ Potential issue | 🟡 Minor

Portable prompt export still skips the overhead-aware budget flow.

This path only generates the base SKILL.md at the end of exportPortablePrompts(), after buildAllSectionPrompts(...) has already run, so portable prompts still fall back to DEFAULT_OVERHEAD. --agent none / portable exports won't get the same section caps as the main sync flow unless this path also computes and passes overheadLines before prompt generation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/sync.ts` around lines 1084 - 1103, The portable export path in
exportPortablePrompts() currently writes SKILL.md after
buildAllSectionPrompts(...) but never computes or passes the overheadLines used
by the main sync flow, so portable prompts fall back to DEFAULT_OVERHEAD; fix by
computing overheadLines the same way the main sync flow does (replicating the
overhead calculation used elsewhere), pass the computed overheadLines into
buildAllSectionPrompts(...) when generating section prompts for portable
exports, and include overheadLines in the options passed to generateSkillMd(...)
so the exported SKILL.md and prompts respect the same overhead-aware caps (refer
to exportPortablePrompts, buildAllSectionPrompts, generateSkillMd, and the
SKILL.md write call to locate and update the code).
♻️ Duplicate comments (1)
src/agent/prompts/optional/budget.ts (1)

13-23: ⚠️ Potential issue | 🟡 Minor

Don’t force min when the remaining body budget is already smaller than it.

If perSection drops below min, Math.max(min, ...) still restores the minimum cap, so the combined section limits can exceed the actual remaining body allowance again. Large overheadLines values should reduce the cap below min, not reintroduce the overflow.

Possible fix
 /** Available body lines after overhead is subtracted */
 function remainingLines(overheadLines?: number): number {
-  return TOTAL_TARGET - (overheadLines ?? DEFAULT_OVERHEAD)
+  return Math.max(0, TOTAL_TARGET - (overheadLines ?? DEFAULT_OVERHEAD))
 }
 
 /** Scale max lines based on enabled section count and available remaining space. */
 export function maxLines(min: number, max: number, sectionCount?: number, overheadLines?: number): number {
   const remaining = remainingLines(overheadLines)
   const sections = Math.max(1, sectionCount ?? 1)
   const perSection = Math.floor(remaining / sections)
   const scale = budgetScale(sectionCount)
-  return Math.max(min, Math.min(Math.round(max * scale), perSection))
+  const scaledMax = Math.min(Math.round(max * scale), perSection)
+  return perSection < min ? scaledMax : Math.max(min, scaledMax)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/agent/prompts/optional/budget.ts` around lines 13 - 23, The current
maxLines enforces the min cap even when perSection (computed from
remainingLines) is below min, allowing total sections to exceed the actual body
budget; update maxLines so that if perSection < min it returns perSection (i.e.,
honor the remaining budget) otherwise apply the existing logic (compute scale
via budgetScale, cap = Math.min(Math.round(max * scale), perSection) and then
enforce min/max). Refer to remainingLines, maxLines, perSection, sectionCount
and budgetScale to locate and implement this conditional.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/commands/sync-parallel.ts`:
- Around line 337-356: The loop over uncachedPkgs uses the raw CLI spec variable
pkg when calling writePromptFiles and later enhanceWithLLM, causing phase-2
operations to target the un-resolved name (e.g., "vue@beta"); update these calls
to use the resolved package identifier from skillData (data.resolved.name or
parsed package name) instead of pkg, e.g., pass data.resolved.name for
packageName and any other package-name arguments in writePromptFiles and
enhanceWithLLM so prompts, versions, and dist-tag syncs reference the same
resolved package used to build skillDir and version state.

In `@src/commands/sync.ts`:
- Around line 1084-1103: The portable export path in exportPortablePrompts()
currently writes SKILL.md after buildAllSectionPrompts(...) but never computes
or passes the overheadLines used by the main sync flow, so portable prompts fall
back to DEFAULT_OVERHEAD; fix by computing overheadLines the same way the main
sync flow does (replicating the overhead calculation used elsewhere), pass the
computed overheadLines into buildAllSectionPrompts(...) when generating section
prompts for portable exports, and include overheadLines in the options passed to
generateSkillMd(...) so the exported SKILL.md and prompts respect the same
overhead-aware caps (refer to exportPortablePrompts, buildAllSectionPrompts,
generateSkillMd, and the SKILL.md write call to locate and update the code).

---

Duplicate comments:
In `@src/agent/prompts/optional/budget.ts`:
- Around line 13-23: The current maxLines enforces the min cap even when
perSection (computed from remainingLines) is below min, allowing total sections
to exceed the actual body budget; update maxLines so that if perSection < min it
returns perSection (i.e., honor the remaining budget) otherwise apply the
existing logic (compute scale via budgetScale, cap = Math.min(Math.round(max *
scale), perSection) and then enforce min/max). Refer to remainingLines,
maxLines, perSection, sectionCount and budgetScale to locate and implement this
conditional.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0db1ceca-4e89-4ec2-b91d-b88ad5b11988

📥 Commits

Reviewing files that changed from the base of the PR and between 153b18e and 0620c5d.

📒 Files selected for processing (13)
  • src/agent/clis/index.ts
  • src/agent/clis/types.ts
  • src/agent/prompts/optional/api-changes.ts
  • src/agent/prompts/optional/best-practices.ts
  • src/agent/prompts/optional/budget.ts
  • src/agent/prompts/optional/custom.ts
  • src/agent/prompts/optional/types.ts
  • src/agent/prompts/prompt.ts
  • src/agent/prompts/skill.ts
  • src/commands/install.ts
  • src/commands/sync-parallel.ts
  • src/commands/sync-shared.ts
  • src/commands/sync.ts
💤 Files with no reviewable changes (1)
  • src/commands/install.ts
✅ Files skipped from review due to trivial changes (1)
  • src/agent/prompts/optional/types.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/agent/prompts/optional/custom.ts
  • src/agent/clis/types.ts
  • src/agent/clis/index.ts
  • src/agent/prompts/optional/api-changes.ts
  • src/agent/prompts/optional/best-practices.ts

Remove the Deps line from generated SKILL.md entirely as it duplicates
what's already in node_modules. Limit Tags to the 3 most recently
released dist-tags, sorted by release date, with dates shown.
Section budgets now account for actual SKILL.md overhead (frontmatter,
header, search block, footer). The base SKILL.md line count is passed
through to budget functions so sections fill available space rather
than using fixed estimates.

Total target raised from 300 to 500 lines. Per-section limits bumped
proportionally: best-practices 100/250 lines 6/15 items, api-changes
60/130 lines 8/18 items.
@harlan-zw harlan-zw force-pushed the refactor/skill-md-tags branch from 0620c5d to 4e4826b Compare March 24, 2026 04:47
@harlan-zw harlan-zw merged commit 77d8422 into main Mar 24, 2026
2 checks passed
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.

1 participant