@groma/scanner-go 0.1.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.
package/GO-LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright 2009 The Go Authors.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above
10
+ copyright notice, this list of conditions and the following disclaimer
11
+ in the documentation and/or other materials provided with the
12
+ distribution.
13
+ * Neither the name of Google LLC nor the names of its
14
+ contributors may be used to endorse or promote products derived from
15
+ this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/GO-MOD-LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright 2009 The Go Authors.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above
10
+ copyright notice, this list of conditions and the following disclaimer
11
+ in the documentation and/or other materials provided with the
12
+ distribution.
13
+ * Neither the name of Google LLC nor the names of its
14
+ contributors may be used to endorse or promote products derived from
15
+ this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,27 @@
1
+ Copyright 2009 The Go Authors.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above
10
+ copyright notice, this list of conditions and the following disclaimer
11
+ in the documentation and/or other materials provided with the
12
+ distribution.
13
+ * Neither the name of Google LLC nor the names of its
14
+ contributors may be used to endorse or promote products derived from
15
+ this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,27 @@
1
+ Copyright 2009 The Go Authors.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above
10
+ copyright notice, this list of conditions and the following disclaimer
11
+ in the documentation and/or other materials provided with the
12
+ distribution.
13
+ * Neither the name of Google LLC nor the names of its
14
+ contributors may be used to endorse or promote products derived from
15
+ this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex Gavrilescu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@groma/scanner-go",
3
+ "version": "0.1.0",
4
+ "description": "Go project evidence through Go language tooling.",
5
+ "private": false,
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "os": [
9
+ "win32",
10
+ "linux",
11
+ "darwin"
12
+ ],
13
+ "cpu": [
14
+ "arm64",
15
+ "x64"
16
+ ],
17
+ "groma": {
18
+ "scanner": {
19
+ "id": "go",
20
+ "entry": "./src/index.js",
21
+ "discovery": {
22
+ "technologies": [
23
+ "go"
24
+ ],
25
+ "rules": [
26
+ {
27
+ "type": "text",
28
+ "files": [
29
+ "**/go.mod"
30
+ ],
31
+ "technology": "go",
32
+ "kind": "language",
33
+ "versionPattern": "^go\\s+(\\S+)",
34
+ "declaration": "Go module go directive"
35
+ }
36
+ ],
37
+ "compatibility": {
38
+ "groma": "^0.3.0",
39
+ "technologyVersions": {
40
+ "go": "1.20.0"
41
+ }
42
+ }
43
+ }
44
+ }
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/MrLesk/Groma.md.git"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }
package/src/index.js ADDED
@@ -0,0 +1,330 @@
1
+ // @bun
2
+ // plugins/scanners/go/src/adapter.ts
3
+ import { execFile } from "child_process";
4
+ import { access, realpath } from "fs/promises";
5
+ import path from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ // packages/scanner/src/index.ts
9
+ function compare(...values) {
10
+ return values.join("\x00");
11
+ }
12
+ function uniqueBy(values, key, label) {
13
+ const seen = new Set;
14
+ for (const value of values) {
15
+ const id = key(value);
16
+ if (seen.has(id))
17
+ throw new Error(`duplicate ${label}: ${id}`);
18
+ seen.add(id);
19
+ }
20
+ return [...values].sort((left, right) => key(left).localeCompare(key(right)));
21
+ }
22
+ function createScanObservation(input) {
23
+ const roots = validateRoots(input.roots);
24
+ const rootIds = new Set(roots.map((root) => root.id));
25
+ const files = uniqueBy(input.files.map((file) => ({
26
+ ...file,
27
+ roots: [...new Set(file.roots)].sort(),
28
+ symbols: [...new Map(file.symbols.map((symbol) => [
29
+ compare(symbol.id, symbol.kind),
30
+ symbol
31
+ ])).values()].sort((left, right) => {
32
+ return compare(left.id, left.kind).localeCompare(compare(right.id, right.kind));
33
+ })
34
+ })), (file) => file.file, "file path");
35
+ const filePaths = new Set(files.map((file) => file.file));
36
+ for (const file of files) {
37
+ if (file.roots.length === 0)
38
+ throw new Error(`file has no root: ${file.file}`);
39
+ for (const root of file.roots) {
40
+ if (!rootIds.has(root))
41
+ throw new Error(`file references unknown root: ${root}`);
42
+ }
43
+ }
44
+ for (const diagnostic of input.diagnostics)
45
+ diagnosticLocation(diagnostic);
46
+ return {
47
+ schemaVersion: 1,
48
+ scanner: input.scanner,
49
+ roots,
50
+ files,
51
+ ...operationEvidence(input, filePaths),
52
+ diagnostics: [...new Map(input.diagnostics.map((diagnostic) => [
53
+ diagnosticKey(diagnostic),
54
+ diagnostic
55
+ ])).values()].sort((left, right) => {
56
+ return diagnosticKey(left).localeCompare(diagnosticKey(right));
57
+ })
58
+ };
59
+ }
60
+ function validateRoots(input) {
61
+ const roots = uniqueBy(input, (root) => root.id, "root id");
62
+ const byId = new Map(roots.map((root) => [root.id, root]));
63
+ for (const root of roots) {
64
+ const visited = new Set([root.id]);
65
+ let parent = root.parent;
66
+ while (parent !== undefined) {
67
+ if (visited.has(parent))
68
+ throw new Error(`root hierarchy contains a cycle: ${parent}`);
69
+ visited.add(parent);
70
+ const ancestor = byId.get(parent);
71
+ if (ancestor === undefined)
72
+ throw new Error(`root references unknown parent: ${parent}`);
73
+ parent = ancestor.parent;
74
+ }
75
+ }
76
+ return roots;
77
+ }
78
+ function diagnosticKey(diagnostic) {
79
+ return compare(diagnostic.severity, diagnostic.code, diagnostic.message, diagnostic.file ?? "", String(diagnostic.line ?? ""));
80
+ }
81
+ function diagnosticLocation(value) {
82
+ if (value.line !== undefined && (!Number.isInteger(value.line) || Number(value.line) < 1)) {
83
+ throw new Error("diagnostic.line must be a positive integer");
84
+ }
85
+ return {
86
+ ...value.file === undefined ? {} : { file: string(value.file, "diagnostic.file") },
87
+ ...value.line === undefined ? {} : { line: Number(value.line) }
88
+ };
89
+ }
90
+ function object(value, label) {
91
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
92
+ throw new Error(`${label} must be an object`);
93
+ }
94
+ return value;
95
+ }
96
+ function string(value, label) {
97
+ if (typeof value !== "string")
98
+ throw new Error(`${label} must be a string`);
99
+ return value;
100
+ }
101
+ function array(value, label) {
102
+ if (!Array.isArray(value))
103
+ throw new Error(`${label} must be an array`);
104
+ return value;
105
+ }
106
+ function parseScanObservation(source) {
107
+ const value = object(JSON.parse(source), "observation");
108
+ if (value.schemaVersion !== 1)
109
+ throw new Error("unsupported scanner schema");
110
+ const scanner = object(value.scanner, "scanner");
111
+ return createScanObservation({
112
+ scanner: {
113
+ id: string(scanner.id, "scanner.id"),
114
+ technology: string(scanner.technology, "scanner.technology"),
115
+ engine: string(scanner.engine, "scanner.engine"),
116
+ engineVersion: string(scanner.engineVersion, "scanner.engineVersion")
117
+ },
118
+ ...parseOperations(value),
119
+ roots: array(value.roots, "roots").map((entry) => {
120
+ const root = object(entry, "root");
121
+ return {
122
+ id: string(root.id, "root.id"),
123
+ kind: string(root.kind, "root.kind"),
124
+ name: string(root.name, "root.name"),
125
+ ...root.file === undefined ? {} : { file: string(root.file, "root.file") },
126
+ ...root.parent === undefined ? {} : { parent: string(root.parent, "root.parent") }
127
+ };
128
+ }),
129
+ files: array(value.files, "files").map((entry, index) => {
130
+ const file = object(entry, `files[${index}]`);
131
+ return {
132
+ file: string(file.file, `files[${index}].file`),
133
+ roots: array(file.roots, "file.roots").map((root) => string(root, "file.root")),
134
+ symbols: array(file.symbols, `files[${index}].symbols`).map((entry, symbolIndex) => {
135
+ const symbol = object(entry, `files[${index}].symbols[${symbolIndex}]`);
136
+ return {
137
+ id: string(symbol.id, "symbol.id"),
138
+ name: string(symbol.name, "symbol.name"),
139
+ kind: string(symbol.kind, "symbol.kind")
140
+ };
141
+ })
142
+ };
143
+ }),
144
+ diagnostics: array(value.diagnostics, "diagnostics").map((entry, index) => {
145
+ const diagnostic = object(entry, `diagnostics[${index}]`);
146
+ return {
147
+ severity: string(diagnostic.severity, `diagnostics[${index}].severity`),
148
+ code: string(diagnostic.code, `diagnostics[${index}].code`),
149
+ message: string(diagnostic.message, `diagnostics[${index}].message`),
150
+ ...diagnosticLocation(diagnostic)
151
+ };
152
+ })
153
+ });
154
+ }
155
+ function parseOperations(value) {
156
+ if (value.operations === undefined) {
157
+ if (value.invocations !== undefined)
158
+ throw new Error("invocations require operation declarations");
159
+ return {};
160
+ }
161
+ const operations = array(value.operations, "operations").map((entry) => {
162
+ const operation = object(entry, "operation");
163
+ return {
164
+ id: string(operation.id, "operation.id"),
165
+ file: string(operation.file, "operation.file"),
166
+ name: string(operation.name, "operation.name"),
167
+ ...sourcePosition(operation.position),
168
+ ...operationTokens(operation)
169
+ };
170
+ });
171
+ const invocations = array(value.invocations, "invocations").map((entry) => {
172
+ const invocation = object(entry, "invocation");
173
+ if (typeof invocation.unresolved !== "boolean")
174
+ throw new Error("invocation.unresolved must be a boolean");
175
+ if (!Number.isInteger(invocation.line) || Number(invocation.line) < 1)
176
+ throw new Error("invocation.line must be a positive integer");
177
+ const binding = invocation.binding === undefined ? undefined : object(invocation.binding, "invocation.binding");
178
+ if (binding && (!Number.isInteger(binding.line) || Number(binding.line) < 1))
179
+ throw new Error("binding.line must be a positive integer");
180
+ return {
181
+ source: string(invocation.source, "invocation.source"),
182
+ targets: array(invocation.targets, "invocation.targets").map((target) => string(target, "invocation.target")),
183
+ unresolved: invocation.unresolved,
184
+ line: Number(invocation.line),
185
+ ...sourcePosition(invocation.position),
186
+ ...invocation.member === undefined ? {} : { member: string(invocation.member, "invocation.member") },
187
+ ...binding === undefined ? {} : { binding: { file: string(binding.file, "binding.file"), line: Number(binding.line), ...sourcePosition(binding.position) } }
188
+ };
189
+ });
190
+ return { operations, invocations };
191
+ }
192
+ function operationEvidence(input, files) {
193
+ if (input.operations === undefined && input.invocations !== undefined)
194
+ throw new Error("invocations require operation declarations");
195
+ if (input.operations === undefined)
196
+ return {};
197
+ const operations = uniqueBy(input.operations, (operation) => operation.id, "operation id");
198
+ const ids = new Set(operations.map((operation) => operation.id));
199
+ for (const operation of operations) {
200
+ if (!files.has(operation.file))
201
+ throw new Error(`operation references unknown file: ${operation.file}`);
202
+ sourcePosition(operation.position);
203
+ validateOperationTokens(operation);
204
+ }
205
+ const invocations = input.invocations ?? [];
206
+ for (const invocation of invocations)
207
+ validateInvocation(invocation, ids, files);
208
+ return { operations, invocations };
209
+ }
210
+ function operationTokens(operation) {
211
+ if (operation.tokens === undefined) {
212
+ if (operation.startLine !== undefined || operation.endLine !== undefined) {
213
+ throw new Error("operation range requires tokens");
214
+ }
215
+ return {};
216
+ }
217
+ if (operation.startLine === undefined || operation.endLine === undefined) {
218
+ throw new Error("operation tokens require a source range");
219
+ }
220
+ if (!Number.isInteger(operation.startLine) || Number(operation.startLine) < 1) {
221
+ throw new Error("operation.startLine must be a positive integer");
222
+ }
223
+ if (!Number.isInteger(operation.endLine) || Number(operation.endLine) < 1) {
224
+ throw new Error("operation.endLine must be a positive integer");
225
+ }
226
+ const startLine = Number(operation.startLine);
227
+ const endLine = Number(operation.endLine);
228
+ if (endLine < startLine)
229
+ throw new Error("operation.endLine must be at or after startLine");
230
+ return {
231
+ startLine,
232
+ endLine,
233
+ tokens: array(operation.tokens, "operation.tokens").map((token) => string(token, "operation.token"))
234
+ };
235
+ }
236
+ function validateOperationTokens(operation) {
237
+ operationTokens({
238
+ tokens: operation.tokens,
239
+ startLine: operation.startLine,
240
+ endLine: operation.endLine
241
+ });
242
+ }
243
+ function validateInvocation(invocation, ids, files) {
244
+ sourcePosition(invocation.position);
245
+ sourcePosition(invocation.binding?.position);
246
+ if (!invocation.targets.length && !invocation.unresolved)
247
+ throw new Error("an empty target set must be unresolved");
248
+ if (!ids.has(invocation.source) || invocation.targets.some((target) => !ids.has(target))) {
249
+ throw new Error("invocation references unknown operation");
250
+ }
251
+ if (invocation.binding && !files.has(invocation.binding.file))
252
+ throw new Error("invocation binding references unknown file");
253
+ }
254
+ function sourcePosition(position) {
255
+ if (position === undefined)
256
+ return {};
257
+ if (!Number.isInteger(position) || Number(position) < 0)
258
+ throw new Error("source position must be a non-negative integer");
259
+ return { position: Number(position) };
260
+ }
261
+
262
+ // plugins/scanners/go/src/adapter.ts
263
+ var packagedWorker = fileURLToPath(new URL(`../dist/${process.platform}-${process.arch}/worker${process.platform === "win32" ? ".exe" : ""}`, import.meta.url));
264
+ function run(command, args, root, env = process.env) {
265
+ return new Promise((resolve, reject) => {
266
+ execFile(command, args, {
267
+ cwd: root,
268
+ env,
269
+ encoding: "utf8",
270
+ timeout: 120000,
271
+ killSignal: "SIGKILL",
272
+ maxBuffer: 64 * 1024 * 1024
273
+ }, (error, stdout, stderr) => {
274
+ if (error)
275
+ reject(new Error(stderr.trim() || stdout.trim() || error.message));
276
+ else
277
+ resolve(stdout);
278
+ });
279
+ });
280
+ }
281
+ async function checkGoReadiness(repositoryRoot, options = {}) {
282
+ const root = await realpath(repositoryRoot);
283
+ const worker = options.worker ?? packagedWorker;
284
+ try {
285
+ await access(worker);
286
+ } catch {
287
+ throw new Error("GO_WORKER_MISSING: Install the packaged Go scanner for this platform, or build it with bun plugins/scanners/go/build.ts.");
288
+ }
289
+ const env = { ...process.env, GOTOOLCHAIN: "local", GOPROXY: "off", GOSUMDB: "off" };
290
+ let context;
291
+ try {
292
+ context = JSON.parse(await run(options.go ?? "go", ["env", "-json", "GOMOD", "GOWORK", "GOROOT"], root, env));
293
+ } catch (error) {
294
+ throw new Error(`GO_TOOLCHAIN_MISSING: Install the project's Go toolchain and add its bin directory to PATH (Go 1.27.1 for the qualified example). ${error}`);
295
+ }
296
+ if (context.GOWORK && context.GOWORK !== "off") {
297
+ throw new Error("GO_PROJECT_SCOPE: This scanner supports one root module. Select the supported module with GOWORK=off; workspace analysis is not qualified.");
298
+ }
299
+ if (context.GOMOD !== path.join(root, "go.mod")) {
300
+ throw new Error("GO_PROJECT_SCOPE: Run Groma at the supported Go module root containing go.mod.");
301
+ }
302
+ env.PATH = `${path.join(context.GOROOT, "bin")}${path.delimiter}${process.env.PATH ?? ""}`;
303
+ try {
304
+ await run(options.go ?? "go", ["list", "-mod=readonly", "-deps", "./..."], root, env);
305
+ } catch (error) {
306
+ throw new Error(`GO_PROJECT_PREPARATION: Prepare dependencies and generated source with the project's documented build commands (go mod download for module dependencies), then retry. Scan does not download tools or modules. ${error}`);
307
+ }
308
+ return { root, worker, env };
309
+ }
310
+ async function scanGoSource(repositoryRoot, options = {}) {
311
+ const { root, worker, env } = await checkGoReadiness(repositoryRoot, options);
312
+ try {
313
+ return parseScanObservation(await run(worker, [root], root, env));
314
+ } catch (error) {
315
+ throw new Error(`GO_COMPILATION_FAILED: No observation was produced. Correct compilation errors with the project's Go toolchain and prepare its dependencies and generated source. ${error}`);
316
+ }
317
+ }
318
+
319
+ // plugins/scanners/go/src/index.ts
320
+ var src_default = {
321
+ id: "go",
322
+ watch: { include: ["**/*.go", "**/go.mod", "**/go.sum", "**/go.work"], exclude: [] },
323
+ checkReadiness: async (root) => {
324
+ await checkGoReadiness(root);
325
+ },
326
+ scan: scanGoSource
327
+ };
328
+ export {
329
+ src_default as default
330
+ };