@tomflow/chatloop-extension 0.3.54 → 0.3.56
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/bin/native-host.mjs +6 -2
- package/extension/actions/continue.js +2 -2
- package/extension/actions/handoff.js +6 -1
- package/extension/background.js +46 -12
- package/extension/loop/observer.js +23 -2
- package/extension/manifest.json +1 -1
- package/lib/context-binding.mjs +40 -0
- package/lib/session-file.mjs +8 -0
- package/package.json +1 -1
package/bin/native-host.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Chrome Native Messaging: one request per process, no persistent server.
|
|
3
|
-
import {readRequest, finish} from '../lib/bridge.mjs';
|
|
3
|
+
import {readRequest, finish, configFile} from '../lib/bridge.mjs';
|
|
4
4
|
import {readSession,writeSession} from '../lib/session-file.mjs';
|
|
5
|
+
import {registeredContext} from '../lib/context-binding.mjs';
|
|
5
6
|
const MAX_INPUT=48*1024*1024;
|
|
6
7
|
const write=obj=>{
|
|
7
8
|
const b=Buffer.from(JSON.stringify(obj)),len=Buffer.alloc(4);
|
|
@@ -26,7 +27,10 @@ process.stdin.on('data',chunk=>{
|
|
|
26
27
|
const r=finish(m);
|
|
27
28
|
write({status:'SAVED',id:r.id,action:r.action,bytes:r.bytes});
|
|
28
29
|
}else if(m.op==='session-read'){
|
|
29
|
-
|
|
30
|
+
const session=readSession();let projectContext=null,contextStatus='MISSING';
|
|
31
|
+
try{projectContext=session?registeredContext(session.projectId):null;
|
|
32
|
+
if(projectContext)contextStatus='VERIFIED';}catch{contextStatus='UNVERIFIED';}
|
|
33
|
+
write({status:'OK',session,contextConfigPath:configFile(),contextStatus,...(projectContext?{projectContext}:{})});
|
|
30
34
|
}else if(m.op==='session-sync'){
|
|
31
35
|
write({status:'OK',session:writeSession(m.session,
|
|
32
36
|
m.replaceBlockedSessionId,m.resumeBlockedSessionId,m.resumeBlockedUpdatedAt??null)});
|
|
@@ -184,12 +184,12 @@ async function run() {
|
|
|
184
184
|
const raw = params.get("tabId") || "";
|
|
185
185
|
let token = params.get("token") || "";
|
|
186
186
|
let tabId = Number(raw);
|
|
187
|
-
if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation")
|
|
187
|
+
if ([...params.keys()].some(k => k !== "tabId" && k !== "token" && k !== "repairLegacyReservation" && k !== "resumeBlockedAt")
|
|
188
188
|
|| [...params.keys()].length !== new Set(params.keys()).size)
|
|
189
189
|
throw Error("ACTION_PARAMETERS_INVALID");
|
|
190
190
|
if (raw && !/^[1-9][0-9]*$/.test(raw)
|
|
191
191
|
|| token && !/^[0-9a-f-]{36}$/.test(token)
|
|
192
|
-
|| token && (!raw||params.has("repairLegacyReservation"))) throw Error("ACTION_PARAMETERS_INVALID");
|
|
192
|
+
|| token && (!raw||params.has("repairLegacyReservation")||params.has("resumeBlockedAt"))) throw Error("ACTION_PARAMETERS_INVALID");
|
|
193
193
|
const own = await chrome.tabs.getCurrent();
|
|
194
194
|
if (!own?.id || own.url !== location.href) throw Error("ACTION_TAB_UNVERIFIED");
|
|
195
195
|
if (!token) {
|
|
@@ -278,7 +278,12 @@ async function run() {
|
|
|
278
278
|
}
|
|
279
279
|
if (observed?.contract !== "chat-loop.turn-observer.v1")
|
|
280
280
|
throw Error("NEW_CHAT_OBSERVER_UNAVAILABLE");
|
|
281
|
-
const
|
|
281
|
+
const contextReferences=permit.projectContext
|
|
282
|
+
?"\n\n【已核实的恢复入口|仅引用,不代表新增批准】\n"
|
|
283
|
+
+JSON.stringify(permit.projectContext)
|
|
284
|
+
+"\n先读取contextPath与taskDocPath,核实当前R/P有效版本、允许工作区和未知副作用;approvalDocPath如有仅是历史批准原文附件,不可替代当前任务有效性判断。"
|
|
285
|
+
:"";
|
|
286
|
+
const message = "你正在接手上一 Chat 未完成的任务。旧 Chat 的网页历史仍可核实,但当前 Chat 没有其隐式上下文。若为项目任务,先按已授权的项目 Skill 或目标仓库真实入口核实规则、进度和上一轮副作用;不要假定每个项目都有 AGENTS.md 或固定 context 目录,也不要重复未知副作用。\n\n交接资料:\n" + contextPacket + contextReferences
|
|
282
287
|
+ "\n\n本轮最终回复末行只能输出一个状态标记:[CHAT_LOOP_STATUS:CONTINUE]、[CHAT_LOOP_STATUS:DONE] 或 [CHAT_LOOP_STATUS:BLOCKED]。是否跨 Chat 由扩展决定,不要主动要求 Handoff。";
|
|
283
288
|
const notice=permit.modelIntent?.id
|
|
284
289
|
? "\n\n【扩展控制回执】本次交接由上一 Chat 的工具意图 "
|
package/extension/background.js
CHANGED
|
@@ -100,7 +100,7 @@ async function saveRun(run) {
|
|
|
100
100
|
const stored=await readRun();
|
|
101
101
|
const recoveryCommit=next.sessionId&&next.phase==="RESERVED"
|
|
102
102
|
&&next.recoveryMode==="TOOL_PREFLIGHT_REPAIRED"
|
|
103
|
-
&&next.recoveryAttempts
|
|
103
|
+
&&next.recoveryAttempts>=1&&stored?.phase==="BLOCKED";
|
|
104
104
|
const syncNative=async()=>{
|
|
105
105
|
if(!next.sessionId)return;
|
|
106
106
|
const record=sessionProjection(next);
|
|
@@ -396,6 +396,11 @@ async function sessionStatus(message,sender){
|
|
|
396
396
|
if(!run||run.phase==='DONE')return {status:'OK',state:'IDLE',
|
|
397
397
|
...(disk.session?{lastSession:disk.session}:{} )};
|
|
398
398
|
const record=sessionProjection(run);
|
|
399
|
+
// Native validates the private project binding; Status only forwards its
|
|
400
|
+
// read-only verified reference for the SAME active owner.
|
|
401
|
+
const projectContext=disk.contextStatus==='VERIFIED'
|
|
402
|
+
&&disk.projectContext?.projectId===run.projectId
|
|
403
|
+
?disk.projectContext:null;
|
|
399
404
|
if(record.activeChatId&&run.phase==='WAITING_REPLY'){
|
|
400
405
|
const tab=await chrome.tabs.get(run.tabId).catch(()=>null);
|
|
401
406
|
if(!tab||pathOf(tab.url)!==run.page)
|
|
@@ -406,7 +411,8 @@ async function sessionStatus(message,sender){
|
|
|
406
411
|
reason:run.reason||null,action:run.action||null,
|
|
407
412
|
userKey:run.userKey||null,assistantKey:run.assistantKey||null,
|
|
408
413
|
newUserKey:run.newUserKey||null,recoveryAttempts:run.recoveryAttempts||0,
|
|
409
|
-
|
|
414
|
+
...(projectContext?{projectContext}:{}),
|
|
415
|
+
recoveryMode:run.recoveryMode||null,recoveryProtocol:run.recoveryProtocol||null,
|
|
410
416
|
recoverySourceAssistantKey:run.recoverySourceAssistantKey||null,
|
|
411
417
|
startedAt:run.startedAt||null,
|
|
412
418
|
deadlineAt:deadlineOf(run),lastManualFeedback:run.lastManualFeedback||null}};
|
|
@@ -784,9 +790,11 @@ async function onTurnFinished(message, sender) {
|
|
|
784
790
|
tabId, page: message.page, userKey: message.userKey,
|
|
785
791
|
assistantKey: message.assistantKey, phase: "RESERVED", token,
|
|
786
792
|
action: nextAction, startedAt, modelReceipts:receiptHistory(previous),
|
|
787
|
-
//
|
|
793
|
+
// Preserve the last recovered message across normal progress: a repair
|
|
794
|
+
// acknowledgement cannot replay that same failed Turn.
|
|
788
795
|
...(previous?.recoveryAttempts ? {recoveryAttempts:previous.recoveryAttempts,
|
|
789
|
-
...(previous.recoveryProtocol?{recoveryProtocol:previous.recoveryProtocol}:{})
|
|
796
|
+
...(previous.recoveryProtocol?{recoveryProtocol:previous.recoveryProtocol}:{}),
|
|
797
|
+
...(previous.recoverySourceAssistantKey?{recoverySourceAssistantKey:previous.recoverySourceAssistantKey}:{})} : {}),
|
|
790
798
|
// Preserve an explicitly configured window through every Continue and
|
|
791
799
|
// Handoff. Otherwise the clock silently falls back to the default
|
|
792
800
|
// after the first completed Turn, breaking the persisted deadline.
|
|
@@ -863,6 +871,14 @@ async function onManualPrepare(message, sender) {
|
|
|
863
871
|
// The old Native Host could NEVER commit BLOCKED -> PENDING. Operator must
|
|
864
872
|
// verify that installed-version provenance before supplying this disk CAS.
|
|
865
873
|
// Modern unknown sends are never eligible, even with the query parameter.
|
|
874
|
+
// Explicit repair acknowledgement binds the operator to the exact disk
|
|
875
|
+
// blocker. It does not claim that the browser can verify business repair.
|
|
876
|
+
const resumeRaw=url.searchParams.get("resumeBlockedAt");
|
|
877
|
+
const resumeAt=resumeRaw!==null?Number(resumeRaw):null;
|
|
878
|
+
if(resumeRaw!==null&&(requested!=="CONTINUE"||!rawTabId
|
|
879
|
+
||!Number.isSafeInteger(resumeAt)||resumeAt<=0
|
|
880
|
+
||url.searchParams.has("repairLegacyReservation")))
|
|
881
|
+
return {status:"DENIED",code:"INVALID_BLOCKED_REPAIR"};
|
|
866
882
|
const legacyRaw=url.searchParams.get("repairLegacyReservation");
|
|
867
883
|
const legacyAt=legacyRaw!==null?Number(legacyRaw):null;
|
|
868
884
|
if(legacyRaw!==null&&(requested!=="CONTINUE"||!rawTabId
|
|
@@ -871,7 +887,7 @@ async function onManualPrepare(message, sender) {
|
|
|
871
887
|
return {status:"DENIED",code:"INVALID_LEGACY_REPAIR"};
|
|
872
888
|
if (url.origin !== new URL(chrome.runtime.getURL(filename)).origin
|
|
873
889
|
|| url.pathname !== "/" + filename || url.searchParams.has("token")
|
|
874
|
-
|| Array.from(url.searchParams.keys()).some(key => key !== "tabId"&&key!=="repairLegacyReservation")
|
|
890
|
+
|| Array.from(url.searchParams.keys()).some(key => key !== "tabId"&&key!=="repairLegacyReservation"&&key!=="resumeBlockedAt")
|
|
875
891
|
|| url.searchParams.size!==new Set(url.searchParams.keys()).size
|
|
876
892
|
|| (rawTabId !== null && (!/^[1-9][0-9]*$/.test(rawTabId)
|
|
877
893
|
|| message.tabId !== Number(rawTabId))))
|
|
@@ -891,7 +907,8 @@ async function onManualPrepare(message, sender) {
|
|
|
891
907
|
&&previous?.sessionId&&previous.phase==="BLOCKED"
|
|
892
908
|
&&Number.isInteger(previous.tabId)
|
|
893
909
|
&&(legacyUnsent||previous.reason==="BLOCKED"
|
|
894
|
-
&&(previous.recoveryAttempts||0)===0
|
|
910
|
+
&&((previous.recoveryAttempts||0)===0||resumeAt
|
|
911
|
+
&&previous.recoverySourceAssistantKey!==previous.assistantKey));
|
|
895
912
|
if (previous && (previous.sessionId&&previous.phase!=="DONE"&&!recoveryCandidate
|
|
896
913
|
|| !["DONE", "BLOCKED"].includes(previous.phase)))
|
|
897
914
|
return {status: "DENIED", code: "LOOP_ALREADY_ACTIVE"};
|
|
@@ -922,7 +939,7 @@ async function onManualPrepare(message, sender) {
|
|
|
922
939
|
&&previous.assistantKey===first.assistantKey
|
|
923
940
|
// Specific repaired tool capability, not generic BLOCKED, human
|
|
924
941
|
// approval failure, unknown browser send or context exhaustion.
|
|
925
|
-
|
|
942
|
+
&&(resumeAt||/\b(?:adopt|Start)\b/i.test(first.replyText))
|
|
926
943
|
&&!first.pendingConfirmation
|
|
927
944
|
&&!second.pendingConfirmation);
|
|
928
945
|
if (recoveryCandidate && !ownedRecovery)
|
|
@@ -948,6 +965,7 @@ async function onManualPrepare(message, sender) {
|
|
|
948
965
|
||disk.session.projectId!==previous.projectId
|
|
949
966
|
||disk.session.generation!==(previous.generation||0)
|
|
950
967
|
||disk.session.activeChatId!==chatIdOf(tab.url)
|
|
968
|
+
||resumeAt&&disk.session.updatedAt!==resumeAt
|
|
951
969
|
||legacyAt&&(!legacyUnsent||disk.session.updatedAt!==legacyAt))
|
|
952
970
|
return {status:"DENIED",code:"BLOCKED_OWNER_PERSISTENCE_UNVERIFIED"};
|
|
953
971
|
}
|
|
@@ -958,8 +976,8 @@ async function onManualPrepare(message, sender) {
|
|
|
958
976
|
action: requested, startedAt:ownedRecovery?previous.startedAt:Date.now(),
|
|
959
977
|
manualActionTabId: sender.tab.id,
|
|
960
978
|
...(ownedRecovery?{recoveryMode:"TOOL_PREFLIGHT_REPAIRED",
|
|
961
|
-
recoveryAttempts:1,recoveryProtocol:1,
|
|
962
|
-
...(legacyUnsent?{recoveryExpectedNativeAt:legacyAt}:{}),
|
|
979
|
+
recoveryAttempts:(previous.recoveryAttempts||0)+1,recoveryProtocol:1,
|
|
980
|
+
...(resumeAt||legacyUnsent?{recoveryExpectedNativeAt:resumeAt||legacyAt}:{}),
|
|
963
981
|
recoverySourceAssistantKey:first.assistantKey}:{}),
|
|
964
982
|
handoffMode: requested === "HANDOFF"
|
|
965
983
|
? (modelStatus === "HANDOFF" ? "EXPLICIT" : "TIMED") : null,
|
|
@@ -1008,6 +1026,20 @@ async function onTake(message, sender) {
|
|
|
1008
1026
|
return {status:"DENIED",code:"CONFIRMATION_DOM_UNVERIFIED"};
|
|
1009
1027
|
}
|
|
1010
1028
|
}
|
|
1029
|
+
let projectContext=null;
|
|
1030
|
+
if(run.action==='HANDOFF'&&run.sessionId){
|
|
1031
|
+
const durable=await chrome.runtime.sendNativeMessage(SESSION_HOST,{op:'session-read'}).catch(()=>null);
|
|
1032
|
+
const projection=sessionProjection(run);
|
|
1033
|
+
if(durable?.status!=='OK'||!durable.session
|
|
1034
|
+
||['sessionId','projectId','phase','generation','activeChatId','activeChatUrl']
|
|
1035
|
+
.some(k=>durable.session[k]!==projection[k])
|
|
1036
|
+
||durable.contextStatus==='UNVERIFIED'
|
|
1037
|
+
||durable.projectContext&&durable.projectContext.projectId!==run.projectId){
|
|
1038
|
+
await saveRun({...run,phase:'BLOCKED',reason:'HANDOFF_CONTEXT_UNVERIFIED'});
|
|
1039
|
+
return {status:'DENIED',code:'HANDOFF_CONTEXT_UNVERIFIED'};
|
|
1040
|
+
}
|
|
1041
|
+
projectContext=durable.projectContext||null;
|
|
1042
|
+
}
|
|
1011
1043
|
// Bind a model-control capability to the next *user* Turn, not to a tab or to another Chat.
|
|
1012
1044
|
// Acceptance fixtures retain their existing prompts; native Retry keeps its original Turn token.
|
|
1013
1045
|
const modelTurnToken = run.retryMode === "NATIVE"
|
|
@@ -1020,11 +1052,13 @@ async function onTake(message, sender) {
|
|
|
1020
1052
|
modelTurnToken,
|
|
1021
1053
|
modelTurnNote: modelTurnToken ? turnToolNote(modelTurnToken) : "",
|
|
1022
1054
|
handoffMode: run.handoffMode || null, retryMode: run.retryMode || null,
|
|
1055
|
+
...(projectContext?{projectContext}:{}),
|
|
1023
1056
|
recoveryMode:run.recoveryMode||null,
|
|
1024
1057
|
target: {tabId: run.tabId, page: run.page,
|
|
1025
1058
|
...(run.sessionId?{sessionId:run.sessionId,projectId:run.projectId,
|
|
1026
1059
|
generation:run.generation||0}:{}),
|
|
1027
|
-
|
|
1060
|
+
...(projectContext?{projectContext}:{}),
|
|
1061
|
+
recoveryMode:run.recoveryMode||null,
|
|
1028
1062
|
assistantKey: run.assistantKey,
|
|
1029
1063
|
userKey: run.retryMode === "NATIVE" || run.handoffMode === "ERROR"
|
|
1030
1064
|
? run.newUserKey : run.userKey,
|
|
@@ -1223,10 +1257,10 @@ async function watchActiveTurn() {
|
|
|
1223
1257
|
// Alarm is still read-only. It may reconcile a verified page failure if
|
|
1224
1258
|
// the observer's original notification was lost while Worker slept.
|
|
1225
1259
|
if (run?.phase === "WAITING_REPLY" && run.tabId === tab.id
|
|
1226
|
-
&& proof?.status === "BLOCKED" && proof.reason
|
|
1260
|
+
&& proof?.status === "BLOCKED" && ["PAGE_ERROR","CONTEXT_LIMIT","SECURITY_CHALLENGE"].includes(proof.reason)
|
|
1227
1261
|
&& proof.page === run.page && proof.userKey === run.newUserKey) {
|
|
1228
1262
|
void serial(() => onTurnBlocked({page: run.page,
|
|
1229
|
-
userKey: run.newUserKey, reason:
|
|
1263
|
+
userKey: run.newUserKey, reason: proof.reason},
|
|
1230
1264
|
{tab, url: tab.url}));
|
|
1231
1265
|
}
|
|
1232
1266
|
} catch { /* Observer unavailable; never infer Turn completion. */ }
|
|
@@ -484,6 +484,14 @@
|
|
|
484
484
|
return new RegExp("^(?:我)?(?:已经|已)?(?:确认|同意|批准)"+target+"[。.!!]?$","i")
|
|
485
485
|
.test(line);
|
|
486
486
|
};
|
|
487
|
+
// Prefer an explicit current-version declaration. Historical mentions
|
|
488
|
+
// must not choose a version; ambiguous prose is not approval evidence.
|
|
489
|
+
const versionOf=(value,type)=>{
|
|
490
|
+
const declared=[...value.matchAll(new RegExp("(?:^|\\n)\\s*(?:#{1,6}\\s*)?(?:方案版本|需求版本|当前版本|版本)?[:: ]*("+type+"[1-9][0-9]*)\\b", "gi"))].map(x=>x[1].toUpperCase());
|
|
491
|
+
const current=[...value.matchAll(new RegExp("(?:本次|当前|本版)[:: ]*("+type+"[1-9][0-9]*)\\b", "gi"))].map(x=>x[1].toUpperCase());
|
|
492
|
+
const versions=[...new Set(current.length?current:declared.length?declared:(value.match(new RegExp("\\b"+type+"[1-9][0-9]*\\b","gi"))||[]).map(x=>x.toUpperCase()))];
|
|
493
|
+
return versions.length===1?versions[0]:null;
|
|
494
|
+
};
|
|
487
495
|
const lastUser=rows.findLastIndex(x=>x.role==="user");
|
|
488
496
|
if(lastUser<3 || rows[lastUser-1].role!=="assistant") {
|
|
489
497
|
fail("APPROVAL_SEQUENCE_UNVERIFIED");return false;
|
|
@@ -494,7 +502,7 @@
|
|
|
494
502
|
|| !/\bP[1-9][0-9]*\b/i.test(textOf(pAssistant))) {
|
|
495
503
|
fail("APPROVAL_PLAN_MISSING");return false;
|
|
496
504
|
}
|
|
497
|
-
const pVersion=textOf(pAssistant)
|
|
505
|
+
const pVersion=versionOf(textOf(pAssistant),"P");
|
|
498
506
|
const pUserVersion=textOf(pUser).match(/\bP[1-9][0-9]*\b/i)?.[0].toUpperCase();
|
|
499
507
|
if(pUserVersion && pVersion!==pUserVersion){
|
|
500
508
|
fail("APPROVAL_PLAN_VERSION_MISMATCH");return false;
|
|
@@ -509,7 +517,20 @@
|
|
|
509
517
|
|| !/\bR[1-9][0-9]*\b/i.test(textOf(rAssistant))) {
|
|
510
518
|
fail("APPROVAL_REQUIREMENTS_MISSING");return false;
|
|
511
519
|
}
|
|
512
|
-
const rVersion=textOf(rAssistant)
|
|
520
|
+
const rVersion=versionOf(textOf(rAssistant),"R");
|
|
521
|
+
const intervening=rows.slice(rIndex+1,lastUser-1);
|
|
522
|
+
const invalidated=intervening.some(x=>{
|
|
523
|
+
const text=textOf(x);
|
|
524
|
+
if(x.role==="assistant"){
|
|
525
|
+
const next=versionOf(text,"R");
|
|
526
|
+
return /需求|范围|验收/.test(text)&&next&&next!==rVersion;
|
|
527
|
+
}
|
|
528
|
+
return /(?:撤销|取消|拒绝|不同意|不批准|修改|修订|变更)/.test(text)
|
|
529
|
+
&& /需求|R[1-9][0-9]*/i.test(text);
|
|
530
|
+
});
|
|
531
|
+
if(!pVersion||!rVersion||invalidated){
|
|
532
|
+
fail("APPROVAL_REVISED_OR_REVOKED");return false;
|
|
533
|
+
}
|
|
513
534
|
const rUserVersion=textOf(rUser).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
|
|
514
535
|
const referencedR=textOf(pAssistant).match(/\bR[1-9][0-9]*\b/i)?.[0].toUpperCase();
|
|
515
536
|
if(!referencedR || referencedR!==rVersion){
|
package/extension/manifest.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Read only operator-owned references from the existing Extension configuration.
|
|
2
|
+
// The files retain the task/approval truth; this index never grants execution.
|
|
3
|
+
import {existsSync,lstatSync,readFileSync,realpathSync} from 'node:fs';
|
|
4
|
+
import {dirname,isAbsolute} from 'node:path';
|
|
5
|
+
import {configFile} from './bridge.mjs';
|
|
6
|
+
const invalid=()=>Object.assign(Error('CONTEXT_BINDING_UNVERIFIED'),{code:'CONTEXT_BINDING_UNVERIFIED'});
|
|
7
|
+
const trusted=(p,directory=false)=>{
|
|
8
|
+
const s=lstatSync(p);
|
|
9
|
+
if(s.isSymbolicLink()||(directory?!s.isDirectory():!s.isFile())
|
|
10
|
+
||process.getuid&&s.uid!==process.getuid()
|
|
11
|
+
||process.platform!=='win32'&&(s.mode&0o077))throw invalid();
|
|
12
|
+
return s;
|
|
13
|
+
};
|
|
14
|
+
const pathValue=(value,directory=false)=>{
|
|
15
|
+
if(typeof value!=='string'||!isAbsolute(value)||value.length>2048||/[\x00-\x1f]/.test(value))
|
|
16
|
+
throw invalid();
|
|
17
|
+
const s=lstatSync(realpathSync(value));
|
|
18
|
+
if(directory?!s.isDirectory():!s.isFile())throw invalid();
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
export function registeredContext(projectId){
|
|
22
|
+
const file=configFile();
|
|
23
|
+
if(!existsSync(file))return null;
|
|
24
|
+
try{
|
|
25
|
+
trusted(dirname(file),true);
|
|
26
|
+
if(trusted(file).size>65536)throw invalid();
|
|
27
|
+
const config=JSON.parse(readFileSync(file,'utf8')),entry=config.projectContext;
|
|
28
|
+
if(entry===undefined||entry?.projectId!==projectId)return null;
|
|
29
|
+
if(!entry||Array.isArray(entry)||typeof entry!=='object'
|
|
30
|
+
||Object.keys(entry).some(k=>!['projectId','sourceRoots','contextPath','taskDocPath','approvalDocPath'].includes(k))
|
|
31
|
+
||!Array.isArray(entry.sourceRoots)||entry.sourceRoots.length<1||entry.sourceRoots.length>8)
|
|
32
|
+
throw invalid();
|
|
33
|
+
const result={projectId,sourceRoots:entry.sourceRoots.map(p=>pathValue(p,true)),
|
|
34
|
+
contextPath:pathValue(entry.contextPath),
|
|
35
|
+
...(entry.taskDocPath!==undefined?{taskDocPath:pathValue(entry.taskDocPath)}:{}),
|
|
36
|
+
...(entry.approvalDocPath!==undefined?{approvalDocPath:pathValue(entry.approvalDocPath)}:{})};
|
|
37
|
+
if(JSON.stringify(result).length>8192)throw invalid();
|
|
38
|
+
return result;
|
|
39
|
+
}catch(error){throw invalid();}
|
|
40
|
+
}
|
package/lib/session-file.mjs
CHANGED
|
@@ -88,6 +88,14 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
88
88
|
next.activeChatId!==null&&old.activeChatId!==next.activeChatId)
|
|
89
89
|
throw fail('SESSION_CHAT_CHANGED_WITHOUT_HANDOFF');
|
|
90
90
|
}
|
|
91
|
+
// A read-only Status query and non-authoritative Worker diagnostics can
|
|
92
|
+
// re-sync the SAME durable projection. These are not a new Session
|
|
93
|
+
// transition: preserve Native's CAS timestamp and avoid rewriting disk.
|
|
94
|
+
// A genuine phase/identity/generation change still advances the record.
|
|
95
|
+
if(old && !replaceBlockedSessionId && !resumeBlockedSessionId
|
|
96
|
+
&& ['sessionId','projectId','phase','generation',
|
|
97
|
+
'activeChatId','activeChatUrl'].every(key=>old[key]===next[key]))
|
|
98
|
+
return old;
|
|
91
99
|
const temp=join(dir,'.active-session-'+randomUUID()+'.tmp');
|
|
92
100
|
try{writeFileSync(temp,JSON.stringify(next,null,2)+'\n',{flag:'wx',mode:0o600});
|
|
93
101
|
renameSync(temp,file);
|