@mark1russell7/guidebook-plans 0.1.4 → 0.1.5

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 CHANGED
@@ -134,7 +134,7 @@ The master chart is one chart for any disaster. A reader starts at a signal, ans
134
134
  | --- | --- |
135
135
  | `signal` | A thing that a reader sees or hears, and the `next` node. |
136
136
  | `question` | A question, two or more `answers` (each with a label, the next node and an optional state of society), and its sources. |
137
- | `goto` | An instruction that sends the reader to a `tab`. |
137
+ | `goto` | An instruction that sends the reader to a `tab`. With `card: true`, it also sends the reader to the card of the event. |
138
138
 
139
139
  The chart gate `checkMasterChart` gives these codes:
140
140
 
@@ -148,7 +148,7 @@ The chart gate `checkMasterChart` gives these codes:
148
148
  | `too-deep` | A path from a signal has more questions than `maxQuestions` (default 3). |
149
149
  | `too-many-nodes`, `too-many-ends` | The chart has more nodes than `maxNodes`, or more ends than `maxEnds`. |
150
150
  | `tab-without-steps` | A tab with keys has no step in its keys and phases. |
151
- | `unused-tab` | No path goes to a tab. |
151
+ | `unused-tab` | No path goes to a tab, and the tab is not in `used`. |
152
152
  | `uncovered-key` | No tab that the chart reaches holds a key of `cover`. Give the hazard codes of a catalog as `cover`, so each hazard has a route. |
153
153
  | `no-source`, `unknown-source` | A question cites no source and gives no `reasoning`, or a node cites an unknown source. |
154
154
 
