@planu/cli 8.2.5 → 8.2.7
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/CHANGELOG.md +10 -0
- package/README.md +2 -2
- package/dist/sdd-engine/host-rule-pack.d.ts +1 -0
- package/dist/sdd-engine/host-rule-pack.js +44 -0
- package/dist/sdd-engine/task-window.d.ts +2 -1
- package/dist/sdd-engine/task-window.js +126 -38
- package/dist/sdd-engine/tools/execution-tools.js +2 -2
- package/dist/sdd-engine/tools/workspace-tools.js +3 -1
- package/dist/types/sdd-engine.d.ts +1 -1
- package/package.json +14 -14
- package/templates/cursor/hooks.json +18 -0
- package/templates/cursor/planu-guard.mjs +207 -0
- package/templates/skills/spec-executor.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [8.2.7] - 2026-09-29
|
|
4
|
+
|
|
5
|
+
- `sdd_complete_task` runs the task Verification command and stores that output; a missing or failing command leaves the checkbox open
|
|
6
|
+
- `sdd_init_workspace` installs a Cursor guard that denies native Write, StrReplace, Delete, and EditNotebook while a locked feature has an unchecked task, and denies `git --no-verify`
|
|
7
|
+
|
|
8
|
+
## [8.2.6] - 2026-09-29
|
|
9
|
+
|
|
10
|
+
- refresh in-range direct dependencies: MCP SDK 1.30.1, vitest 5.0.2, vite 8.3.1, typescript-eslint 8.70.1, prettier 3.9.9, knip 6.38.0, lint-staged 17.6.0, commitlint 21.2.3, and secretlint 13.0.6
|
|
11
|
+
- keep @types/node on 22.20.4 and engines on Node >=22.13.0
|
|
12
|
+
|
|
3
13
|
## [8.2.5] - 2026-09-24
|
|
4
14
|
|
|
5
15
|
- `sdd_complete_task` keeps up to 500 characters of verification evidence, cut at a word boundary, and stores `$` sequences literally
|
package/README.md
CHANGED
|
@@ -114,10 +114,10 @@ The published server asks the host for MCP roots and binds to the open project t
|
|
|
114
114
|
sdd_init_workspace → sdd_create_feature → architect trinity → sdd_lock_spec → execute tasks → verify → git-janitor
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
1. **Initialize:** `sdd_init_workspace` writes `.sdd/features`, stamps host rules,
|
|
117
|
+
1. **Initialize:** `sdd_init_workspace` writes `.sdd/features`, stamps host rules, copies cognitive skills into `.claude/skills/`, `.cursor/skills/`, `.agents/skills/`, and `.gemini/skills/`, and installs the Cursor write guard. Existing `AGENTS.md` is preserved unless `force: true` or it is still a v6 host contract.
|
|
118
118
|
2. **Architect:** Adopt `spec-architect.md`. Call `sdd_create_feature` with a title and omit `id` to reserve the next global `FEAT-NNNN-TITLE` identifier. Explicit `FEAT-*` IDs remain supported for imports; `SPEC-001` is rejected.
|
|
119
119
|
3. **Lock:** `sdd_lock_spec` hashes spec, plan, and tasks. It rejects empty skeletons. Reseal after review with `relock: true` and `reason`.
|
|
120
|
-
4. **Execute:** `sdd_get_active_task` → `sdd_apply_file_patch` → `sdd_complete_task`. CREATE, MODIFY, and READ_ONLY may use `*` / `**` (dot-prefixed segments require an exact entry). DELETE is an exact path. A CREATE entry accepts search/replace patches after the file exists. `.sdd/` and `.git/` are never writable.
|
|
120
|
+
4. **Execute:** `sdd_get_active_task` → `sdd_apply_file_patch` → `sdd_complete_task`. `sdd_complete_task` runs the task Verification command and stores that output. CREATE, MODIFY, and READ_ONLY may use `*` / `**` (dot-prefixed segments require an exact entry). DELETE is an exact path. A CREATE entry accepts search/replace patches after the file exists. `.sdd/` and `.git/` are never writable.
|
|
121
121
|
5. **Verify:** independently prove acceptance criteria with `verification-auditor.md`.
|
|
122
122
|
6. **Janitor:** prune local branches and orphaned worktrees only with authorization.
|
|
123
123
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function isStaleV6HostDoc(content: string): boolean;
|
|
2
2
|
export declare function copyGlobalRules(workspaceRoot: string, force?: boolean): Promise<'preserved' | 'replaced' | 'created'>;
|
|
3
3
|
export declare function installHostSkillPack(workspaceRoot: string): Promise<string[]>;
|
|
4
|
+
export declare function installCursorGuard(workspaceRoot: string): Promise<string[]>;
|
|
4
5
|
export declare function installHostRulePack(workspaceRoot: string): Promise<string[]>;
|
|
5
6
|
//# sourceMappingURL=host-rule-pack.d.ts.map
|
|
@@ -99,6 +99,50 @@ export async function installHostSkillPack(workspaceRoot) {
|
|
|
99
99
|
}
|
|
100
100
|
return written;
|
|
101
101
|
}
|
|
102
|
+
function readCursorHooks(raw) {
|
|
103
|
+
const parsed = JSON.parse(raw);
|
|
104
|
+
if (typeof parsed !== 'object' || parsed === null || !('hooks' in parsed)) {
|
|
105
|
+
throw new Error('Cursor hooks.json must be an object with a hooks map');
|
|
106
|
+
}
|
|
107
|
+
const record = parsed;
|
|
108
|
+
if (typeof record.hooks !== 'object' || record.hooks === null || Array.isArray(record.hooks)) {
|
|
109
|
+
throw new Error('Cursor hooks.json must be an object with a hooks map');
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
version: typeof record.version === 'number' ? record.version : 1,
|
|
113
|
+
hooks: record.hooks,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function isMissingFile(error) {
|
|
117
|
+
return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT';
|
|
118
|
+
}
|
|
119
|
+
export async function installCursorGuard(workspaceRoot) {
|
|
120
|
+
const scriptSrc = path.join(TEMPLATES_ROOT, 'cursor', 'planu-guard.mjs');
|
|
121
|
+
const hooksSrc = path.join(TEMPLATES_ROOT, 'cursor', 'hooks.json');
|
|
122
|
+
const scriptDest = path.join(workspaceRoot, '.cursor', 'hooks', 'planu-guard.mjs');
|
|
123
|
+
const hooksDest = path.join(workspaceRoot, '.cursor', 'hooks.json');
|
|
124
|
+
await fs.mkdir(path.dirname(scriptDest), { recursive: true });
|
|
125
|
+
await fs.copyFile(scriptSrc, scriptDest);
|
|
126
|
+
await fs.chmod(scriptDest, 0o755);
|
|
127
|
+
const incoming = readCursorHooks(await fs.readFile(hooksSrc, 'utf8'));
|
|
128
|
+
let current = { version: 1, hooks: {} };
|
|
129
|
+
try {
|
|
130
|
+
current = readCursorHooks(await fs.readFile(hooksDest, 'utf8'));
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (!isMissingFile(error)) {
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const hooks = { ...current.hooks };
|
|
138
|
+
for (const [event, entries] of Object.entries(incoming.hooks)) {
|
|
139
|
+
const existing = hooks[event] ?? [];
|
|
140
|
+
const commands = new Set(existing.map((entry) => entry.command));
|
|
141
|
+
hooks[event] = [...existing, ...entries.filter((entry) => !commands.has(entry.command))];
|
|
142
|
+
}
|
|
143
|
+
await fs.writeFile(hooksDest, `${JSON.stringify({ version: current.version, hooks }, null, 2)}\n`, 'utf8');
|
|
144
|
+
return ['.cursor/hooks.json', '.cursor/hooks/planu-guard.mjs'];
|
|
145
|
+
}
|
|
102
146
|
export async function installHostRulePack(workspaceRoot) {
|
|
103
147
|
const body = await readHostBody();
|
|
104
148
|
const cursorRule = `---
|
|
@@ -4,6 +4,7 @@ export declare class TaskWindowManager {
|
|
|
4
4
|
private buildActiveTaskResult;
|
|
5
5
|
private parseTasks;
|
|
6
6
|
private extractTaskId;
|
|
7
|
-
completeTask(tasksFilePath: string, taskId: string,
|
|
7
|
+
completeTask(tasksFilePath: string, taskId: string, workspaceRoot: string, _verificationOutput: string): Promise<SddResult<CompleteTaskResult>>;
|
|
8
8
|
}
|
|
9
|
+
export declare function verificationCommand(taskMarkdown: string): string | null;
|
|
9
10
|
//# sourceMappingURL=task-window.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import * as fs from 'node:fs/promises';
|
|
2
3
|
import * as path from 'node:path';
|
|
3
4
|
import { hashArtifact } from './lock-integrity.js';
|
|
@@ -96,50 +97,34 @@ export class TaskWindowManager {
|
|
|
96
97
|
}
|
|
97
98
|
return { id: `TASK-${index}`, title: rawTitle };
|
|
98
99
|
}
|
|
99
|
-
async completeTask(tasksFilePath, taskId,
|
|
100
|
+
async completeTask(tasksFilePath, taskId, workspaceRoot, _verificationOutput) {
|
|
100
101
|
let content;
|
|
101
102
|
try {
|
|
102
103
|
content = await fs.readFile(tasksFilePath, 'utf-8');
|
|
103
104
|
}
|
|
104
105
|
catch {
|
|
105
|
-
return
|
|
106
|
-
success: false,
|
|
107
|
-
error: {
|
|
108
|
-
code: 'ERR_TASK_NOT_FOUND',
|
|
109
|
-
message: `File tasks.md not found at: '${tasksFilePath}'.`,
|
|
110
|
-
trigger: 'sdd_complete_task',
|
|
111
|
-
},
|
|
112
|
-
};
|
|
106
|
+
return missingTasksFile(tasksFilePath);
|
|
113
107
|
}
|
|
114
|
-
const lines = content.split('\n');
|
|
115
108
|
const active = await this.getActiveTask(tasksFilePath);
|
|
116
109
|
if (!active.success) {
|
|
117
110
|
return active;
|
|
118
111
|
}
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
121
|
-
return
|
|
122
|
-
success: false,
|
|
123
|
-
error: {
|
|
124
|
-
code: 'ERR_TASK_OUT_OF_SEQUENCE',
|
|
125
|
-
message: `Task '${taskId}' is not active or was already completed.`,
|
|
126
|
-
trigger: 'sdd_complete_task',
|
|
127
|
-
details: { requestedTaskId: taskId, activeTaskId: activeId ?? null },
|
|
128
|
-
},
|
|
129
|
-
};
|
|
112
|
+
const activeTask = active.data.activeTask;
|
|
113
|
+
if (activeTask?.taskId.toUpperCase() !== taskId.toUpperCase()) {
|
|
114
|
+
return taskOutOfSequence(taskId, activeTask?.taskId ?? null);
|
|
130
115
|
}
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
for (let i = 0; i < lines.length; i++) {
|
|
135
|
-
const line = lines[i];
|
|
136
|
-
if (line !== undefined && regexExact.test(line)) {
|
|
137
|
-
lines[i] = line.replace(regexExact, (_, open, rest) => `${open}x${rest} — [Verified: ${cleanOutput}]`);
|
|
138
|
-
taskFound = true;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
116
|
+
const command = verificationCommand(activeTask.fullTaskMarkdown);
|
|
117
|
+
if (command === null) {
|
|
118
|
+
return verificationMissing();
|
|
141
119
|
}
|
|
142
|
-
|
|
120
|
+
const run = await runVerification(workspaceRoot, command);
|
|
121
|
+
if (!run.ok) {
|
|
122
|
+
return verificationFailed(run);
|
|
123
|
+
}
|
|
124
|
+
const lines = content.split('\n');
|
|
125
|
+
const cleanOutput = summarizeEvidence(run.output);
|
|
126
|
+
const marked = markTaskVerified(lines, taskId, cleanOutput);
|
|
127
|
+
if (!marked) {
|
|
143
128
|
return {
|
|
144
129
|
success: false,
|
|
145
130
|
error: {
|
|
@@ -150,22 +135,125 @@ export class TaskWindowManager {
|
|
|
150
135
|
},
|
|
151
136
|
};
|
|
152
137
|
}
|
|
153
|
-
|
|
154
|
-
await
|
|
138
|
+
const written = marked.join('\n');
|
|
139
|
+
await fs.writeFile(tasksFilePath, written, 'utf-8');
|
|
140
|
+
await refreshTasksHashIfLocked(tasksFilePath, written);
|
|
155
141
|
const checkRes = await this.getActiveTask(tasksFilePath);
|
|
156
|
-
const remainingTasks = checkRes.success && checkRes.data.activeTask
|
|
157
|
-
? checkRes.data.activeTask.totalTasks - checkRes.data.activeTask.completedTasks
|
|
158
|
-
: 0;
|
|
159
142
|
return {
|
|
160
143
|
success: true,
|
|
161
144
|
data: {
|
|
162
145
|
completedTaskId: taskId,
|
|
163
146
|
verificationSummary: cleanOutput,
|
|
164
|
-
remainingTasks,
|
|
147
|
+
remainingTasks: remainingTaskCount(checkRes),
|
|
165
148
|
},
|
|
166
149
|
};
|
|
167
150
|
}
|
|
168
151
|
}
|
|
152
|
+
function missingTasksFile(tasksFilePath) {
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
error: {
|
|
156
|
+
code: 'ERR_TASK_NOT_FOUND',
|
|
157
|
+
message: `File tasks.md not found at: '${tasksFilePath}'.`,
|
|
158
|
+
trigger: 'sdd_complete_task',
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function taskOutOfSequence(taskId, activeTaskId) {
|
|
163
|
+
return {
|
|
164
|
+
success: false,
|
|
165
|
+
error: {
|
|
166
|
+
code: 'ERR_TASK_OUT_OF_SEQUENCE',
|
|
167
|
+
message: `Task '${taskId}' is not active or was already completed.`,
|
|
168
|
+
trigger: 'sdd_complete_task',
|
|
169
|
+
details: { requestedTaskId: taskId, activeTaskId },
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function verificationMissing() {
|
|
174
|
+
return {
|
|
175
|
+
success: false,
|
|
176
|
+
error: {
|
|
177
|
+
code: 'ERR_VERIFICATION_MISSING',
|
|
178
|
+
message: 'The active task needs one Verification line whose command does not contain < or >.',
|
|
179
|
+
trigger: 'sdd_complete_task',
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function verificationFailed(run) {
|
|
184
|
+
return {
|
|
185
|
+
success: false,
|
|
186
|
+
error: {
|
|
187
|
+
code: 'ERR_VERIFICATION_FAILED',
|
|
188
|
+
message: run.output.trim() || `Verification command exited ${String(run.exitCode)}.`,
|
|
189
|
+
trigger: 'sdd_complete_task',
|
|
190
|
+
details: { exitCode: run.exitCode },
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function markTaskVerified(lines, taskId, cleanOutput) {
|
|
195
|
+
const regexExact = new RegExp(`^(\\s*[-*]\\s*\\[)[\\s/](\\]\\s*(?:${taskId}\\b|.*\\b${taskId}\\b.*))`, 'i');
|
|
196
|
+
const next = [...lines];
|
|
197
|
+
for (let i = 0; i < next.length; i++) {
|
|
198
|
+
const line = next[i];
|
|
199
|
+
if (line !== undefined && regexExact.test(line)) {
|
|
200
|
+
next[i] = line.replace(regexExact, (_, open, rest) => `${open}x${rest} — [Verified: ${cleanOutput}]`);
|
|
201
|
+
return next;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
function remainingTaskCount(checkRes) {
|
|
207
|
+
if (!checkRes.success || !checkRes.data.activeTask) {
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
return checkRes.data.activeTask.totalTasks - checkRes.data.activeTask.completedTasks;
|
|
211
|
+
}
|
|
212
|
+
const VERIFICATION_TIMEOUT_MS = 180_000;
|
|
213
|
+
export function verificationCommand(taskMarkdown) {
|
|
214
|
+
const line = taskMarkdown
|
|
215
|
+
.split('\n')
|
|
216
|
+
.map((entry) => entry.trim())
|
|
217
|
+
.find((entry) => /^verification:/iu.test(entry));
|
|
218
|
+
if (!line) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
const command = line.replace(/^verification:\s*/iu, '').trim();
|
|
222
|
+
if (command.length === 0 || command.includes('<') || command.includes('>')) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
return command;
|
|
226
|
+
}
|
|
227
|
+
function runVerification(cwd, command) {
|
|
228
|
+
return new Promise((resolve) => {
|
|
229
|
+
const child = spawn(command, {
|
|
230
|
+
cwd,
|
|
231
|
+
shell: true,
|
|
232
|
+
timeout: VERIFICATION_TIMEOUT_MS,
|
|
233
|
+
windowsHide: true,
|
|
234
|
+
});
|
|
235
|
+
let output = '';
|
|
236
|
+
const append = (chunk) => {
|
|
237
|
+
output += chunk.toString('utf8');
|
|
238
|
+
if (output.length > 100_000) {
|
|
239
|
+
output = output.slice(-100_000);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
child.stdout.on('data', append);
|
|
243
|
+
child.stderr.on('data', append);
|
|
244
|
+
child.on('error', (error) => {
|
|
245
|
+
resolve({ ok: false, exitCode: 1, output: error.message });
|
|
246
|
+
});
|
|
247
|
+
child.on('close', (code, signal) => {
|
|
248
|
+
const timedOut = signal === 'SIGTERM';
|
|
249
|
+
resolve({
|
|
250
|
+
ok: code === 0 && !timedOut,
|
|
251
|
+
exitCode: code,
|
|
252
|
+
output: timedOut ? `${output}\nverification timed out after 180 seconds` : output,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
}
|
|
169
257
|
const EVIDENCE_LIMIT = 500;
|
|
170
258
|
function summarizeEvidence(output) {
|
|
171
259
|
const collapsed = output.trim().replace(/\s+/g, ' ');
|
|
@@ -89,7 +89,7 @@ function registerApplyPatchTool(server, workspace) {
|
|
|
89
89
|
}
|
|
90
90
|
function registerCompleteTaskTool(server, workspace, taskWindow) {
|
|
91
91
|
server.registerTool('sdd_complete_task', {
|
|
92
|
-
description: '
|
|
92
|
+
description: 'Completes the active task by running its Verification command in the workspace and storing that output. verification_output is accepted and ignored.',
|
|
93
93
|
inputSchema: CompleteTaskInputSchema.shape,
|
|
94
94
|
}, async (rawArgs) => {
|
|
95
95
|
const args = CompleteTaskInputSchema.parse(rawArgs);
|
|
@@ -104,7 +104,7 @@ function registerCompleteTaskTool(server, workspace, taskWindow) {
|
|
|
104
104
|
return lockError;
|
|
105
105
|
}
|
|
106
106
|
const tasksPath = path.join(featDir, 'tasks.md');
|
|
107
|
-
const result = await taskWindow.completeTask(tasksPath, args.task_id, args.verification_output);
|
|
107
|
+
const result = await taskWindow.completeTask(tasksPath, args.task_id, resolved.workspaceRoot, args.verification_output);
|
|
108
108
|
return formatResult(result);
|
|
109
109
|
});
|
|
110
110
|
}
|
|
@@ -6,7 +6,7 @@ import { TaskWindowManager } from '../task-window.js';
|
|
|
6
6
|
import { formatResult } from './format-result.js';
|
|
7
7
|
import { homeFallbackFailure } from '../workspace-root.js';
|
|
8
8
|
import { writeLockedTrinity } from '../lock-integrity.js';
|
|
9
|
-
import { copyGlobalRules, installHostRulePack, installHostSkillPack } from '../host-rule-pack.js';
|
|
9
|
+
import { copyGlobalRules, installCursorGuard, installHostRulePack, installHostSkillPack, } from '../host-rule-pack.js';
|
|
10
10
|
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
const MISSING_SDD_HINT = 'No .sdd directory in the client project. Call sdd_init_workspace with scope=project. MCP hosts should advertise roots; do not pin PLANU_WORKSPACE globally.';
|
|
12
12
|
const LEGACY_SPECS_HINT = 'Planu ignores planu/specs. Do not create SPEC-* stubs or copy a FEAT into that tree. Retire host hooks that require planu/specs/SPEC-*/spec.md; the only contract is .sdd/features/FEAT-*.';
|
|
@@ -52,6 +52,7 @@ function registerInitTool(server, workspace) {
|
|
|
52
52
|
}
|
|
53
53
|
const agentsMd = await copyGlobalRules(resolved.workspaceRoot, args.force);
|
|
54
54
|
const hostRules = args.scope === 'project' ? await installHostRulePack(resolved.workspaceRoot) : [];
|
|
55
|
+
const cursorGuard = args.scope === 'project' ? await installCursorGuard(resolved.workspaceRoot) : [];
|
|
55
56
|
const hostSkills = args.scope === 'project' ? await installHostSkillPack(resolved.workspaceRoot) : [];
|
|
56
57
|
const hint = await composeWorkspaceHint(resolved.workspaceRoot, 'Commit .sdd/features with the project. Host quality gates must map .sdd/ as versioned documentation. Cursor, Claude, Gemini, and Codex load Planu skills from sdd_init_workspace host folders, not .sdd/skills.');
|
|
57
58
|
return formatResult({
|
|
@@ -68,6 +69,7 @@ function registerInitTool(server, workspace) {
|
|
|
68
69
|
agentsMd,
|
|
69
70
|
hostRules,
|
|
70
71
|
hostSkills,
|
|
72
|
+
cursorGuard,
|
|
71
73
|
versionedHint: hint,
|
|
72
74
|
},
|
|
73
75
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ArtifactType = 'spec' | 'plan' | 'tasks';
|
|
2
2
|
export type FilePermission = 'CREATE' | 'MODIFY' | 'READ_ONLY' | 'DELETE';
|
|
3
|
-
export type ErrorCode = 'ERR_FEATURE_NOT_FOUND' | 'ERR_FEATURE_ALREADY_EXISTS' | 'ERR_SPEC_NOT_LOCKED' | 'ERR_SPEC_ALREADY_LOCKED' | 'ERR_SPEC_DRIFT' | 'ERR_TASK_OUT_OF_SEQUENCE' | 'ERR_TASK_NOT_FOUND' | 'ERR_FILE_OUT_OF_MANIFEST' | 'ERR_PERMISSION_VIOLATION' | 'ERR_PATCH_FAILED' | 'ERR_INVALID_ARTIFACT' | 'ERR_INVALID_SLICE' | 'ERR_WORKSPACE_UNRESOLVED' | 'ERR_TRINITY_INCOMPLETE' | 'ERR_LOCK_REASON_REQUIRED';
|
|
3
|
+
export type ErrorCode = 'ERR_FEATURE_NOT_FOUND' | 'ERR_FEATURE_ALREADY_EXISTS' | 'ERR_SPEC_NOT_LOCKED' | 'ERR_SPEC_ALREADY_LOCKED' | 'ERR_SPEC_DRIFT' | 'ERR_TASK_OUT_OF_SEQUENCE' | 'ERR_TASK_NOT_FOUND' | 'ERR_FILE_OUT_OF_MANIFEST' | 'ERR_PERMISSION_VIOLATION' | 'ERR_PATCH_FAILED' | 'ERR_INVALID_ARTIFACT' | 'ERR_INVALID_SLICE' | 'ERR_WORKSPACE_UNRESOLVED' | 'ERR_TRINITY_INCOMPLETE' | 'ERR_LOCK_REASON_REQUIRED' | 'ERR_VERIFICATION_MISSING' | 'ERR_VERIFICATION_FAILED';
|
|
4
4
|
export interface SddErrorDetails {
|
|
5
5
|
code: ErrorCode;
|
|
6
6
|
message: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planu/cli",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.7",
|
|
4
4
|
"description": "Planu — MCP Server for Spec Driven Development. Cross-platform (Linux/macOS/Windows, x64/arm64).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -71,18 +71,18 @@
|
|
|
71
71
|
],
|
|
72
72
|
"license": "SEE LICENSE IN LICENSE",
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@modelcontextprotocol/sdk": "^1.30.
|
|
74
|
+
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
75
75
|
"zod": "^4.6.5"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@commitlint/cli": "^21.2.
|
|
79
|
-
"@commitlint/config-conventional": "^21.2.
|
|
78
|
+
"@commitlint/cli": "^21.2.3",
|
|
79
|
+
"@commitlint/config-conventional": "^21.2.3",
|
|
80
80
|
"@eslint/js": "^10.0.1",
|
|
81
|
-
"@secretlint/secretlint-rule-no-homedir": "^13.0.
|
|
82
|
-
"@secretlint/secretlint-rule-preset-recommend": "^13.0.
|
|
81
|
+
"@secretlint/secretlint-rule-no-homedir": "^13.0.6",
|
|
82
|
+
"@secretlint/secretlint-rule-preset-recommend": "^13.0.6",
|
|
83
83
|
"@types/node": "^22.20.4",
|
|
84
84
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
85
|
-
"@vitest/coverage-v8": "^5.0.
|
|
85
|
+
"@vitest/coverage-v8": "^5.0.2",
|
|
86
86
|
"eslint": "10.11.0",
|
|
87
87
|
"eslint-config-prettier": "^10.1.8",
|
|
88
88
|
"eslint-import-resolver-typescript": "^4.4.5",
|
|
@@ -90,18 +90,18 @@
|
|
|
90
90
|
"happy-dom": "^20.14.5",
|
|
91
91
|
"husky": "^9.1.7",
|
|
92
92
|
"jiti": "2.7.0",
|
|
93
|
-
"knip": "^6.
|
|
94
|
-
"lint-staged": "^17.
|
|
93
|
+
"knip": "^6.38.0",
|
|
94
|
+
"lint-staged": "^17.6.0",
|
|
95
95
|
"madge": "^8.0.0",
|
|
96
|
-
"prettier": "^3.9.
|
|
96
|
+
"prettier": "^3.9.9",
|
|
97
97
|
"qrcode": "1.5.4",
|
|
98
|
-
"secretlint": "^13.0.
|
|
98
|
+
"secretlint": "^13.0.6",
|
|
99
99
|
"tsc-alias": "^1.9.5",
|
|
100
100
|
"type-coverage": "^2.30.1",
|
|
101
101
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
102
|
-
"typescript-eslint": "^8.70.
|
|
103
|
-
"vite": "^8.3.
|
|
104
|
-
"vitest": "^5.0.
|
|
102
|
+
"typescript-eslint": "^8.70.1",
|
|
103
|
+
"vite": "^8.3.1",
|
|
104
|
+
"vitest": "^5.0.2"
|
|
105
105
|
},
|
|
106
106
|
"scripts": {
|
|
107
107
|
"check:tool-registration": "bash scripts/check-tool-registration.sh",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"hooks": {
|
|
4
|
+
"preToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"command": "node .cursor/hooks/planu-guard.mjs",
|
|
7
|
+
"matcher": "Write|StrReplace|Delete|EditNotebook",
|
|
8
|
+
"failClosed": true
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"beforeShellExecution": [
|
|
12
|
+
{
|
|
13
|
+
"command": "node .cursor/hooks/planu-guard.mjs",
|
|
14
|
+
"failClosed": true
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const UNCHECKED_TASK = /^[ \t]*[-*][ \t]*\[[ \t/]\][ \t]*(\S.*)$/m;
|
|
5
|
+
function skipsVerification(command) {
|
|
6
|
+
const quoted = [];
|
|
7
|
+
const flat = command
|
|
8
|
+
.replace(/\\\r?\n/g, ' ')
|
|
9
|
+
.replace(/"([^"]*)"|'([^']*)'/g, (_, double, single) => {
|
|
10
|
+
const content = double ?? single;
|
|
11
|
+
if (!/\s/.test(content)) {
|
|
12
|
+
return content;
|
|
13
|
+
}
|
|
14
|
+
quoted.push(content);
|
|
15
|
+
return content.startsWith('-') ? `${content.split(/\s/)[0]} ''` : "''";
|
|
16
|
+
});
|
|
17
|
+
if (quoted.some(skipsVerification)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return flat.split(/[;&|\n()`]+/).some((segment) => {
|
|
21
|
+
const tokens = segment.trim().split(/\s+/);
|
|
22
|
+
const git = tokens.findIndex((token) => token === 'git' || token.endsWith('/git'));
|
|
23
|
+
if (git === -1) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const args = tokens.slice(git + 1);
|
|
27
|
+
const flags = args.filter((_, i) => !takesValue(args[i - 1]));
|
|
28
|
+
return (
|
|
29
|
+
args.some((token) => token.toLowerCase().startsWith('core.hookspath=')) ||
|
|
30
|
+
flags.some((token) => token.startsWith('--no-veri')) ||
|
|
31
|
+
(args.includes('commit') && flags.some((token) => /^-[a-zA-Z]*n[a-zA-Z]*$/.test(token)))
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function takesValue(token) {
|
|
37
|
+
return token === '--message' || token === '--file' || /^-[a-zA-Z]*[mF]$/.test(token ?? '');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function findRoot(cwd) {
|
|
41
|
+
const start = realpathSync(cwd);
|
|
42
|
+
for (let dir = start; ; dir = path.dirname(dir)) {
|
|
43
|
+
if (existsSync(path.join(dir, '.sdd', 'features'))) {
|
|
44
|
+
return dir;
|
|
45
|
+
}
|
|
46
|
+
if (existsSync(path.join(dir, '.git')) || dir === path.dirname(dir)) {
|
|
47
|
+
return start;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function realTarget(cwd, target) {
|
|
53
|
+
const rest = [];
|
|
54
|
+
let current = path.resolve(cwd, target);
|
|
55
|
+
while (!existsSync(current) && current !== path.dirname(current)) {
|
|
56
|
+
rest.unshift(path.basename(current));
|
|
57
|
+
current = path.dirname(current);
|
|
58
|
+
}
|
|
59
|
+
return path.join(realpathSync(current), ...rest);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function executingFeatures(root) {
|
|
63
|
+
const featuresDir = path.join(root, '.sdd', 'features');
|
|
64
|
+
if (!existsSync(featuresDir)) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
return readdirSync(featuresDir, { withFileTypes: true })
|
|
68
|
+
.filter(
|
|
69
|
+
(entry) => entry.isDirectory() && existsSync(path.join(featuresDir, entry.name, '.lock')),
|
|
70
|
+
)
|
|
71
|
+
.map((entry) => {
|
|
72
|
+
const tasksPath = path.join(featuresDir, entry.name, 'tasks.md');
|
|
73
|
+
const match = existsSync(tasksPath)
|
|
74
|
+
? UNCHECKED_TASK.exec(readFileSync(tasksPath, 'utf8'))
|
|
75
|
+
: null;
|
|
76
|
+
return match ? { id: entry.name, task: match[1].trim() } : null;
|
|
77
|
+
})
|
|
78
|
+
.filter((feature) => feature !== null);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function deny(reason) {
|
|
82
|
+
process.stdout.write(
|
|
83
|
+
JSON.stringify({
|
|
84
|
+
hookSpecificOutput: {
|
|
85
|
+
hookEventName: 'PreToolUse',
|
|
86
|
+
permissionDecision: 'deny',
|
|
87
|
+
permissionDecisionReason: reason,
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isUnlockedTrinity(root, relative) {
|
|
94
|
+
const [sdd, features, id] = relative.split(path.sep);
|
|
95
|
+
return (
|
|
96
|
+
sdd === '.sdd' &&
|
|
97
|
+
features === 'features' &&
|
|
98
|
+
id !== undefined &&
|
|
99
|
+
!existsSync(path.join(root, '.sdd', 'features', id, '.lock'))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function writeReason(input) {
|
|
104
|
+
const target =
|
|
105
|
+
input.tool_input?.file_path ??
|
|
106
|
+
input.tool_input?.notebook_path ??
|
|
107
|
+
input.tool_input?.path ??
|
|
108
|
+
input.tool_input?.target_file;
|
|
109
|
+
if (!target) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const root = findRoot(input.cwd);
|
|
113
|
+
const features = executingFeatures(root);
|
|
114
|
+
if (features.length === 0) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const relative = path.relative(root, realTarget(input.cwd, target));
|
|
118
|
+
const outside =
|
|
119
|
+
relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
|
|
120
|
+
if (outside || isUnlockedTrinity(root, relative)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const ids = features.map((feature) => feature.id).join(', ');
|
|
124
|
+
return `Planu: ${ids} executing under Zero-Freedom. Apply changes with sdd_apply_file_patch, not native ${input.tool_name}.`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function preToolUse(input) {
|
|
128
|
+
if (input.tool_name === 'Bash' || input.tool_name === 'Shell') {
|
|
129
|
+
if (skipsVerification(input.tool_input?.command ?? '')) {
|
|
130
|
+
deny(
|
|
131
|
+
'Planu: --no-verify skips repository verification gates. Fix the failing check instead.',
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const reason = writeReason(input);
|
|
137
|
+
if (reason) {
|
|
138
|
+
deny(reason);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const CURSOR_WRITE_TOOLS = new Set([
|
|
143
|
+
'Write',
|
|
144
|
+
'StrReplace',
|
|
145
|
+
'Delete',
|
|
146
|
+
'EditNotebook',
|
|
147
|
+
'Edit',
|
|
148
|
+
'MultiEdit',
|
|
149
|
+
'NotebookEdit',
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
function cursorPermission(reason) {
|
|
153
|
+
process.stdout.write(
|
|
154
|
+
JSON.stringify(
|
|
155
|
+
reason
|
|
156
|
+
? { permission: 'deny', user_message: reason, agent_message: reason }
|
|
157
|
+
: { permission: 'allow' },
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function cursorHook(input) {
|
|
163
|
+
const cwd = typeof input.cwd === 'string' ? input.cwd : process.cwd();
|
|
164
|
+
if (typeof input.command === 'string') {
|
|
165
|
+
cursorPermission(
|
|
166
|
+
skipsVerification(input.command)
|
|
167
|
+
? 'Planu: --no-verify skips repository verification gates. Fix the failing check instead.'
|
|
168
|
+
: null,
|
|
169
|
+
);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const tool = typeof input.tool_name === 'string' ? input.tool_name : '';
|
|
173
|
+
if (!CURSOR_WRITE_TOOLS.has(tool)) {
|
|
174
|
+
cursorPermission(null);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
cursorPermission(writeReason({ ...input, cwd, tool_name: tool }));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function sessionStart(input) {
|
|
181
|
+
const features = executingFeatures(findRoot(input.cwd));
|
|
182
|
+
if (features.length === 0) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const active = features
|
|
186
|
+
.map((feature) => `${feature.id} active task "${feature.task}"`)
|
|
187
|
+
.join('; ');
|
|
188
|
+
process.stdout.write(
|
|
189
|
+
JSON.stringify({
|
|
190
|
+
hookSpecificOutput: {
|
|
191
|
+
hookEventName: 'SessionStart',
|
|
192
|
+
additionalContext: `Planu executing: ${active}. Resume with sdd_get_active_task and mutate files only through sdd_apply_file_patch.`,
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const modes = { 'pre-tool-use': preToolUse, 'session-start': sessionStart };
|
|
199
|
+
const mode = modes[process.argv[2]];
|
|
200
|
+
const rawInput = JSON.parse(readFileSync(0, 'utf8'));
|
|
201
|
+
if (mode) {
|
|
202
|
+
mode(rawInput);
|
|
203
|
+
} else if (process.argv[2] === undefined) {
|
|
204
|
+
cursorHook(rawInput);
|
|
205
|
+
} else {
|
|
206
|
+
throw new Error(`planu-guard: unknown mode ${process.argv[2]}`);
|
|
207
|
+
}
|
|
@@ -29,7 +29,7 @@ You do not make architectural decisions, you do not add dependencies, and you do
|
|
|
29
29
|
|
|
30
30
|
4. **Task Certification & Verification:**
|
|
31
31
|
- Execute the verification command specified in the task (e.g., `cargo test`, `pytest`, `go test`, `pnpm test`).
|
|
32
|
-
- Call `sdd_complete_task(feature_id, task_id, verification_output)
|
|
32
|
+
- Call `sdd_complete_task(feature_id, task_id, verification_output)`. The server runs the task Verification command and stores that output.
|
|
33
33
|
- Repeat from step 1 until `allCompleted` is true.
|
|
34
34
|
- Then adopt `git-janitor.md`.
|
|
35
35
|
|