@kabmo-labs/kabmo 0.53.0 → 0.53.2

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 (152) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +384 -384
  3. package/dist/client/static/js/{Body-sdq2yhmp.js → Body-vaa10tcd.js} +3 -3
  4. package/dist/client/static/js/{CsvGrid-afz6vr3m.js → CsvGrid-wabx4e6w.js} +1 -1
  5. package/dist/client/static/js/{DocxView-xwjgt7qq.js → DocxView-22b3mhh5.js} +1 -1
  6. package/dist/client/static/js/{DrawioView-7m4e8zcm.js → DrawioView-e02qhkp2.js} +1 -1
  7. package/dist/client/static/js/{HtmlPreview-tad0dezn.js → HtmlPreview-q7hwcf4s.js} +1 -1
  8. package/dist/client/static/js/{ImageView-7bpm4xhb.js → ImageView-fxb60ge7.js} +1 -1
  9. package/dist/client/static/js/{LayoutWrapper-ehxhj6t3.js → LayoutWrapper-cey5agsf.js} +2 -2
  10. package/dist/client/static/js/MergeDiffView-1z9mwf73.js +1 -0
  11. package/dist/client/static/js/{Modal-5qt3v5gn.js → Modal-e4yq7p5f.js} +9 -9
  12. package/dist/client/static/js/{PdfView-hbgnnana.js → PdfView-pf3angsq.js} +1 -1
  13. package/dist/client/static/js/{SessionsView-rv9jmr2e.js → SessionsView-mcvhpx0b.js} +1 -1
  14. package/dist/client/static/js/{SheetView-55e0a8as.js → SheetView-5ha5vvsr.js} +1 -1
  15. package/dist/client/static/js/{SvgPreview-10fa6mj1.js → SvgPreview-45wqjw0b.js} +1 -1
  16. package/dist/client/static/js/{abnfDiagram-O67JEVCF-9w4p3dhe.js → abnfDiagram-O67JEVCF-gnf6krbs.js} +1 -1
  17. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-5x6sb253.js → architectureDiagram-NJMV4G6O-00fd0wsg.js} +2 -2
  18. package/dist/client/static/js/{astro-m3fcq2sa.js → astro-asmathwv.js} +1 -1
  19. package/dist/client/static/js/{blockDiagram-BEXU5L5S-2c6y4pkn.js → blockDiagram-BEXU5L5S-9c2sm96a.js} +2 -2
  20. package/dist/client/static/js/c-20y64hcp.js +1 -0
  21. package/dist/client/static/js/{c4Diagram-YGBWAQC7-45rtm401.js → c4Diagram-YGBWAQC7-pemygn0s.js} +2 -2
  22. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-rksw3aw9.js → classDiagram-v2-NBCMYWYE-h7r3sx3s.js} +2 -2
  23. package/dist/client/static/js/{cose-bilkent-JH36ORCC-4hxtttt5.js → cose-bilkent-JH36ORCC-krx9crwv.js} +1 -1
  24. package/dist/client/static/js/cpp-ty6n0dg9.js +1 -0
  25. package/dist/client/static/js/css-ncvxaxt0.js +1 -0
  26. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-5dhexpf2.js → cynefinDiagram-VND7K2PF-5rp2btew.js} +1 -1
  27. package/dist/client/static/js/{dagre-6A5THRUB-1k3w4qm9.js → dagre-6A5THRUB-q57cnz52.js} +2 -2
  28. package/dist/client/static/js/{diagram-22UHCM2B-fw76k272.js → diagram-22UHCM2B-0bptn06k.js} +2 -2
  29. package/dist/client/static/js/{diagram-3UASUU5V-qnb2gn31.js → diagram-3UASUU5V-60snxawz.js} +1 -1
  30. package/dist/client/static/js/{diagram-ATOU4E4O-cavnxzpf.js → diagram-ATOU4E4O-bb0kewfp.js} +2 -2
  31. package/dist/client/static/js/{diagram-CDSNMT55-6dxaj054.js → diagram-CDSNMT55-3cdkns0z.js} +2 -2
  32. package/dist/client/static/js/{diagram-MLGK6HIB-f16fv9ay.js → diagram-MLGK6HIB-03mbhzeq.js} +1 -1
  33. package/dist/client/static/js/{diagram-MPIPVDR6-zsryj72g.js → diagram-MPIPVDR6-bcvzqqf4.js} +1 -1
  34. package/dist/client/static/js/{dockerfile-frznktsa.js → dockerfile-7kqkk4tz.js} +1 -1
  35. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-1zz5h7sw.js → ebnfDiagram-ZINNZB2B-sg6kwnbx.js} +1 -1
  36. package/dist/client/static/js/{elk-276RUBZZ-25pehy1p.js → elk-276RUBZZ-5b8v0sdv.js} +1 -1
  37. package/dist/client/static/js/{erDiagram-OPXOYQCR-ezpjhgzw.js → erDiagram-OPXOYQCR-xbs156j5.js} +2 -2
  38. package/dist/client/static/js/flowDiagram-KWPJA3E3-sasgvf55.js +1 -0
  39. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-n11hq4ag.js → ganttDiagram-FUAMR5RP-4p7pfk6c.js} +1 -1
  40. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-3znkxh7y.js → gitGraphDiagram-X574FWY7-3xqwr9pf.js} +1 -1
  41. package/dist/client/static/js/{index-10cxm9ty.js → index-0btbxkxf.js} +2 -2
  42. package/dist/client/static/js/{index-5pbf6dcz.js → index-1d8ff4t7.js} +3 -3
  43. package/dist/client/static/js/{index-9n1cg95f.js → index-1regq9wd.js} +1 -1
  44. package/dist/client/static/js/{index-4nvcwtvr.js → index-25zpywv7.js} +1 -1
  45. package/dist/client/static/js/{index-qj6b15r4.js → index-26a4afcr.js} +2 -2
  46. package/dist/client/static/js/{index-scmtzcv1.js → index-396g4zz4.js} +2 -2
  47. package/dist/client/static/js/{index-m1hd7ska.js → index-3amzzsdk.js} +25 -25
  48. package/dist/client/static/js/{index-vjmy9r20.js → index-3bmn5cc5.js} +1 -1
  49. package/dist/client/static/js/{index-qrpx4sk1.js → index-3x88t8g9.js} +2 -2
  50. package/dist/client/static/js/{index-e0h6xkpv.js → index-45vcpqp9.js} +1 -1
  51. package/dist/client/static/js/{index-7ag37ghj.js → index-4kchzh9y.js} +8 -8
  52. package/dist/client/static/js/{index-5hqjscys.js → index-5qtnmn76.js} +2 -2
  53. package/dist/client/static/js/{index-wvw70pgd.js → index-668fc1df.js} +2 -2
  54. package/dist/client/static/js/{index-b039ef9w.js → index-ayx3q8t9.js} +2 -2
  55. package/dist/client/static/js/{index-dzp9rwy0.js → index-c8ta3k4g.js} +161 -161
  56. package/dist/client/static/js/{index-ey0ckd66.js → index-cj8v7b50.js} +2 -2
  57. package/dist/client/static/js/{index-dkz8d77n.js → index-cy6ceab8.js} +1 -1
  58. package/dist/client/static/js/index-cysdvwqw.js +1 -0
  59. package/dist/client/static/js/{index-y79ebmam.js → index-e2esj214.js} +1 -1
  60. package/dist/client/static/js/{index-32gh2645.js → index-gzz6snng.js} +1 -1
  61. package/dist/client/static/js/{index-kyarw08m.js → index-hp3s5r3g.js} +2 -2
  62. package/dist/client/static/js/{index-5z7f6bq4.js → index-hwq7zgqd.js} +1 -1
  63. package/dist/client/static/js/{index-1qjxg7mh.js → index-j9t5xc3y.js} +1 -1
  64. package/dist/client/static/js/{index-58kgkwxt.js → index-jf8zcg99.js} +4 -4
  65. package/dist/client/static/js/{index-2k6wyyds.js → index-jg6ecfc7.js} +4 -4
  66. package/dist/client/static/js/{index-er7pj5k6.js → index-m6eh5g1q.js} +1 -1
  67. package/dist/client/static/js/{index-4faphth3.js → index-mgs5nscx.js} +1 -1
  68. package/dist/client/static/js/{index-me7ag6sy.js → index-mtjbp5ga.js} +1 -1
  69. package/dist/client/static/js/{index-dzsjyzht.js → index-ng3e6k6x.js} +2 -2
  70. package/dist/client/static/js/{index-z9msykm1.js → index-nmhwjwmt.js} +1 -1
  71. package/dist/client/static/js/{index-s78f7j47.js → index-nnhs52db.js} +1 -1
  72. package/dist/client/static/js/{index-8972fxm9.js → index-p75b7phb.js} +1 -1
  73. package/dist/client/static/js/{index-5j0wejvq.js → index-pak6t03c.js} +2 -2
  74. package/dist/client/static/js/{index-zkkttvtx.js → index-pdkt3r4r.js} +2 -2
  75. package/dist/client/static/js/{index-gmea6fjd.js → index-qj9tcz44.js} +5 -5
  76. package/dist/client/static/js/{index-ej1va073.js → index-rsyqf691.js} +2 -2
  77. package/dist/client/static/js/{index-tnhnysj1.js → index-rtpg4t84.js} +1 -1
  78. package/dist/client/static/js/{index-1e7fek0v.js → index-ryww3xxj.js} +1 -1
  79. package/dist/client/static/js/index-trrmbq0h.js +2 -0
  80. package/dist/client/static/js/{index-02skcm4d.js → index-vwxt5ss9.js} +1 -1
  81. package/dist/client/static/js/{index-acpn178r.js → index-x0y2c61e.js} +1 -1
  82. package/dist/client/static/js/{index-899yw6fh.js → index-x3g8fwkc.js} +2 -2
  83. package/dist/client/static/js/{index-j97qmbbv.js → index-xqkcx4az.js} +1 -1
  84. package/dist/client/static/js/{index-hqc2cazc.js → index-yf5a6t3p.js} +4 -4
  85. package/dist/client/static/js/{index-ht164kw9.js → index-z7gd7nvb.js} +1 -1
  86. package/dist/client/static/js/{index-1w92sjkm.js → index-zc3snsr9.js} +2 -2
  87. package/dist/client/static/js/{infoDiagram-VRGFBTTK-kmv3jtrd.js → infoDiagram-VRGFBTTK-c362sv3t.js} +1 -1
  88. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-5kp6geeh.js → ishikawaDiagram-OU5B5YK6-yc8ts8wj.js} +1 -1
  89. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-6w5f1ddc.js → journeyDiagram-ZHPQQLJL-178c75fy.js} +2 -2
  90. package/dist/client/static/js/json-xha2drny.js +1 -0
  91. package/dist/client/static/js/{julia-nwh5w343.js → julia-d18zhpyp.js} +1 -1
  92. package/dist/client/static/js/{kanban-definition-PNTS6WVX-6esn6xqn.js → kanban-definition-PNTS6WVX-w6g3n001.js} +2 -2
  93. package/dist/client/static/js/lua-njwwdj4s.js +1 -0
  94. package/dist/client/static/js/{mermaid.core-z83pf8ch.js → mermaid.core-vcdgn378.js} +7 -7
  95. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-0h1nhw66.js → mindmap-definition-NLK3R4M7-t9e8arca.js} +1 -1
  96. package/dist/client/static/js/one-dark-pro-17hh3q12.js +1 -0
  97. package/dist/client/static/js/one-light-cntgvscy.js +1 -0
  98. package/dist/client/static/js/{pegDiagram-GJSIUBJH-xdcpr8my.js → pegDiagram-GJSIUBJH-nehn0x9n.js} +1 -1
  99. package/dist/client/static/js/{perl-wb4wtc9x.js → perl-sns2qvmf.js} +1 -1
  100. package/dist/client/static/js/{php-9g594k9f.js → php-3q6v9eey.js} +1 -1
  101. package/dist/client/static/js/{pieDiagram-5QR66LMP-0210zd5b.js → pieDiagram-5QR66LMP-p1t3ctd4.js} +1 -1
  102. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-j0rtvvcm.js → quadrantDiagram-O4NWA36T-614rtbfe.js} +1 -1
  103. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-mzxat5g5.js → railroadDiagram-XR7U4H2S-2vpr6pw8.js} +1 -1
  104. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-zq5b9ts2.js → requirementDiagram-PLB6GJNP-b91s5q3p.js} +2 -2
  105. package/dist/client/static/js/{ruby-c4hxsegh.js → ruby-f9k99tfq.js} +1 -1
  106. package/dist/client/static/js/{rust-vmn352hx.js → rust-jj206pb7.js} +1 -1
  107. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-06s3r7bv.js → sankeyDiagram-IPEJSGJF-4101kt9r.js} +2 -2
  108. package/dist/client/static/js/{sass-6yxywx7t.js → sass-2syegq28.js} +1 -1
  109. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-7s4gz4t5.js → sequenceDiagram-PO4LG4MO-yq0cxg8c.js} +3 -3
  110. package/dist/client/static/js/{sizeCapture-INFHLROL-yensh9k2.js → sizeCapture-INFHLROL-jkvq39vz.js} +1 -1
  111. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-1q8p06fk.js → stateDiagram-v2-GCMORJYK-y0h7w5rw.js} +1 -1
  112. package/dist/client/static/js/{swimlanes-2SLR337P-2mfxddzf.js → swimlanes-2SLR337P-1y073wzx.js} +1 -1
  113. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-k2xf0gby.js → swimlanesDiagram-TC7HE7FX-8ahz3c68.js} +1 -1
  114. package/dist/client/static/js/{timeline-definition-EJHVYXUP-xrk07evk.js → timeline-definition-EJHVYXUP-yjb0g0ys.js} +2 -2
  115. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-ca9h5skn.js → usecaseDiagram-POWQR4AR-8xjkxrkv.js} +1 -1
  116. package/dist/client/static/js/{vennDiagram-UO4OBE2U-c0y47znt.js → vennDiagram-UO4OBE2U-18wjbwtg.js} +1 -1
  117. package/dist/client/static/js/{vue-rcdqpz7q.js → vue-e8e3q3hj.js} +1 -1
  118. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-mfk1ck3n.js → wardleyDiagram-VNRHLVJA-xqrfsrwp.js} +1 -1
  119. package/dist/client/static/js/xml-8516fzfp.js +1 -0
  120. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-6f8xt89k.js → xychartDiagram-PMCCYNJV-azygghkz.js} +2 -2
  121. package/package.json +2 -2
  122. package/src/client/components/workspace/git-panel/index.test.ts +56 -7
  123. package/src/client/components/workspace/git-panel/index.tsx +9 -4
  124. package/src/client/components/workspace/repo-picker/index.test.tsx +29 -2
  125. package/src/client/hooks/chat/timeline/new-chat-open.ts +5 -3
  126. package/src/client/hooks/chat/timeline/new-chat.test.ts +18 -2
  127. package/src/client/hooks/chat/timeline/new-chat.ts +13 -12
  128. package/src/client/hooks/chat/timeline/scope.test.ts +100 -0
  129. package/src/client/hooks/chat/timeline/scope.ts +9 -9
  130. package/src/client/hooks/workspace/commit-box.ts +6 -1
  131. package/src/client/lib/tts/gapless.ts +205 -0
  132. package/src/client/lib/tts/player.test.ts +83 -64
  133. package/src/client/lib/tts/player.ts +48 -98
  134. package/src/server/lib/fs/fs-write-git.test.ts +15 -47
  135. package/src/server/lib/fs/git-ignore.test.ts +101 -0
  136. package/src/server/lib/fs/git-ignore.ts +38 -1
  137. package/src/server/lib/fs/git-repos.ts +32 -11
  138. package/src/server/lib/fs/listing.test.ts +19 -0
  139. package/src/shared/lib/workspace/active-project.test.ts +45 -0
  140. package/src/shared/lib/workspace/active-project.ts +21 -0
  141. package/dist/client/static/js/MergeDiffView-28xkyts9.js +0 -1
  142. package/dist/client/static/js/c-ypdp030b.js +0 -1
  143. package/dist/client/static/js/cpp-cxwev3gs.js +0 -1
  144. package/dist/client/static/js/css-6mxcqf8c.js +0 -1
  145. package/dist/client/static/js/flowDiagram-KWPJA3E3-zh6hmn6g.js +0 -1
  146. package/dist/client/static/js/index-qva2vqbh.js +0 -2
  147. package/dist/client/static/js/index-xvh25zer.js +0 -1
  148. package/dist/client/static/js/json-mb8k0b1n.js +0 -1
  149. package/dist/client/static/js/lua-nxnqww9z.js +0 -1
  150. package/dist/client/static/js/one-dark-pro-wsgaqq27.js +0 -1
  151. package/dist/client/static/js/one-light-w8zdrvyc.js +0 -1
  152. package/dist/client/static/js/xml-vtrdnrn6.js +0 -1
