@planu/cli 8.8.0 → 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.
- package/CHANGELOG.md +7 -0
- package/README.md +7 -3
- package/dist/sdd-engine/canonical-tools.d.ts +26 -0
- package/dist/sdd-engine/canonical-tools.js +31 -1
- package/dist/sdd-engine/client-workspace.d.ts +8 -1
- package/dist/sdd-engine/client-workspace.js +168 -1
- package/dist/sdd-engine/contracts.d.ts +1 -23
- package/dist/sdd-engine/contracts.js +1 -18
- package/dist/sdd-engine/host-rule-pack.js +4 -2
- 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 +332 -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/workspace-tools.d.ts +2 -1
- package/dist/sdd-engine/tools/workspace-tools.js +2 -2
- package/dist/sdd-engine/tools.js +4 -2
- package/dist/sdd-engine/workspace-root.d.ts +33 -7
- package/dist/sdd-engine/workspace-root.js +204 -139
- package/dist/types/completion.d.ts +20 -2
- package/dist/types/resume-views.d.ts +21 -0
- package/dist/types/sdd-engine.d.ts +23 -60
- package/dist/types/verification.d.ts +59 -0
- package/package.json +1 -1
- package/templates/AGENTS.md +2 -0
- package/templates/host/planu-sdd.md +2 -0
- package/templates/skills/preflight-guardian.md +2 -0
- package/templates/skills/spec-executor.md +2 -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
|
-
|
|
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
|
|
@@ -9,15 +9,16 @@ import { parseManifestContent, parseVerificationReceiptPolicy, toPosixPath, } fr
|
|
|
9
9
|
import { getReceiptActiveTask } from '../verification-receipts.js';
|
|
10
10
|
import { captureVerificationRoot, checkReceiptPatchTarget } from '../verification-inputs.js';
|
|
11
11
|
import { patchMutationError } from '../task-failures.js';
|
|
12
|
-
import { formatResult } from './compact-result.js';
|
|
12
|
+
import { formatCompactResult, formatResult } from './compact-result.js';
|
|
13
|
+
import { readBoundedSource } from '../host-skill-reader.js';
|
|
13
14
|
import { acquireCompletionLease } from '../completion-guard.js';
|
|
14
15
|
import { captureCompletionSnapshot, revalidateCompletionSnapshot } from '../completion-snapshot.js';
|
|
15
|
-
import { homeFallbackFailure, readTextInsideWorkspace } from '../workspace-root.js';
|
|
16
|
+
import { homeFallbackFailure, readTextInsideWorkspace, ReadCursorCodec, } from '../workspace-root.js';
|
|
16
17
|
import { guardFailure } from '../feature-authority.js';
|
|
17
|
-
export function registerExecutionTools(server, workspace, policy) {
|
|
18
|
+
export function registerExecutionTools(server, workspace, policy, codec = new ReadCursorCodec()) {
|
|
18
19
|
const taskWindow = new TaskWindowManager(policy);
|
|
19
20
|
registerReadArtifactTool(server, workspace);
|
|
20
|
-
registerReadFileSliceTool(server, workspace);
|
|
21
|
+
registerReadFileSliceTool(server, workspace, codec);
|
|
21
22
|
registerGetActiveTaskTool(server, workspace, taskWindow);
|
|
22
23
|
registerApplyPatchTool(server, workspace);
|
|
23
24
|
registerCompleteTaskTool(server, workspace, taskWindow);
|
|
@@ -52,13 +53,16 @@ function registerReadArtifactTool(server, workspace) {
|
|
|
52
53
|
return { content: [{ type: 'text', text: read.text }] };
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
function registerReadFileSliceTool(server, workspace) {
|
|
56
|
+
function registerReadFileSliceTool(server, workspace, codec) {
|
|
56
57
|
server.registerTool('sdd_read_file_slice', {
|
|
57
58
|
annotations: TOOL_ANNOTATIONS.sdd_read_file_slice,
|
|
58
59
|
description: 'Reads an exact line slice from a target file to optimize token usage.',
|
|
59
60
|
inputSchema: ReadFileSliceInputSchema.shape,
|
|
60
|
-
}, async (rawArgs) => {
|
|
61
|
+
}, async (rawArgs, extra) => {
|
|
61
62
|
const args = ReadFileSliceInputSchema.parse(rawArgs);
|
|
63
|
+
if (args.view !== undefined || args.cursor !== undefined) {
|
|
64
|
+
return executeBoundedSlice(workspace, args, codec, extra.signal);
|
|
65
|
+
}
|
|
62
66
|
const resolved = await workspace.resolve();
|
|
63
67
|
const homeError = homeFallbackFailure(resolved, 'sdd_read_file_slice');
|
|
64
68
|
if (homeError) {
|
|
@@ -67,6 +71,39 @@ function registerReadFileSliceTool(server, workspace) {
|
|
|
67
71
|
return executeReadFileSlice(resolved.workspaceRoot, args.path, args.start_line, args.end_line);
|
|
68
72
|
});
|
|
69
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
|
+
}
|
|
70
107
|
function registerGetActiveTaskTool(server, workspace, taskWindow) {
|
|
71
108
|
server.registerTool('sdd_get_active_task', {
|
|
72
109
|
annotations: TOOL_ANNOTATIONS.sdd_get_active_task,
|
|
@@ -137,16 +174,20 @@ function registerCompleteTaskTool(server, workspace, taskWindow) {
|
|
|
137
174
|
return formatResult(result);
|
|
138
175
|
});
|
|
139
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
|
+
}
|
|
140
188
|
async function executeReadFileSlice(workspaceRoot, relPath, startLine, endLine) {
|
|
141
189
|
if (startLine > endLine || startLine < 1) {
|
|
142
|
-
return
|
|
143
|
-
success: false,
|
|
144
|
-
error: {
|
|
145
|
-
code: 'ERR_INVALID_SLICE',
|
|
146
|
-
message: `Invalid line range: ${startLine} to ${endLine}.`,
|
|
147
|
-
trigger: 'sdd_read_file_slice',
|
|
148
|
-
},
|
|
149
|
-
});
|
|
190
|
+
return invalidLineRange(startLine, endLine);
|
|
150
191
|
}
|
|
151
192
|
const read = await readTextInsideWorkspace(workspaceRoot, path.resolve(workspaceRoot, path.normalize(relPath)));
|
|
152
193
|
if (!read.ok) {
|
|
@@ -163,26 +204,10 @@ async function executeReadFileSlice(workspaceRoot, relPath, startLine, endLine)
|
|
|
163
204
|
}
|
|
164
205
|
const sliced = sliceNumberedSource(read.text, startLine, endLine);
|
|
165
206
|
if (!sliced.ok) {
|
|
166
|
-
return
|
|
167
|
-
success: false,
|
|
168
|
-
error: {
|
|
169
|
-
code: 'ERR_INVALID_SLICE',
|
|
170
|
-
message: `Invalid line range: ${startLine} to ${endLine}.`,
|
|
171
|
-
trigger: 'sdd_read_file_slice',
|
|
172
|
-
details: { totalLines: sliced.totalLines },
|
|
173
|
-
},
|
|
174
|
-
});
|
|
207
|
+
return invalidLineRange(startLine, endLine, sliced.totalLines);
|
|
175
208
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
data: {
|
|
179
|
-
totalLines: sliced.totalLines,
|
|
180
|
-
startLine: sliced.startLine,
|
|
181
|
-
endLine: sliced.endLine,
|
|
182
|
-
truncated: sliced.truncated,
|
|
183
|
-
text: sliced.text,
|
|
184
|
-
},
|
|
185
|
-
});
|
|
209
|
+
const { ok: _ok, ...data } = sliced;
|
|
210
|
+
return formatResult({ success: true, data });
|
|
186
211
|
}
|
|
187
212
|
async function executeApplyPatch(workspaceRoot, args) {
|
|
188
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,10 +1,10 @@
|
|
|
1
|
+
import { homeFallbackFailure, ReadCursorCodec } from '../workspace-root.js';
|
|
1
2
|
import { TOOL_ANNOTATIONS } 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';
|
|
@@ -41,7 +41,7 @@ async function composeWorkspaceHint(workspaceRoot, extra, suppliedPack) {
|
|
|
41
41
|
}
|
|
42
42
|
return bounded;
|
|
43
43
|
}
|
|
44
|
-
export function registerWorkspaceTools(server, workspace, bundledVersion) {
|
|
44
|
+
export function registerWorkspaceTools(server, workspace, bundledVersion, _codec = new ReadCursorCodec()) {
|
|
45
45
|
const taskWindow = new TaskWindowManager();
|
|
46
46
|
registerInitTool(server, workspace);
|
|
47
47
|
registerListTool(server, workspace, taskWindow, bundledVersion);
|
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,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 { 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: SourceCursorPayload): string;
|
|
24
|
+
decode(token: unknown): SourceCursorPayload | 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
|