@supa-media/tex-contract 0.2.7 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Containing a string somebody else chose, where the app speaks in its own
3
+ * voice.
4
+ *
5
+ * ## The property, and why it is containment rather than cleaning
6
+ *
7
+ * Three different inputs reach the console's own chrome: a note path out of a
8
+ * bucket we do not own, a display name out of a presence room, and text a
9
+ * plugin chose. All three are drawn beside Context's own words — the status
10
+ * bar, the breadcrumb, a card next to the Stop button — and a bidi override
11
+ * inside any of them reverses the rendering of *everything after it*, which
12
+ * includes the app's own labels.
13
+ *
14
+ * There are two ways to answer that and they are not equally strong:
15
+ *
16
+ * - **Stripping is a blocklist.** It works exactly as far as the list of
17
+ * hostile characters reaches, and every character nobody enumerated passes
18
+ * through. Two lists in this repository prove the point: one spells the
19
+ * class `[\p{Cc}\p{Cf}]` and misses U+2028 LINE SEPARATOR, which is `Zl`;
20
+ * the other spells it as hand-written ranges and misses U+061C ARABIC
21
+ * LETTER MARK — a character the bidi algorithm acts on — along with the
22
+ * U+FFF9–FFFB annotation set.
23
+ * - **Isolating is a whitelist of structure.** The value arrives inside a
24
+ * container the bidi algorithm cannot be talked out of: whatever is in
25
+ * there resolves its own direction and cannot reach the text around it.
26
+ * Characters nobody enumerated are contained too, because containment does
27
+ * not depend on recognising them.
28
+ *
29
+ * So this isolates. What it removes, it removes only where an isolate
30
+ * *cannot* do the job.
31
+ *
32
+ * ## What isolation does and does not buy, stated rather than implied
33
+ *
34
+ * **Buys:** a hostile value cannot reorder, reverse or relocate anything
35
+ * outside itself. The label beside it, the version, the word "Private", the
36
+ * Stop button's row — none of them can be made to render as something else by
37
+ * a character inside somebody's filename.
38
+ *
39
+ * **Does not buy:** a value can still misrender *itself*. `sei<RLO>fdp.md`
40
+ * inside an isolate is still a name that reads back to front. Making the value
41
+ * render truthfully means altering it, and for a path that is the wrong trade
42
+ * — the path in the status bar is also the path somebody copies out of it, so
43
+ * a displayed value that differs from the real key is its own defect. Where
44
+ * altering it IS right, because nothing downstream copies the value, the
45
+ * caller strips first and isolates after; `shareTitle.ts` is that case and
46
+ * keeps its strip.
47
+ *
48
+ * ## The two removals, and why each is not an exception to the rule
49
+ *
50
+ * 1. **`\p{Cc}`, U+2028 and U+2029 are removed.** A C0 control, DEL, a line
51
+ * separator and a paragraph separator have no rendering to contain — they
52
+ * break the line the label sits on, inside an isolate as readily as outside
53
+ * one. An isolate is the wrong instrument rather than a weaker one.
54
+ * 2. **U+2069 PDI and U+202C PDF are removed.** These are the *pops*: a PDI
55
+ * inside the value closes the container early and hands the rest of the
56
+ * string the reach this function exists to deny. A container that the
57
+ * contents can end is not a container. Nothing legitimate is lost, because
58
+ * a pop with nothing to pop has no effect in the first place — every
59
+ * embedding the value opens is closed by the PDI this appends.
60
+ *
61
+ * Both are what makes the isolate *hold*, which is why they live here and not
62
+ * in a list each caller keeps.
63
+ *
64
+ * ## Why this is a `.cjs` file in `packages/shared`
65
+ *
66
+ * Its callers include `packages/obsidian-runtime`, which has **no
67
+ * dependencies** by construction, and the gateway, which has none either.
68
+ * Neither can import this package's TypeScript. The same reasoning put
69
+ * `storageLayout.cjs` and `activity.cjs` here, and those are imported by
70
+ * relative path from the zero-dependency halves of the product. A second copy
71
+ * of this rule in each of them is the drift this file exists to end.
72
+ */
73
+
74
+ /** FIRST STRONG ISOLATE — opens a container whose direction is its own. */
75
+ const FIRST_STRONG_ISOLATE = "\u2068";
76
+ /** POP DIRECTIONAL ISOLATE — closes it. */
77
+ const POP_DIRECTIONAL_ISOLATE = "\u2069";
78
+ /** POP DIRECTIONAL FORMATTING — closes an *embedding*, and escapes ours. */
79
+ const POP_DIRECTIONAL_FORMATTING = "\u202c";
80
+
81
+ /**
82
+ * Characters an isolate cannot contain, so they are removed instead.
83
+ *
84
+ * `\p{Cc}` is C0 and DEL. U+2028 and U+2029 are `Zl`/`Zp` — the reason they
85
+ * are named separately is that the `[\p{Cc}\p{Cf}]` spelling elsewhere in this
86
+ * repository does not cover them, and a line separator in a status bar label
87
+ * is a broken layout whichever category it belongs to.
88
+ */
89
+ const UNCONTAINABLE = /[\p{Cc}\p{Zl}\p{Zp}]/gu;
90
+
91
+ /** The two pops, which would end the container from inside it. */
92
+ const POPS = /[\u2069\u202c]/gu;
93
+
94
+ /** Any format character. If one survives the removals, the value is contained. */
95
+ const FORMAT_CHARACTER = /\p{Cf}/u;
96
+
97
+ /**
98
+ * Remove what an isolate cannot contain.
99
+ *
100
+ * Exported on its own because a caller that has already decided to *alter* the
101
+ * value — a share card's title, where nothing downstream copies it — still
102
+ * wants this half, and wants it from here rather than from a regex of its own.
103
+ *
104
+ * @param {unknown} value
105
+ * @returns {string}
106
+ */
107
+ function stripUncontainable(value) {
108
+ return typeof value === "string" ? value.replace(UNCONTAINABLE, "") : "";
109
+ }
110
+
111
+ /**
112
+ * The value, contained, so nothing in it can reach the app's own words.
113
+ *
114
+ * **A string with nothing to contain comes back byte-identical**, deliberately:
115
+ * almost every path, name and label is ordinary text, and wrapping all of them
116
+ * would put two invisible characters into every comparison, every snapshot and
117
+ * everything somebody copies, to no end. The container appears exactly where
118
+ * there is something to hold.
119
+ *
120
+ * Call it at the point the value is known to be *display* — after any length
121
+ * cap the caller applies, so the cap measures the text rather than the
122
+ * container.
123
+ *
124
+ * @param {unknown} value
125
+ * @returns {string}
126
+ */
127
+ function isolateForDisplay(value) {
128
+ const cleaned = stripUncontainable(value).replace(POPS, "");
129
+ if (cleaned === "" || !FORMAT_CHARACTER.test(cleaned)) return cleaned;
130
+ return `${FIRST_STRONG_ISOLATE}${cleaned}${POP_DIRECTIONAL_ISOLATE}`;
131
+ }
132
+
133
+ module.exports = {
134
+ FIRST_STRONG_ISOLATE,
135
+ POP_DIRECTIONAL_ISOLATE,
136
+ POP_DIRECTIONAL_FORMATTING,
137
+ isolateForDisplay,
138
+ stripUncontainable,
139
+ };
@@ -17,6 +17,14 @@
17
17
  * (deletes both). Moving `expires` later is allowed only within the same
