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,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLoopLog = parseLoopLog;
4
+ exports.listLoops = listLoops;
5
+ exports.listHooks = listHooks;
6
+ exports.runLoopNow = runLoopNow;
7
+ exports.loopLogTail = loopLogTail;
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const child_process_1 = require("child_process");
11
+ const util_1 = require("util");
12
+ const orgRegistry_1 = require("./orgRegistry");
13
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
14
+ const HOME = () => process.env.HOME;
15
+ // Splits a loop log into runs: "=== 2026-11-20 16:10:04 board (model, prompt)" + output lines
16
+ function parseLoopLog(text) {
17
+ const runs = [];
18
+ for (const line of text.split('\n')) {
19
+ const m = line.match(/^=== (\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) \S+ \(([^,)]+)/);
20
+ if (m)
21
+ runs.push({ at: m[1], model: m[2], output: '' });
22
+ else if (runs.length && line.trim())
23
+ runs[runs.length - 1].output += (runs[runs.length - 1].output ? '\n' : '') + line;
24
+ }
25
+ return runs;
26
+ }
27
+ async function launchdStatus() {
28
+ const out = await execFileAsync('launchctl', ['list'], { timeout: 5000 }).then(r => r.stdout).catch(() => '');
29
+ const map = new Map();
30
+ for (const line of out.split('\n').slice(1)) {
31
+ const [pid, exit, label] = line.split('\t');
32
+ if (label)
33
+ map.set(label, { pid: pid === '-' ? null : Number(pid), exit: exit === '-' ? null : Number(exit) });
34
+ }
35
+ return map;
36
+ }
37
+ async function listLoops() {
38
+ var _a, _b, _c, _d, _e;
39
+ const dir = (0, path_1.join)(HOME(), 'Library', 'LaunchAgents');
40
+ let files = [];
41
+ try {
42
+ files = (0, fs_1.readdirSync)(dir).filter(f => f.endsWith('.plist'));
43
+ }
44
+ catch (_f) {
45
+ return [];
46
+ }
47
+ const status = await launchdStatus();
48
+ const loops = [];
49
+ for (const f of files) {
50
+ const path = (0, path_1.join)(dir, f);
51
+ let raw = '';
52
+ try {
53
+ raw = (0, fs_1.readFileSync)(path, 'utf-8');
54
+ }
55
+ catch (_g) {
56
+ continue;
57
+ }
58
+ if (!/claude/i.test(raw))
59
+ continue;
60
+ let j;
61
+ try {
62
+ j = JSON.parse((await execFileAsync('plutil', ['-convert', 'json', '-o', '-', path], { timeout: 5000 })).stdout);
63
+ }
64
+ catch (_h) {
65
+ continue;
66
+ }
67
+ const args = (_a = j.ProgramArguments) !== null && _a !== void 0 ? _a : [];
68
+ const label = (_b = j.Label) !== null && _b !== void 0 ? _b : f.replace(/\.plist$/, '');
69
+ // ~/.claude/loops/run.sh <name> → prompts/<name>.md and logs/<name>.log
70
+ const runSh = args.findIndex(a => a.endsWith('/loops/run.sh'));
71
+ const name = runSh >= 0 ? args[runSh + 1] : null;
72
+ const loopsDir = runSh >= 0 ? args[runSh].replace(/\/run\.sh$/, '') : null;
73
+ const logFile = loopsDir && name ? (0, path_1.join)(loopsDir, 'logs', `${name}.log`) : (_c = j.StandardOutPath) !== null && _c !== void 0 ? _c : null;
74
+ let lastRun = null, model = null;
75
+ if (logFile && (0, fs_1.existsSync)(logFile)) {
76
+ const runs = parseLoopLog((0, fs_1.readFileSync)(logFile, 'utf-8').slice(-20000));
77
+ const last = runs.at(-1);
78
+ if (last) {
79
+ lastRun = { at: last.at, output: last.output.slice(0, 600) };
80
+ model = last.model;
81
+ }
82
+ }
83
+ let prompt = null;
84
+ if (loopsDir && name) {
85
+ try {
86
+ prompt = (0, fs_1.readFileSync)((0, path_1.join)(loopsDir, 'prompts', `${name}.md`), 'utf-8').slice(0, 1500);
87
+ }
88
+ catch ( /* none */_j) { /* none */ }
89
+ }
90
+ const st = status.get(label);
91
+ loops.push({
92
+ label, command: args.join(' '), everySec: (_d = j.StartInterval) !== null && _d !== void 0 ? _d : null,
93
+ calendar: j.StartCalendarInterval ? JSON.stringify(j.StartCalendarInterval) : null,
94
+ running: !!(st === null || st === void 0 ? void 0 : st.pid), lastExit: (_e = st === null || st === void 0 ? void 0 : st.exit) !== null && _e !== void 0 ? _e : null, model, prompt, lastRun, logFile,
95
+ });
96
+ }
97
+ return loops.sort((a, b) => a.label.localeCompare(b.label));
98
+ }
99
+ function listHooks() {
100
+ var _a, _b, _c, _d;
101
+ const out = [];
102
+ for (const org of orgRegistry_1.orgRegistry.list()) {
103
+ try {
104
+ const s = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(org.configDir || (0, path_1.join)(HOME(), '.claude'), 'settings.json'), 'utf-8'));
105
+ for (const [event, groups] of Object.entries((_a = s.hooks) !== null && _a !== void 0 ? _a : {})) {
106
+ for (const g of groups)
107
+ for (const h of (_b = g.hooks) !== null && _b !== void 0 ? _b : [])
108
+ out.push({ org: org.name, event, matcher: (_c = g.matcher) !== null && _c !== void 0 ? _c : '', command: String((_d = h.command) !== null && _d !== void 0 ? _d : '').slice(0, 300) });
109
+ }
110
+ }
111
+ catch ( /* no settings */_e) { /* no settings */ }
112
+ }
113
+ return out;
114
+ }
115
+ async function runLoopNow(label) {
116
+ var _a, _b;
117
+ if (!(await listLoops()).some(l => l.label === label))
118
+ throw new Error('Unknown loop');
119
+ const uid = (_b = (_a = process.getuid) === null || _a === void 0 ? void 0 : _a.call(process)) !== null && _b !== void 0 ? _b : 501;
120
+ await execFileAsync('launchctl', ['kickstart', `gui/${uid}/${label}`], { timeout: 10000 });
121
+ }
122
+ function loopLogTail(label, loops, lines = 80) {
123
+ const l = loops.find(x => x.label === label);
124
+ if (!(l === null || l === void 0 ? void 0 : l.logFile))
125
+ return '';
126
+ try {
127
+ return (0, fs_1.readFileSync)(l.logFile, 'utf-8').split('\n').slice(-lines).join('\n');
128
+ }
129
+ catch (_a) {
130
+ return '';
131
+ }
132
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.buildInbox = buildInbox;
5
+ exports.getInbox = getInbox;
6
+ const child_process_1 = require("child_process");
7
+ const util_1 = require("util");
8
+ const ghPrStatus_1 = require("./ghPrStatus");
9
+ const prSessionEntries_1 = require("./prSessionEntries");
10
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
11
+ const CACHE_TTL_MS = 5 * 60 * 1000;
12
+ const MERGED_SECTION_DAYS = 7;
13
+ const STATS_WINDOW_WEEKS = 8;
14
+ const SEARCH_LIMIT = '50';
15
+ const MERGED_SEARCH_LIMIT = '200';
16
+ // gh must use the local keyring credentials (which can see private orgs), so
17
+ // any GITHUB_TOKEN/GH_TOKEN in the server's environment is stripped.
18
+ function ghEnv() {
19
+ const env = Object.assign({}, process.env);
20
+ delete env.GITHUB_TOKEN;
21
+ delete env.GH_TOKEN;
22
+ return env;
23
+ }
24
+ async function ghSearchPrs(args, limit = SEARCH_LIMIT) {
25
+ const { stdout } = await execFileAsync('gh', [
26
+ 'search', 'prs', ...args,
27
+ '--json', 'url,title,repository,updatedAt,createdAt,closedAt,isDraft',
28
+ '--limit', limit,
29
+ ], { timeout: 30000, env: ghEnv(), maxBuffer: 10 * 1024 * 1024 });
30
+ return JSON.parse(stdout);
31
+ }
32
+ function parseMs(iso) {
33
+ const t = iso ? Date.parse(iso) : NaN;
34
+ return Number.isNaN(t) ? 0 : t;
35
+ }
36
+ function toInboxPr(item, sessionByUrl) {
37
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
38
+ const session = sessionByUrl.get(item.url);
39
+ // gh reports Go's zero time ("0001-01-01T00:00:00Z") for open PRs' closedAt
40
+ // — it parses to a large negative number, so only positive times count
41
+ const closedAt = parseMs(item.closedAt);
42
+ return {
43
+ url: item.url,
44
+ title: item.title,
45
+ repo: (_d = (_b = (_a = item.repository) === null || _a === void 0 ? void 0 : _a.nameWithOwner) !== null && _b !== void 0 ? _b : (_c = item.url.match(/github\.com\/([\w.-]+\/[\w.-]+)/)) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : '',
46
+ updatedAt: parseMs(item.updatedAt),
47
+ createdAt: parseMs(item.createdAt),
48
+ closedAt: closedAt > 0 ? closedAt : null,
49
+ isDraft: (_e = item.isDraft) !== null && _e !== void 0 ? _e : false,
50
+ status: (_f = ghPrStatus_1.prStatusCache.get(item.url)) !== null && _f !== void 0 ? _f : null,
51
+ liveId: (_g = session === null || session === void 0 ? void 0 : session.liveId) !== null && _g !== void 0 ? _g : null,
52
+ sessionId: (_h = session === null || session === void 0 ? void 0 : session.sessionId) !== null && _h !== void 0 ? _h : null,
53
+ cwd: (_j = session === null || session === void 0 ? void 0 : session.cwd) !== null && _j !== void 0 ? _j : null,
54
+ };
55
+ }
56
+ // Monday 00:00 local time of the week containing `t`
57
+ function weekStartOf(t) {
58
+ const d = new Date(t);
59
+ d.setHours(0, 0, 0, 0);
60
+ d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
61
+ return d.getTime();
62
+ }
63
+ // Your PR is back in your court when a reviewer asked for changes or CI is red
64
+ function isReturned(status) {
65
+ return !!status && status.state === 'OPEN' &&
66
+ (status.reviewDecision === 'CHANGES_REQUESTED' || status.checks === 'failing');
67
+ }
68
+ async function buildInbox() {
69
+ var _a, _b, _c, _d;
70
+ // Merged query spans the stats window (8 weeks); the "Recently merged"
71
+ // section shows only the last 7 days of it
72
+ const mergedSince = new Date(weekStartOf(Date.now()) - (STATS_WINDOW_WEEKS - 1) * 7 * 86400000).toISOString().slice(0, 10);
73
+ const [authoredRes, reviewRes, mergedRes, sessionEntries] = await Promise.allSettled([
74
+ ghSearchPrs(['--author=@me', '--state=open']),
75
+ ghSearchPrs(['--review-requested=@me', '--state=open']),
76
+ ghSearchPrs(['--author=@me', '--merged', `--merged-at=>=${mergedSince}`], MERGED_SEARCH_LIMIT),
77
+ (0, prSessionEntries_1.buildPrSessionEntries)(),
78
+ ]).then(results => results.map(r => r.status === 'fulfilled' ? r.value : null));
79
+ const authored = (_a = authoredRes) !== null && _a !== void 0 ? _a : [];
80
+ const reviewRequested = (_b = reviewRes) !== null && _b !== void 0 ? _b : [];
81
+ const merged = (_c = mergedRes) !== null && _c !== void 0 ? _c : [];
82
+ const sessions = (_d = sessionEntries) !== null && _d !== void 0 ? _d : [];
83
+ const error = authoredRes === null && reviewRes === null
84
+ ? 'gh search failed — check `gh auth status` on the server machine'
85
+ : null;
86
+ const sessionByUrl = new Map(sessions.map(e => [e.prUrl, e]));
87
+ // Fresh review/checks detail for every open PR — this is what decides
88
+ // returned-vs-waiting, so it can't rely on a stale cache
89
+ const openUrls = [...authored, ...reviewRequested].map(i => i.url);
90
+ await (0, ghPrStatus_1.fetchAllPrStatuses)(openUrls);
91
+ const needsReview = [];
92
+ const returned = [];
93
+ const waiting = [];
94
+ const seen = new Set();
95
+ for (const item of reviewRequested) {
96
+ seen.add(item.url);
97
+ needsReview.push(toInboxPr(item, sessionByUrl));
98
+ }
99
+ for (const item of authored) {
100
+ if (seen.has(item.url))
101
+ continue;
102
+ seen.add(item.url);
103
+ const pr = toInboxPr(item, sessionByUrl);
104
+ if (isReturned(pr.status))
105
+ returned.push(pr);
106
+ else
107
+ waiting.push(pr);
108
+ }
109
+ const mergedAll = merged.filter(i => !seen.has(i.url)).map(i => toInboxPr(i, sessionByUrl));
110
+ const mergedRecent = mergedAll.filter(p => { var _a; return ((_a = p.closedAt) !== null && _a !== void 0 ? _a : 0) >= Date.now() - MERGED_SECTION_DAYS * 86400000; });
111
+ // Merged-per-week buckets across the full stats window (zero-filled)
112
+ const thisWeek = weekStartOf(Date.now());
113
+ const mergedByWeek = Array.from({ length: STATS_WINDOW_WEEKS }, (_, i) => ({
114
+ weekStart: thisWeek - (STATS_WINDOW_WEEKS - 1 - i) * 7 * 86400000,
115
+ count: 0,
116
+ }));
117
+ for (const p of mergedAll) {
118
+ if (!p.closedAt)
119
+ continue;
120
+ const bucket = mergedByWeek.find(b => weekStartOf(p.closedAt) === b.weekStart);
121
+ if (bucket)
122
+ bucket.count++;
123
+ }
124
+ const byUpdated = (a, b) => b.updatedAt - a.updatedAt;
125
+ needsReview.sort(byUpdated);
126
+ returned.sort(byUpdated);
127
+ waiting.sort(byUpdated);
128
+ mergedRecent.sort(byUpdated);
129
+ // Session PRs outside the workload, still relevant (open or status unknown)
130
+ const inboxUrls = new Set(Array.from(seen).concat(mergedRecent.map(p => p.url)));
131
+ const fromSessions = sessions.filter(e => !inboxUrls.has(e.prUrl) && (!e.status || e.status.state === 'OPEN'));
132
+ return {
133
+ sections: { needsReview, returned, waiting, mergedRecent },
134
+ fromSessions,
135
+ mergedByWeek,
136
+ mergedWindow: mergedAll.sort((a, b) => { var _a, _b; return ((_a = b.closedAt) !== null && _a !== void 0 ? _a : 0) - ((_b = a.closedAt) !== null && _b !== void 0 ? _b : 0); }),
137
+ fetchedAt: Date.now(),
138
+ error,
139
+ };
140
+ }
141
+ const st = (_a = global.__ghInbox) !== null && _a !== void 0 ? _a : (global.__ghInbox = { cached: null, inFlight: null });
142
+ async function getInbox(force = false) {
143
+ if (!force && st.cached && Date.now() - st.cached.fetchedAt < CACHE_TTL_MS)
144
+ return st.cached;
145
+ if (!st.inFlight) {
146
+ st.inFlight = buildInbox()
147
+ .then(inbox => { st.cached = inbox; return inbox; })
148
+ .finally(() => { st.inFlight = null; });
149
+ }
150
+ return st.inFlight;
151
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prStatusCache = void 0;
4
+ exports.isValidPrUrl = isValidPrUrl;
5
+ exports.summarizeChecks = summarizeChecks;
6
+ exports.fetchPrStatus = fetchPrStatus;
7
+ exports.fetchAllPrStatuses = fetchAllPrStatuses;
8
+ const child_process_1 = require("child_process");
9
+ const util_1 = require("util");
10
+ const prDetector_1 = require("./prDetector");
11
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
12
+ const CONCURRENCY = 6;
13
+ function isValidPrUrl(url) {
14
+ return prDetector_1.STRICT_PR_URL_RE.test(url);
15
+ }
16
+ // gh's statusCheckRollup mixes CheckRun (`status`/`conclusion`) and legacy
17
+ // StatusContext (`state`) shapes — normalize defensively; treat this as
18
+ // approximate and revisit if it misclassifies real PRs.
19
+ function summarizeChecks(items) {
20
+ if (!items || items.length === 0)
21
+ return 'none';
22
+ const FAILURE_CONCLUSIONS = new Set(['FAILURE', 'CANCELLED', 'TIMED_OUT', 'STARTUP_FAILURE']);
23
+ const FAILURE_STATES = new Set(['FAILURE', 'ERROR']);
24
+ const PENDING_STATUSES = new Set(['QUEUED', 'IN_PROGRESS', 'PENDING', 'WAITING', 'REQUESTED']);
25
+ const PENDING_STATES = new Set(['PENDING']);
26
+ let sawPending = false;
27
+ for (const item of items) {
28
+ if (item.conclusion && FAILURE_CONCLUSIONS.has(item.conclusion))
29
+ return 'failing';
30
+ if (item.state && FAILURE_STATES.has(item.state))
31
+ return 'failing';
32
+ if (item.status && PENDING_STATUSES.has(item.status) && !item.conclusion)
33
+ sawPending = true;
34
+ if (item.state && PENDING_STATES.has(item.state))
35
+ sawPending = true;
36
+ }
37
+ return sawPending ? 'pending' : 'passing';
38
+ }
39
+ // In-memory only — volatile data, cheap to refetch, intentionally lost on
40
+ // server restart. Populated only by explicit refresh calls (no background
41
+ // polling in this MVP).
42
+ exports.prStatusCache = new Map();
43
+ async function fetchPrStatus(url) {
44
+ var _a, _b;
45
+ if (!isValidPrUrl(url))
46
+ return null;
47
+ try {
48
+ const { stdout } = await execFileAsync('gh', [
49
+ 'pr', 'view', url,
50
+ '--json', 'state,reviewDecision,statusCheckRollup,number,title,updatedAt',
51
+ ], {
52
+ timeout: 8000,
53
+ env: Object.assign(Object.assign({}, process.env), (process.env.GITHUB_TOKEN ? { GITHUB_TOKEN: process.env.GITHUB_TOKEN } : {})),
54
+ });
55
+ const json = JSON.parse(stdout);
56
+ const updatedAt = json.updatedAt ? Date.parse(json.updatedAt) : NaN;
57
+ const status = {
58
+ number: json.number,
59
+ title: json.title,
60
+ state: json.state,
61
+ reviewDecision: (_a = json.reviewDecision) !== null && _a !== void 0 ? _a : null,
62
+ checks: summarizeChecks((_b = json.statusCheckRollup) !== null && _b !== void 0 ? _b : []),
63
+ updatedAt: Number.isNaN(updatedAt) ? null : updatedAt,
64
+ fetchedAt: Date.now(),
65
+ };
66
+ exports.prStatusCache.set(url, status);
67
+ return status;
68
+ }
69
+ catch (_c) {
70
+ return null;
71
+ }
72
+ }
73
+ // Concurrency-capped so one hung `gh` call can't block the rest.
74
+ async function fetchAllPrStatuses(urls) {
75
+ const unique = Array.from(new Set(urls));
76
+ const results = new Map();
77
+ for (let i = 0; i < unique.length; i += CONCURRENCY) {
78
+ const batch = unique.slice(i, i + CONCURRENCY);
79
+ const settled = await Promise.allSettled(batch.map(url => fetchPrStatus(url)));
80
+ settled.forEach((r, idx) => {
81
+ if (r.status === 'fulfilled' && r.value)
82
+ results.set(batch[idx], r.value);
83
+ });
84
+ }
85
+ return results;
86
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGitRoot = getGitRoot;
4
+ const child_process_1 = require("child_process");
5
+ const cache = new Map();
6
+ function getGitRoot(dir) {
7
+ if (!dir)
8
+ return null;
9
+ // ~/General/<hash> chat scratch dirs are never repos — skip the synchronous
10
+ // git spawn (hundreds of them made /api/sessions block for ~40s).
11
+ if (/\/General(\/[^/]+)?$/.test(dir))
12
+ return null;
13
+ if (cache.has(dir))
14
+ return cache.get(dir);
15
+ try {
16
+ const root = (0, child_process_1.execSync)(`git -C "${dir}" rev-parse --show-toplevel`, {
17
+ stdio: ['pipe', 'pipe', 'pipe'],
18
+ timeout: 3000,
19
+ }).toString().trim();
20
+ cache.set(dir, root);
21
+ return root;
22
+ }
23
+ catch (_a) {
24
+ cache.set(dir, null);
25
+ return null;
26
+ }
27
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keepAwake = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const settingsStore_1 = require("./settingsStore");
6
+ // Settings → "Keep Mac awake": runs `caffeinate -i` (no idle sleep; the screen can still
7
+ // lock and turn off) for as long as the server runs. Settings are saved by an API route
8
+ // (separate module copy), so re-read them every 15s.
9
+ // ponytail: macOS only; closing the lid still sleeps (needs sudo pmset, which we don't do).
10
+ class KeepAwake {
11
+ constructor() {
12
+ this.proc = null;
13
+ }
14
+ start() {
15
+ if (process.platform !== 'darwin')
16
+ return;
17
+ this.apply();
18
+ setInterval(() => this.apply(), 15000).unref();
19
+ }
20
+ apply() {
21
+ const want = (0, settingsStore_1.getSettings)().power.keepAwake;
22
+ if (want && !this.proc) {
23
+ this.proc = (0, child_process_1.spawn)('caffeinate', ['-i', '-w', String(process.pid)], { stdio: 'ignore' });
24
+ this.proc.on('exit', () => { this.proc = null; });
25
+ }
26
+ else if (!want && this.proc) {
27
+ this.proc.kill();
28
+ this.proc = null;
29
+ }
30
+ }
31
+ }
32
+ exports.keepAwake = new KeepAwake();
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.liveSessionStore = exports.LiveSessionStore = void 0;
5
+ const dataDir_1 = require("./dataDir");
6
+ const fs_1 = require("fs");
7
+ const path_1 = require("path");
8
+ const DEFAULT_PERSIST_DIR = dataDir_1.DATA_DIR;
9
+ const DEFAULT_PERSIST_FILE = (0, path_1.join)(DEFAULT_PERSIST_DIR, 'live-sessions.json');
10
+ class LiveSessionStore {
11
+ // persistFile defaults to the real on-disk location; tests must pass an
12
+ // isolated path so they never touch the user's actual session state.
13
+ constructor(persistFile = DEFAULT_PERSIST_FILE) {
14
+ this.sessions = new Map();
15
+ this.persistFile = persistFile;
16
+ this.persistDir = (0, path_1.join)(persistFile, '..');
17
+ }
18
+ add(session) {
19
+ this.sessions.set(session.id, session);
20
+ this.persist();
21
+ }
22
+ get(id) {
23
+ return this.sessions.get(id);
24
+ }
25
+ list() {
26
+ return Array.from(this.sessions.values());
27
+ }
28
+ setStatus(id, status) {
29
+ const s = this.sessions.get(id);
30
+ if (s)
31
+ s.status = status;
32
+ }
33
+ setClaudeSessionId(id, claudeSessionId) {
34
+ const s = this.sessions.get(id);
35
+ if (s) {
36
+ s.claudeSessionId = claudeSessionId;
37
+ this.persist();
38
+ }
39
+ }
40
+ setRcUrl(id, rcUrl) {
41
+ const s = this.sessions.get(id);
42
+ if (s)
43
+ s.rcUrl = rcUrl;
44
+ }
45
+ setPrUrl(id, prUrl) {
46
+ const s = this.sessions.get(id);
47
+ if (s && s.prUrl !== prUrl) {
48
+ s.prUrl = prUrl;
49
+ this.persist();
50
+ }
51
+ }
52
+ remove(id) {
53
+ this.sessions.delete(id);
54
+ this.persist();
55
+ }
56
+ persist() {
57
+ try {
58
+ if (!(0, fs_1.existsSync)(this.persistDir))
59
+ (0, fs_1.mkdirSync)(this.persistDir, { recursive: true });
60
+ const saved = Array.from(this.sessions.values()).map(s => ({
61
+ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, orgId: s.orgId, backend: s.backend, model: s.model, rc: s.rc, worktree: s.worktree,
62
+ }));
63
+ (0, fs_1.writeFileSync)(this.persistFile, JSON.stringify(saved));
64
+ }
65
+ catch (_a) { }
66
+ }
67
+ // Keeps the last 5 boot-time copies so a bad restore is recoverable.
68
+ static backupSaved(persistFile = DEFAULT_PERSIST_FILE) {
69
+ try {
70
+ if (!(0, fs_1.existsSync)(persistFile))
71
+ return;
72
+ const dir = (0, path_1.dirname)(persistFile);
73
+ (0, fs_1.copyFileSync)(persistFile, (0, path_1.join)(dir, `live-sessions.boot-${Date.now()}.json`));
74
+ (0, fs_1.readdirSync)(dir).filter(f => f.startsWith('live-sessions.boot-')).sort().slice(0, -5)
75
+ .forEach(f => (0, fs_1.unlinkSync)((0, path_1.join)(dir, f)));
76
+ }
77
+ catch (_a) { }
78
+ }
79
+ static loadSaved(persistFile = DEFAULT_PERSIST_FILE) {
80
+ try {
81
+ return JSON.parse((0, fs_1.readFileSync)(persistFile, 'utf-8'));
82
+ }
83
+ catch (_a) {
84
+ return [];
85
+ }
86
+ }
87
+ }
88
+ exports.LiveSessionStore = LiveSessionStore;
89
+ exports.liveSessionStore = (_a = global.__liveSessionStore) !== null && _a !== void 0 ? _a : (global.__liveSessionStore = new LiveSessionStore());
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listMarketplacePlugins = listMarketplacePlugins;
4
+ exports.installPlugin = installPlugin;
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const child_process_1 = require("child_process");
8
+ const util_1 = require("util");
9
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
10
+ const pluginsDir = (configDir) => (0, path_1.join)(configDir || (0, path_1.join)(process.env.HOME, '.claude'), 'plugins');
11
+ const SAFE = /^[\w.-]{1,100}$/;
12
+ function installedIds(configDir) {
13
+ var _a;
14
+ try {
15
+ const d = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(pluginsDir(configDir), 'installed_plugins.json'), 'utf-8'));
16
+ return new Set(Object.keys((_a = d.plugins) !== null && _a !== void 0 ? _a : d));
17
+ }
18
+ catch (_b) {
19
+ return new Set();
20
+ }
21
+ }
22
+ function listMarketplacePlugins(configDir) {
23
+ var _a, _b, _c;
24
+ const installed = installedIds(configDir);
25
+ const out = [];
26
+ let markets = [];
27
+ try {
28
+ markets = (0, fs_1.readdirSync)((0, path_1.join)(pluginsDir(configDir), 'marketplaces'));
29
+ }
30
+ catch (_d) {
31
+ return [];
32
+ }
33
+ for (const m of markets) {
34
+ try {
35
+ const d = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(pluginsDir(configDir), 'marketplaces', m, '.claude-plugin', 'marketplace.json'), 'utf-8'));
36
+ const market = typeof d.name === 'string' ? d.name : m;
37
+ for (const p of (_a = d.plugins) !== null && _a !== void 0 ? _a : []) {
38
+ if (typeof (p === null || p === void 0 ? void 0 : p.name) !== 'string')
39
+ continue;
40
+ out.push({ name: p.name, marketplace: market, description: String((_b = p.description) !== null && _b !== void 0 ? _b : ''), category: (_c = p.category) !== null && _c !== void 0 ? _c : null, installed: installed.has(`${p.name}@${market}`) });
41
+ }
42
+ }
43
+ catch ( /* unreadable marketplace */_e) { /* unreadable marketplace */ }
44
+ }
45
+ return out.sort((a, b) => Number(b.installed) - Number(a.installed) || a.name.localeCompare(b.name));
46
+ }
47
+ // Installs for the user (all projects). Plugins that need a marketplace-declared
48
+ // command to be accepted are refused here; the error says to install in a terminal.
49
+ async function installPlugin(name, marketplace, configDir) {
50
+ var _a, _b, _c, _d;
51
+ if (!SAFE.test(name) || !SAFE.test(marketplace))
52
+ throw new Error('Invalid plugin name');
53
+ try {
54
+ await execFileAsync('claude', ['plugin', 'install', `${name}@${marketplace}`, '--scope', 'user', '--json'], { timeout: 180000, maxBuffer: 5 * 1024 * 1024, env: Object.assign(Object.assign({}, process.env), (configDir ? { CLAUDE_CONFIG_DIR: configDir } : {})) });
55
+ }
56
+ catch (e) {
57
+ const err = e;
58
+ const text = `${(_a = err.stdout) !== null && _a !== void 0 ? _a : ''}\n${(_b = err.stderr) !== null && _b !== void 0 ? _b : ''}`.trim() || err.message;
59
+ throw new Error(/shownCommand|accept-command/.test(text)
60
+ ? `This plugin runs a setup command that needs your approval. Install it in a terminal: claude plugin install ${name}@${marketplace}`
61
+ : (_d = (_c = text.split('\n').filter(Boolean).at(-1)) === null || _c === void 0 ? void 0 : _c.slice(0, 300)) !== null && _d !== void 0 ? _d : 'Install failed');
62
+ }
63
+ }