@distlang/opencode-plugin 0.1.13 → 0.1.15

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/recorder.js +86 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distlang/opencode-plugin",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "OpenCode plugin for Distlang AI Debugger",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/recorder.js CHANGED
@@ -34,6 +34,7 @@ const extensionLanguages = {
34
34
 
35
35
  export function createRecorder({ project, directory, initialPrompt = "" }) {
36
36
  const projectName = deriveProjectName(project, directory);
37
+ const initialMode = inferInteractionMode(initialPrompt);
37
38
  const configuredInitialPrompt = sanitizeDebuggerText(initialPrompt);
38
39
  const sessions = new Map();
39
40
 
@@ -58,6 +59,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
58
59
  summary: "",
59
60
  title: "",
60
61
  initialPrompt: configuredInitialPrompt,
62
+ initialMode,
61
63
  interactions: [],
62
64
  currentInteractionID: "",
63
65
  interactionCounter: 0,
@@ -75,7 +77,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
75
77
  return recorder;
76
78
  }
77
79
 
78
- function createInteraction(recorder, prompt, timestampMs, messageID = "") {
80
+ function createInteraction(recorder, prompt, timestampMs, messageID = "", mode = inferInteractionMode(prompt)) {
79
81
  recorder.interactionCounter += 1;
80
82
  const stableID = configuredValue(messageID, "");
81
83
  const interactionID = stableID ? `${recorder.id}:int:${safeID(stableID)}` : `${recorder.id}:int:${recorder.interactionCounter}`;
@@ -83,7 +85,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
83
85
  id: interactionID,
84
86
  index: recorder.interactionCounter,
85
87
  prompt: configuredValue(prompt, `OpenCode interaction ${recorder.interactionCounter}`),
86
- mode: "build",
88
+ mode,
87
89
  startedAtMs: timestampMs,
88
90
  endedAtMs: 0,
89
91
  status: "success",
@@ -99,24 +101,26 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
99
101
  return recorder.interactions.find((interaction) => interaction.id === interactionID) || null;
100
102
  }
101
103
 
102
- function ensureInteraction(recorder, timestampMs, prompt = "") {
104
+ function ensureInteraction(recorder, timestampMs, prompt = "", mode = inferInteractionMode(prompt)) {
103
105
  const current = findInteraction(recorder, recorder.currentInteractionID);
104
106
  if (current) {
105
107
  if (prompt && (!current.prompt || isGenericInteractionLabel(current.prompt))) {
106
108
  current.prompt = prompt;
107
109
  }
110
+ applyInteractionMode(current, mode);
108
111
  return current;
109
112
  }
110
- return createInteraction(recorder, configuredValue(prompt, recorder.initialPrompt), timestampMs);
113
+ return createInteraction(recorder, configuredValue(prompt, recorder.initialPrompt), timestampMs, "", mode === "plan" ? mode : recorder.initialMode);
111
114
  }
112
115
 
113
- function observeUserPrompt(recorder, messageID, prompt, timestampMs) {
116
+ function observeUserPrompt(recorder, messageID, prompt, timestampMs, mode = inferInteractionMode(prompt)) {
114
117
  const cleanPrompt = sanitizeDebuggerText(prompt);
115
118
  const existingID = recorder.messageInteractions.get(messageID);
116
119
  const existing = existingID ? findInteraction(recorder, existingID) : null;
117
120
  if (existing) {
118
121
  existing.prompt = cleanPrompt;
119
122
  existing.summary = summarizePrompt(cleanPrompt, existing.summary || `Interaction ${existing.index}`);
123
+ applyInteractionMode(existing, mode);
120
124
  return existing;
121
125
  }
122
126
  const current = findInteraction(recorder, recorder.currentInteractionID);
@@ -124,29 +128,35 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
124
128
  if (current && isGenericInteractionLabel(current.prompt) && !currentHasMessage) {
125
129
  current.prompt = cleanPrompt;
126
130
  current.summary = summarizePrompt(cleanPrompt, `Interaction ${current.index}`);
131
+ applyInteractionMode(current, mode);
127
132
  recorder.messageInteractions.set(messageID, current.id);
128
133
  recorder.seenUserMessages.add(messageID);
129
134
  return current;
130
135
  }
131
136
  if (recorder.seenUserMessages.has(messageID)) {
132
- return current || createInteraction(recorder, cleanPrompt, timestampMs);
137
+ if (current) {
138
+ applyInteractionMode(current, mode);
139
+ return current;
140
+ }
141
+ return createInteraction(recorder, cleanPrompt, timestampMs, "", mode);
133
142
  }
134
143
  recorder.seenUserMessages.add(messageID);
135
- const interaction = createInteraction(recorder, cleanPrompt, timestampMs, messageID);
144
+ const interaction = createInteraction(recorder, cleanPrompt, timestampMs, messageID, mode);
136
145
  recorder.messageInteractions.set(messageID, interaction.id);
137
146
  return interaction;
138
147
  }
139
148
 
140
- function interactionForMessage(recorder, messageID, fallbackTimestampMs, prompt = "") {
149
+ function interactionForMessage(recorder, messageID, fallbackTimestampMs, prompt = "", mode = inferInteractionMode(prompt)) {
141
150
  const interactionID = configuredValue(recorder.messageInteractions.get(messageID), "");
142
151
  const interaction = interactionID ? findInteraction(recorder, interactionID) : null;
143
152
  if (interaction) {
144
153
  if (prompt && (!interaction.prompt || isGenericInteractionLabel(interaction.prompt))) {
145
154
  interaction.prompt = prompt;
146
155
  }
156
+ applyInteractionMode(interaction, mode);
147
157
  return interaction;
148
158
  }
149
- return ensureInteraction(recorder, fallbackTimestampMs, prompt);
159
+ return ensureInteraction(recorder, fallbackTimestampMs, prompt, mode);
150
160
  }
151
161
 
152
162
  function addStep(recorder, interaction, step) {
@@ -219,10 +229,10 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
219
229
  return null;
220
230
  }
221
231
  const recorder = ensureSession(sessionID, Date.now());
222
- const interaction = ensureInteraction(recorder, Date.now());
232
+ const interaction = ensureInteraction(recorder, Date.now(), "", inferInteractionMode(event));
223
233
  addStep(recorder, interaction, {
224
234
  kind: "file_edit",
225
- phase: "build",
235
+ phase: interaction.mode,
226
236
  title: `Edit ${filePath}`,
227
237
  started_at: new Date().toISOString(),
228
238
  ended_at: new Date().toISOString(),
@@ -241,14 +251,15 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
241
251
  const recorder = ensureSession(sessionID, Date.now());
242
252
  const id = messageID(info) || `${sessionID}:user:${Date.now()}`;
243
253
  recorder.messageRoles.set(id, "user");
254
+ const mode = inferInteractionMode(info, event);
244
255
  const prompt = extractMessageText(info) || storedMessageText(recorder, id);
245
256
  if (!prompt) {
246
257
  return { sessionID, messageID: id, prompt: "" };
247
258
  }
248
- const interaction = observeUserPrompt(recorder, id, prompt, parseMessageTime(info, Date.now()));
259
+ const interaction = observeUserPrompt(recorder, id, prompt, parseMessageTime(info, Date.now()), mode);
249
260
  addContextContributor(recorder, {
250
261
  category: "user_prompt",
251
- label: `User prompt ${interaction.index}`,
262
+ label: `User prompt from Interaction ${interaction.index}`,
252
263
  source: "opencode.message",
253
264
  text: prompt,
254
265
  });
@@ -273,7 +284,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
273
284
  if (role !== "user") {
274
285
  return { sessionID, messageID, role: configuredValue(role, "unknown"), text };
275
286
  }
276
- const interaction = observeUserPrompt(recorder, messageID, storedMessageText(recorder, messageID), parsePartTime(part, Date.now()));
287
+ const interaction = observeUserPrompt(recorder, messageID, storedMessageText(recorder, messageID), parsePartTime(part, Date.now()), inferInteractionMode(part, event));
277
288
  return { sessionID, messageID, role, text: interaction.prompt };
278
289
  }
279
290
 
@@ -292,7 +303,10 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
292
303
  const parentID = messageParentID(info);
293
304
  const parentInteractionID = configuredValue(recorder.messageInteractions.get(parentID), "");
294
305
  const parentInteraction = parentInteractionID ? findInteraction(recorder, parentInteractionID) : null;
295
- const interaction = parentInteraction || interactionForMessage(recorder, id, Date.now());
306
+ const assistantText = extractMessageText(info) || storedMessageText(recorder, id);
307
+ const mode = inferInteractionMode(info, event, assistantText);
308
+ const interaction = parentInteraction || interactionForMessage(recorder, id, Date.now(), "", mode);
309
+ applyInteractionMode(interaction, mode);
296
310
  recorder.messageInteractions.set(id, interaction.id);
297
311
  const now = Date.now();
298
312
  const existing = recorder.assistantStates.get(id) || {
@@ -313,11 +327,11 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
313
327
  if (finalState.isFinal && !existing.finalized) {
314
328
  existing.finalized = true;
315
329
  const targetInteraction = findInteraction(recorder, existing.interactionID) || interaction;
316
- const assistantText = extractMessageText(info) || storedMessageText(recorder, id);
330
+ applyInteractionMode(targetInteraction, mode);
317
331
  addStep(recorder, targetInteraction, {
318
332
  kind: "llm_call",
319
333
  phase: targetInteraction.mode,
320
- title: summarizePrompt(assistantText, `Assistant response ${targetInteraction.index}`),
334
+ title: summarizePrompt(assistantText, `Model response for Interaction ${targetInteraction.index}`),
321
335
  started_at: new Date(existing.firstSeenAt).toISOString(),
322
336
  ended_at: new Date(now).toISOString(),
323
337
  duration_ms: Math.max(0, now - existing.firstSeenAt),
@@ -337,7 +351,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
337
351
  });
338
352
  addContextContributor(recorder, {
339
353
  category: "assistant_history",
340
- label: `Assistant response ${targetInteraction.index}`,
354
+ label: `Previous assistant response from Interaction ${targetInteraction.index}`,
341
355
  source: "opencode.message",
342
356
  text: assistantText,
343
357
  });
@@ -363,6 +377,8 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
363
377
  const recorder = ensureSession(sessionID, Date.now());
364
378
  const messageID = toolMessageID(input);
365
379
  const interactionID = configuredValue(recorder.messageInteractions.get(messageID), configuredValue(recorder.currentInteractionID, ""));
380
+ const interaction = interactionID ? findInteraction(recorder, interactionID) : null;
381
+ applyInteractionMode(interaction, inferInteractionMode(input));
366
382
  recorder.toolStarts.set(callID, {
367
383
  startedAt: Date.now(),
368
384
  tool: configuredValue(input && input.tool, "unknown"),
@@ -383,7 +399,9 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
383
399
  : { startedAt: Date.now(), tool: configuredValue(input && input.tool, "unknown") };
384
400
  const messageID = toolMessageID(input) || toolMessageID(output);
385
401
  const mappedInteractionID = configuredValue(toolState.interactionID, configuredValue(recorder.messageInteractions.get(messageID), ""));
386
- const interaction = mappedInteractionID ? findInteraction(recorder, mappedInteractionID) || ensureInteraction(recorder, Date.now()) : ensureInteraction(recorder, Date.now());
402
+ const mode = inferInteractionMode(input, output);
403
+ const interaction = mappedInteractionID ? findInteraction(recorder, mappedInteractionID) || ensureInteraction(recorder, Date.now(), "", mode) : ensureInteraction(recorder, Date.now(), "", mode);
404
+ applyInteractionMode(interaction, mode);
387
405
  addStep(recorder, interaction, {
388
406
  kind: "tool_call",
389
407
  phase: interaction.mode,
@@ -580,7 +598,20 @@ function estimateTokens(text) {
580
598
  }
581
599
 
582
600
  function detailCategoryLabel(category) {
583
- return String(category || "unknown").split("_").map((part) => part ? part[0].toUpperCase() + part.slice(1) : part).join(" ");
601
+ const labels = {
602
+ assistant_history: "Previous assistant messages",
603
+ file_context: "File/context snippets",
604
+ instructions: "Instructions",
605
+ system_event: "System event",
606
+ system_prompt: "System prompt",
607
+ tool_call: "Tool call",
608
+ tool_output: "Tool outputs",
609
+ user_prompt: "User prompts",
610
+ llm_call: "Model call",
611
+ file_edit: "File edit",
612
+ };
613
+ const normalized = String(category || "unknown");
614
+ return labels[normalized] || normalized.split("_").map((part) => part ? part[0].toUpperCase() + part.slice(1) : part).join(" ");
584
615
  }
585
616
 
586
617
  function safeDetailLabel(value, fallback) {
@@ -987,6 +1018,41 @@ function summarizePrompt(prompt, fallback) {
987
1018
  return `${trimmed.slice(0, 77)}...`;
988
1019
  }
989
1020
 
1021
+ function inferInteractionMode(...values) {
1022
+ const normalized = values.map((value) => {
1023
+ if (typeof value === "string") {
1024
+ return value;
1025
+ }
1026
+ try {
1027
+ return JSON.stringify(value || {});
1028
+ } catch {
1029
+ return "";
1030
+ }
1031
+ }).join("\n").toLowerCase();
1032
+ if (
1033
+ normalized.includes("plan mode - system reminder") ||
1034
+ normalized.includes("plan mode active") ||
1035
+ normalized.includes('"mode":"plan"') ||
1036
+ normalized.includes('"modeid":"plan"') ||
1037
+ normalized.includes('"mode_id":"plan"')
1038
+ ) {
1039
+ return "plan";
1040
+ }
1041
+ return "build";
1042
+ }
1043
+
1044
+ function applyInteractionMode(interaction, mode) {
1045
+ if (!interaction || mode !== "plan") {
1046
+ return;
1047
+ }
1048
+ interaction.mode = "plan";
1049
+ for (const step of interaction.steps) {
1050
+ if (step.phase === "build") {
1051
+ step.phase = "plan";
1052
+ }
1053
+ }
1054
+ }
1055
+
990
1056
  function inferResultStatus(values, fallback = "success") {
991
1057
  return values.some((value) => value === "error" || value === "failed") ? "error" : fallback;
992
1058
  }