Skip to content

feat(B-0058): add retractibility audit tool#2108

Merged
AceHack merged 1 commit into
mainfrom
worktree-b-0058-retractibility-checker
May 8, 2026
Merged

feat(B-0058): add retractibility audit tool#2108
AceHack merged 1 commit into
mainfrom
worktree-b-0058-retractibility-checker

Conversation

@AceHack
Copy link
Copy Markdown
Member

@AceHack AceHack commented May 8, 2026

Summary

  • Adds tools/alignment/audit_retractibility.ts — B-0058 responsibility deps: Bump FsUnit.xUnit from 7.1.0 to 7.1.1 #1 (retractibility-and-log check)
  • Scans factory surfaces (skills, agents, backlog P0/P1) for git-tracking status and inbound reference counts via git grep
  • Classifies each surface as retractible (< 5 inbound refs), entangled (>= 5), or untracked
  • Supports --json, --md, and human output formats; optional --gate N exit-code gate

Evidence

$ bun tools/alignment/audit_retractibility.ts \
    .claude/skills/alignment-auditor/SKILL.md \
    .claude/agents/alignment-auditor.md \
    docs/backlog/P1/B-0058-ai-ethics-and-safety-research-track.md

retractibility total=3 retractible=1 entangled=2 untracked=0 threshold=5

Entangled surfaces (>= threshold inbound refs):
  [agent] alignment-auditor                        refs=10
  [skill] alignment-auditor                        refs=6

Top retractible surfaces by inbound refs:
  [backlog] B-0058                                   refs=0

Test plan

  • 26 Bun tests pass (bun test tools/alignment/audit_retractibility.test.ts)
  • Existing B-0058 tests pass (34 tests across coverage + drift tools)
  • dotnet build -c Release — 0 warnings, 0 errors
  • README updated with new tool entry

🤖 Generated with Claude Code

B-0058 responsibility #1: verify that factory surfaces (skills, agents,
backlog items) preserve retractibility — git-tracked and one-commit-removable.

The tool scans each surface for inbound references via git grep and
classifies it as retractible (< 5 inbound refs), entangled (>= 5), or
untracked. Emits --json / --md / human output. Optional --gate N flag
fails if any surface has >= N inbound refs.

Includes 26 Bun tests covering arg parsing, ref counting, audit shape,
and CLI exit codes. All existing B-0058 tests pass. Build gate green
(0 warnings, 0 errors).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 8, 2026 17:31
@AceHack AceHack enabled auto-merge (squash) May 8, 2026 17:32
@AceHack AceHack merged commit 914f365 into main May 8, 2026
27 checks passed
@AceHack AceHack deleted the worktree-b-0058-retractibility-checker branch May 8, 2026 17:34
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a84559152

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

export function countInboundRefs(filePath: string, root: string): { count: number; from: readonly string[] } {
const relPath = relative(root, `${root}/${filePath}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Normalize repo-relative path before running git grep

countInboundRefs builds the grep key with relative(root, ${root}/${filePath}), which produces incorrect strings for valid inputs such as absolute paths (e.g. /workspace/Zeta/... becomes workspace/Zeta/...) and, on Windows, backslash-separated paths. In both cases git grep misses real references and returns 0, so surfaces are misclassified as retractible and --gate can pass when it should fail. This breaks the tool’s core entanglement signal for common automation/cross-platform usage.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new alignment tool to audit “retractibility” of factory surfaces by checking (a) whether each surface is git-tracked and (b) how many inbound references it has, with multiple output formats and an optional gate mode.

Changes:

  • Added tools/alignment/audit_retractibility.ts CLI to scan skills/agents/backlog surfaces (or explicit paths) and report inbound reference counts via git grep.
  • Added Bun test coverage for arg parsing, reference counting, audit output shape, and CLI exit codes.
  • Documented the new tool in tools/alignment/README.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tools/alignment/README.md Adds the new retractibility audit tool to the alignment tool index.
tools/alignment/audit_retractibility.ts Implements git-tracking + inbound-ref counting and emits human/JSON/MD output with optional gating.
tools/alignment/audit_retractibility.test.ts Adds Bun tests covering parsing, counting, auditing, and CLI exit codes.

Comment on lines +113 to +116
export function countInboundRefs(filePath: string, root: string): { count: number; from: readonly string[] } {
const relPath = relative(root, `${root}/${filePath}`);

const result = spawnSync(
Comment on lines +195 to +210
export function auditRetractibility(paths: readonly string[]): RetractResult {
const root = process.cwd();
const surfaces: SurfaceRetract[] = [];

for (const p of paths) {
const gitTracked = isGitTracked(p);
const { count, from } = gitTracked ? countInboundRefs(p, root) : { count: 0, from: [] as string[] };
const status = classifyStatus(gitTracked, count);

surfaces.push({
path: p,
kind: kindFromPath(p),
name: nameFromPath(p),
gitTracked,
inboundRefs: count,
inboundFrom: from,
Comment on lines +316 to +325
const { args } = parsed;

process.chdir(repoRoot());

let paths: readonly string[];
if (args.paths.length > 0) {
paths = args.paths;
} else {
paths = [...discoverSkills(), ...discoverAgents(), ...discoverBacklog()];
}
expect(main(["--md", ".claude/agents/alignment-auditor.md"])).toBe(0);
});

test("returns 0 with --gate 0 (trivially satisfied)", () => {
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.

2 participants