@hegemonart/get-design-done 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +62 -0
- package/package.json +2 -1
- package/reference/output-contracts/planner-decision.schema.json +94 -0
- package/reference/output-contracts/verifier-decision.schema.json +66 -0
- package/scripts/lib/audit-aggregator/index.cjs +219 -0
- package/scripts/lib/design-solidify.mjs +265 -0
- package/scripts/lib/design-tokens/_js-harness.cjs +66 -0
- package/scripts/lib/design-tokens/css-vars.cjs +55 -0
- package/scripts/lib/design-tokens/figma.cjs +121 -0
- package/scripts/lib/design-tokens/index.cjs +100 -0
- package/scripts/lib/design-tokens/js-const.cjs +107 -0
- package/scripts/lib/design-tokens/tailwind.cjs +98 -0
- package/scripts/lib/domain-primitives/anti-patterns.cjs +66 -0
- package/scripts/lib/domain-primitives/nng.cjs +136 -0
- package/scripts/lib/domain-primitives/wcag.cjs +166 -0
- package/scripts/lib/parse-contract.cjs +168 -0
- package/scripts/lib/reference-resolver.cjs +184 -0
- package/scripts/lib/touches-analyzer/index.cjs +201 -0
- package/scripts/lib/touches-pattern-miner.cjs +195 -0
- package/scripts/lib/visual-baseline/diff.cjs +137 -0
- package/scripts/lib/visual-baseline/index.cjs +139 -0
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
},
|
|
6
6
|
"metadata": {
|
|
7
7
|
"description": "Get Design Done — 5-stage agent-orchestrated design pipeline with 9 connections, handoff-first workflow, bidirectional Figma write-back, 22+ specialized agents, queryable knowledge layer (intel store, dependency analysis, learnings extraction), and a self-improvement loop (reflector, frontmatter + budget feedback, global-skills layer). v1.20.0 ships the SDK foundation: gdd-state MCP server (11 typed tools), lockfile-safe STATE.md mutations, event stream, and resilience primitives (jittered-backoff, rate-guard, error-classifier, iteration-budget) for rate-limit + 429 + context-overflow recovery. Full CI/CD pipeline (Node 22/24 × Linux/macOS/Windows) and release automation (auto-tag + GitHub Release + release-time smoke test).",
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.23.0"
|
|
9
9
|
},
|
|
10
10
|
"plugins": [
|
|
11
11
|
{
|
|
12
12
|
"name": "get-design-done",
|
|
13
13
|
"source": "./",
|
|
14
14
|
"description": "Agent-orchestrated 5-stage design pipeline: Brief → Explore → Plan → Design → Verify. 22+ specialized agents, 9 connections (Figma, Refero, Preview, Storybook, Chromatic, Figma Writer, Graphify, Pinterest, Claude Design), Claude Design handoff, bidirectional Figma write-back, and a queryable intel store (.design/intel/) for dependency and learnings queries. Standalone commands: style, darkmode, compare, figma-write, graphify, handoff, analyze-dependencies, skill-manifest, extract-learnings. Embeds NNG heuristics, WCAG thresholds, typographic systems, motion framework, and anti-pattern catalog. Ships with a full CI/CD pipeline (Node 22/24 × Linux/macOS/Windows) and release automation. Optimization layer (v1.0.4.1, retroactive): gdd-router + gdd-cache-manager skills, PreToolUse budget-enforcer hook, tier-aware agent frontmatter, lazy checker gates, streaming synthesizer, /gdd:warm-cache + /gdd:optimize commands, and cost telemetry at .design/telemetry/costs.jsonl — targeting 50-70% per-task token-cost reduction with no quality-floor regression. v1.20.0 SDK foundation: gdd-state MCP server (11 typed tools), lockfile-safe STATE.md mutations, event stream at .design/telemetry/events.jsonl, resilience primitives (jittered-backoff, rate-guard, error-classifier, iteration-budget) with rate-limit + 429 + context-overflow recovery, and TypeScript toolchain.",
|
|
15
|
-
"version": "1.
|
|
15
|
+
"version": "1.23.0",
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "hegemonart"
|
|
18
18
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "get-design-done",
|
|
3
3
|
"short_name": "gdd",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.23.0",
|
|
5
5
|
"description": "Agent-orchestrated 5-stage design pipeline: Brief → Explore → Plan → Design → Verify. 22+ specialized agents, 9 connections (Figma, Refero, Preview, Storybook, Chromatic, Figma Writer, Graphify, Pinterest, Claude Design), handoff-first workflow via Claude Design bundles, bidirectional Figma write-back (annotations, Code Connect), queryable intel store (`.design/intel/`) for O(1) design surface lookups, and self-improvement loop (reflector agent, frontmatter + budget feedback, global-skills layer at `~/.claude/gdd/global-skills/`). Standalone commands: style, darkmode, compare, figma-write, graphify, handoff, analyze-dependencies, skill-manifest, extract-learnings, reflect, apply-reflections. Embeds NNG heuristics, WCAG thresholds, typographic systems, motion framework, and anti-pattern catalog. Ships with a full CI/CD pipeline (Node 22/24 × Linux/macOS/Windows, lint + schema + frontmatter + stale-ref + shellcheck + gitleaks + injection-scan + blocking size-budget) and release automation (auto-tag + GitHub Release + release-time smoke test). Optimization layer (v1.0.4.1, retroactive): gdd-router + gdd-cache-manager skills, PreToolUse budget-enforcer hook, tier-aware agent frontmatter, lazy checker gates, streaming synthesizer, /gdd:warm-cache + /gdd:optimize commands, and cost telemetry at .design/telemetry/costs.jsonl — targeting 50-70% per-task token-cost reduction with no quality-floor regression. v1.20.0 SDK foundation: gdd-state MCP server (11 typed tools), lockfile-safe STATE.md mutations, event stream at .design/telemetry/events.jsonl, resilience primitives (jittered-backoff, rate-guard, error-classifier, iteration-budget) with rate-limit + 429 + context-overflow recovery, and TypeScript toolchain.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "hegemonart",
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,68 @@ All notable changes to get-design-done are documented here. Versions follow [sem
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
## [1.23.0] — 2026-04-25
|
|
8
|
+
|
|
9
|
+
Phase 23 GDD SDK Domain Primitives milestone — lands the highest-leverage code primitives from the ROADMAP "GDD SDK Domain Primitives" entry as typed Node modules with tests. 10 atomic plans (23-01 through 23-10), additive — every Phase 20/21/22 consumer keeps working unchanged. Distribution as separate `@hegemonart/gdd-sdk` npm package and screenshot-capture orchestration are explicitly deferred to follow-up phases.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **JSON output contracts** — `reference/output-contracts/planner-decision.schema.json` + `verifier-decision.schema.json` (Draft-07). `scripts/lib/parse-contract.cjs` gains `parsePlannerDecision()` and `parseVerifierDecision()` riding the same extract→parse→validate pipeline as the existing `parseMotionMap`. Lets `/gdd:synthesize` consume planner output without regex-parsing markdown headings, and lets executor↔verifier ping-pong on a typed envelope. (Plan 23-01)
|
|
14
|
+
|
|
15
|
+
- **Solidify-with-rollback gate** — `scripts/lib/design-solidify.mjs` runs the typecheck/build/targeted-test triplet for a task and, on any failure, rolls the working tree back via `git stash` (configurable: `stash` | `hard` | `none`) and emits a `solidify.rollback` event onto the Phase 22 causal chain. Optional `emit()` callback for event-stream telemetry sink. Authored as `.mjs` to sidestep the Phase 22 Node 24 + Windows + .mjs↔.ts loader bug. (Plan 23-02)
|
|
16
|
+
|
|
17
|
+
- **Touches: analyzer + parallelism decision engine** — `scripts/lib/touches-analyzer/index.cjs` parses `Touches:` lines from task markdown into glob lists and produces a pairwise verdict (`parallel` | `sequential`) for any two tasks. Encodes today's prompt-only heuristic into auditable code. Verdict rules (first match wins): empty → unknown-touches; literal equality → shared-glob; shared component dir → shared-component-dir; resolved-file overlap → shared-file; otherwise → disjoint. (Plan 23-03)
|
|
18
|
+
|
|
19
|
+
- **Audit aggregator** — `scripts/lib/audit-aggregator/index.cjs` takes `Array<Finding>` from N audit-agents, dedups by `{file, line, rule_id}`, scores via severity-weighted formula (P0:8/P1:4/P2:2/P3:1), and returns sorted top-N + tally summary. Default merge picks higher-confidence → higher-severity → lex-earliest agent → first-seen. Confidence outside `[0, 1]` clamped with one `process.emitWarning` per call. Cross-platform path normalization. (Plan 23-04)
|
|
20
|
+
|
|
21
|
+
- **Reference resolver** — `scripts/lib/reference-resolver.cjs` adds the resolution direction on top of the Phase 14.5 reference-registry. `resolve('forms')` / `resolve('type:forms')` → `{name, path, type, excerpt}` with a 200-char excerpt suitable for inlining into agent prompts. Lookup order: exact name → slug match → singularize fuzzy → type-only-when-unique. Ambiguous match throws `RangeError` with candidates. `resolveAll(keys, {ignoreMissing})` for bulk. `excerptOf(path, {maxChars})` strips frontmatter / fenced code / HTML comments / markdown headers. (Plan 23-05)
|
|
22
|
+
|
|
23
|
+
- **Touches pattern miner** — `scripts/lib/touches-pattern-miner.cjs` scans `.design/archive/cycle-*/tasks/*.md` after `/gdd:complete-cycle`, canonicalizes signatures (lowercase + backslash-normalize + cycle-slug strip + dedup + sort), and proposes crystallization candidates when a signature recurs in ≥3 tasks across ≥2 cycles. Writes `.design/learnings/touches-patterns.json` atomically (`.tmp` + rename). **NEVER auto-applies** — `/gdd:apply-reflections` is the materialization gate. (Plan 23-06)
|
|
24
|
+
|
|
25
|
+
- **Image diff + visual baseline manager** — `scripts/lib/visual-baseline/diff.cjs` compares two PNG buffers. With `pngjs` installed (probeOptional), decodes both and counts pixels whose R/G/B/A channels differ beyond the tolerance (default 4). Without `pngjs`, falls back to bytewise SHA-256 equality. `scripts/lib/visual-baseline/index.cjs` exposes `compareToBaseline(key, pngBuffer)` and `applyBaseline(key, pngBuffer)`; reads/writes `.design/baselines/<key>.png`; rejects path-traversal keys. `pngjs@7` declared as optional dep. Defers Playwright/Preview MCP screenshot capture orchestration to a later phase. (Plan 23-07)
|
|
26
|
+
|
|
27
|
+
- **Design-token reader (multi-source)** — `scripts/lib/design-tokens/index.cjs` facades over four pure-JS readers producing the uniform `{tokens, source, format, warnings}` shape:
|
|
28
|
+
- `css-vars.cjs` — extracts `--token: value;` from CSS/SCSS, last-write-wins, strips block comments, warns on `$scss-vars`
|
|
29
|
+
- `js-const.cjs` — spawn-node harness evaluates CJS/ESM exports, recognises `{tokens: …}` / default / direct bag, flattens nested with `.` separator
|
|
30
|
+
- `tailwind.cjs` — same harness, walks `theme` + `theme.extend` per scale (extend overrides base)
|
|
31
|
+
- `figma.cjs` — parses `{variableCollections}` shape OR already-flattened bag; emits `rgb(R, G, B)` for color values, per-mode tokens for multi-mode variables
|
|
32
|
+
Auto-detection by extension + content sniff. (Plan 23-08)
|
|
33
|
+
|
|
34
|
+
- **Domain primitives bundle** — three checkers sharing a single hit shape (`{rule_id, severity P0-P3, summary, evidence?, line?, file}`):
|
|
35
|
+
- `domain-primitives/nng.cjs` — runs grep-style heuristic rules loaded from `reference/heuristics.md` fenced yaml blocks; caller may inject `opts.rules` to bypass file-load
|
|
36
|
+
- `domain-primitives/anti-patterns.cjs` — same yaml extractor against `reference/anti-patterns.md`
|
|
37
|
+
- `domain-primitives/wcag.cjs` (no axe-core dep) — `contrastRatio()` (WCAG 1.4.3 luminance), `checkContrast({fg, bg, level: AA|AAA})`, `checkTapTarget({width, height, level})` (AA 24×24, AAA 44×44), `checkAriaLabels({content})` (interactive elements without text + aria-label)
|
|
38
|
+
Both NNG + anti-pattern files allow no parseable yaml today (treated as empty registry); robust to gradual rule population. (Plan 23-09)
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- `tests/semver-compare.test.cjs` `OFF_CADENCE_VERSIONS` gains `1.23.0`.
|
|
43
|
+
- `test-fixture/baselines/phase-20/resilience-primitives.txt` gains `reference-resolver.cjs` (alphabetical between `reference-registry.cjs` and `relevance-counter.cjs`) and `touches-pattern-miner.cjs` (alphabetical at end).
|
|
44
|
+
|
|
45
|
+
### Tests
|
|
46
|
+
|
|
47
|
+
- `tests/output-contracts-23-01.test.cjs` — planner + verifier contracts (14 tests)
|
|
48
|
+
- `tests/design-solidify.test.cjs` — solidify gate, all rollback modes (6)
|
|
49
|
+
- `tests/touches-analyzer.test.cjs` — parser + verdict + matrix (17)
|
|
50
|
+
- `tests/audit-aggregator.test.cjs` — dedup + score + tallies (15)
|
|
51
|
+
- `tests/reference-resolver.test.cjs` — resolution rules + excerpts (12)
|
|
52
|
+
- `tests/touches-pattern-miner.test.cjs` — canonicalize + thresholds + atomic write (10)
|
|
53
|
+
- `tests/visual-baseline.test.cjs` — diff modes + baseline round-trip (14, pngjs-optional path skipped when absent)
|
|
54
|
+
- `tests/design-tokens.test.cjs` — 4 readers + facade auto-detect (15)
|
|
55
|
+
- `tests/domain-primitives.test.cjs` — NNG + anti-pattern + WCAG checkers (18)
|
|
56
|
+
- `tests/phase-23-baseline.test.cjs` — Phase 23 regression baseline (12)
|
|
57
|
+
|
|
58
|
+
Total: 133 new tests. All Phase 20/21/22 tests still green.
|
|
59
|
+
|
|
60
|
+
### Deferred
|
|
61
|
+
|
|
62
|
+
- **`@hegemonart/gdd-sdk` separate npm package** — out of scope; build/packaging project of its own.
|
|
63
|
+
- **Screenshot capture orchestration** (Playwright + Claude Preview MCP wrapper) — needs live MCP infra to validate.
|
|
64
|
+
- **Spec↔code↔visual triangulation verifier** — depends on Phase 16/17 component specs being fleshed out.
|
|
65
|
+
- **Knowledge-graph typed query layer** + cycle/workstream model SDK + pause/resume context serializer SDK + per-stage budget allocator SDK + git operations primitive + handoff bundle parser + intel store typed reader/writer — each is roadmap-text-sized and warrants its own phase scope.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
7
69
|
## [1.22.0] — 2026-04-25
|
|
8
70
|
|
|
9
71
|
Phase 22 GDD SDK Observability milestone — the single-typed `BaseEvent` envelope from Phase 20 grows into a queryable, redacted, transport-able observability layer with tail/grep/WebSocket consumers and a causal event chain. 10 plans (22-01 through 22-10), additive — every Phase 20 + Phase 21 consumer keeps working unchanged.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hegemonart/get-design-done",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "A Claude Code plugin for systematic design improvement",
|
|
5
5
|
"author": "Hegemon",
|
|
6
6
|
"homepage": "https://github.com/hegemonart/get-design-done",
|
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
88
88
|
},
|
|
89
89
|
"optionalDependencies": {
|
|
90
|
+
"pngjs": "^7.0.0",
|
|
90
91
|
"ws": "^8.20.0"
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "planner-decision.schema.json",
|
|
4
|
+
"title": "Planner Decision Output Contract",
|
|
5
|
+
"description": "Schema for the structured JSON block emitted by design-planner. Lets /gdd:synthesize and downstream consumers (executor, audit aggregator) read planner output without regex-parsing markdown.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["schema_version", "plan_id", "tasks", "waves"],
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"schema_version": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"const": "1.0.0"
|
|
13
|
+
},
|
|
14
|
+
"plan_id": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Stable identifier — e.g. '23-04' or 'PLAN.md'.",
|
|
17
|
+
"minLength": 1
|
|
18
|
+
},
|
|
19
|
+
"generated_at": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"format": "date-time"
|
|
22
|
+
},
|
|
23
|
+
"tasks": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"minItems": 1,
|
|
26
|
+
"items": {
|
|
27
|
+
"type": "object",
|
|
28
|
+
"required": ["task_id", "summary", "touches"],
|
|
29
|
+
"additionalProperties": false,
|
|
30
|
+
"properties": {
|
|
31
|
+
"task_id": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"minLength": 1,
|
|
34
|
+
"description": "Stable per-plan task identifier (e.g. T-01, 23-04-T-1)."
|
|
35
|
+
},
|
|
36
|
+
"summary": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"minLength": 3
|
|
39
|
+
},
|
|
40
|
+
"touches": {
|
|
41
|
+
"type": "array",
|
|
42
|
+
"items": { "type": "string" },
|
|
43
|
+
"description": "File globs the task is expected to read or write."
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"type": "array",
|
|
47
|
+
"items": { "type": "string" },
|
|
48
|
+
"description": "Other task_ids that must complete first.",
|
|
49
|
+
"default": []
|
|
50
|
+
},
|
|
51
|
+
"parallel_safe": {
|
|
52
|
+
"type": "boolean",
|
|
53
|
+
"description": "Hint from the planner — the parallelism decision engine confirms via Touches: analysis.",
|
|
54
|
+
"default": false
|
|
55
|
+
},
|
|
56
|
+
"estimated_minutes": {
|
|
57
|
+
"type": "number",
|
|
58
|
+
"minimum": 0,
|
|
59
|
+
"description": "Rough wall-clock estimate; consumed by budget allocator."
|
|
60
|
+
},
|
|
61
|
+
"acceptance": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "Free-form acceptance criteria copy."
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"waves": {
|
|
69
|
+
"type": "array",
|
|
70
|
+
"minItems": 1,
|
|
71
|
+
"items": {
|
|
72
|
+
"type": "object",
|
|
73
|
+
"required": ["wave", "task_ids"],
|
|
74
|
+
"additionalProperties": false,
|
|
75
|
+
"properties": {
|
|
76
|
+
"wave": {
|
|
77
|
+
"type": "string",
|
|
78
|
+
"minLength": 1,
|
|
79
|
+
"description": "Wave label (e.g. 'A', 'B', 'C')."
|
|
80
|
+
},
|
|
81
|
+
"task_ids": {
|
|
82
|
+
"type": "array",
|
|
83
|
+
"items": { "type": "string" },
|
|
84
|
+
"minItems": 1
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"rationale": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"description": "Free-form planner-side rationale — not consumed by code."
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "verifier-decision.schema.json",
|
|
4
|
+
"title": "Verifier Decision Output Contract",
|
|
5
|
+
"description": "Schema for the structured JSON block emitted by design-verifier. Drives executor↔verifier ping-pong with a typed envelope rather than free-form prose.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["schema_version", "verdict", "gaps", "must_fix_before_ship", "confidence"],
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"schema_version": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"const": "1.0.0"
|
|
13
|
+
},
|
|
14
|
+
"generated_at": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"format": "date-time"
|
|
17
|
+
},
|
|
18
|
+
"verdict": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"enum": ["pass", "fail", "gap"],
|
|
21
|
+
"description": "pass = ship-ready, gap = remediable, fail = re-plan."
|
|
22
|
+
},
|
|
23
|
+
"gaps": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"items": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"required": ["id", "severity", "area", "summary"],
|
|
28
|
+
"additionalProperties": false,
|
|
29
|
+
"properties": {
|
|
30
|
+
"id": { "type": "string", "minLength": 1 },
|
|
31
|
+
"severity": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"enum": ["P0", "P1", "P2", "P3"]
|
|
34
|
+
},
|
|
35
|
+
"area": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Free-form domain tag — e.g. 'a11y', 'motion', 'tokens'."
|
|
38
|
+
},
|
|
39
|
+
"summary": { "type": "string", "minLength": 3 },
|
|
40
|
+
"evidence": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "Citation: file:line reference or audit excerpt."
|
|
43
|
+
},
|
|
44
|
+
"remediation": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"description": "One-line proposed fix."
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"must_fix_before_ship": {
|
|
52
|
+
"type": "array",
|
|
53
|
+
"items": { "type": "string" },
|
|
54
|
+
"description": "Subset of gap.id values that block ship — typically the P0/P1 ones."
|
|
55
|
+
},
|
|
56
|
+
"confidence": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"enum": ["high", "med", "low"],
|
|
59
|
+
"description": "Verifier's self-rated confidence — drives whether to escalate to a second pass."
|
|
60
|
+
},
|
|
61
|
+
"rationale": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "Free-form notes — not code-consumed."
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* audit-aggregator/index.cjs — dedup + score + rank findings from N
|
|
3
|
+
* audit-agents (Plan 23-04).
|
|
4
|
+
*
|
|
5
|
+
* Replaces the prompt-only "trust the agent's score" pattern with a
|
|
6
|
+
* deterministic scoring + dedup function that downstream tooling
|
|
7
|
+
* (`/gdd:audit`, `/gdd:reflect`) can rely on.
|
|
8
|
+
*
|
|
9
|
+
* Dedup key: `${lowercased(normalizePath(file))}::${line ?? 0}::${rule_id}`.
|
|
10
|
+
* Survivor selection on collision:
|
|
11
|
+
* 1. higher confidence wins
|
|
12
|
+
* 2. tie → higher severity (P0 > P1 > P2 > P3)
|
|
13
|
+
* 3. tie → lexicographically earliest agent
|
|
14
|
+
* 4. tie → first-seen
|
|
15
|
+
*
|
|
16
|
+
* Score = severityWeight(severity) * confidence.
|
|
17
|
+
*
|
|
18
|
+
* No external deps. CommonJS to match the rest of scripts/lib/.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
'use strict';
|
|
22
|
+
|
|
23
|
+
const SEVERITY_RANK = { P0: 4, P1: 3, P2: 2, P3: 1 };
|
|
24
|
+
const DEFAULT_WEIGHTS = Object.freeze({ P0: 8, P1: 4, P2: 2, P3: 1 });
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} Finding
|
|
28
|
+
* @property {string} file
|
|
29
|
+
* @property {number} [line]
|
|
30
|
+
* @property {string} rule_id
|
|
31
|
+
* @property {'P0'|'P1'|'P2'|'P3'} severity
|
|
32
|
+
* @property {string} summary
|
|
33
|
+
* @property {string} [evidence]
|
|
34
|
+
* @property {string} [agent]
|
|
35
|
+
* @property {number} [confidence]
|
|
36
|
+
* @property {string[]} [merged_from]
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {Object} AggregateResult
|
|
41
|
+
* @property {Finding[]} findings
|
|
42
|
+
* @property {Object<string, number>} byRule
|
|
43
|
+
* @property {Object<string, number>} bySeverity
|
|
44
|
+
* @property {Object<string, number>} byFile
|
|
45
|
+
* @property {number} total
|
|
46
|
+
* @property {number} duplicates
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {Object} AggregateOptions
|
|
51
|
+
* @property {number} [topN]
|
|
52
|
+
* @property {Object<string, number>} [severityWeights]
|
|
53
|
+
* @property {(a: Finding, b: Finding) => Finding} [merge]
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
function normalizePath(p) {
|
|
57
|
+
return String(p).replace(/\\/g, '/').toLowerCase();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let _confidenceWarningEmitted = false;
|
|
61
|
+
|
|
62
|
+
function clampConfidence(c) {
|
|
63
|
+
if (c === undefined || c === null) return 1;
|
|
64
|
+
if (typeof c !== 'number' || Number.isNaN(c)) return 1;
|
|
65
|
+
if (c < 0) {
|
|
66
|
+
if (!_confidenceWarningEmitted) {
|
|
67
|
+
process.emitWarning('audit-aggregator: confidence < 0 clamped to 0', 'AuditAggregator');
|
|
68
|
+
_confidenceWarningEmitted = true;
|
|
69
|
+
}
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
if (c > 1) {
|
|
73
|
+
if (!_confidenceWarningEmitted) {
|
|
74
|
+
process.emitWarning('audit-aggregator: confidence > 1 clamped to 1', 'AuditAggregator');
|
|
75
|
+
_confidenceWarningEmitted = true;
|
|
76
|
+
}
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
return c;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Compute score for a finding.
|
|
84
|
+
*
|
|
85
|
+
* @param {Finding} f
|
|
86
|
+
* @param {Object<string, number>} weights
|
|
87
|
+
* @returns {number}
|
|
88
|
+
*/
|
|
89
|
+
function score(f, weights) {
|
|
90
|
+
const w = (weights && weights[f.severity]) ?? DEFAULT_WEIGHTS[f.severity] ?? 0;
|
|
91
|
+
return w * clampConfidence(f.confidence);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function validateFinding(f, idx) {
|
|
95
|
+
if (!f || typeof f !== 'object') {
|
|
96
|
+
throw new TypeError(`audit-aggregator: input[${idx}] is not an object`);
|
|
97
|
+
}
|
|
98
|
+
if (typeof f.file !== 'string' || f.file.length === 0) {
|
|
99
|
+
throw new TypeError(`audit-aggregator: input[${idx}].file is required (non-empty string)`);
|
|
100
|
+
}
|
|
101
|
+
if (typeof f.rule_id !== 'string' || f.rule_id.length === 0) {
|
|
102
|
+
throw new TypeError(`audit-aggregator: input[${idx}].rule_id is required (non-empty string)`);
|
|
103
|
+
}
|
|
104
|
+
if (!(f.severity in SEVERITY_RANK)) {
|
|
105
|
+
throw new TypeError(
|
|
106
|
+
`audit-aggregator: input[${idx}].severity must be P0|P1|P2|P3 (got ${JSON.stringify(f.severity)})`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function dedupKey(f) {
|
|
112
|
+
return `${normalizePath(f.file)}::${f.line ?? 0}::${f.rule_id}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function defaultMerge(a, b) {
|
|
116
|
+
// Higher confidence wins.
|
|
117
|
+
const ca = clampConfidence(a.confidence);
|
|
118
|
+
const cb = clampConfidence(b.confidence);
|
|
119
|
+
if (ca !== cb) return ca > cb ? a : b;
|
|
120
|
+
// Higher severity wins.
|
|
121
|
+
const ra = SEVERITY_RANK[a.severity];
|
|
122
|
+
const rb = SEVERITY_RANK[b.severity];
|
|
123
|
+
if (ra !== rb) return ra > rb ? a : b;
|
|
124
|
+
// Lexicographic agent.
|
|
125
|
+
const aa = a.agent ?? '';
|
|
126
|
+
const ab = b.agent ?? '';
|
|
127
|
+
if (aa !== ab) return aa < ab ? a : b;
|
|
128
|
+
// First-seen wins (a is by convention the existing entry).
|
|
129
|
+
return a;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Aggregate findings.
|
|
134
|
+
*
|
|
135
|
+
* @param {Finding[]} input
|
|
136
|
+
* @param {AggregateOptions} [opts]
|
|
137
|
+
* @returns {AggregateResult}
|
|
138
|
+
*/
|
|
139
|
+
function aggregate(input, opts = {}) {
|
|
140
|
+
if (!Array.isArray(input)) {
|
|
141
|
+
throw new TypeError('audit-aggregator: input must be an array');
|
|
142
|
+
}
|
|
143
|
+
// Reset the once-per-call warning flag so a second call can warn again.
|
|
144
|
+
_confidenceWarningEmitted = false;
|
|
145
|
+
const merge = typeof opts.merge === 'function' ? opts.merge : defaultMerge;
|
|
146
|
+
const weights = { ...DEFAULT_WEIGHTS, ...(opts.severityWeights || {}) };
|
|
147
|
+
|
|
148
|
+
/** @type {Map<string, Finding>} */
|
|
149
|
+
const byKey = new Map();
|
|
150
|
+
let duplicates = 0;
|
|
151
|
+
for (let i = 0; i < input.length; i++) {
|
|
152
|
+
validateFinding(input[i], i);
|
|
153
|
+
const f = { ...input[i] };
|
|
154
|
+
const key = dedupKey(f);
|
|
155
|
+
if (byKey.has(key)) {
|
|
156
|
+
duplicates += 1;
|
|
157
|
+
const existing = byKey.get(key);
|
|
158
|
+
const winner = merge(existing, f);
|
|
159
|
+
const loser = winner === existing ? f : existing;
|
|
160
|
+
const mergedFrom = new Set(winner.merged_from || []);
|
|
161
|
+
if (existing.agent && existing !== winner) mergedFrom.add(existing.agent);
|
|
162
|
+
if (loser.agent && loser !== winner) mergedFrom.add(loser.agent);
|
|
163
|
+
// Combine prior merged_from too.
|
|
164
|
+
for (const a of (loser.merged_from || [])) mergedFrom.add(a);
|
|
165
|
+
winner.merged_from = Array.from(mergedFrom);
|
|
166
|
+
byKey.set(key, winner);
|
|
167
|
+
} else {
|
|
168
|
+
byKey.set(key, f);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const findings = Array.from(byKey.values()).map((f) => ({ ...f, _score: score(f, weights) }));
|
|
173
|
+
findings.sort((a, b) => {
|
|
174
|
+
if (a._score !== b._score) return b._score - a._score;
|
|
175
|
+
const ra = SEVERITY_RANK[a.severity];
|
|
176
|
+
const rb = SEVERITY_RANK[b.severity];
|
|
177
|
+
if (ra !== rb) return rb - ra;
|
|
178
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
179
|
+
return (a.line ?? 0) - (b.line ?? 0);
|
|
180
|
+
});
|
|
181
|
+
// Strip the internal _score field before returning.
|
|
182
|
+
for (const f of findings) delete f._score;
|
|
183
|
+
|
|
184
|
+
const truncated = typeof opts.topN === 'number' && opts.topN >= 0
|
|
185
|
+
? findings.slice(0, opts.topN)
|
|
186
|
+
: findings;
|
|
187
|
+
|
|
188
|
+
/** @type {Record<string, number>} */
|
|
189
|
+
const byRule = {};
|
|
190
|
+
/** @type {Record<string, number>} */
|
|
191
|
+
const bySeverity = { P0: 0, P1: 0, P2: 0, P3: 0 };
|
|
192
|
+
/** @type {Record<string, number>} */
|
|
193
|
+
const byFile = {};
|
|
194
|
+
for (const f of truncated) {
|
|
195
|
+
byRule[f.rule_id] = (byRule[f.rule_id] ?? 0) + 1;
|
|
196
|
+
bySeverity[f.severity] += 1;
|
|
197
|
+
const k = normalizePath(f.file);
|
|
198
|
+
byFile[k] = (byFile[k] ?? 0) + 1;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
findings: truncated,
|
|
203
|
+
byRule,
|
|
204
|
+
bySeverity,
|
|
205
|
+
byFile,
|
|
206
|
+
total: truncated.length,
|
|
207
|
+
duplicates,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = {
|
|
212
|
+
aggregate,
|
|
213
|
+
score,
|
|
214
|
+
normalizePath,
|
|
215
|
+
dedupKey,
|
|
216
|
+
defaultMerge,
|
|
217
|
+
DEFAULT_WEIGHTS,
|
|
218
|
+
SEVERITY_RANK,
|
|
219
|
+
};
|