@tomflow/chatloop-context 0.6.40 → 0.6.41
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/capabilities/approval.mjs +105 -2
- package/lib/capability-catalog.generated.json +106 -2
- package/lib/core/review.mjs +62 -1
- package/package.json +1 -1
|
@@ -93,7 +93,7 @@ export const capability={
|
|
|
93
93
|
"id": "approval.revoke",
|
|
94
94
|
"group": "approval",
|
|
95
95
|
"mode": "write",
|
|
96
|
-
"description": "
|
|
96
|
+
"description": "Revoke approvals only on explicit user withdrawal, not diagnostics.",
|
|
97
97
|
"inputSchema": {
|
|
98
98
|
"type": "object",
|
|
99
99
|
"required": [
|
|
@@ -103,7 +103,10 @@ export const capability={
|
|
|
103
103
|
"expectedTaskRevision",
|
|
104
104
|
"expectedApprovalRevision",
|
|
105
105
|
"expectedStoreEpoch",
|
|
106
|
-
"writeRequestId"
|
|
106
|
+
"writeRequestId",
|
|
107
|
+
"sourceRole",
|
|
108
|
+
"userTurn",
|
|
109
|
+
"reason"
|
|
107
110
|
],
|
|
108
111
|
"additionalProperties": false,
|
|
109
112
|
"properties": {
|
|
@@ -135,6 +138,17 @@ export const capability={
|
|
|
135
138
|
"type": "string",
|
|
136
139
|
"minLength": 8,
|
|
137
140
|
"maxLength": 128
|
|
141
|
+
},
|
|
142
|
+
"sourceRole": {
|
|
143
|
+
"const": "user"
|
|
144
|
+
},
|
|
145
|
+
"userTurn": {
|
|
146
|
+
"type": "string",
|
|
147
|
+
"minLength": 8,
|
|
148
|
+
"maxLength": 256
|
|
149
|
+
},
|
|
150
|
+
"reason": {
|
|
151
|
+
"const": "USER_WITHDRAWAL"
|
|
138
152
|
}
|
|
139
153
|
}
|
|
140
154
|
},
|
|
@@ -146,6 +160,95 @@ export const capability={
|
|
|
146
160
|
"$args"
|
|
147
161
|
]
|
|
148
162
|
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"id": "approval.restoreRevoked",
|
|
166
|
+
"group": "approval",
|
|
167
|
+
"mode": "write",
|
|
168
|
+
"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.",
|
|
169
|
+
"inputSchema": {
|
|
170
|
+
"type": "object",
|
|
171
|
+
"additionalProperties": false,
|
|
172
|
+
"required": [
|
|
173
|
+
"operation",
|
|
174
|
+
"projectId",
|
|
175
|
+
"taskId",
|
|
176
|
+
"issueId",
|
|
177
|
+
"sourceRole",
|
|
178
|
+
"originalUserTurn",
|
|
179
|
+
"consentUserTurn",
|
|
180
|
+
"presentedAssistantRef",
|
|
181
|
+
"reason",
|
|
182
|
+
"expectedTaskRevision",
|
|
183
|
+
"expectedApprovalRevision",
|
|
184
|
+
"expectedStoreEpoch",
|
|
185
|
+
"writeRequestId"
|
|
186
|
+
],
|
|
187
|
+
"properties": {
|
|
188
|
+
"projectId": {
|
|
189
|
+
"type": "string",
|
|
190
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
|
|
191
|
+
},
|
|
192
|
+
"taskId": {
|
|
193
|
+
"type": "string",
|
|
194
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
|
|
195
|
+
},
|
|
196
|
+
"expectedTaskRevision": {
|
|
197
|
+
"type": "integer",
|
|
198
|
+
"minimum": 1
|
|
199
|
+
},
|
|
200
|
+
"expectedApprovalRevision": {
|
|
201
|
+
"type": "integer",
|
|
202
|
+
"minimum": 1
|
|
203
|
+
},
|
|
204
|
+
"expectedStoreEpoch": {
|
|
205
|
+
"type": "string",
|
|
206
|
+
"minLength": 10,
|
|
207
|
+
"maxLength": 64
|
|
208
|
+
},
|
|
209
|
+
"writeRequestId": {
|
|
210
|
+
"type": "string",
|
|
211
|
+
"minLength": 8,
|
|
212
|
+
"maxLength": 128
|
|
213
|
+
},
|
|
214
|
+
"operation": {
|
|
215
|
+
"const": "approval.restoreRevoked"
|
|
216
|
+
},
|
|
217
|
+
"issueId": {
|
|
218
|
+
"type": "string",
|
|
219
|
+
"minLength": 8,
|
|
220
|
+
"maxLength": 64
|
|
221
|
+
},
|
|
222
|
+
"sourceRole": {
|
|
223
|
+
"const": "user"
|
|
224
|
+
},
|
|
225
|
+
"originalUserTurn": {
|
|
226
|
+
"type": "string",
|
|
227
|
+
"minLength": 48,
|
|
228
|
+
"maxLength": 256
|
|
229
|
+
},
|
|
230
|
+
"consentUserTurn": {
|
|
231
|
+
"type": "string",
|
|
232
|
+
"minLength": 8,
|
|
233
|
+
"maxLength": 256
|
|
234
|
+
},
|
|
235
|
+
"presentedAssistantRef": {
|
|
236
|
+
"type": "string",
|
|
237
|
+
"minLength": 8,
|
|
238
|
+
"maxLength": 256
|
|
239
|
+
},
|
|
240
|
+
"reason": {
|
|
241
|
+
"const": "ERRONEOUS_AGENT_REVOKE"
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
"route": {
|
|
246
|
+
"kind": "core",
|
|
247
|
+
"method": "restoreRevokedApproval",
|
|
248
|
+
"params": [
|
|
249
|
+
"$args"
|
|
250
|
+
]
|
|
251
|
+
}
|
|
149
252
|
}
|
|
150
253
|
]
|
|
151
254
|
};
|
|
@@ -1589,7 +1589,7 @@
|
|
|
1589
1589
|
"id": "approval.revoke",
|
|
1590
1590
|
"group": "approval",
|
|
1591
1591
|
"mode": "write",
|
|
1592
|
-
"description": "
|
|
1592
|
+
"description": "Revoke approvals only on explicit user withdrawal, not diagnostics.",
|
|
1593
1593
|
"inputSchema": {
|
|
1594
1594
|
"type": "object",
|
|
1595
1595
|
"required": [
|
|
@@ -1599,7 +1599,10 @@
|
|
|
1599
1599
|
"expectedTaskRevision",
|
|
1600
1600
|
"expectedApprovalRevision",
|
|
1601
1601
|
"expectedStoreEpoch",
|
|
1602
|
-
"writeRequestId"
|
|
1602
|
+
"writeRequestId",
|
|
1603
|
+
"sourceRole",
|
|
1604
|
+
"userTurn",
|
|
1605
|
+
"reason"
|
|
1603
1606
|
],
|
|
1604
1607
|
"additionalProperties": false,
|
|
1605
1608
|
"properties": {
|
|
@@ -1631,6 +1634,17 @@
|
|
|
1631
1634
|
"type": "string",
|
|
1632
1635
|
"minLength": 8,
|
|
1633
1636
|
"maxLength": 128
|
|
1637
|
+
},
|
|
1638
|
+
"sourceRole": {
|
|
1639
|
+
"const": "user"
|
|
1640
|
+
},
|
|
1641
|
+
"userTurn": {
|
|
1642
|
+
"type": "string",
|
|
1643
|
+
"minLength": 8,
|
|
1644
|
+
"maxLength": 256
|
|
1645
|
+
},
|
|
1646
|
+
"reason": {
|
|
1647
|
+
"const": "USER_WITHDRAWAL"
|
|
1634
1648
|
}
|
|
1635
1649
|
}
|
|
1636
1650
|
},
|
|
@@ -2031,6 +2045,96 @@
|
|
|
2031
2045
|
]
|
|
2032
2046
|
},
|
|
2033
2047
|
"order": 33
|
|
2048
|
+
},
|
|
2049
|
+
{
|
|
2050
|
+
"id": "approval.restoreRevoked",
|
|
2051
|
+
"group": "approval",
|
|
2052
|
+
"mode": "write",
|
|
2053
|
+
"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.",
|
|
2054
|
+
"inputSchema": {
|
|
2055
|
+
"type": "object",
|
|
2056
|
+
"additionalProperties": false,
|
|
2057
|
+
"required": [
|
|
2058
|
+
"operation",
|
|
2059
|
+
"projectId",
|
|
2060
|
+
"taskId",
|
|
2061
|
+
"issueId",
|
|
2062
|
+
"sourceRole",
|
|
2063
|
+
"originalUserTurn",
|
|
2064
|
+
"consentUserTurn",
|
|
2065
|
+
"presentedAssistantRef",
|
|
2066
|
+
"reason",
|
|
2067
|
+
"expectedTaskRevision",
|
|
2068
|
+
"expectedApprovalRevision",
|
|
2069
|
+
"expectedStoreEpoch",
|
|
2070
|
+
"writeRequestId"
|
|
2071
|
+
],
|
|
2072
|
+
"properties": {
|
|
2073
|
+
"projectId": {
|
|
2074
|
+
"type": "string",
|
|
2075
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
|
|
2076
|
+
},
|
|
2077
|
+
"taskId": {
|
|
2078
|
+
"type": "string",
|
|
2079
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
|
|
2080
|
+
},
|
|
2081
|
+
"expectedTaskRevision": {
|
|
2082
|
+
"type": "integer",
|
|
2083
|
+
"minimum": 1
|
|
2084
|
+
},
|
|
2085
|
+
"expectedApprovalRevision": {
|
|
2086
|
+
"type": "integer",
|
|
2087
|
+
"minimum": 1
|
|
2088
|
+
},
|
|
2089
|
+
"expectedStoreEpoch": {
|
|
2090
|
+
"type": "string",
|
|
2091
|
+
"minLength": 10,
|
|
2092
|
+
"maxLength": 64
|
|
2093
|
+
},
|
|
2094
|
+
"writeRequestId": {
|
|
2095
|
+
"type": "string",
|
|
2096
|
+
"minLength": 8,
|
|
2097
|
+
"maxLength": 128
|
|
2098
|
+
},
|
|
2099
|
+
"operation": {
|
|
2100
|
+
"const": "approval.restoreRevoked"
|
|
2101
|
+
},
|
|
2102
|
+
"issueId": {
|
|
2103
|
+
"type": "string",
|
|
2104
|
+
"minLength": 8,
|
|
2105
|
+
"maxLength": 64
|
|
2106
|
+
},
|
|
2107
|
+
"sourceRole": {
|
|
2108
|
+
"const": "user"
|
|
2109
|
+
},
|
|
2110
|
+
"originalUserTurn": {
|
|
2111
|
+
"type": "string",
|
|
2112
|
+
"minLength": 48,
|
|
2113
|
+
"maxLength": 256
|
|
2114
|
+
},
|
|
2115
|
+
"consentUserTurn": {
|
|
2116
|
+
"type": "string",
|
|
2117
|
+
"minLength": 8,
|
|
2118
|
+
"maxLength": 256
|
|
2119
|
+
},
|
|
2120
|
+
"presentedAssistantRef": {
|
|
2121
|
+
"type": "string",
|
|
2122
|
+
"minLength": 8,
|
|
2123
|
+
"maxLength": 256
|
|
2124
|
+
},
|
|
2125
|
+
"reason": {
|
|
2126
|
+
"const": "ERRONEOUS_AGENT_REVOKE"
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
},
|
|
2130
|
+
"route": {
|
|
2131
|
+
"kind": "core",
|
|
2132
|
+
"method": "restoreRevokedApproval",
|
|
2133
|
+
"params": [
|
|
2134
|
+
"$args"
|
|
2135
|
+
]
|
|
2136
|
+
},
|
|
2137
|
+
"order": 34
|
|
2034
2138
|
}
|
|
2035
2139
|
]
|
|
2036
2140
|
}
|
package/lib/core/review.mjs
CHANGED
|
@@ -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',()=>{
|
|
@@ -166,11 +166,72 @@ export function createReviewMethods(values) {
|
|
|
166
166
|
approvalRevision:r.approval_revision+1};
|
|
167
167
|
});
|
|
168
168
|
},
|
|
169
|
+
restoreRevokedApproval(a){
|
|
170
|
+
return receipt(a,'approval.restoreRevoked',()=>{
|
|
171
|
+
const r=scope(a);expectedBusiness(r,a.expectedTaskRevision);
|
|
172
|
+
assert(r.approval_revision===a.expectedApprovalRevision,'APPROVAL_CONFLICT');
|
|
173
|
+
assert(a.reason==='ERRONEOUS_AGENT_REVOKE'&&a.sourceRole==='user'
|
|
174
|
+
&&typeof a.consentUserTurn==='string'
|
|
175
|
+
&&a.consentUserTurn.length>=8&&a.consentUserTurn.length<=256,
|
|
176
|
+
'RESTORE_CONSENT_REQUIRED');
|
|
177
|
+
const original=typeof a.originalUserTurn==='string'
|
|
178
|
+
?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)
|
|
179
|
+
:null;
|
|
180
|
+
assert(original&&a.originalUserTurn!==a.consentUserTurn,
|
|
181
|
+
'RESTORE_ORIGINAL_TURN_INVALID');
|
|
182
|
+
const issue=db.prepare('SELECT * FROM issues WHERE project_id=? AND task_id=? AND issue_id=?')
|
|
183
|
+
.get(a.projectId,a.taskId,a.issueId);
|
|
184
|
+
assert(issue&&issue.state==='PRESENTED'
|
|
185
|
+
&&issue.presented_ref===a.presentedAssistantRef,
|
|
186
|
+
'RESTORE_ORIGINAL_ISSUE_UNVERIFIED');
|
|
187
|
+
const doc=db.prepare('SELECT * FROM documents WHERE project_id=? AND task_id=? AND document_id=? AND version=?')
|
|
188
|
+
.get(a.projectId,a.taskId,issue.document_id,issue.version);
|
|
189
|
+
assert(doc&&doc.kind==='R'&&doc.content_hash===issue.content_hash
|
|
190
|
+
&&new RegExp('(?:^|[-_])r'+issue.version+'(?:[-_]|$)','i').test(original[1]),
|
|
191
|
+
'RESTORE_REQUIREMENT_VERSION_MISMATCH');
|
|
192
|
+
const currentApprovals=parse(r.approval_json);
|
|
193
|
+
assert(Array.isArray(currentApprovals)&¤tApprovals.length===0,
|
|
194
|
+
'RESTORE_APPROVAL_NOT_EMPTY');
|
|
195
|
+
const c=parse(r.context_json);
|
|
196
|
+
assert(r.binding_revision===0&&r.writable_ref===null
|
|
197
|
+
&&r.pending_attempt===null&&r.pending_checkpoint===null
|
|
198
|
+
&&c.stage==='DRAFT'&&!c.executionOutcome&&!c.deliveryRef
|
|
199
|
+
&&!c.sessionCancellation&&unresolvedEffects(c).length===0
|
|
200
|
+
&&!projectDrift(r).projectDrift,'RESTORE_TASK_ALREADY_STARTED');
|
|
201
|
+
assert(!db.prepare('SELECT 1 FROM start_leases WHERE project_id=? AND task_id=? LIMIT 1')
|
|
202
|
+
.get(a.projectId,a.taskId)
|
|
203
|
+
&&!db.prepare('SELECT 1 FROM permits WHERE project_id=? AND task_id=? LIMIT 1')
|
|
204
|
+
.get(a.projectId,a.taskId),'RESTORE_START_HISTORY');
|
|
205
|
+
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=?')
|
|
206
|
+
.all(a.projectId,a.taskId,'PENDING','P');
|
|
207
|
+
assert(pendingPlans.length===1,'RESTORE_PENDING_PLAN_REQUIRED');
|
|
208
|
+
const req=parse(pendingPlans[0].requirement_ref);
|
|
209
|
+
assert(req&&req.documentId===issue.document_id
|
|
210
|
+
&&req.version===issue.version&&req.contentHash===issue.content_hash,
|
|
211
|
+
'RESTORE_PENDING_PLAN_REF_MISMATCH');
|
|
212
|
+
const record={kind:'R',documentId:issue.document_id,version:issue.version,
|
|
213
|
+
contentHash:issue.content_hash,presentedAssistantRef:issue.presented_ref,
|
|
214
|
+
userTurn:a.originalUserTurn,sourceRole:'user',proofLevel:'SOFT_USER_TURN',
|
|
215
|
+
recoveryReason:'ERRONEOUS_AGENT_REVOKE',
|
|
216
|
+
recoveryConsentDigest:digest(a.consentUserTurn)};
|
|
217
|
+
db.prepare('UPDATE tasks SET approval_json=?,approval_revision=approval_revision+1,business_revision=business_revision+1 WHERE project_id=? AND task_id=?')
|
|
218
|
+
.run(JSON.stringify([record]),a.projectId,a.taskId);
|
|
219
|
+
return {status:'RESTORED_SOFT',kind:'R',documentId:issue.document_id,
|
|
220
|
+
version:issue.version,taskRevision:r.business_revision+1,
|
|
221
|
+
approvalRevision:r.approval_revision+1,proofLevel:'SOFT_USER_TURN'};
|
|
222
|
+
});
|
|
223
|
+
},
|
|
169
224
|
revokeApproval(a){
|
|
170
225
|
return receipt(a,'approval.revoke',()=>{
|
|
171
226
|
const r=scope(a);
|
|
172
227
|
expectedBusiness(r,a.expectedTaskRevision);
|
|
173
228
|
assert(r.approval_revision===a.expectedApprovalRevision,'APPROVAL_CONFLICT');
|
|
229
|
+
assert(a.reason==='USER_WITHDRAWAL'&&a.sourceRole==='user'
|
|
230
|
+
&&typeof a.userTurn==='string'&&a.userTurn.length>=8
|
|
231
|
+
&&a.userTurn.length<=256,'APPROVAL_REVOKE_USER_EVIDENCE_REQUIRED');
|
|
232
|
+
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')
|
|
233
|
+
.get(a.projectId,a.taskId,'PENDING','P'),
|
|
234
|
+
'APPROVAL_REVOKE_PENDING_PLAN');
|
|
174
235
|
db.prepare("UPDATE tasks SET approval_json='[]', approval_revision=approval_revision+1, business_revision=business_revision+1 WHERE project_id=? AND task_id=?")
|
|
175
236
|
.run(a.projectId,a.taskId);
|
|
176
237
|
return {status:'REVOKED',approvalRevision:r.approval_revision+1,taskRevision:r.business_revision+1};
|