devzone 0.59.0 → 1.1.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/.devcontainer/agent-erreurs.sh +72 -56
- package/.devcontainer/agent-etat-json.sh +45 -43
- package/.devcontainer/agent-modele.sh +3 -3
- package/.devcontainer/agent-session.sh +122 -125
- package/.devcontainer/agent-workspace.sh +53 -53
- package/.devcontainer/agent.sh +107 -109
- package/.devcontainer/argocd/argocd.sh +4 -16
- package/.devcontainer/catalogue/app.sh +1 -1
- package/.devcontainer/catalogue/catalogue-veilleur.sh +2 -2
- package/.devcontainer/catalogue/mysql/mysql.sh +1 -13
- package/.devcontainer/catalogue.sh +4 -16
- package/.devcontainer/cluster.sh +1 -1
- package/.devcontainer/command-aliases.sh +78 -114
- package/.devcontainer/devzone +34 -48
- package/.devcontainer/etat-json.sh +162 -162
- package/.devcontainer/etat-verrou.sh +25 -24
- package/.devcontainer/etat.sh +122 -123
- package/.devcontainer/gitlab/gitlab.sh +1 -13
- package/.devcontainer/gitlab/installation.sh +3 -3
- package/.devcontainer/gitlab/secrets.sh +1 -1
- package/.devcontainer/gitlab/test-gitlab.sh +1 -1
- package/.devcontainer/help.sh +4 -3
- package/.devcontainer/memoire.sh +58 -58
- package/.devcontainer/metrics-server.sh +52 -51
- package/.devcontainer/paquets.sh +0 -12
- package/.devcontainer/password.sh +88 -87
- package/.devcontainer/ports-auto.sh +6 -6
- package/.devcontainer/ports.sh +1 -13
- package/.devcontainer/postgres/postgres.sh +1 -13
- package/.devcontainer/services-admin.sh +3 -3
- package/.devcontainer/skills/devzone/SKILL.md +2 -2
- package/README.md +13 -3
- package/charts/devzone-workspace/templates/statefulset.yaml +3 -0
- package/manage/devzone +61 -569
- package/manage/scripts/argocd-services.sh +2 -2
- package/manage/scripts/devzone-create.sh +138 -0
- package/manage/scripts/devzone-manifest.sh +171 -0
- package/manage/scripts/devzone-update.sh +222 -0
- package/manage/scripts/migrer.sh +2 -6
- package/manage/scripts/workspace-aliases.sh +4 -31
- package/manage/workspace.sh +7 -12
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Session
|
|
3
|
-
#
|
|
2
|
+
# Session of the agent supervisor: opencode configuration, shared rank, journal,
|
|
3
|
+
# state (#328). Library sourced by agent.sh: no command is launched here.
|
|
4
4
|
|
|
5
|
-
#
|
|
6
|
-
|
|
5
|
+
# Journal path of a folder in workspace/.agents/: outside the repo, ignored by git.
|
|
6
|
+
journal_of() {
|
|
7
7
|
echo "$RACINE/workspace/.agents/$(basename "$1").log"
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
#
|
|
10
|
+
# Last write time (epoch), GNU (stat -c) or BSD/macOS (stat -f).
|
|
11
11
|
mtime() {
|
|
12
12
|
if stat -c %Y "$1" >/dev/null 2>&1; then
|
|
13
13
|
stat -c %Y "$1"
|
|
@@ -16,8 +16,8 @@ mtime() {
|
|
|
16
16
|
fi
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
#
|
|
20
|
-
|
|
19
|
+
# Readable UTC date of an epoch, GNU then BSD date: shown by devzone agent etat.
|
|
20
|
+
utc_time() {
|
|
21
21
|
if date -u -d "@$1" '+%Y-%m-%d %H:%M:%S' >/dev/null 2>&1; then
|
|
22
22
|
date -u -d "@$1" '+%Y-%m-%d %H:%M:%S'
|
|
23
23
|
else
|
|
@@ -25,127 +25,124 @@ heure() {
|
|
|
25
25
|
fi
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
verrou_tracer() {
|
|
28
|
+
# Lock trace in the agent journal ($AGENT_JOURNAL, set by agent.sh): one line when
|
|
29
|
+
# taken and one when released, with the clock and the pid, to diagnose simultaneous
|
|
30
|
+
# launches of the rank in CI (#421). Without a journal, nothing is written. An
|
|
31
|
+
# optional mention (second argument) gives the path, the age or the pid read.
|
|
32
|
+
lock_trace() {
|
|
34
33
|
local d
|
|
35
34
|
[ -n "${AGENT_JOURNAL:-}" ] || return 0
|
|
36
35
|
d="$(date +%s.%N 2>/dev/null)" || d=""
|
|
37
36
|
case "$d" in "" | *N*) d="$(date +%s)" ;; esac
|
|
38
|
-
echo "===
|
|
37
|
+
echo "=== lock $1 $d pid $$${2:+ $2}" >>"$AGENT_JOURNAL"
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
local
|
|
51
|
-
|
|
40
|
+
# Shared rank lock: two simultaneous launches must not start on the same model.
|
|
41
|
+
# mkdir is atomic and present everywhere (flock is missing on macOS); only the age
|
|
42
|
+
# of the lock decides (#377), the pid written being a diagnostic detail only: a pid
|
|
43
|
+
# read from another container of the volume does not exist here.
|
|
44
|
+
# When flock exists, the rank section is also taken under its lock on rang.lock
|
|
45
|
+
# (#421): if two mkdir succeeded, flock still serializes the read and the write of
|
|
46
|
+
# the rank. Each branch is traced (mkdir failure, purge, taking) to establish in CI
|
|
47
|
+
# which of the two launches succeeded in mkdir.
|
|
48
|
+
lock_take() {
|
|
49
|
+
local end age lock_pid
|
|
50
|
+
end=$(( $(date +%s) + ${DEVZONE_AGENT_VERROU_MAX:-10} ))
|
|
52
51
|
while ! mkdir "$AGENT_ETAT/verrou" 2>/dev/null; do
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
# sinon on attend puis on renonce (code 1).
|
|
52
|
+
# A lock is orphaned only by its age: the rank is held for a few milliseconds,
|
|
53
|
+
# 30 s can only be a stop to take over; otherwise wait, then give up (code 1).
|
|
56
54
|
age=""
|
|
57
55
|
if [ -d "$AGENT_ETAT/verrou" ]; then
|
|
58
56
|
age="$(mtime "$AGENT_ETAT/verrou" 2>/dev/null)" || age=""
|
|
59
57
|
fi
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
lock_pid="$(cat "$AGENT_ETAT/verrou/pid" 2>/dev/null)" || lock_pid=""
|
|
59
|
+
lock_trace "mkdir failed" "age=${age:-unknown} lock-pid=${lock_pid:-none}"
|
|
62
60
|
if [ -n "$age" ] && [ "$(( $(date +%s) - age ))" -gt 30 ]; then
|
|
63
61
|
rm -f "$AGENT_ETAT/verrou/pid"
|
|
64
62
|
if rmdir "$AGENT_ETAT/verrou" 2>/dev/null; then
|
|
65
|
-
|
|
63
|
+
lock_trace "purged" "age=$age"
|
|
66
64
|
continue
|
|
67
65
|
fi
|
|
68
66
|
fi
|
|
69
|
-
if [ "$(date +%s)" -ge "$
|
|
67
|
+
if [ "$(date +%s)" -ge "$end" ]; then return 1; fi
|
|
70
68
|
sleep 1
|
|
71
69
|
done
|
|
72
|
-
# pid
|
|
73
|
-
#
|
|
70
|
+
# pid before flock: the other agent never removes the folder while we wait on
|
|
71
|
+
# rang.lock, otherwise our pid write would fail with ENOENT.
|
|
74
72
|
echo "$$" >"$AGENT_ETAT/verrou/pid"
|
|
75
73
|
if command -v flock >/dev/null 2>&1; then
|
|
76
|
-
# exec
|
|
77
|
-
# 3.2
|
|
74
|
+
# exec in an if makes a failure a condition instead of killing the shell
|
|
75
|
+
# (bash 3.2 and GNU alike); without flock, mkdir remains the only guard (macOS).
|
|
78
76
|
if { exec 9>"$AGENT_ETAT/rang.lock"; } && flock -w "${DEVZONE_AGENT_VERROU_MAX:-10}" 9; then
|
|
79
|
-
|
|
77
|
+
AGENT_LOCK_FLOCK=1
|
|
80
78
|
else
|
|
81
|
-
|
|
79
|
+
lock_release
|
|
82
80
|
return 1
|
|
83
81
|
fi
|
|
84
82
|
fi
|
|
85
|
-
|
|
83
|
+
lock_trace taken "path=$AGENT_ETAT/verrou"
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
|
|
86
|
+
# Releases the shared rank taken by lock_take: removes the pid, then the folder, only
|
|
87
|
+
# when this lock belongs to the calling agent (pid in the file == $$). A lock held by
|
|
88
|
+
# another agent is never removed here. flock (#421) is released in every case, even
|
|
89
|
+
# when the pid read does not match: otherwise the next caller would stay blocked on
|
|
90
|
+
# rang.lock.
|
|
91
|
+
lock_release() {
|
|
94
92
|
local pid
|
|
95
93
|
pid="$(cat "$AGENT_ETAT/verrou/pid" 2>/dev/null)" || pid=""
|
|
96
94
|
if [ "$pid" = "$$" ]; then
|
|
97
95
|
rm -f "$AGENT_ETAT/verrou/pid"
|
|
98
96
|
rmdir "$AGENT_ETAT/verrou" 2>/dev/null || true
|
|
99
|
-
|
|
97
|
+
lock_trace released
|
|
100
98
|
fi
|
|
101
|
-
if [ "${
|
|
99
|
+
if [ "${AGENT_LOCK_FLOCK:-0}" = 1 ]; then
|
|
102
100
|
flock -u 9 2>/dev/null || true
|
|
103
101
|
exec 9>&-
|
|
104
|
-
|
|
102
|
+
AGENT_LOCK_FLOCK=0
|
|
105
103
|
fi
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
# Takes the shared rank and returns the start of the rotation (#421). The rank
|
|
109
|
-
# advances only when no requested model is available (#420). The
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
local
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if [ "$
|
|
117
|
-
if modele_rang_avance; then echo $((
|
|
118
|
-
|
|
119
|
-
echo "===
|
|
120
|
-
echo "$
|
|
107
|
+
# advances only when no requested model is available (#420). The "=== rank" line is
|
|
108
|
+
# written to the journal in every case. Called in a command substitution: the lock is
|
|
109
|
+
# taken and released in that same process.
|
|
110
|
+
rank_take() {
|
|
111
|
+
local state="$1" journal="$2" start
|
|
112
|
+
lock_take || return 1
|
|
113
|
+
start=$(( $(cat "$state/rang" 2>/dev/null || echo 0) % ${#FREE_MODELS[@]} ))
|
|
114
|
+
if [ "$PAUSE_RANK" -gt 0 ]; then sleep "$PAUSE_RANK"; fi
|
|
115
|
+
if modele_rang_avance; then echo $(( start + 1 )) >"$state/rang"; fi
|
|
116
|
+
lock_release
|
|
117
|
+
echo "=== rank $(( start + 1 ))/${#FREE_MODELS[@]}" >>"$journal"
|
|
118
|
+
echo "$start"
|
|
121
119
|
}
|
|
122
120
|
|
|
123
|
-
#
|
|
124
|
-
#
|
|
125
|
-
|
|
126
|
-
local
|
|
127
|
-
|
|
121
|
+
# Turns permission.edit into an object and adds, last, one deny per rights file (#361):
|
|
122
|
+
# the last matching rule wins, so the caller cannot remove it.
|
|
123
|
+
rights_edit_deny() {
|
|
124
|
+
local patterns f
|
|
125
|
+
patterns="[]"
|
|
128
126
|
for f in "${DROITS_AGENT[@]}"; do
|
|
129
|
-
|
|
127
|
+
patterns="$(jq -c --arg f "$f" '. + [$f, "**/" + $f]' <<<"$patterns")"
|
|
130
128
|
done
|
|
131
|
-
jq -ce --argjson
|
|
129
|
+
jq -ce --argjson patterns "$patterns" '
|
|
132
130
|
(.permission.edit // "allow") as $e |
|
|
133
131
|
(if ($e | type) == "object" then $e else {"*": $e} end) as $o |
|
|
134
|
-
.permission.edit = (reduce $
|
|
132
|
+
.permission.edit = (reduce $patterns[] as $k ($o; del(.[$k])) + ($patterns | map({(.): "deny"}) | add))
|
|
135
133
|
' <<<"$1"
|
|
136
134
|
}
|
|
137
135
|
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
-
#
|
|
144
|
-
# été remplacé par un lien (#210).
|
|
136
|
+
# Safe configuration: agent.json by default, completed by OPENCODE_CONFIG_CONTENT when
|
|
137
|
+
# it is set. opencode applies the last matching rule: devzone's deny entries are taken
|
|
138
|
+
# out of the merge, then added back at the end (the key order of a jq object is the
|
|
139
|
+
# insertion order), so the caller can add permissions but never remove a devzone deny.
|
|
140
|
+
# ~/bash32 is always protected: the container's bash 3.2 was already replaced by a
|
|
141
|
+
# link (#210). The name configurer is kept: agent-droits-gh.bats calls it.
|
|
145
142
|
configurer() {
|
|
146
143
|
local def config
|
|
147
144
|
def="$ICI/opencode/agent.json"
|
|
148
|
-
[ -r "$def" ] || refuse "configuration
|
|
145
|
+
[ -r "$def" ] || refuse "default configuration missing: $def"
|
|
149
146
|
if [ -n "${OPENCODE_CONFIG_CONTENT:-}" ]; then
|
|
150
147
|
config="$(jq -ce -s '
|
|
151
148
|
.[0] as $def | .[1] as $env |
|
|
@@ -156,9 +153,9 @@ configurer() {
|
|
|
156
153
|
| .permission.bash = (($bashdef + $bashenv) | delpaths($deny | map([.])))
|
|
157
154
|
| reduce $deny[] as $k (. ; .permission.bash[$k] = "deny"))
|
|
158
155
|
' "$def" <(printf '%s' "$OPENCODE_CONFIG_CONTENT"))" ||
|
|
159
|
-
refuse "
|
|
156
|
+
refuse "opencode configuration unreadable: nothing launched"
|
|
160
157
|
else
|
|
161
|
-
config="$(jq -ce . "$def")" || refuse "
|
|
158
|
+
config="$(jq -ce . "$def")" || refuse "opencode configuration unreadable: nothing launched"
|
|
162
159
|
fi
|
|
163
160
|
config="$(jq -ce '.permission.bash = ((.permission.bash // {}) + {
|
|
164
161
|
"git commit*": "allow",
|
|
@@ -168,18 +165,18 @@ configurer() {
|
|
|
168
165
|
"rm *bash32*": "deny",
|
|
169
166
|
"chmod *bash32*": "deny",
|
|
170
167
|
"install *bash32*": "deny"
|
|
171
|
-
})' <<<"$config")" || refuse "
|
|
172
|
-
config="$(
|
|
173
|
-
grep -q '"git push\*":"deny"' <<<"$config" || refuse "git push
|
|
168
|
+
})' <<<"$config")" || refuse "opencode configuration unreadable: nothing launched"
|
|
169
|
+
config="$(rights_edit_deny "$config")" || refuse "opencode configuration unreadable: nothing launched"
|
|
170
|
+
grep -q '"git push\*":"deny"' <<<"$config" || refuse "git push not denied: nothing launched"
|
|
174
171
|
export OPENCODE_CONFIG_CONTENT="$config"
|
|
175
172
|
}
|
|
176
173
|
|
|
177
|
-
#
|
|
178
|
-
#
|
|
179
|
-
|
|
174
|
+
# Free models of the installed version, "opencode/" prefix removed:
|
|
175
|
+
# "opencode models opencode" may return "opencode/big-pickle".
|
|
176
|
+
list_models() {
|
|
180
177
|
local l
|
|
181
178
|
l="$(opencode models opencode 2>/dev/null | sed 's#^opencode/##' |
|
|
182
|
-
grep -E '(-free$|^big-pickle$)' | awk 'NF && !
|
|
179
|
+
grep -E '(-free$|^big-pickle$)' | awk 'NF && !seen[$0]++' || true)"
|
|
183
180
|
if [ -n "$l" ]; then
|
|
184
181
|
printf '%s\n' "$l"
|
|
185
182
|
else
|
|
@@ -187,59 +184,59 @@ liste_modeles() {
|
|
|
187
184
|
fi
|
|
188
185
|
}
|
|
189
186
|
|
|
190
|
-
#
|
|
191
|
-
#
|
|
192
|
-
#
|
|
193
|
-
|
|
194
|
-
local
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
187
|
+
# Model and start of a session (#308): read only on the last "=== model opencode/"
|
|
188
|
+
# line of the supervisor; text written by the model in the journal (a possible
|
|
189
|
+
# "opencode/agent.json") is not read.
|
|
190
|
+
session_model_start() {
|
|
191
|
+
local line
|
|
192
|
+
line="$(grep '^=== model opencode/' "$1" 2>/dev/null | tail -1 || true)"
|
|
193
|
+
MODEL_SESSION="$(sed -nE 's/^=== model opencode\/([^ ]+) start .*/\1/p' <<<"$line")"
|
|
194
|
+
START_SESSION="$(sed -nE 's/.* start ([^ ]+).*/\1/p' <<<"$line")"
|
|
198
195
|
}
|
|
199
196
|
|
|
200
197
|
# Models asked with devzone agent --modele (#420): the last header line
|
|
201
|
-
#
|
|
202
|
-
|
|
203
|
-
local
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if [ "$
|
|
198
|
+
# "=== --modele : " of the journal, empty when nothing was asked.
|
|
199
|
+
session_request() {
|
|
200
|
+
local line
|
|
201
|
+
line="$(grep '^=== --modele : ' "$1" 2>/dev/null | tail -1 || true)"
|
|
202
|
+
REQUEST_SESSION="${line#=== --modele : }"
|
|
203
|
+
if [ "$REQUEST_SESSION" = none ]; then REQUEST_SESSION=""; fi
|
|
207
204
|
}
|
|
208
205
|
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
-
#
|
|
212
|
-
#
|
|
213
|
-
|
|
214
|
-
local
|
|
215
|
-
while IFS= read -r
|
|
216
|
-
case "$
|
|
217
|
-
*agent.sh\ *)
|
|
206
|
+
# A session is running (#308) when a live agent.sh process has as first argument (the
|
|
207
|
+
# folder, absolute since #287) a path whose name is exactly the journal without ".log";
|
|
208
|
+
# a plain folder containing that name is not enough, nor a path that is not an agent
|
|
209
|
+
# folder.
|
|
210
|
+
session_running() {
|
|
211
|
+
local line folder
|
|
212
|
+
while IFS= read -r line; do
|
|
213
|
+
case "$line" in
|
|
214
|
+
*agent.sh\ *) folder="${line#*agent.sh }" ;;
|
|
218
215
|
*) continue ;;
|
|
219
216
|
esac
|
|
220
|
-
|
|
221
|
-
[ -n "$
|
|
222
|
-
if [ "$(basename "$
|
|
217
|
+
folder="${folder%% *}"
|
|
218
|
+
[ -n "$folder" ] || continue
|
|
219
|
+
if [ "$(basename "$folder")" = "$1" ]; then return 0; fi
|
|
223
220
|
done < <(ps -eo args= 2>/dev/null || true)
|
|
224
221
|
return 1
|
|
225
222
|
}
|
|
226
223
|
|
|
227
|
-
#
|
|
228
|
-
#
|
|
229
|
-
|
|
230
|
-
local f m
|
|
231
|
-
echo "devzone agent
|
|
224
|
+
# Known sessions (journal, last model, start, last written) and models excluded
|
|
225
|
+
# by the supervisor, with the end time of each exclusion.
|
|
226
|
+
agent_state() {
|
|
227
|
+
local f m start last seen=0
|
|
228
|
+
echo "devzone agent: state"
|
|
232
229
|
for f in "$RACINE"/workspace/.agents/*.log; do
|
|
233
230
|
[ -e "$f" ] || continue
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
m="${
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
echo " session $(basename "$f")
|
|
231
|
+
seen=1
|
|
232
|
+
session_model_start "$f"
|
|
233
|
+
m="${MODEL_SESSION:+opencode/$MODEL_SESSION}"
|
|
234
|
+
start="$START_SESSION"
|
|
235
|
+
last="$(utc_time "$(mtime "$f")")"
|
|
236
|
+
session_request "$f"
|
|
237
|
+
echo " session $(basename "$f"): model ${m:-unknown}${REQUEST_SESSION:+ (requested: $REQUEST_SESSION)}, since ${start:-unknown}, last written $last"
|
|
241
238
|
done
|
|
242
|
-
[ "$
|
|
243
|
-
|
|
239
|
+
[ "$seen" = 1 ] || echo " no session"
|
|
240
|
+
agent_exclusions
|
|
244
241
|
droits_alertes
|
|
245
242
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
2
|
+
# Why: outside the pod, devzone agent launches opencode in the Kubernetes workspace
|
|
3
|
+
# already started (projects and journals of the pod), or locally with --local; the
|
|
4
|
+
# journal of the pod is brought back into that of the workstation (#431).
|
|
5
|
+
# Library sourced by agent.sh: no command is launched here.
|
|
6
6
|
|
|
7
|
-
#
|
|
8
|
-
|
|
7
|
+
# True in the workspace container of the cluster, which carries the chart marker.
|
|
8
|
+
agent_in_pod() {
|
|
9
9
|
[ "${DEVZONE_WORKSPACE:-}" = kubernetes ]
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
# kubectl
|
|
12
|
+
# kubectl of the workstation: devzone context if it exists, then the workspace namespace.
|
|
13
13
|
agent_kc() {
|
|
14
14
|
if kubectl config get-contexts -o name 2>/dev/null | grep -qx devzone; then
|
|
15
15
|
kubectl --context devzone --namespace devzone-workspace "$@"
|
|
@@ -18,80 +18,80 @@ agent_kc() {
|
|
|
18
18
|
fi
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
local
|
|
26
|
-
local agent_kube="$
|
|
27
|
-
if
|
|
28
|
-
#
|
|
29
|
-
# kubeconfig
|
|
30
|
-
(cd "$
|
|
21
|
+
# Why: launching opencode is common to each model attempt, and the kubeconfig
|
|
22
|
+
# preparation depends on the Kubernetes workspace; this block lives here with the rest
|
|
23
|
+
# of the pod (#431), agent.sh only keeps the model loop.
|
|
24
|
+
opencode_launch() {
|
|
25
|
+
local folder="$1" m="$2" brief="$3" journal="$4" state="$5"
|
|
26
|
+
local agent_kube="$state/kubeconfig"
|
|
27
|
+
if agent_in_pod; then
|
|
28
|
+
# In the pod, the limited service account is the only access: no workstation
|
|
29
|
+
# kubeconfig enters the environment of opencode.
|
|
30
|
+
(cd "$folder" && env -u KUBECONFIG DEVZONE_AGENT_SESSION=1 opencode run --print-logs --log-level ERROR --auto -m "$(modele_ref "$m")" "$(cat "$brief")" </dev/null >>"$journal" 2>&1) &
|
|
31
31
|
else
|
|
32
32
|
if [ -f "$HOME/.kube/config" ]; then
|
|
33
33
|
(umask 077; KUBECONFIG="$HOME/.kube/config" kubectl config view --minify --flatten --context devzone >"$agent_kube") 2>/dev/null || : >"$agent_kube"
|
|
34
34
|
chmod 600 "$agent_kube"
|
|
35
|
-
[ -s "$agent_kube" ] || echo "=== kubernetes
|
|
35
|
+
[ -s "$agent_kube" ] || echo "=== kubernetes: no devzone context, session without access" >>"$journal"
|
|
36
36
|
else
|
|
37
37
|
: >"$agent_kube"
|
|
38
38
|
fi
|
|
39
|
-
(cd "$
|
|
39
|
+
(cd "$folder" && KUBECONFIG="$agent_kube" DEVZONE_AGENT_SESSION=1 opencode run --print-logs --log-level ERROR --auto -m "$(modele_ref "$m")" "$(cat "$brief")" </dev/null >>"$journal" 2>&1) &
|
|
40
40
|
fi
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
#
|
|
44
|
-
|
|
45
|
-
if
|
|
43
|
+
# True when the pod of the workspace runs and the command comes from the workstation.
|
|
44
|
+
workspace_available() {
|
|
45
|
+
if agent_in_pod; then return 1; fi
|
|
46
46
|
local phase
|
|
47
47
|
phase="$(agent_kc get pod devzone-workspace-0 -o jsonpath='{.status.phase}' --request-timeout=5s 2>/dev/null)" || return 1
|
|
48
48
|
[ "$phase" = Running ]
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
# (clone
|
|
51
|
+
# Runs the brief in the pod, then brings its journal back even on failure.
|
|
52
|
+
# A /workspaces/projets/... path absent from here designates a folder of the pod
|
|
53
|
+
# (clone or worktree of devzone ticket, #558): nothing is copied.
|
|
54
54
|
agent_workspace() {
|
|
55
|
-
local
|
|
56
|
-
local
|
|
57
|
-
case "$
|
|
58
|
-
/workspaces/projets/*) [ -d "$
|
|
55
|
+
local folder="$1" brief="$2" name journal code=0 in_pod=""
|
|
56
|
+
local pod_root=/home/vscode/.local/share/devzone
|
|
57
|
+
case "$folder" in
|
|
58
|
+
/workspaces/projets/*) [ -d "$folder" ] || in_pod="$folder" ;;
|
|
59
59
|
esac
|
|
60
|
-
if [ -n "$
|
|
61
|
-
|
|
62
|
-
if ! agent_kc exec devzone-workspace-0 -c workspace -- test -d "$
|
|
63
|
-
refuse "
|
|
60
|
+
if [ -n "$in_pod" ]; then
|
|
61
|
+
name="$(basename "$in_pod")"
|
|
62
|
+
if ! agent_kc exec devzone-workspace-0 -c workspace -- test -d "$in_pod" 2>/dev/null; then
|
|
63
|
+
refuse "folder not found in the pod: $in_pod (devzone workspace clone, then devzone ticket <n> in the pod)"
|
|
64
64
|
fi
|
|
65
65
|
else
|
|
66
|
-
[ -d "$
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if ! agent_kc exec devzone-workspace-0 -c workspace -- test -d "$
|
|
70
|
-
refuse "
|
|
66
|
+
[ -d "$folder" ] || refuse "folder not found: $folder (searched from $(pwd))"
|
|
67
|
+
name="$(basename "$(cd "$folder" && pwd -P)")"
|
|
68
|
+
in_pod="/workspaces/projets/$name"
|
|
69
|
+
if ! agent_kc exec devzone-workspace-0 -c workspace -- test -d "$in_pod" 2>/dev/null; then
|
|
70
|
+
refuse "project $name missing from the Kubernetes workspace: devzone workspace copy-to $folder (on this machine), or --local"
|
|
71
71
|
fi
|
|
72
72
|
fi
|
|
73
|
-
echo "devzone agent
|
|
74
|
-
agent_kc cp "$
|
|
75
|
-
# shellcheck disable=SC2016 # the pod shell expands
|
|
76
|
-
agent_kc exec devzone-workspace-0 -c workspace -- env DEVZONE_RACINE="$
|
|
77
|
-
journal="$(
|
|
73
|
+
echo "devzone agent: Kubernetes workspace (pod devzone-workspace-0, $in_pod); --local for the container"
|
|
74
|
+
agent_kc cp "$brief" "devzone-workspace-0:/tmp/devzone-agent-$name.md" -c workspace
|
|
75
|
+
# shellcheck disable=SC2016 # the pod shell expands MODEL_OPT, not this one
|
|
76
|
+
agent_kc exec devzone-workspace-0 -c workspace -- env DEVZONE_RACINE="$pod_root" MODEL_OPT="$MODELE_LISTE" bash -lc 'devzone agent ${MODEL_OPT:+--modele "$MODEL_OPT"} "$1" "$2"' _ "$in_pod" "/tmp/devzone-agent-$name.md" || code=$?
|
|
77
|
+
journal="$(journal_of "$name")"
|
|
78
78
|
mkdir -p "$(dirname "$journal")"
|
|
79
|
-
if ! agent_kc exec devzone-workspace-0 -c workspace -- cat "$
|
|
80
|
-
echo "=== journal
|
|
79
|
+
if ! agent_kc exec devzone-workspace-0 -c workspace -- cat "$pod_root/workspace/.agents/$name.log" >>"$journal"; then
|
|
80
|
+
echo "=== pod journal not found" >>"$journal"
|
|
81
81
|
fi
|
|
82
82
|
return "$code"
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
agent_aide() {
|
|
86
86
|
cat <<'AGENTEOF2'
|
|
87
|
-
usage
|
|
88
|
-
|
|
89
|
-
--modele
|
|
90
|
-
workspace
|
|
91
|
-
|
|
87
|
+
usage: devzone agent [--modele <m>[,<m2>…]] [--local] <folder> <brief-file>
|
|
88
|
+
runs opencode on the brief, free models in rotation
|
|
89
|
+
--modele: models tried first, in order, then the rotation
|
|
90
|
+
Kubernetes workspace first if it runs; --local: this container
|
|
91
|
+
a /workspaces/projets/... path absent from here is a folder of the pod, without copy
|
|
92
92
|
devzone agent etat
|
|
93
|
-
sessions
|
|
94
|
-
devzone agent liberer [<
|
|
95
|
-
|
|
93
|
+
known sessions and excluded models
|
|
94
|
+
devzone agent liberer [<model>|--tous]
|
|
95
|
+
lifts a model exclusion
|
|
96
96
|
AGENTEOF2
|
|
97
97
|
}
|