@distlang/opencode-plugin 0.2.0 → 0.2.2

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
@@ -1,6 +1,6 @@
1
1
  # @distlang/opencode-plugin
2
2
 
3
- OpenCode plugin for capturing coding sessions and uploading them to Distlang AI Debugger.
3
+ OpenCode plugin for capturing coding sessions and uploading them to Distlang Agent Debugger.
4
4
 
5
5
  ## Install
6
6
 
@@ -59,31 +59,72 @@ If the plugin installs a managed copy because `distlang` was missing, you can lo
59
59
  The plugin uses:
60
60
 
61
61
  - `distlang helpers auth status --json`
62
- - `distlang helpers request POST /ai-debugger/v1/ingest ...`
62
+ - `distlang helpers request POST /agent-debugger/v1/ingest ...`
63
63
 
64
64
  If you are not logged in, the plugin logs one warning and continues without uploading.
65
65
 
66
- ## `/distlang` command
66
+ ## Distlang commands
67
67
 
68
- OpenCode commands are configured separately from plugins, so add a command file to make `/distlang` available in the TUI:
68
+ OpenCode commands are configured separately from plugins, so add command files to make the Distlang controls available in the TUI:
69
69
 
70
- `~/.config/opencode/commands/distlang.md`
70
+ `~/.config/opencode/commands/distlang-start.md`
71
71
 
72
72
  ```md
73
73
  ---
74
- description: Manage Distlang AI Debugger uploads
74
+ description: Sign in and enable Distlang Agent Debugger uploads
75
75
  ---
76
76
  ```
77
77
 
78
- The plugin watches for this command and handles:
78
+ `~/.config/opencode/commands/distlang-stop.md`
79
+
80
+ ```md
81
+ ---
82
+ description: Disable Distlang Agent Debugger uploads and sign out
83
+ ---
84
+ ```
85
+
86
+ `~/.config/opencode/commands/distlang-status.md`
87
+
88
+ ```md
89
+ ---
90
+ description: Show Distlang Agent Debugger upload status
91
+ ---
92
+ ```
93
+
94
+ The plugin watches for these commands:
95
+
96
+ - `/distlang-start`
97
+ - `/distlang-stop`
98
+ - `/distlang-status`
99
+
100
+ The legacy compact command also remains supported:
79
101
 
80
102
  - `/distlang status`
81
103
  - `/distlang start`
82
104
  - `/distlang stop`
105
+ - `/distlang login`
106
+ - `/distlang logout`
83
107
 
84
108
  Command results are written to the OpenCode app log, and also to the debug log file when enabled.
85
109
 
86
- If `/distlang start` finds that Distlang auth is missing, the plugin starts `distlang helpers login`, which opens the browser login flow.
110
+ If `/distlang-start` finds that Distlang auth is missing, the plugin starts `distlang helpers login`, which opens the browser login flow.
111
+
112
+ ### Command usage
113
+
114
+ Run these inside the OpenCode TUI:
115
+
116
+ ```text
117
+ /distlang-start
118
+ /distlang-status
119
+ ```
120
+
121
+ Commands:
122
+
123
+ - `/distlang-status`: show whether uploads are enabled, whether auth is available, and whether recent Agent Debugger sessions are visible
124
+ - `/distlang-start`: sign in if needed and enable Agent Debugger uploads
125
+ - `/distlang-stop`: disable Agent Debugger uploads and sign out of Distlang
126
+
127
+ Legacy aliases remain available: `/distlang status`, `/distlang start`, `/distlang stop`, `/distlang login`, and `/distlang logout`.
87
128
 
88
129
  ## Debugging
89
130
 
@@ -106,12 +147,12 @@ DISTLANG_OPENCODE_LOG_FILE=/tmp/distlang-opencode.log opencode
106
147
  To inspect whether uploads are visible after a run:
107
148
 
108
149
  ```bash
109
- distlang helpers request GET /ai-debugger/v1/sessions --json
150
+ distlang helpers request GET /agent-debugger/v1/sessions --json
110
151
  ```
111
152
 
112
153
  ## Captured Model
113
154
 
114
- The plugin builds a session-batch payload for Distlang AI Debugger:
155
+ The plugin builds a session-batch payload for Distlang Agent Debugger:
115
156
 
116
157
  - `session`
117
158
  - `interaction`
