@ai-sdk/harness-claude-code 1.0.186 → 1.0.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/bridge/index.mjs +169 -6
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/bridge/index.ts +81 -16
package/dist/index.js
CHANGED
|
@@ -346,7 +346,7 @@ const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
|
|
|
346
346
|
z.discriminatedUnion("type", [startMessageSchema, ...harnessV1BridgeInboundCommandSchemas]);
|
|
347
347
|
//#endregion
|
|
348
348
|
//#region src/version.ts
|
|
349
|
-
const VERSION = "1.0.
|
|
349
|
+
const VERSION = "1.0.188";
|
|
350
350
|
//#endregion
|
|
351
351
|
//#region src/claude-code-harness.ts
|
|
352
352
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/harness-claude-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.188",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ai-sdk/harness": "1.0.
|
|
29
|
+
"@ai-sdk/harness": "1.0.184",
|
|
30
30
|
"@ai-sdk/provider": "4.0.38",
|
|
31
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
31
|
+
"@ai-sdk/provider-utils": "5.0.81",
|
|
32
32
|
"ws": "^8.21.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
package/src/bridge/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import {
|
|
8
8
|
runBridge,
|
|
9
9
|
convertHarnessToolModelOutput,
|
|
10
|
+
isWriteProtectedPath,
|
|
10
11
|
type BridgeEvent,
|
|
11
12
|
type BridgeTurn,
|
|
12
13
|
type Experimental_BridgeUserMessage,
|
|
@@ -92,6 +93,17 @@ const NATIVE_TO_COMMON: Readonly<Record<string, CommonBuiltinToolName>> = {
|
|
|
92
93
|
AskUserQuestion: 'askUserQuestions',
|
|
93
94
|
};
|
|
94
95
|
|
|
96
|
+
/*
|
|
97
|
+
* Workspace paths that hold Claude Code configuration or skills, which can run
|
|
98
|
+
* code or change the agent's behavior in later sessions. Writes to them always
|
|
99
|
+
* require host approval unless the permission mode is `allow-all`.
|
|
100
|
+
*/
|
|
101
|
+
const CLAUDE_CODE_WRITE_PROTECTED_PATHS = [
|
|
102
|
+
'.agents/skills',
|
|
103
|
+
'.claude',
|
|
104
|
+
'.mcp.json',
|
|
105
|
+
];
|
|
106
|
+
|
|
95
107
|
const NATIVE_TOOL_KINDS: Readonly<
|
|
96
108
|
Record<string, 'readonly' | 'edit' | 'bash'>
|
|
97
109
|
> = {
|
|
@@ -530,14 +542,56 @@ async function needsHostApproval(input: {
|
|
|
530
542
|
if (input.blockedPath != null) paths.push(input.blockedPath);
|
|
531
543
|
if (!paths.every((value): value is string => typeof value === 'string'))
|
|
532
544
|
return true;
|
|
533
|
-
|
|
545
|
+
if (
|
|
546
|
+
!(await areFileToolPathsTrusted({
|
|
547
|
+
workDir: workdir!,
|
|
548
|
+
cwd: input.cwd,
|
|
549
|
+
paths,
|
|
550
|
+
access,
|
|
551
|
+
readableSkillRoots: input.readableSkillRoots,
|
|
552
|
+
additionalDirectories: input.additionalDirectories,
|
|
553
|
+
}))
|
|
554
|
+
)
|
|
555
|
+
return true;
|
|
556
|
+
return (
|
|
557
|
+
access === 'write' &&
|
|
558
|
+
(await isWriteProtectedPath({
|
|
559
|
+
workDir: workdir!,
|
|
560
|
+
cwd: input.cwd,
|
|
561
|
+
paths,
|
|
562
|
+
writeProtectedPaths: CLAUDE_CODE_WRITE_PROTECTED_PATHS,
|
|
563
|
+
}))
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
async function isProtectedClaudeFileWrite(input: {
|
|
568
|
+
toolName: string;
|
|
569
|
+
toolInput: unknown;
|
|
570
|
+
cwd: string;
|
|
571
|
+
}): Promise<boolean> {
|
|
572
|
+
const args =
|
|
573
|
+
input.toolInput != null && typeof input.toolInput === 'object'
|
|
574
|
+
? (input.toolInput as Record<string, unknown>)
|
|
575
|
+
: {};
|
|
576
|
+
let target: unknown;
|
|
577
|
+
switch (input.toolName) {
|
|
578
|
+
case 'Write':
|
|
579
|
+
case 'Edit':
|
|
580
|
+
target = args.file_path;
|
|
581
|
+
break;
|
|
582
|
+
case 'NotebookEdit':
|
|
583
|
+
target = args.notebook_path;
|
|
584
|
+
break;
|
|
585
|
+
default:
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
if (typeof target !== 'string') return true;
|
|
589
|
+
return isWriteProtectedPath({
|
|
534
590
|
workDir: workdir!,
|
|
535
591
|
cwd: input.cwd,
|
|
536
|
-
paths,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
additionalDirectories: input.additionalDirectories,
|
|
540
|
-
}));
|
|
592
|
+
paths: [target],
|
|
593
|
+
writeProtectedPaths: CLAUDE_CODE_WRITE_PROTECTED_PATHS,
|
|
594
|
+
});
|
|
541
595
|
}
|
|
542
596
|
|
|
543
597
|
/*
|
|
@@ -546,9 +600,13 @@ async function needsHostApproval(input: {
|
|
|
546
600
|
* Resuming the session without a prompt fires the hook again for the same
|
|
547
601
|
* call, and the host's decision is applied then. This survives a bridge
|
|
548
602
|
* restart because nothing waits in memory.
|
|
603
|
+
*
|
|
604
|
+
* In auto mode, Claude Code's classifier decides every other call, so the
|
|
605
|
+
* hook defers only writes to write-protected paths.
|
|
549
606
|
*/
|
|
550
607
|
function createApprovalPreToolUseHook(input: {
|
|
551
608
|
permissionMode: 'allow-reads' | 'allow-edits' | 'allow-all';
|
|
609
|
+
autoMode: boolean;
|
|
552
610
|
inactiveNativeTools: ReadonlySet<string>;
|
|
553
611
|
decisions: Map<string, { approved: boolean; reason?: string }>;
|
|
554
612
|
deferredToolUseIds: Set<string>;
|
|
@@ -587,15 +645,21 @@ function createApprovalPreToolUseHook(input: {
|
|
|
587
645
|
};
|
|
588
646
|
}
|
|
589
647
|
if (
|
|
590
|
-
!(
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
648
|
+
!(input.autoMode
|
|
649
|
+
? await isProtectedClaudeFileWrite({
|
|
650
|
+
toolName,
|
|
651
|
+
toolInput: hookInput.tool_input,
|
|
652
|
+
cwd: hookInput.cwd,
|
|
653
|
+
})
|
|
654
|
+
: await needsHostApproval({
|
|
655
|
+
toolName,
|
|
656
|
+
toolInput: hookInput.tool_input,
|
|
657
|
+
cwd: hookInput.cwd,
|
|
658
|
+
readableSkillRoots: input.readableSkillRoots,
|
|
659
|
+
additionalDirectories: input.additionalDirectories,
|
|
660
|
+
permissionMode: input.permissionMode,
|
|
661
|
+
inactiveNativeTools: input.inactiveNativeTools,
|
|
662
|
+
}))
|
|
599
663
|
) {
|
|
600
664
|
return {};
|
|
601
665
|
}
|
|
@@ -836,6 +900,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
|
|
|
836
900
|
readableSkillRoots: start.readableSkillRoots ?? [],
|
|
837
901
|
additionalDirectories: start.additionalDirectories ?? [],
|
|
838
902
|
permissionMode,
|
|
903
|
+
autoMode: start.autoMode === true,
|
|
839
904
|
inactiveNativeTools: new Set(inactiveNativeTools),
|
|
840
905
|
decisions: approvalDecisions,
|
|
841
906
|
deferredToolUseIds,
|
|
@@ -904,7 +969,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
|
|
|
904
969
|
// `compaction` event; return an empty output so compaction proceeds.
|
|
905
970
|
hooks: {
|
|
906
971
|
PreToolUse: [
|
|
907
|
-
...(permissionMode === 'allow-all'
|
|
972
|
+
...(permissionMode === 'allow-all'
|
|
908
973
|
? []
|
|
909
974
|
: [{ hooks: [approvalPreToolUseHook] }]),
|
|
910
975
|
{
|