@planu/cli 8.7.3 → 8.9.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 (34) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +11 -3
  3. package/dist/sdd-engine/canonical-tools.d.ts +57 -0
  4. package/dist/sdd-engine/canonical-tools.js +78 -0
  5. package/dist/sdd-engine/client-workspace.d.ts +8 -1
  6. package/dist/sdd-engine/client-workspace.js +168 -1
  7. package/dist/sdd-engine/contracts.d.ts +1 -23
  8. package/dist/sdd-engine/contracts.js +1 -18
  9. package/dist/sdd-engine/feature-manifest.js +1 -1
  10. package/dist/sdd-engine/host-rule-pack.d.ts +7 -3
  11. package/dist/sdd-engine/host-rule-pack.js +28 -52
  12. package/dist/sdd-engine/host-skill-reader.d.ts +12 -10
  13. package/dist/sdd-engine/host-skill-reader.js +252 -194
  14. package/dist/sdd-engine/source-descriptor.d.ts +3 -0
  15. package/dist/sdd-engine/source-descriptor.js +332 -0
  16. package/dist/sdd-engine/tools/execution-tools.d.ts +2 -1
  17. package/dist/sdd-engine/tools/execution-tools.js +70 -86
  18. package/dist/sdd-engine/tools/workspace-tools.d.ts +2 -1
  19. package/dist/sdd-engine/tools/workspace-tools.js +10 -20
  20. package/dist/sdd-engine/tools.js +4 -2
  21. package/dist/sdd-engine/trinity-structure.js +1 -1
  22. package/dist/sdd-engine/verification-receipts.d.ts +3 -2
  23. package/dist/sdd-engine/verification-receipts.js +50 -1
  24. package/dist/sdd-engine/workspace-root.d.ts +33 -7
  25. package/dist/sdd-engine/workspace-root.js +204 -139
  26. package/dist/types/completion.d.ts +20 -2
  27. package/dist/types/resume-views.d.ts +62 -0
  28. package/dist/types/sdd-engine.d.ts +23 -60
  29. package/dist/types/verification.d.ts +59 -0
  30. package/package.json +1 -1
  31. package/templates/AGENTS.md +4 -0
  32. package/templates/host/planu-sdd.md +4 -0
  33. package/templates/skills/preflight-guardian.md +4 -0
  34. package/templates/skills/spec-executor.md +4 -0
