@zookanalytics/agent-env 1.1.1 → 1.2.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/config/baseline/devcontainer.json +4 -1
- package/dist/cli.js +204 -66
- package/package.json +1 -1
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
2
|
+
// This value is replaced at runtime by agent-env (see getManagedImage() in
|
|
3
|
+
// packages/agent-env/src/lib/devcontainer.ts). To change the image source,
|
|
4
|
+
// edit MANAGED_IMAGE_REPO in that file.
|
|
5
|
+
"image": "MANAGED_BY_AGENT_ENV_DO_NOT_EDIT",
|
|
3
6
|
"initializeCommand": "bash .agent-env/init-host.sh",
|
|
4
7
|
"mounts": [
|
|
5
8
|
"source=${localWorkspaceFolder}/.agent-env,target=/etc/agent-env,type=bind"
|
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.2.0",
|
|
61
61
|
description: "CLI for creating isolated, AI-ready development environments",
|
|
62
62
|
type: "module",
|
|
63
63
|
bin: {
|
|
@@ -125,7 +125,7 @@ import { join as join8 } from "path";
|
|
|
125
125
|
// src/lib/container.ts
|
|
126
126
|
var DEVCONTAINER_UP_TIMEOUT = 3e5;
|
|
127
127
|
var DEVCONTAINER_UP_NO_CACHE_TIMEOUT = 3e5;
|
|
128
|
-
var DOCKER_PULL_TIMEOUT =
|
|
128
|
+
var DOCKER_PULL_TIMEOUT = 9e5;
|
|
129
129
|
var DOCKER_INSPECT_TIMEOUT = 1e4;
|
|
130
130
|
var DOCKER_INFO_TIMEOUT = 5e3;
|
|
131
131
|
var DOCKER_STOP_TIMEOUT = 3e4;
|
|
@@ -423,12 +423,28 @@ function createContainerLifecycle(executor = createExecutor()) {
|
|
|
423
423
|
if (result.ok) {
|
|
424
424
|
return { ok: true };
|
|
425
425
|
}
|
|
426
|
+
const stderr = result.stderr ?? "";
|
|
427
|
+
const stderrLower = stderr.toLowerCase();
|
|
428
|
+
const isManifestUnknown = stderrLower.includes("manifest unknown") || stderrLower.includes("manifest for") && stderrLower.includes("not found");
|
|
429
|
+
if (isManifestUnknown) {
|
|
430
|
+
return {
|
|
431
|
+
ok: false,
|
|
432
|
+
error: {
|
|
433
|
+
code: "IMAGE_VERSION_NOT_PUBLISHED",
|
|
434
|
+
message: `Image '${image}' is not available in the registry: ${stderr.trim()}`,
|
|
435
|
+
suggestion: `The container image for this agent-env version may not be published yet. Image publishes complete shortly after each release; check workflow status to estimate readiness.
|
|
436
|
+
\u2022 Workflow runs: https://github.com/ZookAnalytics/bmad-orchestrator/actions/workflows/publish-image.yml
|
|
437
|
+
\u2022 Available tags: https://github.com/ZookAnalytics/bmad-orchestrator/pkgs/container/bmad-orchestrator%2Fdevcontainer
|
|
438
|
+
\u2022 Emergency unblock (ONLY if you already have a previously cached image): retry with --no-pull. The container will start with the locally cached image, which may not match agent-env's current version. If no image is cached, you must wait for the registry tag to publish.`
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
426
442
|
return {
|
|
427
443
|
ok: false,
|
|
428
444
|
error: {
|
|
429
445
|
code: "IMAGE_PULL_FAILED",
|
|
430
|
-
message: `Failed to pull '${image}': ${
|
|
431
|
-
suggestion: "Check network connectivity and image name. Use --no-pull
|
|
446
|
+
message: `Failed to pull '${image}': ${stderr}`,
|
|
447
|
+
suggestion: "Check network connectivity and image name. Use --no-pull ONLY if you already have a previously cached image \u2014 the container will start with whatever is cached locally and may not match the current agent-env version."
|
|
432
448
|
}
|
|
433
449
|
};
|
|
434
450
|
}
|
|
@@ -465,7 +481,6 @@ import { dirname as dirname2, join as join7 } from "path";
|
|
|
465
481
|
import { parse as parseJsonc2 } from "jsonc-parser";
|
|
466
482
|
import { constants } from "fs";
|
|
467
483
|
import { access as access2, lstat, readFile as readFile2, readlink, rename, writeFile as writeFile2 } from "fs/promises";
|
|
468
|
-
import { createRequire } from "module";
|
|
469
484
|
import { join as join2 } from "path";
|
|
470
485
|
|
|
471
486
|
// src/lib/container-env.ts
|
|
@@ -518,6 +533,10 @@ var defaultFsDeps = { access, cp, mkdir, readdir, readFile, stat, writeFile };
|
|
|
518
533
|
var DEVCONTAINER_DIR = ".devcontainer";
|
|
519
534
|
var DEVCONTAINER_JSON = "devcontainer.json";
|
|
520
535
|
var DOT_DEVCONTAINER_JSON = ".devcontainer.json";
|
|
536
|
+
var MANAGED_IMAGE_REPO = "ghcr.io/zookanalytics/bmad-orchestrator/devcontainer";
|
|
537
|
+
function getManagedImage() {
|
|
538
|
+
return `${MANAGED_IMAGE_REPO}:${package_default.version}`;
|
|
539
|
+
}
|
|
521
540
|
var cachedPackageRoot;
|
|
522
541
|
function getPackageRoot(checkAccess = accessSync) {
|
|
523
542
|
if (cachedPackageRoot) return cachedPackageRoot;
|
|
@@ -715,7 +734,9 @@ async function readRepoConfig(workspacePath, deps = defaultMergeDeps, logger) {
|
|
|
715
734
|
}
|
|
716
735
|
return void 0;
|
|
717
736
|
}
|
|
718
|
-
|
|
737
|
+
var MAX_WARNED_MISMATCHES = 100;
|
|
738
|
+
var warnedMismatches = /* @__PURE__ */ new Set();
|
|
739
|
+
function validateRepoConfig(config, managedImage, logger, workspaceKey) {
|
|
719
740
|
const rejectedProps = ["build", "dockerFile", "dockerfile", "dockerComposeFile"];
|
|
720
741
|
for (const prop of rejectedProps) {
|
|
721
742
|
if (prop in config && config[prop] !== void 0) {
|
|
@@ -727,9 +748,17 @@ function validateRepoConfig(config, managedImage, logger) {
|
|
|
727
748
|
if ("image" in config && config.image !== void 0) {
|
|
728
749
|
const repoImage = String(config.image);
|
|
729
750
|
if (repoImage !== managedImage) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
751
|
+
const key = `${workspaceKey ?? "*"}|${repoImage}|${managedImage}`;
|
|
752
|
+
if (!warnedMismatches.has(key)) {
|
|
753
|
+
if (warnedMismatches.size >= MAX_WARNED_MISMATCHES) {
|
|
754
|
+
const first = warnedMismatches.values().next().value;
|
|
755
|
+
if (first !== void 0) warnedMismatches.delete(first);
|
|
756
|
+
}
|
|
757
|
+
warnedMismatches.add(key);
|
|
758
|
+
logger?.warn(
|
|
759
|
+
`Repo config specifies image '${repoImage}' which will be overridden by agent-env managed image '${managedImage}'.`
|
|
760
|
+
);
|
|
761
|
+
}
|
|
733
762
|
}
|
|
734
763
|
}
|
|
735
764
|
}
|
|
@@ -986,22 +1015,16 @@ async function loadManagedDefaults(deps = defaultMergeDeps) {
|
|
|
986
1015
|
}
|
|
987
1016
|
}
|
|
988
1017
|
return {
|
|
989
|
-
image
|
|
1018
|
+
// The baseline file's `image` field is a sentinel (MANAGED_BY_AGENT_ENV_DO_NOT_EDIT)
|
|
1019
|
+
// — the real image is computed at runtime from packageJson.version via getManagedImage().
|
|
1020
|
+
// Edit MANAGED_IMAGE_REPO in devcontainer.ts to change the image source.
|
|
1021
|
+
image: getManagedImage(),
|
|
990
1022
|
initializeCmd: config.initializeCommand,
|
|
991
1023
|
baseContainerEnv
|
|
992
1024
|
};
|
|
993
1025
|
}
|
|
994
|
-
function getPackageVersion() {
|
|
995
|
-
try {
|
|
996
|
-
const req = createRequire(import.meta.url);
|
|
997
|
-
const pkg = req("../../package.json");
|
|
998
|
-
return pkg.version;
|
|
999
|
-
} catch {
|
|
1000
|
-
return "unknown";
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
1026
|
async function writeGeneratedConfig(outputPath, config, deps = defaultMergeDeps) {
|
|
1004
|
-
const version2 =
|
|
1027
|
+
const version2 = package_default.version;
|
|
1005
1028
|
const header = `${AUTO_GENERATED_HEADER} v${version2}. Do not edit.
|
|
1006
1029
|
`;
|
|
1007
1030
|
const json = JSON.stringify(config, null, 2);
|
|
@@ -1060,6 +1083,23 @@ function buildManagedConfig(defaults, params) {
|
|
|
1060
1083
|
};
|
|
1061
1084
|
}
|
|
1062
1085
|
|
|
1086
|
+
// src/lib/managed-image-pull.ts
|
|
1087
|
+
async function pullManagedImage(managedImage, pull, deps) {
|
|
1088
|
+
if (!pull) {
|
|
1089
|
+
deps.logger?.warn(
|
|
1090
|
+
`Using cached image; not matched to current agent-env version. Skipping pull of ${managedImage} (--no-pull). The container will start with whichever image is already cached locally. Re-run without --no-pull to fetch the pinned image.`
|
|
1091
|
+
);
|
|
1092
|
+
return { ok: true };
|
|
1093
|
+
}
|
|
1094
|
+
deps.logger?.info(
|
|
1095
|
+
`Pulling ${managedImage}... (no progress output; a first download of this multi-GB image may take several minutes)`
|
|
1096
|
+
);
|
|
1097
|
+
const result = await deps.container.dockerPull(managedImage);
|
|
1098
|
+
if (!result.ok) return { ok: false, error: result.error };
|
|
1099
|
+
deps.logger?.info(`Pulled ${managedImage}`);
|
|
1100
|
+
return { ok: true };
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1063
1103
|
// src/lib/purpose-instance.ts
|
|
1064
1104
|
import { appendFile as appendFile2, mkdir as mkdir4, readdir as readdir3, readFile as readFile6, rename as rename3, stat as stat3, writeFile as writeFile5 } from "fs/promises";
|
|
1065
1105
|
import { homedir as homedir2 } from "os";
|
|
@@ -1748,7 +1788,7 @@ async function setupMergedConfig(wsPath, containerName, repoName, purposeText, d
|
|
|
1748
1788
|
await copyRepoEnvFiles(repoName, wsPath.root);
|
|
1749
1789
|
const repoConfig = await readRepoConfig(wsPath.root, deps.mergeDeps, deps.logger);
|
|
1750
1790
|
if (repoConfig) {
|
|
1751
|
-
validateRepoConfig(repoConfig, defaults.image, deps.logger);
|
|
1791
|
+
validateRepoConfig(repoConfig, defaults.image, deps.logger, wsPath.root);
|
|
1752
1792
|
}
|
|
1753
1793
|
const merged = mergeDevcontainerConfigs(managed, repoConfig);
|
|
1754
1794
|
await copyManagedAssets(wsPath.root, deps.devcontainerFsDeps);
|
|
@@ -1852,6 +1892,21 @@ async function createInstance(instanceName, repoUrl, deps, options) {
|
|
|
1852
1892
|
}
|
|
1853
1893
|
};
|
|
1854
1894
|
}
|
|
1895
|
+
const dockerAvailable = await deps.container.isDockerAvailable();
|
|
1896
|
+
if (!dockerAvailable) {
|
|
1897
|
+
return {
|
|
1898
|
+
ok: false,
|
|
1899
|
+
error: {
|
|
1900
|
+
code: "ORBSTACK_REQUIRED",
|
|
1901
|
+
message: "Docker is not available. OrbStack or Docker Desktop must be running.",
|
|
1902
|
+
suggestion: "Start OrbStack or Docker Desktop, then try again."
|
|
1903
|
+
}
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
const managedPullResult = await pullManagedImage(getManagedImage(), options?.pull ?? true, deps);
|
|
1907
|
+
if (!managedPullResult.ok) {
|
|
1908
|
+
return { ok: false, error: managedPullResult.error };
|
|
1909
|
+
}
|
|
1855
1910
|
const prepResult = await cloneAndPrepareWorkspace(repoUrl, wsPath, deps);
|
|
1856
1911
|
if (!prepResult.ok) return prepResult;
|
|
1857
1912
|
const configResult = await setupMergedConfig(wsPath, containerName, repoName, purposeText, deps);
|
|
@@ -2738,7 +2793,7 @@ async function resolveRepoArg(repoArg, deps) {
|
|
|
2738
2793
|
}
|
|
2739
2794
|
|
|
2740
2795
|
// src/commands/create.ts
|
|
2741
|
-
var createCommand = new Command4("create").description("Create a new isolated development environment").argument("<name>", "Name for the new instance").option("--repo <url|slug>", 'Git repo URL, registered slug, or "." for current directory').option("--purpose <text>", "Set the instance purpose/label at creation time").option("--attach", "Attach immediately after creation").option("--baseline", "[REMOVED] Config merge replaces this flag").option("--no-baseline", "[REMOVED] Config merge replaces this flag").action(async (name, options) => {
|
|
2796
|
+
var createCommand = new Command4("create").description("Create a new isolated development environment").argument("<name>", "Name for the new instance").option("--repo <url|slug>", 'Git repo URL, registered slug, or "." for current directory').option("--purpose <text>", "Set the instance purpose/label at creation time").option("--attach", "Attach immediately after creation").option("--no-pull", "Skip pulling the managed image (use cached image)").option("--baseline", "[REMOVED] Config merge replaces this flag").option("--no-baseline", "[REMOVED] Config merge replaces this flag").action(async (name, options) => {
|
|
2742
2797
|
if (options.baseline !== void 0) {
|
|
2743
2798
|
console.error(
|
|
2744
2799
|
formatError(
|
|
@@ -2786,7 +2841,8 @@ var createCommand = new Command4("create").description("Create a new isolated de
|
|
|
2786
2841
|
try {
|
|
2787
2842
|
const result = await createInstance(name, repoUrl, deps, {
|
|
2788
2843
|
purpose: options.purpose,
|
|
2789
|
-
onProgress: progress.update
|
|
2844
|
+
onProgress: progress.update,
|
|
2845
|
+
pull: options.pull
|
|
2790
2846
|
});
|
|
2791
2847
|
progress.clear();
|
|
2792
2848
|
if (!result.ok) {
|
|
@@ -3283,8 +3339,9 @@ var listCommand = new Command6("list").alias("ps").description("List all instanc
|
|
|
3283
3339
|
import { Command as Command7 } from "commander";
|
|
3284
3340
|
|
|
3285
3341
|
// src/lib/version-drift.ts
|
|
3342
|
+
import { parse as parseJsonc3 } from "jsonc-parser";
|
|
3286
3343
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
3287
|
-
import { access as access4, constants as constants2 } from "fs/promises";
|
|
3344
|
+
import { access as access4, constants as constants2, readFile as readFile11 } from "fs/promises";
|
|
3288
3345
|
import { homedir as homedir7 } from "os";
|
|
3289
3346
|
import { join as join10 } from "path";
|
|
3290
3347
|
|
|
@@ -3360,13 +3417,13 @@ async function checkForUpdate(opts) {
|
|
|
3360
3417
|
cachePath,
|
|
3361
3418
|
cacheTtlMs,
|
|
3362
3419
|
fetchFn = fetch,
|
|
3363
|
-
readFile:
|
|
3420
|
+
readFile: readFile18 = (p, enc) => fs.readFile(p, enc),
|
|
3364
3421
|
writeFile: writeFile14 = (p, d, enc) => fs.writeFile(p, d, enc),
|
|
3365
3422
|
mkdir: mkdir15 = (p, o) => fs.mkdir(p, o),
|
|
3366
3423
|
now = () => Date.now()
|
|
3367
3424
|
} = opts;
|
|
3368
3425
|
const currentTime = now();
|
|
3369
|
-
const cache = await readCache(cachePath,
|
|
3426
|
+
const cache = await readCache(cachePath, readFile18);
|
|
3370
3427
|
let latestVersion = null;
|
|
3371
3428
|
const isCacheFresh = cache !== null && currentTime - cache.lastCheck < cacheTtlMs;
|
|
3372
3429
|
if (isCacheFresh) {
|
|
@@ -3425,6 +3482,31 @@ async function isPackagePathStale(deps = {}) {
|
|
|
3425
3482
|
return true;
|
|
3426
3483
|
}
|
|
3427
3484
|
}
|
|
3485
|
+
async function detectImageDrift(managedConfigPath, deps = {}) {
|
|
3486
|
+
const read = deps.readFile ?? readFile11;
|
|
3487
|
+
const expected = (deps.getExpectedImage ?? getManagedImage)();
|
|
3488
|
+
let content;
|
|
3489
|
+
try {
|
|
3490
|
+
content = await read(managedConfigPath, "utf-8");
|
|
3491
|
+
} catch {
|
|
3492
|
+
return null;
|
|
3493
|
+
}
|
|
3494
|
+
const errors = [];
|
|
3495
|
+
const parsed = parseJsonc3(content, errors, { allowTrailingComma: true });
|
|
3496
|
+
if (errors.length > 0 || parsed === null) {
|
|
3497
|
+
deps.logger?.warn(
|
|
3498
|
+
`Could not parse ${managedConfigPath} to check image drift \u2014 file may be corrupted. Rebuild to regenerate.`
|
|
3499
|
+
);
|
|
3500
|
+
return null;
|
|
3501
|
+
}
|
|
3502
|
+
if (typeof parsed.image !== "string") return null;
|
|
3503
|
+
if (parsed.image === expected) return null;
|
|
3504
|
+
return { configuredImage: parsed.image, expectedImage: expected };
|
|
3505
|
+
}
|
|
3506
|
+
function getManagedConfigPath(workspaceName, fsDeps) {
|
|
3507
|
+
const wsPath = getWorkspacePathByName(workspaceName, fsDeps);
|
|
3508
|
+
return join10(wsPath.agentEnvDir, "devcontainer.json");
|
|
3509
|
+
}
|
|
3428
3510
|
var UPDATE_CHECK_CACHE_PATH = join10(homedir7(), ".agent-env", "update-check.json");
|
|
3429
3511
|
var UPDATE_CHECK_CACHE_TTL_MS = 36e5;
|
|
3430
3512
|
async function fetchUpdateMessageFromRegistry(force = false) {
|
|
@@ -3439,22 +3521,30 @@ async function fetchUpdateMessageFromRegistry(force = false) {
|
|
|
3439
3521
|
return null;
|
|
3440
3522
|
}
|
|
3441
3523
|
}
|
|
3442
|
-
async function detectDriftState(deps = {}, options = {}) {
|
|
3524
|
+
async function detectDriftState(workspaceName, deps = {}, options = {}) {
|
|
3443
3525
|
const {
|
|
3444
3526
|
isPackagePathStale: probe = isPackagePathStale,
|
|
3445
3527
|
fetchUpdateMessage = (force) => fetchUpdateMessageFromRegistry(force),
|
|
3446
|
-
getInstalledVersion: resolveInstalled = getInstalledVersion
|
|
3528
|
+
getInstalledVersion: resolveInstalled = getInstalledVersion,
|
|
3529
|
+
detectImageDrift: imageProbe = (path) => detectImageDrift(path)
|
|
3447
3530
|
} = deps;
|
|
3448
3531
|
const installedVersion = resolveInstalled();
|
|
3449
|
-
const [packageMoved, updateMessage] = await Promise.all([
|
|
3532
|
+
const [packageMoved, updateMessage, imageDrift] = await Promise.all([
|
|
3450
3533
|
probe(),
|
|
3451
|
-
fetchUpdateMessage(options.forceRefresh ?? false)
|
|
3534
|
+
fetchUpdateMessage(options.forceRefresh ?? false),
|
|
3535
|
+
// Resilience: a buggy override could reject. Built-in detectImageDrift
|
|
3536
|
+
// already swallows its own errors, but treat the whole probe as best-effort
|
|
3537
|
+
// so the entire drift state never rejects on the menu's poll loop.
|
|
3538
|
+
workspaceName !== void 0 ? imageProbe(getManagedConfigPath(workspaceName)).catch(
|
|
3539
|
+
() => null
|
|
3540
|
+
) : Promise.resolve(null)
|
|
3452
3541
|
]);
|
|
3453
3542
|
return {
|
|
3454
3543
|
packageMoved,
|
|
3455
3544
|
updateMessage,
|
|
3456
3545
|
installedVersion,
|
|
3457
|
-
currentVersion: package_default.version
|
|
3546
|
+
currentVersion: package_default.version,
|
|
3547
|
+
imageDrift
|
|
3458
3548
|
};
|
|
3459
3549
|
}
|
|
3460
3550
|
function getCurrentVersion() {
|
|
@@ -3602,6 +3692,14 @@ function hasNewerInstall(driftState) {
|
|
|
3602
3692
|
if (!driftState?.installedVersion) return false;
|
|
3603
3693
|
return isNewerVersion2(driftState.currentVersion, driftState.installedVersion);
|
|
3604
3694
|
}
|
|
3695
|
+
function formatImageTagForLabel(image) {
|
|
3696
|
+
const noDigest = image.split("@")[0];
|
|
3697
|
+
const m = /:([^:/]+)$/.exec(noDigest);
|
|
3698
|
+
if (!m) return "refresh";
|
|
3699
|
+
const tag = m[1];
|
|
3700
|
+
if (/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(tag)) return `v${tag}`;
|
|
3701
|
+
return "refresh";
|
|
3702
|
+
}
|
|
3605
3703
|
function buildActionOptions(driftState) {
|
|
3606
3704
|
if (driftState?.packageMoved) {
|
|
3607
3705
|
return [RESTART_REQUIRED_OPTION, ...BASE_ACTION_OPTIONS, EXIT_OPTION];
|
|
@@ -3610,6 +3708,13 @@ function buildActionOptions(driftState) {
|
|
|
3610
3708
|
const label = `\u267B\uFE0F Restart menu (v${driftState.installedVersion} installed)`;
|
|
3611
3709
|
return [{ label, value: "restart" }, ...BASE_ACTION_OPTIONS, EXIT_OPTION];
|
|
3612
3710
|
}
|
|
3711
|
+
if (driftState?.imageDrift) {
|
|
3712
|
+
const imageLabel = formatImageTagForLabel(driftState.imageDrift.expectedImage);
|
|
3713
|
+
const updatedOptions = BASE_ACTION_OPTIONS.map(
|
|
3714
|
+
(o) => o.value === "rebuild" ? { label: `\u{1F6E0} Rebuild container (image ${imageLabel} available)`, value: "rebuild" } : o
|
|
3715
|
+
);
|
|
3716
|
+
return [...updatedOptions, CHECK_FOR_UPDATES_OPTION, EXIT_OPTION];
|
|
3717
|
+
}
|
|
3613
3718
|
if (driftState?.updateMessage) {
|
|
3614
3719
|
return [...BASE_ACTION_OPTIONS, CHECK_FOR_UPDATES_OPTION, EXIT_OPTION];
|
|
3615
3720
|
}
|
|
@@ -3632,6 +3737,15 @@ function DriftBanner({ driftState }) {
|
|
|
3632
3737
|
" is installed \u2014 restart to use it"
|
|
3633
3738
|
] }) });
|
|
3634
3739
|
}
|
|
3740
|
+
if (driftState.imageDrift) {
|
|
3741
|
+
return /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsxs3(Text3, { color: "cyan", children: [
|
|
3742
|
+
"Container image will refresh on next rebuild: ",
|
|
3743
|
+
driftState.imageDrift.configuredImage,
|
|
3744
|
+
" \u2192",
|
|
3745
|
+
" ",
|
|
3746
|
+
driftState.imageDrift.expectedImage
|
|
3747
|
+
] }) });
|
|
3748
|
+
}
|
|
3635
3749
|
if (driftState.updateMessage) {
|
|
3636
3750
|
return /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, flexDirection: "column", children: /* @__PURE__ */ jsx3(Text3, { color: "yellow", children: driftState.updateMessage }) });
|
|
3637
3751
|
}
|
|
@@ -3686,7 +3800,8 @@ function makeNeutralDriftState() {
|
|
|
3686
3800
|
packageMoved: false,
|
|
3687
3801
|
updateMessage: null,
|
|
3688
3802
|
installedVersion: null,
|
|
3689
|
-
currentVersion: getCurrentVersion()
|
|
3803
|
+
currentVersion: getCurrentVersion(),
|
|
3804
|
+
imageDrift: null
|
|
3690
3805
|
};
|
|
3691
3806
|
}
|
|
3692
3807
|
function MenuContainer({
|
|
@@ -3704,7 +3819,7 @@ function MenuContainer({
|
|
|
3704
3819
|
let cancelled = false;
|
|
3705
3820
|
const runProbe = async () => {
|
|
3706
3821
|
try {
|
|
3707
|
-
const next = await detectDriftStateFn();
|
|
3822
|
+
const next = await detectDriftStateFn(instanceInfo.name);
|
|
3708
3823
|
if (!cancelled) {
|
|
3709
3824
|
setDriftState(next);
|
|
3710
3825
|
}
|
|
@@ -3719,7 +3834,7 @@ function MenuContainer({
|
|
|
3719
3834
|
cancelled = true;
|
|
3720
3835
|
clearInterval(handle);
|
|
3721
3836
|
};
|
|
3722
|
-
}, [detectDriftStateFn, pollIntervalMs]);
|
|
3837
|
+
}, [detectDriftStateFn, pollIntervalMs, instanceInfo.name]);
|
|
3723
3838
|
return /* @__PURE__ */ jsx4(
|
|
3724
3839
|
InteractiveMenu,
|
|
3725
3840
|
{
|
|
@@ -3737,7 +3852,7 @@ import {
|
|
|
3737
3852
|
cp as cp3,
|
|
3738
3853
|
mkdir as mkdir9,
|
|
3739
3854
|
readdir as readdir7,
|
|
3740
|
-
readFile as
|
|
3855
|
+
readFile as readFile12,
|
|
3741
3856
|
rename as rename7,
|
|
3742
3857
|
rm as rm3,
|
|
3743
3858
|
stat as stat7,
|
|
@@ -3775,9 +3890,9 @@ function createRebuildDefaultDeps() {
|
|
|
3775
3890
|
executor,
|
|
3776
3891
|
container: createContainerLifecycle(executor),
|
|
3777
3892
|
workspaceFsDeps: { mkdir: mkdir9, readdir: readdir7, stat: stat7, homedir: homedir8 },
|
|
3778
|
-
stateFsDeps: { readFile:
|
|
3779
|
-
devcontainerFsDeps: { cp: cp3, mkdir: mkdir9, readdir: readdir7, readFile:
|
|
3780
|
-
mergeDeps: { readFile:
|
|
3893
|
+
stateFsDeps: { readFile: readFile12, writeFile: writeFile10, rename: rename7, mkdir: mkdir9, appendFile: appendFile6 },
|
|
3894
|
+
devcontainerFsDeps: { cp: cp3, mkdir: mkdir9, readdir: readdir7, readFile: readFile12, stat: stat7, writeFile: writeFile10 },
|
|
3895
|
+
mergeDeps: { readFile: readFile12, writeFile: writeFile10, rename: rename7, access: access5 },
|
|
3781
3896
|
rm: rm3,
|
|
3782
3897
|
rename: rename7,
|
|
3783
3898
|
logger: { warn: (msg) => console.warn(msg), info: (msg) => console.info(msg) }
|
|
@@ -3805,13 +3920,16 @@ async function refreshMergedConfig(wsRoot, containerName, wsName, repoSlug, purp
|
|
|
3805
3920
|
};
|
|
3806
3921
|
}
|
|
3807
3922
|
if (repoConfig) {
|
|
3808
|
-
validateRepoConfig(repoConfig, defaults.image, deps.logger);
|
|
3923
|
+
validateRepoConfig(repoConfig, defaults.image, deps.logger, wsRoot);
|
|
3809
3924
|
}
|
|
3810
3925
|
const merged = mergeDevcontainerConfigs(managed, repoConfig);
|
|
3811
3926
|
await copyManagedAssets(wsRoot, deps.devcontainerFsDeps);
|
|
3812
3927
|
const configPath = join11(wsRoot, AGENT_ENV_DIR, "devcontainer.json");
|
|
3813
3928
|
await writeGeneratedConfig(configPath, merged, deps.mergeDeps);
|
|
3814
|
-
return {
|
|
3929
|
+
return {
|
|
3930
|
+
ok: true,
|
|
3931
|
+
repoConfigDetected: repoConfig !== void 0
|
|
3932
|
+
};
|
|
3815
3933
|
} catch (err) {
|
|
3816
3934
|
return {
|
|
3817
3935
|
ok: false,
|
|
@@ -3835,7 +3953,11 @@ async function lookupWorkspace(instanceName, deps, repoSlug) {
|
|
|
3835
3953
|
const state = await readState(wsPath, deps.stateFsDeps);
|
|
3836
3954
|
return { ok: true, wsPath, state };
|
|
3837
3955
|
}
|
|
3838
|
-
async function executePullStep(wsRoot, pull, deps) {
|
|
3956
|
+
async function executePullStep(wsRoot, pull, managedImage, deps) {
|
|
3957
|
+
const managedPullResult = await pullManagedImage(managedImage, pull, deps);
|
|
3958
|
+
if (!managedPullResult.ok) {
|
|
3959
|
+
return { ok: false, error: managedPullResult.error };
|
|
3960
|
+
}
|
|
3839
3961
|
let dockerfilePath;
|
|
3840
3962
|
try {
|
|
3841
3963
|
dockerfilePath = await resolveDockerfilePath(wsRoot, deps.devcontainerFsDeps);
|
|
@@ -3854,7 +3976,7 @@ async function executePullStep(wsRoot, pull, deps) {
|
|
|
3854
3976
|
return { ok: true, hasDockerfile };
|
|
3855
3977
|
}
|
|
3856
3978
|
if (dockerfilePath === null) {
|
|
3857
|
-
deps.logger?.info("No Dockerfile found \u2014
|
|
3979
|
+
deps.logger?.info("No Dockerfile found \u2014 only managed image pulled.");
|
|
3858
3980
|
return { ok: true, hasDockerfile: false };
|
|
3859
3981
|
}
|
|
3860
3982
|
let dockerfileContent;
|
|
@@ -3949,6 +4071,11 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
|
|
|
3949
4071
|
}
|
|
3950
4072
|
};
|
|
3951
4073
|
}
|
|
4074
|
+
const pullStepResult = await executePullStep(wsPath.root, pull, getManagedImage(), deps);
|
|
4075
|
+
if (!pullStepResult.ok) {
|
|
4076
|
+
return { ok: false, error: pullStepResult.error };
|
|
4077
|
+
}
|
|
4078
|
+
const { hasDockerfile } = pullStepResult;
|
|
3952
4079
|
const configResult = await refreshMergedConfig(
|
|
3953
4080
|
wsPath.root,
|
|
3954
4081
|
containerName,
|
|
@@ -3961,11 +4088,6 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
|
|
|
3961
4088
|
if (!configResult.ok) {
|
|
3962
4089
|
return { ok: false, error: configResult.error };
|
|
3963
4090
|
}
|
|
3964
|
-
const pullStepResult = await executePullStep(wsPath.root, pull, deps);
|
|
3965
|
-
if (!pullStepResult.ok) {
|
|
3966
|
-
return { ok: false, error: pullStepResult.error };
|
|
3967
|
-
}
|
|
3968
|
-
const { hasDockerfile } = pullStepResult;
|
|
3969
4091
|
const statusResult = await deps.container.containerStatus(oldContainerName);
|
|
3970
4092
|
const wasRunning = statusResult.ok && statusResult.status === "running";
|
|
3971
4093
|
if (wasRunning && !force) {
|
|
@@ -4012,7 +4134,7 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
|
|
|
4012
4134
|
}
|
|
4013
4135
|
|
|
4014
4136
|
// src/lib/shutdown-instance.ts
|
|
4015
|
-
import { appendFile as appendFile7, mkdir as mkdir10, readdir as readdir8, readFile as
|
|
4137
|
+
import { appendFile as appendFile7, mkdir as mkdir10, readdir as readdir8, readFile as readFile13, rename as rename8, stat as stat8, writeFile as writeFile11 } from "fs/promises";
|
|
4016
4138
|
import { homedir as homedir9 } from "os";
|
|
4017
4139
|
function createShutdownDefaultDeps() {
|
|
4018
4140
|
const executor = createExecutor();
|
|
@@ -4020,7 +4142,7 @@ function createShutdownDefaultDeps() {
|
|
|
4020
4142
|
executor,
|
|
4021
4143
|
container: createContainerLifecycle(executor),
|
|
4022
4144
|
workspaceFsDeps: { mkdir: mkdir10, readdir: readdir8, stat: stat8, homedir: homedir9 },
|
|
4023
|
-
stateFsDeps: { readFile:
|
|
4145
|
+
stateFsDeps: { readFile: readFile13, writeFile: writeFile11, rename: rename8, mkdir: mkdir10, appendFile: appendFile7 },
|
|
4024
4146
|
logger: { warn: (msg) => console.warn(msg), info: (msg) => console.info(msg) }
|
|
4025
4147
|
};
|
|
4026
4148
|
}
|
|
@@ -4069,7 +4191,7 @@ async function shutdownInstance(instanceName, deps, repoSlug) {
|
|
|
4069
4191
|
}
|
|
4070
4192
|
|
|
4071
4193
|
// src/lib/menu-deps.ts
|
|
4072
|
-
function buildMenuDeps() {
|
|
4194
|
+
function buildMenuDeps(workspaceName) {
|
|
4073
4195
|
return {
|
|
4074
4196
|
attachInstance: (wsName, slug) => {
|
|
4075
4197
|
const deps = createAttachDefaultDeps();
|
|
@@ -4135,7 +4257,15 @@ function buildMenuDeps() {
|
|
|
4135
4257
|
},
|
|
4136
4258
|
checkForUpdates: async () => {
|
|
4137
4259
|
console.log("Checking for updates...");
|
|
4138
|
-
const state = await detectDriftState(
|
|
4260
|
+
const state = await detectDriftState(
|
|
4261
|
+
workspaceName,
|
|
4262
|
+
{
|
|
4263
|
+
// Outside the Ink render loop console output is safe — surface
|
|
4264
|
+
// corrupt-config warnings from the image-drift probe here.
|
|
4265
|
+
detectImageDrift: (path) => detectImageDrift(path, { logger: { warn: (m) => console.warn(m) } })
|
|
4266
|
+
},
|
|
4267
|
+
{ forceRefresh: true }
|
|
4268
|
+
);
|
|
4139
4269
|
const current = getCurrentVersion();
|
|
4140
4270
|
if (state.packageMoved) {
|
|
4141
4271
|
console.log(
|
|
@@ -4145,10 +4275,18 @@ function buildMenuDeps() {
|
|
|
4145
4275
|
console.log(
|
|
4146
4276
|
`\x1B[33magent-env v${state.installedVersion} is installed \u2014 pick "Restart menu" to use it.\x1B[0m`
|
|
4147
4277
|
);
|
|
4148
|
-
} else if (state.updateMessage) {
|
|
4149
|
-
console.log(state.updateMessage);
|
|
4150
4278
|
} else {
|
|
4151
|
-
|
|
4279
|
+
if (state.updateMessage) {
|
|
4280
|
+
console.log(state.updateMessage);
|
|
4281
|
+
}
|
|
4282
|
+
if (state.imageDrift) {
|
|
4283
|
+
console.log(
|
|
4284
|
+
`\x1B[36mContainer image will refresh on next rebuild: ${state.imageDrift.configuredImage} \u2192 ${state.imageDrift.expectedImage}\x1B[0m`
|
|
4285
|
+
);
|
|
4286
|
+
}
|
|
4287
|
+
if (!state.updateMessage && !state.imageDrift) {
|
|
4288
|
+
console.log(`\x1B[32m\u2713\x1B[0m agent-env ${current} is up to date`);
|
|
4289
|
+
}
|
|
4152
4290
|
}
|
|
4153
4291
|
return { ok: true };
|
|
4154
4292
|
},
|
|
@@ -4198,7 +4336,7 @@ var onCommand = new Command7("on").description("Open the interactive menu for an
|
|
|
4198
4336
|
return;
|
|
4199
4337
|
}
|
|
4200
4338
|
const { workspaceName } = lookup;
|
|
4201
|
-
const menuDeps = buildMenuDeps();
|
|
4339
|
+
const menuDeps = buildMenuDeps(workspaceName);
|
|
4202
4340
|
await launchActionLoop(workspaceName, menuDeps, repoSlug);
|
|
4203
4341
|
});
|
|
4204
4342
|
|
|
@@ -4299,7 +4437,7 @@ function handleSetResult(result) {
|
|
|
4299
4437
|
// src/commands/rebuild.ts
|
|
4300
4438
|
import chalk2 from "chalk";
|
|
4301
4439
|
import { Command as Command10 } from "commander";
|
|
4302
|
-
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
|
|
4440
|
+
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 the managed image and base images (use cached images)").option("--use-cache", "Allow Docker build layer cache reuse").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(
|
|
4303
4441
|
async (name, options) => {
|
|
4304
4442
|
const deps = createRebuildDefaultDeps();
|
|
4305
4443
|
const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
|
|
@@ -4386,7 +4524,7 @@ function createAuditEntry(instanceName, gitState, confirmationMethod) {
|
|
|
4386
4524
|
}
|
|
4387
4525
|
|
|
4388
4526
|
// src/lib/remove-instance.ts
|
|
4389
|
-
import { mkdir as mkdir12, readdir as readdir9, readFile as
|
|
4527
|
+
import { mkdir as mkdir12, readdir as readdir9, readFile as readFile14, rm as rm4, stat as stat9 } from "fs/promises";
|
|
4390
4528
|
import { homedir as homedir11 } from "os";
|
|
4391
4529
|
function createRemoveDefaultDeps() {
|
|
4392
4530
|
const executor = createExecutor();
|
|
@@ -4395,7 +4533,7 @@ function createRemoveDefaultDeps() {
|
|
|
4395
4533
|
container: createContainerLifecycle(executor),
|
|
4396
4534
|
gitDetector: createGitStateDetector(executor),
|
|
4397
4535
|
workspaceFsDeps: { mkdir: mkdir12, readdir: readdir9, stat: stat9, homedir: homedir11 },
|
|
4398
|
-
stateFsDeps: { readFile:
|
|
4536
|
+
stateFsDeps: { readFile: readFile14 },
|
|
4399
4537
|
deleteFsDeps: { rm: rm4 }
|
|
4400
4538
|
};
|
|
4401
4539
|
}
|
|
@@ -4791,7 +4929,7 @@ var reposCommand = new Command12("repos").description("List tracked repositories
|
|
|
4791
4929
|
|
|
4792
4930
|
// src/commands/setup-audio.ts
|
|
4793
4931
|
import { Command as Command13 } from "commander";
|
|
4794
|
-
import { copyFile, mkdir as mkdir13, readFile as
|
|
4932
|
+
import { copyFile, mkdir as mkdir13, readFile as readFile15, writeFile as writeFile12, access as access6 } from "fs/promises";
|
|
4795
4933
|
import { homedir as homedir12, platform } from "os";
|
|
4796
4934
|
|
|
4797
4935
|
// src/lib/setup-audio.ts
|
|
@@ -4889,7 +5027,7 @@ function createDefaultSetupAudioDeps() {
|
|
|
4889
5027
|
platform: platform(),
|
|
4890
5028
|
homeDir: homedir12(),
|
|
4891
5029
|
execute: exec,
|
|
4892
|
-
readFile: (path, encoding) =>
|
|
5030
|
+
readFile: (path, encoding) => readFile15(path, encoding),
|
|
4893
5031
|
writeFile: (path, content, encoding) => writeFile12(path, content, encoding),
|
|
4894
5032
|
copyFile,
|
|
4895
5033
|
mkdir: (path, opts) => mkdir13(path, opts),
|
|
@@ -4957,11 +5095,11 @@ import { execSync } from "child_process";
|
|
|
4957
5095
|
import { join as join14 } from "path";
|
|
4958
5096
|
|
|
4959
5097
|
// src/lib/tmux-session.ts
|
|
4960
|
-
import { readFile as
|
|
5098
|
+
import { readFile as readFile16, writeFile as writeFile13, rename as rename9, mkdir as mkdir14 } from "fs/promises";
|
|
4961
5099
|
import { dirname as dirname4, join as join13 } from "path";
|
|
4962
5100
|
async function readPanesState(path) {
|
|
4963
5101
|
try {
|
|
4964
|
-
const content = await
|
|
5102
|
+
const content = await readFile16(path, "utf-8");
|
|
4965
5103
|
const parsed = JSON.parse(content);
|
|
4966
5104
|
if (typeof parsed === "object" && parsed !== null && parsed.version === 1) {
|
|
4967
5105
|
return parsed;
|
|
@@ -4979,7 +5117,7 @@ async function writePanesState(path, state) {
|
|
|
4979
5117
|
}
|
|
4980
5118
|
async function readSessionState(path) {
|
|
4981
5119
|
try {
|
|
4982
|
-
const content = await
|
|
5120
|
+
const content = await readFile16(path, "utf-8");
|
|
4983
5121
|
const parsed = JSON.parse(content);
|
|
4984
5122
|
if (typeof parsed === "object" && parsed !== null && parsed.version === 1 && Array.isArray(parsed.windows)) {
|
|
4985
5123
|
return parsed;
|
|
@@ -5167,9 +5305,9 @@ var tmuxSaveCommand = new Command16("tmux-save").description("Save current tmux
|
|
|
5167
5305
|
import { Command as Command17 } from "commander";
|
|
5168
5306
|
|
|
5169
5307
|
// src/lib/tmux-status.ts
|
|
5170
|
-
import { readFile as
|
|
5308
|
+
import { readFile as readFile17 } from "fs/promises";
|
|
5171
5309
|
var MAX_PURPOSE_DISPLAY_LEN = 40;
|
|
5172
|
-
var defaultDeps3 = { readFile:
|
|
5310
|
+
var defaultDeps3 = { readFile: readFile17 };
|
|
5173
5311
|
function formatTmuxStatus(instance, purpose) {
|
|
5174
5312
|
if (!instance) return "?";
|
|
5175
5313
|
if (!purpose) return instance;
|
|
@@ -5290,7 +5428,7 @@ program.action(async () => {
|
|
|
5290
5428
|
if (pickerResult.kind === "cancelled") {
|
|
5291
5429
|
return;
|
|
5292
5430
|
}
|
|
5293
|
-
const menuDeps = buildMenuDeps();
|
|
5431
|
+
const menuDeps = buildMenuDeps(pickerResult.name);
|
|
5294
5432
|
await launchActionLoop(pickerResult.name, menuDeps);
|
|
5295
5433
|
});
|
|
5296
5434
|
var shouldCheck = !!process.stderr.isTTY && !isInsideContainer() && !isLinked && !isBakedDev;
|