@ai-sdk/harness-opencode 1.0.185 → 1.0.187

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/dist/index.js CHANGED
@@ -747,7 +747,7 @@ const startMessageSchema = harnessV1BridgeStartBaseSchema.omit({ builtinToolFilt
747
747
  z.discriminatedUnion("type", [startMessageSchema, ...harnessV1BridgeInboundCommandSchemas]);
748
748
  //#endregion
749
749
  //#region src/version.ts
750
- const VERSION = "1.0.185";
750
+ const VERSION = "1.0.187";
751
751
  //#endregion
752
752
  //#region src/opencode-harness.ts
753
753
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/harness-opencode",
3
- "version": "1.0.185",
3
+ "version": "1.0.187",
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.182",
29
+ "@ai-sdk/harness": "1.0.184",
30
30
  "@ai-sdk/provider": "4.0.38",
31
- "@ai-sdk/provider-utils": "5.0.80",
31
+ "@ai-sdk/provider-utils": "5.0.81",
32
32
  "ws": "8.21.0"
33
33
  },
34
34
  "peerDependencies": {
@@ -64,6 +64,7 @@ import {
64
64
  import { toOpenCodePromptParts } from './opencode-prompt';
65
65
  import {
66
66
  areOpenCodePermissionPathsTrusted,
67
+ areOpenCodePermissionPathsWriteProtected,
67
68
  type PermissionToolCall,
68
69
  } from './permission-paths';
69
70
 
@@ -1759,17 +1760,21 @@ async function selectPermissionReply({
1759
1760
  permissionMode === 'allow-edits'
1760
1761
  ? kind === 'readonly' || kind === 'edit'
1761
1762
  : kind === 'readonly';
1763
+ const permissionPathOptions = {
1764
+ action,
1765
+ resources,
1766
+ metadata,
1767
+ toolCall,
1768
+ workDir: workdir,
1769
+ readableSkillRoots: context.readableSkillRoots,
1770
+ };
1762
1771
  if (
1763
1772
  allowed &&
1764
1773
  (!filePermission ||
1765
- (await areOpenCodePermissionPathsTrusted({
1766
- action,
1767
- resources,
1768
- metadata,
1769
- toolCall,
1770
- workDir: workdir,
1771
- readableSkillRoots: context.readableSkillRoots,
1772
- })))
1774
+ ((await areOpenCodePermissionPathsTrusted(permissionPathOptions)) &&
1775
+ !(await areOpenCodePermissionPathsWriteProtected(
1776
+ permissionPathOptions,
1777
+ ))))
1773
1778
  )
1774
1779
  return { reply: 'once' };
1775
1780
 
@@ -1,19 +1,65 @@
1
+ import { isWriteProtectedPath } from '@ai-sdk/harness/bridge';
1
2
  import { lstat, realpath } from 'node:fs/promises';
2
3
  import path from 'node:path';
3
4
 
5
+ /*
6
+ * Workspace paths that hold OpenCode configuration or skills it discovers,
7
+ * which can run code or change the agent's behavior in later sessions. Writes
8
+ * to them always require host approval unless the permission mode is
9
+ * `allow-all`.
10
+ */
11
+ const OPENCODE_WRITE_PROTECTED_PATHS = [
12
+ '.agents/skills',
13
+ '.opencode',
14
+ 'opencode.json',
15
+ 'opencode.jsonc',
16
+ '.claude/skills',
17
+ ];
18
+
4
19
  export type PermissionToolCall = {
5
20
  nativeName: string;
6
21
  input: Record<string, unknown>;
7
22
  };
8
23
 
9
- export async function areOpenCodePermissionPathsTrusted(options: {
24
+ type OpenCodePermissionPathOptions = {
10
25
  action: string;
11
26
  resources: string[];
12
27
  metadata: Record<string, unknown> | undefined;
13
28
  toolCall: PermissionToolCall | undefined;
14
29
  workDir: string;
15
30
  readableSkillRoots: readonly string[];
16
- }): Promise<boolean> {
31
+ };
32
+
33
+ export async function areOpenCodePermissionPathsTrusted(
34
+ options: OpenCodePermissionPathOptions,
35
+ ): Promise<boolean> {
36
+ const resolved = resolveOpenCodePermissionTargets(options);
37
+ if (resolved == null) return false;
38
+ return areFileToolPathsTrusted({
39
+ workDir: options.workDir,
40
+ cwd: options.workDir,
41
+ paths: resolved.targets,
42
+ access: resolved.access,
43
+ readableSkillRoots: options.readableSkillRoots,
44
+ });
45
+ }
46
+
47
+ export async function areOpenCodePermissionPathsWriteProtected(
48
+ options: OpenCodePermissionPathOptions,
49
+ ): Promise<boolean> {
50
+ const resolved = resolveOpenCodePermissionTargets(options);
51
+ if (resolved == null) return true;
52
+ if (resolved.access !== 'write') return false;
53
+ return isWriteProtectedPath({
54
+ workDir: options.workDir,
55
+ paths: resolved.targets,
56
+ writeProtectedPaths: OPENCODE_WRITE_PROTECTED_PATHS,
57
+ });
58
+ }
59
+
60
+ export function resolveOpenCodePermissionTargets(
61
+ options: OpenCodePermissionPathOptions,
62
+ ): { access: 'read' | 'write'; targets: string[] } | undefined {
17
63
  const args = options.toolCall?.input;
18
64
  const nativeName = options.toolCall?.nativeName;
19
65
  const access =
@@ -23,7 +69,7 @@ export async function areOpenCodePermissionPathsTrusted(options: {
23
69
  : 'read';
24
70
  let targets: unknown[];
25
71
  if (Array.isArray(options.metadata?.files)) {
26
- if (options.metadata.files.length === 0) return false;
72
+ if (options.metadata.files.length === 0) return undefined;
27
73
  targets = options.metadata.files.flatMap(value => {
28
74
  if (value == null || typeof value !== 'object') return [undefined];
29
75
  const file = value as Record<string, unknown>;
@@ -59,17 +105,11 @@ export async function areOpenCodePermissionPathsTrusted(options: {
59
105
  ) {
60
106
  targets = options.resources;
61
107
  } else {
62
- return false;
108
+ return undefined;
63
109
  }
64
110
  if (!targets.every((value): value is string => typeof value === 'string'))
65
- return false;
66
- return areFileToolPathsTrusted({
67
- workDir: options.workDir,
68
- cwd: options.workDir,
69
- paths: targets,
70
- access,
71
- readableSkillRoots: options.readableSkillRoots,
72
- });
111
+ return undefined;
112
+ return { access, targets };
73
113
  }
74
114
 
75
115
  export async function areFileToolPathsTrusted(options: {