@double_geste/agent-standup 1.46.0 → 1.47.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.
@@ -26,4 +26,4 @@ Command titles and setting descriptions use VS Code's own mechanism: `package.nl
26
26
  They work the same way, with their own files: `website/locales/<code>.json` (agent-standup.com, one page per language, written by `npm run website`) and `landing/locales/<code>.json` (the landing page, which fetches the file of the chosen language). English and French are in the pages themselves (`data-en` / `data-fr` in `website/src/home.html` and `landing/template.html`). `node scripts/site-locales.js extract` regenerates the two `en.json`, and `npm run i18n` checks these files too. Keep the HTML tags of a text exactly as in the English.
27
27
 
28
28
  ## What is *not* translated
29
- The words agents say come from your session (their own language), unless the call is held in French, Spanish or Brazilian Portuguese: these three are in the code (`CALL_LANG` in `public/index.html`), each with its own little banter lines (answers to orders, goodbyes) next to the English and French ones, its voices and its translation. Another language needs all of these, not only a catalogue. The built-in demo exists in English and French only.
29
+ The words agents say come from your session (their own language), unless the call is held in French, Spanish, Brazilian Portuguese, German, Danish, Japanese, Korean or Chinese: these eight are in the code (Chinese twice, Simplified `zh` and Traditional `zt`) (`CALL_LANG` in `public/index.html`), each with its own little banter lines (answers to orders, goodbyes) next to the English and French ones, its voices and its translation. Another language needs all of these, not only a catalogue. The built-in demo exists in English and French only.
@@ -333,7 +333,9 @@
333
333
  "⭐ Rate Agent Standup": "⭐ Bedøm Agent Standup",
334
334
  "⭐ Star Agent Standup on GitHub": "⭐ Giv Agent Standup en stjerne på GitHub",
335
335
  "⭐ Star it": "⭐ Giv en stjerne",
336
+ "⭐ Rate it": "⭐ Bedøm",
336
337
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "Kan du lide Agent Standup? En stjerne på GitHub hjælper andre med at finde det.",
338
+ "Enjoying Agent Standup? A rating helps other people find it.": "Kan du lide Agent Standup? En bedømmelse hjælper andre med at finde det.",
337
339
  "Later": "Senere",
338
340
  "No thanks": "Nej tak",
339
341
  "Model": "Model",
@@ -462,5 +464,8 @@
462
464
  "Agents you named yourself take these names too (switch below).": "Agenter, du selv har navngivet, får også disse navne (kontakten nedenfor).",
463
465
  "Zen: alerts only, no voices (M key)": "Zen: kun advarsler, ingen stemmer (M-tasten)",
464
466
  "Sound: all, zen (alerts only), off": "Lyd: alt, zen (kun advarsler), fra",
465
- "Zen mode: alerts, no voices": "Zen-tilstand: advarsler, ingen stemmer"
467
+ "Zen mode: alerts, no voices": "Zen-tilstand: advarsler, ingen stemmer",
468
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "Holde opkaldet på dette sprog? Din Claude Code oversætter, hvad agenterne siger.",
469
+ "Yes": "Ja",
470
+ "Voices ready in English. This language has natural voices too: one more download.": "Stemmerne er klar på engelsk. Dette sprog har også naturlige stemmer: én download mere."
466
471
  }
@@ -334,7 +334,9 @@
334
334
  "⭐ Rate Agent Standup": "⭐ Agent Standup bewerten",
335
335
  "⭐ Star Agent Standup on GitHub": "⭐ Agent Standup auf GitHub einen Stern geben",
336
336
  "⭐ Star it": "⭐ Stern geben",
337
+ "⭐ Rate it": "⭐ Bewerten",
337
338
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "Gefällt dir Agent Standup? Ein Stern auf GitHub hilft anderen, es zu finden.",
339
+ "Enjoying Agent Standup? A rating helps other people find it.": "Gefällt dir Agent Standup? Eine Bewertung hilft anderen, es zu finden.",
338
340
  "Later": "Später",
339
341
  "No thanks": "Nein danke",
340
342
  "Model": "Modell",
@@ -463,5 +465,8 @@
463
465
  "Agents you named yourself take these names too (switch below).": "Agenten, die du selbst benannt hast, bekommen ebenfalls diese Namen (Schalter unten).",
464
466
  "Zen: alerts only, no voices (M key)": "Zen: nur Hinweistöne, keine Stimmen (Taste M)",
465
467
  "Sound: all, zen (alerts only), off": "Ton: alles, Zen (nur Hinweistöne), aus",
466
- "Zen mode: alerts, no voices": "Zen-Modus: Hinweistöne, keine Stimmen"
468
+ "Zen mode: alerts, no voices": "Zen-Modus: Hinweistöne, keine Stimmen",
469
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "Den Call in dieser Sprache führen? Dein Claude Code übersetzt, was die Agenten sagen.",
470
+ "Yes": "Ja",
471
+ "Voices ready in English. This language has natural voices too: one more download.": "Stimmen auf Englisch bereit. Diese Sprache hat auch natürliche Stimmen: ein Download mehr."
467
472
  }
@@ -15,6 +15,7 @@
15
15
  "☕ Buy the dev a coffee": "☕ Buy the dev a coffee",
16
16
  "⚙ All settings (display, alerts…)": "⚙ All settings (display, alerts…)",
17
17
  "⭐ Rate Agent Standup": "⭐ Rate Agent Standup",
18
+ "⭐ Rate it": "⭐ Rate it",
18
19
  "⭐ Star Agent Standup on GitHub": "⭐ Star Agent Standup on GitHub",
19
20
  "⭐ Star it": "⭐ Star it",
20
21
  "🎞 Export video": "🎞 Export video",
@@ -118,6 +119,7 @@
118
119
  "effort": "effort",
119
120
  "Empty or too long message (4000 characters at most)": "Empty or too long message (4000 characters at most)",
120
121
  "Empty: use the default name.": "Empty: use the default name.",
122
+ "Enjoying Agent Standup? A rating helps other people find it.": "Enjoying Agent Standup? A rating helps other people find it.",
121
123
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "Enjoying Agent Standup? A star on GitHub helps other people find it.",
122
124
  "Entirely optional: the app stays free. It is a way to support the artist and the developer.": "Entirely optional: the app stays free. It is a way to support the artist and the developer.",
123
125
  "EPISODE 1": "EPISODE 1",
@@ -168,6 +170,7 @@
168
170
  "Hide until the next question": "Hide until the next question",
169
171
  "high": "high",
170
172
  "Highlights": "Highlights",
173
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "Hold the call in this language? Your Claude Code translates what the agents say.",
171
174
  "Human": "Human",
172
175
  "I already bought it": "I already bought it",
173
176
  "idle": "idle",
@@ -418,6 +421,7 @@
418
421
  "Using skill ": "Using skill ",
419
422
  "Voice style": "Voice style",
420
423
  "Voice volume": "Voice volume",
424
+ "Voices ready in English. This language has natural voices too: one more download.": "Voices ready in English. This language has natural voices too: one more download.",
421
425
  "Voices ready in English. This language is still read by the system voices.": "Voices ready in English. This language is still read by the system voices.",
422
426
  "Voices ready.": "Voices ready.",
423
427
  "VS Code was started from inside a Claude Code session: restart VS Code normally (Dock, Spotlight) to enable translation.": "VS Code was started from inside a Claude Code session: restart VS Code normally (Dock, Spotlight) to enable translation.",
@@ -440,6 +444,7 @@
440
444
  "working": "working",
441
445
  "working for": "working for",
442
446
  "Writing ": "Writing ",
447
+ "Yes": "Yes",
443
448
  "Yes, tell me": "Yes, tell me",
444
449
  "You": "You",
445
450
  "You are sharing your screen": "You are sharing your screen",
@@ -334,7 +334,9 @@
334
334
  "⭐ Rate Agent Standup": "⭐ Valorar Agent Standup",
335
335
  "⭐ Star Agent Standup on GitHub": "⭐ Dar una estrella a Agent Standup en GitHub",
