@tomflow/chatloop-context 0.6.24 → 0.6.26
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/docs/interfaces.md +3 -1
- package/index.mjs +4 -2
- package/lib/core/health.mjs +2 -1
- package/lib/core/run-cancel.mjs +54 -0
- package/lib/core/run.mjs +1 -0
- package/lib/core/store.mjs +6 -4
- package/lib/trusted-run.mjs +6 -2
- package/package.json +2 -2
package/docs/interfaces.md
CHANGED
|
@@ -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
|
package/index.mjs
CHANGED
|
@@ -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,
|
package/lib/core/health.mjs
CHANGED
|
@@ -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
|
+
}
|
package/lib/core/run.mjs
CHANGED
|
@@ -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.
|
package/lib/core/store.mjs
CHANGED
|
@@ -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
|
}
|
package/lib/trusted-run.mjs
CHANGED
|
@@ -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});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-context",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.26",
|
|
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.34",
|
|
38
38
|
"@tomflow/chatloop-trace": "0.4.6"
|
|
39
39
|
}
|
|
40
40
|
}
|