webhelm 1.0.46 → 1.0.48

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
@@ -76,6 +76,15 @@ this release to register the updater LaunchAgent. The setup and updater also
76
76
  migrate only legacy global CLI symlinks that target an owned immutable
77
77
  `runtime-VERSION/bin/webhelm.mjs` into the stable Runtime link.
78
78
 
79
+ ChatGPT `newThread` / `newTurn` accept optional `enforcement_context` for
80
+ per-request requirements. WebHelm does not parse the contents or know the
81
+ caller's protocol; it wraps the provided text in `<top-instructions>` before
82
+ the actual `message`. If the combined text exceeds 2,000 characters, WebHelm
83
+ uploads the exact original `message` as `prompt.md` and keeps the optional
84
+ context in the visible composer before `Read prompt.md...`. Omitting the
85
+ option preserves the old short composer and attachment behavior. Durable
86
+ queued `newTurn` persists the context and checks it for idempotency.
87
+
79
88
  ## WebHelm Chrome Extension control panel
80
89
 
81
90
  The daemon-managed Chrome Extension is installed from the npm Runtime and does not require the Chrome Web Store. Click the WebHelm toolbar icon to see daemon connectivity, each configured workspace's available capacity and current Session count. The toolbar badge shows the number of **active daemon Sessions** across all workspaces (including `0` when idle). `!` means the daemon heartbeat is stale and `?` means the Session count is unknown. The popup separately shows pool availability and idle tabs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webhelm",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "Agent browser automation in a visible managed Chrome with persistent JavaScript sessions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,18 +1,38 @@
1
1
  export const PROMPT_FILE_THRESHOLD = 2000;
2
2
  export const PROMPT_FILE_MESSAGE = 'Read prompt.md and execute the task in that file.';
3
3
 
