@prestack/thread 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/dist/attach.d.ts +1 -0
  3. package/dist/attach.js +1 -0
  4. package/dist/core/actor.d.ts +12 -0
  5. package/dist/core/actor.js +8 -0
  6. package/dist/core/asking.d.ts +180 -0
  7. package/dist/core/asking.js +1109 -0
  8. package/dist/core/attach.d.ts +54 -0
  9. package/dist/core/attach.js +510 -0
  10. package/dist/core/chain.d.ts +16 -0
  11. package/dist/core/chain.js +114 -0
  12. package/dist/core/cli.d.ts +2 -0
  13. package/dist/core/cli.js +1682 -0
  14. package/dist/core/condition.d.ts +52 -0
  15. package/dist/core/condition.js +198 -0
  16. package/dist/core/descend.d.ts +81 -0
  17. package/dist/core/descend.js +879 -0
  18. package/dist/core/finding.d.ts +12 -0
  19. package/dist/core/finding.js +23 -0
  20. package/dist/core/generators/meta.d.ts +2 -0
  21. package/dist/core/generators/meta.js +823 -0
  22. package/dist/core/init.d.ts +15 -0
  23. package/dist/core/init.js +134 -0
  24. package/dist/core/invoked.d.ts +9 -0
  25. package/dist/core/invoked.js +41 -0
  26. package/dist/core/round.d.ts +1 -0
  27. package/dist/core/round.js +57 -0
  28. package/dist/core/rows.d.ts +26 -0
  29. package/dist/core/rows.js +354 -0
  30. package/dist/core/scope.d.ts +6 -0
  31. package/dist/core/scope.js +12 -0
  32. package/dist/core/thread.d.ts +26 -0
  33. package/dist/core/thread.js +5 -0
  34. package/dist/core/tree.d.ts +12 -0
  35. package/dist/core/tree.js +56 -0
  36. package/dist/core/types.d.ts +49 -0
  37. package/dist/core/types.js +311 -0
  38. package/dist/derivation/attach.d.ts +2 -0
  39. package/dist/derivation/attach.js +61 -0
  40. package/dist/derivation/generators/build.d.ts +16 -0
  41. package/dist/derivation/generators/build.js +217 -0
  42. package/dist/derivation/generators/check.d.ts +18 -0
  43. package/dist/derivation/generators/check.js +78 -0
  44. package/dist/derivation/generators/derivation.d.ts +3 -0
  45. package/dist/derivation/generators/derivation.js +273 -0
  46. package/dist/derivation/generators/determinism.d.ts +20 -0
  47. package/dist/derivation/generators/determinism.js +110 -0
  48. package/dist/derivation/generators/release.d.ts +3 -0
  49. package/dist/derivation/generators/release.js +183 -0
  50. package/dist/derivation/makers/release.d.ts +1 -0
  51. package/dist/derivation/makers/release.js +107 -0
  52. package/dist/derivation/release.d.ts +10 -0
  53. package/dist/derivation/release.js +12 -0
  54. package/dist/integrations/attach.d.ts +6 -0
  55. package/dist/integrations/attach.js +177 -0
  56. package/dist/integrations/generators/read.d.ts +1 -0
  57. package/dist/integrations/generators/read.js +92 -0
  58. package/dist/integrations/generators/sdk.d.ts +1 -0
  59. package/dist/integrations/generators/sdk.js +148 -0
  60. package/dist/integrations/generators/secret.d.ts +1 -0
  61. package/dist/integrations/generators/secret.js +233 -0
  62. package/dist/integrations/generators/target.d.ts +1 -0
  63. package/dist/integrations/generators/target.js +765 -0
  64. package/dist/integrations/generators/vault.d.ts +1 -0
  65. package/dist/integrations/generators/vault.js +164 -0
  66. package/dist/integrations/sdk.d.ts +6 -0
  67. package/dist/integrations/sdk.js +151 -0
  68. package/dist/integrations/secret.d.ts +16 -0
  69. package/dist/integrations/secret.js +30 -0
  70. package/dist/integrations/target.d.ts +49 -0
  71. package/dist/integrations/target.js +225 -0
  72. package/dist/integrations/vault.d.ts +12 -0
  73. package/dist/integrations/vault.js +104 -0
  74. package/dist/integrity/attach.d.ts +2 -0
  75. package/dist/integrity/attach.js +213 -0
  76. package/dist/integrity/check-threads.d.ts +10 -0
  77. package/dist/integrity/check-threads.js +153 -0
  78. package/dist/integrity/constraint.d.ts +16 -0
  79. package/dist/integrity/constraint.js +1105 -0
  80. package/dist/integrity/generators/compiler.d.ts +1 -0
  81. package/dist/integrity/generators/compiler.js +130 -0
  82. package/dist/integrity/generators/gate.d.ts +1 -0
  83. package/dist/integrity/generators/gate.js +172 -0
  84. package/dist/integrity/generators/issues.d.ts +1 -0
  85. package/dist/integrity/generators/issues.js +100 -0
  86. package/dist/integrity/generators/publish.d.ts +1 -0
  87. package/dist/integrity/generators/publish.js +186 -0
  88. package/dist/integrity/generators/rule.d.ts +2 -0
  89. package/dist/integrity/generators/rule.js +213 -0
  90. package/dist/integrity/generators/seal.d.ts +4 -0
  91. package/dist/integrity/generators/seal.js +101 -0
  92. package/dist/integrity/generators/trial.d.ts +39 -0
  93. package/dist/integrity/generators/trial.js +254 -0
  94. package/dist/integrity/lint.d.ts +50 -0
  95. package/dist/integrity/lint.js +161 -0
  96. package/dist/integrity/lsp/bin.d.ts +2 -0
  97. package/dist/integrity/lsp/bin.js +35 -0
  98. package/dist/integrity/lsp/diagnostics.d.ts +25 -0
  99. package/dist/integrity/lsp/diagnostics.js +57 -0
  100. package/dist/integrity/lsp/findings.d.ts +20 -0
  101. package/dist/integrity/lsp/findings.js +39 -0
  102. package/dist/integrity/lsp/lint.d.ts +7 -0
  103. package/dist/integrity/lsp/lint.js +95 -0
  104. package/dist/integrity/lsp/protocol.d.ts +20 -0
  105. package/dist/integrity/lsp/protocol.js +57 -0
  106. package/dist/integrity/lsp/server.d.ts +15 -0
  107. package/dist/integrity/lsp/server.js +171 -0
  108. package/dist/integrity/sealed.d.ts +1 -0
  109. package/dist/integrity/sealed.js +56 -0
  110. package/dist/integrity/slopnator.d.ts +90 -0
  111. package/dist/integrity/slopnator.js +267 -0
  112. package/dist/integrity/slopnators/sl_broken_lineage.d.ts +2 -0
  113. package/dist/integrity/slopnators/sl_broken_lineage.js +35 -0
  114. package/dist/integrity/slopnators/sl_declared_elsewhere.d.ts +2 -0
  115. package/dist/integrity/slopnators/sl_declared_elsewhere.js +33 -0
  116. package/dist/integrity/slopnators/sl_derived_drift.d.ts +8 -0
  117. package/dist/integrity/slopnators/sl_derived_drift.js +91 -0
  118. package/dist/integrity/slopnators/sl_hardcoded_style.d.ts +2 -0
  119. package/dist/integrity/slopnators/sl_hardcoded_style.js +46 -0
  120. package/dist/integrity/slopnators/sl_inert_island.d.ts +2 -0
  121. package/dist/integrity/slopnators/sl_inert_island.js +85 -0
  122. package/dist/integrity/slopnators/sl_inert_slopnator.d.ts +2 -0
  123. package/dist/integrity/slopnators/sl_inert_slopnator.js +76 -0
  124. package/dist/integrity/slopnators/sl_missing_row.d.ts +2 -0
  125. package/dist/integrity/slopnators/sl_missing_row.js +180 -0
  126. package/dist/integrity/slopnators/sl_no_barrel.d.ts +2 -0
  127. package/dist/integrity/slopnators/sl_no_barrel.js +41 -0
  128. package/dist/integrity/slopnators/sl_no_child_process.d.ts +2 -0
  129. package/dist/integrity/slopnators/sl_no_child_process.js +61 -0
  130. package/dist/integrity/slopnators/sl_no_comment.d.ts +2 -0
  131. package/dist/integrity/slopnators/sl_no_comment.js +41 -0
  132. package/dist/integrity/slopnators/sl_no_dispatch_bypass.d.ts +2 -0
  133. package/dist/integrity/slopnators/sl_no_dispatch_bypass.js +301 -0
  134. package/dist/integrity/slopnators/sl_no_import_cycle.d.ts +2 -0
  135. package/dist/integrity/slopnators/sl_no_import_cycle.js +42 -0
  136. package/dist/integrity/slopnators/sl_no_such_command.d.ts +2 -0
  137. package/dist/integrity/slopnators/sl_no_such_command.js +55 -0
  138. package/dist/integrity/slopnators/sl_only_takes_a_literal.d.ts +2 -0
  139. package/dist/integrity/slopnators/sl_only_takes_a_literal.js +59 -0
  140. package/dist/integrity/slopnators/sl_secret_literal.d.ts +2 -0
  141. package/dist/integrity/slopnators/sl_secret_literal.js +89 -0
  142. package/dist/integrity/slopnators/sl_stale_path.d.ts +2 -0
  143. package/dist/integrity/slopnators/sl_stale_path.js +92 -0
  144. package/dist/integrity/slopnators/sl_twice_meant.d.ts +2 -0
  145. package/dist/integrity/slopnators/sl_twice_meant.js +30 -0
  146. package/dist/integrity/slopnators/sl_twice_parented.d.ts +2 -0
  147. package/dist/integrity/slopnators/sl_twice_parented.js +34 -0
  148. package/dist/integrity/slopnators/sl_undeclared_crossing.d.ts +2 -0
  149. package/dist/integrity/slopnators/sl_undeclared_crossing.js +78 -0
  150. package/dist/integrity/slopnators/sl_undeclared_destination.d.ts +2 -0
  151. package/dist/integrity/slopnators/sl_undeclared_destination.js +56 -0
  152. package/dist/integrity/slopnators/sl_undeclared_element.d.ts +2 -0
  153. package/dist/integrity/slopnators/sl_undeclared_element.js +34 -0
  154. package/dist/integrity/slopnators/sl_undeclared_node.d.ts +2 -0
  155. package/dist/integrity/slopnators/sl_undeclared_node.js +59 -0
  156. package/dist/integrity/slopnators/sl_undeclared_operation.d.ts +2 -0
  157. package/dist/integrity/slopnators/sl_undeclared_operation.js +120 -0
  158. package/dist/integrity/slopnators/sl_undeclared_variant.d.ts +2 -0
  159. package/dist/integrity/slopnators/sl_undeclared_variant.js +117 -0
  160. package/dist/integrity/slopnators/sl_undescribed.d.ts +2 -0
  161. package/dist/integrity/slopnators/sl_undescribed.js +54 -0
  162. package/dist/integrity/slopnators/sl_ungoverned_island.d.ts +2 -0
  163. package/dist/integrity/slopnators/sl_ungoverned_island.js +58 -0
  164. package/dist/integrity/slopnators/sl_unkept_rows.d.ts +2 -0
  165. package/dist/integrity/slopnators/sl_unkept_rows.js +104 -0
  166. package/dist/integrity/slopnators/sl_unnamed_island.d.ts +2 -0
  167. package/dist/integrity/slopnators/sl_unnamed_island.js +37 -0
  168. package/dist/integrity/slopnators/sl_unpaired_member.d.ts +2 -0
  169. package/dist/integrity/slopnators/sl_unpaired_member.js +114 -0
  170. package/dist/integrity/slopnators/sl_unpaired_slopnator.d.ts +2 -0
  171. package/dist/integrity/slopnators/sl_unpaired_slopnator.js +60 -0
  172. package/dist/integrity/slopnators/sl_unprefixed_member.d.ts +2 -0
  173. package/dist/integrity/slopnators/sl_unprefixed_member.js +126 -0
  174. package/dist/integrity/slopnators/sl_unseamed_reach.d.ts +2 -0
  175. package/dist/integrity/slopnators/sl_unseamed_reach.js +73 -0
  176. package/dist/integrity/slopnators/sl_unthreaded.d.ts +56 -0
  177. package/dist/integrity/slopnators/sl_unthreaded.js +352 -0
  178. package/dist/integrity/slopnators/sl_untranslated_key.d.ts +2 -0
  179. package/dist/integrity/slopnators/sl_untranslated_key.js +157 -0
  180. package/dist/integrity/slopnators/sl_unversioned.d.ts +2 -0
  181. package/dist/integrity/slopnators/sl_unversioned.js +31 -0
  182. package/dist/integrity/sweep.d.ts +24 -0
  183. package/dist/integrity/sweep.js +264 -0
  184. package/dist/knowledge/attach.d.ts +2 -0
  185. package/dist/knowledge/attach.js +339 -0
  186. package/dist/knowledge/generators/docsgen.d.ts +1 -0
  187. package/dist/knowledge/generators/docsgen.js +145 -0
  188. package/dist/knowledge/generators/glossary.d.ts +1 -0
  189. package/dist/knowledge/generators/glossary.js +56 -0
  190. package/dist/knowledge/generators/skills.d.ts +1 -0
  191. package/dist/knowledge/generators/skills.js +222 -0
  192. package/dist/knowledge/glossary.d.ts +6 -0
  193. package/dist/knowledge/glossary.js +1 -0
  194. package/dist/operations/access.d.ts +27 -0
  195. package/dist/operations/access.js +61 -0
  196. package/dist/operations/attach.d.ts +6 -0
  197. package/dist/operations/attach.js +414 -0
  198. package/dist/operations/capabilities.d.ts +37 -0
  199. package/dist/operations/capabilities.js +35 -0
  200. package/dist/operations/cost.d.ts +14 -0
  201. package/dist/operations/cost.js +37 -0
  202. package/dist/operations/dispatch.d.ts +14 -0
  203. package/dist/operations/dispatch.js +327 -0
  204. package/dist/operations/error-results.d.ts +4 -0
  205. package/dist/operations/error-results.js +25 -0
  206. package/dist/operations/errors/catalog.d.ts +58 -0
  207. package/dist/operations/errors/catalog.js +91 -0
  208. package/dist/operations/errors/classes.d.ts +73 -0
  209. package/dist/operations/errors/classes.js +22 -0
  210. package/dist/operations/errors/errors.d.ts +52 -0
  211. package/dist/operations/errors/errors.js +257 -0
  212. package/dist/operations/generators/capability.d.ts +5 -0
  213. package/dist/operations/generators/capability.js +603 -0
  214. package/dist/operations/generators/compile.d.ts +2 -0
  215. package/dist/operations/generators/compile.js +541 -0
  216. package/dist/operations/generators/grant.d.ts +1 -0
  217. package/dist/operations/generators/grant.js +267 -0
  218. package/dist/operations/generators/operation.d.ts +1 -0
  219. package/dist/operations/generators/operation.js +811 -0
  220. package/dist/operations/generators/permits.d.ts +1 -0
  221. package/dist/operations/generators/permits.js +196 -0
  222. package/dist/operations/generators/seed.d.ts +20 -0
  223. package/dist/operations/generators/seed.js +285 -0
  224. package/dist/operations/generators/trial.d.ts +53 -0
  225. package/dist/operations/generators/trial.js +376 -0
  226. package/dist/operations/http.d.ts +30 -0
  227. package/dist/operations/http.js +121 -0
  228. package/dist/operations/makers/capability.d.ts +1 -0
  229. package/dist/operations/makers/capability.js +117 -0
  230. package/dist/operations/makers/trial.d.ts +1 -0
  231. package/dist/operations/makers/trial.js +413 -0
  232. package/dist/operations/memory.d.ts +104 -0
  233. package/dist/operations/memory.js +365 -0
  234. package/dist/operations/metering.d.ts +55 -0
  235. package/dist/operations/metering.js +247 -0
  236. package/dist/operations/nodes.d.ts +35 -0
  237. package/dist/operations/nodes.js +15 -0
  238. package/dist/operations/operations.d.ts +18 -0
  239. package/dist/operations/operations.js +5 -0
  240. package/dist/operations/queue-policy.d.ts +3 -0
  241. package/dist/operations/queue-policy.js +8 -0
  242. package/dist/operations/result.d.ts +19 -0
  243. package/dist/operations/result.js +10 -0
  244. package/dist/operations/seams.d.ts +239 -0
  245. package/dist/operations/seams.js +45 -0
  246. package/dist/operations/store.d.ts +14 -0
  247. package/dist/operations/store.js +1 -0
  248. package/package.json +16 -0
