@mmerterden/multi-agent-pipeline 23.3.0 → 23.5.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 (239) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +27 -8
  3. package/README.tr.md +28 -9
  4. package/SECURITY.md +16 -0
  5. package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
  6. package/docs/adr/0010-own-code-graph.md +299 -8
  7. package/docs/architecture.md +3 -3
  8. package/docs/ecosystem.md +10 -10
  9. package/docs/engineering.md +4 -4
  10. package/docs/facts.json +8 -8
  11. package/docs/features.md +5 -5
  12. package/docs/performance.md +17 -17
  13. package/install/_dev-only-files.mjs +9 -0
  14. package/install/_platform-filter.mjs +2 -55
  15. package/install/claude.mjs +28 -2
  16. package/install/codex.mjs +1 -3
  17. package/install/copilot.mjs +4 -8
  18. package/install/templates/claude-hooks.json +32 -1
  19. package/manifest.json +236 -167
  20. package/package.json +11 -3
  21. package/pipeline/commands/multi-agent/SKILL.md +1 -1
  22. package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
  23. package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
  24. package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
  25. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  26. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  27. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  28. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  29. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  30. package/pipeline/contract/CHANGELOG.md +63 -0
  31. package/pipeline/contract/README.md +1 -0
  32. package/pipeline/contract/build.mjs +13 -1
  33. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  34. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  35. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  36. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  37. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  38. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  39. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  40. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  41. package/pipeline/contract/fixtures/runs-running.json +4 -1
  42. package/pipeline/contract/manifest.json +41 -15
  43. package/pipeline/contract/types/index.d.ts +81 -3
  44. package/pipeline/lib/detach-self.mjs +95 -0
  45. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  46. package/pipeline/lib/rotated-log.mjs +93 -0
  47. package/pipeline/lib/stack-detect.sh +1 -1
  48. package/pipeline/lib/tls-trust.mjs +29 -0
  49. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  50. package/pipeline/lib/usage-names.generated.mjs +613 -0
  51. package/pipeline/lib/usage-run-key.mjs +235 -0
  52. package/pipeline/lib/usage-vocab.mjs +210 -0
  53. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  54. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  55. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  56. package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
  57. package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
  58. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  59. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  60. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  61. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  62. package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
  63. package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
  64. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  65. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  66. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  67. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  68. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  69. package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
  70. package/pipeline/multi-agent-refs/help/en.md +3 -2
  71. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  72. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  73. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
  74. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  75. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  76. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  77. package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
  78. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  79. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  80. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  81. package/pipeline/office/index.html +1309 -236
  82. package/pipeline/office/toolkit.json +1 -1
  83. package/pipeline/rules/outside-the-pipeline.md +1 -1
  84. package/pipeline/schemas/activity.schema.json +23 -0
  85. package/pipeline/schemas/agent-state.schema.json +6 -1
  86. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  87. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  88. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  89. package/pipeline/schemas/code-graph.schema.json +2 -2
  90. package/pipeline/schemas/examples/design-check-config.json +27 -0
  91. package/pipeline/schemas/learning-curve.schema.json +67 -0
  92. package/pipeline/schemas/mcp-health.schema.json +96 -0
  93. package/pipeline/schemas/office-jobs.json +69 -2
  94. package/pipeline/schemas/office-jobs.schema.json +8 -1
  95. package/pipeline/schemas/phases.json +5 -0
  96. package/pipeline/schemas/phases.schema.json +8 -0
  97. package/pipeline/schemas/prefs.schema.json +46 -12
  98. package/pipeline/schemas/runs-index.schema.json +17 -0
  99. package/pipeline/schemas/toolkit-path-params.json +78 -8
  100. package/pipeline/scripts/README.md +1 -0
  101. package/pipeline/scripts/_code-graph.mjs +184 -103
  102. package/pipeline/scripts/_contract-core.mjs +1 -1
  103. package/pipeline/scripts/_contract-routes-office.mjs +33 -0
  104. package/pipeline/scripts/_diff-impact.mjs +21 -2
  105. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  106. package/pipeline/scripts/_http-post.mjs +103 -115
  107. package/pipeline/scripts/_safe-read.mjs +57 -0
  108. package/pipeline/scripts/_skill-practices.mjs +26 -0
  109. package/pipeline/scripts/_strip-code.mjs +380 -0
  110. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  111. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  112. package/pipeline/scripts/build-stack-plugins.mjs +1 -47
  113. package/pipeline/scripts/call-graph/index.mjs +78 -0
  114. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  115. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  116. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  117. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  118. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  119. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  120. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  121. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  122. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  123. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  124. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  125. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  126. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  127. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  128. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  129. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  130. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  131. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  132. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  133. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  134. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  135. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  136. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  137. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  138. package/pipeline/scripts/contract-server.mjs +3 -0
  139. package/pipeline/scripts/design-check-config.mjs +205 -0
  140. package/pipeline/scripts/feedback-send.mjs +26 -26
  141. package/pipeline/scripts/gate-ledger.mjs +2 -1
  142. package/pipeline/scripts/gen-facts.mjs +1 -2
  143. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  144. package/pipeline/scripts/graph-affected.mjs +109 -20
  145. package/pipeline/scripts/graph-build.mjs +95 -15
  146. package/pipeline/scripts/graph-export.mjs +272 -0
  147. package/pipeline/scripts/graph-hint.mjs +15 -2
  148. package/pipeline/scripts/graph-query.mjs +305 -26
  149. package/pipeline/scripts/graph-report.mjs +187 -1
  150. package/pipeline/scripts/health-report.mjs +3 -4
  151. package/pipeline/scripts/infra/docs.mjs +317 -0
  152. package/pipeline/scripts/infra/extract.mjs +998 -0
  153. package/pipeline/scripts/infra/graph.mjs +245 -0
  154. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  155. package/pipeline/scripts/job-launch.mjs +67 -2
  156. package/pipeline/scripts/learning-curve.mjs +288 -178
  157. package/pipeline/scripts/log-metric.sh +10 -1
  158. package/pipeline/scripts/mcp-health.mjs +309 -0
  159. package/pipeline/scripts/note-agent-event.mjs +3 -4
  160. package/pipeline/scripts/note-command-use.mjs +333 -0
  161. package/pipeline/scripts/note-command-use.sh +126 -0
  162. package/pipeline/scripts/note-mcp-call.sh +89 -0
  163. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  164. package/pipeline/scripts/note-session.sh +62 -3
  165. package/pipeline/scripts/note-skill-use.mjs +58 -2
  166. package/pipeline/scripts/office-build.mjs +115 -1
  167. package/pipeline/scripts/office-memory.mjs +14 -5
  168. package/pipeline/scripts/pair.mjs +333 -0
  169. package/pipeline/scripts/pre-push-check.sh +1 -1
  170. package/pipeline/scripts/remote/cbor.mjs +128 -0
  171. package/pipeline/scripts/remote/contract.mjs +98 -0
  172. package/pipeline/scripts/remote/handler.mjs +330 -0
  173. package/pipeline/scripts/remote/handles.mjs +57 -0
  174. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  175. package/pipeline/scripts/remote/listener.mjs +204 -0
  176. package/pipeline/scripts/remote/lockout.mjs +103 -0
  177. package/pipeline/scripts/remote/nonces.mjs +61 -0
  178. package/pipeline/scripts/remote/pairing.mjs +519 -0
  179. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  180. package/pipeline/scripts/remote/store.mjs +191 -0
  181. package/pipeline/scripts/remote/transport.mjs +211 -0
  182. package/pipeline/scripts/remote/verbs.json +70 -0
  183. package/pipeline/scripts/remote/verbs.mjs +217 -0
  184. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  185. package/pipeline/scripts/remote/wire.mjs +364 -0
  186. package/pipeline/scripts/remote-listener.mjs +83 -0
  187. package/pipeline/scripts/route-learn.mjs +4 -4
  188. package/pipeline/scripts/run-kill.mjs +1 -1
  189. package/pipeline/scripts/run-write.mjs +13 -2
  190. package/pipeline/scripts/runs-index.mjs +30 -3
  191. package/pipeline/scripts/search-logs.sh +9 -0
  192. package/pipeline/scripts/session-brief.mjs +458 -0
  193. package/pipeline/scripts/session-brief.sh +130 -0
  194. package/pipeline/scripts/skill-usage.mjs +16 -5
  195. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  196. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  197. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  198. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  199. package/pipeline/scripts/token-budget-report.mjs +3 -2
  200. package/pipeline/scripts/uninstall.mjs +29 -0
  201. package/pipeline/scripts/usage-access.mjs +16 -31
  202. package/pipeline/scripts/usage-health.mjs +31 -62
  203. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  204. package/pipeline/scripts/usage-register.mjs +39 -29
  205. package/pipeline/scripts/usage-report.mjs +579 -178
  206. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  207. package/pipeline/scripts/write-state.mjs +39 -0
  208. package/pipeline/skills/.skill-manifest.json +21 -17
  209. package/pipeline/skills/.skills-index.json +13 -2
  210. package/pipeline/skills/shared/README.md +5 -4
  211. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  212. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  213. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  214. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  215. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  216. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  217. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  218. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  219. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  220. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  221. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  222. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  223. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  224. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  225. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  226. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  227. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  228. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  229. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  230. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  231. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  232. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  233. package/pipeline/skills/skills-index.md +3 -2
  234. package/docs/FIGMA_PIPELINE.md +0 -137
  235. package/pipeline/lib/identifier-scan.mjs +0 -156
  236. package/pipeline/scripts/_renamed-skills.mjs +0 -164
  237. package/pipeline/scripts/publish-staged.mjs +0 -324
  238. package/pipeline/skills/renamed.json +0 -30
  239. package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
