@mmerterden/multi-agent-pipeline 23.2.0 → 23.4.0

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 (230) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +25 -6
  3. package/README.tr.md +26 -7
  4. package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
  5. package/docs/adr/0010-own-code-graph.md +299 -8
  6. package/docs/architecture.md +3 -3
  7. package/docs/ecosystem.md +10 -10
  8. package/docs/engineering.md +4 -4
  9. package/docs/facts.json +8 -8
  10. package/docs/features.md +6 -6
  11. package/docs/performance.md +17 -17
  12. package/install/_dev-only-files.mjs +9 -0
  13. package/install/claude.mjs +28 -2
  14. package/install/templates/claude-hooks.json +32 -1
  15. package/manifest.json +229 -161
  16. package/package.json +11 -3
  17. package/pipeline/commands/multi-agent/SKILL.md +1 -1
  18. package/pipeline/commands/multi-agent/design-check/SKILL.md +2 -2
  19. package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
  20. package/pipeline/commands/multi-agent/fable-status/SKILL.md +1 -1
  21. package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
  22. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  23. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  24. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  25. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  26. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  27. package/pipeline/contract/CHANGELOG.md +49 -0
  28. package/pipeline/contract/build.mjs +13 -1
  29. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  30. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  31. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  32. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  33. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  34. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  35. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  36. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  37. package/pipeline/contract/fixtures/runs-running.json +4 -1
  38. package/pipeline/contract/manifest.json +28 -15
  39. package/pipeline/contract/types/index.d.ts +55 -3
  40. package/pipeline/lib/detach-self.mjs +95 -0
  41. package/pipeline/lib/model-rung.sh +1 -1
  42. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  43. package/pipeline/lib/rotated-log.mjs +93 -0
  44. package/pipeline/lib/tls-trust.mjs +29 -0
  45. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  46. package/pipeline/lib/usage-names.generated.mjs +614 -0
  47. package/pipeline/lib/usage-run-key.mjs +235 -0
  48. package/pipeline/lib/usage-vocab.mjs +210 -0
  49. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  50. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  51. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  52. package/pipeline/multi-agent-refs/cross-cli-contract.md +4 -4
  53. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  54. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  55. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  56. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  57. package/pipeline/multi-agent-refs/features/model-fallback.md +9 -7
  58. package/pipeline/multi-agent-refs/features/remote-control.md +252 -0
  59. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  60. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  61. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  62. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  63. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  64. package/pipeline/multi-agent-refs/features/usage-reporting.md +252 -24
  65. package/pipeline/multi-agent-refs/help/en.md +3 -2
  66. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  67. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  68. package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +1 -1
  69. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
  70. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  71. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  72. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  73. package/pipeline/multi-agent-refs/phases/phase-3-review.md +5 -3
  74. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  75. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  76. package/pipeline/multi-agent-refs/review/panel.md +1 -1
  77. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  78. package/pipeline/office/index.html +1207 -233
  79. package/pipeline/office/toolkit.json +1 -1
  80. package/pipeline/rules/outside-the-pipeline.md +1 -1
  81. package/pipeline/schemas/activity.schema.json +23 -0
  82. package/pipeline/schemas/agent-state.schema.json +6 -1
  83. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  84. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  85. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  86. package/pipeline/schemas/code-graph.schema.json +2 -2
  87. package/pipeline/schemas/examples/design-check-config.json +27 -0
  88. package/pipeline/schemas/learning-curve.schema.json +67 -0
  89. package/pipeline/schemas/office-jobs.json +69 -2
  90. package/pipeline/schemas/office-jobs.schema.json +8 -1
  91. package/pipeline/schemas/phases.json +5 -0
  92. package/pipeline/schemas/phases.schema.json +8 -0
  93. package/pipeline/schemas/prefs.schema.json +46 -12
  94. package/pipeline/schemas/runs-index.schema.json +17 -0
  95. package/pipeline/schemas/toolkit-path-params.json +84 -8
  96. package/pipeline/scripts/README.md +1 -0
  97. package/pipeline/scripts/_code-graph.mjs +184 -103
  98. package/pipeline/scripts/_contract-core.mjs +1 -1
  99. package/pipeline/scripts/_contract-routes-office.mjs +21 -0
  100. package/pipeline/scripts/_diff-impact.mjs +21 -2
  101. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  102. package/pipeline/scripts/_http-post.mjs +103 -115
  103. package/pipeline/scripts/_safe-read.mjs +57 -0
  104. package/pipeline/scripts/_skill-practices.mjs +26 -0
  105. package/pipeline/scripts/_strip-code.mjs +380 -0
  106. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  107. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  108. package/pipeline/scripts/call-graph/index.mjs +78 -0
  109. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  110. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  111. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  112. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  113. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  114. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  115. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  116. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  117. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  118. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  119. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  120. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  121. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  122. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  123. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  124. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  125. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  126. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  127. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  128. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  129. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  130. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  131. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  132. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  133. package/pipeline/scripts/contract-server.mjs +1 -0
  134. package/pipeline/scripts/cost-table.json +6 -5
  135. package/pipeline/scripts/feedback-send.mjs +26 -26
  136. package/pipeline/scripts/gate-ledger.mjs +2 -1
  137. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  138. package/pipeline/scripts/graph-affected.mjs +109 -20
  139. package/pipeline/scripts/graph-build.mjs +95 -15
  140. package/pipeline/scripts/graph-export.mjs +272 -0
  141. package/pipeline/scripts/graph-hint.mjs +15 -2
  142. package/pipeline/scripts/graph-query.mjs +305 -26
  143. package/pipeline/scripts/graph-report.mjs +187 -1
  144. package/pipeline/scripts/health-report.mjs +3 -4
  145. package/pipeline/scripts/infra/docs.mjs +317 -0
  146. package/pipeline/scripts/infra/extract.mjs +998 -0
  147. package/pipeline/scripts/infra/graph.mjs +245 -0
  148. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  149. package/pipeline/scripts/job-launch.mjs +67 -2
  150. package/pipeline/scripts/learning-curve.mjs +288 -178
  151. package/pipeline/scripts/log-metric.sh +10 -1
  152. package/pipeline/scripts/note-agent-event.mjs +3 -4
  153. package/pipeline/scripts/note-command-use.mjs +333 -0
  154. package/pipeline/scripts/note-command-use.sh +126 -0
  155. package/pipeline/scripts/note-mcp-call.sh +89 -0
  156. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  157. package/pipeline/scripts/note-session.sh +62 -3
  158. package/pipeline/scripts/note-skill-use.mjs +58 -2
  159. package/pipeline/scripts/office-build.mjs +115 -1
  160. package/pipeline/scripts/office-memory.mjs +14 -5
  161. package/pipeline/scripts/pair.mjs +333 -0
  162. package/pipeline/scripts/pre-push-check.sh +1 -1
  163. package/pipeline/scripts/remote/cbor.mjs +128 -0
  164. package/pipeline/scripts/remote/contract.mjs +98 -0
  165. package/pipeline/scripts/remote/handler.mjs +317 -0
  166. package/pipeline/scripts/remote/handles.mjs +57 -0
  167. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  168. package/pipeline/scripts/remote/listener.mjs +204 -0
  169. package/pipeline/scripts/remote/lockout.mjs +103 -0
  170. package/pipeline/scripts/remote/nonces.mjs +61 -0
  171. package/pipeline/scripts/remote/pairing.mjs +519 -0
  172. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  173. package/pipeline/scripts/remote/store.mjs +188 -0
  174. package/pipeline/scripts/remote/transport.mjs +211 -0
  175. package/pipeline/scripts/remote/verbs.json +70 -0
  176. package/pipeline/scripts/remote/verbs.mjs +217 -0
  177. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  178. package/pipeline/scripts/remote/wire.mjs +364 -0
  179. package/pipeline/scripts/remote-listener.mjs +83 -0
  180. package/pipeline/scripts/route-learn.mjs +4 -4
  181. package/pipeline/scripts/run-kill.mjs +1 -1
  182. package/pipeline/scripts/run-write.mjs +13 -2
  183. package/pipeline/scripts/runs-index.mjs +30 -3
  184. package/pipeline/scripts/search-logs.sh +9 -0
  185. package/pipeline/scripts/session-brief.mjs +458 -0
  186. package/pipeline/scripts/session-brief.sh +130 -0
  187. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  188. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  189. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  190. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  191. package/pipeline/scripts/token-budget-report.mjs +3 -2
  192. package/pipeline/scripts/uninstall.mjs +29 -0
  193. package/pipeline/scripts/usage-access.mjs +16 -31
  194. package/pipeline/scripts/usage-health.mjs +31 -62
  195. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  196. package/pipeline/scripts/usage-register.mjs +39 -29
  197. package/pipeline/scripts/usage-report.mjs +579 -178
  198. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  199. package/pipeline/scripts/write-state.mjs +39 -0
  200. package/pipeline/skills/.skill-manifest.json +22 -18
  201. package/pipeline/skills/.skills-index.json +13 -2
  202. package/pipeline/skills/shared/README.md +5 -4
  203. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  204. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  205. package/pipeline/skills/shared/core/multi-agent-fable-status/SKILL.md +1 -1
  206. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  207. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  208. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  209. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  210. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  211. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  212. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  213. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  214. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  215. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  216. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  217. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  218. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  219. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  220. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  221. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  222. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  223. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  224. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  225. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  226. package/pipeline/skills/skills-index.md +3 -2
  227. package/docs/FIGMA_PIPELINE.md +0 -137
  228. package/pipeline/lib/identifier-scan.mjs +0 -156
  229. package/pipeline/scripts/publish-staged.mjs +0 -324
  230. package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
