@zookanalytics/agent-env 0.12.3 → 0.13.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/cli.js +192 -73
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -48,16 +48,16 @@ var execute = createExecutor();
|
|
|
48
48
|
// src/cli.ts
|
|
49
49
|
import { program } from "commander";
|
|
50
50
|
import { render as render3 } from "ink";
|
|
51
|
-
import { existsSync } from "fs";
|
|
52
|
-
import { homedir as
|
|
53
|
-
import { dirname as dirname5, join as
|
|
51
|
+
import { existsSync as existsSync2 } from "fs";
|
|
52
|
+
import { homedir as homedir12 } from "os";
|
|
53
|
+
import { dirname as dirname5, join as join15, resolve } from "path";
|
|
54
54
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
55
55
|
import React4 from "react";
|
|
56
56
|
|
|
57
57
|
// package.json
|
|
58
58
|
var package_default = {
|
|
59
59
|
name: "@zookanalytics/agent-env",
|
|
60
|
-
version: "0.
|
|
60
|
+
version: "0.13.0",
|
|
61
61
|
description: "CLI for creating isolated, AI-ready development environments",
|
|
62
62
|
type: "module",
|
|
63
63
|
bin: {
|
|
@@ -119,8 +119,8 @@ import { Command } from "commander";
|
|
|
119
119
|
|
|
120
120
|
// src/lib/attach-instance.ts
|
|
121
121
|
import { appendFile as appendFile4, mkdir as mkdir6, readdir as readdir5, readFile as readFile8, rename as rename5, stat as stat5, writeFile as writeFile7 } from "fs/promises";
|
|
122
|
-
import { homedir as
|
|
123
|
-
import { join as
|
|
122
|
+
import { homedir as homedir5 } from "os";
|
|
123
|
+
import { join as join8 } from "path";
|
|
124
124
|
|
|
125
125
|
// src/lib/container.ts
|
|
126
126
|
var DEVCONTAINER_UP_TIMEOUT = 3e5;
|
|
@@ -435,8 +435,8 @@ import {
|
|
|
435
435
|
stat as stat4,
|
|
436
436
|
writeFile as writeFile6
|
|
437
437
|
} from "fs/promises";
|
|
438
|
-
import { homedir as
|
|
439
|
-
import { dirname as dirname2, join as
|
|
438
|
+
import { homedir as homedir4 } from "os";
|
|
439
|
+
import { dirname as dirname2, join as join7 } from "path";
|
|
440
440
|
|
|
441
441
|
// src/lib/devcontainer-merge.ts
|
|
442
442
|
import { parse as parseJsonc2 } from "jsonc-parser";
|
|
@@ -465,6 +465,7 @@ import { fileURLToPath } from "url";
|
|
|
465
465
|
// src/lib/types.ts
|
|
466
466
|
var AGENT_ENV_DIR = ".agent-env";
|
|
467
467
|
var WORKSPACES_DIR = "workspaces";
|
|
468
|
+
var REPOS_DIR = "repos";
|
|
468
469
|
var STATE_FILE = "state.json";
|
|
469
470
|
var STATE_FILE_TMP = "state.json.tmp";
|
|
470
471
|
var CONTAINER_PREFIX = "ae-";
|
|
@@ -1526,6 +1527,79 @@ async function setContainerPurpose(value, deps) {
|
|
|
1526
1527
|
return { ok: true, cleared, warning };
|
|
1527
1528
|
}
|
|
1528
1529
|
|
|
1530
|
+
// src/lib/repo-env.ts
|
|
1531
|
+
import { copyFile as fsCopyFile, readFile as fsReadFile } from "fs/promises";
|
|
1532
|
+
import { homedir as homedir3 } from "os";
|
|
1533
|
+
import { join as join6 } from "path";
|
|
1534
|
+
var defaultDeps2 = {
|
|
1535
|
+
readFile: fsReadFile,
|
|
1536
|
+
copyFile: fsCopyFile,
|
|
1537
|
+
homedir: homedir3
|
|
1538
|
+
};
|
|
1539
|
+
var VALID_SLUG_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
1540
|
+
function validateRepoSlug(slug) {
|
|
1541
|
+
if (!slug || !VALID_SLUG_PATTERN.test(slug)) {
|
|
1542
|
+
throw new Error(
|
|
1543
|
+
`Invalid repo slug: "${slug}". Only alphanumeric, dash, dot, and underscore are allowed (must start with alphanumeric).`
|
|
1544
|
+
);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
function getRepoEnvDir(repoSlug, deps = defaultDeps2) {
|
|
1548
|
+
validateRepoSlug(repoSlug);
|
|
1549
|
+
return join6(deps.homedir(), AGENT_ENV_DIR, REPOS_DIR, repoSlug);
|
|
1550
|
+
}
|
|
1551
|
+
function parseEnvFile(content) {
|
|
1552
|
+
const result = {};
|
|
1553
|
+
for (const rawLine of content.split("\n")) {
|
|
1554
|
+
const line = rawLine.trim();
|
|
1555
|
+
if (!line || line.startsWith("#")) continue;
|
|
1556
|
+
const eqIndex = line.indexOf("=");
|
|
1557
|
+
if (eqIndex === -1) continue;
|
|
1558
|
+
const key = line.slice(0, eqIndex).trim();
|
|
1559
|
+
if (!key) continue;
|
|
1560
|
+
let value = line.slice(eqIndex + 1).trim();
|
|
1561
|
+
if (value.length >= 2 && (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'"))) {
|
|
1562
|
+
value = value.slice(1, -1);
|
|
1563
|
+
}
|
|
1564
|
+
result[key] = value;
|
|
1565
|
+
}
|
|
1566
|
+
return result;
|
|
1567
|
+
}
|
|
1568
|
+
async function loadRepoEnv(repoSlug, deps = defaultDeps2) {
|
|
1569
|
+
const dir = getRepoEnvDir(repoSlug, deps);
|
|
1570
|
+
const result = {};
|
|
1571
|
+
for (const filename of [".env", ".env.local"]) {
|
|
1572
|
+
const filePath = join6(dir, filename);
|
|
1573
|
+
try {
|
|
1574
|
+
const content = await deps.readFile(filePath, "utf-8");
|
|
1575
|
+
Object.assign(result, parseEnvFile(content));
|
|
1576
|
+
} catch (error) {
|
|
1577
|
+
if (error.code !== "ENOENT") {
|
|
1578
|
+
throw error;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
return result;
|
|
1583
|
+
}
|
|
1584
|
+
var ENV_FILES = [".env", ".env.local"];
|
|
1585
|
+
async function copyRepoEnvFiles(repoSlug, destDir, deps = defaultDeps2) {
|
|
1586
|
+
const srcDir = getRepoEnvDir(repoSlug, deps);
|
|
1587
|
+
const copied = [];
|
|
1588
|
+
for (const filename of ENV_FILES) {
|
|
1589
|
+
const src = join6(srcDir, filename);
|
|
1590
|
+
const dest = join6(destDir, filename);
|
|
1591
|
+
try {
|
|
1592
|
+
await deps.copyFile(src, dest);
|
|
1593
|
+
copied.push(filename);
|
|
1594
|
+
} catch (error) {
|
|
1595
|
+
if (error.code !== "ENOENT") {
|
|
1596
|
+
throw error;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
return copied;
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1529
1603
|
// src/lib/create-instance.ts
|
|
1530
1604
|
var VALID_INSTANCE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
1531
1605
|
function validateCreateInputs(instanceName, purposeText) {
|
|
@@ -1611,7 +1685,7 @@ function createDefaultDeps() {
|
|
|
1611
1685
|
return {
|
|
1612
1686
|
executor,
|
|
1613
1687
|
container: createContainerLifecycle(executor),
|
|
1614
|
-
workspaceFsDeps: { mkdir: mkdir5, readdir: readdir4, stat: stat4, homedir:
|
|
1688
|
+
workspaceFsDeps: { mkdir: mkdir5, readdir: readdir4, stat: stat4, homedir: homedir4 },
|
|
1615
1689
|
stateFsDeps: { readFile: readFile7, writeFile: writeFile6, rename: rename4, mkdir: mkdir5, appendFile: appendFile3 },
|
|
1616
1690
|
devcontainerFsDeps: { cp: cp2, mkdir: mkdir5, readFile: readFile7, stat: stat4, writeFile: writeFile6 },
|
|
1617
1691
|
mergeDeps: { readFile: readFile7, writeFile: writeFile6, rename: rename4, access: access3 },
|
|
@@ -1631,13 +1705,14 @@ async function setupMergedConfig(wsPath, containerName, repoName, purposeText, d
|
|
|
1631
1705
|
repoSlug: repoName,
|
|
1632
1706
|
purpose: purposeText
|
|
1633
1707
|
});
|
|
1708
|
+
await copyRepoEnvFiles(repoName, wsPath.root);
|
|
1634
1709
|
const repoConfig = await readRepoConfig(wsPath.root, deps.mergeDeps, deps.logger);
|
|
1635
1710
|
if (repoConfig) {
|
|
1636
1711
|
validateRepoConfig(repoConfig, defaults.image, deps.logger);
|
|
1637
1712
|
}
|
|
1638
1713
|
const merged = mergeDevcontainerConfigs(managed, repoConfig);
|
|
1639
1714
|
await copyManagedAssets(wsPath.root, deps.devcontainerFsDeps);
|
|
1640
|
-
const configPath =
|
|
1715
|
+
const configPath = join7(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
|
|
1641
1716
|
await writeGeneratedConfig(configPath, merged, deps.mergeDeps);
|
|
1642
1717
|
return { ok: true, repoConfigDetected: repoConfig !== void 0 };
|
|
1643
1718
|
} catch (err) {
|
|
@@ -1756,7 +1831,7 @@ async function createInstance(instanceName, repoUrl, deps, options) {
|
|
|
1756
1831
|
}
|
|
1757
1832
|
};
|
|
1758
1833
|
}
|
|
1759
|
-
const configPath =
|
|
1834
|
+
const configPath = join7(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
|
|
1760
1835
|
const containerResult = await deps.container.devcontainerUp(wsPath.root, containerName, {
|
|
1761
1836
|
remoteEnv: {
|
|
1762
1837
|
AGENT_INSTANCE: wsPath.name,
|
|
@@ -1853,7 +1928,7 @@ function createAttachDefaultDeps() {
|
|
|
1853
1928
|
return {
|
|
1854
1929
|
executor,
|
|
1855
1930
|
container: createContainerLifecycle(executor),
|
|
1856
|
-
workspaceFsDeps: { mkdir: mkdir6, readdir: readdir5, stat: stat5, homedir:
|
|
1931
|
+
workspaceFsDeps: { mkdir: mkdir6, readdir: readdir5, stat: stat5, homedir: homedir5 },
|
|
1857
1932
|
stateFsDeps: { readFile: readFile8, writeFile: writeFile7, rename: rename5, mkdir: mkdir6, appendFile: appendFile4 }
|
|
1858
1933
|
};
|
|
1859
1934
|
}
|
|
@@ -1891,7 +1966,7 @@ async function attachInstance(instanceName, deps, onContainerStarting, onAttachi
|
|
|
1891
1966
|
}
|
|
1892
1967
|
if (statusResult.status === "stopped" || statusResult.status === "not-found") {
|
|
1893
1968
|
onContainerStarting?.();
|
|
1894
|
-
const configPath =
|
|
1969
|
+
const configPath = join8(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
|
|
1895
1970
|
const startResult = await deps.container.devcontainerUp(wsPath.root, containerName, {
|
|
1896
1971
|
remoteEnv: { AGENT_INSTANCE: wsPath.name },
|
|
1897
1972
|
configPath,
|
|
@@ -1996,22 +2071,22 @@ import {
|
|
|
1996
2071
|
unlink,
|
|
1997
2072
|
writeFile as writeFile8
|
|
1998
2073
|
} from "fs/promises";
|
|
1999
|
-
import { homedir as
|
|
2000
|
-
import { join as
|
|
2074
|
+
import { homedir as homedir6 } from "os";
|
|
2075
|
+
import { join as join9 } from "path";
|
|
2001
2076
|
function createCodeDefaultDeps() {
|
|
2002
2077
|
const executor = createExecutor();
|
|
2003
2078
|
return {
|
|
2004
2079
|
executor,
|
|
2005
2080
|
container: createContainerLifecycle(executor),
|
|
2006
|
-
workspaceFsDeps: { mkdir: mkdir7, readdir: readdir6, stat: stat6, homedir:
|
|
2081
|
+
workspaceFsDeps: { mkdir: mkdir7, readdir: readdir6, stat: stat6, homedir: homedir6 },
|
|
2007
2082
|
stateFsDeps: { readFile: readFile9, writeFile: writeFile8, rename: rename6, mkdir: mkdir7, appendFile: appendFile5 },
|
|
2008
2083
|
codeFsDeps: { lstat: lstat2, symlink, readlink: readlink2, unlink }
|
|
2009
2084
|
};
|
|
2010
2085
|
}
|
|
2011
2086
|
var DEVCONTAINER_OPEN_TIMEOUT = 3e4;
|
|
2012
2087
|
async function ensureConfigSymlink(wsRoot, deps) {
|
|
2013
|
-
const symlinkPath =
|
|
2014
|
-
const target =
|
|
2088
|
+
const symlinkPath = join9(wsRoot, ".devcontainer.json");
|
|
2089
|
+
const target = join9(AGENT_ENV_DIR, "devcontainer.json");
|
|
2015
2090
|
try {
|
|
2016
2091
|
const linkStat = await deps.lstat(symlinkPath);
|
|
2017
2092
|
if (linkStat.isSymbolicLink()) {
|
|
@@ -2027,7 +2102,7 @@ async function ensureConfigSymlink(wsRoot, deps) {
|
|
|
2027
2102
|
await deps.symlink(target, symlinkPath);
|
|
2028
2103
|
}
|
|
2029
2104
|
async function removeConfigSymlink(wsRoot, deps) {
|
|
2030
|
-
const symlinkPath =
|
|
2105
|
+
const symlinkPath = join9(wsRoot, ".devcontainer.json");
|
|
2031
2106
|
try {
|
|
2032
2107
|
const linkStat = await deps.lstat(symlinkPath);
|
|
2033
2108
|
if (!linkStat.isSymbolicLink()) return;
|
|
@@ -2067,7 +2142,7 @@ async function codeInstance(instanceName, deps, onContainerStarting, onOpening,
|
|
|
2067
2142
|
}
|
|
2068
2143
|
};
|
|
2069
2144
|
}
|
|
2070
|
-
const configPath =
|
|
2145
|
+
const configPath = join9(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
|
|
2071
2146
|
if (statusResult.status === "stopped" || statusResult.status === "not-found") {
|
|
2072
2147
|
onContainerStarting?.();
|
|
2073
2148
|
const startResult = await deps.container.devcontainerUp(wsPath.root, containerName, {
|
|
@@ -2660,8 +2735,50 @@ var createCommand = new Command4("create").description("Create a new isolated de
|
|
|
2660
2735
|
}
|
|
2661
2736
|
});
|
|
2662
2737
|
|
|
2663
|
-
// src/commands/
|
|
2738
|
+
// src/commands/env.ts
|
|
2664
2739
|
import { Command as Command5 } from "commander";
|
|
2740
|
+
import { spawnSync } from "child_process";
|
|
2741
|
+
import { existsSync, mkdirSync } from "fs";
|
|
2742
|
+
var envCommand = new Command5("env").description("Manage repo-level env files copied into workspaces").argument("<repo-slug>", "Repo slug (from `agent-env repos`)").option("--edit", "Open .env in $EDITOR").option("--edit-local", "Open .env.local in $EDITOR").option("--path", "Print path to repo env directory").action(
|
|
2743
|
+
async (repoSlug, options) => {
|
|
2744
|
+
const dir = getRepoEnvDir(repoSlug);
|
|
2745
|
+
if (options.path) {
|
|
2746
|
+
console.log(dir);
|
|
2747
|
+
return;
|
|
2748
|
+
}
|
|
2749
|
+
if (options.edit || options.editLocal) {
|
|
2750
|
+
const editor = process.env.EDITOR || process.env.VISUAL || "vi";
|
|
2751
|
+
const filename = options.editLocal ? ".env.local" : ".env";
|
|
2752
|
+
const filePath = `${dir}/${filename}`;
|
|
2753
|
+
if (!existsSync(dir)) {
|
|
2754
|
+
mkdirSync(dir, { recursive: true });
|
|
2755
|
+
}
|
|
2756
|
+
const result = spawnSync(editor, [filePath], { stdio: "inherit" });
|
|
2757
|
+
if (result.status !== 0) {
|
|
2758
|
+
console.error(
|
|
2759
|
+
formatError(createError("EDITOR_ERROR", `Failed to open ${filename} in ${editor}.`))
|
|
2760
|
+
);
|
|
2761
|
+
process.exitCode = 1;
|
|
2762
|
+
}
|
|
2763
|
+
return;
|
|
2764
|
+
}
|
|
2765
|
+
const env = await loadRepoEnv(repoSlug);
|
|
2766
|
+
const keys = Object.keys(env);
|
|
2767
|
+
if (keys.length === 0) {
|
|
2768
|
+
console.log(`No env files found for repo "${repoSlug}".`);
|
|
2769
|
+
console.log(`Create one at: ${dir}/.env`);
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2772
|
+
console.log(`Repo env vars for "${repoSlug}" (${dir}):
|
|
2773
|
+
`);
|
|
2774
|
+
for (const [key, value] of Object.entries(env)) {
|
|
2775
|
+
console.log(` ${key}=${value}`);
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
);
|
|
2779
|
+
|
|
2780
|
+
// src/commands/list.ts
|
|
2781
|
+
import { Command as Command6 } from "commander";
|
|
2665
2782
|
import { render } from "ink";
|
|
2666
2783
|
import React from "react";
|
|
2667
2784
|
|
|
@@ -3033,7 +3150,7 @@ async function listInstances(deps, opts) {
|
|
|
3033
3150
|
}
|
|
3034
3151
|
|
|
3035
3152
|
// src/commands/list.ts
|
|
3036
|
-
var listCommand = new
|
|
3153
|
+
var listCommand = new Command6("list").alias("ps").description("List all instances with status").option("--json", "Output in JSON format").option("--repo <slug>", "Filter instances by repo slug").action(async (options) => {
|
|
3037
3154
|
const result = await listInstances(void 0, {
|
|
3038
3155
|
repoFilter: options.repo
|
|
3039
3156
|
});
|
|
@@ -3085,7 +3202,7 @@ var listCommand = new Command5("list").alias("ps").description("List all instanc
|
|
|
3085
3202
|
});
|
|
3086
3203
|
|
|
3087
3204
|
// src/commands/on.ts
|
|
3088
|
-
import { Command as
|
|
3205
|
+
import { Command as Command7 } from "commander";
|
|
3089
3206
|
|
|
3090
3207
|
// src/lib/interactive-menu.ts
|
|
3091
3208
|
async function launchActionLoop(workspaceName, deps, repoSlug) {
|
|
@@ -3247,8 +3364,8 @@ import {
|
|
|
3247
3364
|
writeFile as writeFile9,
|
|
3248
3365
|
appendFile as appendFile6
|
|
3249
3366
|
} from "fs/promises";
|
|
3250
|
-
import { homedir as
|
|
3251
|
-
import { join as
|
|
3367
|
+
import { homedir as homedir7 } from "os";
|
|
3368
|
+
import { join as join10 } from "path";
|
|
3252
3369
|
|
|
3253
3370
|
// src/lib/tmux-utils.ts
|
|
3254
3371
|
async function saveTmuxState(containerName, deps) {
|
|
@@ -3277,7 +3394,7 @@ function createRebuildDefaultDeps() {
|
|
|
3277
3394
|
return {
|
|
3278
3395
|
executor,
|
|
3279
3396
|
container: createContainerLifecycle(executor),
|
|
3280
|
-
workspaceFsDeps: { mkdir: mkdir8, readdir: readdir7, stat: stat7, homedir:
|
|
3397
|
+
workspaceFsDeps: { mkdir: mkdir8, readdir: readdir7, stat: stat7, homedir: homedir7 },
|
|
3281
3398
|
stateFsDeps: { readFile: readFile10, writeFile: writeFile9, rename: rename7, mkdir: mkdir8, appendFile: appendFile6 },
|
|
3282
3399
|
devcontainerFsDeps: { cp: cp3, mkdir: mkdir8, readdir: readdir7, readFile: readFile10, stat: stat7, writeFile: writeFile9 },
|
|
3283
3400
|
mergeDeps: { readFile: readFile10, writeFile: writeFile9, rename: rename7, access: access4 },
|
|
@@ -3295,6 +3412,7 @@ async function refreshMergedConfig(wsRoot, containerName, wsName, repoSlug, purp
|
|
|
3295
3412
|
repoSlug,
|
|
3296
3413
|
purpose
|
|
3297
3414
|
});
|
|
3415
|
+
await copyRepoEnvFiles(repoSlug, wsRoot);
|
|
3298
3416
|
const repoConfig = await readRepoConfig(wsRoot, deps.mergeDeps, deps.logger);
|
|
3299
3417
|
if (repoConfigExpected && !repoConfig) {
|
|
3300
3418
|
return {
|
|
@@ -3311,7 +3429,7 @@ async function refreshMergedConfig(wsRoot, containerName, wsName, repoSlug, purp
|
|
|
3311
3429
|
}
|
|
3312
3430
|
const merged = mergeDevcontainerConfigs(managed, repoConfig);
|
|
3313
3431
|
await copyManagedAssets(wsRoot, deps.devcontainerFsDeps);
|
|
3314
|
-
const configPath =
|
|
3432
|
+
const configPath = join10(wsRoot, AGENT_ENV_DIR, "devcontainer.json");
|
|
3315
3433
|
await writeGeneratedConfig(configPath, merged, deps.mergeDeps);
|
|
3316
3434
|
return { ok: true, repoConfigDetected: repoConfig !== void 0 };
|
|
3317
3435
|
} catch (err) {
|
|
@@ -3411,7 +3529,7 @@ async function teardownContainer(containerName, container, statusResult) {
|
|
|
3411
3529
|
return { ok: true };
|
|
3412
3530
|
}
|
|
3413
3531
|
async function startAndDiscoverContainer(wsPath, containerName, purpose, buildNoCache, container, onProgress) {
|
|
3414
|
-
const configPath =
|
|
3532
|
+
const configPath = join10(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
|
|
3415
3533
|
const containerResult = await container.devcontainerUp(wsPath.root, containerName, {
|
|
3416
3534
|
buildNoCache,
|
|
3417
3535
|
remoteEnv: { AGENT_INSTANCE: wsPath.name, AGENT_ENV_PURPOSE: purpose },
|
|
@@ -3515,13 +3633,13 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
|
|
|
3515
3633
|
|
|
3516
3634
|
// src/lib/shutdown-instance.ts
|
|
3517
3635
|
import { appendFile as appendFile7, mkdir as mkdir9, readdir as readdir8, readFile as readFile11, rename as rename8, stat as stat8, writeFile as writeFile10 } from "fs/promises";
|
|
3518
|
-
import { homedir as
|
|
3636
|
+
import { homedir as homedir8 } from "os";
|
|
3519
3637
|
function createShutdownDefaultDeps() {
|
|
3520
3638
|
const executor = createExecutor();
|
|
3521
3639
|
return {
|
|
3522
3640
|
executor,
|
|
3523
3641
|
container: createContainerLifecycle(executor),
|
|
3524
|
-
workspaceFsDeps: { mkdir: mkdir9, readdir: readdir8, stat: stat8, homedir:
|
|
3642
|
+
workspaceFsDeps: { mkdir: mkdir9, readdir: readdir8, stat: stat8, homedir: homedir8 },
|
|
3525
3643
|
stateFsDeps: { readFile: readFile11, writeFile: writeFile10, rename: rename8, mkdir: mkdir9, appendFile: appendFile7 },
|
|
3526
3644
|
logger: { warn: (msg) => console.warn(msg), info: (msg) => console.info(msg) }
|
|
3527
3645
|
};
|
|
@@ -3650,7 +3768,7 @@ function buildMenuDeps() {
|
|
|
3650
3768
|
}
|
|
3651
3769
|
|
|
3652
3770
|
// src/commands/on.ts
|
|
3653
|
-
var onCommand = new
|
|
3771
|
+
var onCommand = new Command7("on").description("Open the interactive menu for an instance").argument("<name>", "Instance name").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
|
|
3654
3772
|
if (!process.stdin.isTTY) {
|
|
3655
3773
|
console.error(
|
|
3656
3774
|
formatError(
|
|
@@ -3678,8 +3796,8 @@ var onCommand = new Command6("on").description("Open the interactive menu for an
|
|
|
3678
3796
|
});
|
|
3679
3797
|
|
|
3680
3798
|
// src/commands/path.ts
|
|
3681
|
-
import { Command as
|
|
3682
|
-
var pathCommand = new
|
|
3799
|
+
import { Command as Command8 } from "commander";
|
|
3800
|
+
var pathCommand = new Command8("path").description("Print the host directory path for an instance").argument("<name>", "Instance name").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
|
|
3683
3801
|
const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
|
|
3684
3802
|
const result = await resolveInstance(name, repoSlug);
|
|
3685
3803
|
if (!result.found) {
|
|
@@ -3693,12 +3811,12 @@ var pathCommand = new Command7("path").description("Print the host directory pat
|
|
|
3693
3811
|
});
|
|
3694
3812
|
|
|
3695
3813
|
// src/commands/purpose.ts
|
|
3696
|
-
import { Command as
|
|
3814
|
+
import { Command as Command9 } from "commander";
|
|
3697
3815
|
var defaultPurposeCommandDeps = {
|
|
3698
3816
|
isInsideContainer
|
|
3699
3817
|
};
|
|
3700
3818
|
function createPurposeCommand(deps = defaultPurposeCommandDeps) {
|
|
3701
|
-
return new
|
|
3819
|
+
return new Command9("purpose").description(
|
|
3702
3820
|
"Get or set the purpose/label for an instance. Inside a container: no instance name needed (agent-env purpose [value])"
|
|
3703
3821
|
).argument("[nameOrValue]", "Instance name (host) or purpose value (container)").argument("[value]", "New purpose value (omit to get current, empty string to clear)").option("--repo <slug>", "Repo slug or URL to scope instance lookup (host mode only)").action(async (nameOrValue, value, options) => {
|
|
3704
3822
|
if (deps.isInsideContainer()) {
|
|
@@ -3773,8 +3891,8 @@ function handleSetResult(result) {
|
|
|
3773
3891
|
|
|
3774
3892
|
// src/commands/rebuild.ts
|
|
3775
3893
|
import chalk from "chalk";
|
|
3776
|
-
import { Command as
|
|
3777
|
-
var rebuildCommand = new
|
|
3894
|
+
import { Command as Command10 } from "commander";
|
|
3895
|
+
var rebuildCommand = new Command10("rebuild").description("Rebuild an instance by recreating its container").argument("<name>", "Instance name to rebuild").option("--force", "Rebuild even if the container is currently running").option("--yes", "Skip confirmation prompt").option("--no-pull", "Skip pulling fresh base images").option("--use-cache", "Allow Docker build layer cache reuse").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(
|
|
3778
3896
|
async (name, options) => {
|
|
3779
3897
|
const deps = createRebuildDefaultDeps();
|
|
3780
3898
|
const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
|
|
@@ -3831,22 +3949,22 @@ Any active sessions will be lost. Continue? (y/N) `
|
|
|
3831
3949
|
|
|
3832
3950
|
// src/commands/remove.ts
|
|
3833
3951
|
import chalk3 from "chalk";
|
|
3834
|
-
import { Command as
|
|
3952
|
+
import { Command as Command11 } from "commander";
|
|
3835
3953
|
import { createInterface as createInterface2 } from "readline";
|
|
3836
3954
|
|
|
3837
3955
|
// src/lib/audit-log.ts
|
|
3838
3956
|
import { appendFile as appendFile8, mkdir as mkdir10 } from "fs/promises";
|
|
3839
|
-
import { homedir as
|
|
3840
|
-
import { join as
|
|
3957
|
+
import { homedir as homedir9 } from "os";
|
|
3958
|
+
import { join as join11 } from "path";
|
|
3841
3959
|
function createAuditLogDefaultDeps() {
|
|
3842
|
-
return { appendFile: appendFile8, mkdir: mkdir10, homedir:
|
|
3960
|
+
return { appendFile: appendFile8, mkdir: mkdir10, homedir: homedir9 };
|
|
3843
3961
|
}
|
|
3844
3962
|
function getAuditLogPath(deps) {
|
|
3845
|
-
return
|
|
3963
|
+
return join11(deps.homedir(), AGENT_ENV_DIR, "audit.log");
|
|
3846
3964
|
}
|
|
3847
3965
|
async function writeAuditLogEntry(entry, deps = createAuditLogDefaultDeps()) {
|
|
3848
3966
|
const logPath = getAuditLogPath(deps);
|
|
3849
|
-
await deps.mkdir(
|
|
3967
|
+
await deps.mkdir(join11(deps.homedir(), AGENT_ENV_DIR), { recursive: true });
|
|
3850
3968
|
const line = JSON.stringify(entry) + "\n";
|
|
3851
3969
|
await deps.appendFile(logPath, line, "utf-8");
|
|
3852
3970
|
}
|
|
@@ -3862,14 +3980,14 @@ function createAuditEntry(instanceName, gitState, confirmationMethod) {
|
|
|
3862
3980
|
|
|
3863
3981
|
// src/lib/remove-instance.ts
|
|
3864
3982
|
import { mkdir as mkdir11, readdir as readdir9, readFile as readFile12, rm as rm4, stat as stat9 } from "fs/promises";
|
|
3865
|
-
import { homedir as
|
|
3983
|
+
import { homedir as homedir10 } from "os";
|
|
3866
3984
|
function createRemoveDefaultDeps() {
|
|
3867
3985
|
const executor = createExecutor();
|
|
3868
3986
|
return {
|
|
3869
3987
|
executor,
|
|
3870
3988
|
container: createContainerLifecycle(executor),
|
|
3871
3989
|
gitDetector: createGitStateDetector(executor),
|
|
3872
|
-
workspaceFsDeps: { mkdir: mkdir11, readdir: readdir9, stat: stat9, homedir:
|
|
3990
|
+
workspaceFsDeps: { mkdir: mkdir11, readdir: readdir9, stat: stat9, homedir: homedir10 },
|
|
3873
3991
|
stateFsDeps: { readFile: readFile12 },
|
|
3874
3992
|
deleteFsDeps: { rm: rm4 }
|
|
3875
3993
|
};
|
|
@@ -4150,7 +4268,7 @@ async function resolveConfirmation(name, options) {
|
|
|
4150
4268
|
}
|
|
4151
4269
|
return "typed-name";
|
|
4152
4270
|
}
|
|
4153
|
-
var removeCommand = new
|
|
4271
|
+
var removeCommand = new Command11("remove").description("Remove an instance with safety checks").argument("<name>", "Instance name to remove").option("--repo <slug>", "Repo slug or URL to scope instance lookup").option("--force", "Force removal, bypassing safety checks").option(
|
|
4154
4272
|
"--yes",
|
|
4155
4273
|
"Skip confirmation prompt for --force (DANGEROUS: skips all safety prompts, for scripts only)"
|
|
4156
4274
|
).action(async (name, options) => {
|
|
@@ -4213,8 +4331,8 @@ var removeCommand = new Command10("remove").description("Remove an instance with
|
|
|
4213
4331
|
});
|
|
4214
4332
|
|
|
4215
4333
|
// src/commands/repos.ts
|
|
4216
|
-
import { Command as
|
|
4217
|
-
var reposCommand = new
|
|
4334
|
+
import { Command as Command12 } from "commander";
|
|
4335
|
+
var reposCommand = new Command12("repos").description("List tracked repositories").option("--json", "Output in JSON format").action(async (options) => {
|
|
4218
4336
|
const result = await listRepos();
|
|
4219
4337
|
if (!result.ok) {
|
|
4220
4338
|
const error = createError(
|
|
@@ -4265,9 +4383,9 @@ var reposCommand = new Command11("repos").description("List tracked repositories
|
|
|
4265
4383
|
});
|
|
4266
4384
|
|
|
4267
4385
|
// src/commands/setup-audio.ts
|
|
4268
|
-
import { Command as
|
|
4386
|
+
import { Command as Command13 } from "commander";
|
|
4269
4387
|
import { copyFile, mkdir as mkdir12, readFile as readFile13, writeFile as writeFile11, access as access5 } from "fs/promises";
|
|
4270
|
-
import { homedir as
|
|
4388
|
+
import { homedir as homedir11, platform } from "os";
|
|
4271
4389
|
|
|
4272
4390
|
// src/lib/setup-audio.ts
|
|
4273
4391
|
async function setupAudio(deps) {
|
|
@@ -4362,7 +4480,7 @@ function createDefaultSetupAudioDeps() {
|
|
|
4362
4480
|
const exec = createExecutor();
|
|
4363
4481
|
return {
|
|
4364
4482
|
platform: platform(),
|
|
4365
|
-
homeDir:
|
|
4483
|
+
homeDir: homedir11(),
|
|
4366
4484
|
execute: exec,
|
|
4367
4485
|
readFile: (path, encoding) => readFile13(path, encoding),
|
|
4368
4486
|
writeFile: (path, content, encoding) => writeFile11(path, content, encoding),
|
|
@@ -4371,7 +4489,7 @@ function createDefaultSetupAudioDeps() {
|
|
|
4371
4489
|
access: (path) => access5(path)
|
|
4372
4490
|
};
|
|
4373
4491
|
}
|
|
4374
|
-
var setupAudioCommand = new
|
|
4492
|
+
var setupAudioCommand = new Command13("setup-audio").description("Configure macOS PulseAudio for audio passthrough to containers").action(async () => {
|
|
4375
4493
|
const deps = createDefaultSetupAudioDeps();
|
|
4376
4494
|
const result = await setupAudio(deps);
|
|
4377
4495
|
if (!result.ok) {
|
|
@@ -4392,8 +4510,8 @@ var setupAudioCommand = new Command12("setup-audio").description("Configure macO
|
|
|
4392
4510
|
|
|
4393
4511
|
// src/commands/shutdown.ts
|
|
4394
4512
|
import chalk4 from "chalk";
|
|
4395
|
-
import { Command as
|
|
4396
|
-
var shutdownCommand = new
|
|
4513
|
+
import { Command as Command14 } from "commander";
|
|
4514
|
+
var shutdownCommand = new Command14("shutdown").description("Gracefully shut down an instance (save tmux state, stop container)").argument("<name>", "Instance name to shut down").option("--yes", "Skip confirmation prompt").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
|
|
4397
4515
|
const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
|
|
4398
4516
|
if (!options.yes && process.stdin.isTTY) {
|
|
4399
4517
|
const confirmed = await promptForConfirmation(
|
|
@@ -4427,13 +4545,13 @@ Shutdown '${name}'? This will stop the container. (y/N) `
|
|
|
4427
4545
|
});
|
|
4428
4546
|
|
|
4429
4547
|
// src/commands/tmux-restore.ts
|
|
4430
|
-
import { Command as
|
|
4548
|
+
import { Command as Command15 } from "commander";
|
|
4431
4549
|
import { execSync } from "child_process";
|
|
4432
|
-
import { join as
|
|
4550
|
+
import { join as join13 } from "path";
|
|
4433
4551
|
|
|
4434
4552
|
// src/lib/tmux-session.ts
|
|
4435
4553
|
import { readFile as readFile14, writeFile as writeFile12, rename as rename9, mkdir as mkdir13 } from "fs/promises";
|
|
4436
|
-
import { dirname as dirname3, join as
|
|
4554
|
+
import { dirname as dirname3, join as join12 } from "path";
|
|
4437
4555
|
async function readPanesState(path) {
|
|
4438
4556
|
try {
|
|
4439
4557
|
const content = await readFile14(path, "utf-8");
|
|
@@ -4484,7 +4602,7 @@ function pruneStaleEntries(state, activePaneIds) {
|
|
|
4484
4602
|
function resolveTmuxStateDir(agentInstance) {
|
|
4485
4603
|
const instance = agentInstance || process.env.AGENT_INSTANCE;
|
|
4486
4604
|
if (!instance) return null;
|
|
4487
|
-
return
|
|
4605
|
+
return join12("/shared-data/instance", instance, "tmux");
|
|
4488
4606
|
}
|
|
4489
4607
|
|
|
4490
4608
|
// src/commands/tmux-restore.ts
|
|
@@ -4520,7 +4638,7 @@ function ensureTmuxSession(savedName) {
|
|
|
4520
4638
|
async function executeTmuxRestore() {
|
|
4521
4639
|
const stateDir = resolveTmuxStateDir();
|
|
4522
4640
|
if (!stateDir) return;
|
|
4523
|
-
const sessionState = await readSessionState(
|
|
4641
|
+
const sessionState = await readSessionState(join13(stateDir, "session.json"));
|
|
4524
4642
|
if (!sessionState) return;
|
|
4525
4643
|
const sessionName = ensureTmuxSession(sessionState.tmux_session);
|
|
4526
4644
|
const quotedSession = shellQuote(sessionName);
|
|
@@ -4547,7 +4665,7 @@ async function executeTmuxRestore() {
|
|
|
4547
4665
|
}
|
|
4548
4666
|
}
|
|
4549
4667
|
}
|
|
4550
|
-
var tmuxRestoreCommand = new
|
|
4668
|
+
var tmuxRestoreCommand = new Command15("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
|
|
4551
4669
|
try {
|
|
4552
4670
|
await executeTmuxRestore();
|
|
4553
4671
|
} catch {
|
|
@@ -4555,14 +4673,14 @@ var tmuxRestoreCommand = new Command14("tmux-restore").description("Restore tmux
|
|
|
4555
4673
|
});
|
|
4556
4674
|
|
|
4557
4675
|
// src/commands/tmux-save.ts
|
|
4558
|
-
import { Command as
|
|
4676
|
+
import { Command as Command16 } from "commander";
|
|
4559
4677
|
import { execSync as execSync2 } from "child_process";
|
|
4560
4678
|
import { unlink as unlink2 } from "fs/promises";
|
|
4561
|
-
import { join as
|
|
4679
|
+
import { join as join14 } from "path";
|
|
4562
4680
|
async function executeTmuxSave() {
|
|
4563
4681
|
const stateDir = resolveTmuxStateDir();
|
|
4564
4682
|
if (!stateDir) return;
|
|
4565
|
-
const sessionPath =
|
|
4683
|
+
const sessionPath = join14(stateDir, "session.json");
|
|
4566
4684
|
let tmuxOutput;
|
|
4567
4685
|
try {
|
|
4568
4686
|
tmuxOutput = execSync2(
|
|
@@ -4590,7 +4708,7 @@ async function executeTmuxSave() {
|
|
|
4590
4708
|
});
|
|
4591
4709
|
return;
|
|
4592
4710
|
}
|
|
4593
|
-
const panesPath =
|
|
4711
|
+
const panesPath = join14(stateDir, "claude-sessions.json");
|
|
4594
4712
|
const panesState = await readPanesState(panesPath);
|
|
4595
4713
|
let activeWindow = 1;
|
|
4596
4714
|
try {
|
|
@@ -4633,7 +4751,7 @@ async function executeTmuxSave() {
|
|
|
4633
4751
|
const pruned = pruneStaleEntries(panesState, activePaneIds);
|
|
4634
4752
|
await writePanesState(panesPath, pruned);
|
|
4635
4753
|
}
|
|
4636
|
-
var tmuxSaveCommand = new
|
|
4754
|
+
var tmuxSaveCommand = new Command16("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
|
|
4637
4755
|
try {
|
|
4638
4756
|
await executeTmuxSave();
|
|
4639
4757
|
} catch {
|
|
@@ -4641,12 +4759,12 @@ var tmuxSaveCommand = new Command15("tmux-save").description("Save current tmux
|
|
|
4641
4759
|
});
|
|
4642
4760
|
|
|
4643
4761
|
// src/commands/tmux-status.ts
|
|
4644
|
-
import { Command as
|
|
4762
|
+
import { Command as Command17 } from "commander";
|
|
4645
4763
|
|
|
4646
4764
|
// src/lib/tmux-status.ts
|
|
4647
4765
|
import { readFile as readFile15 } from "fs/promises";
|
|
4648
4766
|
var MAX_PURPOSE_DISPLAY_LEN = 40;
|
|
4649
|
-
var
|
|
4767
|
+
var defaultDeps3 = { readFile: readFile15 };
|
|
4650
4768
|
function formatTmuxStatus(instance, purpose) {
|
|
4651
4769
|
if (!instance) return "?";
|
|
4652
4770
|
if (!purpose) return instance;
|
|
@@ -4655,7 +4773,7 @@ function formatTmuxStatus(instance, purpose) {
|
|
|
4655
4773
|
}
|
|
4656
4774
|
return `${instance} | ${purpose}`;
|
|
4657
4775
|
}
|
|
4658
|
-
async function getTmuxStatus(statePath, deps =
|
|
4776
|
+
async function getTmuxStatus(statePath, deps = defaultDeps3) {
|
|
4659
4777
|
let content;
|
|
4660
4778
|
try {
|
|
4661
4779
|
content = await deps.readFile(statePath, "utf-8");
|
|
@@ -4676,13 +4794,13 @@ async function getTmuxStatus(statePath, deps = defaultDeps2) {
|
|
|
4676
4794
|
}
|
|
4677
4795
|
|
|
4678
4796
|
// src/commands/tmux-status.ts
|
|
4679
|
-
var
|
|
4797
|
+
var defaultDeps4 = {
|
|
4680
4798
|
isInsideContainer,
|
|
4681
4799
|
getTmuxStatus,
|
|
4682
4800
|
statePath: CONTAINER_STATE_PATH
|
|
4683
4801
|
};
|
|
4684
|
-
function createTmuxStatusCommand(deps =
|
|
4685
|
-
return new
|
|
4802
|
+
function createTmuxStatusCommand(deps = defaultDeps4) {
|
|
4803
|
+
return new Command17("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
|
|
4686
4804
|
if (!deps.isInsideContainer()) {
|
|
4687
4805
|
console.log("?");
|
|
4688
4806
|
return;
|
|
@@ -4790,11 +4908,12 @@ async function checkForUpdate(opts) {
|
|
|
4790
4908
|
|
|
4791
4909
|
// src/cli.ts
|
|
4792
4910
|
var __dirname = dirname5(fileURLToPath2(import.meta.url));
|
|
4793
|
-
var isLinked =
|
|
4911
|
+
var isLinked = existsSync2(resolve(__dirname, "..", "..", "..", "pnpm-workspace.yaml"));
|
|
4794
4912
|
var isBakedDev = resolve(__dirname, "..").startsWith("/opt/agent-env-dev");
|
|
4795
4913
|
var version = package_default.version + (isLinked ? "+local" : isBakedDev ? "+dev" : "");
|
|
4796
4914
|
program.name("agent-env").description("CLI for creating isolated, AI-ready development environments").version(version).allowExcessArguments(true);
|
|
4797
4915
|
program.addCommand(createCommand);
|
|
4916
|
+
program.addCommand(envCommand);
|
|
4798
4917
|
program.addCommand(listCommand);
|
|
4799
4918
|
program.addCommand(attachCommand);
|
|
4800
4919
|
program.addCommand(pathCommand);
|
|
@@ -4868,7 +4987,7 @@ var shouldCheck = !!process.stderr.isTTY && !isInsideContainer() && !isLinked &&
|
|
|
4868
4987
|
var updateCheckPromise = shouldCheck ? checkForUpdate({
|
|
4869
4988
|
currentVersion: package_default.version,
|
|
4870
4989
|
packageName: package_default.name,
|
|
4871
|
-
cachePath:
|
|
4990
|
+
cachePath: join15(homedir12(), ".agent-env", "update-check.json"),
|
|
4872
4991
|
cacheTtlMs: 36e5
|
|
4873
4992
|
}) : Promise.resolve(null);
|
|
4874
4993
|
async function main() {
|