@tomflow/chatloop-tools 0.9.17 → 0.9.19

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.
Files changed (140) hide show
  1. package/package.json +3 -11
  2. package/providers/form.mjs +13 -5
  3. package/ui/form/review-app.js +122 -71
  4. package/ui/form/review.html +1 -814
  5. package/node_modules/@tomflow/chatloop-context/README.md +0 -240
  6. package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +0 -48
  7. package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +0 -151
  8. package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +0 -376
  9. package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +0 -266
  10. package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +0 -134
  11. package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +0 -82
  12. package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +0 -349
  13. package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +0 -72
  14. package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +0 -73
  15. package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +0 -507
  16. package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +0 -11
  17. package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +0 -182
  18. package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +0 -277
  19. package/node_modules/@tomflow/chatloop-context/index.mjs +0 -233
  20. package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +0 -86
  21. package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +0 -24
  22. package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +0 -1989
  23. package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +0 -67
  24. package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +0 -280
  25. package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -298
  26. package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -280
  27. package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +0 -115
  28. package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +0 -51
  29. package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +0 -55
  30. package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +0 -262
  31. package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +0 -246
  32. package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +0 -147
  33. package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +0 -343
  34. package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +0 -391
  35. package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +0 -166
  36. package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +0 -13
  37. package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +0 -111
  38. package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +0 -107
  39. package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +0 -117
  40. package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +0 -20
  41. package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +0 -312
  42. package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +0 -153
  43. package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +0 -19
  44. package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +0 -115
  45. package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +0 -86
  46. package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +0 -169
  47. package/node_modules/@tomflow/chatloop-context/package.json +0 -40
  48. package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +0 -114
  49. package/node_modules/@tomflow/chatloop-extension/README.md +0 -94
  50. package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +0 -11
  51. package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +0 -141
  52. package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +0 -109
  53. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +0 -1
  54. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +0 -1
  55. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +0 -1
  56. package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +0 -1
  57. package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +0 -1
  58. package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +0 -1
  59. package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +0 -1
  60. package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +0 -1
  61. package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +0 -1
  62. package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +0 -120
  63. package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +0 -180
  64. package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +0 -322
  65. package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +0 -2
  66. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +0 -378
  67. package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +0 -2
  68. package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +0 -54
  69. package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +0 -9
  70. package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +0 -20
  71. package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +0 -69
  72. package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +0 -287
  73. package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +0 -23
  74. package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +0 -2
  75. package/node_modules/@tomflow/chatloop-extension/extension/background.js +0 -16
  76. package/node_modules/@tomflow/chatloop-extension/extension/clean.html +0 -5
  77. package/node_modules/@tomflow/chatloop-extension/extension/content.js +0 -40
  78. package/node_modules/@tomflow/chatloop-extension/extension/continue.html +0 -9
  79. package/node_modules/@tomflow/chatloop-extension/extension/dom.html +0 -17
  80. package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +0 -9
  81. package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +0 -2
  82. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +0 -275
  83. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +0 -76
  84. package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +0 -107
  85. package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +0 -36
  86. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +0 -227
  87. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +0 -144
  88. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +0 -171
  89. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +0 -109
  90. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +0 -154
  91. package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +0 -254
  92. package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +0 -42
  93. package/node_modules/@tomflow/chatloop-extension/extension/popup.html +0 -25
  94. package/node_modules/@tomflow/chatloop-extension/extension/popup.js +0 -93
  95. package/node_modules/@tomflow/chatloop-extension/extension/reload.html +0 -17
  96. package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +0 -17
  97. package/node_modules/@tomflow/chatloop-extension/extension/start.html +0 -6
  98. package/node_modules/@tomflow/chatloop-extension/extension/status.html +0 -6
  99. package/node_modules/@tomflow/chatloop-extension/extension/text.html +0 -17
  100. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +0 -136
  101. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +0 -220
  102. package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +0 -122
  103. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +0 -155
  104. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +0 -185
  105. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +0 -120
  106. package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +0 -172
  107. package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +0 -165
  108. package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +0 -244
  109. package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +0 -181
  110. package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +0 -147
  111. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +0 -197
  112. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +0 -200
  113. package/node_modules/@tomflow/chatloop-extension/index.mjs +0 -71
  114. package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +0 -18
  115. package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +0 -74
  116. package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +0 -208
  117. package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +0 -40
  118. package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +0 -45
  119. package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +0 -111
  120. package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +0 -67
  121. package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +0 -120
  122. package/node_modules/@tomflow/chatloop-extension/package.json +0 -38
  123. package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +0 -133
  124. package/node_modules/@tomflow/chatloop-trace/README.md +0 -105
  125. package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +0 -23
  126. package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +0 -22
  127. package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +0 -4
  128. package/node_modules/@tomflow/chatloop-trace/index.mjs +0 -59
  129. package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +0 -273
  130. package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +0 -265
  131. package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -205
  132. package/node_modules/@tomflow/chatloop-trace/package.json +0 -30
  133. package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +0 -68
  134. package/node_modules/ps-list/index.d.ts +0 -76
  135. package/node_modules/ps-list/index.js +0 -366
  136. package/node_modules/ps-list/license +0 -9
  137. package/node_modules/ps-list/package.json +0 -44
  138. package/node_modules/ps-list/readme.md +0 -56
  139. package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
  140. package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