@@ -0,0 +1,332 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { constants } from 'node:fs';
3
+ import { lstat, open, realpath } from 'node:fs/promises';
4
+ import { join, relative, resolve, sep } from 'node:path';
5
+ function sameIdentity(a, b) {
6
+ return (a.dev === b.dev && a.ino === b.ino && a.mode === b.mode && a.uid === b.uid && a.gid === b.gid);
7
+ }
8
+ function sameFile(a, b) {
9
+ return (sameIdentity(a, b) &&
10
+ a.nlink === b.nlink &&
11
+ a.size === b.size &&
12
+ a.mtimeNs === b.mtimeNs &&
13
+ a.ctimeNs === b.ctimeNs);
14
+ }
15
+ function safeFile(stat) {
16
+ return stat.isFile() && !stat.isSymbolicLink() && stat.nlink === 1n;
17
+ }
18
+ function errorCause(error, observed) {
19
+ const code = typeof error === 'object' && error !== null && 'code' in error ? error.code : undefined;
20
+ switch (code) {
21
+ case 'ENOENT':
22
+ return observed ? 'unstable' : 'not_found';
23
+ case 'EACCES':
24
+ case 'EPERM':
25
+ return 'access_denied';
26
+ case 'ELOOP':
27
+ case 'ENOTDIR':
28
+ return 'unsafe_path';
29
+ default:
30
+ return 'read_failed';
31
+ }
32
+ }
33
+ class DescriptorFailure extends Error {
34
+ reason;
35
+ constructor(reason) {
36
+ super(reason);
37
+ this.reason = reason;
38
+ }
39
+ }
40
+ function tuple(stat) {
41
+ return [stat.dev, stat.ino, stat.mode, stat.uid, stat.gid].map(String);
42
+ }
43
+ function digest(value) {
44
+ return createHash('sha256').update(JSON.stringify(value)).digest('hex');
45
+ }
46
+ class Descriptor {
47
+ lexicalRoot;
48
+ local;
49
+ profile;
50
+ signal;
51
+ directories = [];
52
+ root = '';
53
+ target = '';
54
+ opened;
55
+ handle;
56
+ observed = false;
57
+ bank;
58
+ bytes = 0;
59
+ calls = 0;
60
+ accepting = false;
61
+ pending = false;
62
+ observation = Promise.resolve();
63
+ failure;
64
+ constructor(lexicalRoot, local, profile, signal) {
65
+ this.lexicalRoot = lexicalRoot;
66
+ this.local = local;
67
+ this.profile = profile;
68
+ this.signal = signal;
69
+ }
70
+ deny(reason) {
71
+ throw new DescriptorFailure(reason);
72
+ }
73
+ abort() {
74
+ if (this.signal?.aborted) {
75
+ this.deny('cancelled');
76
+ }
77
+ }
78
+ async checked(operation) {
79
+ this.abort();
80
+ try {
81
+ return await operation();
82
+ }
83
+ finally {
84
+ this.abort();
85
+ }
86
+ }
87
+ async directoriesStable() {
88
+ if (this.root && (await this.checked(() => realpath(this.lexicalRoot))) !== this.root) {
89
+ return false;
90
+ }
91
+ for (const directory of this.directories) {
92
+ const current = await this.checked(() => lstat(directory.path, { bigint: true }));
93
+ if (!current.isDirectory() ||
94
+ current.isSymbolicLink() ||
95
+ !sameIdentity(directory.stat, current)) {
96
+ return false;
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ projection() {
102
+ const first = this.directories[0];
103
+ if (!first) {
104
+ this.deny('unsafe_path');
105
+ }
106
+ const rootHash = digest(['planu.source-root.v1', this.root, ...tuple(first.stat)]);
107
+ const ancestors = this.directories
108
+ .slice(1)
109
+ .map(({ path, stat }) => [relative(this.root, path), ...tuple(stat)]);
110
+ const file = this.opened;
111
+ return Object.freeze({
112
+ size: Number(file.size),
113
+ rootIdentitySha256: rootHash,
114
+ snapshotSha256: digest([
115
+ 'planu.source-snapshot.v1',
116
+ rootHash,
117
+ ancestors,
118
+ this.local,
119
+ [...tuple(file), ...[file.nlink, file.size, file.mtimeNs, file.ctimeNs].map(String)],
120
+ ]),
121
+ });
122
+ }
123
+ async capture() {
124
+ this.root = await this.checked(() => realpath(this.lexicalRoot));
125
+ let current = this.root;
126
+ for (const component of this.local.split(sep)) {
127
+ const stat = await this.checked(() => lstat(current, { bigint: true }));
128
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
129
+ this.deny('unsafe_path');
130
+ }
131
+ this.directories.push({ path: current, stat });
132
+ current = join(current, component);
133
+ }
134
+ this.target = current;
135
+ return this.captureFile(current);
136
+ }
137
+ async captureFile(current) {
138
+ const before = await this.checked(() => lstat(current, { bigint: true }));
139
+ this.observed = true;
140
+ if (!safeFile(before)) {
141
+ this.deny('unsafe_path');
142
+ }
143
+ if (this.profile !== 'source' && before.size > BigInt(this.profile)) {
144
+ this.deny('over_limit');
145
+ }
146
+ if (before.size < 0n || before.size > BigInt(Number.MAX_SAFE_INTEGER)) {
147
+ this.deny('read_failed');
148
+ }
149
+ await this.checked(async () => {
150
+ this.handle = await open(current, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
151
+ });
152
+ const opened = await this.checked(() => this.requireHandle().stat({ bigint: true }));
153
+ if (!safeFile(opened)) {
154
+ this.deny('unsafe_path');
155
+ }
156
+ if (!sameFile(before, opened)) {
157
+ this.deny('unstable');
158
+ }
159
+ if (this.profile !== 'source' && opened.size > BigInt(this.profile)) {
160
+ this.deny('over_limit');
161
+ }
162
+ this.opened = opened;
163
+ if (!(await this.directoriesStable()) ||
164
+ (await this.checked(() => realpath(current))) !== current) {
165
+ this.deny('unstable');
166
+ }
167
+ const named = await this.checked(() => lstat(current, { bigint: true }));
168
+ if (!safeFile(named) || !sameFile(opened, named)) {
169
+ this.deny('unstable');
170
+ }
171
+ return this.projection();
172
+ }
173
+ requireHandle() {
174
+ if (!this.handle) {
175
+ this.deny('read_failed');
176
+ }
177
+ return this.handle;
178
+ }
179
+ validateRead(position, length, capacity) {
180
+ if (!Number.isSafeInteger(position) ||
181
+ position < 0 ||
182
+ !Number.isSafeInteger(length) ||
183
+ length <= 0 ||
184
+ !Number.isSafeInteger(position + length) ||
185
+ this.bytes >= capacity) {
186
+ this.deny('read_failed');
187
+ }
188
+ if (this.profile === 'source' &&
189
+ (position >= Number(this.opened.size) || length > 4096 || this.calls >= 64)) {
190
+ this.deny('read_failed');
191
+ }
192
+ }
193
+ async executeRead(position, length) {
194
+ this.abort();
195
+ const capacity = this.profile === 'source' ? 65_536 : this.profile;
196
+ this.validateRead(position, length, capacity);
197
+ const amount = Math.min(length, capacity - this.bytes, this.profile === 'source' ? Number(this.opened.size) - position : length);
198
+ const bank = (this.bank ??= Buffer.alloc(capacity));
199
+ const start = this.bytes;
200
+ const result = await this.checked(async () => {
201
+ this.calls++;
202
+ const read = await this.requireHandle().read(bank, start, amount, position);
203
+ this.bytes += read.bytesRead;
204
+ return read;
205
+ });
206
+ if (result.bytesRead === 0 && this.profile === 'source') {
207
+ this.deny('unstable');
208
+ }
209
+ return bank.subarray(start, this.bytes);
210
+ }
211
+ read = (position, length) => {
212
+ if (!this.accepting || this.pending || this.failure !== undefined) {
213
+ const error = new DescriptorFailure('read_failed');
214
+ this.failure ??= error;
215
+ const rejected = Promise.reject(error);
216
+ void rejected.catch(() => undefined);
217
+ return rejected;
218
+ }
219
+ this.pending = true;
220
+ const operation = Promise.resolve().then(() => this.executeRead(position, length));
221
+ this.observation = operation.then(() => {
222
+ this.pending = false;
223
+ }, (error) => {
224
+ this.failure ??= error;
225
+ this.pending = false;
226
+ });
227
+ return operation;
228
+ };
229
+ async revalidate() {
230
+ const after = await this.checked(() => this.requireHandle().stat({ bigint: true }));
231
+ const named = await this.checked(() => lstat(this.target, { bigint: true }));
232
+ if (this.profile !== 'source' &&
233
+ (after.size > BigInt(this.profile) || named.size > BigInt(this.profile))) {
234
+ this.deny('over_limit');
235
+ }
236
+ if (!sameFile(this.opened, after) ||
237
+ !sameFile(after, named) ||
238
+ !safeFile(named) ||
239
+ (this.profile !== 'source' && after.size !== BigInt(this.bytes)) ||
240
+ !(await this.directoriesStable()) ||
241
+ (await this.checked(() => realpath(this.target))) !== this.target) {
242
+ this.deny('unstable');
243
+ }
244
+ }
245
+ async failureCause(error) {
246
+ if (error instanceof DescriptorFailure) {
247
+ return error.reason;
248
+ }
249
+ const cause = errorCause(error, this.observed);
250
+ try {
251
+ if (!(await this.directoriesStable())) {
252
+ return 'unstable';
253
+ }
254
+ return cause === 'not_found' && !this.directories.length ? 'unsafe_path' : cause;
255
+ }
256
+ catch {
257
+ return this.signal?.aborted ? 'cancelled' : 'unstable';
258
+ }
259
+ }
260
+ async run(callback) {
261
+ let result;
262
+ try {
263
+ const snapshot = await this.capture();
264
+ this.accepting = true;
265
+ let value;
266
+ let callbackError;
267
+ let callbackFailed = false;
268
+ try {
269
+ value = await callback({ snapshot, read: this.read });
270
+ }
271
+ catch (error) {
272
+ callbackError = error;
273
+ callbackFailed = true;
274
+ }
275
+ this.accepting = false;
276
+ await this.observation;
277
+ if (callbackFailed) {
278
+ throw new DescriptorFailure(await this.failureCause(callbackError));
279
+ }
280
+ if (this.failure !== undefined) {
281
+ throw new DescriptorFailure(await this.failureCause(this.failure));
282
+ }
283
+ await this.revalidate();
284
+ result = { ok: true, value: value };
285
+ }
286
+ catch (error) {
287
+ result = { ok: false, cause: await this.failureCause(error) };
288
+ }
289
+ finally {
290
+ this.accepting = false;
291
+ try {
292
+ await this.handle?.close();
293
+ }
294
+ catch {
295
+ result = { ok: false, cause: 'read_failed' };
296
+ }
297
+ this.handle = undefined;
298
+ this.bank = undefined;
299
+ }
300
+ if (this.failure !== undefined && result.ok) {
301
+ result = { ok: false, cause: await this.failureCause(this.failure) };
302
+ }
303
+ if (this.signal?.aborted) {
304
+ return { ok: false, cause: 'cancelled' };
305
+ }
306
+ return result;
307
+ }
308
+ }
309
+ function sourceContainsNul(profile, local) {
310
+ return profile === 'source' && local.includes('\0');
311
+ }
312
+ export function withSourceDescriptor(workspaceRoot, local, callback, profile = 'source', signal) {
313
+ if (signal?.aborted) {
314
+ return Promise.resolve({ ok: false, cause: 'cancelled' });
315
+ }
316
+ if (profile === 'source' && (!constants.O_NOFOLLOW || !constants.O_NONBLOCK)) {
317
+ return Promise.resolve({ ok: false, cause: 'capability_unavailable' });
318
+ }
319
+ if (profile !== 'source' && (!Number.isSafeInteger(profile) || profile < 0 || profile > 65_536)) {
320
+ return Promise.resolve({ ok: false, cause: 'read_failed' });
321
+ }
322
+ if (sourceContainsNul(profile, local)) {
323
+ return Promise.resolve({ ok: false, cause: 'unsafe_path' });
324
+ }
325
+ if (!local ||
326
+ local.split(sep).some((part) => !part || part === '.' || part === '..') ||
327
+ resolve(local) === local) {
328
+ return Promise.resolve({ ok: false, cause: 'unsafe_path' });
329
+ }
330
+ return new Descriptor(resolve(workspaceRoot), local, profile, signal).run(callback);
331
+ }
332
+ //# sourceMappingURL=source-descriptor.js.map
@@ -3,5 +3,6 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { TaskWindowManager } from '../task-window.js';
4
4
  export { sliceNumberedSource } from '../task-content.js';
5
5
  import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
6
- export declare function registerExecutionTools(server: McpServer, workspace: SddWorkspaceHandle, policy?: VerificationPolicy): TaskWindowManager;
6
+ import { ReadCursorCodec } from '../workspace-root.js';
7
+ export declare function registerExecutionTools(server: McpServer, workspace: SddWorkspaceHandle, policy?: VerificationPolicy, codec?: ReadCursorCodec): TaskWindowManager;
7
8
  //# sourceMappingURL=execution-tools.d.ts.map
@@ -1,22 +1,24 @@
1
+ import { TOOL_ANNOTATIONS } from '../canonical-tools.js';
1
2
  import * as path from 'node:path';
2
3
  import { ReadSpecArtifactInputSchema, ReadFileSliceInputSchema, GetActiveTaskInputSchema, ApplyFilePatchInputSchema, CompleteTaskInputSchema, } from '../contracts.js';
3
4
  import { PatchSandbox } from '../patch-sandbox.js';
4
- import { TaskWindowManager, verificationCommand } from '../task-window.js';
5
- import { activeTaskFromContent, hasReceiptDirective, sliceNumberedSource, } from '../task-content.js';
5
+ import { TaskWindowManager } from '../task-window.js';
6
+ import { hasReceiptDirective, sliceNumberedSource } from '../task-content.js';
6
7
  export { sliceNumberedSource } from '../task-content.js';
7
8
  import { parseManifestContent, parseVerificationReceiptPolicy, toPosixPath, } from '../feature-manifest.js';
8
- import { captureReceiptEvidence } from '../verification-receipts.js';
9
- import { captureVerificationRoot, checkReceiptPatchTarget, revalidateVerificationInputs, } from '../verification-inputs.js';
10
- import { completionError, completionFailure, patchMutationError } from '../task-failures.js';
11
- import { formatResult } from './compact-result.js';
12
- import { acquireCompletionLease, inspectCompletionGuard } from '../completion-guard.js';
9
+ import { getReceiptActiveTask } from '../verification-receipts.js';
10
+ import { captureVerificationRoot, checkReceiptPatchTarget } from '../verification-inputs.js';
11
+ import { patchMutationError } from '../task-failures.js';
12
+ import { formatCompactResult, formatResult } from './compact-result.js';
13
+ import { readBoundedSource } from '../host-skill-reader.js';
14
+ import { acquireCompletionLease } from '../completion-guard.js';
13
15
  import { captureCompletionSnapshot, revalidateCompletionSnapshot } from '../completion-snapshot.js';
14
- import { homeFallbackFailure, readTextInsideWorkspace } from '../workspace-root.js';
16
+ import { homeFallbackFailure, readTextInsideWorkspace, ReadCursorCodec, } from '../workspace-root.js';
15
17
  import { guardFailure } from '../feature-authority.js';
16
- export function registerExecutionTools(server, workspace, policy) {
18
+ export function registerExecutionTools(server, workspace, policy, codec = new ReadCursorCodec()) {
17
19
  const taskWindow = new TaskWindowManager(policy);
18
20
  registerReadArtifactTool(server, workspace);
19
- registerReadFileSliceTool(server, workspace);
21
+ registerReadFileSliceTool(server, workspace, codec);
20
22
  registerGetActiveTaskTool(server, workspace, taskWindow);
21
23
  registerApplyPatchTool(server, workspace);
22
24
  registerCompleteTaskTool(server, workspace, taskWindow);
@@ -24,6 +26,7 @@ export function registerExecutionTools(server, workspace, policy) {
24
26
  }
25
27
  function registerReadArtifactTool(server, workspace) {
26
28
  server.registerTool('sdd_read_spec_artifact', {
29
+ annotations: TOOL_ANNOTATIONS.sdd_read_spec_artifact,
27
30
  description: 'Reads one of the three Holy Trinity artifacts (spec, plan, or tasks).',
28
31
  inputSchema: ReadSpecArtifactInputSchema.shape,
29
32
  }, async (rawArgs) => {
@@ -50,12 +53,16 @@ function registerReadArtifactTool(server, workspace) {
50
53
  return { content: [{ type: 'text', text: read.text }] };
51
54
  });
52
55
  }
53
- function registerReadFileSliceTool(server, workspace) {
56
+ function registerReadFileSliceTool(server, workspace, codec) {
54
57
  server.registerTool('sdd_read_file_slice', {
58
+ annotations: TOOL_ANNOTATIONS.sdd_read_file_slice,
55
59
  description: 'Reads an exact line slice from a target file to optimize token usage.',
56
60
  inputSchema: ReadFileSliceInputSchema.shape,
57
- }, async (rawArgs) => {
61
+ }, async (rawArgs, extra) => {
58
62
  const args = ReadFileSliceInputSchema.parse(rawArgs);
63
+ if (args.view !== undefined || args.cursor !== undefined) {
64
+ return executeBoundedSlice(workspace, args, codec, extra.signal);
65
+ }
59
66
  const resolved = await workspace.resolve();
60
67
  const homeError = homeFallbackFailure(resolved, 'sdd_read_file_slice');
61
68
  if (homeError) {
@@ -64,8 +71,42 @@ function registerReadFileSliceTool(server, workspace) {
64
71
  return executeReadFileSlice(resolved.workspaceRoot, args.path, args.start_line, args.end_line);
65
72
  });
66
73
  }
74
+ function boundedFailure(reason) {
75
+ return formatCompactResult({
76
+ success: false,
77
+ error: {
78
+ code: reason === 'cancelled' ? 'ERR_VERIFICATION_FAILED' : 'ERR_INVALID_SLICE',
79
+ message: 'Bounded source read is unavailable.',
80
+ trigger: 'sdd_read_file_slice',
81
+ details: { reason, nextAction: reason === 'cancelled' ? 'retry_read' : 'inspect_artifacts' },
82
+ },
83
+ });
84
+ }
85
+ async function executeBoundedSlice(workspace, args, codec, signal) {
86
+ const aborted = () => signal.aborted;
87
+ if (aborted()) {
88
+ return boundedFailure('cancelled');
89
+ }
90
+ let resolved;
91
+ try {
92
+ resolved = await workspace.resolve();
93
+ }
94
+ catch {
95
+ return boundedFailure(aborted() ? 'cancelled' : 'slice_unavailable');
96
+ }
97
+ if (aborted()) {
98
+ return boundedFailure('cancelled');
99
+ }
100
+ const homeError = homeFallbackFailure(resolved, 'sdd_read_file_slice');
101
+ if (homeError) {
102
+ return formatCompactResult(homeError);
103
+ }
104
+ const result = await readBoundedSource(resolved.workspaceRoot, args, codec, signal);
105
+ return aborted() ? boundedFailure('cancelled') : formatCompactResult(result);
106
+ }
67
107
  function registerGetActiveTaskTool(server, workspace, taskWindow) {
68
108
  server.registerTool('sdd_get_active_task', {
109
+ annotations: TOOL_ANNOTATIONS.sdd_get_active_task,
69
110
  description: 'Returns only the active task. For fast resumption use view="resume"; use "relock_history" with history_cursor for older lock references, or "verification_preflight" to inspect evidence. Compact views are read-only and do not certify work.',
70
111
  inputSchema: GetActiveTaskInputSchema.shape,
71
112
  }, async (rawArgs, extra) => {
@@ -101,55 +142,9 @@ function registerGetActiveTaskTool(server, workspace, taskWindow) {
101
142
  return formatResult(result);
102
143
  });
103
144
  }
104
- async function getReceiptActiveTask(feature, previousTaskMarkdown, workspaceRoot, signal) {
105
- const trigger = 'sdd_get_active_task';
106
- try {
107
- const root = await captureVerificationRoot(workspaceRoot);
108
- const snapshot = await captureCompletionSnapshot(feature, {
109
- workspaceRoot: root.canonical,
110
- });
111
- const current = activeTaskFromContent(snapshot.tasksContent, verificationCommand);
112
- const active = current.success ? current.data.activeTask : null;
113
- if (!current.success || active?.fullTaskMarkdown !== previousTaskMarkdown) {
114
- return completionFailure('contract_drift', undefined, trigger);
115
- }
116
- const data = current.data;
117
- const policy = parseVerificationReceiptPolicy(path.basename(snapshot.featDir), snapshot.planContent, snapshot.tasksContent);
118
- const task = policy.status === 'ready' ? policy.tasks.get(active.taskId) : undefined;
119
- if (policy.status !== 'ready' || !task) {
120
- return completionFailure('contract_drift', undefined, trigger);
121
- }
122
- const captured = await captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal);
123
- if (captured.success) {
124
- await revalidateVerificationInputs(captured.data.inputs, signal);
125
- }
126
- await revalidateCompletionSnapshot(snapshot);
127
- const guard = await inspectCompletionGuard(feature);
128
- if (guard) {
129
- return completionFailure(guard.reason, undefined, trigger);
130
- }
131
- if (!captured.success) {
132
- return { ...captured, error: { ...captured.error, trigger } };
133
- }
134
- const manifest = [...parseManifestContent(snapshot.planContent).allowedFiles.entries()].map(([filePath, permission]) => ({ path: filePath, permission }));
135
- return {
136
- success: true,
137
- data: {
138
- ...data,
139
- activeTask: { ...active, verificationCommand: task.command },
140
- locked: true,
141
- trinity: 'ready',
142
- manifest,
143
- verificationEvidence: captured.data.evidence,
144
- },
145
- };
146
- }
147
- catch (error) {
148
- return completionError(error, trigger);
149
- }
150
- }
151
145
  function registerApplyPatchTool(server, workspace) {
152
146
  server.registerTool('sdd_apply_file_patch', {
147
+ annotations: TOOL_ANNOTATIONS.sdd_apply_file_patch,
153
148
  description: 'Applies CREATE and MODIFY patches, or exact DELETE operations, strictly authorized in plan.md File Manifest. DELETE requires empty search_content and replace_content.',
154
149
  inputSchema: ApplyFilePatchInputSchema.shape,
155
150
  }, async (rawArgs) => {
@@ -164,6 +159,7 @@ function registerApplyPatchTool(server, workspace) {
164
159
  }
165
160
  function registerCompleteTaskTool(server, workspace, taskWindow) {
166
161
  server.registerTool('sdd_complete_task', {
162
+ annotations: TOOL_ANNOTATIONS.sdd_complete_task,
167
163
  description: 'Completes the active task by running its Verification command in the workspace and storing that output. verification_output is accepted and ignored.',
168
164
  inputSchema: CompleteTaskInputSchema.shape,
169
165
  }, async (rawArgs, extra) => {
@@ -178,16 +174,20 @@ function registerCompleteTaskTool(server, workspace, taskWindow) {
178
174
  return formatResult(result);
179
175
  });
180
176
  }
177
+ function invalidLineRange(startLine, endLine, totalLines) {
178
+ return formatResult({
179
+ success: false,
180
+ error: {
181
+ code: 'ERR_INVALID_SLICE',
182
+ message: `Invalid line range: ${startLine} to ${endLine}.`,
183
+ trigger: 'sdd_read_file_slice',
184
+ ...(totalLines === undefined ? {} : { details: { totalLines } }),
185
+ },
186
+ });
187
+ }
181
188
  async function executeReadFileSlice(workspaceRoot, relPath, startLine, endLine) {
182
189
  if (startLine > endLine || startLine < 1) {
183
- return formatResult({
184
- success: false,
185
- error: {
186
- code: 'ERR_INVALID_SLICE',
187
- message: `Invalid line range: ${startLine} to ${endLine}.`,
188
- trigger: 'sdd_read_file_slice',
189
- },
190
- });
190
+ return invalidLineRange(startLine, endLine);
191
191
  }
192
192
  const read = await readTextInsideWorkspace(workspaceRoot, path.resolve(workspaceRoot, path.normalize(relPath)));
193
193
  if (!read.ok) {
@@ -204,26 +204,10 @@ async function executeReadFileSlice(workspaceRoot, relPath, startLine, endLine)
204
204
  }
205
205
  const sliced = sliceNumberedSource(read.text, startLine, endLine);
206
206
  if (!sliced.ok) {
207
- return formatResult({
208
- success: false,
209
- error: {
210
- code: 'ERR_INVALID_SLICE',
211
- message: `Invalid line range: ${startLine} to ${endLine}.`,
212
- trigger: 'sdd_read_file_slice',
213
- details: { totalLines: sliced.totalLines },
214
- },
215
- });
207
+ return invalidLineRange(startLine, endLine, sliced.totalLines);
216
208
  }
217
- return formatResult({
218
- success: true,
219
- data: {
220
- totalLines: sliced.totalLines,
221
- startLine: sliced.startLine,
222
- endLine: sliced.endLine,
223
- truncated: sliced.truncated,
224
- text: sliced.text,
225
- },
226
- });
209
+ const { ok: _ok, ...data } = sliced;
210
+ return formatResult({ success: true, data });
227
211
  }
228
212
  async function executeApplyPatch(workspaceRoot, args) {
229
213
  try {
@@ -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,9 +1,10 @@
1
+ import { homeFallbackFailure, ReadCursorCodec } from '../workspace-root.js';
2
+ import { TOOL_ANNOTATIONS } from '../canonical-tools.js';
1
3
  import * as fs from 'node:fs/promises';
2
4
  import * as path from 'node:path';
3
5
  import * as contracts from '../contracts.js';
4
6
  import { TaskWindowManager } from '../task-window.js';
5
7
  import * as compact from './compact-result.js';
6
- import { homeFallbackFailure } from '../workspace-root.js';
7
8
  import { prepareProjectInitialization } from '../workspace-init.js';
8
9
  import { readTrinityFailureIssues, writeLockedTrinity } from '../lock-integrity.js';
9
10
  import { CompletionGuardError } from '../feature-authority.js';
@@ -40,7 +41,7 @@ async function composeWorkspaceHint(workspaceRoot, extra, suppliedPack) {
40
41
  }
41
42
  return bounded;
42
43
  }
43
- export function registerWorkspaceTools(server, workspace, bundledVersion) {
44
+ export function registerWorkspaceTools(server, workspace, bundledVersion, _codec = new ReadCursorCodec()) {
44
45
  const taskWindow = new TaskWindowManager();
45
46
  registerInitTool(server, workspace);
46
47
  registerListTool(server, workspace, taskWindow, bundledVersion);
@@ -49,6 +50,7 @@ export function registerWorkspaceTools(server, workspace, bundledVersion) {
49
50
  }
50
51
  function registerInitTool(server, workspace) {
51
52
  server.registerTool('sdd_init_workspace', {
53
+ annotations: TOOL_ANNOTATIONS.sdd_init_workspace,
52
54
  description: 'Initializes the SDD workspace creating .sdd/ directory and decoupled skills.',
53
55
  inputSchema: contracts.InitWorkspaceInputSchema.shape,
54
56
  }, async (rawArgs) => {
@@ -106,22 +108,9 @@ function listFailure(reason) {
106
108
  }
107
109
  return compact.formatCompactResult(failure);
108
110
  }
109
- async function setupDiagnosticResult(server, workspace, version, args) {
110
- try {
111
- const resolved = await workspace.resolve();
112
- const homeError = homeFallbackFailure(resolved, 'sdd_list_features');
113
- if (homeError) {
114
- return compact.formatCompactResult(homeError);
115
- }
116
- const setupDiagnostics = await hostPack.inspectSetupDiagnostics(resolved.workspaceRoot, version ?? 'unknown', (args.host ?? 'all'), server.server.getClientVersion());
117
- return compact.formatCompactResult({ success: true, data: { setupDiagnostics } });
118
- }
119
- catch {
120
- return listFailure('artifact_unavailable');
121
- }
122
- }
123
111
  function registerListTool(server, workspace, taskWindow, bundledVersion) {
124
112
  server.registerTool('sdd_list_features', {
113
+ annotations: TOOL_ANNOTATIONS.sdd_list_features,
125
114
  description: 'Lists executable Planu v8 FEAT-* features from .sdd/features only.',
126
115
  inputSchema: contracts.ListFeaturesInputSchema,
127
116
  }, async (rawArgs) => {
@@ -129,9 +118,8 @@ function registerListTool(server, workspace, taskWindow, bundledVersion) {
129
118
  if (!parsed.success) {
130
119
  return listFailure('compact_input_invalid');
131
120
  }
132
- const args = parsed.data;
133
- if (args.view !== undefined || args.host !== undefined) {
134
- return setupDiagnosticResult(server, workspace, bundledVersion, args);
121
+ if (parsed.data.view !== undefined || parsed.data.host !== undefined) {
122
+ return hostPack.setupDiagnosticResult(server, workspace, bundledVersion, parsed.data);
135
123
  }
136
124
  const resolved = await workspace.resolve();
137
125
  const homeError = homeFallbackFailure(resolved, 'sdd_list_features');
@@ -143,7 +131,7 @@ function registerListTool(server, workspace, taskWindow, bundledVersion) {
143
131
  if (safety) {
144
132
  return compact.formatResult(safety);
145
133
  }
146
- const collected = await collectFeatures(featuresDir, taskWindow, args.status_filter);
134
+ const collected = await collectFeatures(featuresDir, taskWindow, parsed.data.status_filter);
147
135
  if (!collected.success) {
148
136
  return compact.formatResult(collected);
149
137
  }
@@ -166,6 +154,7 @@ function registerListTool(server, workspace, taskWindow, bundledVersion) {
166
154
  }
167
155
  function registerCreateTool(server, workspace) {
168
156
  server.registerTool('sdd_create_feature', {
157
+ annotations: TOOL_ANNOTATIONS.sdd_create_feature,
169
158
  description: 'Creates a Holy Trinity feature. Omit id to atomically reserve the next global FEAT-NNNN-TITLE identifier; explicit FEAT-* IDs remain supported.',
170
159
  inputSchema: contracts.CreateFeatureInputSchema.shape,
171
160
  }, async (rawArgs) => {
@@ -223,6 +212,7 @@ function registerCreateTool(server, workspace) {
223
212
  }
224
213
  function registerLockTool(server, workspace) {
225
214
  server.registerTool('sdd_lock_spec', {
215
+ annotations: TOOL_ANNOTATIONS.sdd_lock_spec,
226
216
  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.',
227
217
  inputSchema: contracts.LockSpecInputSchema,
228
218
  }, async (rawArgs, extra) => {
@@ -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
- registerWorkspaceTools(server, workspace, bundledVersion);
9
- return registerExecutionTools(server, workspace, policy);
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