336
336
  "⭐ Star it": "⭐ Dar una estrella",
337
+ "⭐ Rate it": "⭐ Valorar",
337
338
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "¿Te gusta Agent Standup? Una estrella en GitHub ayuda a que otros lo encuentren.",
339
+ "Enjoying Agent Standup? A rating helps other people find it.": "¿Te gusta Agent Standup? Una valoración ayuda a que otros lo encuentren.",
338
340
  "Later": "Más tarde",
339
341
  "No thanks": "No, gracias",
340
342
  "Model": "Modelo",
@@ -463,5 +465,8 @@
463
465
  "Agents you named yourself take these names too (switch below).": "Los agentes que nombraste tú también reciben estos nombres (interruptor de abajo).",
464
466
  "Zen: alerts only, no voices (M key)": "Zen: solo las alertas, sin voces (tecla M)",
465
467
  "Sound: all, zen (alerts only), off": "Sonido: todo, zen (solo alertas), silencio",
466
- "Zen mode: alerts, no voices": "Modo zen: alertas, sin voces"
468
+ "Zen mode: alerts, no voices": "Modo zen: alertas, sin voces",
469
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "¿Hacer la llamada en este idioma? Tu Claude Code traduce lo que dicen los agentes.",
470
+ "Yes": "Sí",
471
+ "Voices ready in English. This language has natural voices too: one more download.": "Voces listas en inglés. Este idioma también tiene voces naturales: una descarga más."
467
472
  }
@@ -334,7 +334,9 @@
334
334
  "⭐ Rate Agent Standup": "⭐ Agent Standup を評価する",
335
335
  "⭐ Star Agent Standup on GitHub": "⭐ GitHub で Agent Standup にスターを付ける",
336
336
  "⭐ Star it": "⭐ スターを付ける",
337
+ "⭐ Rate it": "⭐ 評価する",
337
338
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "Agent Standup を気に入っていただけましたか?GitHub でスターを付けていただけると、ほかの人が見つけやすくなります。",
339
+ "Enjoying Agent Standup? A rating helps other people find it.": "Agent Standup を気に入っていただけましたか?評価をいただけると、ほかの人が見つけやすくなります。",
338
340
  "Later": "後で",
339
341
  "No thanks": "結構です",
340
342
  "Model": "モデル",
@@ -463,5 +465,8 @@
463
465
  "Agents you named yourself take these names too (switch below).": "自分で名前を付けたエージェントにもこれらの名前が付きます(下のスイッチ)。",
464
466
  "Zen: alerts only, no voices (M key)": "Zen:通知音のみ、声なし(Mキー)",
465
467
  "Sound: all, zen (alerts only), off": "サウンド:すべて、Zen(通知音のみ)、オフ",
466
- "Zen mode: alerts, no voices": "Zenモード:通知音のみ、声なし"
468
+ "Zen mode: alerts, no voices": "Zenモード:通知音のみ、声なし",
469
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "通話をこの言語で行いますか?エージェントの発言はあなたの Claude Code が翻訳します。",
470
+ "Yes": "はい",
471
+ "Voices ready in English. This language has natural voices too: one more download.": "英語の音声は準備完了です。この言語にも自然な音声があります(追加のダウンロードが必要です)。"
467
472
  }
@@ -334,7 +334,9 @@
334
334
  "⭐ Rate Agent Standup": "⭐ Agent Standup 평가하기",
335
335
  "⭐ Star Agent Standup on GitHub": "⭐ GitHub에서 Agent Standup에 별 주기",
336
336
  "⭐ Star it": "⭐ 별 주기",
337
+ "⭐ Rate it": "⭐ 평가하기",
337
338
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "Agent Standup이 마음에 드시나요? GitHub에 별을 남겨 주시면 다른 분들이 찾는 데 도움이 됩니다.",
339
+ "Enjoying Agent Standup? A rating helps other people find it.": "Agent Standup이 마음에 드시나요? 평가를 남겨 주시면 다른 분들이 찾는 데 도움이 됩니다.",
338
340
  "Later": "나중에",
339
341
  "No thanks": "괜찮습니다",
340
342
  "Model": "모델",
@@ -463,5 +465,8 @@
463
465
  "Agents you named yourself take these names too (switch below).": "직접 이름을 붙인 에이전트도 이 이름을 받습니다(아래 스위치).",
464
466
  "Zen: alerts only, no voices (M key)": "젠: 알림음만, 목소리 없음 (M 키)",
465
467
  "Sound: all, zen (alerts only), off": "소리: 전체, 젠 (알림음만), 끔",
466
- "Zen mode: alerts, no voices": "젠 모드: 알림음만, 목소리 없음"
468
+ "Zen mode: alerts, no voices": "젠 모드: 알림음만, 목소리 없음",
469
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "이 언어로 통화할까요? 에이전트가 하는 말은 내 Claude Code가 번역합니다.",
470
+ "Yes": "예",
471
+ "Voices ready in English. This language has natural voices too: one more download.": "영어 음성이 준비되었습니다. 이 언어에도 자연스러운 음성이 있습니다. 한 번 더 내려받으면 됩니다."
467
472
  }
@@ -334,7 +334,9 @@
334
334
  "⭐ Rate Agent Standup": "⭐ Avaliar o Agent Standup",
335
335
  "⭐ Star Agent Standup on GitHub": "⭐ Dar uma estrela ao Agent Standup no GitHub",
336
336
  "⭐ Star it": "⭐ Dar uma estrela",
337
+ "⭐ Rate it": "⭐ Avaliar",
337
338
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "Está gostando do Agent Standup? Uma estrela no GitHub ajuda outras pessoas a encontrá-lo.",
339
+ "Enjoying Agent Standup? A rating helps other people find it.": "Está gostando do Agent Standup? Uma avaliação ajuda outras pessoas a encontrá-lo.",
338
340
  "Later": "Mais tarde",
339
341
  "No thanks": "Não, obrigado",
340
342
  "Model": "Modelo",
@@ -463,5 +465,8 @@
463
465
  "Agents you named yourself take these names too (switch below).": "Os agentes que você mesmo nomeou também recebem esses nomes (chave abaixo).",
464
466
  "Zen: alerts only, no voices (M key)": "Zen: só os alertas, sem vozes (tecla M)",
465
467
  "Sound: all, zen (alerts only), off": "Som: tudo, zen (só alertas), desligado",
466
- "Zen mode: alerts, no voices": "Modo zen: alertas, sem vozes"
468
+ "Zen mode: alerts, no voices": "Modo zen: alertas, sem vozes",
469
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "Fazer a chamada neste idioma? O seu Claude Code traduz o que os agentes dizem.",
470
+ "Yes": "Sim",
471
+ "Voices ready in English. This language has natural voices too: one more download.": "Vozes prontas em inglês. Este idioma também tem vozes naturais: mais um download."
467
472
  }
@@ -334,7 +334,9 @@
334
334
  "⭐ Rate Agent Standup": "⭐ 为 Agent Standup 评分",
335
335
  "⭐ Star Agent Standup on GitHub": "⭐ 在 GitHub 上为 Agent Standup 加星",
336
336
  "⭐ Star it": "⭐ 加星",
337
+ "⭐ Rate it": "⭐ 去评分",
337
338
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "喜欢 Agent Standup 吗?在 GitHub 上加颗星能帮助更多人发现它。",
339
+ "Enjoying Agent Standup? A rating helps other people find it.": "喜欢 Agent Standup 吗?留下评分能帮助更多人发现它。",
338
340
  "Later": "以后再说",
339
341
  "No thanks": "不用了",
340
342
  "Model": "模型",
@@ -463,5 +465,8 @@
463
465
  "Agents you named yourself take these names too (switch below).": "你自己命名的代理也会使用这些名字(见下方开关)。",
464
466
  "Zen: alerts only, no voices (M key)": "禅模式:只有提示音,没有语音(M 键)",