@@ -0,0 +1,879 @@
1
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
2
+ import { dirname, join, relative, resolve } from 'node:path';
3
+ import ts from 'typescript';
4
+ import { ignored } from "./init.js";
5
+ import { NAMED, ORGANISATION } from "./scope.js";
6
+ import { findTree } from "./tree.js";
7
+ const BUILT = new Set(ignored()
8
+ .split('\n')
9
+ .map((one) => one.trim())
10
+ .filter((one) => one.endsWith('/'))
11
+ .map((one) => one.replace(/\/+$/, '')));
12
+ const TREE_AT = (() => {
13
+ try {
14
+ return findTree();
15
+ }
16
+ catch {
17
+ return undefined;
18
+ }
19
+ })();
20
+ const NOWHERE = '/this-app-has-no-tree';
21
+ function rooted() {
22
+ if (TREE_AT === undefined)
23
+ findTree();
24
+ }
25
+ export const ROOT = TREE_AT?.at ?? NOWHERE;
26
+ export const TREE = `${TREE_AT?.name ?? NOWHERE}/`;
27
+ export const THREAD_AT = `${TREE_AT?.name ?? NOWHERE}/thread.ts`;
28
+ export const LISTS = ['declares', 'derives', 'seeds'];
29
+ const SOURCE = /\.(ts|tsx|mts|cts)$/;
30
+ const RUNNER = /^(?:pnpm|npm|yarn) (?:run )?([\w:.-]+)/;
31
+ export function under(pass, id, root, seen = new Set()) {
32
+ if (id === root)
33
+ return true;
34
+ if (seen.has(id))
35
+ return false;
36
+ seen.add(id);
37
+ return (pass.coined.get(id)?.from ?? []).some((one) => under(pass, one, root, seen));
38
+ }
39
+ function here(path) {
40
+ return relative(ROOT, path).split('\\').join('/');
41
+ }
42
+ const CANONICAL = 'threads/';
43
+ const BESIDE = /^\.\//;
44
+ function settle(at, where) {
45
+ if (BESIDE.test(at))
46
+ return here(resolve(ROOT, dirname(where), at.slice(2)));
47
+ if (at.startsWith(CANONICAL))
48
+ return here(resolve(ROOT, TREE, at.slice(CANONICAL.length)));
49
+ return here(resolve(ROOT, at));
50
+ }
51
+ function itself(at) {
52
+ try {
53
+ return realpathSync(resolve(ROOT, at));
54
+ }
55
+ catch {
56
+ return resolve(ROOT, at);
57
+ }
58
+ }
59
+ function walk(dir, out) {
60
+ let entries;
61
+ try {
62
+ entries = readdirSync(dir);
63
+ }
64
+ catch {
65
+ return out;
66
+ }
67
+ for (const name of [...entries].sort()) {
68
+ if (name === '.git' || BUILT.has(name))
69
+ continue;
70
+ const path = join(dir, name);
71
+ let held;
72
+ try {
73
+ held = statSync(path);
74
+ }
75
+ catch {
76
+ continue;
77
+ }
78
+ if (held.isDirectory())
79
+ walk(path, out);
80
+ else
81
+ out.push(here(path));
82
+ }
83
+ return out;
84
+ }
85
+ let scanned;
86
+ export function sources() {
87
+ rooted();
88
+ scanned ??= walk(ROOT, []).sort();
89
+ return scanned;
90
+ }
91
+ function shipped() {
92
+ const out = [];
93
+ const base = join(ROOT, 'node_modules', ORGANISATION);
94
+ let entries;
95
+ try {
96
+ entries = readdirSync(base);
97
+ }
98
+ catch {
99
+ return out;
100
+ }
101
+ for (const name of [...entries].sort())
102
+ walk(join(base, name, 'src'), out);
103
+ return out;
104
+ }
105
+ const FALLBACK = {
106
+ target: ts.ScriptTarget.Latest,
107
+ module: ts.ModuleKind.ESNext,
108
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
109
+ jsx: ts.JsxEmit.ReactJSX,
110
+ strict: true,
111
+ allowImportingTsExtensions: true,
112
+ allowJs: true,
113
+ resolveJsonModule: true,
114
+ };
115
+ const CONFIGS = ['tsconfig.json', 'tsconfig.base.json'];
116
+ const INVARIANT = {
117
+ noEmit: true,
118
+ skipLibCheck: true,
119
+ allowImportingTsExtensions: true,
120
+ allowJs: true,
121
+ jsx: ts.JsxEmit.ReactJSX,
122
+ };
123
+ export function configured() {
124
+ for (const name of CONFIGS) {
125
+ const at = join(ROOT, name);
126
+ if (!ts.sys.fileExists(at))
127
+ continue;
128
+ const held = ts.readConfigFile(at, ts.sys.readFile.bind(ts.sys));
129
+ if (held.error !== undefined) {
130
+ return {
131
+ options: { ...FALLBACK, ...INVARIANT },
132
+ from: '',
133
+ trouble: `${name} is there and cannot be read: ${ts.flattenDiagnosticMessageText(held.error.messageText, ' ')}`,
134
+ };
135
+ }
136
+ const parsed = ts.parseJsonConfigFileContent(held.config, ts.sys, dirname(at));
137
+ const complained = parsed.errors[0];
138
+ if (complained !== undefined) {
139
+ return {
140
+ options: { ...FALLBACK, ...INVARIANT },
141
+ from: '',
142
+ trouble: `${name} is there and states no options this gate can use: ${ts.flattenDiagnosticMessageText(complained.messageText, ' ')}`,
143
+ };
144
+ }
145
+ return { options: { ...parsed.options, ...INVARIANT }, from: name };
146
+ }
147
+ return { options: { ...FALLBACK, ...INVARIANT }, from: '' };
148
+ }
149
+ let built;
150
+ function compiled() {
151
+ rooted();
152
+ if (built !== undefined)
153
+ return built;
154
+ const roots = [THREAD_AT, ...sources(), ...shipped()].filter((one) => SOURCE.test(one)).map((one) => resolve(ROOT, one));
155
+ const program = ts.createProgram([...new Set(roots)], configured().options);
156
+ built = { program, checker: program.getTypeChecker() };
157
+ return built;
158
+ }
159
+ export function uncompiled() {
160
+ const { program } = compiled();
161
+ const found = [];
162
+ const INSTALLED = 'node_' + 'modules';
163
+ for (const file of program.getSourceFiles()) {
164
+ if (file.isDeclarationFile)
165
+ continue;
166
+ const at = here(file.fileName);
167
+ if (at.startsWith('..') || at.split('/').includes(INSTALLED))
168
+ continue;
169
+ for (const one of [...program.getSyntacticDiagnostics(file), ...program.getSemanticDiagnostics(file)]) {
170
+ const start = one.start === undefined ? undefined : file.getLineAndCharacterOfPosition(one.start);
171
+ found.push({
172
+ file: at,
173
+ at: start === undefined ? undefined : { line: start.line + 1, column: start.character + 1 },
174
+ detail: `will not compile — TS${String(one.code)}: ${ts.flattenDiagnosticMessageText(one.messageText, ' ')}`,
175
+ instead: 'fix the type error. Nothing in this tree is built, served or gated while a file it names does not compile, and every other surface here reads the same program',
176
+ });
177
+ }
178
+ }
179
+ return found;
180
+ }
181
+ function threadedType(checker, program) {
182
+ const root = program.getSourceFile(resolve(ROOT, THREAD_AT));
183
+ if (root === undefined)
184
+ return undefined;
185
+ for (const statement of root.statements) {
186
+ if (!ts.isImportDeclaration(statement))
187
+ continue;
188
+ const bindings = statement.importClause?.namedBindings;
189
+ if (bindings === undefined || !ts.isNamedImports(bindings))
190
+ continue;
191
+ for (const one of bindings.elements) {
192
+ const symbol = checker.getSymbolAtLocation(one.name);
193
+ if (symbol === undefined)
194
+ continue;
195
+ const real = (symbol.flags & ts.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(symbol) : symbol;
196
+ if (real.name === 'Threaded')
197
+ return checker.getDeclaredTypeOfSymbol(real);
198
+ }
199
+ }
200
+ return undefined;
201
+ }
202
+ const source = new Map();
203
+ export function read(at) {
204
+ if (source.has(at))
205
+ return source.get(at);
206
+ let text;
207
+ try {
208
+ text = readFileSync(resolve(ROOT, at), 'utf8');
209
+ }
210
+ catch {
211
+ text = undefined;
212
+ }
213
+ source.set(at, text);
214
+ return text;
215
+ }
216
+ export function shapesNamed() {
217
+ const { program, checker } = compiled();
218
+ const shape = threadedType(checker, program);
219
+ const found = new Map();
220
+ if (shape === undefined)
221
+ return found;
222
+ for (const at of [...sources(), ...shipped()]) {
223
+ if (!SOURCE.test(at))
224
+ continue;
225
+ const file = program.getSourceFile(resolve(ROOT, at));
226
+ if (file === undefined)
227
+ continue;
228
+ for (const statement of file.statements) {
229
+ if (!ts.isInterfaceDeclaration(statement) && !ts.isTypeAliasDeclaration(statement))
230
+ continue;
231
+ if ((statement.typeParameters ?? []).length > 0)
232
+ continue;
233
+ const symbol = checker.getSymbolAtLocation(statement.name);
234
+ if (symbol === undefined)
235
+ continue;
236
+ const shown = (statement.modifiers ?? []).some((one) => one.kind === ts.SyntaxKind.ExportKeyword);
237
+ if (!shown && statement.name.text !== 'Threaded')
238
+ continue;
239
+ const held = ts.isInterfaceDeclaration(statement)
240
+ ? checker.getDeclaredTypeOfSymbol(symbol)
241
+ : checker.getTypeAtLocation(statement.name);
242
+ const named = statement.name.text;
243
+ const shadows = named === 'Threaded';
244
+ const kind = elementOf(checker, held);
245
+ if (!shadows && (kind.flags & ts.TypeFlags.Never) !== 0)
246
+ continue;
247
+ if (!shadows && !checker.isTypeAssignableTo(kind, shape))
248
+ continue;
249
+ const where = found.get(named) ?? [];
250
+ const real = itself(at);
251
+ if (where.some((one) => itself(one) === real))
252
+ continue;
253
+ found.set(named, [...where, at]);
254
+ }
255
+ }
256
+ return found;
257
+ }
258
+ export function threading() {
259
+ return new Set(['Threaded', ...shapesNamed().keys()]);
260
+ }
261
+ export function shapeFields(named, inside) {
262
+ const { program, checker } = compiled();
263
+ for (const at of [...sources(), ...shipped()]) {
264
+ if (!SOURCE.test(at))
265
+ continue;
266
+ if (inside !== undefined && !at.split('\\').join('/').endsWith(inside))
267
+ continue;
268
+ const file = program.getSourceFile(resolve(ROOT, at));
269
+ if (file === undefined)
270
+ continue;
271
+ for (const statement of file.statements) {
272
+ if (!ts.isInterfaceDeclaration(statement) && !ts.isTypeAliasDeclaration(statement))
273
+ continue;
274
+ if (statement.name.text !== named)
275
+ continue;
276
+ const symbol = checker.getSymbolAtLocation(statement.name);
277
+ if (symbol === undefined)
278
+ continue;
279
+ const held = ts.isInterfaceDeclaration(statement)
280
+ ? checker.getDeclaredTypeOfSymbol(symbol)
281
+ : checker.getTypeAtLocation(statement.name);
282
+ const mapped = (kind) => (kind.isUnion() ? kind.types : [kind]).some((each) => (each.flags & ts.TypeFlags.StringLike) === 0 &&
283
+ checker.getIndexTypeOfType(each, ts.IndexKind.Number) === undefined &&
284
+ checker.getIndexTypeOfType(each, ts.IndexKind.String) !== undefined);
285
+ const listed = (kind) => (kind.isUnion() ? kind.types : [kind]).some((each) => (each.flags & ts.TypeFlags.StringLike) === 0 &&
286
+ checker.getIndexTypeOfType(each, ts.IndexKind.Number) !== undefined);
287
+ return checker.getPropertiesOfType(held).map((one) => {
288
+ const kind = checker.getTypeOfSymbolAtLocation(one, statement);
289
+ return {
290
+ name: one.getName(),
291
+ required: (one.flags & ts.SymbolFlags.Optional) === 0,
292
+ list: listed(kind),
293
+ map: mapped(kind),
294
+ worded: (kind.isUnion() ? kind.types : [kind]).some((each) => (each.flags & ts.TypeFlags.StringLike) !== 0),
295
+ guide: ts.displayPartsToString(one.getDocumentationComment(checker)).trim(),
296
+ };
297
+ });
298
+ }
299
+ }
300
+ return [];
301
+ }
302
+ function elementAt(at, list) {
303
+ const { program, checker } = compiled();
304
+ const file = program.getSourceFile(resolve(ROOT, at));
305
+ if (file === undefined)
306
+ return undefined;
307
+ const threaded = threadedType(checker, program);
308
+ let held;
309
+ const consider = (node) => {
310
+ if (held !== undefined)
311
+ return;
312
+ const wanted = checker.getContextualType(node) ?? checker.getTypeAtLocation(node);
313
+ const kinds = (wanted.isUnionOrIntersection() ? wanted.types : [wanted])
314
+ .filter((one) => checker.getIndexTypeOfType(one, ts.IndexKind.Number) !== undefined)
315
+ .map((one) => elementOf(checker, one));
316
+ const type = kinds.find((one) => threaded !== undefined && checker.isTypeAssignableTo(one, threaded)) ??
317
+ (kinds.length === 1 ? kinds[0] : undefined);
318
+ if (type !== undefined)
319
+ held = { type, node };
320
+ };
321
+ const visit = (node) => {
322
+ if (held !== undefined)
323
+ return;
324
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === list) {
325
+ const initial = node.initializer;
326
+ if (initial !== undefined && ts.isArrayLiteralExpression(initial))
327
+ consider(initial);
328
+ }
329
+ if (ts.isPropertyAssignment(node)) {
330
+ const key = ts.isIdentifier(node.name) || ts.isStringLiteralLike(node.name) ? node.name.text : undefined;
331
+ if (key === list && ts.isArrayLiteralExpression(node.initializer))
332
+ consider(node.initializer);
333
+ }
334
+ ts.forEachChild(node, visit);
335
+ };
336
+ visit(file);
337
+ return held;
338
+ }
339
+ export function listShape(at, list) {
340
+ const held = elementAt(at, list);
341
+ return held === undefined ? undefined : compiled().checker.typeToString(held.type);
342
+ }
343
+ export function listFields(at, list) {
344
+ const held = elementAt(at, list);
345
+ if (held === undefined)
346
+ return [];
347
+ const { checker } = compiled();
348
+ const bare = (kind) => (kind.isUnion() ? kind.types : [kind]).filter((each) => (each.flags & (ts.TypeFlags.Undefined | ts.TypeFlags.Null)) === 0);
349
+ const mapped = (kind) => bare(kind).some((each) => (each.flags & ts.TypeFlags.StringLike) === 0 &&
350
+ checker.getIndexTypeOfType(each, ts.IndexKind.Number) === undefined &&
351
+ checker.getIndexTypeOfType(each, ts.IndexKind.String) !== undefined);
352
+ const listed = (kind) => bare(kind).some((each) => (each.flags & ts.TypeFlags.StringLike) === 0 && checker.getIndexTypeOfType(each, ts.IndexKind.Number) !== undefined);
353
+ const flagged = (kind) => {
354
+ const kinds = bare(kind);
355
+ return kinds.length > 0 && kinds.every((each) => (each.flags & ts.TypeFlags.BooleanLike) !== 0);
356
+ };
357
+ const worded = (kind) => bare(kind).some((each) => (each.flags & ts.TypeFlags.StringLike) !== 0);
358
+ return checker.getPropertiesOfType(held.type).map((one) => {
359
+ const kind = checker.getTypeOfSymbolAtLocation(one, held.node);
360
+ return {
361
+ name: one.getName(),
362
+ required: (one.flags & ts.SymbolFlags.Optional) === 0,
363
+ list: listed(kind),
364
+ map: mapped(kind),
365
+ boolean: flagged(kind),
366
+ worded: worded(kind),
367
+ guide: ts.displayPartsToString(one.getDocumentationComment(checker)).trim(),
368
+ };
369
+ });
370
+ }
371
+ function elementOf(checker, type) {
372
+ return checker.getIndexTypeOfType(type, ts.IndexKind.Number) ?? type;
373
+ }
374
+ export function rowShape(at, list) {
375
+ const { program, checker } = compiled();
376
+ const file = program.getSourceFile(resolve(ROOT, at));
377
+ const threaded = threadedType(checker, program);
378
+ if (file === undefined || threaded === undefined)
379
+ return undefined;
380
+ let held;
381
+ const consider = (node) => {
382
+ if (held !== undefined)
383
+ return;
384
+ const wanted = checker.getContextualType(node) ?? checker.getTypeAtLocation(node);
385
+ const each = (wanted.isUnionOrIntersection() ? wanted.types : [wanted]).map((one) => elementOf(checker, one));
386
+ held = each.find((one) => checker.isTypeAssignableTo(one, threaded));
387
+ };
388
+ const visit = (node) => {
389
+ if (held !== undefined)
390
+ return;
391
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === list) {
392
+ const initial = node.initializer;
393
+ if (initial !== undefined && ts.isArrayLiteralExpression(initial))
394
+ consider(initial);
395
+ }
396
+ if (ts.isPropertyAssignment(node)) {
397
+ const key = ts.isIdentifier(node.name) || ts.isStringLiteralLike(node.name) ? node.name.text : undefined;
398
+ if (key === list && ts.isArrayLiteralExpression(node.initializer))
399
+ consider(node.initializer);
400
+ }
401
+ ts.forEachChild(node, visit);
402
+ };
403
+ visit(file);
404
+ return held === undefined ? undefined : checker.typeToString(held);
405
+ }
406
+ function literal(node) {
407
+ if (node === undefined)
408
+ return undefined;
409
+ return ts.isStringLiteralLike(node) ? node.text : undefined;
410
+ }
411
+ function fieldsOf(node) {
412
+ const found = new Map();
413
+ for (const property of node.properties) {
414
+ if (!ts.isPropertyAssignment(property))
415
+ continue;
416
+ const key = ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name) ? property.name.text : undefined;
417
+ if (key !== undefined)
418
+ found.set(key, property.initializer);
419
+ }
420
+ return found;
421
+ }
422
+ function wordsOf(node) {
423
+ if (node === undefined || !ts.isArrayLiteralExpression(node))
424
+ return [];
425
+ return node.elements.map((one) => literal(one)).filter((one) => one !== undefined);
426
+ }
427
+ function rowOf(node, type, where, shape) {
428
+ const fields = fieldsOf(node);
429
+ const named = literal(fields.get('at'));
430
+ const at = named === undefined ? undefined : settle(named, where);
431
+ const id = literal(fields.get('id'));
432
+ const describes = literal(fields.get('describes'));
433
+ const by = literal(fields.get('by'));
434
+ const runs = literal(fields.get('runs'));
435
+ const requires = wordsOf(fields.get('requires'));
436
+ const takes = wordsOf(fields.get('takes'));
437
+ return {
438
+ ...(at === undefined ? {} : { at }),
439
+ ...(id === undefined ? {} : { id }),
440
+ ...(describes === undefined ? {} : { describes }),
441
+ ...(by === undefined ? {} : { by }),
442
+ ...(runs === undefined ? {} : { runs }),
443
+ ...(requires.length === 0 ? {} : { requires }),
444
+ ...(takes.length === 0 ? {} : { takes }),
445
+ ...(shape === undefined ? {} : { shape }),
446
+ type,
447
+ fields,
448
+ where,
449
+ };
450
+ }
451
+ function unwrap(node) {
452
+ let held = node;
453
+ for (;;) {
454
+ if (held === undefined)
455
+ return undefined;
456
+ if (ts.isParenthesizedExpression(held) || ts.isSatisfiesExpression(held) || ts.isAsExpression(held)) {
457
+ held = held.expression;
458
+ continue;
459
+ }
460
+ return held;
461
+ }
462
+ }
463
+ export function nodesIn(at) {
464
+ const { program, checker } = compiled();
465
+ const threaded = threadedType(checker, program);
466
+ const file = program.getSourceFile(resolve(ROOT, at));
467
+ if (file === undefined || threaded === undefined)
468
+ return [];
469
+ const found = [];
470
+ const take = (name, where, initial) => {
471
+ const held = unwrap(initial);
472
+ if (held === undefined)
473
+ return;
474
+ const recognised = (one) => (one.flags & ts.TypeFlags.Any) === 0 && checker.isTypeAssignableTo(one, threaded);
475
+ const declared = checker.getTypeAtLocation(where);
476
+ const each = (declared.isUnionOrIntersection() ? declared.types : [declared]).map((one) => elementOf(checker, one));
477
+ const stated = each.find((one) => recognised(one));
478
+ const parts = ts.isArrayLiteralExpression(held) ? held.elements : [held];
479
+ for (const one of parts) {
480
+ const object = unwrap(one);
481
+ if (object === undefined || !ts.isObjectLiteralExpression(object))
482
+ continue;
483
+ const mine = checker.getWidenedType(checker.getTypeAtLocation(object));
484
+ const known = stated ?? (recognised(mine) ? mine : undefined);
485
+ if (known === undefined)
486
+ continue;
487
+ found.push({ name, type: checker.typeToString(known), shape: known, node: object });
488
+ }
489
+ };
490
+ const step = (statements) => {
491
+ for (const statement of statements) {
492
+ if (ts.isModuleDeclaration(statement) && statement.body !== undefined && ts.isModuleBlock(statement.body)) {
493
+ step(statement.body.statements);
494
+ continue;
495
+ }
496
+ if (ts.isExportAssignment(statement)) {
497
+ take('default', statement.expression, statement.expression);
498
+ continue;
499
+ }
500
+ if (!ts.isVariableStatement(statement))
501
+ continue;
502
+ for (const one of statement.declarationList.declarations) {
503
+ if (!ts.isIdentifier(one.name) || one.initializer === undefined)
504
+ continue;
505
+ take(one.name.text, one.name, one.initializer);
506
+ }
507
+ }
508
+ };
509
+ step(file.statements);
510
+ return found;
511
+ }
512
+ let commands;
513
+ function scripts() {
514
+ if (commands !== undefined)
515
+ return commands;
516
+ const found = new Set();
517
+ try {
518
+ const held = JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf8'));
519
+ for (const name of Object.keys(held.scripts ?? {}))
520
+ found.add(name);
521
+ }
522
+ catch {
523
+ found.clear();
524
+ }
525
+ commands = found;
526
+ return found;
527
+ }
528
+ function mentionsIn(at) {
529
+ const found = [];
530
+ const step = (node) => {
531
+ const fields = fieldsOf(node);
532
+ for (const list of LISTS) {
533
+ const value = fields.get(list);
534
+ if (value === undefined || !ts.isArrayLiteralExpression(value))
535
+ continue;
536
+ for (const one of value.elements) {
537
+ if (!ts.isObjectLiteralExpression(one))
538
+ continue;
539
+ const held = literal(fieldsOf(one).get('at'));
540
+ if (held !== undefined)
541
+ found.push(settle(held, at));
542
+ step(one);
543
+ }
544
+ }
545
+ };
546
+ for (const one of nodesIn(at))
547
+ step(one.node);
548
+ return found;
549
+ }
550
+ let passed;
551
+ export function reached() {
552
+ return [THREAD_AT, ...descend().threaded.keys()];
553
+ }
554
+ export function forget() {
555
+ passed = undefined;
556
+ built = undefined;
557
+ scanned = undefined;
558
+ commands = undefined;
559
+ source.clear();
560
+ }
561
+ export function descend() {
562
+ rooted();
563
+ if (passed !== undefined)
564
+ return passed;
565
+ const { program, checker } = compiled();
566
+ const threaded = new Map();
567
+ const mentioned = new Map();
568
+ const derived = new Map();
569
+ const stated = new Map();
570
+ const coined = new Map();
571
+ const broken = [];
572
+ const findings = [];
573
+ const opened = new Set();
574
+ const shaped = new Map();
575
+ const made = new Map();
576
+ const absent = new Map();
577
+ const demanded = [];
578
+ const thread = [];
579
+ const offered = new Set();
580
+ let declarations = 0;
581
+ let rows = 0;
582
+ const root = program.getSourceFile(resolve(ROOT, THREAD_AT));
583
+ if (root === undefined) {
584
+ broken.push({
585
+ file: THREAD_AT,
586
+ detail: 'the root of the tree cannot be read, so nothing below it is reached and every file here reads as unthreaded',
587
+ instead: 'write the root, or run `thread init`',
588
+ });
589
+ passed = { threaded, mentioned, derived, stated, coined, broken, findings, declarations, rows, sources: sources() };
590
+ return passed;
591
+ }
592
+ const shape = threadedType(checker, program);
593
+ if (shape === undefined) {
594
+ broken.push({
595
+ file: THREAD_AT,
596
+ detail: 'the root does not resolve `Threaded`, so nothing here can be recognised as a declaration and every file reads as unthreaded',
597
+ instead: `import \`Threaded\` from \`${NAMED}/thread\` in the root, or run \`thread init\`. Without the shape there is nothing to hold anything to`,
598
+ });
599
+ passed = { threaded, mentioned, derived, stated, coined, broken, findings, declarations, rows, sources: sources() };
600
+ return passed;
601
+ }
602
+ const said = (by) => (by === '' ? 'the root' : by);
603
+ const names = (row) => row.id ?? row.at ?? 'a row stating neither an id nor an at';
604
+ function coin(id, describes, under, parent) {
605
+ if (id === undefined)
606
+ return;
607
+ const held = coined.get(id) ?? { said: [], under, from: [] };
608
+ const meaning = describes ?? '';
609
+ if (!held.said.includes(meaning))
610
+ held.said.push(meaning);
611
+ if (parent !== '' && parent !== id && !held.from.includes(parent))
612
+ held.from.push(parent);
613
+ coined.set(id, held);
614
+ }
615
+ function judge(row, by, list, own) {
616
+ const at = row.where;
617
+ for (const field of ['by', 'runs']) {
618
+ const command = row[field];
619
+ if (command === undefined)
620
+ continue;
621
+ if (command.startsWith('thread ')) {
622
+ if (field === 'by')
623
+ offered.add(command);
624
+ else
625
+ thread.push({ row, command });
626
+ continue;
627
+ }
628
+ const held = RUNNER.exec(command);
629
+ if (held === null || scripts().has(held[1] ?? ''))
630
+ continue;
631
+ findings.push({
632
+ file: at,
633
+ detail: `\`${names(row)}\` states \`${field}: '${command}'\`, and package.json states no \`${held[1] ?? ''}\` script`,
634
+ instead: 'add the script, or fix the name. A row naming a command is a promise that the command exists',
635
+ });
636
+ }
637
+ for (const field of ['requires', 'takes']) {
638
+ for (const word of wordsOf(row.fields.get(field)))
639
+ demanded.push({ row, word, list: field });
640
+ }
641
+ if (list === 'derives' && row.at !== undefined && !own) {
642
+ const held = made.get(row.at) ?? { by: new Set(), rows: [], where: at };
643
+ if (row.by !== undefined)
644
+ held.by.add(row.by);
645
+ held.rows.push(names(row));
646
+ made.set(row.at, held);
647
+ }
648
+ if (row.at === THREAD_AT && !own) {
649
+ findings.push({
650
+ file: at,
651
+ detail: `\`${names(row)}\` declares \`${THREAD_AT}\`, which is the root`,
652
+ instead: 'delete the row. The root exists by fiat and is the one thing nothing declares — giving it a parent makes its origin a thing the tree answers two ways',
653
+ });
654
+ }
655
+ if (row.at === undefined)
656
+ return;
657
+ if (row.at.startsWith('../') || row.at.startsWith('/')) {
658
+ findings.push({
659
+ file: at,
660
+ detail: `\`${names(row)}\` names \`${row.at}\`, which is outside this repository`,
661
+ instead: 'name something inside the tree. A declaration reaches only what this repository holds, and a row pointing past its edge threads a file nobody here can read, change or delete',
662
+ });
663
+ return;
664
+ }
665
+ const target = resolve(ROOT, row.at);
666
+ if (!existsSync(target)) {
667
+ const derived = list === 'derives' || row.by !== undefined;
668
+ const said = absent.get(row.at);
669
+ if (said !== undefined) {
670
+ said.by.add(names(row));
671
+ said.rows += 1;
672
+ return;
673
+ }
674
+ absent.set(row.at, { at: findings.length, by: new Set([names(row)]), rows: 1 });
675
+ findings.push({
676
+ file: at,
677
+ detail: derived
678
+ ? `\`${names(row)}\` ${list === 'derives' ? 'derives' : 'names'} \`${row.at}\`, and nothing is there yet`
679
+ : `\`${names(row)}\` names \`${row.at}\`, and nothing is there`,
680
+ instead: derived
681
+ ? 'run the generator the row names in `by`. A derived file is absent until it is derived, so this is a warning'
682
+ : 'write the file, fix the path, or delete the row. A row naming nothing brings nothing into existence',
683
+ ...(derived ? { severity: 'warning' } : {}),
684
+ });
685
+ }
686
+ else if (statSync(target).isDirectory()) {
687
+ findings.push({
688
+ file: at,
689
+ detail: `\`${names(row)}\` names \`${row.at}\`, which is a directory`,
690
+ instead: 'name the file. A directory threads nothing beneath it, so every file under this one still reads as declared by nobody while the row itself looks answered',
691
+ });
692
+ }
693
+ const already = shaped.get(row.at);
694
+ if (already === undefined) {
695
+ shaped.set(row.at, { type: row.type, shape: row.shape, by });
696
+ return;
697
+ }
698
+ if (row.shape === undefined || already.shape === undefined)
699
+ return;
700
+ if (checker.isTypeAssignableTo(row.shape, already.shape) || checker.isTypeAssignableTo(already.shape, row.shape))
701
+ return;
702
+ findings.push({
703
+ file: at,
704
+ detail: `\`${row.at}\` is declared \`${row.type}\` by \`${said(by)}\` and \`${already.type}\` by \`${said(already.by)}\`, and neither shape satisfies the other`,
705
+ instead: 'one address has one shape. Decide what the child is and let both rows say it',
706
+ });
707
+ }
708
+ function into(node, type, at, under, parent, judged = false) {
709
+ declarations += 1;
710
+ const held = rowOf(node, type, at);
711
+ if (!judged) {
712
+ coin(held.id, held.describes, under, parent);
713
+ judge(held, parent, 'declares', true);
714
+ if (held.id !== undefined && !stated.has(held.id))
715
+ stated.set(held.id, held);
716
+ }
717
+ const by = held.id ?? at;
718
+ for (const list of LISTS) {
719
+ const stated = held.fields.get(list);
720
+ if (stated === undefined)
721
+ continue;
722
+ const only = ts.isCallExpression(stated) && stated.arguments.length === 1 ? stated.arguments[0] : undefined;
723
+ const value = only !== undefined && ts.isArrayLiteralExpression(only) ? only : stated;
724
+ if (!ts.isArrayLiteralExpression(value)) {
725
+ findings.push({ file: at, detail: `\`${by}\` states a \`${list}\` that is not a list`, instead: `write \`${list}\` as a list of rows` });
726
+ continue;
727
+ }
728
+ for (const one of value.elements) {
729
+ if (!ts.isObjectLiteralExpression(one)) {
730
+ findings.push({
731
+ file: at,
732
+ detail: `\`${by}\` holds something in \`${list}\` that is not a row written out here`,
733
+ instead: 'write the row inline. A row reached through a name is a row the descent would have to run code to read',
734
+ });
735
+ continue;
736
+ }
737
+ rows += 1;
738
+ const wanted = checker.getContextualType(one);
739
+ const kind = wanted === undefined ? undefined : elementOf(checker, wanted);
740
+ const row = rowOf(one, kind === undefined ? type : checker.typeToString(kind), at, kind);
741
+ coin(row.id, row.describes, under, by);
742
+ judge(row, by, list, false);
743
+ if (row.at !== undefined) {
744
+ threaded.set(row.at, [...(threaded.get(row.at) ?? []), { list, by, row }]);
745
+ if (list === 'derives' && row.id !== undefined)
746
+ derived.set(row.id, row);
747
+ }
748
+ if (LISTS.some((name) => row.fields.has(name)))
749
+ into(one, row.type, at, under, by, true);
750
+ if (row.at !== undefined)
751
+ open(row.at, wanted === undefined ? undefined : elementOf(checker, wanted), under, row.id ?? by, by);
752
+ }
753
+ }
754
+ }
755
+ function open(at, expected, under, parent, by) {
756
+ const already = opened.has(at);
757
+ opened.add(at);
758
+ if (!SOURCE.test(at))
759
+ return;
760
+ const file = program.getSourceFile(resolve(ROOT, at));
761
+ if (file === undefined)
762
+ return;
763
+ if (!already) {
764
+ for (const one of program.getSyntacticDiagnostics(file)) {
765
+ broken.push({
766
+ file: at,
767
+ detail: `this file does not parse, so whatever it declares was never read and every child under it reads as absent: ${ts.flattenDiagnosticMessageText(one.messageText, ' ')}`,
768
+ instead: 'fix the syntax. A file the descent cannot read declares nothing, and nothing below it can be found missing',
769
+ });
770
+ break;
771
+ }
772
+ }
773
+ for (const one of nodesIn(at)) {
774
+ if (expected !== undefined && !checker.isTypeAssignableTo(one.shape, expected)) {
775
+ findings.push({
776
+ file: at,
777
+ detail: `\`${one.name}\` here is \`${one.type}\`, and \`${said(by)}\` states its child is \`${checker.typeToString(expected)}\``,
778
+ instead: `annotate it \`${checker.typeToString(expected)}\`, or a shape that satisfies it, or change the row. A parent states the shape of its child, and a child answering with another shape is a child of something else`,
779
+ });
780
+ continue;
781
+ }
782
+ if (already)
783
+ continue;
784
+ into(one.node, one.type, at, under, parent);
785
+ }
786
+ }
787
+ opened.add(THREAD_AT);
788
+ for (const one of nodesIn(THREAD_AT))
789
+ into(one.node, one.type, THREAD_AT, '', '');
790
+ for (const at of [...opened].filter((one) => SOURCE.test(one))) {
791
+ const file = program.getSourceFile(resolve(ROOT, at));
792
+ if (file === undefined)
793
+ continue;
794
+ for (const one of program.getSemanticDiagnostics(file)) {
795
+ findings.push({
796
+ file: at,
797
+ detail: `the compiler refuses this declaration: ${ts.flattenDiagnosticMessageText(one.messageText, ' ')}`,
798
+ instead: 'make the declaration the shape its own type states. A row the compiler will not accept is a row nothing downstream can read',
799
+ });
800
+ }
801
+ }
802
+ for (const [what, held] of made) {
803
+ if (held.by.size === 0) {
804
+ findings.push({
805
+ file: held.where,
806
+ detail: `\`${what}\` is derived by ${held.rows.length === 1 ? `\`${held.rows[0] ?? ''}\`` : `${String(held.rows.length)} rows`}, and not one of them states a \`by\``,
807
+ instead: 'name the command that writes it on one of those rows. A derived file whose generator is unnamed cannot be compared against what it should be, so drift in it is invisible',
808
+ });
809
+ continue;
810
+ }
811
+ if (held.by.size < 2)
812
+ continue;
813
+ findings.push({
814
+ file: held.where,
815
+ detail: `\`${what}\` is derived by ${[...held.by].map((one) => `\`${one}\``).join(' and ')}`,
816
+ instead: 'one file has one generator. Two commands writing one address means whichever runs last wins and the other is overwritten in silence',
817
+ });
818
+ }
819
+ const answers = (command) => offered.has(command) || [...offered].some((one) => command.startsWith(`${one} --`));
820
+ for (const one of thread) {
821
+ if (answers(one.command))
822
+ continue;
823
+ findings.push({
824
+ file: one.row.where,
825
+ detail: `\`${names(one.row)}\` states \`runs: '${one.command}'\`, and no row declares a \`by\` it is a mode of`,
826
+ instead: 'name a command some row brings into existence with a `by`, or a `--` mode of one. A row proving a byproduct proves what another row writes, so the writer has to exist',
827
+ });
828
+ }
829
+ for (const one of demanded) {
830
+ if (coined.has(one.word))
831
+ continue;
832
+ findings.push({
833
+ file: one.row.where,
834
+ detail: `\`${names(one.row)}\` ${one.list} \`${one.word}\`, and nothing in this tree coins that word`,
835
+ instead: `declare something with \`id: '${one.word}'\`, or fix the name. A demand naming nothing is met by nothing, and nothing tells you so`,
836
+ });
837
+ }
838
+ for (const [word, held] of coined) {
839
+ const meanings = [...new Set(held.said.filter((one) => one !== ''))];
840
+ if (meanings.length < 2)
841
+ continue;
842
+ findings.push({
843
+ file: THREAD_AT,
844
+ detail: `\`${word}\` is coined ${String(meanings.length)} times with different meanings: ${meanings.map((one) => `"${one.slice(0, 60)}${one.length > 60 ? '…' : ''}"`).join(' and ')}`,
845
+ instead: 'one word means one thing. Keep the row that coins it and make the others name what they actually are, or say the same sentence in both',
846
+ });
847
+ }
848
+ for (const [name, where] of shapesNamed()) {
849
+ if (where.length < 2)
850
+ continue;
851
+ findings.push({
852
+ file: where[1] ?? THREAD_AT,
853
+ detail: `\`${name}\` is a shape the tree threads by, and it is declared in ${String(where.length)} places: ${where.join(', ')}`,
854
+ instead: 'keep one and delete the rest. Whichever the descent reads first decides what every declaration is held to, so a second one silently rewrites the rules for the whole tree',
855
+ });
856
+ }
857
+ for (const one of [...sources(), ...shipped()]) {
858
+ if (!SOURCE.test(one))
859
+ continue;
860
+ for (const at of mentionsIn(one)) {
861
+ const held = mentioned.get(at) ?? [];
862
+ if (!held.includes(one))
863
+ mentioned.set(at, [...held, one]);
864
+ }
865
+ }
866
+ for (const [path, held] of absent) {
867
+ if (held.rows < 2)
868
+ continue;
869
+ const one = findings[held.at];
870
+ if (one === undefined)
871
+ continue;
872
+ findings[held.at] = {
873
+ ...one,
874
+ detail: `${String(held.rows)} rows derive \`${path}\`, and nothing is there yet — ${[...held.by].sort().join(', ')}`,
875
+ };
876
+ }
877
+ passed = { threaded, mentioned, derived, stated, coined, broken, findings, declarations, rows, sources: sources() };
878
+ return passed;
879
+ }