nemo-fabric-adapters-opencode 0.5.0 → 0.6.0-rc.1

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 CHANGED
@@ -26,6 +26,25 @@ packages reports a stable harness-unavailable error.
26
26
  OpenCode 2.0.23 does not support npm's `install-strategy=nested`. The documented
27
27
  command requires npm's default hoisted layout.
28
28
 
29
+ OpenCode 2.0.23 pins Zod 4.1.8. The NeMo Fabric source workspace overrides
30
+ compatible Zod 4 dependencies to 4.6.7 while preserving the GitLab provider's
31
+ Zod 3 requirement and its dependencies' original peer ranges. For a
32
+ published-adapter installation, apply the `@opencode/core`, `@opencode/plugin`,
33
+ `fast-uri`, and `debug` overrides from the
34
+ [workspace manifest](https://github.com/NVIDIA/NeMo-Fabric/blob/8a5549a72241dd7c3066233275266ba32011fd07/adapters/typescript/package.json)
35
+ to the consuming project's root `package.json`, use Zod 4.6.7 as its root
36
+ Zod peer, and refresh the lockfile. npm does not inherit overrides from
37
+ installed dependency packages. Verify the resulting tree with `npm ls --all`
38
+ and confirm that `npm ls fast-uri debug` resolves to `fast-uri@3.1.9` and
39
+ `debug@4.4.3`.
40
+
41
+ This update fixes early rejection for size-constrained Zod 4 collections.
42
+ Unbounded collections still require input-size and collection-size limits.
43
+ The transitive GitLab provider also retains Zod 3, which has no compatible
44
+ patched release. Do not force Zod 4 into dependencies that require Zod 3.
45
+ Track the remaining exposure and upstream fixes in
46
+ [issue #485](https://github.com/NVIDIA/NeMo-Fabric/issues/485).
47
+
29
48
  ## Supported Configuration
30
49
 
31
50
  The adapter supports the following configuration:
@@ -96,3 +115,11 @@ When OpenCode reports a diff for an invocation and the runtime has an artifact
96
115
  root, the adapter writes it to a runtime- and invocation-scoped path beneath
97
116
  `opencode/` and returns it as a `patch` artifact. Without an artifact root, it
98
117
  returns no patch artifact.
118
+
119
+ ## Runtime Health
120
+
121
+ OpenCode supports `live`, `active`, `ready` through `Fabric.check()`. Each level calls the owned embedded SDK `sessions.get({ sessionID })` and validates the exact native session identity and absence of an archive timestamp. This read-only session response qualifies liveness, access to the initialized session interface, and narrow readiness. Adapter closure and ownership guards reject closed or replaced sessions. Native session data is discarded.
122
+
123
+ Checks remain independent of an invocation. A busy invocation is healthy. Checks use the caller deadline and never cancel an invocation, stop the runtime, or repair a failure. Health does not establish valid model credentials, provider access, MCP connectivity, or successful model output. At most one native request remains outstanding. A check returns `unknown/probe_timeout` while an earlier native request remains pending; later checks do not reuse a delayed reply. Reports contain only the generic health contract fields.
124
+
125
+ Refer to the [SDK health-check overview](../../../docs/sdk/health-checks.mdx) for shared behavior and a comparison of native evidence across adapters.
@@ -581,6 +581,7 @@ function leaseEnvironment(input, credentialName) {
581
581
  return { release: () => replaceEnvironment(original) };
582
582
  }
583
583
  class OpenCodeSdkSessionHandle {
584
+ healthObservation;
584
585
  id;
585
586
  client;
586
587
  environment;
@@ -594,6 +595,29 @@ class OpenCodeSdkSessionHandle {
594
595
  this.endpointProxy = endpointProxy;
595
596
  this.skillsRoot = skillsRoot;
596
597
  }
598
+ async check(level) {
599
+ const source = level === "live" ? "fabric.adapter.liveness" : level === "active" ? "fabric.adapter.interface" : "fabric.adapter.readiness";
600
+ if (this.stopped)
601
+ return { outcome: "failed", reason_code: "session_closed", source, observed_at: new Date().toISOString(), activity: "stopped" };
602
+ if (this.healthObservation !== undefined)
603
+ return { outcome: "unknown", reason_code: "probe_timeout", source, observed_at: null, activity: "unknown" };
604
+ const sessionId = this.id;
605
+ try {
606
+ const observation = Promise.resolve(this.client.sessions.get({ sessionID: sessionId })).then((value) => typeof value === "object" && value !== null && "id" in value && value.id === sessionId && "time" in value && typeof value.time === "object" && value.time !== null && !("archived" in value.time));
607
+ this.healthObservation = observation;
608
+ void observation.finally(() => { if (this.healthObservation === observation)
609
+ this.healthObservation = undefined; }).catch(() => { });
610
+ const valid = await observation;
611
+ if (this.stopped || this.id !== sessionId)
612
+ return { outcome: "unknown", reason_code: "observation_changed", source, observed_at: null, activity: "unknown" };
613
+ return valid
614
+ ? { outcome: "passed", reason_code: null, source, observed_at: new Date().toISOString(), activity: "idle" }
615
+ : { outcome: "unknown", reason_code: "probe_error", source, observed_at: new Date().toISOString(), activity: "unknown" };
616
+ }
617
+ catch {
618
+ return { outcome: "unknown", reason_code: this.stopped || this.id !== sessionId ? "observation_changed" : "probe_error", source, observed_at: null, activity: "unknown" };
619
+ }
620
+ }
597
621
  async prompt(text) {
598
622
  let promptMayHaveBeenSubmitted = false;
599
623
  try {
package/dist/runtime.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AgentRunRequest, AgentRunResult, AgentUsage, RuntimeContext } from "nemo-fabric-adapter-contract";
1
+ import type { AdapterCheckResult, CheckLevel, AgentRunRequest, AgentRunResult, AgentUsage, RuntimeContext } from "nemo-fabric-adapter-contract";
2
2
  import { type AdapterRuntime, type AdapterStartInput } from "nemo-fabric-adapters-common";
3
3
  export interface OpenCodePromptOutcome {
4
4
  text?: string;
@@ -8,6 +8,7 @@ export interface OpenCodePromptOutcome {
8
8
  }
9
9
  export interface OpenCodeSessionHandle {
10
10
  id: string;
11
+ check(level: CheckLevel): Promise<AdapterCheckResult>;
11
12
  prompt(text: string): Promise<OpenCodePromptOutcome>;
12
13
  stop(): Promise<void>;
13
14
  }
@@ -16,12 +17,15 @@ export interface OpenCodeSessionFactory {
16
17
  }
17
18
  export declare class OpenCodeAdapterRuntime implements AdapterRuntime {
18
19
  private readonly factory;
20
+ private generation;
21
+ private activeInvocations;
19
22
  private session?;
20
23
  private artifactCount;
21
24
  constructor(factory: OpenCodeSessionFactory);
22
25
  start(input: AdapterStartInput): Promise<void>;
23
26
  private writePatch;
24
27
  private invalidate;
28
+ check(level: CheckLevel): Promise<AdapterCheckResult>;
25
29
  invoke(request: AgentRunRequest, context: RuntimeContext): Promise<AgentRunResult>;
26
30
  stop(): Promise<void>;
27
31
  }
package/dist/runtime.js CHANGED
@@ -5,7 +5,7 @@
5
5
  import { createHash } from "node:crypto";
6
6
  import { mkdir, writeFile } from "node:fs/promises";
7
7
  import { join } from "node:path";
8
- import { LifecycleError } from "nemo-fabric-adapters-common";
8
+ import { unobservedHealth, LifecycleError } from "nemo-fabric-adapters-common";
9
9
  function failed(code, message, usage, artifacts) {
10
10
  return {
11
11
  status: "failed",
@@ -20,6 +20,8 @@ function artifactSegment(identifier) {
20
20
  }
21
21
  export class OpenCodeAdapterRuntime {
22
22
  factory;
23
+ generation = 0;
24
+ activeInvocations = 0;
23
25
  session;
24
26
  artifactCount = 0;
25
27
  constructor(factory) {
@@ -30,6 +32,8 @@ export class OpenCodeAdapterRuntime {
30
32
  throw new LifecycleError("opencode_already_started", "OpenCode adapter runtime is already started");
31
33
  }
32
34
  this.session = await this.factory.create(input);
35
+ this.generation++;
36
+ this.activeInvocations = 0;
33
37
  this.artifactCount = 0;
34
38
  }
35
39
  async writePatch(patch, context) {
@@ -63,6 +67,22 @@ export class OpenCodeAdapterRuntime {
63
67
  // The runtime is already invalid and must not conceal the original failure.
64
68
  }
65
69
  }
70
+ async check(level) {
71
+ const session = this.session;
72
+ const generation = this.generation;
73
+ if (session === undefined)
74
+ return unobservedHealth("runtime_unavailable");
75
+ let result;
76
+ try {
77
+ result = await session.check(level);
78
+ }
79
+ catch {
80
+ result = unobservedHealth("probe_error");
81
+ }
82
+ if (this.session !== session || this.generation !== generation)
83
+ return unobservedHealth("observation_changed");
84
+ return result.outcome === "passed" ? { ...result, activity: this.activeInvocations > 0 ? "busy" : "idle" } : result;
85
+ }
66
86
  async invoke(request, context) {
67
87
  if (this.session === undefined) {
68
88
  throw new LifecycleError("opencode_not_started", "OpenCode adapter runtime is not started");
@@ -71,32 +91,42 @@ export class OpenCodeAdapterRuntime {
71
91
  return failed("opencode_unsupported_input", "The OpenCode adapter accepts only plain-text input");
72
92
  }
73
93
  const session = this.session;
74
- let outcome;
94
+ const generation = this.generation;
95
+ this.activeInvocations++;
75
96
  try {
76
- outcome = await session.prompt(request.input);
77
- }
78
- catch (error) {
79
- await this.invalidate(session);
80
- if (error instanceof LifecycleError) {
81
- throw error;
97
+ let outcome;
98
+ try {
99
+ outcome = await session.prompt(request.input);
82
100
  }
83
- throw new LifecycleError("opencode_session_failed", "OpenCode session communication failed", { retryable: true });
84
- }
85
- const artifacts = outcome.patch === undefined ? undefined : await this.writePatch(outcome.patch, context);
86
- if (outcome.errorMessage !== undefined) {
87
- return failed("opencode_model_error", outcome.errorMessage, outcome.usage, artifacts);
101
+ catch (error) {
102
+ await this.invalidate(session);
103
+ if (error instanceof LifecycleError) {
104
+ throw error;
105
+ }
106
+ throw new LifecycleError("opencode_session_failed", "OpenCode session communication failed", { retryable: true });
107
+ }
108
+ const artifacts = outcome.patch === undefined ? undefined : await this.writePatch(outcome.patch, context);
109
+ if (outcome.errorMessage !== undefined) {
110
+ return failed("opencode_model_error", outcome.errorMessage, outcome.usage, artifacts);
111
+ }
112
+ if (outcome.text === undefined || outcome.text.length === 0) {
113
+ return failed("opencode_no_assistant_response", "OpenCode completed without a final assistant text response", outcome.usage, artifacts);
114
+ }
115
+ return {
116
+ status: "succeeded",
117
+ output: { response: outcome.text },
118
+ ...(outcome.usage === undefined ? {} : { usage: outcome.usage }),
119
+ ...(artifacts === undefined ? {} : { artifacts }),
120
+ };
88
121
  }
89
- if (outcome.text === undefined || outcome.text.length === 0) {
90
- return failed("opencode_no_assistant_response", "OpenCode completed without a final assistant text response", outcome.usage, artifacts);
122
+ finally {
123
+ if (this.generation === generation)
124
+ this.activeInvocations--;
91
125
  }
92
- return {
93
- status: "succeeded",
94
- output: { response: outcome.text },
95
- ...(outcome.usage === undefined ? {} : { usage: outcome.usage }),
96
- ...(artifacts === undefined ? {} : { artifacts }),
97
- };
98
126
  }
99
127
  async stop() {
128
+ this.generation++;
129
+ this.activeInvocations = 0;
100
130
  const session = this.session;
101
131
  this.session = undefined;
102
132
  if (session !== undefined) {
@@ -63,6 +63,7 @@
63
63
  "additionalProperties": false
64
64
  },
65
65
  "capabilities": {
66
+ "metadata": {"health_checks": ["live", "active", "ready"]},
66
67
  "streaming": false,
67
68
  "cancellation": false,
68
69
  "updates": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemo-fabric-adapters-opencode",
3
- "version": "0.5.0",
3
+ "version": "0.6.0-rc.1",
4
4
  "description": "OpenCode v2 SDK harness adapter for NVIDIA NeMo Fabric.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -42,8 +42,8 @@
42
42
  "bun": ">=1.4.2"
43
43
  },
44
44
  "dependencies": {
45
- "nemo-fabric-adapter-contract": "0.5.0",
46
- "nemo-fabric-adapters-common": "0.5.0"
45
+ "nemo-fabric-adapter-contract": "0.6.0-rc.1",
46
+ "nemo-fabric-adapters-common": "0.6.0-rc.1"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@opencode/core": "2.0.23",