@planu/cli 8.7.0 → 8.7.1

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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## [8.7.1]
2
+
3
+ - Reject hardlinked or nonregular effective MODIFY targets and invalid UTF-8 before mutation; enforce ownership where supported and preserve safe internal symlinks.
4
+ - Recheck identity and path bindings before write admission. Write failures may leave partial changes; this is not atomic rollback or a complete same-user filesystem boundary.
5
+ - Preserve the nine tools and input schemas, existing dependencies and package surface.
6
+
1
7
  ## [8.7.0]
2
8
 
3
9
  - Expose advisory `budget.version=1` observations in preflight and resume; completion revalidates authority and consumes a matching grant before spawning.
package/README.md CHANGED
@@ -149,7 +149,7 @@ The existing nine tools expose additive diagnostics since 8.4.0; 8.5.0 adds comp
149
149
  ```json
150
150
  {
151
151
  "version": 1,
152
- "bundledVersion": "8.7.0",
152
+ "bundledVersion": "8.7.1",
153
153
  "baseline": "available",
154
154
  "catalog": "unverified",
155
155
  "issues": [{
@@ -301,6 +301,8 @@ sdd_init_workspace → sdd_create_feature → architect trinity → sdd_lock_spe
301
301
  5. **Verify:** independently prove acceptance criteria with `verification-auditor.md`.
302
302
  6. **Janitor:** prune local branches and orphaned worktrees only with authorization.
303
303
 
304
+ Effective MODIFY (including CREATE with a nonempty search) requires a regular single-link UTF-8 target and checks ownership where supported; safe internal symlinks remain usable. Identity and path checks reject detected changes before write admission. A write failure may leave partial changes: inspect the file before retrying. These checks do not provide atomic rollback or a complete boundary against a hostile process running as the same user.
305
+
304
306
  `sdd_list_features` enumerates executable `.sdd/features/FEAT-*` records only. Historical v6 records are not executed, enumerated, generated, or shipped by the v8 runtime.
305
307
 
306
308
  ### Canonical tools
@@ -378,7 +380,7 @@ See the [Planu Proprietary Free-Use License](LICENSE) and [planu.dev/license](ht
378
380
  "mcpServers": {
379
381
  "planu": {
380
382
  "command": "npx",
381
- "args": ["-y", "@planu/cli@8.7.0"],
383
+ "args": ["-y", "@planu/cli@8.7.1"],
382
384
  "cwd": ".",
383
385
  "env": {
384
386
  "PLANU_WORKSPACE": "."
@@ -31,6 +31,8 @@ For setup diagnostics and execution window, detail and evidence history views, l
31
31
 
32
32
  Before attempting completion, request a fresh explicit \`verification_preflight\` or \`resume\` and require \`budget.version=1\`; absence is unavailable, never a grant. An older producer may omit it. The observation is advisory, not a reservation or grant. \`execution_window\` and \`execution_detail\` are not decorated with budget and cannot substitute for that fresh request. When a verification process actually ran, its \`verificationProcess\` reports the effective timeout, outcome and owned process group cleanup; \`fixturePostconditions\` remains \`unknown\`. Group cleanup alone does not prove fixture safety. These diagnostics do not record attempts automatically or authorize policy changes, retries or extra time. Reconcile uncertain state before acting.
33
33
 
34
+ Effective MODIFY (including CREATE with a nonempty search) requires a regular single-link target with strict UTF-8; ownership is checked where the platform provides getuid. Stable safe internal symlinks remain supported. A write, truncate, sync or close failure may leave partial changes; inspect before retrying. Checks do not guarantee protection against a hostile same-UID process inserting a link after the final check.
35
+
34
36
  ## Delegation
35
37
 
36
38
  Delegate useful independent work within the active TASK through available native agents; keep trivial/dependent work sequential. Load the bounded protocol from \`spec-executor.md\` on demand; use \`spec-architect.md\` for workstream routing and \`verification-auditor.md\` for provenance checks. The parent alone applies canonical patches and certifies. Preserve all nine tools, lock, File Manifest, limits and protected-root controls; host capabilities grant no extra authority.
@@ -7,7 +7,6 @@ export declare class PatchSandbox {
7
7
  private validateTargetContainment;
8
8
  private rejectsProtectedRoot;
9
9
  private rejectsResolvedProtectedRoot;
10
- private isRawProtectedDelete;
11
10
  private validateCreateTargetAbsent;
12
11
  private nearestExistingParent;
13
12
  private isWithin;
@@ -17,5 +16,7 @@ export declare class PatchSandbox {
17
16
  private executeCreatePatch;
18
17
  private executeDeletePatch;
19
18
  private executeModifyPatch;
19
+ private isAllowedCanonical;
20
+ private modifyFailure;
20
21
  }
21
22
  //# sourceMappingURL=patch-sandbox.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'node:fs/promises';
2
2
  import * as path from 'node:path';
3
3
  import { parseManifestContent, toPosixPath } from './feature-manifest.js';
4
+ import { CompletionGuardError, readArtifact, rewriteArtifact } from './feature-authority.js';
4
5
  export class PatchSandbox {
5
6
  workspaceRoot;
6
7
  constructor(workspaceRoot) {
@@ -98,7 +99,7 @@ export class PatchSandbox {
98
99
  this.isWithin(legacySpecsRoot, fullPath)) {
99
100
  return true;
100
101
  }
101
- return permission === 'DELETE' && this.isRawProtectedDelete(workspacePath, fullPath);
102
+ return permission === 'DELETE' && fullPath === workspacePath;
102
103
  }
103
104
  async rejectsResolvedProtectedRoot(workspaceRealPath, containmentTarget) {
104
105
  for (const dirName of ['.sdd', '.git', path.join('planu', 'specs')]) {
@@ -109,9 +110,6 @@ export class PatchSandbox {
109
110
  }
110
111
  return false;
111
112
  }
112
- isRawProtectedDelete(workspacePath, fullPath) {
113
- return fullPath === workspacePath;
114
- }
115
113
  async validateCreateTargetAbsent(fullPath, normalizedTarget) {
116
114
  try {
117
115
  await fs.lstat(fullPath);
@@ -147,24 +145,19 @@ export class PatchSandbox {
147
145
  (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)));
148
146
  }
149
147
  permissionViolation(normalizedTarget) {
148
+ const message = `Access outside protected workspace boundaries denied: '${normalizedTarget}'.`;
150
149
  return {
151
150
  success: false,
152
- error: {
153
- code: 'ERR_PERMISSION_VIOLATION',
154
- message: `Access outside protected workspace boundaries denied: '${normalizedTarget}'.`,
155
- trigger: 'sdd_apply_file_patch',
156
- },
151
+ error: { code: 'ERR_PERMISSION_VIOLATION', message, trigger: 'sdd_apply_file_patch' },
157
152
  };
158
153
  }
159
154
  patchFailure(message) {
160
- return {
161
- success: false,
162
- error: {
163
- code: 'ERR_PATCH_FAILED',
164
- message,
165
- trigger: 'sdd_apply_file_patch',
166
- },
155
+ const error = {
156
+ code: 'ERR_PATCH_FAILED',
157
+ message,
158
+ trigger: 'sdd_apply_file_patch',
167
159
  };
160
+ return { success: false, error };
168
161
  }
169
162
  isNodeErrorCode(err, code) {
170
163
  return typeof err === 'object' && err !== null && 'code' in err && err.code === code;
@@ -173,35 +166,16 @@ export class PatchSandbox {
173
166
  try {
174
167
  await fs.mkdir(path.dirname(fullPath), { recursive: true });
175
168
  await fs.writeFile(fullPath, replaceContent, { encoding: 'utf-8', flag: 'wx' });
176
- return {
177
- success: true,
178
- data: {
179
- appliedTo: normalizedTarget,
180
- bytesWritten: Buffer.byteLength(replaceContent, 'utf-8'),
181
- },
182
- };
169
+ const bytesWritten = Buffer.byteLength(replaceContent, 'utf-8');
170
+ return { success: true, data: { appliedTo: normalizedTarget, bytesWritten } };
183
171
  }
184
172
  catch (err) {
185
- return {
186
- success: false,
187
- error: {
188
- code: 'ERR_PATCH_FAILED',
189
- message: `Failed to create file: ${err instanceof Error ? err.message : String(err)}`,
190
- trigger: 'sdd_apply_file_patch',
191
- },
192
- };
173
+ return this.patchFailure(`Failed to create file: ${err instanceof Error ? err.message : String(err)}`);
193
174
  }
194
175
  }
195
176
  async executeDeletePatch(fullPath, normalizedTarget, searchContent, replaceContent) {
196
177
  if (searchContent !== '' || replaceContent !== '') {
197
- return {
198
- success: false,
199
- error: {
200
- code: 'ERR_PATCH_FAILED',
201
- message: `DELETE requires empty search_content and replace_content for '${normalizedTarget}'.`,
202
- trigger: 'sdd_apply_file_patch',
203
- },
204
- };
178
+ return this.patchFailure(`DELETE requires empty search_content and replace_content for '${normalizedTarget}'.`);
205
179
  }
206
180
  try {
207
181
  const stat = await fs.lstat(fullPath);
@@ -212,47 +186,42 @@ export class PatchSandbox {
212
186
  };
213
187
  }
214
188
  catch (err) {
215
- return {
216
- success: false,
217
- error: {
218
- code: 'ERR_PATCH_FAILED',
219
- message: `Failed to delete '${normalizedTarget}': ${err instanceof Error ? err.message : String(err)}`,
220
- trigger: 'sdd_apply_file_patch',
221
- },
222
- };
189
+ return this.patchFailure(`Failed to delete '${normalizedTarget}': ${err instanceof Error ? err.message : String(err)}`);
223
190
  }
224
191
  }
225
192
  async executeModifyPatch(fullPath, normalizedTarget, searchContent, replaceContent) {
226
- let existingContent;
193
+ let writeStarted = false;
194
+ let canonicalResolved = false;
227
195
  try {
228
- existingContent = await fs.readFile(fullPath, 'utf-8');
229
- }
230
- catch (err) {
231
- return {
232
- success: false,
233
- error: {
234
- code: 'ERR_PATCH_FAILED',
235
- message: `Target file to modify does not exist: '${normalizedTarget}'.`,
236
- trigger: 'sdd_apply_file_patch',
237
- details: { error: String(err) },
238
- },
239
- };
240
- }
241
- const matchCount = countOccurrences(existingContent, searchContent);
242
- if (matchCount !== 1) {
243
- return {
244
- success: false,
245
- error: {
246
- code: 'ERR_PATCH_FAILED',
247
- message: `MODIFY search_content must occur exactly once in '${normalizedTarget}'.`,
248
- trigger: 'sdd_apply_file_patch',
249
- details: { matchCount, requestedPath: normalizedTarget },
250
- },
251
- };
252
- }
253
- const updatedContent = existingContent.replace(searchContent, () => replaceContent);
254
- try {
255
- await fs.writeFile(fullPath, updatedContent, 'utf-8');
196
+ const canonical = await fs.realpath(fullPath);
197
+ canonicalResolved = true;
198
+ if (!(await this.isAllowedCanonical(canonical))) {
199
+ return this.permissionViolation(normalizedTarget);
200
+ }
201
+ const directory = path.dirname(canonical);
202
+ const name = path.basename(canonical);
203
+ const artifact = await readArtifact(directory, name);
204
+ const matchCount = countOccurrences(artifact.content, searchContent);
205
+ if (matchCount !== 1) {
206
+ return {
207
+ success: false,
208
+ error: {
209
+ code: 'ERR_PATCH_FAILED',
210
+ message: `MODIFY search_content must occur exactly once in '${normalizedTarget}'.`,
211
+ trigger: 'sdd_apply_file_patch',
212
+ details: { matchCount, requestedPath: normalizedTarget },
213
+ },
214
+ };
215
+ }
216
+ const updatedContent = artifact.content.replace(searchContent, () => replaceContent);
217
+ await rewriteArtifact(directory, name, artifact, updatedContent, () => {
218
+ writeStarted = true;
219
+ }, async () => {
220
+ const denial = await this.validateTargetContainment(fullPath, normalizedTarget, 'MODIFY');
221
+ if (denial || (await fs.realpath(fullPath).catch(() => null)) !== canonical) {
222
+ throw new CompletionGuardError('contract_drift', 'Target binding changed.');
223
+ }
224
+ });
256
225
  return {
257
226
  success: true,
258
227
  data: {
@@ -262,16 +231,27 @@ export class PatchSandbox {
262
231
  };
263
232
  }
264
233
  catch (err) {
265
- return {
266
- success: false,
267
- error: {
268
- code: 'ERR_PATCH_FAILED',
269
- message: `Failed to write changes: ${err instanceof Error ? err.message : String(err)}`,
270
- trigger: 'sdd_apply_file_patch',
271
- },
272
- };
234
+ return this.modifyFailure(err, normalizedTarget, writeStarted, canonicalResolved);
273
235
  }
274
236
  }
237
+ async isAllowedCanonical(canonical) {
238
+ const workspaceReal = await fs.realpath(this.workspaceRoot);
239
+ return (this.isWithin(workspaceReal, canonical) &&
240
+ !(await this.rejectsResolvedProtectedRoot(workspaceReal, canonical)));
241
+ }
242
+ modifyFailure(err, normalizedTarget, writeStarted, canonicalResolved) {
243
+ if (!writeStarted &&
244
+ ((err instanceof CompletionGuardError && err.code !== 'ERR_INVALID_ARTIFACT') ||
245
+ this.isNodeErrorCode(err, 'EACCES') ||
246
+ this.isNodeErrorCode(err, 'EPERM') ||
247
+ (canonicalResolved &&
248
+ (this.isNodeErrorCode(err, 'ENOENT') || this.isNodeErrorCode(err, 'ELOOP'))))) {
249
+ return this.permissionViolation(normalizedTarget);
250
+ }
251
+ return this.patchFailure(writeStarted
252
+ ? 'Failed to write changes; the target may be partially modified.'
253
+ : 'Failed to read or write the target file.');
254
+ }
275
255
  }
276
256
  function resolveManifestPermission(allowedFiles, normalizedTarget) {
277
257
  const exact = allowedFiles.get(normalizedTarget);
@@ -308,18 +288,12 @@ function isProtectedPrefix(relativePath, root) {
308
288
  return posix === root || posix.startsWith(`${root}/`);
309
289
  }
310
290
  function countOccurrences(haystack, needle) {
311
- if (needle.length === 0) {
291
+ if (!needle) {
312
292
  return 0;
313
293
  }
314
294
  let count = 0;
315
- let from = 0;
316
- while (from <= haystack.length) {
317
- const at = haystack.indexOf(needle, from);
318
- if (at < 0) {
319
- return count;
320
- }
321
- count += 1;
322
- from = at + needle.length;
295
+ for (let at = haystack.indexOf(needle); at !== -1; at = haystack.indexOf(needle, at + needle.length)) {
296
+ count++;
323
297
  }
324
298
  return count;
325
299
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planu/cli",
3
- "version": "8.7.0",
3
+ "version": "8.7.1",
4
4
  "description": "Planu — MCP server for Spec Driven Development. Planning and file operations on macOS/Linux/Windows; automated verification requires macOS/Linux (POSIX).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,6 +23,8 @@ For supported connections, inspect `sdd_list_features` with `view="setup_diagnos
