@starci/eslint-canon-be 3.18.4 → 3.19.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/CHANGELOG.md +4 -0
- package/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// i18n.mjs - the ONE mechanism for text the owner must read in Vietnamese. Runtime source, comments and messages are English;
|
|
2
|
-
// a message the owner reads (a Telegram notice, a why line, a progress report) is written once in English at its call site and
|
|
3
|
-
// translated through a DECLARED catalog keyed from that English source: modules/i18n/messages/<area>.yaml, a list of
|
|
4
|
-
// `{en, vi}` entries. Each area belongs to a scope: `runtime` for Node callers or `ui` for the generated browser catalog.
|
|
5
|
-
// The `vi` field is declared in scripts/lib/language.mjs, so it is the only Vietnamese source. There is no per-module
|
|
6
|
-
// `TEXT.vi` table and no second catalog mechanism.
|
|
7
|
-
//
|
|
8
|
-
// const tr = translator(config.language); // 'vi' translates, anything else returns the English source
|
|
9
|
-
// tr('Workflow {id} needs your decision', { id })
|
|
10
|
-
//
|
|
11
|
-
// A placeholder is `{name}`; the English and the Vietnamese of one entry carry exactly the same placeholders
|
|
12
|
-
// (scripts/checks/check-i18n-catalog.mjs). An English source with no entry is returned as is: a missing translation degrades
|
|
13
|
-
// to English, never to a blank.
|
|
14
|
-
import { byCodeUnit } from './list.mjs';
|
|
15
|
-
import { escapeRegExp } from './regex.mjs';
|
|
16
|
-
import fs from 'node:fs';
|
|
17
|
-
import path from 'node:path';
|
|
18
|
-
import { skillRoot } from '../../engine/runtime-root.mjs';
|
|
19
|
-
import { parseYaml } from '../../engine/yaml.mjs';
|
|
20
|
-
import { DEFAULT_OWNER_LANGUAGE, loadConfig } from '../../engine/config.mjs';
|
|
21
|
-
export const CATALOG_DIR = 'modules/i18n/messages';
|
|
22
|
-
export const PLACEHOLDER = /\{([A-Za-z_]\w*)\}/g;
|
|
23
|
-
const cache = new Map();
|
|
24
|
-
/** The catalog files of a runtime root: repository-relative paths, sorted. */
|
|
25
|
-
export function catalogFiles(root = skillRoot) {
|
|
26
|
-
const dir = path.join(root, ...CATALOG_DIR.split('/'));
|
|
27
|
-
try {
|
|
28
|
-
return fs.readdirSync(dir).filter((name) => /\.ya?ml$/.test(name)).sort().map((name) => `${CATALOG_DIR}/${name}`);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/** Every entry in one catalog scope: `[{ en, vi, area, scope, file }]`. */
|
|
35
|
-
export function catalogEntries(root = skillRoot, { scope = 'runtime' } = {}) {
|
|
36
|
-
return catalogFiles(root).flatMap((rel) => {
|
|
37
|
-
const doc = parseYaml(fs.readFileSync(path.join(root, ...rel.split('/')), 'utf8'));
|
|
38
|
-
const documentScope = typeof doc?.scope === 'string' ? doc.scope : 'runtime';
|
|
39
|
-
if (documentScope !== scope)
|
|
40
|
-
return [];
|
|
41
|
-
return (Array.isArray(doc?.messages) ? doc.messages : []).map((entry) => ({
|
|
42
|
-
en: entry?.en, vi: entry?.vi, area: doc?.area, scope: documentScope, file: rel,
|
|
43
|
-
}));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/** One scoped catalog as a Map from the English source to the Vietnamese text (cached per root and scope). */
|
|
47
|
-
export function loadCatalog(root = skillRoot, { scope = 'runtime' } = {}) {
|
|
48
|
-
const key = `${root}\0${scope}`;
|
|
49
|
-
if (!cache.has(key))
|
|
50
|
-
cache.set(key, new Map(catalogEntries(root, { scope }).filter((e) => typeof e.en === 'string' && typeof e.vi === 'string').map((e) => [e.en, e.vi])));
|
|
51
|
-
return cache.get(key);
|
|
52
|
-
}
|
|
53
|
-
/** The names each `pattern` match captures (group 1) in `text`, in match order (`sort` sorts them). */
|
|
54
|
-
export const captureNames = (text, pattern, { sort = false } = {}) => {
|
|
55
|
-
const names = [...String(text).matchAll(pattern)].map((m) => m[1]);
|
|
56
|
-
return sort ? names.sort(byCodeUnit) : names;
|
|
57
|
-
};
|
|
58
|
-
/** The names of the placeholders of a message. */
|
|
59
|
-
export const placeholdersOf = (text) => captureNames(text, PLACEHOLDER, { sort: true });
|
|
60
|
-
/** `text` with each `{name}` replaced by vars[name] (an unknown name is left as written). */
|
|
61
|
-
export const fill = (text, vars = {}) => String(text).replace(PLACEHOLDER, (whole, name) => (Object.hasOwn(vars, name) ? String(vars[name]) : whole));
|
|
62
|
-
/** The message `en` in `language` (`vi` translates through the catalog; any other language is the English source). */
|
|
63
|
-
export function translate(en, vars = {}, { language = DEFAULT_OWNER_LANGUAGE, root = skillRoot, scope = 'runtime' } = {}) {
|
|
64
|
-
const vi = language === 'vi' ? loadCatalog(root, { scope }).get(en) : undefined;
|
|
65
|
-
return fill(vi ?? en, vars);
|
|
66
|
-
}
|
|
67
|
-
/** The owner's language (config.yaml `language`); `fallback` when there is no readable config (DEFAULT_OWNER_LANGUAGE of engine/config.mjs). */
|
|
68
|
-
export function ownerLanguage(fallback = DEFAULT_OWNER_LANGUAGE) {
|
|
69
|
-
try {
|
|
70
|
-
return loadConfig()?.language ?? fallback;
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return fallback;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/** A translator bound to one language: `tr(en, vars)`. */
|
|
77
|
-
export const translator = (language = DEFAULT_OWNER_LANGUAGE, { root = skillRoot, scope = 'runtime' } = {}) => (en, vars = {}) => translate(en, vars, { language, root, scope });
|
|
78
|
-
/**
|
|
79
|
-
* A pattern source matching `en` in the owner's language or in English: each language's rendering of the English source,
|
|
80
|
-
* escaped, with the placeholder `slot` (a placeholder name of `en`) replaced by `slotPattern`. Never hardcodes a spelling.
|
|
81
|
-
*/
|
|
82
|
-
export const translatedPattern = (en, slot, slotPattern, languages = ['en', 'vi']) => `(?:${languages.map((language) => escapeRegExp(translate(en, { [slot]: '@@' }, { language })).replace('@@', slotPattern)).join('|')})`;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// in-order.mjs — asynchronous work done strictly one after another, named by what it does. A sequential `await` in a
|
|
2
|
-
// loop is often the point (ordered ledger writes, one Orca or git call at a time, a rate limit, stop at the first
|
|
3
|
-
// failure or match); these helpers state that intent at the call site so no loop body carries an `await`. Each one
|
|
4
|
-
// starts item n+1 only after item n has settled, lets the first rejection (or a synchronous throw of `fn`) stop the run
|
|
5
|
-
// with later items never started, pulls a lazy iterable one item at a time, and closes it on an early stop, the way
|
|
6
|
-
// `for (const x of xs) await fn(x)` does. All of them run on the one `walk` below: promise callbacks, not an async
|
|
7
|
-
// recursion, so the stack and the memory stay flat however long the input is.
|
|
8
|
-
// Provably independent work that needs no order, short-circuit or error contract may use `Promise.all` instead.
|
|
9
|
-
/** Close `iterator` the way a `for...of` leaves it: `return()` when it has one. */
|
|
10
|
-
const close = (iterator) => iterator.return?.();
|
|
11
|
-
/**
|
|
12
|
-
* Drive `visit(item, index)` over `items` one at a time. `decide(outcome, item)` runs after each settled visit: a
|
|
13
|
-
* `{ value }` box ends the walk with that value, anything else goes on. Resolves with the box value, or `undefined` when
|
|
14
|
-
* the items ran out; rejects with the first rejection or throw, after closing the iterator.
|
|
15
|
-
*/
|
|
16
|
-
const walk = (items, visit, decide) => new Promise((resolve, reject) => {
|
|
17
|
-
const iterator = items[Symbol.iterator]();
|
|
18
|
-
let index = 0;
|
|
19
|
-
const fail = (error) => {
|
|
20
|
-
try {
|
|
21
|
-
close(iterator);
|
|
22
|
-
}
|
|
23
|
-
catch { /* the failure being reported wins, as it does in a for...of */ }
|
|
24
|
-
reject(error);
|
|
25
|
-
};
|
|
26
|
-
const stop = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
close(iterator);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
reject(error);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
resolve(value);
|
|
35
|
-
};
|
|
36
|
-
const advance = () => {
|
|
37
|
-
let step, pending;
|
|
38
|
-
try {
|
|
39
|
-
step = iterator.next();
|
|
40
|
-
if (step.done) {
|
|
41
|
-
resolve(undefined);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
pending = visit(step.value, index++);
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
if (step === undefined || step.done)
|
|
48
|
-
reject(error);
|
|
49
|
-
else
|
|
50
|
-
fail(error);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const item = step.value;
|
|
54
|
-
Promise.resolve(pending).then((outcome) => {
|
|
55
|
-
let box;
|
|
56
|
-
try {
|
|
57
|
-
box = decide(outcome, item);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
fail(error);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (box)
|
|
64
|
-
stop(box.value);
|
|
65
|
-
else
|
|
66
|
-
advance();
|
|
67
|
-
}, fail);
|
|
68
|
-
};
|
|
69
|
-
advance();
|
|
70
|
-
});
|
|
71
|
-
const never = () => undefined;
|
|
72
|
-
/** `for (const x of items) await fn(x, index)`: resolves undefined once every item has run, one at a time. */
|
|
73
|
-
export const eachInOrder = (items, fn) => walk(items, fn, never);
|
|
74
|
-
/** The sequential map: `fn(x, index)` for each item in turn, resolving the results in item order. */
|
|
75
|
-
export const mapInOrder = (items, fn) => {
|
|
76
|
-
const results = [];
|
|
77
|
-
return walk(items, fn, (outcome) => { results.push(outcome); return undefined; }).then(() => results);
|
|
78
|
-
};
|
|
79
|
-
/** The first item whose `predicate(x, index)` resolves truthy (undefined when none); later items never run. */
|
|
80
|
-
export const findInOrder = (items, predicate) => walk(items, predicate, (outcome, item) => (outcome ? { value: item } : undefined));
|
|
81
|
-
/**
|
|
82
|
-
* `for (;;) await step(attempt)`: `step(attempt)` runs again, after the previous run settled, until it resolves
|
|
83
|
-
* something other than undefined; that value (null included) is the result. A poll or retry returns undefined to go
|
|
84
|
-
* on and its answer to stop. `attempt` counts from 0.
|
|
85
|
-
*/
|
|
86
|
-
export const repeatInOrder = (step) => walk(forever(), step, (outcome) => (outcome === undefined ? undefined : { value: outcome }));
|
|
87
|
-
function* forever() {
|
|
88
|
-
for (let attempt = 0;; attempt++)
|
|
89
|
-
yield attempt;
|
|
90
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// json-clone.mjs — a deep copy that keeps exactly what survives a JSON text and nothing else: the plain-data
|
|
2
|
-
// copy of a value, detached from every reference, frozen state and class of the original. `structuredClone` keeps
|
|
3
|
-
// what JSON drops (undefined members, Dates, Maps, sparse holes) and refuses what JSON accepts (functions,
|
|
4
|
-
// `toJSON` objects), so it is not a substitute; this walks the value once under the JSON.stringify rules.
|
|
5
|
-
/** The boxed primitives JSON.stringify unwraps: recognised by the internal slot a valueOf call reads, as JSON does. */
|
|
6
|
-
const BOXED = [
|
|
7
|
-
{ slot: Number.prototype.valueOf, read: Number },
|
|
8
|
-
{ slot: String.prototype.valueOf, read: String },
|
|
9
|
-
{ slot: Boolean.prototype.valueOf, read: (box) => Boolean.prototype.valueOf.call(box) },
|
|
10
|
-
{ slot: BigInt.prototype.valueOf, read: (box) => BigInt.prototype.valueOf.call(box) },
|
|
11
|
-
];
|
|
12
|
-
/** Whether `value` carries the internal slot `slot` reads (a valueOf of that boxed type does not throw on it). */
|
|
13
|
-
const hasSlot = (slot, value) => {
|
|
14
|
-
try {
|
|
15
|
-
slot.call(value);
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
/** What JSON.stringify takes of `holder[key]`: the toJSON result when there is one, a boxed primitive unwrapped. */
|
|
23
|
-
const serialized = (holder, key) => {
|
|
24
|
-
let value = holder[key];
|
|
25
|
-
if (value !== null && (typeof value === 'object' || typeof value === 'bigint') && typeof value.toJSON === 'function')
|
|
26
|
-
value = value.toJSON(key);
|
|
27
|
-
if (value === null || typeof value !== 'object')
|
|
28
|
-
return value;
|
|
29
|
-
const box = BOXED.find((candidate) => hasSlot(candidate.slot, value));
|
|
30
|
-
return box ? box.read(value) : value;
|
|
31
|
-
};
|
|
32
|
-
/** A member JSON leaves out of an object (and writes as null in an array). */
|
|
33
|
-
const isAbsent = (value) => value === undefined || typeof value === 'function' || typeof value === 'symbol';
|
|
34
|
-
const copyValue = (value, ancestors) => {
|
|
35
|
-
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
36
|
-
return value;
|
|
37
|
-
if (typeof value === 'number')
|
|
38
|
-
return Number.isFinite(value) ? value + 0 : null;
|
|
39
|
-
if (typeof value === 'bigint')
|
|
40
|
-
throw new TypeError('Do not know how to serialize a BigInt');
|
|
41
|
-
if (ancestors.includes(value))
|
|
42
|
-
throw new TypeError('Converting circular structure to JSON');
|
|
43
|
-
const inside = [...ancestors, value];
|
|
44
|
-
if (Array.isArray(value)) {
|
|
45
|
-
return Array.from({ length: value.length }, (_, index) => {
|
|
46
|
-
const item = serialized(value, String(index));
|
|
47
|
-
return isAbsent(item) ? null : copyValue(item, inside);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const holder = value;
|
|
51
|
-
const entries = [];
|
|
52
|
-
for (const name of Object.keys(holder)) {
|
|
53
|
-
const member = serialized(holder, name);
|
|
54
|
-
if (!isAbsent(member))
|
|
55
|
-
entries.push([name, copyValue(member, inside)]);
|
|
56
|
-
}
|
|
57
|
-
return Object.fromEntries(entries);
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* `value` copied as JSON data: members that are undefined, functions or symbols are dropped (an array item becomes
|
|
61
|
-
* null), non-finite numbers become null and -0 becomes 0, `toJSON` results replace their objects (a Date becomes its ISO string), boxed
|
|
62
|
-
* primitives unwrap, and a cycle or a BigInt throws a TypeError. A value JSON has no text for (undefined, a function,
|
|
63
|
-
* a symbol) throws a SyntaxError, as parsing the missing text does.
|
|
64
|
-
*/
|
|
65
|
-
export function jsonClone(value) {
|
|
66
|
-
const top = serialized({ '': value }, '');
|
|
67
|
-
if (isAbsent(top))
|
|
68
|
-
throw new SyntaxError('"undefined" is not valid JSON');
|
|
69
|
-
return copyValue(top, []);
|
|
70
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// json.mjs — the ledger's forgiving JSON read. Every one of these rows may hold text a peer wrote or a
|
|
2
|
-
// truncated payload, so a malformed column is the caller's fallback, never a throw. The parse of the
|
|
3
|
-
// literal 'null' is kept as null (callers that want {} instead write `parseJsonOr`).
|
|
4
|
-
import { readParsedFile } from './read-text.mjs';
|
|
5
|
-
/** `text` as JSON, or `fallback` when it does not parse. */
|
|
6
|
-
// reason: JSON parsed from a ledger column or file is an untyped input boundary; each caller narrows what it reads.
|
|
7
|
-
export const parseJson = (text, fallback = null) => {
|
|
8
|
-
try {
|
|
9
|
-
return JSON.parse(text);
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
return fallback;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
/** `text` as JSON, or `fallback` when it does not parse OR parses to null/undefined. Rows written
|
|
16
|
-
* as the literal 'null' read back as the fallback too, so a caller that wants an object gets one. */
|
|
17
|
-
// reason: same parsed-JSON boundary as parseJson.
|
|
18
|
-
export const parseJsonOr = (text, fallback = {}) => parseJson(text) ?? fallback;
|
|
19
|
-
/** A jobs/events row spread with `payload`: the row's payload_json parsed via parseJsonOr
|
|
20
|
-
* (`fallback` defaults to {}). Pass fallback null to keep a raw parseJson result, nulls included. */
|
|
21
|
-
// reason: same parsed-JSON boundary as parseJson.
|
|
22
|
-
export const withPayload = (row, fallback = {}) => (row ? { ...row, payload: parseJsonOr(row.payload_json, fallback) } : row);
|
|
23
|
-
/** `file` read and parsed as JSON, or `fallback` when the file is missing, unreadable or malformed. */
|
|
24
|
-
// reason: same parsed-JSON boundary as parseJson.
|
|
25
|
-
export const readJsonFile = (file, fallback = null) => readParsedFile(file, JSON.parse, fallback);
|
|
26
|
-
/** `stdout` as JSON: the trimmed text, else its first-{-to-last-} span; null when neither parses. */
|
|
27
|
-
// reason: same parsed-JSON boundary as parseJson.
|
|
28
|
-
export const jsonFromStdout = (stdout) => {
|
|
29
|
-
const text = String(stdout ?? '').trim();
|
|
30
|
-
if (!text)
|
|
31
|
-
return null;
|
|
32
|
-
try {
|
|
33
|
-
return JSON.parse(text);
|
|
34
|
-
}
|
|
35
|
-
catch { /* fall through */ }
|
|
36
|
-
const first = text.indexOf('{'), last = text.lastIndexOf('}');
|
|
37
|
-
if (first >= 0 && last > first) {
|
|
38
|
-
try {
|
|
39
|
-
return JSON.parse(text.slice(first, last + 1));
|
|
40
|
-
}
|
|
41
|
-
catch { /* not json */ }
|
|
42
|
-
}
|
|
43
|
-
return null;
|
|
44
|
-
};
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
// language.mjs - the one home of "is this text English?" for source, comments, tests and docs (HFS_LANGUAGE_NOT_ENGLISH,
|
|
2
|
-
// BE_SOURCE_FORM, FE_SOURCE_FORM). Shared by the architecture machine (docs) and by both lint canons (each ships a byte
|
|
3
|
-
// copy in its runtime/ bundle, kept by scripts/hfs/sync-runtime.mjs).
|
|
4
|
-
//
|
|
5
|
-
// Detection is structural on characters, never a word list: the letters Vietnamese adds to the Latin alphabet (a-breve, a-circumflex,
|
|
6
|
-
// d-stroke, e-circumflex, o-circumflex, o-horn, u-horn) and every vowel carrying a tone mark. Text is folded to NFC first, so a
|
|
7
|
-
// decomposed spelling (base letter + combining mark) is caught exactly like the precomposed one, and a loanword such as
|
|
8
|
-
// `naive`, `facade` or `Muller` (no tone mark, no Vietnamese letter) is never a hit.
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
/** One Vietnamese letter, precomposed (NFC): the Vietnamese-specific base letters, tone-marked vowels and the Latin Extended Additional block. */
|
|
11
|
-
export const SECOND_LANGUAGE_LETTER = /[À-ÃÈ-ÊÌÍÒ-ÕÙÚÝà-ãè-êìíò-õùúýĂăĐđĨĩŨũƠơƯưẠ-ỿ]/;
|
|
12
|
-
/** Whether `text` holds a Vietnamese letter, in NFC or NFD spelling. */
|
|
13
|
-
export const hasSecondLanguage = (text) => typeof text === 'string' && SECOND_LANGUAGE_LETTER.test(text.normalize('NFC'));
|
|
14
|
-
/** Every line of `text` with a Vietnamese letter: `[{ line, column }]`, both 1-based. */
|
|
15
|
-
function secondLanguageHits(text) {
|
|
16
|
-
const hits = [];
|
|
17
|
-
String(text).split(/\r?\n/).forEach((raw, index) => {
|
|
18
|
-
const match = SECOND_LANGUAGE_LETTER.exec(raw.normalize('NFC'));
|
|
19
|
-
if (match)
|
|
20
|
-
hits.push({ line: index + 1, column: match.index + 1 });
|
|
21
|
-
});
|
|
22
|
-
return hits;
|
|
23
|
-
}
|
|
24
|
-
/** The named bindings of an import from the backend message catalog contract. */
|
|
25
|
-
function messageCatalogBindings(ts, statement) {
|
|
26
|
-
if (!ts.isImportDeclaration(statement) || statement.moduleSpecifier.text !== '@modules/platform/i18n')
|
|
27
|
-
return null;
|
|
28
|
-
return statement.importClause?.namedBindings ?? null;
|
|
29
|
-
}
|
|
30
|
-
/** The local type names imported from the backend message catalog contract. */
|
|
31
|
-
function messageBundleImports(ts, source) {
|
|
32
|
-
const named = new Set();
|
|
33
|
-
const namespaces = new Set();
|
|
34
|
-
for (const statement of source.statements) {
|
|
35
|
-
const bindings = messageCatalogBindings(ts, statement);
|
|
36
|
-
if (!bindings)
|
|
37
|
-
continue;
|
|
38
|
-
if (ts.isNamespaceImport(bindings))
|
|
39
|
-
namespaces.add(bindings.name.text);
|
|
40
|
-
for (const entry of ts.isNamedImports(bindings) ? bindings.elements : []) {
|
|
41
|
-
if ((entry.propertyName ?? entry.name).text === 'MessageBundle')
|
|
42
|
-
named.add(entry.name.text);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return { named, namespaces };
|
|
46
|
-
}
|
|
47
|
-
/** A declaration that introduces a same-named local type or namespace. */
|
|
48
|
-
function declaresTypeName(ts, statement, name) {
|
|
49
|
-
if (statement.name?.text !== name)
|
|
50
|
-
return false;
|
|
51
|
-
return [ts.isTypeAliasDeclaration, ts.isInterfaceDeclaration, ts.isClassDeclaration, ts.isEnumDeclaration, ts.isModuleDeclaration]
|
|
52
|
-
.some(predicate => predicate(statement));
|
|
53
|
-
}
|
|
54
|
-
/** A type reference bound to the imported MessageBundle contract, including import aliases. */
|
|
55
|
-
function isMessageBundleType(ts, type, imports) {
|
|
56
|
-
if (!type || !ts.isTypeReferenceNode(type))
|
|
57
|
-
return false;
|
|
58
|
-
const name = type.typeName;
|
|
59
|
-
if (ts.isIdentifier(name))
|
|
60
|
-
return imports.named.has(name.text) && !shadowsImportedType(ts, type, name.text);
|
|
61
|
-
return ts.isQualifiedName(name) && ts.isIdentifier(name.left)
|
|
62
|
-
&& imports.namespaces.has(name.left.text) && name.right.text === 'MessageBundle' && !shadowsImportedType(ts, type, name.left.text);
|
|
63
|
-
}
|
|
64
|
-
/** A local declaration or generic type parameter takes precedence over a same-named import. */
|
|
65
|
-
function shadowsImportedType(ts, node, name) {
|
|
66
|
-
for (let scope = node.parent; scope; scope = scope.parent) {
|
|
67
|
-
const scoped = scope;
|
|
68
|
-
if (scoped.typeParameters?.some(parameter => parameter.name.text === name))
|
|
69
|
-
return true;
|
|
70
|
-
if (scoped.statements?.some(statement => declaresTypeName(ts, statement, name)))
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
/** The literal object supplied by a variable typed with the imported MessageBundle contract. */
|
|
76
|
-
function messageCatalogObject(ts, node, imports) {
|
|
77
|
-
if (!ts.isVariableDeclaration(node) || !node.initializer)
|
|
78
|
-
return null;
|
|
79
|
-
let value = node.initializer;
|
|
80
|
-
const type = ts.isSatisfiesExpression(value) ? value.type : node.type;
|
|
81
|
-
if (ts.isSatisfiesExpression(value))
|
|
82
|
-
value = value.expression;
|
|
83
|
-
return isMessageBundleType(ts, type, imports) && ts.isObjectLiteralExpression(value) ? value : null;
|
|
84
|
-
}
|
|
85
|
-
/** Literal string values in the Vietnamese locale of one message catalog. */
|
|
86
|
-
function vietnameseValueRanges(ts, catalog, source) {
|
|
87
|
-
const ranges = [];
|
|
88
|
-
for (const locale of catalog.properties) {
|
|
89
|
-
if (!ts.isPropertyAssignment(locale) || locale.name.text !== 'vi' || !ts.isObjectLiteralExpression(locale.initializer))
|
|
90
|
-
continue;
|
|
91
|
-
for (const message of locale.initializer.properties) {
|
|
92
|
-
if (ts.isPropertyAssignment(message) && ts.isStringLiteralLike(message.initializer))
|
|
93
|
-
ranges.push({ start: message.initializer.getStart(source), end: message.initializer.end });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return ranges;
|
|
97
|
-
}
|
|
98
|
-
/** Literal Vietnamese message values of typed catalogs; keys, comments, English values and expressions remain source. */
|
|
99
|
-
function messageBundleValueRanges(ts, source) {
|
|
100
|
-
const imports = messageBundleImports(ts, source);
|
|
101
|
-
const ranges = [];
|
|
102
|
-
const visit = (node) => {
|
|
103
|
-
const catalog = messageCatalogObject(ts, node, imports);
|
|
104
|
-
if (catalog)
|
|
105
|
-
ranges.push(...vietnameseValueRanges(ts, catalog, source));
|
|
106
|
-
ts.forEachChild(node, visit);
|
|
107
|
-
};
|
|
108
|
-
visit(source);
|
|
109
|
-
return ranges;
|
|
110
|
-
}
|
|
111
|
-
/** Source-language hits, treating only literal vi values of typed backend MessageBundle objects as translated product data. */
|
|
112
|
-
export function sourceLanguageHits(rel, text, ts) {
|
|
113
|
-
if (!hasSecondLanguage(text))
|
|
114
|
-
return [];
|
|
115
|
-
if (!ts || !/\.[cm]?tsx?$/.test(rel))
|
|
116
|
-
return secondLanguageHits(text);
|
|
117
|
-
const source = ts.createSourceFile(rel, text, ts.ScriptTarget.Latest, true);
|
|
118
|
-
let sourceText = text;
|
|
119
|
-
for (const range of messageBundleValueRanges(ts, source).sort((left, right) => right.start - left.start)) {
|
|
120
|
-
sourceText = sourceText.slice(0, range.start) + sourceText.slice(range.start, range.end).replace(/[^\r\n]/g, ' ') + sourceText.slice(range.end);
|
|
121
|
-
}
|
|
122
|
-
return secondLanguageHits(sourceText);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* The Vietnamese fields of one failure-code entry: the operator text the owner mandated for the failure-code catalog
|
|
126
|
-
* (scripts/checks/check-failure-codes.mjs types the entry with exactly these). causes_vi is the list companion of the three scalar fields.
|
|
127
|
-
*/
|
|
128
|
-
export const FAILURE_CODE_VIETNAMESE_FIELDS = Object.freeze(['title_vi', 'meaning_vi', 'nextStep_vi', 'causes_vi']);
|
|
129
|
-
/**
|
|
130
|
-
* The fields of a document that carry deliberate Vietnamese text, keyed by file: a declared field-level exception of that file's
|
|
131
|
-
* typed content, never a path pattern over content. `fields` are block keys (the key's own value and its list items are exempt);
|
|
132
|
-
* `flowFields` are keys inside an inline flow map (`{ vi: ..., en: ... }`), where only that key's value is exempt. A Vietnamese
|
|
133
|
-
* value under any other key of the same file is still a finding.
|
|
134
|
-
* - modules/kernel/failure-codes.yaml: the operator text the owner mandated for the failure-code catalog.
|
|
135
|
-
* - modules/ops/_labels.yaml: the op-label catalogue, one `{ vi, en }` pair per op (the `vi` field is the localized label).
|
|
136
|
-
* - modules/goal/archetypes.yaml: the Vietnamese phrase lexicons matched against owner input (the signal phrase sets, and the
|
|
137
|
-
* phrase lists of the archetype recognisers).
|
|
138
|
-
* - modules/goal/source-phrases.yaml: the Vietnamese phrase lists runtime source matchers read through
|
|
139
|
-
* scripts/lib/source-phrases.mjs (owner replies, report wording, product copy) - each leaf list under `phrases`.
|
|
140
|
-
* An op manifest (modules/ops/ops/<id>.yaml, the starci/op@1 documents check-op-manifest types) is declared by
|
|
141
|
-
* OP_MANIFEST_VIETNAMESE_FIELDS: its text objects are {en, vi} (modules/schemas/op.schema.yaml $defs text), and `vi` is the
|
|
142
|
-
* owner's reading of the same rule.
|
|
143
|
-
*/
|
|
144
|
-
export const DECLARED_VIETNAMESE_FIELDS = Object.freeze({
|
|
145
|
-
'modules/kernel/failure-codes.yaml': Object.freeze({ fields: FAILURE_CODE_VIETNAMESE_FIELDS }),
|
|
146
|
-
'modules/ops/_labels.yaml': Object.freeze({ flowFields: Object.freeze(['vi']) }),
|
|
147
|
-
'modules/goal/archetypes.yaml': Object.freeze({
|
|
148
|
-
fields: Object.freeze([
|
|
149
|
-
'buildIntent', 'canonIntent', 'e2eIntent', 'uatIntent', 'proofNegation', 'proofStateCue', 'integrationIntent', 'brandIntent',
|
|
150
|
-
'phrases', 'requires', 'excludes', 'backend', 'frontend', 'package',
|
|
151
|
-
]),
|
|
152
|
-
}),
|
|
153
|
-
'modules/goal/source-phrases.yaml': Object.freeze({
|
|
154
|
-
fields: Object.freeze([
|
|
155
|
-
'prefer', 'avoid', 'only', 'negation', 'refused', 'accept', 'golden',
|
|
156
|
-
'missingPaths', 'grantTooNarrow', 'toolTimeout', 'testGap', 'checkerUnavailable',
|
|
157
|
-
'supervisorVerbs', 'ownerWord', 'orWord', 'beyondAuthority', 'ownerOnly', 'workerDied', 'contractConflict', 'decision',
|
|
158
|
-
'product', 'grammar', 'knowledge', 'sourceLabel', 'internalVocabulary', 'actor', 'success',
|
|
159
|
-
'wizard', 'form', 'dashboard', 'gap', 'anatomy', 'otpLabel',
|
|
160
|
-
]),
|
|
161
|
-
}),
|
|
162
|
-
});
|
|
163
|
-
/**
|
|
164
|
-
* The Vietnamese catalog of owner-visible messages (scripts/lib/i18n.mjs): modules/i18n/messages/<area>.yaml, a list of
|
|
165
|
-
* `{en, vi}` entries keyed from the English source. The `vi` field (block or inline flow) is the declared Vietnamese.
|
|
166
|
-
*/
|
|
167
|
-
const I18N_CATALOG_VIETNAMESE_FIELDS = Object.freeze({ fields: Object.freeze(['vi']), flowFields: Object.freeze(['vi']) });
|
|
168
|
-
const I18N_CATALOG_DIR = 'modules/i18n/messages/';
|
|
169
|
-
/** The `vi` field of an op manifest's text objects (modules/schemas/op.schema.yaml $defs text). */
|
|
170
|
-
const OP_MANIFEST_VIETNAMESE_FIELDS = Object.freeze({ fields: Object.freeze(['vi']) });
|
|
171
|
-
const OP_MANIFEST_DIR = 'modules/ops/ops/';
|
|
172
|
-
/** The declared Vietnamese fields of `rel`: its own entry, or the op-manifest text field for a manifest of modules/ops/ops. */
|
|
173
|
-
const declaredVietnameseFieldsOf = (rel) => DECLARED_VIETNAMESE_FIELDS[rel]
|
|
174
|
-
?? (rel.startsWith(I18N_CATALOG_DIR) && !rel.slice(I18N_CATALOG_DIR.length).includes('/') && /\.ya?ml$/.test(rel) ? I18N_CATALOG_VIETNAMESE_FIELDS : null)
|
|
175
|
-
?? (rel.startsWith(OP_MANIFEST_DIR) && !rel.slice(OP_MANIFEST_DIR.length).includes('/') && /\.ya?ml$/.test(rel) ? OP_MANIFEST_VIETNAMESE_FIELDS : null);
|
|
176
|
-
/**
|
|
177
|
-
* The slots whose files may carry another language, and why: a catalog is product copy in two languages, and an i18n
|
|
178
|
-
* fixture reproduces a real localized string a parser or formatter must accept. Placement is the whole marker - there is no
|
|
179
|
-
* comment pragma and no path pattern. The slots are declared in knowledge/hfs/slots.yaml.
|
|
180
|
-
*/
|
|
181
|
-
const LOCALIZED_TEXT_SLOTS = Object.freeze([
|
|
182
|
-
'be.domain.messages', 'be.feature.messages', 'be.tests.fixtures.i18n',
|
|
183
|
-
'fe.modules.i18n', 'fe.package.i18n',
|
|
184
|
-
]);
|
|
185
|
-
/** Whether a document (Markdown or YAML) of `slot` is exempt: only catalogue and fixture DATA (YAML) is; Markdown is prose and never is. */
|
|
186
|
-
export const isLocalizedDataFile = (rel, slot) => LOCALIZED_TEXT_SLOTS.includes(slot) && /\.ya?ml$/.test(rel);
|
|
187
|
-
/**
|
|
188
|
-
* The key each line of a YAML text belongs to: a `key:` line owns itself, and every deeper-indented line after it (a list item,
|
|
189
|
-
* a folded block, a wrapped scalar) belongs to the same key. A line at or above the key's indent that is not a key belongs to none.
|
|
190
|
-
*/
|
|
191
|
-
function yamlKeyOfEachLine(text) {
|
|
192
|
-
let key = null;
|
|
193
|
-
let keyIndent = -1;
|
|
194
|
-
return String(text).split(/\r?\n/).map((raw) => {
|
|
195
|
-
if (raw.trim() === '')
|
|
196
|
-
return key;
|
|
197
|
-
const indent = raw.length - raw.trimStart().length;
|
|
198
|
-
const own = /^(\s*(?:-\s+)?)([A-Za-z_][\w-]*)\s*:(?:\s|$)/.exec(raw);
|
|
199
|
-
if (own) {
|
|
200
|
-
key = own[2];
|
|
201
|
-
keyIndent = own[1].length;
|
|
202
|
-
return key;
|
|
203
|
-
}
|
|
204
|
-
// a list item may sit at the key's own indent (`key:` then `- item` at the same column)
|
|
205
|
-
if (indent > keyIndent || (indent === keyIndent && /^\s*-\s/.test(raw)))
|
|
206
|
-
return key;
|
|
207
|
-
key = null;
|
|
208
|
-
keyIndent = -1;
|
|
209
|
-
return null;
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
/** The Vietnamese hits of a document, minus the declared field-level exceptions of `rel` (a repository-relative POSIX path). */
|
|
213
|
-
export function documentLanguageHits(rel, text) {
|
|
214
|
-
const declared = declaredVietnameseFieldsOf(rel);
|
|
215
|
-
const hits = secondLanguageHits(text);
|
|
216
|
-
if (!declared)
|
|
217
|
-
return hits;
|
|
218
|
-
const keys = yamlKeyOfEachLine(text);
|
|
219
|
-
const lines = String(text).split(/\r?\n/);
|
|
220
|
-
return hits.filter((hit) => {
|
|
221
|
-
if (declared.fields?.includes(keys[hit.line - 1] ?? ''))
|
|
222
|
-
return false;
|
|
223
|
-
if (!declared.flowFields)
|
|
224
|
-
return true;
|
|
225
|
-
// an inline flow map: drop the declared fields' values and judge what is left of the line
|
|
226
|
-
const rest = declared.flowFields.reduce((line, field) => line.replace(new RegExp(String.raw `\b${field}\s*:\s*(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^,}]*)`, 'g'), ''), lines[hit.line - 1]);
|
|
227
|
-
return hasSecondLanguage(rest);
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
/** The file extensions of a prose document (Markdown and YAML). */
|
|
231
|
-
const DOCUMENT_EXTENSIONS = Object.freeze(['.md', '.yaml', '.yml']);
|
|
232
|
-
/** Whether `rel` is a document a language check reads. */
|
|
233
|
-
export const isDocument = (rel) => DOCUMENT_EXTENSIONS.includes(path.posix.extname(rel));
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// list.mjs — the array-or-empty coercion half the scripts re-declared by hand.
|
|
2
|
-
// `v` when it already is an array, else []. Scalars are NOT wrapped: a caller that wants
|
|
3
|
-
// `[v]` for a lone value writes its own coercion (see contract-version's list).
|
|
4
|
-
export const list = (v) => (Array.isArray(v) ? v : []);
|
|
5
|
-
/** `v` as an array: itself when already one, [] for null/undefined, else [v]. */
|
|
6
|
-
export const asList = (v) => {
|
|
7
|
-
if (Array.isArray(v))
|
|
8
|
-
return v;
|
|
9
|
-
if (v == null)
|
|
10
|
-
return [];
|
|
11
|
-
return [v];
|
|
12
|
-
};
|
|
13
|
-
/** The object entries of `v` (a non-array reads as []). */
|
|
14
|
-
export const objectList = (v) => (Array.isArray(v) ? v : []).filter((item) => item && typeof item === 'object');
|
|
15
|
-
/** Every entry of `v` a non-empty string (`blank: false` also rejects all-whitespace entries). */
|
|
16
|
-
export const stringList = (v, { blank = true } = {}) => Array.isArray(v) && v.every((s) => typeof s === 'string' && s.length > 0 && (blank || s.trim().length > 0));
|
|
17
|
-
/** A non-empty list of distinct values, all accepted by the supplied predicate. */
|
|
18
|
-
export const nonemptyUniqueList = (values, accepts) => Array.isArray(values) && values.length > 0
|
|
19
|
-
&& values.every((entry) => accepts(entry)) && new Set(values).size === values.length;
|
|
20
|
-
/** The items of a `sep`-separated list: trimmed, empties dropped; `dedupe` keeps first occurrences only. */
|
|
21
|
-
export const splitList = (v, { sep = ',', dedupe = false } = {}) => {
|
|
22
|
-
const items = String(v ?? '').split(sep).map((s) => s.trim()).filter(Boolean);
|
|
23
|
-
return dedupe ? [...new Set(items)] : items;
|
|
24
|
-
};
|
|
25
|
-
// The comparator of a bare `sort()` (UTF-16 code-unit order) is owned by the engine, which cannot import scripts/lib.
|
|
26
|
-
export { byCodeUnit } from '../../engine/by-code-unit.mjs';
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// mutation-fence.mjs — ephemeral admission carried through awaited work, never a state store.
|
|
2
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
-
const scope = new AsyncLocalStorage();
|
|
4
|
-
/** Run one admitted call; the checker is synchronous and reads its existing durable owners again. */
|
|
5
|
-
export const withMutationFence = (check, authority, fn) => scope.run({ check, authority, checking: false }, fn);
|
|
6
|
-
/** Recheck after the actual transaction lock or immediately before a native effect. */
|
|
7
|
-
export function assertMutationFence(boundary) {
|
|
8
|
-
const current = scope.getStore();
|
|
9
|
-
if (!current || current.checking)
|
|
10
|
-
return;
|
|
11
|
-
current.checking = true;
|
|
12
|
-
try {
|
|
13
|
-
current.check(boundary);
|
|
14
|
-
}
|
|
15
|
-
finally {
|
|
16
|
-
current.checking = false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/** Identity stamped by existing write owners, never accepted from a command argument. */
|
|
20
|
-
export const mutationAuthority = () => scope.getStore()?.authority ?? null;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// scripts/lib/package-at.mjs — a package the runtime does not ship (playwright, esbuild, tailwindcss) comes from the
|
|
2
|
-
// project that owns it: node resolution from that project's directory, walking up its node_modules.
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
import { skillRoot } from '../../engine/runtime-root.mjs';
|
|
7
|
-
|
|
8
|
-
/** The package.json of `name` as resolved from `dir`, or null. */
|
|
9
|
-
export const packageAt = (dir, name) => {
|
|
10
|
-
try { return createRequire(path.join(dir, 'package.json')).resolve(`${name}/package.json`); } catch { return null; }
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/** This runtime's own `starci` bin (packages/cli is the only package that declares one). */
|
|
14
|
-
const RUNTIME_STARCI_BIN = path.join(skillRoot, 'packages', 'cli', 'bin', 'starci.mjs');
|
|
15
|
-
|
|
16
|
-
/** The `starci` bin of the starci-harness that `dir` installs (a product runs its own pinned CLI), else this runtime's own. */
|
|
17
|
-
function starciBin(dir) {
|
|
18
|
-
const packageFile = packageAt(dir, 'starci-harness');
|
|
19
|
-
if (packageFile) {
|
|
20
|
-
try {
|
|
21
|
-
const { bin } = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
|
22
|
-
const rel = typeof bin === 'string' ? bin : bin?.starci;
|
|
23
|
-
const file = rel ? path.join(path.dirname(packageFile), rel) : null;
|
|
24
|
-
if (file && fs.existsSync(file)) return file;
|
|
25
|
-
} catch { /* an unreadable install falls back to the runtime's own CLI */ }
|
|
26
|
-
}
|
|
27
|
-
return RUNTIME_STARCI_BIN;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** The first of `names` resolvable from the first of `dirs` that has one: {name, root, packageFile, version} or null. */
|
|
31
|
-
export function findPackage(dirs, names) {
|
|
32
|
-
for (const dir of dirs.filter(Boolean)) {
|
|
33
|
-
for (const name of names) {
|
|
34
|
-
const packageFile = packageAt(dir, name);
|
|
35
|
-
if (!packageFile) continue;
|
|
36
|
-
const require = createRequire(packageFile);
|
|
37
|
-
return { name, root: path.dirname(packageFile), packageFile, version: require(packageFile).version };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** The CommonJS entry of a package found by findPackage. */
|
|
44
|
-
export const requirePackage = (found) => createRequire(found.packageFile)(found.name);
|
|
45
|
-
|
|
46
|
-
/** The TypeScript compiler resolvable from the first of `dirs` (an app root, then the caller's own), or null. */
|
|
47
|
-
export const loadTypescript = (...dirs) => {
|
|
48
|
-
const located = findPackage(dirs, ['typescript']);
|
|
49
|
-
return located ? requirePackage(located) : null;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The app's command line and the app implementation behind it: `bin` the `starci` bin of the app's installed starci-harness, else
|
|
54
|
-
* this runtime's packages/cli/bin/starci.mjs (starciBin); `dir` the @starci/hfs that answers
|
|
55
|
-
* `starci app` - the app's own install, else the one beside its starci-harness, else this runtime's packages/hfs - whose runtime
|
|
56
|
-
* slice the gate's base lint (scripts/gates/gate.mjs) and the READ digest (scripts/gates/read-digest.mjs) load in-process.
|
|
57
|
-
*/
|
|
58
|
-
export function hfsEntry(root) {
|
|
59
|
-
const cli = packageAt(root, 'starci-harness');
|
|
60
|
-
const manifest = packageAt(root, '@starci/hfs') ?? (cli && packageAt(path.dirname(cli), '@starci/hfs'));
|
|
61
|
-
return { dir: manifest ? path.dirname(manifest) : path.join(skillRoot, 'packages', 'hfs'), bin: starciBin(root) };
|
|
62
|
-
}
|