返回 CodeWhale
workspace-audit.js
根目录 / crates / plugins / assets / agent-teams / lib / workspace-audit.js
1 /**
2 * The single workspace audit shared by every surface that reports a delivery
3 * or quality-loop conclusion.
4 *
5 * `agent_teams_status`, the activity-panel route and any Web API consumer must
6 * read the same current bytes: if only one of them compared recorded verdicts
7 * against the workspace, the other would keep advertising a passing gate over
8 * a revision no review ever saw (issue #161).
9 *
10 * The audit consumes the artifact reader's *complete* result — digests, the
11 * enumeration gaps and unreadable paths — because a partial read must never
12 * look like a clean one: a scope that outgrew its cap after the review would
13 * otherwise be reported as fully verified.
14 * @module dsh-agent-teams/workspace-audit
15 */
16 import { readArtifactScopes } from "./artifacts.js";
17 import { deliveryArtifactPaths, deliveryScopePatterns } from "./quality-gates.js";
18 /**
19 * Read the current workspace bytes a team's recorded verdicts and generated
20 * work orders depend on.
21 * @param workspace - absolute path of the owning workspace.
22 * @param team - the durable team record.
23 * @returns digests of every recorded path, the current contents of the scopes
24 * the verdicts bound (so a new file cannot slip into a broad scope), and every
25 * gap that makes this audit incomplete.
26 */
27 export function auditTeamWorkspace(workspace, team) {
28 const paths = deliveryArtifactPaths(team);
29 const scopePatterns = deliveryScopePatterns(team);
30 const [pathRead, scopeRead] = readArtifactScopes(workspace, [paths, scopePatterns]);
31 const gaps = [];
32 const seen = new Set();
33 const recordGap = (pattern, reason) => {
34 const key = `${pattern}\u0000${reason}`;
35 if (seen.has(key))
36 return;
37 seen.add(key);
38 gaps.push({ pattern, reason });
39 };
40 for (const gap of [...pathRead.gaps, ...scopeRead.gaps])
41 recordGap(gap.pattern, gap.reason);
42 for (const artifact of [...pathRead.artifacts, ...scopeRead.artifacts]) {
43 // An unreadable path is not a gap in enumeration but a gap in evidence:
44 // report it the same way so no surface treats it as a clean read.
45 if (artifact.unreadable === true)
46 recordGap(artifact.path, artifact.reason ?? 'path could not be read');
47 }
48 return {
49 artifacts: pathRead.artifacts,
50 expandedScope: scopeRead.artifacts.map((artifact) => ({ path: artifact.path, present: artifact.present })),
51 ...gaps.length === 0 ? {} : { gaps },
52 };
53 }
54
54 lines JAVASCRIPT