23
23
 
24
24
  Before attempting completion, request a fresh explicit `verification_preflight` or `resume` and require `budget.version=1`; absence is unavailable, never a grant. An older producer may omit it. The observation is advisory, not a reservation or grant. `execution_window` and `execution_detail` are not decorated with budget and cannot substitute for that fresh request. When a verification process actually ran, its `verificationProcess` reports the effective timeout, outcome and owned process group cleanup; `fixturePostconditions` remains `unknown`. Group cleanup alone does not prove fixture safety. These diagnostics do not record attempts automatically or authorize policy changes, retries or extra time. Reconcile uncertain state before acting.
25
25
 
26
+ Effective MODIFY (including CREATE with a nonempty search) requires a regular single-link target with strict UTF-8; ownership is checked where the platform provides getuid. Stable safe internal symlinks remain supported. A write, truncate, sync or close failure may leave partial changes; inspect before retrying. Checks do not guarantee protection against a hostile same-UID process inserting a link after the final check.
27
+
26
28
  ## Delegation
27
29
 
28
30
  Delegate useful independent work within the active TASK through available native agents; keep trivial/dependent work sequential. Load the bounded protocol from `spec-executor.md` on demand; use `spec-architect.md` for workstream routing and `verification-auditor.md` for provenance checks. The parent alone applies canonical patches and certifies. Preserve all nine tools, lock, File Manifest, limits and protected-root controls; host capabilities grant no extra authority.
