@leavewhite9088/harness-bus 0.2.0 → 0.2.1
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/ARCHITECTURE.md +81 -81
- package/LICENSE +21 -21
- package/README.md +86 -86
- package/SETUP_FOR_AI.md +79 -79
- package/package.json +4 -2
- package/packages/agentd/agentd.config.json +3 -1
- package/packages/agentd/cli/commands.mjs +854 -810
- package/packages/agentd/cli/format.mjs +294 -238
- package/packages/agentd/cli/hbus.mjs +14 -14
- package/packages/agentd/cli/index.mjs +4 -4
- package/packages/agentd/cli/skill/SKILL.md +66 -61
- package/packages/agentd/cli/skill/references/custom.md +12 -0
- package/packages/agentd/cli/skill/references/playbooks.md +89 -86
- package/packages/agentd/cli/skill/references/routing.md +43 -35
- package/packages/agentd/cli/skill-install.mjs +157 -140
- package/packages/agentd/cli/update.mjs +221 -221
- package/packages/agentd/client/index.mjs +3 -3
- package/packages/agentd/contexts/executor.md +13 -12
- package/packages/agentd/contexts/templates/architect.md +12 -12
- package/packages/agentd/contexts/templates/coder.md +12 -12
- package/packages/agentd/contexts/templates/debugger.md +12 -12
- package/packages/agentd/contexts/templates/researcher.md +12 -12
- package/packages/agentd/contexts/templates/reviewer.md +12 -12
- package/packages/agentd/contexts/templates/tester.md +12 -12
- package/packages/agentd/core/base/data-dir.mjs +39 -39
- package/packages/agentd/core/base/index.mjs +5 -5
- package/packages/agentd/core/base/protocol.mjs +13 -13
- package/packages/agentd/core/env/config.mjs +52 -1
- package/packages/agentd/core/env/index.mjs +6 -1
- package/packages/agentd/core/env/install.mjs +82 -4
- package/packages/agentd/core/pi/index.mjs +1 -1
- package/packages/agentd/core/pi/rpc.mjs +206 -206
- package/packages/agentd/core/pool/acp/client.mjs +7 -9
- package/packages/agentd/core/pool/acp/process.mjs +27 -18
- package/packages/agentd/core/pool/acp/run-tracker.mjs +293 -293
- package/packages/agentd/core/pool/acp/sessions.mjs +465 -465
- package/packages/agentd/core/pool/acp/turn-runner.mjs +5 -3
- package/packages/agentd/core/pool/index.mjs +2 -2
- package/packages/agentd/core/pool/instances.mjs +3 -5
- package/packages/agentd/core/pool/probe.mjs +91 -85
- package/packages/agentd/core/pool/registry.mjs +45 -1
- package/packages/agentd/core/pool/support/compaction.mjs +2 -43
- package/packages/agentd/core/pool/support/index.mjs +1 -1
- package/packages/agentd/core/prompts/index.mjs +12 -12
- package/packages/agentd/core/prompts/rules.mjs +22 -22
- package/packages/agentd/core/prompts/templates.mjs +172 -172
- package/packages/agentd/core/providers/index.mjs +14 -14
- package/packages/agentd/core/providers/store.mjs +206 -206
- package/packages/agentd/core/records/cleanup.mjs +51 -51
- package/packages/agentd/core/records/index.mjs +8 -8
- package/packages/agentd/core/records/metrics.mjs +73 -73
- package/packages/agentd/core/records/recovery.mjs +39 -39
- package/packages/agentd/core/records/transcripts.mjs +122 -122
- package/packages/agentd/core/threads/index.mjs +18 -17
- package/packages/agentd/core/threads/manager.mjs +498 -476
- package/packages/agentd/core/threads/paths.mjs +78 -78
- package/packages/agentd/core/threads/store.mjs +146 -125
- package/packages/agentd/daemon/agentd.mjs +58 -58
- package/packages/agentd/daemon/events.mjs +126 -126
- package/packages/agentd/daemon/guard.mjs +127 -127
- package/packages/agentd/daemon/lifecycle.mjs +61 -61
- package/packages/agentd/daemon/ops/index.mjs +15 -15
- package/packages/agentd/daemon/ops/providers.mjs +46 -46
- package/packages/agentd/daemon/ops/run.mjs +413 -400
- package/packages/agentd/daemon/ops/system.mjs +76 -69
- package/packages/agentd/daemon/ops/threads.mjs +156 -153
- package/packages/agentd/daemon/server.mjs +130 -130
- package/packages/agentd/package.json +1 -1
- package/packages/agentd/pi-adapter/acp-adapter.mjs +501 -501
- package/packages/agentd/scripts/restart-daemon.mjs +74 -74
- package/packages/agentd/scripts/run-isolated.mjs +42 -42
- package/packages/agentd/scripts/run-unit.mjs +28 -28
- package/packages/backend/src/daemon.mjs +69 -69
- package/packages/backend/src/server.mjs +270 -270
- package/packages/drivers/{agy.mjs → agy/index.mjs} +2 -1
- package/packages/drivers/{claude.mjs → claude/index.mjs} +23 -1
- package/packages/drivers/{codex.mjs → codex/index.mjs} +2 -1
- package/packages/drivers/{dsh.mjs → dsh/index.mjs} +3 -2
- package/packages/drivers/grok/index.mjs +96 -0
- package/packages/drivers/index.mjs +25 -12
- package/packages/drivers/{kimi.mjs → kimi/index.mjs} +2 -1
- package/packages/drivers/{mcode.mjs → mcode/index.mjs} +2 -1
- package/packages/drivers/{opencode.mjs → opencode/index.mjs} +2 -1
- package/packages/drivers/{pi.mjs → pi/index.mjs} +3 -2
- package/packages/drivers/probes/acp.mjs +109 -109
- package/packages/drivers/probes/index.mjs +131 -129
- package/packages/drivers/probes/provider.mjs +222 -222
- package/packages/drivers/qoder/index.mjs +32 -0
- package/packages/drivers/{bin.mjs → shared/bin.mjs} +2 -0
- package/packages/drivers/shared/index.mjs +2 -0
- package/packages/preflight/bin/preflight.mjs +116 -116
- package/packages/preflight/src/index.mjs +5 -5
- package/packages/preflight/src/report.mjs +18 -1
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/index-CT8dIwav.css +2 -0
- package/packages/web/dist/assets/index-CypTUMFB.js +79 -0
- package/packages/web/dist/favicon-32.png +0 -0
- package/packages/web/dist/favicon.svg +19 -15
- package/packages/web/dist/index.html +5 -5
- package/packages/web/dist/assets/index-B2kdkHNw.js +0 -79
- package/packages/web/dist/assets/index-DQTyjC4x.css +0 -2
- /package/packages/drivers/{dsh-sessions.mjs → dsh/sessions.mjs} +0 -0
- /package/packages/drivers/{pi-catalog.mjs → pi/catalog.mjs} +0 -0
- /package/packages/drivers/{lib.mjs → shared/lib.mjs} +0 -0
|
@@ -1,238 +1,294 @@
|
|
|
1
|
-
const AUTH_HINT_RE = /\b(401|unauthorized|unauthenticated|not logged in|login required|auth(?:entication)? (?:failed|required)|invalid api key|missing api key|credential)\b
|
|
2
|
-
|
|
3
|
-
function isWideCodePoint(cp) {
|
|
4
|
-
return (
|
|
5
|
-
cp >= 0x1100 &&
|
|
6
|
-
(cp <= 0x115f ||
|
|
7
|
-
cp === 0x2329 ||
|
|
8
|
-
cp === 0x232a ||
|
|
9
|
-
(cp >= 0x2e80 && cp <= 0xa4cf && cp !== 0x303f) ||
|
|
10
|
-
(cp >= 0xac00 && cp <= 0xd7a3) ||
|
|
11
|
-
(cp >= 0xf900 && cp <= 0xfaff) ||
|
|
12
|
-
(cp >= 0xfe10 && cp <= 0xfe19) ||
|
|
13
|
-
(cp >= 0xfe30 && cp <= 0xfe6f) ||
|
|
14
|
-
(cp >= 0xff00 && cp <= 0xff60) ||
|
|
15
|
-
(cp >= 0xffe0 && cp <= 0xffe6) ||
|
|
16
|
-
(cp >= 0x20000 && cp <= 0x3fffd))
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function displayWidth(str) {
|
|
21
|
-
let w = 0;
|
|
22
|
-
for (const ch of String(str ?? '')) {
|
|
23
|
-
w += isWideCodePoint(ch.codePointAt(0) ?? 0) ? 2 : 1;
|
|
24
|
-
}
|
|
25
|
-
return w;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function padDisplay(str, targetWidth) {
|
|
29
|
-
const s = String(str ?? '');
|
|
30
|
-
let out = '';
|
|
31
|
-
let w = 0;
|
|
32
|
-
for (const ch of s) {
|
|
33
|
-
const cw = isWideCodePoint(ch.codePointAt(0) ?? 0) ? 2 : 1;
|
|
34
|
-
if (w + cw > targetWidth) {
|
|
35
|
-
if (targetWidth >= 1 && w < targetWidth) {
|
|
36
|
-
out += '…';
|
|
37
|
-
w += 1;
|
|
38
|
-
} else if (out.length > 0) {
|
|
39
|
-
const last = [...out].pop();
|
|
40
|
-
const lw = isWideCodePoint(last.codePointAt(0) ?? 0) ? 2 : 1;
|
|
41
|
-
out = out.slice(0, -last.length) + '…';
|
|
42
|
-
w = w - lw + 1;
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
out += ch;
|
|
47
|
-
w += cw;
|
|
48
|
-
}
|
|
49
|
-
return out + ' '.repeat(Math.max(0, targetWidth - w));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
if (!
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
lines.push(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
lines.push(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
lines.push(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
lines.push(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
1
|
+
const AUTH_HINT_RE = /\b(401|403|unauthorized|unauthenticated|not logged in|login required|auth(?:entication)? (?:failed|required)|invalid api key|missing api key|credential|token expired)\b|未登录|认证失败|登录失效|请先登录/i;
|
|
2
|
+
|
|
3
|
+
function isWideCodePoint(cp) {
|
|
4
|
+
return (
|
|
5
|
+
cp >= 0x1100 &&
|
|
6
|
+
(cp <= 0x115f ||
|
|
7
|
+
cp === 0x2329 ||
|
|
8
|
+
cp === 0x232a ||
|
|
9
|
+
(cp >= 0x2e80 && cp <= 0xa4cf && cp !== 0x303f) ||
|
|
10
|
+
(cp >= 0xac00 && cp <= 0xd7a3) ||
|
|
11
|
+
(cp >= 0xf900 && cp <= 0xfaff) ||
|
|
12
|
+
(cp >= 0xfe10 && cp <= 0xfe19) ||
|
|
13
|
+
(cp >= 0xfe30 && cp <= 0xfe6f) ||
|
|
14
|
+
(cp >= 0xff00 && cp <= 0xff60) ||
|
|
15
|
+
(cp >= 0xffe0 && cp <= 0xffe6) ||
|
|
16
|
+
(cp >= 0x20000 && cp <= 0x3fffd))
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function displayWidth(str) {
|
|
21
|
+
let w = 0;
|
|
22
|
+
for (const ch of String(str ?? '')) {
|
|
23
|
+
w += isWideCodePoint(ch.codePointAt(0) ?? 0) ? 2 : 1;
|
|
24
|
+
}
|
|
25
|
+
return w;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function padDisplay(str, targetWidth) {
|
|
29
|
+
const s = String(str ?? '');
|
|
30
|
+
let out = '';
|
|
31
|
+
let w = 0;
|
|
32
|
+
for (const ch of s) {
|
|
33
|
+
const cw = isWideCodePoint(ch.codePointAt(0) ?? 0) ? 2 : 1;
|
|
34
|
+
if (w + cw > targetWidth) {
|
|
35
|
+
if (targetWidth >= 1 && w < targetWidth) {
|
|
36
|
+
out += '…';
|
|
37
|
+
w += 1;
|
|
38
|
+
} else if (out.length > 0) {
|
|
39
|
+
const last = [...out].pop();
|
|
40
|
+
const lw = isWideCodePoint(last.codePointAt(0) ?? 0) ? 2 : 1;
|
|
41
|
+
out = out.slice(0, -last.length) + '…';
|
|
42
|
+
w = w - lw + 1;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
out += ch;
|
|
47
|
+
w += cw;
|
|
48
|
+
}
|
|
49
|
+
return out + ' '.repeat(Math.max(0, targetWidth - w));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function padDisplayMiddle(str, targetWidth) {
|
|
53
|
+
const s = String(str ?? '');
|
|
54
|
+
const total = displayWidth(s);
|
|
55
|
+
if (total <= targetWidth) return s + ' '.repeat(Math.max(0, targetWidth - total));
|
|
56
|
+
if (targetWidth <= 3) return padDisplay(s, targetWidth);
|
|
57
|
+
const chars = [...s];
|
|
58
|
+
const budget = targetWidth - 1;
|
|
59
|
+
const tailBudget = Math.max(4, Math.min(8, Math.floor(budget * 0.42)));
|
|
60
|
+
const headBudget = budget - tailBudget;
|
|
61
|
+
let head = '';
|
|
62
|
+
let hw = 0;
|
|
63
|
+
for (const ch of chars) {
|
|
64
|
+
const cw = isWideCodePoint(ch.codePointAt(0) ?? 0) ? 2 : 1;
|
|
65
|
+
if (hw + cw > headBudget) break;
|
|
66
|
+
head += ch;
|
|
67
|
+
hw += cw;
|
|
68
|
+
}
|
|
69
|
+
const tailChars = [];
|
|
70
|
+
let tw = 0;
|
|
71
|
+
const remainForTail = budget - hw;
|
|
72
|
+
for (let i = chars.length - 1; i >= 0; i -= 1) {
|
|
73
|
+
const ch = chars[i];
|
|
74
|
+
const cw = isWideCodePoint(ch.codePointAt(0) ?? 0) ? 2 : 1;
|
|
75
|
+
if (tw + cw > remainForTail) break;
|
|
76
|
+
tailChars.unshift(ch);
|
|
77
|
+
tw += cw;
|
|
78
|
+
}
|
|
79
|
+
const out = `${head}…${tailChars.join('')}`;
|
|
80
|
+
return out + ' '.repeat(Math.max(0, targetWidth - (hw + 1 + tw)));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function formatDuration(ms) {
|
|
84
|
+
const n = Number(ms);
|
|
85
|
+
if (!Number.isFinite(n) || n < 0) return '-';
|
|
86
|
+
if (n < 1000) return `${Math.round(n)}ms`;
|
|
87
|
+
const s = n / 1000;
|
|
88
|
+
if (s < 60) return `${s.toFixed(1)}s`;
|
|
89
|
+
const m = Math.floor(s / 60);
|
|
90
|
+
const rem = Math.round(s % 60);
|
|
91
|
+
return `${m}m${rem}s`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function authFixHint(cli, errMessage, hintMap = null) {
|
|
95
|
+
const msg = String(errMessage ?? '');
|
|
96
|
+
if (msg.includes('登录提示(')) return null;
|
|
97
|
+
if (!AUTH_HINT_RE.test(msg)) return null;
|
|
98
|
+
const target = cli || '该工具';
|
|
99
|
+
const specific = cli && hintMap ? hintMap[cli] : null;
|
|
100
|
+
if (specific) return `登录提示(${target}):${specific}`;
|
|
101
|
+
return `提示:${target} 可能尚未登录或凭证已失效。请在终端运行对应官方登录命令完成授权,或运行 "hbus ui" / "hbus provider add" 配置第三方兼容渠道。`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function formatList({ clis = [], cliStatus = null, roles = [], workspaces = [], providers = [] }) {
|
|
105
|
+
const lines = [];
|
|
106
|
+
lines.push('=== Harness Bus 可用能力 ===');
|
|
107
|
+
if (Array.isArray(cliStatus) && cliStatus.length) {
|
|
108
|
+
const installed = cliStatus.filter((c) => c.installed).map((c) => c.type);
|
|
109
|
+
const missing = cliStatus.filter((c) => !c.installed).map((c) => c.type);
|
|
110
|
+
lines.push(`已就绪工具 (${installed.length}): ${installed.length ? installed.join(', ') : '(暂无,请先安装至少一款受支持的原生 CLI)'}`);
|
|
111
|
+
if (missing.length) lines.push(`未安装工具 (${missing.length}): ${missing.join(', ')}`);
|
|
112
|
+
} else {
|
|
113
|
+
lines.push(`原生工具: ${clis.length ? clis.join(', ') : '(无)'}`);
|
|
114
|
+
}
|
|
115
|
+
if (providers.length) {
|
|
116
|
+
lines.push(`第三方渠道: ${providers.map((p) => `${p.id}(${(p.types ?? []).join('/')})`).join(', ')}`);
|
|
117
|
+
}
|
|
118
|
+
lines.push('');
|
|
119
|
+
lines.push('推荐角色 (--role):');
|
|
120
|
+
for (const r of roles) {
|
|
121
|
+
const cliTag = r.type ? ` [默认 ${r.type}]` : '';
|
|
122
|
+
const srcTag = r.source && r.source !== 'builtin' ? ` (${r.source})` : '';
|
|
123
|
+
lines.push(` - ${r.id.padEnd(12)} ${r.name}${cliTag}${srcTag}: ${r.role || ''}`.trimEnd());
|
|
124
|
+
}
|
|
125
|
+
lines.push('');
|
|
126
|
+
const threads = workspaces.flatMap((w) => w.threads ?? []);
|
|
127
|
+
if (!threads.length) {
|
|
128
|
+
lines.push('当前目录活跃工作线: (暂无,派活时传 --topic <主题名> 自动创建)');
|
|
129
|
+
} else {
|
|
130
|
+
lines.push(`工作线 (${threads.length}):`);
|
|
131
|
+
for (const t of threads) {
|
|
132
|
+
const state = t.busy ? `running(${t.activity?.phase ?? 'busy'})` : t.waiting ? `queued(${t.waiting})` : t.alive ? 'idle' : 'saved';
|
|
133
|
+
const label = t.topic ? `${t.topic}` : `(临时 ${t.id})`;
|
|
134
|
+
const roleStr = t.role ? ` role=${t.role}` : '';
|
|
135
|
+
const modelStr = t.model ? ` model=${t.model}` : '';
|
|
136
|
+
const ctxStr = t.context?.percent != null ? ` ctx=${Math.round(t.context.percent)}%` : '';
|
|
137
|
+
lines.push(` - [${state}] ${label} | ${t.type}${modelStr}${roleStr}${ctxStr} | key=${t.key}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return lines.join('\n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function formatPs({ workspaces = [] }) {
|
|
144
|
+
const all = workspaces.flatMap((w) =>
|
|
145
|
+
(w.threads ?? []).map((t) => ({
|
|
146
|
+
ws: w.label || w.id,
|
|
147
|
+
thread: t,
|
|
148
|
+
})),
|
|
149
|
+
);
|
|
150
|
+
const running = all.filter((x) => x.thread.busy || x.thread.waiting > 0);
|
|
151
|
+
const lines = [];
|
|
152
|
+
lines.push(`Harness Bus 状态: ${running.length} 个运行/排队中 / 共 ${all.length} 条工作线`);
|
|
153
|
+
if (!all.length) {
|
|
154
|
+
lines.push(' (当前无活跃或已登记工作线)');
|
|
155
|
+
return lines.join('\n');
|
|
156
|
+
}
|
|
157
|
+
lines.push('');
|
|
158
|
+
lines.push('STATE WORKSPACE TOPIC/ID CLI PHASE ELAPSED IDLE LAST TOOL');
|
|
159
|
+
for (const { ws, thread: t } of all) {
|
|
160
|
+
const state = t.busy ? 'RUNNING' : t.waiting > 0 ? `QUEUED(${t.waiting})` : t.alive ? 'IDLE' : 'SAVED';
|
|
161
|
+
const name = t.topic || t.id;
|
|
162
|
+
const phase = t.busy ? (t.activity?.phase ?? 'running') : t.unstable ? 'unstable' : '-';
|
|
163
|
+
const elapsed = t.busy ? formatDuration(t.activity?.elapsedMs) : '-';
|
|
164
|
+
const idle = t.busy ? formatDuration(t.activity?.idleMs) : '-';
|
|
165
|
+
const tool = t.busy ? (t.activity?.openToolSummary || t.activity?.tool || '-') : (t.lastError ? `ERR: ${t.lastError.slice(0, 32)}` : '-');
|
|
166
|
+
lines.push(
|
|
167
|
+
`${padDisplay(state, 12)} ${padDisplayMiddle(ws, 18)} ${padDisplayMiddle(name, 20)} ${padDisplay(t.type, 9)} ${padDisplay(phase, 10)} ${padDisplay(elapsed, 8)} ${padDisplay(idle, 8)} ${String(tool).slice(0, 48)}`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return lines.join('\n');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function formatRunResult(res) {
|
|
174
|
+
const lines = [];
|
|
175
|
+
const head = `[${res.cli ?? 'agent'}${res.topic ? ` / ${res.topic}` : ''}] job=${res.jobId} thread=${res.thread}`;
|
|
176
|
+
if (res.async || res.timedOut) {
|
|
177
|
+
const why = res.timedOut ? '已超出同步等待时限,任务仍在后台继续运行' : '任务已在后台异步启动';
|
|
178
|
+
lines.push(`${head} — ${why}`);
|
|
179
|
+
if (res.tail) {
|
|
180
|
+
lines.push(`当前阶段: ${res.tail.phase ?? 'starting'} | 已用时 ${formatDuration(res.tail.elapsedMs)} | 工具调用 ${res.tail.toolCalls ?? 0} 次`);
|
|
181
|
+
if (res.tail.openToolSummary) lines.push(`进行中工具: ${res.tail.openToolSummary}`);
|
|
182
|
+
}
|
|
183
|
+
lines.push(`后续收结果: hbus wait ${res.jobId} 或查看轨迹: hbus tail ${res.jobId} --mode tools`);
|
|
184
|
+
return lines.join('\n');
|
|
185
|
+
}
|
|
186
|
+
const dur = formatDuration(res.metrics?.durationMs ?? res.metrics?.totalMs);
|
|
187
|
+
const tools = res.metrics?.toolCalls ?? 0;
|
|
188
|
+
const ctxPart = res.metrics?.context?.percent != null ? `, 上下文 ${Math.round(res.metrics.context.percent)}%` : '';
|
|
189
|
+
lines.push(`${head} — 完成 (${dur}, ${tools} 次工具调用${ctxPart})`);
|
|
190
|
+
const body = res.reply?.text ?? res.text ?? '';
|
|
191
|
+
if (body) {
|
|
192
|
+
lines.push('');
|
|
193
|
+
lines.push(body);
|
|
194
|
+
}
|
|
195
|
+
if ((res.reply?.omitted ?? 0) > 0 && res.reply?.file) {
|
|
196
|
+
lines.push(`\n(回复已自动头尾裁剪,完整内容保存在: ${res.reply.file})`);
|
|
197
|
+
}
|
|
198
|
+
return lines.join('\n');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function formatFanoutResult(res) {
|
|
202
|
+
const lines = [];
|
|
203
|
+
lines.push(
|
|
204
|
+
`=== 并行扇出汇总 (${formatDuration(res.totalMs)}) — 完成 ${res.succeeded} · 运行中 ${res.running} · 失败 ${res.failed} ===`,
|
|
205
|
+
);
|
|
206
|
+
for (const r of res.results ?? []) {
|
|
207
|
+
const tag = `${r.cli ?? r.target?.cli ?? 'auto'}${r.role ? `/${r.role}` : ''}${r.topic ? `/${r.topic}` : ''}`;
|
|
208
|
+
lines.push('');
|
|
209
|
+
if (!r.ok) {
|
|
210
|
+
lines.push(`--- [${tag}] 失败 ---`);
|
|
211
|
+
lines.push(r.error || 'unknown error');
|
|
212
|
+
const hint = r.authHint || authFixHint(r.cli ?? r.target?.cli, r.error);
|
|
213
|
+
if (hint && !String(r.error ?? '').includes(hint)) lines.push(hint);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (r.timedOut || r.async) {
|
|
217
|
+
lines.push(`--- [${tag}] 仍在后台运行 (job=${r.jobId}) ---`);
|
|
218
|
+
lines.push(`查看进度: hbus tail ${r.jobId} --mode tools | 等待完成: hbus wait ${r.jobId}`);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const dur = formatDuration(r.metrics?.durationMs);
|
|
222
|
+
lines.push(`--- [${tag}] 完成 (${dur}, ${r.metrics?.toolCalls ?? 0} 次工具, job=${r.jobId}) ---`);
|
|
223
|
+
lines.push(r.reply?.text ?? r.text ?? '(无输出)');
|
|
224
|
+
}
|
|
225
|
+
return lines.join('\n');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function formatTail(snap, mode = 'summary') {
|
|
229
|
+
if (!snap) return '未找到对应任务或工作线运行记录。';
|
|
230
|
+
const lines = [];
|
|
231
|
+
const state = snap.running ? `运行中(${snap.phase ?? 'busy'})` : `已结束(${snap.outcome ?? snap.metrics?.outcome ?? 'done'})`;
|
|
232
|
+
lines.push(`job=${snap.jobId} thread=${snap.thread} 状态=${state} 用时=${formatDuration(snap.elapsedMs)} 静默=${formatDuration(snap.idleMs)} 工具=${snap.toolCalls ?? 0}次`);
|
|
233
|
+
if (snap.openToolSummary) lines.push(`进行中工具: ${snap.openToolSummary} (已持续 ${formatDuration(snap.openToolMs)})`);
|
|
234
|
+
if (snap.recentTools?.length) {
|
|
235
|
+
lines.push('最近工具轨迹:');
|
|
236
|
+
for (const t of snap.recentTools.slice(-12)) {
|
|
237
|
+
const st = t.status ?? 'ok';
|
|
238
|
+
const title = t.title || t.kind || t.id;
|
|
239
|
+
lines.push(` - [${st}] ${title}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (snap.error) lines.push(`错误: ${snap.error}`);
|
|
243
|
+
if (mode !== 'tools') {
|
|
244
|
+
const body = snap.preview ?? snap.reply?.text ?? snap.text ?? '';
|
|
245
|
+
if (body) {
|
|
246
|
+
lines.push('');
|
|
247
|
+
lines.push(body);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return lines.join('\n');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function formatModels({ cli, catalog, effort = null, providers = [], authHint = null }) {
|
|
254
|
+
const lines = [];
|
|
255
|
+
lines.push(`=== ${cli} 可用模型 ===`);
|
|
256
|
+
const ep = catalog?.endpoint ?? null;
|
|
257
|
+
if (ep?.mode === 'custom') {
|
|
258
|
+
const parts = [];
|
|
259
|
+
if (ep.baseUrl) parts.push(`地址 ${ep.baseUrl}`);
|
|
260
|
+
if (ep.models && Object.keys(ep.models).length) {
|
|
261
|
+
parts.push(`本机别名映射 ${Object.entries(ep.models).map(([k, v]) => `${k}→${v}`).join(', ')}`);
|
|
262
|
+
}
|
|
263
|
+
lines.push(`接入来源: 本机自定义映射 (${parts.join(' | ')})`);
|
|
264
|
+
} else if (ep?.mode === 'official') {
|
|
265
|
+
lines.push('接入来源: 官方默认直连');
|
|
266
|
+
}
|
|
267
|
+
if (catalog?.default) lines.push(`默认模型: ${catalog.default}`);
|
|
268
|
+
const list = catalog?.models ?? [];
|
|
269
|
+
if (!list.length) {
|
|
270
|
+
lines.push('原生模型: (未探测到,可加 --refresh 重新探测,或确认该 CLI 已登录)');
|
|
271
|
+
if (authHint) lines.push(`登录指引: ${authHint}`);
|
|
272
|
+
} else {
|
|
273
|
+
lines.push(`原生模型 (${list.length}):`);
|
|
274
|
+
for (const m of list) {
|
|
275
|
+
const def = m.value === catalog.default ? ' [默认]' : '';
|
|
276
|
+
const label = m.name && m.name !== m.value ? ` (${m.name})` : '';
|
|
277
|
+
lines.push(` - ${m.value}${label}${def}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const eff = effort ?? catalog?.effort ?? null;
|
|
281
|
+
if (eff?.options?.length) {
|
|
282
|
+
const opts = eff.options.map((o) => (o.value === eff.current ? `${o.value}[当前]` : o.value)).join(', ');
|
|
283
|
+
lines.push(`推理强度 (--effort): ${opts}`);
|
|
284
|
+
}
|
|
285
|
+
const matching = (providers ?? []).filter((p) => Array.isArray(p.types) && p.types.includes(cli));
|
|
286
|
+
if (matching.length) {
|
|
287
|
+
lines.push('');
|
|
288
|
+
lines.push(`适配 ${cli} 的第三方渠道 (${matching.length}):`);
|
|
289
|
+
for (const p of matching) {
|
|
290
|
+
lines.push(` - --provider ${p.id} (${p.name || p.id}): ${(p.models ?? []).join(', ') || '(未配置模型)'}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return lines.join('\n');
|
|
294
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { runCli } from './commands.mjs';
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
const code = await runCli(process.argv.slice(2));
|
|
6
|
-
process.exit(code);
|
|
7
|
-
} catch (err) {
|
|
8
|
-
const msg = err?.message ?? String(err);
|
|
9
|
-
process.stderr.write(`错误: ${msg}\n`);
|
|
10
|
-
if (process.env.HBUS_DEBUG === '1' && err?.stack) {
|
|
11
|
-
process.stderr.write(`${err.stack}\n`);
|
|
12
|
-
}
|
|
13
|
-
process.exit(1);
|
|
14
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runCli } from './commands.mjs';
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
const code = await runCli(process.argv.slice(2));
|
|
6
|
+
process.exit(code);
|
|
7
|
+
} catch (err) {
|
|
8
|
+
const msg = err?.message ?? String(err);
|
|
9
|
+
process.stderr.write(`错误: ${msg}\n`);
|
|
10
|
+
if (process.env.HBUS_DEBUG === '1' && err?.stack) {
|
|
11
|
+
process.stderr.write(`${err.stack}\n`);
|
|
12
|
+
}
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { helpText, parseArgv, runCli } from './commands.mjs';
|
|
2
|
-
export { authFixHint, displayWidth, formatDuration, formatFanoutResult, formatList, formatModels, formatPs, formatRunResult, formatTail, padDisplay } from './format.mjs';
|
|
3
|
-
export { PLAYBOOKS_SOURCE, ROUTING_SOURCE, SKILL_NAME, SKILL_SOURCE, installSkills, skillTargets, statusSkills, uninstallSkills } from './skill-install.mjs';
|
|
4
|
-
export { CHECK_INTERVAL_MS, PACKAGE_NAME, checkForUpdate, compareSemver, fetchLatestVersion, formatUpdateNotice, getCachedUpdateNotice, maybeNotifyUpdate, readUpdateCache, updateCacheFile, writeUpdateCache } from './update.mjs';
|
|
1
|
+
export { helpText, parseArgv, runCli } from './commands.mjs';
|
|
2
|
+
export { authFixHint, displayWidth, formatDuration, formatFanoutResult, formatList, formatModels, formatPs, formatRunResult, formatTail, padDisplay, padDisplayMiddle } from './format.mjs';
|
|
3
|
+
export { CUSTOM_SOURCE, PLAYBOOKS_SOURCE, ROUTING_SOURCE, SKILL_NAME, SKILL_SOURCE, installSkills, skillTargets, statusSkills, uninstallSkills } from './skill-install.mjs';
|
|
4
|
+
export { CHECK_INTERVAL_MS, PACKAGE_NAME, checkForUpdate, compareSemver, fetchLatestVersion, formatUpdateNotice, getCachedUpdateNotice, maybeNotifyUpdate, readUpdateCache, updateCacheFile, writeUpdateCache } from './update.mjs';
|