@tomflow/chatloop-tools 0.9.61 → 0.9.62
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/lib/context-control-run.mjs +1 -1
- package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +3 -1
- package/node_modules/@tomflow/chatloop-context/index.mjs +4 -2
- package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +2 -1
- package/node_modules/@tomflow/chatloop-context/lib/core/run-cancel.mjs +54 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +1 -0
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +6 -4
- package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +6 -2
- package/node_modules/@tomflow/chatloop-context/package.json +2 -2
- package/node_modules/@tomflow/chatloop-extension/README.md +5 -2
- package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +3 -2
- package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +5 -2
- package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +80 -2
- package/node_modules/@tomflow/chatloop-extension/capabilities/session.mjs +1 -0
- package/node_modules/@tomflow/chatloop-extension/extension/actions/session.js +52 -0
- package/node_modules/@tomflow/chatloop-extension/extension/background.js +1 -0
- package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +9 -4
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +1 -1
- package/node_modules/@tomflow/chatloop-extension/extension/session.html +6 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +16 -3
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +15 -3
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +29 -1
- package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +1 -0
- package/node_modules/@tomflow/chatloop-extension/extension/worker/session-control.js +75 -0
- package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +2 -1
- package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +25 -0
- package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +32 -7
- package/node_modules/@tomflow/chatloop-extension/package.json +1 -1
- package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +5 -4
- package/package.json +3 -3
- package/providers/extension.mjs +38 -2
|
@@ -22,7 +22,7 @@ const fail=code=>Object.assign(new Error(code),{code});
|
|
|
22
22
|
const assert=(ok,code)=>{if(!ok)throw fail(code)};
|
|
23
23
|
const supported=new Set(['permit.consume','run.bind.initial','run.fence',
|
|
24
24
|
'run.bind.handoff','run.restore-same-owner','run.fence.terminal',
|
|
25
|
-
'run.credential.rotate','run.terminalStatus','run.reopenStatus','run.snapshot']);
|
|
25
|
+
'run.credential.rotate','run.fence.cancel','run.terminalStatus','run.reopenStatus','run.snapshot']);
|
|
26
26
|
const sessionPath=()=>join(process.env.CHAT_LOOP_CONTEXT_NATIVE_SESSION_DIR||
|
|
27
27
|
join(homedir(),'.chat-loop','session'),'active-session.json');
|
|
28
28
|
function readNativePointer(){
|
|
@@ -97,9 +97,11 @@ loadTrustedRuntime() → Context Core → one Project SQLite`.
|
|
|
97
97
|
The Tools private handler passes a signed-IPC-verified Native projection into the Context trusted domain facade, which validates project binding, phase, RunRef and CAS. The private handler supports: `permit.consume`,
|
|
98
98
|
`run.bind.initial`, `run.fence`, `run.bind.handoff`,
|
|
99
99
|
`run.restore-same-owner`, `run.fence.terminal`,
|
|
100
|
-
`run.credential.rotate`, `run.terminalStatus`,
|
|
100
|
+
`run.credential.rotate`, `run.fence.cancel`, `run.terminalStatus`,
|
|
101
101
|
`run.reopenStatus`, `run.snapshot`.
|
|
102
102
|
|
|
103
|
+
`run.fence.cancel` is a Native/Worker-only, exact-Session idle Adopt cancellation transaction. It revokes the current writable Run credential, seals permits, records `CANCELLED_NOT_DELIVERED`, and never manufactures Task `DONE` or a `deliveryRef`. A matching Native BLOCKED Owner and verified private `session` Action request are prerequisites; after the Context receipt, Native checks the terminal marker again before allowing the `CANCELLED` Session CAS. Ordinary Context MCP clients cannot invoke this private command. An interrupted or unknown receipt stays BLOCKED pending original-request reconciliation; it is not permission to retry or clear the Owner.
|
|
104
|
+
|
|
103
105
|
The Browser Native Host now permits the Worker-used `run.reopenStatus`
|
|
104
106
|
through the same signed private IPC path; it is not a public MCP method.
|
|
105
107
|
For first-Start recovery, `run.terminalStatus` accepts the private
|
|
@@ -38,14 +38,15 @@ function sdkRuntime(){
|
|
|
38
38
|
if(!sdkPromise)sdkPromise=(async()=>{
|
|
39
39
|
const [
|
|
40
40
|
core,health,migrationCore,projectCore,taskCore,reviewCore,
|
|
41
|
-
evidenceCore,contextCore,runCore,migration,policy,methods,
|
|
41
|
+
evidenceCore,contextCore,runCore,cancelCore,migration,policy,methods,
|
|
42
42
|
projectStore,operations,lineReview
|
|
43
43
|
]=await Promise.all([
|
|
44
44
|
import('./lib/core/store.mjs'),import('./lib/core/health.mjs'),
|
|
45
45
|
import('./lib/core/migration.mjs'),import('./lib/core/project.mjs'),
|
|
46
46
|
import('./lib/core/task.mjs'),import('./lib/core/review.mjs'),
|
|
47
47
|
import('./lib/core/evidence.mjs'),import('./lib/core/context.mjs'),
|
|
48
|
-
import('./lib/core/run.mjs'),import('./lib/
|
|
48
|
+
import('./lib/core/run.mjs'),import('./lib/core/run-cancel.mjs'),
|
|
49
|
+
import('./lib/context-migration.mjs'),
|
|
49
50
|
import('./lib/approval-policy.mjs'),import('./lib/methods.mjs'),
|
|
50
51
|
import('./lib/project-store.mjs'),import('./lib/operations.mjs'),
|
|
51
52
|
import('./lib/line-review.mjs')
|
|
@@ -62,6 +63,7 @@ function sdkRuntime(){
|
|
|
62
63
|
createEvidenceMethods:evidenceCore.createEvidenceMethods,
|
|
63
64
|
createContextMethods:contextCore.createContextMethods,
|
|
64
65
|
createRunMethods:runCore.createRunMethods,
|
|
66
|
+
createCancelMethods:cancelCore.createCancelMethods,
|
|
65
67
|
verifySourceUnit:migration.verifySourceUnit,
|
|
66
68
|
inspectRegistryReferenceForReview:migration.inspectRegistryReferenceForReview,
|
|
67
69
|
hasApprovedPlan:policy.hasApprovedPlan,
|
|
@@ -36,7 +36,8 @@ export function createHealthMethods(values) {
|
|
|
36
36
|
bindingRevision:r.binding_revision,approvalRevision:r.approval_revision,
|
|
37
37
|
unknownEffectCount:unresolvedEffects(c).length,
|
|
38
38
|
runRef:r.writable_ref,executionOutcome:c.executionOutcome??null,
|
|
39
|
-
deliveryRef:c.deliveryRef??null
|
|
39
|
+
deliveryRef:c.deliveryRef??null,
|
|
40
|
+
sessionCancellation:c.sessionCancellation??null};
|
|
40
41
|
if(startRecoveryLeaseRef===null)return state;
|
|
41
42
|
// Read-only, scoped to the fresh lease. The prior expired leases were
|
|
42
43
|
// removed transactionally by reserve; no prior permit may exist.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Trusted Context Core transaction: idle Adopt cancellation is never Task delivery.
|
|
2
|
+
export function createCancelMethods(values){
|
|
3
|
+
const {internal,receipt,scope,expectedBusiness,expectedBinding,assert,
|
|
4
|
+
projectDrift,ensureNoPendingIssue,parse,unresolvedEffects,db}=values;
|
|
5
|
+
return {
|
|
6
|
+
fenceCancelledIdle(a){
|
|
7
|
+
// Formal Native/Worker-controlled idle Adopt exit, NOT task delivery.
|
|
8
|
+
// Native verifies the exact old blocked Owner before this transaction.
|
|
9
|
+
internal('run.fence.cancel',a);
|
|
10
|
+
return receipt(a,'run.fence.cancel',()=>{
|
|
11
|
+
const r=scope(a);
|
|
12
|
+
expectedBusiness(r,a.expectedTaskRevision);
|
|
13
|
+
expectedBinding(r,a.expectedBindingRevision);
|
|
14
|
+
assert(r.writable_ref!==null&&r.writable_ref===a.runRef
|
|
15
|
+
&&a.runRef===a.sessionId+':'+a.taskId+':'+a.generation,
|
|
16
|
+
'RUN_REF_MISMATCH');
|
|
17
|
+
assert(!r.pending_attempt,'HANDOFF_PENDING');
|
|
18
|
+
assert(r.writer_approval_revision===r.approval_revision,
|
|
19
|
+
'ACTIVE_RUN_APPROVAL_STALE');
|
|
20
|
+
assert(!projectDrift(r).projectDrift,'PROJECT_RULES_DRIFT');
|
|
21
|
+
ensureNoPendingIssue(a.projectId,a.taskId);
|
|
22
|
+
assert(a.reason==='USER_CANCELLED'
|
|
23
|
+
&&typeof a.actionToken==='string'&&a.actionToken.length>=8,
|
|
24
|
+
'CANCEL_INTENT_REQUIRED');
|
|
25
|
+
const context=parse(r.context_json);
|
|
26
|
+
assert(context.stage==='DRAFT'&&context.executionOutcome!=='DONE'
|
|
27
|
+
&&!context.deliveryRef&&!context.sessionCancellation
|
|
28
|
+
&&Array.isArray(context.progress)&&context.progress.length===0
|
|
29
|
+
&&Array.isArray(context.blockers)
|
|
30
|
+
&&unresolvedEffects(context).length===0,
|
|
31
|
+
'IDLE_CANCEL_UNSAFE');
|
|
32
|
+
const cancelled={status:'CANCELLED_NOT_DELIVERED',
|
|
33
|
+
oldRunRef:a.runRef,sessionId:a.sessionId,generation:a.generation,
|
|
34
|
+
requestId:a.writeRequestId,reason:'USER_CANCELLED',at:Date.now()};
|
|
35
|
+
const next={...context,sessionCancellation:cancelled,
|
|
36
|
+
blockers:[...(context.blockers||[]).filter(x=>x!=='SESSION_CANCELLED'),
|
|
37
|
+
'SESSION_CANCELLED']};
|
|
38
|
+
db.prepare(`UPDATE tasks SET writable_ref=NULL,credential_digest=NULL,
|
|
39
|
+
writer_approval_revision=NULL,binding_revision=binding_revision+1,
|
|
40
|
+
business_revision=business_revision+1,context_json=?
|
|
41
|
+
WHERE project_id=? AND task_id=?`)
|
|
42
|
+
.run(JSON.stringify(next),a.projectId,a.taskId);
|
|
43
|
+
// Old permits and start leases cannot be recycled as authority.
|
|
44
|
+
db.prepare("UPDATE permits SET kind='USED' WHERE project_id=? AND task_id=?")
|
|
45
|
+
.run(a.projectId,a.taskId);
|
|
46
|
+
db.prepare('DELETE FROM start_leases WHERE project_id=? AND task_id=?')
|
|
47
|
+
.run(a.projectId,a.taskId);
|
|
48
|
+
return {status:'CANCEL_FENCED',taskRevision:r.business_revision+1,
|
|
49
|
+
bindingRevision:r.binding_revision+1,executionOutcome:null,
|
|
50
|
+
oldRunRef:a.runRef};
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -24,6 +24,7 @@ export function createRunMethods(values) {
|
|
|
24
24
|
// Only a user-requested same-scope reopen may issue a repair lease.
|
|
25
25
|
assert(current.executionOutcome!=='DONE'&¤t.stage!=='ARCHIVED',
|
|
26
26
|
'TASK_ALREADY_DELIVERED');
|
|
27
|
+
assert(!current.sessionCancellation,'SESSION_CANCELLED_NEW_TASK_REQUIRED');
|
|
27
28
|
}
|
|
28
29
|
// Never re-reserve an initial Start whose execution permit may have
|
|
29
30
|
// been consumed. Expired, unconsumed leases cannot commit later.
|
|
@@ -7,14 +7,14 @@ import {dirname} from 'node:path';
|
|
|
7
7
|
|
|
8
8
|
// This module declares ports; index.mjs is the only dependency assembler.
|
|
9
9
|
// No implementation module imports another implementation module.
|
|
10
|
-
let createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches;
|
|
10
|
+
let createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, createCancelMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches;
|
|
11
11
|
let connected=false;
|
|
12
12
|
export function configureCore(capabilities){
|
|
13
13
|
if(connected)throw Error('CONTEXT_MODULE_ALREADY_COMPOSED');
|
|
14
|
-
for(const name of ['createHealthMethods', 'createMigrationMethods', 'createProjectMethods', 'createTaskMethods', 'createReviewMethods', 'createEvidenceMethods', 'createContextMethods', 'createRunMethods', 'verifySourceUnit', 'inspectRegistryReferenceForReview', 'hasApprovedPlan', 'hasRequirementApproval', 'approvedTurnSourceMatches']){
|
|
14
|
+
for(const name of ['createHealthMethods', 'createMigrationMethods', 'createProjectMethods', 'createTaskMethods', 'createReviewMethods', 'createEvidenceMethods', 'createContextMethods', 'createRunMethods', 'createCancelMethods', 'verifySourceUnit', 'inspectRegistryReferenceForReview', 'hasApprovedPlan', 'hasRequirementApproval', 'approvedTurnSourceMatches']){
|
|
15
15
|
if(capabilities?.[name]===undefined)throw Error('CONTEXT_MODULE_PORT_MISSING:'+name);
|
|
16
16
|
}
|
|
17
|
-
({createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches}=capabilities);
|
|
17
|
+
({createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, createCancelMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches}=capabilities);
|
|
18
18
|
connected=true;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -302,6 +302,7 @@ export function openContextProtocol(file,{authorizeInternal=()=>false,authorizeD
|
|
|
302
302
|
'writeFenceRevision','bindingRevision','taskRevision','storeEpoch',
|
|
303
303
|
'projectRuleReview','effectResolutions','projectId','taskId','stage','executionOutcome',
|
|
304
304
|
'deliveryRef','deliveredAt','acceptedAt','acceptance','acceptanceFeedback',
|
|
305
|
+
'sessionCancellation',
|
|
305
306
|
'reopenReason','reopenRequest','archivedAt','authority','migrationSourceUnitId',
|
|
306
307
|
'__proto__','prototype','constructor'
|
|
307
308
|
]);
|
|
@@ -390,6 +391,7 @@ export function openContextProtocol(file,{authorizeInternal=()=>false,authorizeD
|
|
|
390
391
|
createReviewMethods(scopeValues),
|
|
391
392
|
createEvidenceMethods(scopeValues),
|
|
392
393
|
createContextMethods(scopeValues),
|
|
393
|
-
createRunMethods(scopeValues)
|
|
394
|
+
createRunMethods(scopeValues),
|
|
395
|
+
createCancelMethods(scopeValues)
|
|
394
396
|
);
|
|
395
397
|
}
|
|
@@ -19,7 +19,7 @@ const fail=code=>Object.assign(new Error(code),{code});
|
|
|
19
19
|
const assert=(ok,code)=>{if(!ok)throw fail(code)};
|
|
20
20
|
const supported=new Set(['permit.consume','run.bind.initial','run.fence',
|
|
21
21
|
'run.bind.handoff','run.restore-same-owner','run.fence.terminal',
|
|
22
|
-
'run.credential.rotate','run.terminalStatus','run.reopenStatus','run.snapshot']);
|
|
22
|
+
'run.credential.rotate','run.fence.cancel','run.terminalStatus','run.reopenStatus','run.snapshot']);
|
|
23
23
|
|
|
24
24
|
export function executeTrustedRun(command,args,native){
|
|
25
25
|
assert(supported.has(command)&&args&&typeof args==='object'
|
|
@@ -47,7 +47,7 @@ export function executeTrustedRun(command,args,native){
|
|
|
47
47
|
assert(args.targetGeneration===native.generation+1,'TARGET_GENERATION_MISMATCH');
|
|
48
48
|
}
|
|
49
49
|
if(['run.fence','run.fence.terminal','run.bind.initial','run.bind.handoff',
|
|
50
|
-
'run.credential.rotate'].includes(command))
|
|
50
|
+
'run.credential.rotate','run.fence.cancel'].includes(command))
|
|
51
51
|
assert(args.runRef===native.sessionId+':'+native.taskId+':'+native.generation,
|
|
52
52
|
'RUN_REF_MISMATCH');
|
|
53
53
|
if(command==='permit.consume')
|
|
@@ -56,6 +56,9 @@ export function executeTrustedRun(command,args,native){
|
|
|
56
56
|
assert(native.phase==='WAITING_REPLY','NATIVE_PHASE_MISMATCH');
|
|
57
57
|
if(command==='run.credential.rotate')
|
|
58
58
|
assert(native.phase==='PENDING','NATIVE_PHASE_MISMATCH');
|
|
59
|
+
if(command==='run.fence.cancel')
|
|
60
|
+
assert(native.phase==='BLOCKED'&&args.reason==='USER_CANCELLED',
|
|
61
|
+
'CANCEL_NATIVE_NOT_BLOCKED');
|
|
59
62
|
if(command==='run.restore-same-owner')
|
|
60
63
|
assert(native.phase==='RESERVED','NATIVE_PHASE_MISMATCH');
|
|
61
64
|
if(command==='run.fence.terminal'||command==='run.reopenStatus')
|
|
@@ -77,6 +80,7 @@ export function executeTrustedRun(command,args,native){
|
|
|
77
80
|
case 'run.credential.rotate':return db.rotateCredential(args);
|
|
78
81
|
case 'run.bind.initial':return db.bindInitial({...args,ownerCommitted:true});
|
|
79
82
|
case 'run.fence':return db.fence(args);
|
|
83
|
+
case 'run.fence.cancel':return db.fenceCancelledIdle(args);
|
|
80
84
|
case 'run.fence.terminal':return db.fenceTerminal(args);
|
|
81
85
|
case 'run.bind.handoff':
|
|
82
86
|
return db.bindHandoff({...args,ownerCommitted:true,nativeCommitted:true});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-context",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.25",
|
|
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.33",
|
|
38
38
|
"@tomflow/chatloop-trace": "0.4.6"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -78,7 +78,7 @@ Run: chatloop-extension <command> --help
|
|
|
78
78
|
|
|
79
79
|
```text
|
|
80
80
|
Usage: chatloop-extension extension <command>
|
|
81
|
-
Commands: chat text | chat dom | chat screenshot | reload | continue | handoff | clean <tab-id> | status | start | entry test
|
|
81
|
+
Commands: chat text | chat dom | chat screenshot | reload | continue | handoff | clean <tab-id> | status | start | session | entry test
|
|
82
82
|
Run: chatloop-extension extension <command> --help
|
|
83
83
|
```
|
|
84
84
|
|
|
@@ -87,7 +87,10 @@ For the installed command list, run `chatloop-extension extension --help`.
|
|
|
87
87
|
`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
|
|
88
88
|
re-send. Continue/Handoff only register intents with one Turn token and never
|
|
89
89
|
silently send or repeat. Clean needs an exact verified tab ID, and Status
|
|
90
|
-
is read-only.
|
|
90
|
+
is read-only. The single `session` Action page accepts a private, exact
|
|
91
|
+
`operation:cancel` request only for an idle, Context-managed Adopt with no
|
|
92
|
+
business work or UNKNOWN effects. It fences the Context writer before Native
|
|
93
|
+
accepts `CANCELLED`, and never impersonates delivered `DONE`. A previously BLOCKED Session with a lost old Owner tab remains
|
|
91
94
|
`state:BLOCKED` (not `IDLE`) when Worker/Native identities agree; the
|
|
92
95
|
`oldOwnerTabStatus:MISSING_UNVERIFIED` diagnostic is not a replacement permit.
|
|
93
96
|
A missing ACTIVE Owner or mismatched Native pointer remains `UNVERIFIED`.
|
|
@@ -8,5 +8,6 @@ import {capability as a5} from './capabilities/handoff.mjs';
|
|
|
8
8
|
import {capability as a6} from './capabilities/clean.mjs';
|
|
9
9
|
import {capability as a7} from './capabilities/status.mjs';
|
|
10
10
|
import {capability as a8} from './capabilities/start.mjs';
|
|
11
|
-
import {capability as a9} from './capabilities/
|
|
12
|
-
|
|
11
|
+
import {capability as a9} from './capabilities/session.mjs';
|
|
12
|
+
import {capability as a10} from './capabilities/entry_test.mjs';
|
|
13
|
+
export const actionCapabilities=Object.freeze([a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10]);
|
|
@@ -21,6 +21,7 @@ const HELP={
|
|
|
21
21
|
'extension handoff':'Usage: chatloop-extension extension handoff (JSON intent on stdin)\nRequest early handoff or query receipt; does not transfer directly.',
|
|
22
22
|
'extension status':'Usage: chatloop-extension extension status\nRead-only, verified active Web Chat status.',
|
|
23
23
|
'extension start':'Usage: chatloop-extension extension start (JSON on stdin)\nStart a new task with prompt, or use mode=adopt (no prompt) to bind the only R/P-approved existing Chat without sending.',
|
|
24
|
+
'extension session':'Usage: chatloop-extension extension session (JSON intent on stdin)\nCancel only an exact Context-managed idle Adopt; does not deliver the Task.',
|
|
24
25
|
'extension entry test':'Usage: chatloop-extension extension entry test (JSON intent on stdin)\nTEST_ONLY: use the built-in Extension Action to create a new normal Chat, choose the actual native @ App, and send exactly once without a Browser Owner.'
|
|
25
26
|
};
|
|
26
27
|
function helpFor(args){
|
|
@@ -70,7 +71,8 @@ async function executeAction(action,intent) {
|
|
|
70
71
|
const descriptor=actionById.get(action);
|
|
71
72
|
const page=descriptor?.page;
|
|
72
73
|
if(!page)throw Object.assign(Error('Unknown action'),{code:'UNKNOWN_ACTION'});
|
|
73
|
-
const url='chrome-extension://'+config.extensionId+'/'+page+'?requestId='+req.id
|
|
74
|
+
const url='chrome-extension://'+config.extensionId+'/'+page+'?requestId='+req.id
|
|
75
|
+
+(action==='session'?'&operation='+intent.operation:'');
|
|
74
76
|
openAction(url);
|
|
75
77
|
const until=Date.now()+descriptor.waitMs;
|
|
76
78
|
while(Date.now()<until){
|
|
@@ -109,7 +111,8 @@ async function execute(argv) {
|
|
|
109
111
|
return {implemented:['capabilities','host install <extension-id>',
|
|
110
112
|
...actionCapabilities.map(cap=>'extension '+cap.cli.join(' ')+
|
|
111
113
|
(cap.kind==='owner-clean'?' <tab-id>':
|
|
112
|
-
['owner-intent','owner-start','
|
|
114
|
+
['owner-intent','owner-start','owner-session',
|
|
115
|
+
'entry-test'].includes(cap.kind)?' (JSON on stdin)':''))],
|
|
113
116
|
available:existsSync(configFile()),hostConfigured:existsSync(configFile())};
|
|
114
117
|
}
|
|
115
118
|
if(argv[0]==='host'&&argv[1]==='install'&&argv.length===3)return installHost(argv[2]);
|
|
@@ -58,9 +58,24 @@ process.stdin.on('data',async chunk=>{
|
|
|
58
58
|
throw Object.assign(Error('No Context-managed session'),{code:'CONTEXT_SESSION_UNBOUND'});
|
|
59
59
|
if(!['permit.consume','run.bind.initial','run.fence','run.bind.handoff',
|
|
60
60
|
'run.restore-same-owner','run.fence.terminal','run.credential.rotate',
|
|
61
|
+
'run.fence.cancel',
|
|
61
62
|
'run.terminalStatus','run.reopenStatus','run.snapshot'].includes(m.command)
|
|
62
63
|
||!m.args||typeof m.args!=='object'||Array.isArray(m.args))
|
|
63
64
|
throw Object.assign(Error('Invalid Context command'),{code:'CONTEXT_COMMAND_INVALID'});
|
|
65
|
+
if(m.command==='run.fence.cancel'){
|
|
66
|
+
const request=readRequest(m.args.actionToken);
|
|
67
|
+
const intent=request?.intent;
|
|
68
|
+
if(request?.action!=='session'||intent?.operation!=='cancel'
|
|
69
|
+
||intent.confirmed!==true||intent.sessionId!==session.sessionId
|
|
70
|
+
||intent.projectId!==session.projectId
|
|
71
|
+
||intent.taskId!==session.taskId
|
|
72
|
+
||intent.generation!==session.generation
|
|
73
|
+
||intent.contextStoreEpoch!==m.args.expectedStoreEpoch
|
|
74
|
+
||intent.expectedTaskRevision!==m.args.expectedTaskRevision
|
|
75
|
+
||intent.expectedBindingRevision!==m.args.expectedBindingRevision)
|
|
76
|
+
throw Object.assign(Error('Cancel authorization not verified'),
|
|
77
|
+
{code:'SESSION_CANCEL_SOURCE_UNVERIFIED'});
|
|
78
|
+
}
|
|
64
79
|
const own=new Set(['projectId','taskId','sessionId','generation','activeChatId',
|
|
65
80
|
'role','principal','internalAuthorized','ownerCommitted','nativeCommitted',
|
|
66
81
|
'sourceRunRef','oldActionTokenRevoked','workerRestored','nativeRestored','ownerStillSame']);
|
|
@@ -71,7 +86,8 @@ process.stdin.on('data',async chunk=>{
|
|
|
71
86
|
activeChatId:session.activeChatId};
|
|
72
87
|
if(m.command==='run.bind.initial'||m.command==='run.bind.handoff')
|
|
73
88
|
args.runRef=session.sessionId+':'+session.taskId+':'+session.generation;
|
|
74
|
-
if(['run.fence','run.fence.terminal','run.credential.rotate'
|
|
89
|
+
if(['run.fence','run.fence.terminal','run.credential.rotate',
|
|
90
|
+
'run.fence.cancel'].includes(m.command))
|
|
75
91
|
args.runRef=session.sessionId+':'+session.taskId+':'+session.generation;
|
|
76
92
|
const result=await nativeContextControl(m.command,args);
|
|
77
93
|
write({status:'OK',result});
|
|
@@ -80,9 +96,71 @@ process.stdin.on('data',async chunk=>{
|
|
|
80
96
|
const recorded=await nativeApiObservation(m.record);
|
|
81
97
|
write({status:recorded?'RECORDED':'DROPPED'});
|
|
82
98
|
}else if(m.op==='session-sync'){
|
|
99
|
+
// An idle cancellation may become terminal only after the original
|
|
100
|
+
// Context writer has been transactionally fenced. Native is the
|
|
101
|
+
// independent boundary: Worker cannot make a canceled owner by writing
|
|
102
|
+
// a plausible phase or by replaying a URL parameter.
|
|
103
|
+
if(m.session?.phase==='CANCELLED'){
|
|
104
|
+
const request=readRequest(m.cancelRequestId);
|
|
105
|
+
const intent=request?.intent;
|
|
106
|
+
if(request?.action!=='session'||intent?.operation!=='cancel'
|
|
107
|
+
||intent.confirmed!==true||intent.sessionId!==m.session.sessionId
|
|
108
|
+
||intent.projectId!==m.session.projectId
|
|
109
|
+
||intent.taskId!==m.session.taskId
|
|
110
|
+
||intent.generation!==m.session.generation)
|
|
111
|
+
throw Object.assign(Error('Cancel source not verified'),
|
|
112
|
+
{code:'SESSION_CANCEL_SOURCE_UNVERIFIED'});
|
|
113
|
+
const old=readSession();
|
|
114
|
+
if(!old||old.phase!=='BLOCKED'||!old.taskId
|
|
115
|
+
||old.sessionId!==m.session.sessionId
|
|
116
|
+
||old.projectId!==m.session.projectId
|
|
117
|
+
||old.generation!==m.session.generation
|
|
118
|
+
||old.updatedAt!==m.cancelBlockedUpdatedAt)
|
|
119
|
+
throw Object.assign(Error('Cancel Native CAS failed'),
|
|
120
|
+
{code:'SESSION_CANCEL_CAS_MISMATCH'});
|
|
121
|
+
const terminal=await nativeContextControl('run.terminalStatus',{
|
|
122
|
+
projectId:old.projectId,taskId:old.taskId,sessionId:old.sessionId,
|
|
123
|
+
generation:old.generation,activeChatId:old.activeChatId});
|
|
124
|
+
const cancelled=terminal?.sessionCancellation;
|
|
125
|
+
if(terminal?.runRef!==null||terminal?.executionOutcome!==null
|
|
126
|
+
||cancelled?.status!=='CANCELLED_NOT_DELIVERED'
|
|
127
|
+
||cancelled.requestId!=='cancel-'+m.cancelRequestId
|
|
128
|
+
||cancelled?.sessionId!==old.sessionId
|
|
129
|
+
||cancelled?.generation!==old.generation
|
|
130
|
+
||cancelled?.oldRunRef!==old.sessionId+':'+old.taskId+':'+old.generation)
|
|
131
|
+
throw Object.assign(Error('Context cancellation not fenced'),
|
|
132
|
+
{code:'CONTEXT_CANCEL_FENCE_UNVERIFIED'});
|
|
133
|
+
}else if(m.session?.phase==='BLOCKED'
|
|
134
|
+
&&m.cancelFreezeExpectedAt!==undefined){
|
|
135
|
+
const req=readRequest(m.cancelRequestId),intent=req?.intent;
|
|
136
|
+
const old=readSession();
|
|
137
|
+
if(req?.action!=='session'||intent?.operation!=='cancel'
|
|
138
|
+
||intent.confirmed!==true||!old
|
|
139
|
+
||old.phase!=='WAITING_REPLY'
|
|
140
|
+
||old.sessionId!==m.session.sessionId
|
|
141
|
+
||old.projectId!==m.session.projectId
|
|
142
|
+
||old.taskId!==m.session.taskId
|
|
143
|
+
||old.generation!==m.session.generation
|
|
144
|
+
||old.activeChatId!==m.session.activeChatId
|
|
145
|
+
||old.activeChatUrl!==m.session.activeChatUrl
|
|
146
|
+
||intent.sessionId!==old.sessionId
|
|
147
|
+
||intent.projectId!==old.projectId
|
|
148
|
+
||intent.taskId!==old.taskId
|
|
149
|
+
||intent.generation!==old.generation
|
|
150
|
+
||intent.expectedNativeUpdatedAt!==m.cancelFreezeExpectedAt
|
|
151
|
+
||old.updatedAt!==m.cancelFreezeExpectedAt)
|
|
152
|
+
throw Object.assign(Error('Invalid cancellation freeze'),
|
|
153
|
+
{code:'SESSION_CANCEL_FREEZE_CAS_MISMATCH'});
|
|
154
|
+
}else if(Object.hasOwn(m,'cancelBlockedUpdatedAt')
|
|
155
|
+
||Object.hasOwn(m,'cancelFreezeExpectedAt')
|
|
156
|
+
||Object.hasOwn(m,'cancelRequestId'))
|
|
157
|
+
throw Object.assign(Error('Invalid cancel transition'),
|
|
158
|
+
{code:'SESSION_CANCEL_CAS_MISMATCH'});
|
|
83
159
|
write({status:'OK',session:writeSession(m.session,
|
|
84
160
|
m.replaceBlockedSessionId,m.resumeBlockedSessionId,
|
|
85
|
-
m.resumeBlockedUpdatedAt??null,m.sameTaskPrePermitUpdatedAt??null
|
|
161
|
+
m.resumeBlockedUpdatedAt??null,m.sameTaskPrePermitUpdatedAt??null,
|
|
162
|
+
m.cancelBlockedUpdatedAt??null,
|
|
163
|
+
m.cancelFreezeExpectedAt??null)});
|
|
86
164
|
}else throw Object.assign(Error('Unknown operation'),{code:'INVALID_OPERATION'});
|
|
87
165
|
};
|
|
88
166
|
// The telemetry operation is intentionally excluded from self-recording.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const capability=Object.freeze({id:'session',page:'session.html',cli:['session'],kind:'owner-session',waitMs:90000,textResult:true,description:'Exact Owner lifecycle operation (cancel idle Adopt only)'});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// One built-in lifecycle Action page. Query string locates a private CLI
|
|
2
|
+
// request; its operation and authorization are read from Native acquire.
|
|
3
|
+
const host='com.tomflow.chatloop.extension';
|
|
4
|
+
const statusNode=document.getElementById('status');
|
|
5
|
+
const detailsNode=document.getElementById('details');
|
|
6
|
+
const show=(status,text)=>{statusNode.textContent=status;
|
|
7
|
+
detailsNode.textContent=text;document.body.dataset.result=status==='SUCCESS'?'success':'error'};
|
|
8
|
+
async function run(){
|
|
9
|
+
const own=await chrome.tabs.getCurrent(),params=new URLSearchParams(location.search);
|
|
10
|
+
const id=params.get('requestId');
|
|
11
|
+
if(!own?.id||own.url!==location.href||[...params.keys()].join(',')!=='requestId,operation'
|
|
12
|
+
||params.get('operation')!=='cancel'||!/^[a-f0-9]{32}$/.test(id||''))
|
|
13
|
+
throw Error('INVALID_SESSION_ACTION');
|
|
14
|
+
const acquired=await chrome.runtime.sendNativeMessage(host,{
|
|
15
|
+
op:'acquire',id,action:'session'
|
|
16
|
+
});
|
|
17
|
+
if(acquired?.status!=='OK'||acquired.id!==id
|
|
18
|
+
||acquired.action!=='session'||typeof acquired.nonce!=='string'
|
|
19
|
+
||acquired.intent?.operation!=='cancel')
|
|
20
|
+
throw Error(acquired?.code||'SESSION_INTENT_UNVERIFIED');
|
|
21
|
+
show('RUNNING','核验 Session、停止调度并撤销 Context 写权…');
|
|
22
|
+
let result;
|
|
23
|
+
try{
|
|
24
|
+
result=await chrome.runtime.sendMessage({
|
|
25
|
+
type:'CHAT_LOOP_SESSION_CONTROL_V1',requestId:id,operation:'cancel'
|
|
26
|
+
});
|
|
27
|
+
if(result?.status!=='OK'||result.state!=='CANCELLED_NOT_DELIVERED')
|
|
28
|
+
throw Error(result?.code||'SESSION_CANCEL_UNVERIFIED');
|
|
29
|
+
const receipt=await chrome.runtime.sendNativeMessage(host,{
|
|
30
|
+
op:'complete',id,nonce:acquired.nonce,action:'session',
|
|
31
|
+
status:'OK',payload:JSON.stringify(result)
|
|
32
|
+
});
|
|
33
|
+
if(receipt?.status!=='SAVED'||receipt.id!==id)
|
|
34
|
+
throw Error(receipt?.code||'SESSION_RESULT_UNVERIFIED');
|
|
35
|
+
show('SUCCESS','Session 已安全取消;业务任务未交付。');
|
|
36
|
+
await chrome.tabs.remove(own.id);
|
|
37
|
+
}catch(error){
|
|
38
|
+
// The Worker may have fenced Context before a transport failure. Never
|
|
39
|
+
// retry a mutation; the original request and persisted receipt are proof.
|
|
40
|
+
const raw=error?.message;
|
|
41
|
+
const code=/^[A-Z][A-Z0-9_]{1,95}$/.test(raw||'')?raw:'SESSION_CANCEL_UNVERIFIED';
|
|
42
|
+
const receipt=await chrome.runtime.sendNativeMessage(host,{
|
|
43
|
+
op:'complete',id,nonce:acquired.nonce,action:'session',
|
|
44
|
+
status:'FAILED',code
|
|
45
|
+
}).catch(()=>null);
|
|
46
|
+
show('BLOCKED',code);
|
|
47
|
+
if(receipt?.status==='SAVED'&&receipt.id===id)
|
|
48
|
+
await chrome.tabs.remove(own.id).catch(()=>{});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
void run().catch(e=>show('UNVERIFIED',
|
|
52
|
+
/^[A-Z][A-Z0-9_]{1,95}$/.test(e?.message||'')?e.message:'SESSION_ACTION_UNVERIFIED'));
|
|
@@ -5,6 +5,7 @@ importScripts("worker/bootstrap.js");
|
|
|
5
5
|
importScripts("worker/admission.js");
|
|
6
6
|
importScripts("worker/adopt-prepare.js");
|
|
7
7
|
importScripts("worker/adopt-result.js");
|
|
8
|
+
importScripts("worker/session-control.js");
|
|
8
9
|
importScripts("worker/readiness.js");
|
|
9
10
|
importScripts("worker/turn-failure.js");
|
|
10
11
|
importScripts("worker/turn-finished.js");
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
const TERMINAL_TTL = 30_000;
|
|
10
10
|
const READ_ONLY = new Set(['status','text','dom','screenshot','reload']);
|
|
11
11
|
const ACTIONS = new Set(['start','continue','handoff','status','text','dom',
|
|
12
|
-
'screenshot','reload','clean']);
|
|
12
|
+
'screenshot','reload','clean','session']);
|
|
13
13
|
const validId = s => /^[a-f0-9]{32}$/.test(s || '');
|
|
14
14
|
const validTabId = s => /^[1-9][0-9]*$/.test(s || '');
|
|
15
15
|
const extensionBase = () => chrome.runtime.getURL('');
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
return {kind:'audit'}; // Legacy page reaping only; old audit UI is not executable.
|
|
24
24
|
const name = u.pathname.match(/^\/([a-z]+)\.html$/)?.[1];
|
|
25
25
|
if (!ACTIONS.has(name)) return null;
|
|
26
|
+
if (name==='session' && u.searchParams.size===2
|
|
27
|
+
&& validId(u.searchParams.get('requestId'))
|
|
28
|
+
&& u.searchParams.get('operation')==='cancel')
|
|
29
|
+
return {kind:'machine',name,requestId:u.searchParams.get('requestId')};
|
|
26
30
|
if (u.searchParams.size === 1 && validId(u.searchParams.get('requestId')))
|
|
27
31
|
return {kind:READ_ONLY.has(name) || ['continue','handoff'].includes(name)
|
|
28
32
|
? 'read-only' : 'machine', name, requestId:u.searchParams.get('requestId')};
|
|
@@ -155,9 +159,9 @@
|
|
|
155
159
|
// neither is permission to send. A recovered same-Session Owner counts
|
|
156
160
|
// again even when its ledger still records an earlier BLOCKED phase.
|
|
157
161
|
const activeChatCount=liveChatEntries.filter(e=>
|
|
158
|
-
!['DONE','BLOCKED'].includes(e.terminal)
|
|
162
|
+
!['DONE','BLOCKED','CANCELLED'].includes(e.terminal)
|
|
159
163
|
||(e.sessionId===(run?.sessionId||run?.token)
|
|
160
|
-
&&!['DONE','BLOCKED'].includes(run?.phase))).length;
|
|
164
|
+
&&!['DONE','BLOCKED','CANCELLED'].includes(run?.phase))).length;
|
|
161
165
|
const unownedHomes=after.filter(t=>t.url==='https://chatgpt.com/'
|
|
162
166
|
&& !state.entries.some(e=>e.kind==='chat'&&e.id===t.id)).length;
|
|
163
167
|
state.peakActions=Math.max(state.peakActions,actionCount);
|
|
@@ -243,7 +247,8 @@
|
|
|
243
247
|
await save(state);
|
|
244
248
|
}
|
|
245
249
|
async function terminal(run) {
|
|
246
|
-
if (!(run?.sessionId||run?.token)
|
|
250
|
+
if (!(run?.sessionId||run?.token)
|
|
251
|
+
|| !['DONE','BLOCKED','CANCELLED'].includes(run.phase)) return;
|
|
247
252
|
const state=await load();
|
|
248
253
|
for(const entry of state.entries) if(entry.kind==='chat'
|
|
249
254
|
&&entry.sessionId===(run.sessionId||run.token)) entry.terminal=run.phase;
|
|
@@ -0,0 +1,6 @@
|
|
|
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>
|
|
@@ -103,7 +103,7 @@ async function sessionStartPrepare(message,sender){
|
|
|
103
103
|
&&(prior.projectId!==intent.projectId||independentTask
|
|
104
104
|
||prePermitRecovery)||preNativeGhost||driftReplacement);
|
|
105
105
|
if(replace&&!matchingBlocked)return {status:'DENIED',code:'BLOCKED_REPLACEMENT_MISMATCH'};
|
|
106
|
-
if(prior
|
|
106
|
+
if(prior&&!['DONE','CANCELLED'].includes(prior.phase)&&!matchingBlocked)
|
|
107
107
|
return {status:'DENIED',code:'LOOP_ALREADY_ACTIVE'};
|
|
108
108
|
const ownerMatches=Boolean(prior?.sessionId&&disk.session
|
|
109
109
|
&&matchesNativeProjection(sessionProjection(prior),disk.session));
|
|
@@ -136,8 +136,20 @@ async function sessionStartPrepare(message,sender){
|
|
|
136
136
|
}
|
|
137
137
|
// A terminal Worker record cannot authorize a new Start if a different
|
|
138
138
|
// durable Native Owner exists under the same Browser installation.
|
|
139
|
-
if(prior?.phase
|
|
139
|
+
if(['DONE','CANCELLED'].includes(prior?.phase)&&prior.sessionId
|
|
140
|
+
&&disk.session&&!ownerMatches)
|
|
140
141
|
return {status:'DENIED',code:'SESSION_OWNER_MISMATCH'};
|
|
142
|
+
if(prior?.phase==='CANCELLED'){
|
|
143
|
+
// Never treat Worker CANCELLED alone as a fresh Start permit.
|
|
144
|
+
const verified=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
145
|
+
op:'context-control',command:'run.terminalStatus',args:{}}).catch(()=>null);
|
|
146
|
+
const canceled=verified?.result?.sessionCancellation;
|
|
147
|
+
if(disk.session?.phase!=='CANCELLED'||verified?.status!=='OK'
|
|
148
|
+
||verified.result.runRef!==null||canceled?.status!=='CANCELLED_NOT_DELIVERED'
|
|
149
|
+
||canceled.sessionId!==prior.sessionId
|
|
150
|
+
||canceled.generation!==prior.generation)
|
|
151
|
+
return {status:'DENIED',code:'CONTEXT_CANCEL_FENCE_UNVERIFIED'};
|
|
152
|
+
}
|
|
141
153
|
// An abandoned Managed Context writer can outlive its Browser Owner.
|
|
142
154
|
// Replacing the Native session without first verifying its terminal fence
|
|
143
155
|
// would strand a live runRef (and an old write credential) in the Store.
|
|
@@ -152,7 +164,8 @@ async function sessionStartPrepare(message,sender){
|
|
|
152
164
|
||typeof state.deliveryRef!=='string'||!state.deliveryRef)
|
|
153
165
|
return {status:'DENIED',code:'CONTEXT_BLOCKED_RUN_UNFENCED'};
|
|
154
166
|
}
|
|
155
|
-
if(disk.session
|
|
167
|
+
if(disk.session&&!['DONE','CANCELLED'].includes(disk.session.phase)
|
|
168
|
+
&&!matchingBlocked)
|
|
156
169
|
return {status:'DENIED',code:'SESSION_ALREADY_ACTIVE'};
|
|
157
170
|
const capacity=await resources.admit(prior,{kind:intent.mode==='adopt'?'action':'chat'});
|
|
158
171
|
if(!capacity.ok)return {status:'DENIED',code:capacity.code};
|
|
@@ -96,7 +96,13 @@ async function saveRun(run) {
|
|
|
96
96
|
// Native must commit first for the exact terminal CAS transitions.
|
|
97
97
|
const replacementCommit=Boolean(next.replacedBlockedSessionId
|
|
98
98
|
&&next.phase==='STARTING'&&stored?.sessionId!==next.sessionId);
|
|
99
|
-
|
|
99
|
+
// Cancel must commit Native terminal CAS before exposing Worker CANCELLED.
|
|
100
|
+
// A missing Native reply leaves Worker BLOCKED, never falsely IDLE.
|
|
101
|
+
const cancelFreeze=next.reason==='SESSION_CANCEL_PENDING'
|
|
102
|
+
&&next.phase==='BLOCKED'&&stored?.phase==='WAITING_REPLY'
|
|
103
|
+
&&Number.isSafeInteger(next.cancelFreezeExpectedAt);
|
|
104
|
+
const nativeFirst=recoveryCommit||replacementCommit
|
|
105
|
+
||next.phase==='CANCELLED'||cancelFreeze;
|
|
100
106
|
const syncNative=async()=>{
|
|
101
107
|
if(!next.sessionId)return;
|
|
102
108
|
const record=sessionProjection(next);
|
|
@@ -107,7 +113,13 @@ async function saveRun(run) {
|
|
|
107
113
|
...(Number.isSafeInteger(next.sameTaskPrePermitUpdatedAt)
|
|
108
114
|
?{sameTaskPrePermitUpdatedAt:next.sameTaskPrePermitUpdatedAt}:{})}:{}),
|
|
109
115
|
...(recoveryCommit?{resumeBlockedSessionId:next.sessionId,
|
|
110
|
-
resumeBlockedUpdatedAt:next.recoveryExpectedNativeAt}:{})
|
|
116
|
+
resumeBlockedUpdatedAt:next.recoveryExpectedNativeAt}:{}),
|
|
117
|
+
...(next.phase==='CANCELLED'
|
|
118
|
+
?{cancelBlockedUpdatedAt:next.cancelBlockedUpdatedAt,
|
|
119
|
+
cancelRequestId:next.cancelRequestId}:{}),
|
|
120
|
+
...(cancelFreeze
|
|
121
|
+
?{cancelFreezeExpectedAt:next.cancelFreezeExpectedAt,
|
|
122
|
+
cancelRequestId:next.cancelRequestId}:{})}).catch(()=>null);
|
|
111
123
|
// A fresh replacement Session ID identifies this exact CAS. If its
|
|
112
124
|
// transport reply was lost, confirm the durable projection once, without
|
|
113
125
|
// replaying the write. Same-ID recovery has no such unique commit proof.
|
|
@@ -129,7 +141,7 @@ async function saveRun(run) {
|
|
|
129
141
|
await chrome.storage.local.set({[RUN_KEY]:next});
|
|
130
142
|
if(!nativeFirst)await syncNative();
|
|
131
143
|
// The resource inventory is derived evidence; it never grants browser Owner.
|
|
132
|
-
if (["DONE","BLOCKED"].includes(next.phase)
|
|
144
|
+
if (["DONE","BLOCKED","CANCELLED"].includes(next.phase)
|
|
133
145
|
&& next.contextTerminalFence !== "PENDING"
|
|
134
146
|
&& next.contextTerminalFence !== "UNVERIFIED")
|
|
135
147
|
await resources.terminal(next).catch(()=>{});
|
|
@@ -124,6 +124,19 @@ async function entryTestAdmission(message,sender){
|
|
|
124
124
|
return !run.contextManaged||run.taskId&&terminalFenceVerified(run)
|
|
125
125
|
?{status:'OK',scope:'TEST_ONLY'}
|
|
126
126
|
:{status:'DENIED',code:'ENTRY_TEST_UNFENCED'};
|
|
127
|
+
if(run.phase==='CANCELLED'){
|
|
128
|
+
const checked=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
129
|
+
op:'context-control',command:'run.terminalStatus',args:{}
|
|
130
|
+
}).catch(()=>null);
|
|
131
|
+
const cancelled=checked?.result?.sessionCancellation;
|
|
132
|
+
return record.phase==='CANCELLED'&&checked?.status==='OK'
|
|
133
|
+
&&checked.result.runRef===null
|
|
134
|
+
&&cancelled?.status==='CANCELLED_NOT_DELIVERED'
|
|
135
|
+
&&cancelled.sessionId===run.sessionId
|
|
136
|
+
&&cancelled.generation===run.generation
|
|
137
|
+
?{status:'OK',scope:'TEST_ONLY'}
|
|
138
|
+
:{status:'DENIED',code:'ENTRY_TEST_CANCEL_FENCE_UNVERIFIED'};
|
|
139
|
+
}
|
|
127
140
|
if(run.phase!=='BLOCKED'||run.contextManaged&&(!run.taskId||!terminalFenceVerified(run))
|
|
128
141
|
||!Number.isSafeInteger(run.tabId)||!pathOf('https://chatgpt.com'+run.page))
|
|
129
142
|
return {status:'DENIED',code:'ENTRY_TEST_ACTIVE_OWNER'};
|
|
@@ -181,6 +194,19 @@ async function sessionStatus(message,sender){
|
|
|
181
194
|
return {status:'OK',state:'LEGACY_OWNER',phase:run.phase};
|
|
182
195
|
if(run?.phase==='DONE'&&!terminalFenceVerified(run))
|
|
183
196
|
return {status:'UNVERIFIED',code:'CONTEXT_TERMINAL_FENCE_UNVERIFIED'};
|
|
197
|
+
if(run?.phase==='CANCELLED'){
|
|
198
|
+
const proof=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
199
|
+
op:'context-control',command:'run.terminalStatus',args:{}}).catch(()=>null);
|
|
200
|
+
const canceled=proof?.result?.sessionCancellation;
|
|
201
|
+
if(proof?.status!=='OK'||proof.result.runRef!==null
|
|
202
|
+
||canceled?.status!=='CANCELLED_NOT_DELIVERED'
|
|
203
|
+
||canceled.sessionId!==run.sessionId
|
|
204
|
+
||canceled.generation!==run.generation
|
|
205
|
+
||disk.session?.phase!=='CANCELLED')
|
|
206
|
+
return {status:'UNVERIFIED',code:'CONTEXT_CANCEL_FENCE_UNVERIFIED'};
|
|
207
|
+
return {status:'OK',state:'IDLE',lastSession:disk.session,
|
|
208
|
+
terminalReason:'CANCELLED_NOT_DELIVERED'};
|
|
209
|
+
}
|
|
184
210
|
if(!run||run.phase==='DONE')return {status:'OK',state:'IDLE',
|
|
185
211
|
...(disk.session?{lastSession:disk.session}:{} )};
|
|
186
212
|
const record=sessionProjection(run);
|
|
@@ -198,7 +224,9 @@ async function sessionStatus(message,sender){
|
|
|
198
224
|
// Native/Worker identity above must still match; the independent new
|
|
199
225
|
// Start must separately prove the exact replacement and Context fence.
|
|
200
226
|
if(run.phase!=='BLOCKED')
|
|
201
|
-
return {status:'UNVERIFIED',code:'OWNER_TAB_MISSING',session:
|
|
227
|
+
return {status:'UNVERIFIED',code:'OWNER_TAB_MISSING',session:disk.session,
|
|
228
|
+
diagnostics:{extensionVersion:chrome.runtime.getManifest?.().version||null,
|
|
229
|
+
ownerTabId:null,ownerLocatorState:tab?'URL_MISMATCH':'TAB_LOOKUP_UNVERIFIED'}};
|
|
202
230
|
blockedOwnerTabMissing=true;
|
|
203
231
|
}
|
|
204
232
|
}
|
|
@@ -68,6 +68,7 @@ const SERIAL_ROUTES=new Map([
|
|
|
68
68
|
['CHAT_LOOP_SESSION_START_TAKE_V1',sessionStartTake],
|
|
69
69
|
['CHAT_LOOP_SESSION_START_RESULT_V1',sessionStartResult],
|
|
70
70
|
['CHAT_LOOP_SESSION_STATUS_V1',sessionStatus],
|
|
71
|
+
['CHAT_LOOP_SESSION_CONTROL_V1',sessionControl],
|
|
71
72
|
['CHAT_LOOP_ENTRY_TEST_ADMISSION_V1',entryTestAdmission],
|
|
72
73
|
['CHAT_LOOP_RESOURCE_CHAT_V1',resourceChatGate]
|
|
73
74
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Single Worker Owner lifecycle operation. This does not send Chat messages,
|
|
2
|
+
// claim another Owner or finish the business Task.
|
|
3
|
+
async function sessionControl(message,sender){
|
|
4
|
+
if(!Number.isInteger(sender.tab?.id)
|
|
5
|
+
||sender.url!==chrome.runtime.getURL('session.html')
|
|
6
|
+
+'?requestId='+message.requestId+'&operation=cancel'
|
|
7
|
+
||!/^[a-f0-9]{32}$/.test(message.requestId||''))
|
|
8
|
+
return {status:'DENIED',code:'INVALID_SESSION_SOURCE'};
|
|
9
|
+
// URL parameters locate a private request, never authorize mutation.
|
|
10
|
+
const request=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
11
|
+
op:'acquire',id:message.requestId,action:'session'
|
|
12
|
+
}).catch(()=>null);
|
|
13
|
+
const intent=request?.intent;
|
|
14
|
+
if(request?.status!=='OK'||request.id!==message.requestId
|
|
15
|
+
||request.action!=='session'||intent?.operation!=='cancel'
|
|
16
|
+
||message.operation!=='cancel'||intent.confirmed!==true)
|
|
17
|
+
return {status:'DENIED',code:'SESSION_INTENT_UNVERIFIED'};
|
|
18
|
+
const run=await readRun();
|
|
19
|
+
const id=run?.sessionId;
|
|
20
|
+
// V1 intentionally supports ONLY a started but never executing Adopt.
|
|
21
|
+
// A missing browser tab cannot be used to invent an Owner or cancel work.
|
|
22
|
+
if(!id||id!==intent.sessionId
|
|
23
|
+
||run.projectId!==intent.projectId||run.taskId!==intent.taskId
|
|
24
|
+
||run.generation!==intent.generation||run.phase!=='WAITING_REPLY'
|
|
25
|
+
||run.reason!=='ADOPTED_IDLE_BASELINE'||run.action!=='START'
|
|
26
|
+
||!run.contextManaged?.storeEpoch
|
|
27
|
+
||run.contextManaged.storeEpoch!==intent.contextStoreEpoch
|
|
28
|
+
||run.modelIntent?.action ||run.pendingAttempt ||run.contextHandoff)
|
|
29
|
+
return {status:'DENIED',code:'SESSION_CANCEL_NOT_IDLE'};
|
|
30
|
+
const before=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
31
|
+
op:'session-read'
|
|
32
|
+
}).catch(()=>null);
|
|
33
|
+
if(before?.status!=='OK'
|
|
34
|
+
||!matchesNativeProjection(sessionProjection(run),before.session)
|
|
35
|
+
||before.session.updatedAt!==intent.expectedNativeUpdatedAt)
|
|
36
|
+
return {status:'DENIED',code:'SESSION_CANCEL_NATIVE_MISMATCH'};
|
|
37
|
+
// Stop scheduling FIRST. Do not release Native ID or Context writer here.
|
|
38
|
+
const stopped={...run,phase:'BLOCKED',
|
|
39
|
+
reason:'SESSION_CANCEL_PENDING',cancelRequestId:message.requestId,
|
|
40
|
+
cancelFreezeExpectedAt:intent.expectedNativeUpdatedAt};
|
|
41
|
+
await saveRun(stopped);
|
|
42
|
+
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
43
|
+
op:'session-read'
|
|
44
|
+
}).catch(()=>null);
|
|
45
|
+
if(disk?.status!=='OK'||disk.session?.phase!=='BLOCKED'
|
|
46
|
+
||!matchesNativeProjection(sessionProjection(stopped),disk.session))
|
|
47
|
+
return {status:'BLOCKED',code:'SESSION_CANCEL_FREEZE_UNVERIFIED'};
|
|
48
|
+
const writeRequestId='cancel-'+message.requestId;
|
|
49
|
+
const fenced=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
50
|
+
op:'context-control',command:'run.fence.cancel',
|
|
51
|
+
args:{expectedStoreEpoch:intent.contextStoreEpoch,
|
|
52
|
+
writeRequestId,expectedTaskRevision:intent.expectedTaskRevision,
|
|
53
|
+
expectedBindingRevision:intent.expectedBindingRevision,
|
|
54
|
+
actionToken:message.requestId,reason:'USER_CANCELLED'}
|
|
55
|
+
}).catch(()=>null);
|
|
56
|
+
if(fenced?.status!=='OK'||fenced.result?.status!=='CANCEL_FENCED')
|
|
57
|
+
return {status:'BLOCKED',code:fenced?.code||'CONTEXT_CANCEL_FENCE_UNVERIFIED'};
|
|
58
|
+
// A business receipt alone is not enough; read back the same durable state.
|
|
59
|
+
const observed=await chrome.runtime.sendNativeMessage(SESSION_HOST,{
|
|
60
|
+
op:'context-control',command:'run.terminalStatus',args:{}
|
|
61
|
+
}).catch(()=>null);
|
|
62
|
+
const c=observed?.result?.sessionCancellation;
|
|
63
|
+
if(observed?.status!=='OK'||observed.result.runRef!==null
|
|
64
|
+
||c?.status!=='CANCELLED_NOT_DELIVERED'
|
|
65
|
+
||c.requestId!==writeRequestId||c.sessionId!==id
|
|
66
|
+
||c.generation!==run.generation)
|
|
67
|
+
return {status:'BLOCKED',code:'CONTEXT_CANCEL_FENCE_UNVERIFIED'};
|
|
68
|
+
const next={...stopped,phase:'CANCELLED',reason:'SESSION_CANCELLED',
|
|
69
|
+
cancelBlockedUpdatedAt:disk.session.updatedAt,
|
|
70
|
+
contextCancelFence:'CONFIRMED'};
|
|
71
|
+
// The Native Host validates Context again, then exact BLOCKED CAS.
|
|
72
|
+
await saveRun(next);
|
|
73
|
+
return {status:'OK',state:'CANCELLED_NOT_DELIVERED',sessionId:id,
|
|
74
|
+
taskId:run.taskId,bindingRevision:observed.result.bindingRevision};
|
|
75
|
+
}
|
|
@@ -12,7 +12,8 @@ export function matchExtensionAction(catalog,argv){
|
|
|
12
12
|
&&Number.isSafeInteger(Number(input.at(-1))))
|
|
13
13
|
return {id:cap.id,intent:{tabId:Number(input.at(-1))}};
|
|
14
14
|
if(input.length===route.length&&input.join(' ')===route.join(' '))
|
|
15
|
-
return {id:cap.id,needsIntent:['owner-intent','owner-start','
|
|
15
|
+
return {id:cap.id,needsIntent:['owner-intent','owner-start','owner-session',
|
|
16
|
+
'entry-test'].includes(cap.kind)};
|
|
16
17
|
}
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
@@ -61,6 +61,31 @@ export function requestDir(id) {
|
|
|
61
61
|
return join(tempRoot(),id);
|
|
62
62
|
}
|
|
63
63
|
function validateIntent(action, intent) {
|
|
64
|
+
if(action==='session'){
|
|
65
|
+
const ID=/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;
|
|
66
|
+
const UUID=/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
67
|
+
const keys=['operation','projectId','taskId','sessionId','generation',
|
|
68
|
+
'expectedNativeUpdatedAt','expectedTaskRevision',
|
|
69
|
+
'expectedBindingRevision','contextStoreEpoch','confirmed'];
|
|
70
|
+
if(!intent||typeof intent!=='object'||Array.isArray(intent)
|
|
71
|
+
||Object.keys(intent).length!==keys.length
|
|
72
|
+
||keys.some(k=>!Object.hasOwn(intent,k))
|
|
73
|
+
||intent.operation!=='cancel'||intent.confirmed!==true
|
|
74
|
+
||!ID.test(intent.projectId||'')||!ID.test(intent.taskId||'')
|
|
75
|
+
||!UUID.test(intent.sessionId||'')
|
|
76
|
+
||!Number.isSafeInteger(intent.generation)||intent.generation<0
|
|
77
|
+
||!Number.isSafeInteger(intent.expectedNativeUpdatedAt)
|
|
78
|
+
||intent.expectedNativeUpdatedAt<=0
|
|
79
|
+
||!Number.isSafeInteger(intent.expectedTaskRevision)
|
|
80
|
+
||intent.expectedTaskRevision<1
|
|
81
|
+
||!Number.isSafeInteger(intent.expectedBindingRevision)
|
|
82
|
+
||intent.expectedBindingRevision<1
|
|
83
|
+
||typeof intent.contextStoreEpoch!=='string'
|
|
84
|
+
||intent.contextStoreEpoch.length<10||intent.contextStoreEpoch.length>128)
|
|
85
|
+
throw Object.assign(Error('Exact session cancellation required'),
|
|
86
|
+
{code:'INVALID_SESSION_INTENT'});
|
|
87
|
+
return {...intent};
|
|
88
|
+
}
|
|
64
89
|
if(action==='entry_test'){
|
|
65
90
|
if(!intent||typeof intent!=='object'||Array.isArray(intent)
|
|
66
91
|
||Object.keys(intent).some(k=>!['prompt','appId','testOnly','confirmed','recoverTestAt','recoverExactDraft','verifyChatUrl'].includes(k))
|
|
@@ -8,7 +8,7 @@ import {randomUUID} from 'node:crypto';
|
|
|
8
8
|
const ID=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
9
9
|
const CHAT=/^[0-9a-f-]{12,}$/i;
|
|
10
10
|
const PROJECT=/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;
|
|
11
|
-
const PHASE=new Set(['STARTING','RESERVED','PENDING','WAITING_REPLY','DONE','BLOCKED']);
|
|
11
|
+
const PHASE=new Set(['STARTING','RESERVED','PENDING','WAITING_REPLY','DONE','BLOCKED','CANCELLED']);
|
|
12
12
|
const fail=code=>Object.assign(Error(code),{code});
|
|
13
13
|
export const sessionPath=()=>join(homedir(),'.chat-loop','session','active-session.json');
|
|
14
14
|
// An absent path differs from a dangling symlink: existsSync follows the
|
|
@@ -60,13 +60,35 @@ 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,sameTaskPrePermitUpdatedAt=null
|
|
63
|
+
export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSessionId=null,resumeBlockedUpdatedAt=null,sameTaskPrePermitUpdatedAt=null,cancelBlockedUpdatedAt=null,
|
|
64
|
+
cancelFreezeExpectedAt=null){
|
|
64
65
|
const next=validate(input),file=sessionPath(),dir=dirname(file),lock=file+'.lock';
|
|
65
66
|
ensurePrivate(dir);
|
|
66
67
|
let fd;
|
|
67
68
|
try{fd=openSync(lock,'wx',0o600);}catch{throw fail('SESSION_CONCURRENT_UPDATE');}
|
|
68
69
|
try{
|
|
69
70
|
const old=readSession();
|
|
71
|
+
// A canceled idle Adopt is terminal only after Context writer fencing.
|
|
72
|
+
// The Native Host independently verifies the authoritative Context
|
|
73
|
+
// cancellation receipt before passing this exact timestamp CAS.
|
|
74
|
+
const cancelCas=Number.isSafeInteger(cancelBlockedUpdatedAt)
|
|
75
|
+
&&cancelBlockedUpdatedAt>0&&old?.updatedAt===cancelBlockedUpdatedAt
|
|
76
|
+
&&old.phase==='BLOCKED'&&next.phase==='CANCELLED'
|
|
77
|
+
&&old.sessionId===next.sessionId&&old.projectId===next.projectId
|
|
78
|
+
&&old.taskId===next.taskId&&old.generation===next.generation
|
|
79
|
+
&&old.activeChatId===next.activeChatId
|
|
80
|
+
&&old.activeChatUrl===next.activeChatUrl;
|
|
81
|
+
if(cancelBlockedUpdatedAt!==null&&!cancelCas)
|
|
82
|
+
throw fail('SESSION_CANCEL_CAS_MISMATCH');
|
|
83
|
+
const freezeCas=Number.isSafeInteger(cancelFreezeExpectedAt)
|
|
84
|
+
&&cancelFreezeExpectedAt>0&&old?.updatedAt===cancelFreezeExpectedAt
|
|
85
|
+
&&old.phase==='WAITING_REPLY'&&next.phase==='BLOCKED'
|
|
86
|
+
&&old.sessionId===next.sessionId&&old.projectId===next.projectId
|
|
87
|
+
&&old.taskId===next.taskId&&old.generation===next.generation
|
|
88
|
+
&&old.activeChatId===next.activeChatId
|
|
89
|
+
&&old.activeChatUrl===next.activeChatUrl;
|
|
90
|
+
if(cancelFreezeExpectedAt!==null&&!freezeCas)
|
|
91
|
+
throw fail('SESSION_CANCEL_FREEZE_CAS_MISMATCH');
|
|
70
92
|
if(resumeBlockedSessionId){
|
|
71
93
|
// A BLOCKED session is terminal except for an exact-same-owner,
|
|
72
94
|
// same-Chat, same-generation, one-shot recovery CAS. No new Chat,
|
|
@@ -101,7 +123,8 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
101
123
|
&&next.activeChatId===null&&next.activeChatUrl===null;
|
|
102
124
|
if(sameTaskPrePermitUpdatedAt!==null&&!prePermitCas)
|
|
103
125
|
throw fail('SESSION_PRE_PERMIT_CAS_MISMATCH');
|
|
104
|
-
if(old&&old.sessionId!==next.sessionId
|
|
126
|
+
if(old&&old.sessionId!==next.sessionId
|
|
127
|
+
&&!['DONE','CANCELLED'].includes(old.phase)
|
|
105
128
|
&& !(old.phase==='BLOCKED' && next.phase==='STARTING'
|
|
106
129
|
&& replaceBlockedSessionId===old.sessionId
|
|
107
130
|
&& (next.projectId!==old.projectId
|
|
@@ -121,15 +144,17 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
|
|
|
121
144
|
throw fail('SESSION_HANDOFF_IDENTITY_UNVERIFIED');
|
|
122
145
|
// A terminal session may be re-read or fenced, not reassigned to
|
|
123
146
|
// another Chat or generation under the same sessionId.
|
|
124
|
-
if(['DONE','BLOCKED'].includes(old.phase)
|
|
147
|
+
if(['DONE','BLOCKED','CANCELLED'].includes(old.phase)
|
|
125
148
|
&&(next.generation!==old.generation
|
|
126
149
|
||next.activeChatId!==old.activeChatId
|
|
127
150
|
||next.activeChatUrl!==old.activeChatUrl))
|
|
128
151
|
throw fail('SESSION_TERMINAL_IDENTITY_CHANGED');
|
|
129
|
-
if(old.phase==='DONE'&&next.phase!=='DONE'
|
|
152
|
+
if(old.phase==='DONE'&&next.phase!=='DONE'
|
|
153
|
+
||old.phase==='CANCELLED'&&next.phase!=='CANCELLED'
|
|
154
|
+
||old.phase==='BLOCKED'
|
|
130
155
|
&& !['BLOCKED','DONE'].includes(next.phase)
|
|
131
|
-
&&!(resumeBlockedSessionId===old.sessionId
|
|
132
|
-
|
|
156
|
+
&&!(resumeBlockedSessionId===old.sessionId&&next.phase==='RESERVED')
|
|
157
|
+
&&!cancelCas)
|
|
133
158
|
throw fail('SESSION_TERMINAL_LOCKED');
|
|
134
159
|
if(old.activeChatId!==null&&next.generation===old.generation&&
|
|
135
160
|
next.activeChatId!==null&&old.activeChatId!==next.activeChatId)
|
|
@@ -7,25 +7,26 @@ import {createHash} from 'node:crypto';
|
|
|
7
7
|
const root=dirname(dirname(fileURLToPath(import.meta.url)));
|
|
8
8
|
const fail=code=>Object.assign(Error(code),{code});
|
|
9
9
|
const originals=['chat_text','chat_dom','chat_screenshot','reload',
|
|
10
|
-
'continue','handoff','clean','status','start'];
|
|
10
|
+
'continue','handoff','clean','status','start','session'];
|
|
11
11
|
const privilegedKinds=Object.freeze({chat_text:'eye-read',chat_dom:'eye-read',
|
|
12
12
|
chat_screenshot:'eye-screenshot',reload:'eye-reload',
|
|
13
13
|
continue:'owner-intent',handoff:'owner-intent',clean:'owner-clean',
|
|
14
|
-
status:'owner-status',start:'owner-start'});
|
|
14
|
+
status:'owner-status',start:'owner-start',session:'owner-session'});
|
|
15
15
|
// Existing timeout and receipt projection are part of the public action
|
|
16
16
|
// behavior; a descriptor edit must not silently change side-effect handling.
|
|
17
17
|
const builtinBehavior=Object.freeze({
|
|
18
18
|
chat_text:[27000,true],chat_dom:[27000,true],
|
|
19
19
|
chat_screenshot:[27000,false],reload:[27000,false],
|
|
20
20
|
continue:[27000,true],handoff:[27000,true],clean:[27000,true],
|
|
21
|
-
status:[27000,true],start:[310000,true]
|
|
21
|
+
status:[27000,true],start:[310000,true],session:[90000,true]
|
|
22
22
|
});
|
|
23
23
|
const builtinRoute=Object.freeze({
|
|
24
24
|
chat_text:['text.html','chat text'],chat_dom:['dom.html','chat dom'],
|
|
25
25
|
chat_screenshot:['screenshot.html','chat screenshot'],
|
|
26
26
|
reload:['reload.html','reload'],continue:['continue.html','continue'],
|
|
27
27
|
handoff:['handoff.html','handoff'],clean:['clean.html','clean'],
|
|
28
|
-
status:['status.html','status'],start:['start.html','start']
|
|
28
|
+
status:['status.html','status'],start:['start.html','start'],
|
|
29
|
+
session:['session.html','session']
|
|
29
30
|
});
|
|
30
31
|
const generatedMarker='<!-- GENERATED BY build-actions.mjs -->';
|
|
31
32
|
export async function compileActions(source=join(root,'capabilities'),
|
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.62",
|
|
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.25",
|
|
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.33"
|
|
41
41
|
},
|
|
42
42
|
"bundleDependencies": [
|
|
43
43
|
"@tomflow/chatloop-context",
|
package/providers/extension.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const CHAT_URL=/^https:\/\/chatgpt\.com\/(?:c\/[0-9a-f-]{12,}|g\/[^/]+\/c\/[0-9a
|
|
|
5
5
|
const REPLACE_SESSION=/^[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$/;
|
|
6
6
|
const TURN_TOKEN=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
7
7
|
const INTENT_ID=/^[a-f0-9]{32}$/;
|
|
8
|
-
const CONTROL_TOOLS=new Set(['start','continue','handoff']);
|
|
8
|
+
const CONTROL_TOOLS=new Set(['start','continue','handoff','session']);
|
|
9
9
|
export const isControlTool=name=>CONTROL_TOOLS.has(name);
|
|
10
10
|
const extensionTool = (name,description,readOnlyHint,properties={},required=[]) => ({
|
|
11
11
|
name,description,inputSchema:{type:'object',properties,required,additionalProperties:false},
|
|
@@ -19,6 +19,21 @@ const endpoints=[
|
|
|
19
19
|
{tabId:{type:'integer',minimum:1}},['tabId'])],
|
|
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
|
+
[['extension','session'],extensionTool('session',
|
|
23
|
+
'Exact Context-managed idle Adopt cancellation. User authorization required; no delivery or Chat send. Refuses live work, unknown effects and identity drift.',false,
|
|
24
|
+
{operation:{type:'string',enum:['cancel']},
|
|
25
|
+
projectId:{type:'string',pattern:PROJECT_ID.source},
|
|
26
|
+
taskId:{type:'string',pattern:PROJECT_ID.source},
|
|
27
|
+
sessionId:{type:'string',pattern:REPLACE_SESSION.source},
|
|
28
|
+
generation:{type:'integer',minimum:0},
|
|
29
|
+
expectedNativeUpdatedAt:{type:'integer',minimum:1},
|
|
30
|
+
expectedTaskRevision:{type:'integer',minimum:1},
|
|
31
|
+
expectedBindingRevision:{type:'integer',minimum:1},
|
|
32
|
+
contextStoreEpoch:{type:'string',minLength:10,maxLength:128},
|
|
33
|
+
confirmed:{const:true}},
|
|
34
|
+
['operation','projectId','taskId','sessionId','generation',
|
|
35
|
+
'expectedNativeUpdatedAt','expectedTaskRevision','expectedBindingRevision',
|
|
36
|
+
'contextStoreEpoch','confirmed'])],
|
|
22
37
|
[['extension','start'],extensionTool('start',
|
|
23
38
|
'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
39
|
{projectId:{type:'string',minLength:1,maxLength:128,pattern:PROJECT_ID.source},
|
|
@@ -56,6 +71,27 @@ export function validExtensionArgs(name,args){
|
|
|
56
71
|
if(Object.keys(args).length!==1||!Number.isSafeInteger(args.tabId)||args.tabId<1)
|
|
57
72
|
return false;
|
|
58
73
|
}else if(!control && Object.keys(args).length)return false;
|
|
74
|
+
if(name==='session'){
|
|
75
|
+
const k=['operation','projectId','taskId','sessionId','generation',
|
|
76
|
+
'expectedNativeUpdatedAt','expectedTaskRevision',
|
|
77
|
+
'expectedBindingRevision','contextStoreEpoch','confirmed'];
|
|
78
|
+
if(Object.keys(args).length!==k.length
|
|
79
|
+
||k.some(key=>!Object.hasOwn(args,key))
|
|
80
|
+
||args.operation!=='cancel'||args.confirmed!==true
|
|
81
|
+
||!PROJECT_ID.test(args.projectId||'')
|
|
82
|
+
||!PROJECT_ID.test(args.taskId||'')
|
|
83
|
+
||!REPLACE_SESSION.test(args.sessionId||'')
|
|
84
|
+
||!Number.isSafeInteger(args.generation)||args.generation<0
|
|
85
|
+
||!Number.isSafeInteger(args.expectedNativeUpdatedAt)
|
|
86
|
+
||args.expectedNativeUpdatedAt<=0
|
|
87
|
+
||!Number.isSafeInteger(args.expectedTaskRevision)
|
|
88
|
+
||args.expectedTaskRevision<1
|
|
89
|
+
||!Number.isSafeInteger(args.expectedBindingRevision)
|
|
90
|
+
||args.expectedBindingRevision<1
|
|
91
|
+
||typeof args.contextStoreEpoch!=='string'
|
|
92
|
+
||args.contextStoreEpoch.length<10||args.contextStoreEpoch.length>128)
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
59
95
|
if(name==='start'){
|
|
60
96
|
if(!PROJECT_ID.test(args.projectId||'')
|
|
61
97
|
||(args.taskId!==undefined&&!PROJECT_ID.test(args.taskId))
|
|
@@ -82,7 +118,7 @@ export function validExtensionArgs(name,args){
|
|
|
82
118
|
: typeof args.prompt!=='string'||!args.prompt.trim()||args.prompt.length>4000))
|
|
83
119
|
return false;
|
|
84
120
|
}
|
|
85
|
-
if(control
|
|
121
|
+
if(control&&!['start','session'].includes(name)){
|
|
86
122
|
if(typeof args.turnToken!=='string'||!TURN_TOKEN.test(args.turnToken))
|
|
87
123
|
return false;
|
|
88
124
|
const hasId=Object.hasOwn(args,'intentId');
|