peaks-loop 4.1.14 → 4.1.16
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +132 -0
- package/dist/cli/commands/code-gate-command.js +26 -7
- package/dist/services/hooks/gate-path-normalize.d.ts +54 -0
- package/dist/services/hooks/gate-path-normalize.js +121 -0
- package/dist/services/hooks/hook-payload-cwd.d.ts +44 -0
- package/dist/services/hooks/hook-payload-cwd.js +97 -0
- package/dist/services/hooks/pre-tool-code-gate.d.ts +19 -28
- package/dist/services/hooks/pre-tool-code-gate.js +44 -54
- package/package.json +5 -5
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"metadata": {
|
|
3
3
|
"pluginRoot": ".",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.16"
|
|
5
5
|
},
|
|
6
6
|
"plugins": [
|
|
7
7
|
{
|
|
8
8
|
"name": "peaks-loop",
|
|
9
9
|
"description": "Loop Engineering CLI — workflow primitive / loop guards / evaluators / slice orchestration",
|
|
10
|
-
"version": "4.1.
|
|
10
|
+
"version": "4.1.16",
|
|
11
11
|
"author": {
|
|
12
12
|
"name": "SquabbyZ"
|
|
13
13
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,137 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.1.16 — 2026-10-22(相对路径按工具调用实际所在的目录解析)
|
|
4
|
+
|
|
5
|
+
**版本级别**:候选 **patch**(沿用常设规则"默认版本新增采用最小的版本位")。本次是**纯修复**:
|
|
6
|
+
既有 CLI 参数、门禁的六个硬阻断族成员、fail-open 策略、auto-compact 三档阈值、
|
|
7
|
+
peaks-code 的 11 步工序与 Gate A–G **一字不改**。
|
|
8
|
+
上一版(4.1.15)在 QA 复核里**诚实记下了一个洞**:工具调用的工作目录不是项目根时,
|
|
9
|
+
相对路径落在 `src/` 里却被放行 —— "判定只由文件落在哪个目录决定"这条不变量**还没有完全成立**。
|
|
10
|
+
**本次把它收口。**
|
|
11
|
+
|
|
12
|
+
### 1. 相对路径的基准:工具调用实际所在的目录
|
|
13
|
+
|
|
14
|
+
- 此前:相对路径按**调用方指定的项目根**解析。于是 cwd 是 `<root>/src`、payload 是
|
|
15
|
+
`deep/x.ts` 时,这个路径其实指向 `<root>/src/deep/x.ts` —— **落在 `src/` 里、应当被拒**,
|
|
16
|
+
而门禁**放行**了。逃逸是**静默**的。
|
|
17
|
+
- 现在:相对路径按**工具调用实际所在的目录**解析。来源有两条,先用前者:
|
|
18
|
+
payload **顶层**的 `cwd`(IDE 给了就用),否则**门禁进程自己的工作目录**。
|
|
19
|
+
**族仍然相对调用方指定的项目根**比;**绝对路径规则不变**;**嵌在 git 仓库里的项目仍然判自己**。
|
|
20
|
+
- **代价(有意接受,写在这里以免看起来像疏漏)**:基准选错会误拒邻近目录的文件。而回退基准是
|
|
21
|
+
门禁进程的 cwd —— 正常调用里 hook 就跑在工具调用的目录上,所以那条回退**就是**工具调用的目录。
|
|
22
|
+
|
|
23
|
+
### 2. 两个逃逸
|
|
24
|
+
|
|
25
|
+
- ⚠️ **`.sh` 兄弟实现的 `./` 剥离**:它把 `.//deep/x.ts` 剥成前导 `/`,于是被当成**绝对路径**、
|
|
26
|
+
**永不相对化** ⇒ 落在所有族之外 ⇒ **放行**。而那个文件在 `<root>/src/deep/x.ts`,**在 `src/` 里**。
|
|
27
|
+
**同一个文件的 10 种拼法里 6 种,两套实现的判决相反** —— 而**两套实现各自的单测都是绿的**。
|
|
28
|
+
现在:"是不是绝对路径"按**未经剥离的原样拼写**判定。
|
|
29
|
+
- ⚠️ **Node 命令信任了一个不是目录的 payload `cwd`**:payload 说了一个不存在、或者不是目录、
|
|
30
|
+
或者相对的地方,路径因此解析到项目之外,"按拼写回退"那条老路又被走到 ⇒ **逃逸重新打开**。
|
|
31
|
+
现在 payload `cwd` **只有**在"**绝对路径 + 存在的目录 + 在指名的项目之内**"三件事同时成立时才被采信;
|
|
32
|
+
否则用**门禁进程自己的工作目录**。⇒ **修复不依赖 payload 的 `cwd` 存在或正确**。
|
|
33
|
+
|
|
34
|
+
### 3. 必须保持的性质(逐条复验)
|
|
35
|
+
|
|
36
|
+
- **fail-open 策略不变**:payload 判不了时**仍然放行**,stderr 上仍留 `PEAKS_CODE_GATE_UNDECIDABLE`。
|
|
37
|
+
- **六个族的成员不变**:`HARD_BLOCKED_PATH_FAMILIES` 与 `ALLOW_LISTED_PATH_PATTERNS` **零行改动**。
|
|
38
|
+
- **fast lane 仍然打开这些族**:租约是 `peaks-race-code` 时,`src/` 的编辑仍然**放行**。
|
|
39
|
+
- **门禁没有被削弱**:本次**多拒**了原先放行的(那正是逃逸),方向是**收紧**而不是放宽。
|
|
40
|
+
|
|
41
|
+
### 4. 留下的东西(写清楚,免得看起来像漏了)
|
|
42
|
+
|
|
43
|
+
- **落在项目之外的相对路径**仍按"拼写相对项目根"读 ⇒ **不会放宽**门禁:它会拒一个拼得像族、
|
|
44
|
+
而文件其实没落在那里的路径 —— **误拒只是碍事,误放才是漏洞**。
|
|
45
|
+
- **一个残留**:payload `cwd` 不可用**且**门禁进程不在工具调用的目录里时,路径会按错误的树解析,
|
|
46
|
+
项目内的文件**可能**被放行。**改动前同样放行**(它按项目根解析)⇒ **残留,不是回归**;
|
|
47
|
+
而门禁本来就不装在那个位置。**这个形状与 §2.13 的根 `dist/` 轴同源**:拿一个不属于自己的基准去解析。
|
|
48
|
+
- **任何 IDE 报的顶层 `cwd` 至今未实测**(PATH 上的 `claude.exe` 是个 546 KB 启动器,没有 payload
|
|
49
|
+
字符串;本机装的 `@anthropic-ai/claude-code` 二进制里读到的 hook-input 形状是**一次 grep 的转述**,
|
|
50
|
+
QA **没能复现**它)⇒ 所以修复**不依赖**它,回退路径自己扛得住。
|
|
51
|
+
|
|
52
|
+
### 5. QA 独立复核
|
|
53
|
+
|
|
54
|
+
**PASS**(8 条验收标准)。两轮 RD、两轮 QA:QA 第一轮 `return-to-rd`,给的两条缺陷都被独立复现过。
|
|
55
|
+
证据:
|
|
56
|
+
|
|
57
|
+
- 与**改动前**的代码逐行对照 **72 组(action + reason):0 处差异**;
|
|
58
|
+
- 两套实现在 **29 种拼法上 29/29 一致**,**65 行族矩阵 65/65 都拒**;
|
|
59
|
+
- **10 种拼法 0 分歧**(改动前 6 种分歧);
|
|
60
|
+
- **六种不可用的 `cwd` + 完全没有 `cwd`:全部拒**。
|
|
61
|
+
|
|
62
|
+
## 4.1.15 — 2026-10-22(门禁剩下的三种写法也不再决定判定)
|
|
63
|
+
|
|
64
|
+
**版本级别**:候选 **patch**(沿用常设规则"默认版本新增采用最小的版本位")。本次是**纯修复**:
|
|
65
|
+
既有 CLI 参数、门禁的六个硬阻断族成员、fail-open 策略、auto-compact 三档阈值、
|
|
66
|
+
peaks-code 的 11 步工序与 Gate A–G **一字不改**。
|
|
67
|
+
上一版(4.1.14)诚实记录为"留待后续决定"的残留写法里,与本切片同类的三条
|
|
68
|
+
(**大小写变体** / **没解析的 `..`** / **项目嵌在 git 仓库里**),本次全部收口。
|
|
69
|
+
|
|
70
|
+
### 1. 族名的大小写:比较时不区分大小写
|
|
71
|
+
|
|
72
|
+
- 六个族名全是小写,而 `SRC/foo.ts` 在**任何大小写不敏感的文件系统上**(Windows、默认的 macOS)
|
|
73
|
+
**就是** `src/foo.ts`。按字面比较,等于**让写法决定判定**。
|
|
74
|
+
- 现在:**只在比较时**折叠大小写;给调用方的报错里仍然显示**工具实际请求的那个路径**(原样)。
|
|
75
|
+
- **代价(有意接受,写在这里以免看起来像疏漏)**:在**大小写敏感**的文件系统上,
|
|
76
|
+
一个仓库同时有 `src/` 和 `SRC/` 时,`SRC/` 也会被拒。
|
|
77
|
+
**误放是漏洞,误拒只是碍事** —— 判别的不对称被选在了这一边。
|
|
78
|
+
|
|
79
|
+
### 2. 相对路径里没解析的 `..`
|
|
80
|
+
|
|
81
|
+
- 现在:匹配之前把 `..` 解析掉,**基准是调用方指定的项目根**。这条基准不是猜的:
|
|
82
|
+
IDE 以 `peaks code-gate --project "<项目目录>"` 调用门禁,而工具调用的工作目录**就是项目目录**。
|
|
83
|
+
- 解析后**逃出项目根**(`../../elsewhere/src/x.ts`)⇒ 目标在项目之外 ⇒ 不属于任何族 ⇒ **放行**,
|
|
84
|
+
与"项目根之外的绝对路径放行"是同一条规则。
|
|
85
|
+
- **代价**:基准选错会误拒邻近目录的文件;项目根是调用方与工具调用**唯一都认**的那个基准,
|
|
86
|
+
所以它被选作基准,并把这条取舍写进了代码注释。
|
|
87
|
+
|
|
88
|
+
### 3. 项目嵌在 git 仓库里:族相对**调用方指定的项目根**比
|
|
89
|
+
|
|
90
|
+
- 此前 `resolveCanonicalProjectRoot` 把根提升到 **git 根**,于是族是相对 git 根比的:
|
|
91
|
+
绝对写法 `<gitroot>/app/src/x.ts` 落在 `app/` 下 → **不在 `src/` 里** → 放行;
|
|
92
|
+
而相对写法 `src/x.ts` → **被拒**。**同一个文件,两种写法,两个判定。**
|
|
93
|
+
- 现在:**硬阻断族相对 `--project` 指名的项目根**比;**租约查找仍然用规范根**
|
|
94
|
+
(会话和租约住在那里)—— 本次只改路径比对,没有顺手改租约查找。
|
|
95
|
+
|
|
96
|
+
### 4. 三条必须保持的性质(逐条复验)
|
|
97
|
+
|
|
98
|
+
- **fail-open 策略不变**:payload 判不了时**仍然放行**,只是 stderr 上仍留 `PEAKS_CODE_GATE_UNDECIDABLE`。
|
|
99
|
+
- **六个族的成员不变**:`HARD_BLOCKED_PATH_FAMILIES` 与 `ALLOW_LISTED_PATH_PATTERNS` **零行改动**。
|
|
100
|
+
- **fast lane 仍然打开这些族**:租约是 `peaks-race-code` 时,`src/` 的编辑仍然**放行**。
|
|
101
|
+
|
|
102
|
+
### 5. `.sh` 兄弟脚本
|
|
103
|
+
|
|
104
|
+
它**没有项目根**(不收环境变量、没有参数),所以**不假装能判绝对路径** —— 这一条仍然如此。
|
|
105
|
+
它能做的两件同类的事做了:比较时折叠大小写、相对路径的 `..` 折叠。
|
|
106
|
+
它**仍然不**解析 driver —— 那会是同一个决定的第二个实现。
|
|
107
|
+
|
|
108
|
+
### 6. QA 独立复核推翻了一个理由,并挖出一个洞
|
|
109
|
+
|
|
110
|
+
- ⚠️ **"两组模式不相交"是错的。** RD 报告说"大小写折叠同时作用于白名单是安全的",理由是两组模式
|
|
111
|
+
不相交。QA 实测**推翻了它**:有 **12 种路径形态同时命中两组**(`.md` / `.peaks_` 是**后缀**模式,
|
|
112
|
+
族是**前缀**模式)。**结论仍然成立,但理由必须换成 QA 实测的那一个**:折叠让判定**恰好等于**它的
|
|
113
|
+
小写写法(84 条路径 0 例外),而每一个"新被放行"的路径,**它的小写写法在修之前就已被放行**
|
|
114
|
+
⇒ **折叠没有放进任何新文件**。
|
|
115
|
+
- ⚠️ **一个 RD 报告没有提到的洞**(QA 挖出来的;**既有问题,不是本次回归**):当**工具调用的工作目录
|
|
116
|
+
不是项目根**时 —— 例如 cwd 是 `<root>/src`、payload 是 `deep/x.ts` —— 这个路径其实指向
|
|
117
|
+
`<root>/src/deep/x.ts`,**落在 `src/` 里、应当被拒**,而门禁**放行**了。
|
|
118
|
+
本切片写下的不变量是"判定只由文件落在哪个目录决定",**这一条还没有完全成立**。
|
|
119
|
+
它的成因与 `..` 那一族同源:**相对路径的基准**。本切片选了"调用方指定的项目根",
|
|
120
|
+
而这个洞是"**工具调用自己的工作目录**" —— 两者只在 cwd == 项目根时一致。
|
|
121
|
+
- **一个覆盖缺口**(不是缺陷):套件钉住的是**词法**的 `..` 折叠,不是**基于根**的折叠 ——
|
|
122
|
+
换一种写法只红一次,而那种写法会放行一个"逃出去又绕回来"的 `..`。
|
|
123
|
+
**发出去的代码是更强的那一版**(基于根),所以这是覆盖缺口,不是缺陷。
|
|
124
|
+
- **一个数字不复现**:RD 报 `..` 那个变异"5 红";QA 试了 **10 种**改法,得到 9/9/4/14/14/14/2/2/1/1,
|
|
125
|
+
**没有一种得到 5**。**每一种都变红** ⇒ 结论成立,**数字不复现**。
|
|
126
|
+
|
|
127
|
+
### 7. QA 的结论
|
|
128
|
+
|
|
129
|
+
**PASS,0 个缺陷,2 个 LOW 发现**;门禁**没有被削弱**(fail-open 不变、六个族成员零行改动、
|
|
130
|
+
fast lane 仍打开这些族)。全量 `pnpm test:unit`:**568 文件 / 6236 通过 / 3 skip / 0 失败**。
|
|
131
|
+
真实环境:5 个 tarball 装进**仓库之外**的全新目录、npm 自己的提升布局、没手工挪 ⇒
|
|
132
|
+
**装好的那个 CLI** 对三种残留写法全部 DENY,嵌套 git 仓库那一档也 DENY;
|
|
133
|
+
用**抽取出来的 pre-fix 源码**跑同一批路径,三种都 **allow** ⇒ 缺陷复现、修复闭合。
|
|
134
|
+
|
|
3
135
|
## 4.1.14 — 2026-10-21(门禁按文件判而不是按写法判、发布包在任何 npm 布局下都能启动、门禁判不了时说得出来)
|
|
4
136
|
|
|
5
137
|
**版本级别**: 未发布区间 `v4.1.13..HEAD` 共 **4 个 commit**(**3 fix / 1 docs**)。取 **patch**,依维护者 2026-07-22 的常设规则"默认版本新增采用最小的版本位"。本次是**纯修复**:既有 CLI 参数、门禁的六个硬阻断族成员、fail-open 策略、auto-compact 三档阈值、peaks-code 的 11 步工序与 Gate A–G **一字不改**。两处行为变化都是本次要修的:**硬阻断路径的绝对写法现在被拒**(原先放行),以及**判不了的 payload 从静默放行变成留下可见标记**。
|
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
* to render this into any IDE's settings.json shape. This file is
|
|
20
20
|
* vendor-neutral — no vendor references in the source code itself.
|
|
21
21
|
*/
|
|
22
|
+
import { resolve } from 'node:path';
|
|
22
23
|
import { addJsonOption, printResult } from '../cli-helpers.js';
|
|
23
24
|
import { decideGateAction, extractFilePath, isGatedTool } from '../../services/hooks/pre-tool-code-gate.js';
|
|
25
|
+
import { resolveToolCallBaseDir } from '../../services/hooks/hook-payload-cwd.js';
|
|
24
26
|
import { hasLeaseForCaller, resolveActiveSkillForCaller } from '../../services/audit/enforcers/active-skill-resolver.js';
|
|
25
27
|
import { resolveCanonicalProjectRoot } from '../../services/config/config-service.js';
|
|
26
28
|
import { pluckObject, pluckString } from '../../services/ide/hook-translator.js';
|
|
@@ -59,6 +61,16 @@ function resolveDriver(projectRoot, payload) {
|
|
|
59
61
|
return null;
|
|
60
62
|
return resolveActiveSkillForCaller(projectRoot, { callerId }).skill;
|
|
61
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The directory the tool call runs in: the payload's own `cwd` when it names
|
|
66
|
+
* a usable one, and the gate process's own working directory otherwise — the
|
|
67
|
+
* directory the harness ran the hook in. Neither source is guessed: the
|
|
68
|
+
* payload is read at its top level, and the process's own directory is a fact
|
|
69
|
+
* about this process.
|
|
70
|
+
*/
|
|
71
|
+
function resolveToolCallDir(payload, projectRoot) {
|
|
72
|
+
return resolveToolCallBaseDir(payload, projectRoot, process.cwd());
|
|
73
|
+
}
|
|
62
74
|
/**
|
|
63
75
|
* The marker the gate leaves on stderr when it could not decide.
|
|
64
76
|
*
|
|
@@ -164,13 +176,20 @@ export function registerCodeGateCommand(program, io) {
|
|
|
164
176
|
if (undecidable !== null) {
|
|
165
177
|
reportUndecidable(undecidable);
|
|
166
178
|
}
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
// the
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
// TWO roots, because two questions ask for one. The CANONICAL root is
|
|
180
|
+
// where the session and the leases live, so the caller is placed against
|
|
181
|
+
// it. The NAMED root is the project the caller named, and it is what the
|
|
182
|
+
// deny families are relative to: a project nested inside a git repository
|
|
183
|
+
// is judged against ITSELF, not against the git root above it. One file
|
|
184
|
+
// must not get two verdicts from two spellings, and a project that is not
|
|
185
|
+
// the git root is exactly where the two would differ.
|
|
186
|
+
// The tool call's OWN directory is a third fact: it is the base a
|
|
187
|
+
// relative path is read against.
|
|
188
|
+
const namedRoot = resolve(opts.project ?? process.cwd());
|
|
189
|
+
const canonicalRoot = resolveCanonicalProjectRoot(namedRoot);
|
|
190
|
+
const driver = resolveDriver(canonicalRoot, parsed);
|
|
191
|
+
const toolCwd = resolveToolCallDir(parsed, namedRoot);
|
|
192
|
+
const verdict = decideGateAction(tool, input, driver, { projectRoot: namedRoot, toolCwd });
|
|
174
193
|
if (opts.dryRun === true) {
|
|
175
194
|
printDryRunVerdict(io, opts.json === true, { tool, input, verdict, undecidable });
|
|
176
195
|
return;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE spelling-independent form of a target path, and the roots a
|
|
3
|
+
* verdict is taken against.
|
|
4
|
+
*
|
|
5
|
+
* The deny families are project-relative prefixes (`src/`, `tests/unit/`, …),
|
|
6
|
+
* so how the incoming path happens to be SPELLED must not decide the verdict:
|
|
7
|
+
* `src/x.ts`, `./src/x.ts` and the absolute spelling of that same file are one
|
|
8
|
+
* file and must get one verdict. Without this, the same edit is denied in one
|
|
9
|
+
* spelling and allowed in another — and the allow is the one that happens.
|
|
10
|
+
*
|
|
11
|
+
* A RELATIVE path is read against the directory the tool call RUNS IN, not
|
|
12
|
+
* against the project root: the file the call writes is the one that
|
|
13
|
+
* directory names, and the two differ whenever the call runs in a
|
|
14
|
+
* subdirectory. The file it lands in is then judged by where it sits inside
|
|
15
|
+
* the project, so the families still name this project's directories.
|
|
16
|
+
*
|
|
17
|
+
* The arithmetic lives apart from the decision on purpose: the decision is
|
|
18
|
+
* the gate's rule, and this is the path arithmetic it rests on. The file the
|
|
19
|
+
* decision sits in was at its size cap, and the arithmetic needs room.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The roots a verdict is taken against: the project the caller named, and
|
|
23
|
+
* the directory the tool call runs in. A bare string is the project root
|
|
24
|
+
* alone — the shape every earlier call used.
|
|
25
|
+
*/
|
|
26
|
+
export interface GateRootPair {
|
|
27
|
+
readonly projectRoot?: string | null;
|
|
28
|
+
readonly toolCwd?: string | null;
|
|
29
|
+
}
|
|
30
|
+
/** The roots, in either of the two spellings. */
|
|
31
|
+
export type GateRoots = string | null | GateRootPair;
|
|
32
|
+
/**
|
|
33
|
+
* The one form of a target path the families are written in.
|
|
34
|
+
*
|
|
35
|
+
* - separators fold to `/` (a Windows payload spells `src\x.ts`)
|
|
36
|
+
* - a leading `./` is dropped
|
|
37
|
+
* - a `..` segment is resolved
|
|
38
|
+
* - an ABSOLUTE path inside `projectRoot` becomes project-relative
|
|
39
|
+
* - an absolute path OUTSIDE `projectRoot` stays absolute: the families name
|
|
40
|
+
* THIS project's directories, and a path in another repository is another
|
|
41
|
+
* project's business. That is also what the gate already did with every
|
|
42
|
+
* absolute path, so it is not a widening.
|
|
43
|
+
* - with no `projectRoot` an absolute path cannot be made relative and is
|
|
44
|
+
* left as it is
|
|
45
|
+
*
|
|
46
|
+
* A RELATIVE path is read against `toolCwd` — the directory the tool call
|
|
47
|
+
* runs in — and the file it lands in is judged by where it sits inside the
|
|
48
|
+
* project. A path that lands OUTSIDE the project keeps the older reading,
|
|
49
|
+
* the spelling read against the project root, which never widens the gate:
|
|
50
|
+
* it refuses a spelled family the file itself never reached.
|
|
51
|
+
*/
|
|
52
|
+
export declare function normalizeGatePath(filePath: string, projectRoot?: string | null, toolCwd?: string | null): string;
|
|
53
|
+
/** The roots, whichever of the two spellings the caller used. */
|
|
54
|
+
export declare function rootPair(roots: GateRoots | undefined): GateRootPair;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE spelling-independent form of a target path, and the roots a
|
|
3
|
+
* verdict is taken against.
|
|
4
|
+
*
|
|
5
|
+
* The deny families are project-relative prefixes (`src/`, `tests/unit/`, …),
|
|
6
|
+
* so how the incoming path happens to be SPELLED must not decide the verdict:
|
|
7
|
+
* `src/x.ts`, `./src/x.ts` and the absolute spelling of that same file are one
|
|
8
|
+
* file and must get one verdict. Without this, the same edit is denied in one
|
|
9
|
+
* spelling and allowed in another — and the allow is the one that happens.
|
|
10
|
+
*
|
|
11
|
+
* A RELATIVE path is read against the directory the tool call RUNS IN, not
|
|
12
|
+
* against the project root: the file the call writes is the one that
|
|
13
|
+
* directory names, and the two differ whenever the call runs in a
|
|
14
|
+
* subdirectory. The file it lands in is then judged by where it sits inside
|
|
15
|
+
* the project, so the families still name this project's directories.
|
|
16
|
+
*
|
|
17
|
+
* The arithmetic lives apart from the decision on purpose: the decision is
|
|
18
|
+
* the gate's rule, and this is the path arithmetic it rests on. The file the
|
|
19
|
+
* decision sits in was at its size cap, and the arithmetic needs room.
|
|
20
|
+
*/
|
|
21
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
22
|
+
import { normalizePath } from '../../shared/path-utils.js';
|
|
23
|
+
/** The directory a path is resolved against, or `null` when there is none. */
|
|
24
|
+
function resolvedDirectory(value) {
|
|
25
|
+
return typeof value === 'string' && value.length > 0 ? resolve(value) : null;
|
|
26
|
+
}
|
|
27
|
+
/** Drop every leading `./` segment: `./src/x.ts` and `src/x.ts` are one path. */
|
|
28
|
+
function stripLeadingDotSegments(path) {
|
|
29
|
+
let out = path;
|
|
30
|
+
while (out.startsWith('./'))
|
|
31
|
+
out = out.slice(2);
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Collapse the `.` and `..` segments of a RELATIVE path, lexically.
|
|
36
|
+
*
|
|
37
|
+
* The base directory does not enter the answer for a path that stays inside
|
|
38
|
+
* it: a `..` cancels the segment before it, for every base. A `..` that would
|
|
39
|
+
* leave the base is KEPT, so the result still reads as "outside", and a path
|
|
40
|
+
* outside the project belongs to no family.
|
|
41
|
+
*/
|
|
42
|
+
function collapseRelativeDotSegments(path) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const segment of path.split('/')) {
|
|
45
|
+
if (segment === '' || segment === '.')
|
|
46
|
+
continue;
|
|
47
|
+
if (segment === '..') {
|
|
48
|
+
const last = out.length > 0 ? out[out.length - 1] : null;
|
|
49
|
+
if (last !== null && last !== '..')
|
|
50
|
+
out.pop();
|
|
51
|
+
else
|
|
52
|
+
out.push('..');
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
out.push(segment);
|
|
56
|
+
}
|
|
57
|
+
return out.join('/');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The path of `target` relative to `root`, when `target` is INSIDE `root`;
|
|
61
|
+
* `null` when it is not — the target is outside the root, or it is the root.
|
|
62
|
+
*/
|
|
63
|
+
function relativizeInsideRoot(target, root) {
|
|
64
|
+
const relativePath = normalizePath(relative(root, target));
|
|
65
|
+
if (relativePath.length === 0)
|
|
66
|
+
return null;
|
|
67
|
+
if (relativePath.startsWith('..') || isAbsolute(relativePath))
|
|
68
|
+
return null;
|
|
69
|
+
return stripLeadingDotSegments(relativePath);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The one form of a target path the families are written in.
|
|
73
|
+
*
|
|
74
|
+
* - separators fold to `/` (a Windows payload spells `src\x.ts`)
|
|
75
|
+
* - a leading `./` is dropped
|
|
76
|
+
* - a `..` segment is resolved
|
|
77
|
+
* - an ABSOLUTE path inside `projectRoot` becomes project-relative
|
|
78
|
+
* - an absolute path OUTSIDE `projectRoot` stays absolute: the families name
|
|
79
|
+
* THIS project's directories, and a path in another repository is another
|
|
80
|
+
* project's business. That is also what the gate already did with every
|
|
81
|
+
* absolute path, so it is not a widening.
|
|
82
|
+
* - with no `projectRoot` an absolute path cannot be made relative and is
|
|
83
|
+
* left as it is
|
|
84
|
+
*
|
|
85
|
+
* A RELATIVE path is read against `toolCwd` — the directory the tool call
|
|
86
|
+
* runs in — and the file it lands in is judged by where it sits inside the
|
|
87
|
+
* project. A path that lands OUTSIDE the project keeps the older reading,
|
|
88
|
+
* the spelling read against the project root, which never widens the gate:
|
|
89
|
+
* it refuses a spelled family the file itself never reached.
|
|
90
|
+
*/
|
|
91
|
+
export function normalizeGatePath(filePath, projectRoot, toolCwd) {
|
|
92
|
+
if (filePath.length === 0)
|
|
93
|
+
return '';
|
|
94
|
+
const slashed = normalizePath(filePath);
|
|
95
|
+
const root = resolvedDirectory(projectRoot);
|
|
96
|
+
if (root === null) {
|
|
97
|
+
return isAbsolute(slashed)
|
|
98
|
+
? slashed
|
|
99
|
+
: collapseRelativeDotSegments(stripLeadingDotSegments(slashed));
|
|
100
|
+
}
|
|
101
|
+
if (isAbsolute(slashed)) {
|
|
102
|
+
return relativizeInsideRoot(resolve(slashed), root) ?? slashed;
|
|
103
|
+
}
|
|
104
|
+
// The file the call will really touch: the relative path read against the
|
|
105
|
+
// tool call's own directory, then judged by where it lands in the project.
|
|
106
|
+
const base = resolvedDirectory(toolCwd) ?? root;
|
|
107
|
+
const inside = relativizeInsideRoot(resolve(base, slashed), root);
|
|
108
|
+
if (inside !== null)
|
|
109
|
+
return inside;
|
|
110
|
+
// The file is outside the project: the project reads the spelling instead.
|
|
111
|
+
const spelled = resolve(root, slashed);
|
|
112
|
+
return relativizeInsideRoot(spelled, root) ?? normalizePath(spelled);
|
|
113
|
+
}
|
|
114
|
+
/** The roots, whichever of the two spellings the caller used. */
|
|
115
|
+
export function rootPair(roots) {
|
|
116
|
+
if (roots === null || roots === undefined)
|
|
117
|
+
return { projectRoot: null };
|
|
118
|
+
if (typeof roots === 'string')
|
|
119
|
+
return { projectRoot: roots };
|
|
120
|
+
return roots;
|
|
121
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool call's own directory, read from a hook payload.
|
|
3
|
+
*
|
|
4
|
+
* A relative target path belongs to the directory the tool call RUNS in: the
|
|
5
|
+
* file a call writes is the one that directory names, not the one the project
|
|
6
|
+
* root would name. The gate needs that directory to say which file a payload
|
|
7
|
+
* really points at, and the payload is where a harness states it.
|
|
8
|
+
*
|
|
9
|
+
* The read is deliberately narrow — one key, at the top level, holding a
|
|
10
|
+
* string. A `cwd` nested inside the tool's own arguments is an ARGUMENT the
|
|
11
|
+
* tool was handed, not the directory the call runs in, so only the top-level
|
|
12
|
+
* key counts.
|
|
13
|
+
*
|
|
14
|
+
* The absence of the key is not an error: the caller then uses the process's
|
|
15
|
+
* own working directory, which is the same directory whenever the harness runs
|
|
16
|
+
* the hook where the tool call runs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function readToolCallCwd(payload: Readonly<Record<string, unknown>>): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* The directory a relative target path is read against.
|
|
21
|
+
*
|
|
22
|
+
* The payload's own `cwd` is the base only when it is a USABLE one: an
|
|
23
|
+
* absolute path naming an existing directory inside the project the caller
|
|
24
|
+
* named. A `cwd` that is missing, relative, names a file, names a directory
|
|
25
|
+
* that is not there, or names a directory outside the project is not a
|
|
26
|
+
* directory this project can judge the file against — and a base that is not
|
|
27
|
+
* the call's own directory resolves the path against the wrong tree, which is
|
|
28
|
+
* how an edit into a hard-blocked family slipped through.
|
|
29
|
+
*
|
|
30
|
+
* The rule ASSUMES the tool call runs inside the named project, which is
|
|
31
|
+
* where the gate is installed. When it does not, the payload `cwd` is
|
|
32
|
+
* rejected and the path is read against the gate's own working directory
|
|
33
|
+
* instead — a different tree — and the error is one-directional: a file that
|
|
34
|
+
* lies outside every family can be denied. It is never the other way round,
|
|
35
|
+
* and that is the trade the gate makes everywhere else: a wrongly allowed
|
|
36
|
+
* edit is a hole, a wrongly refused one is an inconvenience.
|
|
37
|
+
*
|
|
38
|
+
* The fallback is the gate process's own working directory: that is where the
|
|
39
|
+
* hook runs, and in the normal invocation it IS the tool call's directory.
|
|
40
|
+
* The gate does not fail closed here — it uses the best base it has, and a
|
|
41
|
+
* file that lands outside the project is judged by its spelling, which never
|
|
42
|
+
* widens the gate.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveToolCallBaseDir(payload: Readonly<Record<string, unknown>>, projectRoot: string, fallback: string): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool call's own directory, read from a hook payload.
|
|
3
|
+
*
|
|
4
|
+
* A relative target path belongs to the directory the tool call RUNS in: the
|
|
5
|
+
* file a call writes is the one that directory names, not the one the project
|
|
6
|
+
* root would name. The gate needs that directory to say which file a payload
|
|
7
|
+
* really points at, and the payload is where a harness states it.
|
|
8
|
+
*
|
|
9
|
+
* The read is deliberately narrow — one key, at the top level, holding a
|
|
10
|
+
* string. A `cwd` nested inside the tool's own arguments is an ARGUMENT the
|
|
11
|
+
* tool was handed, not the directory the call runs in, so only the top-level
|
|
12
|
+
* key counts.
|
|
13
|
+
*
|
|
14
|
+
* The absence of the key is not an error: the caller then uses the process's
|
|
15
|
+
* own working directory, which is the same directory whenever the harness runs
|
|
16
|
+
* the hook where the tool call runs.
|
|
17
|
+
*/
|
|
18
|
+
import { statSync } from 'node:fs';
|
|
19
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
20
|
+
import { normalizePath } from '../../shared/path-utils.js';
|
|
21
|
+
export function readToolCallCwd(payload) {
|
|
22
|
+
const cwd = payload['cwd'];
|
|
23
|
+
if (typeof cwd !== 'string')
|
|
24
|
+
return null;
|
|
25
|
+
const trimmed = cwd.trim();
|
|
26
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Does `dir` name a directory that exists?
|
|
30
|
+
*
|
|
31
|
+
* A path that is not there, or that names a file, is not a directory a tool
|
|
32
|
+
* call can run in, and the gate cannot resolve a relative path against it.
|
|
33
|
+
* The read fails CLOSED on a path it cannot stat: an unreadable directory is
|
|
34
|
+
* not a usable base.
|
|
35
|
+
*/
|
|
36
|
+
function isExistingDirectory(dir) {
|
|
37
|
+
try {
|
|
38
|
+
return statSync(dir, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Is `dir` the project root itself, or a directory inside it?
|
|
46
|
+
*
|
|
47
|
+
* The check is LEXICAL, like the path arithmetic it feeds: a symlink inside
|
|
48
|
+
* the project that points outside it passes here. A base outside the project
|
|
49
|
+
* resolves the path against a tree the families do not name, so the file it
|
|
50
|
+
* lands in cannot be judged by where it sits in the project — which is the
|
|
51
|
+
* invariant the gate is built on.
|
|
52
|
+
*/
|
|
53
|
+
function isInsideProject(root, dir) {
|
|
54
|
+
const rel = normalizePath(relative(resolve(root), resolve(dir)));
|
|
55
|
+
if (rel.length === 0)
|
|
56
|
+
return true;
|
|
57
|
+
if (rel === '..' || rel.startsWith('../'))
|
|
58
|
+
return false;
|
|
59
|
+
return !isAbsolute(rel);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The directory a relative target path is read against.
|
|
63
|
+
*
|
|
64
|
+
* The payload's own `cwd` is the base only when it is a USABLE one: an
|
|
65
|
+
* absolute path naming an existing directory inside the project the caller
|
|
66
|
+
* named. A `cwd` that is missing, relative, names a file, names a directory
|
|
67
|
+
* that is not there, or names a directory outside the project is not a
|
|
68
|
+
* directory this project can judge the file against — and a base that is not
|
|
69
|
+
* the call's own directory resolves the path against the wrong tree, which is
|
|
70
|
+
* how an edit into a hard-blocked family slipped through.
|
|
71
|
+
*
|
|
72
|
+
* The rule ASSUMES the tool call runs inside the named project, which is
|
|
73
|
+
* where the gate is installed. When it does not, the payload `cwd` is
|
|
74
|
+
* rejected and the path is read against the gate's own working directory
|
|
75
|
+
* instead — a different tree — and the error is one-directional: a file that
|
|
76
|
+
* lies outside every family can be denied. It is never the other way round,
|
|
77
|
+
* and that is the trade the gate makes everywhere else: a wrongly allowed
|
|
78
|
+
* edit is a hole, a wrongly refused one is an inconvenience.
|
|
79
|
+
*
|
|
80
|
+
* The fallback is the gate process's own working directory: that is where the
|
|
81
|
+
* hook runs, and in the normal invocation it IS the tool call's directory.
|
|
82
|
+
* The gate does not fail closed here — it uses the best base it has, and a
|
|
83
|
+
* file that lands outside the project is judged by its spelling, which never
|
|
84
|
+
* widens the gate.
|
|
85
|
+
*/
|
|
86
|
+
export function resolveToolCallBaseDir(payload, projectRoot, fallback) {
|
|
87
|
+
const cwd = readToolCallCwd(payload);
|
|
88
|
+
if (cwd === null)
|
|
89
|
+
return fallback;
|
|
90
|
+
if (!isAbsolute(cwd))
|
|
91
|
+
return fallback;
|
|
92
|
+
if (!isExistingDirectory(cwd))
|
|
93
|
+
return fallback;
|
|
94
|
+
if (!isInsideProject(projectRoot, cwd))
|
|
95
|
+
return fallback;
|
|
96
|
+
return cwd;
|
|
97
|
+
}
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
* logic, usable from any non-Node harness. Both share the same
|
|
19
19
|
* hard-blocked + allow-listed path families.
|
|
20
20
|
*/
|
|
21
|
+
import { normalizeGatePath, type GateRoots } from './gate-path-normalize.js';
|
|
22
|
+
export { normalizeGatePath };
|
|
23
|
+
export type { GateRoots };
|
|
21
24
|
export type GateToolName = 'Edit' | 'Write' | 'MultiEdit' | string;
|
|
22
25
|
export type GatePathKey = 'file_path' | 'path' | 'notebook_path';
|
|
23
26
|
export interface GateInput {
|
|
@@ -42,30 +45,6 @@ export type GateVerdict = {
|
|
|
42
45
|
};
|
|
43
46
|
/** Pull the target file path from `input.file_path | input.path | input.notebook_path`. */
|
|
44
47
|
export declare function extractFilePath(input: Readonly<Record<string, unknown>>): string;
|
|
45
|
-
/**
|
|
46
|
-
* The ONE spelling-independent form of a target path.
|
|
47
|
-
*
|
|
48
|
-
* The deny families are project-relative prefixes (`src/`, `tests/unit/`, …),
|
|
49
|
-
* so how the incoming path happens to be SPELLED must not decide the verdict:
|
|
50
|
-
* `src/x.ts`, `./src/x.ts` and the absolute spelling of that same file are one
|
|
51
|
-
* file and must get one verdict. Without this, the same edit is denied in one
|
|
52
|
-
* spelling and allowed in another — and the allow is the one that happens.
|
|
53
|
-
*
|
|
54
|
-
* - separators fold to `/` (a Windows payload spells `src\x.ts`)
|
|
55
|
-
* - a leading `./` is dropped
|
|
56
|
-
* - an ABSOLUTE path inside `projectRoot` becomes project-relative
|
|
57
|
-
* - an absolute path OUTSIDE `projectRoot` stays absolute: the families name
|
|
58
|
-
* THIS project's directories, and a path in another repository is another
|
|
59
|
-
* project's business. That is also what the gate already did with every
|
|
60
|
-
* absolute path, so it is not a widening.
|
|
61
|
-
* - with no `projectRoot` an absolute path cannot be made relative and is
|
|
62
|
-
* left as it is
|
|
63
|
-
*
|
|
64
|
-
* A `..` segment is deliberately NOT resolved: a relative path is relative to
|
|
65
|
-
* the tool call's own working directory, which this module does not know, and
|
|
66
|
-
* resolving it against the project root would be a guess.
|
|
67
|
-
*/
|
|
68
|
-
export declare function normalizeGatePath(filePath: string, projectRoot?: string | null): string;
|
|
69
48
|
/**
|
|
70
49
|
* Pure decision function. Given the tool name + input object, return
|
|
71
50
|
* the gate verdict. Tolerates malformed payloads (allow).
|
|
@@ -76,8 +55,20 @@ export declare function normalizeGatePath(filePath: string, projectRoot?: string
|
|
|
76
55
|
* hard-blocked families deny. Resolution is the caller's job, so this
|
|
77
56
|
* module keeps no session, lease or filesystem state.
|
|
78
57
|
*
|
|
79
|
-
* `
|
|
80
|
-
*
|
|
81
|
-
*
|
|
58
|
+
* `roots` is where the verdict is taken: the root the deny families are
|
|
59
|
+
* relative to, and the directory the tool call runs in. A bare string is the
|
|
60
|
+
* project root alone, which is how every earlier call spelled it.
|
|
61
|
+
*
|
|
62
|
+
* The project root is what lets an ABSOLUTE path be judged like its relative
|
|
63
|
+
* spelling; without it an absolute path cannot be related to the project and
|
|
64
|
+
* is left alone. It is the project root the CALLER named, not the canonical
|
|
65
|
+
* root above it: a project nested inside a git repository is judged against
|
|
66
|
+
* itself, and the canonical root - where the session and the leases live - is
|
|
67
|
+
* a different question that this parameter does not answer.
|
|
68
|
+
*
|
|
69
|
+
* The tool call's directory is the base a RELATIVE path is read against: the
|
|
70
|
+
* file a call writes is the one that directory names. It does not move the
|
|
71
|
+
* families - those stay relative to the project root - it only says which
|
|
72
|
+
* file the payload points at.
|
|
82
73
|
*/
|
|
83
|
-
export declare function decideGateAction(tool: GateToolName, input: Readonly<Record<string, unknown>>, driver?: string | null,
|
|
74
|
+
export declare function decideGateAction(tool: GateToolName, input: Readonly<Record<string, unknown>>, driver?: string | null, roots?: GateRoots): GateVerdict;
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* logic, usable from any non-Node harness. Both share the same
|
|
19
19
|
* hard-blocked + allow-listed path families.
|
|
20
20
|
*/
|
|
21
|
-
import {
|
|
22
|
-
|
|
21
|
+
import { normalizeGatePath, rootPair } from './gate-path-normalize.js';
|
|
22
|
+
export { normalizeGatePath };
|
|
23
23
|
/** Hard-blocked path families — orchestrator MUST NOT Edit/Write these. */
|
|
24
24
|
export const HARD_BLOCKED_PATH_FAMILIES = [
|
|
25
25
|
'src/',
|
|
@@ -61,60 +61,36 @@ export function extractFilePath(input) {
|
|
|
61
61
|
}
|
|
62
62
|
return '';
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Does the path belong to one of these families?
|
|
66
|
+
*
|
|
67
|
+
* The comparison folds CASE: every family name is written in lower case, and
|
|
68
|
+
* on a case-insensitive filesystem (Windows, and macOS by default) `SRC/x.ts`
|
|
69
|
+
* IS the file `src/x.ts`, so comparing the case exactly lets the spelling
|
|
70
|
+
* decide the verdict. BOTH lists are folded the same way, because both are
|
|
71
|
+
* judged against the same path: a case variant of an allow-listed file has to
|
|
72
|
+
* reach the same verdict as the file itself, or the fold would only move the
|
|
73
|
+
* inconsistency from one list to the other.
|
|
74
|
+
*
|
|
75
|
+
* THE TRADE-OFF, written down instead of left to look like an oversight: on a
|
|
76
|
+
* case-SENSITIVE filesystem a repository holding BOTH `src/` and `SRC/`
|
|
77
|
+
* refuses the edit under `SRC/` as well. That refusal is accepted on purpose.
|
|
78
|
+
* A wrongly allowed edit is a hole in the gate; a wrongly refused one is an
|
|
79
|
+
* inconvenience the caller can undo. Only the COMPARISON folds case - the
|
|
80
|
+
* path the tool asked for is echoed to the caller exactly as it was spelled,
|
|
81
|
+
* and the family a verdict names is the canonical one, not the folded form.
|
|
82
|
+
*/
|
|
64
83
|
function matchesAny(path, families) {
|
|
84
|
+
const folded = path.toLowerCase();
|
|
65
85
|
for (const fam of families) {
|
|
66
|
-
if (
|
|
86
|
+
if (folded.startsWith(fam.toLowerCase()))
|
|
67
87
|
return fam;
|
|
68
88
|
// also handle ".md" suffix pattern
|
|
69
|
-
if (fam.startsWith('.') &&
|
|
89
|
+
if (fam.startsWith('.') && folded.endsWith(fam.toLowerCase()))
|
|
70
90
|
return fam;
|
|
71
91
|
}
|
|
72
92
|
return null;
|
|
73
93
|
}
|
|
74
|
-
/** Drop every leading `./` segment: `./src/x.ts` and `src/x.ts` are one path. */
|
|
75
|
-
function stripLeadingDotSegments(path) {
|
|
76
|
-
let out = path;
|
|
77
|
-
while (out.startsWith('./'))
|
|
78
|
-
out = out.slice(2);
|
|
79
|
-
return out;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* The ONE spelling-independent form of a target path.
|
|
83
|
-
*
|
|
84
|
-
* The deny families are project-relative prefixes (`src/`, `tests/unit/`, …),
|
|
85
|
-
* so how the incoming path happens to be SPELLED must not decide the verdict:
|
|
86
|
-
* `src/x.ts`, `./src/x.ts` and the absolute spelling of that same file are one
|
|
87
|
-
* file and must get one verdict. Without this, the same edit is denied in one
|
|
88
|
-
* spelling and allowed in another — and the allow is the one that happens.
|
|
89
|
-
*
|
|
90
|
-
* - separators fold to `/` (a Windows payload spells `src\x.ts`)
|
|
91
|
-
* - a leading `./` is dropped
|
|
92
|
-
* - an ABSOLUTE path inside `projectRoot` becomes project-relative
|
|
93
|
-
* - an absolute path OUTSIDE `projectRoot` stays absolute: the families name
|
|
94
|
-
* THIS project's directories, and a path in another repository is another
|
|
95
|
-
* project's business. That is also what the gate already did with every
|
|
96
|
-
* absolute path, so it is not a widening.
|
|
97
|
-
* - with no `projectRoot` an absolute path cannot be made relative and is
|
|
98
|
-
* left as it is
|
|
99
|
-
*
|
|
100
|
-
* A `..` segment is deliberately NOT resolved: a relative path is relative to
|
|
101
|
-
* the tool call's own working directory, which this module does not know, and
|
|
102
|
-
* resolving it against the project root would be a guess.
|
|
103
|
-
*/
|
|
104
|
-
export function normalizeGatePath(filePath, projectRoot) {
|
|
105
|
-
if (filePath.length === 0)
|
|
106
|
-
return '';
|
|
107
|
-
const slashed = normalizePath(filePath);
|
|
108
|
-
if (!isAbsolute(slashed))
|
|
109
|
-
return stripLeadingDotSegments(slashed);
|
|
110
|
-
if (typeof projectRoot === 'string' && projectRoot.length > 0) {
|
|
111
|
-
const relativePath = normalizePath(relative(resolve(projectRoot), resolve(slashed)));
|
|
112
|
-
if (relativePath.length > 0 && !relativePath.startsWith('..') && !isAbsolute(relativePath)) {
|
|
113
|
-
return stripLeadingDotSegments(relativePath);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return slashed;
|
|
117
|
-
}
|
|
118
94
|
/**
|
|
119
95
|
* Pure decision function. Given the tool name + input object, return
|
|
120
96
|
* the gate verdict. Tolerates malformed payloads (allow).
|
|
@@ -125,11 +101,23 @@ export function normalizeGatePath(filePath, projectRoot) {
|
|
|
125
101
|
* hard-blocked families deny. Resolution is the caller's job, so this
|
|
126
102
|
* module keeps no session, lease or filesystem state.
|
|
127
103
|
*
|
|
128
|
-
* `
|
|
129
|
-
*
|
|
130
|
-
*
|
|
104
|
+
* `roots` is where the verdict is taken: the root the deny families are
|
|
105
|
+
* relative to, and the directory the tool call runs in. A bare string is the
|
|
106
|
+
* project root alone, which is how every earlier call spelled it.
|
|
107
|
+
*
|
|
108
|
+
* The project root is what lets an ABSOLUTE path be judged like its relative
|
|
109
|
+
* spelling; without it an absolute path cannot be related to the project and
|
|
110
|
+
* is left alone. It is the project root the CALLER named, not the canonical
|
|
111
|
+
* root above it: a project nested inside a git repository is judged against
|
|
112
|
+
* itself, and the canonical root - where the session and the leases live - is
|
|
113
|
+
* a different question that this parameter does not answer.
|
|
114
|
+
*
|
|
115
|
+
* The tool call's directory is the base a RELATIVE path is read against: the
|
|
116
|
+
* file a call writes is the one that directory names. It does not move the
|
|
117
|
+
* families - those stay relative to the project root - it only says which
|
|
118
|
+
* file the payload points at.
|
|
131
119
|
*/
|
|
132
|
-
export function decideGateAction(tool, input, driver,
|
|
120
|
+
export function decideGateAction(tool, input, driver, roots) {
|
|
133
121
|
// Only gate Edit / Write / MultiEdit.
|
|
134
122
|
if (!isGatedTool(tool)) {
|
|
135
123
|
return { action: 'allow' };
|
|
@@ -145,13 +133,15 @@ export function decideGateAction(tool, input, driver, projectRoot) {
|
|
|
145
133
|
// names it, so the path is reduced to the project-relative form the
|
|
146
134
|
// families are written in before anything is matched. The verdict still
|
|
147
135
|
// echoes the path the tool actually asked for.
|
|
148
|
-
const
|
|
136
|
+
const pair = rootPair(roots);
|
|
137
|
+
const filePath = normalizeGatePath(requestedPath, pair.projectRoot, pair.toolCwd);
|
|
149
138
|
// Allow-list check first — short-circuits any deny, for every driver.
|
|
150
139
|
const allowMatch = matchesAny(filePath, ALLOW_LISTED_PATH_PATTERNS);
|
|
151
140
|
if (allowMatch !== null) {
|
|
152
141
|
return { action: 'allow' };
|
|
153
142
|
}
|
|
154
|
-
// Hard-blocked family check
|
|
143
|
+
// Hard-blocked family check — case-insensitively, because every family name
|
|
144
|
+
// is lower-case and the filesystem holding the file may not be.
|
|
155
145
|
const denyMatch = matchesAny(filePath, HARD_BLOCKED_PATH_FAMILIES);
|
|
156
146
|
if (denyMatch !== null) {
|
|
157
147
|
// A driver that is not the fast lane falls through to the same deny a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peaks-loop",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.16",
|
|
4
4
|
"description": "Loop Engineering CLI — workflow primitive / loop guards / evaluators / slice orchestration",
|
|
5
5
|
"author": "SquabbyZ",
|
|
6
6
|
"keywords": [
|
|
@@ -129,10 +129,10 @@
|
|
|
129
129
|
"picomatch": "4.0.7",
|
|
130
130
|
"yaml": "^2.9.1",
|
|
131
131
|
"zod": "^4.6.7",
|
|
132
|
-
"peaks-loop-mut": "0.1.
|
|
133
|
-
"peaks-loop-shared
|
|
134
|
-
"peaks-loop-shared": "0.0.
|
|
135
|
-
"peaks-loop-internal-runtime": "0.0.
|
|
132
|
+
"peaks-loop-mut": "0.1.70",
|
|
133
|
+
"peaks-loop-shared": "0.0.105",
|
|
134
|
+
"peaks-loop-shared-channel": "0.0.73",
|
|
135
|
+
"peaks-loop-internal-runtime": "0.0.56"
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
138
|
"@changesets/cli": "2.31.1",
|