webhelm 1.0.39 → 1.0.41

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 CHANGED
@@ -50,7 +50,9 @@ The Actions checkout is `~/.local/webhelm`, with site modules at `~/.local/webhe
50
50
  ## Optional site Keep Alive (Extension)
51
51
 
52
52
  Only a Session in the **WebHelm** Workspace can use the Extension's **Keep Alive** toggle on an HTTPS page to
53
- register that website's **origin**. The website stays in the popup's Keep Alive
53
+ register that website's **origin and current path** (without query or fragment).
54
+ There is one site entry per origin, so enabling Keep Alive on another path
55
+ updates its saved destination. The website stays in the popup's Keep Alive
54
56
  Sites list even after the original Session ends. Custom/other Workspace
55
57
  Sessions have no Keep Alive toggle. A green dot and website name mean that
56
58
  the Platform last confirmed login; gray means not confirmed or not logged in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webhelm",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "Agent browser automation in a visible managed Chrome with persistent JavaScript sessions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,3 +1,10 @@
1
+ export const PROMPT_FILE_THRESHOLD = 2000;
2
+ export const PROMPT_FILE_MESSAGE = 'Read prompt.md and execute the task in that file.';
3
+
4
+ export function deliveryMessage(message) {
5
+ return message.length > PROMPT_FILE_THRESHOLD ? PROMPT_FILE_MESSAGE : message;
6
+ }
7
+
1
8
  export function targetUrl(projectId, threadId, message) {
2
9
  if (!threadId || !message) {
3
10
  throw new Error("thread_id and message are required");
@@ -5,7 +12,7 @@ export function targetUrl(projectId, threadId, message) {
5
12
  // A thread identity is global; ChatGPT may redirect /c/id to a
6
13
  // Project-scoped /g/project-id[-slug]/c/id. Use the ordinary URL.
7
14
  return "https://chatgpt.com/c/" + encodeURIComponent(threadId) +
8
- "?" + new URLSearchParams({ prompt: message });
15
+ "?" + new URLSearchParams({ prompt: deliveryMessage(message) });
9
16
  }
10
17
  export const PROBE_JS = `(() => {
11
18
  const visible = e => !!e && !!e.getClientRects().length && getComputedStyle(e).visibility !== 'hidden';
@@ -1,9 +1,10 @@
1
1
  import { DatabaseSync } from "node:sqlite";
2
- import { mkdirSync, existsSync, statSync } from "node:fs";
2
+ import { mkdirSync, mkdtempSync, writeFileSync, rmSync, existsSync, statSync } from "node:fs";
3
3
  import { join, resolve, isAbsolute } from "node:path";
4
+ import { tmpdir } from "node:os";
4
5
  import { attachmentUploadScript } from "./attachment-upload.mjs";
5
6
  import { createHash, randomUUID } from "node:crypto";
6
- import { classifyProbe, PROBE_JS, targetUrl } from "./chatgpt-probe.mjs";
7
+ import { classifyProbe, PROBE_JS, targetUrl, deliveryMessage, PROMPT_FILE_THRESHOLD } from "./chatgpt-probe.mjs";
7
8
  import { SEND_ENABLED_JS } from "./lifecycle-common.mjs";
8
9
  import { submissionScript } from "./submission-script.mjs";
9
10
  import { DurableQueueCore } from "../durable-queue-core.mjs";
@@ -244,11 +245,22 @@ export class ChatGPTQueue extends DurableQueueCore {
244
245
  const sid = this.sessions.get(item.id);
245
246
  if (!sid) throw new Error("missing prepared browser session");
246
247
  const attachments = JSON.parse(item.files_json || "[]");
247
- if (attachments.length) {
248
- const upload = await this._exec(sid, attachmentUploadScript(attachments));
249
- if (!upload?.ready) throw new Error("ChatGPT attachments not ready for Send");
248
+ let tempDir;
249
+ try {
250
+ if (item.message.length > PROMPT_FILE_THRESHOLD) {
251
+ tempDir = mkdtempSync(join(tmpdir(), "webhelm-prompt-"));
252
+ const promptPath = join(tempDir, "prompt.md");
253
+ writeFileSync(promptPath, item.message, {encoding:"utf8",mode:0o600});
254
+ attachments.push(promptPath);
255
+ }
256
+ if (attachments.length) {
257
+ const upload = await this._exec(sid, attachmentUploadScript(attachments));
258
+ if (!upload?.ready) throw new Error("ChatGPT attachments not ready for Send");
259
+ }
260
+ return await this._exec(sid, submissionScript({...item, message:deliveryMessage(item.message)}));
261
+ } finally {
262
+ if (tempDir) rmSync(tempDir, {recursive:true,force:true});
250
263
  }
251
- return this._exec(sid, submissionScript(item));
252
264
  }
253
265
  async _finish(id) {
254
266
  const sid = this.sessions.get(id);
@@ -1,4 +1,4 @@
1
- import {siteOrigin, setKeptSite, listKeptSites, sitesWithStatus, reportKeptSite} from "./site-registry.mjs";
1
+ import {siteOrigin, sitePage, setKeptSite, listKeptSites, sitesWithStatus, reportKeptSite} from "./site-registry.mjs";
2
2
  function validTabId(tabId) { return Number.isSafeInteger(tabId) && tabId > 0; }
3
3
  function validateQueueUrl(url) {
4
4
  const parsed = new URL(url);
@@ -61,8 +61,7 @@ export function createControlRpc({control, manager, summarizeWorkspaces, schedul
61
61
  if (session.workspace !== 'WebHelm')
62
62
  throw Error('Keep Alive can be enabled only from a WebHelm Session');
63
63
  const tab = await chromeApi.tabs.get(session.tabId);
64
- const id = siteOrigin(tab.url || '');
65
- return setKeptSite(chromeApi,id,Boolean(args.enabled));
64
+ return setKeptSite(chromeApi,tab.url || '',Boolean(args.enabled));
66
65
  }
67
66
  case "workspace.control.site.remove": {
68
67
  const site = (await listKeptSites(chromeApi)).find(s => s.id === args.siteId);
@@ -72,14 +71,14 @@ export function createControlRpc({control, manager, summarizeWorkspaces, schedul
72
71
  case "workspace.control.site.open": {
73
72
  const site = (await listKeptSites(chromeApi)).find(s => s.id === args.siteId);
74
73
  if (!site) throw Error('Keep Alive site is no longer registered');
75
- const url = siteOrigin(site.url);
74
+ const url = sitePage(site.url);
76
75
  const daemon = await control.status();
77
76
  const leasedIds = new Set(daemon.connected ? daemon.sessions.flatMap(session =>
78
77
  Array.isArray(session.tabIds) ? session.tabIds : [session.tabId]) : []);
79
78
  // Never hand a human-login operation an active agent-owned leased Tab.
80
79
  const existing = daemon.connected && (await chromeApi.tabs.query({})).find(tab => {
81
80
  if (leasedIds.has(tab.id)) return false;
82
- try { return siteOrigin(tab.url) === url; } catch { return false; }
81
+ try { return sitePage(tab.url) === url; } catch { return false; }
83
82
  });
84
83
  if (existing) {
85
84
  await chromeApi.tabs.update(existing.id,{active:true});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "WebHelm",
4
- "version": "1.0.39",
4
+ "version": "1.0.41",
5
5
  "description": "Own named Chrome tab-group workspaces and lazy reusable tab pools for browser agents.",
6
6
  "permissions": [
7
7
  "storage",
@@ -4,8 +4,13 @@ export const SITE_STORAGE_KEY = 'webhelm.keepalive.sites.v1';
4
4
  export const SITE_STATUS_KEY = 'webhelm.keepalive.status.v1';
5
5
 
6
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; }
7
+ if (!site || typeof site.id !== 'string' || typeof site.url !== 'string' || site.enabled !== true) return false;
8
+ try {
9
+ const url = new URL(site.url);
10
+ return url.protocol === 'https:' && !url.username && !url.password &&
11
+ !url.search && !url.hash && url.origin === site.id &&
12
+ site.url === (url.pathname === '/' ? url.origin : url.origin + url.pathname);
13
+ }
9
14
  catch { return false; }
10
15
  }
11
16
 
@@ -32,12 +37,14 @@ export async function readKeptSites(chromeApi, reported) {
32
37
  }
33
38
 
34
39
  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');
40
+ const parsed = new URL(url);
41
+ const origin = parsed.origin;
42
+ if (parsed.protocol !== 'https:' || parsed.username || parsed.password) throw Error('Keep Alive requires HTTPS');
37
43
  const stored=await chromeApi.storage.local.get(SITE_STORAGE_KEY);
38
44
  const current=Array.isArray(stored[SITE_STORAGE_KEY]) ? stored[SITE_STORAGE_KEY] : [];
39
45
  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()});
46
+ if (enabled) next.push({id:origin,url:parsed.pathname === '/' ? origin : origin + parsed.pathname,
47
+ enabled:true,addedAt:Date.now(),revision:crypto.randomUUID()});
41
48
  await chromeApi.storage.local.set({[SITE_STORAGE_KEY]: next.sort((a,b)=>a.id.localeCompare(b.id))});
42
49
  if (!enabled) {
43
50
  const storedStates=await chromeApi.storage.session.get(SITE_STATUS_KEY);
@@ -38,7 +38,7 @@
38
38
  .keepalive-row { display:flex; align-items:center; gap:7px; min-height:25px; padding:2px 0; }
39
39
  .keepalive-status { flex:0 0 7px; width:7px; height:7px; border-radius:50%; background:light-dark(#8893a1,#8995a5); }
40
40
  .keepalive-status[data-status="alive"] { background:#23915c; }
41
- .keepalive-row .keepalive-name { flex:1; min-width:0; color:light-dark(var(--muted),#acb8c9); font-size:11px; font-weight:500; }
41
+ .keepalive-row .keepalive-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:light-dark(var(--muted),#acb8c9); font-size:11px; font-weight:500; }
42
42
  .keepalive-row .keepalive-name.is-logged-in { color:#23915c; }
43
43
  .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; }
44
44
  .session-row button.site-enabled { color:#23915c; }
@@ -50,6 +50,11 @@ function originForTab(url) {
50
50
  catch { return null; }
51
51
  }
52
52
 
53
+ function siteLabel(url) {
54
+ const page = new URL(url);
55
+ return page.hostname + (page.pathname === '/' ? '' : page.pathname);
56
+ }
57
+
53
58
  function renderKeptSites(sites, busy, connected) {
54
59
  const signature = JSON.stringify(sites) + `:${busy}:${connected}`;
55
60
  if (signature === lastSiteSignature) return;
@@ -70,14 +75,14 @@ function renderKeptSites(sites, busy, connected) {
70
75
  status.dataset.status=loggedIn?'alive':'inactive';
71
76
  status.title=statusText;
72
77
  status.setAttribute('aria-hidden','true');
73
- const name=actionButton(new URL(site.url).hostname,false,async()=>{
78
+ const name=actionButton(siteLabel(site.url),false,async()=>{
74
79
  try {
75
80
  if (canControlSites) await rpc('workspace.control.site.open',{siteId:site.id});
76
81
  else await chrome.tabs.create({url:site.url,active:true});
77
82
  } catch(error){el('message').textContent=error.message;}
78
83
  },`tab-title keepalive-name ${loggedIn?'is-logged-in':''}`);
79
- name.title=`${statusText} · Click to open site`;
80
- name.setAttribute('aria-label',`${new URL(site.url).hostname}: ${statusText}. Open site`);
84
+ name.title=`${siteLabel(site.url)} · ${statusText} · Click to open site`;
85
+ name.setAttribute('aria-label',`${siteLabel(site.url)}: ${statusText}. Open site`);
81
86
  const remove=actionButton('×',false,async()=>{
82
87
  try {
83
88
  if (canControlSites) await rpc('workspace.control.site.remove',{siteId:site.id});
@@ -85,7 +90,7 @@ function renderKeptSites(sites, busy, connected) {
85
90
  lastSiteSignature='';lastSignature='';refresh();
86
91
  } catch(error){el('message').textContent=error.message;}
87
92
  },'keepalive-remove');
88
- remove.title=`Remove ${new URL(site.url).hostname} from Keep Alive`;
93
+ remove.title=`Remove ${siteLabel(site.url)} from Keep Alive`;
89
94
  remove.setAttribute('aria-label',remove.title);
90
95
  row.append(status,name,remove);
91
96
  target.append(row);
@@ -10,16 +10,27 @@ export function siteOrigin(rawUrl) {
10
10
  return parsed.origin;
11
11
  }
12
12
 
13
+ // Keep one registration per origin, but retain the exact page path for opening
14
+ // and for display. Never persist query parameters or fragments.
15
+ export function sitePage(rawUrl) {
16
+ const parsed = new URL(rawUrl);
17
+ const origin = siteOrigin(rawUrl);
18
+ return parsed.pathname === '/' ? origin : origin + parsed.pathname;
19
+ }
20
+
13
21
  export async function listKeptSites(chromeApi) {
14
22
  const record = (await chromeApi.storage.local.get(SITE_STORAGE_KEY))[SITE_STORAGE_KEY];
15
- return Array.isArray(record) ? record.filter(site => site && typeof site.id === 'string' &&
16
- typeof site.url === 'string' && site.id === site.url && site.enabled === true) : [];
23
+ return Array.isArray(record) ? record.filter(site => {
24
+ if (!site || typeof site.id !== 'string' || typeof site.url !== 'string' || site.enabled !== true) return false;
25
+ try { return site.id === siteOrigin(site.url) && site.url === sitePage(site.url); }
26
+ catch { return false; }
27
+ }) : [];
17
28
  }
18
29
 
19
30
  export async function setKeptSite(chromeApi, url, enabled) {
20
31
  const id = siteOrigin(url);
21
32
  const sites = (await listKeptSites(chromeApi)).filter(site => site.id !== id);
22
- if (enabled) sites.push({id, url:id, enabled:true, addedAt:Date.now(), revision:crypto.randomUUID()});
33
+ if (enabled) sites.push({id, url:sitePage(url), enabled:true, addedAt:Date.now(), revision:crypto.randomUUID()});
23
34
  sites.sort((a,b) => a.id.localeCompare(b.id));
24
35
  await chromeApi.storage.local.set({[SITE_STORAGE_KEY]: sites});
25
36
  if (!enabled) {
@@ -15,7 +15,8 @@ export function resolveSiteHeartbeat(site, names=listPlatforms, manifestFor=plat
15
15
  let origin;
16
16
  try {
17
17
  const url = new URL(site?.url);
18
- if (!site?.enabled || url.protocol !== 'https:' || url.origin !== site.id || url.href !== `${url.origin}/`) return null;
18
+ if (!site?.enabled || url.protocol !== 'https:' || url.origin !== site.id ||
19
+ url.username || url.password || url.search || url.hash) return null;
19
20
  origin = url.origin;
20
21
  } catch { return null; }
21
22
  for (const platform of names()) {