opencode-vcc-compaction 0.2.0 → 0.3.0

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 (5) hide show
  1. package/README.md +33 -9
  2. package/events.mjs +55 -0
  3. package/index.ts +185 -87
  4. package/package.json +12 -2
  5. package/tui.tsx +44 -0
package/README.md CHANGED
@@ -241,7 +241,8 @@ pointers against the per-session snapshot.
241
241
 
242
242
  ## Commands
243
243
 
244
- Server-only slash commands (no `./tui`): `/vcc-recall`, `/vcc-search`,
244
+ Server slash commands (plus the `./tui` companion below):
245
+ `/vcc-recall`, `/vcc-search`,
245
246
  `/vcc-status`. Command invocations cannot read history directly, so the
246
247
  `context` hook (with `compaction` as backup) persists a cleaned snapshot
247
248
  of the session's messages to `ctx.storage` (`vcc-snapshot/<sessionID>`,
@@ -259,10 +260,29 @@ recall/search; `/vcc-status` reports its age.
259
260
  (`maxTokens`/`keepMessages`/reasoning/hide/noise counts), and snapshot
260
261
  freshness (version, message count, lastID, age).
261
262
 
262
- Results feed back through `session.prompt`, so the agent presents them.
263
+ Results travel as an RPC event the TUI companion renders: each command
264
+ emits `rpc.opencode-vcc-compaction.replied` and returns void with no
265
+ prompt call, so there is no model turn and no chatter — the TUI toasts
266
+ short replies and dialogs long ones (see `./tui` below). This requires
267
+ the companion: add the package to `cli.json` `plugins`. Without a
268
+ connected TUI the emit goes nowhere and the reply is silent — by
269
+ design (no wake), so non-interactive use stays quiet. Only when RPC
270
+ itself is unavailable (or an emit fails) do replies fall back to
271
+ `session.prompt`, where the agent presents them.
263
272
  A nothing-to-do stays silent (log line only, never an empty agent turn);