@@ -22,6 +22,8 @@ For supported connections, inspect `sdd_list_features` with `view="setup_diagnos
22
22
 
23
23
  Before attempting completion, request a fresh explicit `verification_preflight` or `resume` and require `budget.version=1`; absence is unavailable, never a grant. An older producer may omit it. The observation is advisory, not a reservation or grant. `execution_window` and `execution_detail` are not decorated with budget and cannot substitute for that fresh request. When a verification process actually ran, its `verificationProcess` reports the effective timeout, outcome and owned process group cleanup; `fixturePostconditions` remains `unknown`. Group cleanup alone does not prove fixture safety. These diagnostics do not record attempts automatically or authorize policy changes, retries or extra time. Reconcile uncertain state before acting.
24
24
 
25
+ Effective MODIFY (including CREATE with a nonempty search) requires a regular single-link target with strict UTF-8; ownership is checked where the platform provides getuid. Stable safe internal symlinks remain supported. A write, truncate, sync or close failure may leave partial changes; inspect before retrying. Checks do not guarantee protection against a hostile same-UID process inserting a link after the final check.
26
+
25
27
  ## Delegation
26
28
 
27
29
  Delegate useful independent work within the active TASK through available native agents; keep trivial/dependent work sequential. Load the bounded protocol from `spec-executor.md` on demand; use `spec-architect.md` for workstream routing and `verification-auditor.md` for provenance checks. The parent alone applies canonical patches and certifies. Preserve all nine tools, lock, File Manifest, limits and protected-root controls; host capabilities grant no extra authority.