polyergon 0.0.0-stage → 0.1.0

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 (230) 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/limits/route.js +1 -0
  25. package/.next/server/app/api/limits/route.js.nft.json +1 -0
  26. package/.next/server/app/api/meetings/[id]/route.js +1 -0
  27. package/.next/server/app/api/meetings/[id]/route.js.nft.json +1 -0
  28. package/.next/server/app/api/meetings/[id]/slack/route.js +3 -0
  29. package/.next/server/app/api/meetings/[id]/slack/route.js.nft.json +1 -0
  30. package/.next/server/app/api/meetings/library/route.js +1 -0
  31. package/.next/server/app/api/meetings/library/route.js.nft.json +1 -0
  32. package/.next/server/app/api/meetings/route.js +1 -0
  33. package/.next/server/app/api/meetings/route.js.nft.json +1 -0
  34. package/.next/server/app/api/models/route.js +1 -0
  35. package/.next/server/app/api/models/route.js.nft.json +1 -0
  36. package/.next/server/app/api/notes/route.js +1 -0
  37. package/.next/server/app/api/notes/route.js.nft.json +1 -0
  38. package/.next/server/app/api/orgs/[id]/route.js +1 -0
  39. package/.next/server/app/api/orgs/[id]/route.js.nft.json +1 -0
  40. package/.next/server/app/api/orgs/route.js +1 -0
  41. package/.next/server/app/api/orgs/route.js.nft.json +1 -0
  42. package/.next/server/app/api/prs/inbox/route.js +1 -0
  43. package/.next/server/app/api/prs/inbox/route.js.nft.json +1 -0
  44. package/.next/server/app/api/prs/refresh/route.js +1 -0
  45. package/.next/server/app/api/prs/refresh/route.js.nft.json +1 -0
  46. package/.next/server/app/api/prs/route.js +1 -0
  47. package/.next/server/app/api/prs/route.js.nft.json +1 -0
  48. package/.next/server/app/api/session-names/route.js +1 -0
  49. package/.next/server/app/api/session-names/route.js.nft.json +1 -0
  50. package/.next/server/app/api/sessions/[id]/route.js +1 -0
  51. package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -0
  52. package/.next/server/app/api/sessions/route.js +1 -0
  53. package/.next/server/app/api/sessions/route.js.nft.json +1 -0
  54. package/.next/server/app/api/settings/auth/route.js +1 -0
  55. package/.next/server/app/api/settings/auth/route.js.nft.json +1 -0
  56. package/.next/server/app/api/settings/route.js +1 -0
  57. package/.next/server/app/api/settings/route.js.nft.json +1 -0
  58. package/.next/server/app/api/settings/transcription/route.js +1 -0
  59. package/.next/server/app/api/settings/transcription/route.js.nft.json +1 -0
  60. package/.next/server/app/api/skills/[name]/route.js +8 -0
  61. package/.next/server/app/api/skills/[name]/route.js.nft.json +1 -0
  62. package/.next/server/app/api/skills/marketplace/route.js +2 -0
  63. package/.next/server/app/api/skills/marketplace/route.js.nft.json +1 -0
  64. package/.next/server/app/api/skills/route.js +8 -0
  65. package/.next/server/app/api/skills/route.js.nft.json +1 -0
  66. package/.next/server/app/api/skills/view/route.js +8 -0
  67. package/.next/server/app/api/skills/view/route.js.nft.json +1 -0
  68. package/.next/server/app/api/slack/channels/route.js +1 -0
  69. package/.next/server/app/api/slack/channels/route.js.nft.json +1 -0
  70. package/.next/server/app/api/slack/configured/route.js +1 -0
  71. package/.next/server/app/api/slack/configured/route.js.nft.json +1 -0
  72. package/.next/server/app/api/slack/inbox/route.js +1 -0
  73. package/.next/server/app/api/slack/inbox/route.js.nft.json +1 -0
  74. package/.next/server/app/api/usage/route.js +1 -0
  75. package/.next/server/app/api/usage/route.js.nft.json +1 -0
  76. package/.next/server/app/demo/page.js +1 -0
  77. package/.next/server/app/demo/page.js.nft.json +1 -0
  78. package/.next/server/app/demo/page_client-reference-manifest.js +1 -0
  79. package/.next/server/app/demo.html +1 -0
  80. package/.next/server/app/demo.meta +6 -0
  81. package/.next/server/app/demo.rsc +7 -0
  82. package/.next/server/app/favicon.ico/route.js +12 -0
  83. package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
  84. package/.next/server/app/favicon.ico.body +0 -0
  85. package/.next/server/app/favicon.ico.meta +1 -0
  86. package/.next/server/app/index.html +1 -0
  87. package/.next/server/app/index.meta +5 -0
  88. package/.next/server/app/index.rsc +7 -0
  89. package/.next/server/app/page.js +1 -0
  90. package/.next/server/app/page.js.nft.json +1 -0
  91. package/.next/server/app/page_client-reference-manifest.js +1 -0
  92. package/.next/server/app-paths-manifest.json +34 -0
  93. package/.next/server/chunks/348.js +1 -0
  94. package/.next/server/chunks/471.js +2 -0
  95. package/.next/server/chunks/590.js +7 -0
  96. package/.next/server/chunks/621.js +1 -0
  97. package/.next/server/chunks/682.js +6 -0
  98. package/.next/server/chunks/904.js +1 -0
  99. package/.next/server/chunks/948.js +2 -0
  100. package/.next/server/chunks/972.js +12 -0
  101. package/.next/server/chunks/font-manifest.json +1 -0
  102. package/.next/server/font-manifest.json +1 -0
  103. package/.next/server/functions-config-manifest.json +1 -0
  104. package/.next/server/interception-route-rewrite-manifest.js +1 -0
  105. package/.next/server/middleware-build-manifest.js +1 -0
  106. package/.next/server/middleware-manifest.json +6 -0
  107. package/.next/server/middleware-react-loadable-manifest.js +1 -0
  108. package/.next/server/next-font-manifest.js +1 -0
  109. package/.next/server/next-font-manifest.json +1 -0
  110. package/.next/server/pages/404.html +1 -0
  111. package/.next/server/pages/500.html +1 -0
  112. package/.next/server/pages/_app.js +1 -0
  113. package/.next/server/pages/_app.js.nft.json +1 -0
  114. package/.next/server/pages/_document.js +1 -0
  115. package/.next/server/pages/_document.js.nft.json +1 -0
  116. package/.next/server/pages/_error.js +1 -0
  117. package/.next/server/pages/_error.js.nft.json +1 -0
  118. package/.next/server/pages-manifest.json +1 -0
  119. package/.next/server/server-reference-manifest.js +1 -0
  120. package/.next/server/server-reference-manifest.json +1 -0
  121. package/.next/server/webpack-runtime.js +1 -0
  122. package/.next/static/chunks/117-0f4ac3c2c1871d4c.js +2 -0
  123. package/.next/static/chunks/171-f72ed164561ba218.js +1 -0
  124. package/.next/static/chunks/235.aef4cdc783360b73.js +1 -0
  125. package/.next/static/chunks/30d07d85.9045c666bb43d9e1.js +3 -0
  126. package/.next/static/chunks/app/_not-found/page-8ff6572bc7c9bc61.js +1 -0
  127. package/.next/static/chunks/app/demo/page-6711b34cd2af0e4a.js +1 -0
  128. package/.next/static/chunks/app/layout-d058836232e72324.js +1 -0
  129. package/.next/static/chunks/app/page-cebeba7d6d08548a.js +1 -0
  130. package/.next/static/chunks/fd9d1056-26bd8d656b496dba.js +1 -0
  131. package/.next/static/chunks/framework-f66176bb897dc684.js +1 -0
  132. package/.next/static/chunks/main-960df1c7509a5a8b.js +1 -0
  133. package/.next/static/chunks/main-app-4b855ea14675b961.js +1 -0
  134. package/.next/static/chunks/pages/_app-72b849fbd24ac258.js +1 -0
  135. package/.next/static/chunks/pages/_error-7ba65e1336b92748.js +1 -0
  136. package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  137. package/.next/static/chunks/webpack-1f89b7cb1fca69c4.js +1 -0
  138. package/.next/static/css/a537d3e86c0f36d2.css +3 -0
  139. package/.next/static/css/ab3e4b0f5035257a.css +1 -0
  140. package/.next/static/q-HMeHYZY36qljBJhsyS6/_buildManifest.js +1 -0
  141. package/.next/static/q-HMeHYZY36qljBJhsyS6/_ssgManifest.js +1 -0
  142. package/.next/trace +22 -0
  143. package/.next/types/app/api/automations/existing/route.ts +343 -0
  144. package/.next/types/app/api/backends/route.ts +343 -0
  145. package/.next/types/app/api/limits/route.ts +343 -0
  146. package/.next/types/app/api/meetings/[id]/route.ts +343 -0
  147. package/.next/types/app/api/meetings/[id]/slack/route.ts +343 -0
  148. package/.next/types/app/api/meetings/library/route.ts +343 -0
  149. package/.next/types/app/api/meetings/route.ts +343 -0
  150. package/.next/types/app/api/models/route.ts +343 -0
  151. package/.next/types/app/api/notes/route.ts +343 -0
  152. package/.next/types/app/api/orgs/[id]/route.ts +343 -0
  153. package/.next/types/app/api/orgs/route.ts +343 -0
  154. package/.next/types/app/api/prs/inbox/route.ts +343 -0
  155. package/.next/types/app/api/prs/refresh/route.ts +343 -0
  156. package/.next/types/app/api/prs/route.ts +343 -0
  157. package/.next/types/app/api/session-names/route.ts +343 -0
  158. package/.next/types/app/api/sessions/[id]/route.ts +343 -0
  159. package/.next/types/app/api/sessions/route.ts +343 -0
  160. package/.next/types/app/api/settings/auth/route.ts +343 -0
  161. package/.next/types/app/api/settings/route.ts +343 -0
  162. package/.next/types/app/api/settings/transcription/route.ts +343 -0
  163. package/.next/types/app/api/skills/[name]/route.ts +343 -0
  164. package/.next/types/app/api/skills/marketplace/route.ts +343 -0
  165. package/.next/types/app/api/skills/route.ts +343 -0
  166. package/.next/types/app/api/skills/view/route.ts +343 -0
  167. package/.next/types/app/api/slack/channels/route.ts +343 -0
  168. package/.next/types/app/api/slack/configured/route.ts +343 -0
  169. package/.next/types/app/api/slack/inbox/route.ts +343 -0
  170. package/.next/types/app/api/usage/route.ts +343 -0
  171. package/.next/types/app/demo/page.ts +79 -0
  172. package/.next/types/app/layout.ts +79 -0
  173. package/.next/types/app/page.ts +79 -0
  174. package/.next/types/package.json +1 -0
  175. package/.server-dist/server.js +554 -0
  176. package/.server-dist/src/lib/activeOrg.js +11 -0
  177. package/.server-dist/src/lib/audioCapture.js +157 -0
  178. package/.server-dist/src/lib/backends.js +111 -0
  179. package/.server-dist/src/lib/claudeAuth.js +57 -0
  180. package/.server-dist/src/lib/configFile.js +23 -0
  181. package/.server-dist/src/lib/dataDir.js +7 -0
  182. package/.server-dist/src/lib/existingAutomations.js +132 -0
  183. package/.server-dist/src/lib/ghInbox.js +151 -0
  184. package/.server-dist/src/lib/ghPrStatus.js +86 -0
  185. package/.server-dist/src/lib/gitUtils.js +27 -0
  186. package/.server-dist/src/lib/keepAwake.js +32 -0
  187. package/.server-dist/src/lib/liveSessionStore.js +89 -0
  188. package/.server-dist/src/lib/marketplace.js +63 -0
  189. package/.server-dist/src/lib/meetingAssistant.js +138 -0
  190. package/.server-dist/src/lib/meetingConfig.js +81 -0
  191. package/.server-dist/src/lib/meetingContext.js +82 -0
  192. package/.server-dist/src/lib/meetingManager.js +246 -0
  193. package/.server-dist/src/lib/meetingStore.js +198 -0
  194. package/.server-dist/src/lib/modelCatalog.js +107 -0
  195. package/.server-dist/src/lib/notesStore.js +67 -0
  196. package/.server-dist/src/lib/orgFilter.js +19 -0
  197. package/.server-dist/src/lib/orgParam.js +15 -0
  198. package/.server-dist/src/lib/orgRegistry.js +93 -0
  199. package/.server-dist/src/lib/pipelineView.js +62 -0
  200. package/.server-dist/src/lib/pipelines.js +401 -0
  201. package/.server-dist/src/lib/planLimits.js +101 -0
  202. package/.server-dist/src/lib/prDetector.js +16 -0
  203. package/.server-dist/src/lib/prScanCache.js +144 -0
  204. package/.server-dist/src/lib/prSessionEntries.js +96 -0
  205. package/.server-dist/src/lib/prTypes.js +2 -0
  206. package/.server-dist/src/lib/ptyManager.js +428 -0
  207. package/.server-dist/src/lib/reminders.js +10 -0
  208. package/.server-dist/src/lib/requestGuard.js +29 -0
  209. package/.server-dist/src/lib/sessionNameStore.js +69 -0
  210. package/.server-dist/src/lib/sessionStore.js +215 -0
  211. package/.server-dist/src/lib/settingsStore.js +51 -0
  212. package/.server-dist/src/lib/skillsReader.js +200 -0
  213. package/.server-dist/src/lib/slackBridge.js +270 -0
  214. package/.server-dist/src/lib/slackInbox.js +96 -0
  215. package/.server-dist/src/lib/slackWatchers.js +210 -0
  216. package/.server-dist/src/lib/statusDetector.js +46 -0
  217. package/.server-dist/src/lib/transcriber.js +61 -0
  218. package/.server-dist/src/lib/usageStore.js +254 -0
  219. package/.server-dist/tsconfig.server.tsbuildinfo +1 -0
  220. package/LICENSE +21 -0
  221. package/README.md +99 -2
  222. package/bin/polyergon.js +34 -0
  223. package/next.config.mjs +4 -0
  224. package/package.json +81 -4
  225. package/public/.gitkeep +0 -0
  226. package/public/apple-touch-icon.png +0 -0
  227. package/public/icon-192.png +0 -0
  228. package/public/icon-512.png +0 -0
  229. package/public/icon.svg +1 -0
  230. package/public/manifest.webmanifest +15 -0
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STRICT_PR_URL_RE = void 0;
4
+ exports.extractPrUrl = extractPrUrl;
5
+ // Matches PR URLs anywhere in text — used to scan streaming/file content.
6
+ const PR_URL_RE = /https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+/g;
7
+ // Anchored form for validating a URL right before it's passed to execFile —
8
+ // the URL is substring-extracted from LLM-controlled output, so this is a
9
+ // defense-in-depth check against anything that isn't exactly a PR URL.
10
+ exports.STRICT_PR_URL_RE = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+$/;
11
+ // Returns the last match in `text` — a PR opened later in a session
12
+ // naturally supersedes an earlier one.
13
+ function extractPrUrl(text) {
14
+ const matches = text.match(PR_URL_RE);
15
+ return matches ? matches[matches.length - 1] : null;
16
+ }
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
3
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
+ var m = o[Symbol.asyncIterator], i;
5
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
6
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
7
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
+ };
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ var _a;
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.prUrlCache = exports.PrUrlCache = void 0;
15
+ const dataDir_1 = require("./dataDir");
16
+ const fs_1 = require("fs");
17
+ const fs_2 = require("fs");
18
+ const readline_1 = require("readline");
19
+ const path_1 = __importDefault(require("path"));
20
+ const prDetector_1 = require("./prDetector");
21
+ const DEFAULT_PROJECTS_DIR = path_1.default.join(process.env.HOME, '.claude', 'projects');
22
+ const DEFAULT_CACHE_FILE = path_1.default.join(dataDir_1.DATA_DIR, 'pr-url-cache.json');
23
+ // Persisted, mtime/size-invalidated cache of session -> PR URL. A PR URL from
24
+ // `gh pr create` typically appears well past the small header most other
25
+ // session metadata reads scan, so this does a full read — but only for files
26
+ // that changed since the last scan, never re-reading unchanged ones.
27
+ class PrUrlCache {
28
+ // Both paths default to the real on-disk locations; tests must pass
29
+ // isolated paths so they never touch the user's actual session state.
30
+ constructor(cacheFile = DEFAULT_CACHE_FILE, projectsDir = DEFAULT_PROJECTS_DIR) {
31
+ this.cache = new Map();
32
+ this.loaded = false;
33
+ this.cacheFile = cacheFile;
34
+ this.cacheDir = path_1.default.join(cacheFile, '..');
35
+ this.projectsDir = projectsDir;
36
+ }
37
+ async load() {
38
+ if (this.loaded)
39
+ return;
40
+ this.loaded = true;
41
+ try {
42
+ const raw = await fs_1.promises.readFile(this.cacheFile, 'utf-8');
43
+ const parsed = JSON.parse(raw);
44
+ this.cache = new Map(Object.entries(parsed));
45
+ }
46
+ catch ( /* no cache yet */_a) { /* no cache yet */ }
47
+ }
48
+ async persist() {
49
+ try {
50
+ await fs_1.promises.mkdir(this.cacheDir, { recursive: true });
51
+ await fs_1.promises.writeFile(this.cacheFile, JSON.stringify(Object.fromEntries(this.cache)));
52
+ }
53
+ catch ( /* best-effort */_a) { /* best-effort */ }
54
+ }
55
+ // Returns sessionId -> prUrl for every known session with a detected PR.
56
+ // Scans the given projects roots (defaults to the single constructor dir,
57
+ // which callers override with every org's root).
58
+ async scan(projectsDirs = [this.projectsDir]) {
59
+ var _a, e_1, _b, _c;
60
+ var _d;
61
+ await this.load();
62
+ const result = new Map();
63
+ let changed = false;
64
+ for (const dir of projectsDirs) {
65
+ let projectDirs;
66
+ try {
67
+ projectDirs = await fs_1.promises.readdir(dir);
68
+ }
69
+ catch (_e) {
70
+ continue;
71
+ }
72
+ for (const projectDir of projectDirs) {
73
+ const projectFullPath = path_1.default.join(dir, projectDir);
74
+ let dirStat;
75
+ try {
76
+ dirStat = await fs_1.promises.stat(projectFullPath);
77
+ }
78
+ catch (_f) {
79
+ continue;
80
+ }
81
+ if (!dirStat.isDirectory())
82
+ continue;
83
+ let files;
84
+ try {
85
+ files = await fs_1.promises.readdir(projectFullPath);
86
+ }
87
+ catch (_g) {
88
+ continue;
89
+ }
90
+ for (const file of files) {
91
+ if (!file.endsWith('.jsonl'))
92
+ continue;
93
+ const sessionId = file.replace('.jsonl', '');
94
+ const filePath = path_1.default.join(projectFullPath, file);
95
+ let stat;
96
+ try {
97
+ stat = await fs_1.promises.stat(filePath);
98
+ }
99
+ catch (_h) {
100
+ continue;
101
+ }
102
+ const cached = this.cache.get(sessionId);
103
+ if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
104
+ if (cached.prUrl)
105
+ result.set(sessionId, cached.prUrl);
106
+ continue;
107
+ }
108
+ // Stream line by line — extractPrUrl returns the LAST match, so
109
+ // carrying the latest per-line hit is equivalent to scanning the whole
110
+ // file, without loading a multi-hundred-MB transcript into memory.
111
+ let prUrl = null;
112
+ try {
113
+ const rl = (0, readline_1.createInterface)({ input: (0, fs_2.createReadStream)(filePath, { encoding: 'utf-8' }), crlfDelay: Infinity });
114
+ try {
115
+ for (var _j = true, rl_1 = (e_1 = void 0, __asyncValues(rl)), rl_1_1; rl_1_1 = await rl_1.next(), _a = rl_1_1.done, !_a; _j = true) {
116
+ _c = rl_1_1.value;
117
+ _j = false;
118
+ const line = _c;
119
+ prUrl = (_d = (0, prDetector_1.extractPrUrl)(line)) !== null && _d !== void 0 ? _d : prUrl;
120
+ }
121
+ }
122
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
123
+ finally {
124
+ try {
125
+ if (!_j && !_a && (_b = rl_1.return)) await _b.call(rl_1);
126
+ }
127
+ finally { if (e_1) throw e_1.error; }
128
+ }
129
+ }
130
+ catch ( /* unreadable, treat as no PR */_k) { /* unreadable, treat as no PR */ }
131
+ this.cache.set(sessionId, { prUrl, mtimeMs: stat.mtimeMs, size: stat.size });
132
+ changed = true;
133
+ if (prUrl)
134
+ result.set(sessionId, prUrl);
135
+ }
136
+ }
137
+ }
138
+ if (changed)
139
+ await this.persist();
140
+ return result;
141
+ }
142
+ }
143
+ exports.PrUrlCache = PrUrlCache;
144
+ exports.prUrlCache = (_a = global.__prUrlCache) !== null && _a !== void 0 ? _a : (global.__prUrlCache = new PrUrlCache());
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPrSessionEntries = buildPrSessionEntries;
4
+ exports.effectiveDate = effectiveDate;
5
+ exports.sortPrEntries = sortPrEntries;
6
+ exports.sortPrEntriesByDate = sortPrEntriesByDate;
7
+ const liveSessionStore_1 = require("./liveSessionStore");
8
+ const sessionStore_1 = require("./sessionStore");
9
+ const prScanCache_1 = require("./prScanCache");
10
+ const ghPrStatus_1 = require("./ghPrStatus");
11
+ const orgRegistry_1 = require("./orgRegistry");
12
+ // Assembles the full PR-linked session list: live sessions whose PR was
13
+ // detected from streaming output, plus history-only sessions whose PR was
14
+ // found via the lazy full-file cache scan — decorated with whatever status
15
+ // is already cached (no new `gh` calls here; that's refresh's job).
16
+ async function buildPrSessionEntries() {
17
+ var _a, _b;
18
+ const [historyUrls, historySessions] = await Promise.all([
19
+ prScanCache_1.prUrlCache.scan(orgRegistry_1.orgRegistry.projectRoots().map(r => r.root)),
20
+ (0, sessionStore_1.listAllSessions)(),
21
+ ]);
22
+ const historyBySessionId = new Map(historySessions.map(s => [s.sessionId, s]));
23
+ const entries = [];
24
+ const seenSessionIds = new Set();
25
+ for (const s of liveSessionStore_1.liveSessionStore.list()) {
26
+ if (!s.prUrl)
27
+ continue;
28
+ entries.push({
29
+ source: 'live',
30
+ liveId: s.id,
31
+ sessionId: s.claudeSessionId,
32
+ orgId: (_a = s.orgId) !== null && _a !== void 0 ? _a : orgRegistry_1.DEFAULT_ORG_ID,
33
+ cwd: s.cwd,
34
+ gitRoot: s.gitRoot,
35
+ prUrl: s.prUrl,
36
+ status: (_b = ghPrStatus_1.prStatusCache.get(s.prUrl)) !== null && _b !== void 0 ? _b : null,
37
+ sessionDate: s.createdAt,
38
+ });
39
+ if (s.claudeSessionId)
40
+ seenSessionIds.add(s.claudeSessionId);
41
+ }
42
+ historyUrls.forEach((prUrl, sessionId) => {
43
+ var _a, _b, _c, _d;
44
+ if (seenSessionIds.has(sessionId))
45
+ return; // already covered by a live entry
46
+ const match = historyBySessionId.get(sessionId);
47
+ const parsed = (match === null || match === void 0 ? void 0 : match.lastTimestamp) ? Date.parse(match.lastTimestamp) : NaN;
48
+ entries.push({
49
+ source: 'history',
50
+ liveId: null,
51
+ sessionId,
52
+ orgId: (_a = match === null || match === void 0 ? void 0 : match.orgId) !== null && _a !== void 0 ? _a : orgRegistry_1.DEFAULT_ORG_ID,
53
+ cwd: (_b = match === null || match === void 0 ? void 0 : match.cwd) !== null && _b !== void 0 ? _b : null,
54
+ gitRoot: (_c = match === null || match === void 0 ? void 0 : match.gitRoot) !== null && _c !== void 0 ? _c : null,
55
+ prUrl,
56
+ status: (_d = ghPrStatus_1.prStatusCache.get(prUrl)) !== null && _d !== void 0 ? _d : null,
57
+ sessionDate: Number.isNaN(parsed) ? 0 : parsed,
58
+ });
59
+ });
60
+ return entries;
61
+ }
62
+ function isActionable(e) {
63
+ var _a;
64
+ return ((_a = e.status) === null || _a === void 0 ? void 0 : _a.state) === 'OPEN' && (e.status.reviewDecision === 'CHANGES_REQUESTED' || e.status.checks === 'failing');
65
+ }
66
+ function priority(e) {
67
+ if (isActionable(e))
68
+ return 0;
69
+ if (!e.status || e.status.state === 'OPEN')
70
+ return 1;
71
+ if (e.status.state === 'MERGED')
72
+ return 2;
73
+ return 3; // CLOSED
74
+ }
75
+ // The PR's own GitHub last-updated time once known (post-refresh); falls
76
+ // back to the session's own date so every entry always sorts/displays
77
+ // something meaningful even before a refresh has ever run.
78
+ function effectiveDate(e) {
79
+ var _a, _b;
80
+ return (_b = (_a = e.status) === null || _a === void 0 ? void 0 : _a.updatedAt) !== null && _b !== void 0 ? _b : e.sessionDate;
81
+ }
82
+ // Actionable (changes requested / failing checks) first, then open-no-action
83
+ // (or status not yet known), then merged, then closed last; newest first
84
+ // within each tier.
85
+ function sortPrEntries(entries) {
86
+ return [...entries].sort((a, b) => {
87
+ const pa = priority(a), pb = priority(b);
88
+ if (pa !== pb)
89
+ return pa - pb;
90
+ return effectiveDate(b) - effectiveDate(a);
91
+ });
92
+ }
93
+ // Pure newest-first, ignoring the actionable/state tiering entirely.
94
+ function sortPrEntriesByDate(entries) {
95
+ return [...entries].sort((a, b) => effectiveDate(b) - effectiveDate(a));
96
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });