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,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SILENCE_RMS_THRESHOLD = void 0;
|
|
4
|
+
exports.wavRms = wavRms;
|
|
5
|
+
exports.startCapture = startCapture;
|
|
6
|
+
exports.micTest = micTest;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const os_1 = require("os");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
// 10s balances transcript latency against transcription accuracy — short
|
|
13
|
+
// chunks give the model too little context (hurts Hebrew especially)
|
|
14
|
+
const CHUNK_SECONDS = 10;
|
|
15
|
+
// RMS of 16-bit PCM samples in a WAV file, 0..1. Locates the 'data' chunk
|
|
16
|
+
// instead of assuming a 44-byte header (ffmpeg sometimes writes LIST chunks).
|
|
17
|
+
function wavRms(buf) {
|
|
18
|
+
let offset = 12; // past RIFF header
|
|
19
|
+
while (offset + 8 <= buf.length) {
|
|
20
|
+
const chunkId = buf.toString('ascii', offset, offset + 4);
|
|
21
|
+
const chunkSize = buf.readUInt32LE(offset + 4);
|
|
22
|
+
if (chunkId === 'data') {
|
|
23
|
+
const start = offset + 8;
|
|
24
|
+
const end = Math.min(start + chunkSize, buf.length);
|
|
25
|
+
const sampleCount = Math.floor((end - start) / 2);
|
|
26
|
+
if (sampleCount === 0)
|
|
27
|
+
return 0;
|
|
28
|
+
let sumSq = 0;
|
|
29
|
+
for (let i = 0; i < sampleCount; i++) {
|
|
30
|
+
const s = buf.readInt16LE(start + i * 2) / 32768;
|
|
31
|
+
sumSq += s * s;
|
|
32
|
+
}
|
|
33
|
+
return Math.sqrt(sumSq / sampleCount);
|
|
34
|
+
}
|
|
35
|
+
offset += 8 + chunkSize + (chunkSize % 2);
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
// Below this a chunk is treated as silence and never sent for transcription
|
|
40
|
+
exports.SILENCE_RMS_THRESHOLD = 0.004;
|
|
41
|
+
// Two avfoundation inputs mixed by ffmpeg itself — avoids needing a macOS
|
|
42
|
+
// aggregate input device (whose programmatic creation requires a working
|
|
43
|
+
// Swift toolchain).
|
|
44
|
+
function ffmpegInputArgs(devices) {
|
|
45
|
+
return [
|
|
46
|
+
'-hide_banner', '-loglevel', 'error',
|
|
47
|
+
'-f', 'avfoundation', '-i', `:${devices.system}`,
|
|
48
|
+
'-f', 'avfoundation', '-i', `:${devices.mic}`,
|
|
49
|
+
'-filter_complex', 'amix=inputs=2:duration=longest:normalize=0',
|
|
50
|
+
'-ar', '16000', '-ac', '1',
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
function ffmpegArgs(devices, outPattern) {
|
|
54
|
+
return [
|
|
55
|
+
...ffmpegInputArgs(devices),
|
|
56
|
+
'-f', 'segment', '-segment_time', String(CHUNK_SECONDS),
|
|
57
|
+
'-reset_timestamps', '1',
|
|
58
|
+
outPattern,
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
// Records the device into 5s WAV chunks under <meetingDir>/audio and reports
|
|
62
|
+
// each chunk once it's complete (i.e. once the next chunk has appeared, or on
|
|
63
|
+
// stop). Polling instead of fs.watch — simpler and reliable enough at 5s
|
|
64
|
+
// granularity.
|
|
65
|
+
function startCapture(meetingDir, devices, cb) {
|
|
66
|
+
var _a;
|
|
67
|
+
const audioDir = (0, path_1.join)(meetingDir, 'audio');
|
|
68
|
+
(0, fs_1.mkdirSync)(audioDir, { recursive: true });
|
|
69
|
+
// Each capture run (first start, auto-restart, resume) gets its own prefix so
|
|
70
|
+
// it never overwrites or re-reports an earlier run's chunks.
|
|
71
|
+
const prefix = `chunk-${Date.now()}-`;
|
|
72
|
+
const proc = (0, child_process_1.spawn)('ffmpeg', ffmpegArgs(devices, (0, path_1.join)(audioDir, `${prefix}%05d.wav`)));
|
|
73
|
+
let stderrTail = '';
|
|
74
|
+
(_a = proc.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (d) => { stderrTail = (stderrTail + d.toString()).slice(-2000); });
|
|
75
|
+
const reported = new Set();
|
|
76
|
+
let stopped = false;
|
|
77
|
+
function scan(includeLatest) {
|
|
78
|
+
let files;
|
|
79
|
+
try {
|
|
80
|
+
files = (0, fs_1.readdirSync)(audioDir).filter(f => f.startsWith(prefix) && f.endsWith('.wav')).sort();
|
|
81
|
+
}
|
|
82
|
+
catch (_a) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// The highest-numbered chunk is still being written unless capture ended
|
|
86
|
+
const complete = includeLatest ? files : files.slice(0, -1);
|
|
87
|
+
for (const f of complete) {
|
|
88
|
+
if (reported.has(f))
|
|
89
|
+
continue;
|
|
90
|
+
reported.add(f);
|
|
91
|
+
cb.onChunk((0, path_1.join)(audioDir, f));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const poll = setInterval(() => scan(false), 1000);
|
|
95
|
+
let exited = false;
|
|
96
|
+
const exitPromise = new Promise(resolve => {
|
|
97
|
+
proc.on('exit', (code) => {
|
|
98
|
+
exited = true;
|
|
99
|
+
clearInterval(poll);
|
|
100
|
+
scan(true); // flush the final partial chunk
|
|
101
|
+
if (!stopped)
|
|
102
|
+
cb.onExit(code, stderrTail);
|
|
103
|
+
resolve();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
async stop() {
|
|
108
|
+
stopped = true;
|
|
109
|
+
if (!exited) {
|
|
110
|
+
proc.kill('SIGINT'); // graceful: lets ffmpeg finalize the open segment
|
|
111
|
+
const timeout = new Promise(r => setTimeout(() => { proc.kill('SIGKILL'); r(); }, 3000));
|
|
112
|
+
await Promise.race([exitPromise, timeout]);
|
|
113
|
+
await exitPromise;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// Records ~2s from the device and returns the level, for the pre-meeting mic
|
|
119
|
+
// check. Errors (device missing, no permission) come back as { error }.
|
|
120
|
+
async function micTest(devices) {
|
|
121
|
+
const outFile = (0, path_1.join)((0, os_1.tmpdir)(), `mic-test-${(0, crypto_1.randomUUID)().slice(0, 8)}.wav`);
|
|
122
|
+
return new Promise((resolve) => {
|
|
123
|
+
var _a;
|
|
124
|
+
const proc = (0, child_process_1.spawn)('ffmpeg', [
|
|
125
|
+
...ffmpegInputArgs(devices),
|
|
126
|
+
'-t', '2', outFile,
|
|
127
|
+
]);
|
|
128
|
+
let stderr = '';
|
|
129
|
+
(_a = proc.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (d) => { stderr += d.toString(); });
|
|
130
|
+
const killer = setTimeout(() => proc.kill('SIGKILL'), 8000);
|
|
131
|
+
proc.on('exit', (code) => {
|
|
132
|
+
var _a;
|
|
133
|
+
clearTimeout(killer);
|
|
134
|
+
try {
|
|
135
|
+
if (code !== 0) {
|
|
136
|
+
resolve({ error: (_a = stderr.trim().split('\n').at(-1)) !== null && _a !== void 0 ? _a : `ffmpeg exited ${code}` });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const buf = (0, fs_1.readFileSync)(outFile);
|
|
140
|
+
if ((0, fs_1.statSync)(outFile).size < 100) {
|
|
141
|
+
resolve({ error: 'No audio captured' });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
resolve({ level: wavRms(buf) });
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
resolve({ error: e instanceof Error ? e.message : 'mic test failed' });
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
try {
|
|
151
|
+
(0, fs_1.rmSync)(outFile, { force: true });
|
|
152
|
+
}
|
|
153
|
+
catch (_b) { }
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_BACKEND = exports.BACKENDS = exports.DEFAULT_MODEL_ID = void 0;
|
|
4
|
+
exports.getBackend = getBackend;
|
|
5
|
+
exports.availableBackends = availableBackends;
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
// 'default' = let the CLI use its own configured model (no --model flag)
|
|
10
|
+
exports.DEFAULT_MODEL_ID = 'default';
|
|
11
|
+
const modelArgs = (flag, model) => (model && model !== exports.DEFAULT_MODEL_ID ? [flag, model] : []);
|
|
12
|
+
const CLAUDE = {
|
|
13
|
+
id: 'claude',
|
|
14
|
+
label: 'Claude',
|
|
15
|
+
bin: 'claude',
|
|
16
|
+
spawnArgs: ({ model, resumeId, rcName, rc, skipPermissions }) => [
|
|
17
|
+
...(skipPermissions ? ['--permission-mode', 'bypassPermissions'] : []),
|
|
18
|
+
'--model', model,
|
|
19
|
+
// Remote Control is opt-in per session (📱 on the card) so the phone list
|
|
20
|
+
// only shows sessions you actually want there, labeled with their name.
|
|
21
|
+
...(rc ? ['--remote-control', ...(rcName ? [rcName] : [])] : []),
|
|
22
|
+
...(resumeId ? ['--resume', resumeId] : []),
|
|
23
|
+
],
|
|
24
|
+
env: (model) =>
|
|
25
|
+
// CLI 2.1.241 doesn't recognize the `claude-fable-5-1` id yet and refuses
|
|
26
|
+
// to launch it without this; the flag just skips the unknown-model context
|
|
27
|
+
// guard (Fable is 1M-context anyway). Remove once the CLI knows the id.
|
|
28
|
+
model.startsWith('claude-fable-5-1')
|
|
29
|
+
? { CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT: '1' }
|
|
30
|
+
: {},
|
|
31
|
+
};
|
|
32
|
+
// GitHub Copilot CLI (standalone `copilot`, @github/copilot). Interactive by
|
|
33
|
+
// default (no -p). --allow-all is the full bypassPermissions equivalent
|
|
34
|
+
// (= --allow-all-tools --allow-all-paths --allow-all-urls) so it never prompts;
|
|
35
|
+
// --allow-all-tools alone still asks about file paths and URLs. --resume=<id>
|
|
36
|
+
// resumes a prior session. Copilot has its own remote-control/export prompts
|
|
37
|
+
// that would block an unattended PTY, so we disable them here (unrelated to
|
|
38
|
+
// Claude's Remote Control feature).
|
|
39
|
+
// Copilot records each session in ~/.copilot/session-store.db (sqlite). We find
|
|
40
|
+
// the newest session row for this cwd created at/after spawn time — the direct
|
|
41
|
+
// analog of Claude's per-project .jsonl scan. Uses the sqlite3 CLI to avoid a
|
|
42
|
+
// native dependency; returns null on any error (DB locked, no row yet, etc.).
|
|
43
|
+
function findCopilotSessionIdSince(cwd, sinceMs) {
|
|
44
|
+
const db = (0, path_1.join)(process.env.HOME, '.copilot', 'session-store.db');
|
|
45
|
+
try {
|
|
46
|
+
// Copilot resolves symlinks in cwd (e.g. /tmp -> /private/tmp); match both
|
|
47
|
+
// the raw and realpath'd forms so detection isn't fooled by that.
|
|
48
|
+
let real = cwd;
|
|
49
|
+
try {
|
|
50
|
+
real = (0, child_process_1.execFileSync)('/usr/bin/readlink', ['-f', cwd], { timeout: 2000 }).toString().trim() || cwd;
|
|
51
|
+
}
|
|
52
|
+
catch (_a) { }
|
|
53
|
+
const since = new Date(sinceMs - 1000).toISOString(); // 1s tolerance for lag
|
|
54
|
+
const sql = `SELECT id FROM sessions WHERE cwd IN ('${cwd.replace(/'/g, "''")}','${real.replace(/'/g, "''")}') AND created_at >= '${since}' ORDER BY created_at DESC LIMIT 1;`;
|
|
55
|
+
const out = (0, child_process_1.execFileSync)('sqlite3', [db, sql], { timeout: 3000 }).toString().trim();
|
|
56
|
+
return out || null;
|
|
57
|
+
}
|
|
58
|
+
catch (_b) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const COPILOT = {
|
|
63
|
+
id: 'copilot',
|
|
64
|
+
label: 'Copilot',
|
|
65
|
+
bin: 'copilot',
|
|
66
|
+
detectSessionId: findCopilotSessionIdSince,
|
|
67
|
+
spawnArgs: ({ model, cwd, resumeId, skipPermissions }) => [
|
|
68
|
+
'--model', model,
|
|
69
|
+
...(skipPermissions ? ['--allow-all'] : []),
|
|
70
|
+
// Trust the session's folder up front. --allow-all covers tools/paths/URLs
|
|
71
|
+
// but NOT folder trust, so an interactive session in a new dir would pop a
|
|
72
|
+
// "Confirm folder trust" prompt every time; --add-dir pre-trusts it.
|
|
73
|
+
'--add-dir', cwd,
|
|
74
|
+
'--no-remote',
|
|
75
|
+
'--no-remote-export',
|
|
76
|
+
// Copilot enables terminal mouse tracking by default, which captures drag
|
|
77
|
+
// events so xterm.js can't select text (no copy). Disable it so click-drag
|
|
78
|
+
// selection + copy work the same as in Claude sessions.
|
|
79
|
+
'--no-mouse',
|
|
80
|
+
...(resumeId ? [`--resume=${resumeId}`] : []),
|
|
81
|
+
],
|
|
82
|
+
env: () => ({}),
|
|
83
|
+
};
|
|
84
|
+
const realpath = (p) => { try {
|
|
85
|
+
return (0, child_process_1.execFileSync)('/usr/bin/readlink', ['-f', p], { timeout: 2000 }).toString().trim() || p;
|
|
86
|
+
}
|
|
87
|
+
catch (_a) {
|
|
88
|
+
return p;
|
|
89
|
+
} };
|
|
90
|
+
// OpenCode (sst/opencode). TUI; sessions live in ~/.local/share/opencode/opencode.db.
|
|
91
|
+
// Footer shows "esc interrupt" while working. --auto = approve permissions.
|
|
92
|
+
const OPENCODE = {
|
|
93
|
+
id: 'opencode',
|
|
94
|
+
label: 'OpenCode',
|
|
95
|
+
bin: 'opencode',
|
|
96
|
+
spawnArgs: ({ model, cwd, resumeId, skipPermissions }) => [
|
|
97
|
+
cwd,
|
|
98
|
+
...modelArgs('-m', model),
|
|
99
|
+
...(skipPermissions ? ['--auto'] : []),
|
|
100
|
+
...(resumeId ? ['-s', resumeId] : []),
|
|
101
|
+
],
|
|
102
|
+
env: () => ({}),
|
|
103
|
+
detectSessionId: (cwd, sinceMs) => {
|
|
104
|
+
const db = (0, path_1.join)(process.env.HOME, '.local', 'share', 'opencode', 'opencode.db');
|
|
105
|
+
const q = (s) => `'${s.replace(/'/g, "''")}'`;
|
|
106
|
+
try {
|
|
107
|
+
const out = (0, child_process_1.execFileSync)('sqlite3', [db, `SELECT id FROM session WHERE parent_id IS NULL AND directory IN (${q(cwd)},${q(realpath(cwd))}) AND time_created >= ${sinceMs - 1000} ORDER BY time_created DESC LIMIT 1;`], { timeout: 3000 }).toString().trim();
|
|
108
|
+
return out || null;
|
|
109
|
+
}
|
|
110
|
+
catch (_a) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
// OpenAI Codex CLI. Resume is a subcommand; sessions are JSONL files under
|
|
116
|
+
// ~/.codex/sessions/YYYY/MM/DD whose first line holds {payload: {id, cwd}}.
|
|
117
|
+
function findCodexSessionIdSince(cwd, sinceMs) {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
const root = (0, path_1.join)(process.env.HOME, '.codex', 'sessions');
|
|
120
|
+
const real = realpath(cwd);
|
|
121
|
+
const d = new Date(sinceMs);
|
|
122
|
+
const dirs = [0, 1].map(off => { const x = new Date(d.getTime() + off * 86400000); return (0, path_1.join)(root, String(x.getFullYear()), String(x.getMonth() + 1).padStart(2, '0'), String(x.getDate()).padStart(2, '0')); });
|
|
123
|
+
let best = null;
|
|
124
|
+
for (const dir of dirs) {
|
|
125
|
+
let files = [];
|
|
126
|
+
try {
|
|
127
|
+
files = (0, fs_1.readdirSync)(dir).filter(f => f.endsWith('.jsonl'));
|
|
128
|
+
}
|
|
129
|
+
catch (_c) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
for (const f of files) {
|
|
133
|
+
const p = (0, path_1.join)(dir, f);
|
|
134
|
+
try {
|
|
135
|
+
const t = (0, fs_1.statSync)(p).birthtimeMs;
|
|
136
|
+
if (t < sinceMs - 1000 || (best && t < best.t))
|
|
137
|
+
continue;
|
|
138
|
+
const fd = (0, fs_1.openSync)(p, 'r');
|
|
139
|
+
const buf = Buffer.alloc(8192);
|
|
140
|
+
const n = (0, fs_1.readSync)(fd, buf, 0, buf.length, 0);
|
|
141
|
+
(0, fs_1.closeSync)(fd);
|
|
142
|
+
const meta = JSON.parse(buf.toString('utf-8', 0, n).split('\n')[0]);
|
|
143
|
+
const pl = (_a = meta.payload) !== null && _a !== void 0 ? _a : meta;
|
|
144
|
+
if (pl.id && (pl.cwd === cwd || pl.cwd === real))
|
|
145
|
+
best = { id: pl.id, t };
|
|
146
|
+
}
|
|
147
|
+
catch ( /* partial file */_d) { /* partial file */ }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return (_b = best === null || best === void 0 ? void 0 : best.id) !== null && _b !== void 0 ? _b : null;
|
|
151
|
+
}
|
|
152
|
+
const CODEX = {
|
|
153
|
+
id: 'codex',
|
|
154
|
+
label: 'Codex',
|
|
155
|
+
bin: 'codex',
|
|
156
|
+
spawnArgs: ({ model, resumeId, skipPermissions }) => [
|
|
157
|
+
...(resumeId ? ['resume', resumeId] : []),
|
|
158
|
+
...modelArgs('-m', model),
|
|
159
|
+
...(skipPermissions ? ['--dangerously-bypass-approvals-and-sandbox'] : []),
|
|
160
|
+
],
|
|
161
|
+
env: () => ({}),
|
|
162
|
+
detectSessionId: findCodexSessionIdSince,
|
|
163
|
+
};
|
|
164
|
+
// Google Gemini CLI. --yolo = approve all tool calls. No resume support here yet.
|
|
165
|
+
const GEMINI = {
|
|
166
|
+
id: 'gemini',
|
|
167
|
+
label: 'Gemini',
|
|
168
|
+
bin: 'gemini',
|
|
169
|
+
spawnArgs: ({ model, skipPermissions }) => [
|
|
170
|
+
...modelArgs('-m', model),
|
|
171
|
+
...(skipPermissions ? ['--yolo'] : []),
|
|
172
|
+
],
|
|
173
|
+
env: () => ({}),
|
|
174
|
+
};
|
|
175
|
+
exports.BACKENDS = {
|
|
176
|
+
claude: CLAUDE,
|
|
177
|
+
copilot: COPILOT,
|
|
178
|
+
opencode: OPENCODE,
|
|
179
|
+
codex: CODEX,
|
|
180
|
+
gemini: GEMINI,
|
|
181
|
+
};
|
|
182
|
+
exports.DEFAULT_BACKEND = 'claude';
|
|
183
|
+
function getBackend(id) {
|
|
184
|
+
var _a;
|
|
185
|
+
return (_a = exports.BACKENDS[id]) !== null && _a !== void 0 ? _a : exports.BACKENDS[exports.DEFAULT_BACKEND];
|
|
186
|
+
}
|
|
187
|
+
// Which backends are actually runnable on this machine — the UI only offers
|
|
188
|
+
// these, so a missing binary can never produce a failed spawn.
|
|
189
|
+
const availabilityCache = new Map();
|
|
190
|
+
function isBinaryAvailable(bin) {
|
|
191
|
+
if (availabilityCache.has(bin))
|
|
192
|
+
return availabilityCache.get(bin);
|
|
193
|
+
let ok = false;
|
|
194
|
+
try {
|
|
195
|
+
// login shell so PATH matches where the user's CLIs live (e.g. ~/.local/bin)
|
|
196
|
+
(0, child_process_1.execSync)(`zsh -lc 'command -v ${bin}'`, { stdio: 'ignore' });
|
|
197
|
+
ok = true;
|
|
198
|
+
}
|
|
199
|
+
catch (_a) {
|
|
200
|
+
ok = false;
|
|
201
|
+
}
|
|
202
|
+
availabilityCache.set(bin, ok);
|
|
203
|
+
return ok;
|
|
204
|
+
}
|
|
205
|
+
function availableBackends() {
|
|
206
|
+
return Object.values(exports.BACKENDS)
|
|
207
|
+
.filter(b => isBinaryAvailable(b.bin))
|
|
208
|
+
.map(b => ({ id: b.id, label: b.label }));
|
|
209
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClaudeAuthStatus = getClaudeAuthStatus;
|
|
4
|
+
exports.saveClaudeAuth = saveClaudeAuth;
|
|
5
|
+
exports.claudeAuthEnv = claudeAuthEnv;
|
|
6
|
+
exports.claudeLoginStatus = claudeLoginStatus;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const configFile_1 = require("./configFile");
|
|
9
|
+
function getClaudeAuthStatus(file = configFile_1.CONFIG_FILE) {
|
|
10
|
+
const cfg = (0, configFile_1.readConfig)(file);
|
|
11
|
+
const key = typeof cfg.anthropicApiKey === 'string' ? cfg.anthropicApiKey : '';
|
|
12
|
+
return cfg.claudeAuth === 'apiKey' && key ? { mode: 'apiKey', keyHint: '…' + key.slice(-4) } : { mode: 'login', keyHint: key ? '…' + key.slice(-4) : null };
|
|
13
|
+
}
|
|
14
|
+
// Blank apiKey keeps the saved key. Switching to login keeps the key on disk
|
|
15
|
+
// so switching back doesn't need it again.
|
|
16
|
+
function saveClaudeAuth(input, file = configFile_1.CONFIG_FILE) {
|
|
17
|
+
const cfg = (0, configFile_1.readConfig)(file);
|
|
18
|
+
if (input.mode === 'login') {
|
|
19
|
+
cfg.claudeAuth = 'login';
|
|
20
|
+
}
|
|
21
|
+
else if (input.mode === 'apiKey') {
|
|
22
|
+
const key = (typeof input.apiKey === 'string' ? input.apiKey.trim() : '') || (typeof cfg.anthropicApiKey === 'string' ? cfg.anthropicApiKey : '');
|
|
23
|
+
if (!key)
|
|
24
|
+
throw new Error('API key is required');
|
|
25
|
+
if (!key.startsWith('sk-ant-'))
|
|
26
|
+
throw new Error('That does not look like an Anthropic API key (it should start with sk-ant-)');
|
|
27
|
+
Object.assign(cfg, { claudeAuth: 'apiKey', anthropicApiKey: key });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error('Unknown mode');
|
|
31
|
+
}
|
|
32
|
+
(0, configFile_1.writeConfig)(cfg, file);
|
|
33
|
+
return getClaudeAuthStatus(file);
|
|
34
|
+
}
|
|
35
|
+
// Env for a Claude spawn. Login mode adds nothing (the CLI uses its own login).
|
|
36
|
+
function claudeAuthEnv(file = configFile_1.CONFIG_FILE) {
|
|
37
|
+
const cfg = (0, configFile_1.readConfig)(file);
|
|
38
|
+
return cfg.claudeAuth === 'apiKey' && typeof cfg.anthropicApiKey === 'string' && cfg.anthropicApiKey
|
|
39
|
+
? { ANTHROPIC_API_KEY: cfg.anthropicApiKey }
|
|
40
|
+
: {};
|
|
41
|
+
}
|
|
42
|
+
// `claude auth status` for a config folder (null = ~/.claude). Unknown → null.
|
|
43
|
+
function claudeLoginStatus(configDir) {
|
|
44
|
+
const env = Object.assign(Object.assign({}, process.env), (configDir ? { CLAUDE_CONFIG_DIR: configDir } : {}));
|
|
45
|
+
return new Promise(resolve => {
|
|
46
|
+
(0, child_process_1.execFile)('claude', ['auth', 'status'], { env, timeout: 20000 }, (_err, stdout) => {
|
|
47
|
+
var _a, _b, _c;
|
|
48
|
+
try {
|
|
49
|
+
const j = JSON.parse(stdout);
|
|
50
|
+
resolve({ loggedIn: !!j.loggedIn, email: (_a = j.email) !== null && _a !== void 0 ? _a : null, orgName: (_b = j.orgName) !== null && _b !== void 0 ? _b : null, plan: (_c = j.subscriptionType) !== null && _c !== void 0 ? _c : null });
|
|
51
|
+
}
|
|
52
|
+
catch (_d) {
|
|
53
|
+
resolve(null);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONFIG_FILE = void 0;
|
|
4
|
+
exports.readConfig = readConfig;
|
|
5
|
+
exports.writeConfig = writeConfig;
|
|
6
|
+
const dataDir_1 = require("./dataDir");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
// <data>/config.json holds secrets (API keys), so it is always written 0600.
|
|
10
|
+
exports.CONFIG_FILE = (0, path_1.join)(dataDir_1.DATA_DIR, 'config.json');
|
|
11
|
+
function readConfig(file = exports.CONFIG_FILE) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse((0, fs_1.readFileSync)(file, 'utf-8'));
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function writeConfig(cfg, file = exports.CONFIG_FILE) {
|
|
20
|
+
(0, fs_1.mkdirSync)((0, path_1.join)(file, '..'), { recursive: true });
|
|
21
|
+
(0, fs_1.writeFileSync)(file, JSON.stringify(cfg, null, 2), { mode: 0o600 });
|
|
22
|
+
(0, fs_1.chmodSync)(file, 0o600); // mode above only applies when the file is created
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DATA_DIR = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
// Where every server-side store lives. POLYERGON_DATA_DIR lets a second
|
|
6
|
+
// instance (e.g. a dev copy on another port) run without touching prod data.
|
|
7
|
+
exports.DATA_DIR = process.env.POLYERGON_DATA_DIR || (0, path_1.join)(process.env.HOME, '.claude-session-manager');
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseUnifiedDiff = parseUnifiedDiff;
|
|
4
|
+
exports.prDiff = prDiff;
|
|
5
|
+
exports.sessionDiff = sessionDiff;
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const MAX_BYTES = 1500000;
|
|
10
|
+
const git = (cwd, args) => (0, child_process_1.execFileSync)('git', ['-C', cwd, ...args], { stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 20000000, timeout: 20000 }).toString();
|
|
11
|
+
// Parses `git diff` output into files and numbered lines.
|
|
12
|
+
function parseUnifiedDiff(text) {
|
|
13
|
+
const files = [];
|
|
14
|
+
let f = null, oldNo = 0, newNo = 0;
|
|
15
|
+
for (const line of text.split('\n')) {
|
|
16
|
+
if (line.startsWith('diff --git ')) {
|
|
17
|
+
const m = line.match(/^diff --git a\/(.+) b\/(.+)$/);
|
|
18
|
+
f = { path: m ? m[2] : line.slice(11), status: 'modified', additions: 0, deletions: 0, lines: [] };
|
|
19
|
+
files.push(f);
|
|
20
|
+
}
|
|
21
|
+
else if (!f)
|
|
22
|
+
continue;
|
|
23
|
+
else if (line.startsWith('new file'))
|
|
24
|
+
f.status = 'added';
|
|
25
|
+
else if (line.startsWith('deleted file'))
|
|
26
|
+
f.status = 'deleted';
|
|
27
|
+
else if (line.startsWith('rename to ')) {
|
|
28
|
+
f.status = 'renamed';
|
|
29
|
+
f.path = line.slice(10);
|
|
30
|
+
}
|
|
31
|
+
else if (line.startsWith('Binary files'))
|
|
32
|
+
f.binary = true;
|
|
33
|
+
else if (line.startsWith('@@')) {
|
|
34
|
+
const m = line.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/);
|
|
35
|
+
if (m) {
|
|
36
|
+
oldNo = Number(m[1]);
|
|
37
|
+
newNo = Number(m[2]);
|
|
38
|
+
}
|
|
39
|
+
f.lines.push({ kind: 'hunk', text: line, oldNo: null, newNo: null });
|
|
40
|
+
}
|
|
41
|
+
else if (line.startsWith('+++') || line.startsWith('---') || line.startsWith('index ') || line.startsWith('similarity') || line.startsWith('rename from') || line.startsWith('old mode') || line.startsWith('new mode'))
|
|
42
|
+
continue;
|
|
43
|
+
else if (line.startsWith('+')) {
|
|
44
|
+
f.lines.push({ kind: 'add', text: line.slice(1), oldNo: null, newNo: newNo++ });
|
|
45
|
+
f.additions++;
|
|
46
|
+
}
|
|
47
|
+
else if (line.startsWith('-')) {
|
|
48
|
+
f.lines.push({ kind: 'del', text: line.slice(1), oldNo: oldNo++, newNo: null });
|
|
49
|
+
f.deletions++;
|
|
50
|
+
}
|
|
51
|
+
else if (line.startsWith(' '))
|
|
52
|
+
f.lines.push({ kind: 'ctx', text: line.slice(1), oldNo: oldNo++, newNo: newNo++ });
|
|
53
|
+
}
|
|
54
|
+
return files;
|
|
55
|
+
}
|
|
56
|
+
// Base = where this branch split from the main branch; on the main branch itself, HEAD (so: uncommitted work).
|
|
57
|
+
function findBase(cwd) {
|
|
58
|
+
const head = git(cwd, ['rev-parse', 'HEAD']).trim();
|
|
59
|
+
for (const ref of ['origin/HEAD', 'origin/main', 'origin/master', 'main', 'master']) {
|
|
60
|
+
try {
|
|
61
|
+
const mb = git(cwd, ['merge-base', 'HEAD', ref]).trim();
|
|
62
|
+
if (mb && mb !== head)
|
|
63
|
+
return { base: mb, label: ref.replace(/^origin\//, '') === 'HEAD' ? 'main branch' : ref.replace(/^origin\//, '') };
|
|
64
|
+
if (mb === head)
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
catch ( /* ref missing */_a) { /* ref missing */ }
|
|
68
|
+
}
|
|
69
|
+
return { base: head, label: 'last commit' };
|
|
70
|
+
}
|
|
71
|
+
// A pull request's diff from GitHub (needs gh). For sessions that worked outside their own folder.
|
|
72
|
+
function prDiff(url) {
|
|
73
|
+
const env = Object.assign({}, process.env);
|
|
74
|
+
delete env.GITHUB_TOKEN;
|
|
75
|
+
delete env.GH_TOKEN;
|
|
76
|
+
const run = (args) => (0, child_process_1.execFileSync)('gh', args, { stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 20000000, timeout: 30000, env }).toString();
|
|
77
|
+
let text = run(['pr', 'diff', url]);
|
|
78
|
+
let truncated = false;
|
|
79
|
+
if (text.length > MAX_BYTES) {
|
|
80
|
+
text = text.slice(0, MAX_BYTES);
|
|
81
|
+
truncated = true;
|
|
82
|
+
}
|
|
83
|
+
const meta = JSON.parse(run(['pr', 'view', url, '--json', 'headRefName,baseRefName']));
|
|
84
|
+
return { base: meta.baseRefName, baseLabel: meta.baseRefName, branch: meta.headRefName, files: parseUnifiedDiff(text), truncated };
|
|
85
|
+
}
|
|
86
|
+
function sessionDiff(cwd) {
|
|
87
|
+
const { base, label } = findBase(cwd);
|
|
88
|
+
const branch = git(cwd, ['branch', '--show-current']).trim() || 'detached';
|
|
89
|
+
let text = git(cwd, ['diff', '--no-color', '--find-renames', base]);
|
|
90
|
+
let truncated = false;
|
|
91
|
+
if (text.length > MAX_BYTES) {
|
|
92
|
+
text = text.slice(0, MAX_BYTES);
|
|
93
|
+
truncated = true;
|
|
94
|
+
}
|
|
95
|
+
const files = parseUnifiedDiff(text);
|
|
96
|
+
// New files git doesn't track yet
|
|
97
|
+
for (const p of git(cwd, ['ls-files', '--others', '--exclude-standard']).split('\n').filter(Boolean).slice(0, 200)) {
|
|
98
|
+
try {
|
|
99
|
+
if ((0, fs_1.statSync)((0, path_1.join)(cwd, p)).size > 200000) {
|
|
100
|
+
files.push({ path: p, status: 'added', additions: 0, deletions: 0, lines: [], binary: true });
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const body = (0, fs_1.readFileSync)((0, path_1.join)(cwd, p), 'utf-8');
|
|
104
|
+
if (body.includes('\u0000')) {
|
|
105
|
+
files.push({ path: p, status: 'added', additions: 0, deletions: 0, lines: [], binary: true });
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const rows = body.split('\n');
|
|
109
|
+
if (rows.at(-1) === '')
|
|
110
|
+
rows.pop();
|
|
111
|
+
files.push({ path: p, status: 'added', additions: rows.length, deletions: 0, lines: rows.map((t, i) => ({ kind: 'add', text: t, oldNo: null, newNo: i + 1 })) });
|
|
112
|
+
}
|
|
113
|
+
catch ( /* vanished */_a) { /* vanished */ }
|
|
114
|
+
}
|
|
115
|
+
return { base, baseLabel: label, branch, files, truncated };
|
|
116
|
+
}
|