@tomflow/chatloop-context 0.1.4 → 0.6.0

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.
Files changed (46) hide show
  1. package/README.md +240 -271
  2. package/bin/cli.mjs +25 -250
  3. package/capabilities/approval.mjs +151 -0
  4. package/capabilities/context.mjs +376 -0
  5. package/capabilities/document.mjs +266 -0
  6. package/capabilities/evidence.mjs +134 -0
  7. package/capabilities/presentation.mjs +82 -0
  8. package/capabilities/project.mjs +349 -0
  9. package/capabilities/sdk.mjs +72 -0
  10. package/capabilities/start.mjs +73 -0
  11. package/capabilities/task.mjs +507 -0
  12. package/capabilities.generated.mjs +11 -0
  13. package/docs/interfaces.md +182 -0
  14. package/docs/operator-and-migration.md +277 -0
  15. package/index.mjs +236 -0
  16. package/lib/api-aspect.mjs +190 -0
  17. package/lib/api-log.mjs +161 -0
  18. package/lib/approval-policy.mjs +24 -0
  19. package/lib/capability-catalog.generated.json +1989 -0
  20. package/lib/capability-router.mjs +67 -0
  21. package/lib/cli-commands.mjs +280 -0
  22. package/lib/context-cli.mjs +16 -19
  23. package/lib/context-migration.mjs +17 -9
  24. package/lib/core/context.mjs +115 -0
  25. package/lib/core/evidence.mjs +51 -0
  26. package/lib/core/health.mjs +55 -0
  27. package/lib/core/migration.mjs +262 -0
  28. package/lib/core/project.mjs +246 -0
  29. package/lib/core/review.mjs +147 -0
  30. package/lib/core/run.mjs +343 -0
  31. package/lib/core/store.mjs +391 -0
  32. package/lib/core/task.mjs +166 -0
  33. package/lib/line-review.mjs +13 -0
  34. package/lib/methods.mjs +49 -202
  35. package/lib/operations.mjs +33 -145
  36. package/lib/orphan-operator.mjs +117 -0
  37. package/lib/process-inventory.mjs +20 -0
  38. package/lib/project-branch.mjs +312 -0
  39. package/lib/project-diagnostic.mjs +26 -328
  40. package/lib/project-guards.mjs +19 -0
  41. package/lib/project-store.mjs +115 -0
  42. package/lib/trusted-run.mjs +86 -0
  43. package/lib/workspace-operator.mjs +12 -2
  44. package/package.json +32 -14
  45. package/scripts/build-capabilities.mjs +114 -0
  46. package/lib/context-protocol.mjs +0 -1617
package/bin/cli.mjs CHANGED
@@ -1,272 +1,47 @@
1
1
  #!/usr/bin/env node
2
- // One invocation = one bounded Context SDK request; never a background server.
3
- import {randomUUID,createHash} from 'node:crypto';
4
- import {existsSync,mkdirSync,mkdtempSync,renameSync,rmSync} from 'node:fs';
5
- import {join} from 'node:path';
6
- let canonicalWorkspaceRefs,confirmWorkspaceOperator,assertWorkspaceUnclaimed,
7
- withWorkspaceRegistryLock,rebindProjectWorkspaces,readOperatorWorkspaceReceipt;
8
- import {CONTEXT_CONTRACT,CONTEXT_PACKAGE_VERSION,methodById,validateContextCall,listMethods,describeMethod} from '../lib/methods.mjs';
9
- // Catalog is Node 20-compatible; SQLite operations load only after Node 24 preflight.
10
- let openContextProtocol,dispatchContextCall,contextRoot,allowedProjects,
11
- verifySourceUnit,
12
- createProjectDiagnosticBranch,createManagedProjectBranch,fenceLegacyProjectStore,
13
- auditLegacyProjectSources,inspectLegacyRegistryReference,activeLegacyWriters;
2
+ // The ONLY shell-visible entrypoint; all capabilities come from the root SDK.
3
+ import {CONTEXT_CONTRACT,CONTEXT_PACKAGE_VERSION,
4
+ requestContext,loadLocalOperator} from '../index.mjs';
5
+ // This short-lived Context CLI is the only process that emits the SDK's
6
+ // structured audit records on STDERR. Other npm consumers use subscriptions.
7
+ process.env.CHAT_LOOP_CONTEXT_API_LOG_STDERR='1';
14
8
  const fail=code=>Object.assign(new Error(code),{code});
