@myrialabs/clopen 0.3.20 → 0.3.21
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/backend/engine/adapters/claude/models.ts +43 -0
- package/backend/engine/install-recipes.ts +52 -31
- package/backend/engine/version-check.ts +145 -0
- package/backend/git/git-parser.ts +11 -0
- package/backend/git/git-service.ts +52 -7
- package/backend/index.ts +27 -12
- package/backend/ws/chat/stream.ts +17 -6
- package/backend/ws/system-tools/status.ts +14 -0
- package/dist/assets/main-BgOiIS43.js +360 -0
- package/dist/assets/{main-ClADBkFf.css → main-CJdJeen6.css} +1 -1
- package/dist/index.html +2 -2
- package/package.json +3 -1
- package/shared/types/git.ts +8 -0
- package/dist/assets/main-72Z_L-nD.js +0 -362
|
@@ -9,6 +9,49 @@
|
|
|
9
9
|
import type { EngineModel } from '$shared/types/unified';
|
|
10
10
|
|
|
11
11
|
export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
12
|
+
{
|
|
13
|
+
engine: {
|
|
14
|
+
type: 'claude-code',
|
|
15
|
+
provider: 'anthropic',
|
|
16
|
+
model: {
|
|
17
|
+
id: 'claude-fable-5',
|
|
18
|
+
name: 'Claude Fable 5',
|
|
19
|
+
},
|
|
20
|
+
account: {
|
|
21
|
+
id: 0,
|
|
22
|
+
name: '',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
limit: {
|
|
26
|
+
input: 1_000_000,
|
|
27
|
+
output: 128_000,
|
|
28
|
+
},
|
|
29
|
+
modalities: {
|
|
30
|
+
input: {
|
|
31
|
+
text: true,
|
|
32
|
+
image: true,
|
|
33
|
+
audio: false,
|
|
34
|
+
video: false,
|
|
35
|
+
pdf: true,
|
|
36
|
+
},
|
|
37
|
+
output: {
|
|
38
|
+
text: true,
|
|
39
|
+
image: false,
|
|
40
|
+
audio: false,
|
|
41
|
+
video: false,
|
|
42
|
+
pdf: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
capabilities: {
|
|
46
|
+
reasoning: true,
|
|
47
|
+
tools: true,
|
|
48
|
+
structuredOutput: true,
|
|
49
|
+
},
|
|
50
|
+
cost: {
|
|
51
|
+
input: 10,
|
|
52
|
+
output: 50,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
12
55
|
{
|
|
13
56
|
engine: {
|
|
14
57
|
type: 'claude-code',
|
|
@@ -108,8 +108,6 @@ function detectMacPkgMgr(): 'brew' | null {
|
|
|
108
108
|
* Google Chrome via the distro package manager and skip this scan.
|
|
109
109
|
*/
|
|
110
110
|
export function resolveClopenChromePath(): string | null {
|
|
111
|
-
if (process.platform !== 'darwin' && process.platform !== 'win32') return null;
|
|
112
|
-
|
|
113
111
|
const cacheDir = join(getClopenDir(), 'bin', 'chrome');
|
|
114
112
|
if (!existsSync(cacheDir)) return null;
|
|
115
113
|
|
|
@@ -127,12 +125,18 @@ export function resolveClopenChromePath(): string | null {
|
|
|
127
125
|
);
|
|
128
126
|
if (existsSync(candidate)) return candidate;
|
|
129
127
|
}
|
|
130
|
-
} else {
|
|
128
|
+
} else if (process.platform === 'win32') {
|
|
131
129
|
const winDirs = ['chrome-win64', 'chrome-win'];
|
|
132
130
|
for (const dir of winDirs) {
|
|
133
131
|
const candidate = join(buildDir, dir, 'chrome.exe');
|
|
134
132
|
if (existsSync(candidate)) return candidate;
|
|
135
133
|
}
|
|
134
|
+
} else {
|
|
135
|
+
const linuxDirs = ['chrome-linux64', 'chrome-linux'];
|
|
136
|
+
for (const dir of linuxDirs) {
|
|
137
|
+
const candidate = join(buildDir, dir, 'chrome');
|
|
138
|
+
if (existsSync(candidate)) return candidate;
|
|
139
|
+
}
|
|
136
140
|
}
|
|
137
141
|
}
|
|
138
142
|
} catch {
|
|
@@ -387,7 +391,15 @@ async function resolveOpenCodeRecipe(): Promise<Recipe> {
|
|
|
387
391
|
};
|
|
388
392
|
|
|
389
393
|
if (process.platform === 'win32') {
|
|
390
|
-
base.
|
|
394
|
+
base.autoInstallable = true;
|
|
395
|
+
base.shell = { program: 'powershell.exe', args: ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command'] };
|
|
396
|
+
base.command = ['irm https://opencode.ai/install.ps1 | iex'];
|
|
397
|
+
base.displayCommand = 'irm https://opencode.ai/install.ps1 | iex';
|
|
398
|
+
base.manualInstructions.push({
|
|
399
|
+
label: 'PowerShell',
|
|
400
|
+
command: 'irm https://opencode.ai/install.ps1 | iex',
|
|
401
|
+
docs: 'https://opencode.ai'
|
|
402
|
+
});
|
|
391
403
|
return base;
|
|
392
404
|
}
|
|
393
405
|
|
|
@@ -530,6 +542,9 @@ interface LinuxChromeStrategy {
|
|
|
530
542
|
async function resolveLinuxChromeRecipe(): Promise<Recipe> {
|
|
531
543
|
const mgr = detectLinuxPkgMgr();
|
|
532
544
|
const arch = process.arch;
|
|
545
|
+
const cacheDir = join(getClopenDir(), 'bin');
|
|
546
|
+
const pptrArgs = ['bun', 'x', '@puppeteer/browsers', 'install', 'chrome@stable', '--path', cacheDir];
|
|
547
|
+
const pptrDisplay = `bun x @puppeteer/browsers install chrome@stable --path "${cacheDir}"`;
|
|
533
548
|
|
|
534
549
|
const manual: ManualInstruction[] = [];
|
|
535
550
|
const strategy = pickLinuxChromeStrategy(mgr, arch);
|
|
@@ -541,37 +556,43 @@ async function resolveLinuxChromeRecipe(): Promise<Recipe> {
|
|
|
541
556
|
docs: CHROME_LINUX_DOCS
|
|
542
557
|
});
|
|
543
558
|
}
|
|
559
|
+
manual.push({
|
|
560
|
+
label: 'Puppeteer browsers CLI',
|
|
561
|
+
command: pptrDisplay,
|
|
562
|
+
docs: PPTR_CHROME_DOCS
|
|
563
|
+
});
|
|
544
564
|
|
|
545
|
-
|
|
565
|
+
// Try Google Chrome via system package manager (x64, apt/dnf/zypper, requires root).
|
|
566
|
+
if (strategy) {
|
|
567
|
+
const elevated = await isElevated();
|
|
568
|
+
if (elevated) {
|
|
569
|
+
const base: Recipe = {
|
|
570
|
+
tool: 'chrome',
|
|
571
|
+
autoInstallable: false,
|
|
572
|
+
missingPrereqs: [],
|
|
573
|
+
manualInstructions: manual
|
|
574
|
+
};
|
|
575
|
+
if (!strategy.requiresCurl || attachCurlRequirement(base, 'Google Chrome')) {
|
|
576
|
+
base.autoInstallable = true;
|
|
577
|
+
base.shell = { program: 'sh', args: ['-c'] };
|
|
578
|
+
base.command = [strategy.installCommand];
|
|
579
|
+
base.displayCommand = strategy.manualCommand;
|
|
580
|
+
if (strategy.env) base.env = strategy.env;
|
|
581
|
+
return base;
|
|
582
|
+
}
|
|
583
|
+
// curl unavailable for system install — fall through to puppeteer
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Fallback: puppeteer Chrome for Testing (no root needed, all distros and arm64).
|
|
588
|
+
return {
|
|
546
589
|
tool: 'chrome',
|
|
547
|
-
autoInstallable:
|
|
590
|
+
autoInstallable: true,
|
|
548
591
|
missingPrereqs: [],
|
|
549
|
-
manualInstructions: manual
|
|
592
|
+
manualInstructions: manual,
|
|
593
|
+
command: pptrArgs,
|
|
594
|
+
displayCommand: pptrDisplay
|
|
550
595
|
};
|
|
551
|
-
|
|
552
|
-
if (!strategy) {
|
|
553
|
-
base.unavailableReason = arch !== 'x64'
|
|
554
|
-
? `Google Chrome is only published for Linux x86_64. No Chrome build exists for ${arch}. Download Chrome manually from google.com/chrome.`
|
|
555
|
-
: `Google Chrome is only available via apt, dnf, or zypper on Linux${mgr ? ` (this system uses ${mgr})` : ' — no supported package manager was detected'}. Download Chrome manually from google.com/chrome.`;
|
|
556
|
-
return base;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
if (strategy.requiresCurl && !attachCurlRequirement(base, 'Google Chrome')) {
|
|
560
|
-
return base;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
const elevated = await isElevated();
|
|
564
|
-
if (!elevated) {
|
|
565
|
-
base.unavailableReason = `Installing Google Chrome via ${strategy.pkgMgrLabel} requires root. Run clopen as root, or install Chrome manually with the command below and retry.`;
|
|
566
|
-
return base;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
base.autoInstallable = true;
|
|
570
|
-
base.shell = { program: 'sh', args: ['-c'] };
|
|
571
|
-
base.command = [strategy.installCommand];
|
|
572
|
-
base.displayCommand = strategy.manualCommand;
|
|
573
|
-
if (strategy.env) base.env = strategy.env;
|
|
574
|
-
return base;
|
|
575
596
|
}
|
|
576
597
|
|
|
577
598
|
function pickLinuxChromeStrategy(
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { ToolId } from './install-recipes';
|
|
2
|
+
|
|
3
|
+
export interface UpdateCheckResult {
|
|
4
|
+
latestVersion: string | null;
|
|
5
|
+
/** true = newer available, false = already latest, null = could not determine */
|
|
6
|
+
hasUpdate: boolean | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type VersionSource =
|
|
10
|
+
| { type: 'npm'; pkg: string }
|
|
11
|
+
| { type: 'homebrew-formula'; formula: string }
|
|
12
|
+
| { type: 'github-release'; repo: string }
|
|
13
|
+
| { type: 'chrome-for-testing' };
|
|
14
|
+
|
|
15
|
+
const SOURCES: Record<ToolId, VersionSource> = {
|
|
16
|
+
claude: { type: 'npm', pkg: '@anthropic-ai/claude-code' },
|
|
17
|
+
opencode: { type: 'npm', pkg: 'opencode-ai' },
|
|
18
|
+
copilot: { type: 'npm', pkg: '@github/copilot' },
|
|
19
|
+
codex: { type: 'npm', pkg: '@openai/codex' },
|
|
20
|
+
qwen: { type: 'npm', pkg: '@qwen-code/qwen-code' },
|
|
21
|
+
git: { type: 'homebrew-formula', formula: 'git' },
|
|
22
|
+
chrome: { type: 'chrome-for-testing' },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// ─── version helpers ──────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
function extractVersion(str: string): string | null {
|
|
28
|
+
const m = str.match(/(\d+(?:\.\d+)+)/);
|
|
29
|
+
return m ? m[1] : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function versionGt(a: string, b: string): boolean {
|
|
33
|
+
const av = a.split('.').map(Number);
|
|
34
|
+
const bv = b.split('.').map(Number);
|
|
35
|
+
const len = Math.max(av.length, bv.length);
|
|
36
|
+
for (let i = 0; i < len; i++) {
|
|
37
|
+
if ((av[i] ?? 0) > (bv[i] ?? 0)) return true;
|
|
38
|
+
if ((av[i] ?? 0) < (bv[i] ?? 0)) return false;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ─── fetchers ─────────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
async function fetchNpmLatest(pkg: string): Promise<string | null> {
|
|
46
|
+
try {
|
|
47
|
+
const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(pkg)}/latest`, {
|
|
48
|
+
headers: { Accept: 'application/json' },
|
|
49
|
+
signal: AbortSignal.timeout(10_000)
|
|
50
|
+
});
|
|
51
|
+
if (!res.ok) return null;
|
|
52
|
+
const json = await res.json() as { version?: unknown };
|
|
53
|
+
return typeof json.version === 'string' ? json.version : null;
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Homebrew formula API — no auth, no rate limit, tracks upstream releases
|
|
61
|
+
* tightly. Used as the primary source for git since the GitHub API has a
|
|
62
|
+
* low unauthenticated rate limit.
|
|
63
|
+
*/
|
|
64
|
+
async function fetchHomebrewLatest(formula: string): Promise<string | null> {
|
|
65
|
+
try {
|
|
66
|
+
const res = await fetch(`https://formulae.brew.sh/api/formula/${encodeURIComponent(formula)}.json`, {
|
|
67
|
+
headers: { Accept: 'application/json' },
|
|
68
|
+
signal: AbortSignal.timeout(10_000)
|
|
69
|
+
});
|
|
70
|
+
if (!res.ok) return null;
|
|
71
|
+
const json = await res.json() as { versions?: { stable?: unknown } };
|
|
72
|
+
const v = json.versions?.stable;
|
|
73
|
+
return typeof v === 'string' ? v : null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function fetchGitHubLatest(repo: string): Promise<string | null> {
|
|
80
|
+
try {
|
|
81
|
+
const res = await fetch(`https://api.github.com/repos/${repo}/releases/latest`, {
|
|
82
|
+
headers: {
|
|
83
|
+
Accept: 'application/vnd.github+json',
|
|
84
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
85
|
+
'User-Agent': 'clopen-version-checker'
|
|
86
|
+
},
|
|
87
|
+
signal: AbortSignal.timeout(10_000)
|
|
88
|
+
});
|
|
89
|
+
if (!res.ok) return null;
|
|
90
|
+
const json = await res.json() as { tag_name?: unknown };
|
|
91
|
+
const tag = json.tag_name;
|
|
92
|
+
if (typeof tag !== 'string') return null;
|
|
93
|
+
return tag.startsWith('v') ? tag.slice(1) : tag;
|
|
94
|
+
} catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function fetchChromeLatest(): Promise<string | null> {
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch(
|
|
102
|
+
'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json',
|
|
103
|
+
{ signal: AbortSignal.timeout(10_000) }
|
|
104
|
+
);
|
|
105
|
+
if (!res.ok) return null;
|
|
106
|
+
const json = await res.json() as { channels?: { Stable?: { version?: unknown } } };
|
|
107
|
+
const v = json.channels?.Stable?.version;
|
|
108
|
+
return typeof v === 'string' ? v : null;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ─── public API ───────────────────────────────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
export async function checkToolUpdate(
|
|
117
|
+
tool: ToolId,
|
|
118
|
+
installedVersion: string | null
|
|
119
|
+
): Promise<UpdateCheckResult> {
|
|
120
|
+
const source = SOURCES[tool];
|
|
121
|
+
|
|
122
|
+
let latestVersion: string | null;
|
|
123
|
+
switch (source.type) {
|
|
124
|
+
case 'npm':
|
|
125
|
+
latestVersion = await fetchNpmLatest(source.pkg);
|
|
126
|
+
break;
|
|
127
|
+
case 'homebrew-formula':
|
|
128
|
+
latestVersion = await fetchHomebrewLatest(source.formula);
|
|
129
|
+
break;
|
|
130
|
+
case 'github-release':
|
|
131
|
+
latestVersion = await fetchGitHubLatest(source.repo);
|
|
132
|
+
break;
|
|
133
|
+
case 'chrome-for-testing':
|
|
134
|
+
latestVersion = await fetchChromeLatest();
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!latestVersion) return { latestVersion: null, hasUpdate: null };
|
|
139
|
+
if (!installedVersion) return { latestVersion, hasUpdate: null };
|
|
140
|
+
|
|
141
|
+
const current = extractVersion(installedVersion);
|
|
142
|
+
if (!current) return { latestVersion, hasUpdate: null };
|
|
143
|
+
|
|
144
|
+
return { latestVersion, hasUpdate: versionGt(latestVersion, current) };
|
|
145
|
+
}
|
|
@@ -114,6 +114,17 @@ export function parseBranches(localOutput: string, remoteOutput: string): GitBra
|
|
|
114
114
|
// Format: "* main abc1234 commit message" or " dev abc1234 commit message"
|
|
115
115
|
const isCurrent = line.startsWith('*');
|
|
116
116
|
const trimmed = line.replace(/^\*?\s+/, '');
|
|
117
|
+
|
|
118
|
+
// When HEAD is detached, git emits a parenthesized pseudo-ref instead of a
|
|
119
|
+
// branch name, e.g. "* (no branch, rebasing main)" or "* (HEAD detached at
|
|
120
|
+
// abc1234)". These are not real branches — skip them so they never leak into
|
|
121
|
+
// the branch list or get treated as the current branch (which produced the
|
|
122
|
+
// bogus "(no" branch name). Match git's exact pseudo-ref prefixes so legit
|
|
123
|
+
// branch names containing parentheses (e.g. "feature(x)") are preserved. The
|
|
124
|
+
// real current branch / detached state is resolved authoritatively in
|
|
125
|
+
// git-service. Output is forced to en_US locale, so these strings are stable.
|
|
126
|
+
if (isCurrent && /^\((?:HEAD detached|no branch)\b/.test(trimmed)) continue;
|
|
127
|
+
|
|
117
128
|
const parts = trimmed.split(/\s+/);
|
|
118
129
|
const name = parts[0];
|
|
119
130
|
const lastCommit = parts[1] || '';
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import type {
|
|
20
20
|
GitStatus,
|
|
21
21
|
GitBranchInfo,
|
|
22
|
+
GitOperation,
|
|
22
23
|
GitFileDiff,
|
|
23
24
|
GitLogResult,
|
|
24
25
|
GitRemote,
|
|
@@ -233,9 +234,10 @@ export class GitService {
|
|
|
233
234
|
// ============================================
|
|
234
235
|
|
|
235
236
|
async getBranches(cwd: string): Promise<GitBranchInfo> {
|
|
236
|
-
const [localResult, remoteResult] = await Promise.all([
|
|
237
|
+
const [localResult, remoteResult, headRef] = await Promise.all([
|
|
237
238
|
execGit(['branch', '-v', '--no-color'], cwd),
|
|
238
|
-
execGit(['branch', '-r', '-v', '--no-color'], cwd)
|
|
239
|
+
execGit(['branch', '-r', '-v', '--no-color'], cwd),
|
|
240
|
+
execGit(['rev-parse', '--abbrev-ref', 'HEAD'], cwd)
|
|
239
241
|
]);
|
|
240
242
|
|
|
241
243
|
// Handle empty repo (no commits yet) — branch command returns empty
|
|
@@ -247,6 +249,25 @@ export class GitService {
|
|
|
247
249
|
}
|
|
248
250
|
|
|
249
251
|
const branchInfo = parseBranches(localResult.stdout, remoteResult.stdout);
|
|
252
|
+
branchInfo.operation = await this.detectGitOperation(cwd);
|
|
253
|
+
|
|
254
|
+
// Resolve the current branch authoritatively instead of trusting the parsed
|
|
255
|
+
// `git branch -v` text: while HEAD is detached (rebase, bisect, or a detached
|
|
256
|
+
// checkout) git prints a parenthesized pseudo-ref, which previously leaked
|
|
257
|
+
// through as a bogus "(no" branch name.
|
|
258
|
+
const headName = headRef.exitCode === 0 ? headRef.stdout.trim() : '';
|
|
259
|
+
if (headName === '' || headName === 'HEAD') {
|
|
260
|
+
// Detached HEAD — show a clean short hash, never a real branch.
|
|
261
|
+
branchInfo.detached = true;
|
|
262
|
+
const shortHash = await execGit(['rev-parse', '--short', 'HEAD'], cwd);
|
|
263
|
+
branchInfo.current = shortHash.exitCode === 0 ? shortHash.stdout.trim() : '';
|
|
264
|
+
for (const b of branchInfo.local) b.isCurrent = false;
|
|
265
|
+
return branchInfo;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
branchInfo.detached = false;
|
|
269
|
+
branchInfo.current = headName;
|
|
270
|
+
for (const b of branchInfo.local) b.isCurrent = b.name === headName;
|
|
250
271
|
|
|
251
272
|
// Get ahead/behind for current branch
|
|
252
273
|
if (branchInfo.current) {
|
|
@@ -643,14 +664,38 @@ export class GitService {
|
|
|
643
664
|
* For stash conflicts (no sentinel) we fall back to `git reset --merge`,
|
|
644
665
|
* which unwinds the unmerged paths while keeping unrelated local edits.
|
|
645
666
|
*/
|
|
646
|
-
|
|
667
|
+
/** Resolve the absolute git dir for a working tree (handles worktrees/.git files). */
|
|
668
|
+
private async resolveGitDir(cwd: string): Promise<string> {
|
|
669
|
+
const { join } = await import('node:path');
|
|
670
|
+
const result = await execGit(['rev-parse', '--git-dir'], cwd);
|
|
671
|
+
const raw = result.exitCode === 0 ? result.stdout.trim() : '.git';
|
|
672
|
+
return raw.startsWith('/') ? raw : join(cwd, raw);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Detect an in-progress operation (rebase, merge, cherry-pick, revert, bisect)
|
|
677
|
+
* by probing the sentinel files git writes under the git dir. Returns null when
|
|
678
|
+
* the working tree is in a normal state.
|
|
679
|
+
*/
|
|
680
|
+
private async detectGitOperation(cwd: string): Promise<GitOperation | null> {
|
|
647
681
|
const { existsSync } = await import('node:fs');
|
|
648
682
|
const { join } = await import('node:path');
|
|
683
|
+
const gitDir = await this.resolveGitDir(cwd);
|
|
684
|
+
const has = (name: string) => existsSync(join(gitDir, name));
|
|
685
|
+
|
|
686
|
+
if (has('rebase-merge') || has('rebase-apply')) return 'rebase';
|
|
687
|
+
if (has('MERGE_HEAD')) return 'merge';
|
|
688
|
+
if (has('CHERRY_PICK_HEAD')) return 'cherry-pick';
|
|
689
|
+
if (has('REVERT_HEAD')) return 'revert';
|
|
690
|
+
if (has('BISECT_LOG')) return 'bisect';
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
649
693
|
|
|
650
|
-
|
|
651
|
-
const
|
|
652
|
-
const
|
|
694
|
+
async abortMerge(cwd: string): Promise<void> {
|
|
695
|
+
const { existsSync } = await import('node:fs');
|
|
696
|
+
const { join } = await import('node:path');
|
|
653
697
|
|
|
698
|
+
const gitDir = await this.resolveGitDir(cwd);
|
|
654
699
|
const has = (name: string) => existsSync(join(gitDir, name));
|
|
655
700
|
|
|
656
701
|
let args: string[] | null = null;
|
|
@@ -742,7 +787,7 @@ export class GitService {
|
|
|
742
787
|
if (!npmPath) {
|
|
743
788
|
throw new Error('npm binary not found on PATH');
|
|
744
789
|
}
|
|
745
|
-
const proc = Bun.spawn([npmPath, 'version', bump
|
|
790
|
+
const proc = Bun.spawn([npmPath, 'version', bump], {
|
|
746
791
|
cwd,
|
|
747
792
|
stdout: 'pipe',
|
|
748
793
|
stderr: 'pipe',
|
package/backend/index.ts
CHANGED
|
@@ -240,20 +240,23 @@ process.on('SIGHUP', () => {
|
|
|
240
240
|
debug.log('server', 'Received SIGHUP — ignoring (server stays running)');
|
|
241
241
|
});
|
|
242
242
|
|
|
243
|
-
// Safety net: prevent server crash from unhandled
|
|
244
|
-
// These can occur when
|
|
245
|
-
// the normal try/catch flow
|
|
243
|
+
// Safety net: prevent server crash from unhandled promise rejections.
|
|
244
|
+
// These can occur when third-party SDKs emit asynchronous errors that bypass
|
|
245
|
+
// the normal try/catch flow, e.g.:
|
|
246
|
+
// - AI engine SDKs whose subprocess is killed during initialization
|
|
247
|
+
// - puppeteer-extra's stealth evasions fire a non-awaited
|
|
248
|
+
// `Network.setUserAgentOverride` on a newly created popup target; when the
|
|
249
|
+
// target closes mid-call the resulting TargetCloseError rejects with no
|
|
250
|
+
// handler attached and would otherwise kill the whole server while the user
|
|
251
|
+
// is interacting with the Preview.
|
|
246
252
|
//
|
|
247
|
-
// IMPORTANT
|
|
248
|
-
// process.on('unhandledRejection')
|
|
249
|
-
//
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
event.preventDefault();
|
|
254
|
-
|
|
253
|
+
// IMPORTANT (Bun routing — verified on Bun 1.3.14): top-level unhandled
|
|
254
|
+
// rejections are suppressed by Node's process.on('unhandledRejection') but NOT
|
|
255
|
+
// by the Web API globalThis.addEventListener('unhandledrejection') +
|
|
256
|
+
// preventDefault() (the Web handler does not even fire for these). We register
|
|
257
|
+
// BOTH for cross-version safety; the shared reporter below dedups intent.
|
|
258
|
+
function reportUnhandledRejection(reason: unknown): void {
|
|
255
259
|
try {
|
|
256
|
-
const reason = event.reason;
|
|
257
260
|
const message = reason instanceof Error ? reason.message : String(reason);
|
|
258
261
|
if (message.includes('Operation aborted') || message.includes('aborted')) {
|
|
259
262
|
debug.warn('server', 'Suppressed expected SDK abort rejection:', message);
|
|
@@ -263,6 +266,18 @@ globalThis.addEventListener('unhandledrejection', (event: PromiseRejectionEvent)
|
|
|
263
266
|
} catch {
|
|
264
267
|
console.error('Unhandled promise rejection (server still running)');
|
|
265
268
|
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Primary net on Bun 1.3.x — registering this handler prevents the default
|
|
272
|
+
// crash-on-unhandled-rejection behavior.
|
|
273
|
+
process.on('unhandledRejection', (reason) => {
|
|
274
|
+
reportUnhandledRejection(reason);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Belt-and-suspenders for Bun versions where only the Web API suppresses exit.
|
|
278
|
+
globalThis.addEventListener('unhandledrejection', (event: PromiseRejectionEvent) => {
|
|
279
|
+
event.preventDefault();
|
|
280
|
+
reportUnhandledRejection(event.reason);
|
|
266
281
|
});
|
|
267
282
|
|
|
268
283
|
process.on('uncaughtException', (error) => {
|
|
@@ -132,14 +132,25 @@ export const streamHandler = createRouter()
|
|
|
132
132
|
debug.warn('chat', 'Presence broadcast error after chat join-session:', err);
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
// Rehydrate rate-limit banners: replay
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
// the user is currently viewing.
|
|
135
|
+
// Rehydrate rate-limit banners: replay only snapshots matching the
|
|
136
|
+
// session's engine+account so banners are scoped to the active context.
|
|
137
|
+
// In-memory state takes priority (most current); DB is the fallback for
|
|
138
|
+
// sessions joined after a server restart.
|
|
140
139
|
try {
|
|
141
140
|
const userId = ws.getUserId(conn);
|
|
142
|
-
const
|
|
141
|
+
const inMemoryModel = chatSessionModelState.get(data.chatSessionId);
|
|
142
|
+
const inMemoryAccount = chatSessionAccountState.get(data.chatSessionId);
|
|
143
|
+
const sessionEngine: string | undefined =
|
|
144
|
+
inMemoryModel?.engine ?? sessionQueries.getById(data.chatSessionId)?.engine;
|
|
145
|
+
const sessionAccountId: number | null =
|
|
146
|
+
inMemoryAccount?.accountId ?? sessionQueries.getById(data.chatSessionId)?.account_id ?? null;
|
|
147
|
+
|
|
148
|
+
const snapshots = streamManager.getAllActiveRateLimits().filter(snap => {
|
|
149
|
+
if (sessionEngine && snap.engine !== sessionEngine) return false;
|
|
150
|
+
if (sessionAccountId != null && snap.accountId !== sessionAccountId) return false;
|
|
151
|
+
return true;
|
|
152
|
+
});
|
|
153
|
+
|
|
143
154
|
for (const snap of snapshots) {
|
|
144
155
|
ws.emit.user(userId, 'chat:rate_limit', {
|
|
145
156
|
chatSessionId: data.chatSessionId,
|
|
@@ -12,6 +12,7 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
12
12
|
import { debug } from '$shared/utils/logger';
|
|
13
13
|
import { getToolStatus, resolveRecipe, type ToolId } from '$backend/engine/install-recipes';
|
|
14
14
|
import { getActiveSessionForTool } from '$backend/engine/install-runner';
|
|
15
|
+
import { checkToolUpdate } from '$backend/engine/version-check';
|
|
15
16
|
|
|
16
17
|
const TOOL_UNION = t.Union([
|
|
17
18
|
t.Literal('git'),
|
|
@@ -82,6 +83,19 @@ function toRecipeDTO(tool: ToolId, recipe: Awaited<ReturnType<typeof resolveReci
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
export const systemToolsStatusHandler = createRouter()
|
|
86
|
+
.http('system-tools:check-update', {
|
|
87
|
+
data: t.Object({
|
|
88
|
+
tool: TOOL_UNION,
|
|
89
|
+
installedVersion: t.Union([t.String(), t.Null()])
|
|
90
|
+
}),
|
|
91
|
+
response: t.Object({
|
|
92
|
+
latestVersion: t.Union([t.String(), t.Null()]),
|
|
93
|
+
hasUpdate: t.Union([t.Boolean(), t.Null()])
|
|
94
|
+
})
|
|
95
|
+
}, async ({ data }) => {
|
|
96
|
+
debug.log('path', `system-tools:check-update for ${data.tool}`);
|
|
97
|
+
return checkToolUpdate(data.tool, data.installedVersion);
|
|
98
|
+
})
|
|
85
99
|
.http('system-tools:status', {
|
|
86
100
|
data: t.Object({ tool: TOOL_UNION }),
|
|
87
101
|
response: t.Object({
|