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,554 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const http_1 = require("http");
|
|
40
|
+
const url_1 = require("url");
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const os_1 = __importDefault(require("os"));
|
|
43
|
+
const fs_1 = require("fs");
|
|
44
|
+
const gitUtils_1 = require("./src/lib/gitUtils");
|
|
45
|
+
const next_1 = __importDefault(require("next"));
|
|
46
|
+
const ws_1 = require("ws");
|
|
47
|
+
const requestGuard_1 = require("./src/lib/requestGuard");
|
|
48
|
+
const uuid_1 = require("uuid");
|
|
49
|
+
const liveSessionStore_1 = require("./src/lib/liveSessionStore");
|
|
50
|
+
const ptyManager_1 = require("./src/lib/ptyManager");
|
|
51
|
+
const orgRegistry_1 = require("./src/lib/orgRegistry");
|
|
52
|
+
const backends_1 = require("./src/lib/backends");
|
|
53
|
+
const meetingManager_1 = require("./src/lib/meetingManager");
|
|
54
|
+
const pipelines_1 = require("./src/lib/pipelines");
|
|
55
|
+
const keepAwake_1 = require("./src/lib/keepAwake");
|
|
56
|
+
const slackWatchers_1 = require("./src/lib/slackWatchers");
|
|
57
|
+
const meetingStore_1 = require("./src/lib/meetingStore");
|
|
58
|
+
const sessionNameStore_1 = require("./src/lib/sessionNameStore");
|
|
59
|
+
const sessionStore_1 = require("./src/lib/sessionStore");
|
|
60
|
+
const fs_2 = require("fs");
|
|
61
|
+
const PORT = Number(process.env.PORT) || 3030;
|
|
62
|
+
const dev = process.env.NODE_ENV !== 'production';
|
|
63
|
+
// Compiled builds run from .server-dist/; the Next app lives one level up.
|
|
64
|
+
const appDir = (0, fs_1.existsSync)(path_1.default.join(__dirname, 'package.json')) ? __dirname : path_1.default.join(__dirname, '..');
|
|
65
|
+
const app = (0, next_1.default)({ dev, dir: appDir });
|
|
66
|
+
const handle = app.getRequestHandler();
|
|
67
|
+
// Label for the Remote Control list on the phone: the user's saved name, else
|
|
68
|
+
// the session's first message, else the folder. (Folder was a bare hash.)
|
|
69
|
+
function rcNameFor(s, explicit) {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
if (explicit)
|
|
72
|
+
return explicit;
|
|
73
|
+
const names = sessionNameStore_1.sessionNameStore.all();
|
|
74
|
+
const saved = (_a = names[s.id]) !== null && _a !== void 0 ? _a : (s.claudeSessionId ? names[s.claudeSessionId] : undefined);
|
|
75
|
+
if (saved)
|
|
76
|
+
return saved;
|
|
77
|
+
if (s.claudeSessionId) {
|
|
78
|
+
const root = (_c = (_b = orgRegistry_1.orgRegistry.get(s.orgId)) === null || _b === void 0 ? void 0 : _b.configDir) !== null && _c !== void 0 ? _c : path_1.default.join(process.env.HOME, '.claude');
|
|
79
|
+
let real = s.cwd;
|
|
80
|
+
try {
|
|
81
|
+
real = (0, fs_2.realpathSync)(s.cwd);
|
|
82
|
+
}
|
|
83
|
+
catch (_d) { }
|
|
84
|
+
const file = path_1.default.join(root, 'projects', real.replace(/\//g, '-'), `${s.claudeSessionId}.jsonl`);
|
|
85
|
+
const first = (0, sessionStore_1.firstUserMessageSync)(file);
|
|
86
|
+
if (first)
|
|
87
|
+
return first.slice(0, 60);
|
|
88
|
+
}
|
|
89
|
+
return path_1.default.basename(s.cwd);
|
|
90
|
+
}
|
|
91
|
+
// Session renames waiting for the Claude prompt to be idle (see 'rename-live')
|
|
92
|
+
const pendingRenames = new Map();
|
|
93
|
+
function flushRename(id) {
|
|
94
|
+
const name = pendingRenames.get(id);
|
|
95
|
+
if (!name)
|
|
96
|
+
return;
|
|
97
|
+
pendingRenames.delete(id);
|
|
98
|
+
(0, ptyManager_1.submitLine)(id, `/rename ${name}`);
|
|
99
|
+
}
|
|
100
|
+
app.prepare().then(async () => {
|
|
101
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
102
|
+
// A restarted server can't resume audio capture — mark stale recordings
|
|
103
|
+
meetingStore_1.meetingStore.markInterrupted();
|
|
104
|
+
// Restore live sessions from previous server run.
|
|
105
|
+
// Only the most recent AUTO_RESUME_CAP sessions are actually respawned with
|
|
106
|
+
// --resume; the rest restore as idle (one click resumes them). Respawning
|
|
107
|
+
// everything at once (observed: 87 simultaneous `claude` processes) pins the
|
|
108
|
+
// machine for minutes and starves the dev server itself.
|
|
109
|
+
const AUTO_RESUME_CAP = 15;
|
|
110
|
+
liveSessionStore_1.LiveSessionStore.backupSaved();
|
|
111
|
+
const saved = liveSessionStore_1.LiveSessionStore.loadSaved().filter(s => s.cwd && (0, fs_1.existsSync)(s.cwd));
|
|
112
|
+
const autoResumeIds = new Set([...saved].sort((a, b) => b.createdAt - a.createdAt).slice(0, AUTO_RESUME_CAP).map(s => s.id));
|
|
113
|
+
for (const s of saved) {
|
|
114
|
+
// Pre-existing persisted entries from before orgId was added default to 'default'.
|
|
115
|
+
const orgId = (_a = s.orgId) !== null && _a !== void 0 ? _a : orgRegistry_1.DEFAULT_ORG_ID;
|
|
116
|
+
const org = orgRegistry_1.orgRegistry.get(orgId);
|
|
117
|
+
const configDir = (_b = org === null || org === void 0 ? void 0 : org.configDir) !== null && _b !== void 0 ? _b : null;
|
|
118
|
+
// Sessions with null claudeSessionId hadn't finished detection before this
|
|
119
|
+
// restart — retroactively scan for the .jsonl Claude created since this
|
|
120
|
+
// session's createdAt before giving up and marking it idle.
|
|
121
|
+
const claudeSessionId = (_c = s.claudeSessionId) !== null && _c !== void 0 ? _c : (0, ptyManager_1.findSessionIdSince)(s.cwd, s.createdAt, configDir);
|
|
122
|
+
// Pre-existing persisted entries from before prUrl was added won't have it.
|
|
123
|
+
const prUrl = (_d = s.prUrl) !== null && _d !== void 0 ? _d : null;
|
|
124
|
+
if (claudeSessionId && autoResumeIds.has(s.id)) {
|
|
125
|
+
liveSessionStore_1.liveSessionStore.add(Object.assign(Object.assign({}, s), { claudeSessionId, status: 'thinking', prUrl, orgId }));
|
|
126
|
+
// A spawn failure must not abort the restore loop — the store persists
|
|
127
|
+
// on every add(), so bailing here wiped every not-yet-added session.
|
|
128
|
+
try {
|
|
129
|
+
(0, ptyManager_1.spawnSession)(s.id, s.cwd, claudeSessionId, configDir, (_e = s.model) !== null && _e !== void 0 ? _e : org === null || org === void 0 ? void 0 : org.model, rcNameFor(Object.assign(Object.assign({}, s), { claudeSessionId, orgId })), s.backend, s.rc);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
console.error(`restore: spawn failed for ${s.id}:`, e);
|
|
133
|
+
liveSessionStore_1.liveSessionStore.setStatus(s.id, 'idle');
|
|
134
|
+
}
|
|
135
|
+
// Stagger even the capped spawns — a burst still spikes memory/CPU.
|
|
136
|
+
await new Promise(r => setTimeout(r, 150));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
liveSessionStore_1.liveSessionStore.add(Object.assign(Object.assign({}, s), { claudeSessionId, status: 'idle', prUrl, orgId }));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
+
const nextUpgrade = (_g = (_f = app).getUpgradeHandler) === null || _g === void 0 ? void 0 : _g.call(_f);
|
|
144
|
+
const server = (0, http_1.createServer)((req, res) => {
|
|
145
|
+
if (!(0, requestGuard_1.isAllowedRequest)(req.headers)) {
|
|
146
|
+
res.writeHead(403).end('Forbidden');
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const parsedUrl = (0, url_1.parse)(req.url, true);
|
|
150
|
+
handle(req, res, parsedUrl);
|
|
151
|
+
});
|
|
152
|
+
const wss = new ws_1.WebSocketServer({ noServer: true });
|
|
153
|
+
// Meeting events go to every connected client — a meeting isn't "attached"
|
|
154
|
+
// like a terminal session; any open tab shows its state.
|
|
155
|
+
pipelines_1.pipelineEngine.start();
|
|
156
|
+
slackWatchers_1.slackWatchers.start();
|
|
157
|
+
keepAwake_1.keepAwake.start();
|
|
158
|
+
slackWatchers_1.slackWatchers.on((ev) => {
|
|
159
|
+
const msg = JSON.stringify(ev);
|
|
160
|
+
wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
|
|
161
|
+
c.send(msg); });
|
|
162
|
+
});
|
|
163
|
+
(0, ptyManager_1.onAnyStatusChange)((id, status) => { if (status === 'waiting')
|
|
164
|
+
flushRename(id); });
|
|
165
|
+
pipelines_1.pipelineEngine.on((ev) => {
|
|
166
|
+
const msg = JSON.stringify(ev);
|
|
167
|
+
wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
|
|
168
|
+
c.send(msg); });
|
|
169
|
+
});
|
|
170
|
+
meetingManager_1.meetingManager.on((ev) => {
|
|
171
|
+
const msg = JSON.stringify(ev);
|
|
172
|
+
wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
|
|
173
|
+
c.send(msg); });
|
|
174
|
+
});
|
|
175
|
+
server.on('upgrade', (request, socket, head) => {
|
|
176
|
+
if (!(0, requestGuard_1.isAllowedRequest)(request.headers)) {
|
|
177
|
+
socket.destroy();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const { pathname } = (0, url_1.parse)(request.url, true);
|
|
181
|
+
if (pathname === '/ws') {
|
|
182
|
+
wss.handleUpgrade(request, socket, head, (client) => {
|
|
183
|
+
wss.emit('connection', client, request);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else if (nextUpgrade) {
|
|
187
|
+
nextUpgrade(request, socket, head);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
socket.destroy();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
wss.on('connection', (ws) => {
|
|
194
|
+
let currentSessionId = null;
|
|
195
|
+
let cleanupOutput = null;
|
|
196
|
+
let cleanupStatus = null;
|
|
197
|
+
function send(msg) {
|
|
198
|
+
if (ws.readyState === ws_1.WebSocket.OPEN)
|
|
199
|
+
ws.send(JSON.stringify(msg));
|
|
200
|
+
}
|
|
201
|
+
// Lets the client track every session's status (not just the attached
|
|
202
|
+
// one), so background-session completion can be surfaced in the sidebar
|
|
203
|
+
// and trigger alerts/notifications regardless of what's currently open.
|
|
204
|
+
send({ type: 'pipelines', items: pipelines_1.pipelineEngine.list() });
|
|
205
|
+
send({ type: 'slack-watchers', items: slackWatchers_1.slackWatchers.list() });
|
|
206
|
+
const cleanupAnyStatus = (0, ptyManager_1.onAnyStatusChange)((id, status) => send({ type: 'sessionStatus', id, status }));
|
|
207
|
+
const cleanupAnyPrUrl = (0, ptyManager_1.onAnyPrUrlChange)((id, prUrl) => send({ type: 'sessionPrUrl', id, prUrl }));
|
|
208
|
+
const cleanupAnyRcUrl = (0, ptyManager_1.onAnyRcUrlChange)((id, rcUrl) => send({ type: 'sessionRcUrl', id, rcUrl }));
|
|
209
|
+
function attachToSession(sessionId) {
|
|
210
|
+
cleanupOutput === null || cleanupOutput === void 0 ? void 0 : cleanupOutput();
|
|
211
|
+
cleanupStatus === null || cleanupStatus === void 0 ? void 0 : cleanupStatus();
|
|
212
|
+
currentSessionId = sessionId;
|
|
213
|
+
// Bring this session's PTY/headless-buffer size in line with the
|
|
214
|
+
// client's actual viewport before snapshotting its screen state.
|
|
215
|
+
const { cols, rows } = (0, ptyManager_1.getLastKnownSize)();
|
|
216
|
+
(0, ptyManager_1.resizeSession)(sessionId, cols, rows);
|
|
217
|
+
send({ type: 'clear' });
|
|
218
|
+
const snapshot = (0, ptyManager_1.getSerializedScreen)(sessionId);
|
|
219
|
+
if (snapshot)
|
|
220
|
+
send({ type: 'output', data: snapshot });
|
|
221
|
+
const session = liveSessionStore_1.liveSessionStore.get(sessionId);
|
|
222
|
+
if (session)
|
|
223
|
+
send({ type: 'status', status: session.status });
|
|
224
|
+
cleanupOutput = (0, ptyManager_1.onOutput)(sessionId, (data) => send({ type: 'output', data }));
|
|
225
|
+
cleanupStatus = (0, ptyManager_1.onStatusChange)(sessionId, (status) => send({ type: 'status', status }));
|
|
226
|
+
}
|
|
227
|
+
ws.on('message', (raw) => {
|
|
228
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
229
|
+
let msg;
|
|
230
|
+
try {
|
|
231
|
+
msg = JSON.parse(raw.toString());
|
|
232
|
+
}
|
|
233
|
+
catch (_z) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (msg.type === 'list') {
|
|
237
|
+
send({ type: 'sessions', sessions: liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); }) });
|
|
238
|
+
}
|
|
239
|
+
else if (msg.type === 'create') {
|
|
240
|
+
let cwd = msg.cwd || process.env.HOME;
|
|
241
|
+
if (cwd === 'general') {
|
|
242
|
+
cwd = path_1.default.join(process.env.HOME, 'General', (0, uuid_1.v4)().slice(0, 8));
|
|
243
|
+
(0, fs_1.mkdirSync)(cwd, { recursive: true });
|
|
244
|
+
}
|
|
245
|
+
if (!(0, fs_1.existsSync)(cwd) || !(0, fs_1.statSync)(cwd).isDirectory()) {
|
|
246
|
+
send({ type: 'error', message: `Directory not found: ${cwd}` });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const orgId = msg.orgId || orgRegistry_1.DEFAULT_ORG_ID;
|
|
250
|
+
const org = orgRegistry_1.orgRegistry.get(orgId);
|
|
251
|
+
const id = (0, uuid_1.v4)();
|
|
252
|
+
const gitRoot = (0, gitUtils_1.getGitRoot)(cwd);
|
|
253
|
+
// Name shown for this session in the Claude mobile app / claude.ai
|
|
254
|
+
// Remote Control list — the dialog's name if given, else the folder.
|
|
255
|
+
const rcName = msg.name || path_1.default.basename(cwd);
|
|
256
|
+
// Backend + model chosen in the dialog; model falls back to the org
|
|
257
|
+
// default (or the app default inside spawnSession if that's null too).
|
|
258
|
+
const backend = msg.backend || backends_1.DEFAULT_BACKEND;
|
|
259
|
+
const model = msg.model || (org === null || org === void 0 ? void 0 : org.model) || null;
|
|
260
|
+
const rc = !!msg.rc;
|
|
261
|
+
liveSessionStore_1.liveSessionStore.add({ id, cwd, gitRoot, claudeSessionId: null, status: 'thinking', createdAt: Date.now(), prUrl: null, orgId, backend, model, rc });
|
|
262
|
+
(0, ptyManager_1.spawnSession)(id, cwd, undefined, (_a = org === null || org === void 0 ? void 0 : org.configDir) !== null && _a !== void 0 ? _a : null, model, rcName, backend, rc);
|
|
263
|
+
send({ type: 'created', id, cwd, gitRoot, orgId });
|
|
264
|
+
attachToSession(id);
|
|
265
|
+
// First prompt (e.g. "cr <url>", "/mcp"): sent only once Claude is at its input prompt
|
|
266
|
+
if (typeof msg.prompt === 'string' && msg.prompt.trim())
|
|
267
|
+
(0, ptyManager_1.sendWhenReady)(id, msg.prompt.slice(0, 20000));
|
|
268
|
+
}
|
|
269
|
+
else if (msg.type === 'resume') {
|
|
270
|
+
let cwd = msg.cwd || process.env.HOME;
|
|
271
|
+
if (cwd === 'general') {
|
|
272
|
+
cwd = path_1.default.join(process.env.HOME, 'General', (0, uuid_1.v4)().slice(0, 8));
|
|
273
|
+
(0, fs_1.mkdirSync)(cwd, { recursive: true });
|
|
274
|
+
}
|
|
275
|
+
const rawSessionId = msg.claudeSessionId;
|
|
276
|
+
if (!/^[a-f0-9-]{36}$/i.test(rawSessionId))
|
|
277
|
+
return;
|
|
278
|
+
// If already live and running, just attach — don't spawn a second PTY
|
|
279
|
+
const existing = liveSessionStore_1.liveSessionStore.list().find(s => s.claudeSessionId === rawSessionId);
|
|
280
|
+
if (existing) {
|
|
281
|
+
// Resuming a RUNNING session with a different model = "move it to that
|
|
282
|
+
// model": kill the PTY and fall through to the re-spawn below.
|
|
283
|
+
const wantModel = msg.model || null;
|
|
284
|
+
if (existing.status !== 'idle' && wantModel && wantModel !== existing.model) {
|
|
285
|
+
(0, ptyManager_1.killSession)(existing.id);
|
|
286
|
+
liveSessionStore_1.liveSessionStore.setStatus(existing.id, 'idle');
|
|
287
|
+
}
|
|
288
|
+
if (((_b = liveSessionStore_1.liveSessionStore.get(existing.id)) === null || _b === void 0 ? void 0 : _b.status) === 'idle') {
|
|
289
|
+
// PTY exited — re-spawn it on the same store entry. Always uses the
|
|
290
|
+
// session's OWN stored org, never whatever orgId the client sent —
|
|
291
|
+
// a resume must never silently move a session to a different org.
|
|
292
|
+
const org = orgRegistry_1.orgRegistry.get(existing.orgId);
|
|
293
|
+
liveSessionStore_1.liveSessionStore.setStatus(existing.id, 'thinking');
|
|
294
|
+
// Re-spawn on the session's OWN persisted backend/model, not the
|
|
295
|
+
// client-sent backend. A client-sent model DOES win, so "Resume by ID"
|
|
296
|
+
// with a different model picked moves the session to that model
|
|
297
|
+
// (persisted, so later resumes stay on it).
|
|
298
|
+
const model = msg.model || existing.model || (org === null || org === void 0 ? void 0 : org.model) || null;
|
|
299
|
+
if (model !== existing.model) {
|
|
300
|
+
existing.model = model;
|
|
301
|
+
liveSessionStore_1.liveSessionStore.add(existing);
|
|
302
|
+
}
|
|
303
|
+
(0, ptyManager_1.spawnSession)(existing.id, existing.cwd, rawSessionId, (_c = org === null || org === void 0 ? void 0 : org.configDir) !== null && _c !== void 0 ? _c : null, model, rcNameFor(existing, msg.name), existing.backend, existing.rc);
|
|
304
|
+
}
|
|
305
|
+
send({ type: 'attached', id: existing.id, cwd: existing.cwd });
|
|
306
|
+
attachToSession(existing.id);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const orgId = msg.orgId || orgRegistry_1.DEFAULT_ORG_ID;
|
|
310
|
+
const org = orgRegistry_1.orgRegistry.get(orgId);
|
|
311
|
+
const id = (0, uuid_1.v4)();
|
|
312
|
+
const gitRoot = (0, gitUtils_1.getGitRoot)(cwd);
|
|
313
|
+
const rcName = msg.name || path_1.default.basename(cwd);
|
|
314
|
+
const backend = msg.backend || backends_1.DEFAULT_BACKEND;
|
|
315
|
+
const model = msg.model || (org === null || org === void 0 ? void 0 : org.model) || null;
|
|
316
|
+
liveSessionStore_1.liveSessionStore.add({ id, cwd, gitRoot, claudeSessionId: rawSessionId, status: 'thinking', createdAt: Date.now(), prUrl: null, orgId, backend, model, rc: !!msg.rc });
|
|
317
|
+
(0, ptyManager_1.spawnSession)(id, cwd, rawSessionId, (_d = org === null || org === void 0 ? void 0 : org.configDir) !== null && _d !== void 0 ? _d : null, model, rcNameFor({ id, cwd, claudeSessionId: rawSessionId, orgId }, msg.name), backend, !!msg.rc);
|
|
318
|
+
send({ type: 'created', id, cwd, gitRoot, claudeSessionId: rawSessionId, orgId });
|
|
319
|
+
attachToSession(id);
|
|
320
|
+
}
|
|
321
|
+
else if (msg.type === 'resume-all') {
|
|
322
|
+
// Staggered so resuming dozens of sessions doesn't recreate the
|
|
323
|
+
// restart-storm this replaces; clients get one list update at the end.
|
|
324
|
+
;
|
|
325
|
+
(async () => {
|
|
326
|
+
var _a, _b, _c;
|
|
327
|
+
const idle = liveSessionStore_1.liveSessionStore.list().filter(s => s.status === 'idle' && s.claudeSessionId);
|
|
328
|
+
for (const s of idle) {
|
|
329
|
+
if (((_a = liveSessionStore_1.liveSessionStore.get(s.id)) === null || _a === void 0 ? void 0 : _a.status) !== 'idle')
|
|
330
|
+
continue; // resumed via click meanwhile
|
|
331
|
+
const org = orgRegistry_1.orgRegistry.get(s.orgId);
|
|
332
|
+
liveSessionStore_1.liveSessionStore.setStatus(s.id, 'thinking');
|
|
333
|
+
(0, ptyManager_1.spawnSession)(s.id, s.cwd, s.claudeSessionId, (_b = org === null || org === void 0 ? void 0 : org.configDir) !== null && _b !== void 0 ? _b : null, (_c = s.model) !== null && _c !== void 0 ? _c : org === null || org === void 0 ? void 0 : org.model, rcNameFor(s), s.backend, s.rc);
|
|
334
|
+
await new Promise(r => setTimeout(r, 300));
|
|
335
|
+
}
|
|
336
|
+
const updated = liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); });
|
|
337
|
+
wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
|
|
338
|
+
c.send(JSON.stringify({ type: 'sessions', sessions: updated })); });
|
|
339
|
+
})();
|
|
340
|
+
}
|
|
341
|
+
else if (msg.type === 'attach') {
|
|
342
|
+
const sessionId = msg.sessionId;
|
|
343
|
+
if (liveSessionStore_1.liveSessionStore.get(sessionId))
|
|
344
|
+
attachToSession(sessionId);
|
|
345
|
+
}
|
|
346
|
+
else if (msg.type === 'restart') {
|
|
347
|
+
// Re-spawn a session's pty in place (same store entry, same model) —
|
|
348
|
+
// e.g. to pick up flags like --remote-control after a config change.
|
|
349
|
+
const target = liveSessionStore_1.liveSessionStore.get(msg.sessionId);
|
|
350
|
+
if (target === null || target === void 0 ? void 0 : target.claudeSessionId) {
|
|
351
|
+
(0, ptyManager_1.killSession)(target.id);
|
|
352
|
+
const org = orgRegistry_1.orgRegistry.get(target.orgId);
|
|
353
|
+
liveSessionStore_1.liveSessionStore.setStatus(target.id, 'thinking');
|
|
354
|
+
(0, ptyManager_1.spawnSession)(target.id, target.cwd, target.claudeSessionId, (_e = org === null || org === void 0 ? void 0 : org.configDir) !== null && _e !== void 0 ? _e : null, (_f = target.model) !== null && _f !== void 0 ? _f : org === null || org === void 0 ? void 0 : org.model, rcNameFor(target), target.backend, target.rc);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if (msg.type === 'set-rc') {
|
|
358
|
+
// Toggle Remote Control for one session. Persisted; a running session
|
|
359
|
+
// is re-spawned in place so the flag takes effect now.
|
|
360
|
+
const target = liveSessionStore_1.liveSessionStore.get(msg.sessionId);
|
|
361
|
+
if (target) {
|
|
362
|
+
target.rc = !!msg.on;
|
|
363
|
+
liveSessionStore_1.liveSessionStore.add(target);
|
|
364
|
+
if (target.status !== 'idle' && target.claudeSessionId) {
|
|
365
|
+
(0, ptyManager_1.killSession)(target.id);
|
|
366
|
+
const org = orgRegistry_1.orgRegistry.get(target.orgId);
|
|
367
|
+
liveSessionStore_1.liveSessionStore.setStatus(target.id, 'thinking');
|
|
368
|
+
(0, ptyManager_1.spawnSession)(target.id, target.cwd, target.claudeSessionId, (_g = org === null || org === void 0 ? void 0 : org.configDir) !== null && _g !== void 0 ? _g : null, (_h = target.model) !== null && _h !== void 0 ? _h : org === null || org === void 0 ? void 0 : org.model, rcNameFor(target), target.backend, target.rc);
|
|
369
|
+
}
|
|
370
|
+
const updated = liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); });
|
|
371
|
+
wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
|
|
372
|
+
c.send(JSON.stringify({ type: 'sessions', sessions: updated })); });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else if (msg.type === 'stop') {
|
|
376
|
+
// Stop the pty but keep the card (idle, resumable) — unlike 'kill' (archive).
|
|
377
|
+
const target = liveSessionStore_1.liveSessionStore.get(msg.sessionId);
|
|
378
|
+
if (target) {
|
|
379
|
+
(0, ptyManager_1.killSession)(target.id);
|
|
380
|
+
liveSessionStore_1.liveSessionStore.setRcUrl(target.id, null);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
else if (msg.type === 'compact') {
|
|
384
|
+
// One-click /compact for any session card (not just the attached one).
|
|
385
|
+
const target = msg.sessionId;
|
|
386
|
+
if (liveSessionStore_1.liveSessionStore.get(target))
|
|
387
|
+
(0, ptyManager_1.writeToSession)(target, '/compact\r');
|
|
388
|
+
}
|
|
389
|
+
else if (msg.type === 'kill') {
|
|
390
|
+
const targetId = msg.sessionId;
|
|
391
|
+
(0, ptyManager_1.killSession)(targetId);
|
|
392
|
+
liveSessionStore_1.liveSessionStore.remove(targetId);
|
|
393
|
+
const updated = liveSessionStore_1.liveSessionStore.list().map(s => { var _a; return ({ id: s.id, cwd: s.cwd, gitRoot: s.gitRoot, status: s.status, claudeSessionId: s.claudeSessionId, createdAt: s.createdAt, prUrl: s.prUrl, rcUrl: (_a = s.rcUrl) !== null && _a !== void 0 ? _a : null, rc: !!s.rc, orgId: s.orgId }); });
|
|
394
|
+
wss.clients.forEach(c => { if (c.readyState === ws_1.WebSocket.OPEN)
|
|
395
|
+
c.send(JSON.stringify({ type: 'sessions', sessions: updated })); });
|
|
396
|
+
}
|
|
397
|
+
else if (msg.type === 'paste-image') {
|
|
398
|
+
if (!currentSessionId)
|
|
399
|
+
return;
|
|
400
|
+
const base64 = msg.data;
|
|
401
|
+
const mimeType = msg.mimeType || 'image/png';
|
|
402
|
+
const ext = mimeType.split('/')[1].replace('jpeg', 'jpg').split('+')[0];
|
|
403
|
+
const tmpPath = path_1.default.join(os_1.default.tmpdir(), `claude-paste-${(0, uuid_1.v4)().slice(0, 8)}.${ext}`);
|
|
404
|
+
(0, fs_1.writeFileSync)(tmpPath, Buffer.from(base64, 'base64'));
|
|
405
|
+
(0, ptyManager_1.writeToSession)(currentSessionId, tmpPath);
|
|
406
|
+
send({ type: 'image-pasted', path: tmpPath });
|
|
407
|
+
}
|
|
408
|
+
else if (msg.type === 'meeting-start') {
|
|
409
|
+
const result = meetingManager_1.meetingManager.start((_j = msg.title) !== null && _j !== void 0 ? _j : '', (_k = msg.orgId) !== null && _k !== void 0 ? _k : orgRegistry_1.DEFAULT_ORG_ID);
|
|
410
|
+
if ('error' in result)
|
|
411
|
+
send({ type: 'meeting-error', meetingId: null, message: result.error });
|
|
412
|
+
else
|
|
413
|
+
send({ type: 'meeting-started', meeting: result });
|
|
414
|
+
}
|
|
415
|
+
else if (msg.type === 'rename-live') {
|
|
416
|
+
// Rename the running Claude conversation too, so Remote Control and
|
|
417
|
+
// claude.ai show the title. Sent now if the prompt is idle, else on next idle.
|
|
418
|
+
const name = String((_l = msg.name) !== null && _l !== void 0 ? _l : '').replace(/[\x00-\x1f\x7f]/g, ' ').trim().slice(0, 80);
|
|
419
|
+
const target = liveSessionStore_1.liveSessionStore.get(msg.id);
|
|
420
|
+
if (name && target && target.backend !== 'copilot') {
|
|
421
|
+
pendingRenames.set(target.id, name);
|
|
422
|
+
if (target.status === 'waiting')
|
|
423
|
+
flushRename(target.id);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
else if (msg.type === 'pipeline-start') {
|
|
427
|
+
const cfg = ((_m = msg.config) !== null && _m !== void 0 ? _m : {});
|
|
428
|
+
const ch = ((_o = cfg.slackChannel) === null || _o === void 0 ? void 0 : _o.name) ? { id: String((_p = cfg.slackChannel.id) !== null && _p !== void 0 ? _p : '').replace(/[^A-Z0-9]/gi, ''), name: cfg.slackChannel.name.replace(/^#/, '').slice(0, 80) } : null;
|
|
429
|
+
const result = pipelines_1.pipelineEngine.create(msg.liveId, { slackChannel: ch, maxRounds: Number(cfg.maxRounds) || 3 });
|
|
430
|
+
if ('error' in result)
|
|
431
|
+
send({ type: 'pipeline-error', liveId: msg.liveId, message: result.error });
|
|
432
|
+
}
|
|
433
|
+
else if (msg.type === 'pipeline-add-pr') {
|
|
434
|
+
const err = pipelines_1.pipelineEngine.addPr(msg.id, String((_q = msg.url) !== null && _q !== void 0 ? _q : '').trim());
|
|
435
|
+
if (err)
|
|
436
|
+
send({ type: 'pipeline-error', liveId: msg.liveId, message: err.error });
|
|
437
|
+
}
|
|
438
|
+
else if (msg.type === 'watcher-create') {
|
|
439
|
+
const c = ((_r = msg.channel) !== null && _r !== void 0 ? _r : {});
|
|
440
|
+
const result = slackWatchers_1.slackWatchers.create({
|
|
441
|
+
channel: { id: String((_s = c.id) !== null && _s !== void 0 ? _s : '').replace(/[^A-Z0-9]/gi, ''), name: String((_t = c.name) !== null && _t !== void 0 ? _t : '').replace(/^#/, '').slice(0, 80) },
|
|
442
|
+
liveId: msg.liveId || null, mode: msg.mode === 'auto' ? 'auto' : 'approve', intervalMin: Number(msg.intervalMin) || 5,
|
|
443
|
+
orgId: typeof msg.orgId === 'string' && orgRegistry_1.orgRegistry.get(msg.orgId) ? msg.orgId : orgRegistry_1.DEFAULT_ORG_ID,
|
|
444
|
+
knowledge: typeof msg.knowledge === 'string' ? msg.knowledge : '', instructions: typeof msg.instructions === 'string' ? msg.instructions : '',
|
|
445
|
+
});
|
|
446
|
+
if ('error' in result)
|
|
447
|
+
send({ type: 'watcher-error', message: result.error });
|
|
448
|
+
else
|
|
449
|
+
slackWatchers_1.slackWatchers.run(result.id);
|
|
450
|
+
}
|
|
451
|
+
else if (msg.type === 'watcher-stop') {
|
|
452
|
+
slackWatchers_1.slackWatchers.stop(msg.id);
|
|
453
|
+
}
|
|
454
|
+
else if (msg.type === 'watcher-update') {
|
|
455
|
+
const err = slackWatchers_1.slackWatchers.update(msg.id, ((_u = msg.patch) !== null && _u !== void 0 ? _u : {}));
|
|
456
|
+
if (err)
|
|
457
|
+
send({ type: 'watcher-error', message: err.error });
|
|
458
|
+
}
|
|
459
|
+
else if (msg.type === 'watcher-set-session') {
|
|
460
|
+
slackWatchers_1.slackWatchers.setSession(msg.id, msg.liveId || null);
|
|
461
|
+
}
|
|
462
|
+
else if (msg.type === 'watcher-run') {
|
|
463
|
+
slackWatchers_1.slackWatchers.run(msg.id);
|
|
464
|
+
}
|
|
465
|
+
else if (msg.type === 'watcher-send') {
|
|
466
|
+
slackWatchers_1.slackWatchers.send(msg.id, msg.permalink, String((_v = msg.text) !== null && _v !== void 0 ? _v : '')).then(err => { if (err)
|
|
467
|
+
send({ type: 'watcher-error', message: err.error }); });
|
|
468
|
+
}
|
|
469
|
+
else if (msg.type === 'watcher-dismiss') {
|
|
470
|
+
slackWatchers_1.slackWatchers.dismiss(msg.id, msg.permalink);
|
|
471
|
+
}
|
|
472
|
+
else if (msg.type === 'watcher-redraft') {
|
|
473
|
+
slackWatchers_1.slackWatchers.redraft(msg.id, msg.permalink);
|
|
474
|
+
}
|
|
475
|
+
else if (msg.type === 'pipeline-act') {
|
|
476
|
+
// The one place an automation's message reaches a session: your click
|
|
477
|
+
const err = pipelines_1.pipelineEngine.act(msg.id, msg.prUrl || null);
|
|
478
|
+
if (err)
|
|
479
|
+
send({ type: 'pipeline-error', liveId: msg.liveId, message: err.error });
|
|
480
|
+
}
|
|
481
|
+
else if (msg.type === 'pipeline-auto') {
|
|
482
|
+
pipelines_1.pipelineEngine.setAuto(msg.id, ((_w = msg.auto) !== null && _w !== void 0 ? _w : {}));
|
|
483
|
+
}
|
|
484
|
+
else if (msg.type === 'pipeline-dismiss') {
|
|
485
|
+
pipelines_1.pipelineEngine.dismiss(msg.id, msg.prUrl || null);
|
|
486
|
+
}
|
|
487
|
+
else if (msg.type === 'pipeline-stop') {
|
|
488
|
+
pipelines_1.pipelineEngine.stop(msg.id);
|
|
489
|
+
}
|
|
490
|
+
else if (msg.type === 'meeting-resume') {
|
|
491
|
+
const result = meetingManager_1.meetingManager.resume(msg.meetingId);
|
|
492
|
+
if ('error' in result)
|
|
493
|
+
send({ type: 'meeting-error', meetingId: (_x = msg.meetingId) !== null && _x !== void 0 ? _x : null, message: result.error });
|
|
494
|
+
else
|
|
495
|
+
send({ type: 'meeting-started', meeting: result });
|
|
496
|
+
}
|
|
497
|
+
else if (msg.type === 'meeting-stop') {
|
|
498
|
+
// stop() emits a 'meeting-status' (ended) itself, but if it throws
|
|
499
|
+
// before that (e.g. ffmpeg teardown rejects) the UI would be stuck
|
|
500
|
+
// showing "recording" forever — surface the failure so it isn't silent.
|
|
501
|
+
meetingManager_1.meetingManager.stop(msg.meetingId).catch(err => {
|
|
502
|
+
send({ type: 'meeting-error', meetingId: msg.meetingId, message: `Failed to stop meeting: ${err instanceof Error ? err.message : 'unknown'}` });
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
else if (msg.type === 'meeting-ask') {
|
|
506
|
+
meetingManager_1.meetingManager.ask(msg.meetingId, msg.question);
|
|
507
|
+
}
|
|
508
|
+
else if (msg.type === 'meeting-add-context') {
|
|
509
|
+
const kinds = ['text', 'link', 'slack', 'session', 'meeting'];
|
|
510
|
+
if (typeof msg.meetingId === 'string' && kinds.includes(msg.kind) && typeof msg.value === 'string' && msg.value.trim() && msg.value.length <= 500000) {
|
|
511
|
+
meetingManager_1.meetingManager.addContext(msg.meetingId, msg.kind, msg.value);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
else if (msg.type === 'meeting-mic-test') {
|
|
515
|
+
meetingManager_1.meetingManager.micTest().then(result => send(Object.assign({ type: 'meeting-mic-test-result' }, result)));
|
|
516
|
+
}
|
|
517
|
+
else if (msg.type === 'send-to-live') {
|
|
518
|
+
// User clicked "Ask session" on a Slack card: queue the text for when the session is idle
|
|
519
|
+
const text = String((_y = msg.text) !== null && _y !== void 0 ? _y : '').replace(/[\x00-\x08\x0b-\x1f\x7f]/g, ' ').trim().slice(0, 20000);
|
|
520
|
+
if (text && liveSessionStore_1.liveSessionStore.get(msg.id))
|
|
521
|
+
(0, ptyManager_1.sendWhenReady)(msg.id, text);
|
|
522
|
+
}
|
|
523
|
+
else if (msg.type === 'input') {
|
|
524
|
+
if (currentSessionId)
|
|
525
|
+
(0, ptyManager_1.writeToSession)(currentSessionId, msg.data);
|
|
526
|
+
}
|
|
527
|
+
else if (msg.type === 'resize') {
|
|
528
|
+
if (currentSessionId)
|
|
529
|
+
(0, ptyManager_1.resizeSession)(currentSessionId, msg.cols, msg.rows);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
ws.on('close', () => {
|
|
533
|
+
cleanupOutput === null || cleanupOutput === void 0 ? void 0 : cleanupOutput();
|
|
534
|
+
cleanupStatus === null || cleanupStatus === void 0 ? void 0 : cleanupStatus();
|
|
535
|
+
cleanupAnyStatus();
|
|
536
|
+
cleanupAnyPrUrl();
|
|
537
|
+
cleanupAnyRcUrl();
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
server.listen(PORT, '127.0.0.1', () => {
|
|
541
|
+
const appUrl = `http://polyergon.localhost:${PORT}`;
|
|
542
|
+
if (process.env.POLYERGON_OPEN === '1') {
|
|
543
|
+
// Own window (no tabs or address bar) when Chrome is installed; POLYERGON_WINDOW=browser opens a normal tab
|
|
544
|
+
Promise.resolve().then(() => __importStar(require('child_process'))).then(cp => {
|
|
545
|
+
const chrome = '/Applications/Google Chrome.app';
|
|
546
|
+
const [cmd, args] = process.platform !== 'darwin' ? ['xdg-open', [appUrl]]
|
|
547
|
+
: process.env.POLYERGON_WINDOW !== 'browser' && (0, fs_1.existsSync)(chrome) ? ['open', ['-na', chrome, '--args', `--app=${appUrl}`]]
|
|
548
|
+
: ['open', [appUrl]];
|
|
549
|
+
cp.spawn(cmd, args, { stdio: 'ignore', detached: true }).on('error', () => { }).unref();
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
console.log(`> Polyergon ready on ${appUrl}`);
|
|
553
|
+
});
|
|
554
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setActiveOrg = setActiveOrg;
|
|
4
|
+
exports.withOrg = withOrg;
|
|
5
|
+
// Browser-side: the org selected in the switcher, so Slack/skills calls run
|
|
6
|
+
// against that org's Claude setup. 'all' → Default.
|
|
7
|
+
let current = 'default';
|
|
8
|
+
function setActiveOrg(id) { current = id === 'all' ? 'default' : id; }
|
|
9
|
+
function withOrg(url) {
|
|
10
|
+
return `${url}${url.includes('?') ? '&' : '?'}org=${encodeURIComponent(current)}`;
|
|
11
|
+
}
|