465
467
  "Sound: all, zen (alerts only), off": "声音:全部、禅模式(仅提示音)、关闭",
466
- "Zen mode: alerts, no voices": "禅模式:提示音,无语音"
468
+ "Zen mode: alerts, no voices": "禅模式:提示音,无语音",
469
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "用此语言进行通话吗?智能体说的话由你的 Claude Code 翻译。",
470
+ "Yes": "是",
471
+ "Voices ready in English. This language has natural voices too: one more download.": "英语语音已就绪。此语言也有自然语音:再下载一次即可。"
467
472
  }
@@ -334,7 +334,9 @@
334
334
  "⭐ Rate Agent Standup": "⭐ 為 Agent Standup 評分",
335
335
  "⭐ Star Agent Standup on GitHub": "⭐ 在 GitHub 上為 Agent Standup 加星",
336
336
  "⭐ Star it": "⭐ 加星",
337
+ "⭐ Rate it": "⭐ 去評分",
337
338
  "Enjoying Agent Standup? A star on GitHub helps other people find it.": "喜歡 Agent Standup 嗎?在 GitHub 上加顆星能幫助更多人發現它。",
339
+ "Enjoying Agent Standup? A rating helps other people find it.": "喜歡 Agent Standup 嗎?留下評分能幫助更多人發現它。",
338
340
  "Later": "以後再說",
339
341
  "No thanks": "不用了",
340
342
  "Model": "模型",
@@ -463,5 +465,8 @@
463
465
  "Agents you named yourself take these names too (switch below).": "你自己命名的代理也會使用這些名字(見下方開關)。",
464
466
  "Zen: alerts only, no voices (M key)": "禪模式:只有提示音,沒有語音(M 鍵)",
465
467
  "Sound: all, zen (alerts only), off": "聲音:全部、禪模式(僅提示音)、關閉",
466
- "Zen mode: alerts, no voices": "禪模式:提示音,無語音"
468
+ "Zen mode: alerts, no voices": "禪模式:提示音,無語音",
469
+ "Hold the call in this language? Your Claude Code translates what the agents say.": "用此語言進行通話嗎?代理說的話由你的 Claude Code 翻譯。",
470
+ "Yes": "是",
471
+ "Voices ready in English. This language has natural voices too: one more download.": "英文語音已就緒。此語言也有自然語音:再下載一次即可。"
467
472
  }
package/server.js CHANGED
@@ -1270,7 +1270,7 @@ const translate = (texts, lang) => translateFast(texts, lang);
1270
1270
 
1271
1271
  // Warm `claude` workers: after a slow first call each translation takes ~2-3 s (a cold `claude -p` costs ~6 s).
1272
1272
  // The languages a call can be held in besides English (the page asks for one with `lang`; French when it says nothing, as it always was).
1273
- const TR_LANG = { fr: 'French', es: 'Spanish', pt: 'Brazilian Portuguese' }, trLang = (l) => (Object.hasOwn(TR_LANG, l) ? l : 'fr');
1273
+ const TR_LANG = { fr: 'French', es: 'Spanish', pt: 'Brazilian Portuguese', de: 'German', da: 'Danish', ja: 'Japanese', ko: 'Korean', zh: 'Simplified Chinese', zt: 'Traditional Chinese' }, trLang = (l) => (Object.hasOwn(TR_LANG, l) ? l : 'fr');
1274
1274
  const trInstr = (lang) => `Translate each string of this JSON array into natural spoken ${TR_LANG[lang]}, as a teammate would say it in a meeting. Keep code identifiers, file paths, library names and numbers unchanged.`;
1275
1275
  const trSys = (lang) => `You are a translation engine. Translate the user message into natural spoken ${TR_LANG[lang]}, as a colleague would say it in a meeting. Keep code identifiers, file paths, library names and numbers unchanged. Reply with ONLY the translation, nothing else.`;
1276
1276
  class TrWorker {
@@ -1365,7 +1365,7 @@ function tts(text, voice, rate, engine, fb) {
1365
1365
  if (ttsJobs.has(key)) return ttsJobs.get(key);
1366
1366
  fs.mkdirSync(ttsDir, { recursive: true });
1367
1367
  const tmp = file + '.part.wav';
1368
- const job = (kk ? kokoro.synth(text, voice, kokoro.speedFor(rate), tmp).catch((e) => { const vs = listVoices(), v = vs.voices.find((x) => x.name === fb) || vs.voices.find((x) => x.locale.startsWith(kokoro.localeOf(voice).slice(0, 3))); if (!v) throw e; return synthesize(v.name, rate, text, tmp); }) : synthesize(voice, rate, text, tmp)) // a line Kokoro cannot make goes to a system voice instead of being dropped: the one the page names (fb, its best system voice for this character), or else the first one of the same language
1368
+ const job = (kk ? kokoro.synth(text, voice, kokoro.speedFor(rate), tmp).catch((e) => { if (kokoro.natural(voice)) throw e; const vs = listVoices(), v = vs.voices.find((x) => x.name === fb) || vs.voices.find((x) => x.locale.startsWith(kokoro.localeOf(voice).slice(0, 3))); if (!v) throw e; return synthesize(v.name, rate, text, tmp); }) : synthesize(voice, rate, text, tmp)) // a line Kokoro cannot make goes to a system voice instead of being dropped: the one the page names (fb, its best system voice for this character), or else the first one of the same language. Not for German, Danish, Japanese and Korean (natural): those are natural voices or none, and the page babbles the line
1369
1369
  .then(() => { fs.renameSync(tmp, file); return file; }).finally(() => ttsJobs.delete(key));
1370
1370
  ttsJobs.set(key, job); return job;
1371
1371
  }
@@ -1542,7 +1542,7 @@ function start(port = PORT) {
1542
1542
  if (url.searchParams.get('engine') === 'kokoro') { const st = kokoro.status(); if (st.installed && !st.gaveUp) kokoro.warm(); return json({ available: st.installed && !st.gaveUp, ready: st.ready, voices: kokoro.voices(), platform: process.platform, engine: 'kokoro' }); }
1543
1543
  return loadVoices().then((v) => json(v));
1544
1544
  }
1545
- if (url.pathname === '/api/kokoro/install' && req.method === 'POST') return json(kokoro.install()); if (url.pathname === '/api/usage' && req.method === 'POST') return json(usageWeek());
1545
+ if (url.pathname === '/api/kokoro/install' && req.method === 'POST') return json(kokoro.install({ st: url.searchParams.get('st') === '1', zh: url.searchParams.get('zh') === '1' })); /* st=1: the voices of German, Danish, Japanese and Korean as well; zh=1: the Chinese ones */ if (url.pathname === '/api/usage' && req.method === 'POST') return json(usageWeek());
1546
1546
  if (url.pathname === '/api/update') return updateInfo().then(json, () => json({ on: false, current: VERSION })); /* a newer version, at most one request to npm a day (updateInfo) */
1547
1547
  if (url.pathname === '/api/kokoro') return json(kokoro.status());
1548
1548
  if (url.pathname === '/api/tts') {
@@ -1642,7 +1642,7 @@ function start(port = PORT) {
1642
1642
  } catch (e) { logError(req.method + ' ' + url.pathname, e); if (res.headersSent) return res.destroy(); json({ error: String(e.message || e) }, 500); }
1643
1643
  }).listen(port, '127.0.0.1', function () { console.log(`Agent Standup → http://localhost:${this.address().port}`); });
1644
1644
  }
