draht-codex 2026.10.20 → 2026.10.23
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/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +16 -0
- package/agents/advisor.md +2 -2
- package/agents/architect.md +10 -71
- package/agents/debugger.md +12 -82
- package/agents/git-committer.md +10 -52
- package/agents/implementer.md +15 -63
- package/agents/investigator.md +11 -63
- package/agents/reviewer.md +15 -65
- package/agents/security-auditor.md +12 -105
- package/agents/spec-reviewer.md +12 -53
- package/agents/verifier.md +13 -54
- package/commands/atomic-commit.md +9 -9
- package/commands/create-verification-skill.md +8 -48
- package/commands/discuss-phase.md +5 -9
- package/commands/execute-phase.md +17 -47
- package/commands/fix.md +16 -130
- package/commands/grill.md +6 -51
- package/commands/init-project.md +10 -14
- package/commands/map-codebase.md +2 -2
- package/commands/new-project.md +9 -14
- package/commands/next-milestone.md +3 -7
- package/commands/orchestrate-loop.md +12 -12
- package/commands/orchestrate.md +12 -11
- package/commands/pause-work.md +1 -1
- package/commands/plan-phase.md +16 -38
- package/commands/quick.md +9 -78
- package/commands/resolve-conflicts.md +2 -15
- package/commands/triage.md +3 -14
- package/commands/verify-work.md +17 -106
- package/commands/why.md +18 -118
- package/hooks/hooks.json +10 -0
- package/package.json +4 -4
- package/scripts/checks-runtime.cjs +215 -0
- package/scripts/git-safety-hook.cjs +21 -0
- package/scripts/git-safety.cjs +198 -0
- package/scripts/gsd-post-task.cjs +78 -39
- package/scripts/gsd-quality-gate.cjs +206 -120
- package/scripts/prompt-context.cjs +40 -6
- package/scripts/session-start.cjs +6 -4
- package/scripts/stop-quality-gate.cjs +55 -25
- package/skills/atomic-commit/command.md +9 -9
- package/skills/atomic-reasoning/SKILL.md +6 -105
- package/skills/blast-radius/SKILL.md +1 -1
- package/skills/brainstorming/SKILL.md +8 -126
- package/skills/create-verification-skill/SKILL.md +1 -1
- package/skills/create-verification-skill/command.md +8 -48
- package/skills/ddd-workflow/SKILL.md +8 -101
- package/skills/debugging-workflow/SKILL.md +12 -122
- package/skills/discuss-phase/SKILL.md +1 -0
- package/skills/discuss-phase/agents/openai.yaml +2 -0
- package/skills/discuss-phase/command.md +5 -9
- package/skills/draht/SKILL.md +18 -14
- package/skills/epistemics/SKILL.md +12 -87
- package/skills/execute-phase/SKILL.md +1 -0
- package/skills/execute-phase/agents/openai.yaml +2 -0
- package/skills/execute-phase/command.md +17 -47
- package/skills/explainers/SKILL.md +1 -1
- package/skills/fix/SKILL.md +2 -1
- package/skills/fix/agents/openai.yaml +2 -0
- package/skills/fix/command.md +16 -130
- package/skills/grill/SKILL.md +1 -1
- package/skills/grill/command.md +6 -51
- package/skills/gsd-workflow/SKILL.md +37 -21
- package/skills/gsd-workflow/agents/openai.yaml +2 -0
- package/skills/init-project/SKILL.md +1 -0
- package/skills/init-project/agents/openai.yaml +2 -0
- package/skills/init-project/command.md +10 -14
- package/skills/loop-workflow/SKILL.md +7 -41
- package/skills/map-codebase/command.md +2 -2
- package/skills/model-tiering/SKILL.md +7 -7
- package/skills/new-project/SKILL.md +1 -0
- package/skills/new-project/agents/openai.yaml +2 -0
- package/skills/new-project/command.md +9 -14
- package/skills/next-milestone/SKILL.md +1 -0
- package/skills/next-milestone/agents/openai.yaml +2 -0
- package/skills/next-milestone/command.md +3 -7
- package/skills/orchestrate/command.md +12 -11
- package/skills/orchestrate-loop/command.md +12 -12
- package/skills/pause-work/SKILL.md +1 -0
- package/skills/pause-work/agents/openai.yaml +2 -0
- package/skills/pause-work/command.md +1 -1
- package/skills/plan-phase/SKILL.md +1 -0
- package/skills/plan-phase/agents/openai.yaml +2 -0
- package/skills/plan-phase/command.md +16 -38
- package/skills/progress/SKILL.md +1 -0
- package/skills/progress/agents/openai.yaml +2 -0
- package/skills/quick/SKILL.md +2 -1
- package/skills/quick/agents/openai.yaml +2 -0
- package/skills/quick/command.md +9 -78
- package/skills/resolve-conflicts/command.md +2 -15
- package/skills/resume-work/SKILL.md +1 -0
- package/skills/resume-work/agents/openai.yaml +2 -0
- package/skills/saga-spawner/SKILL.md +1 -1
- package/skills/tdd-workflow/SKILL.md +15 -104
- package/skills/triage/SKILL.md +2 -1
- package/skills/triage/agents/openai.yaml +2 -0
- package/skills/triage/command.md +3 -14
- package/skills/typescript-discipline/SKILL.md +12 -42
- package/skills/typescript-discipline/references/patterns.md +25 -266
- package/skills/unslop/SKILL.md +14 -105
- package/skills/verification-gate/SKILL.md +16 -76
- package/skills/verify-work/SKILL.md +1 -0
- package/skills/verify-work/agents/openai.yaml +2 -0
- package/skills/verify-work/command.md +17 -106
- package/skills/why/SKILL.md +1 -1
- package/skills/why/command.md +18 -118
|
@@ -91,54 +91,93 @@ if (commitHash) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
function hasTypeConfig(directory) {
|
|
95
|
+
while (true) {
|
|
96
|
+
if (fs.existsSync(path.join(directory, "tsconfig.json"))) return true;
|
|
97
|
+
const parent = path.dirname(directory);
|
|
98
|
+
if (parent === directory) return false;
|
|
99
|
+
directory = parent;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function hasTestCommand() {
|
|
104
|
+
if (toolchain.pm === "bun") return true;
|
|
105
|
+
let directory = cwd;
|
|
106
|
+
while (true) {
|
|
107
|
+
const packagePath = path.join(directory, "package.json");
|
|
108
|
+
if (fs.existsSync(packagePath)) {
|
|
109
|
+
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
|
110
|
+
return typeof pkg.scripts?.test === "string" && pkg.scripts.test.trim().length > 0;
|
|
111
|
+
}
|
|
112
|
+
const parent = path.dirname(directory);
|
|
113
|
+
if (parent === directory) return false;
|
|
114
|
+
directory = parent;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function commandFailureReason(error) {
|
|
119
|
+
if (error.code === "ETIMEDOUT") return "timed out";
|
|
120
|
+
if (error.signal) return `signal ${error.signal}`;
|
|
121
|
+
if (typeof error.status === "number") return `exit ${error.status}`;
|
|
122
|
+
return error.code || error.message || "unknown process error";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function verify(command, timeout) {
|
|
126
|
+
try {
|
|
127
|
+
execSync(command, { timeout, encoding: "utf-8", cwd, stdio: "pipe" });
|
|
128
|
+
return "pass";
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const output = [error.stdout, error.stderr].filter(Boolean).join("\n").trim().slice(-4000);
|
|
131
|
+
console.error(`${command} failed (${commandFailureReason(error)})${output ? `:\n${output}` : ""}`);
|
|
132
|
+
return "fail";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let finalStatus = status;
|
|
137
|
+
let checks;
|
|
138
|
+
if (status === "pass") {
|
|
139
|
+
checks = { types: "skip", tests: "skip" };
|
|
140
|
+
if (hasTypeConfig(cwd)) {
|
|
141
|
+
const tsCmd = toolchain.pm === "bun" ? "bun run tsc --noEmit" : "npx tsc --noEmit";
|
|
142
|
+
checks.types = verify(tsCmd, 30000);
|
|
143
|
+
} else {
|
|
144
|
+
console.log("Type check skipped: no tsconfig.json.");
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
if (hasTestCommand()) {
|
|
148
|
+
checks.tests = verify(toolchain.testCmd, 60000);
|
|
149
|
+
} else {
|
|
150
|
+
console.log("Tests skipped: no configured test script.");
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
checks.tests = "fail";
|
|
154
|
+
console.error(`Cannot determine test command: ${error.message}`);
|
|
155
|
+
}
|
|
156
|
+
if (checks.types === "fail" || checks.tests === "fail") {
|
|
157
|
+
finalStatus = "fail";
|
|
158
|
+
if (hookConfig.qualityGateStrict) process.exitCode = 1;
|
|
159
|
+
}
|
|
160
|
+
console.log(`Task ${phaseNum}-${planNum}-${taskNum}: types=${checks.types}, tests=${checks.tests}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Persist only the result after verification, including failures in advisory mode.
|
|
95
164
|
const entry = {
|
|
96
165
|
timestamp: new Date().toISOString(),
|
|
97
166
|
phase: parseInt(phaseNum, 10),
|
|
98
167
|
plan: parseInt(planNum, 10),
|
|
99
168
|
task: parseInt(taskNum, 10),
|
|
100
|
-
status,
|
|
169
|
+
status: finalStatus,
|
|
170
|
+
reportedStatus: status,
|
|
171
|
+
checks,
|
|
101
172
|
commit: commitHash || null,
|
|
102
173
|
};
|
|
103
174
|
|
|
104
175
|
fs.appendFileSync(LOG_FILE, JSON.stringify(entry) + "\n");
|
|
105
176
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const tsCmd = toolchain.pm === "bun" ? "bun run tsc --noEmit 2>&1" : "npx tsc --noEmit 2>&1";
|
|
111
|
-
execSync(tsCmd, { timeout: 30000, encoding: "utf-8", cwd });
|
|
112
|
-
// Run tests
|
|
113
|
-
try {
|
|
114
|
-
const testOutput = execSync(`${toolchain.testCmd} 2>&1`, { timeout: 60000, encoding: "utf-8", cwd });
|
|
115
|
-
const testMatch = testOutput.match(/(\d+) pass/);
|
|
116
|
-
const testCount = testMatch ? testMatch[1] : "?";
|
|
117
|
-
console.log(`✅ Task ${phaseNum}-${planNum}-${taskNum}: passed + types clean + ${testCount} tests pass`);
|
|
118
|
-
} catch (testErr) {
|
|
119
|
-
const testOut = testErr.stdout || testErr.stderr || "";
|
|
120
|
-
const failMatch = testOut.match(/(\d+) fail/);
|
|
121
|
-
if (failMatch) {
|
|
122
|
-
console.log(`⚠️ Task ${phaseNum}-${planNum}-${taskNum}: passed + types clean but ${failMatch[1]} test(s) failed`);
|
|
123
|
-
} else {
|
|
124
|
-
console.log(`✅ Task ${phaseNum}-${planNum}-${taskNum}: passed + types clean (no test runner found)`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
} catch (error) {
|
|
128
|
-
const output = error.stdout || "";
|
|
129
|
-
const errorCount = (output.match(/error TS/g) || []).length;
|
|
130
|
-
if (errorCount > 0) {
|
|
131
|
-
console.log(`⚠️ Task ${phaseNum}-${planNum}-${taskNum}: passed but ${errorCount} type error(s) introduced`);
|
|
132
|
-
fs.appendFileSync(LOG_FILE, JSON.stringify({
|
|
133
|
-
...entry,
|
|
134
|
-
warning: `${errorCount} type errors introduced`,
|
|
135
|
-
}) + "\n");
|
|
136
|
-
} else {
|
|
137
|
-
console.log(`✅ Task ${phaseNum}-${planNum}-${taskNum}: passed`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
} else if (status === "fail") {
|
|
141
|
-
console.log(`❌ Task ${phaseNum}-${planNum}-${taskNum}: FAILED`);
|
|
177
|
+
if (finalStatus === "pass") {
|
|
178
|
+
console.log(`Task ${phaseNum}-${planNum}-${taskNum}: passed`);
|
|
179
|
+
} else if (finalStatus === "fail") {
|
|
180
|
+
console.log(`Task ${phaseNum}-${planNum}-${taskNum}: FAILED`);
|
|
142
181
|
|
|
143
182
|
// Check if we should create a fix plan
|
|
144
183
|
const logContent = fs.readFileSync(LOG_FILE, "utf-8");
|
|
@@ -152,7 +191,7 @@ if (status === "pass") {
|
|
|
152
191
|
if (taskFailures.length >= 3) {
|
|
153
192
|
console.error(`\n❌ HARD STOP: task ${phaseNum}-${planNum}-${taskNum} has failed ${taskFailures.length} times.`);
|
|
154
193
|
console.error(` Do NOT re-dispatch the implementer. Escalate: report to the user or create a fix plan:`);
|
|
155
|
-
console.error(` draht create-fix-plan ${phaseNum} ${planNum} "Task ${taskNum} failed repeatedly"`);
|
|
194
|
+
console.error(` draht-tools create-fix-plan ${phaseNum} ${planNum} "Task ${taskNum} failed repeatedly"`);
|
|
156
195
|
process.exit(1);
|
|
157
196
|
}
|
|
158
197
|
} else {
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
* Usage: node gsd-quality-gate.js [--strict] [--no-tests]
|
|
10
10
|
* --no-tests skips the test-suite run (used by the Stop hook, where the
|
|
11
11
|
* post-task hook and /verify-work own test execution).
|
|
12
|
+
* --checks-only runs configured type, lint, and test checks without workflow heuristics.
|
|
12
13
|
* Exit 0 = quality OK, Exit 1 = quality issues
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
const { execSync } = require("node:child_process");
|
|
16
17
|
const fs = require("node:fs");
|
|
17
18
|
const path = require("node:path");
|
|
19
|
+
const { runChecks } = require("./checks-runtime.cjs");
|
|
18
20
|
|
|
19
21
|
// ── Toolchain detection — mirrors src/gsd/hook-utils.ts ──────────────────────
|
|
20
22
|
function detectToolchain(cwd) {
|
|
@@ -66,164 +68,248 @@ function loadDomainContent(cwd) {
|
|
|
66
68
|
return "";
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
// Match the compiler's upward search without invoking a missing tool in non-TS projects.
|
|
72
|
+
function hasTypeScriptConfig(cwd) {
|
|
73
|
+
let directory = cwd;
|
|
74
|
+
while (true) {
|
|
75
|
+
if (fs.existsSync(path.join(directory, "tsconfig.json"))) return true;
|
|
76
|
+
const parent = path.dirname(directory);
|
|
77
|
+
if (parent === directory) return false;
|
|
78
|
+
directory = parent;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function lintCommand(cwd, pm) {
|
|
83
|
+
let directory = cwd;
|
|
84
|
+
let biome = false;
|
|
85
|
+
while (true) {
|
|
86
|
+
biome ||= ["biome.json", "biome.jsonc"].some((file) => fs.existsSync(path.join(directory, file)));
|
|
87
|
+
const packagePath = path.join(directory, "package.json");
|
|
88
|
+
if (fs.existsSync(packagePath)) {
|
|
89
|
+
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
|
90
|
+
if (typeof pkg.scripts?.lint === "string" && pkg.scripts.lint.trim()) return `${pm} run lint`;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
const parent = path.dirname(directory);
|
|
94
|
+
if (parent === directory) break;
|
|
95
|
+
directory = parent;
|
|
96
|
+
}
|
|
97
|
+
return biome ? `${pm === "bun" ? "bunx" : "npx --no-install"} biome check . --error-on-warnings` : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function hasTestCommand(cwd, pm) {
|
|
101
|
+
if (pm === "bun") return true;
|
|
102
|
+
let directory = cwd;
|
|
103
|
+
while (true) {
|
|
104
|
+
const packagePath = path.join(directory, "package.json");
|
|
105
|
+
if (fs.existsSync(packagePath)) {
|
|
106
|
+
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
|
107
|
+
return typeof pkg.scripts?.test === "string" && pkg.scripts.test.trim().length > 0;
|
|
108
|
+
}
|
|
109
|
+
const parent = path.dirname(directory);
|
|
110
|
+
if (parent === directory) return false;
|
|
111
|
+
directory = parent;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function commandFailureReason(error) {
|
|
116
|
+
if (error.code === "ETIMEDOUT") return "timed out";
|
|
117
|
+
if (error.signal) return `signal ${error.signal}`;
|
|
118
|
+
if (typeof error.status === "number") return `exit ${error.status}`;
|
|
119
|
+
return error.code || error.message || "unknown process error";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function commandFailureOutput(error) {
|
|
123
|
+
return [error.stdout, error.stderr].filter(Boolean).join("\n").trim();
|
|
124
|
+
}
|
|
125
|
+
|
|
69
126
|
// ── Main ──────────────────────────────────────────────────────────────────────
|
|
70
127
|
const cwd = process.cwd();
|
|
128
|
+
const projectChecks = runChecks({ cwd, force: process.argv.includes("--force") });
|
|
129
|
+
if (projectChecks.configured || projectChecks.status === "failed") {
|
|
130
|
+
console.log(projectChecks.summary);
|
|
131
|
+
for (const check of projectChecks.checks) if (check.output) console.log(`${check.name}: ${check.output}`);
|
|
132
|
+
}
|
|
71
133
|
const toolchain = detectToolchain(cwd);
|
|
72
134
|
const hookConfig = readHookConfig(cwd);
|
|
73
135
|
const strict = process.argv.includes("--strict") || hookConfig.qualityGateStrict;
|
|
74
136
|
const skipTests = process.argv.includes("--no-tests");
|
|
75
|
-
const
|
|
137
|
+
const checksOnly = process.argv.includes("--checks-only");
|
|
138
|
+
const issues = projectChecks.status === "failed" ? [{ severity: "error", message: projectChecks.summary }] : [];
|
|
76
139
|
|
|
140
|
+
if (!projectChecks.configured) {
|
|
77
141
|
// 1. TypeScript check
|
|
142
|
+
if (hasTypeScriptConfig(cwd)) {
|
|
143
|
+
try {
|
|
144
|
+
const tsCmd = toolchain.pm === "bun" ? "bun run tsc --noEmit 2>&1" : "npx tsc --noEmit 2>&1";
|
|
145
|
+
execSync(tsCmd, { timeout: 60000, encoding: "utf-8", cwd });
|
|
146
|
+
} catch (error) {
|
|
147
|
+
const output = commandFailureOutput(error);
|
|
148
|
+
const errorLines = output.split("\n").filter((line) => /error TS/.test(line));
|
|
149
|
+
issues.push({
|
|
150
|
+
severity: strict ? "error" : "warning",
|
|
151
|
+
message: errorLines.length > 0
|
|
152
|
+
? `${errorLines.length} TypeScript error(s)`
|
|
153
|
+
: `TypeScript command failed (${commandFailureReason(error)})`,
|
|
154
|
+
details: (errorLines.length > 0 ? errorLines.join("\n") : output).slice(0, 500),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
console.log("TypeScript check skipped: no tsconfig.json");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 2. Respect the package's lint command; use Biome directly only when configured.
|
|
78
162
|
try {
|
|
79
|
-
const
|
|
80
|
-
execSync(
|
|
163
|
+
const lint = lintCommand(cwd, toolchain.pm);
|
|
164
|
+
if (lint) execSync(`${lint} 2>&1`, { timeout: 30000, encoding: "utf-8", cwd });
|
|
165
|
+
else console.log("Lint check skipped: no applicable lint script or Biome configuration");
|
|
81
166
|
} catch (error) {
|
|
82
|
-
const output = error
|
|
83
|
-
|
|
84
|
-
if (errorLines.length > 0) {
|
|
85
|
-
issues.push({ severity: strict ? "error" : "warning", message: `${errorLines.length} TypeScript error(s)`, details: errorLines.join("\n").slice(0, 500) });
|
|
86
|
-
}
|
|
167
|
+
const output = commandFailureOutput(error);
|
|
168
|
+
issues.push({ severity: strict ? "error" : "warning", message: "Lint issues", details: output.slice(0, 500) });
|
|
87
169
|
}
|
|
88
170
|
|
|
89
|
-
//
|
|
90
|
-
if (
|
|
171
|
+
// 3. Run tests. Nonzero exits always fail; reporter text adds detail.
|
|
172
|
+
if (!skipTests) {
|
|
91
173
|
try {
|
|
92
|
-
|
|
174
|
+
if (hasTestCommand(cwd, toolchain.pm)) {
|
|
175
|
+
const testOutput = execSync(`${toolchain.testCmd} 2>&1`, { timeout: 120000, encoding: "utf-8", cwd });
|
|
176
|
+
const failMatch = testOutput.match(/(\d+) fail/);
|
|
177
|
+
if (failMatch && parseInt(failMatch[1], 10) > 0) {
|
|
178
|
+
issues.push({ severity: strict ? "error" : "warning", message: `${failMatch[1]} test(s) failing` });
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
console.log("Tests skipped: no package test script");
|
|
182
|
+
}
|
|
93
183
|
} catch (error) {
|
|
94
|
-
const output = error
|
|
95
|
-
|
|
184
|
+
const output = commandFailureOutput(error);
|
|
185
|
+
const failMatch = output.match(/(\d+) fail/);
|
|
186
|
+
issues.push({
|
|
187
|
+
severity: strict ? "error" : "warning",
|
|
188
|
+
message: failMatch && parseInt(failMatch[1], 10) > 0
|
|
189
|
+
? `${failMatch[1]} test(s) failing`
|
|
190
|
+
: `Test command failed (${commandFailureReason(error)})`,
|
|
191
|
+
details: output.slice(0, 500),
|
|
192
|
+
});
|
|
96
193
|
}
|
|
97
194
|
}
|
|
98
195
|
|
|
99
|
-
// 3. Run tests
|
|
100
|
-
if (!skipTests) try {
|
|
101
|
-
const testOutput = execSync(`${toolchain.testCmd} 2>&1`, { timeout: 120000, encoding: "utf-8", cwd });
|
|
102
|
-
const failMatch = testOutput.match(/(\d+) fail/);
|
|
103
|
-
if (failMatch && parseInt(failMatch[1], 10) > 0) {
|
|
104
|
-
issues.push({ severity: strict ? "error" : "warning", message: `${failMatch[1]} test(s) failing` });
|
|
105
|
-
}
|
|
106
|
-
} catch (error) {
|
|
107
|
-
const output = error.stdout || error.stderr || "";
|
|
108
|
-
const failMatch = output.match(/(\d+) fail/);
|
|
109
|
-
if (failMatch && parseInt(failMatch[1], 10) > 0) {
|
|
110
|
-
issues.push({ severity: strict ? "error" : "warning", message: `${failMatch[1]} test(s) failing` });
|
|
111
|
-
}
|
|
112
196
|
}
|
|
113
197
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
198
|
+
if (!checksOnly) {
|
|
199
|
+
// 4. Check for console.log in source files (not tests)
|
|
200
|
+
try {
|
|
201
|
+
const result = execSync(
|
|
202
|
+
"grep -rn 'console\\.log' src/ --include='*.ts' --include='*.tsx' 2>/dev/null | grep -v '// debug' | head -5",
|
|
203
|
+
{ encoding: "utf-8", cwd }
|
|
204
|
+
).trim();
|
|
205
|
+
if (result) {
|
|
206
|
+
issues.push({ severity: "warning", message: "console.log found in source", details: result });
|
|
207
|
+
}
|
|
208
|
+
} catch { /* grep returns 1 when no match — that's fine */ }
|
|
209
|
+
|
|
210
|
+
// 5. Domain glossary compliance (checks DOMAIN-MODEL.md, falls back to DOMAIN.md)
|
|
211
|
+
const domainContent = loadDomainContent(cwd);
|
|
212
|
+
if (domainContent) {
|
|
213
|
+
try {
|
|
214
|
+
const glossaryTerms = extractGlossaryTerms(domainContent);
|
|
215
|
+
const changedFiles = execSync(
|
|
216
|
+
"git diff --cached --name-only 2>/dev/null || git diff --name-only HEAD~1",
|
|
217
|
+
{ encoding: "utf-8", cwd }
|
|
218
|
+
).trim().split("\n").filter((f) => f.endsWith(".ts") || f.endsWith(".tsx"));
|
|
219
|
+
|
|
220
|
+
const unknownTerms = [];
|
|
221
|
+
for (const file of changedFiles) {
|
|
222
|
+
if (!fs.existsSync(path.join(cwd, file))) continue;
|
|
223
|
+
const src = fs.readFileSync(path.join(cwd, file), "utf-8");
|
|
224
|
+
const declarations = [...src.matchAll(/(?:class|interface|type|enum)\s+([A-Z][a-zA-Z0-9]+)/g)].map((m) => m[1]);
|
|
225
|
+
for (const term of declarations) {
|
|
226
|
+
if (!glossaryTerms.has(term)) unknownTerms.push(`${file}: ${term}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (unknownTerms.length > 0) {
|
|
230
|
+
issues.push({
|
|
231
|
+
severity: hookConfig.tddMode === "strict" ? "error" : "warning",
|
|
232
|
+
message: `${unknownTerms.length} PascalCase type(s) not in domain glossary (DOMAIN-MODEL.md)`,
|
|
233
|
+
details: unknownTerms.slice(0, 5).join(", "),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
} catch { /* ignore */ }
|
|
122
237
|
}
|
|
123
|
-
} catch { /* grep returns 1 when no match — that's fine */ }
|
|
124
238
|
|
|
125
|
-
//
|
|
126
|
-
const domainContent = loadDomainContent(cwd);
|
|
127
|
-
if (domainContent) {
|
|
239
|
+
// 6. Bounded context boundary check — flag suspicious cross-directory imports
|
|
128
240
|
try {
|
|
129
|
-
const
|
|
130
|
-
const changedFiles = execSync(
|
|
241
|
+
const changedSrcFiles = execSync(
|
|
131
242
|
"git diff --cached --name-only 2>/dev/null || git diff --name-only HEAD~1",
|
|
132
243
|
{ encoding: "utf-8", cwd }
|
|
133
|
-
).trim().split("\n").filter((f) => f.endsWith(".ts") || f.endsWith(".tsx"));
|
|
244
|
+
).trim().split("\n").filter((f) => /^src\/[^/]+\//.test(f) && (f.endsWith(".ts") || f.endsWith(".tsx")));
|
|
134
245
|
|
|
135
|
-
const
|
|
136
|
-
for (const file of
|
|
246
|
+
const crossContextImports = [];
|
|
247
|
+
for (const file of changedSrcFiles) {
|
|
137
248
|
if (!fs.existsSync(path.join(cwd, file))) continue;
|
|
249
|
+
const ownContext = file.split("/")[1];
|
|
138
250
|
const src = fs.readFileSync(path.join(cwd, file), "utf-8");
|
|
139
|
-
const
|
|
140
|
-
for (const
|
|
141
|
-
|
|
251
|
+
const imports = [...src.matchAll(/from\s+['"](\.\.\/.+?)['"]/g)].map((m) => m[1]);
|
|
252
|
+
for (const imp of imports) {
|
|
253
|
+
const resolved = path.normalize(path.join(path.dirname(file), imp));
|
|
254
|
+
const parts = resolved.split(path.sep);
|
|
255
|
+
const srcIdx = parts.indexOf("src");
|
|
256
|
+
if (srcIdx !== -1 && parts[srcIdx + 1] && parts[srcIdx + 1] !== ownContext) {
|
|
257
|
+
crossContextImports.push(`${file} → ${parts.slice(srcIdx).join("/")}`);
|
|
258
|
+
}
|
|
142
259
|
}
|
|
143
260
|
}
|
|
144
|
-
if (
|
|
261
|
+
if (crossContextImports.length > 0) {
|
|
145
262
|
issues.push({
|
|
146
|
-
severity:
|
|
147
|
-
message: `${
|
|
148
|
-
details:
|
|
263
|
+
severity: "warning",
|
|
264
|
+
message: `${crossContextImports.length} suspicious cross-context import(s) detected`,
|
|
265
|
+
details: crossContextImports.slice(0, 3).join("; "),
|
|
149
266
|
});
|
|
150
267
|
}
|
|
151
268
|
} catch { /* ignore */ }
|
|
152
|
-
}
|
|
153
269
|
|
|
154
|
-
//
|
|
155
|
-
try {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
270
|
+
// 7. TDD health — check test-to-source file ratio
|
|
271
|
+
try {
|
|
272
|
+
const allSrc = execSync(
|
|
273
|
+
"find src -name '*.ts' -not -name '*.test.ts' -not -name '*.spec.ts' 2>/dev/null | wc -l",
|
|
274
|
+
{ encoding: "utf-8", cwd }
|
|
275
|
+
).trim();
|
|
276
|
+
const allTests = execSync(
|
|
277
|
+
"find src -name '*.test.ts' -o -name '*.spec.ts' 2>/dev/null | wc -l",
|
|
278
|
+
{ encoding: "utf-8", cwd }
|
|
279
|
+
).trim();
|
|
280
|
+
const srcCount = parseInt(allSrc, 10) || 0;
|
|
281
|
+
const testCount = parseInt(allTests, 10) || 0;
|
|
282
|
+
if (srcCount > 0) {
|
|
283
|
+
const ratio = testCount / srcCount;
|
|
284
|
+
if (ratio < 0.3) {
|
|
285
|
+
issues.push({
|
|
286
|
+
severity: "warning",
|
|
287
|
+
message: `TDD health: test-to-source ratio is ${(ratio * 100).toFixed(0)}% (${testCount} tests / ${srcCount} sources) — target ≥ 30%`,
|
|
288
|
+
});
|
|
173
289
|
}
|
|
174
290
|
}
|
|
175
|
-
}
|
|
176
|
-
if (crossContextImports.length > 0) {
|
|
177
|
-
issues.push({
|
|
178
|
-
severity: "warning",
|
|
179
|
-
message: `${crossContextImports.length} suspicious cross-context import(s) detected`,
|
|
180
|
-
details: crossContextImports.slice(0, 3).join("; "),
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
} catch { /* ignore */ }
|
|
184
|
-
|
|
185
|
-
// 7. TDD health — check test-to-source file ratio
|
|
186
|
-
try {
|
|
187
|
-
const allSrc = execSync(
|
|
188
|
-
"find src -name '*.ts' -not -name '*.test.ts' -not -name '*.spec.ts' 2>/dev/null | wc -l",
|
|
189
|
-
{ encoding: "utf-8", cwd }
|
|
190
|
-
).trim();
|
|
191
|
-
const allTests = execSync(
|
|
192
|
-
"find src -name '*.test.ts' -o -name '*.spec.ts' 2>/dev/null | wc -l",
|
|
193
|
-
{ encoding: "utf-8", cwd }
|
|
194
|
-
).trim();
|
|
195
|
-
const srcCount = parseInt(allSrc, 10) || 0;
|
|
196
|
-
const testCount = parseInt(allTests, 10) || 0;
|
|
197
|
-
if (srcCount > 0) {
|
|
198
|
-
const ratio = testCount / srcCount;
|
|
199
|
-
if (ratio < 0.3) {
|
|
200
|
-
issues.push({
|
|
201
|
-
severity: "warning",
|
|
202
|
-
message: `TDD health: test-to-source ratio is ${(ratio * 100).toFixed(0)}% (${testCount} tests / ${srcCount} sources) — target ≥ 30%`,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
} catch { /* ignore — src/ may not exist */ }
|
|
291
|
+
} catch { /* ignore — src/ may not exist */ }
|
|
207
292
|
|
|
208
|
-
// 8. Check for TODO/FIXME/HACK comments in changed files
|
|
209
|
-
try {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
293
|
+
// 8. Check for TODO/FIXME/HACK comments in changed files
|
|
294
|
+
try {
|
|
295
|
+
const diff = execSync(
|
|
296
|
+
"git diff --cached --name-only 2>/dev/null || git diff --name-only HEAD~1",
|
|
297
|
+
{ encoding: "utf-8", cwd }
|
|
298
|
+
).trim();
|
|
299
|
+
if (diff) {
|
|
300
|
+
const files = diff.split("\n").filter((f) => f.endsWith(".ts") || f.endsWith(".tsx"));
|
|
301
|
+
for (const file of files) {
|
|
302
|
+
try {
|
|
303
|
+
const content = fs.readFileSync(path.join(cwd, file), "utf-8");
|
|
304
|
+
const todos = content.match(/\/\/\s*(TODO|FIXME|HACK|XXX):/gi) || [];
|
|
305
|
+
if (todos.length > 0) {
|
|
306
|
+
issues.push({ severity: "info", message: `${file}: ${todos.length} TODO/FIXME comment(s)` });
|
|
307
|
+
}
|
|
308
|
+
} catch { /* file may not exist */ }
|
|
309
|
+
}
|
|
224
310
|
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
311
|
+
} catch { /* ignore */ }
|
|
312
|
+
}
|
|
227
313
|
|
|
228
314
|
// Output
|
|
229
315
|
const errors = issues.filter((i) => i.severity === "error");
|
|
@@ -4,17 +4,51 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* UserPromptSubmit Hook
|
|
6
6
|
* Injects minimal draht planning context before each user prompt is sent to the model.
|
|
7
|
-
*
|
|
7
|
+
* Opt in with hooks.planningContext: true in .planning/config.json.
|
|
8
8
|
* Keep output tiny — this runs on every prompt.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
const fs = require("node:fs");
|
|
12
12
|
const path = require("node:path");
|
|
13
|
+
const { stripVTControlCharacters } = require("node:util");
|
|
14
|
+
|
|
15
|
+
function cleanLine(value) {
|
|
16
|
+
return stripVTControlCharacters(value).replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").replace(/\s+/g, " ").trim();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readField(state, name) {
|
|
20
|
+
const lines = state.split(/\r\n?|\n|\u2028|\u2029/);
|
|
21
|
+
const inline = new RegExp(`^(?:## )?${name}: *(.*)$`);
|
|
22
|
+
for (let index = 0; index < lines.length; index++) {
|
|
23
|
+
const line = cleanLine(lines[index]);
|
|
24
|
+
const match = line.match(inline);
|
|
25
|
+
if (match?.[1]) return match[1];
|
|
26
|
+
if (line !== `## ${name}` && line !== `## ${name}:`) {
|
|
27
|
+
if (match) return "";
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
for (const following of lines.slice(index + 1)) {
|
|
31
|
+
const value = cleanLine(following);
|
|
32
|
+
if (/^#{1,6} |^(?:Current Phase|Status):/.test(value)) return "";
|
|
33
|
+
if (value) return value;
|
|
34
|
+
}
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function shorten(value, limit) {
|
|
41
|
+
const characters = Array.from(value);
|
|
42
|
+
return characters.length > limit ? `${characters.slice(0, limit - 1).join("").trimEnd()}…` : value;
|
|
43
|
+
}
|
|
13
44
|
|
|
14
45
|
const cwd = process.cwd();
|
|
15
46
|
const PLANNING = path.join(cwd, ".planning");
|
|
16
47
|
|
|
17
|
-
|
|
48
|
+
try {
|
|
49
|
+
const config = JSON.parse(fs.readFileSync(path.join(PLANNING, "config.json"), "utf-8"));
|
|
50
|
+
if (config?.hooks?.planningContext !== true) process.exit(0);
|
|
51
|
+
} catch {
|
|
18
52
|
process.exit(0);
|
|
19
53
|
}
|
|
20
54
|
|
|
@@ -25,11 +59,11 @@ if (!fs.existsSync(statePath)) {
|
|
|
25
59
|
|
|
26
60
|
try {
|
|
27
61
|
const state = fs.readFileSync(statePath, "utf-8");
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
62
|
+
const phase = shorten(readField(state, "Current Phase"), 64);
|
|
63
|
+
const status = shorten(readField(state, "Status"), 120);
|
|
64
|
+
if (phase && status) {
|
|
31
65
|
// Print a single-line reminder. Codex prepends stdout to the prompt context.
|
|
32
|
-
console.log(`[draht] ${
|
|
66
|
+
console.log(`[draht] ${phase} — ${status}`);
|
|
33
67
|
}
|
|
34
68
|
} catch {}
|
|
35
69
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* (goal-drift guard — the spec reaches every session, not just milestones)
|
|
10
10
|
* - Surfaces the most recent lessons from STATE.md ## Lessons
|
|
11
11
|
* - Flags CONTINUE-HERE.md if the previous session was paused
|
|
12
|
-
* -
|
|
12
|
+
* - Opt in with hooks.planningContext: true in .planning/config.json
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
const fs = require("node:fs");
|
|
@@ -18,8 +18,10 @@ const path = require("node:path");
|
|
|
18
18
|
const cwd = process.cwd();
|
|
19
19
|
const PLANNING = path.join(cwd, ".planning");
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
try {
|
|
22
|
+
const config = JSON.parse(fs.readFileSync(path.join(PLANNING, "config.json"), "utf-8"));
|
|
23
|
+
if (config?.hooks?.planningContext !== true) process.exit(0);
|
|
24
|
+
} catch {
|
|
23
25
|
process.exit(0);
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -87,7 +89,7 @@ const continuePath = path.join(PLANNING, "CONTINUE-HERE.md");
|
|
|
87
89
|
if (fs.existsSync(continuePath)) {
|
|
88
90
|
lines.push("");
|
|
89
91
|
lines.push("CONTINUE-HERE.md present — the previous session was paused.");
|
|
90
|
-
lines.push("
|
|
92
|
+
lines.push("Read .planning/CONTINUE-HERE.md if relevant to the current task; /resume-work is available for explicit workflow continuation.");
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
if (lines.length > 0) {
|