peaks-loop 4.1.16 → 4.1.17
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 +50 -0
- package/dist/services/hooks/gate-path-normalize.d.ts +37 -0
- package/dist/services/hooks/gate-path-normalize.js +74 -4
- package/dist/services/hooks/hook-payload-cwd.js +25 -9
- package/dist/services/hooks/pre-tool-code-gate.d.ts +20 -0
- package/dist/services/hooks/pre-tool-code-gate.js +68 -18
- 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.17"
|
|
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.17",
|
|
11
11
|
"author": {
|
|
12
12
|
"name": "SquabbyZ"
|
|
13
13
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.1.17 — 2026-10-22(相对路径按它**在哪个目录**判,不按它**怎么拼写**判)
|
|
4
|
+
|
|
5
|
+
**版本级别**:候选 **patch**(沿用常设规则"默认版本新增采用最小的版本位")。本次是**纯修复**:
|
|
6
|
+
既有 CLI 参数、门禁的六个硬阻断族成员、fail-open 策略、auto-compact 三档阈值、
|
|
7
|
+
peaks-code 的 11 步工序与 Gate A–G **一字不改**。
|
|
8
|
+
上一版(4.1.16)把相对路径的**基准**改成了"工具调用实际所在的目录",但**基准与项目根是按字面比较的** ——
|
|
9
|
+
本次把这个洞收口。
|
|
10
|
+
|
|
11
|
+
### 1. 一个目录可以有两种拼法,判决不能因此不同
|
|
12
|
+
|
|
13
|
+
- 此前:相对路径的**基准**(工具调用的目录)与**项目根**按**字面**比较。路径里有符号链接时,
|
|
14
|
+
两者对不上 ⇒ 门禁判定"文件在项目外" ⇒ 退回**按拼写读** ⇒ 拼得像 `src/` 的写法**被放行**。
|
|
15
|
+
- **macOS 上这不是假设**:测试 harness 的项目根来自 `mkdtempSync(tmpdir())`,是**非规范**的
|
|
16
|
+
`/var/folders/...`;而门禁进程自己的工作目录是**规范**的 `/private/var/...`(`/var` 是
|
|
17
|
+
`private/var` 的符号链接)。两者一错配就中招 ⇒ **4.1.16 推上去时 `macos-latest` 那条 job 是红的**,
|
|
18
|
+
8 个用例失败。**Windows 一个月没暴露,只因为本机 temp 路径里没有符号链接。**
|
|
19
|
+
- 现在:路径读**两遍** —— **词面**(怎么写的)与**规范**(文件真实在哪)—— 判决取**最严**的那个。
|
|
20
|
+
**白名单是每一遍各自先判的**:一遍命中白名单不会因为另一遍命中族而变成拒绝。
|
|
21
|
+
- **裁决原则用的是本仓库自己的那条**(见 4.1.15):**误放是漏洞,误拒只是碍事**。
|
|
22
|
+
所以**不是**"规范读法当权威"——那会在 `src` → `shared/src` 这种常见布局里**放宽**门禁
|
|
23
|
+
(词面 `src/x.ts` 拒、规范 `shared/src/x.ts` 放行);而是**任一遍命中族就拒**。
|
|
24
|
+
|
|
25
|
+
### 2. `.sh` 兄弟实现也走同一条规则
|
|
26
|
+
|
|
27
|
+
它原本只按**拼写**判,于是和 Node 版**越漂越远**:Node 拒的写法它放行。
|
|
28
|
+
现在它取同样两遍读法、取同样的最严判决,而且**规范读法相对的是它自己解析出来的那个基准** ——
|
|
29
|
+
两套实现因此不可能对"文件在哪"给出不同答案。
|
|
30
|
+
**两个实现同一条规则,就必须互相测,而不是各自对着自己的预期测。**
|
|
31
|
+
|
|
32
|
+
### 3. 被有意接受的取舍(写在这里以免看起来像疏漏)
|
|
33
|
+
|
|
34
|
+
- **落在项目之外的相对路径**仍按"拼写相对项目根"读 ⇒ **不会放宽**门禁。
|
|
35
|
+
- **一个被纠正的误拒**:当**基准在非族目录**(例如 `<root>/docs`)时,旧的拼写锚定规则会把
|
|
36
|
+
`src/x.ts` 这类写法**拒**掉,而那些文件其实落在 `<root>/docs/…`、**在所有硬阻断族之外**。
|
|
37
|
+
现在按文件真实所在判 ⇒ **放行**。这是**放宽**,方向是裁定自己的不变量(判决跟文件走,不跟拼写走),
|
|
38
|
+
**已接受并记录**(不 claim 掉)。
|
|
39
|
+
- **兄弟实现还有三处已知短板**(它**读不到** payload 顶层 `cwd`、**推导**项目根、**无法相对化绝对路径**),
|
|
40
|
+
归在 backlog §19.1/§19.2 的 owner 决策里,不在本次收口。
|
|
41
|
+
|
|
42
|
+
### 4. 验证
|
|
43
|
+
|
|
44
|
+
- 与**改动前**的代码逐行对照:**896 行里 0 行**让任一实现放行了落在拒绝族里的文件。
|
|
45
|
+
- **不得放宽**:Node 命令**收紧 92 / 放宽 0**;兄弟实现**收紧 76 / 放宽 0**。
|
|
46
|
+
相对**切片前**的代码,Node 112/40、兄弟 108/36 —— 那 76 个放宽**全部**在非族目录的基准上,
|
|
47
|
+
每个文件都落在所有族之外(§3 那个被纠正的误拒),**不是洞**。
|
|
48
|
+
- 家族成员零行改动,fail-open 不变,fast lane 仍然打开这些族。
|
|
49
|
+
- **顺手订正一句注释**:它描述了一种代码并不做的比较(审计里的第六条 LOW)——现在它说的是代码做的事。
|
|
50
|
+
- 另附一条**实测**:门禁读的 payload 顶层 `cwd` **确实是 PreToolUse payload 的顶层字段**
|
|
51
|
+
(对着本机装的 Claude Code 二进制读到构造点,不是推断);**任何 IDE 都会这么发**这一条**仍未实测**。
|
|
52
|
+
|
|
3
53
|
## 4.1.16 — 2026-10-22(相对路径按工具调用实际所在的目录解析)
|
|
4
54
|
|
|
5
55
|
**版本级别**:候选 **patch**(沿用常设规则"默认版本新增采用最小的版本位")。本次是**纯修复**:
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
* subdirectory. The file it lands in is then judged by where it sits inside
|
|
15
15
|
* the project, so the families still name this project's directories.
|
|
16
16
|
*
|
|
17
|
+
* Two readings of one file are offered: the LEXICAL one (`normalizeGatePath`)
|
|
18
|
+
* and the CANONICAL one (`canonicalGatePath`). One directory can be named
|
|
19
|
+
* two ways, and the caller takes the STRICTEST of the two — a wrongly
|
|
20
|
+
* allowed edit is a hole in the gate, a wrongly refused one is only an
|
|
21
|
+
* inconvenience.
|
|
22
|
+
*
|
|
17
23
|
* The arithmetic lives apart from the decision on purpose: the decision is
|
|
18
24
|
* the gate's rule, and this is the path arithmetic it rests on. The file the
|
|
19
25
|
* decision sits in was at its size cap, and the arithmetic needs room.
|
|
@@ -48,7 +54,38 @@ export type GateRoots = string | null | GateRootPair;
|
|
|
48
54
|
* project. A path that lands OUTSIDE the project keeps the older reading,
|
|
49
55
|
* the spelling read against the project root, which never widens the gate:
|
|
50
56
|
* it refuses a spelled family the file itself never reached.
|
|
57
|
+
*
|
|
58
|
+
* "Inside" and "outside" are asked LEXICALLY first and CANONICALLY second
|
|
59
|
+
* (see `relativizeInsideRoot`), so two spellings of one directory reach one
|
|
60
|
+
* verdict.
|
|
61
|
+
*
|
|
62
|
+
* This is the LEXICAL reading. The CANONICAL reading — the file named by the
|
|
63
|
+
* directory it really sits in — is a separate question, asked by
|
|
64
|
+
* `canonicalGatePath`.
|
|
51
65
|
*/
|
|
52
66
|
export declare function normalizeGatePath(filePath: string, projectRoot?: string | null, toolCwd?: string | null): string;
|
|
53
67
|
/** The roots, whichever of the two spellings the caller used. */
|
|
54
68
|
export declare function rootPair(roots: GateRoots | undefined): GateRootPair;
|
|
69
|
+
/**
|
|
70
|
+
* The CANONICAL project-relative form of a target path: the file the call
|
|
71
|
+
* really touches, named by the directory it REALLY sits in.
|
|
72
|
+
*
|
|
73
|
+
* The lexical form says how the path is WRITTEN; this one says where the
|
|
74
|
+
* file IS. The two differ whenever a directory is named two ways — a
|
|
75
|
+
* symlink, a junction, macOS's `/var` → `/private/var` — and the difference
|
|
76
|
+
* is what a symlinked BASE inside the project looks like: the call runs in
|
|
77
|
+
* `link/`, the file is in `src/`, and the lexical form says `link/x.ts`
|
|
78
|
+
* (no family) while this one says `src/x.ts` (a family).
|
|
79
|
+
*
|
|
80
|
+
* The two sides are compared as they are CANONICALLY spelled, so the answer
|
|
81
|
+
* is the directory the file is in and not the spelling the caller used to
|
|
82
|
+
* reach it. The LEXICAL-first-then-canonical retry belongs to the other
|
|
83
|
+
* reading (`relativizeInsideRoot`), which needs it because a lexical answer
|
|
84
|
+
* can be a statement about the SPELLING rather than about the directory.
|
|
85
|
+
*
|
|
86
|
+
* `null` when the file is outside the project: the project has no name for
|
|
87
|
+
* it, and the spelling-anchored reading the caller already holds is the one
|
|
88
|
+
* that applies. `null` also when there is no project root at all, for the
|
|
89
|
+
* same reason — a path cannot be made relative to nothing.
|
|
90
|
+
*/
|
|
91
|
+
export declare function canonicalGatePath(filePath: string, projectRoot?: string | null, toolCwd?: string | null): string | null;
|
|
@@ -14,12 +14,18 @@
|
|
|
14
14
|
* subdirectory. The file it lands in is then judged by where it sits inside
|
|
15
15
|
* the project, so the families still name this project's directories.
|
|
16
16
|
*
|
|
17
|
+
* Two readings of one file are offered: the LEXICAL one (`normalizeGatePath`)
|
|
18
|
+
* and the CANONICAL one (`canonicalGatePath`). One directory can be named
|
|
19
|
+
* two ways, and the caller takes the STRICTEST of the two — a wrongly
|
|
20
|
+
* allowed edit is a hole in the gate, a wrongly refused one is only an
|
|
21
|
+
* inconvenience.
|
|
22
|
+
*
|
|
17
23
|
* The arithmetic lives apart from the decision on purpose: the decision is
|
|
18
24
|
* the gate's rule, and this is the path arithmetic it rests on. The file the
|
|
19
25
|
* decision sits in was at its size cap, and the arithmetic needs room.
|
|
20
26
|
*/
|
|
21
27
|
import { isAbsolute, relative, resolve } from 'node:path';
|
|
22
|
-
import { normalizePath } from '../../shared/path-utils.js';
|
|
28
|
+
import { normalizePath, stablePath } from '../../shared/path-utils.js';
|
|
23
29
|
/** The directory a path is resolved against, or `null` when there is none. */
|
|
24
30
|
function resolvedDirectory(value) {
|
|
25
31
|
return typeof value === 'string' && value.length > 0 ? resolve(value) : null;
|
|
@@ -57,10 +63,10 @@ function collapseRelativeDotSegments(path) {
|
|
|
57
63
|
return out.join('/');
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
* The path of `target` relative to `root`,
|
|
61
|
-
* `
|
|
66
|
+
* The path of `target` relative to `root`, compared LEXICALLY: `null` when
|
|
67
|
+
* `target` is not inside `root` — it is outside the root, or it is the root.
|
|
62
68
|
*/
|
|
63
|
-
function
|
|
69
|
+
function relativizeLexically(target, root) {
|
|
64
70
|
const relativePath = normalizePath(relative(root, target));
|
|
65
71
|
if (relativePath.length === 0)
|
|
66
72
|
return null;
|
|
@@ -68,6 +74,29 @@ function relativizeInsideRoot(target, root) {
|
|
|
68
74
|
return null;
|
|
69
75
|
return stripLeadingDotSegments(relativePath);
|
|
70
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* The path of `target` relative to `root`, when `target` is INSIDE `root`;
|
|
79
|
+
* `null` when it is not — the target is outside the root, or it is the root.
|
|
80
|
+
*
|
|
81
|
+
* The answer is LEXICAL first: the two sides are compared as they are
|
|
82
|
+
* written, so the common case costs no syscall. When the lexical answer is
|
|
83
|
+
* "outside", the question is asked again with the CANONICAL spelling of both
|
|
84
|
+
* sides, because one directory can be named two ways — a symlink, a junction,
|
|
85
|
+
* macOS's `/var` → `/private/var` — and then the lexical answer is a
|
|
86
|
+
* statement about the SPELLING, not about the directory the file is in. The
|
|
87
|
+
* retry can only turn "outside" into "inside", so it can only tighten the
|
|
88
|
+
* gate; whenever the lexical answer says "inside", that answer stands.
|
|
89
|
+
*
|
|
90
|
+
* The canonical answer is relativized against the CANONICAL root, because
|
|
91
|
+
* the project-relative spelling it produces is what the deny families are
|
|
92
|
+
* matched against.
|
|
93
|
+
*/
|
|
94
|
+
function relativizeInsideRoot(target, root) {
|
|
95
|
+
const lexical = relativizeLexically(target, root);
|
|
96
|
+
if (lexical !== null)
|
|
97
|
+
return lexical;
|
|
98
|
+
return relativizeLexically(stablePath(target), stablePath(root));
|
|
99
|
+
}
|
|
71
100
|
/**
|
|
72
101
|
* The one form of a target path the families are written in.
|
|
73
102
|
*
|
|
@@ -87,6 +116,14 @@ function relativizeInsideRoot(target, root) {
|
|
|
87
116
|
* project. A path that lands OUTSIDE the project keeps the older reading,
|
|
88
117
|
* the spelling read against the project root, which never widens the gate:
|
|
89
118
|
* it refuses a spelled family the file itself never reached.
|
|
119
|
+
*
|
|
120
|
+
* "Inside" and "outside" are asked LEXICALLY first and CANONICALLY second
|
|
121
|
+
* (see `relativizeInsideRoot`), so two spellings of one directory reach one
|
|
122
|
+
* verdict.
|
|
123
|
+
*
|
|
124
|
+
* This is the LEXICAL reading. The CANONICAL reading — the file named by the
|
|
125
|
+
* directory it really sits in — is a separate question, asked by
|
|
126
|
+
* `canonicalGatePath`.
|
|
90
127
|
*/
|
|
91
128
|
export function normalizeGatePath(filePath, projectRoot, toolCwd) {
|
|
92
129
|
if (filePath.length === 0)
|
|
@@ -119,3 +156,36 @@ export function rootPair(roots) {
|
|
|
119
156
|
return { projectRoot: roots };
|
|
120
157
|
return roots;
|
|
121
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* The CANONICAL project-relative form of a target path: the file the call
|
|
161
|
+
* really touches, named by the directory it REALLY sits in.
|
|
162
|
+
*
|
|
163
|
+
* The lexical form says how the path is WRITTEN; this one says where the
|
|
164
|
+
* file IS. The two differ whenever a directory is named two ways — a
|
|
165
|
+
* symlink, a junction, macOS's `/var` → `/private/var` — and the difference
|
|
166
|
+
* is what a symlinked BASE inside the project looks like: the call runs in
|
|
167
|
+
* `link/`, the file is in `src/`, and the lexical form says `link/x.ts`
|
|
168
|
+
* (no family) while this one says `src/x.ts` (a family).
|
|
169
|
+
*
|
|
170
|
+
* The two sides are compared as they are CANONICALLY spelled, so the answer
|
|
171
|
+
* is the directory the file is in and not the spelling the caller used to
|
|
172
|
+
* reach it. The LEXICAL-first-then-canonical retry belongs to the other
|
|
173
|
+
* reading (`relativizeInsideRoot`), which needs it because a lexical answer
|
|
174
|
+
* can be a statement about the SPELLING rather than about the directory.
|
|
175
|
+
*
|
|
176
|
+
* `null` when the file is outside the project: the project has no name for
|
|
177
|
+
* it, and the spelling-anchored reading the caller already holds is the one
|
|
178
|
+
* that applies. `null` also when there is no project root at all, for the
|
|
179
|
+
* same reason — a path cannot be made relative to nothing.
|
|
180
|
+
*/
|
|
181
|
+
export function canonicalGatePath(filePath, projectRoot, toolCwd) {
|
|
182
|
+
if (filePath.length === 0)
|
|
183
|
+
return null;
|
|
184
|
+
const slashed = normalizePath(filePath);
|
|
185
|
+
const root = resolvedDirectory(projectRoot);
|
|
186
|
+
if (root === null)
|
|
187
|
+
return null;
|
|
188
|
+
const base = resolvedDirectory(toolCwd) ?? root;
|
|
189
|
+
const target = isAbsolute(slashed) ? resolve(slashed) : resolve(base, slashed);
|
|
190
|
+
return relativizeLexically(stablePath(target), stablePath(root));
|
|
191
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { statSync } from 'node:fs';
|
|
19
19
|
import { isAbsolute, relative, resolve } from 'node:path';
|
|
20
|
-
import { normalizePath } from '../../shared/path-utils.js';
|
|
20
|
+
import { normalizePath, stablePath } from '../../shared/path-utils.js';
|
|
21
21
|
export function readToolCallCwd(payload) {
|
|
22
22
|
const cwd = payload['cwd'];
|
|
23
23
|
if (typeof cwd !== 'string')
|
|
@@ -42,15 +42,10 @@ function isExistingDirectory(dir) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
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.
|
|
45
|
+
* Is `dir` the project root itself, or a directory inside it? Compared
|
|
46
|
+
* LEXICALLY: the two are compared as they are written.
|
|
52
47
|
*/
|
|
53
|
-
function
|
|
48
|
+
function isInsideLexically(root, dir) {
|
|
54
49
|
const rel = normalizePath(relative(resolve(root), resolve(dir)));
|
|
55
50
|
if (rel.length === 0)
|
|
56
51
|
return true;
|
|
@@ -58,6 +53,27 @@ function isInsideProject(root, dir) {
|
|
|
58
53
|
return false;
|
|
59
54
|
return !isAbsolute(rel);
|
|
60
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Is `dir` the project root itself, or a directory inside it?
|
|
58
|
+
*
|
|
59
|
+
* The check is LEXICAL first, like the path arithmetic it feeds: a symlink
|
|
60
|
+
* inside the project that points outside it passes here. A base outside the
|
|
61
|
+
* project resolves the path against a tree the families do not name, so the
|
|
62
|
+
* file it lands in cannot be judged by where it sits in the project — which
|
|
63
|
+
* is the invariant the gate is built on.
|
|
64
|
+
*
|
|
65
|
+
* When the lexical answer says "outside", the question is asked again with the
|
|
66
|
+
* CANONICAL spelling of both sides, because one directory can be named two
|
|
67
|
+
* ways — a symlink, a junction, macOS's `/var` → `/private/var` — and then
|
|
68
|
+
* the lexical answer is a statement about the SPELLING, not about the
|
|
69
|
+
* directory. The retry can only turn "outside" into "inside", so the base it
|
|
70
|
+
* accepts is one that really is inside the project.
|
|
71
|
+
*/
|
|
72
|
+
function isInsideProject(root, dir) {
|
|
73
|
+
if (isInsideLexically(root, dir))
|
|
74
|
+
return true;
|
|
75
|
+
return isInsideLexically(stablePath(root), stablePath(dir));
|
|
76
|
+
}
|
|
61
77
|
/**
|
|
62
78
|
* The directory a relative target path is read against.
|
|
63
79
|
*
|
|
@@ -70,5 +70,25 @@ export declare function extractFilePath(input: Readonly<Record<string, unknown>>
|
|
|
70
70
|
* file a call writes is the one that directory names. It does not move the
|
|
71
71
|
* families - those stay relative to the project root - it only says which
|
|
72
72
|
* file the payload points at.
|
|
73
|
+
*
|
|
74
|
+
* THE VERDICT IS THE STRICTEST OF THE TWO READINGS. The path is read
|
|
75
|
+
* LEXICALLY - how it is written - and, when that reading has not already
|
|
76
|
+
* denied the file, CANONICALLY - where the file really is. A directory can
|
|
77
|
+
* be named two ways, and the difference is what a symlinked base looks like:
|
|
78
|
+
* a call that runs in `link/` and writes `deep/x.ts` lands in `src/deep/x.ts`
|
|
79
|
+
* when `link` points at `src`, and the lexical reading says `link/deep/x.ts`
|
|
80
|
+
* - no family at all. §18.1 rules that the verdict depends on WHICH
|
|
81
|
+
* DIRECTORY the file is in, not on how the path is written.
|
|
82
|
+
*
|
|
83
|
+
* Strictest, and not "canonical wins": making the canonical reading
|
|
84
|
+
* authoritative would WIDEN the gate in a layout this repository supports.
|
|
85
|
+
* When `src` is a symlink to `shared/src`, the lexical reading is
|
|
86
|
+
* `src/x.ts` (a family) and the canonical one is `shared/src/x.ts` (not
|
|
87
|
+
* one), and the file the gate denies today must stay denied. The tie-breaker
|
|
88
|
+
* is the repository's own: a wrongly ALLOWED edit is a hole, a wrongly
|
|
89
|
+
* REFUSED one is only an inconvenience. So a file reached through a
|
|
90
|
+
* directory NAMED `src` stays refused even when it really sits in `docs/` -
|
|
91
|
+
* the spelling is what the path says in this project's terms, and the gate
|
|
92
|
+
* refuses it rather than resolve it.
|
|
73
93
|
*/
|
|
74
94
|
export declare function decideGateAction(tool: GateToolName, input: Readonly<Record<string, unknown>>, driver?: string | null, roots?: GateRoots): GateVerdict;
|
|
@@ -18,7 +18,7 @@
|
|
|
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, rootPair } from './gate-path-normalize.js';
|
|
21
|
+
import { canonicalGatePath, normalizeGatePath, rootPair } from './gate-path-normalize.js';
|
|
22
22
|
export { normalizeGatePath };
|
|
23
23
|
/** Hard-blocked path families — orchestrator MUST NOT Edit/Write these. */
|
|
24
24
|
export const HARD_BLOCKED_PATH_FAMILIES = [
|
|
@@ -91,6 +91,40 @@ function matchesAny(path, families) {
|
|
|
91
91
|
}
|
|
92
92
|
return null;
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* The hard-blocked family a reading of the path names, or `null` when it
|
|
96
|
+
* names none.
|
|
97
|
+
*
|
|
98
|
+
* The ALLOW-LIST is read FIRST, for each reading on its own: a path the
|
|
99
|
+
* project allows is allowed, and a reading that names an allow-listed
|
|
100
|
+
* directory does not become a deny because ANOTHER reading names a family.
|
|
101
|
+
* That is what keeps `src/x.md` allowed, exactly as it was before.
|
|
102
|
+
*
|
|
103
|
+
* The family comparison folds CASE, because every family name is written in
|
|
104
|
+
* lower case and the filesystem holding the file may not be.
|
|
105
|
+
*/
|
|
106
|
+
function hardBlockedFamilyOf(reading) {
|
|
107
|
+
if (matchesAny(reading, ALLOW_LISTED_PATH_PATTERNS) !== null)
|
|
108
|
+
return null;
|
|
109
|
+
return matchesAny(reading, HARD_BLOCKED_PATH_FAMILIES);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The verdict for a file that one reading of the path placed in a
|
|
113
|
+
* hard-blocked family.
|
|
114
|
+
*
|
|
115
|
+
* A driver that is not the fast lane falls through to the same deny a
|
|
116
|
+
* two-argument call produces, so an unresolvable identity can never become a
|
|
117
|
+
* silent pass.
|
|
118
|
+
*/
|
|
119
|
+
function denyVerdict(family, requestedPath, driver) {
|
|
120
|
+
if (driver === FAST_LANE_DRIVER) {
|
|
121
|
+
return { action: 'allow' };
|
|
122
|
+
}
|
|
123
|
+
const reason = `${family} (orchestrator's hard-blocked path family)`;
|
|
124
|
+
const message = `PEAKS_CODE_PROHIBITED_DIRECT_EDIT: ${requestedPath} matches hard-blocked path family ${reason}; ` +
|
|
125
|
+
`orchestrator MUST NOT Edit/Write these directly. Use: peaks sub-agent dispatch rd --prompt '<your task>' --request-id <rid> --project . --batch-id <uuid>`;
|
|
126
|
+
return { action: 'deny', filePath: requestedPath, reason, message };
|
|
127
|
+
}
|
|
94
128
|
/**
|
|
95
129
|
* Pure decision function. Given the tool name + input object, return
|
|
96
130
|
* the gate verdict. Tolerates malformed payloads (allow).
|
|
@@ -116,6 +150,26 @@ function matchesAny(path, families) {
|
|
|
116
150
|
* file a call writes is the one that directory names. It does not move the
|
|
117
151
|
* families - those stay relative to the project root - it only says which
|
|
118
152
|
* file the payload points at.
|
|
153
|
+
*
|
|
154
|
+
* THE VERDICT IS THE STRICTEST OF THE TWO READINGS. The path is read
|
|
155
|
+
* LEXICALLY - how it is written - and, when that reading has not already
|
|
156
|
+
* denied the file, CANONICALLY - where the file really is. A directory can
|
|
157
|
+
* be named two ways, and the difference is what a symlinked base looks like:
|
|
158
|
+
* a call that runs in `link/` and writes `deep/x.ts` lands in `src/deep/x.ts`
|
|
159
|
+
* when `link` points at `src`, and the lexical reading says `link/deep/x.ts`
|
|
160
|
+
* - no family at all. §18.1 rules that the verdict depends on WHICH
|
|
161
|
+
* DIRECTORY the file is in, not on how the path is written.
|
|
162
|
+
*
|
|
163
|
+
* Strictest, and not "canonical wins": making the canonical reading
|
|
164
|
+
* authoritative would WIDEN the gate in a layout this repository supports.
|
|
165
|
+
* When `src` is a symlink to `shared/src`, the lexical reading is
|
|
166
|
+
* `src/x.ts` (a family) and the canonical one is `shared/src/x.ts` (not
|
|
167
|
+
* one), and the file the gate denies today must stay denied. The tie-breaker
|
|
168
|
+
* is the repository's own: a wrongly ALLOWED edit is a hole, a wrongly
|
|
169
|
+
* REFUSED one is only an inconvenience. So a file reached through a
|
|
170
|
+
* directory NAMED `src` stays refused even when it really sits in `docs/` -
|
|
171
|
+
* the spelling is what the path says in this project's terms, and the gate
|
|
172
|
+
* refuses it rather than resolve it.
|
|
119
173
|
*/
|
|
120
174
|
export function decideGateAction(tool, input, driver, roots) {
|
|
121
175
|
// Only gate Edit / Write / MultiEdit.
|
|
@@ -135,25 +189,21 @@ export function decideGateAction(tool, input, driver, roots) {
|
|
|
135
189
|
// echoes the path the tool actually asked for.
|
|
136
190
|
const pair = rootPair(roots);
|
|
137
191
|
const filePath = normalizeGatePath(requestedPath, pair.projectRoot, pair.toolCwd);
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return { action: 'allow' };
|
|
142
|
-
}
|
|
143
|
-
// Hard-blocked family check — case-insensitively, because every family name
|
|
144
|
-
// is lower-case and the filesystem holding the file may not be.
|
|
145
|
-
const denyMatch = matchesAny(filePath, HARD_BLOCKED_PATH_FAMILIES);
|
|
192
|
+
// The LEXICAL reading: the allow-list first — it short-circuits any deny,
|
|
193
|
+
// for every driver — and then the hard-blocked families.
|
|
194
|
+
const denyMatch = hardBlockedFamilyOf(filePath);
|
|
146
195
|
if (denyMatch !== null) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
196
|
+
return denyVerdict(denyMatch, requestedPath, driver ?? null);
|
|
197
|
+
}
|
|
198
|
+
// The CANONICAL reading, asked only when the lexical one has not already
|
|
199
|
+
// denied the file: it costs two filesystem lookups, and the file it names
|
|
200
|
+
// is the one the lexical reading could not place.
|
|
201
|
+
const canonical = canonicalGatePath(requestedPath, pair.projectRoot, pair.toolCwd);
|
|
202
|
+
if (canonical !== null) {
|
|
203
|
+
const canonicalMatch = hardBlockedFamilyOf(canonical);
|
|
204
|
+
if (canonicalMatch !== null) {
|
|
205
|
+
return denyVerdict(canonicalMatch, requestedPath, driver ?? null);
|
|
152
206
|
}
|
|
153
|
-
const reason = `${denyMatch} (orchestrator's hard-blocked path family)`;
|
|
154
|
-
const message = `PEAKS_CODE_PROHIBITED_DIRECT_EDIT: ${requestedPath} matches hard-blocked path family ${reason}; ` +
|
|
155
|
-
`orchestrator MUST NOT Edit/Write these directly. Use: peaks sub-agent dispatch rd --prompt '<your task>' --request-id <rid> --project . --batch-id <uuid>`;
|
|
156
|
-
return { action: 'deny', filePath: requestedPath, reason, message };
|
|
157
207
|
}
|
|
158
208
|
// Anything not in the deny list → allow (e.g. CHANGELOG, README, top-level files).
|
|
159
209
|
return { action: 'allow' };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peaks-loop",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.17",
|
|
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-
|
|
133
|
-
"peaks-loop-shared": "0.0.
|
|
134
|
-
"peaks-loop-shared-channel": "0.0.
|
|
135
|
-
"peaks-loop-
|
|
132
|
+
"peaks-loop-internal-runtime": "0.0.57",
|
|
133
|
+
"peaks-loop-shared": "0.0.106",
|
|
134
|
+
"peaks-loop-shared-channel": "0.0.74",
|
|
135
|
+
"peaks-loop-mut": "0.1.71"
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
138
|
"@changesets/cli": "2.31.1",
|