icoa-cli 1.4.4 → 1.5.0
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/dist/index.js +1 -1
- package/dist/lib/sandbox.d.ts +7 -0
- package/dist/lib/sandbox.js +93 -0
- package/dist/repl.js +14 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ ${B} ${B}
|
|
|
37
37
|
${B} ${chalk.white('Sydney, Australia')} ${chalk.gray('Jun 27 - Jul 2, 2026')} ${B}
|
|
38
38
|
${B} ${chalk.cyan.underline('https://icoa2026.au')} ${B}
|
|
39
39
|
${B} ${B}
|
|
40
|
-
${B} ${chalk.gray('CLI-Native Competition Terminal v1.
|
|
40
|
+
${B} ${chalk.gray('CLI-Native Competition Terminal v1.5.0')} ${B}
|
|
41
41
|
${B} ${B}
|
|
42
42
|
${chalk.cyan('╚══════════════════════════════════════════════════════════╝')}
|
|
43
43
|
`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function isDockerAvailable(): boolean;
|
|
2
|
+
export declare function isSandboxRunning(): boolean;
|
|
3
|
+
export declare function ensureSandbox(): Promise<boolean>;
|
|
4
|
+
export declare function runInSandbox(command: string, rl: {
|
|
5
|
+
pause: () => void;
|
|
6
|
+
resume: () => void;
|
|
7
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { execSync, spawn } from 'node:child_process';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
const IMAGE = 'icoa/sandbox:2026';
|
|
4
|
+
const CONTAINER = 'icoa-sandbox';
|
|
5
|
+
export function isDockerAvailable() {
|
|
6
|
+
try {
|
|
7
|
+
execSync('docker info', { stdio: 'ignore' });
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function isSandboxRunning() {
|
|
15
|
+
try {
|
|
16
|
+
const out = execSync(`docker inspect -f '{{.State.Running}}' ${CONTAINER} 2>/dev/null`, {
|
|
17
|
+
encoding: 'utf-8',
|
|
18
|
+
});
|
|
19
|
+
return out.trim() === 'true';
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function ensureSandbox() {
|
|
26
|
+
if (!isDockerAvailable()) {
|
|
27
|
+
console.log(chalk.yellow(' Docker not found. Install Docker Desktop to use sandbox tools.'));
|
|
28
|
+
console.log(chalk.gray(' https://www.docker.com/products/docker-desktop'));
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (isSandboxRunning())
|
|
32
|
+
return true;
|
|
33
|
+
// Check if container exists but stopped
|
|
34
|
+
try {
|
|
35
|
+
execSync(`docker start ${CONTAINER}`, { stdio: 'ignore' });
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// Container doesn't exist, create it
|
|
40
|
+
}
|
|
41
|
+
// Check if image exists
|
|
42
|
+
try {
|
|
43
|
+
execSync(`docker image inspect ${IMAGE}`, { stdio: 'ignore' });
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
console.log(chalk.gray(' Pulling sandbox image (first time only)...'));
|
|
47
|
+
try {
|
|
48
|
+
execSync(`docker pull ${IMAGE}`, { stdio: 'inherit' });
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Image not on registry yet, try building locally
|
|
52
|
+
console.log(chalk.gray(' Building sandbox from local Dockerfile...'));
|
|
53
|
+
try {
|
|
54
|
+
const dockerDir = new URL('../../docker', import.meta.url).pathname;
|
|
55
|
+
execSync(`docker build -t ${IMAGE} ${dockerDir}`, { stdio: 'inherit' });
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
console.log(chalk.red(' Failed to set up sandbox.'));
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Create and start container
|
|
64
|
+
try {
|
|
65
|
+
execSync(`docker run -d --name ${CONTAINER} ` +
|
|
66
|
+
`-v icoa-challenges:/home/competitor/challenges ` +
|
|
67
|
+
`--network host ` +
|
|
68
|
+
`${IMAGE} sleep infinity`, { stdio: 'ignore' });
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
console.log(chalk.red(' Failed to start sandbox container.'));
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function runInSandbox(command, rl) {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
rl.pause();
|
|
79
|
+
const opts = {
|
|
80
|
+
stdio: 'inherit',
|
|
81
|
+
shell: true,
|
|
82
|
+
};
|
|
83
|
+
const child = spawn('docker', ['exec', '-it', CONTAINER, 'bash', '-c', command], opts);
|
|
84
|
+
child.on('close', () => {
|
|
85
|
+
rl.resume();
|
|
86
|
+
resolve();
|
|
87
|
+
});
|
|
88
|
+
child.on('error', () => {
|
|
89
|
+
rl.resume();
|
|
90
|
+
resolve();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
package/dist/repl.js
CHANGED
|
@@ -4,6 +4,7 @@ import chalk from 'chalk';
|
|
|
4
4
|
import { isConnected, getConfig } from './lib/config.js';
|
|
5
5
|
import { isActivated, activateToken, isFreeCommand, isDeviceMatch, recordExit, recordResume } from './lib/access.js';
|
|
6
6
|
import { resetTerminalTheme } from './lib/theme.js';
|
|
7
|
+
import { ensureSandbox, runInSandbox, isDockerAvailable } from './lib/sandbox.js';
|
|
7
8
|
const INTERCEPT = '__REPL_NO_EXIT__';
|
|
8
9
|
export function startRepl(program, resumeMode) {
|
|
9
10
|
const config = getConfig();
|
|
@@ -127,10 +128,21 @@ export function startRepl(program, resumeMode) {
|
|
|
127
128
|
'lang', 'setup', 'model', 'ctf',
|
|
128
129
|
];
|
|
129
130
|
if (!knownCommands.includes(cmd)) {
|
|
130
|
-
//
|
|
131
|
+
// Route to Docker sandbox if available, otherwise system shell
|
|
131
132
|
processing = true;
|
|
132
133
|
try {
|
|
133
|
-
|
|
134
|
+
if (isDockerAvailable()) {
|
|
135
|
+
const ready = await ensureSandbox();
|
|
136
|
+
if (ready) {
|
|
137
|
+
await runInSandbox(input, rl);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
await runSystemCommand(input, rl);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
await runSystemCommand(input, rl);
|
|
145
|
+
}
|
|
134
146
|
}
|
|
135
147
|
catch {
|
|
136
148
|
console.log(chalk.yellow(` Command failed: ${cmd}`));
|