Map Claude turns to runtime query policies
- Derive Claude SDK query options from runtime policy - Add read-only replay fixture and policy mapping tests - Reuse shared approval-policy fixtures across orchestrator tests Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
7979036cd1
commit
ca835c2508
8 files changed
+524
-116
No files matched your search
@@ -5,14 +5,25 @@ import {
|
||||
recordClaudeAgentSdkReplayTranscript,
|
||||
CLAUDE_AGENT_SDK_REPLAY_PROTOCOL,
|
||||
} from "../src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts";
|
||||
import { claudeRuntimeQueryPolicyForRuntimePolicy } from "../src/orchestration-v2/Adapters/ClaudeAdapterV2.ts";
|
||||
import {
|
||||
ProviderAdapterV2RuntimePolicy,
|
||||
type ProviderAdapterV2RuntimePolicy as ProviderAdapterV2RuntimePolicyType,
|
||||
} from "../src/orchestration-v2/ProviderAdapter.ts";
|
||||
import type { RuntimePolicyV2Override } from "../src/orchestration-v2/RuntimePolicy.ts";
|
||||
import { makeCheckpointWorkspace } from "../src/orchestration-v2/testkit/ReplayFixtureWorkspace.ts";
|
||||
import { CLAUDE_MODEL_SELECTION } from "../src/orchestration-v2/testkit/fixtures/shared.ts";
|
||||
import {
|
||||
MULTI_TURN_FIRST_PROMPT,
|
||||
READ_ONLY_NEVER_POLICY,
|
||||
READ_ONLY_ON_REQUEST_POLICY,
|
||||
RESTRICTED_GRANULAR_POLICY,
|
||||
MULTI_TURN_SECOND_PROMPT,
|
||||
SIMPLE_PROMPT,
|
||||
TOOL_CALL_READ_ONLY_PROMPT,
|
||||
TOOL_CALL_READ_ONLY_WORKSPACE_ROOT,
|
||||
TOOL_CALL_WRITE_PROMPT,
|
||||
WORKSPACE_NEVER_POLICY,
|
||||
WEB_SEARCH_PROMPT,
|
||||
} from "../src/orchestration-v2/testkit/fixtures/shared.ts";
|
||||
|
||||
@@ -22,64 +33,52 @@ const CLAUDE_RECORDINGS = {
|
||||
defaultTranscriptFile: "fixtures/simple/claude_transcript.ndjson",
|
||||
queryMode: "streaming",
|
||||
enableTools: true,
|
||||
permissionMode: "bypassPermissions",
|
||||
allowDangerouslySkipPermissions: true,
|
||||
},
|
||||
multi_turn: {
|
||||
prompts: [MULTI_TURN_FIRST_PROMPT, MULTI_TURN_SECOND_PROMPT],
|
||||
defaultTranscriptFile: "fixtures/multi_turn/claude_transcript.ndjson",
|
||||
queryMode: "streaming",
|
||||
enableTools: true,
|
||||
permissionMode: "bypassPermissions",
|
||||
allowDangerouslySkipPermissions: true,
|
||||
},
|
||||
multi_turn_restart: {
|
||||
prompts: [MULTI_TURN_FIRST_PROMPT, MULTI_TURN_SECOND_PROMPT],
|
||||
defaultTranscriptFile: "fixtures/multi_turn_restart/claude_transcript.ndjson",
|
||||
queryMode: "restart",
|
||||
enableTools: true,
|
||||
permissionMode: "bypassPermissions",
|
||||
allowDangerouslySkipPermissions: true,
|
||||
},
|
||||
tool_call_read_only: {
|
||||
prompts: [TOOL_CALL_READ_ONLY_PROMPT],
|
||||
defaultTranscriptFile: "fixtures/tool_call_read_only/claude_transcript.ndjson",
|
||||
queryMode: "streaming",
|
||||
enableTools: true,
|
||||
permissionMode: "default",
|
||||
enablePermissionCallback: true,
|
||||
runtimePolicyOverride: READ_ONLY_NEVER_POLICY,
|
||||
},
|
||||
tool_call_read_only_on_request: {
|
||||
prompts: [TOOL_CALL_WRITE_PROMPT],
|
||||
defaultTranscriptFile: "fixtures/tool_call_read_only_on_request/claude_transcript.ndjson",
|
||||
queryMode: "streaming",
|
||||
enableTools: true,
|
||||
permissionMode: "default",
|
||||
enablePermissionCallback: true,
|
||||
runtimePolicyOverride: READ_ONLY_ON_REQUEST_POLICY,
|
||||
},
|
||||
tool_call_workspace_never: {
|
||||
prompts: [TOOL_CALL_WRITE_PROMPT],
|
||||
defaultTranscriptFile: "fixtures/tool_call_workspace_never/claude_transcript.ndjson",
|
||||
queryMode: "streaming",
|
||||
enableTools: true,
|
||||
permissionMode: "bypassPermissions",
|
||||
allowDangerouslySkipPermissions: true,
|
||||
runtimePolicyOverride: WORKSPACE_NEVER_POLICY,
|
||||
},
|
||||
tool_call_restricted_granular: {
|
||||
prompts: [TOOL_CALL_WRITE_PROMPT],
|
||||
defaultTranscriptFile: "fixtures/tool_call_restricted_granular/claude_transcript.ndjson",
|
||||
queryMode: "streaming",
|
||||
enableTools: true,
|
||||
permissionMode: "default",
|
||||
enablePermissionCallback: true,
|
||||
runtimePolicyOverride: RESTRICTED_GRANULAR_POLICY,
|
||||
},
|
||||
web_search: {
|
||||
prompts: [WEB_SEARCH_PROMPT],
|
||||
defaultTranscriptFile: "fixtures/web_search/claude_transcript.ndjson",
|
||||
queryMode: "streaming",
|
||||
enableTools: true,
|
||||
permissionMode: "bypassPermissions",
|
||||
allowDangerouslySkipPermissions: true,
|
||||
},
|
||||
} as const;
|
||||
|
||||
@@ -140,12 +139,77 @@ function selectedPrompts(): ReadonlyArray<string> {
|
||||
return recording.prompts;
|
||||
}
|
||||
|
||||
function runtimePolicyForRecording(input: {
|
||||
readonly cwd: string;
|
||||
readonly override?: RuntimePolicyV2Override;
|
||||
}): ProviderAdapterV2RuntimePolicyType {
|
||||
return ProviderAdapterV2RuntimePolicy.make({
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
cwd: input.override?.cwd ?? input.cwd,
|
||||
...(input.override?.approvalPolicy === undefined
|
||||
? {}
|
||||
: { approvalPolicy: input.override.approvalPolicy }),
|
||||
...(input.override?.sandboxPolicy === undefined
|
||||
? {}
|
||||
: { sandboxPolicy: input.override.sandboxPolicy }),
|
||||
...(input.override?.reasoningEffort === undefined
|
||||
? {}
|
||||
: { reasoningEffort: input.override.reasoningEffort }),
|
||||
});
|
||||
}
|
||||
|
||||
async function makeToolCallReadOnlyRecordingWorkspace(): Promise<string> {
|
||||
await rm(TOOL_CALL_READ_ONLY_WORKSPACE_ROOT, { recursive: true, force: true });
|
||||
await mkdir(TOOL_CALL_READ_ONLY_WORKSPACE_ROOT, { recursive: true });
|
||||
return TOOL_CALL_READ_ONLY_WORKSPACE_ROOT;
|
||||
}
|
||||
|
||||
const cwd =
|
||||
process.env.T3_CLAUDE_REPLAY_CWD ??
|
||||
(await makeCheckpointWorkspace(`claude-agent-sdk-record-${scenario}`));
|
||||
(scenario === "tool_call_read_only"
|
||||
? await makeToolCallReadOnlyRecordingWorkspace()
|
||||
: await makeCheckpointWorkspace(`claude-agent-sdk-record-${scenario}`));
|
||||
const shouldRemoveCwd = process.env.T3_CLAUDE_REPLAY_CWD === undefined;
|
||||
|
||||
if (shouldRemoveCwd && scenario === "tool_call_read_only") {
|
||||
await writeFile(
|
||||
path.join(cwd, "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "claude-read-only-fixture",
|
||||
private: true,
|
||||
scripts: { typecheck: "tsc --noEmit" },
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
await writeFile(
|
||||
path.join(cwd, "tsconfig.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
compilerOptions: {
|
||||
module: "ESNext",
|
||||
strict: true,
|
||||
target: "ES2022",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const runtimePolicy = runtimePolicyForRecording({
|
||||
cwd,
|
||||
...("runtimePolicyOverride" in recording ? { override: recording.runtimePolicyOverride } : {}),
|
||||
});
|
||||
const queryPolicy = claudeRuntimeQueryPolicyForRuntimePolicy(runtimePolicy);
|
||||
|
||||
const transcript = await recordClaudeAgentSdkReplayTranscript({
|
||||
scenario,
|
||||
prompts: selectedPrompts(),
|
||||
@@ -159,13 +223,13 @@ try {
|
||||
: { sessionId: process.env.T3_CLAUDE_REPLAY_SESSION_ID }),
|
||||
queryMode: selectedQueryMode(recording.queryMode),
|
||||
...("enableTools" in recording && recording.enableTools === true ? { enableTools: true } : {}),
|
||||
...("permissionMode" in recording ? { permissionMode: recording.permissionMode } : {}),
|
||||
...("allowDangerouslySkipPermissions" in recording
|
||||
? { allowDangerouslySkipPermissions: recording.allowDangerouslySkipPermissions }
|
||||
: {}),
|
||||
...("enablePermissionCallback" in recording
|
||||
? { enablePermissionCallback: recording.enablePermissionCallback }
|
||||
: {}),
|
||||
...(queryPolicy.tools === undefined ? {} : { tools: queryPolicy.tools }),
|
||||
permissionMode: queryPolicy.permissionMode,
|
||||
...(queryPolicy.allowedTools === undefined ? {} : { allowedTools: queryPolicy.allowedTools }),
|
||||
...(queryPolicy.allowDangerouslySkipPermissions === undefined
|
||||
? {}
|
||||
: { allowDangerouslySkipPermissions: queryPolicy.allowDangerouslySkipPermissions }),
|
||||
...(queryPolicy.installPermissionCallback ? { enablePermissionCallback: true } : {}),
|
||||
});
|
||||
await mkdir(path.dirname(outputPath), { recursive: true });
|
||||
await writeFile(outputPath, encodeTranscriptNdjson(transcript), "utf8");
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
|
||||
import { ProviderAdapterV2RuntimePolicy } from "../ProviderAdapter.ts";
|
||||
import {
|
||||
CLAUDE_READ_ONLY_ALLOWED_TOOLS,
|
||||
claudeRuntimeQueryPolicyForRuntimePolicy,
|
||||
} from "./ClaudeAdapterV2.ts";
|
||||
|
||||
describe("ClaudeAdapterV2 runtime query policy", () => {
|
||||
it("maps canonical read-only never policy to Claude dontAsk with read-only tools", () => {
|
||||
const queryPolicy = claudeRuntimeQueryPolicyForRuntimePolicy(
|
||||
ProviderAdapterV2RuntimePolicy.make({
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
cwd: "/workspace",
|
||||
approvalPolicy: "never",
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
assert.deepEqual(queryPolicy, {
|
||||
permissionMode: "dontAsk",
|
||||
tools: CLAUDE_READ_ONLY_ALLOWED_TOOLS,
|
||||
allowedTools: CLAUDE_READ_ONLY_ALLOWED_TOOLS,
|
||||
installPermissionCallback: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("maps canonical read-only on-request policy to Claude default with callbacks", () => {
|
||||
const queryPolicy = claudeRuntimeQueryPolicyForRuntimePolicy(
|
||||
ProviderAdapterV2RuntimePolicy.make({
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
cwd: "/workspace",
|
||||
approvalPolicy: "on-request",
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
assert.deepEqual(queryPolicy, {
|
||||
permissionMode: "default",
|
||||
installPermissionCallback: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not auto-allow reads for canonical restricted read-only never policy", () => {
|
||||
const queryPolicy = claudeRuntimeQueryPolicyForRuntimePolicy(
|
||||
ProviderAdapterV2RuntimePolicy.make({
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
cwd: "/workspace",
|
||||
approvalPolicy: "never",
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: {
|
||||
type: "restricted",
|
||||
includePlatformDefaults: false,
|
||||
readableRoots: [],
|
||||
},
|
||||
networkAccess: false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
assert.deepEqual(queryPolicy, {
|
||||
permissionMode: "dontAsk",
|
||||
tools: CLAUDE_READ_ONLY_ALLOWED_TOOLS,
|
||||
installPermissionCallback: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("maps default full-access policy to Claude bypass permissions", () => {
|
||||
const queryPolicy = claudeRuntimeQueryPolicyForRuntimePolicy(
|
||||
ProviderAdapterV2RuntimePolicy.make({
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
cwd: "/workspace",
|
||||
}),
|
||||
);
|
||||
|
||||
assert.deepEqual(queryPolicy, {
|
||||
permissionMode: "bypassPermissions",
|
||||
allowDangerouslySkipPermissions: true,
|
||||
installPermissionCallback: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
type ClaudeAgentSdkQueryOpenInput,
|
||||
type ClaudeAgentSdkQueryOptions,
|
||||
type ClaudeAgentSdkQuerySession,
|
||||
type ClaudeAgentSdkQueryTools,
|
||||
} from "./ClaudeAdapterV2.ts";
|
||||
import { layer as idAllocatorLayer } from "../IdAllocator.ts";
|
||||
import { ProviderAdapterDriverCreateError } from "../ProviderAdapterDriver.ts";
|
||||
@@ -299,6 +300,9 @@ function stableClaudeQueryOptions(options: ClaudeAgentSdkQueryOptions): ClaudeAg
|
||||
model: options.model,
|
||||
tools: options.tools,
|
||||
permissionMode: options.permissionMode,
|
||||
...(options.allowedTools === undefined ? {} : { allowedTools: options.allowedTools }),
|
||||
...(options.disallowedTools === undefined ? {} : { disallowedTools: options.disallowedTools }),
|
||||
...(options.settings === undefined ? {} : { settings: options.settings }),
|
||||
...(options.allowDangerouslySkipPermissions === true
|
||||
? { allowDangerouslySkipPermissions: true }
|
||||
: {}),
|
||||
@@ -783,7 +787,10 @@ async function recordClaudeStreamingQuery(input: {
|
||||
readonly sessionId: string;
|
||||
readonly entries: Array<ProviderReplayEntry>;
|
||||
readonly enableTools?: boolean;
|
||||
readonly tools?: ClaudeAgentSdkQueryTools;
|
||||
readonly permissionMode?: ClaudeAgentSdkQueryOptions["permissionMode"];
|
||||
readonly allowedTools?: ReadonlyArray<string>;
|
||||
readonly disallowedTools?: ReadonlyArray<string>;
|
||||
readonly allowDangerouslySkipPermissions?: boolean;
|
||||
readonly enablePermissionCallback?: boolean;
|
||||
readonly permissionDecision?: ProviderApprovalDecision;
|
||||
@@ -825,8 +832,12 @@ async function recordClaudeStreamingQuery(input: {
|
||||
cwd: input.cwd,
|
||||
...(input.enableTools === true
|
||||
? {
|
||||
tools: { type: "preset", preset: "claude_code" },
|
||||
tools: input.tools ?? { type: "preset", preset: "claude_code" },
|
||||
permissionMode: input.permissionMode ?? "default",
|
||||
...(input.allowedTools === undefined ? {} : { allowedTools: input.allowedTools }),
|
||||
...(input.disallowedTools === undefined
|
||||
? {}
|
||||
: { disallowedTools: input.disallowedTools }),
|
||||
...(input.allowDangerouslySkipPermissions === true
|
||||
? { allowDangerouslySkipPermissions: true }
|
||||
: {}),
|
||||
@@ -888,7 +899,10 @@ async function recordClaudeRestartingQueries(input: {
|
||||
readonly sessionId: string;
|
||||
readonly entries: Array<ProviderReplayEntry>;
|
||||
readonly enableTools?: boolean;
|
||||
readonly tools?: ClaudeAgentSdkQueryTools;
|
||||
readonly permissionMode?: ClaudeAgentSdkQueryOptions["permissionMode"];
|
||||
readonly allowedTools?: ReadonlyArray<string>;
|
||||
readonly disallowedTools?: ReadonlyArray<string>;
|
||||
readonly allowDangerouslySkipPermissions?: boolean;
|
||||
}): Promise<void> {
|
||||
for (const [index, prompt] of input.prompts.entries()) {
|
||||
@@ -900,8 +914,12 @@ async function recordClaudeRestartingQueries(input: {
|
||||
cwd: input.cwd,
|
||||
...(input.enableTools === true
|
||||
? {
|
||||
tools: { type: "preset", preset: "claude_code" },
|
||||
tools: input.tools ?? { type: "preset", preset: "claude_code" },
|
||||
permissionMode: input.permissionMode ?? "default",
|
||||
...(input.allowedTools === undefined ? {} : { allowedTools: input.allowedTools }),
|
||||
...(input.disallowedTools === undefined
|
||||
? {}
|
||||
: { disallowedTools: input.disallowedTools }),
|
||||
...(input.allowDangerouslySkipPermissions === true
|
||||
? { allowDangerouslySkipPermissions: true }
|
||||
: {}),
|
||||
@@ -968,7 +986,10 @@ export async function recordClaudeAgentSdkReplayTranscript(input: {
|
||||
readonly sessionId?: string;
|
||||
readonly queryMode?: "streaming" | "restart";
|
||||
readonly enableTools?: boolean;
|
||||
readonly tools?: ClaudeAgentSdkQueryTools;
|
||||
readonly permissionMode?: ClaudeAgentSdkQueryOptions["permissionMode"];
|
||||
readonly allowedTools?: ReadonlyArray<string>;
|
||||
readonly disallowedTools?: ReadonlyArray<string>;
|
||||
readonly allowDangerouslySkipPermissions?: boolean;
|
||||
readonly enablePermissionCallback?: boolean;
|
||||
readonly permissionDecision?: ProviderApprovalDecision;
|
||||
@@ -991,7 +1012,10 @@ export async function recordClaudeAgentSdkReplayTranscript(input: {
|
||||
sessionId,
|
||||
entries,
|
||||
...(input.enableTools === undefined ? {} : { enableTools: input.enableTools }),
|
||||
...(input.tools === undefined ? {} : { tools: input.tools }),
|
||||
...(input.permissionMode === undefined ? {} : { permissionMode: input.permissionMode }),
|
||||
...(input.allowedTools === undefined ? {} : { allowedTools: input.allowedTools }),
|
||||
...(input.disallowedTools === undefined ? {} : { disallowedTools: input.disallowedTools }),
|
||||
...(input.allowDangerouslySkipPermissions === undefined
|
||||
? {}
|
||||
: { allowDangerouslySkipPermissions: input.allowDangerouslySkipPermissions }),
|
||||
@@ -1011,7 +1035,10 @@ export async function recordClaudeAgentSdkReplayTranscript(input: {
|
||||
sessionId,
|
||||
entries,
|
||||
...(input.enableTools === undefined ? {} : { enableTools: input.enableTools }),
|
||||
...(input.tools === undefined ? {} : { tools: input.tools }),
|
||||
...(input.permissionMode === undefined ? {} : { permissionMode: input.permissionMode }),
|
||||
...(input.allowedTools === undefined ? {} : { allowedTools: input.allowedTools }),
|
||||
...(input.disallowedTools === undefined ? {} : { disallowedTools: input.disallowedTools }),
|
||||
...(input.allowDangerouslySkipPermissions === undefined
|
||||
? {}
|
||||
: { allowDangerouslySkipPermissions: input.allowDangerouslySkipPermissions }),
|
||||
@@ -1028,8 +1055,10 @@ export async function recordClaudeAgentSdkReplayTranscript(input: {
|
||||
model: input.modelSelection.model,
|
||||
nativeSessionId: sessionId,
|
||||
queryMode,
|
||||
tools: input.enableTools === true ? "claude_code" : "none",
|
||||
tools: input.enableTools === true ? (input.tools ?? "claude_code") : "none",
|
||||
...(input.permissionMode === undefined ? {} : { permissionMode: input.permissionMode }),
|
||||
...(input.allowedTools === undefined ? {} : { allowedTools: input.allowedTools }),
|
||||
...(input.disallowedTools === undefined ? {} : { disallowedTools: input.disallowedTools }),
|
||||
...(input.enablePermissionCallback === undefined
|
||||
? {}
|
||||
: { enablePermissionCallback: input.enablePermissionCallback }),
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
type PermissionMode,
|
||||
type PermissionResult,
|
||||
type Query as ClaudeQuery,
|
||||
type Settings as ClaudeSdkSettings,
|
||||
type SDKAssistantMessage,
|
||||
type SDKMessage,
|
||||
type SDKResultMessage,
|
||||
@@ -30,21 +31,20 @@ import {
|
||||
type ProviderInstanceId,
|
||||
type ProviderRequestKind,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
Cause,
|
||||
Context,
|
||||
DateTime,
|
||||
Deferred,
|
||||
Effect,
|
||||
Exit,
|
||||
Layer,
|
||||
Path,
|
||||
Queue,
|
||||
Random,
|
||||
Ref,
|
||||
Schema,
|
||||
Stream,
|
||||
} from "effect";
|
||||
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Context from "effect/Context";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as Random from "effect/Random";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import { makeClaudeEnvironment } from "../../provider/Drivers/ClaudeHome.ts";
|
||||
import { mergeProviderInstanceEnvironment } from "../../provider/ProviderInstanceEnvironment.ts";
|
||||
@@ -177,6 +177,30 @@ const CLAUDE_CODE_PRESET_TOOLS = {
|
||||
preset: "claude_code",
|
||||
} satisfies NonNullable<ClaudeQueryOptions["tools"]>;
|
||||
|
||||
export type ClaudeAgentSdkQueryToolList = ReadonlyArray<string>;
|
||||
export interface ClaudeAgentSdkQueryPresetTools {
|
||||
readonly type: "preset";
|
||||
readonly preset: "claude_code";
|
||||
}
|
||||
export type ClaudeAgentSdkQueryTools = ClaudeAgentSdkQueryToolList | ClaudeAgentSdkQueryPresetTools;
|
||||
|
||||
export const CLAUDE_READ_ONLY_ALLOWED_TOOLS = ["Read", "Glob", "Grep"] as const;
|
||||
|
||||
function claudeAgentSdkQueryToolsForSdk(
|
||||
tools: ClaudeAgentSdkQueryTools,
|
||||
): NonNullable<ClaudeQueryOptions["tools"]> {
|
||||
if (isClaudeAgentSdkQueryToolList(tools)) {
|
||||
return [...tools];
|
||||
}
|
||||
return { type: tools.type, preset: tools.preset };
|
||||
}
|
||||
|
||||
function isClaudeAgentSdkQueryToolList(
|
||||
tools: ClaudeAgentSdkQueryTools,
|
||||
): tools is ClaudeAgentSdkQueryToolList {
|
||||
return Array.isArray(tools);
|
||||
}
|
||||
|
||||
type ClaudeAgentSdkThreadIdentity =
|
||||
| {
|
||||
readonly sessionId: string;
|
||||
@@ -299,8 +323,11 @@ export function makeClaudeQueryOptions(input: {
|
||||
readonly resume: boolean;
|
||||
readonly cwd: string | null;
|
||||
readonly settings?: ClaudeSettings;
|
||||
readonly sdkSettings?: string | ClaudeSdkSettings;
|
||||
readonly environment?: NodeJS.ProcessEnv;
|
||||
readonly tools?: NonNullable<ClaudeQueryOptions["tools"]>;
|
||||
readonly tools?: ClaudeAgentSdkQueryTools;
|
||||
readonly allowedTools?: ReadonlyArray<string>;
|
||||
readonly disallowedTools?: ReadonlyArray<string>;
|
||||
readonly permissionMode?: PermissionMode;
|
||||
readonly canUseTool?: CanUseTool;
|
||||
readonly allowDangerouslySkipPermissions?: boolean;
|
||||
@@ -310,15 +337,19 @@ export function makeClaudeQueryOptions(input: {
|
||||
const threadIdentity: ClaudeAgentSdkThreadIdentity = input.resume
|
||||
? { resume: input.nativeThreadId }
|
||||
: { sessionId: input.nativeThreadId };
|
||||
const selectedTools = input.tools ?? CLAUDE_CODE_PRESET_TOOLS;
|
||||
const options: ClaudeAgentSdkQueryOptions = {
|
||||
model: input.modelSelection.model,
|
||||
tools: input.tools ?? [],
|
||||
tools: claudeAgentSdkQueryToolsForSdk(selectedTools),
|
||||
permissionMode: input.permissionMode ?? "default",
|
||||
...threadIdentity,
|
||||
...(input.allowedTools === undefined ? {} : { allowedTools: [...input.allowedTools] }),
|
||||
...(input.disallowedTools === undefined ? {} : { disallowedTools: [...input.disallowedTools] }),
|
||||
...(input.canUseTool === undefined ? {} : { canUseTool: input.canUseTool }),
|
||||
...(input.allowDangerouslySkipPermissions === true
|
||||
? { allowDangerouslySkipPermissions: true }
|
||||
: {}),
|
||||
...(input.sdkSettings === undefined ? {} : { settings: input.sdkSettings }),
|
||||
...(input.settings?.binaryPath
|
||||
? { pathToClaudeCodeExecutable: input.settings.binaryPath }
|
||||
: {}),
|
||||
@@ -479,6 +510,35 @@ function assertNever(value: never): never {
|
||||
throw new Error(`Unhandled Claude SDK variant: ${jsonStringifyForTool(value)}`);
|
||||
}
|
||||
|
||||
const ClaudeRuntimeSandboxPolicyKind = Schema.Struct({
|
||||
type: Schema.Literals(["dangerFullAccess", "externalSandbox", "readOnly", "workspaceWrite"]),
|
||||
});
|
||||
type ClaudeRuntimeSandboxPolicy = typeof ClaudeRuntimeSandboxPolicyKind.Type;
|
||||
type ClaudeRuntimeSandboxPolicyKindName = ClaudeRuntimeSandboxPolicy["type"];
|
||||
|
||||
const ClaudeRuntimeReadOnlyFullAccessSandboxPolicy = Schema.Struct({
|
||||
type: Schema.Literal("readOnly"),
|
||||
access: Schema.Struct({
|
||||
type: Schema.Literal("fullAccess"),
|
||||
}),
|
||||
});
|
||||
|
||||
function sandboxPolicyKindForClaudeRuntimePolicy(
|
||||
runtimePolicy: ProviderAdapterV2RuntimePolicy,
|
||||
): ClaudeRuntimeSandboxPolicyKindName | undefined {
|
||||
return runtimePolicy.sandboxPolicy !== undefined &&
|
||||
Schema.is(ClaudeRuntimeSandboxPolicyKind)(runtimePolicy.sandboxPolicy)
|
||||
? runtimePolicy.sandboxPolicy.type
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function readOnlyPolicyAllowsGlobalReads(runtimePolicy: ProviderAdapterV2RuntimePolicy): boolean {
|
||||
return (
|
||||
runtimePolicy.sandboxPolicy !== undefined &&
|
||||
Schema.is(ClaudeRuntimeReadOnlyFullAccessSandboxPolicy)(runtimePolicy.sandboxPolicy)
|
||||
);
|
||||
}
|
||||
|
||||
function permissionModeForClaudeRuntimePolicy(
|
||||
runtimePolicy: ProviderAdapterV2RuntimePolicy,
|
||||
): PermissionMode {
|
||||
@@ -489,6 +549,17 @@ function permissionModeForClaudeRuntimePolicy(
|
||||
return "default";
|
||||
}
|
||||
|
||||
switch (sandboxPolicyKindForClaudeRuntimePolicy(runtimePolicy)) {
|
||||
case "readOnly":
|
||||
return "dontAsk";
|
||||
case "dangerFullAccess":
|
||||
return "bypassPermissions";
|
||||
case "externalSandbox":
|
||||
case "workspaceWrite":
|
||||
case undefined:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (runtimePolicy.runtimeMode) {
|
||||
case "approval-required":
|
||||
return "default";
|
||||
@@ -499,10 +570,66 @@ function permissionModeForClaudeRuntimePolicy(
|
||||
}
|
||||
}
|
||||
|
||||
function shouldInstallClaudePermissionCallback(
|
||||
export interface ClaudeRuntimeQueryPolicy {
|
||||
readonly permissionMode: PermissionMode;
|
||||
readonly tools?: ClaudeAgentSdkQueryTools;
|
||||
readonly allowedTools?: ReadonlyArray<string>;
|
||||
readonly allowDangerouslySkipPermissions?: true;
|
||||
readonly installPermissionCallback: boolean;
|
||||
}
|
||||
|
||||
export function claudeRuntimeQueryPolicyForRuntimePolicy(
|
||||
runtimePolicy: ProviderAdapterV2RuntimePolicy,
|
||||
): boolean {
|
||||
return permissionModeForClaudeRuntimePolicy(runtimePolicy) !== "bypassPermissions";
|
||||
): ClaudeRuntimeQueryPolicy {
|
||||
const permissionMode = permissionModeForClaudeRuntimePolicy(runtimePolicy);
|
||||
const readOnlyTools =
|
||||
permissionMode === "dontAsk" &&
|
||||
sandboxPolicyKindForClaudeRuntimePolicy(runtimePolicy) === "readOnly"
|
||||
? CLAUDE_READ_ONLY_ALLOWED_TOOLS
|
||||
: undefined;
|
||||
const allowedTools =
|
||||
readOnlyTools !== undefined && readOnlyPolicyAllowsGlobalReads(runtimePolicy)
|
||||
? readOnlyTools
|
||||
: undefined;
|
||||
|
||||
if (permissionMode === "plan") {
|
||||
return {
|
||||
permissionMode,
|
||||
...(readOnlyTools === undefined ? {} : { tools: readOnlyTools }),
|
||||
...(allowedTools === undefined ? {} : { allowedTools }),
|
||||
installPermissionCallback: false,
|
||||
};
|
||||
}
|
||||
|
||||
const installPermissionCallback =
|
||||
runtimePolicy.approvalPolicy === undefined
|
||||
? runtimePolicy.runtimeMode === "approval-required"
|
||||
: runtimePolicy.approvalPolicy !== "never";
|
||||
|
||||
return {
|
||||
permissionMode,
|
||||
...(readOnlyTools === undefined ? {} : { tools: readOnlyTools }),
|
||||
...(allowedTools === undefined ? {} : { allowedTools }),
|
||||
...(permissionMode === "bypassPermissions" ? { allowDangerouslySkipPermissions: true } : {}),
|
||||
installPermissionCallback,
|
||||
};
|
||||
}
|
||||
|
||||
function shouldInstallClaudePermissionCallback(policy: ClaudeRuntimeQueryPolicy): boolean {
|
||||
if (policy.permissionMode === "plan") {
|
||||
return false;
|
||||
}
|
||||
return policy.installPermissionCallback;
|
||||
}
|
||||
|
||||
function claudeRuntimeQueryPolicyKey(policy: ClaudeRuntimeQueryPolicy): string {
|
||||
return JSON.stringify({
|
||||
permissionMode: policy.permissionMode,
|
||||
tools: policy.tools,
|
||||
allowedTools: policy.allowedTools,
|
||||
allowDangerouslySkipPermissions: policy.allowDangerouslySkipPermissions,
|
||||
installPermissionCallback: policy.installPermissionCallback,
|
||||
});
|
||||
}
|
||||
|
||||
type ClaudeToolItemType = Extract<
|
||||
@@ -1046,7 +1173,7 @@ interface ActiveClaudeTurnContext {
|
||||
interface ClaudeLiveQueryContext {
|
||||
readonly nativeThreadId: string;
|
||||
readonly query: ClaudeAgentSdkQuerySession;
|
||||
readonly permissionMode: PermissionMode;
|
||||
readonly queryPolicyKey: string;
|
||||
currentModel: string;
|
||||
}
|
||||
|
||||
@@ -1696,12 +1823,13 @@ export function makeClaudeAdapterV2(
|
||||
turnInput: ProviderAdapterV2TurnInput,
|
||||
nativeThreadId: string,
|
||||
) {
|
||||
const permissionMode = permissionModeForClaudeRuntimePolicy(turnInput.runtimePolicy);
|
||||
const queryPolicy = claudeRuntimeQueryPolicyForRuntimePolicy(turnInput.runtimePolicy);
|
||||
const queryPolicyKey = claudeRuntimeQueryPolicyKey(queryPolicy);
|
||||
const existing = yield* Ref.get(queryContext);
|
||||
if (
|
||||
existing !== null &&
|
||||
existing.nativeThreadId === nativeThreadId &&
|
||||
existing.permissionMode === permissionMode
|
||||
existing.queryPolicyKey === queryPolicyKey
|
||||
) {
|
||||
if (existing.currentModel !== turnInput.modelSelection.model) {
|
||||
yield* existing.query.setModel(turnInput.modelSelection.model);
|
||||
@@ -1723,20 +1851,21 @@ export function makeClaudeAdapterV2(
|
||||
cwd: turnInput.runtimePolicy.cwd,
|
||||
settings: adapterOptions.settings,
|
||||
environment: adapterOptions.environment,
|
||||
tools: CLAUDE_CODE_PRESET_TOOLS,
|
||||
permissionMode,
|
||||
...(permissionMode === "bypassPermissions"
|
||||
? { allowDangerouslySkipPermissions: true }
|
||||
: {}),
|
||||
...(shouldInstallClaudePermissionCallback(turnInput.runtimePolicy)
|
||||
? { canUseTool }
|
||||
: {}),
|
||||
tools: queryPolicy.tools ?? CLAUDE_CODE_PRESET_TOOLS,
|
||||
...(queryPolicy.allowedTools === undefined
|
||||
? {}
|
||||
: { allowedTools: queryPolicy.allowedTools }),
|
||||
permissionMode: queryPolicy.permissionMode,
|
||||
...(queryPolicy.allowDangerouslySkipPermissions === undefined
|
||||
? {}
|
||||
: { allowDangerouslySkipPermissions: queryPolicy.allowDangerouslySkipPermissions }),
|
||||
...(shouldInstallClaudePermissionCallback(queryPolicy) ? { canUseTool } : {}),
|
||||
}),
|
||||
});
|
||||
const context: ClaudeLiveQueryContext = {
|
||||
nativeThreadId,
|
||||
query: querySession,
|
||||
permissionMode,
|
||||
queryPolicyKey,
|
||||
currentModel: turnInput.modelSelection.model,
|
||||
};
|
||||
yield* Ref.set(queryContext, context);
|
||||
|
||||
@@ -18,6 +18,8 @@ import { assertThreadRollbackOutput } from "./thread_rollback/codex_output.ts";
|
||||
import { threadRollbackInput } from "./thread_rollback/input.ts";
|
||||
import { assertTodoListOutput } from "./todo_list/codex_output.ts";
|
||||
import { todoListInput } from "./todo_list/input.ts";
|
||||
import { assertToolCallReadOnlyClaudeOutput } from "./tool_call_read_only/claude_output.ts";
|
||||
import { toolCallReadOnlyInput } from "./tool_call_read_only/input.ts";
|
||||
import { assertToolCallReadOnlyOnRequestClaudeOutput } from "./tool_call_read_only_on_request/claude_output.ts";
|
||||
import { assertToolCallReadOnlyOnRequestOutput } from "./tool_call_read_only_on_request/codex_output.ts";
|
||||
import { toolCallReadOnlyOnRequestInput } from "./tool_call_read_only_on_request/input.ts";
|
||||
@@ -35,58 +37,13 @@ import { webSearchInput } from "./web_search/input.ts";
|
||||
import {
|
||||
CLAUDE_MODEL_SELECTION,
|
||||
CODEX_MODEL_SELECTION,
|
||||
READ_ONLY_NEVER_POLICY,
|
||||
READ_ONLY_ON_REQUEST_POLICY,
|
||||
RESTRICTED_GRANULAR_POLICY,
|
||||
type OrchestratorReplayFixture,
|
||||
WORKSPACE_NEVER_POLICY,
|
||||
} from "./shared.ts";
|
||||
|
||||
const READ_ONLY_ON_REQUEST_POLICY = {
|
||||
approvalPolicy: "on-request",
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const;
|
||||
|
||||
const READ_ONLY_NEVER_POLICY = {
|
||||
approvalPolicy: "never",
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const;
|
||||
|
||||
const WORKSPACE_NEVER_POLICY = {
|
||||
approvalPolicy: "never",
|
||||
sandboxPolicy: {
|
||||
type: "workspaceWrite",
|
||||
writableRoots: [],
|
||||
readOnlyAccess: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const;
|
||||
|
||||
const RESTRICTED_GRANULAR_POLICY = {
|
||||
approvalPolicy: {
|
||||
granular: {
|
||||
mcp_elicitations: true,
|
||||
request_permissions: true,
|
||||
rules: true,
|
||||
sandbox_approval: true,
|
||||
skill_approval: true,
|
||||
},
|
||||
},
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: {
|
||||
type: "restricted",
|
||||
includePlatformDefaults: false,
|
||||
readableRoots: [],
|
||||
},
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const ORCHESTRATOR_REPLAY_FIXTURES = [
|
||||
{
|
||||
name: "simple",
|
||||
@@ -106,6 +63,19 @@ export const ORCHESTRATOR_REPLAY_FIXTURES = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "tool_call_read_only",
|
||||
buildInput: toolCallReadOnlyInput,
|
||||
providers: [
|
||||
{
|
||||
provider: "claudeAgent",
|
||||
transcriptFile: new URL("./tool_call_read_only/claude_transcript.ndjson", import.meta.url),
|
||||
modelSelection: CLAUDE_MODEL_SELECTION,
|
||||
runtimePolicyOverride: READ_ONLY_NEVER_POLICY,
|
||||
assertOutput: assertToolCallReadOnlyClaudeOutput,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "tool_call_read_only_on_request",
|
||||
buildInput: toolCallReadOnlyOnRequestInput,
|
||||
@@ -336,12 +306,6 @@ export const ORCHESTRATOR_REPLAY_FIXTURES = [
|
||||
},
|
||||
] satisfies ReadonlyArray<OrchestratorReplayFixture>;
|
||||
|
||||
// TODO(claude-v2/tool_call_read_only): add a Claude provider variant to `tool_call_read_only`
|
||||
// after read-only tool behavior has its own real Claude transcript. Use
|
||||
// `tool_call_read_only/input.ts` and compare against
|
||||
// `tool_call_read_only_on_request/claude_transcript.ndjson` for the callback frame shape and
|
||||
// `tool_call_read_only_on_request/codex_transcript.ndjson` for V2 projection expectations.
|
||||
|
||||
// TODO(claude-v2/approvals-denied): add denied write fixtures after the live query runner records
|
||||
// Claude denial callback responses. Cross-reference
|
||||
// `tool_call_read_only_on_request/claude_transcript.ndjson`,
|
||||
|
||||
@@ -34,8 +34,8 @@ export const PROVIDER_THREAD_RESUME_FIRST_PROMPT =
|
||||
"Respond with exactly: provider thread resume fixture first turn complete";
|
||||
export const PROVIDER_THREAD_RESUME_SECOND_PROMPT =
|
||||
"Using the conversation history available in this resumed thread, first repeat the exact final answer you gave in the previous turn. Then on a new line write exactly: provider thread resume fixture second turn complete";
|
||||
export const TOOL_CALL_READ_ONLY_PROMPT =
|
||||
"Read package.json and tsconfig.json from the current workspace, then answer exactly: read only tool fixture complete";
|
||||
export const TOOL_CALL_READ_ONLY_WORKSPACE_ROOT = "/tmp/claude-replay-tool_call_read_only";
|
||||
export const TOOL_CALL_READ_ONLY_PROMPT = `Read ${TOOL_CALL_READ_ONLY_WORKSPACE_ROOT}/package.json and ${TOOL_CALL_READ_ONLY_WORKSPACE_ROOT}/tsconfig.json, then answer exactly: read only tool fixture complete`;
|
||||
export const TOOL_CALL_WRITE_PROMPT =
|
||||
"Create or overwrite .codex-probe-write-action.txt with exactly this text: codex app-server approval fixture. Use a local shell command or file edit only, then briefly report what happened. Do not read package metadata, use GitHub, use web, or use MCP.";
|
||||
export const SUBAGENT_PROMPT =
|
||||
@@ -139,6 +139,55 @@ export const CLAUDE_MODEL_SELECTION = {
|
||||
model: "claude-sonnet-4-6",
|
||||
} satisfies ModelSelection;
|
||||
|
||||
export const READ_ONLY_ON_REQUEST_POLICY = {
|
||||
approvalPolicy: "on-request",
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const satisfies RuntimePolicyV2Override;
|
||||
|
||||
export const READ_ONLY_NEVER_POLICY = {
|
||||
approvalPolicy: "never",
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const satisfies RuntimePolicyV2Override;
|
||||
|
||||
export const WORKSPACE_NEVER_POLICY = {
|
||||
approvalPolicy: "never",
|
||||
sandboxPolicy: {
|
||||
type: "workspaceWrite",
|
||||
writableRoots: [],
|
||||
readOnlyAccess: { type: "fullAccess" },
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const satisfies RuntimePolicyV2Override;
|
||||
|
||||
export const RESTRICTED_GRANULAR_POLICY = {
|
||||
approvalPolicy: {
|
||||
granular: {
|
||||
mcp_elicitations: true,
|
||||
request_permissions: true,
|
||||
rules: true,
|
||||
sandbox_approval: true,
|
||||
skill_approval: true,
|
||||
},
|
||||
},
|
||||
sandboxPolicy: {
|
||||
type: "readOnly",
|
||||
access: {
|
||||
type: "restricted",
|
||||
includePlatformDefaults: false,
|
||||
readableRoots: [],
|
||||
},
|
||||
networkAccess: false,
|
||||
},
|
||||
} as const satisfies RuntimePolicyV2Override;
|
||||
|
||||
export function createThreadCommand(input: {
|
||||
readonly commandId: CommandId;
|
||||
readonly ids: FixtureIds;
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
import { assert } from "@effect/vitest";
|
||||
import type { ProviderReplayTranscript } from "@t3tools/contracts";
|
||||
|
||||
import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
|
||||
import {
|
||||
assertAssistantTextIncludes,
|
||||
assertBaseProjection,
|
||||
assertReplayLabelPrefixCount,
|
||||
assertRuntimeRequestCounts,
|
||||
assertSemanticProjectionIntegrity,
|
||||
assertTurnItemTypes,
|
||||
assertUserMessagesInclude,
|
||||
assertVisibleTurnItemsMirrorLocalTurnItems,
|
||||
projectionFor,
|
||||
TOOL_CALL_READ_ONLY_PROMPT,
|
||||
} from "../shared.ts";
|
||||
|
||||
export function assertToolCallReadOnlyClaudeOutput(
|
||||
result: OrchestratorV2ScenarioResult,
|
||||
transcript: ProviderReplayTranscript,
|
||||
) {
|
||||
assertBaseProjection({ result, transcript, runCount: 1, runStatuses: ["completed"] });
|
||||
|
||||
const projection = projectionFor(result, transcript.scenario);
|
||||
assertSemanticProjectionIntegrity(projection);
|
||||
assertVisibleTurnItemsMirrorLocalTurnItems(projection);
|
||||
assertTurnItemTypes(projection, ["user_message", "dynamic_tool", "assistant_message"]);
|
||||
assertUserMessagesInclude(projection, [TOOL_CALL_READ_ONLY_PROMPT]);
|
||||
assertAssistantTextIncludes(projection, "read only tool fixture complete");
|
||||
assertRuntimeRequestCounts(projection, { total: 0 });
|
||||
assertReplayLabelPrefixCount(transcript, "permission.request:", 0);
|
||||
assertReplayLabelPrefixCount(transcript, "permission.response:", 0);
|
||||
assert.notInclude(JSON.stringify(transcript.entries), '"is_error":true');
|
||||
assert.notInclude(JSON.stringify(transcript.entries), "File does not exist");
|
||||
|
||||
const dynamicTools = projection.turnItems.filter((item) => item.type === "dynamic_tool");
|
||||
assert.lengthOf(dynamicTools, 2);
|
||||
assert.lengthOf(
|
||||
dynamicTools.filter((item) => item.toolName === "Glob"),
|
||||
0,
|
||||
"Claude should not need discovery errors for this deterministic read-only fixture",
|
||||
);
|
||||
assert.lengthOf(
|
||||
dynamicTools.filter((item) => item.toolName === "Read"),
|
||||
2,
|
||||
"Claude must project Read file tool calls",
|
||||
);
|
||||
assert.isTrue(
|
||||
dynamicTools.some((item) =>
|
||||
JSON.stringify(item.output ?? null).includes("claude-read-only-fixture"),
|
||||
),
|
||||
"Claude must read package.json contents",
|
||||
);
|
||||
assert.isTrue(
|
||||
dynamicTools.some((item) => JSON.stringify(item.output ?? null).includes("ESNext")),
|
||||
"Claude must read tsconfig.json contents",
|
||||
);
|
||||
assert.lengthOf(
|
||||
projection.turnItems.filter((item) => item.type === "approval_request"),
|
||||
0,
|
||||
);
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{"type":"transcript_start","provider":"claudeAgent","protocol":"claude-agent-sdk.query","version":"0.2.111","scenario":"tool_call_read_only","metadata":{"prompts":["Read /tmp/claude-replay-tool_call_read_only/package.json and /tmp/claude-replay-tool_call_read_only/tsconfig.json, then answer exactly: read only tool fixture complete"],"model":"claude-sonnet-4-6","nativeSessionId":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","queryMode":"streaming","tools":["Read","Glob","Grep"],"permissionMode":"dontAsk","allowedTools":["Read","Glob","Grep"],"generatedBy":"recordClaudeAgentSdkReplayTranscript"}}
|
||||
{"type":"expect_outbound","label":"query.open","frame":{"type":"query.open","options":{"model":"claude-sonnet-4-6","tools":["Read","Glob","Grep"],"permissionMode":"dontAsk","allowedTools":["Read","Glob","Grep"],"sessionId":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9"}}}
|
||||
{"type":"expect_outbound","label":"prompt.offer:1","frame":{"type":"prompt.offer","message":{"type":"user","message":{"role":"user","content":"Read /tmp/claude-replay-tool_call_read_only/package.json and /tmp/claude-replay-tool_call_read_only/tsconfig.json, then answer exactly: read only tool fixture complete"},"parent_tool_use_id":null}}}
|
||||
{"type":"emit_inbound","label":"system","frame":{"type":"system","subtype":"hook_started","hook_id":"4d07cf82-fa99-4897-afc7-51775243eb93","hook_name":"SessionStart:startup","hook_event":"SessionStart","uuid":"1c40e207-bb7e-438e-b09e-8fe547a5fd7f","session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9"}}
|
||||
{"type":"emit_inbound","label":"system","frame":{"type":"system","subtype":"hook_response","hook_id":"4d07cf82-fa99-4897-afc7-51775243eb93","hook_name":"SessionStart:startup","hook_event":"SessionStart","output":"","stdout":"","stderr":"","exit_code":0,"outcome":"success","uuid":"926cc2b6-6925-495e-95d4-15e722ed3e80","session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9"}}
|
||||
{"type":"emit_inbound","label":"system","frame":{"type":"system","subtype":"init","agents":[],"apiKeySource":"none","claude_code_version":"2.1.111","cwd":"/tmp/claude-replay-tool_call_read_only","tools":[],"mcp_servers":[],"model":"claude-sonnet-4-6","permissionMode":"dontAsk","slash_commands":[],"output_style":"default","skills":[],"plugins":[],"fast_mode_state":"off","uuid":"7d295979-f2e5-43cb-a9ee-b05f140f3ed8","session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9"}}
|
||||
{"type":"emit_inbound","label":"assistant","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_01GA9LpBQUx46bYfJz1Dg3sx","type":"message","role":"assistant","content":[{"type":"thinking","thinking":"Let me read both files simultaneously.","signature":"EuMBClsIDRgCKkCgcxLVMMfd/q0XMe3G9eezJXNLWZHFeCeLQQe+ZV/7LgzunPPqJA4qIhBlaUd20MdLktQmupV8Pf3F0M48mCXvMhFjbGF1ZGUtc29ubmV0LTQtNjgAEgyXwqTEvhX6TK7UPN0aDFxE8OrDIanq7FuUWSIwylTxDMwjDluRqVJpzPtcyggC9mQWyDuXfygmPXaHmQC4tKfQm7u+n1Q+KXKkqQQQKjYALOZjd9uroAWLpWRN1lxeoD9ivHXr/I/DLToXbofDxYKZ7+AUJPsKWfIBAjUtu208DrI5/FsYAQ=="}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":3,"cache_creation_input_tokens":0,"cache_read_input_tokens":3149,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","uuid":"7afffaac-efb9-4e50-a30d-2fbab11e09ff"}}
|
||||
{"type":"emit_inbound","label":"assistant","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_01GA9LpBQUx46bYfJz1Dg3sx","type":"message","role":"assistant","content":[{"type":"text","text":"I'll read both files simultaneously!"}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":3,"cache_creation_input_tokens":0,"cache_read_input_tokens":3149,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","uuid":"1431fb1c-7870-4f90-bb8b-f93f3e1c2c39"}}
|
||||
{"type":"emit_inbound","label":"assistant","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_01GA9LpBQUx46bYfJz1Dg3sx","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_017Q89TYYCDJPT2uLttrCn3A","name":"Read","input":{"file_path":"/tmp/claude-replay-tool_call_read_only/package.json"},"caller":{"type":"direct"}}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":3,"cache_creation_input_tokens":0,"cache_read_input_tokens":3149,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","uuid":"b1f4ff95-1ab5-4b39-ad86-0b820abfba5a"}}
|
||||
{"type":"emit_inbound","label":"assistant","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_01GA9LpBQUx46bYfJz1Dg3sx","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01CAafSU7YvuRYWdrFzpGCCW","name":"Read","input":{"file_path":"/tmp/claude-replay-tool_call_read_only/tsconfig.json"},"caller":{"type":"direct"}}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":3,"cache_creation_input_tokens":0,"cache_read_input_tokens":3149,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","uuid":"4a184534-4099-48f8-8bd0-4b9aaab8868c"}}
|
||||
{"type":"emit_inbound","label":"rate_limit_event","frame":{"type":"rate_limit_event","rate_limit_info":{"status":"allowed"},"uuid":"1d2f25d8-fb17-4671-bd83-c918afbabdff","session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9"}}
|
||||
{"type":"emit_inbound","label":"user","frame":{"type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_017Q89TYYCDJPT2uLttrCn3A","type":"tool_result","content":"1\t{\n2\t \"name\": \"claude-read-only-fixture\",\n3\t \"private\": true,\n4\t \"scripts\": {\n5\t \"typecheck\": \"tsc --noEmit\"\n6\t }\n7\t}"}]},"parent_tool_use_id":null,"session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","uuid":"0d5bfbc0-e826-466a-bea8-54368db21675","timestamp":"2026-05-07T03:35:43.611Z","tool_use_result":{"type":"text","file":{"filePath":"/tmp/claude-replay-tool_call_read_only/package.json","content":"{\n \"name\": \"claude-read-only-fixture\",\n \"private\": true,\n \"scripts\": {\n \"typecheck\": \"tsc --noEmit\"\n }\n}","numLines":7,"startLine":1,"totalLines":7}}}}
|
||||
{"type":"emit_inbound","label":"user","frame":{"type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_01CAafSU7YvuRYWdrFzpGCCW","type":"tool_result","content":"1\t{\n2\t \"compilerOptions\": {\n3\t \"module\": \"ESNext\",\n4\t \"strict\": true,\n5\t \"target\": \"ES2022\"\n6\t }\n7\t}"}]},"parent_tool_use_id":null,"session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","uuid":"259604ce-267c-4f3f-8a26-29e55f461d40","timestamp":"2026-05-07T03:35:43.652Z","tool_use_result":{"type":"text","file":{"filePath":"/tmp/claude-replay-tool_call_read_only/tsconfig.json","content":"{\n \"compilerOptions\": {\n \"module\": \"ESNext\",\n \"strict\": true,\n \"target\": \"ES2022\"\n }\n}","numLines":7,"startLine":1,"totalLines":7}}}}
|
||||
{"type":"emit_inbound","label":"assistant","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_017vbtgCJT7W7ayU6dpcREpU","type":"message","role":"assistant","content":[{"type":"text","text":"read only tool fixture complete"}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":1,"cache_creation_input_tokens":328,"cache_read_input_tokens":3149,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":328},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","uuid":"5f4a941e-08e7-4217-bc4c-a48cd3c237fa"}}
|
||||
{"type":"emit_inbound","label":"result","frame":{"type":"result","subtype":"success","is_error":false,"api_error_status":null,"duration_ms":4122,"duration_api_ms":3687,"num_turns":3,"result":"read only tool fixture complete","stop_reason":"end_turn","session_id":"473fb58f-85a3-4f21-b9d3-b1fdf5ef41f9","total_cost_usd":0.005561399999999999,"usage":{"input_tokens":4,"cache_creation_input_tokens":328,"cache_read_input_tokens":6298,"output_tokens":162,"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":328,"ephemeral_5m_input_tokens":0},"inference_geo":"","iterations":[{"input_tokens":1,"output_tokens":8,"cache_read_input_tokens":3149,"cache_creation_input_tokens":328,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":328},"type":"message"}],"speed":"standard"},"modelUsage":{"claude-sonnet-4-6":{"inputTokens":4,"outputTokens":162,"cacheReadInputTokens":6298,"cacheCreationInputTokens":328,"webSearchRequests":0,"costUSD":0.005561399999999999,"contextWindow":200000,"maxOutputTokens":32000}},"permission_denials":[],"terminal_reason":"completed","fast_mode_state":"off","uuid":"6f61e05c-80c8-4b60-afd0-ce2d0a9eafc9"}}
|
||||
{"type":"runtime_exit","status":"success"}
|
||||
Reference in new issue
Block a user