Skip to content

Commit b16ce68

Browse files
committed
fix(acp,terminal): support auth url bridging and avoid unnecessary acode helper rewrites
1 parent 45c43a2 commit b16ce68

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

src/components/terminal/terminalManager.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,17 @@ class TerminalManager {
667667
terminalComponent.onOscOpen = async (type, path) => {
668668
if (!path) return;
669669

670-
// Convert proot path
671-
const fileUri = this.convertProotPath(path);
672-
// Extract folder/file name from normalized path
673-
const name = this.getPathDisplayName(path);
674-
675670
try {
671+
if (type === "url" || this.isExternalUrl(path)) {
672+
system.openInBrowser(path);
673+
return;
674+
}
675+
676+
// Convert proot path
677+
const fileUri = this.convertProotPath(path);
678+
// Extract folder/file name from normalized path
679+
const name = this.getPathDisplayName(path);
680+
676681
if (type === "folder") {
677682
// Open folder in sidebar
678683
await openFolder(fileUri, { name, saveState: true, listFiles: true });
@@ -994,6 +999,12 @@ class TerminalManager {
994999
return normalized.pop() || "folder";
9951000
}
9961001

1002+
isExternalUrl(value) {
1003+
if (typeof value !== "string") return false;
1004+
1005+
return /^(https?|ftps?|mailto|tel|sms|geo):/i.test(value.trim());
1006+
}
1007+
9971008
shouldConfirmTerminalClose() {
9981009
const settings = appSettings?.value?.terminalSettings;
9991010
if (settings && settings.confirmTabClose === false) {

src/plugins/terminal/scripts/init-alpine.sh

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,39 @@ Working with packages:
6565
EOF
6666
fi
6767

68-
# Create acode CLI tool
69-
if [ ! -e "$PREFIX/alpine/usr/local/bin/acode" ]; then
70-
mkdir -p "$PREFIX/alpine/usr/local/bin"
71-
cat <<'ACODE_CLI' > "$PREFIX/alpine/usr/local/bin/acode"
68+
# Refresh the Acode CLI bridge only when its generated content changes.
69+
mkdir -p "$PREFIX/alpine/usr/local/bin"
70+
acode_cli_path="$PREFIX/alpine/usr/local/bin/acode"
71+
acode_cli_tmp="$PREFIX/alpine/usr/local/bin/.acode.tmp"
72+
cat <<'ACODE_CLI' > "$acode_cli_tmp"
7273
#!/bin/bash
7374
# acode - Open files/folders in Acode editor
7475
# Uses OSC escape sequences to communicate with the Acode terminal
7576
7677
usage() {
7778
echo "Usage: acode [file/folder...]"
7879
echo ""
79-
echo "Open files or folders in Acode editor."
80+
echo "Open files, folders, or URLs in Acode."
8081
echo ""
8182
echo "Examples:"
8283
echo " acode file.txt # Open a file"
8384
echo " acode . # Open current folder"
8485
echo " acode ~/project # Open a folder"
86+
echo " acode https://... # Open a URL"
8587
echo " acode -h, --help # Show this help"
8688
}
8789
90+
is_url() {
91+
case "$1" in
92+
http://*|https://*|ftp://*|ftps://*|mailto:*|tel:*|sms:*|geo:*)
93+
return 0
94+
;;
95+
*)
96+
return 1
97+
;;
98+
esac
99+
}
100+
88101
get_abs_path() {
89102
local path="$1"
90103
local abs_path=""
@@ -121,6 +134,13 @@ open_in_acode() {
121134
printf '\e]7777;open;%s;%s\a' "$type" "$path"
122135
}
123136
137+
open_url_in_acode() {
138+
# Headless consumers like ACP auth can poll this file when no terminal is
139+
# available to intercept OSC output.
140+
printf '%s\n' "$1" > /tmp/.acode_open_url
141+
printf '\e]7777;open;%s;%s\a' "url" "$1"
142+
}
143+
124144
if [[ $# -eq 0 ]]; then
125145
open_in_acode "."
126146
exit 0
@@ -133,19 +153,28 @@ for arg in "$@"; do
133153
exit 0
134154
;;
135155
*)
136-
if [[ -e "$arg" ]]; then
156+
if is_url "$arg"; then
157+
open_url_in_acode "$arg"
158+
elif [[ -e "$arg" ]]; then
137159
open_in_acode "$arg"
138160
else
139-
echo "Error: '$arg' does not exist" >&2
161+
echo "Error: '$arg' does not exist or is not a supported URL" >&2
140162
exit 1
141163
fi
142164
;;
143165
esac
144166
done
145167
ACODE_CLI
146-
chmod +x "$PREFIX/alpine/usr/local/bin/acode"
168+
if [ ! -e "$acode_cli_path" ] || ! cmp -s "$acode_cli_tmp" "$acode_cli_path"; then
169+
mv "$acode_cli_tmp" "$acode_cli_path"
170+
chmod +x "$acode_cli_path"
171+
else
172+
rm -f "$acode_cli_tmp"
147173
fi
148174

175+
# Make xdg-open use the Acode CLI bridge inside the terminal environment.
176+
ln -sfn acode "$PREFIX/alpine/usr/local/bin/xdg-open"
177+
149178
# Create initrc if it doesn't exist
150179
#initrc runs in bash so we can use bash features
151180
if [ ! -e "$PREFIX/alpine/initrc" ]; then

0 commit comments

Comments
 (0)