Commit Graph

13 Commits

Author SHA1 Message Date
John Lindquist 17be9898ea Add sitemap field to SkillConfig and inject sitemap URLs alongside doc links in the docs warning block. For each skill, find the sitemap.xml URL for its primary documentation domain and add it as metadata.sitemap in SKILL.md frontmatter. Update buildDocsBlock() in patterns.mts to render sitemap URLs parenthetically after doc links. Parse and validate the new field in skill-map-frontmatter.mts, include it in the generated manifest via build-manifest.ts, and propagate the type through pretooluse and user-prompt-submit hooks. 35 of 46 skills now have sitemaps (8 skipped: domains without sitemaps). Rebuild hooks and manifest. 2026-03-10 14:29:36 -06:00
John Lindquist d5b5ef47f7 Replace skill body injection with Skill tool invocation instructions
Instead of injecting the full SKILL.md body as additionalContext, inject
"You must run the Skill(<name>) tool." — a more conventional way of
telling the agent to use the Skill tool for context loading.
2026-03-10 12:46:11 -06:00
John Lindquist 2f8111da6d feat(subagent-state): add pending launch state helpers
Add a shared hooks library for pending subagent launch records and per-agent JSON state. The module filters stale launch records, claims the oldest matching launch under a file lock, and writes agent state with atomic rename semantics.

Verified: bun test tests/subagent-state.test.ts
Verified: node --input-type=module -e "import('./hooks/subagent-state.mjs').then((mod) => { if (typeof mod.listPendingLaunches !== 'function' || typeof mod.claimPendingLaunch !== 'function' || typeof mod.appendPendingLaunch !== 'function' || typeof mod.readAgentState !== 'function' || typeof mod.writeAgentState !== 'function') { process.exit(1); } })"
Swarm-Agent: codex-subagent-state
2026-03-09 16:25:50 -06:00
John Lindquist ad5859e2c7 fix(hook-env): harden dedup temp paths
Hash invalid session IDs before constructing dedup temp paths so crafted stdin values cannot smuggle traversal segments into recursive claim cleanup. Shared temp-path resolution now verifies the resolved target stays under tmpdir, and seen-skills tests cover both stable safe IDs and hashed invalid IDs.

Verified: bun test tests/session-start-seen-skills.test.ts
How to test: bun test tests/session-start-seen-skills.test.ts
Swarm-Agent: codex-path-traversal
2026-03-09 13:39:32 -06:00
John Lindquist 08ee18d51d feat(hooks): atomic per-skill claim dedup, fix race condition and UserPromptSubmit sharing; bump to 0.6.0
Parallel PreToolUse hooks were racing on the same seen-skills file, causing 2-6x
duplicate injections. UserPromptSubmit hook didn't share dedup state at all.

Fix by implementing atomic per-skill claim files (Oracle session: fix-dedup-race-condition-plan):

1. In hooks/src/hook-env.mts, add tryClaimSessionKey(sessionId, kind, key) using
   openSync(path, 'wx') for atomic exclusive create. Add listSessionKeys() to read
   claim dir, syncSessionFileFromClaims() to derive the txt snapshot, and
   removeSessionClaimDir() for cleanup. Claim files live in
   <tmpdir>/vercel-plugin-<sessionId>-seen-skills.d/<skill-name>.

2. In hooks/src/patterns.mts, add mergeSeenSkillStates(...values) to union env var,
   session file, and claim dir state. Add serializeSeenSkills(set) helper.

3. In hooks/src/pretooluse-skill-inject.mts, load merged state from env+file+claims.
   Before injecting each skill, call tryClaimSessionKey — first process wins, others
   get EEXIST and skip. Use same claim path for once-only keys (agent-browser warning,
   vercel-env-help). Pass sessionId through InjectOptions.

4. In hooks/src/user-prompt-submit-skill-inject.mts, preserve sessionId from parsed
   input, load merged seen state, pass sessionId to injection flow so it uses the
   shared claim backend. Skills injected via promptSignals now visible to PreToolUse.

5. In hooks/src/session-end-cleanup.mts, add rmSync deletion of claim directories.

