@yaks/code 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +106 -2
- package/_dist/anatomy.d.ts +144 -0
- package/_dist/anatomy.d.ts.map +1 -0
- package/_dist/described.d.ts +31 -0
- package/_dist/described.d.ts.map +1 -0
- package/_dist/effects.d.ts +9 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/frames.d.ts +16 -0
- package/_dist/frames.d.ts.map +1 -0
- package/_dist/mod.d.ts +26 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/read.d.ts +89 -0
- package/_dist/read.d.ts.map +1 -0
- package/_dist/source.d.ts +55 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/sync.d.ts +39 -0
- package/_dist/sync.d.ts.map +1 -0
- package/_dist/tools.d.ts +8 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/anatomy.js +552 -0
- package/anatomy.js.map +1 -0
- package/anatomy.ts +638 -0
- package/deno.json +1 -0
- package/described.js +274 -0
- package/described.js.map +1 -0
- package/described.ts +314 -0
- package/effects.js +24 -0
- package/effects.js.map +1 -0
- package/effects.ts +30 -0
- package/frames.js +46 -0
- package/frames.js.map +1 -0
- package/frames.ts +54 -0
- package/mod.js +26 -0
- package/mod.js.map +1 -0
- package/mod.ts +27 -0
- package/package.json +54 -4
- package/read.js +178 -0
- package/read.js.map +1 -0
- package/read.ts +249 -0
- package/source.js +238 -0
- package/source.js.map +1 -0
- package/source.ts +263 -0
- package/sync.js +345 -0
- package/sync.js.map +1 -0
- package/sync.ts +323 -0
- package/tools.js +49 -0
- package/tools.js.map +1 -0
- package/tools.ts +59 -0
- package/vocab.js +21 -0
- package/vocab.js.map +1 -0
- package/vocab.json +143 -0
- package/vocab.ts +22 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Catalog } from "./frames.js";
|
|
2
|
+
export type Location = {
|
|
3
|
+
file: string;
|
|
4
|
+
function?: string;
|
|
5
|
+
line?: number;
|
|
6
|
+
};
|
|
7
|
+
export type Sources = {
|
|
8
|
+
roots: string[];
|
|
9
|
+
origins?: string[];
|
|
10
|
+
};
|
|
11
|
+
export type SourceOptions = {
|
|
12
|
+
cwd: string;
|
|
13
|
+
url: string;
|
|
14
|
+
origins?: string[];
|
|
15
|
+
workspace?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Frames thrown at a commit, each told whether it is the application's and,
|
|
18
|
+
* where the catalog matches that commit, its module and symbol. */ export type Resolver = <T extends Location>(frames: T[], commit: string) => Promise<(T & {
|
|
19
|
+
app: boolean;
|
|
20
|
+
module?: string;
|
|
21
|
+
symbol?: string;
|
|
22
|
+
})[]>;
|
|
23
|
+
export declare let sourcePath: (file: string, sources: Sources) => string | undefined;
|
|
24
|
+
/** Read only requested global identities from the fleet's existing HTTP door. */ export declare let catalogAt: (url: string, send?: typeof fetch) => Catalog;
|
|
25
|
+
/** How often a frame under no known checkout reads the worktrees again (ms). */ export declare let ROOTS: number;
|
|
26
|
+
/** A catalog whose answers are kept for `ms`: frames thrown at one commit ask
|
|
27
|
+
* after the same files and exports again and again, and the catalog changes
|
|
28
|
+
* only as the code syncs. Callers asking at once share one request; a failed
|
|
29
|
+
* request is not kept.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { equal } from '@yaks/testing'
|
|
33
|
+
* import { remembered } from '@yaks/code/source'
|
|
34
|
+
*
|
|
35
|
+
* let asked: string[][] = []
|
|
36
|
+
* let catalog = remembered({
|
|
37
|
+
* get: (ids) => (asked.push(ids), Promise.resolve([{ entity: { eid: 'f' } }])),
|
|
38
|
+
* })
|
|
39
|
+
* await Promise.all([catalog.get(['f', 'g']), catalog.get(['f'])])
|
|
40
|
+
* equal(asked, [['f', 'g']])
|
|
41
|
+
* ```
|
|
42
|
+
*/ export declare let remembered: (catalog: Catalog, ms?: number) => Catalog;
|
|
43
|
+
/** A resolver for frames thrown at a commit. What it reads Git for is kept for
|
|
44
|
+
* the life of the resolver, so a run costs no process: the checkout and its
|
|
45
|
+
* repository never move, and a commit's tree never changes. Linked worktrees
|
|
46
|
+
* come and go, so a file frame under none of the roots known reads them again,
|
|
47
|
+
* at most once every {@link ROOTS} ms. The catalog it asks by default is
|
|
48
|
+
* {@link remembered}. */ export declare let sourceFrames: (options: SourceOptions, catalog?: Catalog) => Resolver;
|
|
49
|
+
/** The uniquely placed repository at the catalog, or no attribution while
|
|
50
|
+
* placement is unknown, ambiguous or the catalog is unavailable. Unqualified
|
|
51
|
+
* historical observations do not hide a qualified repository. */ export declare let catalogRepository: (url: string, common: string, send?: typeof fetch) => Promise<string | undefined>;
|
|
52
|
+
/** Frame attribution shares one repository lookup across concurrent errors.
|
|
53
|
+
* Recheck placement after a minute, including absent/ambiguous results: optional
|
|
54
|
+
* enrichment cannot flood the serving graph while an error spool drains. */ export declare let repositoryCatalog: (url: string, send?: typeof fetch) => (common: string) => Promise<string | undefined>;
|
|
55
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sources":["../source.ts"],"names":[],"mappings":"AAOA,SAAS,KAAK,OAAO,sBAAoC;AAEzD,YAAY;EAAa,MAAM,MAAM;EAAE,WAAW,MAAM;EAAE,OAAO,MAAM;;AACvE,YAAY;EAAY,OAAO,MAAM;EAAI,UAAU,MAAM;;AACzD,YAAY;EACV,KAAK,MAAM;EACX,KAAK,MAAM;EACX,UAAU,MAAM;EAChB,YAAY,MAAM;;AAEpB;iEACiE,GACjE,YAAY,YAAY,UAAU,UAChC,QAAQ,KACR,QAAQ,MAAM,KACX,SAAS;EAAM,KAAK,OAAO;EAAE,SAAS,MAAM;EAAE,SAAS,MAAM;;AAKlE,OAAO,YAAI,aACT,MAAM,MAAM,EACZ,SAAS,YACR,MAAM,GAAG,SAAS,CA0BpB;AAED,+EAA+E,GAC/E,OAAO,YAAI,YAAa,KAAK,MAAM,EAAE,cAAa,UAAgB,QA2BhE;AAmBF,8EAA8E,GAC9E,OAAO,YAAI,cAAa;AAExB;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,YAAI,aAAc,SAAS,SAAS,gBAAc,QAgCxD;AAED;;;;;uBAKuB,GACvB,OAAO,YAAI,eACT,SAAS,eACT,UAAS,YACR,SAsCF;AAKD;;+DAE+D,GAC/D,OAAO,YAAI,oBACT,KAAK,MAAM,EACX,QAAQ,MAAM,EACd,cAAa,UACZ,QAAQ,MAAM,GAAG,SAAS,EAuB5B;AAED;;0EAE0E,GAC1E,OAAO,YAAI,oBACT,KAAK,MAAM,EACX,cAAa,WAEX,QAAQ,MAAM,KAAK,QAAQ,MAAM,GAAG,SAAS,EAYhD"}
|
package/_dist/sync.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Graph } from "@yaks/graph";
|
|
2
|
+
import type { Actor } from "@yaks/graph";
|
|
3
|
+
import type { Binding } from "@yaks/mirror";
|
|
4
|
+
import { type DocNode } from "./read.js";
|
|
5
|
+
/** The checkout `cwd` is in: its root, and its repository's common Git
|
|
6
|
+
* directory, both canonical. */ export declare let checkout: (cwd: string) => Promise<{
|
|
7
|
+
root: string;
|
|
8
|
+
common: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** Which tracked files are code: TS/JS modules, markdown, package manifests
|
|
11
|
+
* and vocabularies, outside any `vendor` directory. */ export declare let covered: (path: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The exports of many modules at once. `deno doc` refuses a whole batch when
|
|
14
|
+
* one module in it cannot be resolved, so a refused module is set aside —
|
|
15
|
+
* named in `refused`, read for everything but its exports — and the rest are
|
|
16
|
+
* asked again.
|
|
17
|
+
*/ export declare let exported: (root: string, paths: string[]) => Promise<{
|
|
18
|
+
nodes: Record<string, DocNode>;
|
|
19
|
+
refused: string[];
|
|
20
|
+
}>;
|
|
21
|
+
/** What a sync of one checkout did, beyond what the mirror reports. */ export type Read = {
|
|
22
|
+
modules: number;
|
|
23
|
+
symbols: number;
|
|
24
|
+
imports: number;
|
|
25
|
+
packages: number;
|
|
26
|
+
refused: string[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The binding for one checkout. `full` forgets what was read, so every file
|
|
30
|
+
* is read again; `read` accumulates what the reads found into `said`.
|
|
31
|
+
*/ export declare let codeMirror: (g: Graph, cwd: string, opts?: {
|
|
32
|
+
full?: boolean;
|
|
33
|
+
actor?: Actor | null;
|
|
34
|
+
}) => Promise<{
|
|
35
|
+
binding: Binding;
|
|
36
|
+
said: Read;
|
|
37
|
+
root: string;
|
|
38
|
+
}>;
|
|
39
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sources":["../sync.ts"],"names":[],"mappings":"AAoBA,cAAiC,KAAK,2BAAgC;AAItE,cAAc,KAAK,2BAAgC;AAGnD,cAAc,OAAO,4BAAiC;AAEtD,SACE,KAAK,OAAO,oBAYI;AAmBlB;8BAC8B,GAC9B,OAAO,YAAI,WACT,KAAK,MAAM,KACV;EAAU,MAAM,MAAM;EAAE,QAAQ,MAAM;GAQxC;AAED;qDACqD,GACrD,OAAO,YAAI,UAAW,MAAM,MAAM,KAAG,OAAO,CAGO;AAEnD;;;;;CAKC,GACD,OAAO,YAAI,WACT,MAAM,MAAM,EACZ,OAAO,MAAM,OACZ;EAAU,OAAO,OAAO,MAAM,EAAE;EAAU,SAAS,MAAM;GAyB3D;AAED,qEAAqE,GACrE,YAAY;EACV,SAAS,MAAM;EACf,SAAS,MAAM;EACf,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,SAAS,MAAM;;AAMjB;;;CAGC,GACD,OAAO,YAAI,aACT,GAAG,OACH,KAAK,MAAM,EACX;EAAQ,OAAO,OAAO;EAAE,QAAQ,QAAQ,IAAI;MAC3C;EAAU,SAAS;EAAS,MAAM;EAAM,MAAM,MAAM;GAwLtD"}
|
package/_dist/tools.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Actor, Graph } from "@yaks/graph";
|
|
2
|
+
import type { Runs } from "@yaks/graph/tools";
|
|
3
|
+
/** Sync the checkout at `cwd` into `g`, and say what it did in one line. */ export declare let codeSync: (g: Graph, cwd: string | undefined, opts?: {
|
|
4
|
+
full?: boolean;
|
|
5
|
+
actor?: Actor | null;
|
|
6
|
+
}) => Promise<string>;
|
|
7
|
+
/** The implementations of the tools ./vocab.json declares. */ export declare let runs: () => Runs;
|
|
8
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAQA,cAAc,KAAK,EAAgB,KAAK,2BAAgC;AAExE,cAAc,IAAI,iCAAsC;AAKxD,0EAA0E,GAC1E,OAAO,YAAI,WACT,GAAG,OACH,KAAK,MAAM,GAAG,SAAS,EACvB;EAAQ,OAAO,OAAO;EAAE,QAAQ,QAAQ,IAAI;MAC3C,QAAQ,MAAM,EAuBhB;AAED,4DAA4D,GAC5D,OAAO,YAAI,YAAW,KAYpB"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
/** `package`, `module`, `symbol`, the `imports` relation and `code sync`. */ export declare let codeDoc: VocabDoc;
|
|
3
|
+
/** What this package is: its manifest's description, the one place it is
|
|
4
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
5
|
+
/** Every document this plugin declares. */ export declare let docs: VocabDoc[];
|
|
6
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AASA,cAAc,QAAQ,2BAAgC;AAItD,2EAA2E,GAC3E,OAAO,YAAI,SAAS,SAAc;AAElC;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAsB"}
|
package/anatomy.js
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
/** Value-free composition metadata shared by native hosts, workers and pages. */ /** A declaration is not evidence that its implementation was imported or bound. */ /** IDs depend on provenance and registration identity, never on loading state. */ export let anatomyId = (group, owner = '', name = '', key = '')=>[
|
|
2
|
+
group,
|
|
3
|
+
owner,
|
|
4
|
+
name,
|
|
5
|
+
key
|
|
6
|
+
].map(encodeURIComponent).join(':');
|
|
7
|
+
// JSON metadata may include authored defaults. Accessors, class instances and
|
|
8
|
+
// executable values are not metadata: in particular, reading an accessor must
|
|
9
|
+
// never become an accidental vault read while preparing a page's snapshot.
|
|
10
|
+
let json = (value, seen = new Set())=>{
|
|
11
|
+
if (value === null || typeof value == 'string' || typeof value == 'boolean') {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
if (typeof value == 'number') {
|
|
15
|
+
return Number.isFinite(value) ? value : undefined;
|
|
16
|
+
}
|
|
17
|
+
if (!value || typeof value != 'object' || seen.has(value)) return undefined;
|
|
18
|
+
let proto = Object.getPrototypeOf(value);
|
|
19
|
+
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
seen.add(value);
|
|
23
|
+
let out = {};
|
|
24
|
+
for (let key of Object.keys(value)){
|
|
25
|
+
let d = Object.getOwnPropertyDescriptor(value, key);
|
|
26
|
+
if (!d || !('value' in d)) continue;
|
|
27
|
+
let kept = json(d.value, seen);
|
|
28
|
+
if (kept === undefined) continue;
|
|
29
|
+
// Assigned, which keeps the copy a fast object. A key named `__proto__`
|
|
30
|
+
// is defined instead: where a runtime keeps that accessor (a browser,
|
|
31
|
+
// workerd), assigning it would set the copy's prototype.
|
|
32
|
+
if (key == '__proto__') {
|
|
33
|
+
Object.defineProperty(out, key, {
|
|
34
|
+
value: kept,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
configurable: true
|
|
38
|
+
});
|
|
39
|
+
} else out[key] = kept;
|
|
40
|
+
}
|
|
41
|
+
seen.delete(value);
|
|
42
|
+
return Array.isArray(value) ? Array.from({
|
|
43
|
+
length: value.length
|
|
44
|
+
}, (_, i)=>out[String(i)] ?? null) : out;
|
|
45
|
+
};
|
|
46
|
+
/** Clone schema/declaration data without invoking getters or keeping functions. */ export let anatomyData = (value)=>{
|
|
47
|
+
let kept = json(value);
|
|
48
|
+
return kept && typeof kept == 'object' && !Array.isArray(kept) ? kept : {};
|
|
49
|
+
};
|
|
50
|
+
let GROUPS = [
|
|
51
|
+
'packages',
|
|
52
|
+
'roles',
|
|
53
|
+
'facets',
|
|
54
|
+
'comps',
|
|
55
|
+
'tools',
|
|
56
|
+
'commands',
|
|
57
|
+
'effects',
|
|
58
|
+
'rules',
|
|
59
|
+
'hooks',
|
|
60
|
+
'routes',
|
|
61
|
+
'views',
|
|
62
|
+
'inspectViews',
|
|
63
|
+
'tui',
|
|
64
|
+
'kits',
|
|
65
|
+
'themes',
|
|
66
|
+
'skills',
|
|
67
|
+
'secrets'
|
|
68
|
+
];
|
|
69
|
+
let TEXT = [
|
|
70
|
+
'name',
|
|
71
|
+
'package',
|
|
72
|
+
'facet',
|
|
73
|
+
'description'
|
|
74
|
+
];
|
|
75
|
+
let value = (source, key)=>{
|
|
76
|
+
if (!source || typeof source != 'object') return undefined;
|
|
77
|
+
let d = Object.getOwnPropertyDescriptor(source, key);
|
|
78
|
+
return d && 'value' in d ? d.value : undefined;
|
|
79
|
+
};
|
|
80
|
+
let text = (source, key)=>{
|
|
81
|
+
let kept = value(source, key);
|
|
82
|
+
return typeof kept == 'string' ? kept : undefined;
|
|
83
|
+
};
|
|
84
|
+
let strings = (source)=>{
|
|
85
|
+
let kept = json(source);
|
|
86
|
+
return Array.isArray(kept) ? kept.filter((s)=>typeof s == 'string') : [];
|
|
87
|
+
};
|
|
88
|
+
// Even an adapter's seed is an allowlist boundary. Do not read through a
|
|
89
|
+
// caller's accessors, including its name, flags, group arrays or host label.
|
|
90
|
+
let part = (group, seed)=>{
|
|
91
|
+
let name = text(seed, 'name');
|
|
92
|
+
if (name === undefined) return undefined;
|
|
93
|
+
let out = {
|
|
94
|
+
id: anatomyId(group, text(seed, 'package'), name, text(seed, 'key')),
|
|
95
|
+
name,
|
|
96
|
+
declared: value(seed, 'declared') === true,
|
|
97
|
+
loaded: value(seed, 'loaded') === true,
|
|
98
|
+
bound: value(seed, 'bound') === true
|
|
99
|
+
};
|
|
100
|
+
for (let key of TEXT){
|
|
101
|
+
if (group == 'secrets' && key == 'description') continue;
|
|
102
|
+
let kept = text(seed, key);
|
|
103
|
+
if (kept !== undefined) out[key] = kept;
|
|
104
|
+
}
|
|
105
|
+
let fields = {
|
|
106
|
+
packages: [
|
|
107
|
+
'configured'
|
|
108
|
+
],
|
|
109
|
+
roles: [
|
|
110
|
+
'facets'
|
|
111
|
+
],
|
|
112
|
+
facets: [
|
|
113
|
+
'selected',
|
|
114
|
+
'attempted'
|
|
115
|
+
],
|
|
116
|
+
comps: [
|
|
117
|
+
'schema',
|
|
118
|
+
'props',
|
|
119
|
+
'extends',
|
|
120
|
+
'refs',
|
|
121
|
+
'before',
|
|
122
|
+
'rules',
|
|
123
|
+
'indexes',
|
|
124
|
+
'identity',
|
|
125
|
+
'assocs'
|
|
126
|
+
],
|
|
127
|
+
tools: [
|
|
128
|
+
'inputSchema',
|
|
129
|
+
'outputSchema',
|
|
130
|
+
'tier',
|
|
131
|
+
'hints'
|
|
132
|
+
],
|
|
133
|
+
commands: [
|
|
134
|
+
'schema',
|
|
135
|
+
'usage'
|
|
136
|
+
],
|
|
137
|
+
effects: [
|
|
138
|
+
'handler',
|
|
139
|
+
'noop',
|
|
140
|
+
'triggers',
|
|
141
|
+
'registration'
|
|
142
|
+
],
|
|
143
|
+
rules: [
|
|
144
|
+
'hooks',
|
|
145
|
+
'kind',
|
|
146
|
+
'match',
|
|
147
|
+
'phase',
|
|
148
|
+
'before',
|
|
149
|
+
'optimistic',
|
|
150
|
+
'requests',
|
|
151
|
+
'resources',
|
|
152
|
+
'capabilities'
|
|
153
|
+
],
|
|
154
|
+
routes: [
|
|
155
|
+
'method',
|
|
156
|
+
'path'
|
|
157
|
+
],
|
|
158
|
+
skills: [
|
|
159
|
+
'path'
|
|
160
|
+
]
|
|
161
|
+
};
|
|
162
|
+
for (let key of fields[group] ?? []){
|
|
163
|
+
let kept = json(value(seed, key));
|
|
164
|
+
if (kept !== undefined) out[key] = kept;
|
|
165
|
+
}
|
|
166
|
+
if (group == 'packages') out.configured = out.configured === true;
|
|
167
|
+
if (group == 'roles') out.facets = strings(out.facets);
|
|
168
|
+
if (group == 'facets') {
|
|
169
|
+
out.selected = out.selected === true;
|
|
170
|
+
out.attempted = out.attempted === true;
|
|
171
|
+
}
|
|
172
|
+
if (group == 'comps') {
|
|
173
|
+
out.schema = anatomyData(out.schema);
|
|
174
|
+
out.rules = anatomyData(out.rules);
|
|
175
|
+
out.extends = out.extends === true;
|
|
176
|
+
out.before = strings(out.before);
|
|
177
|
+
out.refs = strings(out.refs);
|
|
178
|
+
out.props = (Array.isArray(out.props) ? out.props : []).flatMap((p)=>{
|
|
179
|
+
let name = text(p, 'name');
|
|
180
|
+
return name === undefined ? [] : [
|
|
181
|
+
{
|
|
182
|
+
name,
|
|
183
|
+
schema: anatomyData(value(p, 'schema')),
|
|
184
|
+
refs: strings(value(p, 'refs')),
|
|
185
|
+
...value(p, 'rules') ? {
|
|
186
|
+
rules: anatomyData(value(p, 'rules'))
|
|
187
|
+
} : {}
|
|
188
|
+
}
|
|
189
|
+
];
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (group == 'tools') {
|
|
193
|
+
out.inputSchema = anatomyData(out.inputSchema);
|
|
194
|
+
if (out.outputSchema !== undefined) {
|
|
195
|
+
out.outputSchema = anatomyData(out.outputSchema);
|
|
196
|
+
}
|
|
197
|
+
if (out.hints !== undefined) out.hints = anatomyData(out.hints);
|
|
198
|
+
if (typeof out.tier != 'string') delete out.tier;
|
|
199
|
+
}
|
|
200
|
+
if (group == 'commands') {
|
|
201
|
+
if (out.schema !== undefined) out.schema = anatomyData(out.schema);
|
|
202
|
+
if (typeof out.usage != 'string') delete out.usage;
|
|
203
|
+
}
|
|
204
|
+
if (group == 'effects') {
|
|
205
|
+
out.noop = out.noop === true;
|
|
206
|
+
if (typeof out.handler != 'string') delete out.handler;
|
|
207
|
+
if (out.triggers !== undefined) out.triggers = anatomyData(out.triggers);
|
|
208
|
+
if (out.registration !== undefined) {
|
|
209
|
+
out.registration = out.registration === true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (group == 'rules') {
|
|
213
|
+
out.hooks = strings(out.hooks);
|
|
214
|
+
if (typeof out.kind != 'string' || ![
|
|
215
|
+
'plugin',
|
|
216
|
+
'code',
|
|
217
|
+
'data'
|
|
218
|
+
].includes(out.kind)) delete out.kind;
|
|
219
|
+
for (let k of [
|
|
220
|
+
'match',
|
|
221
|
+
'phase'
|
|
222
|
+
]){
|
|
223
|
+
if (typeof out[k] != 'string') delete out[k];
|
|
224
|
+
}
|
|
225
|
+
for (let k of [
|
|
226
|
+
'before',
|
|
227
|
+
'requests',
|
|
228
|
+
'resources',
|
|
229
|
+
'capabilities'
|
|
230
|
+
]){
|
|
231
|
+
if (out[k] !== undefined) out[k] = strings(out[k]);
|
|
232
|
+
}
|
|
233
|
+
if (out.optimistic !== undefined) out.optimistic = out.optimistic === true;
|
|
234
|
+
}
|
|
235
|
+
if (group == 'skills' && typeof out.path != 'string') delete out.path;
|
|
236
|
+
if (group == 'routes') {
|
|
237
|
+
out.method = typeof out.method == 'string' ? out.method : '';
|
|
238
|
+
out.path = typeof out.path == 'string' ? out.path : '';
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
};
|
|
242
|
+
/** The same value-free DTO and relationship mapper for every host adapter. */ export let anatomy = (source)=>{
|
|
243
|
+
let scope = text(source, 'scope');
|
|
244
|
+
let observed = value(source, 'observed');
|
|
245
|
+
let out = {
|
|
246
|
+
version: 1,
|
|
247
|
+
host: text(source, 'host') ?? '',
|
|
248
|
+
scope: scope == 'native' || scope == 'worker' ? scope : 'static',
|
|
249
|
+
observed: Object.fromEntries(GROUPS.map((g)=>[
|
|
250
|
+
g,
|
|
251
|
+
value(observed, g) === true
|
|
252
|
+
])),
|
|
253
|
+
edges: []
|
|
254
|
+
};
|
|
255
|
+
for (let group of GROUPS){
|
|
256
|
+
let seeds = value(source, group);
|
|
257
|
+
let made = new Map();
|
|
258
|
+
// Array accessors are no more trustworthy than object accessors.
|
|
259
|
+
if (Array.isArray(seeds)) {
|
|
260
|
+
for (let d of Object.values(Object.getOwnPropertyDescriptors(seeds))){
|
|
261
|
+
if (!d.enumerable || !('value' in d)) continue;
|
|
262
|
+
let p = part(group, d.value);
|
|
263
|
+
if (p) made.set(p.id, p);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
Object.assign(out, {
|
|
267
|
+
[group]: [
|
|
268
|
+
...made.values()
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
let packages = new Map(out.packages.map((p)=>[
|
|
273
|
+
p.name,
|
|
274
|
+
p.id
|
|
275
|
+
]));
|
|
276
|
+
let facets = new Map(out.facets.map((p)=>[
|
|
277
|
+
`${p.package}/${p.name}`,
|
|
278
|
+
p.id
|
|
279
|
+
]));
|
|
280
|
+
let comps = new Map(out.comps.filter((c)=>!c.extends).map((c)=>[
|
|
281
|
+
c.name,
|
|
282
|
+
c.id
|
|
283
|
+
]));
|
|
284
|
+
let edges = new Map();
|
|
285
|
+
let link = (from, to, kind)=>{
|
|
286
|
+
if (!from || !to || from == to) return;
|
|
287
|
+
let id = anatomyId('edges', from, to, kind);
|
|
288
|
+
edges.set(id, {
|
|
289
|
+
id,
|
|
290
|
+
from,
|
|
291
|
+
to,
|
|
292
|
+
kind
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
for (let group of GROUPS.filter((g)=>g != 'packages' && g != 'roles')){
|
|
296
|
+
for (let p of out[group]){
|
|
297
|
+
link(packages.get(p.package ?? ''), p.id, 'contributes');
|
|
298
|
+
link(facets.get(`${p.package}/${p.facet}`), p.id, 'provides');
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
for (let r of out.roles){
|
|
302
|
+
for (let f of out.facets){
|
|
303
|
+
if (f.selected && r.facets.includes(f.name) && (!r.package || r.package == f.package)) {
|
|
304
|
+
link(r.id, f.id, 'selects');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
for (let c of out.comps){
|
|
309
|
+
if (c.extends) link(c.id, comps.get(c.name), 'extends');
|
|
310
|
+
for (let before of c.before)link(c.id, comps.get(before), 'before');
|
|
311
|
+
for (let p of c.props){
|
|
312
|
+
for (let ref of p.refs)link(c.id, comps.get(ref), `ref:${p.name}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
for (let t of out.tools.filter((t)=>t.bound)){
|
|
316
|
+
link(facets.get(`${t.package}/tools`), t.id, 'binds');
|
|
317
|
+
}
|
|
318
|
+
for (let e of out.effects){
|
|
319
|
+
if (e.handler) link(facets.get(`${e.handler}/effects`), e.id, 'handles');
|
|
320
|
+
}
|
|
321
|
+
out.edges = [
|
|
322
|
+
...edges.values()
|
|
323
|
+
];
|
|
324
|
+
return out;
|
|
325
|
+
};
|
|
326
|
+
let entries = (source)=>{
|
|
327
|
+
if (!source || typeof source != 'object') return [];
|
|
328
|
+
return Object.entries(Object.getOwnPropertyDescriptors(source)).flatMap(([k, d])=>d.enumerable && 'value' in d ? [
|
|
329
|
+
[
|
|
330
|
+
k,
|
|
331
|
+
d.value
|
|
332
|
+
]
|
|
333
|
+
] : []);
|
|
334
|
+
};
|
|
335
|
+
let array = (source)=>Array.isArray(source) ? entries(source).map(([, v])=>v) : [];
|
|
336
|
+
let picked = (source, keys)=>Object.fromEntries(keys.flatMap((k)=>{
|
|
337
|
+
let kept = json(value(source, k));
|
|
338
|
+
return kept === undefined ? [] : [
|
|
339
|
+
[
|
|
340
|
+
k,
|
|
341
|
+
kept
|
|
342
|
+
]
|
|
343
|
+
];
|
|
344
|
+
}));
|
|
345
|
+
/** Project authored documents, keeping additive declarations with their owner. */ export let anatomyDocuments = (documents)=>{
|
|
346
|
+
let comps = [];
|
|
347
|
+
let tools = [];
|
|
348
|
+
let effects = [];
|
|
349
|
+
let rules = [];
|
|
350
|
+
array(documents).forEach((doc, ordinal)=>{
|
|
351
|
+
let owner = text(doc, 'label');
|
|
352
|
+
let docKey = `${text(doc, '$id') ?? text(doc, 'title') ?? ''}:${ordinal}`;
|
|
353
|
+
for (let [name, def] of entries(value(doc, '$defs'))){
|
|
354
|
+
let description = text(def, 'description');
|
|
355
|
+
let part = {
|
|
356
|
+
name,
|
|
357
|
+
package: owner,
|
|
358
|
+
facet: 'vocab',
|
|
359
|
+
declared: true,
|
|
360
|
+
loaded: true,
|
|
361
|
+
...description === undefined ? {} : {
|
|
362
|
+
description
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
if (value(def, 'component') === true) {
|
|
366
|
+
let props = entries(value(def, 'properties')).map(([name, schema])=>{
|
|
367
|
+
let ref = text(schema, 'ref');
|
|
368
|
+
return {
|
|
369
|
+
name,
|
|
370
|
+
schema: anatomyData(schema),
|
|
371
|
+
refs: ref ? [
|
|
372
|
+
ref
|
|
373
|
+
] : []
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
comps.push({
|
|
377
|
+
...part,
|
|
378
|
+
key: docKey,
|
|
379
|
+
schema: anatomyData(def),
|
|
380
|
+
props,
|
|
381
|
+
extends: value(def, 'extends') === true,
|
|
382
|
+
before: strings(value(def, 'before')),
|
|
383
|
+
refs: [
|
|
384
|
+
...new Set(props.flatMap((p)=>p.refs))
|
|
385
|
+
],
|
|
386
|
+
rules: picked(def, [
|
|
387
|
+
'wire',
|
|
388
|
+
'computed',
|
|
389
|
+
'embed',
|
|
390
|
+
'journal',
|
|
391
|
+
'kind',
|
|
392
|
+
'mark',
|
|
393
|
+
'sync',
|
|
394
|
+
'durable',
|
|
395
|
+
'pace',
|
|
396
|
+
'search',
|
|
397
|
+
'status',
|
|
398
|
+
'required',
|
|
399
|
+
'identity',
|
|
400
|
+
'unique',
|
|
401
|
+
'index'
|
|
402
|
+
])
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (value(def, 'tool') === true) {
|
|
406
|
+
let inputSchema = {
|
|
407
|
+
type: 'object',
|
|
408
|
+
additionalProperties: false,
|
|
409
|
+
properties: anatomyData(value(def, 'input'))
|
|
410
|
+
};
|
|
411
|
+
let required = strings(value(def, 'required'));
|
|
412
|
+
if (required.length) inputSchema.required = required;
|
|
413
|
+
let outputSchema = value(def, 'outputSchema');
|
|
414
|
+
tools.push({
|
|
415
|
+
...part,
|
|
416
|
+
loaded: false,
|
|
417
|
+
inputSchema,
|
|
418
|
+
...outputSchema ? {
|
|
419
|
+
outputSchema: anatomyData(outputSchema)
|
|
420
|
+
} : {},
|
|
421
|
+
hints: picked(def, [
|
|
422
|
+
'title',
|
|
423
|
+
'options',
|
|
424
|
+
'readOnly',
|
|
425
|
+
'destructive',
|
|
426
|
+
'idempotent',
|
|
427
|
+
'openWorld',
|
|
428
|
+
'surfaces',
|
|
429
|
+
'roles'
|
|
430
|
+
])
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
if (value(def, 'effect') === true) {
|
|
434
|
+
effects.push({
|
|
435
|
+
...part,
|
|
436
|
+
loaded: false,
|
|
437
|
+
noop: false,
|
|
438
|
+
triggers: picked(def, [
|
|
439
|
+
'created',
|
|
440
|
+
'changed',
|
|
441
|
+
'removed',
|
|
442
|
+
'start',
|
|
443
|
+
'active',
|
|
444
|
+
'match',
|
|
445
|
+
'tries',
|
|
446
|
+
'idempotent'
|
|
447
|
+
])
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
if (value(def, 'rule') === true) {
|
|
451
|
+
rules.push({
|
|
452
|
+
...part,
|
|
453
|
+
kind: 'data',
|
|
454
|
+
hooks: [],
|
|
455
|
+
phase: 'rules',
|
|
456
|
+
...picked(def, [
|
|
457
|
+
'match',
|
|
458
|
+
'before',
|
|
459
|
+
'optimistic'
|
|
460
|
+
])
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
return {
|
|
466
|
+
comps,
|
|
467
|
+
tools,
|
|
468
|
+
effects,
|
|
469
|
+
rules
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
/** Read registrations, never execute hooks, resources, rules or tool code. */ export let anatomyPlugin = (owner, plugin, ordinal = '')=>{
|
|
473
|
+
let name = text(plugin, 'name') ?? 'plugin';
|
|
474
|
+
let phases = entries(value(plugin, 'hooks')).filter(([, h])=>typeof h == 'function').map(([phase])=>phase);
|
|
475
|
+
let capabilities = [
|
|
476
|
+
'track',
|
|
477
|
+
'beforeWrite',
|
|
478
|
+
'wants',
|
|
479
|
+
'derive',
|
|
480
|
+
'address'
|
|
481
|
+
].filter((k)=>typeof value(plugin, k) == 'function');
|
|
482
|
+
let rules = [
|
|
483
|
+
{
|
|
484
|
+
name,
|
|
485
|
+
package: owner,
|
|
486
|
+
facet: 'graph',
|
|
487
|
+
key: ordinal,
|
|
488
|
+
kind: 'plugin',
|
|
489
|
+
hooks: phases,
|
|
490
|
+
requests: strings(value(plugin, 'requests')),
|
|
491
|
+
resources: entries(value(plugin, 'resources')).map(([k])=>k),
|
|
492
|
+
capabilities,
|
|
493
|
+
declared: true,
|
|
494
|
+
loaded: true,
|
|
495
|
+
bound: true
|
|
496
|
+
}
|
|
497
|
+
];
|
|
498
|
+
let hooks = phases.map((phase)=>({
|
|
499
|
+
name: `${name}:${phase}`,
|
|
500
|
+
package: owner,
|
|
501
|
+
facet: 'graph',
|
|
502
|
+
key: ordinal,
|
|
503
|
+
declared: true,
|
|
504
|
+
loaded: true,
|
|
505
|
+
bound: true
|
|
506
|
+
}));
|
|
507
|
+
array(value(plugin, 'rules')).forEach((r, i)=>{
|
|
508
|
+
let match = text(r, 'match');
|
|
509
|
+
rules.push({
|
|
510
|
+
name: text(r, 'name') ?? `${name}:rule:${i}`,
|
|
511
|
+
package: owner,
|
|
512
|
+
facet: 'graph',
|
|
513
|
+
key: `${ordinal}:code:${i}`,
|
|
514
|
+
kind: 'code',
|
|
515
|
+
hooks: [],
|
|
516
|
+
phase: text(r, 'phase'),
|
|
517
|
+
...match === undefined ? {} : {
|
|
518
|
+
match
|
|
519
|
+
},
|
|
520
|
+
declared: true,
|
|
521
|
+
loaded: true,
|
|
522
|
+
bound: true
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
array(value(plugin, 'declared')).forEach((d, i)=>{
|
|
526
|
+
// Declared entries wrap a rule plus its compiled pattern. The pattern and
|
|
527
|
+
// any literal Patch on a code rule are deliberately outside the boundary.
|
|
528
|
+
let r = value(d, 'rule') ?? d;
|
|
529
|
+
rules.push({
|
|
530
|
+
name: text(r, 'name') ?? `${name}:declared:${i}`,
|
|
531
|
+
package: owner,
|
|
532
|
+
facet: 'graph',
|
|
533
|
+
key: `${ordinal}:data:${i}`,
|
|
534
|
+
kind: 'data',
|
|
535
|
+
hooks: [],
|
|
536
|
+
phase: 'rules',
|
|
537
|
+
...picked(r, [
|
|
538
|
+
'match',
|
|
539
|
+
'before',
|
|
540
|
+
'optimistic'
|
|
541
|
+
]),
|
|
542
|
+
declared: true,
|
|
543
|
+
loaded: true,
|
|
544
|
+
bound: true
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
return {
|
|
548
|
+
rules,
|
|
549
|
+
hooks
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
//# sourceMappingURL=anatomy.js.map
|