@distlang/opencode-plugin 0.3.0 → 0.4.0

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
@@ -20,10 +20,12 @@ on an earlier plugin release. OpenCode installs npm plugins automatically.
20
20
 
21
21
  ## Local use
22
22
 
23
- The plugin uses `distlang` only for two things:
23
+ The plugin uses `distlang` for authentication, API requests, and the local MCP
24
+ server:
24
25
 
25
26
  - `distlang helpers auth status --json`
26
27
  - `distlang helpers request ...`
28
+ - `distlang mcp`
27
29
 
28
30
  If `distlang` is not already available, the plugin can install a managed copy automatically.
29
31
 
@@ -104,12 +106,20 @@ Commands:
104
106
 
105
107
  - `/distlang-status`: show whether uploads are enabled, whether auth is available, and whether recent Agent Debugger sessions are visible
106
108
  - `/distlang-start`: sign in if needed and enable Agent Debugger uploads
107
- - `/distlang-stop`: disable Agent Debugger uploads and sign out of Distlang
109
+ - `/distlang-stop`: disable Agent Debugger uploads without signing out
108
110
  - `/distlang-view [session-id]`: open the latest uploaded OpenCode Agent Debugger session, the provided session id, or the Agent Debugger overview when no session is available yet
109
111
  - `/distlang-view-local`: start/open the local Agent Debugger without requiring Distlang login
110
112
 
111
113
  Legacy aliases remain available: `/distlang status`, `/distlang start`, `/distlang stop`, `/distlang login`, `/distlang logout`, and `/distlang view-local`.
112
114
 
115
+ Capture is off by default for new installations; existing explicit settings are
116
+ preserved. `/distlang-start` checks login before enabling capture and registers
117
+ the local, read-only MCP server when the resolved CLI supports `distlang mcp`.
118
+ An older CLI continues to work for capture but cannot provide MCP; update the
119
+ CLI or set `DISTLANG_BIN` to a compatible binary. A user-configured MCP server
120
+ named `distlang` is never overwritten. `/distlang-stop` does not disconnect an
121
+ already connected MCP server; use OpenCode's `/mcps` controls for that.
122
+
113
123
  If Distlang cloud login is unavailable, the plugin attempts to save session snapshots to the local Agent Debugger instead of dropping them. The local fallback expects `distlang-agent-debugger` to be installed and available on `PATH`, or configured with `DISTLANG_AGENT_DEBUGGER_BIN`.
114
124
 
115
125
  ## Debugging
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distlang/opencode-plugin",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "OpenCode plugin for Distlang Agent Debugger",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/command.js CHANGED
@@ -11,7 +11,7 @@ export const distlangCommands = [
11
11
  },
12
12
  {
13
13
  name: "distlang-stop",
14
- description: "Disable Distlang Agent Debugger uploads and sign out",
14
+ description: "Disable Distlang Agent Debugger uploads",
15
15
  action: "stop",
16
16
  },
17
17
  {
package/src/distlang.js CHANGED
@@ -196,6 +196,15 @@ export async function runDistlang(args, options = {}) {
196
196
  });
197
197
  }
198
198
 
