@planu/cli 8.9.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +4 -2
  3. package/dist/sdd-engine/canonical-tools.d.ts +13 -1
  4. package/dist/sdd-engine/canonical-tools.js +76 -3
  5. package/dist/sdd-engine/catalogue-presentation.d.ts +23 -0
  6. package/dist/sdd-engine/catalogue-presentation.js +123 -0
  7. package/dist/sdd-engine/completion-snapshot.d.ts +2 -1
  8. package/dist/sdd-engine/completion-snapshot.js +81 -23
  9. package/dist/sdd-engine/contracts.d.ts +1 -1
  10. package/dist/sdd-engine/contracts.js +4 -1
  11. package/dist/sdd-engine/feature-authority.d.ts +3 -2
  12. package/dist/sdd-engine/feature-authority.js +29 -1
  13. package/dist/sdd-engine/host-rule-pack.js +12 -2
  14. package/dist/sdd-engine/source-descriptor.d.ts +2 -2
  15. package/dist/sdd-engine/source-descriptor.js +38 -14
  16. package/dist/sdd-engine/tools/feature-store.d.ts +6 -6
  17. package/dist/sdd-engine/tools/feature-store.js +188 -84
  18. package/dist/sdd-engine/tools/workspace-tools.d.ts +1 -1
  19. package/dist/sdd-engine/tools/workspace-tools.js +43 -34
  20. package/dist/sdd-engine/workspace-init.d.ts +6 -0
  21. package/dist/sdd-engine/workspace-init.js +92 -2
  22. package/dist/sdd-engine/workspace-root.d.ts +3 -3
  23. package/dist/sdd-engine/workspace-root.js +23 -5
  24. package/dist/types/completion.d.ts +27 -1
  25. package/dist/types/resume-views.d.ts +15 -1
  26. package/dist/types/sdd-engine.d.ts +12 -1
  27. package/package.json +2 -2
  28. package/templates/AGENTS.md +2 -0
  29. package/templates/host/planu-sdd.md +2 -0
  30. package/templates/skills/preflight-guardian.md +2 -0
  31. package/templates/skills/spec-executor.md +2 -0
