@mark1russell7/guidebook-plans 0.1.5 → 0.1.6

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
@@ -190,6 +190,25 @@ import { checkMasterGraph } from "@mark1russell7/guidebook-plans";
190
190
  const gate = checkMasterGraph(graph, library, sources, { on: keys, cover: hazards, cases, maxNodes: 20, maxEnds: 13 });
191
191
  ```
192
192
 
193
+ ### The walk of the graph
194
+
195
+ The walk functions give one query over the graph for each reader: the app and the converter of the binder. The state of a walk `WalkState` is plain data: the node `at`, the `hazard`, the state of `society` and the `trail`.
196
+
197
+ | Function | Result |
198
+ | --- | --- |
199
+ | `walkStart(graph, hazard?, signal?)` | The start: the entry of the row of the hazard, or a signal. |
200
+ | `walkAnswer(graph, state, label?)` | The state after an answer. An answer with a state of society sets it. |
201
+ | `walkBack(state)` | The state one node back, with the state of society at that node. |
202
+ | `walkEnd(graph, state, steps)` | At a goto: the tab, the steps of its keys by phase for the state of society, and the card of the hazard. |
203
+
204
+ ```ts
205
+ import { walkAnswer, walkEnd, walkStart } from "@mark1russell7/guidebook-plans";
206
+
207
+ const start = walkStart(graph, "met.flood"); // At the entry of the row of the flood.
208
+ const next = start && walkAnswer(graph, start, "No");
209
+ const end = next && walkEnd(graph, next, steps); // The tab, its steps by phase and the card of the flood.
210
+ ```
211
+
193
212
  ## Limits
194
213
 
195
214
  - The gate does not evaluate `when`. The planner of an app evaluates it over the live state.
package/build/index.d.ts CHANGED
@@ -183,6 +183,56 @@ interface GraphGateOptions extends MasterGateOptions {
183
183
  * Each entry reaches an end whose tab has keys.
184
184
  */
185
185
  export declare function checkMasterGraph<P extends string>(graph: MasterGraph<P>, steps: readonly Step<P>[], sources: readonly Source[], options: GraphGateOptions): GateResult<MasterFinding>;
186
+ /** A node that a walk left, with the state of society at that node. */
187
+ interface WalkStep {
188
+ readonly at: string;
189
+ readonly society?: Society;
190
+ }
191
+ /**
192
+ * The state of a walk of the master graph. It is plain data, so a reader can keep it in an address or a store.
193
+ * `at` is the id of the current node. `trail` holds the nodes before it, the first one first.
194
+ */
195
+ interface WalkState {
196
+ readonly at: string;
197
+ /** The key of the case of the reader, if the reader came from a row of the catalog. */
198
+ readonly hazard?: string;
199
+ /** The state of society that the answers told, if any. */
200
+ readonly society?: Society;
201
+ readonly trail: readonly WalkStep[];
202
+ }
203
+ /** The steps of one phase at the end of a walk. */
204
+ interface WalkPhase<P extends string = Phase> {
205
+ readonly phase: P;
206
+ readonly steps: readonly Step<P>[];
207
+ }
208
+ /** The end of a walk: the tab, its steps by phase for the state of society, and the card of the hazard. */
209
+ interface WalkEnd<P extends string = Phase> {
210
+ readonly tab: Tab<P>;
211
+ /** The state of society of the steps. No value means the steps of each state. */
212
+ readonly society?: Society;
213
+ readonly phases: readonly WalkPhase<P>[];
214
+ /** The steps of the card of the hazard, when the end has `card` and the walk has a hazard. */
215
+ readonly card: readonly Step<P>[];
216
+ }
217
+ /**
218
+ * This function gives the start of a walk.
219
+ * With a hazard, the walk starts at the entry of its row. With no hazard, it starts at `signal` or at the first signal.
220
+ * It gives `undefined` for an unknown hazard or signal.
221
+ */
222
+ export declare function walkStart<P extends string>(graph: MasterGraph<P>, hazard?: string, signal?: string): WalkState | undefined;
223
+ /**
224
+ * This function gives the state after an answer.
225
+ * At a signal, the walk goes to its next node, and the label is not used. At a question, the label selects the answer.
226
+ * An answer with a state of society sets it. The function gives `undefined` for an unknown label or at an end.
227
+ */
228
+ export declare function walkAnswer<P extends string>(graph: MasterGraph<P>, state: WalkState, label?: string): WalkState | undefined;
229
+ /** This function gives the state one node back, with the state of society at that node. At the start, it gives the same state. */
230
+ export declare function walkBack(state: WalkState): WalkState;
231
+ /**
232
+ * This function gives the end of a walk at a goto: its tab, the steps of the tab by phase, and the card.
233
+ * The steps are for the state of society of the walk. It gives `undefined` when the walk is not at a goto.
234
+ */
235
+ export declare function walkEnd<P extends string>(graph: MasterGraph<P>, state: WalkState, steps: readonly Step<P>[]): WalkEnd<P> | undefined;
186
236
  /**
187
237
  * One action of a plan. A step belongs to a key and to a phase.
188
238
  * 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.
@@ -351,5 +401,5 @@ interface ChartQuestion<P extends string = Phase> {
351
401
  }
352
402
  /** This function gives the chart of a set of rules: one question for each kind that has rules, in the sequence of `RULE_KINDS`. */
353
403
  export declare function chartOf<P extends string>(rules: readonly Rule<P>[]): readonly ChartQuestion<P>[];
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 };
404
+ 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, WalkEnd, WalkPhase, WalkState, WalkStep };
355
405
  //# 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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,6 +615,93 @@ function checkMasterGraph(graph, steps, sources, options) {
615
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
616
  return resultOf(out);
617
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 };
618
+ /**
619
+ * This function gives the start of a walk.
620
+ * With a hazard, the walk starts at the entry of its row. With no hazard, it starts at `signal` or at the first signal.
621
+ * It gives `undefined` for an unknown hazard or signal.
622
+ */
623
+ function walkStart(graph, hazard, signal) {
624
+ if (hazard !== void 0) {
625
+ const row = graph.hazards.find((item) => item.key === hazard);
626
+ return row === void 0 ? void 0 : {
627
+ at: row.entry,
628
+ hazard,
629
+ trail: []
630
+ };
631
+ }
632
+ const start = graph.nodes.find((node) => node.kind === "signal" && (signal === void 0 || node.id === signal));
633
+ return start === void 0 ? void 0 : {
634
+ at: start.id,
635
+ trail: []
636
+ };
637
+ }
638
+ /**
639
+ * This function gives the state after an answer.
640
+ * At a signal, the walk goes to its next node, and the label is not used. At a question, the label selects the answer.
641
+ * An answer with a state of society sets it. The function gives `undefined` for an unknown label or at an end.
642
+ */
643
+ function walkAnswer(graph, state, label) {
644
+ const node = graph.nodes.find((item) => item.id === state.at);
645
+ const trail = [...state.trail, {
646
+ at: state.at,
647
+ ...state.society === void 0 ? {} : { society: state.society }
648
+ }];
649
+ const keep = state.hazard === void 0 ? {} : { hazard: state.hazard };
650
+ if (node?.kind === "signal") return {
651
+ at: node.next,
652
+ ...keep,
653
+ ...state.society === void 0 ? {} : { society: state.society },
654
+ trail
655
+ };
656
+ if (node?.kind !== "question") return void 0;
657
+ const answer = node.answers.find((item) => item.label === label);
658
+ if (answer === void 0) return void 0;
659
+ const society = answer.society ?? state.society;
660
+ return {
661
+ at: answer.next,
662
+ ...keep,
663
+ ...society === void 0 ? {} : { society },
664
+ trail
665
+ };
666
+ }
667
+ /** This function gives the state one node back, with the state of society at that node. At the start, it gives the same state. */
668
+ function walkBack(state) {
669
+ const last = state.trail.at(-1);
670
+ if (last === void 0) return state;
671
+ return {
672
+ at: last.at,
673
+ ...state.hazard === void 0 ? {} : { hazard: state.hazard },
674
+ ...last.society === void 0 ? {} : { society: last.society },
675
+ trail: state.trail.slice(0, -1)
676
+ };
677
+ }
678
+ /**
679
+ * This function gives the end of a walk at a goto: its tab, the steps of the tab by phase, and the card.
680
+ * The steps are for the state of society of the walk. It gives `undefined` when the walk is not at a goto.
681
+ */
682
+ function walkEnd(graph, state, steps) {
683
+ const node = graph.nodes.find((item) => item.id === state.at);
684
+ if (node?.kind !== "goto") return void 0;
685
+ const tab = graph.tabs.find((item) => item.id === node.tab);
686
+ if (tab === void 0) return void 0;
687
+ const options = state.society === void 0 ? {} : { society: state.society };
688
+ const phases = tab.phases.map((phase) => ({
689
+ phase,
690
+ steps: stepsFor(steps, tab.keys, [phase], options)
691
+ })).filter((item) => item.steps.length > 0);
692
+ const row = node.card === true && state.hazard !== void 0 ? graph.hazards.find((item) => item.key === state.hazard) : void 0;
693
+ const byId = new Map(steps.map((step) => [step.id, step]));
694
+ const card = (row?.card ?? []).flatMap((id) => {
695
+ const step = byId.get(id);
696
+ return step === void 0 ? [] : [step];
697
+ });
698
+ return {
699
+ tab,
700
+ ...options,
701
+ phases,
702
+ card
703
+ };
704
+ }
705
+ 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, walkAnswer, walkBack, walkEnd, walkStart };
619
706
 
620
707
  //# 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 /** 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":";;;AAG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GAAG,MAAM,kBAAkB,IAAI,KAAK,0BAA0B;EACzF,KAAK,MAAM,MAAM,IAAI,SAAS,IAAI,KAAK,IAAI,EAAE,CAAC,EAAE,SAAS,UAAU,MAAM,kBAAkB,IAAI,KAAK,kBAAkB,GAAG,+BAA+B;EACxJ,IAAI,CAAC,KAAK,IAAI,IAAI,KAAK,GAAG,MAAM,iBAAiB,IAAI,KAAK,oCAAoC,IAAI,MAAM,GAAG;OACtG,IAAI,CAAC,OAAO,IAAI,KAAK,GAAG,MAAM,YAAY,IAAI,KAAK,4DAA4D;EACpH,KAAK,MAAM,MAAM,IAAI,MAAM,IAAI,SAAS,IAAI,EAAE,CAAC,EAAE,OAAO,IAAI,KAAK,MAAM,qBAAqB,IAAI,KAAK,mBAAmB,GAAG,oCAAoC;CACjK;CACA,KAAK,MAAM,OAAO,QAAQ,OAAO,IAAI,CAAC,KAAK,IAAI,GAAG,GAAG,MAAM,kBAAkB,KAAK,wCAAwC,IAAI,GAAG;CACjI,OAAO,SAAS,GAAG;AACrB"}
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 { stepsFor } from \"./steps.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\n/** A node that a walk left, with the state of society at that node. */\nexport interface WalkStep {\n readonly at: string;\n readonly society?: Society;\n}\n\n/**\n * The state of a walk of the master graph. It is plain data, so a reader can keep it in an address or a store.\n * `at` is the id of the current node. `trail` holds the nodes before it, the first one first.\n */\nexport interface WalkState {\n readonly at: string;\n /** The key of the case of the reader, if the reader came from a row of the catalog. */\n readonly hazard?: string;\n /** The state of society that the answers told, if any. */\n readonly society?: Society;\n readonly trail: readonly WalkStep[];\n}\n\n/** The steps of one phase at the end of a walk. */\nexport interface WalkPhase<P extends string = Phase> {\n readonly phase: P;\n readonly steps: readonly Step<P>[];\n}\n\n/** The end of a walk: the tab, its steps by phase for the state of society, and the card of the hazard. */\nexport interface WalkEnd<P extends string = Phase> {\n readonly tab: Tab<P>;\n /** The state of society of the steps. No value means the steps of each state. */\n readonly society?: Society;\n readonly phases: readonly WalkPhase<P>[];\n /** The steps of the card of the hazard, when the end has `card` and the walk has a hazard. */\n readonly card: readonly Step<P>[];\n}\n\n/**\n * This function gives the start of a walk.\n * With a hazard, the walk starts at the entry of its row. With no hazard, it starts at `signal` or at the first signal.\n * It gives `undefined` for an unknown hazard or signal.\n */\nexport function walkStart<P extends string>(graph: MasterGraph<P>, hazard?: string, signal?: string): WalkState | undefined {\n if (hazard !== undefined) {\n const row = graph.hazards.find((item) => item.key === hazard);\n return row === undefined ? undefined : { at: row.entry, hazard, trail: [] };\n }\n const start = graph.nodes.find((node) => node.kind === \"signal\" && (signal === undefined || node.id === signal));\n return start === undefined ? undefined : { at: start.id, trail: [] };\n}\n\n/**\n * This function gives the state after an answer.\n * At a signal, the walk goes to its next node, and the label is not used. At a question, the label selects the answer.\n * An answer with a state of society sets it. The function gives `undefined` for an unknown label or at an end.\n */\nexport function walkAnswer<P extends string>(graph: MasterGraph<P>, state: WalkState, label?: string): WalkState | undefined {\n const node = graph.nodes.find((item) => item.id === state.at);\n const trail = [...state.trail, { at: state.at, ...(state.society === undefined ? {} : { society: state.society }) }];\n const keep = state.hazard === undefined ? {} : { hazard: state.hazard };\n if (node?.kind === \"signal\") return { at: node.next, ...keep, ...(state.society === undefined ? {} : { society: state.society }), trail };\n if (node?.kind !== \"question\") return undefined;\n const answer = node.answers.find((item) => item.label === label);\n if (answer === undefined) return undefined;\n const society = answer.society ?? state.society;\n return { at: answer.next, ...keep, ...(society === undefined ? {} : { society }), trail };\n}\n\n/** This function gives the state one node back, with the state of society at that node. At the start, it gives the same state. */\nexport function walkBack(state: WalkState): WalkState {\n const last = state.trail.at(-1);\n if (last === undefined) return state;\n return { at: last.at, ...(state.hazard === undefined ? {} : { hazard: state.hazard }), ...(last.society === undefined ? {} : { society: last.society }), trail: state.trail.slice(0, -1) };\n}\n\n/**\n * This function gives the end of a walk at a goto: its tab, the steps of the tab by phase, and the card.\n * The steps are for the state of society of the walk. It gives `undefined` when the walk is not at a goto.\n */\nexport function walkEnd<P extends string>(graph: MasterGraph<P>, state: WalkState, steps: readonly Step<P>[]): WalkEnd<P> | undefined {\n const node = graph.nodes.find((item) => item.id === state.at);\n if (node?.kind !== \"goto\") return undefined;\n const tab = graph.tabs.find((item) => item.id === node.tab);\n if (tab === undefined) return undefined;\n const options = state.society === undefined ? {} : { society: state.society };\n const phases = tab.phases.map((phase) => ({ phase, steps: stepsFor(steps, tab.keys, [phase], options) })).filter((item) => item.steps.length > 0);\n const row = node.card === true && state.hazard !== undefined ? graph.hazards.find((item) => item.key === state.hazard) : undefined;\n const byId = new Map(steps.map((step) => [step.id, step] as const));\n const card = (row?.card ?? []).flatMap((id) => {\n const step = byId.get(id);\n return step === undefined ? [] : [step];\n });\n return { tab, ...options, phases, card };\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,MAAM,IAAI,WAAW,qBAAqB,OAAO,OAAO,EAAE,yBAAyB;CAClH,IAAI,UAAU,GAAG,OAAO,SAAS,OAAO,SAAS,OAAO;CACxD,IAAI;CACJ,KAAK,MAAM,QAAQ,OAAO,OAAO,IAAI,W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AkB,OAAmD;CACpI,MAAM,OAAO,MAAM,MAAM,MAAM,SAAS,KAAK,OAAO,MAAM,EAAE;CAC5D,IAAI,MAAM,SAAS,QAAQ,OAAO,KAAA;CAClC,MAAM,MAAM,MAAM,KAAK,MAAM,SAAS,KAAK,OAAO,KAAK,GAAG;CAC1D,IAAI,QAAQ,KAAA,GAAW,OAAO,KAAA;CAC9B,MAAM,UAAU,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,QAAQ;CAC5E,MAAM,SAAS,IAAI,OAAO,KAAK,WAAW;EAAE;EAAO,OAAO,SAAS,OAAO,IAAI,MAAM,CAAC,KAAK,GAAG,OAAO;CAAE,EAAE,CAAC,CAAC,QAAQ,SAAS,KAAK,MAAM,SAAS,CAAC;CAChJ,MAAM,MAAM,KAAK,SAAS,QAAQ,MAAM,WAAW,KAAA,IAAY,MAAM,QAAQ,MAAM,SAAS,KAAK,QAAQ,MAAM,MAAM,IAAI,KAAA;CACzH,MAAM,OAAO,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC,KAAK,IAAI,IAAI,CAAU,CAAC;CAClE,MAAM,QAAQ,KAAK,QAAQ,CAAC,EAAA,CAAG,SAAS,OAAO;EAC7C,MAAM,OAAO,KAAK,IAAI,EAAE;EACxB,OAAO,SAAS,KAAA,IAAY,CAAC,IAAI,CAAC,IAAI;CACxC,CAAC;CACD,OAAO;EAAE;EAAK,GAAG;EAAS;EAAQ;CAAK;AACzC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/guidebook-plans",
4
- "version": "0.1.5",
4
+ "version": "0.1.6",
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 { 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";
12
+ export { GRAPH_SCHEMA, MASTER_FINDING_CODES, SOCIETY_STATES, SOCIETY_TITLES, checkMasterChart, checkMasterGraph, masterChartOf, walkAnswer, walkBack, walkEnd, walkStart } from "./master.ts";
13
+ export type { ChartAnswer, ChartEdge, ChartNode, GotoNode, GraphGateOptions, HazardRow, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, MasterGraph, PlacedNode, WalkEnd, WalkPhase, WalkState, WalkStep, QuestionNode, SignalNode, Society, Tab } from "./master.ts";
package/src/master.ts CHANGED
@@ -5,6 +5,7 @@ import { stronglyConnectedComponents } from "@mark1russell7/collections/graph";
5
5
  import { resultOf } from "@mark1russell7/guidebook";
6
6
  import type { Finding, GateResult, Source } from "@mark1russell7/guidebook";
7
7
  import type { Phase } from "./ladder.ts";
8
+ import { stepsFor } from "./steps.ts";
8
9
  import type { Step } from "./steps.ts";
9
10
 
10
11
  /** The states of society after an event, from a society that works to a society that does not work. */
@@ -385,3 +386,96 @@ export function checkMasterGraph<P extends string>(
385
386
  for (const key of options.cases) if (!rows.has(key)) error("missing-hazard", key, `The catalog has no row for the case "${key}".`);
386
387
  return resultOf(out);
387
388
  }
389
+
390
+ /** A node that a walk left, with the state of society at that node. */
391
+ export interface WalkStep {
392
+ readonly at: string;
393
+ readonly society?: Society;
394
+ }
395
+
396
+ /**
397
+ * The state of a walk of the master graph. It is plain data, so a reader can keep it in an address or a store.
398
+ * `at` is the id of the current node. `trail` holds the nodes before it, the first one first.
399
+ */
400
+ export interface WalkState {
401
+ readonly at: string;
402
+ /** The key of the case of the reader, if the reader came from a row of the catalog. */
403
+ readonly hazard?: string;
404
+ /** The state of society that the answers told, if any. */
405
+ readonly society?: Society;
406
+ readonly trail: readonly WalkStep[];
407
+ }
408
+
409
+ /** The steps of one phase at the end of a walk. */
410
+ export interface WalkPhase<P extends string = Phase> {
411
+ readonly phase: P;
412
+ readonly steps: readonly Step<P>[];
413
+ }
414
+
415
+ /** The end of a walk: the tab, its steps by phase for the state of society, and the card of the hazard. */
416
+ export interface WalkEnd<P extends string = Phase> {
417
+ readonly tab: Tab<P>;
418
+ /** The state of society of the steps. No value means the steps of each state. */
419
+ readonly society?: Society;
420
+ readonly phases: readonly WalkPhase<P>[];
421
+ /** The steps of the card of the hazard, when the end has `card` and the walk has a hazard. */
422
+ readonly card: readonly Step<P>[];
423
+ }
424
+
425
+ /**
426
+ * This function gives the start of a walk.
427
+ * With a hazard, the walk starts at the entry of its row. With no hazard, it starts at `signal` or at the first signal.
428
+ * It gives `undefined` for an unknown hazard or signal.
429
+ */
430
+ export function walkStart<P extends string>(graph: MasterGraph<P>, hazard?: string, signal?: string): WalkState | undefined {
431
+ if (hazard !== undefined) {
432
+ const row = graph.hazards.find((item) => item.key === hazard);
433
+ return row === undefined ? undefined : { at: row.entry, hazard, trail: [] };
434
+ }
435
+ const start = graph.nodes.find((node) => node.kind === "signal" && (signal === undefined || node.id === signal));
436
+ return start === undefined ? undefined : { at: start.id, trail: [] };
437
+ }
438
+
439
+ /**
440
+ * This function gives the state after an answer.
441
+ * At a signal, the walk goes to its next node, and the label is not used. At a question, the label selects the answer.
442
+ * An answer with a state of society sets it. The function gives `undefined` for an unknown label or at an end.
443
+ */
444
+ export function walkAnswer<P extends string>(graph: MasterGraph<P>, state: WalkState, label?: string): WalkState | undefined {
445
+ const node = graph.nodes.find((item) => item.id === state.at);
446
+ const trail = [...state.trail, { at: state.at, ...(state.society === undefined ? {} : { society: state.society }) }];
447
+ const keep = state.hazard === undefined ? {} : { hazard: state.hazard };
448
+ if (node?.kind === "signal") return { at: node.next, ...keep, ...(state.society === undefined ? {} : { society: state.society }), trail };
449
+ if (node?.kind !== "question") return undefined;
450
+ const answer = node.answers.find((item) => item.label === label);
451
+ if (answer === undefined) return undefined;
452
+ const society = answer.society ?? state.society;
453
+ return { at: answer.next, ...keep, ...(society === undefined ? {} : { society }), trail };
454
+ }
455
+
456
+ /** This function gives the state one node back, with the state of society at that node. At the start, it gives the same state. */
457
+ export function walkBack(state: WalkState): WalkState {
458
+ const last = state.trail.at(-1);
459
+ if (last === undefined) return state;
460
+ return { at: last.at, ...(state.hazard === undefined ? {} : { hazard: state.hazard }), ...(last.society === undefined ? {} : { society: last.society }), trail: state.trail.slice(0, -1) };
461
+ }
462
+
463
+ /**
464
+ * This function gives the end of a walk at a goto: its tab, the steps of the tab by phase, and the card.
465
+ * The steps are for the state of society of the walk. It gives `undefined` when the walk is not at a goto.
466
+ */
467
+ export function walkEnd<P extends string>(graph: MasterGraph<P>, state: WalkState, steps: readonly Step<P>[]): WalkEnd<P> | undefined {
468
+ const node = graph.nodes.find((item) => item.id === state.at);
469
+ if (node?.kind !== "goto") return undefined;
470
+ const tab = graph.tabs.find((item) => item.id === node.tab);
471
+ if (tab === undefined) return undefined;
472
+ const options = state.society === undefined ? {} : { society: state.society };
473
+ const phases = tab.phases.map((phase) => ({ phase, steps: stepsFor(steps, tab.keys, [phase], options) })).filter((item) => item.steps.length > 0);
474
+ const row = node.card === true && state.hazard !== undefined ? graph.hazards.find((item) => item.key === state.hazard) : undefined;
475
+ const byId = new Map(steps.map((step) => [step.id, step] as const));
476
+ const card = (row?.card ?? []).flatMap((id) => {
477
+ const step = byId.get(id);
478
+ return step === undefined ? [] : [step];
479
+ });
480
+ return { tab, ...options, phases, card };
481
+ }