@distlang/opencode-plugin 0.1.9 → 0.1.11
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 +24 -1
- package/package.json +5 -4
- package/src/index.js +8 -0
- package/src/recorder.js +151 -11
package/README.md
CHANGED
|
@@ -130,6 +130,29 @@ npm test
|
|
|
130
130
|
npm run pack:check
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
### Local OpenCode integration test
|
|
134
|
+
|
|
135
|
+
The repository includes a live local integration harness. It is not included in the published npm package.
|
|
136
|
+
|
|
137
|
+
The harness uses your existing local OpenCode auth to run the requested model. It does not read, copy, or print OpenCode credential files. It writes only a temporary OpenCode config that loads this local plugin source.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npm run test:opencode -- --model openai/gpt-5.5
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
If `--model` and `OPENCODE_MODEL` are omitted, the harness defaults to `openai/gpt-5.5`. Use any provider-qualified model ID shown by `opencode models`.
|
|
144
|
+
|
|
145
|
+
Useful flags:
|
|
146
|
+
|
|
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.
|
|
149
|
+
- `--keep-temp` keeps temporary logs and fixtures for debugging. Do not commit those files.
|
|
150
|
+
- `--verbose` prints redacted command output.
|
|
151
|
+
|
|
152
|
+
The default test validates local plugin capture from the plugin debug log. If `distlang` is authenticated, it also validates the uploaded session and deletes it unless `--keep-session` is set.
|
|
153
|
+
|
|
154
|
+
For upload validation, the harness resolves Distlang from `DISTLANG_BIN`, `distlang` on `PATH`, or the plugin-managed binary at `~/.cache/distlang/opencode-plugin/bin/distlang`.
|
|
155
|
+
|
|
133
156
|
## Release
|
|
134
157
|
|
|
135
158
|
This repo uses a manual release flow.
|
|
@@ -149,7 +172,7 @@ git push origin main
|
|
|
149
172
|
3. Publish to npm:
|
|
150
173
|
|
|
151
174
|
```bash
|
|
152
|
-
npm run publish
|
|
175
|
+
npm run publish:public
|
|
153
176
|
```
|
|
154
177
|
|
|
155
178
|
4. Create and push the release tag:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distlang/opencode-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "OpenCode plugin for Distlang AI Debugger",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
"README.md"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"test": "node --check src/index.js && node --check src/recorder.js && node --check src/distlang.js && node --check src/state.js && node --check src/command.js && node --test test/*.test.js",
|
|
17
|
+
"test": "node --check src/index.js && node --check src/recorder.js && node --check src/distlang.js && node --check src/state.js && node --check src/command.js && node --check integration/opencode-local-test.mjs && node --check integration/assert-package-contents.mjs && node --test test/*.test.js",
|
|
18
18
|
"check": "npm test",
|
|
19
|
-
"pack:check": "
|
|
19
|
+
"pack:check": "node integration/assert-package-contents.mjs",
|
|
20
|
+
"test:opencode": "node integration/opencode-local-test.mjs",
|
|
20
21
|
"release": "npm test && npm run pack:check",
|
|
21
|
-
"publish": "npm publish --access public"
|
|
22
|
+
"publish:public": "npm publish --access public"
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|
|
24
25
|
"distlang",
|
package/src/index.js
CHANGED
|
@@ -395,6 +395,14 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
|
|
|
395
395
|
return;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
if (event.type === "message.part.updated") {
|
|
399
|
+
const observed = recorder.observeMessagePartUpdated(event);
|
|
400
|
+
if (observed) {
|
|
401
|
+
await debugLog("message.part.updated observed", observed);
|
|
402
|
+
}
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
398
406
|
if (event.type !== "message.updated") {
|
|
399
407
|
return;
|
|
400
408
|
}
|
package/src/recorder.js
CHANGED
|
@@ -63,6 +63,9 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
63
63
|
interactionCounter: 0,
|
|
64
64
|
stepCounter: 0,
|
|
65
65
|
assistantStates: new Map(),
|
|
66
|
+
messageRoles: new Map(),
|
|
67
|
+
messageTextParts: new Map(),
|
|
68
|
+
messageInteractions: new Map(),
|
|
66
69
|
toolStarts: new Map(),
|
|
67
70
|
seenUserMessages: new Set(),
|
|
68
71
|
};
|
|
@@ -70,10 +73,12 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
70
73
|
return recorder;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
function createInteraction(recorder, prompt, timestampMs) {
|
|
76
|
+
function createInteraction(recorder, prompt, timestampMs, messageID = "") {
|
|
74
77
|
recorder.interactionCounter += 1;
|
|
78
|
+
const stableID = configuredValue(messageID, "");
|
|
79
|
+
const interactionID = stableID ? `${recorder.id}:int:${safeID(stableID)}` : `${recorder.id}:int:${recorder.interactionCounter}`;
|
|
75
80
|
const interaction = {
|
|
76
|
-
id:
|
|
81
|
+
id: interactionID,
|
|
77
82
|
index: recorder.interactionCounter,
|
|
78
83
|
prompt: configuredValue(prompt, `OpenCode interaction ${recorder.interactionCounter}`),
|
|
79
84
|
mode: "build",
|
|
@@ -103,6 +108,45 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
103
108
|
return createInteraction(recorder, configuredValue(prompt, recorder.initialPrompt), timestampMs);
|
|
104
109
|
}
|
|
105
110
|
|
|
111
|
+
function observeUserPrompt(recorder, messageID, prompt, timestampMs) {
|
|
112
|
+
const cleanPrompt = sanitizeDebuggerText(prompt);
|
|
113
|
+
const existingID = recorder.messageInteractions.get(messageID);
|
|
114
|
+
const existing = existingID ? findInteraction(recorder, existingID) : null;
|
|
115
|
+
if (existing) {
|
|
116
|
+
existing.prompt = cleanPrompt;
|
|
117
|
+
existing.summary = summarizePrompt(cleanPrompt, existing.summary || `Interaction ${existing.index}`);
|
|
118
|
+
return existing;
|
|
119
|
+
}
|
|
120
|
+
const current = findInteraction(recorder, recorder.currentInteractionID);
|
|
121
|
+
const currentHasMessage = Array.from(recorder.messageInteractions.values()).includes(current?.id);
|
|
122
|
+
if (current && isGenericInteractionLabel(current.prompt) && !currentHasMessage) {
|
|
123
|
+
current.prompt = cleanPrompt;
|
|
124
|
+
current.summary = summarizePrompt(cleanPrompt, `Interaction ${current.index}`);
|
|
125
|
+
recorder.messageInteractions.set(messageID, current.id);
|
|
126
|
+
recorder.seenUserMessages.add(messageID);
|
|
127
|
+
return current;
|
|
128
|
+
}
|
|
129
|
+
if (recorder.seenUserMessages.has(messageID)) {
|
|
130
|
+
return current || createInteraction(recorder, cleanPrompt, timestampMs);
|
|
131
|
+
}
|
|
132
|
+
recorder.seenUserMessages.add(messageID);
|
|
133
|
+
const interaction = createInteraction(recorder, cleanPrompt, timestampMs, messageID);
|
|
134
|
+
recorder.messageInteractions.set(messageID, interaction.id);
|
|
135
|
+
return interaction;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function interactionForMessage(recorder, messageID, fallbackTimestampMs, prompt = "") {
|
|
139
|
+
const interactionID = configuredValue(recorder.messageInteractions.get(messageID), "");
|
|
140
|
+
const interaction = interactionID ? findInteraction(recorder, interactionID) : null;
|
|
141
|
+
if (interaction) {
|
|
142
|
+
if (prompt && (!interaction.prompt || isGenericInteractionLabel(interaction.prompt))) {
|
|
143
|
+
interaction.prompt = prompt;
|
|
144
|
+
}
|
|
145
|
+
return interaction;
|
|
146
|
+
}
|
|
147
|
+
return ensureInteraction(recorder, fallbackTimestampMs, prompt);
|
|
148
|
+
}
|
|
149
|
+
|
|
106
150
|
function addStep(recorder, interaction, step) {
|
|
107
151
|
recorder.stepCounter += 1;
|
|
108
152
|
const normalized = {
|
|
@@ -192,13 +236,35 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
192
236
|
}
|
|
193
237
|
const recorder = ensureSession(sessionID, Date.now());
|
|
194
238
|
const id = messageID(info) || `${sessionID}:user:${Date.now()}`;
|
|
195
|
-
|
|
196
|
-
|
|
239
|
+
recorder.messageRoles.set(id, "user");
|
|
240
|
+
const prompt = extractMessageText(info) || storedMessageText(recorder, id);
|
|
241
|
+
if (!prompt) {
|
|
242
|
+
return { sessionID, messageID: id, prompt: "" };
|
|
243
|
+
}
|
|
244
|
+
const interaction = observeUserPrompt(recorder, id, prompt, parseMessageTime(info, Date.now()));
|
|
245
|
+
return { sessionID, messageID: id, prompt: interaction.prompt };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function observeMessagePartUpdated(event) {
|
|
249
|
+
const part = extractMessagePart(event);
|
|
250
|
+
if (!part || part.type !== "text") {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
const sessionID = configuredValue(part.sessionID, activeSessionID());
|
|
254
|
+
const messageID = configuredValue(part.messageID, "");
|
|
255
|
+
const partID = configuredValue(part.id, "");
|
|
256
|
+
const text = sanitizeDebuggerText(configuredValue(part.text, configuredValue(event?.properties?.delta, "")));
|
|
257
|
+
if (!sessionID || !messageID || !partID || !text) {
|
|
197
258
|
return null;
|
|
198
259
|
}
|
|
199
|
-
recorder.
|
|
200
|
-
|
|
201
|
-
|
|
260
|
+
const recorder = ensureSession(sessionID, Date.now());
|
|
261
|
+
storeMessageTextPart(recorder, messageID, partID, text);
|
|
262
|
+
const role = recorder.messageRoles.get(messageID);
|
|
263
|
+
if (role !== "user") {
|
|
264
|
+
return { sessionID, messageID, role: configuredValue(role, "unknown"), text };
|
|
265
|
+
}
|
|
266
|
+
const interaction = observeUserPrompt(recorder, messageID, storedMessageText(recorder, messageID), parsePartTime(part, Date.now()));
|
|
267
|
+
return { sessionID, messageID, role, text: interaction.prompt };
|
|
202
268
|
}
|
|
203
269
|
|
|
204
270
|
function observeAssistantMessage(event) {
|
|
@@ -212,10 +278,15 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
212
278
|
return null;
|
|
213
279
|
}
|
|
214
280
|
const recorder = ensureSession(sessionID, Date.now());
|
|
215
|
-
|
|
281
|
+
recorder.messageRoles.set(id, "assistant");
|
|
282
|
+
const parentID = messageParentID(info);
|
|
283
|
+
const parentInteractionID = configuredValue(recorder.messageInteractions.get(parentID), "");
|
|
284
|
+
const parentInteraction = parentInteractionID ? findInteraction(recorder, parentInteractionID) : null;
|
|
285
|
+
const interaction = parentInteraction || interactionForMessage(recorder, id, Date.now());
|
|
286
|
+
recorder.messageInteractions.set(id, interaction.id);
|
|
216
287
|
const now = Date.now();
|
|
217
288
|
const existing = recorder.assistantStates.get(id) || {
|
|
218
|
-
firstSeenAt:
|
|
289
|
+
firstSeenAt: parseMessageTime(info, now),
|
|
219
290
|
firstTokenAt: null,
|
|
220
291
|
interactionID: interaction.id,
|
|
221
292
|
provider: assistantProvider(info),
|
|
@@ -232,10 +303,11 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
232
303
|
if (finalState.isFinal && !existing.finalized) {
|
|
233
304
|
existing.finalized = true;
|
|
234
305
|
const targetInteraction = findInteraction(recorder, existing.interactionID) || interaction;
|
|
306
|
+
const assistantText = extractMessageText(info) || storedMessageText(recorder, id);
|
|
235
307
|
addStep(recorder, targetInteraction, {
|
|
236
308
|
kind: "llm_call",
|
|
237
309
|
phase: targetInteraction.mode,
|
|
238
|
-
title: summarizePrompt(
|
|
310
|
+
title: summarizePrompt(assistantText, `Assistant response ${targetInteraction.index}`),
|
|
239
311
|
started_at: new Date(existing.firstSeenAt).toISOString(),
|
|
240
312
|
ended_at: new Date(now).toISOString(),
|
|
241
313
|
duration_ms: Math.max(0, now - existing.firstSeenAt),
|
|
@@ -272,9 +344,12 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
272
344
|
return null;
|
|
273
345
|
}
|
|
274
346
|
const recorder = ensureSession(sessionID, Date.now());
|
|
347
|
+
const messageID = toolMessageID(input);
|
|
348
|
+
const interactionID = configuredValue(recorder.messageInteractions.get(messageID), configuredValue(recorder.currentInteractionID, ""));
|
|
275
349
|
recorder.toolStarts.set(callID, {
|
|
276
350
|
startedAt: Date.now(),
|
|
277
351
|
tool: configuredValue(input && input.tool, "unknown"),
|
|
352
|
+
interactionID,
|
|
278
353
|
});
|
|
279
354
|
return { sessionID, callID, tool: configuredValue(input && input.tool, "unknown") };
|
|
280
355
|
}
|
|
@@ -289,7 +364,9 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
289
364
|
const toolState = callID && recorder.toolStarts.has(callID)
|
|
290
365
|
? recorder.toolStarts.get(callID)
|
|
291
366
|
: { startedAt: Date.now(), tool: configuredValue(input && input.tool, "unknown") };
|
|
292
|
-
const
|
|
367
|
+
const messageID = toolMessageID(input) || toolMessageID(output);
|
|
368
|
+
const mappedInteractionID = configuredValue(toolState.interactionID, configuredValue(recorder.messageInteractions.get(messageID), ""));
|
|
369
|
+
const interaction = mappedInteractionID ? findInteraction(recorder, mappedInteractionID) || ensureInteraction(recorder, Date.now()) : ensureInteraction(recorder, Date.now());
|
|
293
370
|
addStep(recorder, interaction, {
|
|
294
371
|
kind: "tool_call",
|
|
295
372
|
phase: interaction.mode,
|
|
@@ -350,6 +427,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
350
427
|
setSessionTitle,
|
|
351
428
|
observeFileEdited,
|
|
352
429
|
observeUserMessage,
|
|
430
|
+
observeMessagePartUpdated,
|
|
353
431
|
observeAssistantMessage,
|
|
354
432
|
observeToolBefore,
|
|
355
433
|
observeToolAfter,
|
|
@@ -358,6 +436,20 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
358
436
|
};
|
|
359
437
|
}
|
|
360
438
|
|
|
439
|
+
function storeMessageTextPart(recorder, messageID, partID, text) {
|
|
440
|
+
const parts = recorder.messageTextParts.get(messageID) || new Map();
|
|
441
|
+
parts.set(partID, sanitizeDebuggerText(text));
|
|
442
|
+
recorder.messageTextParts.set(messageID, parts);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function storedMessageText(recorder, messageID) {
|
|
446
|
+
const parts = recorder.messageTextParts.get(messageID);
|
|
447
|
+
if (!parts) {
|
|
448
|
+
return "";
|
|
449
|
+
}
|
|
450
|
+
return sanitizeDebuggerText(Array.from(parts.values()).filter(Boolean).join("\n"));
|
|
451
|
+
}
|
|
452
|
+
|
|
361
453
|
function buildSessionPayload(recorder) {
|
|
362
454
|
const sessionTitle = sanitizeDebuggerText(recorder.title);
|
|
363
455
|
const interactions = recorder.interactions.map((interaction) => buildInteractionPayload(interaction, sessionTitle));
|
|
@@ -485,6 +577,35 @@ function extractMessageInfo(event) {
|
|
|
485
577
|
return null;
|
|
486
578
|
}
|
|
487
579
|
|
|
580
|
+
function extractMessagePart(event) {
|
|
581
|
+
if (!event || typeof event !== "object") {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
if (event.part && typeof event.part === "object") {
|
|
585
|
+
return event.part;
|
|
586
|
+
}
|
|
587
|
+
if (event.properties && event.properties.part && typeof event.properties.part === "object") {
|
|
588
|
+
return event.properties.part;
|
|
589
|
+
}
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function parseMessageTime(info, fallback) {
|
|
594
|
+
const time = info && info.time;
|
|
595
|
+
if (time && typeof time === "object") {
|
|
596
|
+
return parseTimestamp(time.created, fallback);
|
|
597
|
+
}
|
|
598
|
+
return parseTimestamp(time, fallback);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function parsePartTime(part, fallback) {
|
|
602
|
+
const time = part && part.time;
|
|
603
|
+
if (time && typeof time === "object") {
|
|
604
|
+
return parseTimestamp(time.start ?? time.created, fallback);
|
|
605
|
+
}
|
|
606
|
+
return parseTimestamp(time, fallback);
|
|
607
|
+
}
|
|
608
|
+
|
|
488
609
|
function isAssistantMessage(info) {
|
|
489
610
|
if (!info || typeof info !== "object") {
|
|
490
611
|
return false;
|
|
@@ -512,10 +633,29 @@ function messageID(info) {
|
|
|
512
633
|
return configuredValue(info && info.id, "");
|
|
513
634
|
}
|
|
514
635
|
|
|
636
|
+
function messageParentID(info) {
|
|
637
|
+
return configuredValue(info && (info.parentID ?? info.parentId ?? info.parent_id), "");
|
|
638
|
+
}
|
|
639
|
+
|
|
515
640
|
function messageSessionID(info, event) {
|
|
516
641
|
return configuredValue(info && info.sessionID, configuredValue(event && event.sessionID, ""));
|
|
517
642
|
}
|
|
518
643
|
|
|
644
|
+
function toolMessageID(value) {
|
|
645
|
+
if (!value || typeof value !== "object") {
|
|
646
|
+
return "";
|
|
647
|
+
}
|
|
648
|
+
return configuredValue(
|
|
649
|
+
value.messageID ?? value.messageId ?? value.message_id,
|
|
650
|
+
configuredValue(value.assistantMessageID ?? value.assistantMessageId ?? value.assistant_message_id, configuredValue(value.properties?.messageID ?? value.properties?.messageId ?? value.properties?.message_id, "")),
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function safeID(value) {
|
|
655
|
+
const cleaned = String(value || "").replace(/[^A-Za-z0-9_.:-]/g, "_");
|
|
656
|
+
return cleaned || "unknown";
|
|
657
|
+
}
|
|
658
|
+
|
|
519
659
|
function assistantProvider(info) {
|
|
520
660
|
return configuredValue(info && info.providerID, configuredValue(info && info.model && info.model.providerID, "unknown"));
|
|
521
661
|
}
|