1645
- module.exports = { answerIn, missingTranscripts, noteEditor, forgetEditor, _winArg: winArg, start, currentSession, shutdown, findClaude, bundledClaude, boardRows, timeline: (proj, id) => timelineEntry(proj, id).tl, transcriptFile: (proj, id) => path.join(projDir(proj, id), id + '.jsonl'), sessionRows: listSessions, sessionsSince: (t) => listSessions0(+t || 0), codexPending: () => guard(() => !!(codex.zPending && codex.zPending()), false), charactersDir, listCharacters, packsDir, installPack, logError, updateInfo, _reveal: reveal, _scrub: { tidy, homeRe }, _artifact: { page: artifactPage, csp: artifactCsp } };
1645
+ module.exports = { answerIn, missingTranscripts, noteEditor, forgetEditor, _winArg: winArg, start, currentSession, shutdown, findClaude, bundledClaude, boardRows, timeline: (proj, id) => timelineEntry(proj, id).tl, transcriptFile: (proj, id) => path.join(projDir(proj, id), id + '.jsonl'), sessionRows: listSessions, sessionsSince: (t) => listSessions0(+t || 0), codexPending: () => guard(() => !!(codex.zPending && codex.zPending()), false), charactersDir, listCharacters, packsDir, installPack, logError, updateInfo, _reveal: reveal, _scrub: { tidy, homeRe }, _artifact: { page: artifactPage, csp: artifactCsp }, readPrefs, leadKey: (proj, id) => guard(() => (leadProject(proj, id) || {}).key || '', '') };
1646
1646
  if (require.main === module && process.env.AGENT_STANDUP_CHILD === '1' && typeof process.send === 'function') { // started by the VS Code extension in a process of its own (see extension.js): reading a large session no longer stops the editor's extensions. Asked for by name: pm2 and others give any app a channel too
1647
1647
  const srv = start(+process.env.PORT || 0), tell = (m) => { try { process.send(m); } catch {} };
1648
1648
  srv.on('listening', () => tell({ port: srv.address().port })).on('error', (e) => { tell({ error: e.code || String(e) }); process.exit(1); });
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ // Supertonic worker: the natural voices of German, Danish, Japanese and Korean, which Kokoro does not speak. Supertonic 3 (Supertone; model under the OpenRAIL-M licence, downloaded on demand by kokoro.js,
3
+ // never shipped with the app) runs on the onnxruntime-node that the Kokoro install already holds. Loads the four parts of the model once, then reads one JSON request per stdin line
4
+ // ({ id, text, voice, lang, speed, out }: voice is a style file, F1 to M5), writes a 16-bit WAV to `out` and answers { id, ok, seconds } or { id, ok: false, error }. Started by kokoro.js.
5
+ // The inference follows Supertone's MIT-licensed Node example (github.com/supertone-inc/supertonic, nodejs/helper.js), with three changes: a line is cut at the ends of its sentences in every script
6
+ // (。!? too: the example only cuts at ". "), a character the model does not know is left out instead of sent as -1, and the noise the model starts from is drawn from the line itself,
7
+ // so the same line sounds the same each time it is made (the example draws it at random, and a slip then comes and goes).
8
+ const fs = require('fs'), path = require('path'), readline = require('readline'), { createRequire } = require('module');
9
+ const send = (o) => fs.writeSync(1, JSON.stringify(o) + '\n');
10
+ const STEPS = 8; // 5 steps slipped words in French (October 2026 audit); 8 did not
11
+ const LANGS = new Set(['en', 'ko', 'ja', 'ar', 'bg', 'cs', 'da', 'de', 'el', 'es', 'et', 'fi', 'fr', 'hi', 'hr', 'hu', 'id', 'it', 'lt', 'lv', 'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sv', 'tr', 'uk', 'vi']);
12
+ const finite = (s) => { for (let i = 0; i < s.length; i++) if (s[i] !== s[i]) return false; return true; };
13
+ function wav(samples, rate) { // Float32 in [-1, 1] → 16-bit mono WAV
14
+ const n = samples.length, buf = Buffer.alloc(44 + n * 2);
15
+ buf.write('RIFF', 0); buf.writeUInt32LE(36 + n * 2, 4); buf.write('WAVEfmt ', 8); buf.writeUInt32LE(16, 16); buf.writeUInt16LE(1, 20); buf.writeUInt16LE(1, 22); buf.writeUInt32LE(rate, 24); buf.writeUInt32LE(rate * 2, 28); buf.writeUInt16LE(2, 32); buf.writeUInt16LE(16, 34); buf.write('data', 36); buf.writeUInt32LE(n * 2, 40);
16
+ for (let i = 0; i < n; i++) { const s = Math.max(-1, Math.min(1, samples[i])); buf.writeInt16LE(Math.round(s < 0 ? s * 32768 : s * 32767), 44 + i * 2); }
17
+ return buf;
18
+ }
19
+ // ---- text, as the model was trained to read it (the example's normaliser)
20
+ const EMOJI = /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F1E6}-\u{1F1FF}]+/gu;
21
+ const SWAP = [['–', '-'], ['‑', '-'], ['—', '-'], ['_', ' '], ['“', '"'], ['”', '"'], ['‘', "'"], ['’', "'"], ['´', "'"], ['`', "'"], ['[', ' '], [']', ' '], ['|', ' '], ['/', ' '], ['#', ' '], ['→', ' '], ['←', ' '], ['@', ' at '], ['e.g.,', 'for example, '], ['i.e.,', 'that is, ']];
22
+ function normalise(text) {
23
+ text = text.normalize('NFKD').replace(EMOJI, ''); for (const [a, b] of SWAP) text = text.split(a).join(b);
24
+ text = text.replace(/[♥☆♡©\\]/g, '').replace(/ ([,.!?;:'])/g, '$1').replace(/"{2,}/g, '"').replace(/'{2,}/g, "'").replace(/\s+/g, ' ').trim();
25
+ return /[.!?;:,'")\]}…。」』】〉》›»]$/.test(text) ? text : text + '.';
26
+ }
27
+ // ---- a long line is made in parts and joined. The model takes about 300 characters at a time (120 in Japanese and Korean, the example's limits), cut where a pause is natural, best first:
28
+ // the end of a sentence, a comma, a space; a text with none of these is cut in the middle. Each cut gets its pause, in seconds at speed 1.
29
+ const CUTS = [[/[.!?…。!?]+["'”’»)\]」』]*\s*/g, 0.45], [/[,;:、,;:]\s*/g, 0.2], [/\s+/g, 0.05]];
30
+ function halve(s) {
31
+ for (const [re, gap] of CUTS) { let at = 0; for (const m of s.matchAll(re)) { const i = m.index + m[0].length; if (i < s.length && Math.abs(i - s.length / 2) < Math.abs(at - s.length / 2)) at = i; } if (at) return [s.slice(0, at), s.slice(at), gap]; }
32
+ const at = Math.ceil(s.length / 2); return [s.slice(0, at), s.slice(at), 0];
33
+ }
34
+ function pieces(text, max) { if (text.length <= max) return [text]; const [a, b, gap] = halve(text); return [...pieces(a.trim(), max), gap, ...pieces(b.trim(), max)].filter((x) => x !== ''); }
35
+ // ---- the noise: a generator seeded by the line, the voice and the language
36
+ function seeded(str) {
37
+ let h = 2166136261; for (let i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = Math.imul(h, 16777619); }
38
+ return () => { h = (h + 0x6d2b79f5) | 0; let t = Math.imul(h ^ (h >>> 15), 1 | h); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
39
+ }
40
+ async function main() {
41
+ const dir = process.env.AGENT_STANDUP_KOKORO_DIR, model = process.env.AGENT_STANDUP_ST_DIR || path.join(dir, 'supertonic-3');
42
+ const ort = createRequire(path.join(dir, 'node_modules', 'x.js'))('onnxruntime-node'); // resolved from the install folder, not from the extension
43
+ const onnx = (n) => path.join(model, 'onnx', n), cfg = JSON.parse(fs.readFileSync(onnx('tts.json'), 'utf8')), index = JSON.parse(fs.readFileSync(onnx('unicode_indexer.json'), 'utf8'));
44
+ // without ONNX Runtime's memory arena and patterns, the worker holds about 470 MB instead of 760, at the same speed (measured on an M1 Pro, November 2026)
45
+ const [dp, enc, est, voc] = await Promise.all(['duration_predictor', 'text_encoder', 'vector_estimator', 'vocoder'].map((n) => ort.InferenceSession.create(onnx(n + '.onnx'), { enableCpuMemArena: false, enableMemPattern: false })));
46
+ const rate = cfg.ae.sample_rate, chunk = cfg.ae.base_chunk_size * cfg.ttl.chunk_compress_factor, dim = cfg.ttl.latent_dim * cfg.ttl.chunk_compress_factor;
47
+ const styles = new Map(), style = (v) => { // a voice: two tensors, read once from voice_styles/<v>.json
48
+ if (!/^[FM][1-5]$/.test(v)) throw new Error('unknown voice ' + v);
49
+ if (!styles.has(v)) { const j = JSON.parse(fs.readFileSync(path.join(model, 'voice_styles', v + '.json'), 'utf8')), t = (o) => new ort.Tensor('float32', Float32Array.from(o.data.flat(Infinity)), o.dims); styles.set(v, { ttl: t(j.style_ttl), dp: t(j.style_dp) }); }
50
+ return styles.get(v);
51
+ };
52
+ const f32 = (data, dims) => new ort.Tensor('float32', data, dims);
53
+ async function infer(text, lang, st, speed, seed) { // one piece → Float32Array at `rate`
54
+ const ids = []; for (const ch of `<${lang}>${normalise(text)}</${lang}>`) { const id = index[ch.charCodeAt(0)]; if (id >= 0) ids.push(BigInt(id)); }
55
+ const n = ids.length, textIds = new ort.Tensor('int64', BigInt64Array.from(ids), [1, n]), textMask = f32(new Float32Array(n).fill(1), [1, 1, n]);
56
+ const dur = (await dp.run({ text_ids: textIds, style_dp: st.dp, text_mask: textMask })).duration.data[0] / speed;
57
+ const emb = (await enc.run({ text_ids: textIds, style_ttl: st.ttl, text_mask: textMask })).text_emb;
58
+ const len = Math.floor(dur * rate), T = Math.max(1, Math.ceil(len / chunk)), rnd = seeded(seed), lat = new Float32Array(dim * T);
59
+ for (let i = 0; i < lat.length; i++) { const u = Math.max(1e-10, rnd()), v = rnd(); lat[i] = Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v); }
60
+ let x = f32(lat, [1, dim, T]); const latMask = f32(new Float32Array(T).fill(1), [1, 1, T]), total = f32(Float32Array.of(STEPS), [1]);
61
+ for (let s = 0; s < STEPS; s++) x = f32((await est.run({ noisy_latent: x, text_emb: emb, style_ttl: st.ttl, text_mask: textMask, latent_mask: latMask, total_step: total, current_step: f32(Float32Array.of(s), [1]) })).denoised_latent.data, [1, dim, T]);
62
+ const out = (await voc.run({ latent: x })).wav_tts.data; return out.subarray(0, Math.min(len, out.length));
63
+ }
64
+ async function make(text, lang, voice, speed) { // the whole line, its pieces joined by their pauses; a piece the model returns as NaN is made once more from other noise
65
+ if (!LANGS.has(lang)) throw new Error('unknown language ' + lang);
66
+ const st = style(voice), parts = pieces(String(text).replace(/\s+/g, ' ').trim(), lang === 'ja' || lang === 'ko' ? 120 : 300), audio = [];
67
+ for (const p of parts) {
68
+ if (typeof p === 'number') { audio.push(new Float32Array(Math.round((p / speed) * rate))); continue; }
69
+ let a = await infer(p, lang, st, speed, voice + '|' + lang + '|' + p); if (!finite(a)) { a = await infer(p, lang, st, speed, 'again|' + voice + '|' + p); if (!finite(a)) throw new Error('the model returned NaN'); }
70
+ audio.push(a);
71
+ }
72
+ const all = new Float32Array(audio.reduce((n, a) => n + a.length, 0)); let at = 0; for (const a of audio) { all.set(a, at); at += a.length; } return all;
73
+ }
74
+ send({ ready: true });
75
+ for await (const line of readline.createInterface({ input: process.stdin })) {
76
+ let m; try { m = JSON.parse(line); } catch { continue; }
77
+ try { const a = await make(m.text, m.lang, m.voice, (+m.speed || 1) * 1.05); fs.writeFileSync(m.out, wav(a, rate)); send({ id: m.id, ok: true, seconds: a.length / rate }); } // 1.05: the example's pace, the model's own at speed 1
78
+ catch (e) { send({ id: m.id, ok: false, error: String((e && e.message) || e).slice(0, 200) }); }
79
+ }
80
+ }
81
+ if (require.main === module) main().catch((e) => { console.error(String((e && e.stack) || e)); process.exit(1); });
82
+ module.exports = { normalise, pieces, seeded };
package/zh-g2p.js ADDED
@@ -0,0 +1,175 @@
1
+ // Chinese text → the phonemes Kokoro-82M-v1.1-zh was trained on: a port of misaki's ZHG2P(version='1.1') (hexgrad/misaki, Apache-2.0: zh.py, zh_frontend.py and tone_sandhi.py,
2
+ // themselves adapted from PaddleSpeech, Apache-2.0) to JavaScript, on packages the Chinese voices add to the install: pinyin-pro (MIT) for pypinyin and jieba-wasm (MIT) for jieba.
3
+ // Each syllable is written as its initial and final in Zhuyin (some finals as the CJK characters misaki chose for them) and its tone (1 to 5, 5 the neutral tone), the words of a
4
+ // segment joined by '/'. Numbers are first written in Chinese (as cn2an does), punctuation is the model's, and a stretch of Latin letters goes to `en` (English phonemes).
5
+ // A Traditional text (a call held for Taiwan) is read once converted to Simplified (opencc-js, MIT and Apache-2.0). Used by kokoro-worker.js. The test against misaki's own output is test/zh-g2p.test.js.
6
+ const UNK = '❓';
7
+ // ---- cn2an.transform(text, 'an2cn'), for what an agent writes: dates, fractions, percentages, °C, plain and decimal numbers
8
+ const D = '零一二三四五六七八九';
9
+ function int2cn(s) {
10
+ s = s.replace(/^0+(?=\d)/, ''); if (/^0+$/.test(s)) return '零';
11
+ const secs = []; for (let i = s.length; i > 0; i -= 4) secs.unshift(s.slice(Math.max(0, i - 4), i));
12
+ const big = ['', '万', '亿', '万亿', '亿亿']; let out = '';
13
+ secs.forEach((g, k) => {
14
+ if (+g === 0) return; let part = '', zero = false; const p = g.padStart(4, '0');
15
+ for (let j = 0; j < 4; j++) { const d = +p[j]; if (!d) { if (part || out) zero = true; continue; } if (zero) { part += '零'; zero = false; } part += D[d] + ['千', '百', '十', ''][j]; }
16
+ out += part + big[secs.length - 1 - k];
17
+ });
18
+ return out.replace(/^一十/, '十');
19
+ }
20
+ const num2cn = (s) => { const neg = s.startsWith('-'); s = s.replace(/^-/, ''); const [a, b] = s.split('.'); return (neg ? '负' : '') + int2cn(a) + (b !== undefined ? '点' + [...b].map((d) => D[+d]).join('') : ''); };
21
+ function an2cn(t) {
22
+ t = t.replace(/%/g, '%');
23
+ t = t.replace(/(?:(\d{4}|\d{2})年)?(?:(0?[1-9]|1[0-2])月)?(?:([12]\d|3[01]|0?[1-9])日)?/g, (m, y, mo, d) => (!m || (!y && !mo && !d) ? m : (y ? [...y].map((x) => D[+x]).join('') + '年' : '') + (mo ? int2cn(mo) + '月' : '') + (d ? int2cn(d) + '日' : '')));
24
+ t = t.replace(/(\d+)\/(\d+)/g, (m, a, b) => int2cn(b) + '分之' + int2cn(a));
25
+ t = t.replace(/(-?\d+(?:\.\d+)?)%/g, (m, n) => '百分之' + num2cn(n));
26
+ t = t.replace(/(\d+(?:\.\d+)?)℃/g, (m, n) => '摄氏' + num2cn(n) + '度');
27
+ return t.replace(/-?\d+(?:\.\d+)?/g, (m) => num2cn(m));
28
+ }
29
+ const PUNCT = [['、', ', '], [',', ', '], ['。', '. '], ['.', '. '], ['!', '! '], [':', ': '], [';', '; '], ['?', '? '], ['«', ' “'], ['»', '” '], ['《', ' “'], ['》', '” '], ['「', ' “'], ['」', '” '], ['【', ' “'], ['】', '” '], ['(', ' ('], [')', ') ']];
30
+ const mapPunctuation = (t) => { for (const [a, b] of PUNCT) t = t.split(a).join(b); return t.trim(); };
31
+ // ---- pinyin, as pypinyin's strict INITIALS and FINALS_TONE3 (neutral tone 5) give it
32
+ const INITIALS = ['zh', 'ch', 'sh', 'b', 'p', 'm', 'f', 'd', 't', 'n', 'l', 'g', 'k', 'h', 'j', 'q', 'x', 'r', 'z', 'c', 's'];
33
+ const Y = { yi: 'i', ya: 'ia', ye: 'ie', yao: 'iao', you: 'iou', yan: 'ian', yin: 'in', yang: 'iang', ying: 'ing', yong: 'iong', yo: 'io', yu: 'v', yue: 've', yuan: 'van', yun: 'vn', wu: 'u', wa: 'ua', wo: 'uo', wai: 'uai', wei: 'uei', wan: 'uan', wen: 'uen', wang: 'uang', weng: 'ueng' };
34
+ function split(py) { // 'zhuang4' → ['zh', 'uang4']; a character pinyin-pro left as it is → ['', the character]
35
+ const m = /^([a-zü]+)([0-5])$/.exec(py.replace(/ü/g, 'v')); if (!m) return ['', py];
36
+ let [, s, tone] = m; if (tone === '0') tone = '5';
37
+ const ini = INITIALS.find((i) => s.startsWith(i) && s.length > i.length) || ''; let fin = s.slice(ini.length);
38
+ if (!ini) fin = Y[s] || s;
39
+ else { if ('jqx'.includes(ini)) fin = fin.replace(/^u/, 'v'); fin = fin === 'iu' ? 'iou' : fin === 'ui' ? 'uei' : fin === 'un' ? 'uen' : fin; }
40
+ if (fin === 'i' && ['z', 'c', 's'].includes(ini)) fin = 'ii'; else if (fin === 'i' && ['zh', 'ch', 'sh', 'r'].includes(ini)) fin = 'iii';
41
+ return [ini, fin + tone];
42
+ }
43
+ const ZH_MAP = { b: 'ㄅ', p: 'ㄆ', m: 'ㄇ', f: 'ㄈ', d: 'ㄉ', t: 'ㄊ', n: 'ㄋ', l: 'ㄌ', g: 'ㄍ', k: 'ㄎ', h: 'ㄏ', j: 'ㄐ', q: 'ㄑ', x: 'ㄒ', zh: 'ㄓ', ch: 'ㄔ', sh: 'ㄕ', r: 'ㄖ', z: 'ㄗ', c: 'ㄘ', s: 'ㄙ', a: 'ㄚ', o: 'ㄛ', e: 'ㄜ', ie: 'ㄝ', ai: 'ㄞ', ei: 'ㄟ', ao: 'ㄠ', ou: 'ㄡ', an: 'ㄢ', en: 'ㄣ', ang: 'ㄤ', eng: 'ㄥ', er: 'ㄦ', i: 'ㄧ', u: 'ㄨ', v: 'ㄩ', ii: 'ㄭ', iii: '十', ve: '月', ia: '压', ian: '言', iang: '阳', iao: '要', in: '阴', ing: '应', iong: '用', iou: '又', ong: '中', ua: '穵', uai: '外', uan: '万', uang: '王', uei: '为', uen: '文', ueng: '瓮', uo: '我', van: '元', vn: '云' };
44
+ for (const p of ';:,.!?/—…"()“” 12345R') ZH_MAP[p] = p;
45
+ // ---- tone sandhi (tone_sandhi.py)
46
+ const MUST_NEUTRAL = new Set('麻烦 麻利 鸳鸯 高粱 骨头 骆驼 马虎 首饰 馒头 馄饨 风筝 难为 队伍 阔气 闺女 门道 锄头 铺盖 铃铛 铁匠 钥匙 里脊 里头 部分 那么 道士 造化 迷糊 连累 这么 这个 运气 过去 软和 转悠 踏实 跳蚤 跟头 趔趄 财主 豆腐 讲究 记性 记号 认识 规矩 见识 裁缝 补丁 衣裳 衣服 衙门 街坊 行李 行当 蛤蟆 蘑菇 薄荷 葫芦 葡萄 萝卜 荸荠 苗条 苗头 苍蝇 芝麻 舒服 舒坦 舌头 自在 膏药 脾气 脑袋 脊梁 能耐 胳膊 胭脂 胡萝 胡琴 胡同 聪明 耽误 耽搁 耷拉 耳朵 老爷 老实 老婆 戏弄 将军 翻腾 罗嗦 罐头 编辑 结实 红火 累赘 糨糊 糊涂 精神 粮食 簸箕 篱笆 算计 算盘 答应 笤帚 笑语 笑话 窟窿 窝囊 窗户 稳当 稀罕 称呼 秧歌 秀气 秀才 福气 祖宗 砚台 码头 石榴 石头 石匠 知识 眼睛 眯缝 眨巴 眉毛 相声 盘算 白净 痢疾 痛快 疟疾 疙瘩 疏忽 畜生 生意 甘蔗 琵琶 琢磨 琉璃 玻璃 玫瑰 玄乎 狐狸 状元 特务 牲口 牙碜 牌楼 爽快 爱人 热闹 烧饼 烟筒 烂糊 点心 炊帚 灯笼 火候 漂亮 滑溜 溜达 温和 清楚 消息 浪头 活泼 比方 正经 欺负 模糊 槟榔 棺材 棒槌 棉花 核桃 栅栏 柴火 架势 枕头 枇杷 机灵 本事 木头 木匠 朋友 月饼 月亮 暖和 明白 时候 新鲜 故事 收拾 收成 提防 挖苦 挑剔 指甲 指头 拾掇 拳头 拨弄 招牌 招呼 抬举 护士 折腾 扫帚 打量 打算 打扮 打听 打发 扎实 扁担 戒指 懒得 意识 意思 悟性 怪物 思量 怎么 念头 念叨 别人 快活 忙活 志气 心思 得罪 张罗 弟兄 开通 应酬 庄稼 干事 帮手 帐篷 希罕 师父 师傅 巴结 巴掌 差事 工夫 岁数 屁股 尾巴 少爷 小气 小伙 将就 对头 对付 寡妇 家伙 客气 实在 官司 学问 字号 嫁妆 媳妇 媒人 婆家 娘家 委屈 姑娘 姐夫 妯娌 妥当 妖精 奴才 女婿 头发 太阳 大爷 大方 大意 大夫 多少 多么 外甥 壮实 地道 地方 在乎 困难 嘴巴 嘱咐 嘟囔 嘀咕 喜欢 喇嘛 喇叭 商量 唾沫 哑巴 哈欠 哆嗦 咳嗽 和尚 告诉 告示 含糊 吓唬 后头 名字 名堂 合同 吆喝 叫唤 口袋 厚道 厉害 千斤 包袱 包涵 匀称 勤快 动静 动弹 功夫 力气 前头 刺猬 刺激 别扭 利落 利索 利害 分析 出息 凑合 凉快 冷战 冤枉 冒失 养活 关系 先生 兄弟 便宜 使唤 佩服 作坊 体面 位置 似的 伙计 休息 什么 人家 亲戚 亲家 交情 云彩 事情 买卖 主意 丫头 丧气 两口 东西 东家 世故 不由 下水 下巴 上头 上司 丈夫 丈人 一辈 那个 菩萨 父亲 母亲 咕噜 邋遢 费用 冤家 甜头 介绍 荒唐 大人 泥鳅 幸福 熟悉 计划 扑腾 蜡烛 姥爷 照顾 喉咙 吉他 弄堂 蚂蚱 凤凰 拖沓 寒碜 糟蹋 倒腾 报复 逻辑 盘缠 喽啰 牢骚 咖喱 扫把 惦记'.split(' '));
47
+ const MUST_NOT_NEUTRAL = new Set('男子 女子 分子 原子 量子 莲子 石子 瓜子 电子 人人 虎虎 幺幺 干嘛 学子 哈哈 数数 袅袅 局地 以下 娃哈哈 花花草草 留得 耕地 想想 熙熙 攘攘 卵子 死死 冉冉 恳恳 佼佼 吵吵 打打 考考 整整 莘莘 落地 算子 家家户户 青青'.split(' '));
48
+ const SANDHI_PUNC = '、:,;。?!“”‘’\':,;.?!', X_ENG = new Set(['x', 'eng']);
49
+ const numeric = (c) => /\p{N}/u.test(c) || '零一二三四五六七八九十百千万亿两〇壹贰叁肆伍陆柒捌玖拾佰仟'.includes(c); // Python's str.isnumeric() is true for the Chinese numerals too
50
+ const set5 = (f) => f.slice(0, -1) + '5', setT = (f, t) => f.slice(0, -1) + t, allThree = (fs) => fs.every((x) => x.endsWith('3'));
51
+ const MUST_ERHUA = new Set(['小院儿', '胡同儿', '范儿', '老汉儿', '撒欢儿', '寻老礼儿', '妥妥儿', '媳妇儿']);
52
+ const NOT_ERHUA = new Set('虐儿 为儿 护儿 瞒儿 救儿 替儿 有儿 一儿 我儿 俺儿 妻儿 拐儿 聋儿 乞儿 患儿 幼儿 孤儿 婴儿 婴幼儿 连体儿 脑瘫儿 流浪儿 体弱儿 混血儿 蜜雪儿 舫儿 祖儿 美儿 应采儿 可儿 侄儿 孙儿 侄孙儿 女儿 男儿 红孩儿 花儿 虫儿 马儿 鸟儿 猪儿 猫儿 狗儿 少儿'.split(' '));
53
+ const PHRASES = { 开户行: ['kai1', 'hu4', 'hang2'], 发卡行: ['fa4', 'ka3', 'hang2'], 放款行: ['fang4', 'kuan3', 'hang2'], 茧行: ['jian3', 'hang2'], 行号: ['hang2', 'hao4'], 各地: ['ge4', 'di4'], 借还款: ['jie4', 'huan2', 'kuan3'], 时间为: ['shi2', 'jian1', 'wei2'], 为准: ['wei2', 'zhun3'], 色差: ['se4', 'cha1'], 嗲: ['dia3'], 呗: ['bei5'], 不: ['bu4'], 咗: ['zuo5'], 嘞: ['lei5'], 掺和: ['chan1', 'huo5'] }; // misaki's own corrections to pypinyin
54
+
55
+ function make(pinyinPro, jieba, t2s, { CONTEXT = true, HMM = true } = {}) { // t2s: Traditional → Simplified (opencc-js), the same sounds in the characters pinyin-pro and jieba know best (還 hai, 車 che, 麼 me)
56
+ const PY = { toneType: 'num', type: 'array', toneSandhi: false, v: true }; let ctx = null; // ctx: the pinyin of the whole stretch, read once with its context, which pinyin-pro needs to pick the reading of a character alone (了 le, 只 zhi3)
57
+ const pys = (word, at) => { // one pinyin per character, without pinyin-pro's own tone sandhi (applied below, as misaki does); '地' alone is de (load_single_dict)
58
+ if (PHRASES[word]) return PHRASES[word].slice();
59
+ const w = [...word], out = ctx && at != null && ctx.text.slice(at, at + w.length).join('') === word ? ctx.py.slice(at, at + w.length) : pinyinPro.pinyin(word, PY);
60
+ return w.map((c, i) => (c === '嗯' ? 'n2' : word === '地' ? 'de5' : out[i] || c));
61
+ };
62
+ const finalsOf = (word, at) => pys(word, at).map((p) => split(p)[1]);
63
+ const splitWord = (word) => { // _split_word: the shortest search segment, and what is left of the word
64
+ const list = jieba.cut_for_search(word, true).sort((a, b) => a.length - b.length), first = list[0];
65
+ return word.indexOf(first) === 0 ? [first, word.slice(first.length)] : [word.slice(0, -first.length), first];
66
+ };
67
+ function neutral(word, pos, f) {
68
+ if (MUST_NOT_NEUTRAL.has(word)) return f;
69
+ const w = [...word];
70
+ w.forEach((c, j) => { if (j >= 1 && c === w[j - 1] && 'nva'.includes(pos[0])) f[j] = set5(f[j]); });
71
+ const ge = w.indexOf('个'), last = w[w.length - 1];
72
+ if ('吧呢啊呐噻嘛吖嗨呐哦哒滴哩哟喽啰耶喔诶'.includes(last)) f[f.length - 1] = set5(f[f.length - 1]);
73
+ else if ('的地得'.includes(last)) f[f.length - 1] = set5(f[f.length - 1]);
74
+ else if (w.length === 1 && '了着过'.includes(word) && ['ul', 'uz', 'ug'].includes(pos)) f[f.length - 1] = set5(f[f.length - 1]);
75
+ else if (w.length > 1 && '们子'.includes(last) && ['r', 'n'].includes(pos)) f[f.length - 1] = set5(f[f.length - 1]);
76
+ else if (w.length > 1 && '上下'.includes(last) && ['s', 'l', 'f'].includes(pos)) f[f.length - 1] = set5(f[f.length - 1]);
77
+ else if (w.length > 1 && '来去'.includes(last) && '上下进出回过起开'.includes(w[w.length - 2])) f[f.length - 1] = set5(f[f.length - 1]);
78
+ else if ((ge >= 1 && (numeric(w[ge - 1]) || '几有两半多各整每做是'.includes(w[ge - 1]))) || word === '个') f[ge] = set5(f[ge]);
79
+ else if (MUST_NEUTRAL.has(word) || MUST_NEUTRAL.has(w.slice(-2).join(''))) f[f.length - 1] = set5(f[f.length - 1]);
80
+ const parts = splitWord(word), n0 = [...parts[0]].length, fl = [f.slice(0, n0), f.slice(n0)];
81
+ parts.forEach((p, i) => { const pw = [...p]; if (fl[i].length && (MUST_NEUTRAL.has(p) || MUST_NEUTRAL.has(pw.slice(-2).join('')))) fl[i][fl[i].length - 1] = set5(fl[i][fl[i].length - 1]); });
82
+ return fl[0].concat(fl[1]);
83
+ }
84
+ function bu(word, f) {
85
+ const w = [...word];
86
+ if (w.length === 3 && w[1] === '不') f[1] = set5(f[1]);
87
+ else w.forEach((c, i) => { if (c === '不' && i + 1 < w.length && f[i + 1].endsWith('4')) f[i] = setT(f[i], '2'); });
88
+ return f;
89
+ }
90
+ function yi(word, f) {
91
+ const w = [...word];
92
+ if (w.includes('一') && w.filter((c) => c !== '一').every(numeric)) return f;
93
+ if (w.length === 3 && w[1] === '一' && w[0] === w[2]) f[1] = set5(f[1]);
94
+ else if (word.startsWith('第一')) f[1] = setT(f[1], '1');
95
+ else w.forEach((c, i) => { if (c === '一' && i + 1 < w.length) { if ('45'.includes(f[i + 1].slice(-1))) f[i] = setT(f[i], '2'); else if (!SANDHI_PUNC.includes(w[i + 1])) f[i] = setT(f[i], '4'); } });
96
+ return f;
97
+ }
98
+ function three(word, f) {
99
+ const n = [...word].length;
100
+ if (n === 2 && allThree(f)) f[0] = setT(f[0], '2');
101
+ else if (n === 3) {
102
+ const parts = splitWord(word), n0 = [...parts[0]].length;
103
+ if (allThree(f)) { if (n0 === 2) { f[0] = setT(f[0], '2'); f[1] = setT(f[1], '2'); } else if (n0 === 1) f[1] = setT(f[1], '2'); }
104
+ else {
105
+ const fl = [f.slice(0, n0), f.slice(n0)];
106
+ fl.forEach((sub, i) => {
107
+ if (allThree(sub) && sub.length === 2) sub[0] = setT(sub[0], '2');
108
+ else if (i === 1 && !allThree(sub) && sub[0] && sub[0].endsWith('3') && fl[0].length && fl[0][fl[0].length - 1].endsWith('3')) fl[0][fl[0].length - 1] = setT(fl[0][fl[0].length - 1], '2');
109
+ });
110
+ f = fl[0].concat(fl[1]);
111
+ }
112
+ } else if (n === 4) { const fl = [f.slice(0, 2), f.slice(2)]; f = []; for (const sub of fl) { if (allThree(sub)) sub[0] = setT(sub[0], '2'); f.push(...sub); } }
113
+ return f;
114
+ }
115
+ const modified = (word, pos, f) => three(word, neutral(word, pos, yi(word, bu(word, f))));
116
+ // pre_merge_for_modify: words merged before the sandhi, so that it sees them whole
117
+ function premerge(seg) { // seg: [word, pos, offset of its first character]
118
+ let s = [];
119
+ seg.forEach(([w, p, at], i) => { if (!X_ENG.has(p) && i > 0 && seg[i - 1][0] === '不') { w = '不' + w; at = seg[i - 1][2]; } const np = i + 1 < seg.length ? seg[i + 1][1] : null; if (w !== '不' || np === null || X_ENG.has(np)) s.push([w, p, at]); });
120
+ seg = s; s = []; let skip = false;
121
+ seg.forEach(([w, p, at], i) => { if (skip) { skip = false; return; } if (i >= 1 && w === '一' && i + 1 < seg.length && seg[i - 1][0] === seg[i + 1][0] && seg[i - 1][1] === 'v' && !X_ENG.has(seg[i + 1][1])) { s[s.length - 1] = [s[s.length - 1][0] + '一' + seg[i + 1][0], s[s.length - 1][1], s[s.length - 1][2]]; skip = true; } else s.push([w, p, at]); });
122
+ seg = s; s = [];
123
+ seg.forEach(([w, p, at]) => { if (s.length && s[s.length - 1][0] === '一' && !X_ENG.has(p)) s[s.length - 1] = [s[s.length - 1][0] + w, s[s.length - 1][1], s[s.length - 1][2]]; else s.push([w, p, at]); });
124
+ seg = s; s = [];
125
+ seg.forEach(([w, p, at]) => { if (s.length && w === s[s.length - 1][0] && !X_ENG.has(p)) s[s.length - 1][0] += w; else s.push([w, p, at]); });
126
+ const redup = (w) => [...w].length === 2 && [...w][0] === [...w][1];
127
+ for (const rule of [(a, b) => allThree(a) && allThree(b), (a, b) => a[a.length - 1].endsWith('3') && b[0].endsWith('3')]) {
128
+ seg = s; s = []; const fl = seg.map(([w, p, at]) => (X_ENG.has(p) ? ['0'] : finalsOf(w, at))), merged = seg.map(() => false);
129
+ seg.forEach(([w, p, at], i) => {
130
+ if (!X_ENG.has(p) && i >= 1 && rule(fl[i - 1], fl[i]) && !merged[i - 1] && !redup(seg[i - 1][0]) && [...seg[i - 1][0]].length + [...w].length <= 3) { s[s.length - 1][0] += w; merged[i] = true; }
131
+ else s.push([w, p, at]);
132
+ });
133
+ }
134
+ seg = s; s = [];
135
+ seg.forEach(([w, p, at], i) => { if (i >= 1 && w === '儿' && !X_ENG.has(s[s.length - 1][1])) s[s.length - 1][0] += w; else s.push([w, p, at]); });
136
+ return s;
137
+ }
138
+ function erhua(ini, fin, word, pos) {
139
+ const w = [...word];
140
+ fin.forEach((ph, i) => { if (i === fin.length - 1 && w[i] === '儿' && ph === 'er1') fin[i] = 'er2'; });
141
+ if (!MUST_ERHUA.has(word) && (NOT_ERHUA.has(word) || ['a', 'j', 'nr'].includes(pos))) return [ini, fin];
142
+ if (fin.length !== w.length) return [ini, fin];
143
+ const ni = [], nf = [];
144
+ fin.forEach((ph, i) => { if (i === fin.length - 1 && w[i] === '儿' && ['er2', 'er5'].includes(ph) && !NOT_ERHUA.has(w.slice(-2).join('')) && nf.length) nf[nf.length - 1] = nf[nf.length - 1].slice(0, -1) + 'R' + nf[nf.length - 1].slice(-1); else { ni.push(ini[i]); nf.push(ph); } });
145
+ return [ni, nf];
146
+ }
147
+ const PUNC = new Set([...';:,.!?—…"()“”']);
148
+ function frontend(text) { // ZHFrontend.__call__
149
+ const toks = [], tags = jieba.tag(text, HMM); let off = 0; const seg = tags.map((t) => { const at = off; off += [...t.word].length; return [t.word, t.tag, at]; });
150
+ ctx = CONTEXT ? { text: [...text], py: pinyinPro.pinyin(text, PY) } : null;
151
+ for (let [word, pos, at] of premerge(seg)) {
152
+ const han = [...word].every((c) => c >= '一' && c <= '鿿');
153
+ if (pos === 'x' && han) pos = 'X'; else if (pos !== 'x' && PUNC.has(word)) pos = 'x';
154
+ const tk = { text: word, tag: pos, ws: '', ph: null };
155
+ if (pos === 'x' || pos === 'eng') { if (word.trim()) { if (pos === 'x' && PUNC.has(word)) tk.ph = word; toks.push(tk); } else if (toks.length) toks[toks.length - 1].ws += word; continue; }
156
+ else if (toks.length && !X_ENG.has(toks[toks.length - 1].tag) && !toks[toks.length - 1].ws) toks[toks.length - 1].ws = '/';
157
+ const p = pys(word, at).map(split); let ini = p.map((x) => x[0]), fin = p.map((x) => x[1]);
158
+ fin = modified(word, pos, fin); [ini, fin] = erhua(ini, fin, word, pos);
159
+ const phones = []; ini.forEach((c, i) => { const v = fin[i]; if (c) phones.push(c); if (v && (!PUNC.has(v) || v !== c)) phones.push(v); });
160
+ tk.ph = phones.join('_').replace(/_eR/g, '_er').replace(/R/g, '_R').replace(/(?=\d)/g, '_').split('_').map((x) => ZH_MAP[x] ?? UNK).join('');
161
+ toks.push(tk);
162
+ }
163
+ return toks.map((t) => (t.ph === null ? UNK : t.ph) + t.ws).join('');
164
+ }
165
+ return async function g2p(text, en) { // ZHG2P.__call__ (version 1.1); en: a stretch of Latin letters → its phonemes
166
+ if (!text.trim()) return '';
167
+ text = mapPunctuation(an2cn(t2s ? t2s(text) : text)); const out = [];
168
+ for (const m of text.matchAll(/([A-Za-z '-]*[A-Za-z][A-Za-z '-]*)|([^A-Za-z]+)/g)) {
169
+ const e = (m[1] || '').trim(), z = (m[2] || '').trim();
170
+ if (z) out.push(frontend(z)); else if (e) out.push(en ? await en(e) : UNK);
171
+ }
172
+ return out.join(' ');
173
+ };
174
+ }
175
+ module.exports = { make, an2cn, split, UNK };