@tomflow/chatloop-context 0.6.40 → 0.6.42

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.
@@ -57,7 +57,8 @@ export const capability={
57
57
  "userTurn": {
58
58
  "type": "string",
59
59
  "minLength": 8,
60
- "maxLength": 256
60
+ "maxLength": 256,
61
+ "description": "For a Form A without platform user message ID, store its exact real identifiers: user-turn:UNAVAILABLE; form:<actual formId>; trace:<actual traceRef>; approve. Reject generic current-chat placeholders; never invent user approval."
61
62
  },
62
63
  "presentedAssistantRef": {
63
64
  "type": "string",
@@ -93,7 +94,7 @@ export const capability={
93
94
  "id": "approval.revoke",
94
95
  "group": "approval",
95
96
  "mode": "write",
96
- "description": "Invalidate earlier approvals at the correct task revision.",
97
+ "description": "Revoke approvals only on explicit user withdrawal, not diagnostics.",
97
98
  "inputSchema": {
98
99
  "type": "object",
99
100
  "required": [
@@ -103,7 +104,10 @@ export const capability={
103
104
  "expectedTaskRevision",
104
105
  "expectedApprovalRevision",
105
106
  "expectedStoreEpoch",
106
- "writeRequestId"
107
+ "writeRequestId",
108
+ "sourceRole",
109
+ "userTurn",
110
+ "reason"
107
111
  ],
108
112
  "additionalProperties": false,
109
113
  "properties": {
@@ -135,6 +139,17 @@ export const capability={
135
139
  "type": "string",
136
140
  "minLength": 8,
137
141
  "maxLength": 128
142
+ },
143
+ "sourceRole": {
144
+ "const": "user"
145
+ },
146
+ "userTurn": {
147
+ "type": "string",
148
+ "minLength": 8,
149
+ "maxLength": 256
150
+ },
151
+ "reason": {
152
+ "const": "USER_WITHDRAWAL"
138
153
  }
139
154
  }
140
155
  },
@@ -146,6 +161,95 @@ export const capability={
146
161
  "$args"
147
162
  ]
148
163
  }
164
+ },
165
+ {
166
+ "id": "approval.restoreRevoked",
167
+ "group": "approval",
168
+ "mode": "write",
169
+ "description": "Recover one previously presented R approval mistakenly revoked after a P issue was prepared; requires fresh user consent, matching original Form evidence, no Start/Owner history, exact CAS.",
170
+ "inputSchema": {
171
+ "type": "object",
172
+ "additionalProperties": false,
173
+ "required": [
174
+ "operation",
175
+ "projectId",
176
+ "taskId",
177
+ "issueId",
178
+ "sourceRole",
179
+ "originalUserTurn",
180
+ "consentUserTurn",
181
+ "presentedAssistantRef",
182
+ "reason",
183
+ "expectedTaskRevision",
184
+ "expectedApprovalRevision",
185
+ "expectedStoreEpoch",
186
+ "writeRequestId"
187
+ ],
188
+ "properties": {
189
+ "projectId": {
190
+ "type": "string",
191
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
192
+ },
193
+ "taskId": {
194
+ "type": "string",
195
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
196
+ },
197
+ "expectedTaskRevision": {
198
+ "type": "integer",
199
+ "minimum": 1
200
+ },
201
+ "expectedApprovalRevision": {
202
+ "type": "integer",
203
+ "minimum": 1
204
+ },
205
+ "expectedStoreEpoch": {
206
+ "type": "string",
207
+ "minLength": 10,
208
+ "maxLength": 64
209
+ },
210
+ "writeRequestId": {
211
+ "type": "string",
212
+ "minLength": 8,
213
+ "maxLength": 128
214
+ },
215
+ "operation": {
216
+ "const": "approval.restoreRevoked"
217
+ },
218
+ "issueId": {
219
+ "type": "string",
220
+ "minLength": 8,
221
+ "maxLength": 64
222
+ },
223
+ "sourceRole": {
224
+ "const": "user"
225
+ },
226
+ "originalUserTurn": {
227
+ "type": "string",
228
+ "minLength": 48,
229
+ "maxLength": 256
230
+ },
231
+ "consentUserTurn": {
232
+ "type": "string",
233
+ "minLength": 8,
234
+ "maxLength": 256
235
+ },
236
+ "presentedAssistantRef": {
237
+ "type": "string",
238
+ "minLength": 8,
239
+ "maxLength": 256
240
+ },
241
+ "reason": {
242
+ "const": "ERRONEOUS_AGENT_REVOKE"
243
+ }
244
+ }
245
+ },
246
+ "route": {
247
+ "kind": "core",
248
+ "method": "restoreRevokedApproval",
249
+ "params": [
250
+ "$args"
251
+ ]
252
+ }
149
253
  }
150
254
  ]
151
255
  };
