@chemx/starter-kit 26.10.29-360 → 26.11.15-614
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 +106 -433
- package/cli/audit/ratchet.js +52 -7
- package/cli/commands/cmd-router.js +3 -1
- package/cli/commands-schema-commit.js +3 -2
- package/cli/commands-schema-search.js +1 -0
- package/cli/commands-schema-team.js +11 -4
- package/cli/commit/commit-args.js +5 -4
- package/cli/commit/commit-hunks.js +108 -0
- package/cli/commit/commit-run.js +33 -2
- package/cli/config/index.js +28 -0
- package/cli/docs-check/command-tree.js +1 -1
- package/cli/generator-indexer.js +3 -2
- package/cli/index-seed.js +1 -0
- package/cli/lang/detect.js +189 -0
- package/cli/lang/legacy-extensions.js +9 -0
- package/cli/lang/records/c.js +53 -0
- package/cli/lang/records/cpp.js +76 -0
- package/cli/lang/records/csharp.js +59 -0
- package/cli/lang/records/go.js +47 -0
- package/cli/lang/records/index.js +18 -0
- package/cli/lang/records/java.js +55 -0
- package/cli/lang/records/javascript.js +50 -0
- package/cli/lang/records/kotlin.js +48 -0
- package/cli/lang/records/php.js +54 -0
- package/cli/lang/records/python.js +50 -0
- package/cli/lang/records/rust.js +47 -0
- package/cli/lang/records/svelte.js +45 -0
- package/cli/lang/records/typescript.js +66 -0
- package/cli/lang/records/vue.js +45 -0
- package/cli/lang/registry.js +73 -0
- package/cli/lang/rollout.js +114 -0
- package/cli/lang/schema.js +288 -0
- package/cli/lang/static-table.js +71 -0
- package/cli/lang/types.d.ts +142 -0
- package/cli/lang/vocab.js +90 -0
- package/cli/languages.js +50 -88
- package/cli/search-args.js +1 -1
- package/cli/search-ast-module.js +26 -3
- package/cli/search-ast.js +4 -2
- package/cli/search-commands.js +44 -0
- package/cli/search-db.js +1 -0
- package/cli/search-index-meta.js +23 -7
- package/cli/search-index-write.js +5 -2
- package/cli/search-literal.js +24 -6
- package/cli/search-queries.js +19 -0
- package/cli/search-schema-ddl.js +11 -0
- package/cli/search-schema.js +6 -3
- package/cli/search-sync-paths.js +4 -3
- package/cli/search-sync-rows.js +2 -2
- package/cli/search-sync.js +2 -0
- package/cli/search.js +8 -3
- package/cli/team/check-delivery.js +115 -0
- package/cli/team/check-drainer.js +288 -0
- package/cli/team/check-executor.js +106 -0
- package/cli/team/check-fingerprint.js +105 -0
- package/cli/team/check-queue.js +114 -0
- package/cli/team/help/card-rows.js +2 -1
- package/cli/team/help/check.js +6 -0
- package/cli/team/team-commands-check.js +142 -0
- package/cli/team/team-commands.js +6 -4
- package/cli/team/team-db-feed.js +6 -0
- package/cli/team/team-db-task-helpers.js +9 -6
- package/cli/team/team-dispatch-prompts.js +10 -1
- package/cli/team/team-dispatch-select.js +1 -0
- package/cli/team/team-dispatch-v2.js +1 -0
- package/cli/team/team-dispatch.js +3 -1
- package/cli/team/team-help-golden.json +20 -5
- package/cli/team/team-schema-checks.js +46 -0
- package/cli/team/team-schema.js +2 -0
- package/cli/ui-api-index.js +39 -0
- package/cli/ui-handlers.js +17 -20
- package/cli/ui-html.js +17 -4
- package/cli/ui-index.html +298 -107
- package/cli/ui-page/components/00-core.css +10 -0
- package/cli/ui-page/components/00-core.js +78 -0
- package/cli/ui-page/components/xo-agent-profile.js +6 -0
- package/cli/ui-page/components/xo-avatar.js +17 -0
- package/cli/ui-page/components/xo-composer.js +5 -0
- package/cli/ui-page/components/xo-notification-bell.js +5 -0
- package/cli/ui-page/components/xo-post-card.js +20 -0
- package/cli/ui-page/components/xo-post-permalink.js +5 -0
- package/cli/ui-page/components/xo-post-thread.js +5 -0
- package/cli/ui-page/components/xo-timeline.js +52 -0
- package/cli/ui-page/components/xo-today-card.js +5 -0
- package/cli/ui-paging-agents.js +34 -0
- package/cli/ui-paging-feed.js +14 -0
- package/cli/ui-paging-task-where.js +63 -0
- package/cli/ui-paging-tasks.js +68 -0
- package/cli/ui-paging.js +35 -0
- package/cli/ui-server-routes.js +5 -4
- package/cli/ui-server.js +12 -0
- package/cli/ui-social-digest.js +12 -0
- package/cli/ui-social-feed.js +12 -0
- package/cli/ui-social-mentions.js +12 -0
- package/cli/ui-social-notify.js +12 -0
- package/cli/ui-social-posts.js +12 -0
- package/cli/ui-social-profile.js +12 -0
- package/cli/ui-social-routes.js +21 -0
- package/cli/ui-social-threads.js +12 -0
- package/package.json +2 -2
- package/scripts/package-json-guard.mjs +35 -0
- package/scripts/package-json-guard.spec.mjs +50 -0
- package/scripts/publish-both.mjs +25 -7
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure validator for language records (design spec 4.2). A record is plain data: no functions,
|
|
3
|
+
* no RegExp objects, no class instances. Every violation carries the dotted path of the value.
|
|
4
|
+
* Hook and resolver names are checked against `vocab.js`; that the module behind a name exists
|
|
5
|
+
* is the wiring spec's job, so this file stays free of filesystem access.
|
|
6
|
+
*/
|
|
7
|
+
import * as V from './vocab.js';
|
|
8
|
+
|
|
9
|
+
// Schema nodes are small plain objects; `check(node, value, path, errors)` interprets them.
|
|
10
|
+
const str = { t: 'str' };
|
|
11
|
+
const bool = { t: 'bool' };
|
|
12
|
+
const int = (min) => ({ t: 'int', min });
|
|
13
|
+
const en = (values) => ({ t: 'enum', values });
|
|
14
|
+
const arr = (of) => ({ t: 'arr', of });
|
|
15
|
+
const map = (of, keys) => ({ t: 'map', of, keys });
|
|
16
|
+
const obj = (fields, optional = []) => ({ t: 'obj', fields, optional });
|
|
17
|
+
const union = (...options) => ({ t: 'union', options });
|
|
18
|
+
const strList = arr(str);
|
|
19
|
+
const glob = { t: 'glob' };
|
|
20
|
+
const regex = { t: 'regex' };
|
|
21
|
+
const globs = arr(glob);
|
|
22
|
+
const regexes = arr(regex);
|
|
23
|
+
const hook = (values) => ({ t: 'enum', values, what: 'hook' });
|
|
24
|
+
const data = { t: 'data' };
|
|
25
|
+
|
|
26
|
+
const engine = en(V.ENGINES);
|
|
27
|
+
const kind = en(V.SYMBOL_KINDS);
|
|
28
|
+
|
|
29
|
+
const exportRule = {
|
|
30
|
+
t: 'tagged', tag: 'kind', values: V.EXPORT_RULE_KINDS, variants: {
|
|
31
|
+
all: obj({ kind: str }), 'top-level-only': obj({ kind: str }), capture: obj({ kind: str }),
|
|
32
|
+
'name-capitalized': obj({ kind: str }),
|
|
33
|
+
'name-not-prefix': obj({ kind: str, prefix: str }),
|
|
34
|
+
modifier: obj({ kind: str, anyOf: strList, noneOf: strList, default: bool }, ['noneOf'])
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const tieBreak = obj({ when: obj({ sibling: glob, ancestor: glob }, ['sibling', 'ancestor']), pick: str });
|
|
39
|
+
|
|
40
|
+
const files = obj({
|
|
41
|
+
extensions: arr({ t: 'ext' }), filenames: strList, paths: globs, shebangs: strList,
|
|
42
|
+
ambiguous: map(obj({
|
|
43
|
+
markers: arr(obj({ re: regex, weight: { t: 'num' } })), minScore: { t: 'num' }, tieBreak: arr(tieBreak)
|
|
44
|
+
}, ['tieBreak'])),
|
|
45
|
+
exclude: globs, declaration: globs, generated: globs, generatedMarkers: regexes,
|
|
46
|
+
vendorDirs: arr(obj({ name: str, when: union(en(V.VENDOR_WHEN), obj({ sibling: glob })) })),
|
|
47
|
+
tests: obj({ names: globs, dirs: strList, contentMarkers: regexes }, ['dirs', 'contentMarkers']),
|
|
48
|
+
regions: hook(V.REGION_HOOKS),
|
|
49
|
+
dialects: obj({ default: str, byExtension: map(str) }, ['byExtension'])
|
|
50
|
+
}, ['filenames', 'paths', 'shebangs', 'ambiguous', 'exclude', 'declaration', 'generated', 'generatedMarkers',
|
|
51
|
+
'vendorDirs', 'regions', 'dialects']);
|
|
52
|
+
|
|
53
|
+
const syntax = obj({
|
|
54
|
+
lineComment: strList,
|
|
55
|
+
blockComment: arr(obj({ open: str, close: str, nests: bool }, ['nests'])),
|
|
56
|
+
docString: arr(obj({ open: str, close: str })),
|
|
57
|
+
strings: arr(obj({
|
|
58
|
+
open: str, close: str, escape: { t: 'nullable', of: str }, raw: bool, multiline: bool
|
|
59
|
+
}, ['raw', 'multiline'])),
|
|
60
|
+
blockStyle: en(V.BLOCK_STYLES), blockOpeners: strList, endKeywords: strList, keywords: strList,
|
|
61
|
+
qualifier: en(V.QUALIFIERS)
|
|
62
|
+
}, ['docString', 'blockOpeners', 'endKeywords']);
|
|
63
|
+
|
|
64
|
+
const parse = obj({
|
|
65
|
+
grammar: union(str, map(str)), queries: str, inheritQueries: strList,
|
|
66
|
+
grammarStatus: en(V.GRAMMAR_STATUSES), errorPolicy: en(V.ERROR_POLICIES),
|
|
67
|
+
maxBytes: int(1), timeBudgetMs: int(1)
|
|
68
|
+
}, ['grammar', 'queries', 'inheritQueries', 'maxBytes', 'timeBudgetMs']);
|
|
69
|
+
|
|
70
|
+
const symbols = obj({
|
|
71
|
+
exportRule, memberKinds: map(kind, V.SYMBOL_KINDS),
|
|
72
|
+
constructorRule: obj({ names: strList, nameEqualsContainer: bool }, ['names', 'nameEqualsContainer']),
|
|
73
|
+
indexKinds: arr(kind)
|
|
74
|
+
}, ['memberKinds', 'constructorRule', 'indexKinds']);
|
|
75
|
+
|
|
76
|
+
const imports = obj({
|
|
77
|
+
resolver: en(V.RESOLVER_NAMES), options: data, normalize: hook(V.IMPORT_NORMALIZERS),
|
|
78
|
+
implicitEdges: arr(hook(V.IMPLICIT_EDGE_HOOKS))
|
|
79
|
+
}, ['options', 'normalize', 'implicitEdges']);
|
|
80
|
+
|
|
81
|
+
const layout = obj({
|
|
82
|
+
tiers: arr(obj({ glob, tier: en(V.LAYOUT_TIERS) })), entryPoints: globs, viewMarkup: bool
|
|
83
|
+
}, ['tiers', 'entryPoints', 'viewMarkup']);
|
|
84
|
+
|
|
85
|
+
const audit = obj({
|
|
86
|
+
analysisRevision: int(0), passes: arr(en(V.PASS_NAMES)), analyzer: hook(V.ANALYZER_HOOKS),
|
|
87
|
+
defaultOff: strList, droppedTextRules: strList, envAccess: regexes, fakeGreen: regexes, deltaGate: bool
|
|
88
|
+
}, ['analyzer', 'defaultOff', 'droppedTextRules', 'envAccess', 'fakeGreen', 'deltaGate']);
|
|
89
|
+
|
|
90
|
+
export const LANGUAGE_RECORD_SCHEMA = obj({
|
|
91
|
+
id: { t: 'id' }, name: str, version: int(0), legacyId: en(V.LEGACY_IDS), reportAs: str,
|
|
92
|
+
files, syntax, parse,
|
|
93
|
+
engines: obj(Object.fromEntries(V.ENGINE_SLOTS.map((s) => [s, engine]))),
|
|
94
|
+
stages: map(en(V.STAGES), V.CAPABILITIES),
|
|
95
|
+
fallback: str, symbols, imports, layout, ecosystems: strList, audit,
|
|
96
|
+
notApplicable: map({ t: 'reason' }, V.NA_FEATURES)
|
|
97
|
+
}, ['legacyId', 'reportAs', 'fallback']);
|
|
98
|
+
|
|
99
|
+
const PLAIN_PROTOTYPES = [Object.prototype, null];
|
|
100
|
+
const isObjectLike = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
101
|
+
const isPlain = (v) => isObjectLike(v) && PLAIN_PROTOTYPES.includes(Object.getPrototypeOf(v));
|
|
102
|
+
const join = (path, key) => (path ? `${path}.${key}` : key);
|
|
103
|
+
const rootName = (path) => path || '<root>';
|
|
104
|
+
const expect = (ok, message) => (ok ? null : message);
|
|
105
|
+
|
|
106
|
+
function describeValue(v) {
|
|
107
|
+
const isRegExp = v instanceof RegExp;
|
|
108
|
+
const isFunction = typeof v === 'function';
|
|
109
|
+
const isInstance = isObjectLike(v) && !isPlain(v);
|
|
110
|
+
const special = [
|
|
111
|
+
[isRegExp, 'a RegExp object (use a source string)'],
|
|
112
|
+
[isFunction, 'a function (records are plain data)'],
|
|
113
|
+
[isInstance, `a ${v?.constructor?.name ?? 'non-plain'} instance`]
|
|
114
|
+
].find(([hit]) => hit);
|
|
115
|
+
const plainTypes = [[v === null, 'null'], [Array.isArray(v), 'array']];
|
|
116
|
+
const [, base = typeof v] = plainTypes.find(([hit]) => hit) ?? [];
|
|
117
|
+
return special ? special[1] : base;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const BRACE_DELTA = { '{': 1, '}': -1 };
|
|
121
|
+
|
|
122
|
+
function braceProblem(src) {
|
|
123
|
+
let depth = 0;
|
|
124
|
+
for (const c of src) {
|
|
125
|
+
depth += BRACE_DELTA[c] ?? 0;
|
|
126
|
+
const closedEarly = depth < 0;
|
|
127
|
+
if (closedEarly) return 'unbalanced } in glob';
|
|
128
|
+
}
|
|
129
|
+
return depth > 0 ? 'unclosed { in glob' : null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A glob compiles when it is non-empty, has no NUL and balanced `[]` and `{}` (escapes honored). */
|
|
133
|
+
export function globProblem(src) {
|
|
134
|
+
const isEmpty = typeof src !== 'string' || src === '';
|
|
135
|
+
const hasNul = !isEmpty && src.includes('\0');
|
|
136
|
+
const stripped = isEmpty ? '' : src.replace(/\\./g, '').replace(/\[[^\]]*\]/g, '');
|
|
137
|
+
const hasOpenClass = stripped.includes('[');
|
|
138
|
+
const problems = [
|
|
139
|
+
[isEmpty, 'empty glob'], [hasNul, 'glob contains a NUL byte'], [hasOpenClass, 'unclosed [ in glob']
|
|
140
|
+
];
|
|
141
|
+
const hit = problems.find(([bad]) => bad);
|
|
142
|
+
return hit ? hit[1] : braceProblem(stripped);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function regexProblem(src) {
|
|
146
|
+
try {
|
|
147
|
+
new RegExp(src);
|
|
148
|
+
return null;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
return `regex does not compile: ${e.message}`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const ID_PATTERN = /^[a-z][a-z0-9]*$/;
|
|
155
|
+
const EXT_PATTERN = /^\.[^./\\\s]+(\.[^./\\\s]+)*$/;
|
|
156
|
+
const isString = (v) => typeof v === 'string';
|
|
157
|
+
const isNonEmptyString = (v) => isString(v) && v.trim() !== '';
|
|
158
|
+
const isInt = (v, min) => Number.isInteger(v) && v >= min;
|
|
159
|
+
|
|
160
|
+
/** Leaf checks: each returns a message, or null when the value is fine. */
|
|
161
|
+
const LEAF = {
|
|
162
|
+
str: (n, v) => expect(isString(v), `expected a string, got ${describeValue(v)}`),
|
|
163
|
+
bool: (n, v) => expect(typeof v === 'boolean', `expected a boolean, got ${describeValue(v)}`),
|
|
164
|
+
num: (n, v) => expect(Number.isFinite(v), `expected a number, got ${describeValue(v)}`),
|
|
165
|
+
int: (n, v) => expect(isInt(v, n.min), `expected an integer >= ${n.min}, got ${describeValue(v)}`),
|
|
166
|
+
id: (n, v) => expect(isString(v) && ID_PATTERN.test(v), `expected an id matching ${ID_PATTERN}`),
|
|
167
|
+
ext: (n, v) => expect(isString(v) && EXT_PATTERN.test(v), 'expected a dotted extension such as ".go"'),
|
|
168
|
+
reason: (n, v) => expect(isNonEmptyString(v), 'expected a non-empty reason string'),
|
|
169
|
+
glob: (n, v) => (isString(v) ? globProblem(v) : `expected a glob source string, got ${describeValue(v)}`),
|
|
170
|
+
regex: (n, v) => (isString(v) ? regexProblem(v) : `expected a regex source string, got ${describeValue(v)}`),
|
|
171
|
+
enum: (n, v) => enumProblem(n, v)
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function enumProblem(node, value) {
|
|
175
|
+
const isKnown = isString(value) && node.values.includes(value);
|
|
176
|
+
if (isKnown) return null;
|
|
177
|
+
const what = node.what === 'hook' ? 'hook name' : 'value';
|
|
178
|
+
const known = node.values.length ? node.values.join(', ') : '(none registered)';
|
|
179
|
+
const shown = isString(value) ? JSON.stringify(value) : describeValue(value);
|
|
180
|
+
return `unknown ${what} ${shown}; expected one of: ${known}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function checkData(value, path, errors) {
|
|
184
|
+
const isScalar = value === null || ['string', 'number', 'boolean'].includes(typeof value);
|
|
185
|
+
const isList = Array.isArray(value);
|
|
186
|
+
const isForeign = !isScalar && !isList && !isPlain(value);
|
|
187
|
+
if (isScalar) return;
|
|
188
|
+
if (isList) return value.forEach((v, i) => checkData(v, `${path}[${i}]`, errors));
|
|
189
|
+
if (isForeign) return errors.push({ path, message: `expected plain data, got ${describeValue(value)}` });
|
|
190
|
+
Object.entries(value).forEach(([k, v]) => checkData(v, join(path, k), errors));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function expectObject(value, path, errors) {
|
|
194
|
+
const ok = isPlain(value);
|
|
195
|
+
if (!ok) errors.push({ path: rootName(path), message: `expected an object, got ${describeValue(value)}` });
|
|
196
|
+
return ok;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function checkObject(node, value, path, errors) {
|
|
200
|
+
const isObject = expectObject(value, path, errors);
|
|
201
|
+
if (!isObject) return;
|
|
202
|
+
const unknownKeys = Object.keys(value).filter((key) => !(key in node.fields));
|
|
203
|
+
unknownKeys.forEach((key) => errors.push({ path: join(path, key), message: 'unknown key' }));
|
|
204
|
+
for (const [key, child] of Object.entries(node.fields)) {
|
|
205
|
+
const present = value[key] !== undefined;
|
|
206
|
+
const missing = !present && !node.optional.includes(key);
|
|
207
|
+
if (present) check(child, value[key], join(path, key), errors);
|
|
208
|
+
if (missing) errors.push({ path: join(path, key), message: 'required' });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function checkArray(node, value, path, errors) {
|
|
213
|
+
const ok = Array.isArray(value);
|
|
214
|
+
if (!ok) errors.push({ path: rootName(path), message: `expected an array, got ${describeValue(value)}` });
|
|
215
|
+
if (ok) value.forEach((v, i) => check(node.of, v, `${path}[${i}]`, errors));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function checkMap(node, value, path, errors) {
|
|
219
|
+
const isObject = expectObject(value, path, errors);
|
|
220
|
+
if (!isObject) return;
|
|
221
|
+
for (const [key, child] of Object.entries(value)) {
|
|
222
|
+
const known = !node.keys || node.keys.includes(key);
|
|
223
|
+
if (known) check(node.of, child, join(path, key), errors);
|
|
224
|
+
else errors.push({ path: join(path, key), message: `unknown key; expected one of: ${node.keys.join(', ')}` });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function checkTagged(node, value, path, errors) {
|
|
229
|
+
const isObject = expectObject(value, path, errors);
|
|
230
|
+
if (!isObject) return;
|
|
231
|
+
const tag = value[node.tag];
|
|
232
|
+
const known = node.values.includes(tag);
|
|
233
|
+
const message = enumProblem({ values: node.values }, tag);
|
|
234
|
+
if (known) checkObject(node.variants[tag], value, path, errors);
|
|
235
|
+
else errors.push({ path: join(path, node.tag), message });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// A union reports the errors of the branch whose outer shape the value already has.
|
|
239
|
+
const SHAPE_MATCHES = { str: isString, enum: isString, map: isPlain, obj: isPlain };
|
|
240
|
+
|
|
241
|
+
function checkUnion(node, value, path, errors) {
|
|
242
|
+
const trials = node.options.map((option) => {
|
|
243
|
+
const found = [];
|
|
244
|
+
check(option, value, path, found);
|
|
245
|
+
return found;
|
|
246
|
+
});
|
|
247
|
+
const passes = trials.some((found) => found.length === 0);
|
|
248
|
+
const shaped = trials.findIndex((found, i) => SHAPE_MATCHES[node.options[i].t]?.(value));
|
|
249
|
+
const fallback = [{ path: rootName(path), message: 'does not match any allowed shape' }];
|
|
250
|
+
if (!passes) errors.push(...(shaped >= 0 ? trials[shaped] : fallback));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function checkNullable(node, value, path, errors) {
|
|
254
|
+
const isNull = value === null;
|
|
255
|
+
if (!isNull) check(node.of, value, path, errors);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const COMPOSITE = {
|
|
259
|
+
obj: checkObject, arr: checkArray, map: checkMap, tagged: checkTagged, union: checkUnion,
|
|
260
|
+
nullable: checkNullable, data: (node, value, path, errors) => checkData(value, rootName(path), errors)
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
function check(node, value, path, errors) {
|
|
264
|
+
const leaf = LEAF[node.t];
|
|
265
|
+
const composite = COMPOSITE[node.t];
|
|
266
|
+
const message = leaf?.(node, value);
|
|
267
|
+
if (message) errors.push({ path: rootName(path), message });
|
|
268
|
+
if (composite) composite(node, value, path, errors);
|
|
269
|
+
const isUnknownNode = !leaf && !composite;
|
|
270
|
+
if (isUnknownNode) throw new Error(`schema: unknown node type ${node.t}`);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** @returns {{ ok: boolean, errors: { path: string, message: string }[] }} */
|
|
274
|
+
export function validateLanguageRecord(record) {
|
|
275
|
+
const errors = [];
|
|
276
|
+
check(LANGUAGE_RECORD_SCHEMA, record, '', errors);
|
|
277
|
+
return { ok: errors.length === 0, errors };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Throws one Error listing every violation; returns the record unchanged when valid. */
|
|
281
|
+
export function assertLanguageRecord(record) {
|
|
282
|
+
const { ok, errors } = validateLanguageRecord(record);
|
|
283
|
+
const id = isPlain(record) && isString(record.id) ? record.id : '?';
|
|
284
|
+
const lines = errors.map((e) => ` ${e.path}: ${e.message}`).join('\n');
|
|
285
|
+
const isInvalid = !ok;
|
|
286
|
+
if (isInvalid) throw new Error(`language record "${id}" is invalid:\n${lines}`);
|
|
287
|
+
return record;
|
|
288
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one extension table (design spec 4.13). It imports only the records, so the guard can
|
|
3
|
+
* load it without the registry, a parser or any engine. `buildTable(records)` derives the
|
|
4
|
+
* lookups; `STATIC_TABLE` is the table over the shipped records. Later phases add the guard,
|
|
5
|
+
* preflight, micro-sync and vendor sets here, derived the same way.
|
|
6
|
+
*/
|
|
7
|
+
import { LANGUAGE_RECORDS } from './records/index.js';
|
|
8
|
+
|
|
9
|
+
const escapeText = (text) => text.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
|
|
10
|
+
|
|
11
|
+
// Glob token -> RegExp source, tried in order at the head of the remaining glob.
|
|
12
|
+
const GLOB_TOKENS = [
|
|
13
|
+
[/^\*\*\//, () => '(?:.*/)?'],
|
|
14
|
+
[/^\*\*/, () => '.*'],
|
|
15
|
+
[/^\*/, () => '[^/]*'],
|
|
16
|
+
[/^\?/, () => '[^/]'],
|
|
17
|
+
[/^\[[^\]]+\]/, (m) => m.replace(/^\[!/, '[^')],
|
|
18
|
+
[/^\{[^}]*\}/, (m) => `(?:${m.slice(1, -1).split(',').map(escapeText).join('|')})`],
|
|
19
|
+
[/^\\./, (m) => escapeText(m[1])],
|
|
20
|
+
[/^./, (m) => escapeText(m)]
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** An anchored RegExp for a glob over a forward-slash path: `*` and `?` stay inside one segment. */
|
|
24
|
+
export const compileGlob = (glob) => {
|
|
25
|
+
let source = '';
|
|
26
|
+
let rest = glob;
|
|
27
|
+
while (rest) {
|
|
28
|
+
const [pattern, render] = GLOB_TOKENS.find(([re]) => re.test(rest));
|
|
29
|
+
const token = rest.match(pattern)[0];
|
|
30
|
+
source += render(token);
|
|
31
|
+
rest = rest.slice(token.length);
|
|
32
|
+
}
|
|
33
|
+
return new RegExp(`^${source}$`);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const pushTo = (map, key, id) => {
|
|
37
|
+
const ids = map.get(key) ?? [];
|
|
38
|
+
if (!ids.includes(id)) ids.push(id);
|
|
39
|
+
map.set(key, ids);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Lookups derived from `records`; every id list keeps registration order. */
|
|
43
|
+
export const buildTable = (records) => {
|
|
44
|
+
const byExtension = new Map();
|
|
45
|
+
const byFilename = new Map();
|
|
46
|
+
const shebangs = new Map();
|
|
47
|
+
const paths = [];
|
|
48
|
+
const extensions = new Set();
|
|
49
|
+
const sourceExtensions = new Set();
|
|
50
|
+
const declarations = [];
|
|
51
|
+
for (const { id, files, stages } of records) {
|
|
52
|
+
const isSource = (stages.source ?? 'off') !== 'off';
|
|
53
|
+
for (const ext of files.extensions) {
|
|
54
|
+
pushTo(byExtension, ext, id);
|
|
55
|
+
extensions.add(ext);
|
|
56
|
+
if (isSource) sourceExtensions.add(ext);
|
|
57
|
+
}
|
|
58
|
+
(files.filenames ?? []).forEach((name) => pushTo(byFilename, name, id));
|
|
59
|
+
(files.shebangs ?? []).forEach((name) => pushTo(shebangs, name, id));
|
|
60
|
+
(files.paths ?? []).forEach((glob) => paths.push({ glob, re: compileGlob(glob), id }));
|
|
61
|
+
(files.declaration ?? []).forEach((glob) => declarations.push(compileGlob(glob)));
|
|
62
|
+
}
|
|
63
|
+
/** True for a declaration file such as `*.d.ts`, matched on the basename. */
|
|
64
|
+
const isDeclarationName = (name) => {
|
|
65
|
+
const base = name.split(/[\\/]/).pop();
|
|
66
|
+
return declarations.some((re) => re.test(base));
|
|
67
|
+
};
|
|
68
|
+
return { byExtension, byFilename, shebangs, paths, extensions, sourceExtensions, isDeclarationName };
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const STATIC_TABLE = buildTable(LANGUAGE_RECORDS);
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language adapter contract (design spec 4.2 and 4.5). A language is one plain-data record;
|
|
3
|
+
* `schema.js` enforces this shape at runtime and `vocab.js` holds every closed vocabulary.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Matches /^[a-z][a-z0-9]*$/; not a closed union, a new language adds a record, not a type. */
|
|
7
|
+
export type LanguageId = string;
|
|
8
|
+
/** A glob source string. */
|
|
9
|
+
export type Glob = string;
|
|
10
|
+
/** A regular expression source string; records never hold RegExp objects. */
|
|
11
|
+
export type RegexSource = string;
|
|
12
|
+
/** A name resolved to a module by convention (spec 4.16), checked against vocab.js. */
|
|
13
|
+
export type HookName = string;
|
|
14
|
+
|
|
15
|
+
export type SymbolKind =
|
|
16
|
+
| 'module' | 'namespace' | 'class' | 'struct' | 'interface' | 'trait' | 'protocol' | 'enum' | 'record' | 'union'
|
|
17
|
+
| 'type' | 'function' | 'method' | 'constructor' | 'property' | 'field' | 'const' | 'variable' | 'macro'
|
|
18
|
+
| 'component' | 'test' | 'resource' | 'table' | 'view' | 'procedure'
|
|
19
|
+
| 'impl' | 'extension' | 'block';
|
|
20
|
+
export type Visibility = 'public' | 'private' | 'protected' | 'internal' | 'package' | 'fileprivate' | 'open';
|
|
21
|
+
export type ImportKind = 'import' | 'from' | 'require' | 'include' | 'use' | 'using' | 'source' | 'module' | 'dynamic' | 'reexport';
|
|
22
|
+
export type Engine = 'babel' | 'sfc' | 'php-parser' | 'csharp-heuristic' | 'tree-sitter' | 'regex' | 'legacy-polyglot' | 'text';
|
|
23
|
+
export type EngineSlot = 'index' | 'outline' | 'symbol' | 'logic' | 'audit' | 'editGate';
|
|
24
|
+
export type Capability = 'source' | 'index' | 'outline' | 'imports' | 'resolve' | 'editGate' | 'audit' | 'guard';
|
|
25
|
+
export type Stage = 'off' | 'text' | 'shadow' | 'on';
|
|
26
|
+
export type BlockStyle = 'brace' | 'indent' | 'end-keyword' | 'paren' | 'none';
|
|
27
|
+
export type Tier = 'primitive' | 'prefab' | 'construct' | 'blueprint' | 'level' | 'atom' | 'molecule' | 'organism' | 'template' | 'page';
|
|
28
|
+
export type PassName = 'text' | 'structure' | 'complexity' | 'errors' | 'security' | 'logging' | 'tests' | 'env';
|
|
29
|
+
export type NaFeature = 'forge' | 'heal' | 'explode' | 'generate' | 'capsule' | 'scaffold' | 'lanes' | 'template' | 'autofix' | 'mutators';
|
|
30
|
+
export type ResolverName =
|
|
31
|
+
| 'js' | 'path-probe' | 'python' | 'c-include' | 'go-module' | 'rust-crate' | 'jvm-package' | 'dotnet-namespace' | 'php-psr4';
|
|
32
|
+
|
|
33
|
+
/** Free-form resolver options: plain JSON-like data only. */
|
|
34
|
+
export type ResolverOptions = { [key: string]: unknown };
|
|
35
|
+
|
|
36
|
+
export interface TieBreak {
|
|
37
|
+
when: { sibling?: Glob; ancestor?: Glob };
|
|
38
|
+
/** The language id chosen when the condition holds. */
|
|
39
|
+
pick: LanguageId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ExportRule =
|
|
43
|
+
| { kind: 'all' } | { kind: 'top-level-only' } | { kind: 'capture' }
|
|
44
|
+
| { kind: 'name-not-prefix'; prefix: string } | { kind: 'name-capitalized' }
|
|
45
|
+
| { kind: 'modifier'; anyOf: string[]; noneOf?: string[]; default: boolean };
|
|
46
|
+
|
|
47
|
+
export interface LanguageRecord {
|
|
48
|
+
id: LanguageId;
|
|
49
|
+
name: string;
|
|
50
|
+
/** Bumps when the record or its queries change meaning. */
|
|
51
|
+
version: number;
|
|
52
|
+
/** Facade id until the coverage bucket switch. */
|
|
53
|
+
legacyId?: 'jvm' | 'cpp';
|
|
54
|
+
/** Coverage and ratchet bucket key. */
|
|
55
|
+
reportAs?: string;
|
|
56
|
+
files: {
|
|
57
|
+
extensions: string[];
|
|
58
|
+
filenames?: string[];
|
|
59
|
+
paths?: Glob[];
|
|
60
|
+
shebangs?: string[];
|
|
61
|
+
ambiguous?: Record<string, { markers: { re: RegexSource; weight: number }[]; minScore: number; tieBreak?: TieBreak[] }>;
|
|
62
|
+
exclude?: Glob[];
|
|
63
|
+
declaration?: Glob[];
|
|
64
|
+
generated?: Glob[];
|
|
65
|
+
generatedMarkers?: RegexSource[];
|
|
66
|
+
vendorDirs?: { name: string; when: 'always' | 'project-root' | { sibling: Glob } }[];
|
|
67
|
+
tests: { names: Glob[]; dirs?: string[]; contentMarkers?: RegexSource[] };
|
|
68
|
+
/** Embedded-language splitter. */
|
|
69
|
+
regions?: HookName;
|
|
70
|
+
dialects?: { default: string; byExtension?: Record<string, string> };
|
|
71
|
+
};
|
|
72
|
+
syntax: {
|
|
73
|
+
lineComment: string[];
|
|
74
|
+
blockComment: { open: string; close: string; nests?: boolean }[];
|
|
75
|
+
docString?: { open: string; close: string }[];
|
|
76
|
+
strings: { open: string; close: string; escape: string | null; raw?: boolean; multiline?: boolean }[];
|
|
77
|
+
blockStyle: BlockStyle;
|
|
78
|
+
blockOpeners?: string[];
|
|
79
|
+
endKeywords?: string[];
|
|
80
|
+
keywords: string[];
|
|
81
|
+
qualifier: '.' | '::' | '\\';
|
|
82
|
+
};
|
|
83
|
+
parse: {
|
|
84
|
+
grammar?: string | Record<string, string>;
|
|
85
|
+
queries?: string;
|
|
86
|
+
inheritQueries?: string[];
|
|
87
|
+
grammarStatus: 'vetted' | 'experimental' | 'none';
|
|
88
|
+
errorPolicy: 'report' | 'coverage-only';
|
|
89
|
+
maxBytes?: number;
|
|
90
|
+
timeBudgetMs?: number;
|
|
91
|
+
};
|
|
92
|
+
engines: Record<EngineSlot, Engine>;
|
|
93
|
+
stages: Partial<Record<Capability, Stage>>;
|
|
94
|
+
/** Own-language regex module in cli/lang/fallback/. */
|
|
95
|
+
fallback?: string;
|
|
96
|
+
symbols: {
|
|
97
|
+
exportRule: ExportRule;
|
|
98
|
+
memberKinds?: Partial<Record<SymbolKind, SymbolKind>>;
|
|
99
|
+
constructorRule?: { names?: string[]; nameEqualsContainer?: boolean };
|
|
100
|
+
indexKinds?: SymbolKind[];
|
|
101
|
+
};
|
|
102
|
+
imports: { resolver: ResolverName; options?: ResolverOptions; normalize?: HookName; implicitEdges?: HookName[] };
|
|
103
|
+
layout: { tiers?: { glob: Glob; tier: Tier }[]; entryPoints?: Glob[]; viewMarkup?: boolean };
|
|
104
|
+
ecosystems: string[];
|
|
105
|
+
audit: {
|
|
106
|
+
analysisRevision: number;
|
|
107
|
+
passes: PassName[];
|
|
108
|
+
analyzer?: HookName;
|
|
109
|
+
defaultOff?: string[];
|
|
110
|
+
droppedTextRules?: string[];
|
|
111
|
+
envAccess?: RegexSource[];
|
|
112
|
+
fakeGreen?: RegexSource[];
|
|
113
|
+
deltaGate?: boolean;
|
|
114
|
+
};
|
|
115
|
+
/** Feature to the reason shown to the user. */
|
|
116
|
+
notApplicable: Partial<Record<NaFeature, string>>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SymbolRow {
|
|
120
|
+
name: string; kind: SymbolKind; startLine: number; endLine: number; startColumn: number;
|
|
121
|
+
signature: string; isExport: boolean; visibility: Visibility | null; container: string | null;
|
|
122
|
+
qualifiedName: string; depth: number; isMember: boolean; docStartLine: number | null;
|
|
123
|
+
language: string; engine: Engine; confidence: 'ast' | 'heuristic';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface ImportRow {
|
|
127
|
+
specifier: string; kind: ImportKind; names: string[]; alias: string | null;
|
|
128
|
+
line: number; isTypeOnly: boolean; confidence: 'ast' | 'heuristic';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface Extraction {
|
|
132
|
+
language: string; engine: Engine;
|
|
133
|
+
status: 'ok' | 'partial' | 'error' | 'minified' | 'skipped' | 'unavailable' | 'heuristic' | 'text';
|
|
134
|
+
reason: string | null; errorCount: number;
|
|
135
|
+
firstError: { line: number; column: number; message: string } | null;
|
|
136
|
+
symbols: SymbolRow[]; imports: ImportRow[];
|
|
137
|
+
/** `${id}@${version}:${engine}:${grammarSha8|'-'}:${stage}` */
|
|
138
|
+
fingerprint: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface SchemaError { path: string; message: string }
|
|
142
|
+
export interface SchemaResult { ok: boolean; errors: SchemaError[] }
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Closed vocabularies of the language-adapter contract (design spec 4.16). Each vocabulary has
|
|
3
|
+
* exactly one registration point, here: adding a name is one line, and the code behind a name is
|
|
4
|
+
* a module found by convention. Pure data, no imports, safe for the guard's import closure.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const list = (...names) => Object.freeze(names);
|
|
8
|
+
|
|
9
|
+
export const SYMBOL_KINDS = list(
|
|
10
|
+
'module', 'namespace', 'class', 'struct', 'interface', 'trait', 'protocol', 'enum', 'record', 'union',
|
|
11
|
+
'type', 'function', 'method', 'constructor', 'property', 'field', 'const', 'variable', 'macro',
|
|
12
|
+
'component', 'test', 'resource', 'table', 'view', 'procedure',
|
|
13
|
+
// container-only kinds: they group members but are not indexed as definitions
|
|
14
|
+
'impl', 'extension', 'block'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const VISIBILITIES = list('public', 'private', 'protected', 'internal', 'package', 'fileprivate', 'open');
|
|
18
|
+
export const IMPORT_KINDS = list('import', 'from', 'require', 'include', 'use', 'using', 'source', 'module', 'dynamic', 'reexport');
|
|
19
|
+
|
|
20
|
+
/** Capture names per kit-owned query file (spec 4.5). `@definition.*` and `@container.*` expand from the kinds. */
|
|
21
|
+
export const CAPTURES = Object.freeze({
|
|
22
|
+
tags: list(
|
|
23
|
+
...SYMBOL_KINDS.filter((k) => !['impl', 'extension', 'block'].includes(k)).map((k) => `@definition.${k}`),
|
|
24
|
+
'@container.impl', '@container.extension', '@container.block',
|
|
25
|
+
'@name', '@body', '@doc', '@export', '@visibility', '@modifier', '@reference.type', '@entry'
|
|
26
|
+
),
|
|
27
|
+
imports: list(
|
|
28
|
+
'@import', '@import.source', '@import.source.system', '@import.name', '@import.alias', '@import.wildcard',
|
|
29
|
+
'@import.mod', '@import.type-only', '@import.dynamic'
|
|
30
|
+
),
|
|
31
|
+
calls: list('@call', '@call.name', '@call.receiver'),
|
|
32
|
+
syntax: list('@comment', '@comment.doc', '@string'),
|
|
33
|
+
audit: list(
|
|
34
|
+
'@scope.function', '@branch', '@logic', '@nest', '@ternary', '@catch', '@catch.body', '@catch.swallow',
|
|
35
|
+
'@exec', '@log', '@flow.return', '@flow.throw', '@flow.loop'
|
|
36
|
+
)
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** Predicates that `#set!` may carry in query files. */
|
|
40
|
+
export const QUERY_PROPERTIES = list('chemx.kind', 'chemx.skip', 'chemx.importKind');
|
|
41
|
+
|
|
42
|
+
export const ENGINES = list('babel', 'sfc', 'php-parser', 'csharp-heuristic', 'tree-sitter', 'regex', 'legacy-polyglot', 'text');
|
|
43
|
+
export const ENGINE_SLOTS = list('index', 'outline', 'symbol', 'logic', 'audit', 'editGate');
|
|
44
|
+
export const CAPABILITIES = list('source', 'index', 'outline', 'imports', 'resolve', 'editGate', 'audit', 'guard');
|
|
45
|
+
export const STAGES = list('off', 'text', 'shadow', 'on');
|
|
46
|
+
|
|
47
|
+
export const BLOCK_STYLES = list('brace', 'indent', 'end-keyword', 'paren', 'none');
|
|
48
|
+
export const QUALIFIERS = list('.', '::', '\\');
|
|
49
|
+
export const GRAMMAR_STATUSES = list('vetted', 'experimental', 'none');
|
|
50
|
+
export const ERROR_POLICIES = list('report', 'coverage-only');
|
|
51
|
+
export const GRAMMAR_TIERS = list('core', 'extended', 'experimental');
|
|
52
|
+
export const LEGACY_IDS = list('jvm', 'cpp');
|
|
53
|
+
export const VENDOR_WHEN = list('always', 'project-root');
|
|
54
|
+
export const LAYOUT_TIERS = list(
|
|
55
|
+
'primitive', 'prefab', 'construct', 'blueprint', 'level', 'atom', 'molecule', 'organism', 'template', 'page'
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
export const EXPORT_RULE_KINDS = list('all', 'top-level-only', 'capture', 'name-not-prefix', 'name-capitalized', 'modifier');
|
|
59
|
+
|
|
60
|
+
export const RESOLVER_NAMES = list(
|
|
61
|
+
'js', 'path-probe', 'python', 'c-include', 'go-module', 'rust-crate', 'jvm-package', 'dotnet-namespace', 'php-psr4'
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
/** Audit pass families a record may enable; the analyzer behind each is chosen by `engines.audit`. */
|
|
65
|
+
export const PASS_NAMES = list('text', 'structure', 'complexity', 'errors', 'security', 'logging', 'tests', 'env');
|
|
66
|
+
|
|
67
|
+
/** Features a language can mark not applicable, with a reason shown to the user (spec 4.15). */
|
|
68
|
+
export const NA_FEATURES = list(
|
|
69
|
+
'forge', 'heal', 'explode', 'generate', 'capsule', 'scaffold', 'lanes', 'template', 'autofix', 'mutators'
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// Hook names: each resolves to a module by convention (spec 4.16); the name check happens here.
|
|
73
|
+
export const REGION_HOOKS = list('regions-ipynb', 'regions-rmd', 'regions-jinja-sql', 'regions-tsql-batches');
|
|
74
|
+
export const IMPORT_NORMALIZERS = list('rust-use-tree', 'dbt-refs');
|
|
75
|
+
export const IMPLICIT_EDGE_HOOKS = list(
|
|
76
|
+
'same-package-decl', 'same-namespace', 'same-module-target', 'header-impl', 'autoload-constant',
|
|
77
|
+
'terraform-dir', 'conftest-fixture', 'declared-name'
|
|
78
|
+
);
|
|
79
|
+
export const ANALYZER_HOOKS = list();
|
|
80
|
+
export const PLANNER_HOOKS = list('npm-legacy', 'php-harness');
|
|
81
|
+
export const FORMAT_HOOKS = list('json-diagnostics');
|
|
82
|
+
|
|
83
|
+
// Toolchain ecosystem vocabularies (spec 4.11).
|
|
84
|
+
export const TARGET_MODES = list('file', 'files', 'dir', 'package', 'module', 'project', 'none');
|
|
85
|
+
export const WORKSPACE_FORMATS = list('go-work', 'cargo-toml', 'gradle-settings', 'sln', 'maven-modules', 'pnpm', 'npm', 'uv');
|
|
86
|
+
export const MANIFEST_FORMATS = list('json', 'toml-lite', 'xml-lite', 'go-mod', 'line');
|
|
87
|
+
export const PARSER_IDS = list(
|
|
88
|
+
'node-legacy', 'junit', 'trx', 'tap', 'go-test-json', 'dart-json', 'json-diagnostics',
|
|
89
|
+
'gcc', 'msbuild', 'javac-maven', 'kotlinc', 'rustc-short', 'mypy', 'pyright', 'ruff', 'cargo-test'
|
|
90
|
+
);
|