264
273
  a storage read failure replies explicitly ("snapshot read failed, try
265
- again in a moment"), never a misleading "none yet".
274
+ again in a moment"), never a misleading "none yet". Unexpected command
275
+ errors attempt a visible "command failed, try again" prompt reply before
276
+ giving up to the log.
277
+
278
+ ## TUI companion (`./tui` export)
279
+
280
+ `tui.tsx` listens for the reply event and renders it immediately: short
281
+ replies as toasts, long ones as large centered dialogs. No keymap
282
+ commands — none are needed, since the event carries its session. Add
283
+ the package to `cli.json` `plugins` (TUI-only surface, also works
284
+ against a remote server). The server commands stay as the transcript
285
+ record; the companion is the quiet visible channel.
266
286
 
267
287
  ## Message mapping
268
288
 
@@ -309,19 +329,23 @@ and control bytes are stripped deterministically before counting.
309
329
  ## Verify
310
330
 
311
331
  ```sh
312
- node --check vcc-plugin/index.ts
313
- node vcc-plugin/selftest.mjs
314
- node scripts/check-engine-sync.mjs
315
- node compiler/selftest.mjs
332
+ npm run typecheck # node --check index.ts + tsc -p tsconfig.tui.json
333
+ npm run test # both selftests + engine-sync
334
+ npm run lint:md # markdown lint over the tree
316
335
  ```
317
336
 
337
+ Run from the repo root (workspace scripts; toolchain installs with `npm ci`).
338
+
318
339
  Live compaction runs only with explicit approval + explicit `--model`,
319
340
  from a scratch project, never a real one.
320
341
 
321
342
  ## Status and limits
322
343
 
323
- - v0.2.0 ships the hook + three server-only slash commands
324
- (`/vcc-recall`, `/vcc-search`, `/vcc-status`; no `./tui`). `(seq N)`
344
+ - v0.3.0 (in tree, unreleased — package.json still reads 0.2.0
345
+ until `scripts/release.sh minor` runs) ships the hook + three
346
+ server slash commands
347
+ (`/vcc-recall`, `/vcc-search`, `/vcc-status`) plus the `./tui`
348
+ companion that renders their replies quietly. `(seq N)`
325
349
  pointers are 1-based ordinals over the compiled messages (skipped
326
350
  messages consume no seq); recall/search resolve them against the
327
351
  per-session snapshot.
package/events.mjs ADDED
@@ -0,0 +1,55 @@
1
+ // Event contract for the vcc TUI companion (dependency-free).
2
+ //
3
+ // The server cannot emit visible output without waking the agent, so
4
+ // /vcc-* replies travel as an RPC event the TUI toasts: the server
5
+ // emits `rpc.opencode-vcc-compaction.replied` with the reply payload
6
+ // and returns void with no prompt call (no wake, no chatter, no inbox
7
+ // row). The TUI filters `ctx.data.listen` by `replyEventType()` and
8
+ // renders it.
9
+ //
10
+ // Both `index.ts` (server, Rpc.define + emit) and `tui.tsx` (TUI,
11
+ // listen + dialog) import this module so the type string and payload
12
+ // shape have a single source of truth. No external imports so
13
+ // `selftest.mjs` runs it without node_modules.
14
+
15
+ export const VCC_RPC_ID = "opencode-vcc-compaction";
16
+
17
+ export const VCC_REPLY_EVENT = "replied";
18
+
19
+ export function replyEventType() {
20
+ return `rpc.${VCC_RPC_ID}.${VCC_REPLY_EVENT}`;
21
+ }
22
+
23
+ // The bus carries the whole reply; cap pathological payloads (a huge
24
+ // recall range) so one event cannot flood it. Truncation is explicit.
25
+ export const MAX_REPLY_TEXT = 30000;
26
+
27
+ // Payload the server emits per command reply. `command` is the slash
28
+ // name without arguments ("/vcc-status"); `text` the rendered reply.
29
+ // Non-string text is coerced so a future caller passing unvalidated
30
+ // data gets a payload (which `isReplyPayload` still accepts) instead
31
+ // of an exception on `.length`.
32
+ export function buildReplyPayload(sessionID, command, text) {
33
+ const body = typeof text === "string" ? text : String(text);
34
+ return {
35
+ sessionID,
36
+ command,
37
+ text:
38
+ body.length > MAX_REPLY_TEXT
39
+ ? `${body.slice(0, MAX_REPLY_TEXT)}\n\n[truncated: reply exceeds ${MAX_REPLY_TEXT} chars — narrow the selection and retry]`
40
+ : body,
41
+ };
42
+ }
43
+
44
+ // Short replies toast; longer ones need a large centered dialog.
45
+ export const MAX_TOAST_TEXT = 300;
46
+
47
+ export function isReplyPayload(value) {
48
+ return (
49
+ typeof value === "object" &&
50
+ value !== null &&
51
+ typeof value.sessionID === "string" &&
52
+ typeof value.command === "string" &&
53
+ typeof value.text === "string"
54
+ );
55
+ }
package/index.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { Plugin } from "@opencode/plugin/effect"
2
- import { Effect } from "effect"
1
+ import { Plugin, Rpc } from "@opencode/plugin/effect"
2
+ import type { SessionInbox } from "@opencode/schema/session-inbox"
3
+ import { Effect, Schema } from "effect"
3
4
  import { buildConfig, compileCompaction } from "./adapter.mjs"
5
+ import { VCC_REPLY_EVENT, VCC_RPC_ID, buildReplyPayload } from "./events.mjs"
4
6
  import {
5
7
  COMPILER_REV,
6
8
  SNAPSHOT_KEY_PREFIX,
@@ -31,6 +33,43 @@ import {
31
33
  //
32
34
  // Effect-direct by owner decision: written against @opencode/plugin/effect
33
35
  // from the start, so no convert-to-Effect task ever arises.
36
+ //
37
+ // Command replies travel as an RPC event the TUI companion toasts:
38
+ // the server emits `rpc.opencode-vcc-compaction.replied` and returns
39
+ // void with no prompt call (no wake, no chatter, no inbox row) — the
40
+ // goal-plugin pattern (`get` + event). Without the companion the
41
+ // event goes nowhere, and without RPC itself replies fall back to
42
+ // `session.prompt` (visible + wakes), so output is never lost.
43
+ // Payload shape shared with events.mjs (runtime single source of truth
44
+ // lives there for the dependency-free selftest; this alias only types
45
+ // the emit call site).
46
+ type ReplyPayload = { sessionID: string; command: string; text: string }
47
+
48
+ const VccRpc = Rpc.define({ id: VCC_RPC_ID,
49
+ methods: {
50
+ get: {
51
+ input: Schema.toStandardSchemaV1(Schema.Struct({ sessionID: Schema.String })),
52
+ output: Schema.toStandardSchemaV1(
53
+ Schema.NullOr(
54
+ Schema.Struct({
55
+ version: Schema.Number,
56
+ messages: Schema.Array(Schema.Unknown),
57
+ count: Schema.Number,
58
+ lastID: Schema.optional(Schema.String),
59
+ writtenAt: Schema.Number,
60
+ }),
61
+ ),
62
+ ),
63
+ },
64
+ },
65
+ events: {
66
+ [VCC_REPLY_EVENT]: {
67
+ schema: Schema.toStandardSchemaV1(
68
+ Schema.Struct({ sessionID: Schema.String, command: Schema.String, text: Schema.String }),
69
+ ),
70
+ },
71
+ },
72
+ })
34
73
 
35
74
  export default Plugin.define({
36
75
  id: "opencode-vcc-compaction",
@@ -38,6 +77,90 @@ export default Plugin.define({
38
77
  const config = buildConfig(ctx.options)
39
78
  const seen = new Map<string, { version: number; count: number; lastID: string | undefined }>()
40
79
 
80
+ const readStored = (sessionID: string, label: string) =>
81
+ Effect.catch(
82
+ ctx.storage.get(`${SNAPSHOT_KEY_PREFIX}${sessionID}`),
83
+ (error) =>
84
+ Effect.sync(() => {
85
+ console.warn(`[opencode-vcc-compaction] ${label}: snapshot read failed:`, error)
86
+ return { __vccReadFailed: true as const }
87
+ }),
88
+ )
89
+
90
+ // RPC registration must never break init: a JS try/catch around
91
+ // yield* cannot intercept Effect failures, so catch the cause
92
+ // channel explicitly and degrade to prompt replies.
93
+ const rpc = yield* Effect.catchCause(
94
+ ctx.rpc.register(VccRpc, {
95
+ get: (input) =>
96
+ Effect.flatMap(readStored(input.sessionID, "rpc.get"), (stored) => {
97
+ const classified = classifySnapshotStore(stored as never)
98
+ if (classified.status !== "ready") return Effect.succeed(null)
99
+ const candidate = classified.stored as Partial<
100
+ Record<"version" | "messages" | "count" | "lastID" | "writtenAt", unknown>
101
+ >
102
+ // The store only guarantees a non-empty messages array; project
103
+ // the five schema fields (or null) instead of trusting the
104
+ // envelope, so hand-written or older shapes fail soft.
105
+ return Effect.succeed(
106
+ typeof candidate.version === "number" &&
107
+ Array.isArray(candidate.messages) &&
108
+ typeof candidate.count === "number" &&
109
+ typeof candidate.writtenAt === "number"
110
+ ? {
111
+ version: candidate.version,
112
+ messages: candidate.messages,
113
+ count: candidate.count,
114
+ ...(typeof candidate.lastID === "string" ? { lastID: candidate.lastID } : {}),
115
+ writtenAt: candidate.writtenAt,
116
+ }
117
+ : null,
118
+ )
119
+ }),
120
+ }),
121
+ (cause) =>
122
+ Effect.flatMap(
123
+ Effect.sync(() => {
124
+ console.warn("[opencode-vcc-compaction] rpc unavailable; /vcc-* replies fall back to prompt:", cause)
125
+ }),
126
+ () => Effect.succeed(null),
127
+ ),
128
+ )
129
+ const emitReply: ((payload: ReplyPayload) => Effect.Effect<void, unknown>) | null =
130
+ rpc === null ? null : (payload) => rpc.events.emit(VCC_REPLY_EVENT, payload)
131
+
132
+ // Primary path emits the reply event for the TUI companion (silent,
133
+ // no wake). Fallbacks keep output visible: emit failure or missing
134
+ // RPC revert to session.prompt (visible + wakes, 0.2.0 behavior).
135
+ // The host passes `input.prompt` as `{ text }`; normalize a plain
136
+ // string too so a host-shape change degrades to working, not to a
137
+ // permanent usage error.
138
+ const promptText = (input: { prompt: unknown }) =>
139
+ typeof input.prompt === "string" ? input.prompt : ((input.prompt as { text?: unknown })?.text ?? "")
140
+
141
+ const reply = (input: { sessionID: string; delivery?: SessionInbox.Delivery }, command: string, text: string) =>
142
+ emitReply === null
143
+ ? ctx.session.prompt({
144
+ sessionID: input.sessionID,
145
+ text,
146
+ delivery: input.delivery,
147
+ })
148
+ : Effect.catch(
149
+ emitReply(buildReplyPayload(input.sessionID, command, text)),
150
+ (error) =>
151
+ Effect.flatMap(
152
+ Effect.sync(() => {
153
+ console.warn("[opencode-vcc-compaction] reply emit failed; falling back to prompt:", error)
154
+ }),
155
+ () =>
156
+ ctx.session.prompt({
157
+ sessionID: input.sessionID,
158
+ text,
159
+ delivery: input.delivery,
160
+ }),
161
+ ),
162
+ )
163
+
41
164
  const remember = (sessionID: unknown, messages: unknown) =>
42
165
  Effect.catch(
43
166
  Effect.flatMap(
@@ -120,32 +243,17 @@ export default Plugin.define({
120
243
  execute: (input) =>
121
244
  Effect.catchCause(
122
245
  Effect.flatMap(
123
- Effect.sync(() => parseRecallArgs((input.prompt as { text?: unknown })?.text ?? "")),
246
+ Effect.sync(() => parseRecallArgs(promptText(input))),
124
247
  (parsed) => {
125
248
  if ("error" in parsed) {
126
- return ctx.session.prompt({
127
- sessionID: input.sessionID,
128
- text: `**/vcc-recall** — ${parsed.error}`,
129
- delivery: input.delivery,
130
- })
249
+ return reply(input, "/vcc-recall", `**/vcc-recall** — ${parsed.error}`)
131
250
  }
132
251
  return Effect.flatMap(
133
- Effect.catch(
134
- ctx.storage.get(`${SNAPSHOT_KEY_PREFIX}${input.sessionID}`),
135
- (error) =>
136
- Effect.sync(() => {
137
- console.warn("[opencode-vcc-compaction] vcc-recall: snapshot read failed:", error)
138
- return { __vccReadFailed: true as const }
139
- }),
140
- ),
252
+ readStored(input.sessionID, "vcc-recall"),
141
253
  (stored) => {
142
254
  const classified = classifySnapshotStore(stored as never)
143
255
  if (classified.status === "failed") {
144
- return ctx.session.prompt({
145
- sessionID: input.sessionID,
146
- text: "**/vcc-recall** — snapshot read failed, try again in a moment",
147
- delivery: input.delivery,
148
- })
256
+ return reply(input, "/vcc-recall", "**/vcc-recall** — snapshot read failed, try again in a moment")
149
257
  }
150
258
  if (classified.status === "empty") {
151
259
  console.log("[opencode-vcc-compaction] vcc-recall: no snapshot yet for this session")
@@ -153,26 +261,30 @@ export default Plugin.define({
153
261
  }
154
262
  const resolved = resolveRecallSelections(classified.messages as never, parsed.type, parsed.id)
155
263
  if (resolved.errors.length > 0 || resolved.selections.length === 0) {
156
- return ctx.session.prompt({
157
- sessionID: input.sessionID,
158
- text: `**/vcc-recall** — ${resolved.errors.join("; ") || "nothing to recall"}`,
159
- delivery: input.delivery,
160
- })
264
+ return reply(
265
+ input,
266
+ "/vcc-recall",
267
+ `**/vcc-recall** — ${resolved.errors.join("; ") || "nothing to recall"}`,
268
+ )
161
269
  }
162
270
  const recalled = recallFromSnapshot(classified.messages as never, resolved.selections)
163
- return ctx.session.prompt({
164
- sessionID: input.sessionID,
165
- text: formatRecallReply(parsed.type, parsed.id, recalled as never),
166
- delivery: input.delivery,
167
- })
271
+ return reply(input, "/vcc-recall", formatRecallReply(parsed.type, parsed.id, recalled as never))
168
272
  },
169
273
  )
170
274
  },
171
275
  ),
172
276
  (cause) =>
173
- Effect.sync(() => {
174
- console.warn("[opencode-vcc-compaction] vcc-recall failed:", cause)
175
- }),
277
+ Effect.catchCause(
278
+ ctx.session.prompt({
279
+ sessionID: input.sessionID,
280
+ text: "**/vcc-recall** — command failed, try again in a moment",
281
+ delivery: input.delivery,
282
+ }),
283
+ () =>
284
+ Effect.sync(() => {
285
+ console.warn("[opencode-vcc-compaction] vcc-recall failed:", cause)
286
+ }),
287
+ ),
176
288
  ),
177
289
  })
178
290
  editor.add({
@@ -181,32 +293,17 @@ export default Plugin.define({
181
293
  execute: (input) =>
182
294
  Effect.catchCause(
183
295
  Effect.flatMap(
184
- Effect.sync(() => parseSearchArgs((input.prompt as { text?: unknown })?.text ?? "")),
296
+ Effect.sync(() => parseSearchArgs(promptText(input))),
185
297
  (parsed) => {
186
298
  if ("error" in parsed) {
187
- return ctx.session.prompt({
188
- sessionID: input.sessionID,
189
- text: `**/vcc-search** — ${parsed.error}`,
190
- delivery: input.delivery,
191
- })
299
+ return reply(input, "/vcc-search", `**/vcc-search** — ${parsed.error}`)
192
300
  }
193
301
  return Effect.flatMap(
194
- Effect.catch(
195
- ctx.storage.get(`${SNAPSHOT_KEY_PREFIX}${input.sessionID}`),
196
- (error) =>
197
- Effect.sync(() => {
198
- console.warn("[opencode-vcc-compaction] vcc-search: snapshot read failed:", error)
199
- return { __vccReadFailed: true as const }
200
- }),
201
- ),
302
+ readStored(input.sessionID, "vcc-search"),
202
303
  (stored) => {
203
304
  const classified = classifySnapshotStore(stored as never)
204
305
  if (classified.status === "failed") {
205
- return ctx.session.prompt({
206
- sessionID: input.sessionID,
207
- text: "**/vcc-search** — snapshot read failed, try again in a moment",
208
- delivery: input.delivery,
209
- })
306
+ return reply(input, "/vcc-search", "**/vcc-search** — snapshot read failed, try again in a moment")
210
307
  }
211
308
  if (classified.status === "empty") {
212
309
  console.log("[opencode-vcc-compaction] vcc-search: no snapshot yet for this session")
@@ -216,25 +313,29 @@ export default Plugin.define({
216
313
  try {
217
314
  found = searchSnapshot(classified.messages as never, parsed.pattern)
218
315
  } catch (error) {
219
- return ctx.session.prompt({
220
- sessionID: input.sessionID,
221
- text: `**/vcc-search** — ${error instanceof Error ? error.message : String(error)}`,
222
- delivery: input.delivery,
223
- })
316
+ return reply(
317
+ input,
318
+ "/vcc-search",
319
+ `**/vcc-search** — ${error instanceof Error ? error.message : String(error)}`,
320
+ )
224
321
  }
225
- return ctx.session.prompt({
226
- sessionID: input.sessionID,
227
- text: formatSearchReply(parsed.pattern, found as never),
228
- delivery: input.delivery,
229
- })
322
+ return reply(input, "/vcc-search", formatSearchReply(parsed.pattern, found as never))
230
323
  },
231
324
  )
232
325
  },
233
326
  ),
234
327
  (cause) =>
235
- Effect.sync(() => {
236
- console.warn("[opencode-vcc-compaction] vcc-search failed:", cause)
237
- }),
328
+ Effect.catchCause(
329
+ ctx.session.prompt({
330
+ sessionID: input.sessionID,
331
+ text: "**/vcc-search** — command failed, try again in a moment",
332
+ delivery: input.delivery,
333
+ }),
334
+ () =>
335
+ Effect.sync(() => {
336
+ console.warn("[opencode-vcc-compaction] vcc-search failed:", cause)
337
+ }),
338
+ ),
238
339
  ),
239
340
  })
240
341
  editor.add({
@@ -243,39 +344,36 @@ export default Plugin.define({
243
344
  execute: (input) =>
244
345
  Effect.catchCause(
245
346
  Effect.flatMap(
246
- Effect.catch(
247
- ctx.storage.get(`${SNAPSHOT_KEY_PREFIX}${input.sessionID}`),
248
- (error) =>
249
- Effect.sync(() => {
250
- console.warn("[opencode-vcc-compaction] vcc-status: snapshot read failed:", error)
251
- return { __vccReadFailed: true as const }
252
- }),
253
- ),
347
+ readStored(input.sessionID, "vcc-status"),
254
348
  (stored) => {
255
349
  const classified = classifySnapshotStore(stored as never)
256
350
  if (classified.status === "failed") {
257
- return ctx.session.prompt({
258
- sessionID: input.sessionID,
259
- text: "**/vcc-status** — snapshot read failed, try again in a moment",
260
- delivery: input.delivery,
261
- })
351
+ return reply(input, "/vcc-status", "**/vcc-status** — snapshot read failed, try again in a moment")
262
352
  }
263
- return ctx.session.prompt({
264
- sessionID: input.sessionID,
265
- text: formatStatusText(
353
+ return reply(
354
+ input,
355
+ "/vcc-status",
356
+ formatStatusText(
266
357
  classified.status === "ready" ? classified.stored as never : undefined,
267
358
  config as never,
268
359
  COMPILER_REV as string,
269
360
  Date.now(),
270
361
  ),
271
- delivery: input.delivery,
272
- })
362
+ )
273
363
  },
274
364
  ),
275
365
  (cause) =>
276
- Effect.sync(() => {
277
- console.warn("[opencode-vcc-compaction] vcc-status failed:", cause)
278
- }),
366
+ Effect.catchCause(
367
+ ctx.session.prompt({
368
+ sessionID: input.sessionID,
369
+ text: "**/vcc-status** — command failed, try again in a moment",
370
+ delivery: input.delivery,
371
+ }),
372
+ () =>
373
+ Effect.sync(() => {
374
+ console.warn("[opencode-vcc-compaction] vcc-status failed:", cause)
375
+ }),
376
+ ),
279
377
  ),
280
378
  })
281
379
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-vcc-compaction",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Deterministic LLM-free compaction summaries for OpenCode V2 (VCC reference engine, Effect-direct hook).",
5
5
  "license": "MIT",
6
6
  "author": "jwitmann <jerome_witmann@witmanco.net>",
@@ -24,12 +24,22 @@
24
24
  ],
25
25
  "type": "module",
26
26
  "main": "./index.ts",
27
- "files": ["index.ts", "adapter.mjs", "snapshot.mjs", "engine/", "README.md"],
27
+ "exports": {
28
+ ".": "./index.ts",
29
+ "./tui": "./tui.tsx",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": ["index.ts", "adapter.mjs", "snapshot.mjs", "events.mjs", "tui.tsx", "engine/", "README.md"],
28
33
  "engines": {
29
34
  "node": ">=18"
30
35
  },
31
36
  "peerDependencies": {
32
37
  "@opencode/plugin": "^2.0.0",
33
38
  "effect": "^4.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@opentui/solid": "^0.5.17",
42
+ "solid-js": "^1.9.12",
43
+ "typescript": "^5.9.2"
34
44
  }
35
45
  }
package/tui.tsx ADDED
@@ -0,0 +1,44 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ import { Plugin } from "@opencode/plugin/tui"
4
+ import { isReplyPayload, MAX_TOAST_TEXT, replyEventType } from "./events.mjs"
5
+
6
+ // opencode-vcc-compaction TUI companion: quiet visible output for the
7
+ // server /vcc-* commands. The server emits
8
+ // `rpc.opencode-vcc-compaction.replied` and returns void (no wake, no
9
+ // chatter); this listener toasts/dialogs the reply. No keymap commands:
10
+ // slash lookup has no session context, and none is needed — the event
11
+ // carries its session. (ODF tui.tsx pattern: dialog.alert large +
12
+ // centered for long content.)
13
+
14
+ const replyType = replyEventType()
15
+
16
+ export default Plugin.define({
17
+ id: "opencode-vcc-compaction",
18
+ setup(ctx) {
19
+ ctx.data.listen((event) => {
20
+ try {
21
+ const details = (event as { details?: unknown }).details as
22
+ | { type?: unknown; data?: unknown }
23
+ | undefined
24
+ if (details?.type !== replyType) return
25
+ const payload = (details as { data?: unknown }).data
26
+ // Runtime shape already validated; the guard lives in untyped
27
+ // .mjs (no node_modules for real types), so narrow by cast.
28
+ if (!isReplyPayload(payload)) return
29
+ const reply = payload as { sessionID: string; command: string; text: string }
30
+ const title = `vcc ${reply.command}`
31
+ if (reply.text.length < MAX_TOAST_TEXT) {
32
+ void ctx.ui.toast.show({ title, message: reply.text, variant: "info" })
33
+ return
34
+ }
35
+ // ODF dialog pattern: alert, then presentation, then drop the handle.
36
+ const shown = ctx.ui.dialog.alert({ title, message: reply.text })
37
+ ctx.ui.dialog.set({ size: "large", centered: true })
38
+ void shown
39
+ } catch (error) {
40
+ console.warn("[opencode-vcc-compaction] reply render failed:", error)
41
+ }
42
+ })
43
+ },
44
+ })