@planu/cli 8.2.16 → 8.2.18
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 +20 -0
- package/README.md +15 -3
- package/dist/sdd-engine/cli.js +0 -0
- package/dist/sdd-engine/completion-guard.d.ts +28 -0
- package/dist/sdd-engine/completion-guard.js +320 -0
- package/dist/sdd-engine/completion-snapshot.d.ts +11 -0
- package/dist/sdd-engine/completion-snapshot.js +155 -0
- package/dist/sdd-engine/feature-authority.d.ts +20 -0
- package/dist/sdd-engine/feature-authority.js +199 -0
- package/dist/sdd-engine/feature-manifest.d.ts +6 -0
- package/dist/sdd-engine/feature-manifest.js +116 -0
- package/dist/sdd-engine/host-rule-pack.d.ts +1 -0
- package/dist/sdd-engine/host-rule-pack.js +63 -7
- package/dist/sdd-engine/lock-integrity.d.ts +3 -18
- package/dist/sdd-engine/lock-integrity.js +192 -217
- package/dist/sdd-engine/patch-sandbox.js +6 -14
- package/dist/sdd-engine/server.js +4 -6
- package/dist/sdd-engine/task-content.d.ts +8 -0
- package/dist/sdd-engine/task-content.js +132 -0
- package/dist/sdd-engine/task-failures.d.ts +12 -0
- package/dist/sdd-engine/task-failures.js +125 -0
- package/dist/sdd-engine/task-window.d.ts +10 -4
- package/dist/sdd-engine/task-window.js +177 -246
- package/dist/sdd-engine/tools/execution-tools.js +29 -26
- package/dist/sdd-engine/tools/feature-store.d.ts +11 -0
- package/dist/sdd-engine/tools/feature-store.js +224 -0
- package/dist/sdd-engine/tools/workspace-tools.js +70 -127
- package/dist/sdd-engine/workspace-init.d.ts +3 -0
- package/dist/sdd-engine/workspace-init.js +197 -0
- package/dist/sdd-engine/workspace-root.d.ts +3 -1
- package/dist/sdd-engine/workspace-root.js +69 -3
- package/dist/types/completion.d.ts +77 -0
- package/dist/types/completion.js +2 -0
- package/package.json +32 -35
- package/templates/AGENTS.md +4 -0
- package/templates/host/planu-sdd.md +4 -0
- package/templates/skills/reconciler.md +8 -0
- package/templates/skills/spec-architect.md +22 -5
- package/templates/skills/spec-executor.md +11 -0
- package/templates/skills/verification-auditor.md +20 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { CompletionGuardError } from '../feature-authority.js';
|
|
4
|
+
export async function createExplicitFeatureDirectory(featDir, featureId) {
|
|
5
|
+
try {
|
|
6
|
+
await fs.mkdir(featDir);
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
if (isNodeErrorCode(err, 'EEXIST')) {
|
|
11
|
+
return {
|
|
12
|
+
success: false,
|
|
13
|
+
error: {
|
|
14
|
+
code: 'ERR_FEATURE_ALREADY_EXISTS',
|
|
15
|
+
message: `Feature '${featureId}' already exists in the workspace.`,
|
|
16
|
+
trigger: 'sdd_create_feature',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function reserveAutomaticFeatureDirectory(featuresDir, title) {
|
|
24
|
+
const entries = await fs.readdir(featuresDir, { withFileTypes: true });
|
|
25
|
+
const featureNames = entries
|
|
26
|
+
.filter((entry) => entry.isDirectory() && /^FEAT[-_]/u.test(entry.name))
|
|
27
|
+
.map((entry) => entry.name);
|
|
28
|
+
const allocatedSequences = entries.flatMap((entry) => {
|
|
29
|
+
if (!entry.isDirectory()) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const sequence = /^FEAT[-_](\d+)(?:[-_]|$)/u.exec(entry.name)?.[1] ??
|
|
33
|
+
/^\.FEAT-(\d+)\.reserve$/u.exec(entry.name)?.[1];
|
|
34
|
+
return sequence ? [Number(sequence)] : [];
|
|
35
|
+
});
|
|
36
|
+
const highestSequence = Math.max(0, ...allocatedSequences);
|
|
37
|
+
let nextSequence = Math.max(highestSequence + 1, featureNames.length + 1);
|
|
38
|
+
const slug = createFeatureSlug(title);
|
|
39
|
+
for (;;) {
|
|
40
|
+
const sequenceLabel = String(nextSequence).padStart(4, '0');
|
|
41
|
+
const reservationDir = path.join(featuresDir, `.FEAT-${sequenceLabel}.reserve`);
|
|
42
|
+
try {
|
|
43
|
+
await fs.mkdir(reservationDir);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (!isNodeErrorCode(err, 'EEXIST')) {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
nextSequence += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const featureId = `FEAT-${sequenceLabel}-${slug}`;
|
|
53
|
+
const featDir = path.join(featuresDir, featureId);
|
|
54
|
+
try {
|
|
55
|
+
await fs.mkdir(featDir);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
await fs.rm(reservationDir, { recursive: true, force: true });
|
|
59
|
+
if (isNodeErrorCode(err, 'EEXIST')) {
|
|
60
|
+
nextSequence += 1;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
await fs.rm(reservationDir, { recursive: true, force: false });
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
await fs.rm(featDir, { recursive: true, force: true });
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
return { featureId, featDir };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function createFeatureSlug(title) {
|
|
76
|
+
const slug = title
|
|
77
|
+
.normalize('NFKD')
|
|
78
|
+
.replace(/[\u0300-\u036f]/gu, '')
|
|
79
|
+
.toUpperCase()
|
|
80
|
+
.replace(/[^A-Z0-9]+/gu, '-')
|
|
81
|
+
.replace(/^-+|-+$/gu, '')
|
|
82
|
+
.slice(0, 48)
|
|
83
|
+
.replace(/-+$/gu, '');
|
|
84
|
+
return slug || 'FEATURE';
|
|
85
|
+
}
|
|
86
|
+
function isNodeErrorCode(err, code) {
|
|
87
|
+
return typeof err === 'object' && err !== null && 'code' in err && err.code === code;
|
|
88
|
+
}
|
|
89
|
+
export async function collectFeatures(featuresDir, taskWindow, statusFilter) {
|
|
90
|
+
const result = [];
|
|
91
|
+
let entries;
|
|
92
|
+
try {
|
|
93
|
+
entries = await fs.readdir(featuresDir, { withFileTypes: true });
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (isNodeErrorCode(error, 'ENOENT')) {
|
|
97
|
+
return { success: true, data: [] };
|
|
98
|
+
}
|
|
99
|
+
return catalogueFailure();
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const candidates = entries.filter((entry) => /^FEAT[-_][A-Z0-9_-]+$/u.test(entry.name));
|
|
103
|
+
// Bound concurrent feature reads to eight. allSettled drains every started read
|
|
104
|
+
// before returning a failure, and ordered reduction preserves filesystem order.
|
|
105
|
+
for (let offset = 0; offset < candidates.length; offset += 8) {
|
|
106
|
+
const settled = await Promise.allSettled(candidates
|
|
107
|
+
.slice(offset, offset + 8)
|
|
108
|
+
.map(async (entry) => {
|
|
109
|
+
if (entry.isSymbolicLink()) {
|
|
110
|
+
return pathFailure('sdd_list_features', true);
|
|
111
|
+
}
|
|
112
|
+
if (!entry.isDirectory()) {
|
|
113
|
+
return catalogueFailure();
|
|
114
|
+
}
|
|
115
|
+
const featId = entry.name;
|
|
116
|
+
const featPath = path.join(featuresDir, featId);
|
|
117
|
+
const entryResult = await taskWindow.getCatalogueEntry(featPath);
|
|
118
|
+
if (!entryResult.success) {
|
|
119
|
+
return entryResult;
|
|
120
|
+
}
|
|
121
|
+
if (!statusFilter ||
|
|
122
|
+
statusFilter === 'all' ||
|
|
123
|
+
statusFilter === entryResult.data.status) {
|
|
124
|
+
return { success: true, data: entryResult.data };
|
|
125
|
+
}
|
|
126
|
+
return { success: true, data: null };
|
|
127
|
+
}));
|
|
128
|
+
for (const outcome of settled) {
|
|
129
|
+
if (outcome.status === 'rejected') {
|
|
130
|
+
throw outcome.reason;
|
|
131
|
+
}
|
|
132
|
+
const current = outcome.value;
|
|
133
|
+
if (!current.success) {
|
|
134
|
+
return current;
|
|
135
|
+
}
|
|
136
|
+
if (current.data !== null) {
|
|
137
|
+
result.push(current.data);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error instanceof CompletionGuardError) {
|
|
144
|
+
return {
|
|
145
|
+
success: false,
|
|
146
|
+
error: {
|
|
147
|
+
code: error.code,
|
|
148
|
+
message: error.message,
|
|
149
|
+
trigger: 'sdd_list_features',
|
|
150
|
+
details: { reason: error.reason },
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return catalogueFailure();
|
|
155
|
+
}
|
|
156
|
+
return { success: true, data: result };
|
|
157
|
+
}
|
|
158
|
+
function pathFailure(trigger, outside) {
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
error: {
|
|
162
|
+
code: outside ? 'ERR_PERMISSION_VIOLATION' : 'ERR_INVALID_ARTIFACT',
|
|
163
|
+
message: outside
|
|
164
|
+
? 'Unsafe feature path outside the physical workspace boundary.'
|
|
165
|
+
: 'Feature storage is not a readable directory.',
|
|
166
|
+
trigger,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function catalogueFailure(entry) {
|
|
171
|
+
return {
|
|
172
|
+
success: false,
|
|
173
|
+
error: {
|
|
174
|
+
code: 'ERR_INVALID_ARTIFACT',
|
|
175
|
+
message: 'Could not read the complete feature catalogue.',
|
|
176
|
+
trigger: 'sdd_list_features',
|
|
177
|
+
...(entry ? { details: { entry } } : {}),
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export async function featurePathFailure(workspaceRoot, directory, trigger) {
|
|
182
|
+
const relative = path.relative(path.resolve(workspaceRoot), path.resolve(directory));
|
|
183
|
+
if (relative.startsWith('..' + path.sep) || relative === '..' || path.isAbsolute(relative)) {
|
|
184
|
+
return pathFailure(trigger, true);
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
let current = await fs.realpath(workspaceRoot);
|
|
188
|
+
for (const segment of relative.split(path.sep).filter(Boolean)) {
|
|
189
|
+
current = path.join(current, segment);
|
|
190
|
+
let stat;
|
|
191
|
+
try {
|
|
192
|
+
stat = await fs.lstat(current);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (isNodeErrorCode(error, 'ENOENT')) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
if (stat.isSymbolicLink()) {
|
|
201
|
+
return pathFailure(trigger, true);
|
|
202
|
+
}
|
|
203
|
+
if (!stat.isDirectory()) {
|
|
204
|
+
return pathFailure(trigger, false);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return pathFailure(trigger, false);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export async function writeFeatureArtifacts(featDir, id, title) {
|
|
214
|
+
const initialSpec = `# Spec: ${title}\nFeature ID: ${id}\n\n## Observable Outcome\n- Select the smallest useful user outcome and explain its observable demonstration.\n\n## Acceptance Behavior\n- Replace these instructions with concrete executable acceptance scenarios for the selected outcome. This scaffold is not ready to lock.\n\n## Out-of-Scope (Mandatory)\n- Explicitly list excluded modules, dependencies, behaviors and deferred user outcomes.\n\n## Contracts & Data Models\n- Reuse existing contracts by exact source reference. Define strict types only for affected boundaries; explain when no contract changes are needed.\n\n## Error Matrix\n| Trigger | Condition | Error Code | Status / Payload |\n|---|---|---|---|\n| Describe applicable trigger | Describe condition | Reuse or define the affected error | State observable behavior |\n`;
|
|
215
|
+
const initialPlan = `# Plan: ${title}\nFeature ID: ${id}\n\n## Increment Design\n- Identify only the necessary layers and existing components for the selected outcome.\n- Justify any new abstraction or foundational step against a current requirement; describe the first usable result.\n\n## Frozen Dependencies\n- (Frozen dependencies: zero new packages or dependencies allowed without architectural authorization)\n\n## File Manifest\n- CREATE: \n- MODIFY: \n- READ_ONLY: \n- DELETE: \n`;
|
|
216
|
+
const initialTasks = `# Tasks: ${title}\nFeature ID: ${id}\n\n- [ ] TASK-1: Deliver the first useful increment with an observable demonstration\n Verification: <executable test command>\n`;
|
|
217
|
+
await fs.writeFile(path.join(featDir, 'spec.md'), initialSpec, { encoding: 'utf8', flag: 'wx' });
|
|
218
|
+
await fs.writeFile(path.join(featDir, 'plan.md'), initialPlan, { encoding: 'utf8', flag: 'wx' });
|
|
219
|
+
await fs.writeFile(path.join(featDir, 'tasks.md'), initialTasks, {
|
|
220
|
+
encoding: 'utf8',
|
|
221
|
+
flag: 'wx',
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=feature-store.js.map
|
|
@@ -5,8 +5,11 @@ import { InitWorkspaceInputSchema, ListFeaturesInputSchema, CreateFeatureInputSc
|
|
|
5
5
|
import { TaskWindowManager } from '../task-window.js';
|
|
6
6
|
import { formatResult } from './format-result.js';
|
|
7
7
|
import { homeFallbackFailure } from '../workspace-root.js';
|
|
8
|
+
import { prepareProjectInitialization } from '../workspace-init.js';
|
|
8
9
|
import { writeLockedTrinity } from '../lock-integrity.js';
|
|
9
|
-
import {
|
|
10
|
+
import { CompletionGuardError } from '../feature-authority.js';
|
|
11
|
+
import { reserveAutomaticFeatureDirectory, createExplicitFeatureDirectory, collectFeatures, featurePathFailure, writeFeatureArtifacts, } from './feature-store.js';
|
|
12
|
+
import { copyGlobalRules, installCursorGuard, installHostRulePack, installHostSkillPack, inspectHostSkillPack, } from '../host-rule-pack.js';
|
|
10
13
|
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
11
14
|
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
15
|
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-*.';
|
|
@@ -15,10 +18,24 @@ async function composeWorkspaceHint(workspaceRoot, extra) {
|
|
|
15
18
|
.access(path.join(workspaceRoot, 'planu', 'specs'))
|
|
16
19
|
.then(() => true)
|
|
17
20
|
.catch(() => false);
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
const pack = await inspectHostSkillPack(workspaceRoot).catch(() => 'Planu host skill verification was unavailable. Run sdd_init_workspace for requested project setup and read the matching role.');
|
|
22
|
+
const combined = [extra, pack, legacySpecsPresent ? LEGACY_SPECS_HINT : undefined]
|
|
23
|
+
.filter((item) => item !== undefined)
|
|
24
|
+
.join(' ');
|
|
25
|
+
if (!combined) {
|
|
26
|
+
return undefined;
|
|
20
27
|
}
|
|
21
|
-
|
|
28
|
+
let bounded = '';
|
|
29
|
+
let bytes = 0;
|
|
30
|
+
for (const character of combined) {
|
|
31
|
+
const size = Buffer.byteLength(character);
|
|
32
|
+
if (bytes + size > 1024) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
bounded += character;
|
|
36
|
+
bytes += size;
|
|
37
|
+
}
|
|
38
|
+
return bounded;
|
|
22
39
|
}
|
|
23
40
|
export function registerWorkspaceTools(server, workspace) {
|
|
24
41
|
const taskWindow = new TaskWindowManager();
|
|
@@ -45,7 +62,11 @@ function registerInitTool(server, workspace) {
|
|
|
45
62
|
: resolved.sddDir;
|
|
46
63
|
const featuresDir = path.join(targetBase, 'features');
|
|
47
64
|
const skillsDir = path.join(targetBase, 'skills');
|
|
65
|
+
const refreshMirrors = args.scope === 'project'
|
|
66
|
+
? await prepareProjectInitialization(resolved.workspaceRoot)
|
|
67
|
+
: undefined;
|
|
48
68
|
await fs.mkdir(featuresDir, { recursive: true });
|
|
69
|
+
await refreshMirrors?.();
|
|
49
70
|
if (args.scope === 'global') {
|
|
50
71
|
await fs.mkdir(skillsDir, { recursive: true });
|
|
51
72
|
await copySkillTemplates(skillsDir);
|
|
@@ -54,7 +75,7 @@ function registerInitTool(server, workspace) {
|
|
|
54
75
|
const hostRules = args.scope === 'project' ? await installHostRulePack(resolved.workspaceRoot) : [];
|
|
55
76
|
const cursorGuard = args.scope === 'project' ? await installCursorGuard(resolved.workspaceRoot) : [];
|
|
56
77
|
const hostSkills = args.scope === 'project' ? await installHostSkillPack(resolved.workspaceRoot) : [];
|
|
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.');
|
|
78
|
+
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. Read .agents/skills/planu-preflight-guardian/SKILL.md and the matching role with sdd_read_file_slice now. Host catalog discovery may require a client/session reload; restarting MCP and reloading host skills are separate actions.');
|
|
58
79
|
return formatResult({
|
|
59
80
|
success: true,
|
|
60
81
|
data: {
|
|
@@ -87,7 +108,15 @@ function registerListTool(server, workspace, taskWindow) {
|
|
|
87
108
|
return formatResult(homeError);
|
|
88
109
|
}
|
|
89
110
|
const featuresDir = path.join(resolved.sddDir, 'features');
|
|
90
|
-
const
|
|
111
|
+
const safety = await featurePathFailure(resolved.workspaceRoot, featuresDir, 'sdd_list_features');
|
|
112
|
+
if (safety) {
|
|
113
|
+
return formatResult(safety);
|
|
114
|
+
}
|
|
115
|
+
const collected = await collectFeatures(featuresDir, taskWindow, args.status_filter);
|
|
116
|
+
if (!collected.success) {
|
|
117
|
+
return formatResult(collected);
|
|
118
|
+
}
|
|
119
|
+
const featuresList = collected.data;
|
|
91
120
|
const hint = await composeWorkspaceHint(resolved.workspaceRoot, resolved.sddPresent ? undefined : MISSING_SDD_HINT);
|
|
92
121
|
return formatResult({
|
|
93
122
|
success: true,
|
|
@@ -114,26 +143,26 @@ function registerCreateTool(server, workspace) {
|
|
|
114
143
|
return formatResult(homeError);
|
|
115
144
|
}
|
|
116
145
|
const featuresDir = path.join(resolved.sddDir, 'features');
|
|
146
|
+
const safety = await featurePathFailure(resolved.workspaceRoot, featuresDir, 'sdd_create_feature');
|
|
147
|
+
if (safety) {
|
|
148
|
+
return formatResult(safety);
|
|
149
|
+
}
|
|
117
150
|
await fs.mkdir(featuresDir, { recursive: true });
|
|
151
|
+
const afterCreation = await featurePathFailure(resolved.workspaceRoot, featuresDir, 'sdd_create_feature');
|
|
152
|
+
if (afterCreation) {
|
|
153
|
+
return formatResult(afterCreation);
|
|
154
|
+
}
|
|
118
155
|
let featureId = args.id;
|
|
119
156
|
let featDir;
|
|
120
157
|
if (featureId) {
|
|
121
158
|
featDir = path.join(featuresDir, featureId);
|
|
122
|
-
|
|
123
|
-
|
|
159
|
+
const existingSafety = await featurePathFailure(resolved.workspaceRoot, featDir, 'sdd_create_feature');
|
|
160
|
+
if (existingSafety) {
|
|
161
|
+
return formatResult(existingSafety);
|
|
124
162
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
success: false,
|
|
129
|
-
error: {
|
|
130
|
-
code: 'ERR_FEATURE_ALREADY_EXISTS',
|
|
131
|
-
message: `Feature '${featureId}' already exists in the workspace.`,
|
|
132
|
-
trigger: 'sdd_create_feature',
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
throw err;
|
|
163
|
+
const creationFailure = await createExplicitFeatureDirectory(featDir, featureId);
|
|
164
|
+
if (creationFailure) {
|
|
165
|
+
return formatResult(creationFailure);
|
|
137
166
|
}
|
|
138
167
|
}
|
|
139
168
|
else {
|
|
@@ -141,7 +170,12 @@ function registerCreateTool(server, workspace) {
|
|
|
141
170
|
featureId = reservation.featureId;
|
|
142
171
|
featDir = reservation.featDir;
|
|
143
172
|
}
|
|
173
|
+
const featureSafety = await featurePathFailure(resolved.workspaceRoot, featDir, 'sdd_create_feature');
|
|
174
|
+
if (featureSafety) {
|
|
175
|
+
return formatResult(featureSafety);
|
|
176
|
+
}
|
|
144
177
|
await writeFeatureArtifacts(featDir, featureId, args.title);
|
|
178
|
+
const hint = await composeWorkspaceHint(resolved.workspaceRoot);
|
|
145
179
|
return formatResult({
|
|
146
180
|
success: true,
|
|
147
181
|
data: {
|
|
@@ -149,73 +183,11 @@ function registerCreateTool(server, workspace) {
|
|
|
149
183
|
artifactsCreated: ['spec.md', 'plan.md', 'tasks.md'],
|
|
150
184
|
directory: featDir,
|
|
151
185
|
workspaceRoot: resolved.workspaceRoot,
|
|
186
|
+
...(hint ? { hint } : {}),
|
|
152
187
|
},
|
|
153
188
|
});
|
|
154
189
|
});
|
|
155
190
|
}
|
|
156
|
-
async function reserveAutomaticFeatureDirectory(featuresDir, title) {
|
|
157
|
-
const entries = await fs.readdir(featuresDir, { withFileTypes: true });
|
|
158
|
-
const featureNames = entries
|
|
159
|
-
.filter((entry) => entry.isDirectory() && /^FEAT[-_]/u.test(entry.name))
|
|
160
|
-
.map((entry) => entry.name);
|
|
161
|
-
const allocatedSequences = entries.flatMap((entry) => {
|
|
162
|
-
if (!entry.isDirectory()) {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
const sequence = /^FEAT[-_](\d+)(?:[-_]|$)/u.exec(entry.name)?.[1] ??
|
|
166
|
-
/^\.FEAT-(\d+)\.reserve$/u.exec(entry.name)?.[1];
|
|
167
|
-
return sequence ? [Number(sequence)] : [];
|
|
168
|
-
});
|
|
169
|
-
const highestSequence = Math.max(0, ...allocatedSequences);
|
|
170
|
-
let nextSequence = Math.max(highestSequence + 1, featureNames.length + 1);
|
|
171
|
-
const slug = createFeatureSlug(title);
|
|
172
|
-
for (;;) {
|
|
173
|
-
const sequenceLabel = String(nextSequence).padStart(4, '0');
|
|
174
|
-
const reservationDir = path.join(featuresDir, `.FEAT-${sequenceLabel}.reserve`);
|
|
175
|
-
try {
|
|
176
|
-
await fs.mkdir(reservationDir);
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
if (!isNodeErrorCode(err, 'EEXIST')) {
|
|
180
|
-
throw err;
|
|
181
|
-
}
|
|
182
|
-
nextSequence += 1;
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
const featureId = `FEAT-${sequenceLabel}-${slug}`;
|
|
186
|
-
const featDir = path.join(featuresDir, featureId);
|
|
187
|
-
try {
|
|
188
|
-
await fs.mkdir(featDir);
|
|
189
|
-
}
|
|
190
|
-
catch (err) {
|
|
191
|
-
await fs.rm(reservationDir, { recursive: true, force: true });
|
|
192
|
-
if (isNodeErrorCode(err, 'EEXIST')) {
|
|
193
|
-
nextSequence += 1;
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
throw err;
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
await fs.rm(reservationDir, { recursive: true, force: false });
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
await fs.rm(featDir, { recursive: true, force: true });
|
|
203
|
-
throw err;
|
|
204
|
-
}
|
|
205
|
-
return { featureId, featDir };
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function createFeatureSlug(title) {
|
|
209
|
-
const slug = title
|
|
210
|
-
.normalize('NFKD')
|
|
211
|
-
.replace(/[\u0300-\u036f]/gu, '')
|
|
212
|
-
.toUpperCase()
|
|
213
|
-
.replace(/[^A-Z0-9]+/gu, '-')
|
|
214
|
-
.replace(/^-+|-+$/gu, '')
|
|
215
|
-
.slice(0, 48)
|
|
216
|
-
.replace(/-+$/gu, '');
|
|
217
|
-
return slug || 'FEATURE';
|
|
218
|
-
}
|
|
219
191
|
function registerLockTool(server, workspace) {
|
|
220
192
|
server.registerTool('sdd_lock_spec', {
|
|
221
193
|
description: 'Locks spec.md, plan.md, and tasks.md. Pass relock=true and reason to reseal after review.',
|
|
@@ -231,9 +203,6 @@ function registerLockTool(server, workspace) {
|
|
|
231
203
|
return executeLockSpec(featDir, args.feature_id, args.relock === true, args.reason);
|
|
232
204
|
});
|
|
233
205
|
}
|
|
234
|
-
function isNodeErrorCode(err, code) {
|
|
235
|
-
return typeof err === 'object' && err !== null && 'code' in err && err.code === code;
|
|
236
|
-
}
|
|
237
206
|
async function copySkillTemplates(skillsDir) {
|
|
238
207
|
const sourceSkillsDir = path.resolve(moduleDir, '..', '..', '..', 'templates', 'skills');
|
|
239
208
|
const files = await fs.readdir(sourceSkillsDir);
|
|
@@ -244,50 +213,24 @@ async function copySkillTemplates(skillsDir) {
|
|
|
244
213
|
}
|
|
245
214
|
}
|
|
246
215
|
}
|
|
247
|
-
async function
|
|
248
|
-
|
|
216
|
+
async function executeLockSpec(featDir, featureId, relock, reason) {
|
|
217
|
+
let outcome;
|
|
249
218
|
try {
|
|
250
|
-
|
|
251
|
-
for (const entry of entries) {
|
|
252
|
-
if (!entry.isDirectory() || !/^FEAT[-_][A-Z0-9_-]+$/u.test(entry.name)) {
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
const featId = entry.name;
|
|
256
|
-
const featPath = path.join(featuresDir, featId);
|
|
257
|
-
const lockExists = await fs
|
|
258
|
-
.access(path.join(featPath, '.lock'))
|
|
259
|
-
.then(() => true)
|
|
260
|
-
.catch(() => false);
|
|
261
|
-
let status = 'planning';
|
|
262
|
-
let activeTaskId = null;
|
|
263
|
-
const tasksPath = path.join(featPath, 'tasks.md');
|
|
264
|
-
const taskRes = await taskWindow.getActiveTask(tasksPath);
|
|
265
|
-
if (lockExists) {
|
|
266
|
-
status = taskRes.success && taskRes.data.allCompleted ? 'done' : 'executing';
|
|
267
|
-
}
|
|
268
|
-
if (taskRes.success) {
|
|
269
|
-
activeTaskId = taskRes.data.activeTask?.taskId ?? null;
|
|
270
|
-
}
|
|
271
|
-
if (!statusFilter || statusFilter === 'all' || statusFilter === status) {
|
|
272
|
-
result.push({ id: featId, status, locked: lockExists, activeTaskId });
|
|
273
|
-
}
|
|
274
|
-
}
|
|
219
|
+
outcome = await writeLockedTrinity(featDir, featureId, relock, reason);
|
|
275
220
|
}
|
|
276
|
-
catch {
|
|
277
|
-
|
|
221
|
+
catch (error) {
|
|
222
|
+
return formatResult({
|
|
223
|
+
success: false,
|
|
224
|
+
error: {
|
|
225
|
+
code: error instanceof CompletionGuardError ? error.code : 'ERR_INVALID_ARTIFACT',
|
|
226
|
+
message: error instanceof CompletionGuardError
|
|
227
|
+
? error.message
|
|
228
|
+
: 'The feature could not be safely locked.',
|
|
229
|
+
trigger: 'sdd_lock_spec',
|
|
230
|
+
details: { reason: error instanceof CompletionGuardError ? error.reason : 'failed' },
|
|
231
|
+
},
|
|
232
|
+
});
|
|
278
233
|
}
|
|
279
|
-
return result;
|
|
280
|
-
}
|
|
281
|
-
async function writeFeatureArtifacts(featDir, id, title) {
|
|
282
|
-
const initialSpec = `# Spec: ${title}\nFeature ID: ${id}\n\n## 1. Out-of-Scope (Mandatory)\n- Explicitly list all modules, dependencies, and behaviors strictly forbidden from being modified.\n\n## 2. Contracts & Data Models\n- Define strict types, interfaces, structs, or schemas using the project's native programming language. Zero loose types.\n\n## 3. Error Matrix\n| Trigger | Condition | Error Code | Status / Payload |\n|---|---|---|---|\n| Invalid input | Missing required field | ERR_INVALID_INPUT | 400 Bad Request |\n`;
|
|
283
|
-
const initialPlan = `# Plan: ${title}\nFeature ID: ${id}\n\n## Frozen Dependencies\n- (Frozen dependencies: zero new packages or dependencies allowed without architectural authorization)\n\n## File Manifest\n- CREATE: \n- MODIFY: \n- READ_ONLY: \n- DELETE: \n`;
|
|
284
|
-
const initialTasks = `# Tasks: ${title}\nFeature ID: ${id}\n\n- [ ] TASK-1: Define core data structures and initial contracts\n Verification: <executable test command>\n`;
|
|
285
|
-
await fs.writeFile(path.join(featDir, 'spec.md'), initialSpec, 'utf-8');
|
|
286
|
-
await fs.writeFile(path.join(featDir, 'plan.md'), initialPlan, 'utf-8');
|
|
287
|
-
await fs.writeFile(path.join(featDir, 'tasks.md'), initialTasks, 'utf-8');
|
|
288
|
-
}
|
|
289
|
-
async function executeLockSpec(featDir, featureId, relock, reason) {
|
|
290
|
-
const outcome = await writeLockedTrinity(featDir, featureId, relock, reason);
|
|
291
234
|
if (!outcome.ok) {
|
|
292
235
|
return formatResult({
|
|
293
236
|
success: false,
|