15
- const requestLimit=5*1024*1024;
16
- const output=o=>process.stdout.write(JSON.stringify({
17
- contract:CONTEXT_CONTRACT,packageVersion:CONTEXT_PACKAGE_VERSION,...o
9
+ const limit=5*1024*1024;
10
+ const output=value=>process.stdout.write(JSON.stringify({
11
+ contract:CONTEXT_CONTRACT,packageVersion:CONTEXT_PACKAGE_VERSION,...value
18
12
  })+'\n');
19
- async function stdinJson(){
13
+ async function readJson(){
20
14
  let bytes=0,parts=[];
21
15
  for await(const chunk of process.stdin){
22
16
  bytes+=chunk.length;
23
- if(bytes>requestLimit)throw fail('REQUEST_TOO_LARGE');
17
+ if(bytes>limit)throw fail('REQUEST_TOO_LARGE');
24
18
  parts.push(chunk);
25
19
  }
26
20
  if(!bytes)throw fail('REQUEST_REQUIRED');
27
21
  try{return JSON.parse(Buffer.concat(parts).toString('utf8'))}
28
22
  catch{throw fail('INVALID_JSON')}
29
23
  }
30
- async function registerProject(projectId,title,workspaces=[],reviewed=false){
31
- if(process.env.CHAT_LOOP_CONTEXT_ADMIN_ENABLE!=='1')throw fail('ADMIN_REQUIRED');
32
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
33
- if(!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(projectId))throw fail('INVALID_SCOPE');
34
- if(typeof title!=='string'||!title.trim()||title.length>200)throw fail('INVALID_TITLE');
35
- if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
36
- const refs=canonicalWorkspaceRefs(workspaces,{allowEmpty:!reviewed});
37
- const root=contextRoot(),final=join(root,projectId);
38
- if(existsSync(final))throw fail('PROJECT_EXISTS');
39
- // The user-reviewed entry never creates a Store (or even a directory)
40
- // before the local operator confirms the exact canonical roots.
41
- if(reviewed)await confirmWorkspaceOperator('REGISTER',projectId,0,refs);
42
- mkdirSync(root,{recursive:true,mode:0o700});
43
- return withWorkspaceRegistryLock(root,()=>{
44
- let tmp;
45
- try{
46
- if(existsSync(final))throw fail('PROJECT_EXISTS');
47
- if(reviewed){
48
- const current=canonicalWorkspaceRefs(workspaces);
49
- if(JSON.stringify(current)!==JSON.stringify(refs))throw fail('WORKSPACE_CHANGED');
50
- assertWorkspaceUnclaimed(root,projectId,refs);
51
- }
52
- tmp=mkdtempSync(join(root,'.register-'));
53
- const db=openContextProtocol(join(tmp,'context.sqlite'),{
54
- allowCreate:true,authorizeData:()=>true,principalId:'local-operator'});
55
- let result;
56
- try{
57
- result=db.projectCreate({projectId,title,sharedContext:{workspaceRefs:refs},
58
- expectedStoreEpoch:db.epoch,writeRequestId:randomUUID()});
59
- }finally{db.close()}
60
- renameSync(tmp,final);tmp=null;
61
- return {...result,workspaceRefs:refs,projectDirectory:final};
62
- }finally{
63
- // Incomplete staging is diagnostic only, never silently promoted.
64
- if(tmp)rmSync(tmp,{recursive:true,force:true});
65
- }
66
- });
67
- }
68
24
  const args=process.argv.slice(2);
69
25
  try{
70
26
  const node24=Number(process.versions.node.split('.')[0])>=24;
71
27
  if(!node24&&args[0]!=='methods')throw fail('CONTEXT_RUNTIME_UNSUPPORTED');
72
- if(node24){
73
- ({openContextProtocol}=await import('../lib/context-protocol.mjs'));
74
- ({verifySourceUnit}=await import('../lib/context-migration.mjs'));
75
- ({dispatchContextCall,contextRoot,allowedProjects}=await import('../lib/operations.mjs'));
76
- ({canonicalWorkspaceRefs,confirmWorkspaceOperator,assertWorkspaceUnclaimed,
77
- withWorkspaceRegistryLock,rebindProjectWorkspaces,readOperatorWorkspaceReceipt}=
78
- await import('../lib/workspace-operator.mjs'));
79
- ({createProjectDiagnosticBranch,createManagedProjectBranch,fenceLegacyProjectStore,
80
- auditLegacyProjectSources,inspectLegacyRegistryReference}=
81
- await import('../lib/project-diagnostic.mjs'));
82
- ({activeLegacyWriters}=await import('../lib/context-cli.mjs'));
83
- }
84
- const [command,sub,...rest]=args;
85
28
  let value;
86
- if(command==='methods'&&sub==='list'&&rest.length<=1)
87
- value=listMethods(rest[0]==='--json'?undefined:rest[0]);
88
- else if(command==='methods'&&sub==='describe'&&rest.length===1)
89
- value=describeMethod(rest[0]);
90
- else if(command==='request'&&sub==='--json'&&rest.length===0){
91
- const payload=await stdinJson();
92
- if(!payload||typeof payload!=='object'||Array.isArray(payload))throw fail('INVALID_ARGUMENT');
93
- const method=validateContextCall(
94
- payload.operation&&['sdk.methods.list','sdk.methods.describe'].includes(payload.operation)?
95
- 'chat_loop_context_get':
96
- // A method is always assigned a fixed read/write mode by the SDK Catalog.
97
- methodById.get(payload.operation)?.mode==='write'?
98
- 'chat_loop_context_mutate':'chat_loop_context_get',payload);
99
- value=await dispatchContextCall(method.mode==='write'?
100
- 'chat_loop_context_mutate':'chat_loop_context_get',payload);
101
- }else if(command==='project'&&sub==='init'&&(rest.length===2||rest.length===3))
102
- value=await registerProject(rest[0],rest[1],rest.slice(2));
103
- else if(command==='project'&&sub==='register'&&rest.length>=3&&rest.length<=18)
104
- value=await registerProject(rest[0],rest[1],rest.slice(2),true);
105
- else if(command==='project'&&sub==='bind'&&rest.length>=4&&rest.length<=20){
106
- const [projectId,revision,epoch,requestId,...paths]=rest;
107
- if(paths.length===1&&paths[0]==='--clear')paths.length=0;
108
- value=await rebindProjectWorkspaces({projectId,
109
- expectedProjectRevision:Number(revision),expectedStoreEpoch:epoch,
110
- writeRequestId:requestId,workspaces:paths});
111
- }else if(command==='project'&&sub==='receipt'&&rest.length===3)
112
- value=await readOperatorWorkspaceReceipt({projectId:rest[0],
113
- storeEpoch:rest[1],writeRequestId:rest[2]});
114
- else if(command==='project'&&sub==='reconcile-reference'&&rest.length===10){
115
- const [projectId,sourceDb,expectedStoreEpoch,sourceUnitId,revision,
116
- taskId,originalArchivePath,expectedCurrentHash,reviewRef,writeRequestId]=rest;
117
- if(process.env.CHAT_LOOP_CONTEXT_ADMIN_ENABLE!=='1')throw fail('ADMIN_REQUIRED');
118
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
119
- if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
120
- const expectedMigrationRevision=Number(revision);
121
- if(!Number.isSafeInteger(expectedMigrationRevision)||expectedMigrationRevision<1)
122
- throw fail('MIGRATION_VERSION_CONFLICT');
123
- // Fail closed before any writable handle exists. Review is NOT user R/P.
124
- const evidence=inspectLegacyRegistryReference({sourceDb,projectId,
125
- expectedStoreEpoch,sourceUnitId,taskId,archiveFile:originalArchivePath});
126
- if(evidence.changeKind!=='INSERTIONS_ONLY'||
127
- evidence.currentTaskHash!==expectedCurrentHash)
128
- throw fail('REGISTRY_REFERENCE_VERSION_CONFLICT');
129
- await confirmWorkspaceOperator('RECONCILE_REFERENCE',projectId,
130
- expectedMigrationRevision,[sourceDb,sourceUnitId,taskId,
131
- evidence.archivedTaskHash,expectedCurrentHash,reviewRef]);
132
- const db=openContextProtocol(sourceDb,{principalId:'local-operator',
133
- authorizeData:(_mode,p)=>p===projectId,
134
- authorizeAdmin:(op,p)=>p===projectId&&[
135
- 'migration.reference.reconcile',
136
- 'migration.reference.reconcile.reviewed'].includes(op)});
137
- try{
138
- value=db.migrationReconcileReference({projectId,sourceUnitId,
139
- expectedMigrationRevision,expectedStoreEpoch,writeRequestId,
140
- taskId,originalArchivePath,expectedCurrentHash,
141
- sourceHash:evidence.sourceHash,reviewRef});
142
- }finally{db.close()}
143
- }else if(command==='project'&&['reconcile-receipt','migration-receipt'].includes(sub)&&rest.length===4){
144
- const [projectId,sourceDb,storeEpoch,writeRequestId]=rest;
145
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
146
- const db=openContextProtocol(sourceDb,{readOnly:true,
147
- principalId:'local-operator',
148
- authorizeData:(_mode,p)=>p===projectId});
149
- try{value=db.requestStatus({projectId,storeEpoch,writeRequestId})}
150
- finally{db.close()}
151
- }else if(command==='project'&&sub==='classify-evidence'&&rest.length===8){
152
- const [projectId,sourceDb,expectedStoreEpoch,sourceUnitId,revision,
153
- sourceHash,reviewRef,writeRequestId]=rest;
154
- if(process.env.CHAT_LOOP_CONTEXT_ADMIN_ENABLE!=='1')throw fail('ADMIN_REQUIRED');
155
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
156
- if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
157
- const expectedMigrationRevision=Number(revision);
158
- if(!Number.isSafeInteger(expectedMigrationRevision)||expectedMigrationRevision<1)
159
- throw fail('MIGRATION_VERSION_CONFLICT');
160
- if(typeof reviewRef!=='string'||reviewRef.length<8||reviewRef.length>256)
161
- throw fail('REVIEW_REFERENCE_REQUIRED');
162
- // The historical body's original bytes must already be a matching
163
- // LEGACY_UNVERIFIED Project Material, never a synthesized current Task.
164
- const reader=openContextProtocol(sourceDb,{readOnly:true,
165
- principalId:'local-operator',authorizeData:(_mode,p)=>p===projectId,
166
- authorizeAdmin:(op,p)=>op==='migration.list'&&p===projectId});
167
- let unit;
168
- try{
169
- if(reader.mode!=='ACTIVE')throw fail('STORE_DIAGNOSTIC_ONLY');
170
- if(reader.epoch!==expectedStoreEpoch)throw fail('STALE_EPOCH');
171
- unit=reader.migrationList(projectId).find(x=>x.sourceUnitId===sourceUnitId);
172
- if(!unit||unit.status!=='SHADOW_RO'||
173
- unit.manifest.sourceKind!=='MIXED_CONTEXT')
174
- throw fail('MIXED_SOURCE_NOT_SHADOW');
175
- if(unit.migrationRevision!==expectedMigrationRevision)
176
- throw fail('MIGRATION_VERSION_CONFLICT');
177
- if(unit.sourceHash!==sourceHash)throw fail('SOURCE_CHANGED');
178
- verifySourceUnit(unit.manifest);
179
- const material=reader.projectMaterialList(projectId).filter(m=>
180
- m.sourcePath===unit.sourcePath&&m.contentHash===sourceHash&&
181
- m.provenance==='LEGACY_UNVERIFIED');
182
- if(!material.some(m=>createHash('sha256').update(
183
- reader.projectMaterialGet(projectId,m.materialId,m.version).body
184
- ).digest('hex')===sourceHash))throw fail('MIGRATION_BODY_NOT_IMPORTED');
185
- }finally{reader.close()}
186
- // Human-reviewed disposition: preserve FULL mixed history as
187
- // EvidenceOnly/UNKNOWN. Do not assert any current Task or R/P fact.
188
- await confirmWorkspaceOperator('CLASSIFY_EVIDENCE_ONLY',projectId,
189
- expectedMigrationRevision,[sourceDb,sourceUnitId,sourceHash,reviewRef]);
190
- const db=openContextProtocol(sourceDb,{principalId:'local-operator',
191
- authorizeData:(_mode,p)=>p===projectId,
192
- authorizeAdmin:(op,p)=>p===projectId&&
193
- ['migration.classify','migration.classify.reviewed'].includes(op)});
194
- try{
195
- value=db.migrationClassify({projectId,sourceUnitId,sourceHash,
196
- expectedStoreEpoch,expectedMigrationRevision,writeRequestId,
197
- classification:{projectId,sourceUnitId,sourceHash,
198
- currentFactsComplete:true,reviewRef,taskContexts:[],
199
- projectSharedContext:{},
200
- unknownHistoryRefs:[{locator:unit.sourcePath,sourceHash}]}});
201
- }finally{db.close()}
202
- }else if(command==='project'&&sub==='inspect-reference'&&rest.length===6){
203
- const [projectId,sourceDb,expectedStoreEpoch,sourceUnitId,taskId,archiveFile]=rest;
204
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
205
- value=inspectLegacyRegistryReference({projectId,sourceDb,
206
- expectedStoreEpoch,sourceUnitId,taskId,archiveFile});
207
- }else if(command==='project'&&sub==='audit-sources'&&rest.length===3){
208
- const [projectId,sourceDb,expectedStoreEpoch]=rest;
209
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
210
- value=auditLegacyProjectSources({projectId,sourceDb,expectedStoreEpoch});
211
- // Observe known, supported MCP writers without claiming an independent
212
- // old-writer fence. Only PIDs are returned, never process argv or secrets.
213
- let writerObservation;
214
- try{
215
- const pids=activeLegacyWriters().map(line=>Number(line.match(/^\d+/)[0]));
216
- writerObservation={status:pids.length?'MATCHED':'NO_SUPPORTED_PROCESS_MATCH',pids};
217
- }catch{writerObservation={status:'UNVERIFIED',pids:[]}}
218
- value={...value,supportedWriterObservation:writerObservation};
219
- }else if(command==='project'&&sub==='seal-source'&&rest.length===6){
220
- const [projectId,sourceDb,epoch,revision,backupPath,sealManifestPath]=rest;
221
- if(process.env.CHAT_LOOP_CONTEXT_ADMIN_ENABLE!=='1')throw fail('ADMIN_REQUIRED');
222
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
223
- if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
224
- const expectedProjectRevision=Number(revision);
225
- if(!Number.isSafeInteger(expectedProjectRevision)||expectedProjectRevision<1)
226
- throw fail('PROJECT_VERSION_CONFLICT');
227
- await confirmWorkspaceOperator('SEAL_SOURCE',projectId,
228
- expectedProjectRevision,[sourceDb,epoch,backupPath,sealManifestPath]);
229
- value=await fenceLegacyProjectStore({sourceDb,projectId,
230
- expectedStoreEpoch:epoch,expectedProjectRevision,backupPath,sealManifestPath});
231
- }else if(command==='project'&&sub==='publish-managed'&&rest.length===6){
232
- const [projectId,sourceDb,epoch,revision,sealManifest,expectedSealHash]=rest;
233
- if(process.env.CHAT_LOOP_CONTEXT_ADMIN_ENABLE!=='1')throw fail('ADMIN_REQUIRED');
234
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
235
- if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
236
- const expectedProjectRevision=Number(revision);
237
- if(!Number.isSafeInteger(expectedProjectRevision)||expectedProjectRevision<1)
238
- throw fail('PROJECT_VERSION_CONFLICT');
239
- await confirmWorkspaceOperator('PUBLISH_MANAGED',projectId,
240
- expectedProjectRevision,[sourceDb,epoch,sealManifest,expectedSealHash]);
241
- const root=contextRoot();
242
- mkdirSync(root,{recursive:true,mode:0o700});
243
- value=await withWorkspaceRegistryLock(root,()=>createManagedProjectBranch({
244
- sourceDb,targetRoot:root,projectId,expectedStoreEpoch:epoch,
245
- expectedProjectRevision,sealManifest,expectedSealHash
246
- }));
247
- }else if(command==='project'&&sub==='stage-diagnostic'&&rest.length===4){
248
- const [projectId,sourceDb,expectedStoreEpoch,revision]=rest;
249
- if(process.env.CHAT_LOOP_CONTEXT_ADMIN_ENABLE!=='1')throw fail('ADMIN_REQUIRED');
250
- if(!allowedProjects().has(projectId))throw fail('PROJECT_ACCESS_DENIED');
251
- if(process.env.CHAT_LOOP_CONTEXT_DB)throw fail('EXPLICIT_DB_INIT_REQUIRED');
252
- const expectedProjectRevision=Number(revision);
253
- if(!Number.isSafeInteger(expectedProjectRevision)||expectedProjectRevision<1)
254
- throw fail('PROJECT_VERSION_CONFLICT');
255
- // This is an offline diagnostic extract; NEVER a source cutover.
256
- // The operator must review the exact source path and source CAS identity.
257
- await confirmWorkspaceOperator('STAGE_DIAGNOSTIC',projectId,
258
- expectedProjectRevision,[sourceDb,expectedStoreEpoch]);
259
- const root=contextRoot();
260
- mkdirSync(root,{recursive:true,mode:0o700});
261
- value=await withWorkspaceRegistryLock(root,()=>createProjectDiagnosticBranch({
262
- sourceDb,targetRoot:root,projectId,expectedStoreEpoch,expectedProjectRevision
263
- }));
264
- }else if(command==='doctor'&&sub==='--json'&&rest.length===0)
265
- value={status:'READY',packageVersion:CONTEXT_PACKAGE_VERSION,projectRoot:contextRoot()};
266
- else throw fail('UNKNOWN_COMMAND');
29
+ if(!node24){
30
+ const [command,sub,...rest]=args;
31
+ if(command==='methods'&&sub==='list'&&rest.length<=1)
32
+ value=await requestContext({operation:'sdk.methods.list',...(rest[0]==='--json'?{}:rest[0]?{group:rest[0]}:{})});
33
+ else if(command==='methods'&&sub==='groups'&&rest.length<=1)
34
+ value=await requestContext({operation:'sdk.methods.list',view:'groups',...(rest[0]?{group:rest[0]}:{})});
35
+ else if(command==='methods'&&sub==='describe'&&rest.length===1)
36
+ value=await requestContext({operation:'sdk.methods.describe',methodId:rest[0]});
37
+ else throw fail('UNKNOWN_COMMAND');
38
+ }else{
39
+ const {runLocalCliCommand}=await loadLocalOperator();
40
+ value=await runLocalCliCommand(args,readJson);
41
+ }
267
42
  output({ok:true,result:value});
268
43
  }catch(error){
269
- // Never expose arbitrary OS/SQLite exception messages, paths or user data.
44
+ // Never leak arbitrary filesystem, SQLite, or user data in CLI errors.
270
45
  const code=error.code||'CONTEXT_FAILED';
271
46
  output({ok:false,error:{code:/^[A-Z0-9_]+$/.test(code)?code:'CONTEXT_FAILED'}});
272
47
  process.exitCode=1;
@@ -0,0 +1,151 @@
1
+ // One self-contained Context capability contract. Registered at build time.
2
+ export const capability={
3
+ "id": "approval",
4
+ "version": 1,
5
+ "purpose": "Observe or revoke R/P decisions with actual user-turn evidence",
6
+ "startWith": "approval.observe",
7
+ "methods": [
8
+ {
9
+ "id": "approval.observe",
10
+ "group": "approval",
11
+ "mode": "write",
12
+ "description": "Record soft evidence of a real user decision on a displayed R/P version.",
13
+ "inputSchema": {
14
+ "type": "object",
15
+ "required": [
16
+ "operation",
17
+ "projectId",
18
+ "taskId",
19
+ "issueId",
20
+ "decision",
21
+ "sourceRole",
22
+ "userTurn",
23
+ "presentedAssistantRef",
24
+ "expectedTaskRevision",
25
+ "expectedStoreEpoch",
26
+ "writeRequestId"
27
+ ],
28
+ "additionalProperties": false,
29
+ "properties": {
30
+ "operation": {
31
+ "const": "approval.observe"
32
+ },
33
+ "projectId": {
34
+ "type": "string",
35
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
36
+ },
37
+ "taskId": {
38
+ "type": "string",
39
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
40
+ },
41
+ "issueId": {
42
+ "type": "string",
43
+ "minLength": 8,
44
+ "maxLength": 64
45
+ },
46
+ "decision": {
47
+ "enum": [
48
+ "APPROVE",
49
+ "REJECT",
50
+ "REQUEST_CHANGE",
51
+ "CUSTOM"
52
+ ]
53
+ },
54
+ "sourceRole": {
55
+ "const": "user"
56
+ },
57
+ "userTurn": {
58
+ "type": "string",
59
+ "minLength": 8,
60
+ "maxLength": 256
61
+ },
62
+ "presentedAssistantRef": {
63
+ "type": "string",
64
+ "minLength": 8,
65
+ "maxLength": 256
66
+ },
67
+ "expectedTaskRevision": {
68
+ "type": "integer",
69
+ "minimum": 1
70
+ },
71
+ "expectedStoreEpoch": {
72
+ "type": "string",
73
+ "minLength": 10,
74
+ "maxLength": 64
75
+ },
76
+ "writeRequestId": {
77
+ "type": "string",
78
+ "minLength": 8,
79
+ "maxLength": 128
80
+ }
81
+ }
82
+ },
83
+ "order": 27,
84
+ "route": {
85
+ "kind": "core",
86
+ "method": "observeApproval",
87
+ "params": [
88
+ "$args"
89
+ ]
90
+ }
91
+ },
92
+ {
93
+ "id": "approval.revoke",
94
+ "group": "approval",
95
+ "mode": "write",
96
+ "description": "Invalidate earlier approvals at the correct task revision.",
97
+ "inputSchema": {
98
+ "type": "object",
99
+ "required": [
100
+ "operation",
101
+ "projectId",
102
+ "taskId",
103
+ "expectedTaskRevision",
104
+ "expectedApprovalRevision",
105
+ "expectedStoreEpoch",
106
+ "writeRequestId"
107
+ ],
108
+ "additionalProperties": false,
109
+ "properties": {
110
+ "operation": {
111
+ "const": "approval.revoke"
112
+ },
113
+ "projectId": {
114
+ "type": "string",
115
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
116
+ },
117
+ "taskId": {
118
+ "type": "string",
119
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$"
120
+ },
121
+ "expectedTaskRevision": {
122
+ "type": "integer",
123
+ "minimum": 1
124
+ },
125
+ "expectedApprovalRevision": {
126
+ "type": "integer",
127
+ "minimum": 1
128
+ },
129
+ "expectedStoreEpoch": {
130
+ "type": "string",
131
+ "minLength": 10,
132
+ "maxLength": 64
133
+ },
134
+ "writeRequestId": {
135
+ "type": "string",
136
+ "minLength": 8,
137
+ "maxLength": 128
138
+ }
139
+ }
140
+ },
141
+ "order": 28,
142
+ "route": {
143
+ "kind": "core",
144
+ "method": "revokeApproval",
145
+ "params": [
146
+ "$args"
147
+ ]
148
+ }
149
+ }
150
+ ]
151
+ };