synabun 2026.4.26 → 2026.4.27
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/CHANGELOG.md +11 -126
- package/neural-interface/public/shared/cdx/cdx-panel.js +4 -4
- package/neural-interface/public/shared/cdx/cdx-styles.js +1 -1
- package/neural-interface/public/shared/ocp/ocp-panel.js +5 -4
- package/neural-interface/public/shared/ocp/ocp-styles.js +1 -1
- package/neural-interface/public/shared/styles.css +257 -151
- package/neural-interface/public/shared/ui-claude-panel.js +5 -5
- package/neural-interface/public/shared/ui-menubar.js +64 -36
- package/neural-interface/public/shared/ui-tool-updates.js +77 -3
- package/neural-interface/public/shared/ui-update.js +234 -32
- package/neural-interface/server.js +926 -74
- package/package.json +4 -1
- package/postinstall.js +20 -0
- package/preuninstall.js +140 -6
- package/updater.cmd +31 -0
- package/updater.mjs +245 -0
- package/updater.sh +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "synabun",
|
|
3
|
-
"version": "2026.4.
|
|
3
|
+
"version": "2026.4.27",
|
|
4
4
|
"description": "Persistent vector memory for AI assistants",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "The SynaBun Authors",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"setup.js",
|
|
18
18
|
"postinstall.js",
|
|
19
19
|
"preuninstall.js",
|
|
20
|
+
"updater.mjs",
|
|
21
|
+
"updater.cmd",
|
|
22
|
+
"updater.sh",
|
|
20
23
|
"mcp-server/package.json",
|
|
21
24
|
"mcp-server/dist/",
|
|
22
25
|
"mcp-server/tsconfig.json",
|
package/postinstall.js
CHANGED
|
@@ -197,6 +197,25 @@ function registerProtocolHandler() {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
// ── Updater shim executable bit ──
|
|
201
|
+
//
|
|
202
|
+
// npm publish drops the executable bit on macOS/Linux when the tarball is
|
|
203
|
+
// built on Windows (a common pipeline issue). The in-app updater needs
|
|
204
|
+
// updater.sh to be executable so the per-OS terminal-launch path can
|
|
205
|
+
// `exec()` it directly. Restore the bit defensively on every postinstall.
|
|
206
|
+
|
|
207
|
+
function ensureUpdaterShExecutable() {
|
|
208
|
+
if (platform() === 'win32') return;
|
|
209
|
+
const shPath = resolve(__dirname, 'updater.sh');
|
|
210
|
+
if (!existsSync(shPath)) return;
|
|
211
|
+
try {
|
|
212
|
+
chmodSync(shPath, 0o755);
|
|
213
|
+
ok('updater.sh marked executable');
|
|
214
|
+
} catch (err) {
|
|
215
|
+
warn(`updater.sh chmod failed (${err.message}) — manual fix: chmod +x "${shPath}"`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
200
219
|
// ── Main ──
|
|
201
220
|
|
|
202
221
|
function main() {
|
|
@@ -207,6 +226,7 @@ function main() {
|
|
|
207
226
|
rebuildPty();
|
|
208
227
|
buildMcpServer();
|
|
209
228
|
registerProtocolHandler();
|
|
229
|
+
ensureUpdaterShExecutable();
|
|
210
230
|
|
|
211
231
|
console.log(`\n ${c.green}\u2713${c.reset} Setup complete. Run ${c.cyan}synabun${c.reset} to start.\n`);
|
|
212
232
|
}
|
package/preuninstall.js
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* SynaBun — NPM preuninstall script
|
|
5
5
|
*
|
|
6
|
-
* Runs before `npm uninstall synabun
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Runs before `npm uninstall synabun` AND before `npm i -g synabun@x`
|
|
7
|
+
* overwrites the existing install.
|
|
8
|
+
*
|
|
9
|
+
* 1. Politely ask any running SynaBun server to shut down so its child
|
|
10
|
+
* processes (opencode sidecar, agents, pty terminals) release file
|
|
11
|
+
* handles inside neural-interface/. Without this step, npm's rename
|
|
12
|
+
* step fails with EBUSY on Windows.
|
|
13
|
+
* 2. Remove nested node_modules that cause EPERM/deep-path errors on Windows.
|
|
14
|
+
* 3. Remove the synabun:// protocol handler registration.
|
|
15
|
+
*
|
|
16
|
+
* Graceful — if any step fails, don't block the uninstall. npm will handle
|
|
17
|
+
* the remainder; the user can always retry.
|
|
10
18
|
*/
|
|
11
19
|
|
|
12
20
|
import { rmSync, existsSync } from 'node:fs';
|
|
@@ -17,7 +25,133 @@ import { homedir, platform } from 'node:os';
|
|
|
17
25
|
|
|
18
26
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
27
|
|
|
20
|
-
// ──
|
|
28
|
+
// ── Step 1: ask running SynaBun server to shut down cleanly ──
|
|
29
|
+
// Default port 3344 (matches NEURAL_PORT default in server.js). If the user
|
|
30
|
+
// changed NEURAL_PORT we miss them; that's acceptable since the next steps
|
|
31
|
+
// degrade gracefully. We don't want to scan all ports — too invasive for a
|
|
32
|
+
// preuninstall script.
|
|
33
|
+
|
|
34
|
+
await tryGracefulServerShutdown();
|
|
35
|
+
|
|
36
|
+
async function tryGracefulServerShutdown() {
|
|
37
|
+
const port = Number(process.env.NEURAL_PORT) || 3344;
|
|
38
|
+
const url = `http://127.0.0.1:${port}/api/server/shutdown`;
|
|
39
|
+
try {
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
const timeout = setTimeout(() => controller.abort(), 2000);
|
|
42
|
+
const res = await fetch(url, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: { 'Content-Type': 'application/json' },
|
|
45
|
+
body: '{}',
|
|
46
|
+
signal: controller.signal,
|
|
47
|
+
});
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
if (!res.ok) return; // server returned but not OK — proceed anyway
|
|
50
|
+
// Wait for server to actually exit (poll with a HEAD request to /api/health
|
|
51
|
+
// or just sleep — sleep is simpler and uses no network).
|
|
52
|
+
for (let i = 0; i < 20; i++) {
|
|
53
|
+
await new Promise(r => setTimeout(r, 250));
|
|
54
|
+
try {
|
|
55
|
+
const ping = new AbortController();
|
|
56
|
+
const tt = setTimeout(() => ping.abort(), 500);
|
|
57
|
+
await fetch(`http://127.0.0.1:${port}/api/health`, { signal: ping.signal });
|
|
58
|
+
clearTimeout(tt);
|
|
59
|
+
// Still up — keep waiting.
|
|
60
|
+
} catch {
|
|
61
|
+
// Connection refused / aborted — server is gone.
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Extra grace for child processes to release file handles on Windows.
|
|
66
|
+
await new Promise(r => setTimeout(r, 1500));
|
|
67
|
+
} catch {
|
|
68
|
+
// No server listening, fetch unavailable, etc. — just continue.
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ── Step 1b: kill any orphaned processes holding file handles ──
|
|
73
|
+
//
|
|
74
|
+
// Even after a graceful server shutdown (or when no server is running),
|
|
75
|
+
// orphaned children can survive: opencode-ai sidecars spawned via cmd.exe,
|
|
76
|
+
// MCP servers (claude-memory-mcp) spawned by Claude Code instances rather
|
|
77
|
+
// than by SynaBun itself, agent processes, etc. On Windows these orphans
|
|
78
|
+
// keep file handles inside the install dir open, causing EBUSY when npm
|
|
79
|
+
// tries to rename it.
|
|
80
|
+
//
|
|
81
|
+
// We nuke any process whose command line references the SynaBun install
|
|
82
|
+
// path. This catches every orphan regardless of how they got that way.
|
|
83
|
+
// Skips the current PID (we are the preuninstall process itself).
|
|
84
|
+
|
|
85
|
+
killOrphansInsideInstall();
|
|
86
|
+
|
|
87
|
+
function killOrphansInsideInstall() {
|
|
88
|
+
const installPath = __dirname;
|
|
89
|
+
const selfPid = process.pid;
|
|
90
|
+
const plat = platform();
|
|
91
|
+
|
|
92
|
+
if (plat === 'win32') {
|
|
93
|
+
// PowerShell: Get-CimInstance returns every process with CommandLine.
|
|
94
|
+
// Pass the install path via env so this PowerShell command line does not
|
|
95
|
+
// itself contain the path we are trying to match and kill.
|
|
96
|
+
// Stop-Process -Force kills synchronously; -ErrorAction SilentlyContinue
|
|
97
|
+
// suppresses "process already exited" noise.
|
|
98
|
+
const ps = `
|
|
99
|
+
$ErrorActionPreference = 'SilentlyContinue';
|
|
100
|
+
$installPath = $env:SYNABUN_INSTALL_PATH;
|
|
101
|
+
$selfPid = [int]$env:SYNABUN_PREUNINSTALL_PID;
|
|
102
|
+
Get-CimInstance Win32_Process |
|
|
103
|
+
Where-Object {
|
|
104
|
+
$_.ProcessId -ne $selfPid -and
|
|
105
|
+
$_.ProcessId -ne $PID -and (
|
|
106
|
+
($_.CommandLine -and $_.CommandLine -like "*$installPath*") -or
|
|
107
|
+
($_.ExecutablePath -and $_.ExecutablePath -like "$installPath*")
|
|
108
|
+
)
|
|
109
|
+
} |
|
|
110
|
+
ForEach-Object {
|
|
111
|
+
Write-Host (' Killing orphan PID ' + $_.ProcessId + ' (' + $_.Name + ')');
|
|
112
|
+
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
|
|
113
|
+
}
|
|
114
|
+
`.trim();
|
|
115
|
+
try {
|
|
116
|
+
execSync(`powershell -NoProfile -ExecutionPolicy Bypass -Command "${ps.replace(/"/g, '\\"').replace(/\n/g, ' ')}"`, {
|
|
117
|
+
stdio: 'inherit',
|
|
118
|
+
timeout: 8000,
|
|
119
|
+
env: {
|
|
120
|
+
...process.env,
|
|
121
|
+
SYNABUN_INSTALL_PATH: installPath,
|
|
122
|
+
SYNABUN_PREUNINSTALL_PID: String(selfPid),
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
} catch {
|
|
126
|
+
// PowerShell unavailable, blocked, or timed out. Fall through.
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
// Unix: pgrep -f matches against the full command line. -P 1 skips
|
|
130
|
+
// self/children of init we shouldn't touch. We just enumerate then
|
|
131
|
+
// SIGKILL each one that isn't us.
|
|
132
|
+
try {
|
|
133
|
+
const out = execSync(`pgrep -f "${installPath.replace(/[/.*?+^$|(){}\\\[\]]/g, '\\$&')}"`, {
|
|
134
|
+
encoding: 'utf8',
|
|
135
|
+
timeout: 5000,
|
|
136
|
+
}).trim();
|
|
137
|
+
const pids = out.split('\n')
|
|
138
|
+
.map(s => Number(s.trim()))
|
|
139
|
+
.filter(n => Number.isFinite(n) && n > 0 && n !== selfPid);
|
|
140
|
+
for (const pid of pids) {
|
|
141
|
+
try { process.kill(pid, 'SIGKILL'); } catch {}
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
// No matches or pgrep missing — fine.
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Brief grace for OS to release file handles after killing.
|
|
149
|
+
// Synchronous busy-wait so we run before the rmSync calls below.
|
|
150
|
+
const until = Date.now() + 1500;
|
|
151
|
+
while (Date.now() < until) { /* spin */ }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── Step 2: remove nested node_modules ──
|
|
21
155
|
|
|
22
156
|
const dirs = [
|
|
23
157
|
resolve(__dirname, 'neural-interface', 'node_modules'),
|
|
@@ -32,7 +166,7 @@ for (const dir of dirs) {
|
|
|
32
166
|
}
|
|
33
167
|
}
|
|
34
168
|
|
|
35
|
-
// ──
|
|
169
|
+
// ── Step 3: remove protocol handler ──
|
|
36
170
|
|
|
37
171
|
const plat = platform();
|
|
38
172
|
|
package/updater.cmd
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enableextensions
|
|
3
|
+
title SynaBun Updater
|
|
4
|
+
|
|
5
|
+
rem ───────────────────────────────────────────────────────
|
|
6
|
+
rem Windows shim for the cross-platform updater (updater.mjs).
|
|
7
|
+
rem Invoked by the running SynaBun server via:
|
|
8
|
+
rem start "" "<install>\updater.cmd" --payload payload.json
|
|
9
|
+
rem
|
|
10
|
+
rem We use a shim instead of spawning node directly so cmd's
|
|
11
|
+
rem quoting rules don't mangle the command line, and so the
|
|
12
|
+
rem window stays open for the user to read npm output even
|
|
13
|
+
rem if node exits unexpectedly.
|
|
14
|
+
rem ───────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
set "SCRIPT_DIR=%~dp0"
|
|
17
|
+
set "EXIT_CODE=0"
|
|
18
|
+
|
|
19
|
+
rem %~dp0 ends with backslash. updater.mjs lives next to this file.
|
|
20
|
+
node "%SCRIPT_DIR%updater.mjs" %* --no-hold
|
|
21
|
+
set EXIT_CODE=%ERRORLEVEL%
|
|
22
|
+
|
|
23
|
+
echo.
|
|
24
|
+
if %EXIT_CODE%==0 (
|
|
25
|
+
echo [Update finished. Press any key to close this window.]
|
|
26
|
+
) else (
|
|
27
|
+
echo [Update exited with code %EXIT_CODE%. Press any key to close this window.]
|
|
28
|
+
)
|
|
29
|
+
pause >nul
|
|
30
|
+
|
|
31
|
+
endlocal ^& exit /b %EXIT_CODE%
|
package/updater.mjs
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SynaBun updater.
|
|
3
|
+
//
|
|
4
|
+
// Normal flow:
|
|
5
|
+
// 1. The running server copies this file into a user-data staging directory.
|
|
6
|
+
// 2. The staged runner calls it with --payload payload.json.
|
|
7
|
+
// 3. This process waits for the old server to exit, then runs npm i -g.
|
|
8
|
+
//
|
|
9
|
+
// Keeping the updater outside the installed package is intentional. On Windows,
|
|
10
|
+
// running from node_modules/synabun can hold locks on the directory npm needs to
|
|
11
|
+
// rename during a global update.
|
|
12
|
+
|
|
13
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
|
+
|
|
16
|
+
const args = parseArgs(process.argv.slice(2));
|
|
17
|
+
const payload = loadPayload(args.payload);
|
|
18
|
+
|
|
19
|
+
const legacyTag = sanitizeTag(args.tag || 'latest');
|
|
20
|
+
const installSpec = sanitizeInstallSpec(payload.installSpec || args['install-spec'] || `synabun@${legacyTag}`);
|
|
21
|
+
const displayCommand = payload.displayCommand || `npm i -g ${installSpec}`;
|
|
22
|
+
const serverPid = toPid(payload.serverPid ?? args.pid);
|
|
23
|
+
const cleanupPids = sanitizePidList(payload.cleanupPids).filter(pid => pid !== serverPid && pid !== process.pid);
|
|
24
|
+
const autoRestart = payload.autoRestart != null ? !!payload.autoRestart : !!args.restart;
|
|
25
|
+
const safeCwd = payload.cwd || process.cwd();
|
|
26
|
+
const noHold = !!args['no-hold'];
|
|
27
|
+
|
|
28
|
+
const isWin = process.platform === 'win32';
|
|
29
|
+
const NPM_BIN = isWin ? 'npm.cmd' : 'npm';
|
|
30
|
+
const HR = '='.repeat(56);
|
|
31
|
+
|
|
32
|
+
process.on('SIGINT', () => {});
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
if (!installSpec) throw new Error('No valid SynaBun install target was provided.');
|
|
36
|
+
|
|
37
|
+
console.log(`\n${HR}`);
|
|
38
|
+
console.log(` SynaBun Updater`);
|
|
39
|
+
if (payload.current || payload.target) {
|
|
40
|
+
console.log(` ${payload.current || '?'} -> ${payload.target || installSpec}`);
|
|
41
|
+
}
|
|
42
|
+
console.log(`${HR}\n`);
|
|
43
|
+
|
|
44
|
+
if (serverPid) {
|
|
45
|
+
console.log(`Waiting for SynaBun server (PID ${serverPid}) to exit...`);
|
|
46
|
+
const exited = await waitForExit(serverPid, 30000);
|
|
47
|
+
if (exited) {
|
|
48
|
+
console.log(' Server exited.\n');
|
|
49
|
+
} else {
|
|
50
|
+
console.warn(' Server still alive after 30s - forcing server process kill.\n');
|
|
51
|
+
forceKillPid(serverPid);
|
|
52
|
+
await sleep(1500);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
console.log('No server PID provided - assuming already stopped.\n');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await sleep(1500);
|
|
59
|
+
if (cleanupPids.length) {
|
|
60
|
+
console.log(`Cleaning up ${cleanupPids.length} pre-existing child process${cleanupPids.length === 1 ? '' : 'es'}...`);
|
|
61
|
+
for (const pid of cleanupPids) {
|
|
62
|
+
if (!isPidAlive(pid)) continue;
|
|
63
|
+
forceKillTree(pid);
|
|
64
|
+
}
|
|
65
|
+
await sleep(1000);
|
|
66
|
+
console.log(' Cleanup complete.\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log(`Running: ${displayCommand}\n`);
|
|
70
|
+
console.log(HR);
|
|
71
|
+
const installRes = spawnSync(NPM_BIN, ['i', '-g', installSpec], {
|
|
72
|
+
cwd: safeCwd,
|
|
73
|
+
stdio: 'inherit',
|
|
74
|
+
shell: isWin,
|
|
75
|
+
});
|
|
76
|
+
console.log(HR);
|
|
77
|
+
|
|
78
|
+
if (installRes.error) throw installRes.error;
|
|
79
|
+
if (installRes.status !== 0) {
|
|
80
|
+
console.error(`\nnpm update command failed with exit code ${installRes.status}.\n`);
|
|
81
|
+
printFixTips(displayCommand);
|
|
82
|
+
await maybeHoldOpen(noHold);
|
|
83
|
+
process.exit(installRes.status || 1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(`\nSynaBun update installed.\n`);
|
|
87
|
+
|
|
88
|
+
if (autoRestart) {
|
|
89
|
+
console.log('Relaunching SynaBun...\n');
|
|
90
|
+
const child = spawn(isWin ? 'synabun.cmd' : 'synabun', [], {
|
|
91
|
+
cwd: safeCwd,
|
|
92
|
+
detached: true,
|
|
93
|
+
stdio: 'ignore',
|
|
94
|
+
shell: isWin,
|
|
95
|
+
});
|
|
96
|
+
child.unref();
|
|
97
|
+
console.log(' synabun launched (detached).\n');
|
|
98
|
+
} else {
|
|
99
|
+
console.log('Run "synabun" to start the new version.\n');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
await maybeHoldOpen(noHold);
|
|
103
|
+
process.exit(0);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
console.error(`\nUpdate failed: ${err.message}\n`);
|
|
106
|
+
printFixTips(displayCommand);
|
|
107
|
+
await maybeHoldOpen(noHold);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseArgs(argv) {
|
|
112
|
+
const out = {};
|
|
113
|
+
for (let i = 0; i < argv.length; i++) {
|
|
114
|
+
const a = argv[i];
|
|
115
|
+
if (!a.startsWith('--')) continue;
|
|
116
|
+
const key = a.slice(2);
|
|
117
|
+
const next = argv[i + 1];
|
|
118
|
+
if (next == null || next.startsWith('--')) {
|
|
119
|
+
out[key] = true;
|
|
120
|
+
} else {
|
|
121
|
+
out[key] = next;
|
|
122
|
+
i++;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function loadPayload(path) {
|
|
129
|
+
if (!path) return {};
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
132
|
+
} catch (err) {
|
|
133
|
+
throw new Error(`Could not read update payload: ${err.message}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function sanitizeTag(raw) {
|
|
138
|
+
const allowed = new Set(['latest', 'beta', 'next', 'rc', 'alpha']);
|
|
139
|
+
const t = String(raw || '').replace(/[^a-zA-Z0-9_.-]/g, '');
|
|
140
|
+
return allowed.has(t) ? t : 'latest';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function sanitizeInstallSpec(raw) {
|
|
144
|
+
const spec = String(raw || '').trim();
|
|
145
|
+
if (/^synabun@(latest|beta|next|rc|alpha)$/.test(spec)) return spec;
|
|
146
|
+
if (/^synabun@\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(spec)) return spec;
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function toPid(raw) {
|
|
151
|
+
const pid = Number(raw);
|
|
152
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function sanitizePidList(raw) {
|
|
156
|
+
if (!Array.isArray(raw)) return [];
|
|
157
|
+
const out = [];
|
|
158
|
+
const seen = new Set();
|
|
159
|
+
for (const item of raw) {
|
|
160
|
+
const pid = toPid(item);
|
|
161
|
+
if (!pid || seen.has(pid)) continue;
|
|
162
|
+
seen.add(pid);
|
|
163
|
+
out.push(pid);
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function waitForExit(pid, timeoutMs) {
|
|
169
|
+
const deadline = Date.now() + timeoutMs;
|
|
170
|
+
while (Date.now() < deadline) {
|
|
171
|
+
if (!isPidAlive(pid)) return true;
|
|
172
|
+
await sleep(250);
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isPidAlive(pid) {
|
|
178
|
+
try {
|
|
179
|
+
process.kill(pid, 0);
|
|
180
|
+
return true;
|
|
181
|
+
} catch (e) {
|
|
182
|
+
return e.code === 'EPERM';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function forceKillTree(pid) {
|
|
187
|
+
try {
|
|
188
|
+
if (isWin) {
|
|
189
|
+
spawnSync('taskkill', ['/pid', String(pid), '/T', '/F'], {
|
|
190
|
+
shell: true,
|
|
191
|
+
windowsHide: true,
|
|
192
|
+
stdio: 'ignore',
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
try { spawnSync('pkill', ['-P', String(pid)], { stdio: 'ignore' }); } catch {}
|
|
196
|
+
try { process.kill(pid, 'SIGKILL'); } catch {}
|
|
197
|
+
}
|
|
198
|
+
} catch {}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function forceKillPid(pid) {
|
|
202
|
+
try {
|
|
203
|
+
if (isWin) {
|
|
204
|
+
spawnSync('taskkill', ['/pid', String(pid), '/F'], {
|
|
205
|
+
shell: true,
|
|
206
|
+
windowsHide: true,
|
|
207
|
+
stdio: 'ignore',
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
try { process.kill(pid, 'SIGKILL'); } catch {}
|
|
211
|
+
}
|
|
212
|
+
} catch {}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function printFixTips(command) {
|
|
216
|
+
console.error('Common fixes:');
|
|
217
|
+
if (isWin) {
|
|
218
|
+
console.error(' EBUSY/EPERM: close other SynaBun terminals/windows, then retry.');
|
|
219
|
+
console.error(' Run as admin: right-click cmd -> "Run as administrator", then retry.');
|
|
220
|
+
console.error(' Force kill: taskkill /F /IM node.exe (warning: kills all node processes)');
|
|
221
|
+
} else {
|
|
222
|
+
console.error(' EACCES: re-run with sudo, or fix global npm prefix permissions.');
|
|
223
|
+
console.error(' Stale lock: rm -rf ~/.npm/_locks/*');
|
|
224
|
+
}
|
|
225
|
+
console.error(' Cache: npm cache clean --force');
|
|
226
|
+
console.error(`\nManual retry: ${command}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function sleep(ms) {
|
|
230
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function maybeHoldOpen(skip) {
|
|
234
|
+
if (skip) return Promise.resolve();
|
|
235
|
+
return new Promise(resolve => {
|
|
236
|
+
console.log('\n[Press Enter to close this window]');
|
|
237
|
+
try {
|
|
238
|
+
process.stdin.setEncoding('utf8');
|
|
239
|
+
process.stdin.resume();
|
|
240
|
+
process.stdin.once('data', () => resolve());
|
|
241
|
+
} catch {
|
|
242
|
+
setTimeout(resolve, 30000);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
package/updater.sh
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ───────────────────────────────────────────────────────
|
|
3
|
+
# Unix shim for the cross-platform updater (updater.mjs).
|
|
4
|
+
# Invoked by the running SynaBun server inside a fresh
|
|
5
|
+
# terminal window — keeps the terminal open after node
|
|
6
|
+
# exits so the user can read npm output and any errors.
|
|
7
|
+
# ───────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
set +e
|
|
10
|
+
|
|
11
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
12
|
+
NODE_BIN="${SYNABUN_NODE_BIN:-node}"
|
|
13
|
+
|
|
14
|
+
# Pretty terminal title (no-op in some terminals).
|
|
15
|
+
printf '\033]0;SynaBun Updater\007' 2>/dev/null || true
|
|
16
|
+
|
|
17
|
+
"$NODE_BIN" "$SCRIPT_DIR/updater.mjs" "$@" --no-hold
|
|
18
|
+
EXIT_CODE=$?
|
|
19
|
+
|
|
20
|
+
echo
|
|
21
|
+
if [ "$EXIT_CODE" = "0" ]; then
|
|
22
|
+
echo "[Update finished. Press Enter to close this window.]"
|
|
23
|
+
else
|
|
24
|
+
echo "[Update exited with code $EXIT_CODE. Press Enter to close this window.]"
|
|
25
|
+
fi
|
|
26
|
+
# Read one line. If stdin is closed (e.g. piped run), fall through immediately.
|
|
27
|
+
read -r _ || true
|
|
28
|
+
|
|
29
|
+
exit $EXIT_CODE
|