@@ -5,67 +5,82 @@
5
5
 
6
6
  /**
7
7
  * The player's own contract: an answer is split at the engine's budget, each
8
- * chunk is fetched once, playback runs in order, and the snapshot returns to
9
- * idle at the end.
8
+ * chunk is fetched once, chunk audio is scheduled back-to-back, and the
9
+ * snapshot returns to idle at the end.
10
10
  *
11
- * Audio and fetch are fakes. What is pinned is the sequence Kabmo controls —
12
- * chunk boundaries, the `/api/tts/speak` body, and the cache — not the browser's
13
- * decoder.
11
+ * Audio is a fake AudioContext. What is pinned is the sequence Kabmo controls —
12
+ * chunk boundaries, the `/api/tts/speak` body, the cache, and the contiguous
13
+ * start times that remove the gap between chunks — not the browser's decoder.
14
14
  */
15
15
 
16
16
  import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
17
+ import { GaplessAudio } from '@/client/lib/tts/gapless';
17
18
  import { ttsPlayer, type TtsSnapshot } from '@/client/lib/tts/player';
18
19
  import { DEFAULT_TTS_CONFIG } from '@/shared/lib/tts/settings';
19
20
 
20
21
  const originalFetch = globalThis.fetch;
21
- const originalAudio = globalThis.Audio;
22
- const originalCreate = URL.createObjectURL;
23
- const originalRevoke = URL.revokeObjectURL;
22
+ const originalAudioContext = globalThis.AudioContext;
24
23
 
