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,215 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.decodeProjectPath = decodeProjectPath;
14
+ exports.getSessionMessages = getSessionMessages;
15
+ exports.firstUserMessageSync = firstUserMessageSync;
16
+ exports.titleFromLines = titleFromLines;
17
+ exports.listAllSessions = listAllSessions;
18
+ const fs_1 = __importDefault(require("fs"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const readline_1 = require("readline");
21
+ const gitUtils_1 = require("./gitUtils");
22
+ const orgRegistry_1 = require("./orgRegistry");
23
+ /**
24
+ * Decode the encoded project directory name back to a path.
25
+ * NOTE: This replacement is ambiguous — it cannot distinguish between
26
+ * path separators and dashes that are part of directory/project names.
27
+ */
28
+ function decodeProjectPath(encoded) {
29
+ return encoded.replace(/-/g, '/');
30
+ }
31
+ // Only scan the first 20 lines — fast enough to get cwd + firstUserMessage
32
+ function extractSessionMetadata(content, sessionId, mtime) {
33
+ var _a, _b, _c, _d, _e;
34
+ let cwd = null;
35
+ let firstUserMessage = null;
36
+ let messageCount = 0;
37
+ let headless = false;
38
+ const lines = content.split('\n');
39
+ for (const line of lines) {
40
+ if (!line.trim())
41
+ continue;
42
+ try {
43
+ const entry = JSON.parse(line);
44
+ if (entry.entrypoint === 'sdk-cli')
45
+ headless = true;
46
+ if (entry.type === 'user' && ((_a = entry.message) === null || _a === void 0 ? void 0 : _a.role) === 'user') {
47
+ if (cwd === null && entry.cwd)
48
+ cwd = entry.cwd;
49
+ const text = typeof entry.message.content === 'string'
50
+ ? entry.message.content
51
+ : (_d = (_c = (_b = entry.message.content) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : '';
52
+ if (firstUserMessage === null && text)
53
+ firstUserMessage = text.slice(0, 100);
54
+ messageCount++;
55
+ }
56
+ else if (entry.type === 'assistant' && ((_e = entry.message) === null || _e === void 0 ? void 0 : _e.role) === 'assistant') {
57
+ messageCount++;
58
+ }
59
+ }
60
+ catch ( /* skip malformed lines */_f) { /* skip malformed lines */ }
61
+ }
62
+ return { sessionId, cwd, messageCount, lastTimestamp: mtime.toISOString(), firstUserMessage, headless };
63
+ }
64
+ // Streams the transcript line by line and keeps only the last `keepLast`
65
+ // messages. Transcripts reach hundreds of MB (a 209 MB one exists); reading
66
+ // the whole file into a string OOM-killed the server even at an 8 GB heap.
67
+ async function getSessionMessages(filePath, keepLast = 30) {
68
+ var _a, e_1, _b, _c;
69
+ var _d, _e, _f, _g, _h, _j, _k, _l;
70
+ const messages = [];
71
+ const rl = (0, readline_1.createInterface)({ input: fs_1.default.createReadStream(filePath, { encoding: 'utf-8' }), crlfDelay: Infinity });
72
+ try {
73
+ for (var _m = true, rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = await rl_1.next(), _a = rl_1_1.done, !_a; _m = true) {
74
+ _c = rl_1_1.value;
75
+ _m = false;
76
+ const line = _c;
77
+ if (!line.trim())
78
+ continue;
79
+ try {
80
+ const entry = JSON.parse(line);
81
+ if (entry.type === 'user' && ((_d = entry.message) === null || _d === void 0 ? void 0 : _d.role) === 'user') {
82
+ const text = typeof entry.message.content === 'string'
83
+ ? entry.message.content
84
+ : (_g = (_f = (_e = entry.message.content) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.text) !== null && _g !== void 0 ? _g : '';
85
+ if (text)
86
+ messages.push({ role: 'user', content: text, timestamp: (_h = entry.timestamp) !== null && _h !== void 0 ? _h : null });
87
+ }
88
+ else if (entry.type === 'assistant' && ((_j = entry.message) === null || _j === void 0 ? void 0 : _j.role) === 'assistant') {
89
+ const parts = (_k = entry.message.content) !== null && _k !== void 0 ? _k : [];
90
+ const text = parts.filter(p => p.type === 'text').map(p => p.text).join('');
91
+ if (text)
92
+ messages.push({ role: 'assistant', content: text, timestamp: (_l = entry.timestamp) !== null && _l !== void 0 ? _l : null });
93
+ }
94
+ if (messages.length > keepLast)
95
+ messages.shift();
96
+ }
97
+ catch ( /* skip malformed */_o) { /* skip malformed */ }
98
+ }
99
+ }
100
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
101
+ finally {
102
+ try {
103
+ if (!_m && !_a && (_b = rl_1.return)) await _b.call(rl_1);
104
+ }
105
+ finally { if (e_1) throw e_1.error; }
106
+ }
107
+ return messages;
108
+ }
109
+ // Cheap title for a transcript: first user message from its first 64KB.
110
+ function firstUserMessageSync(filePath) {
111
+ try {
112
+ const fd = fs_1.default.openSync(filePath, 'r');
113
+ const buf = Buffer.alloc(65536);
114
+ const n = fs_1.default.readSync(fd, buf, 0, 65536, 0);
115
+ fs_1.default.closeSync(fd);
116
+ const head = buf.subarray(0, n).toString('utf-8');
117
+ return extractSessionMetadata(head.slice(0, head.lastIndexOf('\n') + 1), '', new Date(0)).firstUserMessage;
118
+ }
119
+ catch (_a) {
120
+ return null;
121
+ }
122
+ }
123
+ // Claude appends title entries as the session goes, so the newest is near the
124
+ // end: prefer the last /rename (custom-title), else the last auto title.
125
+ function titleFromLines(text) {
126
+ let custom = null, ai = null;
127
+ for (const line of text.split('\n')) {
128
+ if (!line.includes('-title"'))
129
+ continue;
130
+ try {
131
+ const e = JSON.parse(line);
132
+ if (e.type === 'custom-title' && e.customTitle)
133
+ custom = String(e.customTitle);
134
+ else if (e.type === 'ai-title' && e.aiTitle)
135
+ ai = String(e.aiTitle);
136
+ }
137
+ catch ( /* partial line */_a) { /* partial line */ }
138
+ }
139
+ return custom !== null && custom !== void 0 ? custom : ai;
140
+ }
141
+ async function titleFromTail(filePath, size = 262144) {
142
+ try {
143
+ const fd = await fs_1.default.promises.open(filePath, 'r');
144
+ const { size: total } = await fd.stat();
145
+ const start = Math.max(0, total - size);
146
+ const buf = Buffer.alloc(Math.min(size, total));
147
+ const { bytesRead } = await fd.read(buf, 0, buf.length, start);
148
+ await fd.close();
149
+ return titleFromLines(buf.subarray(0, bytesRead).toString('utf-8'));
150
+ }
151
+ catch (_a) {
152
+ return null;
153
+ }
154
+ }
155
+ async function listAllSessions() {
156
+ // Collect all .jsonl files with their mtime first (cheap stat), across
157
+ // every registered org's projects root.
158
+ const files = [];
159
+ for (const { orgId, root } of orgRegistry_1.orgRegistry.projectRoots()) {
160
+ let projectDirs;
161
+ try {
162
+ projectDirs = await fs_1.default.promises.readdir(root);
163
+ }
164
+ catch (_a) {
165
+ continue;
166
+ }
167
+ for (const projectDir of projectDirs) {
168
+ const projectFullPath = path_1.default.join(root, projectDir);
169
+ let dirStat;
170
+ try {
171
+ dirStat = await fs_1.default.promises.stat(projectFullPath);
172
+ }
173
+ catch (_b) {
174
+ continue;
175
+ }
176
+ if (!dirStat.isDirectory())
177
+ continue;
178
+ for (const file of await fs_1.default.promises.readdir(projectFullPath)) {
179
+ if (!file.endsWith('.jsonl'))
180
+ continue;
181
+ const filePath = path_1.default.join(projectFullPath, file);
182
+ try {
183
+ const s = await fs_1.default.promises.stat(filePath);
184
+ files.push({ filePath, projectDir, sessionId: file.replace('.jsonl', ''), mtime: s.mtime, orgId });
185
+ }
186
+ catch ( /* skip */_c) { /* skip */ }
187
+ }
188
+ }
189
+ }
190
+ // Parse metadata from the first 64 KB of each file (covers large preambles)
191
+ const READ_SIZE = 65536;
192
+ const summaries = [];
193
+ await Promise.all(files.map(async ({ filePath, projectDir, sessionId, mtime, orgId }) => {
194
+ try {
195
+ const fd = await fs_1.default.promises.open(filePath, 'r');
196
+ const buf = Buffer.alloc(READ_SIZE);
197
+ const { bytesRead } = await fd.read(buf, 0, READ_SIZE, 0);
198
+ await fd.close();
199
+ const head = buf.subarray(0, bytesRead).toString('utf-8');
200
+ // Trim last (possibly incomplete) line
201
+ const content = head.slice(0, head.lastIndexOf('\n') + 1);
202
+ const metadata = extractSessionMetadata(content, sessionId, mtime);
203
+ metadata.title = await titleFromTail(filePath);
204
+ const gitRoot = metadata.cwd ? (0, gitUtils_1.getGitRoot)(metadata.cwd) : null;
205
+ summaries.push(Object.assign(Object.assign({}, metadata), { projectPath: decodeProjectPath(projectDir), projectEncoded: projectDir, filePath, gitRoot, orgId }));
206
+ }
207
+ catch ( /* skip unreadable */_a) { /* skip unreadable */ }
208
+ }));
209
+ return summaries.sort((a, b) => {
210
+ var _a, _b;
211
+ const ta = (_a = a.lastTimestamp) !== null && _a !== void 0 ? _a : '';
212
+ const tb = (_b = b.lastTimestamp) !== null && _b !== void 0 ? _b : '';
213
+ return tb > ta ? 1 : tb < ta ? -1 : 0;
214
+ });
215
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SETTINGS = exports.AUTO_COMPACT_MAX = exports.AUTO_COMPACT_MIN = void 0;
4
+ exports.getSettings = getSettings;
5
+ exports.updateSettings = updateSettings;
6
+ exports.autoCompactEnv = autoCompactEnv;
7
+ const dataDir_1 = require("./dataDir");
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ // Claude Code's CLAUDE_CODE_AUTO_COMPACT_WINDOW accepts 100k–1M.
11
+ exports.AUTO_COMPACT_MIN = 100000;
12
+ exports.AUTO_COMPACT_MAX = 1000000;
13
+ exports.DEFAULT_SETTINGS = { autoCompact: { enabled: true, windowTokens: 300000 }, notifications: { enabled: true }, sessions: { skipPermissions: false }, power: { keepAwake: false } };
14
+ const FILE = (0, path_1.join)(dataDir_1.DATA_DIR, 'settings.json');
15
+ const clamp = (n) => Math.min(exports.AUTO_COMPACT_MAX, Math.max(exports.AUTO_COMPACT_MIN, Math.round(n)));
16
+ function getSettings(file = FILE) {
17
+ var _a, _b;
18
+ try {
19
+ const raw = JSON.parse((0, fs_1.readFileSync)(file, 'utf-8'));
20
+ const ac = Object.assign(Object.assign({}, exports.DEFAULT_SETTINGS.autoCompact), raw.autoCompact);
21
+ const nt = Object.assign(Object.assign({}, exports.DEFAULT_SETTINGS.notifications), raw.notifications);
22
+ return {
23
+ autoCompact: { enabled: !!ac.enabled, windowTokens: clamp(Number(ac.windowTokens) || exports.DEFAULT_SETTINGS.autoCompact.windowTokens) },
24
+ notifications: { enabled: !!nt.enabled },
25
+ sessions: { skipPermissions: ((_a = raw.sessions) === null || _a === void 0 ? void 0 : _a.skipPermissions) === true },
26
+ power: { keepAwake: ((_b = raw.power) === null || _b === void 0 ? void 0 : _b.keepAwake) === true },
27
+ };
28
+ }
29
+ catch (_c) {
30
+ return structuredClone(exports.DEFAULT_SETTINGS);
31
+ }
32
+ }
33
+ function updateSettings(patch, file = FILE) {
34
+ const cur = getSettings(file);
35
+ const next = {
36
+ autoCompact: Object.assign(Object.assign({}, cur.autoCompact), patch.autoCompact),
37
+ notifications: { enabled: !!Object.assign(Object.assign({}, cur.notifications), patch.notifications).enabled },
38
+ sessions: { skipPermissions: (Object.assign(Object.assign({}, cur.sessions), patch.sessions)).skipPermissions === true },
39
+ power: { keepAwake: (Object.assign(Object.assign({}, cur.power), patch.power)).keepAwake === true },
40
+ };
41
+ next.autoCompact.windowTokens = clamp(Number(next.autoCompact.windowTokens) || cur.autoCompact.windowTokens);
42
+ next.autoCompact.enabled = !!next.autoCompact.enabled;
43
+ (0, fs_1.mkdirSync)((0, path_1.join)(file, '..'), { recursive: true });
44
+ (0, fs_1.writeFileSync)(file, JSON.stringify(next, null, 2));
45
+ return next;
46
+ }
47
+ // Env for a Claude spawn. Disabled → nothing set, the CLI keeps its own default.
48
+ function autoCompactEnv() {
49
+ const { autoCompact } = getSettings();
50
+ return autoCompact.enabled ? { CLAUDE_CODE_AUTO_COMPACT_WINDOW: String(autoCompact.windowTokens) } : {};
51
+ }
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SKILL_NAME = void 0;
4
+ exports.parseFrontmatter = parseFrontmatter;
5
+ exports.listSkills = listSkills;
6
+ exports.buildSkill = buildSkill;
7
+ exports.readUserSkill = readUserSkill;
8
+ exports.saveUserSkill = saveUserSkill;
9
+ exports.trashUserSkill = trashUserSkill;
10
+ exports.readSkillByName = readSkillByName;
11
+ const fs_1 = require("fs");
12
+ const dataDir_1 = require("./dataDir");
13
+ const path_1 = require("path");
14
+ // Parse the `name` and `description` from a SKILL.md YAML frontmatter block.
15
+ // Handles inline values (`description: text`), quoted values, and YAML block
16
+ // scalars (`description: >-` / `|` with the text indented on following lines).
17
+ function parseFrontmatter(md) {
18
+ const m = md.match(/^---\s*\n([\s\S]*?)\n---/);
19
+ if (!m)
20
+ return {};
21
+ const lines = m[1].split('\n');
22
+ const out = {};
23
+ for (let i = 0; i < lines.length; i++) {
24
+ const kv = lines[i].match(/^(name|description):\s*(.*)$/);
25
+ if (!kv)
26
+ continue;
27
+ const key = kv[1];
28
+ let val = kv[2].trim();
29
+ if (val === '>-' || val === '>' || val === '|' || val === '|-') {
30
+ // Block scalar: collect subsequent more-indented lines.
31
+ const collected = [];
32
+ for (let j = i + 1; j < lines.length; j++) {
33
+ if (/^\s+\S/.test(lines[j]) || lines[j].trim() === '')
34
+ collected.push(lines[j].trim());
35
+ else
36
+ break;
37
+ }
38
+ val = collected.join(' ').trim();
39
+ }
40
+ else {
41
+ val = val.replace(/^["']|["']$/g, '');
42
+ }
43
+ out[key] = val;
44
+ }
45
+ return out;
46
+ }
47
+ function readSkillDir(dir, source, plugin) {
48
+ const file = (0, path_1.join)(dir, 'SKILL.md');
49
+ if (!(0, fs_1.existsSync)(file))
50
+ return null;
51
+ try {
52
+ const fm = parseFrontmatter((0, fs_1.readFileSync)(file, 'utf-8'));
53
+ const name = fm.name || dir.split('/').at(-1) || 'skill';
54
+ return { name, description: fm.description || '', source, plugin, path: dir };
55
+ }
56
+ catch (_a) {
57
+ return null;
58
+ }
59
+ }
60
+ function skillsUnder(skillsRoot, source, plugin) {
61
+ if (!(0, fs_1.existsSync)(skillsRoot))
62
+ return [];
63
+ const out = [];
64
+ for (const entry of (0, fs_1.readdirSync)(skillsRoot)) {
65
+ const dir = (0, path_1.join)(skillsRoot, entry);
66
+ try {
67
+ if (!(0, fs_1.statSync)(dir).isDirectory())
68
+ continue;
69
+ }
70
+ catch (_a) {
71
+ continue;
72
+ }
73
+ const skill = readSkillDir(dir, source, plugin);
74
+ if (skill)
75
+ out.push(skill);
76
+ }
77
+ return out;
78
+ }
79
+ // User skills live in ~/.claude/skills/<name>/SKILL.md. Installed plugin skills
80
+ // live under ~/.claude/plugins/cache/<marketplace>/<plugin>/<version>/skills/.
81
+ // We read both, tag each with its source, and dedupe by name (user wins).
82
+ const claudeRoot = (configDir) => configDir || (0, path_1.join)(process.env.HOME, '.claude');
83
+ // configDir: the org's Claude config folder (null = ~/.claude)
84
+ function listSkills(configDir) {
85
+ const claudeDir = claudeRoot(configDir);
86
+ const user = skillsUnder((0, path_1.join)(claudeDir, 'skills'), 'user');
87
+ const plugin = [];
88
+ const cacheRoot = (0, path_1.join)(claudeDir, 'plugins', 'cache');
89
+ if ((0, fs_1.existsSync)(cacheRoot)) {
90
+ // cache/<marketplace>/<plugin>/<version>/skills/<name>
91
+ for (const marketplace of safeReaddir(cacheRoot)) {
92
+ const mDir = (0, path_1.join)(cacheRoot, marketplace);
93
+ for (const pluginName of safeReaddir(mDir)) {
94
+ const pDir = (0, path_1.join)(mDir, pluginName);
95
+ for (const version of safeReaddir(pDir)) {
96
+ const skillsRoot = (0, path_1.join)(pDir, version, 'skills');
97
+ plugin.push(...skillsUnder(skillsRoot, 'plugin', pluginName));
98
+ }
99
+ }
100
+ }
101
+ }
102
+ // Dedupe by name — user skills take precedence, then first plugin seen.
103
+ const byName = new Map();
104
+ for (const s of [...user, ...plugin]) {
105
+ if (!byName.has(s.name))
106
+ byName.set(s.name, s);
107
+ }
108
+ return Array.from(byName.values()).sort((a, b) => a.name.localeCompare(b.name));
109
+ }
110
+ function safeReaddir(dir) {
111
+ try {
112
+ return (0, fs_1.readdirSync)(dir).filter(e => { try {
113
+ return (0, fs_1.statSync)((0, path_1.join)(dir, e)).isDirectory();
114
+ }
115
+ catch (_a) {
116
+ return false;
117
+ } });
118
+ }
119
+ catch (_a) {
120
+ return [];
121
+ }
122
+ }
123
+ // ---- Writing user skills (~/.claude/skills/<name>/SKILL.md) ----
124
+ const userSkillsRoot = (configDir) => (0, path_1.join)(claudeRoot(configDir), 'skills');
125
+ // Claude Code skill names: lowercase letters, digits and hyphens.
126
+ exports.SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
127
+ // Builds the SKILL.md text and validates it. Throws a user-facing message.
128
+ function buildSkill(input) {
129
+ var _a, _b, _c, _d, _e;
130
+ let content;
131
+ let name;
132
+ let description;
133
+ if ((_a = input.raw) === null || _a === void 0 ? void 0 : _a.trim()) {
134
+ content = input.raw.replace(/\r\n/g, '\n').trim() + '\n';
135
+ ({ name, description } = parseFrontmatter(content));
136
+ if (!name && !description)
137
+ throw new Error('SKILL.md must start with a --- frontmatter block that has name and description');
138
+ }
139
+ else {
140
+ name = (_b = input.name) === null || _b === void 0 ? void 0 : _b.trim();
141
+ description = (_c = input.description) === null || _c === void 0 ? void 0 : _c.trim().replace(/\s+/g, ' ');
142
+ const body = (_e = (_d = input.instructions) === null || _d === void 0 ? void 0 : _d.trim()) !== null && _e !== void 0 ? _e : '';
143
+ if (!body)
144
+ throw new Error('Instructions are required');
145
+ // Folded block scalar: any characters (quotes, colons) are kept as-is
146
+ content = `---\nname: ${name !== null && name !== void 0 ? name : ''}\ndescription: >-\n ${description !== null && description !== void 0 ? description : ''}\n---\n\n${body}\n`;
147
+ }
148
+ if (!name || !exports.SKILL_NAME.test(name))
149
+ throw new Error('Name must be lowercase letters, digits and hyphens (e.g. release-notes)');
150
+ if (!description)
151
+ throw new Error('Description is required: it tells Claude when to use the skill');
152
+ if (content.length > 200000)
153
+ throw new Error('Skill is too large (max 200 KB)');
154
+ return { name, content };
155
+ }
156
+ function readUserSkill(name, configDir) {
157
+ if (!exports.SKILL_NAME.test(name))
158
+ return null;
159
+ try {
160
+ return (0, fs_1.readFileSync)((0, path_1.join)(userSkillsRoot(configDir), name, 'SKILL.md'), 'utf-8');
161
+ }
162
+ catch (_a) {
163
+ return null;
164
+ }
165
+ }
166
+ // replaces: the existing skill being edited (null = new skill, must not exist).
167
+ function saveUserSkill(input, replaces = null, configDir) {
168
+ const { name, content } = buildSkill(input);
169
+ const dir = (0, path_1.join)(userSkillsRoot(configDir), name);
170
+ if (name !== replaces && (0, fs_1.existsSync)(dir))
171
+ throw new Error(`A skill named "${name}" already exists`);
172
+ if (replaces && name !== replaces)
173
+ trashUserSkill(replaces, configDir); // renamed
174
+ (0, fs_1.mkdirSync)(dir, { recursive: true });
175
+ (0, fs_1.writeFileSync)((0, path_1.join)(dir, 'SKILL.md'), content);
176
+ return name;
177
+ }
178
+ // Moves the skill folder to <data>/trash/skills (never deletes).
179
+ function trashUserSkill(name, configDir) {
180
+ if (!exports.SKILL_NAME.test(name))
181
+ return false;
182
+ const dir = (0, path_1.join)(userSkillsRoot(configDir), name);
183
+ if (!(0, fs_1.existsSync)(dir))
184
+ return false;
185
+ const dest = (0, path_1.join)(dataDir_1.DATA_DIR, 'trash', 'skills');
186
+ (0, fs_1.mkdirSync)(dest, { recursive: true });
187
+ (0, fs_1.renameSync)(dir, (0, path_1.join)(dest, `${name}-${Date.now()}`));
188
+ return true;
189
+ }
190
+ function readSkillByName(name, configDir) {
191
+ const skill = listSkills(configDir).find(s => s.name === name);
192
+ if (!skill)
193
+ return null;
194
+ try {
195
+ return { skill, raw: (0, fs_1.readFileSync)((0, path_1.join)(skill.path, 'SKILL.md'), 'utf-8') };
196
+ }
197
+ catch (_a) {
198
+ return null;
199
+ }
200
+ }