@@ -1553,7 +1553,8 @@
1553
1553
  "userTurn": {
1554
1554
  "type": "string",
1555
1555
  "minLength": 8,
1556
- "maxLength": 256
1556
+ "maxLength": 256,
1557
+ "description": "For a Form A without platform user message ID, store its exact real identifiers: user-turn:UNAVAILABLE; form:<actual formId>; trace:<actual traceRef>; approve. Reject generic current-chat placeholders; never invent user approval."
1557
1558
  },
1558
1559
  "presentedAssistantRef": {
1559
1560
  "type": "string",
@@ -1589,7 +1590,7 @@
1589
1590
  "id": "approval.revoke",
1590
1591
  "group": "approval",
1591
1592
  "mode": "write",
1592
- "description": "Invalidate earlier approvals at the correct task revision.",
1593
+ "description": "Revoke approvals only on explicit user withdrawal, not diagnostics.",
1593
1594
  "inputSchema": {
1594
1595
  "type": "object",
1595
1596
  "required": [
@@ -1599,7 +1600,10 @@
1599
1600
  "expectedTaskRevision",
1600
1601
  "expectedApprovalRevision",
1601
1602
  "expectedStoreEpoch",
1602
- "writeRequestId"
1603
+ "writeRequestId",
1604
+ "sourceRole",
1605
+ "userTurn",
1606
+ "reason"
1603
1607
  ],
1604
1608
  "additionalProperties": false,
1605
1609
  "properties": {
@@ -1631,6 +1635,17 @@
1631
1635
  "type": "string",
1632
1636
  "minLength": 8,
1633
1637
  "maxLength": 128
1638
+ },
1639
+ "sourceRole": {
1640
+ "const": "user"
1641
+ },
1642
+ "userTurn": {
1643
+ "type": "string",
1644
+ "minLength": 8,
1645
+ "maxLength": 256
1646
+ },
1647
+ "reason": {
1648
+ "const": "USER_WITHDRAWAL"
1634
1649
  }
1635
1650
  }
1636
1651
  },
@@ -2031,6 +2046,96 @@
2031
2046
  ]
2032
2047
  },
2033
2048
  "order": 33
2049
+ },
2050
+ {
2051
+ "id": "approval.restoreRevoked",
2052
+ "group": "approval",
2053
+ "mode": "write",
2054
+ "description": "Recover one previously presented R approval mistakenly revoked after a P issue was prepared; requires fresh user consent, matching original Form evidence, no Start/Owner history, exact CAS.",
2055
+ "inputSchema": {
2056
+ "type": "object",
2057
+ "additionalProperties": false,
2058
+ "required": [
2059
+ "operation",
2060
+ "projectId",
2061
+ "taskId",
2062
+ "issueId",
2063
+ "sourceRole",
2064
+ "originalUserTurn",
2065
+ "consentUserTurn",
2066
+ "presentedAssistantRef",
2067
+ "reason",
2068
+ "expectedTaskRevision",
2069
+ "expectedApprovalRevision",
2070
+ "expectedStoreEpoch",
2071
+ "writeRequestId"
2072
+ ],
2073
+ "properties": {
2074
+ "projectId": {
2075
+ "type": "string",
2076
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
2077
+ },
2078
+ "taskId": {
2079
+ "type": "string",
2080
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
2081
+ },
2082
+ "expectedTaskRevision": {
2083
+ "type": "integer",
2084
+ "minimum": 1
2085
+ },
2086
+ "expectedApprovalRevision": {
2087
+ "type": "integer",
2088
+ "minimum": 1
2089
+ },
2090
+ "expectedStoreEpoch": {
2091
+ "type": "string",
2092
+ "minLength": 10,
2093
+ "maxLength": 64
2094
+ },
2095
+ "writeRequestId": {
2096
+ "type": "string",
2097
+ "minLength": 8,
2098
+ "maxLength": 128
2099
+ },
2100
+ "operation": {
2101
+ "const": "approval.restoreRevoked"
2102
+ },
2103
+ "issueId": {
2104
+ "type": "string",
2105
+ "minLength": 8,
2106
+ "maxLength": 64
2107
+ },
2108
+ "sourceRole": {
2109
+ "const": "user"
2110
+ },
2111
+ "originalUserTurn": {
2112
+ "type": "string",
2113
+ "minLength": 48,
2114
+ "maxLength": 256
2115
+ },
2116
+ "consentUserTurn": {
2117
+ "type": "string",
2118
+ "minLength": 8,
2119
+ "maxLength": 256
2120
+ },
2121
+ "presentedAssistantRef": {
2122
+ "type": "string",
2123
+ "minLength": 8,
2124
+ "maxLength": 256
2125
+ },
2126
+ "reason": {
2127
+ "const": "ERRONEOUS_AGENT_REVOKE"
2128
+ }
2129
+ }
2130
+ },
2131
+ "route": {
2132
+ "kind": "core",
2133
+ "method": "restoreRevokedApproval",
2134
+ "params": [
2135
+ "$args"
2136
+ ]
2137
+ },
2138
+ "order": 34
2034
2139
  }