4
- export function deliveryMessage(message) {
5
- return message.length > PROMPT_FILE_THRESHOLD ? PROMPT_FILE_MESSAGE : message;
4
+ // Optional caller-supplied per-request constraints. No service-specific tags,
5
+ // response IDs, or protocol parsing belong in WebHelm.
6
+ export function enforcementContext(value = '') {
7
+ if (value === undefined || value === null || value === '') return '';
8
+ if (typeof value !== 'string' || !value.trim() || value.length > 1500 ||
9
+ value.includes('</top-instructions>')) {
10
+ throw new TypeError('enforcement_context must be a non-empty string of at most 1500 characters without closing tag');
11
+ }
12
+ return `<top-instructions>\n${value}\n</top-instructions>`;
6
13
  }
7
-
8
- export function targetUrl(projectId, threadId, message) {
14
+ export function fullDeliveryMessage(message, context = '') {
15
+ const header = enforcementContext(context);
16
+ return (header ? header+'\n\n' : '') + message;
17
+ }
18
+ export function requiresPromptFile(message, context = '') {
19
+ return fullDeliveryMessage(message, context).length > PROMPT_FILE_THRESHOLD;
20
+ }
21
+ export function deliveryMessage(message, context = '') {
22
+ const full = fullDeliveryMessage(message, context);
23
+ if (full.length <= PROMPT_FILE_THRESHOLD) return full;
24
+ const header = enforcementContext(context);
25
+ if (!header) return PROMPT_FILE_MESSAGE;
26
+ const short = header+'\n\n'+PROMPT_FILE_MESSAGE;
27
+ if (short.length > PROMPT_FILE_THRESHOLD) throw new TypeError('enforcement_context exceeds the short message limit');
28
+ return short;
29
+ }
30
+ export function targetUrl(projectId, threadId, message, enforcement_context = '') {
9
31
  if (!threadId || !message) {
10
32
  throw new Error("thread_id and message are required");
11
33
  }
12
- // A thread identity is global; ChatGPT may redirect /c/id to a
13
- // Project-scoped /g/project-id[-slug]/c/id. Use the ordinary URL.
14
34
  return "https://chatgpt.com/c/" + encodeURIComponent(threadId) +
15
- "?" + new URLSearchParams({ prompt: deliveryMessage(message) });
35
+ "?" + new URLSearchParams({ prompt: deliveryMessage(message, enforcement_context) });
16
36
  }
17
37
  export const PROBE_JS = `(() => {
18
38
  const visible = e => !!e && !!e.getClientRects().length && getComputedStyle(e).visibility !== 'hidden';
@@ -4,7 +4,7 @@ import { join, resolve, isAbsolute } from "node:path";
4
4
  import { tmpdir } from "node:os";
5
5
  import { attachmentUploadScript } from "./attachment-upload.mjs";
6
6
  import { createHash, randomUUID } from "node:crypto";
7
- import { classifyProbe, PROBE_JS, targetUrl, deliveryMessage, PROMPT_FILE_THRESHOLD } from "./chatgpt-probe.mjs";
7
+ import { classifyProbe, PROBE_JS, targetUrl, deliveryMessage, requiresPromptFile, enforcementContext } from "./chatgpt-probe.mjs";
8
8
  import { SEND_ENABLED_JS } from "./lifecycle-common.mjs";
9
9
  import { submissionScript } from "./submission-script.mjs";
10
10
  import { DurableQueueCore } from "../durable-queue-core.mjs";
@@ -27,7 +27,9 @@ const chatgptQueuePolicy = {
27
27
  one(db, sql, ...args) { return db.prepare(sql).get(...args) || null; },
28
28
  rows(db) { return db.prepare("SELECT * FROM turns ORDER BY seq").all(); },
29
29
  enqueue(db, request = {}, now) {
30
- const {thread_id, message, idempotency_key, idempotencyKey, project_id=null, mergeable=false, file=[]} = request;
30
+ const {thread_id, message, idempotency_key, idempotencyKey, project_id=null, mergeable=false, file=[], enforcement_context:rawContext=''} = request;
31
+ const enforcement_context=rawContext??'';
32
+ enforcementContext(enforcement_context);
31
33
  if (!Array.isArray(file) || file.length > 4 ||
32
34
  file.some(p => typeof p !== "string" || !isAbsolute(p) ||
33
35
  !existsSync(p) || !statSync(p).isFile())) {
@@ -40,19 +42,19 @@ const chatgptQueuePolicy = {
40
42
  if (typeof mergeable !== "boolean") throw new TypeError("mergeable must be a boolean");
41
43
  const merged=this.one(db, "SELECT * FROM merged_requests WHERE idem_key=?", key);
42
44
  if (merged) {
43
- if (merged.thread_id!==thread_id || merged.message!==message || merged.project_id!==project_id || filesJson!=="[]") throw new Error("idempotency key reused with different payload");
44
45
  const row=this.one(db, "SELECT * FROM turns WHERE id=?", merged.queue_id);
46
+ if (merged.thread_id!==thread_id || merged.message!==message || merged.project_id!==project_id || filesJson!=="[]" || row.enforcement_context!==enforcement_context) throw new Error("idempotency key reused with different payload");
45
47
  return {ok:true,status:"queued",queue_id:row.id,thread_id:row.thread_id,state:row.state};
46
48
  }
47
49
  const same=this.one(db, "SELECT * FROM turns WHERE idem_key=?", key);
48
50
  if (same) {
49
- if (same.thread_id!==thread_id || same.message!==message || same.project_id!==project_id || (same.files_json||"[]")!==filesJson) throw new Error("idempotency key reused with different payload");
51
+ if (same.thread_id!==thread_id || same.message!==message || same.project_id!==project_id || same.enforcement_context!==enforcement_context || (same.files_json||"[]")!==filesJson) throw new Error("idempotency key reused with different payload");
50
52
  return {ok:true,status:"queued",queue_id:same.id,thread_id:same.thread_id,state:same.state};
51
53
  }
52
54
  const tail=mergeable ? this.one(db, "SELECT * FROM turns WHERE thread_id=? ORDER BY seq DESC LIMIT 1", thread_id) : null;
53
55
  // WAITING denotes admitted work being retried; only QUEUED is cancellable
54
56
  // and eligible for a new enqueue-time merge.
55
- if (tail && tail.mergeable && tail.project_id===project_id && tail.state==="QUEUED") {
57
+ if (tail && tail.mergeable && tail.project_id===project_id && tail.enforcement_context===enforcement_context && tail.state==="QUEUED") {
56
58
  db.prepare("INSERT OR IGNORE INTO merged_requests VALUES(?,?,?,?,?)").run(tail.idem_key,tail.project_id,thread_id,tail.message,tail.id);
57
59
  db.prepare("INSERT INTO merged_requests VALUES(?,?,?,?,?)").run(key,project_id,thread_id,message,tail.id);
58
60
  db.prepare("UPDATE turns SET message=message || ? WHERE id=?").run("\n"+message,tail.id);
@@ -60,7 +62,7 @@ const chatgptQueuePolicy = {
60
62
  return {ok:true,status:"queued",queue_id:row.id,thread_id:row.thread_id,state:row.state};
61
63
  }
62
64
  const id=randomUUID();
63
- db.prepare("INSERT INTO turns(id,idem_key,project_id,thread_id,message,state,next_check_at,created_at,mergeable,files_json) VALUES(?,?,?,?,?,'QUEUED',?,?,?,?)").run(id,key,project_id,thread_id,message,now,now,mergeable?1:0,filesJson);
65
+ db.prepare("INSERT INTO turns(id,idem_key,project_id,thread_id,message,enforcement_context,state,next_check_at,created_at,mergeable,files_json) VALUES(?,?,?,?,?,?,'QUEUED',?,?,?,?)").run(id,key,project_id,thread_id,message,enforcement_context,now,now,mergeable?1:0,filesJson);
64
66
  return {ok:true,status:"queued",queue_id:id,thread_id,state:"QUEUED"};
65
67
  },
66
68
  claim(db, owner, now, leaseSeconds) {
@@ -130,9 +132,11 @@ export class ChatGPTQueue extends DurableQueueCore {
130
132
  db.exec(
131
133
  `CREATE TABLE IF NOT EXISTS turns(seq INTEGER PRIMARY KEY AUTOINCREMENT,id TEXT NOT NULL UNIQUE,idem_key TEXT NOT NULL UNIQUE,project_id TEXT,thread_id TEXT NOT NULL,message TEXT NOT NULL,state TEXT NOT NULL,lease_owner TEXT,lease_until REAL,next_check_at REAL NOT NULL,created_at REAL NOT NULL,attempts INTEGER NOT NULL DEFAULT 0,receipt TEXT,mergeable INTEGER NOT NULL DEFAULT 0); CREATE INDEX IF NOT EXISTS turns_thread_order ON turns(thread_id,seq); CREATE TABLE IF NOT EXISTS merged_requests(idem_key TEXT PRIMARY KEY,project_id TEXT,thread_id TEXT NOT NULL,message TEXT NOT NULL,queue_id TEXT NOT NULL);`,
132
134
  );
133
- if (!db.prepare("PRAGMA table_info(turns)").all().some(row => row.name === "files_json")) {
135
+ const columns = db.prepare("PRAGMA table_info(turns)").all().map(row=>row.name);
136
+ if (!columns.includes('files_json'))
134
137
  db.exec("ALTER TABLE turns ADD COLUMN files_json TEXT NOT NULL DEFAULT '[]'");
135
- }
138
+ if (!columns.includes('enforcement_context'))
139
+ db.exec("ALTER TABLE turns ADD COLUMN enforcement_context TEXT NOT NULL DEFAULT ''");
136
140
  super(db, chatgptQueuePolicy, now, {
137
141
  concurrency: Math.min(4, Math.max(1, Number(concurrency) || 4)), intervalMs,
138
142
  });
@@ -220,7 +224,7 @@ export class ChatGPTQueue extends DurableQueueCore {
220
224
  return response?.value ?? response;
221
225
  }
222
226
  async _probe(item) {
223
- const url = targetUrl(item.project_id, item.thread_id, item.message);
227
+ const url = targetUrl(item.project_id, item.thread_id, item.message, item.enforcement_context);
224
228
  const session = await this.startSession({ url });
225
229
  const sid = session.session_id ?? session.sessionId;
226
230
  if (!sid) throw new Error("session start returned no session_id");
@@ -247,7 +251,7 @@ export class ChatGPTQueue extends DurableQueueCore {
247
251
  const attachments = JSON.parse(item.files_json || "[]");
248
252
  let tempDir;
249
253
  try {
250
- if (item.message.length > PROMPT_FILE_THRESHOLD) {
254
+ if (requiresPromptFile(item.message,item.enforcement_context)) {
251
255
  tempDir = mkdtempSync(join(tmpdir(), "webhelm-prompt-"));
252
256
  const promptPath = join(tempDir, "prompt.md");
253
257
  writeFileSync(promptPath, item.message, {encoding:"utf8",mode:0o600});
@@ -257,7 +261,7 @@ export class ChatGPTQueue extends DurableQueueCore {
257
261
  const upload = await this._exec(sid, attachmentUploadScript(attachments));
258
262
  if (!upload?.ready) throw new Error("ChatGPT attachments not ready for Send");
259
263
  }
260
- return await this._exec(sid, submissionScript({...item, message:deliveryMessage(item.message)}));
264
+ return await this._exec(sid, submissionScript({...item, message:deliveryMessage(item.message,item.enforcement_context)}));
261
265
  } finally {
262
266
  if (tempDir) rmSync(tempDir, {recursive:true,force:true});
263
267
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "WebHelm",
4
- "version": "1.0.46",
4
+ "version": "1.0.48",
5
5
  "description": "Own named Chrome tab-group workspaces and lazy reusable tab pools for browser agents.",
6
6
  "permissions": [
7
7
  "storage",