@tomflow/chatloop-context 0.1.5 → 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.
- 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/package.json
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Independent local Context SDK and short-lived CLI for Chat Loop projects",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=24"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"chatloop-context": "./bin/cli.mjs"
|
|
14
|
+
},
|
|
9
15
|
"exports": {
|
|
10
|
-
".": "./
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
".": "./index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.mjs",
|
|
20
|
+
"capabilities.generated.mjs",
|
|
21
|
+
"capabilities/",
|
|
22
|
+
"lib/",
|
|
23
|
+
"bin/",
|
|
24
|
+
"scripts/",
|
|
25
|
+
"README.md",
|
|
26
|
+
"docs/"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "node --test ./test/*.test.mjs",
|
|
30
|
+
"build:capabilities": "node ./scripts/build-capabilities.mjs",
|
|
31
|
+
"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"
|
|
18
34
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"ps-list": "9.0.0",
|
|
37
|
+
"@tomflow/chatloop-extension": "0.4.0"
|
|
38
|
+
}
|
|
21
39
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Deterministic, build-time Context capability composition.
|
|
2
|
+
// Source of truth: capabilities/<id>.mjs. Runtime never scans directories.
|
|
3
|
+
import {readdirSync,readFileSync,writeFileSync} from 'node:fs';
|
|
4
|
+
import {dirname,join,resolve} from 'node:path';
|
|
5
|
+
import {fileURLToPath,pathToFileURL} from 'node:url';
|
|
6
|
+
import {createHash} from 'node:crypto';
|
|
7
|
+
|
|
8
|
+
const ROOT=dirname(dirname(fileURLToPath(import.meta.url)));
|
|
9
|
+
const ID=/^[a-z][a-z0-9-]{0,63}$/;
|
|
10
|
+
const METHOD=/^[a-z][a-z0-9-]*\.[a-zA-Z0-9._-]+$/;
|
|
11
|
+
const ADAPTERS=new Set(['sdk.methods.list','sdk.methods.describe','project.resolve',
|
|
12
|
+
'project.list','project.open','task.open']);
|
|
13
|
+
const failure=code=>Object.assign(Error(code),{code});
|
|
14
|
+
const object=x=>x!==null&&typeof x==='object'&&!Array.isArray(x);
|
|
15
|
+
|
|
16
|
+
export async function compileCapabilities(sourceDir=join(ROOT,'capabilities')){
|
|
17
|
+
const files=readdirSync(sourceDir).filter(s=>s.endsWith('.mjs')).sort();
|
|
18
|
+
if(!files.length)throw failure('CAPABILITY_EMPTY');
|
|
19
|
+
const caps=[],seenIds=new Set(),seenMethods=new Set();
|
|
20
|
+
for(const name of files){
|
|
21
|
+
if(!/^[a-z][a-z0-9-]*\.mjs$/.test(name))throw failure('CAPABILITY_FILENAME_INVALID');
|
|
22
|
+
const path=resolve(sourceDir,name);
|
|
23
|
+
const fingerprint=createHash('sha256').update(readFileSync(path)).digest('hex');
|
|
24
|
+
const {capability:c}=await import(pathToFileURL(path).href+'?sha256='+fingerprint);
|
|
25
|
+
if(!object(c)||!ID.test(c.id)||name!==c.id+'.mjs'||seenIds.has(c.id)
|
|
26
|
+
||!Number.isSafeInteger(c.version)||c.version<1
|
|
27
|
+
||typeof c.purpose!=='string'||!c.purpose.length
|
|
28
|
+
||typeof c.startWith!=='string'||!Array.isArray(c.methods)||!c.methods.length)
|
|
29
|
+
throw failure('CAPABILITY_DECLARATION_INVALID');
|
|
30
|
+
seenIds.add(c.id);
|
|
31
|
+
for(const m of c.methods){
|
|
32
|
+
if(!object(m)||!METHOD.test(m.id)||m.group!==c.id
|
|
33
|
+
||!m.id.startsWith(c.id+'.')||seenMethods.has(m.id)
|
|
34
|
+
||(m.order!==undefined&&(!Number.isSafeInteger(m.order)||m.order<0))
|
|
35
|
+
||!['read','write'].includes(m.mode)||typeof m.description!=='string'
|
|
36
|
+
||!object(m.inputSchema)||m.inputSchema.type!=='object'
|
|
37
|
+
||m.inputSchema.additionalProperties!==false
|
|
38
|
+
||!Array.isArray(m.inputSchema.required)
|
|
39
|
+
||!m.inputSchema.required.includes('operation')
|
|
40
|
+
||!object(m.inputSchema.properties)
|
|
41
|
+
||m.inputSchema.properties.operation?.const!==m.id
|
|
42
|
+
||m.inputSchema.required.some(k=>!Object.hasOwn(m.inputSchema.properties,k))
|
|
43
|
+
||!object(m.route))throw failure('CAPABILITY_METHOD_INVALID');
|
|
44
|
+
seenMethods.add(m.id);
|
|
45
|
+
if(m.route.kind==='adapter'){
|
|
46
|
+
if(!ADAPTERS.has(m.id)||m.route.name!==m.id)
|
|
47
|
+
throw failure('CAPABILITY_ADAPTER_NOT_ALLOWED');
|
|
48
|
+
}else if(m.route.kind==='core'){
|
|
49
|
+
if(!/^[a-zA-Z][a-zA-Z0-9]*$/.test(m.route.method)
|
|
50
|
+
||!Array.isArray(m.route.params)
|
|
51
|
+
||m.route.params.some(p=>!(typeof p==='string'||
|
|
52
|
+
object(p)&&Object.keys(p).length===1&&object(p.$object))))
|
|
53
|
+
throw failure('CAPABILITY_CORE_ROUTE_INVALID');
|
|
54
|
+
}else if(m.route.kind==='module'){
|
|
55
|
+
// Unreviewed custom business writes must not bypass Core's CAS/receipt.
|
|
56
|
+
// A new writer must first acquire an explicitly reviewed receipt port.
|
|
57
|
+
if(m.mode!=='read'||!m.inputSchema.required.includes('projectId')
|
|
58
|
+
||typeof c.execute!=='function')
|
|
59
|
+
throw failure('CAPABILITY_CUSTOM_PERMISSION_INVALID');
|
|
60
|
+
}else throw failure('CAPABILITY_ROUTE_INVALID');
|
|
61
|
+
}
|
|
62
|
+
if(!c.methods.some(m=>m.id===c.startWith))
|
|
63
|
+
throw failure('CAPABILITY_START_METHOD_INVALID');
|
|
64
|
+
caps.push(c);
|
|
65
|
+
}
|
|
66
|
+
const flattened=caps.flatMap(c=>c.methods);
|
|
67
|
+
const explicitOrders=flattened.filter(m=>m.order!==undefined).map(m=>m.order);
|
|
68
|
+
if(new Set(explicitOrders).size!==explicitOrders.length)
|
|
69
|
+
throw failure('CAPABILITY_METHOD_ORDER_DUPLICATE');
|
|
70
|
+
// Existing APIs retain their published presentation order. New capability
|
|
71
|
+
// methods need no global position: the compiler deterministically appends
|
|
72
|
+
// them by ID, so adding a group never edits another group's declarations.
|
|
73
|
+
let nextOrder=Math.max(-1,...explicitOrders)+1;
|
|
74
|
+
const assigned=new Map(flattened.filter(m=>m.order===undefined)
|
|
75
|
+
.sort((a,b)=>a.id.localeCompare(b.id))
|
|
76
|
+
.map(m=>[m.id,nextOrder++]));
|
|
77
|
+
const methods=flattened.map(m=>{
|
|
78
|
+
const {id,group,mode,description,inputSchema,route,lifecycle}=m;
|
|
79
|
+
return {id,group,mode,description,inputSchema,route,
|
|
80
|
+
order:m.order??assigned.get(id),...(lifecycle?{lifecycle}:{})};
|
|
81
|
+
}).sort((a,b)=>a.order-b.order);
|
|
82
|
+
const groups=caps.map(c=>({
|
|
83
|
+
id:c.id,purpose:c.purpose,startWith:c.startWith,
|
|
84
|
+
order:Math.min(...methods.filter(m=>m.group===c.id).map(m=>m.order))
|
|
85
|
+
})).sort((a,b)=>a.order-b.order);
|
|
86
|
+
const json=JSON.stringify({groups,methods},null,2)+'\n';
|
|
87
|
+
const imports=files.map((file,i)=>
|
|
88
|
+
"import {capability as c"+i+"} from './capabilities/"+file+"';").join('\n');
|
|
89
|
+
const js='// GENERATED from capabilities/*.mjs. Do not edit.\n'+
|
|
90
|
+
imports+'\nexport const capabilities=Object.freeze(['+
|
|
91
|
+
files.map((_,i)=>'c'+i).join(',')+']);\n';
|
|
92
|
+
return {json,js,groups,methods};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function main(){
|
|
96
|
+
const {json,js,methods}=await compileCapabilities();
|
|
97
|
+
const targets=[
|
|
98
|
+
[join(ROOT,'lib/capability-catalog.generated.json'),json],
|
|
99
|
+
[join(ROOT,'capabilities.generated.mjs'),js]
|
|
100
|
+
];
|
|
101
|
+
if(process.argv.includes('--check')){
|
|
102
|
+
for(const [file,expected] of targets){
|
|
103
|
+
let actual;try{actual=readFileSync(file,'utf8')}catch{}
|
|
104
|
+
if(actual!==expected)throw failure('CAPABILITY_BUILD_STALE:'+file);
|
|
105
|
+
}
|
|
106
|
+
if(process.env.npm_lifecycle_event!=='prepack')
|
|
107
|
+
console.log('CAPABILITIES_CURRENT '+methods.length);
|
|
108
|
+
}else{
|
|
109
|
+
for(const [file,value] of targets)writeFileSync(file,value);
|
|
110
|
+
console.log('CAPABILITIES_BUILT '+methods.length);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if(process.argv[1]&&resolve(process.argv[1])===fileURLToPath(import.meta.url))
|
|
114
|
+
await main();
|