polyergon 0.0.0-stage → 0.1.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.
Files changed (239) hide show
  1. package/.next/BUILD_ID +1 -0
  2. package/.next/app-build-manifest.json +35 -0
  3. package/.next/app-path-routes-manifest.json +1 -0
  4. package/.next/build-manifest.json +32 -0
  5. package/.next/export-marker.json +1 -0
  6. package/.next/images-manifest.json +1 -0
  7. package/.next/next-minimal-server.js.nft.json +1 -0
  8. package/.next/next-server.js.nft.json +1 -0
  9. package/.next/package.json +1 -0
  10. package/.next/prerender-manifest.json +1 -0
  11. package/.next/react-loadable-manifest.json +10 -0
  12. package/.next/required-server-files.json +1 -0
  13. package/.next/routes-manifest.json +1 -0
  14. package/.next/server/app/_not-found/page.js +1 -0
  15. package/.next/server/app/_not-found/page.js.nft.json +1 -0
  16. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  17. package/.next/server/app/_not-found.html +1 -0
  18. package/.next/server/app/_not-found.meta +6 -0
  19. package/.next/server/app/_not-found.rsc +9 -0
  20. package/.next/server/app/api/automations/existing/route.js +1 -0
  21. package/.next/server/app/api/automations/existing/route.js.nft.json +1 -0
  22. package/.next/server/app/api/backends/route.js +1 -0
  23. package/.next/server/app/api/backends/route.js.nft.json +1 -0
  24. package/.next/server/app/api/diff/route.js +1 -0
  25. package/.next/server/app/api/diff/route.js.nft.json +1 -0
  26. package/.next/server/app/api/limits/route.js +1 -0
  27. package/.next/server/app/api/limits/route.js.nft.json +1 -0
  28. package/.next/server/app/api/meetings/[id]/route.js +1 -0
  29. package/.next/server/app/api/meetings/[id]/route.js.nft.json +1 -0
  30. package/.next/server/app/api/meetings/[id]/slack/route.js +3 -0
  31. package/.next/server/app/api/meetings/[id]/slack/route.js.nft.json +1 -0
  32. package/.next/server/app/api/meetings/library/route.js +1 -0
  33. package/.next/server/app/api/meetings/library/route.js.nft.json +1 -0
  34. package/.next/server/app/api/meetings/route.js +1 -0
  35. package/.next/server/app/api/meetings/route.js.nft.json +1 -0
  36. package/.next/server/app/api/models/route.js +1 -0
  37. package/.next/server/app/api/models/route.js.nft.json +1 -0
  38. package/.next/server/app/api/notes/route.js +1 -0
  39. package/.next/server/app/api/notes/route.js.nft.json +1 -0
  40. package/.next/server/app/api/orgs/[id]/route.js +1 -0
  41. package/.next/server/app/api/orgs/[id]/route.js.nft.json +1 -0
  42. package/.next/server/app/api/orgs/route.js +1 -0
  43. package/.next/server/app/api/orgs/route.js.nft.json +1 -0
  44. package/.next/server/app/api/prs/inbox/route.js +1 -0
  45. package/.next/server/app/api/prs/inbox/route.js.nft.json +1 -0
  46. package/.next/server/app/api/prs/refresh/route.js +1 -0
  47. package/.next/server/app/api/prs/refresh/route.js.nft.json +1 -0
  48. package/.next/server/app/api/prs/route.js +1 -0
  49. package/.next/server/app/api/prs/route.js.nft.json +1 -0
  50. package/.next/server/app/api/session-names/route.js +1 -0
  51. package/.next/server/app/api/session-names/route.js.nft.json +1 -0
  52. package/.next/server/app/api/sessions/[id]/route.js +1 -0
  53. package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -0
  54. package/.next/server/app/api/sessions/route.js +1 -0
  55. package/.next/server/app/api/sessions/route.js.nft.json +1 -0
  56. package/.next/server/app/api/settings/auth/route.js +1 -0
  57. package/.next/server/app/api/settings/auth/route.js.nft.json +1 -0
  58. package/.next/server/app/api/settings/route.js +1 -0
  59. package/.next/server/app/api/settings/route.js.nft.json +1 -0
  60. package/.next/server/app/api/settings/transcription/route.js +1 -0
  61. package/.next/server/app/api/settings/transcription/route.js.nft.json +1 -0
  62. package/.next/server/app/api/skills/[name]/route.js +8 -0
  63. package/.next/server/app/api/skills/[name]/route.js.nft.json +1 -0
  64. package/.next/server/app/api/skills/marketplace/route.js +2 -0
  65. package/.next/server/app/api/skills/marketplace/route.js.nft.json +1 -0
  66. package/.next/server/app/api/skills/route.js +8 -0
  67. package/.next/server/app/api/skills/route.js.nft.json +1 -0
  68. package/.next/server/app/api/skills/view/route.js +8 -0
  69. package/.next/server/app/api/skills/view/route.js.nft.json +1 -0
  70. package/.next/server/app/api/slack/channels/route.js +1 -0
  71. package/.next/server/app/api/slack/channels/route.js.nft.json +1 -0
  72. package/.next/server/app/api/slack/configured/route.js +1 -0
  73. package/.next/server/app/api/slack/configured/route.js.nft.json +1 -0
  74. package/.next/server/app/api/slack/inbox/route.js +1 -0
  75. package/.next/server/app/api/slack/inbox/route.js.nft.json +1 -0
  76. package/.next/server/app/api/tasks/route.js +1 -0
  77. package/.next/server/app/api/tasks/route.js.nft.json +1 -0
  78. package/.next/server/app/api/usage/route.js +1 -0
  79. package/.next/server/app/api/usage/route.js.nft.json +1 -0
  80. package/.next/server/app/demo/page.js +1 -0
  81. package/.next/server/app/demo/page.js.nft.json +1 -0
  82. package/.next/server/app/demo/page_client-reference-manifest.js +1 -0
  83. package/.next/server/app/demo.html +1 -0
  84. package/.next/server/app/demo.meta +6 -0
  85. package/.next/server/app/demo.rsc +7 -0
  86. package/.next/server/app/favicon.ico/route.js +12 -0
  87. package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
  88. package/.next/server/app/favicon.ico.body +0 -0
  89. package/.next/server/app/favicon.ico.meta +1 -0
  90. package/.next/server/app/index.html +1 -0
  91. package/.next/server/app/index.meta +5 -0
  92. package/.next/server/app/index.rsc +7 -0
  93. package/.next/server/app/page.js +10 -0
  94. package/.next/server/app/page.js.nft.json +1 -0
  95. package/.next/server/app/page_client-reference-manifest.js +1 -0
  96. package/.next/server/app-paths-manifest.json +36 -0
  97. package/.next/server/chunks/36.js +1 -0
  98. package/.next/server/chunks/471.js +2 -0
  99. package/.next/server/chunks/590.js +7 -0
  100. package/.next/server/chunks/621.js +1 -0
  101. package/.next/server/chunks/682.js +6 -0
  102. package/.next/server/chunks/904.js +1 -0
  103. package/.next/server/chunks/948.js +2 -0
  104. package/.next/server/chunks/972.js +12 -0
  105. package/.next/server/chunks/font-manifest.json +1 -0
  106. package/.next/server/font-manifest.json +1 -0
  107. package/.next/server/functions-config-manifest.json +1 -0
  108. package/.next/server/interception-route-rewrite-manifest.js +1 -0
  109. package/.next/server/middleware-build-manifest.js +1 -0
  110. package/.next/server/middleware-manifest.json +6 -0
  111. package/.next/server/middleware-react-loadable-manifest.js +1 -0
  112. package/.next/server/next-font-manifest.js +1 -0
  113. package/.next/server/next-font-manifest.json +1 -0
  114. package/.next/server/pages/404.html +1 -0
  115. package/.next/server/pages/500.html +1 -0
  116. package/.next/server/pages/_app.js +1 -0
  117. package/.next/server/pages/_app.js.nft.json +1 -0
  118. package/.next/server/pages/_document.js +1 -0
  119. package/.next/server/pages/_document.js.nft.json +1 -0
  120. package/.next/server/pages/_error.js +1 -0
  121. package/.next/server/pages/_error.js.nft.json +1 -0
  122. package/.next/server/pages-manifest.json +1 -0
  123. package/.next/server/server-reference-manifest.js +1 -0
  124. package/.next/server/server-reference-manifest.json +1 -0
  125. package/.next/server/webpack-runtime.js +1 -0
  126. package/.next/static/2gHioRND6aAzT4OB5OHDV/_buildManifest.js +1 -0
  127. package/.next/static/2gHioRND6aAzT4OB5OHDV/_ssgManifest.js +1 -0
  128. package/.next/static/chunks/117-0f4ac3c2c1871d4c.js +2 -0
  129. package/.next/static/chunks/171-d325f9625379d70a.js +1 -0
  130. package/.next/static/chunks/235.aef4cdc783360b73.js +1 -0
  131. package/.next/static/chunks/30d07d85.9045c666bb43d9e1.js +3 -0
  132. package/.next/static/chunks/app/_not-found/page-8ff6572bc7c9bc61.js +1 -0
  133. package/.next/static/chunks/app/demo/page-6711b34cd2af0e4a.js +1 -0
  134. package/.next/static/chunks/app/layout-d058836232e72324.js +1 -0
  135. package/.next/static/chunks/app/page-fedaef1e63f186c2.js +1 -0
  136. package/.next/static/chunks/fd9d1056-26bd8d656b496dba.js +1 -0
  137. package/.next/static/chunks/framework-f66176bb897dc684.js +1 -0
  138. package/.next/static/chunks/main-app-4b855ea14675b961.js +1 -0
  139. package/.next/static/chunks/main-e88dbd51c3bdafca.js +1 -0
  140. package/.next/static/chunks/pages/_app-72b849fbd24ac258.js +1 -0
  141. package/.next/static/chunks/pages/_error-7ba65e1336b92748.js +1 -0
  142. package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  143. package/.next/static/chunks/webpack-1f89b7cb1fca69c4.js +1 -0
  144. package/.next/static/css/6e83ef44d507c857.css +3 -0
  145. package/.next/static/css/ab3e4b0f5035257a.css +1 -0
  146. package/.next/trace +23 -0
  147. package/.next/types/app/api/automations/existing/route.ts +343 -0
  148. package/.next/types/app/api/backends/route.ts +343 -0
  149. package/.next/types/app/api/diff/route.ts +343 -0
  150. package/.next/types/app/api/limits/route.ts +343 -0
  151. package/.next/types/app/api/meetings/[id]/route.ts +343 -0
  152. package/.next/types/app/api/meetings/[id]/slack/route.ts +343 -0
  153. package/.next/types/app/api/meetings/library/route.ts +343 -0
  154. package/.next/types/app/api/meetings/route.ts +343 -0
  155. package/.next/types/app/api/models/route.ts +343 -0
  156. package/.next/types/app/api/notes/route.ts +343 -0
  157. package/.next/types/app/api/orgs/[id]/route.ts +343 -0
  158. package/.next/types/app/api/orgs/route.ts +343 -0
  159. package/.next/types/app/api/prs/inbox/route.ts +343 -0
  160. package/.next/types/app/api/prs/refresh/route.ts +343 -0
  161. package/.next/types/app/api/prs/route.ts +343 -0
  162. package/.next/types/app/api/session-names/route.ts +343 -0
  163. package/.next/types/app/api/sessions/[id]/route.ts +343 -0
  164. package/.next/types/app/api/sessions/route.ts +343 -0
  165. package/.next/types/app/api/settings/auth/route.ts +343 -0
  166. package/.next/types/app/api/settings/route.ts +343 -0
  167. package/.next/types/app/api/settings/transcription/route.ts +343 -0
  168. package/.next/types/app/api/skills/[name]/route.ts +343 -0
  169. package/.next/types/app/api/skills/marketplace/route.ts +343 -0
  170. package/.next/types/app/api/skills/route.ts +343 -0
  171. package/.next/types/app/api/skills/view/route.ts +343 -0
  172. package/.next/types/app/api/slack/channels/route.ts +343 -0
  173. package/.next/types/app/api/slack/configured/route.ts +343 -0
  174. package/.next/types/app/api/slack/inbox/route.ts +343 -0
  175. package/.next/types/app/api/tasks/route.ts +343 -0
  176. package/.next/types/app/api/usage/route.ts +343 -0
  177. package/.next/types/app/demo/page.ts +79 -0
  178. package/.next/types/app/layout.ts +79 -0
  179. package/.next/types/app/page.ts +79 -0
  180. package/.next/types/package.json +1 -0
  181. package/.server-dist/server.js +600 -0
  182. package/.server-dist/src/lib/activeOrg.js +11 -0
  183. package/.server-dist/src/lib/audioCapture.js +157 -0
  184. package/.server-dist/src/lib/backends.js +209 -0
  185. package/.server-dist/src/lib/claudeAuth.js +57 -0
  186. package/.server-dist/src/lib/configFile.js +23 -0
  187. package/.server-dist/src/lib/dataDir.js +7 -0
  188. package/.server-dist/src/lib/diffReview.js +116 -0
  189. package/.server-dist/src/lib/existingAutomations.js +132 -0
  190. package/.server-dist/src/lib/ghInbox.js +151 -0
  191. package/.server-dist/src/lib/ghPrStatus.js +86 -0
  192. package/.server-dist/src/lib/gitUtils.js +27 -0
  193. package/.server-dist/src/lib/keepAwake.js +32 -0
  194. package/.server-dist/src/lib/liveSessionStore.js +89 -0
  195. package/.server-dist/src/lib/marketplace.js +63 -0
  196. package/.server-dist/src/lib/meetingAssistant.js +138 -0
  197. package/.server-dist/src/lib/meetingConfig.js +81 -0
  198. package/.server-dist/src/lib/meetingContext.js +82 -0
  199. package/.server-dist/src/lib/meetingManager.js +246 -0
  200. package/.server-dist/src/lib/meetingStore.js +198 -0
  201. package/.server-dist/src/lib/modelCatalog.js +114 -0
  202. package/.server-dist/src/lib/notesStore.js +67 -0
  203. package/.server-dist/src/lib/orgFilter.js +19 -0
  204. package/.server-dist/src/lib/orgParam.js +15 -0
  205. package/.server-dist/src/lib/orgRegistry.js +93 -0
  206. package/.server-dist/src/lib/pipelineView.js +62 -0
  207. package/.server-dist/src/lib/pipelines.js +427 -0
  208. package/.server-dist/src/lib/planLimits.js +101 -0
  209. package/.server-dist/src/lib/prDetector.js +16 -0
  210. package/.server-dist/src/lib/prScanCache.js +144 -0
  211. package/.server-dist/src/lib/prSessionEntries.js +96 -0
  212. package/.server-dist/src/lib/prTypes.js +2 -0
  213. package/.server-dist/src/lib/ptyManager.js +437 -0
  214. package/.server-dist/src/lib/reminders.js +10 -0
  215. package/.server-dist/src/lib/requestGuard.js +29 -0
  216. package/.server-dist/src/lib/sessionNameStore.js +69 -0
  217. package/.server-dist/src/lib/sessionStore.js +215 -0
  218. package/.server-dist/src/lib/settingsStore.js +51 -0
  219. package/.server-dist/src/lib/skillsReader.js +200 -0
  220. package/.server-dist/src/lib/slackBridge.js +270 -0
  221. package/.server-dist/src/lib/slackInbox.js +96 -0
  222. package/.server-dist/src/lib/slackWatchers.js +210 -0
  223. package/.server-dist/src/lib/statusDetector.js +50 -0
  224. package/.server-dist/src/lib/taskStore.js +42 -0
  225. package/.server-dist/src/lib/transcriber.js +61 -0
  226. package/.server-dist/src/lib/usageStore.js +254 -0
  227. package/.server-dist/src/lib/worktrees.js +42 -0
  228. package/.server-dist/tsconfig.server.tsbuildinfo +1 -0
  229. package/LICENSE +21 -0
  230. package/README.md +111 -2
  231. package/bin/polyergon.js +34 -0
  232. package/next.config.mjs +4 -0
  233. package/package.json +81 -4
  234. package/public/.gitkeep +0 -0
  235. package/public/apple-touch-icon.png +0 -0
  236. package/public/icon-192.png +0 -0
  237. package/public/icon-512.png +0 -0
  238. package/public/icon.svg +1 -0
  239. package/public/manifest.webmanifest +15 -0
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MeetingAssistant = void 0;
4
+ exports.runClaude = runClaude;
5
+ exports.parseNotesTick = parseNotesTick;
6
+ const child_process_1 = require("child_process");
7
+ const claudeAuth_1 = require("./claudeAuth");
8
+ const CALL_TIMEOUT_MS = 180000;
9
+ // One headless `claude -p` call (optionally resuming a conversation). Runs with
10
+ // permission prompts off so it can use web/file tools and MCP connectors.
11
+ // forkSession: resume a COPY of the conversation (new id); the original is untouched.
12
+ function runClaude(prompt, opts) {
13
+ return new Promise((resolve, reject) => {
14
+ var _a;
15
+ const args = [
16
+ '-p', '--output-format', 'json',
17
+ '--permission-mode', 'bypassPermissions',
18
+ ...(opts.model ? ['--model', opts.model] : []),
19
+ ...(opts.resumeId ? ['--resume', opts.resumeId, ...(opts.forkSession ? ['--fork-session'] : [])] : []),
20
+ ];
21
+ const env = Object.assign(Object.assign(Object.assign(Object.assign({}, Object.fromEntries(['PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'TERM', 'LANG', 'LC_ALL']
22
+ .filter(k => process.env[k])
23
+ .map(k => [k, process.env[k]]))), (0, claudeAuth_1.claudeAuthEnv)()), (opts.configDir ? { CLAUDE_CONFIG_DIR: opts.configDir } : {})), opts.extraEnv);
24
+ const proc = (0, child_process_1.spawn)('claude', args, { cwd: opts.cwd, env });
25
+ let stdout = '';
26
+ let stderr = '';
27
+ proc.stdout.on('data', (d) => { stdout += d.toString(); });
28
+ proc.stderr.on('data', (d) => { stderr = (stderr + d.toString()).slice(-1000); });
29
+ const killer = setTimeout(() => proc.kill('SIGKILL'), (_a = opts.timeoutMs) !== null && _a !== void 0 ? _a : CALL_TIMEOUT_MS);
30
+ proc.on('error', (e) => { clearTimeout(killer); reject(e); });
31
+ proc.on('exit', (code) => {
32
+ var _a, _b;
33
+ clearTimeout(killer);
34
+ if (code !== 0) {
35
+ reject(new Error(code === null ? 'Claude took too long and was stopped' : `claude -p exited ${code}: ${stderr.trim().slice(-300)}`));
36
+ return;
37
+ }
38
+ try {
39
+ const parsed = JSON.parse(stdout);
40
+ resolve({ result: (_a = parsed.result) !== null && _a !== void 0 ? _a : '', sessionId: (_b = parsed.session_id) !== null && _b !== void 0 ? _b : null });
41
+ }
42
+ catch (_c) {
43
+ reject(new Error(`unparseable claude output: ${stdout.slice(0, 200)}`));
44
+ }
45
+ });
46
+ proc.stdin.write(prompt);
47
+ proc.stdin.end();
48
+ });
49
+ }
50
+ const PREAMBLE = `You are a live meeting assistant. You receive transcript excerpts from an ongoing meeting as they happen (transcribed from audio — expect some transcription errors, and possibly mixed Hebrew/English). Your job across this conversation:
51
+ - Maintain structured meeting notes (topics discussed, decisions made, action items with owners when identifiable).
52
+ - Answer questions the user asks mid-meeting, concisely — they're in the meeting and need fast answers.
53
+ - Occasionally offer ONE genuinely useful proactive suggestion (an answer to a question someone raised, a factual correction, relevant context). Most updates need no suggestion — only include one when it truly helps.
54
+ Never invent transcript content. If the transcript is too sparse to conclude something, leave it out.`;
55
+ // One persistent headless Claude conversation (claude -p / --resume) per
56
+ // meeting, under the meeting org's config dir + model. Calls are serialized —
57
+ // notes ticks, asks and the summary share one conversation and must not race.
58
+ class MeetingAssistant {
59
+ constructor(opts, existingSessionId = null) {
60
+ this.queue = Promise.resolve();
61
+ this.onSessionId = null;
62
+ this.opts = opts;
63
+ this.sessionId = existingSessionId;
64
+ }
65
+ // Exposed so the manager can persist it and survive server restarts
66
+ getSessionId() {
67
+ return this.sessionId;
68
+ }
69
+ enqueue(fn) {
70
+ const run = this.queue.then(fn, fn);
71
+ this.queue = run.catch(() => { });
72
+ return run;
73
+ }
74
+ async call(prompt) {
75
+ var _a;
76
+ const { result, sessionId } = await runClaude(prompt, Object.assign(Object.assign({}, this.opts), { resumeId: this.sessionId }));
77
+ if (sessionId) {
78
+ this.sessionId = sessionId;
79
+ (_a = this.onSessionId) === null || _a === void 0 ? void 0 : _a.call(this, sessionId);
80
+ }
81
+ return result;
82
+ }
83
+ withPreamble(body) {
84
+ // The preamble only needs to be sent once; --resume keeps the context
85
+ return this.sessionId ? body : `${PREAMBLE}\n\n${body}`;
86
+ }
87
+ notesTick(transcriptDelta) {
88
+ return this.enqueue(async () => {
89
+ const prompt = this.withPreamble(`New transcript since the last update:\n---\n${transcriptDelta}\n---\n` +
90
+ `Update your running notes for the whole meeting so far. Respond with ONLY a JSON object, no prose, no markdown fences:\n` +
91
+ `{"notes": {"topics": string[], "decisions": string[], "actionItems": string[]}, "suggestion": string | null}`);
92
+ const raw = await this.call(prompt);
93
+ return parseNotesTick(raw);
94
+ });
95
+ }
96
+ ask(question, transcriptDelta) {
97
+ return this.enqueue(() => this.call(this.withPreamble((transcriptDelta ? `New transcript since the last update:\n---\n${transcriptDelta}\n---\n` : '') +
98
+ `The user asks (mid-meeting, answer concisely and directly): ${question}`)));
99
+ }
100
+ // Background material for the rest of the meeting. Returns the assistant's
101
+ // one-line read of it; a line starting with FAILED means it couldn't load it.
102
+ addContext(label, body, fetch) {
103
+ return this.enqueue(() => this.call(this.withPreamble(fetch
104
+ ? `The user added a source as background context for this meeting: ${body}\n` +
105
+ `Load it now with your tools (web fetch, file read, or the matching MCP connector such as Slack, Notion, Google Drive or Gmail). ` +
106
+ `Keep what you learn in mind for notes, answers and suggestions for the rest of the meeting. ` +
107
+ `Reply with ONE short line saying what it is about, or "FAILED: <reason>" if you cannot load it.`
108
+ : `The user added background context for this meeting (${label}):\n---\n${body}\n---\n` +
109
+ `Keep it in mind for notes, answers and suggestions for the rest of the meeting. Reply with ONE short line saying what it is about.`)));
110
+ }
111
+ summarize(transcriptDelta) {
112
+ return this.enqueue(() => this.call(this.withPreamble((transcriptDelta ? `Final transcript segment:\n---\n${transcriptDelta}\n---\n` : '') +
113
+ `The meeting has ended. Write a markdown recap of the ENTIRE meeting with sections: ## Summary (a few sentences), ## Decisions (bullets), ## Action Items (bullets with owners where known). Respond with only the markdown.`)));
114
+ }
115
+ }
116
+ exports.MeetingAssistant = MeetingAssistant;
117
+ // Tolerates fenced or prose-wrapped JSON — extracts the outermost object
118
+ function parseNotesTick(raw) {
119
+ const start = raw.indexOf('{');
120
+ const end = raw.lastIndexOf('}');
121
+ if (start === -1 || end <= start)
122
+ return { notes: null, suggestion: null };
123
+ try {
124
+ const obj = JSON.parse(raw.slice(start, end + 1));
125
+ const n = obj.notes;
126
+ const notes = n && typeof n === 'object'
127
+ ? {
128
+ topics: Array.isArray(n.topics) ? n.topics.filter((x) => typeof x === 'string') : [],
129
+ decisions: Array.isArray(n.decisions) ? n.decisions.filter((x) => typeof x === 'string') : [],
130
+ actionItems: Array.isArray(n.actionItems) ? n.actionItems.filter((x) => typeof x === 'string') : [],
131
+ }
132
+ : null;
133
+ return { notes, suggestion: typeof obj.suggestion === 'string' && obj.suggestion.trim() ? obj.suggestion.trim() : null };
134
+ }
135
+ catch (_a) {
136
+ return { notes: null, suggestion: null };
137
+ }
138
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTranscriptionConfig = getTranscriptionConfig;
4
+ exports.getTranscriptionStatus = getTranscriptionStatus;
5
+ exports.saveTranscriptionConfig = saveTranscriptionConfig;
6
+ exports.getAudioDevices = getAudioDevices;
7
+ const configFile_1 = require("./configFile");
8
+ // Azure (AI Foundry deployment) takes precedence when configured; plain
9
+ // OpenAI key works as before.
10
+ function getTranscriptionConfig(file = configFile_1.CONFIG_FILE) {
11
+ const cfg = (0, configFile_1.readConfig)(file);
12
+ const { azureEndpoint, azureApiKey, azureDeployment } = cfg;
13
+ if (typeof azureEndpoint === 'string' && azureEndpoint && typeof azureApiKey === 'string' && azureApiKey) {
14
+ return {
15
+ kind: 'azure',
16
+ endpoint: azureEndpoint.replace(/\/+$/, ''),
17
+ apiKey: azureApiKey,
18
+ deployment: typeof azureDeployment === 'string' && azureDeployment ? azureDeployment : 'gpt-4o-transcribe',
19
+ };
20
+ }
21
+ const key = process.env.OPENAI_API_KEY || cfg.openaiApiKey;
22
+ if (typeof key === 'string' && key)
23
+ return { kind: 'openai', apiKey: key };
24
+ return null;
25
+ }
26
+ function getTranscriptionStatus(file = configFile_1.CONFIG_FILE) {
27
+ const c = getTranscriptionConfig(file);
28
+ const hint = (k) => '…' + k.slice(-4);
29
+ if (!c)
30
+ return { provider: null, keyHint: null, fromEnv: false, endpoint: null, deployment: null };
31
+ if (c.kind === 'azure')
32
+ return { provider: 'azure', keyHint: hint(c.apiKey), fromEnv: false, endpoint: c.endpoint, deployment: c.deployment };
33
+ return { provider: 'openai', keyHint: hint(c.apiKey), fromEnv: !(0, configFile_1.readConfig)(file).openaiApiKey, endpoint: null, deployment: null };
34
+ }
35
+ // Saves provider settings into config.json (0600, other keys kept). An empty
36
+ // apiKey keeps the saved one, so the UI never needs to know it.
37
+ function saveTranscriptionConfig(input, file = configFile_1.CONFIG_FILE) {
38
+ const cfg = (0, configFile_1.readConfig)(file);
39
+ const str = (v) => (typeof v === 'string' ? v.trim() : '');
40
+ if (input.provider === 'none') {
41
+ for (const k of ['azureEndpoint', 'azureApiKey', 'azureDeployment', 'openaiApiKey'])
42
+ delete cfg[k];
43
+ }
44
+ else if (input.provider === 'openai') {
45
+ const key = str(input.apiKey) || str(cfg.openaiApiKey);
46
+ if (!key)
47
+ throw new Error('API key is required');
48
+ for (const k of ['azureEndpoint', 'azureApiKey', 'azureDeployment'])
49
+ delete cfg[k];
50
+ cfg.openaiApiKey = key;
51
+ }
52
+ else if (input.provider === 'azure') {
53
+ const endpoint = str(input.endpoint);
54
+ let url;
55
+ try {
56
+ url = new URL(endpoint);
57
+ }
58
+ catch (_a) {
59
+ throw new Error('Endpoint must be a URL');
60
+ }
61
+ if (url.protocol !== 'https:')
62
+ throw new Error('Endpoint must use https');
63
+ const key = str(input.apiKey) || str(cfg.azureApiKey);
64
+ if (!key)
65
+ throw new Error('API key is required');
66
+ delete cfg.openaiApiKey;
67
+ Object.assign(cfg, { azureEndpoint: endpoint, azureApiKey: key, azureDeployment: str(input.deployment) || 'gpt-4o-transcribe' });
68
+ }
69
+ else {
70
+ throw new Error('Unknown provider');
71
+ }
72
+ (0, configFile_1.writeConfig)(cfg, file);
73
+ return getTranscriptionStatus(file);
74
+ }
75
+ function getAudioDevices() {
76
+ const cfg = (0, configFile_1.readConfig)();
77
+ return {
78
+ system: typeof cfg.systemAudioDevice === 'string' && cfg.systemAudioDevice ? cfg.systemAudioDevice : 'BlackHole 2ch',
79
+ mic: typeof cfg.micDevice === 'string' && cfg.micDevice ? cfg.micDevice : 'MacBook Pro Microphone',
80
+ };
81
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_CONTEXT_CHARS = void 0;
4
+ exports.resolveContext = resolveContext;
5
+ const path_1 = require("path");
6
+ const fs_1 = require("fs");
7
+ const meetingStore_1 = require("./meetingStore");
8
+ const liveSessionStore_1 = require("./liveSessionStore");
9
+ const orgRegistry_1 = require("./orgRegistry");
10
+ const sessionNameStore_1 = require("./sessionNameStore");
11
+ const sessionStore_1 = require("./sessionStore");
12
+ const ptyManager_1 = require("./ptyManager");
13
+ // ponytail: hard cap per item; summarize long sources first if this proves too small.
14
+ exports.MAX_CONTEXT_CHARS = 40000;
15
+ const clip = (s) => (s.length > exports.MAX_CONTEXT_CHARS ? '…' + s.slice(-exports.MAX_CONTEXT_CHARS) : s);
16
+ // Turns what the user picked into text (or a reference) for the assistant.
17
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
18
+ // Finds <id>.jsonl under any org's projects root (ids are UUIDs, so no path tricks).
19
+ function findTranscript(id) {
20
+ for (const { root } of orgRegistry_1.orgRegistry.projectRoots()) {
21
+ let dirs;
22
+ try {
23
+ dirs = (0, fs_1.readdirSync)(root);
24
+ }
25
+ catch (_a) {
26
+ continue;
27
+ }
28
+ for (const d of dirs) {
29
+ const f = (0, path_1.join)(root, d, `${id}.jsonl`);
30
+ if ((0, fs_1.existsSync)(f))
31
+ return f;
32
+ }
33
+ }
34
+ return null;
35
+ }
36
+ async function resolveContext(kind, value) {
37
+ var _a, _b, _c, _d, _e, _f;
38
+ const v = value.trim();
39
+ if (!v)
40
+ throw new Error('Nothing to add');
41
+ if (kind === 'text')
42
+ return { label: v.split('\n')[0].slice(0, 60), body: clip(v), fetch: false };
43
+ if (kind === 'link')
44
+ return { label: v.slice(0, 80), body: v, fetch: true };
45
+ if (kind === 'slack') {
46
+ const channel = v.startsWith('http') ? v : '#' + v.replace(/^#/, '');
47
+ return { label: `Slack: ${channel}`, body: `the Slack channel ${channel}. Use the Slack connector to read its messages from the last 7 days, including thread replies that matter`, fetch: true };
48
+ }
49
+ if (kind === 'meeting') {
50
+ const m = meetingStore_1.meetingStore.get(v);
51
+ if (!m)
52
+ throw new Error('Meeting not found');
53
+ const notes = meetingStore_1.meetingStore.readNotes(v);
54
+ const summary = meetingStore_1.meetingStore.readSummary(v);
55
+ const parts = [`Past meeting "${m.title}" on ${new Date(m.startedAt).toLocaleString()}`];
56
+ if (summary)
57
+ parts.push(summary);
58
+ else if (notes)
59
+ parts.push(`Decisions:\n- ${notes.decisions.join('\n- ')}\nAction items:\n- ${notes.actionItems.join('\n- ')}`);
60
+ else
61
+ parts.push(meetingStore_1.meetingStore.readTranscript(v).map(s => s.text).join('\n'));
62
+ return { label: `Meeting: ${m.title}`, body: clip(parts.join('\n\n')), fetch: false };
63
+ }
64
+ if (kind === 'session') {
65
+ // A live card id, or a Claude session id from History
66
+ const s = liveSessionStore_1.liveSessionStore.get(v);
67
+ const claudeId = (_a = s === null || s === void 0 ? void 0 : s.claudeSessionId) !== null && _a !== void 0 ? _a : (UUID.test(v) ? v : null);
68
+ const file = (s === null || s === void 0 ? void 0 : s.claudeSessionId)
69
+ ? (0, path_1.join)((0, ptyManager_1.claudeProjectDir)(s.cwd, (_b = orgRegistry_1.orgRegistry.get(s.orgId)) === null || _b === void 0 ? void 0 : _b.configDir), `${s.claudeSessionId}.jsonl`)
70
+ : claudeId ? findTranscript(claudeId) : null;
71
+ if (!claudeId || !file || !(0, fs_1.existsSync)(file))
72
+ throw new Error('Session not found or has no Claude transcript yet');
73
+ const msgs = await (0, sessionStore_1.getSessionMessages)(file, 40);
74
+ if (msgs.length === 0)
75
+ throw new Error('Session transcript is empty');
76
+ const names = sessionNameStore_1.sessionNameStore.all();
77
+ const name = (_f = (_d = (_c = (s && names[s.id])) !== null && _c !== void 0 ? _c : names[claudeId]) !== null && _d !== void 0 ? _d : (_e = (0, sessionStore_1.firstUserMessageSync)(file)) === null || _e === void 0 ? void 0 : _e.slice(0, 60)) !== null && _f !== void 0 ? _f : claudeId;
78
+ const text = msgs.map(m => `${m.role === 'user' ? 'User' : 'Claude'}: ${m.content}`).join('\n\n');
79
+ return { label: `Session: ${name}`, body: clip(`Claude Code session${s ? ` in ${s.cwd}` : ''}\n\n${text}`), fetch: false };
80
+ }
81
+ throw new Error('Unknown context type');
82
+ }
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.meetingManager = void 0;
5
+ const meetingStore_1 = require("./meetingStore");
6
+ const meetingContext_1 = require("./meetingContext");
7
+ const crypto_1 = require("crypto");
8
+ const audioCapture_1 = require("./audioCapture");
9
+ const transcriber_1 = require("./transcriber");
10
+ const meetingAssistant_1 = require("./meetingAssistant");
11
+ const meetingConfig_1 = require("./meetingConfig");
12
+ const orgRegistry_1 = require("./orgRegistry");
13
+ const NOTES_TICK_MS = 90000;
14
+ class MeetingManager {
15
+ constructor() {
16
+ this.active = new Map();
17
+ this.listeners = new Set();
18
+ }
19
+ on(fn) {
20
+ this.listeners.add(fn);
21
+ return () => { this.listeners.delete(fn); };
22
+ }
23
+ emit(ev) {
24
+ this.listeners.forEach(fn => fn(ev));
25
+ }
26
+ activeMeetings() {
27
+ return Array.from(this.active.values()).map(a => a.meeting);
28
+ }
29
+ micTest() {
30
+ return (0, audioCapture_1.micTest)((0, meetingConfig_1.getAudioDevices)());
31
+ }
32
+ 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
+ }
36
+ return this.begin(meetingStore_1.meetingStore.create(title, orgId || orgRegistry_1.DEFAULT_ORG_ID));
37
+ }
38
+ // Continue an ended/interrupted meeting: same transcript, notes and assistant
39
+ // conversation; new audio is appended. The summary is rewritten on stop.
40
+ resume(meetingId) {
41
+ 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
+ }
45
+ const existing = meetingStore_1.meetingStore.get(meetingId);
46
+ if (!existing)
47
+ return { error: 'Meeting not found' };
48
+ if (this.active.has(meetingId) || existing.status === 'recording')
49
+ return { error: 'Meeting is already recording' };
50
+ if (this.active.size > 0)
51
+ return { error: 'Another meeting is recording. Stop it first.' };
52
+ const meeting = (_a = meetingStore_1.meetingStore.update(meetingId, { status: 'recording', endedAt: null })) !== null && _a !== void 0 ? _a : existing;
53
+ return this.begin(meeting);
54
+ }
55
+ begin(meeting) {
56
+ var _a, _b;
57
+ const org = orgRegistry_1.orgRegistry.get(meeting.orgId);
58
+ const assistant = new meetingAssistant_1.MeetingAssistant({
59
+ cwd: meetingStore_1.meetingStore.dir(meeting.id),
60
+ configDir: (_a = org === null || org === void 0 ? void 0 : org.configDir) !== null && _a !== void 0 ? _a : null,
61
+ model: (_b = org === null || org === void 0 ? void 0 : org.model) !== null && _b !== void 0 ? _b : null,
62
+ }, meeting.claudeSessionId);
63
+ assistant.onSessionId = (sid) => {
64
+ const updated = meetingStore_1.meetingStore.update(meeting.id, { claudeSessionId: sid });
65
+ const a = this.active.get(meeting.id);
66
+ if (a && updated)
67
+ a.meeting = updated;
68
+ };
69
+ // On resume, the earlier transcript was already sent to the assistant
70
+ const priorText = meetingStore_1.meetingStore.readTranscript(meeting.id).map(s => s.text).join('\n');
71
+ const active = {
72
+ meeting,
73
+ assistant,
74
+ chunkQueue: [],
75
+ transcribing: false,
76
+ restarted: false,
77
+ sentTranscriptChars: priorText.length,
78
+ transcriptText: priorText,
79
+ capture: this.spawnCapture(meeting.id),
80
+ notesTimer: setInterval(() => this.notesTick(meeting.id), NOTES_TICK_MS),
81
+ };
82
+ this.active.set(meeting.id, active);
83
+ this.emit({ type: 'meeting-status', meeting });
84
+ return meeting;
85
+ }
86
+ spawnCapture(meetingId) {
87
+ return (0, audioCapture_1.startCapture)(meetingStore_1.meetingStore.dir(meetingId), (0, meetingConfig_1.getAudioDevices)(), {
88
+ onChunk: (filePath) => this.enqueueChunk(meetingId, filePath),
89
+ onExit: (code, stderrTail) => {
90
+ var _a;
91
+ const a = this.active.get(meetingId);
92
+ if (!a)
93
+ return;
94
+ // One automatic restart; a second death surfaces to the user
95
+ if (!a.restarted) {
96
+ a.restarted = true;
97
+ a.capture = this.spawnCapture(meetingId);
98
+ this.emit({ type: 'meeting-error', meetingId, message: 'Audio capture restarted after an unexpected exit' });
99
+ }
100
+ else {
101
+ this.emit({ type: 'meeting-error', meetingId, message: `Audio capture died (ffmpeg exit ${code}): ${(_a = stderrTail.split('\n').at(-1)) !== null && _a !== void 0 ? _a : ''}` });
102
+ this.stop(meetingId).catch(() => { });
103
+ }
104
+ },
105
+ });
106
+ }
107
+ enqueueChunk(meetingId, filePath) {
108
+ const a = this.active.get(meetingId);
109
+ if (!a)
110
+ return;
111
+ a.chunkQueue.push(filePath);
112
+ this.drainChunks(meetingId);
113
+ }
114
+ async drainChunks(meetingId) {
115
+ const a = this.active.get(meetingId);
116
+ if (!a || a.transcribing)
117
+ return;
118
+ a.transcribing = true;
119
+ try {
120
+ const config = (0, meetingConfig_1.getTranscriptionConfig)();
121
+ while (a.chunkQueue.length > 0) {
122
+ const filePath = a.chunkQueue.shift();
123
+ if (!config)
124
+ continue;
125
+ try {
126
+ // Last ~200 chars of transcript as context for language consistency
127
+ const text = await (0, transcriber_1.transcribeChunk)(filePath, config, a.transcriptText.slice(-200));
128
+ if (text) {
129
+ const segment = { t: Date.now(), text };
130
+ meetingStore_1.meetingStore.appendTranscript(meetingId, segment);
131
+ a.transcriptText += (a.transcriptText ? '\n' : '') + text;
132
+ this.emit({ type: 'meeting-transcript', meetingId, segment });
133
+ }
134
+ }
135
+ catch (e) {
136
+ this.emit({ type: 'meeting-error', meetingId, message: `Transcription gap: ${e instanceof Error ? e.message : 'unknown error'}` });
137
+ }
138
+ }
139
+ }
140
+ finally {
141
+ a.transcribing = false;
142
+ }
143
+ }
144
+ transcriptDelta(a) {
145
+ const delta = a.transcriptText.slice(a.sentTranscriptChars);
146
+ a.sentTranscriptChars = a.transcriptText.length;
147
+ return delta;
148
+ }
149
+ async notesTick(meetingId) {
150
+ const a = this.active.get(meetingId);
151
+ if (!a)
152
+ return;
153
+ const delta = a.transcriptText.slice(a.sentTranscriptChars);
154
+ if (!delta.trim())
155
+ return; // nobody said anything new — skip the call
156
+ a.sentTranscriptChars = a.transcriptText.length;
157
+ try {
158
+ const { notes, suggestion } = await a.assistant.notesTick(delta);
159
+ if (notes) {
160
+ meetingStore_1.meetingStore.saveNotes(meetingId, notes);
161
+ this.emit({ type: 'meeting-notes', meetingId, notes });
162
+ }
163
+ if (suggestion)
164
+ this.emit({ type: 'meeting-suggestion', meetingId, suggestion });
165
+ }
166
+ catch (e) {
167
+ // Notes going stale is fine; next tick retries with a bigger delta
168
+ this.emit({ type: 'meeting-error', meetingId, message: `Notes update failed (will retry): ${e instanceof Error ? e.message : 'unknown'}` });
169
+ a.sentTranscriptChars -= delta.length; // resend this delta next tick
170
+ }
171
+ }
172
+ async ask(meetingId, question) {
173
+ const a = this.active.get(meetingId);
174
+ if (!a) {
175
+ this.emit({ type: 'meeting-error', meetingId, message: 'Meeting is not active' });
176
+ return;
177
+ }
178
+ try {
179
+ const answer = await a.assistant.ask(question, this.transcriptDelta(a));
180
+ this.emit({ type: 'meeting-answer', meetingId, question, answer });
181
+ }
182
+ catch (e) {
183
+ this.emit({ type: 'meeting-error', meetingId, message: `Ask failed: ${e instanceof Error ? e.message : 'unknown'}` });
184
+ }
185
+ }
186
+ async addContext(meetingId, kind, value) {
187
+ const a = this.active.get(meetingId);
188
+ if (!a) {
189
+ this.emit({ type: 'meeting-error', meetingId, message: 'Context can only be added while the meeting is recording' });
190
+ return;
191
+ }
192
+ const item = { id: (0, crypto_1.randomUUID)(), kind, label: value.trim().slice(0, 60) || kind, value, addedAt: Date.now(), status: 'loading', summary: null };
193
+ const save = (patch) => {
194
+ const items = meetingStore_1.meetingStore.readContext(meetingId);
195
+ const i = items.findIndex(x => x.id === item.id);
196
+ if (i >= 0)
197
+ items[i] = Object.assign(Object.assign({}, items[i]), patch);
198
+ else
199
+ items.push(Object.assign(Object.assign({}, item), patch));
200
+ meetingStore_1.meetingStore.saveContext(meetingId, items);
201
+ this.emit({ type: 'meeting-context', meetingId, items });
202
+ };
203
+ save({});
204
+ try {
205
+ const resolved = await (0, meetingContext_1.resolveContext)(kind, value);
206
+ save({ label: resolved.label });
207
+ const reply = (await a.assistant.addContext(resolved.label, resolved.body, resolved.fetch)).trim().split('\n')[0];
208
+ save(/^FAILED/i.test(reply) ? { status: 'failed', summary: reply.replace(/^FAILED:?\s*/i, '') } : { status: 'loaded', summary: reply });
209
+ }
210
+ catch (e) {
211
+ save({ status: 'failed', summary: e instanceof Error ? e.message : 'unknown error' });
212
+ }
213
+ }
214
+ async stop(meetingId) {
215
+ var _a, _b;
216
+ const a = this.active.get(meetingId);
217
+ if (!a)
218
+ return;
219
+ clearInterval(a.notesTimer);
220
+ // Graceful ffmpeg stop flushes the final chunks into the queue (the
221
+ // meeting must still be in `active` for enqueueChunk to accept them)
222
+ await a.capture.stop();
223
+ this.drainChunks(meetingId);
224
+ // Wait for the final chunks to transcribe, but cap it — a wedged transcribe
225
+ // must never hang teardown forever (transcribeChunk itself now times out at
226
+ // 30s/attempt, so ~45s is a generous ceiling past normal drain).
227
+ const drainDeadline = Date.now() + 45000;
228
+ while ((a.chunkQueue.length > 0 || a.transcribing) && Date.now() < drainDeadline) {
229
+ await new Promise(r => setTimeout(r, 250));
230
+ }
231
+ this.active.delete(meetingId);
232
+ let meeting = (_a = meetingStore_1.meetingStore.update(meetingId, { status: 'ended', endedAt: Date.now() })) !== null && _a !== void 0 ? _a : a.meeting;
233
+ this.emit({ type: 'meeting-status', meeting });
234
+ try {
235
+ const summary = await a.assistant.summarize(this.transcriptDelta(a));
236
+ if (summary.trim())
237
+ meetingStore_1.meetingStore.saveSummary(meetingId, summary);
238
+ }
239
+ catch (e) {
240
+ this.emit({ type: 'meeting-error', meetingId, message: `Summary failed: ${e instanceof Error ? e.message : 'unknown'}` });
241
+ }
242
+ meeting = (_b = meetingStore_1.meetingStore.get(meetingId)) !== null && _b !== void 0 ? _b : meeting;
243
+ this.emit({ type: 'meeting-status', meeting });
244
+ }
245
+ }
246
+ exports.meetingManager = (_a = global.__meetingManager) !== null && _a !== void 0 ? _a : (global.__meetingManager = new MeetingManager());