用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/SocketDev/action --skill guarding-paths命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Propagate a wheelhouse template change across fleet repos: worktrees, push/PR fallback, cleanup.
Run this repo's GitHub Actions locally with Agent-CI before pushing CI-sensitive changes.
Audit package exports for dead, internal-only, or weakly-consumed subpaths before pruning.
基于 SOC 职业分类
正在显示 SKILL.md
| name | guarding-paths |
| description | Enforce one constructed path per concern; fix duplicated build, test, runtime, config paths. |
| user-invocable | true |
| allowed-tools | Task, Read, Edit, Write, Grep, Glob, AskUserQuestion, Bash(pnpm run check:*), Bash(node scripts/fleet/check/paths-are-canonical.mts:*), Bash(rg:*), Bash(grep:*), Bash(find:*), Bash(git:*) |
| model | claude-haiku-4-5 |
| context | fork |
| metadata | {"internal":true} |
Mantra: 1 path, 1 reference. A path is constructed exactly once; everywhere else references the constructed value. Re-constructing the same path twice is the violation. Referencing the constructed value many times is fine.
| Invocation | Effect |
|---|---|
/guarding-paths | Full audit-and-fix on the current repo (default). |
/guarding-paths check | Read-only audit; report violations; no fixes. |
/guarding-paths fix <id> | Fix a single finding from a prior check run, by index. |
/guarding-paths install | Drop the gate + hook + rule + allowlist into a fresh repo. |
The strategy lives in three artifacts that ship together:
## 1 path, 1 reference. Synced from _shared/path-guard-rule.md..claude/hooks/fleet/path-guard/index.mts runs PreToolUse on Edit / Write of .mts / .cts files. Blocks new violations at edit time.scripts/fleet/check/paths-are-canonical.mts runs in pnpm check (and CI). Whole-repo scan. Fails the build on any unsanctioned violation.The hook and gate share their stage / build-root / mode / sibling-package vocabulary via .claude/hooks/fleet/path-guard/segments.mts: a single canonical source. Adding a new stage segment or fleet package means editing one file; the two consumers can never drift on what counts as a build-output path.
This skill is the audit-and-fix workflow that makes a repo conform initially and validates conformance over time.
The gate enforces six rules. The hook enforces a subset (A and B), since it sees only one diff at a time.
| Rule | What it catches | Where checked |
|---|---|---|
| A | Multi-stage path.join(...) constructed inline. Two or more "stage" segments (Final, Release, Stripped, Compressed, Optimized, Synced, wasm, downloaded), or one stage + build-root + mode. | .mts / .cts files outside a paths.mts. Hook + gate. |
| B | Cross-package traversal: path.join(*, '..', '<sibling-package>', 'build', ...) reaching into a sibling's output instead of importing via exports. | .mts / .cts files. Hook + gate. |
| C | Workflow YAML constructs the same path string in 2+ steps outside a "Compute paths" step. | .github/workflows/*.yml. Gate. |
| D | Comment encodes a fully-qualified multi-stage path string (e.g. # build/dev/darwin-arm64/out/Final/binary). | .github/workflows/*.yml. Gate. |
| F | Same path shape constructed in 2+ different files. | All scanned files. Gate. |
| G | Hand-built multi-stage path constructed 2+ times in the same Makefile / Dockerfile / shell stage. | Makefile, *.mk, *.Dockerfile, Dockerfile.*, *.sh. Gate. |
Comments may describe path structure with placeholders (<mode>/<arch> or ${BUILD_MODE}/${PLATFORM_ARCH}) but should not encode a complete literal path string. Violations in .mts, Makefiles, Dockerfiles, workflow YAML, and shell scripts are blocking; comments come second.
| # | Phase | Outcome |
|---|---|---|
| 1 | Setup | Spawn worktree off origin/$BASE (default-branch fallback). |
| 2 | Audit | pnpm run check:paths --json > /tmp/paths-findings.json; pnpm run check:paths --explain for human-readable. |
| 3 | Fix loop | For each finding, apply the matching pattern from reference.md. Re-run the gate after each fix. Stop when pnpm run check:paths exits 0. |
| 4 | Verify | pnpm check + zizmor on any modified workflow. |
| 5 | Commit + push | Per-rule commits, atomic. Push directly to $BASE for repos that allow it; PR for socket-cli / socket-sdk-js / socket-registry. |
| 6 | Cleanup | git worktree remove ../<repo>-paths-audit. git worktree list should show only the primary afterward. |
Worktree setup uses the default-branch fallback from CLAUDE.md:
# Resolved by the shared runner so the chain lives in exactly one place.
BASE=$(node .claude/skills/fleet/_shared/scripts/git-default-branch.mts)
git worktree add -b paths-audit ../<repo>-paths-audit "$BASE"
pnpm run check:paths --explain
Prints findings without making edits. Exit 0 if clean, 1 if findings present. Useful for CI / pre-merge inspection.
For Socket repos that don't yet have the gate:
cp .claude/skills/guarding-paths/templates/check-paths.mts.tmpl scripts/fleet/check/paths-are-canonical.mts
pathsAllowlist array of .config/socket-wheelhouse.json (absent key = no exemptions, which is the default)."check:paths": "node scripts/fleet/check/paths-are-canonical.mts" to package.json.runPathHygieneCheck() into scripts/check.mts (after the existing checks)._shared/path-guard-rule.md to the repo's CLAUDE.md if a 1 path, 1 reference section is missing..claude/settings.json PreToolUse matcher Edit|Write:
{
"type": "command",
"command": "node .claude/hooks/fleet/path-guard/index.mts"
}
Genuine exemptions are rare; most "false positives" should be reported as gate bugs. When needed, add an entry to the pathsAllowlist array in .config/socket-wheelhouse.json (each entry needs a reason). Two ways to pin:
line:: exact line number. Strict; a single-line edit above shifts the entry off-target and the finding re-surfaces.snippet_hash:: 12-char SHA-256 prefix of the offending snippet (whitespace-normalized). Drift-resistant: survives reformatting, but any content-changing edit invalidates it. Get the hash via pnpm run check:paths --show-hashes.Both may be set — either matching is sufficient. Prefer snippet_hash over raw line: when the exemption is expected to outlive routine reformatting; prefer line: when you specifically want the entry to fall off after any nearby edit.
packages/foo/ and Rule C workflow fix go in separate commits even when found in the same audit pass.pnpm run check:paths is the entry criterion.chore/paths-audit-wip if the audit gets interrupted.Conventional commit shape: fix(paths): rule A: extract foo build paths into scripts/paths.mts.
scanning-quality/scanning-quality calls pnpm run check:paths --json as one of its sub-scans and surfaces findings in its A-F report. The full audit-and-fix workflow lives here. scanning-quality only detects during periodic scans.
Per-rule fix templates (Rules A through G) plus the worked-example reference patterns from socket-btm: reference.md. File scaffolding for install mode lives in templates/.