@weaveio/weave-adapter-opencode 0.0.0-preview-20260708084849

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-plan-execution.d.ts","sourceRoot":"","sources":["../src/start-plan-execution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAEV,iBAAiB,EACjB,YAAY,EACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKpD,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAM3B;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAG,cAAuB,CAAC;AAE3D;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,EAAG,aAAsB,CAAC;AAMjE;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,EAAG,oBAA6B,CAAC;AAMxE;;;;;;;;;GASG;AACH,MAAM,MAAM,uBAAuB,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5D;IAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC/D;IACE,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACtD,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAMzE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE5C;;;;;;;;OAQG;IACH,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAE1D;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAElC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;CAC/B;AAsED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,uBAAuB,GAC7B,WAAW,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAoDzD"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Maps abstract Weave `EffectiveToolPolicy` capabilities to OpenCode
3
+ * `AgentConfig.permission` and `AgentConfig.tools` fields.
4
+ *
5
+ * Boundary rule: this module is the single place where abstract Weave
6
+ * capability names are translated to concrete OpenCode tool/permission
7
+ * identifiers. No other adapter module should hard-code OpenCode tool names.
8
+ *
9
+ * Mapping rationale:
10
+ * - `read` → `tools` map (enable/disable read-class tools by name)
11
+ * - `write` → `permission.edit`
12
+ * - `execute` → `permission.bash`
13
+ * - `network` → `permission.webfetch`
14
+ * - `delegate` → `permission.doom_loop`
15
+ *
16
+ * The `read` capability has no dedicated `permission` field in OpenCode; it is
17
+ * enforced by toggling the boolean presence of read-class tool names in the
18
+ * `tools` map. When `read` is `"deny"`, all read-class tools are set to
19
+ * `false`. When `"allow"` or `"ask"`, they are omitted (OpenCode default:
20
+ * enabled). `"ask"` is treated as `"allow"` for read tools because OpenCode
21
+ * has no per-read-tool approval mechanism.
22
+ */
23
+ import type { EffectiveToolPolicy } from "@weaveio/weave-engine";
24
+ import type { OpenCodeAgentConfig } from "./sdk-types.js";
25
+ /**
26
+ * The three permission values accepted by OpenCode's `permission` fields.
27
+ * Mirrors the literal union used in `AgentConfig.permission.*`.
28
+ */
29
+ export type OpenCodePermissionValue = "allow" | "deny" | "ask";
30
+ /**
31
+ * The resolved OpenCode permission block produced by `mapToolPolicy`.
32
+ * Matches the shape of `AgentConfig.permission`.
33
+ */
34
+ export type OpenCodeToolPermissions = NonNullable<OpenCodeAgentConfig["permission"]>;
35
+ /**
36
+ * The concrete OpenCode tool identifiers that implement the abstract `read`
37
+ * capability. When `read` is `"deny"`, each of these is set to `false` in
38
+ * `AgentConfig.tools`. When `"allow"` or `"ask"`, they are omitted (OpenCode
39
+ * default is enabled).
40
+ *
41
+ * This list is the single source of truth for read-class tool names in the
42
+ * OpenCode adapter. Update it when OpenCode adds or removes read tools.
43
+ */
44
+ export declare const READ_TOOL_NAMES: readonly string[];
45
+ /**
46
+ * Converts a Weave `ToolPermission` value to the equivalent OpenCode
47
+ * permission string.
48
+ *
49
+ * The mapping is 1-to-1: Weave and OpenCode share the same three-value
50
+ * vocabulary (`"allow"`, `"deny"`, `"ask"`).
51
+ */
52
+ export declare function toOpenCodePermission(permission: "allow" | "deny" | "ask"): OpenCodePermissionValue;
53
+ /**
54
+ * Builds the `AgentConfig.tools` map entry for the `read` capability.
55
+ *
56
+ * Returns `undefined` when `read` is `"allow"` or `"ask"` — OpenCode enables
57
+ * read tools by default, so no explicit entry is needed.
58
+ *
59
+ * Returns a map with all `READ_TOOL_NAMES` set to `false` when `read` is
60
+ * `"deny"`.
61
+ */
62
+ export declare function buildReadToolsEntry(readPermission: "allow" | "deny" | "ask"): Record<string, boolean> | undefined;
63
+ /**
64
+ * Maps a fully-resolved Weave `EffectiveToolPolicy` to the OpenCode
65
+ * `AgentConfig.permission` block and an optional `AgentConfig.tools` patch.
66
+ *
67
+ * @returns An object with:
68
+ * - `permission` — the `AgentConfig.permission` block to merge into the
69
+ * translated agent config.
70
+ * - `tools` — optional `AgentConfig.tools` patch for read-class tools.
71
+ * `undefined` when no tool overrides are needed.
72
+ */
73
+ export declare function mapToolPolicy(policy: EffectiveToolPolicy): {
74
+ permission: OpenCodeToolPermissions;
75
+ tools: Record<string, boolean> | undefined;
76
+ };
77
+ //# sourceMappingURL=tool-policy-mapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-policy-mapping.d.ts","sourceRoot":"","sources":["../src/tool-policy-mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAM1D;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAC/C,mBAAmB,CAAC,YAAY,CAAC,CAClC,CAAC;AAMF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAKnC,CAAC;AAMX;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,GACnC,uBAAuB,CAIzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,GACvC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAQrC;AAMD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG;IAC1D,UAAU,EAAE,uBAAuB,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC5C,CAWA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Translates a Weave `AgentDescriptor` into an OpenCode `AgentConfig`.
3
+ *
4
+ * This module is the single place where normalized Weave agent intent is
5
+ * converted to the concrete shape expected by the OpenCode SDK. All
6
+ * harness-specific field names and structural decisions live here.
7
+ *
8
+ * Boundary rule: this module imports SDK types only through `./sdk-types` and
9
+ * tool-policy mapping only through `./tool-policy-mapping`. It must not import
10
+ * directly from `@opencode-ai/sdk`.
11
+ */
12
+ import type { AgentDescriptor } from "@weaveio/weave-engine";
13
+ import { type Result } from "neverthrow";
14
+ import type { OpenCodeAgentConfig } from "./sdk-types.js";
15
+ /**
16
+ * Discriminated union of errors that `translateAgent` can return.
17
+ *
18
+ * Currently only one variant exists; the union is defined as a type alias so
19
+ * future variants can be added without breaking callers.
20
+ */
21
+ export type TranslateAgentError = {
22
+ type: "TranslateAgentError";
23
+ agentName: string;
24
+ message: string;
25
+ };
26
+ /**
27
+ * Translates a normalized Weave `AgentDescriptor` into an OpenCode
28
+ * `AgentConfig` object suitable for writing into an OpenCode configuration
29
+ * file or passing to the SDK client.
30
+ *
31
+ * Translation rules:
32
+ * - `composedPrompt` → `prompt`
33
+ * - `resolvedModel` → `model` (pre-validated by `resolveModelForAgent()`; when
34
+ * `undefined` the model field is omitted and OpenCode uses its own default)
35
+ * - `temperature` → `temperature` (passed through when defined)
36
+ * - `description` → `description` (passed through when defined)
37
+ * - `mode` → `mode`
38
+ * - `effectiveToolPolicy` → `permission` + optional `tools` patch via
39
+ * `mapToolPolicy`
40
+ *
41
+ * @param descriptor - The fully composed agent descriptor from the engine.
42
+ * @param resolvedModel - The pre-validated model string from
43
+ * `resolveModelForAgent()`. Pass `undefined` to omit the model field.
44
+ * @returns `ok(OpenCodeAgentConfig)` on success, or
45
+ * `err(TranslateAgentError)` when the descriptor cannot be translated.
46
+ */
47
+ export declare function translateAgent(descriptor: AgentDescriptor, resolvedModel?: string): Result<OpenCodeAgentConfig, TranslateAgentError>;
48
+ //# sourceMappingURL=translate-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate-agent.d.ts","sourceRoot":"","sources":["../src/translate-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAO1D;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,eAAe,EAC3B,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAgClD"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@weaveio/weave-adapter-opencode",
3
+ "version": "0.0.0-preview-20260708084849",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "registry": "https://registry.npmjs.org/"
7
+ },
8
+ "description": "OpenCode plugin adapter for the Weave orchestration framework",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "module": "./dist/index.js",
12
+ "files": [
13
+ "dist",
14
+ "README.md"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./plugin": {
22
+ "types": "./dist/plugin.d.ts",
23
+ "import": "./dist/plugin.js"
24
+ }
25
+ },
26
+ "scripts": {
27
+ "build": "bun run --filter @weaveio/weave-core build && bun run --filter @weaveio/weave-engine --filter @weaveio/weave-config build && bun build ./src/index.ts --outdir ./dist --target bun && bun build ./src/plugin.ts --outfile ./dist/plugin.js --target bun && tsc -p tsconfig.build.json --emitDeclarationOnly",
28
+ "typecheck": "tsc --noEmit -p tsconfig.json",
29
+ "clean": "rm -rf dist"
30
+ },
31
+ "dependencies": {
32
+ "@opencode-ai/plugin": "~1.15.9",
33
+ "@opencode-ai/sdk": "~1.15.9",
34
+ "@weaveio/weave-config": "workspace:*",
35
+ "@weaveio/weave-core": "workspace:*",
36
+ "@weaveio/weave-engine": "workspace:*",
37
+ "neverthrow": "^8.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "typescript": "^5.4.5"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/weave-io/weave"
45
+ }
46
+ }