Skip to content

feat(B-0058): alignment-clause drift detector#2103

Merged
AceHack merged 1 commit into
mainfrom
worktree-b-0058+clause-drift-detector
May 8, 2026
Merged

feat(B-0058): alignment-clause drift detector#2103
AceHack merged 1 commit into
mainfrom
worktree-b-0058+clause-drift-detector

Conversation

@AceHack
Copy link
Copy Markdown
Member

@AceHack AceHack commented May 8, 2026

Summary

What it does

Answers the question from B-0058 §4: "who depends on this clause, and what breaks if it moves?" before the renegotiation is accepted.

$ bun tools/alignment/audit_clause_drift.ts --base 00b02e09~1 --head 00b02e09
clause_drift base=00b02e09~1 head=00b02e09 base_clauses=21 head_clauses=21 diffs=2

~ SD-2 "Peer / big-kid register, no sermonizing" (body changed)
  depends: skill:alignment-auditor, skill:alignment-observability
~ SD-9 "Agreement is signal, not proof" (body changed)

Supports --json, --md, and human-readable output. Exit code 1 when removals or body changes detected; 0 otherwise.

Test plan

  • Default mode (--base main --head HEAD): 0 diffs, exit 0
  • Against known ALIGNMENT.md change (00b02e09): correctly detects SD-2 + SD-9 body changes with dependent surfaces
  • --json output: valid JSON with schema clause-drift-v1
  • --md output: valid markdown table
  • --help: prints usage
  • Build gate: dotnet build -c Release — 0 warnings, 0 errors

🤖 Generated with Claude Code

New TS tool at tools/alignment/audit_clause_drift.ts — compares
docs/ALIGNMENT.md between two git refs to detect clause additions,
removals, title changes, and body modifications. For each changed
clause, cross-references the existing clause-coverage audit to
report which factory surfaces (skills, agents) depend on it.

This is slice 2 of B-0058 (responsibility #4: alignment-clause
drift detector). Enables impact-survey before any renegotiation
of alignment clauses — answers "who depends on this clause, and
what breaks if it moves?"

Tested: detects SD-2 + SD-9 body changes across commit 00b02e0.
Build gate: 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 16:59
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@AceHack AceHack enabled auto-merge (squash) May 8, 2026 17:01
@AceHack AceHack merged commit f7127ee into main May 8, 2026
27 checks passed
@AceHack AceHack deleted the worktree-b-0058+clause-drift-detector branch May 8, 2026 17:02
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 Bun/TypeScript automation tool to detect drift in docs/ALIGNMENT.md clauses between two git refs and report which factory surfaces cite the affected clauses, extending the existing alignment observability tooling.

Changes:

  • Added tools/alignment/audit_clause_drift.ts to diff alignment clauses between --base and --head refs and emit human/JSON/Markdown reports.
  • Cross-referenced clause drift results with audit_clause_coverage.ts output to list dependent skills/agents.
  • Registered the new tool in tools/alignment/README.md.

Reviewed changes

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

File Description
tools/alignment/README.md Adds the new drift-audit script to the alignment tools index.
tools/alignment/audit_clause_drift.ts New drift detector that parses clause snapshots at two refs and reports adds/removals/title/body changes plus dependent surfaces.

Comment on lines +217 to +233
} else if (baseClause.title !== headClause.title) {
diffs.push({
id,
kind: "title-changed",
baseTitle: baseClause.title,
headTitle: headClause.title,
dependentSurfaces: depMap.get(id) ?? [],
});
} else if (baseClause.body !== headClause.body) {
diffs.push({
id,
kind: "body-changed",
baseTitle: baseClause.title,
headTitle: headClause.title,
dependentSurfaces: depMap.get(id) ?? [],
});
}
Comment on lines +119 to +125
function getFileAtRef(ref: string, path: string): string | null {
const result = spawnSync(
"git", // eslint-disable-line sonarjs/no-os-command-from-path
["show", `${ref}:${path}`],
{ encoding: "utf8" },
);
if (result.error || result.status !== 0) return null;
Comment on lines +198 to +205
const baseClauses = baseContent !== null ? extractClauses(baseContent) : [];
const headClauses = headContent !== null ? extractClauses(headContent) : [];

const baseMap = new Map(baseClauses.map((c) => [c.id, c]));
const headMap = new Map(headClauses.map((c) => [c.id, c]));
const depMap = buildDependencyMap();

const diffs: ClauseDiff[] = [];
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