claude-rpc 1.7.4 → 1.9.0
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/README.md +5 -4
- package/SECURITY.md +20 -0
- package/package.json +1 -1
- package/src/cli.js +153 -48
- package/src/commands.js +1 -0
- package/src/community.js +36 -2
- package/src/config-edit.js +59 -0
- package/src/daemon.js +120 -30
- package/src/doctor.js +23 -1
- package/src/ensure-daemon.js +155 -8
- package/src/install.js +19 -2
- package/src/paths.js +9 -0
- package/src/server/assets/dashboard.html +1 -0
- package/src/server/assets/settings.client.js +422 -0
- package/src/server/assets/settings.css +145 -0
- package/src/server/assets/settings.html +176 -0
- package/src/server/index.js +67 -16
- package/src/server/page.js +17 -3
- package/src/server/routes.js +16 -0
- package/src/server/settings.js +227 -0
- package/src/tui.js +3 -2
- package/src/updater.js +29 -6
- package/src/version.js +1 -1
package/src/updater.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
//
|
|
11
11
|
// Pure decision functions up top (unit-tested); side effects below.
|
|
12
12
|
|
|
13
|
-
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
13
|
+
import { readFileSync, writeFileSync, mkdirSync, accessSync, constants as fsConstants } from 'node:fs';
|
|
14
14
|
import { join, dirname, delimiter } from 'node:path';
|
|
15
15
|
import { STATE_DIR, ROOT, IS_PACKAGED, IS_NPM_INSTALL, IS_NPX } from './paths.js';
|
|
16
16
|
|
|
@@ -61,10 +61,13 @@ export function updateCommand(kind) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// → { action: 'none' | 'notify' | 'install', reason }
|
|
64
|
-
export function planUpdate({ current, latest, auto = true, kind, failed = null, seen = null, cooldownMs = COOLDOWN_MS, now = Date.now() }) {
|
|
64
|
+
export function planUpdate({ current, latest, auto = true, kind, writable = true, failed = null, seen = null, cooldownMs = COOLDOWN_MS, now = Date.now() }) {
|
|
65
65
|
if (!isNewer(latest, current)) return { action: 'none', reason: 'up to date' };
|
|
66
66
|
if (kind !== 'npm-global') return { action: 'notify', reason: `installed via ${kind}` };
|
|
67
67
|
if (!auto) return { action: 'notify', reason: 'auto-update is off' };
|
|
68
|
+
// A root-owned global (system node, `sudo npm i -g`) fails with EACCES every
|
|
69
|
+
// single attempt — say so once instead of failing silently every day.
|
|
70
|
+
if (!writable) return { action: 'notify', reason: 'the global npm folder needs admin rights — update manually' };
|
|
68
71
|
if (!sameMajor(latest, current)) return { action: 'notify', reason: 'new major version — update manually' };
|
|
69
72
|
if (failed && failed.version === latest && now - failed.at < RETRY_FAILED_MS) {
|
|
70
73
|
return { action: 'notify', reason: 'last install attempt failed — retrying later' };
|
|
@@ -118,9 +121,24 @@ export async function installVersion(version) {
|
|
|
118
121
|
});
|
|
119
122
|
}
|
|
120
123
|
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
export
|
|
124
|
+
// Can this process replace its own package? (npm writes the new copy into the
|
|
125
|
+
// folder that holds ours: …/lib/node_modules on POSIX, %AppData%\npm\node_modules.)
|
|
126
|
+
export function installDirWritable(root = ROOT) {
|
|
127
|
+
try { accessSync(dirname(root), fsConstants.W_OK); return true; } catch { return false; }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// The version now on disk where THIS copy lives. npm exiting 0 doesn't mean it
|
|
131
|
+
// replaced us: with a different npm prefix (volta, pnpm/yarn/bun globals, a
|
|
132
|
+
// changed `npm config prefix`) it installs somewhere else, the restart comes
|
|
133
|
+
// back up on the old code, and the daemon reinstalled again every 5 minutes.
|
|
134
|
+
export function installedVersion(root = ROOT) {
|
|
135
|
+
try { return JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version || null; } catch { return null; }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// One check cycle. Returns { plan, latest, installed }. `install`, `verify`
|
|
139
|
+
// and `writable` are injectable for tests; callers restart the daemon when
|
|
140
|
+
// `installed` is true.
|
|
141
|
+
export async function checkForUpdate({ current, auto, kind = installKind(), fetchLatestFn = fetchLatest, install = installVersion, verify = (v) => installedVersion() === v, writable = installDirWritable, now = Date.now(), cooldownMs = COOLDOWN_MS, statePath = UPDATE_STATE_PATH } = {}) {
|
|
124
142
|
const latest = await fetchLatestFn();
|
|
125
143
|
writeUpdateState({ checkedAt: now, ...(latest ? { latest } : {}) }, statePath);
|
|
126
144
|
if (!latest) return { plan: { action: 'none', reason: 'registry unreachable' }, latest: null, installed: false };
|
|
@@ -129,9 +147,14 @@ export async function checkForUpdate({ current, auto, kind = installKind(), fetc
|
|
|
129
147
|
writeUpdateState({ seen: { version: latest, at: now } }, statePath);
|
|
130
148
|
state = readUpdateState(statePath);
|
|
131
149
|
}
|
|
132
|
-
const plan = planUpdate({ current, latest, auto, kind, failed: state.failed || null, seen: state.seen || null, cooldownMs, now });
|
|
150
|
+
const plan = planUpdate({ current, latest, auto, kind, writable: kind === 'npm-global' ? writable() : true, failed: state.failed || null, seen: state.seen || null, cooldownMs, now });
|
|
151
|
+
writeUpdateState({ lastPlan: { action: plan.action, reason: plan.reason, latest, at: now } }, statePath);
|
|
133
152
|
if (plan.action !== 'install') return { plan, latest, installed: false };
|
|
134
153
|
const res = await install(latest);
|
|
154
|
+
if (res.ok && !verify(latest)) {
|
|
155
|
+
res.ok = false;
|
|
156
|
+
res.output = `npm reported success but this copy (${ROOT}) is still v${current} — npm installs its globals somewhere else here (npm prefix / volta / pnpm). Update with the tool that installed claude-rpc.`;
|
|
157
|
+
}
|
|
135
158
|
if (res.ok) {
|
|
136
159
|
writeUpdateState({ updatedFrom: current, updatedTo: latest, updatedAt: now, failed: null }, statePath);
|
|
137
160
|
return { plan, latest, installed: true };
|