@bojackduy/opencode-voice 0.10.1 → 0.11.1

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.
@@ -0,0 +1,561 @@
1
+ import { createV2Preview } from "./v2-preview.js";
2
+
3
+ // OpenCode v2 compatibility shim (submit-only mode).
4
+ //
5
+ // WHY this file exists: v2's TUI plugin `Context` renamed or replaced every
6
+ // v1 `TuiPluginApi` surface this plugin uses (see the drift table in the
7
+ // research goal's progress.md). Rather than forking every lib module, this
8
+ // adapter presents a v1-shaped `api` over a v2 `Context` so the SAME core
9
+ // modules run unmodified. Every mapping is capability-detected (feature
10
+ // presence, never version strings), and every surface with no v2 path
11
+ // degrades loudly (warn log + honest toast), never silently.
12
+ //
13
+ // Non-negotiable product decision (user-accepted): v2 2.0.26 has no
14
+ // plugin-reachable append-to-composer API (`tui.prompt.append` exists only
15
+ // as a server→TUI event type, not a client method). So on v2, STT
16
+ // transcribes and SUBMITS immediately via `session.prompt`. The adapted api
17
+ // passes `renderer: null` so `appendTranscription` skips the focused-input
18
+ // insert path and lands on the client shim below, which submits.
19
+
20
+ // Event renames with no same-named v2 equivalent. Values are the v2 event
21
+ // type to subscribe to instead (both verified present in the v2
22
+ // `OpenCodeEvent` union; `question.asked` has NO v2 counterpart —
23
+ // `form.created` is the closest gate signal and is best-effort, see below).
24
+ const EVENT_REMAP = {
25
+ "message.part.delta": "session.text.delta",
26
+ "question.asked": "form.created",
27
+ };
28
+
29
+ // Capability probe: v2 TUI `Context` has all three of these; v1 `api` has
30
+ // none under these paths. Never version-sniff.
31
+ export function isV2Context(ctx) {
32
+ return (
33
+ !!ctx &&
34
+ typeof ctx?.keymap?.layer === "function" &&
35
+ typeof ctx?.ui?.toast?.show === "function" &&
36
+ !!ctx?.storage
37
+ );
38
+ }
39
+
40
+ // Normalize a v2 `SessionMessageInfo` union member to the v1 message shape
41
+ // our lib modules read (`{id, role, time, summary?}` + v1-like `parts`).
42
+ // v2 uses `type: "user" | "assistant" | …` (no `role` field); assistant text
43
+ // lives in `content[]` (`{type: "text", text}`), user text in `text`.
44
+ // Without this, every v1 `msg.role === "assistant"` filter is empty on v2 —
45
+ // the root cause of "no assistant response to speak" and the dead
46
+ // conversation reply stream. v1 hosts never pass through here.
47
+ function normalizeV2Message(msg) {
48
+ if (!msg || typeof msg !== "object") return msg;
49
+ const type = msg?.type;
50
+ const role = type === "assistant" ? "assistant" : type === "user" ? "user" : type;
51
+ let parts = [];
52
+ try {
53
+ if (Array.isArray(msg.content)) {
54
+ parts = msg.content
55
+ .map((c, i) =>
56
+ c && typeof c.text === "string"
57
+ ? { id: `${msg.id}:${i}`, type: c.type === "text" ? "text" : c.type, text: c.text }
58
+ : null,
59
+ )
60
+ .filter(Boolean);
61
+ } else if (typeof msg.text === "string" && msg.text) {
62
+ parts = [{ id: `${msg.id}:0`, type: "text", text: msg.text }];
63
+ }
64
+ } catch {
65
+ parts = [];
66
+ }
67
+ return { ...msg, role, parts };
68
+ }
69
+
70
+ // Wrap a v2 event envelope `{type, data}` so v1-style handlers reading
71
+ // `event.properties` keep working. v1 handlers also read renamed fields,
72
+ // normalized per remapped type below.
73
+ function wrapHandler(type, fn) {
74
+ return (event) => {
75
+ const data = event?.data ?? event?.properties ?? {};
76
+ let properties = { ...data };
77
+ if (type === "message.part.delta") {
78
+ // v2 `session.text.delta` data: {sessionID, assistantMessageID,
79
+ // ordinal, delta}. v1 handler expects {sessionID, messageID, partID?,
80
+ // delta, field}. `ordinal` is the content-block index, so synthesize
81
+ // the part id the normalized parts carry (`${messageID}:${ordinal}`)
82
+ // for the part-type guard; a missed lookup stays fail-open downstream.
83
+ const messageID = data.assistantMessageID ?? data.messageID;
84
+ properties = {
85
+ ...properties,
86
+ messageID,
87
+ partID:
88
+ data.partID ??
89
+ (messageID !== undefined && data.ordinal !== undefined
90
+ ? `${messageID}:${data.ordinal}`
91
+ : data.partID),
92
+ field: "text",
93
+ };
94
+ }
95
+ if (type === "question.asked") {
96
+ // v2 `form.created` data: {form}. The form may not carry a sessionID;
97
+ // an absent sessionID matches the current session in our handlers
98
+ // (`forSession` treats missing as match), which is correct for the
99
+ // common single-session case. Multi-session over-triggering is
100
+ // possible and documented in the README caveat list.
101
+ properties = { ...data, ...data?.form, sessionID: data?.sessionID ?? data?.form?.sessionID };
102
+ }
103
+ try {
104
+ fn({ ...event, properties });
105
+ } catch {
106
+ // Handlers are already internally guarded; never let a mapping throw.
107
+ }
108
+ };
109
+ }
110
+
111
+ // Sync `kv` facade over v2 async `storage`. v2 `storage.store` is a
112
+ // solid-store pair; our lib modules need synchronous get/set, so the facade
113
+ // mirrors values in memory and persists fire-and-forget. Worst case (persist
114
+ // fails or storage shape differs) the in-memory values still work for the
115
+ // session — settings just don't survive restart.
116
+ function createKv(storage, warn) {
117
+ const mem = new Map();
118
+ let update = null;
119
+ try {
120
+ const pair = storage.store("opencode-voice", { initial: { values: {} } });
121
+ const store = pair?.[0];
122
+ update = typeof pair?.[1] === "function" ? pair[1] : null;
123
+ for (const [k, v] of Object.entries(store?.values ?? {})) mem.set(k, v);
124
+ } catch (err) {
125
+ warn?.(`kv seed from v2 storage failed, using memory only: ${err?.message || err}`);
126
+ }
127
+ return {
128
+ get(k, fb) {
129
+ return mem.has(k) ? mem.get(k) : fb;
130
+ },
131
+ set(k, v) {
132
+ mem.set(k, v);
133
+ if (update) {
134
+ const snapshot = Object.fromEntries(mem);
135
+ void Promise.resolve()
136
+ .then(() => update((draft) => void (draft.values = snapshot)))
137
+ .catch(() => {});
138
+ }
139
+ },
140
+ };
141
+ }
142
+
143
+ // `api.ui.dialog.replace(() => api.ui.DialogSelect(props))` over v2 promise
144
+ // `dialog.select`. Our 7 call sites all use option-level `onSelect` (no
145
+ // top-level `onSelect`), but both are honored. `dialog.clear()` inside an
146
+ // option handler is a no-op on v2 (promise dialogs close on resolve).
147
+ function createDialog(dialog, warn) {
148
+ async function runSelect(props) {
149
+ const options = (props?.options || []).map((o) => ({
150
+ title: o?.title,
151
+ value: o?.value,
152
+ description: o?.description,
153
+ footer: o?.footer,
154
+ category: o?.category,
155
+ disabled: o?.disabled,
156
+ }));
157
+ let chosen;
158
+ try {
159
+ chosen = await dialog.select({
160
+ title: props?.title,
161
+ placeholder: props?.placeholder,
162
+ options,
163
+ current: props?.current,
164
+ });
165
+ } catch (err) {
166
+ warn?.(`dialog.select failed: ${err?.message || err}`);
167
+ return;
168
+ }
169
+ if (chosen === undefined) return; // dismissed
170
+ const match = (props?.options || []).find((o) => o?.value === chosen);
171
+ try {
172
+ if (match?.onSelect) await match.onSelect();
173
+ else if (typeof props?.onSelect === "function") await props.onSelect(chosen);
174
+ } catch (err) {
175
+ warn?.(`dialog option handler failed: ${err?.message || err}`);
176
+ }
177
+ }
178
+ return {
179
+ replace(render) {
180
+ let rendered;
181
+ try {
182
+ rendered = render();
183
+ } catch (err) {
184
+ warn?.(`dialog.replace render failed: ${err?.message || err}`);
185
+ return;
186
+ }
187
+ const props = rendered?.__v2DialogSelect ? rendered.props : null;
188
+ if (!props) {
189
+ warn?.("dialog.replace called with non-DialogSelect content (no v2 path), ignored");
190
+ return;
191
+ }
192
+ void runSelect(props);
193
+ },
194
+ clear() {},
195
+ };
196
+ }
197
+
198
+ function DialogSelect(props) {
199
+ return { __v2DialogSelect: true, props: props || {} };
200
+ }
201
+
202
+ export function adaptV2Context(ctx) {
203
+ const disposers = [];
204
+ const preview = createV2Preview(ctx);
205
+ disposers.push(() => preview.clear());
206
+ const warned = new Set();
207
+ const warnMessages = [];
208
+ let disposed = false;
209
+ let submission = null;
210
+ let submissionText = null;
211
+ // Loud degradation: warn logs are collected for evidence and also sent
212
+ // through the real logger once boot creates it (wired via onWarn below).
213
+ let warnSink = null;
214
+ const warn = (message) => {
215
+ if (warned.has(message)) return;
216
+ warned.add(message);
217
+ warnMessages.push(message);
218
+ try {
219
+ warnSink?.(`v2-compat: ${message}`);
220
+ } catch {}
221
+ };
222
+
223
+ const toast = (input) => {
224
+ try {
225
+ const options = typeof input === "string" ? { message: input } : input || {};
226
+ ctx.ui.toast.show({
227
+ title: options.title,
228
+ message: options.message ?? "",
229
+ variant: options.variant,
230
+ duration: options.duration,
231
+ sessionID: options.sessionID,
232
+ });
233
+ } catch {}
234
+ };
235
+
236
+ function currentSessionID() {
237
+ try {
238
+ const route = ctx.ui.router.current();
239
+ return route?.type === "session" ? route?.sessionID : undefined;
240
+ } catch {
241
+ return undefined;
242
+ }
243
+ }
244
+
245
+ function submitTextAsPrompt(text, isCurrent = () => true) {
246
+ const captured = String(text || "");
247
+ if (submission) {
248
+ return captured === submissionText
249
+ ? submission
250
+ : Promise.reject(new Error("Voice submission already in progress"));
251
+ }
252
+ const alive = () => !disposed && isCurrent();
253
+ const check = () => {
254
+ if (!alive()) throw new Error("Voice submission cancelled");
255
+ };
256
+ const task = (async () => {
257
+ check();
258
+ if (!captured.trim()) throw new Error("No transcript to submit");
259
+ const selected = ctx.ui.model?.current();
260
+ const model = selected
261
+ ? {
262
+ id: selected.modelID,
263
+ providerID: selected.providerID,
264
+ ...(selected.variant ? { variant: selected.variant } : {}),
265
+ }
266
+ : undefined;
267
+ let sessionID = currentSessionID();
268
+ try {
269
+ if (!sessionID) {
270
+ const created = await ctx.client.session.create({
271
+ ...(ctx.location ? { location: ctx.location } : {}),
272
+ ...(model ? { model } : {}),
273
+ });
274
+ check();
275
+ sessionID = created.id;
276
+ ctx.ui.router.navigate({ type: "session", sessionID });
277
+ }
278
+ check();
279
+ // Model/agent belong to session metadata in v2, not prompt input.
280
+ await ctx.client.session.prompt({ sessionID, text: captured });
281
+ check();
282
+ } catch (err) {
283
+ if (alive()) {
284
+ // A dialog retains the full transcript for recovery; a short toast
285
+ // alone would lose long recordings on create/prompt failure.
286
+ void ctx.ui.dialog.alert({
287
+ title: "Voice transcript — not submitted",
288
+ message: captured,
289
+ });
290
+ }
291
+ throw err;
292
+ }
293
+ })();
294
+ submission = task;
295
+ submissionText = captured;
296
+ void task
297
+ .finally(() => {
298
+ if (submission === task) submission = null;
299
+ })
300
+ .catch(() => {});
301
+ return task;
302
+ }
303
+
304
+ // `Object.create` (not spread) so client methods keep their `this`.
305
+ // v2 `session.message` is a `{get}` namespace, not the v1 callable, so
306
+ // the v1 call shape `client.session.message({sessionID, messageID})` is
307
+ // shimmed onto `message.get` with the result normalized (see above).
308
+ const session = Object.create(ctx.client.session, {
309
+ message: {
310
+ value: async (input) => {
311
+ const full = await ctx.client.session.message.get({
312
+ sessionID: input?.sessionID,
313
+ messageID: input?.messageID,
314
+ });
315
+ return { data: normalizeV2Message(full) };
316
+ },
317
+ },
318
+ });
319
+ const client = Object.create(ctx.client, {
320
+ session: { value: session },
321
+ // `client.app.log` has no v2 path — silent no-op (pre-existing `?.`
322
+ // tolerance in createLogger already expects absence).
323
+ app: { value: { log: async () => {} } },
324
+ tui: {
325
+ value: {
326
+ submitOnly: true,
327
+ // Submit-only: append-for-edit is unimplementable on v2, so append
328
+ // becomes submit. Accepts both v1 call shapes ({body:{text}} and
329
+ // {text}) used by stt.js. The `submitted` marker lets the caller's
330
+ // toast report a submit instead of an edit-step append.
331
+ appendPrompt: async (input) => {
332
+ await submitTextAsPrompt(input?.body?.text ?? input?.text ?? "", input?.isCurrent);
333
+ return { data: null, submitted: true };
334
+ },
335
+ submitPrompt: async () => {},
336
+ },
337
+ },
338
+ });
339
+
340
+ const dialog = createDialog(ctx.ui.dialog, warn);
341
+
342
+ const api = {
343
+ client,
344
+ // Submit-only enforcement: with no renderer, `appendTranscription`
345
+ // skips `insertIntoFocusedInput` and lands on the client shim above,
346
+ // which submits via `session.prompt`. Streaming display is separate:
347
+ // voicePreview uses additive slots without composer editing.
348
+ renderer: null,
349
+ voicePreview: preview,
350
+ ui: { toast, dialog, DialogSelect },
351
+ event: {
352
+ on: (type, fn) => {
353
+ const remapped = EVENT_REMAP[type];
354
+ if (remapped) warn(`event "${type}" remapped to v2 "${remapped}"`);
355
+ if (type === "question.asked") {
356
+ warn(
357
+ 'event "question.asked" has no v2 equivalent; best-effort mapping to "form.created" ' +
358
+ "(may over-trigger with multiple sessions)",
359
+ );
360
+ }
361
+ try {
362
+ return ctx.data.on(remapped || type, wrapHandler(type, fn));
363
+ } catch (err) {
364
+ warn(`event subscribe "${type}" failed: ${err?.message || err}`);
365
+ return () => {};
366
+ }
367
+ },
368
+ },
369
+ lifecycle: {
370
+ onDispose: (fn) => void disposers.push(fn),
371
+ },
372
+ kv: createKv(ctx.storage, warn),
373
+ route: {
374
+ get current() {
375
+ const route = ctx.ui.router.current();
376
+ if (route?.type === "session") {
377
+ return { name: "session", params: { sessionID: route.sessionID } };
378
+ }
379
+ return { name: route?.type || "home", params: {} };
380
+ },
381
+ },
382
+ state: {
383
+ session: {
384
+ messages: (sessionID) => {
385
+ try {
386
+ return (ctx.data.session.message.list(sessionID) || []).map(normalizeV2Message);
387
+ } catch {
388
+ return [];
389
+ }
390
+ },
391
+ },
392
+ // v1 `state.part(messageID)` over live v2 embedded content. Resolve
393
+ // through the current session first, then known sessions (message ids
394
+ // are unique). Never cache text: content changes while replies stream.
395
+ part: (messageID) => {
396
+ try {
397
+ const sessionIDs = [];
398
+ const current = currentSessionID();
399
+ if (current) sessionIDs.push(current);
400
+ for (const s of ctx.data.session.list() || []) {
401
+ if (s?.id && !sessionIDs.includes(s.id)) sessionIDs.push(s.id);
402
+ }
403
+ for (const sid of sessionIDs) {
404
+ let msg;
405
+ try {
406
+ msg = ctx.data.session.message.get(sid, messageID);
407
+ } catch {
408
+ msg = undefined;
409
+ }
410
+ if (msg) {
411
+ return normalizeV2Message(msg)?.parts || [];
412
+ }
413
+ }
414
+ } catch {
415
+ // Fall through to [] below.
416
+ }
417
+ return [];
418
+ },
419
+ path: {
420
+ // v2 `location` is a LocationRef, not a directory string.
421
+ get directory() {
422
+ try {
423
+ return ctx.location?.directory || process.cwd();
424
+ } catch {
425
+ return process.cwd();
426
+ }
427
+ },
428
+ },
429
+ },
430
+ command: {
431
+ register: (getCommands) => {
432
+ let commands = [];
433
+ try {
434
+ commands = getCommands() || [];
435
+ } catch (err) {
436
+ warn(`command registration failed: ${err?.message || err}`);
437
+ return;
438
+ }
439
+ // v1 `{title, value, category, description, keybind?, slash?, onSelect}`
440
+ // → v2 `KeymapCommand {id, title, group, bind, palette, slash, run}`
441
+ // + layer `bindings`. Every command joins palette + slash so all
442
+ // stay reachable; keybinds are translated below (invalid binds are
443
+ // reported by the host parser, not here).
444
+ // v1 bind strings use a `<leader>X` token for two-key sequences; the
445
+ // v2 keymap resolves the `<leader>` token itself (leader defaults to
446
+ // ctrl+x, configurable as `keybinds.leader`), so v1 binds pass
447
+ // through UNTOUCHED — including v2-native "ctrl+r" style customs.
448
+ // (An earlier revision translated to `ctrl+x X`; that form never
449
+ // dispatches on the host and was the actual shortcut bug.)
450
+ // "none"/falsy disables: reported as bind:false so no automatic
451
+ // binding is configured, and the layer builder omits it.
452
+ const toV2Bind = (bind) => {
453
+ if (typeof bind !== "string" || bind.length === 0 || bind === "none") return false;
454
+ return bind;
455
+ };
456
+ const mapped = commands.map((c) => ({
457
+ id: c?.value,
458
+ title: c?.title,
459
+ description: c?.description,
460
+ group: c?.category,
461
+ bind: toV2Bind(c?.keybind),
462
+ palette: true,
463
+ slash: c?.slash ? { name: c.slash.name, aliases: c.slash.aliases } : undefined,
464
+ run: (...args) => c?.onSelect?.(...args),
465
+ }));
466
+ const registerLayer = () => {
467
+ try {
468
+ ctx.keymap.layer(() => ({
469
+ mode: "global",
470
+ commands: mapped.map((c) => {
471
+ const cmd = {
472
+ id: c.id,
473
+ title: c.title,
474
+ group: c.group,
475
+ palette: true,
476
+ slash: c.slash,
477
+ run: c.run,
478
+ };
479
+ if (c.description) cmd.description = c.description;
480
+ if (typeof c.bind === "string" && c.bind.length > 0) cmd.bind = c.bind;
481
+ return cmd;
482
+ }),
483
+ // Binds are displayed from command.bind but only become
484
+ // ACTIVE when listed here — verified live: without this the
485
+ // palette shows the shortcut yet the keystroke does nothing.
486
+ // Only ids with a real bind string join (binding a bind-less
487
+ // id is contradictory).
488
+ bindings: mapped
489
+ .filter((c) => typeof c.bind === "string" && c.bind.length > 0)
490
+ .map((c) => c.id),
491
+ }));
492
+ } catch (err) {
493
+ warn(`keymap.layer rejected commands: ${err?.message || err}`);
494
+ }
495
+ };
496
+ // layer() must run inside a component: the host resolves the layer
497
+ // against the ambient Keymap provider, and a direct call in setup()
498
+ // never registers (the failure surfaces only as missing commands,
499
+ // never as an error). So claim the always-mounted "app" slot with
500
+ // a null-render component as the mount point and register once
501
+ // from its render. Unclaiming on dispose removes the layer.
502
+ if (typeof ctx.ui?.slot === "function") {
503
+ let claimed = false;
504
+ try {
505
+ const unclaim = ctx.ui.slot({
506
+ append: "app",
507
+ render: () => {
508
+ if (!claimed) {
509
+ claimed = true;
510
+ registerLayer();
511
+ }
512
+ return null;
513
+ },
514
+ });
515
+ disposers.push(() => {
516
+ try {
517
+ unclaim();
518
+ } catch {}
519
+ });
520
+ return;
521
+ } catch (err) {
522
+ warn(`slot claim for keymap failed, trying direct layer: ${err?.message || err}`);
523
+ }
524
+ }
525
+ registerLayer();
526
+ },
527
+ },
528
+ };
529
+
530
+ // v1 reads `api.state.provider` as an array (`resolveVoiceProviderModel`
531
+ // does `api?.state?.provider || []` then `.find`); v2 lists per location.
532
+ // A getter keeps the array shape without touching callers.
533
+ Object.defineProperty(api.state, "provider", {
534
+ get() {
535
+ try {
536
+ return ctx.data.location.provider.list() || [];
537
+ } catch {
538
+ return [];
539
+ }
540
+ },
541
+ enumerable: true,
542
+ });
543
+
544
+ function cleanup() {
545
+ disposed = true;
546
+ for (const fn of disposers.splice(0)) {
547
+ try {
548
+ const r = fn();
549
+ if (r?.then) void r.catch(() => {});
550
+ } catch {}
551
+ }
552
+ }
553
+
554
+ return {
555
+ api,
556
+ cleanup,
557
+ submitOnly: true,
558
+ warnMessages,
559
+ onWarn: (sink) => void (warnSink = sink),
560
+ };
561
+ }
@@ -0,0 +1,74 @@
1
+ // Host-owned Solid/OpenTUI modules are loaded only when a v2 recording starts.
2
+ // No composer mutation: this bounded display is an additive, documented slot.
3
+ export function createV2Preview(
4
+ ctx,
5
+ load = async () => {
6
+ const [solid, tui] = await Promise.all([import("solid-js"), import("@opentui/solid")]);
7
+ return { ...solid, ...tui };
8
+ },
9
+ ) {
10
+ let generation = 0;
11
+ let active = false;
12
+ let partial = { stableText: "", tentativeText: "" };
13
+ const nodes = new Set();
14
+ let setContent = null;
15
+ function display() {
16
+ const stable = partial.stableText || "";
17
+ const tentative = partial.tentativeText || "";
18
+ return `Voice live · ${stable ? `${stable} ` : ""}${tentative ? `[${tentative}]` : stable ? "" : "Listening…"}`.slice(
19
+ -1600,
20
+ );
21
+ }
22
+ let unclaims = [];
23
+ function clear() {
24
+ generation += 1;
25
+ active = false;
26
+ partial = { stableText: "", tentativeText: "" };
27
+ nodes.clear();
28
+ setContent = null;
29
+ for (const unclaim of unclaims.splice(0)) unclaim();
30
+ }
31
+ return {
32
+ async begin() {
33
+ clear();
34
+ active = true;
35
+ const mine = generation;
36
+ const { createElement, setProp, insertNode, onCleanup } = await load();
37
+ if (!active || mine !== generation) return false;
38
+ setContent = (node, value) => setProp(node, "content", value);
39
+ const render = () => {
40
+ if (!active || mine !== generation) return null;
41
+ const box = createElement("box");
42
+ setProp(box, "height", 3);
43
+ setProp(box, "flexShrink", 0);
44
+ const node = createElement("text");
45
+ setProp(node, "maxHeight", 5);
46
+ setProp(node, "minHeight", 1);
47
+ setProp(node, "width", "100%");
48
+ setProp(node, "fg", ctx.theme?.text || "#eeeeee");
49
+ setProp(node, "content", display());
50
+ nodes.add(node);
51
+ insertNode(box, node);
52
+ onCleanup?.(() => nodes.delete(node));
53
+ return box;
54
+ };
55
+ unclaims = [ctx.ui.slot({ before: "prompt.footer", render })];
56
+ return true;
57
+ },
58
+ applyPartial(p) {
59
+ if (!active) return;
60
+ partial = { stableText: p?.stableText || "", tentativeText: p?.tentativeText || "" };
61
+ for (const node of nodes) {
62
+ if (node.isDestroyed) nodes.delete(node);
63
+ else setContent?.(node, display());
64
+ }
65
+ },
66
+ getTranscript: () => [partial.stableText, partial.tentativeText].filter(Boolean).join(" "),
67
+ finalize(text) {
68
+ clear();
69
+ return { text, inserted: false };
70
+ },
71
+ cancel: clear,
72
+ clear,
73
+ };
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bojackduy/opencode-voice",
3
- "version": "0.10.1",
3
+ "version": "0.11.1",
4
4
  "description": "Speech-to-text and text-to-speech for OpenCode. Record voice prompts with whisper-cpp, hear responses via Piper TTS, with LLM normalization through any OpenAI-compatible endpoint.",
5
5
  "keywords": [
6
6
  "opencode",
@@ -20,6 +20,7 @@
20
20
  },
21
21
  "files": [
22
22
  "index.js",
23
+ "tui.js",
23
24
  "lib"
24
25
  ],
25
26
  "type": "module",
package/tui.js ADDED
@@ -0,0 +1,14 @@
1
+ // OpenCode v2 TUI entrypoint (file probe, not package exports).
2
+ //
3
+ // WHY this file exists: v2 resolves a package's TUI entrypoint by probing
4
+ // for a literal `./tui` FILE inside the package directory
5
+ // (`resolve({directory})` → `path.resolve(directory, "tui")` in
6
+ // `@opencode/plugin`'s host mirror) — package.json `exports["./tui"]` alone
7
+ // is NOT consulted for path-form packages, so without this file v2 silently
8
+ // skips the package entirely (proven: `plugin list` empty before, listed
9
+ // after). v1 keeps loading via `exports["./tui"]` → `./index.js`, unchanged.
10
+ //
11
+ // Single core: this re-exports the same default object (with both `tui` for
12
+ // v1 and `setup` for v2) — each host reads its own key off the one module
13
+ // instance. See index.js, lib/boot.js, lib/v2-compat.js.
14
+ export { default } from "./index.js";