18
18
  * limit from `added`, so a flag cannot be kept forever by editing its date.
19
19
  *
20
+ * ## On for staff in code
21
+ *
22
+ * `staff: true` turns a flag on for staff (the verified `ADMIN_EMAILS`
23
+ * addresses) before anyone else, as a launch pull request, not a console
24
+ * press. The console's row still wins: `people` and `everyone` widen it as
25
+ * always, and a row set to `off` turns it off for staff too, which is the
26
+ * rollback short of a revert. Read by `apps/convex/functions/lib/featureFlags.ts`.
27
+ *
20
28
  * ## Ids
21
29
  *
22
30
  * `area.name`, lower case words joined by hyphens (`tex.conversation-threads`).
@@ -57,12 +65,26 @@ const FLAGS = Object.freeze({
57
65
  description: "The app saves whole notes through the gateway into the workspace object, not through Convex.",
58
66
  added: "2026-11-24",
59
67
  expires: "2027-02-21",
68
+ staff: true,
60
69
  },
61
70
  "files.app-reads-in-objects": {
62
71
  label: "App reads in objects",
63
72
  description: "The app's previews, peeks, mail and admin note reads go through the gateway to the workspace object, not through Convex.",
64
73
  added: "2026-11-29",
65
74
  expires: "2027-02-26",
75
+ staff: true,
76
+ },
77
+ "files.app-trash-list-in-objects": {
78
+ label: "Trash list in objects",
79
+ description: "The app's Trash page lists the trash from the workspace object through the gateway, not from Convex.",
80
+ added: "2026-11-29",
81
+ expires: "2027-02-26",
82
+ },
83
+ "notes.app-visibility-in-objects": {
84
+ label: "App visibility in objects",
85
+ description: "The app changes a note's visibility through the gateway in the workspace object, not through Convex.",
86
+ added: "2026-11-29",
87
+ expires: "2027-02-26",
66
88
  },
67
89
  "shares.shared-with-me-in-objects": {
68
90
  label: "Shared with me from objects",
@@ -70,6 +92,18 @@ const FLAGS = Object.freeze({
70
92
  added: "2026-11-29",
71
93
  expires: "2027-02-26",
72
94
  },
95
+ "files.share-cards-in-objects": {
96
+ label: "Share cards and access lists from objects",
97
+ description: "A share link finds its note, and the share dialog reads who has access, from the workspace object instead of Convex's tree copy.",
98
+ added: "2026-11-29",
99
+ expires: "2027-02-26",
100
+ },
101
+ "shares.granted-in-objects": {
102
+ label: "Granted notes judged in objects",
103
+ description: "A note or folder granted to somebody outside the workspace is judged and read in the workspace object, not from Convex's copy of the rows.",
104
+ added: "2026-11-29",
105
+ expires: "2027-02-26",
106
+ },
73
107
  });
74
108
 
75
109
  const FLAG_MODES = Object.freeze(["off", "people", "everyone"]);
@@ -109,6 +143,7 @@ function flagProblems(flags, today) {
109
143
  }
110
144
  if (typeof flag.label !== "string" || flag.label.trim() === "") problems.push(`${id}: needs a label.`);
111
145
  if (typeof flag.description !== "string" || flag.description.trim() === "") problems.push(`${id}: needs a description.`);
146
+ if (flag.staff !== undefined && typeof flag.staff !== "boolean") problems.push(`${id}: staff is true or left out.`);
112
147
  const added = dayMs(flag.added);
113
148
  const expires = dayMs(flag.expires);
114
149
  if (Number.isNaN(added)) problems.push(`${id}: added must be a YYYY-MM-DD day.`);
@@ -9,6 +9,8 @@ export interface FlagInfo {
9
9
  added: string;
10
10
  /** `YYYY-MM-DD`, at most `MAX_FLAG_DAYS` after `added`. */
11
11
  expires: string;
12
+ /** On for staff unless the console's row is set to `off`. */
13
+ staff?: boolean;
12
14
  }
13
15
 
14
16
  export declare const FLAGS: Readonly<Record<string, FlagInfo>>;
@@ -3,25 +3,40 @@
3
3
  * (`infra/tex-runner`). A workflow job with `id-token: write` asks GitHub for a token naming the service as its
4
4
  * audience; GitHub signs it, and its claims say which repository, which workflow file at which ref, and which run
5
5
  * asked. Each service checks the signature against GitHub's published keys and then the claims, so only main's own
6
- * workflow for that door gets in. There is no secret to keep: a branch can dispatch `tex-test-set.yml` on itself,
6
+ * workflow for that door, in Context's or Tex's repository, gets in. There is no secret to keep: a branch can dispatch `tex-test-set.yml` on itself,
7
7
  * but then its token names `@refs/heads/<branch>`, and is refused.
8
8
  */
9
9
 
10
10
  export const ISSUER = "https://token.actions.githubusercontent.com";
11
11
  export const AUDIENCE = "context-tex-eval";
12
+ /** Context's repository, where these workflows have run until now. */
12
13
  export const REPOSITORY = "Supa-Media/context";
14
+ /**
15
+ * Tex's own repository (the clean split, 2026-11-29): Tex's workflows move there, and while they move each door takes
16
+ * its workflow from either repository, always only from that repository's main. No other repository, fork included.
17
+ */
18
+ export const TEX_REPOSITORY = "Supa-Media/tex";
19
+ export const REPOSITORIES = [REPOSITORY, TEX_REPOSITORY] as const;
13
20
  const JWKS_URL = `${ISSUER}/.well-known/jwks`;
14
21
 
15
- /** The workflows each door takes, as GitHub writes `job_workflow_ref`: the file on main and nowhere else. */
16
- export const WORKFLOWS = {
17
- run: `${REPOSITORY}/.github/workflows/tex-test-set.yml@refs/heads/main`,
18
- seed: `${REPOSITORY}/.github/workflows/tex-test-set-seed.yml@refs/heads/main`,
19
- "search-run": `${REPOSITORY}/.github/workflows/search-test-set.yml@refs/heads/main`,
20
- "search-seed": `${REPOSITORY}/.github/workflows/search-test-set-seed.yml@refs/heads/main`,
22
+ /** The workflow file each door takes. */
23
+ export const WORKFLOW_FILES = {
24
+ run: "tex-test-set.yml",
25
+ seed: "tex-test-set-seed.yml",
26
+ "search-run": "search-test-set.yml",
27
+ "search-seed": "search-test-set-seed.yml",
21
28
  // Not a door of this service: the Lab runner (infra/tex-runner) checks its own audience with this same code.
22
- "lab-runner": `${REPOSITORY}/.github/workflows/tex-lab-sandbox.yml@refs/heads/main`,
29
+ "lab-runner": "tex-lab-sandbox.yml",
23
30
  } as const;
24
- export type Door = keyof typeof WORKFLOWS;
31
+ export type Door = keyof typeof WORKFLOW_FILES;
32
+
33
+ /** A door's workflow as GitHub writes `job_workflow_ref`: the file on that repository's main and nowhere else. */
34
+ export const workflowRef = (repository: string, door: Door) => `${repository}/.github/workflows/${WORKFLOW_FILES[door]}@refs/heads/main`;
35
+
36
+ /** Each door's workflow in Context's repository (as before the split). */
37
+ export const WORKFLOWS = Object.fromEntries(Object.keys(WORKFLOW_FILES).map((door) => [door, workflowRef(REPOSITORY, door as Door)])) as Record<Door, string>;
38
+ /** Each door's workflow in Tex's repository. */
39
+ export const TEX_WORKFLOWS = Object.fromEntries(Object.keys(WORKFLOW_FILES).map((door) => [door, workflowRef(TEX_REPOSITORY, door as Door)])) as Record<Door, string>;
25
40
 
26
41
  export interface Claims {
27
42
  iss: string;
@@ -91,8 +106,11 @@ export async function verify(authorization: string | null, door: Door, keys: Key
91
106
  if (!aud.includes(audience)) throw new Refused("not meant for this service");
92
107
  if (!(claims.exp > s)) throw new Refused("expired");
93
108
  if (typeof claims.nbf === "number" && claims.nbf > s + 60) throw new Refused("not valid yet");
94
- if (claims.repository !== REPOSITORY) throw new Refused("not this repository");
95
- if (claims.job_workflow_ref !== WORKFLOWS[door] || claims.ref !== "refs/heads/main") throw new Refused(`only ${WORKFLOWS[door]} may use this door`);
109
+ if (!(REPOSITORIES as readonly string[]).includes(claims.repository)) throw new Refused("not this repository");
110
+ // The workflow must be the door's file in the same repository the token names, on its main.
111
+ if (claims.job_workflow_ref !== workflowRef(claims.repository, door) || claims.ref !== "refs/heads/main") {
112
+ throw new Refused(`only ${WORKFLOWS[door]} or ${TEX_WORKFLOWS[door]} may use this door`);
113
+ }
96
114
  if (!/^\d+$/.test(String(claims.run_id ?? ""))) throw new Refused("no run named");
97
115
  return claims;
98
116
  }
@@ -0,0 +1,158 @@
1
+ /**
2
+ * SEARCH'S CONFIG, AS EVERY RUNTIME READS IT (Dev2, 2026-11-21: "we can have like a texting config, text nightly
3
+ * config, and then search config because not only text users search").
4
+ *
5
+ * `searchConfig.json` holds every step a search runs (a node), its settings, and the wires between them, in the
6
+ * Lab's graph shape (the one Tex's `texConfig.json` uses). The gateway's search (`config/nodes.js`, run by the shared
7
+ * graph runner) and the defaults every other caller of the search code ranks by (`../ranking.js`, `../settings.js`)
8
+ * read it through this file only, so a config that does not match the schema below fails loudly at start instead of
9
+ * being misread. The Lab draws it on its Search page and a Promote changes it in a pull request.
10
+ *
11
+ * The schema is this file's: `SEARCH_SETTINGS_BOUNDS` (what each setting may be), the node and wire fields, and
12
+ * `searchConfigProblems(config)`, everything wrong with a config as sentences. A draft from the Lab is checked by the
13
+ * same function before a search runs on it.
14
+ */
15
+ "use strict";
16
+
17
+ const { PERSON_SEARCH_BOUNDS } = require("../texContract/searchSettings.cjs");
18
+
19
+ const SEARCH_SCHEMA_VERSION = 1;
20
+
21
+ /**
22
+ * Every setting a search step may have, and what it may be. The ranking knobs are `../ranking.js`'s; `minScore`,
23
+ * `extraNotes` and `snippetChars` are the person-facing search settings (`../settings.js`), whose defaults are here.
24
+ */
25
+ const SEARCH_SETTINGS_BOUNDS = Object.freeze({
26
+ // The person-facing three are a contract Tex reads too (`packages/shared/src/texContract/searchSettings.cjs`).
27
+ ...PERSON_SEARCH_BOUNDS,
28
+ rrfK: { min: 1, max: 1000, integer: false },
29
+ loosePenalty: { min: 0, max: 1000, integer: false },
30
+ titleWeight: { min: 0, max: 1, integer: false },
31
+ phraseBonus: { min: 0, max: 1, integer: false },
32
+ snippetPhraseBonus: { min: 0, max: 1, integer: false },
33
+ boostFactor: { min: 1, max: 10, integer: false },
34
+ meaningFloor: { min: 0, max: 1, integer: false },
35
+ looseReads: { min: 0, max: 20, integer: true },
36
+ hits: { min: 1, max: 50, integer: true },
37
+ logPrior: { min: 0, max: 1, integer: false },
38
+ inboxPrior: { min: 0, max: 1, integer: false },
39
+ rerankTop: { min: 2, max: 50, integer: true },
40
+ rerankWeight: { min: 0, max: 5, integer: false },
41
+ rerankChars: { min: 100, max: 2000, integer: true },
42
+ readLate: { min: 0, max: 1, integer: true },
43
+ waitAfterMeaning: { min: 0, max: 5000, integer: true },
44
+ sharedWords: { min: 0, max: 2, integer: true },
45
+ workspaceWeight: { min: 0, max: 1, integer: false },
46
+ openMine: { min: 0, max: 5, integer: false },
47
+ openPeople: { min: 0, max: 5, integer: false },
48
+ openAi: { min: 0, max: 5, integer: false },
49
+ contentWords: { min: 0, max: 1, integer: true },
50
+ });
51
+
52
+ /** Which settings each step reads: a setting on a step that does not read it would be a knob that does nothing. */
53
+ const SETTINGS_OF = Object.freeze({
54
+ search: Object.freeze([]),
55
+ open: Object.freeze([]),
56
+ words: Object.freeze(["contentWords"]),
57
+ meaning: Object.freeze(["minScore"]),
58
+ visible: Object.freeze([]),
59
+ probes: Object.freeze([]),
60
+ floor: Object.freeze(["meaningFloor"]),
61
+ merge: Object.freeze(["rrfK"]),
62
+ title: Object.freeze(["titleWeight", "phraseBonus", "snippetPhraseBonus"]),
63
+ prior: Object.freeze(["logPrior", "inboxPrior"]),
64
+ opens: Object.freeze(["openMine", "openPeople", "openAi"]),
65
+ budget: Object.freeze(["extraNotes", "looseReads"]),
66
+ snippets: Object.freeze(["snippetChars"]),
67
+ rerankWords: Object.freeze(["rerankTop", "rerankChars", "waitAfterMeaning"]),
68
+ rerank: Object.freeze(["rerankTop", "rerankWeight", "rerankChars", "readLate"]),
69
+ code: Object.freeze([]),
70
+ answer: Object.freeze([]),
71
+ fuse: Object.freeze(["hits", "rrfK", "loosePenalty", "titleWeight", "phraseBonus", "snippetPhraseBonus", "meaningFloor", "looseReads", "boostFactor", "logPrior", "inboxPrior", "rerankWeight", "sharedWords", "workspaceWeight", "openMine", "openPeople", "openAi"]),
72
+ });
73
+
74
+ /** The steps every search needs, which a draft may not turn off: the others are passed over when off (`config/nodes.js`). */
75
+ const ALWAYS_ON = Object.freeze(["search", "open", "visible", "code", "fuse", "answer"]);
76
+
77
+ const NODE_KEYS = Object.freeze(["id", "label", "goal", "on", "model", "kind", "icon", "file", "note", "x", "y", "group", "settings", "inSchema", "outSchema", "log"]);
78
+ const EDGE_KEYS = Object.freeze(["from", "to", "mode", "when"]);
79
+ /**
80
+ * Search's wires wait (each step runs on the output of the ones before it, left to right), or a step uses another: it
81
+ * calls it for one part of its work, as Words hands each workspace's hits to "Rerank word hits" the moment that
82
+ * workspace answers (Dev2, 2026-11-21).
83
+ */
84
+ const MODES = Object.freeze(["wait", "uses"]);
85
+
86
+ /** Why one setting's value is refused, or null when it may be used. */
87
+ function settingProblem(name, value) {
88
+ const bound = SEARCH_SETTINGS_BOUNDS[name];
89
+ if (!bound) return `"${name}" is not a search setting (one of ${Object.keys(SEARCH_SETTINGS_BOUNDS).join(", ")})`;
90
+ if (typeof value !== "number" || !Number.isFinite(value)) return `${name} must be a number`;
91
+ if (value < bound.min || value > bound.max) return `${name} must be from ${bound.min} to ${bound.max}`;
92
+ if (bound.integer && !Number.isInteger(value)) return `${name} must be a whole number`;
93
+ return null;
94
+ }
95
+
96
+ /** Everything wrong with a parsed search config, as sentences a person reads; [] when it is sound. */
97
+ function searchConfigProblems(config) {
98
+ const out = [];
99
+ if (!config || typeof config !== "object" || Array.isArray(config)) return ["the search config is not an object"];
100
+ if (config.searchConfig !== SEARCH_SCHEMA_VERSION) out.push(`it is search schema version ${JSON.stringify(config.searchConfig)}, not ${SEARCH_SCHEMA_VERSION}`);
101
+ if (!Array.isArray(config.nodes) || !Array.isArray(config.edges)) return [...out, "it has no nodes and edges lists"];
102
+ const ids = new Set();
103
+ for (const n of config.nodes) {
104
+ if (!n || typeof n.id !== "string") {
105
+ out.push("a step has no id");
106
+ continue;
107
+ }
108
+ if (ids.has(n.id)) out.push(`step "${n.id}" is there twice`);
109
+ ids.add(n.id);
110
+ const reads = SETTINGS_OF[n.id];
111
+ if (!reads) out.push(`step "${n.id}" is not a search step (one of ${Object.keys(SETTINGS_OF).join(", ")})`);
112
+ for (const k of Object.keys(n)) if (!NODE_KEYS.includes(k)) out.push(`step "${n.id}" has a field the search schema does not know: ${k}`);
113
+ if (typeof n.label !== "string") out.push(`step "${n.id}" has no label`);
114
+ if (typeof n.on !== "boolean") out.push(`step "${n.id}" on must be true or false`);
115
+ else if (!n.on && ALWAYS_ON.includes(n.id)) out.push(`step "${n.id}" is one every search needs, so it cannot be turned off`);
116
+ if (n.model !== "code") out.push(`step "${n.id}" runs as code (model "code")`);
117
+ const settings = n.settings ?? {};
118
+ if (typeof settings !== "object" || Array.isArray(settings)) {
119
+ out.push(`step "${n.id}" settings must be an object`);
120
+ continue;
121
+ }
122
+ for (const [name, value] of Object.entries(settings)) {
123
+ const problem = settingProblem(name, value);
124
+ if (problem) out.push(`step "${n.id}": ${problem}`);
125
+ else if (reads && !reads.includes(name)) out.push(`step "${n.id}" does not read ${name}`);
126
+ }
127
+ for (const name of reads ?? []) if (!(name in settings)) out.push(`step "${n.id}" has no ${name} setting`);
128
+ }
129
+ for (const id of Object.keys(SETTINGS_OF)) if (!ids.has(id)) out.push(`there is no "${id}" step`);
130
+ for (const e of config.edges) {
131
+ const name = `${e?.from} → ${e?.to}`;
132
+ if (!e || !ids.has(e.from) || !ids.has(e.to)) {
133
+ out.push(`the wire ${name} joins a step that is not there`);
134
+ continue;
135
+ }
136
+ for (const k of Object.keys(e)) if (!EDGE_KEYS.includes(k)) out.push(`the wire ${name} has a field the search schema does not know: ${k}`);
137
+ if (!MODES.includes(e.mode)) out.push(`the wire ${name} has mode "${e.mode}": search wires are ${MODES.join(" or ")}`);
138
+ if (!Array.isArray(e.when) || e.when.length === 0) out.push(`the wire ${name} needs a when list`);
139
+ }
140
+ return out;
141
+ }
142
+
143
+ /** A parsed config, checked: answered as it is, or an error naming every problem. */
144
+ function searchConfigOf(config) {
145
+ const problems = searchConfigProblems(config);
146
+ if (problems.length > 0) throw new Error(`searchConfig.json does not match its schema (searchConfig.cjs): ${problems.join("; ")}`);
147
+ return config;
148
+ }
149
+
150
+ const SEARCH_CONFIG = Object.freeze(searchConfigOf(require("./searchConfig.json")));
151
+
152
+ /** A step's settings in a config (main's when none is given), or {} when it has none. */
153
+ function settingsOf(id, config = SEARCH_CONFIG) {
154
+ const node = (config?.nodes ?? []).find((n) => n && n.id === id);
155
+ return node && node.settings && typeof node.settings === "object" ? node.settings : {};
156
+ }
157
+
158
+ module.exports = { ALWAYS_ON, NODE_KEYS, EDGE_KEYS, SEARCH_SCHEMA_VERSION, SEARCH_SETTINGS_BOUNDS, SETTINGS_OF, SEARCH_CONFIG, searchConfigProblems, searchConfigOf, settingProblem, settingsOf };
@@ -0,0 +1,11 @@
1
+ /** Types for `searchConfig.cjs`: search's config as `searchConfig.json` has it, and its schema. */
2
+ export declare const NODE_KEYS: readonly string[];
3
+ export declare const EDGE_KEYS: readonly string[];
4
+ export declare const SEARCH_SCHEMA_VERSION: number;
5
+ export declare const SEARCH_SETTINGS_BOUNDS: Readonly<Record<string, { min: number; max: number; integer: boolean }>>;
6
+ export declare const SETTINGS_OF: Readonly<Record<string, readonly string[]>>;
7
+ export declare const SEARCH_CONFIG: typeof import("./searchConfig.json");
8
+ export declare function searchConfigProblems(config: unknown): string[];
9
+ export declare function searchConfigOf<T>(config: T): T;
10
+ export declare function settingProblem(name: string, value: unknown): string | null;
11
+ export declare function settingsOf(id: string, config?: unknown): Record<string, number>;