Skip to content

Commit e64a3ce

Browse files
committed
fix(exec-approvals): state the repair directory in prose so every shell can follow it
1 parent 2ed3761 commit e64a3ce

4 files changed

Lines changed: 20 additions & 33 deletions

File tree

‎apps/shared/OpenClawKit/Sources/OpenClawKit/ExecApprovalsLegacyMigrationGate.swift‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,15 @@ enum ExecApprovalsLegacyMigrationGate {
3030
NSLocalizedDescriptionKey:
3131
"Legacy exec approvals exist at \(sourceURL.path). " +
3232
// Doctor repairs whichever state directory its own environment resolves to,
33-
// and an app store never shares the CLI's default root, so always scope the
34-
// command; a bare `doctor --fix` would repair a different directory.
35-
"Run `OPENCLAW_STATE_DIR=\(self.shellQuoted(stateDirectoryURL.path)) " +
36-
"openclaw doctor --fix` before using exec approvals.",
33+
// and an app store never shares the CLI's default root, so always name the
34+
// directory; a bare `doctor --fix` would repair a different one. Prose,
35+
// not a `VAR=value cmd` one-liner, so the path needs no shell quoting.
36+
"Run `openclaw doctor --fix` with OPENCLAW_STATE_DIR set to " +
37+
"\(stateDirectoryURL.path) before using exec approvals.",
3738
])
3839
}
3940
}
4041

41-
/// POSIX single-quote so an app state directory under `Application Support` stays one shell word.
42-
private static func shellQuoted(_ value: String) -> String {
43-
"'" + value.replacingOccurrences(of: "'", with: "'\\''") + "'"
44-
}
45-
4642
private static func pathMayExist(_ url: URL) -> Bool {
4743
let fileManager = FileManager.default
4844
return fileManager.fileExists(atPath: url.path)

‎apps/shared/OpenClawKit/Tests/OpenClawKitTests/ExecApprovalsSQLiteStoreTests.swift‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ struct ExecApprovalsSQLiteStoreTests {
213213
_ = try ExecApprovalsSQLiteStore.read(stateDirectoryURL: stateDirectoryURL)
214214
Issue.record("Expected pending legacy approvals to refuse SQLite access")
215215
} catch {
216-
// A scoped state directory must be named, and quoted so a path containing
217-
// spaces stays one shell word; a bare command repairs the default root.
216+
// The blocked state directory must be named; a bare command repairs the
217+
// default root, and an app store never shares the CLI's default root.
218218
#expect(
219219
error.localizedDescription.contains(
220-
"Run `OPENCLAW_STATE_DIR='\(stateDirectoryURL.path)' openclaw doctor --fix`"))
220+
"Run `openclaw doctor --fix` with OPENCLAW_STATE_DIR set to "
221+
+ stateDirectoryURL.path))
221222
}
222223
}
223224
}

‎src/infra/exec-approvals-migration-gate.ts‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@ import { resolveExecApprovalsPath } from "./exec-approvals-config.js";
66
const DOCTOR_CLAIM_SUFFIX = ".doctor-importing";
77
const legacyPresenceCache = new Map<string, boolean>();
88

9-
/** POSIX single-quote so a state directory containing spaces stays one shell word. */
10-
function shellQuoteStateDir(stateDir: string): string {
11-
return `'${stateDir.replaceAll("'", "'\\''")}'`;
12-
}
13-
149
/**
1510
* Doctor repairs whichever state directory its own environment resolves to, so a bare
1611
* `openclaw doctor --fix` repairs the default root while a scoped install stays blocked.
17-
* Name the directory whenever this process is scoped to a non-default one.
12+
* Name the directory whenever this process is scoped to a non-default one. Say it in
13+
* prose rather than as a `VAR=value cmd` one-liner, which no Windows shell accepts.
1814
*/
19-
function formatDoctorFixCommand(filePath: string): string {
15+
function doctorFixInstruction(filePath: string): string {
16+
const command = "Run `openclaw doctor --fix`";
2017
return process.env.OPENCLAW_STATE_DIR?.trim()
21-
? `OPENCLAW_STATE_DIR=${shellQuoteStateDir(path.dirname(filePath))} openclaw doctor --fix`
22-
: "openclaw doctor --fix";
18+
? `${command} with OPENCLAW_STATE_DIR set to ${path.dirname(filePath)}`
19+
: command;
2320
}
2421

2522
export class ExecApprovalsMigrationRequiredError extends Error {
2623
constructor(filePath: string) {
2724
super(
28-
`Legacy exec approvals exist at ${filePath}. Run \`${formatDoctorFixCommand(filePath)}\` before using exec approvals.`,
25+
`Legacy exec approvals exist at ${filePath}. ${doctorFixInstruction(filePath)} before using exec approvals.`,
2926
);
3027
this.name = "ExecApprovalsMigrationRequiredError";
3128
}

‎src/infra/exec-approvals-store.test.ts‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,11 @@ describe("exec approvals SQLite store", () => {
407407
path.join(stateDir, "exec-approvals.json"),
408408
);
409409

410-
expect(error.message).toContain(`OPENCLAW_STATE_DIR='${stateDir}' openclaw doctor --fix`);
411-
});
412-
413-
it("keeps a spaced state directory one shell word", () => {
414-
// macOS app state lives under "Application Support"; an unquoted path would
415-
// word-split and make the prescribed command repair the wrong directory.
416-
const stateDir = path.join(process.env.OPENCLAW_STATE_DIR ?? "", "Application Support");
417-
const error = new ExecApprovalsMigrationRequiredError(
418-
path.join(stateDir, "exec-approvals.json"),
410+
// Prose, not `VAR=value cmd`: no Windows shell accepts that form, and a path
411+
// containing spaces would need shell-specific quoting to survive a paste.
412+
expect(error.message).toContain(
413+
`Run \`openclaw doctor --fix\` with OPENCLAW_STATE_DIR set to ${stateDir}`,
419414
);
420-
421-
expect(error.message).toContain(`OPENCLAW_STATE_DIR='${stateDir}' openclaw doctor --fix`);
422415
});
423416

424417
it.each([

0 commit comments

Comments
 (0)