@myrialabs/clopen 0.3.19 → 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/database/migrations/039_create_file_audit_log.ts +45 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/file-audit-log-queries.test.ts +377 -0
- package/backend/database/queries/file-audit-log-queries.ts +184 -0
- package/backend/database/queries/index.ts +2 -1
- package/backend/db-client/drivers/mysql.ts +28 -10
- package/backend/db-client/drivers/postgres.ts +34 -18
- package/backend/engine/adapters/claude/models.ts +43 -0
- package/backend/engine/install-recipes.ts +53 -140
- 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/http/files-upload.ts +84 -3
- package/backend/index.ts +27 -12
- package/backend/tunnel/tunnel-config.ts +76 -209
- package/backend/utils/client-ip.test.ts +55 -0
- package/backend/utils/client-ip.ts +42 -0
- package/backend/utils/ws.ts +6 -3
- package/backend/ws/auth/login.test.ts +271 -0
- package/backend/ws/auth/login.ts +36 -3
- package/backend/ws/auth/users.ts +3 -2
- package/backend/ws/chat/stream.ts +17 -6
- package/backend/ws/files/path-access.test.ts +60 -1
- package/backend/ws/files/path-access.ts +21 -0
- package/backend/ws/system-tools/install.ts +0 -1
- package/backend/ws/system-tools/status.ts +17 -4
- package/backend/ws/tunnel/config.ts +17 -25
- package/backend/ws/tunnel/operations.ts +63 -68
- 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 +4 -1
- package/shared/types/git.ts +8 -0
- package/shared/utils/ws-client.ts +188 -38
- package/backend/tunnel/cloudflared/binary.ts +0 -171
- package/backend/tunnel/cloudflared/index.ts +0 -24
- package/backend/tunnel/cloudflared/tunnel.ts +0 -444
- package/backend/tunnel/global-tunnel-manager.ts +0 -687
- package/backend/tunnel/project-tunnel-manager.ts +0 -264
- package/dist/assets/main-BOUXyIaW.js +0 -362
|
@@ -58,6 +58,7 @@ export class PostgresAdapter implements DbClientDriverAdapter {
|
|
|
58
58
|
private defaultSchema: string | null = null;
|
|
59
59
|
private conn: DbClientConnection | null = null;
|
|
60
60
|
private tunnelPort: number | undefined = undefined;
|
|
61
|
+
private ensureLock = Promise.resolve();
|
|
61
62
|
|
|
62
63
|
private buildUrl(conn: DbClientConnection, tunnelPort?: number): string {
|
|
63
64
|
const host = tunnelPort ? '127.0.0.1' : (conn.host ?? '127.0.0.1');
|
|
@@ -91,31 +92,46 @@ export class PostgresAdapter implements DbClientDriverAdapter {
|
|
|
91
92
|
|
|
92
93
|
private async ensureDatabase(database?: string): Promise<void> {
|
|
93
94
|
if (!this.conn) return;
|
|
94
|
-
// No specific database → revert to the home database, so connection-level
|
|
95
|
-
// operations don't run against whatever database was last browsed.
|
|
96
95
|
const target = database || this.homeDb;
|
|
97
96
|
if (target === this.defaultDb) return;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
|
|
98
|
+
let release: () => void;
|
|
99
|
+
const prev = this.ensureLock;
|
|
100
|
+
this.ensureLock = new Promise<void>((resolve) => { release = resolve; });
|
|
101
|
+
await prev;
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
if (target === this.defaultDb) return;
|
|
105
|
+
const newConn = { ...this.conn, database: target };
|
|
106
|
+
const url = this.buildUrl(newConn, this.tunnelPort);
|
|
107
|
+
const next = new SQL(url);
|
|
108
|
+
await next.connect();
|
|
109
|
+
const prevSql = this.sql;
|
|
110
|
+
this.sql = next;
|
|
111
|
+
this.defaultDb = target;
|
|
112
|
+
this.conn = newConn;
|
|
113
|
+
this.alive = true;
|
|
114
|
+
if (prevSql) await prevSql.close().catch((err) => debug.warn('db-client', 'pg switch close error:', err));
|
|
115
|
+
} finally {
|
|
116
|
+
release!();
|
|
117
|
+
}
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
async close(): Promise<void> {
|
|
111
|
-
|
|
112
|
-
|
|
121
|
+
let release: () => void;
|
|
122
|
+
const prev = this.ensureLock;
|
|
123
|
+
this.ensureLock = new Promise<void>((resolve) => { release = resolve; });
|
|
124
|
+
await prev;
|
|
125
|
+
|
|
113
126
|
try {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
this.alive = false;
|
|
128
|
+
this.conn = null;
|
|
129
|
+
if (!this.sql) return;
|
|
130
|
+
await this.sql.close().catch((err) => debug.warn('db-client', 'Postgres close error:', err));
|
|
131
|
+
this.sql = null;
|
|
132
|
+
} finally {
|
|
133
|
+
release!();
|
|
117
134
|
}
|
|
118
|
-
this.sql = null;
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
isAlive(): boolean {
|
|
@@ -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',
|
|
@@ -20,7 +20,7 @@ import { getClopenDir } from '$backend/utils/paths';
|
|
|
20
20
|
import { resolveBinary, resolveBinaryWithRefresh } from '$backend/utils/cli';
|
|
21
21
|
import { resolveStaticCurlAsset } from '$backend/utils/static-curl';
|
|
22
22
|
|
|
23
|
-
export type ToolId = 'git' | 'claude' | 'opencode' | 'copilot' | 'codex' | 'qwen' | 'chrome'
|
|
23
|
+
export type ToolId = 'git' | 'claude' | 'opencode' | 'copilot' | 'codex' | 'qwen' | 'chrome';
|
|
24
24
|
|
|
25
25
|
export interface ManualInstruction {
|
|
26
26
|
label: string;
|
|
@@ -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 {
|
|
@@ -205,15 +209,6 @@ export async function getToolStatus(tool: ToolId): Promise<ToolStatus> {
|
|
|
205
209
|
const version = await runVersion(resolved);
|
|
206
210
|
if (!version) return { tool, installed: false, version: null, source: null };
|
|
207
211
|
|
|
208
|
-
// Cloudflared: tag binaries under ~/.clopen/bin as "clopen"-managed so the
|
|
209
|
-
// UI distinguishes System Tools installs from system-wide ones.
|
|
210
|
-
if (tool === 'cloudflared') {
|
|
211
|
-
const clopenBinDir = join(getClopenDir(), 'bin');
|
|
212
|
-
if (resolved.startsWith(clopenBinDir)) {
|
|
213
|
-
return { tool, installed: true, version, source: 'clopen' };
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
212
|
return { tool, installed: true, version, source: resolved };
|
|
218
213
|
}
|
|
219
214
|
|
|
@@ -396,7 +391,15 @@ async function resolveOpenCodeRecipe(): Promise<Recipe> {
|
|
|
396
391
|
};
|
|
397
392
|
|
|
398
393
|
if (process.platform === 'win32') {
|
|
399
|
-
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
|
+
});
|
|
400
403
|
return base;
|
|
401
404
|
}
|
|
402
405
|
|
|
@@ -539,6 +542,9 @@ interface LinuxChromeStrategy {
|
|
|
539
542
|
async function resolveLinuxChromeRecipe(): Promise<Recipe> {
|
|
540
543
|
const mgr = detectLinuxPkgMgr();
|
|
541
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}"`;
|
|
542
548
|
|
|
543
549
|
const manual: ManualInstruction[] = [];
|
|
544
550
|
const strategy = pickLinuxChromeStrategy(mgr, arch);
|
|
@@ -550,37 +556,43 @@ async function resolveLinuxChromeRecipe(): Promise<Recipe> {
|
|
|
550
556
|
docs: CHROME_LINUX_DOCS
|
|
551
557
|
});
|
|
552
558
|
}
|
|
559
|
+
manual.push({
|
|
560
|
+
label: 'Puppeteer browsers CLI',
|
|
561
|
+
command: pptrDisplay,
|
|
562
|
+
docs: PPTR_CHROME_DOCS
|
|
563
|
+
});
|
|
553
564
|
|
|
554
|
-
|
|
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 {
|
|
555
589
|
tool: 'chrome',
|
|
556
|
-
autoInstallable:
|
|
590
|
+
autoInstallable: true,
|
|
557
591
|
missingPrereqs: [],
|
|
558
|
-
manualInstructions: manual
|
|
592
|
+
manualInstructions: manual,
|
|
593
|
+
command: pptrArgs,
|
|
594
|
+
displayCommand: pptrDisplay
|
|
559
595
|
};
|
|
560
|
-
|
|
561
|
-
if (!strategy) {
|
|
562
|
-
base.unavailableReason = arch !== 'x64'
|
|
563
|
-
? `Google Chrome is only published for Linux x86_64. No Chrome build exists for ${arch}. Download Chrome manually from google.com/chrome.`
|
|
564
|
-
: `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.`;
|
|
565
|
-
return base;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
if (strategy.requiresCurl && !attachCurlRequirement(base, 'Google Chrome')) {
|
|
569
|
-
return base;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
const elevated = await isElevated();
|
|
573
|
-
if (!elevated) {
|
|
574
|
-
base.unavailableReason = `Installing Google Chrome via ${strategy.pkgMgrLabel} requires root. Run clopen as root, or install Chrome manually with the command below and retry.`;
|
|
575
|
-
return base;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
base.autoInstallable = true;
|
|
579
|
-
base.shell = { program: 'sh', args: ['-c'] };
|
|
580
|
-
base.command = [strategy.installCommand];
|
|
581
|
-
base.displayCommand = strategy.manualCommand;
|
|
582
|
-
if (strategy.env) base.env = strategy.env;
|
|
583
|
-
return base;
|
|
584
596
|
}
|
|
585
597
|
|
|
586
598
|
function pickLinuxChromeStrategy(
|
|
@@ -628,104 +640,6 @@ function pickLinuxChromeStrategy(
|
|
|
628
640
|
return null;
|
|
629
641
|
}
|
|
630
642
|
|
|
631
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
632
|
-
// Cloudflared recipe — downloads the Cloudflare-signed binary into ~/.clopen/bin
|
|
633
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
634
|
-
|
|
635
|
-
const CLOUDFLARED_RELEASE_BASE = 'https://github.com/cloudflare/cloudflared/releases/latest/download';
|
|
636
|
-
const CLOUDFLARED_DOCS = 'https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/';
|
|
637
|
-
|
|
638
|
-
const CLOUDFLARED_LINUX_ARCH: Record<string, string> = {
|
|
639
|
-
x64: 'amd64',
|
|
640
|
-
arm64: 'arm64',
|
|
641
|
-
arm: 'arm',
|
|
642
|
-
ia32: '386'
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
async function resolveCloudflaredRecipe(): Promise<Recipe> {
|
|
646
|
-
const base: Recipe = {
|
|
647
|
-
tool: 'cloudflared',
|
|
648
|
-
autoInstallable: false,
|
|
649
|
-
missingPrereqs: [],
|
|
650
|
-
manualInstructions: []
|
|
651
|
-
};
|
|
652
|
-
|
|
653
|
-
const binDir = join(getClopenDir(), 'bin');
|
|
654
|
-
|
|
655
|
-
if (process.platform === 'darwin') {
|
|
656
|
-
const archKey = process.arch === 'arm64' ? 'arm64' : 'amd64';
|
|
657
|
-
const file = `cloudflared-darwin-${archKey}.tgz`;
|
|
658
|
-
const url = `${CLOUDFLARED_RELEASE_BASE}/${file}`;
|
|
659
|
-
const cmd =
|
|
660
|
-
`mkdir -p "${binDir}" && ` +
|
|
661
|
-
`curl -fsSL -o "${binDir}/${file}" "${url}" && ` +
|
|
662
|
-
`tar -xzf "${binDir}/${file}" -C "${binDir}" && ` +
|
|
663
|
-
`rm -f "${binDir}/${file}" && ` +
|
|
664
|
-
`chmod +x "${binDir}/cloudflared"`;
|
|
665
|
-
|
|
666
|
-
base.manualInstructions.push({
|
|
667
|
-
label: 'curl + tar',
|
|
668
|
-
command: cmd,
|
|
669
|
-
docs: CLOUDFLARED_DOCS
|
|
670
|
-
});
|
|
671
|
-
if (!attachCurlRequirement(base, 'Cloudflared')) return base;
|
|
672
|
-
base.autoInstallable = true;
|
|
673
|
-
base.shell = { program: 'bash', args: ['-c'] };
|
|
674
|
-
base.command = [cmd];
|
|
675
|
-
base.displayCommand = cmd;
|
|
676
|
-
return base;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
if (process.platform === 'linux') {
|
|
680
|
-
const archKey = CLOUDFLARED_LINUX_ARCH[process.arch];
|
|
681
|
-
if (!archKey) {
|
|
682
|
-
base.unavailableReason = `Cloudflared has no published Linux build for ${process.arch}.`;
|
|
683
|
-
return base;
|
|
684
|
-
}
|
|
685
|
-
const file = `cloudflared-linux-${archKey}`;
|
|
686
|
-
const url = `${CLOUDFLARED_RELEASE_BASE}/${file}`;
|
|
687
|
-
const cmd =
|
|
688
|
-
`mkdir -p "${binDir}" && ` +
|
|
689
|
-
`curl -fsSL -o "${binDir}/cloudflared" "${url}" && ` +
|
|
690
|
-
`chmod +x "${binDir}/cloudflared"`;
|
|
691
|
-
|
|
692
|
-
base.manualInstructions.push({
|
|
693
|
-
label: 'curl',
|
|
694
|
-
command: cmd,
|
|
695
|
-
docs: CLOUDFLARED_DOCS
|
|
696
|
-
});
|
|
697
|
-
if (!attachCurlRequirement(base, 'Cloudflared')) return base;
|
|
698
|
-
base.autoInstallable = true;
|
|
699
|
-
base.shell = { program: 'bash', args: ['-c'] };
|
|
700
|
-
base.command = [cmd];
|
|
701
|
-
base.displayCommand = cmd;
|
|
702
|
-
return base;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
if (process.platform === 'win32') {
|
|
706
|
-
const archKey = process.arch === 'ia32' ? '386' : 'amd64';
|
|
707
|
-
const file = `cloudflared-windows-${archKey}.exe`;
|
|
708
|
-
const url = `${CLOUDFLARED_RELEASE_BASE}/${file}`;
|
|
709
|
-
const psCmd =
|
|
710
|
-
`New-Item -ItemType Directory -Path "${binDir}" -Force | Out-Null; ` +
|
|
711
|
-
`Invoke-WebRequest -Uri "${url}" -OutFile "${binDir}\\cloudflared.exe"`;
|
|
712
|
-
|
|
713
|
-
base.manualInstructions.push({
|
|
714
|
-
label: 'PowerShell',
|
|
715
|
-
command: psCmd,
|
|
716
|
-
docs: CLOUDFLARED_DOCS
|
|
717
|
-
});
|
|
718
|
-
base.autoInstallable = true;
|
|
719
|
-
base.shell = { program: 'powershell.exe', args: ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command'] };
|
|
720
|
-
base.command = [psCmd];
|
|
721
|
-
base.displayCommand = psCmd;
|
|
722
|
-
return base;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
base.unavailableReason = `Unsupported platform: ${process.platform}`;
|
|
726
|
-
return base;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
643
|
/**
|
|
730
644
|
* Resolve the install recipe for a tool on the current platform.
|
|
731
645
|
* Result is platform- and privilege-aware: recipes that would fail
|
|
@@ -740,6 +654,5 @@ export async function resolveRecipe(tool: ToolId): Promise<Recipe> {
|
|
|
740
654
|
case 'codex': return resolveCodexRecipe();
|
|
741
655
|
case 'qwen': return resolveQwenRecipe();
|
|
742
656
|
case 'chrome': return resolveChromeRecipe();
|
|
743
|
-
case 'cloudflared': return resolveCloudflaredRecipe();
|
|
744
657
|
}
|
|
745
658
|
}
|
|
@@ -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',
|