@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.
- package/README.md +83 -0
- package/dist/adapter.d.ts +218 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/command-templates.d.ts +38 -0
- package/dist/command-templates.d.ts.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26155 -0
- package/dist/model-resolution.d.ts +112 -0
- package/dist/model-resolution.d.ts.map +1 -0
- package/dist/opencode-client.d.ts +94 -0
- package/dist/opencode-client.d.ts.map +1 -0
- package/dist/plugin.d.ts +184 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +23973 -0
- package/dist/projection-helpers.d.ts +59 -0
- package/dist/projection-helpers.d.ts.map +1 -0
- package/dist/reconcile-agent.d.ts +131 -0
- package/dist/reconcile-agent.d.ts.map +1 -0
- package/dist/run-workflow.d.ts +127 -0
- package/dist/run-workflow.d.ts.map +1 -0
- package/dist/runtime-command-projection.d.ts +365 -0
- package/dist/runtime-command-projection.d.ts.map +1 -0
- package/dist/sdk-types.d.ts +56 -0
- package/dist/sdk-types.d.ts.map +1 -0
- package/dist/skill-discovery.d.ts +73 -0
- package/dist/skill-discovery.d.ts.map +1 -0
- package/dist/start-plan-execution.d.ts +164 -0
- package/dist/start-plan-execution.d.ts.map +1 -0
- package/dist/tool-policy-mapping.d.ts +77 -0
- package/dist/tool-policy-mapping.d.ts.map +1 -0
- package/dist/translate-agent.d.ts +48 -0
- package/dist/translate-agent.d.ts.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-local model resolution for the OpenCode adapter.
|
|
3
|
+
*
|
|
4
|
+
* This module gathers OpenCode model context (available models, UI-selected
|
|
5
|
+
* model, system default) and calls `resolveAdapterModelIntent()` from
|
|
6
|
+
* `@weaveio/weave-engine` to produce a validated model selection for each agent.
|
|
7
|
+
*
|
|
8
|
+
* ## Design
|
|
9
|
+
*
|
|
10
|
+
* - Model discovery is adapter-owned: this module is the only place that
|
|
11
|
+
* queries OpenCode for available models.
|
|
12
|
+
* - `resolveAdapterModelIntent()` is engine-owned: it applies the priority
|
|
13
|
+
* chain (override → ui-selected → category → agent → system-default →
|
|
14
|
+
* constant-fallback) without querying harness state itself.
|
|
15
|
+
* - Explicit subagent model intent fails fast when the requested model is not
|
|
16
|
+
* in the available set. This prevents silent fallback to an unintended model
|
|
17
|
+
* when the user has declared a specific model preference.
|
|
18
|
+
*
|
|
19
|
+
* ## Fail-fast rule for explicit subagent models
|
|
20
|
+
*
|
|
21
|
+
* When an agent's `mode` is `"subagent"` and `agentModels` is non-empty, the
|
|
22
|
+
* first declared model must be available. If it is not, `resolveModelForAgent`
|
|
23
|
+
* returns `err(ModelNotAvailableError)` rather than falling back silently.
|
|
24
|
+
*
|
|
25
|
+
* This rule is intentionally strict: subagents are typically invoked
|
|
26
|
+
* programmatically with a specific model in mind, and silent fallback would
|
|
27
|
+
* produce unexpected behavior that is hard to debug.
|
|
28
|
+
*
|
|
29
|
+
* Boundary rule: this module imports engine types only through `@weaveio/weave-engine`
|
|
30
|
+
* and SDK types only through `./sdk-types`. It must not import directly from
|
|
31
|
+
* `@opencode-ai/sdk`.
|
|
32
|
+
*/
|
|
33
|
+
import type { AgentDescriptor } from "@weaveio/weave-engine";
|
|
34
|
+
import { type Result } from "neverthrow";
|
|
35
|
+
/**
|
|
36
|
+
* Discriminated union of errors that model resolution can return.
|
|
37
|
+
*/
|
|
38
|
+
export type ModelResolutionError = {
|
|
39
|
+
/**
|
|
40
|
+
* The agent declared an explicit model preference but none of the
|
|
41
|
+
* declared models are available in the current OpenCode instance.
|
|
42
|
+
*
|
|
43
|
+
* This is a hard error for subagent mode — silent fallback is not
|
|
44
|
+
* permitted when the user has declared explicit model intent.
|
|
45
|
+
*/
|
|
46
|
+
type: "ModelNotAvailableError";
|
|
47
|
+
agentName: string;
|
|
48
|
+
requestedModels: string[];
|
|
49
|
+
availableModels: string[];
|
|
50
|
+
message: string;
|
|
51
|
+
} | {
|
|
52
|
+
/**
|
|
53
|
+
* The model resolution input was structurally invalid.
|
|
54
|
+
*/
|
|
55
|
+
type: "ModelResolutionInputError";
|
|
56
|
+
agentName: string;
|
|
57
|
+
message: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Adapter-provided OpenCode model context.
|
|
61
|
+
*
|
|
62
|
+
* Adapters gather this context from the OpenCode runtime (e.g. via
|
|
63
|
+
* `client.app.providers()`) and pass it to `resolveModelForAgent()`.
|
|
64
|
+
* The engine never queries harness state directly.
|
|
65
|
+
*/
|
|
66
|
+
export interface OpenCodeModelContext {
|
|
67
|
+
/**
|
|
68
|
+
* Set of model IDs available in the current OpenCode instance.
|
|
69
|
+
*
|
|
70
|
+
* Gathered from the OpenCode provider/model list. When `undefined`, model
|
|
71
|
+
* availability filtering is skipped and any declared model is accepted.
|
|
72
|
+
*/
|
|
73
|
+
availableModels?: Set<string>;
|
|
74
|
+
/**
|
|
75
|
+
* The model currently selected in the OpenCode UI, if the adapter can
|
|
76
|
+
* supply one.
|
|
77
|
+
*
|
|
78
|
+
* Passed as `uiSelectedModel` to `resolveAdapterModelIntent()`. Ignored for
|
|
79
|
+
* `subagent` mode agents (per engine resolution rules).
|
|
80
|
+
*/
|
|
81
|
+
uiSelectedModel?: string;
|
|
82
|
+
/**
|
|
83
|
+
* The harness/system default model.
|
|
84
|
+
*
|
|
85
|
+
* Passed as `systemDefault` to `resolveAdapterModelIntent()`. Used when no
|
|
86
|
+
* agent preference, category preference, or UI selection is available.
|
|
87
|
+
*/
|
|
88
|
+
systemDefault?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve the model for a single agent descriptor using OpenCode model context.
|
|
92
|
+
*
|
|
93
|
+
* Calls `resolveAdapterModelIntent()` with the adapter-provided context and
|
|
94
|
+
* applies the fail-fast rule for explicit subagent model intent.
|
|
95
|
+
*
|
|
96
|
+
* ## Fail-fast rule
|
|
97
|
+
*
|
|
98
|
+
* When `descriptor.mode === "subagent"` and `descriptor.models` is non-empty,
|
|
99
|
+
* the first declared model must be present in `context.availableModels`. If it
|
|
100
|
+
* is not, this function returns `err(ModelNotAvailableError)`.
|
|
101
|
+
*
|
|
102
|
+
* This rule only applies when `context.availableModels` is defined. When the
|
|
103
|
+
* available model set is unknown (undefined), the declared model is accepted
|
|
104
|
+
* without availability filtering.
|
|
105
|
+
*
|
|
106
|
+
* @param descriptor - The normalized agent descriptor from the engine.
|
|
107
|
+
* @param context - Adapter-provided OpenCode model context.
|
|
108
|
+
* @returns `ok(resolvedModel)` on success, or `err(ModelResolutionError)` when
|
|
109
|
+
* explicit subagent model intent cannot be satisfied.
|
|
110
|
+
*/
|
|
111
|
+
export declare function resolveModelForAgent(descriptor: AgentDescriptor, context: OpenCodeModelContext): Result<string, ModelResolutionError>;
|
|
112
|
+
//# sourceMappingURL=model-resolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-resolution.d.ts","sourceRoot":"","sources":["../src/model-resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,uBAAuB,CAAC;AAEnF,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAMlD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IACE;;;;;;OAMG;IACH,IAAI,EAAE,wBAAwB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE;;OAEG;IACH,IAAI,EAAE,2BAA2B,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAMN;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAE9B;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAMD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAqCtC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-local OpenCode client facade.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the narrow `OpenCodeClientFacade` interface that the
|
|
5
|
+
* adapter uses to interact with a running OpenCode instance. All SDK-backed
|
|
6
|
+
* agent list/create/update operations flow through this interface so that the
|
|
7
|
+
* exact SDK method names and shapes remain adapter-local and can evolve
|
|
8
|
+
* without changing engine-facing contracts.
|
|
9
|
+
*
|
|
10
|
+
* Boundary rule: this module imports SDK types only through `./sdk-types`.
|
|
11
|
+
* It must not import directly from `@opencode-ai/sdk`.
|
|
12
|
+
*
|
|
13
|
+
* Design notes:
|
|
14
|
+
* - `listAgents()` returns the live agent list from the running OpenCode
|
|
15
|
+
* instance via `client.app.agents()`.
|
|
16
|
+
* - `createAgent(name, config)` and `updateAgent(name, config)` both write
|
|
17
|
+
* through `client.config.update()` by patching the `agent` map in the
|
|
18
|
+
* current config. OpenCode has no separate create/update agent endpoint;
|
|
19
|
+
* both operations are expressed as a config patch.
|
|
20
|
+
* - The facade does not perform reconciliation logic — that belongs in
|
|
21
|
+
* `reconcile-agent.ts` (task 3). The facade only wraps the raw SDK calls.
|
|
22
|
+
*/
|
|
23
|
+
import { ResultAsync } from "neverthrow";
|
|
24
|
+
import type { OpenCodeAgent, OpenCodeAgentConfig, OpencodeClient } from "./sdk-types.js";
|
|
25
|
+
/**
|
|
26
|
+
* Discriminated union of errors that `OpenCodeClientFacade` methods can return.
|
|
27
|
+
*/
|
|
28
|
+
export type OpenCodeClientError = {
|
|
29
|
+
type: "ListAgentsError";
|
|
30
|
+
message: string;
|
|
31
|
+
cause?: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
type: "CreateAgentError";
|
|
34
|
+
agentName: string;
|
|
35
|
+
message: string;
|
|
36
|
+
cause?: unknown;
|
|
37
|
+
} | {
|
|
38
|
+
type: "UpdateAgentError";
|
|
39
|
+
agentName: string;
|
|
40
|
+
message: string;
|
|
41
|
+
cause?: unknown;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Narrow adapter-local interface for OpenCode agent operations.
|
|
45
|
+
*
|
|
46
|
+
* Implementations wrap the `OpencodeClient` SDK calls needed for agent
|
|
47
|
+
* materialization. Tests provide a mock implementation without a live
|
|
48
|
+
* OpenCode runtime.
|
|
49
|
+
*/
|
|
50
|
+
export interface OpenCodeClientFacade {
|
|
51
|
+
/**
|
|
52
|
+
* Returns the current list of agents known to the running OpenCode instance.
|
|
53
|
+
*
|
|
54
|
+
* Corresponds to `client.app.agents()`.
|
|
55
|
+
*/
|
|
56
|
+
listAgents(): ResultAsync<OpenCodeAgent[], OpenCodeClientError>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new agent in the running OpenCode instance by patching the
|
|
59
|
+
* config's `agent` map with the provided config under `name`.
|
|
60
|
+
*
|
|
61
|
+
* Corresponds to a `client.config.update()` call that merges `{ agent: { [name]: config } }`.
|
|
62
|
+
*
|
|
63
|
+
* @param name - The canonical agent name (used as the config map key).
|
|
64
|
+
* @param config - The translated OpenCode agent config to write.
|
|
65
|
+
*/
|
|
66
|
+
createAgent(name: string, config: OpenCodeAgentConfig): ResultAsync<void, OpenCodeClientError>;
|
|
67
|
+
/**
|
|
68
|
+
* Updates an existing Weave-managed agent in the running OpenCode instance
|
|
69
|
+
* by patching the config's `agent` map.
|
|
70
|
+
*
|
|
71
|
+
* Semantically identical to `createAgent` at the SDK level — both write
|
|
72
|
+
* through `config.update()`. The distinction exists at the reconciliation
|
|
73
|
+
* layer (`reconcile-agent.ts`) where ownership is verified before calling
|
|
74
|
+
* this method.
|
|
75
|
+
*
|
|
76
|
+
* @param name - The canonical agent name (used as the config map key).
|
|
77
|
+
* @param config - The updated OpenCode agent config to write.
|
|
78
|
+
*/
|
|
79
|
+
updateAgent(name: string, config: OpenCodeAgentConfig): ResultAsync<void, OpenCodeClientError>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* SDK-backed implementation of `OpenCodeClientFacade`.
|
|
83
|
+
*
|
|
84
|
+
* Wraps an injected `OpencodeClient` instance. Constructed by the adapter
|
|
85
|
+
* during `init()` when a real SDK client is available.
|
|
86
|
+
*/
|
|
87
|
+
export declare class SdkOpenCodeClient implements OpenCodeClientFacade {
|
|
88
|
+
private readonly client;
|
|
89
|
+
constructor(client: OpencodeClient);
|
|
90
|
+
listAgents(): ResultAsync<OpenCodeAgent[], OpenCodeClientError>;
|
|
91
|
+
createAgent(name: string, config: OpenCodeAgentConfig): ResultAsync<void, OpenCodeClientError>;
|
|
92
|
+
updateAgent(name: string, config: OpenCodeAgentConfig): ResultAsync<void, OpenCodeClientError>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=opencode-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-client.d.ts","sourceRoot":"","sources":["../src/opencode-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAW,WAAW,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAMxB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAMN;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,UAAU,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,mBAAmB,CAAC,CAAC;IAEhE;;;;;;;;OAQG;IACH,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,mBAAmB,GAC1B,WAAW,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAE1C;;;;;;;;;;;OAWG;IACH,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,mBAAmB,GAC1B,WAAW,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;CAC3C;AAMD;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,oBAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAEnD,UAAU,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,mBAAmB,CAAC;IAkB/D,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,mBAAmB,GAC1B,WAAW,CAAC,IAAI,EAAE,mBAAmB,CAAC;IAoBzC,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,mBAAmB,GAC1B,WAAW,CAAC,IAAI,EAAE,mBAAmB,CAAC;CAmB1C"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode plugin entry point for `@weaveio/weave-adapter-opencode`.
|
|
3
|
+
*
|
|
4
|
+
* This module exports the `Plugin` function that OpenCode loads at startup
|
|
5
|
+
* when `@weaveio/weave-adapter-opencode` is listed in the `plugin` array of
|
|
6
|
+
* `opencode.json`. It is the primary runtime integration surface between
|
|
7
|
+
* Weave and OpenCode.
|
|
8
|
+
*
|
|
9
|
+
* ## How it works
|
|
10
|
+
*
|
|
11
|
+
* 1. OpenCode calls the exported `server` function (the `Plugin`) with a
|
|
12
|
+
* `PluginInput` context that includes a pre-constructed SDK client and the
|
|
13
|
+
* project directory.
|
|
14
|
+
* 2. The plugin loads the Weave config from `input.directory` via
|
|
15
|
+
* `loadConfig()`.
|
|
16
|
+
* 3. It calls `materializeAgents()` to compose all agent descriptors from the
|
|
17
|
+
* resolved config.
|
|
18
|
+
* 4. It translates each descriptor into an `OpenCodeAgentConfig` via
|
|
19
|
+
* `translateAgent()` and collects the results into a `translatedMap`.
|
|
20
|
+
* 5. It returns a `Hooks` object **immediately** with two hooks:
|
|
21
|
+
* a. **`config` hook** — injects the translated agent configs into
|
|
22
|
+
* `cfg.agent` so that `opencode debug config` reflects all Weave-managed
|
|
23
|
+
* agents. This runs once at startup before OpenCode finalises its config.
|
|
24
|
+
* b. **`event` hook** — listens for the first `session.created` event and
|
|
25
|
+
* then performs SDK-backed reconciliation (`adapter.init()` +
|
|
26
|
+
* `spawnSubagent()`) exactly once per plugin activation. This defers the
|
|
27
|
+
* SDK/DB path to real session time, so `opencode debug config` is never
|
|
28
|
+
* blocked by runtime SDK calls.
|
|
29
|
+
*
|
|
30
|
+
* ## Why deferred SDK reconciliation?
|
|
31
|
+
*
|
|
32
|
+
* `opencode debug config` calls the plugin function and waits for `Hooks` to
|
|
33
|
+
* be returned. In the previous design, `adapter.init()` and `spawnSubagent()`
|
|
34
|
+
* were called eagerly before `Hooks` was returned. Both operations touch the
|
|
35
|
+
* OpenCode SDK / DB path (`client.app.agents()`, `config.update()`), which
|
|
36
|
+
* hangs in the `debug config` context because the runtime store is not
|
|
37
|
+
* available.
|
|
38
|
+
*
|
|
39
|
+
* The fix: config loading and agent translation are pure computation (no SDK
|
|
40
|
+
* calls). `Hooks` is returned immediately after translation. SDK reconciliation
|
|
41
|
+
* is deferred to the `event` hook, which only fires during a real OpenCode
|
|
42
|
+
* session — never during `debug config`.
|
|
43
|
+
*
|
|
44
|
+
* ## Why both paths?
|
|
45
|
+
*
|
|
46
|
+
* The `config` hook and the SDK-backed reconciliation serve different purposes:
|
|
47
|
+
*
|
|
48
|
+
* - The `config` hook makes agents visible to `opencode debug config` and to
|
|
49
|
+
* any OpenCode subsystem that reads the merged config at startup. It is
|
|
50
|
+
* purely additive — it does not persist agents across restarts.
|
|
51
|
+
* - The SDK-backed reconciliation (`spawnSubagent`) writes agents into
|
|
52
|
+
* OpenCode's runtime store via `client.config.update()`. This is the
|
|
53
|
+
* durable path that survives config reloads and is the source of truth for
|
|
54
|
+
* what OpenCode actually uses at runtime.
|
|
55
|
+
*
|
|
56
|
+
* Both paths are required for full materialization: the `config` hook for
|
|
57
|
+
* observability and startup-time config visibility, and the SDK path for
|
|
58
|
+
* runtime persistence and ownership-safe upsert.
|
|
59
|
+
*
|
|
60
|
+
* ## Installation
|
|
61
|
+
*
|
|
62
|
+
* Add `@weaveio/weave-adapter-opencode/plugin` to the `plugin` array in `opencode.json`.
|
|
63
|
+
* Use the subpath export — **not** the bare package name:
|
|
64
|
+
*
|
|
65
|
+
* ```jsonc
|
|
66
|
+
* // opencode.json
|
|
67
|
+
* {
|
|
68
|
+
* "plugin": ["@weaveio/weave-adapter-opencode/plugin"]
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* The bare `@weaveio/weave-adapter-opencode` entry (`dist/index.js`) exports non-function
|
|
73
|
+
* values (constants, type re-exports) that cause OpenCode's `getLegacyPlugins`
|
|
74
|
+
* loader to throw `TypeError: Plugin export is not a function`. This module
|
|
75
|
+
* (`dist/plugin.js`) exports only the plugin function and is the correct entry
|
|
76
|
+
* point for OpenCode.
|
|
77
|
+
*
|
|
78
|
+
* Restart OpenCode after adding the plugin. The plugin entry point receives
|
|
79
|
+
* the runtime context, constructs an `OpenCodeAdapter` with the injected SDK
|
|
80
|
+
* client, and materializes all agents declared in `.weave/config.weave`.
|
|
81
|
+
*
|
|
82
|
+
* ## Boundary rules
|
|
83
|
+
*
|
|
84
|
+
* - The plugin entry point is the only place that imports from
|
|
85
|
+
* `@opencode-ai/plugin`. All other adapter modules remain plugin-agnostic.
|
|
86
|
+
* - The `PluginInput.client` is injected into `SdkOpenCodeClient` — the
|
|
87
|
+
* adapter never constructs its own SDK client.
|
|
88
|
+
* - Config loading and agent materialization follow the same path as any
|
|
89
|
+
* other adapter consumer: `loadConfig → materializeAgents → spawnSubagent`.
|
|
90
|
+
*/
|
|
91
|
+
import type { Plugin } from "@opencode-ai/plugin";
|
|
92
|
+
import { type FileReader } from "@weaveio/weave-config";
|
|
93
|
+
import { type OpenCodeClientFacade } from "./opencode-client.js";
|
|
94
|
+
/**
|
|
95
|
+
* Options for `createWeavePlugin`.
|
|
96
|
+
*
|
|
97
|
+
* All fields are optional. In production, the defaults are used. In tests,
|
|
98
|
+
* pass a custom `fileReader` and/or `clientFacade` to isolate the test from
|
|
99
|
+
* the developer's environment.
|
|
100
|
+
*/
|
|
101
|
+
export interface WeavePluginOptions {
|
|
102
|
+
/**
|
|
103
|
+
* Custom file reader for config loading.
|
|
104
|
+
*
|
|
105
|
+
* In production, the default `bunFileReader` is used. In tests, pass a
|
|
106
|
+
* `projectOnlyReader` to prevent the developer's global config from
|
|
107
|
+
* interfering with test results.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const plugin = createWeavePlugin({ fileReader: projectOnlyReader(root) });
|
|
112
|
+
* const hooks = await plugin(input);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
readonly fileReader?: FileReader;
|
|
116
|
+
/**
|
|
117
|
+
* Pre-constructed `OpenCodeClientFacade` to use instead of wrapping
|
|
118
|
+
* `input.client` in `SdkOpenCodeClient`.
|
|
119
|
+
*
|
|
120
|
+
* In production, this is always `undefined` — the plugin wraps `input.client`
|
|
121
|
+
* (the raw SDK client) in `SdkOpenCodeClient`. In tests, pass a
|
|
122
|
+
* `MockOpenCodeClient` here to avoid needing a real SDK client.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const mockClient = new MockOpenCodeClient();
|
|
127
|
+
* const plugin = createWeavePlugin({ clientFacade: mockClient });
|
|
128
|
+
* const hooks = await plugin(input);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
readonly clientFacade?: OpenCodeClientFacade;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Creates a Weave OpenCode plugin with optional configuration.
|
|
135
|
+
*
|
|
136
|
+
* Returns a `Plugin` function that OpenCode can load at startup. In
|
|
137
|
+
* production, call `createWeavePlugin()` with no arguments (or use the
|
|
138
|
+
* pre-built `WeavePlugin` export). In tests, pass a custom `fileReader` to
|
|
139
|
+
* isolate the test from the developer's global `~/.weave/config.weave`.
|
|
140
|
+
*
|
|
141
|
+
* The returned plugin function:
|
|
142
|
+
* 1. Loads Weave config and translates agent descriptors (pure computation).
|
|
143
|
+
* 2. Returns `Hooks` **immediately** — never blocks on SDK/DB calls.
|
|
144
|
+
* 3. Defers `adapter.init()` + `spawnSubagent()` to the `event` hook, which
|
|
145
|
+
* fires on the first `session.created` event during a real OpenCode session.
|
|
146
|
+
*
|
|
147
|
+
* This design ensures `opencode debug config` returns quickly because it only
|
|
148
|
+
* exercises the `config` hook path, never the deferred SDK reconciliation path.
|
|
149
|
+
*
|
|
150
|
+
* @param options - Optional plugin configuration.
|
|
151
|
+
* @returns A `Plugin` function compatible with `@opencode-ai/plugin`.
|
|
152
|
+
*/
|
|
153
|
+
export declare function createWeavePlugin(options?: WeavePluginOptions): Plugin;
|
|
154
|
+
/**
|
|
155
|
+
* Weave OpenCode plugin.
|
|
156
|
+
*
|
|
157
|
+
* Loaded by OpenCode at startup when `@weaveio/weave-adapter-opencode` is listed in
|
|
158
|
+
* the `plugin` array of `opencode.json`. Materializes all agents declared in
|
|
159
|
+
* `.weave/config.weave` into the running OpenCode instance.
|
|
160
|
+
*
|
|
161
|
+
* Returns a `Hooks` object **immediately** with:
|
|
162
|
+
* - `config` hook — injects translated agent configs into `cfg.agent` so that
|
|
163
|
+
* `opencode debug config` shows all Weave-managed agents.
|
|
164
|
+
* - `event` hook — defers SDK-backed reconciliation (`spawnSubagent`) to the
|
|
165
|
+
* first `session.created` event, ensuring `opencode debug config` never
|
|
166
|
+
* blocks on SDK/DB calls.
|
|
167
|
+
*
|
|
168
|
+
* @param input - Runtime context provided by OpenCode, including the SDK
|
|
169
|
+
* client and the project directory.
|
|
170
|
+
* @returns A `Hooks` object with `config` and `event` hooks on success, or an
|
|
171
|
+
* empty `Hooks` object when config loading fails.
|
|
172
|
+
*/
|
|
173
|
+
export declare const WeavePlugin: Plugin;
|
|
174
|
+
/**
|
|
175
|
+
* Named `server` export for `PluginModule` compatibility.
|
|
176
|
+
*
|
|
177
|
+
* OpenCode resolves plugins as `PluginModule` objects with a `server` property.
|
|
178
|
+
* When the module's default export is a function, OpenCode also accepts it
|
|
179
|
+
* directly as the plugin. Both forms are exported here for maximum
|
|
180
|
+
* compatibility.
|
|
181
|
+
*/
|
|
182
|
+
export declare const server: Plugin;
|
|
183
|
+
export default WeavePlugin;
|
|
184
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AAGH,OAAO,KAAK,EAAS,MAAM,EAAe,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,uBAAuB,CAAC;AAepE,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,sBAAsB,CAAC;AAuB9B;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAEjC;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CA6P1E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,EAAE,MAA4B,CAAC;AAEvD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAAc,CAAC;AAElC,eAAe,WAAW,CAAC"}
|