@tomflow/chatloop-tools 0.9.44 → 0.9.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/bin/cli.mjs +12 -5
- package/index.mjs +59 -12
- package/lib/adapters/mcp-child.mjs +142 -30
- package/lib/adapters/tunnel.mjs +22 -11
- package/lib/context-control-auth.mjs +0 -5
- package/lib/context-gateway.mjs +14 -1
- package/lib/control.mjs +27 -8
- package/lib/extension-cli-contract.mjs +5 -3
- package/lib/extension-proxy.mjs +80 -10
- package/lib/gateway.mjs +20 -8
- package/lib/release-health-checks.mjs +49 -12
- package/lib/release-owner-preflight.mjs +1 -2
- package/lib/release-upgrade.mjs +6 -2
- package/lib/release.mjs +27 -6
- package/lib/supervisor-observability.mjs +2 -2
- package/lib/supervisor-runtime.mjs +96 -33
- package/lib/trace-gateway.mjs +64 -42
- package/lib/tunnel.mjs +15 -5
- package/node_modules/@tomflow/chatloop-context/README.md +2 -2
- package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +1 -1
- package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +1 -1
- package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +1 -1
- package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +2 -7
- package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +3 -1
- package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +8 -3
- package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +13 -7
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +12 -8
- package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +20 -3
- package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +8 -4
- package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +5 -3
- package/node_modules/@tomflow/chatloop-context/package.json +3 -3
- package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +14 -6
- package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +26 -7
- package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +6 -3
- package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +5 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +22 -4
- package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +19 -4
- package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +4 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +11 -3
- package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +2 -1
- package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +11 -3
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +10 -9
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +1 -1
- package/node_modules/@tomflow/chatloop-extension/extension/popup.js +9 -3
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +2 -2
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +8 -10
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +7 -2
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +2 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +7 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +16 -5
- package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +5 -7
- package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +12 -3
- package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +35 -21
- package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +11 -6
- package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +11 -3
- package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +39 -5
- package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +5 -1
- package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +5 -1
- package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +27 -3
- package/node_modules/@tomflow/chatloop-extension/package.json +2 -2
- package/node_modules/@tomflow/chatloop-trace/README.md +7 -2
- package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +66 -36
- package/node_modules/@tomflow/chatloop-trace/lib/trace-retention.mjs +17 -4
- package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +30 -6
- package/node_modules/@tomflow/chatloop-trace/package.json +1 -1
- package/package.json +9 -9
- package/providers/context.mjs +5 -1
- package/providers/desktop.mjs +23 -6
- package/providers/document.mjs +5 -3
- package/providers/extension.mjs +6 -4
- package/providers/form.mjs +5 -3
- package/providers/runtime.mjs +14 -6
- package/providers/trace.mjs +3 -2
|
@@ -55,7 +55,7 @@ async function onTake(message, sender) {
|
|
|
55
55
|
const snapshot=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
56
56
|
op:"context-control",command:"run.snapshot",args:{}}).catch(()=>null);
|
|
57
57
|
const cp=snapshot?.result;
|
|
58
|
-
if(snapshot?.status!=="OK" || cp.taskRevision!==h.taskRevision
|
|
58
|
+
if(snapshot?.status!=="OK" || !cp || cp.taskRevision!==h.taskRevision
|
|
59
59
|
||cp.bindingRevision!==h.bindingRevision ||cp.runRef!==null
|
|
60
60
|
||cp.checkpointId!==h.checkpointId ||cp.unknownEffectCount!==0){
|
|
61
61
|
await saveRun({...run,phase:"BLOCKED",reason:"CONTEXT_RESTORE_SNAPSHOT_UNVERIFIED"});
|
|
@@ -191,9 +191,9 @@ async function onTake(message, sender) {
|
|
|
191
191
|
? {id:run.modelIntent.id,nextPrompt:run.modelIntent.nextPrompt} : null,
|
|
192
192
|
text: run.action === "HANDOFF" ? run.handoffText || null
|
|
193
193
|
: run.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
|
|
194
|
-
? "【Chat Loop 同 Chat 受控恢复】上一轮以 BLOCKED
|
|
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
195
|
: run.recoveryMode==="ADOPT_KICKOFF"
|
|
196
|
-
? "【Chat Loop 原 Chat 已正式 Start/adopt
|
|
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
197
|
: run.modelIntent?.action==="CONTINUE" ? (
|
|
198
198
|
"【Chat Loop 续接来源】上一轮由模型登记的 Continue 请求 " + run.modelIntent.id
|
|
199
199
|
+ " 已被扩展唯一 Action 领取。\n"
|
|
@@ -202,17 +202,15 @@ async function onTake(message, sender) {
|
|
|
202
202
|
+ "执行前核对当前项目状态、既有用户授权和已完成副作用,不重做不明操作。"
|
|
203
203
|
+ "本轮完成后,末行只输出一个状态标记:[CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。")
|
|
204
204
|
: CONTINUE_TEXT};
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
permit.text += "\n\n【Chat Loop Context|HANDOFF_NOT_SENT 单次恢复写凭据】\n"
|
|
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"
|
|
211
210
|
+JSON.stringify({projectId:run.projectId,taskId:run.taskId,
|
|
212
211
|
sessionId:run.sessionId,generation:run.generation||0,
|
|
213
212
|
...recoveredContext})+"\n请先按原 Session 核实 Context 与未知副作用,"
|
|
214
213
|
+"此凭据仅用于当前任务 Context 写入;旧 Handoff 不得重新发送。";
|
|
215
|
-
}
|
|
216
214
|
}
|
|
217
215
|
if (modelTurnToken && typeof permit.text === "string")
|
|
218
216
|
permit.text += permit.modelTurnNote;
|
|
@@ -48,9 +48,14 @@ async function sessionStartPrepare(message,sender){
|
|
|
48
48
|
return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
|
|
49
49
|
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
|
|
50
50
|
if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const ownerMatches=Boolean(prior?.sessionId&&disk.session
|
|
52
|
+
&&matchesNativeProjection(sessionProjection(prior),disk.session));
|
|
53
|
+
if(matchingBlocked&&!ownerMatches)
|
|
53
54
|
return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
|
|
55
|
+
// A terminal Worker record cannot authorize a new Start if a different
|
|
56
|
+
// durable Native Owner exists under the same Browser installation.
|
|
57
|
+
if(prior?.phase==='DONE'&&prior.sessionId&&disk.session&&!ownerMatches)
|
|
58
|
+
return {status:'DENIED',code:'SESSION_OWNER_MISMATCH'};
|
|
54
59
|
// An abandoned Managed Context writer can outlive its Browser Owner.
|
|
55
60
|
// Replacing the Native session without first verifying its terminal fence
|
|
56
61
|
// would strand a live runRef (and an old write credential) in the Store.
|
|
@@ -142,7 +142,8 @@ async function onAdoptBaselineRepair(message,sender){
|
|
|
142
142
|
return {status:'DENIED',code:'ADOPT_BASELINE_OBSERVER_UNVERIFIED'};
|
|
143
143
|
await saveRun({...prior,phase:'RESERVED',
|
|
144
144
|
reason:'ADOPT_BASELINE_RECOVERY',
|
|
145
|
-
recoveryMode:'ADOPT_IDLE_BASELINE',recoveryAttempts:1
|
|
145
|
+
recoveryMode:'ADOPT_IDLE_BASELINE',recoveryAttempts:1,
|
|
146
|
+
recoveryExpectedNativeAt:disk.session.updatedAt});
|
|
146
147
|
const clean={...prior,phase:'WAITING_REPLY',reason:'ADOPTED_IDLE_BASELINE',
|
|
147
148
|
recoveryAttempts:1,userKey:prior.newUserKey,assistantKey:prior.assistantKey};
|
|
148
149
|
delete clean.recoveryMode;
|
|
@@ -43,7 +43,13 @@ async function sessionStartResult(message,sender){
|
|
|
43
43
|
// Four-hour execution clock begins at confirmed enrollment, not at
|
|
44
44
|
// the UI approval or potentially long Start readiness/preparation.
|
|
45
45
|
const adoptedIdle=confirmed&&adopted&&!!run.adoptPostApprovalAssistantKey;
|
|
46
|
-
const next={...run,
|
|
46
|
+
const next={...run,
|
|
47
|
+
// Protect the crash window between a confirmed browser send and Native
|
|
48
|
+
// run.bind.initial. This marks the session as Context-governed, NOT as
|
|
49
|
+
// successfully bound; subsequent DONE/Continue must verify the real Store.
|
|
50
|
+
...(confirmed&&run.contextLeaseRef
|
|
51
|
+
?{contextManaged:{storeEpoch:run.contextStoreEpoch}}:{}),
|
|
52
|
+
phase:confirmed?'WAITING_REPLY':'BLOCKED',
|
|
47
53
|
startedAt:confirmed?Date.now():run.startedAt,
|
|
48
54
|
lastStartActionTabId:sender.tab.id,
|
|
49
55
|
...(adoptedIdle?{assistantKey:run.adoptPostApprovalAssistantKey,
|
|
@@ -4,10 +4,16 @@ const RUN_KEY = "chat-loop.action.run.v1";
|
|
|
4
4
|
const SESSION_HOST = "com.tomflow.chatloop.extension";
|
|
5
5
|
const ALARM_NAME = "chat-loop.turn-watch.v1";
|
|
6
6
|
const DEADLINE_ALARM_NAME = "chat-loop.handoff-deadline.v1";
|
|
7
|
-
const
|
|
8
|
-
const CONTINUE_TEXT = "继续当前任务,完成本轮后只在末行写一个状态:[CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。";
|
|
7
|
+
const CONTINUE_TEXT = "继续当前已授权任务,先核实真实进度、权限和已发生副作用;UNKNOWN 只查原回执,不盲目重试,也不把续接视为新增授权。完成本轮后末行只写一个状态:[CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。";
|
|
9
8
|
const turnToolNote = token => "\n\n【Chat Loop 本轮工具凭证】只有本轮需要自定下一轮内容或提前交接时,才能调用 chat_loop_extension__continue / chat_loop_extension__handoff;参数 turnToken 填写 " + token + "。工具只登记意图,不等待本轮结束,不直接发送;请照常在本轮结束时输出 CONTINUE、DONE 或 BLOCKED 标记。不要在助手正文重复该凭证。";
|
|
10
9
|
let queue = Promise.resolve();
|
|
10
|
+
// Business callbacks expose typed, bounded error codes only; raw messages can
|
|
11
|
+
// contain native paths, browser state or extension internals.
|
|
12
|
+
const safeWorkerErrorCode=(failure,fallback)=>{
|
|
13
|
+
const code=failure?.code||failure?.message;
|
|
14
|
+
return typeof code==='string'&&/^[A-Z][A-Z0-9_]{1,95}$/.test(code)
|
|
15
|
+
?code:fallback;
|
|
16
|
+
};
|
|
11
17
|
const serial = fn => {
|
|
12
18
|
const work = queue.then(fn);
|
|
13
19
|
queue = work.catch(() => {});
|
|
@@ -84,6 +90,9 @@ async function saveRun(run) {
|
|
|
84
90
|
const recoveryCommit=next.sessionId&&next.phase==="RESERVED"
|
|
85
91
|
&&["TOOL_PREFLIGHT_REPAIRED","HANDOFF_NOT_SENT","ADOPT_IDLE_BASELINE"].includes(next.recoveryMode)
|
|
86
92
|
&&next.recoveryAttempts>=1&&stored?.phase==="BLOCKED";
|
|
93
|
+
if(recoveryCommit&&(!Number.isSafeInteger(next.recoveryExpectedNativeAt)
|
|
94
|
+
||next.recoveryExpectedNativeAt<=0))
|
|
95
|
+
throw Error('SESSION_RECOVERY_CAS_MISSING');
|
|
87
96
|
const syncNative=async()=>{
|
|
88
97
|
if(!next.sessionId)return;
|
|
89
98
|
const record=sessionProjection(next);
|
|
@@ -92,9 +101,11 @@ async function saveRun(run) {
|
|
|
92
101
|
...(next.replacedBlockedSessionId&&!recoveryCommit&&next.phase==='STARTING'
|
|
93
102
|
?{replaceBlockedSessionId:next.replacedBlockedSessionId}:{}),
|
|
94
103
|
...(recoveryCommit?{resumeBlockedSessionId:next.sessionId,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
resumeBlockedUpdatedAt:next.recoveryExpectedNativeAt}:{})}).catch(()=>null);
|
|
105
|
+
// Native acknowledgment must match the whole immutable Owner pointer,
|
|
106
|
+
// not merely its sessionId and phase. updatedAt is CAS metadata, not
|
|
107
|
+
// part of this identity projection.
|
|
108
|
+
if(saved?.status!=="OK"||!matchesNativeProjection(record,saved.session))
|
|
98
109
|
throw Error(saved?.code||"SESSION_PERSISTENCE_UNVERIFIED");
|
|
99
110
|
};
|
|
100
111
|
// A terminal BLOCKED session may resume only after native CAS first.
|
|
@@ -116,18 +116,17 @@ async function onManualPrepare(message, sender) {
|
|
|
116
116
|
|| !/目标/.test(summary) || !/已完成|进度/.test(summary)
|
|
117
117
|
|| !/下一步|待办/.test(summary)))
|
|
118
118
|
return {status: "DENIED", code: "HANDOFF_PACKET_MISSING"};
|
|
119
|
+
let recoveryExpectedNativeAt=null;
|
|
119
120
|
if(ownedRecovery){
|
|
120
121
|
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
121
122
|
{op:"session-read"}).catch(()=>null);
|
|
122
|
-
if(disk?.status!=="OK"
|
|
123
|
-
|
|
124
|
-
||disk.session.projectId!==previous.projectId
|
|
125
|
-
||disk.session.generation!==(previous.generation||0)
|
|
126
|
-
||disk.session.activeChatId!==chatIdOf(tab.url)
|
|
123
|
+
if(disk?.status!=="OK"
|
|
124
|
+
||!matchesNativeProjection(sessionProjection(previous),disk.session)
|
|
127
125
|
||resumeAt&&disk.session.updatedAt!==resumeAt
|
|
128
126
|
||contextAt&&disk.session.updatedAt!==contextAt
|
|
129
127
|
||legacyAt&&(!legacyUnsent||disk.session.updatedAt!==legacyAt))
|
|
130
128
|
return {status:"DENIED",code:"BLOCKED_OWNER_PERSISTENCE_UNVERIFIED"};
|
|
129
|
+
recoveryExpectedNativeAt=disk.session.updatedAt;
|
|
131
130
|
}
|
|
132
131
|
const token = crypto.randomUUID();
|
|
133
132
|
await saveRun({...(ownedRecovery?previous:{}),
|
|
@@ -137,8 +136,7 @@ async function onManualPrepare(message, sender) {
|
|
|
137
136
|
manualActionTabId: sender.tab.id,
|
|
138
137
|
...(ownedRecovery?{recoveryMode:contextNotSent?"HANDOFF_NOT_SENT":"TOOL_PREFLIGHT_REPAIRED",
|
|
139
138
|
recoveryAttempts:(previous.recoveryAttempts||0)+1,recoveryProtocol:1,
|
|
140
|
-
|
|
141
|
-
?{recoveryExpectedNativeAt:contextAt||resumeAt||legacyAt}:{}),
|
|
139
|
+
recoveryExpectedNativeAt,
|
|
142
140
|
...(contextNotSent?{contextSourceMarker:"[CHAT_LOOP_STATUS:"+modelStatus+"]",
|
|
143
141
|
contextRecoveryCredential:Array.from(crypto.getRandomValues(new Uint8Array(32)),
|
|
144
142
|
x=>x.toString(16).padStart(2,"0")).join(""),
|
|
@@ -79,7 +79,7 @@ const onBrowserMessage=(message, sender, reply, dispatchParent=null) => {
|
|
|
79
79
|
let result;
|
|
80
80
|
try{result=await handle(type==='CHAT_LOOP_SESSION_STATUS_V1'
|
|
81
81
|
?{...message,auditDispatchParent:dispatchParent}:message,sender);}
|
|
82
|
-
catch(error){result={status:'BLOCKED',code:error
|
|
82
|
+
catch(error){result={status:'BLOCKED',code:safeWorkerErrorCode(error,'SCHEDULER_ERROR')};}
|
|
83
83
|
// A bounded diagnostic receipt, never permission or a second state store.
|
|
84
84
|
// In particular a rejected manual recovery must be observable remotely.
|
|
85
85
|
if(type==='CHAT_LOOP_ACTION_MANUAL_PREPARE_V1'){
|
|
@@ -89,7 +89,7 @@ const onBrowserMessage=(message, sender, reply, dispatchParent=null) => {
|
|
|
89
89
|
code:/^[A-Z0-9_]{1,100}$/.test(result.code||'')?result.code:null,at:Date.now()}}});
|
|
90
90
|
}
|
|
91
91
|
return result;
|
|
92
|
-
}).then(reply,error=>reply({status:'BLOCKED',code:error
|
|
92
|
+
}).then(reply,error=>reply({status:'BLOCKED',code:safeWorkerErrorCode(error,'SCHEDULER_ERROR')}));
|
|
93
93
|
return true;
|
|
94
94
|
}
|
|
95
95
|
if (type === 'CHAT_LOOP_POPUP_CLEAN_OPEN_V1') {
|
|
@@ -104,6 +104,7 @@ const onBrowserMessage=(message, sender, reply, dispatchParent=null) => {
|
|
|
104
104
|
}
|
|
105
105
|
if (type !== "CHAT_LOOP_EYE_RELOAD_V1") return false;
|
|
106
106
|
const id = sender.tab?.id;
|
|
107
|
+
let acknowledged=false;
|
|
107
108
|
void (async () => {
|
|
108
109
|
try {
|
|
109
110
|
if (!Number.isInteger(id)) throw Error("NO_ACTION_TAB");
|
|
@@ -113,6 +114,9 @@ const onBrowserMessage=(message, sender, reply, dispatchParent=null) => {
|
|
|
113
114
|
(tab.url!==reloadBase &&
|
|
114
115
|
!/^\?requestId=[a-f0-9]{32}$/.test(tab.url.slice(reloadBase.length))))
|
|
115
116
|
throw Error("INVALID_RELOAD_SOURCE");
|
|
117
|
+
// Acknowledgement is deliberately not a verified reload result.
|
|
118
|
+
// Once sent, never issue a second contradictory callback.
|
|
119
|
+
acknowledged=true;
|
|
116
120
|
reply({status: "ACCEPTED"});
|
|
117
121
|
await chrome.tabs.remove(id);
|
|
118
122
|
// Reload terminates pending MV3 Native Messaging Promises immediately.
|
|
@@ -129,7 +133,12 @@ const onBrowserMessage=(message, sender, reply, dispatchParent=null) => {
|
|
|
129
133
|
}
|
|
130
134
|
}catch{/* Audit cannot change the accepted business result. */}
|
|
131
135
|
chrome.runtime.reload();
|
|
132
|
-
} catch (error) {
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if(!acknowledged)
|
|
138
|
+
reply({status: "FAILED", code: safeWorkerErrorCode(error,'RELOAD_UNVERIFIED')});
|
|
139
|
+
// After ACCEPTED, the caller retains ACCEPTED_UNVERIFIED and must
|
|
140
|
+
// recheck the same extension instance; no automatic replay.
|
|
141
|
+
}
|
|
133
142
|
})();
|
|
134
143
|
return true;
|
|
135
144
|
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// Chat Loop Worker — scheduler. Imported in order by background.js; no independent Browser Owner.
|
|
2
2
|
// Extension updates invalidate previous injected listeners. Reconnect only its own observers.
|
|
3
|
+
// A detached alarm/reconnect must settle its own failure, not create a
|
|
4
|
+
// second scheduler or implicitly repeat a browser Action.
|
|
5
|
+
const observeBackground=(work,scope)=>{
|
|
6
|
+
void work.catch(error=>console.warn('CHAT_LOOP_SCHEDULER_UNVERIFIED',
|
|
7
|
+
scope,safeWorkerErrorCode(error,'SCHEDULER_ERROR')));
|
|
8
|
+
};
|
|
3
9
|
async function reconnectOpenChats() {
|
|
4
10
|
const tabs = await chrome.tabs.query({url: "https://chatgpt.com/*"});
|
|
5
11
|
for (const tab of tabs) {
|
|
@@ -30,9 +36,14 @@ async function reconnectOpenChats() {
|
|
|
30
36
|
startedAt: owner.startedAt
|
|
31
37
|
}).catch(() => null);
|
|
32
38
|
if (res?.status !== "RESUMED" && res?.status !== "ALREADY_MONITORING")
|
|
33
|
-
console.warn("
|
|
39
|
+
console.warn("CHAT_LOOP_TURN_RESUME_UNVERIFIED",
|
|
40
|
+
safeWorkerErrorCode({code:res?.reason||res?.status},
|
|
41
|
+
"OBSERVER_RESUME_UNVERIFIED"));
|
|
34
42
|
}
|
|
35
|
-
} catch (error) {
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.warn("CHAT_LOOP_OBSERVER_RECONNECT_UNVERIFIED",
|
|
45
|
+
safeWorkerErrorCode(error,"OBSERVER_RECONNECT_UNVERIFIED"));
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
// MV3 background service workers can suspend, and hidden-page setInterval
|
|
@@ -85,47 +96,50 @@ async function watchActiveTurn() {
|
|
|
85
96
|
// A human response can fail after the previous question was kept in
|
|
86
97
|
// WAITING_REPLY. Do not let this become an indefinite silent wait.
|
|
87
98
|
if(freshHuman && proof.status==="BLOCKED") {
|
|
88
|
-
|
|
99
|
+
observeBackground(serial(()=>onTurnBlocked({page:run.page,userKey:proof.userKey,
|
|
89
100
|
reason:proof.reason||"PAGE_ERROR"},
|
|
90
|
-
{tab,url:tab.url}));
|
|
101
|
+
{tab,url:tab.url})),'HUMAN_TURN_RECOVERY');
|
|
91
102
|
}
|
|
92
103
|
// Alarm is still read-only. It may reconcile a verified page failure if
|
|
93
104
|
// the observer's original notification was lost while Worker slept.
|
|
94
105
|
if (run?.phase === "WAITING_REPLY" && run.tabId === tab.id
|
|
95
106
|
&& proof?.status === "BLOCKED" && ["PAGE_ERROR","CONTEXT_LIMIT","SECURITY_CHALLENGE"].includes(proof.reason)
|
|
96
107
|
&& proof.page === run.page && proof.userKey === run.newUserKey) {
|
|
97
|
-
|
|
108
|
+
observeBackground(serial(() => onTurnBlocked({page: run.page,
|
|
98
109
|
userKey: run.newUserKey, reason: proof.reason},
|
|
99
|
-
{tab, url: tab.url}));
|
|
110
|
+
{tab, url: tab.url})),'TURN_FAILURE_RECOVERY');
|
|
100
111
|
}
|
|
101
112
|
} catch { /* Observer unavailable; never infer Turn completion. */ }
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
115
|
chrome.alarms?.onAlarm?.addListener(alarm => {
|
|
105
|
-
if (alarm?.name === ALARM_NAME)
|
|
116
|
+
if (alarm?.name === ALARM_NAME)
|
|
117
|
+
observeBackground(watchActiveTurn(),'TURN_WATCH_ALARM');
|
|
106
118
|
if (alarm?.name === DEADLINE_ALARM_NAME)
|
|
107
|
-
|
|
119
|
+
observeBackground(serial(prepareHandoffIfDue),'HANDOFF_DEADLINE_ALARM');
|
|
108
120
|
});
|
|
109
121
|
chrome.runtime.onInstalled?.addListener(() => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
await resources.reconcile(await readRun()).catch(()=>{});})
|
|
113
|
-
|
|
122
|
+
observeBackground(ensureAlarm(),'ALARM_SETUP');
|
|
123
|
+
observeBackground(serial(async()=>{await expireStaleAction();
|
|
124
|
+
await resources.reconcile(await readRun()).catch(()=>{});}),
|
|
125
|
+
'INSTALL_RECONCILIATION');
|
|
126
|
+
observeBackground(reconnectOpenChats(),'CHAT_RECONNECT');
|
|
114
127
|
});
|
|
115
128
|
chrome.runtime.onStartup?.addListener(() => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
await resources.reconcile(await readRun()).catch(()=>{});})
|
|
119
|
-
|
|
129
|
+
observeBackground(ensureAlarm(),'ALARM_SETUP');
|
|
130
|
+
observeBackground(serial(async()=>{await expireStaleAction();
|
|
131
|
+
await resources.reconcile(await readRun()).catch(()=>{});}),
|
|
132
|
+
'INSTALL_RECONCILIATION');
|
|
133
|
+
observeBackground(reconnectOpenChats(),'CHAT_RECONNECT');
|
|
120
134
|
});
|
|
121
|
-
|
|
135
|
+
observeBackground(ensureAlarm(),'ALARM_SETUP');
|
|
122
136
|
// Reconcile an elapsed deadline after MV3 Worker suspension/reload.
|
|
123
|
-
|
|
137
|
+
observeBackground(serial(async()=>{await expireStaleAction();
|
|
124
138
|
await resources.reconcile(await readRun()).catch(()=>{});
|
|
125
|
-
await prepareHandoffIfDue();});
|
|
139
|
+
await prepareHandoffIfDue();}),'STARTUP_RECONCILIATION');
|
|
126
140
|
// A manual extension Reload does not necessarily fire onInstalled/onStartup.
|
|
127
141
|
// Reattach the two idempotent read-only scripts to existing ChatGPT tabs.
|
|
128
|
-
|
|
142
|
+
observeBackground(reconnectOpenChats(),'CHAT_RECONNECT');
|
|
129
143
|
// User-clicked popup Clean must share the same Action quota as Worker actions.
|
|
130
144
|
// The popup cannot create extra Chrome tabs directly.
|
|
131
145
|
async function openPopupClean(message,sender) {
|
|
@@ -142,6 +156,6 @@ async function openPopupClean(message,sender) {
|
|
|
142
156
|
+'?tabId='+target.id,windowId:target.windowId,active:true});
|
|
143
157
|
return {status:'OK',actionTabId:action.id};
|
|
144
158
|
} catch(error) {
|
|
145
|
-
return {status:'BLOCKED',code:error
|
|
159
|
+
return {status:'BLOCKED',code:safeWorkerErrorCode(error,'CLEAN_ACTION_UNVERIFIED')};
|
|
146
160
|
}
|
|
147
161
|
}
|
|
@@ -23,6 +23,14 @@ async function onTurnFinished(message, sender) {
|
|
|
23
23
|
return {status: "IGNORED", code: "ALREADY_HANDLED"};
|
|
24
24
|
if (previous.phase !== "WAITING_REPLY")
|
|
25
25
|
return {status: "IGNORED", code: "INVALID_PHASE"};
|
|
26
|
+
// Previous extension versions may have persisted a confirmed first send
|
|
27
|
+
// before recording whether its Context bind completed. Do not downgrade
|
|
28
|
+
// such an Owner to unmanaged execution on Worker restart or upgrade.
|
|
29
|
+
if(previous.contextLeaseRef&&!previous.contextManaged){
|
|
30
|
+
await saveRun({...previous,phase:'BLOCKED',
|
|
31
|
+
reason:'CONTEXT_INITIAL_BIND_UNVERIFIED'});
|
|
32
|
+
return {status:'BLOCKED',code:'CONTEXT_INITIAL_BIND_UNVERIFIED'};
|
|
33
|
+
}
|
|
26
34
|
// A clicked ChatGPT choice creates a regular NEW user Turn. Its preceding
|
|
27
35
|
// assistant must be the exact already-handled question from this Owner, with
|
|
28
36
|
// no intervening user messages. This keeps the old identity boundary
|
|
@@ -169,7 +177,7 @@ async function onTurnFinished(message, sender) {
|
|
|
169
177
|
return {status: "QUEUED", actionTabId: actionTab.id};
|
|
170
178
|
} catch (error) {
|
|
171
179
|
await saveRun({...recorded, phase: "BLOCKED", reason: "ACTION_PAGE_CREATE_FAILED"});
|
|
172
|
-
return {status: "BLOCKED", code: error
|
|
180
|
+
return {status: "BLOCKED", code: safeWorkerErrorCode(error,"ACTION_PAGE_CREATE_FAILED")};
|
|
173
181
|
}
|
|
174
182
|
}
|
|
175
183
|
// Recover ONLY an interrupted pre-send reservation from the old Worker
|
|
@@ -185,11 +193,8 @@ async function repairUncommittedBlockedRecovery(){
|
|
|
185
193
|
return run;
|
|
186
194
|
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
187
195
|
{op:"session-read"}).catch(()=>null);
|
|
188
|
-
if(disk?.status!=="OK"
|
|
189
|
-
|
|
190
|
-
||disk.session.projectId!==run.projectId
|
|
191
|
-
||disk.session.generation!==(run.generation||0)
|
|
192
|
-
||disk.session.activeChatId!==chatIdOf("https://chatgpt.com"+run.page))
|
|
196
|
+
if(disk?.status!=="OK"
|
|
197
|
+
||!matchesNativeProjection(sessionProjection({...run,phase:"BLOCKED"}),disk.session))
|
|
193
198
|
return run;
|
|
194
199
|
const restored={...run,phase:"BLOCKED",reason:"BLOCKED",recoveryAttempts:0};
|
|
195
200
|
for(const field of ["recoveryMode","recoverySourceAssistantKey","token",
|
|
@@ -10,9 +10,9 @@ export function createOrderedApiObservationSender(deliver,{parallel=8,capacity=2
|
|
|
10
10
|
function pump(){
|
|
11
11
|
scheduled=false;
|
|
12
12
|
while(running<parallel){
|
|
13
|
-
const position=waiting.findIndex(({
|
|
13
|
+
const position=waiting.findIndex(({callId})=>!active.has(callId));
|
|
14
14
|
if(position<0)return;
|
|
15
|
-
const [{record,resolve}]=waiting.splice(position,1),id=
|
|
15
|
+
const [{record,callId,resolve}]=waiting.splice(position,1),id=callId;
|
|
16
16
|
running++;active.add(id);
|
|
17
17
|
let success=false;
|
|
18
18
|
Promise.resolve().then(()=>deliver(record)).then(result=>{
|
|
@@ -36,12 +36,20 @@ export function createOrderedApiObservationSender(deliver,{parallel=8,capacity=2
|
|
|
36
36
|
}
|
|
37
37
|
function send(record){
|
|
38
38
|
health.submitted++;
|
|
39
|
+
// A malformed telemetry record must not throw later inside an unhandled
|
|
40
|
+
// queueMicrotask or mutate its ordering key after being queued.
|
|
41
|
+
let callId;
|
|
42
|
+
try{callId=record?.callId}catch{}
|
|
43
|
+
if(typeof callId!=='string'||!callId||callId.length>128){
|
|
44
|
+
health.dropped++;health.lastFailureCode='OBSERVATION_INVALID';
|
|
45
|
+
return Promise.resolve(false);
|
|
46
|
+
}
|
|
39
47
|
if(waiting.length>=capacity){
|
|
40
48
|
health.dropped++;
|
|
41
49
|
health.lastFailureCode='OBSERVATION_QUEUE_FULL';
|
|
42
50
|
return Promise.resolve(false);
|
|
43
51
|
}
|
|
44
|
-
return new Promise(resolve=>{waiting.push({record,resolve});schedule()});
|
|
52
|
+
return new Promise(resolve=>{waiting.push({record,callId,resolve});schedule()});
|
|
45
53
|
}
|
|
46
54
|
return Object.freeze({send,
|
|
47
55
|
health:()=>Object.freeze({...health,pending:waiting.length,inFlight:running})});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {randomUUID} from 'node:crypto';
|
|
2
|
-
import {existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync,
|
|
2
|
+
import {existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync} from 'node:fs';
|
|
3
3
|
import {homedir, tmpdir} from 'node:os';
|
|
4
4
|
import {join} from 'node:path';
|
|
5
5
|
|
|
@@ -174,7 +174,9 @@ export function finish({id,nonce,action,status,payload='',code=null}) {
|
|
|
174
174
|
bytes=buf.length;
|
|
175
175
|
if(filename)writeFileSync(join(dir,filename),buf,{flag:'wx',mode:0o600});
|
|
176
176
|
}
|
|
177
|
-
const
|
|
177
|
+
const failureCode=typeof code==='string'&&/^[A-Z][A-Z0-9_]{1,95}$/.test(code)
|
|
178
|
+
?code:'ACTION_FAILED';
|
|
179
|
+
const rec={id,action,status,code:status==='FAILED'?failureCode:null,
|
|
178
180
|
path:filename?join(dir,filename):null,bytes,mimeType,at:Date.now(),
|
|
179
181
|
verified:action!=='reload'};
|
|
180
182
|
writeFileSync(resultPath+'.tmp',JSON.stringify(rec),{flag:'wx',mode:0o600});
|
|
@@ -182,11 +184,43 @@ export function finish({id,nonce,action,status,payload='',code=null}) {
|
|
|
182
184
|
return rec;
|
|
183
185
|
}
|
|
184
186
|
export function readResult(id) {
|
|
185
|
-
const
|
|
187
|
+
const dir=requestDir(id),p=join(dir,'result.json');
|
|
186
188
|
if(!pathEntryExists(p))return null;
|
|
187
|
-
privateDir(
|
|
189
|
+
privateDir(dir);
|
|
188
190
|
privateRecord(p,'UNTRUSTED_RESULT');
|
|
189
|
-
|
|
191
|
+
let rec;
|
|
192
|
+
try{rec=JSON.parse(readFileSync(p,'utf8'))}catch{
|
|
193
|
+
throw Object.assign(Error('Untrusted result'),{code:'UNTRUSTED_RESULT'});
|
|
194
|
+
}
|
|
195
|
+
const request=readRequest(id);
|
|
196
|
+
const expectedFile=request.action==='reload'?null:
|
|
197
|
+
request.action==='chat_screenshot'?'result.png':
|
|
198
|
+
request.action==='chat_dom'?'result.html':'result.txt';
|
|
199
|
+
const expectedMime=request.action==='chat_screenshot'?'image/png':
|
|
200
|
+
request.action==='chat_dom'?'text/html':'text/plain';
|
|
201
|
+
const invalid=()=>Object.assign(Error('Untrusted result'),{code:'UNTRUSTED_RESULT'});
|
|
202
|
+
if(!rec||typeof rec!=='object'||Array.isArray(rec)
|
|
203
|
+
||Object.keys(rec).some(k=>!['id','action','status','code','path',
|
|
204
|
+
'bytes','mimeType','at','verified'].includes(k))
|
|
205
|
+
||rec.id!==id||rec.action!==request.action
|
|
206
|
+
||!['OK','FAILED'].includes(rec.status)
|
|
207
|
+
||rec.verified!==(request.action!=='reload')
|
|
208
|
+
||!Number.isSafeInteger(rec.at)||rec.at<request.at||rec.at>request.expiresAt
|
|
209
|
+
||!Number.isSafeInteger(rec.bytes)||rec.bytes<0
|
|
210
|
+
||(rec.status==='FAILED'
|
|
211
|
+
?rec.path!==null||rec.mimeType!==null||rec.bytes!==0
|
|
212
|
+
||typeof rec.code!=='string'||!/^[A-Z][A-Z0-9_]{1,95}$/.test(rec.code)
|
|
213
|
+
:rec.code!==null||rec.mimeType!==expectedMime
|
|
214
|
+
||rec.path!==(expectedFile?join(dir,expectedFile):null)
|
|
215
|
+
||rec.bytes>(request.action==='chat_screenshot'?MAX_PNG:MAX_TEXT)))
|
|
216
|
+
throw invalid();
|
|
217
|
+
if(rec.status==='OK'&&expectedFile){
|
|
218
|
+
try{
|
|
219
|
+
privateRecord(rec.path,'UNTRUSTED_RESULT');
|
|
220
|
+
if(lstatSync(rec.path).size!==rec.bytes)throw invalid();
|
|
221
|
+
}catch{throw invalid()}
|
|
222
|
+
}
|
|
223
|
+
return rec;
|
|
190
224
|
}
|
|
191
225
|
export function cleanup(){
|
|
192
226
|
const root=tempRoot();
|
|
@@ -61,7 +61,11 @@ export async function nativeContextControl(command,args){
|
|
|
61
61
|
const reply=await ipc({...signed,action:'context-control',mac},6000);
|
|
62
62
|
if(reply.contract!==hello.contract||reply.requestId!==signed.requestId)
|
|
63
63
|
throw fail('CONTEXT_CONTROL_REPLY_INVALID');
|
|
64
|
-
if(reply.status!=='OK')
|
|
64
|
+
if(reply.status!=='OK'){
|
|
65
|
+
const code=reply.error?.code;
|
|
66
|
+
throw fail(typeof code==='string'&&/^[A-Z][A-Z0-9_]{1,95}$/.test(code)
|
|
67
|
+
?code:'CONTEXT_CONTROL_FAILED');
|
|
68
|
+
}
|
|
65
69
|
return reply.result;
|
|
66
70
|
}
|
|
67
71
|
|
|
@@ -14,6 +14,7 @@ export function configureOwnerEvidence(api){
|
|
|
14
14
|
const fail=code=>Object.assign(new Error(code),{code});
|
|
15
15
|
const ensure=(ok,code)=>{if(!ok)throw fail(code)};
|
|
16
16
|
const sha=raw=>createHash('sha256').update(raw).digest('hex');
|
|
17
|
+
const packageVersion=JSON.parse(readFileSync(new URL('../package.json',import.meta.url),'utf8')).version;
|
|
17
18
|
|
|
18
19
|
function checkedNative(){
|
|
19
20
|
const session=readSession();
|
|
@@ -38,7 +39,10 @@ function checkedExtensionIdle(){
|
|
|
38
39
|
encoding:'utf8',timeout:14000,maxBuffer:524288,stdio:['ignore','pipe','pipe']});
|
|
39
40
|
const rows=out.trim().split('\n').map(s=>JSON.parse(s));
|
|
40
41
|
const result=rows.findLast(x=>x.event==='RESULT');
|
|
41
|
-
ensure(result?.
|
|
42
|
+
ensure(result?.contract==='chat-loop.extension-cli.v1'
|
|
43
|
+
&&result.command==='extension status'
|
|
44
|
+
&&result.providerVersion===packageVersion
|
|
45
|
+
&&result.ok===true&&result.value?.verified===true
|
|
42
46
|
&&result.value?.truncated===false,'EXTENSION_STATUS_UNVERIFIED');
|
|
43
47
|
const v=JSON.parse(result.value.content||'{}');
|
|
44
48
|
ensure(v.status==='OK'&&v.state==='IDLE'
|
|
@@ -72,7 +72,9 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
72
72
|
// same-Chat, same-generation, one-shot recovery CAS. No new Chat,
|
|
73
73
|
// task, project, approval or Handoff may be smuggled into recovery.
|
|
74
74
|
if(replaceBlockedSessionId || !old || old.phase!=='BLOCKED'
|
|
75
|
-
|
|
75
|
+
||!Number.isSafeInteger(resumeBlockedUpdatedAt)
|
|
76
|
+
||resumeBlockedUpdatedAt<=0
|
|
77
|
+
||old.updatedAt!==resumeBlockedUpdatedAt
|
|
76
78
|
||old.sessionId!==resumeBlockedSessionId
|
|
77
79
|
||next.sessionId!==old.sessionId
|
|
78
80
|
||next.projectId!==old.projectId
|
|
@@ -94,6 +96,20 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
94
96
|
if(next.projectId!==old.projectId)throw fail('SESSION_PROJECT_CHANGED');
|
|
95
97
|
if(next.taskId!==old.taskId)throw fail('SESSION_TASK_CHANGED');
|
|
96
98
|
if(next.generation<old.generation)throw fail('SESSION_STALE_GENERATION');
|
|
99
|
+
// One verified Handoff advances exactly one generation. A skipped
|
|
100
|
+
// generation cannot become a durable Owner identity.
|
|
101
|
+
if(next.generation>old.generation+1)throw fail('SESSION_GENERATION_GAP');
|
|
102
|
+
if(next.generation===old.generation+1
|
|
103
|
+
&&(old.activeChatId===null||next.activeChatId===null
|
|
104
|
+
||next.activeChatId===old.activeChatId))
|
|
105
|
+
throw fail('SESSION_HANDOFF_IDENTITY_UNVERIFIED');
|
|
106
|
+
// A terminal session may be re-read or fenced, not reassigned to
|
|
107
|
+
// another Chat or generation under the same sessionId.
|
|
108
|
+
if(['DONE','BLOCKED'].includes(old.phase)
|
|
109
|
+
&&(next.generation!==old.generation
|
|
110
|
+
||next.activeChatId!==old.activeChatId
|
|
111
|
+
||next.activeChatUrl!==old.activeChatUrl))
|
|
112
|
+
throw fail('SESSION_TERMINAL_IDENTITY_CHANGED');
|
|
97
113
|
if(old.phase==='DONE'&&next.phase!=='DONE'||old.phase==='BLOCKED'
|
|
98
114
|
&& !['BLOCKED','DONE'].includes(next.phase)
|
|
99
115
|
&&!(resumeBlockedSessionId===old.sessionId
|
|
@@ -111,10 +127,18 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
111
127
|
&& ['sessionId','projectId','taskId','phase','generation',
|
|
112
128
|
'activeChatId','activeChatUrl'].every(key=>old[key]===next[key]))
|
|
113
129
|
return old;
|
|
130
|
+
// updatedAt is the Native recovery CAS value, not merely display time.
|
|
131
|
+
// Two Worker transitions can occur inside one millisecond. Every actual
|
|
132
|
+
// write must advance that version; an identical projection returned above
|
|
133
|
+
// deliberately keeps the previous value.
|
|
134
|
+
const committed=old&&next.updatedAt<=old.updatedAt
|
|
135
|
+
?{...next,updatedAt:old.updatedAt+1}:next;
|
|
136
|
+
if(!Number.isSafeInteger(committed.updatedAt))
|
|
137
|
+
throw fail('SESSION_CLOCK_EXHAUSTED');
|
|
114
138
|
const temp=join(dir,'.active-session-'+randomUUID()+'.tmp');
|
|
115
|
-
try{writeFileSync(temp,JSON.stringify(
|
|
139
|
+
try{writeFileSync(temp,JSON.stringify(committed,null,2)+'\n',{flag:'wx',mode:0o600});
|
|
116
140
|
renameSync(temp,file);
|
|
117
141
|
}catch(e){try{unlinkSync(temp);}catch{}throw e;}
|
|
118
|
-
return
|
|
142
|
+
return committed;
|
|
119
143
|
}finally{closeSync(fd);unlinkSync(lock);}
|
|
120
144
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-extension",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
".": "./index.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tomflow/chatloop-trace": "0.4.
|
|
36
|
+
"@tomflow/chatloop-trace": "0.4.6"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -92,8 +92,13 @@ read-only, never migrated into a new current receipt or permission.
|
|
|
92
92
|
|
|
93
93
|
The SDK verifies file owner, permissions, symlink safety and bounds event
|
|
94
94
|
and query sizes. Scoped readers stream logs up to 2 GiB without loading the
|
|
95
|
-
full JSONL file into memory;
|
|
96
|
-
|
|
95
|
+
full JSONL file into memory; individual lines are bounded to 8 KiB and
|
|
96
|
+
diagnostic deduplication is capped at 200,000 event IDs (excess fails closed,
|
|
97
|
+
never becomes a complete report). The Writer refuses to append or rotate a
|
|
98
|
+
file whose final JSONL record lacks its newline terminator, preserving torn
|
|
99
|
+
evidence instead of reporting a false write success. The default 30-day
|
|
100
|
+
retention keeps normal operational history within the read bound.
|
|
101
|
+
Diagnostics expose truncation, corrupted lines, writer
|
|
97
102
|
restarts, legacy records and pending receipts as **uncertainty**. They never
|
|
98
103
|
grant approval, Context write rights, Owner transfer or automatic retry.
|
|
99
104
|
A missing or interrupted Writer must be checked against the authoritative
|