dsh-workplan 1.12.1 → 1.12.2
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 +32 -0
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/host.js +46 -3
- package/lib/runtime.js +74 -5
- package/package.json +1 -1
- package/src/host.ts +46 -4
- package/src/runtime.ts +71 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
## 1.12.2 — 2026-11-04
|
|
2
|
+
|
|
3
|
+
**修好 G1/G2/G3 三个写保护漏洞(1.12.1 只记录了缺口)。这是一次有意的行为变更:已交付文件的写保护现在真正无死角,且不再区分「谁在写」。**
|
|
4
|
+
|
|
5
|
+
### 一、修了什么(三个漏洞,逐条)
|
|
6
|
+
|
|
7
|
+
| 编号 | 1.12.1 的状态 | 1.12.2 的修法 | 代码位置 |
|
|
8
|
+
|---|---|---|---|
|
|
9
|
+
| **G1** 子 Agent 不受保护 | 非根会话直接放行:「门卫只认户主,保姆拿钥匙能进」 | 去掉角色判断。已交付文件在计划未就绪期间不得被原地改写,**与谁在写无关**。 | `src/runtime.ts` `presentedWriteDenialReason` |
|
|
10
|
+
| **G2** 只认三个工具名 | 只接管 write / edit / str_replace_editor,第四个写工具(如 `apply_patch`)根本不进闸门 | 改为**按参数形状识别**写操作:带 `file_path`/`path`,或 patch 文本含 `*** Update/Add/Delete File:`。一次调用含多个文件时,只要有任一命中就整单拒绝。读类工具显式白名单排除。 | `src/host.ts` `fileWriteGuardReason` / `isWriteShapedCall`;`src/runtime.ts` `writeTargets` |
|
|
11
|
+
| **G3** 符号链接绕过 | 只做 `path.resolve`,`/link/report.md` 与 `/real/report.md` 被当成两个文件 | 两侧都归一到**真实文件身份**(`realpath.native`)。交付链接、写真实路径(或反之)都能认出来。文件尚不存在时解析最近的存在祖先;完全解析不了时退回旧行为。 | `src/runtime.ts` `realPathIdentity` / `identityPath` |
|
|
12
|
+
|
|
13
|
+
### 二、行为影响(会影响现有使用的部分,务必读完)
|
|
14
|
+
|
|
15
|
+
1. **子 Agent 写已交付文件会被拒绝**(G1)。以前后台子 Agent 能改掉用户手上那份报告,现在与主 Agent 同等对待。**present 仍只有主会话可用**,所以「交付能力」没有扩大,只是「改写已交付文件」的口子被堵上。
|
|
16
|
+
2. **更多工具名进入写保护**(G2)。过去改一个名字(如 `apply_patch`、`write_file`)就能绕过的写法,现在同样被拦;一次 patch 改动多个文件时,只要有一个是已交付文件就整单拒绝。
|
|
17
|
+
3. **符号链接不再是第二种写法**(G3)。通过软链接路径改写已交付文件会被拦下,报错文案与直接路径完全一致。
|
|
18
|
+
4. **照旧保留的出路**:计划交付就绪后放行;计划被 `dsh_workplan_cancel` 显式取消后放行;present 之后才新建的计划不受限制;plan 模式下写保护不生效。
|
|
19
|
+
5. **没有削弱的权限**:其余 8 处 `NOT_ROOT` 校验(子 Agent 不能 update / replan / cancel / dispatch 主计划、不能下发指示、不能处置跨部门需求、不能补发 follow-up、不能 present)**一处未动**。那是「子 Agent 不能改计划」的权限,与「不能改文件」是两件事。
|
|
20
|
+
|
|
21
|
+
### 三、验证(双向红绿,不是只跑一次绿)
|
|
22
|
+
|
|
23
|
+
- **修复前**(换回 1.12.1 的 `src/runtime.ts` + `src/host.ts`):`tests 498 / pass 491 / fail 7`,失败项正是 6 条 G1/G2/G3 新用例 + 1 条既有契约用例。
|
|
24
|
+
- **修复后**:`tests 498 / pass 498 / fail 0`,退出码 0;`npm run check`(tsc --noEmit)退出码 0。
|
|
25
|
+
- 用例数构成:基线 495 + G1 一条 + G2 一条 + G3 反向一条 = 498。
|
|
26
|
+
- 三条原本「钉住缺口」的用例已翻转成「钉住修复」:`p03-m1-write-guard-gaps.test.ts` 的 G3 条、`p03-m1-guard-gating-gaps.test.ts` 的 G1/G2 条、以及既有契约 `workplan-presented-write-guard.test.ts` 中「非根会话放行」的断言。
|
|
27
|
+
|
|
28
|
+
### 四、事实边界(不得外推)
|
|
29
|
+
|
|
30
|
+
- 真实模型在 20 条任务上的通过率**未被本版刷新**,仍为 2026-11-03 的 `pass 4/20`。原因:模型密钥 4 个环境变量全空 + 工作区外写配置权限缺失,20 条真实模型验证无法在本轮重跑。
|
|
31
|
+
- 1.12.2 是**代码级修复 + 回归验证**的结论,不代表 20 条真实模型任务的表现有任何变化。
|
|
32
|
+
|
|
1
33
|
## 1.12.1 — 2026-11-04
|
|
2
34
|
|
|
3
35
|
**补强任务理解的三处漏判:部门覆盖硬校验、指代先行词核实、写保护缺口固化测试。**
|
package/README.en.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **Two selling points, one line: a full ISO/IEC 15408:2026 evidence pack you can verify with 5 commands, and a one-command install with zero runtime dependencies.**
|
|
4
4
|
|
|
5
5
|
[](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml)
|
|
6
|
-
[](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.2)
|
|
7
7
|
|
|
8
8
|
Adds "plan first → dispatch real department subagents → watch progress in the sidebar" to **DeepSeek Harness (DSH)**. No app, no DSH source patch, no page replacement.
|
|
9
9
|
|
|
@@ -80,7 +80,7 @@ The full contract — roles, data shapes, state machine, recovery, and the three
|
|
|
80
80
|
## Install
|
|
81
81
|
|
|
82
82
|
```bash
|
|
83
|
-
dsh plugin --profile web add dsh-workplan@1.12.
|
|
83
|
+
dsh plugin --profile web add dsh-workplan@1.12.2
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
Restart the DSH Web process (or reload the page) so the bundle is picked up.
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **两个卖点,一句话:ISO/IEC 15408:2026 全套安全证据,5 条命令自己验;安装一条命令、零第三方运行时依赖。**
|
|
4
4
|
|
|
5
5
|
[](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml)
|
|
6
|
-
[](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.2)
|
|
7
7
|
|
|
8
8
|
给 **DeepSeek Harness(DSH)** 加一段「先拆计划 → 真派部门子 Agent 去做 → 左侧栏实时看进度」的能力。不装 App、不改 DSH 源码、不换页面。
|
|
9
9
|
|
|
@@ -69,7 +69,7 @@ grep -RInE "child_process|execSync|eval\(|writeFileSync" src || echo "0 命中
|
|
|
69
69
|
## 一键安装
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
dsh plugin --profile web add dsh-workplan@1.12.
|
|
72
|
+
dsh plugin --profile web add dsh-workplan@1.12.2
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
装完**重启一次 DSH Web**(或重新载入当前页面)让插件生效。
|
package/README.zh.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **两个卖点,一句话:ISO/IEC 15408:2026 全套安全证据,5 条命令自己验;安装一条命令、零第三方运行时依赖。**
|
|
4
4
|
|
|
5
5
|
[](https://github.com/abbaababa/dsh-workplan/actions/workflows/verify.yml)
|
|
6
|
-
[](https://github.com/abbaababa/dsh-workplan/releases/tag/v1.12.2)
|
|
7
7
|
|
|
8
8
|
给 **DeepSeek Harness(DSH)** 加一段「先拆计划 → 真派部门子 Agent 去做 → 左侧栏实时看进度」的能力。不装 App、不改 DSH 源码、不换页面。
|
|
9
9
|
|
|
@@ -69,7 +69,7 @@ grep -RInE "child_process|execSync|eval\(|writeFileSync" src || echo "0 命中
|
|
|
69
69
|
## 一键安装
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
dsh plugin --profile web add dsh-workplan@1.12.
|
|
72
|
+
dsh plugin --profile web add dsh-workplan@1.12.2
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
装完**重启一次 DSH Web**(或重新载入当前页面)让插件生效。
|
package/lib/host.js
CHANGED
|
@@ -1146,7 +1146,7 @@ export function apply(ctx, config = {}) {
|
|
|
1146
1146
|
}
|
|
1147
1147
|
export const meta = {
|
|
1148
1148
|
name,
|
|
1149
|
-
version: '1.12.
|
|
1149
|
+
version: '1.12.2',
|
|
1150
1150
|
promptOrder: PROMPT_ORDER,
|
|
1151
1151
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
1152
1152
|
};
|
|
@@ -1159,7 +1159,50 @@ export { PROMPT_SECTION, createCancelTool, createDispatchTool, createEscalateToo
|
|
|
1159
1159
|
* 取第一个非空原因,互不覆盖。
|
|
1160
1160
|
*/
|
|
1161
1161
|
export function fileWriteGuardReason(exec, runtime) {
|
|
1162
|
-
if (exec
|
|
1162
|
+
if (!isWriteShapedCall(exec))
|
|
1163
1163
|
return undefined;
|
|
1164
|
-
|
|
1164
|
+
// The three historical write tools pass their arguments through untouched, so
|
|
1165
|
+
// their behaviour stays exactly as before (argument-shape matching is only an
|
|
1166
|
+
// EXTENSION: a tool that used to be denied is still denied the same way).
|
|
1167
|
+
const direct = exec?.name === 'write' || exec?.name === 'edit' || exec?.name === 'str_replace_editor';
|
|
1168
|
+
const reason = direct ? runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments) : undefined;
|
|
1169
|
+
if (typeof reason === 'string')
|
|
1170
|
+
return reason;
|
|
1171
|
+
// [1.12.2] G2: a single call can touch several files (apply_patch hunks).
|
|
1172
|
+
// Deny the call as a whole if any of its targets is a protected deliverable.
|
|
1173
|
+
for (const target of runtime.writeTargets(exec?.agent, exec?.arguments) ?? []) {
|
|
1174
|
+
const extra = runtime.presentedWriteDenialReason(exec?.agent, { file_path: target });
|
|
1175
|
+
if (typeof extra === 'string')
|
|
1176
|
+
return extra;
|
|
1177
|
+
}
|
|
1178
|
+
return undefined;
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* [1.12.2] G2: recognise write calls by their argument shape, not by a tool-name
|
|
1182
|
+
* allow-list. The 1.8.18 version named write/edit/str_replace_editor only, so a
|
|
1183
|
+
* fourth write tool such as apply_patch never reached the guard at all.
|
|
1184
|
+
*
|
|
1185
|
+
* Shape rule: a path/first positional argument PLUS a content-bearing argument
|
|
1186
|
+
* (content, file_text, new_str, old_string, patch, input). read/read_image/
|
|
1187
|
+
* present/glob/grep carry no such pair, so they stay untouched.
|
|
1188
|
+
*/
|
|
1189
|
+
const READ_ONLY_TOOLS = new Set([
|
|
1190
|
+
'read', 'read_image', 'glob', 'grep', 'ls', 'list', 'list_dir',
|
|
1191
|
+
'present', 'todo_write', 'ask_user_question',
|
|
1192
|
+
]);
|
|
1193
|
+
function isWriteShapedCall(exec) {
|
|
1194
|
+
const name = exec?.name;
|
|
1195
|
+
if (typeof name !== 'string' || !name)
|
|
1196
|
+
return false;
|
|
1197
|
+
const args = exec?.arguments;
|
|
1198
|
+
if (!args || typeof args !== 'object')
|
|
1199
|
+
return false;
|
|
1200
|
+
// Read-only tools also carry file_path/path; the guard must never touch them.
|
|
1201
|
+
if (READ_ONLY_TOOLS.has(name))
|
|
1202
|
+
return false;
|
|
1203
|
+
// A patch tool names its target(s) inside the patch text, not in an argument.
|
|
1204
|
+
if (typeof args.input === 'string' && /\*\*\* (Update|Add|Delete|Move) File/.test(args.input))
|
|
1205
|
+
return true;
|
|
1206
|
+
// Every other write form names a single target: file_path or path.
|
|
1207
|
+
return typeof args.file_path === 'string' || typeof args.path === 'string';
|
|
1165
1208
|
}
|
package/lib/runtime.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* in this file is allowed to escape as an unhandled rejection from a listener.
|
|
13
13
|
*/
|
|
14
14
|
import { randomUUID } from 'node:crypto';
|
|
15
|
-
import { existsSync, statSync } from 'node:fs';
|
|
16
|
-
import { isAbsolute, resolve } from 'node:path';
|
|
15
|
+
import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
16
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
17
17
|
import { MAX_CONCURRENT, PlanError, aggregateInvariantViolations, applyStatus, attachPlanMeta, blockCancelledDependents, buildChildPrompt, buildCancelMessage, buildDegradedMessage, buildPlanMessage, buildPlannerPrompt, buildResultMessage, buildStopSteerText, createStatuses, deliveryReadiness, derivePlanSnapshot, extractJson, flattenSubtasks, isRecord, isSocialMessage, isTerminalPhase, isStatusQuestion, isVagueContinuation, makeUserMessage, markDependentsBlocked, messageText, readySubtasks, MAX_PLAN_RESUMES, PRESENT_DENY_CODES, canResumePlan, resetBlockedStatuses, parseCancelMessage, parseResultMessage, parseWorkplanMessage, planPhase, reconcilePhase, truncate, validatePlan, applyResultStatuses, adjudicateResult, activeDenyCode, MAX_CONVERSATION_CHARS, MAX_ESCALATION_OPTIONS, MAX_INSTRUCTION_CHARS, MAX_QUESTION_CHARS, parseUpdateMessage, buildUpdateMessage, normaliseHandoffs, openHandoffs, DEPARTMENTS, DEPARTMENT_IDS, MAX_HANDOFF_RESPONSE_CHARS, } from './plan.js';
|
|
18
18
|
import { compactUnderstandingAudit, validatePlanContext } from './understanding.js';
|
|
19
19
|
import { computeMappingDigest, verifyMappingDigest } from './supersede-digest.js';
|
|
@@ -5374,6 +5374,38 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5374
5374
|
* 集合里,所以“用户要求改版 → 新计划”不会被写保护卡死;cancel 仍是显式出路。
|
|
5375
5375
|
*/
|
|
5376
5376
|
const presentedPaths = new Map();
|
|
5377
|
+
/*
|
|
5378
|
+
* [1.12.2] G3 修复:符号链接必须归一到同一个文件。
|
|
5379
|
+
* 1.8.18 的 canonicalPath 只做 path.resolve,同一个文件因此有无限种写法——
|
|
5380
|
+
* 交付的是 /a/report.md,改 /link/report.md(link 指向 a)就被放过。
|
|
5381
|
+
* 这里再用 realpath.native 把路径解析成真实身份,两侧都解析才能比对。
|
|
5382
|
+
* 文件尚不存在时解析最近的存在祖先后拼回剩余段落;完全解析不了时
|
|
5383
|
+
* 返回 undefined,调用方回落到旧的 path.resolve 结果(不改变旧行为)。
|
|
5384
|
+
*/
|
|
5385
|
+
function realPathIdentity(value) {
|
|
5386
|
+
try {
|
|
5387
|
+
return realpathSync.native(value);
|
|
5388
|
+
}
|
|
5389
|
+
catch {
|
|
5390
|
+
// 文件可能尚未创建,继续找最近的存在祖先。
|
|
5391
|
+
}
|
|
5392
|
+
let cursor = value;
|
|
5393
|
+
const tail = [];
|
|
5394
|
+
for (let depth = 0; depth < 64; depth += 1) {
|
|
5395
|
+
const parent = dirname(cursor);
|
|
5396
|
+
if (!parent || parent === cursor)
|
|
5397
|
+
return undefined;
|
|
5398
|
+
tail.unshift(basename(cursor));
|
|
5399
|
+
cursor = parent;
|
|
5400
|
+
try {
|
|
5401
|
+
return join(realpathSync.native(cursor), ...tail);
|
|
5402
|
+
}
|
|
5403
|
+
catch {
|
|
5404
|
+
// 继续向上。
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
return undefined;
|
|
5408
|
+
}
|
|
5377
5409
|
function canonicalPath(session, value) {
|
|
5378
5410
|
if (typeof value !== 'string' || value.trim() === '')
|
|
5379
5411
|
return undefined;
|
|
@@ -5382,6 +5414,12 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5382
5414
|
const cwd = session?.header?.cwd ?? options.cwd;
|
|
5383
5415
|
return typeof cwd === 'string' && cwd ? resolve(cwd, value) : undefined;
|
|
5384
5416
|
}
|
|
5417
|
+
function identityPath(session, value) {
|
|
5418
|
+
const canonical = canonicalPath(session, value);
|
|
5419
|
+
if (canonical === undefined)
|
|
5420
|
+
return undefined;
|
|
5421
|
+
return realPathIdentity(canonical) ?? canonical;
|
|
5422
|
+
}
|
|
5385
5423
|
function presentedEntries(session) {
|
|
5386
5424
|
if (typeof session?.eventAt !== 'function' || !(Number(session.seq) >= 0))
|
|
5387
5425
|
return [];
|
|
@@ -5412,7 +5450,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5412
5450
|
for (const file of event.data?.files ?? []) {
|
|
5413
5451
|
if (typeof file?.path !== 'string' || file.path.trim() === '')
|
|
5414
5452
|
continue;
|
|
5415
|
-
entries.push({ raw: file.path, canonical:
|
|
5453
|
+
entries.push({ raw: file.path, canonical: identityPath(session, file.path), planIds });
|
|
5416
5454
|
}
|
|
5417
5455
|
}
|
|
5418
5456
|
presentedPaths.set(session.id, {
|
|
@@ -5430,7 +5468,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5430
5468
|
}
|
|
5431
5469
|
function presentedWriteDenialReason(agent, args) {
|
|
5432
5470
|
const session = agent?.session;
|
|
5433
|
-
if (!session
|
|
5471
|
+
if (!session)
|
|
5434
5472
|
return undefined;
|
|
5435
5473
|
if (isPlanModeActive(ctx, session))
|
|
5436
5474
|
return undefined;
|
|
@@ -5440,8 +5478,15 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5440
5478
|
const requested = args?.file_path ?? args?.path;
|
|
5441
5479
|
if (typeof requested !== 'string' || requested.trim() === '')
|
|
5442
5480
|
return undefined;
|
|
5443
|
-
|
|
5481
|
+
// [1.12.2] G3: compare by real file identity (symlinks resolved).
|
|
5482
|
+
const canonical = identityPath(session, requested);
|
|
5483
|
+
/*
|
|
5484
|
+
* [1.12.2] G3: compare like-for-like. The entry now holds the real identity
|
|
5485
|
+
* of the presented path, so a link delivered earlier and a write through
|
|
5486
|
+
* the real path (or vice versa) resolve to the same string.
|
|
5487
|
+
*/
|
|
5444
5488
|
const matched = entries.filter((entry) => entry.raw === requested
|
|
5489
|
+
|| (entry.raw !== undefined && identityPath(session, entry.raw) === canonical)
|
|
5445
5490
|
|| (canonical !== undefined && entry.canonical !== undefined && entry.canonical === canonical));
|
|
5446
5491
|
if (matched.length === 0)
|
|
5447
5492
|
return undefined;
|
|
@@ -5465,6 +5510,29 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5465
5510
|
+ '完成后重新 present 新版本;确实不做的计划用 dsh_workplan_cancel 显式取消。'
|
|
5466
5511
|
+ '(present 之后新建的计划不受此限制。)';
|
|
5467
5512
|
}
|
|
5513
|
+
/**
|
|
5514
|
+
* [1.12.2] G2: every path a single write call can touch.
|
|
5515
|
+
* apply_patch carries many files in one string; parsing the directives here
|
|
5516
|
+
* lets the guard deny the whole call instead of letting an unrelated path
|
|
5517
|
+
* in the arguments form a blind spot.
|
|
5518
|
+
*/
|
|
5519
|
+
function writeTargets(_agent, args) {
|
|
5520
|
+
const targets = [];
|
|
5521
|
+
const single = args?.file_path ?? args?.path;
|
|
5522
|
+
if (typeof single === 'string' && single.trim() !== '')
|
|
5523
|
+
targets.push(single);
|
|
5524
|
+
const patch = typeof args?.input === 'string' ? args.input : (typeof args?.patch === 'string' ? args.patch : '');
|
|
5525
|
+
if (patch) {
|
|
5526
|
+
const directive = /^\*\*\* (?:Update File|Add File|Delete File|Move to): (.+)$/gm;
|
|
5527
|
+
let match;
|
|
5528
|
+
while ((match = directive.exec(patch)) !== null) {
|
|
5529
|
+
const path = match[1].trim();
|
|
5530
|
+
if (path !== '')
|
|
5531
|
+
targets.push(path);
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
return targets;
|
|
5535
|
+
}
|
|
5468
5536
|
function plansPayload(sessionId) {
|
|
5469
5537
|
/*
|
|
5470
5538
|
* [1.8.15] The feed must carry build identity too.
|
|
@@ -5558,6 +5626,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5558
5626
|
presentDenialVerdict,
|
|
5559
5627
|
supersededDenialVerdict,
|
|
5560
5628
|
presentedWriteDenialReason,
|
|
5629
|
+
writeTargets,
|
|
5561
5630
|
updateStatus,
|
|
5562
5631
|
cancelPlan,
|
|
5563
5632
|
dispatchTool,
|
package/package.json
CHANGED
package/src/host.ts
CHANGED
|
@@ -1255,7 +1255,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
1255
1255
|
|
|
1256
1256
|
export const meta = {
|
|
1257
1257
|
name,
|
|
1258
|
-
version: '1.12.
|
|
1258
|
+
version: '1.12.2',
|
|
1259
1259
|
promptOrder: PROMPT_ORDER,
|
|
1260
1260
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
1261
1261
|
}
|
|
@@ -1271,8 +1271,50 @@ export { PROMPT_SECTION, createCancelTool, createDispatchTool, createEscalateToo
|
|
|
1271
1271
|
*/
|
|
1272
1272
|
export function fileWriteGuardReason(
|
|
1273
1273
|
exec: any,
|
|
1274
|
-
runtime: {
|
|
1274
|
+
runtime: {
|
|
1275
|
+
presentedWriteDenialReason(agent: any, args: any): string | undefined
|
|
1276
|
+
writeTargets(agent: any, args: any): string[]
|
|
1277
|
+
},
|
|
1275
1278
|
) {
|
|
1276
|
-
if (exec
|
|
1277
|
-
|
|
1279
|
+
if (!isWriteShapedCall(exec)) return undefined
|
|
1280
|
+
// The three historical write tools pass their arguments through untouched, so
|
|
1281
|
+
// their behaviour stays exactly as before (argument-shape matching is only an
|
|
1282
|
+
// EXTENSION: a tool that used to be denied is still denied the same way).
|
|
1283
|
+
const direct = exec?.name === 'write' || exec?.name === 'edit' || exec?.name === 'str_replace_editor'
|
|
1284
|
+
const reason = direct ? runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments) : undefined
|
|
1285
|
+
if (typeof reason === 'string') return reason
|
|
1286
|
+
// [1.12.2] G2: a single call can touch several files (apply_patch hunks).
|
|
1287
|
+
// Deny the call as a whole if any of its targets is a protected deliverable.
|
|
1288
|
+
for (const target of runtime.writeTargets(exec?.agent, exec?.arguments) ?? []) {
|
|
1289
|
+
const extra = runtime.presentedWriteDenialReason(exec?.agent, { file_path: target })
|
|
1290
|
+
if (typeof extra === 'string') return extra
|
|
1291
|
+
}
|
|
1292
|
+
return undefined
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
/**
|
|
1296
|
+
* [1.12.2] G2: recognise write calls by their argument shape, not by a tool-name
|
|
1297
|
+
* allow-list. The 1.8.18 version named write/edit/str_replace_editor only, so a
|
|
1298
|
+
* fourth write tool such as apply_patch never reached the guard at all.
|
|
1299
|
+
*
|
|
1300
|
+
* Shape rule: a path/first positional argument PLUS a content-bearing argument
|
|
1301
|
+
* (content, file_text, new_str, old_string, patch, input). read/read_image/
|
|
1302
|
+
* present/glob/grep carry no such pair, so they stay untouched.
|
|
1303
|
+
*/
|
|
1304
|
+
const READ_ONLY_TOOLS = new Set([
|
|
1305
|
+
'read', 'read_image', 'glob', 'grep', 'ls', 'list', 'list_dir',
|
|
1306
|
+
'present', 'todo_write', 'ask_user_question',
|
|
1307
|
+
])
|
|
1308
|
+
|
|
1309
|
+
function isWriteShapedCall(exec: any) {
|
|
1310
|
+
const name = exec?.name
|
|
1311
|
+
if (typeof name !== 'string' || !name) return false
|
|
1312
|
+
const args = exec?.arguments
|
|
1313
|
+
if (!args || typeof args !== 'object') return false
|
|
1314
|
+
// Read-only tools also carry file_path/path; the guard must never touch them.
|
|
1315
|
+
if (READ_ONLY_TOOLS.has(name)) return false
|
|
1316
|
+
// A patch tool names its target(s) inside the patch text, not in an argument.
|
|
1317
|
+
if (typeof args.input === 'string' && /\*\*\* (Update|Add|Delete|Move) File/.test(args.input)) return true
|
|
1318
|
+
// Every other write form names a single target: file_path or path.
|
|
1319
|
+
return typeof args.file_path === 'string' || typeof args.path === 'string'
|
|
1278
1320
|
}
|
package/src/runtime.ts
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { randomUUID } from 'node:crypto'
|
|
16
|
-
import { existsSync, statSync } from 'node:fs'
|
|
17
|
-
import { isAbsolute, resolve } from 'node:path'
|
|
16
|
+
import { existsSync, realpathSync, statSync } from 'node:fs'
|
|
17
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
20
|
MAX_CONCURRENT,
|
|
@@ -5397,6 +5397,36 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5397
5397
|
entries: Array<{ raw: string; canonical?: string; planIds: string[] }>
|
|
5398
5398
|
}>()
|
|
5399
5399
|
|
|
5400
|
+
/*
|
|
5401
|
+
* [1.12.2] G3 修复:符号链接必须归一到同一个文件。
|
|
5402
|
+
* 1.8.18 的 canonicalPath 只做 path.resolve,同一个文件因此有无限种写法——
|
|
5403
|
+
* 交付的是 /a/report.md,改 /link/report.md(link 指向 a)就被放过。
|
|
5404
|
+
* 这里再用 realpath.native 把路径解析成真实身份,两侧都解析才能比对。
|
|
5405
|
+
* 文件尚不存在时解析最近的存在祖先后拼回剩余段落;完全解析不了时
|
|
5406
|
+
* 返回 undefined,调用方回落到旧的 path.resolve 结果(不改变旧行为)。
|
|
5407
|
+
*/
|
|
5408
|
+
function realPathIdentity(value: string) {
|
|
5409
|
+
try {
|
|
5410
|
+
return realpathSync.native(value)
|
|
5411
|
+
} catch {
|
|
5412
|
+
// 文件可能尚未创建,继续找最近的存在祖先。
|
|
5413
|
+
}
|
|
5414
|
+
let cursor = value
|
|
5415
|
+
const tail: string[] = []
|
|
5416
|
+
for (let depth = 0; depth < 64; depth += 1) {
|
|
5417
|
+
const parent = dirname(cursor)
|
|
5418
|
+
if (!parent || parent === cursor) return undefined
|
|
5419
|
+
tail.unshift(basename(cursor))
|
|
5420
|
+
cursor = parent
|
|
5421
|
+
try {
|
|
5422
|
+
return join(realpathSync.native(cursor), ...tail)
|
|
5423
|
+
} catch {
|
|
5424
|
+
// 继续向上。
|
|
5425
|
+
}
|
|
5426
|
+
}
|
|
5427
|
+
return undefined
|
|
5428
|
+
}
|
|
5429
|
+
|
|
5400
5430
|
function canonicalPath(session: any, value: any) {
|
|
5401
5431
|
if (typeof value !== 'string' || value.trim() === '') return undefined
|
|
5402
5432
|
if (isAbsolute(value)) return resolve(value)
|
|
@@ -5404,6 +5434,12 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5404
5434
|
return typeof cwd === 'string' && cwd ? resolve(cwd, value) : undefined
|
|
5405
5435
|
}
|
|
5406
5436
|
|
|
5437
|
+
function identityPath(session: any, value: any) {
|
|
5438
|
+
const canonical = canonicalPath(session, value)
|
|
5439
|
+
if (canonical === undefined) return undefined
|
|
5440
|
+
return realPathIdentity(canonical) ?? canonical
|
|
5441
|
+
}
|
|
5442
|
+
|
|
5407
5443
|
function presentedEntries(session: any) {
|
|
5408
5444
|
if (typeof session?.eventAt !== 'function' || !(Number(session.seq) >= 0)) return []
|
|
5409
5445
|
const cache = presentedPaths.get(session.id)
|
|
@@ -5428,7 +5464,7 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5428
5464
|
const planIds = [...seen]
|
|
5429
5465
|
for (const file of event.data?.files ?? []) {
|
|
5430
5466
|
if (typeof file?.path !== 'string' || file.path.trim() === '') continue
|
|
5431
|
-
entries.push({ raw: file.path, canonical:
|
|
5467
|
+
entries.push({ raw: file.path, canonical: identityPath(session, file.path), planIds })
|
|
5432
5468
|
}
|
|
5433
5469
|
}
|
|
5434
5470
|
presentedPaths.set(session.id, {
|
|
@@ -5447,15 +5483,22 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5447
5483
|
|
|
5448
5484
|
function presentedWriteDenialReason(agent: any, args: any) {
|
|
5449
5485
|
const session = agent?.session
|
|
5450
|
-
if (!session
|
|
5486
|
+
if (!session) return undefined
|
|
5451
5487
|
if (isPlanModeActive(ctx, session)) return undefined
|
|
5452
5488
|
const entries = presentedEntries(session)
|
|
5453
5489
|
if (entries.length === 0) return undefined
|
|
5454
5490
|
const requested = args?.file_path ?? args?.path
|
|
5455
5491
|
if (typeof requested !== 'string' || requested.trim() === '') return undefined
|
|
5456
|
-
|
|
5492
|
+
// [1.12.2] G3: compare by real file identity (symlinks resolved).
|
|
5493
|
+
const canonical = identityPath(session, requested)
|
|
5494
|
+
/*
|
|
5495
|
+
* [1.12.2] G3: compare like-for-like. The entry now holds the real identity
|
|
5496
|
+
* of the presented path, so a link delivered earlier and a write through
|
|
5497
|
+
* the real path (or vice versa) resolve to the same string.
|
|
5498
|
+
*/
|
|
5457
5499
|
const matched = entries.filter((entry: any) =>
|
|
5458
5500
|
entry.raw === requested
|
|
5501
|
+
|| (entry.raw !== undefined && identityPath(session, entry.raw) === canonical)
|
|
5459
5502
|
|| (canonical !== undefined && entry.canonical !== undefined && entry.canonical === canonical))
|
|
5460
5503
|
if (matched.length === 0) return undefined
|
|
5461
5504
|
const planIds = new Set<string>()
|
|
@@ -5475,6 +5518,28 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5475
5518
|
+ '(present 之后新建的计划不受此限制。)'
|
|
5476
5519
|
}
|
|
5477
5520
|
|
|
5521
|
+
/**
|
|
5522
|
+
* [1.12.2] G2: every path a single write call can touch.
|
|
5523
|
+
* apply_patch carries many files in one string; parsing the directives here
|
|
5524
|
+
* lets the guard deny the whole call instead of letting an unrelated path
|
|
5525
|
+
* in the arguments form a blind spot.
|
|
5526
|
+
*/
|
|
5527
|
+
function writeTargets(_agent: any, args: any): string[] {
|
|
5528
|
+
const targets: string[] = []
|
|
5529
|
+
const single = args?.file_path ?? args?.path
|
|
5530
|
+
if (typeof single === 'string' && single.trim() !== '') targets.push(single)
|
|
5531
|
+
const patch = typeof args?.input === 'string' ? args.input : (typeof args?.patch === 'string' ? args.patch : '')
|
|
5532
|
+
if (patch) {
|
|
5533
|
+
const directive = /^\*\*\* (?:Update File|Add File|Delete File|Move to): (.+)$/gm
|
|
5534
|
+
let match
|
|
5535
|
+
while ((match = directive.exec(patch)) !== null) {
|
|
5536
|
+
const path = match[1].trim()
|
|
5537
|
+
if (path !== '') targets.push(path)
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5540
|
+
return targets
|
|
5541
|
+
}
|
|
5542
|
+
|
|
5478
5543
|
function plansPayload(sessionId: any) {
|
|
5479
5544
|
/*
|
|
5480
5545
|
* [1.8.15] The feed must carry build identity too.
|
|
@@ -5567,6 +5632,7 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5567
5632
|
presentDenialVerdict,
|
|
5568
5633
|
supersededDenialVerdict,
|
|
5569
5634
|
presentedWriteDenialReason,
|
|
5635
|
+
writeTargets,
|
|
5570
5636
|
updateStatus,
|
|
5571
5637
|
cancelPlan,
|
|
5572
5638
|
dispatchTool,
|