@@ -159,6 +159,37 @@ const gate = checkMasterChart(nodes, tabs, library, sources, { on: keys, cover:
159
159
  const chart = masterChartOf(nodes, tabs); // The nodes by layer, the edges with their labels and the tabs that the chart reaches.
160
160
  ```
161
161
 
162
+ ## The master graph
163
+
164
+ The master graph `MasterGraph` is the one value that a printed binder and an app read. Its schema is `GRAPH_SCHEMA`, `"guidebook-graph/1"`. A reader refuses a graph with another value.
165
+
166
+ | Field | Value |
167
+ | --- | --- |
168
+ | `schema` | The name and the major version of the schema. |
169
+ | `start`, `catalog` | The id of the tab of the chart, and the id of the tab of the hazard catalog. |
170
+ | `societies` | The states of society, in the sequence of the sections of each tab. |
171
+ | `nodes`, `tabs` | The nodes and the tabs of the chart. The edges come from `masterChartOf`, so no second list can disagree. |
172
+ | `hazards` | The rows of the hazard catalog. Each row has a case `key`, a `title`, its `signals`, its `entry` node and its `card`: the ids of the steps unique to the case. |
173
+
174
+ The graph holds ids. A reader gets the steps and the sources from their own exports. The ids of the nodes, the tabs and the steps are stable. A change of an id is a new major version of the schema.
175
+
176
+ The graph gate `checkMasterGraph` applies the chart gate. It also gives these codes:
177
+
178
+ | Code | When |
179
+ | --- | --- |
180
+ | `bad-schema` | The schema is not `GRAPH_SCHEMA`. |
181
+ | `unknown-start`, `unknown-catalog` | The start tab or the catalog tab is not a tab. |
182
+ | `unknown-hazard`, `duplicate-hazard`, `missing-hazard` | A row names an unknown case, two rows have one case, or a case of `cases` has no row. |
183
+ | `unknown-signal`, `unknown-entry` | A row names no signal, a node that is not a signal, or an unknown entry. |
184
+ | `unknown-card-step` | A card names a step that is not a step of its case. |
185
+ | `no-route` | No path from the entry of a row goes to a tab with keys. |
186
+
187
+ ```ts
188
+ import { checkMasterGraph } from "@mark1russell7/guidebook-plans";
189
+
190
+ const gate = checkMasterGraph(graph, library, sources, { on: keys, cover: hazards, cases, maxNodes: 20, maxEnds: 13 });
191
+ ```
192
+
162
193
  ## Limits
163
194
 
164
195
  - The gate does not evaluate `when`. The planner of an app evaluates it over the live state.
package/build/index.d.ts CHANGED
@@ -88,11 +88,13 @@ interface GotoNode {
88
88
  readonly text: string;
89
89
  readonly tab: string;
90
90
  readonly sources?: readonly string[];
91
+ /** The end also shows the card of the hazard of the reader, if the reader came with one. */
92
+ readonly card?: true;
91
93
  }
92
94
  /** A node of the master chart. */
93
95
  type ChartNode = SignalNode | QuestionNode | GotoNode;
94
96
  /** The codes of the findings of the chart gate. */
95
- export declare const MASTER_FINDING_CODES: readonly ["duplicate-id", "unknown-node", "unknown-tab", "unknown-key", "few-answers", "no-signal", "unreachable", "cycle", "too-deep", "too-many-nodes", "too-many-ends", "tab-without-steps", "unused-tab", "uncovered-key", "no-source", "unknown-source"];
97
+ export declare const MASTER_FINDING_CODES: readonly ["duplicate-id", "unknown-node", "unknown-tab", "unknown-key", "few-answers", "no-signal", "unreachable", "cycle", "too-deep", "too-many-nodes", "too-many-ends", "tab-without-steps", "unused-tab", "uncovered-key", "no-source", "unknown-source", "bad-schema", "unknown-start", "unknown-catalog", "unknown-hazard", "duplicate-hazard", "missing-hazard", "unknown-signal", "unknown-entry", "unknown-card-step", "no-route"];
96
98
  /** A code of a finding of the chart gate. */
97
99
  type MasterFindingCode = (typeof MASTER_FINDING_CODES)[number];
98
100
  /** A finding of the chart gate. */
@@ -109,6 +111,8 @@ interface MasterGateOptions {
109
111
  readonly maxNodes?: number;
110
112
  /** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */
111
113
  readonly maxEnds?: number;
114
+ /** The ids of the tabs that a reader reaches by another way than an end, for example the catalog through the cards. */
115
+ readonly used?: readonly string[];
112
116
  }
113
117
  /**
114
118
  * This function applies the chart gate.
@@ -136,6 +140,49 @@ interface MasterChart<P extends string = Phase> {
136
140
  }
137
141
  /** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */
138
142
  export declare function masterChartOf<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[]): MasterChart<P>;
143
+ /** The name and the major version of the schema of the master graph. A reader refuses a graph with another value. */
144
+ export declare const GRAPH_SCHEMA = "guidebook-graph/1";
145
+ /** A row of the hazard catalog: an index into the graph, with the facts that are unique to the hazard. */
146
+ interface HazardRow {
147
+ /** The key of the case. */
148
+ readonly key: string;
149
+ readonly title: string;
150
+ /** The ids of the signal nodes that the hazard gives. */
151
+ readonly signals: readonly string[];
152
+ /** The id of the node where a reader with this hazard joins the graph. */
153
+ readonly entry: string;
154
+ /** The ids of the steps of the case that are unique to it: its card. */
155
+ readonly card: readonly string[];
156
+ }
157
+ /**
158
+ * The master graph: one value that a printed binder and an app read.
159
+ * The edges come from the nodes with `masterChartOf`, so no second list can disagree with them.
160
+ */
161
+ interface MasterGraph<P extends string = Phase> {
162
+ readonly schema: typeof GRAPH_SCHEMA;
163
+ /** The id of the tab of the chart itself, the entry of the binder. */
164
+ readonly start: string;
165
+ /** The id of the tab of the hazard catalog. An end with `card` shows the card from it. */
166
+ readonly catalog: string;
167
+ /** The states of society, in the sequence of the sections of each tab. */
168
+ readonly societies: readonly Society[];
169
+ readonly nodes: readonly ChartNode[];
170
+ readonly tabs: readonly Tab<P>[];
171
+ readonly hazards: readonly HazardRow[];
172
+ }
173
+ /** The options of the graph gate: the options of the chart gate and the cases that the catalog must index. */
174
+ interface GraphGateOptions extends MasterGateOptions {
175
+ /** The keys of the cases. Each case has one row of the catalog. */
176
+ readonly cases: readonly string[];
177
+ }
178
+ /**
179
+ * This function applies the graph gate: the chart gate, and the gate of the hazard rows.
180
+ *
181
+ * The start tab and the catalog tab are tabs. The start tab needs no path. An end with `card` uses the catalog tab.
182
+ * Each case has one row. Each row names known signals, a known entry and steps of its case.
183
+ * Each entry reaches an end whose tab has keys.
184
+ */
185
+ export declare function checkMasterGraph<P extends string>(graph: MasterGraph<P>, steps: readonly Step<P>[], sources: readonly Source[], options: GraphGateOptions): GateResult<MasterFinding>;
139
186
  /**
140
187
  * One action of a plan. A step belongs to a key and to a phase.
141
188
  * A key names a case (a kind of event) or a cut (a service that an event stops). A plan of a case is its own steps and the steps of its cuts.
@@ -304,5 +351,5 @@ interface ChartQuestion<P extends string = Phase> {
304
351
  }
305
352
  /** This function gives the chart of a set of rules: one question for each kind that has rules, in the sequence of `RULE_KINDS`. */
306
353
  export declare function chartOf<P extends string>(rules: readonly Rule<P>[]): readonly ChartQuestion<P>[];
307
- export type { Cell, ChartAnswer, ChartEdge, ChartNode, ChartQuestion, CoverageFinding, CoverageFindingCode, CoverageOptions, Gap, GotoNode, KeyCoverage, Ladder, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, Phase, PlacedNode, QuestionNode, Rule, RuleFinding, RuleFindingCode, RuleGateOptions, RuleKind, RuleTarget, SignalNode, Society, Step, StepFinding, StepFindingCode, StepGateOptions, StepsForOptions, Tab };
354
+ export type { Cell, ChartAnswer, ChartEdge, ChartNode, ChartQuestion, CoverageFinding, CoverageFindingCode, CoverageOptions, Gap, GotoNode, GraphGateOptions, HazardRow, KeyCoverage, Ladder, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, MasterGraph, Phase, PlacedNode, QuestionNode, Rule, RuleFinding, RuleFindingCode, RuleGateOptions, RuleKind, RuleTarget, SignalNode, Society, Step, StepFinding, StepFindingCode, StepGateOptions, StepsForOptions, Tab };
308
355
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ladder.ts","../src/master.ts","../src/steps.ts","../src/coverage.ts","../src/rules.ts"],"mappings":";;qBAWa;;UAGI,OAAO;;WAEb,OAAO;;WAEP,QAAQ;;WAER;aAA2B,OAAO;aAAY;;WAC9C,QAAQ,SAAS,OAAO;;;qBAItB;;KAGD,gBAAgB;;qBAGf;;qBAGA,cAAc,SAAS,OAAO;;qBAY9B,QAAQ,OAAO;;wBAQZ,SAAS,kBAAkB,QAAQ,OAAO,cAAc;;;;;;wBASxD,QAAQ,kBAAkB,QAAQ,OAAO,IAAI,iBAAiB,mBAAiB;;wBAU/E,QAAQ,iBAAiB,mBAAiB;;qBC/D7C;;KAGD,kBAAkB;;qBAGjB,gBAAgB,SAAS,OAAO;;;;;UAU5B,IAAI,mBAAmB;WAC7B;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;;UAIM;;WAEN;;WAEA;;WAEA,UAAU;;;UAIJ;WACN;WACA;WACA;WACA;WACA;;;UAIM;WACN;WACA;WACA;WACA,kBAAkB;;WAElB;;WAEA;;;UAIM;WACN;WACA;WACA;WACA;WACA;;;KAIC,YAAY,aAAa,eAAe;;qBAGvC;;KAoBD,4BAA4B;;KAG5B,gBAAgB,QAAQ;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  "no-source",
403
- "unknown-source"
403
+ "unknown-source",
404
+ "bad-schema",
405
+ "unknown-start",
406
+ "unknown-catalog",
407
+ "unknown-hazard",
408
+ "duplicate-hazard",
409
+ "missing-hazard",
410
+ "unknown-signal",
411
+ "unknown-entry",
412
+ "unknown-card-step",
413
+ "no-route"
404
414
  ];
405
415
  /** The ids of the nodes that come after a node. */
406
416
  function nextOf(node) {
@@ -498,7 +508,7 @@ function checkMasterChart(nodes, tabs, steps, sources, options) {
498
508
  if (options.maxNodes !== void 0 && nodes.length > options.maxNodes) error("too-many-nodes", "chart", `The chart has ${nodes.length} nodes. The limit is ${options.maxNodes}.`);
499
509
  const ends = nodes.filter((node) => node.kind === "goto").length;
500
510
  if (options.maxEnds !== void 0 && ends > options.maxEnds) error("too-many-ends", "chart", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);
501
- const used = new Set(nodes.filter((node) => seen.has(node.id)).flatMap((node) => node.kind === "goto" ? [node.tab] : []));
511
+ const used = /* @__PURE__ */ new Set([...options.used ?? [], ...nodes.filter((node) => seen.has(node.id)).flatMap((node) => node.kind === "goto" ? [node.tab] : [])]);
502
512
  for (const tab of tabs) {
503
513
  for (const key of tab.keys) if (!known.has(key)) error("unknown-key", tab.id, `The tab names the unknown key "${key}".`);
504
514
  const keys = new Set(tab.keys);
@@ -548,6 +558,63 @@ function masterChartOf(nodes, tabs) {
548
558
  tabs: tabs.filter((tab) => tabIds.has(tab.id))
549
559
  };
550
560
  }
551
- export { COVERAGE_FINDING_CODES, HORIZONS, LADDER, MASTER_FINDING_CODES, PHASES, PHASE_BOUNDS, PHASE_TITLES, RULE_FINDING_CODES, RULE_KINDS, RULE_KIND_TITLES, SECONDS_PER_DAY, SOCIETY_STATES, SOCIETY_TITLES, STEP_FINDING_CODES, chartOf, checkCoverage, checkMasterChart, checkRules, checkSteps, coverageOf, masterChartOf, phaseIn, phaseOf, phasesOf, planMatrix, stepsFor, unitsOf };
561
+ /** The name and the major version of the schema of the master graph. A reader refuses a graph with another value. */
562
+ const GRAPH_SCHEMA = "guidebook-graph/1";
563
+ /**
564
+ * This function applies the graph gate: the chart gate, and the gate of the hazard rows.
565
+ *
566
+ * The start tab and the catalog tab are tabs. The start tab needs no path. An end with `card` uses the catalog tab.
567
+ * Each case has one row. Each row names known signals, a known entry and steps of its case.
568
+ * Each entry reaches an end whose tab has keys.
569
+ */
570
+ function checkMasterGraph(graph, steps, sources, options) {
571
+ const out = [];
572
+ const error = (code, id, message) => {
573
+ out.push({
574
+ level: "error",
575
+ code,
576
+ record: "chart",
577
+ id,
578
+ message
579
+ });
580
+ };
581
+ if (graph.schema !== "guidebook-graph/1") error("bad-schema", "graph", `The schema is "${String(graph.schema)}", not "${GRAPH_SCHEMA}".`);
582
+ const tabIds = new Set(graph.tabs.map((tab) => tab.id));
583
+ if (!tabIds.has(graph.start)) error("unknown-start", graph.start, `The start tab "${graph.start}" is not a tab.`);
584
+ if (!tabIds.has(graph.catalog)) error("unknown-catalog", graph.catalog, `The catalog tab "${graph.catalog}" is not a tab.`);
585
+ const withCards = graph.nodes.some((node) => node.kind === "goto" && node.card === true);
586
+ const chartTabs = graph.tabs.filter((tab) => tab.id !== graph.start);
587
+ const chart = checkMasterChart(graph.nodes, chartTabs, steps, sources, {
588
+ ...options,
589
+ used: [...options.used ?? [], ...withCards ? [graph.catalog] : []]
590
+ });
591
+ out.push(...chart.findings);
592
+ const byId = new Map(graph.nodes.map((node) => [node.id, node]));
593
+ const stepById = new Map(steps.map((step) => [step.id, step]));
594
+ const tabById = new Map(graph.tabs.map((tab) => [tab.id, tab]));
595
+ const cases = new Set(options.cases);
596
+ const rows = /* @__PURE__ */ new Set();
597
+ const routes = (id, seen = /* @__PURE__ */ new Set()) => {
598
+ if (seen.has(id)) return false;
599
+ seen.add(id);
600
+ const node = byId.get(id);
601
+ if (node === void 0) return false;
602
+ if (node.kind === "goto") return (tabById.get(node.tab)?.keys.length ?? 0) > 0;
603
+ return nextOf(node).some((to) => routes(to, seen));
604
+ };
605
+ for (const row of graph.hazards) {
606
+ if (rows.has(row.key)) error("duplicate-hazard", row.key, `Two rows of the catalog have the key "${row.key}".`);
607
+ rows.add(row.key);
608
+ if (!cases.has(row.key)) error("unknown-hazard", row.key, `The row names the unknown case "${row.key}".`);
609
+ if (row.signals.length === 0) error("unknown-signal", row.key, "The row names no signal.");
610
+ for (const id of row.signals) if (byId.get(id)?.kind !== "signal") error("unknown-signal", row.key, `The row names "${id}", which is not a signal node.`);
611
+ if (!byId.has(row.entry)) error("unknown-entry", row.key, `The row names the unknown entry "${row.entry}".`);
612
+ else if (!routes(row.entry)) error("no-route", row.key, "No path from the entry of the row goes to a tab with keys.");
613
+ for (const id of row.card) if (stepById.get(id)?.on !== row.key) error("unknown-card-step", row.key, `The card names "${id}", which is not a step of the case.`);
614
+ }
615
+ for (const key of options.cases) if (!rows.has(key)) error("missing-hazard", key, `The catalog has no row for the case "${key}".`);
616
+ return resultOf(out);
617
+ }
618
+ export { COVERAGE_FINDING_CODES, GRAPH_SCHEMA, HORIZONS, LADDER, MASTER_FINDING_CODES, PHASES, PHASE_BOUNDS, PHASE_TITLES, RULE_FINDING_CODES, RULE_KINDS, RULE_KIND_TITLES, SECONDS_PER_DAY, SOCIETY_STATES, SOCIETY_TITLES, STEP_FINDING_CODES, chartOf, checkCoverage, checkMasterChart, checkMasterGraph, checkRules, checkSteps, coverageOf, masterChartOf, phaseIn, phaseOf, phasesOf, planMatrix, stepsFor, unitsOf };
552
619
 
553
620
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/ladder.ts","../src/steps.ts","../src/coverage.ts","../src/rules.ts","../src/master.ts"],"sourcesContent":["// The time ladder of a plan: the phases before the start of an event, and the phases after it, each with its first second.\n\nconst MINUTE = 60;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\nconst WEEK = 7 * DAY;\n/** A month of the ladder is 30 days, and a year is 365 days. */\nconst MONTH = 30 * DAY;\nconst YEAR = 365 * DAY;\n\n/** This constant is the number of seconds in one day. */\nexport const SECONDS_PER_DAY: number = DAY;\n\n/** A ladder of phases. Each phase has a title that a print or a page shows. */\nexport interface Ladder<P extends string = string> {\n /** The phase before the start of an event, when no warning is live. */\n readonly ready: P;\n /** The phase before the start of an event, when a warning is live. */\n readonly warned: P;\n /** The phases after the start, in their sequence. Each phase starts at its second `from`. The first phase starts at 0. */\n readonly timed: readonly { readonly phase: P; readonly from: number }[];\n readonly titles: Readonly<Record<P, string>>;\n}\n\n/** The phases of the default ladder, in their sequence. */\nexport const PHASES = [\"ready\", \"warned\", \"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** One phase of the default ladder. */\nexport type Phase = (typeof PHASES)[number];\n\n/** The bounds of the phases `P0` to `P5`, in seconds: 0, 5 min, 5 h, 5 d, 5 wk, 5 mo and 5 yr. */\nexport const PHASE_BOUNDS: readonly number[] = [0, 5 * MINUTE, 5 * HOUR, 5 * DAY, 5 * WEEK, 5 * MONTH, 5 * YEAR];\n\n/** The words of each phase of the default ladder. */\nexport const PHASE_TITLES: Readonly<Record<Phase, string>> = {\n ready: \"Before an event\",\n warned: \"When a warning comes\",\n P0: \"In the first 5 minutes\",\n P1: \"From 5 minutes to 5 hours\",\n P2: \"From 5 hours to 5 days\",\n P3: \"From 5 days to 5 weeks\",\n P4: \"From 5 weeks to 5 months\",\n P5: \"From 5 months to 5 years\",\n};\n\n/** The default ladder: each phase after the start is approximately 60 times longer than the phase before it. */\nexport const LADDER: Ladder<Phase> = {\n ready: \"ready\",\n warned: \"warned\",\n timed: ([\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const).map((phase, i) => ({ phase, from: PHASE_BOUNDS[i] ?? 0 })),\n titles: PHASE_TITLES,\n};\n\n/** This function gives the phases of a ladder in their sequence: `ready`, `warned`, then the timed phases. */\nexport function phasesOf<P extends string>(ladder: Ladder<P>): readonly P[] {\n return [ladder.ready, ladder.warned, ...ladder.timed.map((step) => step.phase)];\n}\n\n/**\n * This function gives the phase of a time on a ladder, in seconds from the start of the event.\n * A negative time is before the start: it gives `warned` when a warning is live, else `ready`.\n * A time at a bound is in the later phase. A time after the start of the last phase stays in the last phase.\n */\nexport function phaseIn<P extends string>(ladder: Ladder<P>, seconds: number, warned = false): P {\n if (!Number.isFinite(seconds)) throw new RangeError(`phaseIn: the time ${String(seconds)} is not a finite number.`);\n if (seconds < 0) return warned ? ladder.warned : ladder.ready;\n let phase: P | undefined;\n for (const step of ladder.timed) if (seconds >= step.from) phase = step.phase;\n if (phase === undefined) throw new RangeError(\"phaseIn: the ladder has no timed phase that starts at 0.\");\n return phase;\n}\n\n/** This function gives the phase of a time on the default ladder. 5 minutes gives `P1`. */\nexport function phaseOf(seconds: number, warned = false): Phase {\n return phaseIn(LADDER, seconds, warned);\n}\n","// The steps of a plan, the query of the steps, the matrix of the library, and the step gate.\n\nimport { checkUnits, resultOf } from \"@mark1russell7/guidebook\";\nimport type { CitedUnit, Finding, GateResult, Source, SourceId, UseContext } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Society } from \"./master.ts\";\n\n/**\n * One action of a plan. A step belongs to a key and to a phase.\n * A key names a case (a kind of event) or a cut (a service that an event stops). A plan of a case is its own steps and the steps of its cuts.\n */\nexport interface Step<P extends string = Phase> {\n readonly id: string;\n /** The key of the step: a case or a cut. */\n readonly on: string;\n readonly phase: P;\n /** The needs that the step protects. */\n readonly needs: readonly string[];\n /** An optional condition: a Vex program over the live state. No `when` means always. */\n readonly when?: string;\n /**\n * The action, as one instruction in Simplified Technical English, in the words of the guidebook.\n * When the step has a `when`, this text names the condition in words, because a print cannot examine `when`.\n */\n readonly do: string;\n /** The parts, the resources and the topics that the step uses. */\n readonly uses?: readonly string[];\n /** The order of the step in its phase, from 1. */\n readonly order: number;\n /** The sources of the step. A step with no `reasoning` has one or more. */\n readonly sources: readonly SourceId[];\n /**\n * The reasoning of a strategy step from first principles, for a step that no source tells.\n * A step with a number in its text (a dose, a time or a safety limit) still cites a source.\n */\n readonly reasoning?: string;\n /** The states of society that the step is for. No `society` means each state. */\n readonly society?: readonly Society[];\n}\n\n/** A marked gap: a key and a phase that have no step on purpose, with the reason. */\nexport interface Gap<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n /** The reason, for example \"A house fire gives no warning.\" */\n readonly why: string;\n}\n\n/** A cell of the matrix of a library: the steps of one key in one phase, or the marked gap of the cell. */\nexport interface Cell<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n readonly steps: readonly Step<P>[];\n readonly gap?: Gap<P>;\n}\n\nconst byOrder = <P extends string>(a: Step<P>, b: Step<P>): number => a.order - b.order || a.id.localeCompare(b.id);\n\n/** The options of the steps query. */\nexport interface StepsForOptions {\n /** Only the steps for this state of society. A step with no `society` is for each state. */\n readonly society?: Society;\n}\n\n/**\n * This function gives the steps whose `on` is in `on` and whose phase is in `phases`.\n * The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.\n */\nexport function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[], options: StepsForOptions = {}): readonly Step<P>[] {\n const { society } = options;\n const fits = (step: Step<P>): boolean => society === undefined || step.society === undefined || step.society.includes(society);\n const out: Step<P>[] = [];\n const seen = new Set<string>();\n for (const key of on) {\n for (const phase of phases) {\n const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id) && fits(step)).sort(byOrder);\n for (const step of hits) {\n seen.add(step.id);\n out.push(step);\n }\n }\n }\n return out;\n}\n\n/** This function gives the matrix of a library: one row for each key of `on`, with one cell for each phase of `phases`. */\nexport function planMatrix<P extends string>(\n library: readonly Step<P>[],\n gaps: readonly Gap<P>[],\n on: readonly string[],\n phases: readonly P[],\n): readonly (readonly Cell<P>[])[] {\n return on.map((key) =>\n phases.map((phase) => {\n const steps = library.filter((step) => step.on === key && step.phase === phase).sort(byOrder);\n const gap = gaps.find((item) => item.on === key && item.phase === phase);\n return gap === undefined ? { on: key, phase, steps } : { on: key, phase, steps, gap };\n }),\n );\n}\n\n/** The codes of the findings of the step gate. The codes of the source gate also apply to the sources of the steps. */\nexport const STEP_FINDING_CODES = [\n \"duplicate-id\",\n \"empty-text\",\n \"no-source\",\n \"number-without-source\",\n \"empty-reasoning\",\n \"missing-source\",\n \"use-refused\",\n \"unknown-phase\",\n \"bad-order\",\n \"duplicate-order\",\n \"unmarked-gap\",\n \"gap-with-steps\",\n \"duplicate-gap\",\n \"empty-reason\",\n] as const;\n\n/** A code of a finding of the step gate. */\nexport type StepFindingCode = (typeof STEP_FINDING_CODES)[number];\n\n/** A finding of the step gate. */\nexport type StepFinding = Finding<StepFindingCode, \"step\" | \"gap\" | \"cell\">;\n\n/** The options of the step gate. */\nexport interface StepGateOptions<P extends string> extends UseContext {\n /** The phases that a step can have. */\n readonly phases: readonly P[];\n /** The keys of the matrix. With them, the gate finds each cell that has no step and no marked gap. */\n readonly on?: readonly string[];\n /** The marked gaps of the library. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** This function gives one summary unit for each source of each step, so the source gate examines the steps. */\nexport function unitsOf<P extends string>(steps: readonly Step<P>[]): readonly CitedUnit[] {\n return steps.flatMap((step) => step.sources.map((source) => ({ id: `${step.id}@${source}`, use: \"summary\" as const, text: step.do, source })));\n}\n\n/**\n * This function applies the step gate. It examines the ids, the text, the sources, the phases and the order of each step.\n * It examines the sources with the source gate: the text of a step is a summary of each of its sources.\n * With `on`, it also finds each cell of the matrix that has no step and no marked gap.\n */\nexport function checkSteps<P extends string>(steps: readonly Step<P>[], sources: readonly Source[], options: StepGateOptions<P>): GateResult<StepFinding> {\n const out: StepFinding[] = [];\n const error = (code: StepFindingCode, record: StepFinding[\"record\"], id: string, message: string): void => {\n out.push({ level: \"error\", code, record, id, message });\n };\n const phases = new Set<string>(options.phases);\n const ids = new Set<string>();\n const orders = new Map<string, string>();\n for (const step of steps) {\n if (ids.has(step.id)) error(\"duplicate-id\", \"step\", step.id, `Two steps have the id \"${step.id}\".`);\n ids.add(step.id);\n if (step.do.trim() === \"\") error(\"empty-text\", \"step\", step.id, `The step \"${step.id}\" has no text.`);\n if (step.reasoning !== undefined && step.reasoning.trim() === \"\") error(\"empty-reasoning\", \"step\", step.id, `The step \"${step.id}\" has an empty reasoning.`);\n if (step.sources.length === 0) {\n if (step.reasoning === undefined) error(\"no-source\", \"step\", step.id, `The step \"${step.id}\" cites no source and gives no reasoning.`);\n else if (/[0-9]/.test(step.do)) error(\"number-without-source\", \"step\", step.id, `The step \"${step.id}\" has a number, so it needs a source.`);\n }\n if (!phases.has(step.phase)) error(\"unknown-phase\", \"step\", step.id, `The step \"${step.id}\" has the unknown phase \"${step.phase}\".`);\n if (!Number.isInteger(step.order) || step.order < 1) error(\"bad-order\", \"step\", step.id, `The step \"${step.id}\" has the order ${String(step.order)}. It needs an integer from 1.`);\n const cell = `${step.on}\\u0000${step.phase}\\u0000${String(step.order)}`;\n const other = orders.get(cell);\n if (other !== undefined) error(\"duplicate-order\", \"step\", step.id, `The steps \"${other}\" and \"${step.id}\" have the same order in \"${step.on}\", phase \"${step.phase}\".`);\n else orders.set(cell, step.id);\n }\n for (const finding of checkUnits(unitsOf(steps), sources, options)) {\n if (finding.code !== \"missing-source\" && finding.code !== \"use-refused\") continue;\n const id = finding.id.slice(0, finding.id.lastIndexOf(\"@\"));\n out.push({ level: finding.level, code: finding.code, record: \"step\", id, message: finding.message.replace(`unit \"${finding.id}\"`, `step \"${id}\"`) });\n }\n out.push(...checkGaps(steps, options));\n return resultOf(out);\n}\n\nfunction checkGaps<P extends string>(steps: readonly Step<P>[], options: StepGateOptions<P>): StepFinding[] {\n const out: StepFinding[] = [];\n const gaps = options.gaps ?? [];\n const seen = new Set<string>();\n for (const gap of gaps) {\n const id = `${gap.on}/${gap.phase}`;\n if (seen.has(id)) out.push({ level: \"error\", code: \"duplicate-gap\", record: \"gap\", id, message: `Two gaps mark \"${gap.on}\" in phase \"${gap.phase}\".` });\n seen.add(id);\n if (gap.why.trim() === \"\") out.push({ level: \"error\", code: \"empty-reason\", record: \"gap\", id, message: `The gap of \"${gap.on}\" in phase \"${gap.phase}\" gives no reason.` });\n const count = steps.filter((step) => step.on === gap.on && step.phase === gap.phase).length;\n if (count > 0) out.push({ level: \"error\", code: \"gap-with-steps\", record: \"gap\", id, message: `A gap marks \"${gap.on}\" in phase \"${gap.phase}\", but the cell has ${String(count)} steps.` });\n if (!options.phases.includes(gap.phase)) out.push({ level: \"error\", code: \"unknown-phase\", record: \"gap\", id, message: `The gap of \"${gap.on}\" has the unknown phase \"${gap.phase}\".` });\n }\n if (options.on === undefined) return out;\n for (const row of planMatrix(steps, gaps, options.on, options.phases)) {\n for (const cell of row) {\n const id = `${cell.on}/${cell.phase}`;\n if (cell.steps.length === 0 && cell.gap === undefined) {\n out.push({ level: \"error\", code: \"unmarked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\", and no gap marks the cell.` });\n }\n }\n }\n return out;\n}\n","// The coverage gate: each key of a catalog has steps in each phase of a set. A marked gap does not pass it.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult } from \"@mark1russell7/guidebook\";\nimport { planMatrix, type Gap, type Step } from \"./steps.ts\";\n\n/** The horizons of a plan: the phases from the first 5 minutes to 5 years. The coverage gate examines them by default. */\nexport const HORIZONS = [\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** The codes of the findings of the coverage gate. */\nexport const COVERAGE_FINDING_CODES = [\"no-step\", \"marked-gap\"] as const;\n\n/** A code of a finding of the coverage gate. */\nexport type CoverageFindingCode = (typeof COVERAGE_FINDING_CODES)[number];\n\n/** A finding of the coverage gate. Its `id` is `<key>/<phase>`. */\nexport type CoverageFinding = Finding<CoverageFindingCode, \"cell\">;\n\n/** The options of the coverage gate. */\nexport interface CoverageOptions<P extends string> {\n /** The keys of the catalog. Each key needs steps in each phase. */\n readonly on: readonly string[];\n /** The phases that each key needs. */\n readonly phases: readonly P[];\n /** The marked gaps of the library. The gate shows the reason of a gap, but the gap does not pass. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** The coverage of one key: the phases with steps and the phases with no step. */\nexport interface KeyCoverage<P extends string> {\n readonly on: string;\n readonly covered: readonly P[];\n readonly missing: readonly P[];\n}\n\n/** This function gives the coverage of each key of `on` over `phases`, in the sequence of `on`. */\nexport function coverageOf<P extends string>(steps: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly KeyCoverage<P>[] {\n return planMatrix(steps, [], on, phases).map((row, index) => ({\n on: on[index] ?? \"\",\n covered: row.filter((cell) => cell.steps.length > 0).map((cell) => cell.phase),\n missing: row.filter((cell) => cell.steps.length === 0).map((cell) => cell.phase),\n }));\n}\n\n/**\n * This function applies the coverage gate. Each key of `on` needs one or more steps in each phase of `phases`.\n * A cell with no step is an error, also when a gap marks it: the finding `marked-gap` gives the reason of the gap.\n * Thus a key with no step shows each of its gaps, and it does not pass.\n */\nexport function checkCoverage<P extends string>(steps: readonly Step<P>[], options: CoverageOptions<P>): GateResult<CoverageFinding> {\n const out: CoverageFinding[] = [];\n for (const row of planMatrix(steps, options.gaps ?? [], options.on, options.phases)) {\n for (const cell of row) {\n if (cell.steps.length > 0) continue;\n const id = `${cell.on}/${cell.phase}`;\n out.push(\n cell.gap === undefined\n ? { level: \"error\", code: \"no-step\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\".` }\n : { level: \"error\", code: \"marked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\". The gap gives the reason: ${cell.gap.why}` },\n );\n }\n }\n return resultOf(out);\n}\n","// The decision chart: trigger rules as data. Each rule names a trigger, the keys of the trigger and a target in the steps.\n// The rule gate examines that each key is known, each target has steps and each rule cites its sources.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult, Source } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Step } from \"./steps.ts\";\n\n/**\n * The kinds of rule, in the sequence of the chart.\n * The chart asks first for the place. Then it asks for an immediate danger and for the cuts.\n * Then it asks when to stay, to go or to change the plan.\n */\nexport const RULE_KINDS = [\"place\", \"reflex\", \"module\", \"stay\", \"go\", \"fallback\", \"long-plan\"] as const;\n\n/** A kind of rule. */\nexport type RuleKind = (typeof RULE_KINDS)[number];\n\n/** The words of each kind of rule, for a chart. */\nexport const RULE_KIND_TITLES: Readonly<Record<RuleKind, string>> = {\n place: \"Where am I?\",\n reflex: \"Is there an immediate danger?\",\n module: \"What is cut?\",\n stay: \"When do I stay?\",\n go: \"When do I go?\",\n fallback: \"When do I go to a fallback place?\",\n \"long-plan\": \"When do I change to the long plan?\",\n};\n\n/** The target of a rule: the steps of a key in the given phases. */\nexport interface RuleTarget<P extends string = Phase> {\n readonly on: string;\n readonly phases: readonly P[];\n}\n\n/** A trigger rule of the decision chart. */\nexport interface Rule<P extends string = Phase> {\n readonly id: string;\n readonly kind: RuleKind;\n /** The trigger, as one sentence in Simplified Technical English. A print shows it. */\n readonly when: string;\n /** The action, as one instruction. A print shows it with the target. */\n readonly then: string;\n /** The keys that the trigger names: cases, cuts or needs. */\n readonly on: readonly string[];\n /** The steps that the rule sends the reader to. A rule of the kind `place` has no target, because the places are input data. */\n readonly target?: RuleTarget<P>;\n /** The rank in its kind. A rule with a lower rank comes first. */\n readonly rank: number;\n /** The ids of the sources that tell the trigger and the action. */\n readonly sources: readonly string[];\n}\n\n/** The codes of the findings of the rule gate. */\nexport const RULE_FINDING_CODES = [\"duplicate-id\", \"unknown-key\", \"no-target\", \"target-without-steps\", \"no-source\", \"unknown-source\"] as const;\n\n/** A code of a finding of the rule gate. */\nexport type RuleFindingCode = (typeof RULE_FINDING_CODES)[number];\n\n/** A finding of the rule gate. */\nexport type RuleFinding = Finding<RuleFindingCode, \"rule\">;\n\n/** The options of the rule gate. */\nexport interface RuleGateOptions {\n /** The known keys: the cases, the cuts and the needs. */\n readonly on: readonly string[];\n}\n\n/**\n * This function applies the rule gate.\n * Each key of a rule is known. Each rule other than `place` has a target with one or more steps. Each rule cites a known source.\n */\nexport function checkRules<P extends string>(rules: readonly Rule<P>[], steps: readonly Step<P>[], sources: readonly Source[], options: RuleGateOptions): GateResult<RuleFinding> {\n const out: RuleFinding[] = [];\n const known = new Set(options.on);\n const sourceIds = new Set(sources.map((source) => source.id));\n const seen = new Set<string>();\n const error = (code: RuleFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"rule\", id, message });\n };\n for (const rule of rules) {\n if (seen.has(rule.id)) error(\"duplicate-id\", rule.id, `Two rules have the id \"${rule.id}\".`);\n seen.add(rule.id);\n for (const key of rule.on) if (!known.has(key)) error(\"unknown-key\", rule.id, `The rule names the unknown key \"${key}\".`);\n if (rule.target === undefined) {\n if (rule.kind !== \"place\") error(\"no-target\", rule.id, `The rule of the kind \"${rule.kind}\" has no target.`);\n } else {\n const { on, phases } = rule.target;\n if (!known.has(on)) error(\"unknown-key\", rule.id, `The target names the unknown key \"${on}\".`);\n else if (!steps.some((step) => step.on === on && phases.includes(step.phase))) {\n error(\"target-without-steps\", rule.id, `The target \"${on}\" has no step in the phases ${phases.join(\", \")}.`);\n }\n }\n if (rule.sources.length === 0) error(\"no-source\", rule.id, \"The rule cites no source.\");\n for (const id of rule.sources) if (!sourceIds.has(id)) error(\"unknown-source\", rule.id, `The rule cites the unknown source \"${id}\".`);\n }\n return resultOf(out);\n}\n\n/** One question of the chart: a kind of rule and its rules in the sequence of their rank. */\nexport interface ChartQuestion<P extends string = Phase> {\n readonly kind: RuleKind;\n readonly title: string;\n readonly rules: readonly Rule<P>[];\n}\n\n/** This function gives the chart of a set of rules: one question for each kind that has rules, in the sequence of `RULE_KINDS`. */\nexport function chartOf<P extends string>(rules: readonly Rule<P>[]): readonly ChartQuestion<P>[] {\n return RULE_KINDS.flatMap((kind) => {\n const ofKind = rules.filter((rule) => rule.kind === kind).sort((a, b) => a.rank - b.rank || a.id.localeCompare(b.id));\n return ofKind.length === 0 ? [] : [{ kind, title: RULE_KIND_TITLES[kind], rules: ofKind }];\n });\n}\n","// The master chart: one chart for any disaster, as data. A reader starts at a signal, answers a few questions and goes to a tab.\n// A tab is a section of a printed plan: a set of keys and phases. The print gives each tab its page.\n\nimport { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult, Source } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Step } from \"./steps.ts\";\n\n/** The states of society after an event, from a society that works to a society that does not work. */\nexport const SOCIETY_STATES = [\"works\", \"partly\", \"none\"] as const;\n\n/** A state of society: the emergency services, the shops, the grid and the law work, work in part or do not work. */\nexport type Society = (typeof SOCIETY_STATES)[number];\n\n/** The words of each state of society, for a chart. */\nexport const SOCIETY_TITLES: Readonly<Record<Society, string>> = {\n works: \"Society works\",\n partly: \"Society works in part\",\n none: \"Society does not work\",\n};\n\n/**\n * A tab of a printed plan: the steps of its keys in its phases.\n * Each state of society is a section in the tab, so a tab is for one need or one subject, not for one state.\n */\nexport interface Tab<P extends string = Phase> {\n readonly id: string;\n readonly title: string;\n /** The keys of the tab: cases, cuts or needs. A tab of reference text or of a chart has no keys. */\n readonly keys: readonly string[];\n readonly phases: readonly P[];\n /** The most pages that the print of the tab can use. */\n readonly pages?: number;\n}\n\n/** An answer to a question of the chart. */\nexport interface ChartAnswer {\n /** The words of the answer, for a chart. */\n readonly label: string;\n /** The id of the next node. */\n readonly next: string;\n /** The state of society that the answer tells, if any. */\n readonly society?: Society;\n}\n\n/** A start of the chart: a thing that a reader sees or hears. */\nexport interface SignalNode {\n readonly id: string;\n readonly kind: \"signal\";\n readonly text: string;\n readonly next: string;\n readonly sources?: readonly string[];\n}\n\n/** A question of the chart, with two or more answers. */\nexport interface QuestionNode {\n readonly id: string;\n readonly kind: \"question\";\n readonly text: string;\n readonly answers: readonly ChartAnswer[];\n /** The ids of the sources that tell the question and its answers. */\n readonly sources: readonly string[];\n /** The reasoning of the question from first principles, for a question that no source tells. */\n readonly reasoning?: string;\n}\n\n/** An end of the chart: an instruction that sends the reader to a tab. */\nexport interface GotoNode {\n readonly id: string;\n readonly kind: \"goto\";\n readonly text: string;\n readonly tab: string;\n readonly sources?: readonly string[];\n}\n\n/** A node of the master chart. */\nexport type ChartNode = SignalNode | QuestionNode | GotoNode;\n\n/** The codes of the findings of the chart gate. */\nexport const MASTER_FINDING_CODES = [\n \"duplicate-id\",\n \"unknown-node\",\n \"unknown-tab\",\n \"unknown-key\",\n \"few-answers\",\n \"no-signal\",\n \"unreachable\",\n \"cycle\",\n \"too-deep\",\n \"too-many-nodes\",\n \"too-many-ends\",\n \"tab-without-steps\",\n \"unused-tab\",\n \"uncovered-key\",\n \"no-source\",\n \"unknown-source\",\n] as const;\n\n/** A code of a finding of the chart gate. */\nexport type MasterFindingCode = (typeof MASTER_FINDING_CODES)[number];\n\n/** A finding of the chart gate. */\nexport type MasterFinding = Finding<MasterFindingCode, \"chart\">;\n\n/** The options of the chart gate. */\nexport interface MasterGateOptions {\n /** The known keys: the cases, the cuts and the needs. */\n readonly on: readonly string[];\n /** The keys that a tab of the chart must hold. No `cover` means no key. */\n readonly cover?: readonly string[];\n /** The most questions on a path from a signal to a tab. The default is 3. */\n readonly maxQuestions?: number;\n /** The most nodes that the print of the chart can hold. No `maxNodes` means no limit. */\n readonly maxNodes?: number;\n /** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */\n readonly maxEnds?: number;\n}\n\n/** The ids of the nodes that come after a node. */\nfunction nextOf(node: ChartNode): readonly string[] {\n if (node.kind === \"signal\") return [node.next];\n if (node.kind === \"question\") return node.answers.map((answer) => answer.next);\n return [];\n}\n\n/** The nodes in a cycle. A chart with a cycle has no end on that path. */\nfunction cycleNodes(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {\n const next = (id: string): readonly string[] => {\n const node = byId.get(id);\n return node === undefined ? [] : nextOf(node).filter((to) => byId.has(to));\n };\n const out = new Set<string>();\n for (const group of stronglyConnectedComponents(nodes.map((node) => node.id), next)) {\n const [first] = group;\n if (group.length > 1 || (first !== undefined && next(first).includes(first))) for (const id of group) out.add(id);\n }\n return out;\n}\n\n/** The most questions from each node to an end, on a chart with no cycle. */\nfunction questionsToEnd(byId: ReadonlyMap<string, ChartNode>, skip: ReadonlySet<string>): Map<string, number> {\n const memo = new Map<string, number>();\n const walk = (id: string): number => {\n const known = memo.get(id);\n if (known !== undefined) return known;\n const node = byId.get(id);\n if (node === undefined || skip.has(id)) return 0;\n const rest = Math.max(0, ...nextOf(node).map(walk));\n const value = (node.kind === \"question\" ? 1 : 0) + rest;\n memo.set(id, value);\n return value;\n };\n for (const id of byId.keys()) walk(id);\n return memo;\n}\n\n/** The ids of the nodes that a signal reaches. */\nfunction reached(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {\n const seen = new Set<string>();\n const stack = nodes.filter((node) => node.kind === \"signal\").map((node) => node.id);\n for (let id = stack.pop(); id !== undefined; id = stack.pop()) {\n if (seen.has(id)) continue;\n seen.add(id);\n const node = byId.get(id);\n if (node !== undefined) stack.push(...nextOf(node));\n }\n return seen;\n}\n\n/**\n * This function applies the chart gate.\n * Each node is known and reached, and each path ends at a known tab after a few questions.\n * Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.\n */\nexport function checkMasterChart<P extends string>(\n nodes: readonly ChartNode[],\n tabs: readonly Tab<P>[],\n steps: readonly Step<P>[],\n sources: readonly Source[],\n options: MasterGateOptions,\n): GateResult<MasterFinding> {\n const out: MasterFinding[] = [];\n const error = (code: MasterFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"chart\", id, message });\n };\n const byId = new Map<string, ChartNode>();\n for (const node of nodes) {\n if (byId.has(node.id)) error(\"duplicate-id\", node.id, `Two nodes have the id \"${node.id}\".`);\n byId.set(node.id, node);\n }\n const tabById = new Map<string, Tab<P>>();\n for (const tab of tabs) {\n if (tabById.has(tab.id)) error(\"duplicate-id\", tab.id, `Two tabs have the id \"${tab.id}\".`);\n tabById.set(tab.id, tab);\n }\n const known = new Set(options.on);\n const sourceIds = new Set(sources.map((source) => source.id));\n\n for (const node of nodes) {\n for (const to of nextOf(node)) if (!byId.has(to)) error(\"unknown-node\", node.id, `The node goes to the unknown node \"${to}\".`);\n if (node.kind === \"question\" && node.answers.length < 2) error(\"few-answers\", node.id, \"The question has fewer than 2 answers.\");\n if (node.kind === \"goto\" && !tabById.has(node.tab)) error(\"unknown-tab\", node.id, `The node goes to the unknown tab \"${node.tab}\".`);\n if (node.kind === \"question\" && node.sources.length === 0 && (node.reasoning ?? \"\").trim() === \"\") error(\"no-source\", node.id, \"The question cites no source and gives no reasoning.\");\n for (const id of node.sources ?? []) if (!sourceIds.has(id)) error(\"unknown-source\", node.id, `The node cites the unknown source \"${id}\".`);\n }\n if (!nodes.some((node) => node.kind === \"signal\")) error(\"no-signal\", \"chart\", \"The chart has no signal, so a reader cannot start.\");\n\n const seen = reached(nodes, byId);\n for (const node of nodes) if (!seen.has(node.id)) error(\"unreachable\", node.id, \"No signal reaches the node.\");\n const cycle = cycleNodes(nodes, byId);\n for (const id of cycle) error(\"cycle\", id, \"The node is in a cycle, so its path has no end.\");\n const limit = options.maxQuestions ?? 3;\n const depth = questionsToEnd(byId, cycle);\n for (const node of nodes) {\n const value = depth.get(node.id) ?? 0;\n if (node.kind === \"signal\" && value > limit) error(\"too-deep\", node.id, `A path from the signal has ${value} questions. The limit is ${limit}.`);\n }\n\n if (options.maxNodes !== undefined && nodes.length > options.maxNodes) error(\"too-many-nodes\", \"chart\", `The chart has ${nodes.length} nodes. The limit is ${options.maxNodes}.`);\n const ends = nodes.filter((node) => node.kind === \"goto\").length;\n if (options.maxEnds !== undefined && ends > options.maxEnds) error(\"too-many-ends\", \"chart\", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);\n\n const used = new Set(nodes.filter((node) => seen.has(node.id)).flatMap((node) => (node.kind === \"goto\" ? [node.tab] : [])));\n for (const tab of tabs) {\n for (const key of tab.keys) if (!known.has(key)) error(\"unknown-key\", tab.id, `The tab names the unknown key \"${key}\".`);\n const keys = new Set(tab.keys);\n if (keys.size > 0 && !steps.some((step) => keys.has(step.on) && tab.phases.includes(step.phase))) error(\"tab-without-steps\", tab.id, \"The tab has no step in its keys and phases.\");\n if (!used.has(tab.id)) error(\"unused-tab\", tab.id, \"No path of the chart goes to the tab.\");\n }\n const held = new Set([...used].flatMap((id) => tabById.get(id)?.keys ?? []));\n for (const key of options.cover ?? []) if (!held.has(key)) error(\"uncovered-key\", key, `No tab of the chart holds the key \"${key}\".`);\n return resultOf(out);\n}\n\n/** An edge of the master chart, for a renderer. */\nexport interface ChartEdge {\n readonly from: string;\n readonly to: string;\n /** The words of the answer. A signal edge has no label. */\n readonly label?: string;\n}\n\n/** A node of the master chart with its layer: the most edges from a signal to the node. */\nexport interface PlacedNode {\n readonly node: ChartNode;\n readonly layer: number;\n}\n\n/** The master chart, for a renderer: the nodes by layer, the edges and the tabs that the chart reaches. */\nexport interface MasterChart<P extends string = Phase> {\n readonly nodes: readonly PlacedNode[];\n readonly edges: readonly ChartEdge[];\n readonly tabs: readonly Tab<P>[];\n}\n\n/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */\nexport function masterChartOf<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[]): MasterChart<P> {\n const byId = new Map(nodes.map((node) => [node.id, node] as const));\n const cycle = cycleNodes(nodes, byId);\n const edges: ChartEdge[] = nodes.flatMap((node): ChartEdge[] => {\n if (node.kind === \"signal\") return [{ from: node.id, to: node.next }];\n if (node.kind === \"question\") return node.answers.map((answer) => ({ from: node.id, to: answer.next, label: answer.label }));\n return [];\n });\n const layer = new Map<string, number>();\n const into = new Map<string, string[]>();\n for (const edge of edges) into.set(edge.to, [...(into.get(edge.to) ?? []), edge.from]);\n const layerOf = (id: string): number => {\n const known = layer.get(id);\n if (known !== undefined) return known;\n const before = (into.get(id) ?? []).filter((from) => byId.has(from) && !cycle.has(from));\n const value = before.length === 0 ? 0 : 1 + Math.max(...before.map(layerOf));\n layer.set(id, value);\n return value;\n };\n const placed = nodes.filter((node) => !cycle.has(node.id)).map((node) => ({ node, layer: layerOf(node.id) }));\n placed.sort((a, b) => a.layer - b.layer);\n const tabIds = new Set(nodes.flatMap((node) => (node.kind === \"goto\" ? [node.tab] : [])));\n return { nodes: placed, edges, tabs: tabs.filter((tab) => tabIds.has(tab.id)) };\n}\n"],"mappings":";;;AAGA,MAAM,OAAO;AACb,MAAM,MAAM,KAAK;AACjB,MAAM,OAAO,IAAI;;AAEjB,MAAM,QAAQ,KAAK;AACnB,MAAM,OAAO,MAAM;;AAGnB,MAAa,kBAA0B;;AAcvC,MAAa,SAAS;CAAC;CAAS;CAAU;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;;AAM5E,MAAa,eAAkC;CAAC;CAAG;CAAY,IAAI;CAAM,IAAI;CAAK,IAAI;CAAM,IAAI;CAAO,IAAI;AAAI;;AAG/G,MAAa,eAAgD;CAC3D,OAAO;CACP,QAAQ;CACR,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;;AAGA,MAAa,SAAwB;CACnC,OAAO;CACP,QAAQ;CACR,OAAQ;EAAC;EAAM;EAAM;EAAM;EAAM;EAAM;CAAI,CAAC,CAAW,KAAK,OAAO,OAAO;EAAE;EAAO,MAAM,aAAa,MAAM;CAAE,EAAE;CAChH,QAAQ;AACV;;AAGA,SAAgB,SAA2B,QAAiC;CAC1E,OAAO;EAAC,OAAO;EAAO,OAAO;EAAQ,GAAG,OAAO,MAAM,KAAK,SAAS,KAAK,KAAK;CAAC;AAChF;;;;;;AAOA,SAAgB,QAA0B,QAAmB,SAAiB,SAAS,OAAU;CAC/F,IAAI,CAAC,OAAO,SAAS,OAAO,GAAG,M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ACrF,MAAM,WAAW,OAAuB;EACtC,MAAM,QAAQ,MAAM,IAAI,EAAE;EAC1B,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,MAAM,UAAU,KAAK,IAAI,EAAE,KAAK,CAAC,EAAA,CAAG,QAAQ,SAAS,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC;EACvF,MAAM,QAAQ,OAAO,WAAW,IAAI,IAAI,IAAI,KAAK,IAAI,GAAG,OAAO,IAAI,OAAO,CAAC;EAC3E,MAAM,IAAI,IAAI,KAAK;EACnB,OAAO;CACT;CACA,MAAM,SAAS,MAAM,QAAQ,SAAS,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,UAAU;EAAE;EAAM,OAAO,QAAQ,KAAK,EAAE;CAAE,EAAE;CAC5G,OAAO,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;CACvC,MAAM,SAAS,IAAI,IAAI,MAAM,SAAS,SAAU,KAAK,SAAS,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,CAAE,CAAC;CACxF,OAAO;EAAE,OAAO;EAAQ;EAAO,MAAM,KAAK,QAAQ,QAAQ,OAAO,IAAI,IAAI,EAAE,CAAC;CAAE;AAChF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/ladder.ts","../src/steps.ts","../src/coverage.ts","../src/rules.ts","../src/master.ts"],"sourcesContent":["// The time ladder of a plan: the phases before the start of an event, and the phases after it, each with its first second.\n\nconst MINUTE = 60;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\nconst WEEK = 7 * DAY;\n/** A month of the ladder is 30 days, and a year is 365 days. */\nconst MONTH = 30 * DAY;\nconst YEAR = 365 * DAY;\n\n/** This constant is the number of seconds in one day. */\nexport const SECONDS_PER_DAY: number = DAY;\n\n/** A ladder of phases. Each phase has a title that a print or a page shows. */\nexport interface Ladder<P extends string = string> {\n /** The phase before the start of an event, when no warning is live. */\n readonly ready: P;\n /** The phase before the start of an event, when a warning is live. */\n readonly warned: P;\n /** The phases after the start, in their sequence. Each phase starts at its second `from`. The first phase starts at 0. */\n readonly timed: readonly { readonly phase: P; readonly from: number }[];\n readonly titles: Readonly<Record<P, string>>;\n}\n\n/** The phases of the default ladder, in their sequence. */\nexport const PHASES = [\"ready\", \"warned\", \"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** One phase of the default ladder. */\nexport type Phase = (typeof PHASES)[number];\n\n/** The bounds of the phases `P0` to `P5`, in seconds: 0, 5 min, 5 h, 5 d, 5 wk, 5 mo and 5 yr. */\nexport const PHASE_BOUNDS: readonly number[] = [0, 5 * MINUTE, 5 * HOUR, 5 * DAY, 5 * WEEK, 5 * MONTH, 5 * YEAR];\n\n/** The words of each phase of the default ladder. */\nexport const PHASE_TITLES: Readonly<Record<Phase, string>> = {\n ready: \"Before an event\",\n warned: \"When a warning comes\",\n P0: \"In the first 5 minutes\",\n P1: \"From 5 minutes to 5 hours\",\n P2: \"From 5 hours to 5 days\",\n P3: \"From 5 days to 5 weeks\",\n P4: \"From 5 weeks to 5 months\",\n P5: \"From 5 months to 5 years\",\n};\n\n/** The default ladder: each phase after the start is approximately 60 times longer than the phase before it. */\nexport const LADDER: Ladder<Phase> = {\n ready: \"ready\",\n warned: \"warned\",\n timed: ([\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const).map((phase, i) => ({ phase, from: PHASE_BOUNDS[i] ?? 0 })),\n titles: PHASE_TITLES,\n};\n\n/** This function gives the phases of a ladder in their sequence: `ready`, `warned`, then the timed phases. */\nexport function phasesOf<P extends string>(ladder: Ladder<P>): readonly P[] {\n return [ladder.ready, ladder.warned, ...ladder.timed.map((step) => step.phase)];\n}\n\n/**\n * This function gives the phase of a time on a ladder, in seconds from the start of the event.\n * A negative time is before the start: it gives `warned` when a warning is live, else `ready`.\n * A time at a bound is in the later phase. A time after the start of the last phase stays in the last phase.\n */\nexport function phaseIn<P extends string>(ladder: Ladder<P>, seconds: number, warned = false): P {\n if (!Number.isFinite(seconds)) throw new RangeError(`phaseIn: the time ${String(seconds)} is not a finite number.`);\n if (seconds < 0) return warned ? ladder.warned : ladder.ready;\n let phase: P | undefined;\n for (const step of ladder.timed) if (seconds >= step.from) phase = step.phase;\n if (phase === undefined) throw new RangeError(\"phaseIn: the ladder has no timed phase that starts at 0.\");\n return phase;\n}\n\n/** This function gives the phase of a time on the default ladder. 5 minutes gives `P1`. */\nexport function phaseOf(seconds: number, warned = false): Phase {\n return phaseIn(LADDER, seconds, warned);\n}\n","// The steps of a plan, the query of the steps, the matrix of the library, and the step gate.\n\nimport { checkUnits, resultOf } from \"@mark1russell7/guidebook\";\nimport type { CitedUnit, Finding, GateResult, Source, SourceId, UseContext } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Society } from \"./master.ts\";\n\n/**\n * One action of a plan. A step belongs to a key and to a phase.\n * A key names a case (a kind of event) or a cut (a service that an event stops). A plan of a case is its own steps and the steps of its cuts.\n */\nexport interface Step<P extends string = Phase> {\n readonly id: string;\n /** The key of the step: a case or a cut. */\n readonly on: string;\n readonly phase: P;\n /** The needs that the step protects. */\n readonly needs: readonly string[];\n /** An optional condition: a Vex program over the live state. No `when` means always. */\n readonly when?: string;\n /**\n * The action, as one instruction in Simplified Technical English, in the words of the guidebook.\n * When the step has a `when`, this text names the condition in words, because a print cannot examine `when`.\n */\n readonly do: string;\n /** The parts, the resources and the topics that the step uses. */\n readonly uses?: readonly string[];\n /** The order of the step in its phase, from 1. */\n readonly order: number;\n /** The sources of the step. A step with no `reasoning` has one or more. */\n readonly sources: readonly SourceId[];\n /**\n * The reasoning of a strategy step from first principles, for a step that no source tells.\n * A step with a number in its text (a dose, a time or a safety limit) still cites a source.\n */\n readonly reasoning?: string;\n /** The states of society that the step is for. No `society` means each state. */\n readonly society?: readonly Society[];\n}\n\n/** A marked gap: a key and a phase that have no step on purpose, with the reason. */\nexport interface Gap<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n /** The reason, for example \"A house fire gives no warning.\" */\n readonly why: string;\n}\n\n/** A cell of the matrix of a library: the steps of one key in one phase, or the marked gap of the cell. */\nexport interface Cell<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n readonly steps: readonly Step<P>[];\n readonly gap?: Gap<P>;\n}\n\nconst byOrder = <P extends string>(a: Step<P>, b: Step<P>): number => a.order - b.order || a.id.localeCompare(b.id);\n\n/** The options of the steps query. */\nexport interface StepsForOptions {\n /** Only the steps for this state of society. A step with no `society` is for each state. */\n readonly society?: Society;\n}\n\n/**\n * This function gives the steps whose `on` is in `on` and whose phase is in `phases`.\n * The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.\n */\nexport function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[], options: StepsForOptions = {}): readonly Step<P>[] {\n const { society } = options;\n const fits = (step: Step<P>): boolean => society === undefined || step.society === undefined || step.society.includes(society);\n const out: Step<P>[] = [];\n const seen = new Set<string>();\n for (const key of on) {\n for (const phase of phases) {\n const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id) && fits(step)).sort(byOrder);\n for (const step of hits) {\n seen.add(step.id);\n out.push(step);\n }\n }\n }\n return out;\n}\n\n/** This function gives the matrix of a library: one row for each key of `on`, with one cell for each phase of `phases`. */\nexport function planMatrix<P extends string>(\n library: readonly Step<P>[],\n gaps: readonly Gap<P>[],\n on: readonly string[],\n phases: readonly P[],\n): readonly (readonly Cell<P>[])[] {\n return on.map((key) =>\n phases.map((phase) => {\n const steps = library.filter((step) => step.on === key && step.phase === phase).sort(byOrder);\n const gap = gaps.find((item) => item.on === key && item.phase === phase);\n return gap === undefined ? { on: key, phase, steps } : { on: key, phase, steps, gap };\n }),\n );\n}\n\n/** The codes of the findings of the step gate. The codes of the source gate also apply to the sources of the steps. */\nexport const STEP_FINDING_CODES = [\n \"duplicate-id\",\n \"empty-text\",\n \"no-source\",\n \"number-without-source\",\n \"empty-reasoning\",\n \"missing-source\",\n \"use-refused\",\n \"unknown-phase\",\n \"bad-order\",\n \"duplicate-order\",\n \"unmarked-gap\",\n \"gap-with-steps\",\n \"duplicate-gap\",\n \"empty-reason\",\n] as const;\n\n/** A code of a finding of the step gate. */\nexport type StepFindingCode = (typeof STEP_FINDING_CODES)[number];\n\n/** A finding of the step gate. */\nexport type StepFinding = Finding<StepFindingCode, \"step\" | \"gap\" | \"cell\">;\n\n/** The options of the step gate. */\nexport interface StepGateOptions<P extends string> extends UseContext {\n /** The phases that a step can have. */\n readonly phases: readonly P[];\n /** The keys of the matrix. With them, the gate finds each cell that has no step and no marked gap. */\n readonly on?: readonly string[];\n /** The marked gaps of the library. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** This function gives one summary unit for each source of each step, so the source gate examines the steps. */\nexport function unitsOf<P extends string>(steps: readonly Step<P>[]): readonly CitedUnit[] {\n return steps.flatMap((step) => step.sources.map((source) => ({ id: `${step.id}@${source}`, use: \"summary\" as const, text: step.do, source })));\n}\n\n/**\n * This function applies the step gate. It examines the ids, the text, the sources, the phases and the order of each step.\n * It examines the sources with the source gate: the text of a step is a summary of each of its sources.\n * With `on`, it also finds each cell of the matrix that has no step and no marked gap.\n */\nexport function checkSteps<P extends string>(steps: readonly Step<P>[], sources: readonly Source[], options: StepGateOptions<P>): GateResult<StepFinding> {\n const out: StepFinding[] = [];\n const error = (code: StepFindingCode, record: StepFinding[\"record\"], id: string, message: string): void => {\n out.push({ level: \"error\", code, record, id, message });\n };\n const phases = new Set<string>(options.phases);\n const ids = new Set<string>();\n const orders = new Map<string, string>();\n for (const step of steps) {\n if (ids.has(step.id)) error(\"duplicate-id\", \"step\", step.id, `Two steps have the id \"${step.id}\".`);\n ids.add(step.id);\n if (step.do.trim() === \"\") error(\"empty-text\", \"step\", step.id, `The step \"${step.id}\" has no text.`);\n if (step.reasoning !== undefined && step.reasoning.trim() === \"\") error(\"empty-reasoning\", \"step\", step.id, `The step \"${step.id}\" has an empty reasoning.`);\n if (step.sources.length === 0) {\n if (step.reasoning === undefined) error(\"no-source\", \"step\", step.id, `The step \"${step.id}\" cites no source and gives no reasoning.`);\n else if (/[0-9]/.test(step.do)) error(\"number-without-source\", \"step\", step.id, `The step \"${step.id}\" has a number, so it needs a source.`);\n }\n if (!phases.has(step.phase)) error(\"unknown-phase\", \"step\", step.id, `The step \"${step.id}\" has the unknown phase \"${step.phase}\".`);\n if (!Number.isInteger(step.order) || step.order < 1) error(\"bad-order\", \"step\", step.id, `The step \"${step.id}\" has the order ${String(step.order)}. It needs an integer from 1.`);\n const cell = `${step.on}\\u0000${step.phase}\\u0000${String(step.order)}`;\n const other = orders.get(cell);\n if (other !== undefined) error(\"duplicate-order\", \"step\", step.id, `The steps \"${other}\" and \"${step.id}\" have the same order in \"${step.on}\", phase \"${step.phase}\".`);\n else orders.set(cell, step.id);\n }\n for (const finding of checkUnits(unitsOf(steps), sources, options)) {\n if (finding.code !== \"missing-source\" && finding.code !== \"use-refused\") continue;\n const id = finding.id.slice(0, finding.id.lastIndexOf(\"@\"));\n out.push({ level: finding.level, code: finding.code, record: \"step\", id, message: finding.message.replace(`unit \"${finding.id}\"`, `step \"${id}\"`) });\n }\n out.push(...checkGaps(steps, options));\n return resultOf(out);\n}\n\nfunction checkGaps<P extends string>(steps: readonly Step<P>[], options: StepGateOptions<P>): StepFinding[] {\n const out: StepFinding[] = [];\n const gaps = options.gaps ?? [];\n const seen = new Set<string>();\n for (const gap of gaps) {\n const id = `${gap.on}/${gap.phase}`;\n if (seen.has(id)) out.push({ level: \"error\", code: \"duplicate-gap\", record: \"gap\", id, message: `Two gaps mark \"${gap.on}\" in phase \"${gap.phase}\".` });\n seen.add(id);\n if (gap.why.trim() === \"\") out.push({ level: \"error\", code: \"empty-reason\", record: \"gap\", id, message: `The gap of \"${gap.on}\" in phase \"${gap.phase}\" gives no reason.` });\n const count = steps.filter((step) => step.on === gap.on && step.phase === gap.phase).length;\n if (count > 0) out.push({ level: \"error\", code: \"gap-with-steps\", record: \"gap\", id, message: `A gap marks \"${gap.on}\" in phase \"${gap.phase}\", but the cell has ${String(count)} steps.` });\n if (!options.phases.includes(gap.phase)) out.push({ level: \"error\", code: \"unknown-phase\", record: \"gap\", id, message: `The gap of \"${gap.on}\" has the unknown phase \"${gap.phase}\".` });\n }\n if (options.on === undefined) return out;\n for (const row of planMatrix(steps, gaps, options.on, options.phases)) {\n for (const cell of row) {\n const id = `${cell.on}/${cell.phase}`;\n if (cell.steps.length === 0 && cell.gap === undefined) {\n out.push({ level: \"error\", code: \"unmarked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\", and no gap marks the cell.` });\n }\n }\n }\n return out;\n}\n","// The coverage gate: each key of a catalog has steps in each phase of a set. A marked gap does not pass it.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult } from \"@mark1russell7/guidebook\";\nimport { planMatrix, type Gap, type Step } from \"./steps.ts\";\n\n/** The horizons of a plan: the phases from the first 5 minutes to 5 years. The coverage gate examines them by default. */\nexport const HORIZONS = [\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** The codes of the findings of the coverage gate. */\nexport const COVERAGE_FINDING_CODES = [\"no-step\", \"marked-gap\"] as const;\n\n/** A code of a finding of the coverage gate. */\nexport type CoverageFindingCode = (typeof COVERAGE_FINDING_CODES)[number];\n\n/** A finding of the coverage gate. Its `id` is `<key>/<phase>`. */\nexport type CoverageFinding = Finding<CoverageFindingCode, \"cell\">;\n\n/** The options of the coverage gate. */\nexport interface CoverageOptions<P extends string> {\n /** The keys of the catalog. Each key needs steps in each phase. */\n readonly on: readonly string[];\n /** The phases that each key needs. */\n readonly phases: readonly P[];\n /** The marked gaps of the library. The gate shows the reason of a gap, but the gap does not pass. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** The coverage of one key: the phases with steps and the phases with no step. */\nexport interface KeyCoverage<P extends string> {\n readonly on: string;\n readonly covered: readonly P[];\n readonly missing: readonly P[];\n}\n\n/** This function gives the coverage of each key of `on` over `phases`, in the sequence of `on`. */\nexport function coverageOf<P extends string>(steps: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly KeyCoverage<P>[] {\n return planMatrix(steps, [], on, phases).map((row, index) => ({\n on: on[index] ?? \"\",\n covered: row.filter((cell) => cell.steps.length > 0).map((cell) => cell.phase),\n missing: row.filter((cell) => cell.steps.length === 0).map((cell) => cell.phase),\n }));\n}\n\n/**\n * This function applies the coverage gate. Each key of `on` needs one or more steps in each phase of `phases`.\n * A cell with no step is an error, also when a gap marks it: the finding `marked-gap` gives the reason of the gap.\n * Thus a key with no step shows each of its gaps, and it does not pass.\n */\nexport function checkCoverage<P extends string>(steps: readonly Step<P>[], options: CoverageOptions<P>): GateResult<CoverageFinding> {\n const out: CoverageFinding[] = [];\n for (const row of planMatrix(steps, options.gaps ?? [], options.on, options.phases)) {\n for (const cell of row) {\n if (cell.steps.length > 0) continue;\n const id = `${cell.on}/${cell.phase}`;\n out.push(\n cell.gap === undefined\n ? { level: \"error\", code: \"no-step\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\".` }\n : { level: \"error\", code: \"marked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\". The gap gives the reason: ${cell.gap.why}` },\n );\n }\n }\n return resultOf(out);\n}\n","// The decision chart: trigger rules as data. Each rule names a trigger, the keys of the trigger and a target in the steps.\n// The rule gate examines that each key is known, each target has steps and each rule cites its sources.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult, Source } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Step } from \"./steps.ts\";\n\n/**\n * The kinds of rule, in the sequence of the chart.\n * The chart asks first for the place. Then it asks for an immediate danger and for the cuts.\n * Then it asks when to stay, to go or to change the plan.\n */\nexport const RULE_KINDS = [\"place\", \"reflex\", \"module\", \"stay\", \"go\", \"fallback\", \"long-plan\"] as const;\n\n/** A kind of rule. */\nexport type RuleKind = (typeof RULE_KINDS)[number];\n\n/** The words of each kind of rule, for a chart. */\nexport const RULE_KIND_TITLES: Readonly<Record<RuleKind, string>> = {\n place: \"Where am I?\",\n reflex: \"Is there an immediate danger?\",\n module: \"What is cut?\",\n stay: \"When do I stay?\",\n go: \"When do I go?\",\n fallback: \"When do I go to a fallback place?\",\n \"long-plan\": \"When do I change to the long plan?\",\n};\n\n/** The target of a rule: the steps of a key in the given phases. */\nexport interface RuleTarget<P extends string = Phase> {\n readonly on: string;\n readonly phases: readonly P[];\n}\n\n/** A trigger rule of the decision chart. */\nexport interface Rule<P extends string = Phase> {\n readonly id: string;\n readonly kind: RuleKind;\n /** The trigger, as one sentence in Simplified Technical English. A print shows it. */\n readonly when: string;\n /** The action, as one instruction. A print shows it with the target. */\n readonly then: string;\n /** The keys that the trigger names: cases, cuts or needs. */\n readonly on: readonly string[];\n /** The steps that the rule sends the reader to. A rule of the kind `place` has no target, because the places are input data. */\n readonly target?: RuleTarget<P>;\n /** The rank in its kind. A rule with a lower rank comes first. */\n readonly rank: number;\n /** The ids of the sources that tell the trigger and the action. */\n readonly sources: readonly string[];\n}\n\n/** The codes of the findings of the rule gate. */\nexport const RULE_FINDING_CODES = [\"duplicate-id\", \"unknown-key\", \"no-target\", \"target-without-steps\", \"no-source\", \"unknown-source\"] as const;\n\n/** A code of a finding of the rule gate. */\nexport type RuleFindingCode = (typeof RULE_FINDING_CODES)[number];\n\n/** A finding of the rule gate. */\nexport type RuleFinding = Finding<RuleFindingCode, \"rule\">;\n\n/** The options of the rule gate. */\nexport interface RuleGateOptions {\n /** The known keys: the cases, the cuts and the needs. */\n readonly on: readonly string[];\n}\n\n/**\n * This function applies the rule gate.\n * Each key of a rule is known. Each rule other than `place` has a target with one or more steps. Each rule cites a known source.\n */\nexport function checkRules<P extends string>(rules: readonly Rule<P>[], steps: readonly Step<P>[], sources: readonly Source[], options: RuleGateOptions): GateResult<RuleFinding> {\n const out: RuleFinding[] = [];\n const known = new Set(options.on);\n const sourceIds = new Set(sources.map((source) => source.id));\n const seen = new Set<string>();\n const error = (code: RuleFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"rule\", id, message });\n };\n for (const rule of rules) {\n if (seen.has(rule.id)) error(\"duplicate-id\", rule.id, `Two rules have the id \"${rule.id}\".`);\n seen.add(rule.id);\n for (const key of rule.on) if (!known.has(key)) error(\"unknown-key\", rule.id, `The rule names the unknown key \"${key}\".`);\n if (rule.target === undefined) {\n if (rule.kind !== \"place\") error(\"no-target\", rule.id, `The rule of the kind \"${rule.kind}\" has no target.`);\n } else {\n const { on, phases } = rule.target;\n if (!known.has(on)) error(\"unknown-key\", rule.id, `The target names the unknown key \"${on}\".`);\n else if (!steps.some((step) => step.on === on && phases.includes(step.phase))) {\n error(\"target-without-steps\", rule.id, `The target \"${on}\" has no step in the phases ${phases.join(\", \")}.`);\n }\n }\n if (rule.sources.length === 0) error(\"no-source\", rule.id, \"The rule cites no source.\");\n for (const id of rule.sources) if (!sourceIds.has(id)) error(\"unknown-source\", rule.id, `The rule cites the unknown source \"${id}\".`);\n }\n return resultOf(out);\n}\n\n/** One question of the chart: a kind of rule and its rules in the sequence of their rank. */\nexport interface ChartQuestion<P extends string = Phase> {\n readonly kind: RuleKind;\n readonly title: string;\n readonly rules: readonly Rule<P>[];\n}\n\n/** This function gives the chart of a set of rules: one question for each kind that has rules, in the sequence of `RULE_KINDS`. */\nexport function chartOf<P extends string>(rules: readonly Rule<P>[]): readonly ChartQuestion<P>[] {\n return RULE_KINDS.flatMap((kind) => {\n const ofKind = rules.filter((rule) => rule.kind === kind).sort((a, b) => a.rank - b.rank || a.id.localeCompare(b.id));\n return ofKind.length === 0 ? [] : [{ kind, title: RULE_KIND_TITLES[kind], rules: ofKind }];\n });\n}\n","// The master chart: one chart for any disaster, as data. A reader starts at a signal, answers a few questions and goes to a tab.\n// A tab is a section of a printed plan: a set of keys and phases. The print gives each tab its page.\n\nimport { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult, Source } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Step } from \"./steps.ts\";\n\n/** The states of society after an event, from a society that works to a society that does not work. */\nexport const SOCIETY_STATES = [\"works\", \"partly\", \"none\"] as const;\n\n/** A state of society: the emergency services, the shops, the grid and the law work, work in part or do not work. */\nexport type Society = (typeof SOCIETY_STATES)[number];\n\n/** The words of each state of society, for a chart. */\nexport const SOCIETY_TITLES: Readonly<Record<Society, string>> = {\n works: \"Society works\",\n partly: \"Society works in part\",\n none: \"Society does not work\",\n};\n\n/**\n * A tab of a printed plan: the steps of its keys in its phases.\n * Each state of society is a section in the tab, so a tab is for one need or one subject, not for one state.\n */\nexport interface Tab<P extends string = Phase> {\n readonly id: string;\n readonly title: string;\n /** The keys of the tab: cases, cuts or needs. A tab of reference text or of a chart has no keys. */\n readonly keys: readonly string[];\n readonly phases: readonly P[];\n /** The most pages that the print of the tab can use. */\n readonly pages?: number;\n}\n\n/** An answer to a question of the chart. */\nexport interface ChartAnswer {\n /** The words of the answer, for a chart. */\n readonly label: string;\n /** The id of the next node. */\n readonly next: string;\n /** The state of society that the answer tells, if any. */\n readonly society?: Society;\n}\n\n/** A start of the chart: a thing that a reader sees or hears. */\nexport interface SignalNode {\n readonly id: string;\n readonly kind: \"signal\";\n readonly text: string;\n readonly next: string;\n readonly sources?: readonly string[];\n}\n\n/** A question of the chart, with two or more answers. */\nexport interface QuestionNode {\n readonly id: string;\n readonly kind: \"question\";\n readonly text: string;\n readonly answers: readonly ChartAnswer[];\n /** The ids of the sources that tell the question and its answers. */\n readonly sources: readonly string[];\n /** The reasoning of the question from first principles, for a question that no source tells. */\n readonly reasoning?: string;\n}\n\n/** An end of the chart: an instruction that sends the reader to a tab. */\nexport interface GotoNode {\n readonly id: string;\n readonly kind: \"goto\";\n readonly text: string;\n readonly tab: string;\n readonly sources?: readonly string[];\n /** The end also shows the card of the hazard of the reader, if the reader came with one. */\n readonly card?: true;\n}\n\n/** A node of the master chart. */\nexport type ChartNode = SignalNode | QuestionNode | GotoNode;\n\n/** The codes of the findings of the chart gate. */\nexport const MASTER_FINDING_CODES = [\n \"duplicate-id\",\n \"unknown-node\",\n \"unknown-tab\",\n \"unknown-key\",\n \"few-answers\",\n \"no-signal\",\n \"unreachable\",\n \"cycle\",\n \"too-deep\",\n \"too-many-nodes\",\n \"too-many-ends\",\n \"tab-without-steps\",\n \"unused-tab\",\n \"uncovered-key\",\n \"no-source\",\n \"unknown-source\",\n \"bad-schema\",\n \"unknown-start\",\n \"unknown-catalog\",\n \"unknown-hazard\",\n \"duplicate-hazard\",\n \"missing-hazard\",\n \"unknown-signal\",\n \"unknown-entry\",\n \"unknown-card-step\",\n \"no-route\",\n] as const;\n\n/** A code of a finding of the chart gate. */\nexport type MasterFindingCode = (typeof MASTER_FINDING_CODES)[number];\n\n/** A finding of the chart gate. */\nexport type MasterFinding = Finding<MasterFindingCode, \"chart\">;\n\n/** The options of the chart gate. */\nexport interface MasterGateOptions {\n /** The known keys: the cases, the cuts and the needs. */\n readonly on: readonly string[];\n /** The keys that a tab of the chart must hold. No `cover` means no key. */\n readonly cover?: readonly string[];\n /** The most questions on a path from a signal to a tab. The default is 3. */\n readonly maxQuestions?: number;\n /** The most nodes that the print of the chart can hold. No `maxNodes` means no limit. */\n readonly maxNodes?: number;\n /** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */\n readonly maxEnds?: number;\n /** The ids of the tabs that a reader reaches by another way than an end, for example the catalog through the cards. */\n readonly used?: readonly string[];\n}\n\n/** The ids of the nodes that come after a node. */\nfunction nextOf(node: ChartNode): readonly string[] {\n if (node.kind === \"signal\") return [node.next];\n if (node.kind === \"question\") return node.answers.map((answer) => answer.next);\n return [];\n}\n\n/** The nodes in a cycle. A chart with a cycle has no end on that path. */\nfunction cycleNodes(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {\n const next = (id: string): readonly string[] => {\n const node = byId.get(id);\n return node === undefined ? [] : nextOf(node).filter((to) => byId.has(to));\n };\n const out = new Set<string>();\n for (const group of stronglyConnectedComponents(nodes.map((node) => node.id), next)) {\n const [first] = group;\n if (group.length > 1 || (first !== undefined && next(first).includes(first))) for (const id of group) out.add(id);\n }\n return out;\n}\n\n/** The most questions from each node to an end, on a chart with no cycle. */\nfunction questionsToEnd(byId: ReadonlyMap<string, ChartNode>, skip: ReadonlySet<string>): Map<string, number> {\n const memo = new Map<string, number>();\n const walk = (id: string): number => {\n const known = memo.get(id);\n if (known !== undefined) return known;\n const node = byId.get(id);\n if (node === undefined || skip.has(id)) return 0;\n const rest = Math.max(0, ...nextOf(node).map(walk));\n const value = (node.kind === \"question\" ? 1 : 0) + rest;\n memo.set(id, value);\n return value;\n };\n for (const id of byId.keys()) walk(id);\n return memo;\n}\n\n/** The ids of the nodes that a signal reaches. */\nfunction reached(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {\n const seen = new Set<string>();\n const stack = nodes.filter((node) => node.kind === \"signal\").map((node) => node.id);\n for (let id = stack.pop(); id !== undefined; id = stack.pop()) {\n if (seen.has(id)) continue;\n seen.add(id);\n const node = byId.get(id);\n if (node !== undefined) stack.push(...nextOf(node));\n }\n return seen;\n}\n\n/**\n * This function applies the chart gate.\n * Each node is known and reached, and each path ends at a known tab after a few questions.\n * Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.\n */\nexport function checkMasterChart<P extends string>(\n nodes: readonly ChartNode[],\n tabs: readonly Tab<P>[],\n steps: readonly Step<P>[],\n sources: readonly Source[],\n options: MasterGateOptions,\n): GateResult<MasterFinding> {\n const out: MasterFinding[] = [];\n const error = (code: MasterFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"chart\", id, message });\n };\n const byId = new Map<string, ChartNode>();\n for (const node of nodes) {\n if (byId.has(node.id)) error(\"duplicate-id\", node.id, `Two nodes have the id \"${node.id}\".`);\n byId.set(node.id, node);\n }\n const tabById = new Map<string, Tab<P>>();\n for (const tab of tabs) {\n if (tabById.has(tab.id)) error(\"duplicate-id\", tab.id, `Two tabs have the id \"${tab.id}\".`);\n tabById.set(tab.id, tab);\n }\n const known = new Set(options.on);\n const sourceIds = new Set(sources.map((source) => source.id));\n\n for (const node of nodes) {\n for (const to of nextOf(node)) if (!byId.has(to)) error(\"unknown-node\", node.id, `The node goes to the unknown node \"${to}\".`);\n if (node.kind === \"question\" && node.answers.length < 2) error(\"few-answers\", node.id, \"The question has fewer than 2 answers.\");\n if (node.kind === \"goto\" && !tabById.has(node.tab)) error(\"unknown-tab\", node.id, `The node goes to the unknown tab \"${node.tab}\".`);\n if (node.kind === \"question\" && node.sources.length === 0 && (node.reasoning ?? \"\").trim() === \"\") error(\"no-source\", node.id, \"The question cites no source and gives no reasoning.\");\n for (const id of node.sources ?? []) if (!sourceIds.has(id)) error(\"unknown-source\", node.id, `The node cites the unknown source \"${id}\".`);\n }\n if (!nodes.some((node) => node.kind === \"signal\")) error(\"no-signal\", \"chart\", \"The chart has no signal, so a reader cannot start.\");\n\n const seen = reached(nodes, byId);\n for (const node of nodes) if (!seen.has(node.id)) error(\"unreachable\", node.id, \"No signal reaches the node.\");\n const cycle = cycleNodes(nodes, byId);\n for (const id of cycle) error(\"cycle\", id, \"The node is in a cycle, so its path has no end.\");\n const limit = options.maxQuestions ?? 3;\n const depth = questionsToEnd(byId, cycle);\n for (const node of nodes) {\n const value = depth.get(node.id) ?? 0;\n if (node.kind === \"signal\" && value > limit) error(\"too-deep\", node.id, `A path from the signal has ${value} questions. The limit is ${limit}.`);\n }\n\n if (options.maxNodes !== undefined && nodes.length > options.maxNodes) error(\"too-many-nodes\", \"chart\", `The chart has ${nodes.length} nodes. The limit is ${options.maxNodes}.`);\n const ends = nodes.filter((node) => node.kind === \"goto\").length;\n if (options.maxEnds !== undefined && ends > options.maxEnds) error(\"too-many-ends\", \"chart\", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);\n\n const used = new Set([...(options.used ?? []), ...nodes.filter((node) => seen.has(node.id)).flatMap((node) => (node.kind === \"goto\" ? [node.tab] : []))]);\n for (const tab of tabs) {\n for (const key of tab.keys) if (!known.has(key)) error(\"unknown-key\", tab.id, `The tab names the unknown key \"${key}\".`);\n const keys = new Set(tab.keys);\n if (keys.size > 0 && !steps.some((step) => keys.has(step.on) && tab.phases.includes(step.phase))) error(\"tab-without-steps\", tab.id, \"The tab has no step in its keys and phases.\");\n if (!used.has(tab.id)) error(\"unused-tab\", tab.id, \"No path of the chart goes to the tab.\");\n }\n const held = new Set([...used].flatMap((id) => tabById.get(id)?.keys ?? []));\n for (const key of options.cover ?? []) if (!held.has(key)) error(\"uncovered-key\", key, `No tab of the chart holds the key \"${key}\".`);\n return resultOf(out);\n}\n\n/** An edge of the master chart, for a renderer. */\nexport interface ChartEdge {\n readonly from: string;\n readonly to: string;\n /** The words of the answer. A signal edge has no label. */\n readonly label?: string;\n}\n\n/** A node of the master chart with its layer: the most edges from a signal to the node. */\nexport interface PlacedNode {\n readonly node: ChartNode;\n readonly layer: number;\n}\n\n/** The master chart, for a renderer: the nodes by layer, the edges and the tabs that the chart reaches. */\nexport interface MasterChart<P extends string = Phase> {\n readonly nodes: readonly PlacedNode[];\n readonly edges: readonly ChartEdge[];\n readonly tabs: readonly Tab<P>[];\n}\n\n/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */\nexport function masterChartOf<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[]): MasterChart<P> {\n const byId = new Map(nodes.map((node) => [node.id, node] as const));\n const cycle = cycleNodes(nodes, byId);\n const edges: ChartEdge[] = nodes.flatMap((node): ChartEdge[] => {\n if (node.kind === \"signal\") return [{ from: node.id, to: node.next }];\n if (node.kind === \"question\") return node.answers.map((answer) => ({ from: node.id, to: answer.next, label: answer.label }));\n return [];\n });\n const layer = new Map<string, number>();\n const into = new Map<string, string[]>();\n for (const edge of edges) into.set(edge.to, [...(into.get(edge.to) ?? []), edge.from]);\n const layerOf = (id: string): number => {\n const known = layer.get(id);\n if (known !== undefined) return known;\n const before = (into.get(id) ?? []).filter((from) => byId.has(from) && !cycle.has(from));\n const value = before.length === 0 ? 0 : 1 + Math.max(...before.map(layerOf));\n layer.set(id, value);\n return value;\n };\n const placed = nodes.filter((node) => !cycle.has(node.id)).map((node) => ({ node, layer: layerOf(node.id) }));\n placed.sort((a, b) => a.layer - b.layer);\n const tabIds = new Set(nodes.flatMap((node) => (node.kind === \"goto\" ? [node.tab] : [])));\n return { nodes: placed, edges, tabs: tabs.filter((tab) => tabIds.has(tab.id)) };\n}\n\n/** The name and the major version of the schema of the master graph. A reader refuses a graph with another value. */\nexport const GRAPH_SCHEMA = \"guidebook-graph/1\";\n\n/** A row of the hazard catalog: an index into the graph, with the facts that are unique to the hazard. */\nexport interface HazardRow {\n /** The key of the case. */\n readonly key: string;\n readonly title: string;\n /** The ids of the signal nodes that the hazard gives. */\n readonly signals: readonly string[];\n /** The id of the node where a reader with this hazard joins the graph. */\n readonly entry: string;\n /** The ids of the steps of the case that are unique to it: its card. */\n readonly card: readonly string[];\n}\n\n/**\n * The master graph: one value that a printed binder and an app read.\n * The edges come from the nodes with `masterChartOf`, so no second list can disagree with them.\n */\nexport interface MasterGraph<P extends string = Phase> {\n readonly schema: typeof GRAPH_SCHEMA;\n /** The id of the tab of the chart itself, the entry of the binder. */\n readonly start: string;\n /** The id of the tab of the hazard catalog. An end with `card` shows the card from it. */\n readonly catalog: string;\n /** The states of society, in the sequence of the sections of each tab. */\n readonly societies: readonly Society[];\n readonly nodes: readonly ChartNode[];\n readonly tabs: readonly Tab<P>[];\n readonly hazards: readonly HazardRow[];\n}\n\n/** The options of the graph gate: the options of the chart gate and the cases that the catalog must index. */\nexport interface GraphGateOptions extends MasterGateOptions {\n /** The keys of the cases. Each case has one row of the catalog. */\n readonly cases: readonly string[];\n}\n\n/**\n * This function applies the graph gate: the chart gate, and the gate of the hazard rows.\n *\n * The start tab and the catalog tab are tabs. The start tab needs no path. An end with `card` uses the catalog tab.\n * Each case has one row. Each row names known signals, a known entry and steps of its case.\n * Each entry reaches an end whose tab has keys.\n */\nexport function checkMasterGraph<P extends string>(\n graph: MasterGraph<P>,\n steps: readonly Step<P>[],\n sources: readonly Source[],\n options: GraphGateOptions,\n): GateResult<MasterFinding> {\n const out: MasterFinding[] = [];\n const error = (code: MasterFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"chart\", id, message });\n };\n if (graph.schema !== GRAPH_SCHEMA) error(\"bad-schema\", \"graph\", `The schema is \"${String(graph.schema)}\", not \"${GRAPH_SCHEMA}\".`);\n const tabIds = new Set(graph.tabs.map((tab) => tab.id));\n if (!tabIds.has(graph.start)) error(\"unknown-start\", graph.start, `The start tab \"${graph.start}\" is not a tab.`);\n if (!tabIds.has(graph.catalog)) error(\"unknown-catalog\", graph.catalog, `The catalog tab \"${graph.catalog}\" is not a tab.`);\n const withCards = graph.nodes.some((node) => node.kind === \"goto\" && node.card === true);\n const chartTabs = graph.tabs.filter((tab) => tab.id !== graph.start);\n const chart = checkMasterChart(graph.nodes, chartTabs, steps, sources, { ...options, used: [...(options.used ?? []), ...(withCards ? [graph.catalog] : [])] });\n out.push(...chart.findings);\n\n const byId = new Map(graph.nodes.map((node) => [node.id, node] as const));\n const stepById = new Map(steps.map((step) => [step.id, step] as const));\n const tabById = new Map(graph.tabs.map((tab) => [tab.id, tab] as const));\n const cases = new Set(options.cases);\n const rows = new Set<string>();\n const routes = (id: string, seen = new Set<string>()): boolean => {\n if (seen.has(id)) return false;\n seen.add(id);\n const node = byId.get(id);\n if (node === undefined) return false;\n if (node.kind === \"goto\") return (tabById.get(node.tab)?.keys.length ?? 0) > 0;\n return nextOf(node).some((to) => routes(to, seen));\n };\n for (const row of graph.hazards) {\n if (rows.has(row.key)) error(\"duplicate-hazard\", row.key, `Two rows of the catalog have the key \"${row.key}\".`);\n rows.add(row.key);\n if (!cases.has(row.key)) error(\"unknown-hazard\", row.key, `The row names the unknown case \"${row.key}\".`);\n if (row.signals.length === 0) error(\"unknown-signal\", row.key, \"The row names no signal.\");\n for (const id of row.signals) if (byId.get(id)?.kind !== \"signal\") error(\"unknown-signal\", row.key, `The row names \"${id}\", which is not a signal node.`);\n if (!byId.has(row.entry)) error(\"unknown-entry\", row.key, `The row names the unknown entry \"${row.entry}\".`);\n else if (!routes(row.entry)) error(\"no-route\", row.key, \"No path from the entry of the row goes to a tab with keys.\");\n for (const id of row.card) if (stepById.get(id)?.on !== row.key) error(\"unknown-card-step\", row.key, `The card names \"${id}\", which is not a step of the case.`);\n }\n for (const key of options.cases) if (!rows.has(key)) error(\"missing-hazard\", key, `The catalog has no row for the case \"${key}\".`);\n return resultOf(out);\n}\n"],"mappings":";;;AAGA,MAAM,OAAO;AACb,MAAM,MAAM,KAAK;AACjB,MAAM,OAAO,IAAI;;AAEjB,MAAM,QAAQ,KAAK;AACnB,MAAM,OAAO,MAAM;;AAGnB,MAAa,kBAA0B;;AAcvC,MAAa,SAAS;CAAC;CAAS;CAAU;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;;AAM5E,MAAa,eAAkC;CAAC;CAAG;CAAY,IAAI;CAAM,IAAI;CAAK,IAAI;CAAM,IAAI;CAAO,IAAI;AAAI;;AAG/G,MAAa,eAAgD;CAC3D,OAAO;CACP,QAAQ;CACR,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;;AAGA,MAAa,SAAwB;CACnC,OAAO;CACP,QAAQ;CACR,OAAQ;EAAC;EAAM;EAAM;EAAM;EAAM;EAAM;CAAI,CAAC,CAAW,KAAK,OAAO,OAAO;EAAE;EAAO,MAAM,aAAa,MAAM;CAAE,EAAE;CAChH,QAAQ;AACV;;AAGA,SAAgB,SAA2B,QAAiC;CAC1E,OAAO;EAAC,OA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@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/guidebook-plans",
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "description": "The plans add-on of the guidebook: a time ladder of phases, steps keyed by a case or a cut and a phase, the steps query, the matrix of a library with its marked gaps, and the step gate.",
6
6
  "keywords": [
7
7
  "guidebook",
package/src/index.ts CHANGED
@@ -9,5 +9,5 @@ export { COVERAGE_FINDING_CODES, HORIZONS, checkCoverage, coverageOf } from "./c
9
9
  export type { CoverageFinding, CoverageFindingCode, CoverageOptions, KeyCoverage } from "./coverage.ts";
10
10
  export { RULE_FINDING_CODES, RULE_KINDS, RULE_KIND_TITLES, chartOf, checkRules } from "./rules.ts";
11
11
  export type { ChartQuestion, Rule, RuleFinding, RuleFindingCode, RuleGateOptions, RuleKind, RuleTarget } from "./rules.ts";
12
- export { MASTER_FINDING_CODES, SOCIETY_STATES, SOCIETY_TITLES, checkMasterChart, masterChartOf } from "./master.ts";
13
- export type { ChartAnswer, ChartEdge, ChartNode, GotoNode, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, PlacedNode, QuestionNode, SignalNode, Society, Tab } from "./master.ts";
12
+ export { GRAPH_SCHEMA, MASTER_FINDING_CODES, SOCIETY_STATES, SOCIETY_TITLES, checkMasterChart, checkMasterGraph, masterChartOf } from "./master.ts";
13
+ export type { ChartAnswer, ChartEdge, ChartNode, GotoNode, GraphGateOptions, HazardRow, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, MasterGraph, PlacedNode, QuestionNode, SignalNode, Society, Tab } from "./master.ts";
package/src/master.ts CHANGED
@@ -72,6 +72,8 @@ export interface GotoNode {
72
72
  readonly text: string;
73
73
  readonly tab: string;
74
74
  readonly sources?: readonly string[];
75
+ /** The end also shows the card of the hazard of the reader, if the reader came with one. */
76
+ readonly card?: true;
75
77
  }
76
78
 
77
79
  /** A node of the master chart. */
@@ -95,6 +97,16 @@ export const MASTER_FINDING_CODES = [
95
97
  "uncovered-key",
96
98
  "no-source",
97
99
  "unknown-source",
100
+ "bad-schema",
101
+ "unknown-start",
102
+ "unknown-catalog",
103
+ "unknown-hazard",
104
+ "duplicate-hazard",
105
+ "missing-hazard",
106
+ "unknown-signal",
107
+ "unknown-entry",
108
+ "unknown-card-step",
109
+ "no-route",
98
110
  ] as const;
99
111
 
100
112
  /** A code of a finding of the chart gate. */
@@ -115,6 +127,8 @@ export interface MasterGateOptions {
115
127
  readonly maxNodes?: number;
116
128
  /** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */
117
129
  readonly maxEnds?: number;
130
+ /** The ids of the tabs that a reader reaches by another way than an end, for example the catalog through the cards. */
131
+ readonly used?: readonly string[];
118
132
  }
119
133
 
120
134
  /** The ids of the nodes that come after a node. */
@@ -221,7 +235,7 @@ export function checkMasterChart<P extends string>(
221
235
  const ends = nodes.filter((node) => node.kind === "goto").length;
222
236
  if (options.maxEnds !== undefined && ends > options.maxEnds) error("too-many-ends", "chart", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);
223
237
 
224
- const used = new Set(nodes.filter((node) => seen.has(node.id)).flatMap((node) => (node.kind === "goto" ? [node.tab] : [])));
238
+ const used = new Set([...(options.used ?? []), ...nodes.filter((node) => seen.has(node.id)).flatMap((node) => (node.kind === "goto" ? [node.tab] : []))]);
225
239
  for (const tab of tabs) {
226
240
  for (const key of tab.keys) if (!known.has(key)) error("unknown-key", tab.id, `The tab names the unknown key "${key}".`);
227
241
  const keys = new Set(tab.keys);
@@ -279,3 +293,95 @@ export function masterChartOf<P extends string>(nodes: readonly ChartNode[], tab
279
293
  const tabIds = new Set(nodes.flatMap((node) => (node.kind === "goto" ? [node.tab] : [])));
280
294
  return { nodes: placed, edges, tabs: tabs.filter((tab) => tabIds.has(tab.id)) };
281
295
  }
296
+
297
+ /** The name and the major version of the schema of the master graph. A reader refuses a graph with another value. */
298
+ export const GRAPH_SCHEMA = "guidebook-graph/1";
299
+
300
+ /** A row of the hazard catalog: an index into the graph, with the facts that are unique to the hazard. */
301
+ export interface HazardRow {
302
+ /** The key of the case. */
303
+ readonly key: string;
304
+ readonly title: string;
305
+ /** The ids of the signal nodes that the hazard gives. */
306
+ readonly signals: readonly string[];
307
+ /** The id of the node where a reader with this hazard joins the graph. */
308
+ readonly entry: string;
309
+ /** The ids of the steps of the case that are unique to it: its card. */
310
+ readonly card: readonly string[];
311
+ }
312
+
313
+ /**
314
+ * The master graph: one value that a printed binder and an app read.
315
+ * The edges come from the nodes with `masterChartOf`, so no second list can disagree with them.
316
+ */
317
+ export interface MasterGraph<P extends string = Phase> {
318
+ readonly schema: typeof GRAPH_SCHEMA;
319
+ /** The id of the tab of the chart itself, the entry of the binder. */
320
+ readonly start: string;
321
+ /** The id of the tab of the hazard catalog. An end with `card` shows the card from it. */
322
+ readonly catalog: string;
323
+ /** The states of society, in the sequence of the sections of each tab. */
324
+ readonly societies: readonly Society[];
325
+ readonly nodes: readonly ChartNode[];
326
+ readonly tabs: readonly Tab<P>[];
327
+ readonly hazards: readonly HazardRow[];
328
+ }
329
+
330
+ /** The options of the graph gate: the options of the chart gate and the cases that the catalog must index. */
331
+ export interface GraphGateOptions extends MasterGateOptions {
332
+ /** The keys of the cases. Each case has one row of the catalog. */
333
+ readonly cases: readonly string[];
334
+ }
335
+
336
+ /**
337
+ * This function applies the graph gate: the chart gate, and the gate of the hazard rows.
338
+ *
339
+ * The start tab and the catalog tab are tabs. The start tab needs no path. An end with `card` uses the catalog tab.
340
+ * Each case has one row. Each row names known signals, a known entry and steps of its case.
341
+ * Each entry reaches an end whose tab has keys.
342
+ */
343
+ export function checkMasterGraph<P extends string>(
344
+ graph: MasterGraph<P>,
345
+ steps: readonly Step<P>[],
346
+ sources: readonly Source[],
347
+ options: GraphGateOptions,
348
+ ): GateResult<MasterFinding> {
349
+ const out: MasterFinding[] = [];
350
+ const error = (code: MasterFindingCode, id: string, message: string): void => {
351
+ out.push({ level: "error", code, record: "chart", id, message });
352
+ };
353
+ if (graph.schema !== GRAPH_SCHEMA) error("bad-schema", "graph", `The schema is "${String(graph.schema)}", not "${GRAPH_SCHEMA}".`);
354
+ const tabIds = new Set(graph.tabs.map((tab) => tab.id));
355
+ if (!tabIds.has(graph.start)) error("unknown-start", graph.start, `The start tab "${graph.start}" is not a tab.`);
356
+ if (!tabIds.has(graph.catalog)) error("unknown-catalog", graph.catalog, `The catalog tab "${graph.catalog}" is not a tab.`);
357
+ const withCards = graph.nodes.some((node) => node.kind === "goto" && node.card === true);
358
+ const chartTabs = graph.tabs.filter((tab) => tab.id !== graph.start);
359
+ const chart = checkMasterChart(graph.nodes, chartTabs, steps, sources, { ...options, used: [...(options.used ?? []), ...(withCards ? [graph.catalog] : [])] });
360
+ out.push(...chart.findings);
361
+
362
+ const byId = new Map(graph.nodes.map((node) => [node.id, node] as const));
363
+ const stepById = new Map(steps.map((step) => [step.id, step] as const));
364
+ const tabById = new Map(graph.tabs.map((tab) => [tab.id, tab] as const));
365
+ const cases = new Set(options.cases);
366
+ const rows = new Set<string>();
367
+ const routes = (id: string, seen = new Set<string>()): boolean => {
368
+ if (seen.has(id)) return false;
369
+ seen.add(id);
370
+ const node = byId.get(id);
371
+ if (node === undefined) return false;
372
+ if (node.kind === "goto") return (tabById.get(node.tab)?.keys.length ?? 0) > 0;
373
+ return nextOf(node).some((to) => routes(to, seen));
374
+ };
375
+ for (const row of graph.hazards) {
376
+ if (rows.has(row.key)) error("duplicate-hazard", row.key, `Two rows of the catalog have the key "${row.key}".`);
377
+ rows.add(row.key);
378
+ if (!cases.has(row.key)) error("unknown-hazard", row.key, `The row names the unknown case "${row.key}".`);
379
+ if (row.signals.length === 0) error("unknown-signal", row.key, "The row names no signal.");
380
+ for (const id of row.signals) if (byId.get(id)?.kind !== "signal") error("unknown-signal", row.key, `The row names "${id}", which is not a signal node.`);
381
+ if (!byId.has(row.entry)) error("unknown-entry", row.key, `The row names the unknown entry "${row.entry}".`);
382
+ else if (!routes(row.entry)) error("no-route", row.key, "No path from the entry of the row goes to a tab with keys.");
383
+ for (const id of row.card) if (stepById.get(id)?.on !== row.key) error("unknown-card-step", row.key, `The card names "${id}", which is not a step of the case.`);
384
+ }
385
+ for (const key of options.cases) if (!rows.has(key)) error("missing-hazard", key, `The catalog has no row for the case "${key}".`);
386
+ return resultOf(out);
387
+ }