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,334 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
2
|
+
import { join, basename } from "path";
|
|
3
|
+
|
|
4
|
+
export interface AssembleResult {
|
|
5
|
+
briefPath: string;
|
|
6
|
+
acCount: number;
|
|
7
|
+
contextFileCount: number;
|
|
8
|
+
validated: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const BRIEF_POLICIES_PATH = join(
|
|
12
|
+
process.env.HOME || "",
|
|
13
|
+
".claude",
|
|
14
|
+
"skills",
|
|
15
|
+
"ship",
|
|
16
|
+
"brief-policies.json",
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const REQUIRED_SECTIONS = ["Goal", "ACs", "Files", "Scope", "Verify"] as const;
|
|
20
|
+
|
|
21
|
+
export async function assembleBrief(opts: {
|
|
22
|
+
slug: string;
|
|
23
|
+
workDir: string;
|
|
24
|
+
projectRoot: string;
|
|
25
|
+
}): Promise<AssembleResult> {
|
|
26
|
+
const { slug, workDir, projectRoot } = opts;
|
|
27
|
+
|
|
28
|
+
const sf = join(workDir, "workflow-state.json");
|
|
29
|
+
if (!existsSync(sf)) {
|
|
30
|
+
throw new Error(`workflow-state.json not found at ${sf}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const state = JSON.parse(readFileSync(sf, "utf-8"));
|
|
34
|
+
const acs: any[] = state.acs || [];
|
|
35
|
+
|
|
36
|
+
const contextFiles = deduplicateContextFiles(acs);
|
|
37
|
+
const verifyCommands = extractVerifyCommands(acs);
|
|
38
|
+
const scopeOut: string[] = state.scopeOut || [];
|
|
39
|
+
|
|
40
|
+
const harness = loadProjectHarness(projectRoot);
|
|
41
|
+
const projectContextDocs = extractContextDocs(harness);
|
|
42
|
+
const hasAgents = existsSync(join(projectRoot, "AGENTS.md"));
|
|
43
|
+
|
|
44
|
+
const sections: string[] = [];
|
|
45
|
+
|
|
46
|
+
sections.push(buildContextSection(projectRoot));
|
|
47
|
+
sections.push(buildSpecAlignment(state.governingSpec));
|
|
48
|
+
sections.push(buildTaskSection(state.issueGoal, acs));
|
|
49
|
+
if (state.issueType === "bug-fix" || state.issueType === "bug") {
|
|
50
|
+
sections.push(buildRCASection(state.rca));
|
|
51
|
+
}
|
|
52
|
+
sections.push(buildGitProtocol(state.issue));
|
|
53
|
+
sections.push(buildFilesSection(contextFiles));
|
|
54
|
+
sections.push(buildScopeSection(scopeOut));
|
|
55
|
+
sections.push(buildVerifySection(verifyCommands));
|
|
56
|
+
sections.push(buildReportSection());
|
|
57
|
+
|
|
58
|
+
const brief = sections.join("\n\n");
|
|
59
|
+
const briefPath = join(workDir, "marcus-brief.md");
|
|
60
|
+
writeFileSync(briefPath, brief);
|
|
61
|
+
|
|
62
|
+
const validated = validateBrief(brief);
|
|
63
|
+
|
|
64
|
+
const projectContextCount = projectContextDocs.length + (hasAgents ? 1 : 0);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
briefPath,
|
|
68
|
+
acCount: acs.length,
|
|
69
|
+
contextFileCount: contextFiles.length + projectContextCount,
|
|
70
|
+
validated,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function deduplicateContextFiles(acs: any[]): Array<{ path: string; reason: string }> {
|
|
75
|
+
const seen = new Set<string>();
|
|
76
|
+
const result: Array<{ path: string; reason: string }> = [];
|
|
77
|
+
|
|
78
|
+
for (const ac of acs) {
|
|
79
|
+
for (const cf of ac.contextFiles || []) {
|
|
80
|
+
if (!seen.has(cf.path)) {
|
|
81
|
+
seen.add(cf.path);
|
|
82
|
+
result.push({ path: cf.path, reason: cf.reason || "" });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function extractVerifyCommands(acs: any[]): string[] {
|
|
91
|
+
const commands: string[] = [];
|
|
92
|
+
for (const ac of acs) {
|
|
93
|
+
const cmd = ac.evidenceMethod?.command;
|
|
94
|
+
if (cmd) commands.push(cmd);
|
|
95
|
+
}
|
|
96
|
+
return commands;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function loadProjectHarness(projectRoot: string): Record<string, any> | null {
|
|
100
|
+
const harnessPath = join(projectRoot, ".claude", "rungate.json");
|
|
101
|
+
if (!existsSync(harnessPath)) return null;
|
|
102
|
+
try {
|
|
103
|
+
return JSON.parse(readFileSync(harnessPath, "utf-8"));
|
|
104
|
+
} catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function extractContextDocs(harness: Record<string, any> | null): string[] {
|
|
110
|
+
if (!harness?.contextDocs) return [];
|
|
111
|
+
const docs = harness.contextDocs;
|
|
112
|
+
if (Array.isArray(docs)) return docs;
|
|
113
|
+
if (typeof docs === "object") return Object.values(docs) as string[];
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function buildContextSection(projectRoot: string): string {
|
|
118
|
+
const lines = [
|
|
119
|
+
"## Context (read first, in order)",
|
|
120
|
+
`1. ${projectRoot}/CLAUDE.md (if exists)`,
|
|
121
|
+
`2. ${projectRoot}/MODEL.md (PRIMARY — system flow, three rules, troubleshooting map)`,
|
|
122
|
+
`3. ${projectRoot}/PRINCIPLES.md (ONLY if MODEL.md doesn't exist)`,
|
|
123
|
+
`4. ${projectRoot}/ARCHITECTURE.md (ONLY if MODEL.md doesn't exist)`,
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
let idx = 5;
|
|
127
|
+
|
|
128
|
+
// Include AGENTS.md from project repo when present
|
|
129
|
+
const agentsPath = join(projectRoot, "AGENTS.md");
|
|
130
|
+
if (existsSync(agentsPath)) {
|
|
131
|
+
lines.push(`${idx}. ${projectRoot}/AGENTS.md (agent role definitions)`);
|
|
132
|
+
idx++;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Include contextDocs from rungate.json
|
|
136
|
+
const harness = loadProjectHarness(projectRoot);
|
|
137
|
+
const contextDocs = extractContextDocs(harness);
|
|
138
|
+
for (const doc of contextDocs) {
|
|
139
|
+
lines.push(`${idx}. ${projectRoot}/${doc}`);
|
|
140
|
+
idx++;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return lines.join("\n");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function buildSpecAlignment(governingSpec?: { path: string; detectedFrom?: string }): string {
|
|
147
|
+
if (!governingSpec) {
|
|
148
|
+
return [
|
|
149
|
+
"## Spec Alignment",
|
|
150
|
+
"- **Governing spec:** None detected",
|
|
151
|
+
"- **Verified no contradiction:** N/A",
|
|
152
|
+
].join("\n");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return [
|
|
156
|
+
"## Spec Alignment (MANDATORY)",
|
|
157
|
+
`- **Governing spec:** ${governingSpec.path}`,
|
|
158
|
+
`- **Detected from:** ${governingSpec.detectedFrom || "unknown"}`,
|
|
159
|
+
"- **Verified no contradiction:** DA verified before brief generation",
|
|
160
|
+
].join("\n");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function buildTaskSection(issueGoal: string, acs: any[]): string {
|
|
164
|
+
const lines = ["## Task", "", `**Goal:** ${issueGoal}`, ""];
|
|
165
|
+
|
|
166
|
+
lines.push("### Acceptance Criteria", "");
|
|
167
|
+
if (acs.length === 0) {
|
|
168
|
+
lines.push("- (no acceptance criteria defined yet)");
|
|
169
|
+
} else {
|
|
170
|
+
for (const ac of acs) {
|
|
171
|
+
const threshold = ac.threshold
|
|
172
|
+
? ` (${ac.threshold.op} ${ac.threshold.value}${ac.threshold.unit ? " " + ac.threshold.unit : ""})`
|
|
173
|
+
: "";
|
|
174
|
+
lines.push(`- **${ac.id}** [${ac.type || "CODE"}]: ${ac.statement}${threshold}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return lines.join("\n");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function buildGitProtocol(issue: number): string {
|
|
182
|
+
return [
|
|
183
|
+
"## Git protocol",
|
|
184
|
+
`- Branch: \`${issue}-deep-modules\` (create from main if not in a worktree)`,
|
|
185
|
+
"- Before committing, rebase onto latest main",
|
|
186
|
+
"- Commit all changes before reporting back",
|
|
187
|
+
"- Push with `-u` before reporting",
|
|
188
|
+
"- Never commit to main directly, never force push",
|
|
189
|
+
].join("\n");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function buildFilesSection(contextFiles: Array<{ path: string; reason: string }>): string {
|
|
193
|
+
const lines = ["## Files to read before touching anything"];
|
|
194
|
+
|
|
195
|
+
if (contextFiles.length === 0) {
|
|
196
|
+
lines.push("- (no context files specified)");
|
|
197
|
+
} else {
|
|
198
|
+
for (const cf of contextFiles) {
|
|
199
|
+
lines.push(`- ${cf.path}${cf.reason ? " — " + cf.reason : ""}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return lines.join("\n");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function buildScopeSection(scopeOut: string[]): string {
|
|
207
|
+
const lines = ["## Scope — do NOT touch"];
|
|
208
|
+
|
|
209
|
+
if (scopeOut.length === 0) {
|
|
210
|
+
lines.push("- (no explicit scope boundaries — stay within task scope)");
|
|
211
|
+
} else {
|
|
212
|
+
for (const item of scopeOut) {
|
|
213
|
+
lines.push(`- ${item}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
lines.push("- Never run `make rebuild` — DA does that");
|
|
218
|
+
|
|
219
|
+
return lines.join("\n");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function buildVerifySection(commands: string[]): string {
|
|
223
|
+
const lines = ["## Verify"];
|
|
224
|
+
|
|
225
|
+
if (commands.length === 0) {
|
|
226
|
+
lines.push("- `bunx tsc --noEmit`");
|
|
227
|
+
} else {
|
|
228
|
+
for (const cmd of commands) {
|
|
229
|
+
lines.push(`- \`${cmd}\``);
|
|
230
|
+
}
|
|
231
|
+
lines.push("- `bunx tsc --noEmit`");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return lines.join("\n");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function buildRCASection(rca?: { rootCause?: string; prediction?: string; predictionVerified?: boolean }): string {
|
|
238
|
+
return [
|
|
239
|
+
"## Root Cause Analysis (bug-fix)",
|
|
240
|
+
`- **Root cause:** ${rca?.rootCause || "(investigate and fill)"}`,
|
|
241
|
+
`- **Prediction:** ${rca?.prediction || "(what will the fix change?)"}`,
|
|
242
|
+
`- **Prediction verified:** ${rca?.predictionVerified ?? "(verify after fix)"}`,
|
|
243
|
+
].join("\n");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface JourneyStep {
|
|
247
|
+
action: string;
|
|
248
|
+
wait_for?: string;
|
|
249
|
+
assertion?: { type: string; target?: string; expected?: string };
|
|
250
|
+
on_fail?: string;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export const MAX_JOURNEY_STEPS = 8;
|
|
254
|
+
|
|
255
|
+
export function validateJourneySteps(steps: JourneyStep[]): { valid: boolean; splitRequired: boolean } {
|
|
256
|
+
if (steps.length <= MAX_JOURNEY_STEPS) return { valid: true, splitRequired: false };
|
|
257
|
+
return { valid: false, splitRequired: true };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function splitJourney(steps: JourneyStep[]): JourneyStep[][] {
|
|
261
|
+
const chunks: JourneyStep[][] = [];
|
|
262
|
+
for (let i = 0; i < steps.length; i += MAX_JOURNEY_STEPS) {
|
|
263
|
+
chunks.push(steps.slice(i, i + MAX_JOURNEY_STEPS));
|
|
264
|
+
}
|
|
265
|
+
return chunks;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function buildReportSection(): string {
|
|
269
|
+
return [
|
|
270
|
+
"## Report back",
|
|
271
|
+
"For each acceptance criterion, provide evidence:",
|
|
272
|
+
"- AC-N: → file.ts:L## [description] (code presence)",
|
|
273
|
+
"- AC-N: → grep: \"pattern\" returned N matches (absence/presence)",
|
|
274
|
+
"- AC-N: → test: test-name PASS (test-verified)",
|
|
275
|
+
"Plus: files changed (paths + line numbers), test output, scope conflicts",
|
|
276
|
+
].join("\n");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function validateBrief(brief: string): boolean {
|
|
280
|
+
let policies: any = null;
|
|
281
|
+
if (existsSync(BRIEF_POLICIES_PATH)) {
|
|
282
|
+
try {
|
|
283
|
+
policies = JSON.parse(readFileSync(BRIEF_POLICIES_PATH, "utf-8"));
|
|
284
|
+
} catch {
|
|
285
|
+
// If policies can't be read, skip validation
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!policies?.policies?.marcus?.requiredPatterns) {
|
|
290
|
+
// Fallback: check for required section headers
|
|
291
|
+
for (const section of REQUIRED_SECTIONS) {
|
|
292
|
+
const patterns: Record<string, RegExp> = {
|
|
293
|
+
Goal: /(?:goal|objective|task)/i,
|
|
294
|
+
ACs: /(?:acceptance criter|AC-|success criter)/i,
|
|
295
|
+
Files: /(?:files to|files changed|file.*read)/i,
|
|
296
|
+
Scope: /(?:scope.*not|do not touch|out of scope)/i,
|
|
297
|
+
Verify: /(?:verify|verification)/i,
|
|
298
|
+
};
|
|
299
|
+
if (!patterns[section]?.test(brief)) return false;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
for (const pattern of policies.policies.marcus.requiredPatterns) {
|
|
305
|
+
let p = pattern.pattern as string;
|
|
306
|
+
let flags = "";
|
|
307
|
+
if (p.startsWith("(?i)")) {
|
|
308
|
+
p = p.slice(4);
|
|
309
|
+
flags = "i";
|
|
310
|
+
}
|
|
311
|
+
const re = new RegExp(p, flags);
|
|
312
|
+
if (!re.test(brief)) return false;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// CLI entry point
|
|
319
|
+
if (import.meta.main) {
|
|
320
|
+
const args = process.argv.slice(2);
|
|
321
|
+
let slug = "", workDir = "", projectRoot = "";
|
|
322
|
+
for (let i = 0; i < args.length; i++) {
|
|
323
|
+
if (args[i] === "--slug" && args[i + 1]) slug = args[++i];
|
|
324
|
+
if (args[i] === "--work-dir" && args[i + 1]) workDir = args[++i];
|
|
325
|
+
if (args[i] === "--project-root" && args[i + 1]) projectRoot = args[++i];
|
|
326
|
+
}
|
|
327
|
+
if (!slug || !workDir || !projectRoot) {
|
|
328
|
+
console.error("Usage: bun run brief-assembler.ts --slug SLUG --work-dir DIR --project-root DIR");
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
assembleBrief({ slug, workDir, projectRoot })
|
|
332
|
+
.then(r => console.log(`Brief written: ${r.briefPath} (${r.acCount} ACs, validated=${r.validated})`))
|
|
333
|
+
.catch(e => { console.error(e.message); process.exit(1); });
|
|
334
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { test, expect, describe } from "bun:test";
|
|
2
|
+
import { readFileSync, existsSync } from "fs";
|
|
3
|
+
import { GoalRecordSchema, ShipEvidenceSchema, ProveEvidenceSchema } from "./schema";
|
|
4
|
+
|
|
5
|
+
const TEST_DIR = process.env.TEST_WORK_DIR || "";
|
|
6
|
+
|
|
7
|
+
function tryRead(filename: string) {
|
|
8
|
+
const path = `${TEST_DIR}/${filename}`;
|
|
9
|
+
if (!existsSync(path)) return null;
|
|
10
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("chain: goal → ship → prove artifacts", () => {
|
|
14
|
+
test("goal-record.json validates if present", () => {
|
|
15
|
+
const data = tryRead("goal-record.json");
|
|
16
|
+
if (!data) return;
|
|
17
|
+
const result = GoalRecordSchema.safeParse(data);
|
|
18
|
+
if (!result.success) {
|
|
19
|
+
const issues = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`);
|
|
20
|
+
expect(issues).toEqual([]);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("goal-record has non-empty success criteria", () => {
|
|
25
|
+
const data = tryRead("goal-record.json");
|
|
26
|
+
if (!data) return;
|
|
27
|
+
expect(data.successCriteria.length).toBeGreaterThan(0);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("goal-record SCs all have thresholds", () => {
|
|
31
|
+
const data = tryRead("goal-record.json");
|
|
32
|
+
if (!data) return;
|
|
33
|
+
const missing = data.successCriteria.filter((sc: any) => !sc.threshold);
|
|
34
|
+
expect(missing.map((sc: any) => sc.id)).toEqual([]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("ship-evidence.json validates if present", () => {
|
|
38
|
+
const data = tryRead("ship-evidence.json");
|
|
39
|
+
if (!data) return;
|
|
40
|
+
const result = ShipEvidenceSchema.safeParse(data);
|
|
41
|
+
if (!result.success) {
|
|
42
|
+
const issues = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`);
|
|
43
|
+
expect(issues).toEqual([]);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("ship-evidence has no FAIL results when status is PASS", () => {
|
|
48
|
+
const data = tryRead("ship-evidence.json");
|
|
49
|
+
if (!data || data.gateOut.status !== "PASS") return;
|
|
50
|
+
const fails = data.gateOut.evidence.filter((e: any) => e.result === "FAIL");
|
|
51
|
+
expect(fails.map((e: any) => e.criterion)).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("prove-evidence.json validates if present", () => {
|
|
55
|
+
const data = tryRead("prove-evidence.json");
|
|
56
|
+
if (!data) return;
|
|
57
|
+
const result = ProveEvidenceSchema.safeParse(data);
|
|
58
|
+
if (!result.success) {
|
|
59
|
+
const issues = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`);
|
|
60
|
+
expect(issues).toEqual([]);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("prove verdict consistent with before/after evidence", () => {
|
|
65
|
+
const data = tryRead("prove-evidence.json");
|
|
66
|
+
if (!data) return;
|
|
67
|
+
if (data.verdict === "PROVEN") {
|
|
68
|
+
expect(data.afterEvidence.description.length).toBeGreaterThan(0);
|
|
69
|
+
expect(data.comparisonSummary.length).toBeGreaterThan(0);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("prove PROVEN has no unresolved gaps", () => {
|
|
74
|
+
const data = tryRead("prove-evidence.json");
|
|
75
|
+
if (!data || data.verdict !== "PROVEN") return;
|
|
76
|
+
const unresolved = (data.gaps || []).filter((g: any) => g.status === "UNPROVEN");
|
|
77
|
+
expect(unresolved.map((g: any) => g.ac)).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("chain consistency: issue numbers match across artifacts", () => {
|
|
81
|
+
const goal = tryRead("goal-record.json");
|
|
82
|
+
const ship = tryRead("ship-evidence.json");
|
|
83
|
+
const prove = tryRead("prove-evidence.json");
|
|
84
|
+
if (!goal || !ship) return;
|
|
85
|
+
const goalNum = parseInt(goal.id.replace("issue-", ""));
|
|
86
|
+
expect(ship.issueNumber).toBe(goalNum);
|
|
87
|
+
if (prove) {
|
|
88
|
+
expect(prove.issueNumber).toBe(goalNum);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { test, expect, describe } from "bun:test";
|
|
2
|
+
import { readFileSync, existsSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { WorkflowStateSchema } from "./schema";
|
|
5
|
+
import { SIGNAL_PHRASE_PATTERNS } from "../lib/conformity";
|
|
6
|
+
|
|
7
|
+
const STANDALONE = !process.env.TEST_WORK_DIR;
|
|
8
|
+
const TEST_DIR = process.env.TEST_WORK_DIR || "/tmp/gate-e2e-smoke";
|
|
9
|
+
const SF = `${TEST_DIR}/workflow-state.json`;
|
|
10
|
+
|
|
11
|
+
function loadState(): any | null {
|
|
12
|
+
if (!existsSync(SF)) return null;
|
|
13
|
+
const raw = JSON.parse(readFileSync(SF, "utf-8"));
|
|
14
|
+
return WorkflowStateSchema.passthrough().parse(raw);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function sf(path: string): any {
|
|
18
|
+
if (!existsSync(SF)) return undefined;
|
|
19
|
+
const wf = JSON.parse(readFileSync(SF, "utf-8"));
|
|
20
|
+
const parts = path.replace(/^\./, "").split(".").filter(Boolean);
|
|
21
|
+
let val: any = wf;
|
|
22
|
+
for (const p of parts) {
|
|
23
|
+
if (val == null) return undefined;
|
|
24
|
+
val = val[p];
|
|
25
|
+
}
|
|
26
|
+
return val;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function loadSpec(path: string, projectRoot?: string): string {
|
|
30
|
+
const resolved = path.startsWith('/') ? path : join(projectRoot || '.', path);
|
|
31
|
+
return readFileSync(resolved, "utf-8");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function extractSpecRules(spec: string): string[] {
|
|
35
|
+
const rules: string[] = [];
|
|
36
|
+
for (const p of SIGNAL_PHRASE_PATTERNS) {
|
|
37
|
+
for (const m of spec.matchAll(new RegExp(p.source, p.flags))) {
|
|
38
|
+
rules.push(m[0].replace(/^[-*] /, "").trim().replace(/[.;]$/, ""));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return [...new Set(rules)];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe("E2E: governing spec compliance", () => {
|
|
45
|
+
if (STANDALONE || !existsSync(SF)) {
|
|
46
|
+
test("skipped — no active workflow (standalone run)", () => {});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const tier = sf("sizing")?.ceremonyTier;
|
|
50
|
+
if (tier === "LIGHT") {
|
|
51
|
+
test("skipped — spec checks not required for LIGHT tier", () => {});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
test("governing spec exists and is readable", () => {
|
|
56
|
+
const wf = loadState() as any;
|
|
57
|
+
expect(wf.sourceSpecs?.[0]?.path).toBeDefined();
|
|
58
|
+
const specPath = wf.sourceSpecs[0].path.startsWith('/') ? wf.sourceSpecs[0].path : join(wf.projectRoot || '.', wf.sourceSpecs[0].path);
|
|
59
|
+
expect(existsSync(specPath)).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("spec has extractable rules", () => {
|
|
63
|
+
const wf = loadState() as any;
|
|
64
|
+
const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
|
|
65
|
+
const rules = extractSpecRules(spec);
|
|
66
|
+
expect(rules.length).toBeGreaterThan(0);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("E2E: hardcoded values violate spec", () => {
|
|
71
|
+
if (STANDALONE || !existsSync(SF)) {
|
|
72
|
+
test("skipped — no active workflow (standalone run)", () => {});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const tier = sf("sizing")?.ceremonyTier;
|
|
76
|
+
if (tier === "LIGHT") {
|
|
77
|
+
test("skipped — spec checks not required for LIGHT tier", () => {});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
test("no hardcoded paths in AC statements", () => {
|
|
82
|
+
const wf = loadState() as any;
|
|
83
|
+
const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
|
|
84
|
+
|
|
85
|
+
if (!spec.match(/never hardcod|read from config|configurable/i)) return;
|
|
86
|
+
|
|
87
|
+
const hardcodedPath = /\/usr\/|\/opt\/|\/home\/|\/tmp\/[a-z]/i;
|
|
88
|
+
const hardcodedPort = /\bport\s+\d{4}\b/i;
|
|
89
|
+
const hits = wf.acs.filter((ac: any) =>
|
|
90
|
+
hardcodedPath.test(ac.statement) || hardcodedPort.test(ac.statement)
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("no hardcoded numeric thresholds in AC statements", () => {
|
|
97
|
+
const wf = loadState() as any;
|
|
98
|
+
const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
|
|
99
|
+
|
|
100
|
+
if (!spec.match(/configurable|environment variable|config/i)) return;
|
|
101
|
+
|
|
102
|
+
const hardcodedNum = /\bhardcoded to \d+\.?\d*\b/i;
|
|
103
|
+
const hits = wf.acs.filter((ac: any) => hardcodedNum.test(ac.statement));
|
|
104
|
+
|
|
105
|
+
expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("E2E: behavioral language violates spec", () => {
|
|
110
|
+
if (STANDALONE || !existsSync(SF)) {
|
|
111
|
+
test("skipped — no active workflow (standalone run)", () => {});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
test("no 'DA should' or behavioral delegation in ACs", () => {
|
|
115
|
+
const wf = loadState() as any;
|
|
116
|
+
if (!wf) return;
|
|
117
|
+
const behavioral = /\b(DA should|remember to|make sure|don't forget)\b/i;
|
|
118
|
+
const hits = wf.acs.filter((ac: any) => behavioral.test(ac.statement));
|
|
119
|
+
|
|
120
|
+
expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("E2E: spec-prohibited patterns in ACs", () => {
|
|
125
|
+
if (STANDALONE || !existsSync(SF)) {
|
|
126
|
+
test("skipped — no active workflow (standalone run)", () => {});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const tier = sf("sizing")?.ceremonyTier;
|
|
130
|
+
if (tier === "LIGHT") {
|
|
131
|
+
test("skipped — spec checks not required for LIGHT tier", () => {});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
test("no setTimeout when spec says use backoff", () => {
|
|
136
|
+
const wf = loadState() as any;
|
|
137
|
+
const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
|
|
138
|
+
|
|
139
|
+
if (!spec.match(/not use setTimeout|exponential backoff/i)) return;
|
|
140
|
+
|
|
141
|
+
const hits = wf.acs.filter((ac: any) =>
|
|
142
|
+
/setTimeout/i.test(ac.statement) || /setTimeout/i.test(ac.evidenceMethod?.command || "")
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("no stdout/console.log when spec says use logger", () => {
|
|
149
|
+
const wf = loadState() as any;
|
|
150
|
+
const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
|
|
151
|
+
|
|
152
|
+
if (!spec.match(/not write directly to stdout|use the logger/i)) return;
|
|
153
|
+
|
|
154
|
+
const hits = wf.acs.filter((ac: any) =>
|
|
155
|
+
/console\.log|stdout|directly/i.test(ac.statement)
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("no string error handling when spec says use typed errors", () => {
|
|
162
|
+
const wf = loadState() as any;
|
|
163
|
+
const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
|
|
164
|
+
|
|
165
|
+
if (!spec.match(/structured error|typed error|never raw string/i)) return;
|
|
166
|
+
|
|
167
|
+
const hits = wf.acs.filter((ac: any) =>
|
|
168
|
+
/string message|raw.*throw|catch.*string/i.test(ac.statement)
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
expect(hits.map((ac: any) => `${ac.id}: ${ac.statement}`)).toEqual([]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("E2E: Marcus brief cites governing spec", () => {
|
|
176
|
+
if (STANDALONE || !existsSync(SF)) {
|
|
177
|
+
test("skipped — no active workflow (standalone run)", () => {});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const tier = sf("sizing")?.ceremonyTier;
|
|
181
|
+
if (tier === "LIGHT") {
|
|
182
|
+
test("skipped — spec checks not required for LIGHT tier", () => {});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
test("brief references spec constraints", () => {
|
|
187
|
+
const wf = loadState() as any;
|
|
188
|
+
if (!wf.sourceSpecs?.[0]?.path || !wf.agents?.marcus?.brief) return;
|
|
189
|
+
|
|
190
|
+
const spec = loadSpec(wf.sourceSpecs[0].path, wf.projectRoot);
|
|
191
|
+
const rules = extractSpecRules(spec);
|
|
192
|
+
const brief = wf.agents.marcus.brief.toLowerCase();
|
|
193
|
+
|
|
194
|
+
const cited = rules.filter(r =>
|
|
195
|
+
brief.includes(r.slice(0, 25).toLowerCase())
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
expect(cited.length).toBeGreaterThanOrEqual(
|
|
199
|
+
Math.min(3, rules.length)
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// ═══ ADR-008 MIGRATION COMPLETENESS ════════════════════════════════════
|
|
205
|
+
|
|
206
|
+
describe("E2E: ADR-008 migration", () => {
|
|
207
|
+
test("ADR-008 'What to delete' files are actually deleted", () => {
|
|
208
|
+
const adrPath = join(process.env.HOME || "", ".claude", "PAI", "ADR", "ADR-008-harness-v3-bun-tests-migration.md");
|
|
209
|
+
if (!existsSync(adrPath)) return;
|
|
210
|
+
const adr = readFileSync(adrPath, "utf-8");
|
|
211
|
+
|
|
212
|
+
const deletionTargets = [
|
|
213
|
+
"skills/ship/gate-runner.sh",
|
|
214
|
+
"skills/ship/gate-checks.sh",
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const existing = deletionTargets.filter(f =>
|
|
218
|
+
existsSync(join(process.env.HOME || "", ".claude", f))
|
|
219
|
+
);
|
|
220
|
+
expect(existing).toEqual([]);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("stop-the-bleeding: no .sh files in skills/ship/", () => {
|
|
224
|
+
const { execSync } = require("child_process");
|
|
225
|
+
const shipDir = join(process.env.HOME || "", ".claude", "skills", "ship");
|
|
226
|
+
try {
|
|
227
|
+
const result = execSync(`find "${shipDir}" -name '*.sh'`, { encoding: "utf-8", timeout: 5000 }).trim();
|
|
228
|
+
const files = result ? result.split("\n").filter(Boolean) : [];
|
|
229
|
+
expect(files).toEqual([]);
|
|
230
|
+
} catch {
|
|
231
|
+
// find command failed — skip
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|