skillfit 0.0.0-stage → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +226 -2
- package/README.zh-CN.md +224 -0
- package/benches/README.md +172 -0
- package/benches/code-review/bench.json +57 -0
- package/benches/code-review/fixtures/explain-x1/.skillfit-mock.json +10 -0
- package/benches/code-review/fixtures/explain-x1/SPEC.md +16 -0
- package/benches/code-review/fixtures/explain-x1/src/compact.js +18 -0
- package/benches/code-review/fixtures/explain-x1/tests/compact.test.js +18 -0
- package/benches/code-review/fixtures/review-r1/.skillfit-mock.json +10 -0
- package/benches/code-review/fixtures/review-r1/CHANGES.diff +42 -0
- package/benches/code-review/fixtures/review-r1/SPEC.md +16 -0
- package/benches/code-review/fixtures/review-r1/src/errors.js +7 -0
- package/benches/code-review/fixtures/review-r1/src/money.js +3 -0
- package/benches/code-review/fixtures/review-r1/src/order.js +13 -0
- package/benches/code-review/fixtures/review-r1/tests/order.test.js +17 -0
- package/benches/code-review/fixtures/review-r2/.skillfit-mock.json +10 -0
- package/benches/code-review/fixtures/review-r2/CHANGES.diff +81 -0
- package/benches/code-review/fixtures/review-r2/SPEC.md +25 -0
- package/benches/code-review/fixtures/review-r2/src/errors.js +7 -0
- package/benches/code-review/fixtures/review-r2/src/invoice.js +9 -0
- package/benches/code-review/fixtures/review-r2/src/money.js +3 -0
- package/benches/code-review/fixtures/review-r2/tests/invoice.test.js +13 -0
- package/benches/code-review/fixtures/review-r3/.skillfit-mock.json +10 -0
- package/benches/code-review/fixtures/review-r3/CHANGES.diff +76 -0
- package/benches/code-review/fixtures/review-r3/SPEC.md +24 -0
- package/benches/code-review/fixtures/review-r3/src/errors.js +7 -0
- package/benches/code-review/fixtures/review-r3/src/money.js +3 -0
- package/benches/code-review/fixtures/review-r3/src/pricing.js +20 -0
- package/benches/code-review/fixtures/review-r3/tests/pricing.test.js +15 -0
- package/benches/code-review/fixtures/summarize-s1/.skillfit-mock.json +16 -0
- package/benches/code-review/fixtures/summarize-s1/CHANGES.diff +27 -0
- package/benches/code-review/fixtures/summarize-s1/SPEC.md +15 -0
- package/benches/code-review/fixtures/summarize-s1/src/discount.js +20 -0
- package/benches/code-review/fixtures/summarize-s1/src/errors.js +7 -0
- package/benches/code-review/fixtures/summarize-s1/src/money.js +7 -0
- package/benches/code-review/ground-truth/oracle-r1.mjs +21 -0
- package/benches/code-review/ground-truth/oracle-r2.mjs +21 -0
- package/benches/code-review/ground-truth/oracle-r3.mjs +20 -0
- package/benches/code-review/ground-truth/oracle-summarize-s1.mjs +21 -0
- package/benches/code-review/ground-truth/oracle-x1.mjs +18 -0
- package/benches/code-review/ground-truth/r1.md +22 -0
- package/benches/code-review/ground-truth/r2.md +21 -0
- package/benches/code-review/ground-truth/r3.md +18 -0
- package/benches/code-review/ground-truth/summarize-s1.md +26 -0
- package/benches/code-review/ground-truth/x1.md +7 -0
- package/benches/code-review/prompts/explain-x1.md +5 -0
- package/benches/code-review/prompts/explain-x1.trigger.md +5 -0
- package/benches/code-review/prompts/review-r1.md +7 -0
- package/benches/code-review/prompts/review-r1.trigger.md +7 -0
- package/benches/code-review/prompts/review-r2.md +7 -0
- package/benches/code-review/prompts/review-r2.trigger.md +7 -0
- package/benches/code-review/prompts/review-r3.md +7 -0
- package/benches/code-review/prompts/review-r3.trigger.md +7 -0
- package/benches/code-review/prompts/summarize-s1.md +9 -0
- package/benches/code-review/prompts/summarize-s1.trigger.md +9 -0
- package/benches/code-review/verifiers/explain-x1.mjs +30 -0
- package/benches/code-review/verifiers/review-r2.mjs +66 -0
- package/benches/code-review/verifiers/review-r3.mjs +60 -0
- package/benches/code-review/verifiers/seeded-bugs.mjs +74 -0
- package/benches/code-review/verifiers/summarize-s1.mjs +80 -0
- package/benches/contrib/README.md +42 -0
- package/benches/contrib/oss-lru-cache/README.md +24 -0
- package/benches/contrib/oss-lru-cache/bench.json +37 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/LICENSE +15 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/README.md +3 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/index.js +1044 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/package.json +11 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/runtime.mjs +22 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/test.mjs +11 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/LICENSE.md +55 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/README.md +3 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/package.json +11 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/runtime.mjs +22 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-browser.ts +11 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-cjs.cts +11 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-esm.mts +29 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-node.ts +7 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel.ts +6 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/index.ts +3148 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/perf.ts +17 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/test.mjs +11 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-size/LICENSE +15 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-size/README.md +3 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-size/index.js +1028 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-size/package.json +11 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-size/runtime.mjs +22 -0
- package/benches/contrib/oss-lru-cache/fixtures/fetch-size/test.mjs +11 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-abort/LICENSE +15 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-abort/index.js +1053 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-abort.md +11 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/LICENSE.md +55 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-browser.ts +11 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-cjs.cts +11 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-esm.mts +29 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-node.ts +7 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel.ts +6 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/index.ts +3174 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/perf.ts +17 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle.md +11 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-size/LICENSE +15 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-size/index.js +1028 -0
- package/benches/contrib/oss-lru-cache/ground-truth/fetch-size.md +11 -0
- package/benches/contrib/oss-lru-cache/ground-truth/oracle-fetch-abort.mjs +8 -0
- package/benches/contrib/oss-lru-cache/ground-truth/oracle-fetch-lifecycle.mjs +7 -0
- package/benches/contrib/oss-lru-cache/ground-truth/oracle-fetch-size.mjs +7 -0
- package/benches/contrib/oss-lru-cache/ground-truth/oracle.mjs +9 -0
- package/benches/contrib/oss-lru-cache/prompts/fetch-abort.md +5 -0
- package/benches/contrib/oss-lru-cache/prompts/fetch-lifecycle.md +5 -0
- package/benches/contrib/oss-lru-cache/prompts/fetch-size.md +5 -0
- package/benches/contrib/oss-lru-cache/provenance.json +62 -0
- package/benches/contrib/oss-lru-cache/runtime.mjs +22 -0
- package/benches/contrib/oss-lru-cache/verifiers/cases.mjs +74 -0
- package/benches/contrib/oss-lru-cache/verifiers/fetch-abort.mjs +3 -0
- package/benches/contrib/oss-lru-cache/verifiers/fetch-lifecycle.mjs +3 -0
- package/benches/contrib/oss-lru-cache/verifiers/fetch-size.mjs +3 -0
- package/benches/contrib/oss-lru-cache/verifiers/probe.mjs +14 -0
- package/benches/contrib/oss-lru-cache/verifiers/shared.mjs +130 -0
- package/benches/contrib/oss-lru-cache/verifiers/test-reporter.mjs +29 -0
- package/benches/contrib/oss-mcp-use-utf8/LICENSE.upstream +21 -0
- package/benches/contrib/oss-mcp-use-utf8/README.md +56 -0
- package/benches/contrib/oss-mcp-use-utf8/bench.json +16 -0
- package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/LICENSE +21 -0
- package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/package.json +3 -0
- package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/src/ext-apps-bridge.js +3 -0
- package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/src/resolve-view-resource.ts +96 -0
- package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/test/basic.test.mjs +13 -0
- package/benches/contrib/oss-mcp-use-utf8/ground-truth/README.md +5 -0
- package/benches/contrib/oss-mcp-use-utf8/ground-truth/oracle-view-utf8.mjs +11 -0
- package/benches/contrib/oss-mcp-use-utf8/ground-truth/solutions/view-utf8/src/resolve-view-resource.ts +96 -0
- package/benches/contrib/oss-mcp-use-utf8/ground-truth/solutions/view-utf8/test/utf8.regression.test.mjs +14 -0
- package/benches/contrib/oss-mcp-use-utf8/prompts/view-utf8.md +8 -0
- package/benches/contrib/oss-mcp-use-utf8/verifiers/view-utf8.mjs +120 -0
- package/benches/contrib/waza-behavior/LICENSE.upstream +21 -0
- package/benches/contrib/waza-behavior/README.md +31 -0
- package/benches/contrib/waza-behavior/bench.json +10 -0
- package/benches/contrib/waza-behavior/fixtures/explicit-hold/README.md +1 -0
- package/benches/contrib/waza-behavior/fixtures/explicit-hold/notes.txt +1 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-current/README.md +1 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-current/docs/guide.md +2 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-current/notes.txt +1 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-current/scripts/check-links.mjs +16 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-current/validation-receipt.json +10 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-stale/README.md +1 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-stale/docs/guide.md +3 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-stale/notes.txt +1 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-stale/scripts/check-links.mjs +16 -0
- package/benches/contrib/waza-behavior/fixtures/receipt-stale/validation-receipt.json +10 -0
- package/benches/contrib/waza-behavior/ground-truth/oracle.mjs +24 -0
- package/benches/contrib/waza-behavior/prompts/explicit-hold.md +1 -0
- package/benches/contrib/waza-behavior/prompts/receipt-current.md +1 -0
- package/benches/contrib/waza-behavior/prompts/receipt-stale.md +1 -0
- package/benches/contrib/waza-behavior/verifiers/behavior.mjs +59 -0
- package/benches/debugging/bench.json +93 -0
- package/benches/debugging/fixtures/async-queue/src/task-queue.mjs +50 -0
- package/benches/debugging/fixtures/async-queue/test/basic.test.mjs +18 -0
- package/benches/debugging/fixtures/chunked-decoder/src/frame-decoder.mjs +39 -0
- package/benches/debugging/fixtures/chunked-decoder/test/basic.test.mjs +17 -0
- package/benches/debugging/fixtures/debug-redaction/src/debug-redaction.mjs +33 -0
- package/benches/debugging/fixtures/debug-redaction/test/basic.test.mjs +26 -0
- package/benches/debugging/fixtures/document-queue/.skillfit-mock.json +16 -0
- package/benches/debugging/fixtures/document-queue/src/task-queue.mjs +52 -0
- package/benches/debugging/fixtures/document-queue/test/basic.test.mjs +23 -0
- package/benches/debugging/fixtures/explain-cache/.skillfit-mock.json +16 -0
- package/benches/debugging/fixtures/explain-cache/src/ttl-cache.mjs +31 -0
- package/benches/debugging/fixtures/explain-cache/test/basic.test.mjs +28 -0
- package/benches/debugging/fixtures/feat-slug/test/slug.test.mjs +15 -0
- package/benches/debugging/fixtures/range-parser/src/range-parser.mjs +9 -0
- package/benches/debugging/fixtures/range-parser/test/basic.test.mjs +8 -0
- package/benches/debugging/fixtures/ttl-cache/src/ttl-cache.mjs +30 -0
- package/benches/debugging/fixtures/ttl-cache/test/basic.test.mjs +11 -0
- package/benches/debugging/ground-truth/async-queue.md +81 -0
- package/benches/debugging/ground-truth/chunked-decoder.md +91 -0
- package/benches/debugging/ground-truth/debug-redaction.md +113 -0
- package/benches/debugging/ground-truth/document-queue.md +24 -0
- package/benches/debugging/ground-truth/explain-cache.md +22 -0
- package/benches/debugging/ground-truth/feat-slug.md +45 -0
- package/benches/debugging/ground-truth/oracle-async-queue.mjs +14 -0
- package/benches/debugging/ground-truth/oracle-chunked-decoder.mjs +14 -0
- package/benches/debugging/ground-truth/oracle-debug-redaction.mjs +30 -0
- package/benches/debugging/ground-truth/oracle-document-queue.mjs +27 -0
- package/benches/debugging/ground-truth/oracle-explain-cache.mjs +28 -0
- package/benches/debugging/ground-truth/oracle-feat-slug.mjs +13 -0
- package/benches/debugging/ground-truth/oracle-range-parser.mjs +14 -0
- package/benches/debugging/ground-truth/oracle-ttl-cache.mjs +14 -0
- package/benches/debugging/ground-truth/range-parser.md +121 -0
- package/benches/debugging/ground-truth/solutions/async-queue/src/task-queue.mjs +52 -0
- package/benches/debugging/ground-truth/solutions/chunked-decoder/src/frame-decoder.mjs +50 -0
- package/benches/debugging/ground-truth/solutions/debug-redaction/src/debug-redaction.mjs +27 -0
- package/benches/debugging/ground-truth/solutions/debug-redaction/test/debug-leak.regression.test.mjs +27 -0
- package/benches/debugging/ground-truth/solutions/feat-slug/src/slug.mjs +6 -0
- package/benches/debugging/ground-truth/solutions/range-parser/src/range-parser.mjs +34 -0
- package/benches/debugging/ground-truth/solutions/range-parser/test/basic.test.mjs +26 -0
- package/benches/debugging/ground-truth/solutions/ttl-cache/src/ttl-cache.mjs +31 -0
- package/benches/debugging/ground-truth/ttl-cache.md +69 -0
- package/benches/debugging/prompts/async-queue.md +13 -0
- package/benches/debugging/prompts/async-queue.trigger.md +13 -0
- package/benches/debugging/prompts/chunked-decoder.md +13 -0
- package/benches/debugging/prompts/chunked-decoder.trigger.md +13 -0
- package/benches/debugging/prompts/debug-redaction.md +23 -0
- package/benches/debugging/prompts/debug-redaction.trigger.md +23 -0
- package/benches/debugging/prompts/document-queue.md +10 -0
- package/benches/debugging/prompts/document-queue.trigger.md +10 -0
- package/benches/debugging/prompts/explain-cache.md +10 -0
- package/benches/debugging/prompts/explain-cache.trigger.md +10 -0
- package/benches/debugging/prompts/feat-slug.md +3 -0
- package/benches/debugging/prompts/feat-slug.trigger.md +5 -0
- package/benches/debugging/prompts/range-parser.md +15 -0
- package/benches/debugging/prompts/range-parser.trigger.md +15 -0
- package/benches/debugging/prompts/ttl-cache.md +18 -0
- package/benches/debugging/prompts/ttl-cache.trigger.md +18 -0
- package/benches/debugging/verifiers/async-queue.mjs +221 -0
- package/benches/debugging/verifiers/chunked-decoder.mjs +208 -0
- package/benches/debugging/verifiers/debug-redaction.mjs +283 -0
- package/benches/debugging/verifiers/document-queue.mjs +52 -0
- package/benches/debugging/verifiers/explain-cache.mjs +62 -0
- package/benches/debugging/verifiers/feat-slug.mjs +127 -0
- package/benches/debugging/verifiers/range-parser.mjs +146 -0
- package/benches/debugging/verifiers/ttl-cache.mjs +111 -0
- package/dist/agents.js +26 -0
- package/dist/cli.js +310 -0
- package/dist/cli.test.js +76 -0
- package/dist/commands/bench.js +1035 -0
- package/dist/commands/bench.test.js +1061 -0
- package/dist/commands/bundle.js +334 -0
- package/dist/commands/bundle.test.js +142 -0
- package/dist/commands/confirm.js +39 -0
- package/dist/commands/doctor.js +399 -0
- package/dist/commands/doctor.test.js +280 -0
- package/dist/commands/eval-report.js +485 -0
- package/dist/commands/eval-report.test.js +306 -0
- package/dist/commands/eval.js +391 -0
- package/dist/commands/eval.test.js +446 -0
- package/dist/commands/install.js +653 -0
- package/dist/commands/install.test.js +555 -0
- package/dist/commands/mcp.js +20 -0
- package/dist/commands/report.js +78 -0
- package/dist/commands/report.test.js +110 -0
- package/dist/commands/setup.js +95 -0
- package/dist/commands/setup.test.js +150 -0
- package/dist/commands/upstream.js +210 -0
- package/dist/commands/upstream.test.js +139 -0
- package/dist/docs.test.js +154 -0
- package/dist/frontmatter.js +53 -0
- package/dist/frontmatter.test.js +49 -0
- package/dist/harness/bench.js +134 -0
- package/dist/harness/bench.test.js +109 -0
- package/dist/harness/bundle.js +46 -0
- package/dist/harness/bundle.test.js +71 -0
- package/dist/harness/constants.js +2 -0
- package/dist/harness/executors/api.js +68 -0
- package/dist/harness/executors/api.test.js +75 -0
- package/dist/harness/executors/cli.js +348 -0
- package/dist/harness/executors/cli.test.js +402 -0
- package/dist/harness/executors/mock.js +34 -0
- package/dist/harness/executors/mock.test.js +43 -0
- package/dist/harness/experiment-session.js +345 -0
- package/dist/harness/experiment-session.test.js +223 -0
- package/dist/harness/hash.js +29 -0
- package/dist/harness/installed-skill.js +78 -0
- package/dist/harness/installed-skill.test.js +162 -0
- package/dist/harness/judge.js +108 -0
- package/dist/harness/judge.test.js +181 -0
- package/dist/harness/kill-tree.js +43 -0
- package/dist/harness/kimi-usage.js +94 -0
- package/dist/harness/kimi-usage.test.js +62 -0
- package/dist/harness/oss-lru-cache.test.js +79 -0
- package/dist/harness/oss-regression-witness.test.js +89 -0
- package/dist/harness/prompt.js +57 -0
- package/dist/harness/prompt.test.js +48 -0
- package/dist/harness/receipts.js +297 -0
- package/dist/harness/receipts.test.js +148 -0
- package/dist/harness/report.js +225 -0
- package/dist/harness/report.test.js +297 -0
- package/dist/harness/runner.js +629 -0
- package/dist/harness/runner.test.js +555 -0
- package/dist/harness/stats.js +93 -0
- package/dist/harness/stats.test.js +124 -0
- package/dist/harness/target.js +90 -0
- package/dist/harness/target.test.js +60 -0
- package/dist/harness/trigger.js +368 -0
- package/dist/harness/trigger.test.js +249 -0
- package/dist/harness/types.js +1 -0
- package/dist/harness/verifier-summary.js +59 -0
- package/dist/harness/verifier-summary.test.js +99 -0
- package/dist/harness/waza-behavior.test.js +139 -0
- package/dist/invocation.js +21 -0
- package/dist/matrix/agents.json +200 -0
- package/dist/matrix/agents.schema.json +152 -0
- package/dist/mcp/probe.js +317 -0
- package/dist/mcp/probe.test.js +87 -0
- package/dist/version.js +4 -0
- package/docs/assets/skillfit-flow.en.svg +47 -0
- package/docs/assets/skillfit-flow.zh-CN.svg +47 -0
- package/docs/assets/skillfit-mark.svg +9 -0
- package/docs/audit-2026-09-24-triage.md +231 -0
- package/docs/audit-2026-09-24.md +876 -0
- package/docs/bench-authoring.md +407 -0
- package/docs/codex-upstream-audit.md +41 -0
- package/docs/config-experiments.md +119 -0
- package/docs/examples/bench-check.yml +32 -0
- package/docs/examples/eval-manifest.synthetic.json +61 -0
- package/docs/experiment-workflow.md +15 -0
- package/docs/first-real-eval.md +90 -0
- package/docs/growth-roadmap-2026-10.md +100 -0
- package/docs/installed-skill-evaluation.md +77 -0
- package/docs/metrics.md +318 -0
- package/docs/oss-task-evaluation.md +139 -0
- package/docs/plans/2026-10-01-oss-task-evaluation.md +73 -0
- package/docs/plans/2026-10-09-experiment-workflow.md +18 -0
- package/docs/plans/2026-10-09-grader-calibration-audit.md +13 -0
- package/docs/plans/2026-10-09-waza-resource-evaluation.md +46 -0
- package/docs/portable-codex.md +31 -0
- package/docs/reproducible-offline-example.md +29 -0
- package/docs/selectable-codex.md +41 -0
- package/docs/sharing-results.md +53 -0
- package/evidence/2026-07-skill-baseline.md +34 -0
- package/evidence/2026-09-22-codex-trigger-capture.md +36 -0
- package/evidence/2026-09-bench-calibration.md +46 -0
- package/evidence/2026-09-debugging-bench-exploratory.md +55 -0
- package/evidence/2026-09-debugging-hardening.md +42 -0
- package/evidence/2026-09-ocr-vs-code-review.md +31 -0
- package/evidence/2026-09-trigger-snapshot-correction.md +48 -0
- package/evidence/2026-10-01-codex-diagnosing-bugs-pilot.md +58 -0
- package/evidence/2026-10-01-oss-case-selection.md +42 -0
- package/evidence/2026-10-01-oss-workspace-smoke.md +110 -0
- package/evidence/README.md +47 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/README.md +27 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/artifact-index.json +118 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/output.md +5 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/prompt.txt +14 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/result.json +65 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/verifier.txt +2 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/LICENSE +21 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/package.json +3 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/src/ext-apps-bridge.js +3 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/src/resolve-view-resource.ts +100 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/test/basic.test.mjs +13 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/test/resolve-view-resource.test.mjs +102 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/manifest.json +206 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/original-console.txt +44 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/report.md +67 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/output.md +5 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/prompt.txt +163 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/result.json +65 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/verifier.txt +2 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/LICENSE +21 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/package.json +3 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/src/ext-apps-bridge.js +3 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/src/resolve-view-resource.ts +100 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/test/basic.test.mjs +13 -0
- package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/test/resolve-view-resource.test.mjs +136 -0
- package/evidence/inputs/README.md +15 -0
- package/evidence/inputs/diagnosing-bugs/LICENSE +21 -0
- package/evidence/inputs/diagnosing-bugs/SKILL.md +138 -0
- package/evidence/inputs/diagnosing-bugs/agents/openai.yaml +3 -0
- package/evidence/inputs/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/evidence/plans/2026-10-01-oss-workspace-smoke.json +29 -0
- package/package.json +47 -4
- package/profiles/codex-curated/catalog.json +28 -0
- package/profiles/codex-curated/profile.json +282 -0
- package/profiles/codex-curated/rules/global.md +12 -0
- package/profiles/codex-curated/skills/autonomous-iteration/SKILL.md +75 -0
- package/profiles/codex-curated/skills/autonomous-iteration/agents/openai.yaml +4 -0
- package/profiles/codex-curated/skills/vibe-coding/SKILL.md +45 -0
- package/profiles/codex-curated/skills/vibe-coding/agents/openai.yaml +4 -0
- package/profiles/codex-upstream-sources.json +2980 -0
- package/profiles/recommended/profile.json +12 -0
- package/profiles/recommended/rules/core-workflow.md +41 -0
- package/profiles/recommended/skills/commit-message/SKILL.md +18 -0
- package/skills/skillfit/SKILL.md +60 -0
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { promises as fs } from 'node:fs';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { getAgent } from '../agents.js';
|
|
8
|
+
import { parseFrontmatter } from '../frontmatter.js';
|
|
9
|
+
import { confirm as confirmPrompt } from './confirm.js';
|
|
10
|
+
export const MARKER_START = '<!-- SKILLFIT_START -->';
|
|
11
|
+
export const MARKER_END = '<!-- SKILLFIT_END -->';
|
|
12
|
+
export const BACKUP_SUFFIX = '.skillfit-bak';
|
|
13
|
+
export const LOCKFILE_NAME = 'skillfit.lock.json';
|
|
14
|
+
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
15
|
+
export async function runInstall(opts) {
|
|
16
|
+
const log = opts.log ?? ((line) => console.log(line));
|
|
17
|
+
const homeDir = opts.homeDir ?? os.homedir();
|
|
18
|
+
const projectDir = opts.projectDir ?? process.cwd();
|
|
19
|
+
const profilesDir = opts.profilesDir ?? fileURLToPath(new URL('../../profiles/', import.meta.url));
|
|
20
|
+
const env = opts.env ?? process.env;
|
|
21
|
+
const now = opts.now ?? (() => new Date());
|
|
22
|
+
const scope = opts.project ? 'project' : 'user';
|
|
23
|
+
const scopeDir = opts.project ? projectDir : homeDir;
|
|
24
|
+
const selectedProfileDir = opts.profilePath ? path.resolve(opts.profilePath) : null;
|
|
25
|
+
const { dir: profileDir, manifest } = selectedProfileDir
|
|
26
|
+
? await loadProfile(path.dirname(selectedProfileDir), path.basename(selectedProfileDir))
|
|
27
|
+
: await loadProfile(profilesDir, opts.profile);
|
|
28
|
+
if (manifest.scope !== undefined && manifest.scope !== scope) {
|
|
29
|
+
throw new Error(`Profile "${manifest.name}" requires ${manifest.scope} scope`);
|
|
30
|
+
}
|
|
31
|
+
const agents = selectAgents(manifest, opts.agent, homeDir, env);
|
|
32
|
+
const lockPath = path.join(scopeDir, LOCKFILE_NAME);
|
|
33
|
+
const lock = await readLockfile(lockPath);
|
|
34
|
+
const items = [];
|
|
35
|
+
for (const agent of agents) {
|
|
36
|
+
items.push(...await planRulesItems(agent, manifest, profileDir, scope, homeDir, projectDir, env));
|
|
37
|
+
for (const skill of manifest.skills ?? []) {
|
|
38
|
+
items.push(await planSkillItem(agent, skill, profileDir, scope, homeDir, projectDir, lock));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
printPlan(log, manifest, scope, scopeDir, items);
|
|
42
|
+
const conflicts = items.filter((i) => i.action === 'conflict');
|
|
43
|
+
if (conflicts.length > 0) {
|
|
44
|
+
// A dry run is a question, not an attempt: it reports what would block an install and exits 0, so
|
|
45
|
+
// a human reading the plan is not handed a failure code for asking. CI that wants conflicts to
|
|
46
|
+
// fail passes --strict. A real run always throws, since it cannot proceed.
|
|
47
|
+
if (opts.dryRun && !opts.strict) {
|
|
48
|
+
log('');
|
|
49
|
+
log(`${conflicts.length} conflict(s) would block this install. Resolve the files listed above, then re-run. ` +
|
|
50
|
+
'(Dry run reports conflicts and exits 0; pass --strict to make them fail.)');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`${conflicts.length} conflict(s) found. Keep or remove the listed files manually and re-run. Nothing was written.`);
|
|
54
|
+
}
|
|
55
|
+
const writes = items.filter((i) => i.action === 'create' || i.action === 'update');
|
|
56
|
+
if (writes.length === 0) {
|
|
57
|
+
log('Everything is up to date; nothing to do.');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (opts.dryRun) {
|
|
61
|
+
log('Dry run: nothing was written. Re-run with --yes to apply.');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!opts.yes) {
|
|
65
|
+
const confirm = opts.confirm ?? confirmPrompt;
|
|
66
|
+
const ok = await confirm(`Apply ${writes.length} change(s)? [y/N] `);
|
|
67
|
+
if (!ok) {
|
|
68
|
+
log('Aborted; nothing was written.');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
recordEntries(lock, items, manifest, now().toISOString());
|
|
73
|
+
const lockContent = `${JSON.stringify(lock, null, 2)}\n`;
|
|
74
|
+
await executeWrites(writes, lockPath, lockContent, async () => {
|
|
75
|
+
const problems = await validateWrites(writes);
|
|
76
|
+
if (problems.length > 0) {
|
|
77
|
+
throw new Error(`Post-install validation failed:\n ${problems.join('\n ')}`);
|
|
78
|
+
}
|
|
79
|
+
if (await fs.readFile(lockPath, 'utf8') !== lockContent) {
|
|
80
|
+
throw new Error(`Post-install validation failed: lockfile content differs from the plan at ${lockPath}`);
|
|
81
|
+
}
|
|
82
|
+
}, log);
|
|
83
|
+
log(`Post-install validation passed (${writes.length} item(s) checked).`);
|
|
84
|
+
log(`Lockfile updated: ${lockPath}`);
|
|
85
|
+
log('Install complete.');
|
|
86
|
+
}
|
|
87
|
+
export async function loadProfile(profilesDir, name) {
|
|
88
|
+
if (!NAME_PATTERN.test(name)) {
|
|
89
|
+
throw new Error(`Invalid profile name "${name}". Use lowercase letters, digits and dashes.`);
|
|
90
|
+
}
|
|
91
|
+
const dir = path.join(profilesDir, name);
|
|
92
|
+
let raw;
|
|
93
|
+
try {
|
|
94
|
+
raw = await readProfileFile(dir, 'profile.json');
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error.code !== 'ENOENT')
|
|
98
|
+
throw error;
|
|
99
|
+
throw new Error(`Profile "${name}" not found at ${dir}`);
|
|
100
|
+
}
|
|
101
|
+
const manifest = JSON.parse(raw);
|
|
102
|
+
validateManifest(manifest, name);
|
|
103
|
+
await validateProfileFiles(dir, manifest);
|
|
104
|
+
return { dir, manifest };
|
|
105
|
+
}
|
|
106
|
+
function validateManifest(manifest, expectedName) {
|
|
107
|
+
if (typeof manifest !== 'object' || manifest === null) {
|
|
108
|
+
throw new Error('profile.json must be an object');
|
|
109
|
+
}
|
|
110
|
+
if (manifest.name !== expectedName) {
|
|
111
|
+
throw new Error(`profile.json name "${manifest.name}" does not match directory "${expectedName}"`);
|
|
112
|
+
}
|
|
113
|
+
if (typeof manifest.version !== 'string' || manifest.version.length === 0) {
|
|
114
|
+
throw new Error('profile.json must declare a version string');
|
|
115
|
+
}
|
|
116
|
+
if (manifest.scope !== undefined && manifest.scope !== 'user' && manifest.scope !== 'project') {
|
|
117
|
+
throw new Error('profile.json scope must be user or project');
|
|
118
|
+
}
|
|
119
|
+
if (!Array.isArray(manifest.agents) || manifest.agents.length === 0) {
|
|
120
|
+
throw new Error('profile.json must list at least one target agent');
|
|
121
|
+
}
|
|
122
|
+
if (new Set(manifest.agents).size !== manifest.agents.length) {
|
|
123
|
+
throw new Error('profile.json lists duplicate agents');
|
|
124
|
+
}
|
|
125
|
+
for (const id of manifest.agents)
|
|
126
|
+
getAgent(id);
|
|
127
|
+
if (manifest.rules !== undefined && (typeof manifest.rules !== 'object' || manifest.rules === null || typeof manifest.rules.template !== 'string')) {
|
|
128
|
+
throw new Error('profile.json rules.template must be a relative path');
|
|
129
|
+
}
|
|
130
|
+
if (manifest.skills !== undefined && !Array.isArray(manifest.skills)) {
|
|
131
|
+
throw new Error('profile.json skills must be an array');
|
|
132
|
+
}
|
|
133
|
+
const skillNames = new Set();
|
|
134
|
+
for (const skill of manifest.skills ?? []) {
|
|
135
|
+
if (typeof skill !== 'object' || skill === null)
|
|
136
|
+
throw new Error('profile.json skills must contain objects');
|
|
137
|
+
if (!NAME_PATTERN.test(skill.name))
|
|
138
|
+
throw new Error(`Invalid skill name "${skill.name}" in profile.json`);
|
|
139
|
+
if (skillNames.has(skill.name))
|
|
140
|
+
throw new Error(`Duplicate skill "${skill.name}" in profile.json`);
|
|
141
|
+
skillNames.add(skill.name);
|
|
142
|
+
if (typeof skill.source !== 'string')
|
|
143
|
+
throw new Error(`Skill "${skill.name}" must declare a source path`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function validateProfileFiles(dir, manifest) {
|
|
147
|
+
if (manifest.rules)
|
|
148
|
+
await readProfileFile(dir, manifest.rules.template);
|
|
149
|
+
for (const skill of manifest.skills ?? []) {
|
|
150
|
+
const skillMd = await readProfileFile(dir, `${skill.source}/SKILL.md`).catch((error) => {
|
|
151
|
+
if (error.code !== 'ENOENT')
|
|
152
|
+
throw error;
|
|
153
|
+
throw new Error(`Skill "${skill.name}" is missing SKILL.md at ${skill.source}`);
|
|
154
|
+
});
|
|
155
|
+
const fm = parseFrontmatter(skillMd);
|
|
156
|
+
if (!fm?.name || !fm.description) {
|
|
157
|
+
throw new Error(`Skill "${skill.name}" SKILL.md must have name and description frontmatter`);
|
|
158
|
+
}
|
|
159
|
+
if (fm.name !== skill.name) {
|
|
160
|
+
throw new Error(`Skill "${skill.name}" SKILL.md declares name "${fm.name}"`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function readProfileFile(dir, rel) {
|
|
165
|
+
return await fs.readFile(await safeProfileFile(dir, rel), 'utf8');
|
|
166
|
+
}
|
|
167
|
+
function safeJoin(base, rel) {
|
|
168
|
+
const abs = path.resolve(base, rel);
|
|
169
|
+
if (abs !== base && !abs.startsWith(base + path.sep)) {
|
|
170
|
+
throw new Error(`Profile path "${rel}" escapes the profile directory`);
|
|
171
|
+
}
|
|
172
|
+
return abs;
|
|
173
|
+
}
|
|
174
|
+
async function safeProfileFile(base, rel) {
|
|
175
|
+
const target = safeJoin(base, rel);
|
|
176
|
+
let current = base;
|
|
177
|
+
for (const component of path.relative(base, target).split(path.sep)) {
|
|
178
|
+
current = path.join(current, component);
|
|
179
|
+
if ((await fs.lstat(current)).isSymbolicLink()) {
|
|
180
|
+
throw new Error(`Profile path "${rel}" contains a symlink: ${current}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return target;
|
|
184
|
+
}
|
|
185
|
+
export function renderManagedBlock(body, profile, version) {
|
|
186
|
+
return [
|
|
187
|
+
MARKER_START,
|
|
188
|
+
`Managed by skillfit (profile: ${profile} v${version}). Edit outside these markers; the block is rewritten on install.`,
|
|
189
|
+
'',
|
|
190
|
+
body.trim(),
|
|
191
|
+
'',
|
|
192
|
+
MARKER_END,
|
|
193
|
+
].join('\n');
|
|
194
|
+
}
|
|
195
|
+
export function upsertManagedBlock(existing, block) {
|
|
196
|
+
if (existing === null || existing.trim().length === 0)
|
|
197
|
+
return `${block}\n`;
|
|
198
|
+
const starts = indicesOf(existing, MARKER_START);
|
|
199
|
+
const ends = indicesOf(existing, MARKER_END);
|
|
200
|
+
if (starts.length === 0 && ends.length === 0) {
|
|
201
|
+
const glue = existing.endsWith('\n') ? '' : '\n';
|
|
202
|
+
return `${existing}${glue}\n${block}\n`;
|
|
203
|
+
}
|
|
204
|
+
const start = starts[0];
|
|
205
|
+
const end = ends[0];
|
|
206
|
+
if (starts.length !== 1 || ends.length !== 1 || start === undefined || end === undefined || end < start) {
|
|
207
|
+
throw new Error(`Malformed skillfit markers; expected exactly one ${MARKER_START} followed by one ${MARKER_END}`);
|
|
208
|
+
}
|
|
209
|
+
return `${existing.slice(0, start)}${block}${existing.slice(end + MARKER_END.length)}`;
|
|
210
|
+
}
|
|
211
|
+
function indicesOf(haystack, needle) {
|
|
212
|
+
const out = [];
|
|
213
|
+
let i = haystack.indexOf(needle);
|
|
214
|
+
while (i !== -1) {
|
|
215
|
+
out.push(i);
|
|
216
|
+
i = haystack.indexOf(needle, i + needle.length);
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
function extractBlock(content, targetPath) {
|
|
221
|
+
const starts = indicesOf(content, MARKER_START);
|
|
222
|
+
const ends = indicesOf(content, MARKER_END);
|
|
223
|
+
if (starts.length === 0 && ends.length === 0)
|
|
224
|
+
return null;
|
|
225
|
+
const start = starts[0];
|
|
226
|
+
const end = ends[0];
|
|
227
|
+
if (starts.length !== 1 || ends.length !== 1 || start === undefined || end === undefined || end < start) {
|
|
228
|
+
throw new Error(`${targetPath}: malformed skillfit markers; fix or remove them manually`);
|
|
229
|
+
}
|
|
230
|
+
return content.slice(start, end + MARKER_END.length);
|
|
231
|
+
}
|
|
232
|
+
function classifyBlock(existing, block, targetPath) {
|
|
233
|
+
if (existing === null)
|
|
234
|
+
return { action: 'create', detail: `create file with managed block (${lineCount(block)} lines)` };
|
|
235
|
+
const current = extractBlock(existing, targetPath);
|
|
236
|
+
if (current === null)
|
|
237
|
+
return { action: 'update', detail: `append managed block (${lineCount(block)} lines)` };
|
|
238
|
+
if (current === block)
|
|
239
|
+
return { action: 'skip', detail: 'unchanged' };
|
|
240
|
+
return { action: 'update', detail: `rewrite managed block (${lineCount(current)} -> ${lineCount(block)} lines)` };
|
|
241
|
+
}
|
|
242
|
+
function lineCount(s) {
|
|
243
|
+
return s.split('\n').length;
|
|
244
|
+
}
|
|
245
|
+
function selectAgents(manifest, agentId, homeDir, env) {
|
|
246
|
+
if (agentId) {
|
|
247
|
+
const agent = getAgent(agentId);
|
|
248
|
+
if (!manifest.agents.includes(agent.id)) {
|
|
249
|
+
throw new Error(`Profile "${manifest.name}" does not target ${agent.displayName} (targets: ${manifest.agents.join(', ')})`);
|
|
250
|
+
}
|
|
251
|
+
return [agent];
|
|
252
|
+
}
|
|
253
|
+
const candidates = manifest.agents.map((id) => getAgent(id));
|
|
254
|
+
const detected = candidates.filter((a) => isAgentDetected(a, homeDir, env));
|
|
255
|
+
if (detected.length === 0) {
|
|
256
|
+
throw new Error(`No target agents detected (${candidates.map((a) => a.id).join(', ')}). Re-run with --agent <id> to install anyway.`);
|
|
257
|
+
}
|
|
258
|
+
return detected;
|
|
259
|
+
}
|
|
260
|
+
function isAgentDetected(agent, homeDir, env) {
|
|
261
|
+
const markers = [...agent.detect.userDirs, ...agent.detect.userFiles];
|
|
262
|
+
if (markers.some((p) => existsSync(expandHome(p, homeDir))))
|
|
263
|
+
return true;
|
|
264
|
+
return agent.detect.binaries.some((bin) => binaryOnPath(bin, env));
|
|
265
|
+
}
|
|
266
|
+
function expandHome(p, homeDir) {
|
|
267
|
+
if (p === '~')
|
|
268
|
+
return homeDir;
|
|
269
|
+
if (p.startsWith('~/'))
|
|
270
|
+
return path.join(homeDir, p.slice(2));
|
|
271
|
+
return p;
|
|
272
|
+
}
|
|
273
|
+
function binaryOnPath(name, env) {
|
|
274
|
+
const dirs = (env.PATH ?? '').split(path.delimiter).filter((d) => d.length > 0);
|
|
275
|
+
const exts = process.platform === 'win32'
|
|
276
|
+
? ['', ...(env.PATHEXT ?? '.EXE;.CMD;.BAT;.PS1').split(';')]
|
|
277
|
+
: [''];
|
|
278
|
+
return dirs.some((dir) => exts.some((ext) => existsSync(path.join(dir, name + ext))));
|
|
279
|
+
}
|
|
280
|
+
function resolveScoped(rel, scope, homeDir, projectDir) {
|
|
281
|
+
if (rel === '~' || rel.startsWith('~/'))
|
|
282
|
+
return expandHome(rel, homeDir);
|
|
283
|
+
return path.resolve(projectDir, rel);
|
|
284
|
+
}
|
|
285
|
+
function rulesTarget(agent, scope, homeDir, projectDir, env) {
|
|
286
|
+
const rel = scope === 'user' ? agent.rules.userFiles[0] : agent.rules.projectFiles[0];
|
|
287
|
+
if (!rel)
|
|
288
|
+
throw new Error(`${agent.displayName} has no ${scope}-level rules file in the matrix`);
|
|
289
|
+
const override = scope === 'user' ? agent.rules.userHomeOverride : undefined;
|
|
290
|
+
const envHome = override === undefined ? undefined : env[override.env];
|
|
291
|
+
const nativeFile = override !== undefined && envHome
|
|
292
|
+
? path.resolve(envHome, override.relativePath)
|
|
293
|
+
: resolveScoped(rel, scope, homeDir, projectDir);
|
|
294
|
+
const bridge = agent.rules.agentsMdBridge;
|
|
295
|
+
if (agent.rules.readsAgentsMd || bridge === null)
|
|
296
|
+
return { rulesFile: nativeFile, bridgeFile: null, importLine: null };
|
|
297
|
+
return {
|
|
298
|
+
rulesFile: path.join(path.dirname(nativeFile), bridge.fileName),
|
|
299
|
+
bridgeFile: nativeFile,
|
|
300
|
+
importLine: bridge.importLine,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function skillsTargetDir(agent, scope, homeDir, projectDir) {
|
|
304
|
+
const shared = agent.skills.sharedDirs.find((dir) => (scope === 'user' ? dir.startsWith('~/') : !dir.startsWith('~')));
|
|
305
|
+
if (shared)
|
|
306
|
+
return resolveScoped(shared, scope, homeDir, projectDir);
|
|
307
|
+
const rel = scope === 'user' ? agent.skills.userDirs[0] : agent.skills.projectDirs[0];
|
|
308
|
+
if (!rel)
|
|
309
|
+
throw new Error(`${agent.displayName} has no ${scope}-level skills directory in the matrix`);
|
|
310
|
+
return resolveScoped(rel, scope, homeDir, projectDir);
|
|
311
|
+
}
|
|
312
|
+
async function readIfExists(p) {
|
|
313
|
+
try {
|
|
314
|
+
return await fs.readFile(p, 'utf8');
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
if (error.code === 'ENOENT')
|
|
318
|
+
return null;
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async function readBufferIfExists(p) {
|
|
323
|
+
try {
|
|
324
|
+
return await fs.readFile(p);
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
if (error.code === 'ENOENT')
|
|
328
|
+
return null;
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
async function readLockfile(lockPath) {
|
|
333
|
+
const raw = await readIfExists(lockPath);
|
|
334
|
+
if (raw === null)
|
|
335
|
+
return { version: 1, entries: {} };
|
|
336
|
+
let parsed;
|
|
337
|
+
try {
|
|
338
|
+
parsed = JSON.parse(raw);
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
throw new Error(`Lockfile at ${lockPath} is not valid JSON; fix or delete it.`);
|
|
342
|
+
}
|
|
343
|
+
if (typeof parsed !== 'object' || parsed === null || typeof parsed.entries !== 'object') {
|
|
344
|
+
throw new Error(`Lockfile at ${lockPath} has an unexpected shape; fix or delete it.`);
|
|
345
|
+
}
|
|
346
|
+
return { version: 1, entries: parsed.entries ?? {} };
|
|
347
|
+
}
|
|
348
|
+
async function planRulesItems(agent, manifest, profileDir, scope, homeDir, projectDir, env) {
|
|
349
|
+
if (!manifest.rules)
|
|
350
|
+
return [];
|
|
351
|
+
const template = await readProfileFile(profileDir, manifest.rules.template);
|
|
352
|
+
const { rulesFile, bridgeFile, importLine } = rulesTarget(agent, scope, homeDir, projectDir, env);
|
|
353
|
+
const block = renderManagedBlock(template, manifest.name, manifest.version);
|
|
354
|
+
const overrideName = scope === 'user' ? agent.rules.userHomeOverride?.overrideRelativePath : undefined;
|
|
355
|
+
if (overrideName) {
|
|
356
|
+
const overridePath = path.join(path.dirname(rulesFile), overrideName);
|
|
357
|
+
const overrideContent = await readIfExists(overridePath);
|
|
358
|
+
if (overrideContent !== null && overrideContent.trim().length > 0) {
|
|
359
|
+
return [{
|
|
360
|
+
agent: agent.id, kind: 'rules', label: 'rules', targetPath: rulesFile,
|
|
361
|
+
lockKey: `${agent.id}:rules`, sha256: sha256Hex(block), action: 'conflict',
|
|
362
|
+
detail: `${overridePath} shadows ${rulesFile}; remove the override before installing global rules`,
|
|
363
|
+
files: [],
|
|
364
|
+
}];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const items = [await planBlockItem(agent.id, 'rules', 'rules', rulesFile, block)];
|
|
368
|
+
if (bridgeFile !== null && importLine !== null) {
|
|
369
|
+
const bridgeBlock = renderManagedBlock(importLine, manifest.name, manifest.version);
|
|
370
|
+
const existing = await readIfExists(bridgeFile);
|
|
371
|
+
if (existing !== null && extractBlock(existing, bridgeFile) === null && hasBridgeLine(existing, importLine)) {
|
|
372
|
+
items.push(skipItem(agent.id, 'bridge', 'CLAUDE.md bridge', bridgeFile, sha256Hex(bridgeBlock), `${importLine} import already present (unmanaged)`));
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
items.push(await planBlockItem(agent.id, 'bridge', 'CLAUDE.md bridge', bridgeFile, bridgeBlock, existing));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return items;
|
|
379
|
+
}
|
|
380
|
+
function hasBridgeLine(content, importLine) {
|
|
381
|
+
return content.split(/\r?\n/).some((line) => line.trim() === importLine);
|
|
382
|
+
}
|
|
383
|
+
async function assertNotSymlink(targetPath) {
|
|
384
|
+
try {
|
|
385
|
+
if ((await fs.lstat(targetPath)).isSymbolicLink()) {
|
|
386
|
+
throw new Error(`Refusing to write through a symlink: ${targetPath}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
if (error.code !== 'ENOENT')
|
|
391
|
+
throw error;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
async function planBlockItem(agentId, kind, label, targetPath, block, existingArg) {
|
|
395
|
+
await assertNotSymlink(targetPath);
|
|
396
|
+
const existing = existingArg !== undefined ? existingArg : await readIfExists(targetPath);
|
|
397
|
+
const { action, detail } = classifyBlock(existing, block, targetPath);
|
|
398
|
+
const files = action === 'skip'
|
|
399
|
+
? []
|
|
400
|
+
: [{ path: targetPath, content: upsertManagedBlock(existing, block), backup: existing !== null }];
|
|
401
|
+
return {
|
|
402
|
+
agent: agentId, kind, label, targetPath,
|
|
403
|
+
lockKey: `${agentId}:${kind}`,
|
|
404
|
+
sha256: sha256Hex(block),
|
|
405
|
+
action, detail, files,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function skipItem(agentId, kind, label, targetPath, hash, detail) {
|
|
409
|
+
return { agent: agentId, kind, label, targetPath, lockKey: `${agentId}:${kind}`, sha256: hash, action: 'skip', detail, files: [] };
|
|
410
|
+
}
|
|
411
|
+
async function planSkillItem(agent, skill, profileDir, scope, homeDir, projectDir, lock) {
|
|
412
|
+
const srcDir = await safeProfileFile(profileDir, skill.source);
|
|
413
|
+
const relPaths = await walkFiles(srcDir);
|
|
414
|
+
const desired = new Map();
|
|
415
|
+
for (const rel of relPaths)
|
|
416
|
+
desired.set(rel, await fs.readFile(path.join(srcDir, rel)));
|
|
417
|
+
const desiredHash = hashFiles(desired);
|
|
418
|
+
const targetDir = path.join(skillsTargetDir(agent, scope, homeDir, projectDir), skill.name);
|
|
419
|
+
let targetFiles = [];
|
|
420
|
+
try {
|
|
421
|
+
const stat = await fs.lstat(targetDir);
|
|
422
|
+
if (stat.isSymbolicLink())
|
|
423
|
+
throw new Error(`Target skill is a symlink: ${targetDir}`);
|
|
424
|
+
targetFiles = await walkFiles(targetDir);
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
if (error.code !== 'ENOENT')
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
const current = new Map();
|
|
431
|
+
for (const rel of relPaths) {
|
|
432
|
+
const content = await readBufferIfExists(path.join(targetDir, rel));
|
|
433
|
+
if (content !== null)
|
|
434
|
+
current.set(rel, content);
|
|
435
|
+
}
|
|
436
|
+
const lockKey = `${agent.id}:skill:${skill.name}`;
|
|
437
|
+
const base = { agent: agent.id, kind: 'skill', label: `skill "${skill.name}"`, targetPath: targetDir, lockKey, sha256: desiredHash };
|
|
438
|
+
const extras = targetFiles.filter((rel) => !desired.has(rel) && !rel.endsWith(BACKUP_SUFFIX));
|
|
439
|
+
if (extras.length > 0) {
|
|
440
|
+
return { ...base, action: 'conflict', detail: `existing files absent from profile: ${extras.join(', ')}`, files: [] };
|
|
441
|
+
}
|
|
442
|
+
const missing = relPaths.filter((rel) => !current.has(rel));
|
|
443
|
+
const differing = relPaths.filter((rel) => {
|
|
444
|
+
const before = current.get(rel);
|
|
445
|
+
const after = desired.get(rel);
|
|
446
|
+
return before !== undefined && after !== undefined && !before.equals(after);
|
|
447
|
+
});
|
|
448
|
+
if (missing.length === 0 && differing.length === 0) {
|
|
449
|
+
return { ...base, action: 'skip', detail: 'unchanged', files: [] };
|
|
450
|
+
}
|
|
451
|
+
if (differing.length > 0) {
|
|
452
|
+
const entry = lock.entries[lockKey];
|
|
453
|
+
const pristine = entry !== undefined && missing.length === 0 && hashFiles(current) === entry.sha256;
|
|
454
|
+
if (!pristine) {
|
|
455
|
+
const list = differing.map((rel) => path.join(targetDir, rel)).join(', ');
|
|
456
|
+
return { ...base, action: 'conflict', detail: `existing content differs: ${list}`, files: [] };
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const writeRels = [...missing, ...differing];
|
|
460
|
+
const files = writeRels.map((rel) => ({
|
|
461
|
+
path: path.join(targetDir, rel),
|
|
462
|
+
content: desired.get(rel) ?? Buffer.alloc(0),
|
|
463
|
+
backup: current.has(rel),
|
|
464
|
+
}));
|
|
465
|
+
const action = missing.length === relPaths.length ? 'create' : 'update';
|
|
466
|
+
const detail = `${action === 'create' ? 'copy' : 'update'} ${writeRels.length} file(s): ${writeRels.join(', ')}`;
|
|
467
|
+
return { ...base, action, detail, files };
|
|
468
|
+
}
|
|
469
|
+
async function walkFiles(dir, prefix = '') {
|
|
470
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
471
|
+
const out = [];
|
|
472
|
+
for (const entry of entries) {
|
|
473
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
474
|
+
if (entry.isSymbolicLink())
|
|
475
|
+
throw new Error(`Profile skill contains a symlink: ${path.join(dir, entry.name)}`);
|
|
476
|
+
if (entry.isDirectory())
|
|
477
|
+
out.push(...await walkFiles(path.join(dir, entry.name), rel));
|
|
478
|
+
else if (entry.isFile())
|
|
479
|
+
out.push(rel);
|
|
480
|
+
}
|
|
481
|
+
return out.sort();
|
|
482
|
+
}
|
|
483
|
+
function hashFiles(entries) {
|
|
484
|
+
const hash = createHash('sha256');
|
|
485
|
+
for (const [rel, content] of [...entries].sort(([a], [b]) => a.localeCompare(b))) {
|
|
486
|
+
hash.update(rel, 'utf8');
|
|
487
|
+
hash.update('\0');
|
|
488
|
+
hash.update(content);
|
|
489
|
+
hash.update('\0');
|
|
490
|
+
}
|
|
491
|
+
return hash.digest('hex');
|
|
492
|
+
}
|
|
493
|
+
function sha256Hex(content) {
|
|
494
|
+
return createHash('sha256').update(content, 'utf8').digest('hex');
|
|
495
|
+
}
|
|
496
|
+
function printPlan(log, manifest, scope, scopeDir, items) {
|
|
497
|
+
log(`Profile "${manifest.name}" v${manifest.version} — scope: ${scope} (${scopeDir})`);
|
|
498
|
+
log('');
|
|
499
|
+
for (const item of items) {
|
|
500
|
+
log(` [${item.agent}] ${item.kind.padEnd(6)} ${item.action.toUpperCase().padEnd(8)} ${item.targetPath}`);
|
|
501
|
+
log(`${' '.repeat(11)}${item.detail}`);
|
|
502
|
+
}
|
|
503
|
+
const counts = { create: 0, update: 0, skip: 0, conflict: 0 };
|
|
504
|
+
for (const item of items)
|
|
505
|
+
counts[item.action] += 1;
|
|
506
|
+
log('');
|
|
507
|
+
log(`Summary: ${counts.create} create, ${counts.update} update, ${counts.skip} skipped (unchanged), ${counts.conflict} conflict`);
|
|
508
|
+
}
|
|
509
|
+
async function executeWrites(writes, lockPath, lockContent, validate, log) {
|
|
510
|
+
// Every target gets a temporary copy of its immediately previous state for rollback. The
|
|
511
|
+
// user-facing .skillfit-bak has a different purpose: it preserves the earliest original.
|
|
512
|
+
// Include the lockfile in this batch so its write and post-write validation can also roll back.
|
|
513
|
+
const files = writes.flatMap((item) => item.files.map((file) => ({ ...file, isLockfile: false })));
|
|
514
|
+
files.push({ path: lockPath, content: lockContent, backup: existsSync(lockPath), isLockfile: true });
|
|
515
|
+
const staged = [];
|
|
516
|
+
try {
|
|
517
|
+
for (const file of files) {
|
|
518
|
+
await fs.mkdir(path.dirname(file.path), { recursive: true });
|
|
519
|
+
const suffix = `${process.pid}.${randomUUID()}`;
|
|
520
|
+
const tmp = `${file.path}.${suffix}.skillfit-staged`;
|
|
521
|
+
const restore = existsSync(file.path) ? `${file.path}.${suffix}.skillfit-restore` : null;
|
|
522
|
+
const entry = { target: file.path, tmp, restore, backedUp: null, isLockfile: file.isLockfile };
|
|
523
|
+
staged.push(entry);
|
|
524
|
+
if (restore)
|
|
525
|
+
await fs.copyFile(file.path, restore);
|
|
526
|
+
if (file.backup) {
|
|
527
|
+
// The lockfile backup tracks the previous version; user-content backups keep the first.
|
|
528
|
+
if (file.isLockfile) {
|
|
529
|
+
await fs.copyFile(file.path, file.path + BACKUP_SUFFIX);
|
|
530
|
+
entry.backedUp = file.path + BACKUP_SUFFIX;
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
entry.backedUp = await backupOnce(file.path);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
await fs.writeFile(tmp, file.content);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
catch (error) {
|
|
540
|
+
await cleanupStaged(staged);
|
|
541
|
+
throw error;
|
|
542
|
+
}
|
|
543
|
+
const applied = [];
|
|
544
|
+
try {
|
|
545
|
+
for (const entry of staged) {
|
|
546
|
+
await fs.rename(entry.tmp, entry.target);
|
|
547
|
+
applied.push(entry);
|
|
548
|
+
}
|
|
549
|
+
await validate();
|
|
550
|
+
}
|
|
551
|
+
catch (error) {
|
|
552
|
+
const rollbackFailures = [];
|
|
553
|
+
const preserveRestores = new Set();
|
|
554
|
+
for (const entry of applied.reverse()) {
|
|
555
|
+
try {
|
|
556
|
+
if (entry.restore)
|
|
557
|
+
await fs.copyFile(entry.restore, entry.target);
|
|
558
|
+
else
|
|
559
|
+
await fs.rm(entry.target, { force: true });
|
|
560
|
+
}
|
|
561
|
+
catch (rollbackError) {
|
|
562
|
+
rollbackFailures.push(`${entry.target}: ${rollbackError.message}`);
|
|
563
|
+
preserveRestores.add(entry.target);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
await cleanupStaged(staged, preserveRestores);
|
|
567
|
+
if (rollbackFailures.length > 0) {
|
|
568
|
+
throw new Error(`Install failed (${error.message}) and rollback failed for ${rollbackFailures.join('; ')}. ` +
|
|
569
|
+
`Recovery copies with the .skillfit-restore suffix were kept beside those targets.`, { cause: error });
|
|
570
|
+
}
|
|
571
|
+
throw error;
|
|
572
|
+
}
|
|
573
|
+
await cleanupStaged(staged);
|
|
574
|
+
for (const entry of staged) {
|
|
575
|
+
if (!entry.isLockfile)
|
|
576
|
+
log(` wrote ${entry.target}${entry.backedUp ? ` (backup: ${entry.backedUp})` : ''}`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
async function cleanupStaged(staged, preserveRestores = new Set()) {
|
|
580
|
+
for (const entry of staged) {
|
|
581
|
+
await fs.rm(entry.tmp, { force: true });
|
|
582
|
+
if (entry.restore && !preserveRestores.has(entry.target))
|
|
583
|
+
await fs.rm(entry.restore, { force: true });
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Back up a file at most once. `.skillfit-bak` is a single slot, and the copy worth keeping is the
|
|
588
|
+
* user's pre-skillfit original: overwriting it on a later update would destroy the only copy of the
|
|
589
|
+
* content the suffix exists to protect. Returns the backup path when one was created, else null.
|
|
590
|
+
*/
|
|
591
|
+
async function backupOnce(target) {
|
|
592
|
+
const backup = target + BACKUP_SUFFIX;
|
|
593
|
+
try {
|
|
594
|
+
await fs.access(backup);
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
catch {
|
|
598
|
+
// absent — take the backup
|
|
599
|
+
}
|
|
600
|
+
await fs.copyFile(target, backup);
|
|
601
|
+
return backup;
|
|
602
|
+
}
|
|
603
|
+
async function validateWrites(writes) {
|
|
604
|
+
const problems = [];
|
|
605
|
+
for (const item of writes) {
|
|
606
|
+
for (const file of item.files) {
|
|
607
|
+
const actual = await readBufferIfExists(file.path);
|
|
608
|
+
const expected = Buffer.isBuffer(file.content) ? file.content : Buffer.from(file.content, 'utf8');
|
|
609
|
+
if (actual === null || !actual.equals(expected)) {
|
|
610
|
+
problems.push(`${file.path}: content differs from the install plan`);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
if (item.kind === 'skill') {
|
|
614
|
+
const skillMd = path.join(item.targetPath, 'SKILL.md');
|
|
615
|
+
const content = await readIfExists(skillMd);
|
|
616
|
+
const fm = content === null ? null : parseFrontmatter(content);
|
|
617
|
+
if (!fm?.name || !fm.description) {
|
|
618
|
+
problems.push(`${skillMd}: SKILL.md is missing or its frontmatter lacks name/description`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
const content = await readIfExists(item.targetPath);
|
|
623
|
+
if (content === null || !content.includes(MARKER_START) || !content.includes(MARKER_END)) {
|
|
624
|
+
problems.push(`${item.targetPath}: managed block missing after write`);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return problems;
|
|
629
|
+
}
|
|
630
|
+
function recordEntries(lock, items, manifest, installedAt) {
|
|
631
|
+
for (const item of items) {
|
|
632
|
+
if (item.action === 'conflict')
|
|
633
|
+
continue;
|
|
634
|
+
const prior = lock.entries[item.lockKey];
|
|
635
|
+
// A skip means the file on disk already matches what this profile wants. Refreshing its entry is
|
|
636
|
+
// what lets a run that failed partway — content applied, lockfile not yet written — reconcile on
|
|
637
|
+
// the next success instead of leaving a stale profileVersion behind permanently. Only refresh
|
|
638
|
+
// keys already recorded: a skip on an unmanaged file (a CLAUDE.md bridge import skillfit did not
|
|
639
|
+
// write) must not be claimed as ours.
|
|
640
|
+
if (item.action === 'skip' && prior === undefined)
|
|
641
|
+
continue;
|
|
642
|
+
lock.entries[item.lockKey] = {
|
|
643
|
+
agent: item.agent,
|
|
644
|
+
kind: item.kind,
|
|
645
|
+
path: item.targetPath,
|
|
646
|
+
sha256: item.sha256,
|
|
647
|
+
profile: manifest.name,
|
|
648
|
+
profileVersion: manifest.version,
|
|
649
|
+
// A refreshed skip was installed earlier; keep the original timestamp.
|
|
650
|
+
installedAt: item.action === 'skip' && prior !== undefined ? prior.installedAt : installedAt,
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
}
|