@planu/cli 8.8.0 → 8.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +9 -3
- package/dist/sdd-engine/canonical-tools.d.ts +38 -0
- package/dist/sdd-engine/canonical-tools.js +105 -2
- package/dist/sdd-engine/catalogue-presentation.d.ts +23 -0
- package/dist/sdd-engine/catalogue-presentation.js +123 -0
- package/dist/sdd-engine/client-workspace.d.ts +8 -1
- package/dist/sdd-engine/client-workspace.js +168 -1
- package/dist/sdd-engine/completion-snapshot.d.ts +2 -1
- package/dist/sdd-engine/completion-snapshot.js +81 -23
- package/dist/sdd-engine/contracts.d.ts +2 -24
- package/dist/sdd-engine/contracts.js +5 -19
- package/dist/sdd-engine/feature-authority.d.ts +3 -2
- package/dist/sdd-engine/feature-authority.js +29 -1
- package/dist/sdd-engine/host-rule-pack.js +16 -4
- package/dist/sdd-engine/host-skill-reader.d.ts +12 -11
- package/dist/sdd-engine/host-skill-reader.js +235 -225
- package/dist/sdd-engine/source-descriptor.d.ts +3 -0
- package/dist/sdd-engine/source-descriptor.js +356 -0
- package/dist/sdd-engine/tools/execution-tools.d.ts +2 -1
- package/dist/sdd-engine/tools/execution-tools.js +58 -33
- package/dist/sdd-engine/tools/feature-store.d.ts +6 -6
- package/dist/sdd-engine/tools/feature-store.js +188 -84
- package/dist/sdd-engine/tools/workspace-tools.d.ts +2 -1
- package/dist/sdd-engine/tools/workspace-tools.js +44 -35
- package/dist/sdd-engine/tools.js +4 -2
- package/dist/sdd-engine/workspace-init.d.ts +6 -0
- package/dist/sdd-engine/workspace-init.js +92 -2
- package/dist/sdd-engine/workspace-root.d.ts +33 -7
- package/dist/sdd-engine/workspace-root.js +222 -139
- package/dist/types/completion.d.ts +46 -2
- package/dist/types/resume-views.d.ts +36 -1
- package/dist/types/sdd-engine.d.ts +35 -61
- package/dist/types/verification.d.ts +59 -0
- package/package.json +2 -2
- package/templates/AGENTS.md +4 -0
- package/templates/host/planu-sdd.md +4 -0
- package/templates/skills/preflight-guardian.md +4 -0
- package/templates/skills/spec-executor.md +4 -0
|
@@ -1,88 +1,13 @@
|
|
|
1
|
+
import * as catalogue from '../catalogue-presentation.js';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
1
4
|
import * as fs from 'node:fs/promises';
|
|
2
5
|
import * as path from 'node:path';
|
|
3
6
|
import { CompletionGuardError } from '../feature-authority.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
}
|
|
7
|
+
import { captureCatalogueArtifacts } from '../completion-snapshot.js';
|
|
8
|
+
import { catalogueFromContent } from '../task-content.js';
|
|
9
|
+
import { verificationCommand } from '../task-failures.js';
|
|
10
|
+
export { createExplicitFeatureDirectory, reserveAutomaticFeatureDirectory, } from '../workspace-init.js';
|
|
86
11
|
function isNodeErrorCode(err, code) {
|
|
87
12
|
return typeof err === 'object' && err !== null && 'code' in err && err.code === code;
|
|
88
13
|
}
|
|
@@ -214,11 +139,190 @@ export async function writeFeatureArtifacts(featDir, id, title) {
|
|
|
214
139
|
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
140
|
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
141
|
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, {
|
|
218
|
-
|
|
142
|
+
await fs.writeFile(path.join(featDir, 'spec.md'), initialSpec, {
|
|
143
|
+
encoding: 'utf8',
|
|
144
|
+
flag: 'wx',
|
|
145
|
+
});
|
|
146
|
+
await fs.writeFile(path.join(featDir, 'plan.md'), initialPlan, {
|
|
147
|
+
encoding: 'utf8',
|
|
148
|
+
flag: 'wx',
|
|
149
|
+
});
|
|
219
150
|
await fs.writeFile(path.join(featDir, 'tasks.md'), initialTasks, {
|
|
220
151
|
encoding: 'utf8',
|
|
221
152
|
flag: 'wx',
|
|
222
153
|
});
|
|
223
154
|
}
|
|
155
|
+
function catalogueHash(value) {
|
|
156
|
+
return createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
157
|
+
}
|
|
158
|
+
function directoryTuple(stat) {
|
|
159
|
+
return [stat.dev, stat.ino, stat.mode, stat.uid, stat.gid].map(String);
|
|
160
|
+
}
|
|
161
|
+
async function catalogueDirectory(name, signal) {
|
|
162
|
+
catalogue.checkCatalogueAbort(signal);
|
|
163
|
+
try {
|
|
164
|
+
const stat = await fs.lstat(name, { bigint: true });
|
|
165
|
+
catalogue.checkCatalogueAbort(signal);
|
|
166
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
167
|
+
throw new catalogue.CatalogueReadError('catalogue_path_unsafe');
|
|
168
|
+
}
|
|
169
|
+
return directoryTuple(stat);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
catalogue.checkCatalogueAbort(signal);
|
|
173
|
+
if (isNodeErrorCode(error, 'ENOENT')) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
if (isNodeErrorCode(error, 'ENOTDIR') || isNodeErrorCode(error, 'ELOOP')) {
|
|
177
|
+
throw new catalogue.CatalogueReadError('catalogue_path_unsafe');
|
|
178
|
+
}
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function catalogueBatch(names, read, signal) {
|
|
183
|
+
const values = [];
|
|
184
|
+
for (let i = 0; i < names.length; i += 8) {
|
|
185
|
+
catalogue.checkCatalogueAbort(signal);
|
|
186
|
+
const batch = await Promise.allSettled(names.slice(i, i + 8).map(read));
|
|
187
|
+
const uncertain = batch.find((item) => item.status === 'rejected' &&
|
|
188
|
+
item.reason instanceof CompletionGuardError &&
|
|
189
|
+
item.reason.reason === 'persistence_uncertain');
|
|
190
|
+
if (uncertain?.status === 'rejected') {
|
|
191
|
+
throw uncertain.reason;
|
|
192
|
+
}
|
|
193
|
+
const guarded = batch.find((item) => item.status === 'rejected' &&
|
|
194
|
+
item.reason instanceof CompletionGuardError &&
|
|
195
|
+
item.reason.reason === 'guard_present');
|
|
196
|
+
if (guarded?.status === 'rejected') {
|
|
197
|
+
throw guarded.reason;
|
|
198
|
+
}
|
|
199
|
+
catalogue.checkCatalogueAbort(signal);
|
|
200
|
+
for (const result of batch) {
|
|
201
|
+
if (result.status === 'rejected') {
|
|
202
|
+
throw result.reason;
|
|
203
|
+
}
|
|
204
|
+
values.push(result.value);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return values;
|
|
208
|
+
}
|
|
209
|
+
async function catalogueHead(workspaceRoot, signal) {
|
|
210
|
+
catalogue.checkCatalogueAbort(signal);
|
|
211
|
+
const root = await fs.realpath(workspaceRoot);
|
|
212
|
+
const identity = await catalogueDirectory(root, signal);
|
|
213
|
+
if (!identity) {
|
|
214
|
+
throw new catalogue.CatalogueReadError('catalogue_unavailable');
|
|
215
|
+
}
|
|
216
|
+
const sdd = path.join(root, '.sdd');
|
|
217
|
+
const sddIdentity = await catalogueDirectory(sdd, signal);
|
|
218
|
+
const features = path.join(sdd, 'features');
|
|
219
|
+
const featuresIdentity = sddIdentity ? await catalogueDirectory(features, signal) : null;
|
|
220
|
+
catalogue.checkCatalogueAbort(signal);
|
|
221
|
+
const names = featuresIdentity
|
|
222
|
+
? (await fs.readdir(features)).filter((name) => /^FEAT[-_][A-Z0-9_-]+$/u.test(name)).sort()
|
|
223
|
+
: [];
|
|
224
|
+
catalogue.checkCatalogueAbort(signal);
|
|
225
|
+
return {
|
|
226
|
+
root,
|
|
227
|
+
rootHash: catalogueHash(['planu.source-root.v1', root, ...identity]),
|
|
228
|
+
identity,
|
|
229
|
+
sddIdentity,
|
|
230
|
+
featuresIdentity,
|
|
231
|
+
features,
|
|
232
|
+
names,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async function catalogueSnapshot(head, signal) {
|
|
236
|
+
const captured = await catalogueBatch(head.names, async (id) => {
|
|
237
|
+
catalogue.checkCatalogueAbort(signal);
|
|
238
|
+
if (!catalogue.compactIdValid(id)) {
|
|
239
|
+
throw new catalogue.CatalogueReadError('catalogue_identifier_invalid');
|
|
240
|
+
}
|
|
241
|
+
const artifacts = await captureCatalogueArtifacts(path.join(head.features, id), head.root, signal);
|
|
242
|
+
catalogue.checkCatalogueAbort(signal);
|
|
243
|
+
if (!catalogue.sameCatalogueRoot(head.rootHash, artifacts.tasks, artifacts.lock)) {
|
|
244
|
+
throw new catalogue.CatalogueReadError('catalogue_cursor_stale');
|
|
245
|
+
}
|
|
246
|
+
const summary = catalogueFromContent(id, artifacts.lock !== null, artifacts.tasks.content, verificationCommand);
|
|
247
|
+
if (!summary.success) {
|
|
248
|
+
throw new catalogue.CatalogueReadError('catalogue_unavailable');
|
|
249
|
+
}
|
|
250
|
+
if (summary.data.activeTaskId !== null &&
|
|
251
|
+
!catalogue.compactIdValid(summary.data.activeTaskId)) {
|
|
252
|
+
throw new catalogue.CatalogueReadError('catalogue_identifier_invalid');
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
summary: summary.data,
|
|
256
|
+
projection: [
|
|
257
|
+
id,
|
|
258
|
+
artifacts.directories,
|
|
259
|
+
[artifacts.tasks.rawSha256, artifacts.tasks.descriptor],
|
|
260
|
+
artifacts.lock ? [artifacts.lock.rawSha256, artifacts.lock.descriptor] : null,
|
|
261
|
+
],
|
|
262
|
+
};
|
|
263
|
+
}, signal);
|
|
264
|
+
return {
|
|
265
|
+
entries: captured.map((item) => item.summary),
|
|
266
|
+
digest: catalogueHash([
|
|
267
|
+
'planu.feature-catalogue.v1',
|
|
268
|
+
head.rootHash,
|
|
269
|
+
head.sddIdentity,
|
|
270
|
+
head.featuresIdentity,
|
|
271
|
+
captured.map((item) => item.projection),
|
|
272
|
+
]),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function catalogueError(error, revalidation, aborted) {
|
|
276
|
+
if (error instanceof CompletionGuardError) {
|
|
277
|
+
return catalogue.compactCatalogueFailure(catalogue.classifyCatalogueError('guard', error.reason, error.code, revalidation, aborted));
|
|
278
|
+
}
|
|
279
|
+
if (error instanceof catalogue.CatalogueReadError) {
|
|
280
|
+
return catalogue.compactCatalogueFailure(catalogue.classifyCatalogueError('catalogue', error.reason, undefined, revalidation, aborted));
|
|
281
|
+
}
|
|
282
|
+
return catalogue.compactCatalogueFailure(catalogue.classifyCatalogueError('other', undefined, undefined, revalidation, aborted));
|
|
283
|
+
}
|
|
284
|
+
export async function readFeatureCatalogue(workspaceRoot, input, codec, signal) {
|
|
285
|
+
const options = catalogue.catalogueOptions(input);
|
|
286
|
+
if (!options) {
|
|
287
|
+
return catalogue.compactCatalogueFailure('catalogue_input_invalid');
|
|
288
|
+
}
|
|
289
|
+
const request = catalogueHash([
|
|
290
|
+
'planu.read-cursor.v1',
|
|
291
|
+
'catalogue',
|
|
292
|
+
options.query,
|
|
293
|
+
options.status,
|
|
294
|
+
options.size,
|
|
295
|
+
]);
|
|
296
|
+
const cursor = catalogue.catalogueCursor(input.cursor, request, codec);
|
|
297
|
+
if (cursor === undefined) {
|
|
298
|
+
return catalogue.compactCatalogueFailure('catalogue_cursor_invalid');
|
|
299
|
+
}
|
|
300
|
+
if (!constants.O_NOFOLLOW || !constants.O_NONBLOCK || typeof process.getuid !== 'function') {
|
|
301
|
+
return catalogue.compactCatalogueFailure('catalogue_capability_unavailable');
|
|
302
|
+
}
|
|
303
|
+
let revalidation = false;
|
|
304
|
+
try {
|
|
305
|
+
const head = await catalogueHead(workspaceRoot, signal);
|
|
306
|
+
const initial = await catalogueSnapshot(head, signal);
|
|
307
|
+
if (cursor && (cursor[2] !== head.rootHash || cursor[4] !== initial.digest)) {
|
|
308
|
+
return catalogue.compactCatalogueFailure('catalogue_cursor_stale');
|
|
309
|
+
}
|
|
310
|
+
const page = catalogue.cataloguePage(initial.entries, head.rootHash, initial.digest, request, options, cursor, codec);
|
|
311
|
+
revalidation = true;
|
|
312
|
+
const middle = await catalogueHead(workspaceRoot, signal);
|
|
313
|
+
if (JSON.stringify(head) !== JSON.stringify(middle)) {
|
|
314
|
+
return catalogue.compactCatalogueFailure('catalogue_cursor_stale');
|
|
315
|
+
}
|
|
316
|
+
const current = await catalogueSnapshot(middle, signal);
|
|
317
|
+
const last = await catalogueHead(workspaceRoot, signal);
|
|
318
|
+
if (initial.digest !== current.digest || JSON.stringify(middle) !== JSON.stringify(last)) {
|
|
319
|
+
return catalogue.compactCatalogueFailure('catalogue_cursor_stale');
|
|
320
|
+
}
|
|
321
|
+
catalogue.checkCatalogueAbort(signal);
|
|
322
|
+
return page;
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
return catalogueError(error, revalidation, signal?.aborted === true);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
224
328
|
//# sourceMappingURL=feature-store.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { ReadCursorCodec } from '../workspace-root.js';
|
|
1
2
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
3
|
import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
|
|
3
|
-
export declare function registerWorkspaceTools(server: McpServer, workspace: SddWorkspaceHandle, bundledVersion?: string): void;
|
|
4
|
+
export declare function registerWorkspaceTools(server: McpServer, workspace: SddWorkspaceHandle, bundledVersion?: string, codec?: ReadCursorCodec): void;
|
|
4
5
|
//# sourceMappingURL=workspace-tools.d.ts.map
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { homeFallbackFailure, ReadCursorCodec } from '../workspace-root.js';
|
|
2
|
+
import * as canonical from '../canonical-tools.js';
|
|
2
3
|
import * as fs from 'node:fs/promises';
|
|
3
4
|
import * as path from 'node:path';
|
|
4
5
|
import * as contracts from '../contracts.js';
|
|
5
6
|
import { TaskWindowManager } from '../task-window.js';
|
|
6
7
|
import * as compact from './compact-result.js';
|
|
7
|
-
import { homeFallbackFailure } from '../workspace-root.js';
|
|
8
8
|
import { prepareProjectInitialization } from '../workspace-init.js';
|
|
9
9
|
import { readTrinityFailureIssues, writeLockedTrinity } from '../lock-integrity.js';
|
|
10
10
|
import { CompletionGuardError } from '../feature-authority.js';
|
|
11
11
|
import { checkpointCapability } from '../evidence-journal.js';
|
|
12
12
|
import { appendEvidenceCheckpoint } from '../evidence-checkpoints.js';
|
|
13
|
-
import { reserveAutomaticFeatureDirectory, createExplicitFeatureDirectory, collectFeatures, featurePathFailure, writeFeatureArtifacts, } from './feature-store.js';
|
|
13
|
+
import { reserveAutomaticFeatureDirectory, createExplicitFeatureDirectory, collectFeatures, readFeatureCatalogue, featurePathFailure, writeFeatureArtifacts, } from './feature-store.js';
|
|
14
14
|
import * as hostPack from '../host-rule-pack.js';
|
|
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-*.';
|
|
16
15
|
async function composeWorkspaceHint(workspaceRoot, extra, suppliedPack) {
|
|
17
16
|
const legacySpecsPresent = await fs
|
|
18
17
|
.access(path.join(workspaceRoot, 'planu', 'specs'))
|
|
@@ -23,34 +22,22 @@ async function composeWorkspaceHint(workspaceRoot, extra, suppliedPack) {
|
|
|
23
22
|
: await hostPack
|
|
24
23
|
.inspectHostSkillPack(workspaceRoot)
|
|
25
24
|
.catch(() => 'Planu host skill verification was unavailable. Run sdd_init_workspace for requested project setup and read the matching role.');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
let bounded = '';
|
|
33
|
-
let bytes = 0;
|
|
34
|
-
for (const character of combined) {
|
|
35
|
-
const size = Buffer.byteLength(character);
|
|
36
|
-
if (bytes + size > 1024) {
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
bounded += character;
|
|
40
|
-
bytes += size;
|
|
41
|
-
}
|
|
42
|
-
return bounded;
|
|
25
|
+
return canonical.boundedWorkspaceHint([
|
|
26
|
+
extra,
|
|
27
|
+
pack,
|
|
28
|
+
legacySpecsPresent ? canonical.LEGACY_SPECS_HINT : undefined,
|
|
29
|
+
]);
|
|
43
30
|
}
|
|
44
|
-
export function registerWorkspaceTools(server, workspace, bundledVersion) {
|
|
31
|
+
export function registerWorkspaceTools(server, workspace, bundledVersion, codec = new ReadCursorCodec()) {
|
|
45
32
|
const taskWindow = new TaskWindowManager();
|
|
46
33
|
registerInitTool(server, workspace);
|
|
47
|
-
registerListTool(server, workspace, taskWindow, bundledVersion);
|
|
34
|
+
registerListTool(server, workspace, taskWindow, codec, bundledVersion);
|
|
48
35
|
registerCreateTool(server, workspace);
|
|
49
36
|
registerLockTool(server, workspace);
|
|
50
37
|
}
|
|
51
38
|
function registerInitTool(server, workspace) {
|
|
52
39
|
server.registerTool('sdd_init_workspace', {
|
|
53
|
-
annotations: TOOL_ANNOTATIONS.sdd_init_workspace,
|
|
40
|
+
annotations: canonical.TOOL_ANNOTATIONS.sdd_init_workspace,
|
|
54
41
|
description: 'Initializes the SDD workspace creating .sdd/ directory and decoupled skills.',
|
|
55
42
|
inputSchema: contracts.InitWorkspaceInputSchema.shape,
|
|
56
43
|
}, async (rawArgs) => {
|
|
@@ -101,22 +88,44 @@ function registerInitTool(server, workspace) {
|
|
|
101
88
|
});
|
|
102
89
|
});
|
|
103
90
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
async function dispatchCatalogue(workspace, input, codec, signal) {
|
|
92
|
+
if (canonical.signalIsAborted(signal)) {
|
|
93
|
+
return compact.formatCompactResult(canonical.catalogueDispatchFailure('cancelled'));
|
|
94
|
+
}
|
|
95
|
+
if (input.host !== undefined) {
|
|
96
|
+
return compact.formatCompactResult(canonical.catalogueInputFailure());
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const resolved = await workspace.resolve();
|
|
100
|
+
if (canonical.signalIsAborted(signal)) {
|
|
101
|
+
return compact.formatCompactResult(canonical.catalogueDispatchFailure('cancelled'));
|
|
102
|
+
}
|
|
103
|
+
const homeError = homeFallbackFailure(resolved, 'sdd_list_features');
|
|
104
|
+
if (homeError) {
|
|
105
|
+
return compact.formatCompactResult(homeError);
|
|
106
|
+
}
|
|
107
|
+
return compact.formatCompactResult(await readFeatureCatalogue(resolved.workspaceRoot, input, codec, signal));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return compact.formatCompactResult(canonical.catalogueDispatchFailure(canonical.signalIsAborted(signal) ? 'cancelled' : 'catalogue_unavailable'));
|
|
108
111
|
}
|
|
109
|
-
return compact.formatCompactResult(failure);
|
|
110
112
|
}
|
|
111
|
-
function registerListTool(server, workspace, taskWindow, bundledVersion) {
|
|
113
|
+
function registerListTool(server, workspace, taskWindow, codec, bundledVersion) {
|
|
112
114
|
server.registerTool('sdd_list_features', {
|
|
113
|
-
annotations: TOOL_ANNOTATIONS.sdd_list_features,
|
|
115
|
+
annotations: canonical.TOOL_ANNOTATIONS.sdd_list_features,
|
|
114
116
|
description: 'Lists executable Planu v8 FEAT-* features from .sdd/features only.',
|
|
115
117
|
inputSchema: contracts.ListFeaturesInputSchema,
|
|
116
|
-
}, async (rawArgs) => {
|
|
118
|
+
}, async (rawArgs, extra) => {
|
|
117
119
|
const parsed = contracts.ListFeaturesInputSchema.safeParse(rawArgs);
|
|
118
120
|
if (!parsed.success) {
|
|
119
|
-
return
|
|
121
|
+
return compact.formatCompactResult(canonical.listInputFailure());
|
|
122
|
+
}
|
|
123
|
+
const input = parsed.data;
|
|
124
|
+
if (input.view === 'catalogue') {
|
|
125
|
+
return dispatchCatalogue(workspace, input, codec, extra.signal);
|
|
126
|
+
}
|
|
127
|
+
if (canonical.hasCatalogueOptions(input)) {
|
|
128
|
+
return compact.formatCompactResult(canonical.catalogueInputFailure());
|
|
120
129
|
}
|
|
121
130
|
if (parsed.data.view !== undefined || parsed.data.host !== undefined) {
|
|
122
131
|
return hostPack.setupDiagnosticResult(server, workspace, bundledVersion, parsed.data);
|
|
@@ -154,7 +163,7 @@ function registerListTool(server, workspace, taskWindow, bundledVersion) {
|
|
|
154
163
|
}
|
|
155
164
|
function registerCreateTool(server, workspace) {
|
|
156
165
|
server.registerTool('sdd_create_feature', {
|
|
157
|
-
annotations: TOOL_ANNOTATIONS.sdd_create_feature,
|
|
166
|
+
annotations: canonical.TOOL_ANNOTATIONS.sdd_create_feature,
|
|
158
167
|
description: 'Creates a Holy Trinity feature. Omit id to atomically reserve the next global FEAT-NNNN-TITLE identifier; explicit FEAT-* IDs remain supported.',
|
|
159
168
|
inputSchema: contracts.CreateFeatureInputSchema.shape,
|
|
160
169
|
}, async (rawArgs) => {
|
|
@@ -212,7 +221,7 @@ function registerCreateTool(server, workspace) {
|
|
|
212
221
|
}
|
|
213
222
|
function registerLockTool(server, workspace) {
|
|
214
223
|
server.registerTool('sdd_lock_spec', {
|
|
215
|
-
annotations: TOOL_ANNOTATIONS.sdd_lock_spec,
|
|
224
|
+
annotations: canonical.TOOL_ANNOTATIONS.sdd_lock_spec,
|
|
216
225
|
description: 'Locks spec.md, plan.md, and tasks.md. Pass relock=true and reason to reseal after review. The explicit evidence_checkpoint operation records a caller-reported, non-certifying observation.',
|
|
217
226
|
inputSchema: contracts.LockSpecInputSchema,
|
|
218
227
|
}, async (rawArgs, extra) => {
|
package/dist/sdd-engine/tools.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { ReadCursorCodec } from './workspace-root.js';
|
|
2
3
|
import { McpClientWorkspace } from './client-workspace.js';
|
|
3
4
|
import { registerWorkspaceTools } from './tools/workspace-tools.js';
|
|
4
5
|
import { registerExecutionTools } from './tools/execution-tools.js';
|
|
5
6
|
export const bundledPackageVersion = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
|
|
6
7
|
export function registerUltralightSddTools(server, pinnedRoot, policy, bundledVersion = bundledPackageVersion) {
|
|
7
8
|
const workspace = new McpClientWorkspace(server, pinnedRoot);
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const codec = new ReadCursorCodec();
|
|
10
|
+
registerWorkspaceTools(server, workspace, bundledVersion, codec);
|
|
11
|
+
return registerExecutionTools(server, workspace, policy, codec);
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=tools.js.map
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import type { SddFailure } from '../types/sdd-engine.js';
|
|
1
2
|
/** Validate the complete project init write set before the caller writes anything. */
|
|
2
3
|
export declare function prepareProjectInitialization(workspaceRoot: string): Promise<() => Promise<void>>;
|
|
4
|
+
export declare function createExplicitFeatureDirectory(featDir: string, featureId: string): Promise<SddFailure | null>;
|
|
5
|
+
export declare function reserveAutomaticFeatureDirectory(featuresDir: string, title: string): Promise<{
|
|
6
|
+
featureId: string;
|
|
7
|
+
featDir: string;
|
|
8
|
+
}>;
|
|
3
9
|
//# sourceMappingURL=workspace-init.d.ts.map
|
|
@@ -17,7 +17,9 @@ function missing(error) {
|
|
|
17
17
|
return error instanceof Error && 'code' in error && error.code === 'ENOENT';
|
|
18
18
|
}
|
|
19
19
|
function unsafe(relative, code = 'EINVAL') {
|
|
20
|
-
return Object.assign(new Error(`Unsafe initialization path: ${relative}`), {
|
|
20
|
+
return Object.assign(new Error(`Unsafe initialization path: ${relative}`), {
|
|
21
|
+
code,
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
function containedPath(root, relative) {
|
|
23
25
|
const contained = path.relative(root, path.resolve(root, relative));
|
|
@@ -91,7 +93,10 @@ async function readTemplates() {
|
|
|
91
93
|
}
|
|
92
94
|
const templates = [];
|
|
93
95
|
for (const name of names) {
|
|
94
|
-
templates.push({
|
|
96
|
+
templates.push({
|
|
97
|
+
name,
|
|
98
|
+
content: await readRegular(path.join(packageRoot, source, name)),
|
|
99
|
+
});
|
|
95
100
|
}
|
|
96
101
|
for (const relative of [
|
|
97
102
|
'templates/AGENTS.md',
|
|
@@ -194,4 +199,89 @@ export async function prepareProjectInitialization(workspaceRoot) {
|
|
|
194
199
|
}
|
|
195
200
|
};
|
|
196
201
|
}
|
|
202
|
+
export async function createExplicitFeatureDirectory(featDir, featureId) {
|
|
203
|
+
try {
|
|
204
|
+
await fs.mkdir(featDir);
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
if (isNodeErrorCode(err, 'EEXIST')) {
|
|
209
|
+
return {
|
|
210
|
+
success: false,
|
|
211
|
+
error: {
|
|
212
|
+
code: 'ERR_FEATURE_ALREADY_EXISTS',
|
|
213
|
+
message: `Feature '${featureId}' already exists in the workspace.`,
|
|
214
|
+
trigger: 'sdd_create_feature',
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
throw err;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export async function reserveAutomaticFeatureDirectory(featuresDir, title) {
|
|
222
|
+
const entries = await fs.readdir(featuresDir, { withFileTypes: true });
|
|
223
|
+
const featureNames = entries
|
|
224
|
+
.filter((entry) => entry.isDirectory() && /^FEAT[-_]/u.test(entry.name))
|
|
225
|
+
.map((entry) => entry.name);
|
|
226
|
+
const allocatedSequences = entries.flatMap((entry) => {
|
|
227
|
+
if (!entry.isDirectory()) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
const sequence = /^FEAT[-_](\d+)(?:[-_]|$)/u.exec(entry.name)?.[1] ??
|
|
231
|
+
/^\.FEAT-(\d+)\.reserve$/u.exec(entry.name)?.[1];
|
|
232
|
+
return sequence ? [Number(sequence)] : [];
|
|
233
|
+
});
|
|
234
|
+
const highestSequence = Math.max(0, ...allocatedSequences);
|
|
235
|
+
let nextSequence = Math.max(highestSequence + 1, featureNames.length + 1);
|
|
236
|
+
const slug = createFeatureSlug(title);
|
|
237
|
+
for (;;) {
|
|
238
|
+
const sequenceLabel = String(nextSequence).padStart(4, '0');
|
|
239
|
+
const reservationDir = path.join(featuresDir, `.FEAT-${sequenceLabel}.reserve`);
|
|
240
|
+
try {
|
|
241
|
+
await fs.mkdir(reservationDir);
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
if (!isNodeErrorCode(err, 'EEXIST')) {
|
|
245
|
+
throw err;
|
|
246
|
+
}
|
|
247
|
+
nextSequence += 1;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const featureId = `FEAT-${sequenceLabel}-${slug}`;
|
|
251
|
+
const featDir = path.join(featuresDir, featureId);
|
|
252
|
+
try {
|
|
253
|
+
await fs.mkdir(featDir);
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
await fs.rm(reservationDir, { recursive: true, force: true });
|
|
257
|
+
if (isNodeErrorCode(err, 'EEXIST')) {
|
|
258
|
+
nextSequence += 1;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
throw err;
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
await fs.rm(reservationDir, { recursive: true, force: false });
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
await fs.rm(featDir, { recursive: true, force: true });
|
|
268
|
+
throw err;
|
|
269
|
+
}
|
|
270
|
+
return { featureId, featDir };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function createFeatureSlug(title) {
|
|
274
|
+
const slug = title
|
|
275
|
+
.normalize('NFKD')
|
|
276
|
+
.replace(/[\u0300-\u036f]/gu, '')
|
|
277
|
+
.toUpperCase()
|
|
278
|
+
.replace(/[^A-Z0-9]+/gu, '-')
|
|
279
|
+
.replace(/^-+|-+$/gu, '')
|
|
280
|
+
.slice(0, 48)
|
|
281
|
+
.replace(/-+$/gu, '');
|
|
282
|
+
return slug || 'FEATURE';
|
|
283
|
+
}
|
|
284
|
+
function isNodeErrorCode(err, code) {
|
|
285
|
+
return typeof err === 'object' && err !== null && 'code' in err && err.code === code;
|
|
286
|
+
}
|
|
197
287
|
//# sourceMappingURL=workspace-init.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
1
|
+
import type * as Models from '../types/resume-views.js';
|
|
2
|
+
import type * as Engine from '../types/sdd-engine.js';
|
|
3
|
+
import type * as Completion from '../types/completion.js';
|
|
4
|
+
import type { ReadCursorPayload, SourceCursorPayload } from '../types/resume-views.js';
|
|
5
|
+
import type { HostSkillReadResult } from '../types/sdd-engine.js';
|
|
6
|
+
export { withSourceDescriptor } from './source-descriptor.js';
|
|
7
7
|
export declare function readTextInsideWorkspace(workspaceRoot: string, absolutePath: string, options?: {
|
|
8
8
|
maxBytes: number;
|
|
9
9
|
}): Promise<{
|
|
@@ -13,5 +13,31 @@ export declare function readTextInsideWorkspace(workspaceRoot: string, absoluteP
|
|
|
13
13
|
ok: false;
|
|
14
14
|
reason: 'outside' | 'missing';
|
|
15
15
|
}>;
|
|
16
|
-
export {
|
|
16
|
+
export { parseMcpRootUri, resolveSddWorkspaceRoot, resolveSddWorkspace, isHomeFallbackWorkspace, homeFallbackFailure, } from './client-workspace.js';
|
|
17
|
+
export declare function readTextInsideWorkspaceDetailed(workspaceRoot: string, absolutePath: string, options: {
|
|
18
|
+
maxBytes: number;
|
|
19
|
+
}): Promise<HostSkillReadResult>;
|
|
20
|
+
export declare function sourceRequestSha256(path: string, startLine: number, endLine: number): string;
|
|
21
|
+
export declare class ReadCursorCodec {
|
|
22
|
+
#private;
|
|
23
|
+
encode(payload: ReadCursorPayload): string;
|
|
24
|
+
decode(token: unknown): ReadCursorPayload | null;
|
|
25
|
+
}
|
|
26
|
+
declare const failures: {
|
|
27
|
+
readonly slice_input_invalid: readonly ["ERR_INVALID_SLICE", "fix_inputs"];
|
|
28
|
+
readonly slice_cursor_invalid: readonly ["ERR_INVALID_SLICE", "reread_slice"];
|
|
29
|
+
readonly slice_cursor_stale: readonly ["ERR_SPEC_DRIFT", "reread_slice"];
|
|
30
|
+
readonly slice_path_unsafe: readonly ["ERR_PERMISSION_VIOLATION", "inspect_artifacts"];
|
|
31
|
+
readonly slice_capability_unavailable: readonly ["ERR_PERMISSION_VIOLATION", "use_supported_runtime"];
|
|
32
|
+
readonly slice_unavailable: readonly ["ERR_INVALID_SLICE", "inspect_artifacts"];
|
|
33
|
+
readonly slice_invalid_utf8: readonly ["ERR_INVALID_SLICE", "inspect_artifacts"];
|
|
34
|
+
readonly slice_range_unavailable: readonly ["ERR_INVALID_SLICE", "fix_inputs"];
|
|
35
|
+
readonly slice_response_too_large: readonly ["ERR_INVALID_SLICE", "inspect_artifacts"];
|
|
36
|
+
readonly cancelled: readonly ["ERR_VERIFICATION_FAILED", "retry_read"];
|
|
37
|
+
};
|
|
38
|
+
export declare function failure(reason: keyof typeof failures): Engine.SddResult<never>;
|
|
39
|
+
export declare function slicePath(workspaceRoot: string, input: Engine.ReadFileSliceInput): string | null | undefined;
|
|
40
|
+
export declare function descriptorFailure(cause: Completion.SourceDescriptorFailure, cursor: boolean): keyof typeof failures;
|
|
41
|
+
export declare function initialPosition(cursor: Models.SourceCursorPayload | null, snapshot: Completion.SourceDescriptorSnapshot, input: Engine.ReadFileSliceInput): Models.SourceProgress | keyof typeof failures;
|
|
42
|
+
export declare function requestCursor(input: Engine.ReadFileSliceInput, path: string, codec: ReadCursorCodec): SourceCursorPayload | null | undefined;
|
|
17
43
|
//# sourceMappingURL=workspace-root.d.ts.map
|