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.

Preserve dollar sequences in literal file replacements

wyte24245ed90d7
diff --git a/src/main/model/core-agent/local-tools.ts b/src/main/model/core-agent/local-tools.ts
index c7b1a5c9..a89528a4 100644
--- a/src/main/model/core-agent/local-tools.ts
+++ b/src/main/model/core-agent/local-tools.ts
@@ -5612,7 +5612,7 @@ function createEditFileTool(opts: LocalToolsOpts): AgentTool {
};
}
- const next = replaceAll ? body.split(matchText).join(newStr) : body.replace(matchText, newStr);
+ const next = replaceAll ? body.split(matchText).join(newStr) : body.replace(matchText, () => newStr);
const oauthClientMismatchErr = guardGoogleWorkspaceOauthClientMismatchText(next);
if (oauthClientMismatchErr) {
log.warn('edit_file google oauth client/scope mismatch reject', { user_id: maskId(opts.userId), path: logPathRef(abs) });
diff --git a/test/main/model/core-agent/local-tools.test.ts b/test/main/model/core-agent/local-tools.test.ts
index 2f7314d9..99eaf4ca 100644
--- a/test/main/model/core-agent/local-tools.test.ts
+++ b/test/main/model/core-agent/local-tools.test.ts
@@ -2564,6 +2564,26 @@ describe('local-tools › edit_file › file kind / existence', () => {
});
describe('local-tools › edit_file › matching semantics', () => {
+ it.each(['exact', 'whitespace_relaxed', 'replace_all'])('writes replacement tokens literally (%s)', async (mode) => {
+ await allFilesAuto();
+ const written: string[] = [];
+ const { edit, wsDir } = await buildEditTool({ onFileWritten: (p) => written.push(p) });
+ const p = path.join(wsDir, 'literal.ps1');
+ const needle = 'first\nsecond';
+ const source = mode === 'whitespace_relaxed' ? 'first \nsecond' : needle;
+ const replacement = "if ($value -match '^ok$') { '$& $$ $` $1 $<name>' }";
+ const before = `prefix\r\n${source}\r\nsuffix` + (mode === 'replace_all' ? `\r\n${source}` : '');
+ const expected = `prefix\r\n${replacement}\r\nsuffix` + (mode === 'replace_all' ? `\r\n${replacement}` : '');
+ fs.writeFileSync(p, before);
+ const result = await run(edit, { path: p, old_string: needle, new_string: replacement, replace_all: mode === 'replace_all' });
+ expect(result.isError).toBeFalsy();
+ expect(fs.readFileSync(p, 'utf8')).toBe(expected);
+ expect(result.content).toContain(`edited="${mode === 'replace_all' ? 2 : 1}"`);
+ expect(result.content).toContain('revision=');
+ expect(written).toEqual([p]);
+ if (mode === 'whitespace_relaxed') expect(result.content).toContain('match="whitespace_relaxed"');
+ });
+
it('returns bounded real contexts for long-line matches and supports an exact targeted retry', async () => {
await allFilesAuto();
const { edit, wsDir } = await buildEditTool();