@anthropic-ai/claude-code 0.2.102 → 0.2.103
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/cli.js +651 -636
- package/package.json +1 -1
- package/claude-restart.sh +0 -99
package/package.json
CHANGED
package/claude-restart.sh
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
|
|
3
|
-
# Claude CLI Restart Wrapper
|
|
4
|
-
#
|
|
5
|
-
# This script acts as a wrapper around the main Claude CLI (cli.mjs) that:
|
|
6
|
-
# 1. Launches the CLI with the same arguments passed to this script
|
|
7
|
-
# 2. Monitors the CLI process for a special exit code (42)
|
|
8
|
-
# 3. If the special exit code is detected, it restarts the CLI with the same arguments
|
|
9
|
-
|
|
10
|
-
# Get the real path of this script by using Node.js to follow all symlinks
|
|
11
|
-
SCRIPT_PATH="${BASH_SOURCE[0]}"
|
|
12
|
-
REAL_SCRIPT_PATH=$(/usr/bin/env node -e "console.log(require('fs').realpathSync('$SCRIPT_PATH'))")
|
|
13
|
-
|
|
14
|
-
# Get the directory of the real script
|
|
15
|
-
SCRIPT_DIR="$( dirname "$REAL_SCRIPT_PATH" )"
|
|
16
|
-
|
|
17
|
-
# Path to cli.js - look for it in the same directory as this script
|
|
18
|
-
CLI_PATH="$SCRIPT_DIR/cli.js"
|
|
19
|
-
|
|
20
|
-
# DO NOT change the current working directory
|
|
21
|
-
# The CLI needs to maintain the original working directory it was launched from
|
|
22
|
-
|
|
23
|
-
# Define the signals we'll use to indicate a restart is needed
|
|
24
|
-
# Using exit code 42 as our special signal for command-based restart
|
|
25
|
-
RESTART_EXIT_CODE=42
|
|
26
|
-
# Using exit code 43 as our special signal for tool-based restart
|
|
27
|
-
TOOL_RESTART_EXIT_CODE=43
|
|
28
|
-
|
|
29
|
-
# Check if cli.mjs exists
|
|
30
|
-
if [ ! -f "$CLI_PATH" ]; then
|
|
31
|
-
echo "Error: Could not find $CLI_PATH"
|
|
32
|
-
exit 1
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
# Function to start the CLI
|
|
36
|
-
start_cli() {
|
|
37
|
-
local is_restart="${2:-false}"
|
|
38
|
-
local args=("$@")
|
|
39
|
-
|
|
40
|
-
# Remove the is_restart parameter from args
|
|
41
|
-
if [ "$is_restart" = "true" ]; then
|
|
42
|
-
# If second parameter is "true", remove first two parameters
|
|
43
|
-
args=("${args[@]:2}")
|
|
44
|
-
else
|
|
45
|
-
# If second parameter is not "true", just remove first parameter
|
|
46
|
-
args=("${args[@]:1}")
|
|
47
|
-
fi
|
|
48
|
-
|
|
49
|
-
# If this is a restart triggered by exit code 42 and no args are provided, add 'resume 0' to restore the last conversation
|
|
50
|
-
if [ "$is_restart" = "true" ] && [ ${#args[@]} -eq 0 ]; then
|
|
51
|
-
# Always add resume 0 when restarting due to exit code 42 and no other arguments exist
|
|
52
|
-
args=("resume" "0")
|
|
53
|
-
fi
|
|
54
|
-
|
|
55
|
-
# Run cli.mjs with the provided arguments
|
|
56
|
-
"$CLI_PATH" "${args[@]}"
|
|
57
|
-
|
|
58
|
-
# Capture the exit code
|
|
59
|
-
EXIT_CODE=$?
|
|
60
|
-
|
|
61
|
-
# Check if we need to restart
|
|
62
|
-
if [ $EXIT_CODE -eq $RESTART_EXIT_CODE ]; then
|
|
63
|
-
|
|
64
|
-
# When restarting due to exit code 42, filter args to keep only flags (starting with - or --)
|
|
65
|
-
# and add "resume 0" at the end
|
|
66
|
-
local restart_args=()
|
|
67
|
-
for arg in "${args[@]}"; do
|
|
68
|
-
if [[ "$arg" == -* ]]; then
|
|
69
|
-
restart_args+=("$arg")
|
|
70
|
-
fi
|
|
71
|
-
done
|
|
72
|
-
|
|
73
|
-
# Add resume 0 at the end
|
|
74
|
-
restart_args+=("resume" "0")
|
|
75
|
-
|
|
76
|
-
start_cli "true" "${restart_args[@]}"
|
|
77
|
-
elif [ $EXIT_CODE -eq $TOOL_RESTART_EXIT_CODE ]; then
|
|
78
|
-
|
|
79
|
-
# When restarting due to exit code 43 (tool restart), filter args to keep only flags (starting with - or --)
|
|
80
|
-
# and use "Keep going.." prompt instead
|
|
81
|
-
local restart_args=()
|
|
82
|
-
for arg in "${args[@]}"; do
|
|
83
|
-
if [[ "$arg" == -* ]]; then
|
|
84
|
-
restart_args+=("$arg")
|
|
85
|
-
fi
|
|
86
|
-
done
|
|
87
|
-
|
|
88
|
-
# Start with "Keep going.." prompt
|
|
89
|
-
restart_args+=("Keep going..")
|
|
90
|
-
|
|
91
|
-
start_cli "true" "${restart_args[@]}"
|
|
92
|
-
else
|
|
93
|
-
# Any other exit code - exit with the same code
|
|
94
|
-
exit $EXIT_CODE
|
|
95
|
-
fi
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
# Start the CLI with all arguments passed to this script
|
|
99
|
-
start_cli "false" "$@"
|