Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions hooks/hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"hooks": [
{
"type": "command",
"command": "node ./hooks/session-start.mjs"
"command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/session-start.mjs"
}
]
}
Expand All @@ -14,9 +14,8 @@
{
"hooks": [
{
"type": "prompt",
"prompt": "Check if Specwright has active work. Read .specwright/state/workflow.json. If currentWork exists and currentWork.status is NOT 'shipped', 'abandoned', or null, respond: {\"ok\": false, \"reason\": \"Specwright has active work: [work-id] (status: [status], [completed]/[total] tasks done). Consider running /sw-status before ending this session, or /sw-status --reset to abandon.\"}. If no active work or file does not exist, respond: {\"ok\": true}. IMPORTANT: Check $ARGUMENTS — if stop_hook_active is true, always respond {\"ok\": true} to prevent loops.",
"timeout": 10
"type": "command",
"command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/session-stop.mjs"
}
]
}
Expand Down
38 changes: 38 additions & 0 deletions hooks/session-stop.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Specwright session-stop hook.
* Checks if there's active work and warns the user before ending the session.
* Deterministic — no LLM involved.
*/

import { readFileSync, existsSync } from 'fs';
import { join } from 'path';

const cwd = process.cwd();
const statePath = join(cwd, '.specwright', 'state', 'workflow.json');

if (!existsSync(statePath)) {
// No Specwright state — nothing to warn about
console.log(JSON.stringify({ ok: true }));
process.exit(0);
}

try {
const state = JSON.parse(readFileSync(statePath, 'utf-8'));
const work = state.currentWork;

if (work && !['shipped', 'abandoned', null].includes(work.status)) {
const completed = work.tasksCompleted?.length ?? 0;
const total = work.tasksTotal ?? '?';
console.log(JSON.stringify({
ok: false,
reason: `Specwright has active work: ${work.id} (status: ${work.status}, ${completed}/${total} tasks done). Consider running /sw-status before ending this session, or /sw-status --reset to abandon.`
}));
} else {
console.log(JSON.stringify({ ok: true }));
}
} catch {
// Don't block session end on read errors
console.log(JSON.stringify({ ok: true }));
}

process.exit(0);