Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix(tools): align edit freshness recovery guidance

CloudTianTian5b8988f1f5c0
diff --git a/src/main/model/core-agent/read-tracker.ts b/src/main/model/core-agent/read-tracker.ts
index d102f4f1..e0b7d51b 100644
--- a/src/main/model/core-agent/read-tracker.ts
+++ b/src/main/model/core-agent/read-tracker.ts
@@ -78,8 +78,15 @@ export type EditBlock = { code: 'E_NOT_READ' | 'E_STALE'; msg: string };
* Decide whether `edit_file` may proceed on `abs`, given its current stat.
* Returns null when the edit is allowed (or when the run-scoped map is absent,
* i.e. the host opted out — see module header), otherwise the block reason:
- * - never read this run → E_NOT_READ (read it first)
- * - read, but mtime/size changed → E_STALE (re-read; it moved under you)
+ * - never read this run → E_NOT_READ
+ * - read, but mtime/size changed → E_STALE
+ *
+ * Message contract: every consumer (edit_file, apply_patch) appends a
+ * recovery block with the current bytes and a fresh file_hash, and refreshes
+ * the read baseline on rejection — so the messages steer the model at that
+ * returned context first. A bare "call read_file again" here made models pay
+ * a full re-read round the trailer had already made unnecessary
+ * (2026-08-16 latency review P0-4).
*/
export function checkEditFreshness(
ctx: ToolContext,
@@ -102,7 +109,7 @@ export function checkEditFreshness(
if (!seen) {
return {
code: 'E_NOT_READ',
- msg: `${abs}: read the file with read_file before editing it, so old_string matches the real current contents.`,
+ msg: `${abs}: not read in this run, so old_string cannot be checked against the real current contents. Use the current context and file_hash returned below to retry (pass expected_hash); use read_file with a bounded range only if that window misses your target.`,
};
}
if (
@@ -112,7 +119,7 @@ export function checkEditFreshness(
) {
return {
code: 'E_STALE',
- msg: `${abs}: file changed on disk since you read it (another worker, a command, or an external edit). Call read_file again, then redo the edit against the current contents.`,
+ msg: `${abs}: file changed on disk since you read it (another worker, a command, or an external edit). Retry against the current context and file_hash returned below (pass expected_hash); re-read only the affected region with read_file range if that window is insufficient.`,
};
}
return null;
diff --git a/test/main/model/core-agent/read-tracker.test.ts b/test/main/model/core-agent/read-tracker.test.ts
index 2aed1f25..46037dfa 100644
--- a/test/main/model/core-agent/read-tracker.test.ts
+++ b/test/main/model/core-agent/read-tracker.test.ts
@@ -53,6 +53,12 @@ describe('read-tracker › checkEditFreshness', () => {
const st = fs.statSync(file);
const block = checkEditFreshness(ctx, file, st);
expect(block?.code).toBe('E_NOT_READ');
+ // The refusal steers at the recovery block every consumer appends, not at
+ // a bare full re-read: a "call read_file" instruction here made models pay
+ // a whole re-read round the returned context had already made unnecessary.
+ expect(block?.msg).toContain('expected_hash');
+ expect(block?.msg).toContain('bounded range');
+ expect(block?.msg).not.toMatch(/read the file with read_file before/);
});
it('allows the edit after a read records the baseline', () => {
@@ -80,6 +86,11 @@ describe('read-tracker › checkEditFreshness', () => {
fs.writeFileSync(file, 'a much longer body than before', 'utf8'); // size changes
const block = checkEditFreshness(ctx, file, fs.statSync(file));
expect(block?.code).toBe('E_STALE');
+ // Same recovery-first contract as E_NOT_READ: retry against the returned
+ // context/hash, bounded range re-read only as the fallback.
+ expect(block?.msg).toContain('expected_hash');
+ expect(block?.msg).toContain('read_file range');
+ expect(block?.msg).not.toMatch(/Call read_file again/);
});
it('blocks with E_STALE when only mtime changed (same size)', () => {