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.
- package/.next/BUILD_ID +1 -0
- package/.next/app-build-manifest.json +35 -0
- package/.next/app-path-routes-manifest.json +1 -0
- package/.next/build-manifest.json +32 -0
- package/.next/export-marker.json +1 -0
- package/.next/images-manifest.json +1 -0
- package/.next/next-minimal-server.js.nft.json +1 -0
- package/.next/next-server.js.nft.json +1 -0
- package/.next/package.json +1 -0
- package/.next/prerender-manifest.json +1 -0
- package/.next/react-loadable-manifest.json +10 -0
- package/.next/required-server-files.json +1 -0
- package/.next/routes-manifest.json +1 -0
- package/.next/server/app/_not-found/page.js +1 -0
- package/.next/server/app/_not-found/page.js.nft.json +1 -0
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
- package/.next/server/app/_not-found.html +1 -0
- package/.next/server/app/_not-found.meta +6 -0
- package/.next/server/app/_not-found.rsc +9 -0
- package/.next/server/app/api/automations/existing/route.js +1 -0
- package/.next/server/app/api/automations/existing/route.js.nft.json +1 -0
- package/.next/server/app/api/backends/route.js +1 -0
- package/.next/server/app/api/backends/route.js.nft.json +1 -0
- package/.next/server/app/api/diff/route.js +1 -0
- package/.next/server/app/api/diff/route.js.nft.json +1 -0
- package/.next/server/app/api/limits/route.js +1 -0
- package/.next/server/app/api/limits/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/[id]/route.js +1 -0
- package/.next/server/app/api/meetings/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/[id]/slack/route.js +3 -0
- package/.next/server/app/api/meetings/[id]/slack/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/library/route.js +1 -0
- package/.next/server/app/api/meetings/library/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/route.js +1 -0
- package/.next/server/app/api/meetings/route.js.nft.json +1 -0
- package/.next/server/app/api/models/route.js +1 -0
- package/.next/server/app/api/models/route.js.nft.json +1 -0
- package/.next/server/app/api/notes/route.js +1 -0
- package/.next/server/app/api/notes/route.js.nft.json +1 -0
- package/.next/server/app/api/orgs/[id]/route.js +1 -0
- package/.next/server/app/api/orgs/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/orgs/route.js +1 -0
- package/.next/server/app/api/orgs/route.js.nft.json +1 -0
- package/.next/server/app/api/prs/inbox/route.js +1 -0
- package/.next/server/app/api/prs/inbox/route.js.nft.json +1 -0
- package/.next/server/app/api/prs/refresh/route.js +1 -0
- package/.next/server/app/api/prs/refresh/route.js.nft.json +1 -0
- package/.next/server/app/api/prs/route.js +1 -0
- package/.next/server/app/api/prs/route.js.nft.json +1 -0
- package/.next/server/app/api/session-names/route.js +1 -0
- package/.next/server/app/api/session-names/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/route.js +1 -0
- package/.next/server/app/api/sessions/route.js.nft.json +1 -0
- package/.next/server/app/api/settings/auth/route.js +1 -0
- package/.next/server/app/api/settings/auth/route.js.nft.json +1 -0
- package/.next/server/app/api/settings/route.js +1 -0
- package/.next/server/app/api/settings/route.js.nft.json +1 -0
- package/.next/server/app/api/settings/transcription/route.js +1 -0
- package/.next/server/app/api/settings/transcription/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/[name]/route.js +8 -0
- package/.next/server/app/api/skills/[name]/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/marketplace/route.js +2 -0
- package/.next/server/app/api/skills/marketplace/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/route.js +8 -0
- package/.next/server/app/api/skills/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/view/route.js +8 -0
- package/.next/server/app/api/skills/view/route.js.nft.json +1 -0
- package/.next/server/app/api/slack/channels/route.js +1 -0
- package/.next/server/app/api/slack/channels/route.js.nft.json +1 -0
- package/.next/server/app/api/slack/configured/route.js +1 -0
- package/.next/server/app/api/slack/configured/route.js.nft.json +1 -0
- package/.next/server/app/api/slack/inbox/route.js +1 -0
- package/.next/server/app/api/slack/inbox/route.js.nft.json +1 -0
- package/.next/server/app/api/tasks/route.js +1 -0
- package/.next/server/app/api/tasks/route.js.nft.json +1 -0
- package/.next/server/app/api/usage/route.js +1 -0
- package/.next/server/app/api/usage/route.js.nft.json +1 -0
- package/.next/server/app/demo/page.js +1 -0
- package/.next/server/app/demo/page.js.nft.json +1 -0
- package/.next/server/app/demo/page_client-reference-manifest.js +1 -0
- package/.next/server/app/demo.html +1 -0
- package/.next/server/app/demo.meta +6 -0
- package/.next/server/app/demo.rsc +7 -0
- package/.next/server/app/favicon.ico/route.js +12 -0
- package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
- package/.next/server/app/favicon.ico.body +0 -0
- package/.next/server/app/favicon.ico.meta +1 -0
- package/.next/server/app/index.html +1 -0
- package/.next/server/app/index.meta +5 -0
- package/.next/server/app/index.rsc +7 -0
- package/.next/server/app/page.js +10 -0
- package/.next/server/app/page.js.nft.json +1 -0
- package/.next/server/app/page_client-reference-manifest.js +1 -0
- package/.next/server/app-paths-manifest.json +36 -0
- package/.next/server/chunks/36.js +1 -0
- package/.next/server/chunks/471.js +2 -0
- package/.next/server/chunks/590.js +7 -0
- package/.next/server/chunks/621.js +1 -0
- package/.next/server/chunks/682.js +6 -0
- package/.next/server/chunks/904.js +1 -0
- package/.next/server/chunks/948.js +2 -0
- package/.next/server/chunks/972.js +12 -0
- package/.next/server/chunks/font-manifest.json +1 -0
- package/.next/server/font-manifest.json +1 -0
- package/.next/server/functions-config-manifest.json +1 -0
- package/.next/server/interception-route-rewrite-manifest.js +1 -0
- package/.next/server/middleware-build-manifest.js +1 -0
- package/.next/server/middleware-manifest.json +6 -0
- package/.next/server/middleware-react-loadable-manifest.js +1 -0
- package/.next/server/next-font-manifest.js +1 -0
- package/.next/server/next-font-manifest.json +1 -0
- package/.next/server/pages/404.html +1 -0
- package/.next/server/pages/500.html +1 -0
- package/.next/server/pages/_app.js +1 -0
- package/.next/server/pages/_app.js.nft.json +1 -0
- package/.next/server/pages/_document.js +1 -0
- package/.next/server/pages/_document.js.nft.json +1 -0
- package/.next/server/pages/_error.js +1 -0
- package/.next/server/pages/_error.js.nft.json +1 -0
- package/.next/server/pages-manifest.json +1 -0
- package/.next/server/server-reference-manifest.js +1 -0
- package/.next/server/server-reference-manifest.json +1 -0
- package/.next/server/webpack-runtime.js +1 -0
- package/.next/static/2gHioRND6aAzT4OB5OHDV/_buildManifest.js +1 -0
- package/.next/static/2gHioRND6aAzT4OB5OHDV/_ssgManifest.js +1 -0
- package/.next/static/chunks/117-0f4ac3c2c1871d4c.js +2 -0
- package/.next/static/chunks/171-d325f9625379d70a.js +1 -0
- package/.next/static/chunks/235.aef4cdc783360b73.js +1 -0
- package/.next/static/chunks/30d07d85.9045c666bb43d9e1.js +3 -0
- package/.next/static/chunks/app/_not-found/page-8ff6572bc7c9bc61.js +1 -0
- package/.next/static/chunks/app/demo/page-6711b34cd2af0e4a.js +1 -0
- package/.next/static/chunks/app/layout-d058836232e72324.js +1 -0
- package/.next/static/chunks/app/page-fedaef1e63f186c2.js +1 -0
- package/.next/static/chunks/fd9d1056-26bd8d656b496dba.js +1 -0
- package/.next/static/chunks/framework-f66176bb897dc684.js +1 -0
- package/.next/static/chunks/main-app-4b855ea14675b961.js +1 -0
- package/.next/static/chunks/main-e88dbd51c3bdafca.js +1 -0
- package/.next/static/chunks/pages/_app-72b849fbd24ac258.js +1 -0
- package/.next/static/chunks/pages/_error-7ba65e1336b92748.js +1 -0
- package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/.next/static/chunks/webpack-1f89b7cb1fca69c4.js +1 -0
- package/.next/static/css/6e83ef44d507c857.css +3 -0
- package/.next/static/css/ab3e4b0f5035257a.css +1 -0
- package/.next/trace +23 -0
- package/.next/types/app/api/automations/existing/route.ts +343 -0
- package/.next/types/app/api/backends/route.ts +343 -0
- package/.next/types/app/api/diff/route.ts +343 -0
- package/.next/types/app/api/limits/route.ts +343 -0
- package/.next/types/app/api/meetings/[id]/route.ts +343 -0
- package/.next/types/app/api/meetings/[id]/slack/route.ts +343 -0
- package/.next/types/app/api/meetings/library/route.ts +343 -0
- package/.next/types/app/api/meetings/route.ts +343 -0
- package/.next/types/app/api/models/route.ts +343 -0
- package/.next/types/app/api/notes/route.ts +343 -0
- package/.next/types/app/api/orgs/[id]/route.ts +343 -0
- package/.next/types/app/api/orgs/route.ts +343 -0
- package/.next/types/app/api/prs/inbox/route.ts +343 -0
- package/.next/types/app/api/prs/refresh/route.ts +343 -0
- package/.next/types/app/api/prs/route.ts +343 -0
- package/.next/types/app/api/session-names/route.ts +343 -0
- package/.next/types/app/api/sessions/[id]/route.ts +343 -0
- package/.next/types/app/api/sessions/route.ts +343 -0
- package/.next/types/app/api/settings/auth/route.ts +343 -0
- package/.next/types/app/api/settings/route.ts +343 -0
- package/.next/types/app/api/settings/transcription/route.ts +343 -0
- package/.next/types/app/api/skills/[name]/route.ts +343 -0
- package/.next/types/app/api/skills/marketplace/route.ts +343 -0
- package/.next/types/app/api/skills/route.ts +343 -0
- package/.next/types/app/api/skills/view/route.ts +343 -0
- package/.next/types/app/api/slack/channels/route.ts +343 -0
- package/.next/types/app/api/slack/configured/route.ts +343 -0
- package/.next/types/app/api/slack/inbox/route.ts +343 -0
- package/.next/types/app/api/tasks/route.ts +343 -0
- package/.next/types/app/api/usage/route.ts +343 -0
- package/.next/types/app/demo/page.ts +79 -0
- package/.next/types/app/layout.ts +79 -0
- package/.next/types/app/page.ts +79 -0
- package/.next/types/package.json +1 -0
- package/.server-dist/server.js +600 -0
- package/.server-dist/src/lib/activeOrg.js +11 -0
- package/.server-dist/src/lib/audioCapture.js +157 -0
- package/.server-dist/src/lib/backends.js +209 -0
- package/.server-dist/src/lib/claudeAuth.js +57 -0
- package/.server-dist/src/lib/configFile.js +23 -0
- package/.server-dist/src/lib/dataDir.js +7 -0
- package/.server-dist/src/lib/diffReview.js +116 -0
- package/.server-dist/src/lib/existingAutomations.js +132 -0
- package/.server-dist/src/lib/ghInbox.js +151 -0
- package/.server-dist/src/lib/ghPrStatus.js +86 -0
- package/.server-dist/src/lib/gitUtils.js +27 -0
- package/.server-dist/src/lib/keepAwake.js +32 -0
- package/.server-dist/src/lib/liveSessionStore.js +89 -0
- package/.server-dist/src/lib/marketplace.js +63 -0
- package/.server-dist/src/lib/meetingAssistant.js +138 -0
- package/.server-dist/src/lib/meetingConfig.js +81 -0
- package/.server-dist/src/lib/meetingContext.js +82 -0
- package/.server-dist/src/lib/meetingManager.js +246 -0
- package/.server-dist/src/lib/meetingStore.js +198 -0
- package/.server-dist/src/lib/modelCatalog.js +114 -0
- package/.server-dist/src/lib/notesStore.js +67 -0
- package/.server-dist/src/lib/orgFilter.js +19 -0
- package/.server-dist/src/lib/orgParam.js +15 -0
- package/.server-dist/src/lib/orgRegistry.js +93 -0
- package/.server-dist/src/lib/pipelineView.js +62 -0
- package/.server-dist/src/lib/pipelines.js +427 -0
- package/.server-dist/src/lib/planLimits.js +101 -0
- package/.server-dist/src/lib/prDetector.js +16 -0
- package/.server-dist/src/lib/prScanCache.js +144 -0
- package/.server-dist/src/lib/prSessionEntries.js +96 -0
- package/.server-dist/src/lib/prTypes.js +2 -0
- package/.server-dist/src/lib/ptyManager.js +437 -0
- package/.server-dist/src/lib/reminders.js +10 -0
- package/.server-dist/src/lib/requestGuard.js +29 -0
- package/.server-dist/src/lib/sessionNameStore.js +69 -0
- package/.server-dist/src/lib/sessionStore.js +215 -0
- package/.server-dist/src/lib/settingsStore.js +51 -0
- package/.server-dist/src/lib/skillsReader.js +200 -0
- package/.server-dist/src/lib/slackBridge.js +270 -0
- package/.server-dist/src/lib/slackInbox.js +96 -0
- package/.server-dist/src/lib/slackWatchers.js +210 -0
- package/.server-dist/src/lib/statusDetector.js +50 -0
- package/.server-dist/src/lib/taskStore.js +42 -0
- package/.server-dist/src/lib/transcriber.js +61 -0
- package/.server-dist/src/lib/usageStore.js +254 -0
- package/.server-dist/src/lib/worktrees.js +42 -0
- package/.server-dist/tsconfig.server.tsbuildinfo +1 -0
- package/LICENSE +21 -0
- package/README.md +111 -2
- package/bin/polyergon.js +34 -0
- package/next.config.mjs +4 -0
- package/package.json +81 -4
- package/public/.gitkeep +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/icon-192.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +1 -0
- package/public/manifest.webmanifest +15 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findDueReminder = findDueReminder;
|
|
4
|
+
// Client-safe (no fs import — notesStore.ts is server-only and can't be
|
|
5
|
+
// bundled into components). First note whose reminder is due and not yet
|
|
6
|
+
// fired; shared by the Sidebar's 30s tick and the test.
|
|
7
|
+
function findDueReminder(notes, now = Date.now()) {
|
|
8
|
+
var _a;
|
|
9
|
+
return (_a = notes.find(n => n.remindAt !== undefined && n.remindAt <= now && !n.reminderDone)) !== null && _a !== void 0 ? _a : null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.allowedHosts = allowedHosts;
|
|
4
|
+
exports.isAllowedRequest = isAllowedRequest;
|
|
5
|
+
// Polyergon drives shells with permission checks off, so only the app's own
|
|
6
|
+
// pages may talk to it. Blocks other websites (cross-site WebSocket / CSRF via
|
|
7
|
+
// the Origin header) and DNS rebinding (via the Host header).
|
|
8
|
+
// polyergon.localhost: browsers resolve *.localhost to this machine with no setup
|
|
9
|
+
const DEFAULT_HOSTS = ['localhost', '127.0.0.1', '[::1]', 'polyergon', 'polyergon.localhost'];
|
|
10
|
+
function allowedHosts() {
|
|
11
|
+
var _a;
|
|
12
|
+
const extra = ((_a = process.env.POLYERGON_ALLOWED_HOSTS) !== null && _a !== void 0 ? _a : '').split(',').map(h => h.trim()).filter(Boolean);
|
|
13
|
+
return [...DEFAULT_HOSTS, ...extra];
|
|
14
|
+
}
|
|
15
|
+
function hostname(hostHeader) {
|
|
16
|
+
return hostHeader.startsWith('[') ? hostHeader.slice(0, hostHeader.indexOf(']') + 1) : hostHeader.split(':')[0];
|
|
17
|
+
}
|
|
18
|
+
function isAllowedRequest(headers, hosts = allowedHosts()) {
|
|
19
|
+
if (!headers.host || !hosts.includes(hostname(headers.host).toLowerCase()))
|
|
20
|
+
return false;
|
|
21
|
+
if (!headers.origin)
|
|
22
|
+
return true; // same-origin GETs and non-browser clients send none
|
|
23
|
+
try {
|
|
24
|
+
return hosts.includes(hostname(new URL(headers.origin).host).toLowerCase());
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.sessionNameStore = exports.SessionNameStore = void 0;
|
|
5
|
+
const dataDir_1 = require("./dataDir");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
// Server-side persistence for user-chosen session names, keyed by session id
|
|
9
|
+
// (both the app's internal live id and the CLI's claudeSessionId are stored, so
|
|
10
|
+
// a name resolves whichever key a card looks it up by). Lives on the server —
|
|
11
|
+
// not browser localStorage — so names are the same across hostnames, browsers,
|
|
12
|
+
// and machines. This is what makes localhost:3030 and polyergon:3030 agree.
|
|
13
|
+
const DEFAULT_FILE = (0, path_1.join)(dataDir_1.DATA_DIR, 'session-names.json');
|
|
14
|
+
class SessionNameStore {
|
|
15
|
+
constructor(file = DEFAULT_FILE) {
|
|
16
|
+
this.names = {};
|
|
17
|
+
this.file = file;
|
|
18
|
+
this.dir = (0, path_1.join)(file, '..');
|
|
19
|
+
this.load();
|
|
20
|
+
}
|
|
21
|
+
load() {
|
|
22
|
+
try {
|
|
23
|
+
this.names = JSON.parse((0, fs_1.readFileSync)(this.file, 'utf-8'));
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
this.names = {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
all() {
|
|
30
|
+
return Object.assign({}, this.names);
|
|
31
|
+
}
|
|
32
|
+
set(key, name) {
|
|
33
|
+
const trimmed = name.trim();
|
|
34
|
+
if (!trimmed)
|
|
35
|
+
return;
|
|
36
|
+
this.names[key] = trimmed;
|
|
37
|
+
this.persist();
|
|
38
|
+
}
|
|
39
|
+
// Bulk import (used to migrate existing browser localStorage names in). Only
|
|
40
|
+
// fills keys we don't already have, so a stale client copy can't clobber a
|
|
41
|
+
// name already set on the server.
|
|
42
|
+
merge(incoming) {
|
|
43
|
+
let changed = false;
|
|
44
|
+
for (const [k, v] of Object.entries(incoming)) {
|
|
45
|
+
if (typeof v === 'string' && v.trim() && !this.names[k]) {
|
|
46
|
+
this.names[k] = v.trim();
|
|
47
|
+
changed = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (changed)
|
|
51
|
+
this.persist();
|
|
52
|
+
}
|
|
53
|
+
remove(key) {
|
|
54
|
+
if (key in this.names) {
|
|
55
|
+
delete this.names[key];
|
|
56
|
+
this.persist();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
persist() {
|
|
60
|
+
try {
|
|
61
|
+
if (!(0, fs_1.existsSync)(this.dir))
|
|
62
|
+
(0, fs_1.mkdirSync)(this.dir, { recursive: true });
|
|
63
|
+
(0, fs_1.writeFileSync)(this.file, JSON.stringify(this.names));
|
|
64
|
+
}
|
|
65
|
+
catch (_a) { }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.SessionNameStore = SessionNameStore;
|
|
69
|
+
exports.sessionNameStore = (_a = global.__sessionNameStore) !== null && _a !== void 0 ? _a : (global.__sessionNameStore = new SessionNameStore());
|
|
@@ -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
|
+
}
|