@tomflow/chatloop-tools 0.9.17 → 0.9.18
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/package.json +3 -11
- package/providers/form.mjs +4 -2
- package/ui/form/review-app.js +122 -71
- package/ui/form/review.html +1 -814
- package/node_modules/@tomflow/chatloop-context/README.md +0 -240
- package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +0 -48
- package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +0 -151
- package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +0 -376
- package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +0 -266
- package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +0 -134
- package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +0 -82
- package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +0 -349
- package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +0 -72
- package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +0 -73
- package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +0 -507
- package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +0 -11
- package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +0 -182
- package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +0 -277
- package/node_modules/@tomflow/chatloop-context/index.mjs +0 -233
- package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +0 -86
- package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +0 -24
- package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +0 -1989
- package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +0 -67
- package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +0 -280
- package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -298
- package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -280
- package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +0 -115
- package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +0 -51
- package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +0 -55
- package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +0 -262
- package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +0 -246
- package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +0 -147
- package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +0 -343
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +0 -391
- package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +0 -166
- package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +0 -13
- package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +0 -111
- package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +0 -107
- package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +0 -117
- package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +0 -20
- package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +0 -312
- package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +0 -153
- package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +0 -19
- package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +0 -115
- package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +0 -86
- package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +0 -169
- package/node_modules/@tomflow/chatloop-context/package.json +0 -40
- package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +0 -114
- package/node_modules/@tomflow/chatloop-extension/README.md +0 -94
- package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +0 -11
- package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +0 -141
- package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +0 -109
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +0 -120
- package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +0 -180
- package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +0 -322
- package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +0 -378
- package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +0 -54
- package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +0 -9
- package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +0 -20
- package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +0 -69
- package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +0 -287
- package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +0 -23
- package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/background.js +0 -16
- package/node_modules/@tomflow/chatloop-extension/extension/clean.html +0 -5
- package/node_modules/@tomflow/chatloop-extension/extension/content.js +0 -40
- package/node_modules/@tomflow/chatloop-extension/extension/continue.html +0 -9
- package/node_modules/@tomflow/chatloop-extension/extension/dom.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +0 -9
- package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +0 -275
- package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +0 -76
- package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +0 -107
- package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +0 -36
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +0 -227
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +0 -144
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +0 -171
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +0 -109
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +0 -154
- package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +0 -254
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +0 -42
- package/node_modules/@tomflow/chatloop-extension/extension/popup.html +0 -25
- package/node_modules/@tomflow/chatloop-extension/extension/popup.js +0 -93
- package/node_modules/@tomflow/chatloop-extension/extension/reload.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/start.html +0 -6
- package/node_modules/@tomflow/chatloop-extension/extension/status.html +0 -6
- package/node_modules/@tomflow/chatloop-extension/extension/text.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +0 -136
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +0 -220
- package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +0 -122
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +0 -155
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +0 -185
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +0 -120
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +0 -172
- package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +0 -165
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +0 -244
- package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +0 -181
- package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +0 -147
- package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +0 -197
- package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +0 -200
- package/node_modules/@tomflow/chatloop-extension/index.mjs +0 -71
- package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +0 -18
- package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +0 -74
- package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +0 -208
- package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +0 -40
- package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +0 -45
- package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +0 -111
- package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +0 -67
- package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +0 -120
- package/node_modules/@tomflow/chatloop-extension/package.json +0 -38
- package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +0 -133
- package/node_modules/@tomflow/chatloop-trace/README.md +0 -105
- package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +0 -23
- package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +0 -22
- package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +0 -4
- package/node_modules/@tomflow/chatloop-trace/index.mjs +0 -59
- package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +0 -273
- package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +0 -265
- package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -205
- package/node_modules/@tomflow/chatloop-trace/package.json +0 -30
- package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +0 -68
- package/node_modules/ps-list/index.d.ts +0 -76
- package/node_modules/ps-list/index.js +0 -366
- package/node_modules/ps-list/license +0 -9
- package/node_modules/ps-list/package.json +0 -44
- package/node_modules/ps-list/readme.md +0 -56
- package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
- package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// Read-only ChatGPT Turn observation. No composer writes, clicks, or task decisions.
|
|
2
|
-
// Candidate DOM selectors must be verified against an authorized real ChatGPT tab.
|
|
3
|
-
(() => {
|
|
4
|
-
if (globalThis.__CHAT_LOOP_OBSERVER_V1__) return;
|
|
5
|
-
globalThis.__CHAT_LOOP_OBSERVER_V1__ = true;
|
|
6
|
-
const CONTRACT = "chat-loop.turn-observer.v1";
|
|
7
|
-
const STABLE_MS = 2200;
|
|
8
|
-
const POLL_MS = 60_000; // Temporary: check Turn status once per minute, independent of Handoff clock.
|
|
9
|
-
const session = {
|
|
10
|
-
path: "", baselineUser: null, baselineAssistant: null,
|
|
11
|
-
pendingUser: null, completedUser: null,
|
|
12
|
-
candidate: "", stableSince: 0, firstSendSeen: false, firstSendAt: 0,
|
|
13
|
-
sawHomepage: false, attaching: false, attachingFirstTurn: false,
|
|
14
|
-
priorUser: null, attachSignature: "", attachSince: 0,
|
|
15
|
-
emittedCount: 0, firstTurnAt: 0, reportedErrorUser: null
|
|
16
|
-
};
|
|
17
|
-
let state = {contract: CONTRACT, status: "UNKNOWN", reason: "INITIALIZING", eventCount: 0};
|
|
18
|
-
|
|
19
|
-
const conversationPath = () => {
|
|
20
|
-
if (location.protocol !== "https:" || location.hostname !== "chatgpt.com") return "";
|
|
21
|
-
const path = location.pathname.replace(/\/$/, "");
|
|
22
|
-
return /^\/(?:c\/[0-9a-f-]{12,}|g\/[^/]+\/c\/[0-9a-f-]{12,})$/i.test(path)
|
|
23
|
-
? path : "";
|
|
24
|
-
};
|
|
25
|
-
function visible(el) {
|
|
26
|
-
if (!el || !el.getClientRects?.().length) return false;
|
|
27
|
-
if (el.closest?.('[hidden],[aria-hidden="true"]')) return false;
|
|
28
|
-
const style = globalThis.getComputedStyle?.(el);
|
|
29
|
-
return style?.display !== "none" && style?.visibility !== "hidden";
|
|
30
|
-
}
|
|
31
|
-
function messageId(node, role) {
|
|
32
|
-
if (!node) return null;
|
|
33
|
-
const container = node.closest?.('[data-testid^="conversation-turn-"]');
|
|
34
|
-
const ids = node.getAttribute?.("data-chatgpt-search-message-ids") || "";
|
|
35
|
-
const id = node.getAttribute?.("data-message-id")
|
|
36
|
-
|| ids.trim().split(/\s+/)[0] || container?.getAttribute?.("data-testid");
|
|
37
|
-
return id ? role + ":" + id : null;
|
|
38
|
-
}
|
|
39
|
-
function fingerprint(text) {
|
|
40
|
-
let hash = 2166136261;
|
|
41
|
-
// Hash every UTF-16 code unit: for...of exposes whole Unicode code points
|
|
42
|
-
// and charCodeAt(0) would ignore the LOW surrogate of different emoji.
|
|
43
|
-
for (let i=0;i<text.length;i++) {
|
|
44
|
-
hash = Math.imul(hash ^ text.charCodeAt(i), 16777619);
|
|
45
|
-
}
|
|
46
|
-
return (hash >>> 0).toString(16) + ":" + text.length;
|
|
47
|
-
}
|
|
48
|
-
// Formal approval and repair are two independent evidence consumers, but
|
|
49
|
-
// both must read the ONE visible Chat, not merge hidden/virtualized mains.
|
|
50
|
-
// Keep this read-only snapshot separate from the Turn polling state machine.
|
|
51
|
-
const {activeEvidenceConversation,inspect}=
|
|
52
|
-
globalThis.ChatLoopObserverInspectV1({conversationPath,visible,messageId});
|
|
53
|
-
|
|
54
|
-
function emit(status, reason, snap, event = null) {
|
|
55
|
-
if (event) session.emittedCount += 1;
|
|
56
|
-
state = {contract: CONTRACT, status, reason, page: snap.path || null,
|
|
57
|
-
userKey: snap.userKey || null, assistantKey: snap.assistantKey || null,
|
|
58
|
-
retryAvailable: status === "BLOCKED" && snap.retryAvailable === true,
|
|
59
|
-
eventCount: session.emittedCount, observedAt: Date.now(),
|
|
60
|
-
pendingConfirmation: snap.pendingConfirmation === true,
|
|
61
|
-
priorAssistantKey: snap.priorAssistantKey || null,
|
|
62
|
-
priorAssistantUserKey:snap.priorAssistantUserKey || null,
|
|
63
|
-
directReplyAfterPriorAssistant:snap.directReplyAfterPriorAssistant===true};
|
|
64
|
-
if (event) {
|
|
65
|
-
document.dispatchEvent(new CustomEvent("CHAT_LOOP_TURN_FINISHED_V1", {
|
|
66
|
-
detail: {contract: CONTRACT, page: snap.path,
|
|
67
|
-
userKey: snap.userKey, assistantKey: snap.assistantKey}
|
|
68
|
-
}));
|
|
69
|
-
// Sensor -> extension scheduler: no composer writes or action decisions here.
|
|
70
|
-
// Only a freshly verified Turn can request autonomous scheduling.
|
|
71
|
-
if (typeof chrome.runtime.sendMessage === "function") {
|
|
72
|
-
void Promise.resolve(chrome.runtime.sendMessage({
|
|
73
|
-
type: "CHAT_LOOP_TURN_FINISHED_V1", page: snap.path,
|
|
74
|
-
userKey: snap.userKey, assistantKey: snap.assistantKey,
|
|
75
|
-
replyText: snap.text, startedAt: session.firstTurnAt || Date.now(),
|
|
76
|
-
pendingConfirmation: snap.pendingConfirmation === true,
|
|
77
|
-
priorAssistantKey: snap.priorAssistantKey || null,
|
|
78
|
-
priorAssistantUserKey:snap.priorAssistantUserKey || null,
|
|
79
|
-
directReplyAfterPriorAssistant:snap.directReplyAfterPriorAssistant===true
|
|
80
|
-
})).catch(() => {});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return state;
|
|
84
|
-
}
|
|
85
|
-
function resetCandidate() {
|
|
86
|
-
session.candidate = "";
|
|
87
|
-
session.stableSince = 0;
|
|
88
|
-
}
|
|
89
|
-
const poll=globalThis.ChatLoopObserverPollV1({session,inspect,emit,
|
|
90
|
-
resetCandidate,fingerprint,STABLE_MS,getState:()=>state});
|
|
91
|
-
function recordFirstChatSubmission(event) {
|
|
92
|
-
if (!event?.target?.closest) return;
|
|
93
|
-
const fromHome = !conversationPath() && !session.path;
|
|
94
|
-
const fromEmptyChat = Boolean(conversationPath()) && session.attaching
|
|
95
|
-
&& !session.baselineUser && !session.attachSignature;
|
|
96
|
-
if (!fromHome && !fromEmptyChat) return;
|
|
97
|
-
const sendClick = event.type === "click" && event.target.closest(
|
|
98
|
-
'button[type="submit"][aria-label="发送"],button[data-testid="send-button"],' +
|
|
99
|
-
'button[data-testid="composer-send-button"],button[aria-label="Send message"]');
|
|
100
|
-
const sendEnter = event.type === "keydown" && event.key === "Enter"
|
|
101
|
-
&& !event.shiftKey && !event.isComposing && event.target.closest(
|
|
102
|
-
'[contenteditable="true"][data-composer-markdown],#prompt-textarea');
|
|
103
|
-
if (!sendClick && !sendEnter) return;
|
|
104
|
-
const editor = document.querySelector('[contenteditable="true"][data-composer-markdown]')
|
|
105
|
-
|| document.querySelector('#prompt-textarea[contenteditable="true"]');
|
|
106
|
-
if (!visible(editor) || !(editor.innerText ?? editor.textContent ?? "").trim()) return;
|
|
107
|
-
session.firstSendSeen = true;
|
|
108
|
-
session.firstSendAt = Date.now();
|
|
109
|
-
if (!session.firstTurnAt) session.firstTurnAt = session.firstSendAt;
|
|
110
|
-
if (fromEmptyChat) {
|
|
111
|
-
session.attaching = false;
|
|
112
|
-
session.attachingFirstTurn = true;
|
|
113
|
-
session.baselineUser = null;
|
|
114
|
-
session.baselineAssistant = null;
|
|
115
|
-
session.pendingUser = null;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
document.addEventListener?.("click", recordFirstChatSubmission, true);
|
|
119
|
-
document.addEventListener?.("keydown", recordFirstChatSubmission, true);
|
|
120
|
-
globalThis.ChatLoopTurnObserverV1 = Object.freeze({
|
|
121
|
-
poll, read: () => ({...state})
|
|
122
|
-
});
|
|
123
|
-
const onRecovery=globalThis.ChatLoopObserverRecoveryV1({
|
|
124
|
-
CONTRACT,session,inspect,poll,resetCandidate,activeEvidenceConversation,messageId});
|
|
125
|
-
const onApproval=globalThis.ChatLoopObserverApprovalV1({
|
|
126
|
-
CONTRACT,inspect,activeEvidenceConversation,messageId});
|
|
127
|
-
chrome.runtime.onMessage.addListener((message,_sender,reply)=>{
|
|
128
|
-
if(['CHAT_LOOP_TURN_RETRY_MONITOR_V1','CHAT_LOOP_TURN_RESUME_V1',
|
|
129
|
-
'CHAT_LOOP_REPAIR_EVIDENCE_V1'].includes(message?.type))
|
|
130
|
-
return onRecovery(message,reply);
|
|
131
|
-
if(message?.type==='CHAT_LOOP_APPROVAL_EVIDENCE_V1')
|
|
132
|
-
return onApproval(message,reply);
|
|
133
|
-
if (message?.type === "CHAT_LOOP_TURN_VERIFY_V1") {
|
|
134
|
-
// Explicit manual Action: only a fresh read-only completed-Turn candidate.
|
|
135
|
-
// This does not emit a completion event or write anything to the page.
|
|
136
|
-
const snap = inspect();
|
|
137
|
-
const ready = Boolean(snap.path && snap.userKey && snap.assistantKey
|
|
138
|
-
&& snap.text && snap.composerReady && snap.copyAction
|
|
139
|
-
&& !snap.stop && !snap.busy && !snap.toolUnknown && !snap.fatal
|
|
140
|
-
&& !snap.dialog && (!snap.turnState || snap.turnState === "complete"));
|
|
141
|
-
reply({contract: CONTRACT, status: ready ? "READY" : "UNVERIFIED",
|
|
142
|
-
page: snap.path || null, userKey: snap.userKey || null,
|
|
143
|
-
assistantKey: snap.assistantKey || null,
|
|
144
|
-
replyText: ready ? snap.text : null});
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
if (message?.type !== "CHAT_LOOP_TURN_OBSERVE_V1") return false;
|
|
148
|
-
if (message.poll === true) poll();
|
|
149
|
-
reply({...state});
|
|
150
|
-
return false;
|
|
151
|
-
});
|
|
152
|
-
setInterval(poll, POLL_MS);
|
|
153
|
-
poll();
|
|
154
|
-
})();
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
// One bounded inventory for the existing Extension Worker. It never sends,
|
|
2
|
-
// types into, or otherwise drives a ChatGPT page.
|
|
3
|
-
(() => {
|
|
4
|
-
const KEY = 'chat-loop.resources.v1';
|
|
5
|
-
const ACTION_LIMIT = 3; // Includes machine Eye, Start, manual and timed Actions.
|
|
6
|
-
const CHAT_LIMIT = 2; // One owner plus at most one Handoff successor.
|
|
7
|
-
const AUDIT_TTL = 60_000; // Reap obsolete audit pages from installed older Extension versions.
|
|
8
|
-
const READ_TTL = 180_000;
|
|
9
|
-
const TERMINAL_TTL = 30_000;
|
|
10
|
-
const READ_ONLY = new Set(['status','text','dom','screenshot','reload']);
|
|
11
|
-
const ACTIONS = new Set(['start','continue','handoff','status','text','dom',
|
|
12
|
-
'screenshot','reload','clean']);
|
|
13
|
-
const validId = s => /^[a-f0-9]{32}$/.test(s || '');
|
|
14
|
-
const validTabId = s => /^[1-9][0-9]*$/.test(s || '');
|
|
15
|
-
const extensionBase = () => chrome.runtime.getURL('');
|
|
16
|
-
function classify(tab) {
|
|
17
|
-
if (!Number.isInteger(tab?.id) || !tab.url) return null;
|
|
18
|
-
let u;
|
|
19
|
-
try {u = new URL(tab.url);} catch {return null;}
|
|
20
|
-
if (u.protocol !== 'chrome-extension:' || !tab.url.startsWith(extensionBase())
|
|
21
|
-
|| u.host !== new URL(extensionBase()).host) return null;
|
|
22
|
-
if (u.pathname === '/popup.html' && u.search === '?audit=1')
|
|
23
|
-
return {kind:'audit'}; // Legacy page reaping only; old audit UI is not executable.
|
|
24
|
-
const name = u.pathname.match(/^\/([a-z]+)\.html$/)?.[1];
|
|
25
|
-
if (!ACTIONS.has(name)) return null;
|
|
26
|
-
if (u.searchParams.size === 1 && validId(u.searchParams.get('requestId')))
|
|
27
|
-
return {kind:READ_ONLY.has(name) || ['continue','handoff'].includes(name)
|
|
28
|
-
? 'read-only' : 'machine', name, requestId:u.searchParams.get('requestId')};
|
|
29
|
-
if (['continue','handoff'].includes(name)
|
|
30
|
-
&& u.searchParams.size === 2 && validTabId(u.searchParams.get('tabId'))
|
|
31
|
-
&& /^[0-9a-f-]{36}$/i.test(u.searchParams.get('token') || ''))
|
|
32
|
-
return {kind:'send', name, token:u.searchParams.get('token'),
|
|
33
|
-
targetId:Number(u.searchParams.get('tabId'))};
|
|
34
|
-
// Manual pages count toward the quota but are never automatically closed.
|
|
35
|
-
return {kind:'manual', name};
|
|
36
|
-
}
|
|
37
|
-
const initial = () => ({created:0, observed:0, closed:0, denied:0,
|
|
38
|
-
peakActions:0, peakChats:0, lastDenial:null, entries:[]});
|
|
39
|
-
const load = async () => {
|
|
40
|
-
const value=(await chrome.storage.local.get(KEY))[KEY];
|
|
41
|
-
return value && Array.isArray(value.entries) ? value : initial();
|
|
42
|
-
};
|
|
43
|
-
const save = state => chrome.storage.local.set({[KEY]:state});
|
|
44
|
-
const cleanEntry = x => x && Number.isInteger(x.id) && typeof x.url === 'string';
|
|
45
|
-
const safeRemove = async (tab,entry,state,reason) => {
|
|
46
|
-
const live=await chrome.tabs.get(tab.id).catch(()=>null);
|
|
47
|
-
if (!live || live.url !== entry.url || live.active || live.pinned) return false;
|
|
48
|
-
try {await chrome.tabs.remove(tab.id);}
|
|
49
|
-
catch (error) {
|
|
50
|
-
// A user can close this tab after the final ownership check. Treat an
|
|
51
|
-
// absent tab as unconfirmed cleanup and reconcile it on the next scan;
|
|
52
|
-
// a still-live tab with a remove error must remain an explicit failure.
|
|
53
|
-
if (await chrome.tabs.get(tab.id).catch(()=>null)) throw error;
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
state.closed++;
|
|
57
|
-
state.lastReaped={id:tab.id, reason, at:Date.now()};
|
|
58
|
-
state.entries=state.entries.filter(e=>e.id!==tab.id);
|
|
59
|
-
return true;
|
|
60
|
-
};
|
|
61
|
-
const noDraft = async tabId => {
|
|
62
|
-
try {
|
|
63
|
-
const [p]=await chrome.scripting.executeScript({target:{tabId},func:()=>{
|
|
64
|
-
if (location.origin !== 'https://chatgpt.com' || !/^\/c\/[0-9a-f-]{12,}$/i.test(location.pathname)) return false;
|
|
65
|
-
const editor=document.querySelector('[contenteditable="true"][data-composer-markdown]')
|
|
66
|
-
||document.querySelector('#prompt-textarea[contenteditable="true"]');
|
|
67
|
-
return !!editor && !(editor.innerText || editor.textContent || '').trim()
|
|
68
|
-
&& !document.querySelector('[data-testid*="attachment-preview"], [data-testid*="image-preview"], [data-testid="composer-attachment"]');
|
|
69
|
-
}});
|
|
70
|
-
return p?.result===true;
|
|
71
|
-
} catch {return false;}
|
|
72
|
-
};
|
|
73
|
-
async function reconcile(run, {reap=true}={}) {
|
|
74
|
-
const state=await load(),now=Date.now();
|
|
75
|
-
const all=await chrome.tabs.query({});
|
|
76
|
-
const live=new Map(all.filter(t=>Number.isInteger(t.id)).map(t=>[t.id,t]));
|
|
77
|
-
const kept=[];
|
|
78
|
-
for (const entry of state.entries.filter(cleanEntry)) {
|
|
79
|
-
const tab=live.get(entry.id);
|
|
80
|
-
if (!tab || tab.url!==entry.url && entry.kind!=='chat') {
|
|
81
|
-
if (!tab) state.closed++;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
// A Chat URL may change from blank to canonical only via markConfirmed.
|
|
85
|
-
if (entry.kind==='chat' && tab.url!==entry.url) {
|
|
86
|
-
kept.push(entry);continue; // Preserve provenance; never delete on unknown navigation.
|
|
87
|
-
}
|
|
88
|
-
kept.push(entry);
|
|
89
|
-
}
|
|
90
|
-
state.entries=kept;
|
|
91
|
-
for (const tab of all) {
|
|
92
|
-
const info=classify(tab);
|
|
93
|
-
if (!info || state.entries.some(e=>e.id===tab.id)) continue;
|
|
94
|
-
state.entries.push({id:tab.id,url:tab.url,kind:'action',type:info.kind,
|
|
95
|
-
name:info.name||null,firstSeenAt:now,owned:false});
|
|
96
|
-
state.observed++;
|
|
97
|
-
}
|
|
98
|
-
// A crashed Action may have created a Chat before calling registerChat.
|
|
99
|
-
// Chrome's trusted openerTabId lets us recover that exact provenance,
|
|
100
|
-
// including after an MV3 Worker restart. Unknown other Chats are not owned.
|
|
101
|
-
for (const tab of all) {
|
|
102
|
-
if (!Number.isInteger(tab.id)||!Number.isInteger(tab.openerTabId)
|
|
103
|
-
|| !/^https:\/\/chatgpt\.com\/(?:|c\/[0-9a-f-]{12,})$/i.test(tab.url||'')
|
|
104
|
-
|| state.entries.some(e=>e.id===tab.id)) continue;
|
|
105
|
-
const opener=live.get(tab.openerTabId), proof=classify(opener);
|
|
106
|
-
const exactStart=proof?.name==='start' && proof.kind==='machine'
|
|
107
|
-
&& [run?.machineActionTabId,run?.lastStartActionTabId].includes(opener?.id);
|
|
108
|
-
const exactHandoff=proof?.name==='handoff' && proof.kind==='send'
|
|
109
|
-
&& proof.token===run?.token
|
|
110
|
-
&& [run?.tabId,run?.sourceTabId].includes(proof.targetId);
|
|
111
|
-
if ((!exactStart&&!exactHandoff)||!(run?.sessionId||run?.token)) continue;
|
|
112
|
-
state.entries.push({id:tab.id,url:tab.url,kind:'chat',
|
|
113
|
-
sessionId:run.sessionId||run.token,firstSeenAt:now,confirmed:false,
|
|
114
|
-
testOwned:/^cl-intent-e2e-[a-z0-9-]+$/i.test(run.projectId||'')});
|
|
115
|
-
state.observed++;state.created++;
|
|
116
|
-
}
|
|
117
|
-
if (reap) {
|
|
118
|
-
for (const entry of [...state.entries]) {
|
|
119
|
-
const tab=live.get(entry.id);
|
|
120
|
-
if (!tab || tab.active || tab.pinned) continue;
|
|
121
|
-
const age=now-(entry.firstSeenAt||now);
|
|
122
|
-
if (entry.kind==='action') {
|
|
123
|
-
const info=classify(tab);
|
|
124
|
-
if (!info || tab.url!==entry.url) continue;
|
|
125
|
-
if (info.kind==='audit' && age>=AUDIT_TTL)
|
|
126
|
-
await safeRemove(tab,entry,state,'STALE_AUDIT');
|
|
127
|
-
else if (info.kind==='read-only' && age>=READ_TTL)
|
|
128
|
-
await safeRemove(tab,entry,state,'STALE_READ_ONLY_NO_SEND');
|
|
129
|
-
else if (info.kind==='send' && age>=TERMINAL_TTL
|
|
130
|
-
&& ['DONE','BLOCKED'].includes(run?.phase)
|
|
131
|
-
&& run?.token===info.token
|
|
132
|
-
&& [run.tabId,run.sourceTabId].includes(info.targetId))
|
|
133
|
-
await safeRemove(tab,entry,state,'CONFIRMED_TERMINAL_ACTION');
|
|
134
|
-
else if (info.kind==='machine' && info.name==='start'
|
|
135
|
-
&& age>=TERMINAL_TTL && ['DONE','BLOCKED'].includes(run?.phase)
|
|
136
|
-
&& [run?.lastStartActionTabId,run?.machineActionTabId].includes(tab.id))
|
|
137
|
-
await safeRemove(tab,entry,state,'CONFIRMED_TERMINAL_START');
|
|
138
|
-
} else if (entry.kind==='chat' && entry.confirmed
|
|
139
|
-
&& entry.testOwned===true && entry.terminal==='DONE' && age>=TERMINAL_TTL
|
|
140
|
-
&& tab.url===entry.url && await noDraft(tab.id)) {
|
|
141
|
-
await safeRemove(tab,entry,state,'DONE_OWNED_CHAT');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
// Count every live matching page, even when the bounded evidence index
|
|
146
|
-
// cannot retain every item after an external flood of manual pages.
|
|
147
|
-
const after=await chrome.tabs.query({});
|
|
148
|
-
const actionCount=after.filter(t=>classify(t)).length;
|
|
149
|
-
const afterIds=new Set(after.map(t=>t.id));
|
|
150
|
-
const liveChatEntries=state.entries.filter(e=>e.kind==='chat'
|
|
151
|
-
&& afterIds.has(e.id));
|
|
152
|
-
const chatCount=liveChatEntries.length;
|
|
153
|
-
// The quota is for in-flight Owners and a Handoff successor, not for
|
|
154
|
-
// retained historical Chat tabs. Keep terminal provenance and the tabs;
|
|
155
|
-
// neither is permission to send. A recovered same-Session Owner counts
|
|
156
|
-
// again even when its ledger still records an earlier BLOCKED phase.
|
|
157
|
-
const activeChatCount=liveChatEntries.filter(e=>
|
|
158
|
-
!['DONE','BLOCKED'].includes(e.terminal)
|
|
159
|
-
||(e.sessionId===(run?.sessionId||run?.token)
|
|
160
|
-
&&!['DONE','BLOCKED'].includes(run?.phase))).length;
|
|
161
|
-
const unownedHomes=after.filter(t=>t.url==='https://chatgpt.com/'
|
|
162
|
-
&& !state.entries.some(e=>e.kind==='chat'&&e.id===t.id)).length;
|
|
163
|
-
state.peakActions=Math.max(state.peakActions,actionCount);
|
|
164
|
-
state.peakChats=Math.max(state.peakChats,chatCount);
|
|
165
|
-
// Retain tracked Chats first: evicting their provenance would weaken the
|
|
166
|
-
// quota and could make an unknown send appear safe to replay.
|
|
167
|
-
const chatEntries=state.entries.filter(e=>e.kind==='chat');
|
|
168
|
-
const actionEntries=state.entries.filter(e=>e.kind==='action');
|
|
169
|
-
const slots=Math.max(0,32-chatEntries.length);
|
|
170
|
-
state.entries=[...chatEntries,...(slots?actionEntries.slice(-slots):[])];
|
|
171
|
-
// Native/manual pages remain counted directly from the browser snapshot.
|
|
172
|
-
state.current={actions:actionCount,chats:chatCount,
|
|
173
|
-
activeChats:activeChatCount,unownedHomes,totalTabs:after.length,at:now};
|
|
174
|
-
await save(state);
|
|
175
|
-
return {state,actionCount,chatCount,activeChatCount,unownedHomes};
|
|
176
|
-
}
|
|
177
|
-
async function admit(run,{kind='action'}={}) {
|
|
178
|
-
const {state,actionCount,chatCount,activeChatCount,unownedHomes}=await reconcile(run);
|
|
179
|
-
const blocked=actionCount+(kind==='action'?1:0)>ACTION_LIMIT
|
|
180
|
-
? 'RESOURCE_ACTION_LIMIT' : activeChatCount+unownedHomes+(kind==='chat'?1:0)>CHAT_LIMIT
|
|
181
|
-
? 'RESOURCE_CHAT_LIMIT' : null;
|
|
182
|
-
if (blocked) {
|
|
183
|
-
state.denied++;state.lastDenial={code:blocked,at:Date.now()};
|
|
184
|
-
await save(state);
|
|
185
|
-
}
|
|
186
|
-
return blocked?{ok:false,code:blocked,actionCount,chatCount}
|
|
187
|
-
:{ok:true,actionCount,chatCount};
|
|
188
|
-
}
|
|
189
|
-
async function registerAction(tab) {
|
|
190
|
-
const info=classify(tab);
|
|
191
|
-
if (!info) return false;
|
|
192
|
-
const state=await load();
|
|
193
|
-
if (!state.entries.some(e=>e.id===tab.id)) {
|
|
194
|
-
state.entries.push({id:tab.id,url:tab.url,kind:'action',
|
|
195
|
-
type:info.kind,firstSeenAt:Date.now(),owned:true});
|
|
196
|
-
state.created++;
|
|
197
|
-
// Fast actions can finish before the next alarm/reconciliation. Count
|
|
198
|
-
// their observed creation in peak metrics even if no later scan sees them.
|
|
199
|
-
state.peakActions=Math.max(state.peakActions,
|
|
200
|
-
state.entries.filter(e=>e.kind==='action').length);
|
|
201
|
-
await save(state);
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
async function registerChat(tab,run) {
|
|
206
|
-
if (!Number.isInteger(tab?.id) || tab.url!=='https://chatgpt.com/'
|
|
207
|
-
|| !(run?.sessionId || run?.token) || run.phase!=='PENDING') return false;
|
|
208
|
-
const state=await load();
|
|
209
|
-
const existing=state.entries.find(e=>e.id===tab.id);
|
|
210
|
-
if(existing)return existing.kind==='chat'
|
|
211
|
-
&&existing.sessionId===(run.sessionId||run.token);
|
|
212
|
-
state.entries.push({id:tab.id,url:tab.url,kind:'chat',
|
|
213
|
-
sessionId:run.sessionId||run.token,firstSeenAt:Date.now(),confirmed:false,
|
|
214
|
-
testOwned:/^cl-intent-e2e-[a-z0-9-]+$/i.test(run.projectId||'')});
|
|
215
|
-
state.created++;
|
|
216
|
-
state.peakChats=Math.max(state.peakChats,
|
|
217
|
-
state.entries.filter(e=>e.kind==='chat').length);
|
|
218
|
-
await save(state);
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
async function adoptChat(tab,run) {
|
|
222
|
-
if(!Number.isInteger(tab?.id)||typeof tab.url!=="string"
|
|
223
|
-
|| !/^https:\/\/chatgpt\.com\/(?:c\/[0-9a-f-]{12,}|g\/[^/]+\/c\/[0-9a-f-]{12,})$/i.test(tab.url)
|
|
224
|
-
||!run?.sessionId||run.phase!=="PENDING"||run.adoptTabId!==tab.id)
|
|
225
|
-
return false;
|
|
226
|
-
const state=await load();
|
|
227
|
-
if(state.entries.some(e=>e.id===tab.id))return false; // Existing Owner, even terminal, is not silently replaced.
|
|
228
|
-
state.entries.push({id:tab.id,url:tab.url,kind:"chat",
|
|
229
|
-
sessionId:run.sessionId,firstSeenAt:Date.now(),confirmed:true,
|
|
230
|
-
adopted:true,testOwned:false});
|
|
231
|
-
state.created++;
|
|
232
|
-
state.peakChats=Math.max(state.peakChats,
|
|
233
|
-
state.entries.filter(e=>e.kind==="chat").length);
|
|
234
|
-
await save(state);
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
|
-
async function confirmChat(id,sessionId,url) {
|
|
238
|
-
const state=await load();
|
|
239
|
-
const entry=state.entries.find(e=>e.id===id&&e.kind==='chat'
|
|
240
|
-
&&e.sessionId===sessionId);
|
|
241
|
-
if (!entry || !/^https:\/\/chatgpt\.com\/(?:c\/[0-9a-f-]{12,}|g\/[^/]+\/c\/[0-9a-f-]{12,})$/i.test(url)) return;
|
|
242
|
-
entry.url=url;entry.confirmed=true;
|
|
243
|
-
await save(state);
|
|
244
|
-
}
|
|
245
|
-
async function terminal(run) {
|
|
246
|
-
if (!(run?.sessionId||run?.token) || !['DONE','BLOCKED'].includes(run.phase)) return;
|
|
247
|
-
const state=await load();
|
|
248
|
-
for(const entry of state.entries) if(entry.kind==='chat'
|
|
249
|
-
&&entry.sessionId===(run.sessionId||run.token)) entry.terminal=run.phase;
|
|
250
|
-
await save(state);
|
|
251
|
-
}
|
|
252
|
-
globalThis.ChatLoopResourcesV1=Object.freeze({reconcile,admit,registerAction,
|
|
253
|
-
registerChat,adoptChat,confirmChat,terminal,KEY,ACTION_LIMIT,CHAT_LIMIT});
|
|
254
|
-
})();
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"manifest_version": 3,
|
|
3
|
-
"name": "Chat Loop Extension",
|
|
4
|
-
"version": "0.4.11",
|
|
5
|
-
"description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
|
|
6
|
-
"permissions": [
|
|
7
|
-
"activeTab",
|
|
8
|
-
"tabs",
|
|
9
|
-
"downloads",
|
|
10
|
-
"clipboardWrite",
|
|
11
|
-
"nativeMessaging",
|
|
12
|
-
"storage",
|
|
13
|
-
"alarms",
|
|
14
|
-
"scripting"
|
|
15
|
-
],
|
|
16
|
-
"host_permissions": [
|
|
17
|
-
"https://chatgpt.com/*"
|
|
18
|
-
],
|
|
19
|
-
"background": {
|
|
20
|
-
"service_worker": "background.js"
|
|
21
|
-
},
|
|
22
|
-
"action": {
|
|
23
|
-
"default_title": "Check Chat Loop web environment",
|
|
24
|
-
"default_popup": "popup.html"
|
|
25
|
-
},
|
|
26
|
-
"content_scripts": [
|
|
27
|
-
{
|
|
28
|
-
"matches": [
|
|
29
|
-
"https://chatgpt.com/*"
|
|
30
|
-
],
|
|
31
|
-
"js": [
|
|
32
|
-
"content.js",
|
|
33
|
-
"loop/observer-inspect.js",
|
|
34
|
-
"loop/observer-poll.js",
|
|
35
|
-
"loop/observer-recovery.js",
|
|
36
|
-
"loop/observer-approval.js",
|
|
37
|
-
"loop/observer.js"
|
|
38
|
-
],
|
|
39
|
-
"run_at": "document_idle"
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>Chat Loop Extension · 环境检测</title>
|
|
7
|
-
<style>
|
|
8
|
-
body { font-family: system-ui, sans-serif; width: 310px; margin: 0; padding: 18px; color: #242424; }
|
|
9
|
-
h1 { font-size: 17px; margin: 0 0 12px; }
|
|
10
|
-
#status { font-size: 15px; font-weight: 650; }
|
|
11
|
-
#detail { color: #60636a; line-height: 1.5; font-size: 13px; }
|
|
12
|
-
a { color: #1269c7; }
|
|
13
|
-
</style>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
<h1>Chat Loop Extension · 环境检查</h1>
|
|
17
|
-
<p id="status" role="status">正在检测…</p>
|
|
18
|
-
<p id="detail">仅检查当前页面与浏览器类型,不读取聊天内容。</p>
|
|
19
|
-
<p>打开动作页即执行,成功后自动关闭。多 Chat 标签页时请在动作页 URL 指定 <code>?tabId=...</code>。</p>
|
|
20
|
-
<p><a href="screenshot.html" target="_blank">Screenshot</a> · <a href="dom.html" target="_blank">DOM</a> · <a href="text.html" target="_blank">Text</a> · <a href="reload.html" target="_blank">Reload</a> · <button id="clean-action" type="button">Clean 输入框</button></p>
|
|
21
|
-
<p><a href="https://chatgpt.com/" target="_blank" rel="noopener noreferrer">打开 ChatGPT 网页版</a></p>
|
|
22
|
-
<p id="action-state" role="status">最近发送动作:读取中…</p>
|
|
23
|
-
<script src="popup.js"></script>
|
|
24
|
-
</body>
|
|
25
|
-
</html>
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const CONTRACT = "chat-loop.web-environment.v1";
|
|
2
|
-
const statusNode = document.getElementById("status");
|
|
3
|
-
const detailNode = document.getElementById("detail");
|
|
4
|
-
|
|
5
|
-
function show(status, detail) {
|
|
6
|
-
statusNode.textContent = status;
|
|
7
|
-
detailNode.textContent = detail;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function requestProof(tabId) {
|
|
11
|
-
return new Promise((resolve) => {
|
|
12
|
-
chrome.tabs.sendMessage(tabId, { type: "CHAT_LOOP_WEB_CHECK_V1" }, (proof) => {
|
|
13
|
-
if (chrome.runtime.lastError) {
|
|
14
|
-
resolve({ status: "EXTENSION_UNVERIFIED" });
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
resolve(proof);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function check() {
|
|
23
|
-
if(typeof chrome.tabs?.query!=='function'){
|
|
24
|
-
show('EXTENSION_API_UNAVAILABLE','Chrome 标签页 API 不可用,请检查扩展状态。');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
28
|
-
const tab = tabs[0];
|
|
29
|
-
if (!tab || !tab.url) {
|
|
30
|
-
show("WEB_UNVERIFIED", "无法确认当前 Chrome 标签页。");
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
let url;
|
|
34
|
-
try { url = new URL(tab.url); } catch {
|
|
35
|
-
show("WEB_UNVERIFIED", "当前标签页地址无效。");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (url.protocol !== "https:" || url.hostname !== "chatgpt.com") {
|
|
39
|
-
show("UNSUPPORTED_PAGE", "请在 Chrome 中打开 https://chatgpt.com 后重新检测。");
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const proof = await requestProof(tab.id);
|
|
43
|
-
if (proof?.contract !== CONTRACT) {
|
|
44
|
-
show("EXTENSION_UNVERIFIED", "页面尚未连接扩展。请刷新 ChatGPT 页面后再打开此扩展。");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (proof.status === "WEB_READY" && proof.browser === "GOOGLE_CHROME") {
|
|
48
|
-
show("WEB_READY", "Chrome 网页环境已验证;这是扩展本地检测结果,尚未回传给 ChatGPT Plugin。");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
show(proof.status || "WEB_UNVERIFIED",
|
|
52
|
-
"当前浏览器环境尚未得到 Google Chrome 的有效证明。");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
void check().catch(() => show("WEB_UNVERIFIED", "浏览器检测失败,请重试。"));
|
|
56
|
-
|
|
57
|
-
// Read-only action feedback; never expose the single-use token or message text.
|
|
58
|
-
async function showActionState() {
|
|
59
|
-
const key = "chat-loop.action.run.v1";
|
|
60
|
-
const run = (await chrome.storage.local.get(key))[key];
|
|
61
|
-
const allowed = ["phase", "action", "reason", "tabId", "page", "sourceTabId", "sourcePage",
|
|
62
|
-
"userKey", "assistantKey", "newUserKey", "startedAt",
|
|
63
|
-
"sessionId", "projectId", "generation",
|
|
64
|
-
"deadlineAt", "handoffPending", "handoffPendingAt", "attemptedNewTabId"];
|
|
65
|
-
const summary = {version: chrome.runtime.getManifest().version};
|
|
66
|
-
if (run) for (const key of allowed) if (run[key] !== undefined) summary[key] = run[key];
|
|
67
|
-
document.body.dataset.actionState = JSON.stringify(summary);
|
|
68
|
-
document.getElementById("action-state").textContent = run
|
|
69
|
-
? "最近发送动作:" + run.action + " · " + run.phase + (run.reason ? " · " + run.reason : "")
|
|
70
|
-
: "尚无发送动作记录";
|
|
71
|
-
}
|
|
72
|
-
void showActionState().catch(() => {
|
|
73
|
-
document.getElementById("action-state").textContent = "最近发送动作:状态无法确认,不要重复发送";
|
|
74
|
-
});
|
|
75
|
-
chrome.storage.onChanged.addListener(() => {void showActionState();});
|
|
76
|
-
|
|
77
|
-
// User-clicked menu action only; bind to the single active ChatGPT tab.
|
|
78
|
-
document.getElementById('clean-action').addEventListener('click',async()=>{
|
|
79
|
-
if(typeof chrome.tabs?.query!=='function'){
|
|
80
|
-
show('CLEAN_BLOCKED','Chrome 标签页 API 不可用,未执行清理。');
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
let selected;
|
|
84
|
-
try{selected=(await chrome.tabs.query({active:true,currentWindow:true}))[0]}
|
|
85
|
-
catch{show('CLEAN_BLOCKED','当前标签页无法验证,未执行清理。');return;}
|
|
86
|
-
if(!selected?.id||!selected?.url?.startsWith('https://chatgpt.com/')){
|
|
87
|
-
show('CLEAN_NOT_AVAILABLE','请先选中要清理的 ChatGPT 标签页。');return;
|
|
88
|
-
}
|
|
89
|
-
const opened=await chrome.runtime.sendMessage({
|
|
90
|
-
type:'CHAT_LOOP_POPUP_CLEAN_OPEN_V1',tabId:selected.id}).catch(()=>null);
|
|
91
|
-
if(opened?.status!=='OK')
|
|
92
|
-
show('CLEAN_BLOCKED',opened?.code||'CLEAN_ACTION_UNVERIFIED');
|
|
93
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>Chat Loop Extension · Reload</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 Extension · Reload</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/reload.js"></script>
|
|
16
|
-
</body>
|
|
17
|
-
</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 · Screenshot</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 Extension · Screenshot</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/screenshot.js"></script>
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN"><head><meta charset="utf-8"><title>Chat Loop · start</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><h1>Chat Loop · start</h1><p id="status" role="status">STARTING</p>
|
|
5
|
-
<p id="details">只有已确认意图且成功取得全局执行权才会发送首条消息。</p>
|
|
6
|
-
<script src="actions/start.js"></script></body></html>
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN"><head><meta charset="utf-8"><title>Chat Loop · status</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><h1>Chat Loop · status</h1><p id="status" role="status">STARTING</p>
|
|
5
|
-
<p id="details">只读查询唯一网页执行会话,不执行网页副作用。</p>
|
|
6
|
-
<script src="actions/status.js"></script></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 · Text</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 Extension · Text</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/text.js"></script>
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|