6. Update CLAUDE.md dedup contract to document atomic claim mechanism.
7. Bump .plugin/plugin.json to 0.6.0, rebuild.
2026-03-07 17:19:25 -07:00
John Lindquist cd5f369dcb Add new skills, typecheck gate, remove arg/ms/serve skills, bump to 0.4.2
- Add 8 new skills: edge-runtime, geist, micro, ncc, satori, streamdown, styled-jsx, swr
- Remove arg, ms, serve skills (standalone utilities, not relevant to shipping apps on Vercel)
- Add typecheck script and wire into `bun run test` and pre-commit hook
- Fix StdioOptions type error in session-start-profiler
- Add hook-env module and posttooluse-shadcn-font-fix hook
- Refactor skill-map-frontmatter, patterns, pretooluse-skill-inject
- Update generated catalog and manifest (42 skills)
- Add .gitignore with .DS_Store
2026-03-06 19:04:25 -07:00
John Lindquist b725f5308e refactor(hooks): switch to tsup, remove compiled/ intermediate dir
- Replace tsc+cp+rm pipeline with tsup (7ms builds, no intermediate dir)
- tsup compiles hooks/src/*.mts directly to hooks/*.mjs
- tsconfig.json retained for type-checking only (noEmit)
- Remove all .sh references from tests, docs, and hooks.json
- Fix glob pattern test to handle tsup's output format
2026-03-06 13:08:58 -07:00
John Lindquist 5a0591c292 feat(hooks): convert hooks to TypeScript with SDK type-checking
Hook source now lives in hooks/src/*.mts and compiles to hooks/*.mjs via tsc.
The formatOutput() return type is checked against SyncHookJSONOutput from
@anthropic-ai/claude-agent-sdk, preventing unknown fields in hookSpecificOutput
that Claude Code's strict Zod validation would silently reject.

Root cause: skillInjection metadata was a sibling key in hookSpecificOutput,
which Claude Code rejected as "Hook JSON output validation failed: Invalid input".
All skill injections were silently discarded. Now skillInjection metadata is
embedded as an HTML comment inside additionalContext.

- Add hooks/src/*.mts (TypeScript source for all 6 hook modules)
- Add hooks/tsconfig.json (strict, NodeNext, compiles .mts → .mjs)
- Add build:hooks script and pre-commit hook for auto-compilation
- Install @anthropic-ai/claude-agent-sdk as devDependency for types
- Bump plugin version to 0.4.0
2026-03-06 12:48:39 -07:00
John Lindquist 50c2b61ad2 chore: bump plugin version to 0.3.4
- Add greenfield project detection to session-start profiler
- Add profiler boost (+5 priority) for likely skills in PreToolUse
- Remove zzz-test-redos-pattern test skill
- Update golden fixtures and snapshots
- Add agent-browser to ecosystem graph
- Add new golden fixture tests
2026-03-06 10:36:58 -07:00
John Lindquist a5b9f7320a chore: bump plugin version to 0.3.2 2026-03-06 09:48:04 -07:00
John Lindquist 242d69f686 Extract the match/rank engine from pretooluse-skill-inject.mjs into patterns.mjs so it can be shared between the PreToolUse hook and a new CLI explain command. Add compileSkillPatterns() and rankMatches() to patterns.mjs. Refactor pretooluse-skill-inject.mjs to import and use the shared engine instead of inline matching logic.
Create hooks/vercel-config.mjs that reads vercel.json and maps top-level keys (rewrites, redirects, headers, crons, functions) to skill slugs, so skills are injected when the project uses those Vercel features.

Create hooks/logger.mjs with structured logging at four levels (off, summary, debug, trace) controlled by VERCEL_PLUGIN_LOG_LEVEL env var. Support legacy VERCEL_PLUGIN_DEBUG=1 mapping to debug level.

Create src/cli/explain.ts that takes a tool name and input JSON, runs the match engine, and prints which skills would fire and why. Create src/cli/index.ts as the CLI entry point. Create src/commands/doctor.ts for diagnosing plugin setup issues.

Create src/shared/logger.ts and src/shared/match-engine.ts as TypeScript versions of the shared utilities.

Create scripts/build-manifest.ts that reads all SKILL.md files, parses frontmatter, and generates generated/skill-manifest.json.

Add CLAUDE.md documenting the architecture, dedup contract, YAML parser quirks, test conventions, and log levels.

Add tests: tests/cli-explain.test.ts, tests/logger.test.ts, tests/vercel-config.test.ts, tests/snapshot-runner.test.ts with snapshot files in tests/snapshots/. Add test fixtures in tests/fixtures/. Update existing tests to copy new hook modules (logger.mjs, vercel-config.mjs) into temp dirs.

Update package.json with new bin entry and dependencies.
2026-03-06 06:01:17 -07:00
John Lindquist 29b0737376 fix(hooks): switch dedup from temp file to env var
The seen-skills dedup was using a temp file written via SessionStart,
but PreToolUse hooks can't update CLAUDE_ENV_FILE. This caused errors
when the temp file became stale or inaccessible across session clears.

Now VERCEL_PLUGIN_SEEN_SKILLS is a comma-delimited string stored
directly in the session environment. SessionStart initializes it as
empty, and the PreToolUse hook reads/updates process.env in-place.
2026-03-05 22:13:55 -07:00
John Lindquist f838270eac refactor(hooks): extract shared patterns module and add validation
Extract glob-to-regex and seen-skills file utilities into hooks/patterns.mjs
for reuse across the PreToolUse hook and validation script. Add
validateSkillMap to skill-map-frontmatter.mjs. Expand plugin tags for
chat-sdk/bot variants. Comprehensive tests for all new modules.
2026-03-05 20:45:14 -07:00