@aiyiran/myclaw 1.1.156 → 1.1.160
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/assets/debug-collector.js +5 -45
- package/assets/debug-probe.js +1 -19
- package/assets/myclaw-inject.js +95 -59
- package/package.json +1 -1
|
@@ -120,54 +120,14 @@ function appendDebugEvent(probeEvent) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
123
|
+
* 控制日志长度。
|
|
124
124
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* - 关键事件(导航 / 交互 / 各类报错)优先全量保留;
|
|
129
|
-
* - console 只保留最近一批,给它单独的配额。
|
|
125
|
+
* 【当前阶段:全量,不做任何丢弃/折叠】
|
|
126
|
+
* 先采集完整真实的数据流以便观察。待看清真实形态后,再实现
|
|
127
|
+
* "错误锚点 + 重复折叠 + 丢弃留痕"的精简策略(届时恢复本函数)。
|
|
130
128
|
*/
|
|
131
129
|
function trimDebugEvents(events) {
|
|
132
|
-
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const KEY_TYPES = new Set([
|
|
137
|
-
"probe-ready",
|
|
138
|
-
"page-enter",
|
|
139
|
-
"click",
|
|
140
|
-
"keydown",
|
|
141
|
-
"runtime-error",
|
|
142
|
-
"unhandledrejection",
|
|
143
|
-
"resource-error",
|
|
144
|
-
"console-truncated"
|
|
145
|
-
]);
|
|
146
|
-
|
|
147
|
-
const keyEvents = events.filter((event) => KEY_TYPES.has(event.type));
|
|
148
|
-
const consoleEvents = events.filter((event) => !KEY_TYPES.has(event.type));
|
|
149
|
-
|
|
150
|
-
// console 配额 = 总上限减去关键事件占用,至少留一部分给 console。
|
|
151
|
-
const consoleQuota = Math.max(0, MAX_EVENTS - keyEvents.length);
|
|
152
|
-
const keptConsole = consoleEvents.slice(-consoleQuota);
|
|
153
|
-
|
|
154
|
-
// 合并后按 seq 还原时间顺序,再做去重。
|
|
155
|
-
const merged = [...keyEvents, ...keptConsole].sort(
|
|
156
|
-
(a, b) => (a.seq || 0) - (b.seq || 0)
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const seen = new Set();
|
|
160
|
-
const deduped = [];
|
|
161
|
-
|
|
162
|
-
for (const event of merged) {
|
|
163
|
-
const key = event.seq || `${event.type}-${event.time}-${event.pageUrl}`;
|
|
164
|
-
if (seen.has(key)) continue;
|
|
165
|
-
seen.add(key);
|
|
166
|
-
deduped.push(event);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
events.length = 0;
|
|
170
|
-
events.push(...deduped.slice(-MAX_EVENTS));
|
|
130
|
+
return;
|
|
171
131
|
}
|
|
172
132
|
|
|
173
133
|
/**
|
package/assets/debug-probe.js
CHANGED
|
@@ -19,18 +19,11 @@
|
|
|
19
19
|
|
|
20
20
|
window.__OPENCLAW_DEBUG_PROBE_INSTALLED__ = true;
|
|
21
21
|
|
|
22
|
-
const PROBE_VERSION = "
|
|
22
|
+
const PROBE_VERSION = "probe_005";
|
|
23
23
|
const MAX_TEXT_LENGTH = 1000;
|
|
24
24
|
const MAX_STACK_LENGTH = 3000;
|
|
25
25
|
const MAX_ELEMENT_TEXT_LENGTH = 80;
|
|
26
26
|
|
|
27
|
-
// console 上报限流:作品可能在循环里疯狂打 log,无节制上报会刷爆父页面
|
|
28
|
-
// 的事件缓冲、把 page-enter / error 等关键事件挤掉。超过上限后停止上报
|
|
29
|
-
// console(其它类型不受影响),并补一条截断提示。
|
|
30
|
-
const MAX_CONSOLE_EVENTS = 100;
|
|
31
|
-
let _consoleEventCount = 0;
|
|
32
|
-
let _consoleTruncatedNotified = false;
|
|
33
|
-
|
|
34
27
|
function now() {
|
|
35
28
|
return new Date().toISOString();
|
|
36
29
|
}
|
|
@@ -229,22 +222,11 @@
|
|
|
229
222
|
original.apply(console, args);
|
|
230
223
|
} catch (error) {}
|
|
231
224
|
|
|
232
|
-
// error 级别始终上报(数量少且关键);log/warn 受限流约束。
|
|
233
|
-
if (level !== "error" && _consoleEventCount >= MAX_CONSOLE_EVENTS) {
|
|
234
|
-
if (!_consoleTruncatedNotified) {
|
|
235
|
-
_consoleTruncatedNotified = true;
|
|
236
|
-
sendEvent("console-truncated", { limit: MAX_CONSOLE_EVENTS });
|
|
237
|
-
}
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
225
|
try {
|
|
242
226
|
const stringArgs = args.map(function (arg) {
|
|
243
227
|
return truncate(safeStringify(arg), MAX_TEXT_LENGTH);
|
|
244
228
|
});
|
|
245
229
|
|
|
246
|
-
if (level !== "error") _consoleEventCount++;
|
|
247
|
-
|
|
248
230
|
sendEvent("console", {
|
|
249
231
|
level,
|
|
250
232
|
message: truncate(stringArgs.join(" "), MAX_TEXT_LENGTH),
|
package/assets/myclaw-inject.js
CHANGED
|
@@ -315,61 +315,66 @@
|
|
|
315
315
|
|
|
316
316
|
// ═══ 3. Debug 按钮 ═══
|
|
317
317
|
|
|
318
|
-
function
|
|
319
|
-
var
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
btn.innerHTML = [
|
|
325
|
-
'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18"',
|
|
326
|
-
' viewBox="0 0 24 24" fill="none" stroke="currentColor"',
|
|
327
|
-
' stroke-width="2" stroke-linecap="round" stroke-linejoin="round">',
|
|
328
|
-
' <path d="m8 2 1.88 1.88"/>',
|
|
329
|
-
' <path d="M14.12 3.88 16 2"/>',
|
|
330
|
-
' <path d="M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/>',
|
|
331
|
-
' <path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/>',
|
|
332
|
-
' <path d="M12 20v-9"/>',
|
|
333
|
-
' <path d="M6.53 9C4.6 9.43 3 11.3 3 13.5"/>',
|
|
334
|
-
' <path d="M20.97 13.5c0-2.2-1.6-4.07-3.53-4.5"/>',
|
|
335
|
-
' <path d="M4 19.5c0-2.2 1.8-4 4-4"/>',
|
|
336
|
-
' <path d="M20 19.5c0-2.2-1.8-4-4-4"/>',
|
|
337
|
-
'</svg>',
|
|
338
|
-
].join("");
|
|
318
|
+
function buildTestDonePrompt() {
|
|
319
|
+
var rec = window.myclawLastDebugRecord;
|
|
320
|
+
var lines = [
|
|
321
|
+
"我刚才已经完成了测试。",
|
|
322
|
+
"请你检查我的测试数据 debug/debug-record.html,重点查看里面的 JS 日志。",
|
|
323
|
+
];
|
|
339
324
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
325
|
+
if (rec && rec.debugRecordPath) {
|
|
326
|
+
lines.push("如果你能读取本地路径,也可以查看:" + rec.debugRecordPath);
|
|
327
|
+
}
|
|
328
|
+
if (rec && rec.entryFile) {
|
|
329
|
+
lines.push("我刚才测试的文件是:" + rec.entryFile);
|
|
330
|
+
}
|
|
344
331
|
|
|
345
|
-
|
|
332
|
+
lines.push("");
|
|
333
|
+
lines.push("请帮我判断:我们之前的问题是否已经修复。");
|
|
334
|
+
lines.push("如果已经修复,请简单说明你从日志里看到了什么证据。");
|
|
335
|
+
lines.push("如果还没有修复,请指出日志里最关键的问题,并建议下一步最小修改。");
|
|
336
|
+
|
|
337
|
+
return lines.join("\n");
|
|
346
338
|
}
|
|
347
339
|
|
|
348
|
-
function
|
|
340
|
+
function createProblemMenuButton() {
|
|
341
|
+
var wrap = document.createElement("div");
|
|
342
|
+
wrap.id = "myclaw-problem-menu";
|
|
343
|
+
|
|
349
344
|
var btn = document.createElement("button");
|
|
350
|
-
btn.id = "myclaw-
|
|
345
|
+
btn.id = "myclaw-problem-btn";
|
|
346
|
+
btn.type = "button";
|
|
351
347
|
btn.className = "agent-chat__input-btn";
|
|
352
|
-
btn.title = "
|
|
353
|
-
btn.setAttribute("aria-label", "
|
|
354
|
-
btn.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
348
|
+
btn.title = "查问题";
|
|
349
|
+
btn.setAttribute("aria-label", "查问题");
|
|
350
|
+
btn.textContent = "查问题";
|
|
351
|
+
|
|
352
|
+
var menu = document.createElement("div");
|
|
353
|
+
menu.className = "myclaw-problem-menu-panel";
|
|
354
|
+
|
|
355
|
+
function makeItem(text, onClick) {
|
|
356
|
+
var item = document.createElement("button");
|
|
357
|
+
item.type = "button";
|
|
358
|
+
item.className = "myclaw-problem-menu-item";
|
|
359
|
+
item.textContent = text;
|
|
360
|
+
item.addEventListener("click", function (e) {
|
|
361
|
+
e.preventDefault();
|
|
362
|
+
e.stopPropagation();
|
|
363
|
+
onClick();
|
|
364
|
+
});
|
|
365
|
+
return item;
|
|
366
|
+
}
|
|
366
367
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
368
|
+
menu.appendChild(makeItem("查报错", showDebugModal));
|
|
369
|
+
menu.appendChild(makeItem("加日志", showLogModal));
|
|
370
|
+
menu.appendChild(makeItem("看结果", function () {
|
|
371
|
+
setTextareaValue(buildTestDonePrompt());
|
|
372
|
+
trySend();
|
|
373
|
+
}));
|
|
371
374
|
|
|
372
|
-
|
|
375
|
+
wrap.appendChild(btn);
|
|
376
|
+
wrap.appendChild(menu);
|
|
377
|
+
return wrap;
|
|
373
378
|
}
|
|
374
379
|
|
|
375
380
|
var debugVoiceDestroyers = [];
|
|
@@ -564,7 +569,15 @@
|
|
|
564
569
|
lines.push("学生描述:" + (state.description || "(未填写)"));
|
|
565
570
|
lines.push("");
|
|
566
571
|
lines.push("请从学生描述里提取:我做了什么、发生了什么、我的预期是什么。");
|
|
567
|
-
lines.push("
|
|
572
|
+
lines.push("");
|
|
573
|
+
lines.push("如何阅读调试记录(不要通读整个 HTML,按下面抓重点):");
|
|
574
|
+
lines.push("1. 调试记录是一个 HTML 文件,完整事件数据在 <script id=\"debug-data\" type=\"application/json\"> 这段 JSON 里——只读这段,别看页面样式。");
|
|
575
|
+
lines.push("2. 先在事件里找 runtime-error / unhandledrejection / 以及 level 为 error 的 console 事件,它们是问题的起点。");
|
|
576
|
+
lines.push("3. 抓住报错事件的 message、stack、filename、lineno——直接定位到源码里出错的那个函数/那几行,只看相关代码段,不要通读整个作品文件。");
|
|
577
|
+
lines.push("4. 再倒着看报错之前的 page-enter / click / keydown / console,还原“做了什么 → 触发了什么”的因果链,确认重现路径。");
|
|
578
|
+
lines.push("5. 如果没有任何报错(属于逻辑 bug),就对比【学生的预期】和事件里 console 输出 / 交互序列反映出的【实际行为】,差异处就是 bug。");
|
|
579
|
+
lines.push("");
|
|
580
|
+
lines.push("定位到根因后只做最小修复。修复后说明:问题原因、改了哪个文件的哪段代码、为什么这样改能解决。");
|
|
568
581
|
|
|
569
582
|
return lines.join("\n");
|
|
570
583
|
}
|
|
@@ -956,8 +969,7 @@ btn.addEventListener("click", function () {
|
|
|
956
969
|
var toolbar = document.querySelector(".agent-chat__toolbar-left");
|
|
957
970
|
if (!toolbar) return;
|
|
958
971
|
if (
|
|
959
|
-
toolbar.querySelector("#myclaw-
|
|
960
|
-
toolbar.querySelector("#myclaw-log-btn") &&
|
|
972
|
+
toolbar.querySelector("#myclaw-problem-menu") &&
|
|
961
973
|
toolbar.querySelector("#myclaw-prompt-btn") &&
|
|
962
974
|
toolbar.querySelector("#myclaw-voice-btn")
|
|
963
975
|
) {
|
|
@@ -969,19 +981,17 @@ btn.addEventListener("click", function () {
|
|
|
969
981
|
window.myclawIteration.init({ trySend: trySend });
|
|
970
982
|
}
|
|
971
983
|
|
|
972
|
-
var
|
|
973
|
-
var logBtn = document.querySelector("#myclaw-log-btn") || createLogButton();
|
|
984
|
+
var problemMenu = document.querySelector("#myclaw-problem-menu") || createProblemMenuButton();
|
|
974
985
|
var promptBtn = document.querySelector("#myclaw-prompt-btn") || createPromptButton();
|
|
975
986
|
var voiceBtn = document.querySelector("#myclaw-voice-btn") || createVoiceButton();
|
|
976
987
|
|
|
977
|
-
//
|
|
988
|
+
// 插入到工具栏最前面:语音、查问题、prompt 依次靠右
|
|
978
989
|
toolbar.insertBefore(promptBtn, toolbar.firstChild);
|
|
979
|
-
toolbar.insertBefore(
|
|
980
|
-
toolbar.insertBefore(
|
|
981
|
-
toolbar.insertBefore(voiceBtn, debugBtn);
|
|
990
|
+
toolbar.insertBefore(problemMenu, promptBtn);
|
|
991
|
+
toolbar.insertBefore(voiceBtn, problemMenu);
|
|
982
992
|
|
|
983
993
|
injected = true;
|
|
984
|
-
console.log("[myclaw-inject] \u2705 \u8bed\u97f3/
|
|
994
|
+
console.log("[myclaw-inject] \u2705 \u8bed\u97f3/\u67e5\u95ee\u9898/prompt\u6309\u94ae\u5df2\u6ce8\u5165");
|
|
985
995
|
}
|
|
986
996
|
|
|
987
997
|
// ═══ 注入录音态样式 ═══
|
|
@@ -1007,6 +1017,33 @@ btn.addEventListener("click", function () {
|
|
|
1007
1017
|
" animation: myclaw-ring 1.5s ease-out infinite;",
|
|
1008
1018
|
" pointer-events: none;",
|
|
1009
1019
|
"}",
|
|
1020
|
+
/* 查问题悬浮菜单 */
|
|
1021
|
+
"#myclaw-problem-menu {",
|
|
1022
|
+
" position: relative; display: inline-flex; align-items: center; flex-shrink: 0;",
|
|
1023
|
+
"}",
|
|
1024
|
+
"#myclaw-problem-btn {",
|
|
1025
|
+
" width: auto !important; min-width: 66px; padding: 0 12px !important;",
|
|
1026
|
+
" font-size: 13px; font-weight: 700; white-space: nowrap;",
|
|
1027
|
+
" border-radius: 8px;",
|
|
1028
|
+
"}",
|
|
1029
|
+
".myclaw-problem-menu-panel {",
|
|
1030
|
+
" display: none; position: absolute; left: 0; bottom: 100%;",
|
|
1031
|
+
" min-width: 92px; padding: 6px; border-radius: 10px;",
|
|
1032
|
+
" background: #1e1e2e; border: 1px solid #3d3d5c;",
|
|
1033
|
+
" box-shadow: 0 10px 32px rgba(0,0,0,0.35); z-index: 100000;",
|
|
1034
|
+
"}",
|
|
1035
|
+
"#myclaw-problem-menu:hover .myclaw-problem-menu-panel,",
|
|
1036
|
+
"#myclaw-problem-menu:focus-within .myclaw-problem-menu-panel {",
|
|
1037
|
+
" display: flex; flex-direction: column; gap: 4px;",
|
|
1038
|
+
"}",
|
|
1039
|
+
".myclaw-problem-menu-item {",
|
|
1040
|
+
" border: none; border-radius: 7px; background: transparent; color: #cdd6f4;",
|
|
1041
|
+
" padding: 8px 10px; text-align: left; cursor: pointer;",
|
|
1042
|
+
" font-size: 13px; font-weight: 600; font-family: -apple-system,sans-serif;",
|
|
1043
|
+
"}",
|
|
1044
|
+
".myclaw-problem-menu-item:hover, .myclaw-problem-menu-item:focus {",
|
|
1045
|
+
" background: #31314a; color: #fff; outline: none;",
|
|
1046
|
+
"}",
|
|
1010
1047
|
/* 按钮处理中态:半透明 + 2秒红圈收缩动画 */
|
|
1011
1048
|
".myclaw-voice-stopping {",
|
|
1012
1049
|
" opacity: 0.5 !important;",
|
|
@@ -2309,8 +2346,7 @@ btn.addEventListener("click", function () {
|
|
|
2309
2346
|
// 持续监听 DOM 变化,确保按钮始终在
|
|
2310
2347
|
new MutationObserver(function () {
|
|
2311
2348
|
if (
|
|
2312
|
-
!document.querySelector("#myclaw-
|
|
2313
|
-
!document.querySelector("#myclaw-log-btn") ||
|
|
2349
|
+
!document.querySelector("#myclaw-problem-menu") ||
|
|
2314
2350
|
!document.querySelector("#myclaw-prompt-btn") ||
|
|
2315
2351
|
!document.querySelector("#myclaw-voice-btn")
|
|
2316
2352
|
) {
|