webhelm 1.0.31 → 1.0.33
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 +1 -1
- package/package.json +1 -1
- package/runtime/chrome.mjs +2 -2
- package/runtime/cli-help.mjs +0 -12
- package/runtime/cli.mjs +0 -7
- package/runtime/config-paths.mjs +3 -6
- package/runtime/extension/manifest.json +1 -1
- package/runtime/extension/popup-data.mjs +73 -0
- package/runtime/extension/popup.html +8 -1
- package/runtime/extension/popup.mjs +95 -53
- package/runtime/extension-manager.mjs +1 -1
- package/runtime/node-daemon.mjs +2 -2
- package/runtime/migrate.mjs +0 -80
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ The Platform Action implementation and its verification belong in
|
|
|
88
88
|
|
|
89
89
|
## Architecture and compatibility
|
|
90
90
|
|
|
91
|
-
The Runtime stores
|
|
91
|
+
The Runtime stores the Chrome profile under `~/.local/webhelm/chrome` and the persistent FIFO queue and IPC socket under `~/.config/webhelm/runtime/`. The runtime refuses to start against a conflicting Chrome profile rather than silently replacing an existing login. Session idle GC runs on Node before new Session allocation (5 minutes without operations or explicit heartbeat); no background sweep is started. A timed-out Session refuses subsequent exec, platform Actions and heartbeat, while already-issued browser effects retain tab ownership until settled. A stop that times out while queued cannot execute a late release, and a stop already physically releasing keeps its Session closing until the release finishes. Managed tabs are navigated back to their Extension idle URL instead of closing CDP targets; the Extension does not use `tab.lastAccessed` GC. An async Session execution has a finite deadline: if it expires, its helper capabilities are revoked and the poisoned Session is collected on the next Tab request (or immediately by an explicit stop). Session stop also has a bounded drain/release deadline and cannot leave a permanent closing flag. Client IPC requests have an independent absolute timeout and return an error if the daemon does not respond. These safeguards do not introduce periodic background GC. Only one daemon is permitted to own the queue. A CLI package update does not kill a running daemon or close another agent's tabs; upgrade daemons when idle.
|
|
92
92
|
|
|
93
93
|
NeoY and Relay can continue using `webhelm` session commands, `result.stdout` JSON receipts, and `admin_helper` returned by `status`. An `admin_helper` inside the installed Skill is a stable connector to the same Node IPC socket. `webhelm capacity` replaces the legacy Python capacity probe.
|
|
94
94
|
|
package/package.json
CHANGED
package/runtime/chrome.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import net from 'node:net';
|
|
4
4
|
import { spawn, execFileSync } from 'node:child_process';
|
|
5
5
|
|
|
6
|
-
import { CONFIG_ROOT, PROFILE_DIR, OLD_PROFILE_DIR,
|
|
6
|
+
import { CONFIG_ROOT, PROFILE_DIR, OLD_PROFILE_DIR, assertProfileConsistency } from './config-paths.mjs';
|
|
7
7
|
import { stageExtension } from './extension-manager.mjs';
|
|
8
8
|
const ROOT = CONFIG_ROOT;
|
|
9
9
|
const PROFILE = PROFILE_DIR;
|
|
@@ -122,7 +122,7 @@ export async function ensureManagedChrome(){
|
|
|
122
122
|
// Explicit CDP endpoints also support hermetic mock-browser tests.
|
|
123
123
|
const specified=process.env.WEBHELM_CDP_URL;
|
|
124
124
|
if (specified) return {mode:'override',reused:true,endpoint:specified,profile_dir:PROFILE};
|
|
125
|
-
|
|
125
|
+
assertProfileConsistency();
|
|
126
126
|
return lockOwnership(async()=>{
|
|
127
127
|
const existing=await fromState()||await discover();
|
|
128
128
|
if(existing)return {...existing, mode:'managed',reused:true,endpoint:`http://127.0.0.1:${existing.port}`};
|
package/runtime/cli-help.mjs
CHANGED
|
@@ -25,7 +25,6 @@ Commands:
|
|
|
25
25
|
webhelm platform run NAME ACTION [...] Execute an installed site Action
|
|
26
26
|
webhelm platform sync Update installed site Actions
|
|
27
27
|
webhelm platform publish --message MSG Publish reviewed site Action changes
|
|
28
|
-
webhelm migrate Migrate supported legacy local browser data
|
|
29
28
|
webhelm help [command [subcommand]] Show command help
|
|
30
29
|
Options:
|
|
31
30
|
-h, --help Show help without running the command
|
|
@@ -87,17 +86,6 @@ Output: JSON capacity information.
|
|
|
87
86
|
|
|
88
87
|
Example:
|
|
89
88
|
webhelm capacity`,
|
|
90
|
-
migrate: `webhelm migrate — migrate supported legacy local browser data
|
|
91
|
-
|
|
92
|
-
Usage:
|
|
93
|
-
webhelm migrate
|
|
94
|
-
|
|
95
|
-
Run only after stopping the legacy daemon and browser and draining Sessions.
|
|
96
|
-
Preserves the signed-in browser profile and supported local state.
|
|
97
|
-
Output: JSON with migration results.
|
|
98
|
-
|
|
99
|
-
Example:
|
|
100
|
-
webhelm migrate`,
|
|
101
89
|
session: `webhelm session — manage persistent JavaScript browser Sessions
|
|
102
90
|
|
|
103
91
|
Usage:
|
package/runtime/cli.mjs
CHANGED
|
@@ -7,7 +7,6 @@ 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 { migrateConfig, migrateChromeProfile } from './migrate.mjs';
|
|
11
10
|
import { installLoginGuard, stageRuntimeForLoginGuard } from './login-guard.mjs';
|
|
12
11
|
import { cliHelp } from './cli-help.mjs';
|
|
13
12
|
|
|
@@ -105,12 +104,6 @@ async function main(args = process.argv.slice(2)) {
|
|
|
105
104
|
return console.log(cliHelp(topics));
|
|
106
105
|
}
|
|
107
106
|
rejectWorkspaceOverride(args);
|
|
108
|
-
if (group === 'migrate') {
|
|
109
|
-
await ensureActions(); // ~/.local/webhelm is the Actions Git checkout, never create an empty replacement.
|
|
110
|
-
const legacy=await migrateConfig();
|
|
111
|
-
const chrome=await migrateChromeProfile();
|
|
112
|
-
return emit({legacy,chrome});
|
|
113
|
-
}
|
|
114
107
|
if (group === 'setup') {
|
|
115
108
|
const repo=await ensureActions();
|
|
116
109
|
const chrome=await ensureDaemon();
|
package/runtime/config-paths.mjs
CHANGED
|
@@ -3,18 +3,15 @@ import path from 'node:path';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
|
|
5
5
|
export const CONFIG_ROOT = path.resolve(process.env.WEBHELM_CONFIG_ROOT || path.join(os.homedir(), '.config', 'webhelm'));
|
|
6
|
-
export const LEGACY_ROOT = path.resolve(process.env.WEBHELM_LEGACY_ROOT || (process.env.WEBHELM_CONFIG_ROOT ? path.join(CONFIG_ROOT,'legacy-browser-workspace') : path.join(os.homedir(), '.config', 'browser-workspace')));
|
|
7
6
|
export const LOCAL_ROOT = path.resolve(process.env.WEBHELM_LOCAL_ROOT || path.join(os.homedir(), '.local', 'webhelm'));
|
|
8
7
|
export const OLD_PROFILE_DIR = path.join(CONFIG_ROOT, 'chrome');
|
|
9
8
|
export const PROFILE_DIR = path.join(LOCAL_ROOT, 'chrome');
|
|
10
9
|
export const RUNTIME_DIR = path.join(CONFIG_ROOT, 'runtime');
|
|
11
10
|
|
|
12
|
-
//
|
|
13
|
-
export function
|
|
14
|
-
if (fs.existsSync(path.join(LEGACY_ROOT, 'chrome')) && !fs.existsSync(OLD_PROFILE_DIR) && !fs.existsSync(PROFILE_DIR))
|
|
15
|
-
throw Error(`Legacy Chrome profile exists at ${LEGACY_ROOT}. Stop old Chrome and WebHelm daemon, then run webhelm migrate.`);
|
|
11
|
+
// Refuse to start Chrome when the current WebHelm profile is not safely migrated.
|
|
12
|
+
export function assertProfileConsistency() {
|
|
16
13
|
if (fs.existsSync(OLD_PROFILE_DIR) && !fs.existsSync(PROFILE_DIR))
|
|
17
|
-
throw Error(`Chrome profile
|
|
14
|
+
throw Error(`WebHelm Chrome profile exists at ${OLD_PROFILE_DIR}, but ${PROFILE_DIR} is missing. Stop active Sessions, WebHelm daemon and Chrome before moving the profile to ${PROFILE_DIR}.`);
|
|
18
15
|
if (fs.existsSync(OLD_PROFILE_DIR) && fs.existsSync(PROFILE_DIR) &&
|
|
19
16
|
fs.realpathSync(OLD_PROFILE_DIR)!==fs.realpathSync(PROFILE_DIR))
|
|
20
17
|
throw Error('Two distinct WebHelm Chrome Profiles exist; refusing to use either until reconciled.');
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Pure display shaping. Keep pending work intact: folding never acknowledges,
|
|
2
|
+
// cancels, retries or removes an entry from the durable queue.
|
|
3
|
+
export const SITE_STORAGE_KEY = 'webhelm.keepalive.sites.v1';
|
|
4
|
+
export const SITE_STATUS_KEY = 'webhelm.keepalive.status.v1';
|
|
5
|
+
|
|
6
|
+
function validSite(site) {
|
|
7
|
+
if (!site || typeof site.id !== 'string' || site.id !== site.url || site.enabled !== true) return false;
|
|
8
|
+
try { const url = new URL(site.url); return url.protocol === 'https:' && url.origin === site.id; }
|
|
9
|
+
catch { return false; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function mergeKeptSites(persisted, statusById, reported) {
|
|
13
|
+
const sites = new Map();
|
|
14
|
+
for (const site of Array.isArray(persisted) ? persisted : []) {
|
|
15
|
+
if (validSite(site)) sites.set(site.id, {...site, status:statusById?.[site.id]?.status || 'pending'});
|
|
16
|
+
}
|
|
17
|
+
for (const site of Array.isArray(reported) ? reported : []) {
|
|
18
|
+
if (validSite(site)) sites.set(site.id, {...sites.get(site.id), ...site});
|
|
19
|
+
}
|
|
20
|
+
return [...sites.values()].sort((a,b)=>a.id.localeCompare(b.id));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function readKeptSites(chromeApi, reported) {
|
|
24
|
+
let persisted=[], statuses={};
|
|
25
|
+
try {
|
|
26
|
+
const stored=await chromeApi.storage.local.get(SITE_STORAGE_KEY);
|
|
27
|
+
persisted=stored[SITE_STORAGE_KEY];
|
|
28
|
+
const latest=await chromeApi.storage.session.get(SITE_STATUS_KEY);
|
|
29
|
+
statuses=latest[SITE_STATUS_KEY] || {};
|
|
30
|
+
} catch { /* Keep any site entries returned by the current service worker. */ }
|
|
31
|
+
return mergeKeptSites(persisted,statuses,reported);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function setStoredSite(chromeApi, url, enabled) {
|
|
35
|
+
const origin = new URL(url).origin;
|
|
36
|
+
if (!/^https:\/\//.test(origin)) throw Error('Keep Alive requires HTTPS');
|
|
37
|
+
const stored=await chromeApi.storage.local.get(SITE_STORAGE_KEY);
|
|
38
|
+
const current=Array.isArray(stored[SITE_STORAGE_KEY]) ? stored[SITE_STORAGE_KEY] : [];
|
|
39
|
+
const next=current.filter(site=>site?.id!==origin);
|
|
40
|
+
if (enabled) next.push({id:origin,url:origin,enabled:true,addedAt:Date.now(),revision:crypto.randomUUID()});
|
|
41
|
+
await chromeApi.storage.local.set({[SITE_STORAGE_KEY]: next.sort((a,b)=>a.id.localeCompare(b.id))});
|
|
42
|
+
if (!enabled) {
|
|
43
|
+
const storedStates=await chromeApi.storage.session.get(SITE_STATUS_KEY);
|
|
44
|
+
const states=storedStates[SITE_STATUS_KEY] || {};
|
|
45
|
+
delete states[origin];
|
|
46
|
+
await chromeApi.storage.session.set({[SITE_STATUS_KEY]:states});
|
|
47
|
+
}
|
|
48
|
+
return {id:origin,enabled:Boolean(enabled)};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const priority = {UNCERTAIN:0,BLOCKED:1,SENDING:2,CHECKING:2,WAITING:3,QUEUED:4};
|
|
52
|
+
function threadKey(item) {
|
|
53
|
+
// Old queue adapters might not identify threads; don't merge unrelated IDs.
|
|
54
|
+
return `${item.platform||'Queue'}\u0000${item.thread_id||item.id}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function compactQueue(items, {expanded=false,maxHeads=8}={}) {
|
|
58
|
+
const all=Array.isArray(items) ? items : [];
|
|
59
|
+
const threads=new Map();
|
|
60
|
+
for (const [index,item] of all.entries()) {
|
|
61
|
+
const key=threadKey(item);
|
|
62
|
+
if (!threads.has(key)) threads.set(key,{head:item,index,count:0});
|
|
63
|
+
threads.get(key).count++;
|
|
64
|
+
}
|
|
65
|
+
const heads=[...threads.values()].sort((a,b)=>
|
|
66
|
+
(priority[a.head.state]??5)-(priority[b.head.state]??5)||a.index-b.index);
|
|
67
|
+
const visible=expanded ? all : heads.slice(0,Math.max(1,maxHeads)).map(x=>x.head);
|
|
68
|
+
const behind=new Map(heads.map(x=>[x.head.id,x.count-1]));
|
|
69
|
+
const uncertain=all.filter(x=>x.state==='UNCERTAIN').length;
|
|
70
|
+
const blocked=all.filter(x=>x.state==='BLOCKED').length;
|
|
71
|
+
return {visible,total:all.length,threads:threads.size,behind,
|
|
72
|
+
hidden:all.length-visible.length,uncertain,blocked};
|
|
73
|
+
}
|
|
@@ -41,7 +41,12 @@
|
|
|
41
41
|
.keepalive-row .keepalive-name.is-logged-in { color:#23915c; }
|
|
42
42
|
.keepalive-row .keepalive-remove { flex:0 0 19px; width:19px; padding:1px; border:0; background:transparent; color:light-dark(var(--muted),#acb8c9); font-size:16px; font-weight:400; line-height:18px; }
|
|
43
43
|
.session-row button.site-enabled { color:#23915c; }
|
|
44
|
-
#queue-list { border-top:1px solid light-dark(var(--border),#334155); padding-top:6px; margin-top:2px; }
|
|
44
|
+
#queue-list { border-top:1px solid light-dark(var(--border),#334155); padding-top:6px; margin-top:2px; max-height:240px; }
|
|
45
|
+
#queue-heading { display:flex; justify-content:space-between; align-items:center; gap:8px; margin-top:8px; }
|
|
46
|
+
#queue-heading strong { font-size:12px; }
|
|
47
|
+
#queue-count { color:light-dark(var(--muted),#acb8c9); font-size:11px; font-weight:400; }
|
|
48
|
+
#queue-toggle { width:auto; flex-shrink:0; padding:3px 6px; font-size:11px; }
|
|
49
|
+
#queue-note { color:light-dark(var(--muted),#acb8c9); font-size:11px; padding:5px 0; }
|
|
45
50
|
.queue-platform { padding:5px 0; }
|
|
46
51
|
.queue-platform + .queue-platform { border-top:1px solid light-dark(var(--border),#334155); }
|
|
47
52
|
.queue-platform-title { font-size:12px; }
|
|
@@ -68,6 +73,8 @@
|
|
|
68
73
|
<strong>Keep Alive Sites</strong>
|
|
69
74
|
<div id="keepalive-list" aria-label="Keep Alive Sites">Loading…</div>
|
|
70
75
|
<div id="workspace-list" class="session-list" aria-label="Workspaces" aria-live="polite">Connecting…</div>
|
|
76
|
+
<div id="queue-heading"><strong>Queue <span id="queue-count"></span></strong><button id="queue-toggle" type="button" aria-controls="queue-list" aria-expanded="false" hidden>Show all</button></div>
|
|
77
|
+
<div id="queue-note" role="status" hidden></div>
|
|
71
78
|
<div id="queue-list" class="session-list" aria-label="Queue" aria-live="polite">No queue entries</div>
|
|
72
79
|
<section id="confirmation" hidden aria-label="Confirm clear sessions">
|
|
73
80
|
<p id="confirm-text">Stop the selected WebHelm session(s)? Tasks in progress may be interrupted. Queued jobs remain and may create new sessions.</p>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {readKeptSites, setStoredSite, compactQueue} from './popup-data.mjs';
|
|
1
2
|
const el = id => document.getElementById(id);
|
|
2
3
|
let confirming = false;
|
|
3
4
|
let chosen = null;
|
|
@@ -6,6 +7,11 @@ let lastQueueSignature = '';
|
|
|
6
7
|
let lastSiteSignature = '';
|
|
7
8
|
let currentSites = [];
|
|
8
9
|
let refreshRunning = false;
|
|
10
|
+
let canControlSites = false;
|
|
11
|
+
let queueExpanded = false;
|
|
12
|
+
let currentQueue = [];
|
|
13
|
+
let queueBusy = false;
|
|
14
|
+
let queueConnected = false;
|
|
9
15
|
const queueRows = new Map();
|
|
10
16
|
const queueGroups = new Map();
|
|
11
17
|
|
|
@@ -63,14 +69,19 @@ function renderKeptSites(sites, busy, connected) {
|
|
|
63
69
|
status.title=statusText;
|
|
64
70
|
status.setAttribute('aria-hidden','true');
|
|
65
71
|
const name=actionButton(new URL(site.url).hostname,false,async()=>{
|
|
66
|
-
try {
|
|
67
|
-
|
|
72
|
+
try {
|
|
73
|
+
if (canControlSites) await rpc('workspace.control.site.open',{siteId:site.id});
|
|
74
|
+
else await chrome.tabs.create({url:site.url,active:true});
|
|
75
|
+
} catch(error){el('message').textContent=error.message;}
|
|
68
76
|
},`tab-title keepalive-name ${loggedIn?'is-logged-in':''}`);
|
|
69
77
|
name.title=`${statusText} · Click to open site`;
|
|
70
78
|
name.setAttribute('aria-label',`${new URL(site.url).hostname}: ${statusText}. Open site`);
|
|
71
79
|
const remove=actionButton('×',false,async()=>{
|
|
72
|
-
try {
|
|
73
|
-
|
|
80
|
+
try {
|
|
81
|
+
if (canControlSites) await rpc('workspace.control.site.remove',{siteId:site.id});
|
|
82
|
+
else await setStoredSite(chrome,site.url,false);
|
|
83
|
+
lastSiteSignature='';lastSignature='';refresh();
|
|
84
|
+
} catch(error){el('message').textContent=error.message;}
|
|
74
85
|
},'keepalive-remove');
|
|
75
86
|
remove.title=`Remove ${new URL(site.url).hostname} from Keep Alive`;
|
|
76
87
|
remove.setAttribute('aria-label',remove.title);
|
|
@@ -82,7 +93,7 @@ function renderKeptSites(sites, busy, connected) {
|
|
|
82
93
|
function renderWorkspaces(workspaces, busy, connected) {
|
|
83
94
|
const signature = JSON.stringify(workspaces.map(w => [
|
|
84
95
|
w.name,w.initialized,w.available,w.poolSize,w.idleTabs,w.leasedTabs,w.sessions.map(s => [s.session_id,s.tab_title,s.tabId,s.tab_url]),
|
|
85
|
-
])) + ':' + JSON.stringify(currentSites.map(site=>site.id)) + ':' + busy + ':' + connected;
|
|
96
|
+
])) + ':' + JSON.stringify(currentSites.map(site=>site.id)) + ':' + canControlSites + ':' + busy + ':' + connected;
|
|
86
97
|
if (signature === lastSignature) return;
|
|
87
98
|
lastSignature = signature;
|
|
88
99
|
const target = el('workspace-list');
|
|
@@ -121,12 +132,14 @@ function renderWorkspaces(workspaces, busy, connected) {
|
|
|
121
132
|
sessionRow.append(details);
|
|
122
133
|
if (workspace.name === 'WebHelm' && siteId) {
|
|
123
134
|
const enabled=currentSites.some(site=>site.id===siteId);
|
|
124
|
-
|
|
135
|
+
const toggle=actionButton(enabled?'On':'Keep Alive',busy||!connected||!canControlSites,async()=>{
|
|
125
136
|
try {
|
|
126
137
|
await rpc('workspace.control.site.toggle',{sessionId:session.session_id,enabled:!enabled});
|
|
127
138
|
lastSignature='';refresh();
|
|
128
139
|
} catch(error){el('message').textContent=error.message;}
|
|
129
|
-
},enabled?'site-enabled':'')
|
|
140
|
+
},enabled?'site-enabled':'');
|
|
141
|
+
if(!canControlSites) toggle.title='Update the running WebHelm daemon to manage Keep Alive sites';
|
|
142
|
+
sessionRow.append(toggle);
|
|
130
143
|
}
|
|
131
144
|
sessionRow.append(actionButton('Stop', busy || !connected,
|
|
132
145
|
() => showConfirmation('stop', {sessionId:session.session_id})));
|
|
@@ -137,72 +150,92 @@ function renderWorkspaces(workspaces, busy, connected) {
|
|
|
137
150
|
}
|
|
138
151
|
|
|
139
152
|
function renderQueue(items, busy, connected) {
|
|
140
|
-
|
|
153
|
+
if(!items.length)queueExpanded=false;
|
|
154
|
+
const view=compactQueue(items,{expanded:queueExpanded,maxHeads:8});
|
|
155
|
+
const shown=view.visible;
|
|
156
|
+
const signature=JSON.stringify({shown:shown.map(item=>[item.id,item.platform,item.thread_id,item.title,item.url,item.state,item.attempts]),
|
|
157
|
+
total:view.total,threads:view.threads,hidden:view.hidden,uncertain:view.uncertain,blocked:view.blocked,
|
|
158
|
+
behind:[...view.behind],busy,connected,queueExpanded});
|
|
141
159
|
if (signature===lastQueueSignature) return;
|
|
142
160
|
lastQueueSignature=signature;
|
|
161
|
+
const count=el('queue-count');
|
|
162
|
+
count.textContent=view.total ? `${view.total} pending · ${view.threads} thread${view.threads===1?'':'s'}` : 'Empty';
|
|
163
|
+
const toggle=el('queue-toggle');
|
|
164
|
+
toggle.hidden=!(queueExpanded || view.hidden>0);
|
|
165
|
+
toggle.textContent=queueExpanded?'Show less':`Show all ${view.total}`;
|
|
166
|
+
toggle.setAttribute('aria-expanded',String(queueExpanded));
|
|
167
|
+
const note=el('queue-note');
|
|
168
|
+
note.hidden=!view.uncertain && !view.blocked;
|
|
169
|
+
if(!note.hidden) note.textContent=[
|
|
170
|
+
view.uncertain ? `${view.uncertain} uncertain` : '',
|
|
171
|
+
view.blocked ? `${view.blocked} blocked` : '',
|
|
172
|
+
].filter(Boolean).join(' · ') + ' — verify before retrying; later turns in the same thread may be waiting.';
|
|
173
|
+
|
|
143
174
|
const target=el('queue-list');
|
|
144
|
-
const grouped
|
|
145
|
-
for (const item of
|
|
146
|
-
const platform
|
|
147
|
-
if
|
|
175
|
+
const grouped=new Map();
|
|
176
|
+
for (const item of shown) {
|
|
177
|
+
const platform=String(item.platform||'Queue');
|
|
178
|
+
if(!grouped.has(platform)) grouped.set(platform,[]);
|
|
148
179
|
grouped.get(platform).push(item);
|
|
149
180
|
}
|
|
150
|
-
const activeGroupKeys
|
|
151
|
-
const activeRowKeys
|
|
152
|
-
for (const [key, group] of queueGroups) if
|
|
153
|
-
group.remove();
|
|
181
|
+
const activeGroupKeys=new Set(grouped.keys());
|
|
182
|
+
const activeRowKeys=new Set(shown.map(item=>`${item.platform||'Queue'}:${item.id}`));
|
|
183
|
+
for (const [key, group] of queueGroups) if(!activeGroupKeys.has(key)) {
|
|
184
|
+
group.remove();queueGroups.delete(key);
|
|
154
185
|
}
|
|
155
|
-
for (const [key, row] of queueRows) if
|
|
156
|
-
row.remove();
|
|
186
|
+
for (const [key, row] of queueRows) if(!activeRowKeys.has(key)) {
|
|
187
|
+
row.remove();queueRows.delete(key);
|
|
157
188
|
}
|
|
158
|
-
if
|
|
159
|
-
target.replaceChildren();
|
|
160
|
-
const empty=document.createElement('div');
|
|
189
|
+
if(!items.length) {
|
|
190
|
+
target.replaceChildren();queueGroups.clear();queueRows.clear();
|
|
191
|
+
const empty=document.createElement('div');empty.className='empty-queue';empty.textContent='No queue entries';
|
|
161
192
|
target.append(empty);
|
|
162
193
|
return;
|
|
163
194
|
}
|
|
164
195
|
target.querySelector('.empty-queue')?.remove();
|
|
165
|
-
for (const [platform,
|
|
166
|
-
let group
|
|
167
|
-
if
|
|
168
|
-
group
|
|
169
|
-
const heading
|
|
196
|
+
for (const [platform,entries] of grouped) {
|
|
197
|
+
let group=queueGroups.get(platform);
|
|
198
|
+
if(!group) {
|
|
199
|
+
group=document.createElement('section');group.className='queue-platform';
|
|
200
|
+
const heading=document.createElement('strong');heading.className='queue-platform-title';
|
|
170
201
|
heading.textContent=platform==='Queue'?'Queue':`${platform} Queue`;
|
|
171
|
-
const rows
|
|
172
|
-
group.append(heading,
|
|
202
|
+
const rows=document.createElement('div');rows.className='queue-platform-rows';
|
|
203
|
+
group.append(heading,rows);queueGroups.set(platform,group);target.append(group);
|
|
173
204
|
}
|
|
174
205
|
for (const item of entries) {
|
|
175
|
-
const key
|
|
176
|
-
let row
|
|
177
|
-
if
|
|
178
|
-
row=document.createElement('div');
|
|
179
|
-
const info=document.createElement('div');
|
|
180
|
-
const title=actionButton('',
|
|
181
|
-
try {
|
|
182
|
-
catch(error)
|
|
183
|
-
},
|
|
184
|
-
const detail=document.createElement('span');
|
|
185
|
-
const remove=actionButton('Remove',
|
|
186
|
-
try {
|
|
187
|
-
catch(error)
|
|
206
|
+
const key=`${platform}:${item.id}`;
|
|
207
|
+
let row=queueRows.get(key);
|
|
208
|
+
if(!row) {
|
|
209
|
+
row=document.createElement('div');row.className='queue-row';
|
|
210
|
+
const info=document.createElement('div');info.className='queue-info';
|
|
211
|
+
const title=actionButton('',false,async()=>{
|
|
212
|
+
try {await rpc('workspace.control.openQueue',{queueId:item.id});el('message').textContent='Queue destination opened.';}
|
|
213
|
+
catch(error){el('message').textContent=error.message;}
|
|
214
|
+
},'queue-title');
|
|
215
|
+
const detail=document.createElement('span');detail.className='queue-detail';
|
|
216
|
+
const remove=actionButton('Remove',false,async()=>{
|
|
217
|
+
try {const result=await rpc('workspace.control.queueCancel',{queueId:item.id});if(!result.id)throw Error('Missing queue request ID');el('message').textContent='Waiting for WebHelm daemon…';}
|
|
218
|
+
catch(error){el('message').textContent=error.message;}
|
|
188
219
|
refresh();
|
|
189
220
|
});
|
|
190
|
-
row.append(info,
|
|
191
|
-
queueRows.set(key,row);
|
|
221
|
+
row.append(info,remove);info.append(title,detail);queueRows.set(key,row);
|
|
192
222
|
}
|
|
193
223
|
const title=row.querySelector('.queue-title');
|
|
194
|
-
title.textContent=item.title
|
|
195
|
-
title.title=item.title
|
|
196
|
-
title.disabled=!connected
|
|
197
|
-
|
|
224
|
+
title.textContent=item.title||`${platform} message`;
|
|
225
|
+
title.title=item.title||`${platform} message`;
|
|
226
|
+
title.disabled=!connected||!item.url;
|
|
227
|
+
const attempts=Number(item.attempts)||0;
|
|
228
|
+
const more=!queueExpanded ? (view.behind.get(item.id)||0) : 0;
|
|
229
|
+
row.querySelector('.queue-detail').textContent=`${String(item.state||'queued').toLowerCase()} · ${attempts} attempt${attempts===1?'':'s'}`+
|
|
230
|
+
(more ? ` · ${more} more in this thread` : '');
|
|
198
231
|
const remove=row.querySelector('button:last-child');
|
|
199
232
|
const safe=['QUEUED','WAITING','BLOCKED','UNCERTAIN'].includes(item.state);
|
|
200
|
-
remove.disabled=!safe
|
|
233
|
+
remove.disabled=!safe||busy||!connected;
|
|
201
234
|
remove.title=safe?'':'Cannot remove a running or completed submission';
|
|
202
235
|
const rows=group.querySelector('.queue-platform-rows');
|
|
203
|
-
if
|
|
236
|
+
if(row.parentElement!==rows)rows.append(row);
|
|
204
237
|
}
|
|
205
|
-
if
|
|
238
|
+
if(group.parentElement!==target)target.append(group);
|
|
206
239
|
}
|
|
207
240
|
}
|
|
208
241
|
|
|
@@ -214,10 +247,13 @@ async function refresh() {
|
|
|
214
247
|
el('daemon-status').textContent = state.connected ? 'Online' : 'Offline';
|
|
215
248
|
el('daemon-status').className = `daemon-state ${state.connected ? 'online' : 'offline'}`;
|
|
216
249
|
const busy = Boolean(state.request);
|
|
217
|
-
|
|
250
|
+
canControlSites=Array.isArray(state.keptSites);
|
|
251
|
+
currentSites=await readKeptSites(chrome,state.keptSites);
|
|
218
252
|
renderKeptSites(currentSites,busy,state.connected);
|
|
219
|
-
renderWorkspaces(state.workspaces || [],
|
|
220
|
-
|
|
253
|
+
renderWorkspaces(state.workspaces || [],busy,state.connected);
|
|
254
|
+
currentQueue=state.queue||[];
|
|
255
|
+
queueBusy=busy;queueConnected=state.connected;
|
|
256
|
+
renderQueue(currentQueue,busy,state.connected);
|
|
221
257
|
el('confirm').disabled = !state.connected || busy;
|
|
222
258
|
if (busy) {
|
|
223
259
|
el('message').textContent = 'Applying WebHelm action…';
|
|
@@ -236,6 +272,12 @@ async function refresh() {
|
|
|
236
272
|
}
|
|
237
273
|
}
|
|
238
274
|
|
|
275
|
+
el('queue-toggle').addEventListener('click',()=>{
|
|
276
|
+
queueExpanded=!queueExpanded;
|
|
277
|
+
lastQueueSignature='';
|
|
278
|
+
renderQueue(currentQueue,queueBusy,queueConnected);
|
|
279
|
+
});
|
|
280
|
+
|
|
239
281
|
el('cancel').addEventListener('click', () => {
|
|
240
282
|
confirming = false;
|
|
241
283
|
el('confirmation').hidden = true;
|
|
@@ -12,7 +12,7 @@ export const EXTENSION_HOME=path.resolve(process.env.WEBHELM_EXTENSION_HOME ||
|
|
|
12
12
|
(SOURCE_MODE ? SOURCE : path.join(LOCAL_ROOT,'extension')));
|
|
13
13
|
const FILES=[
|
|
14
14
|
'manifest.json','service-worker.mjs','workspace-manager.mjs','workspace.html','helm.html','workspace-page.mjs',
|
|
15
|
-
'control-channel.mjs','control-rpc.mjs','site-registry.mjs','workspace-summary.mjs','session-badge.mjs','popup.html','popup.mjs',
|
|
15
|
+
'control-channel.mjs','control-rpc.mjs','site-registry.mjs','popup-data.mjs','workspace-summary.mjs','session-badge.mjs','popup.html','popup.mjs',
|
|
16
16
|
...[16,32,48,128].map(size => `icons/webhelm-${size}.png`),
|
|
17
17
|
];
|
|
18
18
|
|
package/runtime/node-daemon.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { stopMatchingSessions } from './session-control.mjs';
|
|
|
14
14
|
import { ensureManagedChrome } from './chrome.mjs';
|
|
15
15
|
import { ensureExtensionLoaded } from './extension-manager.mjs';
|
|
16
16
|
import { createManagedChromeGuard } from './managed-chrome-guard.mjs';
|
|
17
|
-
import { PROFILE_DIR, RUNTIME_DIR,
|
|
17
|
+
import { PROFILE_DIR, RUNTIME_DIR, assertProfileConsistency } from './config-paths.mjs';
|
|
18
18
|
|
|
19
19
|
const ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
20
20
|
const PACKAGE_VERSION=JSON.parse(fs.readFileSync(new URL('../package.json',import.meta.url),'utf8')).version;
|
|
@@ -808,6 +808,6 @@ async function request(payload,ensure=true){
|
|
|
808
808
|
conn.on('error',error=>finish(error));
|
|
809
809
|
});
|
|
810
810
|
}
|
|
811
|
-
export async function ensureDaemon(){try{const p=await request({op:'ping'},false);if(p.ok)return p}catch{}if(!process.env.WEBHELM_CDP_URL)
|
|
811
|
+
export async function ensureDaemon(){try{const p=await request({op:'ping'},false);if(p.ok)return p}catch{}if(!process.env.WEBHELM_CDP_URL)assertProfileConsistency();fs.mkdirSync(RUNTIME,{recursive:true,mode:0o700});if(fs.existsSync(LOCK)){let owner=0;try{owner=Number(fs.readFileSync(LOCK,'utf8').trim())}catch{};let alive=false;if(owner>0)try{process.kill(owner,0);alive=true}catch{};if(alive)throw Error(`daemon owner lock exists but socket is unreachable; refusing duplicate startup (${LOCK})`);fs.unlinkSync(LOCK)}const child=await import('node:child_process');const log=fs.openSync(path.join(RUNTIME,'session-node.log'),'a');child.spawn(process.execPath,[fileURLToPath(import.meta.url),'daemon'],{detached:true,stdio:['ignore',log,log],env:process.env}).unref();for(let i=0;i<100;i++){await delay(100);try{const p=await request({op:'ping'},false);if(p.ok)return p}catch{}}throw Error(`WebHelm Node daemon did not start; see ${path.join(RUNTIME,'session-node.log')}`)}
|
|
812
812
|
if(process.argv[2]==='daemon')main().catch(e=>{console.error(e);process.exit(1)});
|
|
813
813
|
export {request,SOCKET,RUNTIME};
|
package/runtime/migrate.mjs
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { execFileSync } from 'node:child_process';
|
|
4
|
-
import net from 'node:net';
|
|
5
|
-
import { CONFIG_ROOT, LEGACY_ROOT, OLD_PROFILE_DIR, PROFILE_DIR } from './config-paths.mjs';
|
|
6
|
-
|
|
7
|
-
function liveSocket(socketPath) {
|
|
8
|
-
return new Promise(resolve => {
|
|
9
|
-
const socket = net.createConnection(socketPath);
|
|
10
|
-
const finish = result => { socket.destroy(); resolve(result); };
|
|
11
|
-
socket.once('connect', () => finish(true));
|
|
12
|
-
socket.once('error', () => finish(false));
|
|
13
|
-
socket.setTimeout(1200, () => finish(true)); // Fail closed if probing hangs.
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function migrateConfig({ legacyRoot = LEGACY_ROOT, configRoot = CONFIG_ROOT,
|
|
18
|
-
processList = () => execFileSync('ps', ['-axo', 'command='], { encoding: 'utf8' }),
|
|
19
|
-
socketCheck = liveSocket } = {}) {
|
|
20
|
-
const legacy = path.resolve(legacyRoot);
|
|
21
|
-
const target = path.resolve(configRoot);
|
|
22
|
-
if (legacy === target) throw Error('Legacy and new config paths are identical');
|
|
23
|
-
let oldStat;
|
|
24
|
-
try { oldStat = fs.lstatSync(legacy); }
|
|
25
|
-
catch (e) { if (e.code === 'ENOENT') return { status: 'not_needed', config_root: target }; throw e; }
|
|
26
|
-
if (oldStat.isSymbolicLink()) {
|
|
27
|
-
if (fs.existsSync(target) && fs.realpathSync(legacy) === fs.realpathSync(target))
|
|
28
|
-
return { status: 'already_migrated', config_root: target, compatibility_symlink: legacy };
|
|
29
|
-
throw Error(`Legacy path is a different symlink: ${legacy}`);
|
|
30
|
-
}
|
|
31
|
-
if (!oldStat.isDirectory()) throw Error(`Legacy path is not a directory: ${legacy}`);
|
|
32
|
-
if (fs.existsSync(target)) throw Error(`Target already exists; refusing to overwrite: ${target}`);
|
|
33
|
-
const running = processList().split('\n').filter(line =>
|
|
34
|
-
line.includes(`--user-data-dir=${path.join(legacy, 'chrome')}`) ||
|
|
35
|
-
(line.includes('node-daemon.mjs daemon') && !line.includes('migrate.mjs')));
|
|
36
|
-
if (running.length) throw Error('Chrome or WebHelm daemon is still running; stop Sessions, daemon and Chrome before migration');
|
|
37
|
-
const socket = path.join(legacy, 'runtime', 'session-node.sock');
|
|
38
|
-
if (fs.existsSync(socket) && await socketCheck(socket))
|
|
39
|
-
throw Error('Legacy daemon socket is active; refusing migration');
|
|
40
|
-
fs.renameSync(legacy, target); // Same-volume atomic directory move; preserve Chrome data and FIFO WAL.
|
|
41
|
-
try { fs.symlinkSync(target, legacy, 'dir'); }
|
|
42
|
-
catch (error) {
|
|
43
|
-
fs.renameSync(target, legacy);
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
return { status: 'migrated', config_root: target, compatibility_symlink: legacy };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Move only the Chrome Profile. Durable FIFO and logs stay under ~/.config/webhelm/runtime.
|
|
50
|
-
// Chrome must be stopped because its SingletonLock and keychain-bound profile
|
|
51
|
-
// resources cannot be safely relocated while the browser is still running.
|
|
52
|
-
export async function migrateChromeProfile({oldProfile=OLD_PROFILE_DIR,newProfile=PROFILE_DIR,
|
|
53
|
-
processList=()=>execFileSync('ps',['-axo','command='],{encoding:'utf8'}),
|
|
54
|
-
socketCheck=liveSocket}={}){
|
|
55
|
-
const old=path.resolve(oldProfile),target=path.resolve(newProfile);
|
|
56
|
-
if(old===target)throw Error('Chrome source and destination paths must differ');
|
|
57
|
-
if(fs.existsSync(target)){
|
|
58
|
-
if(!fs.existsSync(old))return {status:'already_migrated',profile_dir:target};
|
|
59
|
-
if(fs.realpathSync(old)===fs.realpathSync(target))return {status:'already_migrated',profile_dir:target,compatibility_symlink:old};
|
|
60
|
-
throw Error(`Different Chrome Profiles at ${old} and ${target}; refusing to overwrite`);
|
|
61
|
-
}
|
|
62
|
-
if(!fs.existsSync(old))return {status:'not_needed',profile_dir:target};
|
|
63
|
-
if(fs.lstatSync(old).isSymbolicLink() || !fs.statSync(old).isDirectory())
|
|
64
|
-
throw Error('Old Chrome Profile is not a regular directory');
|
|
65
|
-
const running=processList().split('\n').filter(s=>s.includes(`--user-data-dir=${old}`)||s.includes(`--user-data-dir=${target}`)||s.includes('node-daemon.mjs daemon') && !s.includes('migrate.mjs'));
|
|
66
|
-
if(running.length)throw Error('Managed Chrome or daemon is running; stop and drain before migrating Profile');
|
|
67
|
-
const socket=path.join(path.dirname(old),'runtime/session-node.sock');
|
|
68
|
-
if(fs.existsSync(socket)&&await socketCheck(socket))throw Error('Session daemon still accepting requests');
|
|
69
|
-
if(!fs.existsSync(path.join(old,'Default')))throw Error('Old Chrome Profile lacks Default; refusing to migrate');
|
|
70
|
-
const parent=path.dirname(target);
|
|
71
|
-
if(fs.existsSync(path.join(parent,'.git'))){
|
|
72
|
-
const info=path.join(parent,'.git/info/exclude');
|
|
73
|
-
const current=fs.existsSync(info)?fs.readFileSync(info,'utf8'):'';
|
|
74
|
-
if(!current.split(/\r?\n/).includes('/chrome/'))fs.appendFileSync(info,'\n/chrome/\n');
|
|
75
|
-
}
|
|
76
|
-
fs.mkdirSync(parent,{recursive:true});
|
|
77
|
-
fs.renameSync(old,target);
|
|
78
|
-
try{fs.symlinkSync(target,old,'dir');}catch(error){fs.renameSync(target,old);throw error;}
|
|
79
|
-
return {status:'migrated',profile_dir:target,compatibility_symlink:old};
|
|
80
|
-
}
|