@mrtrinhvn/ag-kit 1.4.8 → 1.4.11
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/package.json
CHANGED
|
@@ -8,6 +8,18 @@ cd "$PROJECT_DIR"
|
|
|
8
8
|
|
|
9
9
|
mkdir -p .agent/logs
|
|
10
10
|
|
|
11
|
+
# 0. NVM/Node PATH Resolution for GUI Execution
|
|
12
|
+
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
|
|
13
|
+
if [ -f "$HOME/.bashrc" ]; then
|
|
14
|
+
source "$HOME/.bashrc" >/dev/null 2>&1 || true
|
|
15
|
+
fi
|
|
16
|
+
if [ -s "$HOME/.nvm/nvm.sh" ]; then
|
|
17
|
+
source "$HOME/.nvm/nvm.sh" >/dev/null 2>&1 || true
|
|
18
|
+
fi
|
|
19
|
+
if [ -s "$HOME/.bun/_bun" ]; then
|
|
20
|
+
export PATH="$HOME/.bun/bin:$PATH"
|
|
21
|
+
fi
|
|
22
|
+
|
|
11
23
|
# 1. Load Cấu hình Tĩnh từ .env
|
|
12
24
|
if [ -f .env ]; then
|
|
13
25
|
source .env
|
|
@@ -15,6 +27,7 @@ fi
|
|
|
15
27
|
|
|
16
28
|
export IDE_PORT=${IDE_PORT:-9555}
|
|
17
29
|
export BRIDGE_PORT=${BRIDGE_PORT:-9656}
|
|
30
|
+
export PROJECT_NAME=${PROJECT_NAME:-"UnknownProject"}
|
|
18
31
|
|
|
19
32
|
echo "════════════════════════════════════════════════════"
|
|
20
33
|
echo " 🏢 AG GATEWAY - CẦU NỐI NỘI BỘ [$BRIDGE_PORT]"
|
|
@@ -28,7 +41,7 @@ if [ -f "$BRIDGE_PID_FILE" ]; then
|
|
|
28
41
|
fi
|
|
29
42
|
# Surgical Port Kill (Garbage Collection)
|
|
30
43
|
lsof -ti tcp:${BRIDGE_PORT} | xargs kill -9 2>/dev/null || true
|
|
31
|
-
|
|
44
|
+
setsid node scripts/ag_portal_bridge.js > ".agent/logs/portal_bridge_${BRIDGE_PORT}.log" 2>&1 &
|
|
32
45
|
echo $! > "$BRIDGE_PID_FILE"
|
|
33
46
|
echo " ✅ Bridge đang chạy (PID: $(cat "$BRIDGE_PID_FILE") tại Cổng $BRIDGE_PORT)"
|
|
34
47
|
|
|
@@ -46,7 +59,7 @@ if [ -f "$BOT_PID_FILE" ]; then
|
|
|
46
59
|
fi
|
|
47
60
|
sleep 1
|
|
48
61
|
|
|
49
|
-
|
|
62
|
+
setsid bash -c "while true; do
|
|
50
63
|
echo \"\$(date): Khởi động Bot...\" >> .agent/logs/bot_interaction.log
|
|
51
64
|
npx tsx src/index.ts >> .agent/logs/bot_interaction.log 2>&1
|
|
52
65
|
EXIT_CODE=\$?
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
if (window.ag_popup_win && !window.ag_popup_win.closed) window.ag_popup_win.close();
|
|
4
4
|
|
|
5
5
|
const HUD_ID = 'antigravity-elite-statusbar-item';
|
|
6
|
-
if (document.getElementById(HUD_ID))
|
|
6
|
+
if (document.getElementById(HUD_ID)) return "ALREADY_EXISTS";
|
|
7
7
|
|
|
8
8
|
// 2. Locate Status Bar
|
|
9
9
|
const statusBar = document.querySelector('.part.statusbar');
|
|
@@ -32,8 +32,14 @@ async function refreshTargets() {
|
|
|
32
32
|
try {
|
|
33
33
|
const targets = JSON.parse(data);
|
|
34
34
|
|
|
35
|
-
// Find
|
|
36
|
-
const
|
|
35
|
+
// Find workbench target for specific project
|
|
36
|
+
const projName = process.env.PROJECT_NAME || '';
|
|
37
|
+
const workbenchTargets = targets.filter(t =>
|
|
38
|
+
t.url &&
|
|
39
|
+
t.url.includes('workbench.html') &&
|
|
40
|
+
t.title &&
|
|
41
|
+
t.title.toLowerCase().includes(projName.toLowerCase())
|
|
42
|
+
);
|
|
37
43
|
|
|
38
44
|
workbenchTargets.forEach(target => {
|
|
39
45
|
if (!activeConnections.has(target.webSocketDebuggerUrl)) {
|
|
@@ -87,21 +93,15 @@ function injectHUDIntoContext(ws, contextId) {
|
|
|
87
93
|
if (!fs.existsSync(hudPath)) return;
|
|
88
94
|
|
|
89
95
|
const script = fs.readFileSync(hudPath, 'utf8');
|
|
90
|
-
const b64Script = Buffer.from(script).toString('base64');
|
|
91
96
|
|
|
92
97
|
const message = {
|
|
93
98
|
id: 1000 + contextId,
|
|
94
99
|
method: "Runtime.evaluate",
|
|
95
100
|
params: {
|
|
96
|
-
expression:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
s.textContent = atob('${b64Script}');
|
|
101
|
-
document.head.appendChild(s);
|
|
102
|
-
return "INJECTED";
|
|
103
|
-
})();`,
|
|
104
|
-
contextId: contextId
|
|
101
|
+
expression: script,
|
|
102
|
+
contextId: contextId,
|
|
103
|
+
awaitPromise: true,
|
|
104
|
+
userGesture: true
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
ws.send(JSON.stringify(message));
|
package/template/start.sh
CHANGED
|
@@ -44,31 +44,9 @@ if nc -z 127.0.0.1 $PORT &>/dev/null; then
|
|
|
44
44
|
if curl -s --max-time 2 http://127.0.0.1:$PORT/json/list | grep -i "\"title\":.*$PROJ" &>/dev/null; then
|
|
45
45
|
echo "✅ [HỢP THỂ]: Cổng $PORT đang mở và Workspace [$PROJ] đang được hiển thị. Trực tiếp cắm ngầm Bot vào màn hình này..."
|
|
46
46
|
else
|
|
47
|
-
echo "⚠️ [
|
|
48
|
-
|
|
49
|
-
# Quét tìm cổng trống
|
|
50
|
-
NEW_PORT=9555
|
|
51
|
-
while nc -z 127.0.0.1 $NEW_PORT &>/dev/null; do
|
|
52
|
-
NEW_PORT=$((NEW_PORT + 1))
|
|
53
|
-
done
|
|
54
|
-
|
|
55
|
-
# Cổng Bridge cách IDE 101 cổng cho dễ quản lý
|
|
56
|
-
NEW_BRIDGE=$((NEW_PORT + 101))
|
|
57
|
-
|
|
58
|
-
echo "🚀 Đã phân bổ cặp cổng trống mới: IDE=$NEW_PORT, BRIDGE=$NEW_BRIDGE"
|
|
59
|
-
|
|
60
|
-
# Cập nhật .env
|
|
61
|
-
update_env "IDE_PORT" "$NEW_PORT"
|
|
62
|
-
update_env "BRIDGE_PORT" "$NEW_BRIDGE"
|
|
63
|
-
|
|
64
|
-
# Cập nhật lại biến môi trường cho phiên shell này
|
|
65
|
-
PORT=$NEW_PORT
|
|
66
|
-
export IDE_PORT=$NEW_PORT
|
|
67
|
-
export BRIDGE_PORT=$NEW_BRIDGE
|
|
68
|
-
|
|
69
|
-
echo "⚠️ [MỞ MỚI ĐỘC LẬP]: Đang phóng cỗ máy IDE chuyên biệt tại không gian $PORT..."
|
|
47
|
+
echo "⚠️ [GỌI CỬA]: Cổng $PORT có IDE đang chạy, nhưng chưa mở màn hình cho [$PROJ]. Đang ra lệnh mở thêm giao diện cho dự án này..."
|
|
70
48
|
open_ide
|
|
71
|
-
echo "⏳ Đang đợi
|
|
49
|
+
echo "⏳ Đang đợi màn hình phụ tải xong..."
|
|
72
50
|
sleep 4
|
|
73
51
|
fi
|
|
74
52
|
else
|
|
@@ -78,6 +56,32 @@ else
|
|
|
78
56
|
sleep 4
|
|
79
57
|
fi
|
|
80
58
|
|
|
59
|
+
# Quét tìm cổng Bridge trống nếu bị trùng
|
|
60
|
+
ORIGINAL_BRIDGE=$BRIDGE
|
|
61
|
+
while nc -z 127.0.0.1 $BRIDGE &>/dev/null; do
|
|
62
|
+
# Kiểm tra xem cổng này có phải do chính dự án mình đang giữ từ phiên trước không
|
|
63
|
+
PID_FILE=".agent/logs/.portal_bridge_${BRIDGE}.pid"
|
|
64
|
+
if [ -f "$PID_FILE" ]; then
|
|
65
|
+
PID_IN_FILE=$(cat "$PID_FILE" 2>/dev/null)
|
|
66
|
+
if [ -n "$PID_IN_FILE" ]; then
|
|
67
|
+
if kill -0 "$PID_IN_FILE" 2>/dev/null; then
|
|
68
|
+
echo "🗑️ Dọn dẹp tiến trình cũ của dự án tại cổng $BRIDGE..."
|
|
69
|
+
kill -9 "$PID_IN_FILE" 2>/dev/null || true
|
|
70
|
+
sleep 1
|
|
71
|
+
continue
|
|
72
|
+
fi
|
|
73
|
+
fi
|
|
74
|
+
fi
|
|
75
|
+
# Nếu không phải của mình, nhảy cổng tiếp
|
|
76
|
+
BRIDGE=$((BRIDGE + 1))
|
|
77
|
+
done
|
|
78
|
+
|
|
79
|
+
if [ "$BRIDGE" != "$ORIGINAL_BRIDGE" ]; then
|
|
80
|
+
echo "🚀 Cổng Bridge $ORIGINAL_BRIDGE đã bị chiếm. Đã phân bổ cổng trống mới: BRIDGE=$BRIDGE"
|
|
81
|
+
update_env "BRIDGE_PORT" "$BRIDGE"
|
|
82
|
+
export BRIDGE_PORT=$BRIDGE
|
|
83
|
+
fi
|
|
84
|
+
|
|
81
85
|
# 3. Khởi động Giao diện & Agent (Receptionist)
|
|
82
86
|
echo "🚀 Đang đánh thức bộ não Agentic Gateway..."
|
|
83
87
|
bash .agent/scripts/receptionist_up.sh
|