codeql-development-mcp-server 2.24.1-rc1

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 (67) hide show
  1. package/LICENSE +178 -0
  2. package/README.md +113 -0
  3. package/dist/codeql-development-mcp-server.js +9474 -0
  4. package/dist/codeql-development-mcp-server.js.map +7 -0
  5. package/package.json +101 -0
  6. package/ql/README.md +57 -0
  7. package/ql/actions/tools/src/PrintAST/PrintAST.ql +40 -0
  8. package/ql/actions/tools/src/PrintCFG/PrintCFG.md +53 -0
  9. package/ql/actions/tools/src/PrintCFG/PrintCFG.ql +23 -0
  10. package/ql/actions/tools/src/codeql-pack.lock.yml +32 -0
  11. package/ql/actions/tools/src/codeql-pack.yml +6 -0
  12. package/ql/cpp/tools/src/CallGraphFrom/CallGraphFrom.ql +55 -0
  13. package/ql/cpp/tools/src/CallGraphTo/CallGraphTo.ql +55 -0
  14. package/ql/cpp/tools/src/PrintAST/PrintAST.ql +57 -0
  15. package/ql/cpp/tools/src/PrintCFG/PrintCFG.md +56 -0
  16. package/ql/cpp/tools/src/PrintCFG/PrintCFG.ql +22 -0
  17. package/ql/cpp/tools/src/codeql-pack.lock.yml +28 -0
  18. package/ql/cpp/tools/src/codeql-pack.yml +6 -0
  19. package/ql/csharp/tools/src/CallGraphFrom/CallGraphFrom.ql +50 -0
  20. package/ql/csharp/tools/src/CallGraphTo/CallGraphTo.ql +50 -0
  21. package/ql/csharp/tools/src/PrintAST/PrintAST.ql +57 -0
  22. package/ql/csharp/tools/src/PrintCFG/PrintCFG.md +55 -0
  23. package/ql/csharp/tools/src/PrintCFG/PrintCFG.ql +22 -0
  24. package/ql/csharp/tools/src/codeql-pack.lock.yml +24 -0
  25. package/ql/csharp/tools/src/codeql-pack.yml +6 -0
  26. package/ql/go/tools/src/CallGraphFrom/CallGraphFrom.ql +39 -0
  27. package/ql/go/tools/src/CallGraphTo/CallGraphTo.ql +47 -0
  28. package/ql/go/tools/src/PrintAST/PrintAST.ql +58 -0
  29. package/ql/go/tools/src/PrintCFG/PrintCFG.md +55 -0
  30. package/ql/go/tools/src/PrintCFG/PrintCFG.ql +22 -0
  31. package/ql/go/tools/src/codeql-pack.lock.yml +24 -0
  32. package/ql/go/tools/src/codeql-pack.yml +6 -0
  33. package/ql/java/tools/src/CallGraphFrom/CallGraphFrom.ql +50 -0
  34. package/ql/java/tools/src/CallGraphTo/CallGraphTo.ql +50 -0
  35. package/ql/java/tools/src/PrintAST/PrintAST.ql +57 -0
  36. package/ql/java/tools/src/PrintCFG/PrintCFG.md +55 -0
  37. package/ql/java/tools/src/PrintCFG/PrintCFG.ql +35 -0
  38. package/ql/java/tools/src/codeql-pack.lock.yml +32 -0
  39. package/ql/java/tools/src/codeql-pack.yml +6 -0
  40. package/ql/javascript/tools/src/CallGraphFrom/CallGraphFrom.ql +49 -0
  41. package/ql/javascript/tools/src/CallGraphTo/CallGraphTo.ql +47 -0
  42. package/ql/javascript/tools/src/PrintAST/PrintAST.ql +60 -0
  43. package/ql/javascript/tools/src/PrintCFG/PrintCFG.md +57 -0
  44. package/ql/javascript/tools/src/PrintCFG/PrintCFG.ql +21 -0
  45. package/ql/javascript/tools/src/codeql-pack.lock.yml +30 -0
  46. package/ql/javascript/tools/src/codeql-pack.yml +6 -0
  47. package/ql/python/tools/src/CallGraphFrom/CallGraphFrom.ql +49 -0
  48. package/ql/python/tools/src/CallGraphTo/CallGraphTo.ql +47 -0
  49. package/ql/python/tools/src/PrintAST/PrintAST.ql +62 -0
  50. package/ql/python/tools/src/PrintCFG/PrintCFG.md +52 -0
  51. package/ql/python/tools/src/PrintCFG/PrintCFG.ql +21 -0
  52. package/ql/python/tools/src/codeql-pack.lock.yml +30 -0
  53. package/ql/python/tools/src/codeql-pack.yml +6 -0
  54. package/ql/ruby/tools/src/CallGraphFrom/CallGraphFrom.ql +40 -0
  55. package/ql/ruby/tools/src/CallGraphTo/CallGraphTo.ql +48 -0
  56. package/ql/ruby/tools/src/PrintAST/PrintAST.ql +57 -0
  57. package/ql/ruby/tools/src/PrintCFG/PrintCFG.md +55 -0
  58. package/ql/ruby/tools/src/PrintCFG/PrintCFG.ql +22 -0
  59. package/ql/ruby/tools/src/codeql-pack.lock.yml +24 -0
  60. package/ql/ruby/tools/src/codeql-pack.yml +6 -0
  61. package/ql/swift/tools/src/CallGraphFrom/CallGraphFrom.ql +53 -0
  62. package/ql/swift/tools/src/CallGraphTo/CallGraphTo.ql +49 -0
  63. package/ql/swift/tools/src/PrintAST/PrintAST.ql +58 -0
  64. package/ql/swift/tools/src/PrintCFG/PrintCFG.ql +68 -0
  65. package/ql/swift/tools/src/codeql-pack.lock.yml +24 -0
  66. package/ql/swift/tools/src/codeql-pack.yml +6 -0
  67. package/scripts/setup-packs.sh +150 -0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @name Call Graph To for ruby
