@tomflow/chatloop-tools 0.9.62 → 0.9.64

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 (154) hide show
  1. package/README.md +13 -1
  2. package/index.mjs +7 -7
  3. package/lib/context-control-run.mjs +23 -5
  4. package/lib/extension-proxy.mjs +29 -10
  5. package/lib/native-owner-v2.mjs +128 -0
  6. package/lib/release-health-checks.mjs +29 -5
  7. package/lib/trace-gateway.mjs +3 -1
  8. package/package.json +3 -13
  9. package/providers/extension.mjs +59 -16
  10. package/node_modules/@tomflow/chatloop-context/README.md +0 -240
  11. package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +0 -48
  12. package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +0 -151
  13. package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +0 -376
  14. package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +0 -266
  15. package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +0 -134
  16. package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +0 -82
  17. package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +0 -349
  18. package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +0 -72
  19. package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +0 -73
  20. package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +0 -507
  21. package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +0 -11
  22. package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +0 -192
  23. package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +0 -277
  24. package/node_modules/@tomflow/chatloop-context/index.mjs +0 -236
  25. package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +0 -86
  26. package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +0 -77
  27. package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +0 -1989
  28. package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +0 -69
  29. package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +0 -285
  30. package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -298
  31. package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -286
  32. package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +0 -115
  33. package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +0 -51
  34. package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +0 -75
  35. package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +0 -262
  36. package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +0 -246
  37. package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +0 -147
  38. package/node_modules/@tomflow/chatloop-context/lib/core/run-cancel.mjs +0 -54
  39. package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +0 -375
  40. package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +0 -397
  41. package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +0 -183
  42. package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +0 -13
  43. package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +0 -111
  44. package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +0 -107
  45. package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +0 -118
  46. package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +0 -20
  47. package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +0 -316
  48. package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +0 -153
  49. package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +0 -19
  50. package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +0 -117
  51. package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +0 -97
  52. package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +0 -169
  53. package/node_modules/@tomflow/chatloop-context/package.json +0 -40
  54. package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +0 -114
  55. package/node_modules/@tomflow/chatloop-extension/README.md +0 -124
  56. package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +0 -13
  57. package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +0 -153
  58. package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +0 -207
  59. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +0 -1
  60. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +0 -1
  61. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +0 -1
  62. package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +0 -1
  63. package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +0 -1
  64. package/node_modules/@tomflow/chatloop-extension/capabilities/entry_test.mjs +0 -1
  65. package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +0 -1
  66. package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +0 -1
  67. package/node_modules/@tomflow/chatloop-extension/capabilities/session.mjs +0 -1
  68. package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +0 -1
  69. package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +0 -1
  70. package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +0 -123
  71. package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +0 -183
  72. package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +0 -340
  73. package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +0 -2
  74. package/node_modules/@tomflow/chatloop-extension/extension/actions/entry_test.js +0 -241
  75. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +0 -393
  76. package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +0 -2
  77. package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +0 -56
  78. package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +0 -9
  79. package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +0 -20
  80. package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +0 -77
  81. package/node_modules/@tomflow/chatloop-extension/extension/actions/session.js +0 -52
  82. package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +0 -295
  83. package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +0 -24
  84. package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +0 -2
  85. package/node_modules/@tomflow/chatloop-extension/extension/background.js +0 -17
  86. package/node_modules/@tomflow/chatloop-extension/extension/clean.html +0 -5
  87. package/node_modules/@tomflow/chatloop-extension/extension/content.js +0 -40
  88. package/node_modules/@tomflow/chatloop-extension/extension/continue.html +0 -9
  89. package/node_modules/@tomflow/chatloop-extension/extension/dom.html +0 -17
  90. package/node_modules/@tomflow/chatloop-extension/extension/entry_test.html +0 -6
  91. package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +0 -9
  92. package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +0 -2
  93. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +0 -275
  94. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +0 -84
  95. package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +0 -107
  96. package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +0 -36
  97. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +0 -299
  98. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +0 -144
  99. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +0 -171
  100. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +0 -109
  101. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +0 -154
  102. package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +0 -259
  103. package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +0 -42
  104. package/node_modules/@tomflow/chatloop-extension/extension/popup.html +0 -25
  105. package/node_modules/@tomflow/chatloop-extension/extension/popup.js +0 -99
  106. package/node_modules/@tomflow/chatloop-extension/extension/reload.html +0 -17
  107. package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +0 -17
  108. package/node_modules/@tomflow/chatloop-extension/extension/session.html +0 -6
  109. package/node_modules/@tomflow/chatloop-extension/extension/start.html +0 -6
  110. package/node_modules/@tomflow/chatloop-extension/extension/status.html +0 -6
  111. package/node_modules/@tomflow/chatloop-extension/extension/text.html +0 -17
  112. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +0 -136
  113. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +0 -218
  114. package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +0 -124
  115. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +0 -296
  116. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +0 -186
  117. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +0 -126
  118. package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +0 -230
  119. package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +0 -163
  120. package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +0 -345
  121. package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +0 -192
  122. package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +0 -161
  123. package/node_modules/@tomflow/chatloop-extension/extension/worker/session-control.js +0 -75
  124. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +0 -197
  125. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +0 -205
  126. package/node_modules/@tomflow/chatloop-extension/index.mjs +0 -71
  127. package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +0 -19
  128. package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +0 -82
  129. package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +0 -303
  130. package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +0 -83
  131. package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +0 -45
  132. package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +0 -115
  133. package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +0 -75
  134. package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +0 -185
  135. package/node_modules/@tomflow/chatloop-extension/package.json +0 -38
  136. package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +0 -138
  137. package/node_modules/@tomflow/chatloop-trace/README.md +0 -118
  138. package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +0 -23
  139. package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +0 -22
  140. package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +0 -4
  141. package/node_modules/@tomflow/chatloop-trace/index.mjs +0 -59
  142. package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +0 -273
  143. package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +0 -308
  144. package/node_modules/@tomflow/chatloop-trace/lib/trace-retention.mjs +0 -140
  145. package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -236
  146. package/node_modules/@tomflow/chatloop-trace/package.json +0 -30
  147. package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +0 -68
  148. package/node_modules/ps-list/index.d.ts +0 -76
  149. package/node_modules/ps-list/index.js +0 -366
  150. package/node_modules/ps-list/license +0 -9
  151. package/node_modules/ps-list/package.json +0 -44
  152. package/node_modules/ps-list/readme.md +0 -56
  153. package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
  154. package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
