@zookanalytics/agent-env 1.0.1 → 1.1.1
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/config/baseline/init-host.sh +18 -6
- package/dist/cli.js +108 -32
- package/package.json +1 -1
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# init-host.sh - Runs on the HOST before container creation (initializeCommand)
|
|
3
3
|
# Ensures mount sources exist to prevent devcontainer up failures.
|
|
4
|
-
# The .gitconfig
|
|
4
|
+
# The .gitconfig mount is provided by the image LABEL metadata; the SSH agent
|
|
5
|
+
# socket mount is injected per-platform by agent-env (resolveSshAgentMount).
|
|
5
6
|
|
|
6
7
|
set -euo pipefail
|
|
7
8
|
|
|
8
9
|
GITCONFIG="$HOME/.gitconfig"
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
# Host SSH agent socket. macOS Docker Desktop/OrbStack expose it at a fixed path;
|
|
12
|
+
# on Linux it is the host's real $SSH_AUTH_SOCK. Used only for a pre-flight warning.
|
|
13
|
+
if [ "$(uname -s)" = "Darwin" ]; then
|
|
14
|
+
SSH_SOCKET="/run/host-services/ssh-auth.sock"
|
|
15
|
+
else
|
|
16
|
+
SSH_SOCKET="${SSH_AUTH_SOCK:-}"
|
|
17
|
+
fi
|
|
10
18
|
|
|
11
19
|
# Ensure ~/.gitconfig exists (mounted read-only into container)
|
|
12
20
|
if [ ! -f "$GITCONFIG" ]; then
|
|
@@ -48,11 +56,15 @@ if [ -f "$PULSE_COOKIE_SRC" ]; then
|
|
|
48
56
|
echo "agent-env: Staged PulseAudio cookie for audio passthrough"
|
|
49
57
|
fi
|
|
50
58
|
|
|
51
|
-
# Verify SSH agent socket
|
|
52
|
-
if [ ! -S "$SSH_SOCKET" ]; then
|
|
53
|
-
echo "agent-env: Warning: SSH agent socket
|
|
59
|
+
# Verify a host SSH agent socket is available to forward into the container.
|
|
60
|
+
if [ -z "$SSH_SOCKET" ] || [ ! -S "$SSH_SOCKET" ]; then
|
|
61
|
+
echo "agent-env: Warning: no SSH agent socket found${SSH_SOCKET:+ at $SSH_SOCKET}"
|
|
54
62
|
echo "agent-env: SSH operations (git clone/push) may not work inside the container."
|
|
55
|
-
|
|
63
|
+
if [ "$(uname -s)" = "Darwin" ]; then
|
|
64
|
+
echo "agent-env: Ensure Docker Desktop or OrbStack is running."
|
|
65
|
+
else
|
|
66
|
+
echo "agent-env: Start an SSH agent and load your key (eval \"\$(ssh-agent -s)\" && ssh-add)."
|
|
67
|
+
fi
|
|
56
68
|
fi
|
|
57
69
|
|
|
58
70
|
echo "agent-env: Host initialization complete"
|
package/dist/cli.js
CHANGED
|
@@ -57,7 +57,7 @@ import React5 from "react";
|
|
|
57
57
|
// package.json
|
|
58
58
|
var package_default = {
|
|
59
59
|
name: "@zookanalytics/agent-env",
|
|
60
|
-
version: "1.
|
|
60
|
+
version: "1.1.1",
|
|
61
61
|
description: "CLI for creating isolated, AI-ready development environments",
|
|
62
62
|
type: "module",
|
|
63
63
|
bin: {
|
|
@@ -194,6 +194,37 @@ function createContainerLifecycle(executor = createExecutor()) {
|
|
|
194
194
|
const result = await executor("docker", ["info"], { timeout: DOCKER_INFO_TIMEOUT });
|
|
195
195
|
return result.ok;
|
|
196
196
|
}
|
|
197
|
+
async function isDevcontainerCliAvailable() {
|
|
198
|
+
const result = await executor("devcontainer", ["--version"], { timeout: DOCKER_INFO_TIMEOUT });
|
|
199
|
+
return result.ok;
|
|
200
|
+
}
|
|
201
|
+
async function checkDevcontainerPrerequisites() {
|
|
202
|
+
if (!await isDockerAvailable()) {
|
|
203
|
+
return {
|
|
204
|
+
ok: false,
|
|
205
|
+
status: "not-found",
|
|
206
|
+
containerId: null,
|
|
207
|
+
error: {
|
|
208
|
+
code: "ORBSTACK_REQUIRED",
|
|
209
|
+
message: "Docker is not available. OrbStack or Docker Desktop must be running.",
|
|
210
|
+
suggestion: "Start OrbStack or Docker Desktop, then try again."
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (!await isDevcontainerCliAvailable()) {
|
|
215
|
+
return {
|
|
216
|
+
ok: false,
|
|
217
|
+
status: "not-found",
|
|
218
|
+
containerId: null,
|
|
219
|
+
error: {
|
|
220
|
+
code: "DEVCONTAINER_CLI_MISSING",
|
|
221
|
+
message: "The `devcontainer` CLI was not found on your PATH.",
|
|
222
|
+
suggestion: 'Install it with `npm install -g @devcontainers/cli`, or \u2014 if you use VS Code \u2014 run the "Dev Containers: Install devcontainer CLI" command and ensure the resulting binary is on your PATH.'
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
197
228
|
async function containerStatus(containerName) {
|
|
198
229
|
const result = await executor("docker", ["inspect", containerName], {
|
|
199
230
|
timeout: DOCKER_INSPECT_TIMEOUT
|
|
@@ -296,18 +327,9 @@ function createContainerLifecycle(executor = createExecutor()) {
|
|
|
296
327
|
return name || null;
|
|
297
328
|
}
|
|
298
329
|
async function devcontainerUp(workspacePath, containerName, options) {
|
|
299
|
-
const
|
|
300
|
-
if (
|
|
301
|
-
return
|
|
302
|
-
ok: false,
|
|
303
|
-
status: "not-found",
|
|
304
|
-
containerId: null,
|
|
305
|
-
error: {
|
|
306
|
-
code: "ORBSTACK_REQUIRED",
|
|
307
|
-
message: "Docker is not available. OrbStack or Docker Desktop must be running.",
|
|
308
|
-
suggestion: "Start OrbStack or Docker Desktop, then try again."
|
|
309
|
-
}
|
|
310
|
-
};
|
|
330
|
+
const prereqError = await checkDevcontainerPrerequisites();
|
|
331
|
+
if (prereqError) {
|
|
332
|
+
return prereqError;
|
|
311
333
|
}
|
|
312
334
|
const buildNoCache = options?.buildNoCache === true;
|
|
313
335
|
const remoteEnvArgs = Object.entries(options?.remoteEnv ?? {}).flatMap(([key, value]) => [
|
|
@@ -412,6 +434,7 @@ function createContainerLifecycle(executor = createExecutor()) {
|
|
|
412
434
|
}
|
|
413
435
|
return {
|
|
414
436
|
isDockerAvailable,
|
|
437
|
+
isDevcontainerCliAvailable,
|
|
415
438
|
containerStatus,
|
|
416
439
|
getContainerNameById,
|
|
417
440
|
findContainerByWorkspaceLabel,
|
|
@@ -988,12 +1011,28 @@ async function writeGeneratedConfig(outputPath, config, deps = defaultMergeDeps)
|
|
|
988
1011
|
await deps.writeFile(tmpPath, content, "utf-8");
|
|
989
1012
|
await deps.rename(tmpPath, outputPath);
|
|
990
1013
|
}
|
|
1014
|
+
var SSH_AGENT_CONTAINER_SOCKET = "/run/host-services/ssh-auth.sock";
|
|
1015
|
+
function resolveSshAgentMount(platform2 = process.platform, sshAuthSock = process.env.SSH_AUTH_SOCK) {
|
|
1016
|
+
const target = SSH_AGENT_CONTAINER_SOCKET;
|
|
1017
|
+
const forwarding = (source) => ({
|
|
1018
|
+
mount: `source=${source},target=${target},type=bind`,
|
|
1019
|
+
env: { SSH_AUTH_SOCK: target }
|
|
1020
|
+
});
|
|
1021
|
+
if (platform2 === "darwin") {
|
|
1022
|
+
return forwarding(target);
|
|
1023
|
+
}
|
|
1024
|
+
if (sshAuthSock && sshAuthSock.length > 0) {
|
|
1025
|
+
return forwarding("${localEnv:SSH_AUTH_SOCK}");
|
|
1026
|
+
}
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
991
1029
|
function buildManagedConfig(defaults, params) {
|
|
992
1030
|
const statusBarWatcher = {
|
|
993
1031
|
match: `${STATUS_BAR_JSON_FILENAME}$`,
|
|
994
1032
|
event: "onFolderChange",
|
|
995
1033
|
vscodeTask: "betterStatusBar.refreshButtons"
|
|
996
1034
|
};
|
|
1035
|
+
const sshAgent = params.sshAgent === void 0 ? resolveSshAgentMount() : params.sshAgent;
|
|
997
1036
|
return {
|
|
998
1037
|
image: defaults.image,
|
|
999
1038
|
instanceName: params.instanceName,
|
|
@@ -1005,9 +1044,10 @@ function buildManagedConfig(defaults, params) {
|
|
|
1005
1044
|
...defaults.baseContainerEnv,
|
|
1006
1045
|
AGENT_ENV_INSTANCE: params.instanceName,
|
|
1007
1046
|
AGENT_ENV_REPO: params.repoSlug,
|
|
1008
|
-
AGENT_ENV_PURPOSE: params.purpose
|
|
1047
|
+
AGENT_ENV_PURPOSE: params.purpose,
|
|
1048
|
+
...sshAgent?.env ?? {}
|
|
1009
1049
|
},
|
|
1010
|
-
mounts: [],
|
|
1050
|
+
mounts: sshAgent ? [sshAgent.mount] : [],
|
|
1011
1051
|
customizations: {
|
|
1012
1052
|
vscode: {
|
|
1013
1053
|
settings: {
|
|
@@ -2556,28 +2596,66 @@ import { Command as Command4 } from "commander";
|
|
|
2556
2596
|
|
|
2557
2597
|
// src/lib/progress-line.ts
|
|
2558
2598
|
var ERASE_LINE = "\x1B[K";
|
|
2559
|
-
|
|
2599
|
+
var PREFIX = "\u23F3 ";
|
|
2600
|
+
var PREFIX_LEN = 3;
|
|
2601
|
+
var DEFAULT_MAX_LINES = 5;
|
|
2602
|
+
function createProgressLine(stream = process.stderr, columns, maxLines = DEFAULT_MAX_LINES) {
|
|
2603
|
+
if (!Number.isFinite(maxLines) || maxLines < 1) {
|
|
2604
|
+
throw new RangeError(`maxLines must be at least 1; received ${maxLines}`);
|
|
2605
|
+
}
|
|
2560
2606
|
if (!stream.isTTY) {
|
|
2561
2607
|
return { update() {
|
|
2562
2608
|
}, clear() {
|
|
2563
2609
|
} };
|
|
2564
2610
|
}
|
|
2565
2611
|
const maxWidth = columns ?? stream.columns ?? 80;
|
|
2566
|
-
const
|
|
2567
|
-
|
|
2568
|
-
|
|
2612
|
+
const buffer = [];
|
|
2613
|
+
let drawnHeight = 0;
|
|
2614
|
+
function truncate(line) {
|
|
2615
|
+
const clean = line.replace(/\x1b\[[0-9;]*m/g, "");
|
|
2616
|
+
if (clean.length + PREFIX_LEN <= maxWidth) {
|
|
2617
|
+
return clean;
|
|
2618
|
+
}
|
|
2619
|
+
return clean.slice(0, maxWidth - PREFIX_LEN - 1) + "\u2026";
|
|
2620
|
+
}
|
|
2621
|
+
function redraw() {
|
|
2622
|
+
let out = "";
|
|
2623
|
+
if (drawnHeight > 1) {
|
|
2624
|
+
out += `\x1B[${drawnHeight - 1}A`;
|
|
2625
|
+
}
|
|
2626
|
+
out += "\r";
|
|
2627
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
2628
|
+
if (i > 0) out += "\r\n";
|
|
2629
|
+
out += `${ERASE_LINE}${PREFIX}${truncate(buffer[i])}`;
|
|
2630
|
+
}
|
|
2631
|
+
stream.write(out);
|
|
2632
|
+
drawnHeight = buffer.length;
|
|
2633
|
+
}
|
|
2569
2634
|
return {
|
|
2570
2635
|
update(line) {
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2636
|
+
buffer.push(line);
|
|
2637
|
+
if (buffer.length > maxLines) {
|
|
2638
|
+
buffer.shift();
|
|
2639
|
+
}
|
|
2640
|
+
redraw();
|
|
2575
2641
|
},
|
|
2576
2642
|
clear() {
|
|
2577
|
-
if (
|
|
2578
|
-
|
|
2579
|
-
|
|
2643
|
+
if (drawnHeight === 0) return;
|
|
2644
|
+
let out = "";
|
|
2645
|
+
if (drawnHeight > 1) {
|
|
2646
|
+
out += `\x1B[${drawnHeight - 1}A`;
|
|
2647
|
+
}
|
|
2648
|
+
out += `\r${ERASE_LINE}`;
|
|
2649
|
+
for (let i = 1; i < drawnHeight; i++) {
|
|
2650
|
+
out += `\r
|
|
2651
|
+
${ERASE_LINE}`;
|
|
2652
|
+
}
|
|
2653
|
+
if (drawnHeight > 1) {
|
|
2654
|
+
out += `\x1B[${drawnHeight - 1}A\r`;
|
|
2580
2655
|
}
|
|
2656
|
+
stream.write(out);
|
|
2657
|
+
buffer.length = 0;
|
|
2658
|
+
drawnHeight = 0;
|
|
2581
2659
|
}
|
|
2582
2660
|
};
|
|
2583
2661
|
}
|
|
@@ -5013,7 +5091,7 @@ async function executeTmuxSave() {
|
|
|
5013
5091
|
let tmuxOutput;
|
|
5014
5092
|
try {
|
|
5015
5093
|
tmuxOutput = execSync2(
|
|
5016
|
-
'tmux list-panes -a -F "#{pane_id} #{window_index} #{window_name} #{pane_current_path} #{
|
|
5094
|
+
'tmux list-panes -a -F "#{pane_id} #{window_index} #{window_name} #{pane_current_path} #{session_name}"',
|
|
5017
5095
|
{ encoding: "utf-8", timeout: 5e3 }
|
|
5018
5096
|
);
|
|
5019
5097
|
} catch {
|
|
@@ -5022,13 +5100,12 @@ async function executeTmuxSave() {
|
|
|
5022
5100
|
return;
|
|
5023
5101
|
}
|
|
5024
5102
|
const panes = tmuxOutput.trim().split("\n").filter((line) => line.trim()).map((line) => {
|
|
5025
|
-
const [paneId, indexStr, windowName, cwd,
|
|
5103
|
+
const [paneId, indexStr, windowName, cwd, sessionName2] = line.split(" ");
|
|
5026
5104
|
return {
|
|
5027
5105
|
paneId,
|
|
5028
5106
|
windowIndex: parseInt(indexStr, 10),
|
|
5029
5107
|
windowName,
|
|
5030
5108
|
cwd,
|
|
5031
|
-
command,
|
|
5032
5109
|
sessionName: sessionName2
|
|
5033
5110
|
};
|
|
5034
5111
|
});
|
|
@@ -5056,14 +5133,13 @@ async function executeTmuxSave() {
|
|
|
5056
5133
|
seenWindows.add(pane.windowIndex);
|
|
5057
5134
|
const paneEntry = panesState[pane.paneId];
|
|
5058
5135
|
const hasClaudeEntry = typeof paneEntry === "object" && paneEntry !== null && "session_id" in paneEntry;
|
|
5059
|
-
const isClaudeRunning = pane.command === "claude";
|
|
5060
5136
|
const window = {
|
|
5061
5137
|
index: pane.windowIndex,
|
|
5062
5138
|
name: pane.windowName,
|
|
5063
5139
|
cwd: pane.cwd,
|
|
5064
|
-
program:
|
|
5140
|
+
program: hasClaudeEntry ? "claude" : null
|
|
5065
5141
|
};
|
|
5066
|
-
if (
|
|
5142
|
+
if (hasClaudeEntry) {
|
|
5067
5143
|
window.claude_session_id = paneEntry.session_id;
|
|
5068
5144
|
}
|
|
5069
5145
|
windows.push(window);
|