@distlang/opencode-plugin 0.2.3 → 0.2.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 +2 -0
- package/package.json +1 -1
- package/src/command.js +1 -1
- package/src/index.js +125 -10
package/README.md
CHANGED
|
@@ -96,6 +96,7 @@ The plugin watches for these commands:
|
|
|
96
96
|
- `/distlang-start`
|
|
97
97
|
- `/distlang-stop`
|
|
98
98
|
- `/distlang-status`
|
|
99
|
+
- `/distlang-view [session-id]`
|
|
99
100
|
|
|
100
101
|
The legacy compact command also remains supported:
|
|
101
102
|
|
|
@@ -123,6 +124,7 @@ Commands:
|
|
|
123
124
|
- `/distlang-status`: show whether uploads are enabled, whether auth is available, and whether recent Agent Debugger sessions are visible
|
|
124
125
|
- `/distlang-start`: sign in if needed and enable Agent Debugger uploads
|
|
125
126
|
- `/distlang-stop`: disable Agent Debugger uploads and sign out of Distlang
|
|
127
|
+
- `/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
|
|
126
128
|
|
|
127
129
|
Legacy aliases remain available: `/distlang status`, `/distlang start`, `/distlang stop`, `/distlang login`, and `/distlang logout`.
|
|
128
130
|
|
package/package.json
CHANGED
package/src/command.js
CHANGED
|
@@ -78,7 +78,7 @@ function distlangInvocation(parsed) {
|
|
|
78
78
|
return parsed;
|
|
79
79
|
}
|
|
80
80
|
const action = parsed.name.startsWith("distlang-") ? parsed.name.slice("distlang-".length) : "";
|
|
81
|
-
if (action === "start" || action === "stop" || action === "status") {
|
|
81
|
+
if (action === "start" || action === "stop" || action === "status" || action === "view") {
|
|
82
82
|
return {
|
|
83
83
|
...parsed,
|
|
84
84
|
name: "distlang",
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { extractDistlangInvocation } from "./command.js";
|
|
|
3
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
|
+
import { spawn } from "node:child_process";
|
|
6
7
|
|
|
7
8
|
function configuredValue(value, fallback = "") {
|
|
8
9
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : fallback;
|
|
@@ -90,6 +91,80 @@ export const DistlangAgentDebugger = async ({ project, directory, client }) => {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
function dashboardBaseUrl() {
|
|
95
|
+
return configuredValue(process.env.DISTLANG_DASHBOARD_URL, "https://dash.distlang.com").replace(/\/+$/, "");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function sessionUrl(sessionID) {
|
|
99
|
+
const id = configuredValue(sessionID, "");
|
|
100
|
+
return id ? `${dashboardBaseUrl()}/agent-debugger/sessions/${encodeURIComponent(id)}` : "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function agentDebuggerUrl() {
|
|
104
|
+
return `${dashboardBaseUrl()}/agent-debugger`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function openerCommand() {
|
|
108
|
+
if (process.platform === "darwin") return { command: "open", args: [] };
|
|
109
|
+
if (process.platform === "win32") return { command: "cmd", args: ["/c", "start", ""] };
|
|
110
|
+
return { command: "xdg-open", args: [] };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function openUrl(url) {
|
|
114
|
+
const { command, args } = openerCommand();
|
|
115
|
+
return new Promise((resolve) => {
|
|
116
|
+
try {
|
|
117
|
+
const child = spawn(command, [...args, url], { detached: true, stdio: "ignore" });
|
|
118
|
+
child.on("error", () => resolve(false));
|
|
119
|
+
child.unref();
|
|
120
|
+
resolve(true);
|
|
121
|
+
} catch {
|
|
122
|
+
resolve(false);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function commandArgument(invocation, action) {
|
|
128
|
+
const args = Array.isArray(invocation?.args) ? invocation.args : [];
|
|
129
|
+
if (configuredValue(invocation?.action, "")) {
|
|
130
|
+
return configuredValue(args[0], "");
|
|
131
|
+
}
|
|
132
|
+
return configuredValue(args[0], "").toLowerCase() === action ? configuredValue(args[1], "") : configuredValue(args[0], "");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function sessionsFromResponse(response) {
|
|
136
|
+
const candidates = [
|
|
137
|
+
response?.body?.sessions,
|
|
138
|
+
response?.sessions,
|
|
139
|
+
response?.body?.data?.sessions,
|
|
140
|
+
response?.data?.sessions,
|
|
141
|
+
response?.body?.items,
|
|
142
|
+
response?.items,
|
|
143
|
+
];
|
|
144
|
+
for (const candidate of candidates) {
|
|
145
|
+
if (Array.isArray(candidate)) return candidate;
|
|
146
|
+
}
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function firstSessionID(response) {
|
|
151
|
+
for (const session of sessionsFromResponse(response)) {
|
|
152
|
+
const id = configuredValue(session?.id, configuredValue(session?.session_id, ""));
|
|
153
|
+
if (id) return id;
|
|
154
|
+
}
|
|
155
|
+
return "";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function ensureCommandAuth(source, action, state = null, resolved = null) {
|
|
159
|
+
let auth = await getAuthStatus();
|
|
160
|
+
if (!auth || auth.ok !== true || auth.logged_in !== true) {
|
|
161
|
+
await maybeLogCommandResult("info", "Opening browser for Distlang login", { source, action, state, distlang: resolved });
|
|
162
|
+
await loginWithDistlang();
|
|
163
|
+
auth = await getAuthStatus();
|
|
164
|
+
}
|
|
165
|
+
return auth;
|
|
166
|
+
}
|
|
167
|
+
|
|
93
168
|
async function handleDistlangCommand(invocation, source) {
|
|
94
169
|
const now = Date.now();
|
|
95
170
|
if (now - commandHandledAt < 250) {
|
|
@@ -98,11 +173,11 @@ export const DistlangAgentDebugger = async ({ project, directory, client }) => {
|
|
|
98
173
|
commandHandledAt = now;
|
|
99
174
|
const requestedAction = configuredValue(invocation.action, configuredValue(invocation.args[0], "status")).toLowerCase();
|
|
100
175
|
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-
|
|
176
|
+
if (!["status", "start", "stop", "view"].includes(action)) {
|
|
177
|
+
await maybeLogCommandResult("warn", "Unknown Distlang command. Use /distlang-status, /distlang-start, /distlang-stop, or /distlang-view", {
|
|
103
178
|
source,
|
|
104
179
|
action: requestedAction,
|
|
105
|
-
command_hint: "/distlang-status | /distlang-start | /distlang-stop",
|
|
180
|
+
command_hint: "/distlang-status | /distlang-start | /distlang-stop | /distlang-view",
|
|
106
181
|
});
|
|
107
182
|
return;
|
|
108
183
|
}
|
|
@@ -118,12 +193,7 @@ export const DistlangAgentDebugger = async ({ project, directory, client }) => {
|
|
|
118
193
|
return;
|
|
119
194
|
}
|
|
120
195
|
try {
|
|
121
|
-
auth = await
|
|
122
|
-
if (!auth || auth.ok !== true || auth.logged_in !== true) {
|
|
123
|
-
await maybeLogCommandResult("info", "Opening browser for Distlang login", { source, action, state, distlang: resolved });
|
|
124
|
-
await loginWithDistlang();
|
|
125
|
-
auth = await getAuthStatus();
|
|
126
|
-
}
|
|
196
|
+
auth = await ensureCommandAuth(source, action, state, resolved);
|
|
127
197
|
} catch (error) {
|
|
128
198
|
await maybeLogCommandResult("warn", "Distlang uploads enabled, but auth check failed", { source, action, state, distlang: resolved, error: String(error) });
|
|
129
199
|
return;
|
|
@@ -151,6 +221,51 @@ export const DistlangAgentDebugger = async ({ project, directory, client }) => {
|
|
|
151
221
|
return;
|
|
152
222
|
}
|
|
153
223
|
|
|
224
|
+
if (action === "view") {
|
|
225
|
+
const state = await readPluginState();
|
|
226
|
+
let resolved = null;
|
|
227
|
+
let auth = null;
|
|
228
|
+
let sessions = null;
|
|
229
|
+
try {
|
|
230
|
+
resolved = await resolveDistlangBinary({ installIfMissing: true });
|
|
231
|
+
auth = await ensureCommandAuth(source, action, state, resolved);
|
|
232
|
+
sessions = await fetchAgentDebuggerSessions();
|
|
233
|
+
} catch (error) {
|
|
234
|
+
await maybeLogCommandResult("warn", "Unable to open Distlang Agent Debugger session", { source, action, state, distlang: resolved, error: String(error) });
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const sessionID = commandArgument(invocation, action) || firstSessionID(sessions);
|
|
238
|
+
const url = sessionID ? sessionUrl(sessionID) : agentDebuggerUrl();
|
|
239
|
+
const opened = await openUrl(url);
|
|
240
|
+
if (!sessionID) {
|
|
241
|
+
await maybeLogCommandResult("info", `Open Distlang Agent Debugger: ${url}`, {
|
|
242
|
+
source,
|
|
243
|
+
action,
|
|
244
|
+
state,
|
|
245
|
+
distlang: resolved,
|
|
246
|
+
auth,
|
|
247
|
+
session_id: null,
|
|
248
|
+
url,
|
|
249
|
+
opened,
|
|
250
|
+
fallback: "agent_debugger_overview",
|
|
251
|
+
sessions,
|
|
252
|
+
});
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
await maybeLogCommandResult("info", `Open Distlang Agent Debugger session: ${url}`, {
|
|
256
|
+
source,
|
|
257
|
+
action,
|
|
258
|
+
state,
|
|
259
|
+
distlang: resolved,
|
|
260
|
+
auth,
|
|
261
|
+
session_id: sessionID,
|
|
262
|
+
url,
|
|
263
|
+
opened,
|
|
264
|
+
sessions,
|
|
265
|
+
});
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
154
269
|
const state = await readPluginState();
|
|
155
270
|
let resolved = null;
|
|
156
271
|
let auth = null;
|
|
@@ -171,7 +286,7 @@ export const DistlangAgentDebugger = async ({ project, directory, client }) => {
|
|
|
171
286
|
auth,
|
|
172
287
|
sessions,
|
|
173
288
|
error: resolutionError,
|
|
174
|
-
command_hint: "/distlang-status | /distlang-start | /distlang-stop",
|
|
289
|
+
command_hint: "/distlang-status | /distlang-start | /distlang-stop | /distlang-view",
|
|
175
290
|
});
|
|
176
291
|
}
|
|
177
292
|
|