2035
2140
  ]
2036
2141
  }
@@ -1,6 +1,6 @@
1
1
  // Context Core review methods. Shared access and transactions are injected from store.mjs.
2
2
  export function createReviewMethods(values) {
3
- const {assert, ID, digest, parse, db, hasRequirementApproval, randomUUID, checkIds, receipt, readAuth, ensureNoPendingIssue, expectedBusiness, scope} = values;
3
+ const {assert, ID, digest, parse, db, hasRequirementApproval, randomUUID, checkIds, receipt, readAuth, ensureNoPendingIssue, expectedBusiness, scope, projectDrift, unresolvedEffects} = values;
4
4
  return {
5
5
  documentCreate(a){
6
6
  return receipt(a,'document.createDraft',()=>{
@@ -134,6 +134,11 @@ export function createReviewMethods(values) {
134
134
  .get(a.projectId,a.taskId,issue.document_id,issue.version);
135
135
  assert(doc&&doc.content_hash===issue.content_hash,'DOCUMENT_CHANGED');
136
136
  assert(['R','P'].includes(doc.kind),'ISSUE_DOCUMENT_KIND_INVALID');
137
+ if(a.decision==='APPROVE'&&a.userTurn.startsWith('user-turn:UNAVAILABLE')){
138
+ const source=a.userTurn.match(/^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);
139
+ assert(source&&source[1].toLowerCase()!==source[2].toLowerCase(),
140
+ 'APPROVAL_FORM_SOURCE_REF_REQUIRED');
141
+ }
137
142
  if(a.decision!=='APPROVE'){
138
143
  // The legacy CUSTOM decision has the same meaning as a change request.
139
144
  const issueStatus=a.decision==='REJECT'?'REJECTED':'CHANGE_REQUESTED';
@@ -166,11 +171,72 @@ export function createReviewMethods(values) {
166
171
  approvalRevision:r.approval_revision+1};
167
172
  });
168
173
  },
174
+ restoreRevokedApproval(a){
175
+ return receipt(a,'approval.restoreRevoked',()=>{
176
+ const r=scope(a);expectedBusiness(r,a.expectedTaskRevision);
177
+ assert(r.approval_revision===a.expectedApprovalRevision,'APPROVAL_CONFLICT');
178
+ assert(a.reason==='ERRONEOUS_AGENT_REVOKE'&&a.sourceRole==='user'
179
+ &&typeof a.consentUserTurn==='string'
180
+ &&a.consentUserTurn.length>=8&&a.consentUserTurn.length<=256,
181
+ 'RESTORE_CONSENT_REQUIRED');
182
+ const original=typeof a.originalUserTurn==='string'
183
+ ?a.originalUserTurn.match(/^user-turn:UNAVAILABLE; form:([a-z0-9_-]{8,80}); trace:([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}); approve$/i)
184
+ :null;
185
+ assert(original&&a.originalUserTurn!==a.consentUserTurn,
186
+ 'RESTORE_ORIGINAL_TURN_INVALID');
187
+ const issue=db.prepare('SELECT * FROM issues WHERE project_id=? AND task_id=? AND issue_id=?')
188
+ .get(a.projectId,a.taskId,a.issueId);
189
+ assert(issue&&issue.state==='PRESENTED'
190
+ &&issue.presented_ref===a.presentedAssistantRef,
191
+ 'RESTORE_ORIGINAL_ISSUE_UNVERIFIED');
192
+ const doc=db.prepare('SELECT * FROM documents WHERE project_id=? AND task_id=? AND document_id=? AND version=?')
193
+ .get(a.projectId,a.taskId,issue.document_id,issue.version);
194
+ assert(doc&&doc.kind==='R'&&doc.content_hash===issue.content_hash
195
+ &&new RegExp('(?:^|[-_])r'+issue.version+'(?:[-_]|$)','i').test(original[1]),
196
+ 'RESTORE_REQUIREMENT_VERSION_MISMATCH');
197
+ const currentApprovals=parse(r.approval_json);
198
+ assert(Array.isArray(currentApprovals)&&currentApprovals.length===0,
199
+ 'RESTORE_APPROVAL_NOT_EMPTY');
200
+ const c=parse(r.context_json);
201
+ assert(r.binding_revision===0&&r.writable_ref===null
202
+ &&r.pending_attempt===null&&r.pending_checkpoint===null
203
+ &&c.stage==='DRAFT'&&!c.executionOutcome&&!c.deliveryRef
204
+ &&!c.sessionCancellation&&unresolvedEffects(c).length===0
205
+ &&!projectDrift(r).projectDrift,'RESTORE_TASK_ALREADY_STARTED');
206
+ assert(!db.prepare('SELECT 1 FROM start_leases WHERE project_id=? AND task_id=? LIMIT 1')
207
+ .get(a.projectId,a.taskId)
208
+ &&!db.prepare('SELECT 1 FROM permits WHERE project_id=? AND task_id=? LIMIT 1')
209
+ .get(a.projectId,a.taskId),'RESTORE_START_HISTORY');
210
+ const pendingPlans=db.prepare('SELECT d.requirement_ref FROM issues i JOIN documents d ON d.project_id=i.project_id AND d.task_id=i.task_id AND d.document_id=i.document_id AND d.version=i.version WHERE i.project_id=? AND i.task_id=? AND i.state=? AND d.kind=?')
211
+ .all(a.projectId,a.taskId,'PENDING','P');
212
+ assert(pendingPlans.length===1,'RESTORE_PENDING_PLAN_REQUIRED');
213
+ const req=parse(pendingPlans[0].requirement_ref);
214
+ assert(req&&req.documentId===issue.document_id
215
+ &&req.version===issue.version&&req.contentHash===issue.content_hash,
216
+ 'RESTORE_PENDING_PLAN_REF_MISMATCH');
217
+ const record={kind:'R',documentId:issue.document_id,version:issue.version,
218
+ contentHash:issue.content_hash,presentedAssistantRef:issue.presented_ref,
219
+ userTurn:a.originalUserTurn,sourceRole:'user',proofLevel:'SOFT_USER_TURN',
220
+ recoveryReason:'ERRONEOUS_AGENT_REVOKE',
221
+ recoveryConsentDigest:digest(a.consentUserTurn)};
222
+ db.prepare('UPDATE tasks SET approval_json=?,approval_revision=approval_revision+1,business_revision=business_revision+1 WHERE project_id=? AND task_id=?')
223
+ .run(JSON.stringify([record]),a.projectId,a.taskId);
224
+ return {status:'RESTORED_SOFT',kind:'R',documentId:issue.document_id,
225
+ version:issue.version,taskRevision:r.business_revision+1,
226
+ approvalRevision:r.approval_revision+1,proofLevel:'SOFT_USER_TURN'};
227
+ });
228
+ },
169
229
  revokeApproval(a){
170
230
  return receipt(a,'approval.revoke',()=>{
171
231
  const r=scope(a);
172
232
  expectedBusiness(r,a.expectedTaskRevision);
173
233
  assert(r.approval_revision===a.expectedApprovalRevision,'APPROVAL_CONFLICT');
234
+ assert(a.reason==='USER_WITHDRAWAL'&&a.sourceRole==='user'
235
+ &&typeof a.userTurn==='string'&&a.userTurn.length>=8
236
+ &&a.userTurn.length<=256,'APPROVAL_REVOKE_USER_EVIDENCE_REQUIRED');
237
+ assert(!db.prepare('SELECT 1 FROM issues i JOIN documents d ON d.project_id=i.project_id AND d.task_id=i.task_id AND d.document_id=i.document_id AND d.version=i.version WHERE i.project_id=? AND i.task_id=? AND i.state=? AND d.kind=? LIMIT 1')
238
+ .get(a.projectId,a.taskId,'PENDING','P'),
239
+ 'APPROVAL_REVOKE_PENDING_PLAN');
174
240
  db.prepare("UPDATE tasks SET approval_json='[]', approval_revision=approval_revision+1, business_revision=business_revision+1 WHERE project_id=? AND task_id=?")
175
241
  .run(a.projectId,a.taskId);
176
242
  return {status:'REVOKED',approvalRevision:r.approval_revision+1,taskRevision:r.business_revision+1};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-context",
3
- "version": "0.6.40",
3
+ "version": "0.6.42",
4
4
  "type": "module",
5
5
  "description": "Independent local Context SDK and short-lived CLI for Chat Loop projects",
6
6
  "publishConfig": {
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "ps-list": "9.0.0",
35
- "@tomflow/chatloop-extension": "0.4.44",
35
+ "@tomflow/chatloop-extension": "0.4.45",
36
36
  "@tomflow/chatloop-trace": "0.4.6"
37
37
  }
38
38
  }