forked from bchapuis/brokk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli
More file actions
executable file
·137 lines (126 loc) · 4.11 KB
/
cli
File metadata and controls
executable file
·137 lines (126 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
#
# Helper script to launch Brokk CLI from the most-recent build artifact.
# Scans app/build/libs for the latest brokk-*.jar and runs the CLI.
set -euo pipefail
# Determine the directory this script lives in, resolving any symlinks.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LIB_DIR="$SCRIPT_DIR/app/build/libs"
# Ensure at least one brokk-*.jar exists
if ! ls "$LIB_DIR"/brokk-*.jar &>/dev/null; then
echo "Error: No brokk-*.jar found in $LIB_DIR" >&2
exit 1
fi
# Use the most recently modified brokk-*.jar as the classpath
CLASSPATH="$(ls -t "$LIB_DIR"/brokk-*.jar | head -n 1)"
# Determine which BrokkCli class exists in the JAR
if jar -tf "$CLASSPATH" | grep -q '^ai/brokk/cli/BrokkCli\.class$'; then
CLASS_NAME="ai.brokk.cli.BrokkCli"
elif jar -tf "$CLASSPATH" | grep -q '^io/github/jbellis/brokk/cli/BrokkCli\.class$'; then
CLASS_NAME="io.github.jbellis.brokk.cli.BrokkCli"
else
echo "Error: BrokkCli class not found in $CLASSPATH" >&2
exit 1
fi
# Launch BrokkCli.
# We use PGC because it's more space-efficient than the default G1,
# and in cli mode we're not latency sensitive.
# Remote debugger is ENABLED by default. Disable via --no-debug or BROKK_DEBUG=false.
# Supported CLI flags:
# --debug[=PORT] enable JDWP on PORT (default 5005)
# --debug-port=PORT same as --debug=PORT
# --debug-suspend wait for debugger to attach before starting
# --no-debug disable JDWP (overrides env/default)
# Env vars:
# BROKK_DEBUG=true|false|PORT enable/disable debug; PORT overrides port (true/1/yes/on; false/0/no/off)
# BROKK_DEBUG_PORT=PORT port to listen on (default 5005)
# BROKK_DEBUG_SUSPEND=y|n whether to suspend on start (default n)
declare -a JVM_ARGS=()
declare -a APP_ARGS=()
DEBUG_ENABLED=false
DEBUG_PORT="${BROKK_DEBUG_PORT:-5005}"
DEBUG_SUSPEND="${BROKK_DEBUG_SUSPEND:-n}"
# Environment override for debug behavior
if [[ -n "${BROKK_DEBUG:-}" ]]; then
brokk_debug_lc="$(printf '%s' "${BROKK_DEBUG}" | tr '[:upper:]' '[:lower:]')"
case "${brokk_debug_lc}" in
false|0|no|off)
DEBUG_ENABLED=false
;;
true|1|yes|on)
DEBUG_ENABLED=true
;;
*)
if [[ "${BROKK_DEBUG}" =~ ^[0-9]+$ ]]; then
DEBUG_ENABLED=true
DEBUG_PORT="${BROKK_DEBUG}"
else
# Unknown value; keep default enabled
DEBUG_ENABLED=true
fi
;;
esac
fi
for arg in "$@"; do
case "$arg" in
--debug)
DEBUG_ENABLED=true
;;
--debug=*)
DEBUG_ENABLED=true
DEBUG_PORT="${arg#--debug=}"
;;
--debug-port=*)
DEBUG_ENABLED=true
DEBUG_PORT="${arg#--debug-port=}"
;;
--debug-suspend)
DEBUG_ENABLED=true
DEBUG_SUSPEND="y"
;;
--no-debug)
DEBUG_ENABLED=false
;;
-X*|-D*)
JVM_ARGS+=("$arg")
;;
*)
APP_ARGS+=("$arg")
;;
esac
done
# Build the final JVM argument list, adding a default -Xmx1G unless the caller
# already supplied an explicit -Xmx option.
declare -a EFFECTIVE_JVM_ARGS=("-ea" "-XX:+UseParallelGC")
# Always use test logging configuration
EFFECTIVE_JVM_ARGS+=("-Dlog4j.configurationFile=$SCRIPT_DIR/app/src/test/resources/log4j2-test.xml")
xmx_specified=false
for arg in "${JVM_ARGS[@]-}"; do
if [[ $arg == -Xmx* ]]; then
xmx_specified=true
break
fi
done
if ! $xmx_specified; then
EFFECTIVE_JVM_ARGS+=("-Xmx1G")
fi
# Append any user-supplied JVM args (which may include their own -Xmx)
EFFECTIVE_JVM_ARGS+=(${JVM_ARGS[@]+"${JVM_ARGS[@]}"})
# Add JDWP agent if debugging is enabled and not already specified by the user
jdwp_specified=false
for arg in "${JVM_ARGS[@]-}"; do
if [[ $arg == -agentlib:jdwp* || $arg == -Xrunjdwp* ]]; then
jdwp_specified=true
break
fi
done
if $DEBUG_ENABLED && ! $jdwp_specified; then
EFFECTIVE_JVM_ARGS+=("-agentlib:jdwp=transport=dt_socket,server=y,suspend=$DEBUG_SUSPEND,address=*:$DEBUG_PORT")
echo "Debugging enabled on port $DEBUG_PORT (suspend=$DEBUG_SUSPEND)" >&2
fi
# Launch BrokkCli with the determined class name
exec java \
"${EFFECTIVE_JVM_ARGS[@]}" \
-cp "$CLASSPATH" \
"$CLASS_NAME" \
"${APP_ARGS[@]-}"