dsh-multi-folder 0.2.2 → 0.2.3

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/docs/design.md CHANGED
@@ -46,9 +46,13 @@ A listener on the `tools/execute` around-dispatch waterfall handles `write`, `ed
46
46
  default pipeline, which raises the canonical abort error.
47
47
  The result carries the same canonical value/content shapes as the shipped tools, so
48
48
  downstream presentation keeps working.
49
- 5. Anything else — unknown tools, paths outside every secondary directory, escalation
50
- arguments (`sandbox_permissions`), missing optional services (`shell`, `jobs`),
51
- or any error — falls through to `next()` and the default pipeline.
49
+ 5. Anything else — unknown tools, paths outside every secondary directory, missing
50
+ optional services (`shell`, `jobs`), or a failure **before** the target is
51
+ resolved into a secondary directory (path resolution, config lookup, service
52
+ lookup) — falls through to `next()` and the default pipeline. An explicit
53
+ escalation request (`sandbox_permissions` carrying a non-empty mode string) also
54
+ belongs to the default pipeline, which owns the approval flow; a `null`/empty
55
+ value is not a request and is intercepted normally.
52
56
 
53
57
  **Why mode parity is free:** the mode field of the standing policy is never touched.
54
58
  The DSH sandbox backends treat the per-call policy as fully specified and fence by its
package/lib/index.js CHANGED
@@ -16,6 +16,13 @@
16
16
  * here with the session's standing sandbox policy re-rooted to that
17
17
  * directory — identical semantics to the primary workspace in every mode
18
18
  * (read-only denies, workspace-write allows, danger-full-access allows).
19
+ * Interception OWNS such a call from the moment its target is resolved
20
+ * inside a secondary directory: an interception failure is reported as the
21
+ * call's own error and NEVER falls through to the default pipeline, which
22
+ * fences every call against the PRIMARY workspace root and would therefore
23
+ * turn any ordinary failure (a missing `old_string`, a locked target, an
24
+ * unreadable file) into the spurious
25
+ * `[sandbox: file access denied under workspace-write mode]` marker.
19
26
  * Interception hydrates the configuration AWAITED (never a fire-and-forget
20
27
  * read) and looks the dirs up by BOTH the policy root and the header cwd
21
28
  * spelling, so a cold first call and a symlinked workspace cannot fall
@@ -544,6 +551,30 @@ export function apply(ctx) {
544
551
  return read.delta + (read.delta.length > 0 && !read.delta.endsWith('\n') ? '\n' : '') + notices.join('\n')
545
552
  }
546
553
 
554
+ /**
555
+ * Model-facing failure for a call the interception OWNS (see the ownership
556
+ * rule below). A claimed call is never handed back to the default pipeline,
557
+ * so its real error reaches the model in the shipped tools' error envelope —
558
+ * `Error: <message>` plus the `FS_*` code — instead of the primary-rooted
559
+ * sandbox denial. A genuine sandbox denial (read-only mode) keeps the standard
560
+ * marker plus the one-shot escalation hint, exactly as the shipped
561
+ * `write`/`edit` tools render it, so the escalation flow is unchanged.
562
+ */
563
+ const ownedFailure = (error, policy) => {
564
+ const code = error && typeof error.code === 'string' && error.code.length > 0 ? error.code : undefined
565
+ const message =
566
+ code === 'FS_SANDBOX_DENIED'
567
+ ? '[sandbox: file access denied under ' + policy.mode + ' mode]\n' +
568
+ '[sandbox: escalation available \u2014 retry this exact operation once with sandbox_permissions ' +
569
+ '(the narrowest wider mode that suffices) + justification; the approval prompt asks the user]'
570
+ : String(error && error.message ? error.message : error)
571
+ return {
572
+ isError: true,
573
+ error: { message, ...(code === undefined ? {} : { info: { code } }) },
574
+ content: [{ type: 'text', text: 'Error: ' + message }],
575
+ }
576
+ }
577
+
547
578
  ctx.on('tools/execute', async (exec, next) => {
548
579
  // Hydration must be AWAITED on the interception path, not fire-and-forget:
549
580
  // a first call that arrives before the config read resolves would see an
@@ -560,12 +591,21 @@ export function apply(ctx) {
560
591
  await loadDirs(headerCwd)
561
592
  }
562
593
  if (!INTERCEPT_TOOLS.has(exec.name)) return next()
594
+ // Non-null once the call's target has been resolved into a configured
595
+ // secondary directory: from that point the interception OWNS the call and a
596
+ // failure must be reported as this call's error, never handed back to the
597
+ // default pipeline (which fences against the PRIMARY workspace root and
598
+ // would answer any failure with the spurious workspace-write denial).
599
+ let owned = null
563
600
  try {
564
601
  const args = exec.arguments
565
602
  const standing = sandboxPolicy.resolve(exec.agent ? { session: exec.agent.session } : {})
566
603
  const primary = standing.workspaceRoot
567
- // An explicit escalation request belongs to the default pipeline.
568
- if (args && args.sandbox_permissions !== undefined) return next()
604
+ // An explicit escalation request belongs to the default pipeline (it owns
605
+ // the approval flow). Only a non-empty mode string is a request: a
606
+ // null/empty value is not, and must not hand a secondary-directory
607
+ // mutation to the primary-rooted pipeline.
608
+ if (args && typeof args.sandbox_permissions === 'string' && args.sandbox_permissions.length > 0) return next()
569
609
  // The policy root is realpath-canonicalized by sandbox-policy while
570
610
  // hydration is keyed by the session cwd as spelled in the header; on a
571
611
  // workspace reached through a symlinked/junctioned ancestor the two
@@ -579,7 +619,20 @@ export function apply(ctx) {
579
619
  if (filePath === null) return next()
580
620
  // Resolve first so `..`, symlinks, and case differences canonicalize
581
621
  // before containment matching (same cwd the shipped tools use).
582
- const target = await fs.resolve(filePath, { cwd: primary })
622
+ let target
623
+ try {
624
+ target = await fs.resolve(filePath, { cwd: primary })
625
+ } catch (error) {
626
+ // An unresolvable ABSOLUTE path that is lexically inside a secondary
627
+ // directory is still this plugin's call to answer: the default pipeline
628
+ // would resolve it against the PRIMARY root and report the sandbox
629
+ // denial, hiding the resolution failure.
630
+ if (dirs !== null && isAbsolute(filePath)) {
631
+ const rawHit = longestRootFirst(dirs).find((d) => pathInside(filePath, d))
632
+ if (rawHit !== undefined) return ownedFailure(error, { ...standing, workspaceRoot: rawHit })
633
+ }
634
+ return next()
635
+ }
583
636
  const abs = fs.processPath(target)
584
637
  // Security boundary: configuration is user-managed. Reject direct
585
638
  // write/edit attempts against the host-owned config file, even before
@@ -601,6 +654,7 @@ export function apply(ctx) {
601
654
  const policy = { ...standing, workspaceRoot: hit }
602
655
 
603
656
  if (exec.name === 'write') {
657
+ owned = { policy }
604
658
  const outcome = await fs.writeText(target, String(args.content), undefined, exec.signal, policy)
605
659
  // Keep the observation layer coherent with the shipped write tool's
606
660
  // contract: a successful create/update is a presence observation.
@@ -628,6 +682,7 @@ export function apply(ctx) {
628
682
  const newString = args && typeof args.new_string === 'string' ? args.new_string : null
629
683
  if (oldString === null || newString === null) return next()
630
684
  const replaceAll = args.replace_all === true
685
+ owned = { policy }
631
686
  const outcome = await fs.editText(
632
687
  target,
633
688
  { oldString, newString, replaceAll },
@@ -684,6 +739,7 @@ export function apply(ctx) {
684
739
  if (exec.signal && exec.signal.aborted) return next()
685
740
  const jobs = ctx.get('jobs')
686
741
  if (jobs === undefined) return next()
742
+ owned = { policy }
687
743
  const jobId = jobs.start({
688
744
  kind: exec.name,
689
745
  label: String(args.command),
@@ -704,6 +760,7 @@ export function apply(ctx) {
704
760
  }
705
761
  }
706
762
 
763
+ owned = { policy }
707
764
  const result = await shell.run(shell.resolve({ ...request, signal: exec.signal }))
708
765
  if (result.aborted) {
709
766
  return {
@@ -744,9 +801,14 @@ export function apply(ctx) {
744
801
  return { isError: false, value, content: [{ type: 'text', text: shellRender(value) }] }
745
802
  }
746
803
  return next()
747
- } catch {
748
- // Any interception failure falls back to the default pipeline.
749
- return next()
804
+ } catch (error) {
805
+ // A failure BEFORE the call was claimed (path resolution, config lookup,
806
+ // shell service lookup) falls back to the default pipeline. A failure
807
+ // AFTER the claim — the mutation or the shell run itself — does not: the
808
+ // default pipeline fences the call against the PRIMARY workspace root, so
809
+ // it could only answer with the spurious workspace-write denial and would
810
+ // hide the real cause (for example a missing `old_string`).
811
+ return owned === null ? next() : ownedFailure(error, owned.policy)
750
812
  }
751
813
  })
752
814
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-multi-folder",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "DeepSeek Harness plugin: secondary working directories for a project. The agent keeps the primary workspace as cwd, gains equal write/exec permissions on configured secondary directories under workspace-write mode, and is notified of configuration changes at the next message boundary. Configurable from the session header AND from the session-creation page (before the first message) through a sessionless multiFolder remote API.",
5
5
  "keywords": [
6
6
  "dsh-plugin",