@tomflow/chatloop-tools 0.9.54 → 0.9.55
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/cli.mjs +16 -4
- package/index.mjs +4 -3
- package/lib/extension-proxy.mjs +16 -4
- package/lib/local-write-probe.mjs +49 -0
- package/node_modules/@tomflow/chatloop-context/package.json +2 -2
- package/node_modules/@tomflow/chatloop-extension/README.md +7 -3
- package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +2 -1
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +1 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +34 -3
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +6 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +2 -1
- package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +2 -0
- package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +16 -2
- package/node_modules/@tomflow/chatloop-extension/package.json +1 -1
- package/package.json +3 -3
- package/providers/extension.mjs +4 -1
package/bin/cli.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const cliApi=await loadToolsCli();
|
|
|
11
11
|
const cliExtensions=cliApi.cliExtensions;
|
|
12
12
|
const HELP={
|
|
13
13
|
'': 'Usage: chatloop-tools <command> [target]\nCommands: doctor, mcp, start, stop, restart, status, upgrade, tunnel, capabilities, api-usage\nRun: chatloop-tools <command> --help',
|
|
14
|
-
doctor:'Usage: chatloop-tools doctor
|
|
14
|
+
doctor:'Usage: chatloop-tools doctor [--local-write-probe]\nDefault doctor is read-only. Explicit probe checks write/read/cleanup only inside a private system temporary directory; this does not grant project write access or prove remote MCP connectivity.',
|
|
15
15
|
mcp:'Usage: chatloop-tools mcp\nServe namespaced MCP tools over stdio.',
|
|
16
16
|
start:'Usage: chatloop-tools start [desktop-commander|tunnel]\nStart all enabled tools or one.',
|
|
17
17
|
stop:'Usage: chatloop-tools stop [desktop-commander|tunnel]\nStop all enabled tools or one.',
|
|
@@ -37,7 +37,7 @@ if(helpSection!==null){
|
|
|
37
37
|
const {lifecycleDeadlineMs,CONTRACT,ACTIONS,registry,ensurePrivateDir,
|
|
38
38
|
safeFallback,recoverStaleLock,exitCode,talk,runGateway,apiUsage,tunnelDoctor,runTunnel,
|
|
39
39
|
promptTunnelRuntimeKey,storeTunnelRuntimeKey,upgradeRuntime,runtimeNeedsUpgrade,
|
|
40
|
-
prepareReleaseCandidate}=cliApi;
|
|
40
|
+
prepareReleaseCandidate,localWriteProbe}=cliApi;
|
|
41
41
|
const require=createRequire(import.meta.url);
|
|
42
42
|
const command=process.argv[2]??'doctor';
|
|
43
43
|
const extra=process.argv.slice(3);
|
|
@@ -146,8 +146,20 @@ if(command==='mcp'){
|
|
|
146
146
|
process.exitCode=5;
|
|
147
147
|
}else if(ACTIONS.has(command))await runControl();
|
|
148
148
|
else if(command==='doctor'){
|
|
149
|
-
if(extra.length
|
|
150
|
-
|
|
149
|
+
if(extra.length&&!(extra.length===1&&extra[0]==='--local-write-probe')){
|
|
150
|
+
emit(fail('INVALID_ARGUMENT'));process.exitCode=2;
|
|
151
|
+
}else{
|
|
152
|
+
const snapshot=inspect();
|
|
153
|
+
const probe=extra[0]==='--local-write-probe'&&snapshot.status==='LOCAL_READY'
|
|
154
|
+
?localWriteProbe():null;
|
|
155
|
+
const ready=snapshot.status==='LOCAL_READY'
|
|
156
|
+
&&(probe===null||probe.status==='PASS');
|
|
157
|
+
emit({contract:'chat-loop.local-tools.v1',command,...snapshot,
|
|
158
|
+
...(probe?{localWriteProbe:probe}:{}),
|
|
159
|
+
...(ready?{}:{status:'BLOCKED',
|
|
160
|
+
reason:probe?.code||snapshot.reason})});
|
|
161
|
+
if(!ready)process.exitCode=1;
|
|
162
|
+
}
|
|
151
163
|
}else if(command==='tunnel'){
|
|
152
164
|
if(extra.length===1&&extra[0]==='doctor'){
|
|
153
165
|
const result=await tunnelDoctor();
|
package/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {createApiAspect,subscribeTraceApiLog} from '@tomflow/chatloop-trace';
|
|
|
7
7
|
import {providerDefinitions} from './providers.generated.mjs';
|
|
8
8
|
import {createMcpToolRouter} from './lib/mcp-tool-router.mjs';
|
|
9
9
|
import {createCliCommandRouter} from './lib/cli-command-router.mjs';
|
|
10
|
+
import {probeLocalWriteCapability,trustedSystemTempRoot} from './lib/local-write-probe.mjs';
|
|
10
11
|
// One bounded SDK/CLI/MCP side channel; the Supervisor is the only writer.
|
|
11
12
|
// Cold-start observations are held until the port is composed, never on an
|
|
12
13
|
// API's business execution stack.
|
|
@@ -167,7 +168,8 @@ async function runtime(){
|
|
|
167
168
|
isControlTool:extensionContract.isControlTool,
|
|
168
169
|
acceptExtensionCliReceipt:extensionCliContract.acceptExtensionCliReceipt,
|
|
169
170
|
extensionTools:extensionContract.extensionTools,
|
|
170
|
-
readApiParent:apiAspect.current
|
|
171
|
+
readApiParent:apiAspect.current,localWriteProbe:probeLocalWriteCapability,
|
|
172
|
+
trustedTempRoot:trustedSystemTempRoot});
|
|
171
173
|
release.configureRelease({PACKAGE_VERSION:control.PACKAGE_VERSION});
|
|
172
174
|
releaseUpgrade.configureReleaseUpgrade({
|
|
173
175
|
...release.releaseUpgradeDependencies(),CONTRACT:control.CONTRACT,
|
|
@@ -339,7 +341,6 @@ async function runtime(){
|
|
|
339
341
|
})();
|
|
340
342
|
return runtimePromise;
|
|
341
343
|
}
|
|
342
|
-
|
|
343
344
|
// Public SDK entry with explicitly separated runtime roles.
|
|
344
345
|
async function loadToolsCliCore(){
|
|
345
346
|
const {control,tunnel,tunnelAuth,release,gateway}=await runtime();
|
|
@@ -362,6 +363,7 @@ async function loadToolsCliCore(){
|
|
|
362
363
|
[INTERNAL_DRAIN]:drainCliTelemetry,
|
|
363
364
|
cliExtensions:apiAspect.methods(createCliCommandRouter(providerDefinitions),
|
|
364
365
|
'cliExtensions','cli'),
|
|
366
|
+
localWriteProbe:probeLocalWriteCapability,
|
|
365
367
|
lifecycleDeadlineMs:control.lifecycleDeadlineMs,
|
|
366
368
|
CONTRACT:control.CONTRACT,ACTIONS:control.ACTIONS,
|
|
367
369
|
registry:control.registry,ensurePrivateDir:control.ensurePrivateDir,
|
|
@@ -388,7 +390,6 @@ async function loadToolsCliCore(){
|
|
|
388
390
|
prepareReleaseCandidate:release.prepareReleaseCandidate
|
|
389
391
|
}), 'tools','sdk');
|
|
390
392
|
}
|
|
391
|
-
|
|
392
393
|
// SDK role for the internal Native/Supervisor executable under bin/.
|
|
393
394
|
async function runToolsSupervisorCore(){
|
|
394
395
|
const {supervisor}=await runtime();
|
package/lib/extension-proxy.mjs
CHANGED
|
@@ -6,13 +6,13 @@ import {tmpdir} from 'node:os';
|
|
|
6
6
|
import {join,dirname,basename} from 'node:path';
|
|
7
7
|
// All internal dependencies are supplied as API contracts by index.mjs.
|
|
8
8
|
// Private modules never import or resolve another private implementation.
|
|
9
|
-
let extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools, readApiParent;
|
|
9
|
+
let extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools, readApiParent,localWriteProbe,trustedTempRoot;
|
|
10
10
|
let connected=false;
|
|
11
11
|
export function configureExtensionProxy(ports){
|
|
12
12
|
if(connected)throw Error('TOOLS_MODULE_ALREADY_COMPOSED');
|
|
13
|
-
for(const name of ['extensionCommand', 'validExtensionArgs', 'isControlTool', 'acceptExtensionCliReceipt', 'extensionTools', 'readApiParent'])
|
|
13
|
+
for(const name of ['extensionCommand', 'validExtensionArgs', 'isControlTool', 'acceptExtensionCliReceipt', 'extensionTools', 'readApiParent', 'localWriteProbe', 'trustedTempRoot'])
|
|
14
14
|
if(ports?.[name]===undefined)throw Error('TOOLS_PORT_MISSING:'+name);
|
|
15
|
-
({extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools, readApiParent}=ports);
|
|
15
|
+
({extensionCommand, validExtensionArgs, isControlTool, acceptExtensionCliReceipt, extensionTools, readApiParent,localWriteProbe,trustedTempRoot}=ports);
|
|
16
16
|
connected=true;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -77,13 +77,25 @@ function screenshotSourceVerified(path){
|
|
|
77
77
|
}
|
|
78
78
|
export async function forwardExtensionAction(name,args={}) {
|
|
79
79
|
if(!validExtensionArgs(name,args))return fail('INVALID_ARGUMENT');
|
|
80
|
+
// Enforce the local capability gate at the actual MCP Start boundary,
|
|
81
|
+
// not only in the Workflow text. No CLI/Native/Chrome action on failure.
|
|
82
|
+
if(name==='start'){
|
|
83
|
+
let proof;
|
|
84
|
+
try{proof=localWriteProbe()}catch{return fail('START_LOCAL_PREFLIGHT_BLOCKED')}
|
|
85
|
+
if(proof?.status!=='PASS'||proof.scope!=='SYSTEM_TEMP_ONLY'
|
|
86
|
+
||proof.writeReadVerified!==true||proof.cleaned!==true)
|
|
87
|
+
return fail('START_LOCAL_PREFLIGHT_BLOCKED');
|
|
88
|
+
}
|
|
80
89
|
const invocation=extensionInvocation(name);
|
|
81
90
|
if(!invocation)return fail('EXTENSION_PROVIDER_UNTRUSTED');
|
|
82
91
|
const control=isControlTool(name);
|
|
83
92
|
if(name==='clean')invocation.args.push(String(args.tabId));
|
|
93
|
+
const fixedTemp=name==='start'?trustedTempRoot():null;
|
|
94
|
+
const env=childApiEnvironment();
|
|
95
|
+
if(fixedTemp)for(const key of ['TMPDIR','TMP','TEMP'])env[key]=fixedTemp;
|
|
84
96
|
const response=await new Promise(resolve=>{
|
|
85
97
|
const child=spawn(invocation.executable,invocation.args,{stdio:[control?'pipe':'ignore','pipe','pipe'],
|
|
86
|
-
cwd:tmpdir(),windowsHide:true,env
|
|
98
|
+
cwd:fixedTemp||tmpdir(),windowsHide:true,env});
|
|
87
99
|
let stdout='',stdoutBytes=0,finished=false,closed=false,tailTimer=null;
|
|
88
100
|
const settle=(value,receiptCompleted=false)=>{
|
|
89
101
|
if(finished)return;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Bounded, reversible local file capability proof for Stage 03 ONLY.
|
|
2
|
+
// This proves process-scoped system temp write/read/cleanup, not project ACL,
|
|
3
|
+
// remote ChatGPT→MCP connectivity or permission to install dependencies.
|
|
4
|
+
import {randomUUID} from 'node:crypto';
|
|
5
|
+
import {mkdtempSync,writeFileSync,readFileSync,unlinkSync,rmdirSync,
|
|
6
|
+
lstatSync,realpathSync} from 'node:fs';
|
|
7
|
+
import {join,resolve,sep} from 'node:path';
|
|
8
|
+
|
|
9
|
+
// Never trust TMPDIR/TMP/TEMP: Node os.tmpdir() can point at a source tree.
|
|
10
|
+
// On supported POSIX hosts only a root-owned sticky system temp is eligible.
|
|
11
|
+
const SYSTEM_TEMP=process.platform==='darwin'?'/private/tmp'
|
|
12
|
+
:process.platform==='linux'?'/tmp':null;
|
|
13
|
+
export function trustedSystemTempRoot(){return SYSTEM_TEMP}
|
|
14
|
+
|
|
15
|
+
export function probeLocalWriteCapability(base=SYSTEM_TEMP){
|
|
16
|
+
let dir=null,file=null,cleaned=true;
|
|
17
|
+
try{
|
|
18
|
+
if(!SYSTEM_TEMP)throw Error('UNSUPPORTED_TEMP_PLATFORM');
|
|
19
|
+
const system=lstatSync(SYSTEM_TEMP);
|
|
20
|
+
if(!system.isDirectory()||system.isSymbolicLink()
|
|
21
|
+
||system.uid!==0||(system.mode&0o1000)===0
|
|
22
|
+
||(system.mode&0o002)===0)throw Error('UNTRUSTED_SYSTEM_TEMP');
|
|
23
|
+
const target=resolve(base);
|
|
24
|
+
if((target!==SYSTEM_TEMP&&!target.startsWith(SYSTEM_TEMP+sep))
|
|
25
|
+
||realpathSync(target)!==target)throw Error('TEMP_SCOPE_VIOLATION');
|
|
26
|
+
const root=lstatSync(target);
|
|
27
|
+
if(!root.isDirectory()||root.isSymbolicLink())
|
|
28
|
+
throw Error('INVALID_TEMP_ROOT');
|
|
29
|
+
dir=mkdtempSync(join(target,'chatloop-write-probe-'));
|
|
30
|
+
const st=lstatSync(dir);
|
|
31
|
+
if(!st.isDirectory()||st.isSymbolicLink()||(st.mode&0o077)
|
|
32
|
+
||(process.getuid&&st.uid!==process.getuid()))
|
|
33
|
+
throw Object.assign(Error('UNTRUSTED_TEMP_DIR'),{code:'UNTRUSTED_TEMP_DIR'});
|
|
34
|
+
file=join(dir,'probe');
|
|
35
|
+
const bytes=Buffer.from(randomUUID(),'utf8');
|
|
36
|
+
writeFileSync(file,bytes,{flag:'wx',mode:0o600});
|
|
37
|
+
if(!readFileSync(file).equals(bytes))
|
|
38
|
+
throw Object.assign(Error('WRITE_READ_MISMATCH'),{code:'WRITE_READ_MISMATCH'});
|
|
39
|
+
unlinkSync(file);file=null;
|
|
40
|
+
rmdirSync(dir);dir=null;
|
|
41
|
+
return {status:'PASS',scope:'SYSTEM_TEMP_ONLY',writeReadVerified:true,
|
|
42
|
+
cleaned:true};
|
|
43
|
+
}catch{
|
|
44
|
+
if(file){try{unlinkSync(file)}catch{cleaned=false}}
|
|
45
|
+
if(dir){try{rmdirSync(dir)}catch{cleaned=false}}
|
|
46
|
+
return {status:'BLOCKED',code:'LOCAL_WRITE_PROBE_FAILED',
|
|
47
|
+
scope:'SYSTEM_TEMP_ONLY',writeReadVerified:false,cleaned};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-context",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Independent local Context SDK and short-lived CLI for Chat Loop projects",
|
|
6
6
|
"publishConfig": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"ps-list": "9.0.0",
|
|
37
|
-
"@tomflow/chatloop-extension": "0.4.
|
|
37
|
+
"@tomflow/chatloop-extension": "0.4.27",
|
|
38
38
|
"@tomflow/chatloop-trace": "0.4.6"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -78,7 +78,7 @@ Run: chatloop-extension extension <command> --help
|
|
|
78
78
|
|
|
79
79
|
For the installed command list, run `chatloop-extension extension --help`.
|
|
80
80
|
|
|
81
|
-
`extension start` requires the real approved intent; `mode=adopt` does not
|
|
81
|
+
`extension start` requires the real approved intent; `mode=adopt` requires an exact Context `start.reserve` lease, taskId, store epoch and revisions at the public CLI input boundary, with actual approval/lease validity independently checked by Native `permit.consume`. A browser-only R/P text pattern and `confirmed:true` cannot authorize a production Adopt; the prompt-based legacy Start has separate rules. `mode=adopt` does not
|
|
82
82
|
re-send. Continue/Handoff only register intents with one Turn token and never
|
|
83
83
|
silently send or repeat. Clean needs an exact verified tab ID, and Status
|
|
84
84
|
is read-only. A previously BLOCKED Session with a lost old Owner tab remains
|
|
@@ -86,8 +86,12 @@ is read-only. A previously BLOCKED Session with a lost old Owner tab remains
|
|
|
86
86
|
`oldOwnerTabStatus:MISSING_UNVERIFIED` diagnostic is not a replacement permit.
|
|
87
87
|
A missing ACTIVE Owner or mismatched Native pointer remains `UNVERIFIED`.
|
|
88
88
|
Explicit Adopt of a different approved Task still requires the exact old
|
|
89
|
-
Session ID, old Context fence, and a fresh Start lease.
|
|
90
|
-
|
|
89
|
+
Session ID, old Context fence, and a fresh Start lease. An exceptional
|
|
90
|
+
same-Task recovery is limited to a proven pre-permit BLOCKED Adopt with no
|
|
91
|
+
send/Owner/writer, a fresh Context lease and one exact Native timestamp CAS;
|
|
92
|
+
a Worker-only failed Native sync permits at most one additional fenced repair,
|
|
93
|
+
never a general BLOCKED retry. Two distinct genuine Form A-confirmation
|
|
94
|
+
user Turns may serve as SOFT R/P evidence in an explicitly
|
|
91
95
|
specified original Chat; this never substitutes for Context approval or Start
|
|
92
96
|
permission. IPC messages are one-shot and have durable identity checks.
|
|
93
97
|
|
|
@@ -81,7 +81,8 @@ process.stdin.on('data',async chunk=>{
|
|
|
81
81
|
write({status:recorded?'RECORDED':'DROPPED'});
|
|
82
82
|
}else if(m.op==='session-sync'){
|
|
83
83
|
write({status:'OK',session:writeSession(m.session,
|
|
84
|
-
m.replaceBlockedSessionId,m.resumeBlockedSessionId,
|
|
84
|
+
m.replaceBlockedSessionId,m.resumeBlockedSessionId,
|
|
85
|
+
m.resumeBlockedUpdatedAt??null,m.sameTaskPrePermitUpdatedAt??null)});
|
|
85
86
|
}else throw Object.assign(Error('Unknown operation'),{code:'INVALID_OPERATION'});
|
|
86
87
|
};
|
|
87
88
|
// The telemetry operation is intentionally excluded from self-recording.
|
|
@@ -67,9 +67,29 @@ async function sessionStartPrepare(message,sender){
|
|
|
67
67
|
&&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
|
|
68
68
|
&&Number.isInteger(prior.adoptTabId)
|
|
69
69
|
&&typeof prior.adoptUserKey==='string');
|
|
70
|
+
// If the previous pre-permit replacement wrote Worker STARTING but Native
|
|
71
|
+
// rejected its CAS, Worker/Native disagree. No send was attempted, but this
|
|
72
|
+
// is NOT a free retry: one exact native-BLOCKED repair with a fresh lease
|
|
73
|
+
// is allowed; any managed writer, late send or second repair remains denied.
|
|
74
|
+
const preNativeGhost=Boolean(prior?.phase==='STARTING'
|
|
75
|
+
&&prior.action==='START'&&prior.mode==='adopt'
|
|
76
|
+
&&prior.prePermitRetryUsed===true&&!prior.preNativeRepairUsed
|
|
77
|
+
&&prior.replacedBlockedSessionId===replace
|
|
78
|
+
&&prior.sessionId!==replace&&prior.contextLeaseRef
|
|
79
|
+
&&intent.contextLeaseRef&&intent.contextLeaseRef!==prior.contextLeaseRef
|
|
80
|
+
&&!prior.contextManaged&&prior.projectId===intent.projectId
|
|
81
|
+
&&prior.taskId===intent.taskId
|
|
82
|
+
&&prior.contextStoreEpoch===intent.contextStoreEpoch
|
|
83
|
+
&&prior.contextTaskRevision===intent.contextTaskRevision
|
|
84
|
+
&&prior.contextApprovalRevision===intent.contextApprovalRevision
|
|
85
|
+
&&prior.tabId===null&&prior.page==='/'&&!prior.newUserKey
|
|
86
|
+
&&!prior.userKey&&!prior.attemptedNewTabId
|
|
87
|
+
&&!!intent.chatUrl&&prior.adoptPage===pathOf(intent.chatUrl)
|
|
88
|
+
&&Number.isInteger(prior.adoptTabId)
|
|
89
|
+
&&typeof prior.adoptUserKey==='string');
|
|
70
90
|
const matchingBlocked=prior?.phase==='BLOCKED' && prior.sessionId===replace
|
|
71
91
|
&& (prior.projectId!==intent.projectId || independentTask
|
|
72
|
-
||prePermitRecovery);
|
|
92
|
+
||prePermitRecovery)||preNativeGhost;
|
|
73
93
|
if(replace&&!matchingBlocked)return {status:'DENIED',code:'BLOCKED_REPLACEMENT_MISMATCH'};
|
|
74
94
|
if(prior&&prior.phase!=='DONE'&&!matchingBlocked)
|
|
75
95
|
return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
|
|
@@ -77,7 +97,15 @@ async function sessionStartPrepare(message,sender){
|
|
|
77
97
|
if(disk?.status!=='OK')return {status:'DENIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
78
98
|
const ownerMatches=Boolean(prior?.sessionId&&disk.session
|
|
79
99
|
&&matchesNativeProjection(sessionProjection(prior),disk.session));
|
|
80
|
-
|
|
100
|
+
const sameTaskNative=Boolean((prePermitRecovery||preNativeGhost)
|
|
101
|
+
&&disk.session?.sessionId===replace&&disk.session.phase==='BLOCKED'
|
|
102
|
+
&&disk.session.projectId===intent.projectId
|
|
103
|
+
&&disk.session.taskId===intent.taskId&&disk.session.generation===0
|
|
104
|
+
&&disk.session.activeChatId===null&&disk.session.activeChatUrl===null
|
|
105
|
+
&&Number.isSafeInteger(disk.session.updatedAt)
|
|
106
|
+
&&disk.session.updatedAt>0);
|
|
107
|
+
if((matchingBlocked&&!(ownerMatches||(preNativeGhost&&sameTaskNative)))
|
|
108
|
+
||((prePermitRecovery||preNativeGhost)&&!sameTaskNative))
|
|
81
109
|
return {status:'DENIED',code:'SESSION_REPLACEMENT_MISMATCH'};
|
|
82
110
|
// A terminal Worker record cannot authorize a new Start if a different
|
|
83
111
|
// durable Native Owner exists under the same Browser installation.
|
|
@@ -133,7 +161,10 @@ async function sessionStartPrepare(message,sender){
|
|
|
133
161
|
page:'/',tabId:null,startedAt:Date.now(),
|
|
134
162
|
machineRequestId:message.requestId,machineActionTabId:sender.tab.id,
|
|
135
163
|
...(matchingBlocked?{replacedBlockedSessionId:replace}:{}),
|
|
136
|
-
...(prePermitRecovery?{
|
|
164
|
+
...(prePermitRecovery||preNativeGhost?{
|
|
165
|
+
prePermitRetryUsed:true,
|
|
166
|
+
...(preNativeGhost?{preNativeRepairUsed:true}:{}),
|
|
167
|
+
sameTaskPrePermitUpdatedAt:disk.session.updatedAt}:{}),
|
|
137
168
|
...(adoption?{mode:'adopt',adoptTabId:adoption.target.tabId,
|
|
138
169
|
adoptPage:adoption.target.page,adoptUserKey:adoption.target.userKey,
|
|
139
170
|
...((intent.chatUrl||adoption.target.explicitChatId)
|
|
@@ -99,7 +99,9 @@ async function saveRun(run) {
|
|
|
99
99
|
const saved=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
100
100
|
{op:"session-sync",session:record,
|
|
101
101
|
...(next.replacedBlockedSessionId&&!recoveryCommit&&next.phase==='STARTING'
|
|
102
|
-
?{replaceBlockedSessionId:next.replacedBlockedSessionId
|
|
102
|
+
?{replaceBlockedSessionId:next.replacedBlockedSessionId,
|
|
103
|
+
...(Number.isSafeInteger(next.sameTaskPrePermitUpdatedAt)
|
|
104
|
+
?{sameTaskPrePermitUpdatedAt:next.sameTaskPrePermitUpdatedAt}:{})}:{}),
|
|
103
105
|
...(recoveryCommit?{resumeBlockedSessionId:next.sessionId,
|
|
104
106
|
resumeBlockedUpdatedAt:next.recoveryExpectedNativeAt}:{})}).catch(()=>null);
|
|
105
107
|
// Native acknowledgment must match the whole immutable Owner pointer,
|
|
@@ -143,6 +145,9 @@ const SESSION_POINTER_KEYS=Object.freeze(['sessionId','projectId','taskId','phas
|
|
|
143
145
|
'generation','activeChatId','activeChatUrl']);
|
|
144
146
|
const matchesNativeProjection=(projected,native)=>Boolean(native
|
|
145
147
|
&&SESSION_POINTER_KEYS.every(key=>projected[key]===native[key]));
|
|
148
|
+
// Read-only status diagnosis: reveal field NAMES only, never Owner identities.
|
|
149
|
+
const sessionProjectionDrift=(projected,native)=>SESSION_POINTER_KEYS.filter(
|
|
150
|
+
key=>projected[key]!==native?.[key]);
|
|
146
151
|
const sessionPage=(sender,name,id)=> Number.isInteger(sender.tab?.id)
|
|
147
152
|
&& typeof id==='string'&&/^[a-f0-9]{32}$/.test(id)
|
|
148
153
|
&& sender.url===chrome.runtime.getURL(name+'.html')+'?requestId='+id;
|
|
@@ -155,7 +155,8 @@ async function sessionStatus(message,sender){
|
|
|
155
155
|
if(disk?.status!=='OK')return {status:'UNVERIFIED',code:'SESSION_STATE_UNVERIFIED'};
|
|
156
156
|
const projection=run?.sessionId?sessionProjection(run):null;
|
|
157
157
|
if(projection&&!matchesNativeProjection(projection,disk.session))
|
|
158
|
-
return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH'
|
|
158
|
+
return {status:'UNVERIFIED',code:'SESSION_FILE_MISMATCH',
|
|
159
|
+
mismatchedFields:sessionProjectionDrift(projection,disk.session)};
|
|
159
160
|
if(!run?.sessionId&&disk.session&&disk.session.phase!=='DONE')
|
|
160
161
|
return {status:'UNVERIFIED',code:'SESSION_OWNER_MISMATCH'};
|
|
161
162
|
if(run&&run.phase!=='DONE'&&!run.sessionId)
|
|
@@ -85,6 +85,8 @@ function validateIntent(action, intent) {
|
|
|
85
85
|
||typeof intent.contextStoreEpoch!=='string'||intent.contextStoreEpoch.length<10
|
|
86
86
|
||!Number.isSafeInteger(intent.contextTaskRevision)||intent.contextTaskRevision<1
|
|
87
87
|
||!Number.isSafeInteger(intent.contextApprovalRevision)||intent.contextApprovalRevision<1))
|
|
88
|
+
// Public Extension CLI must not bypass the managed Context Start lease.
|
|
89
|
+
||(intent.mode==='adopt'&&!Object.hasOwn(intent,'contextLeaseRef'))
|
|
88
90
|
||intent.confirmed!==true || (intent.mode!==undefined && intent.mode!=='adopt')
|
|
89
91
|
|| (intent.replaceBlockedSessionId!==undefined
|
|
90
92
|
&& !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(intent.replaceBlockedSessionId))
|
|
@@ -60,7 +60,7 @@ export function readSession(){
|
|
|
60
60
|
try{return validate(JSON.parse(readFileSync(file,'utf8')));}
|
|
61
61
|
catch(e){if(e.code)throw e;throw fail('SESSION_FILE_CORRUPT');}
|
|
62
62
|
}
|
|
63
|
-
export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSessionId=null,resumeBlockedUpdatedAt=null){
|
|
63
|
+
export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSessionId=null,resumeBlockedUpdatedAt=null,sameTaskPrePermitUpdatedAt=null){
|
|
64
64
|
const next=validate(input),file=sessionPath(),dir=dirname(file),lock=file+'.lock';
|
|
65
65
|
ensurePrivate(dir);
|
|
66
66
|
let fd;
|
|
@@ -88,11 +88,25 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
88
88
|
if(replaceBlockedSessionId && (!old||old.sessionId!==next.sessionId
|
|
89
89
|
&& (old.phase!=='BLOCKED'||old.sessionId!==replaceBlockedSessionId)))
|
|
90
90
|
throw fail('SESSION_REPLACEMENT_MISMATCH');
|
|
91
|
+
// The Worker alone identifies the pre-permit failure. Native requires
|
|
92
|
+
// an independent one-shot disk CAS before allowing the SAME scoped Task
|
|
93
|
+
// to replace its unsent BLOCKED session; other BLOCKED phases stay locked.
|
|
94
|
+
const prePermitCas=Number.isSafeInteger(sameTaskPrePermitUpdatedAt)
|
|
95
|
+
&&sameTaskPrePermitUpdatedAt>0&&old?.updatedAt===sameTaskPrePermitUpdatedAt
|
|
96
|
+
&&old.phase==='BLOCKED'&&old.sessionId===replaceBlockedSessionId
|
|
97
|
+
&&old.projectId===next.projectId&&typeof old.taskId==='string'
|
|
98
|
+
&&old.taskId===next.taskId&&next.sessionId!==old.sessionId
|
|
99
|
+
&&old.generation===0&&next.generation===0&&next.phase==='STARTING'
|
|
100
|
+
&&old.activeChatId===null&&old.activeChatUrl===null
|
|
101
|
+
&&next.activeChatId===null&&next.activeChatUrl===null;
|
|
102
|
+
if(sameTaskPrePermitUpdatedAt!==null&&!prePermitCas)
|
|
103
|
+
throw fail('SESSION_PRE_PERMIT_CAS_MISMATCH');
|
|
91
104
|
if(old&&old.sessionId!==next.sessionId&&old.phase!=='DONE'
|
|
92
105
|
&& !(old.phase==='BLOCKED' && next.phase==='STARTING'
|
|
93
106
|
&& replaceBlockedSessionId===old.sessionId
|
|
94
107
|
&& (next.projectId!==old.projectId
|
|
95
|
-
||next.taskId!==undefined&&next.taskId!==old.taskId
|
|
108
|
+
||next.taskId!==undefined&&next.taskId!==old.taskId
|
|
109
|
+
||prePermitCas)))
|
|
96
110
|
throw fail('SESSION_ALREADY_ACTIVE');
|
|
97
111
|
if(old&&old.sessionId===next.sessionId){
|
|
98
112
|
if(next.projectId!==old.projectId)throw fail('SESSION_PROJECT_CHANGED');
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.55",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
|
|
9
9
|
"bin": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"prepack": "node ./scripts/build-providers.mjs --check && node ./scripts/build-form-app.mjs --check && node ./scripts/build-document-app.mjs --check"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tomflow/chatloop-context": "0.6.
|
|
36
|
+
"@tomflow/chatloop-context": "0.6.18",
|
|
37
37
|
"@tomflow/chatloop-trace": "0.4.6",
|
|
38
38
|
"@wonderwhy-er/desktop-commander": "0.2.44",
|
|
39
39
|
"ps-list": "9.0.0",
|
|
40
|
-
"@tomflow/chatloop-extension": "0.4.
|
|
40
|
+
"@tomflow/chatloop-extension": "0.4.27"
|
|
41
41
|
},
|
|
42
42
|
"bundleDependencies": [
|
|
43
43
|
"@tomflow/chatloop-context",
|
package/providers/extension.mjs
CHANGED
|
@@ -20,7 +20,7 @@ const endpoints=[
|
|
|
20
20
|
[['extension','reload'],extensionTool('reload','Request reload of Chat Loop Extension; final health is unverified.',false)],
|
|
21
21
|
[['extension','status'],extensionTool('status','Read the unique current Mac Chrome Web Chat Owner; never starts or sends.',true)],
|
|
22
22
|
[['extension','start'],extensionTool('start',
|
|
23
|
-
'Controlled execution ONLY: in Stage 03, mode=adopt
|
|
23
|
+
'Controlled execution ONLY: in Stage 03, mode=adopt requires a fresh Context start.reserve lease (taskId, contextLeaseRef, store epoch and revisions); Native validates the real R/P-approved original Chat without resending. The prompt-based branch creates a machine-owned execution session and requires the model status protocol; it is NOT a native @ Chat Loop user entry or Stage 01/02 testing mechanism. For TEST_ONLY native @ App entry, use the separate Extension entry test action, not Start.',false,
|
|
24
24
|
{projectId:{type:'string',minLength:1,maxLength:128,pattern:PROJECT_ID.source},
|
|
25
25
|
taskId:{type:'string',minLength:1,maxLength:128,pattern:PROJECT_ID.source},
|
|
26
26
|
purpose:{type:'string',enum:['REPAIR_SAME_SCOPE']},
|
|
@@ -69,6 +69,9 @@ export function validExtensionArgs(name,args){
|
|
|
69
69
|
||!Number.isSafeInteger(args.contextTaskRevision)||args.contextTaskRevision<1
|
|
70
70
|
||!Number.isSafeInteger(args.contextApprovalRevision)||args.contextApprovalRevision<1))
|
|
71
71
|
||args.confirmed!==true
|
|
72
|
+
// A managed original-Chat Adopt must carry a Context start.reserve lease.
|
|
73
|
+
// The exact lease/approval is checked by Native permit.consume, not here.
|
|
74
|
+
||(args.mode==='adopt'&&!Object.hasOwn(args,'contextLeaseRef'))
|
|
72
75
|
||(args.replaceBlockedSessionId!==undefined
|
|
73
76
|
&& !REPLACE_SESSION.test(args.replaceBlockedSessionId))
|
|
74
77
|
||(args.mode!==undefined && args.mode!=='adopt')
|