@tomflow/chatloop-context 0.6.26 → 0.6.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -61,6 +61,62 @@ import {
61
61
  action. They organize trusted integrators behind **the same root**; they are
62
62
  not ordinary model/MCP operations.
63
63
 
64
+ **Task-scoped Native Writer read (unreleased source contract):**
65
+ `loadTrustedRuntime().execute('run.terminalStatus',args,native)` uses
66
+ an exact, independently verified `projectId/taskId/sessionId/generation`
67
+ Native owner projection. Its read-only result includes
68
+ `pendingHandoff: boolean` (from the authoritative Task
69
+ `pending_attempt`) and `pendingCheckpointId: string|null` (from
70
+ `pending_checkpoint`) alongside the existing `runRef`,
71
+ `bindingRevision`, `unknownEffectCount` and execution outcome.
72
+ It also reports `writerApprovalCurrent` and `projectRulesDrift`
73
+ from the same authoritative Task/Project snapshot; a later R/P change
74
+ or Project rule drift cannot silently inherit the old Writer.
75
+ A bound `runRef` by itself is **not** a safe Continue permission:
76
+ Native/Worker must reject a pending Handoff, pending Checkpoint,
77
+ an UNKNOWN effect or a stale owner. `run.snapshot` means the latest
78
+ immutable Checkpoint, **not** the live pending-attempt status.
79
+ When a signed Native Owner is already in `PENDING`, this private
80
+ `run.terminalStatus` may additionally accept the exact
81
+ `expectedHandoffAttemptId` (128-bit original signed Handoff request).
82
+ Context compares it with the authoritative `pending_attempt` inside
83
+ its read snapshot and returns only `pendingAttemptMatches: boolean`.
84
+ It never reveals the pending request ID, credential or digest, and never
85
+ releases a fenced Writer. The trusted adapter refuses the probe outside
86
+ Native PENDING except for a positive-revision V2 Native BLOCKED Owner
87
+ with an existing Chat, strictly for the original abort-revocation
88
+ **read-only** receipt; it always rejects a probe combined with Start
89
+ recovery. The Handoff Native consumer requires
90
+ `pendingAttemptMatches===true` before accepting the original
91
+ pending-fence or revoked-abort proof. The BLOCKED read cannot revive a
92
+ Writer, consume a Permit, replay Handoff or change Task data. This is NOT authorization to replay or
93
+ restore a Chat send.
94
+
95
+ A signed, exact V2 Native Task Status may also read
96
+ `run.terminalStatus` while generation zero is `STARTING/RESERVED/PENDING`
97
+ with both `activeChatId` and `activeChatUrl` null. This narrowly
98
+ scoped exception requires a positive V2 Native Session revision and
99
+ does not apply to V1, later generations, writes, Permit consumption
100
+ or `run.bind.initial`. It lets the existing Status Action report the
101
+ pre-Adopt phase instead of failing solely because no Chat has yet
102
+ been claimed.
103
+
104
+ This is an additive **internal trusted read**; it does not add a public
105
+ SDK method, MCP tool, writer, retry capability or browser send. Source
106
+ is not yet rebuilt, deployed or tested.
107
+
108
+ The private `loadTrustedRuntime().execute(command,...)` facade additionally
109
+ accepts `permit.status` (the exact original Task + actionToken, returning
110
+ bounded recorded kind/approval revision) and
111
+ `run.idleStartPermitStatus` (whether the **only** permit in that Task is
112
+ the consumed original START permit). The latter is preliminary evidence:
113
+ `run.fence.cancel` repeats the same original START-only Permit check inside
114
+ **its own SQLite transaction**, so a concurrent CONTINUE/HANDOFF reservation
115
+ cannot slip between the read and cancellation commit. V2 Context reads
116
+ also supply the fixed `storeEpoch` and current Project/R/P writer checks.
117
+ Neither method is an open/public `context.*` capability or additional
118
+ MCP tool. One Task's SQLite revisions never authorize another Task.
119
+
64
120
  See [provider / consumer / dependency matrix](docs/interfaces.md) for the
65
121
  **complete** cross-module reference. For exact method IDs, schemas and
66
122
  semantics, use `sdk.methods.list` / `sdk.methods.describe` on the connected SDK.
@@ -160,6 +160,30 @@ export const capability={
160
160
  "minLength": 8,
161
161
  "maxLength": 128
162
162
  },
163
+ "literalRevision": {
164
+ "type": "object",
165
+ "additionalProperties": false,
166
+ "required": ["baseVersion", "baseContentHash", "replacements"],
167
+ "properties": {
168
+ "baseVersion": {"type": "integer", "minimum": 1},
169
+ "baseContentHash": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
170
+ "replacements": {
171
+ "type": "array",
172
+ "minItems": 1,
173
+ "maxItems": 32,
174
+ "items": {
175
+ "type": "object",
176
+ "additionalProperties": false,
177
+ "required": ["from", "to", "expectedCount"],
178
+ "properties": {
179
+ "from": {"type": "string", "minLength": 1},
180
+ "to": {"type": "string"},
181
+ "expectedCount": {"type": "integer", "minimum": 1, "maximum": 100}
182
+ }
183
+ }
184
+ }
185
+ }
186
+ },
163
187
  "requirementRef": {
164
188
  "type": "object",
165
189
  "additionalProperties": false,
@@ -9,7 +9,7 @@ export const capability={
9
9
  "id": "start.reserve",
10
10
  "group": "start",
11
11
  "mode": "write",
12
- "description": "Reserve a short-lived start lease after both effective R/P approvals.",
12
+ "description": "Reserve a short-lived Start lease after both effective R/P approvals; an explicit Task executionPermission (including review-only or unknown) is a restriction and cannot be overridden by R/P. Legacy tasks without this field retain their prior Start eligibility. No installation or filesystem grants.",
13
13
  "inputSchema": {
14
14
  "type": "object",
15
15
  "required": [
@@ -97,7 +97,7 @@ export const capability={
97
97
  "id": "task.create",
98
98
  "group": "task",
99
99
  "mode": "write",
100
- "description": "Create a project-scoped task with an initial DRAFT state.",
100
+ "description": "Create a project-scoped DRAFT task without durable review-only executionPermission. Current-round R/P limits are not permanent Task scope; R/P approvals and Stage 03 independently guard Start. Existing legacy restrictions remain enforced.",
101
101
  "inputSchema": {
102
102
  "type": "object",
103
103
  "required": [
@@ -437,7 +437,7 @@ export const capability={
437
437
  "id": "task.patch",
438
438
  "group": "task",
439
439
  "mode": "write",
440
- "description": "Patch permitted Task fields with revision and run-holder checks.",
440
+ "description": "Patch permitted Task fields with CAS/run-holder checks; an R/P-approved idle Task may report bounded preflight progress, blockers and nextStep only.",
441
441
  "inputSchema": {
442
442
  "type": "object",
443
443
  "required": [
@@ -66,6 +66,36 @@ contract; this prose document is not a parallel API schema authority.
66
66
  Ordinary MCP **never exposes** `permit.consume`, `run.bind.initial`,
67
67
  `run.fence`, `run.bind.handoff` or other private Run/Permit actions.
68
68
 
69
+ ### Task creation vs. legacy review-only restrictions
70
+
71
+ Public `task.create` creates a DRAFT task without accepting `context.executionPermission` (`TASK_CREATE_REVIEW_SCOPE_FORBIDDEN`). Stage 01/02 review-round restrictions belong to the Workflow and R/P approval flow, not permanent Task execution scope. This change **does not grant execution**: Stage 03 still requires effective R/P approvals and independent authorization for any filesystem, installation or browser operation. Existing Task records carrying review-only/unknown `executionPermission` are not silently migrated or made executable; `start.reserve`, Native START permit and initial run bind remain fail-closed. A clearly requested review-only engagement should finish at its authorized review scope, without manufacturing a future implementation/Start permission.
72
+
73
+ ### Local operator: correct an incorrectly permanent review-only Task
74
+
75
+ `chatloop-context task correct-review-scope <projectId> <taskId> <taskRevision> <approvalRevision> <storeEpoch> <expectedPermission> <operatorEvidenceRef> <writeRequestId>`
76
+
77
+ This is an **independent local operator** action, not an SDK/MCP method
78
+ or a model-executable task mutation. It requires the existing
79
+ `CHAT_LOOP_CONTEXT_ADMIN_ENABLE=1`, exact allowed Project, a real
80
+ interactive TTY confirmation bound to the Task, both revisions, epoch,
81
+ old permission and original-intent evidence reference. Operator must
82
+ independently inspect the original user request and R/P before consenting.
83
+ A normal non-interactive MCP process is rejected. Reconcile an uncertain
84
+ write only with `task scope-correction-receipt <projectId> <storeEpoch> <writeRequestId>`;
85
+ do not repeat the mutation with a new ID.
86
+
87
+ Core rejects mismatched CAS, unapproved or pending R/P, project drift,
88
+ any prior Start lease or permit, active/pending Run, unresolved effects,
89
+ an unknown permission value, or a second correction. It preserves
90
+ original R/P and approved hashes, Project and read-only Workspace bounds,
91
+ Task identity and original objective, and records a durable audit note.
92
+ The receipt `SCOPE_CORRECTED_NOT_OPERATION_AUTHORIZED` **does not authorize**
93
+ installation, download, temporary writes, packing, repository access,
94
+ browser sending or Stage 04; those are independently checked against
95
+ the approved Pn and actual user/operator authorization. The current
96
+ production version may not contain this source-only operator command
97
+ until the Context release is installed and verified.
98
+
69
99
  ## 4. Provider → consumer matrix (actual source paths)
70
100
 
71
101
  | Provider | API / action consumed | Actual consumer | Boundary and result |
@@ -102,6 +132,32 @@ The Tools private handler passes a signed-IPC-verified Native projection into th
102
132
 
103
133
  `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
134
 
135
+ The new private V2 `permit.consume(kind:RECOVER_HANDOFF)` and
136
+ `run.restore-fenced-handoff` share the existing Task SQLite/receipt
137
+ transactions, not the V1 `RESERVED` restore. The permit is only
138
+ consumable while the exact Native Owner is `BLOCKED`, and the
139
+ transaction checks the original pending attempt, pinned checkpoint,
140
+ successor generation/RunRef, existing USED Handoff permit, current
141
+ approved R/P, zero unresolved effects, unique unused recovery permit,
142
+ CAS and fresh credential before rebinding the original generation.
143
+ The original Extension `session` Action now has a source-only
144
+ `recover-handoff` route through the Native BLOCKED Owner, Worker
145
+ `NOT_SENT` evidence and the signed Tools Supervisor IPC. The original
146
+ private recovery request generates one credential; a lost ACK must
147
+ reconcile the same request's USED permit, Context binding and Native
148
+ CAS, not mint a second permit. **None of this is run, packaged,
149
+ published or E2E-accepted**; a Context method alone never authorizes
150
+ a browser send or proves that the installed Writer was restored.
151
+
152
+ The existing V1 `run.restore-same-owner` is not a V2 Handoff
153
+ recovery contract: it requires the old Native `RESERVED` phase.
154
+ Its Context transaction independently rejects any already delivered,
155
+ cancelled or unresolved-effect Task before rebinding a Writer, even
156
+ when the original Checkpoint and single-use CONTINUE permit match.
157
+ It also requires the pending Handoff to target exactly the same
158
+ Session's next generation and RunRef; a same-attempt receipt alone
159
+ cannot redirect recovery to a different successor.
160
+
105
161
  The Browser Native Host now permits the Worker-used `run.reopenStatus`
106
162
  through the same signed private IPC path; it is not a public MCP method.
107
163
  For first-Start recovery, `run.terminalStatus` accepts the private
@@ -113,6 +169,19 @@ no writer/unknown effect exists, and current approvals remain valid.
113
169
  expired unused initial leases transactionally; the read-only proof does not
114
170
  grant a permit, bind a writer, or replace a Session.
115
171
 
172
+ For V2 Handoff, the same trusted `run.terminalStatus` accepts
173
+ `expectedHandoffAttemptId` with the independently checked Native
174
+ `PENDING` Owner, or with its exact positive-revision `BLOCKED` Owner
175
+ after the original pre-SEND_BEGIN Native abort fence. This remains a
176
+ read-only proof, never a Start recovery lease or a Writer recovery.
177
+ Context compares the signed original attempt to `pending_attempt`
178
+ inside the SQLite read snapshot and exposes only
179
+ `pendingAttemptMatches: boolean` rather than an ID or credential.
180
+ Native requires this match and the original USED Handoff Permit to
181
+ authorize `send-check` while PENDING, or to confirm the revoked
182
+ `handoff-abort-fence-read-v2` receipt once BLOCKED. No probe permits
183
+ replaying a SEND_BEGIN-unknown effect or reviving Context Writer.
184
+
116
185
  ## 5. Context → external dependencies (reverse direction)
117
186
 
118
187
  | External owner / dependency | Context call, file or mechanism | Source | Coupling and scope |
package/index.mjs CHANGED
@@ -38,7 +38,7 @@ function sdkRuntime(){
38
38
  if(!sdkPromise)sdkPromise=(async()=>{
39
39
  const [
40
40
  core,health,migrationCore,projectCore,taskCore,reviewCore,
41
- evidenceCore,contextCore,runCore,cancelCore,migration,policy,methods,
41
+ evidenceCore,contextCore,runCore,cancelCore,recoveryCore,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'),
@@ -46,6 +46,7 @@ function sdkRuntime(){
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
48
  import('./lib/core/run.mjs'),import('./lib/core/run-cancel.mjs'),
49
+ import('./lib/core/run-recovery.mjs'),
49
50
  import('./lib/context-migration.mjs'),
50
51
  import('./lib/approval-policy.mjs'),import('./lib/methods.mjs'),
51
52
  import('./lib/project-store.mjs'),import('./lib/operations.mjs'),
@@ -64,6 +65,7 @@ function sdkRuntime(){
64
65
  createContextMethods:contextCore.createContextMethods,
65
66
  createRunMethods:runCore.createRunMethods,
66
67
  createCancelMethods:cancelCore.createCancelMethods,
68
+ createRecoveryMethods:recoveryCore.createRecoveryMethods,
67
69
  verifySourceUnit:migration.verifySourceUnit,
68
70
  inspectRegistryReferenceForReview:migration.inspectRegistryReferenceForReview,
69
71
  hasApprovedPlan:policy.hasApprovedPlan,
@@ -36,13 +36,23 @@ const formReceipt=(text,kind,stored)=>{
36
36
  [,formId,traceRef,version,label]=m;
37
37
  }else{
38
38
  const lines=text.split(/\r?\n/).map(x=>x.trim()).filter(Boolean);
39
- if(lines.length!==6||lines[0]!=='Chat Loop Form 提交结果(由用户点击表单提交)'
40
- ||lines[3]!=='选项值: A'||lines[5]!==FORM_NOTE)return null;
41
- const id=lines[1].match(new RegExp('^formId:\\s*('+FORM_UUID+')$','i'));
39
+ if(lines.length!==6||lines[0]!==FORM_HEADER
40
+ ||!['选项值: A','选项值: approve'].includes(lines[3])
41
+ ||lines[5]!==FORM_NOTE)return null;
42
+ const id=lines[1].match(/^formId:\s*([a-z0-9][a-z0-9_-]{7,127})$/i);
42
43
  const trace=lines[2].match(new RegExp('^traceRef:\\s*('+FORM_UUID+')$','i'));
43
- const choice=lines[4].match(/^选项标签:\s*A[||]\s*确认当前\s*([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
44
- if(!id||!trace||!choice)return null;
45
- formId=id[1];traceRef=trace[1];version=choice[1];label=choice[2];
44
+ const oldChoice=lines[4].match(/^选项标签:\s*A[||]\s*确认当前\s*([RP][1-9][0-9]*)\s*(需求|技术与验证方案|技术方案|方案)$/i);
45
+ const modernChoice=lines[3]==='选项值: approve'
46
+ &&lines[4].match(/^选项标签:\s*A[||]\s*确认(需求|技术与验证方案|技术方案|方案)$/);
47
+ if(!id||!trace||!oldChoice&&!modernChoice)return null;
48
+ formId=id[1];traceRef=trace[1];
49
+ const versions=[...formId.matchAll(/(?:^|[-_])([rp][1-9][0-9]*)(?=[-_]|$)/gi)]
50
+ .map(m=>m[1].toUpperCase());
51
+ version=oldChoice?.[1]
52
+ ||(modernChoice&&versions.length===1?versions[0]:null);
53
+ label=oldChoice?.[2]||modernChoice?.[1];
54
+ if(!version||oldChoice&&versions.some(v=>v!==version.toUpperCase()))
55
+ return null;
46
56
  }
47
57
  version=version.toUpperCase();
48
58
  if(!versionedLabel(version,label,kind)
@@ -73,5 +83,16 @@ export function approvedTurnSourceMatches(record,observed,kind){
73
83
  &&stored.version===actual.version&&stored.label===actual.label
74
84
  &&stored.version===observed.version);
75
85
  }
86
+ // Current workflow records only a bounded soft receipt in approval.observe.
87
+ // A matching original six-line user Turn and both independent identifiers
88
+ // are mandatory; this summary is never itself browser approval evidence.
89
+ const summary=typeof record.userTurn==='string'&&record.userTurn.match(
90
+ /^user-turn:UNAVAILABLE; form:([a-z0-9][a-z0-9_-]{7,127}); trace:([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}); approve$/i);
91
+ if(summary){
92
+ const actual=formReceipt(observed.userText,kind,false);
93
+ return Boolean(actual&&actual.formId===summary[1].toLowerCase()
94
+ &&actual.traceRef===summary[2].toLowerCase()
95
+ &&actual.version===observed.version);
96
+ }
76
97
  return record.userTurn===observed.userText||record.userTurn===observed.userKey;
77
98
  }
@@ -804,7 +804,7 @@
804
804
  "id": "task.create",
805
805
  "group": "task",
806
806
  "mode": "write",
807
- "description": "Create a project-scoped task with an initial DRAFT state.",
807
+ "description": "Create a project-scoped DRAFT task without durable review-only executionPermission. Current-round R/P limits are not permanent Task scope; R/P approvals and Stage 03 independently guard Start. Existing legacy restrictions remain enforced.",
808
808
  "inputSchema": {
809
809
  "type": "object",
810
810
  "required": [
@@ -1144,7 +1144,7 @@
1144
1144
  "id": "task.patch",
1145
1145
  "group": "task",
1146
1146
  "mode": "write",
1147
- "description": "Patch permitted Task fields with revision and run-holder checks.",
1147
+ "description": "Patch permitted Task fields with CAS/run-holder checks; an R/P-approved idle Task may report bounded preflight progress, blockers and nextStep only.",
1148
1148
  "inputSchema": {
1149
1149
  "type": "object",
1150
1150
  "required": [
@@ -1279,6 +1279,53 @@
1279
1279
  "minLength": 8,
1280
1280
  "maxLength": 128
1281
1281
  },
1282
+ "literalRevision": {
1283
+ "type": "object",
1284
+ "additionalProperties": false,
1285
+ "required": [
1286
+ "baseVersion",
1287
+ "baseContentHash",
1288
+ "replacements"
1289
+ ],
1290
+ "properties": {
1291
+ "baseVersion": {
1292
+ "type": "integer",
1293
+ "minimum": 1
1294
+ },
1295
+ "baseContentHash": {
1296
+ "type": "string",
1297
+ "pattern": "^[a-f0-9]{64}$"
1298
+ },
1299
+ "replacements": {
1300
+ "type": "array",
1301
+ "minItems": 1,
1302
+ "maxItems": 32,
1303
+ "items": {
1304
+ "type": "object",
1305
+ "additionalProperties": false,
1306
+ "required": [
1307
+ "from",
1308
+ "to",
1309
+ "expectedCount"
1310
+ ],
1311
+ "properties": {
1312
+ "from": {
1313
+ "type": "string",
1314
+ "minLength": 1
1315
+ },
1316
+ "to": {
1317
+ "type": "string"
1318
+ },
1319
+ "expectedCount": {
1320
+ "type": "integer",
1321
+ "minimum": 1,
1322
+ "maximum": 100
1323
+ }
1324
+ }
1325
+ }
1326
+ }
1327
+ }
1328
+ },
1282
1329
  "requirementRef": {
1283
1330
  "type": "object",
1284
1331
  "additionalProperties": false,
@@ -1688,7 +1735,7 @@
1688
1735
  "id": "start.reserve",
1689
1736
  "group": "start",
1690
1737
  "mode": "write",
1691
- "description": "Reserve a short-lived start lease after both effective R/P approvals.",
1738
+ "description": "Reserve a short-lived Start lease after both effective R/P approvals; an explicit Task executionPermission (including review-only or unknown) is a restriction and cannot be overridden by R/P. Legacy tasks without this field retain their prior Start eligibility. No installation or filesystem grants.",
1692
1739
  "inputSchema": {
1693
1740
  "type": "object",
1694
1741
  "required": [
@@ -106,7 +106,60 @@ export async function runLocalCliCommand(args,readJson){
106
106
  expectedBindingRevision:Number(bindingRevision),
107
107
  expectedStoreEpoch,evidenceDocumentId,
108
108
  evidenceVersion:Number(evidenceVersion),evidenceHash,writeRequestId});
109
- }else if(command==='task'&&sub==='orphan-receipt'&&rest.length===3){
109
+ }else if(command==='task'&&sub==='correct-review-scope'&&rest.length===8){
110
+ // Independent, explicit local operator action; NOT exposed via Context MCP.
111
+ const [projectId,taskId,revision,approvalRevision,storeEpoch,
112
+ expectedPermission,operatorEvidenceRef,writeRequestId]=rest;
113
+ if(process.env.CHAT_LOOP_CONTEXT_ADMIN_ENABLE!=='1')throw fail('ADMIN_REQUIRED');
114
+ if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
115
+ if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
116
+ const expectedTaskRevision=Number(revision),
117
+ expectedApprovalRevision=Number(approvalRevision);
118
+ if(!Number.isSafeInteger(expectedTaskRevision)||expectedTaskRevision<1
119
+ ||!Number.isSafeInteger(expectedApprovalRevision)||expectedApprovalRevision<1)
120
+ throw fail('SCOPE_CORRECTION_REVISION_INVALID');
121
+ if(!['REQUIREMENTS_REVIEW_ONLY','PLAN_REVIEW_ONLY'].includes(expectedPermission)
122
+ ||typeof operatorEvidenceRef!=='string'||operatorEvidenceRef.length<8
123
+ ||operatorEvidenceRef.length>256
124
+ ||typeof writeRequestId!=='string'||writeRequestId.length<8
125
+ ||writeRequestId.length>128)
126
+ throw fail('SCOPE_CORRECTION_ARGUMENT_INVALID');
127
+ const file=join(contextRoot(),projectId,'context.sqlite');
128
+ const read=openContextProtocol(file,{readOnly:true,principalId:'local-operator',
129
+ authorizeData:(_mode,p)=>p===projectId});
130
+ try{
131
+ const current=read.get(projectId,taskId);
132
+ if(read.epoch!==storeEpoch)throw fail('STALE_EPOCH');
133
+ if(current.taskRevision!==expectedTaskRevision)
134
+ throw fail('BUSINESS_VERSION_CONFLICT');
135
+ if(current.approvalRevision!==expectedApprovalRevision)
136
+ throw fail('APPROVAL_CONFLICT');
137
+ if(current.currentContext.executionPermission!==expectedPermission)
138
+ throw fail('SCOPE_CORRECTION_NOT_ELIGIBLE');
139
+ if(read.projectBusinessAuthority(projectId).writable!==true)
140
+ throw fail('PROJECT_CUTOVER_NOT_VERIFIED');
141
+ }finally{read.close()}
142
+ await confirmWorkspaceOperator('CORRECT_REVIEW_SCOPE',projectId,
143
+ expectedTaskRevision,[taskId,expectedPermission,
144
+ String(expectedApprovalRevision),storeEpoch,operatorEvidenceRef]);
145
+ const db=openContextProtocol(file,{principalId:'local-operator',
146
+ authorizeData:(_mode,p)=>p===projectId,
147
+ authorizeAdmin:(op,p)=>op==='task.reviewScope.correct'&&p===projectId});
148
+ try{
149
+ value=db.taskCorrectReviewScope({projectId,taskId,
150
+ expectedTaskRevision,expectedApprovalRevision,
151
+ expectedPermission,operatorEvidenceRef,
152
+ reason:'STAGE_ONLY_INTENT_MISCLASSIFIED',
153
+ expectedStoreEpoch:storeEpoch,writeRequestId});
154
+ const after=db.get(projectId,taskId);
155
+ if(after.taskRevision!==value.taskRevision
156
+ ||after.bindingRevision!==0||after.runRef!==null
157
+ ||Object.hasOwn(after.currentContext,'executionPermission')
158
+ ||after.currentContext.scopeCorrection?.operatorEvidenceRef!==operatorEvidenceRef)
159
+ throw fail('SCOPE_CORRECTION_READBACK_FAILED');
160
+ value={...value,projectId,taskId,storeEpoch,writeRequestId};
161
+ }finally{db.close()}
162
+ }else if(command==='task'&&['orphan-receipt','scope-correction-receipt'].includes(sub)&&rest.length===3){
110
163
  const [projectId,storeEpoch,writeRequestId]=rest;
111
164
  if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
112
165
  if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
@@ -29,6 +29,8 @@ export function createContextMethods(values) {
29
29
  const r=scope(a);written(r,a);
30
30
  const current=parse(r.context_json);
31
31
  validContextPatch(a.patch,current);
32
+ assert(!['executionPermission','authorizedWorkspace','sourceAccess'].some(
33
+ key=>Object.hasOwn(a.patch,key)),'TASK_SCOPE_IMMUTABLE');
32
34
  const context={...current,...a.patch};
33
35
  saveTaskContext(a.projectId,a.taskId,context);
34
36
  return {status:'COMMITTED',taskRevision:r.business_revision+1,bindingRevision:r.binding_revision};
@@ -28,13 +28,36 @@ export function createHealthMethods(values) {
28
28
  reopenUserTurn:c.reopenRequest?.userTurn??null,
29
29
  previousDeliveryRef:c.deliveryRef??null};
30
30
  },
31
- terminalStatus(projectId,taskId,startRecoveryLeaseRef=null){
31
+ terminalStatus(projectId,taskId,startRecoveryLeaseRef=null,
32
+ expectedHandoffAttemptId=null){
32
33
  checkIds(projectId,taskId);readAuth(projectId,taskId,'run.terminalStatus');
34
+ // Only report whether the caller's exact original attempt matches.
35
+ // Never return the private request token or pending credential.
36
+ assert(expectedHandoffAttemptId===null
37
+ ||startRecoveryLeaseRef===null
38
+ &&typeof expectedHandoffAttemptId==='string'
39
+ &&/^[a-f0-9]{32}$/.test(expectedHandoffAttemptId),
40
+ 'HANDOFF_STATUS_PROBE_INVALID');
33
41
  return readSnapshot(()=>{
34
42
  const r=required(projectId,taskId),c=parse(r.context_json);
35
- const state={projectId,taskId,taskRevision:r.business_revision,
43
+ const state={projectId,taskId,storeEpoch:epoch,
44
+ taskRevision:r.business_revision,
36
45
  bindingRevision:r.binding_revision,approvalRevision:r.approval_revision,
37
46
  unknownEffectCount:unresolvedEffects(c).length,
47
+ // A bound Writer is not sufficient evidence that its prior
48
+ // Handoff has settled. Native V2 read-only checks must distinguish
49
+ // an outstanding attempt from an available, unambiguous Owner.
50
+ pendingHandoff:r.pending_attempt!==null,
51
+ pendingCheckpointId:r.pending_checkpoint??null,
52
+ ...(expectedHandoffAttemptId!==null
53
+ ?{pendingAttemptMatches:r.pending_attempt===expectedHandoffAttemptId}
54
+ :{}),
55
+ // A current RunRef cannot implicitly inherit a later R/P or
56
+ // altered Project rules; read the business approval at source.
57
+ writerApprovalCurrent:r.writer_approval_revision!==null
58
+ &&r.writer_approval_revision===r.approval_revision
59
+ &&hasApprovedPlan(parse(r.approval_json)),
60
+ projectRulesDrift:projectDrift(r).projectDrift,
38
61
  runRef:r.writable_ref,executionOutcome:c.executionOutcome??null,
39
62
  deliveryRef:c.deliveryRef??null,
40
63
  sessionCancellation:c.sessionCancellation??null};
@@ -57,6 +80,42 @@ export function createHealthMethods(values) {
57
80
  return {...state,storeEpoch:epoch,startRecovery:{status:'UNBOUND_NO_PERMIT',leaseRef:startRecoveryLeaseRef}};
58
81
  });
59
82
  },
83
+ idleStartPermitStatus(projectId,taskId,startActionToken){
84
+ checkIds(projectId,taskId);
85
+ readAuth(projectId,taskId,'run.idleStartPermitStatus');
86
+ assert(typeof startActionToken==='string'
87
+ &&/^[a-f0-9]{32}$/.test(startActionToken),
88
+ 'START_PERMIT_TOKEN_INVALID');
89
+ return readSnapshot(()=>{
90
+ required(projectId,taskId);
91
+ const permits=db.prepare(
92
+ 'SELECT action_token,kind FROM permits WHERE project_id=? AND task_id=?'
93
+ ).all(projectId,taskId);
94
+ // BindInitial preserves a USED tombstone. Any later Continue,
95
+ // Handoff or unknown permit means idle cancellation is unsafe,
96
+ // even if a Worker reason still says ADOPTED_IDLE_BASELINE.
97
+ return {projectId,taskId,
98
+ startOnly:permits.length===1
99
+ &&permits[0].action_token===startActionToken
100
+ &&permits[0].kind==='USED'};
101
+ });
102
+ },
103
+ permitStatus(projectId,taskId,actionToken){
104
+ checkIds(projectId,taskId);readAuth(projectId,taskId,'permit.status');
105
+ assert(typeof actionToken==='string'
106
+ &&/^[a-f0-9]{32}$/.test(actionToken),
107
+ 'PERMIT_STATUS_TOKEN_INVALID');
108
+ return readSnapshot(()=>{
109
+ required(projectId,taskId);
110
+ const permit=db.prepare(
111
+ 'SELECT kind,approval_revision FROM permits WHERE project_id=? AND task_id=? AND action_token=?'
112
+ ).get(projectId,taskId,actionToken);
113
+ return {projectId,taskId,actionToken,
114
+ status:permit?'RECORDED':'NOT_FOUND',
115
+ kind:permit?.kind??null,
116
+ approvalRevision:permit?.approval_revision??null};
117
+ });
118
+ },
60
119
  latestCheckpoint(projectId,taskId){
61
120
  checkIds(projectId,taskId);readAuth(projectId,taskId,'context.latestCheckpoint');
62
121
  const r=required(projectId,taskId);
@@ -5,6 +5,10 @@ export function createReviewMethods(values) {
5
5
  documentCreate(a){
6
6
  return receipt(a,'document.createDraft',()=>{
7
7
  const r=scope(a);expectedBusiness(r,a.expectedTaskRevision);
8
+ // An R/P replacement must first record the user's decision on the
9
+ // pending issue. A draft written before REQUEST_CHANGE would create
10
+ // an immutable orphan version that cannot be legally presented.
11
+ if(a.kind==='R'||a.kind==='P')ensureNoPendingIssue(a.projectId,a.taskId);
8
12
  // The public Method Catalog also advertises immutable task-scoped
9
13
  // reference and historical-evidence drafts. They are storage only:
10
14
  // document.prepareIssue must never turn them into R/P approval issues.
@@ -24,6 +28,35 @@ export function createReviewMethods(values) {
24
28
  }
25
29
  assert(!db.prepare('SELECT 1 FROM documents WHERE project_id=? AND task_id=? AND document_id=? AND version=?')
26
30
  .get(a.projectId,a.taskId,a.documentId,a.version),'DOCUMENT_EXISTS');
31
+ if(a.literalRevision!==undefined){
32
+ const guard=a.literalRevision;
33
+ assert(a.kind==='P'&&Number.isInteger(guard?.baseVersion)
34
+ &&guard.baseVersion>=1&&guard.baseVersion<a.version
35
+ &&typeof guard.baseContentHash==='string'
36
+ &&Array.isArray(guard.replacements)
37
+ &&guard.replacements.length>=1&&guard.replacements.length<=32,
38
+ 'LITERAL_REVISION_INVALID');
39
+ const base=db.prepare('SELECT body,content_hash FROM documents WHERE project_id=? AND task_id=? AND document_id=? AND version=? AND kind=?')
40
+ .get(a.projectId,a.taskId,a.documentId,guard.baseVersion,a.kind);
41
+ assert(base&&base.content_hash===guard.baseContentHash,
42
+ 'LITERAL_REVISION_BASE_MISMATCH');
43
+ let candidate=base.body;
44
+ const used=new Set();
45
+ for(const edit of guard.replacements){
46
+ assert(typeof edit?.from==='string'&&edit.from.length>0
47
+ &&typeof edit.to==='string'&&edit.from!==edit.to
48
+ &&!edit.to.includes(edit.from)
49
+ &&Number.isInteger(edit.expectedCount)
50
+ &&edit.expectedCount>=1&&edit.expectedCount<=100
51
+ &&!used.has(edit.from),'LITERAL_REVISION_INVALID');
52
+ used.add(edit.from);
53
+ const parts=candidate.split(edit.from);
54
+ assert(parts.length-1===edit.expectedCount,
55
+ 'LITERAL_REVISION_COUNT_MISMATCH');
56
+ candidate=parts.join(edit.to);
57
+ }
58
+ assert(candidate===a.body,'LITERAL_REVISION_CONTENT_MISMATCH');
59
+ }
27
60
  const contentHash=digest(a.body);
28
61
  db.prepare('INSERT INTO documents VALUES(?,?,?,?,?,?,?,?)')
29
62
  .run(a.projectId,a.taskId,a.documentId,a.version,a.kind,a.body,contentHash,
@@ -15,6 +15,20 @@ export function createCancelMethods(values){
15
15
  &&a.runRef===a.sessionId+':'+a.taskId+':'+a.generation,
16
16
  'RUN_REF_MISMATCH');
17
17
  assert(!r.pending_attempt,'HANDOFF_PENDING');
18
+ if(a.scopedStartActionToken!==undefined){
19
+ // V2 idle Cancel must prove IN THIS SAME Context transaction that
20
+ // no Continue/Handoff permit was ever consumed or reserved. The
21
+ // earlier read-only query alone has a time-of-check race.
22
+ assert(typeof a.scopedStartActionToken==='string'
23
+ &&/^[a-f0-9]{32}$/.test(a.scopedStartActionToken),
24
+ 'IDLE_START_TOKEN_INVALID');
25
+ const all=db.prepare(
26
+ 'SELECT action_token,kind FROM permits WHERE project_id=? AND task_id=?'
27
+ ).all(a.projectId,a.taskId);
28
+ assert(all.length===1
29
+ &&all[0].action_token===a.scopedStartActionToken
30
+ &&all[0].kind==='USED','IDLE_CANCEL_EXECUTION_PERMIT_EXISTS');
31
+ }
18
32
  assert(r.writer_approval_revision===r.approval_revision,
19
33
  'ACTIVE_RUN_APPROVAL_STALE');
20
34
  assert(!projectDrift(r).projectDrift,'PROJECT_RULES_DRIFT');
@@ -0,0 +1,112 @@
1
+ // The two same-Task recovery transactions share the original Context SQLite
2
+ // receipt authority. V1 and V2 have distinct Native admission contracts;
3
+ // neither is a public MCP capability or a browser sender.
4
+ export function createRecoveryMethods(values){
5
+ const {internal,receipt,assert,scope,expectedBusiness,expectedBinding,
6
+ assertPinnedHandoffCurrent,parse,unresolvedEffects,db,runDigest,epoch,
7
+ hasApprovedPlan}=values;
8
+ return {
9
+ restoreSameOwner(a){
10
+ internal('run.bind.restore-same-owner',a);
11
+ return receipt(a,'run.bind.restore-same-owner',()=>{
12
+ // These proofs are adapter assertions in W01 only. Real Worker/Native
13
+ // provenance MUST be verified by the transport before W07 enables this.
14
+ assert(a.sendState==='NOT_SENT' && a.oldActionTokenRevoked===true,
15
+ 'SEND_NOT_PROVEN_ABSENT');
16
+ assert(a.workerRestored===true && a.nativeRestored===true &&
17
+ a.ownerStillSame===true,'OWNER_UNVERIFIED');
18
+ const r=scope(a);expectedBusiness(r,a.expectedTaskRevision);
19
+ expectedBinding(r,a.expectedBindingRevision);
20
+ assert(r.writable_ref===null && r.pending_attempt===a.attemptId
21
+ &&r.pending_checkpoint===a.checkpointId
22
+ &&r.pending_target_generation===a.generation+1
23
+ &&r.pending_next_ref===a.sessionId+':'+a.taskId+':'+(a.generation+1),
24
+ 'HANDOFF_MISMATCH');
25
+ assertPinnedHandoffCurrent(r,a.checkpointId);
26
+ const state=parse(r.context_json);
27
+ assert(state.executionOutcome!=='DONE'&&!state.deliveryRef
28
+ &&!state.sessionCancellation
29
+ &&unresolvedEffects(state).length===0,'RUN_RECOVERY_UNSAFE');
30
+ assert(typeof a.recoveryCredential==='string'&&a.recoveryCredential.length===64,
31
+ 'WRITE_CREDENTIAL_INVALID');
32
+ assert(typeof a.recoveryActionToken==='string'&&a.recoveryActionToken.length>=8,
33
+ 'ACTION_TOKEN_REQUIRED');
34
+ assert(typeof a.sourceRunRef==='string'&&a.sourceRunRef.length>=8,
35
+ 'RUN_REF_MISSING');
36
+ const permit=db.prepare('SELECT * FROM permits WHERE project_id=? AND task_id=? AND action_token=?')
37
+ .get(a.projectId,a.taskId,a.recoveryActionToken);
38
+ assert(permit&&permit.kind==='CONTINUE'
39
+ &&permit.approval_revision===r.approval_revision,'RECOVERY_PERMIT_MISSING');
40
+ assert(hasApprovedPlan(parse(r.approval_json)),'APPROVAL_REVOKED');
41
+ db.prepare(`UPDATE tasks SET writable_ref=?,credential_digest=?,
42
+ writer_approval_revision=?,pending_attempt=NULL,pending_checkpoint=NULL,
43
+ pending_target_generation=NULL,pending_credential_digest=NULL,
44
+ pending_next_ref=NULL,binding_revision=binding_revision+1
45
+ WHERE project_id=? AND task_id=?`).run(a.sourceRunRef,
46
+ runDigest(epoch,a.projectId,a.taskId,a.sourceRunRef,a.recoveryCredential),
47
+ r.approval_revision,a.projectId,a.taskId);
48
+ // Retain a durable one-use tombstone, so the same token cannot be reissued.
49
+ db.prepare("UPDATE permits SET kind='USED' WHERE project_id=? AND task_id=? AND action_token=?")
50
+ .run(a.projectId,a.taskId,a.recoveryActionToken);
51
+ return {status:'RESTORED_SAME_OWNER',runRef:a.sourceRunRef,
52
+ bindingRevision:r.binding_revision+1,recoveryActionToken:a.recoveryActionToken};
53
+ });
54
+ },
55
+
56
+ restoreFencedHandoff(a){
57
+ internal('run.bind.restore-fenced-handoff',a);
58
+ return receipt(a,'run.bind.restore-fenced-handoff',()=>{
59
+ const r=scope(a);
60
+ expectedBusiness(r,a.expectedTaskRevision);
61
+ expectedBinding(r,a.expectedBindingRevision);
62
+ const next=a.sessionId+':'+a.taskId+':'+(a.generation+1);
63
+ const source=a.sessionId+':'+a.taskId+':'+a.generation;
64
+ assert(r.writable_ref===null&&r.credential_digest===null
65
+ &&r.writer_approval_revision===null
66
+ &&r.pending_attempt===a.attemptId
67
+ &&r.pending_checkpoint===a.checkpointId
68
+ &&r.pending_target_generation===a.generation+1
69
+ &&r.pending_next_ref===next
70
+ &&r.pending_credential_digest!==null
71
+ &&a.sourceRunRef===source,'HANDOFF_RECOVERY_FENCE_MISMATCH');
72
+ assertPinnedHandoffCurrent(r,a.checkpointId);
73
+ const state=parse(r.context_json);
74
+ assert(state.executionOutcome!=='DONE'&&!state.deliveryRef
75
+ &&!state.sessionCancellation
76
+ &&unresolvedEffects(state).length===0,'RUN_RECOVERY_UNSAFE');
77
+ assert(hasApprovedPlan(parse(r.approval_json))
78
+ &&r.approval_revision===a.expectedApprovalRevision,
79
+ 'APPROVAL_REVOKED');
80
+ assert(typeof a.newRunCredential==='string'
81
+ &&/^[0-9a-f]{64}$/.test(a.newRunCredential),
82
+ 'WRITE_CREDENTIAL_INVALID');
83
+ assert(typeof a.recoveryActionToken==='string'
84
+ &&/^[a-f0-9]{32}$/.test(a.recoveryActionToken),
85
+ 'RECOVERY_TOKEN_INVALID');
86
+ const permits=db.prepare(
87
+ 'SELECT action_token,kind,approval_revision FROM permits WHERE project_id=? AND task_id=?'
88
+ ).all(a.projectId,a.taskId);
89
+ assert(permits.some(p=>p.action_token===a.attemptId
90
+ &&p.kind==='USED'&&p.approval_revision===r.approval_revision),
91
+ 'ORIGINAL_HANDOFF_PERMIT_UNVERIFIED');
92
+ assert(permits.filter(p=>p.kind!=='USED').length===1
93
+ &&permits.some(p=>p.action_token===a.recoveryActionToken
94
+ &&p.kind==='RECOVER_HANDOFF'
95
+ &&p.approval_revision===r.approval_revision),
96
+ 'RECOVERY_PERMIT_NOT_UNIQUE');
97
+ db.prepare('UPDATE tasks SET writable_ref=?,credential_digest=?,'
98
+ +'writer_approval_revision=?,pending_attempt=NULL,pending_checkpoint=NULL,'
99
+ +'pending_target_generation=NULL,pending_credential_digest=NULL,'
100
+ +'pending_next_ref=NULL,binding_revision=binding_revision+1 '
101
+ +'WHERE project_id=? AND task_id=?').run(source,
102
+ runDigest(epoch,a.projectId,a.taskId,source,a.newRunCredential),
103
+ r.approval_revision,a.projectId,a.taskId);
104
+ db.prepare("UPDATE permits SET kind='USED' WHERE project_id=? AND task_id=? AND action_token=?")
105
+ .run(a.projectId,a.taskId,a.recoveryActionToken);
106
+ return {status:'HANDOFF_WRITER_RESTORED',runRef:source,
107
+ bindingRevision:r.binding_revision+1,
108
+ recoveryActionToken:a.recoveryActionToken};
109
+ });
110
+ }
111
+ };
112
+ }
package/lib/core/run.mjs CHANGED
@@ -1,6 +1,11 @@
1
1
  // Context Core run methods. Shared access and transactions are injected from store.mjs.
2
2
  export function createRunMethods(values) {
3
3
  const {fail, assert, ID, runDigest, parse, db, epoch, hasApprovedPlan, approvedTurnSourceMatches, randomUUID, projectDrift, receipt, internal, admin, unresolvedEffects, ensureNoPendingIssue, expectedBusiness, expectedBinding, assertPinnedHandoffCurrent, scope} = values;
4
+ // A review-only Task cannot become executable merely because R/P was approved.
5
+ // This is an explicit denial, not a substitute for independent install/IO grants.
6
+ const assertExecutableScope=context=>assert(
7
+ !Object.hasOwn(context,'executionPermission'),
8
+ 'EXECUTION_SCOPE_NOT_AUTHORIZED');
4
9
  return {
5
10
  reserve(a){
6
11
  return receipt(a,'start.reserve',()=>{
@@ -13,6 +18,7 @@ export function createRunMethods(values) {
13
18
  assert(hasApprovedPlan(approvals),'APPROVAL_REQUIRED');
14
19
  assert(r.approval_revision===a.expectedApprovalRevision,'APPROVAL_CONFLICT');
15
20
  const current=parse(r.context_json);
21
+ assertExecutableScope(current);
16
22
  if(a.purpose==='REPAIR_SAME_SCOPE'){
17
23
  assert(current.stage==='REOPENED'&&current.reopenReason==='REPAIR_SAME_SCOPE'
18
24
  &&current.reopenRequest?.sourceRole==='user'
@@ -50,6 +56,7 @@ export function createRunMethods(values) {
50
56
  ensureNoPendingIssue(a.projectId,a.taskId);
51
57
  const approvals=parse(r.approval_json);
52
58
  assert(hasApprovedPlan(approvals),'APPROVAL_REVOKED');
59
+ if((a.kind??'START')==='START')assertExecutableScope(parse(r.context_json));
53
60
  // Managed original-Chat Adopt is not authorized by a valid lease
54
61
  // alone. The observed R/P user turns must also be those approved for
55
62
  // THIS Task. The browser proof is soft; Native still owns the lease,
@@ -82,6 +89,29 @@ export function createRunMethods(values) {
82
89
  assert(r.writer_approval_revision===r.approval_revision,
83
90
  'ACTIVE_RUN_APPROVAL_STALE');
84
91
  }
92
+ if(a.kind==='RECOVER_HANDOFF'){
93
+ // This permit is only for a separately signed Native BLOCKED
94
+ // recovery Action. It never licenses the old Handoff send.
95
+ expectedBinding(r,a.expectedBindingRevision);
96
+ assert(r.writable_ref===null&&r.credential_digest===null
97
+ &&r.pending_attempt===a.recoveryOfAttemptId
98
+ &&r.pending_checkpoint===a.checkpointId
99
+ &&r.pending_target_generation===a.generation+1
100
+ &&r.pending_next_ref===a.sessionId+':'+a.taskId+':'+(a.generation+1),
101
+ 'HANDOFF_RECOVERY_FENCE_MISMATCH');
102
+ assertPinnedHandoffCurrent(r,a.checkpointId);
103
+ const state=parse(r.context_json);
104
+ assert(state.executionOutcome!=='DONE'&&!state.deliveryRef
105
+ &&!state.sessionCancellation&&unresolvedEffects(state).length===0,
106
+ 'RUN_RECOVERY_UNSAFE');
107
+ assert(!db.prepare("SELECT 1 FROM permits WHERE project_id=? AND task_id=? AND kind!='USED' LIMIT 1")
108
+ .get(a.projectId,a.taskId),'RECOVERY_PERMIT_CONFLICT');
109
+ const original=db.prepare('SELECT kind,approval_revision FROM permits WHERE project_id=? AND task_id=? AND action_token=?')
110
+ .get(a.projectId,a.taskId,a.recoveryOfAttemptId);
111
+ assert(original?.kind==='USED'
112
+ &&original.approval_revision===r.approval_revision,
113
+ 'ORIGINAL_HANDOFF_PERMIT_UNVERIFIED');
114
+ }
85
115
  if((a.kind??'START')==='START'){
86
116
  assert(r.writable_ref===null&&r.pending_attempt===null,'RUN_ALREADY_BOUND');
87
117
  const lease=db.prepare('SELECT * FROM start_leases WHERE lease_ref=?').get(a.leaseRef);
@@ -126,6 +156,7 @@ export function createRunMethods(values) {
126
156
  assert(permit.approval_revision===r.approval_revision &&
127
157
  hasApprovedPlan(parse(r.approval_json)),'APPROVAL_REVOKED');
128
158
  const initialContext=parse(r.context_json);
159
+ assertExecutableScope(initialContext);
129
160
  assert(initialContext.stage==='REOPENED' &&
130
161
  initialContext.reopenReason==='REPAIR_SAME_SCOPE' ||
131
162
  initialContext.executionOutcome!=='DONE' &&
@@ -331,45 +362,6 @@ export function createRunMethods(values) {
331
362
  return {status:'TERMINAL_FENCED',taskRevision:r.business_revision,
332
363
  bindingRevision:r.binding_revision+1};
333
364
  });
334
- },
335
- restoreSameOwner(a){
336
- internal('run.bind.restore-same-owner',a);
337
- return receipt(a,'run.bind.restore-same-owner',()=>{
338
- // These proofs are adapter assertions in W01 only. Real Worker/Native
339
- // provenance MUST be verified by the transport before W07 enables this.
340
- assert(a.sendState==='NOT_SENT' && a.oldActionTokenRevoked===true,
341
- 'SEND_NOT_PROVEN_ABSENT');
342
- assert(a.workerRestored===true && a.nativeRestored===true &&
343
- a.ownerStillSame===true,'OWNER_UNVERIFIED');
344
- const r=scope(a);expectedBusiness(r,a.expectedTaskRevision);
345
- expectedBinding(r,a.expectedBindingRevision);
346
- assert(r.writable_ref===null && r.pending_attempt===a.attemptId
347
- && r.pending_checkpoint===a.checkpointId,'HANDOFF_MISMATCH');
348
- assertPinnedHandoffCurrent(r,a.checkpointId);
349
- assert(typeof a.recoveryCredential==='string'&&a.recoveryCredential.length===64,
350
- 'WRITE_CREDENTIAL_INVALID');
351
- assert(typeof a.recoveryActionToken==='string'&&a.recoveryActionToken.length>=8,
352
- 'ACTION_TOKEN_REQUIRED');
353
- assert(typeof a.sourceRunRef==='string'&&a.sourceRunRef.length>=8,
354
- 'RUN_REF_MISSING');
355
- const permit=db.prepare('SELECT * FROM permits WHERE project_id=? AND task_id=? AND action_token=?')
356
- .get(a.projectId,a.taskId,a.recoveryActionToken);
357
- assert(permit&&permit.kind==='CONTINUE'
358
- &&permit.approval_revision===r.approval_revision,'RECOVERY_PERMIT_MISSING');
359
- assert(hasApprovedPlan(parse(r.approval_json)),'APPROVAL_REVOKED');
360
- db.prepare(`UPDATE tasks SET writable_ref=?,credential_digest=?,
361
- writer_approval_revision=?,pending_attempt=NULL,pending_checkpoint=NULL,
362
- pending_target_generation=NULL,pending_credential_digest=NULL,
363
- pending_next_ref=NULL,binding_revision=binding_revision+1
364
- WHERE project_id=? AND task_id=?`).run(a.sourceRunRef,
365
- runDigest(epoch,a.projectId,a.taskId,a.sourceRunRef,a.recoveryCredential),
366
- r.approval_revision,a.projectId,a.taskId);
367
- // Retain a durable one-use tombstone, so the same token cannot be reissued.
368
- db.prepare("UPDATE permits SET kind='USED' WHERE project_id=? AND task_id=? AND action_token=?")
369
- .run(a.projectId,a.taskId,a.recoveryActionToken);
370
- return {status:'RESTORED_SAME_OWNER',runRef:a.sourceRunRef,
371
- bindingRevision:r.binding_revision+1,recoveryActionToken:a.recoveryActionToken};
372
- });
373
365
  }
374
366
  };
375
367
  }
@@ -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, createCancelMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches;
10
+ let createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, createCancelMethods, createRecoveryMethods, 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', 'createCancelMethods', 'verifySourceUnit', 'inspectRegistryReferenceForReview', 'hasApprovedPlan', 'hasRequirementApproval', 'approvedTurnSourceMatches']){
14
+ for(const name of ['createHealthMethods', 'createMigrationMethods', 'createProjectMethods', 'createTaskMethods', 'createReviewMethods', 'createEvidenceMethods', 'createContextMethods', 'createRunMethods', 'createCancelMethods', 'createRecoveryMethods', '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, createCancelMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches}=capabilities);
17
+ ({createHealthMethods, createMigrationMethods, createProjectMethods, createTaskMethods, createReviewMethods, createEvidenceMethods, createContextMethods, createRunMethods, createCancelMethods, createRecoveryMethods, verifySourceUnit, inspectRegistryReferenceForReview, hasApprovedPlan, hasRequirementApproval, approvedTurnSourceMatches}=capabilities);
18
18
  connected=true;
19
19
  }
20
20
 
@@ -300,7 +300,7 @@ export function openContextProtocol(file,{authorizeInternal=()=>false,authorizeD
300
300
  'approval','approvals','approved','approvalRevision','rRef','pRef',
301
301
  'runRef','runCredential','credentialDigest','writableRunRef','pendingHandoff',
302
302
  'writeFenceRevision','bindingRevision','taskRevision','storeEpoch',
303
- 'projectRuleReview','effectResolutions','projectId','taskId','stage','executionOutcome',
303
+ 'projectRuleReview','scopeCorrection','effectResolutions','projectId','taskId','stage','executionOutcome',
304
304
  'deliveryRef','deliveredAt','acceptedAt','acceptance','acceptanceFeedback',
305
305
  'sessionCancellation',
306
306
  'reopenReason','reopenRequest','archivedAt','authority','migrationSourceUnitId',
@@ -392,6 +392,7 @@ export function openContextProtocol(file,{authorizeInternal=()=>false,authorizeD
392
392
  createEvidenceMethods(scopeValues),
393
393
  createContextMethods(scopeValues),
394
394
  createRunMethods(scopeValues),
395
- createCancelMethods(scopeValues)
395
+ createCancelMethods(scopeValues),
396
+ createRecoveryMethods(scopeValues)
396
397
  );
397
398
  }
package/lib/core/task.mjs CHANGED
@@ -1,6 +1,28 @@
1
1
  // Context Core task methods. Shared access and transactions are injected from store.mjs.
2
2
  export function createTaskMethods(values) {
3
- const {assert, ID, parse, db, saveTaskContext, authorizeData, enableTestFixtures, hasApprovedPlan, row, required, checkIds, receipt, readAuth, readSnapshot, validContextPatch, unresolvedEffects, ensureNoPendingIssue, expectedBusiness, written, publicTask, scope} = values;
3
+ const {assert, ID, parse, db, saveTaskContext, authorizeData, enableTestFixtures, hasApprovedPlan, row, required, checkIds, receipt, readAuth, readSnapshot, validContextPatch, unresolvedEffects, ensureNoPendingIssue, expectedBusiness, written, publicTask, scope, admin, projectDrift} = values;
4
+ // Prior to first Start, an approved Task may record preflight findings only.
5
+ // No scope, permissions, business approvals or protected state can be patched.
6
+ const preflightFields=new Set(['progress','blockers','nextStep']);
7
+ const immutableScopeFields=new Set(['executionPermission','authorizedWorkspace','sourceAccess']);
8
+ const assertScopeUnchanged=patch=>assert(
9
+ !Object.keys(patch).some(key=>immutableScopeFields.has(key)),
10
+ 'TASK_SCOPE_IMMUTABLE');
11
+ const validPreflightReport=patch=>{
12
+ const keys=Object.keys(patch);
13
+ assert(keys.length>0&&keys.every(key=>preflightFields.has(key)),
14
+ 'PREFLIGHT_PATCH_SCOPE_DENIED');
15
+ for(const key of ['progress','blockers']){
16
+ if(!Object.hasOwn(patch,key))continue;
17
+ const entries=patch[key];
18
+ assert(Array.isArray(entries)&&entries.length<=100
19
+ &&entries.every(item=>typeof item==='string'&&item.length<=1200),
20
+ 'PREFLIGHT_PATCH_VALUE_INVALID');
21
+ }
22
+ if(Object.hasOwn(patch,'nextStep'))
23
+ assert(typeof patch.nextStep==='string'&&patch.nextStep.length<=1200,
24
+ 'PREFLIGHT_PATCH_VALUE_INVALID');
25
+ };
4
26
  return {
5
27
  taskCreate(a){
6
28
  return receipt(a,'task.create',()=>{
@@ -12,6 +34,11 @@ export function createTaskMethods(values) {
12
34
  validContextPatch(a.context??{},{
13
35
  unknownEffects:[]
14
36
  });
37
+ // Task creation does not assign durable execution eligibility.
38
+ // A review round is governed by R/P approvals; old scope restrictions
39
+ // remain immutable and are still enforced by the Stage 03 Start gate.
40
+ assert(!Object.hasOwn(a.context??{},'executionPermission'),
41
+ 'TASK_CREATE_REVIEW_SCOPE_FORBIDDEN');
15
42
  const ctx={title:a.title,objective:a.objective??'',stage:'DRAFT',
16
43
  progress:[],blockers:[],unknownEffects:[],nextStep:'',...a.context};
17
44
  db.prepare('INSERT INTO tasks(project_id,task_id,adopted_project_revision,context_json,approval_json) VALUES(?,?,?,?,?)')
@@ -50,16 +77,70 @@ export function createTaskMethods(values) {
50
77
  nextCursor:incomplete?chosen.at(-1):null,limit};
51
78
  });
52
79
  },
80
+ // A review-only scope written from a stage-only intent may be corrected
81
+ // only by an independently confirmed local operator. This is not an MCP
82
+ // capability, not a generic patch, and not a grant to install or write.
83
+ taskCorrectReviewScope(a){
84
+ admin('task.reviewScope.correct',a.projectId);
85
+ return receipt(a,'task.correctReviewScope',()=>{
86
+ const r=scope(a);expectedBusiness(r,a.expectedTaskRevision);
87
+ assert(r.approval_revision===a.expectedApprovalRevision,'APPROVAL_CONFLICT');
88
+ assert(r.binding_revision===0&&r.writable_ref===null&&r.pending_attempt===null,
89
+ 'SCOPE_CORRECTION_ACTIVE_TASK');
90
+ assert(!projectDrift(r).projectDrift,'PROJECT_RULES_DRIFT');
91
+ ensureNoPendingIssue(a.projectId,a.taskId);
92
+ assert(hasApprovedPlan(parse(r.approval_json)),'APPROVAL_REQUIRED');
93
+ assert(!db.prepare('SELECT 1 FROM start_leases WHERE project_id=? AND task_id=? LIMIT 1')
94
+ .get(a.projectId,a.taskId),'SCOPE_CORRECTION_START_HISTORY');
95
+ assert(!db.prepare('SELECT 1 FROM permits WHERE project_id=? AND task_id=? LIMIT 1')
96
+ .get(a.projectId,a.taskId),'SCOPE_CORRECTION_START_HISTORY');
97
+ const current=parse(r.context_json);
98
+ assert(['REQUIREMENTS_REVIEW_ONLY','PLAN_REVIEW_ONLY'].includes(
99
+ current.executionPermission)
100
+ &&current.executionPermission===a.expectedPermission
101
+ &&!Object.hasOwn(current,'scopeCorrection'),
102
+ 'SCOPE_CORRECTION_NOT_ELIGIBLE');
103
+ assert(a.reason==='STAGE_ONLY_INTENT_MISCLASSIFIED'
104
+ &&typeof a.operatorEvidenceRef==='string'
105
+ &&a.operatorEvidenceRef.length>=8&&a.operatorEvidenceRef.length<=256,
106
+ 'SCOPE_CORRECTION_EVIDENCE_REQUIRED');
107
+ assert(current.executionOutcome!=='DONE'&&current.stage!=='ARCHIVED'
108
+ &&!current.sessionCancellation,'SCOPE_CORRECTION_TERMINAL_TASK');
109
+ assert(unresolvedEffects(current).length===0,'UNKNOWN_EFFECTS_UNRESOLVED');
110
+ const next={...current};
111
+ delete next.executionPermission;
112
+ next.scopeCorrection={from:a.expectedPermission,
113
+ to:'UNSPECIFIED_EXECUTION_ELIGIBILITY',
114
+ reason:a.reason,operatorEvidenceRef:a.operatorEvidenceRef,
115
+ proofLevel:'LOCAL_OPERATOR_TTY_CONFIRMATION',at:Date.now()};
116
+ saveTaskContext(a.projectId,a.taskId,next);
117
+ return {status:'SCOPE_CORRECTED_NOT_OPERATION_AUTHORIZED',
118
+ taskRevision:r.business_revision+1,bindingRevision:r.binding_revision,
119
+ approvalRevision:r.approval_revision};
120
+ });
121
+ },
53
122
  taskPatch(a){
54
123
  return receipt(a,'task.patch',()=>{
55
124
  const r=scope(a);expectedBusiness(r,a.expectedTaskRevision);
56
125
  const current=parse(r.context_json);
57
126
  validContextPatch(a.patch,current);
127
+ assertScopeUnchanged(a.patch);
58
128
  if(r.writable_ref!==null)written(r,a);
59
129
  else{
60
130
  assert(r.pending_attempt===null,'WRITER_FENCED');
61
- assert(current.stage==='DRAFT'&&parse(r.approval_json).length===0,
62
- 'CURRENT_CONTEXT_REQUIRES_ACTIVE_RUN');
131
+ const approvals=parse(r.approval_json);
132
+ if(approvals.length===0){
133
+ assert(current.stage==='DRAFT','CURRENT_CONTEXT_REQUIRES_ACTIVE_RUN');
134
+ }else{
135
+ assert(r.binding_revision===0&&hasApprovedPlan(approvals),
136
+ 'PREFLIGHT_REPORT_REQUIRES_APPROVED_IDLE_TASK');
137
+ validPreflightReport(a.patch);
138
+ // A pending/consumed Start is not a safe idle reporting window.
139
+ assert(!db.prepare('SELECT 1 FROM start_leases WHERE project_id=? AND task_id=? AND expires_at>? LIMIT 1')
140
+ .get(a.projectId,a.taskId,Date.now()),'PREFLIGHT_START_IN_FLIGHT');
141
+ assert(!db.prepare('SELECT 1 FROM permits WHERE project_id=? AND task_id=? LIMIT 1')
142
+ .get(a.projectId,a.taskId),'PREFLIGHT_START_IN_FLIGHT');
143
+ }
63
144
  ensureNoPendingIssue(a.projectId,a.taskId);
64
145
  }
65
146
  const next={...current,...a.patch};
@@ -18,8 +18,11 @@ export function configureTrustedRun(capabilities){
18
18
  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
- 'run.bind.handoff','run.restore-same-owner','run.fence.terminal',
22
- 'run.credential.rotate','run.fence.cancel','run.terminalStatus','run.reopenStatus','run.snapshot']);
21
+ 'run.bind.handoff','run.restore-same-owner',
22
+ 'run.restore-fenced-handoff','run.fence.terminal',
23
+ 'run.credential.rotate','run.fence.cancel','run.terminalStatus',
24
+ 'run.reopenStatus','run.snapshot','permit.status',
25
+ 'run.idleStartPermitStatus']);
23
26
 
24
27
  export function executeTrustedRun(command,args,native){
25
28
  assert(supported.has(command)&&args&&typeof args==='object'
@@ -29,16 +32,33 @@ export function executeTrustedRun(command,args,native){
29
32
  'nativeCommitted'].some(k=>Object.hasOwn(args,k)),
30
33
  'CLIENT_AUTH_FIELD_FORBIDDEN');
31
34
  const startRecovery=command==='run.terminalStatus'&&Object.hasOwn(args,'startRecoveryLeaseRef');
35
+ const handoffProbe=Object.hasOwn(args,'expectedHandoffAttemptId');
36
+ if(handoffProbe)assert(command==='run.terminalStatus'
37
+ &&!startRecovery&&(native.phase==='PENDING'
38
+ ||native.phase==='BLOCKED'&&native.activeChatId!==null
39
+ &&Number.isSafeInteger(native.revision)&&native.revision>=2)
40
+ &&typeof args.expectedHandoffAttemptId==='string'
41
+ &&/^[a-f0-9]{32}$/.test(args.expectedHandoffAttemptId),
42
+ 'HANDOFF_STATUS_PROBE_DENIED');
32
43
  if(startRecovery)assert(native.phase==='BLOCKED'&&native.generation===0
33
44
  &&native.activeChatId===null&&native.activeChatUrl===null
34
45
  &&typeof args.startRecoveryLeaseRef==='string'
35
46
  &&/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(args.startRecoveryLeaseRef),
36
47
  'START_RECOVERY_NATIVE_UNVERIFIED');
48
+ // A signed V2 Task Status can read an exact pre-Adopt Owner whose Chat
49
+ // has not been claimed yet. V1 has no Native revision; this exception
50
+ // is read-only, generation zero and cannot authorize a START permit.
51
+ const preAdoptStatus=command==='run.terminalStatus'
52
+ &&Number.isSafeInteger(native.revision)&&native.revision>=1
53
+ &&native.generation===0
54
+ &&['STARTING','RESERVED','PENDING'].includes(native.phase)
55
+ &&native.activeChatId===null&&native.activeChatUrl===null;
37
56
  assert(native.projectId===args.projectId && native.taskId===args.taskId
38
57
  && native.sessionId===args.sessionId
39
58
  && native.generation===args.generation
40
59
  && native.activeChatId===args.activeChatId
41
- && (native.activeChatId!==null || command==='permit.consume'&&args.kind==='START'||startRecovery),
60
+ && (native.activeChatId!==null || command==='permit.consume'&&args.kind==='START'
61
+ ||startRecovery||preAdoptStatus),
42
62
  'CONTEXT_NATIVE_BINDING_MISMATCH');
43
63
  const allowed=allowedProjects();
44
64
  assert(allowed.has(native.projectId),'PROJECT_ACCESS_DENIED');
@@ -51,7 +71,14 @@ export function executeTrustedRun(command,args,native){
51
71
  assert(args.runRef===native.sessionId+':'+native.taskId+':'+native.generation,
52
72
  'RUN_REF_MISMATCH');
53
73
  if(command==='permit.consume')
54
- assert(['RESERVED','PENDING'].includes(native.phase),'NATIVE_PHASE_MISMATCH');
74
+ assert(args.kind==='RECOVER_HANDOFF'
75
+ ?native.phase==='BLOCKED'&&native.activeChatId!==null
76
+ &&Number.isSafeInteger(native.revision)&&native.revision>=2
77
+ :['RESERVED','PENDING'].includes(native.phase)
78
+ ||['CONTINUE','HANDOFF'].includes(args.kind)
79
+ &&native.phase==='WAITING_REPLY'
80
+ &&Number.isSafeInteger(native.revision)&&native.revision>=1,
81
+ 'NATIVE_PHASE_MISMATCH');
55
82
  if(['run.bind.initial','run.bind.handoff'].includes(command))
56
83
  assert(native.phase==='WAITING_REPLY','NATIVE_PHASE_MISMATCH');
57
84
  if(command==='run.credential.rotate')
@@ -61,21 +88,36 @@ export function executeTrustedRun(command,args,native){
61
88
  'CANCEL_NATIVE_NOT_BLOCKED');
62
89
  if(command==='run.restore-same-owner')
63
90
  assert(native.phase==='RESERVED','NATIVE_PHASE_MISMATCH');
64
- if(command==='run.fence.terminal'||command==='run.reopenStatus')
91
+ if(command==='run.restore-fenced-handoff')
92
+ assert(native.phase==='BLOCKED'&&native.activeChatId!==null
93
+ &&Number.isSafeInteger(native.revision)&&native.revision>=2,
94
+ 'NATIVE_RECOVERY_NOT_FENCED');
95
+ if(command==='run.fence.terminal')
96
+ assert(native.phase==='DONE'
97
+ ||native.phase==='WAITING_REPLY'
98
+ &&Number.isSafeInteger(native.revision)&&native.revision>=1,
99
+ 'NATIVE_PHASE_MISMATCH');
100
+ if(command==='run.reopenStatus')
65
101
  assert(native.phase==='DONE','NATIVE_PHASE_MISMATCH');
66
102
 
67
103
  const file=resolveVerifiedProjectDatabase(args.projectId);
68
104
  const db=openContextProtocol(file,{principalId:'native-controlled',
69
105
  authorizeData:(_access,p)=>allowed.has(p),authorizeInternal:()=>true});
70
106
  try{
71
- if((startRecovery||!['run.terminalStatus','run.reopenStatus','run.snapshot'].includes(command))
107
+ if((startRecovery||!['run.terminalStatus','run.reopenStatus','run.snapshot',
108
+ 'permit.status','run.idleStartPermitStatus'].includes(command))
72
109
  &&!db.projectBusinessAuthority(args.projectId).writable)
73
110
  throw fail('PROJECT_CUTOVER_NOT_VERIFIED');
74
111
  switch(command){
75
112
  case 'run.terminalStatus':return db.terminalStatus(args.projectId,args.taskId,
76
- startRecovery?args.startRecoveryLeaseRef:null);
113
+ startRecovery?args.startRecoveryLeaseRef:null,
114
+ handoffProbe?args.expectedHandoffAttemptId:null);
77
115
  case 'run.reopenStatus':return db.reopenStatus(args.projectId,args.taskId);
78
116
  case 'run.snapshot':return db.latestCheckpoint(args.projectId,args.taskId);
117
+ case 'permit.status':return db.permitStatus(
118
+ args.projectId,args.taskId,args.actionToken);
119
+ case 'run.idleStartPermitStatus':return db.idleStartPermitStatus(
120
+ args.projectId,args.taskId,args.startActionToken);
79
121
  case 'permit.consume':return db.consumePermit(args);
80
122
  case 'run.credential.rotate':return db.rotateCredential(args);
81
123
  case 'run.bind.initial':return db.bindInitial({...args,ownerCommitted:true});
@@ -84,6 +126,9 @@ export function executeTrustedRun(command,args,native){
84
126
  case 'run.fence.terminal':return db.fenceTerminal(args);
85
127
  case 'run.bind.handoff':
86
128
  return db.bindHandoff({...args,ownerCommitted:true,nativeCommitted:true});
129
+ case 'run.restore-fenced-handoff':
130
+ return db.restoreFencedHandoff({...args,
131
+ sourceRunRef:native.sessionId+':'+native.taskId+':'+native.generation});
87
132
  case 'run.restore-same-owner':
88
133
  assert(args.sendState==='NOT_SENT'
89
134
  &&typeof args.recoveryActionToken==='string',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-context",
3
- "version": "0.6.26",
3
+ "version": "0.6.33",
4
4
  "type": "module",
5
5
  "description": "Independent local Context SDK and short-lived CLI for Chat Loop projects",
6
6
  "publishConfig": {
@@ -26,15 +26,13 @@
26
26
  "docs/"
27
27
  ],
28
28
  "scripts": {
29
- "test": "node --test ./test/*.test.mjs",
30
29
  "build:capabilities": "node ./scripts/build-capabilities.mjs",
31
30
  "build:capabilities:check": "node ./scripts/build-capabilities.mjs --check",
32
- "prepack": "node ./scripts/build-capabilities.mjs --check",
33
- "pretest": "node ./scripts/build-capabilities.mjs --check"
31
+ "prepack": "node ./scripts/build-capabilities.mjs --check"
34
32
  },
35
33
  "dependencies": {
36
34
  "ps-list": "9.0.0",
37
- "@tomflow/chatloop-extension": "0.4.34",
35
+ "@tomflow/chatloop-extension": "0.4.35",
38
36
  "@tomflow/chatloop-trace": "0.4.6"
39
37
  }
40
38
  }