webhelm 1.0.43 → 1.0.45
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 +9 -2
- package/package.json +1 -1
- package/runtime/auto-update.mjs +42 -6
- package/runtime/cli-help.mjs +2 -2
- package/runtime/cli.mjs +8 -3
- package/runtime/extension/manifest.json +1 -1
- package/runtime/login-guard.mjs +19 -0
package/README.md
CHANGED
|
@@ -58,13 +58,20 @@ new daemon against the existing Chrome/profile/queue, and verifies its version.
|
|
|
58
58
|
A busy daemon returns `deferred` and retries on the next scheduled run. A failed
|
|
59
59
|
installation reverts the pointer and resumes the old queue. Unavailable npm or
|
|
60
60
|
unrecognized old daemon upgrade protocols fail closed rather than killing a
|
|
61
|
-
Session.
|
|
61
|
+
Session. For a one-time manual migration, `webhelm upgrade --force` verifies
|
|
62
|
+
the daemon PID/lock and sends SIGTERM before starting the new Runtime.
|
|
63
|
+
This bypasses idle checks and may interrupt active Sessions or running queue
|
|
64
|
+
workers; it does not deliberately restart Chrome. The scheduled updater
|
|
65
|
+
never uses `--force`. The update log is at
|
|
66
|
+
`~/.config/webhelm/runtime/auto-update.log`.
|
|
62
67
|
|
|
63
68
|
Neo Master uses `WEBHELM_SOURCE_MODE=1` and runs its linked Git checkout, not
|
|
64
69
|
a published npm package. Automatic npm updates are deliberately disabled
|
|
65
70
|
there; updating a development checkout is a separate, reviewed Git operation.
|
|
66
71
|
Existing npm installations need to run `webhelm setup` once after receiving
|
|
67
|
-
this release to register the updater LaunchAgent.
|
|
72
|
+
this release to register the updater LaunchAgent. The setup and updater also
|
|
73
|
+
migrate only legacy global CLI symlinks that target an owned immutable
|
|
74
|
+
`runtime-VERSION/bin/webhelm.mjs` into the stable Runtime link.
|
|
68
75
|
|
|
69
76
|
## WebHelm Chrome Extension control panel
|
|
70
77
|
|
package/package.json
CHANGED
package/runtime/auto-update.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import {execFileSync} from 'node:child_process';
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
6
|
import {request} from './node-daemon.mjs';
|
|
7
|
-
import {activateRuntime,currentRuntimePath,installLoginGuard,installRuntimeUpdate,stageRuntimeForLoginGuard} from './login-guard.mjs';
|
|
7
|
+
import {activateRuntime,currentRuntimePath,installLoginGuard,installRuntimeUpdate,migrateLegacyRuntimeCli,stageRuntimeForLoginGuard} from './login-guard.mjs';
|
|
8
8
|
|
|
9
9
|
const REGISTRY='https://registry.npmjs.org';
|
|
10
10
|
const SOURCE=fileURLToPath(new URL('../',import.meta.url));
|
|
@@ -77,12 +77,39 @@ function acquireLock(home) {
|
|
|
77
77
|
return null;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
// Explicit --force only. Verify the PID against the local daemon lock and
|
|
81
|
+
// live IPC identity before sending SIGTERM. Never signal managed Chrome.
|
|
82
|
+
export async function forceStopDaemon(daemon,{home=os.homedir(),ipc=req=>request(req,false),
|
|
83
|
+
lockPath=process.env.WEBHELM_LOCK||path.join(home,'.config/webhelm/runtime/session-node.lock'),
|
|
84
|
+
signal=process.kill,inspect=pid=>execFileSync('ps',['-p',String(pid),'-o','command='],
|
|
85
|
+
{encoding:'utf8',timeout:5000}),timeoutMs=30000}={}) {
|
|
86
|
+
const pid=daemon?.pid;
|
|
87
|
+
if(!Number.isSafeInteger(pid)||pid<=1||pid===process.pid)
|
|
88
|
+
throw Error('Refusing forced upgrade: invalid daemon PID');
|
|
89
|
+
const owner=Number(fs.readFileSync(lockPath,'utf8').trim());
|
|
90
|
+
if(owner!==pid)throw Error('Refusing forced upgrade: daemon lock PID mismatch');
|
|
91
|
+
const command=await inspect(pid);
|
|
92
|
+
if(!/node-daemon\.mjs\s+daemon(?:\s|$)/.test(command))
|
|
93
|
+
throw Error('Refusing forced upgrade: PID is not a WebHelm daemon');
|
|
94
|
+
const live=await ipc({op:'ping'});
|
|
95
|
+
if(live?.pid!==pid||live.version!==daemon.version)
|
|
96
|
+
throw Error('Refusing forced upgrade: daemon identity changed');
|
|
97
|
+
signal(pid,'SIGTERM');
|
|
98
|
+
const deadline=Date.now()+timeoutMs;
|
|
99
|
+
while(Date.now()<deadline){
|
|
100
|
+
// Lock removal follows shutdown cleanup, including queue worker teardown.
|
|
101
|
+
if(!fs.existsSync(lockPath))return {stopping:true,stopped:true,pid};
|
|
102
|
+
await sleep(100);
|
|
103
|
+
}
|
|
104
|
+
return {stopping:true,stopped:false,pid};
|
|
105
|
+
}
|
|
106
|
+
|
|
80
107
|
// Inject ports for isolated tests. Production never imports npm code or
|
|
81
108
|
// touches another Chrome profile to decide whether to upgrade.
|
|
82
109
|
export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=process.execPath,
|
|
83
110
|
latest=npmLatest,download=downloadRuntime,ipc=req=>request(req,false),
|
|
84
111
|
installGuard=installLoginGuard,installPoller=installRuntimeUpdate,
|
|
85
|
-
activate=activateRuntime,verify=null,apply=true}={}) {
|
|
112
|
+
activate=activateRuntime,verify=null,restart=forceStopDaemon,apply=true,force=false}={}) {
|
|
86
113
|
if(process.env.WEBHELM_SOURCE_MODE==='1')return {status:'source_checkout',upgraded:false};
|
|
87
114
|
const unlock=acquireLock(home);
|
|
88
115
|
if(!unlock)return {status:'already_running',upgraded:false};
|
|
@@ -100,11 +127,11 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
|
|
|
100
127
|
const upToDate=daemon?.version===target && currentTarget &&
|
|
101
128
|
fs.existsSync(path.join(currentTarget,'package.json')) &&
|
|
102
129
|
JSON.parse(fs.readFileSync(path.join(currentTarget,'package.json'),'utf8')).version===target;
|
|
103
|
-
if(upToDate)return {status:'current',upgraded:false,version:target};
|
|
130
|
+
if(upToDate&&!force)return {status:'current',upgraded:false,version:target,global_cli:migrateLegacyRuntimeCli({home})};
|
|
104
131
|
// Stage before requesting the daemon to drain; download may take time.
|
|
105
132
|
const staged=compareVersions(target,local)>0
|
|
106
133
|
? await download(target,{home}) : stageRuntimeForLoginGuard({home,source});
|
|
107
|
-
if(daemon && compareVersions(daemon.version,target)<0){
|
|
134
|
+
if(!force && daemon && compareVersions(daemon.version,target)<0){
|
|
108
135
|
let gate;
|
|
109
136
|
try{gate=await ipc({op:'upgrade-prepare'});}
|
|
110
137
|
catch(error){return {status:'deferred',upgraded:false,reason:'daemon_upgrade_protocol_unavailable',detail:error.message,latest:target};}
|
|
@@ -113,12 +140,20 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
|
|
|
113
140
|
}
|
|
114
141
|
prior=currentTarget;
|
|
115
142
|
activate(staged.path,{home});switched=true;
|
|
143
|
+
const global_cli=migrateLegacyRuntimeCli({home});
|
|
116
144
|
const cliPath=path.join(current,'bin/webhelm.mjs');
|
|
117
145
|
const guard=installGuard({home,cliPath,nodePath,apply});
|
|
118
146
|
const poller=installPoller({home,cliPath,nodePath,apply});
|
|
119
147
|
if(['staged_not_loaded','skipped'].includes(guard.status)||
|
|
120
148
|
['staged_not_loaded','skipped'].includes(poller.status))throw Error('Runtime LaunchAgent activation failed');
|
|
121
|
-
if(
|
|
149
|
+
if(force && daemon){
|
|
150
|
+
const stopped=await restart(daemon,{home,ipc});
|
|
151
|
+
if(!stopped?.stopping)throw Error('Forced daemon restart was not accepted');
|
|
152
|
+
committed=true;
|
|
153
|
+
if(!stopped.stopped)return {status:'deferred',upgraded:false,
|
|
154
|
+
reason:'daemon_shutdown_timeout',daemon_pid:daemon.pid,latest:target,
|
|
155
|
+
forced:true,warning:'SIGTERM sent; runtime pointer updated but daemon has not completed shutdown'};
|
|
156
|
+
}else if(prepared){
|
|
122
157
|
const result=await ipc({op:'upgrade-commit'});
|
|
123
158
|
if(!result?.stopping)throw Error('Daemon did not accept Runtime cutover');
|
|
124
159
|
prepared=false;committed=true;
|
|
@@ -136,7 +171,8 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
|
|
|
136
171
|
const state=await run();
|
|
137
172
|
if(state.version!==target)throw Error(`Cutover verification failed: ${state.version} !== ${target}`);
|
|
138
173
|
return {status:'upgraded',upgraded:true,from:daemon?.version||null,to:target,
|
|
139
|
-
daemon_pid:state.daemon?.pid||null,guard:guard.status,auto_update:poller.status
|
|
174
|
+
daemon_pid:state.daemon?.pid||null,global_cli,guard:guard.status,auto_update:poller.status,
|
|
175
|
+
...(force?{forced:true,sessions_before_restart:daemon?.session_count??null}:{})};
|
|
140
176
|
}catch(error){
|
|
141
177
|
// Never point new clients at an old Runtime after a committed daemon
|
|
142
178
|
// cutover: the new daemon may already be serving requests.
|
package/runtime/cli-help.mjs
CHANGED
|
@@ -13,7 +13,7 @@ Commands:
|
|
|
13
13
|
webhelm setup Set up managed Chrome and local Actions
|
|
14
14
|
webhelm status Report browser and daemon status (JSON)
|
|
15
15
|
webhelm ensure Check and recover managed Chrome health
|
|
16
|
-
webhelm upgrade
|
|
16
|
+
webhelm upgrade [--force] Check npm and upgrade the Runtime
|
|
17
17
|
webhelm capacity Report available browser capacity (JSON)
|
|
18
18
|
webhelm session start [--url URL] Start a persistent browser Session
|
|
19
19
|
webhelm session list List CLI-owned Sessions
|
|
@@ -56,7 +56,7 @@ Output: JSON with status, Actions checkout path, daemon and browser details.
|
|
|
56
56
|
|
|
57
57
|
Example:
|
|
58
58
|
webhelm setup`,
|
|
59
|
-
upgrade: `webhelm upgrade — update the npm Runtime when safely idle\n\nUsage:\n webhelm upgrade\n\nChecks npm once. Stages newer Runtime without executing install scripts.\nCutover waits until all Sessions and in-flight queue workers are idle;\notherwise reports deferred and retries on the next hourly LaunchAgent run.\nNever updates a source-mode checkout or restarts
|
|
59
|
+
upgrade: `webhelm upgrade — update the npm Runtime when safely idle\n\nUsage:\n webhelm upgrade [--force]\n\nChecks npm once. Stages newer Runtime without executing install scripts.\nCutover waits until all Sessions and in-flight queue workers are idle;\notherwise reports deferred and retries on the next hourly LaunchAgent run.\nOld daemons without the upgrade protocol defer safely.\n--force bypasses idle checks and sends SIGTERM to the verified WebHelm\ndaemon (including legacy versions), which is then restarted.\nActive Sessions and in-flight queue work may be interrupted.\nThe hourly updater never uses --force.\nNever updates a source-mode checkout or deliberately restarts Chrome.\n\nOutput: JSON current, upgraded, deferred, or source_checkout.`,
|
|
60
60
|
status: `webhelm status — inspect managed browser and daemon
|
|
61
61
|
|
|
62
62
|
Usage:
|
package/runtime/cli.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
7
7
|
import { ensureDaemon, request, SOCKET } from './node-daemon.mjs';
|
|
8
8
|
import { PLATFORMS, listPlatforms, platformProfile, actionPath, validateConfig } from './platforms.mjs';
|
|
9
9
|
import { ACTIONS_DIR, ensureActions, syncActions, publishActions } from './actions-repo.mjs';
|
|
10
|
-
import { activateRuntime, currentRuntimePath, installLoginGuard, installRuntimeUpdate, stageRuntimeForLoginGuard } from './login-guard.mjs';
|
|
10
|
+
import { activateRuntime, currentRuntimePath, installLoginGuard, installRuntimeUpdate, migrateLegacyRuntimeCli, stageRuntimeForLoginGuard } from './login-guard.mjs';
|
|
11
11
|
import { upgradeRuntime } from './auto-update.mjs';
|
|
12
12
|
import { cliHelp } from './cli-help.mjs';
|
|
13
13
|
|
|
@@ -113,11 +113,16 @@ async function main(args = process.argv.slice(2)) {
|
|
|
113
113
|
const cliPath=sourceMode
|
|
114
114
|
? fileURLToPath(new URL('../bin/webhelm.mjs',import.meta.url))
|
|
115
115
|
: path.join(currentRuntimePath(),'bin/webhelm.mjs');
|
|
116
|
+
const global_cli=sourceMode?{status:'source_checkout'}:migrateLegacyRuntimeCli();
|
|
116
117
|
const login_guard=installLoginGuard({cliPath,nodePath:process.execPath,sourceMode});
|
|
117
118
|
const auto_update=installRuntimeUpdate({cliPath,nodePath:process.execPath,sourceMode});
|
|
118
|
-
return emit({status:'ready',...repo,daemon_pid:chrome.pid,managed_chrome:chrome.managed_chrome,login_guard,auto_update});
|
|
119
|
+
return emit({status:'ready',...repo,daemon_pid:chrome.pid,managed_chrome:chrome.managed_chrome,global_cli,login_guard,auto_update});
|
|
120
|
+
}
|
|
121
|
+
if (group === 'upgrade') {
|
|
122
|
+
if(args.some(value=>value!=='upgrade'&&value!=='--force'))
|
|
123
|
+
throw Error('upgrade supports only --force');
|
|
124
|
+
return emit(await upgradeRuntime({force:has(args,'--force')}));
|
|
119
125
|
}
|
|
120
|
-
if (group === 'upgrade') return emit(await upgradeRuntime());
|
|
121
126
|
if (group === 'ensure') {
|
|
122
127
|
try { return emit(await request({op:'guard-check'})); }
|
|
123
128
|
catch(error) {
|
package/runtime/login-guard.mjs
CHANGED
|
@@ -140,3 +140,22 @@ export function activateRuntime(stagedPath,{home=os.homedir()}={}) {
|
|
|
140
140
|
try{fs.renameSync(temp,current);}finally{if(fs.existsSync(temp))fs.unlinkSync(temp);}
|
|
141
141
|
return {path:current,updated:true};
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
// Pre-updater installations may have pointed ~/.local/bin/webhelm directly
|
|
145
|
+
// at an immutable runtime-VERSION snapshot. Migrate ONLY this owned pattern;
|
|
146
|
+
// preserve Skill launchers, unmanaged binaries and other symlinks.
|
|
147
|
+
export function migrateLegacyRuntimeCli({home=os.homedir()}={}) {
|
|
148
|
+
const link=path.join(home,'.local/bin/webhelm');
|
|
149
|
+
const stable=path.join(currentRuntimePath(home),'bin/webhelm.mjs');
|
|
150
|
+
if(!fs.existsSync(stable))return {status:'skipped',reason:'stable_runtime_missing'};
|
|
151
|
+
try{if(!fs.lstatSync(link).isSymbolicLink())return {status:'preserved',reason:'unmanaged_cli'};}
|
|
152
|
+
catch(error){if(error.code==='ENOENT')return {status:'skipped',reason:'no_existing_cli'};throw error;}
|
|
153
|
+
const resolved=path.resolve(path.dirname(link),fs.readlinkSync(link));
|
|
154
|
+
const relative=path.relative(path.join(home,'.local/share/webhelm'),resolved).split(path.sep).join('/');
|
|
155
|
+
if(!/^runtime-\d+\.\d+\.\d+\/bin\/webhelm\.mjs$/.test(relative))
|
|
156
|
+
return {status:'preserved',reason:'not_a_versioned_runtime_link'};
|
|
157
|
+
const tmp=`${link}.${process.pid}.${Date.now()}.tmp`;
|
|
158
|
+
fs.symlinkSync(stable,tmp);
|
|
159
|
+
try{fs.renameSync(tmp,link);}finally{if(fs.existsSync(tmp))fs.unlinkSync(tmp);}
|
|
160
|
+
return {status:'migrated',path:link,target:stable};
|
|
161
|
+
}
|