@weaveio/weave-adapter-opencode 0.0.0-preview-20260715084847 → 0.0.0-preview-20260716120703

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/adapter.d.ts CHANGED
@@ -8,8 +8,10 @@
8
8
  * Boundary rule: this module imports SDK types only through `./sdk-types`.
9
9
  * It must not import directly from `@opencode-ai/sdk`.
10
10
  */
11
- import type { AgentDescriptor, HarnessAdapter, PlanStateProvider, SkillInfo } from "@weaveio/weave-engine";
11
+ import type { WeaveConfig } from "@weaveio/weave-core";
12
+ import type { AgentDescriptor, HarnessAdapter, PlanStateProvider, ReviewExecutionResult, ReviewFanOutAdapterError, ReviewVariantDescriptor, SkillInfo } from "@weaveio/weave-engine";
12
13
  import { type ResultAsync } from "neverthrow";
14
+ import { type DirectReviewError, type DirectReviewResult } from "./direct-review.js";
13
15
  import { type OpenCodeModelContext } from "./model-resolution.js";
14
16
  import type { OpenCodeClientFacade } from "./opencode-client.js";
15
17
  import type { OpenCodeAgentConfig } from "./sdk-types.js";
@@ -93,6 +95,16 @@ export interface OpenCodeAdapterOptions {
93
95
  * ```
94
96
  */
95
97
  readonly availableSkills?: SkillInfo[];
98
+ /**
99
+ * Resolved Weave configuration.
100
+ *
101
+ * When provided, enables the `executeDirectReview()` method which fans out a
102
+ * reviewer agent to one session per `review_models` entry, runs them in
103
+ * parallel, and collates the results into a `CollatedReview`.
104
+ *
105
+ * When omitted, `executeDirectReview()` returns an error immediately.
106
+ */
107
+ readonly config?: WeaveConfig;
96
108
  }
97
109
  /**
98
110
  * OpenCode harness adapter.
@@ -165,6 +177,13 @@ export declare class OpenCodeAdapter implements HarnessAdapter {
165
177
  * `undefined` when no skills were injected (adapter returns empty list).
166
178
  */
167
179
  private readonly harnessSkills;
180
+ /**
181
+ * Resolved Weave configuration.
182
+ *
183
+ * Injected at construction time. Required for `executeDirectReview()`. When
184
+ * `undefined`, `executeDirectReview()` returns `err(DirectReviewError)`.
185
+ */
186
+ private readonly weaveConfig;
168
187
  constructor(options?: OpenCodeAdapterOptions);
169
188
  /**
170
189
  * Perform one-time initialisation required before any agent can be
@@ -213,6 +232,44 @@ export declare class OpenCodeAdapter implements HarnessAdapter {
213
232
  * @returns `ok(undefined)` on success, `err(OpenCodeAdapterError)` on failure.
214
233
  */
215
234
  spawnSubagent(descriptor: AgentDescriptor): ResultAsync<void, OpenCodeAdapterError>;
235
+ /**
236
+ * Execute a parallel fan-out of review variant agents.
237
+ *
238
+ * When no OpenCode client is available (translation-only mode), returns an
239
+ * error immediately — review fan-out requires a live harness connection.
240
+ *
241
+ * When a client is available, delegates to `executeReviewVariants()` which
242
+ * spawns each variant as an OpenCode session in parallel and collects results.
243
+ *
244
+ * @param variants - One descriptor per review variant to spawn.
245
+ * @param reviewPrompt - The rendered review prompt text to send to each variant agent.
246
+ * @returns `ok(results)` with one result per variant, or `err` on fatal
247
+ * infrastructure failure. Partial per-variant failures are captured inside
248
+ * the `ok` results array — callers should inspect each entry.
249
+ */
250
+ spawnReviewVariants(variants: ReviewVariantDescriptor[], reviewPrompt: string): ResultAsync<ReviewExecutionResult[], ReviewFanOutAdapterError>;
251
+ /**
252
+ * Execute a direct review for the named agent.
253
+ *
254
+ * Fans out to one variant per `review_models` entry on the named agent,
255
+ * runs them in parallel, collates the results, and returns the combined
256
+ * `CollatedReview`.
257
+ *
258
+ * This is a separate entry point from the workflow gate path (`spawnReviewVariants`).
259
+ * It is intended for callers that invoke a reviewer agent directly — outside
260
+ * a workflow step — and need the collated result rather than a gate pass/fail.
261
+ *
262
+ * Returns `err(DirectReviewError)` when:
263
+ * - No `WeaveConfig` was injected at construction time.
264
+ * - No `OpenCodeClientFacade` was injected at construction time.
265
+ * - The named agent does not declare `review_models` (fan-out produces no variants).
266
+ * - All review variants failed during execution.
267
+ *
268
+ * @param agentName - Logical name of the reviewer agent (must declare `review_models`).
269
+ * @param reviewPrompt - The rendered review prompt text sent to each variant.
270
+ * @returns `ok(DirectReviewResult)` on success, `err(DirectReviewError)` on failure.
271
+ */
272
+ executeDirectReview(agentName: string, reviewPrompt: string): ResultAsync<DirectReviewResult, DirectReviewError>;
216
273
  }
217
274
  export {};
218
275
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,SAAS,EACV,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAK1D,KAAK,wBAAwB,GACzB,sBAAsB,GACtB,qBAAqB,GACrB,qBAAqB,CAAC;AAE1B,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;gBAEZ,KAAK,EAAE;QACjB,IAAI,EAAE,wBAAwB,CAAC;QAC/B,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAOF;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAEvC;;;;;;;;OAQG;IACH,QAAQ,CAAC,YAAY,CA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AM,EAAE,mBAAmB,CAAC,CAAa;IAExE;;;;;;;OAOG;IACH,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,CAAa;IAE7D,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAErC;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmC;IAElE;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuB;IAEpD;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0B;IAExD;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;gBAE1C,OAAO,GAAE,sBAA2B;IAQhD;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAa3B;;;;;;;;;;;;;;;OAeG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IASjD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,aAAa,CACX,UAAU,EAAE,eAAe,GAC1B,WAAW,CAAC,IAAI,EAAE,oBAAoB,CAAC;IAkG1C;;;;;;;;;;;;;;OAcG;IACH,mBAAmB,CACjB,QAAQ,EAAE,uBAAuB,EAAE,EACnC,YAAY,EAAE,MAAM,GACnB,WAAW,CAAC,qBAAqB,EAAE,EAAE,wBAAwB,CAAC;IAiCjE;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,mBAAmB,CACjB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,WAAW,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;CAsBtD"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Direct review execution path for the OpenCode adapter.
3
+ *
4
+ * When a reviewer agent with `review_models` is invoked directly (outside a
5
+ * workflow gate), this module fans out to one variant per review model, runs
6
+ * them in parallel, collates the results, and returns the combined review.
7
+ *
8
+ * ## Flow
9
+ *
10
+ * 1. `ReviewOrchestrator.fanOut(agentName)` — derive variant descriptors
11
+ * 2. Map `GeneratedReviewVariant` entries to `ReviewVariantDescriptor[]`
12
+ * 3. `executeReviewVariants(variants, client, reviewPrompt)` — parallel execution
13
+ * 4. `ReviewOrchestrator.collate(results)` — aggregate into `CollatedReview`
14
+ *
15
+ * @see packages/adapters/opencode/src/execute-review-variants.ts
16
+ * @see packages/engine/src/review-orchestration.ts
17
+ * @see docs/adapter-boundary.md
18
+ */
19
+ import type { WeaveConfig } from "@weaveio/weave-core";
20
+ import type { CollatedReview } from "@weaveio/weave-engine";
21
+ import { type ResultAsync } from "neverthrow";
22
+ import type { OpenCodeClientFacade } from "./opencode-client.js";
23
+ /**
24
+ * The successful result of `executeDirectReview`.
25
+ *
26
+ * The formatted summary is returned to the caller. In the OpenCode plugin,
27
+ * the caller can inject it into the session via the agent's response, or
28
+ * display it via a toast/log. The adapter does not own session I/O for
29
+ * direct review results; the plugin entry point or command handler does.
30
+ */
31
+ export interface DirectReviewResult {
32
+ readonly collatedReview: CollatedReview;
33
+ readonly formattedSummary: string;
34
+ }
35
+ /**
36
+ * Discriminated union of errors that `executeDirectReview` can return.
37
+ *
38
+ * - `FanOutPlanError` — `ReviewOrchestrator.fanOut` failed (agent not found,
39
+ * conflict, or no `review_models` declared).
40
+ * - `ExecutionError` — `executeReviewVariants` returned an infrastructure
41
+ * error during parallel session execution.
42
+ * - `CollationError` — all variants failed; `ReviewOrchestrator.collate`
43
+ * returned an error (typically `CollatedReviewAllFailedError`).
44
+ */
45
+ export type DirectReviewError = {
46
+ type: "FanOutPlanError";
47
+ message: string;
48
+ } | {
49
+ type: "ExecutionError";
50
+ message: string;
51
+ } | {
52
+ type: "CollationError";
53
+ message: string;
54
+ };
55
+ /**
56
+ * Execute a direct review for the named agent.
57
+ *
58
+ * Fans out to one variant per `review_models` entry, runs them in parallel via
59
+ * the provided `OpenCodeClientFacade`, collates the results, and returns the
60
+ * combined `CollatedReview`.
61
+ *
62
+ * This is a separate entry point from the workflow gate path. It does not
63
+ * replace `spawnSubagent`; adapters and plugins call it when a reviewer agent
64
+ * is invoked directly rather than through a workflow step.
65
+ *
66
+ * @param agentName - Logical name of the reviewer agent (must declare `review_models`).
67
+ * @param config - The resolved `WeaveConfig` containing the agent definition.
68
+ * @param client - Live `OpenCodeClientFacade` used to spawn parallel sessions.
69
+ * @param reviewPrompt - The rendered review prompt text sent to each variant.
70
+ * @returns `ok(DirectReviewResult)` on success, `err(DirectReviewError)` on failure.
71
+ */
72
+ export declare function executeDirectReview(agentName: string, config: WeaveConfig, client: OpenCodeClientFacade, reviewPrompt: string): ResultAsync<DirectReviewResult, DirectReviewError>;
73
+ //# sourceMappingURL=direct-review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-review.d.ts","sourceRoot":"","sources":["../src/direct-review.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAGjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AASjE;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAMD;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAMhD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,oBAAoB,EAC5B,YAAY,EAAE,MAAM,GACnB,WAAW,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAkFpD"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Review variant fan-out executor for the OpenCode adapter.
3
+ *
4
+ * Executes a set of review variant agents in parallel via the
5
+ * `OpenCodeClientFacade` session API and returns results compatible with
6
+ * `ReviewOrchestrator.collate()`.
7
+ *
8
+ * Design notes:
9
+ * - All variants run in parallel via `Promise.allSettled`.
10
+ * - Individual variant failures are captured as `success: false` entries and
11
+ * do NOT propagate to the top-level `ResultAsync` error channel.
12
+ * - Session cleanup (`deleteSession`) is best-effort: a cleanup failure is
13
+ * logged but does not cause the variant to be marked as failed.
14
+ * - Only a catastrophic infrastructure failure that prevents all variants from
15
+ * even starting should return `err(ReviewFanOutAdapterError)`. If at least
16
+ * one variant ran (even if it failed), `ok(results)` is returned.
17
+ */
18
+ import type { ReviewExecutionResult, ReviewFanOutAdapterError, ReviewVariantDescriptor } from "@weaveio/weave-engine";
19
+ import { ResultAsync } from "neverthrow";
20
+ import type { OpenCodeClientFacade } from "./opencode-client.js";
21
+ /**
22
+ * Executes review variant agents in parallel via the OpenCode session API.
23
+ *
24
+ * All variants run concurrently via `Promise.allSettled`. Individual variant
25
+ * failures are captured as `success: false` entries and do not propagate to
26
+ * the top-level error channel. Only an infrastructure failure that prevents
27
+ * any variants from running returns `err(ReviewFanOutAdapterError)`.
28
+ *
29
+ * @param variants - Normalized variant descriptors produced by the engine.
30
+ * @param client - The `OpenCodeClientFacade` to use for session operations.
31
+ * @param reviewPrompt - The composed review prompt text to send to each variant.
32
+ * @returns A `ResultAsync` resolving to an array of per-variant results.
33
+ */
34
+ export declare function executeReviewVariants(variants: ReviewVariantDescriptor[], client: OpenCodeClientFacade, reviewPrompt: string): ResultAsync<ReviewExecutionResult[], ReviewFanOutAdapterError>;
35
+ //# sourceMappingURL=execute-review-variants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-review-variants.d.ts","sourceRoot":"","sources":["../src/execute-review-variants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAY,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAkHjE;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,uBAAuB,EAAE,EACnC,MAAM,EAAE,oBAAoB,EAC5B,YAAY,EAAE,MAAM,GACnB,WAAW,CAAC,qBAAqB,EAAE,EAAE,wBAAwB,CAAC,CAoEhE"}