kcode-pi 0.1.42 → 0.1.43
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.
|
@@ -148,6 +148,7 @@ export const PROJECT_PERSISTENT_RULES = [
|
|
|
148
148
|
"提示语集中管理为正式工程指令;禁止口语化、闲聊式、鼓励式提示词进入运行时规则。",
|
|
149
149
|
"工具使用必须匹配当前会话实际可用工具和操作系统;Windows 默认使用 PowerShell、`rg`、`Get-ChildItem`、`Get-Content`,禁止假设 bash 可用。",
|
|
150
150
|
"Windows 查找文件和目录时优先使用 `kd_find_file`、`kd_list_dir` 或 PowerShell;禁止用 Linux find/ls 语法反复调用 Pi 内置 bash。",
|
|
151
|
+
"写入或编辑文件时禁止使用当前工作区外的绝对路径;生产源码必须使用当前业务项目相对路径,并受 PLAN.md 批准文件约束。",
|
|
151
152
|
"文件定位必须使用真实搜索或目录读取结果;工具不可用时明确说明阻塞原因和需要用户执行的命令,禁止猜测路径、反复自述工具失败或用 kd_subagent 代替基础文件搜索。",
|
|
152
153
|
"不做旧状态迁移兼容或旧问题答案推断;坏状态只过滤,缺失事实必须重新提问确认。",
|
|
153
154
|
];
|
|
@@ -192,6 +193,7 @@ export const PROMPT_PROHIBITED_BEHAVIORS = [
|
|
|
192
193
|
"禁止一次性向用户索要多项业务信息。",
|
|
193
194
|
"禁止重复询问已确认事实或已存在 open blocking question 的问题。",
|
|
194
195
|
"禁止猜测路径、包名、类名、FormId、字段、实体、SQL 表名、数据库字段名或接口字段映射。",
|
|
196
|
+
"禁止写入或编辑当前工作区外的绝对路径。",
|
|
195
197
|
"禁止用子 agent、shell 失败自述或自由文本计划绕过门禁。",
|
|
196
198
|
"禁止将外部系统操作、BOS 注册、人工功能测试或生产验证描述为 LLM 已完成。",
|
|
197
199
|
];
|
|
@@ -210,7 +212,7 @@ export const CORE_WORKFLOW_CONSTRAINTS = [
|
|
|
210
212
|
"Java/Cosmic 使用当前项目 Gradle;C#/企业版使用 dotnet build。",
|
|
211
213
|
"evidence 必须记录命令、Exit 和关键输出;命令无法运行时记录阻塞原因。",
|
|
212
214
|
"外部系统操作、BOS 注册、人工功能测试和生产环境验证不能由 LLM 代办;必须要求用户提供验证结果或可核验证据,并记录证据来源。",
|
|
213
|
-
"Windows
|
|
215
|
+
"Windows 路径规则:读取可使用工作区内绝对路径;写入和编辑必须使用当前工作区内路径,默认使用项目相对路径。禁止写入 C:\\Users、Desktop 或其他非当前工作区路径。",
|
|
214
216
|
"工具规则:按当前会话实际 shell 和工具执行;Windows 不假设 bash,优先用 kd_find_file/kd_list_dir/PowerShell;禁止猜路径或用 kd_subagent 代替基础搜索失败。",
|
|
215
217
|
];
|
|
216
218
|
export const PHASE_GUIDANCE = {
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,19 @@
|
|
|
6
6
|
|
|
7
7
|
- 暂无。
|
|
8
8
|
|
|
9
|
+
## 0.1.43 - 2026-06-07
|
|
10
|
+
|
|
11
|
+
### 修复
|
|
12
|
+
|
|
13
|
+
- `write`/`edit` 工具调用新增工作区外绝对路径拦截,禁止直接写入 `C:/Users`、Desktop 或其他非当前工作区路径。
|
|
14
|
+
- Windows 路径规则补充为写入必须使用当前项目相对路径或工作区内路径,避免外部绝对路径触发上游写入超时。
|
|
15
|
+
- Harness smoke 增加 `C:/Users/...` 外部路径判定回归测试。
|
|
16
|
+
|
|
17
|
+
### 验证
|
|
18
|
+
|
|
19
|
+
- `npm run check`
|
|
20
|
+
- `npm run smoke:harness`
|
|
21
|
+
|
|
9
22
|
## 0.1.42 - 2026-06-07
|
|
10
23
|
|
|
11
24
|
### 改进
|
|
@@ -26,7 +26,7 @@ import { flagshipWriteBlockReason, isSourceLikePath, planWriteBlockReason } from
|
|
|
26
26
|
import { sdkSignatureProductionWriteBlockReason } from "../src/harness/sdk-policy.ts";
|
|
27
27
|
import { dataSourceProductionWriteBlockReason } from "../src/harness/data-source-policy.ts";
|
|
28
28
|
import { tddProductionWriteBlockReason } from "../src/harness/tdd-policy.ts";
|
|
29
|
-
import { windowsPathHint } from "../src/platform/path.ts";
|
|
29
|
+
import { isExternalAbsolutePath, isPathInsideWorkspace, windowsPathHint } from "../src/platform/path.ts";
|
|
30
30
|
import { repairPromptForRun, workflowPromptForRun } from "../src/harness/prompt.ts";
|
|
31
31
|
import { recordVerifyResult, type VerifyResultOutcome } from "../src/harness/repair.ts";
|
|
32
32
|
import { isSubagentChild, subagentRoleFromEnv, subagentToolCallBlockReason } from "../src/harness/delegation.ts";
|
|
@@ -157,6 +157,12 @@ function codeWriteBlockReason(cwd: string, path: string | undefined): string | u
|
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
function externalWriteBlockReason(cwd: string, toolName: string, path: string | undefined): string | undefined {
|
|
161
|
+
if (!path || !["write", "edit"].includes(toolName)) return undefined;
|
|
162
|
+
if (!isExternalAbsolutePath(path) || isPathInsideWorkspace(cwd, path)) return undefined;
|
|
163
|
+
return `拒绝写入工作区外绝对路径 ${path}。执行指令:先确认当前业务项目根目录;生产源码必须使用当前项目相对路径,并受 PLAN.md 批准文件、execute 阶段和证据门禁约束。禁止直接写入 C:/Users、Desktop 或其他非当前工作区路径。`;
|
|
164
|
+
}
|
|
165
|
+
|
|
160
166
|
const kdPlanStatusTool = defineTool({
|
|
161
167
|
name: "kd_plan_status",
|
|
162
168
|
label: "KD 状态",
|
|
@@ -427,6 +433,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
427
433
|
pi.on("tool_call", (event, ctx) => {
|
|
428
434
|
const input = event.input as Record<string, unknown>;
|
|
429
435
|
const path = typeof input.path === "string" ? input.path : undefined;
|
|
436
|
+
const externalWriteReason = externalWriteBlockReason(ctx.cwd, event.toolName, path);
|
|
437
|
+
if (externalWriteReason) {
|
|
438
|
+
if (ctx.hasUI) ctx.ui.notify(externalWriteReason, "warning");
|
|
439
|
+
return { block: true, reason: externalWriteReason };
|
|
440
|
+
}
|
|
430
441
|
const hint = path ? windowsPathHint(path) : undefined;
|
|
431
442
|
if (hint && ["read", "write", "edit"].includes(event.toolName)) {
|
|
432
443
|
const reason = `当前是 Windows 工作区,路径 ${path} 不是本项目使用的路径形式。执行指令:改用项目相对路径;必须使用绝对路径时,使用 Windows 路径 ${hint}。`;
|
package/package.json
CHANGED
|
@@ -160,6 +160,7 @@ export const PROJECT_PERSISTENT_RULES = [
|
|
|
160
160
|
"提示语集中管理为正式工程指令;禁止口语化、闲聊式、鼓励式提示词进入运行时规则。",
|
|
161
161
|
"工具使用必须匹配当前会话实际可用工具和操作系统;Windows 默认使用 PowerShell、`rg`、`Get-ChildItem`、`Get-Content`,禁止假设 bash 可用。",
|
|
162
162
|
"Windows 查找文件和目录时优先使用 `kd_find_file`、`kd_list_dir` 或 PowerShell;禁止用 Linux find/ls 语法反复调用 Pi 内置 bash。",
|
|
163
|
+
"写入或编辑文件时禁止使用当前工作区外的绝对路径;生产源码必须使用当前业务项目相对路径,并受 PLAN.md 批准文件约束。",
|
|
163
164
|
"文件定位必须使用真实搜索或目录读取结果;工具不可用时明确说明阻塞原因和需要用户执行的命令,禁止猜测路径、反复自述工具失败或用 kd_subagent 代替基础文件搜索。",
|
|
164
165
|
"不做旧状态迁移兼容或旧问题答案推断;坏状态只过滤,缺失事实必须重新提问确认。",
|
|
165
166
|
];
|
|
@@ -210,6 +211,7 @@ export const PROMPT_PROHIBITED_BEHAVIORS = [
|
|
|
210
211
|
"禁止一次性向用户索要多项业务信息。",
|
|
211
212
|
"禁止重复询问已确认事实或已存在 open blocking question 的问题。",
|
|
212
213
|
"禁止猜测路径、包名、类名、FormId、字段、实体、SQL 表名、数据库字段名或接口字段映射。",
|
|
214
|
+
"禁止写入或编辑当前工作区外的绝对路径。",
|
|
213
215
|
"禁止用子 agent、shell 失败自述或自由文本计划绕过门禁。",
|
|
214
216
|
"禁止将外部系统操作、BOS 注册、人工功能测试或生产验证描述为 LLM 已完成。",
|
|
215
217
|
];
|
|
@@ -229,7 +231,7 @@ export const CORE_WORKFLOW_CONSTRAINTS = [
|
|
|
229
231
|
"Java/Cosmic 使用当前项目 Gradle;C#/企业版使用 dotnet build。",
|
|
230
232
|
"evidence 必须记录命令、Exit 和关键输出;命令无法运行时记录阻塞原因。",
|
|
231
233
|
"外部系统操作、BOS 注册、人工功能测试和生产环境验证不能由 LLM 代办;必须要求用户提供验证结果或可核验证据,并记录证据来源。",
|
|
232
|
-
"Windows
|
|
234
|
+
"Windows 路径规则:读取可使用工作区内绝对路径;写入和编辑必须使用当前工作区内路径,默认使用项目相对路径。禁止写入 C:\\Users、Desktop 或其他非当前工作区路径。",
|
|
233
235
|
"工具规则:按当前会话实际 shell 和工具执行;Windows 不假设 bash,优先用 kd_find_file/kd_list_dir/PowerShell;禁止猜路径或用 kd_subagent 代替基础搜索失败。",
|
|
234
236
|
];
|
|
235
237
|
|
package/src/platform/path.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAbsolute, resolve } from "node:path";
|
|
1
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
2
2
|
|
|
3
3
|
const WINDOWS_DRIVE_RE = /^[a-zA-Z]:[\\/]/;
|
|
4
4
|
|
|
@@ -7,6 +7,18 @@ export function resolveWorkspacePath(cwd: string, inputPath: string): string {
|
|
|
7
7
|
return isAbsolute(normalized) || WINDOWS_DRIVE_RE.test(normalized) ? resolve(normalized) : resolve(cwd, normalized);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export function isExternalAbsolutePath(inputPath: string): boolean {
|
|
11
|
+
const normalized = normalizeExternalPath(inputPath);
|
|
12
|
+
return isAbsolute(normalized) || WINDOWS_DRIVE_RE.test(normalized);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isPathInsideWorkspace(cwd: string, inputPath: string): boolean {
|
|
16
|
+
const workspace = resolve(cwd);
|
|
17
|
+
const target = resolveWorkspacePath(cwd, inputPath);
|
|
18
|
+
const rel = relative(workspace, target);
|
|
19
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
export function normalizeExternalPath(inputPath: string): string {
|
|
11
23
|
let value = inputPath.trim();
|
|
12
24
|
if (value.startsWith("file://")) {
|