@@ -0,0 +1,303 @@
1
+ /**
2
+ * @file go.mjs - Go profile for the call-edge scanner.
3
+ *
4
+ * Methods hang off their receiver type, struct embedding promotes the embedded
5
+ * type's methods, an interface is satisfied structurally (a type with every
6
+ * method name of the interface is an implementer), and a package is a
7
+ * directory. Not modelled: generics constraints, method values, function-typed
8
+ * variables, and which of two same-named imports a build tag selects.
9
+ *
10
+ * @module pipeline/scripts/call-graph/lang/go
11
+ */
12
+
13
+ import { isIdent, readType, splitTop, tick } from "../lex.mjs";
14
+
15
+ const KEYWORDS = new Set(
16
+ `if for switch select case default return go defer func type struct interface map chan var const
17
+ range break continue fallthrough goto package import else nil true false iota make new len cap
18
+ append copy delete panic recover print println`.split(/\s+/),
19
+ );
20
+
21
+ function readParams(tk, open) {
22
+ const params = [];
23
+ let min = 0;
24
+ let max = 0;
25
+ const parts = splitTop(tk, open);
26
+ const named = parts.some(
27
+ ([a, b]) => isIdent(tk.t[a]) && b - a > 1 && tk.t[a + 1] !== "." && tk.t[a + 1] !== "[",
28
+ );
29
+ let pendingNames = [];
30
+ for (const [a, b] of parts) {
31
+ let k = a;
32
+ let variadic = false;
33
+ if (named && isIdent(tk.t[k]) && b - a === 1) {
34
+ pendingNames.push(tk.t[k]);
35
+ continue;
36
+ }
37
+ let name = null;
38
+ if (named && isIdent(tk.t[k])) {
39
+ name = tk.t[k];
40
+ k++;
41
+ }
42
+ if (tk.t[k] === "...") {
43
+ variadic = true;
44
+ k++;
45
+ }
46
+ const r = readType(tk, k, { limit: b });
47
+ const names = name ? [...pendingNames, name] : [null];
48
+ pendingNames = [];
49
+ for (const nm of names) {
50
+ params.push([nm, nm || "_", variadic && r.name ? `[${r.name}]` : r.name]);
51
+ if (variadic) max = Infinity;
52
+ else if (max !== Infinity) max++;
53
+ if (!variadic) min++;
54
+ }
55
+ }
56
+ return { params, min, max };
57
+ }
58
+
59
+ function readResult(tk, j, to) {
60
+ const t = tk.t;
61
+ if (t[j] === "(" && tk.m[j] > j) {
62
+ const parts = splitTop(tk, j);
63
+ if (!parts.length) return { ret: null, next: tk.m[j] + 1 };
64
+ const [first, b] = parts[0];
65
+ const named =
66
+ isIdent(t[first]) && b - first > 1 && t[first + 1] !== "." && t[first + 1] !== "[";
67
+ return { ret: readType(tk, named ? first + 1 : first, { limit: b }).name, next: tk.m[j] + 1 };
68
+ }
69
+ if (isIdent(t[j]) || t[j] === "*" || t[j] === "[") {
70
+ const r = readType(tk, j, { limit: to });
71
+ return { ret: r.name, next: r.next };
72
+ }
73
+ return { ret: null, next: j };
74
+ }
75
+
76
+ function parse(tk) {
77
+ const t = tk.t;
78
+ const types = [];
79
+ const fns = [];
80
+
81
+ const typeSpec = (i, to) => {
82
+ const name = t[i];
83
+ let j = i + 1;
84
+ if (t[j] === "[" && tk.m[j] > j) j = tk.m[j] + 1;
85
+ if (t[j] === "=") j++;
86
+ const kw = t[j];
87
+ if ((kw === "struct" || kw === "interface") && t[j + 1] === "{" && tk.m[j + 1] > j + 1) {
88
+ const open = j + 1;
89
+ const close = tk.m[open];
90
+ const sup = [];
91
+ const f = {};
92
+ let k = open + 1;
93
+ while (k < close) {
94
+ const lineEnd = (() => {
95
+ let e = k;
96
+ while (e < close && !(tk.first[e] === 1 && e > k)) e++;
97
+ return e;
98
+ })();
99
+ if (kw === "struct") {
100
+ if (isIdent(t[k]) && lineEnd - k >= 2 && t[k + 1] !== ".") {
101
+ const names = [];
102
+ let q = k;
103
+ while (isIdent(t[q]) && t[q + 1] === ",") {
104
+ names.push(t[q]);
105
+ q += 2;
106
+ }
107
+ if (isIdent(t[q])) {
108
+ names.push(t[q]);
109
+ const r = readType(tk, q + 1, { limit: lineEnd });
110
+ for (const nm of names) if (r.name) f[nm] = r.name;
111
+ }
112
+ } else {
113
+ const r = readType(tk, k, { skip: new Set(["*"]), limit: lineEnd });
114
+ if (r.name) sup.push(r.name);
115
+ }
116
+ } else if (isIdent(t[k]) && t[k + 1] === "(" && tk.m[k + 1] > k + 1) {
117
+ const sig = readParams(tk, k + 1);
118
+ const res = readResult(tk, tk.m[k + 1] + 1, lineEnd);
119
+ fns.push({
120
+ n: t[k],
121
+ o: name,
122
+ a: [sig.min, sig.max],
123
+ p: sig.params,
124
+ r: res.ret,
125
+ l: tk.line[k],
126
+ e: tk.line[k],
127
+ ab: 1,
128
+ body: null,
129
+ });
130
+ } else if (isIdent(t[k]) && lineEnd - k === 1) sup.push(t[k]);
131
+ k = Math.max(lineEnd, k + 1);
132
+ }
133
+ types.push({ n: name, k: kw, line: tk.line[i], end: tk.line[close], sup, f });
134
+ return tk.m[open] + 1;
135
+ }
136
+ const r = readType(tk, j, { limit: to });
137
+ types.push({
138
+ n: name,
139
+ k: "type",
140
+ line: tk.line[i],
141
+ end: tk.line[i],
142
+ sup: r.name ? [r.name] : [],
143
+ f: {},
144
+ });
145
+ return r.next;
146
+ };
147
+
148
+ let i = 0;
149
+ while (i < tk.n) {
150
+ tick(tk);
151
+ const s = t[i];
152
+ if (s === "type" && tk.dep[i] === 0) {
153
+ if (t[i + 1] === "(" && tk.m[i + 1] > i + 1) {
154
+ let k = i + 2;
155
+ while (k < tk.m[i + 1]) {
156
+ if (isIdent(t[k]) && tk.first[k] === 1) k = typeSpec(k, tk.m[i + 1]);
157
+ else k++;
158
+ }
159
+ i = tk.m[i + 1] + 1;
160
+ } else if (isIdent(t[i + 1])) i = typeSpec(i + 1, tk.n);
161
+ else i++;
162
+ continue;
163
+ }
164
+ if (s === "func" && tk.dep[i] === 0) {
165
+ let j = i + 1;
166
+ let owner = null;
167
+ let recvName = null;
168
+ let recvType = null;
169
+ if (t[j] === "(" && tk.m[j] > j) {
170
+ const parts = splitTop(tk, j);
171
+ if (parts.length) {
172
+ const [a, b] = parts[0];
173
+ let q = a;
174
+ if (isIdent(t[q]) && b - a > 1 && t[q + 1] !== ".") {
175
+ recvName = t[q];
176
+ q++;
177
+ }
178
+ recvType = readType(tk, q, { limit: b }).name;
179
+ owner = recvType;
180
+ }
181
+ j = tk.m[j] + 1;
182
+ }
183
+ if (isIdent(t[j])) {
184
+ const name = t[j];
185
+ j++;
186
+ if (t[j] === "[" && tk.m[j] > j) j = tk.m[j] + 1;
187
+ if (t[j] === "(" && tk.m[j] > j) {
188
+ const sig = readParams(tk, j);
189
+ const res = readResult(tk, tk.m[j] + 1, tk.n);
190
+ let k = res.next;
191
+ while (k < tk.n && t[k] !== "{" && !(tk.first[k] === 1)) k++;
192
+ const body = t[k] === "{" && tk.m[k] > k ? [k + 1, tk.m[k]] : null;
193
+ const params = recvName ? [[null, recvName, recvType], ...sig.params] : sig.params;
194
+ fns.push({
195
+ n: name,
196
+ o: owner,
197
+ a: [sig.min, sig.max],
198
+ p: params,
199
+ r: res.ret,
200
+ l: tk.line[i],
201
+ e: tk.line[body ? body[1] : i],
202
+ ...(body ? {} : { ab: 1 }),
203
+ body,
204
+ });
205
+ i = body ? body[1] + 1 : k;
206
+ continue;
207
+ }
208
+ }
209
+ }
210
+ i++;
211
+ }
212
+ return { types, fns, binds: [] };
213
+ }
214
+
215
+ function localDecl(tk, i, end) {
216
+ const t = tk.t;
217
+ const s = t[i];
218
+ if (s === "var" && isIdent(t[i + 1])) {
219
+ const name = t[i + 1];
220
+ let j = i + 2;
221
+ let type = null;
222
+ if (t[j] !== "=") {
223
+ const r = readType(tk, j, { limit: end });
224
+ type = r.name;
225
+ j = r.next;
226
+ }
227
+ if (t[j] === "=") return { name, type, init: j + 1, next: j + 1 };
228
+ return type ? { name, type, init: null, next: j } : null;
229
+ }
230
+ if (s === "for") {
231
+ let k = i + 1;
232
+ const names = [];
233
+ while (k < end && isIdent(t[k]) && (t[k + 1] === "," || t[k + 1] === ":=")) {
234
+ if (t[k] !== "_") names.push(t[k]);
235
+ k += 2;
236
+ }
237
+ if (names.length && t[k - 1] === ":=")
238
+ return { name: names[0], also: names.slice(1), type: null, init: null, next: k };
239
+ return null;
240
+ }
241
+ if (!isIdent(s) || KEYWORDS.has(s) || tk.first[i] !== 1) {
242
+ if (!(
243
+ isIdent(s) &&
244
+ (t[i - 1] === ";" || t[i - 1] === "{" || t[i - 1] === "if" || t[i - 1] === "switch")
245
+ ))
246
+ return null;
247
+ }
248
+ const names = [];
249
+ let k = i;
250
+ while (isIdent(t[k]) && t[k + 1] === ",") {
251
+ names.push(t[k]);
252
+ k += 2;
253
+ }
254
+ if (!isIdent(t[k])) return null;
255
+ names.push(t[k]);
256
+ if (t[k + 1] !== ":=") return null;
257
+ const first = names[0] === "_" ? "_" : names[0];
258
+ return { name: first, also: names.slice(1), type: null, init: k + 2, next: k + 2 };
259
+ }
260
+
261
+ function binds(text) {
262
+ const out = [];
263
+ const add = (alias, path) => {
264
+ if (path.startsWith("C")) return;
265
+ const last = path.split("/").pop();
266
+ const l = alias || (/^v\d+$/.test(last) ? path.split("/").slice(-2)[0] : last);
267
+ if (l !== "_" && l !== ".") out.push({ l: l.replace(/-/g, "_"), m: path, x: null });
268
+ };
269
+ for (const m of text.matchAll(/^[ \t]*import\s+(?:([\w.]+)\s+)?"([^"]+)"/gm)) add(m[1], m[2]);
270
+ for (const block of text.matchAll(/^[ \t]*import[ \t]{0,4}\(([^)]{0,6000})\)/gm)) {
271
+ for (const m of block[1].matchAll(/^[ \t]*(?:([\w.]+)\s+)?"([^"]+)"/gm)) add(m[1], m[2]);
272
+ }
273
+ return out;
274
+ }
275
+
276
+ function moduleSuffixes(path) {
277
+ const segs = path.split("/");
278
+ const out = [];
279
+ for (let n = Math.min(3, segs.length); n >= 1; n--) out.push(`${segs.slice(-n).join("/")}/`);
280
+ return out;
281
+ }
282
+
283
+ export default {
284
+ id: "go",
285
+ stringType: "string",
286
+ exts: [".go"],
287
+ implicitSelf: false,
288
+ initName: "New",
289
+ selfWords: new Set(),
290
+ superWords: new Set(),
291
+ newKeyword: null,
292
+ memberOps: new Set(["."]),
293
+ labelOps: [":"],
294
+ keywords: KEYWORDS,
295
+ declWords: new Set(["func", "type", "var", "const", "package", "import"]),
296
+ condWords: new Set(["if", "switch", "for"]),
297
+ structuralInterfaces: true,
298
+ keepStrings: true,
299
+ parse,
300
+ localDecl,
301
+ binds,
302
+ moduleSuffixes,
303
+ };
@@ -0,0 +1,370 @@
1
+ /**
2
+ * @file java.mjs - Java profile for the call-edge scanner.
3
+ *
4
+ * Also read for C# through the same member grammar (see csharp.mjs): a member is
5
+ * a run of modifiers, a type, a name, and either a parameter list or a field
6
+ * initialiser. Types resolve by simple name and the nearest package; two classes
7
+ * with one simple name in distant packages stay ambiguous. Not modelled:
8
+ * overloads that differ only by parameter type, lambdas' inferred parameter
9
+ * types, generics' bound methods and reflection.
10
+ *
11
+ * @module pipeline/scripts/call-graph/lang/java
12
+ */
13
+
14
+ import { isIdent, readType, skipAngles, tick, MAX_HEADER_TOKENS } from "../lex.mjs";
15
+ import { genericNames, skipAnnotations, typeList, paramsTypeFirst } from "./shared.mjs";
16
+
17
+ export const JAVA_MODS = new Set(
18
+ `public private protected static final abstract native synchronized transient volatile strictfp
19
+ default sealed non-sealed`.split(/\s+/),
20
+ );
21
+ const TYPE_KW = new Set(["class", "interface", "enum", "record", "@interface"]);
22
+ const KEYWORDS = new Set(
23
+ `if else for while do switch case default return throw throws try catch finally new instanceof
24
+ break continue class interface enum extends implements import package static public private
25
+ protected final abstract synchronized volatile transient native void int long short byte char
26
+ boolean double float true false null assert var`.split(/\s+/),
27
+ );
28
+
29
+ /**
30
+ * Member grammar shared by the C-family object languages.
31
+ *
32
+ * @param {object} cfg
33
+ * @param {Set<string>} cfg.mods
34
+ * @param {Set<string>} cfg.typeKw
35
+ */
36
+ export function makeParse(cfg) {
37
+ return function parse(tk) {
38
+ const t = tk.t;
39
+ const types = [];
40
+ const fns = [];
41
+
42
+ const lastTypeNamed = (name) => {
43
+ for (let n = types.length - 1; n >= 0; n--) if (types[n].n === name) return types[n];
44
+ return undefined;
45
+ };
46
+
47
+ const walk = (from, to, owner, ownerKind) => {
48
+ let i = from;
49
+ let isStatic = false;
50
+ let isAbstract = false;
51
+ const thisParamExt = false;
52
+ void thisParamExt;
53
+ while (i < to) {
54
+ tick(tk);
55
+ i = skipAnnotations(tk, i);
56
+ if (cfg.skipAttributes) i = cfg.skipAttributes(tk, i);
57
+ const s = t[i];
58
+ if (s === undefined || i >= to) break;
59
+ if (s === "@") {
60
+ i++;
61
+ continue;
62
+ }
63
+ if (cfg.mods.has(s) && !cfg.typeKw.has(s)) {
64
+ if (s === "static") isStatic = true;
65
+ if (s === "abstract") isAbstract = true;
66
+ i++;
67
+ continue;
68
+ }
69
+ if (cfg.namespaces && s === "namespace" && isIdent(t[i + 1])) {
70
+ let j = i + 2;
71
+ while (t[j] === "." && isIdent(t[j + 1])) j += 2;
72
+ if (t[j] === "{" && tk.m[j] > j) {
73
+ walk(j + 1, tk.m[j], null, null);
74
+ i = tk.m[j] + 1;
75
+ continue;
76
+ }
77
+ i = j + 1;
78
+ continue;
79
+ }
80
+ if (cfg.typeKw.has(s) && isIdent(t[i + 1])) {
81
+ i = typeDecl(i, to, owner, isAbstract, cfg.partialOf?.(tk, from, i));
82
+ isStatic = false;
83
+ isAbstract = false;
84
+ continue;
85
+ }
86
+ if (owner && (isIdent(s) || s === "<" || s === "~")) {
87
+ const next = member(i, to, owner, ownerKind, isStatic, isAbstract);
88
+ if (next > i) {
89
+ i = next;
90
+ isStatic = false;
91
+ isAbstract = false;
92
+ continue;
93
+ }
94
+ }
95
+ if (s === "{" && tk.m[i] > i) {
96
+ i = tk.m[i] + 1;
97
+ continue;
98
+ }
99
+ isStatic = false;
100
+ isAbstract = false;
101
+ i++;
102
+ }
103
+ };
104
+
105
+ const typeDecl = (i, to, outer, isAbstract, partial) => {
106
+ const kw = t[i];
107
+ const name = t[i + 1];
108
+ let j = i + 2;
109
+ const g = genericNames(tk, j);
110
+ j = g.next;
111
+ const f = {};
112
+ let ctorSig = null;
113
+ if (kw === "record" && t[j] === "(" && tk.m[j] > j) {
114
+ ctorSig = paramsTypeFirst(tk, j);
115
+ for (const p of ctorSig.params) if (p[2] && p[1]) f[p[1]] = p[2];
116
+ j = tk.m[j] + 1;
117
+ }
118
+ const sup = [];
119
+ const lim = Math.min(to, j + MAX_HEADER_TOKENS);
120
+ while (j < lim && t[j] !== "{" && t[j] !== ";") {
121
+ if (t[j] === "extends" || t[j] === "implements" || t[j] === ":" || t[j] === "permits") {
122
+ let k = j + 1;
123
+ while (
124
+ k < lim &&
125
+ t[k] !== "{" &&
126
+ t[k] !== "implements" &&
127
+ t[k] !== "permits" &&
128
+ t[k] !== "where"
129
+ ) {
130
+ k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
131
+ }
132
+ if (t[j] !== "permits") sup.push(...typeList(tk, j + 1, k, new Set(["new"])));
133
+ j = k;
134
+ } else if (t[j] === "where") {
135
+ while (j < lim && t[j] !== "{") j++;
136
+ } else j = tk.m[j] > j ? tk.m[j] + 1 : j + 1;
137
+ }
138
+ if (t[j] !== "{" || tk.m[j] < 0) return i + 2;
139
+ types.push({
140
+ n: name,
141
+ k: kw === "@interface" ? "interface" : kw === "record" ? "class" : kw,
142
+ line: tk.line[i],
143
+ end: tk.line[tk.m[j]],
144
+ sup,
145
+ ...(outer ? { outer } : {}),
146
+ ...(g.gen.length ? { gen: g.gen } : {}),
147
+ ...(isAbstract && kw === "class" ? { abs: 1 } : {}),
148
+ ...(partial ? { partial: 1 } : {}),
149
+ f,
150
+ });
151
+ if (ctorSig) {
152
+ fns.push({
153
+ n: "constructor",
154
+ o: name,
155
+ a: [ctorSig.min, ctorSig.max],
156
+ p: ctorSig.params,
157
+ r: name,
158
+ l: tk.line[i],
159
+ e: tk.line[i],
160
+ });
161
+ }
162
+ let from = j + 1;
163
+ if (kw === "enum") {
164
+ let k = from;
165
+ while (k < tk.m[j] && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
166
+ from = t[k] === ";" ? k + 1 : tk.m[j];
167
+ }
168
+ walk(from, tk.m[j], name, kw);
169
+ return tk.m[j] + 1;
170
+ };
171
+
172
+ const member = (i, to, owner, ownerKind, isStatic, isAbstract) => {
173
+ let j = i;
174
+ const g = genericNames(tk, j);
175
+ j = g.next;
176
+ if (cfg.ctorWord && t[j] === "~") j++;
177
+ const start = j;
178
+ // constructor: Name(
179
+ if (t[j] === owner && t[j + 1] === "(" && tk.m[j + 1] > j + 1) {
180
+ const sig = (cfg.params || paramsTypeFirst)(tk, j + 1, { mods: cfg.paramMods });
181
+ let k = tk.m[j + 1] + 1;
182
+ while (k < to && t[k] !== "{" && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
183
+ const body = t[k] === "{" && tk.m[k] > k ? [k + 1, tk.m[k]] : null;
184
+ fns.push({
185
+ n: "constructor",
186
+ o: owner,
187
+ a: [sig.min, sig.max],
188
+ p: sig.params,
189
+ r: owner,
190
+ l: tk.line[i],
191
+ e: tk.line[body ? body[1] : i],
192
+ body,
193
+ });
194
+ return body ? body[1] + 1 : k + 1;
195
+ }
196
+ const r = readType(tk, j, { skip: cfg.typeSkip });
197
+ if (!r.name && r.next === j) return i;
198
+ j = r.next;
199
+ while (t[j] === "[" && tk.m[j] === j + 1) j += 2;
200
+ if (!isIdent(t[j])) return i;
201
+ let name = t[j];
202
+ j++;
203
+ if (cfg.explicitImpl && t[j] === "." && isIdent(t[j + 1])) {
204
+ name = t[j + 1];
205
+ j += 2;
206
+ }
207
+ const g2 = genericNames(tk, j);
208
+ j = g2.next;
209
+ if (t[j] === "(" && tk.m[j] > j) {
210
+ const sig = (cfg.params || paramsTypeFirst)(tk, j, { mods: cfg.paramMods });
211
+ let k = tk.m[j] + 1;
212
+ while (k < to && t[k] !== "{" && t[k] !== ";" && t[k] !== "=>") {
213
+ if (t[k] === "where" || t[k] === "throws") {
214
+ k++;
215
+ continue;
216
+ }
217
+ k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
218
+ }
219
+ let body = null;
220
+ let next = k + 1;
221
+ if (t[k] === "{" && tk.m[k] > k) {
222
+ body = [k + 1, tk.m[k]];
223
+ next = tk.m[k] + 1;
224
+ } else if (t[k] === "=>") {
225
+ let e = k + 1;
226
+ while (e < to && t[e] !== ";") e = tk.m[e] > e ? tk.m[e] + 1 : e + 1;
227
+ body = [k + 1, e];
228
+ next = e + 1;
229
+ }
230
+ const thisExt = cfg.extensionThis && t[tk.m[j] > j ? j + 1 : j] === "this";
231
+ const extOwner = thisExt ? sig.params[0]?.[2] : null;
232
+ fns.push({
233
+ n: name,
234
+ o: extOwner || owner,
235
+ a: thisExt ? [Math.max(0, sig.min - 1), sig.max - 1] : [sig.min, sig.max],
236
+ p: thisExt ? sig.params.slice(1) : sig.params,
237
+ r: r.name,
238
+ l: tk.line[i],
239
+ e: tk.line[body ? Math.max(body[1], body[0]) : i],
240
+ ...(isStatic && !thisExt ? { s: 1 } : {}),
241
+ ...(!body || isAbstract ? { ab: 1 } : {}),
242
+ ...(g.gen.length || g2.gen.length ? { g: [...g.gen, ...g2.gen] } : {}),
243
+ body,
244
+ });
245
+ return next;
246
+ }
247
+ const rec = lastTypeNamed(owner);
248
+ let fieldType = r.name;
249
+ if (rec && cfg.propertyBraces && t[j] === "{" && tk.m[j] > j) {
250
+ if (fieldType && fieldType !== "var") rec.f[name] = fieldType;
251
+ let k = tk.m[j] + 1;
252
+ if (t[k] === "=") while (k < to && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
253
+ return k + 1;
254
+ }
255
+ let k = j;
256
+ let init = null;
257
+ if (t[k] === "=") init = k + 1;
258
+ while (k < to && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
259
+ if (rec && name) {
260
+ if (
261
+ (!fieldType || fieldType === "var") &&
262
+ init &&
263
+ t[init] === "new" &&
264
+ isIdent(t[init + 1])
265
+ ) {
266
+ fieldType = readType(tk, init + 1).name;
267
+ }
268
+ if (fieldType && fieldType !== "var") rec.f[name] = fieldType;
269
+ }
270
+ void start;
271
+ return k + 1;
272
+ };
273
+
274
+ walk(0, tk.n, null, null);
275
+ return { types, fns, binds: [] };
276
+ };
277
+ }
278
+
279
+ function localDecl(tk, i, end) {
280
+ const t = tk.t;
281
+ const s = t[i];
282
+ if (
283
+ KEYWORDS.has(s) &&
284
+ !["var", "final"].includes(s) &&
285
+ !["int", "long", "short", "byte", "char", "boolean", "double", "float"].includes(s)
286
+ )
287
+ return null;
288
+ let j = i;
289
+ while (t[j] === "final" || t[j] === "@") {
290
+ j = t[j] === "@" ? j + 2 : j + 1;
291
+ }
292
+ const r = readType(tk, j, { limit: end });
293
+ if (!r.name && r.next === j) return null;
294
+ let k = r.next;
295
+ while (t[k] === "[" && tk.m[k] === k + 1) k += 2;
296
+ if (!isIdent(t[k]) || KEYWORDS.has(t[k])) return null;
297
+ const name = t[k];
298
+ const nx = t[k + 1];
299
+ if (nx === "=") {
300
+ return { name, type: r.name === "var" ? null : r.name, init: k + 2, next: k + 2 };
301
+ }
302
+ if (nx === ";" || nx === "," || nx === ":")
303
+ return { name, type: r.name === "var" ? null : r.name, init: null, next: k + 1 };
304
+ return null;
305
+ }
306
+
307
+ function lambdaParams(tk, i) {
308
+ const t = tk.t;
309
+ if (t[i] === "(" && tk.m[i] > i && t[tk.m[i] + 1] === "->") {
310
+ const params = [];
311
+ for (let k = i + 1; k < tk.m[i]; k++)
312
+ if (isIdent(t[k]) && (t[k + 1] === "," || k + 1 === tk.m[i])) params.push([t[k], null]);
313
+ return params.length ? { params } : null;
314
+ }
315
+ if (isIdent(t[i]) && t[i + 1] === "->") return { params: [[t[i], null]] };
316
+ return null;
317
+ }
318
+
319
+ function castType(tk, open) {
320
+ const close = tk.m[open];
321
+ if (tk.t[open + 1] === "(" && tk.m[open + 1] > open + 1) {
322
+ return readType(tk, open + 2, { limit: tk.m[open + 1] }).name;
323
+ }
324
+ void close;
325
+ return null;
326
+ }
327
+
328
+ function binds(text) {
329
+ const out = [];
330
+ for (const m of text.matchAll(/^[ \t]*import\s+(?:static\s+)?([\w.]+)(\.\*)?\s*;/gm)) {
331
+ const fqn = m[1];
332
+ const last = fqn.split(".").pop();
333
+ if (!m[2]) out.push({ l: last, m: fqn, x: null });
334
+ }
335
+ return out;
336
+ }
337
+
338
+ export default {
339
+ id: "java",
340
+ stringType: "String",
341
+ exts: [".java"],
342
+ implicitSelf: true,
343
+ initName: "constructor",
344
+ selfWords: new Set(["this"]),
345
+ superWords: new Set(["super"]),
346
+ newKeyword: "new",
347
+ memberOps: new Set(["."]),
348
+ labelOps: [],
349
+ keywords: KEYWORDS,
350
+ declWords: new Set([
351
+ "class",
352
+ "interface",
353
+ "enum",
354
+ "record",
355
+ "new",
356
+ "import",
357
+ "package",
358
+ "extends",
359
+ "implements",
360
+ "throws",
361
+ "instanceof",
362
+ ]),
363
+ condWords: new Set(["for", "catch", "try", "("]),
364
+ castFn: castType,
365
+ parse: makeParse({ mods: JAVA_MODS, typeKw: TYPE_KW, paramMods: new Set(["final"]) }),
366
+ localDecl,
367
+ lambdaParams,
368
+ binds,
369
+ };
370
+ export { skipAngles };