@ai-sdk/harness-opencode 1.0.153 → 1.0.155

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/harness-opencode",
3
- "version": "1.0.153",
3
+ "version": "1.0.155",
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.151",
30
- "@ai-sdk/provider": "4.0.27",
31
- "@ai-sdk/provider-utils": "5.0.59",
29
+ "@ai-sdk/harness": "1.0.153",
30
+ "@ai-sdk/provider": "4.0.28",
31
+ "@ai-sdk/provider-utils": "5.0.61",
32
32
  "ws": "8.21.0"
33
33
  },
34
34
  "peerDependencies": {
@@ -40,6 +40,7 @@
40
40
  "@types/node": "22.19.19",
41
41
  "@types/ws": "^8.5.13",
42
42
  "@vercel/ai-tsconfig": "0.0.0",
43
+ "@vscode/ripgrep": "1.18.0",
43
44
  "tsdown": "^0.23.0",
44
45
  "typescript": "6.0.3",
45
46
  "zod": "3.25.76"
@@ -8,7 +8,10 @@ import { mkdirSync, realpathSync, writeFileSync } from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { argv, env as procEnv } from 'node:process';
10
10
  import { isDeepStrictEqual } from 'node:util';
11
- import type { StartMessage } from '../opencode-bridge-protocol';
11
+ import type {
12
+ OpenCodeBuiltinToolName,
13
+ StartMessage,
14
+ } from '../opencode-bridge-protocol';
12
15
 
13
16
  import {
14
17
  createOpencodeClient,
@@ -33,7 +36,7 @@ import {
33
36
  } from './opencode-context-fallback';
34
37
  import { createEmitStreamEvent, stringValue } from './create-emit-stream-event';
35
38
  import { mapOpenCodeFinishReason } from './opencode-finish-step';
36
- import { prependOpenCodeBinToPath } from './opencode-path';
39
+ import { configureOpenCodePath } from './opencode-path';
37
40
  import { configureOpenCodeServerAuth } from './opencode-server-auth';
38
41
  import {
39
42
  addUsage,
@@ -68,6 +71,7 @@ type RuntimeState = {
68
71
  sessionId?: string;
69
72
  relay?: ToolRelay;
70
73
  openCodeConfig?: Record<string, unknown>;
74
+ inactiveBuiltinToolNames?: StartMessage['inactiveBuiltinToolNames'];
71
75
  toolNames: Set<string>;
72
76
  mcpToolPrefixes: Set<string>;
73
77
  };
@@ -102,9 +106,23 @@ const OPENCODE_TO_WIRE: Readonly<Record<string, string>> = {
102
106
  subtask: 'agent',
103
107
  };
104
108
 
105
- const PUBLIC_TO_NATIVE: Readonly<Record<string, string>> = {
106
- read: 'view',
107
- write: 'write',
109
+ type OpenCodePermissionName =
110
+ | 'question'
111
+ | 'read'
112
+ | 'edit'
113
+ | 'bash'
114
+ | 'glob'
115
+ | 'grep'
116
+ | 'list'
117
+ | 'webfetch'
118
+ | 'skill'
119
+ | 'todowrite'
120
+ | 'task';
121
+
122
+ const BUILTIN_TOOL_PERMISSION = {
123
+ askUserQuestions: 'question',
124
+ read: 'read',
125
+ write: 'edit',
108
126
  edit: 'edit',
109
127
  bash: 'bash',
110
128
  glob: 'glob',
@@ -113,8 +131,8 @@ const PUBLIC_TO_NATIVE: Readonly<Record<string, string>> = {
113
131
  webfetch: 'webfetch',
114
132
  skill: 'skill',
115
133
  todowrite: 'todowrite',
116
- agent: 'agent',
117
- };
134
+ agent: 'task',
135
+ } as const satisfies Record<OpenCodeBuiltinToolName, OpenCodePermissionName>;
118
136
 
119
137
  const TOOL_KIND: Readonly<Record<string, 'readonly' | 'edit' | 'bash'>> = {
120
138
  read: 'readonly',
@@ -147,7 +165,7 @@ const runtime: RuntimeState = {
147
165
  */
148
166
  let currentHostInputTracker: OpenCodeHostInputTracker | undefined;
149
167
  let currentTurn: BridgeTurn | undefined;
150
- prependOpenCodeBinToPath({ bootstrapDir, env: procEnv });
168
+ configureOpenCodePath({ bootstrapDir, env: procEnv });
151
169
 
152
170
  await runBridge<StartMessage>({
153
171
  bridgeType: 'opencode',
@@ -215,7 +233,11 @@ async function ensureRuntime({
215
233
  }): Promise<void> {
216
234
  if (
217
235
  runtime.client &&
218
- isDeepStrictEqual(runtime.openCodeConfig, start.openCodeConfig)
236
+ isDeepStrictEqual(runtime.openCodeConfig, start.openCodeConfig) &&
237
+ isDeepStrictEqual(
238
+ runtime.inactiveBuiltinToolNames,
239
+ start.inactiveBuiltinToolNames,
240
+ )
219
241
  ) {
220
242
  return;
221
243
  }
@@ -263,6 +285,9 @@ async function ensureRuntime({
263
285
  .map(([serverName]) => `${sanitizeMcpToolName(serverName)}_`),
264
286
  );
265
287
  runtime.openCodeConfig = structuredClone(start.openCodeConfig);
288
+ runtime.inactiveBuiltinToolNames = structuredClone(
289
+ start.inactiveBuiltinToolNames,
290
+ );
266
291
  } catch (error) {
267
292
  closeRuntime();
268
293
  throw error;
@@ -276,6 +301,7 @@ function closeRuntime(): void {
276
301
  runtime.client = undefined;
277
302
  runtime.relay = undefined;
278
303
  runtime.openCodeConfig = undefined;
304
+ runtime.inactiveBuiltinToolNames = undefined;
279
305
  runtime.toolNames = new Set();
280
306
  runtime.mcpToolPrefixes = new Set();
281
307
  }
@@ -309,17 +335,9 @@ function buildOpenCodeConfig({
309
335
  };
310
336
  if (start.model) config.model = start.model;
311
337
  if (skillsDir) config.skills = { paths: [skillsDir] };
312
- const inactiveToolNames = resolveInactiveBuiltinToolNames(start);
313
338
  const permission = config.permission as Record<string, unknown>;
314
- for (const toolName of inactiveToolNames) {
315
- const permissionName = toPermissionToolName(
316
- PUBLIC_TO_NATIVE[toolName] ?? toolName,
317
- );
318
- if (permissionName === 'ls') {
319
- permission.list = 'ask';
320
- } else {
321
- permission[permissionName] = 'ask';
322
- }
339
+ for (const toolName of start.inactiveBuiltinToolNames ?? []) {
340
+ permission[BUILTIN_TOOL_PERMISSION[toolName]] = 'deny';
323
341
  }
324
342
  const provider = buildProviderConfig(start);
325
343
  if (provider) config.provider = provider;
@@ -736,7 +754,7 @@ async function runPrompt({
736
754
  client,
737
755
  sessionId,
738
756
  permissionMode: start.permissionMode,
739
- builtinToolFiltering: start.builtinToolFiltering,
757
+ inactiveBuiltinToolNames: start.inactiveBuiltinToolNames,
740
758
  turn,
741
759
  state,
742
760
  hostInputTracker,
@@ -966,7 +984,7 @@ async function runCompaction({
966
984
  client,
967
985
  sessionId,
968
986
  permissionMode: start.permissionMode,
969
- builtinToolFiltering: start.builtinToolFiltering,
987
+ inactiveBuiltinToolNames: start.inactiveBuiltinToolNames,
970
988
  turn,
971
989
  state: createTranslationState(),
972
990
  emit: msg => {
@@ -1030,7 +1048,7 @@ async function consumeEvents({
1030
1048
  client,
1031
1049
  sessionId,
1032
1050
  permissionMode,
1033
- builtinToolFiltering,
1051
+ inactiveBuiltinToolNames,
1034
1052
  turn,
1035
1053
  state,
1036
1054
  hostInputTracker,
@@ -1042,7 +1060,7 @@ async function consumeEvents({
1042
1060
  client: OpenCodeClient;
1043
1061
  sessionId: string;
1044
1062
  permissionMode: StartMessage['permissionMode'];
1045
- builtinToolFiltering: StartMessage['builtinToolFiltering'];
1063
+ inactiveBuiltinToolNames: StartMessage['inactiveBuiltinToolNames'];
1046
1064
  turn: BridgeTurn;
1047
1065
  state: TranslationState;
1048
1066
  hostInputTracker?: OpenCodeHostInputTracker;
@@ -1248,7 +1266,7 @@ async function consumeEvents({
1248
1266
  client,
1249
1267
  sessionId: scopedSessionId,
1250
1268
  permissionMode,
1251
- builtinToolFiltering,
1269
+ inactiveBuiltinToolNames,
1252
1270
  turn,
1253
1271
  emit,
1254
1272
  event,
@@ -1261,7 +1279,7 @@ async function consumeEvents({
1261
1279
  client,
1262
1280
  sessionId: scopedSessionId,
1263
1281
  permissionMode,
1264
- builtinToolFiltering,
1282
+ inactiveBuiltinToolNames,
1265
1283
  turn,
1266
1284
  emit,
1267
1285
  event,
@@ -1385,7 +1403,7 @@ async function handlePermissionV2({
1385
1403
  client,
1386
1404
  sessionId,
1387
1405
  permissionMode,
1388
- builtinToolFiltering,
1406
+ inactiveBuiltinToolNames,
1389
1407
  turn,
1390
1408
  emit,
1391
1409
  event,
@@ -1394,7 +1412,7 @@ async function handlePermissionV2({
1394
1412
  client: OpenCodeClient;
1395
1413
  sessionId: string;
1396
1414
  permissionMode: StartMessage['permissionMode'];
1397
- builtinToolFiltering: StartMessage['builtinToolFiltering'];
1415
+ inactiveBuiltinToolNames: StartMessage['inactiveBuiltinToolNames'];
1398
1416
  turn: BridgeTurn;
1399
1417
  emit: Emit;
1400
1418
  event: OpenCodeEvent;
@@ -1411,7 +1429,7 @@ async function handlePermissionV2({
1411
1429
  requestID,
1412
1430
  toolCallId: String(props.source?.callID ?? requestID),
1413
1431
  permissionMode,
1414
- builtinToolFiltering,
1432
+ inactiveBuiltinToolNames,
1415
1433
  turn,
1416
1434
  emit,
1417
1435
  waitFor,
@@ -1428,7 +1446,7 @@ async function handlePermission({
1428
1446
  client,
1429
1447
  sessionId,
1430
1448
  permissionMode,
1431
- builtinToolFiltering,
1449
+ inactiveBuiltinToolNames,
1432
1450
  turn,
1433
1451
  emit,
1434
1452
  event,
@@ -1437,7 +1455,7 @@ async function handlePermission({
1437
1455
  client: OpenCodeClient;
1438
1456
  sessionId: string;
1439
1457
  permissionMode: StartMessage['permissionMode'];
1440
- builtinToolFiltering: StartMessage['builtinToolFiltering'];
1458
+ inactiveBuiltinToolNames: StartMessage['inactiveBuiltinToolNames'];
1441
1459
  turn: BridgeTurn;
1442
1460
  emit: Emit;
1443
1461
  event: OpenCodeEvent;
@@ -1453,7 +1471,7 @@ async function handlePermission({
1453
1471
  requestID,
1454
1472
  toolCallId: String(tool?.callID ?? requestID),
1455
1473
  permissionMode,
1456
- builtinToolFiltering,
1474
+ inactiveBuiltinToolNames,
1457
1475
  turn,
1458
1476
  emit,
1459
1477
  waitFor,
@@ -1473,7 +1491,7 @@ async function selectPermissionReply({
1473
1491
  requestID,
1474
1492
  toolCallId,
1475
1493
  permissionMode,
1476
- builtinToolFiltering,
1494
+ inactiveBuiltinToolNames,
1477
1495
  turn,
1478
1496
  emit,
1479
1497
  waitFor,
@@ -1483,7 +1501,7 @@ async function selectPermissionReply({
1483
1501
  requestID: string;
1484
1502
  toolCallId: string;
1485
1503
  permissionMode: StartMessage['permissionMode'];
1486
- builtinToolFiltering: StartMessage['builtinToolFiltering'];
1504
+ inactiveBuiltinToolNames: StartMessage['inactiveBuiltinToolNames'];
1487
1505
  turn: BridgeTurn;
1488
1506
  emit: Emit;
1489
1507
  waitFor?: WaitForHostInput;
@@ -1496,9 +1514,7 @@ async function selectPermissionReply({
1496
1514
  .finally(() => wait?.clearWaiting());
1497
1515
  };
1498
1516
  const toolName = toPermissionToolName(action);
1499
- if (
1500
- isBuiltinToolInactive({ toolName, toolFiltering: builtinToolFiltering })
1501
- ) {
1517
+ if (isBuiltinToolInactive({ toolName, inactiveBuiltinToolNames })) {
1502
1518
  emit({
1503
1519
  type: 'tool-approval-request',
1504
1520
  approvalId: requestID,
@@ -1555,26 +1571,15 @@ function toPermissionToolName(action: string): string {
1555
1571
  return toWireToolName(normalized);
1556
1572
  }
1557
1573
 
1558
- function resolveInactiveBuiltinToolNames(
1559
- start: StartMessage,
1560
- ): ReadonlyArray<string> {
1561
- const toolFiltering = start.builtinToolFiltering;
1562
- if (toolFiltering == null) return [];
1563
- return toolFiltering.mode === 'allow'
1564
- ? Object.keys(PUBLIC_TO_NATIVE).filter(
1565
- name => !toolFiltering.toolNames.includes(name),
1566
- )
1567
- : toolFiltering.toolNames;
1568
- }
1569
-
1570
1574
  function isBuiltinToolInactive(input: {
1571
1575
  toolName: string;
1572
- toolFiltering: StartMessage['builtinToolFiltering'];
1576
+ inactiveBuiltinToolNames: StartMessage['inactiveBuiltinToolNames'];
1573
1577
  }): boolean {
1574
- if (input.toolFiltering == null) return false;
1575
- return input.toolFiltering.mode === 'allow'
1576
- ? !input.toolFiltering.toolNames.includes(input.toolName)
1577
- : input.toolFiltering.toolNames.includes(input.toolName);
1578
+ return (
1579
+ input.inactiveBuiltinToolNames?.some(
1580
+ toolName => toolName === input.toolName,
1581
+ ) ?? false
1582
+ );
1578
1583
  }
1579
1584
 
1580
1585
  function isExternalPath(resource: string): boolean {
@@ -1,9 +1,10 @@
1
1
  import path from 'node:path';
2
+ import { rgPath } from '@vscode/ripgrep';
2
3
 
3
4
  const fallbackPath =
4
5
  '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin';
5
6
 
6
- export function prependOpenCodeBinToPath({
7
+ export function configureOpenCodePath({
7
8
  bootstrapDir,
8
9
  env,
9
10
  }: {
@@ -13,5 +14,6 @@ export function prependOpenCodeBinToPath({
13
14
  env.PATH = [
14
15
  path.join(bootstrapDir, 'node_modules', '.bin'),
15
16
  env.PATH || fallbackPath,
17
+ path.dirname(rgPath),
16
18
  ].join(path.delimiter);
17
19
  }
@@ -6,6 +6,7 @@
6
6
  "dependencies": {
7
7
  "@modelcontextprotocol/sdk": "1.32.1",
8
8
  "@opencode-ai/sdk": "1.18.34",
9
+ "@vscode/ripgrep": "1.18.0",
9
10
  "opencode-ai": "1.18.34",
10
11
  "ws": "8.21.0",
11
12
  "zod": "3.25.76"
@@ -14,6 +14,9 @@ importers:
14
14
  '@opencode-ai/sdk':
15
15
  specifier: 1.18.34
16
16
  version: 1.18.34
17
+ '@vscode/ripgrep':
18
+ specifier: 1.18.0
19
+ version: 1.18.0
17
20
  opencode-ai:
18
21
  specifier: 1.18.34
19
22
  version: 1.18.34
@@ -45,6 +48,69 @@ packages:
45
48
  '@opencode-ai/sdk@1.18.34':
46
49
  resolution: {integrity: sha512-R9QWUpcngtdQ6FCixz7NC6n1WsSho6CEuRUzYHz/CzZcp3miSklDzXkm0oDwXVCnuEu+ANoeM0f6RDp51kOMzQ==}
47
50
 
51
+ '@vscode/ripgrep-darwin-arm64@1.18.0':
52
+ resolution: {integrity: sha512-r3ktHSvbFycQNF6sl7sNDPocpsI7J+mEzh1IaZFkY0spm3k2Z9t8hPAeOK7+p0l6p6/swkQC14XWX01low+94Q==}
53
+ cpu: [arm64]
54
+ os: [darwin]
55
+
56
+ '@vscode/ripgrep-darwin-x64@1.18.0':
57
+ resolution: {integrity: sha512-25b4gWbL138dGuQU244ebCKKc0q05ULBMoFSz9oAEUHNeqK/lOJViDS7DRvbDazzAzSEdan391Znks/R5mkaTQ==}
58
+ cpu: [x64]
59
+ os: [darwin]
60
+
61
+ '@vscode/ripgrep-linux-arm64@1.18.0':
62
+ resolution: {integrity: sha512-lQ/5zTG++U0E3IhVgS4EPTTn/U4okncaRMM5GOFfOYZywS4nuD31GhkHbNYlDk5CuDC68+hYJ0/eQeyCKJDA+g==}
63
+ cpu: [arm64]
64
+ os: [linux]
65
+
66
+ '@vscode/ripgrep-linux-arm@1.18.0':
67
+ resolution: {integrity: sha512-GDAvufNDHu8zqLEmXstalQF0Wh6wQvdsBi/Vg3Yi3CK4a8XoFXqqXVEHEZ9xQz3t0NfoSEc9JbvK9DDS6FxyxQ==}
68
+ cpu: [arm]
69
+ os: [linux]
70
+
71
+ '@vscode/ripgrep-linux-ia32@1.18.0':
72
+ resolution: {integrity: sha512-YWLkSUtFd4Jh5EepIhA9RJSfv3uMAVMo+2rBIGHPBnvgLrZciIs2cDKei1/p6Wc/aCzUoHyMAg2R6tw4ZCBKGg==}
73
+ cpu: [ia32]
74
+ os: [linux]
75
+
76
+ '@vscode/ripgrep-linux-ppc64@1.18.0':
77
+ resolution: {integrity: sha512-quXVY8fwQ8O/lvU1yrSqSl3jlUzysRSb+AfUfCL/tRtphxsKlFvPAejryZ6vg4Bgvn8XL74xb4qMCDmWgYrT5w==}
78
+ cpu: [ppc64]
79
+ os: [linux]
80
+
81
+ '@vscode/ripgrep-linux-riscv64@1.18.0':
82
+ resolution: {integrity: sha512-f5kBQBrWfQt8Q7OhSORuNDei5dkYagBj3y4jImSUXGMy8B/Ke7SltSRcUtjPv166FAFfHCAmWuZp3+cWnX2/Vw==}
83
+ cpu: [riscv64]
84
+ os: [linux]
85
+
86
+ '@vscode/ripgrep-linux-s390x@1.18.0':
87
+ resolution: {integrity: sha512-rTOcJFGGcl2c07RUOWUo4U1ndnemKhY6A9hnMB18uk7jSgJc0d/QLBGWMWpumdtoJtpizn/wIv5mXIisJukusQ==}
88
+ cpu: [s390x]
89
+ os: [linux]
90
+
91
+ '@vscode/ripgrep-linux-x64@1.18.0':
92
+ resolution: {integrity: sha512-mQ3bVrUpnD2vs7QT0vX90Lt0cnUq467uFtEktIdsJJmW296RoSULRGqWgzG1AKxyBpNDD6l4ZO4qKf6SgyC23Q==}
93
+ cpu: [x64]
94
+ os: [linux]
95
+
96
+ '@vscode/ripgrep-win32-arm64@1.18.0':
97
+ resolution: {integrity: sha512-vfTIjq1OHnzUjxZcHVQAMbnggp8dpGf+0QKFOZHwWPqFwXxQC8eCWM+5NUdoJ6yrElCeMzoUTXoK/LdZaniB+Q==}
98
+ cpu: [arm64]
99
+ os: [win32]
100
+
101
+ '@vscode/ripgrep-win32-ia32@1.18.0':
102
+ resolution: {integrity: sha512-//rfAE+BOw5AC2EMmepmiE36jUuevtQYNQqqlw1s3m9FlRxjxEut97RkRPHAu9BG4mSojatZx+kXZXNdyI9caQ==}
103
+ cpu: [ia32]
104
+ os: [win32]
105
+
106
+ '@vscode/ripgrep-win32-x64@1.18.0':
107
+ resolution: {integrity: sha512-KNPvtElldqILHdnAetujPaowkNbpqJy3ssIGGN6F6Kve9Qi+nNLI2DN01O83JjCEVQbCzl8Ov3QZ9Eov3BR8Dg==}
108
+ cpu: [x64]
109
+ os: [win32]
110
+
111
+ '@vscode/ripgrep@1.18.0':
112
+ resolution: {integrity: sha512-ns5lWe44tSfbTMbVUsyB+I1819PVSw4AdpgK0RNkzfWfwy6+3IUNSxwSrfTno1/oWaS/hERNz+XLWVyga2aJBQ==}
113
+
48
114
  accepts@2.0.0:
49
115
  resolution: {integrity: sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==}
50
116
  engines: {node: '>= 0.6'}
@@ -507,6 +573,57 @@ snapshots:
507
573
  dependencies:
508
574
  cross-spawn: 7.0.6
509
575
 
576
+ '@vscode/ripgrep-darwin-arm64@1.18.0':
577
+ optional: true
578
+
579
+ '@vscode/ripgrep-darwin-x64@1.18.0':
580
+ optional: true
581
+
582
+ '@vscode/ripgrep-linux-arm64@1.18.0':
583
+ optional: true
584
+
585
+ '@vscode/ripgrep-linux-arm@1.18.0':
586
+ optional: true
587
+
588
+ '@vscode/ripgrep-linux-ia32@1.18.0':
589
+ optional: true
590
+
591
+ '@vscode/ripgrep-linux-ppc64@1.18.0':
592
+ optional: true
593
+
594
+ '@vscode/ripgrep-linux-riscv64@1.18.0':
595
+ optional: true
596
+
597
+ '@vscode/ripgrep-linux-s390x@1.18.0':
598
+ optional: true
599
+
600
+ '@vscode/ripgrep-linux-x64@1.18.0':
601
+ optional: true
602
+
603
+ '@vscode/ripgrep-win32-arm64@1.18.0':
604
+ optional: true
605
+
606
+ '@vscode/ripgrep-win32-ia32@1.18.0':
607
+ optional: true
608
+
609
+ '@vscode/ripgrep-win32-x64@1.18.0':
610
+ optional: true
611
+
612
+ '@vscode/ripgrep@1.18.0':
613
+ optionalDependencies:
614
+ '@vscode/ripgrep-darwin-arm64': 1.18.0
615
+ '@vscode/ripgrep-darwin-x64': 1.18.0
616
+ '@vscode/ripgrep-linux-arm': 1.18.0
617
+ '@vscode/ripgrep-linux-arm64': 1.18.0
618
+ '@vscode/ripgrep-linux-ia32': 1.18.0
619
+ '@vscode/ripgrep-linux-ppc64': 1.18.0
620
+ '@vscode/ripgrep-linux-riscv64': 1.18.0
621
+ '@vscode/ripgrep-linux-s390x': 1.18.0
622
+ '@vscode/ripgrep-linux-x64': 1.18.0
623
+ '@vscode/ripgrep-win32-arm64': 1.18.0
624
+ '@vscode/ripgrep-win32-ia32': 1.18.0
625
+ '@vscode/ripgrep-win32-x64': 1.18.0
626
+
510
627
  accepts@2.0.0:
511
628
  dependencies:
512
629
  mime-types: 3.0.2
@@ -9,17 +9,39 @@ import { z } from 'zod/v4';
9
9
  export const outboundMessageSchema = harnessV1BridgeOutboundMessageSchema;
10
10
  export type OutboundMessage = z.infer<typeof outboundMessageSchema>;
11
11
 
12
- export const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
13
- operation: z.enum(['prompt', 'compact']).optional(),
14
- provider: z.string().optional(),
15
- variant: z.string().optional(),
16
- instructions: z.string().optional(),
17
- skillsChanged: z.boolean().optional(),
18
- resumeSessionId: z.string().optional(),
19
- openCodeConfig: z.record(z.string(), z.unknown()).optional(),
20
- mcpServers: z.record(z.string(), z.unknown()).optional(),
21
- headers: z.record(z.string(), z.string()).optional(),
22
- });
12
+ const openCodeBuiltinToolNameSchema = z.enum([
13
+ 'askUserQuestions',
14
+ 'read',
15
+ 'write',
16
+ 'edit',
17
+ 'bash',
18
+ 'glob',
19
+ 'grep',
20
+ 'ls',
21
+ 'webfetch',
22
+ 'skill',
23
+ 'todowrite',
24
+ 'agent',
25
+ ]);
26
+
27
+ export type OpenCodeBuiltinToolName = z.infer<
28
+ typeof openCodeBuiltinToolNameSchema
29
+ >;
30
+
31
+ export const startMessageSchema = harnessV1BridgeStartBaseSchema
32
+ .omit({ builtinToolFiltering: true })
33
+ .extend({
34
+ operation: z.enum(['prompt', 'compact']).optional(),
35
+ provider: z.string().optional(),
36
+ variant: z.string().optional(),
37
+ instructions: z.string().optional(),
38
+ skillsChanged: z.boolean().optional(),
39
+ resumeSessionId: z.string().optional(),
40
+ openCodeConfig: z.record(z.string(), z.unknown()).optional(),
41
+ mcpServers: z.record(z.string(), z.unknown()).optional(),
42
+ headers: z.record(z.string(), z.string()).optional(),
43
+ inactiveBuiltinToolNames: z.array(openCodeBuiltinToolNameSchema).optional(),
44
+ });
23
45
 
24
46
  export type StartMessage = z.infer<typeof startMessageSchema>;
25
47
 
@@ -4,6 +4,7 @@ import {
4
4
  HARNESS_V1_BUILTIN_TOOLS,
5
5
  HarnessCapabilityUnsupportedError,
6
6
  harnessV1DiagnosticFromBridgeFrame,
7
+ isHarnessV1BuiltinToolIncluded,
7
8
  type HarnessV1,
8
9
  type HarnessV1BuiltinTool,
9
10
  type HarnessV1BuiltinToolFiltering,
@@ -77,6 +78,7 @@ import {
77
78
  import {
78
79
  outboundMessageSchema,
79
80
  type InboundMessage,
81
+ type OpenCodeBuiltinToolName,
80
82
  type OutboundMessage,
81
83
  } from './opencode-bridge-protocol';
82
84
  import { VERSION } from './version';
@@ -242,7 +244,14 @@ const OPENCODE_BUILTIN_TOOLS = {
242
244
  metadata: optionalStringRecord,
243
245
  }),
244
246
  }),
245
- } as const satisfies Record<string, HarnessV1BuiltinTool<any, any>>;
247
+ } as const satisfies Record<
248
+ OpenCodeBuiltinToolName,
249
+ HarnessV1BuiltinTool<any, any>
250
+ >;
251
+
252
+ const OPENCODE_BUILTIN_TOOL_NAMES = Object.keys(
253
+ OPENCODE_BUILTIN_TOOLS,
254
+ ) as OpenCodeBuiltinToolName[];
246
255
 
247
256
  const openCodeBridgeCoordsSchema = z.object({
248
257
  port: z.number(),
@@ -275,9 +284,11 @@ export function createOpenCode(
275
284
  harnessId: 'opencode',
276
285
  builtinTools: OPENCODE_BUILTIN_TOOLS,
277
286
  supportsBuiltinToolApprovals: true,
287
+ supportsBuiltinToolFiltering: true,
278
288
  lifecycleStateSchema: openCodeResumeStateSchema,
279
289
  getBootstrap: getOpenCodeBootstrap,
280
290
  doStart: async startOpts => {
291
+ validateBuiltinToolFiltering(startOpts.builtinToolFiltering);
281
292
  const sandboxSession = startOpts.sandboxSession;
282
293
  const toolSafeSandboxSession =
283
294
  getRestrictedSandboxSession(sandboxSession);
@@ -672,6 +683,30 @@ export function createOpenCode(
672
683
  };
673
684
  }
674
685
 
686
+ function validateBuiltinToolFiltering(
687
+ toolFiltering: HarnessV1BuiltinToolFiltering | undefined,
688
+ ): void {
689
+ if (toolFiltering == null) return;
690
+ const isActive = (toolName: 'write' | 'edit') =>
691
+ isHarnessV1BuiltinToolIncluded({ toolName, toolFiltering });
692
+ if (isActive('write') !== isActive('edit')) {
693
+ throw new HarnessCapabilityUnsupportedError({
694
+ harnessId: 'opencode',
695
+ message:
696
+ "OpenCode built-in filtering requires 'write' and 'edit' to either both be active or both be inactive.",
697
+ });
698
+ }
699
+ }
700
+
701
+ function resolveInactiveBuiltinToolNames(
702
+ toolFiltering: HarnessV1BuiltinToolFiltering | undefined,
703
+ ): OpenCodeBuiltinToolName[] | undefined {
704
+ if (toolFiltering == null) return undefined;
705
+ return OPENCODE_BUILTIN_TOOL_NAMES.filter(
706
+ toolName => !isHarnessV1BuiltinToolIncluded({ toolName, toolFiltering }),
707
+ );
708
+ }
709
+
675
710
  function resolveBridgePort({
676
711
  sandboxSession,
677
712
  override,
@@ -931,7 +966,10 @@ function createSession({
931
966
  let selectedModel: string | undefined;
932
967
  let activeTurn = false;
933
968
  let pendingTurnDrain: Promise<void> = Promise.resolve();
969
+ let abortedTurnDrain: Promise<void> = Promise.resolve();
934
970
  const pendingCompactionParts: HarnessV1StreamPart[] = [];
971
+ const inactiveBuiltinToolNames =
972
+ resolveInactiveBuiltinToolNames(builtinToolFiltering);
935
973
 
936
974
  channel.on('bridge-thread', msg => {
937
975
  latestOpenCodeSessionId = msg.threadId;
@@ -1066,6 +1104,7 @@ function createSession({
1066
1104
  new DOMException('Aborted', 'AbortError');
1067
1105
  isSettled = true;
1068
1106
  drainingAfterAbort = true;
1107
+ abortedTurnDrain = turnDrain;
1069
1108
  userMessageSubmitter?.close(error);
1070
1109
  pendingReject!(error);
1071
1110
  };
@@ -1122,7 +1161,7 @@ function createSession({
1122
1161
  ...(mcpServers == null ? {} : { mcpServers }),
1123
1162
  ...(headers == null ? {} : { headers }),
1124
1163
  ...(permissionMode ? { permissionMode } : {}),
1125
- ...(builtinToolFiltering ? { builtinToolFiltering } : {}),
1164
+ ...(inactiveBuiltinToolNames == null ? {} : { inactiveBuiltinToolNames }),
1126
1165
  ...(pendingResumeSessionId
1127
1166
  ? { resumeSessionId: pendingResumeSessionId }
1128
1167
  : latestOpenCodeSessionId
@@ -1140,7 +1179,6 @@ function createSession({
1140
1179
  control: HarnessV1PromptControl;
1141
1180
  skillWriteResult: WriteSkillsResult;
1142
1181
  }> => {
1143
- await pendingTurnDrain;
1144
1182
  if (
1145
1183
  opts.responseFormat?.type === 'json' &&
1146
1184
  opts.responseFormat.schema == null
@@ -1173,6 +1211,7 @@ function createSession({
1173
1211
  sessionId,
1174
1212
  isResume,
1175
1213
  doPromptTurn: async promptOpts => {
1214
+ await pendingTurnDrain;
1176
1215
  const { control, skillWriteResult } = await prepareTurn(promptOpts);
1177
1216
  const turnModel = promptOpts.model ?? selectedModel;
1178
1217
  if (turnModel) selectedModel = turnModel;
@@ -1195,11 +1234,14 @@ function createSession({
1195
1234
  ...startBase(turnModel),
1196
1235
  });
1197
1236
  pendingResumeSessionId = undefined;
1237
+ rerunContinue = false;
1198
1238
  return control;
1199
1239
  },
1200
1240
  doContinueTurn: async continueOpts => {
1241
+ await abortedTurnDrain;
1201
1242
  const { control, skillWriteResult } = await prepareTurn(continueOpts);
1202
1243
  if (rerunContinue) {
1244
+ rerunContinue = false;
1203
1245
  const turnModel = continueOpts.model ?? selectedModel;
1204
1246
  if (turnModel) selectedModel = turnModel;
1205
1247
  channel.send({
@@ -1248,6 +1290,7 @@ function createSession({
1248
1290
  provider,
1249
1291
  permissionMode,
1250
1292
  debug,
1293
+ inactiveBuiltinToolNames,
1251
1294
  openCodeConfig,
1252
1295
  mcpServers,
1253
1296
  headers,
@@ -1422,6 +1465,7 @@ async function runCompactOperation({
1422
1465
  provider,
1423
1466
  permissionMode,
1424
1467
  debug,
1468
+ inactiveBuiltinToolNames,
1425
1469
  openCodeConfig,
1426
1470
  mcpServers,
1427
1471
  headers,
@@ -1433,6 +1477,7 @@ async function runCompactOperation({
1433
1477
  provider: string | undefined;
1434
1478
  permissionMode: HarnessV1PermissionMode | undefined;
1435
1479
  debug: HarnessV1DebugConfig | undefined;
1480
+ inactiveBuiltinToolNames: OpenCodeBuiltinToolName[] | undefined;
1436
1481
  openCodeConfig: Record<string, unknown> | undefined;
1437
1482
  mcpServers: Record<string, unknown> | undefined;
1438
1483
  headers: Readonly<Record<string, string>> | undefined;
@@ -1467,6 +1512,7 @@ async function runCompactOperation({
1467
1512
  ...(mcpServers == null ? {} : { mcpServers }),
1468
1513
  ...(headers == null ? {} : { headers }),
1469
1514
  ...(permissionMode ? { permissionMode } : {}),
1515
+ ...(inactiveBuiltinToolNames == null ? {} : { inactiveBuiltinToolNames }),
1470
1516
  ...(resumeSessionId ? { resumeSessionId } : {}),
1471
1517
  ...(debug ? { debug } : {}),
1472
1518
  });