-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/token optimization #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2fce146
5d5f390
0b11981
535b88c
f66417e
3ecf22b
975f478
bbefe36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,37 +8,49 @@ description: Incremental skill updater that maps git diffs to affected skills an | |||||
| This skill triggers when editing doc-sync-related files: | ||||||
| - `src/commands/doc-sync.js` | ||||||
| - `src/prompts/doc-sync.md` | ||||||
| - `src/prompts/doc-sync-refresh.md` | ||||||
| - `src/lib/git-helpers.js` | ||||||
| - `src/lib/diff-helpers.js` | ||||||
| - `src/lib/git-hook.js` | ||||||
|
|
||||||
| Keywords: doc-sync, refresh, sync, git-hook | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| You are working on **doc-sync**, the incremental skill update command (`aspens doc sync`). | ||||||
|
|
||||||
| ## Key Files | ||||||
| - `src/commands/doc-sync.js` — Main command: git diff → graph rebuild → skill mapping → Claude update → write | ||||||
| - `src/prompts/doc-sync.md` — System prompt sent to Claude (uses `{{skill-format}}` partial) | ||||||
| - `src/commands/doc-sync.js` — Main command: git diff → graph rebuild → skill mapping → Claude update → write. Also contains refresh mode and `skillToDomain()` export. | ||||||
| - `src/prompts/doc-sync.md` — System prompt for diff-based sync (uses `{{skill-format}}` partial) | ||||||
| - `src/prompts/doc-sync-refresh.md` — System prompt for `--refresh` mode (full skill review) | ||||||
| - `src/lib/git-helpers.js` — `isGitRepo()`, `getGitDiff()`, `getGitLog()`, `getChangedFiles()` — git primitives | ||||||
| - `src/lib/diff-helpers.js` — `getSelectedFilesDiff()`, `buildPrioritizedDiff()`, `truncateDiff()` — diff budgeting | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix helper name mismatch in the doc. The command imports Proposed fix-- `src/lib/diff-helpers.js` — `getSelectedFilesDiff()`, `buildPrioritizedDiff()`, `truncateDiff()` — diff budgeting
+- `src/lib/diff-helpers.js` — `getSelectedFilesDiff()`, `buildPrioritizedDiff()`, `truncate()` — diff budgeting📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| - `src/lib/git-hook.js` — `installGitHook()` / `removeGitHook()` for post-commit auto-sync | ||||||
| - `src/lib/context-builder.js` — `buildDomainContext()`, `buildBaseContext()` used by refresh mode | ||||||
| - `src/lib/runner.js` — `runClaude()`, `loadPrompt()`, `parseFileOutput()` shared across commands | ||||||
| - `src/lib/skill-writer.js` — `writeSkillFiles()` writes `{ path, content }[]` to disk | ||||||
| - `src/lib/graph-persistence.js` — `loadGraph()`, `extractSubgraph()`, `formatNavigationContext()` for graph context | ||||||
| - `src/lib/skill-writer.js` — `writeSkillFiles()`, `extractRulesFromSkills()` for output | ||||||
|
|
||||||
| ## Key Concepts | ||||||
| - **Diff-based flow:** Gets `git diff HEAD~N..HEAD` and `git log`, feeds them plus existing skill contents and graph context to Claude. | ||||||
| - **Refresh mode (`--refresh`):** Skips diff entirely. Reviews every skill against the current codebase. Base skill refreshed first, then domain skills in parallel batches of `PARALLEL_LIMIT` (3). Also refreshes CLAUDE.md and reports uncovered domains. | ||||||
| - **Graph rebuild on every sync:** Calls `buildRepoGraph` + `persistGraphArtifacts` to keep `.claude/graph.json` fresh. Graph failure is non-fatal. | ||||||
| - **Graph-aware skill mapping:** `mapChangesToSkills()` checks not just direct file matches but also whether changed files are imported by files matching a skill's activation block. | ||||||
| - **Graph-aware skill mapping:** `mapChangesToSkills()` checks direct file matches via `fileMatchesActivation()` (from `skill-reader.js`) and also whether changed files are imported by files matching a skill's activation block. | ||||||
| - **Interactive file picker:** When diff exceeds 80k chars and TTY is available, offers multiselect with skill-relevant files pre-selected. | ||||||
| - **Prioritized diff:** Skill-relevant files get 60k char budget, everything else gets 20k (80k total). Cuts at `diff --git` boundaries. | ||||||
| - **Skill mapping:** Matches changed file names and meaningful path segments against `## Activation` sections. Generic segments excluded via `GENERIC_PATH_SEGMENTS`. | ||||||
| - **Prioritized diff:** `buildPrioritizedDiff()` gives skill-relevant files 60k char budget, everything else 20k (80k total). Cuts at `diff --git` boundaries. | ||||||
| - **Token optimization:** Affected skills sent in full; non-affected skills send only path + description line. | ||||||
| - **Diff truncation:** `truncateDiff()` caps at configurable limit, cutting at the last `diff --git` boundary. CLAUDE.md capped at 5,000 chars. | ||||||
| - **Git hook:** `installGitHook()` creates a `post-commit` hook with 5-minute cooldown lock file. `removeGitHook()` removes via `>>>` / `<<<` markers. | ||||||
| - **Skill-rules regeneration:** After writing, regenerates `skill-rules.json` via `extractRulesFromSkills()` so hooks see updated activation patterns. | ||||||
| - **Git hook:** `installGitHook()` creates a `post-commit` hook with 5-minute cooldown lock file (`/tmp/aspens-sync-*.lock` keyed by repo path hash). `removeGitHook()` removes via `>>>` / `<<<` markers. | ||||||
| - **Force writes:** doc-sync always calls `writeSkillFiles` with `force: true`. | ||||||
|
|
||||||
| ## Critical Rules | ||||||
| - `runClaude` is called with `allowedTools: ['Read', 'Glob', 'Grep']` — doc-sync must never grant write tools. | ||||||
| - `parseFileOutput` restricts paths to `.claude/` prefix and `CLAUDE.md` exactly — any other path is silently dropped. | ||||||
| - `getGitDiff` gracefully falls back from N commits to 1 if fewer available. `actualCommits` tracks what was used. | ||||||
| - The command exits early with `CliError` if `.claude/skills/` doesn't exist. | ||||||
| - The hook cooldown uses `/tmp/aspens-sync-*.lock` keyed by repo path hash — don't change naming without updating cleanup. | ||||||
| - `checkMissingHooks()` in `bin/cli.js` warns when skills exist but hooks are missing (pre-0.2.2 installs). | ||||||
|
|
||||||
| ## References | ||||||
| - **Patterns:** `src/lib/skill-reader.js` — `GENERIC_PATH_SEGMENTS`, `fileMatchesActivation()`, `getActivationBlock()` | ||||||
|
|
||||||
| --- | ||||||
| **Last Updated:** 2026-03-24 | ||||||
| **Last Updated:** 2026-03-28 | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify that graph rebuild is optional.
This line reads as unconditional, but
doc-syncnow skips graph work when--no-graphis set.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents