rungate 0.2.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/agents/aditi.md +47 -0
- package/.claude/agents/marcus.md +50 -0
- package/.claude/agents/quinn.md +58 -0
- package/.claude/agents/rook.md +47 -0
- package/.claude/agents/serena.md +46 -0
- package/.claude/rungate.json +11 -0
- package/.fallowrc.json +28 -0
- package/.github/copilot-instructions.md +20 -0
- package/.rungate/conformity-findings.json +648 -0
- package/AGENTS.md +106 -0
- package/CODE-MAP.md +50 -0
- package/HARNESS.md +88 -0
- package/bun.lock +26 -0
- package/bunfig.toml +2 -0
- package/config/brief-policies.json +28 -0
- package/config/ceremony-profiles.json +212 -0
- package/config/consumer-cascade-map.json +24 -0
- package/config/doc-cascade-map.json +24 -0
- package/config/eval.json +84 -0
- package/config/profiles/account-plan.yaml +36 -0
- package/config/profiles/campaign.yaml +94 -0
- package/config/prove-evidence.schema.json +65 -0
- package/config/spec-policies.json +36 -0
- package/config/workflow-schema.json +281 -0
- package/gates/SCHEMA-GUIDE.md +121 -0
- package/gates/ac-quality.test.ts +106 -0
- package/gates/adversarial.test.ts +274 -0
- package/gates/brief-assembler.test.ts +429 -0
- package/gates/brief-assembler.ts +334 -0
- package/gates/bunfig.toml +2 -0
- package/gates/chain.test.ts +91 -0
- package/gates/e2e-smoke.test.ts +234 -0
- package/gates/error-classifier.test.ts +249 -0
- package/gates/error-classifier.ts +89 -0
- package/gates/orchestrator.test.ts +950 -0
- package/gates/orchestrator.ts +569 -0
- package/gates/preload.ts +77 -0
- package/gates/prompts/ac-adversary.md +20 -0
- package/gates/prompts/evidence-validator.md +22 -0
- package/gates/prompts/prove-reproducer.md +53 -0
- package/gates/prove.test.ts +164 -0
- package/gates/run-gate.ts +936 -0
- package/gates/schema-parity.test.ts +197 -0
- package/gates/schema.ts +362 -0
- package/gates/self-heal.test.ts +511 -0
- package/gates/self-heal.ts +121 -0
- package/gates/ship-orchestrator.test.ts +379 -0
- package/gates/ship-orchestrator.ts +363 -0
- package/gates/test-fixtures/broken-no-environments.json +60 -0
- package/gates/test-fixtures/valid-standard.json +54 -0
- package/gates/test-utils.ts +43 -0
- package/gates/witness.ts +220 -0
- package/gates/workflow.test.ts +1053 -0
- package/hooks/AgentBriefGuard.hook.ts +586 -0
- package/hooks/AgentVerdictCapture.hook.ts +134 -0
- package/hooks/AutoVerifyGate.hook.ts +76 -0
- package/hooks/GateEnforcement.hook.ts +273 -0
- package/hooks/IssueCloseGuard.hook.ts +116 -0
- package/hooks/MergeGuard.hook.ts +55 -0
- package/hooks/StaleTTLCleanup.hook.ts +133 -0
- package/hooks/VerifyPhaseLock.hook.ts +81 -0
- package/hooks/WorkflowStateGuard.hook.ts +37 -0
- package/hooks/lib/agentDetection.ts +70 -0
- package/hooks/lib/findWorkflow.ts +101 -0
- package/hooks/lib/parseStdin.ts +37 -0
- package/hooks/lib/paths.ts +111 -0
- package/hooks/lib/utils.ts +81 -0
- package/lib/conformity.ts +959 -0
- package/lib/paths.ts +23 -0
- package/lib/rungate-schema.ts +60 -0
- package/lib/signal-phrases.ts +7 -0
- package/package.json +20 -0
- package/prompts/ac-adversary.md +20 -0
- package/prompts/ac-format.md +34 -0
- package/prompts/aditi.md +29 -0
- package/prompts/blast-radius.md +29 -0
- package/prompts/coding-principles.md +34 -0
- package/prompts/container-rebuild.md +29 -0
- package/prompts/container-verify.md +28 -0
- package/prompts/discovery.md +27 -0
- package/prompts/environment.md +28 -0
- package/prompts/escalation-decision-tree.md +38 -0
- package/prompts/evidence-hierarchy.md +31 -0
- package/prompts/evidence-validator.md +22 -0
- package/prompts/marcus.md +29 -0
- package/prompts/prevention.md +26 -0
- package/prompts/prove-reproducer.md +43 -0
- package/prompts/quinn-decision-tree.md +31 -0
- package/prompts/quinn-ui-brief.md +106 -0
- package/prompts/quinn.md +29 -0
- package/prompts/rca.md +28 -0
- package/prompts/read-before-write.md +30 -0
- package/prompts/regression.md +26 -0
- package/prompts/rook.md +29 -0
- package/prompts/serena.md +28 -0
- package/prompts/testing-strategy.md +34 -0
- package/reference/migration-manifest.json +554 -0
- package/reference/prompts/agent-aditi.md +38 -0
- package/reference/prompts/agent-marcus.md +38 -0
- package/reference/prompts/agent-quinn.md +38 -0
- package/reference/prompts/agent-rook.md +37 -0
- package/reference/prompts/agent-serena.md +37 -0
- package/reference/prompts/council-skill.md +170 -0
- package/reference/prompts/goal-skill.md +235 -0
- package/reference/prompts/prove-skill.md +283 -0
- package/reference/prompts/quinn-standard.md +246 -0
- package/reference/prompts/ship-convergence.md +65 -0
- package/reference/prompts/ship-escalation.md +43 -0
- package/reference/prompts/ship-iteration.md +382 -0
- package/reference/prompts/ship-pending-patches.md +246 -0
- package/reference/prompts/ship-reference.md +250 -0
- package/reference/prompts/ship-skill.md +347 -0
- package/reference/prompts/ship-templates.md +215 -0
- package/reference/scripts/batch-status.sh +68 -0
- package/reference/scripts/chain-compat-check.sh +67 -0
- package/reference/scripts/context-audit.sh +314 -0
- package/reference/scripts/dead-export-check.sh +61 -0
- package/reference/scripts/generate-qc-tables.sh +92 -0
- package/reference/scripts/harness-init.sh +111 -0
- package/reference/scripts/pai-054-baseline-check.sh +40 -0
- package/reference/scripts/prove-smoke-test.sh +112 -0
- package/reference/scripts/setup-keychain-salt.sh +12 -0
- package/reference/scripts/skill-optimizer-friday.sh +88 -0
- package/reference/scripts/skill-qc-test.sh +351 -0
- package/reference/scripts/skill-synthesize-tonight.sh +66 -0
- package/reference/specs/HARNESS-EXTRACTION-SPEC.md +263 -0
- package/reference/specs/harness-v3-bash-deletion-plan.md +65 -0
- package/reference/specs/harness-v3-migration-plan.md +188 -0
- package/scripts/decision-reconcile.sh +74 -0
- package/scripts/decision-reconcile.ts +152 -0
- package/scripts/extract-constraints.ts +260 -0
- package/scripts/generate-code-map.ts +339 -0
- package/scripts/git-hooks/pre-commit +76 -0
- package/scripts/git-hooks/pre-push +271 -0
- package/scripts/harness-skill-check.sh +52 -0
- package/scripts/lib/gap-emit.sh +65 -0
- package/scripts/lib/jq-update.sh +30 -0
- package/scripts/lib/resolve-slug.sh +30 -0
- package/scripts/lib/verify-spec-compliance.sh +102 -0
- package/scripts/prove-backfill.sh +87 -0
- package/scripts/scaffold-project.ts +1488 -0
- package/scripts/scaffold-rungate-config.ts +91 -0
- package/scripts/self-containment-check.sh +109 -0
- package/scripts/skill-qc-validator.sh +402 -0
- package/scripts/slug-resolver.sh +14 -0
- package/scripts/sync-spec-tests.ts +236 -0
- package/specs/BOOTSTRAP-DATA-FLOW-SPEC.md +2493 -0
- package/specs/BOOTSTRAP-TEST-PLAN.md +571 -0
- package/specs/HARNESS-GATES.md +256 -0
- package/specs/HARNESS-SKILL-CHAIN.md +286 -0
- package/specs/HARNESS-SKILL-CONTRACT.md +93 -0
- package/specs/HARNESS-STANDARD.md +488 -0
- package/specs/SPEC-TEMPLATE.md +53 -0
- package/specs/bootstrap-data-flow.png +0 -0
- package/specs/harness-automation-matrix.md +314 -0
- package/specs/harness-automation-matrix.rules.json +64 -0
- package/test/anti.test.ts +80 -0
- package/test/contract-negative.test.ts +86 -0
- package/test/contract.test.ts +158 -0
- package/test/external-deps.test.ts +48 -0
- package/test/fixtures/golden-project/.env.example +3 -0
- package/test/fixtures/golden-project/Makefile +7 -0
- package/test/fixtures/golden-project/docs/adr/ADR-001-framework.md +23 -0
- package/test/fixtures/golden-project/docs/setup-guide.md +10 -0
- package/test/fixtures/golden-project/package.json +10 -0
- package/test/fixtures/golden-project/specs/api-spec.md +20 -0
- package/test/fixtures/golden-project/src/auth.ts +8 -0
- package/test/fixtures/golden-project/src/db.ts +11 -0
- package/test/fixtures/golden-project/src/index.ts +19 -0
- package/test/fixtures/golden-project/src/utils/format.ts +3 -0
- package/test/fixtures/golden-project/test/auth.test.ts +15 -0
- package/test/fixtures/golden-project/tsconfig.json +12 -0
- package/test/meta-sc-coverage.test.ts +159 -0
- package/test/phase-0.test.ts +846 -0
- package/test/phase-1.test.ts +617 -0
- package/test/phase-2.test.ts +620 -0
- package/test/phase-3.test.ts +99 -0
- package/test/scaffold-conformity.test.ts +8 -0
- package/test/schema-canary.test.ts +51 -0
- package/test/spec-compliance-auto.test.ts +64 -0
- package/test/spec-compliance.test.ts +295 -0
- package/test/spec-discovery.test.ts +68 -0
- package/test/spec-drift.test.ts +5 -0
- package/test/structure.test.ts +165 -0
- package/test/unit/agent-brief-guard-ship.test.ts +293 -0
- package/test/unit/extract-constraints.test.ts +145 -0
- package/test/unit/issue-close-guard.test.ts +204 -0
- package/test/unit/scaffold-project.test.ts +417 -0
- package/test/unit/skill-cooccurrence.test.ts +177 -0
- package/test/unit/skill-sequence-logger.test.ts +244 -0
- package/test/unit/workflow-state-guard.test.ts +95 -0
- package/workflows/batch-ship.js +295 -0
- package/workflows/council.js +481 -0
- package/workflows/prove.js +560 -0
- package/workflows/ship.js +789 -0
- package/workflows/verify.js +236 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { test, expect, describe } from "bun:test";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { THRESHOLD_OPS, EVIDENCE_METHOD_TYPES } from "./schema";
|
|
5
|
+
import { parseTestResults } from "./run-gate";
|
|
6
|
+
|
|
7
|
+
const GATES_DIR = __dirname;
|
|
8
|
+
const V2_SCHEMA_PATH = join(GATES_DIR, "..", "config", "workflow-schema.json");
|
|
9
|
+
const V3_SCHEMA_PATH = join(GATES_DIR, "schema.ts");
|
|
10
|
+
|
|
11
|
+
function extractJsonSchemaPaths(obj: any, prefix = ""): string[] {
|
|
12
|
+
const paths: string[] = [];
|
|
13
|
+
if (!obj || typeof obj !== "object") return paths;
|
|
14
|
+
|
|
15
|
+
if (obj.properties) {
|
|
16
|
+
for (const [key, val] of Object.entries(obj.properties)) {
|
|
17
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
18
|
+
paths.push(path);
|
|
19
|
+
if ((val as any).properties) {
|
|
20
|
+
paths.push(...extractJsonSchemaPaths(val, path));
|
|
21
|
+
}
|
|
22
|
+
if ((val as any).items?.properties) {
|
|
23
|
+
paths.push(...extractJsonSchemaPaths((val as any).items, `${path}[]`));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return paths;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function extractZodFields(source: string): string[] {
|
|
31
|
+
const fields: string[] = [];
|
|
32
|
+
const patterns = [
|
|
33
|
+
/(\w+):\s*z\./g,
|
|
34
|
+
/(\w+):\s*(?:Agent|Environment|GateResult|SourceSpec|Threshold|EvidenceMethod|Evidence|ContextFile|Changelog|PhaseTiming)/g,
|
|
35
|
+
];
|
|
36
|
+
for (const p of patterns) {
|
|
37
|
+
for (const m of source.matchAll(p)) {
|
|
38
|
+
fields.push(m[1]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return [...new Set(fields)];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe("schema parity: v2 JSON Schema vs v3 Zod", () => {
|
|
45
|
+
const v2 = JSON.parse(readFileSync(V2_SCHEMA_PATH, "utf-8"));
|
|
46
|
+
const v3Source = readFileSync(V3_SCHEMA_PATH, "utf-8");
|
|
47
|
+
|
|
48
|
+
const v2Paths = extractJsonSchemaPaths(v2);
|
|
49
|
+
const v3Fields = extractZodFields(v3Source);
|
|
50
|
+
|
|
51
|
+
const V2_TOP_LEVEL = [
|
|
52
|
+
"schemaVersion", "issue", "repo", "issueRepo", "projectRoot", "slug", "phase",
|
|
53
|
+
"issueGoal", "sourceSpecs", "sizing", "acs", "agents", "environments", "gates",
|
|
54
|
+
"daDirectEdits", "iterationCount", "startTs", "updatedTs", "phaseTimings",
|
|
55
|
+
"gateContract", "changelog",
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
for (const field of V2_TOP_LEVEL) {
|
|
59
|
+
test(`v2 top-level field "${field}" exists in v3 Zod schema`, () => {
|
|
60
|
+
expect(v3Source).toContain(field);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const V2_SIZING = ["predicted", "ceremonyTier", "actualFiles", "actualMinutes"];
|
|
65
|
+
for (const field of V2_SIZING) {
|
|
66
|
+
test(`v2 sizing.${field} exists in v3`, () => {
|
|
67
|
+
expect(v3Source).toContain(field);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const V2_AC_FIELDS = ["id", "type", "statement", "specElement", "threshold", "evidenceMethod", "contextFiles", "evidence", "verdict"];
|
|
72
|
+
for (const field of V2_AC_FIELDS) {
|
|
73
|
+
test(`v2 acs[].${field} exists in v3 ACSchema`, () => {
|
|
74
|
+
expect(v3Source).toContain(field);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const V2_AGENT_FIELDS = ["spawned", "verdict", "branch", "iterations", "comparedToSpec", "screenshots", "findings"];
|
|
79
|
+
for (const field of V2_AGENT_FIELDS) {
|
|
80
|
+
test(`v2 agents.*.${field} exists in v3 AgentSchema`, () => {
|
|
81
|
+
expect(v3Source).toContain(field);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const V2_ENV_LOCAL = ["api", "apiSkipReason", "ui", "uiSkipReason", "tests"];
|
|
86
|
+
for (const field of V2_ENV_LOCAL) {
|
|
87
|
+
test(`v2 environments.local.${field} exists in v3`, () => {
|
|
88
|
+
expect(v3Source).toContain(field);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const V2_ENV_PROD = ["rebuild", "rebuildSkipReason", "smoke", "smokeSkipReason", "quinn", "quinnSkipReason", "quinnSpot", "quinnSpotSkipReason"];
|
|
93
|
+
for (const field of V2_ENV_PROD) {
|
|
94
|
+
test(`v2 environments.prod.${field} exists in v3`, () => {
|
|
95
|
+
expect(v3Source).toContain(field);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const V2_GATE = ["result", "attempt", "failures", "ts"];
|
|
100
|
+
for (const field of V2_GATE) {
|
|
101
|
+
test(`v2 gates.*.${field} exists in v3 GateResultSchema`, () => {
|
|
102
|
+
expect(v3Source).toContain(field);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const V2_EVIDENCE_METHOD_TYPES = ["GREP_CHECK", "FILE_EXISTS", "CURL_CHECK", "BUN_TEST", "SCREENSHOT", "PLAYWRIGHT", "COMMAND", "MANUAL"];
|
|
107
|
+
for (const t of V2_EVIDENCE_METHOD_TYPES) {
|
|
108
|
+
test(`v2 evidenceMethod.type "${t}" in v3 enum`, () => {
|
|
109
|
+
expect(v3Source).toContain(t);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const V2_THRESHOLD_OPS = ["==", ">=", "<=", ">", "<", "!=", "contains", "exists"];
|
|
114
|
+
for (const op of V2_THRESHOLD_OPS) {
|
|
115
|
+
test(`v2 threshold.op "${op}" in v3 enum`, () => {
|
|
116
|
+
expect(v3Source).toContain(`"${op}"`);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
test("v2 phase CIRCUIT_BREAK in v3 enum", () => {
|
|
121
|
+
expect(v3Source).toContain("CIRCUIT_BREAK");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("v2 verdict PENDING in v3 ACSchema", () => {
|
|
125
|
+
expect(v3Source).toContain("PENDING");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const V2_BASELINES = ["testBaseline", "tscBaseline"];
|
|
129
|
+
for (const field of V2_BASELINES) {
|
|
130
|
+
test(`v2 gateContract.baselines.${field} exists in v3`, () => {
|
|
131
|
+
expect(v3Source).toContain(field);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const V2_CHANGELOG = ["event", "detail", "actor"];
|
|
136
|
+
for (const field of V2_CHANGELOG) {
|
|
137
|
+
test(`v2 changelog[].${field} exists in v3`, () => {
|
|
138
|
+
expect(v3Source).toContain(field);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
test("v2 phaseTimings entry fields in v3", () => {
|
|
143
|
+
expect(v3Source).toContain("enteredTs");
|
|
144
|
+
expect(v3Source).toContain("exitedTs");
|
|
145
|
+
expect(v3Source).toContain("iteration");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("GI-1: gate failure detail includes Zod error paths", () => {
|
|
150
|
+
test("parseTestResults captures lines after (fail) as detail", () => {
|
|
151
|
+
const bunOutput = [
|
|
152
|
+
"(pass) schema validation > acs-exist: at least one AC",
|
|
153
|
+
"(fail) schema validation > workflow-state.json validates (includes threshold + behavioral superRefine)",
|
|
154
|
+
" acs.0.threshold.op: Invalid enum value. Expected '==' | '>=' | '<=' | '>' | '<' | '!=' | 'contains' | 'exists', received 'equals'",
|
|
155
|
+
" acs.1.statement: AC-2: statement too short (3 words, min 5)",
|
|
156
|
+
"(pass) scope checks > sizing-declared",
|
|
157
|
+
].join("\n");
|
|
158
|
+
const results = parseTestResults(bunOutput);
|
|
159
|
+
const fail = results.find(r => r.result === "FAIL");
|
|
160
|
+
expect(fail).toBeTruthy();
|
|
161
|
+
expect(fail!.detail).toContain("Invalid enum value");
|
|
162
|
+
expect(fail!.detail).toContain("acs.0.threshold.op");
|
|
163
|
+
expect(fail!.detail).not.toBe("failed");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("parseTestResults falls back to 'failed' when no detail lines follow (fail)", () => {
|
|
167
|
+
const bunOutput = [
|
|
168
|
+
"(fail) some-check",
|
|
169
|
+
"(pass) another-check",
|
|
170
|
+
].join("\n");
|
|
171
|
+
const results = parseTestResults(bunOutput);
|
|
172
|
+
const fail = results.find(r => r.result === "FAIL");
|
|
173
|
+
expect(fail!.detail).toBe("failed");
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe("GI-5: DISCOVERY_SCHEMA enum parity with schema.ts", () => {
|
|
178
|
+
const shipSource = readFileSync(join(GATES_DIR, "..", "workflows", "ship.js"), "utf-8");
|
|
179
|
+
|
|
180
|
+
test("DISCOVERY_SCHEMA threshold.op has enum matching THRESHOLD_OPS", () => {
|
|
181
|
+
const opEnumMatch = shipSource.match(/op:\s*\{\s*type:\s*'string'\s*,\s*enum:\s*\[([^\]]+)\]/);
|
|
182
|
+
expect(opEnumMatch, "threshold.op must have enum constraint in DISCOVERY_SCHEMA").toBeTruthy();
|
|
183
|
+
const ops = opEnumMatch![1].split(",").map(s => s.trim().replace(/'/g, ""));
|
|
184
|
+
expect(ops.sort()).toEqual([...THRESHOLD_OPS].sort());
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("DISCOVERY_SCHEMA evidenceMethod.type has enum matching EVIDENCE_METHOD_TYPES", () => {
|
|
188
|
+
const discoveryBlock = shipSource.slice(
|
|
189
|
+
shipSource.indexOf("const DISCOVERY_SCHEMA"),
|
|
190
|
+
shipSource.indexOf("const DISCOVERY_SCHEMA") + 3000
|
|
191
|
+
);
|
|
192
|
+
const evidenceMethodMatch = discoveryBlock.match(/evidenceMethod:\s*\{[^}]*properties:\s*\{[^}]*type:\s*\{\s*type:\s*'string'\s*,\s*enum:\s*\[([^\]]+)\]/s);
|
|
193
|
+
expect(evidenceMethodMatch, "evidenceMethod.type must have enum constraint in DISCOVERY_SCHEMA").toBeTruthy();
|
|
194
|
+
const types = evidenceMethodMatch![1].split(",").map(s => s.trim().replace(/'/g, ""));
|
|
195
|
+
expect(types.sort()).toEqual([...EVIDENCE_METHOD_TYPES].sort());
|
|
196
|
+
});
|
|
197
|
+
});
|
package/gates/schema.ts
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
const BEHAVIORAL_PATTERN = /\b(DA should|remember to|make sure to|don't forget)\b/i;
|
|
4
|
+
|
|
5
|
+
const GARBAGE_PATTERNS = [
|
|
6
|
+
/^file exists?$/i,
|
|
7
|
+
/^it works?$/i,
|
|
8
|
+
/^code is (?:correct|good|done|working)$/i,
|
|
9
|
+
/^(?:the )?(?:feature|function|code|system) (?:works?|exists?|is (?:done|complete))$/i,
|
|
10
|
+
/^no errors?$/i,
|
|
11
|
+
/^tests? pass(?:es)?$/i,
|
|
12
|
+
/^changes? (?:are )?(?:made|applied|done)$/i,
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export const THRESHOLD_OPS = ["==", ">=", "<=", ">", "<", "!=", "contains", "exists"] as const;
|
|
16
|
+
export const EVIDENCE_METHOD_TYPES = ["GREP_CHECK", "FILE_EXISTS", "CURL_CHECK", "BUN_TEST", "SCREENSHOT", "PLAYWRIGHT", "COMMAND", "MANUAL", "grep", "command", "api", "screenshot", "manual"] as const;
|
|
17
|
+
|
|
18
|
+
export const ThresholdSchema = z.object({
|
|
19
|
+
op: z.enum(THRESHOLD_OPS),
|
|
20
|
+
value: z.union([z.string(), z.number()]),
|
|
21
|
+
unit: z.string().optional(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const EvidenceMethodSchema = z.object({
|
|
25
|
+
type: z.enum(EVIDENCE_METHOD_TYPES),
|
|
26
|
+
command: z.string().optional(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const EvidenceSchema = z.object({
|
|
30
|
+
type: z.enum(["file-citation", "grep-output", "api-response", "screenshot", "test-output", "command-output", "manual-attestation"]),
|
|
31
|
+
content: z.string().optional(),
|
|
32
|
+
value: z.number().nullable().optional(),
|
|
33
|
+
url: z.string().nullable().optional(),
|
|
34
|
+
}).nullable().optional();
|
|
35
|
+
|
|
36
|
+
export const ContextFileSchema = z.object({
|
|
37
|
+
path: z.string(),
|
|
38
|
+
lines: z.string().optional(),
|
|
39
|
+
reason: z.string().optional(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const ACSchema = z.object({
|
|
43
|
+
id: z.string(),
|
|
44
|
+
type: z.enum(["CODE", "OUTCOME"]).optional(),
|
|
45
|
+
statement: z.string(),
|
|
46
|
+
specElement: z.string().optional(),
|
|
47
|
+
threshold: ThresholdSchema.optional(),
|
|
48
|
+
evidenceMethod: EvidenceMethodSchema.optional(),
|
|
49
|
+
contextFiles: z.array(ContextFileSchema).optional(),
|
|
50
|
+
evidence: EvidenceSchema,
|
|
51
|
+
verdict: z.enum(["PENDING", "PASS", "FAIL", "SKIP"]).optional(),
|
|
52
|
+
}).superRefine((ac, ctx) => {
|
|
53
|
+
if (!ac.threshold) {
|
|
54
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `${ac.id}: missing threshold`, path: ["threshold"] });
|
|
55
|
+
}
|
|
56
|
+
if (BEHAVIORAL_PATTERN.test(ac.statement)) {
|
|
57
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `${ac.id}: behavioral language "${ac.statement.match(BEHAVIORAL_PATTERN)?.[0]}"`, path: ["statement"] });
|
|
58
|
+
}
|
|
59
|
+
// Heuristic: minimum statement length (5 words)
|
|
60
|
+
const words = ac.statement.split(/\s+/).filter(Boolean);
|
|
61
|
+
if (words.length < 5) {
|
|
62
|
+
ctx.addIssue({
|
|
63
|
+
code: z.ZodIssueCode.custom,
|
|
64
|
+
message: `${ac.id}: statement too short (${words.length} words, min 5)`,
|
|
65
|
+
path: ["statement"],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Heuristic: garbage/tautological statement detection
|
|
69
|
+
for (const pattern of GARBAGE_PATTERNS) {
|
|
70
|
+
if (pattern.test(ac.statement.trim())) {
|
|
71
|
+
ctx.addIssue({
|
|
72
|
+
code: z.ZodIssueCode.custom,
|
|
73
|
+
message: `${ac.id}: tautological/garbage statement "${ac.statement}"`,
|
|
74
|
+
path: ["statement"],
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Heuristic: weak threshold detection
|
|
80
|
+
if (ac.threshold) {
|
|
81
|
+
const numVal = Number(ac.threshold.value);
|
|
82
|
+
if (ac.threshold.op === ">=" && !isNaN(numVal) && numVal <= 1) {
|
|
83
|
+
ctx.addIssue({
|
|
84
|
+
code: z.ZodIssueCode.custom,
|
|
85
|
+
message: `${ac.id}: threshold too weak (${ac.threshold.op} ${ac.threshold.value}) — effectively always passes`,
|
|
86
|
+
path: ["threshold"],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const SourceSpecSchema = z.object({
|
|
93
|
+
path: z.string(),
|
|
94
|
+
citedInDiscovery: z.boolean(),
|
|
95
|
+
specElements: z.array(z.string()).optional(),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const AgentSchema = z.object({
|
|
99
|
+
spawned: z.boolean().optional(),
|
|
100
|
+
verdict: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
101
|
+
branch: z.string().optional(),
|
|
102
|
+
iterations: z.number().optional(),
|
|
103
|
+
comparedToSpec: z.boolean().optional(),
|
|
104
|
+
screenshots: z.array(z.string()).optional(),
|
|
105
|
+
findings: z.string().nullable().optional(),
|
|
106
|
+
testedSha: z.string().optional(),
|
|
107
|
+
testedPaths: z.array(z.string()).optional(),
|
|
108
|
+
port: z.number().optional(),
|
|
109
|
+
}).optional();
|
|
110
|
+
|
|
111
|
+
export const EnvironmentLocalSchema = z.object({
|
|
112
|
+
api: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
113
|
+
apiSkipReason: z.string().optional(),
|
|
114
|
+
ui: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
115
|
+
uiSkipReason: z.string().optional(),
|
|
116
|
+
tests: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
117
|
+
quinn: z.object({
|
|
118
|
+
port: z.number().optional(),
|
|
119
|
+
}).optional(),
|
|
120
|
+
}).optional();
|
|
121
|
+
|
|
122
|
+
export const EnvironmentProdSchema = z.object({
|
|
123
|
+
rebuild: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
124
|
+
rebuildSkipReason: z.string().nullable().optional(),
|
|
125
|
+
smoke: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
126
|
+
smokeSkipReason: z.string().nullable().optional(),
|
|
127
|
+
quinn: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
128
|
+
quinnSkipReason: z.string().nullable().optional(),
|
|
129
|
+
quinnSpot: z.enum(["PASS", "FAIL", "SKIP"]).nullable().optional(),
|
|
130
|
+
quinnSpotSkipReason: z.string().optional(),
|
|
131
|
+
}).optional();
|
|
132
|
+
|
|
133
|
+
export const GateResultSchema = z.object({
|
|
134
|
+
result: z.enum(["PASS", "FAIL"]).nullable().optional(),
|
|
135
|
+
attempt: z.number().optional(),
|
|
136
|
+
failures: z.array(z.any()).optional(),
|
|
137
|
+
ts: z.string().optional(),
|
|
138
|
+
commitSha: z.string().optional(),
|
|
139
|
+
}).optional();
|
|
140
|
+
|
|
141
|
+
export const PhaseTimingEntry = z.object({
|
|
142
|
+
enteredTs: z.string(),
|
|
143
|
+
exitedTs: z.string().optional(),
|
|
144
|
+
iteration: z.number().optional(),
|
|
145
|
+
source: z.enum(["gate-runner", "DA"]),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
export const ChangelogEntry = z.object({
|
|
149
|
+
ts: z.string(),
|
|
150
|
+
event: z.string(),
|
|
151
|
+
detail: z.string().optional(),
|
|
152
|
+
phase: z.string().optional(),
|
|
153
|
+
actor: z.enum(["da", "marcus", "quinn", "rook", "gate-runner", "ship-workflow"]).optional(),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export const WorkflowStateSchema = z.object({
|
|
157
|
+
schemaVersion: z.literal(2),
|
|
158
|
+
issue: z.number(),
|
|
159
|
+
repo: z.string().optional(),
|
|
160
|
+
issueRepo: z.string().optional(),
|
|
161
|
+
projectRoot: z.string().optional(),
|
|
162
|
+
slug: z.string(),
|
|
163
|
+
phase: z.enum(["GOAL", "DISCOVERY", "SCOPE", "BUILD", "VERIFY", "SHIP", "DONE", "CIRCUIT_BREAK"]),
|
|
164
|
+
issueGoal: z.string().min(1, "issueGoal cannot be empty"),
|
|
165
|
+
|
|
166
|
+
sourceSpecs: z.array(SourceSpecSchema).optional(),
|
|
167
|
+
|
|
168
|
+
sizing: z.object({
|
|
169
|
+
predicted: z.enum(["XS", "S", "M", "L"]).optional(),
|
|
170
|
+
ceremonyTier: z.enum(["LIGHT", "STANDARD", "THOROUGH"]).optional(),
|
|
171
|
+
actualFiles: z.number().optional(),
|
|
172
|
+
actualMinutes: z.number().optional(),
|
|
173
|
+
}).optional(),
|
|
174
|
+
|
|
175
|
+
acs: z.array(ACSchema),
|
|
176
|
+
|
|
177
|
+
governingSpec: z.object({
|
|
178
|
+
path: z.string(),
|
|
179
|
+
detectedFrom: z.string().optional(),
|
|
180
|
+
}).optional(),
|
|
181
|
+
|
|
182
|
+
agents: z.object({
|
|
183
|
+
marcus: AgentSchema,
|
|
184
|
+
quinn: AgentSchema,
|
|
185
|
+
rook: AgentSchema,
|
|
186
|
+
}).optional(),
|
|
187
|
+
|
|
188
|
+
environments: z.object({
|
|
189
|
+
local: EnvironmentLocalSchema,
|
|
190
|
+
prod: EnvironmentProdSchema,
|
|
191
|
+
}).optional(),
|
|
192
|
+
|
|
193
|
+
gates: z.object({
|
|
194
|
+
scope: GateResultSchema,
|
|
195
|
+
verify: GateResultSchema,
|
|
196
|
+
ship: GateResultSchema,
|
|
197
|
+
}).optional(),
|
|
198
|
+
|
|
199
|
+
daDirectEdits: z.number().optional(),
|
|
200
|
+
iterationCount: z.number().optional(),
|
|
201
|
+
startTs: z.string().optional(),
|
|
202
|
+
updatedTs: z.string().optional(),
|
|
203
|
+
|
|
204
|
+
phaseTimings: z.record(z.string(), z.array(PhaseTimingEntry)).optional(),
|
|
205
|
+
|
|
206
|
+
gateContract: z.object({
|
|
207
|
+
environments: z.any().optional(),
|
|
208
|
+
verdicts: z.any().optional(),
|
|
209
|
+
evidence: z.any().optional(),
|
|
210
|
+
baselines: z.object({
|
|
211
|
+
testBaseline: z.number().optional(),
|
|
212
|
+
tscBaseline: z.number().optional(),
|
|
213
|
+
}).optional(),
|
|
214
|
+
}).optional(),
|
|
215
|
+
|
|
216
|
+
changelog: z.array(ChangelogEntry).optional(),
|
|
217
|
+
|
|
218
|
+
verifyBlockers: z.array(z.object({
|
|
219
|
+
id: z.string(),
|
|
220
|
+
description: z.string(),
|
|
221
|
+
fixCommit: z.string().optional(),
|
|
222
|
+
quinnReverified: z.boolean().default(false),
|
|
223
|
+
})).optional(),
|
|
224
|
+
|
|
225
|
+
bootstrappedFrom: z.string().optional(),
|
|
226
|
+
beforeState: z.object({
|
|
227
|
+
type: z.enum(["text", "screenshot", "api", "data", "none"]),
|
|
228
|
+
path: z.string().nullable(),
|
|
229
|
+
capturedAt: z.string(),
|
|
230
|
+
description: z.string().optional(),
|
|
231
|
+
}).optional(),
|
|
232
|
+
|
|
233
|
+
issueType: z.enum(["feature", "bug-fix", "bug", "refactor", "chore"]).optional(),
|
|
234
|
+
rca: z.object({
|
|
235
|
+
rootCause: z.string().optional(),
|
|
236
|
+
prediction: z.string().optional(),
|
|
237
|
+
predictionVerified: z.boolean().optional(),
|
|
238
|
+
}).optional(),
|
|
239
|
+
|
|
240
|
+
blastRadius: z.object({
|
|
241
|
+
filesRead: z.number(),
|
|
242
|
+
filesChanged: z.number(),
|
|
243
|
+
}).optional(),
|
|
244
|
+
|
|
245
|
+
foundIssues: z.array(z.object({
|
|
246
|
+
description: z.string(),
|
|
247
|
+
disposition: z.enum(["fixed", "filed", "scoped-out"]).optional(),
|
|
248
|
+
issueNumber: z.number().optional(),
|
|
249
|
+
})).optional(),
|
|
250
|
+
|
|
251
|
+
filesChangedOutsideBrief: z.array(z.string()).optional(),
|
|
252
|
+
|
|
253
|
+
quinnJourneyPath: z.string().optional(),
|
|
254
|
+
|
|
255
|
+
conformityFindings: z.any().optional(),
|
|
256
|
+
|
|
257
|
+
preExistingFailures: z.array(z.string()).optional(),
|
|
258
|
+
|
|
259
|
+
proofOfFix: z.object({
|
|
260
|
+
commitSha: z.string(),
|
|
261
|
+
verified: z.boolean(),
|
|
262
|
+
}).optional(),
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
export type WorkflowState = z.infer<typeof WorkflowStateSchema>;
|
|
266
|
+
|
|
267
|
+
// ── AFK batch plan schema (#468) ────────────────────────────
|
|
268
|
+
|
|
269
|
+
const REJECTED_SKIP_REASONS = [
|
|
270
|
+
"needs investigation",
|
|
271
|
+
"needs browser testing",
|
|
272
|
+
"can't do from here",
|
|
273
|
+
];
|
|
274
|
+
|
|
275
|
+
export const AfkBatchPlanSchema = z.object({
|
|
276
|
+
approvedAt: z.string(),
|
|
277
|
+
planned: z.array(z.number()),
|
|
278
|
+
shipped: z.array(z.number()),
|
|
279
|
+
skipped: z.array(z.object({
|
|
280
|
+
issue: z.number(),
|
|
281
|
+
reason: z.string(),
|
|
282
|
+
delegationAction: z.string().optional(),
|
|
283
|
+
})),
|
|
284
|
+
inProgress: z.number().nullable(),
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export type AfkBatchPlan = z.infer<typeof AfkBatchPlanSchema>;
|
|
288
|
+
|
|
289
|
+
export { REJECTED_SKIP_REASONS };
|
|
290
|
+
|
|
291
|
+
// ── Adversary report schema (ADR-009 B1) ──────────────────────
|
|
292
|
+
|
|
293
|
+
export const AdversaryReportSchema = z.object({
|
|
294
|
+
gameable: z.number(),
|
|
295
|
+
approved: z.boolean(),
|
|
296
|
+
exploits: z.array(z.object({
|
|
297
|
+
acId: z.string(),
|
|
298
|
+
exploit: z.string(),
|
|
299
|
+
recommendation: z.string(),
|
|
300
|
+
})),
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// ── Chain artifact schemas ──────────────────────────────────
|
|
304
|
+
|
|
305
|
+
export const GoalRecordSchema = z.object({
|
|
306
|
+
contractVersion: z.string(),
|
|
307
|
+
id: z.string(),
|
|
308
|
+
goalStatement: z.string().min(1),
|
|
309
|
+
governingSpec: z.object({
|
|
310
|
+
path: z.string(),
|
|
311
|
+
detectedFrom: z.string().optional(),
|
|
312
|
+
}).optional(),
|
|
313
|
+
successCriteria: z.array(z.object({
|
|
314
|
+
id: z.string(),
|
|
315
|
+
assertion: z.string(),
|
|
316
|
+
evidenceType: z.string(),
|
|
317
|
+
threshold: z.object({ op: z.string(), value: z.string(), unit: z.string().optional() }),
|
|
318
|
+
})),
|
|
319
|
+
scopeBoundary: z.object({ in: z.array(z.string()), out: z.array(z.string()) }).optional(),
|
|
320
|
+
artifactRef: z.object({ type: z.string(), locator: z.string() }).optional(),
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
export const ShipEvidenceSchema = z.object({
|
|
324
|
+
contractVersion: z.string(),
|
|
325
|
+
issueNumber: z.number(),
|
|
326
|
+
gateOut: z.object({
|
|
327
|
+
status: z.enum(["PASS", "FAIL"]),
|
|
328
|
+
evidence: z.array(z.object({
|
|
329
|
+
criterion: z.string(),
|
|
330
|
+
result: z.enum(["PASS", "FAIL", "SKIP"]),
|
|
331
|
+
detail: z.any().optional(),
|
|
332
|
+
})),
|
|
333
|
+
}),
|
|
334
|
+
mergeCommitSha: z.string().optional(),
|
|
335
|
+
capturedAt: z.string(),
|
|
336
|
+
iterationCount: z.number().optional(),
|
|
337
|
+
sizing: z.object({ predicted: z.string().optional(), actual: z.string().optional() }).optional(),
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
export const ProveEvidenceSchema = z.object({
|
|
341
|
+
issueNumber: z.number(),
|
|
342
|
+
verdict: z.enum(["PROVEN", "UNPROVEN", "INCONCLUSIVE"]),
|
|
343
|
+
commitSHA: z.string(),
|
|
344
|
+
capturedAt: z.string(),
|
|
345
|
+
beforeEvidence: z.object({
|
|
346
|
+
type: z.enum(["text", "screenshot", "api", "data", "none"]),
|
|
347
|
+
path: z.string().nullable(),
|
|
348
|
+
capturedAt: z.string(),
|
|
349
|
+
description: z.string(),
|
|
350
|
+
}),
|
|
351
|
+
afterEvidence: z.object({
|
|
352
|
+
type: z.enum(["text", "screenshot", "api", "data", "none"]),
|
|
353
|
+
path: z.string().nullable(),
|
|
354
|
+
capturedAt: z.string(),
|
|
355
|
+
environment: z.enum(["local", "prod"]),
|
|
356
|
+
description: z.string(),
|
|
357
|
+
}),
|
|
358
|
+
comparisonSummary: z.string(),
|
|
359
|
+
quinnVerdict: z.enum(["PASS", "FAIL", "SKIP"]).optional(),
|
|
360
|
+
reproduced: z.boolean(),
|
|
361
|
+
gaps: z.array(z.object({ ac: z.string(), status: z.string(), detail: z.string() })).optional(),
|
|
362
|
+
});
|