3
+ * @description Displays calls made to a specified method, showing the call graph inbound to the target method.
4
+ * @id ruby/tools/call-graph-to
5
+ * @kind problem
6
+ * @problem.severity recommendation
7
+ * @tags call-graph
8
+ */
9
+
10
+ private import codeql.ruby.AST
11
+ private import codeql.ruby.DataFlow
12
+
13
+ /**
14
+ * Gets the target method name for which to generate the call graph.
15
+ * Can be a single method name or comma-separated list of method names.
16
+ */
17
+ external string targetFunction();
18
+
19
+ /**
20
+ * Gets a single target method name from the comma-separated list.
21
+ */
22
+ string getTargetFunctionName() {
23
+ result = targetFunction().splitAt(",").trim()
24
+ }
25
+
26
+ /**
27
+ * Gets the caller name for a call expression.
28
+ */
29
+ string getCallerName(MethodCall call) {
30
+ if exists(call.getEnclosingMethod())
31
+ then result = call.getEnclosingMethod().getName()
32
+ else result = "Top-level"
33
+ }
34
+
35
+ from MethodCall call
36
+ where
37
+ (
38
+ // Use external predicate if available
39
+ call.getMethodName() = getTargetFunctionName()
40
+ or
41
+ // Fallback for unit tests: include test files
42
+ (
43
+ not exists(getTargetFunctionName()) and
44
+ call.getLocation().getFile().getParentContainer().getParentContainer().getBaseName() = "test"
45
+ )
46
+ )
47
+ select call,
48
+ "Call to `" + call.getMethodName() + "` from `" + getCallerName(call) + "`"
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @name Print AST for ruby
3
+ * @description Outputs a representation of the Abstract Syntax Tree for specified source files.
4
+ * @id ruby/tools/print-ast
5
+ * @kind graph
6
+ * @tags ast
7
+ */
8
+
9
+ private import codeql.ruby.AST
10
+ private import codeql.ruby.printAst
11
+
12
+ /**
13
+ * Gets the source files to generate AST from.
14
+ * Can be a single file path or comma-separated list of file paths.
15
+ */
16
+ external string selectedSourceFiles();
17
+
18
+ /**
19
+ * Gets a single source file from the comma-separated list.
20
+ */
21
+ string getSelectedSourceFile() {
22
+ result = selectedSourceFiles().splitAt(",").trim()
23
+ }
24
+
25
+ /**
26
+ * Gets a file by matching against the selected source file paths.
27
+ */
28
+ File getSelectedFile() {
29
+ exists(string selectedFile |
30
+ selectedFile = getSelectedSourceFile() and
31
+ (
32
+ // Match by exact relative path from source root
33
+ result.getRelativePath() = selectedFile or
34
+ // Match by file name if no path separators
35
+ (not selectedFile.matches("%/%") and result.getBaseName() = selectedFile) or
36
+ // Match by ending path component
37
+ result.getAbsolutePath().suffix(result.getAbsolutePath().length() - selectedFile.length()) = selectedFile
38
+ )
39
+ )
40
+ }
41
+
42
+ /**
43
+ * Configuration for PrintAST that uses external predicates to specify source files.
44
+ * Falls back to all files when external predicates are not available (for unit tests).
45
+ */
46
+ class Cfg extends PrintAstConfiguration {
47
+ override predicate shouldPrintNode(AstNode n) {
48
+ super.shouldPrintNode(n) and
49
+ (
50
+ // Use external predicate if available
51
+ n.getLocation().getFile() = getSelectedFile()
52
+ or
53
+ // Fallback for unit tests: include all files
54
+ not exists(getSelectedFile())
55
+ )
56
+ }
57
+ }
@@ -0,0 +1,55 @@
1
+ # Print CFG for Ruby
2
+
3
+ Produces a representation of a file's Control Flow Graph (CFG) for specified source files.
4
+
5
+ ## Overview
6
+
7
+ The Control Flow Graph represents the order in which statements and expressions are executed in a program. Each node in the graph represents a control-flow element (statement or expression), and edges represent possible execution paths between them.
8
+
9
+ This query outputs all CFG nodes and their successor relationships for Ruby code, which is useful for understanding program execution flow, debugging control flow issues, and analyzing code paths.
10
+
11
+ ## Use Cases
12
+
13
+ This query is primarily used for:
14
+
15
+ - Visualizing program execution flow
16
+ - Understanding complex branching logic
17
+ - Debugging control flow issues
18
+ - Analysis of code paths and reachability
19
+ - IDE integration for control flow visualization
20
+
21
+ ## Example
22
+
23
+ The following Ruby code demonstrates control flow through conditional statements and loops:
24
+
25
+ ```ruby
26
+ def example(x)
27
+ if x > 0 # COMPLIANT - Branching creates CFG edges
28
+ puts "Positive"
29
+ else
30
+ puts "Non-positive"
31
+ end
32
+
33
+ (0..2).each do |i| # COMPLIANT - Iterator creates CFG paths
34
+ puts i
35
+ end
36
+ end
37
+ ```
38
+
39
+ In the resulting CFG:
40
+
41
+ - The `if` condition creates two outgoing edges (true/false branches)
42
+ - The `each` iterator creates paths through the block
43
+ - Each statement connects to its successor in execution order
44
+
45
+ ## Output Format
46
+
47
+ The query produces two relations:
48
+
49
+ - `nodes(CfgNode, string, string)`: Each CFG node with its label
50
+ - `edges(CfgNode, CfgNode)`: Successor relationships between nodes
51
+
52
+ ## References
53
+
54
+ - [Ruby Control Structures](https://ruby-doc.org/core/doc/syntax/control_expressions_rdoc.html)
55
+ - [CodeQL Control Flow Graph](https://codeql.github.com/docs/writing-codeql-queries/about-control-flow-in-codeql/)
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @name Print CFG for ruby
3
+ * @description Produces a representation of a file's Control Flow Graph for specified source files.
4
+ * @id ruby/tools/print-cfg
5
+ * @kind graph
6
+ * @tags cfg
7
+ */
8
+
9
+ private import codeql.ruby.AST
10
+ private import codeql.ruby.controlflow.ControlFlowGraph
11
+
12
+ /**
13
+ * Configuration for PrintCFG that outputs all CFG nodes and edges.
14
+ */
15
+ query predicate nodes(CfgNode node, string property, string value) {
16
+ property = "semmle.label" and
17
+ value = node.toString()
18
+ }
19
+
20
+ query predicate edges(CfgNode pred, CfgNode succ) {
21
+ pred.getASuccessor() = succ
22
+ }
@@ -0,0 +1,24 @@
1
+ ---
2
+ lockVersion: 1.0.0
3
+ dependencies:
4
+ codeql/concepts:
5
+ version: 0.0.15
6
+ codeql/controlflow:
7
+ version: 2.0.25
8
+ codeql/dataflow:
9
+ version: 2.0.25
10
+ codeql/mad:
11
+ version: 1.0.41
12
+ codeql/regex:
13
+ version: 1.0.41
14
+ codeql/ruby-all:
15
+ version: 5.1.9
16
+ codeql/ssa:
17
+ version: 2.0.17
18
+ codeql/tutorial:
19
+ version: 1.0.41
20
+ codeql/typetracking:
21
+ version: 2.0.25
22
+ codeql/util:
23
+ version: 2.0.28
24
+ compiled: false
@@ -0,0 +1,6 @@
1
+ name: advanced-security/ql-mcp-ruby-tools-src
2
+ version: 2.24.1-rc1
3
+ description: 'Queries for codeql-development-mcp-server tools for ruby language'
4
+ library: false
5
+ dependencies:
6
+ codeql/ruby-all: 5.1.9
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @name Call Graph From for swift
3
+ * @description Displays calls made from a specified function, showing the call graph outbound from the source function.
4
+ * @id swift/tools/call-graph-from
5
+ * @kind problem
6
+ * @problem.severity recommendation
7
+ * @tags call-graph
8
+ */
9
+
10
+ import swift
11
+
12
+ /**
13
+ * Gets the source function name for which to generate the call graph.
14
+ * Can be a single function name or comma-separated list of function names.
15
+ */
16
+ external string sourceFunction();
17
+
18
+ /**
19
+ * Gets a single source function name from the comma-separated list.
20
+ */
21
+ string getSourceFunctionName() { result = sourceFunction().splitAt(",").trim() }
22
+
23
+ /**
24
+ * Gets a function by matching against the selected source function names.
25
+ */
26
+ Function getSourceFunction() {
27
+ exists(string selectedFunc |
28
+ selectedFunc = getSourceFunctionName() and
29
+ result.getName() = selectedFunc
30
+ )
31
+ }
32
+
33
+ /**
34
+ * Gets the name of the called function.
35
+ */
36
+ string getCalleeName(CallExpr call) {
37
+ if exists(call.getStaticTarget())
38
+ then result = call.getStaticTarget().getName()
39
+ else result = call.toString()
40
+ }
41
+
42
+ from CallExpr call, Function source
43
+ where
44
+ call.getEnclosingFunction() = source and
45
+ (
46
+ // Use external predicate if available
47
+ source = getSourceFunction()
48
+ or
49
+ // Fallback for unit tests: include specific test files
50
+ not exists(getSourceFunction()) and
51
+ source.getFile().getBaseName() = "Example1.swift"
52
+ )
53
+ select call, "Call from `" + source.getName() + "` to `" + getCalleeName(call) + "`"
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @name Call Graph To for swift
3
+ * @description Displays calls made to a specified function, showing the call graph inbound to the target function.
4
+ * @id swift/tools/call-graph-to
5
+ * @kind problem
6
+ * @problem.severity recommendation
7
+ * @tags call-graph
8
+ */
9
+
10
+ import swift
11
+
12
+ /**
13
+ * Gets the target function name for which to generate the call graph.
14
+ * Can be a single function name or comma-separated list of function names.
15
+ */
16
+ external string targetFunction();
17
+
18
+ /**
19
+ * Gets a single target function name from the comma-separated list.
20
+ */
21
+ string getTargetFunctionName() { result = targetFunction().splitAt(",").trim() }
22
+
23
+ /**
24
+ * Gets the caller name for a call expression.
25
+ */
26
+ string getCallerName(CallExpr call) {
27
+ if exists(call.getEnclosingFunction())
28
+ then result = call.getEnclosingFunction().getName()
29
+ else result = "Top-level"
30
+ }
31
+
32
+ /**
33
+ * Gets the name of the called function.
34
+ */
35
+ string getCalleeName(CallExpr call) {
36
+ if exists(call.getStaticTarget())
37
+ then result = call.getStaticTarget().getName()
38
+ else result = call.toString()
39
+ }
40
+
41
+ from CallExpr call
42
+ where
43
+ // Use external predicate if available
44
+ call.getStaticTarget().getName() = getTargetFunctionName()
45
+ or
46
+ // Fallback for unit tests: include specific test files
47
+ not exists(getTargetFunctionName()) and
48
+ call.getLocation().getFile().getBaseName() = "Example1.swift"
49
+ select call, "Call to `" + getCalleeName(call) + "` from `" + getCallerName(call) + "`"
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @name Print AST for swift
3
+ * @description Outputs a representation of the Abstract Syntax Tree for specified source files.
4
+ * @id swift/tools/print-ast
5
+ * @kind graph
6
+ * @tags ast
7
+ */
8
+
9
+ import codeql.swift.printast.PrintAst
10
+
11
+ /**
12
+ * Gets the source files to generate AST from.
13
+ * Can be a single file path or comma-separated list of file paths.
14
+ */
15
+ external string selectedSourceFiles();
16
+
17
+ /**
18
+ * Gets a single source file from the comma-separated list.
19
+ */
20
+ string getSelectedSourceFile() { result = selectedSourceFiles().splitAt(",").trim() }
21
+
22
+ /**
23
+ * Gets a file by matching against the selected source file paths.
24
+ */
25
+ File getSelectedFile() {
26
+ exists(string selectedFile |
27
+ selectedFile = getSelectedSourceFile() and
28
+ (
29
+ // Match by exact relative path from source root
30
+ result.getRelativePath() = selectedFile
31
+ or
32
+ // Match by file name if no path separators
33
+ not selectedFile.matches("%/%") and result.getBaseName() = selectedFile
34
+ or
35
+ // Match by ending path component
36
+ result.getAbsolutePath().suffix(result.getAbsolutePath().length() - selectedFile.length()) =
37
+ selectedFile
38
+ )
39
+ )
40
+ }
41
+
42
+ /**
43
+ * Configuration for PrintAST that uses external predicates to specify source files.
44
+ * Falls back to test files when external predicates are not available.
45
+ */
46
+ class Cfg extends PrintAstConfiguration {
47
+ override predicate shouldPrint(Locatable e) {
48
+ super.shouldPrint(e) and
49
+ (
50
+ // Use external predicate if available
51
+ e.getLocation().getFile() = getSelectedFile()
52
+ or
53
+ // Fallback for unit tests: include specific test files
54
+ not exists(getSelectedFile()) and
55
+ e.getLocation().getFile().getBaseName() = "Example1.swift"
56
+ )
57
+ }
58
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @name Print CFG for swift
3
+ * @description Produces a representation of a file's Control Flow Graph for specified source files.
4
+ * @id swift/tools/print-cfg
5
+ * @kind graph
6
+ * @tags cfg
7
+ */
8
+
9
+ import swift
10
+ import codeql.swift.controlflow.ControlFlowGraph
11
+
12
+ /**
13
+ * Gets the source files to generate CFG from.
14
+ * Can be a single file path or comma-separated list of file paths.
15
+ */
16
+ external string selectedSourceFiles();
17
+
18
+ /**
19
+ * Gets a single source file from the comma-separated list.
20
+ */
21
+ string getSelectedSourceFile() { result = selectedSourceFiles().splitAt(",").trim() }
22
+
23
+ /**
24
+ * Gets a file by matching against the selected source file paths.
25
+ */
26
+ File getSelectedFile() {
27
+ exists(string selectedFile |
28
+ selectedFile = getSelectedSourceFile() and
29
+ (
30
+ // Match by exact relative path from source root
31
+ result.getRelativePath() = selectedFile
32
+ or
33
+ // Match by file name if no path separators
34
+ not selectedFile.matches("%/%") and result.getBaseName() = selectedFile
35
+ or
36
+ // Match by ending path component
37
+ result.getAbsolutePath().suffix(result.getAbsolutePath().length() - selectedFile.length()) =
38
+ selectedFile
39
+ )
40
+ )
41
+ }
42
+
43
+ /**
44
+ * Holds if this CFG node should be included in output.
45
+ */
46
+ predicate shouldPrintNode(ControlFlowNode node) {
47
+ // Use external predicate if available
48
+ node.getLocation().getFile() = getSelectedFile()
49
+ or
50
+ // Fallback for unit tests: include specific test files
51
+ not exists(getSelectedFile()) and
52
+ node.getLocation().getFile().getBaseName() = "Example1.swift"
53
+ }
54
+
55
+ /**
56
+ * Configuration for PrintCFG that outputs filtered CFG nodes and edges.
57
+ */
58
+ query predicate nodes(ControlFlowNode node, string property, string value) {
59
+ shouldPrintNode(node) and
60
+ property = "semmle.label" and
61
+ value = node.toString()
62
+ }
63
+
64
+ query predicate edges(ControlFlowNode pred, ControlFlowNode succ) {
65
+ shouldPrintNode(pred) and
66
+ shouldPrintNode(succ) and
67
+ pred.getASuccessor() = succ
68
+ }
@@ -0,0 +1,24 @@
1
+ ---
2
+ lockVersion: 1.0.0
3
+ dependencies:
4
+ codeql/concepts:
5
+ version: 0.0.15
6
+ codeql/controlflow:
7
+ version: 2.0.25
8
+ codeql/dataflow:
9
+ version: 2.0.25
10
+ codeql/mad:
11
+ version: 1.0.41
12
+ codeql/regex:
13
+ version: 1.0.41
14
+ codeql/ssa:
15
+ version: 2.0.17
16
+ codeql/swift-all:
17
+ version: 6.2.1
18
+ codeql/tutorial:
19
+ version: 1.0.41
20
+ codeql/typetracking:
21
+ version: 2.0.25
22
+ codeql/util:
23
+ version: 2.0.28
24
+ compiled: false
@@ -0,0 +1,6 @@
1
+ name: advanced-security/ql-mcp-swift-tools-src
2
+ version: 2.24.1-rc1
3
+ description: 'Queries for codeql-development-mcp-server tools for swift language'
4
+ library: false
5
+ dependencies:
6
+ codeql/swift-all: 6.2.1
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ## setup-packs.sh — Install CodeQL pack dependencies for bundled tool query packs.
5
+ ##
6
+ ## This script runs `codeql pack install` for each tool query source pack bundled
7
+ ## with the codeql-development-mcp-server. It works from both:
8
+ ## - npm install layout: <pkg>/ql/<language>/tools/src/
9
+ ## - monorepo layout: server/ql/<language>/tools/src/
10
+ ##
11
+ ## The lock files (codeql-pack.lock.yml) shipped with each source pack pin exact
12
+ ## dependency versions. `codeql pack install` reads these and fetches packages
13
+ ## from the GitHub Container Registry (GHCR) into ~/.codeql/packages/.
14
+ ##
15
+ ## Prerequisites: codeql CLI must be on PATH (or set CODEQL_PATH).
16
+ ##
17
+ ## Usage:
18
+ ## setup-packs.sh [OPTIONS]
19
+ ##
20
+ ## Options:
21
+ ## --language <lang> Install packs only for the specified language
22
+ ## -h, --help Show this help message
23
+
24
+ LANGUAGE=""
25
+
26
+ usage() {
27
+ cat << EOF
28
+ Usage: $0 [OPTIONS]
29
+
30
+ Install CodeQL pack dependencies for bundled tool query packs.
31
+
32
+ OPTIONS:
33
+ --language <lang> Install packs only for the specified language
34
+ Valid values: actions, cpp, csharp, go, java, javascript, python, ruby, swift
35
+ -h, --help Show this help message
36
+
37
+ By default, installs pack dependencies for all supported languages.
38
+ EOF
39
+ }
40
+
41
+ while [[ $# -gt 0 ]]; do
42
+ case $1 in
43
+ --language)
44
+ if [[ $# -lt 2 || "$2" =~ ^- ]]; then
45
+ echo "Error: --language requires a value" >&2
46
+ usage >&2
47
+ exit 1
48
+ fi
49
+ LANGUAGE="$2"
50
+ shift 2
51
+ ;;
52
+ -h|--help)
53
+ usage
54
+ exit 0
55
+ ;;
56
+ *)
57
+ echo "Error: Unknown option $1" >&2
58
+ usage >&2
59
+ exit 1
60
+ ;;
61
+ esac
62
+ done
63
+
64
+ ## Validate language if provided
65
+ VALID_LANGUAGES=("actions" "cpp" "csharp" "go" "java" "javascript" "python" "ruby" "swift")
66
+ if [ -n "${LANGUAGE}" ]; then
67
+ LANGUAGE_VALID=false
68
+ for valid_lang in "${VALID_LANGUAGES[@]}"; do
69
+ if [ "${LANGUAGE}" = "${valid_lang}" ]; then
70
+ LANGUAGE_VALID=true
71
+ break
72
+ fi
73
+ done
74
+
75
+ if [ "${LANGUAGE_VALID}" = false ]; then
76
+ echo "Error: Invalid language '${LANGUAGE}'" >&2
77
+ echo "Valid languages: ${VALID_LANGUAGES[*]}" >&2
78
+ exit 1
79
+ fi
80
+ fi
81
+
82
+ ## Resolve the CodeQL CLI binary.
83
+ CODEQL="${CODEQL_PATH:-codeql}"
84
+ if ! command -v "${CODEQL}" &> /dev/null; then
85
+ echo "Error: CodeQL CLI not found. Install it or set CODEQL_PATH." >&2
86
+ exit 1
87
+ fi
88
+
89
+ ## Resolve the ql/ root directory.
90
+ ## Works from both:
91
+ ## npm layout: <pkg>/scripts/setup-packs.sh → <pkg>/ql/
92
+ ## monorepo layout: server/scripts/setup-packs.sh → server/ql/
93
+ ## When invoked via npm bin shim/symlink, BASH_SOURCE[0] may point to the
94
+ ## .bin/ directory. Resolve the real path first to find the actual package root.
95
+ SCRIPT_PATH="${BASH_SOURCE[0]}"
96
+ if command -v realpath &> /dev/null; then
97
+ SCRIPT_PATH="$(realpath "${SCRIPT_PATH}")"
98
+ elif command -v readlink &> /dev/null; then
99
+ # macOS readlink doesn't support -f, use a loop to resolve symlinks
100
+ while [ -L "${SCRIPT_PATH}" ]; do
101
+ LINK_TARGET="$(readlink "${SCRIPT_PATH}")"
102
+ # Resolve relative targets against the symlink's directory
103
+ if [[ "${LINK_TARGET}" != /* ]]; then
104
+ LINK_TARGET="$(cd "$(dirname "${SCRIPT_PATH}")" && pwd)/${LINK_TARGET}"
105
+ fi
106
+ SCRIPT_PATH="${LINK_TARGET}"
107
+ done
108
+ fi
109
+ SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_PATH}")" && pwd)"
110
+ PACKAGE_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
111
+ QL_ROOT="${PACKAGE_ROOT}/ql"
112
+
113
+ if [ ! -d "${QL_ROOT}" ]; then
114
+ echo "Error: ql/ directory not found at ${QL_ROOT}" >&2
115
+ exit 1
116
+ fi
117
+
118
+ ## Install pack dependencies for a single language.
119
+ install_language_pack() {
120
+ local lang="$1"
121
+ local pack_dir="${QL_ROOT}/${lang}/tools/src"
122
+
123
+ if [ ! -d "${pack_dir}" ]; then
124
+ echo "⚠️ Skipping ${lang}: ${pack_dir} not found"
125
+ return
126
+ fi
127
+
128
+ if [ ! -f "${pack_dir}/codeql-pack.yml" ]; then
129
+ echo "⚠️ Skipping ${lang}: no codeql-pack.yml in ${pack_dir}"
130
+ return
131
+ fi
132
+
133
+ echo "📦 Installing pack dependencies for ${lang}..."
134
+ "${CODEQL}" pack install --no-strict-mode -- "${pack_dir}"
135
+ echo "✅ ${lang} pack dependencies installed"
136
+ }
137
+
138
+ ## Main
139
+ if [ -n "${LANGUAGE}" ]; then
140
+ echo "Installing pack dependencies for language: ${LANGUAGE}"
141
+ install_language_pack "${LANGUAGE}"
142
+ else
143
+ echo "Installing pack dependencies for all languages..."
144
+ for lang in "${VALID_LANGUAGES[@]}"; do
145
+ install_language_pack "${lang}"
146
+ done
147
+ fi
148
+
149
+ echo ""
150
+ echo "Done. Tool query pack dependencies are cached in ~/.codeql/packages/"