@zookanalytics/agent-env 0.9.1 → 0.11.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 +538 -275
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -25,7 +25,7 @@ function createExecutor(executor = execa) {
|
|
|
25
25
|
if (onLine) {
|
|
26
26
|
const sub = subprocess;
|
|
27
27
|
const handleChunk = (chunk) => {
|
|
28
|
-
for (const line of chunk.toString().split(
|
|
28
|
+
for (const line of chunk.toString().split(/\r?\n|\r/)) {
|
|
29
29
|
const trimmed = line.trim();
|
|
30
30
|
if (trimmed)
|
|
31
31
|
onLine(trimmed);
|
|
@@ -47,16 +47,17 @@ var execute = createExecutor();
|
|
|
47
47
|
|
|
48
48
|
// src/cli.ts
|
|
49
49
|
import { program } from "commander";
|
|
50
|
-
import { render as
|
|
50
|
+
import { render as render3 } from "ink";
|
|
51
51
|
import { existsSync } from "fs";
|
|
52
|
-
import {
|
|
52
|
+
import { homedir as homedir10 } from "os";
|
|
53
|
+
import { dirname as dirname5, join as join14, resolve } from "path";
|
|
53
54
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
54
|
-
import
|
|
55
|
+
import React4 from "react";
|
|
55
56
|
|
|
56
57
|
// package.json
|
|
57
58
|
var package_default = {
|
|
58
59
|
name: "@zookanalytics/agent-env",
|
|
59
|
-
version: "0.
|
|
60
|
+
version: "0.11.0",
|
|
60
61
|
description: "CLI for creating isolated, AI-ready development environments",
|
|
61
62
|
type: "module",
|
|
62
63
|
bin: {
|
|
@@ -625,7 +626,7 @@ var defaultMergeDeps = {
|
|
|
625
626
|
var STATUS_BAR_JSON_FILENAME = "statusBar.json";
|
|
626
627
|
var LABEL_LIFECYCLE_CMDS = {
|
|
627
628
|
postCreateCommand: "/usr/local/bin/post-create.sh",
|
|
628
|
-
postStartCommand: "sudo /usr/local/bin/start-sshd.sh; tmux
|
|
629
|
+
postStartCommand: "sudo /usr/local/bin/start-sshd.sh; /home/node/.local/bin/tmux-session --detached || true; : > /tmp/install-shared-skills.log; /usr/local/bin/install-shared-skills.sh >> /tmp/install-shared-skills.log 2>&1 || true"
|
|
629
630
|
};
|
|
630
631
|
var COMPOSABLE_LIFECYCLE_CMDS = [
|
|
631
632
|
"postCreateCommand",
|
|
@@ -2141,6 +2142,7 @@ var COMMANDS = [
|
|
|
2141
2142
|
"list",
|
|
2142
2143
|
"ps",
|
|
2143
2144
|
"attach",
|
|
2145
|
+
"path",
|
|
2144
2146
|
"rebuild",
|
|
2145
2147
|
"remove",
|
|
2146
2148
|
"repos",
|
|
@@ -2223,7 +2225,7 @@ _agent_env_completions() {
|
|
|
2223
2225
|
|
|
2224
2226
|
# Complete based on command
|
|
2225
2227
|
case "\${prev}" in
|
|
2226
|
-
attach|purpose)
|
|
2228
|
+
attach|path|purpose)
|
|
2227
2229
|
local instances
|
|
2228
2230
|
instances="$(_agent_env_instances)"
|
|
2229
2231
|
COMPREPLY=($(compgen -W "--repo \${instances}" -- "\${cur}"))
|
|
@@ -2270,7 +2272,32 @@ _agent_env_completions() {
|
|
|
2270
2272
|
return 0
|
|
2271
2273
|
}
|
|
2272
2274
|
|
|
2273
|
-
complete -F _agent_env_completions agent-env
|
|
2275
|
+
complete -F _agent_env_completions agent-env
|
|
2276
|
+
|
|
2277
|
+
# aecd: cd into an instance's host directory
|
|
2278
|
+
aecd() {
|
|
2279
|
+
local dir
|
|
2280
|
+
dir="$(agent-env path "$@")" || return 1
|
|
2281
|
+
cd "\${dir}" || return 1
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
_aecd_completions() {
|
|
2285
|
+
local cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
2286
|
+
local prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
2287
|
+
local i has_repo=0
|
|
2288
|
+
for ((i=1; i < COMP_CWORD; i++)); do
|
|
2289
|
+
[[ "\${COMP_WORDS[i]}" == "--repo" ]] && has_repo=1 && break
|
|
2290
|
+
done
|
|
2291
|
+
if [[ "\${prev}" == "--repo" ]]; then
|
|
2292
|
+
COMPREPLY=($(compgen -W "$(_agent_env_repos)" -- "\${cur}"))
|
|
2293
|
+
elif [[ "\${cur}" == -* && \${has_repo} -eq 0 ]]; then
|
|
2294
|
+
COMPREPLY=($(compgen -W "--repo" -- "\${cur}"))
|
|
2295
|
+
else
|
|
2296
|
+
COMPREPLY=($(compgen -W "$(_agent_env_instances)" -- "\${cur}"))
|
|
2297
|
+
fi
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
complete -F _aecd_completions aecd`;
|
|
2274
2301
|
}
|
|
2275
2302
|
function generateZshCompletion() {
|
|
2276
2303
|
const commandDescriptions = [
|
|
@@ -2278,6 +2305,7 @@ function generateZshCompletion() {
|
|
|
2278
2305
|
"list:List all instances",
|
|
2279
2306
|
"ps:List all instances (alias)",
|
|
2280
2307
|
"attach:Attach to an instance tmux session",
|
|
2308
|
+
"path:Print host directory path for an instance",
|
|
2281
2309
|
"rebuild:Rebuild an instance container",
|
|
2282
2310
|
"remove:Remove an instance",
|
|
2283
2311
|
"repos:List tracked repositories",
|
|
@@ -2340,7 +2368,7 @@ ${commandDescriptions.map((desc) => ` '${desc}'`).join("\n")}
|
|
|
2340
2368
|
;;
|
|
2341
2369
|
args)
|
|
2342
2370
|
case $words[1] in
|
|
2343
|
-
attach|purpose)
|
|
2371
|
+
attach|path|purpose)
|
|
2344
2372
|
_arguments \\
|
|
2345
2373
|
'--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \\
|
|
2346
2374
|
'1:instance:_agent_env_instances'
|
|
@@ -2385,7 +2413,23 @@ ${commandDescriptions.map((desc) => ` '${desc}'`).join("\n")}
|
|
|
2385
2413
|
esac
|
|
2386
2414
|
}
|
|
2387
2415
|
|
|
2388
|
-
compdef _agent_env agent-env
|
|
2416
|
+
compdef _agent_env agent-env
|
|
2417
|
+
|
|
2418
|
+
# aecd: cd into an instance's host directory
|
|
2419
|
+
# Note: requires eval installation (not fpath autoload) for the function to be available
|
|
2420
|
+
aecd() {
|
|
2421
|
+
local dir
|
|
2422
|
+
dir="$(agent-env path "$@")" || return 1
|
|
2423
|
+
cd "\${dir}" || return 1
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
_aecd() {
|
|
2427
|
+
_arguments \\
|
|
2428
|
+
'--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \\
|
|
2429
|
+
'1:instance:_agent_env_instances'
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
compdef _aecd aecd`;
|
|
2389
2433
|
}
|
|
2390
2434
|
|
|
2391
2435
|
// src/commands/completion.ts
|
|
@@ -2863,6 +2907,31 @@ function parseBranches(result) {
|
|
|
2863
2907
|
}
|
|
2864
2908
|
|
|
2865
2909
|
// src/lib/list-instances.ts
|
|
2910
|
+
async function getInstanceInfo(workspaceName, deps) {
|
|
2911
|
+
const container = deps?.container ?? createContainerLifecycle();
|
|
2912
|
+
const wsFsDeps = deps?.workspaceFsDeps;
|
|
2913
|
+
const stateFsDeps = deps?.stateFsDeps;
|
|
2914
|
+
const wsPath = getWorkspacePathByName(workspaceName, wsFsDeps);
|
|
2915
|
+
const state = await readState(wsPath, stateFsDeps);
|
|
2916
|
+
const dockerAvailable = await container.isDockerAvailable();
|
|
2917
|
+
const containerResult = dockerAvailable ? await container.containerStatus(state.containerName) : null;
|
|
2918
|
+
let status;
|
|
2919
|
+
if (!dockerAvailable || containerResult === null) {
|
|
2920
|
+
status = "unknown";
|
|
2921
|
+
} else if (!containerResult.ok) {
|
|
2922
|
+
status = "unknown";
|
|
2923
|
+
} else if (containerResult.status === "not-found") {
|
|
2924
|
+
status = "orphaned";
|
|
2925
|
+
} else {
|
|
2926
|
+
status = containerResult.status;
|
|
2927
|
+
}
|
|
2928
|
+
return {
|
|
2929
|
+
name: workspaceName,
|
|
2930
|
+
repoSlug: state.repoSlug,
|
|
2931
|
+
purpose: state.purpose,
|
|
2932
|
+
status
|
|
2933
|
+
};
|
|
2934
|
+
}
|
|
2866
2935
|
async function listInstances(deps, opts) {
|
|
2867
2936
|
try {
|
|
2868
2937
|
const container = deps?.container ?? createContainerLifecycle();
|
|
@@ -2988,90 +3057,137 @@ var listCommand = new Command5("list").alias("ps").description("List all instanc
|
|
|
2988
3057
|
await waitUntilExit();
|
|
2989
3058
|
});
|
|
2990
3059
|
|
|
2991
|
-
// src/commands/
|
|
3060
|
+
// src/commands/on.ts
|
|
2992
3061
|
import { Command as Command6 } from "commander";
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3062
|
+
|
|
3063
|
+
// src/lib/interactive-menu.ts
|
|
3064
|
+
async function launchActionLoop(workspaceName, deps, repoSlug) {
|
|
3065
|
+
while (true) {
|
|
3066
|
+
try {
|
|
3067
|
+
const instanceInfo = await deps.getInstanceInfo(workspaceName);
|
|
3068
|
+
const { action, purposeValue } = await deps.renderMenu(instanceInfo);
|
|
3069
|
+
if (action === "exit") {
|
|
3070
|
+
break;
|
|
3071
|
+
}
|
|
3072
|
+
let result;
|
|
3073
|
+
switch (action) {
|
|
3074
|
+
case "attach":
|
|
3075
|
+
result = await deps.attachInstance(workspaceName, repoSlug);
|
|
3076
|
+
break;
|
|
3077
|
+
case "code":
|
|
3078
|
+
result = await deps.codeInstance(workspaceName, repoSlug);
|
|
3079
|
+
break;
|
|
3080
|
+
case "rebuild":
|
|
3081
|
+
result = await deps.rebuildInstance(workspaceName, repoSlug);
|
|
3082
|
+
break;
|
|
3083
|
+
case "set-purpose":
|
|
3084
|
+
result = await deps.setPurpose(workspaceName, purposeValue ?? "", repoSlug);
|
|
3085
|
+
break;
|
|
3086
|
+
}
|
|
3087
|
+
if (!result.ok && result.error) {
|
|
3088
|
+
const { code, message, suggestion } = result.error;
|
|
3089
|
+
console.error(formatError(createError(code, message, suggestion)));
|
|
3090
|
+
}
|
|
3091
|
+
} catch (err) {
|
|
3092
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
3093
|
+
console.error(formatError(createError("ACTION_ERROR", message)));
|
|
3004
3094
|
}
|
|
3005
|
-
});
|
|
3006
|
-
}
|
|
3007
|
-
var purposeCommand = createPurposeCommand();
|
|
3008
|
-
async function handleContainerMode(purposeValue) {
|
|
3009
|
-
const deps = createContainerPurposeDefaultDeps();
|
|
3010
|
-
if (purposeValue === void 0) {
|
|
3011
|
-
const result = await getContainerPurpose(deps);
|
|
3012
|
-
handleGetResult(result);
|
|
3013
|
-
} else {
|
|
3014
|
-
const result = await setContainerPurpose(purposeValue, deps);
|
|
3015
|
-
handleSetResult(result);
|
|
3016
3095
|
}
|
|
3017
3096
|
}
|
|
3018
|
-
async function
|
|
3019
|
-
|
|
3097
|
+
async function launchInstancePicker(deps) {
|
|
3098
|
+
const listResult = await deps.listInstances();
|
|
3099
|
+
if (!listResult.ok) {
|
|
3100
|
+
const { code, message } = listResult.error;
|
|
3020
3101
|
console.error(
|
|
3021
|
-
formatError(
|
|
3022
|
-
createError(
|
|
3023
|
-
"MISSING_ARGUMENT",
|
|
3024
|
-
"Instance name is required when running on the host",
|
|
3025
|
-
"Usage: agent-env purpose <name> [value]"
|
|
3026
|
-
)
|
|
3027
|
-
)
|
|
3102
|
+
formatError(createError(code, message, "Check if ~/.agent-env/workspaces/ is accessible."))
|
|
3028
3103
|
);
|
|
3029
|
-
|
|
3030
|
-
return;
|
|
3104
|
+
return { kind: "error" };
|
|
3031
3105
|
}
|
|
3032
|
-
const
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
const result = await getPurpose(name, deps, repoSlug);
|
|
3036
|
-
handleGetResult(result);
|
|
3037
|
-
} else {
|
|
3038
|
-
const result = await setPurpose(name, value, deps, repoSlug);
|
|
3039
|
-
handleSetResult(result);
|
|
3106
|
+
const selected = await deps.renderPicker(listResult.instances);
|
|
3107
|
+
if (selected === null) {
|
|
3108
|
+
return { kind: "cancelled" };
|
|
3040
3109
|
}
|
|
3110
|
+
return { kind: "selected", name: selected };
|
|
3041
3111
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3112
|
+
|
|
3113
|
+
// src/lib/menu-deps.ts
|
|
3114
|
+
import { render as render2 } from "ink";
|
|
3115
|
+
import React3 from "react";
|
|
3116
|
+
|
|
3117
|
+
// src/components/InteractiveMenu.tsx
|
|
3118
|
+
import { Select, TextInput } from "@inkjs/ui";
|
|
3119
|
+
import { Box as Box2, Text as Text3, useInput } from "ink";
|
|
3120
|
+
import { useState } from "react";
|
|
3121
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
3122
|
+
function statusSymbol(status) {
|
|
3123
|
+
switch (status) {
|
|
3124
|
+
case "running":
|
|
3125
|
+
return "\u25B6";
|
|
3126
|
+
case "stopped":
|
|
3127
|
+
return "\u25A0";
|
|
3128
|
+
case "orphaned":
|
|
3129
|
+
case "not-found":
|
|
3130
|
+
return "\u2717";
|
|
3131
|
+
case "unknown":
|
|
3132
|
+
return "?";
|
|
3052
3133
|
}
|
|
3053
3134
|
}
|
|
3054
|
-
function
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
}
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3135
|
+
function PurposeInput({
|
|
3136
|
+
onSubmit,
|
|
3137
|
+
onCancel
|
|
3138
|
+
}) {
|
|
3139
|
+
useInput((_input, key) => {
|
|
3140
|
+
if (key.escape) {
|
|
3141
|
+
onCancel();
|
|
3142
|
+
}
|
|
3143
|
+
});
|
|
3144
|
+
return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
|
|
3145
|
+
/* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsxs3(Text3, { children: [
|
|
3146
|
+
/* @__PURE__ */ jsx3(Text3, { bold: true, children: "Purpose:" }),
|
|
3147
|
+
" ",
|
|
3148
|
+
/* @__PURE__ */ jsx3(Text3, { color: "gray", children: "(Escape to cancel)" })
|
|
3149
|
+
] }) }),
|
|
3150
|
+
/* @__PURE__ */ jsx3(TextInput, { placeholder: "Enter purpose...", onSubmit })
|
|
3151
|
+
] });
|
|
3152
|
+
}
|
|
3153
|
+
var ACTION_OPTIONS = [
|
|
3154
|
+
{ label: "\u{1F680} Attach to session", value: "attach" },
|
|
3155
|
+
{ label: "\u{1F4BB} Open in VS Code", value: "code" },
|
|
3156
|
+
{ label: "\u{1F6E0} Rebuild container", value: "rebuild" },
|
|
3157
|
+
{ label: "\u{1F4DD} Set Purpose", value: "set-purpose" },
|
|
3158
|
+
{ label: "\u{1F6AA} Exit", value: "exit" }
|
|
3159
|
+
];
|
|
3160
|
+
function InteractiveMenu({
|
|
3161
|
+
instanceInfo,
|
|
3162
|
+
onAction,
|
|
3163
|
+
onSetPurpose
|
|
3164
|
+
}) {
|
|
3165
|
+
const [mode, setMode] = useState("actions");
|
|
3166
|
+
const { name, status, repoSlug, purpose } = instanceInfo;
|
|
3167
|
+
const symbol = statusSymbol(status);
|
|
3168
|
+
const handleActionChange = (value) => {
|
|
3169
|
+
if (value === "set-purpose") {
|
|
3170
|
+
setMode("set-purpose");
|
|
3171
|
+
return;
|
|
3172
|
+
}
|
|
3173
|
+
onAction(value);
|
|
3174
|
+
};
|
|
3175
|
+
const handlePurposeSubmit = (value) => {
|
|
3176
|
+
onSetPurpose(value);
|
|
3177
|
+
};
|
|
3178
|
+
const handlePurposeCancel = () => {
|
|
3179
|
+
setMode("actions");
|
|
3180
|
+
};
|
|
3181
|
+
const headerParts = [name, symbol, repoSlug];
|
|
3182
|
+
if (purpose !== null) {
|
|
3183
|
+
headerParts.push(purpose);
|
|
3067
3184
|
}
|
|
3185
|
+
return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
|
|
3186
|
+
/* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: headerParts.join(" \xB7 ") }) }),
|
|
3187
|
+
mode === "actions" ? /* @__PURE__ */ jsx3(Select, { options: ACTION_OPTIONS, onChange: handleActionChange }) : /* @__PURE__ */ jsx3(PurposeInput, { onSubmit: handlePurposeSubmit, onCancel: handlePurposeCancel })
|
|
3188
|
+
] });
|
|
3068
3189
|
}
|
|
3069
3190
|
|
|
3070
|
-
// src/commands/rebuild.ts
|
|
3071
|
-
import chalk from "chalk";
|
|
3072
|
-
import { Command as Command7 } from "commander";
|
|
3073
|
-
import { createInterface } from "readline";
|
|
3074
|
-
|
|
3075
3191
|
// src/lib/rebuild-instance.ts
|
|
3076
3192
|
import {
|
|
3077
3193
|
access as access4,
|
|
@@ -3341,7 +3457,201 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
|
|
|
3341
3457
|
};
|
|
3342
3458
|
}
|
|
3343
3459
|
|
|
3460
|
+
// src/lib/menu-deps.ts
|
|
3461
|
+
function buildMenuDeps() {
|
|
3462
|
+
return {
|
|
3463
|
+
attachInstance: (wsName, slug) => {
|
|
3464
|
+
const deps = createAttachDefaultDeps();
|
|
3465
|
+
return attachInstance(
|
|
3466
|
+
wsName,
|
|
3467
|
+
deps,
|
|
3468
|
+
() => console.log("Starting container..."),
|
|
3469
|
+
() => {
|
|
3470
|
+
console.log();
|
|
3471
|
+
console.log("Attaching to tmux session...");
|
|
3472
|
+
},
|
|
3473
|
+
slug
|
|
3474
|
+
);
|
|
3475
|
+
},
|
|
3476
|
+
codeInstance: (wsName, slug) => {
|
|
3477
|
+
const deps = createCodeDefaultDeps();
|
|
3478
|
+
return codeInstance(
|
|
3479
|
+
wsName,
|
|
3480
|
+
deps,
|
|
3481
|
+
() => console.log("Starting container..."),
|
|
3482
|
+
() => console.log("Opening VS Code..."),
|
|
3483
|
+
slug
|
|
3484
|
+
);
|
|
3485
|
+
},
|
|
3486
|
+
rebuildInstance: (wsName, slug) => {
|
|
3487
|
+
const rebuildDeps = createRebuildDefaultDeps();
|
|
3488
|
+
const progress = createProgressLine();
|
|
3489
|
+
console.log(`Rebuilding instance '${wsName}'...`);
|
|
3490
|
+
return rebuildInstance(
|
|
3491
|
+
wsName,
|
|
3492
|
+
rebuildDeps,
|
|
3493
|
+
{ force: true, onProgress: progress.update },
|
|
3494
|
+
slug
|
|
3495
|
+
).then((result) => {
|
|
3496
|
+
progress.clear();
|
|
3497
|
+
return result;
|
|
3498
|
+
}).catch((err) => {
|
|
3499
|
+
progress.clear();
|
|
3500
|
+
throw err;
|
|
3501
|
+
});
|
|
3502
|
+
},
|
|
3503
|
+
setPurpose: (wsName, value, slug) => {
|
|
3504
|
+
const deps = createPurposeDefaultDeps();
|
|
3505
|
+
return setPurpose(wsName, value, deps, slug);
|
|
3506
|
+
},
|
|
3507
|
+
getInstanceInfo: (wsName) => getInstanceInfo(wsName),
|
|
3508
|
+
renderMenu: (instanceInfo) => {
|
|
3509
|
+
return new Promise((resolve2) => {
|
|
3510
|
+
const { unmount, waitUntilExit } = render2(
|
|
3511
|
+
React3.createElement(InteractiveMenu, {
|
|
3512
|
+
instanceInfo,
|
|
3513
|
+
onAction: (action) => {
|
|
3514
|
+
unmount();
|
|
3515
|
+
resolve2({ action });
|
|
3516
|
+
},
|
|
3517
|
+
onSetPurpose: (value) => {
|
|
3518
|
+
unmount();
|
|
3519
|
+
resolve2({ action: "set-purpose", purposeValue: value });
|
|
3520
|
+
}
|
|
3521
|
+
})
|
|
3522
|
+
);
|
|
3523
|
+
void waitUntilExit();
|
|
3524
|
+
});
|
|
3525
|
+
}
|
|
3526
|
+
};
|
|
3527
|
+
}
|
|
3528
|
+
|
|
3529
|
+
// src/commands/on.ts
|
|
3530
|
+
var onCommand = new Command6("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) => {
|
|
3531
|
+
if (!process.stdin.isTTY) {
|
|
3532
|
+
console.error(
|
|
3533
|
+
formatError(
|
|
3534
|
+
createError(
|
|
3535
|
+
"TTY_REQUIRED",
|
|
3536
|
+
"The interactive menu requires a terminal (TTY).",
|
|
3537
|
+
"Run this command in an interactive terminal session."
|
|
3538
|
+
)
|
|
3539
|
+
)
|
|
3540
|
+
);
|
|
3541
|
+
process.exit(1);
|
|
3542
|
+
return;
|
|
3543
|
+
}
|
|
3544
|
+
const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
|
|
3545
|
+
const lookup = await resolveInstance(name, repoSlug);
|
|
3546
|
+
if (!lookup.found) {
|
|
3547
|
+
const { code, message, suggestion } = lookup.error;
|
|
3548
|
+
console.error(formatError(createError(code, message, suggestion)));
|
|
3549
|
+
process.exit(1);
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
const { workspaceName } = lookup;
|
|
3553
|
+
const menuDeps = buildMenuDeps();
|
|
3554
|
+
await launchActionLoop(workspaceName, menuDeps, repoSlug);
|
|
3555
|
+
});
|
|
3556
|
+
|
|
3557
|
+
// src/commands/path.ts
|
|
3558
|
+
import { Command as Command7 } from "commander";
|
|
3559
|
+
var pathCommand = new Command7("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) => {
|
|
3560
|
+
const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
|
|
3561
|
+
const result = await resolveInstance(name, repoSlug);
|
|
3562
|
+
if (!result.found) {
|
|
3563
|
+
const { code, message, suggestion } = result.error;
|
|
3564
|
+
console.error(formatError(createError(code, message, suggestion)));
|
|
3565
|
+
process.exit(1);
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
const wsPath = getWorkspacePathByName(result.workspaceName);
|
|
3569
|
+
console.log(wsPath.root);
|
|
3570
|
+
});
|
|
3571
|
+
|
|
3572
|
+
// src/commands/purpose.ts
|
|
3573
|
+
import { Command as Command8 } from "commander";
|
|
3574
|
+
var defaultPurposeCommandDeps = {
|
|
3575
|
+
isInsideContainer
|
|
3576
|
+
};
|
|
3577
|
+
function createPurposeCommand(deps = defaultPurposeCommandDeps) {
|
|
3578
|
+
return new Command8("purpose").description(
|
|
3579
|
+
"Get or set the purpose/label for an instance. Inside a container: no instance name needed (agent-env purpose [value])"
|
|
3580
|
+
).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) => {
|
|
3581
|
+
if (deps.isInsideContainer()) {
|
|
3582
|
+
await handleContainerMode(nameOrValue);
|
|
3583
|
+
} else {
|
|
3584
|
+
await handleHostMode(nameOrValue, value, options?.repo);
|
|
3585
|
+
}
|
|
3586
|
+
});
|
|
3587
|
+
}
|
|
3588
|
+
var purposeCommand = createPurposeCommand();
|
|
3589
|
+
async function handleContainerMode(purposeValue) {
|
|
3590
|
+
const deps = createContainerPurposeDefaultDeps();
|
|
3591
|
+
if (purposeValue === void 0) {
|
|
3592
|
+
const result = await getContainerPurpose(deps);
|
|
3593
|
+
handleGetResult(result);
|
|
3594
|
+
} else {
|
|
3595
|
+
const result = await setContainerPurpose(purposeValue, deps);
|
|
3596
|
+
handleSetResult(result);
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
async function handleHostMode(name, value, repo) {
|
|
3600
|
+
if (!name) {
|
|
3601
|
+
console.error(
|
|
3602
|
+
formatError(
|
|
3603
|
+
createError(
|
|
3604
|
+
"MISSING_ARGUMENT",
|
|
3605
|
+
"Instance name is required when running on the host",
|
|
3606
|
+
"Usage: agent-env purpose <name> [value]"
|
|
3607
|
+
)
|
|
3608
|
+
)
|
|
3609
|
+
);
|
|
3610
|
+
process.exit(1);
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
const repoSlug = await resolveRepoOrExit({ repo, cwd: process.cwd() });
|
|
3614
|
+
const deps = createPurposeDefaultDeps();
|
|
3615
|
+
if (value === void 0) {
|
|
3616
|
+
const result = await getPurpose(name, deps, repoSlug);
|
|
3617
|
+
handleGetResult(result);
|
|
3618
|
+
} else {
|
|
3619
|
+
const result = await setPurpose(name, value, deps, repoSlug);
|
|
3620
|
+
handleSetResult(result);
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
function handleGetResult(result) {
|
|
3624
|
+
if (!result.ok) {
|
|
3625
|
+
const { code, message, suggestion } = result.error;
|
|
3626
|
+
console.error(formatError(createError(code, message, suggestion)));
|
|
3627
|
+
process.exit(1);
|
|
3628
|
+
}
|
|
3629
|
+
if (result.purpose === null) {
|
|
3630
|
+
console.log("(no purpose set)");
|
|
3631
|
+
} else {
|
|
3632
|
+
console.log(result.purpose);
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
function handleSetResult(result) {
|
|
3636
|
+
if (!result.ok) {
|
|
3637
|
+
const { code, message, suggestion } = result.error;
|
|
3638
|
+
console.error(formatError(createError(code, message, suggestion)));
|
|
3639
|
+
process.exit(1);
|
|
3640
|
+
}
|
|
3641
|
+
if (result.cleared) {
|
|
3642
|
+
console.log("Purpose cleared");
|
|
3643
|
+
} else {
|
|
3644
|
+
console.log("Purpose updated");
|
|
3645
|
+
}
|
|
3646
|
+
if (result.warning) {
|
|
3647
|
+
console.warn(`\x1B[33m\u26A0\x1B[0m ${result.warning}`);
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3344
3651
|
// src/commands/rebuild.ts
|
|
3652
|
+
import chalk from "chalk";
|
|
3653
|
+
import { Command as Command9 } from "commander";
|
|
3654
|
+
import { createInterface } from "readline";
|
|
3345
3655
|
function promptForConfirmation(instanceName) {
|
|
3346
3656
|
return new Promise((resolve2) => {
|
|
3347
3657
|
const rl = createInterface({
|
|
@@ -3363,7 +3673,7 @@ Any active sessions will be lost. Continue? (y/N) `,
|
|
|
3363
3673
|
});
|
|
3364
3674
|
});
|
|
3365
3675
|
}
|
|
3366
|
-
var rebuildCommand = new
|
|
3676
|
+
var rebuildCommand = new Command9("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(
|
|
3367
3677
|
async (name, options) => {
|
|
3368
3678
|
const deps = createRebuildDefaultDeps();
|
|
3369
3679
|
const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
|
|
@@ -3416,7 +3726,7 @@ var rebuildCommand = new Command7("rebuild").description("Rebuild an instance by
|
|
|
3416
3726
|
|
|
3417
3727
|
// src/commands/remove.ts
|
|
3418
3728
|
import chalk3 from "chalk";
|
|
3419
|
-
import { Command as
|
|
3729
|
+
import { Command as Command10 } from "commander";
|
|
3420
3730
|
import { createInterface as createInterface2 } from "readline";
|
|
3421
3731
|
|
|
3422
3732
|
// src/lib/audit-log.ts
|
|
@@ -3735,7 +4045,7 @@ async function resolveConfirmation(name, options) {
|
|
|
3735
4045
|
}
|
|
3736
4046
|
return "typed-name";
|
|
3737
4047
|
}
|
|
3738
|
-
var removeCommand = new
|
|
4048
|
+
var removeCommand = new Command10("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(
|
|
3739
4049
|
"--yes",
|
|
3740
4050
|
"Skip confirmation prompt for --force (DANGEROUS: skips all safety prompts, for scripts only)"
|
|
3741
4051
|
).action(async (name, options) => {
|
|
@@ -3798,8 +4108,8 @@ var removeCommand = new Command8("remove").description("Remove an instance with
|
|
|
3798
4108
|
});
|
|
3799
4109
|
|
|
3800
4110
|
// src/commands/repos.ts
|
|
3801
|
-
import { Command as
|
|
3802
|
-
var reposCommand = new
|
|
4111
|
+
import { Command as Command11 } from "commander";
|
|
4112
|
+
var reposCommand = new Command11("repos").description("List tracked repositories").option("--json", "Output in JSON format").action(async (options) => {
|
|
3803
4113
|
const result = await listRepos();
|
|
3804
4114
|
if (!result.ok) {
|
|
3805
4115
|
const error = createError(
|
|
@@ -3850,7 +4160,7 @@ var reposCommand = new Command9("repos").description("List tracked repositories"
|
|
|
3850
4160
|
});
|
|
3851
4161
|
|
|
3852
4162
|
// src/commands/setup-audio.ts
|
|
3853
|
-
import { Command as
|
|
4163
|
+
import { Command as Command12 } from "commander";
|
|
3854
4164
|
import { copyFile, mkdir as mkdir11, readFile as readFile12, writeFile as writeFile10, access as access5 } from "fs/promises";
|
|
3855
4165
|
import { homedir as homedir9, platform } from "os";
|
|
3856
4166
|
|
|
@@ -3956,7 +4266,7 @@ function createDefaultSetupAudioDeps() {
|
|
|
3956
4266
|
access: (path) => access5(path)
|
|
3957
4267
|
};
|
|
3958
4268
|
}
|
|
3959
|
-
var setupAudioCommand = new
|
|
4269
|
+
var setupAudioCommand = new Command12("setup-audio").description("Configure macOS PulseAudio for audio passthrough to containers").action(async () => {
|
|
3960
4270
|
const deps = createDefaultSetupAudioDeps();
|
|
3961
4271
|
const result = await setupAudio(deps);
|
|
3962
4272
|
if (!result.ok) {
|
|
@@ -3976,7 +4286,7 @@ var setupAudioCommand = new Command10("setup-audio").description("Configure macO
|
|
|
3976
4286
|
});
|
|
3977
4287
|
|
|
3978
4288
|
// src/commands/tmux-restore.ts
|
|
3979
|
-
import { Command as
|
|
4289
|
+
import { Command as Command13 } from "commander";
|
|
3980
4290
|
import { execSync } from "child_process";
|
|
3981
4291
|
import { join as join12 } from "path";
|
|
3982
4292
|
|
|
@@ -4096,7 +4406,7 @@ async function executeTmuxRestore() {
|
|
|
4096
4406
|
}
|
|
4097
4407
|
}
|
|
4098
4408
|
}
|
|
4099
|
-
var tmuxRestoreCommand = new
|
|
4409
|
+
var tmuxRestoreCommand = new Command13("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
|
|
4100
4410
|
try {
|
|
4101
4411
|
await executeTmuxRestore();
|
|
4102
4412
|
} catch {
|
|
@@ -4104,7 +4414,7 @@ var tmuxRestoreCommand = new Command11("tmux-restore").description("Restore tmux
|
|
|
4104
4414
|
});
|
|
4105
4415
|
|
|
4106
4416
|
// src/commands/tmux-save.ts
|
|
4107
|
-
import { Command as
|
|
4417
|
+
import { Command as Command14 } from "commander";
|
|
4108
4418
|
import { execSync as execSync2 } from "child_process";
|
|
4109
4419
|
import { unlink as unlink2 } from "fs/promises";
|
|
4110
4420
|
import { join as join13 } from "path";
|
|
@@ -4182,7 +4492,7 @@ async function executeTmuxSave() {
|
|
|
4182
4492
|
const pruned = pruneStaleEntries(panesState, activePaneIds);
|
|
4183
4493
|
await writePanesState(panesPath, pruned);
|
|
4184
4494
|
}
|
|
4185
|
-
var tmuxSaveCommand = new
|
|
4495
|
+
var tmuxSaveCommand = new Command14("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
|
|
4186
4496
|
try {
|
|
4187
4497
|
await executeTmuxSave();
|
|
4188
4498
|
} catch {
|
|
@@ -4190,7 +4500,7 @@ var tmuxSaveCommand = new Command12("tmux-save").description("Save current tmux
|
|
|
4190
4500
|
});
|
|
4191
4501
|
|
|
4192
4502
|
// src/commands/tmux-status.ts
|
|
4193
|
-
import { Command as
|
|
4503
|
+
import { Command as Command15 } from "commander";
|
|
4194
4504
|
|
|
4195
4505
|
// src/lib/tmux-status.ts
|
|
4196
4506
|
import { readFile as readFile14 } from "fs/promises";
|
|
@@ -4231,7 +4541,7 @@ var defaultDeps3 = {
|
|
|
4231
4541
|
statePath: CONTAINER_STATE_PATH
|
|
4232
4542
|
};
|
|
4233
4543
|
function createTmuxStatusCommand(deps = defaultDeps3) {
|
|
4234
|
-
return new
|
|
4544
|
+
return new Command15("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
|
|
4235
4545
|
if (!deps.isInsideContainer()) {
|
|
4236
4546
|
console.log("?");
|
|
4237
4547
|
return;
|
|
@@ -4242,179 +4552,103 @@ function createTmuxStatusCommand(deps = defaultDeps3) {
|
|
|
4242
4552
|
}
|
|
4243
4553
|
var tmuxStatusCommand = createTmuxStatusCommand();
|
|
4244
4554
|
|
|
4245
|
-
// src/
|
|
4246
|
-
import
|
|
4247
|
-
import
|
|
4248
|
-
import {
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4555
|
+
// src/lib/update-check.ts
|
|
4556
|
+
import chalk4 from "chalk";
|
|
4557
|
+
import * as fs from "fs/promises";
|
|
4558
|
+
import { dirname as dirname4 } from "path";
|
|
4559
|
+
function normaliseVersion(version2) {
|
|
4560
|
+
const withoutBuild = version2.split("+")[0];
|
|
4561
|
+
const withoutPre = withoutBuild.split("-")[0];
|
|
4562
|
+
return withoutPre;
|
|
4563
|
+
}
|
|
4564
|
+
function isNewerVersion(current, registry) {
|
|
4565
|
+
const normCurrent = normaliseVersion(current);
|
|
4566
|
+
const normRegistry = normaliseVersion(registry);
|
|
4567
|
+
const currentParts = normCurrent.split(".").map(Number);
|
|
4568
|
+
const registryParts = normRegistry.split(".").map(Number);
|
|
4569
|
+
const len = Math.max(currentParts.length, registryParts.length);
|
|
4570
|
+
for (let i = 0; i < len; i++) {
|
|
4571
|
+
const c = currentParts[i] ?? 0;
|
|
4572
|
+
const r = registryParts[i] ?? 0;
|
|
4573
|
+
if (r > c) return true;
|
|
4574
|
+
if (r < c) return false;
|
|
4575
|
+
}
|
|
4576
|
+
return false;
|
|
4577
|
+
}
|
|
4578
|
+
async function readCache(cachePath, readFileFn) {
|
|
4579
|
+
try {
|
|
4580
|
+
const raw = await readFileFn(cachePath, "utf-8");
|
|
4581
|
+
const parsed = JSON.parse(raw);
|
|
4582
|
+
if (parsed !== null && typeof parsed === "object" && "lastCheck" in parsed && "latestVersion" in parsed && typeof parsed.lastCheck === "number" && typeof parsed.latestVersion === "string") {
|
|
4583
|
+
return parsed;
|
|
4584
|
+
}
|
|
4585
|
+
return null;
|
|
4586
|
+
} catch {
|
|
4587
|
+
return null;
|
|
4264
4588
|
}
|
|
4265
4589
|
}
|
|
4266
|
-
function
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
if (!purpose) return "";
|
|
4272
|
-
if (maxLen <= 3) return "";
|
|
4273
|
-
if (purpose.length <= maxLen) return purpose;
|
|
4274
|
-
return purpose.slice(0, maxLen - 3) + "...";
|
|
4275
|
-
}
|
|
4276
|
-
function buildOptionLabel(instance, terminalWidth) {
|
|
4277
|
-
const name = instance.name;
|
|
4278
|
-
const status = statusSymbol(instance.status);
|
|
4279
|
-
const git = gitIndicatorString(instance.gitState);
|
|
4280
|
-
const fixedWidth = name.length + COLUMN_PADDING + status.length + COLUMN_PADDING + git.length + COLUMN_PADDING;
|
|
4281
|
-
const availableForPurpose = Math.max(0, terminalWidth - fixedWidth - SELECT_PREFIX_WIDTH);
|
|
4282
|
-
const purpose = truncatePurpose(instance.purpose, availableForPurpose);
|
|
4283
|
-
const parts = [name, status, git];
|
|
4284
|
-
if (purpose) {
|
|
4285
|
-
parts.push(purpose);
|
|
4286
|
-
}
|
|
4287
|
-
return parts.join(" ");
|
|
4288
|
-
}
|
|
4289
|
-
function ActionMenu({
|
|
4290
|
-
instanceName,
|
|
4291
|
-
onSelectAction
|
|
4292
|
-
}) {
|
|
4293
|
-
const options = [
|
|
4294
|
-
{ label: "\u{1F680} Attach to session", value: "attach" },
|
|
4295
|
-
{ label: "\u{1F6E0} Rebuild container", value: "rebuild" },
|
|
4296
|
-
{ label: "\u{1F4DD} Show purpose", value: "purpose" },
|
|
4297
|
-
{ label: "\u{1F5D1} Remove instance", value: "remove" }
|
|
4298
|
-
];
|
|
4299
|
-
return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
|
|
4300
|
-
/* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsxs3(Text3, { children: [
|
|
4301
|
-
"Manage",
|
|
4302
|
-
" ",
|
|
4303
|
-
/* @__PURE__ */ jsx3(Text3, { bold: true, color: "cyan", children: instanceName }),
|
|
4304
|
-
":"
|
|
4305
|
-
] }) }),
|
|
4306
|
-
/* @__PURE__ */ jsx3(Select, { options, onChange: onSelectAction })
|
|
4307
|
-
] });
|
|
4308
|
-
}
|
|
4309
|
-
function InteractiveMenu({
|
|
4310
|
-
instances,
|
|
4311
|
-
onAction,
|
|
4312
|
-
terminalWidth
|
|
4313
|
-
}) {
|
|
4314
|
-
const [selectedInstance, setSelectedInstance] = useState(null);
|
|
4315
|
-
const width = terminalWidth ?? process.stdout.columns ?? 80;
|
|
4316
|
-
if (instances.length === 0) {
|
|
4317
|
-
return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
|
|
4318
|
-
/* @__PURE__ */ jsx3(Text3, { children: "No instances found." }),
|
|
4319
|
-
/* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
|
|
4320
|
-
"Create one with: agent-env create ",
|
|
4321
|
-
"<name>",
|
|
4322
|
-
" --repo ",
|
|
4323
|
-
"<url>"
|
|
4324
|
-
] })
|
|
4325
|
-
] });
|
|
4326
|
-
}
|
|
4327
|
-
if (selectedInstance) {
|
|
4328
|
-
return /* @__PURE__ */ jsx3(
|
|
4329
|
-
ActionMenu,
|
|
4330
|
-
{
|
|
4331
|
-
instanceName: selectedInstance,
|
|
4332
|
-
onSelectAction: (action) => onAction(action, selectedInstance)
|
|
4333
|
-
}
|
|
4334
|
-
);
|
|
4590
|
+
async function writeCache(cachePath, data, mkdirFn, writeFileFn) {
|
|
4591
|
+
try {
|
|
4592
|
+
await mkdirFn(dirname4(cachePath), { recursive: true });
|
|
4593
|
+
await writeFileFn(cachePath, JSON.stringify(data), "utf-8");
|
|
4594
|
+
} catch {
|
|
4335
4595
|
}
|
|
4336
|
-
const options = instances.map((instance) => ({
|
|
4337
|
-
label: buildOptionLabel(instance, width),
|
|
4338
|
-
value: instance.name
|
|
4339
|
-
}));
|
|
4340
|
-
return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
|
|
4341
|
-
/* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: "Select an instance:" }) }),
|
|
4342
|
-
/* @__PURE__ */ jsx3(Select, { options, onChange: setSelectedInstance })
|
|
4343
|
-
] });
|
|
4344
4596
|
}
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
ok: false,
|
|
4352
|
-
error: {
|
|
4353
|
-
code: listResult.error.code,
|
|
4354
|
-
message: listResult.error.message,
|
|
4355
|
-
suggestion: "Check if ~/.agent-env/workspaces/ is accessible."
|
|
4356
|
-
}
|
|
4357
|
-
};
|
|
4358
|
-
}
|
|
4359
|
-
if (listResult.instances.length === 0) {
|
|
4360
|
-
deps.renderMenu(listResult.instances, () => {
|
|
4361
|
-
});
|
|
4362
|
-
return { ok: true, action: "empty" };
|
|
4363
|
-
}
|
|
4364
|
-
let selectedName;
|
|
4365
|
-
let selectedAction;
|
|
4366
|
-
const selectionPromise = new Promise((resolve2) => {
|
|
4367
|
-
const { waitUntilExit } = deps.renderMenu(
|
|
4368
|
-
listResult.instances,
|
|
4369
|
-
(action2, name2) => {
|
|
4370
|
-
selectedAction = action2;
|
|
4371
|
-
selectedName = name2;
|
|
4372
|
-
resolve2({ action: action2, name: name2 });
|
|
4373
|
-
}
|
|
4374
|
-
);
|
|
4375
|
-
void waitUntilExit().then(() => {
|
|
4376
|
-
if (!selectedName || !selectedAction) {
|
|
4377
|
-
resolve2({ action: "attach", name: "" });
|
|
4378
|
-
}
|
|
4597
|
+
async function fetchLatestVersion(packageName, fetchFn) {
|
|
4598
|
+
try {
|
|
4599
|
+
const url = `https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`;
|
|
4600
|
+
const response = await fetchFn(url, {
|
|
4601
|
+
headers: { Accept: "application/json" },
|
|
4602
|
+
signal: AbortSignal.timeout(5e3)
|
|
4379
4603
|
});
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
return { ok: true, action: "empty" };
|
|
4384
|
-
}
|
|
4385
|
-
switch (action) {
|
|
4386
|
-
case "attach": {
|
|
4387
|
-
const attachDeps = deps.createAttachDeps();
|
|
4388
|
-
const attachResult = await deps.attachInstance(name, attachDeps);
|
|
4389
|
-
if (!attachResult.ok) return { ok: false, error: attachResult.error };
|
|
4390
|
-
return { ok: true, action: "attached", instanceName: name };
|
|
4604
|
+
const json = await response.json();
|
|
4605
|
+
if (json !== null && typeof json === "object" && "version" in json && typeof json.version === "string") {
|
|
4606
|
+
return json.version;
|
|
4391
4607
|
}
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4608
|
+
return null;
|
|
4609
|
+
} catch {
|
|
4610
|
+
return null;
|
|
4611
|
+
}
|
|
4612
|
+
}
|
|
4613
|
+
function formatUpdateMessage(currentVersion, latestVersion, packageName) {
|
|
4614
|
+
const normCurrent = normaliseVersion(currentVersion);
|
|
4615
|
+
const line1 = chalk4.yellow(`Update available: ${normCurrent} -> ${latestVersion}`);
|
|
4616
|
+
const line2 = chalk4.cyan(`Run: pnpm add -g ${packageName}`);
|
|
4617
|
+
return `${line1}
|
|
4618
|
+
${line2}`;
|
|
4619
|
+
}
|
|
4620
|
+
async function checkForUpdate(opts) {
|
|
4621
|
+
const {
|
|
4622
|
+
currentVersion,
|
|
4623
|
+
packageName,
|
|
4624
|
+
cachePath,
|
|
4625
|
+
cacheTtlMs,
|
|
4626
|
+
fetchFn = fetch,
|
|
4627
|
+
readFile: readFile16 = (p, enc) => fs.readFile(p, enc),
|
|
4628
|
+
writeFile: writeFile13 = (p, d, enc) => fs.writeFile(p, d, enc),
|
|
4629
|
+
mkdir: mkdir14 = (p, o) => fs.mkdir(p, o),
|
|
4630
|
+
now = () => Date.now()
|
|
4631
|
+
} = opts;
|
|
4632
|
+
const currentTime = now();
|
|
4633
|
+
const cache = await readCache(cachePath, readFile16);
|
|
4634
|
+
let latestVersion = null;
|
|
4635
|
+
const isCacheFresh = cache !== null && currentTime - cache.lastCheck < cacheTtlMs;
|
|
4636
|
+
if (isCacheFresh) {
|
|
4637
|
+
latestVersion = cache.latestVersion;
|
|
4638
|
+
} else {
|
|
4639
|
+
latestVersion = await fetchLatestVersion(packageName, fetchFn);
|
|
4640
|
+
if (latestVersion !== null) {
|
|
4641
|
+
await writeCache(cachePath, { lastCheck: currentTime, latestVersion }, mkdir14, writeFile13);
|
|
4412
4642
|
}
|
|
4413
4643
|
}
|
|
4644
|
+
if (latestVersion !== null && isNewerVersion(currentVersion, latestVersion)) {
|
|
4645
|
+
return formatUpdateMessage(currentVersion, latestVersion, packageName);
|
|
4646
|
+
}
|
|
4647
|
+
return null;
|
|
4414
4648
|
}
|
|
4415
4649
|
|
|
4416
4650
|
// src/cli.ts
|
|
4417
|
-
var __dirname =
|
|
4651
|
+
var __dirname = dirname5(fileURLToPath2(import.meta.url));
|
|
4418
4652
|
var isLinked = existsSync(resolve(__dirname, "..", "..", "..", "pnpm-workspace.yaml"));
|
|
4419
4653
|
var isBakedDev = resolve(__dirname, "..").startsWith("/opt/agent-env-dev");
|
|
4420
4654
|
var version = package_default.version + (isLinked ? "+local" : isBakedDev ? "+dev" : "");
|
|
@@ -4422,10 +4656,12 @@ program.name("agent-env").description("CLI for creating isolated, AI-ready devel
|
|
|
4422
4656
|
program.addCommand(createCommand);
|
|
4423
4657
|
program.addCommand(listCommand);
|
|
4424
4658
|
program.addCommand(attachCommand);
|
|
4659
|
+
program.addCommand(pathCommand);
|
|
4425
4660
|
program.addCommand(codeCommand);
|
|
4426
4661
|
program.addCommand(rebuildCommand);
|
|
4427
4662
|
program.addCommand(removeCommand);
|
|
4428
4663
|
program.addCommand(purposeCommand);
|
|
4664
|
+
program.addCommand(onCommand);
|
|
4429
4665
|
program.addCommand(reposCommand);
|
|
4430
4666
|
program.addCommand(tmuxStatusCommand);
|
|
4431
4667
|
program.addCommand(tmuxSaveCommand);
|
|
@@ -4448,29 +4684,56 @@ program.action(async () => {
|
|
|
4448
4684
|
program.help();
|
|
4449
4685
|
return;
|
|
4450
4686
|
}
|
|
4451
|
-
const
|
|
4687
|
+
const { Select: Select2 } = await import("@inkjs/ui");
|
|
4688
|
+
const pickerResult = await launchInstancePicker({
|
|
4452
4689
|
listInstances,
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4690
|
+
renderPicker: (instances) => {
|
|
4691
|
+
if (instances.length === 0) {
|
|
4692
|
+
console.log("No instances found.");
|
|
4693
|
+
console.log("Create one with: agent-env create <name> --repo <url>");
|
|
4694
|
+
return Promise.resolve(null);
|
|
4695
|
+
}
|
|
4696
|
+
return new Promise((resolve2) => {
|
|
4697
|
+
const options = instances.map((inst) => ({
|
|
4698
|
+
label: inst.name,
|
|
4699
|
+
value: inst.name
|
|
4700
|
+
}));
|
|
4701
|
+
const { unmount } = render3(
|
|
4702
|
+
React4.createElement(() => {
|
|
4703
|
+
return React4.createElement(Select2, {
|
|
4704
|
+
options,
|
|
4705
|
+
onChange: (value) => {
|
|
4706
|
+
unmount();
|
|
4707
|
+
resolve2(value);
|
|
4708
|
+
}
|
|
4709
|
+
});
|
|
4710
|
+
})
|
|
4711
|
+
);
|
|
4712
|
+
});
|
|
4464
4713
|
}
|
|
4465
4714
|
});
|
|
4466
|
-
if (
|
|
4467
|
-
const { code, message, suggestion } = result.error;
|
|
4468
|
-
console.error(formatError(createError(code, message, suggestion)));
|
|
4715
|
+
if (pickerResult.kind === "error") {
|
|
4469
4716
|
process.exitCode = 1;
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4717
|
+
return;
|
|
4718
|
+
}
|
|
4719
|
+
if (pickerResult.kind === "cancelled") {
|
|
4720
|
+
return;
|
|
4474
4721
|
}
|
|
4722
|
+
const menuDeps = buildMenuDeps();
|
|
4723
|
+
await launchActionLoop(pickerResult.name, menuDeps);
|
|
4475
4724
|
});
|
|
4476
|
-
|
|
4725
|
+
var shouldCheck = !!process.stderr.isTTY && !isInsideContainer() && !isLinked && !isBakedDev;
|
|
4726
|
+
var updateCheckPromise = shouldCheck ? checkForUpdate({
|
|
4727
|
+
currentVersion: package_default.version,
|
|
4728
|
+
packageName: package_default.name,
|
|
4729
|
+
cachePath: join14(homedir10(), ".agent-env", "update-check.json"),
|
|
4730
|
+
cacheTtlMs: 36e5
|
|
4731
|
+
}) : Promise.resolve(null);
|
|
4732
|
+
async function main() {
|
|
4733
|
+
await program.parseAsync();
|
|
4734
|
+
const updateMessage = await updateCheckPromise;
|
|
4735
|
+
if (updateMessage) {
|
|
4736
|
+
process.stderr.write(updateMessage + "\n");
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zookanalytics/agent-env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "CLI for creating isolated, AI-ready development environments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"ink-testing-library": "^4.0.0",
|
|
44
44
|
"tsup": "^8.5.1",
|
|
45
45
|
"tsx": "^4.21.0",
|
|
46
|
-
"@zookanalytics/shared": "0.1.
|
|
46
|
+
"@zookanalytics/shared": "0.1.1"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"dev": "tsx src/cli.ts",
|