@distlang/opencode-plugin 0.1.13 → 0.1.14

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 +69 -16
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.14",
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,11 +251,12 @@ 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
262
  label: `User prompt ${interaction.index}`,
@@ -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,7 +327,7 @@ 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,
@@ -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,
@@ -987,6 +1005,41 @@ function summarizePrompt(prompt, fallback) {
987
1005
  return `${trimmed.slice(0, 77)}...`;
988
1006
  }
989
1007
 
1008
+ function inferInteractionMode(...values) {
1009
+ const normalized = values.map((value) => {
1010
+ if (typeof value === "string") {
1011
+ return value;
1012
+ }
1013
+ try {
1014
+ return JSON.stringify(value || {});
1015
+ } catch {
1016
+ return "";
1017
+ }
1018
+ }).join("\n").toLowerCase();
1019
+ if (
1020
+ normalized.includes("plan mode - system reminder") ||
1021
+ normalized.includes("plan mode active") ||
1022
+ normalized.includes('"mode":"plan"') ||
1023
+ normalized.includes('"modeid":"plan"') ||
1024
+ normalized.includes('"mode_id":"plan"')
1025
+ ) {
1026
+ return "plan";
1027
+ }
1028
+ return "build";
1029
+ }
1030
+
1031
+ function applyInteractionMode(interaction, mode) {
1032
+ if (!interaction || mode !== "plan") {
1033
+ return;
1034
+ }
1035
+ interaction.mode = "plan";
1036
+ for (const step of interaction.steps) {
1037
+ if (step.phase === "build") {
1038
+ step.phase = "plan";
1039
+ }
1040
+ }
1041
+ }
1042
+
990
1043
  function inferResultStatus(values, fallback = "success") {
991
1044
  return values.some((value) => value === "error" || value === "failed") ? "error" : fallback;
992
1045
  }