@@ -1,322 +0,0 @@
1
- // Sole writer for one autonomous continuation. Never imported by the Chat page.
2
- // The background schedules an Action page; this page alone performs the DOM mutation.
3
- const statusNode = document.getElementById("status");
4
- const detailsNode = document.getElementById("details");
5
- function show(status, details) {
6
- statusNode.textContent = status;
7
- detailsNode.textContent = details;
8
- document.body.dataset.result = status === "SUCCESS" ? "success" : "error";
9
- }
10
- async function sendOnce(target, text) {
11
- const [execution] = await chrome.scripting.executeScript({
12
- target: {tabId: target.tabId},
13
- func: async (expected, instruction) => {
14
- try {
15
- if (location.origin !== "https://chatgpt.com" || location.pathname !== expected.page)
16
- throw Error("CHAT_PAGE_CHANGED");
17
- const visible = node => Boolean(node?.getClientRects?.().length)
18
- && !node.closest?.('[hidden],[aria-hidden="true"]')
19
- && getComputedStyle(node).display !== "none";
20
- const mains = [...document.querySelectorAll("main")].filter(visible);
21
- if (mains.length !== 1) throw Error("CHAT_MAIN_UNVERIFIED");
22
- const main = mains[0];
23
- const modern = [...main.querySelectorAll(
24
- '[data-chatgpt-search-unit-key][data-chatgpt-search-message-ids]')];
25
- const legacy = [...main.querySelectorAll('[data-message-author-role]')];
26
- const roles = modern.length ? modern : legacy;
27
- const role = node => node.getAttribute("data-message-author-role")
28
- || node.getAttribute("data-chatgpt-search-unit-key")?.split(":").at(-1);
29
- const idOf = node => node?.getAttribute("data-message-id")
30
- || node?.getAttribute("data-chatgpt-search-message-ids")?.trim().split(/\s+/)[0]
31
- || node?.closest('[data-testid^="conversation-turn-"]')?.getAttribute("data-testid");
32
- const user = roles.filter(node => role(node) === "user").at(-1);
33
- const answer = roles.filter(node => role(node) === "assistant").at(-1);
34
- if ("user:" + idOf(user) !== expected.userKey
35
- || "assistant:" + idOf(answer) !== expected.assistantKey)
36
- throw Error("TURN_IDENTITY_CHANGED");
37
- const scope = answer.closest('[data-testid^="conversation-turn-"]')
38
- || answer.closest('[data-talvt-turn-state]') || answer;
39
- const replyText = (answer.querySelector('.markdown')?.innerText || answer.innerText || '').trim();
40
- const lines = replyText.split(/\r?\n/);
41
- const expectedMarker=expected.recoveryMode==="ADOPT_KICKOFF"
42
- ? null : expected.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
43
- ? "[CHAT_LOOP_STATUS:BLOCKED]" : expected.recoveryMode==="HANDOFF_NOT_SENT"
44
- ? expected.contextSourceMarker : "[CHAT_LOOP_STATUS:CONTINUE]";
45
- if ((expectedMarker===null
46
- ? lines.some(line=>/^\[CHAT_LOOP_STATUS:(?:CONTINUE|DONE|BLOCKED|HANDOFF)\]$/.test(line.trim()))
47
- : lines.at(-1)?.trim() !== expectedMarker
48
- ||lines.filter(line=>/^\[CHAT_LOOP_STATUS:(?:CONTINUE|DONE|BLOCKED|HANDOFF)\]$/.test(line.trim())).length !== 1)) {
49
- throw Error("CONTINUE_STATUS_CHANGED");
50
- }
51
- const turnState = scope.getAttribute?.('data-talvt-turn-state');
52
- if (turnState && turnState !== "complete") throw Error("TURN_NOT_COMPLETE");
53
- if ([...document.querySelectorAll('button[data-testid="stop-button"],button[aria-label="停止响应"],button[aria-label="Stop generating"]')].some(visible))
54
- throw Error("GENERATION_STILL_RUNNING");
55
- if (![...scope.querySelectorAll('button[aria-label="复制"],button[aria-label="Copy"],button[data-testid="copy-turn-action-button"]')].some(visible))
56
- throw Error("FINAL_UI_EVIDENCE_MISSING");
57
- let input = document.querySelector('[contenteditable="true"][data-composer-markdown]')
58
- || document.querySelector('#prompt-textarea[contenteditable="true"]')
59
- || document.querySelector('[data-testid="composer-input"][contenteditable="true"]');
60
- if (!visible(input) || input.closest('[aria-disabled="true"]'))
61
- throw Error("COMPOSER_UNAVAILABLE");
62
- if ((input.innerText || input.textContent || '').trim())
63
- throw Error("COMPOSER_NOT_EMPTY");
64
- input.focus();
65
- if (!document.execCommand("insertText", false, instruction)) throw Error("INPUT_NOT_ACCEPTED");
66
- // DOM writes can precede React composer state. Do not click a stale
67
- // enabled button in the same task as insertion (especially after reset).
68
- await new Promise(resolve => setTimeout(resolve, 400));
69
- const canonical = value => String(value || '').replace(/\s+/g, '');
70
- let verified = false;
71
- for (let n = 0; n < 30; n++) {
72
- if (canonical(input.innerText) === canonical(instruction)
73
- || canonical(input.textContent) === canonical(instruction)) {verified = true; break;}
74
- await new Promise(resolve => setTimeout(resolve, 120));
75
- }
76
- if (!verified) throw Error("INPUT_NOT_VERIFIED");
77
- let button;
78
- for (let n = 0; n < 16; n++) {
79
- button = document.querySelector('button[type="submit"][aria-label="发送"]')
80
- || document.querySelector('button[data-testid="send-button"]')
81
- || document.querySelector('button[data-testid="composer-send-button"]')
82
- || document.querySelector('button[aria-label="Send message"]');
83
- if (button && !button.disabled && visible(button)) break;
84
- await new Promise(resolve => setTimeout(resolve, 120));
85
- }
86
- if (!button || button.disabled || !visible(button)) throw Error("SEND_BUTTON_UNAVAILABLE");
87
- // Final same-page DOM guard. The Worker checked before Action Take; a
88
- // confirmation may appear while React settles the composer. Reuse
89
- // Observer's existing read-only detection, no new action or state.
90
- const gate = globalThis.ChatLoopTurnObserverV1?.poll?.();
91
- if (gate?.contract !== "chat-loop.turn-observer.v1"
92
- || gate.page !== expected.page
93
- || gate.userKey !== expected.userKey
94
- || gate.assistantKey !== expected.assistantKey
95
- || gate.reason === "WAITING_CHAT_HYDRATION"
96
- || typeof gate.pendingConfirmation !== "boolean")
97
- throw Error("CONFIRMATION_OBSERVER_UNVERIFIED");
98
- if (gate.pendingConfirmation) throw Error("CONFIRMATION_PENDING_DOM");
99
- if (location.pathname !== expected.page) throw Error("CHAT_PAGE_CHANGED_BEFORE_SEND");
100
- if (canonical(input.innerText) !== canonical(instruction)
101
- && canonical(input.textContent) !== canonical(instruction)) throw Error("INPUT_CHANGED_BEFORE_SEND");
102
- // Snapshot the visible message identities before the ONE irreversible
103
- // click. A matching latest bubble is not enough if the UI exposes TWO
104
- // newly created user Turns for this one send.
105
- const beforeUserIds = new Set(roles.filter(node => role(node) === "user")
106
- .map(idOf).filter(Boolean));
107
- button.click(); // Once, after durable PENDING commit in the worker. Never retry.
108
- let candidateId = null, candidateStableAt = 0;
109
- for (let n = 0; n < 32; n++) {
110
- if (location.pathname !== expected.page) throw Error("CHAT_PAGE_CHANGED_AFTER_SEND");
111
- const visibleMain = [...document.querySelectorAll("main")].filter(visible);
112
- if (visibleMain.length !== 1) throw Error("CHAT_MAIN_CHANGED_AFTER_SEND");
113
- const rows = [...visibleMain[0].querySelectorAll(
114
- '[data-chatgpt-search-unit-key][data-chatgpt-search-message-ids], [data-message-author-role]')];
115
- const users = rows.filter(node => role(node) === "user");
116
- const latest = users.at(-1), newId = idOf(latest);
117
- const newIds = [...new Set(users.map(idOf)
118
- .filter(id => id && !beforeUserIds.has(id)))];
119
- if (newIds.length > 1) throw Error("DUPLICATE_USER_TURN_UNVERIFIED");
120
- if (newId && 'user:' + newId !== expected.userKey) {
121
- // On live ChatGPT the collapsed bubble has a "显示更多"
122
- // button; only the actual message text qualifies as a receipt.
123
- const message = latest?.querySelector('[data-search-result-target]')
124
- || latest?.querySelector('[data-user-message-bubble="true"]') || latest;
125
- if (newIds.length !== 1 || newIds[0] !== newId
126
- || (canonical(message?.innerText) !== canonical(instruction)
127
- && canonical(message?.textContent) !== canonical(instruction)))
128
- throw Error("NEW_USER_TURN_UNVERIFIED");
129
- if (candidateId !== newId) {
130
- candidateId = newId;
131
- candidateStableAt = Date.now();
132
- }
133
- // Recheck the DOM for a short stable window; one immediate new
134
- // bubble does not prove that no duplicate followed the click.
135
- if (Date.now() - candidateStableAt >= 750)
136
- return {status: "SENT_CONFIRMED", newUserKey: 'user:' + newId,
137
- newPage: location.pathname};
138
- }
139
- await new Promise(resolve => setTimeout(resolve, 250));
140
- }
141
- throw Error("SEND_UNVERIFIED"); // Side effect may exist: block, don't retry.
142
- } catch (error) {return {status: "UNVERIFIED", reason: error.message || "SEND_ERROR"};}
143
- },
144
- args: [target, text]
145
- });
146
- if (!execution?.result || execution.result.status !== "SENT_CONFIRMED")
147
- throw Error(execution?.result?.reason || "SEND_RESULT_UNVERIFIED");
148
- return execution.result;
149
- }
150
- // Reuse the formal Continue Action page for a *different* one-shot recovery
151
- // operation. Native Retry targets the existing user Turn: never type or send.
152
- async function retryNativeOnce(target) {
153
- const [execution] = await chrome.scripting.executeScript({
154
- target: {tabId: target.tabId},
155
- func: async expected => {
156
- try {
157
- if (location.origin !== "https://chatgpt.com" || location.pathname !== expected.page)
158
- throw Error("RETRY_CHAT_CHANGED");
159
- const visible = node => Boolean(node?.getClientRects?.().length)
160
- && !node.closest?.('[hidden],[aria-hidden="true"]')
161
- && getComputedStyle(node).display !== "none";
162
- const mains = [...document.querySelectorAll('main')].filter(visible);
163
- if (mains.length !== 1) throw Error("RETRY_MAIN_UNVERIFIED");
164
- const main = mains[0];
165
- const rows = [...main.querySelectorAll('[data-chatgpt-search-unit-key][data-chatgpt-search-message-ids]')];
166
- const messages = rows.length ? rows : [...main.querySelectorAll('[data-message-author-role]')];
167
- const role = node => node.getAttribute('data-message-author-role')
168
- || node.getAttribute('data-chatgpt-search-unit-key')?.split(':').at(-1);
169
- const id = node => node?.getAttribute('data-message-id')
170
- || node?.getAttribute('data-chatgpt-search-message-ids')?.trim().split(/\s+/)[0]
171
- || node?.closest('[data-testid^="conversation-turn-"]')?.getAttribute('data-testid');
172
- const latestUser = messages.filter(node => role(node) === 'user').at(-1);
173
- const latestAssistant = messages.filter(node => role(node) === 'assistant').at(-1);
174
- if ('user:' + id(latestUser) !== expected.userKey
175
- || (latestAssistant ? 'assistant:' + id(latestAssistant) : null) !== expected.assistantKey)
176
- throw Error("RETRY_TURN_CHANGED");
177
- if ([...document.querySelectorAll('button[data-testid="stop-button"],button[aria-label="停止响应"],button[aria-label="Stop generating"]')].some(visible))
178
- throw Error("RETRY_STILL_GENERATING");
179
- const alerts = [...main.querySelectorAll('[role="alert"],[role="status"],[data-testid="conversation-error"]')]
180
- .filter(visible);
181
- const failed = alerts.filter(el => /unknown error|something went wrong|an error occurred|unable to load|connection (?:lost|interrupted)|请求失败|网络错误|发生错误|出错了/i.test(el.innerText || el.textContent || ''));
182
- if (failed.length !== 1) throw Error("RETRY_ERROR_NOT_UNIQUE");
183
- const buttons = [...failed[0].querySelectorAll('button')].filter(button => visible(button)
184
- && /^(?:retry|try again|重试|再试一次)$/i.test(
185
- (button.innerText || button.textContent || button.getAttribute('aria-label') || '').trim()));
186
- if (buttons.length !== 1 || buttons[0].disabled) throw Error("RETRY_BUTTON_UNVERIFIED");
187
- buttons[0].click(); // Exact native retry on the existing user Turn, once.
188
- // Require visible evidence that the page accepted the native retry,
189
- // not merely that the click function returned without throwing.
190
- for (let attempt = 0; attempt < 24; attempt++) {
191
- await new Promise(resolve => setTimeout(resolve, 250));
192
- if (location.pathname !== expected.page) throw Error("RETRY_PAGE_CHANGED_AFTER_CLICK");
193
- const current = [...document.querySelectorAll('main')].filter(visible);
194
- if (current.length !== 1) throw Error("RETRY_MAIN_CHANGED_AFTER_CLICK");
195
- const latest = [...current[0].querySelectorAll('[role="alert"],[role="status"],[data-testid="conversation-error"]')]
196
- .filter(visible).some(el => /unknown error|something went wrong|an error occurred|unable to load|connection (?:lost|interrupted)|请求失败|网络错误|发生错误|出错了/i.test(el.innerText || el.textContent || ''));
197
- if (!latest) return {status: 'RETRY_CLICKED'};
198
- }
199
- throw Error("NATIVE_RETRY_NOT_ACKNOWLEDGED");
200
- } catch(error) {return {status:'UNVERIFIED',reason:error.message||'RETRY_FAILED'};}
201
- }, args: [target]
202
- });
203
- return execution?.result || {status:'UNVERIFIED',reason:'RETRY_RESULT_UNKNOWN'};
204
- }
205
- // Recovery-only UI reveal. A Worker+Native CAS check must grant the exact
206
- // terminal Owner before this Action can move its viewport. No message is sent.
207
- async function revealLatestOwnerTurn(tabId, expectedPage) {
208
- const [execution]=await chrome.scripting.executeScript({
209
- target:{tabId},
210
- func: page => {
211
- if(location.origin!=='https://chatgpt.com'||location.pathname!==page)
212
- return 'CHAT_PAGE_CHANGED';
213
- const marks=[...document.querySelectorAll('main [data-chatgpt-search-unit-key]')];
214
- let ancestor=marks.at(-1);
215
- if(!ancestor)return 'NO_VISIBLE_TURN';
216
- while(ancestor){
217
- const style=getComputedStyle(ancestor);
218
- if(/^(auto|scroll)$/.test(style.overflowY)
219
- &&ancestor.scrollHeight-ancestor.clientHeight>24){
220
- ancestor.scrollTop=ancestor.scrollHeight;
221
- return 'SCROLLED';
222
- }
223
- ancestor=ancestor.parentElement;
224
- }
225
- return 'CHAT_SCROLL_CONTAINER_UNVERIFIED';
226
- },args:[expectedPage]
227
- });
228
- if(execution?.result!=='SCROLLED')
229
- throw Error(execution?.result||'CHAT_SCROLL_UNVERIFIED');
230
- }
231
- async function run() {
232
- const params = new URLSearchParams(location.search);
233
- const raw = params.get("tabId") || "";
234
- let token = params.get("token") || "";
235
- let tabId = Number(raw);
236
- if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation" && k !== "resumeBlockedAt" && k !== "recoverContextNotSentAt" && k !== "adoptBaselineAt" && k !== "adoptKickoffAt")
237
- || [...params.keys()].length !== new Set(params.keys()).size)
238
- throw Error("ACTION_PARAMETERS_INVALID");
239
- if (raw && !/^[1-9][0-9]*$/.test(raw)
240
- || token && !/^[0-9a-f-]{36}$/.test(token)
241
- || token && (!raw||params.has("repairLegacyReservation")||params.has("resumeBlockedAt")
242
- ||params.has("recoverContextNotSentAt"))) throw Error("ACTION_PARAMETERS_INVALID");
243
- const own = await chrome.tabs.getCurrent();
244
- if (!own?.id || own.url !== location.href) throw Error("ACTION_TAB_UNVERIFIED");
245
- if(params.has("adoptBaselineAt")){
246
- const rawAt=params.get("adoptBaselineAt"),at=Number(rawAt);
247
- if(params.size!==2||!raw||token||!/^[1-9][0-9]{12}$/.test(rawAt||"")
248
- ||!Number.isSafeInteger(at))
249
- throw Error("ADOPT_BASELINE_PARAMETERS_INVALID");
250
- show("VERIFYING","对同一原 Chat 的历史审批回复进行只读复核;绝不发送消息。");
251
- const result=await chrome.runtime.sendMessage({
252
- type:"CHAT_LOOP_ADOPT_BASELINE_REPAIR_V1",
253
- tabId,nativeUpdatedAt:at});
254
- if(result?.status!=="REPAIRED")
255
- throw Error(result?.code||"ADOPT_BASELINE_REPAIR_UNVERIFIED");
256
- show("SUCCESS","已对原 Chat 完成历史基线恢复;未创建 Chat、未发送消息。");
257
- await chrome.tabs.remove(own.id);
258
- return;
259
- }
260
- if(params.has("adoptKickoffAt")){
261
- const rawAt=params.get("adoptKickoffAt"),at=Number(rawAt);
262
- if(params.size!==2||!raw||token||!/^[1-9][0-9]{12}$/.test(rawAt||"")
263
- ||!Number.isSafeInteger(at))
264
- throw Error("ADOPT_KICKOFF_PARAMETERS_INVALID");
265
- show("VERIFYING","核查当前 Managed Task、已批准 R/P 和原 Chat 的历史回复,再申请唯一首轮执行许可。");
266
- const prepared=await chrome.runtime.sendMessage({
267
- type:"CHAT_LOOP_ADOPT_KICKOFF_PREPARE_V1",tabId,nativeUpdatedAt:at});
268
- if(prepared?.status!=="PREPARED")
269
- throw Error(prepared?.code||"ADOPT_KICKOFF_NOT_PREPARED");
270
- token=prepared.token;
271
- }
272
- if (!token) {
273
- show("VERIFYING", "手动打开 Continue:核对当前已完成的 Turn,并申请单次发送许可。");
274
- if(params.has("resumeBlockedAt")){
275
- // A terminal Chat may be displaying an older virtualized segment. Only
276
- // the exact operator-acknowledged Native revision can authorize a
277
- // one-time scroll by this formal Action, before double identity proof.
278
- const reveal=await chrome.runtime.sendMessage({
279
- type:"CHAT_LOOP_ACTION_MANUAL_REVEAL_V1",
280
- tabId,resumeBlockedAt:Number(params.get("resumeBlockedAt"))
281
- });
282
- if(reveal?.status!=="OK")throw Error(reveal?.code||"REVEAL_NOT_AUTHORIZED");
283
- await revealLatestOwnerTurn(tabId,reveal.page);
284
- await new Promise(resolve=>setTimeout(resolve,400));
285
- }
286
- const prepared = await chrome.runtime.sendMessage({
287
- type: "CHAT_LOOP_ACTION_MANUAL_PREPARE_V1", action: "CONTINUE",
288
- ...(raw ? {tabId} : {})
289
- });
290
- if (prepared?.status !== "PREPARED")
291
- throw Error(prepared?.code || "MANUAL_PREPARE_DENIED");
292
- tabId = prepared.tabId;
293
- token = prepared.token;
294
- }
295
- const request = {token, tabId};
296
- const permit = await chrome.runtime.sendMessage({type: "CHAT_LOOP_ACTION_TAKE_V1", ...request});
297
- if (permit?.status === "DENIED" && permit.code === "PENDING_CONFIRMATION_DOM") {
298
- // The Worker durably returned the Owner to WAITING_REPLY before denying
299
- // this Action. No click occurred; close the now-obsolete Action tab so
300
- // pending human choices do not accumulate background Chrome tabs.
301
- await chrome.tabs.remove(own.id);
302
- return;
303
- }
304
- if (permit?.status !== "OK" || permit.target?.tabId !== tabId)
305
- throw Error(permit?.code || "ACTION_NOT_AUTHORIZED");
306
- show("RUNNING", "已独占一次发送许可,正在核验目标 Chat 和最新已完成 Turn。");
307
- let result;
308
- try { result = permit.retryMode === "NATIVE"
309
- ? await retryNativeOnce(permit.target) : await sendOnce(permit.target, permit.text); }
310
- catch (error) { result = {status: "UNVERIFIED", reason: error.message || "SEND_ERROR"}; }
311
- const final = await chrome.runtime.sendMessage({type: "CHAT_LOOP_ACTION_RESULT_V1", ...request,
312
- result: result.status, reason: result.reason, newUserKey: result.newUserKey, newPage: result.newPage});
313
- if (!(result.status === "SENT_CONFIRMED" || permit.retryMode === "NATIVE"
314
- && result.status === "RETRY_CLICKED") || final?.status !== "OK")
315
- throw Error(result.reason || final?.code || "ACTION_RESULT_NOT_COMMITTED");
316
- show("SUCCESS", permit.retryMode === "NATIVE" ? "已点击原消息的网页重试一次;没有发送新用户消息。"
317
- : "已确认新增一次用户消息;Action 已完成,等待下一轮 Observer。");
318
- await chrome.tabs.remove(own.id);
319
- }
320
- (new URLSearchParams(location.search).has("requestId")
321
- ? import(chrome.runtime.getURL("actions/index.js")).then(m => m.queueModelIntent("continue")) : run())
322
- .catch(error => show("BLOCKED", error.message || "ACTION_FAILED"));
@@ -1,2 +0,0 @@
1
- // DOM Action: independent entrypoint; shared verified read path.
2
- void globalThis.ChatLoopActionCommonV1.runReadAction('dom',1000);