@@ -1,99 +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
- const stateUnavailable=()=>{
73
- document.getElementById("action-state").textContent =
74
- "最近发送动作:状态无法确认,不要重复发送";
75
- };
76
- void showActionState().catch(stateUnavailable);
77
- chrome.storage.onChanged.addListener((changes,area)=>{
78
- // Unrelated storage churn must not repeatedly reread the Owner projection.
79
- if(area==='local'&&Object.hasOwn(changes,'chat-loop.action.run.v1'))
80
- void showActionState().catch(stateUnavailable);
81
- });
82
-
83
- // User-clicked menu action only; bind to the single active ChatGPT tab.
84
- document.getElementById('clean-action').addEventListener('click',async()=>{
85
- if(typeof chrome.tabs?.query!=='function'){
86
- show('CLEAN_BLOCKED','Chrome 标签页 API 不可用,未执行清理。');
87
- return;
88
- }
89
- let selected;
90
- try{selected=(await chrome.tabs.query({active:true,currentWindow:true}))[0]}
91
- catch{show('CLEAN_BLOCKED','当前标签页无法验证,未执行清理。');return;}
92
- if(!selected?.id||!selected?.url?.startsWith('https://chatgpt.com/')){
93
- show('CLEAN_NOT_AVAILABLE','请先选中要清理的 ChatGPT 标签页。');return;
94
- }
95
- const opened=await chrome.runtime.sendMessage({
96
- type:'CHAT_LOOP_POPUP_CLEAN_OPEN_V1',tabId:selected.id}).catch(()=>null);
97
- if(opened?.status!=='OK')
98
- show('CLEAN_BLOCKED',opened?.code||'CLEAN_ACTION_UNVERIFIED');
99
- });
@@ -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 · session</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 · Session</h1><p id="status" role="status">STARTING</p>
5
- <p id="details">验证精确 Session 和 Context 写权,不直接操作 Chat 页面。</p>
6
- <script src="actions/session.js"></script></body></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>
@@ -1,136 +0,0 @@
1
- // Chat Loop Worker — action-result. Imported in order by background.js; no independent Browser Owner.
2
- // Durable pre-send evidence; once recorded a browser send may have happened.
3
- // A later timeout is UNKNOWN, never equivalent to NOT_SENT.
4
- async function onHandoffSendBegin(message,sender){
5
- const run=await readRun();
6
- if(!isAction(sender,message,run)||run?.action!=="HANDOFF"
7
- ||run.phase!=="PENDING"||!run.contextHandoff
8
- ||run.token!==message.token||run.tabId!==message.tabId)
9
- return {status:"DENIED",code:"HANDOFF_SEND_SOURCE_INVALID"};
10
- if(run.contextHandoff.sendBeginAt)
11
- return {status:"DENIED",code:"HANDOFF_SEND_ALREADY_BEGUN"};
12
- await saveRun({...run,contextHandoff:{...run.contextHandoff,sendBeginAt:Date.now()}});
13
- return {status:"RECORDED"};
14
- }
15
- async function onResult(message, sender) {
16
- const run = await readRun();
17
- if (!isAction(sender, message, run)) return {status: "DENIED", code: "ACTION_SOURCE_INVALID"};
18
- if (run?.phase !== "PENDING" || run.token !== message.token)
19
- return {status: "DENIED", code: "ACTION_NOT_PENDING"};
20
- // Native Retry does not submit another user message. One-time click is
21
- // confirmed separately and re-arms the already-owned pending user Turn.
22
- if (run.retryMode === "NATIVE") {
23
- const tab = await chrome.tabs.get(run.tabId).catch(() => null);
24
- const confirmedRetry = message.result === "RETRY_CLICKED" && tab
25
- && pathOf(tab.url) === run.page && run.retryCount === 1;
26
- const nextRetry = {...run, phase: confirmedRetry ? "WAITING_REPLY" : "BLOCKED",
27
- reason: confirmedRetry ? "" : "RETRY_UNVERIFIED"};
28
- delete nextRetry.retryMode;
29
- await saveRun(nextRetry);
30
- if (confirmedRetry) {
31
- const reset = await chrome.tabs.sendMessage(run.tabId,
32
- {type: "CHAT_LOOP_TURN_RETRY_MONITOR_V1", page: run.page,
33
- userKey: run.newUserKey}).catch(() => null);
34
- if (reset?.status !== "REARMED") {
35
- await saveRun({...nextRetry, phase: "BLOCKED", reason: "RETRY_OBSERVER_UNVERIFIED"});
36
- return {status: "BLOCKED", code: "RETRY_OBSERVER_UNVERIFIED"};
37
- }
38
- }
39
- return {status: confirmedRetry ? "OK" : "BLOCKED"};
40
- }
41
- let confirmed = message.result === "SENT_CONFIRMED"
42
- && typeof message.newUserKey === "string"
43
- && /^user:[^\s]{8,}$/.test(message.newUserKey)
44
- && message.newUserKey !== run.userKey;
45
- const failure = typeof message.reason === "string" && /^[A-Z0-9_]{4,100}$/.test(message.reason)
46
- ? message.reason : "SEND_UNVERIFIED";
47
- let next = {...run, phase: "BLOCKED", reason: failure};
48
- // Diagnostic only: retain the possibly-created target without granting ownership.
49
- if (run.action === "HANDOFF" && Number.isInteger(message.newTabId))
50
- next.attemptedNewTabId = message.newTabId;
51
- if (confirmed && run.action === "HANDOFF") {
52
- const newTab = Number.isInteger(message.newTabId)
53
- ? await chrome.tabs.get(message.newTabId).catch(() => null) : null;
54
- confirmed = Boolean(newTab && message.newTabId !== run.tabId
55
- && pathOf(newTab.url) && pathOf(newTab.url) === message.newPage);
56
- if (confirmed) {
57
- // Transfer the single loop owner. The old Chat remains open for audit.
58
- next = {...run, action: "HANDOFF", sourceTabId: run.tabId,
59
- sourcePage: run.page, tabId: newTab.id, page: message.newPage,
60
- // Keep source identities as the already-processed baseline; the new
61
- // user's first reply must not be suppressed by duplicate detection.
62
- newUserKey: message.newUserKey, phase: "WAITING_REPLY", reason: "",
63
- ...(run.sessionId?{generation:(run.generation||0)+1}:{}),
64
- // The new Chat has no previous assistant message. Never authenticate
65
- // its first Retry/Error Handoff using the OLD Chat's assistant ID.
66
- userKey: null, assistantKey: null, startedAt: Date.now(),
67
- errorHandoffCount: run.handoffMode === "ERROR" ? (run.errorHandoffCount || 0) + 1 : 0,
68
- };
69
- delete next.handoffText;
70
- delete next.errorReason;
71
- delete next.handoffPending;
72
- delete next.handoffPendingAt;
73
- delete next.deadlineAt;
74
- }
75
- } else if (confirmed) {
76
- next = {...run, phase: "WAITING_REPLY", reason: "",
77
- newUserKey: message.newUserKey};
78
- }
79
- // A model prompt is one-shot. Keep only a short receipt, not the prompt
80
- // body, after the Action has reached a confirmed or blocked terminal state.
81
- // The Adopt kickoff exception applies only to the verified pre-Adopt
82
- // assistant reply. Remove it after this send; later Turns must carry
83
- // ordinary independent terminal markers and never inherit the exception.
84
- if(run.recoveryMode==="ADOPT_KICKOFF")delete next.recoveryMode;
85
- if(run.modelIntent){
86
- const override=run.action==="HANDOFF"&&run.modelIntent.action==="CONTINUE";
87
- const finalStatus=confirmed?"SENT_CONFIRMED":"BLOCKED";
88
- next=updateModelReceipt(next,run.modelIntent.id,{
89
- status:finalStatus,actualAction:run.action,
90
- reason:override?"OVERRIDDEN_BY_DEADLINE":confirmed?null:failure,
91
- checkpointForwarded:confirmed&&override});
92
- // The bounded modelReceipts entry above is the unique final intent record.
93
- delete next.modelIntent;
94
- }
95
- if (!confirmed) delete next.modelTurnToken;
96
- if(confirmed&&run.recoveryMode==="HANDOFF_NOT_SENT"){
97
- for(const key of ["contextRecoveryCredential","contextRecoveryBound",
98
- "contextHandoff","recoveryMode","contextSourceMarker",
99
- "recoveryExpectedNativeAt","recoverySourceAssistantKey",
100
- "recoveryProtocol","recoveryAttempts","contextRecoveryAttempted"])
101
- delete next[key];
102
- }
103
- if(!confirmed && run.action==="HANDOFF" && run.contextHandoff){
104
- const notSent=!run.contextHandoff.sendBeginAt;
105
- next={...next,reason:notSent?"CONTEXT_HANDOFF_NOT_SENT":"CONTEXT_HANDOFF_SEND_UNKNOWN",
106
- contextHandoff:{...run.contextHandoff,
107
- sendOutcome:notSent?"NOT_SENT":"SEND_UNKNOWN",
108
- // This is derived ONLY after original Action Result is received.
109
- terminalActionResultAt:Date.now()}};
110
- }
111
- await saveRun(next);
112
- if(confirmed && run.action==="HANDOFF" && run.contextHandoff){
113
- const h=run.contextHandoff;
114
- const bound=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
115
- op:"context-control",command:"run.bind.handoff",
116
- args:{expectedStoreEpoch:h.storeEpoch,writeRequestId:h.attemptId+":bind",
117
- expectedTaskRevision:h.taskRevision,expectedBindingRevision:h.bindingRevision,
118
- attemptId:h.attemptId,checkpointId:h.checkpointId,
119
- targetGeneration:h.targetGeneration,runCredential:h.nextRunCredential}
120
- }).catch(()=>null);
121
- if(bound?.status!=="OK"||bound.result?.status!=="BOUND"){
122
- const failed={...next,phase:"BLOCKED",reason:"CONTEXT_NEW_OWNER_BIND_UNVERIFIED"};
123
- // Retain the exact original attempt and pending credential in private
124
- // Worker storage for receipt-only diagnosis. Never re-send the message.
125
- await saveRun(failed);
126
- return {status:"BLOCKED",code:bound?.code||"CONTEXT_NEW_OWNER_BIND_UNVERIFIED"};
127
- }
128
- const clean={...next,contextManaged:{storeEpoch:h.storeEpoch}};
129
- delete clean.contextHandoff;
130
- await saveRun(clean); // secret has already been delivered in the unique first message
131
- }
132
- if(confirmed && run.action==="HANDOFF" && Number.isInteger(message.newTabId))
133
- await resources.confirmChat(message.newTabId,next.sessionId||next.token,
134
- "https://chatgpt.com"+message.newPage).catch(()=>{});
135
- return {status: confirmed ? "OK" : "BLOCKED"};
136
- }
@@ -1,218 +0,0 @@
1
- // Chat Loop Worker — action-take. Imported in order by background.js; no independent Browser Owner.
2
- async function onTake(message, sender) {
3
- const run = await readRun();
4
- if (!isAction(sender, message, run)) return {status: "DENIED", code: "ACTION_SOURCE_INVALID"};
5
- if (run?.phase !== "RESERVED" || run.token !== message.token
6
- || run.tabId !== message.tabId) return {status: "DENIED", code: "ACTION_NOT_RESERVED"};
7
- const tab = await chrome.tabs.get(run.tabId).catch(() => null);
8
- if (!tab || pathOf(tab.url) !== run.page) {
9
- await saveRun({...run, phase: "BLOCKED", reason: "CHAT_TARGET_CHANGED"});
10
- return {status: "DENIED", code: "CHAT_TARGET_CHANGED"};
11
- }
12
- if (run.retryMode!=="NATIVE" && run.handoffMode!=="ERROR") {
13
- const pending=await currentConfirmation(run.tabId,run.page,
14
- run.userKey,run.assistantKey);
15
- if(pending===true) {
16
- // A widget appeared after the scheduler decided to Continue.
17
- // Cancel this Action without a send; the same owner observes a fresh
18
- // user reply through the existing Turn observer.
19
- const held=settleModelIntent({...run,phase:"WAITING_REPLY",
20
- newUserKey:run.userKey,reason:"PENDING_CONFIRMATION_DOM"},
21
- "CANCELLED_PENDING_USER_INPUT","PENDING_CONFIRMATION_DOM");
22
- await saveRun(held);
23
- return {status:"DENIED",code:"PENDING_CONFIRMATION_DOM"};
24
- }
25
- if(pending===null) {
26
- await saveRun({...run,phase:"BLOCKED",reason:"CONFIRMATION_DOM_UNVERIFIED"});
27
- return {status:"DENIED",code:"CONFIRMATION_DOM_UNVERIFIED"};
28
- }
29
- }
30
- let projectContext=null;
31
- if(run.action==='HANDOFF'&&run.sessionId){
32
- const durable=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
33
- const projection=sessionProjection(run);
34
- if(durable?.status!=='OK'
35
- ||!matchesNativeProjection(projection,durable.session)
36
- ||durable.contextStatus==='UNVERIFIED'
37
- ||durable.projectContext&&durable.projectContext.projectId!==run.projectId){
38
- await saveRun({...run,phase:'BLOCKED',reason:'HANDOFF_CONTEXT_UNVERIFIED'});
39
- return {status:'DENIED',code:'HANDOFF_CONTEXT_UNVERIFIED'};
40
- }
41
- projectContext=durable.projectContext||null;
42
- }
43
- // Bind a model-control capability to the next *user* Turn, not to a tab or to another Chat.
44
- // Acceptance fixtures retain their existing prompts; native Retry keeps its original Turn token.
45
- const modelTurnToken = run.retryMode === "NATIVE"
46
- ? run.modelTurnToken || null : crypto.randomUUID();
47
- let recoveredContext=null;
48
- if(run.action==="CONTINUE" && run.recoveryMode==="HANDOFF_NOT_SENT"){
49
- const h=run.contextHandoff;
50
- if(!run.contextRecoveryCredential || !h || h.sendOutcome!=="NOT_SENT"
51
- ||h.sendBeginAt ||h.attemptId===run.token){
52
- await saveRun({...run,phase:"BLOCKED",reason:"CONTEXT_NOT_SENT_PROOF_INVALID"});
53
- return {status:"DENIED",code:"CONTEXT_NOT_SENT_PROOF_INVALID"};
54
- }
55
- const snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
56
- op:"context-control",command:"run.snapshot",args:{}}).catch(()=>null);
57
- const cp=snapshot?.result;
58
- if(snapshot?.status!=="OK" || !cp || cp.taskRevision!==h.taskRevision
59
- ||cp.bindingRevision!==h.bindingRevision ||cp.runRef!==null
60
- ||cp.checkpointId!==h.checkpointId ||cp.unknownEffectCount!==0){
61
- await saveRun({...run,phase:"BLOCKED",reason:"CONTEXT_RESTORE_SNAPSHOT_UNVERIFIED"});
62
- return {status:"DENIED",code:"CONTEXT_RESTORE_SNAPSHOT_UNVERIFIED"};
63
- }
64
- const approval=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
65
- op:"context-control",command:"permit.consume",
66
- args:{expectedStoreEpoch:h.storeEpoch,writeRequestId:run.token+":permit",
67
- actionToken:run.token,kind:"CONTINUE",expectedTaskRevision:h.taskRevision,
68
- expectedApprovalRevision:cp.approvalRevision}
69
- }).catch(()=>null);
70
- if(approval?.status!=="OK"||approval.result?.status!=="PERMITTED"){
71
- await saveRun({...run,phase:"BLOCKED",reason:"CONTEXT_RESTORE_PERMIT_UNVERIFIED"});
72
- return {status:"DENIED",code:"CONTEXT_RESTORE_PERMIT_UNVERIFIED"};
73
- }
74
- const restored=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
75
- op:"context-control",command:"run.restore-same-owner",
76
- args:{expectedStoreEpoch:h.storeEpoch,writeRequestId:run.token+":restore",
77
- expectedTaskRevision:h.taskRevision,expectedBindingRevision:h.bindingRevision,
78
- attemptId:h.attemptId,checkpointId:h.checkpointId,
79
- recoveryCredential:run.contextRecoveryCredential,
80
- recoveryActionToken:run.token,sendState:"NOT_SENT"}
81
- }).catch(()=>null);
82
- if(restored?.status!=="OK"||restored.result?.status!=="RESTORED_SAME_OWNER"){
83
- await saveRun({...run,phase:"BLOCKED",reason:"CONTEXT_RESTORE_BIND_UNVERIFIED"});
84
- return {status:"DENIED",code:"CONTEXT_RESTORE_BIND_UNVERIFIED"};
85
- }
86
- recoveredContext={runRef:restored.result.runRef,
87
- runCredential:run.contextRecoveryCredential,storeEpoch:h.storeEpoch,
88
- bindingRevision:restored.result.bindingRevision,taskRevision:h.taskRevision};
89
- }
90
- const pending={...run, phase: "PENDING", modelTurnToken,
91
- ...(recoveredContext?{contextRecoveryBound:recoveredContext}:{})};
92
- await saveRun(run.modelIntent ? updateModelReceipt(pending,run.modelIntent.id,{
93
- status:run.action==="HANDOFF"&&run.modelIntent.action==="CONTINUE"
94
- ?"OVERRIDDEN_BY_DEADLINE":"PENDING"}) : pending);
95
- if(run.action==="CONTINUE" &&run.contextManaged &&!recoveredContext &&run.retryMode!=="NATIVE"){
96
- let snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
97
- op:"context-control",command:"run.snapshot",args:{}}).catch(()=>null);
98
- // First controlled Continue may precede the FIRST business checkpoint.
99
- // Only a proven CHECKPOINT_NOT_FOUND may use the current live task/run
100
- // projection. Network errors and all other snapshot failures stay BLOCKED.
101
- if(snapshot?.status!=="OK"&&snapshot?.code==="CHECKPOINT_NOT_FOUND")
102
- snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
103
- op:"context-control",command:"run.terminalStatus",args:{}}).catch(()=>null);
104
- const cp=snapshot?.result;
105
- if(snapshot?.status!=="OK"||!cp ||cp.runRef!==
106
- run.sessionId+":"+run.taskId+":"+(run.generation||0)
107
- ||!Number.isSafeInteger(cp.taskRevision)||cp.taskRevision<1
108
- ||!Number.isSafeInteger(cp.approvalRevision)||cp.approvalRevision<1
109
- ||cp.unknownEffectCount!==0||cp.executionOutcome==="DONE"){
110
- await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_CONTINUE_SNAPSHOT_UNVERIFIED"});
111
- return {status:"DENIED",code:"CONTEXT_CONTINUE_SNAPSHOT_UNVERIFIED"};
112
- }
113
- const allowed=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
114
- op:"context-control",command:"permit.consume",
115
- args:{expectedStoreEpoch:run.contextManaged.storeEpoch,
116
- writeRequestId:run.token+":permit",expectedTaskRevision:cp.taskRevision,
117
- expectedApprovalRevision:cp.approvalRevision,
118
- actionToken:run.token,kind:"CONTINUE"}
119
- }).catch(()=>null);
120
- if(allowed?.status!=="OK"||allowed.result?.status!=="PERMITTED"){
121
- await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_CONTINUE_PERMIT_UNVERIFIED"});
122
- return {status:"DENIED",code:"CONTEXT_CONTINUE_PERMIT_UNVERIFIED"};
123
- }
124
- }
125
- let managedHandoff=null;
126
- if(run.action==="HANDOFF"&&run.contextManaged){
127
- if(!run.taskId||!run.sessionId){
128
- await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_TASK_IDENTITY_MISSING"});
129
- return {status:"DENIED",code:"CONTEXT_TASK_IDENTITY_MISSING"};
130
- }
131
- const proof=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
132
- op:"context-control",command:"run.snapshot",args:{}}).catch(()=>null);
133
- const cp=proof?.result;
134
- if(proof?.status!=="OK"||!cp?.checkpointCurrent||cp.unknownEffectCount!==0
135
- ||cp.runRef!==run.sessionId+":"+run.taskId+":"+(run.generation||0)){
136
- await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_CHECKPOINT_UNVERIFIED"});
137
- return {status:"DENIED",code:"CONTEXT_CHECKPOINT_UNVERIFIED"};
138
- }
139
- const permitProof=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
140
- op:"context-control",command:"permit.consume",
141
- args:{expectedStoreEpoch:run.contextManaged.storeEpoch,
142
- writeRequestId:run.token+":permit",actionToken:run.token,kind:"HANDOFF",
143
- expectedTaskRevision:cp.taskRevision,
144
- expectedApprovalRevision:cp.approvalRevision}
145
- }).catch(()=>null);
146
- if(permitProof?.status!=="OK"||permitProof.result?.status!=="PERMITTED"){
147
- await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_HANDOFF_PERMIT_UNVERIFIED"});
148
- return {status:"DENIED",code:"CONTEXT_HANDOFF_PERMIT_UNVERIFIED"};
149
- }
150
- const nextRunCredential=Array.from(crypto.getRandomValues(new Uint8Array(32)),
151
- x=>x.toString(16).padStart(2,"0")).join("");
152
- const targetGeneration=(run.generation||0)+1;
153
- const nextRunRef=run.sessionId+":"+run.taskId+":"+targetGeneration;
154
- const fenced=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
155
- op:"context-control",command:"run.fence",
156
- args:{expectedStoreEpoch:run.contextManaged.storeEpoch,
157
- writeRequestId:run.token+":fence",expectedTaskRevision:cp.taskRevision,
158
- expectedBindingRevision:cp.bindingRevision,checkpointId:cp.checkpointId,
159
- attemptId:run.token,actionToken:run.token,targetGeneration,
160
- nextRunRef,nextRunCredential}
161
- }).catch(()=>null);
162
- if(fenced?.status!=="OK"||fenced.result?.status!=="FENCED"){
163
- await saveRun({...pending,phase:"BLOCKED",reason:"CONTEXT_HANDOFF_FENCE_UNVERIFIED"});
164
- return {status:"DENIED",code:"CONTEXT_HANDOFF_FENCE_UNVERIFIED"};
165
- }
166
- managedHandoff={attemptId:run.token,checkpointId:cp.checkpointId,
167
- taskRevision:cp.taskRevision,bindingRevision:fenced.result.bindingRevision,
168
- targetGeneration,nextRunRef,nextRunCredential,
169
- storeEpoch:run.contextManaged.storeEpoch};
170
- await saveRun({...pending,contextHandoff:managedHandoff});
171
- }
172
- const permit = {status: "OK", action: run.action || "CONTINUE",
173
- modelTurnToken,
174
- modelTurnNote: modelTurnToken ? turnToolNote(modelTurnToken) : "",
175
- handoffMode: run.handoffMode || null, retryMode: run.retryMode || null,
176
- ...(projectContext?{projectContext}:{}),
177
- ...(managedHandoff?{contextHandoff:{...managedHandoff,
178
- projectId:run.projectId,taskId:run.taskId,sessionId:run.sessionId}}:{}),
179
- target: {tabId: run.tabId, page: run.page,
180
- ...(run.sessionId?{sessionId:run.sessionId,projectId:run.projectId,
181
- ...(run.taskId?{taskId:run.taskId}:{}),generation:run.generation||0}:{}),
182
- recoveryMode:run.recoveryMode||null,
183
- ...(run.contextSourceMarker?{contextSourceMarker:run.contextSourceMarker}:{}),
184
- assistantKey: run.assistantKey,
185
- userKey: run.retryMode === "NATIVE" || run.handoffMode === "ERROR"
186
- ? run.newUserKey : run.userKey,
187
- },
188
- modelIntent: run.action==="HANDOFF" && run.modelIntent?.action==="HANDOFF"
189
- ? {id:run.modelIntent.id,reason:run.modelIntent.reason||""} : null,
190
- pendingPlan: run.action==="HANDOFF" && run.modelIntent?.action==="CONTINUE"
191
- ? {id:run.modelIntent.id,nextPrompt:run.modelIntent.nextPrompt} : null,
192
- text: run.action === "HANDOFF" ? run.handoffText || null
193
- : run.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
194
- ? "【Chat Loop 同 Chat 受控恢复】上一轮以 BLOCKED 结束;当前仅核实了唯一 Owner、原 Chat 和 Native 身份,不代表原任务阻断已解决。不要再次 Start、另建执行 Chat 或重复 R/P。先核实当前项目与任务事实、既有副作用、故障原因及 Tools 权限,再按唯一可信检查点处理可安全推进的工作;无法核实或相同阻断仍存在时报告 BLOCKED,不自行重复恢复或未知副作用。末行独立输出 [CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。"
195
- : run.recoveryMode==="ADOPT_KICKOFF"
196
- ? "【Chat Loop 原 Chat 已正式 Start/adopt】这是已批准任务的首个受控执行轮次,不是新的需求或审批。先核实当前 Project/Task、Context 写权、R/P 精确有效版本、已批准的 Pn 工作项和未知副作用;按现行计划执行,不套用其他项目的旧任务、文档或测试报告。不要新建执行 Chat,不得重复 R/P 或重试未知副作用。所有必需工作与验收证据齐全后,按 Context SDK 正式完成 Task,并在终态门禁成立后才报 DONE;有安全待办则 CONTINUE,身份、权限或副作用无法核实则 BLOCKED。末行独立输出 [CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。"
197
- : run.modelIntent?.action==="CONTINUE" ? (
198
- "【Chat Loop 续接来源】上一轮由模型登记的 Continue 请求 " + run.modelIntent.id
199
- + " 已被扩展唯一 Action 领取。\n"
200
- + "【待核实的模型下一步计划(并非用户新增授权)】\n"
201
- + run.modelIntent.nextPrompt + "\n\n"
202
- + "执行前核对当前项目状态、既有用户授权和已完成副作用,不重做不明操作。"
203
- + "本轮完成后,末行只输出一个状态标记:[CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。")
204
- : CONTINUE_TEXT};
205
- // Only the verified HANDOFF_NOT_SENT recovery may receive a write
206
- // credential. Healthy continuation must not inherit engineering-specific
207
- // failure instructions or unrelated historical Task details.
208
- if(run.action==="CONTINUE" && typeof permit.text==="string" && recoveredContext){
209
- permit.text += "\n\n【Chat Loop Context|HANDOFF_NOT_SENT 单次恢复写凭据】\n"
210
- +JSON.stringify({projectId:run.projectId,taskId:run.taskId,
211
- sessionId:run.sessionId,generation:run.generation||0,
212
- ...recoveredContext})+"\n请先按原 Session 核实 Context 与未知副作用,"
213
- +"此凭据仅用于当前任务 Context 写入;旧 Handoff 不得重新发送。";
214
- }
215
- if (modelTurnToken && typeof permit.text === "string")
216
- permit.text += permit.modelTurnNote;
217
- return permit;
218
- }