polyergon 0.1.4 → 0.1.5

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 (141) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-build-manifest.json +16 -16
  3. package/.next/app-path-routes-manifest.json +1 -1
  4. package/.next/build-manifest.json +8 -8
  5. package/.next/next-minimal-server.js.nft.json +1 -1
  6. package/.next/next-server.js.nft.json +1 -1
  7. package/.next/prerender-manifest.json +1 -1
  8. package/.next/react-loadable-manifest.json +3 -3
  9. package/.next/required-server-files.json +1 -1
  10. package/.next/server/app/_not-found/page.js +1 -1
  11. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  12. package/.next/server/app/_not-found.html +1 -1
  13. package/.next/server/app/_not-found.rsc +1 -1
  14. package/.next/server/app/api/automations/existing/route.js +1 -1
  15. package/.next/server/app/api/backends/route.js +1 -1
  16. package/.next/server/app/api/diff/route.js +1 -1
  17. package/.next/server/app/api/limits/route.js +1 -1
  18. package/.next/server/app/api/meetings/[id]/route.js +1 -1
  19. package/.next/server/app/api/meetings/[id]/slack/route.js +2 -2
  20. package/.next/server/app/api/meetings/library/route.js +1 -1
  21. package/.next/server/app/api/meetings/route.js +1 -1
  22. package/.next/server/app/api/models/route.js +1 -1
  23. package/.next/server/app/api/notes/route.js +1 -1
  24. package/.next/server/app/api/orgs/[id]/route.js +1 -1
  25. package/.next/server/app/api/orgs/route.js +1 -1
  26. package/.next/server/app/api/pick-folder/route.js +1 -0
  27. package/.next/server/app/api/pick-folder/route.js.nft.json +1 -0
  28. package/.next/server/app/api/prs/inbox/route.js +1 -1
  29. package/.next/server/app/api/prs/refresh/route.js +1 -1
  30. package/.next/server/app/api/prs/route.js +1 -1
  31. package/.next/server/app/api/session-names/route.js +1 -1
  32. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  33. package/.next/server/app/api/sessions/route.js +1 -1
  34. package/.next/server/app/api/settings/auth/route.js +1 -1
  35. package/.next/server/app/api/settings/route.js +1 -1
  36. package/.next/server/app/api/settings/transcription/local/route.js +1 -0
  37. package/.next/server/app/api/settings/transcription/local/route.js.nft.json +1 -0
  38. package/.next/server/app/api/settings/transcription/route.js +1 -1
  39. package/.next/server/app/api/skills/[name]/route.js +2 -2
  40. package/.next/server/app/api/skills/marketplace/route.js +2 -2
  41. package/.next/server/app/api/skills/route.js +2 -2
  42. package/.next/server/app/api/skills/view/route.js +2 -2
  43. package/.next/server/app/api/slack/channels/route.js +1 -1
  44. package/.next/server/app/api/slack/configured/route.js +1 -1
  45. package/.next/server/app/api/slack/inbox/route.js +1 -1
  46. package/.next/server/app/api/tasks/route.js +1 -1
  47. package/.next/server/app/api/usage/route.js +1 -1
  48. package/.next/server/app/demo/page.js +1 -1
  49. package/.next/server/app/demo/page.js.nft.json +1 -1
  50. package/.next/server/app/demo/page_client-reference-manifest.js +1 -1
  51. package/.next/server/app/demo.html +1 -1
  52. package/.next/server/app/demo.rsc +2 -2
  53. package/.next/server/app/favicon.ico/route.js +2 -2
  54. package/.next/server/app/index.html +1 -1
  55. package/.next/server/app/index.rsc +2 -2
  56. package/.next/server/app/page.js +3 -3
  57. package/.next/server/app/page.js.nft.json +1 -1
  58. package/.next/server/app/page_client-reference-manifest.js +1 -1
  59. package/.next/server/app-paths-manifest.json +17 -15
  60. package/.next/server/chunks/36.js +1 -1
  61. package/.next/server/chunks/471.js +1 -1
  62. package/.next/server/chunks/474.js +1 -0
  63. package/.next/server/chunks/590.js +1 -1
  64. package/.next/server/chunks/621.js +1 -1
  65. package/.next/server/functions-config-manifest.json +1 -1
  66. package/.next/server/middleware-build-manifest.js +1 -1
  67. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  68. package/.next/server/pages/404.html +1 -1
  69. package/.next/server/pages/500.html +1 -1
  70. package/.next/server/server-reference-manifest.json +1 -1
  71. package/.next/static/chunks/{235.aef4cdc783360b73.js → 235.ea131d1a8ad571fe.js} +1 -1
  72. package/.next/static/chunks/682-f14325e9764fa3ef.js +1 -0
  73. package/.next/static/chunks/app/demo/{page-7420731cd3533884.js → page-2f850214701ce480.js} +1 -1
  74. package/.next/static/chunks/app/layout-3f109cf2eddaaad9.js +1 -0
  75. package/.next/static/chunks/app/page-dcbcf242a4a56fc7.js +1 -0
  76. package/.next/static/chunks/e868780c.3a02ccb3e7ac46be.js +18 -0
  77. package/.next/static/chunks/{main-e88dbd51c3bdafca.js → main-91e15570e34d95e9.js} +1 -1
  78. package/.next/static/chunks/main-app-bfc83ad35f0351b5.js +1 -0
  79. package/.next/static/chunks/webpack-e26c509879d51b83.js +1 -0
  80. package/.next/static/css/aea575e52126f68c.css +1 -0
  81. package/.next/static/css/ef597e1c0fb510ac.css +3 -0
  82. package/.next/trace +23 -23
  83. package/.next/types/app/api/automations/existing/route.ts +1 -1
  84. package/.next/types/app/api/backends/route.ts +1 -1
  85. package/.next/types/app/api/diff/route.ts +1 -1
  86. package/.next/types/app/api/limits/route.ts +1 -1
  87. package/.next/types/app/api/meetings/[id]/route.ts +1 -1
  88. package/.next/types/app/api/meetings/[id]/slack/route.ts +1 -1
  89. package/.next/types/app/api/meetings/library/route.ts +1 -1
  90. package/.next/types/app/api/meetings/route.ts +1 -1
  91. package/.next/types/app/api/models/route.ts +1 -1
  92. package/.next/types/app/api/notes/route.ts +1 -1
  93. package/.next/types/app/api/orgs/[id]/route.ts +1 -1
  94. package/.next/types/app/api/orgs/route.ts +1 -1
  95. package/.next/types/app/api/pick-folder/route.ts +343 -0
  96. package/.next/types/app/api/prs/inbox/route.ts +1 -1
  97. package/.next/types/app/api/prs/refresh/route.ts +1 -1
  98. package/.next/types/app/api/prs/route.ts +1 -1
  99. package/.next/types/app/api/session-names/route.ts +1 -1
  100. package/.next/types/app/api/sessions/[id]/route.ts +1 -1
  101. package/.next/types/app/api/sessions/route.ts +1 -1
  102. package/.next/types/app/api/settings/auth/route.ts +1 -1
  103. package/.next/types/app/api/settings/route.ts +1 -1
  104. package/.next/types/app/api/settings/transcription/local/route.ts +343 -0
  105. package/.next/types/app/api/settings/transcription/route.ts +1 -1
  106. package/.next/types/app/api/skills/[name]/route.ts +1 -1
  107. package/.next/types/app/api/skills/marketplace/route.ts +1 -1
  108. package/.next/types/app/api/skills/route.ts +1 -1
  109. package/.next/types/app/api/skills/view/route.ts +1 -1
  110. package/.next/types/app/api/slack/channels/route.ts +1 -1
  111. package/.next/types/app/api/slack/configured/route.ts +1 -1
  112. package/.next/types/app/api/slack/inbox/route.ts +1 -1
  113. package/.next/types/app/api/tasks/route.ts +1 -1
  114. package/.next/types/app/api/usage/route.ts +1 -1
  115. package/.next/types/app/demo/page.ts +1 -1
  116. package/.next/types/app/layout.ts +1 -1
  117. package/.next/types/app/page.ts +1 -1
  118. package/.server-dist/server.js +48 -11
  119. package/.server-dist/src/lib/backends.js +3 -1
  120. package/.server-dist/src/lib/localWhisper.js +80 -0
  121. package/.server-dist/src/lib/meetingConfig.js +10 -1
  122. package/.server-dist/src/lib/meetingManager.js +13 -6
  123. package/.server-dist/src/lib/pipelines.js +51 -9
  124. package/.server-dist/src/lib/ptyManager.js +47 -11
  125. package/.server-dist/src/lib/slackBridge.js +1 -0
  126. package/.server-dist/src/lib/slackWatchers.js +62 -13
  127. package/.server-dist/src/lib/transcriber.js +3 -0
  128. package/.server-dist/tsconfig.server.tsbuildinfo +1 -1
  129. package/README.md +7 -5
  130. package/package.json +3 -3
  131. package/.next/server/chunks/230.js +0 -1
  132. package/.next/static/chunks/30d07d85.9045c666bb43d9e1.js +0 -3
  133. package/.next/static/chunks/682-08ba9b4d06999826.js +0 -1
  134. package/.next/static/chunks/app/layout-d4e0e8009d3c2d10.js +0 -1
  135. package/.next/static/chunks/app/page-f59a702198ab6800.js +0 -1
  136. package/.next/static/chunks/main-app-bcfbc1d8b71a1721.js +0 -1
  137. package/.next/static/chunks/webpack-1f89b7cb1fca69c4.js +0 -1
  138. package/.next/static/css/4e20bb95d8c93645.css +0 -3
  139. package/.next/static/css/ab3e4b0f5035257a.css +0 -1
  140. /package/.next/static/{sHKtMJhzMf5r2iknSwAAE → DNZuK4bG0htvuqEt2cGuw}/_buildManifest.js +0 -0
  141. /package/.next/static/{sHKtMJhzMf5r2iknSwAAE → DNZuK4bG0htvuqEt2cGuw}/_ssgManifest.js +0 -0
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOCAL_MODEL_PATH = void 0;
4
+ exports.localWhisperProblem = localWhisperProblem;
5
+ exports.localWhisperStatus = localWhisperStatus;
6
+ exports.downloadLocalModel = downloadLocalModel;
7
+ exports.transcribeLocal = transcribeLocal;
8
+ const child_process_1 = require("child_process");
9
+ const fs_1 = require("fs");
10
+ const path_1 = require("path");
11
+ const stream_1 = require("stream");
12
+ const promises_1 = require("stream/promises");
13
+ const dataDir_1 = require("./dataDir");
14
+ // Local, offline transcription with whisper.cpp (`brew install whisper-cpp`).
15
+ // large-v3-turbo (q5_0) is ~550 MB, fast on Apple Silicon, good with Hebrew.
16
+ const MODEL_FILE = 'ggml-large-v3-turbo-q5_0.bin';
17
+ const MODEL_URL = `https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${MODEL_FILE}`;
18
+ exports.LOCAL_MODEL_PATH = (0, path_1.join)(dataDir_1.DATA_DIR, 'whisper', MODEL_FILE);
19
+ const CLI = 'whisper-cli';
20
+ let download = null;
21
+ function cliInstalled() {
22
+ return new Promise(resolve => (0, child_process_1.execFile)('which', [CLI], err => resolve(!err)));
23
+ }
24
+ // Why local transcription can't run right now, or null when it can.
25
+ function localWhisperProblem() {
26
+ try {
27
+ (0, child_process_1.execFileSync)('which', [CLI], { stdio: 'ignore' });
28
+ }
29
+ catch (_a) {
30
+ return 'Local Whisper is not installed. In Terminal run: brew install whisper-cpp';
31
+ }
32
+ if (!(0, fs_1.existsSync)(exports.LOCAL_MODEL_PATH))
33
+ return 'The Whisper model is not downloaded yet. Open Settings → Meetings and click Download model.';
34
+ return null;
35
+ }
36
+ async function localWhisperStatus() {
37
+ var _a;
38
+ return {
39
+ cli: await cliInstalled(),
40
+ model: (0, fs_1.existsSync)(exports.LOCAL_MODEL_PATH),
41
+ downloading: download && !download.error ? (download.total ? Math.floor(download.done / download.total * 100) : 0) : null,
42
+ error: (_a = download === null || download === void 0 ? void 0 : download.error) !== null && _a !== void 0 ? _a : null,
43
+ };
44
+ }
45
+ // Starts the model download in the background; status reports progress.
46
+ function downloadLocalModel() {
47
+ if ((0, fs_1.existsSync)(exports.LOCAL_MODEL_PATH) || (download && !download.error))
48
+ return;
49
+ download = { done: 0, total: 0, error: null };
50
+ const d = download;
51
+ const part = exports.LOCAL_MODEL_PATH + '.part';
52
+ (0, fs_1.mkdirSync)((0, path_1.join)(dataDir_1.DATA_DIR, 'whisper'), { recursive: true });
53
+ (async () => {
54
+ const res = await fetch(MODEL_URL);
55
+ if (!res.ok || !res.body)
56
+ throw new Error(`Download failed (${res.status})`);
57
+ d.total = Number(res.headers.get('content-length')) || 0;
58
+ const body = stream_1.Readable.fromWeb(res.body);
59
+ body.on('data', (c) => { d.done += c.length; });
60
+ await (0, promises_1.pipeline)(body, (0, fs_1.createWriteStream)(part));
61
+ if (d.total && (0, fs_1.statSync)(part).size !== d.total)
62
+ throw new Error('Download incomplete');
63
+ (0, fs_1.renameSync)(part, exports.LOCAL_MODEL_PATH);
64
+ download = null;
65
+ })().catch(e => { d.error = e instanceof Error ? e.message : 'Download failed'; });
66
+ }
67
+ // Transcribes one WAV chunk. `prompt` (earlier transcript) keeps language and terms consistent.
68
+ function transcribeLocal(file, prompt) {
69
+ const args = ['-m', exports.LOCAL_MODEL_PATH, '-f', file, '-l', 'auto', '-nt', '-np'];
70
+ if (prompt)
71
+ args.push('--prompt', prompt.slice(-800));
72
+ return new Promise((resolve, reject) => {
73
+ (0, child_process_1.execFile)(CLI, args, { timeout: 120000, maxBuffer: 4 * 1024 * 1024 }, (err, stdout) => {
74
+ if (err)
75
+ return reject(new Error(`whisper-cli failed: ${err.message.slice(0, 200)}`));
76
+ const text = stdout.replace(/\s+/g, ' ').trim();
77
+ resolve(text && !/^\[(BLANK_AUDIO|MUSIC|SILENCE)\]$/i.test(text) ? text : null);
78
+ });
79
+ });
80
+ }
@@ -5,10 +5,13 @@ exports.getTranscriptionStatus = getTranscriptionStatus;
5
5
  exports.saveTranscriptionConfig = saveTranscriptionConfig;
