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,14 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# shellcheck disable=SC2034
|
|
3
|
-
#
|
|
4
|
-
#
|
|
3
|
+
# Model exclusions and network wait of the agent supervisor (#328).
|
|
4
|
+
# Library sourced by agent.sh: no command is launched here.
|
|
5
5
|
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
# Known opencode error texts (grep -E); error_cause takes the cause from them.
|
|
7
|
+
ERRORS='not available in your country|Free usage limit|content filter|Model is unavailable|Upstream request failed|ProviderHeaderTimeout|ENOTFOUND|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|ECONNRESET|fetch failed|network'
|
|
8
|
+
# Prefix of an opencode error line. Erreur: stays so that French output still matches.
|
|
9
|
+
ERROR_LINE='(^|[[:space:]])(Error|ERROR|Erreur):'
|
|
9
10
|
|
|
10
|
-
# Cause
|
|
11
|
-
|
|
11
|
+
# Cause of a failure: pays (country, lasting), quota, filtre (filter), reseau
|
|
12
|
+
# (network, no exclusion) or autre (other). The stored names stay as they are:
|
|
13
|
+
# they are written to the state files and to devzone agent etat --json.
|
|
14
|
+
error_cause() {
|
|
12
15
|
local t="$1"
|
|
13
16
|
case "$t" in
|
|
14
17
|
*"not available in your country"*) echo "pays" ;;
|
|
@@ -20,20 +23,32 @@ erreur_cause() {
|
|
|
20
23
|
esac
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
#
|
|
24
|
-
|
|
26
|
+
# Cause name shown to the user, from a stored cause (mute and muet are both silent).
|
|
27
|
+
cause_label() {
|
|
28
|
+
case "$1" in
|
|
29
|
+
pays) echo "country" ;;
|
|
30
|
+
quota) echo "quota" ;;
|
|
31
|
+
filtre) echo "filter" ;;
|
|
32
|
+
reseau) echo "network" ;;
|
|
33
|
+
mute | muet) echo "silent" ;;
|
|
34
|
+
*) echo "other" ;;
|
|
35
|
+
esac
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Duration of an exclusion in seconds: country 7 days (DEVZONE_AGENT_ECART_PAYS), the others 1 h.
|
|
39
|
+
exclusion_duration() {
|
|
25
40
|
case "$1" in
|
|
26
41
|
pays) echo "${DEVZONE_AGENT_ECART_PAYS:-604800}" ;;
|
|
27
42
|
*) echo 3600 ;;
|
|
28
43
|
esac
|
|
29
44
|
}
|
|
30
45
|
|
|
31
|
-
#
|
|
32
|
-
|
|
46
|
+
# Readable duration of an exclusion for the journal: "7 d", "1 h" or "30 s".
|
|
47
|
+
exclusion_label() {
|
|
33
48
|
local d
|
|
34
|
-
d="$(
|
|
49
|
+
d="$(exclusion_duration "$1")"
|
|
35
50
|
if [ "$d" -ge 86400 ]; then
|
|
36
|
-
echo "$(( d / 86400 ))
|
|
51
|
+
echo "$(( d / 86400 )) d"
|
|
37
52
|
elif [ "$d" -ge 3600 ]; then
|
|
38
53
|
echo "$(( d / 3600 )) h"
|
|
39
54
|
else
|
|
@@ -41,14 +56,15 @@ ecart_libelle() {
|
|
|
41
56
|
fi
|
|
42
57
|
}
|
|
43
58
|
|
|
44
|
-
#
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
# Writes the exclusion of the model: "<start> <cause> <duration>" in $AGENT_ETAT/ecart-<model>
|
|
60
|
+
# (the state file keeps its name on disk).
|
|
61
|
+
model_exclude() {
|
|
62
|
+
printf '%s %s %s\n' "$(date +%s)" "$2" "$(exclusion_duration "$2")" >"$AGENT_ETAT/ecart-$1"
|
|
47
63
|
}
|
|
48
64
|
|
|
49
|
-
#
|
|
50
|
-
# (
|
|
51
|
-
|
|
65
|
+
# True (0) when the model is excluded right now. Also reads the old muet-<model>
|
|
66
|
+
# format (timestamp only, 1 h).
|
|
67
|
+
model_excluded() {
|
|
52
68
|
local f e cause d
|
|
53
69
|
f="$AGENT_ETAT/ecart-$1"
|
|
54
70
|
if [ ! -f "$f" ]; then f="$AGENT_ETAT/muet-$1"; fi
|
|
@@ -57,20 +73,20 @@ modele_ecarte() {
|
|
|
57
73
|
[ "$(date +%s)" -lt $(( e + ${d:-3600} )) ]
|
|
58
74
|
}
|
|
59
75
|
|
|
60
|
-
#
|
|
61
|
-
|
|
76
|
+
# True (0) when opencode.ai resolves and answers over HTTPS: one try, no wait.
|
|
77
|
+
network_reachable() {
|
|
62
78
|
getent hosts opencode.ai >/dev/null 2>&1 && curl -sI --max-time 5 https://opencode.ai >/dev/null 2>&1
|
|
63
79
|
}
|
|
64
80
|
|
|
65
|
-
#
|
|
66
|
-
# DEVZONE_AGENT_RESEAU_MAX s
|
|
67
|
-
|
|
68
|
-
local
|
|
69
|
-
|
|
70
|
-
echo "===
|
|
71
|
-
while [ "$(date +%s)" -lt "$
|
|
72
|
-
if
|
|
73
|
-
echo "===
|
|
81
|
+
# Waits for the network to come back: a try every DEVZONE_AGENT_RESEAU_PAS s, for
|
|
82
|
+
# DEVZONE_AGENT_RESEAU_MAX s at most. Returns 0 when it is back.
|
|
83
|
+
network_wait() {
|
|
84
|
+
local end
|
|
85
|
+
end=$(( $(date +%s) + ${DEVZONE_AGENT_RESEAU_MAX:-1800} ))
|
|
86
|
+
echo "=== network down, waiting" >>"$AGENT_JOURNAL"
|
|
87
|
+
while [ "$(date +%s)" -lt "$end" ]; do
|
|
88
|
+
if network_reachable; then
|
|
89
|
+
echo "=== network back" >>"$AGENT_JOURNAL"
|
|
74
90
|
return 0
|
|
75
91
|
fi
|
|
76
92
|
sleep "${DEVZONE_AGENT_RESEAU_PAS:-30}"
|
|
@@ -78,51 +94,51 @@ reseau_attendre() {
|
|
|
78
94
|
return 1
|
|
79
95
|
}
|
|
80
96
|
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
local f m e cause d
|
|
84
|
-
|
|
97
|
+
# Lists the current exclusions for devzone agent etat (muet- too, without cause).
|
|
98
|
+
agent_exclusions() {
|
|
99
|
+
local f m e cause d end now
|
|
100
|
+
now="$(date +%s)"
|
|
85
101
|
for f in "$AGENT_ETAT"/ecart-*; do
|
|
86
102
|
[ -e "$f" ] || continue
|
|
87
103
|
m="${f##*/ecart-}"
|
|
88
104
|
read -r e cause d <<<"$(cat "$f")"
|
|
89
|
-
|
|
90
|
-
[ "$
|
|
91
|
-
echo "
|
|
105
|
+
end=$(( e + ${d:-3600} ))
|
|
106
|
+
[ "$now" -lt "$end" ] || continue
|
|
107
|
+
echo " model $m excluded ($(cause_label "$cause")) until $(utc_time "$end")"
|
|
92
108
|
done
|
|
93
109
|
for f in "$AGENT_ETAT"/muet-*; do
|
|
94
110
|
[ -e "$f" ] || continue
|
|
95
111
|
m="${f##*/muet-}"
|
|
96
112
|
e="$(cat "$f" 2>/dev/null || true)"
|
|
97
113
|
[ -n "$e" ] || continue
|
|
98
|
-
|
|
99
|
-
[ "$
|
|
100
|
-
echo "
|
|
114
|
+
end=$(( e + 3600 ))
|
|
115
|
+
[ "$now" -lt "$end" ] || continue
|
|
116
|
+
echo " model $m excluded (silent) until $(utc_time "$end")"
|
|
101
117
|
done
|
|
102
118
|
}
|
|
103
119
|
|
|
104
|
-
#
|
|
105
|
-
|
|
120
|
+
# Lifts the exclusion of a model, or of all (--tous): devzone agent liberer.
|
|
121
|
+
exclusion_clear() {
|
|
106
122
|
case "$1" in
|
|
107
123
|
--tous) rm -f "$AGENT_ETAT"/ecart-* "$AGENT_ETAT"/muet-* ;;
|
|
108
124
|
*) rm -f "$AGENT_ETAT/ecart-$1" "$AGENT_ETAT/muet-$1" ;;
|
|
109
125
|
esac
|
|
110
126
|
}
|
|
111
127
|
|
|
112
|
-
#
|
|
113
|
-
#
|
|
114
|
-
#
|
|
115
|
-
|
|
128
|
+
# Keeps the opencode log lines of the session written by --print-logs: only the
|
|
129
|
+
# "timestamp=... level=ERROR ..." lines of a failure declare an exclusion, not the
|
|
130
|
+
# rest of the text read or written by the model.
|
|
131
|
+
error_lines() {
|
|
116
132
|
printf '%s\n' "$1" | sed -e $'s/\033\[[0-9;]*m//g' | grep -a -E '^timestamp=.* level=ERROR ' || true
|
|
117
133
|
}
|
|
118
134
|
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
|
|
122
|
-
local pid="$1" journal="$2" offset="$3" m="$4"
|
|
123
|
-
local
|
|
124
|
-
|
|
125
|
-
cause="$(
|
|
135
|
+
# Stops the current session when the journal holds quota, country or filter since
|
|
136
|
+
# its start: the model is excluded and the session is killed (process and children).
|
|
137
|
+
session_fatal_error() {
|
|
138
|
+
local pid="$1" journal="$2" offset="$3" m="$4" folder="$5"
|
|
139
|
+
local output cause
|
|
140
|
+
output="$(tail -c "+$(( offset + 1 ))" "$journal" 2>/dev/null || true)"
|
|
141
|
+
cause="$(error_cause "$(error_lines "$output")")"
|
|
126
142
|
case "$cause" in
|
|
127
143
|
quota | pays | filtre) ;;
|
|
128
144
|
*) return 1 ;;
|
|
@@ -130,9 +146,9 @@ session_erreur_fatale() {
|
|
|
130
146
|
pkill -P "$pid" 2>/dev/null || true
|
|
131
147
|
kill "$pid" 2>/dev/null || true
|
|
132
148
|
wait "$pid" 2>/dev/null || true
|
|
133
|
-
droits_verifier "$
|
|
134
|
-
|
|
149
|
+
droits_verifier "$folder"
|
|
150
|
+
model_exclude "$m" "$cause"
|
|
135
151
|
modele_demande_ecart "$m" "$cause" "$journal"
|
|
136
|
-
printf '%s\n' "=== opencode/$m
|
|
152
|
+
printf '%s\n' "=== opencode/$m excluded ($(cause_label "$cause")): next model" >>"$journal"
|
|
137
153
|
return 0
|
|
138
154
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
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.
|
|
3
5
|
set -euo pipefail
|
|
4
6
|
|
|
5
7
|
SOURCE="${BASH_SOURCE[0]}"
|
|
@@ -26,7 +28,7 @@ RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
|
|
|
26
28
|
|
|
27
29
|
AGENT_ETAT="${DEVZONE_AGENT_ETAT:-$HOME/.local/state/oc-lancer}"
|
|
28
30
|
|
|
29
|
-
#
|
|
31
|
+
# UTC ISO-8601 date of an epoch, GNU then BSD date: the fin field of the exclusions.
|
|
30
32
|
iso() {
|
|
31
33
|
if date -u -d "@$1" '+%Y-%m-%dT%H:%M:%SZ' >/dev/null 2>&1; then
|
|
32
34
|
date -u -d "@$1" '+%Y-%m-%dT%H:%M:%SZ'
|
|
@@ -35,81 +37,81 @@ iso() {
|
|
|
35
37
|
fi
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
local sessions_json='[]'
|
|
42
|
-
local f journal
|
|
43
|
-
local e cause d
|
|
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
|
|
44
46
|
|
|
45
47
|
for f in "$RACINE"/workspace/.agents/*.log; do
|
|
46
48
|
[ -e "$f" ] || continue
|
|
47
49
|
journal="$(basename "$f")"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[ -n "$
|
|
52
|
-
|
|
53
|
-
|
|
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")")"
|
|
54
56
|
project="${journal%.log}"
|
|
55
|
-
|
|
56
|
-
if
|
|
57
|
+
running=false
|
|
58
|
+
if session_running "$project"; then running=true; fi
|
|
57
59
|
sessions_json="$(jq -c \
|
|
58
60
|
--arg journal "$journal" \
|
|
59
|
-
--arg
|
|
60
|
-
--arg
|
|
61
|
-
--arg
|
|
62
|
-
--arg
|
|
63
|
-
--argjson
|
|
64
|
-
'. + [{journal:$journal,modele:$
|
|
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}]' \
|
|
65
67
|
<<<"$sessions_json")"
|
|
66
68
|
done
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
now="$(date +%s)"
|
|
69
71
|
for f in "$AGENT_ETAT"/ecart-*; do
|
|
70
72
|
[ -e "$f" ] || continue
|
|
71
|
-
|
|
73
|
+
model="${f##*/ecart-}"
|
|
72
74
|
read -r e cause d <<<"$(cat "$f" 2>/dev/null || true)"
|
|
73
75
|
[ -n "$e" ] || continue
|
|
74
|
-
|
|
75
|
-
[ "$
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
--arg modele "$
|
|
76
|
+
end=$(( e + ${d:-3600} ))
|
|
77
|
+
[ "$now" -lt "$end" ] || continue
|
|
78
|
+
end_iso="$(iso "$end")"
|
|
79
|
+
exclusions_json="$(jq -c \
|
|
80
|
+
--arg modele "$model" \
|
|
79
81
|
--arg cause "${cause:-autre}" \
|
|
80
|
-
--arg fin "$
|
|
82
|
+
--arg fin "$end_iso" \
|
|
81
83
|
'. + [{modele:$modele,cause:$cause,fin:$fin}]' \
|
|
82
|
-
<<<"$
|
|
84
|
+
<<<"$exclusions_json")"
|
|
83
85
|
done
|
|
84
86
|
for f in "$AGENT_ETAT"/muet-*; do
|
|
85
87
|
[ -e "$f" ] || continue
|
|
86
|
-
|
|
88
|
+
model="${f##*/muet-}"
|
|
87
89
|
e="$(cat "$f" 2>/dev/null || true)"
|
|
88
90
|
[ -n "$e" ] || continue
|
|
89
|
-
|
|
90
|
-
[ "$
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
--arg modele "$
|
|
91
|
+
end=$(( e + 3600 ))
|
|
92
|
+
[ "$now" -lt "$end" ] || continue
|
|
93
|
+
end_iso="$(iso "$end")"
|
|
94
|
+
exclusions_json="$(jq -c \
|
|
95
|
+
--arg modele "$model" \
|
|
94
96
|
--arg cause "muet" \
|
|
95
|
-
--arg fin "$
|
|
97
|
+
--arg fin "$end_iso" \
|
|
96
98
|
'. + [{modele:$modele,cause:$cause,fin:$fin}]' \
|
|
97
|
-
<<<"$
|
|
99
|
+
<<<"$exclusions_json")"
|
|
98
100
|
done
|
|
99
101
|
|
|
100
102
|
for f in "$AGENT_ETAT"/droits-*.alerte; do
|
|
101
103
|
[ -e "$f" ] || continue
|
|
102
104
|
name="${f##*/droits-}"
|
|
103
105
|
name="${name%.alerte}"
|
|
104
|
-
|
|
106
|
+
alerts_json="$(jq -c --arg n "$name" '. + [$n]' <<<"$alerts_json")"
|
|
105
107
|
done
|
|
106
108
|
|
|
107
109
|
jq -n \
|
|
108
110
|
--argjson schema 1 \
|
|
109
111
|
--argjson sessions "$sessions_json" \
|
|
110
|
-
--argjson ecarts "$
|
|
111
|
-
--argjson alertes "$
|
|
112
|
+
--argjson ecarts "$exclusions_json" \
|
|
113
|
+
--argjson alertes "$alerts_json" \
|
|
112
114
|
'{schema:$schema,sessions:$sessions,ecarts:$ecarts,alertes_droits:$alertes}'
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
|
|
117
|
+
agent_state_json
|
|
@@ -29,7 +29,7 @@ modeles_charger() {
|
|
|
29
29
|
FREE_MODELS=()
|
|
30
30
|
while IFS= read -r m; do
|
|
31
31
|
if [ -n "$m" ]; then FREE_MODELS+=("$m"); fi
|
|
32
|
-
done < <(
|
|
32
|
+
done < <(list_models)
|
|
33
33
|
[ "${#FREE_MODELS[@]}" -gt 0 ] || refuse "$MSG_AUCUN_MODELE"
|
|
34
34
|
MODELES_DEMANDES=()
|
|
35
35
|
if [ -n "$MODELE_LISTE" ]; then
|
|
@@ -40,7 +40,7 @@ modeles_charger() {
|
|
|
40
40
|
esac
|
|
41
41
|
done < <(printf '%s\n' "$MODELE_LISTE" | tr ',' '\n')
|
|
42
42
|
fi
|
|
43
|
-
echo "=== --modele : ${MODELE_LISTE:-
|
|
43
|
+
echo "=== --modele : ${MODELE_LISTE:-none}" >>"$journal"
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
# True when model $1 was asked with --modele.
|
|
@@ -107,7 +107,7 @@ modele_ordre() {
|
|
|
107
107
|
modele_rang_avance() {
|
|
108
108
|
local k
|
|
109
109
|
for ((k = 0; k < ${#MODELES_DEMANDES[@]}; k++)); do
|
|
110
|
-
if !
|
|
110
|
+
if ! model_excluded "${MODELES_DEMANDES[$k]}"; then return 1; fi
|
|
111
111
|
done
|
|
112
112
|
return 0
|
|
113
113
|
}
|