@@ -15,6 +15,11 @@ function sameFile(a, b) {
15
15
  function safeFile(stat) {
16
16
  return stat.isFile() && !stat.isSymbolicLink() && stat.nlink === 1n;
17
17
  }
18
+ function safeOwned(stat, profile) {
19
+ return (safeFile(stat) &&
20
+ (profile !== 'catalogue' ||
21
+ (typeof process.getuid === 'function' && stat.uid === BigInt(process.getuid()))));
22
+ }
18
23
  function errorCause(error, observed) {
19
24
  const code = typeof error === 'object' && error !== null && 'code' in error ? error.code : undefined;
20
25
  switch (code) {
@@ -137,10 +142,10 @@ class Descriptor {
137
142
  async captureFile(current) {
138
143
  const before = await this.checked(() => lstat(current, { bigint: true }));
139
144
  this.observed = true;
140
- if (!safeFile(before)) {
145
+ if (!safeOwned(before, this.profile)) {
141
146
  this.deny('unsafe_path');
142
147
  }
143
- if (this.profile !== 'source' && before.size > BigInt(this.profile)) {
148
+ if (typeof this.profile === 'number' && before.size > BigInt(this.profile)) {
144
149
  this.deny('over_limit');
145
150
  }
146
151
  if (before.size < 0n || before.size > BigInt(Number.MAX_SAFE_INTEGER)) {
@@ -150,13 +155,13 @@ class Descriptor {
150
155
  this.handle = await open(current, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
151
156
  });
152
157
  const opened = await this.checked(() => this.requireHandle().stat({ bigint: true }));
153
- if (!safeFile(opened)) {
158
+ if (!safeOwned(opened, this.profile)) {
154
159
  this.deny('unsafe_path');
155
160
  }
156
161
  if (!sameFile(before, opened)) {
157
162
  this.deny('unstable');
158
163
  }
159
- if (this.profile !== 'source' && opened.size > BigInt(this.profile)) {
164
+ if (typeof this.profile === 'number' && opened.size > BigInt(this.profile)) {
160
165
  this.deny('over_limit');
161
166
  }
162
167
  this.opened = opened;
@@ -176,13 +181,18 @@ class Descriptor {
176
181
  }
177
182
  return this.handle;
178
183
  }
184
+ invalidCatalogueRead(position, length) {
185
+ return (this.profile === 'catalogue' &&
186
+ (position !== this.bytes || position >= Number(this.opened.size) || length > 4096));
187
+ }
179
188
  validateRead(position, length, capacity) {
180
189
  if (!Number.isSafeInteger(position) ||
181
190
  position < 0 ||
182
191
  !Number.isSafeInteger(length) ||
183
192
  length <= 0 ||
184
193
  !Number.isSafeInteger(position + length) ||
185
- this.bytes >= capacity) {
194
+ (this.profile !== 'catalogue' && this.bytes >= capacity) ||
195
+ this.invalidCatalogueRead(position, length)) {
186
196
  this.deny('read_failed');
187
197
  }
188
198
  if (this.profile === 'source' &&
@@ -192,21 +202,21 @@ class Descriptor {
192
202
  }
193
203
  async executeRead(position, length) {
194
204
  this.abort();
195
- const capacity = this.profile === 'source' ? 65_536 : this.profile;
205
+ const capacity = this.profile === 'source' ? 65_536 : this.profile === 'catalogue' ? 4096 : this.profile;
196
206
  this.validateRead(position, length, capacity);
197
- const amount = Math.min(length, capacity - this.bytes, this.profile === 'source' ? Number(this.opened.size) - position : length);
207
+ const amount = Math.min(length, this.profile === 'catalogue' ? capacity : capacity - this.bytes, typeof this.profile !== 'number' ? Number(this.opened.size) - position : length);
198
208
  const bank = (this.bank ??= Buffer.alloc(capacity));
199
- const start = this.bytes;
209
+ const start = this.profile === 'catalogue' ? 0 : this.bytes;
200
210
  const result = await this.checked(async () => {
201
211
  this.calls++;
202
212
  const read = await this.requireHandle().read(bank, start, amount, position);
203
213
  this.bytes += read.bytesRead;
204
214
  return read;
205
215
  });
206
- if (result.bytesRead === 0 && this.profile === 'source') {
216
+ if (result.bytesRead === 0 && typeof this.profile !== 'number') {
207
217
  this.deny('unstable');
208
218
  }
209
- return bank.subarray(start, this.bytes);
219
+ return bank.subarray(start, this.profile === 'catalogue' ? result.bytesRead : this.bytes);
210
220
  }
211
221
  read = (position, length) => {
212
222
  if (!this.accepting || this.pending || this.failure !== undefined) {
@@ -229,7 +239,7 @@ class Descriptor {
229
239
  async revalidate() {
230
240
  const after = await this.checked(() => this.requireHandle().stat({ bigint: true }));
231
241
  const named = await this.checked(() => lstat(this.target, { bigint: true }));
232
- if (this.profile !== 'source' &&
242
+ if (typeof this.profile === 'number' &&
233
243
  (after.size > BigInt(this.profile) || named.size > BigInt(this.profile))) {
234
244
  this.deny('over_limit');
235
245
  }
@@ -307,16 +317,30 @@ class Descriptor {
307
317
  }
308
318
  }
309
319
  function sourceContainsNul(profile, local) {
310
- return profile === 'source' && local.includes('\0');
320
+ return typeof profile !== 'number' && local.includes('\0');
321
+ }
322
+ function supportedProfile(profile) {
323
+ return (profile === 'source' ||
324
+ profile === 'catalogue' ||
325
+ (typeof profile === 'number' &&
326
+ Number.isSafeInteger(profile) &&
327
+ profile >= 0 &&
328
+ profile <= 65_536));
329
+ }
330
+ function missingCapability(profile) {
331
+ return ((profile === 'source' || profile === 'catalogue') &&
332
+ (!constants.O_NOFOLLOW ||
333
+ !constants.O_NONBLOCK ||
334
+ (profile === 'catalogue' && typeof process.getuid !== 'function')));
311
335
  }
312
336
  export function withSourceDescriptor(workspaceRoot, local, callback, profile = 'source', signal) {
313
337
  if (signal?.aborted) {
314
338
  return Promise.resolve({ ok: false, cause: 'cancelled' });
315
339
  }
316
- if (profile === 'source' && (!constants.O_NOFOLLOW || !constants.O_NONBLOCK)) {
340
+ if (missingCapability(profile)) {
317
341
  return Promise.resolve({ ok: false, cause: 'capability_unavailable' });
318
342
  }
319
- if (profile !== 'source' && (!Number.isSafeInteger(profile) || profile < 0 || profile > 65_536)) {
343
+ if (!supportedProfile(profile)) {
320
344
  return Promise.resolve({ ok: false, cause: 'read_failed' });
321
345
  }
322
346
  if (sourceContainsNul(profile, local)) {
@@ -1,11 +1,11 @@
1
- import type { FeatureSummary, SddFailure, SddResult } from '../../types/sdd-engine.js';
1
+ import type { CataloguePageV1, FeatureSummary, ListFeaturesInput, SddFailure, SddResult } from '../../types/sdd-engine.js';
2
+ import type { ReadCursorCodec } from '../workspace-root.js';
2
3
  import type { TaskWindowManager } from '../task-window.js';
3
- export declare function createExplicitFeatureDirectory(featDir: string, featureId: string): Promise<SddFailure | null>;
4
- export declare function reserveAutomaticFeatureDirectory(featuresDir: string, title: string): Promise<{
5
- featureId: string;
6
- featDir: string;
7
- }>;
4
+ export { createExplicitFeatureDirectory, reserveAutomaticFeatureDirectory, } from '../workspace-init.js';
8
5
  export declare function collectFeatures(featuresDir: string, taskWindow: TaskWindowManager, statusFilter?: 'all' | 'planning' | 'executing' | 'done'): Promise<SddResult<FeatureSummary[]>>;
9
6
  export declare function featurePathFailure(workspaceRoot: string, directory: string, trigger: string): Promise<SddFailure | null>;
10
7
  export declare function writeFeatureArtifacts(featDir: string, id: string, title: string): Promise<void>;
8
+ export declare function readFeatureCatalogue(workspaceRoot: string, input: ListFeaturesInput, codec: ReadCursorCodec, signal?: AbortSignal): Promise<SddResult<{
9
+ catalogue: CataloguePageV1;
10
+ }>>;
11
11
  //# sourceMappingURL=feature-store.d.ts.map
@@ -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
- 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
- }
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, { encoding: 'utf8', flag: 'wx' });
218
- await fs.writeFile(path.join(featDir, 'plan.md'), initialPlan, { encoding: 'utf8', flag: 'wx' });
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,5 +1,5 @@
1
1
  import { ReadCursorCodec } from '../workspace-root.js';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
4
- export declare function registerWorkspaceTools(server: McpServer, workspace: SddWorkspaceHandle, bundledVersion?: string, _codec?: ReadCursorCodec): void;
4
+ export declare function registerWorkspaceTools(server: McpServer, workspace: SddWorkspaceHandle, bundledVersion?: string, codec?: ReadCursorCodec): void;
5
5
  //# sourceMappingURL=workspace-tools.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { homeFallbackFailure, ReadCursorCodec } from '../workspace-root.js';
2
- import { TOOL_ANNOTATIONS } from '../canonical-tools.js';
2
+ import * as canonical from '../canonical-tools.js';
3
3
  import * as fs from 'node:fs/promises';
4
4
  import * as path from 'node:path';
5
5
  import * as contracts from '../contracts.js';
@@ -10,9 +10,8 @@ import { readTrinityFailureIssues, writeLockedTrinity } from '../lock-integrity.
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
- const combined = [extra, pack, legacySpecsPresent ? LEGACY_SPECS_HINT : undefined]
27
- .filter((item) => item !== undefined)
28
- .join(' ');
29
- if (!combined) {
30
- return undefined;
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, _codec = new ReadCursorCodec()) {
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 listFailure(reason) {
105
- const failure = compact.compactFailure(reason);
106
- if (!failure.success) {
107
- failure.error.trigger = 'sdd_list_features';
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 listFailure('compact_input_invalid');
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) => {
@@ -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