@tsplc/tmp-debug 0.0.0-stage → 0.6.3
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 +38 -2
- package/dist/api.js +744 -0
- package/dist/api.js.map +12 -0
- package/dist/constant.js +33 -0
- package/dist/constant.js.map +10 -0
- package/dist/explain-file.js +468 -0
- package/dist/explain-file.js.map +11 -0
- package/dist/explain.js +1310 -0
- package/dist/explain.js.map +19 -0
- package/dist/format.js +214 -0
- package/dist/format.js.map +12 -0
- package/dist/index.js +4066 -0
- package/dist/index.js.map +44 -0
- package/dist/manifest.js +240 -0
- package/dist/manifest.js.map +10 -0
- package/dist/paths.js +242 -0
- package/dist/paths.js.map +10 -0
- package/package.json +72 -4
- package/src/adapter.ts +77 -0
- package/src/api.ts +446 -0
- package/src/app-server.ts +151 -0
- package/src/build-files.ts +46 -0
- package/src/constant.ts +41 -0
- package/src/debugger.ts +237 -0
- package/src/errors.ts +13 -0
- package/src/explain-expressions.ts +484 -0
- package/src/explain-file.ts +325 -0
- package/src/explain-frames.ts +155 -0
- package/src/explain-loops.ts +151 -0
- package/src/explain-operations.ts +232 -0
- package/src/explain-tables.ts +345 -0
- package/src/explain-value.ts +203 -0
- package/src/explain-verdicts.ts +548 -0
- package/src/explain.ts +82 -0
- package/src/hardware.ts +159 -0
- package/src/http.ts +218 -0
- package/src/index.ts +44 -0
- package/src/jobs.ts +139 -0
- package/src/login-value.ts +165 -0
- package/src/login.ts +315 -0
- package/src/manifest.ts +328 -0
- package/src/opcua.ts +80 -0
- package/src/paths.ts +363 -0
- package/src/requests.ts +99 -0
- package/src/server-cursor.ts +22 -0
- package/src/shown.ts +229 -0
- package/src/telemetry.ts +125 -0
- package/src/timeline.ts +148 -0
- package/src/trace.ts +62 -0
- package/src/ui/bits.ts +48 -0
- package/src/ui/client.ts +87 -0
- package/src/ui/dom.ts +61 -0
- package/src/ui/explain-read.ts +105 -0
- package/src/ui/format.ts +261 -0
- package/src/ui/hardware.ts +425 -0
- package/src/ui/header.ts +207 -0
- package/src/ui/health.ts +64 -0
- package/src/ui/index.ts +27 -0
- package/src/ui/jobs.ts +263 -0
- package/src/ui/links.ts +59 -0
- package/src/ui/live-value.ts +85 -0
- package/src/ui/main.ts +76 -0
- package/src/ui/overview.ts +178 -0
- package/src/ui/page.ts +286 -0
- package/src/ui/pages.ts +64 -0
- package/src/ui/recent-window.ts +49 -0
- package/src/ui/recent.ts +355 -0
- package/src/ui/request-trace.ts +38 -0
- package/src/ui/requests.ts +80 -0
- package/src/ui/routes.ts +98 -0
- package/src/ui/store.ts +295 -0
- package/src/ui/success-cache.ts +11 -0
- package/src/ui/tree.ts +162 -0
- package/src/ui/variables.ts +597 -0
- package/src/ui/why-watch.ts +11 -0
- package/src/ui/why.ts +694 -0
- package/src/values.ts +170 -0
- package/src/watch.ts +32 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/build-files.ts", "../src/explain-file.ts", "../src/manifest.ts", "../src/debugger.ts", "../src/adapter.ts", "../src/app-server.ts", "../src/errors.ts", "../src/server-cursor.ts", "../src/timeline.ts", "../src/requests.ts", "../src/explain-value.ts", "../src/constant.ts", "../src/paths.ts", "../src/explain-frames.ts", "../src/explain-loops.ts", "../src/explain-operations.ts", "../src/explain-expressions.ts", "../src/explain-tables.ts", "../src/explain-verdicts.ts", "../src/explain.ts", "../src/hardware.ts", "../src/jobs.ts", "../src/shown.ts", "../src/telemetry.ts", "../src/trace.ts", "../src/api.ts", "../src/values.ts", "../src/watch.ts", "../src/http.ts", "../src/ui/index.ts", "../src/ui/page.ts", "../src/ui/success-cache.ts", "../src/login.ts", "../src/login-value.ts", "../src/opcua.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { type ExplainFile, explainFile, explainFileName } from \"./explain-file\";\nimport { type DebugManifest, debugManifest } from \"./manifest\";\n\n/** An `explain.json` that matched its manifest's digest, and its exact text. */\nexport interface LoadedExplanations {\n\ttext: string;\n\tsha256: string;\n\tfile: ExplainFile;\n}\n\nexport const loadManifest = async (file: string) =>\n\tdebugManifest.parse(JSON.parse(await readFile(file, \"utf8\")));\n\n/**\n * The build's `explain.json` beside its manifest: null when the manifest records none, refused\n * when the file's digest isn't the one the manifest records.\n */\nexport const loadExplanations = async (\n\tmanifestFile: string,\n\tmanifest: DebugManifest,\n): Promise<LoadedExplanations | null> => {\n\tif (!manifest.explain) {\n\t\treturn null;\n\t}\n\tconst text = await readFile(\n\t\tjoin(dirname(manifestFile), explainFileName),\n\t\t\"utf8\",\n\t);\n\tconst sha256 = createHash(\"sha256\").update(text).digest(\"hex\");\n\tif (sha256 !== manifest.explain.sha256) {\n\t\tthrow new Error(`${explainFileName} doesn't belong to this build`);\n\t}\n\treturn { text, sha256, file: explainFile.parse(JSON.parse(text)) };\n};\n\n/** The debug manifest at `manifestFile` and its build's explanations. */\nexport const loadDebugBuild = async (manifestFile: string) => {\n\tconst manifest = await loadManifest(manifestFile);\n\treturn {\n\t\tmanifest,\n\t\texplanations: await loadExplanations(manifestFile, manifest),\n\t};\n};\n",
|
|
6
|
+
"import {\n\tvalueBinaryOperators,\n\tvalueUnaryOperators,\n} from \"@tsplc/iec/arithmetic\";\nimport { z } from \"zod\";\nimport { json, sourceRange } from \"./manifest\";\n\n/**\n * Why each stored value is what it is: every statement that writes it, the conditions it runs\n * under and the expressions it evaluates, rebuilt from the compiler's per-instance model. Written\n * beside `debug.json`, whose `explain.sha256` binds it to the build, as `explainFile`.\n */\nexport const explainFileName = \"explain.json\";\n\n/** An index into one of this file's tables. */\nconst tableIndex = z.number().int().nonnegative();\n/** A pre-order statement index within a routine. */\nconst position = z.number().int().nonnegative();\n\nexport const explainExpression = z.discriminatedUnion(\"kind\", [\n\t/** Stored state, captured at `capturedAt`; `path` is a slot of its routine row's `paths`. */\n\tz.object({\n\t\tkind: z.literal(\"read\"),\n\t\tpath: tableIndex,\n\t\tcapturedAt: position,\n\t\t/** A call runs between the read and its use, and may have changed what was read. */\n\t\tinterleaved: z.literal(true).optional(),\n\t\ttype: z.string(),\n\t}),\n\t/** An element at runtime indexes: `path` has a `[*]` for each of `indexes`. */\n\tz.object({\n\t\tkind: z.literal(\"pattern\"),\n\t\tpath: tableIndex,\n\t\tindexes: z.array(tableIndex),\n\t\tcapturedAt: position,\n\t\tinterleaved: z.literal(true).optional(),\n\t\ttype: z.string(),\n\t}),\n\tz.object({ kind: z.literal(\"constant\"), value: json, type: z.string() }),\n\tz.object({\n\t\tkind: z.literal(\"record\"),\n\t\tfields: z.record(z.string(), tableIndex),\n\t\ttype: z.string(),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"array\"),\n\t\tlower: z.number().int(),\n\t\titems: z.array(tableIndex),\n\t\ttype: z.string(),\n\t}),\n\t/** A local, by its slot in its routine row's `locals`, read at `at`. */\n\tz.object({\n\t\tkind: z.literal(\"local\"),\n\t\tlocal: tableIndex,\n\t\tpath: z.array(z.string()),\n\t\tat: position,\n\t\ttype: z.string(),\n\t}),\n\t/** The routine's parameter: the call site's argument, or its `locals` slot when the routine writes it. */\n\tz.object({\n\t\tkind: z.literal(\"parameter\"),\n\t\tparameter: z.number().int().nonnegative(),\n\t\tpath: z.array(z.string()),\n\t\tat: position,\n\t\tlocal: tableIndex.nullable(),\n\t\ttype: z.string(),\n\t}),\n\t/** A call's result: `call` is a slot of its routine row's `calls`. */\n\tz.object({\n\t\tkind: z.literal(\"call\"),\n\t\tcall: tableIndex,\n\t\tpath: z.array(z.string()),\n\t\ttype: z.string(),\n\t}),\n\t/** The PLC's millisecond clock as a DINT. */\n\tz.object({ kind: z.literal(\"clock\"), type: z.string() }),\n\t/** An object reference: its operand holds a setup object's id, listed in `references`. */\n\tz.object({ kind: z.literal(\"reference\"), operand: tableIndex }),\n\tz.object({\n\t\tkind: z.literal(\"unary\"),\n\t\toperator: z.enum(valueUnaryOperators),\n\t\toperand: tableIndex,\n\t\ttype: z.string(),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"binary\"),\n\t\toperator: z.enum(valueBinaryOperators),\n\t\tpolicy: z.enum([\"wrap\", \"saturate\"]).optional(),\n\t\tleft: tableIndex,\n\t\tright: tableIndex,\n\t\ttype: z.string(),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"convert\"),\n\t\tpolicy: z.enum([\"exact\", \"wrap\", \"saturate\"]),\n\t\toperand: tableIndex,\n\t\ttype: z.string(),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"logical\"),\n\t\toperator: z.enum([\"and\", \"or\"]),\n\t\tleft: tableIndex,\n\t\tright: tableIndex,\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"select\"),\n\t\tcondition: tableIndex,\n\t\t// biome-ignore lint/suspicious/noThenProperty: a `?:` branch is data, not a thenable.\n\t\tthen: tableIndex,\n\t\telse: tableIndex,\n\t\ttype: z.string(),\n\t}),\n\t/** Not traced: `text` says why, and `reads` lists the stored values it depends on. */\n\tz.object({\n\t\tkind: z.literal(\"opaque\"),\n\t\ttext: tableIndex,\n\t\treads: z.array(tableIndex),\n\t\ttype: z.string(),\n\t}),\n]);\nexport type ExplainExpression = z.infer<typeof explainExpression>;\n\n/** Holds when none of the conjunctions holds: no earlier statement left. */\nconst exitsCondition = z.object({\n\tkind: z.literal(\"exits\"),\n\tget any(): z.ZodArray<z.ZodArray<typeof explainCondition>> {\n\t\treturn z.array(z.array(explainCondition));\n\t},\n});\n\n// A union rather than a discriminated one: TypeScript can't infer a discriminated union that contains itself.\nexport const explainCondition = z.union([\n\tz.object({\n\t\tkind: z.literal(\"test\"),\n\t\ttest: tableIndex,\n\t\tholds: z.boolean(),\n\t\tat: position,\n\t\ttext: tableIndex.nullable(),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"cases\"),\n\t\ttest: tableIndex,\n\t\tvalues: z.array(json),\n\t\tmember: z.boolean(),\n\t\tat: position,\n\t\ttext: tableIndex.nullable(),\n\t}),\n\texitsCondition,\n\t/** `loop` is a slot of the routine row's `loops`. */\n\tz.object({ kind: z.literal(\"loop\"), loop: tableIndex }),\n\t/** Holds when no iteration of the loop returned. */\n\tz.object({ kind: z.literal(\"loopReturns\"), loop: tableIndex }),\n\t/** The routine row's job is at `step`. */\n\tz.object({ kind: z.literal(\"job\"), step: z.number().int() }),\n\t/** Code outside the job's step switch, which runs while the job is busy. */\n\tz.object({ kind: z.literal(\"jobBusy\") }),\n]);\nexport type ExplainCondition = z.infer<typeof explainCondition>;\n\nconst record = {\n\troutine: tableIndex,\n\tposition,\n\t/** The innermost `conditions` entry the statement runs under; its parents are the outer ones. Null for none. */\n\tconditions: tableIndex.nullable(),\n\t/** The `sites` entry for where the statement is; null when it has no source in the project. */\n\tsite: tableIndex.nullable(),\n};\n\nconst written = z.discriminatedUnion(\"kind\", [\n\tz.object({ kind: z.literal(\"path\"), path: tableIndex }),\n\tz.object({\n\t\tkind: z.literal(\"pattern\"),\n\t\tpath: tableIndex,\n\t\tindexes: z.array(tableIndex),\n\t}),\n]);\n\nexport const explainAssignment = z.object({\n\t...record,\n\tkind: z.enum([\"assign\", \"call\", \"block\", \"input\", \"return\", \"counter\"]),\n\twrites: written,\n\t/** A record or array written as a whole, so it writes every path below `writes`. */\n\twhole: z.boolean(),\n\tvalue: tableIndex.nullable(),\n\t/** A standard block's update: its kind, inputs and elapsed-time output. */\n\tblock: z\n\t\t.object({\n\t\t\tkind: z.string(),\n\t\t\tinputs: z.record(z.string(), tableIndex),\n\t\t\telapsed: tableIndex.nullable(),\n\t\t})\n\t\t.nullable(),\n\t/**\n\t * For a write through a by-reference parameter, the calls from the writer up to where the place\n\t * is named, innermost first. The write reaches the path only through these calls, and the\n\t * indexes of a pattern it writes are evaluated in the outermost one's caller.\n\t */\n\tvia: z.array(tableIndex),\n\tloop: tableIndex.nullable(),\n});\nexport type ExplainAssignment = z.infer<typeof explainAssignment>;\n\nexport const explainLocal = z.object({\n\troutine: tableIndex,\n\tname: z.string(),\n\tparameter: z.boolean(),\n\treference: z.boolean(),\n\tdefinitions: z.array(\n\t\tz.object({\n\t\t\t...record,\n\t\t\tkind: z.enum([\"assign\", \"borrowed\", \"counter\"]),\n\t\t\tpath: z.array(z.string()),\n\t\t\tvalue: tableIndex.nullable(),\n\t\t\tcall: tableIndex.nullable(),\n\t\t\tloop: tableIndex.nullable(),\n\t\t}),\n\t),\n});\nexport type ExplainLocal = z.infer<typeof explainLocal>;\n\nexport const explainCall = z.object({\n\t...record,\n\t/** The callee's `routines[].key`; the receiver picks the instance row. */\n\tcallee: z.string(),\n\treceiver: z.discriminatedUnion(\"kind\", [\n\t\tz.object({ kind: z.literal(\"none\") }),\n\t\tz.object({ kind: z.literal(\"path\"), path: tableIndex }),\n\t\tz.object({\n\t\t\tkind: z.literal(\"pattern\"),\n\t\t\tpath: tableIndex,\n\t\t\tindexes: z.array(tableIndex),\n\t\t}),\n\t]),\n\t/** One expression per parameter; a by-reference argument is the place it borrows. */\n\targuments: z.array(tableIndex),\n\tloop: tableIndex.nullable(),\n});\nexport type ExplainCall = z.infer<typeof explainCall>;\n\nexport const explainFlags = z.object({\n\tpath: tableIndex,\n\t/** The manifest `io` row the path is bound to. */\n\tinput: z.number().int().nullable(),\n\tclientWritable: z.boolean(),\n\t/** The label of the HMI control that writes the path. */\n\thmiControl: z.string().nullable(),\n\tretained: z.boolean(),\n\tconstantTable: z.boolean(),\n\t/** Every task that writes the path, when that isn't only the task that reads it. */\n\twriterTasks: z.array(z.string()),\n\t/** The manifest job and service whose response the path holds. */\n\tservice: z.object({ job: z.number().int(), service: z.string() }).nullable(),\n\tinitial: json.nullable(),\n\treference: z.boolean(),\n});\nexport type ExplainFlags = z.infer<typeof explainFlags>;\n\nexport const explainFile = z.object({\n\tkind: z.literal(\"tsplc-explain\"),\n\tversion: z.literal(1),\n\tpaths: z.array(z.string()),\n\ttexts: z.array(z.string()),\n\texpressions: z.array(explainExpression),\n\t/**\n\t * Conditions as a tree: each entry holds under its parent, so a statement's conditions are its\n\t * entry and every parent, outermost last. Statements in one branch share the outer entries.\n\t */\n\tconditions: z.array(\n\t\tz.object({ parent: tableIndex.nullable(), condition: explainCondition }),\n\t),\n\t/** Source locations, with the source text there. */\n\tsites: z.array(z.object({ range: sourceRange, text: tableIndex.nullable() })),\n\troutines: z.array(\n\t\tz.object({\n\t\t\tkey: z.string(),\n\t\t\t/** The manifest's function id, when the manifest lists the routine. */\n\t\t\tfunction: z.number().int().nullable(),\n\t\t\tinstance: tableIndex.nullable(),\n\t\t\tname: z.string(),\n\t\t\tdeclaration: sourceRange.nullable(),\n\t\t\t/** The manifest job the instance is. */\n\t\t\tjob: z.number().int().nullable(),\n\t\t\t/**\n\t\t\t * What its expressions and conditions name, by slot: instances of one routine share those\n\t\t\t * and differ only here. `paths` index `paths`, `locals` index `locals`, `calls` index\n\t\t\t * `calls` and `loops` index `loops`.\n\t\t\t */\n\t\t\tpaths: z.array(tableIndex),\n\t\t\tlocals: z.array(tableIndex),\n\t\t\tcalls: z.array(tableIndex),\n\t\t\tloops: z.array(tableIndex),\n\t\t}),\n\t),\n\tloops: z.array(\n\t\tz.object({\n\t\t\troutine: tableIndex,\n\t\t\tposition,\n\t\t\tcounter: tableIndex,\n\t\t\tfirst: tableIndex,\n\t\t\tlimit: tableIndex,\n\t\t\texclusive: z.boolean(),\n\t\t\tstep: tableIndex,\n\t\t\tmaxIterations: z.number().int().nonnegative(),\n\t\t\tbreaks: z.array(z.array(explainCondition)),\n\t\t\tparent: tableIndex.nullable(),\n\t\t\tsite: tableIndex.nullable(),\n\t\t}),\n\t),\n\tassignments: z.array(explainAssignment),\n\tlocals: z.array(explainLocal),\n\treturns: z.array(z.object({ ...record, value: tableIndex.nullable() })),\n\tcalls: z.array(explainCall),\n\t/** The routines each task runs directly, in the order it runs them. */\n\tentries: z.array(\n\t\tz.object({\n\t\t\troutine: tableIndex,\n\t\t\ttask: z.string(),\n\t\t\torder: z.number().int().nonnegative(),\n\t\t}),\n\t),\n\tflags: z.array(explainFlags),\n\t/** Object id → `paths` index; −1 is `undefined`. */\n\treferences: z.record(z.string(), tableIndex),\n});\nexport type ExplainFile = z.infer<typeof explainFile>;\n",
|
|
7
|
+
"import { z } from \"zod\";\n\n/**\n * What a build tells the debugger: every TypeScript identity it can show, and the target symbol each one reads.\n * TypeScript paths (`bench.instruments[10].phase`) are the identity; `target` strings are opaque to\n * everything except the target's adapter (for CODESYS, IEC symbol paths such as `Bench.instruments…`).\n * Written by the compiler beside its emitted ST and shipped with each release, as `debugManifestFile`.\n */\nexport const debugManifestFile = \"debug.json\";\n\n/** A location in the project's own sources: `file` indexes `sources`; lines and columns are 1-based. */\nexport const sourceRange = z.object({\n\tfile: z.number().int(),\n\tline: z.number().int(),\n\tcolumn: z.number().int(),\n\tendLine: z.number().int(),\n\tendColumn: z.number().int(),\n});\n\n/** Any JSON value. */\nexport const json: z.ZodType<unknown> = z.lazy(() =>\n\tz.union([\n\t\tz.string(),\n\t\tz.number(),\n\t\tz.boolean(),\n\t\tz.null(),\n\t\tz.array(json),\n\t\tz.record(z.string(), json),\n\t]),\n);\n\nexport const debugField = z.object({\n\tname: z.string(),\n\ttarget: z.string(),\n\ttype: z.string(),\n\tdeclaration: sourceRange.optional(),\n\t/** Compiler-made storage, such as an async job's `step`; hidden unless asked for. */\n\tgenerated: z.literal(true).optional(),\n});\n\n/** Keys of `types` are opaque ids; scalars use their IEC name, such as `BOOL`. */\nexport const debugType = z.discriminatedUnion(\"kind\", [\n\tz.object({\n\t\tkind: z.literal(\"scalar\"),\n\t\tiec: z.string(),\n\t\t/** A STRING's or WSTRING's capacity in characters. */\n\t\tcapacity: z.number().int().optional(),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"enum\"),\n\t\tname: z.string(),\n\t\tmembers: z.record(z.string(), z.number().int()),\n\t\t/** For a plain TypeScript program's string-literal union, the string each member stands for. */\n\t\ttexts: z.record(z.string(), z.string()).optional(),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"record\"),\n\t\tname: z.string(),\n\t\tdeclaration: sourceRange.optional(),\n\t\tfields: z.array(debugField),\n\t}),\n\tz.object({\n\t\tkind: z.literal(\"array\"),\n\t\telement: z.string(),\n\t\tlength: z.number().int(),\n\t\t/** The first index; TypeScript paths use the target's own indexes, `lower` to `lower + length - 1`. */\n\t\tlower: z.number().int(),\n\t\t/** For `Record<Enum, T>`, the enum whose member values are the indexes. */\n\t\tindex: z.string().optional(),\n\t}),\n]);\n\nexport const debugRoot = z.object({\n\tpath: z.string(),\n\ttarget: z.string(),\n\ttype: z.string(),\n\tdeclaration: sourceRange.optional(),\n\t/** Readable at runtime through the target's adapter; for CODESYS, all stored state is. */\n\treadable: z.boolean(),\n\tgenerated: z.literal(true).optional(),\n});\n\n/** A field the compiler folded away: it has no runtime storage, but its value is known. */\nexport const debugConstant = z.object({\n\tpath: z.string(),\n\ttype: z.string(),\n\t/** Integers and durations as `encodeConstant` writes them. */\n\tvalue: json,\n\tdeclaration: sourceRange.optional(),\n});\n\nexport const debugIo = z.object({\n\tpath: z.string(),\n\ttarget: z.string(),\n\tdirection: z.enum([\"input\", \"output\"]),\n\ttype: z.string(),\n\tdevice: z.string().optional(),\n\tchannel: z.string().optional(),\n\taddress: z.string().optional(),\n\tinverted: z.literal(true).optional(),\n\tshared: z.literal(true).optional(),\n});\n\nexport const debugChannel = z.object({\n\tid: z.string(),\n\tname: z.string(),\n\tdirection: z.enum([\"input\", \"output\"]),\n\ttype: z.string(),\n\toffsetBits: z.number().int(),\n\tbits: z.number().int(),\n\taddress: z.string().optional(),\n\tunit: z.string().optional(),\n\tdescription: z.string().optional(),\n});\n\nexport const debugDevice = z.object({\n\tid: z.string(),\n\tproduct: z.string().optional(),\n\tvendor: z.string().optional(),\n\tproductCode: z.string().optional(),\n\tnetwork: z\n\t\t.object({ address: z.string(), rpiMs: z.number().optional() })\n\t\t.optional(),\n\tconnection: z.string().optional(),\n\tassemblies: z.array(\n\t\tz.object({\n\t\t\tdirection: z.enum([\"input\", \"output\"]),\n\t\t\tbytes: z.number().int(),\n\t\t\taddress: z.string().optional(),\n\t\t\t/** A byte array over the whole assembly, mapped or not. */\n\t\t\traw: z.string().optional(),\n\t\t}),\n\t),\n\t/**\n\t * Target paths of the driver's own state, such as a generated adapter's `eState`; absent means\n\t * the device's health is unknown.\n\t */\n\thealth: z\n\t\t.object({\n\t\t\tstate: z.string().optional(),\n\t\t\tstates: z.record(z.string(), z.number().int()).optional(),\n\t\t\tdiagnostic: z.string().optional(),\n\t\t\tmessage: z.string().optional(),\n\t\t})\n\t\t.optional(),\n\t/** Status symbols by label: hand-configured ones, and a generated Modbus server's error. */\n\tstatus: z.record(z.string(), z.string()).optional(),\n\tchannels: z.array(debugChannel),\n});\n\n/** A specialized function: one per method per instance, so `reads` resolve to concrete paths. */\nexport const debugFunction = z.object({\n\tid: z.number().int(),\n\tname: z.string(),\n\tdeclaration: sourceRange,\n\t/** The TypeScript path of `this`, for a method specialized to one instance. */\n\tinstance: z.string().optional(),\n\ttask: z.string().optional(),\n\ttarget: z.string(),\n\t/** Member reads in the body whose runtime path is static in this specialization. */\n\treads: z.array(z.object({ range: sourceRange, path: z.string() })),\n});\n\n/** The fields of a job's state, by name, with the IEC type the generated job block declares. */\nexport const jobStateFields = {\n\tstep: \"UINT\",\n\tcancelling: \"BOOL\",\n\tbusy: \"BOOL\",\n\tdone: \"BOOL\",\n\terror: \"UDINT\",\n} as const;\n\n/**\n * The fields the compiler adds to a block for the debugger, by key, with their IEC types: copies\n * of a job's `busy` and `step` for its trace, when it last started, and a service call's job and\n * request counter.\n */\nexport const instrumentationFields = {\n\tbusy: jobStateFields.busy,\n\tstep: jobStateFields.step,\n\tstartedAt: \"UDINT\",\n\tjob: \"UDINT\",\n\tsequence: \"UDINT\",\n} as const;\n\nexport const debugJob = z.object({\n\tid: z.number().int(),\n\tname: z.string(),\n\tdeclaration: sourceRange,\n\tinstance: z.string().optional(),\n\t/** The job's state, with the fields of `jobStateFields`. */\n\ttarget: z.string(),\n\tsteps: z.array(\n\t\tz.object({\n\t\t\tstep: z.number().int(),\n\t\t\tkind: z.enum([\"await\", \"return\", \"throw\", \"statement\"]),\n\t\t\trange: sourceRange,\n\t\t\ttext: z.string(),\n\t\t}),\n\t),\n\t/**\n\t * The PLC clock in milliseconds when the job last started: the clock of telemetry records'\n\t * `time` and a batch's `now`.\n\t */\n\tstartedAt: z.string().optional(),\n\t/**\n\t * Service calls the job awaits, its nested jobs' included; `sequence` is the request counter sent\n\t * as `x-tsplc-request`, with `job`'s id when a nested job makes the call.\n\t */\n\trequests: z.array(\n\t\tz.object({\n\t\t\tservice: z.string(),\n\t\t\ttarget: z.string(),\n\t\t\tsequence: z.string(),\n\t\t\tjob: z.number().int().optional(),\n\t\t}),\n\t),\n\t/** Made by the compiler, such as a service call's own job; hidden unless asked for. */\n\tgenerated: z.literal(true).optional(),\n});\n\n/**\n * Where `debug.trace` records: an enum state field changing, a decision function returning a\n * different value, or a job starting or finishing. Trace records name their site by `id`.\n */\nexport const debugEventSite = z.object({\n\tid: z.number().int(),\n\tkind: z.enum([\"state\", \"decision\", \"job\"]),\n\t/** For `kind: \"job\"`: the job, and whether it starts or finishes at this site. */\n\tjob: z.number().int().optional(),\n\tphase: z.enum([\"started\", \"finished\"]).optional(),\n\t/** The TypeScript path written, or of the job. */\n\tpath: z.string(),\n\tfunction: z.number().int().optional(),\n\ttype: z.string(),\n\trange: sourceRange,\n\ttext: z.string(),\n\ttask: z.string(),\n\t/**\n\t * Guard values captured in the same scan, at the write: each `if` condition leaf enclosing it.\n\t * `stable` is false when the body between the guard and the write can change the leaf.\n\t */\n\toperands: z.array(\n\t\tz.object({\n\t\t\ttext: z.string(),\n\t\t\trange: sourceRange,\n\t\t\ttype: z.string(),\n\t\t\tpath: z.string().optional(),\n\t\t\tstable: z.boolean(),\n\t\t}),\n\t),\n});\n\n/** A writer slot's value before any site writes it; site ids count from 1. */\nexport const neverWrittenSlot = 0;\n\n/** The IEC type of a writer slot, which holds the id of the site that last wrote its output. */\nexport const writerSlotType = \"UINT\";\n\n/** The statement that last wrote each output, per scan. */\nexport const debugWriter = z.object({\n\toutput: z.string(),\n\ttarget: z.string(),\n\t/** Every statement that can write `output` is probed, so the slot names its last writer exactly. */\n\texact: z.boolean().optional(),\n\tsites: z.array(\n\t\tz.object({\n\t\t\tid: z.number().int(),\n\t\t\trange: sourceRange,\n\t\t\tfunction: z.number().int(),\n\t\t\t/** The `explain.json` assignments this site is, one per instance that runs it. */\n\t\t\tassignments: z.array(z.number().int()).optional(),\n\t\t}),\n\t),\n});\n\n/** The IEC type of a task's scan clock. */\nexport const scanClockType = \"DINT\";\n\nexport const debugTask = z.object({\n\tname: z.string(),\n\tintervalMs: z.number(),\n\tpriority: z.number().int(),\n\t/** The PLC clock in milliseconds, of type `scanClockType`, as the task's first program read it this scan. */\n\tclock: z.string().optional(),\n});\n\nexport const debugManifest = z.object({\n\tkind: z.literal(\"tsplc-debug\"),\n\tversion: z.literal(1),\n\tbuild: z.object({\n\t\tid: z.string(),\n\t\t/** A variable holding `id`, to tell which build the controller runs. */\n\t\ttarget: z.string(),\n\t\tcompiler: z.string(),\n\t}),\n\t/** Project-relative paths. */\n\tsources: z.array(z.string()),\n\ttypes: z.record(z.string(), debugType),\n\troots: z.array(debugRoot),\n\tconstants: z.array(debugConstant),\n\tio: z.array(debugIo),\n\tdevices: z.array(debugDevice),\n\tfunctions: z.array(debugFunction),\n\tjobs: z.array(debugJob),\n\tevents: z.array(debugEventSite),\n\twriters: z.array(debugWriter),\n\ttasks: z.array(debugTask),\n\t/** Job error codes by number: 1 cancelled, 2 timeout… */\n\terrors: z.record(z.string(), z.string()),\n\t/** The digest of the build's `explain.json`; absent when the build has no explanations. */\n\texplain: z.object({ sha256: z.string() }).optional(),\n});\n\nexport type SourceRange = z.infer<typeof sourceRange>;\nexport type DebugType = z.infer<typeof debugType>;\nexport type DebugField = z.infer<typeof debugField>;\nexport type DebugRoot = z.infer<typeof debugRoot>;\nexport type DebugConstant = z.infer<typeof debugConstant>;\nexport type DebugIo = z.infer<typeof debugIo>;\nexport type DebugDevice = z.infer<typeof debugDevice>;\nexport type DebugChannel = z.infer<typeof debugChannel>;\nexport type DebugFunction = z.infer<typeof debugFunction>;\nexport type DebugJob = z.infer<typeof debugJob>;\nexport type DebugEventSite = z.infer<typeof debugEventSite>;\nexport type DebugWriter = z.infer<typeof debugWriter>;\nexport type DebugTask = z.infer<typeof debugTask>;\nexport type DebugManifest = z.infer<typeof debugManifest>;\n",
|
|
8
|
+
"import { join } from \"node:path\";\nimport { scalarRead, type TargetAdapter } from \"./adapter\";\nimport type {\n\tExplanationResponse,\n\tForced,\n\tSession,\n\tStreamEvent,\n\tTimelineEntry,\n\tWatchGroups,\n} from \"./api\";\nimport { followAppServer } from \"./app-server\";\nimport type { LoadedExplanations } from \"./build-files\";\nimport { DebugError } from \"./errors\";\nimport { createExplainer } from \"./explain\";\nimport type { DebugManifest } from \"./manifest\";\nimport { createPaths } from \"./paths\";\nimport { createRequestFollower } from \"./requests\";\nimport { createShownReads } from \"./shown\";\nimport { createTelemetryFollower } from \"./telemetry\";\nimport { createTimeline, timelineEntries } from \"./timeline\";\nimport { createTraceDecoder } from \"./trace\";\nimport { createValueReader } from \"./values\";\nimport { loadWatchGroups } from \"./watch\";\n\nexport interface DebuggerOptions {\n\tmanifest: DebugManifest;\n\t/** Owned by the debugger from here on: closing the debugger closes it. */\n\tadapter: TargetAdapter;\n\t/** Saved watch groups live here. */\n\tstateDirectory: string;\n\t/** `debug.watch` from the config. */\n\twatch: Record<string, string[]>;\n\t/** The app server, whose telemetry and request trace are pulled every second. */\n\tserver?: { url: string; token: string };\n\trelease?: Session[\"release\"];\n\t/** Entries from before the debugger started, such as the agent's deployments. */\n\ttimeline?: readonly TimelineEntry[];\n\tprojectRoot?: string;\n\t/** The build's `explain.json`, or null when it has none. */\n\texplanations: LoadedExplanations | null;\n\t/** The IEC expressions the controller forces, or null when they can't be read; null when nothing reports them. */\n\tforced: (() => Promise<readonly string[] | null>) | null;\n\tlog: (message: string) => void;\n}\n\n/** How often the build id is read through the controller. */\nconst buildCheckMs = 10_000;\n\n/**\n * The debugger for one build on one controller (contributing/architecture.md). It reads what the\n * pages show through the adapter, follows the app server's telemetry and requests, and keeps the\n * recent window of both. Everything it offers is read-only.\n */\nexport const createDebugger = async (options: DebuggerOptions) => {\n\tconst { manifest, adapter } = options;\n\tconst paths = createPaths(manifest);\n\tconst telemetry = createTelemetryFollower(manifest);\n\tconst requests = createRequestFollower();\n\tconst timeline = createTimeline();\n\tconst watchGroups = await loadWatchGroups(\n\t\tjoin(options.stateDirectory, \"watch.json\"),\n\t\toptions.watch,\n\t);\n\tconst listeners = new Set<(event: StreamEvent) => void>();\n\tconst controller = new AbortController();\n\tlet controllerBuild: string | null = null;\n\n\tconst emit = (event: StreamEvent) => {\n\t\tfor (const listener of listeners) {\n\t\t\tlistener(event);\n\t\t}\n\t};\n\tconst record = (entry: TimelineEntry) => {\n\t\temit({ name: \"timeline\", data: timeline.add(entry) });\n\t};\n\tfor (const entry of options.timeline ?? []) {\n\t\ttimeline.add(entry);\n\t}\n\n\tconst session = (): Session => ({\n\t\tbuild: {\n\t\t\tmanifest: manifest.build.id,\n\t\t\tcontroller: controllerBuild,\n\t\t\tmatches: controllerBuild === manifest.build.id,\n\t\t},\n\t\tconnection: { ...adapter.connection(), endpoint: adapter.endpoint },\n\t\treading: { method: adapter.method, intervalMs: adapter.samplingMs },\n\t\ttasks: telemetry.tasks(),\n\t\tclock: telemetry.clock(),\n\t\t...(options.release && { release: options.release }),\n\t\t...(options.projectRoot && { projectRoot: options.projectRoot }),\n\t});\n\tconst sessionChanged = () => emit({ name: \"session\", data: session() });\n\n\tconst setBuild = (build: string) => {\n\t\tif (build === controllerBuild) {\n\t\t\treturn;\n\t\t}\n\t\tcontrollerBuild = build;\n\t\tsessionChanged();\n\t};\n\n\tconst values = createValueReader({ manifest, paths, adapter });\n\tconst shown = createShownReads({\n\t\tmanifest,\n\t\tpaths,\n\t\tadapter,\n\t\temit,\n\t\tclock: telemetry.clock,\n\t\trequest: requests.call,\n\t});\n\n\tconst stopBuild = adapter.subscribe(\n\t\t[scalarRead(manifest.build.target, \"STRING\")],\n\t\t(_, sample) => {\n\t\t\tif (sample.quality === \"good\" && typeof sample.value === \"string\") {\n\t\t\t\tsetBuild(sample.value);\n\t\t\t}\n\t\t},\n\t\tbuildCheckMs,\n\t);\n\n\tconst stopConnection = adapter.onConnection((connection) => {\n\t\trecord(\n\t\t\ttimelineEntries.connection(\n\t\t\t\tconnection.since,\n\t\t\t\tconnection.state,\n\t\t\t\tconnection.error,\n\t\t\t),\n\t\t);\n\t\tsessionChanged();\n\t\tif (connection.state !== \"connected\") {\n\t\t\tshown.disconnected(connection.error ?? \"The controller is not connected\");\n\t\t}\n\t});\n\n\tconst running = options.server\n\t\t? followAppServer({\n\t\t\t\tserver: options.server,\n\t\t\t\tmanifest,\n\t\t\t\ttelemetry,\n\t\t\t\trequests,\n\t\t\t\ttrace: createTraceDecoder(manifest, paths),\n\t\t\t\tshown,\n\t\t\t\temit,\n\t\t\t\trecord,\n\t\t\t\trecordChange: (entry) =>\n\t\t\t\t\temit({ name: \"timeline\", data: timeline.changed(entry) }),\n\t\t\t\tsetBuild,\n\t\t\t\tsessionChanged,\n\t\t\t\tsignal: controller.signal,\n\t\t\t\tlog: options.log,\n\t\t\t})\n\t\t: undefined;\n\n\tconst explained = options.explanations && {\n\t\tfile: options.explanations,\n\t\texplainer: createExplainer(manifest, options.explanations.file),\n\t};\n\tconst explanations = () => {\n\t\tif (!explained) {\n\t\t\tthrow new DebugError(\"This build has no explanations\", 404);\n\t\t}\n\t\treturn explained;\n\t};\n\t/** The statements that can write `path`; refused when the build has no explanations or the path is unknown. */\n\tconst explain = (path: string): ExplanationResponse => {\n\t\tconst { explainer } = explanations();\n\t\tconst resolved = paths.resolve(path);\n\t\tif (resolved?.kind !== \"target\") {\n\t\t\tthrow new DebugError(`Unknown path ${path}`, 400);\n\t\t}\n\t\tconst explanation = explainer.explain(path);\n\t\treturn {\n\t\t\t...explanation,\n\t\t\ttype: resolved.type,\n\t\t\twriters: explanation.writers.map((writer) => ({\n\t\t\t\t...writer,\n\t\t\t\tindexes: writer.indexes.map(Number),\n\t\t\t\tchains: writer.chains.map((chain) => ({\n\t\t\t\t\t...chain,\n\t\t\t\t\tcalls: [...chain.calls],\n\t\t\t\t})),\n\t\t\t})),\n\t\t};\n\t};\n\t/** The paths the forced IEC expressions name: storage roots and their fields, and I/O bindings. */\n\tconst forced = async (): Promise<Forced> => {\n\t\tconst at = new Date().toISOString();\n\t\tconst expressions = options.forced ? await options.forced() : null;\n\t\treturn {\n\t\t\tforced: expressions && [\n\t\t\t\t...new Set(\n\t\t\t\t\texpressions.flatMap(\n\t\t\t\t\t\t(expression) => paths.fromTarget(expression) ?? [],\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t],\n\t\t\tat,\n\t\t};\n\t};\n\n\treturn {\n\t\tmanifest,\n\t\tpaths,\n\t\tsession,\n\t\texplain,\n\t\tforced,\n\t\t/** `explain.json` as the build wrote it; refused when the build has no explanations. */\n\t\texplanationFile: () => explanations().file,\n\t\tvalues: values.read,\n\t\tjobs: shown.jobs,\n\t\thardware: shown.hardware,\n\t\ttimeline: timeline.since,\n\t\twatchGroups: () => watchGroups.groups(),\n\t\tsaveWatchGroups: (groups: WatchGroups) => watchGroups.save(groups),\n\t\t/** Adds an entry from another source, such as the agent's audit log. */\n\t\trecord,\n\t\twatch: values.watch,\n\t\tshow: shown.show,\n\t\t/** Calls `listener` with every other stream event until the returned function is called. */\n\t\tsubscribe: (listener: (event: StreamEvent) => void) => {\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => listeners.delete(listener);\n\t\t},\n\t\tclose: async () => {\n\t\t\tcontroller.abort();\n\t\t\tstopBuild();\n\t\t\tshown.close();\n\t\t\tstopConnection();\n\t\t\tawait running;\n\t\t\tawait adapter.close();\n\t\t},\n\t};\n};\n\nexport type Debugger = Awaited<ReturnType<typeof createDebugger>>;\n",
|
|
9
|
+
"import type { Quality } from \"@tsplc/opcua/contract\";\nimport type { ConnectionState } from \"./api\";\nimport type { DebugType } from \"./manifest\";\n\n/** One target's value, before the debugger names it by TypeScript path and decodes it. */\nexport interface TargetSample {\n\tvalue: unknown;\n\tquality: Quality;\n\tstatus: string;\n\treceivedAt: string;\n\t/**\n\t * The controller read that returned it: samples with the same `read` were copied in one call.\n\t * Absent from an adapter that doesn't read in batches.\n\t */\n\tread?: number;\n}\n\n/** A target to read, with its type in the manifest, which an adapter may need to parse it. */\nexport interface TargetRead {\n\ttarget: string;\n\ttype: DebugType;\n}\n\nexport const scalarRead = (target: string, iec: string): TargetRead => ({\n\ttarget,\n\ttype: { kind: \"scalar\", iec },\n});\n\nconst qualityRank: Record<Quality, number> = {\n\tgood: 0,\n\tuncertain: 1,\n\tbad: 2,\n\tunavailable: 3,\n};\n\n/** The worst of these qualities; nothing read is unavailable. */\nexport const worstQuality = (\n\tsamples: readonly (TargetSample | undefined)[],\n): Quality =>\n\tsamples.reduce<Quality>((worst, sample) => {\n\t\tconst quality = sample?.quality ?? \"unavailable\";\n\t\treturn qualityRank[quality] > qualityRank[worst] ? quality : worst;\n\t}, \"good\");\n\nexport interface Connection {\n\tstate: ConnectionState;\n\tsince: string;\n\terror?: string;\n}\n\n/**\n * Reads one vendor's controller. Only the adapter interprets `target` strings, which come from\n * the manifest (for CODESYS, IEC symbol paths). It never writes.\n */\nexport interface TargetAdapter {\n\t/** How it reads, for display, such as \"engineering login\". */\n\treadonly method: string;\n\t/** Where it reads, for display. */\n\treadonly endpoint: string;\n\t/** How often subscribed targets are read; a value is at most about this old while connected. */\n\treadonly samplingMs: number;\n\tconnection(): Connection;\n\tonConnection(listener: (connection: Connection) => void): () => void;\n\t/** Reads targets now; fails while disconnected. Targets that can't be read come back bad or unavailable. */\n\tread(targets: readonly TargetRead[]): Promise<Map<string, TargetSample>>;\n\t/**\n\t * Calls `listener` with each target's value, about every `intervalMs` (`samplingMs` by\n\t * default) or on every change, across reconnects, until the returned function is called. While\n\t * disconnected each target is reported unavailable or bad.\n\t */\n\tsubscribe(\n\t\ttargets: readonly TargetRead[],\n\t\tlistener: (target: string, sample: TargetSample) => void,\n\t\tintervalMs?: number,\n\t): () => void;\n\tclose(): Promise<void>;\n}\n",
|
|
10
|
+
"import { sleep } from \"@tsplc/opcua\";\nimport { requestsPath, requestsReply } from \"@tsplc/server/requests\";\nimport { telemetryPath, telemetryReply } from \"@tsplc/server/telemetry\";\nimport type { StreamEvent, TimelineEntry } from \"./api\";\nimport { errorMessage } from \"./errors\";\nimport type { DebugManifest } from \"./manifest\";\nimport { type createRequestFollower, taggedCall } from \"./requests\";\nimport type { createShownReads } from \"./shown\";\nimport type { createTelemetryFollower, ReceivedRecord } from \"./telemetry\";\nimport { timelineEntries } from \"./timeline\";\nimport type { createTraceDecoder } from \"./trace\";\n\nconst pullMs = 1000;\n\n/**\n * Pulls the app server's telemetry and request trace every second until `signal` aborts: records\n * go to the timeline, and the jobs they name are updated. A failing pull is logged when its\n * reason changes.\n */\nexport const followAppServer = (context: {\n\tserver: { url: string; token: string };\n\tmanifest: DebugManifest;\n\ttelemetry: ReturnType<typeof createTelemetryFollower>;\n\trequests: ReturnType<typeof createRequestFollower>;\n\ttrace: ReturnType<typeof createTraceDecoder>;\n\tshown: ReturnType<typeof createShownReads>;\n\temit: (event: StreamEvent) => void;\n\t/** Adds an entry to the timeline. */\n\trecord: (entry: TimelineEntry) => void;\n\t/** Sends again an entry of the timeline that has changed. */\n\trecordChange: (entry: TimelineEntry) => void;\n\t/** The build the controller runs, as the telemetry reports it. */\n\tsetBuild: (build: string) => void;\n\t/** Sends the session, whose scan rates and clock estimate the telemetry changes. */\n\tsessionChanged: () => void;\n\tsignal: AbortSignal;\n\tlog: (message: string) => void;\n}) => {\n\tconst { server, manifest, telemetry, requests, trace, shown, signal } =\n\t\tcontext;\n\n\tconst receive = (received: ReceivedRecord) => {\n\t\tconst { record, at } = received;\n\t\tif (record.kind === \"trace\") {\n\t\t\tconst traced = { ...received, record };\n\t\t\tconst event = trace.decode(traced);\n\t\t\tif (event) {\n\t\t\t\tcontext.record(timelineEntries.trace(at, event));\n\t\t\t}\n\t\t\tconst site = trace.job(traced);\n\t\t\tif (site) {\n\t\t\t\tshown.traced(site.job, site.started, at);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcontext.record(\n\t\t\ttimelineEntries.app(at, received.task, received.sequence, record),\n\t\t);\n\t\tif (record.kind !== \"exception\" || record.handled) {\n\t\t\treturn;\n\t\t}\n\t\tconst job = manifest.jobs.find(\n\t\t\t({ name, instance }) =>\n\t\t\t\tname === record.function && instance === record.instance,\n\t\t);\n\t\tif (job) {\n\t\t\tshown.failed(job, {\n\t\t\t\tat,\n\t\t\t\tcode: record.code,\n\t\t\t\t...(record.name && { name: record.name }),\n\t\t\t\tsource: record.source,\n\t\t\t});\n\t\t}\n\t};\n\n\tconst pull = async (path: string, since: number) => {\n\t\tconst url = new URL(path, server.url);\n\t\turl.searchParams.set(\"since\", String(since));\n\t\tconst response = await fetch(url, {\n\t\t\theaders: { authorization: `Bearer ${server.token}` },\n\t\t\tsignal,\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`The server answered ${response.status}`);\n\t\t}\n\t\treturn response.json();\n\t};\n\n\tconst pullTelemetry = async () => {\n\t\tconst reply = telemetryReply.parse(\n\t\t\tawait pull(telemetryPath, telemetry.since()),\n\t\t);\n\t\tfor (const item of telemetry.accept(reply)) {\n\t\t\treceive(item);\n\t\t}\n\t\tconst build = telemetry.build();\n\t\tif (build) {\n\t\t\tcontext.setBuild(build);\n\t\t}\n\t\tif (reply.batches.length) {\n\t\t\tcontext.sessionChanged();\n\t\t}\n\t};\n\n\tconst pullRequests = async () => {\n\t\tconst reply = requestsReply.parse(\n\t\t\tawait pull(requestsPath, requests.since()),\n\t\t);\n\t\trequests.accept(reply, ({ request, entry, added }) => {\n\t\t\tcontext.emit({ name: \"request\", data: request });\n\t\t\tif (added) {\n\t\t\t\tcontext.record(entry);\n\t\t\t} else {\n\t\t\t\tcontext.recordChange(entry);\n\t\t\t}\n\t\t\tconst call = taggedCall(request);\n\t\t\tif (!call) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst job = manifest.jobs.find(({ id }) => id === call.job);\n\t\t\tif (job) {\n\t\t\t\tshown.updateJob(job);\n\t\t\t}\n\t\t});\n\t};\n\n\tconst repeat = async (name: string, work: () => Promise<void>) => {\n\t\tlet failure: string | undefined;\n\t\twhile (!signal.aborted) {\n\t\t\ttry {\n\t\t\t\tawait work();\n\t\t\t\tfailure = undefined;\n\t\t\t} catch (error) {\n\t\t\t\tif (signal.aborted) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst message = errorMessage(error);\n\t\t\t\tif (message !== failure) {\n\t\t\t\t\tcontext.log(`${name} failed: ${message}`);\n\t\t\t\t}\n\t\t\t\tfailure = message;\n\t\t\t}\n\t\t\tawait sleep(pullMs, signal);\n\t\t}\n\t};\n\n\treturn Promise.all([\n\t\trepeat(\"Reading the server's telemetry\", pullTelemetry),\n\t\trepeat(\"Reading the server's requests\", pullRequests),\n\t]);\n};\n",
|
|
11
|
+
"/** What to show for a caught value: an error's message, or anything else as text. */\nexport const errorMessage = (error: unknown) =>\n\terror instanceof Error ? error.message : String(error);\n\n/** A request the API refuses, with its HTTP status. */\nexport class DebugError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly status: number,\n\t) {\n\t\tsuper(message);\n\t}\n}\n",
|
|
12
|
+
"/**\n * How far a follower has taken one of the app server's logs, whose entries count from 1. A\n * restarted server counts from 1 again, so a reply whose `latest` is below the newest entry taken\n * means starting over.\n */\nexport const createServerCursor = () => {\n\tlet newest = 0;\n\treturn {\n\t\tnewest: () => newest,\n\t\t/** False, and back at the start, when the server restarted since the entries taken. */\n\t\tcontinues: (latest: number) => {\n\t\t\tif (latest < newest) {\n\t\t\t\tnewest = 0;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\t\ttake: (seq: number) => {\n\t\t\tnewest = Math.max(newest, seq);\n\t\t},\n\t};\n};\n",
|
|
13
|
+
"import type {\n\tAppRecord,\n\tConnectionState,\n\tRequestTrace,\n\tTimelineEntry,\n\tTraceEvent,\n} from \"./api\";\n\nexport type Entry<Kind extends TimelineEntry[\"kind\"]> = Extract<\n\tTimelineEntry,\n\t{ kind: Kind }\n>;\ntype Details<Kind extends TimelineEntry[\"kind\"]> = Omit<\n\tEntry<Kind>,\n\t\"at\" | \"approximate\" | \"source\" | \"kind\"\n>;\n\n/**\n * Timeline entries by source. The PLC's records are placed on the app server's clock from their\n * age when the server received them, and the server keeps its own clock, so those are\n * approximate. The agent's entries reach a debugger only when the agent hosts it, on the same clock.\n */\nexport const timelineEntries = {\n\tapp: (\n\t\tat: string,\n\t\ttask: string,\n\t\tsequence: number,\n\t\trecord: AppRecord,\n\t): Entry<\"app\"> => ({\n\t\tat,\n\t\tapproximate: true,\n\t\tsource: \"plc\",\n\t\tkind: \"app\",\n\t\ttask,\n\t\tsequence,\n\t\trecord,\n\t}),\n\ttrace: (at: string, trace: TraceEvent): Entry<\"trace\"> => ({\n\t\tat,\n\t\tapproximate: true,\n\t\tsource: \"plc\",\n\t\tkind: \"trace\",\n\t\ttrace,\n\t}),\n\trequest: (request: RequestTrace): Entry<\"request\"> => ({\n\t\tat: request.startedAt,\n\t\tapproximate: true,\n\t\tsource: \"server\",\n\t\tkind: \"request\",\n\t\trequest,\n\t}),\n\tdeploy: (at: string, details: Details<\"deploy\">): Entry<\"deploy\"> => ({\n\t\tat,\n\t\tapproximate: false,\n\t\tsource: \"agent\",\n\t\tkind: \"deploy\",\n\t\t...details,\n\t}),\n\taudit: (at: string, details: Details<\"audit\">): Entry<\"audit\"> => ({\n\t\tat,\n\t\tapproximate: false,\n\t\tsource: \"agent\",\n\t\tkind: \"audit\",\n\t\t...details,\n\t}),\n\tconnection: (\n\t\tat: string,\n\t\tstate: ConnectionState,\n\t\terror?: string,\n\t): Entry<\"connection\"> => ({\n\t\tat,\n\t\tapproximate: false,\n\t\tsource: \"debugger\",\n\t\tkind: \"connection\",\n\t\tstate,\n\t\t...(error && { error }),\n\t}),\n};\n\n/**\n * Adds `entry` to `entries`, which are oldest first. Sources arrive late and out of order, so it\n * goes after the last entry not later than it.\n */\nexport const insertInTimeOrder = <Placed extends { at: string }>(\n\tentries: Placed[],\n\tentry: Placed,\n) => {\n\tfor (let index = entries.length; index >= 0; index--) {\n\t\tconst before = entries[index - 1];\n\t\tif (before === undefined || before.at <= entry.at) {\n\t\t\tentries.splice(index, 0, entry);\n\t\t\treturn;\n\t\t}\n\t}\n};\n\n/** `<host>.<taken>`: the timeline that issued it, and how many entries it had taken by then. */\nconst cursorPattern = /^([0-9a-f]{8})\\.(\\d+)$/;\n\nexport const isTimelineCursor = (text: string) => cursorPattern.test(text);\n\n/** Where a client resumes the timeline: after the entry with `cursor` `after`, else after time `since`. */\nexport interface TimelineQuery {\n\tsince?: string;\n\tafter?: string;\n}\n\n/** The most entries a timeline keeps; older ones make room. */\nexport const timelineLimit = 10_000;\n\n/**\n * Entries from every source in time order, keeping the newest `timelineLimit`. A cursor from\n * another timeline, such as the one before a deploy or a restart, resumes from the start of this one.\n */\nexport const createTimeline = () => {\n\tconst host = crypto.randomUUID().slice(0, 8);\n\tconst entries: (TimelineEntry & { cursor: string })[] = [];\n\tlet taken = 0;\n\tconst takenAt = (cursor: string) => {\n\t\tconst [, issuer, count] = cursorPattern.exec(cursor) ?? [];\n\t\treturn issuer === host ? Number(count) : 0;\n\t};\n\tconst stamp = (entry: TimelineEntry) => {\n\t\ttaken += 1;\n\t\treturn Object.assign(entry, { cursor: `${host}.${taken}` });\n\t};\n\treturn {\n\t\t/** Stamps `entry` with its `cursor` in place, because the request follower changes an entry after adding it. */\n\t\tadd: (entry: TimelineEntry) => {\n\t\t\tconst stamped = stamp(entry);\n\t\t\tinsertInTimeOrder(entries, stamped);\n\t\t\tif (entries.length > timelineLimit) {\n\t\t\t\tentries.splice(0, entries.length - timelineLimit);\n\t\t\t}\n\t\t\treturn stamped;\n\t\t},\n\t\t/** Gives an added entry that has since changed the next cursor, so a client resuming after an earlier one receives the change. */\n\t\tchanged: stamp,\n\t\t/** In time order; all of them without a query. */\n\t\tsince: ({ since, after }: TimelineQuery) => {\n\t\t\tif (after !== undefined) {\n\t\t\t\tconst resumed = takenAt(after);\n\t\t\t\treturn entries.filter((entry) => takenAt(entry.cursor) > resumed);\n\t\t\t}\n\t\t\treturn since ? entries.filter((entry) => entry.at > since) : [...entries];\n\t\t},\n\t};\n};\n",
|
|
14
|
+
"import type { RequestsReply } from \"@tsplc/server/requests\";\nimport type { RequestTrace } from \"./api\";\nimport { createServerCursor } from \"./server-cursor\";\nimport { type Entry, timelineEntries } from \"./timeline\";\n\n/** Traces kept for jobs to find their calls by; older ones are forgotten. */\nconst callsRemembered = 1000;\n\n/** A call that started or ended, with its timeline entry; `added` when the entry is new. */\ninterface RequestChange {\n\trequest: RequestTrace;\n\tentry: Entry<\"request\">;\n\tadded: boolean;\n}\n\n/** What the PLC tags a call with: its job and the call site's count. */\ninterface TaggedCall {\n\tjob: number;\n\tservice: string;\n\tsequence: number;\n}\n\n/** The tags of a call the PLC made from a job; undefined for any other call. */\nexport const taggedCall = ({\n\tjob,\n\tservice,\n\tsequence,\n}: RequestTrace): TaggedCall | undefined =>\n\tjob === undefined || sequence === undefined\n\t\t? undefined\n\t\t: { job, service, sequence };\n\nconst callKey = ({ job, service, sequence }: TaggedCall) =>\n\t`${job}:${service}:${sequence}`;\n\n/**\n * Follows the app server's request trace (`GET /tsplc/debug/requests`), asking again from before\n * the oldest call still pending, so each call is seen when it starts and again when it ends.\n */\nexport const createRequestFollower = () => {\n\tconst cursor = createServerCursor();\n\tconst pending = new Map<number, Entry<\"request\">>();\n\tconst calls = new Map<string, RequestTrace>();\n\n\treturn {\n\t\t/** Where the next pull starts. */\n\t\tsince: () =>\n\t\t\tpending.size ? Math.min(...pending.keys()) - 1 : cursor.newest(),\n\t\t/** Takes a reply to `?since=<since()>`, telling `changed` of each call as it is taken. */\n\t\taccept: (\n\t\t\treply: RequestsReply,\n\t\t\tchanged: (change: RequestChange) => void,\n\t\t) => {\n\t\t\tif (!cursor.continues(reply.latest)) {\n\t\t\t\tpending.clear();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst oldest = reply.requests[0]?.seq;\n\t\t\tif (oldest !== undefined) {\n\t\t\t\tfor (const seq of pending.keys()) {\n\t\t\t\t\tif (seq < oldest) {\n\t\t\t\t\t\tpending.delete(seq);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const request of reply.requests) {\n\t\t\t\tconst waiting = pending.get(request.seq);\n\t\t\t\tif (waiting && request.status === \"pending\") {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!waiting && request.seq <= cursor.newest()) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst entry = waiting ?? timelineEntries.request(request);\n\t\t\t\tentry.request = request;\n\t\t\t\tcursor.take(request.seq);\n\t\t\t\tif (request.status === \"pending\") {\n\t\t\t\t\tpending.set(request.seq, entry);\n\t\t\t\t} else {\n\t\t\t\t\tpending.delete(request.seq);\n\t\t\t\t}\n\t\t\t\tconst tagged = taggedCall(request);\n\t\t\t\tif (tagged) {\n\t\t\t\t\tcalls.set(callKey(tagged), request);\n\t\t\t\t\tfor (const key of [...calls.keys()].slice(0, -callsRemembered)) {\n\t\t\t\t\t\tcalls.delete(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tchanged({ request, entry, added: !waiting });\n\t\t\t}\n\t\t},\n\t\t/** The server's trace of a call by its tags. */\n\t\tcall: (call: TaggedCall) => calls.get(callKey(call)),\n\t};\n};\n\nexport type ServiceCallLookup = ReturnType<\n\ttypeof createRequestFollower\n>[\"call\"];\n",
|
|
15
|
+
"import {\n\telementaryType,\n\tisIntegerValued,\n\tnanosecondsPerMillisecond,\n} from \"@tsplc/iec\";\nimport { type ConstantScalar, decodeConstant } from \"./constant\";\nimport type { DebugManifest } from \"./manifest\";\nimport { typeOf } from \"./paths\";\n\n/** A value as the PLC holds it: durations in nanoseconds, enums by member value. */\nexport type PlcValue =\n\t| { kind: \"bool\"; value: boolean }\n\t| { kind: \"integer\"; value: bigint }\n\t| { kind: \"float\"; value: number }\n\t| { kind: \"text\"; value: string }\n\t/** The PLC clock, known to lie between `low` and `high`. */\n\t| { kind: \"interval\"; low: bigint; high: bigint }\n\t| { kind: \"record\"; fields: Readonly<Record<string, Outcome>> }\n\t| { kind: \"array\"; lower: number; items: readonly Outcome[] }\n\t/** An object reference: the id it holds (−1 for `undefined`) and the object's path, null for `undefined`. */\n\t| { kind: \"instance\"; id: bigint; path: string | null };\n\n/** A value, or why it isn't known, with the reasons it is only an estimate. */\nexport type Outcome =\n\t| { known: true; value: PlcValue; estimate: readonly string[] }\n\t| { known: false; reason: string; estimate: readonly string[] };\n\nexport type UnknownOutcome = Extract<Outcome, { known: false }>;\n\n/** Three-valued truth, and `candidate` for a job step that may have run this scan or earlier. */\nexport type Truth = \"true\" | \"false\" | \"unknown\" | \"candidate\";\n\nexport const unknown = (\n\treason: string,\n\testimate: readonly string[] = [],\n): UnknownOutcome => ({\n\tknown: false,\n\treason,\n\testimate,\n});\nexport const known = (\n\tvalue: PlcValue,\n\testimate: readonly string[] = [],\n): Outcome => ({\n\tknown: true,\n\tvalue,\n\testimate,\n});\nexport const withEstimate = (\n\toutcome: Outcome,\n\testimate: readonly string[],\n): Outcome =>\n\testimate.length\n\t\t? { ...outcome, estimate: [...new Set([...outcome.estimate, ...estimate])] }\n\t\t: outcome;\nexport const merge = (...lists: readonly (readonly string[])[]): string[] => [\n\t...new Set(lists.flat()),\n];\n\nexport const and = (truths: readonly Truth[]): Truth => {\n\tif (truths.includes(\"false\")) {\n\t\treturn \"false\";\n\t}\n\tif (truths.includes(\"unknown\")) {\n\t\treturn \"unknown\";\n\t}\n\treturn truths.includes(\"candidate\") ? \"candidate\" : \"true\";\n};\n\nconst fromConstant = (scalar: ConstantScalar): PlcValue => ({\n\tkind: \"integer\",\n\tvalue: scalar.kind === \"integer\" ? scalar.value : scalar.nanoseconds,\n});\n\n/** A JSON constant of `explain.json`, or a decoded sample, as the PLC value of `type`. */\nexport const sampleValue = (\n\tmanifest: DebugManifest,\n\ttype: string,\n\tdecoded: unknown,\n): PlcValue | undefined => {\n\tconst declared = typeOf(manifest, type);\n\tif (declared.kind === \"enum\") {\n\t\tconst member =\n\t\t\ttypeof decoded === \"string\" ? declared.members[decoded] : undefined;\n\t\tif (typeof member === \"number\") {\n\t\t\treturn { kind: \"integer\", value: BigInt(member) };\n\t\t}\n\t\treturn typeof decoded === \"number\" || typeof decoded === \"bigint\"\n\t\t\t? { kind: \"integer\", value: BigInt(decoded) }\n\t\t\t: undefined;\n\t}\n\tconst scalar =\n\t\tdeclared.kind === \"scalar\" ? elementaryType(declared.iec) : undefined;\n\tconst constant = decodeConstant(decoded);\n\tif (isIntegerValued(scalar)) {\n\t\tif (typeof decoded === \"bigint\") {\n\t\t\treturn { kind: \"integer\", value: decoded };\n\t\t}\n\t\treturn constant?.kind === \"integer\" ? fromConstant(constant) : undefined;\n\t}\n\tswitch (scalar?.family) {\n\t\tcase \"bool\":\n\t\t\tif (typeof decoded === \"boolean\") {\n\t\t\t\treturn { kind: \"bool\", value: decoded };\n\t\t\t}\n\t\t\treturn typeof decoded === \"number\"\n\t\t\t\t? { kind: \"bool\", value: decoded !== 0 }\n\t\t\t\t: undefined;\n\t\tcase \"real\":\n\t\t\treturn typeof decoded === \"number\"\n\t\t\t\t? { kind: \"float\", value: decoded }\n\t\t\t\t: undefined;\n\t\tcase \"duration\":\n\t\t\tif (typeof decoded === \"number\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"integer\",\n\t\t\t\t\tvalue: BigInt(\n\t\t\t\t\t\tMath.round(decoded * Number(nanosecondsPerMillisecond)),\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn typeof decoded === \"string\" && constant?.kind === \"duration\"\n\t\t\t\t? fromConstant(constant)\n\t\t\t\t: undefined;\n\t\tcase \"string\":\n\t\t\treturn typeof decoded === \"string\"\n\t\t\t\t? { kind: \"text\", value: decoded }\n\t\t\t\t: undefined;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n};\n\n/** A constant of `explain.json` whose type doesn't say how to read it, by its JSON shape. */\nexport const constantAggregate = (value: unknown): Outcome => {\n\tif (Array.isArray(value)) {\n\t\treturn known({\n\t\t\tkind: \"array\",\n\t\t\tlower: 0,\n\t\t\titems: value.map((item) => constantAggregate(item)),\n\t\t});\n\t}\n\tif (typeof value === \"object\" && value !== null) {\n\t\treturn known({\n\t\t\tkind: \"record\",\n\t\t\tfields: Object.fromEntries(\n\t\t\t\tObject.entries(value).map(([name, item]) => [\n\t\t\t\t\tname,\n\t\t\t\t\tconstantAggregate(item),\n\t\t\t\t]),\n\t\t\t),\n\t\t});\n\t}\n\tif (typeof value === \"boolean\") {\n\t\treturn known({ kind: \"bool\", value });\n\t}\n\tif (typeof value !== \"number\" && typeof value !== \"string\") {\n\t\treturn unknown(\"a constant this debugger can't show\");\n\t}\n\tconst constant = decodeConstant(value);\n\tif (constant) {\n\t\treturn known(fromConstant(constant));\n\t}\n\treturn known(\n\t\ttypeof value === \"number\"\n\t\t\t? { kind: \"float\", value }\n\t\t\t: { kind: \"text\", value },\n\t);\n};\n\nexport const equalValues = (\n\tleft: PlcValue,\n\tright: PlcValue,\n): boolean | undefined => {\n\tif (left.kind === \"float\" || right.kind === \"float\") {\n\t\tconst leftNumber =\n\t\t\tleft.kind === \"float\" || left.kind === \"integer\"\n\t\t\t\t? Number(left.value)\n\t\t\t\t: Number.NaN;\n\t\tconst rightNumber =\n\t\t\tright.kind === \"float\" || right.kind === \"integer\"\n\t\t\t\t? Number(right.value)\n\t\t\t\t: Number.NaN;\n\t\t// REAL rounding and the login's text precision both blur the last digits.\n\t\treturn (\n\t\t\tMath.abs(leftNumber - rightNumber) <=\n\t\t\tMath.max(Math.abs(leftNumber), Math.abs(rightNumber)) * 1e-6 + 1e-9\n\t\t);\n\t}\n\tif (left.kind === \"bool\" && right.kind === \"bool\") {\n\t\treturn left.value === right.value;\n\t}\n\tif (left.kind === \"integer\" && right.kind === \"integer\") {\n\t\treturn left.value === right.value;\n\t}\n\tif (left.kind === \"text\" && right.kind === \"text\") {\n\t\treturn left.value === right.value;\n\t}\n\tif (left.kind === \"instance\" && right.kind === \"instance\") {\n\t\treturn left.path === right.path;\n\t}\n\treturn undefined;\n};\n",
|
|
16
|
+
"import { nanosecondsPerMillisecond } from \"@tsplc/iec\";\n\n/** A constant's scalar that JSON can't hold as itself: a whole number, or a duration. */\nexport type ConstantScalar =\n\t| { kind: \"integer\"; value: bigint }\n\t| { kind: \"duration\"; nanoseconds: bigint };\n\n/**\n * How `debug.json` and `explain.json` write a constant's scalar: an integer as a number while\n * doubles hold it exactly, else as its decimal text; a duration as whole milliseconds, `250ms`.\n */\nexport const encodeConstant = (scalar: ConstantScalar): number | string => {\n\tswitch (scalar.kind) {\n\t\tcase \"integer\":\n\t\t\treturn Number.isSafeInteger(Number(scalar.value))\n\t\t\t\t? Number(scalar.value)\n\t\t\t\t: String(scalar.value);\n\t\tcase \"duration\":\n\t\t\treturn `${scalar.nanoseconds / nanosecondsPerMillisecond}ms`;\n\t}\n};\n\n/** What `encodeConstant` wrote, or undefined for any other JSON value. */\nexport const decodeConstant = (value: unknown): ConstantScalar | undefined => {\n\tif (typeof value === \"number\" && Number.isInteger(value)) {\n\t\treturn { kind: \"integer\", value: BigInt(value) };\n\t}\n\tif (typeof value !== \"string\") {\n\t\treturn undefined;\n\t}\n\tif (/^-?\\d+$/.test(value)) {\n\t\treturn { kind: \"integer\", value: BigInt(value) };\n\t}\n\tconst milliseconds = /^(-?\\d+)ms$/.exec(value)?.[1];\n\treturn milliseconds === undefined\n\t\t? undefined\n\t\t: {\n\t\t\t\tkind: \"duration\",\n\t\t\t\tnanoseconds: BigInt(milliseconds) * nanosecondsPerMillisecond,\n\t\t\t};\n};\n",
|
|
17
|
+
"import { isWithin } from \"@tsplc/iec/st\";\nimport {\n\tarrayIndex,\n\tjoinPath,\n\tsymbolPathSegments,\n} from \"@tsplc/opcua/contract\";\nimport type { DebugManifest, DebugType, SourceRange } from \"./manifest\";\n\n/**\n * TypeScript paths over a manifest: `bench.instruments[10].phase` names a root\n * (`program.benchs`), then record fields and array indexes. Pure, so the browser UI can use it.\n */\n\n/** A path that reads a target, or a constant the compiler folded. */\nexport type ResolvedPath =\n\t| {\n\t\t\tkind: \"target\";\n\t\t\tpath: string;\n\t\t\ttarget: string;\n\t\t\ttype: string;\n\t\t\treadable: boolean;\n\t\t\tgenerated?: true;\n\t\t\tdeclaration?: SourceRange;\n\t }\n\t| {\n\t\t\tkind: \"constant\";\n\t\t\tpath: string;\n\t\t\ttype: string;\n\t\t\tvalue: unknown;\n\t\t\tdeclaration?: SourceRange;\n\t };\n\ntype TargetPath = Extract<ResolvedPath, { kind: \"target\" }>;\n\n/** Roots or constants that share a prefix, such as `program` above `program.benchs`. */\ninterface GroupPath {\n\tkind: \"group\";\n\tpath: string;\n}\n\n/** A child in the instance tree. */\nexport type PathNode = { name: string } & (ResolvedPath | GroupPath);\n\n/** In a pattern, every index of an array. */\nexport const anyIndex = \"[*]\";\n\n/** Whether `path` is a pattern: `*` stands for any one segment and `[*]` for any index. */\nexport const isPattern = (path: string) => path.includes(\"*\");\n\n/** Thrown by `expand` when more paths match than its limit. */\nexport class TooManyMatches extends RangeError {\n\tconstructor(limit: number) {\n\t\tsuper(`More than ${limit} values match`);\n\t}\n}\n\n/** Names and indexes as the controller's symbol paths split them, and `[*]` in patterns. */\nexport const pathSegments = (path: string) =>\n\tpath\n\t\t.split(anyIndex)\n\t\t.flatMap((part, index) => [\n\t\t\t...(index > 0 ? [anyIndex] : []),\n\t\t\t...symbolPathSegments(part),\n\t\t]);\n\n/** `path` with every index as `[*]`, so a pattern and each of its elements compare equal. */\nexport const patternOf = (path: string) =>\n\tpathSegments(path)\n\t\t.map((segment) => (arrayIndex(segment) === undefined ? segment : anyIndex))\n\t\t.reduce(joinPath, \"\");\n\n/** Scalar type ids are their IEC names, and may have no entry in `types`. */\nexport const typeOf = (\n\tmanifest: Pick<DebugManifest, \"types\">,\n\tid: string,\n): DebugType => manifest.types[id] ?? { kind: \"scalar\", iec: id };\n\n/** What resolving and expanding paths needs from a manifest. */\nexport type PathManifest = Pick<\n\tDebugManifest,\n\t\"roots\" | \"io\" | \"constants\" | \"types\"\n>;\n\nexport const createPaths = (manifest: PathManifest) => {\n\tconst typeOfId = (id: string) => typeOf(manifest, id);\n\tconst constants = new Map(\n\t\tmanifest.constants.map(({ path, ...constant }) => [\n\t\t\tpath,\n\t\t\t{ kind: \"constant\" as const, path, ...constant },\n\t\t]),\n\t);\n\tconst roots = new Map<string, TargetPath>(\n\t\tmanifest.roots.map(({ path, ...root }) => [\n\t\t\tpath,\n\t\t\t{ kind: \"target\", path, ...root },\n\t\t]),\n\t);\n\t/** `path` walked from the longest prefix in `bases` through record fields and array indexes. */\n\tconst walk = (\n\t\tbases: ReadonlyMap<string, TargetPath>,\n\t\tpath: string,\n\t): TargetPath | undefined => {\n\t\tconst segments = pathSegments(path);\n\t\tfor (let length = segments.length; length > 0; length--) {\n\t\t\tconst base = bases.get(segments.slice(0, length).reduce(joinPath, \"\"));\n\t\t\tif (!base) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet resolved = base;\n\t\t\tfor (const segment of segments.slice(length)) {\n\t\t\t\tconst type = typeOfId(resolved.type);\n\t\t\t\tif (type.kind === \"record\") {\n\t\t\t\t\tconst field = type.fields.find(({ name }) => name === segment);\n\t\t\t\t\tif (!field) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tresolved = {\n\t\t\t\t\t\tkind: \"target\",\n\t\t\t\t\t\tpath: joinPath(resolved.path, segment),\n\t\t\t\t\t\ttarget: `${resolved.target}.${field.target}`,\n\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\treadable: resolved.readable,\n\t\t\t\t\t\t...(field.generated && { generated: true }),\n\t\t\t\t\t\t...(field.declaration && { declaration: field.declaration }),\n\t\t\t\t\t};\n\t\t\t\t} else if (type.kind === \"array\") {\n\t\t\t\t\tconst index = arrayIndex(segment);\n\t\t\t\t\tif (\n\t\t\t\t\t\tindex === undefined ||\n\t\t\t\t\t\tindex < type.lower ||\n\t\t\t\t\t\tindex >= type.lower + type.length\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tresolved = {\n\t\t\t\t\t\tkind: \"target\",\n\t\t\t\t\t\tpath: joinPath(resolved.path, segment),\n\t\t\t\t\t\ttarget: `${resolved.target}${segment}`,\n\t\t\t\t\t\ttype: type.element,\n\t\t\t\t\t\treadable: resolved.readable,\n\t\t\t\t\t\t...(resolved.declaration && { declaration: resolved.declaration }),\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn resolved;\n\t\t}\n\t};\n\t// A logical input's or output's path is its root's too, and the root declares it.\n\tconst bases = new Map<string, TargetPath>([\n\t\t...roots,\n\t\t...manifest.io.map(({ path, target, type }): [string, TargetPath] => {\n\t\t\tconst declared = walk(roots, path);\n\t\t\treturn [\n\t\t\t\tpath,\n\t\t\t\t{\n\t\t\t\t\tkind: \"target\",\n\t\t\t\t\tpath,\n\t\t\t\t\ttarget,\n\t\t\t\t\ttype,\n\t\t\t\t\treadable: true,\n\t\t\t\t\t...(declared?.generated && { generated: true }),\n\t\t\t\t\t...(declared?.declaration && { declaration: declared.declaration }),\n\t\t\t\t},\n\t\t\t];\n\t\t}),\n\t]);\n\t/** Children of the prefixes of every root and constant path, which are groups unless they resolve. */\n\tconst groups = new Map<string, Set<string>>();\n\tfor (const path of [...bases.keys(), ...constants.keys()]) {\n\t\tlet prefix = \"\";\n\t\tfor (const segment of pathSegments(path)) {\n\t\t\tlet children = groups.get(prefix);\n\t\t\tif (!children) {\n\t\t\t\tchildren = new Set();\n\t\t\t\tgroups.set(prefix, children);\n\t\t\t}\n\t\t\tchildren.add(segment);\n\t\t\tprefix = joinPath(prefix, segment);\n\t\t}\n\t}\n\n\tconst resolve = (path: string): ResolvedPath | undefined =>\n\t\tconstants.get(path) ?? walk(bases, path);\n\n\tconst typedChildren = (resolved: ResolvedPath | undefined) => {\n\t\tconst type =\n\t\t\tresolved?.kind === \"target\" ? typeOfId(resolved.type) : undefined;\n\t\tif (type?.kind === \"record\") {\n\t\t\treturn type.fields.map(({ name }) => name);\n\t\t}\n\t\tif (type?.kind === \"array\") {\n\t\t\treturn Array.from(\n\t\t\t\t{ length: type.length },\n\t\t\t\t(_, index) => `[${type.lower + index}]`,\n\t\t\t);\n\t\t}\n\t\treturn [];\n\t};\n\n\t/** A path's fields or indexes, and the roots and constants below it. */\n\tconst children = (path: string): PathNode[] => {\n\t\tconst names = [\n\t\t\t...typedChildren(resolve(path)),\n\t\t\t...(groups.get(path) ?? []),\n\t\t];\n\t\treturn [...new Set(names)].map((name) => {\n\t\t\tconst child = joinPath(path, name);\n\t\t\treturn { name, ...(resolve(child) ?? { kind: \"group\", path: child }) };\n\t\t});\n\t};\n\n\tconst isLeaf = (node: ResolvedPath | GroupPath) =>\n\t\tnode.kind === \"constant\" ||\n\t\t(node.kind === \"target\" &&\n\t\t\t[\"scalar\", \"enum\"].includes(typeOfId(node.type).kind));\n\n\t/**\n\t * Leaf paths matching `patterns`, where `*` stands for one segment. A pattern naming a record,\n\t * array or group stands for all its leaves; wildcards and expansion skip compiler-made fields.\n\t * Paths that don't resolve are kept, so callers can report them.\n\t */\n\tconst expand = (patterns: readonly string[], limit = 2000) => {\n\t\tconst leaves = new Set<string>();\n\t\tconst add = (path: string) => {\n\t\t\tleaves.add(path);\n\t\t\tif (leaves.size > limit) {\n\t\t\t\tthrow new TooManyMatches(limit);\n\t\t\t}\n\t\t};\n\t\tconst below = (node: ResolvedPath | GroupPath) => {\n\t\t\tif (isLeaf(node)) {\n\t\t\t\treturn add(node.path);\n\t\t\t}\n\t\t\tfor (const child of children(node.path)) {\n\t\t\t\tif (!(child.kind === \"target\" && child.generated)) {\n\t\t\t\t\tbelow(child);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tconst match = (\n\t\t\tprefix: string,\n\t\t\trest: readonly string[],\n\t\t\twildcard: boolean,\n\t\t) => {\n\t\t\tconst [head, ...tail] = rest;\n\t\t\tif (head === undefined) {\n\t\t\t\tconst node: ResolvedPath | GroupPath | undefined =\n\t\t\t\t\tresolve(prefix) ??\n\t\t\t\t\t(groups.has(prefix) ? { kind: \"group\", path: prefix } : undefined);\n\t\t\t\tif (node) {\n\t\t\t\t\tbelow(node);\n\t\t\t\t} else if (!wildcard) {\n\t\t\t\t\tadd(prefix);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (head === \"*\" || head === anyIndex) {\n\t\t\t\tfor (const child of children(prefix)) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!(child.kind === \"target\" && child.generated) &&\n\t\t\t\t\t\t(head === \"*\" || child.name.startsWith(\"[\"))\n\t\t\t\t\t) {\n\t\t\t\t\t\tmatch(child.path, tail, true);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmatch(joinPath(prefix, head), tail, wildcard);\n\t\t\t}\n\t\t};\n\t\tfor (const pattern of patterns) {\n\t\t\tmatch(\"\", pathSegments(pattern), false);\n\t\t}\n\t\treturn [...leaves];\n\t};\n\n\t/** A value as TypeScript shows it: enum members by name, BOOL as a boolean. */\n\tconst decode = (typeId: string, raw: unknown) => {\n\t\tconst type = typeOfId(typeId);\n\t\tif (type.kind === \"enum\") {\n\t\t\treturn (\n\t\t\t\tObject.entries(type.members).find(([, value]) => value === raw)?.[0] ??\n\t\t\t\traw\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\ttype.kind === \"scalar\" &&\n\t\t\ttype.iec === \"BOOL\" &&\n\t\t\ttypeof raw === \"number\"\n\t\t) {\n\t\t\treturn raw !== 0;\n\t\t}\n\t\treturn raw;\n\t};\n\n\t/**\n\t * The TypeScript path an IEC symbol path names: an I/O binding by its target or address, or a\n\t * storage root's target followed by its fields' targets and indexes. IEC names are\n\t * case-insensitive. Undefined for one that names nothing the manifest knows.\n\t */\n\tconst fromTarget = (expression: string): string | undefined => {\n\t\tconst upper = expression.trim().toUpperCase();\n\t\tconst whole = targets.get(upper);\n\t\tif (whole) {\n\t\t\treturn whole;\n\t\t}\n\t\tconst root = manifest.roots\n\t\t\t.filter((item) => isWithin(item.target, upper))\n\t\t\t.sort((a, b) => b.target.length - a.target.length)[0];\n\t\tif (!root) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet path = root.path;\n\t\tlet type = root.type;\n\t\tfor (const segment of pathSegments(\n\t\t\texpression.trim().slice(root.target.length).replace(/^\\./, \"\"),\n\t\t)) {\n\t\t\tconst declared = typeOfId(type);\n\t\t\tif (segment.startsWith(\"[\")) {\n\t\t\t\tif (declared.kind !== \"array\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tpath = joinPath(path, segment);\n\t\t\t\ttype = declared.element;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst field =\n\t\t\t\tdeclared.kind === \"record\"\n\t\t\t\t\t? declared.fields.find(\n\t\t\t\t\t\t\t(item) => item.target.toUpperCase() === segment.toUpperCase(),\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\tif (!field) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tpath = joinPath(path, field.name);\n\t\t\ttype = field.type;\n\t\t}\n\t\treturn path;\n\t};\n\tconst targets = new Map<string, string>([\n\t\t...manifest.io.flatMap((io) => [\n\t\t\t[io.target.toUpperCase(), io.path] as const,\n\t\t\t...(io.address ? [[io.address.toUpperCase(), io.path] as const] : []),\n\t\t]),\n\t\t...manifest.roots.map(\n\t\t\t(root) => [root.target.toUpperCase(), root.path] as const,\n\t\t),\n\t]);\n\n\treturn {\n\t\ttypeOf: typeOfId,\n\t\tresolve,\n\t\tchildren,\n\t\tisLeaf,\n\t\texpand,\n\t\tdecode,\n\t\tfromTarget,\n\t};\n};\n\nexport type Paths = ReturnType<typeof createPaths>;\n",
|
|
18
|
+
"import type { Quality } from \"@tsplc/opcua/contract\";\nimport type { ExplainCondition, ExplainFile } from \"./explain-file\";\nimport type { Chain, ExplainTables } from \"./explain-tables\";\nimport {\n\tmerge,\n\ttype Outcome,\n\ttype UnknownOutcome,\n\tunknown,\n} from \"./explain-value\";\nimport type { ConditionResult, ConditionsTruth } from \"./explain-verdicts\";\nimport type { DebugManifest } from \"./manifest\";\n\n/** One read: every value an evaluation uses comes from it. */\nexport interface ExplainRead {\n\t/** A stored path's sample, decoded as the debugger decodes it; undefined when this read lacks it. */\n\tsample(path: string): { value: unknown; quality: Quality } | undefined;\n\t/** A manifest job's state; undefined when it isn't known. */\n\tjob(id: number):\n\t\t| {\n\t\t\t\tbusy: boolean | null;\n\t\t\t\tstep?: number;\n\t\t\t\tcancelling?: boolean;\n\t\t\t\tunread?: true;\n\t\t }\n\t\t| undefined;\n\t/** The PLC clock in DINT milliseconds as a task saw it; undefined when this build has no clock to read. */\n\tclock(task: string): { low: bigint; high: bigint } | undefined;\n\t/** The paths the controller forces, or null when the forced state isn't known. */\n\treadonly forced: ReadonlySet<string> | null;\n\t/**\n\t * The path's last-writer slot in this read: the assignments its last writer stands for, or null\n\t * when nothing wrote it since the controller started; undefined when the build has no slot for it.\n\t */\n\tslot(\n\t\tpath: string,\n\t): { assignments: readonly number[] | null; exact: boolean } | undefined;\n}\n\n/** A routine row as one chain of calls runs it. */\nexport interface Frame {\n\treadonly row: number;\n\treadonly caller: { readonly call: number; readonly frame: Frame } | null;\n\treadonly task: string;\n\t/** Scan order: the entry's order, then each call's position down the chain. */\n\treadonly order: readonly number[];\n\t/** Loop counters bound while a loop is executed, by loop index. */\n\treadonly counters: ReadonlyMap<number, bigint>;\n}\n\n/**\n * One explanation's evaluation over one read, which each topic's functions take: its tables and\n * read, what it has spent, and the evaluations that recurse across topics.\n */\nexport interface Evaluation {\n\treadonly manifest: DebugManifest;\n\treadonly file: ExplainFile;\n\treadonly tables: ExplainTables;\n\treadonly read: ExplainRead;\n\t/** Stored paths the evaluation needed and its read didn't have. */\n\treadonly needs: Set<string>;\n\t/** Each expression's outcome by expression and frame. */\n\treadonly memo: Map<string, Outcome>;\n\t/** Expression nodes evaluated so far, and how deep the evaluation is now. */\n\treadonly budget: { spent: number; depth: number };\n\texpression(index: number, frame: Frame): Outcome;\n\tconditionTruth(condition: ExplainCondition, frame: Frame): ConditionResult;\n\tconditionsTruth(entry: number | null, frame: Frame): ConditionsTruth;\n}\n\n/** Which of two scan-order keys runs first in one task: negative when `left` does. */\nexport const compareOrder = (\n\tleft: readonly number[],\n\tright: readonly number[],\n): number => {\n\tfor (let index = 0; index < Math.min(left.length, right.length); index++) {\n\t\tconst difference = (left[index] ?? 0) - (right[index] ?? 0);\n\t\tif (difference !== 0) {\n\t\t\treturn difference;\n\t\t}\n\t}\n\treturn left.length - right.length;\n};\n\nexport const frameKey = (frame: Frame): string =>\n\t`${frame.row}:${frame.caller ? `${frame.caller.call}@${frameKey(frame.caller.frame)}` : \"\"}:${[...frame.counters].join(\",\")}`;\n\n/** The frame `call`, at `position` of `frame`, runs routine row `row` in. */\nconst callFrame = (\n\trow: number,\n\tcall: number,\n\tposition: number,\n\tframe: Frame,\n): Frame => ({\n\trow,\n\tcaller: { call, frame },\n\ttask: frame.task,\n\torder: [...frame.order, position],\n\tcounters: new Map(),\n});\n\n/** The innermost frame of a chain, each call running its first callee. */\nexport const rootFrame = (\n\t{ file, tables }: Pick<Evaluation, \"file\" | \"tables\">,\n\tchain: Chain,\n): Frame => {\n\tconst start: Frame = {\n\t\trow: chain.entry,\n\t\tcaller: null,\n\t\ttask: chain.task,\n\t\torder: [tables.entries.get(chain.entry)?.order ?? 0],\n\t\tcounters: new Map(),\n\t};\n\treturn chain.calls.reduce<Frame>((frame, call) => {\n\t\tconst record = file.calls[call];\n\t\tconst callee = record ? tables.calleesOf(record)[0]?.row : undefined;\n\t\treturn callFrame(callee ?? frame.row, call, record?.position ?? 0, frame);\n\t}, start);\n};\n\n/** The frame a call runs its callee in, when the receiver picks one row. */\nexport const calleeFrame = (\n\tevaluation: Evaluation,\n\tcall: number,\n\tframe: Frame,\n): Frame | UnknownOutcome => {\n\tconst record = evaluation.file.calls[call];\n\tif (!record) {\n\t\treturn unknown(\"a call that isn't traced\");\n\t}\n\tconst callees = evaluation.tables.calleesOf(record);\n\tif (record.receiver.kind === \"pattern\") {\n\t\tconst indexes = record.receiver.indexes.map((item) =>\n\t\t\tevaluation.expression(item, frame),\n\t\t);\n\t\tconst values = indexes.flatMap((item) =>\n\t\t\titem.known && item.value.kind === \"integer\" ? [item.value.value] : [],\n\t\t);\n\t\tif (values.length !== indexes.length) {\n\t\t\treturn unknown(\n\t\t\t\t\"depends on which instance the call runs on\",\n\t\t\t\tmerge(...indexes.map((item) => item.estimate)),\n\t\t\t);\n\t\t}\n\t\tconst match = callees.find((callee) =>\n\t\t\tcallee.indexes.every((value, position) => value === values[position]),\n\t\t);\n\t\treturn match\n\t\t\t? callFrame(match.row, call, record.position, frame)\n\t\t\t: unknown(\"an instance this build doesn't have\");\n\t}\n\tconst [only] = callees;\n\treturn only && callees.length === 1\n\t\t? callFrame(only.row, call, record.position, frame)\n\t\t: unknown(\"a call this debugger can't follow\");\n};\n",
|
|
19
|
+
"import { loopIterations } from \"@tsplc/iec/arithmetic\";\nimport type { Evaluation, Frame } from \"./explain-frames\";\nimport {\n\tand,\n\tmerge,\n\ttype Outcome,\n\ttype Truth,\n\ttype UnknownOutcome,\n\tunknown,\n} from \"./explain-value\";\n\n/** The most iterations a loop is executed to follow it; longer loops are unknown. */\nexport const maxLoopIterations = 64;\n\n/** What a loop's execution checks in each iteration. */\nexport type LoopWatch = (inner: Frame) => {\n\ttruth: Truth;\n\testimate: readonly string[];\n};\n\nexport type LoopRun =\n\t| {\n\t\t\tkind: \"run\";\n\t\t\t/** The last iteration whose watched conditions held. */\n\t\t\tran: Frame | null;\n\t\t\treturned: boolean;\n\t\t\testimate: string[];\n\t }\n\t| { kind: \"unknown\"; reason: string; estimate: string[] };\n\n/** The value a loop's counter starts from, in `frame`. */\nexport const firstOf = (\n\tevaluation: Evaluation,\n\tloop: number,\n\tframe: Frame,\n): Outcome => {\n\tconst record = evaluation.file.loops[loop];\n\treturn record\n\t\t? evaluation.expression(record.first, frame)\n\t\t: unknown(\"a loop this debugger can't follow\");\n};\n\n/**\n * Executes a loop in order: `watch`'s conditions are checked in each iteration. A loop runs\n * until an iteration breaks or returns, or its iteration count; over the cap it is unknown.\n */\nexport const executeLoop = (\n\tevaluation: Evaluation,\n\tloop: number,\n\tframe: Frame,\n\twatch: LoopWatch | null,\n): LoopRun => {\n\tconst { file, tables } = evaluation;\n\tconst record = file.loops[loop];\n\tif (!record) {\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\treason: \"a loop this debugger can't follow\",\n\t\t\testimate: [],\n\t\t};\n\t}\n\tif (record.parent !== null && !frame.counters.has(record.parent)) {\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\treason: \"a loop inside another loop\",\n\t\t\testimate: [],\n\t\t};\n\t}\n\tconst bounds = [record.first, record.limit, record.step].map((index) =>\n\t\tevaluation.expression(index, frame),\n\t);\n\tconst estimate = merge(...bounds.map((item) => item.estimate));\n\tconst missing = bounds.find((item): item is UnknownOutcome => !item.known);\n\tif (missing) {\n\t\treturn { kind: \"unknown\", reason: missing.reason, estimate };\n\t}\n\tconst [first, limit, step] = bounds.map((item) =>\n\t\titem.known && item.value.kind === \"integer\" ? item.value.value : undefined,\n\t);\n\tif (\n\t\tfirst === undefined ||\n\t\tlimit === undefined ||\n\t\tstep === undefined ||\n\t\tstep === 0n\n\t) {\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\treason: \"a loop this debugger can't follow\",\n\t\t\testimate,\n\t\t};\n\t}\n\tconst iterations = loopIterations(first, limit, record.exclusive, step);\n\tif (iterations > BigInt(Math.min(record.maxIterations, maxLoopIterations))) {\n\t\treturn { kind: \"unknown\", reason: \"loop too long\", estimate };\n\t}\n\tconst returns = file.returns.filter(\n\t\t(item) =>\n\t\t\titem.routine === frame.row &&\n\t\t\ttables\n\t\t\t\t.conditionList(item.conditions)\n\t\t\t\t.some(\n\t\t\t\t\t(part) =>\n\t\t\t\t\t\tpart.kind === \"loop\" &&\n\t\t\t\t\t\ttables.loopAt(frame.row, part.loop) === loop,\n\t\t\t\t),\n\t);\n\tlet ran: Frame | null = null;\n\tconst seen = [...estimate];\n\tfor (let iteration = 0n; iteration < iterations; iteration++) {\n\t\tconst inner: Frame = {\n\t\t\t...frame,\n\t\t\tcounters: new Map([...frame.counters, [loop, first + iteration * step]]),\n\t\t};\n\t\tif (watch !== null) {\n\t\t\tconst truth = watch(inner);\n\t\t\tseen.push(...truth.estimate);\n\t\t\tif (truth.truth === \"true\") {\n\t\t\t\tran = inner;\n\t\t\t} else if (truth.truth !== \"false\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"unknown\",\n\t\t\t\t\treason: \"depends on a condition inside the loop\",\n\t\t\t\t\testimate: merge(seen),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tconst breaks = record.breaks.map((all) =>\n\t\t\tand(all.map((part) => evaluation.conditionTruth(part, inner).truth)),\n\t\t);\n\t\tconst returned = returns.map(\n\t\t\t(item) => evaluation.conditionsTruth(item.conditions, inner).truth,\n\t\t);\n\t\tconst stops = [...breaks, ...returned];\n\t\tif (stops.includes(\"true\")) {\n\t\t\treturn {\n\t\t\t\tkind: \"run\",\n\t\t\t\tran,\n\t\t\t\treturned: returned.includes(\"true\"),\n\t\t\t\testimate: merge(seen),\n\t\t\t};\n\t\t}\n\t\tif (stops.includes(\"unknown\") || stops.includes(\"candidate\")) {\n\t\t\treturn {\n\t\t\t\tkind: \"unknown\",\n\t\t\t\treason: \"can't tell whether the loop stopped\",\n\t\t\t\testimate: merge(seen),\n\t\t\t};\n\t\t}\n\t}\n\treturn { kind: \"run\", ran, returned: false, estimate: merge(seen) };\n};\n",
|
|
20
|
+
"import { elementaryType, isIntegerValued } from \"@tsplc/iec\";\nimport {\n\tapplyIntegerPolicy,\n\tcompare,\n\tfloatArithmetic,\n\tfloatUnary,\n\tintegerArithmetic,\n\tintegerUnary,\n\tisElementary,\n\troundFloat,\n\tsaturateFloatToInteger,\n} from \"@tsplc/iec/arithmetic\";\nimport type { ExplainExpression } from \"./explain-file\";\nimport { known, type Outcome, type PlcValue, unknown } from \"./explain-value\";\n\ntype Node<Kind extends ExplainExpression[\"kind\"]> = Extract<\n\tExplainExpression,\n\t{ kind: Kind }\n>;\n\nconst integerLayout = (type: string) => {\n\tconst scalar = elementaryType(type);\n\treturn isIntegerValued(scalar)\n\t\t? { bits: scalar.bits, signed: scalar.signed }\n\t\t: undefined;\n};\nconst floatLayout = (type: string) => {\n\tconst scalar = elementaryType(type);\n\treturn scalar?.family === \"real\" ? { bits: scalar.bits } : undefined;\n};\n\n/** Wraps an integer result to its type, as the emitted `TO_<type>` does. */\nconst typed = (\n\tvalue: bigint,\n\ttype: string,\n\tpolicy: \"wrap\" | \"saturate\" = \"wrap\",\n): PlcValue => {\n\tconst layout = integerLayout(type);\n\treturn {\n\t\tkind: \"integer\",\n\t\tvalue: layout ? applyIntegerPolicy(value, layout, policy) : value,\n\t};\n};\n\nexport const binary = (\n\tnode: Node<\"binary\">,\n\tleft: PlcValue,\n\tright: PlcValue,\n): Outcome => {\n\tif (left.kind === \"interval\" || right.kind === \"interval\") {\n\t\treturn intervalBinary(node, left, right);\n\t}\n\t// A reference compares by the id it holds, as the PLC compares it.\n\tif (left.kind === \"instance\" || right.kind === \"instance\") {\n\t\tconst id = (value: PlcValue): PlcValue =>\n\t\t\tvalue.kind === \"instance\" ? { kind: \"integer\", value: value.id } : value;\n\t\treturn binary(node, id(left), id(right));\n\t}\n\tif (left.kind === \"bool\" && right.kind === \"bool\") {\n\t\tconst compared = compare(\n\t\t\tnode.operator,\n\t\t\tNumber(left.value),\n\t\t\tNumber(right.value),\n\t\t);\n\t\treturn compared === undefined\n\t\t\t? unknown(\"an operation this debugger can't evaluate\")\n\t\t\t: known({ kind: \"bool\", value: compared });\n\t}\n\tif (left.kind === \"integer\" && right.kind === \"integer\") {\n\t\tconst compared = compare(node.operator, left.value, right.value);\n\t\tif (compared !== undefined) {\n\t\t\treturn known({ kind: \"bool\", value: compared });\n\t\t}\n\t\tconst result = integerArithmetic(node.operator, left.value, right.value);\n\t\tif (result === undefined) {\n\t\t\treturn unknown(\n\t\t\t\tright.value === 0n\n\t\t\t\t\t? \"a division by zero\"\n\t\t\t\t\t: \"an operation this debugger can't evaluate\",\n\t\t\t);\n\t\t}\n\t\treturn known(typed(result, node.type, node.policy));\n\t}\n\tconst leftNumber =\n\t\tleft.kind === \"float\" || left.kind === \"integer\"\n\t\t\t? Number(left.value)\n\t\t\t: undefined;\n\tconst rightNumber =\n\t\tright.kind === \"float\" || right.kind === \"integer\"\n\t\t\t? Number(right.value)\n\t\t\t: undefined;\n\tif (leftNumber === undefined || rightNumber === undefined) {\n\t\tif (left.kind === \"text\" && right.kind === \"text\") {\n\t\t\tconst compared = compare(node.operator, left.value, right.value);\n\t\t\treturn compared === undefined\n\t\t\t\t? unknown(\"an operation on text\")\n\t\t\t\t: known({ kind: \"bool\", value: compared });\n\t\t}\n\t\treturn unknown(\"an operation this debugger can't evaluate\");\n\t}\n\tconst compared = compare(node.operator, leftNumber, rightNumber);\n\tif (compared !== undefined) {\n\t\treturn known({ kind: \"bool\", value: compared }, [\n\t\t\t\"a comparison of REAL values\",\n\t\t]);\n\t}\n\tconst result = floatArithmetic(node.operator, leftNumber, rightNumber);\n\tconst layout = floatLayout(node.type);\n\treturn result === undefined\n\t\t? unknown(\"an operation this debugger can't evaluate\")\n\t\t: known({\n\t\t\t\tkind: \"float\",\n\t\t\t\tvalue: layout ? roundFloat(result, layout) : result,\n\t\t\t});\n};\n\n/** An operation on the clock interval: decided only when both ends agree. */\nconst intervalBinary = (\n\tnode: Node<\"binary\">,\n\tleft: PlcValue,\n\tright: PlcValue,\n): Outcome => {\n\tconst ends = (value: PlcValue): [bigint, bigint] | undefined => {\n\t\tif (value.kind === \"interval\") {\n\t\t\treturn [value.low, value.high];\n\t\t}\n\t\treturn value.kind === \"integer\" ? [value.value, value.value] : undefined;\n\t};\n\tconst leftEnds = ends(left);\n\tconst rightEnds = ends(right);\n\tif (!leftEnds || !rightEnds) {\n\t\treturn unknown(\"an operation on the clock\");\n\t}\n\tconst low = binary(\n\t\tnode,\n\t\t{ kind: \"integer\", value: leftEnds[0] },\n\t\t{ kind: \"integer\", value: rightEnds[0] },\n\t);\n\tconst high = binary(\n\t\tnode,\n\t\t{ kind: \"integer\", value: leftEnds[1] },\n\t\t{ kind: \"integer\", value: rightEnds[1] },\n\t);\n\tif (!low.known || !high.known) {\n\t\treturn unknown(\"an operation on the clock\");\n\t}\n\tif (low.value.kind === \"bool\" && high.value.kind === \"bool\") {\n\t\treturn low.value.value === high.value.value\n\t\t\t? known(low.value)\n\t\t\t: unknown(\"within one scan of the limit\");\n\t}\n\tif (low.value.kind === \"integer\" && high.value.kind === \"integer\") {\n\t\t// Only addition and subtraction keep the interval's order, and a wrap inside it splits it.\n\t\tconst monotonic = node.operator === \"add\" || node.operator === \"subtract\";\n\t\tconst [from, to] =\n\t\t\tnode.operator === \"subtract\" && right.kind === \"interval\"\n\t\t\t\t? [high.value.value, low.value.value]\n\t\t\t\t: [low.value.value, high.value.value];\n\t\treturn monotonic && from <= to\n\t\t\t? known({ kind: \"interval\", low: from, high: to })\n\t\t\t: unknown(\"within one scan of the clock\");\n\t}\n\treturn unknown(\"an operation on the clock\");\n};\n\nexport const unary = (node: Node<\"unary\">, operand: PlcValue): Outcome => {\n\tif (node.operator === \"not\" && operand.kind === \"bool\") {\n\t\treturn known({ kind: \"bool\", value: !operand.value });\n\t}\n\tif (operand.kind === \"integer\") {\n\t\tconst result = integerUnary(node.operator, operand.value);\n\t\tif (result !== undefined) {\n\t\t\treturn known(typed(result, node.type));\n\t\t}\n\t}\n\tif (operand.kind === \"float\") {\n\t\tconst result = floatUnary(node.operator, operand.value);\n\t\tif (result === undefined) {\n\t\t\treturn unknown(\"an operation this debugger can't evaluate\");\n\t\t}\n\t\tif (node.operator === \"truncate\") {\n\t\t\treturn known(typed(BigInt(result), node.type));\n\t\t}\n\t\tconst layout = floatLayout(node.type);\n\t\treturn known({\n\t\t\tkind: \"float\",\n\t\t\tvalue:\n\t\t\t\tlayout && isElementary(node.operator)\n\t\t\t\t\t? roundFloat(result, layout)\n\t\t\t\t\t: result,\n\t\t});\n\t}\n\treturn unknown(\"an operation this debugger can't evaluate\");\n};\n\nexport const convert = (node: Node<\"convert\">, operand: PlcValue): Outcome => {\n\tconst integer = integerLayout(node.type);\n\tconst float = floatLayout(node.type);\n\tif (operand.kind === \"integer\" && integer) {\n\t\treturn known({\n\t\t\tkind: \"integer\",\n\t\t\tvalue:\n\t\t\t\tnode.policy === \"exact\"\n\t\t\t\t\t? operand.value\n\t\t\t\t\t: applyIntegerPolicy(operand.value, integer, node.policy),\n\t\t});\n\t}\n\tif (operand.kind === \"integer\" && float) {\n\t\treturn known({\n\t\t\tkind: \"float\",\n\t\t\tvalue: roundFloat(Number(operand.value), float),\n\t\t});\n\t}\n\tif (operand.kind === \"float\" && integer && node.policy === \"saturate\") {\n\t\treturn known({\n\t\t\tkind: \"integer\",\n\t\t\tvalue: saturateFloatToInteger(operand.value, integer),\n\t\t});\n\t}\n\tif (operand.kind === \"float\" && float) {\n\t\treturn known({\n\t\t\tkind: \"float\",\n\t\t\tvalue: roundFloat(operand.value, float),\n\t\t});\n\t}\n\tif (operand.kind === \"interval\" && integer) {\n\t\treturn known(operand);\n\t}\n\treturn node.policy === \"exact\"\n\t\t? known(operand)\n\t\t: unknown(\"a conversion this debugger can't evaluate\");\n};\n",
|
|
21
|
+
"import {\n\tcalleeFrame,\n\tcompareOrder,\n\ttype Evaluation,\n\ttype Frame,\n\tframeKey,\n} from \"./explain-frames\";\nimport { firstOf } from \"./explain-loops\";\nimport { binary, convert, unary } from \"./explain-operations\";\nimport {\n\tconstantAggregate,\n\tequalValues,\n\tknown,\n\tmerge,\n\ttype Outcome,\n\tsampleValue,\n\ttype UnknownOutcome,\n\tunknown,\n\twithEstimate,\n} from \"./explain-value\";\nimport { anyIndex } from \"./paths\";\n\n/** The most expression nodes one explanation evaluates. */\nexport const nodeBudget = 20_000;\n/** The deepest nesting one evaluation follows, well inside the JavaScript stack. */\nexport const maxDepth = 400;\n\n/** A stored path's value in the evaluation's read. */\nexport const sampleOutcome = (\n\t{ manifest, tables, read, needs }: Evaluation,\n\tpath: string,\n\ttype: string,\n): Outcome => {\n\tconst flags = tables.flagsOf(path);\n\tif (flags.constantTable && flags.initial !== null) {\n\t\tconst value = sampleValue(manifest, type, flags.initial);\n\t\treturn value\n\t\t\t? known(value)\n\t\t\t: unknown(\"a constant this debugger can't show\");\n\t}\n\tconst sample = read.sample(path);\n\tif (!sample) {\n\t\tneeds.add(path);\n\t\treturn unknown(\"reading\");\n\t}\n\tif (sample.quality !== \"good\") {\n\t\treturn unknown(`read ${sample.quality}`);\n\t}\n\tconst value = sampleValue(manifest, type, sample.value);\n\treturn value ? known(value) : unknown(\"a value this debugger can't evaluate\");\n};\n\n/** Whether a write of `path` in the frame's task runs after position `at` of the frame. */\nconst writtenAfter = (\n\t{ file, tables }: Evaluation,\n\tpath: string,\n\tframe: Frame,\n\tat: number,\n): boolean => {\n\tconst here = [...frame.order, at];\n\treturn tables.writersOf(path).some((writer) => {\n\t\tconst assignment = file.assignments[writer.assignment];\n\t\treturn (\n\t\t\tassignment !== undefined &&\n\t\t\twriter.chains.some(\n\t\t\t\t(chain) =>\n\t\t\t\t\tchain.task === frame.task &&\n\t\t\t\t\tcompareOrder(tables.writeOrder(chain, assignment.position), here) > 0,\n\t\t\t)\n\t\t);\n\t});\n};\n\n/** A read of stored state at `capturedAt`, with how the sample relates to what the scan saw. */\nconst stored = (\n\tevaluation: Evaluation,\n\tpath: string,\n\ttype: string,\n\tcapturedAt: number,\n\tframe: Frame,\n\tinterleaved: boolean,\n): Outcome => {\n\tconst outcome = sampleOutcome(evaluation, path, type);\n\tconst flags = evaluation.tables.flagsOf(path);\n\tconst estimate = [\n\t\t...(flags.writerTasks.some((task) => task !== frame.task)\n\t\t\t? [\"also written by another task\"]\n\t\t\t: []),\n\t\t...(writtenAfter(evaluation, path, frame, capturedAt)\n\t\t\t? [\"from the previous scan\"]\n\t\t\t: []),\n\t\t...(interleaved && evaluation.tables.writersOf(path).length\n\t\t\t? [\"a call between its read and its use may have changed it\"]\n\t\t\t: []),\n\t];\n\treturn withEstimate(outcome, estimate);\n};\n\nconst project = (outcome: Outcome, path: readonly string[]): Outcome => {\n\tconst [first, ...rest] = path;\n\tif (first === undefined || !outcome.known) {\n\t\treturn outcome;\n\t}\n\tconst { value } = outcome;\n\tif (value.kind === \"record\") {\n\t\tconst field = value.fields[first];\n\t\treturn field\n\t\t\t? project(withEstimate(field, outcome.estimate), rest)\n\t\t\t: unknown(\"a field this value lacks\");\n\t}\n\tif (value.kind === \"array\") {\n\t\tconst item = value.items[Number(first) - value.lower];\n\t\treturn item\n\t\t\t? project(withEstimate(item, outcome.estimate), rest)\n\t\t\t: unknown(\"an element this value lacks\");\n\t}\n\treturn unknown(\"a part of a scalar\");\n};\n\n/** The value of the PLC clock where a frame runs. */\nconst clock = ({ read }: Evaluation, frame: Frame): Outcome => {\n\tconst own = read.clock(frame.task);\n\treturn own\n\t\t? known({ kind: \"interval\", low: own.low, high: own.high })\n\t\t: unknown(\"no PLC clock in this build\");\n};\n\n/** The definitions of a local or written-through parameter before `at`, latest first. */\nconst definitionsBefore = ({ file }: Evaluation, local: number, at: number) =>\n\t(file.locals[local]?.definitions ?? [])\n\t\t.filter((definition) => definition.position < at)\n\t\t.sort((a, b) => b.position - a.position);\n\nconst localValue = (\n\tevaluation: Evaluation,\n\tlocal: number,\n\tpath: readonly string[],\n\tat: number,\n\tframe: Frame,\n): Outcome | undefined => {\n\tconst { file, tables } = evaluation;\n\tfor (const [loop, value] of frame.counters) {\n\t\tif (tables.loopCounterLocal(loop) === local) {\n\t\t\treturn known({ kind: \"integer\", value });\n\t\t}\n\t}\n\t// A definition later in a loop being executed ran in the previous iteration, unless this is the first.\n\tfor (const definition of file.locals[local]?.definitions ?? []) {\n\t\tconst counter =\n\t\t\tdefinition.loop === null\n\t\t\t\t? undefined\n\t\t\t\t: frame.counters.get(definition.loop);\n\t\tif (\n\t\t\tdefinition.position < at ||\n\t\t\tdefinition.loop === null ||\n\t\t\tcounter === undefined\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst first = firstOf(evaluation, definition.loop, frame);\n\t\tif (!first.known) {\n\t\t\treturn unknown(first.reason, first.estimate);\n\t\t}\n\t\tif (first.value.kind !== \"integer\" || counter !== first.value.value) {\n\t\t\treturn unknown(\"changed inside this loop\");\n\t\t}\n\t}\n\tfor (const definition of definitionsBefore(evaluation, local, at)) {\n\t\tconst prefix = definition.path.every((name, index) => path[index] === name);\n\t\tconst part =\n\t\t\t!prefix && path.every((name, index) => definition.path[index] === name);\n\t\tif (!prefix && !part) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst truth = evaluation.conditionsTruth(definition.conditions, frame);\n\t\tif (truth.truth === \"false\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst site = tables.siteText(definition.site);\n\t\tif (truth.truth !== \"true\") {\n\t\t\treturn unknown(`depends on whether ${site} ran`, truth.estimate);\n\t\t}\n\t\tif (part) {\n\t\t\treturn unknown(`partly set by ${site}`, truth.estimate);\n\t\t}\n\t\tif (definition.kind === \"borrowed\") {\n\t\t\treturn unknown(`changed by the call ${site}`, truth.estimate);\n\t\t}\n\t\tif (definition.kind === \"counter\" || definition.value === null) {\n\t\t\treturn unknown(`set by the loop ${site}`, truth.estimate);\n\t\t}\n\t\treturn withEstimate(\n\t\t\tproject(\n\t\t\t\texpression(evaluation, definition.value, frame),\n\t\t\t\tpath.slice(definition.path.length),\n\t\t\t),\n\t\t\ttruth.estimate,\n\t\t);\n\t}\n\treturn undefined;\n};\n\nconst callResult = (\n\tevaluation: Evaluation,\n\tcall: number,\n\tframe: Frame,\n): Outcome => {\n\tconst inner = calleeFrame(evaluation, call, frame);\n\tif (\"known\" in inner) {\n\t\treturn inner;\n\t}\n\tconst returns = evaluation.file.returns\n\t\t.filter((item) => item.routine === inner.row)\n\t\t.sort((a, b) => a.position - b.position);\n\tfor (const returned of returns) {\n\t\tconst truth = evaluation.conditionsTruth(returned.conditions, inner);\n\t\tif (truth.truth === \"false\") {\n\t\t\tcontinue;\n\t\t}\n\t\tif (truth.truth !== \"true\" || returned.value === null) {\n\t\t\treturn unknown(\n\t\t\t\t`depends on whether ${evaluation.tables.siteText(returned.site)} returned`,\n\t\t\t\ttruth.estimate,\n\t\t\t);\n\t\t}\n\t\treturn withEstimate(\n\t\t\texpression(evaluation, returned.value, inner),\n\t\t\ttruth.estimate,\n\t\t);\n\t}\n\treturn unknown(\"returns nothing this debugger can follow\");\n};\n\n/** The value of an expression of `explain.json` in a frame, once per evaluation and within its budget. */\nexport const expression = (\n\tevaluation: Evaluation,\n\tindex: number,\n\tframe: Frame,\n): Outcome => {\n\tconst { memo, budget } = evaluation;\n\tconst key = `${index}|${frameKey(frame)}`;\n\tconst cached = memo.get(key);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\tbudget.spent += 1;\n\tif (budget.spent > nodeBudget || budget.depth >= maxDepth) {\n\t\treturn unknown(\"too deep\");\n\t}\n\tbudget.depth += 1;\n\ttry {\n\t\tconst outcome = evaluate(evaluation, index, frame);\n\t\tmemo.set(key, outcome);\n\t\treturn outcome;\n\t} finally {\n\t\tbudget.depth -= 1;\n\t}\n};\n\nconst evaluate = (\n\tevaluation: Evaluation,\n\tindex: number,\n\tframe: Frame,\n): Outcome => {\n\tconst { manifest, file, tables } = evaluation;\n\tconst node = file.expressions[index];\n\tif (!node) {\n\t\treturn unknown(\"not traced\");\n\t}\n\tswitch (node.kind) {\n\t\tcase \"read\": {\n\t\t\tconst path = tables.pathAt(frame.row, node.path);\n\t\t\tconst bound = [...frame.counters].find(\n\t\t\t\t([loop]) => tables.loopCounterPath(loop) === path,\n\t\t\t)?.[1];\n\t\t\treturn bound === undefined\n\t\t\t\t? stored(\n\t\t\t\t\t\tevaluation,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tnode.type,\n\t\t\t\t\t\tnode.capturedAt,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t\tnode.interleaved === true,\n\t\t\t\t\t)\n\t\t\t\t: known({ kind: \"integer\", value: bound });\n\t\t}\n\t\tcase \"pattern\": {\n\t\t\tconst indexes = node.indexes.map((item) =>\n\t\t\t\texpression(evaluation, item, frame),\n\t\t\t);\n\t\t\tconst estimate = merge(...indexes.map((item) => item.estimate));\n\t\t\tconst missing = indexes.find(\n\t\t\t\t(item): item is UnknownOutcome => !item.known,\n\t\t\t);\n\t\t\tif (missing) {\n\t\t\t\treturn unknown(missing.reason, estimate);\n\t\t\t}\n\t\t\tconst values = indexes.flatMap((item) =>\n\t\t\t\titem.known && item.value.kind === \"integer\" ? [item.value.value] : [],\n\t\t\t);\n\t\t\tif (values.length !== indexes.length) {\n\t\t\t\treturn unknown(\"an index this debugger can't evaluate\", estimate);\n\t\t\t}\n\t\t\tconst path = tables\n\t\t\t\t.pathAt(frame.row, node.path)\n\t\t\t\t.split(anyIndex)\n\t\t\t\t.reduce(\n\t\t\t\t\t(built, part, position) =>\n\t\t\t\t\t\t`${built}${position ? `[${values[position - 1]}]` : \"\"}${part}`,\n\t\t\t\t\t\"\",\n\t\t\t\t);\n\t\t\treturn withEstimate(\n\t\t\t\tstored(\n\t\t\t\t\tevaluation,\n\t\t\t\t\tpath,\n\t\t\t\t\tnode.type,\n\t\t\t\t\tnode.capturedAt,\n\t\t\t\t\tframe,\n\t\t\t\t\tnode.interleaved === true,\n\t\t\t\t),\n\t\t\t\testimate,\n\t\t\t);\n\t\t}\n\t\tcase \"constant\": {\n\t\t\tconst value = sampleValue(manifest, node.type, node.value);\n\t\t\treturn value ? known(value) : constantAggregate(node.value);\n\t\t}\n\t\tcase \"record\":\n\t\t\treturn known({\n\t\t\t\tkind: \"record\",\n\t\t\t\tfields: Object.fromEntries(\n\t\t\t\t\tObject.entries(node.fields).map(([name, field]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\texpression(evaluation, field, frame),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t});\n\t\tcase \"array\":\n\t\t\treturn known({\n\t\t\t\tkind: \"array\",\n\t\t\t\tlower: node.lower,\n\t\t\t\titems: node.items.map((item) => expression(evaluation, item, frame)),\n\t\t\t});\n\t\tcase \"local\":\n\t\t\treturn (\n\t\t\t\tlocalValue(\n\t\t\t\t\tevaluation,\n\t\t\t\t\ttables.localAt(frame.row, node.local),\n\t\t\t\t\tnode.path,\n\t\t\t\t\tnode.at,\n\t\t\t\t\tframe,\n\t\t\t\t) ?? unknown(\"no value before this point\")\n\t\t\t);\n\t\tcase \"parameter\": {\n\t\t\tconst own =\n\t\t\t\tnode.local === null\n\t\t\t\t\t? undefined\n\t\t\t\t\t: localValue(\n\t\t\t\t\t\t\tevaluation,\n\t\t\t\t\t\t\ttables.localAt(frame.row, node.local),\n\t\t\t\t\t\t\tnode.path,\n\t\t\t\t\t\t\tnode.at,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t);\n\t\t\tif (own) {\n\t\t\t\treturn own;\n\t\t\t}\n\t\t\tconst caller = frame.caller;\n\t\t\tconst call = caller ? file.calls[caller.call] : undefined;\n\t\t\tconst argument = call?.arguments[node.parameter];\n\t\t\tif (!caller || argument === undefined) {\n\t\t\t\treturn unknown(\"depends on the call\");\n\t\t\t}\n\t\t\treturn project(expression(evaluation, argument, caller.frame), node.path);\n\t\t}\n\t\tcase \"call\":\n\t\t\treturn project(\n\t\t\t\tcallResult(evaluation, tables.callAt(frame.row, node.call), frame),\n\t\t\t\tnode.path,\n\t\t\t);\n\t\tcase \"clock\":\n\t\t\treturn clock(evaluation, frame);\n\t\tcase \"reference\": {\n\t\t\tconst operand = expression(evaluation, node.operand, frame);\n\t\t\tif (!operand.known) {\n\t\t\t\treturn operand;\n\t\t\t}\n\t\t\tif (operand.value.kind !== \"integer\") {\n\t\t\t\treturn unknown(\n\t\t\t\t\t\"a reference this debugger can't follow\",\n\t\t\t\t\toperand.estimate,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst id = operand.value.value;\n\t\t\tconst path =\n\t\t\t\tid < 0n ? null : file.paths[file.references[String(id)] ?? -1];\n\t\t\treturn known(\n\t\t\t\t{ kind: \"instance\", id, path: path ?? null },\n\t\t\t\toperand.estimate,\n\t\t\t);\n\t\t}\n\t\tcase \"unary\": {\n\t\t\tconst operand = expression(evaluation, node.operand, frame);\n\t\t\treturn operand.known\n\t\t\t\t? withEstimate(unary(node, operand.value), operand.estimate)\n\t\t\t\t: operand;\n\t\t}\n\t\tcase \"convert\": {\n\t\t\tconst operand = expression(evaluation, node.operand, frame);\n\t\t\treturn operand.known\n\t\t\t\t? withEstimate(convert(node, operand.value), operand.estimate)\n\t\t\t\t: operand;\n\t\t}\n\t\tcase \"binary\": {\n\t\t\tconst left = expression(evaluation, node.left, frame);\n\t\t\tconst right = expression(evaluation, node.right, frame);\n\t\t\tconst estimate = merge(left.estimate, right.estimate);\n\t\t\tif (!left.known) {\n\t\t\t\treturn withEstimate(left, right.estimate);\n\t\t\t}\n\t\t\tif (!right.known) {\n\t\t\t\treturn withEstimate(right, left.estimate);\n\t\t\t}\n\t\t\treturn withEstimate(binary(node, left.value, right.value), estimate);\n\t\t}\n\t\tcase \"logical\": {\n\t\t\tconst left = expression(evaluation, node.left, frame);\n\t\t\tconst decided = node.operator === \"or\";\n\t\t\tif (\n\t\t\t\tleft.known &&\n\t\t\t\tleft.value.kind === \"bool\" &&\n\t\t\t\tleft.value.value === decided\n\t\t\t) {\n\t\t\t\treturn left;\n\t\t\t}\n\t\t\tconst right = expression(evaluation, node.right, frame);\n\t\t\tif (\n\t\t\t\tright.known &&\n\t\t\t\tright.value.kind === \"bool\" &&\n\t\t\t\tright.value.value === decided\n\t\t\t) {\n\t\t\t\t// Kleene: `? && false` and `? || true` decide without the other operand.\n\t\t\t\treturn withEstimate(right, left.estimate);\n\t\t\t}\n\t\t\tif (!left.known) {\n\t\t\t\treturn withEstimate(left, right.estimate);\n\t\t\t}\n\t\t\treturn withEstimate(right, left.estimate);\n\t\t}\n\t\tcase \"select\": {\n\t\t\tconst condition = expression(evaluation, node.condition, frame);\n\t\t\tif (condition.known && condition.value.kind === \"bool\") {\n\t\t\t\treturn withEstimate(\n\t\t\t\t\texpression(\n\t\t\t\t\t\tevaluation,\n\t\t\t\t\t\tcondition.value.value ? node.then : node.else,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t),\n\t\t\t\t\tcondition.estimate,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst then = expression(evaluation, node.then, frame);\n\t\t\tconst otherwise = expression(evaluation, node.else, frame);\n\t\t\tif (\n\t\t\t\tthen.known &&\n\t\t\t\totherwise.known &&\n\t\t\t\tequalValues(then.value, otherwise.value)\n\t\t\t) {\n\t\t\t\treturn withEstimate(\n\t\t\t\t\tthen,\n\t\t\t\t\tmerge(condition.estimate, otherwise.estimate),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn unknown(\n\t\t\t\tcondition.known\n\t\t\t\t\t? \"a condition this debugger can't evaluate\"\n\t\t\t\t\t: condition.reason,\n\t\t\t\tcondition.estimate,\n\t\t\t);\n\t\t}\n\t\tcase \"opaque\":\n\t\t\treturn unknown(`not traced: ${tables.text(node.text) ?? \"\"}`);\n\t}\n};\n",
|
|
22
|
+
"import { arrayIndex, joinPath } from \"@tsplc/opcua/contract\";\nimport type {\n\tExplainAssignment,\n\tExplainCall,\n\tExplainCondition,\n\tExplainFile,\n\tExplainFlags,\n} from \"./explain-file\";\nimport { merge } from \"./explain-value\";\nimport type { DebugIo, DebugManifest } from \"./manifest\";\nimport { anyIndex, pathSegments } from \"./paths\";\n\n/** The most chains followed from the task to each writer. */\nconst maxChains = 16;\n\n/** A path through calls from a task's entry to a writer's routine instance. */\nexport interface Chain {\n\treadonly task: string;\n\t/** The entry routine row. */\n\treadonly entry: number;\n\t/** Call indexes, outermost first. */\n\treadonly calls: readonly number[];\n}\n\nexport interface Writer {\n\treadonly assignment: number;\n\t/** The indexes of the explained path the writer's `[*]`s must take. */\n\treadonly indexes: readonly bigint[];\n\treadonly chains: readonly Chain[];\n}\n\nexport interface Explanation {\n\treadonly path: string;\n\treadonly writers: readonly Writer[];\n\treadonly flags: Omit<ExplainFlags, \"path\">;\n\treadonly io: DebugIo | null;\n}\n\n/**\n * Whether a concrete path starts with a match of a pattern's segments, the index each `[*]` takes,\n * and whether the path ends where the pattern does.\n */\nconst matchPattern = (pattern: readonly string[], path: string) => {\n\tconst segments = pathSegments(path);\n\tconst indexes: bigint[] = [];\n\tfor (const [position, part] of pattern.entries()) {\n\t\tconst segment = segments[position];\n\t\tif (segment === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (part === anyIndex) {\n\t\t\tconst index = arrayIndex(segment);\n\t\t\tif (index === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tindexes.push(BigInt(index));\n\t\t} else if (part !== segment) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn { indexes, exact: segments.length === pattern.length };\n};\n\n/**\n * What `explain.json` says, by what an evaluation looks up: the writers of a path and the chains\n * of calls that reach them, the flags of a path, and what each routine row's slots name.\n */\nexport const createExplainTables = (\n\tmanifest: DebugManifest,\n\tfile: ExplainFile,\n) => {\n\tconst text = (index: number | null): string | null =>\n\t\tindex === null ? null : (file.texts[index] ?? null);\n\t/** A statement's source text and where it is, for reasons. */\n\tconst siteText = (site: number | null): string => {\n\t\tconst found = site === null ? undefined : file.sites[site];\n\t\tconst source = found ? text(found.text) : null;\n\t\tconst sourceFile = found ? manifest.sources[found.range.file] : undefined;\n\t\tconst where =\n\t\t\tfound && sourceFile\n\t\t\t\t? `${sourceFile.split(\"/\").at(-1)}:${found.range.line}`\n\t\t\t\t: \"\";\n\t\treturn [source, where && `at ${where}`].filter(Boolean).join(\" \");\n\t};\n\n\tconst byPath = new Map<string, number[]>();\n\tconst patterns: {\n\t\tassignment: number;\n\t\tsegments: string[];\n\t\twhole: boolean;\n\t}[] = [];\n\tfile.assignments.forEach((assignment, index) => {\n\t\tconst written = file.paths[assignment.writes.path] ?? \"\";\n\t\tif (assignment.writes.kind === \"pattern\") {\n\t\t\tpatterns.push({\n\t\t\t\tassignment: index,\n\t\t\t\tsegments: pathSegments(written),\n\t\t\t\twhole: assignment.whole,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tbyPath.set(written, [...(byPath.get(written) ?? []), index]);\n\t});\n\tconst flagsByPath = new Map(\n\t\tfile.flags.map((item) => [file.paths[item.path] ?? \"\", item]),\n\t);\n\tconst rowsByKey = new Map<string, number[]>();\n\tfile.routines.forEach((row, index) => {\n\t\trowsByKey.set(row.key, [...(rowsByKey.get(row.key) ?? []), index]);\n\t});\n\t// Expressions and conditions name paths, locals, calls and loops by slot in their routine row.\n\tconst slots = (row: number) => file.routines[row];\n\tconst pathAt = (row: number, slot: number): string =>\n\t\tfile.paths[slots(row)?.paths[slot] ?? -1] ?? \"\";\n\tconst localAt = (row: number, slot: number): number =>\n\t\tslots(row)?.locals[slot] ?? -1;\n\tconst callAt = (row: number, slot: number): number =>\n\t\tslots(row)?.calls[slot] ?? -1;\n\tconst loopAt = (row: number, slot: number): number =>\n\t\tslots(row)?.loops[slot] ?? -1;\n\tconst loopSlot = (row: number, loop: number): number =>\n\t\tslots(row)?.loops.indexOf(loop) ?? -1;\n\tconst instanceOf = (row: number): string | null => {\n\t\tconst instance = file.routines[row]?.instance;\n\t\treturn instance === null || instance === undefined\n\t\t\t? null\n\t\t\t: (file.paths[instance] ?? null);\n\t};\n\n\t/** The routine rows a call can run, and the receiver indexes each needs. */\n\tconst calleesOf = (\n\t\tcall: ExplainCall,\n\t): { row: number; indexes: readonly bigint[] }[] => {\n\t\tconst rows = rowsByKey.get(call.callee) ?? [];\n\t\tconst { receiver } = call;\n\t\tif (receiver.kind === \"none\") {\n\t\t\treturn rows\n\t\t\t\t.filter((row) => instanceOf(row) === null)\n\t\t\t\t.map((row) => ({ row, indexes: [] }));\n\t\t}\n\t\tconst target = file.paths[receiver.path] ?? \"\";\n\t\tif (receiver.kind === \"path\") {\n\t\t\treturn rows\n\t\t\t\t.filter((row) => instanceOf(row) === target)\n\t\t\t\t.map((row) => ({ row, indexes: [] }));\n\t\t}\n\t\tconst pattern = pathSegments(target);\n\t\treturn rows.flatMap((row) => {\n\t\t\tconst match = matchPattern(pattern, instanceOf(row) ?? \"\");\n\t\t\treturn match?.exact ? [{ row, indexes: match.indexes }] : [];\n\t\t});\n\t};\n\tconst callers = new Map<number, number[]>();\n\tfile.calls.forEach((call, index) => {\n\t\tfor (const { row } of calleesOf(call)) {\n\t\t\tcallers.set(row, [...(callers.get(row) ?? []), index]);\n\t\t}\n\t});\n\tconst entries = new Map(file.entries.map((entry) => [entry.routine, entry]));\n\n\t/** Chains from task entries to a row, outermost call first. */\n\tconst chainsTo = (row: number): Chain[] => {\n\t\tconst found: Chain[] = [];\n\t\tconst walk = (\n\t\t\tcurrent: number,\n\t\t\tbelow: readonly number[],\n\t\t\tseen: ReadonlySet<number>,\n\t\t) => {\n\t\t\tif (found.length >= maxChains) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst entry = entries.get(current);\n\t\t\tif (entry) {\n\t\t\t\tfound.push({ task: entry.task, entry: current, calls: below });\n\t\t\t}\n\t\t\tfor (const call of callers.get(current) ?? []) {\n\t\t\t\tconst caller = file.calls[call]?.routine;\n\t\t\t\tif (caller !== undefined && !seen.has(caller)) {\n\t\t\t\t\twalk(caller, [call, ...below], new Set([...seen, caller]));\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\twalk(row, [], new Set([row]));\n\t\treturn found;\n\t};\n\tconst chainCache = new Map<number, Chain[]>();\n\tconst chains = (row: number): Chain[] => {\n\t\tconst cached = chainCache.get(row);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\t\tconst computed = chainsTo(row);\n\t\tchainCache.set(row, computed);\n\t\treturn computed;\n\t};\n\n\t/**\n\t * The chains that reach a writer. A write through a by-reference parameter reaches the path only\n\t * through the calls that pass it, so its chains run to the outermost of them and end with them.\n\t */\n\tconst writerChains = (assignment: ExplainAssignment): Chain[] => {\n\t\tconst outermost = assignment.via.at(-1);\n\t\tif (outermost === undefined) {\n\t\t\treturn chains(assignment.routine);\n\t\t}\n\t\tconst passing = [...assignment.via].reverse();\n\t\treturn chains(file.calls[outermost]?.routine ?? -1).map((chain) => ({\n\t\t\t...chain,\n\t\t\tcalls: [...chain.calls, ...passing],\n\t\t}));\n\t};\n\n\t/** The flags of a path: those stored at it and at every prefix. */\n\tconst flagsOf = (path: string): Omit<ExplainFlags, \"path\"> => {\n\t\tconst merged: Omit<ExplainFlags, \"path\"> = {\n\t\t\tinput: null,\n\t\t\tclientWritable: false,\n\t\t\thmiControl: null,\n\t\t\tretained: false,\n\t\t\tconstantTable: false,\n\t\t\twriterTasks: [],\n\t\t\tservice: null,\n\t\t\tinitial: null,\n\t\t\treference: false,\n\t\t};\n\t\tlet prefix = \"\";\n\t\tfor (const segment of pathSegments(path)) {\n\t\t\tprefix = joinPath(prefix, segment);\n\t\t\tconst item = flagsByPath.get(prefix);\n\t\t\tif (!item) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmerged.input ??= item.input;\n\t\t\tmerged.clientWritable ||= item.clientWritable;\n\t\t\tmerged.hmiControl ??= item.hmiControl;\n\t\t\tmerged.retained ||= item.retained;\n\t\t\tmerged.constantTable ||= item.constantTable;\n\t\t\tmerged.writerTasks = merge(merged.writerTasks, item.writerTasks);\n\t\t\tmerged.service ??= item.service;\n\t\t\tmerged.reference ||= item.reference;\n\t\t\tif (prefix === path) {\n\t\t\t\tmerged.initial = item.initial;\n\t\t\t}\n\t\t}\n\t\treturn merged;\n\t};\n\n\t/** Writers of `path` itself, of a record or array above it written whole, or of a pattern matching it. */\n\tconst writersOf = (path: string): Writer[] => {\n\t\tconst found: { assignment: number; indexes: bigint[] }[] = [];\n\t\tconst segments = pathSegments(path);\n\t\tlet prefix = \"\";\n\t\tfor (const [position, segment] of segments.entries()) {\n\t\t\tprefix = joinPath(prefix, segment);\n\t\t\tconst last = position === segments.length - 1;\n\t\t\tfor (const assignment of byPath.get(prefix) ?? []) {\n\t\t\t\tif (last || file.assignments[assignment]?.whole) {\n\t\t\t\t\tfound.push({ assignment, indexes: [] });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const pattern of patterns) {\n\t\t\tconst match = matchPattern(pattern.segments, path);\n\t\t\tif (match && (match.exact || pattern.whole)) {\n\t\t\t\tfound.push({ assignment: pattern.assignment, indexes: match.indexes });\n\t\t\t}\n\t\t}\n\t\treturn found.map((item) => {\n\t\t\tconst assignment = file.assignments[item.assignment];\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tchains: assignment ? writerChains(assignment) : [],\n\t\t\t};\n\t\t});\n\t};\n\n\t/** The scan order of a write through `chain`: the entry's order, then each call's and its own position. */\n\tconst writeOrder = (chain: Chain, position: number): number[] => [\n\t\tentries.get(chain.entry)?.order ?? 0,\n\t\t...chain.calls.map((call) => file.calls[call]?.position ?? 0),\n\t\tposition,\n\t];\n\n\t/** The conditions of a tree entry and its parents, outermost first. */\n\tconst conditionList = (entry: number | null): ExplainCondition[] => {\n\t\tconst list: ExplainCondition[] = [];\n\t\tfor (\n\t\t\tlet current = entry;\n\t\t\tcurrent !== null;\n\t\t\tcurrent = file.conditions[current]?.parent ?? null\n\t\t) {\n\t\t\tconst item = file.conditions[current];\n\t\t\tif (item) {\n\t\t\t\tlist.unshift(item.condition);\n\t\t\t}\n\t\t}\n\t\treturn list;\n\t};\n\n\t/** A loop's counter: the local it is, or the stored path. */\n\tconst counterNode = (loop: number) => {\n\t\tconst record = file.loops[loop];\n\t\tconst node = record ? file.expressions[record.counter] : undefined;\n\t\treturn record && node && { routine: record.routine, node };\n\t};\n\tconst loopCounterLocal = (loop: number): number | undefined => {\n\t\tconst counter = counterNode(loop);\n\t\treturn counter?.node.kind === \"local\"\n\t\t\t? localAt(counter.routine, counter.node.local)\n\t\t\t: undefined;\n\t};\n\tconst loopCounterPath = (loop: number): string | undefined => {\n\t\tconst counter = counterNode(loop);\n\t\treturn counter?.node.kind === \"read\"\n\t\t\t? pathAt(counter.routine, counter.node.path)\n\t\t\t: undefined;\n\t};\n\n\treturn {\n\t\ttext,\n\t\tsiteText,\n\t\tslots,\n\t\tpathAt,\n\t\tlocalAt,\n\t\tcallAt,\n\t\tloopAt,\n\t\tloopSlot,\n\t\tcalleesOf,\n\t\tentries,\n\t\tflagsOf,\n\t\twritersOf,\n\t\twriteOrder,\n\t\tconditionList,\n\t\tloopCounterLocal,\n\t\tloopCounterPath,\n\t\texplain: (path: string): Explanation => ({\n\t\t\tpath,\n\t\t\twriters: writersOf(path),\n\t\t\tflags: flagsOf(path),\n\t\t\tio: manifest.io.find((item) => item.path === path) ?? null,\n\t\t}),\n\t};\n};\n\nexport type ExplainTables = ReturnType<typeof createExplainTables>;\n",
|
|
23
|
+
"import { sampleOutcome } from \"./explain-expressions\";\nimport type { ExplainCondition } from \"./explain-file\";\nimport {\n\tcalleeFrame,\n\tcompareOrder,\n\ttype Evaluation,\n\ttype Frame,\n\trootFrame,\n} from \"./explain-frames\";\nimport { executeLoop, type LoopRun } from \"./explain-loops\";\nimport type { Chain, Explanation, Writer } from \"./explain-tables\";\nimport {\n\tand,\n\tconstantAggregate,\n\tequalValues,\n\tmerge,\n\ttype Outcome,\n\tsampleValue,\n\ttype Truth,\n} from \"./explain-value\";\nimport type { DebugIo } from \"./manifest\";\n\n/** A condition with its truth, for the page to show. */\nexport interface ConditionResult {\n\treadonly condition: ExplainCondition;\n\t/** The routine row it was evaluated in, whose slots its expressions name. */\n\treadonly row: number;\n\treadonly truth: Truth;\n\treadonly reasons: readonly string[];\n\treadonly estimate: readonly string[];\n}\n\n/** The conditions a statement runs under, each with its truth, and the truth of them all. */\nexport interface ConditionsTruth {\n\ttruth: Truth;\n\tresults: ConditionResult[];\n\testimate: string[];\n}\n\nexport interface Verdict {\n\treadonly writer: Writer;\n\treadonly chain: Chain;\n\treadonly state: \"runs\" | \"blocked\" | \"unknown\" | \"candidate\";\n\t/** Why it is unknown or a candidate, or what blocks it. */\n\treadonly reasons: readonly string[];\n\treadonly estimate: readonly string[];\n\t/** The writer's own conditions and each call's on the chain, outermost first. */\n\treadonly conditions: readonly ConditionResult[];\n\t/** The value it writes, when it runs. */\n\treadonly value: Outcome | null;\n}\n\nexport type Answer =\n\t| { kind: \"forced\"; value: Outcome }\n\t/** The last-writer slot names it: the verdict of that writer, or null when nothing wrote it since the controller started. */\n\t| { kind: \"exact\"; writer: Verdict | null }\n\t| { kind: \"input\"; io: DebugIo; value: Outcome }\n\t| {\n\t\t\tkind: \"set\";\n\t\t\twriter: Verdict;\n\t\t\t/** Later writers that may have run instead. */\n\t\t\tunless: readonly Verdict[];\n\t\t\testimate: readonly string[];\n\t }\n\t| {\n\t\t\tkind: \"held\";\n\t\t\t/** The writers that could have produced the current value. */\n\t\t\twriters: readonly Verdict[];\n\t\t\testimate: readonly string[];\n\t }\n\t| { kind: \"changed\"; writers: readonly Verdict[] }\n\t| {\n\t\t\tkind: \"unknown\";\n\t\t\twriters: readonly Verdict[];\n\t\t\treasons: readonly string[];\n\t };\n\nexport interface AnswerResult {\n\treadonly answer: Answer;\n\treadonly verdicts: readonly Verdict[];\n\t/** Clients may write the path. */\n\treadonly clientWritable: boolean;\n\t/** The HMI control that writes the path. */\n\treadonly hmiControl: string | null;\n\t/** The path is kept across restarts. */\n\treadonly retained: boolean;\n\t/** Tasks besides the one that reads the path also write it. */\n\treadonly writerTasks: readonly string[];\n\t/** Stored paths the evaluation needed and this read didn't have. */\n\treadonly needs: readonly string[];\n\t/** The writers a last-writer slot that isn't exact recorded, as a hint. */\n\treadonly hint: readonly Verdict[];\n}\n\ntype Result = (\n\ttruth: Truth,\n\treasons?: readonly string[],\n\testimate?: readonly string[],\n) => ConditionResult;\n\n/** A job step condition: true while the job waits at it, else a candidate of this scan or earlier. */\nconst jobTruth = (\n\t{ manifest, read }: Evaluation,\n\tjob: number,\n\tstep: number,\n\tresult: Result,\n): ConditionResult => {\n\tconst state = read.job(job);\n\tconst declared = manifest.jobs.find((item) => item.id === job);\n\tconst steps = declared?.steps ?? [];\n\tconst stepText =\n\t\tsteps.find((item) => item.step === step)?.text ?? `step ${step}`;\n\tif (!state || state.busy === null) {\n\t\treturn result(\"unknown\", [\"the job's state isn't known\"]);\n\t}\n\tif (state.unread) {\n\t\treturn result(\"unknown\", [\"over the jobs read per poll\"]);\n\t}\n\tconst current = steps.find((item) => item.step === state.step);\n\tconst cancelling = state.cancelling ? [\"the job is being cancelled\"] : [];\n\tif (state.busy && state.step === step && current?.kind === \"await\") {\n\t\treturn result(\n\t\t\t\"true\",\n\t\t\t[`waiting at ${stepText}`],\n\t\t\t[\"a job's step can change between scans\", ...cancelling],\n\t\t);\n\t}\n\treturn result(\n\t\t\"candidate\",\n\t\t[\n\t\t\t`ran when job ${declared?.name ?? `job ${job}`} passed ${stepText}, this scan or earlier`,\n\t\t],\n\t\tcancelling,\n\t);\n};\n\nexport const conditionTruth = (\n\tevaluation: Evaluation,\n\tcondition: ExplainCondition,\n\tframe: Frame,\n): ConditionResult => {\n\tconst { tables, read } = evaluation;\n\tconst result: Result = (truth, reasons = [], estimate = []) => ({\n\t\tcondition,\n\t\trow: frame.row,\n\t\ttruth,\n\t\treasons,\n\t\testimate,\n\t});\n\tswitch (condition.kind) {\n\t\tcase \"test\": {\n\t\t\tconst outcome = evaluation.expression(condition.test, frame);\n\t\t\tif (!outcome.known) {\n\t\t\t\treturn result(\"unknown\", [outcome.reason], outcome.estimate);\n\t\t\t}\n\t\t\tif (outcome.value.kind !== \"bool\") {\n\t\t\t\treturn result(\n\t\t\t\t\t\"unknown\",\n\t\t\t\t\t[\"a condition this debugger can't evaluate\"],\n\t\t\t\t\toutcome.estimate,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn result(\n\t\t\t\toutcome.value.value === condition.holds ? \"true\" : \"false\",\n\t\t\t\t[],\n\t\t\t\toutcome.estimate,\n\t\t\t);\n\t\t}\n\t\tcase \"cases\": {\n\t\t\tconst outcome = evaluation.expression(condition.test, frame);\n\t\t\tif (!outcome.known) {\n\t\t\t\treturn result(\"unknown\", [outcome.reason], outcome.estimate);\n\t\t\t}\n\t\t\tconst member = condition.values.some((value) => {\n\t\t\t\tconst constant = constantAggregate(value);\n\t\t\t\treturn (\n\t\t\t\t\tconstant.known && equalValues(constant.value, outcome.value) === true\n\t\t\t\t);\n\t\t\t});\n\t\t\treturn result(\n\t\t\t\tmember === condition.member ? \"true\" : \"false\",\n\t\t\t\t[],\n\t\t\t\toutcome.estimate,\n\t\t\t);\n\t\t}\n\t\tcase \"exits\": {\n\t\t\tconst parts = condition.any.map((all) =>\n\t\t\t\tall.map((part) => conditionTruth(evaluation, part, frame)),\n\t\t\t);\n\t\t\tconst any = parts.map((all) => and(all.map((part) => part.truth)));\n\t\t\tconst estimate = merge(...parts.flat().map((part) => part.estimate));\n\t\t\tif (any.includes(\"true\")) {\n\t\t\t\treturn result(\"false\", [], estimate);\n\t\t\t}\n\t\t\tif (any.includes(\"unknown\") || any.includes(\"candidate\")) {\n\t\t\t\treturn result(\n\t\t\t\t\t\"unknown\",\n\t\t\t\t\t[\"depends on whether an earlier statement left\"],\n\t\t\t\t\testimate,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn result(\"true\", [], estimate);\n\t\t}\n\t\tcase \"loop\":\n\t\t\treturn frame.counters.has(tables.loopAt(frame.row, condition.loop))\n\t\t\t\t? result(\"true\")\n\t\t\t\t: result(\"unknown\", [\"inside a loop\"]);\n\t\tcase \"loopReturns\": {\n\t\t\tconst run = executeLoop(\n\t\t\t\tevaluation,\n\t\t\t\ttables.loopAt(frame.row, condition.loop),\n\t\t\t\tframe,\n\t\t\t\tnull,\n\t\t\t);\n\t\t\tif (run.kind === \"unknown\") {\n\t\t\t\treturn result(\"unknown\", [run.reason], run.estimate);\n\t\t\t}\n\t\t\treturn result(run.returned ? \"false\" : \"true\", [], run.estimate);\n\t\t}\n\t\tcase \"job\":\n\t\t\treturn jobTruth(\n\t\t\t\tevaluation,\n\t\t\t\ttables.slots(frame.row)?.job ?? -1,\n\t\t\t\tcondition.step,\n\t\t\t\tresult,\n\t\t\t);\n\t\tcase \"jobBusy\": {\n\t\t\tconst state = read.job(tables.slots(frame.row)?.job ?? -1);\n\t\t\tif (!state || state.busy === null) {\n\t\t\t\treturn result(\"unknown\", [\"the job's state isn't known\"]);\n\t\t\t}\n\t\t\treturn state.busy\n\t\t\t\t? result(\"true\", [], [\"the job may have moved on since\"])\n\t\t\t\t: result(\"candidate\", [\"the job isn't running now\"]);\n\t\t}\n\t}\n};\n\nexport const conditionsTruth = (\n\tevaluation: Evaluation,\n\tentry: number | null,\n\tframe: Frame,\n): ConditionsTruth => {\n\tconst results = evaluation.tables\n\t\t.conditionList(entry)\n\t\t.map((condition) => conditionTruth(evaluation, condition, frame));\n\treturn {\n\t\ttruth: and(results.map((item) => item.truth)),\n\t\tresults,\n\t\testimate: merge(...results.map((item) => item.estimate)),\n\t};\n};\n\n/** Whether an index a pattern writes at runtime is the one the explained path has. */\nconst indexTruth = (outcome: Outcome, wanted: bigint | undefined): Truth => {\n\tif (!outcome.known) {\n\t\treturn \"unknown\";\n\t}\n\treturn outcome.value.kind === \"integer\" && outcome.value.value === wanted\n\t\t? \"true\"\n\t\t: \"false\";\n};\n\n/** How a writer inside a loop fared over the loop's execution. */\nconst loopResult = (\n\trun: LoopRun,\n): Pick<ConditionResult, \"truth\" | \"reasons\"> => {\n\tif (run.kind === \"unknown\") {\n\t\treturn { truth: \"unknown\", reasons: [run.reason] };\n\t}\n\treturn run.ran\n\t\t? { truth: \"true\", reasons: [] }\n\t\t: { truth: \"false\", reasons: [\"no iteration ran it\"] };\n};\n\nconst states = {\n\ttrue: \"runs\",\n\tfalse: \"blocked\",\n\tunknown: \"unknown\",\n\tcandidate: \"candidate\",\n} as const;\n\n/** A writer's verdict through one chain. */\nconst verdict = (\n\tevaluation: Evaluation,\n\twriter: Writer,\n\tchain: Chain,\n): Verdict => {\n\tconst { file, tables } = evaluation;\n\tconst assignment = file.assignments[writer.assignment];\n\tif (!assignment) {\n\t\treturn {\n\t\t\twriter,\n\t\t\tchain,\n\t\t\tstate: \"unknown\",\n\t\t\treasons: [\"not traced\"],\n\t\t\testimate: [],\n\t\t\tconditions: [],\n\t\t\tvalue: null,\n\t\t};\n\t}\n\tconst results: ConditionResult[] = [];\n\tlet frame = rootFrame(evaluation, { ...chain, calls: [] });\n\tconst reasons: string[] = [];\n\tfor (const call of chain.calls) {\n\t\tconst record = file.calls[call];\n\t\tif (!record) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (record.loop !== null) {\n\t\t\treasons.push(\"called inside a loop\");\n\t\t\tresults.push({\n\t\t\t\tcondition: {\n\t\t\t\t\tkind: \"loop\",\n\t\t\t\t\tloop: tables.loopSlot(frame.row, record.loop),\n\t\t\t\t},\n\t\t\t\trow: frame.row,\n\t\t\t\ttruth: \"unknown\",\n\t\t\t\treasons: [\"called inside a loop\"],\n\t\t\t\testimate: [],\n\t\t\t});\n\t\t} else {\n\t\t\tresults.push(\n\t\t\t\t...conditionsTruth(evaluation, record.conditions, frame).results,\n\t\t\t);\n\t\t}\n\t\tconst next = calleeFrame(evaluation, call, frame);\n\t\tif (\"known\" in next) {\n\t\t\treturn {\n\t\t\t\twriter,\n\t\t\t\tchain,\n\t\t\t\tstate: \"unknown\",\n\t\t\t\treasons: [next.reason],\n\t\t\t\testimate: [...next.estimate],\n\t\t\t\tconditions: results,\n\t\t\t\tvalue: null,\n\t\t\t};\n\t\t}\n\t\tframe = next;\n\t}\n\t// A place written through a parameter is named, with its indexes, in the outermost caller.\n\tconst namingFrame = (inner: Frame): Frame =>\n\t\tassignment.via.reduce<Frame>(\n\t\t\t(frame) => frame.caller?.frame ?? frame,\n\t\t\tinner,\n\t\t);\n\t// A write at runtime indexes reaches the explained path only when each index matches.\n\tconst indexMatch = (inner: Frame): ConditionResult[] =>\n\t\tassignment.writes.kind === \"pattern\"\n\t\t\t? assignment.writes.indexes.map((index, position) => {\n\t\t\t\t\tconst outcome = evaluation.expression(index, namingFrame(inner));\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcondition: {\n\t\t\t\t\t\t\tkind: \"test\",\n\t\t\t\t\t\t\ttest: index,\n\t\t\t\t\t\t\tholds: true,\n\t\t\t\t\t\t\tat: assignment.position,\n\t\t\t\t\t\t\ttext: null,\n\t\t\t\t\t\t},\n\t\t\t\t\t\trow: namingFrame(inner).row,\n\t\t\t\t\t\ttruth: indexTruth(outcome, writer.indexes[position]),\n\t\t\t\t\t\treasons: outcome.known ? [] : [outcome.reason],\n\t\t\t\t\t\testimate: outcome.estimate,\n\t\t\t\t\t};\n\t\t\t\t})\n\t\t\t: [];\n\tconst reaches = (inner: Frame) => {\n\t\tconst own = conditionsTruth(evaluation, assignment.conditions, inner);\n\t\tconst matched = indexMatch(inner);\n\t\treturn {\n\t\t\ttruth: and([own.truth, ...matched.map((item) => item.truth)]),\n\t\t\testimate: merge(own.estimate, ...matched.map((item) => item.estimate)),\n\t\t\tresults: [...own.results, ...matched],\n\t\t};\n\t};\n\tif (assignment.loop !== null) {\n\t\tconst run = executeLoop(evaluation, assignment.loop, frame, reaches);\n\t\tresults.push({\n\t\t\tcondition: {\n\t\t\t\tkind: \"loop\",\n\t\t\t\tloop: tables.loopSlot(frame.row, assignment.loop),\n\t\t\t},\n\t\t\trow: frame.row,\n\t\t\t...loopResult(run),\n\t\t\testimate: run.estimate,\n\t\t});\n\t\tif (run.kind === \"run\" && run.ran) {\n\t\t\tframe = run.ran;\n\t\t}\n\t} else {\n\t\tresults.push(...reaches(frame).results);\n\t}\n\tconst truth = and(results.map((item) => item.truth));\n\treturn {\n\t\twriter,\n\t\tchain,\n\t\tstate: states[truth],\n\t\treasons: [\n\t\t\t...reasons,\n\t\t\t...results\n\t\t\t\t.filter((item) => item.truth === truth && truth !== \"true\")\n\t\t\t\t.flatMap((item) => item.reasons),\n\t\t],\n\t\testimate: merge(...results.map((item) => item.estimate)),\n\t\tconditions: results,\n\t\tvalue:\n\t\t\ttruth === \"true\" && assignment.value !== null\n\t\t\t\t? evaluation.expression(assignment.value, frame)\n\t\t\t\t: null,\n\t};\n};\n\n/** Why the path has its value in the evaluation's read; `type` is the path's manifest type. */\nexport const answer = (\n\tevaluation: Evaluation,\n\texplanation: Explanation,\n\ttype: string,\n): AnswerResult => {\n\tconst { manifest, file, tables, read, needs } = evaluation;\n\tconst current = sampleOutcome(evaluation, explanation.path, type);\n\tconst verdicts = explanation.writers.flatMap((writer) =>\n\t\twriter.chains.length\n\t\t\t? writer.chains.map((chain) => verdict(evaluation, writer, chain))\n\t\t\t: [\n\t\t\t\t\t{\n\t\t\t\t\t\twriter,\n\t\t\t\t\t\tchain: { task: \"\", entry: -1, calls: [] },\n\t\t\t\t\t\tstate: \"blocked\" as const,\n\t\t\t\t\t\treasons: [\"no task reaches it\"],\n\t\t\t\t\t\testimate: [],\n\t\t\t\t\t\tconditions: [],\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t},\n\t\t\t\t],\n\t);\n\tconst slot = read.slot(explanation.path);\n\tconst slotted = verdicts.filter((item) =>\n\t\tslot?.assignments?.includes(item.writer.assignment),\n\t);\n\tconst result = (answer: Answer): AnswerResult => ({\n\t\tanswer,\n\t\tverdicts,\n\t\tclientWritable: explanation.flags.clientWritable,\n\t\thmiControl: explanation.flags.hmiControl,\n\t\tretained: explanation.flags.retained,\n\t\twriterTasks: explanation.flags.writerTasks,\n\t\tneeds: [...needs],\n\t\thint: slot && !slot.exact ? slotted : [],\n\t});\n\tif (read.forced?.has(explanation.path)) {\n\t\treturn result({ kind: \"forced\", value: current });\n\t}\n\tif (slot?.exact) {\n\t\treturn result({\n\t\t\tkind: \"exact\",\n\t\t\twriter:\n\t\t\t\tslot.assignments === null\n\t\t\t\t\t? null\n\t\t\t\t\t: (slotted.find((item) => item.state === \"runs\") ??\n\t\t\t\t\t\tslotted[0] ??\n\t\t\t\t\t\tnull),\n\t\t});\n\t}\n\tif (explanation.io?.direction === \"input\") {\n\t\treturn result({ kind: \"input\", io: explanation.io, value: current });\n\t}\n\tconst orderOf = (item: Verdict) =>\n\t\ttables.writeOrder(\n\t\t\titem.chain,\n\t\t\tfile.assignments[item.writer.assignment]?.position ?? 0,\n\t\t);\n\tconst ordered = [...verdicts].sort((a, b) =>\n\t\tcompareOrder(orderOf(a), orderOf(b)),\n\t);\n\tconst consistent = (item: Verdict): boolean => {\n\t\tif (!item.value?.known || item.value.estimate.length || !current.known) {\n\t\t\treturn true;\n\t\t}\n\t\treturn equalValues(item.value.value, current.value) !== false;\n\t};\n\tconst running = ordered.filter((item) => item.state === \"runs\");\n\tconst excluded = running.filter((item) => !consistent(item));\n\tconst candidates = running.filter((item) => consistent(item));\n\tconst last = candidates.at(-1);\n\tif (last) {\n\t\tconst tasks = new Set(running.map((item) => item.chain.task));\n\t\tconst later = ordered\n\t\t\t.slice(ordered.indexOf(last) + 1)\n\t\t\t.filter(\n\t\t\t\t(item) =>\n\t\t\t\t\titem.state === \"unknown\" ||\n\t\t\t\t\titem.state === \"candidate\" ||\n\t\t\t\t\t(item.state === \"runs\" && item.chain.task !== last.chain.task),\n\t\t\t);\n\t\tconst others =\n\t\t\ttasks.size > 1\n\t\t\t\t? running.filter(\n\t\t\t\t\t\t(item) => item !== last && item.chain.task !== last.chain.task,\n\t\t\t\t\t)\n\t\t\t\t: [];\n\t\tconst unless = [...new Set([...later, ...others])];\n\t\treturn result({\n\t\t\tkind: \"set\",\n\t\t\twriter: last,\n\t\t\tunless,\n\t\t\testimate: merge(\n\t\t\t\tlast.estimate,\n\t\t\t\tunless.length ? [\"another writer may have run after it\"] : [],\n\t\t\t\texcluded.some((item) => ordered.indexOf(item) > ordered.indexOf(last))\n\t\t\t\t\t? [\"a later writer's value didn't match\"]\n\t\t\t\t\t: [],\n\t\t\t),\n\t\t});\n\t}\n\tif (excluded.length) {\n\t\treturn result({ kind: \"changed\", writers: excluded });\n\t}\n\tif (\n\t\tverdicts.every(\n\t\t\t(item) => item.state === \"blocked\" || item.state === \"candidate\",\n\t\t)\n\t) {\n\t\tconst could = verdicts.filter((item) => {\n\t\t\tconst assignment = file.assignments[item.writer.assignment];\n\t\t\tconst constant =\n\t\t\t\tassignment?.value === null || assignment?.value === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: file.expressions[assignment.value];\n\t\t\tif (constant?.kind !== \"constant\" || !current.known) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst value = sampleValue(manifest, constant.type, constant.value);\n\t\t\treturn !value || equalValues(value, current.value) !== false;\n\t\t});\n\t\tconst jobs = verdicts.filter((item) => item.state === \"candidate\");\n\t\treturn result({\n\t\t\tkind: \"held\",\n\t\t\twriters: could,\n\t\t\testimate: jobs.length ? [\"set by a job step, this scan or earlier\"] : [],\n\t\t});\n\t}\n\tconst open = verdicts.filter((item) => item.state === \"unknown\");\n\treturn result({\n\t\tkind: \"unknown\",\n\t\twriters: open,\n\t\treasons: merge(...open.map((item) => item.reasons)),\n\t});\n};\n",
|
|
24
|
+
"import { expression } from \"./explain-expressions\";\nimport type { ExplainFile } from \"./explain-file\";\nimport { type Evaluation, type ExplainRead, rootFrame } from \"./explain-frames\";\nimport {\n\ttype Chain,\n\tcreateExplainTables,\n\ttype Explanation,\n} from \"./explain-tables\";\nimport { answer, conditionsTruth, conditionTruth } from \"./explain-verdicts\";\nimport type { DebugManifest } from \"./manifest\";\n\n/**\n * Why a stored value is what it is: the statements that write it, the conditions they run under\n * and the live values those read. Pure, so the browser UI and the VS Code extension evaluate with\n * the same rules. Every evaluation reads one `ExplainRead`: values the login read together.\n */\n\nexport { maxDepth, nodeBudget } from \"./explain-expressions\";\nexport type { ExplainRead } from \"./explain-frames\";\nexport { maxLoopIterations } from \"./explain-loops\";\nexport type { Chain, Explanation, Writer } from \"./explain-tables\";\nexport {\n\ttype Outcome,\n\ttype PlcValue,\n\tsampleValue,\n\ttype Truth,\n} from \"./explain-value\";\nexport type {\n\tAnswer,\n\tAnswerResult,\n\tConditionResult,\n\tVerdict,\n} from \"./explain-verdicts\";\n\nexport const createExplainer = (manifest: DebugManifest, file: ExplainFile) => {\n\tconst tables = createExplainTables(manifest, file);\n\n\t/** One explanation's evaluation over one read. */\n\tconst evaluation = (read: ExplainRead): Evaluation => {\n\t\tconst context: Evaluation = {\n\t\t\tmanifest,\n\t\t\tfile,\n\t\t\ttables,\n\t\t\tread,\n\t\t\tneeds: new Set(),\n\t\t\tmemo: new Map(),\n\t\t\tbudget: { spent: 0, depth: 0 },\n\t\t\texpression: (index, frame) => expression(context, index, frame),\n\t\t\tconditionTruth: (condition, frame) =>\n\t\t\t\tconditionTruth(context, condition, frame),\n\t\t\tconditionsTruth: (entry, frame) => conditionsTruth(context, entry, frame),\n\t\t};\n\t\treturn context;\n\t};\n\n\treturn {\n\t\texplain: tables.explain,\n\t\t/** Why `path` has its value in `read`; `type` is the path's manifest type. */\n\t\tanswer: (explanation: Explanation, type: string, read: ExplainRead) =>\n\t\t\tanswer(evaluation(read), explanation, type),\n\t\t/**\n\t\t * The value of an expression of `explain.json` in `read`, evaluated in routine row `row` as\n\t\t * the chain reaches it: its innermost frame of that row.\n\t\t */\n\t\tevaluate: (index: number, chain: Chain, read: ExplainRead, row: number) => {\n\t\t\tconst run = evaluation(read);\n\t\t\tconst frames = chain.calls.map((_, depth) =>\n\t\t\t\trootFrame(run, { ...chain, calls: chain.calls.slice(0, depth + 1) }),\n\t\t\t);\n\t\t\tconst frame =\n\t\t\t\t[rootFrame(run, { ...chain, calls: [] }), ...frames]\n\t\t\t\t\t.reverse()\n\t\t\t\t\t.find((item) => item.row === row) ?? rootFrame(run, chain);\n\t\t\treturn expression(run, index, frame);\n\t\t},\n\t\t/** The stored path a read or pattern of routine row `row` names by `slot`. */\n\t\tpathAt: tables.pathAt,\n\t\tfile,\n\t};\n};\n\nexport type Explainer = ReturnType<typeof createExplainer>;\n",
|
|
25
|
+
"import type { Quality } from \"@tsplc/opcua/contract\";\nimport {\n\tscalarRead,\n\ttype TargetRead,\n\ttype TargetSample,\n\tworstQuality,\n} from \"./adapter\";\nimport type { DeviceState } from \"./api\";\nimport type { DebugDevice, DebugIo, DebugType } from \"./manifest\";\n\n/** Driver state names that mean the connection isn't working. */\nconst faultyState = /error|fault|fail|timeout|lost|closed/i;\n\n/** What a device's health is read from: the driver's own state, when the build names it. */\nexport const healthReads = (device: DebugDevice): TargetRead[] => {\n\tconst { state, states, diagnostic, message } = device.health ?? {};\n\treturn [\n\t\t// The driver's state is an enum, which the login names, whether or not the manifest lists its members.\n\t\t...(state\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\ttarget: state,\n\t\t\t\t\t\ttype: {\n\t\t\t\t\t\t\tkind: \"enum\" as const,\n\t\t\t\t\t\t\tname: \"state\",\n\t\t\t\t\t\t\tmembers: states ?? {},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: []),\n\t\t...(diagnostic ? [scalarRead(diagnostic, \"BOOL\")] : []),\n\t\t...(message ? [scalarRead(message, \"STRING\")] : []),\n\t];\n};\n\n/** Everything a device's page shows: its health, raw assembly bytes, bound channels and status symbols. */\nexport const deviceReads = (\n\tdevice: DebugDevice,\n\tio: readonly DebugIo[],\n\ttypeOf: (id: string) => DebugType,\n): TargetRead[] => [\n\t...healthReads(device),\n\t...device.assemblies.flatMap(({ raw, bytes }) =>\n\t\traw\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\ttarget: raw,\n\t\t\t\t\t\ttype: {\n\t\t\t\t\t\t\tkind: \"array\" as const,\n\t\t\t\t\t\t\telement: \"BYTE\",\n\t\t\t\t\t\t\tlength: bytes,\n\t\t\t\t\t\t\tlower: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [],\n\t),\n\t...io\n\t\t.filter((binding) => binding.device === device.id)\n\t\t.map(({ target, type }) => ({ target, type: typeOf(type) })),\n\t// Hand-configured status symbols have no type in the manifest; they show as read.\n\t...Object.values(device.status ?? {}).map((target) =>\n\t\tscalarRead(target, \"ANY\"),\n\t),\n];\n\n/** A reading that is no longer good says nothing current, fault or not. */\nconst healthState = (quality: Quality, faulted: boolean) => {\n\tif (quality !== \"good\") {\n\t\treturn \"stale\";\n\t}\n\treturn faulted ? \"fault\" : \"ok\";\n};\n\nconst health = (\n\tdevice: DebugDevice,\n\tvalue: (target: string) => TargetSample | undefined,\n): DeviceState[\"health\"] => {\n\tconst { state, states, diagnostic, message } = device.health ?? {};\n\tif (!state && !diagnostic) {\n\t\treturn { state: \"unknown\", quality: \"unavailable\" };\n\t}\n\tconst stateSample = state ? value(state) : undefined;\n\tconst diagnosticSample = diagnostic ? value(diagnostic) : undefined;\n\tconst messageSample = message ? value(message) : undefined;\n\tconst quality = worstQuality([\n\t\t...(state ? [stateSample] : []),\n\t\t...(diagnostic ? [diagnosticSample] : []),\n\t]);\n\tconst number =\n\t\ttypeof stateSample?.value === \"number\" ? stateSample.value : undefined;\n\t// The login names enum members the manifest may not list.\n\tconst name =\n\t\tObject.entries(states ?? {}).find(([, member]) => member === number)?.[0] ??\n\t\t(typeof stateSample?.value === \"string\" ? stateSample.value : undefined);\n\tconst faulted =\n\t\tdiagnosticSample?.value === true ||\n\t\t(name !== undefined && faultyState.test(name));\n\treturn {\n\t\tstate: healthState(quality, faulted),\n\t\t...(number !== undefined && { value: number }),\n\t\t...(name && { name }),\n\t\t...(typeof diagnosticSample?.value === \"boolean\" && {\n\t\t\tdiagnostic: diagnosticSample.value,\n\t\t}),\n\t\t...(typeof messageSample?.value === \"string\" && {\n\t\t\tmessage: messageSample.value,\n\t\t}),\n\t\tquality,\n\t};\n};\n\nconst reading = (sample: TargetSample | undefined) => ({\n\tvalue: sample?.value ?? null,\n\tquality: sample?.quality ?? \"unavailable\",\n});\n\n/**\n * A device's driver health, raw assembly bytes, bound channel values and status symbols. Health\n * is \"unknown\" unless the manifest names the driver's own state.\n */\nexport const deviceState = (\n\tdevice: DebugDevice,\n\tio: readonly DebugIo[],\n\tvalue: (target: string) => TargetSample | undefined,\n): DeviceState => ({\n\tid: device.id,\n\thealth: health(device, value),\n\tassemblies: device.assemblies.map(({ direction, address, raw }) => {\n\t\tconst sample = raw ? value(raw) : undefined;\n\t\treturn {\n\t\t\tdirection,\n\t\t\t...(address && { address }),\n\t\t\tbytes:\n\t\t\t\tArray.isArray(sample?.value) &&\n\t\t\t\tsample.value.every((byte): byte is number => typeof byte === \"number\")\n\t\t\t\t\t? sample.value\n\t\t\t\t\t: null,\n\t\t\tquality: sample?.quality ?? \"unavailable\",\n\t\t};\n\t}),\n\tchannels: io.flatMap((binding) =>\n\t\tbinding.device === device.id && binding.channel\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: binding.channel,\n\t\t\t\t\t\tpath: binding.path,\n\t\t\t\t\t\t...reading(value(binding.target)),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [],\n\t),\n\tstatus: Object.fromEntries(\n\t\tObject.entries(device.status ?? {}).map(([label, target]) => [\n\t\t\tlabel,\n\t\t\treading(value(target)),\n\t\t]),\n\t),\n});\n",
|
|
26
|
+
"import { scalarRead, type TargetRead, type TargetSample } from \"./adapter\";\nimport type { JobState, Session } from \"./api\";\nimport {\n\ttype DebugJob,\n\tinstrumentationFields,\n\tjobStateFields,\n} from \"./manifest\";\nimport type { ServiceCallLookup } from \"./requests\";\n\n/** What the trace said of a job: whether it is running, and when it last started. */\nexport interface TracedJob {\n\tbusy: boolean;\n\tstartedAt?: string;\n}\n\nconst stateRead = (job: DebugJob, field: keyof typeof jobStateFields) =>\n\tscalarRead(`${job.target}.${field}`, jobStateFields[field]);\n\n/** The job's `busy` flag, read while a page shows the job and the trace says nothing of it. */\nexport const busyRead = (job: DebugJob) => stateRead(job, \"busy\");\n\n/** What a busy job shows: where it waits, since when, and its latest request. */\nexport const detailReads = (job: DebugJob): TargetRead[] => [\n\tstateRead(job, \"step\"),\n\tstateRead(job, \"cancelling\"),\n\t...(job.startedAt\n\t\t? [scalarRead(job.startedAt, instrumentationFields.startedAt)]\n\t\t: []),\n\t...job.requests.map(({ sequence }) =>\n\t\tscalarRead(sequence, instrumentationFields.sequence),\n\t),\n];\n\nconst busyFrom = (\n\tread: TargetSample | undefined,\n\ttraced: TracedJob | undefined,\n) => (read?.quality === \"good\" ? read.value === true : (traced?.busy ?? null));\n\n/**\n * From the last read, else from the trace; null when neither knows. A read wins: a job's caller\n * stops running it once it finishes, so the trace can miss the finish.\n */\nexport const busyOf = (\n\tjob: DebugJob,\n\tvalue: (target: string) => TargetSample | undefined,\n\ttraced: TracedJob | undefined,\n) => busyFrom(value(busyRead(job).target), traced);\n\nconst numberOf = (sample: TargetSample | undefined) =>\n\tsample?.quality === \"good\" && typeof sample.value === \"number\"\n\t\t? sample.value\n\t\t: undefined;\n\n/**\n * A job as the debugger shows it at host time `now`. Details are shown only while it is busy;\n * its last start stays, so a later run tells a failure apart from the current state. Without a\n * clock estimate there is no start time from the PLC's own `startedAt`.\n */\nexport const jobState = (\n\tjob: DebugJob,\n\tinputs: {\n\t\tvalue: (target: string) => TargetSample | undefined;\n\t\ttraced: TracedJob | undefined;\n\t\tfailure: JobState[\"failure\"];\n\t\t/** Busy, but its details aren't read for want of room in the poll. */\n\t\tunread: boolean;\n\t\tclock: Session[\"clock\"];\n\t\tnow: number;\n\t\trequest: ServiceCallLookup;\n\t},\n): JobState => {\n\tconst { value, traced, clock, now } = inputs;\n\tconst busySample = value(busyRead(job).target);\n\tconst busy = busyFrom(busySample, traced);\n\tconst startedPlc =\n\t\tjob.startedAt === undefined ? undefined : numberOf(value(job.startedAt));\n\tconst startedAt =\n\t\ttraced?.startedAt ??\n\t\t(clock && startedPlc !== undefined\n\t\t\t? new Date(startedPlc - clock.offsetMs).toISOString()\n\t\t\t: undefined);\n\tconst base: JobState = {\n\t\tid: job.id,\n\t\tquality: busySample?.quality ?? (traced ? \"good\" : \"unavailable\"),\n\t\tbusy,\n\t\t...(startedAt && { startedAt }),\n\t\t...(inputs.failure && { failure: inputs.failure }),\n\t};\n\tif (!busy) {\n\t\treturn base;\n\t}\n\tif (inputs.unread) {\n\t\treturn { ...base, unread: true };\n\t}\n\n\tconst step = numberOf(value(stateRead(job, \"step\").target));\n\tconst current = job.steps.find((candidate) => candidate.step === step);\n\t// Each call site counts its own requests, so the latest is the one the server saw start last,\n\t// or the one counted furthest while the server has yet to report them.\n\tconst calls = job.requests\n\t\t.map((call) => {\n\t\t\tconst sequence = numberOf(value(call.sequence)) ?? 0;\n\t\t\tconst trace = inputs.request({\n\t\t\t\tjob: call.job ?? job.id,\n\t\t\t\tservice: call.service,\n\t\t\t\tsequence,\n\t\t\t});\n\t\t\treturn { service: call.service, sequence, trace };\n\t\t})\n\t\t.filter(({ sequence }) => sequence > 0);\n\tconst later = (call: (typeof calls)[number], than: (typeof calls)[number]) =>\n\t\tcall.trace && than.trace\n\t\t\t? call.trace.startedAt > than.trace.startedAt\n\t\t\t: call.sequence > than.sequence;\n\tconst latest = calls.reduce<(typeof calls)[number] | undefined>(\n\t\t(latest, call) => (latest && !later(call, latest) ? latest : call),\n\t\tundefined,\n\t);\n\tconst cancelling = value(stateRead(job, \"cancelling\").target);\n\n\treturn {\n\t\t...base,\n\t\t...(cancelling?.quality === \"good\" && {\n\t\t\tcancelling: cancelling.value === true,\n\t\t}),\n\t\t...(step !== undefined && { step }),\n\t\t...(current && {\n\t\t\tcurrent: { kind: current.kind, range: current.range, text: current.text },\n\t\t}),\n\t\t...(startedAt && { elapsedMs: Math.max(0, now - Date.parse(startedAt)) }),\n\t\t...(latest && {\n\t\t\trequest: {\n\t\t\t\tservice: latest.service,\n\t\t\t\tsequence: latest.sequence,\n\t\t\t\t...(latest.trace && { trace: latest.trace }),\n\t\t\t},\n\t\t}),\n\t};\n};\n",
|
|
27
|
+
"import type { TargetAdapter, TargetRead, TargetSample } from \"./adapter\";\nimport type { Interest, JobState, Session, StreamEvent } from \"./api\";\nimport { deviceReads, deviceState, healthReads } from \"./hardware\";\nimport {\n\tbusyOf,\n\tbusyRead,\n\tdetailReads,\n\tjobState,\n\ttype TracedJob,\n} from \"./jobs\";\nimport type { DebugDevice, DebugJob, DebugManifest } from \"./manifest\";\nimport type { Paths } from \"./paths\";\nimport type { ServiceCallLookup } from \"./requests\";\n\n/** Device health, raw bytes and channels change rarely enough for this. */\nconst hardwareMs = 5000;\n/** Busy jobs whose details each poll reads; the rest show as busy only. */\nconst detailedJobs = 16;\n\n/** Counts how many streams show each key. */\nconst countShown = <Key>() => {\n\tconst counts = new Map<Key, number>();\n\treturn {\n\t\thas: (key: Key) => counts.has(key),\n\t\tadd: (keys: readonly Key[]) => {\n\t\t\tfor (const key of keys) {\n\t\t\t\tcounts.set(key, (counts.get(key) ?? 0) + 1);\n\t\t\t}\n\t\t\treturn () => {\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\tconst count = (counts.get(key) ?? 1) - 1;\n\t\t\t\t\tif (count) {\n\t\t\t\t\t\tcounts.set(key, count);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcounts.delete(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t};\n};\n\n/**\n * The jobs and devices the pages show: each is read only while a stream shows it, and its state\n * is sent to the streams when it changes.\n */\nexport const createShownReads = ({\n\tmanifest,\n\tpaths,\n\tadapter,\n\temit,\n\tclock,\n\trequest,\n}: {\n\tmanifest: DebugManifest;\n\tpaths: Paths;\n\tadapter: TargetAdapter;\n\temit: (event: StreamEvent) => void;\n\tclock: () => Session[\"clock\"];\n\trequest: ServiceCallLookup;\n}) => {\n\tconst latest = new Map<string, TargetSample>();\n\tconst traced = new Map<number, TracedJob>();\n\tconst failures = new Map<number, NonNullable<JobState[\"failure\"]>>();\n\tlet unread = new Set<number>();\n\tconst shownJobs = countShown<number>();\n\tconst shownHealth = countShown<string>();\n\tconst shownDevices = countShown<string>();\n\t/** The JSON of what each stream last got, so unchanged states aren't sent again. */\n\tconst sent = new Map<string, string>();\n\tconst value = (target: string) => latest.get(target);\n\n\tconst jobOf = (job: DebugJob) =>\n\t\tjobState(job, {\n\t\t\tvalue,\n\t\t\ttraced: traced.get(job.id),\n\t\t\tfailure: failures.get(job.id),\n\t\t\tunread: unread.has(job.id),\n\t\t\tclock: clock(),\n\t\t\tnow: Date.now(),\n\t\t\trequest,\n\t\t});\n\tconst deviceOf = (device: DebugDevice) =>\n\t\tdeviceState(device, manifest.io, value);\n\tconst send = (key: string, event: StreamEvent) => {\n\t\tconst json = JSON.stringify(event.data);\n\t\tif (sent.get(key) === json) {\n\t\t\treturn;\n\t\t}\n\t\tsent.set(key, json);\n\t\temit(event);\n\t};\n\tconst updateJob = (job: DebugJob) =>\n\t\tsend(`job:${job.id}`, { name: \"job\", data: jobOf(job) });\n\tconst updateDevice = (device: DebugDevice) =>\n\t\tsend(`device:${device.id}`, { name: \"device\", data: deviceOf(device) });\n\n\t/** Re-subscribes `reads` when they change, telling `update` which owners each sample is for. */\n\tconst reader = <Owner>(\n\t\tintervalMs: number,\n\t\tupdate: (owner: Owner) => void,\n\t) => {\n\t\tlet current = { key: \"\", stop: () => {} };\n\t\treturn (reads: { owner: Owner; read: TargetRead }[]) => {\n\t\t\tconst key = reads.map(({ read }) => read.target).join(\"\\n\");\n\t\t\tif (key === current.key) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcurrent.stop();\n\t\t\tconst owners = new Map<string, Owner[]>();\n\t\t\tfor (const { owner, read } of reads) {\n\t\t\t\towners.set(read.target, [...(owners.get(read.target) ?? []), owner]);\n\t\t\t}\n\t\t\tcurrent = {\n\t\t\t\tkey,\n\t\t\t\tstop: reads.length\n\t\t\t\t\t? adapter.subscribe(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t...new Map(\n\t\t\t\t\t\t\t\t\treads.map(({ read }) => [read.target, read]),\n\t\t\t\t\t\t\t\t).values(),\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t(target, sample) => {\n\t\t\t\t\t\t\t\tlatest.set(target, sample);\n\t\t\t\t\t\t\t\tfor (const owner of owners.get(target) ?? []) {\n\t\t\t\t\t\t\t\t\tupdate(owner);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tschedule();\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tintervalMs,\n\t\t\t\t\t\t)\n\t\t\t\t\t: () => {},\n\t\t\t};\n\t\t};\n\t};\n\tconst readJobs = reader<DebugJob>(adapter.samplingMs, updateJob);\n\tconst readDevices = reader<DebugDevice>(hardwareMs, updateDevice);\n\n\t/** Everything of a device whose page is shown, else its health while a list shows it. */\n\tconst shownDeviceReads = (device: DebugDevice) => {\n\t\tif (shownDevices.has(device.id)) {\n\t\t\treturn deviceReads(device, manifest.io, paths.typeOf);\n\t\t}\n\t\tif (shownHealth.has(device.id)) {\n\t\t\treturn healthReads(device);\n\t\t}\n\t\treturn [];\n\t};\n\n\t/** Reads `busy` of the shown jobs, and the details of the busy ones. */\n\tconst plan = () => {\n\t\tconst shown = manifest.jobs.filter((job) => shownJobs.has(job.id));\n\t\tconst busy = shown.filter((job) => busyOf(job, value, traced.get(job.id)));\n\t\tunread = new Set(busy.slice(detailedJobs).map(({ id }) => id));\n\t\treadJobs([\n\t\t\t...shown.map((job) => ({ owner: job, read: busyRead(job) })),\n\t\t\t...busy\n\t\t\t\t.slice(0, detailedJobs)\n\t\t\t\t.flatMap((job) =>\n\t\t\t\t\tdetailReads(job).map((read) => ({ owner: job, read })),\n\t\t\t\t),\n\t\t]);\n\t\treadDevices(\n\t\t\tmanifest.devices.flatMap((device) =>\n\t\t\t\tshownDeviceReads(device).map((read) => ({ owner: device, read })),\n\t\t\t),\n\t\t);\n\t};\n\tlet planned = false;\n\tconst schedule = () => {\n\t\tif (planned) {\n\t\t\treturn;\n\t\t}\n\t\tplanned = true;\n\t\tqueueMicrotask(() => {\n\t\t\tplanned = false;\n\t\t\tplan();\n\t\t});\n\t};\n\n\treturn {\n\t\tjobs: () => manifest.jobs.map(jobOf),\n\t\thardware: () => manifest.devices.map(deviceOf),\n\t\tupdateJob,\n\t\t/** Reads what `interest` shows until the returned function is called. */\n\t\tshow: (interest: Pick<Interest, \"jobs\" | \"health\" | \"devices\">) => {\n\t\t\tconst stops = [\n\t\t\t\tshownJobs.add(interest.jobs),\n\t\t\t\tshownHealth.add(interest.health),\n\t\t\t\tshownDevices.add(interest.devices),\n\t\t\t];\n\t\t\tschedule();\n\t\t\treturn () => {\n\t\t\t\tfor (const stop of stops) {\n\t\t\t\t\tstop();\n\t\t\t\t}\n\t\t\t\tschedule();\n\t\t\t};\n\t\t},\n\t\t/** A trace record of `job` starting or finishing at `at`. */\n\t\ttraced: (job: DebugJob, started: boolean, at: string) => {\n\t\t\tconst startedAt = started ? at : traced.get(job.id)?.startedAt;\n\t\t\ttraced.set(job.id, { busy: started, ...(startedAt && { startedAt }) });\n\t\t\tupdateJob(job);\n\t\t\tschedule();\n\t\t},\n\t\t/** A failure of `job` that nothing caught. */\n\t\tfailed: (job: DebugJob, failure: NonNullable<JobState[\"failure\"]>) => {\n\t\t\tfailures.set(job.id, failure);\n\t\t\tupdateJob(job);\n\t\t},\n\t\t/** Nothing read is current while the controller isn't connected, for `status`. */\n\t\tdisconnected: (status: string) => {\n\t\t\tfor (const [target, sample] of latest) {\n\t\t\t\tlatest.set(target, { ...sample, quality: \"unavailable\", status });\n\t\t\t}\n\t\t\tfor (const job of manifest.jobs) {\n\t\t\t\tupdateJob(job);\n\t\t\t}\n\t\t\tfor (const device of manifest.devices) {\n\t\t\t\tupdateDevice(device);\n\t\t\t}\n\t\t},\n\t\tclose: () => {\n\t\t\treadJobs([]);\n\t\t\treadDevices([]);\n\t\t},\n\t};\n};\n",
|
|
28
|
+
"import type {\n\tTelemetryBatch,\n\tTelemetryRecord,\n\tTelemetryReply,\n} from \"@tsplc/server/telemetry\";\nimport { recordedAt } from \"@tsplc/server/telemetry-log\";\nimport type { Session } from \"./api\";\nimport type { DebugManifest } from \"./manifest\";\nimport { createServerCursor } from \"./server-cursor\";\n\n/** Clock estimates are kept this long, on the server's clock. */\nconst clockWindowMs = 60_000;\n\n/** A record with the batch it came in, numbered in its task's sequence, at its time on the server's clock. */\nexport interface ReceivedRecord {\n\tbuild: string;\n\ttask: string;\n\tsequence: number;\n\tat: string;\n\trecord: TelemetryRecord;\n}\n\n/**\n * Follows the app server's telemetry ring (`GET /tsplc/telemetry`): it hands out each new record\n * once, keeps the tasks' scan rates, and estimates the PLC's clock against the server's.\n */\nexport const createTelemetryFollower = (manifest: DebugManifest) => {\n\tconst intervals = new Map(\n\t\tmanifest.tasks.map(({ name, intervalMs }) => [name, intervalMs]),\n\t);\n\tconst tasks = new Map<string, Session[\"tasks\"][number]>(\n\t\tmanifest.tasks.map(({ name }) => [\n\t\t\tname,\n\t\t\t{ name, scan: null, scansPerSecond: null, dropped: 0 },\n\t\t]),\n\t);\n\tconst rates = new Map<string, { scan: number; now: number }>();\n\tlet estimates: { offsetMs: number; intervalMs: number; at: number }[] = [];\n\tconst cursor = createServerCursor();\n\tlet build: string | null = null;\n\n\t/**\n\t * A batch's `now` was read before it was sent, so `now − receivedAt` falls short of the true\n\t * offset by its transit time: the largest recent estimate is the closest, and their spread,\n\t * plus a scan, bounds how far off it may be.\n\t */\n\tconst clock = (): Session[\"clock\"] => {\n\t\tif (!estimates.length) {\n\t\t\treturn null;\n\t\t}\n\t\tconst offsets = estimates.map(({ offsetMs }) => offsetMs);\n\t\tconst best = estimates.reduce((best, estimate) =>\n\t\t\testimate.offsetMs > best.offsetMs ? estimate : best,\n\t\t);\n\t\treturn {\n\t\t\toffsetMs: best.offsetMs,\n\t\t\tuncertaintyMs: best.offsetMs - Math.min(...offsets) + best.intervalMs,\n\t\t};\n\t};\n\n\tconst observe = (batch: TelemetryBatch, receivedAt: number) => {\n\t\tconst rate = rates.get(batch.task);\n\t\t// The PLC's clock went back, by a restart or its wrap, so earlier offsets don't compare.\n\t\tif (rate !== undefined && batch.now < rate.now) {\n\t\t\testimates = [];\n\t\t}\n\t\testimates = estimates.filter(({ at }) => receivedAt - at < clockWindowMs);\n\t\testimates.push({\n\t\t\toffsetMs: batch.now - receivedAt,\n\t\t\tintervalMs: intervals.get(batch.task) ?? 0,\n\t\t\tat: receivedAt,\n\t\t});\n\t\tconst stats = {\n\t\t\tname: batch.task,\n\t\t\tscansPerSecond: tasks.get(batch.task)?.scansPerSecond ?? null,\n\t\t\tscan: batch.scan,\n\t\t\tdropped: batch.dropped,\n\t\t};\n\t\t// A restarted PLC counts scans from zero again. Its clock is a UDINT, so it wraps.\n\t\tconst restarted = !rate || batch.scan < rate.scan;\n\t\tconst elapsedMs = rate ? (batch.now - rate.now) >>> 0 : 0;\n\t\tif (restarted) {\n\t\t\trates.set(batch.task, { scan: batch.scan, now: batch.now });\n\t\t} else if (elapsedMs >= 1000) {\n\t\t\tstats.scansPerSecond = ((batch.scan - rate.scan) * 1000) / elapsedMs;\n\t\t\trates.set(batch.task, { scan: batch.scan, now: batch.now });\n\t\t}\n\t\ttasks.set(batch.task, stats);\n\t};\n\n\treturn {\n\t\t/** Where the next pull starts. */\n\t\tsince: cursor.newest,\n\t\t/** Takes a reply to `GET /tsplc/telemetry?since=<since()>`; a restarted server starts over. */\n\t\taccept: (reply: TelemetryReply): ReceivedRecord[] => {\n\t\t\tif (!cursor.continues(reply.latest)) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst received: ReceivedRecord[] = [];\n\t\t\tfor (const batch of reply.batches) {\n\t\t\t\tif (batch.seq <= cursor.newest()) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tcursor.take(batch.seq);\n\t\t\t\tbuild = batch.build;\n\t\t\t\tconst receivedAt = new Date(batch.receivedAt);\n\t\t\t\tobserve(batch, receivedAt.getTime());\n\t\t\t\tbatch.records.forEach((record, index) => {\n\t\t\t\t\treceived.push({\n\t\t\t\t\t\tbuild: batch.build,\n\t\t\t\t\t\ttask: batch.task,\n\t\t\t\t\t\tsequence: batch.first + index,\n\t\t\t\t\t\tat: recordedAt(batch, record, receivedAt).toISOString(),\n\t\t\t\t\t\trecord,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn received;\n\t\t},\n\t\t/** The build the newest batch came from. */\n\t\tbuild: () => build,\n\t\tclock,\n\t\ttasks: () => [...tasks.values()].map((task) => ({ ...task })),\n\t};\n};\n",
|
|
29
|
+
"import type { TelemetryRecord } from \"@tsplc/server/telemetry\";\nimport type { TraceEvent } from \"./api\";\nimport type { DebugJob, DebugManifest } from \"./manifest\";\nimport type { Paths } from \"./paths\";\nimport type { ReceivedRecord } from \"./telemetry\";\n\nexport type TraceRecord = Extract<TelemetryRecord, { kind: \"trace\" }>;\n\nexport type ReceivedTrace = Omit<ReceivedRecord, \"record\"> & {\n\trecord: TraceRecord;\n};\n\n/**\n * Decodes the opt-in trace through the manifest's event sites (docs/03-guides/debugging.md). Records\n * of another build decode to nothing: its site ids mean other code.\n */\nexport const createTraceDecoder = (manifest: DebugManifest, paths: Paths) => {\n\tconst sites = new Map(manifest.events.map((site) => [site.id, site]));\n\tconst jobs = new Map(manifest.jobs.map((job) => [job.id, job]));\n\tconst jobSites = new Map(\n\t\tmanifest.events.flatMap(({ id, job: jobId, phase }) => {\n\t\t\tconst job = jobId === undefined ? undefined : jobs.get(jobId);\n\t\t\treturn job && phase\n\t\t\t\t? [[id, { job, started: phase === \"started\" }] as const]\n\t\t\t\t: [];\n\t\t}),\n\t);\n\tconst ours = ({ build, record }: ReceivedTrace) =>\n\t\tbuild === manifest.build.id ? record : undefined;\n\n\treturn {\n\t\tdecode: (received: ReceivedTrace): TraceEvent | undefined => {\n\t\t\tconst record = ours(received);\n\t\t\tconst site = record && sites.get(record.site);\n\t\t\tif (!record || !site) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst { task, sequence } = received;\n\t\t\treturn {\n\t\t\t\tsequence,\n\t\t\t\ttask,\n\t\t\t\tscan: record.scan,\n\t\t\t\tplcTime: record.time,\n\t\t\t\tsite: site.id,\n\t\t\t\tvalue: paths.decode(site.type, record.value),\n\t\t\t\toperands: site.operands.map(({ text, path, stable, type }, index) => ({\n\t\t\t\t\ttext,\n\t\t\t\t\t...(path && { path }),\n\t\t\t\t\tstable,\n\t\t\t\t\tvalue: paths.decode(type, record.operands[index]),\n\t\t\t\t})),\n\t\t\t};\n\t\t},\n\t\t/** The job a record starts or finishes, if its site is a job's. */\n\t\tjob: (\n\t\t\treceived: ReceivedTrace,\n\t\t): { job: DebugJob; started: boolean } | undefined => {\n\t\t\tconst record = ours(received);\n\t\t\treturn record && jobSites.get(record.site);\n\t\t},\n\t};\n};\n",
|
|
30
|
+
"import { qualitySchema } from \"@tsplc/opcua/contract\";\nimport { serviceCall } from \"@tsplc/server/requests\";\nimport { type AppRecord, appRecord } from \"@tsplc/server/telemetry\";\nimport { z } from \"zod\";\nimport { explainFile, explainFlags } from \"./explain-file\";\nimport { debugIo, debugManifest, sourceRange } from \"./manifest\";\n\n/**\n * The debugger API's response shapes, shared by the host, the browser UI and the VS Code extension,\n * which validate what they receive against them. Routes are listed in `createDebugHandler` (http.ts);\n * streams are Server-Sent Events whose event names are the keys of `streamEventSchemas`.\n */\n\n/**\n * The header the debugger's and the agent dashboard's pages send on anything but `GET`. Another site\n * can make a browser send a cookie, but not a custom header, so the agent refuses a change signed in\n * by cookie, Tailscale or from its own PC without it.\n */\nexport const dashboardHeader = \"x-tsplc-dashboard\";\n\n/** The query parameter that carries a page's token to the API, since EventSource cannot send headers. */\nexport const tokenQueryParameter = \"token\";\n\n/** The body of every 4xx and 5xx reply. */\nexport const errorBodySchema = z.object({ error: z.string() });\nexport type ErrorBody = z.infer<typeof errorBodySchema>;\n\nexport { type Quality, qualitySchema } from \"@tsplc/opcua/contract\";\n\n/** One value as read. Values of different paths may come from different scans. */\nexport const sampleSchema = z.object({\n\tpath: z.string(),\n\tvalue: z.unknown(),\n\tquality: qualitySchema,\n\tstatus: z.string(),\n\t/** When the debugger host received it; the controller reports no time of its own. */\n\treceivedAt: z.string(),\n\t/** The controller read that returned it; samples with the same `read` were read together. */\n\tread: z.number().int().optional(),\n});\nexport type Sample = z.infer<typeof sampleSchema>;\n\n/** `unavailable`: nothing to read through, such as no engineering login open. */\nexport const connectionStateSchema = z.enum([\n\t\"connecting\",\n\t\"connected\",\n\t\"lost\",\n\t\"failed\",\n\t\"unavailable\",\n]);\nexport type ConnectionState = z.infer<typeof connectionStateSchema>;\n\nexport const sessionSchema = z.object({\n\tbuild: z.object({\n\t\tmanifest: z.string().nullable(),\n\t\tcontroller: z.string().nullable(),\n\t\tmatches: z.boolean(),\n\t}),\n\tconnection: z.object({\n\t\tstate: connectionStateSchema,\n\t\tsince: z.string(),\n\t\tendpoint: z.string(),\n\t\terror: z.string().optional(),\n\t}),\n\t/** How live values are read, such as \"engineering login\", and how often. */\n\treading: z.object({ method: z.string(), intervalMs: z.number() }),\n\t/** From the tasks' telemetry batches; `dropped` counts records overwritten before they were sent. */\n\ttasks: z.array(\n\t\tz.object({\n\t\t\tname: z.string(),\n\t\t\tscan: z.number().nullable(),\n\t\t\tscansPerSecond: z.number().nullable(),\n\t\t\tdropped: z.number(),\n\t\t}),\n\t),\n\t/** PLC clock minus the app server's clock, estimated from telemetry batches. */\n\tclock: z\n\t\t.object({ offsetMs: z.number(), uncertaintyMs: z.number() })\n\t\t.nullable(),\n\trelease: z\n\t\t.object({ id: z.string(), deployedAt: z.string(), operation: z.string() })\n\t\t.optional(),\n\t/** The project directory on the host, when served by `tsplc debug`. */\n\tprojectRoot: z.string().optional(),\n});\nexport type Session = z.infer<typeof sessionSchema>;\n\n/** A trace record, decoded through the manifest's event sites. */\nexport const traceEventSchema = z.object({\n\tsequence: z.number(),\n\ttask: z.string(),\n\tscan: z.number(),\n\tplcTime: z.number(),\n\tsite: z.number(),\n\tvalue: z.unknown(),\n\t/** The site's guard operands, in the site's order. */\n\toperands: z.array(\n\t\tz.object({\n\t\t\ttext: z.string(),\n\t\t\tpath: z.string().optional(),\n\t\t\tstable: z.boolean(),\n\t\t\tvalue: z.unknown(),\n\t\t}),\n\t),\n});\nexport type TraceEvent = z.infer<typeof traceEventSchema>;\n\nexport type { AppRecord };\n\n/** One PLC service call, as the app server traced it. */\nexport const requestTraceSchema = serviceCall;\nexport type RequestTrace = z.infer<typeof requestTraceSchema>;\n\n/**\n * A job as last seen. `busy` is null until it is known: from the trace's start and finish\n * records, or read through the login while a page shows the job. The rest is read only while it\n * is busy and shown.\n */\nexport const jobStateSchema = z.object({\n\tid: z.number(),\n\t/** Of the `busy` reading; a traced job's is good. */\n\tquality: qualitySchema,\n\tbusy: z.boolean().nullable(),\n\tcancelling: z.boolean().optional(),\n\tstep: z.number().optional(),\n\tcurrent: z\n\t\t.object({ kind: z.string(), range: sourceRange, text: z.string() })\n\t\t.optional(),\n\tstartedAt: z.string().optional(),\n\telapsedMs: z.number().optional(),\n\trequest: z\n\t\t.object({\n\t\t\tservice: z.string(),\n\t\t\tsequence: z.number(),\n\t\t\ttrace: requestTraceSchema.optional(),\n\t\t})\n\t\t.optional(),\n\t/** Busy, but over the number of jobs whose details are read on each poll. */\n\tunread: z.literal(true).optional(),\n\t/** The last failure nothing caught, from the program's `exception` records. */\n\tfailure: z\n\t\t.object({\n\t\t\tat: z.string(),\n\t\t\tcode: z.number(),\n\t\t\tname: z.string().optional(),\n\t\t\tsource: z.string(),\n\t\t})\n\t\t.optional(),\n});\nexport type JobState = z.infer<typeof jobStateSchema>;\n\n/** \"unknown\" unless the driver's own state was read. */\nexport const healthStateSchema = z.enum([\"unknown\", \"ok\", \"fault\", \"stale\"]);\nexport type HealthState = z.infer<typeof healthStateSchema>;\n\nexport const deviceStateSchema = z.object({\n\tid: z.string(),\n\thealth: z.object({\n\t\tstate: healthStateSchema,\n\t\tvalue: z.number().optional(),\n\t\tname: z.string().optional(),\n\t\tdiagnostic: z.boolean().optional(),\n\t\tmessage: z.string().optional(),\n\t\tquality: qualitySchema,\n\t}),\n\tassemblies: z.array(\n\t\tz.object({\n\t\t\tdirection: z.enum([\"input\", \"output\"]),\n\t\t\taddress: z.string().optional(),\n\t\t\tbytes: z.array(z.number()).nullable(),\n\t\t\tquality: qualitySchema,\n\t\t}),\n\t),\n\t/** Channels bound to TypeScript I/O paths, by channel id. */\n\tchannels: z.array(\n\t\tz.object({\n\t\t\tid: z.string(),\n\t\t\tpath: z.string(),\n\t\t\tvalue: z.unknown(),\n\t\t\tquality: qualitySchema,\n\t\t}),\n\t),\n\t/** The device's hand-configured status symbols, by label. */\n\tstatus: z.record(\n\t\tz.string(),\n\t\tz.object({ value: z.unknown(), quality: qualitySchema }),\n\t),\n});\nexport type DeviceState = z.infer<typeof deviceStateSchema>;\n\nexport const timelineSourceSchema = z.enum([\n\t\"plc\",\n\t\"server\",\n\t\"agent\",\n\t\"debugger\",\n]);\nexport type TimelineSource = z.infer<typeof timelineSourceSchema>;\n\nconst timelinePlacement = {\n\tat: z.string(),\n\t/** Placed through another clock (the PLC's, or the app server's), so its order is approximate. */\n\tapproximate: z.boolean(),\n\tsource: timelineSourceSchema,\n\t/**\n\t * Where a client resumes, with `GET /api/timeline?after=<cursor>` rather than `since`: entries\n\t * arrive late and are placed by `at`, so the timeline is in time order, not cursor order. A\n\t * client resumes from the cursor on the entry it received last. An entry that changes, such as\n\t * a call that ends, takes a new cursor and is served again. A host started since the cursor was\n\t * issued, such as by a deploy, answers it with its whole timeline.\n\t */\n\tcursor: z.string().optional(),\n};\n\n/** An entry of the \"Recent\" view: the server's recent window, merged with the agent's logs. */\nexport const timelineEntrySchema = z.discriminatedUnion(\"kind\", [\n\tz.object({\n\t\t...timelinePlacement,\n\t\tkind: z.literal(\"app\"),\n\t\ttask: z.string(),\n\t\tsequence: z.number(),\n\t\trecord: appRecord,\n\t}),\n\tz.object({\n\t\t...timelinePlacement,\n\t\tkind: z.literal(\"trace\"),\n\t\ttrace: traceEventSchema,\n\t}),\n\tz.object({\n\t\t...timelinePlacement,\n\t\tkind: z.literal(\"request\"),\n\t\trequest: requestTraceSchema,\n\t}),\n\tz.object({\n\t\t...timelinePlacement,\n\t\tkind: z.literal(\"deploy\"),\n\t\trelease: z.string(),\n\t\toperation: z.string(),\n\t\tbuild: z.string().optional(),\n\t\tuser: z.string().optional(),\n\t\thost: z.string().optional(),\n\t}),\n\tz.object({\n\t\t...timelinePlacement,\n\t\tkind: z.literal(\"audit\"),\n\t\t/** As typed after `tsplc`, such as `force` or `reset cold`. */\n\t\tcommand: z.string(),\n\t\t/** Expressions written or forced, with their values; unforced expressions map to \"\". */\n\t\tvalues: z.record(z.string(), z.string()),\n\t\t/** The values read just before a write or force. */\n\t\tprevious: z.record(z.string(), z.string()).optional(),\n\t\tuser: z.string().optional(),\n\t\thost: z.string().optional(),\n\t\trelease: z.string().optional(),\n\t\terror: z.string().optional(),\n\t}),\n\tz.object({\n\t\t...timelinePlacement,\n\t\tkind: z.literal(\"connection\"),\n\t\tstate: connectionStateSchema,\n\t\terror: z.string().optional(),\n\t}),\n]);\nexport type TimelineEntry = z.infer<typeof timelineEntrySchema>;\n\nexport const watchGroupsSchema = z.strictObject({\n\tgroups: z.record(z.string().nonempty(), z.array(z.string().nonempty())),\n});\nexport type WatchGroups = z.infer<typeof watchGroupsSchema>;\n\n/**\n * What a page shows, so the host reads only that: `watch` paths, `jobs` by id, the health of\n * `health` devices, and everything of `devices`. Stream query parameters, comma-separated.\n */\nexport interface Interest {\n\twatch: string[];\n\tjobs: number[];\n\thealth: string[];\n\tdevices: string[];\n\t/** Tasks whose PLC clock to read with the watched values, as `clockSample(task)` samples. */\n\tclocks: string[];\n\t/** `writers` entries whose last-writer slot to read with the watched values, as `slotSample(index)` samples. */\n\tslots: number[];\n}\n\n/**\n * The sample path of a task's PLC clock and of a last-writer slot. TypeScript paths never contain\n * a colon, so these can't name a variable.\n */\nexport const clockSample = (task: string) => `tsplc:clock/${task}`;\nexport const slotSample = (writer: number) => `tsplc:writer/${writer}`;\n\n/** A stream's query for `interest`: each non-empty list, deduplicated, sorted and comma-separated. */\nexport const interestQuery = (\n\tinterest: Partial<Interest>,\n): Record<string, string> =>\n\tObject.fromEntries(\n\t\tObject.entries(interest).flatMap(([name, values]) => {\n\t\t\tconst list = [...new Set(values.map(String))].sort().join(\",\");\n\t\t\treturn list ? [[name, list]] : [];\n\t\t}),\n\t);\n\n/** Each stream event's data, by event name. Clients ignore names not listed here. */\nexport const streamEventSchemas = {\n\tsession: sessionSchema,\n\tsample: sampleSchema,\n\tjob: jobStateSchema,\n\trequest: requestTraceSchema,\n\tdevice: deviceStateSchema,\n\ttimeline: timelineEntrySchema,\n};\nexport type StreamEvents = {\n\t[Name in keyof typeof streamEventSchemas]: z.infer<\n\t\t(typeof streamEventSchemas)[Name]\n\t>;\n};\n\ntype NamedStreamEvent<Name extends keyof StreamEvents> = {\n\t[Event in Name]: { name: Event; data: StreamEvents[Event] };\n}[Name];\nexport type StreamEvent = NamedStreamEvent<keyof StreamEvents>;\n\nconst isStreamEventName = (name: string): name is keyof StreamEvents =>\n\tObject.hasOwn(streamEventSchemas, name);\n\nconst decodeNamed = <Name extends keyof StreamEvents>(\n\tname: Name,\n\tdata: string,\n): NamedStreamEvent<Name> => {\n\t// Typed per event, so `schemas[name]` stays paired with `Name` rather than widening to every schema.\n\tconst schemas: {\n\t\t[Event in keyof StreamEvents]: z.ZodType<StreamEvents[Event]>;\n\t} = streamEventSchemas;\n\tconst parsed = schemas[name].safeParse(JSON.parse(data));\n\tif (!parsed.success) {\n\t\tthrow new Error(\n\t\t\t`The debugger sent a malformed ${name} event: ${z.prettifyError(parsed.error)}`,\n\t\t);\n\t}\n\treturn { name, data: parsed.data };\n};\n\n/**\n * Decodes one stream event's data, or returns undefined for an event this client doesn't know,\n * so a newer host's events are ignored. Data that doesn't match a known event's shape throws.\n */\nexport const decodeStreamEvent = (\n\tname: string,\n\tdata: string,\n): StreamEvent | undefined =>\n\tisStreamEventName(name) ? decodeNamed(name, data) : undefined;\n\n/** The statements that can write a path, with the chains of calls each runs through. */\nexport const explanationSchema = z.object({\n\tpath: z.string(),\n\ttype: z.string(),\n\twriters: z.array(\n\t\tz.object({\n\t\t\tassignment: z.number().int(),\n\t\t\t/** The path's index for each `[*]` of the writer's pattern. */\n\t\t\tindexes: z.array(z.number().int()),\n\t\t\tchains: z.array(\n\t\t\t\tz.object({\n\t\t\t\t\ttask: z.string(),\n\t\t\t\t\tentry: z.number().int(),\n\t\t\t\t\tcalls: z.array(z.number().int()),\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t),\n\tflags: explainFlags.omit({ path: true }),\n\tio: debugIo.nullable(),\n});\nexport type ExplanationResponse = z.infer<typeof explanationSchema>;\n\n/** The paths the controller forces, or null when the forced state isn't known, as of `at`. */\nexport const forcedSchema = z.object({\n\tforced: z.array(z.string()).nullable(),\n\tat: z.string(),\n});\nexport type Forced = z.infer<typeof forcedSchema>;\n\n/** Response bodies by route; errors are `errorBodySchema`. */\nexport const apiResponseSchemas = {\n\t\"GET /api/session\": sessionSchema,\n\t\"GET /api/manifest\": debugManifest,\n\t\"GET /api/values\": z.array(sampleSchema),\n\t\"GET /api/jobs\": z.array(jobStateSchema),\n\t\"GET /api/hardware\": z.array(deviceStateSchema),\n\t\"GET /api/timeline\": z.array(timelineEntrySchema),\n\t\"GET /api/watch\": watchGroupsSchema,\n\t\"PUT /api/watch\": watchGroupsSchema,\n\t\"GET /api/explain\": explanationSchema,\n\t\"GET /api/explain-file\": explainFile,\n\t\"GET /api/forced\": forcedSchema,\n};\nexport type ApiResponses = {\n\t[Route in keyof typeof apiResponseSchemas]: z.infer<\n\t\t(typeof apiResponseSchemas)[Route]\n\t>;\n};\n\nexport interface ServerSentEvent {\n\tevent: string;\n\tdata: string;\n}\n\n/**\n * Parses a `text/event-stream` body by the HTML field rules, with lines ended by CR, LF or CRLF.\n * Comments, `id` and `retry` are skipped.\n */\nexport async function* parseEventStream(\n\tchunks: AsyncIterable<string>,\n): AsyncGenerator<ServerSentEvent> {\n\tlet buffer = \"\";\n\tlet event = \"\";\n\tlet data: string[] = [];\n\tfor await (const chunk of chunks) {\n\t\tbuffer += chunk;\n\t\t// A trailing CR may be the first half of a CRLF split across chunks.\n\t\tconst end = buffer.endsWith(\"\\r\") ? buffer.length - 1 : buffer.length;\n\t\tconst lines = buffer.slice(0, end).split(/\\r\\n|\\r|\\n/);\n\t\tbuffer = lines.splice(-1).join(\"\") + buffer.slice(end);\n\t\tfor (const line of lines) {\n\t\t\tif (!line) {\n\t\t\t\tif (data.length) {\n\t\t\t\t\tyield { event: event || \"message\", data: data.join(\"\\n\") };\n\t\t\t\t}\n\t\t\t\tevent = \"\";\n\t\t\t\tdata = [];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (line.startsWith(\":\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst colon = line.indexOf(\":\");\n\t\t\tconst field = colon < 0 ? line : line.slice(0, colon);\n\t\t\tconst value = colon < 0 ? \"\" : line.slice(colon + 1).replace(/^ /, \"\");\n\t\t\tif (field === \"event\") {\n\t\t\t\tevent = value;\n\t\t\t} else if (field === \"data\") {\n\t\t\t\tdata.push(value);\n\t\t\t}\n\t\t}\n\t}\n}\n",
|
|
31
|
+
"import type { TargetAdapter, TargetRead, TargetSample } from \"./adapter\";\nimport { clockSample, type Sample, slotSample } from \"./api\";\nimport { DebugError } from \"./errors\";\nimport { type DebugManifest, scanClockType, writerSlotType } from \"./manifest\";\nimport type { Paths } from \"./paths\";\n\n/** A stored value to read: its sample's path, its target and its manifest type. */\ninterface Located {\n\tpath: string;\n\ttarget: string;\n\ttype: string;\n}\n\n/** Values by TypeScript path: read now, or watched each sampling interval. */\nexport const createValueReader = ({\n\tmanifest,\n\tpaths,\n\tadapter,\n}: {\n\tmanifest: DebugManifest;\n\tpaths: Paths;\n\tadapter: TargetAdapter;\n}) => {\n\tconst unavailable = (path: string, status: string): Sample => ({\n\t\tpath,\n\t\tvalue: null,\n\t\tquality: \"unavailable\",\n\t\tstatus,\n\t\treceivedAt: new Date().toISOString(),\n\t});\n\n\t/** A path's target, or the sample it has without reading the controller. */\n\tconst locate = (path: string): Located | Sample => {\n\t\tconst resolved = paths.resolve(path);\n\t\tif (!resolved) {\n\t\t\treturn unavailable(path, \"Unknown path\");\n\t\t}\n\t\tif (resolved.kind === \"constant\") {\n\t\t\treturn {\n\t\t\t\tpath,\n\t\t\t\tvalue: resolved.value,\n\t\t\t\tquality: \"good\",\n\t\t\t\tstatus: \"Constant\",\n\t\t\t\treceivedAt: new Date().toISOString(),\n\t\t\t};\n\t\t}\n\t\tif (!resolved.readable) {\n\t\t\treturn unavailable(path, \"Not readable\");\n\t\t}\n\t\treturn resolved;\n\t};\n\n\tconst targetRead = ({ target, type }: Located): TargetRead => ({\n\t\ttarget,\n\t\ttype: paths.typeOf(type),\n\t});\n\n\tconst sampleOf = ({ path, type }: Located, sample: TargetSample): Sample => ({\n\t\tpath,\n\t\t...sample,\n\t\tvalue: paths.decode(type, sample.value),\n\t});\n\n\t/** The clocks and last-writer slots asked for, as samples of their own paths. */\n\tconst rawTargets = (raw: {\n\t\tclocks: readonly string[];\n\t\tslots: readonly number[];\n\t}): Located[] => [\n\t\t...raw.clocks.flatMap((name) => {\n\t\t\tconst target = manifest.tasks.find((task) => task.name === name)?.clock;\n\t\t\treturn target\n\t\t\t\t? [{ path: clockSample(name), target, type: scanClockType }]\n\t\t\t\t: [];\n\t\t}),\n\t\t...raw.slots.flatMap((index) => {\n\t\t\tconst target = manifest.writers[index]?.target;\n\t\t\treturn target\n\t\t\t\t? [{ path: slotSample(index), target, type: writerSlotType }]\n\t\t\t\t: [];\n\t\t}),\n\t];\n\n\t/**\n\t * Reads the leaves `patterns` match each sampling interval, and the clocks and last-writer slots\n\t * asked for in the same read, until the returned function is called.\n\t */\n\tconst watch = (\n\t\tpatterns: readonly string[],\n\t\tlistener: (sample: Sample) => void,\n\t\traw: { clocks: readonly string[]; slots: readonly number[] },\n\t) => {\n\t\tconst watched = new Map<string, Located[]>();\n\t\tconst reads: TargetRead[] = [];\n\t\tconst add = (located: Located) => {\n\t\t\tif (!watched.has(located.target)) {\n\t\t\t\treads.push(targetRead(located));\n\t\t\t}\n\t\t\twatched.set(located.target, [\n\t\t\t\t...(watched.get(located.target) ?? []),\n\t\t\t\tlocated,\n\t\t\t]);\n\t\t};\n\t\tfor (const item of rawTargets(raw)) {\n\t\t\tadd(item);\n\t\t}\n\t\tconst unread: Sample[] = [];\n\t\tfor (const path of paths.expand(patterns)) {\n\t\t\tconst located = locate(path);\n\t\t\tif (\"target\" in located) {\n\t\t\t\tadd(located);\n\t\t\t} else {\n\t\t\t\tunread.push(located);\n\t\t\t\tlistener(located);\n\t\t\t}\n\t\t}\n\t\t// A sample that needs no read, such as a constant's, is as current as those read with it.\n\t\tconst repeat = unread.length\n\t\t\t? setInterval(() => {\n\t\t\t\t\tif (adapter.connection().state !== \"connected\") {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst receivedAt = new Date().toISOString();\n\t\t\t\t\tfor (const sample of unread) {\n\t\t\t\t\t\tlistener({ ...sample, receivedAt });\n\t\t\t\t\t}\n\t\t\t\t}, adapter.samplingMs)\n\t\t\t: undefined;\n\t\tconst stop = reads.length\n\t\t\t? adapter.subscribe(reads, (target, received) => {\n\t\t\t\t\tfor (const located of watched.get(target) ?? []) {\n\t\t\t\t\t\tlistener(sampleOf(located, received));\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t: () => {};\n\t\treturn () => {\n\t\t\tclearInterval(repeat);\n\t\t\tstop();\n\t\t};\n\t};\n\n\t/** Reads the leaves `patterns` match now; refused while the controller isn't connected. */\n\tconst read = async (patterns: readonly string[]) => {\n\t\tconst connection = adapter.connection();\n\t\tif (connection.state !== \"connected\") {\n\t\t\tthrow new DebugError(\n\t\t\t\tconnection.error ?? \"The controller is not connected\",\n\t\t\t\t503,\n\t\t\t);\n\t\t}\n\t\tconst located = paths\n\t\t\t.expand(patterns)\n\t\t\t.map((path) => ({ path, located: locate(path) }));\n\t\tconst samples = await adapter.read(\n\t\t\tlocated.flatMap(({ located }) =>\n\t\t\t\t\"target\" in located ? [targetRead(located)] : [],\n\t\t\t),\n\t\t);\n\t\treturn located.map(({ path, located }) => {\n\t\t\tif (!(\"target\" in located)) {\n\t\t\t\treturn located;\n\t\t\t}\n\t\t\tconst sample = samples.get(located.target);\n\t\t\treturn sample\n\t\t\t\t? sampleOf({ ...located, path }, sample)\n\t\t\t\t: unavailable(path, \"Not read\");\n\t\t});\n\t};\n\n\treturn { watch, read };\n};\n",
|
|
32
|
+
"import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { type WatchGroups, watchGroupsSchema } from \"./api\";\n\n/**\n * Watch groups: the config's `debug.watch`, then groups saved in `file`. Saving keeps only the\n * groups that differ from the config, so the config stays their source.\n */\nexport const loadWatchGroups = async (\n\tfile: string,\n\tconfigured: Record<string, string[]>,\n) => {\n\tlet saved = existsSync(file)\n\t\t? watchGroupsSchema.parse(JSON.parse(await readFile(file, \"utf8\"))).groups\n\t\t: {};\n\tconst groups = (): WatchGroups => ({ groups: { ...configured, ...saved } });\n\treturn {\n\t\tgroups,\n\t\tsave: async ({ groups: next }: WatchGroups) => {\n\t\t\tsaved = Object.fromEntries(\n\t\t\t\tObject.entries(next).filter(\n\t\t\t\t\t([name, paths]) => !isDeepStrictEqual(configured[name], paths),\n\t\t\t\t),\n\t\t\t);\n\t\t\tawait mkdir(dirname(file), { recursive: true });\n\t\t\tawait writeFile(file, JSON.stringify({ groups: saved }, null, 2));\n\t\t\treturn groups();\n\t\t},\n\t};\n};\n",
|
|
33
|
+
"import { z } from \"zod\";\nimport {\n\ttype ErrorBody,\n\ttype Interest,\n\ttype StreamEvent,\n\twatchGroupsSchema,\n} from \"./api\";\nimport type { Debugger } from \"./debugger\";\nimport { DebugError } from \"./errors\";\nimport { TooManyMatches } from \"./paths\";\nimport { isTimelineCursor, type TimelineQuery } from \"./timeline\";\nimport { loadUi } from \"./ui/index\";\n\n/** Comments keep proxies and Bun's idle timeout from closing a quiet stream. */\nconst heartbeatMs = 5000;\nconst encoder = new TextEncoder();\n\nconst json = (body: unknown, status = 200) =>\n\tResponse.json(body, { status, headers: { \"Cache-Control\": \"no-store\" } });\n\nconst failure = (error: string, status: number) =>\n\tjson({ error } satisfies ErrorBody, status);\n\nconst list = (value: string | null) =>\n\t(value ?? \"\")\n\t\t.split(\",\")\n\t\t.map((item) => item.trim())\n\t\t.filter(Boolean);\n\n/** What a stream's page shows, from its query. */\nconst interest = (search: URLSearchParams): Interest => {\n\tconst jobs = list(search.get(\"jobs\")).map(Number);\n\tif (!jobs.every(Number.isInteger)) {\n\t\tthrow new DebugError(\"jobs must be job ids\", 400);\n\t}\n\tconst slots = list(search.get(\"slots\")).map(Number);\n\tif (!slots.every(Number.isInteger)) {\n\t\tthrow new DebugError(\"slots must be writer indexes\", 400);\n\t}\n\treturn {\n\t\twatch: list(search.get(\"watch\")),\n\t\tjobs,\n\t\thealth: list(search.get(\"health\")),\n\t\tdevices: list(search.get(\"devices\")),\n\t\tclocks: list(search.get(\"clocks\")),\n\t\tslots,\n\t};\n};\n\n/** Where `GET /api/timeline` resumes, from its query. */\nconst timelineQuery = (search: URLSearchParams): TimelineQuery => {\n\tconst after = search.get(\"after\");\n\tif (after === null) {\n\t\tconst since = search.get(\"since\");\n\t\treturn since === null ? {} : { since };\n\t}\n\tif (!isTimelineCursor(after)) {\n\t\tthrow new DebugError(\"after must be a timeline cursor\", 400);\n\t}\n\treturn { after };\n};\n\n/** The path `GET /api/explain` explains, from its query. */\nconst explainedPath = (search: URLSearchParams) => {\n\tconst path = search.get(\"path\");\n\tif (!path) {\n\t\tthrow new DebugError(\"path must name the path to explain\", 400);\n\t}\n\treturn path;\n};\n\n/** Every stream event, plus samples of the watched paths and states of the shown jobs and devices. */\nconst stream = (\n\tdebug: Debugger,\n\t{ watch, clocks, slots, ...shown }: Interest,\n) => {\n\t// Refuse a watch that matches too much before the stream starts.\n\tdebug.paths.expand(watch);\n\tlet stop = () => {};\n\treturn new Response(\n\t\tnew ReadableStream<Uint8Array>({\n\t\t\tstart: (controller) => {\n\t\t\t\tlet open = true;\n\t\t\t\tconst write = (text: string) => {\n\t\t\t\t\tif (open) {\n\t\t\t\t\t\tcontroller.enqueue(encoder.encode(text));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst send = ({ name, data }: StreamEvent) =>\n\t\t\t\t\twrite(`event: ${name}\\ndata: ${JSON.stringify(data)}\\n\\n`);\n\t\t\t\tsend({ name: \"session\", data: debug.session() });\n\t\t\t\tconst unsubscribe = debug.subscribe(send);\n\t\t\t\tconst unwatch = debug.watch(\n\t\t\t\t\twatch,\n\t\t\t\t\t(sample) => send({ name: \"sample\", data: sample }),\n\t\t\t\t\t{ clocks, slots },\n\t\t\t\t);\n\t\t\t\tconst unshow = debug.show(shown);\n\t\t\t\tconst heartbeat = setInterval(\n\t\t\t\t\t() => write(\": keepalive\\n\\n\"),\n\t\t\t\t\theartbeatMs,\n\t\t\t\t);\n\t\t\t\tstop = () => {\n\t\t\t\t\topen = false;\n\t\t\t\t\tclearInterval(heartbeat);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tunwatch();\n\t\t\t\t\tunshow();\n\t\t\t\t};\n\t\t\t},\n\t\t\tcancel: () => stop(),\n\t\t}),\n\t\t{\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"text/event-stream\",\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t},\n\t);\n};\n\n/**\n * The debugger's routes, with `route` the request's path below where\n * the host mounts them. There is no route that writes to the controller; hosts authenticate.\n */\nexport const createDebugHandler =\n\t(debug: Debugger, log: (message: string) => void) =>\n\tasync (request: Request, route: string): Promise<Response> => {\n\t\tconst { searchParams } = new URL(request.url);\n\t\tconst key = `${request.method} ${route}`;\n\t\ttry {\n\t\t\tswitch (key) {\n\t\t\t\tcase \"GET /\":\n\t\t\t\t\treturn new Response((await loadUi()).html, {\n\t\t\t\t\t\theaders: { \"Content-Type\": \"text/html; charset=utf-8\" },\n\t\t\t\t\t});\n\t\t\t\tcase \"GET /ui.js\":\n\t\t\t\t\treturn new Response((await loadUi()).script, {\n\t\t\t\t\t\theaders: { \"Content-Type\": \"text/javascript; charset=utf-8\" },\n\t\t\t\t\t});\n\t\t\t\tcase \"GET /api/session\":\n\t\t\t\t\treturn json(debug.session());\n\t\t\t\tcase \"GET /api/manifest\":\n\t\t\t\t\treturn json(debug.manifest);\n\t\t\t\tcase \"GET /api/stream\":\n\t\t\t\t\treturn stream(debug, interest(searchParams));\n\t\t\t\tcase \"GET /api/values\":\n\t\t\t\t\treturn json(await debug.values(list(searchParams.get(\"paths\"))));\n\t\t\t\tcase \"GET /api/jobs\":\n\t\t\t\t\treturn json(debug.jobs());\n\t\t\t\tcase \"GET /api/hardware\":\n\t\t\t\t\treturn json(debug.hardware());\n\t\t\t\tcase \"GET /api/timeline\":\n\t\t\t\t\treturn json(debug.timeline(timelineQuery(searchParams)));\n\t\t\t\tcase \"GET /api/watch\":\n\t\t\t\t\treturn json(debug.watchGroups());\n\t\t\t\tcase \"GET /api/explain\":\n\t\t\t\t\treturn json(debug.explain(explainedPath(searchParams)));\n\t\t\t\tcase \"GET /api/explain-file\": {\n\t\t\t\t\tconst loaded = debug.explanationFile();\n\t\t\t\t\t// The digest names the content, so a client keeps the file until the build changes.\n\t\t\t\t\treturn new Response(loaded.text, {\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\t\tETag: `\"${loaded.sha256}\"`,\n\t\t\t\t\t\t\t\"Cache-Control\": \"private, max-age=31536000, immutable\",\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tcase \"GET /api/forced\":\n\t\t\t\t\treturn json(await debug.forced());\n\t\t\t\tcase \"PUT /api/watch\":\n\t\t\t\t\treturn json(\n\t\t\t\t\t\tawait debug.saveWatchGroups(\n\t\t\t\t\t\t\twatchGroupsSchema.parse(await request.json()),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t}\n\t\t\treturn failure(`No route ${key}`, 404);\n\t\t} catch (error) {\n\t\t\tif (error instanceof DebugError) {\n\t\t\t\treturn failure(error.message, error.status);\n\t\t\t}\n\t\t\t// SyntaxError: a body isn't JSON.\n\t\t\tif (error instanceof TooManyMatches || error instanceof SyntaxError) {\n\t\t\t\treturn failure(error.message, 400);\n\t\t\t}\n\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\treturn failure(z.prettifyError(error), 400);\n\t\t\t}\n\t\t\tlog(\n\t\t\t\t`${key} failed: ${error instanceof Error ? error.stack : String(error)}`,\n\t\t\t);\n\t\t\treturn failure(\"The debugger failed; see its log\", 500);\n\t\t}\n\t};\n\n/**\n * Serves the debugger on 127.0.0.1 without a token. Requests that name another host are refused,\n * so no website can reach it by rebinding a domain name to 127.0.0.1.\n */\nexport const serveDebugger = (\n\tdebug: Debugger,\n\toptions: { port: number; log: (message: string) => void },\n) => {\n\tconst handle = createDebugHandler(debug, options.log);\n\treturn Bun.serve({\n\t\thostname: \"127.0.0.1\",\n\t\tport: options.port,\n\t\tfetch: (request) => {\n\t\t\tconst host = request.headers.get(\"host\")?.replace(/:\\d+$/, \"\");\n\t\t\tif (host !== \"127.0.0.1\" && host !== \"localhost\") {\n\t\t\t\treturn failure(\"Use http://127.0.0.1 or http://localhost\", 403);\n\t\t\t}\n\t\t\treturn handle(request, new URL(request.url).pathname);\n\t\t},\n\t});\n};\n",
|
|
34
|
+
"import { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path\";\nimport { html } from \"./page\";\nimport { cacheSuccess } from \"./success-cache\";\n\nconst build = async () => {\n\tconst result = await Bun.build({\n\t\tentrypoints: [\n\t\t\tresolve(\n\t\t\t\tdirname(createRequire(import.meta.url).resolve(\"@tsplc/debug\")),\n\t\t\t\t\"../src/ui/main.ts\",\n\t\t\t),\n\t\t],\n\t\ttarget: \"browser\",\n\t\t// Workspace packages resolve to their sources, as they do for the host, so no build is needed first.\n\t\tconditions: [\"bun\"],\n\t\tminify: true,\n\t});\n\tconst [output] = result.outputs;\n\tif (!result.success || !output) {\n\t\tthrow new AggregateError(result.logs, \"Bundling the debugger UI failed\");\n\t}\n\treturn { html, script: await output.text() };\n};\n\n/** The browser UI: serve `html` at `GET /` and `script` at `GET /ui.js`. Bundled on first call, then kept once it succeeds. */\nexport const loadUi = cacheSuccess(build);\n",
|
|
35
|
+
"import type {\n\tAppRecord,\n\tConnectionState,\n\tHealthState,\n\tRequestTrace,\n\tTimelineSource,\n} from \"../api\";\nimport type { Verdict } from \"../explain\";\nimport type { JobStatus, ValueState } from \"./format\";\n\n/** A colour of the palette, by its custom property. */\ntype Tone =\n\t| \"live\"\n\t| \"uncertain\"\n\t| \"bad\"\n\t| \"stale\"\n\t| \"unavailable\"\n\t| \"constant\"\n\t| \"dim\"\n\t| \"link\"\n\t| \"accent\";\n\nconst hatch =\n\t\"repeating-linear-gradient(135deg,transparent 0 4px,var(--hatch) 4px 8px)\";\n\n/** `selector(value){declaration(tone)}` for each value of an enum, so none goes unstyled. */\nconst rules = <Value extends string>(\n\ttones: Record<Value, Tone>,\n\tselector: (value: string) => string,\n\tdeclaration: (tone: Tone) => string,\n) =>\n\tObject.entries<Tone>(tones)\n\t\t.map(([value, tone]) => `${selector(value)}{${declaration(tone)}}`)\n\t\t.join(\"\");\n\nconst connectionTones: Record<ConnectionState, Tone> = {\n\tconnecting: \"uncertain\",\n\tconnected: \"live\",\n\tlost: \"bad\",\n\tfailed: \"bad\",\n\tunavailable: \"uncertain\",\n};\n\nconst statusTones: Record<\n\tJobStatus | RequestTrace[\"status\"] | ConnectionState,\n\tTone\n> = {\n\t...connectionTones,\n\tbusy: \"uncertain\",\n\tpending: \"uncertain\",\n\tcancelling: \"uncertain\",\n\terror: \"bad\",\n\ttimeout: \"bad\",\n\tok: \"live\",\n\tidle: \"dim\",\n\tunknown: \"dim\",\n};\n\nconst sourceTones: Record<TimelineSource, Tone> = {\n\tplc: \"accent\",\n\tserver: \"link\",\n\tagent: \"constant\",\n\tdebugger: \"dim\",\n};\n\nconst levelTones: Record<Extract<AppRecord, { kind: \"log\" }>[\"level\"], Tone> = {\n\tinfo: \"link\",\n\twarn: \"uncertain\",\n\terror: \"bad\",\n};\n\nconst verdictTones: Record<Verdict[\"state\"], Tone> = {\n\truns: \"live\",\n\tblocked: \"dim\",\n\tunknown: \"uncertain\",\n\tcandidate: \"constant\",\n};\n\n/** How each value state marks a value and its meta; its colour is the custom property of its name. */\nconst valueStateStyles: Record<ValueState, { value: string; marker: string }> =\n\t{\n\t\tlive: { value: \"\", marker: \"●\" },\n\t\tuncertain: { value: \"text-decoration:underline dotted\", marker: \"◐\" },\n\t\tbad: { value: \"text-decoration:line-through\", marker: \"✕\" },\n\t\tstale: { value: `background:${hatch}`, marker: \"○\" },\n\t\tunavailable: { value: \"\", marker: \"–\" },\n\t\tconstant: { value: \"font-style:italic\", marker: \"◆\" },\n\t};\n\nconst healthStyles: Record<HealthState, string> = {\n\tok: \"color:var(--live);border-color:var(--live)\",\n\tfault: \"color:#fff;background:var(--bad);border-color:var(--bad)\",\n\tstale: `color:var(--stale);border-color:var(--stale);background:${hatch}`,\n\tunknown: \"color:var(--dim);border-color:var(--dim);border-style:dashed\",\n};\n\nconst color = (tone: Tone) => `color:var(--${tone})`;\n\nconst css = `\n:root{color-scheme:dark;\n--bg:#0c0e11;--grid:rgba(255,255,255,.025);--panel:#13161b;--panel-2:#191d23;--line:#262b33;--line-soft:#1d2128;\n--fg:#d8dce2;--dim:#7c848f;--accent:#f2a33a;--link:#79c0ff;\n--live:#5ee0a0;--uncertain:#f3c64a;--bad:#ff6b6b;--stale:#8a919b;--unavailable:#5a616b;--constant:#b8a2ff;\n--hatch:rgba(138,145,155,.16);\n--mono:\"JetBrains Mono\",\"Cascadia Mono\",\"IBM Plex Mono\",\"SF Mono\",Menlo,Consolas,monospace;\n--sans:\"IBM Plex Sans\",\"Segoe UI Variable Text\",\"Segoe UI\",\"Helvetica Neue\",sans-serif}\n@media (prefers-color-scheme:light){:root{color-scheme:light;\n--bg:#f3f1ec;--grid:rgba(0,0,0,.035);--panel:#fffefb;--panel-2:#f6f4ef;--line:#d8d3c8;--line-soft:#e7e3da;\n--fg:#1b1e22;--dim:#6a6e75;--accent:#b5650a;--link:#0a5bb0;\n--live:#0d8048;--uncertain:#9a6400;--bad:#c42525;--stale:#767b83;--unavailable:#a1a6ad;--constant:#6447cc;\n--hatch:rgba(118,123,131,.16)}}\n*{box-sizing:border-box}\nhtml,body{height:100%}\nbody{margin:0;font:13px/1.45 var(--sans);color:var(--fg);background:var(--bg);\nbackground-image:linear-gradient(var(--grid) 1px,transparent 1px),linear-gradient(90deg,var(--grid) 1px,transparent 1px);\nbackground-size:24px 24px;display:grid;grid-template-rows:auto minmax(0,1fr);font-variant-numeric:tabular-nums}\na{color:var(--link);text-decoration:none}a:hover{text-decoration:underline}\ncode,.mono,.path,.src{font-family:var(--mono);font-size:12px}\n.src,.nowrap,.grid td.num{white-space:nowrap}\ncode{color:var(--fg);background:var(--panel-2);border:1px solid var(--line-soft);border-radius:3px;padding:0 4px}\n.dim,.hint,.empty{color:var(--dim)}.hint{margin:4px 0 12px}.empty{margin:8px 0;font-style:italic}\n.err{color:var(--bad)}.num{text-align:right}\nbutton,input{font:inherit;color:inherit}\nbutton{background:var(--panel-2);border:1px solid var(--line);border-radius:4px;padding:3px 10px;cursor:pointer}\nbutton:hover{border-color:var(--dim)}button.primary{background:var(--accent);border-color:var(--accent);color:#16110a;font-weight:600}\nbutton:disabled{opacity:.5;cursor:default}\ninput{background:var(--panel);border:1px solid var(--line);border-radius:4px;padding:4px 8px}\ninput:focus,button:focus-visible,.vlist:focus-visible{outline:1px solid var(--accent);outline-offset:1px}\nh1{font:600 18px var(--sans);margin:0 0 12px;letter-spacing:-.01em}\nh2{font:600 10.5px var(--sans);text-transform:uppercase;letter-spacing:.14em;color:var(--dim);margin:0 0 10px}\nh2 a{color:inherit}h3{font:600 12px var(--sans);margin:14px 0 6px}\n\nheader{background:var(--panel);border-top:2px solid var(--accent);border-bottom:1px solid var(--line)}\n.bar{display:flex;align-items:stretch;gap:0;overflow-x:auto}\n.brand{display:flex;align-items:center;gap:6px;padding:8px 16px;border-right:1px solid var(--line);white-space:nowrap}\n.brand b{font:700 13px var(--mono);letter-spacing:.04em}.brand span{font:500 13px var(--mono);color:var(--accent)}\n.brand .ro{font:600 9.5px var(--sans);letter-spacing:.14em;text-transform:uppercase;color:var(--dim);border:1px solid var(--line);border-radius:3px;padding:1px 5px;margin-left:6px}\n.readouts{display:flex;flex:1}\n.readout{display:flex;flex-direction:column;justify-content:center;padding:6px 14px;border-right:1px solid var(--line-soft);white-space:nowrap}\n.readout .label{font:600 9px var(--sans);letter-spacing:.16em;text-transform:uppercase;color:var(--dim)}\n.readout .reading{font:12px var(--mono);display:flex;align-items:center;gap:8px}\n.build.match i{color:var(--live);font-style:normal}.build.mismatch{color:var(--bad)}.build.mismatch i{font-style:normal;font-weight:700}\n.task b{color:var(--fg);font-weight:600}\n.dot{width:8px;height:8px;border-radius:50%;display:inline-block;background:var(--unavailable)}\n${rules(\n\tconnectionTones,\n\t(state) => `.dot.c-${state}`,\n\t(tone) => `background:var(--${tone})`,\n)}\n.dot.c-connected{box-shadow:0 0 6px var(--live)}.dot.c-connecting{animation:pulse 1s infinite alternate}\n@keyframes pulse{to{opacity:.3}}\nnav{display:flex;gap:2px;padding:0 10px;border-top:1px solid var(--line-soft)}\nnav a{color:var(--dim);padding:7px 12px 6px;text-transform:capitalize;border-bottom:2px solid transparent;font-weight:500}\nnav a:hover{color:var(--fg);text-decoration:none}nav a.on{color:var(--fg);border-bottom-color:var(--accent)}\n.banner{padding:7px 16px;font-weight:600;display:flex;gap:12px;align-items:center}\n.banner.danger{background:var(--bad);color:#fff}\n.banner.warn{background:repeating-linear-gradient(135deg,var(--uncertain) 0 14px,color-mix(in srgb,var(--uncertain) 85%,#000) 14px 28px);color:#1b1404}\n.banner.error{background:var(--panel-2);color:var(--bad);border-top:1px solid var(--bad)}\n.banner button{margin-left:auto}\n\nmain{overflow:auto;min-height:0}\n.page{padding:16px 18px 28px;animation:enter .18s ease-out}\n@keyframes enter{from{opacity:0;transform:translateY(3px)}}\n.panel{background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:12px 14px}\n.toolbar{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:10px}\n.check{display:inline-flex;gap:5px;align-items:center;color:var(--dim);cursor:pointer}.check input{margin:0}\n.sep{margin-left:8px}.count{color:var(--dim);font:12px var(--mono);margin-left:auto}\n.tabs{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:10px;align-items:center}\n.tab{background:transparent}.tab.on{border-color:var(--accent);color:var(--fg)}\n.tab .n{color:var(--dim);margin-left:6px;font:11px var(--mono)}\n.tag{font:600 9.5px var(--sans);letter-spacing:.08em;text-transform:uppercase;color:var(--dim);border:1px solid var(--line);border-radius:3px;padding:0 4px;margin:0 4px}\ndl{display:grid;grid-template-columns:max-content 1fr;gap:3px 14px;margin:0}dt{color:var(--dim)}dd{margin:0;min-width:0;overflow-wrap:anywhere}\n.facts{margin-bottom:14px}.readings dd{display:flex;gap:8px;align-items:baseline}\n.crumbs{color:var(--dim);margin-bottom:4px}\n\ntable.grid{width:100%;border-collapse:collapse;background:var(--panel);border:1px solid var(--line);border-radius:6px}\n.grid th{font:600 9.5px var(--sans);letter-spacing:.14em;text-transform:uppercase;color:var(--dim);text-align:left;padding:7px 10px;border-bottom:1px solid var(--line);position:sticky;top:0;background:var(--panel)}\n.grid td{padding:6px 10px;border-bottom:1px solid var(--line-soft);vertical-align:top}\n.grid tr:last-child td{border-bottom:0}.link-row{cursor:pointer}.link-row:hover td{background:var(--panel-2)}\ntr.highlight td{background:color-mix(in srgb,var(--accent) 12%,transparent)}\n\n.value{font:12.5px var(--mono);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.meta{font:11px var(--mono);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.meta::before{display:inline-block;width:1.4ch}\n${Object.entries(valueStateStyles)\n\t.map(\n\t\t([state, { value, marker }]) =>\n\t\t\t`.s-${state}{color:var(--${state})}.value.s-${state}{${value}}.meta.s-${state}::before{content:\"${marker}\"}`,\n\t)\n\t.join(\"\\n\")}\n.s-group{color:var(--dim)}\n\n.variables{height:100%;display:flex;flex-direction:column;padding-bottom:12px}\n.search{flex:1;min-width:280px;max-width:640px;font-family:var(--mono);font-size:12.5px;padding:6px 10px}\n.split{flex:1;min-height:0;display:grid;grid-template-columns:minmax(0,1fr) 380px;gap:12px}\n.listwrap{display:flex;flex-direction:column;min-height:0;background:var(--panel);border:1px solid var(--line);border-radius:6px;overflow:hidden}\n.vlist{flex:1;overflow:auto;position:relative;outline:none}\n.vspacer{position:relative}.vwindow{position:absolute;left:0;right:0;top:0}\n.row{display:grid;grid-template-columns:minmax(220px,1fr) minmax(90px,15ch) 21ch 17ch 40px minmax(110px,19ch);gap:8px;align-items:center;height:26px;padding-right:10px;border-bottom:1px solid var(--line-soft);cursor:default}\n.row:hover{background:var(--panel-2)}.row.selected{background:color-mix(in srgb,var(--accent) 13%,transparent);box-shadow:inset 2px 0 0 var(--accent)}\n.row.head{font:600 9.5px var(--sans);letter-spacing:.14em;text-transform:uppercase;color:var(--dim);border-bottom:1px solid var(--line);padding-left:10px}\n.row.generated .name{opacity:.7}\n.name{font:12.5px var(--mono);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:flex;align-items:center}\n.name mark{background:color-mix(in srgb,var(--accent) 35%,transparent);color:inherit;border-radius:2px}\n.twisty{display:inline-grid;place-items:center;width:18px;height:18px;flex:none;padding:0;border:0;background:none;color:var(--dim);font-size:10px}\n.type{font:11.5px var(--mono);color:var(--dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.row .src{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:11px}\n.rec{padding:0;width:22px;height:18px;border:1px solid transparent;background:none;color:var(--line);font-size:11px}\n.rec:hover{color:var(--dim);border-color:var(--line)}.rec.on{color:var(--bad)}.rec.elsewhere{color:var(--dim)}\n.side{display:flex;flex-direction:column;gap:12px;overflow:auto;min-height:0}\n.detail-path{font-size:12.5px;overflow-wrap:anywhere;margin-bottom:8px;color:var(--fg)}\n.detail-value{display:flex;gap:12px;align-items:baseline;margin-bottom:10px;padding:8px 10px;background:var(--panel-2);border-radius:4px}\n.detail-value .value{font-size:20px}.detail .site{margin:3px 0}.detail button{margin-top:10px}\n.member{display:grid;grid-template-columns:minmax(0,1fr) auto auto 22px;gap:8px;align-items:center;padding:3px 0;border-bottom:1px solid var(--line-soft)}\n.member .path{font-size:11.5px}.remove{padding:0 5px;border:0;background:none;color:var(--dim)}\n.groups form input{width:110px;padding:2px 6px}\n\n.badge{display:inline-block;font:600 10.5px var(--mono);letter-spacing:.04em;padding:1px 7px;border-radius:3px;border:1px solid;text-transform:uppercase}\n${Object.entries(healthStyles)\n\t.map(([health, style]) => `.h-${health}{${style}}`)\n\t.join(\"\\n\")}\n.st{font:600 11px var(--mono);text-transform:lowercase}\n${rules(statusTones, (status) => `.st-${status}`, color)}\n.await code{white-space:pre-wrap}\n\n.overview{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;align-items:start}\n.overview .wide{grid-column:1/-1}\n.overview>*{animation:enter .25s ease-out backwards}.overview>:nth-child(2){animation-delay:.04s}.overview>:nth-child(3){animation-delay:.08s}.overview>:nth-child(4){animation-delay:.12s}\n.counts{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-bottom:10px}\n.count-box{border:1px solid;border-radius:5px;padding:6px 10px;display:flex;flex-direction:column}\n.count-box b{font:600 22px var(--mono)}.count-box span{font:600 9.5px var(--sans);letter-spacing:.14em;text-transform:uppercase}\n.count-box.h-fault{background:color-mix(in srgb,var(--bad) 12%,transparent);color:var(--bad)}\n.device-line{padding:3px 0}\n\n.assemblies{display:flex;flex-direction:column;gap:12px;margin-bottom:18px}\n.assembly h3{margin:0 0 10px}\n.bitgrid{display:grid;grid-template-columns:4ch repeat(8,52px) 4ch minmax(0,1fr);gap:3px;align-items:stretch}\n.bh{font:600 9.5px var(--mono);color:var(--dim);text-align:center;letter-spacing:.06em}.legend-head{text-align:left;padding-left:6px}\n.byte,.hex{font-size:11.5px;color:var(--dim);align-self:center}\n.bit{position:relative;height:34px;display:flex;flex-direction:column;align-items:center;justify-content:center;font:600 13px var(--mono);\nborder:1px dashed var(--line);border-radius:3px;color:var(--unavailable)}\n.bit small{font:9px var(--mono);color:var(--dim);max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:0 2px}\n.bit.mapped{border-style:solid;color:var(--dim);background:var(--panel-2)}\n.bit.on{color:var(--fg)}\n.bit.mapped.on{color:var(--live);background:color-mix(in srgb,var(--live) 16%,transparent);border-color:color-mix(in srgb,var(--live) 60%,transparent);box-shadow:0 0 8px color-mix(in srgb,var(--live) 25%,transparent)}\n.bit.none{color:var(--unavailable)}\n.q-stale .bit,.q-uncertain .bit,.q-bad .bit{background-image:${hatch}}\n.q-stale .bit.on,.q-bad .bit.on{color:var(--stale);box-shadow:none;border-color:var(--line)}\n.legend{display:flex;flex-wrap:wrap;gap:4px 12px;align-items:center;font-size:11.5px;padding-left:6px}\n.legend-item{display:inline-flex;gap:6px;align-items:baseline}.legend-item b{font:600 11px var(--mono)}\n.mapped-path{display:flex;flex-wrap:wrap;gap:4px 10px;align-items:baseline}\n\n.recent .entries{display:flex;flex-direction:column;background:var(--panel);border:1px solid var(--line);border-radius:6px}\n.entry{display:grid;grid-template-columns:14ch 9ch minmax(0,1fr);gap:10px;padding:7px 12px;border-bottom:1px solid var(--line-soft)}\n.overview .entry{padding:6px 0}\n.when{color:var(--dim);font-size:11.5px}.approx{color:var(--uncertain);margin-left:4px;cursor:help}\n.source{font:600 9.5px var(--sans);letter-spacing:.12em;text-transform:uppercase;padding-top:2px}\n${rules(sourceTones, (source) => `.src-${source}`, color)}\n.body>div{margin:1px 0}.val{font:600 12.5px var(--mono)}\n.chips{display:flex;flex-wrap:wrap;gap:5px;align-items:center;margin-top:3px}\n.chip{display:inline-flex;align-items:baseline;gap:3px;font:11.5px var(--mono);border:1px solid var(--line);border-radius:10px;padding:0 8px;background:var(--panel-2)}\n.chip.unstable{border-style:dashed}\n.why{display:grid;gap:12px;max-width:1100px}.why .trail{font:12px var(--mono);color:var(--dim)}\n.why-sentence{font-size:15px;margin:0}.why-writer .badge{margin-right:4px}\n.why-conditions{list-style:none;margin:8px 0 0;padding:0;display:grid;gap:4px}.why-conditions .mark{display:inline-block;width:1.4em}\n.v-runs{border-color:var(--live)}${rules(verdictTones, (state) => `.badge.v-${state}`, color)}\n.why-link{margin-left:10px;font:600 11px var(--sans)}\n${rules(\n\tlevelTones,\n\t(level) => `.tag.lvl-${level}`,\n\t(tone) => `color:var(--${tone});border-color:var(--${tone})`,\n)}\n.recent>button{margin-top:10px}\n\n.fatal{padding:40px;max-width:720px}.fatal h1{color:var(--bad)}\n@media (max-width:1100px){.split{grid-template-columns:minmax(0,1fr)}.side{max-height:40vh}.overview{grid-template-columns:minmax(0,1fr)}}\n`;\n\n/** The page shell; `./ui.js` builds everything from the API, so the same page works at `/` and under `/debug/`. */\nexport const html = `<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<title>tsPLC debug</title><link rel=\"icon\" href=\"data:,\">\n<script>if(!location.pathname.endsWith(\"/\"))location.replace(location.pathname+\"/\"+location.search+location.hash)</script>\n<style>${css}</style></head>\n<body><p class=\"empty\" style=\"padding:24px\">Loading the debugger…</p>\n<script type=\"module\" src=\"./ui.js\"></script></body></html>`;\n",
|
|
36
|
+
"/** `load`, run once and its result kept; a failed load is forgotten, so the next call tries again. */\nexport const cacheSuccess = <T>(load: () => Promise<T>) => {\n\tlet loaded: Promise<T> | undefined;\n\treturn () => {\n\t\tloaded ??= load().catch((error: unknown) => {\n\t\t\tloaded = undefined;\n\t\t\tthrow error;\n\t\t});\n\t\treturn loaded;\n\t};\n};\n",
|
|
37
|
+
"import { sleep } from \"@tsplc/opcua\";\nimport type {\n\tConnection,\n\tTargetAdapter,\n\tTargetRead,\n\tTargetSample,\n} from \"./adapter\";\nimport type { DebuggerOptions } from \"./debugger\";\nimport { errorMessage } from \"./errors\";\nimport { parseLoginValue } from \"./login-value\";\nimport type { DebugManifest, DebugType } from \"./manifest\";\n\n/** Why the login can't read now; `state` is what the debugger shows meanwhile. */\nexport class LoginUnavailable extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\toptions?: ErrorOptions & { state?: \"connecting\" | \"unavailable\" },\n\t) {\n\t\tsuper(message, options);\n\t\tthis.state = options?.state ?? \"unavailable\";\n\t}\n\n\treadonly state: \"connecting\" | \"unavailable\";\n}\n\nexport const noLogin =\n\t\"Live values need an engineering login: run `tsplc login`.\";\n\n/** How long to wait between attempts while there is no login to read through. */\nconst retryMs = 5000;\n/** A read still unanswered after this many sampling intervals means the login stopped answering. */\nconst stalledIntervals = 3;\n/** Timers fire a little early or late; a subscription due within this part of an interval is read now. */\nconst dueTolerance = 0.5;\n\n/** The login's text for each expression it returned, and the call that returned it. */\ntype Texts = Record<string, { text: string; read: number }>;\n\nconst typeName = (type: DebugType) =>\n\ttype.kind === \"scalar\" ? type.iec : type.kind;\n\n/**\n * Reads through an engineering login that answers `read(expressions)` with CODESYS's own text\n * for each value: no publication is needed, and nothing is subscribed. Watched targets are polled\n * every `samplingMs`, one command per poll, and a poll that overruns delays the next by as long.\n *\n * A read fails as a whole when one expression can't be read, so a failing read is retried with\n * `probe` alone: if that fails too the login is lost; otherwise the read is split until the\n * expressions that fail are found, and those are reported bad until the next login.\n */\nexport const createLoginAdapter = (options: {\n\tread: (expressions: string[]) => Promise<Record<string, string>>;\n\t/** A target that always reads, such as the build id. */\n\tprobe: string;\n\tendpoint: string;\n\tsamplingMs?: number;\n}): TargetAdapter => {\n\tconst samplingMs = options.samplingMs ?? 1000;\n\tlet connection: Connection = {\n\t\tstate: \"connecting\",\n\t\tsince: new Date().toISOString(),\n\t};\n\tconst connectionListeners = new Set<(connection: Connection) => void>();\n\tconst subscriptions = new Set<{\n\t\ttargets: readonly TargetRead[];\n\t\tlistener: (target: string, sample: TargetSample) => void;\n\t\tintervalMs: number;\n\t\tdue: number;\n\t}>();\n\t/** Expressions the controller refused, with its reason, until the login is lost. */\n\tconst rejected = new Map<string, string>();\n\tconst controller = new AbortController();\n\n\tconst setConnection = (state: Connection[\"state\"], error?: string) => {\n\t\tif (controller.signal.aborted) {\n\t\t\treturn;\n\t\t}\n\t\tif (connection.state === state && connection.error === error) {\n\t\t\treturn;\n\t\t}\n\t\tif (state !== \"connected\") {\n\t\t\trejected.clear();\n\t\t}\n\t\tconnection = {\n\t\t\tstate,\n\t\t\tsince: new Date().toISOString(),\n\t\t\t...(error && { error }),\n\t\t};\n\t\tfor (const listener of connectionListeners) {\n\t\t\tlistener(connection);\n\t\t}\n\t};\n\n\t/** Each `read_values` call's own sequence, so a read split into several calls is never taken as one. */\n\tlet reads = 0;\n\tconst readCall = async (expressions: string[]): Promise<Texts> => {\n\t\tconst texts = await options.read(expressions);\n\t\treads += 1;\n\t\tconst read = reads;\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(texts).map(([target, text]) => [target, { text, read }]),\n\t\t);\n\t};\n\n\tconst split = async (expressions: string[]): Promise<Texts> => {\n\t\ttry {\n\t\t\treturn await readCall(expressions);\n\t\t} catch (error) {\n\t\t\tif (error instanceof LoginUnavailable) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst [only, ...others] = expressions;\n\t\t\tif (only !== undefined && !others.length) {\n\t\t\t\trejected.set(only, errorMessage(error));\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst half = Math.ceil(expressions.length / 2);\n\t\t\treturn {\n\t\t\t\t...(await split(expressions.slice(0, half))),\n\t\t\t\t...(await split(expressions.slice(half))),\n\t\t\t};\n\t\t}\n\t};\n\n\tconst readText = async (expressions: string[]): Promise<Texts> => {\n\t\ttry {\n\t\t\treturn await readCall(expressions);\n\t\t} catch (error) {\n\t\t\tif (error instanceof LoginUnavailable) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\t// One expression the controller can't read fails the whole read; a lost login fails the probe too.\n\t\t\tawait options.read([options.probe]);\n\t\t\treturn split(expressions);\n\t\t}\n\t};\n\n\t/** The login's text for each expression, or why it can't read; keeps `connection` current. */\n\tconst readTexts = async (\n\t\texpressions: string[],\n\t): Promise<{ texts: Texts } | { error: string }> => {\n\t\tconst overdue = setTimeout(\n\t\t\t() => setConnection(\"lost\", \"The engineering login stopped answering\"),\n\t\t\tstalledIntervals * samplingMs,\n\t\t);\n\t\ttry {\n\t\t\tconst texts = expressions.length ? await readText(expressions) : {};\n\t\t\tsetConnection(\"connected\");\n\t\t\treturn { texts };\n\t\t} catch (error) {\n\t\t\tsetConnection(\n\t\t\t\terror instanceof LoginUnavailable ? error.state : \"lost\",\n\t\t\t\terrorMessage(error),\n\t\t\t);\n\t\t\treturn { error: errorMessage(error) };\n\t\t} finally {\n\t\t\tclearTimeout(overdue);\n\t\t}\n\t};\n\n\t/** A target's value from the login's text, or bad with the reason it has none. */\n\tconst parsedSample = (\n\t\t{ target, type }: TargetRead,\n\t\treturned: Texts[string] | undefined,\n\t\treceivedAt: string,\n\t): TargetSample => {\n\t\tconst text = returned?.text;\n\t\tconst value = text === undefined ? undefined : parseLoginValue(type, text);\n\t\tif (value !== undefined && returned) {\n\t\t\treturn {\n\t\t\t\tvalue,\n\t\t\t\tquality: \"good\",\n\t\t\t\tstatus: \"Good\",\n\t\t\t\treceivedAt,\n\t\t\t\tread: returned.read,\n\t\t\t};\n\t\t}\n\t\tconst reason =\n\t\t\ttext === undefined\n\t\t\t\t? \"Not returned by the login\"\n\t\t\t\t: `Not a ${typeName(type)}`;\n\t\treturn {\n\t\t\tvalue: text ?? null,\n\t\t\tquality: \"bad\",\n\t\t\tstatus: rejected.get(target) ?? reason,\n\t\t\treceivedAt,\n\t\t};\n\t};\n\n\t/** Never fails: while the login can't read, every target is unavailable. */\n\tconst read = async (targets: readonly TargetRead[]) => {\n\t\tconst unique = [\n\t\t\t...new Map(targets.map((target) => [target.target, target])).values(),\n\t\t];\n\t\tconst result = await readTexts(\n\t\t\tunique\n\t\t\t\t.map(({ target }) => target)\n\t\t\t\t.filter((target) => !rejected.has(target)),\n\t\t);\n\t\tconst receivedAt = new Date().toISOString();\n\t\tif (\"error\" in result) {\n\t\t\treturn new Map<string, TargetSample>(\n\t\t\t\tunique.map(({ target }) => [\n\t\t\t\t\ttarget,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\tquality: \"unavailable\",\n\t\t\t\t\t\tstatus: result.error,\n\t\t\t\t\t\treceivedAt,\n\t\t\t\t\t},\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\t\treturn new Map(\n\t\t\tunique.map((read) => [\n\t\t\t\tread.target,\n\t\t\t\tparsedSample(read, result.texts[read.target], receivedAt),\n\t\t\t]),\n\t\t);\n\t};\n\n\t/** Until the next poll: the rest of the interval, as long again after an overrun, longer without a login. */\n\tconst pauseAfter = (tookMs: number) => {\n\t\tif (connection.state !== \"connected\" && connection.state !== \"connecting\") {\n\t\t\treturn retryMs;\n\t\t}\n\t\treturn tookMs > samplingMs ? tookMs : samplingMs - tookMs;\n\t};\n\n\tconst poll = async () => {\n\t\twhile (!controller.signal.aborted) {\n\t\t\tconst started = Date.now();\n\t\t\tconst due = [...subscriptions].filter(\n\t\t\t\t({ due }) => due <= started + samplingMs * dueTolerance,\n\t\t\t);\n\t\t\tif (due.length) {\n\t\t\t\tfor (const subscription of due) {\n\t\t\t\t\tsubscription.due = started + subscription.intervalMs;\n\t\t\t\t}\n\t\t\t\t// Closing the debugger must not wait for an engineering worker that stopped answering.\n\t\t\t\tconst stopped = Promise.withResolvers<void>();\n\t\t\t\tconst stop = () => stopped.resolve();\n\t\t\t\tcontroller.signal.addEventListener(\"abort\", stop, { once: true });\n\t\t\t\tconst samples = await Promise.race([\n\t\t\t\t\tread(due.flatMap(({ targets }) => targets)),\n\t\t\t\t\tstopped.promise,\n\t\t\t\t]).finally(() => controller.signal.removeEventListener(\"abort\", stop));\n\t\t\t\tif (!samples || controller.signal.aborted) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfor (const subscription of due) {\n\t\t\t\t\tif (subscriptions.has(subscription)) {\n\t\t\t\t\t\tfor (const { target } of subscription.targets) {\n\t\t\t\t\t\t\tconst sample = samples.get(target);\n\t\t\t\t\t\t\tif (sample) {\n\t\t\t\t\t\t\t\tsubscription.listener(target, sample);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait sleep(pauseAfter(Date.now() - started), controller.signal);\n\t\t}\n\t};\n\tconst running = poll();\n\n\treturn {\n\t\tmethod: \"engineering login\",\n\t\tendpoint: options.endpoint,\n\t\tsamplingMs,\n\t\tconnection: () => connection,\n\t\tonConnection: (listener) => {\n\t\t\tconnectionListeners.add(listener);\n\t\t\treturn () => connectionListeners.delete(listener);\n\t\t},\n\t\tread,\n\t\tsubscribe: (targets, listener, intervalMs = samplingMs) => {\n\t\t\tconst subscription = { targets, listener, intervalMs, due: 0 };\n\t\t\tsubscriptions.add(subscription);\n\t\t\treturn () => subscriptions.delete(subscription);\n\t\t},\n\t\tclose: async () => {\n\t\t\tcontroller.abort();\n\t\t\tsubscriptions.clear();\n\t\t\tconnectionListeners.clear();\n\t\t\tawait running;\n\t\t},\n\t};\n};\n\n/**\n * The controller of a debugger that reads through an engineering login: a login adapter that\n * probes the manifest's build id, and the forced expressions the login reports.\n */\nexport const loginReader = (\n\tmanifest: DebugManifest,\n\tlogin: {\n\t\tread: (expressions: string[]) => Promise<Record<string, string>>;\n\t\t/** The login's state, with the expressions the controller forces, or why it can't report them. */\n\t\tstatus: () => Promise<\n\t\t\t{ forced: readonly string[] } | { error: string } | null\n\t\t>;\n\t\tendpoint: string;\n\t},\n): Pick<DebuggerOptions, \"adapter\" | \"forced\"> => ({\n\tadapter: createLoginAdapter({\n\t\tread: login.read,\n\t\tprobe: manifest.build.target,\n\t\tendpoint: login.endpoint,\n\t}),\n\tforced: async () => {\n\t\tconst status = await login.status();\n\t\treturn status && \"forced\" in status ? status.forced : null;\n\t},\n});\n",
|
|
38
|
+
"import {\n\telementaryType,\n\tisIntegerValued,\n\tmillisecondsPerDay,\n\tnanosecondsPerMillisecond,\n\tsecondsPerDay,\n\tstringType,\n} from \"@tsplc/iec\";\nimport {\n\tintegerLiteral,\n\ttemporalPrefixes,\n\tunescapeString,\n} from \"@tsplc/iec/st\";\nimport { encodeConstant } from \"./constant\";\nimport type { DebugType } from \"./manifest\";\n\n/** CODESYS's `TRUE`/`FALSE`, and the digits a BOOL may also read as. */\nconst booleans: Record<string, boolean> = {\n\tTRUE: true,\n\tFALSE: false,\n\t\"1\": true,\n\t\"0\": false,\n};\n\nconst millisecondsPerSecond = Number(millisecondsPerDay / secondsPerDay);\n\nconst timeUnits: Record<string, number> = {\n\td: Number(millisecondsPerDay),\n\th: 3600 * millisecondsPerSecond,\n\tm: 60 * millisecondsPerSecond,\n\ts: millisecondsPerSecond,\n\tms: 1,\n\tus: 0.001,\n\tns: 1 / Number(nanosecondsPerMillisecond),\n};\n\nconst durationPrefixes = [...temporalPrefixes]\n\t.flatMap(([prefix, type]) => (type.family === \"duration\" ? [prefix] : []))\n\t.join(\"|\");\nconst durationLiteral = new RegExp(`^(?:${durationPrefixes})#(-?)(.+)$`, \"i\");\n\n/** A typed literal's type, as in `INT#5`, but not a duration's own prefix. */\nconst typePrefix = new RegExp(\n\t`^(?!(?:${durationPrefixes})#)[a-z_]+#(?=.)`,\n\t\"i\",\n);\n\nconst withoutTypePrefix = (text: string) => text.replace(typePrefix, \"\");\n\n/** An integer literal, as the debugger decodes integers. */\nconst integer = (text: string) => {\n\tconst value = integerLiteral(text);\n\treturn value === undefined\n\t\t? undefined\n\t\t: encodeConstant({ kind: \"integer\", value });\n};\n\nconst real = (text: string) => {\n\tconst number = Number(text);\n\treturn text !== \"\" && !Number.isNaN(number) ? number : undefined;\n};\n\n/** `T#1h2m3s4ms`, `TIME#-1.5s`, `LTIME#5us`, in milliseconds. */\nconst duration = (text: string) => {\n\tconst [, sign, body] = durationLiteral.exec(text) ?? [];\n\tif (body === undefined) {\n\t\treturn undefined;\n\t}\n\tconst units = body.replaceAll(\"_\", \"\");\n\tconst parts = [...units.matchAll(/(\\d+(?:\\.\\d+)?)(ms|us|ns|d|h|m|s)/gi)];\n\tif (parts.map(([part]) => part).join(\"\") !== units) {\n\t\treturn undefined;\n\t}\n\tconst ms = parts.reduce<number | undefined>((total, [, amount, unit]) => {\n\t\tconst factor =\n\t\t\tunit === undefined ? undefined : timeUnits[unit.toLowerCase()];\n\t\treturn total === undefined || factor === undefined\n\t\t\t? undefined\n\t\t\t: total + Number(amount) * factor;\n\t}, 0);\n\treturn ms !== undefined && sign ? -ms : ms;\n};\n\n/** `'it$'s'` or `\"wide\"`, with IEC's `$` escapes. */\nconst quoted = (text: string, wide: boolean) => {\n\tconst [, , body] = /^(['\"])(.*)\\1$/s.exec(text) ?? [];\n\treturn body === undefined ? undefined : unescapeString(body, { wide });\n};\n\n/** A member's number, or the name the login gave when the manifest doesn't list it. */\nconst enumValue = (\n\ttype: Extract<DebugType, { kind: \"enum\" }>,\n\ttext: string,\n) => {\n\tconst number = integer(text);\n\tif (typeof number === \"number\") {\n\t\treturn number;\n\t}\n\t// `E_Bin.Present`, `Present`, or a member the manifest lacks with its number: `Missing (7)`.\n\tconst [, name, value] =\n\t\t/^(?:\\w+\\.)*(\\w+)(?:\\s*\\((-?\\d+)\\))?$/.exec(text) ?? [];\n\tif (name === undefined) {\n\t\treturn undefined;\n\t}\n\treturn type.members[name] ?? (value === undefined ? name : Number(value));\n};\n\n/** Only raw assembly bytes are read whole; their elements are scalars named by IEC type. */\nconst arrayValue = (\n\ttype: Extract<DebugType, { kind: \"array\" }>,\n\ttext: string,\n) => {\n\tconst items = text.replace(/^\\[/, \"\").replace(/\\]$/, \"\").trim();\n\tif (!items) {\n\t\treturn [];\n\t}\n\tconst values = items\n\t\t.split(/\\s*,\\s*/)\n\t\t.map((item) => scalarValue(type.element, item));\n\treturn values.length === type.length &&\n\t\tvalues.every((value) => value !== undefined)\n\t\t? values\n\t\t: undefined;\n};\n\nconst scalarValue = (iec: string, text: string): unknown => {\n\tconst untyped = withoutTypePrefix(text);\n\tconst name = iec.toUpperCase();\n\tconst type = elementaryType(name);\n\tif (isIntegerValued(type)) {\n\t\treturn integer(untyped);\n\t}\n\tswitch (type?.family) {\n\t\tcase \"bool\":\n\t\t\treturn booleans[untyped.toUpperCase()];\n\t\tcase \"real\":\n\t\t\treturn real(untyped);\n\t\tcase \"duration\":\n\t\t\treturn duration(text);\n\t\tcase \"string\":\n\t\t\treturn quoted(text, name === \"WSTRING\") ?? text;\n\t}\n\tconst sized = stringType(name);\n\treturn sized ? (quoted(text, sized.wide) ?? text) : text;\n};\n\n/**\n * A value as `read_value` returns it, in the form the debugger decodes: BOOL as a boolean,\n * numbers and TIME (in ms) as numbers, enums as their member's number (or its name when the\n * manifest doesn't list it), STRING unquoted, and arrays read whole as arrays. Undefined when the\n * text doesn't fit the type.\n */\nexport const parseLoginValue = (type: DebugType, text: string): unknown => {\n\tconst trimmed = text.trim();\n\tswitch (type.kind) {\n\t\tcase \"enum\":\n\t\t\treturn enumValue(type, withoutTypePrefix(trimmed));\n\t\tcase \"array\":\n\t\t\treturn arrayValue(type, withoutTypePrefix(trimmed));\n\t\tcase \"record\":\n\t\t\treturn undefined;\n\t\tcase \"scalar\":\n\t\t\treturn scalarValue(type.iec, trimmed);\n\t}\n};\n",
|
|
39
|
+
"import type { Environment, ResolvedTsplcConfig } from \"@tsplc/config\";\nimport {\n\tcreateMonitor,\n\ttype MonitorOptions,\n\tmonitorConnection,\n\tmonitorPassword,\n\ttype Reading,\n} from \"@tsplc/opcua\";\nimport type { TargetAdapter, TargetRead, TargetSample } from \"./adapter\";\n\n/** The config's `monitor` connection, with the user's password from `passwordEnv` in `env`. */\nexport const opcUaConnection = (\n\tmonitor: NonNullable<ResolvedTsplcConfig[\"monitor\"]>,\n\toptions: { root: string; env: Environment },\n): MonitorOptions =>\n\tmonitorConnection(monitor, {\n\t\troot: options.root,\n\t\tpassword: monitorPassword(monitor, options.env),\n\t});\n\n/**\n * Reads a CODESYS controller over OPC UA, where targets are IEC symbol paths. It reads only\n * what the build publishes, so it suits a local virtual PLC.\n */\nexport const createOpcUaAdapter = (options: MonitorOptions): TargetAdapter => {\n\tconst monitor = createMonitor(options);\n\tconst controller = new AbortController();\n\tconst running = monitor.run(controller.signal);\n\tconst sample = ({ value, quality, status }: Reading): TargetSample => ({\n\t\tvalue,\n\t\tquality,\n\t\tstatus,\n\t\treceivedAt: new Date().toISOString(),\n\t});\n\tconst names = (targets: readonly TargetRead[]) =>\n\t\ttargets.map(({ target }) => target);\n\n\treturn {\n\t\tmethod: \"OPC UA\",\n\t\tendpoint: options.endpoint,\n\t\tsamplingMs: monitor.samplingMs,\n\t\tconnection: monitor.status,\n\t\tonConnection: monitor.onStatus,\n\t\tread: async (targets) =>\n\t\t\tnew Map(\n\t\t\t\tObject.entries(await monitor.read(names(targets))).map(\n\t\t\t\t\t([target, reading]) => [target, sample(reading)],\n\t\t\t\t),\n\t\t\t),\n\t\tsubscribe: (targets, listener, intervalMs = monitor.samplingMs) => {\n\t\t\tconst latest = new Map<string, { reading: Reading; at: number }>();\n\t\t\tconst report = (target: string, reading: Reading) => {\n\t\t\t\tlatest.set(target, { reading, at: Date.now() });\n\t\t\t\tlistener(target, sample(reading));\n\t\t\t};\n\t\t\tconst stop = monitor.watch(names(targets), report);\n\t\t\t// OPC UA reports a value only when it changes. While the session holds, an unchanged value\n\t\t\t// is still current, so it is reported again each interval.\n\t\t\tconst repeat = setInterval(() => {\n\t\t\t\tif (monitor.status().state !== \"connected\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst now = Date.now();\n\t\t\t\tfor (const [target, { reading, at }] of latest) {\n\t\t\t\t\tif (now - at >= intervalMs) {\n\t\t\t\t\t\treport(target, reading);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, intervalMs);\n\t\t\treturn () => {\n\t\t\t\tclearInterval(repeat);\n\t\t\t\tstop();\n\t\t\t};\n\t\t},\n\t\tclose: async () => {\n\t\t\tcontroller.abort();\n\t\t\tawait running;\n\t\t},\n\t};\n};\n"
|
|
40
|
+
],
|
|
41
|
+
"mappings": ";AAAA;AACA;AACA;;;ACFA;AAAA;AAAA;AAAA;AAIA,cAAS;;;ACJT;AAWO,IAAM,cAAc,EAAE,OAAO;AAAA,EACnC,MAAM,EAAE,OAAO,EAAE,IAAI;AAAA,EACrB,MAAM,EAAE,OAAO,EAAE,IAAI;AAAA,EACrB,QAAQ,EAAE,OAAO,EAAE,IA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