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