@@ -144,8 +185,8 @@ If `--model` and `OPENCODE_MODEL` are omitted, the harness defaults to `openai/g
144
185
 
145
186
  Useful flags:
146
187
 
147
- - `--require-upload` fails unless Distlang auth is available and the uploaded AI Debugger session validates.
148
- - `--keep-session` keeps the uploaded AI Debugger session for dashboard inspection.
188
+ - `--require-upload` fails unless Distlang auth is available and the uploaded Agent Debugger session validates.
189
+ - `--keep-session` keeps the uploaded Agent Debugger session for dashboard inspection.
149
190
  - `--keep-temp` keeps temporary logs and fixtures for debugging. Do not commit those files.
150
191
  - `--verbose` prints redacted command output.
151
192
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@distlang/opencode-plugin",
3
- "version": "0.2.0",
4
- "description": "OpenCode plugin for Distlang AI Debugger",
3
+ "version": "0.2.2",
4
+ "description": "OpenCode plugin for Distlang Agent Debugger",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "exports": {
@@ -25,7 +25,7 @@
25
25
  "distlang",
26
26
  "opencode",
27
27
  "plugin",
28
- "ai-debugger"
28
+ "agent-debugger"
29
29
  ],
30
30
  "repository": {
31
31
  "type": "git",
package/src/command.js CHANGED
@@ -60,14 +60,31 @@ export function extractDistlangInvocation(input) {
60
60
  ];
61
61
  for (const candidate of candidates) {
62
62
  const parsed = commandLike(candidate);
63
- if (parsed && parsed.name === "distlang") {
64
- return parsed;
63
+ const invocation = distlangInvocation(parsed);
64
+ if (invocation) {
65
+ return invocation;
65
66
  }
66
67
  }
67
68
 
68
69
  const directText = splitCommandText(configuredValue(input?.commandLine, configuredValue(input?.text, configuredValue(input?.input, configuredValue(input?.raw, "")))));
69
- if (directText && directText.name === "distlang") {
70
- return directText;
70
+ return distlangInvocation(directText);
71
+ }
72
+
73
+ function distlangInvocation(parsed) {
74
+ if (!parsed) {
75
+ return null;
76
+ }
77
+ if (parsed.name === "distlang") {
78
+ return parsed;
79
+ }
80
+ const action = parsed.name.startsWith("distlang-") ? parsed.name.slice("distlang-".length) : "";
81
+ if (action === "start" || action === "stop" || action === "status") {
82
+ return {
83
+ ...parsed,
84
+ name: "distlang",
85
+ action,
86
+ raw: parsed.raw || `/${parsed.name}`,
87
+ };
71
88
  }
72
89
  return null;
73
90
  }
package/src/distlang.js CHANGED
@@ -181,15 +181,19 @@ export async function loginWithDistlang() {
181
181
  return runDistlang(["helpers", "login"]);
182
182
  }
183
183
 
184
- export async function uploadAIDebuggerPayload(payload) {
185
- const tempFile = join(tmpdir(), `distlang-ai-debugger-${randomUUID()}.json`);
184
+ export async function logoutWithDistlang() {
185
+ return runDistlang(["helpers", "logout"]);
186
+ }
187
+
188
+ export async function uploadAgentDebuggerPayload(payload) {
189
+ const tempFile = join(tmpdir(), `distlang-agent-debugger-${randomUUID()}.json`);
186
190
  await fs.writeFile(tempFile, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
187
191
  try {
188
192
  const { stdout } = await runDistlang([
189
193
  "helpers",
190
194
  "request",
191
195
  "POST",
192
- "/ai-debugger/v1/ingest",
196
+ "/agent-debugger/v1/ingest",
193
197
  `--body-file=${tempFile}`,
194
198
  "--content-type=application/json",
195
199
  "--json",
@@ -200,12 +204,12 @@ export async function uploadAIDebuggerPayload(payload) {
200
204
  }
201
205
  }
202
206
 
203
- export async function fetchAIDebuggerSessions() {
207
+ export async function fetchAgentDebuggerSessions() {
204
208
  const { stdout } = await runDistlang([
205
209
  "helpers",
206
210
  "request",
207
211
  "GET",
208
- "/ai-debugger/v1/sessions?source=opencode&limit=5",
212
+ "/agent-debugger/v1/sessions?source=opencode&limit=5",
209
213
  "--json",
210
214
  ]);
211
215
  return JSON.parse(stdout || "{}");
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRecorder, extractSessionTitle } from "./recorder.js";
2
2
  import { extractDistlangInvocation } from "./command.js";
3
- import { distlangCommandInfo, fetchAIDebuggerSessions, getAuthStatus, loginWithDistlang, resolveDistlangBinary, uploadAIDebuggerPayload } from "./distlang.js";
3
+ import { distlangCommandInfo, fetchAgentDebuggerSessions, getAuthStatus, loginWithDistlang, logoutWithDistlang, resolveDistlangBinary, uploadAgentDebuggerPayload } from "./distlang.js";
4
4
  import { pluginStatePath, readPluginState, writePluginState } from "./state.js";
5
5
  import { appendFile } from "node:fs/promises";
6
6
 
@@ -17,7 +17,7 @@ function debugLogFile() {
17
17
  return configuredValue(process.env.DISTLANG_OPENCODE_LOG_FILE, "");
18
18
  }
19
19
 
20
- export const DistlangAIDebugger = async ({ project, directory, client }) => {
20
+ export const DistlangAgentDebugger = async ({ project, directory, client }) => {
21
21
  const debug = debugEnabled();
22
22
  const recorder = createRecorder({ project, directory, initialPrompt: extractOpenCodeRunPrompt(process.argv) });
23
23
  let loggedInit = false;
@@ -28,7 +28,7 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
28
28
  async function log(level, message, extra = undefined) {
29
29
  const line = JSON.stringify({
30
30
  ts: new Date().toISOString(),
31
- service: "distlang-ai-debugger",
31
+ service: "distlang-agent-debugger",
32
32
  level,
33
33
  message,
34
34
  extra,
@@ -42,7 +42,7 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
42
42
  }
43
43
  await client.app.log({
44
44
  body: {
45
- service: "distlang-ai-debugger",
45
+ service: "distlang-agent-debugger",
46
46
  level,
47
47
  message,
48
48
  extra,
@@ -62,7 +62,7 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
62
62
  return;
63
63
  }
64
64
  loggedInit = true;
65
- await log(debug ? "debug" : "info", "Distlang OpenCode AI Debugger plugin initialized", {
65
+ await log(debug ? "debug" : "info", "Distlang OpenCode Agent Debugger plugin initialized", {
66
66
  debug,
67
67
  statePath: pluginStatePath(),
68
68
  distlang: distlangCommandInfo(),
@@ -96,7 +96,16 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
96
96
  return;
97
97
  }
98
98
  commandHandledAt = now;
99
- const action = configuredValue(invocation.args[0], "status").toLowerCase();
99
+ const requestedAction = configuredValue(invocation.action, configuredValue(invocation.args[0], "status")).toLowerCase();
100
+ const action = requestedAction === "login" ? "start" : requestedAction === "logout" ? "stop" : requestedAction;
101
+ if (!["status", "start", "stop"].includes(action)) {
102
+ await maybeLogCommandResult("warn", "Unknown Distlang command. Use /distlang-status, /distlang-start, or /distlang-stop", {
103
+ source,
104
+ action: requestedAction,
105
+ command_hint: "/distlang-status | /distlang-start | /distlang-stop",
106
+ });
107
+ return;
108
+ }
100
109
  if (action === "start") {
101
110
  const state = await writePluginState(true);
102
111
  authWarningLogged = false;
@@ -119,7 +128,7 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
119
128
  await maybeLogCommandResult("warn", "Distlang uploads enabled, but auth check failed", { source, action, state, distlang: resolved, error: String(error) });
120
129
  return;
121
130
  }
122
- await maybeLogCommandResult("info", "Distlang AI Debugger uploads enabled", {
131
+ await maybeLogCommandResult("info", "Distlang Agent Debugger uploads enabled", {
123
132
  source,
124
133
  action,
125
134
  state,
@@ -131,7 +140,14 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
131
140
 
132
141
  if (action === "stop") {
133
142
  const state = await writePluginState(false);
134
- await maybeLogCommandResult("info", "Distlang AI Debugger uploads disabled", { source, action, state });
143
+ authWarningLogged = false;
144
+ try {
145
+ const resolved = await resolveDistlangBinary({ installIfMissing: true });
146
+ await logoutWithDistlang();
147
+ await maybeLogCommandResult("info", "Distlang Agent Debugger uploads disabled and signed out", { source, action, state, distlang: resolved });
148
+ } catch (error) {
149
+ await maybeLogCommandResult("warn", "Distlang Agent Debugger uploads disabled, but sign out failed", { source, action, state, error: String(error) });
150
+ }
135
151
  return;
136
152
  }
137
153
 
@@ -143,11 +159,11 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
143
159
  try {
144
160
  resolved = await resolveDistlangBinary({ installIfMissing: true });
145
161
  auth = await getAuthStatus();
146
- sessions = await fetchAIDebuggerSessions();
162
+ sessions = await fetchAgentDebuggerSessions();
147
163
  } catch (error) {
148
164
  resolutionError = String(error);
149
165
  }
150
- await maybeLogCommandResult("info", "Distlang AI Debugger status", {
166
+ await maybeLogCommandResult("info", "Distlang Agent Debugger status", {
151
167
  source,
152
168
  action,
153
169
  state,
@@ -155,13 +171,13 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
155
171
  auth,
156
172
  sessions,
157
173
  error: resolutionError,
158
- command_hint: "/distlang status | /distlang start | /distlang stop",
174
+ command_hint: "/distlang-status | /distlang-start | /distlang-stop",
159
175
  });
160
176
  }
161
177
 
162
178
  async function ensureAuthStatus() {
163
179
  if (!(await uploadEnabled())) {
164
- await debugLog("Distlang AI Debugger uploads are disabled", { state: await readPluginState() });
180
+ await debugLog("Distlang Agent Debugger uploads are disabled", { state: await readPluginState() });
165
181
  return false;
166
182
  }
167
183
  try {
@@ -171,7 +187,10 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
171
187
  await debugLog("Distlang auth status resolved", { authAvailable, payload, distlang: resolved });
172
188
  if (!authAvailable && !authWarningLogged) {
173
189
  authWarningLogged = true;
174
- await log("warn", "Distlang AI Debugger upload disabled: run `distlang helpers login` first", { auth: payload });
190
+ await maybeLogCommandResult("warn", "Distlang Agent Debugger upload disabled: run `/distlang-start` to sign in and enable uploads", {
191
+ auth: payload,
192
+ command_hint: "/distlang-start",
193
+ });
175
194
  } else if (authAvailable) {
176
195
  authWarningLogged = false;
177
196
  }
@@ -180,11 +199,11 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
180
199
  if (error && typeof error === "object" && error.code === "ENOENT") {
181
200
  if (!distlangMissingLogged) {
182
201
  distlangMissingLogged = true;
183
- await log("warn", "distlang CLI not found; AI Debugger upload disabled", { distlang: distlangCommandInfo() });
202
+ await log("warn", "distlang CLI not found; Agent Debugger upload disabled", { distlang: distlangCommandInfo() });
184
203
  }
185
204
  } else if (!authWarningLogged) {
186
205
  authWarningLogged = true;
187
- await log("warn", "Distlang AI Debugger auth check failed; upload disabled", { error: String(error) });
206
+ await log("warn", "Distlang Agent Debugger auth check failed; upload disabled", { error: String(error) });
188
207
  }
189
208
  return false;
190
209
  }
@@ -196,14 +215,14 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
196
215
  await refreshSessionMetadata(sessionID, { retry: true });
197
216
  payload = recorder.finalizeSession(sessionID, result, Date.now());
198
217
  } catch (error) {
199
- await log("error", "AI Debugger session finalization failed", { sessionID, result, error: String(error) });
218
+ await log("error", "Agent Debugger session finalization failed", { sessionID, result, error: String(error) });
200
219
  return;
201
220
  }
202
221
  if (!payload) {
203
222
  await debugLog("No payload produced during session finalization", { sessionID, result });
204
223
  return;
205
224
  }
206
- await debugLog("Finalized AI Debugger session payload", {
225
+ await debugLog("Finalized Agent Debugger session payload", {
207
226
  sessionID,
208
227
  result,
209
228
  interactions: Array.isArray(payload.interactions) ? payload.interactions.length : 0,
@@ -215,15 +234,15 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
215
234
  return;
216
235
  }
217
236
  try {
218
- const response = await uploadAIDebuggerPayload(payload);
219
- await debugLog("AI Debugger upload response received", { sessionID, response });
237
+ const response = await uploadAgentDebuggerPayload(payload);
238
+ await debugLog("Agent Debugger upload response received", { sessionID, response });
220
239
  if (!response.ok) {
221
- await log("warn", "AI Debugger upload failed", { sessionID, response });
240
+ await log("warn", "Agent Debugger upload failed", { sessionID, response });
222
241
  return;
223
242
  }
224
- await debugLog("AI Debugger session uploaded", { sessionID, response });
243
+ await debugLog("Agent Debugger session uploaded", { sessionID, response });
225
244
  } catch (error) {
226
- await log("warn", "AI Debugger upload failed", { sessionID, error: String(error) });
245
+ await log("warn", "Agent Debugger upload failed", { sessionID, error: String(error) });
227
246
  }
228
247
  }
229
248
 
@@ -233,14 +252,14 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
233
252
  await refreshSessionMetadata(sessionID, { retry: true });
234
253
  payload = recorder.snapshotSession(sessionID, result, Date.now());
235
254
  } catch (error) {
236
- await log("error", "AI Debugger session snapshot failed", { sessionID, result, error: String(error) });
255
+ await log("error", "Agent Debugger session snapshot failed", { sessionID, result, error: String(error) });
237
256
  return;
238
257
  }
239
258
  if (!payload) {
240
259
  await debugLog("No payload produced during session snapshot", { sessionID, result });
241
260
  return;
242
261
  }
243
- await debugLog("Prepared AI Debugger session snapshot", {
262
+ await debugLog("Prepared Agent Debugger session snapshot", {
244
263
  sessionID,
245
264
  result,
246
265
  interactions: Array.isArray(payload.interactions) ? payload.interactions.length : 0,
@@ -252,15 +271,15 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
252
271
  return;
253
272
  }
254
273
  try {
255
- const response = await uploadAIDebuggerPayload(payload);
256
- await debugLog("AI Debugger snapshot upload response received", { sessionID, response });
274
+ const response = await uploadAgentDebuggerPayload(payload);
275
+ await debugLog("Agent Debugger snapshot upload response received", { sessionID, response });
257
276
  if (!response.ok) {
258
- await log("warn", "AI Debugger snapshot upload failed", { sessionID, response });
277
+ await log("warn", "Agent Debugger snapshot upload failed", { sessionID, response });
259
278
  return;
260
279
  }
261
- await debugLog("AI Debugger session snapshot uploaded", { sessionID, response });
280
+ await debugLog("Agent Debugger session snapshot uploaded", { sessionID, response });
262
281
  } catch (error) {
263
- await log("warn", "AI Debugger snapshot upload failed", { sessionID, error: String(error) });
282
+ await log("warn", "Agent Debugger snapshot upload failed", { sessionID, error: String(error) });
264
283
  }
265
284
  }
266
285
 
@@ -469,4 +488,4 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
469
488
  };
470
489
  };
471
490
 
472
- export default DistlangAIDebugger;
491
+ export default DistlangAgentDebugger;
package/src/recorder.js CHANGED
@@ -169,7 +169,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
169
169
 
170
170
  function addStep(recorder, interaction, step) {
171
171
  recorder.stepCounter += 1;
172
- const stepID = `${recorder.id}:step:${recorder.stepCounter}`;
172
+ const stepID = configuredValue(step.id, `${recorder.id}:step:${recorder.stepCounter}`);
173
173
  const normalized = {
174
174
  id: stepID,
175
175
  index: recorder.stepCounter,
@@ -239,6 +239,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
239
239
  const recorder = ensureSession(sessionID, Date.now());
240
240
  const interaction = ensureInteraction(recorder, Date.now(), "", inferInteractionMode(event));
241
241
  addStep(recorder, interaction, {
242
+ id: `${recorder.id}:step:file:${safeID(filePath)}:${Date.now()}`,
242
243
  kind: "file_edit",
243
244
  phase: interaction.mode,
244
245
  title: `Edit ${filePath}`,
@@ -346,6 +347,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
346
347
  const loopIteration = targetInteraction.steps.filter((step) => step.kind === "llm_call").length + 1;
347
348
  const previousToolStep = findPreviousToolStep(targetInteraction, id);
348
349
  const llmStep = addStep(recorder, targetInteraction, {
350
+ id: `${recorder.id}:step:llm:${safeID(id)}`,
349
351
  kind: "llm_call",
350
352
  phase: targetInteraction.mode,
351
353
  title: summarizePrompt(assistantText, `Model response for Interaction ${targetInteraction.index}`),
@@ -444,6 +446,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
444
446
  const interaction = mappedInteractionID ? findInteraction(recorder, mappedInteractionID) || ensureInteraction(recorder, Date.now(), "", mode) : ensureInteraction(recorder, Date.now(), "", mode);
445
447
  applyInteractionMode(interaction, mode);
446
448
  const toolStep = addStep(recorder, interaction, {
449
+ id: callID ? `${recorder.id}:step:tool:${safeID(callID)}` : `${recorder.id}:step:tool:${safeID(messageID || configuredValue(toolState.messageID, "") || Date.now())}`,
447
450
  kind: "tool_call",
448
451
  phase: interaction.mode,
449
452
  title: `Run ${configuredValue(toolState.tool, "unknown")}`,