@zookanalytics/agent-env 1.2.1 → 1.2.3
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/README.md +14 -0
- package/bin/agent-env.js +27 -1
- package/completions/_agent-env +148 -0
- package/completions/agent-env.bash +124 -0
- package/dist/InstanceList-GLFIEBZM.js +137 -0
- package/dist/MenuContainer-UYYYFIFW.js +225 -0
- package/dist/build-EHN2NQPH.js +43 -0
- package/dist/chunk-JSBRDJBE.js +30 -0
- package/dist/chunk-VDILAY23.js +3651 -0
- package/dist/chunk-Y37YO5ZL.js +682 -0
- package/dist/cli.js +239 -5321
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -205,6 +205,20 @@ agent-env purpose <name> # Get current purpose
|
|
|
205
205
|
agent-env purpose <name> "Working on feature X" # Set purpose
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
+
## Shell Completion
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# ~/.zshrc (after compinit)
|
|
212
|
+
eval "$(agent-env completion zsh)"
|
|
213
|
+
|
|
214
|
+
# ~/.bashrc
|
|
215
|
+
eval "$(agent-env completion bash)"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
This completes subcommands, options, instance names and repo slugs, and defines `aecd` (`cd` into an instance's host directory).
|
|
219
|
+
|
|
220
|
+
The same scripts ship as static files in the package's `completions/` directory (`_agent-env` for zsh, `agent-env.bash` for bash) if you prefer to `source` them or add the directory to `fpath`.
|
|
221
|
+
|
|
208
222
|
## License
|
|
209
223
|
|
|
210
224
|
MIT
|
package/bin/agent-env.js
CHANGED
|
@@ -1,2 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
// Fast path for `agent-env completion <shell>`.
|
|
3
|
+
//
|
|
4
|
+
// `eval "$(agent-env completion zsh)"` runs on every new shell, so this must not
|
|
5
|
+
// load the CLI bundle (commander, execa, ...). The completion scripts are static
|
|
6
|
+
// text, generated at build time from the real CLI by scripts/generate-completions.mjs,
|
|
7
|
+
// so we just print the pre-generated file. Anything else — including a missing
|
|
8
|
+
// file, an unsupported shell, or extra args like --help — falls through to the CLI.
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
10
|
+
|
|
11
|
+
const COMPLETION_FILES = { bash: 'agent-env.bash', zsh: '_agent-env' };
|
|
12
|
+
|
|
13
|
+
const args = process.argv.slice(2);
|
|
14
|
+
let handled = false;
|
|
15
|
+
|
|
16
|
+
if (args.length === 2 && args[0] === 'completion' && Object.hasOwn(COMPLETION_FILES, args[1])) {
|
|
17
|
+
try {
|
|
18
|
+
const file = new URL(`../completions/${COMPLETION_FILES[args[1]]}`, import.meta.url);
|
|
19
|
+
process.stdout.write(readFileSync(file));
|
|
20
|
+
handled = true;
|
|
21
|
+
} catch {
|
|
22
|
+
// Pre-generated script unavailable — let the full CLI generate it.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!handled) {
|
|
27
|
+
await import('../dist/cli.js');
|
|
28
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#compdef agent-env aecd
|
|
2
|
+
# agent-env zsh completion script
|
|
3
|
+
# Install: eval "$(agent-env completion zsh)"
|
|
4
|
+
|
|
5
|
+
_agent_env_repos() {
|
|
6
|
+
local ws_dir=~/.agent-env/workspaces
|
|
7
|
+
local -a repos
|
|
8
|
+
local entry base repo
|
|
9
|
+
if [[ -d "${ws_dir}" ]]; then
|
|
10
|
+
for entry in "${ws_dir}"/*/; do
|
|
11
|
+
[[ -d "${entry}" ]] || continue
|
|
12
|
+
base="${entry%/}"
|
|
13
|
+
base="${base##*/}"
|
|
14
|
+
repo="${base%-*}"
|
|
15
|
+
[[ "${repo}" != "${base}" ]] && repos+=("${repo}")
|
|
16
|
+
done
|
|
17
|
+
fi
|
|
18
|
+
repos=(${(u)repos})
|
|
19
|
+
_describe 'repo' repos
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_agent_env_instances() {
|
|
23
|
+
local ws_dir=~/.agent-env/workspaces
|
|
24
|
+
local -a instances
|
|
25
|
+
local entry base
|
|
26
|
+
if [[ -d "${ws_dir}" ]]; then
|
|
27
|
+
for entry in "${ws_dir}"/*/; do
|
|
28
|
+
[[ -d "${entry}" ]] || continue
|
|
29
|
+
base="${entry%/}"
|
|
30
|
+
base="${base##*/}"
|
|
31
|
+
instances+=("${base}")
|
|
32
|
+
done
|
|
33
|
+
fi
|
|
34
|
+
instances=(${(u)instances})
|
|
35
|
+
_describe 'instance' instances
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_agent_env() {
|
|
39
|
+
local -a commands
|
|
40
|
+
commands=(
|
|
41
|
+
'create:Create a new isolated development environment'
|
|
42
|
+
'env:Manage repo-level env files copied into workspaces'
|
|
43
|
+
'list:List all instances with status'
|
|
44
|
+
'ps:List all instances with status (alias)'
|
|
45
|
+
'attach:Attach to an instance'\''s tmux session'
|
|
46
|
+
'path:Print the host directory path for an instance'
|
|
47
|
+
'code:Open an instance in VS Code via Dev Containers'
|
|
48
|
+
'rebuild:Rebuild an instance by recreating its container'
|
|
49
|
+
'shutdown:Gracefully shut down an instance (save tmux state, stop container)'
|
|
50
|
+
'remove:Remove an instance with safety checks'
|
|
51
|
+
'purpose:Get or set the purpose/label for an instance. Inside a container: no instance name needed (agent-env purpose [value])'
|
|
52
|
+
'on:Open the interactive menu for an instance'
|
|
53
|
+
'repos:List tracked repositories'
|
|
54
|
+
'tmux-status:Output formatted instance status for tmux status bar (container only)'
|
|
55
|
+
'completion:Generate shell completion script for bash or zsh'
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
_arguments -C \
|
|
59
|
+
'--help[Show help]' \
|
|
60
|
+
'--version[Show version]' \
|
|
61
|
+
'1:command:->command' \
|
|
62
|
+
'*::arg:->args'
|
|
63
|
+
|
|
64
|
+
case $state in
|
|
65
|
+
command)
|
|
66
|
+
_describe 'command' commands
|
|
67
|
+
;;
|
|
68
|
+
args)
|
|
69
|
+
case $words[1] in
|
|
70
|
+
on|code|attach|path|purpose)
|
|
71
|
+
_arguments \
|
|
72
|
+
'--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \
|
|
73
|
+
'1:instance:_agent_env_instances'
|
|
74
|
+
;;
|
|
75
|
+
create)
|
|
76
|
+
_arguments \
|
|
77
|
+
'--repo[Repository URL]:url:' \
|
|
78
|
+
'--purpose[Set instance purpose]:text:' \
|
|
79
|
+
'--attach[Attach after creation]'
|
|
80
|
+
;;
|
|
81
|
+
list|ps)
|
|
82
|
+
_arguments \
|
|
83
|
+
'--json[Output as JSON]' \
|
|
84
|
+
'--repo[Filter by repo slug]:slug:_agent_env_repos'
|
|
85
|
+
;;
|
|
86
|
+
rebuild)
|
|
87
|
+
_arguments \
|
|
88
|
+
'--force[Rebuild running container]' \
|
|
89
|
+
'--yes[Skip confirmation prompt]' \
|
|
90
|
+
'--no-pull[Skip pulling fresh images]' \
|
|
91
|
+
'--use-cache[Allow Docker layer cache]' \
|
|
92
|
+
'--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \
|
|
93
|
+
'1:instance:_agent_env_instances'
|
|
94
|
+
;;
|
|
95
|
+
shutdown)
|
|
96
|
+
_arguments \
|
|
97
|
+
'--yes[Skip confirmation prompt]' \
|
|
98
|
+
'--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \
|
|
99
|
+
'1:instance:_agent_env_instances'
|
|
100
|
+
;;
|
|
101
|
+
remove)
|
|
102
|
+
_arguments \
|
|
103
|
+
'--force[Force removal]' \
|
|
104
|
+
'--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \
|
|
105
|
+
'1:instance:_agent_env_instances'
|
|
106
|
+
;;
|
|
107
|
+
repos)
|
|
108
|
+
_arguments \
|
|
109
|
+
'--json[Output as JSON]'
|
|
110
|
+
;;
|
|
111
|
+
tmux-status)
|
|
112
|
+
;;
|
|
113
|
+
completion)
|
|
114
|
+
_describe 'shell' '(bash zsh)'
|
|
115
|
+
;;
|
|
116
|
+
esac
|
|
117
|
+
;;
|
|
118
|
+
esac
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
compdef _agent_env agent-env
|
|
122
|
+
|
|
123
|
+
# aecd: cd into an instance's host directory
|
|
124
|
+
# Note: with fpath autoload this is defined on the first Tab after agent-env or aecd;
|
|
125
|
+
# eval or source the script to have it available immediately
|
|
126
|
+
aecd() {
|
|
127
|
+
local dir
|
|
128
|
+
dir="$(agent-env path "$@")" || return 1
|
|
129
|
+
cd "${dir}" || return 1
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_aecd() {
|
|
133
|
+
_arguments \
|
|
134
|
+
'--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \
|
|
135
|
+
'1:instance:_agent_env_instances'
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
compdef _aecd aecd
|
|
139
|
+
|
|
140
|
+
# When autoloaded from fpath, this file is the body of the _agent-env function and
|
|
141
|
+
# is running because of a Tab press: the definitions above are now loaded, so
|
|
142
|
+
# complete the current word right away instead of waiting for the next Tab.
|
|
143
|
+
if [[ "${funcstack[1]}" == "_agent-env" ]]; then
|
|
144
|
+
case "${service}" in
|
|
145
|
+
aecd) _aecd "$@" ;;
|
|
146
|
+
*) _agent_env "$@" ;;
|
|
147
|
+
esac
|
|
148
|
+
fi
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# agent-env bash completion script
|
|
3
|
+
# Install: eval "$(agent-env completion bash)"
|
|
4
|
+
|
|
5
|
+
_agent_env_repos() {
|
|
6
|
+
local ws_dir=~/.agent-env/workspaces
|
|
7
|
+
local entry base repo
|
|
8
|
+
if [[ -d "${ws_dir}" ]]; then
|
|
9
|
+
for entry in "${ws_dir}"/*/; do
|
|
10
|
+
[[ -d "${entry}" ]] || continue
|
|
11
|
+
base="${entry%/}"
|
|
12
|
+
base="${base##*/}"
|
|
13
|
+
repo="${base%-*}"
|
|
14
|
+
[[ "${repo}" != "${base}" ]] && echo "${repo}"
|
|
15
|
+
done | sort -u
|
|
16
|
+
fi
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_agent_env_instances() {
|
|
20
|
+
local ws_dir=~/.agent-env/workspaces
|
|
21
|
+
local entry base
|
|
22
|
+
if [[ -d "${ws_dir}" ]]; then
|
|
23
|
+
for entry in "${ws_dir}"/*/; do
|
|
24
|
+
[[ -d "${entry}" ]] || continue
|
|
25
|
+
base="${entry%/}"
|
|
26
|
+
base="${base##*/}"
|
|
27
|
+
echo "${base}"
|
|
28
|
+
done | sort -u
|
|
29
|
+
fi
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_agent_env_completions() {
|
|
33
|
+
local cur prev commands
|
|
34
|
+
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
35
|
+
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
36
|
+
commands="create env list ps attach path code rebuild shutdown remove purpose on repos tmux-status completion"
|
|
37
|
+
|
|
38
|
+
# Complete commands at position 1
|
|
39
|
+
if [[ ${COMP_CWORD} -eq 1 ]]; then
|
|
40
|
+
COMPREPLY=($(compgen -W "${commands}" -- "${cur}"))
|
|
41
|
+
return 0
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
# Complete based on command
|
|
45
|
+
case "${prev}" in
|
|
46
|
+
on|code|attach|path|purpose)
|
|
47
|
+
local instances
|
|
48
|
+
instances="$(_agent_env_instances)"
|
|
49
|
+
COMPREPLY=($(compgen -W "--repo ${instances}" -- "${cur}"))
|
|
50
|
+
return 0
|
|
51
|
+
;;
|
|
52
|
+
create)
|
|
53
|
+
COMPREPLY=($(compgen -W "--repo --purpose --attach" -- "${cur}"))
|
|
54
|
+
return 0
|
|
55
|
+
;;
|
|
56
|
+
list|ps)
|
|
57
|
+
COMPREPLY=($(compgen -W "--json --repo" -- "${cur}"))
|
|
58
|
+
return 0
|
|
59
|
+
;;
|
|
60
|
+
rebuild)
|
|
61
|
+
local instances
|
|
62
|
+
instances="$(_agent_env_instances)"
|
|
63
|
+
COMPREPLY=($(compgen -W "--force --yes --no-pull --use-cache --repo ${instances}" -- "${cur}"))
|
|
64
|
+
return 0
|
|
65
|
+
;;
|
|
66
|
+
shutdown)
|
|
67
|
+
local instances
|
|
68
|
+
instances="$(_agent_env_instances)"
|
|
69
|
+
COMPREPLY=($(compgen -W "--yes --repo ${instances}" -- "${cur}"))
|
|
70
|
+
return 0
|
|
71
|
+
;;
|
|
72
|
+
remove)
|
|
73
|
+
local instances
|
|
74
|
+
instances="$(_agent_env_instances)"
|
|
75
|
+
COMPREPLY=($(compgen -W "--force --repo ${instances}" -- "${cur}"))
|
|
76
|
+
return 0
|
|
77
|
+
;;
|
|
78
|
+
repos)
|
|
79
|
+
COMPREPLY=($(compgen -W "--json" -- "${cur}"))
|
|
80
|
+
return 0
|
|
81
|
+
;;
|
|
82
|
+
tmux-status)
|
|
83
|
+
# no arguments or options
|
|
84
|
+
return 0
|
|
85
|
+
;;
|
|
86
|
+
completion)
|
|
87
|
+
COMPREPLY=($(compgen -W "bash zsh" -- "${cur}"))
|
|
88
|
+
return 0
|
|
89
|
+
;;
|
|
90
|
+
--repo)
|
|
91
|
+
COMPREPLY=($(compgen -W "$(_agent_env_repos)" -- "${cur}"))
|
|
92
|
+
return 0
|
|
93
|
+
;;
|
|
94
|
+
esac
|
|
95
|
+
|
|
96
|
+
return 0
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
complete -F _agent_env_completions agent-env
|
|
100
|
+
|
|
101
|
+
# aecd: cd into an instance's host directory
|
|
102
|
+
aecd() {
|
|
103
|
+
local dir
|
|
104
|
+
dir="$(agent-env path "$@")" || return 1
|
|
105
|
+
cd "${dir}" || return 1
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_aecd_completions() {
|
|
109
|
+
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
110
|
+
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
111
|
+
local i has_repo=0
|
|
112
|
+
for ((i=1; i < COMP_CWORD; i++)); do
|
|
113
|
+
[[ "${COMP_WORDS[i]}" == "--repo" ]] && has_repo=1 && break
|
|
114
|
+
done
|
|
115
|
+
if [[ "${prev}" == "--repo" ]]; then
|
|
116
|
+
COMPREPLY=($(compgen -W "$(_agent_env_repos)" -- "${cur}"))
|
|
117
|
+
elif [[ "${cur}" == -* && ${has_repo} -eq 0 ]]; then
|
|
118
|
+
COMPREPLY=($(compgen -W "--repo" -- "${cur}"))
|
|
119
|
+
else
|
|
120
|
+
COMPREPLY=($(compgen -W "$(_agent_env_instances)" -- "${cur}"))
|
|
121
|
+
fi
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
complete -F _aecd_completions aecd
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import "./chunk-JSBRDJBE.js";
|
|
2
|
+
|
|
3
|
+
// src/components/InstanceList.tsx
|
|
4
|
+
import { Box, Text as Text2 } from "ink";
|
|
5
|
+
import { format as timeago } from "timeago.js";
|
|
6
|
+
|
|
7
|
+
// src/components/StatusIndicator.tsx
|
|
8
|
+
import { Text } from "ink";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
function formatGitIndicators(gitState) {
|
|
11
|
+
if (!gitState || !gitState.ok) {
|
|
12
|
+
return [{ symbol: "?", color: "gray" }];
|
|
13
|
+
}
|
|
14
|
+
const state = gitState.state;
|
|
15
|
+
if (state.isClean) {
|
|
16
|
+
return [{ symbol: "\u2713", color: "green" }];
|
|
17
|
+
}
|
|
18
|
+
const indicators = [];
|
|
19
|
+
if (state.hasStaged || state.hasUnstaged || state.hasUntracked) {
|
|
20
|
+
indicators.push({ symbol: "\u25CF", color: "yellow" });
|
|
21
|
+
}
|
|
22
|
+
if (state.unpushedBranches.length > 0) {
|
|
23
|
+
indicators.push({ symbol: "\u2191", color: "blue" });
|
|
24
|
+
}
|
|
25
|
+
if (state.neverPushedBranches.length > 0) {
|
|
26
|
+
indicators.push({
|
|
27
|
+
symbol: `\u26A0 ${state.neverPushedBranches.length}`,
|
|
28
|
+
color: "red"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (indicators.length === 0) {
|
|
32
|
+
indicators.push({ symbol: "\u25CF", color: "yellow" });
|
|
33
|
+
}
|
|
34
|
+
return indicators;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/components/InstanceList.tsx
|
|
38
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
39
|
+
function statusColor(status) {
|
|
40
|
+
switch (status) {
|
|
41
|
+
case "running":
|
|
42
|
+
return "green";
|
|
43
|
+
case "stopped":
|
|
44
|
+
return "yellow";
|
|
45
|
+
case "orphaned":
|
|
46
|
+
return "red";
|
|
47
|
+
case "unknown":
|
|
48
|
+
return "gray";
|
|
49
|
+
case "not-found":
|
|
50
|
+
return "red";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function statusLabel(status, dockerAvailable) {
|
|
54
|
+
if (!dockerAvailable && status === "unknown") {
|
|
55
|
+
return "unknown (Docker unavailable)";
|
|
56
|
+
}
|
|
57
|
+
return status;
|
|
58
|
+
}
|
|
59
|
+
function formatLastAttached(lastAttached) {
|
|
60
|
+
if (!lastAttached) return "-";
|
|
61
|
+
try {
|
|
62
|
+
return timeago(lastAttached);
|
|
63
|
+
} catch {
|
|
64
|
+
return "-";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function formatPurpose(purpose) {
|
|
68
|
+
if (!purpose) return "-";
|
|
69
|
+
if (purpose.length > 30) {
|
|
70
|
+
return purpose.slice(0, 27) + "...";
|
|
71
|
+
}
|
|
72
|
+
return purpose;
|
|
73
|
+
}
|
|
74
|
+
function formatSSH(ssh) {
|
|
75
|
+
if (!ssh) return "-";
|
|
76
|
+
if (ssh.length > 40) {
|
|
77
|
+
return ssh.slice(0, 37) + "...";
|
|
78
|
+
}
|
|
79
|
+
return ssh;
|
|
80
|
+
}
|
|
81
|
+
function InstanceList({
|
|
82
|
+
instances,
|
|
83
|
+
dockerAvailable
|
|
84
|
+
}) {
|
|
85
|
+
if (instances.length === 0) {
|
|
86
|
+
return /* @__PURE__ */ jsxs2(Box, { flexDirection: "column", children: [
|
|
87
|
+
/* @__PURE__ */ jsx2(Text2, { children: "No instances found." }),
|
|
88
|
+
/* @__PURE__ */ jsxs2(Text2, { color: "gray", children: [
|
|
89
|
+
"Create one with: agent-env create ",
|
|
90
|
+
"<name>",
|
|
91
|
+
" --repo ",
|
|
92
|
+
"<url>"
|
|
93
|
+
] })
|
|
94
|
+
] });
|
|
95
|
+
}
|
|
96
|
+
const augmentedInstances = instances.map((instance) => {
|
|
97
|
+
const indicators = formatGitIndicators(instance.gitState);
|
|
98
|
+
const indicatorText = indicators.map((ind) => ind.symbol).join(" ");
|
|
99
|
+
return { ...instance, indicators, indicatorText };
|
|
100
|
+
});
|
|
101
|
+
const nameWidth = Math.max(4, ...augmentedInstances.map((i) => i.name.length)) + 2;
|
|
102
|
+
const repoWidth = Math.max(4, ...augmentedInstances.map((i) => i.repoSlug.length)) + 2;
|
|
103
|
+
const statusWidth = Math.max(6, ...augmentedInstances.map((i) => statusLabel(i.status, dockerAvailable).length)) + 2;
|
|
104
|
+
const gitWidth = Math.max(3, ...augmentedInstances.map((i) => i.indicatorText.length)) + 2;
|
|
105
|
+
const lastAttachedWidth = Math.max(13, ...augmentedInstances.map((i) => formatLastAttached(i.lastAttached).length)) + 2;
|
|
106
|
+
const sshWidth = Math.max(4, ...augmentedInstances.map((i) => formatSSH(i.sshConnection).length)) + 2;
|
|
107
|
+
return /* @__PURE__ */ jsxs2(Box, { flexDirection: "column", children: [
|
|
108
|
+
/* @__PURE__ */ jsxs2(Box, { children: [
|
|
109
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, children: pad("NAME", nameWidth) }),
|
|
110
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, children: pad("REPO", repoWidth) }),
|
|
111
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, children: pad("STATUS", statusWidth) }),
|
|
112
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, children: pad("GIT", gitWidth) }),
|
|
113
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, children: pad("LAST ATTACHED", lastAttachedWidth) }),
|
|
114
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, children: pad("SSH", sshWidth) }),
|
|
115
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, children: "PURPOSE" })
|
|
116
|
+
] }),
|
|
117
|
+
augmentedInstances.map((instance) => /* @__PURE__ */ jsxs2(Box, { children: [
|
|
118
|
+
/* @__PURE__ */ jsx2(Text2, { children: pad(instance.name, nameWidth) }),
|
|
119
|
+
/* @__PURE__ */ jsx2(Text2, { color: "blue", children: pad(instance.repoSlug, repoWidth) }),
|
|
120
|
+
/* @__PURE__ */ jsx2(Text2, { color: statusColor(instance.status), children: pad(statusLabel(instance.status, dockerAvailable), statusWidth) }),
|
|
121
|
+
/* @__PURE__ */ jsx2(Box, { width: gitWidth, children: instance.indicators.map((ind, idx) => /* @__PURE__ */ jsxs2(Text2, { color: ind.color, children: [
|
|
122
|
+
idx > 0 ? " " : "",
|
|
123
|
+
ind.symbol
|
|
124
|
+
] }, idx)) }),
|
|
125
|
+
/* @__PURE__ */ jsx2(Text2, { children: pad(formatLastAttached(instance.lastAttached), lastAttachedWidth) }),
|
|
126
|
+
/* @__PURE__ */ jsx2(Text2, { color: "cyan", children: pad(formatSSH(instance.sshConnection), sshWidth) }),
|
|
127
|
+
/* @__PURE__ */ jsx2(Text2, { color: "gray", children: formatPurpose(instance.purpose) })
|
|
128
|
+
] }, instance.name)),
|
|
129
|
+
!dockerAvailable && /* @__PURE__ */ jsx2(Box, { marginTop: 1, children: /* @__PURE__ */ jsx2(Text2, { color: "yellow", children: "\u26A0 Docker is not available. Container status cannot be determined." }) })
|
|
130
|
+
] });
|
|
131
|
+
}
|
|
132
|
+
function pad(str, width) {
|
|
133
|
+
return str.padEnd(width);
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
InstanceList
|
|
137
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
detectDriftState,
|
|
3
|
+
getCurrentVersion,
|
|
4
|
+
isNewerVersion
|
|
5
|
+
} from "./chunk-Y37YO5ZL.js";
|
|
6
|
+
import {
|
|
7
|
+
Select,
|
|
8
|
+
TextInput
|
|
9
|
+
} from "./chunk-VDILAY23.js";
|
|
10
|
+
import "./chunk-JSBRDJBE.js";
|
|
11
|
+
|
|
12
|
+
// src/components/MenuContainer.tsx
|
|
13
|
+
import { useEffect, useState as useState2 } from "react";
|
|
14
|
+
|
|
15
|
+
// src/components/InteractiveMenu.tsx
|
|
16
|
+
import { Box, Text, useInput } from "ink";
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
function statusSymbol(status) {
|
|
20
|
+
switch (status) {
|
|
21
|
+
case "running":
|
|
22
|
+
return "\u25B6";
|
|
23
|
+
case "stopped":
|
|
24
|
+
return "\u25A0";
|
|
25
|
+
case "orphaned":
|
|
26
|
+
case "not-found":
|
|
27
|
+
return "\u2717";
|
|
28
|
+
case "unknown":
|
|
29
|
+
return "?";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function PurposeInput({
|
|
33
|
+
onSubmit,
|
|
34
|
+
onCancel
|
|
35
|
+
}) {
|
|
36
|
+
useInput((_input, key) => {
|
|
37
|
+
if (key.escape) {
|
|
38
|
+
onCancel();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
42
|
+
/* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { children: [
|
|
43
|
+
/* @__PURE__ */ jsx(Text, { bold: true, children: "Purpose:" }),
|
|
44
|
+
" ",
|
|
45
|
+
/* @__PURE__ */ jsx(Text, { color: "gray", children: "(Escape to cancel)" })
|
|
46
|
+
] }) }),
|
|
47
|
+
/* @__PURE__ */ jsx(TextInput, { placeholder: "Enter purpose...", onSubmit })
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
var BASE_ACTION_OPTIONS = [
|
|
51
|
+
{ label: "\u{1F680} Attach to session", value: "attach" },
|
|
52
|
+
{ label: "\u{1F4BB} Open in VS Code", value: "code" },
|
|
53
|
+
{ label: "\u{1F6E0} Rebuild container", value: "rebuild" },
|
|
54
|
+
{ label: "\u23F9 Shutdown container", value: "shutdown" },
|
|
55
|
+
{ label: "\u{1F4DD} Set Purpose", value: "set-purpose" }
|
|
56
|
+
];
|
|
57
|
+
var EXIT_OPTION = { label: "\u{1F6AA} Exit", value: "exit" };
|
|
58
|
+
var RESTART_REQUIRED_OPTION = {
|
|
59
|
+
label: "\u267B\uFE0F Restart menu (required \u2014 agent-env was upgraded)",
|
|
60
|
+
value: "restart"
|
|
61
|
+
};
|
|
62
|
+
var CHECK_FOR_UPDATES_OPTION = {
|
|
63
|
+
label: "\u{1F504} Check for updates",
|
|
64
|
+
value: "check-updates"
|
|
65
|
+
};
|
|
66
|
+
function hasNewerInstall(driftState) {
|
|
67
|
+
if (!driftState?.installedVersion) return false;
|
|
68
|
+
return isNewerVersion(driftState.currentVersion, driftState.installedVersion);
|
|
69
|
+
}
|
|
70
|
+
function formatImageTagForLabel(image) {
|
|
71
|
+
const noDigest = image.split("@")[0];
|
|
72
|
+
const m = /:([^:/]+)$/.exec(noDigest);
|
|
73
|
+
if (!m) return "refresh";
|
|
74
|
+
const tag = m[1];
|
|
75
|
+
if (/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(tag)) return `v${tag}`;
|
|
76
|
+
return "refresh";
|
|
77
|
+
}
|
|
78
|
+
function buildActionOptions(driftState) {
|
|
79
|
+
if (driftState?.packageMoved) {
|
|
80
|
+
return [RESTART_REQUIRED_OPTION, ...BASE_ACTION_OPTIONS, EXIT_OPTION];
|
|
81
|
+
}
|
|
82
|
+
if (driftState && hasNewerInstall(driftState)) {
|
|
83
|
+
const label = `\u267B\uFE0F Restart menu (v${driftState.installedVersion} installed)`;
|
|
84
|
+
return [{ label, value: "restart" }, ...BASE_ACTION_OPTIONS, EXIT_OPTION];
|
|
85
|
+
}
|
|
86
|
+
if (driftState?.imageDrift) {
|
|
87
|
+
const imageLabel = formatImageTagForLabel(driftState.imageDrift.expectedImage);
|
|
88
|
+
const updatedOptions = BASE_ACTION_OPTIONS.map(
|
|
89
|
+
(o) => o.value === "rebuild" ? { label: `\u{1F6E0} Rebuild container (image ${imageLabel} available)`, value: "rebuild" } : o
|
|
90
|
+
);
|
|
91
|
+
return [...updatedOptions, CHECK_FOR_UPDATES_OPTION, EXIT_OPTION];
|
|
92
|
+
}
|
|
93
|
+
if (driftState?.updateMessage) {
|
|
94
|
+
return [...BASE_ACTION_OPTIONS, CHECK_FOR_UPDATES_OPTION, EXIT_OPTION];
|
|
95
|
+
}
|
|
96
|
+
if (driftState) {
|
|
97
|
+
return [...BASE_ACTION_OPTIONS, CHECK_FOR_UPDATES_OPTION, EXIT_OPTION];
|
|
98
|
+
}
|
|
99
|
+
return [...BASE_ACTION_OPTIONS, EXIT_OPTION];
|
|
100
|
+
}
|
|
101
|
+
function DriftBanner({ driftState }) {
|
|
102
|
+
if (driftState.packageMoved) {
|
|
103
|
+
return /* @__PURE__ */ jsxs(Box, { marginBottom: 1, flexDirection: "column", children: [
|
|
104
|
+
/* @__PURE__ */ jsx(Text, { color: "red", bold: true, children: "\u26A0 agent-env was upgraded since this menu started." }),
|
|
105
|
+
/* @__PURE__ */ jsx(Text, { color: "red", children: "Rebuild and other commands will fail until you restart the menu." })
|
|
106
|
+
] });
|
|
107
|
+
}
|
|
108
|
+
if (hasNewerInstall(driftState)) {
|
|
109
|
+
return /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: "yellow", children: [
|
|
110
|
+
"agent-env v",
|
|
111
|
+
driftState.installedVersion,
|
|
112
|
+
" is installed \u2014 restart to use it"
|
|
113
|
+
] }) });
|
|
114
|
+
}
|
|
115
|
+
if (driftState.imageDrift) {
|
|
116
|
+
return /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: "cyan", children: [
|
|
117
|
+
"Container image will refresh on next rebuild: ",
|
|
118
|
+
driftState.imageDrift.configuredImage,
|
|
119
|
+
" \u2192",
|
|
120
|
+
" ",
|
|
121
|
+
driftState.imageDrift.expectedImage
|
|
122
|
+
] }) });
|
|
123
|
+
}
|
|
124
|
+
if (driftState.updateMessage) {
|
|
125
|
+
return /* @__PURE__ */ jsx(Box, { marginBottom: 1, flexDirection: "column", children: /* @__PURE__ */ jsx(Text, { color: "yellow", children: driftState.updateMessage }) });
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
function InteractiveMenu({
|
|
130
|
+
instanceInfo,
|
|
131
|
+
onAction,
|
|
132
|
+
onSetPurpose,
|
|
133
|
+
driftState
|
|
134
|
+
}) {
|
|
135
|
+
const [mode, setMode] = useState("actions");
|
|
136
|
+
const { name, status, repoSlug, purpose } = instanceInfo;
|
|
137
|
+
const symbol = statusSymbol(status);
|
|
138
|
+
const handleActionChange = (value) => {
|
|
139
|
+
if (value === "set-purpose") {
|
|
140
|
+
setMode("set-purpose");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
onAction(value);
|
|
144
|
+
};
|
|
145
|
+
const handlePurposeSubmit = (value) => {
|
|
146
|
+
onSetPurpose(value);
|
|
147
|
+
};
|
|
148
|
+
const handlePurposeCancel = () => {
|
|
149
|
+
setMode("actions");
|
|
150
|
+
};
|
|
151
|
+
const headerParts = [name, symbol, repoSlug];
|
|
152
|
+
if (purpose !== null) {
|
|
153
|
+
headerParts.push(purpose);
|
|
154
|
+
}
|
|
155
|
+
const actionOptions = buildActionOptions(driftState);
|
|
156
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
157
|
+
driftState ? /* @__PURE__ */ jsx(DriftBanner, { driftState }) : null,
|
|
158
|
+
/* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { bold: true, children: headerParts.join(" \xB7 ") }) }),
|
|
159
|
+
mode === "actions" ? /* @__PURE__ */ jsx(
|
|
160
|
+
Select,
|
|
161
|
+
{
|
|
162
|
+
options: actionOptions,
|
|
163
|
+
onChange: handleActionChange,
|
|
164
|
+
visibleOptionCount: actionOptions.length
|
|
165
|
+
}
|
|
166
|
+
) : /* @__PURE__ */ jsx(PurposeInput, { onSubmit: handlePurposeSubmit, onCancel: handlePurposeCancel })
|
|
167
|
+
] });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/components/MenuContainer.tsx
|
|
171
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
172
|
+
var DRIFT_POLL_INTERVAL_MS = 10 * 60 * 1e3;
|
|
173
|
+
function makeNeutralDriftState() {
|
|
174
|
+
return {
|
|
175
|
+
packageMoved: false,
|
|
176
|
+
updateMessage: null,
|
|
177
|
+
installedVersion: null,
|
|
178
|
+
currentVersion: getCurrentVersion(),
|
|
179
|
+
imageDrift: null
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function MenuContainer({
|
|
183
|
+
instanceInfo,
|
|
184
|
+
onAction,
|
|
185
|
+
onSetPurpose,
|
|
186
|
+
initialDriftState,
|
|
187
|
+
detectDriftStateFn = detectDriftState,
|
|
188
|
+
pollIntervalMs = DRIFT_POLL_INTERVAL_MS
|
|
189
|
+
}) {
|
|
190
|
+
const [driftState, setDriftState] = useState2(
|
|
191
|
+
initialDriftState ?? makeNeutralDriftState()
|
|
192
|
+
);
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
let cancelled = false;
|
|
195
|
+
const runProbe = async () => {
|
|
196
|
+
try {
|
|
197
|
+
const next = await detectDriftStateFn(instanceInfo.name);
|
|
198
|
+
if (!cancelled) {
|
|
199
|
+
setDriftState(next);
|
|
200
|
+
}
|
|
201
|
+
} catch {
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
void runProbe();
|
|
205
|
+
const handle = setInterval(() => {
|
|
206
|
+
void runProbe();
|
|
207
|
+
}, pollIntervalMs);
|
|
208
|
+
return () => {
|
|
209
|
+
cancelled = true;
|
|
210
|
+
clearInterval(handle);
|
|
211
|
+
};
|
|
212
|
+
}, [detectDriftStateFn, pollIntervalMs, instanceInfo.name]);
|
|
213
|
+
return /* @__PURE__ */ jsx2(
|
|
214
|
+
InteractiveMenu,
|
|
215
|
+
{
|
|
216
|
+
instanceInfo,
|
|
217
|
+
onAction,
|
|
218
|
+
onSetPurpose,
|
|
219
|
+
driftState
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
MenuContainer
|
|
225
|
+
};
|