@hmharness/cli 0.23.21 → 0.23.22
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/dist/acp-serve.d.ts +5 -5
- package/dist/acp-serve.js +95 -41
- package/package.json +14 -14
package/dist/acp-serve.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type ChatMessage } from '@hmharness/kernel';
|
|
2
2
|
import { type RunnerEvents } from '@hmharness/agent';
|
|
3
|
-
/** close every window NOT in the
|
|
4
|
-
* (the host's per-connection workspace windows
|
|
5
|
-
*
|
|
6
|
-
* never
|
|
7
|
-
export declare function recycleBlankWindows(port: number,
|
|
3
|
+
/** close every window NOT in the protected snapshot whose tabs are ALL
|
|
4
|
+
* blank (the host's per-connection workspace windows). Protected-set
|
|
5
|
+
* windows — everything that existed when our connection initialized —
|
|
6
|
+
* are never touched. Returns how many closed; never throws. */
|
|
7
|
+
export declare function recycleBlankWindows(port: number, protectedWindows: Set<number>): Promise<number>;
|
|
8
8
|
interface AcpSession {
|
|
9
9
|
cwd: string;
|
|
10
10
|
/** hmh rollout id once the first prompt ran (resume appends) */
|
package/dist/acp-serve.js
CHANGED
|
@@ -100,16 +100,16 @@ async function listContentWindows(port) {
|
|
|
100
100
|
}
|
|
101
101
|
return content;
|
|
102
102
|
}
|
|
103
|
-
/** close every window NOT in the
|
|
104
|
-
* (the host's per-connection workspace windows
|
|
105
|
-
*
|
|
106
|
-
* never
|
|
107
|
-
export async function recycleBlankWindows(port,
|
|
103
|
+
/** close every window NOT in the protected snapshot whose tabs are ALL
|
|
104
|
+
* blank (the host's per-connection workspace windows). Protected-set
|
|
105
|
+
* windows — everything that existed when our connection initialized —
|
|
106
|
+
* are never touched. Returns how many closed; never throws. */
|
|
107
|
+
export async function recycleBlankWindows(port, protectedWindows) {
|
|
108
108
|
try {
|
|
109
109
|
const current = await listHostWindows(port);
|
|
110
110
|
let closed = 0;
|
|
111
111
|
for (const windowId of current) {
|
|
112
|
-
if (
|
|
112
|
+
if (protectedWindows.has(windowId))
|
|
113
113
|
continue;
|
|
114
114
|
try {
|
|
115
115
|
if (await windowIsBlank(port, windowId)) {
|
|
@@ -201,18 +201,46 @@ export function createAcpServer(opts) {
|
|
|
201
201
|
// implement (initialize/new/load/prompt/cancel/update/permission) is
|
|
202
202
|
// stable across the 0.4 interop baseline and later additions are
|
|
203
203
|
// optional; a hard version mismatch would just refuse to connect.
|
|
204
|
-
// loadSession
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
204
|
+
// loadSession + sessionCapabilities: the host treats agents that
|
|
205
|
+
// declare session-lifecycle capabilities (close/delete/fork/list/
|
|
206
|
+
// resume — observed on the built-in claude-agent-acp) as long-lived
|
|
207
|
+
// manageable sessions and REUSES the connection; without them it
|
|
208
|
+
// spawns a fresh agent (and a fresh workspace WINDOW) per message —
|
|
209
|
+
// the exact "a new browser window on every message" bug.
|
|
208
210
|
ok({
|
|
209
211
|
protocolVersion: m.params?.protocolVersion ?? '0',
|
|
210
|
-
agentCapabilities: {
|
|
212
|
+
agentCapabilities: {
|
|
213
|
+
loadSession: true,
|
|
214
|
+
sessionCapabilities: {
|
|
215
|
+
additionalDirectories: {},
|
|
216
|
+
close: {},
|
|
217
|
+
delete: {},
|
|
218
|
+
fork: {},
|
|
219
|
+
list: {},
|
|
220
|
+
resume: {},
|
|
221
|
+
},
|
|
222
|
+
// the host hands every session a browser MCP over http (with an
|
|
223
|
+
// internal lease header) — declaring we speak http MCP may be
|
|
224
|
+
// what keeps it from provisioning a workspace WINDOW instead
|
|
225
|
+
mcpCapabilities: { http: true, sse: false },
|
|
226
|
+
},
|
|
211
227
|
authMethods: [],
|
|
212
228
|
});
|
|
213
229
|
await opts.onInitialized?.().catch(() => undefined);
|
|
214
230
|
return;
|
|
215
231
|
}
|
|
232
|
+
case 'session/close':
|
|
233
|
+
case 'session/delete': {
|
|
234
|
+
const sid = m.params?.sessionId;
|
|
235
|
+
if (sid)
|
|
236
|
+
sessions.delete(sid);
|
|
237
|
+
ok({});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
case 'session/list': {
|
|
241
|
+
ok({ sessions: [...sessions.keys()].map((id) => ({ sessionId: id, ...(sessions.get(id).hmhId ? { title: sessions.get(id).hmhId } : {}) })) });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
216
244
|
case 'authenticate': {
|
|
217
245
|
ok({});
|
|
218
246
|
return;
|
|
@@ -225,10 +253,14 @@ export function createAcpServer(opts) {
|
|
|
225
253
|
ok({ sessionId });
|
|
226
254
|
return;
|
|
227
255
|
}
|
|
228
|
-
case 'session/load':
|
|
256
|
+
case 'session/load':
|
|
257
|
+
case 'session/resume': {
|
|
258
|
+
// `session/resume` is the acpx host's name for the same operation
|
|
259
|
+
// (observed on the wire) — both register the prior session and
|
|
260
|
+
// restore its transcript from the hmh rollout.
|
|
229
261
|
const sid = typeof m.params?.sessionId === 'string' ? m.params.sessionId : '';
|
|
230
262
|
if (!sid) {
|
|
231
|
-
err(m.id, -32602,
|
|
263
|
+
err(m.id, -32602, `${m.method} needs sessionId`);
|
|
232
264
|
return;
|
|
233
265
|
}
|
|
234
266
|
if (!sessions.has(sid)) {
|
|
@@ -361,6 +393,15 @@ export function createAcpServer(opts) {
|
|
|
361
393
|
return;
|
|
362
394
|
}
|
|
363
395
|
default: {
|
|
396
|
+
// unknown session/* methods: answer tolerantly with {} (the host's
|
|
397
|
+
// extended session vocabulary evolves; a hard -32601 made it fall
|
|
398
|
+
// back to fresh-session-per-message behavior). The wire log records
|
|
399
|
+
// every such call so we can implement the ones the host actually
|
|
400
|
+
// uses.
|
|
401
|
+
if (isRequest && m.method.startsWith('session/')) {
|
|
402
|
+
ok({});
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
364
405
|
if (isRequest)
|
|
365
406
|
err(m.id, -32601, `method not found: ${m.method}`);
|
|
366
407
|
}
|
|
@@ -404,15 +445,18 @@ export async function serveAcp() {
|
|
|
404
445
|
});
|
|
405
446
|
},
|
|
406
447
|
};
|
|
407
|
-
// window-recycling
|
|
408
|
-
//
|
|
409
|
-
//
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
//
|
|
448
|
+
// window-recycling (host browser only), SNAPSHOT-based — the safe design
|
|
449
|
+
// after the 2026-10-04 incident. The host opens a blank workspace window
|
|
450
|
+
// for every new agent connection (per-message in practice). W0 = ALL
|
|
451
|
+
// window ids at initialize time; sweeps close ONLY windows that (a) are
|
|
452
|
+
// not in W0 AND (b) currently hold nothing but blank tabs. The user's own
|
|
453
|
+
// windows ALWAYS predate our connection → they are in W0 → they can
|
|
454
|
+
// never be closed, even mid-load (the incident's failure mode). The one
|
|
455
|
+
// residual risk: a blank window the USER opens during our connection
|
|
456
|
+
// lifetime — accepted, it is empty by definition. No initialize (host
|
|
457
|
+
// skip) → no recycling (miss, never misfire).
|
|
414
458
|
const attachPort = Number(process.env.HMH_BROWSER_ATTACH ?? 0);
|
|
415
|
-
let
|
|
459
|
+
let w0Snapshot = null;
|
|
416
460
|
const recycleLog = async (msg) => {
|
|
417
461
|
console.error(`[acp-window] ${msg}`);
|
|
418
462
|
try {
|
|
@@ -424,35 +468,28 @@ export async function serveAcp() {
|
|
|
424
468
|
catch { /* logging is best-effort */ }
|
|
425
469
|
};
|
|
426
470
|
const sweep = async (why) => {
|
|
427
|
-
if (!
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
const closed = await recycleBlankWindows(attachPort, contentBaseline);
|
|
432
|
-
contentBaseline = await listContentWindows(attachPort).catch(() => contentBaseline);
|
|
433
|
-
await recycleLog(`${why}: closed=${closed} contentWindows=${contentBaseline?.size ?? '?'}`);
|
|
471
|
+
if (!w0Snapshot)
|
|
472
|
+
return; // no initialize → no snapshot → never sweep
|
|
473
|
+
const closed = await recycleBlankWindows(attachPort, w0Snapshot);
|
|
474
|
+
await recycleLog(`${why}: closed=${closed} (W0=${w0Snapshot.size})`);
|
|
434
475
|
};
|
|
435
|
-
const
|
|
476
|
+
const recycleEnabled = process.env.HMH_BROWSER_RECYCLE !== '0' && Number.isInteger(attachPort) && attachPort > 0;
|
|
477
|
+
const hooks = recycleEnabled
|
|
436
478
|
? {
|
|
437
479
|
onInitialized: async () => {
|
|
438
|
-
|
|
439
|
-
await recycleLog(`initialize:
|
|
440
|
-
// opening sweep: recycle whatever blank windows earlier
|
|
441
|
-
// connections left behind (the host may hard-kill us between
|
|
442
|
-
// messages — taskkill gives no stdin-close cleanup chance)
|
|
443
|
-
await sweep('opening');
|
|
480
|
+
w0Snapshot = await listHostWindows(attachPort).catch(() => null);
|
|
481
|
+
await recycleLog(`initialize: W0 snapshot = ${w0Snapshot?.size ?? 'unavailable'} windows`);
|
|
444
482
|
},
|
|
445
483
|
onTurnSettled: async () => {
|
|
446
484
|
await sweep('turn-settled');
|
|
447
|
-
// the host sometimes opens the workspace window AFTER the stop
|
|
448
|
-
// response — sweep again shortly, fire-and-forget
|
|
449
|
-
void (async () => {
|
|
450
|
-
await new Promise((r) => setTimeout(r, 2_500));
|
|
451
|
-
await sweep('turn-settled+2.5s').catch(() => undefined);
|
|
452
|
-
})();
|
|
453
485
|
},
|
|
454
486
|
}
|
|
455
487
|
: {};
|
|
488
|
+
let residentTimer = null;
|
|
489
|
+
if (recycleEnabled) {
|
|
490
|
+
residentTimer = setInterval(() => { void sweep('resident').catch(() => undefined); }, 2_000);
|
|
491
|
+
residentTimer.unref?.();
|
|
492
|
+
}
|
|
456
493
|
const server = createAcpServer({ io, ...hooks });
|
|
457
494
|
const rl = readline.createInterface({ input: process.stdin });
|
|
458
495
|
rl.on('line', (line) => {
|
|
@@ -467,6 +504,21 @@ export async function serveAcp() {
|
|
|
467
504
|
console.error('[acp] unparseable frame:', text.slice(0, 120));
|
|
468
505
|
return;
|
|
469
506
|
}
|
|
507
|
+
// full wire log (host→agent frames): the single best forensic artifact
|
|
508
|
+
// for host-behavior mysteries. Truncated params keep it bounded.
|
|
509
|
+
void (async () => {
|
|
510
|
+
try {
|
|
511
|
+
const { appendFile, mkdir } = await import('node:fs/promises');
|
|
512
|
+
const logsDir = join(homeDir(), 'logs');
|
|
513
|
+
await mkdir(logsDir, { recursive: true });
|
|
514
|
+
const m = msg;
|
|
515
|
+
const brief = m.method
|
|
516
|
+
? `${m.method} id=${String(m.id)} params=${JSON.stringify(m.params ?? {}).slice(0, 400)}`
|
|
517
|
+
: `response id=${String(m.id)} ${JSON.stringify(msg).slice(0, 200)}`;
|
|
518
|
+
await appendFile(join(logsDir, 'acp-wire.log'), `${new Date().toISOString()} ${brief}\n`, 'utf8');
|
|
519
|
+
}
|
|
520
|
+
catch { /* best-effort */ }
|
|
521
|
+
})();
|
|
470
522
|
// responses to OUR agent→client requests (permissions)
|
|
471
523
|
if ((msg.id !== undefined) && !('method' in msg)) {
|
|
472
524
|
const entry = pending.get(Number(msg.id));
|
|
@@ -486,6 +538,8 @@ export async function serveAcp() {
|
|
|
486
538
|
rl.on('close', async () => {
|
|
487
539
|
for (const [, p] of pending)
|
|
488
540
|
p.reject(new Error('client disconnected'));
|
|
541
|
+
if (residentTimer)
|
|
542
|
+
clearInterval(residentTimer);
|
|
489
543
|
// last-chance sweep: the host disposes us between messages, and the
|
|
490
544
|
// workspace window it gave this connection would otherwise linger
|
|
491
545
|
await Promise.race([sweep('disconnect'), new Promise((r) => setTimeout(r, 6_000))]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.22",
|
|
4
4
|
"description": "hmharness command line: one-shot tasks, an interactive REPL, a fullscreen TUI, the web frontend, and direct tool invocation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
"build": "tsc -p tsconfig.build.json"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@hmharness/agent": "0.23.
|
|
48
|
-
"@hmharness/browser": "0.23.
|
|
49
|
-
"@hmharness/cognitive": "0.23.
|
|
50
|
-
"@hmharness/domain-harmony": "0.23.
|
|
51
|
-
"@hmharness/domain-ops": "0.23.
|
|
52
|
-
"@hmharness/environments": "0.23.
|
|
53
|
-
"@hmharness/evaluation": "0.23.
|
|
54
|
-
"@hmharness/evolution": "0.23.
|
|
55
|
-
"@hmharness/kernel": "0.23.
|
|
56
|
-
"@hmharness/observability": "0.23.
|
|
57
|
-
"@hmharness/sandbox": "0.23.
|
|
58
|
-
"@hmharness/web": "0.23.
|
|
47
|
+
"@hmharness/agent": "0.23.22",
|
|
48
|
+
"@hmharness/browser": "0.23.22",
|
|
49
|
+
"@hmharness/cognitive": "0.23.22",
|
|
50
|
+
"@hmharness/domain-harmony": "0.23.22",
|
|
51
|
+
"@hmharness/domain-ops": "0.23.22",
|
|
52
|
+
"@hmharness/environments": "0.23.22",
|
|
53
|
+
"@hmharness/evaluation": "0.23.22",
|
|
54
|
+
"@hmharness/evolution": "0.23.22",
|
|
55
|
+
"@hmharness/kernel": "0.23.22",
|
|
56
|
+
"@hmharness/observability": "0.23.22",
|
|
57
|
+
"@hmharness/sandbox": "0.23.22",
|
|
58
|
+
"@hmharness/web": "0.23.22",
|
|
59
59
|
"qrcode": "^1.5.4",
|
|
60
|
-
"@hmharness/lsp": "0.23.
|
|
60
|
+
"@hmharness/lsp": "0.23.22"
|
|
61
61
|
}
|
|
62
62
|
}
|