fix(agents): default agent dir to multi-agent path
This commit is contained in:
@@ -105,7 +105,7 @@ Legacy agent dir (pre multi-agent):
|
|||||||
|
|
||||||
Overrides:
|
Overrides:
|
||||||
- OAuth dir (legacy import only): `CLAWDBOT_OAUTH_DIR`
|
- OAuth dir (legacy import only): `CLAWDBOT_OAUTH_DIR`
|
||||||
- Agent dir (legacy/default agent only): `CLAWDBOT_AGENT_DIR` (preferred), `PI_CODING_AGENT_DIR` (legacy)
|
- Agent dir (default agent root override): `CLAWDBOT_AGENT_DIR` (preferred), `PI_CODING_AGENT_DIR` (legacy)
|
||||||
|
|
||||||
On first use, Clawdbot imports `oauth.json` entries into `auth-profiles.json`.
|
On first use, Clawdbot imports `oauth.json` entries into `auth-profiles.json`.
|
||||||
|
|
||||||
@@ -1023,7 +1023,7 @@ Notes:
|
|||||||
`google-generative-ai`
|
`google-generative-ai`
|
||||||
- Use `authHeader: true` + `headers` for custom auth needs.
|
- Use `authHeader: true` + `headers` for custom auth needs.
|
||||||
- Override the agent config root with `CLAWDBOT_AGENT_DIR` (or `PI_CODING_AGENT_DIR`)
|
- Override the agent config root with `CLAWDBOT_AGENT_DIR` (or `PI_CODING_AGENT_DIR`)
|
||||||
if you want `models.json` stored elsewhere.
|
if you want `models.json` stored elsewhere (default: `~/.clawdbot/agents/main/agent`).
|
||||||
|
|
||||||
### `session`
|
### `session`
|
||||||
|
|
||||||
|
|||||||
58
src/agents/agent-paths.test.ts
Normal file
58
src/agents/agent-paths.test.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import fs from "node:fs/promises";
|
||||||
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { resolveClawdbotAgentDir } from "./agent-paths.js";
|
||||||
|
|
||||||
|
describe("resolveClawdbotAgentDir", () => {
|
||||||
|
const previousStateDir = process.env.CLAWDBOT_STATE_DIR;
|
||||||
|
const previousAgentDir = process.env.CLAWDBOT_AGENT_DIR;
|
||||||
|
const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
||||||
|
let tempStateDir: string | null = null;
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
if (tempStateDir) {
|
||||||
|
await fs.rm(tempStateDir, { recursive: true, force: true });
|
||||||
|
tempStateDir = null;
|
||||||
|
}
|
||||||
|
if (previousStateDir === undefined) {
|
||||||
|
delete process.env.CLAWDBOT_STATE_DIR;
|
||||||
|
} else {
|
||||||
|
process.env.CLAWDBOT_STATE_DIR = previousStateDir;
|
||||||
|
}
|
||||||
|
if (previousAgentDir === undefined) {
|
||||||
|
delete process.env.CLAWDBOT_AGENT_DIR;
|
||||||
|
} else {
|
||||||
|
process.env.CLAWDBOT_AGENT_DIR = previousAgentDir;
|
||||||
|
}
|
||||||
|
if (previousPiAgentDir === undefined) {
|
||||||
|
delete process.env.PI_CODING_AGENT_DIR;
|
||||||
|
} else {
|
||||||
|
process.env.PI_CODING_AGENT_DIR = previousPiAgentDir;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("defaults to the multi-agent path when no overrides are set", async () => {
|
||||||
|
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-agent-"));
|
||||||
|
process.env.CLAWDBOT_STATE_DIR = tempStateDir;
|
||||||
|
delete process.env.CLAWDBOT_AGENT_DIR;
|
||||||
|
delete process.env.PI_CODING_AGENT_DIR;
|
||||||
|
|
||||||
|
const resolved = resolveClawdbotAgentDir();
|
||||||
|
|
||||||
|
expect(resolved).toBe(path.join(tempStateDir, "agents", "main", "agent"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("honors CLAWDBOT_AGENT_DIR overrides", async () => {
|
||||||
|
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-agent-"));
|
||||||
|
const override = path.join(tempStateDir, "agent");
|
||||||
|
process.env.CLAWDBOT_AGENT_DIR = override;
|
||||||
|
delete process.env.PI_CODING_AGENT_DIR;
|
||||||
|
|
||||||
|
const resolved = resolveClawdbotAgentDir();
|
||||||
|
|
||||||
|
expect(resolved).toBe(path.resolve(override));
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,14 +1,21 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
import { resolveConfigDir, resolveUserPath } from "../utils.js";
|
import { resolveStateDir } from "../config/paths.js";
|
||||||
|
import { DEFAULT_AGENT_ID } from "../routing/session-key.js";
|
||||||
|
import { resolveUserPath } from "../utils.js";
|
||||||
|
|
||||||
export function resolveClawdbotAgentDir(): string {
|
export function resolveClawdbotAgentDir(): string {
|
||||||
const defaultAgentDir = path.join(resolveConfigDir(), "agent");
|
|
||||||
const override =
|
const override =
|
||||||
process.env.CLAWDBOT_AGENT_DIR?.trim() ||
|
process.env.CLAWDBOT_AGENT_DIR?.trim() ||
|
||||||
process.env.PI_CODING_AGENT_DIR?.trim() ||
|
process.env.PI_CODING_AGENT_DIR?.trim();
|
||||||
defaultAgentDir;
|
if (override) return resolveUserPath(override);
|
||||||
return resolveUserPath(override);
|
const defaultAgentDir = path.join(
|
||||||
|
resolveStateDir(),
|
||||||
|
"agents",
|
||||||
|
DEFAULT_AGENT_ID,
|
||||||
|
"agent",
|
||||||
|
);
|
||||||
|
return resolveUserPath(defaultAgentDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ensureClawdbotAgentEnv(): string {
|
export function ensureClawdbotAgentEnv(): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user