@hmharness/cli 0.23.37 → 0.23.38
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/board/install-kaihongos.cjs +3 -3
- package/dist/extension-agent-brain.d.ts +50 -0
- package/dist/extension-agent-brain.js +119 -0
- package/dist/extension-chat.d.ts +29 -8
- package/dist/extension-chat.js +270 -51
- package/dist/main.js +68 -7
- package/dist/tui-mouse.d.ts +54 -0
- package/dist/tui-mouse.js +79 -0
- package/dist/tui.d.ts +4 -0
- package/dist/tui.js +76 -1
- package/dist/web-daemon.d.ts +6 -0
- package/dist/web-daemon.js +116 -1
- package/package.json +15 -15
- package/release-notes.json +5 -0
|
@@ -63,9 +63,9 @@ let PACKAGES = ['cli', 'web', 'agent', 'kernel', 'sandbox', 'evolution',
|
|
|
63
63
|
// The release bot keeps versions synced; the NAMES must cover the full
|
|
64
64
|
// first-party set so the offline path cannot produce an incomplete tree.
|
|
65
65
|
const FALLBACK_PINS = {
|
|
66
|
-
cli: '0.23.
|
|
67
|
-
sandbox: '0.23.
|
|
68
|
-
evaluation: '0.23.
|
|
66
|
+
cli: '0.23.38', web: '0.23.38', agent: '0.23.38', kernel: '0.23.38',
|
|
67
|
+
sandbox: '0.23.38', evolution: '0.23.38', 'domain-ops': '0.23.38',
|
|
68
|
+
evaluation: '0.23.38', observability: '0.23.38', 'domain-harmony': '0.23.38',
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
// ---------- helpers ---------------------------------------------------------
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cli - extension chat via the REAL agent (round 52)
|
|
3
|
+
*
|
|
4
|
+
* The user's side-by-side verdict: the BrowserOS panel (hmh acp-serve) and
|
|
5
|
+
* the extension sidebar were "the same hmh CLI AI" in name only — acp-serve
|
|
6
|
+
* runs runAgentTask (full tool registry + the real system prompt with
|
|
7
|
+
* memory/skills/insights + session continuity), while the sidebar was a
|
|
8
|
+
* hand-rolled chat loop. This module converges them: one chat turn = one
|
|
9
|
+
* runAgentTask on a per-origin SESSION (conversations continue like a real
|
|
10
|
+
* agent thread), tools/events/approval wired:
|
|
11
|
+
* - events.onToolCall/onToolResult → the live activity feed
|
|
12
|
+
* - approvalAsk → the conversational confirm gate: deny now, record the
|
|
13
|
+
* exact call, the user's 「确认」 next turn executes it pre-loop and
|
|
14
|
+
* injects the result (identical contract to the compact brain)
|
|
15
|
+
* - proactive page context rides as task prefix (round 48 discipline)
|
|
16
|
+
* - wall-clock abort at the segment boundary → auto-continue sentinel
|
|
17
|
+
*/
|
|
18
|
+
import type { ChatTurnInput, PageAct } from '@hmharness/extension';
|
|
19
|
+
import type { Registry, ToolContext } from '@hmharness/kernel';
|
|
20
|
+
/** what serve injects: the agent machinery + the bridge page channel */
|
|
21
|
+
export interface AgentBrainEnv {
|
|
22
|
+
buildRegistry: () => Promise<{
|
|
23
|
+
reg: Registry;
|
|
24
|
+
}>;
|
|
25
|
+
/** native-only rebuild (no MCP servers) for the degraded path */
|
|
26
|
+
buildRegistryNative?: () => Promise<{
|
|
27
|
+
reg: Registry;
|
|
28
|
+
}>;
|
|
29
|
+
runAgentTask: (opts: Record<string, unknown>) => Promise<{
|
|
30
|
+
text: string;
|
|
31
|
+
turns: number;
|
|
32
|
+
toolUses: number;
|
|
33
|
+
sessionId: string;
|
|
34
|
+
}>;
|
|
35
|
+
ctx: ToolContext;
|
|
36
|
+
/** bridge page channel: goto + proactive read (http/https enforced bridge-side) */
|
|
37
|
+
goto: (url: string) => Promise<unknown>;
|
|
38
|
+
readPage: () => Promise<unknown>;
|
|
39
|
+
step: (line: string) => void;
|
|
40
|
+
log?: (line: string) => void;
|
|
41
|
+
/** per-request wall clock (tests inject milliseconds) */
|
|
42
|
+
segmentMs?: number;
|
|
43
|
+
}
|
|
44
|
+
/** One chat turn = one real agent task on the origin's session. */
|
|
45
|
+
export declare function answerWithAgentTurn(input: ChatTurnInput, env: AgentBrainEnv): Promise<string>;
|
|
46
|
+
/** the compact fallback path stays for brain-less/agent-less environments */
|
|
47
|
+
export type CompactDeps = {
|
|
48
|
+
readPage: () => Promise<unknown>;
|
|
49
|
+
act: (act: PageAct) => Promise<unknown>;
|
|
50
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { formatPageSnapshot, summarizePage } from '@hmharness/extension';
|
|
2
|
+
/** per-origin agent state: session id (conversation continuity) + the last
|
|
3
|
+
* approval the user was asked to confirm (name+args, executed on 「确认」) */
|
|
4
|
+
const sessions = new Map();
|
|
5
|
+
const agentPending = new Map();
|
|
6
|
+
const CONFIRM_RE = /^(确认|确定|执行|同意|yes|ok)\s*$/i;
|
|
7
|
+
const SEGMENT_MS = 360_000;
|
|
8
|
+
const pageGotoTool = (goto) => ({
|
|
9
|
+
name: 'page_goto',
|
|
10
|
+
description: '把用户浏览器当前标签页导航到指定网址(http/https)。需要换页面时直接用。',
|
|
11
|
+
parameters: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: { url: { type: 'string', description: '完整网址,必须 http(s)://' } },
|
|
14
|
+
required: ['url'],
|
|
15
|
+
},
|
|
16
|
+
async execute(args) {
|
|
17
|
+
const url = String(args.url ?? '');
|
|
18
|
+
if (!/^https?:\/\//i.test(url))
|
|
19
|
+
return { output: 'page_goto 只允许 http/https 地址', isError: true };
|
|
20
|
+
return { output: JSON.stringify(await goto(url)).slice(0, 2000) };
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
async function pageContext(env) {
|
|
24
|
+
try {
|
|
25
|
+
const raw = await env.readPage();
|
|
26
|
+
if (!raw || typeof raw !== 'object')
|
|
27
|
+
return '';
|
|
28
|
+
return `\n\n【用户当前浏览器页面 · 自动附上】\n${formatPageSnapshot(summarizePage(raw)).slice(0, 6000)}`;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return ''; // proactive context is a bonus, never a blocker
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** One chat turn = one real agent task on the origin's session. */
|
|
35
|
+
export async function answerWithAgentTurn(input, env) {
|
|
36
|
+
const origin = input.origin ?? 'anon';
|
|
37
|
+
env.step('组装工具注册表…');
|
|
38
|
+
let reg;
|
|
39
|
+
try {
|
|
40
|
+
reg = (await Promise.race([
|
|
41
|
+
env.buildRegistry(),
|
|
42
|
+
new Promise((_, rej) => setTimeout(() => rej(new Error('registry build timeout (30s)')), 30_000)),
|
|
43
|
+
])).reg;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
// a dead/slow MCP server must not black-hole the FIRST turn of a fresh
|
|
47
|
+
// daemon (field-caught round 53: 888s of silence before any step) —
|
|
48
|
+
// degrade to the native registry (everything except MCP tools)
|
|
49
|
+
env.step(`注册表组装超时——降级为原生工具集(不含 MCP)`);
|
|
50
|
+
if (!env.buildRegistryNative)
|
|
51
|
+
throw err;
|
|
52
|
+
reg = (await Promise.race([
|
|
53
|
+
env.buildRegistryNative(),
|
|
54
|
+
new Promise((_, rej) => setTimeout(() => rej(new Error('native fallback timeout')), 15_000)),
|
|
55
|
+
])).reg;
|
|
56
|
+
}
|
|
57
|
+
env.step('注册表就绪');
|
|
58
|
+
// the bridge page channel joins the real registry (idempotent by name)
|
|
59
|
+
try {
|
|
60
|
+
reg.register(pageGotoTool(env.goto));
|
|
61
|
+
}
|
|
62
|
+
catch { /* already there */ }
|
|
63
|
+
// resolve last turn's pending approval: 「确认」 executes it pre-loop
|
|
64
|
+
let prefix = '';
|
|
65
|
+
const pending = agentPending.get(origin);
|
|
66
|
+
agentPending.delete(origin);
|
|
67
|
+
if (pending) {
|
|
68
|
+
if (CONFIRM_RE.test(input.message.trim())) {
|
|
69
|
+
env.step(`确认执行: ${pending.summary}`);
|
|
70
|
+
env.log?.(`侧栏确认执行(agent): ${pending.summary}`);
|
|
71
|
+
try {
|
|
72
|
+
const r = await pending.reg.get(pending.name)?.execute(pending.args, pending.ctx);
|
|
73
|
+
prefix = `【已执行: ${pending.summary}】\n${String(r?.output ?? '').slice(0, 4000)}\n\n`;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
prefix = `【执行失败: ${pending.summary}】${String(err instanceof Error ? err.message : err).slice(0, 300)}\n\n`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
prefix = `【已取消: ${pending.summary}(用户未确认)】\n\n`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const task = `${prefix}${input.message}${await pageContext(env)}`;
|
|
84
|
+
const sessionId = sessions.get(origin);
|
|
85
|
+
const ac = new AbortController();
|
|
86
|
+
const bail = setTimeout(() => { try {
|
|
87
|
+
ac.abort();
|
|
88
|
+
}
|
|
89
|
+
catch { /* gone */ } }, env.segmentMs ?? SEGMENT_MS);
|
|
90
|
+
try {
|
|
91
|
+
const r = await env.runAgentTask({
|
|
92
|
+
task,
|
|
93
|
+
registry: reg,
|
|
94
|
+
ctx: env.ctx,
|
|
95
|
+
...(sessionId ? { sessionId } : {}),
|
|
96
|
+
signal: ac.signal,
|
|
97
|
+
events: {
|
|
98
|
+
onToolCall: (name, args) => env.step(`工具 ${name}: ${JSON.stringify(args).slice(0, 80)}`),
|
|
99
|
+
onToolResult: (name, output, isError) => env.step(isError ? `${name} 失败: ${output.slice(0, 80)}` : `${name} 完成`),
|
|
100
|
+
},
|
|
101
|
+
approvalAsk: async (name, args) => {
|
|
102
|
+
const summary = `${name} ${JSON.stringify(args).slice(0, 100)}`;
|
|
103
|
+
agentPending.set(origin, { name, args, summary, reg, ctx: env.ctx });
|
|
104
|
+
env.step(`待确认: ${summary}`);
|
|
105
|
+
return false; // the model relays the ask; 「确认」 executes next turn
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
sessions.set(origin, r.sessionId);
|
|
109
|
+
return r.text?.trim() || '(模型返回了空回复)';
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
if (ac.signal.aborted)
|
|
113
|
+
return '(这一段到达时间边界,已收尾——任务未完,自动继续。)\n[[hmh:auto-continue]]';
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
clearTimeout(bail);
|
|
118
|
+
}
|
|
119
|
+
}
|
package/dist/extension-chat.d.ts
CHANGED
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @hmharness/cli - extension chat brain (
|
|
2
|
+
* @hmharness/cli - extension chat brain (rounds 45/48/49)
|
|
3
3
|
*
|
|
4
|
-
* The other end of the browser-side chat panel:
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The other end of the browser-side chat panel: an agent turn that HAS the
|
|
5
|
+
* current page (proactive pre-read, round 48) plus — when the serve process
|
|
6
|
+
* wires them — navigation, tabs, workspace files and shell commands (round
|
|
7
|
+
* 49: the user called the two-tool version "crippled"; this is the full
|
|
8
|
+
* hmharness capability set, with a CONVERSATIONAL approval gate for the
|
|
9
|
+
* dangerous ones: the model proposes, the user types 「确认」).
|
|
9
10
|
*/
|
|
10
11
|
import { chat, type ProviderConfig } from '@hmharness/kernel';
|
|
11
12
|
import type { ChatTurnInput, PageAct } from '@hmharness/extension';
|
|
12
13
|
export interface ChatBrainDeps {
|
|
13
14
|
readPage: () => Promise<unknown>;
|
|
14
15
|
act: (act: PageAct) => Promise<unknown>;
|
|
15
|
-
/** audit line sink — page_act
|
|
16
|
+
/** audit line sink — page_act and confirmed commands are logged */
|
|
16
17
|
log?: (line: string) => void;
|
|
18
|
+
/** navigate the user's active tab (http/https enforced both ends) */
|
|
19
|
+
goto?: (url: string) => Promise<unknown>;
|
|
20
|
+
listTabs?: () => Promise<unknown>;
|
|
21
|
+
/** shell — ToolResult-shaped { output, isError? } from the agent's runCommandTool */
|
|
22
|
+
runCommand?: (command: string, timeoutMs?: number) => Promise<unknown>;
|
|
23
|
+
readFile?: (path: string) => Promise<unknown>;
|
|
24
|
+
writeFile?: (path: string, content: string) => Promise<unknown>;
|
|
25
|
+
listDir?: (path: string) => Promise<unknown>;
|
|
26
|
+
/** the working directory commands/files resolve against (told to the model) */
|
|
27
|
+
workspace?: string;
|
|
28
|
+
/** LIVE activity feed (round 50): every step lands in the panel while it waits */
|
|
29
|
+
step?: (line: string) => void;
|
|
17
30
|
}
|
|
31
|
+
/** PROACTIVE page context (round 48): read the user's current tab BEFORE the
|
|
32
|
+
* model runs, so even a tool-call-less model already HAS the page. A failed
|
|
33
|
+
* read becomes an honest note in the prompt, never a silent blank. */
|
|
34
|
+
/** PROACTIVE page context (round 48): read the user's current tab BEFORE the
|
|
35
|
+
* model runs, so even a tool-call-less model already HAS the page. A failed
|
|
36
|
+
* read becomes an honest note in the prompt, never a silent blank.
|
|
37
|
+
* Takes only the readPage sliver — the full brain deps are not needed. */
|
|
38
|
+
export declare function readPageContext(deps: Pick<ChatBrainDeps, 'readPage'>): Promise<string>;
|
|
18
39
|
/** Run ONE conversational turn (message + history → reply string). */
|
|
19
40
|
export declare function answerChatTurn(input: ChatTurnInput, deps: ChatBrainDeps): Promise<string>;
|
|
20
41
|
/** The tool loop, separated so tests can inject a fake chat implementation. */
|
|
21
|
-
export declare function runChatTurn(provider: ProviderConfig, input: ChatTurnInput, deps: ChatBrainDeps, chatImpl: typeof chat): Promise<string>;
|
|
42
|
+
export declare function runChatTurn(provider: ProviderConfig, input: ChatTurnInput, deps: ChatBrainDeps, chatImpl: typeof chat, origin?: string, maxRounds?: number, wallClockMs?: number): Promise<string>;
|
package/dist/extension-chat.js
CHANGED
|
@@ -1,93 +1,312 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @hmharness/cli - extension chat brain (
|
|
2
|
+
* @hmharness/cli - extension chat brain (rounds 45/48/49)
|
|
3
3
|
*
|
|
4
|
-
* The other end of the browser-side chat panel:
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The other end of the browser-side chat panel: an agent turn that HAS the
|
|
5
|
+
* current page (proactive pre-read, round 48) plus — when the serve process
|
|
6
|
+
* wires them — navigation, tabs, workspace files and shell commands (round
|
|
7
|
+
* 49: the user called the two-tool version "crippled"; this is the full
|
|
8
|
+
* hmharness capability set, with a CONVERSATIONAL approval gate for the
|
|
9
|
+
* dangerous ones: the model proposes, the user types 「确认」).
|
|
9
10
|
*/
|
|
10
11
|
import { loadConfig, resolveProvider, chat } from '@hmharness/kernel';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
import { formatPageSnapshot, summarizePage } from '@hmharness/extension';
|
|
13
|
+
/** round bound: the CLI's own maxTurns guard, floored at 50 for the sidebar
|
|
14
|
+
* (round 49: hand over a task, get it FINISHED — the panel auto-continues
|
|
15
|
+
* past the budget via the sentinel, so the floor only guards one HTTP
|
|
16
|
+
* request against infinite loops, never the task). */
|
|
17
|
+
const DEFAULT_MAX_ROUNDS = 50;
|
|
18
|
+
/** pending confirmation per chat origin: the model proposed, we wait for 「确认」 */
|
|
19
|
+
const pendingConfirm = new Map();
|
|
20
|
+
const CONFIRM_RE = /^(确认|确定|执行|同意|yes|ok)\s*$/i;
|
|
21
|
+
function baseTools() {
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
type: 'function',
|
|
25
|
+
function: {
|
|
26
|
+
name: 'page_read',
|
|
27
|
+
description: '重新读取用户当前浏览器标签页(内容可能已变)。回答页面问题前若已附有自动读取的内容,先基于它回答。',
|
|
28
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
29
|
+
},
|
|
20
30
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
{
|
|
32
|
+
type: 'function',
|
|
33
|
+
function: {
|
|
34
|
+
name: 'page_act',
|
|
35
|
+
description: '操作用户当前标签页(click/type/scroll/select)。动作会在用户眼前执行;不确定时先 page_read 看页面、再问用户。',
|
|
36
|
+
parameters: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
action: { type: 'string', enum: ['click', 'type', 'scroll', 'select'] },
|
|
40
|
+
selector: { type: 'string', description: '目标元素的 CSS 选择器' },
|
|
41
|
+
text: { type: 'string', description: 'action=type 时要输入的文本' },
|
|
42
|
+
direction: { type: 'string', enum: ['up', 'down', 'top', 'bottom'], description: 'action=scroll 时的方向' },
|
|
43
|
+
},
|
|
44
|
+
required: ['action'],
|
|
34
45
|
},
|
|
35
|
-
required: ['action'],
|
|
36
46
|
},
|
|
37
47
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
function extendedTools(deps) {
|
|
51
|
+
const tools = baseTools();
|
|
52
|
+
if (deps.goto) {
|
|
53
|
+
tools.push({
|
|
54
|
+
type: 'function',
|
|
55
|
+
function: {
|
|
56
|
+
name: 'page_goto',
|
|
57
|
+
description: '把用户当前标签页导航到指定网址(http/https)。页面打不开/需要换页面时直接用它,不要请用户手动开。',
|
|
58
|
+
parameters: { type: 'object', properties: { url: { type: 'string', description: '完整网址,必须 http(s)://' } }, required: ['url'] },
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (deps.listTabs) {
|
|
63
|
+
tools.push({
|
|
64
|
+
type: 'function',
|
|
65
|
+
function: {
|
|
66
|
+
name: 'tabs_list',
|
|
67
|
+
description: '列出用户浏览器当前打开的全部标签页。',
|
|
68
|
+
parameters: { type: 'object', properties: {} },
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (deps.runCommand) {
|
|
73
|
+
tools.push({
|
|
74
|
+
type: 'function',
|
|
75
|
+
function: {
|
|
76
|
+
name: 'run_command',
|
|
77
|
+
description: '在工作目录执行一条终端命令(npm/git 等)。危险操作会先征求用户确认——把确认提示原样转达给用户。',
|
|
78
|
+
parameters: {
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: { command: { type: 'string', description: '单行命令' }, timeout_ms: { type: 'number', description: '超时毫秒(默认 60000,最大 300000)' } },
|
|
81
|
+
required: ['command'],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (deps.readFile) {
|
|
87
|
+
tools.push({
|
|
88
|
+
type: 'function',
|
|
89
|
+
function: {
|
|
90
|
+
name: 'read_file',
|
|
91
|
+
description: '读取工作目录中的文件内容。',
|
|
92
|
+
parameters: { type: 'object', properties: { path: { type: 'string', description: '文件路径' } }, required: ['path'] },
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (deps.listDir) {
|
|
97
|
+
tools.push({
|
|
98
|
+
type: 'function',
|
|
99
|
+
function: {
|
|
100
|
+
name: 'list_dir',
|
|
101
|
+
description: '列出工作目录中某路径下的内容。',
|
|
102
|
+
parameters: { type: 'object', properties: { path: { type: 'string', description: '目录路径(空 = 工作目录)' } }, required: ['path'] },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (deps.writeFile) {
|
|
107
|
+
tools.push({
|
|
108
|
+
type: 'function',
|
|
109
|
+
function: {
|
|
110
|
+
name: 'write_file',
|
|
111
|
+
description: '写入/覆盖工作目录中的文件。会先征求用户确认。',
|
|
112
|
+
parameters: { type: 'object', properties: { path: { type: 'string' }, content: { type: 'string' } }, required: ['path', 'content'] },
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return tools;
|
|
117
|
+
}
|
|
118
|
+
function systemPrompt(input, pageBlock, deps) {
|
|
42
119
|
const lines = [
|
|
43
|
-
'你是 hmharness
|
|
44
|
-
'
|
|
120
|
+
'你是 hmharness 智能体的浏览器侧栏形态,用简洁中文工作。',
|
|
121
|
+
'页面能力:当前页面内容已自动附上;可用 page_read 重读、page_act 操作、page_goto 导航、tabs_list 列标签页。',
|
|
45
122
|
];
|
|
123
|
+
if (deps.runCommand) {
|
|
124
|
+
lines.push(`终端能力:工作目录 ${deps.workspace ?? '(serve 进程目录)'} 下可 run_command(执行命令)、read_file / write_file / list_dir(文件操作)。修改类与命令类操作需用户逐次确认——把确认提示原样转达,用户回复「确认」后才执行。`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
lines.push('本会话未接入终端/文件能力(仅页面能力)。');
|
|
128
|
+
}
|
|
129
|
+
lines.push('页面打不开时先 page_goto,不要请用户手动操作。回答基于证据;做不到就明说。');
|
|
130
|
+
lines.push('任务策略:Dependabot/安全告警/CI 报错等通知类任务——邮件只是通知,病根在本地代码与依赖锁定文件里;直接用文件读写+命令在本地修复并 git 提交推送即可关闭远程告警,除非明确需要网页上的信息,否则不要去操作网页。');
|
|
46
131
|
if (input.page?.url)
|
|
47
132
|
lines.push(`用户当前标签页: ${input.page.title ?? '(无标题)'} — ${input.page.url}`);
|
|
133
|
+
if (pageBlock)
|
|
134
|
+
lines.push(pageBlock);
|
|
48
135
|
return lines.join('\n');
|
|
49
136
|
}
|
|
137
|
+
/** PROACTIVE page context (round 48): read the user's current tab BEFORE the
|
|
138
|
+
* model runs, so even a tool-call-less model already HAS the page. A failed
|
|
139
|
+
* read becomes an honest note in the prompt, never a silent blank. */
|
|
140
|
+
/** PROACTIVE page context (round 48): read the user's current tab BEFORE the
|
|
141
|
+
* model runs, so even a tool-call-less model already HAS the page. A failed
|
|
142
|
+
* read becomes an honest note in the prompt, never a silent blank.
|
|
143
|
+
* Takes only the readPage sliver — the full brain deps are not needed. */
|
|
144
|
+
export async function readPageContext(deps) {
|
|
145
|
+
try {
|
|
146
|
+
const raw = await deps.readPage();
|
|
147
|
+
if (!raw || typeof raw !== 'object')
|
|
148
|
+
return '【当前页面】读取无结果(受保护页面或站点权限未授予)。';
|
|
149
|
+
const text = formatPageSnapshot(summarizePage(raw)).slice(0, 6000);
|
|
150
|
+
return `【当前页面 · 自动读取】\n${text}`;
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
return `【当前页面】自动读取失败: ${String(err instanceof Error ? err.message : err).slice(0, 150)}(浏览器内置页/受保护页面无法读取;可尝试 page_goto 到普通网页)`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
50
156
|
/** Run ONE conversational turn (message + history → reply string). */
|
|
51
157
|
export async function answerChatTurn(input, deps) {
|
|
52
158
|
const cfg = await loadConfig();
|
|
53
159
|
const provider = resolveProvider(cfg, 'chat');
|
|
54
160
|
if (!provider?.apiKey)
|
|
55
161
|
throw new Error('尚未配置 LLM provider — 在网页端设置或运行 hmh web 设置密钥后重试');
|
|
56
|
-
|
|
162
|
+
const origin = input.origin ?? 'anon';
|
|
163
|
+
// pending-confirmation gate (round 49): 「确认」 executes, anything else cancels
|
|
164
|
+
const pending = pendingConfirm.get(origin);
|
|
165
|
+
pendingConfirm.delete(origin);
|
|
166
|
+
let executed = '';
|
|
167
|
+
if (pending) {
|
|
168
|
+
if (CONFIRM_RE.test(input.message.trim())) {
|
|
169
|
+
try {
|
|
170
|
+
const r = (await pending.run());
|
|
171
|
+
deps.log?.(`侧栏确认执行: ${pending.summary}`);
|
|
172
|
+
executed = `【已执行: ${pending.summary}】\n${String(r?.output ?? '').slice(0, 4000)}${r?.isError ? '\n(执行报错)' : ''}\n\n`;
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
executed = `【执行失败: ${pending.summary}】${String(err instanceof Error ? err.message : err).slice(0, 300)}\n\n`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
executed = `【已取消: ${pending.summary}(用户未确认)】\n\n`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return runChatTurn(provider, { ...input, message: executed + input.message }, deps, chat, origin, Math.max(cfg.maxTurns ?? DEFAULT_MAX_ROUNDS, DEFAULT_MAX_ROUNDS));
|
|
57
183
|
}
|
|
58
184
|
/** The tool loop, separated so tests can inject a fake chat implementation. */
|
|
59
|
-
export async function runChatTurn(provider, input, deps, chatImpl) {
|
|
185
|
+
export async function runChatTurn(provider, input, deps, chatImpl, origin = 'anon', maxRounds = DEFAULT_MAX_ROUNDS, wallClockMs = 360_000) {
|
|
186
|
+
const t0 = Date.now();
|
|
187
|
+
const step = (line) => { try {
|
|
188
|
+
deps.step?.(line);
|
|
189
|
+
}
|
|
190
|
+
catch { /* feed is best-effort */ } };
|
|
191
|
+
step('读取当前页面(预热)…');
|
|
192
|
+
let pageFails = 0; // page-channel damper: a ghost extension turns every
|
|
193
|
+
// page op into a full 20s timeout burn — after 3 consecutive failures the
|
|
194
|
+
// channel short-circuits so the loop pivots instead of grinding invisibly
|
|
60
195
|
const messages = [
|
|
61
|
-
{ role: 'system', content: systemPrompt(input) },
|
|
196
|
+
{ role: 'system', content: systemPrompt(input, await readPageContext(deps), deps) },
|
|
62
197
|
...input.history.map((t) => ({ role: t.role, content: t.content })),
|
|
63
198
|
{ role: 'user', content: input.message },
|
|
64
199
|
];
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
200
|
+
const tools = extendedTools(deps);
|
|
201
|
+
step(`上下文就绪(工具 ${tools.length} 个,轮预算 ${maxRounds})`);
|
|
202
|
+
for (let round = 0; round < maxRounds; round++) {
|
|
203
|
+
// wall-clock bound (round 50): one REQUEST may not run forever — the
|
|
204
|
+
// sentinel + panel chaining carry the TASK onward, each segment visible
|
|
205
|
+
const outOfTime = Date.now() - t0 > wallClockMs;
|
|
206
|
+
// LAST round (or out of time): strip tools so the model MUST wrap up in
|
|
207
|
+
// prose — the user gets a real progress summary, not a code excuse
|
|
208
|
+
const last = round === maxRounds - 1 || outOfTime;
|
|
209
|
+
if (outOfTime)
|
|
210
|
+
step('已达单段时限,收尾汇报…');
|
|
211
|
+
step(`第 ${round + 1} 轮思考中…(已用 ${Math.round((Date.now() - t0) / 1000)}s)`);
|
|
212
|
+
const res = await chatImpl(provider, messages, last ? [] : [...tools], { timeoutMs: 120_000, retry: { attempts: 2 } });
|
|
213
|
+
const calls = last ? [] : res.message.tool_calls ?? [];
|
|
214
|
+
if (!calls.length) {
|
|
215
|
+
const text = res.message.content?.trim() || '(模型返回了空回复)';
|
|
216
|
+
// AUTONOMOUS CONTINUATION (round 49): the task is not done, the round
|
|
217
|
+
// budget is — the panel auto-sends 「继续」 when it sees this sentinel,
|
|
218
|
+
// so the user hands over a task and gets it finished, no babysitting
|
|
219
|
+
return last ? text + '\n[[hmh:auto-continue]]' : text;
|
|
220
|
+
}
|
|
221
|
+
step(`第 ${round + 1} 轮: ${calls.map((c) => c.function.name).join(', ')}`);
|
|
70
222
|
messages.push(res.message);
|
|
71
223
|
for (const call of calls) {
|
|
72
224
|
let result;
|
|
73
225
|
try {
|
|
74
226
|
const args = JSON.parse(call.function.arguments || '{}');
|
|
75
|
-
if (
|
|
76
|
-
result = JSON.stringify(
|
|
77
|
-
}
|
|
78
|
-
else if (call.function.name === 'page_act') {
|
|
79
|
-
deps.log?.(`侧栏对话触发页面操作: ${JSON.stringify(args)}`);
|
|
80
|
-
result = JSON.stringify(await deps.act(args)).slice(0, 4_000);
|
|
227
|
+
if (pageFails >= 3 && (name => name === 'page_read' || name === 'page_act' || name === 'page_goto')(call.function.name)) {
|
|
228
|
+
result = JSON.stringify({ ok: false, error: '页面通道连续失败(扩展断连?)——已熔断。请停止页面操作:基于已有信息回答,或让用户重连扩展后重试。' });
|
|
81
229
|
}
|
|
82
230
|
else {
|
|
83
|
-
result =
|
|
231
|
+
result = await dispatchTool(call.function.name, args, deps, origin, step);
|
|
232
|
+
if (/^page_/.test(call.function.name) && result.includes('"error"'))
|
|
233
|
+
pageFails++;
|
|
234
|
+
else if (/^page_/.test(call.function.name))
|
|
235
|
+
pageFails = 0;
|
|
84
236
|
}
|
|
85
237
|
}
|
|
86
238
|
catch (err) {
|
|
87
239
|
result = JSON.stringify({ ok: false, error: String(err instanceof Error ? err.message : err).slice(0, 200) });
|
|
240
|
+
if (/^page_/.test(call.function.name))
|
|
241
|
+
pageFails++;
|
|
88
242
|
}
|
|
89
243
|
messages.push({ role: 'tool', tool_call_id: call.id, content: result });
|
|
90
244
|
}
|
|
91
245
|
}
|
|
92
|
-
return '
|
|
246
|
+
return '[[hmh:auto-continue]]';
|
|
247
|
+
}
|
|
248
|
+
async function dispatchTool(name, args, deps, origin, step) {
|
|
249
|
+
const json = (v, cap = 12_000) => JSON.stringify(v).slice(0, cap);
|
|
250
|
+
switch (name) {
|
|
251
|
+
case 'page_read': {
|
|
252
|
+
step?.('读取当前页面…');
|
|
253
|
+
try {
|
|
254
|
+
const r = await deps.readPage();
|
|
255
|
+
step?.('页面读取完成');
|
|
256
|
+
return json(r);
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
step?.('页面读取失败: ' + String(e instanceof Error ? e.message : e).slice(0, 80));
|
|
260
|
+
throw e;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
case 'page_act': {
|
|
264
|
+
step?.(`页面操作: ${String(args.action ?? '')} ${String(args.selector ?? args.direction ?? '').slice(0, 50)}`);
|
|
265
|
+
deps.log?.(`侧栏对话触发页面操作: ${JSON.stringify(args)}`);
|
|
266
|
+
return json(await deps.act(args), 4_000);
|
|
267
|
+
}
|
|
268
|
+
case 'page_goto': {
|
|
269
|
+
const url = String(args.url ?? '');
|
|
270
|
+
if (!/^https?:\/\//i.test(url))
|
|
271
|
+
return JSON.stringify({ ok: false, error: 'page_goto 只允许 http/https 地址' });
|
|
272
|
+
step?.(`导航: ${url.slice(0, 70)}`);
|
|
273
|
+
deps.log?.(`侧栏导航: ${url}`);
|
|
274
|
+
return json(await deps.goto(url), 2_000);
|
|
275
|
+
}
|
|
276
|
+
case 'tabs_list':
|
|
277
|
+
step?.('列出标签页…');
|
|
278
|
+
return json(await deps.listTabs(), 6_000);
|
|
279
|
+
case 'run_command': {
|
|
280
|
+
const command = String(args.command ?? '');
|
|
281
|
+
step?.(`命令待确认: ${command.slice(0, 80)}`);
|
|
282
|
+
// ALWAYS gated: turn N proposes (needConfirm) → user replies 「确认」 →
|
|
283
|
+
// turn N+1's pre-loop executes it and injects 【已执行】. A model
|
|
284
|
+
// re-calling the same command in one turn must NOT double-run it.
|
|
285
|
+
pendingConfirm.set(origin, {
|
|
286
|
+
kind: 'run_command',
|
|
287
|
+
summary: command,
|
|
288
|
+
run: () => deps.runCommand(command, Number(args.timeout_ms)),
|
|
289
|
+
});
|
|
290
|
+
return JSON.stringify({ needConfirm: true, message: `即将在终端执行: ${command}`, hint: '转达给用户:回复「确认」执行,回复其他内容取消。若上方已有【已执行】记录,不要重复执行,直接使用其结果。' });
|
|
291
|
+
}
|
|
292
|
+
case 'write_file': {
|
|
293
|
+
const path = String(args.path ?? '');
|
|
294
|
+
const content = String(args.content ?? '');
|
|
295
|
+
const summary = `write_file ${path}(${content.length} 字符)`;
|
|
296
|
+
pendingConfirm.set(origin, {
|
|
297
|
+
kind: 'write_file',
|
|
298
|
+
summary,
|
|
299
|
+
run: () => deps.writeFile(path, content),
|
|
300
|
+
});
|
|
301
|
+
return JSON.stringify({ needConfirm: true, message: `即将写入文件: ${summary}`, hint: '转达给用户:回复「确认」执行,回复其他内容取消。' });
|
|
302
|
+
}
|
|
303
|
+
case 'read_file':
|
|
304
|
+
step?.(`读取文件: ${String(args.path ?? '')}`);
|
|
305
|
+
return JSON.stringify(await deps.readFile(String(args.path ?? ''))).slice(0, 12_000);
|
|
306
|
+
case 'list_dir':
|
|
307
|
+
step?.(`列目录: ${String(args.path ?? '')}`);
|
|
308
|
+
return json(await deps.listDir(String(args.path ?? '')), 6_000);
|
|
309
|
+
default:
|
|
310
|
+
return JSON.stringify({ ok: false, error: `unknown tool ${name}` });
|
|
311
|
+
}
|
|
93
312
|
}
|
package/dist/main.js
CHANGED
|
@@ -27,7 +27,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
27
27
|
import { mkdir, rm } from 'node:fs/promises';
|
|
28
28
|
import { join } from 'node:path';
|
|
29
29
|
import { tmpdir } from 'node:os';
|
|
30
|
-
import { stopWebDaemon, startWebDaemon, hmhWebUp, readWebPid } from "./web-daemon.js";
|
|
30
|
+
import { stopWebDaemon, startWebDaemon, hmhWebUp, readWebPid, ensureWebDaemon } from "./web-daemon.js";
|
|
31
31
|
import { chat, homeDir, resolveProvider, initHome, latestSession, listProviders, listSessions, loadConfig, loadTranscript, mcpServerTools, Registry, runLoop, setChatRoute, setLocale, } from '@hmharness/kernel';
|
|
32
32
|
import { listSkills, listDrafts, promoteSkill, runBench, runEvolution, rollbackSkill, unpromoteSkill, } from '@hmharness/evolution';
|
|
33
33
|
import { harmonyTools } from '@hmharness/domain-harmony';
|
|
@@ -1113,12 +1113,54 @@ flags:
|
|
|
1113
1113
|
bridge.onConnectionChange = (connected) => {
|
|
1114
1114
|
stdout.write(connected ? '\n ✓ 浏览器扩展已连接\n' : '\n ✗ 浏览器扩展断开\n');
|
|
1115
1115
|
};
|
|
1116
|
-
//
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1116
|
+
// 侧栏对话面板的大脑(round 52):与 BrowserOS 面板收敛为同一个智能体
|
|
1117
|
+
// ——runAgentTask(完整工具注册表+真实系统提示词[记忆/技能/洞察]+按
|
|
1118
|
+
// 浏览器隔离的会话延续);审批门=对话式确认;步骤流实时上屏。旧的
|
|
1119
|
+
// 紧凑循环留作 agent 不可用时的降级路径。
|
|
1120
|
+
const tctx = { cwd: process.cwd(), home: homeDir() };
|
|
1121
|
+
const stepOf = (input) => (l) => {
|
|
1122
|
+
bridge.noteChatActivity(input.origin ?? 'anon', l);
|
|
1123
|
+
stdout.write(` ${DIM('· ' + l)}\n`);
|
|
1124
|
+
};
|
|
1125
|
+
let agentBrain = null;
|
|
1126
|
+
try {
|
|
1127
|
+
const { buildRegistry, runAgentTask } = await import('@hmharness/agent');
|
|
1128
|
+
const { answerWithAgentTurn } = await import("./extension-agent-brain.js");
|
|
1129
|
+
let cached = null;
|
|
1130
|
+
agentBrain = (input) => answerWithAgentTurn(input, {
|
|
1131
|
+
buildRegistry: async () => (cached ??= await buildRegistry({ mcp: true, announce: false })),
|
|
1132
|
+
buildRegistryNative: async () => buildRegistry({ mcp: false, announce: false }),
|
|
1133
|
+
runAgentTask: runAgentTask,
|
|
1134
|
+
ctx: tctx,
|
|
1135
|
+
goto: (url) => bridge.command('page.goto', { url }, 20_000),
|
|
1136
|
+
readPage: () => bridge.command('page.read', undefined, 20_000),
|
|
1137
|
+
step: stepOf(input),
|
|
1138
|
+
log: (l) => stdout.write(` ${DIM(l)}\n`),
|
|
1139
|
+
});
|
|
1140
|
+
stdout.write(' 大脑: 完整 agent(与 BrowserOS/acp-serve 同源)\n');
|
|
1141
|
+
}
|
|
1142
|
+
catch (err) {
|
|
1143
|
+
stdout.write(` 大脑: 紧凑循环(agent 不可用: ${String(err instanceof Error ? err.message : err).slice(0, 80)})\n`);
|
|
1144
|
+
}
|
|
1145
|
+
if (agentBrain) {
|
|
1146
|
+
bridge.onChat = (input) => agentBrain(input);
|
|
1147
|
+
}
|
|
1148
|
+
else {
|
|
1149
|
+
const { readFileTool, writeFileTool, listDirTool, runCommandTool } = await import('@hmharness/agent');
|
|
1150
|
+
bridge.onChat = (input) => answerChatTurn(input, {
|
|
1151
|
+
workspace: process.cwd(),
|
|
1152
|
+
readPage: () => bridge.command('page.read', undefined, 20_000),
|
|
1153
|
+
act: (a) => bridge.command('page.act', { act: a }, 20_000),
|
|
1154
|
+
goto: (url) => bridge.command('page.goto', { url }, 20_000),
|
|
1155
|
+
listTabs: () => bridge.command('tabs.list', undefined, 20_000),
|
|
1156
|
+
readFile: (p) => readFileTool.execute({ path: p }, tctx),
|
|
1157
|
+
writeFile: (p, c) => writeFileTool.execute({ path: p, content: c }, tctx),
|
|
1158
|
+
listDir: (p) => listDirTool.execute({ path: p || '.' }, tctx),
|
|
1159
|
+
runCommand: (cmd, t) => runCommandTool.execute({ command: cmd, ...(t ? { timeout_ms: t } : {}) }, tctx),
|
|
1160
|
+
log: (l) => stdout.write(` ${DIM(l)}\n`),
|
|
1161
|
+
step: stepOf(input),
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1122
1164
|
bridge.onAutoPair = (origin) => {
|
|
1123
1165
|
stdout.write(`\n ✓ 扩展自动授权: ${origin}(零操作连接)\n`);
|
|
1124
1166
|
};
|
|
@@ -1846,6 +1888,25 @@ flags:
|
|
|
1846
1888
|
}
|
|
1847
1889
|
const t = await uiStrings();
|
|
1848
1890
|
const sub = rest.find((a) => !a.startsWith('-'));
|
|
1891
|
+
if (sub === 'install-daemon') {
|
|
1892
|
+
// boot auto-start (2026-10-23): the web daemon starts at LOGIN with
|
|
1893
|
+
// no terminal/app needed — phone remote control is always reachable.
|
|
1894
|
+
const { installWebDaemonAutostart } = await import("./web-daemon.js");
|
|
1895
|
+
const path = installWebDaemonAutostart(port, process.argv[1]);
|
|
1896
|
+
stdout.write(`✓ 远程控制守护已设为开机自启(登录即启动,无需打开任何应用)\n`);
|
|
1897
|
+
stdout.write(` 启动项: ${path}\n`);
|
|
1898
|
+
stdout.write(DIM(` 移除: hmh web uninstall-daemon\n`));
|
|
1899
|
+
const ok = await ensureWebDaemon(port);
|
|
1900
|
+
if (ok)
|
|
1901
|
+
stdout.write(`✓ 守护已启动 · 手机随时可连\n`);
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
if (sub === 'uninstall-daemon') {
|
|
1905
|
+
const { uninstallWebDaemonAutostart } = await import("./web-daemon.js");
|
|
1906
|
+
const removed = uninstallWebDaemonAutostart();
|
|
1907
|
+
stdout.write(removed ? `已移除开机自启: ${removed}\n` : `(未安装)\n`);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1849
1910
|
if (sub === 'stop') {
|
|
1850
1911
|
stdout.write(stopWebDaemon() ? t.webStopped + '\n' : t.webNotRunning + '\n');
|
|
1851
1912
|
return;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cli - tui-mouse (2026-10-22, dsh-TUI style mouse support)
|
|
3
|
+
*
|
|
4
|
+
* SGR mouse tracking (DECSET 1000+1002+1006): the terminal reports
|
|
5
|
+
* ESC[<button;col;row M (press) / m (release) sequences. This module
|
|
6
|
+
* parses them, maintains a clickable-region registry populated during
|
|
7
|
+
* render, and dispatches clicks on left-button release (dsh-TUI's click
|
|
8
|
+
* contract: release without drag = click).
|
|
9
|
+
*
|
|
10
|
+
* Region registration: the renderer registers (row, colStart, colEnd, fn)
|
|
11
|
+
* for each interactive element while drawing. Regions are cleared at the
|
|
12
|
+
* start of every frame, so the registry is always one frame fresh.
|
|
13
|
+
*/
|
|
14
|
+
/** Enable SGR mouse tracking (click + drag + wheel). */
|
|
15
|
+
export declare const ENABLE_MOUSE = "\u001B[?1000h\u001B[?1002h\u001B[?1006h";
|
|
16
|
+
/** Disable all mouse tracking modes. */
|
|
17
|
+
export declare const DISABLE_MOUSE = "\u001B[?1006l\u001B[?1002l\u001B[?1000l";
|
|
18
|
+
export interface ParsedMouse {
|
|
19
|
+
kind: 'click' | 'wheel';
|
|
20
|
+
col: number;
|
|
21
|
+
row: number;
|
|
22
|
+
wheelUp: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Try to parse an SGR mouse sequence from the head of the input chunk.
|
|
26
|
+
* Returns [event, rest-of-chunk] or null if the chunk doesn't start with one.
|
|
27
|
+
* ConPTY can split reports across stdin reads; a partial prefix
|
|
28
|
+
* (ESC[<digits;) is held by the caller until more data arrives.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseMouse(chunk: string): [ParsedMouse, string] | null;
|
|
31
|
+
/** True if the chunk LOOKS like the start of a mouse report (may be partial). */
|
|
32
|
+
export declare function isMousePrefix(chunk: string): boolean;
|
|
33
|
+
export interface ClickRegion {
|
|
34
|
+
row: number;
|
|
35
|
+
colStart: number;
|
|
36
|
+
colEnd: number;
|
|
37
|
+
fn: () => void;
|
|
38
|
+
/** higher z wins when regions overlap (later registrations = drawn on top) */
|
|
39
|
+
z: number;
|
|
40
|
+
}
|
|
41
|
+
/** Clear the registry — call at the START of each render frame. */
|
|
42
|
+
export declare function clearRegions(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Register a clickable region. The renderer calls this while drawing each
|
|
45
|
+
* interactive element; z-order follows registration order (later = on top).
|
|
46
|
+
*/
|
|
47
|
+
export declare function addClickRegion(row: number, colStart: number, colEnd: number, fn: () => void): void;
|
|
48
|
+
/**
|
|
49
|
+
* Dispatch a click at terminal (col, row). The highest-z region containing
|
|
50
|
+
* the point wins; returns true if any region consumed the click.
|
|
51
|
+
*/
|
|
52
|
+
export declare function dispatchClick(col: number, row: number): boolean;
|
|
53
|
+
/** Test helper: current region count. */
|
|
54
|
+
export declare function regionCount(): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cli - tui-mouse (2026-10-22, dsh-TUI style mouse support)
|
|
3
|
+
*
|
|
4
|
+
* SGR mouse tracking (DECSET 1000+1002+1006): the terminal reports
|
|
5
|
+
* ESC[<button;col;row M (press) / m (release) sequences. This module
|
|
6
|
+
* parses them, maintains a clickable-region registry populated during
|
|
7
|
+
* render, and dispatches clicks on left-button release (dsh-TUI's click
|
|
8
|
+
* contract: release without drag = click).
|
|
9
|
+
*
|
|
10
|
+
* Region registration: the renderer registers (row, colStart, colEnd, fn)
|
|
11
|
+
* for each interactive element while drawing. Regions are cleared at the
|
|
12
|
+
* start of every frame, so the registry is always one frame fresh.
|
|
13
|
+
*/
|
|
14
|
+
/** Enable SGR mouse tracking (click + drag + wheel). */
|
|
15
|
+
export const ENABLE_MOUSE = '\x1b[?1000h\x1b[?1002h\x1b[?1006h';
|
|
16
|
+
/** Disable all mouse tracking modes. */
|
|
17
|
+
export const DISABLE_MOUSE = '\x1b[?1006l\x1b[?1002l\x1b[?1000l';
|
|
18
|
+
/** SGR mouse report: ESC[<btn;col;rowM (press) / m (release). */
|
|
19
|
+
const SGR_MOUSE_RE = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])/;
|
|
20
|
+
/**
|
|
21
|
+
* Try to parse an SGR mouse sequence from the head of the input chunk.
|
|
22
|
+
* Returns [event, rest-of-chunk] or null if the chunk doesn't start with one.
|
|
23
|
+
* ConPTY can split reports across stdin reads; a partial prefix
|
|
24
|
+
* (ESC[<digits;) is held by the caller until more data arrives.
|
|
25
|
+
*/
|
|
26
|
+
export function parseMouse(chunk) {
|
|
27
|
+
const m = SGR_MOUSE_RE.exec(chunk);
|
|
28
|
+
if (!m)
|
|
29
|
+
return null;
|
|
30
|
+
const button = parseInt(m[1], 10);
|
|
31
|
+
const col = parseInt(m[2], 10) - 1; // SGR is 1-indexed, we 0-index
|
|
32
|
+
const row = parseInt(m[3], 10) - 1;
|
|
33
|
+
const isRelease = m[4] === 'm';
|
|
34
|
+
const rest = chunk.slice(m[0].length);
|
|
35
|
+
// wheel: button bit 6 set (0x40), low bits 0=up 1=down
|
|
36
|
+
if ((button & 0x40) !== 0) {
|
|
37
|
+
return [{ kind: 'wheel', col, row, wheelUp: (button & 0x01) === 0 }, rest];
|
|
38
|
+
}
|
|
39
|
+
// left-button (button bits 0-1 = 0) release = click
|
|
40
|
+
if ((button & 0x03) === 0 && isRelease) {
|
|
41
|
+
return [{ kind: 'click', col, row, wheelUp: false }, rest];
|
|
42
|
+
}
|
|
43
|
+
// press events, right/middle button, drag-motion: consumed silently
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/** True if the chunk LOOKS like the start of a mouse report (may be partial). */
|
|
47
|
+
export function isMousePrefix(chunk) {
|
|
48
|
+
// complete report or a partial prefix (ConPTY fragmentation)
|
|
49
|
+
return /^\x1b\[<\d+(?:;\d*){0,2}[Mm]?/.test(chunk) || /^\x1b\[<\d*$/.test(chunk);
|
|
50
|
+
}
|
|
51
|
+
let regions = [];
|
|
52
|
+
let zCounter = 0;
|
|
53
|
+
/** Clear the registry — call at the START of each render frame. */
|
|
54
|
+
export function clearRegions() {
|
|
55
|
+
regions = [];
|
|
56
|
+
zCounter = 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Register a clickable region. The renderer calls this while drawing each
|
|
60
|
+
* interactive element; z-order follows registration order (later = on top).
|
|
61
|
+
*/
|
|
62
|
+
export function addClickRegion(row, colStart, colEnd, fn) {
|
|
63
|
+
regions.push({ row, colStart, colEnd, fn, z: zCounter++ });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Dispatch a click at terminal (col, row). The highest-z region containing
|
|
67
|
+
* the point wins; returns true if any region consumed the click.
|
|
68
|
+
*/
|
|
69
|
+
export function dispatchClick(col, row) {
|
|
70
|
+
const hits = regions.filter((r) => r.row === row && col >= r.colStart && col <= r.colEnd);
|
|
71
|
+
if (hits.length === 0)
|
|
72
|
+
return false;
|
|
73
|
+
hits.sort((a, b) => b.z - a.z)[0].fn();
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
/** Test helper: current region count. */
|
|
77
|
+
export function regionCount() {
|
|
78
|
+
return regions.length;
|
|
79
|
+
}
|
package/dist/tui.d.ts
CHANGED
|
@@ -126,6 +126,8 @@ export declare class TuiRuntime {
|
|
|
126
126
|
/** bracketed-paste accumulator: non-null while the 201~ end marker has
|
|
127
127
|
* not arrived yet; everything buffered is literal insert-on-completion */
|
|
128
128
|
private pasteBuf;
|
|
129
|
+
/** partial SGR mouse report held across stdin reads (ConPTY fragmentation) */
|
|
130
|
+
private mouseBuf;
|
|
129
131
|
/** restores the console methods and process handlers captured by the
|
|
130
132
|
* TUI's terminal ownership (see installConsoleRedirection) */
|
|
131
133
|
private restoreConsole;
|
|
@@ -286,6 +288,8 @@ export declare class TuiRuntime {
|
|
|
286
288
|
private onKey;
|
|
287
289
|
/** insert literal (sanitized paste) text at the caret - the same path
|
|
288
290
|
* printable typing takes, so caret/history/palette side-effects match */
|
|
291
|
+
/** Mouse wheel drives the transcript scroll (same as arrow keys: 3 lines). */
|
|
292
|
+
private wheelScroll;
|
|
289
293
|
private insertText;
|
|
290
294
|
render(): void;
|
|
291
295
|
private flushFrame;
|
package/dist/tui.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { stdin, stdout } from 'node:process';
|
|
14
14
|
import { basename } from 'node:path';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
|
+
import { parseMouse, isMousePrefix, dispatchClick, clearRegions, addClickRegion } from "./tui-mouse.js";
|
|
16
17
|
import { loadConfig, homeDir, resolveProvider, listProviders, setChatRoute, setLocale, PROVIDER_PRESETS, addProviders, detectLocalProviders, latestSession, listSessions, loadTranscript, transcriptChars, compactMessages, adaptiveContextChars, getGoal, setGoal, clearGoal, isProviderAuthError } from '@hmharness/kernel';
|
|
17
18
|
import { listDrafts, listSkills, runBench, runEvolution } from '@hmharness/evolution';
|
|
18
19
|
import { buildRegistry, runAgentTask, strings } from '@hmharness/agent';
|
|
@@ -319,6 +320,8 @@ export class TuiRuntime {
|
|
|
319
320
|
/** bracketed-paste accumulator: non-null while the 201~ end marker has
|
|
320
321
|
* not arrived yet; everything buffered is literal insert-on-completion */
|
|
321
322
|
pasteBuf = null;
|
|
323
|
+
/** partial SGR mouse report held across stdin reads (ConPTY fragmentation) */
|
|
324
|
+
mouseBuf = null;
|
|
322
325
|
/** restores the console methods and process handlers captured by the
|
|
323
326
|
* TUI's terminal ownership (see installConsoleRedirection) */
|
|
324
327
|
restoreConsole = null;
|
|
@@ -351,7 +354,7 @@ export class TuiRuntime {
|
|
|
351
354
|
// keys itself - no click capture, native selection stays native.
|
|
352
355
|
// Bracketed paste (?2004h): multi-line pastes arrive delimited and
|
|
353
356
|
// insert as one reviewable input instead of auto-submitting per line.
|
|
354
|
-
stdout.write('\x1b[?1049h\x1b[?25l\x1b[2J\x1b[?1l\x1b[?1007h\x1b[?2004h');
|
|
357
|
+
stdout.write('\x1b[?1049h\x1b[?25l\x1b[2J\x1b[?1l\x1b[?1007h\x1b[?2004h\x1b[?1000h\x1b[?1002h\x1b[?1006h');
|
|
355
358
|
stdin.setRawMode?.(true);
|
|
356
359
|
stdin.resume();
|
|
357
360
|
stdin.setEncoding('utf8');
|
|
@@ -495,6 +498,9 @@ export class TuiRuntime {
|
|
|
495
498
|
const sel = from + i === st.selected;
|
|
496
499
|
const plain = truncateTo(formatRow(vis[from + i], sel, W - 1), W - 1);
|
|
497
500
|
frame.push(sel ? '\x1b[7m' + plain + ' '.repeat(Math.max(0, W - 1 - strWidth(plain))) + '\x1b[27m' : ' ' + plain);
|
|
501
|
+
// mouse click region: this row picks that session
|
|
502
|
+
const pickRow = frame.length - 1;
|
|
503
|
+
addClickRegion(pickRow, 0, W - 1, () => { st.selected = from + i; this.pickerInput('return'); });
|
|
498
504
|
}
|
|
499
505
|
if (st.loading)
|
|
500
506
|
frame.push(DIM(' ' + (vis.length === 0 ? t.pickerLoading : t.pickerMore)));
|
|
@@ -1151,6 +1157,50 @@ export class TuiRuntime {
|
|
|
1151
1157
|
return n;
|
|
1152
1158
|
}
|
|
1153
1159
|
onKey(data) {
|
|
1160
|
+
// SGR mouse events (dsh-TUI style, 2026-10-22): intercept BEFORE any
|
|
1161
|
+
// key processing — the terminal sends ESC[<btn;col;rowM/m sequences that
|
|
1162
|
+
// would otherwise leak into the input as garbage. A click dispatches to
|
|
1163
|
+
// the region registry; wheel drives the transcript scroll; all other
|
|
1164
|
+
// mouse reports (press, drag, right/middle) are consumed silently.
|
|
1165
|
+
{
|
|
1166
|
+
let chunk = data;
|
|
1167
|
+
for (;;) {
|
|
1168
|
+
if (chunk === '' || chunk[0] !== '\x1b')
|
|
1169
|
+
break;
|
|
1170
|
+
if (!isMousePrefix(chunk))
|
|
1171
|
+
break;
|
|
1172
|
+
const parsed = parseMouse(chunk);
|
|
1173
|
+
if (parsed) {
|
|
1174
|
+
const [ev, rest] = parsed;
|
|
1175
|
+
if (ev.kind === 'click')
|
|
1176
|
+
dispatchClick(ev.col, ev.row);
|
|
1177
|
+
else if (ev.kind === 'wheel')
|
|
1178
|
+
this.wheelScroll(ev.wheelUp);
|
|
1179
|
+
chunk = rest;
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
// partial SGR prefix (ConPTY fragmentation): hold in the mouse buf
|
|
1183
|
+
if (/^\x1b\[<\d*$/.test(chunk)) {
|
|
1184
|
+
this.mouseBuf = chunk;
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
break;
|
|
1188
|
+
}
|
|
1189
|
+
if (this.mouseBuf !== null) {
|
|
1190
|
+
const joined = this.mouseBuf + chunk;
|
|
1191
|
+
this.mouseBuf = null;
|
|
1192
|
+
if (joined !== data) {
|
|
1193
|
+
this.onKey(joined);
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
chunk = joined;
|
|
1197
|
+
}
|
|
1198
|
+
if (chunk !== data) {
|
|
1199
|
+
if (chunk === '')
|
|
1200
|
+
return;
|
|
1201
|
+
data = chunk;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1154
1204
|
// bracketed paste (T22): buffer until the 201~ end marker, then insert
|
|
1155
1205
|
// the sanitized body at the caret; keys/bytes outside the markers keep
|
|
1156
1206
|
// flowing through the normal path (recursion depth stays 1: indexOf
|
|
@@ -1467,6 +1517,26 @@ export class TuiRuntime {
|
|
|
1467
1517
|
}
|
|
1468
1518
|
/** insert literal (sanitized paste) text at the caret - the same path
|
|
1469
1519
|
* printable typing takes, so caret/history/palette side-effects match */
|
|
1520
|
+
/** Mouse wheel drives the transcript scroll (same as arrow keys: 3 lines). */
|
|
1521
|
+
wheelScroll(up) {
|
|
1522
|
+
if (this.overlay) {
|
|
1523
|
+
this.overlay.top = Math.max(0, this.overlay.top + (up ? -3 : 3));
|
|
1524
|
+
this.dirty = true;
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
if (up) {
|
|
1528
|
+
if (this.scrollFromBottom < this.totalLines()) {
|
|
1529
|
+
this.scrollFromBottom = Math.min(this.totalLines(), this.scrollFromBottom + 3);
|
|
1530
|
+
this.dirty = true;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
else {
|
|
1534
|
+
if (this.scrollFromBottom > 0) {
|
|
1535
|
+
this.scrollFromBottom = Math.max(0, this.scrollFromBottom - 3);
|
|
1536
|
+
this.dirty = true;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1470
1540
|
insertText(text) {
|
|
1471
1541
|
if (!text)
|
|
1472
1542
|
return;
|
|
@@ -1484,6 +1554,7 @@ export class TuiRuntime {
|
|
|
1484
1554
|
const W = stdout.columns || 100;
|
|
1485
1555
|
const H = stdout.rows || 30;
|
|
1486
1556
|
const frame = [];
|
|
1557
|
+
clearRegions(); // mouse click regions are re-registered fresh each frame
|
|
1487
1558
|
if (this.resumeModal) {
|
|
1488
1559
|
this.renderResumePicker(frame, W, H);
|
|
1489
1560
|
this.flushFrame(frame, H);
|
|
@@ -1548,6 +1619,10 @@ export class TuiRuntime {
|
|
|
1548
1619
|
const argsTxt = JSON.stringify(this.approval.args);
|
|
1549
1620
|
frame.push(YELLOW(this.t.tuiApproval) + ' ' + YELLOW(BOLD(this.approval.name)) + ' ' + DIM(truncateTo(argsTxt, Math.max(0, W - 24))));
|
|
1550
1621
|
frame.push(` [y] ${GREEN(this.t.tuiApprove)} [n] ${RED(this.t.tuiDeny)} ${DIM(this.t.tuiApprovalHint)}`);
|
|
1622
|
+
// mouse click regions for the approval buttons
|
|
1623
|
+
const apprRow = frame.length - 1;
|
|
1624
|
+
addClickRegion(apprRow, 2, 5, () => this.approvalResolve?.(true));
|
|
1625
|
+
addClickRegion(apprRow, 12, 15, () => this.approvalResolve?.(false));
|
|
1551
1626
|
frame.push(DIM('─'.repeat(W)));
|
|
1552
1627
|
}
|
|
1553
1628
|
// busy status line right above the input box (same position as the web
|
package/dist/web-daemon.d.ts
CHANGED
|
@@ -43,3 +43,9 @@ export declare function startWebDaemon(port?: number, entry?: string, extraArgs?
|
|
|
43
43
|
already: boolean;
|
|
44
44
|
pid: number;
|
|
45
45
|
};
|
|
46
|
+
/** Install the boot auto-start for the CURRENT user. Idempotent. */
|
|
47
|
+
export declare function installWebDaemonAutostart(port?: number, entry?: string): string;
|
|
48
|
+
/** Remove the boot auto-start. Returns the removed file path or ''. */
|
|
49
|
+
export declare function uninstallWebDaemonAutostart(): string;
|
|
50
|
+
/** Check if the boot auto-start is installed. */
|
|
51
|
+
export declare function webDaemonAutostartInstalled(): boolean;
|
package/dist/web-daemon.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { spawn } from 'node:child_process';
|
|
14
14
|
import { execSync } from 'node:child_process';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
|
-
import { openSync, readFileSync, unlinkSync, writeFileSync, closeSync } from 'node:fs';
|
|
16
|
+
import { openSync, readFileSync, unlinkSync, writeFileSync, closeSync, mkdirSync, existsSync } from 'node:fs';
|
|
17
17
|
import { join } from 'node:path';
|
|
18
18
|
import { homeDir } from '@hmharness/kernel';
|
|
19
19
|
export const DEFAULT_WEB_PORT = 7788;
|
|
@@ -251,3 +251,118 @@ export function startWebDaemon(port = DEFAULT_WEB_PORT, entry = process.argv[1],
|
|
|
251
251
|
return { already: true, pid };
|
|
252
252
|
return { already: false, pid: spawnWebDaemon(port, entry, extraArgs) };
|
|
253
253
|
}
|
|
254
|
+
/* ---- Boot auto-start (2026-10-23 user request) ----
|
|
255
|
+
* The web daemon normally starts lazily — when a CLI command or the TUI
|
|
256
|
+
* brings it up. For phone remote control to work "even when no app is
|
|
257
|
+
* open", the daemon must come up at LOGIN with no user action.
|
|
258
|
+
*
|
|
259
|
+
* Windows: a .cmd shortcut in the user's Startup folder (no admin rights
|
|
260
|
+
* needed, starts at every logon).
|
|
261
|
+
* macOS: a LaunchAgent plist (~/Library/LaunchAgents).
|
|
262
|
+
* Linux: a systemd user unit (loginctl enable-linger for boot-start).
|
|
263
|
+
* All three run `node <entry> web start --port=<port>` invisibly.
|
|
264
|
+
*/
|
|
265
|
+
function startupDir() {
|
|
266
|
+
if (process.platform === 'win32') {
|
|
267
|
+
return join(process.env.APPDATA ?? '', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup');
|
|
268
|
+
}
|
|
269
|
+
if (process.platform === 'darwin') {
|
|
270
|
+
return join(process.env.HOME ?? '', 'Library', 'LaunchAgents');
|
|
271
|
+
}
|
|
272
|
+
return join(process.env.HOME ?? '', '.config', 'systemd', 'user');
|
|
273
|
+
}
|
|
274
|
+
function autostartLabel() {
|
|
275
|
+
return 'hmharness-web-daemon';
|
|
276
|
+
}
|
|
277
|
+
/** Install the boot auto-start for the CURRENT user. Idempotent. */
|
|
278
|
+
export function installWebDaemonAutostart(port = DEFAULT_WEB_PORT, entry = process.argv[1]) {
|
|
279
|
+
const dir = startupDir();
|
|
280
|
+
if (process.platform === 'win32') {
|
|
281
|
+
mkdirSync(dir, { recursive: true });
|
|
282
|
+
const cmdPath = join(dir, `${autostartLabel()}.cmd`);
|
|
283
|
+
const nodeExe = process.execPath.replace(/\\/g, '\\\\');
|
|
284
|
+
const entryPath = entry.replace(/\\/g, '\\\\');
|
|
285
|
+
writeFileSync(cmdPath, [
|
|
286
|
+
`@echo off`,
|
|
287
|
+
`"${nodeExe}" "${entryPath}" web start --port=${port} > NUL 2>&1`,
|
|
288
|
+
].join('\r\n'), 'utf8');
|
|
289
|
+
return cmdPath;
|
|
290
|
+
}
|
|
291
|
+
if (process.platform === 'darwin') {
|
|
292
|
+
mkdirSync(dir, { recursive: true });
|
|
293
|
+
const plist = join(dir, `${autostartLabel()}.plist`);
|
|
294
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
295
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
296
|
+
<plist version="1.0"><dict>
|
|
297
|
+
<key>Label</key><string>${autostartLabel()}</string>
|
|
298
|
+
<key>ProgramArguments</key><array>
|
|
299
|
+
<string>${process.execPath}</string>
|
|
300
|
+
<string>${entry}</string>
|
|
301
|
+
<string>web</string>
|
|
302
|
+
<string>start</string>
|
|
303
|
+
<string>--port=${port}</string>
|
|
304
|
+
</array>
|
|
305
|
+
<key>RunAtLoad</key><true/>
|
|
306
|
+
<key>StandardOutPath</key><string>${join(homeDir(), 'web.log')}</string>
|
|
307
|
+
<key>StandardErrorPath</key><string>${join(homeDir(), 'web.log')}</string>
|
|
308
|
+
</dict></plist>`;
|
|
309
|
+
writeFileSync(plist, xml, 'utf8');
|
|
310
|
+
return plist;
|
|
311
|
+
}
|
|
312
|
+
// Linux: systemd user unit
|
|
313
|
+
mkdirSync(dir, { recursive: true });
|
|
314
|
+
const unit = join(dir, `${autostartLabel()}.service`);
|
|
315
|
+
writeFileSync(unit, [
|
|
316
|
+
`[Unit]`,
|
|
317
|
+
`Description=hmharness web daemon (phone remote control)`,
|
|
318
|
+
``,
|
|
319
|
+
`[Service]`,
|
|
320
|
+
`Type=oneshot`,
|
|
321
|
+
`RemainAfterExit=yes`,
|
|
322
|
+
`ExecStart=${process.execPath} ${entry} web start --port=${port}`,
|
|
323
|
+
``,
|
|
324
|
+
`[Install]`,
|
|
325
|
+
`WantedBy=default.target`,
|
|
326
|
+
].join('\n'), 'utf8');
|
|
327
|
+
try {
|
|
328
|
+
execSync('systemctl --user daemon-reload', { timeout: 10_000 });
|
|
329
|
+
}
|
|
330
|
+
catch { /* best effort */ }
|
|
331
|
+
try {
|
|
332
|
+
execSync(`systemctl --user enable ${autostartLabel()}`, { timeout: 10_000 });
|
|
333
|
+
}
|
|
334
|
+
catch { /* best effort */ }
|
|
335
|
+
return unit;
|
|
336
|
+
}
|
|
337
|
+
/** Remove the boot auto-start. Returns the removed file path or ''. */
|
|
338
|
+
export function uninstallWebDaemonAutostart() {
|
|
339
|
+
const dir = startupDir();
|
|
340
|
+
const candidates = [
|
|
341
|
+
join(dir, `${autostartLabel()}.cmd`),
|
|
342
|
+
join(dir, `${autostartLabel()}.plist`),
|
|
343
|
+
join(dir, `${autostartLabel()}.service`),
|
|
344
|
+
];
|
|
345
|
+
for (const c of candidates) {
|
|
346
|
+
if (existsSync(c)) {
|
|
347
|
+
try {
|
|
348
|
+
unlinkSync(c);
|
|
349
|
+
}
|
|
350
|
+
catch { /* locked */ }
|
|
351
|
+
if (process.platform === 'linux') {
|
|
352
|
+
try {
|
|
353
|
+
execSync(`systemctl --user disable ${autostartLabel()}`, { timeout: 10_000 });
|
|
354
|
+
}
|
|
355
|
+
catch { /* best effort */ }
|
|
356
|
+
}
|
|
357
|
+
return c;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return '';
|
|
361
|
+
}
|
|
362
|
+
/** Check if the boot auto-start is installed. */
|
|
363
|
+
export function webDaemonAutostartInstalled() {
|
|
364
|
+
const dir = startupDir();
|
|
365
|
+
return existsSync(join(dir, `${autostartLabel()}.cmd`))
|
|
366
|
+
|| existsSync(join(dir, `${autostartLabel()}.plist`))
|
|
367
|
+
|| existsSync(join(dir, `${autostartLabel()}.service`));
|
|
368
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.38",
|
|
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",
|
|
@@ -45,20 +45,20 @@
|
|
|
45
45
|
"build": "tsc -p tsconfig.build.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@hmharness/agent": "0.23.
|
|
49
|
-
"@hmharness/browser": "0.23.
|
|
50
|
-
"@hmharness/cognitive": "0.23.
|
|
51
|
-
"@hmharness/domain-harmony": "0.23.
|
|
52
|
-
"@hmharness/domain-ops": "0.23.
|
|
53
|
-
"@hmharness/environments": "0.23.
|
|
54
|
-
"@hmharness/evaluation": "0.23.
|
|
55
|
-
"@hmharness/evolution": "0.23.
|
|
56
|
-
"@hmharness/extension": "0.23.
|
|
57
|
-
"@hmharness/kernel": "0.23.
|
|
58
|
-
"@hmharness/observability": "0.23.
|
|
59
|
-
"@hmharness/sandbox": "0.23.
|
|
60
|
-
"@hmharness/web": "0.23.
|
|
48
|
+
"@hmharness/agent": "0.23.38",
|
|
49
|
+
"@hmharness/browser": "0.23.38",
|
|
50
|
+
"@hmharness/cognitive": "0.23.38",
|
|
51
|
+
"@hmharness/domain-harmony": "0.23.38",
|
|
52
|
+
"@hmharness/domain-ops": "0.23.38",
|
|
53
|
+
"@hmharness/environments": "0.23.38",
|
|
54
|
+
"@hmharness/evaluation": "0.23.38",
|
|
55
|
+
"@hmharness/evolution": "0.23.38",
|
|
56
|
+
"@hmharness/extension": "0.23.38",
|
|
57
|
+
"@hmharness/kernel": "0.23.38",
|
|
58
|
+
"@hmharness/observability": "0.23.38",
|
|
59
|
+
"@hmharness/sandbox": "0.23.38",
|
|
60
|
+
"@hmharness/web": "0.23.38",
|
|
61
61
|
"qrcode": "^1.5.4",
|
|
62
|
-
"@hmharness/lsp": "0.23.
|
|
62
|
+
"@hmharness/lsp": "0.23.38"
|
|
63
63
|
}
|
|
64
64
|
}
|