@distlang/opencode-plugin 0.1.10 → 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 +4 -3
- package/src/recorder.js +48 -6
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,9 +14,10 @@
|
|
|
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
22
|
"publish:public": "npm publish --access public"
|
|
22
23
|
},
|
package/src/recorder.js
CHANGED
|
@@ -73,10 +73,12 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
73
73
|
return recorder;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
function createInteraction(recorder, prompt, timestampMs) {
|
|
76
|
+
function createInteraction(recorder, prompt, timestampMs, messageID = "") {
|
|
77
77
|
recorder.interactionCounter += 1;
|
|
78
|
+
const stableID = configuredValue(messageID, "");
|
|
79
|
+
const interactionID = stableID ? `${recorder.id}:int:${safeID(stableID)}` : `${recorder.id}:int:${recorder.interactionCounter}`;
|
|
78
80
|
const interaction = {
|
|
79
|
-
id:
|
|
81
|
+
id: interactionID,
|
|
80
82
|
index: recorder.interactionCounter,
|
|
81
83
|
prompt: configuredValue(prompt, `OpenCode interaction ${recorder.interactionCounter}`),
|
|
82
84
|
mode: "build",
|
|
@@ -128,11 +130,23 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
128
130
|
return current || createInteraction(recorder, cleanPrompt, timestampMs);
|
|
129
131
|
}
|
|
130
132
|
recorder.seenUserMessages.add(messageID);
|
|
131
|
-
const interaction = createInteraction(recorder, cleanPrompt, timestampMs);
|
|
133
|
+
const interaction = createInteraction(recorder, cleanPrompt, timestampMs, messageID);
|
|
132
134
|
recorder.messageInteractions.set(messageID, interaction.id);
|
|
133
135
|
return interaction;
|
|
134
136
|
}
|
|
135
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
|
+
|
|
136
150
|
function addStep(recorder, interaction, step) {
|
|
137
151
|
recorder.stepCounter += 1;
|
|
138
152
|
const normalized = {
|
|
@@ -265,10 +279,14 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
265
279
|
}
|
|
266
280
|
const recorder = ensureSession(sessionID, Date.now());
|
|
267
281
|
recorder.messageRoles.set(id, "assistant");
|
|
268
|
-
const
|
|
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);
|
|
269
287
|
const now = Date.now();
|
|
270
288
|
const existing = recorder.assistantStates.get(id) || {
|
|
271
|
-
firstSeenAt:
|
|
289
|
+
firstSeenAt: parseMessageTime(info, now),
|
|
272
290
|
firstTokenAt: null,
|
|
273
291
|
interactionID: interaction.id,
|
|
274
292
|
provider: assistantProvider(info),
|
|
@@ -326,9 +344,12 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
326
344
|
return null;
|
|
327
345
|
}
|
|
328
346
|
const recorder = ensureSession(sessionID, Date.now());
|
|
347
|
+
const messageID = toolMessageID(input);
|
|
348
|
+
const interactionID = configuredValue(recorder.messageInteractions.get(messageID), configuredValue(recorder.currentInteractionID, ""));
|
|
329
349
|
recorder.toolStarts.set(callID, {
|
|
330
350
|
startedAt: Date.now(),
|
|
331
351
|
tool: configuredValue(input && input.tool, "unknown"),
|
|
352
|
+
interactionID,
|
|
332
353
|
});
|
|
333
354
|
return { sessionID, callID, tool: configuredValue(input && input.tool, "unknown") };
|
|
334
355
|
}
|
|
@@ -343,7 +364,9 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
343
364
|
const toolState = callID && recorder.toolStarts.has(callID)
|
|
344
365
|
? recorder.toolStarts.get(callID)
|
|
345
366
|
: { startedAt: Date.now(), tool: configuredValue(input && input.tool, "unknown") };
|
|
346
|
-
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());
|
|
347
370
|
addStep(recorder, interaction, {
|
|
348
371
|
kind: "tool_call",
|
|
349
372
|
phase: interaction.mode,
|
|
@@ -610,10 +633,29 @@ function messageID(info) {
|
|
|
610
633
|
return configuredValue(info && info.id, "");
|
|
611
634
|
}
|
|
612
635
|
|
|
636
|
+
function messageParentID(info) {
|
|
637
|
+
return configuredValue(info && (info.parentID ?? info.parentId ?? info.parent_id), "");
|
|
638
|
+
}
|
|
639
|
+
|
|
613
640
|
function messageSessionID(info, event) {
|
|
614
641
|
return configuredValue(info && info.sessionID, configuredValue(event && event.sessionID, ""));
|
|
615
642
|
}
|
|
616
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
|
+
|
|
617
659
|
function assistantProvider(info) {
|
|
618
660
|
return configuredValue(info && info.providerID, configuredValue(info && info.model && info.model.providerID, "unknown"));
|
|
619
661
|
}
|