25
24
  let requests: Array<{ text: string; config: Record<string, unknown> }> = [];
26
25
 
27
- class FakeAudio {
26
+ class FakeSource {
28
27
  onended: (() => void) | null = null;
29
- onerror: (() => void) | null = null;
30
- src = '';
31
- play(): Promise<void> {
32
- queueMicrotask(() => this.onended?.());
33
- return Promise.resolve();
28
+ buffer: AudioBuffer | null = null;
29
+ startedAt: number | null = null;
30
+ stopped = false;
31
+
32
+ connect(): void {}
33
+ disconnect(): void {}
34
+
35
+ start(when: number): void {
36
+ this.startedAt = when;
37
+ }
38
+
39
+ stop(): void {
40
+ this.stopped = true;
34
41
  }
35
- pause(): void {}
36
- removeAttribute(name: string): void {
37
- if (name === 'src') this.src = '';
42
+
43
+ end(): void {
44
+ if (this.stopped) return;
45
+ this.stopped = true;
46
+ this.onended?.();
38
47
  }
39
- load(): void {}
40
48
  }
41
49
 
42
- /** An element whose playback only ends when the test says so. */
43
- class ManualAudio {
44
- static instances: ManualAudio[] = [];
45
- /** Fires for each element the player creates, so a test can await the next chunk. */
46
- static created: ((audio: ManualAudio) => void) | null = null;
47
- onended: (() => void) | null = null;
48
- onerror: (() => void) | null = null;
49
- src = '';
50
- playCalls = 0;
51
- pauseCalls = 0;
50
+ class FakeAudioContext {
51
+ static instances: FakeAudioContext[] = [];
52
+ static autoEnd = true;
53
+
54
+ state: AudioContextState = 'running';
55
+ currentTime = 0;
56
+ destination = {} as AudioDestinationNode;
57
+ sources: FakeSource[] = [];
58
+
52
59
  constructor() {
53
- ManualAudio.instances.push(this);
54
- ManualAudio.created?.(this);
60
+ FakeAudioContext.instances.push(this);
61
+ }
62
+
63
+ createBufferSource(): AudioBufferSourceNode {
64
+ const source = new FakeSource();
65
+ this.sources.push(source);
66
+ if (FakeAudioContext.autoEnd) queueMicrotask(() => source.end());
67
+ return source as unknown as AudioBufferSourceNode;
55
68
  }
56
- play(): Promise<void> {
57
- this.playCalls += 1;
58
- return Promise.resolve();
69
+
70
+ async decodeAudioData(_bytes: ArrayBuffer): Promise<AudioBuffer> {
71
+ return { duration: 1 } as AudioBuffer;
59
72
  }
60
- pause(): void {
61
- this.pauseCalls += 1;
73
+
74
+ async suspend(): Promise<void> {
75
+ this.state = 'suspended';
62
76
  }
63
- removeAttribute(name: string): void {
64
- if (name === 'src') this.src = '';
77
+
78
+ async resume(): Promise<void> {
79
+ this.state = 'running';
65
80
  }
66
- load(): void {}
67
- end(): void {
68
- this.onended?.();
81
+
82
+ async close(): Promise<void> {
83
+ this.state = 'closed';
69
84
  }
70
85
  }
71
86
 
@@ -82,25 +97,21 @@ function waitFor(predicate: (snapshot: TtsSnapshot) => boolean): Promise<TtsSnap
82
97
 
83
98
  beforeEach(() => {
84
99
  requests = [];
85
- ManualAudio.instances = [];
86
- ManualAudio.created = null;
100
+ FakeAudioContext.instances = [];
101
+ FakeAudioContext.autoEnd = true;
87
102
  ttsPlayer.stop();
88
103
  globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => {
89
104
  const body = JSON.parse(String(init?.body)) as { text: string; config: Record<string, unknown> };
90
105
  requests.push(body);
91
106
  return new Response(new Blob([new Uint8Array([1])]), { headers: { 'content-type': 'audio/mpeg' } });
92
107
  }) as unknown as typeof fetch;
93
- globalThis.Audio = FakeAudio as unknown as typeof Audio;
94
- URL.createObjectURL = () => 'blob:test';
95
- URL.revokeObjectURL = () => {};
108
+ globalThis.AudioContext = FakeAudioContext as unknown as typeof AudioContext;
96
109
  });
97
110
 
98
111
  afterEach(() => {
99
112
  ttsPlayer.stop();
100
113
  globalThis.fetch = originalFetch;
101
- globalThis.Audio = originalAudio;
102
- URL.createObjectURL = originalCreate;
103
- URL.revokeObjectURL = originalRevoke;
114
+ globalThis.AudioContext = originalAudioContext;
104
115
  });
105
116
 
106
117
  describe('ttsPlayer', () => {
@@ -112,6 +123,7 @@ describe('ttsPlayer', () => {
112
123
  const snapshot = await settled;
113
124
 
114
125
  expect(snapshot).toEqual({ status: 'idle', activeKey: null, error: null });
126
+ expect(FakeAudioContext.instances).toHaveLength(1);
115
127
  expect(requests.length).toBeGreaterThan(1);
116
128
  for (const request of requests) {
117
129
  expect(request.text.length).toBeLessThanOrEqual(4096);
@@ -133,32 +145,39 @@ describe('ttsPlayer', () => {
133
145
  expect(requests).toHaveLength(1);
134
146
  });
135
147
 
136
- test('pause holds the read and never starts the next chunk', async () => {
137
- globalThis.Audio = ManualAudio as unknown as typeof Audio;
138
- const nextChunk = Promise.withResolvers<ManualAudio>();
139
- ManualAudio.created = () => {
140
- if (ManualAudio.instances.length === 2) nextChunk.resolve(ManualAudio.instances[1]!);
141
- };
148
+ test('pause suspends the audio context and resume continues it', async () => {
149
+ FakeAudioContext.autoEnd = false;
142
150
  const text = Array.from({ length: 30 }, (_, index) => `Sentence number ${index + 1} is here.`).join(' ');
143
151
 
144
152
  ttsPlayer.speak(text, 'run-1', { ...DEFAULT_TTS_CONFIG, engine: 'openai' });
145
153
  await waitFor((snapshot) => snapshot.status === 'playing');
146
- const first = ManualAudio.instances[0];
147
- expect(first).toBeDefined();
154
+ const context = FakeAudioContext.instances.at(-1);
155
+ expect(context).toBeDefined();
156
+ expect(context!.sources.length).toBeGreaterThan(0);
148
157
 
149
158
  ttsPlayer.pause();
150
159
  expect(ttsPlayer.getSnapshot()).toEqual({ status: 'paused', activeKey: 'run-1', error: null });
151
- expect(first!.pauseCalls).toBe(1);
152
-
153
- // The chunk ends while paused: the next one must be loaded but silent.
154
- first!.end();
155
- const second = await nextChunk.promise;
156
- expect(ttsPlayer.getSnapshot().status).toBe('paused');
157
- expect(second.playCalls).toBe(0);
160
+ expect(context!.state).toBe('suspended');
158
161
 
159
162
  ttsPlayer.resume();
160
163
  expect(ttsPlayer.getSnapshot().status).toBe('playing');
161
- expect(second.playCalls).toBe(1);
164
+ expect(context!.state).toBe('running');
162
165
  ttsPlayer.stop();
163
166
  });
167
+
168
+ test('starts each chunk at the previous chunk end', async () => {
169
+ FakeAudioContext.autoEnd = false;
170
+ const context = new FakeAudioContext();
171
+ const audio = new GaplessAudio(() => context as unknown as AudioContext);
172
+
173
+ await audio.ensure();
174
+ await audio.schedule(new Blob([new Uint8Array([1])]));
175
+ await audio.schedule(new Blob([new Uint8Array([2])]));
176
+
177
+ expect(context.sources).toHaveLength(2);
178
+ expect(context.sources[0]!.startedAt).toBeCloseTo(0.05, 5);
179
+ expect(context.sources[1]!.startedAt).toBeCloseTo(1.05, 5);
180
+
181
+ audio.stop();
182
+ });
164
183
  });
@@ -12,17 +12,18 @@
12
12
  * snapshot so the speaker button can follow the run it started.
13
13
  *
14
14
  * An answer is read as a stream. `speechChunks` cuts it at paragraph and
15
- * sentence boundaries, two requests stay in flight, and each chunk plays as
16
- * soon as it lands — that is the difference between a 14-second silence before
17
- * a long local answer and audio starting after the first paragraph. Pause
18
- * suspends the current element and never starts the next chunk, so a paused
19
- * read costs no synthesis; resume continues from the same sample.
15
+ * sentence boundaries, two requests stay in flight, and each chunk is decoded
16
+ * into `GaplessAudio` as soon as it lands. The scheduler starts a chunk at the
17
+ * previous one's exact end, so a paragraph boundary is not an audio boundary.
18
+ * Pause suspends the shared audio context, which freezes every scheduled
19
+ * source at its current sample; resume continues from there.
20
20
  */
21
21
 
22
22
  import { readKabmoSetting } from '@/shared/lib/settings/client';
23
23
  import { ttsEngine } from '@/shared/lib/tts/engines';
24
24
  import { normalizeTtsConfig, type TtsConfig } from '@/shared/lib/tts/settings';
25
25
  import { speechChunks } from '@/shared/lib/tts/speakable';
26
+ import { GaplessAudio } from '@/client/lib/tts/gapless';
26
27
 
27
28
  export type TtsStatus = 'idle' | 'loading' | 'playing' | 'paused' | 'error';
28
29
 
@@ -67,11 +68,8 @@ class TtsPlayer {
67
68
  private snapshot: TtsSnapshot = IDLE;
68
69
  private readonly listeners = new Set<() => void>();
69
70
  private readonly cache = new Map<string, Blob>();
70
- private audio: HTMLAudioElement | null = null;
71
- private objectUrl: string | null = null;
71
+ private playback: GaplessAudio | null = null;
72
72
  private abort: AbortController | null = null;
73
- /** Ends the chunk in flight; an argument reports it as a failure. */
74
- private finishPlayback: ((message?: string) => void) | null = null;
75
73
  private paused = false;
76
74
  private run = 0;
77
75
 
@@ -98,35 +96,46 @@ class TtsPlayer {
98
96
  return;
99
97
  }
100
98
 
99
+ const playback = this.playback ??= GaplessAudio.create();
100
+ if (!playback) {
101
+ this.publish('error', key, 'This browser cannot play synthesized speech.');
102
+ return;
103
+ }
104
+
101
105
  const run = ++this.run;
102
106
  const controller = new AbortController();
103
107
  this.abort = controller;
104
108
  this.publish('loading', key, null);
105
109
 
106
- void this.playChunks(chunks, config, key, run, controller);
110
+ void this.playChunks(playback, chunks, config, key, run, controller);
107
111
  }
108
112
 
109
- /** Hold the read where it is; the next chunk is not started. */
113
+ /** Hold the read where it is; the audio context freezes every scheduled chunk. */
110
114
  pause(): void {
111
115
  const status = this.snapshot.status;
112
116
  if (this.paused || (status !== 'playing' && status !== 'loading')) return;
113
117
  this.paused = true;
114
- this.audio?.pause();
118
+ this.playback?.pause();
115
119
  this.publish('paused', this.snapshot.activeKey, null);
116
120
  }
117
121
 
118
- /** Continue a paused read from the sample it stopped on. */
122
+ /** Continue a paused read from the sample where the context froze. */
119
123
  resume(): void {
120
124
  if (!this.paused) return;
121
125
  this.paused = false;
122
- const audio = this.audio;
126
+ const playback = this.playback;
123
127
  const key = this.snapshot.activeKey;
124
- if (!audio) {
125
- this.publish('loading', key, null);
128
+ if (!playback) {
129
+ this.publish('error', key, 'This browser cannot play synthesized speech.');
126
130
  return;
127
131
  }
128
- this.publish('playing', key, null);
129
- this.startPlayback(audio, this.run);
132
+
133
+ const run = this.run;
134
+ this.publish(playback.hasAudio ? 'playing' : 'loading', key, null);
135
+ void playback.resume().catch((error: unknown) => {
136
+ if (run !== this.run || this.paused) return;
137
+ this.failRun(error instanceof Error ? error.message : 'The audio could not be played.');
138
+ });
130
139
  }
131
140
 
132
141
  stop(): void {
@@ -134,27 +143,14 @@ class TtsPlayer {
134
143
  this.abort?.abort();
135
144
  this.abort = null;
136
145
  this.paused = false;
137
- const finish = this.finishPlayback;
138
- this.finishPlayback = null;
139
- const audio = this.audio;
140
- this.audio = null;
141
- const url = this.objectUrl;
142
- this.objectUrl = null;
143
- if (audio) {
144
- audio.onended = null;
145
- audio.onerror = null;
146
- audio.pause();
147
- audio.removeAttribute('src');
148
- audio.load();
149
- }
150
- if (url) URL.revokeObjectURL(url);
151
- finish?.();
146
+ this.playback?.stop();
152
147
  if (this.snapshot.status !== 'idle' || this.snapshot.activeKey !== null) {
153
148
  this.publish('idle', null, null);
154
149
  }
155
150
  }
156
151
 
157
152
  private async playChunks(
153
+ playback: GaplessAudio,
158
154
  chunks: string[],
159
155
  config: TtsConfig,
160
156
  key: string,
@@ -168,21 +164,35 @@ class TtsPlayer {
168
164
  promise.catch(() => undefined);
169
165
  pending.set(index, promise);
170
166
  };
171
- for (let index = 0; index < PREFETCH_WINDOW; index += 1) startFetch(index);
172
167
 
173
168
  try {
169
+ // A blocked autoplay must not spend a provider request before it fails.
170
+ await playback.ensure();
171
+ if (run !== this.run) return;
172
+ for (let index = 0; index < PREFETCH_WINDOW; index += 1) startFetch(index);
173
+
174
174
  for (let index = 0; index < chunks.length; index += 1) {
175
175
  if (run !== this.run) return;
176
176
  const blob = await pending.get(index);
177
177
  pending.delete(index);
178
178
  if (!blob || run !== this.run) return;
179
179
  startFetch(index + PREFETCH_WINDOW);
180
- await this.playBlob(blob, run);
180
+ await playback.schedule(blob);
181
181
  if (run !== this.run) return;
182
+ if (this.snapshot.status === 'loading') this.publish('playing', key, null);
182
183
  }
183
- if (run === this.run) this.publish('idle', null, null);
184
- } catch (error) {
184
+
185
+ await playback.finish();
185
186
  if (run !== this.run) return;
187
+ playback.idle();
188
+ this.abort = null;
189
+ this.publish('idle', null, null);
190
+ } catch (error: unknown) {
191
+ if (run !== this.run) return;
192
+ controller.abort();
193
+ if (this.abort === controller) this.abort = null;
194
+ this.paused = false;
195
+ playback.stop();
186
196
  const message = error instanceof Error ? error.message : 'Could not read the answer aloud.';
187
197
  this.publish('error', key, message);
188
198
  }
@@ -224,69 +234,9 @@ class TtsPlayer {
224
234
  this.abort?.abort();
225
235
  this.abort = null;
226
236
  this.paused = false;
237
+ this.playback?.stop();
227
238
  this.publish('error', this.snapshot.activeKey, message);
228
239
  }
229
-
230
- private startPlayback(audio: HTMLAudioElement, run: number): void {
231
- void audio.play().then(() => {
232
- if (run !== this.run || this.paused) return;
233
- const status = this.snapshot.status;
234
- if (status === 'loading' || status === 'paused') {
235
- this.publish('playing', this.snapshot.activeKey, null);
236
- }
237
- }).catch((error: unknown) => {
238
- if (run !== this.run || this.paused) return;
239
- if (error instanceof Error && error.name === 'AbortError') return;
240
- const blocked = error instanceof Error && error.name === 'NotAllowedError';
241
- this.finishPlayback?.(
242
- blocked
243
- ? 'The browser blocked autoplay. Press the speaker button to hear this answer.'
244
- : 'The audio could not be played.',
245
- );
246
- });
247
- }
248
-
249
- private playBlob(blob: Blob, run: number): Promise<void> {
250
- if (run !== this.run) return Promise.resolve();
251
- const audio = this.audio ?? new Audio();
252
- this.audio = audio;
253
-
254
- const url = URL.createObjectURL(blob);
255
- const stale = this.objectUrl;
256
- this.objectUrl = url;
257
- audio.src = url;
258
- if (stale) URL.revokeObjectURL(stale);
259
-
260
- const finished = Promise.withResolvers<void>();
261
- let settled = false;
262
- const done = (): void => {
263
- if (settled) return;
264
- settled = true;
265
- if (this.finishPlayback === fail) this.finishPlayback = null;
266
- audio.onended = null;
267
- audio.onerror = null;
268
- audio.removeAttribute('src');
269
- audio.load();
270
- if (this.audio === audio) this.audio = null;
271
- if (this.objectUrl === url) this.objectUrl = null;
272
- URL.revokeObjectURL(url);
273
- finished.resolve();
274
- };
275
- const fail = (message?: string): void => {
276
- if (message) this.failRun(message);
277
- done();
278
- };
279
-
280
- this.finishPlayback = fail;
281
- audio.onended = done;
282
- audio.onerror = () => {
283
- if (run === this.run) fail('The audio could not be played.');
284
- else done();
285
- };
286
- // A paused read never starts the next chunk; `resume` starts this one.
287
- if (!this.paused) this.startPlayback(audio, run);
288
- return finished.promise;
289
- }
290
240
  }
291
241
 
292
242
  export const ttsPlayer = new TtsPlayer();
@@ -21,10 +21,8 @@
21
21
  * `LOCK_TIMEOUT_MS`) are the one place real wall-clock time is exercised.
22
22
  *
23
23
  * `git-repos` walks a TEMP tree (`git init` in a couple of subdirs) to pin the
24
- * pruning and depth rules that keep the walk bounded; `git-ignore` drives a
25
- * real `git check-ignore` against fixture `.gitignore` files to pin pattern,
26
- * negation and directory matching, plus the "not a repository" (exit 128)
27
- * non-answer.
24
+ * pruning and depth rules that keep the walk bounded. `git-ignore` has its own
25
+ * file (`git-ignore.test.ts`), next to the module whose scope it pins.
28
26
  */
29
27
 
30
28
  import { afterAll, beforeEach, describe, expect, test } from 'bun:test';
@@ -48,7 +46,6 @@ import { execFileSync } from 'node:child_process';
48
46
  import { writeFileAtomic } from '@kabmo-labs/kabmo-fs/config/atomic-write';
49
47
  import { withConfigLock } from '@kabmo-labs/kabmo-fs/config/config-lock';
50
48
  import { discoveredRepos, rescanRepos, startRepoScan } from '@/server/lib/fs/git-repos';
51
- import { collectIgnoredPaths } from '@/server/lib/fs/git-ignore';
52
49
  import { testPosix } from '@/test-support/platform';
53
50
 
54
51
  const tempDirs: string[] = [];
@@ -283,50 +280,21 @@ describe('git-repos discovery', () => {
283
280
  rescanRepos(root);
284
281
  expect((await settled(root)).repos).toContain('two');
285
282
  });
286
- });
287
-
288
- describe('collectIgnoredPaths', () => {
289
- test('no paths means no git call and an empty answer', async () => {
290
- expect(await collectIgnoredPaths(tempDir('ignore'), [])).toEqual(new Set());
291
- });
292
283
 
293
- test('patterns, negation and directory patterns match what git refuses', async () => {
294
- const dir = tempDir('ignore');
295
- execFileSync('git', ['init', '-q'], { cwd: dir });
296
- writeFileSync(join(dir, '.gitignore'), 'build/\n*.log\n!keep.log\n');
297
- mkdirSync(join(dir, 'build'), { recursive: true });
298
- writeFileSync(join(dir, 'build', 'x.txt'), '');
299
- writeFileSync(join(dir, 'a.log'), '');
300
- writeFileSync(join(dir, 'keep.log'), '');
301
- mkdirSync(join(dir, 'src'), { recursive: true });
302
- writeFileSync(join(dir, 'src', 'main.ts'), '');
303
-
304
- const ignored = await collectIgnoredPaths(dir, ['build/x.txt', 'a.log', 'keep.log', 'src/main.ts']);
305
- expect(ignored.has('build/x.txt')).toBe(true); // directory pattern
306
- expect(ignored.has('a.log')).toBe(true); // extension pattern
307
- expect(ignored.has('keep.log')).toBe(false); // negated
308
- expect(ignored.has('src/main.ts')).toBe(false);
309
- });
284
+ test('a rescan keeps the previous list while its walk runs', async () => {
285
+ // The topic answers whatever `discoveredRepos` holds, and every picker on
286
+ // the root renders it. Blanking the cache to `['.']` for the length of the
287
+ // walk made a refresh drop every nested row — including the selected one,
288
+ // whose absence made the picker name the workspace ROOT instead.
289
+ const root = tempDir('repos');
290
+ gitInit(join(root, 'one'));
291
+ startRepoScan(root);
292
+ const first = await settled(root);
310
293
 
311
- test('a non-repository (exit 128) is not cached as an answer', async () => {
312
- const dir = tempDir('ignore');
313
- writeFileSync(join(dir, 'a.log'), '');
314
- expect(await collectIgnoredPaths(dir, ['a.log'])).toEqual(new Set());
315
- // Same path, now inside a repository with a rule that matches it: had the
316
- // 128 answer been cached, this would still be empty.
317
- execFileSync('git', ['init', '-q'], { cwd: dir });
318
- writeFileSync(join(dir, '.gitignore'), '*.log\n');
319
- expect((await collectIgnoredPaths(dir, ['a.log'])).has('a.log')).toBe(true);
320
- });
294
+ rescanRepos(root);
295
+ expect(discoveredRepos(root)).toEqual({ repos: first.repos, pending: true });
321
296
 
322
- test('an answer is cached for the TTL, so a just-edited rule is briefly stale', async () => {
323
- const dir = tempDir('ignore');
324
- execFileSync('git', ['init', '-q'], { cwd: dir });
325
- writeFileSync(join(dir, '.gitignore'), '*.log\n');
326
- writeFileSync(join(dir, 'a.log'), '');
327
- expect((await collectIgnoredPaths(dir, ['a.log'])).has('a.log')).toBe(true);
328
- rmSync(join(dir, '.gitignore'));
329
- // Within the 5s TTL the memoized "ignored" answer is still returned.
330
- expect((await collectIgnoredPaths(dir, ['a.log'])).has('a.log')).toBe(true);
297
+ const second = await settled(root);
298
+ expect(second.repos).toContain('one');
331
299
  });
332
300
  });
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `git check-ignore` as the Files panel's dim rule.
8
+ *
9
+ * Every case drives a REAL git against a temp tree: the question is what git
10
+ * refuses to track, so a hand-written pattern matcher would pin a second
11
+ * implementation instead of the authority. What is pinned is the scope of the
12
+ * answer — per-directory `.gitignore`, negation and directory patterns, the
13
+ * "not a repository" (exit 128) non-answer, the 5 s memo, and the ceiling that
14
+ * stops an enclosing repository from answering for a root it does not own.
15
+ */
16
+
17
+ import { afterAll, describe, expect, test } from 'bun:test';
18
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
19
+ import { execFileSync } from 'node:child_process';
20
+ import { tmpdir } from 'node:os';
21
+ import { join } from 'node:path';
22
+ import { collectIgnoredPaths } from '@/server/lib/fs/git-ignore';
23
+
24
+ const tempDirs: string[] = [];
25
+
26
+ function tempDir(prefix: string): string {
27
+ const dir = mkdtempSync(join(tmpdir(), `kabmo-${prefix}-`));
28
+ tempDirs.push(dir);
29
+ return dir;
30
+ }
31
+
32
+ afterAll(() => {
33
+ for (const dir of tempDirs) rmSync(dir, { recursive: true, force: true });
34
+ });
35
+
36
+ describe('collectIgnoredPaths', () => {
37
+ test('no paths means no git call and an empty answer', async () => {
38
+ expect(await collectIgnoredPaths(tempDir('ignore'), [])).toEqual(new Set());
39
+ });
40
+
41
+ test('patterns, negation and directory patterns match what git refuses', async () => {
42
+ const dir = tempDir('ignore');
43
+ execFileSync('git', ['init', '-q'], { cwd: dir });
44
+ writeFileSync(join(dir, '.gitignore'), 'build/\n*.log\n!keep.log\n');
45
+ mkdirSync(join(dir, 'build'), { recursive: true });
46
+ writeFileSync(join(dir, 'build', 'x.txt'), '');
47
+ writeFileSync(join(dir, 'a.log'), '');
48
+ writeFileSync(join(dir, 'keep.log'), '');
49
+ mkdirSync(join(dir, 'src'), { recursive: true });
50
+ writeFileSync(join(dir, 'src', 'main.ts'), '');
51
+
52
+ const ignored = await collectIgnoredPaths(dir, ['build/x.txt', 'a.log', 'keep.log', 'src/main.ts']);
53
+ expect(ignored.has('build/x.txt')).toBe(true); // directory pattern
54
+ expect(ignored.has('a.log')).toBe(true); // extension pattern
55
+ expect(ignored.has('keep.log')).toBe(false); // negated
56
+ expect(ignored.has('src/main.ts')).toBe(false);
57
+ });
58
+
59
+ test('an enclosing repository above the browsed root does not answer for it', async () => {
60
+ const outer = tempDir('ignore-nested');
61
+ execFileSync('git', ['init', '-q'], { cwd: outer });
62
+ writeFileSync(join(outer, '.gitignore'), 'projects/\n');
63
+ const root = join(outer, 'projects');
64
+ mkdirSync(join(root, 'child-one'), { recursive: true });
65
+ mkdirSync(join(root, 'child-two'), { recursive: true });
66
+ execFileSync('git', ['init', '-q'], { cwd: join(root, 'child-one') });
67
+
68
+ // `projects/` is ignored by the repository ABOVE the browsed root — the
69
+ // folder-of-repositories layout (`projects/<name>/.git`) that Kabmo opens
70
+ // as a workspace. Every row used to come back dimmed from those rules.
71
+ expect(await collectIgnoredPaths(root, ['child-one', 'child-two'])).toEqual(new Set());
72
+
73
+ // The root's OWN repository still answers: the ceiling is its parent, not
74
+ // the root itself (git treats a ceiling equal to the start as no ceiling).
75
+ writeFileSync(join(root, 'child-one', '.gitignore'), '*.log\n');
76
+ writeFileSync(join(root, 'child-one', 'a.log'), '');
77
+ expect((await collectIgnoredPaths(join(root, 'child-one'), ['a.log'])).has('a.log')).toBe(true);
78
+ });
79
+
80
+ test('a non-repository (exit 128) is not cached as an answer', async () => {
81
+ const dir = tempDir('ignore');
82
+ writeFileSync(join(dir, 'a.log'), '');
83
+ expect(await collectIgnoredPaths(dir, ['a.log'])).toEqual(new Set());
84
+ // Same path, now inside a repository with a rule that matches it: had the
85
+ // 128 answer been cached, this would still be empty.
86
+ execFileSync('git', ['init', '-q'], { cwd: dir });
87
+ writeFileSync(join(dir, '.gitignore'), '*.log\n');
88
+ expect((await collectIgnoredPaths(dir, ['a.log'])).has('a.log')).toBe(true);
89
+ });
90
+
91
+ test('an answer is cached for the TTL, so a just-edited rule is briefly stale', async () => {
92
+ const dir = tempDir('ignore');
93
+ execFileSync('git', ['init', '-q'], { cwd: dir });
94
+ writeFileSync(join(dir, '.gitignore'), '*.log\n');
95
+ writeFileSync(join(dir, 'a.log'), '');
96
+ expect((await collectIgnoredPaths(dir, ['a.log'])).has('a.log')).toBe(true);
97
+ rmSync(join(dir, '.gitignore'));
98
+ // Within the 5s TTL the memoized "ignored" answer is still returned.
99
+ expect((await collectIgnoredPaths(dir, ['a.log'])).has('a.log')).toBe(true);
100
+ });
101
+ });