@distlang/opencode-plugin 0.1.3 → 0.1.5

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
@@ -73,9 +73,6 @@ OpenCode commands are configured separately from plugins, so add a command file
73
73
  ---
74
74
  description: Manage Distlang AI Debugger uploads
75
75
  ---
76
-
77
- Handled locally by the Distlang OpenCode plugin.
78
- Use `/distlang status`, `/distlang start`, or `/distlang stop`.
79
76
  ```
80
77
 
81
78
  The plugin watches for this command and handles:
@@ -86,6 +83,8 @@ The plugin watches for this command and handles:
86
83
 
87
84
  Command results are written to the OpenCode app log, and also to the debug log file when enabled.
88
85
 
86
+ If `/distlang start` finds that Distlang auth is missing, the plugin starts `distlang helpers login`, which opens the browser login flow.
87
+
89
88
  ## Debugging
90
89
 
91
90
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distlang/opencode-plugin",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "OpenCode plugin for Distlang AI Debugger",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/command.js CHANGED
@@ -52,6 +52,7 @@ export function extractDistlangInvocation(input) {
52
52
  const candidates = [
53
53
  input,
54
54
  input?.event,
55
+ input?.properties,
55
56
  input?.command,
56
57
  input?.info,
57
58
  input?.properties,
package/src/distlang.js CHANGED
@@ -177,6 +177,10 @@ export async function getAuthStatus() {
177
177
  return JSON.parse(stdout || "{}");
178
178
  }
179
179
 
180
+ export async function loginWithDistlang() {
181
+ return runDistlang(["helpers", "login"]);
182
+ }
183
+
180
184
  export async function uploadAIDebuggerPayload(payload) {
181
185
  const tempFile = join(tmpdir(), `distlang-ai-debugger-${randomUUID()}.json`);
182
186
  await fs.writeFile(tempFile, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRecorder } from "./recorder.js";
2
2
  import { extractDistlangInvocation } from "./command.js";
3
- import { distlangCommandInfo, fetchAIDebuggerSessions, getAuthStatus, resolveDistlangBinary, uploadAIDebuggerPayload } from "./distlang.js";
3
+ import { distlangCommandInfo, fetchAIDebuggerSessions, getAuthStatus, loginWithDistlang, resolveDistlangBinary, uploadAIDebuggerPayload } from "./distlang.js";
4
4
  import { pluginStatePath, readPluginState, writePluginState } from "./state.js";
5
5
  import { appendFile } from "node:fs/promises";
6
6
 
@@ -76,6 +76,18 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
76
76
 
77
77
  async function maybeLogCommandResult(level, message, extra = undefined) {
78
78
  await log(level, message, extra);
79
+ if (client?.tui && typeof client.tui.showToast === "function") {
80
+ const variant = level === "error" ? "error" : level === "warn" ? "warning" : level === "info" ? "success" : "info";
81
+ const detail = typeof extra?.error === "string" && extra.error.trim() !== "" ? extra.error.trim() : undefined;
82
+ await client.tui.showToast({
83
+ body: {
84
+ title: "Distlang",
85
+ message: detail ? `${message}: ${detail}` : message,
86
+ variant,
87
+ duration: 5000,
88
+ },
89
+ }).catch(() => {});
90
+ }
79
91
  }
80
92
 
81
93
  async function handleDistlangCommand(invocation, source) {
@@ -98,6 +110,11 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
98
110
  }
99
111
  try {
100
112
  auth = await getAuthStatus();
113
+ if (!auth || auth.ok !== true || auth.logged_in !== true) {
114
+ await maybeLogCommandResult("info", "Opening browser for Distlang login", { source, action, state, distlang: resolved });
115
+ await loginWithDistlang();
116
+ auth = await getAuthStatus();
117
+ }
101
118
  } catch (error) {
102
119
  await maybeLogCommandResult("warn", "Distlang uploads enabled, but auth check failed", { source, action, state, distlang: resolved, error: String(error) });
103
120
  return;
@@ -318,6 +335,16 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
318
335
  await handleDistlangCommand(invocation, "tui.command.execute");
319
336
  },
320
337
 
338
+ "command.execute.before": async (input, output) => {
339
+ await logInit();
340
+ const invocation = extractDistlangInvocation(input);
341
+ if (!invocation) {
342
+ return;
343
+ }
344
+ await handleDistlangCommand(invocation, "command.execute.before");
345
+ output.parts = [];
346
+ },
347
+
321
348
  "tool.execute.before": async (input) => {
322
349
  await logInit();
323
350
  const observed = recorder.observeToolBefore(input);
package/src/recorder.js CHANGED
@@ -514,15 +514,15 @@ function tokensFromMessage(info) {
514
514
  }
515
515
 
516
516
  function extractMessageText(info) {
517
- const direct = configuredValue(info && (info.text ?? info.prompt ?? info.message ?? info.body), "");
517
+ const direct = sanitizeDebuggerText(configuredValue(info && (info.text ?? info.prompt ?? info.message ?? info.body), ""));
518
518
  if (direct !== "") {
519
519
  return direct;
520
520
  }
521
- if (typeof info?.content === "string" && info.content.trim() !== "") {
522
- return info.content.trim();
521
+ if (typeof info?.content === "string") {
522
+ return sanitizeDebuggerText(info.content);
523
523
  }
524
524
  if (Array.isArray(info?.content)) {
525
- return info.content
525
+ return sanitizeDebuggerText(info.content
526
526
  .map((part) => {
527
527
  if (typeof part === "string") {
528
528
  return part;
@@ -534,11 +534,24 @@ function extractMessageText(info) {
534
534
  })
535
535
  .filter(Boolean)
536
536
  .join("\n")
537
- .trim();
537
+ .trim());
538
538
  }
539
539
  return "";
540
540
  }
541
541
 
542
+ function sanitizeDebuggerText(value) {
543
+ if (typeof value !== "string") {
544
+ return "";
545
+ }
546
+ return value
547
+ .replace(/<system-reminder>[\s\S]*?<\/system-reminder>/gi, "")
548
+ .replace(/<system>[\s\S]*?<\/system>/gi, "")
549
+ .split("\n")
550
+ .filter((line) => !line.trim().startsWith("# Plan Mode - System Reminder"))
551
+ .join("\n")
552
+ .trim();
553
+ }
554
+
542
555
  function summarizePrompt(prompt, fallback) {
543
556
  const trimmed = configuredValue(prompt, fallback);
544
557
  if (trimmed.length <= 80) {