@@ -0,0 +1,692 @@
1
+ /**
2
+ * @file typescript.mjs - TypeScript and JavaScript profile for the call-edge scanner.
3
+ *
4
+ * Reads classes (fields, constructor parameter properties, methods, arrow-function
5
+ * fields), interfaces, functions and `const f = (...) =>` bindings, plus import and
6
+ * require and dynamic-import bindings so a call can be traced to the module it came from. Types come
7
+ * only from annotations and `new Foo(...)`; in plain JavaScript that leaves most
8
+ * receivers untyped, and those fall back to a method name that is unique in the
9
+ * repository, at low confidence.
10
+ *
11
+ * @module pipeline/scripts/call-graph/lang/typescript
12
+ */
13
+
14
+ import { isIdent, readType, splitTop, tick, MAX_HEADER_TOKENS } from "../lex.mjs";
15
+ import {
16
+ genericNames,
17
+ typeList,
18
+ exprEnd,
19
+ paramsColon,
20
+ complement,
21
+ patternNames,
22
+ } from "./shared.mjs";
23
+
24
+ const MODS = new Set(
25
+ `export default declare abstract async public private protected static readonly override get set
26
+ accessor`.split(/\s+/),
27
+ );
28
+ const KEYWORDS = new Set(
29
+ `if else for while do switch case default return throw try catch finally new typeof instanceof void
30
+ delete in of await yield function class interface enum type import export const let var async extends
31
+ implements null undefined true false static public private protected readonly declare abstract as
32
+ satisfies from keyof namespace module get set constructor`.split(/\s+/),
33
+ );
34
+ const CONTEXTUAL = new Set(
35
+ "declare type of from as get set module namespace keyof readonly abstract satisfies".split(" "),
36
+ );
37
+ const EXTS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"];
38
+
39
+ function parse(tk) {
40
+ const t = tk.t;
41
+ const types = [];
42
+ const fns = [];
43
+ const gl = {};
44
+ const vars = [];
45
+ let defName = null;
46
+ const spans = [];
47
+
48
+ const walk = (from, to, owner, ownerKind) => {
49
+ let i = from;
50
+ let isStatic = false;
51
+ while (i < to) {
52
+ tick(tk);
53
+ const s = t[i];
54
+ if (s === "@") {
55
+ i += 2;
56
+ if (t[i] === "(" && tk.m[i] > i) i = tk.m[i] + 1;
57
+ continue;
58
+ }
59
+ if (
60
+ (s === "get" || s === "set" || s === "async" || s === "static") &&
61
+ owner &&
62
+ (isIdent(t[i + 1]) || t[i + 1] === "*" || t[i + 1] === "[")
63
+ ) {
64
+ if (s === "static") isStatic = true;
65
+ i++;
66
+ continue;
67
+ }
68
+ if (s === "default" && !owner && !defName) {
69
+ let k = i + 1;
70
+ if (t[k] === "async") k++;
71
+ if (t[k] === "function" || t[k] === "class") {
72
+ k++;
73
+ if (t[k] === "*") k++;
74
+ if (isIdent(t[k])) defName = t[k];
75
+ } else if (isIdent(t[k]) && (t[k + 1] === ";" || tk.first[k + 1] === 1)) defName = t[k];
76
+ }
77
+ if (MODS.has(s) && s !== "get" && s !== "set") {
78
+ if (s === "static") isStatic = true;
79
+ i++;
80
+ continue;
81
+ }
82
+ if ((s === "class" || s === "interface" || s === "enum") && isIdent(t[i + 1]) && !owner) {
83
+ spans.push([i, (i = typeDecl(i, to))]);
84
+ continue;
85
+ }
86
+ if (
87
+ (s === "class" || s === "interface" || s === "enum") &&
88
+ isIdent(t[i + 1]) &&
89
+ ownerKind === "ns"
90
+ ) {
91
+ i = typeDecl(i, to);
92
+ continue;
93
+ }
94
+ if ((s === "namespace" || s === "module") && isIdent(t[i + 1]) && t[i + 2] === "{") {
95
+ walk(i + 3, tk.m[i + 2], null, "ns");
96
+ i = tk.m[i + 2] + 1;
97
+ continue;
98
+ }
99
+ if (s === "function" && !owner) {
100
+ spans.push([i, (i = funcDecl(i, to))]);
101
+ continue;
102
+ }
103
+ if ((s === "const" || s === "let" || s === "var") && !owner) {
104
+ spans.push([i, (i = varDecl(i, to))]);
105
+ continue;
106
+ }
107
+ if (owner && ownerKind !== "ns" && (isIdent(s) || s === "[" || s === "#" || s === "*")) {
108
+ i = member(i, to, owner, ownerKind, isStatic);
109
+ isStatic = false;
110
+ continue;
111
+ }
112
+ if (s === "{" && tk.m[i] > i) {
113
+ i = tk.m[i] + 1;
114
+ continue;
115
+ }
116
+ isStatic = false;
117
+ i++;
118
+ }
119
+ };
120
+
121
+ const typeDecl = (i, to) => {
122
+ const kw = t[i];
123
+ const name = t[i + 1];
124
+ let j = i + 2;
125
+ const g = genericNames(tk, j);
126
+ j = g.next;
127
+ const sup = [];
128
+ const lim = Math.min(to, j + MAX_HEADER_TOKENS);
129
+ while (j < lim && t[j] !== "{") {
130
+ if (t[j] === "extends" || t[j] === "implements") {
131
+ let k = j + 1;
132
+ while (k < lim && t[k] !== "{" && t[k] !== "implements" && t[k] !== "extends") {
133
+ k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
134
+ }
135
+ sup.push(...typeList(tk, j + 1, k));
136
+ j = k;
137
+ } else j++;
138
+ }
139
+ if (t[j] !== "{" || tk.m[j] < 0) return i + 2;
140
+ const rec = {
141
+ n: name,
142
+ k: kw === "interface" ? "interface" : kw,
143
+ line: tk.line[i],
144
+ end: tk.line[tk.m[j]],
145
+ sup,
146
+ ...(g.gen.length ? { gen: g.gen } : {}),
147
+ f: {},
148
+ };
149
+ types.push(rec);
150
+ walk(j + 1, tk.m[j], name, kw);
151
+ return tk.m[j] + 1;
152
+ };
153
+
154
+ const readSig = (open, to) => {
155
+ const sig = paramsColon(tk, open, { mods: MODS, union: true, optional: true });
156
+ const props = [];
157
+ for (const [a, b] of splitTop(tk, open)) {
158
+ let k = a;
159
+ let isProp = false;
160
+ while (["public", "private", "protected", "readonly"].includes(t[k])) {
161
+ isProp = true;
162
+ k++;
163
+ }
164
+ if (isProp && isIdent(t[k]) && t[k + 1] === ":") {
165
+ const r = readType(tk, k + 2, { limit: b, union: true });
166
+ if (r.name) props.push([t[k], r.name]);
167
+ }
168
+ }
169
+ let j = tk.m[open] + 1;
170
+ let ret = null;
171
+ if (t[j] === ":" && t[j + 1] === "{" && tk.m[j + 1] > j + 1) {
172
+ j = tk.m[j + 1] + 1;
173
+ for (;;) {
174
+ while (t[j] === "[" && t[j + 1] === "]") j += 2;
175
+ if (t[j] !== "|" && t[j] !== "&") break;
176
+ if (t[j + 1] === "{" && tk.m[j + 1] > j + 1) j = tk.m[j + 1] + 1;
177
+ else j = readType(tk, j + 1, { limit: to }).next;
178
+ }
179
+ } else if (t[j] === ":") {
180
+ const r = readType(tk, j + 1, { limit: to, union: true });
181
+ ret = r.name;
182
+ j = r.next;
183
+ while (t[j] === "[" && t[j + 1] === "]") j += 2;
184
+ }
185
+ return { sig, props, ret, next: j, pr: [open + 1, tk.m[open]] };
186
+ };
187
+
188
+ const bodyAt = (j, to) => {
189
+ if (t[j] === "{" && tk.m[j] > j) return { body: [j + 1, tk.m[j]], next: tk.m[j] + 1 };
190
+ if (t[j] === "=>") {
191
+ if (t[j + 1] === "{" && tk.m[j + 1] > j + 1) {
192
+ return { body: [j + 2, tk.m[j + 1]], next: tk.m[j + 1] + 1 };
193
+ }
194
+ const end = exprEnd(tk, j + 1, to);
195
+ return { body: [j + 1, end], next: end };
196
+ }
197
+ return null;
198
+ };
199
+
200
+ const funcDecl = (i, to) => {
201
+ let j = i + 1;
202
+ if (t[j] === "*") j++;
203
+ if (!isIdent(t[j])) return i + 1;
204
+ const name = t[j];
205
+ j++;
206
+ const g = genericNames(tk, j);
207
+ j = g.next;
208
+ if (t[j] !== "(" || tk.m[j] < 0) return i + 1;
209
+ const { sig, ret, next, pr } = readSig(j, to);
210
+ const b = bodyAt(next, to);
211
+ fns.push({
212
+ n: name,
213
+ o: null,
214
+ pr,
215
+ a: [sig.min, sig.max],
216
+ p: sig.params,
217
+ r: ret,
218
+ l: tk.line[i],
219
+ e: tk.line[b ? Math.max(b.body[1], b.body[0]) : i],
220
+ ...(g.gen.length ? { g: g.gen } : {}),
221
+ body: b ? b.body : null,
222
+ });
223
+ return b ? b.next : next;
224
+ };
225
+
226
+ const varDecl = (i, to, local = false) => {
227
+ let j = i + 1;
228
+ if (!isIdent(t[j])) return i + 1;
229
+ const name = t[j];
230
+ j++;
231
+ let type = null;
232
+ if (t[j] === ":") {
233
+ const r = readType(tk, j + 1, { limit: to, union: true });
234
+ type = r.name;
235
+ j = r.next;
236
+ }
237
+ if (t[j] !== "=") return j;
238
+ j++;
239
+ if (t[j] === "async") j++;
240
+ if (t[j] === "function") {
241
+ let k = j + 1;
242
+ if (t[k] === "*") k++;
243
+ if (isIdent(t[k])) k++;
244
+ const g = genericNames(tk, k);
245
+ k = g.next;
246
+ if (t[k] === "(" && tk.m[k] > k) {
247
+ const { sig, ret, next, pr } = readSig(k, to);
248
+ const b = bodyAt(next, to);
249
+ fns.push({
250
+ n: name,
251
+ o: null,
252
+ pr,
253
+ a: [sig.min, sig.max],
254
+ p: sig.params,
255
+ r: ret || type,
256
+ l: tk.line[i],
257
+ e: tk.line[b ? b.body[1] : i],
258
+ body: b ? b.body : null,
259
+ });
260
+ return b ? b.next : next;
261
+ }
262
+ }
263
+ let k = j;
264
+ const g = genericNames(tk, k);
265
+ k = g.next;
266
+ if (t[k] === "(" && tk.m[k] > k) {
267
+ const { sig, ret, next, pr } = readSig(k, to);
268
+ if (t[next] === "=>") {
269
+ const b = bodyAt(next, to);
270
+ fns.push({
271
+ n: name,
272
+ o: null,
273
+ pr,
274
+ a: [sig.min, sig.max],
275
+ p: sig.params,
276
+ r: ret,
277
+ l: tk.line[i],
278
+ e: tk.line[b.body[1]] || tk.line[i],
279
+ body: b.body,
280
+ });
281
+ return b.next;
282
+ }
283
+ } else if (isIdent(t[k]) && t[k + 1] === "=>") {
284
+ const b = bodyAt(k + 1, to);
285
+ fns.push({
286
+ n: name,
287
+ o: null,
288
+ a: [1, 1],
289
+ p: [[t[k], t[k], null]],
290
+ r: null,
291
+ l: tk.line[i],
292
+ e: tk.line[b.body[1]] || tk.line[i],
293
+ body: b.body,
294
+ });
295
+ return b.next;
296
+ }
297
+ if (!type && t[j] === "new" && isIdent(t[j + 1])) type = readType(tk, j + 1).name;
298
+ if (type && !local) gl[name] = type;
299
+ if (!local && !vars.includes(name)) vars.push(name);
300
+ return j;
301
+ };
302
+
303
+ const member = (i, to, owner, ownerKind, isStatic) => {
304
+ let j = i;
305
+ if (t[j] === "*") j++;
306
+ if (t[j] === "#") j++;
307
+ let name;
308
+ if (t[j] === "[" && tk.m[j] > j) {
309
+ name = null;
310
+ j = tk.m[j] + 1;
311
+ } else if (isIdent(t[j])) {
312
+ name = t[j];
313
+ j++;
314
+ } else return i + 1;
315
+ if (t[j] === "?" || t[j] === "!") j++;
316
+ const g = genericNames(tk, j);
317
+ j = g.next;
318
+ const rec = [...types].reverse().find((x) => x.n === owner);
319
+ if (t[j] === "(" && tk.m[j] > j && name) {
320
+ const { sig, props, ret, next, pr } = readSig(j, to);
321
+ const ctor = name === "constructor";
322
+ if (ctor && rec) for (const [pn, pt] of props) rec.f[pn] = pt;
323
+ const b = bodyAt(next, to);
324
+ let after = next;
325
+ if (b) after = b.next;
326
+ else if (t[after] === ";") after++;
327
+ fns.push({
328
+ n: ctor ? "constructor" : name,
329
+ o: owner,
330
+ pr,
331
+ a: [sig.min, sig.max],
332
+ p: sig.params,
333
+ r: ctor ? owner : ret,
334
+ l: tk.line[i],
335
+ e: tk.line[Math.max(i, after - 1)],
336
+ ...(isStatic ? { s: 1 } : {}),
337
+ ...(!b ? { ab: 1 } : {}),
338
+ ...(g.gen.length ? { g: g.gen } : {}),
339
+ body: b ? b.body : null,
340
+ });
341
+ return after;
342
+ }
343
+ let type = null;
344
+ if (t[j] === ":") {
345
+ const r = readType(tk, j + 1, { limit: to, union: true });
346
+ type = r.name;
347
+ j = r.next;
348
+ }
349
+ if (t[j] === "=" && name) {
350
+ let k = j + 1;
351
+ if (t[k] === "async") k++;
352
+ const gg = genericNames(tk, k);
353
+ const q = gg.next;
354
+ let arrow = null;
355
+ if (t[q] === "(" && tk.m[q] > q) {
356
+ const r = readSig(q, to);
357
+ if (t[r.next] === "=>") arrow = { sig: r.sig, ret: r.ret, at: r.next, pr: r.pr };
358
+ } else if (isIdent(t[q]) && t[q + 1] === "=>") {
359
+ arrow = { sig: { params: [[t[q], t[q], null]], min: 1, max: 1 }, ret: null, at: q + 1 };
360
+ }
361
+ if (arrow) {
362
+ const b = bodyAt(arrow.at, to);
363
+ fns.push({
364
+ n: name,
365
+ o: owner,
366
+ pr: arrow.pr,
367
+ a: [arrow.sig.min, arrow.sig.max],
368
+ p: arrow.sig.params,
369
+ r: arrow.ret,
370
+ l: tk.line[i],
371
+ e: tk.line[b.body[1]] || tk.line[i],
372
+ ...(isStatic ? { s: 1 } : {}),
373
+ body: b.body,
374
+ });
375
+ return b.next;
376
+ }
377
+ if (!type && t[k] === "new" && isIdent(t[k + 1])) type = readType(tk, k + 1).name;
378
+ j = exprEnd(tk, j + 1, to);
379
+ }
380
+ if (rec && name && type) rec.f[name] = type;
381
+ if (t[j] === ";" || t[j] === ",") j++;
382
+ return Math.max(j, i + 1);
383
+ };
384
+
385
+ walk(0, tk.n, null, null);
386
+
387
+ const LOCAL_CAP = 4000;
388
+ const queue = fns.filter((f) => f.body);
389
+ for (let qi = 0; qi < queue.length && fns.length < LOCAL_CAP; qi++) {
390
+ const parent = queue[qi];
391
+ const [from, to] = parent.body;
392
+ const open = [];
393
+ for (let i = from; i < to;) {
394
+ tick(tk);
395
+ const s = t[i];
396
+ if (s === "{" && tk.m[i] > i) {
397
+ open.push(i);
398
+ i++;
399
+ continue;
400
+ }
401
+ if (s === "}") {
402
+ open.pop();
403
+ i++;
404
+ continue;
405
+ }
406
+ const prev = i > from ? t[i - 1] : "{";
407
+ const stmt = tk.first[i] === 1 || ";{}".includes(prev) || prev === "async";
408
+ const start = fns.length;
409
+ let next = i + 1;
410
+ let bound = false;
411
+ if (stmt && s === "async" && t[i + 1] === "function") next = funcDecl(i + 1, to);
412
+ else if (stmt && s === "function") next = funcDecl(i, to);
413
+ else if (stmt && (s === "const" || s === "let" || s === "var")) {
414
+ next = varDecl(i, to, true);
415
+ bound = true;
416
+ }
417
+ const block = open.length ? open[open.length - 1] : -1;
418
+ for (let k = start; k < fns.length; k++) {
419
+ const f = fns[k];
420
+ f.lo = 1;
421
+ f.pl = parent.l;
422
+ f.pe = parent.e;
423
+ if (block >= 0 && tk.m[block] > block) {
424
+ f.vs = tk.line[block];
425
+ f.ve = tk.line[tk.m[block]];
426
+ }
427
+ if (bound) f.lv = 1;
428
+ if (f.body) queue.push(f);
429
+ }
430
+ i = Math.max(next, i + 1);
431
+ }
432
+ }
433
+ return { types, fns, binds: [], gl, vars, def: defName, top: complement(spans, tk.n, tk) };
434
+ }
435
+
436
+ /** Does the initializer at i read a module (`require("m")`, `await import("m")`)? */
437
+ function loadsModule(tk, i) {
438
+ if (i == null) return false;
439
+ let j = i;
440
+ if (tk.t[j] === "await") j++;
441
+ return (tk.t[j] === "require" || tk.t[j] === "import") && tk.t[j + 1] === "(";
442
+ }
443
+
444
+ function localDecl(tk, i, end) {
445
+ const t = tk.t;
446
+ const s = t[i];
447
+ const fnAt = s === "async" && t[i + 1] === "function" ? i + 1 : s === "function" ? i : -1;
448
+ if (fnAt >= 0) {
449
+ const named = t[fnAt + 1] === "*" ? fnAt + 2 : fnAt + 1;
450
+ if (isIdent(t[named]) && t[named + 1] === "(")
451
+ return { name: t[named], type: null, init: null, next: named + 1 };
452
+ }
453
+ if (s === "const" || s === "let" || s === "var") {
454
+ let j = i + 1;
455
+ if (t[j] === "{" || t[j] === "[") {
456
+ const close = tk.m[j];
457
+ if (close < 0) return null;
458
+ const names = patternNames(tk, j, close);
459
+ const after = close + 1;
460
+ const init = t[after] === "=" ? after + 1 : null;
461
+ return {
462
+ name: names[0] || "_",
463
+ also: names.slice(1),
464
+ type: null,
465
+ init,
466
+ next: after,
467
+ bound: loadsModule(tk, init),
468
+ ...(t.slice(j + 1, close).includes("=") ? { scan: [j + 1, close] } : {}),
469
+ };
470
+ }
471
+ if (!isIdent(t[j])) return null;
472
+ const name = t[j];
473
+ j++;
474
+ let type = null;
475
+ if (t[j] === ":") {
476
+ const r = readType(tk, j + 1, { limit: end, union: true });
477
+ type = r.name;
478
+ j = r.next;
479
+ }
480
+ if (t[j] === "=")
481
+ return { name, type, init: j + 1, next: j + 1, bound: loadsModule(tk, j + 1) };
482
+ return type ? { name, type, init: null, next: j } : null;
483
+ }
484
+ if (s === "for" && t[i + 1] === "(") {
485
+ let k = i + 2;
486
+ if (["const", "let", "var"].includes(t[k])) k++;
487
+ if (isIdent(t[k]) && (t[k + 1] === "of" || t[k + 1] === "in")) {
488
+ return { name: t[k], type: null, init: null, next: k + 1 };
489
+ }
490
+ }
491
+ if (s === "catch" && t[i + 1] === "(" && isIdent(t[i + 2])) {
492
+ return { name: t[i + 2], type: null, init: null, next: i + 3 };
493
+ }
494
+ return null;
495
+ }
496
+
497
+ function lambdaParams(tk, i) {
498
+ const t = tk.t;
499
+ if (t[i] === "(" && tk.m[i] > i && t[tk.m[i] + 1] === "=>") {
500
+ const params = [];
501
+ for (const [a, b] of splitTop(tk, i)) {
502
+ if (isIdent(t[a])) {
503
+ const type = t[a + 1] === ":" ? readType(tk, a + 2, { limit: b, union: true }).name : null;
504
+ params.push([t[a], type]);
505
+ }
506
+ }
507
+ return params.length ? { params } : null;
508
+ }
509
+ if (isIdent(t[i]) && t[i + 1] === "=>" && !t[i - 1]?.startsWith("."))
510
+ return { params: [[t[i], null]] };
511
+ return null;
512
+ }
513
+
514
+ function resolveRelative(fromPath, spec) {
515
+ const base = fromPath.split("/").slice(0, -1);
516
+ for (const part of spec.split("/")) {
517
+ if (part === "." || part === "") continue;
518
+ if (part === "..") base.pop();
519
+ else base.push(part);
520
+ }
521
+ return base.join("/");
522
+ }
523
+
524
+ const IMPORT_WINDOW = 1500;
525
+ const MAX_IMPORTS = 5000;
526
+
527
+ /**
528
+ * `import <clause> from "<module>"` statements, read without backtracking: the
529
+ * clause runs from the keyword to the first quote or semicolon, so a file of
530
+ * `import` lines with no module costs one bounded look per line.
531
+ */
532
+ function importStatements(text) {
533
+ const found = [];
534
+ const re = /^[ \t]*import\b/gm;
535
+ while (re.exec(text) && found.length < MAX_IMPORTS) {
536
+ const window = text.slice(re.lastIndex, re.lastIndex + IMPORT_WINDOW);
537
+ let q = 0;
538
+ while (q < window.length && window[q] !== '"' && window[q] !== "'" && window[q] !== ";") q++;
539
+ if (q >= window.length || window[q] === ";") continue;
540
+ const end = window.indexOf(window[q], q + 1);
541
+ if (end < 0 || end - q > 400) continue;
542
+ const head = window.slice(0, q).trimEnd();
543
+ if (!head.endsWith("from") || !/[\s}*,]/.test(head[head.length - 5] ?? " ")) continue;
544
+ found.push({ clause: head.slice(0, -4).trim(), mod: window.slice(q + 1, end) });
545
+ }
546
+ return found;
547
+ }
548
+
549
+ function binds(text) {
550
+ const out = [];
551
+ const add = (l, m, x) => l && out.push({ l, m, x });
552
+ for (const { clause, mod } of importStatements(text)) {
553
+ const named = clause.match(/\{([^}]*)\}/);
554
+ const rest = clause
555
+ .replace(/\{[^}]*\}/, "")
556
+ .replace(/,\s*$/, "")
557
+ .trim();
558
+ const ns = rest.match(/\*\s+as\s+([\w$]+)/);
559
+ if (ns) add(ns[1], mod, null);
560
+ else if (rest) {
561
+ const local = rest.replace(/,$/, "").trim();
562
+ if (local) out.push({ l: local, m: mod, x: local, d: 1 });
563
+ }
564
+ if (named) {
565
+ for (const part of named[1].split(",")) {
566
+ const [a, b] = part.trim().split(/\s+as\s+/);
567
+ if (a) add(b || a, mod, a);
568
+ }
569
+ }
570
+ }
571
+ for (const m of text.matchAll(
572
+ /(?:const|let|var)\s{1,4}(\{[^}]{0,2000}\}|[\w$]{1,200})\s{0,4}=\s{0,4}(?:await\s{1,4})?(?:require|import)\(\s{0,4}["']([^"'\n]{1,300})["']\s{0,4}\)/g,
573
+ )) {
574
+ if (m[1].startsWith("{")) {
575
+ for (const part of m[1].slice(1, -1).split(",")) {
576
+ const [a, b] = part.trim().split(/\s*:\s*/);
577
+ if (a) add(b || a, m[2], a);
578
+ }
579
+ } else add(m[1], m[2], null);
580
+ }
581
+ return out;
582
+ }
583
+
584
+ /**
585
+ * `export { a, b as c } from "m"` and `export * from "m"`, read with bounded
586
+ * windows: what a module re-exports, so an import of the barrel can be followed
587
+ * to the file that defines the name.
588
+ */
589
+ function reexports(text) {
590
+ const out = [];
591
+ const re = /^[ \t]*export\b/gm;
592
+ while (re.exec(text) && out.length < MAX_IMPORTS) {
593
+ const window = text.slice(re.lastIndex, re.lastIndex + IMPORT_WINDOW);
594
+ let k = 0;
595
+ const skip = () => {
596
+ while (k < window.length && /\s/.test(window[k])) k++;
597
+ };
598
+ skip();
599
+ if (window.startsWith("type", k) && /\s/.test(window[k + 4] ?? "")) {
600
+ k += 4;
601
+ skip();
602
+ }
603
+ let star = false;
604
+ let names = null;
605
+ if (window[k] === "*") {
606
+ star = true;
607
+ k++;
608
+ skip();
609
+ if (window.startsWith("as", k) && /\s/.test(window[k + 2] ?? "")) continue;
610
+ } else if (window[k] === "{") {
611
+ const close = window.indexOf("}", k);
612
+ if (close < 0) continue;
613
+ names = window
614
+ .slice(k + 1, close)
615
+ .split(",")
616
+ .map((part) =>
617
+ part
618
+ .trim()
619
+ .replace(/^type\s+/, "")
620
+ .split(/\s+as\s+/),
621
+ )
622
+ .filter((p) => p[0] && p[0] !== "default")
623
+ .map((p) => [p[1] || p[0], p[0]]);
624
+ k = close + 1;
625
+ skip();
626
+ } else continue;
627
+ if (names && !window.startsWith("from", k)) {
628
+ if (names.length) out.push({ m: null, n: names });
629
+ continue;
630
+ }
631
+ if (!window.startsWith("from", k)) continue;
632
+ k += 4;
633
+ skip();
634
+ const quote = window[k];
635
+ if (quote !== '"' && quote !== "'") continue;
636
+ const end = window.indexOf(quote, k + 1);
637
+ if (end < 0 || end - k > 400) continue;
638
+ out.push({ m: window.slice(k + 1, end), ...(star ? { star: 1 } : { n: names }) });
639
+ }
640
+ return out;
641
+ }
642
+
643
+ function moduleSuffixes(spec, fromPath) {
644
+ let base;
645
+ if (spec.startsWith(".")) base = resolveRelative(fromPath, spec);
646
+ else if (spec.startsWith("@/") || spec.startsWith("~/")) base = spec.slice(2);
647
+ else return [];
648
+ const stem = base.replace(/\.(m?[jt]sx?|cjs|cts)$/, "");
649
+ return [...EXTS.map((e) => `${stem}${e}`), ...EXTS.map((e) => `${stem}/index${e}`)];
650
+ }
651
+
652
+ export default {
653
+ id: "typescript",
654
+ stringType: "string",
655
+ exts: EXTS,
656
+ implicitSelf: false,
657
+ initName: "constructor",
658
+ selfWords: new Set(["this"]),
659
+ superWords: new Set(["super"]),
660
+ newKeyword: "new",
661
+ memberOps: new Set([".", "?.", "!."]),
662
+ labelOps: [":"],
663
+ trailingClosure: false,
664
+ genericCalls: true,
665
+ castWords: new Set(["as", "satisfies"]),
666
+ keywords: KEYWORDS,
667
+ contextual: CONTEXTUAL,
668
+ jsx: true,
669
+ declWords: new Set([
670
+ "function",
671
+ "class",
672
+ "interface",
673
+ "enum",
674
+ "type",
675
+ "new",
676
+ "import",
677
+ "const",
678
+ "let",
679
+ "var",
680
+ "namespace",
681
+ ]),
682
+ condWords: null,
683
+ union: true,
684
+ keepStrings: true,
685
+ topLevel: true,
686
+ parse,
687
+ localDecl,
688
+ lambdaParams,
689
+ binds,
690
+ reexports,
691
+ moduleSuffixes,
692
+ };