dsh-extra-paths 0.0.0-stage → 0.1.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/README.md +79 -2
- package/cordis.patch.yml +6 -0
- package/lib/argv.js +45 -0
- package/lib/argv.js.map +1 -0
- package/lib/client.js +905 -0
- package/lib/config.js +123 -0
- package/lib/config.js.map +1 -0
- package/lib/context.js +30 -0
- package/lib/context.js.map +1 -0
- package/lib/grant.js +21 -0
- package/lib/grant.js.map +1 -0
- package/lib/index.js +173 -0
- package/lib/index.js.map +1 -0
- package/lib/listener.js +57 -0
- package/lib/listener.js.map +1 -0
- package/lib/paths.js +70 -0
- package/lib/paths.js.map +1 -0
- package/lib/pattern.js +206 -0
- package/lib/pattern.js.map +1 -0
- package/lib/policy.js +17 -0
- package/lib/policy.js.map +1 -0
- package/lib/preview.js +126 -0
- package/lib/preview.js.map +1 -0
- package/lib/resolve.js +153 -0
- package/lib/resolve.js.map +1 -0
- package/lib/schema.js +54 -0
- package/lib/schema.js.map +1 -0
- package/lib/types/argv.d.ts +17 -0
- package/lib/types/config.d.ts +55 -0
- package/lib/types/context.d.ts +13 -0
- package/lib/types/grant.d.ts +17 -0
- package/lib/types/index.d.ts +86 -0
- package/lib/types/listener.d.ts +40 -0
- package/lib/types/paths.d.ts +32 -0
- package/lib/types/pattern.d.ts +88 -0
- package/lib/types/policy.d.ts +21 -0
- package/lib/types/preview.d.ts +77 -0
- package/lib/types/resolve.d.ts +63 -0
- package/lib/types/schema.d.ts +42 -0
- package/lib/types/wrap-fs.d.ts +50 -0
- package/lib/types/wrap-sandbox.d.ts +60 -0
- package/lib/wrap-fs.js +75 -0
- package/lib/wrap-fs.js.map +1 -0
- package/lib/wrap-sandbox.js +89 -0
- package/lib/wrap-sandbox.js.map +1 -0
- package/package.json +113 -4
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-extra-paths
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
让 DSH 对一组配置的外部路径**首次尝试即可写、无需审批**:既覆盖 `write`/`edit` 工具,也覆盖 `bash` 子进程。
|
|
4
|
+
插件以服务包装实现,不改 DSH 核心代码,并提供 Web 设置页与「当前工作区解析出的生效根」预览。
|
|
5
|
+
|
|
6
|
+
## 安装
|
|
7
|
+
|
|
8
|
+
需要 DSH `0.1.5` / `0.2.0` / `0.2.1`(不在范围内会被安装闸门拒绝)。
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm install && pnpm build
|
|
12
|
+
dsh plugin --profile <name> add /path/to/dsh-extra-paths # <name>=你的 profile 名;路径=本仓库的绝对路径
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
装好后打开 **设置 → 插件** 里的「Extra paths」卡片,或设置左栏的「额外可写路径」。
|
|
16
|
+
|
|
17
|
+
## 配置
|
|
18
|
+
|
|
19
|
+
写进设置文档 `~/.dsh/settings.yaml` 的 `extra-paths` 段,或直接用设置页(**保存即生效,无需重启**)。
|
|
20
|
+
下面的 `<工作根>` 是占位符,指你放项目的那个上层目录(绝对路径,或 `~/` 开头的路径):
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
extra-paths:
|
|
24
|
+
paths:
|
|
25
|
+
- <工作根>/notes/home # 用默认 scope/surfaces
|
|
26
|
+
- path: ../../notes/home # 相对路径按「会话工作区」解析
|
|
27
|
+
scope: always-write
|
|
28
|
+
- path: <工作根>/some-repo
|
|
29
|
+
scope: write
|
|
30
|
+
surfaces: [fs] # 只允许 write/edit 工具写
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
| scope | 会话 read-only | 会话 workspace-write |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `write`(默认) | 拒绝 | 可写 |
|
|
36
|
+
| `always-write` | 可写 | 可写 |
|
|
37
|
+
|
|
38
|
+
`surfaces`:`fs` = `write`/`edit`/str-replace 工具;`shell` = `bash` 子进程。读与执行本来就不受沙箱限制。
|
|
39
|
+
|
|
40
|
+
### 相对路径怎么写
|
|
41
|
+
|
|
42
|
+
相对路径按**各会话自己的工作区**解析(设置页里可以改「基准工作区」来预览):
|
|
43
|
+
|
|
44
|
+
| 写法 | 解析成 | 说明 |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `..` | `<工作根>` | 工作区的**上一层**,该目录及其所有兄弟目录都可写 |
|
|
47
|
+
| `../某仓库` | `<工作根>/某仓库` | 只放行那一个兄弟仓库(比 `..` 精确,推荐) |
|
|
48
|
+
| `../../notes/home` | `<工作根>/notes/home` | 往上几层再进别的树 |
|
|
49
|
+
| `~/notes/home` | 家目录下 | 与工作区无关;`~user` 不展开(与宿主一致) |
|
|
50
|
+
|
|
51
|
+
### 模式:按目录结构锚定(不用写死路径)
|
|
52
|
+
|
|
53
|
+
`path` 里可以用通配符描述**一组目录**,于是"路径里存在某个目录"可以变成一个条件:
|
|
54
|
+
|
|
55
|
+
| 写法 | 命中(授予的根) |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `<工作根>/**/.worktrees/..` | 每个**含 `.worktrees` 的仓库根**(`.worktrees` 的上级) |
|
|
58
|
+
| `<工作根>/**/.worktrees/*` | 每个具体 worktree(不碰 `.git` 与主检出) |
|
|
59
|
+
| `<工作根>/<某仓库>/.worktrees/*` | 某一个仓库下所有 worktree(**零遍历开销**,最推荐) |
|
|
60
|
+
| `<工作根>/*/notes` | 每个仓库/项目下的 `notes` 目录 |
|
|
61
|
+
|
|
62
|
+
语法:`*` = 恰好一层、`**` = 最多 3 层(**只匹配真实存在的目录**,所以"必须存在 `.worktrees`"是自然结果);
|
|
63
|
+
结尾的 `..` 在**命中之后**再上移(因此 `…/.worktrees/..` 就是"`.worktrees` 的上级",不会被词法折叠吃掉)。
|
|
64
|
+
|
|
65
|
+
安全边界(都是硬约束,不是建议):
|
|
66
|
+
|
|
67
|
+
- 通配符前必须有**字面量锚点**,且锚点至少两层、必须是绝对路径或 `~/` 开头 —— `/**`、`~/**`、`/srv/**` 一律拒绝
|
|
68
|
+
- 遍历**不进入** `node_modules`、`.git`,`**` 也不进入隐藏目录(`.worktrees` 本身是字面量,仍在当层匹配)
|
|
69
|
+
- 有界:`**` 最多 3 层、目录数 > 4096 或命中 > 256 时**整个模式不生效**(fail closed,绝不给"部分命中"这种不可预期的授权);触顶原因会写进告警
|
|
70
|
+
- 展开结果缓存 30 秒,因此**新建的 worktree 最迟 30 秒**被纳入
|
|
71
|
+
|
|
72
|
+
设置页每行会**实时显示解析到的绝对路径**(符号链接以宿主的「解析预览」为准),模式行显示命中条数 `[生效 ×N]`
|
|
73
|
+
并列出每个具体根;0 命中或被拦截都会明确说明,所以不必"先保存再看解析对不对"。
|
|
74
|
+
|
|
75
|
+
## 已知边界
|
|
76
|
+
|
|
77
|
+
- 逐路径的"完全不受限"做不到:bash 沙箱是整次调用粒度。
|
|
78
|
+
- 相对路径按会话工作区解析,因此同一份配置在不同工作区指向不同目录——设置页的预览会显示实际解析结果。
|
|
79
|
+
- Windows 的 shell 侧不放行;`always-write` 会削弱 `read-only` 急停按钮对该路径的作用。
|
|
80
|
+
- 写在工作区外的文件不会出现在 `deliverables` 的工作区变更卡片里。
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# dsh-extra-paths bundle patch: ONE inserted row over the profile root, nothing
|
|
2
|
+
# disabled. Later layers (the user's profile cordis.patch.yml) may address this
|
|
3
|
+
# row by id; the plugin's own settings live in the dsh settings document.
|
|
4
|
+
- insert:
|
|
5
|
+
- id: extra-paths
|
|
6
|
+
name: 'dsh-extra-paths'
|
package/lib/argv.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner-dialect widening: append one write grant per configured root to an
|
|
3
|
+
* argv the base provider already wrapped. Detection is structural (flags, not
|
|
4
|
+
* program names) and every unrecognised shape fails closed by returning
|
|
5
|
+
* `undefined` — the caller then leaves the argv untouched, so the write is
|
|
6
|
+
* denied rather than silently mis-granted.
|
|
7
|
+
* @module dsh-extra-paths/argv
|
|
8
|
+
*/
|
|
9
|
+
/** Quote one path as an SBPL string literal. */
|
|
10
|
+
function sbplString(path) {
|
|
11
|
+
return `"${path.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Insert write grants for `roots` into a confined argv.
|
|
15
|
+
* @param confined - the argv the base provider produced (runner, profile, `--`, command).
|
|
16
|
+
* @param wrappedLength - length of the caller's original argv, which locates the separator.
|
|
17
|
+
* @param roots - canonical roots to grant.
|
|
18
|
+
* @returns the widened argv, the unchanged argv when there is nothing to grant,
|
|
19
|
+
* or `undefined` when the dialect is unrecognised (the caller must not grant).
|
|
20
|
+
*/
|
|
21
|
+
export function widenArgv(confined, wrappedLength, roots) {
|
|
22
|
+
if (roots.length === 0)
|
|
23
|
+
return confined;
|
|
24
|
+
const separatorIndex = confined.length - wrappedLength - 1;
|
|
25
|
+
if (separatorIndex <= 0 || confined[separatorIndex] !== '--')
|
|
26
|
+
return undefined;
|
|
27
|
+
const head = confined.slice(0, separatorIndex);
|
|
28
|
+
const tail = confined.slice(separatorIndex);
|
|
29
|
+
// Seatbelt: sandbox-exec -p <profile> -- <argv>
|
|
30
|
+
if (head[1] === '-p' && head[2]?.startsWith('(version 1)') === true) {
|
|
31
|
+
const extra = roots.map(root => ` (allow file-write* (subpath ${sbplString(root)}))`).join('');
|
|
32
|
+
return [...head.slice(0, 2), `${head[2]}${extra}`, ...head.slice(3), ...tail];
|
|
33
|
+
}
|
|
34
|
+
// bwrap: --ro-bind / / ... (a writable bind per root)
|
|
35
|
+
if (head.includes('--ro-bind')) {
|
|
36
|
+
return [...head, ...roots.flatMap(root => ['--bind', root, root]), ...tail];
|
|
37
|
+
}
|
|
38
|
+
// Landlock launcher: --ro <path> / --rw <path> grants
|
|
39
|
+
if (head.includes('--ro') || head.includes('--rw')) {
|
|
40
|
+
return [...head, ...roots.flatMap(root => ['--rw', root]), ...tail];
|
|
41
|
+
}
|
|
42
|
+
// windows-acl and any future runner: not expressible here.
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=argv.js.map
|
package/lib/argv.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argv.js","sourceRoot":"","sources":["../src/argv.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,gDAAgD;AAChD,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAA;AACpE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACvB,QAA2B,EAC3B,aAAqB,EACrB,KAAwB;IAExB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAA;IACvC,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,GAAG,aAAa,GAAG,CAAC,CAAA;IAC1D,IAAI,cAAc,IAAI,CAAC,IAAI,QAAQ,CAAC,cAAc,CAAC,KAAK,IAAI;QAAE,OAAO,SAAS,CAAA;IAC9E,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAA;IAC9C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IAE3C,gDAAgD;IAChD,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,KAAK,IAAI,EAAE,CAAC;QACpE,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,gCAAgC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC9F,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IAC/E,CAAC;IACD,sDAAsD;IACtD,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IAC7E,CAAC;IACD,sDAAsD;IACtD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IACrE,CAAC;IACD,2DAA2D;IAC3D,OAAO,SAAS,CAAA;AAClB,CAAC"}
|