devzone 1.0.0 → 2.0.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/Dockerfile +4 -4
- package/.devcontainer/agent-errors.sh +154 -0
- package/.devcontainer/agent-local.sh +2 -2
- package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
- package/.devcontainer/{agent-modele.sh → agent-model.sh} +8 -8
- package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
- package/.devcontainer/agent-session.sh +122 -125
- package/.devcontainer/agent-state-json.sh +117 -0
- package/.devcontainer/agent-workspace.sh +53 -53
- package/.devcontainer/agent.sh +113 -115
- package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
- package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +4 -4
- package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +3 -3
- package/.devcontainer/argocd/argocd.sh +8 -8
- package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +1 -1
- package/.devcontainer/argocd/services-hook.sh +5 -5
- package/.devcontainer/{catalogue → catalog}/app.sh +4 -4
- package/.devcontainer/{catalogue/catalogue-veilleur.sh → catalog/catalog-watcher.sh} +7 -7
- package/.devcontainer/{catalogue → catalog}/mysql/mysql.sh +7 -7
- package/.devcontainer/{catalogue.sh → catalog.sh} +13 -13
- package/.devcontainer/cluster.sh +8 -8
- package/.devcontainer/devcontainer.json +1 -1
- package/.devcontainer/devzone +55 -54
- package/.devcontainer/{docker-relais.sh → docker-relay.sh} +2 -2
- package/.devcontainer/gitlab/argocd.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +4 -4
- package/.devcontainer/gitlab/installation.sh +5 -5
- package/.devcontainer/gitlab/secrets.sh +1 -1
- package/.devcontainer/help.sh +1 -0
- package/.devcontainer/{kind-enveloppe.sh → kind-wrapper.sh} +5 -5
- package/.devcontainer/{kube-compte.sh → kube-account.sh} +3 -3
- package/.devcontainer/{kube-joignable.sh → kube-reachable.sh} +1 -1
- package/.devcontainer/memory.sh +113 -0
- package/.devcontainer/metrics-server.sh +52 -51
- package/.devcontainer/{paquets.sh → packages.sh} +4 -4
- package/.devcontainer/password.sh +88 -87
- package/.devcontainer/ports-auto.sh +7 -7
- package/.devcontainer/ports.sh +4 -4
- package/.devcontainer/post-create.sh +2 -2
- package/.devcontainer/postgres/postgres.sh +3 -3
- package/.devcontainer/services-admin.sh +5 -5
- package/.devcontainer/skills/devzone/SKILL.md +1 -1
- package/.devcontainer/{demarrage.sh → startup.sh} +5 -5
- package/.devcontainer/state-json.sh +308 -0
- package/.devcontainer/state-lock.sh +53 -0
- package/.devcontainer/state.sh +219 -0
- package/.devcontainer/workspace-init.sh +1 -1
- package/Makefile +7 -7
- package/README.md +2 -2
- package/charts/devzone-workspace/templates/statefulset.yaml +3 -0
- package/manage/devzone +3 -3
- package/manage/scripts/check-go-layout.sh +40 -0
- package/manage/scripts/check-names.sh +60 -0
- package/manage/scripts/devzone-create.sh +2 -2
- package/manage/scripts/devzone-manifest.sh +2 -2
- package/manage/scripts/docker-workstation.sh +2 -2
- package/manage/scripts/docker.sh +2 -2
- package/manage/scripts/{lancer.sh → launch.sh} +3 -3
- package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +1 -1
- package/manage/scripts/{migrer.sh → migrate.sh} +1 -1
- package/manage/workspace.sh +4 -4
- package/package.json +1 -1
- package/.devcontainer/agent-erreurs.sh +0 -138
- package/.devcontainer/agent-etat-json.sh +0 -115
- package/.devcontainer/etat-json.sh +0 -308
- package/.devcontainer/etat-verrou.sh +0 -52
- package/.devcontainer/etat.sh +0 -220
- package/.devcontainer/memoire.sh +0 -113
- /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
- /package/.devcontainer/{ia → ai}/host-check.message +0 -0
- /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
- /package/.devcontainer/{ia → ai}/host-models.sh +0 -0
- /package/.devcontainer/{catalogue → catalog}/mysql/app.conf +0 -0
- /package/.devcontainer/{catalogue/mysql/installer.sh → catalog/mysql/install.sh} +0 -0
- /package/.devcontainer/{catalogue → catalog}/mysql/volume.sh +0 -0
- /package/.devcontainer/{docker-sans-hote.sh → docker-without-host.sh} +0 -0
- /package/.devcontainer/{isolement.sh → isolation.sh} +0 -0
- /package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +0 -0
- /package/manage/scripts/{desinstaller.sh → uninstall.sh} +0 -0
|
@@ -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-rights-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
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Machine output of devzone agent etat (--json): sessions, exclusions, rights alerts.
|
|
3
|
+
# Keys (schema, sessions, ecarts, fin, alertes_droits...) and values are a public
|
|
4
|
+
# format: they keep their French names.
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
SOURCE="${BASH_SOURCE[0]}"
|
|
8
|
+
while [ -L "$SOURCE" ]; do
|
|
9
|
+
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
10
|
+
SOURCE="$(readlink "$SOURCE")"
|
|
11
|
+
case "$SOURCE" in
|
|
12
|
+
/*) ;;
|
|
13
|
+
*) SOURCE="$DIR/$SOURCE" ;;
|
|
14
|
+
esac
|
|
15
|
+
done
|
|
16
|
+
ICI="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
17
|
+
RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
|
|
18
|
+
|
|
19
|
+
# shellcheck source=agent-errors.sh
|
|
20
|
+
# shellcheck disable=SC1091
|
|
21
|
+
. "$ICI/agent-errors.sh"
|
|
22
|
+
# shellcheck source=agent-rights.sh
|
|
23
|
+
# shellcheck disable=SC1091
|
|
24
|
+
. "$ICI/agent-rights.sh"
|
|
25
|
+
# shellcheck source=agent-session.sh
|
|
26
|
+
# shellcheck disable=SC1091
|
|
27
|
+
. "$ICI/agent-session.sh"
|
|
28
|
+
|
|
29
|
+
AGENT_ETAT="${DEVZONE_AGENT_ETAT:-$HOME/.local/state/oc-lancer}"
|
|
30
|
+
|
|
31
|
+
# UTC ISO-8601 date of an epoch, GNU then BSD date: the fin field of the exclusions.
|
|
32
|
+
iso() {
|
|
33
|
+
if date -u -d "@$1" '+%Y-%m-%dT%H:%M:%SZ' >/dev/null 2>&1; then
|
|
34
|
+
date -u -d "@$1" '+%Y-%m-%dT%H:%M:%SZ'
|
|
35
|
+
else
|
|
36
|
+
date -u -r "$1" '+%Y-%m-%dT%H:%M:%SZ'
|
|
37
|
+
fi
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
# Agent state in JSON: reuses the data of agent_state, agent_exclusions and
|
|
41
|
+
# droits_alertes, without copying their logic.
|
|
42
|
+
agent_state_json() {
|
|
43
|
+
local sessions_json='[]' exclusions_json='[]' alerts_json='[]'
|
|
44
|
+
local f journal model start last project running name
|
|
45
|
+
local e cause d end end_iso now
|
|
46
|
+
|
|
47
|
+
for f in "$RACINE"/workspace/.agents/*.log; do
|
|
48
|
+
[ -e "$f" ] || continue
|
|
49
|
+
journal="$(basename "$f")"
|
|
50
|
+
session_model_start "$f"
|
|
51
|
+
session_request "$f"
|
|
52
|
+
model="$MODEL_SESSION"
|
|
53
|
+
[ -n "$model" ] || model="inconnu"
|
|
54
|
+
start="$START_SESSION"
|
|
55
|
+
last="$(utc_time "$(mtime "$f")")"
|
|
56
|
+
project="${journal%.log}"
|
|
57
|
+
running=false
|
|
58
|
+
if session_running "$project"; then running=true; fi
|
|
59
|
+
sessions_json="$(jq -c \
|
|
60
|
+
--arg journal "$journal" \
|
|
61
|
+
--arg model "$model" \
|
|
62
|
+
--arg start "$start" \
|
|
63
|
+
--arg last "$last" \
|
|
64
|
+
--arg request "$REQUEST_SESSION" \
|
|
65
|
+
--argjson running "$running" \
|
|
66
|
+
'. + [{journal:$journal,modele:$model,debut:(if $start=="" then null else $start end),dernier_ecrit:(if $last=="" then null else $last end),demande:(if $request=="" then null else $request end),en_cours:$running}]' \
|
|
67
|
+
<<<"$sessions_json")"
|
|
68
|
+
done
|
|
69
|
+
|
|
70
|
+
now="$(date +%s)"
|
|
71
|
+
for f in "$AGENT_ETAT"/ecart-*; do
|
|
72
|
+
[ -e "$f" ] || continue
|
|
73
|
+
model="${f##*/ecart-}"
|
|
74
|
+
read -r e cause d <<<"$(cat "$f" 2>/dev/null || true)"
|
|
75
|
+
[ -n "$e" ] || continue
|
|
76
|
+
end=$(( e + ${d:-3600} ))
|
|
77
|
+
[ "$now" -lt "$end" ] || continue
|
|
78
|
+
end_iso="$(iso "$end")"
|
|
79
|
+
exclusions_json="$(jq -c \
|
|
80
|
+
--arg modele "$model" \
|
|
81
|
+
--arg cause "${cause:-autre}" \
|
|
82
|
+
--arg fin "$end_iso" \
|
|
83
|
+
'. + [{modele:$modele,cause:$cause,fin:$fin}]' \
|
|
84
|
+
<<<"$exclusions_json")"
|
|
85
|
+
done
|
|
86
|
+
for f in "$AGENT_ETAT"/muet-*; do
|
|
87
|
+
[ -e "$f" ] || continue
|
|
88
|
+
model="${f##*/muet-}"
|
|
89
|
+
e="$(cat "$f" 2>/dev/null || true)"
|
|
90
|
+
[ -n "$e" ] || continue
|
|
91
|
+
end=$(( e + 3600 ))
|
|
92
|
+
[ "$now" -lt "$end" ] || continue
|
|
93
|
+
end_iso="$(iso "$end")"
|
|
94
|
+
exclusions_json="$(jq -c \
|
|
95
|
+
--arg modele "$model" \
|
|
96
|
+
--arg cause "muet" \
|
|
97
|
+
--arg fin "$end_iso" \
|
|
98
|
+
'. + [{modele:$modele,cause:$cause,fin:$fin}]' \
|
|
99
|
+
<<<"$exclusions_json")"
|
|
100
|
+
done
|
|
101
|
+
|
|
102
|
+
for f in "$AGENT_ETAT"/droits-*.alerte; do
|
|
103
|
+
[ -e "$f" ] || continue
|
|
104
|
+
name="${f##*/droits-}"
|
|
105
|
+
name="${name%.alerte}"
|
|
106
|
+
alerts_json="$(jq -c --arg n "$name" '. + [$n]' <<<"$alerts_json")"
|
|
107
|
+
done
|
|
108
|
+
|
|
109
|
+
jq -n \
|
|
110
|
+
--argjson schema 1 \
|
|
111
|
+
--argjson sessions "$sessions_json" \
|
|
112
|
+
--argjson ecarts "$exclusions_json" \
|
|
113
|
+
--argjson alertes "$alerts_json" \
|
|
114
|
+
'{schema:$schema,sessions:$sessions,ecarts:$ecarts,alertes_droits:$alertes}'
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
agent_state_json
|