@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,287 +0,0 @@
1
- // Dedicated first-Turn Action. Only this page creates and sends the initial Web Chat.
2
- // All subsequent turns are owned by the existing Observer / Continue / Handoff flow.
3
- const info=document.getElementById('details'),label=document.getElementById('status');
4
- const pause=ms=>new Promise(resolve=>setTimeout(resolve,ms));
5
- // Timeout only read-only Chrome probes. Never race/retry a composer write or click.
6
- const boundedRead=(call,ms)=>Promise.race([
7
- Promise.resolve().then(call).catch(()=>null),
8
- pause(Math.max(1,ms)).then(()=>null)
9
- ]);
10
- const show=(s,d)=>{label.textContent=s;info.textContent=d;document.body.dataset.result=s==='SUCCESS'?'success':'error';};
11
- const host='com.tomflow.chatloop.extension';
12
- async function waitForHomeUrl(id){
13
- const deadline=Date.now()+12_000;
14
- for(let i=0;i<40 && Date.now()<deadline;i++){
15
- const tab=await boundedRead(()=>chrome.tabs.get(id),
16
- Math.min(1200,deadline-Date.now()));
17
- if(tab?.url==='https://chatgpt.com/')return;
18
- await pause(Math.min(250,Math.max(1,deadline-Date.now())));
19
- }
20
- throw Error('START_HOME_URL_UNVERIFIED');
21
- }
22
- async function newChatReady(id){
23
- // Preserve 35s+ cold hydration but return well before the Worker watchdog.
24
- // A never-settling Chrome read must not leave Start PENDING indefinitely.
25
- const deadline=Date.now()+90_000;
26
- for(let i=0;i<200 && Date.now()<deadline;i++){
27
- const tab=await boundedRead(()=>chrome.tabs.get(id),
28
- Math.min(1500,deadline-Date.now()));
29
- if(tab?.url==='https://chatgpt.com/'){
30
- const result=await boundedRead(()=>chrome.scripting.executeScript({target:{tabId:id},func:()=>{
31
- const visible=e=>Boolean(e?.getClientRects?.().length);
32
- const mains=[...document.querySelectorAll('main')].filter(visible);
33
- const editor=document.querySelector('[contenteditable="true"][data-composer-markdown]')
34
- ||document.querySelector('#prompt-textarea[contenteditable="true"]');
35
- if(location.origin!=='https://chatgpt.com'||location.pathname!=='/'
36
- ||mains.length!==1||!visible(editor)
37
- ||mains[0].querySelector('[data-chatgpt-search-message-ids],[data-message-author-role]'))
38
- return false;
39
- // A visible account-switch notice invalidates the first-send
40
- // environment. Catch it before any editor mutation or send click.
41
- const switched=/你的账户已切换[。.!!\s]*请重新发送消息|your account (?:has been |was )?switched[.!\s]*please (?:re-?send|send again) (?:your )?message/i;
42
- if(switched.test(mains[0].innerText||mains[0].textContent||''))
43
- return 'START_ACCOUNT_SWITCH_VISIBLE';
44
- return (editor.innerText||editor.textContent||'').trim()
45
- ?'START_COMPOSER_NOT_EMPTY':true;
46
- }}),Math.min(1500,deadline-Date.now()));
47
- if(result?.[0]?.result==='START_COMPOSER_NOT_EMPTY')
48
- throw Error('START_COMPOSER_NOT_EMPTY');
49
- if(result?.[0]?.result==='START_ACCOUNT_SWITCH_VISIBLE')
50
- throw Error('START_ACCOUNT_SWITCH_VISIBLE');
51
- if(result?.[0]?.result===true)return;
52
- }
53
- await pause(Math.min(420,Math.max(1,deadline-Date.now())));
54
- }
55
- throw Error('NEW_CHAT_NOT_READY');
56
- }
57
- async function observerReady(id){
58
- let proof=await boundedRead(()=>chrome.tabs.sendMessage(id,
59
- {type:'CHAT_LOOP_TURN_OBSERVE_V1'}),3000);
60
- if(proof?.contract!=='chat-loop.turn-observer.v1'){
61
- const injected=await boundedRead(()=>chrome.scripting.executeScript({
62
- target:{tabId:id},files:['content.js', 'loop/observer-inspect.js', 'loop/observer-poll.js', 'loop/observer-recovery.js', 'loop/observer-approval.js', 'loop/observer.js']}),3000);
63
- if(!injected)throw Error('FIRST_TURN_OBSERVER_UNAVAILABLE');
64
- proof=await boundedRead(()=>chrome.tabs.sendMessage(id,
65
- {type:'CHAT_LOOP_TURN_OBSERVE_V1'}),3000);
66
- }
67
- if(proof?.contract!=='chat-loop.turn-observer.v1')
68
- throw Error('FIRST_TURN_OBSERVER_UNAVAILABLE');
69
- }
70
- async function sendFirst(id,text){
71
- const [clicked]=await chrome.scripting.executeScript({target:{tabId:id},
72
- func:async instruction=>{
73
- try{
74
- const visible=e=>Boolean(e?.getClientRects?.().length);
75
- if(location.origin!=='https://chatgpt.com'||location.pathname!=='/')throw Error('START_PAGE_CHANGED');
76
- const mains=[...document.querySelectorAll('main')].filter(visible);
77
- const editor=document.querySelector('[contenteditable="true"][data-composer-markdown]')
78
- ||document.querySelector('#prompt-textarea[contenteditable="true"]');
79
- if(mains.length!==1||!visible(editor)||!(editor.isContentEditable)||!document.contains(editor)
80
- ||(editor.innerText||editor.textContent||'').trim()
81
- ||mains[0].querySelector('[data-chatgpt-search-message-ids],[data-message-author-role]'))
82
- throw Error('START_COMPOSER_UNVERIFIED');
83
- // Recheck immediately before changing the composer; account
84
- // identity may have switched after the initial readiness probe.
85
- const switched=/你的账户已切换[。.!!\s]*请重新发送消息|your account (?:has been |was )?switched[.!\s]*please (?:re-?send|send again) (?:your )?message/i;
86
- if(switched.test(mains[0].innerText||mains[0].textContent||''))
87
- throw Error('START_ACCOUNT_SWITCH_VISIBLE');
88
- const canonical=v=>String(v||'').replace(/\s+/g,'');
89
- editor.focus();
90
- if(!document.execCommand('insertText',false,instruction))throw Error('START_INPUT_REJECTED');
91
- let verified=false;
92
- for(let i=0;i<25;i++){
93
- if(location.pathname!=='/')throw Error('START_PAGE_CHANGED_DURING_INPUT');
94
- if(canonical(editor.innerText)===canonical(instruction)
95
- ||canonical(editor.textContent)===canonical(instruction)){verified=true;break;}
96
- await new Promise(r=>setTimeout(r,120));
97
- }
98
- if(!verified)throw Error('START_INPUT_UNVERIFIED');
99
- let send;
100
- for(let i=0;i<16;i++){
101
- send=document.querySelector('button[data-testid="send-button"]')
102
- ||document.querySelector('button[data-testid="composer-send-button"]')
103
- ||document.querySelector('button[type="submit"][aria-label="发送"]')
104
- ||document.querySelector('button[aria-label="Send message"]');
105
- if(send&&!send.disabled&&visible(send))break;
106
- await new Promise(r=>setTimeout(r,120));
107
- }
108
- if(!send||send.disabled||!visible(send))throw Error('START_SEND_BUTTON_UNAVAILABLE');
109
- if(location.pathname!=='/'||(canonical(editor.innerText)!==canonical(instruction)
110
- &&canonical(editor.textContent)!==canonical(instruction)))
111
- throw Error('START_INPUT_CHANGED');
112
- send.click(); // Once only. Worker persisted PENDING before this point.
113
- return {clickedOnce:true};
114
- }catch(e){return {clickedOnce:false,reason:e.message||'START_INPUT_UNKNOWN'};}
115
- },args:[text]});
116
- if(clicked?.result?.clickedOnce!==true)
117
- throw Error(clicked?.result?.reason||'START_CLICK_UNVERIFIED');
118
- // Once clicked: ONLY bounded read-only receipt probes. A provisional
119
- // local-chatgpt URL can settle late; never retry typing or clicking.
120
- // Keep even the worst-case read budget below the 330s Worker watchdog,
121
- // including the preceding 90s cold-page readiness window.
122
- const deadline=Date.now()+120_000;
123
- // E15 must verify a single, stable server-backed first user Turn.
124
- // One transient bubble is not proof that ChatGPT emitted exactly one Turn.
125
- let candidatePage=null,candidateUserKey=null,stableProbes=0;
126
- for(let i=0;i<200&&Date.now()<deadline;i++){
127
- const tab=await boundedRead(()=>chrome.tabs.get(id),
128
- Math.min(1200,Math.max(1,deadline-Date.now())));
129
- const page=tab?.url&&new URL(tab.url).pathname;
130
- if(/^\/c\/[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(page||'')){
131
- const rows=await boundedRead(()=>chrome.scripting.executeScript({target:{tabId:id},func:expected=>{
132
- const visible=e=>Boolean(e?.getClientRects?.().length);
133
- const mains=[...document.querySelectorAll('main')].filter(visible);
134
- if(mains.length!==1)return null;
135
- const modern=[...mains[0].querySelectorAll('[data-chatgpt-search-unit-key][data-chatgpt-search-message-ids]')];
136
- const rows=modern.length?modern:[...mains[0].querySelectorAll('[data-message-author-role]')];
137
- const role=n=>n.getAttribute('data-message-author-role')
138
- ||n.getAttribute('data-chatgpt-search-unit-key')?.split(':').at(-1);
139
- const users=rows.filter(n=>role(n)==='user');
140
- const user=users.at(-1);
141
- const idOf=node=>node?.getAttribute('data-message-id')
142
- ||node?.getAttribute('data-chatgpt-search-message-ids')?.trim().split(/\s+/)[0];
143
- const ids=users.map(idOf);
144
- const id=idOf(user);
145
- const bubble=user?.querySelector('[data-search-result-target]')
146
- ||user?.querySelector('[data-user-message-bubble="true"]')||user;
147
- const canonical=v=>String(v||'').replace(/\s+/g,'');
148
- return {observedPage:location.pathname,userMessageCount:users.length,
149
- distinctUserIds:new Set(ids).size,
150
- userKey:id&&canonical(bubble?.innerText||bubble?.textContent)===canonical(expected)
151
- ?'user:'+id:null};
152
- },args:[text]}),Math.min(1200,Math.max(1,deadline-Date.now())));
153
- const evidence=rows?.[0]?.result;
154
- if(evidence?.observedPage&&evidence.observedPage!==page)
155
- throw Error('FIRST_SEND_PAGE_DRIFT_UNVERIFIED');
156
- if(evidence?.userMessageCount>1||evidence?.distinctUserIds>1)
157
- throw Error('FIRST_SEND_DUPLICATE_UNVERIFIED');
158
- const exactOne=evidence?.userMessageCount===1
159
- &&evidence.distinctUserIds===1&&typeof evidence.userKey==='string';
160
- if(exactOne){
161
- if(candidatePage===page&&candidateUserKey===evidence.userKey)stableProbes++;
162
- else {candidatePage=page;candidateUserKey=evidence.userKey;stableProbes=1;}
163
- // Four independent bounded DOM probes (~1.2s in Chrome). Never
164
- // claim SENT_CONFIRMED from the first transient matching bubble.
165
- if(stableProbes>=4)return {status:'SENT_CONFIRMED',
166
- newUserKey:candidateUserKey,newPage:page,newTabId:id};
167
- }else if(evidence){candidatePage=null;candidateUserKey=null;stableProbes=0;}
168
- }
169
- await pause(Math.min(420,Math.max(1,deadline-Date.now())));
170
- }
171
- throw Error('FIRST_SEND_RECEIPT_UNKNOWN');
172
- }
173
- async function run(){
174
- const own=await chrome.tabs.getCurrent();
175
- const q=new URLSearchParams(location.search),id=q.get('requestId');
176
- if(!own?.id||own.url!==location.href||[...q.keys()].length!==1
177
- ||!/^[a-f0-9]{32}$/.test(id||''))throw Error('START_ACTION_SOURCE_INVALID');
178
- const proof=await chrome.runtime.sendNativeMessage(host,{op:'acquire',id,action:'start'});
179
- if(proof?.status!=='OK'||proof.action!=='start'||proof.id!==id
180
- ||typeof proof.nonce!=='string')throw Error(proof?.code||'START_NATIVE_INVALID');
181
- let prepared,taken,newTab,committed;
182
- try{
183
- prepared=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_PREPARE_V1',
184
- requestId:id,...(proof.traceParent?{traceParent:proof.traceParent}:{})});
185
- if(prepared?.status!=='PREPARED')throw Error(prepared?.code||'START_PREPARE_DENIED');
186
- taken=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_TAKE_V1',
187
- requestId:id,token:prepared.token,
188
- ...(proof.traceParent?{traceParent:proof.traceParent}:{})});
189
- if(taken?.status!=='OK'||taken.sessionId!==prepared.sessionId
190
- ||(taken.mode==='adopt'
191
- ? !Number.isSafeInteger(taken.tabId)||!/^\/c\/[0-9a-f-]{12,}$/i.test(taken.page||'')
192
- && !/^\/g\/[^/]+\/c\/[0-9a-f-]{12,}$/i.test(taken.page||'')
193
- ||typeof taken.userKey!=='string'
194
- : typeof taken.prompt!=='string'))
195
- throw Error(taken?.code||'START_TAKE_DENIED');
196
- if(taken.mode==='adopt'){
197
- const existing=await chrome.tabs.get(taken.tabId).catch(()=>null);
198
- if(!existing || new URL(existing.url).pathname!==taken.page)
199
- throw Error('ADOPTION_TAB_UNVERIFIED');
200
- await observerReady(existing.id);
201
- const repair=taken.purpose==='REPAIR_SAME_SCOPE';
202
- const evidence=await chrome.tabs.sendMessage(existing.id,
203
- {type:repair?'CHAT_LOOP_REPAIR_EVIDENCE_V1':'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
204
- ...(taken.explicitChatId
205
- ?{explicitChatId:taken.explicitChatId}:{}),
206
- ...(taken.expectedTaskId
207
- ?{expectedTaskId:taken.expectedTaskId}:{})}).catch(()=>null);
208
- if(evidence?.contract!=='chat-loop.turn-observer.v1'
209
- ||evidence.status!=='VERIFIED'||evidence.page!==taken.page
210
- ||evidence.userKey!==taken.userKey
211
- ||(repair
212
- ? evidence.userText!==taken.repairUserText
213
- ||evidence.priorDoneAssistantKey!==taken.priorDoneAssistantKey
214
- : evidence.rVersion!==taken.rVersion
215
- ||evidence.pVersion!==taken.pVersion
216
- ||(evidence.priorAssistantKey||null)!==(taken.priorAssistantKey||null)
217
- ||(evidence.postApprovalAssistantKey||null)!==(taken.postApprovalAssistantKey||null)))
218
- throw Error('ADOPTION_APPROVAL_CHANGED');
219
- const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
220
- action:'start',stage:'adopt',tabId:existing.id});
221
- if(registered?.status!=='OK')throw Error(registered?.code||'ADOPTION_RESOURCE_UNVERIFIED');
222
- // No tabs.create, no composer input, no send-button click in this branch.
223
- committed=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
224
- requestId:id,token:prepared.token,result:'ADOPTED_CONFIRMED',
225
- ...(proof.traceParent?{traceParent:proof.traceParent}:{}),
226
- newTabId:existing.id,newPage:taken.page,newUserKey:taken.userKey});
227
- if(committed?.status!=='OK')throw Error(committed?.code||'ADOPTION_COMMIT_UNVERIFIED');
228
- await chrome.tabs.sendMessage(existing.id,{type:'CHAT_LOOP_TURN_RESUME_V1',
229
- page:taken.page,userKey:taken.userKey,
230
- assistantKey:taken.postApprovalAssistantKey||taken.priorAssistantKey||null,
231
- ...(taken.postApprovalAssistantKey?{baselineOnly:true}:{}),
232
- startedAt:Date.now()}).catch(()=>null);
233
- const stored=await chrome.runtime.sendNativeMessage(host,{op:'complete',
234
- id,nonce:proof.nonce,action:'start',status:'OK',payload:JSON.stringify(committed)});
235
- if(stored?.status!=='SAVED')throw Error(stored?.code||'ADOPTION_RECEIPT_UNVERIFIED');
236
- show('SUCCESS','已接管完成 R/P 确认的原 Chat;没有新建会话或重新发送消息。');
237
- await chrome.tabs.remove(own.id);
238
- return;
239
- }
240
- const quota=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
241
- action:'start',stage:'preflight'});
242
- if(quota?.status!=='OK')throw Error(quota?.code||'RESOURCE_QUOTA_UNVERIFIED');
243
- show('RUNNING','已独占会话,正在创建唯一网页 Chat 并确认首轮发送。');
244
- newTab=await chrome.tabs.create({url:'https://chatgpt.com/',active:true,
245
- windowId:own.windowId,openerTabId:own.id});
246
- await waitForHomeUrl(newTab.id);
247
- const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
248
- action:'start',stage:'register',tabId:newTab.id});
249
- if(registered?.status!=='OK')throw Error(registered?.code||'RESOURCE_REGISTER_UNVERIFIED');
250
- await newChatReady(newTab.id);
251
- await observerReady(newTab.id);
252
- const receipt=await sendFirst(newTab.id,taken.prompt);
253
- committed=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
254
- requestId:id,token:prepared.token,...receipt,result:receipt.status,
255
- ...(proof.traceParent?{traceParent:proof.traceParent}:{})});
256
- if(committed?.status!=='OK')throw Error(committed?.code||'START_COMMIT_UNVERIFIED');
257
- const stored=await chrome.runtime.sendNativeMessage(host,{op:'complete',
258
- id,nonce:proof.nonce,action:'start',status:'OK',payload:JSON.stringify(committed)});
259
- if(stored?.status!=='SAVED')throw Error(stored?.code||'START_RECEIPT_NOT_STORED');
260
- show('SUCCESS','唯一网页 Chat 已确认;执行由 Observer 和 Continue/Handoff 接管。');
261
- await chrome.tabs.remove(own.id);
262
- }catch(e){
263
- if(taken&&committed?.status!=='OK') {
264
- // This is diagnostics only; it does NOT authorize a retry or prove a
265
- // message was never sent. Keep the existing fail-closed Owner semantics.
266
- const failureCode=['START_HOME_URL_UNVERIFIED','NEW_CHAT_NOT_READY',
267
- 'START_COMPOSER_NOT_EMPTY','START_ACCOUNT_SWITCH_VISIBLE',
268
- 'FIRST_TURN_OBSERVER_UNAVAILABLE','START_SEND_BUTTON_UNAVAILABLE','START_INPUT_CHANGED',
269
- 'START_INPUT_UNVERIFIED','START_INPUT_REJECTED',
270
- 'START_CLICK_UNVERIFIED','FIRST_SEND_RECEIPT_UNKNOWN',
271
- 'FIRST_SEND_DUPLICATE_UNVERIFIED','FIRST_SEND_PAGE_DRIFT_UNVERIFIED']
272
- .includes(e.message) ? e.message : null;
273
- await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
274
- requestId:id,token:prepared.token,result:'UNVERIFIED',newTabId:newTab?.id,
275
- ...(proof.traceParent?{traceParent:proof.traceParent}:{}),
276
- ...(failureCode?{failureCode}:{})}).catch(()=>{});
277
- }
278
- const failed=await chrome.runtime.sendNativeMessage(host,{op:'complete',id,nonce:proof.nonce,
279
- action:'start',status:'FAILED',code:String(e.message||'START_UNVERIFIED').slice(0,100)}).catch(()=>null);
280
- // Only the Action page closes after its durable FAILED receipt; the
281
- // possibly-sent Chat and any unverified draft remain untouched.
282
- if(failed?.status==='SAVED' && failed.id===id)
283
- await chrome.tabs.remove(own.id).catch(()=>{});
284
- throw e; // Never auto-retry a possibly clicked first user Turn.
285
- }
286
- }
287
- void run().catch(e=>show('BLOCKED',e.message||'START_UNVERIFIED'));
@@ -1,23 +0,0 @@
1
- // Read-only machine Status. Does not create a Chat or modify the browser Owner.
2
- const host='com.tomflow.chatloop.extension';
3
- async function run(){
4
- const own=await chrome.tabs.getCurrent(),q=new URLSearchParams(location.search);
5
- const id=q.get('requestId');
6
- if(!own?.id||own.url!==location.href||[...q.keys()].length!==1
7
- ||!/^[a-f0-9]{32}$/.test(id||''))throw Error('INVALID_STATUS_ACTION');
8
- const proof=await chrome.runtime.sendNativeMessage(host,{op:'acquire',id,action:'status'});
9
- if(proof?.status!=='OK'||proof.action!=='status'||proof.id!==id)
10
- throw Error(proof?.code||'STATUS_NATIVE_INVALID');
11
- const state=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_STATUS_V1',
12
- requestId:id,...(proof.traceParent?{traceParent:proof.traceParent}:{})});
13
- const receipt=await chrome.runtime.sendNativeMessage(host,{op:'complete',id,
14
- nonce:proof.nonce,action:'status',status:'OK',payload:JSON.stringify(state)});
15
- if(receipt?.status!=='SAVED')throw Error(receipt?.code||'STATUS_NOT_STORED');
16
- document.getElementById('status').textContent='SUCCESS';
17
- document.getElementById('details').textContent='只读状态已返回本机请求;未修改执行 Chat。';
18
- await chrome.tabs.remove(own.id);
19
- }
20
- void run().catch(e=>{
21
- document.getElementById('status').textContent='UNVERIFIED';
22
- document.getElementById('details').textContent=e.message||'STATUS_UNKNOWN';
23
- });
@@ -1,2 +0,0 @@
1
- // TEXT Action: independent entrypoint; shared verified read path.
2
- void globalThis.ChatLoopActionCommonV1.runReadAction('text',250);
@@ -1,16 +0,0 @@
1
- // Chrome MV3 classic service Worker. Shared lexical context; exact order
2
- // preserves the original single-Worker Owner and serialized Action lifecycle.
3
- importScripts("loop/index.js");
4
- importScripts("worker/bootstrap.js");
5
- importScripts("worker/admission.js");
6
- importScripts("worker/adopt-prepare.js");
7
- importScripts("worker/adopt-result.js");
8
- importScripts("worker/readiness.js");
9
- importScripts("worker/turn-failure.js");
10
- importScripts("worker/turn-finished.js");
11
- importScripts("worker/adopt-recovery.js");
12
- importScripts("worker/manual.js");
13
- importScripts("worker/action-take.js");
14
- importScripts("worker/action-result.js");
15
- importScripts("worker/scheduler.js");
16
- importScripts("worker/router.js");
@@ -1,5 +0,0 @@
1
- <!doctype html>
2
- <html lang="zh-CN"><head><meta charset="utf-8"><title>Chat Loop · Clean</title>
3
- <style>body{font:14px system-ui;padding:22px;color:#242424}#status{font-weight:bold}#details{color:#666}</style></head>
4
- <body><h1>Clean · 清理输入框</h1><p id="status">VERIFYING</p><p id="details">正在核实目标 Chat,不发送消息。</p>
5
- <script src="actions/clean.js"></script></body></html>
@@ -1,40 +0,0 @@
1
- // Read-only ChatGPT page agent. Reinjection after extension reload is idempotent.
2
- (() => {
3
- if (globalThis.__CHAT_LOOP_EYE_V1__) return;
4
- globalThis.__CHAT_LOOP_EYE_V1__ = true;
5
- const CONTRACT = "chat-loop.web-environment.v1";
6
- const READ_CONTRACT = "chat-loop.eye.v1";
7
- const onChatGPT = () => location.protocol === "https:" && location.hostname === "chatgpt.com";
8
-
9
- function inspectChatPage() {
10
- const brands = navigator.userAgentData?.brands;
11
- const chromeBrowser = Array.isArray(brands)
12
- && brands.some(entry => entry?.brand === "Google Chrome");
13
- return {
14
- contract: CONTRACT,
15
- status: !onChatGPT() ? "UNSUPPORTED_PAGE" : !chromeBrowser
16
- ? "BROWSER_UNVERIFIED" : "WEB_READY",
17
- pageOrigin: onChatGPT() ? "https://chatgpt.com" : null,
18
- browser: chromeBrowser ? "GOOGLE_CHROME" : "UNVERIFIED",
19
- extensionVersion: chrome.runtime.getManifest().version
20
- };
21
- }
22
-
23
- chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
24
- if (message?.type === "CHAT_LOOP_WEB_CHECK_V1") {
25
- sendResponse(inspectChatPage());
26
- return false;
27
- }
28
- if (message?.type !== "CHAT_LOOP_EYE_READ_V1") return false;
29
- if (!onChatGPT() || !["dom", "text"].includes(message.mode)) {
30
- sendResponse({contract: READ_CONTRACT, status: "UNSUPPORTED"});
31
- return false;
32
- }
33
- const value = message.mode === "dom"
34
- ? document.documentElement.outerHTML
35
- : (document.querySelector("main")?.innerText ?? document.body?.innerText ?? "");
36
- sendResponse({contract: READ_CONTRACT, status: "OK",
37
- mode: message.mode, url: location.href, value, length: value.length});
38
- return false;
39
- });
40
- })();
@@ -1,9 +0,0 @@
1
- <!doctype html>
2
- <html lang="zh-CN"><head><meta charset="utf-8"><title>Chat Loop Extension · Continue Action</title>
3
- <style>body{font:15px system-ui,sans-serif;padding:24px;max-width:620px;color:#222}#status{font-weight:bold}#details{white-space:pre-wrap;overflow-wrap:anywhere}body[data-result="error"] #status{color:#b00020}</style>
4
- </head><body>
5
- <h1>Chat Loop · Continue</h1>
6
- <p id="status" role="status">STARTING</p>
7
- <p id="details">仅执行一次已授权的固定续接。失败时保留本页,不重新发送。</p>
8
- <script src="actions/continue.js"></script>
9
- </body></html>
@@ -1,17 +0,0 @@
1
- <!doctype html>
2
- <html lang="zh-CN">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Chat Loop Extension · DOM</title>
6
- <style>body{font:15px system-ui,sans-serif;padding:24px;max-width:620px;color:#222}
7
- #status{font-weight:700}#details{white-space:pre-wrap;overflow-wrap:anywhere;color:#555}
8
- body[data-result="error"] #status{color:#b00020}</style>
9
- </head>
10
- <body>
11
- <h1>Chat Loop · DOM</h1>
12
- <p id="status" role="status">STARTING</p>
13
- <p id="details">正在执行,成功后关闭此页面;失败则保留错误以供诊断。</p>
14
- <script src="actions/common.js"></script>
15
- <script src="actions/dom.js"></script>
16
- </body>
17
- </html>
@@ -1,9 +0,0 @@
1
- <!doctype html>
2
- <html lang="zh-CN"><head><meta charset="utf-8"><title>Chat Loop · Handoff Action</title>
3
- <style>body{font:15px system-ui,sans-serif;padding:24px;max-width:620px}#status{font-weight:700}#details{white-space:pre-wrap;overflow-wrap:anywhere}body[data-result="error"] #status{color:#b00020}</style>
4
- </head><body>
5
- <h1>Chat Loop · Handoff</h1>
6
- <p id="status" role="status">STARTING</p>
7
- <p id="details">仅在旧 Chat 已完成并给出明确交接包时,创建一次新 Chat 并发送一次。未知结果禁止重试。</p>
8
- <script src="actions/handoff.js"></script>
9
- </body></html>
@@ -1,2 +0,0 @@
1
- // GENERATED by scripts/build-actions.mjs — do not edit.
2
- globalThis.ChatLoopEyeCatalogV1=Object.freeze({"chat_text":{"page":"text.html","kind":"eye-read","readMode":"text"},"chat_dom":{"page":"dom.html","kind":"eye-read","readMode":"dom"},"chat_screenshot":{"page":"screenshot.html","kind":"eye-screenshot","readMode":null},"reload":{"page":"reload.html","kind":"eye-reload","readMode":null}});