@distlang/opencode-plugin 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distlang/opencode-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "OpenCode plugin for Distlang AI Debugger",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/distlang.js CHANGED
@@ -7,14 +7,26 @@ import { promisify } from "node:util";
7
7
 
8
8
  const execFileAsync = promisify(execFile);
9
9
 
10
+ function distlangBinary() {
11
+ return process.env.DISTLANG_BIN && process.env.DISTLANG_BIN.trim() !== ""
12
+ ? process.env.DISTLANG_BIN.trim()
13
+ : "distlang";
14
+ }
15
+
10
16
  export async function runDistlang(args, options = {}) {
11
- return execFileAsync("distlang", args, {
17
+ return execFileAsync(distlangBinary(), args, {
12
18
  env: process.env,
13
19
  maxBuffer: 16 * 1024 * 1024,
14
20
  ...options,
15
21
  });
16
22
  }
17
23
 
24
+ export function distlangCommandInfo() {
25
+ return {
26
+ bin: distlangBinary(),
27
+ };
28
+ }
29
+
18
30
  export async function getAuthStatus() {
19
31
  const { stdout } = await runDistlang(["helpers", "auth", "status", "--json"]);
20
32
  return JSON.parse(stdout || "{}");
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRecorder } from "./recorder.js";
2
- import { getAuthStatus, uploadAIDebuggerPayload } from "./distlang.js";
2
+ import { distlangCommandInfo, getAuthStatus, uploadAIDebuggerPayload } from "./distlang.js";
3
3
 
4
4
  function configuredValue(value, fallback = "") {
5
5
  return typeof value === "string" && value.trim() !== "" ? value.trim() : fallback;
@@ -47,6 +47,7 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
47
47
  loggedInit = true;
48
48
  await log(debug ? "debug" : "info", "Distlang OpenCode AI Debugger plugin initialized", {
49
49
  debug,
50
+ distlang: distlangCommandInfo(),
50
51
  });
51
52
  }
52
53
 
@@ -58,6 +59,7 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
58
59
  try {
59
60
  const payload = await getAuthStatus();
60
61
  authAvailable = payload && payload.ok === true && payload.logged_in === true;
62
+ await debugLog("Distlang auth status resolved", { authAvailable, payload });
61
63
  if (!authAvailable && !authWarningLogged) {
62
64
  authWarningLogged = true;
63
65
  await log("warn", "Distlang AI Debugger upload disabled: run `distlang helpers login` first", { auth: payload });
@@ -67,7 +69,7 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
67
69
  if (error && typeof error === "object" && error.code === "ENOENT") {
68
70
  if (!distlangMissingLogged) {
69
71
  distlangMissingLogged = true;
70
- await log("warn", "distlang CLI not found; AI Debugger upload disabled");
72
+ await log("warn", "distlang CLI not found; AI Debugger upload disabled", { distlang: distlangCommandInfo() });
71
73
  }
72
74
  } else if (!authWarningLogged) {
73
75
  authWarningLogged = true;
@@ -81,14 +83,23 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
81
83
  async function finalizeSession(sessionID, result) {
82
84
  const payload = recorder.finalizeSession(sessionID, result, Date.now());
83
85
  if (!payload) {
86
+ await debugLog("No payload produced during session finalization", { sessionID, result });
84
87
  return;
85
88
  }
89
+ await debugLog("Finalized AI Debugger session payload", {
90
+ sessionID,
91
+ result,
92
+ interactions: Array.isArray(payload.interactions) ? payload.interactions.length : 0,
93
+ steps: Array.isArray(payload.interactions) ? payload.interactions.reduce((total, interaction) => total + (Array.isArray(interaction.steps) ? interaction.steps.length : 0), 0) : 0,
94
+ project: payload.project,
95
+ });
86
96
  if (!(await ensureAuthStatus())) {
87
97
  await debugLog("Skipping AI debugger upload because auth is unavailable", { sessionID });
88
98
  return;
89
99
  }
90
100
  try {
91
101
  const response = await uploadAIDebuggerPayload(payload);
102
+ await debugLog("AI Debugger upload response received", { sessionID, response });
92
103
  if (!response.ok) {
93
104
  await log("warn", "AI Debugger upload failed", { sessionID, response });
94
105
  return;
@@ -115,8 +126,9 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
115
126
  }
116
127
 
117
128
  if (event.type === "session.idle" || event.type === "session.error") {
118
- const sessionID = configuredValue(event.sessionID, "");
129
+ const sessionID = configuredValue(event.sessionID, recorder.activeSessionID());
119
130
  if (!sessionID) {
131
+ await debugLog("Session terminal event missing sessionID", { type: event.type, eventKeys: Object.keys(event) });
120
132
  return;
121
133
  }
122
134
  const result = event.type === "session.error" ? "error" : "success";
package/src/recorder.js CHANGED
@@ -303,6 +303,7 @@ export function createRecorder({ project, directory }) {
303
303
  }
304
304
 
305
305
  return {
306
+ activeSessionID,
306
307
  observeSessionCreated,
307
308
  observeFileEdited,
308
309
  observeUserMessage,