199
+ export async function supportsDistlangMcp(binaryPath) {
200
+ try {
201
+ const { stdout } = await execFileAsync(binaryPath, ["mcp", "--help"], { timeout: 5000 });
202
+ return stdout.includes("distlang mcp");
203
+ } catch {
204
+ return false;
205
+ }
206
+ }
207
+
199
208
  export function distlangCommandInfo() {
200
209
  return {
201
210
  bin: distlangBinary(),
package/src/index.js CHANGED
@@ -6,7 +6,7 @@ import path from "node:path";
6
6
  import { createRecorder, extractSessionTitle } from "./recorder.js";
7
7
  import { createV2Bridge } from "./v2.js";
8
8
  import { commandInvocation, distlangCommands, legacyCommandInvocation } from "./command.js";
9
- import { distlangCommandInfo, ensureLocalAgentDebugger, fetchAgentDebuggerSessions, fetchLocalAgentDebuggerSessions, getAuthStatus, localAgentDebuggerUrl, loginWithDistlang, logoutWithDistlang, resolveDistlangBinary, uploadAgentDebuggerPayload, uploadLocalAgentDebuggerPayload } from "./distlang.js";
9
+ import { distlangCommandInfo, ensureLocalAgentDebugger, fetchAgentDebuggerSessions, fetchLocalAgentDebuggerSessions, getAuthStatus, localAgentDebuggerUrl, loginWithDistlang, logoutWithDistlang, resolveDistlangBinary, supportsDistlangMcp, uploadAgentDebuggerPayload, uploadLocalAgentDebuggerPayload } from "./distlang.js";
10
10
  import { pluginStatePath, readPluginState, writePluginState } from "./state.js";
11
11
 
12
12
  // Server events the plugin records. Anything else on the event stream is ignored.
@@ -84,6 +84,18 @@ export default Plugin.define({
84
84
  let loggedInit = false;
85
85
  let authWarningLogged = false;
86
86
  let distlangMissingLogged = false;
87
+ let mcpBinary = "";
88
+ if ((await readPluginState()).enabled) {
89
+ const resolved = await resolveDistlangBinary({ installIfMissing: false }).catch(() => null);
90
+ if (resolved && await supportsDistlangMcp(resolved.path)) mcpBinary = resolved.path;
91
+ }
92
+ await ctx.mcp.transform((editor) => {
93
+ // Never overwrite a user-configured server.
94
+ if (mcpBinary && !editor.get("distlang")) {
95
+ editor.set("distlang", { type: "local", command: [mcpBinary, "mcp"] });
96
+ }
97
+ });
98
+ if (mcpBinary) await ctx.mcp.reload().catch(() => {});
87
99
 
88
100
  async function log(level, message, extra = undefined) {
89
101
  const line = JSON.stringify({
@@ -210,8 +222,8 @@ export default Plugin.define({
210
222
 
211
223
  async function handleDistlangCommand(invocation, source) {
212
224
  const requestedAction = configuredValue(invocation.action, configuredValue(invocation.args[0], "status")).toLowerCase();
213
- const action = requestedAction === "login" ? "start" : requestedAction === "logout" ? "stop" : requestedAction;
214
- if (!["status", "start", "stop", "view", "view-local"].includes(action)) {
225
+ const action = requestedAction;
226
+ if (!["status", "start", "stop", "login", "logout", "view", "view-local"].includes(action)) {
215
227
  await logCommandResult("warn", "Unknown Distlang command. Use /distlang-status, /distlang-start, /distlang-stop, /distlang-view, or /distlang-view-local", {
216
228
  source,
217
229
  action: requestedAction,
@@ -219,23 +231,39 @@ export default Plugin.define({
219
231
  });
220
232
  return;
221
233
  }
222
- if (action === "start") {
223
- const state = await writePluginState(true);
234
+ if (action === "start" || action === "login") {
235
+ const stateBefore = await readPluginState();
224
236
  authWarningLogged = false;
225
237
  let resolved = null;
226
238
  let auth = null;
227
239
  try {
228
240
  resolved = await resolveDistlangBinary({ installIfMissing: true });
229
241
  } catch (error) {
230
- await logCommandResult("warn", "Distlang uploads enabled, but distlang install/resolve failed", { source, action, error: String(error) });
242
+ await logCommandResult("warn", "Distlang install/resolve failed; capture state unchanged", { source, action, error: String(error) });
231
243
  return;
232
244
  }
233
245
  try {
234
- auth = await ensureCommandAuth(source, action, state, resolved);
246
+ auth = await ensureCommandAuth(source, action, stateBefore, resolved);
247
+ if (!auth?.ok || !auth?.logged_in) throw new Error("Distlang login was not completed");
235
248
  } catch (error) {
236
- await logCommandResult("warn", "Distlang uploads enabled, but auth check failed", { source, action, state, distlang: resolved, error: String(error) });
249
+ await logCommandResult("warn", "Distlang login failed; capture state unchanged", { source, action, state: stateBefore, distlang: resolved, error: String(error) });
237
250
  return;
238
251
  }
252
+ if (action === "login") {
253
+ await logCommandResult("info", "Signed in to Distlang", { source, action });
254
+ return;
255
+ }
256
+ const state = await writePluginState(true);
257
+ if (await supportsDistlangMcp(resolved.path)) {
258
+ mcpBinary = resolved.path;
259
+ try {
260
+ await ctx.mcp.reload();
261
+ } catch (error) {
262
+ await logCommandResult("warn", "Capture enabled, but MCP reload failed", { source, action, error: String(error) });
263
+ }
264
+ } else {
265
+ await logCommandResult("warn", "Capture enabled, but this Distlang CLI does not support MCP; install a version with distlang mcp", { source, action });
266
+ }
239
267
  await logCommandResult("info", "Distlang Agent Debugger uploads enabled", {
240
268
  source,
241
269
  action,
@@ -249,18 +277,21 @@ export default Plugin.define({
249
277
  if (action === "stop") {
250
278
  const state = await writePluginState(false);
251
279
  authWarningLogged = false;
280
+ await logCommandResult("info", "Distlang Agent Debugger uploads disabled; still signed in", { source, action, state });
281
+ return;
282
+ }
283
+ if (action === "logout") {
252
284
  try {
253
- const resolved = await resolveDistlangBinary({ installIfMissing: true });
254
285
  await logoutWithDistlang();
255
- await logCommandResult("info", "Distlang Agent Debugger uploads disabled and signed out", { source, action, state, distlang: resolved });
286
+ await logCommandResult("info", "Signed out of Distlang", { source, action });
256
287
  } catch (error) {
257
- await logCommandResult("warn", "Distlang Agent Debugger uploads disabled, but sign out failed", { source, action, state, error: String(error) });
288
+ await logCommandResult("warn", "Distlang sign out failed", { source, action, error: String(error) });
258
289
  }
259
290
  return;
260
291
  }
261
292
 
262
293
  if (action === "view-local") {
263
- const state = await writePluginState(true);
294
+ const state = await readPluginState();
264
295
  authWarningLogged = false;
265
296
  let local = null;
266
297
  let sessions = null;
package/src/state.js CHANGED
@@ -8,7 +8,7 @@ function configuredValue(value, fallback = "") {
8
8
 
9
9
  function defaultState() {
10
10
  return {
11
- enabled: true,
11
+ enabled: false,
12
12
  updated_at: null,
13
13
  };
14
14
  }
@@ -27,7 +27,7 @@ export async function readPluginState() {
27
27
  const raw = await fs.readFile(filePath, "utf8");
28
28
  const parsed = JSON.parse(raw);
29
29
  return {
30
- enabled: parsed && parsed.enabled === false ? false : true,
30
+ enabled: parsed?.enabled === true,
31
31
  updated_at: typeof parsed?.updated_at === "string" && parsed.updated_at.trim() !== "" ? parsed.updated_at : null,
32
32
  };
33
33
  } catch (error) {