Skip to content

Commit 52c0486

Browse files
committed
refactor(skills): coral tpu now uses js monitor for host entry tracking
Aligns the yolo-detection-2026-coral-tpu skill architectural flow with CameraClaw by using a host-side `monitor.js` script rather than emitting a hardcoded `run_command` from `deploy.sh`. This fixes Docker invocation inconsistencies natively inside Aegis. Also handles cross-platform volume mapping via `os.tmpdir()` which fixes Windows mapping issues.
1 parent c5f0d40 commit 52c0486

4 files changed

Lines changed: 77 additions & 18 deletions

File tree

skills/detection/yolo-detection-2026-coral-tpu/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: yolo-detection-2026-coral-tpu
33
description: "Google Coral Edge TPU — real-time object detection via Docker"
44
version: 1.0.0
55
icon: assets/icon.png
6-
entry: scripts/detect.py
6+
entry: scripts/monitor.js
77
deploy: deploy.sh
88
runtime: docker
99

skills/detection/yolo-detection-2026-coral-tpu/deploy.bat

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ if %errorlevel% equ 0 (
6161
echo {"event": "progress", "stage": "probe", "message": "No Edge TPU detected - CPU fallback"}
6262
)
6363

64-
REM ─── Step 4: Set run command ──────────────────────────────────────────────
65-
66-
set "RUN_CMD=docker run -i --rm --privileged -v /tmp/aegis_detection:/tmp/aegis_detection --env AEGIS_SKILL_ID --env AEGIS_SKILL_PARAMS --env PYTHONUNBUFFERED=1 %IMAGE_NAME%:%IMAGE_TAG%"
67-
68-
echo {"event": "complete", "status": "success", "run_command": "%RUN_CMD%", "message": "Coral TPU skill installed"}
64+
echo {"event": "complete", "status": "success", "message": "Coral TPU skill installed"}
6965

7066
echo %LOG_PREFIX% Done! 1>&2
7167
exit /b 0

skills/detection/yolo-detection-2026-coral-tpu/deploy.sh

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,16 @@ else
113113
emit '{"event": "progress", "stage": "probe", "message": "No Edge TPU detected — CPU fallback available"}'
114114
fi
115115

116-
# ─── Step 5: Build run command ───────────────────────────────────────────────
117-
118-
# The run command Aegis will use to launch the skill
119-
# stdin/stdout pipe (-i), auto-remove (--rm), shared volume
120-
RUN_CMD="$DOCKER_CMD run -i --rm $USB_FLAG"
121-
RUN_CMD="$RUN_CMD -v /tmp/aegis_detection:/tmp/aegis_detection"
122-
RUN_CMD="$RUN_CMD --env AEGIS_SKILL_ID --env AEGIS_SKILL_PARAMS --env PYTHONUNBUFFERED=1"
123-
RUN_CMD="$RUN_CMD $IMAGE_NAME:$IMAGE_TAG"
124-
125-
log "Runtime command: $RUN_CMD"
116+
# ─── Step 5: Complete ────────────────────────────────────────────────────────
126117

127118
# ─── Step 6: Complete ────────────────────────────────────────────────────────
128119

129120
if [ "$TPU_FOUND" = true ]; then
130-
emit "{\"event\": \"complete\", \"status\": \"success\", \"tpu_found\": true, \"run_command\": \"$RUN_CMD\", \"message\": \"Coral TPU skill installed — Edge TPU ready\"}"
121+
emit "{\"event\": \"complete\", \"status\": \"success\", \"tpu_found\": true, \"message\": \"Coral TPU skill installed — Edge TPU ready\"}"
131122
log "Done! Edge TPU ready."
132123
exit 0
133124
else
134-
emit "{\"event\": \"complete\", \"status\": \"partial\", \"tpu_found\": false, \"run_command\": \"$RUN_CMD\", \"message\": \"Coral TPU skill installed — no TPU detected (CPU fallback)\"}"
125+
emit "{\"event\": \"complete\", \"status\": \"partial\", \"tpu_found\": false, \"message\": \"Coral TPU skill installed — no TPU detected (CPU fallback)\"}"
135126
log "Done with warning: no TPU detected. Connect Coral USB and restart."
136127
exit 2
137128
fi
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Coral TPU Monitor
3+
* Host-side wrapper to launch the Coral TPU Docker container.
4+
* Matches the CameraClaw architecture by acting as the skill entrypoint.
5+
*/
6+
7+
const { spawn } = require('node:child_process');
8+
const os = require('node:os');
9+
const fs = require('node:fs');
10+
11+
function main() {
12+
const imageName = 'aegis-coral-tpu';
13+
const imageTag = 'latest';
14+
15+
const cmd = 'docker';
16+
const args = ['run', '-i', '--rm'];
17+
18+
// Extra PATH augmentation to ensure docker is found when launched via Electron on macOS
19+
const extraPaths = ['/opt/homebrew/bin', '/usr/local/bin', '/usr/bin'];
20+
const currentPath = process.env.PATH || '';
21+
const missing = extraPaths.filter(p => !currentPath.split(':').includes(p));
22+
if (missing.length > 0) {
23+
process.env.PATH = [...missing, currentPath].join(':');
24+
}
25+
26+
// Handle USB Passthrough (Coral Edge TPU)
27+
// macOS/Windows handle USB dynamically via Docker Desktop 4.35+
28+
// Only Linux requires explicit device mounting
29+
if (os.platform() === 'linux' && fs.existsSync('/dev/bus/usb')) {
30+
args.push('--device', '/dev/bus/usb:/dev/bus/usb');
31+
}
32+
33+
// Shared memory volume for video frames
34+
const path = require('node:path');
35+
const sharedMemoryHost = path.join(os.tmpdir(), 'aegis_detection');
36+
if (!fs.existsSync(sharedMemoryHost)) {
37+
fs.mkdirSync(sharedMemoryHost, { recursive: true });
38+
}
39+
args.push('-v', `${sharedMemoryHost}:/tmp/aegis_detection`);
40+
41+
// Pass through Aegis parameters and ID dynamically
42+
for (const [key, val] of Object.entries(process.env)) {
43+
if (key.startsWith('AEGIS_') || key === 'PYTHONUNBUFFERED') {
44+
args.push('--env', `${key}=${val}`);
45+
}
46+
}
47+
48+
if (!process.env.PYTHONUNBUFFERED) {
49+
args.push('--env', 'PYTHONUNBUFFERED=1');
50+
}
51+
52+
args.push(`${imageName}:${imageTag}`);
53+
54+
const child = spawn(cmd, args, {
55+
stdio: 'inherit'
56+
});
57+
58+
child.on('error', (err) => {
59+
console.log(JSON.stringify({
60+
event: 'error',
61+
message: `Docker is not installed or not in PATH: ${err.message}`,
62+
retriable: false
63+
}));
64+
process.exit(1);
65+
});
66+
67+
child.on('exit', (code) => {
68+
process.exit(code || 0);
69+
});
70+
}
71+
72+
main();

0 commit comments

Comments
 (0)