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.
- 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/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/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 +1 -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 +34 -0
- package/.next/server/chunks/348.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/chunks/117-0f4ac3c2c1871d4c.js +2 -0
- package/.next/static/chunks/171-f72ed164561ba218.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-cebeba7d6d08548a.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-960df1c7509a5a8b.js +1 -0
- package/.next/static/chunks/main-app-4b855ea14675b961.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/a537d3e86c0f36d2.css +3 -0
- package/.next/static/css/ab3e4b0f5035257a.css +1 -0
- package/.next/static/q-HMeHYZY36qljBJhsyS6/_buildManifest.js +1 -0
- package/.next/static/q-HMeHYZY36qljBJhsyS6/_ssgManifest.js +1 -0
- package/.next/trace +22 -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/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/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 +554 -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 +111 -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/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 +107 -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 +401 -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 +428 -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 +46 -0
- package/.server-dist/src/lib/transcriber.js +61 -0
- package/.server-dist/src/lib/usageStore.js +254 -0
- package/.server-dist/tsconfig.server.tsbuildinfo +1 -0
- package/LICENSE +21 -0
- package/README.md +99 -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,428 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.STARTUP_DIALOG_RE = void 0;
|
|
37
|
+
exports.claudeProjectDir = claudeProjectDir;
|
|
38
|
+
exports.findSessionIdSince = findSessionIdSince;
|
|
39
|
+
exports.spawnSession = spawnSession;
|
|
40
|
+
exports.writeToSession = writeToSession;
|
|
41
|
+
exports.onScreenDialog = onScreenDialog;
|
|
42
|
+
exports.sendWhenReady = sendWhenReady;
|
|
43
|
+
exports.submitLine = submitLine;
|
|
44
|
+
exports.resizeSession = resizeSession;
|
|
45
|
+
exports.getLastKnownSize = getLastKnownSize;
|
|
46
|
+
exports.killSession = killSession;
|
|
47
|
+
exports.onOutput = onOutput;
|
|
48
|
+
exports.onStatusChange = onStatusChange;
|
|
49
|
+
exports.onAnyStatusChange = onAnyStatusChange;
|
|
50
|
+
exports.onAnyRcUrlChange = onAnyRcUrlChange;
|
|
51
|
+
exports.onAnyPrUrlChange = onAnyPrUrlChange;
|
|
52
|
+
exports.getSerializedScreen = getSerializedScreen;
|
|
53
|
+
const pty = __importStar(require("node-pty"));
|
|
54
|
+
const fs_1 = require("fs");
|
|
55
|
+
const path_1 = require("path");
|
|
56
|
+
const headless_1 = require("@xterm/headless");
|
|
57
|
+
const addon_serialize_1 = require("@xterm/addon-serialize");
|
|
58
|
+
const liveSessionStore_1 = require("./liveSessionStore");
|
|
59
|
+
const statusDetector_1 = require("./statusDetector");
|
|
60
|
+
const prDetector_1 = require("./prDetector");
|
|
61
|
+
const backends_1 = require("./backends");
|
|
62
|
+
const settingsStore_1 = require("./settingsStore");
|
|
63
|
+
const claudeAuth_1 = require("./claudeAuth");
|
|
64
|
+
const UUID_JSONL = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.jsonl$/i;
|
|
65
|
+
// Auto-confirm the workspace trust dialog matches on this stripped text, and
|
|
66
|
+
// PR-URL scanning needs the same ANSI-free view of each chunk — computed once
|
|
67
|
+
// per chunk and shared by both.
|
|
68
|
+
const ANSI_STRIP = /\x1b\[[0-9;]*[a-zA-Z]|\x1b[()][A-Z0-9]/g;
|
|
69
|
+
function claudeProjectDir(cwd, configDir) {
|
|
70
|
+
// Claude Code resolves symlinks in cwd before naming its project dir
|
|
71
|
+
// (e.g. macOS /tmp -> /private/tmp), so we must match that exactly.
|
|
72
|
+
let real = cwd;
|
|
73
|
+
try {
|
|
74
|
+
real = (0, fs_1.realpathSync)(cwd);
|
|
75
|
+
}
|
|
76
|
+
catch (_a) { }
|
|
77
|
+
const root = configDir || (0, path_1.join)(process.env.HOME, '.claude');
|
|
78
|
+
return (0, path_1.join)(root, 'projects', real.replace(/\//g, '-'));
|
|
79
|
+
}
|
|
80
|
+
// Find the .jsonl file Claude created for a session in cwd by looking for
|
|
81
|
+
// files whose birth time is >= sinceTime. Uses birth time (not mtime) so it
|
|
82
|
+
// can't be fooled by writes to older session files.
|
|
83
|
+
function findSessionIdSince(cwd, sinceTime, configDir) {
|
|
84
|
+
var _a;
|
|
85
|
+
const projectDir = claudeProjectDir(cwd, configDir);
|
|
86
|
+
if (!(0, fs_1.existsSync)(projectDir))
|
|
87
|
+
return null;
|
|
88
|
+
let best = null;
|
|
89
|
+
for (const f of (0, fs_1.readdirSync)(projectDir)) {
|
|
90
|
+
if (!UUID_JSONL.test(f))
|
|
91
|
+
continue;
|
|
92
|
+
try {
|
|
93
|
+
const { birthtimeMs } = (0, fs_1.statSync)((0, path_1.join)(projectDir, f));
|
|
94
|
+
// Accept files born at or after sinceTime (1 s tolerance for event-loop lag)
|
|
95
|
+
if (birthtimeMs >= sinceTime - 1000 && (!best || birthtimeMs > best.t)) {
|
|
96
|
+
best = { uuid: f.replace('.jsonl', ''), t: birthtimeMs };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (_b) { }
|
|
100
|
+
}
|
|
101
|
+
return (_a = best === null || best === void 0 ? void 0 : best.uuid) !== null && _a !== void 0 ? _a : null;
|
|
102
|
+
}
|
|
103
|
+
async function detectAndStoreSessionId(id, cwd, spawnTime, configDir, backend) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
for (let i = 0; i < 60; i++) {
|
|
106
|
+
await new Promise(r => setTimeout(r, 500));
|
|
107
|
+
if (!ptyProcesses.has(id))
|
|
108
|
+
return;
|
|
109
|
+
// Claude's finder needs the configDir (which project dir to scan); other
|
|
110
|
+
// backends provide their own detectSessionId (e.g. Copilot's session store).
|
|
111
|
+
const uuid = backend.id === 'claude'
|
|
112
|
+
? findSessionIdSince(cwd, spawnTime, configDir)
|
|
113
|
+
: (_b = (_a = backend.detectSessionId) === null || _a === void 0 ? void 0 : _a.call(backend, cwd, spawnTime)) !== null && _b !== void 0 ? _b : null;
|
|
114
|
+
if (uuid) {
|
|
115
|
+
liveSessionStore_1.liveSessionStore.setClaudeSessionId(id, uuid);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const outputListeners = new Map();
|
|
121
|
+
const statusListeners = new Map();
|
|
122
|
+
// Unlike statusListeners (only populated for whichever session a connection
|
|
123
|
+
// has attached to), this fires for every session's status change regardless
|
|
124
|
+
// of attachment, so clients can track sessions they aren't currently viewing.
|
|
125
|
+
const anyStatusListeners = new Set();
|
|
126
|
+
const anyPrUrlListeners = new Set();
|
|
127
|
+
const anyRcUrlListeners = new Set();
|
|
128
|
+
const RC_URL_RE = /https:\/\/claude\.ai\/code\/session_[A-Za-z0-9]+/;
|
|
129
|
+
const ptyProcesses = new Map();
|
|
130
|
+
const thinkingTimers = new Map();
|
|
131
|
+
// Small rolling ANSI-stripped tail per session, scanned for a PR URL as
|
|
132
|
+
// output streams through — no extra file I/O beyond what's already flowing.
|
|
133
|
+
const prScanBuffers = new Map();
|
|
134
|
+
const PR_SCAN_BUFFER_MAX = 300;
|
|
135
|
+
// Headless terminal per session: mirrors the PTY's actual rendered screen state.
|
|
136
|
+
// Claude's CLI redraws in place via relative cursor movement rather than plain
|
|
137
|
+
// appended output, so reattach/status-detection must read the real current
|
|
138
|
+
// buffer instead of replaying or pattern-matching raw output chunks.
|
|
139
|
+
const headlessTerms = new Map();
|
|
140
|
+
let lastCols = 120;
|
|
141
|
+
let lastRows = 30;
|
|
142
|
+
// Returns the plain-text lines around the cursor's current row, for status
|
|
143
|
+
// detection against the terminal's true current state (not a transient chunk).
|
|
144
|
+
function emitStatus(id, status) {
|
|
145
|
+
var _a;
|
|
146
|
+
(_a = statusListeners.get(id)) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(status));
|
|
147
|
+
anyStatusListeners.forEach(fn => fn(id, status));
|
|
148
|
+
}
|
|
149
|
+
function emitRcUrl(id, rcUrl) {
|
|
150
|
+
anyRcUrlListeners.forEach(fn => fn(id, rcUrl));
|
|
151
|
+
}
|
|
152
|
+
function emitPrUrl(id, prUrl) {
|
|
153
|
+
anyPrUrlListeners.forEach(fn => fn(id, prUrl));
|
|
154
|
+
}
|
|
155
|
+
function bufferTail(term, maxLines = 8) {
|
|
156
|
+
const buf = term.buffer.active;
|
|
157
|
+
const cursorAbsY = buf.baseY + buf.cursorY;
|
|
158
|
+
const startY = Math.max(0, cursorAbsY - maxLines + 1);
|
|
159
|
+
const lines = [];
|
|
160
|
+
for (let y = startY; y <= cursorAbsY; y++) {
|
|
161
|
+
const line = buf.getLine(y);
|
|
162
|
+
if (line)
|
|
163
|
+
lines.push(line.translateToString(true));
|
|
164
|
+
}
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
// Last `n` rows of the visible screen (for TUIs whose status bar is at the bottom).
|
|
168
|
+
function bottomRows(term, n) {
|
|
169
|
+
const buf = term.buffer.active;
|
|
170
|
+
const lines = [];
|
|
171
|
+
for (let y = buf.viewportY + term.rows - n; y < buf.viewportY + term.rows; y++) {
|
|
172
|
+
const line = buf.getLine(y);
|
|
173
|
+
if (line)
|
|
174
|
+
lines.push(line.translateToString(true));
|
|
175
|
+
}
|
|
176
|
+
return lines.join('\n');
|
|
177
|
+
}
|
|
178
|
+
// The account has Fable 5.1 (API id `claude-fable-5-1`, with dashes). Two
|
|
179
|
+
// gotchas: the dotted form `claude-fable-5.1` is silently accepted but falls
|
|
180
|
+
// back to Opus 5, and CLI 2.1.241 doesn't yet recognize the dashed id — it
|
|
181
|
+
// rejects it unless CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1 is
|
|
182
|
+
// set on the process env (see spawn env below).
|
|
183
|
+
const DEFAULT_MODEL = 'claude-opus-5-5';
|
|
184
|
+
// The Claude mobile app / claude.ai lists each Remote Control session by the
|
|
185
|
+
// name passed to `--remote-control <name>`. Keep it a clean single token-ish
|
|
186
|
+
// label (spaces are fine — it's its own argv element — but strip control chars
|
|
187
|
+
// and cap the length so the phone list stays readable).
|
|
188
|
+
function sanitizeRcName(name) {
|
|
189
|
+
return name.replace(/[\x00-\x1f\x7f]/g, '').trim().slice(0, 60);
|
|
190
|
+
}
|
|
191
|
+
function spawnSession(id, cwd, resumeId, configDir, model, rcName, backendId, rc) {
|
|
192
|
+
const spawnTime = Date.now();
|
|
193
|
+
const cleanRcName = rcName ? sanitizeRcName(rcName) : '';
|
|
194
|
+
const backend = (0, backends_1.getBackend)(backendId);
|
|
195
|
+
const effectiveModel = model || DEFAULT_MODEL;
|
|
196
|
+
// The backend (Claude / Copilot / …) owns its own argv shape, binary, and
|
|
197
|
+
// any model-specific env. Remote Control naming etc. is Claude-specific and
|
|
198
|
+
// handled inside its spec. Remote Control is gated by the user's
|
|
199
|
+
// ~/.claude/settings.json CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC flag — we
|
|
200
|
+
// must NOT drop the user settings source to bypass it (it also carries all
|
|
201
|
+
// skills/plugins; doing so blanked every skill).
|
|
202
|
+
const args = backend.spawnArgs({ model: effectiveModel, cwd, resumeId, rcName: cleanRcName || undefined, rc: !!rc, skipPermissions: (0, settingsStore_1.getSettings)().sessions.skipPermissions });
|
|
203
|
+
const proc = pty.spawn(backend.bin, args, {
|
|
204
|
+
name: 'xterm-color',
|
|
205
|
+
cols: lastCols,
|
|
206
|
+
rows: lastRows,
|
|
207
|
+
cwd,
|
|
208
|
+
env: Object.assign(Object.assign(Object.assign(Object.assign({}, Object.fromEntries(['PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'TERM', 'LANG', 'LC_ALL', 'ANTHROPIC_API_KEY']
|
|
209
|
+
.filter(k => process.env[k])
|
|
210
|
+
.map(k => [k, process.env[k]]))), backend.env(effectiveModel)), (backend.id === 'claude' ? Object.assign(Object.assign({}, (0, settingsStore_1.autoCompactEnv)()), (0, claudeAuth_1.claudeAuthEnv)()) : {})), (configDir ? { CLAUDE_CONFIG_DIR: configDir } : {})),
|
|
211
|
+
});
|
|
212
|
+
ptyProcesses.set(id, proc);
|
|
213
|
+
liveSessionStore_1.liveSessionStore.setRcUrl(id, null);
|
|
214
|
+
outputListeners.set(id, new Set());
|
|
215
|
+
statusListeners.set(id, new Set());
|
|
216
|
+
const headlessTerm = new headless_1.Terminal({ cols: lastCols, rows: lastRows, allowProposedApi: true, scrollback: 2000 });
|
|
217
|
+
const serializeAddon = new addon_serialize_1.SerializeAddon();
|
|
218
|
+
headlessTerm.loadAddon(serializeAddon);
|
|
219
|
+
headlessTerms.set(id, { term: headlessTerm, serialize: serializeAddon });
|
|
220
|
+
// For new sessions, detect the session file Claude creates and persist its ID
|
|
221
|
+
if (!resumeId)
|
|
222
|
+
detectAndStoreSessionId(id, cwd, spawnTime, configDir, backend);
|
|
223
|
+
// Auto-confirm the workspace/folder trust dialog both CLIs show for a new
|
|
224
|
+
// directory. Claude: "Yes, trust" is pre-selected, \r accepts it. Copilot:
|
|
225
|
+
// "Do you trust the files in this folder?" with option 1 (Yes) pre-selected
|
|
226
|
+
// and option 2 ("Yes, and remember…") below — we pick 2 (↓ then \r) so it
|
|
227
|
+
// won't ask again for that folder. The prompt can span multiple PTY chunks,
|
|
228
|
+
// so we match against a small rolling buffer, not a single chunk. Words are
|
|
229
|
+
// separated by cursor-forward ANSI codes, so match on ANSI-stripped text.
|
|
230
|
+
let trustConfirmed = false;
|
|
231
|
+
let trustScanBuf = '';
|
|
232
|
+
prScanBuffers.set(id, '');
|
|
233
|
+
proc.onData((data) => {
|
|
234
|
+
var _a, _b, _c, _d;
|
|
235
|
+
(_a = outputListeners.get(id)) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(data));
|
|
236
|
+
const stripped = data.replace(ANSI_STRIP, '');
|
|
237
|
+
if (!trustConfirmed) {
|
|
238
|
+
trustScanBuf = (trustScanBuf + stripped).slice(-2000);
|
|
239
|
+
if (backend.id === 'claude' && /Enter/.test(trustScanBuf) && /confirm/.test(trustScanBuf)) {
|
|
240
|
+
trustConfirmed = true;
|
|
241
|
+
// CLI ≥2.1.3xx preselects "No, exit"; older ones preselect "Yes". Read
|
|
242
|
+
// the rendered screen once it settles and move to "Yes" only if needed.
|
|
243
|
+
setTimeout(() => {
|
|
244
|
+
const tail = bufferTail(headlessTerm, 12);
|
|
245
|
+
if (/❯\s*No/.test(tail)) {
|
|
246
|
+
proc.write('\x1b[B');
|
|
247
|
+
setTimeout(() => proc.write('\r'), 500);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
proc.write('\r');
|
|
251
|
+
}
|
|
252
|
+
}, 1000);
|
|
253
|
+
}
|
|
254
|
+
else if (backend.id !== 'claude' && /trust the files in this folder/i.test(trustScanBuf)) {
|
|
255
|
+
trustConfirmed = true;
|
|
256
|
+
proc.write('\x1b[B'); // ↓ to option 2 ("Yes, and remember this folder")
|
|
257
|
+
setTimeout(() => proc.write('\r'), 60);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// Rolling tail scan for a PR URL (e.g. from `gh pr create` output) — no
|
|
261
|
+
// extra file I/O, reuses output already streaming through.
|
|
262
|
+
const buf = (((_b = prScanBuffers.get(id)) !== null && _b !== void 0 ? _b : '') + stripped).slice(-PR_SCAN_BUFFER_MAX);
|
|
263
|
+
prScanBuffers.set(id, buf);
|
|
264
|
+
// Remote Control pairing link ("Continue here, on your phone, or at …")
|
|
265
|
+
const rc = (_c = buf.match(RC_URL_RE)) === null || _c === void 0 ? void 0 : _c[0];
|
|
266
|
+
if (rc && ((_d = liveSessionStore_1.liveSessionStore.get(id)) === null || _d === void 0 ? void 0 : _d.rcUrl) !== rc) {
|
|
267
|
+
liveSessionStore_1.liveSessionStore.setRcUrl(id, rc);
|
|
268
|
+
emitRcUrl(id, rc);
|
|
269
|
+
}
|
|
270
|
+
const prUrl = (0, prDetector_1.extractPrUrl)(buf);
|
|
271
|
+
if (prUrl) {
|
|
272
|
+
const session = liveSessionStore_1.liveSessionStore.get(id);
|
|
273
|
+
if (session && session.prUrl !== prUrl) {
|
|
274
|
+
liveSessionStore_1.liveSessionStore.setPrUrl(id, prUrl);
|
|
275
|
+
emitPrUrl(id, prUrl);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// headlessTerm.write() parses asynchronously — the buffer only reflects
|
|
279
|
+
// this chunk once the callback fires, so status detection must happen there.
|
|
280
|
+
headlessTerm.write(data, () => {
|
|
281
|
+
if (!headlessTerms.has(id))
|
|
282
|
+
return;
|
|
283
|
+
// Copilot's status lives in the footer below the cursor, so read the
|
|
284
|
+
// screen bottom for it; Claude's lives in the lines around the cursor.
|
|
285
|
+
const status = backend.id === 'copilot'
|
|
286
|
+
? (0, statusDetector_1.detectStatus)(bottomRows(headlessTerm, 3), 'copilot')
|
|
287
|
+
// Claude's footer (below the prompt) says "esc to interrupt" while busy
|
|
288
|
+
: (0, statusDetector_1.detectStatus)(bufferTail(headlessTerm) + '\n' + bottomRows(headlessTerm, 3));
|
|
289
|
+
const session = liveSessionStore_1.liveSessionStore.get(id);
|
|
290
|
+
if (!session)
|
|
291
|
+
return;
|
|
292
|
+
if (status === 'waiting') {
|
|
293
|
+
// Cancel any pending thinking transition — waiting wins immediately
|
|
294
|
+
const t = thinkingTimers.get(id);
|
|
295
|
+
if (t) {
|
|
296
|
+
clearTimeout(t);
|
|
297
|
+
thinkingTimers.delete(id);
|
|
298
|
+
}
|
|
299
|
+
if (session.status !== 'waiting') {
|
|
300
|
+
liveSessionStore_1.liveSessionStore.setStatus(id, 'waiting');
|
|
301
|
+
emitStatus(id, 'waiting');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
else if (status === 'thinking' && session.status !== 'thinking') {
|
|
305
|
+
// Debounce: trailing chunks after the ❯ prompt often lack ❯, don't
|
|
306
|
+
// let them immediately clobber a 'waiting' state we just set.
|
|
307
|
+
if (!thinkingTimers.has(id)) {
|
|
308
|
+
thinkingTimers.set(id, setTimeout(() => {
|
|
309
|
+
thinkingTimers.delete(id);
|
|
310
|
+
const s = liveSessionStore_1.liveSessionStore.get(id);
|
|
311
|
+
if (s && s.status !== 'thinking') {
|
|
312
|
+
liveSessionStore_1.liveSessionStore.setStatus(id, 'thinking');
|
|
313
|
+
emitStatus(id, 'thinking');
|
|
314
|
+
}
|
|
315
|
+
}, 800));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
proc.onExit(() => {
|
|
321
|
+
var _a;
|
|
322
|
+
// A re-spawn (restart / resume-with-new-model) registers a NEW proc under
|
|
323
|
+
// the same id before this old one has exited. Only the current owner may
|
|
324
|
+
// tear the id's state down, or the new session is orphaned on arrival.
|
|
325
|
+
if (ptyProcesses.get(id) !== proc)
|
|
326
|
+
return;
|
|
327
|
+
const t = thinkingTimers.get(id);
|
|
328
|
+
if (t) {
|
|
329
|
+
clearTimeout(t);
|
|
330
|
+
thinkingTimers.delete(id);
|
|
331
|
+
}
|
|
332
|
+
liveSessionStore_1.liveSessionStore.setStatus(id, 'idle');
|
|
333
|
+
emitStatus(id, 'idle');
|
|
334
|
+
ptyProcesses.delete(id);
|
|
335
|
+
outputListeners.delete(id);
|
|
336
|
+
statusListeners.delete(id);
|
|
337
|
+
(_a = headlessTerms.get(id)) === null || _a === void 0 ? void 0 : _a.term.dispose();
|
|
338
|
+
headlessTerms.delete(id);
|
|
339
|
+
prScanBuffers.delete(id);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function writeToSession(id, data) {
|
|
343
|
+
var _a;
|
|
344
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.write(data);
|
|
345
|
+
}
|
|
346
|
+
// Startup screens that take keystrokes but are NOT the input prompt (folder
|
|
347
|
+
// trust, login, theme, etc.). Typing a prompt into them answers them wrongly.
|
|
348
|
+
exports.STARTUP_DIALOG_RE = /trust this folder|Quick safety check|Enter to confirm|Do you trust|Select login method|Choose the text style|Press Enter to continue/i;
|
|
349
|
+
function onScreenDialog(id) {
|
|
350
|
+
const h = headlessTerms.get(id);
|
|
351
|
+
return !!h && exports.STARTUP_DIALOG_RE.test(bottomRows(h.term, 25));
|
|
352
|
+
}
|
|
353
|
+
// Sends `text` as the session's first prompt once it sits at the real input
|
|
354
|
+
// prompt; while a startup dialog is showing it waits for you to answer it.
|
|
355
|
+
function sendWhenReady(id, text, timeoutMs = 10 * 60000) {
|
|
356
|
+
const started = Date.now();
|
|
357
|
+
const tick = () => {
|
|
358
|
+
var _a;
|
|
359
|
+
if (!ptyProcesses.has(id) || Date.now() - started > timeoutMs)
|
|
360
|
+
return;
|
|
361
|
+
if (((_a = liveSessionStore_1.liveSessionStore.get(id)) === null || _a === void 0 ? void 0 : _a.status) === 'waiting' && !onScreenDialog(id)) {
|
|
362
|
+
submitLine(id, text);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
setTimeout(tick, 1000);
|
|
366
|
+
};
|
|
367
|
+
setTimeout(tick, 1500);
|
|
368
|
+
}
|
|
369
|
+
// Types a line into the agent's prompt and submits it. Enter goes separately:
|
|
370
|
+
// sent in the same write, the TUI treats it as part of a paste and doesn't submit.
|
|
371
|
+
function submitLine(id, text) {
|
|
372
|
+
var _a;
|
|
373
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.write(text);
|
|
374
|
+
setTimeout(() => { var _a; return (_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.write('\r'); }, 250);
|
|
375
|
+
}
|
|
376
|
+
function resizeSession(id, cols, rows) {
|
|
377
|
+
var _a, _b;
|
|
378
|
+
lastCols = cols;
|
|
379
|
+
lastRows = rows;
|
|
380
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.resize(cols, rows);
|
|
381
|
+
(_b = headlessTerms.get(id)) === null || _b === void 0 ? void 0 : _b.term.resize(cols, rows);
|
|
382
|
+
}
|
|
383
|
+
function getLastKnownSize() {
|
|
384
|
+
return { cols: lastCols, rows: lastRows };
|
|
385
|
+
}
|
|
386
|
+
function killSession(id) {
|
|
387
|
+
var _a, _b;
|
|
388
|
+
const t = thinkingTimers.get(id);
|
|
389
|
+
if (t) {
|
|
390
|
+
clearTimeout(t);
|
|
391
|
+
thinkingTimers.delete(id);
|
|
392
|
+
}
|
|
393
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.kill();
|
|
394
|
+
ptyProcesses.delete(id);
|
|
395
|
+
outputListeners.delete(id);
|
|
396
|
+
statusListeners.delete(id);
|
|
397
|
+
(_b = headlessTerms.get(id)) === null || _b === void 0 ? void 0 : _b.term.dispose();
|
|
398
|
+
headlessTerms.delete(id);
|
|
399
|
+
prScanBuffers.delete(id);
|
|
400
|
+
}
|
|
401
|
+
function onOutput(id, fn) {
|
|
402
|
+
var _a;
|
|
403
|
+
(_a = outputListeners.get(id)) === null || _a === void 0 ? void 0 : _a.add(fn);
|
|
404
|
+
return () => { var _a; return (_a = outputListeners.get(id)) === null || _a === void 0 ? void 0 : _a.delete(fn); };
|
|
405
|
+
}
|
|
406
|
+
function onStatusChange(id, fn) {
|
|
407
|
+
var _a;
|
|
408
|
+
(_a = statusListeners.get(id)) === null || _a === void 0 ? void 0 : _a.add(fn);
|
|
409
|
+
return () => { var _a; return (_a = statusListeners.get(id)) === null || _a === void 0 ? void 0 : _a.delete(fn); };
|
|
410
|
+
}
|
|
411
|
+
function onAnyStatusChange(fn) {
|
|
412
|
+
anyStatusListeners.add(fn);
|
|
413
|
+
return () => anyStatusListeners.delete(fn);
|
|
414
|
+
}
|
|
415
|
+
function onAnyRcUrlChange(fn) {
|
|
416
|
+
anyRcUrlListeners.add(fn);
|
|
417
|
+
return () => anyRcUrlListeners.delete(fn);
|
|
418
|
+
}
|
|
419
|
+
function onAnyPrUrlChange(fn) {
|
|
420
|
+
anyPrUrlListeners.add(fn);
|
|
421
|
+
return () => anyPrUrlListeners.delete(fn);
|
|
422
|
+
}
|
|
423
|
+
// Full ANSI reconstruction of the session's actual current screen state, for
|
|
424
|
+
// sending on reattach — not a replay of raw output history.
|
|
425
|
+
function getSerializedScreen(id) {
|
|
426
|
+
var _a, _b;
|
|
427
|
+
return (_b = (_a = headlessTerms.get(id)) === null || _a === void 0 ? void 0 : _a.serialize.serialize()) !== null && _b !== void 0 ? _b : '';
|
|
428
|
+
}
|
|
@@ -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());
|