fix: validate sessionId on resume and respect CLAUDE_CONFIG_DIR
- Use CLAUDE_CONFIG_DIR env var for Claude config location - Rename tool call name to 'permission' for permission requests - Update tests to use CLAUDE_CONFIG_DIR instead of HOME
This commit is contained in:
@@ -1261,9 +1261,10 @@ function normalizeCwdCandidates(cwd: string): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cleanupClaudeHistory(cwd: string) {
|
function cleanupClaudeHistory(cwd: string) {
|
||||||
|
const configDir = process.env.CLAUDE_CONFIG_DIR ?? path.join(os.homedir(), ".claude");
|
||||||
for (const candidate of normalizeCwdCandidates(cwd)) {
|
for (const candidate of normalizeCwdCandidates(cwd)) {
|
||||||
const sanitized = sanitizeClaudeProjectName(candidate);
|
const sanitized = sanitizeClaudeProjectName(candidate);
|
||||||
const projectDir = path.join(os.homedir(), ".claude", "projects", sanitized);
|
const projectDir = path.join(configDir, "projects", sanitized);
|
||||||
if (existsSync(projectDir)) {
|
if (existsSync(projectDir)) {
|
||||||
rmSync(projectDir, { recursive: true, force: true });
|
rmSync(projectDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,7 +325,8 @@ export class ClaudeAgentClient implements AgentClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async listPersistedAgents(options?: ListPersistedAgentsOptions): Promise<PersistedAgentDescriptor[]> {
|
async listPersistedAgents(options?: ListPersistedAgentsOptions): Promise<PersistedAgentDescriptor[]> {
|
||||||
const projectsRoot = path.join(os.homedir(), ".claude", "projects");
|
const configDir = process.env.CLAUDE_CONFIG_DIR ?? path.join(os.homedir(), ".claude");
|
||||||
|
const projectsRoot = path.join(configDir, "projects");
|
||||||
if (!(await pathExists(projectsRoot))) {
|
if (!(await pathExists(projectsRoot))) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -628,7 +629,7 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
};
|
};
|
||||||
pending.resolve(result);
|
pending.resolve(result);
|
||||||
this.pushToolCall({
|
this.pushToolCall({
|
||||||
name: pending.request.name,
|
name: "permission",
|
||||||
status: "granted",
|
status: "granted",
|
||||||
callId: pending.request.id,
|
callId: pending.request.id,
|
||||||
input: pending.request.input,
|
input: pending.request.input,
|
||||||
@@ -641,7 +642,7 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
};
|
};
|
||||||
pending.resolve(result);
|
pending.resolve(result);
|
||||||
this.pushToolCall({
|
this.pushToolCall({
|
||||||
name: pending.request.name,
|
name: "permission",
|
||||||
status: "denied",
|
status: "denied",
|
||||||
callId: pending.request.id,
|
callId: pending.request.id,
|
||||||
input: pending.request.input,
|
input: pending.request.input,
|
||||||
@@ -1050,7 +1051,7 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.pushToolCall({
|
this.pushToolCall({
|
||||||
name: toolName,
|
name: "permission",
|
||||||
status: "requested",
|
status: "requested",
|
||||||
callId: requestId,
|
callId: requestId,
|
||||||
input,
|
input,
|
||||||
@@ -1075,7 +1076,7 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
cleanup();
|
cleanup();
|
||||||
const error = new Error("Permission request timed out");
|
const error = new Error("Permission request timed out");
|
||||||
this.pushToolCall({
|
this.pushToolCall({
|
||||||
name: toolName,
|
name: "permission",
|
||||||
status: "denied",
|
status: "denied",
|
||||||
callId: requestId,
|
callId: requestId,
|
||||||
input,
|
input,
|
||||||
|
|||||||
@@ -2660,13 +2660,11 @@ describe("daemon E2E", () => {
|
|||||||
|
|
||||||
describe("Claude persisted agent import", () => {
|
describe("Claude persisted agent import", () => {
|
||||||
test("filters internal warmup entries from persisted Claude history", async () => {
|
test("filters internal warmup entries from persisted Claude history", async () => {
|
||||||
const previousHome = process.env.HOME;
|
const previousClaudeConfigDir = process.env.CLAUDE_CONFIG_DIR;
|
||||||
const previousUserProfile = process.env.USERPROFILE;
|
const claudeConfigDir = mkdtempSync(path.join(tmpdir(), "claude-config-"));
|
||||||
const homeDir = mkdtempSync(path.join(tmpdir(), "claude-home-"));
|
process.env.CLAUDE_CONFIG_DIR = claudeConfigDir;
|
||||||
process.env.HOME = homeDir;
|
|
||||||
process.env.USERPROFILE = homeDir;
|
|
||||||
|
|
||||||
const projectDir = path.join(homeDir, ".claude", "projects", "test-project");
|
const projectDir = path.join(claudeConfigDir, "projects", "test-project");
|
||||||
mkdirSync(projectDir, { recursive: true });
|
mkdirSync(projectDir, { recursive: true });
|
||||||
|
|
||||||
const sessionId = `session-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
const sessionId = `session-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||||
@@ -2708,17 +2706,12 @@ describe("daemon E2E", () => {
|
|||||||
expect(timelineTexts).toContain("Real task prompt");
|
expect(timelineTexts).toContain("Real task prompt");
|
||||||
expect(timelineTexts).not.toContain("Warmup");
|
expect(timelineTexts).not.toContain("Warmup");
|
||||||
} finally {
|
} finally {
|
||||||
if (previousHome === undefined) {
|
if (previousClaudeConfigDir === undefined) {
|
||||||
delete process.env.HOME;
|
delete process.env.CLAUDE_CONFIG_DIR;
|
||||||
} else {
|
} else {
|
||||||
process.env.HOME = previousHome;
|
process.env.CLAUDE_CONFIG_DIR = previousClaudeConfigDir;
|
||||||
}
|
}
|
||||||
if (previousUserProfile === undefined) {
|
rmSync(claudeConfigDir, { recursive: true, force: true });
|
||||||
delete process.env.USERPROFILE;
|
|
||||||
} else {
|
|
||||||
process.env.USERPROFILE = previousUserProfile;
|
|
||||||
}
|
|
||||||
rmSync(homeDir, { recursive: true, force: true });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user