Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(protocol): register scoped-write denial codes

v_wyxgwang4bd6d4a1f2de
diff --git a/apps/desktop/test/error-code-registry.test.mjs b/apps/desktop/test/error-code-registry.test.mjs
index f3230ffc7..55defb3f8 100644
--- a/apps/desktop/test/error-code-registry.test.mjs
+++ b/apps/desktop/test/error-code-registry.test.mjs
@@ -32,6 +32,8 @@ function hostEmittedCodes() {
for (const m of tools.matchAll(/ToolError::new\(\s*"([A-Z][A-Z0-9_]+)"/g)) codes.add(m[1]);
const ignore = read("crates/host-core/src/tools/ignore_rules.rs");
for (const m of ignore.matchAll(/DENIED_CODE: &str = "([A-Z][A-Z0-9_]+)"/g)) codes.add(m[1]);
+ const scope = read("crates/host-core/src/tools/write_scope.rs");
+ for (const m of scope.matchAll(/VIOLATION: &str = "([A-Z][A-Z0-9_]+)"/g)) codes.add(m[1]);
return codes;
}
diff --git a/docs/spec/03-runtime/08-error-codes.md b/docs/spec/03-runtime/08-error-codes.md
index f6d0ebaf1..f37604312 100644
--- a/docs/spec/03-runtime/08-error-codes.md
+++ b/docs/spec/03-runtime/08-error-codes.md
@@ -139,6 +139,9 @@ and transient 5xx envelopes retain their existing classifications.
| `TOOL_BINARY_CONTENT` | no | `Read` refused to dump a binary file into the model context |
| `TOOL_NOT_FOUND` | no | unknown tool |
| `TOOL_DENIED` | no | permission denied / mode forbidden |
+| `TOOL_CONTEXT_CHANGED` | no | session mode or workspace changed during admission; start a new authorized call |
+| `WRITE_SCOPE_UNAVAILABLE` | no | the host cannot verify a local write scope for this workspace |
+| `WRITE_SCOPE_VIOLATION` | no | a delegated write target or move destination is outside the verified scope; report the blocked path |
| `TOOL_TIMEOUT` | yes | tool execution timeout |
| `TOOL_FAILED` | maybe | tool executed but failed |
| `FILE_NOT_FOUND` | no | Read/Write/Edit target path does not exist (distinct from `TOOL_DENIED`) |
diff --git a/packages/shared/src/errors.ts b/packages/shared/src/errors.ts
index eeecb6e80..bdf78fe10 100644
--- a/packages/shared/src/errors.ts
+++ b/packages/shared/src/errors.ts
@@ -178,6 +178,9 @@ export const ErrorCodes = {
VISUALIZATION_HTML_ONLY: "VISUALIZATION_HTML_ONLY",
TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
TOOL_DENIED: "TOOL_DENIED",
+ TOOL_CONTEXT_CHANGED: "TOOL_CONTEXT_CHANGED",
+ WRITE_SCOPE_UNAVAILABLE: "WRITE_SCOPE_UNAVAILABLE",
+ WRITE_SCOPE_VIOLATION: "WRITE_SCOPE_VIOLATION",
TOOL_TIMEOUT: "TOOL_TIMEOUT",
TOOL_FAILED: "TOOL_FAILED",
/** Read/Write/Edit target path does not exist. Distinct from TOOL_DENIED. */