6
6
  exports.getAudioDevices = getAudioDevices;
7
7
  const configFile_1 = require("./configFile");
8
+ const localWhisper_1 = require("./localWhisper");
8
9
  // Azure (AI Foundry deployment) takes precedence when configured; plain
9
10
  // OpenAI key works as before.
10
11
  function getTranscriptionConfig(file = configFile_1.CONFIG_FILE) {
11
12
  const cfg = (0, configFile_1.readConfig)(file);
13
+ if (cfg.transcriptionProvider === 'local')
14
+ return { kind: 'local', model: localWhisper_1.LOCAL_MODEL_PATH };
12
15
  const { azureEndpoint, azureApiKey, azureDeployment } = cfg;
13
16
  if (typeof azureEndpoint === 'string' && azureEndpoint && typeof azureApiKey === 'string' && azureApiKey) {
14
17
  return {
@@ -28,6 +31,8 @@ function getTranscriptionStatus(file = configFile_1.CONFIG_FILE) {
28
31
  const hint = (k) => '…' + k.slice(-4);
29
32
  if (!c)
30
33
  return { provider: null, keyHint: null, fromEnv: false, endpoint: null, deployment: null };
34
+ if (c.kind === 'local')
35
+ return { provider: 'local', keyHint: null, fromEnv: false, endpoint: null, deployment: null };
31
36
  if (c.kind === 'azure')
32
37
  return { provider: 'azure', keyHint: hint(c.apiKey), fromEnv: false, endpoint: c.endpoint, deployment: c.deployment };
33
38
  return { provider: 'openai', keyHint: hint(c.apiKey), fromEnv: !(0, configFile_1.readConfig)(file).openaiApiKey, endpoint: null, deployment: null };
@@ -37,7 +42,11 @@ function getTranscriptionStatus(file = configFile_1.CONFIG_FILE) {
37
42
  function saveTranscriptionConfig(input, file = configFile_1.CONFIG_FILE) {
38
43
  const cfg = (0, configFile_1.readConfig)(file);
39
44
  const str = (v) => (typeof v === 'string' ? v.trim() : '');
40
- if (input.provider === 'none') {
45
+ delete cfg.transcriptionProvider; // only 'local' sets it; saved keys stay for switching back
46
+ if (input.provider === 'local') {
47
+ cfg.transcriptionProvider = 'local';
48
+ }
49
+ else if (input.provider === 'none') {
41
50
  for (const k of ['azureEndpoint', 'azureApiKey', 'azureDeployment', 'openaiApiKey'])
42
51
  delete cfg[k];
43
52
  }
@@ -9,8 +9,15 @@ const audioCapture_1 = require("./audioCapture");
9
9
  const transcriber_1 = require("./transcriber");
10
10
  const meetingAssistant_1 = require("./meetingAssistant");
11
11
  const meetingConfig_1 = require("./meetingConfig");
12
+ const localWhisper_1 = require("./localWhisper");
12
13
  const orgRegistry_1 = require("./orgRegistry");
13
14
  const NOTES_TICK_MS = 90000;
15
+ function transcriptionProblem() {
16
+ const c = (0, meetingConfig_1.getTranscriptionConfig)();
17
+ if (!c)
18
+ return 'Transcription not configured: open Settings → Meetings and choose OpenAI, Azure OpenAI or Local Whisper.';
19
+ return c.kind === 'local' ? (0, localWhisper_1.localWhisperProblem)() : null;
20
+ }
14
21
  class MeetingManager {
15
22
  constructor() {
16
23
  this.active = new Map();
@@ -30,18 +37,18 @@ class MeetingManager {
30
37
  return (0, audioCapture_1.micTest)((0, meetingConfig_1.getAudioDevices)());
31
38
  }
32
39
  start(title, orgId) {
33
- if (!(0, meetingConfig_1.getTranscriptionConfig)()) {
34
- return { error: 'Transcription not configured: open Settings → Meeting transcription and add an OpenAI or Azure OpenAI key.' };
35
- }
40
+ const notReady = transcriptionProblem();
41
+ if (notReady)
42
+ return { error: notReady };
36
43
  return this.begin(meetingStore_1.meetingStore.create(title, orgId || orgRegistry_1.DEFAULT_ORG_ID));
37
44
  }
38
45
  // Continue an ended/interrupted meeting: same transcript, notes and assistant
39
46
  // conversation; new audio is appended. The summary is rewritten on stop.
40
47
  resume(meetingId) {
41
48
  var _a;
42
- if (!(0, meetingConfig_1.getTranscriptionConfig)()) {
43
- return { error: 'Transcription not configured: open Settings → Meeting transcription and add an OpenAI or Azure OpenAI key.' };
44
- }
49
+ const notReady = transcriptionProblem();
50
+ if (notReady)
51
+ return { error: notReady };
45
52
  const existing = meetingStore_1.meetingStore.get(meetingId);
46
53
  if (!existing)
47
54
  return { error: 'Meeting not found' };
@@ -222,25 +222,58 @@ class PipelineEngine {
222
222
  return p;
223
223
  }
224
224
  // Track another PR on a running automation (from the dialog).
225
- addPr(id, url) {
225
+ addPr(id, url, review) {
226
226
  const p = this.items.find(x => x.id === id);
227
227
  if (!p || !pipelineView_2.ACTIVE_PHASES.includes(p.phase))
228
228
  return { error: 'Automation is not running' };
229
229
  if (!(0, ghPrStatus_1.isValidPrUrl)(url))
230
230
  return { error: 'Not a GitHub pull request URL' };
231
- this.addTrack(p, url, 'You added');
231
+ this.addTrack(p, url, 'You added', cleanReview(review));
232
232
  this.step(p.id, true);
233
233
  return null;
234
234
  }
235
- addTrack(p, url, why) {
235
+ // Change one PR's review setup: posts to the new channel and requests the new reviewers.
236
+ setPrReview(id, url, review) {
237
+ var _a, _b;
238
+ const p = this.items.find(x => x.id === id);
239
+ const t = p === null || p === void 0 ? void 0 : p.prs.find(x => x.url === url);
240
+ if (!p || !t)
241
+ return { error: 'PR not found' };
242
+ const next = cleanReview(review);
243
+ const before = (_a = t.review) !== null && _a !== void 0 ? _a : { channel: p.config.slackChannel, reviewers: [] };
244
+ t.review = next;
245
+ const added = next.reviewers.filter(r => !before.reviewers.includes(r));
246
+ this.update(p, {}, `Review for ${(0, pipelineView_3.shortPr)(url)}: ${next.channel ? `#${next.channel.name}` : 'no Slack post'}${next.reviewers.length ? `, reviewers ${next.reviewers.join(', ')}` : ''}`);
247
+ if (added.length)
248
+ this.requestReviewers(p, t, added);
249
+ if (next.channel && next.channel.name !== ((_b = t.slack) === null || _b === void 0 ? void 0 : _b.channel))
250
+ this.announce(p, t, true);
251
+ return null;
252
+ }
253
+ addTrack(p, url, why, review) {
236
254
  if (p.prs.some(t => t.url === url))
237
255
  return;
238
- const t = { url, state: 'in-review', seenFeedback: -1, reviewRounds: 0, ciFixes: 0 };
256
+ const t = Object.assign({ url, state: 'in-review', seenFeedback: -1, reviewRounds: 0, ciFixes: 0 }, (review ? { review } : {}));
239
257
  p.prs = [...p.prs, t];
240
258
  p.phase = 'tracking';
241
259
  this.update(p, {}, `${why} ${(0, pipelineView_3.shortPr)(url)}`);
260
+ if (review === null || review === void 0 ? void 0 : review.reviewers.length)
261
+ this.requestReviewers(p, t, review.reviewers);
242
262
  this.announce(p, t);
243
263
  }
264
+ async requestReviewers(p, t, logins) {
265
+ const env = Object.assign({}, process.env);
266
+ delete env.GITHUB_TOKEN;
267
+ delete env.GH_TOKEN;
268
+ try {
269
+ await execFileAsync('gh', ['pr', 'edit', t.url, '--add-reviewer', logins.join(',')], { timeout: 30000, env });
270
+ this.update(p, {}, `Asked ${logins.join(', ')} to review ${(0, pipelineView_3.shortPr)(t.url)}`);
271
+ }
272
+ catch (e) {
273
+ const msg = String(e.stderr || e.message).trim().split('\n').filter(Boolean).at(-1);
274
+ this.update(p, {}, `Could not request reviewers on ${(0, pipelineView_3.shortPr)(t.url)}: ${msg}`);
275
+ }
276
+ }
244
277
  // You clicked "Send to session" on a suggestion (prUrl = which PR's; none = open-PR)
245
278
  act(id, prUrl) {
246
279
  var _a;
@@ -450,16 +483,16 @@ class PipelineEngine {
450
483
  if (p.prs.length && p.prs.every(t => t.state === 'done'))
451
484
  this.update(p, { phase: 'done' }, 'All PRs are merged or closed', { title: 'Automation finished', body: `${p.prs.length} PR(s) done` });
452
485
  }
453
- async announce(p, t) {
454
- var _a, _b;
455
- const ch = p.config.slackChannel;
456
- if (!ch)
486
+ async announce(p, t, force = false) {
487
+ var _a, _b, _c;
488
+ const ch = t.review ? t.review.channel : p.config.slackChannel;
489
+ if (!ch || (((_a = t.slack) === null || _a === void 0 ? void 0 : _a.permalink) && !force))
457
490
  return;
458
491
  const pr = await prSnapshot(t.url);
459
492
  if (pr)
460
493
  this.patchTrack(p, t, { view: pr.view });
461
494
  try {
462
- const { permalink } = await (0, slackBridge_1.postToSlack)(ch, `:eyes: Ready for review: *${(_a = pr === null || pr === void 0 ? void 0 : pr.title) !== null && _a !== void 0 ? _a : 'PR'}*\n${t.url}`, (_b = liveSessionStore_1.liveSessionStore.get(p.liveId)) === null || _b === void 0 ? void 0 : _b.orgId);
495
+ const { permalink } = await (0, slackBridge_1.postToSlack)(ch, `:eyes: Ready for review: *${(_b = pr === null || pr === void 0 ? void 0 : pr.title) !== null && _b !== void 0 ? _b : 'PR'}*\n${t.url}`, (_c = liveSessionStore_1.liveSessionStore.get(p.liveId)) === null || _c === void 0 ? void 0 : _c.orgId);
463
496
  this.patchTrack(p, t, { slack: { channel: ch.name, permalink, checkedAt: Date.now() } }, `Posted ${(0, pipelineView_3.shortPr)(t.url)} to #${ch.name}`);
464
497
  }
465
498
  catch (e) {
@@ -482,3 +515,12 @@ class PipelineEngine {
482
515
  }
483
516
  }
484
517
  exports.pipelineEngine = (_a = global.__pipelineEngine) !== null && _a !== void 0 ? _a : (global.__pipelineEngine = new PipelineEngine());
518
+ // Trims a review setup from the browser: valid channel or null, logins without @ (teams as org/team)
519
+ function cleanReview(r) {
520
+ var _a;
521
+ if (!r)
522
+ return undefined;
523
+ const ch = r.channel && typeof r.channel.name === 'string' && r.channel.name.trim() ? { id: String((_a = r.channel.id) !== null && _a !== void 0 ? _a : ''), name: r.channel.name.replace(/^#/, '').trim() } : null;
524
+ const reviewers = [...new Set((Array.isArray(r.reviewers) ? r.reviewers : []).map(x => String(x).trim().replace(/^@/, '')).filter(x => /^[\w.-]+(\/[\w.-]+)?$/.test(x)))].slice(0, 15);
525
+ return { channel: ch, reviewers };
526
+ }
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.STARTUP_DIALOG_RE = exports.lastOutputAt = void 0;
37
37
  exports.claudeProjectDir = claudeProjectDir;
38
38
  exports.findSessionIdSince = findSessionIdSince;
39
+ exports.onAnySessionId = onAnySessionId;
39
40
  exports.spawnSession = spawnSession;
40
41
  exports.screenText = screenText;
41
42
  exports.writeToSession = writeToSession;
@@ -117,6 +118,7 @@ async function detectAndStoreSessionId(id, cwd, spawnTime, configDir, backend) {
117
118
  : (_b = (_a = backend.detectSessionId) === null || _a === void 0 ? void 0 : _a.call(backend, cwd, spawnTime)) !== null && _b !== void 0 ? _b : null;
118
119
  if (uuid) {
119
120
  liveSessionStore_1.liveSessionStore.setClaudeSessionId(id, uuid);
121
+ anySessionIdListeners.forEach(fn => fn(id, uuid));
120
122
  return;
121
123
  }
122
124
  }
@@ -132,6 +134,12 @@ const anyRcUrlListeners = new Set();
132
134
  const RC_URL_RE = /https:\/\/claude\.ai\/code\/session_[A-Za-z0-9]+/;
133
135
  const ptyProcesses = new Map();
134
136
  const thinkingTimers = new Map();
137
+ // "Waiting" must hold for WAITING_SETTLE_MS with no sign of work. Claude Code redraws
138
+ // its screen every second (spinner): between erase and redraw the frame shows the ❯
139
+ // prompt without the busy footer, which used to flip cards to "waiting" mid-turn.
140
+ const WAITING_SETTLE_MS = 1500;
141
+ const waitingTimers = new Map();
142
+ const lastBusyAt = new Map();
135
143
  // Small rolling ANSI-stripped tail per session, scanned for a PR URL as
136
144
  // output streams through — no extra file I/O beyond what's already flowing.
137
145
  const prScanBuffers = new Map();
@@ -153,6 +161,12 @@ function emitStatus(id, status) {
153
161
  function emitRcUrl(id, rcUrl) {
154
162
  anyRcUrlListeners.forEach(fn => fn(id, rcUrl));
155
163
  }
164
+ // Fires when a new session's conversation id is found, so browsers can update.
165
+ const anySessionIdListeners = new Set();
166
+ function onAnySessionId(fn) {
167
+ anySessionIdListeners.add(fn);
168
+ return () => anySessionIdListeners.delete(fn);
169
+ }
156
170
  function emitPrUrl(id, prUrl) {
157
171
  anyPrUrlListeners.forEach(fn => fn(id, prUrl));
158
172
  }
@@ -287,28 +301,45 @@ function spawnSession(id, cwd, resumeId, configDir, model, rcName, backendId, rc
287
301
  return;
288
302
  // Copilot's status lives in the footer below the cursor, so read the
289
303
  // screen bottom for it; Claude's lives in the lines around the cursor.
290
- const status = backend.id !== 'claude'
304
+ const readStatus = () => backend.id !== 'claude'
291
305
  ? (0, statusDetector_1.detectStatus)(bottomRows(headlessTerm, 3), backend.id)
292
306
  // Claude's footer (below the prompt) says "esc to interrupt" while busy
293
307
  : (0, statusDetector_1.detectStatus)(bufferTail(headlessTerm) + '\n' + bottomRows(headlessTerm, 3));
308
+ const status = readStatus();
294
309
  const session = liveSessionStore_1.liveSessionStore.get(id);
295
310
  if (!session)
296
311
  return;
312
+ if (status === 'thinking')
313
+ lastBusyAt.set(id, Date.now());
297
314
  if (status === 'waiting') {
298
- // Cancel any pending thinking transition — waiting wins immediately
299
- const t = thinkingTimers.get(id);
300
- if (t) {
301
- clearTimeout(t);
302
- thinkingTimers.delete(id);
303
- }
304
- if (session.status !== 'waiting') {
315
+ if (session.status === 'waiting' || waitingTimers.has(id))
316
+ return;
317
+ const settle = (delay) => waitingTimers.set(id, setTimeout(() => {
318
+ var _a;
319
+ waitingTimers.delete(id);
320
+ const s = liveSessionStore_1.liveSessionStore.get(id);
321
+ if (!s || s.status === 'waiting' || !headlessTerms.has(id))
322
+ return;
323
+ if (readStatus() !== 'waiting')
324
+ return; // busy again; the next waiting frame re-arms
325
+ // A busy frame came in meanwhile: check again once it's WAITING_SETTLE_MS old
326
+ const sinceBusy = Date.now() - ((_a = lastBusyAt.get(id)) !== null && _a !== void 0 ? _a : 0);
327
+ if (sinceBusy < WAITING_SETTLE_MS) {
328
+ settle(WAITING_SETTLE_MS - sinceBusy);
329
+ return;
330
+ }
331
+ const t = thinkingTimers.get(id);
332
+ if (t) {
333
+ clearTimeout(t);
334
+ thinkingTimers.delete(id);
335
+ }
305
336
  liveSessionStore_1.liveSessionStore.setStatus(id, 'waiting');
306
337
  emitStatus(id, 'waiting');
307
- }
338
+ }, delay));
339
+ settle(WAITING_SETTLE_MS);
308
340
  }
309
341
  else if (status === 'thinking' && session.status !== 'thinking') {
310
- // Debounce: trailing chunks after the ❯ prompt often lack ❯, don't
311
- // let them immediately clobber a 'waiting' state we just set.
342
+ // Debounce: a lone busy-looking frame shouldn't wake an idle/waiting card
312
343
  if (!thinkingTimers.has(id)) {
313
344
  thinkingTimers.set(id, setTimeout(() => {
314
345
  thinkingTimers.delete(id);
@@ -334,6 +365,11 @@ function spawnSession(id, cwd, resumeId, configDir, model, rcName, backendId, rc
334
365
  clearTimeout(t);
335
366
  thinkingTimers.delete(id);
336
367
  }
368
+ const wt = waitingTimers.get(id);
369
+ if (wt) {
370
+ clearTimeout(wt);
371
+ waitingTimers.delete(id);
372
+ }
337
373
  liveSessionStore_1.liveSessionStore.setStatus(id, 'idle');
338
374
  emitStatus(id, 'idle');
339
375
  ptyProcesses.delete(id);
@@ -248,6 +248,7 @@ async function draftChannelReply(r, channel, ctx, orgId = orgRegistry_1.DEFAULT_
248
248
  'Use what you know from this conversation and the code here. If you are not sure, say what you would check instead of guessing. ' +
249
249
  'Never promise work for later ("I\'ll check", "I\'ll post the results"): nobody will do it. ' +
250
250
  `If you can't give a real answer now, start the reply with ${exports.NEEDS_OWNER} so I write it myself. ` +
251
+ `If they ask for something to be done (deploy, rollout, fix, restart) and it is not done yet, do not reply with a plan or a command for them to run: start with ${exports.NEEDS_OWNER} so the work gets done first. ` +
251
252
  'Respond with ONLY the reply text.';
252
253
  const { result } = ctx
253
254
  ? await (0, meetingAssistant_1.runClaude)(prompt, { cwd: ctx.cwd, configDir: ctx.configDir, model: null, extraEnv: slackEnv(ctx.configDir), resumeId: ctx.resumeId, forkSession: true, timeoutMs: 300000 })
@@ -2,6 +2,7 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.slackWatchers = void 0;
5
+ exports.threadKey = threadKey;
5
6
  const fs_1 = require("fs");
6
7
  const path_1 = require("path");
7
8
  const crypto_1 = require("crypto");
@@ -111,8 +112,19 @@ class SlackWatcherEngine {
111
112
  if (fresh.length) {
112
113
  w.items = [...fresh.map(r => (Object.assign(Object.assign({}, r), { state: 'drafting', draft: null }))), ...w.items].slice(0, 100);
113
114
  this.log(w, `Found ${fresh.length} question${fresh.length > 1 ? 's' : ''} in #${w.channel.name}`, undefined, { detail: fresh.map(r => `${r.author}: ${r.text}`).join('\n\n') });
114
- for (const r of fresh)
115
- await this.draft(w, r.permalink);
115
+ for (const r of fresh) {
116
+ // A new message in a thread the session is already working: pass it on, don't draft over it
117
+ const owner = w.liveId && liveSessionStore_1.liveSessionStore.get(w.liveId) && w.items.find(i => i.state === 'delegated' && i.permalink !== r.permalink && threadKey(i.permalink) === threadKey(r.permalink));
118
+ const it = w.items.find(i => i.permalink === r.permalink);
119
+ if (owner && it) {
120
+ (0, ptyManager_1.sendWhenReady)(w.liveId, `Follow-up in the Slack thread you are handling (${r.permalink}) from ${r.author}: "${r.text.replace(/\s+/g, ' ').slice(0, 1500)}". ` +
121
+ 'Continue until it is resolved and verified, then reply in the thread. Ask me here before any production change.');
122
+ it.state = 'delegated';
123
+ this.log(w, `${r.author} followed up: passed to the session`, undefined, { detail: r.text, link: r.permalink });
124
+ }
125
+ else
126
+ await this.draft(w, r.permalink);
127
+ }
116
128
  }
117
129
  else {
118
130
  // One rolling line, not one per check
@@ -136,12 +148,12 @@ class SlackWatcherEngine {
136
148
  const s = w.liveId ? liveSessionStore_1.liveSessionStore.get(w.liveId) : null;
137
149
  return (s === null || s === void 0 ? void 0 : s.claudeSessionId) ? { resumeId: s.claudeSessionId, cwd: s.cwd, configDir: (_b = (_a = orgRegistry_1.orgRegistry.get(s.orgId)) === null || _a === void 0 ? void 0 : _a.configDir) !== null && _b !== void 0 ? _b : null } : null;
138
150
  }
139
- async draft(w, permalink) {
151
+ async draft(w, permalink, hint = '') {
140
152
  const it = w.items.find(i => i.permalink === permalink);
141
153
  if (!it)
142
154
  return;
143
155
  try {
144
- const raw = await (0, slackBridge_1.draftChannelReply)(it, w.channel.name, this.ctxFor(w), w.orgId, { knowledge: w.knowledge, instructions: w.instructions });
156
+ const raw = await (0, slackBridge_1.draftChannelReply)(it, w.channel.name, this.ctxFor(w), w.orgId, { knowledge: w.knowledge, instructions: [w.instructions, hint && `For this reply, the owner says: ${hint}`].filter(Boolean).join('\n') });
145
157
  const needsYou = raw.startsWith(slackBridge_1.NEEDS_OWNER);
146
158
  it.draft = needsYou ? raw.slice(slackBridge_1.NEEDS_OWNER.length).trim() : raw;
147
159
  // Auto-answer only messages posted after you started the watcher; older backlog waits for your approval
@@ -206,12 +218,37 @@ class SlackWatcherEngine {
206
218
  return { error: 'Already handed off' };
207
219
  const text = it.text.replace(/\s+/g, ' ').slice(0, 1500);
208
220
  (0, ptyManager_1.sendWhenReady)(w.liveId, `Slack request in #${w.channel.name} from ${it.author} (${it.permalink}): "${text}". ` +
209
- 'Do the work needed to answer it (run the checks, read the code or logs). Then reply in that Slack thread with the Slack connector, with the actual results. ' +
210
- 'Report only what you verified; if something failed or you could not check it, say so plainly. Do not promise to do it later.');
221
+ 'Do the work needed to answer it (run the checks, read the code or logs, make the change). Then reply in that Slack thread with the Slack connector, with the actual results. ' +
222
+ 'Report only what you verified; if something failed or you could not check it, say so plainly. Do not promise to do it later. ' +
223
+ 'Keep going until it is actually finished and verified: do not stop at a plan, a status update or a command for someone else to run. ' +
224
+ 'Before any step that changes production (deploy, set image, rollout, restart, delete, migrate), ask me here and wait for my OK, then continue. ' +
225
+ 'Reply in the Slack thread only when it is done (with how you verified it) or truly blocked (say exactly what blocks it). ' +
226
+ 'If they reply in the thread again, I will pass it to you here.');
211
227
  it.state = 'delegated';
212
228
  this.log(w, `${auto ? 'Needed real work: sent' : 'You sent'} ${it.author}'s request to the session`, undefined, { detail: it.text, link: it.permalink });
213
229
  return null;
214
230
  }
231
+ // Your one-off instruction about this channel ("answer Koren with the deploy status"),
232
+ // done by the linked session with the Slack connector.
233
+ instruct(id, text) {
234
+ const w = this.items.find(x => x.id === id);
235
+ if (!w)
236
+ return { error: 'Not found' };
237
+ if (!w.liveId || !liveSessionStore_1.liveSessionStore.get(w.liveId))
238
+ return { error: 'Link a session to this watcher first (the 🧠 menu on the card)' };
239
+ const t = text.trim().slice(0, 4000);
240
+ if (!t)
241
+ return { error: 'Write what it should do' };
242
+ (0, ptyManager_1.sendWhenReady)(w.liveId, `About the Slack channel #${w.channel.name} (id ${w.channel.id}), the owner asks: ${t.replace(/\s+/g, ' ')} ` +
243
+ '— Use the Slack connector to read what you need and do it. Post in Slack only if that is what the owner asked for. ' +
244
+ 'Report only what you verified; if you could not do something, say so plainly. ' +
245
+ 'Keep going until it is actually finished and verified: do not stop at a plan, a status update or a command for someone else to run. ' +
246
+ 'Before any step that changes production (deploy, set image, rollout, restart, delete, migrate), ask me here and wait for my OK, then continue. ' +
247
+ 'Reply in the Slack thread only when it is done (with how you verified it) or truly blocked (say exactly what blocks it). ' +
248
+ 'If they reply in the thread again, I will pass it to you here.');
249
+ this.log(w, 'You told the session what to do', undefined, { detail: t });
250
+ return null;
251
+ }
215
252
  dismiss(id, permalink) {
216
253
  const w = this.items.find(x => x.id === id);
217
254
  const it = w === null || w === void 0 ? void 0 : w.items.find(i => i.permalink === permalink);
@@ -220,16 +257,28 @@ class SlackWatcherEngine {
220
257
  this.log(w, `You dismissed ${it.author}'s question`, undefined, { link: permalink });
221
258
  }
222
259
  }
223
- redraft(id, permalink) {
260
+ // hint: your guidance for this one reply ("mention the rollback", "it's fixed in 2.3")
261
+ redraft(id, permalink, hint) {
224
262
  const w = this.items.find(x => x.id === id);
225
263
  const it = w === null || w === void 0 ? void 0 : w.items.find(i => i.permalink === permalink);
226
- if (w && it) {
227
- it.state = 'drafting';
228
- it.error = undefined;
229
- this.save();
230
- this.draft(w, permalink);
231
- }
264
+ if (!w || !it)
265
+ return;
266
+ const h = String(hint !== null && hint !== void 0 ? hint : '').trim().slice(0, 2000);
267
+ if (h)
268
+ this.log(w, `You guided the reply to ${it.author}`, undefined, { link: permalink, detail: h });
269
+ it.state = 'drafting';
270
+ it.error = undefined;
271
+ this.save();
272
+ this.draft(w, permalink, h);
232
273
  }
233
274
  }
234
275
  SlackWatcherEngine.BACKLOG_MS = 24 * 60 * 60000;
235
276
  exports.slackWatchers = (_a = global.__slackWatchers) !== null && _a !== void 0 ? _a : (global.__slackWatchers = new SlackWatcherEngine());
277
+ // Same Slack thread? Replies carry thread_ts; a top-level post's ts is in /p<10 digits><6 digits>.
278
+ function threadKey(permalink) {
279
+ const t = permalink.match(/thread_ts=(\d+\.\d+)/);
280
+ if (t)
281
+ return t[1];
282
+ const p = permalink.match(/\/p(\d{10})(\d{6})/);
283
+ return p ? `${p[1]}.${p[2]}` : permalink;
284
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transcribeChunk = transcribeChunk;
4
4
  const fs_1 = require("fs");
5
5
  const audioCapture_1 = require("./audioCapture");
6
+ const localWhisper_1 = require("./localWhisper");
6
7
  const MAX_ATTEMPTS = 3;
7
8
  function requestFor(config, buf, prompt) {
8
9
  const form = new FormData();
@@ -33,6 +34,8 @@ async function transcribeChunk(filePath, config, prompt = '') {
33
34
  const buf = (0, fs_1.readFileSync)(filePath);
34
35
  if ((0, audioCapture_1.wavRms)(buf) < audioCapture_1.SILENCE_RMS_THRESHOLD)
35
36
  return null;
37
+ if (config.kind === 'local')
38
+ return (0, localWhisper_1.transcribeLocal)(filePath, prompt);
36
39
  let lastError;
37
40
  for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
38
41
  if (attempt > 0)