fix(mods): ADR-406 catalog classifies lower-case report workflows and anchors to inventoried files

`.*report.*` labelled the real workflow analysis:performance-report as
documentation. Loader-exposed docs are the all-caps basenames (README,
COMMAND_COMPLIANCE_REPORT); match those only. 226 shipped, 15 documentation.

The catalog's sourceCommit was the newest commit under any scanned root, so
an unrelated plugin commit made `catalog generate --check` stale. It is now
the newest commit touching a file the catalog actually inventories.

Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
ruv committed 2026-10-01 22:39:15 -04:00
1 parent 0483ac5517
commit 5913dd519b
4 files changed
+45 -15

No files matched your search

@@ -10,6 +10,7 @@ import { join, resolve } from 'node:path';
import {
CATALOG_RELATIVE_PATH,
INIT_COMMAND_CATEGORIES,
anchorCommit,
buildCatalog,
catalogDigest,
collectInventory,
@@ -38,6 +39,8 @@ function put(rel: string, text: string): void {
function fixtureRepo(): void {
put('.claude/commands/sparc/architect.md', '---\nallowed-tools: Read, Bash\nargument-hint: <task>\n---\nDesign $ARGUMENTS\n');
put('.claude/commands/agents/README.md', '# Agents\n');
put('.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md', '# Report\n');
put('.claude/commands/analysis/performance-report.md', 'Report on $ARGUMENTS\n');
put('.claude/commands/claude-flow-help.md', 'help\n');
put('v3/@claude-flow/cli/.claude/commands/sparc/architect.md', '---\nallowed-tools: Read, Bash\n---\nDesign it differently $ARGUMENTS\n');
put('v3/@claude-flow/cli/.claude/commands/claude-flow-help.md', 'help\n');
@@ -106,6 +109,9 @@ describe('inventory and catalog over a fixture repository', () => {
const readme = byId.get('project/agents:readme')!;
expect(readme.status).toBe('documentation');
expect(readme.definition.kind).toBe('help');
expect(byId.get('project/analysis:command_compliance_report')!.status).toBe('documentation');
// A lower-case workflow whose name contains "report" is a workflow, not docs.
expect(byId.get('project/analysis:performance-report')!.definition).toMatchObject({ kind: 'prompt', disposition: 'delegate' });
const watch = byId.get('ruflo-swarm/ruflo-swarm:watch')!;
expect(watch.sources.map((s) => s.binding)).toEqual(['markdown-loader', 'mod-middleware-on-markdown']);
@@ -160,6 +166,15 @@ describe('validator (P1 gate)', () => {
});
});
describe('catalog anchor commit', () => {
it('is the newest commit touching an inventoried path, not any commit under the roots', () => {
const commits = { byPath: { 'a.md': 'c2', 'b.md': 'c3' }, order: ['c1', 'c2', 'c3'], dirty: new Set<string>() };
expect(anchorCommit(['a.md', 'b.md'], commits)).toBe('c2');
expect(anchorCommit(['a.md', 'x.md'], commits)).toBe('uncommitted');
expect(anchorCommit(['a.md'], { ...commits, dirty: new Set(['a.md']) })).toBe('uncommitted');
});
});
describe('engine validate parsing', () => {
it('collects command hooks and host calls from per-file lines, not the "Validating hooks" header', () => {
const text = [
@@ -877,9 +877,9 @@
"maxLength": 8192,
"type": "string"
},
"disposition": "legacy",
"disposition": "delegate",
"id": "project/analysis:performance-report",
"kind": "help",
"kind": "prompt",
"legacyNames": [
"analysis:performance-report"
],
@@ -903,7 +903,6 @@
},
"divergent": true,
"notes": [
"documentation file exposed by the engine command loader; not an executable workflow",
"copies differ between delivery channels; see sources[].digest"
],
"sources": [
@@ -931,7 +930,7 @@
"sourcePath": "v3/@claude-flow/cli/.claude/commands/analysis/performance-report.md"
}
],
"status": "documentation"
"status": "shipped"
},
{
"definition": {
@@ -13434,6 +13433,6 @@
"status": "shipped"
}
],
"sourceCommit": "d3a3979ae64380b39020888de5a89e204a108c75",
"sourceDigest": "sha256:b11779b021abfb7c79ce96683b2ffd48bce766202de14ef9a13d88e9744817a8"
"sourceCommit": "8a1e11f3bde0ba6c3855f23e420eeb6f003c8374",
"sourceDigest": "sha256:a21f24c53c5620e6f9f4f630fd58358c307ac5526eda503787fb19748671e5f8"
}
@@ -23,7 +23,10 @@ import {
import { sha256Hex, type RawCommand } from './inventory.js';
export const REPOSITORY = 'ruvnet/ruflo';
const DOC_NAME = /^(?:readme|changelog|.*report.*|.*compliance.*)$/i;
// Loader-exposed documentation is named in capitals (README, CHANGELOG,
// COMMAND_COMPLIANCE_REPORT). Lower-case names such as `performance-report`
// are real workflows and must not be matched by content words.
const DOC_NAME = /^[A-Z][A-Z0-9_]+$/;
const CHANNEL_PRIORITY: Record<InventorySource['channel'], number> = {
'repo-project-commands': 0,
'cli-init-template': 1,
@@ -36,24 +36,37 @@ export const defaultRunner: Runner = (file, args, env) => {
}
};
/** Last commit per repository-relative path, in one `git log` pass; dirty paths are `uncommitted`. */
export function lastCommits(repoRoot: string, roots: readonly string[], run: Runner = defaultRunner): { byPath: Record<string, string>; newest: string } {
/**
* Last commit per repository-relative path, in one `git log` pass; dirty paths
* are dropped (they read as `uncommitted`). `order` lists commits newest first.
*/
export function lastCommits(repoRoot: string, roots: readonly string[], run: Runner = defaultRunner): { byPath: Record<string, string>; order: string[]; dirty: Set<string> } {
const log = run('git', ['-C', repoRoot, 'log', '--format=%x00%H', '--name-only', '--', ...roots], process.env);
const byPath: Record<string, string> = {};
const order: string[] = [];
let current = '';
let newest = '';
for (const line of log.stdout.split('\n')) {
if (line.startsWith('\u0000')) { current = line.slice(1).trim(); if (!newest) newest = current; continue; }
if (line.startsWith('\u0000')) { current = line.slice(1).trim(); order.push(current); continue; }
const path = line.trim();
if (path && current && !(path in byPath)) byPath[path] = current;
}
const status = run('git', ['-C', repoRoot, 'status', '--porcelain', '--untracked-files=all', '--', ...roots], process.env);
let dirty = false;
const dirty = new Set<string>();
for (const line of status.stdout.split('\n')) {
const path = line.slice(3).trim();
if (path) { delete byPath[path]; dirty = true; }
if (path) { delete byPath[path]; dirty.add(path); }
}
return { byPath, newest: dirty || !newest ? 'uncommitted' : newest };
return { byPath, order, dirty };
}
/**
* The catalog's anchor: the newest commit that touched a file the catalog
* actually inventories, so unrelated plugin commits do not make it stale.
*/
export function anchorCommit(paths: readonly string[], commits: ReturnType<typeof lastCommits>): string {
if (paths.some((p) => commits.dirty.has(p) || !commits.byPath[p])) return 'uncommitted';
const used = new Set(paths.map((p) => commits.byPath[p]));
return commits.order.find((c) => used.has(c)) ?? 'uncommitted';
}
/** `npm pack --dry-run --json` file list for a package directory, made repository-relative. */
@@ -125,7 +138,7 @@ export function generate(input: GenerateInput): GenerateResult {
const options: CatalogOptions = {
commits: commits.byPath,
packageContentsInspected: Object.keys(packed).length > 0,
sourceCommit: commits.newest,
sourceCommit: anchorCommit([...new Set(inventory.map((r) => r.source.sourcePath))], commits),
};
return {
inventory,