@codexstar/pi-listen 1.0.4

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,524 @@
1
+ # pi-voice remaining implementation plan
2
+
3
+ ## Purpose
4
+
5
+ This plan covers the next stage of `pi-voice` after the onboarding overhaul already shipped in code.
6
+
7
+ The remaining product goal is to make onboarding and repair flows **cache-aware and model-aware**, so users are told when a backend/model is already available on their machine and can configure it immediately without unnecessary download or setup prompts.
8
+
9
+ This plan assumes the current repo already has:
10
+ - first-run onboarding on interactive `session_start`
11
+ - API vs Local mode selection
12
+ - scope-aware config saving
13
+ - diagnostics and recommendations
14
+ - `/voice doctor` and `/voice reconfigure`
15
+ - provisioning-plan helpers
16
+ - runtime correctness fixes
17
+ - docs and automated coverage
18
+
19
+ ## Outcome
20
+
21
+ A user installing or reconfiguring `pi-voice` should get a setup flow that can say:
22
+ - "You already have `faster-whisper` installed"
23
+ - "You already have model `small` ready to use"
24
+ - "This model would require download"
25
+ - "We can configure the existing model now"
26
+ - "We recommend this already-installed path over a fresh download"
27
+
28
+ The final UX should reduce unnecessary installation friction and make setup feel smarter and more premium.
29
+
30
+ ---
31
+
32
+ ## Current gaps
33
+
34
+ ### Diagnostics gaps
35
+ - `extensions/voice/diagnostics.ts` currently detects **backend availability**, but not **per-model availability**.
36
+ - The diagnostics contract only exposes `available`, `type`, `default_model`, and `models`.
37
+ - There is no distinction between:
38
+ - backend package installed but model not cached
39
+ - backend package installed and a specific model already present
40
+ - backend package installed but model presence unknown
41
+
42
+ ### Onboarding gaps
43
+ - `extensions/voice/onboarding.ts` can recommend a backend/model, but it cannot tell the user whether that model is already present.
44
+ - Backend choices show only `available` / install-hint style suffixes, not model-ready states.
45
+ - Model selection treats all models the same regardless of whether they are already downloaded.
46
+
47
+ ### Provisioning gaps
48
+ - `extensions/voice/install.ts` can build install/manual steps for missing dependencies, but it cannot short-circuit when a selected model is already present.
49
+ - `/voice doctor` can distinguish repair-vs-recommendation flows, but not model-ready-vs-download-required states.
50
+
51
+ ### Docs/QA gaps
52
+ - Current docs describe backend-level setup well enough, but not installed-model detection behavior.
53
+ - QA docs capture onboarding flows and repair states, but not model-aware recommendations and no-redownload paths.
54
+
55
+ ---
56
+
57
+ ## Scope of this plan
58
+
59
+ This plan covers:
60
+ 1. installed-model detection
61
+ 2. cache-aware recommendations
62
+ 3. onboarding UX for already-installed models
63
+ 4. provisioning short-circuiting
64
+ 5. doctor/test/info updates
65
+ 6. docs updates
66
+ 7. QA and release validation
67
+
68
+ This plan does **not** require redesigning the entire onboarding architecture again.
69
+
70
+ ---
71
+
72
+ ## Guiding principles
73
+
74
+ 1. **Backend-aware and model-aware are different.** The product must surface both.
75
+ 2. **Prefer ready-now flows.** If a good local model already exists, recommend using it.
76
+ 3. **Do not overclaim certainty.** Model detection should support `installed`, `not_installed`, and `unknown` states.
77
+ 4. **Stay machine-readable first.** Expose detection in `transcribe.py` first, then consume it in TypeScript.
78
+ 5. **Preserve current correctness guarantees.** No model-awareness feature should regress config/daemon behavior.
79
+
80
+ ---
81
+
82
+ ## Proposed milestones
83
+
84
+ ## Milestone A — model detection contract
85
+
86
+ ### Objective
87
+ Extend backend discovery so the system can report model-level readiness, not just backend-level readiness.
88
+
89
+ ### Deliverables
90
+ - machine-readable model presence detection in `transcribe.py`
91
+ - a stable JSON contract consumed by TypeScript diagnostics
92
+ - confidence-aware detection rules per backend
93
+
94
+ ### File changes
95
+
96
+ #### `transcribe.py`
97
+ Add support for richer backend metadata in `--list-backends` output, for example:
98
+
99
+ ```json
100
+ {
101
+ "name": "faster-whisper",
102
+ "available": true,
103
+ "type": "local",
104
+ "default_model": "small",
105
+ "models": [
106
+ {
107
+ "id": "small",
108
+ "status": "installed",
109
+ "source": "huggingface-cache",
110
+ "path": "~/.cache/..."
111
+ },
112
+ {
113
+ "id": "medium",
114
+ "status": "unknown"
115
+ }
116
+ ]
117
+ }
118
+ ```
119
+
120
+ If fully nested model objects are too disruptive, use an additive field such as:
121
+ - `model_statuses`
122
+ - `installed_models`
123
+ - `model_presence`
124
+
125
+ Recommended shape:
126
+
127
+ ```json
128
+ {
129
+ "models": ["small", "medium", "large-v3-turbo"],
130
+ "model_presence": {
131
+ "small": { "status": "installed", "source": "cache", "path": "/..." },
132
+ "medium": { "status": "not_installed" },
133
+ "large-v3-turbo": { "status": "unknown" }
134
+ }
135
+ }
136
+ ```
137
+
138
+ ### Detection strategy by backend
139
+
140
+ #### faster-whisper
141
+ Detect using best-effort heuristics such as:
142
+ - Hugging Face cache directories under `~/.cache/huggingface/`, `~/Library/Caches/huggingface/`, or environment-driven locations if practical
143
+ - any CTranslate2/converter output cache locations if they are predictably discoverable
144
+
145
+ Confidence note:
146
+ - `installed` should only be returned when a concrete model directory/file can be found with confidence
147
+ - otherwise prefer `unknown` over a false `not_installed`
148
+
149
+ #### whisper-cpp
150
+ Detect by checking common model file locations already partially used by the runtime:
151
+ - `~/.cache/whisper-cpp/ggml-<model>.bin`
152
+ - `/opt/homebrew/share/whisper-cpp/models/ggml-<model>.bin`
153
+ - `/usr/local/share/whisper-cpp/models/ggml-<model>.bin`
154
+
155
+ This backend has the most reliable model-file detection path.
156
+
157
+ #### moonshine
158
+ If a predictable cache path cannot be verified safely, use:
159
+ - backend installed = true/false
160
+ - model presence = `unknown`
161
+
162
+ #### parakeet
163
+ If NeMo/Hugging Face cache layout is not easy to detect safely, use:
164
+ - backend installed = true/false
165
+ - model presence = `unknown`
166
+
167
+ #### deepgram
168
+ No local model download applies.
169
+ Use:
170
+ - `status = api`
171
+ - or omit model presence and treat cloud models separately in TypeScript
172
+
173
+ ### Acceptance criteria
174
+ - `python3 transcribe.py --list-backends` returns model-level metadata
175
+ - model presence detection does not crash when caches are absent
176
+ - unknown states are used conservatively when certainty is low
177
+
178
+ ### Verification
179
+ - `python3 transcribe.py --list-backends`
180
+ - `python3 -m py_compile transcribe.py daemon.py`
181
+ - add targeted Python smoke tests if practical
182
+
183
+ ---
184
+
185
+ ## Milestone B — TypeScript diagnostics upgrade
186
+
187
+ ### Objective
188
+ Consume the richer model detection contract and expose it to onboarding, doctor, and provisioning flows.
189
+
190
+ ### Deliverables
191
+ - new TypeScript types for model presence
192
+ - richer `EnvironmentDiagnostics`
193
+ - helper functions for querying installed/preferred models
194
+
195
+ ### File changes
196
+
197
+ #### `extensions/voice/diagnostics.ts`
198
+ Extend the contract:
199
+ - `BackendAvailability` should support model-level presence metadata
200
+ - `EnvironmentDiagnostics` should surface a normalized structure usable by UI and provisioning logic
201
+
202
+ Suggested TypeScript additions:
203
+
204
+ ```ts
205
+ export type ModelPresenceStatus = "installed" | "not_installed" | "unknown" | "api";
206
+
207
+ export interface ModelPresence {
208
+ status: ModelPresenceStatus;
209
+ source?: string;
210
+ path?: string;
211
+ }
212
+
213
+ export interface BackendAvailability {
214
+ ...
215
+ modelPresence?: Record<string, ModelPresence>;
216
+ }
217
+ ```
218
+
219
+ Add helpers such as:
220
+ - `getInstalledModels(backend)`
221
+ - `isModelInstalled(backend, model)`
222
+ - `getPreferredInstalledModel(backends, preference)`
223
+ - `hasReadyLocalPath(diagnostics)`
224
+
225
+ ### Recommendation logic changes
226
+ Update `recommendVoiceSetup()` so it can prefer:
227
+ 1. already-installed good local models
228
+ 2. already-configured API mode
229
+ 3. backend-only installed local paths
230
+ 4. install-required local paths
231
+
232
+ Expected behavior examples:
233
+ - if `faster-whisper small` is installed, recommend that over a download-required `medium`
234
+ - if no local models are installed but Deepgram is configured and user chose speed, recommend API
235
+ - if local backend is present but model presence is unknown, explain uncertainty honestly
236
+
237
+ ### Acceptance criteria
238
+ - recommendations change when installed-model info changes
239
+ - recommendation reasons mention ready-now states where appropriate
240
+ - tests cover installed / not-installed / unknown cases
241
+
242
+ ### Verification
243
+ - new Bun tests for recommendation ranking
244
+ - `bun run test`
245
+ - `bun run typecheck`
246
+
247
+ ---
248
+
249
+ ## Milestone C — onboarding UX for already-installed models
250
+
251
+ ### Objective
252
+ Make the onboarding flow visibly smarter when models are already present.
253
+
254
+ ### Deliverables
255
+ - backend list messaging that reflects installed-model readiness
256
+ - model picker with installed/download-required labels
257
+ - summary screen that says when a model is ready immediately
258
+
259
+ ### File changes
260
+
261
+ #### `extensions/voice/onboarding.ts`
262
+ Enhance:
263
+ - `buildSelectableBackends()`
264
+ - `chooseBackendAndModel()`
265
+ - summary generation
266
+
267
+ ### UX changes
268
+
269
+ #### Backend selection
270
+ Display labels like:
271
+ - `faster-whisper — backend installed, 2 models ready`
272
+ - `whisper-cpp — model file found`
273
+ - `moonshine — installed, model status unknown`
274
+ - `deepgram — API available`
275
+
276
+ #### Model selection
277
+ Display labels like:
278
+ - `small (already installed, recommended)`
279
+ - `medium (download required)`
280
+ - `large-v3-turbo (status unknown)`
281
+
282
+ #### Summary screen
283
+ Include language such as:
284
+ - `Model status: already installed`
285
+ - `Setup path: ready to configure now`
286
+ - `Download required: no`
287
+
288
+ or
289
+ - `Model status: not installed`
290
+ - `Setup path: dependency/model download required`
291
+
292
+ ### Product behavior
293
+ If a model is already installed:
294
+ - the onboarding flow should still ask for user selection
295
+ - but it should explicitly say: `We found this on your machine`
296
+ - and it should prefer that model in recommendations where reasonable
297
+
298
+ ### Acceptance criteria
299
+ - onboarding distinguishes installed vs missing models
300
+ - user sees explicit no-redownload paths
301
+ - selection flow remains keyboard-friendly and simple
302
+
303
+ ### Verification
304
+ - new Bun tests for option labeling helpers
305
+ - manual QA in RPC mode for UI branch coverage
306
+
307
+ ---
308
+
309
+ ## Milestone D — provisioning short-circuiting
310
+
311
+ ### Objective
312
+ Avoid showing install/download steps when the selected model is already ready.
313
+
314
+ ### Deliverables
315
+ - `buildProvisioningPlan()` becomes model-aware
316
+ - selected installed models produce zero unnecessary install commands
317
+ - repair flows remain correct for missing prerequisites
318
+
319
+ ### File changes
320
+
321
+ #### `extensions/voice/install.ts`
322
+ Enhance provisioning logic to account for:
323
+ - backend installed?
324
+ - model installed?
325
+ - SoX missing?
326
+ - API key missing?
327
+
328
+ Expected behavior:
329
+ - local backend installed + model installed + SoX present => `ready: true`
330
+ - local backend installed + model missing => install/download guidance only for model/backend path
331
+ - API mode + key present + no local SoX requirement for transcription itself, but keep recording prereq guidance if recording is part of UX
332
+
333
+ ### Acceptance criteria
334
+ - no redundant install commands when model is already present
335
+ - provisioning summary reflects current machine state accurately
336
+
337
+ ### Verification
338
+ - new Bun tests for installed-model provisioning cases
339
+ - `bun run test`
340
+
341
+ ---
342
+
343
+ ## Milestone E — doctor/test/info upgrades
344
+
345
+ ### Objective
346
+ Make runtime introspection and repair UX model-aware.
347
+
348
+ ### Deliverables
349
+ - `/voice doctor` reports current backend + model readiness
350
+ - `/voice test` reports current config and whether selected model appears ready
351
+ - `/voice info` reports model-aware state cleanly
352
+
353
+ ### File changes
354
+
355
+ #### `extensions/voice.ts`
356
+ Update command output to include:
357
+ - selected model presence (`installed` / `not installed` / `unknown`)
358
+ - whether current setup is ready-now or repair-needed
359
+ - whether recommendation is using an already-installed model
360
+
361
+ ### Example doctor output
362
+
363
+ ```text
364
+ Current config: local/faster-whisper/small
365
+ Current model status: installed
366
+ Repair current setup:
367
+ - none
368
+
369
+ Recommended alternative: local/faster-whisper/small
370
+ Why: already installed and ready now
371
+ ```
372
+
373
+ ### Acceptance criteria
374
+ - doctor/test/info no longer operate at backend-only granularity
375
+ - current-config repair and recommendation remain clearly separated
376
+
377
+ ### Verification
378
+ - manual/RPC-assisted QA for command output
379
+ - update QA docs with expected text fragments
380
+
381
+ ---
382
+
383
+ ## Milestone F — docs and release polish
384
+
385
+ ### Objective
386
+ Document the smarter onboarding behavior clearly.
387
+
388
+ ### Deliverables
389
+ - README updated with installed-model-aware behavior
390
+ - backend guide updated with model detection caveats
391
+ - troubleshooting updated with model-ready vs model-missing guidance
392
+ - QA docs updated with installed-model scenarios
393
+
394
+ ### File changes
395
+ - `README.md`
396
+ - `docs/backends.md`
397
+ - `docs/troubleshooting.md`
398
+ - `docs/qa-matrix.md`
399
+ - `docs/qa-results.md`
400
+
401
+ ### Doc requirements
402
+ Explain clearly:
403
+ - backend installed does not always mean every model is ready
404
+ - some backends can reliably detect model presence; others may report `unknown`
405
+ - onboarding may say `already installed`, `download required`, or `status unknown`
406
+
407
+ ### Acceptance criteria
408
+ - docs match real behavior
409
+ - no overpromising on weak-confidence detection backends
410
+
411
+ ---
412
+
413
+ ## Milestone G — QA and release signoff
414
+
415
+ ### Objective
416
+ Ship the model-aware onboarding safely.
417
+
418
+ ### Deliverables
419
+ - automated coverage for model-aware logic
420
+ - manual/RPC-assisted evidence for the major paths
421
+ - release signoff checklist
422
+
423
+ ### Automated test targets
424
+ Add or expand tests for:
425
+ - diagnostics parsing of model presence
426
+ - recommendation preferring installed models
427
+ - onboarding labeling for installed/download-required models
428
+ - provisioning short-circuit behavior
429
+ - current-config repair vs recommendation output with model-aware state
430
+
431
+ ### Manual / RPC-assisted QA targets
432
+ 1. fresh install, no config -> startup prompt appears
433
+ 2. partial legacy config -> onboarding still appears
434
+ 3. remind-me-later -> suppress startup prompt within defer window
435
+ 4. `/voice reconfigure` -> launches setup flow
436
+ 5. project scope save -> writes `.pi/settings.json`
437
+ 6. local path with installed model -> summary reports ready-now path
438
+ 7. local path with missing model -> summary reports download-required path
439
+ 8. doctor output -> separates current repair from recommendation and includes model state
440
+
441
+ ### Verification commands
442
+ - `bun run check`
443
+ - `python3 transcribe.py --list-backends`
444
+ - manual/RPC-assisted smoke scripts as needed
445
+
446
+ ---
447
+
448
+ ## Recommended implementation order
449
+
450
+ ### Step 1 — detection contract
451
+ Do first because everything else depends on it.
452
+ - update `transcribe.py`
453
+ - add detection heuristics conservatively
454
+ - validate JSON shape
455
+
456
+ ### Step 2 — TypeScript diagnostics
457
+ - parse the new contract
458
+ - add model presence helpers
459
+ - update recommendation logic
460
+
461
+ ### Step 3 — provisioning logic
462
+ - make `buildProvisioningPlan()` model-aware
463
+ - add tests
464
+
465
+ ### Step 4 — onboarding UI
466
+ - upgrade backend/model labels
467
+ - surface ready-now paths
468
+ - add summary enhancements
469
+
470
+ ### Step 5 — doctor/test/info
471
+ - reflect model-aware readiness in runtime UX
472
+
473
+ ### Step 6 — docs + QA
474
+ - update docs
475
+ - run verification
476
+ - capture QA evidence
477
+
478
+ ---
479
+
480
+ ## Risks and mitigations
481
+
482
+ ### Risk: model cache detection is unreliable for some backends
483
+ **Mitigation:** support `unknown` state and document it. Never fake certainty.
484
+
485
+ ### Risk: faster-whisper cache layout varies by environment
486
+ **Mitigation:** mark `installed` only when concrete evidence exists. Otherwise return `unknown`, not `not_installed`.
487
+
488
+ ### Risk: onboarding becomes too verbose
489
+ **Mitigation:** keep labels compact and push detail into summary/doctor output.
490
+
491
+ ### Risk: install logic gets too coupled to backend heuristics
492
+ **Mitigation:** keep detection, provisioning, and UI mapping in separate modules.
493
+
494
+ ### Risk: deepgram/API path gets conflated with local model semantics
495
+ **Mitigation:** represent API models distinctly (`api` status or equivalent), not as local installed/not-installed.
496
+
497
+ ---
498
+
499
+ ## Time estimate
500
+
501
+ From the current repository state, this remaining work should take roughly:
502
+ - **16–24 hours** for a solid implementation
503
+ - **20–32 hours** for a fully polished, release-ready version
504
+
505
+ ### Breakdown
506
+ - model detection contract: 4–8h
507
+ - diagnostics + recommendation updates: 3–6h
508
+ - onboarding UX updates: 4–8h
509
+ - provisioning/doctor/test/info updates: 3–6h
510
+ - docs + QA: 3–6h
511
+
512
+ Practical working estimate: **2–4 focused days**.
513
+
514
+ ---
515
+
516
+ ## Definition of done
517
+
518
+ This remaining work is done when:
519
+ - onboarding can explicitly say when a chosen local model is already available
520
+ - recommendations prefer already-installed models when appropriate
521
+ - provisioning skips unnecessary install steps for already-ready paths
522
+ - doctor/test/info reflect model-aware readiness
523
+ - docs explain the behavior accurately
524
+ - verification passes and QA evidence is captured