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,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
+
};
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
var _a;
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.prUrlCache = exports.PrUrlCache = void 0;
|
|
15
|
+
const dataDir_1 = require("./dataDir");
|
|
16
|
+
const fs_1 = require("fs");
|
|
17
|
+
const fs_2 = require("fs");
|
|
18
|
+
const readline_1 = require("readline");
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const prDetector_1 = require("./prDetector");
|
|
21
|
+
const DEFAULT_PROJECTS_DIR = path_1.default.join(process.env.HOME, '.claude', 'projects');
|
|
22
|
+
const DEFAULT_CACHE_FILE = path_1.default.join(dataDir_1.DATA_DIR, 'pr-url-cache.json');
|
|
23
|
+
// Persisted, mtime/size-invalidated cache of session -> PR URL. A PR URL from
|
|
24
|
+
// `gh pr create` typically appears well past the small header most other
|
|
25
|
+
// session metadata reads scan, so this does a full read — but only for files
|
|
26
|
+
// that changed since the last scan, never re-reading unchanged ones.
|
|
27
|
+
class PrUrlCache {
|
|
28
|
+
// Both paths default to the real on-disk locations; tests must pass
|
|
29
|
+
// isolated paths so they never touch the user's actual session state.
|
|
30
|
+
constructor(cacheFile = DEFAULT_CACHE_FILE, projectsDir = DEFAULT_PROJECTS_DIR) {
|
|
31
|
+
this.cache = new Map();
|
|
32
|
+
this.loaded = false;
|
|
33
|
+
this.cacheFile = cacheFile;
|
|
34
|
+
this.cacheDir = path_1.default.join(cacheFile, '..');
|
|
35
|
+
this.projectsDir = projectsDir;
|
|
36
|
+
}
|
|
37
|
+
async load() {
|
|
38
|
+
if (this.loaded)
|
|
39
|
+
return;
|
|
40
|
+
this.loaded = true;
|
|
41
|
+
try {
|
|
42
|
+
const raw = await fs_1.promises.readFile(this.cacheFile, 'utf-8');
|
|
43
|
+
const parsed = JSON.parse(raw);
|
|
44
|
+
this.cache = new Map(Object.entries(parsed));
|
|
45
|
+
}
|
|
46
|
+
catch ( /* no cache yet */_a) { /* no cache yet */ }
|
|
47
|
+
}
|
|
48
|
+
async persist() {
|
|
49
|
+
try {
|
|
50
|
+
await fs_1.promises.mkdir(this.cacheDir, { recursive: true });
|
|
51
|
+
await fs_1.promises.writeFile(this.cacheFile, JSON.stringify(Object.fromEntries(this.cache)));
|
|
52
|
+
}
|
|
53
|
+
catch ( /* best-effort */_a) { /* best-effort */ }
|
|
54
|
+
}
|
|
55
|
+
// Returns sessionId -> prUrl for every known session with a detected PR.
|
|
56
|
+
// Scans the given projects roots (defaults to the single constructor dir,
|
|
57
|
+
// which callers override with every org's root).
|
|
58
|
+
async scan(projectsDirs = [this.projectsDir]) {
|
|
59
|
+
var _a, e_1, _b, _c;
|
|
60
|
+
var _d;
|
|
61
|
+
await this.load();
|
|
62
|
+
const result = new Map();
|
|
63
|
+
let changed = false;
|
|
64
|
+
for (const dir of projectsDirs) {
|
|
65
|
+
let projectDirs;
|
|
66
|
+
try {
|
|
67
|
+
projectDirs = await fs_1.promises.readdir(dir);
|
|
68
|
+
}
|
|
69
|
+
catch (_e) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
for (const projectDir of projectDirs) {
|
|
73
|
+
const projectFullPath = path_1.default.join(dir, projectDir);
|
|
74
|
+
let dirStat;
|
|
75
|
+
try {
|
|
76
|
+
dirStat = await fs_1.promises.stat(projectFullPath);
|
|
77
|
+
}
|
|
78
|
+
catch (_f) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!dirStat.isDirectory())
|
|
82
|
+
continue;
|
|
83
|
+
let files;
|
|
84
|
+
try {
|
|
85
|
+
files = await fs_1.promises.readdir(projectFullPath);
|
|
86
|
+
}
|
|
87
|
+
catch (_g) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
for (const file of files) {
|
|
91
|
+
if (!file.endsWith('.jsonl'))
|
|
92
|
+
continue;
|
|
93
|
+
const sessionId = file.replace('.jsonl', '');
|
|
94
|
+
const filePath = path_1.default.join(projectFullPath, file);
|
|
95
|
+
let stat;
|
|
96
|
+
try {
|
|
97
|
+
stat = await fs_1.promises.stat(filePath);
|
|
98
|
+
}
|
|
99
|
+
catch (_h) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const cached = this.cache.get(sessionId);
|
|
103
|
+
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
104
|
+
if (cached.prUrl)
|
|
105
|
+
result.set(sessionId, cached.prUrl);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
// Stream line by line — extractPrUrl returns the LAST match, so
|
|
109
|
+
// carrying the latest per-line hit is equivalent to scanning the whole
|
|
110
|
+
// file, without loading a multi-hundred-MB transcript into memory.
|
|
111
|
+
let prUrl = null;
|
|
112
|
+
try {
|
|
113
|
+
const rl = (0, readline_1.createInterface)({ input: (0, fs_2.createReadStream)(filePath, { encoding: 'utf-8' }), crlfDelay: Infinity });
|
|
114
|
+
try {
|
|
115
|
+
for (var _j = true, rl_1 = (e_1 = void 0, __asyncValues(rl)), rl_1_1; rl_1_1 = await rl_1.next(), _a = rl_1_1.done, !_a; _j = true) {
|
|
116
|
+
_c = rl_1_1.value;
|
|
117
|
+
_j = false;
|
|
118
|
+
const line = _c;
|
|
119
|
+
prUrl = (_d = (0, prDetector_1.extractPrUrl)(line)) !== null && _d !== void 0 ? _d : prUrl;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
123
|
+
finally {
|
|
124
|
+
try {
|
|
125
|
+
if (!_j && !_a && (_b = rl_1.return)) await _b.call(rl_1);
|
|
126
|
+
}
|
|
127
|
+
finally { if (e_1) throw e_1.error; }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch ( /* unreadable, treat as no PR */_k) { /* unreadable, treat as no PR */ }
|
|
131
|
+
this.cache.set(sessionId, { prUrl, mtimeMs: stat.mtimeMs, size: stat.size });
|
|
132
|
+
changed = true;
|
|
133
|
+
if (prUrl)
|
|
134
|
+
result.set(sessionId, prUrl);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (changed)
|
|
139
|
+
await this.persist();
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.PrUrlCache = PrUrlCache;
|
|
144
|
+
exports.prUrlCache = (_a = global.__prUrlCache) !== null && _a !== void 0 ? _a : (global.__prUrlCache = new PrUrlCache());
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPrSessionEntries = buildPrSessionEntries;
|
|
4
|
+
exports.effectiveDate = effectiveDate;
|
|
5
|
+
exports.sortPrEntries = sortPrEntries;
|
|
6
|
+
exports.sortPrEntriesByDate = sortPrEntriesByDate;
|
|
7
|
+
const liveSessionStore_1 = require("./liveSessionStore");
|
|
8
|
+
const sessionStore_1 = require("./sessionStore");
|
|
9
|
+
const prScanCache_1 = require("./prScanCache");
|
|
10
|
+
const ghPrStatus_1 = require("./ghPrStatus");
|
|
11
|
+
const orgRegistry_1 = require("./orgRegistry");
|
|
12
|
+
// Assembles the full PR-linked session list: live sessions whose PR was
|
|
13
|
+
// detected from streaming output, plus history-only sessions whose PR was
|
|
14
|
+
// found via the lazy full-file cache scan — decorated with whatever status
|
|
15
|
+
// is already cached (no new `gh` calls here; that's refresh's job).
|
|
16
|
+
async function buildPrSessionEntries() {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const [historyUrls, historySessions] = await Promise.all([
|
|
19
|
+
prScanCache_1.prUrlCache.scan(orgRegistry_1.orgRegistry.projectRoots().map(r => r.root)),
|
|
20
|
+
(0, sessionStore_1.listAllSessions)(),
|
|
21
|
+
]);
|
|
22
|
+
const historyBySessionId = new Map(historySessions.map(s => [s.sessionId, s]));
|
|
23
|
+
const entries = [];
|
|
24
|
+
const seenSessionIds = new Set();
|
|
25
|
+
for (const s of liveSessionStore_1.liveSessionStore.list()) {
|
|
26
|
+
if (!s.prUrl)
|
|
27
|
+
continue;
|
|
28
|
+
entries.push({
|
|
29
|
+
source: 'live',
|
|
30
|
+
liveId: s.id,
|
|
31
|
+
sessionId: s.claudeSessionId,
|
|
32
|
+
orgId: (_a = s.orgId) !== null && _a !== void 0 ? _a : orgRegistry_1.DEFAULT_ORG_ID,
|
|
33
|
+
cwd: s.cwd,
|
|
34
|
+
gitRoot: s.gitRoot,
|
|
35
|
+
prUrl: s.prUrl,
|
|
36
|
+
status: (_b = ghPrStatus_1.prStatusCache.get(s.prUrl)) !== null && _b !== void 0 ? _b : null,
|
|
37
|
+
sessionDate: s.createdAt,
|
|
38
|
+
});
|
|
39
|
+
if (s.claudeSessionId)
|
|
40
|
+
seenSessionIds.add(s.claudeSessionId);
|
|
41
|
+
}
|
|
42
|
+
historyUrls.forEach((prUrl, sessionId) => {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
if (seenSessionIds.has(sessionId))
|
|
45
|
+
return; // already covered by a live entry
|
|
46
|
+
const match = historyBySessionId.get(sessionId);
|
|
47
|
+
const parsed = (match === null || match === void 0 ? void 0 : match.lastTimestamp) ? Date.parse(match.lastTimestamp) : NaN;
|
|
48
|
+
entries.push({
|
|
49
|
+
source: 'history',
|
|
50
|
+
liveId: null,
|
|
51
|
+
sessionId,
|
|
52
|
+
orgId: (_a = match === null || match === void 0 ? void 0 : match.orgId) !== null && _a !== void 0 ? _a : orgRegistry_1.DEFAULT_ORG_ID,
|
|
53
|
+
cwd: (_b = match === null || match === void 0 ? void 0 : match.cwd) !== null && _b !== void 0 ? _b : null,
|
|
54
|
+
gitRoot: (_c = match === null || match === void 0 ? void 0 : match.gitRoot) !== null && _c !== void 0 ? _c : null,
|
|
55
|
+
prUrl,
|
|
56
|
+
status: (_d = ghPrStatus_1.prStatusCache.get(prUrl)) !== null && _d !== void 0 ? _d : null,
|
|
57
|
+
sessionDate: Number.isNaN(parsed) ? 0 : parsed,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
return entries;
|
|
61
|
+
}
|
|
62
|
+
function isActionable(e) {
|
|
63
|
+
var _a;
|
|
64
|
+
return ((_a = e.status) === null || _a === void 0 ? void 0 : _a.state) === 'OPEN' && (e.status.reviewDecision === 'CHANGES_REQUESTED' || e.status.checks === 'failing');
|
|
65
|
+
}
|
|
66
|
+
function priority(e) {
|
|
67
|
+
if (isActionable(e))
|
|
68
|
+
return 0;
|
|
69
|
+
if (!e.status || e.status.state === 'OPEN')
|
|
70
|
+
return 1;
|
|
71
|
+
if (e.status.state === 'MERGED')
|
|
72
|
+
return 2;
|
|
73
|
+
return 3; // CLOSED
|
|
74
|
+
}
|
|
75
|
+
// The PR's own GitHub last-updated time once known (post-refresh); falls
|
|
76
|
+
// back to the session's own date so every entry always sorts/displays
|
|
77
|
+
// something meaningful even before a refresh has ever run.
|
|
78
|
+
function effectiveDate(e) {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
return (_b = (_a = e.status) === null || _a === void 0 ? void 0 : _a.updatedAt) !== null && _b !== void 0 ? _b : e.sessionDate;
|
|
81
|
+
}
|
|
82
|
+
// Actionable (changes requested / failing checks) first, then open-no-action
|
|
83
|
+
// (or status not yet known), then merged, then closed last; newest first
|
|
84
|
+
// within each tier.
|
|
85
|
+
function sortPrEntries(entries) {
|
|
86
|
+
return [...entries].sort((a, b) => {
|
|
87
|
+
const pa = priority(a), pb = priority(b);
|
|
88
|
+
if (pa !== pb)
|
|
89
|
+
return pa - pb;
|
|
90
|
+
return effectiveDate(b) - effectiveDate(a);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Pure newest-first, ignoring the actionable/state tiering entirely.
|
|
94
|
+
function sortPrEntriesByDate(entries) {
|
|
95
|
+
return [...entries].sort((a, b) => effectiveDate(b) - effectiveDate(a));
|
|
96
|
+
}
|
|
@@ -0,0 +1,437 @@
|
|
|
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
|
+
// Claude writes its transcript at once; other CLIs (OpenCode) only create the session on the
|
|
106
|
+
// first message, which may come minutes later
|
|
107
|
+
const [tries, every] = backend.id === 'claude' ? [60, 500] : [300, 2000];
|
|
108
|
+
for (let i = 0; i < tries; i++) {
|
|
109
|
+
await new Promise(r => setTimeout(r, every));
|
|
110
|
+
if (!ptyProcesses.has(id))
|
|
111
|
+
return;
|
|
112
|
+
// Claude's finder needs the configDir (which project dir to scan); other
|
|
113
|
+
// backends provide their own detectSessionId (e.g. Copilot's session store).
|
|
114
|
+
const uuid = backend.id === 'claude'
|
|
115
|
+
? findSessionIdSince(cwd, spawnTime, configDir)
|
|
116
|
+
: (_b = (_a = backend.detectSessionId) === null || _a === void 0 ? void 0 : _a.call(backend, cwd, spawnTime)) !== null && _b !== void 0 ? _b : null;
|
|
117
|
+
if (uuid) {
|
|
118
|
+
liveSessionStore_1.liveSessionStore.setClaudeSessionId(id, uuid);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const outputListeners = new Map();
|
|
124
|
+
const statusListeners = new Map();
|
|
125
|
+
// Unlike statusListeners (only populated for whichever session a connection
|
|
126
|
+
// has attached to), this fires for every session's status change regardless
|
|
127
|
+
// of attachment, so clients can track sessions they aren't currently viewing.
|
|
128
|
+
const anyStatusListeners = new Set();
|
|
129
|
+
const anyPrUrlListeners = new Set();
|
|
130
|
+
const anyRcUrlListeners = new Set();
|
|
131
|
+
const RC_URL_RE = /https:\/\/claude\.ai\/code\/session_[A-Za-z0-9]+/;
|
|
132
|
+
const ptyProcesses = new Map();
|
|
133
|
+
const thinkingTimers = new Map();
|
|
134
|
+
// Small rolling ANSI-stripped tail per session, scanned for a PR URL as
|
|
135
|
+
// output streams through — no extra file I/O beyond what's already flowing.
|
|
136
|
+
const prScanBuffers = new Map();
|
|
137
|
+
const PR_SCAN_BUFFER_MAX = 300;
|
|
138
|
+
// Headless terminal per session: mirrors the PTY's actual rendered screen state.
|
|
139
|
+
// Claude's CLI redraws in place via relative cursor movement rather than plain
|
|
140
|
+
// appended output, so reattach/status-detection must read the real current
|
|
141
|
+
// buffer instead of replaying or pattern-matching raw output chunks.
|
|
142
|
+
const headlessTerms = new Map();
|
|
143
|
+
let lastCols = 120;
|
|
144
|
+
let lastRows = 30;
|
|
145
|
+
// Returns the plain-text lines around the cursor's current row, for status
|
|
146
|
+
// detection against the terminal's true current state (not a transient chunk).
|
|
147
|
+
function emitStatus(id, status) {
|
|
148
|
+
var _a;
|
|
149
|
+
(_a = statusListeners.get(id)) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(status));
|
|
150
|
+
anyStatusListeners.forEach(fn => fn(id, status));
|
|
151
|
+
}
|
|
152
|
+
function emitRcUrl(id, rcUrl) {
|
|
153
|
+
anyRcUrlListeners.forEach(fn => fn(id, rcUrl));
|
|
154
|
+
}
|
|
155
|
+
function emitPrUrl(id, prUrl) {
|
|
156
|
+
anyPrUrlListeners.forEach(fn => fn(id, prUrl));
|
|
157
|
+
}
|
|
158
|
+
function bufferTail(term, maxLines = 8) {
|
|
159
|
+
const buf = term.buffer.active;
|
|
160
|
+
const cursorAbsY = buf.baseY + buf.cursorY;
|
|
161
|
+
const startY = Math.max(0, cursorAbsY - maxLines + 1);
|
|
162
|
+
const lines = [];
|
|
163
|
+
for (let y = startY; y <= cursorAbsY; y++) {
|
|
164
|
+
const line = buf.getLine(y);
|
|
165
|
+
if (line)
|
|
166
|
+
lines.push(line.translateToString(true));
|
|
167
|
+
}
|
|
168
|
+
return lines.join('\n');
|
|
169
|
+
}
|
|
170
|
+
// Last `n` rows of the visible screen (for TUIs whose status bar is at the bottom).
|
|
171
|
+
function bottomRows(term, n) {
|
|
172
|
+
const buf = term.buffer.active;
|
|
173
|
+
const lines = [];
|
|
174
|
+
for (let y = buf.viewportY + term.rows - n; y < buf.viewportY + term.rows; y++) {
|
|
175
|
+
const line = buf.getLine(y);
|
|
176
|
+
if (line)
|
|
177
|
+
lines.push(line.translateToString(true));
|
|
178
|
+
}
|
|
179
|
+
return lines.join('\n');
|
|
180
|
+
}
|
|
181
|
+
// The account has Fable 5.1 (API id `claude-fable-5-1`, with dashes). Two
|
|
182
|
+
// gotchas: the dotted form `claude-fable-5.1` is silently accepted but falls
|
|
183
|
+
// back to Opus 5, and CLI 2.1.241 doesn't yet recognize the dashed id — it
|
|
184
|
+
// rejects it unless CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1 is
|
|
185
|
+
// set on the process env (see spawn env below).
|
|
186
|
+
const DEFAULT_MODEL = 'claude-opus-5-5';
|
|
187
|
+
// The Claude mobile app / claude.ai lists each Remote Control session by the
|
|
188
|
+
// name passed to `--remote-control <name>`. Keep it a clean single token-ish
|
|
189
|
+
// label (spaces are fine — it's its own argv element — but strip control chars
|
|
190
|
+
// and cap the length so the phone list stays readable).
|
|
191
|
+
function sanitizeRcName(name) {
|
|
192
|
+
return name.replace(/[\x00-\x1f\x7f]/g, '').trim().slice(0, 60);
|
|
193
|
+
}
|
|
194
|
+
function spawnSession(id, cwd, resumeId, configDir, model, rcName, backendId, rc) {
|
|
195
|
+
const spawnTime = Date.now();
|
|
196
|
+
const cleanRcName = rcName ? sanitizeRcName(rcName) : '';
|
|
197
|
+
const backend = (0, backends_1.getBackend)(backendId);
|
|
198
|
+
const effectiveModel = model || DEFAULT_MODEL;
|
|
199
|
+
// The backend (Claude / Copilot / …) owns its own argv shape, binary, and
|
|
200
|
+
// any model-specific env. Remote Control naming etc. is Claude-specific and
|
|
201
|
+
// handled inside its spec. Remote Control is gated by the user's
|
|
202
|
+
// ~/.claude/settings.json CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC flag — we
|
|
203
|
+
// must NOT drop the user settings source to bypass it (it also carries all
|
|
204
|
+
// skills/plugins; doing so blanked every skill).
|
|
205
|
+
const args = backend.spawnArgs({ model: effectiveModel, cwd, resumeId, rcName: cleanRcName || undefined, rc: !!rc, skipPermissions: (0, settingsStore_1.getSettings)().sessions.skipPermissions });
|
|
206
|
+
const proc = pty.spawn(backend.bin, args, {
|
|
207
|
+
name: 'xterm-color',
|
|
208
|
+
cols: lastCols,
|
|
209
|
+
rows: lastRows,
|
|
210
|
+
cwd,
|
|
211
|
+
env: Object.assign(Object.assign(Object.assign(Object.assign({}, Object.fromEntries(['PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'TERM', 'LANG', 'LC_ALL', 'ANTHROPIC_API_KEY']
|
|
212
|
+
.filter(k => process.env[k])
|
|
213
|
+
.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 } : {})),
|
|
214
|
+
});
|
|
215
|
+
ptyProcesses.set(id, proc);
|
|
216
|
+
liveSessionStore_1.liveSessionStore.setRcUrl(id, null);
|
|
217
|
+
outputListeners.set(id, new Set());
|
|
218
|
+
statusListeners.set(id, new Set());
|
|
219
|
+
const headlessTerm = new headless_1.Terminal({ cols: lastCols, rows: lastRows, allowProposedApi: true, scrollback: 2000 });
|
|
220
|
+
const serializeAddon = new addon_serialize_1.SerializeAddon();
|
|
221
|
+
headlessTerm.loadAddon(serializeAddon);
|
|
222
|
+
headlessTerms.set(id, { term: headlessTerm, serialize: serializeAddon });
|
|
223
|
+
// For new sessions, detect the session file Claude creates and persist its ID
|
|
224
|
+
if (!resumeId)
|
|
225
|
+
detectAndStoreSessionId(id, cwd, spawnTime, configDir, backend);
|
|
226
|
+
// Auto-confirm the workspace/folder trust dialog both CLIs show for a new
|
|
227
|
+
// directory. Claude: "Yes, trust" is pre-selected, \r accepts it. Copilot:
|
|
228
|
+
// "Do you trust the files in this folder?" with option 1 (Yes) pre-selected
|
|
229
|
+
// and option 2 ("Yes, and remember…") below — we pick 2 (↓ then \r) so it
|
|
230
|
+
// won't ask again for that folder. The prompt can span multiple PTY chunks,
|
|
231
|
+
// so we match against a small rolling buffer, not a single chunk. Words are
|
|
232
|
+
// separated by cursor-forward ANSI codes, so match on ANSI-stripped text.
|
|
233
|
+
let trustConfirmed = false;
|
|
234
|
+
let trustScanBuf = '';
|
|
235
|
+
prScanBuffers.set(id, '');
|
|
236
|
+
proc.onData((data) => {
|
|
237
|
+
var _a, _b, _c, _d;
|
|
238
|
+
(_a = outputListeners.get(id)) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn(data));
|
|
239
|
+
const stripped = data.replace(ANSI_STRIP, '');
|
|
240
|
+
if (!trustConfirmed) {
|
|
241
|
+
trustScanBuf = (trustScanBuf + stripped).slice(-2000);
|
|
242
|
+
if (backend.id === 'claude' && /Enter/.test(trustScanBuf) && /confirm/.test(trustScanBuf)) {
|
|
243
|
+
trustConfirmed = true;
|
|
244
|
+
// CLI ≥2.1.3xx preselects "No, exit"; older ones preselect "Yes". Read
|
|
245
|
+
// the rendered screen once it settles and move to "Yes" only if needed.
|
|
246
|
+
setTimeout(() => {
|
|
247
|
+
const tail = bufferTail(headlessTerm, 12);
|
|
248
|
+
if (/❯\s*No/.test(tail)) {
|
|
249
|
+
proc.write('\x1b[B');
|
|
250
|
+
setTimeout(() => proc.write('\r'), 500);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
proc.write('\r');
|
|
254
|
+
}
|
|
255
|
+
}, 1000);
|
|
256
|
+
}
|
|
257
|
+
else if (backend.id !== 'claude' && /trust the files in this folder/i.test(trustScanBuf)) {
|
|
258
|
+
trustConfirmed = true;
|
|
259
|
+
proc.write('\x1b[B'); // ↓ to option 2 ("Yes, and remember this folder")
|
|
260
|
+
setTimeout(() => proc.write('\r'), 60);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Rolling tail scan for a PR URL (e.g. from `gh pr create` output) — no
|
|
264
|
+
// extra file I/O, reuses output already streaming through.
|
|
265
|
+
const buf = (((_b = prScanBuffers.get(id)) !== null && _b !== void 0 ? _b : '') + stripped).slice(-PR_SCAN_BUFFER_MAX);
|
|
266
|
+
prScanBuffers.set(id, buf);
|
|
267
|
+
// Remote Control pairing link ("Continue here, on your phone, or at …")
|
|
268
|
+
const rc = (_c = buf.match(RC_URL_RE)) === null || _c === void 0 ? void 0 : _c[0];
|
|
269
|
+
if (rc && ((_d = liveSessionStore_1.liveSessionStore.get(id)) === null || _d === void 0 ? void 0 : _d.rcUrl) !== rc) {
|
|
270
|
+
liveSessionStore_1.liveSessionStore.setRcUrl(id, rc);
|
|
271
|
+
emitRcUrl(id, rc);
|
|
272
|
+
}
|
|
273
|
+
const prUrl = (0, prDetector_1.extractPrUrl)(buf);
|
|
274
|
+
if (prUrl) {
|
|
275
|
+
const session = liveSessionStore_1.liveSessionStore.get(id);
|
|
276
|
+
if (session && session.prUrl !== prUrl) {
|
|
277
|
+
liveSessionStore_1.liveSessionStore.setPrUrl(id, prUrl);
|
|
278
|
+
emitPrUrl(id, prUrl);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// headlessTerm.write() parses asynchronously — the buffer only reflects
|
|
282
|
+
// this chunk once the callback fires, so status detection must happen there.
|
|
283
|
+
headlessTerm.write(data, () => {
|
|
284
|
+
if (!headlessTerms.has(id))
|
|
285
|
+
return;
|
|
286
|
+
// Copilot's status lives in the footer below the cursor, so read the
|
|
287
|
+
// screen bottom for it; Claude's lives in the lines around the cursor.
|
|
288
|
+
const status = backend.id !== 'claude'
|
|
289
|
+
? (0, statusDetector_1.detectStatus)(bottomRows(headlessTerm, 3), backend.id)
|
|
290
|
+
// Claude's footer (below the prompt) says "esc to interrupt" while busy
|
|
291
|
+
: (0, statusDetector_1.detectStatus)(bufferTail(headlessTerm) + '\n' + bottomRows(headlessTerm, 3));
|
|
292
|
+
const session = liveSessionStore_1.liveSessionStore.get(id);
|
|
293
|
+
if (!session)
|
|
294
|
+
return;
|
|
295
|
+
if (status === 'waiting') {
|
|
296
|
+
// Cancel any pending thinking transition — waiting wins immediately
|
|
297
|
+
const t = thinkingTimers.get(id);
|
|
298
|
+
if (t) {
|
|
299
|
+
clearTimeout(t);
|
|
300
|
+
thinkingTimers.delete(id);
|
|
301
|
+
}
|
|
302
|
+
if (session.status !== 'waiting') {
|
|
303
|
+
liveSessionStore_1.liveSessionStore.setStatus(id, 'waiting');
|
|
304
|
+
emitStatus(id, 'waiting');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else if (status === 'thinking' && session.status !== 'thinking') {
|
|
308
|
+
// Debounce: trailing chunks after the ❯ prompt often lack ❯, don't
|
|
309
|
+
// let them immediately clobber a 'waiting' state we just set.
|
|
310
|
+
if (!thinkingTimers.has(id)) {
|
|
311
|
+
thinkingTimers.set(id, setTimeout(() => {
|
|
312
|
+
thinkingTimers.delete(id);
|
|
313
|
+
const s = liveSessionStore_1.liveSessionStore.get(id);
|
|
314
|
+
if (s && s.status !== 'thinking') {
|
|
315
|
+
liveSessionStore_1.liveSessionStore.setStatus(id, 'thinking');
|
|
316
|
+
emitStatus(id, 'thinking');
|
|
317
|
+
}
|
|
318
|
+
}, 800));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
proc.onExit(() => {
|
|
324
|
+
var _a;
|
|
325
|
+
// A re-spawn (restart / resume-with-new-model) registers a NEW proc under
|
|
326
|
+
// the same id before this old one has exited. Only the current owner may
|
|
327
|
+
// tear the id's state down, or the new session is orphaned on arrival.
|
|
328
|
+
if (ptyProcesses.get(id) !== proc)
|
|
329
|
+
return;
|
|
330
|
+
const t = thinkingTimers.get(id);
|
|
331
|
+
if (t) {
|
|
332
|
+
clearTimeout(t);
|
|
333
|
+
thinkingTimers.delete(id);
|
|
334
|
+
}
|
|
335
|
+
liveSessionStore_1.liveSessionStore.setStatus(id, 'idle');
|
|
336
|
+
emitStatus(id, 'idle');
|
|
337
|
+
ptyProcesses.delete(id);
|
|
338
|
+
outputListeners.delete(id);
|
|
339
|
+
statusListeners.delete(id);
|
|
340
|
+
(_a = headlessTerms.get(id)) === null || _a === void 0 ? void 0 : _a.term.dispose();
|
|
341
|
+
headlessTerms.delete(id);
|
|
342
|
+
prScanBuffers.delete(id);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
function writeToSession(id, data) {
|
|
346
|
+
var _a;
|
|
347
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.write(data);
|
|
348
|
+
}
|
|
349
|
+
// Startup screens that take keystrokes but are NOT the input prompt (folder
|
|
350
|
+
// trust, login, theme, etc.). Typing a prompt into them answers them wrongly.
|
|
351
|
+
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;
|
|
352
|
+
function onScreenDialog(id) {
|
|
353
|
+
const h = headlessTerms.get(id);
|
|
354
|
+
return !!h && exports.STARTUP_DIALOG_RE.test(bottomRows(h.term, 25));
|
|
355
|
+
}
|
|
356
|
+
// Sends `text` as the session's first prompt once it sits at the real input
|
|
357
|
+
// prompt; while a startup dialog is showing it waits for you to answer it.
|
|
358
|
+
function sendWhenReady(id, text, timeoutMs = 10 * 60000) {
|
|
359
|
+
const started = Date.now();
|
|
360
|
+
let readySince = 0; // prompt must stay ready ~2s: TUIs report "waiting" before they finish drawing
|
|
361
|
+
const tick = () => {
|
|
362
|
+
var _a;
|
|
363
|
+
if (!ptyProcesses.has(id) || Date.now() - started > timeoutMs)
|
|
364
|
+
return;
|
|
365
|
+
if (((_a = liveSessionStore_1.liveSessionStore.get(id)) === null || _a === void 0 ? void 0 : _a.status) === 'waiting' && !onScreenDialog(id)) {
|
|
366
|
+
readySince || (readySince = Date.now());
|
|
367
|
+
if (Date.now() - readySince >= 2000) {
|
|
368
|
+
submitLine(id, text);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else
|
|
373
|
+
readySince = 0;
|
|
374
|
+
setTimeout(tick, 1000);
|
|
375
|
+
};
|
|
376
|
+
setTimeout(tick, 1500);
|
|
377
|
+
}
|
|
378
|
+
// Types a line into the agent's prompt and submits it. Enter goes separately:
|
|
379
|
+
// sent in the same write, the TUI treats it as part of a paste and doesn't submit.
|
|
380
|
+
function submitLine(id, text) {
|
|
381
|
+
var _a;
|
|
382
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.write(text);
|
|
383
|
+
setTimeout(() => { var _a; return (_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.write('\r'); }, 250);
|
|
384
|
+
}
|
|
385
|
+
function resizeSession(id, cols, rows) {
|
|
386
|
+
var _a, _b;
|
|
387
|
+
lastCols = cols;
|
|
388
|
+
lastRows = rows;
|
|
389
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.resize(cols, rows);
|
|
390
|
+
(_b = headlessTerms.get(id)) === null || _b === void 0 ? void 0 : _b.term.resize(cols, rows);
|
|
391
|
+
}
|
|
392
|
+
function getLastKnownSize() {
|
|
393
|
+
return { cols: lastCols, rows: lastRows };
|
|
394
|
+
}
|
|
395
|
+
function killSession(id) {
|
|
396
|
+
var _a, _b;
|
|
397
|
+
const t = thinkingTimers.get(id);
|
|
398
|
+
if (t) {
|
|
399
|
+
clearTimeout(t);
|
|
400
|
+
thinkingTimers.delete(id);
|
|
401
|
+
}
|
|
402
|
+
(_a = ptyProcesses.get(id)) === null || _a === void 0 ? void 0 : _a.kill();
|
|
403
|
+
ptyProcesses.delete(id);
|
|
404
|
+
outputListeners.delete(id);
|
|
405
|
+
statusListeners.delete(id);
|
|
406
|
+
(_b = headlessTerms.get(id)) === null || _b === void 0 ? void 0 : _b.term.dispose();
|
|
407
|
+
headlessTerms.delete(id);
|
|
408
|
+
prScanBuffers.delete(id);
|
|
409
|
+
}
|
|
410
|
+
function onOutput(id, fn) {
|
|
411
|
+
var _a;
|
|
412
|
+
(_a = outputListeners.get(id)) === null || _a === void 0 ? void 0 : _a.add(fn);
|
|
413
|
+
return () => { var _a; return (_a = outputListeners.get(id)) === null || _a === void 0 ? void 0 : _a.delete(fn); };
|
|
414
|
+
}
|
|
415
|
+
function onStatusChange(id, fn) {
|
|
416
|
+
var _a;
|
|
417
|
+
(_a = statusListeners.get(id)) === null || _a === void 0 ? void 0 : _a.add(fn);
|
|
418
|
+
return () => { var _a; return (_a = statusListeners.get(id)) === null || _a === void 0 ? void 0 : _a.delete(fn); };
|
|
419
|
+
}
|
|
420
|
+
function onAnyStatusChange(fn) {
|
|
421
|
+
anyStatusListeners.add(fn);
|
|
422
|
+
return () => anyStatusListeners.delete(fn);
|
|
423
|
+
}
|
|
424
|
+
function onAnyRcUrlChange(fn) {
|
|
425
|
+
anyRcUrlListeners.add(fn);
|
|
426
|
+
return () => anyRcUrlListeners.delete(fn);
|
|
427
|
+
}
|
|
428
|
+
function onAnyPrUrlChange(fn) {
|
|
429
|
+
anyPrUrlListeners.add(fn);
|
|
430
|
+
return () => anyPrUrlListeners.delete(fn);
|
|
431
|
+
}
|
|
432
|
+
// Full ANSI reconstruction of the session's actual current screen state, for
|
|
433
|
+
// sending on reattach — not a replay of raw output history.
|
|
434
|
+
function getSerializedScreen(id) {
|
|
435
|
+
var _a, _b;
|
|
436
|
+
return (_b = (_a = headlessTerms.get(id)) === null || _a === void 0 ? void 0 : _a.serialize.serialize()) !== null && _b !== void 0 ? _b : '';
|
|
437
|
+
}
|