@tomflow/chatloop-extension 0.3.47 → 0.3.53
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/README.md +23 -7
- package/bin/cli.mjs +2 -2
- package/bin/native-host.mjs +3 -6
- package/extension/actions/clean.js +4 -10
- package/extension/actions/common.js +24 -1
- package/extension/actions/continue.js +33 -66
- package/extension/actions/dom.js +2 -25
- package/extension/actions/handoff.js +30 -50
- package/extension/actions/start.js +36 -1
- package/extension/actions/text.js +2 -25
- package/extension/background.js +429 -479
- package/extension/loop/core.js +3 -16
- package/extension/loop/observer.js +129 -3
- package/extension/loop/resources.js +25 -15
- package/extension/manifest.json +1 -1
- package/extension/popup.html +0 -1
- package/extension/popup.js +1 -1
- package/lib/bridge.mjs +12 -16
- package/lib/session-file.mjs +21 -3
- package/package.json +1 -1
- package/extension/acceptance.js +0 -641
- package/extension/actions/clock.js +0 -29
- package/extension/clock.html +0 -4
- package/lib/mcp-tools.json +0 -26
package/README.md
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## P0 资源生命周期(Extension Worker 唯一仲裁)
|
|
4
4
|
|
|
5
|
-
`extension/loop/resources.js` 在既有 Worker 内维护持久资源索引,不引入第二浏览器驱动。正式 Action 同时最多 3 页,已登记执行 Chat 同时最多 2 页(Owner 与 Handoff successor);新建前拒绝超限。已存在的普通 Chat、未知发送、BLOCKED 或带草稿页面不自动关闭。只对精确登记且测试 projectId 为 `cl-intent-e2e-*` 的 DONE Chat 执行空草稿、非激活、URL 未变化的 TTL 回收。用户真实任务的 Chat 不会自动删除;其配额满时安全拒绝新建,需用户确认归属后清理。机器只读 Action 最多 3 分钟后有界回收;写入 Action 仅凭匹配终态与 token
|
|
5
|
+
`extension/loop/resources.js` 在既有 Worker 内维护持久资源索引,不引入第二浏览器驱动。正式 Action 同时最多 3 页,已登记执行 Chat 同时最多 2 页(Owner 与 Handoff successor);新建前拒绝超限。已存在的普通 Chat、未知发送、BLOCKED 或带草稿页面不自动关闭。只对精确登记且测试 projectId 为 `cl-intent-e2e-*` 的 DONE Chat 执行空草稿、非激活、URL 未变化的 TTL 回收。用户真实任务的 Chat 不会自动删除;其配额满时安全拒绝新建,需用户确认归属后清理。机器只读 Action 最多 3 分钟后有界回收;写入 Action 仅凭匹配终态与 token 回收。资源创建/关闭/峰值/拒绝写入唯一 `chat-loop.resources.v1` 供 Worker 回溯;未知收据不补发。`ACTION_RESULT_TIMEOUT_UNVERIFIED` 为安全 BLOCKED,不是自动重试。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**运行状态与手动操作**:首轮发送前新 Chat 未就绪时 Worker 记录安全白名单内的失败码并 BLOCKED,绝不补发未知用户消息。Popup 常规环境检测和用户明确点击 Clean 仍可用,且 Clean 必须经过 Worker 同一个 Action 配额准入。原 `popup.html?audit=1`、`newTest` 与各种隐藏测试清理参数已从运行入口移除;升级时遗留的精确 audit 页仅在非活动且到期后由原有资源管理器清理。
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
**验收边界**:源码测试不等于已安装 Chrome 实测。安装 npm 新包并 Reload 后须由正式 Extension Audit 验证 `resources` 字段及资源前后/峰值;未见该字段即表示仍在运行旧扩展。
|
|
9
|
+
**验收边界**:离线源码回归不等于已安装 Chrome 真机通过;正式安装包的 Owner、资源配额及受控发送需要独立实测,不能用旧版证据替代。
|
|
12
10
|
|
|
13
11
|
Chrome 扩展(9 个独立 Action,含 Status / Start)及其独立 CLI / Native Messaging Host。执行前先看 Help:
|
|
14
12
|
|
|
@@ -34,13 +32,15 @@ Run: chatloop-extension extension <command> --help
|
|
|
34
32
|
|
|
35
33
|
**Chrome 独立运行安装路径:**先用 `npm install --prefix "$HOME/.chat-loop/extension/npm" --save-exact --ignore-scripts @tomflow/chatloop-extension@latest` 下载,再在 `chrome://extensions` 加载该目录下的 `node_modules/@tomflow/chatloop-extension/extension`。改目录会改变扩展 ID,必须通过同一个 npm 包的 `host install <id>` 更新 Native Host。详情见 [Extension 主文档](../../docs/extension.md)。
|
|
36
34
|
|
|
35
|
+
**原 Chat 接管候选接口**:用户在同一普通 Chat 完成两轮真实 R/P 确认后,用 `chat_loop_extension__start({projectId,mode:'adopt',confirmed:true})` 申请原地绑定;可选提供规范化的 `chatUrl` 精确限制候选范围,但不可用它代替批准证据。扩展自己核对真实网页 R→user确认→P(引用当前R)→user确认,必须唯一匹配;不新建 Chat、不写输入框、不重发消息。未匹配/多匹配/版本变化一律拒绝;当前代码的正式 Chrome E2E 尚未完成,不能以本机测试替代发布。
|
|
36
|
+
|
|
37
37
|
`extension start` 正常只在 `status=IDLE`、用户确认后启动。上一 Session 若是 `BLOCKED`,可在用户**再次明确批准一个不同 projectId 的全新任务**时附上 `replaceBlockedSessionId`(精确 UUID)作为受控替换条件:扩展 Worker 与本机持久指针必须同时指向该 BLOCKED Session,才能允许新 Session;旧执行 Chat 保留审计,旧用户 Turn 永不自动重发。示例只用于说明 JSON 签名,不会自动调用:
|
|
38
38
|
|
|
39
39
|
```json
|
|
40
40
|
{"projectId":"new-distinct-test","prompt":"新的独立任务","confirmed":true,"replaceBlockedSessionId":"11111111-1111-4111-a111-111111111111"}
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
`PAGE_ERROR` 且无原生 Retry 时,Worker
|
|
43
|
+
`PAGE_ERROR` 且无原生 Retry 时,Worker 最多四次只读核实同一用户消息;只有同一 Turn 的错误消失并连续稳定,才恢复观察;仍有错误、身份变化或回执不明时 BLOCKED。`lastFaultProof` 存在当前 Owner 的持久状态中,不会把当前网页错误消失推断成“可以重发”。
|
|
44
44
|
|
|
45
45
|
Clean 只清空输入框,不发送,不更改 Owner;必须指定精确标签页 ID 且验证目标。Chrome 已安装扩展不随 npm 包自动安装。本地源码与已发布 npm 版本可能不同,真实结果请看 [CURRENT](../../context/CURRENT.md)。
|
|
46
46
|
|
|
@@ -50,4 +50,20 @@ Clean 只清空输入框,不发送,不更改 Owner;必须指定精确标
|
|
|
50
50
|
|
|
51
51
|
**0.3.46 Chrome pendingUrl 修复**:Worker 创建正式 Action 时,以自己刚发起的受控 Extension URL 与 Chrome 返回的数值 tabId 登记资源,不能依赖 `tabs.create` 立即返回最终 `tab.url`(它可能仅有 `pendingUrl`)。Action 自身仍需验证真实 URL、Owner、token,任何未确认发送都不得重试;代码回归覆盖过渡 tab.url 缺失但单次 Action 正常创建。
|
|
52
52
|
|
|
53
|
-
**0.3.
|
|
53
|
+
**npm 发行版 0.3.48**:Worker 内正式串行消息类型统一以显式路由表派发,各处理器的来源、一次性凭证和 Owner 身份校验保持不变。此版本已发布到 npm 并安装到本机原扩展目录;Chrome 是否重新载入新代码以及真实 E2E 结果须单独验证,具体以 [CURRENT](../../context/CURRENT.md) 为准。
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
**0.3.48 中的源码级熵减**:删除仅用于旧手动验收的 Popup 脚本、Clock Action、计数/模拟墙钟状态及其专属测试。正式 Start、Continue、Handoff 与 Observer/Owner、十分钟真实时钟、错误隔离、配额与已登记测试 Chat 的安全回收保持实现。继续/交接只能由独立 Action 单次发送,用户未发送草稿不允许清除;过往隐藏验收 URL 不再可调用。确切最新测试数量及未验证项只看 [CURRENT](../../context/CURRENT.md)。
|
|
57
|
+
|
|
58
|
+
**源码候选 0.3.49(未发布)**:扩展同 Chat 接管候选修复,不改变旧新 Chat Start/Continue/Handoff 入口;需要真实 Chrome 与云端同 Chat 审批正向验收后才能发布。
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## 原 Owner 的有界技术恢复
|
|
62
|
+
|
|
63
|
+
Worker仍是唯一发送裁决者,Native会话文件只是带身份校验的持久投影。正式Status返回当前Session/Chat及有限diagnostics(版本、失败码、消息身份、恢复预算、执行时钟),不返回发送token或任务正文;终态BLOCKED的Eye可只读检查同一个已确认Owner,不获得发送权。
|
|
64
|
+
|
|
65
|
+
已由可信操作者核实修复的Start/adopt工具前置故障,可通过原内置 `continue.html?tabId=<原Owner精确tabId>` 申请一次恢复。必须保持Session/project/Chat/generation、两条原消息身份和执行时钟,无待确认表单;未知发送、权限拒绝和页面挑战不自动恢复。恢复预算在后续Continue中继续保留。恢复成功不是业务DONE。
|
|
66
|
+
|
|
67
|
+
仅升级前的0.3.52遗留预留可能需要显式 `&repairLegacyReservation=<Native原updatedAt>`:操作者须先验证保存的旧Native源码确实不能提交BLOCKED→PENDING,且原消息和指针未变。Worker还要求旧恢复来源、旧user未变、没有现代recoveryProtocol;Native在锁内对精确updatedAt做CAS。缺任何证据均禁止使用;此参数不能解锁现代未知发送,也不是自动重试机制。禁止直接编辑active-session.json。
|
|
68
|
+
|
|
69
|
+
Native与Chrome.storage是两个存储,按顺序提交不代表跨存储原子事务;中途崩溃且无法证明发送边界时保持UNVERIFIED/BLOCKED,先查正式回执,不重发。回滚Native/Extension前先核实当前Owner,不把旧代码强行覆盖正在执行的新协议。
|
package/bin/cli.mjs
CHANGED
|
@@ -11,11 +11,11 @@ const HELP={
|
|
|
11
11
|
'': 'Usage: chatloop-extension <command> [options]\nCommands: capabilities, host, extension\nRun: chatloop-extension <command> --help',
|
|
12
12
|
host: 'Usage: chatloop-extension host install <extension-id>\nRegisters the local Chrome Native Messaging Host (macOS).',
|
|
13
13
|
extension: 'Usage: chatloop-extension extension <command>\nCommands: chat text | chat dom | chat screenshot | reload | clean <tab-id> | continue | handoff | status | start\nRun: chatloop-extension extension <command> --help',
|
|
14
|
-
'extension clean':'Usage: chatloop-extension extension clean <tab-id>\nClear only the verified ChatGPT composer. Never send or close a Chat.\
|
|
14
|
+
'extension clean':'Usage: chatloop-extension extension clean <tab-id>\nClear only the verified ChatGPT composer. Never send or close a Chat.\nMachine Clean requires the exact tab id of a terminal Chat Loop Owner; popup Clean requires a user-selected ChatGPT tab.',
|
|
15
15
|
'extension continue':'Usage: chatloop-extension extension continue (JSON intent on stdin)\nSubmit next-turn text or query receipt; does not send directly.',
|
|
16
16
|
'extension handoff':'Usage: chatloop-extension extension handoff (JSON intent on stdin)\nRequest early handoff or query receipt; does not transfer directly.',
|
|
17
17
|
'extension status':'Usage: chatloop-extension extension status\nRead-only, verified active Web Chat status.',
|
|
18
|
-
'extension start':'Usage: chatloop-extension extension start (JSON on stdin)\nStart
|
|
18
|
+
'extension start':'Usage: chatloop-extension extension start (JSON on stdin)\nStart a new task with prompt, or use mode=adopt (no prompt) to bind the only R/P-approved existing Chat without sending.'
|
|
19
19
|
};
|
|
20
20
|
function helpFor(args){
|
|
21
21
|
if(args.length===1&&['-h','--help','help'].includes(args[0]))return HELP[''];
|
package/bin/native-host.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Chrome Native Messaging: one request per process, no persistent server.
|
|
3
|
-
import {readRequest, finish
|
|
3
|
+
import {readRequest, finish} from '../lib/bridge.mjs';
|
|
4
4
|
import {readSession,writeSession} from '../lib/session-file.mjs';
|
|
5
5
|
const MAX_INPUT=48*1024*1024;
|
|
6
6
|
const write=obj=>{
|
|
@@ -28,11 +28,8 @@ process.stdin.on('data',chunk=>{
|
|
|
28
28
|
}else if(m.op==='session-read'){
|
|
29
29
|
write({status:'OK',session:readSession()});
|
|
30
30
|
}else if(m.op==='session-sync'){
|
|
31
|
-
write({status:'OK',session:writeSession(m.session,
|
|
32
|
-
|
|
33
|
-
const confirmed=staleFailureConfirmed(m.id,m.action);
|
|
34
|
-
write({status:confirmed?'STALE_FAILURE_CONFIRMED':'NOT_ELIGIBLE',
|
|
35
|
-
id:m.id,action:m.action});
|
|
31
|
+
write({status:'OK',session:writeSession(m.session,
|
|
32
|
+
m.replaceBlockedSessionId,m.resumeBlockedSessionId,m.resumeBlockedUpdatedAt??null)});
|
|
36
33
|
}else throw Object.assign(Error('Unknown operation'),{code:'INVALID_OPERATION'});
|
|
37
34
|
}catch(e){write({status:'FAILED',code:e.code||'NATIVE_HOST_ERROR'});}
|
|
38
35
|
});
|
|
@@ -7,15 +7,12 @@ const isChat=url=>{try{const u=new URL(url);return u.origin==='https://chatgpt.c
|
|
|
7
7
|
&& (u.pathname==='/'||/^\/(?:c\/[0-9a-f-]{12,}|g\/[^/]+\/c\/[0-9a-f-]{12,})$/i.test(u.pathname));}
|
|
8
8
|
catch{return false;}};
|
|
9
9
|
const runKey='chat-loop.action.run.v1';
|
|
10
|
-
|
|
11
|
-
function targetAuthorized(tab,run,owned,machine,own){
|
|
10
|
+
function targetAuthorized(tab,run,machine,own){
|
|
12
11
|
if(!isChat(tab?.url) || !Number.isSafeInteger(tab?.id))throw Error('CLEAN_TARGET_NOT_CHATGPT');
|
|
13
12
|
if(tab.id===own.id)throw Error('CLEAN_SELF_TARGET');
|
|
14
13
|
if(machine){
|
|
15
|
-
const testHome=tab.url==='https://chatgpt.com/' && Array.isArray(owned)
|
|
16
|
-
&& owned.some(entry=>entry.id===tab.id);
|
|
17
14
|
const owner=run?.tabId===tab.id && tab.url==='https://chatgpt.com'+run?.page;
|
|
18
|
-
if(!
|
|
15
|
+
if(!owner)throw Error('CLEAN_MACHINE_TARGET_NOT_OWNED');
|
|
19
16
|
if(run && !['DONE','BLOCKED'].includes(run.phase))
|
|
20
17
|
throw Error('CLEAN_ACTIVE_LOOP_DENIED');
|
|
21
18
|
}else{
|
|
@@ -47,9 +44,6 @@ async function clear(target,machine){
|
|
|
47
44
|
if([...document.querySelectorAll(
|
|
48
45
|
'button[data-testid="stop-button"],button[aria-label="Stop generating"],button[aria-label="停止响应"]')]
|
|
49
46
|
.some(visible))return {status:'TURN_STILL_RUNNING'};
|
|
50
|
-
if(expected.machine&&expected.url==='https://chatgpt.com/'
|
|
51
|
-
&& main[0].querySelector('[data-chatgpt-search-message-ids],[data-message-author-role]'))
|
|
52
|
-
return {status:'TEST_HOME_HAS_MESSAGES'};
|
|
53
47
|
const before=(input.innerText||input.textContent||'').trim();
|
|
54
48
|
if(before){
|
|
55
49
|
input.focus();
|
|
@@ -91,8 +85,8 @@ async function run(){
|
|
|
91
85
|
}else tabId=Number(params.get('tabId'));
|
|
92
86
|
try{
|
|
93
87
|
const tab=await chrome.tabs.get(tabId);
|
|
94
|
-
const state=await chrome.storage.local.get(
|
|
95
|
-
targetAuthorized(tab,state[runKey],
|
|
88
|
+
const state=await chrome.storage.local.get(runKey);
|
|
89
|
+
targetAuthorized(tab,state[runKey],machine,own);
|
|
96
90
|
show('RUNNING','已确认单个目标,清理其未发送文本。');
|
|
97
91
|
const result=await clear(tab,machine);
|
|
98
92
|
if(machine){
|
|
@@ -134,6 +134,29 @@ function copyText(value) {
|
|
|
134
134
|
if (!tab?.id) throw Error("ACTION_TAB_UNVERIFIED");
|
|
135
135
|
return tab;
|
|
136
136
|
}
|
|
137
|
+
// Text and DOM share the same verified read path. Their separate pages
|
|
138
|
+
// select a fixed mode and clipboard settling delay; no extra executor.
|
|
139
|
+
async function runReadAction(mode, clipboardMs) {
|
|
140
|
+
const action="chat_"+mode;
|
|
141
|
+
try {
|
|
142
|
+
const machine=await machineBinding(action);
|
|
143
|
+
const own=requireOwnTab(await chrome.tabs.getCurrent());
|
|
144
|
+
const target=machine ? await machineTarget(machine) : await findTarget(own);
|
|
145
|
+
show("RUNNING", mode+" → ChatGPT tab "+target.id);
|
|
146
|
+
const value=await readChat(target,mode);
|
|
147
|
+
if(!value.length)throw Error("EMPTY_CONTENT");
|
|
148
|
+
if(machine)await machineResult(machine,value);
|
|
149
|
+
else {
|
|
150
|
+
copyText(value);
|
|
151
|
+
await new Promise(resolve=>setTimeout(resolve,clipboardMs));
|
|
152
|
+
}
|
|
153
|
+
await done(own,mode,target);
|
|
154
|
+
}catch(error){
|
|
155
|
+
await machineFailure(action,error);
|
|
156
|
+
fail(error.message || "UNEXPECTED_ERROR",
|
|
157
|
+
"操作未完成;动作页已保留,未对其他 ChatGPT 标签页进行操作。");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
137
160
|
function done(ownTab, action, target) {
|
|
138
161
|
show("SUCCESS", action + " completed for tab " + target.id);
|
|
139
162
|
document.body.dataset.result = "success";
|
|
@@ -141,6 +164,6 @@ function copyText(value) {
|
|
|
141
164
|
}
|
|
142
165
|
globalThis.ChatLoopActionCommonV1 = Object.freeze({
|
|
143
166
|
show, fail, findTarget, readChat, copyText, closeAction, done, requireOwnTab,
|
|
144
|
-
machineBinding, machineTarget, machineResult, machineFailure
|
|
167
|
+
machineBinding, machineTarget, machineResult, machineFailure, runReadAction
|
|
145
168
|
});
|
|
146
169
|
})();
|
|
@@ -31,18 +31,16 @@ async function sendOnce(target, text) {
|
|
|
31
31
|
|| node?.closest('[data-testid^="conversation-turn-"]')?.getAttribute("data-testid");
|
|
32
32
|
const user = roles.filter(node => role(node) === "user").at(-1);
|
|
33
33
|
const answer = roles.filter(node => role(node) === "assistant").at(-1);
|
|
34
|
-
if (expected.
|
|
35
|
-
|
|
36
|
-
} else if ("user:" + idOf(user) !== expected.userKey
|
|
37
|
-
|| "assistant:" + idOf(answer) !== expected.assistantKey) {
|
|
34
|
+
if ("user:" + idOf(user) !== expected.userKey
|
|
35
|
+
|| "assistant:" + idOf(answer) !== expected.assistantKey)
|
|
38
36
|
throw Error("TURN_IDENTITY_CHANGED");
|
|
39
|
-
}
|
|
40
|
-
if (!expected.testSetup) {
|
|
41
37
|
const scope = answer.closest('[data-testid^="conversation-turn-"]')
|
|
42
38
|
|| answer.closest('[data-talvt-turn-state]') || answer;
|
|
43
39
|
const replyText = (answer.querySelector('.markdown')?.innerText || answer.innerText || '').trim();
|
|
44
40
|
const lines = replyText.split(/\r?\n/);
|
|
45
|
-
|
|
41
|
+
const expectedMarker=expected.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
|
|
42
|
+
? "[CHAT_LOOP_STATUS:BLOCKED]" : "[CHAT_LOOP_STATUS:CONTINUE]";
|
|
43
|
+
if (lines.at(-1)?.trim() !== expectedMarker
|
|
46
44
|
|| (replyText.match(/\[CHAT_LOOP_STATUS:(?:CONTINUE|DONE|BLOCKED)\]/g) || []).length !== 1) {
|
|
47
45
|
throw Error("CONTINUE_STATUS_CHANGED");
|
|
48
46
|
}
|
|
@@ -52,50 +50,13 @@ async function sendOnce(target, text) {
|
|
|
52
50
|
throw Error("GENERATION_STILL_RUNNING");
|
|
53
51
|
if (![...scope.querySelectorAll('button[aria-label="复制"],button[aria-label="Copy"],button[data-testid="copy-turn-action-button"]')].some(visible))
|
|
54
52
|
throw Error("FINAL_UI_EVIDENCE_MISSING");
|
|
55
|
-
}
|
|
56
53
|
let input = document.querySelector('[contenteditable="true"][data-composer-markdown]')
|
|
57
54
|
|| document.querySelector('#prompt-textarea[contenteditable="true"]')
|
|
58
55
|
|| document.querySelector('[data-testid="composer-input"][contenteditable="true"]');
|
|
59
56
|
if (!visible(input) || input.closest('[aria-disabled="true"]'))
|
|
60
57
|
throw Error("COMPOSER_UNAVAILABLE");
|
|
61
|
-
if ((input.innerText || input.textContent || '').trim())
|
|
62
|
-
|
|
63
|
-
if (!expected.testSetup || !expected.discardDraft
|
|
64
|
-
|| !(draft.includes("LOOP-V037-FAST-3C1H") || (draft.startsWith("你正在接手上一 Chat 未完成的任务。旧 Chat 的网页历史仍可核实")
|
|
65
|
-
&& draft.includes("【交接参考:只读网页片段,可能截断】")
|
|
66
|
-
&& draft.includes("【原始任务用户消息】")
|
|
67
|
-
&& draft.includes("【最近轮次证据】")
|
|
68
|
-
&& draft.endsWith("是否跨 Chat 由扩展决定,不要主动要求 Handoff。")
|
|
69
|
-
&& draft.length >= 450 && draft.length <= 8192))
|
|
70
|
-
|| !((draft.startsWith("这是 Chat Loop 短轮回归专用测试")
|
|
71
|
-
&& draft.length >= 150 && draft.length <= 800)
|
|
72
|
-
|| (draft.startsWith("你正在接手上一 Chat 尚未完成的同一个任务")
|
|
73
|
-
&& draft.length >= 450 && (draft.length <= 2000
|
|
74
|
-
|| (draft.length <= 8192 && draft.includes("【原始任务用户消息】")
|
|
75
|
-
&& draft.includes("【最近轮次证据】"))))
|
|
76
|
-
|| (draft.startsWith("你正在接手上一 Chat 未完成的任务。旧 Chat 的网页历史仍可核实")
|
|
77
|
-
&& draft.includes("【原始任务用户消息】") && draft.includes("【最近轮次证据】")
|
|
78
|
-
&& draft.endsWith("是否跨 Chat 由扩展决定,不要主动要求 Handoff。")
|
|
79
|
-
&& draft.length >= 450 && draft.length <= 8192)
|
|
80
|
-
|| (draft.startsWith("这是 Chat Loop 的长回复与一小时边界隔离测试")
|
|
81
|
-
&& draft.includes("MODE-TIMED-1H") && draft.length >= 350 && draft.length <= 800)
|
|
82
|
-
|| (draft.startsWith("这是 Chat Loop 的墙钟边界隔离测试")
|
|
83
|
-
&& draft.includes("MODE-WALL-10M") && draft.endsWith("WALL-CLOCK-TEST。")
|
|
84
|
-
&& draft.length >= 250 && draft.length <= 800)))
|
|
85
|
-
throw Error("COMPOSER_NOT_EMPTY");
|
|
86
|
-
// Explicit test preparation on the caller-created empty Chat only.
|
|
87
|
-
// Never clear the source Chat or use this branch for normal continuation.
|
|
88
|
-
input.focus();
|
|
89
|
-
const range = document.createRange();
|
|
90
|
-
range.selectNodeContents(input);
|
|
91
|
-
const selection = window.getSelection();
|
|
92
|
-
selection.removeAllRanges();
|
|
93
|
-
selection.addRange(range);
|
|
94
|
-
if (!document.execCommand("delete", false)) throw Error("TEST_DRAFT_CLEAR_REJECTED");
|
|
95
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
96
|
-
if ((input.innerText || input.textContent || '').trim())
|
|
97
|
-
throw Error("TEST_DRAFT_CLEAR_UNVERIFIED");
|
|
98
|
-
}
|
|
58
|
+
if ((input.innerText || input.textContent || '').trim())
|
|
59
|
+
throw Error("COMPOSER_NOT_EMPTY");
|
|
99
60
|
input.focus();
|
|
100
61
|
if (!document.execCommand("insertText", false, instruction)) throw Error("INPUT_NOT_ACCEPTED");
|
|
101
62
|
// DOM writes can precede React composer state. Do not click a stale
|
|
@@ -119,14 +80,24 @@ async function sendOnce(target, text) {
|
|
|
119
80
|
await new Promise(resolve => setTimeout(resolve, 120));
|
|
120
81
|
}
|
|
121
82
|
if (!button || button.disabled || !visible(button)) throw Error("SEND_BUTTON_UNAVAILABLE");
|
|
83
|
+
// Final same-page DOM guard. The Worker checked before Action Take; a
|
|
84
|
+
// confirmation may appear while React settles the composer. Reuse
|
|
85
|
+
// Observer's existing read-only detection, no new action or state.
|
|
86
|
+
const gate = globalThis.ChatLoopTurnObserverV1?.poll?.();
|
|
87
|
+
if (gate?.contract !== "chat-loop.turn-observer.v1"
|
|
88
|
+
|| gate.page !== expected.page
|
|
89
|
+
|| gate.userKey !== expected.userKey
|
|
90
|
+
|| gate.assistantKey !== expected.assistantKey
|
|
91
|
+
|| gate.reason === "WAITING_CHAT_HYDRATION"
|
|
92
|
+
|| typeof gate.pendingConfirmation !== "boolean")
|
|
93
|
+
throw Error("CONFIRMATION_OBSERVER_UNVERIFIED");
|
|
94
|
+
if (gate.pendingConfirmation) throw Error("CONFIRMATION_PENDING_DOM");
|
|
122
95
|
if (location.pathname !== expected.page) throw Error("CHAT_PAGE_CHANGED_BEFORE_SEND");
|
|
123
96
|
if (canonical(input.innerText) !== canonical(instruction)
|
|
124
97
|
&& canonical(input.textContent) !== canonical(instruction)) throw Error("INPUT_CHANGED_BEFORE_SEND");
|
|
125
98
|
button.click(); // Once, after durable PENDING commit in the worker. Never retry.
|
|
126
99
|
for (let n = 0; n < 32; n++) {
|
|
127
|
-
if (
|
|
128
|
-
&& !/^\/c\/(?:[0-9a-f-]{12,}|local-chatgpt%3A[0-9a-f-]{36})$/i.test(location.pathname)
|
|
129
|
-
: location.pathname !== expected.page) throw Error("CHAT_PAGE_CHANGED_AFTER_SEND");
|
|
100
|
+
if (location.pathname !== expected.page) throw Error("CHAT_PAGE_CHANGED_AFTER_SEND");
|
|
130
101
|
const visibleMain = [...document.querySelectorAll("main")].filter(visible);
|
|
131
102
|
if (visibleMain.length !== 1) throw Error("CHAT_MAIN_CHANGED_AFTER_SEND");
|
|
132
103
|
const rows = [...visibleMain[0].querySelectorAll(
|
|
@@ -140,10 +111,6 @@ async function sendOnce(target, text) {
|
|
|
140
111
|
if (newId && 'user:' + newId !== expected.userKey
|
|
141
112
|
&& (canonical(message?.innerText) === canonical(instruction)
|
|
142
113
|
|| canonical(message?.textContent) === canonical(instruction))) {
|
|
143
|
-
if (expected.testSetup && !/^\/c\/[0-9a-f-]{12,}$/i.test(location.pathname)) {
|
|
144
|
-
await new Promise(resolve => setTimeout(resolve, 250));
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
114
|
return {status: "SENT_CONFIRMED", newUserKey: 'user:' + newId, newPage: location.pathname};
|
|
148
115
|
}
|
|
149
116
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
@@ -217,24 +184,18 @@ async function run() {
|
|
|
217
184
|
const raw = params.get("tabId") || "";
|
|
218
185
|
let token = params.get("token") || "";
|
|
219
186
|
let tabId = Number(raw);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|| !["1", "2", "10m"].includes(params.get("wall")))) throw Error("TEST_WALL_PARAMETERS_INVALID");
|
|
224
|
-
if (params.has("count") && (!setup || params.get("count") !== "86"
|
|
225
|
-
|| params.get("wall") !== "10m" || params.get("timed") !== "1"))
|
|
226
|
-
throw Error("COUNT_TEST_PARAMETERS_INVALID");
|
|
187
|
+
if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation")
|
|
188
|
+
|| [...params.keys()].length !== new Set(params.keys()).size)
|
|
189
|
+
throw Error("ACTION_PARAMETERS_INVALID");
|
|
227
190
|
if (raw && !/^[1-9][0-9]*$/.test(raw)
|
|
228
191
|
|| token && !/^[0-9a-f-]{36}$/.test(token)
|
|
229
|
-
|| token && !raw) throw Error("ACTION_PARAMETERS_INVALID");
|
|
192
|
+
|| token && (!raw||params.has("repairLegacyReservation"))) throw Error("ACTION_PARAMETERS_INVALID");
|
|
230
193
|
const own = await chrome.tabs.getCurrent();
|
|
231
194
|
if (!own?.id || own.url !== location.href) throw Error("ACTION_TAB_UNVERIFIED");
|
|
232
195
|
if (!token) {
|
|
233
|
-
show("VERIFYING",
|
|
234
|
-
? "测试首回合准备(不计作 Continue 验收):核对指定空白测试 Chat,申请一次固定测试消息许可。"
|
|
235
|
-
: "手动打开 Continue:核对当前已完成的 Turn,并申请单次发送许可。");
|
|
196
|
+
show("VERIFYING", "手动打开 Continue:核对当前已完成的 Turn,并申请单次发送许可。");
|
|
236
197
|
const prepared = await chrome.runtime.sendMessage({
|
|
237
|
-
type:
|
|
198
|
+
type: "CHAT_LOOP_ACTION_MANUAL_PREPARE_V1", action: "CONTINUE",
|
|
238
199
|
...(raw ? {tabId} : {})
|
|
239
200
|
});
|
|
240
201
|
if (prepared?.status !== "PREPARED")
|
|
@@ -244,6 +205,13 @@ async function run() {
|
|
|
244
205
|
}
|
|
245
206
|
const request = {token, tabId};
|
|
246
207
|
const permit = await chrome.runtime.sendMessage({type: "CHAT_LOOP_ACTION_TAKE_V1", ...request});
|
|
208
|
+
if (permit?.status === "DENIED" && permit.code === "PENDING_CONFIRMATION_DOM") {
|
|
209
|
+
// The Worker durably returned the Owner to WAITING_REPLY before denying
|
|
210
|
+
// this Action. No click occurred; close the now-obsolete Action tab so
|
|
211
|
+
// pending human choices do not accumulate background Chrome tabs.
|
|
212
|
+
await chrome.tabs.remove(own.id);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
247
215
|
if (permit?.status !== "OK" || permit.target?.tabId !== tabId)
|
|
248
216
|
throw Error(permit?.code || "ACTION_NOT_AUTHORIZED");
|
|
249
217
|
show("RUNNING", "已独占一次发送许可,正在核验目标 Chat 和最新已完成 Turn。");
|
|
@@ -257,7 +225,6 @@ async function run() {
|
|
|
257
225
|
&& result.status === "RETRY_CLICKED") || final?.status !== "OK")
|
|
258
226
|
throw Error(result.reason || final?.code || "ACTION_RESULT_NOT_COMMITTED");
|
|
259
227
|
show("SUCCESS", permit.retryMode === "NATIVE" ? "已点击原消息的网页重试一次;没有发送新用户消息。"
|
|
260
|
-
: setup ? "测试首回合已确认;等待正式 Continue 与 Handoff 独立执行。"
|
|
261
228
|
: "已确认新增一次用户消息;Action 已完成,等待下一轮 Observer。");
|
|
262
229
|
await chrome.tabs.remove(own.id);
|
|
263
230
|
}
|
package/extension/actions/dom.js
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
// DOM Action:
|
|
2
|
-
(
|
|
3
|
-
const {show, fail, findTarget, readChat, copyText, done, requireOwnTab,
|
|
4
|
-
machineBinding, machineTarget, machineResult, machineFailure}
|
|
5
|
-
= globalThis.ChatLoopActionCommonV1;
|
|
6
|
-
let machine;
|
|
7
|
-
async function run() {
|
|
8
|
-
machine = await machineBinding("chat_dom");
|
|
9
|
-
const own = requireOwnTab(await chrome.tabs.getCurrent());
|
|
10
|
-
const target = machine ? await machineTarget(machine) : await findTarget(own);
|
|
11
|
-
show("RUNNING", "dom → ChatGPT tab " + target.id);
|
|
12
|
-
const value = await readChat(target, "dom");
|
|
13
|
-
if (!value.length) throw Error("EMPTY_CONTENT");
|
|
14
|
-
if(machine) await machineResult(machine,value);
|
|
15
|
-
else copyText(value);
|
|
16
|
-
// Let Chrome publish selections to macOS pasteboard before closing.
|
|
17
|
-
if(!machine) await new Promise(resolve => setTimeout(resolve, 1000));
|
|
18
|
-
await done(own, "dom", target);
|
|
19
|
-
}
|
|
20
|
-
run().catch(async error => {
|
|
21
|
-
await machineFailure("chat_dom",error);
|
|
22
|
-
fail(error.message || "UNEXPECTED_ERROR",
|
|
23
|
-
"操作未完成;动作页已保留,未对其他 ChatGPT 标签页进行操作。");
|
|
24
|
-
});
|
|
25
|
-
})();
|
|
1
|
+
// DOM Action: independent entrypoint; shared verified read path.
|
|
2
|
+
void globalThis.ChatLoopActionCommonV1.runReadAction('dom',1000);
|
|
@@ -61,6 +61,19 @@ async function verifyOldChat(target, summary, mode = "EXPLICIT") {
|
|
|
61
61
|
throw Error("SOURCE_GENERATION_STILL_RUNNING");
|
|
62
62
|
if (handoffMode !== "ERROR" && ![...scope.querySelectorAll('button[aria-label="复制"],button[aria-label="Copy"],button[data-testid="copy-turn-action-button"]')].some(visible))
|
|
63
63
|
throw Error("SOURCE_NOT_FINAL");
|
|
64
|
+
// Last read-only guard before the Action creates any successor Chat:
|
|
65
|
+
// an unanswered confirmation in the current assistant Turn wins.
|
|
66
|
+
if (handoffMode !== "ERROR") {
|
|
67
|
+
const gate = globalThis.ChatLoopTurnObserverV1?.poll?.();
|
|
68
|
+
if (gate?.contract !== "chat-loop.turn-observer.v1"
|
|
69
|
+
|| gate.page !== expected.page
|
|
70
|
+
|| gate.userKey !== expected.userKey
|
|
71
|
+
|| gate.assistantKey !== expected.assistantKey
|
|
72
|
+
|| gate.reason === "WAITING_CHAT_HYDRATION"
|
|
73
|
+
|| typeof gate.pendingConfirmation !== "boolean")
|
|
74
|
+
throw Error("CONFIRMATION_OBSERVER_UNVERIFIED");
|
|
75
|
+
if (gate.pendingConfirmation) throw Error("CONFIRMATION_PENDING_DOM");
|
|
76
|
+
}
|
|
64
77
|
// Timed handoff must not modify the original Chat. Capture a bounded
|
|
65
78
|
// read-only evidence snapshot here, not through URL or Worker storage.
|
|
66
79
|
if (handoffMode === "TIMED" || handoffMode === "ERROR") {
|
|
@@ -89,56 +102,22 @@ async function verifyOldChat(target, summary, mode = "EXPLICIT") {
|
|
|
89
102
|
|| execution.result.snapshot.length < 120)) throw Error("SOURCE_SNAPSHOT_UNVERIFIED");
|
|
90
103
|
return execution.result.snapshot || summary;
|
|
91
104
|
}
|
|
92
|
-
|
|
105
|
+
// Read-only readiness of the new, strictly blank Chat home. Never clear a
|
|
106
|
+
// restored human draft, even if its text resembles a historical test prompt.
|
|
107
|
+
async function waitForNewChat(tabId) {
|
|
93
108
|
for (let attempt = 0; attempt < 520; attempt++) {
|
|
94
109
|
const tab = await chrome.tabs.get(tabId);
|
|
95
110
|
if (tab.url?.startsWith("https://chatgpt.com/")) {
|
|
96
111
|
try {
|
|
97
|
-
const [check] = await chrome.scripting.executeScript({target: {tabId}, func:
|
|
112
|
+
const [check] = await chrome.scripting.executeScript({target: {tabId}, func: () => {
|
|
98
113
|
if (location.origin !== "https://chatgpt.com" || location.pathname !== "/") return false;
|
|
99
114
|
const input = document.querySelector('[contenteditable="true"][data-composer-markdown]')
|
|
100
115
|
|| document.querySelector('#prompt-textarea[contenteditable="true"]');
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// An acceptance-only new Chat may restore the exact prior Chat Loop
|
|
105
|
-
// test instruction. Never discard a real user's unsent draft.
|
|
106
|
-
if (!allowTestClear || !(draft.includes("LOOP-V037-FAST-3C1H") || (draft.startsWith("你正在接手上一 Chat 未完成的任务。旧 Chat 的网页历史仍可核实")
|
|
107
|
-
&& draft.includes("【交接参考:只读网页片段,可能截断】")
|
|
108
|
-
&& draft.includes("【原始任务用户消息】")
|
|
109
|
-
&& draft.includes("【最近轮次证据】")
|
|
110
|
-
&& draft.endsWith("是否跨 Chat 由扩展决定,不要主动要求 Handoff。")
|
|
111
|
-
&& draft.length >= 450 && draft.length <= 8192))
|
|
112
|
-
|| !((draft.startsWith("这是 Chat Loop 短轮回归专用测试")
|
|
113
|
-
&& draft.length >= 150 && draft.length <= 800)
|
|
114
|
-
|| (draft.startsWith("你正在接手上一 Chat 尚未完成的同一个任务")
|
|
115
|
-
&& draft.length >= 450 && (draft.length <= 2000
|
|
116
|
-
|| (draft.length <= 8192 && draft.includes("【原始任务用户消息】")
|
|
117
|
-
&& draft.includes("【最近轮次证据】"))))
|
|
118
|
-
|| (draft.startsWith("你正在接手上一 Chat 未完成的任务。旧 Chat 的网页历史仍可核实")
|
|
119
|
-
&& draft.includes("【原始任务用户消息】") && draft.includes("【最近轮次证据】")
|
|
120
|
-
&& draft.endsWith("是否跨 Chat 由扩展决定,不要主动要求 Handoff。")
|
|
121
|
-
&& draft.length >= 450 && draft.length <= 8192)
|
|
122
|
-
|| (draft.startsWith("这是 Chat Loop 的长回复与一小时边界隔离测试")
|
|
123
|
-
&& draft.includes("MODE-TIMED-1H") && draft.length >= 350 && draft.length <= 800)
|
|
124
|
-
|| (draft.startsWith("这是 Chat Loop 的计数隔离验收")
|
|
125
|
-
&& draft.includes("COUNT-86-100") && draft.endsWith("WALL-CLOCK-TEST。")
|
|
126
|
-
&& draft.length >= 200 && draft.length <= 900)
|
|
127
|
-
|| (draft.startsWith("这是 Chat Loop 的墙钟边界隔离测试")
|
|
128
|
-
&& draft.includes("MODE-WALL-10M") && draft.endsWith("WALL-CLOCK-TEST。")
|
|
129
|
-
&& draft.length >= 250 && draft.length <= 800))) return false;
|
|
130
|
-
input.focus();
|
|
131
|
-
const range = document.createRange();
|
|
132
|
-
range.selectNodeContents(input);
|
|
133
|
-
const selection = window.getSelection();
|
|
134
|
-
selection.removeAllRanges();
|
|
135
|
-
selection.addRange(range);
|
|
136
|
-
if (!document.execCommand("delete", false)) return false;
|
|
137
|
-
return !(input.innerText || input.textContent || '').trim() ? "CLEARED_TEST_DRAFT" : false;
|
|
138
|
-
}, args: [allowKnownTestDraftCleanup]});
|
|
116
|
+
return !!input?.getClientRects?.().length
|
|
117
|
+
&& !(input.innerText || input.textContent || "").trim();
|
|
118
|
+
}});
|
|
139
119
|
if (check?.result === true) return;
|
|
140
|
-
|
|
141
|
-
} catch { /* Only retry a read-only readiness probe, never the send. */ }
|
|
120
|
+
} catch { /* Retry only the read-only readiness probe. */ }
|
|
142
121
|
}
|
|
143
122
|
await delay(450);
|
|
144
123
|
}
|
|
@@ -242,6 +221,12 @@ async function run() {
|
|
|
242
221
|
}
|
|
243
222
|
const request = {tabId, token};
|
|
244
223
|
const permit = await chrome.runtime.sendMessage({type: "CHAT_LOOP_ACTION_TAKE_V1", ...request});
|
|
224
|
+
if (permit?.status === "DENIED" && permit.code === "PENDING_CONFIRMATION_DOM") {
|
|
225
|
+
// A choice appeared after timed Handoff was reserved. Worker retains
|
|
226
|
+
// the same Owner and no new Chat was created; close this stale Action.
|
|
227
|
+
await chrome.tabs.remove(own.id);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
245
230
|
if (permit?.status !== "OK" || permit.action !== "HANDOFF"
|
|
246
231
|
|| permit.target?.tabId !== request.tabId
|
|
247
232
|
|| (permit.handoffMode === "EXPLICIT" && typeof permit.text !== "string")
|
|
@@ -264,10 +249,6 @@ async function run() {
|
|
|
264
249
|
// Opening a new Chat is itself a side effect; never create another on failure.
|
|
265
250
|
newTab = await chrome.tabs.create({url: "https://chatgpt.com/", active: true,
|
|
266
251
|
windowId: source.windowId, openerTabId: own.id});
|
|
267
|
-
const registry = (await chrome.storage.local.get("chat-loop.acceptance.owned.v1"))[
|
|
268
|
-
"chat-loop.acceptance.owned.v1"];
|
|
269
|
-
const dedicatedTest = Array.isArray(registry)
|
|
270
|
-
&& registry.some(item => item.id === request.tabId);
|
|
271
252
|
// Chrome may initially report about:blank while the requested home URL loads.
|
|
272
253
|
let homeUrlReady=false;
|
|
273
254
|
for(let i=0;i<40;i++){
|
|
@@ -279,7 +260,7 @@ async function run() {
|
|
|
279
260
|
const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
|
|
280
261
|
action:'handoff',stage:'register',tabId:newTab.id});
|
|
281
262
|
if(registered?.status!=='OK')throw Error(registered?.code||'RESOURCE_REGISTER_UNVERIFIED');
|
|
282
|
-
await waitForNewChat(newTab.id
|
|
263
|
+
await waitForNewChat(newTab.id);
|
|
283
264
|
// The observer must exist before the first user click on the new home page.
|
|
284
265
|
// A successful send without an observer cannot be automatically continued.
|
|
285
266
|
let observed;
|
|
@@ -306,9 +287,8 @@ async function run() {
|
|
|
306
287
|
+ permit.pendingPlan.nextPrompt
|
|
307
288
|
+ "\n【边界】这只是上一轮模型提出的计划,不代表用户新增批准。新 Chat 必须先核实任务状态、项目规则及已发生的副作用,不能盲目重复。"
|
|
308
289
|
: "";
|
|
309
|
-
result = await sendHandoffOnce(newTab.id,
|
|
310
|
-
|
|
311
|
-
: message + notice + checkpoint + (permit.modelTurnNote || ""));
|
|
290
|
+
result = await sendHandoffOnce(newTab.id,
|
|
291
|
+
message + notice + checkpoint + (permit.modelTurnNote || ""));
|
|
312
292
|
} catch (error) {result = {status: "UNVERIFIED", reason: error.message || "HANDOFF_ERROR"};}
|
|
313
293
|
const committed = await chrome.runtime.sendMessage({type: "CHAT_LOOP_ACTION_RESULT_V1", ...request,
|
|
314
294
|
result: result.status, reason: result.reason,
|
|
@@ -128,7 +128,42 @@ async function run(){
|
|
|
128
128
|
taken=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_TAKE_V1',
|
|
129
129
|
requestId:id,token:prepared.token});
|
|
130
130
|
if(taken?.status!=='OK'||taken.sessionId!==prepared.sessionId
|
|
131
|
-
||
|
|
131
|
+
||(taken.mode==='adopt'
|
|
132
|
+
? !Number.isSafeInteger(taken.tabId)||!/^\/c\/[0-9a-f-]{12,}$/i.test(taken.page||'')
|
|
133
|
+
&& !/^\/g\/[^/]+\/c\/[0-9a-f-]{12,}$/i.test(taken.page||'')
|
|
134
|
+
||typeof taken.userKey!=='string'
|
|
135
|
+
: typeof taken.prompt!=='string'))
|
|
136
|
+
throw Error(taken?.code||'START_TAKE_DENIED');
|
|
137
|
+
if(taken.mode==='adopt'){
|
|
138
|
+
const existing=await chrome.tabs.get(taken.tabId).catch(()=>null);
|
|
139
|
+
if(!existing || new URL(existing.url).pathname!==taken.page)
|
|
140
|
+
throw Error('ADOPTION_TAB_UNVERIFIED');
|
|
141
|
+
await observerReady(existing.id);
|
|
142
|
+
const evidence=await chrome.tabs.sendMessage(existing.id,
|
|
143
|
+
{type:'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
|
|
144
|
+
...(taken.explicitChatId
|
|
145
|
+
?{explicitChatId:taken.explicitChatId}:{})}).catch(()=>null);
|
|
146
|
+
if(evidence?.status!=='VERIFIED'||evidence.page!==taken.page
|
|
147
|
+
||evidence.userKey!==taken.userKey)
|
|
148
|
+
throw Error('ADOPTION_APPROVAL_CHANGED');
|
|
149
|
+
const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
|
|
150
|
+
action:'start',stage:'adopt',tabId:existing.id});
|
|
151
|
+
if(registered?.status!=='OK')throw Error(registered?.code||'ADOPTION_RESOURCE_UNVERIFIED');
|
|
152
|
+
// No tabs.create, no composer input, no send-button click in this branch.
|
|
153
|
+
committed=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
|
|
154
|
+
requestId:id,token:prepared.token,result:'ADOPTED_CONFIRMED',
|
|
155
|
+
newTabId:existing.id,newPage:taken.page,newUserKey:taken.userKey});
|
|
156
|
+
if(committed?.status!=='OK')throw Error(committed?.code||'ADOPTION_COMMIT_UNVERIFIED');
|
|
157
|
+
await chrome.tabs.sendMessage(existing.id,{type:'CHAT_LOOP_TURN_RESUME_V1',
|
|
158
|
+
page:taken.page,userKey:taken.userKey,
|
|
159
|
+
assistantKey:taken.priorAssistantKey||null,startedAt:Date.now()}).catch(()=>null);
|
|
160
|
+
const stored=await chrome.runtime.sendNativeMessage(host,{op:'complete',
|
|
161
|
+
id,nonce:proof.nonce,action:'start',status:'OK',payload:JSON.stringify(committed)});
|
|
162
|
+
if(stored?.status!=='SAVED')throw Error(stored?.code||'ADOPTION_RECEIPT_UNVERIFIED');
|
|
163
|
+
show('SUCCESS','已接管完成 R/P 确认的原 Chat;没有新建会话或重新发送消息。');
|
|
164
|
+
await chrome.tabs.remove(own.id);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
132
167
|
const quota=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
|
|
133
168
|
action:'start',stage:'preflight'});
|
|
134
169
|
if(quota?.status!=='OK')throw Error(quota?.code||'RESOURCE_QUOTA_UNVERIFIED');
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
// TEXT Action:
|
|
2
|
-
(
|
|
3
|
-
const {show, fail, findTarget, readChat, copyText, done, requireOwnTab,
|
|
4
|
-
machineBinding, machineTarget, machineResult, machineFailure}
|
|
5
|
-
= globalThis.ChatLoopActionCommonV1;
|
|
6
|
-
let machine;
|
|
7
|
-
async function run() {
|
|
8
|
-
machine = await machineBinding("chat_text");
|
|
9
|
-
const own = requireOwnTab(await chrome.tabs.getCurrent());
|
|
10
|
-
const target = machine ? await machineTarget(machine) : await findTarget(own);
|
|
11
|
-
show("RUNNING", "text → ChatGPT tab " + target.id);
|
|
12
|
-
const value = await readChat(target, "text");
|
|
13
|
-
if (!value.length) throw Error("EMPTY_CONTENT");
|
|
14
|
-
if(machine) await machineResult(machine,value);
|
|
15
|
-
else copyText(value);
|
|
16
|
-
// Let Chrome publish selections to macOS pasteboard before closing.
|
|
17
|
-
if(!machine) await new Promise(resolve => setTimeout(resolve, 250));
|
|
18
|
-
await done(own, "text", target);
|
|
19
|
-
}
|
|
20
|
-
run().catch(async error => {
|
|
21
|
-
await machineFailure("chat_text",error);
|
|
22
|
-
fail(error.message || "UNEXPECTED_ERROR",
|
|
23
|
-
"操作未完成;动作页已保留,未对其他 ChatGPT 标签页进行操作。");
|
|
24
|
-
});
|
|
25
|
-
})();
|
|
1
|
+
// TEXT Action: independent entrypoint; shared verified read path.
|
|
2
|
+
void globalThis.ChatLoopActionCommonV1.runReadAction('text',250);
|