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.
Files changed (79) hide show
  1. package/.devcontainer/Dockerfile +4 -4
  2. package/.devcontainer/agent-errors.sh +154 -0
  3. package/.devcontainer/agent-local.sh +2 -2
  4. package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
  5. package/.devcontainer/{agent-modele.sh → agent-model.sh} +8 -8
  6. package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
  7. package/.devcontainer/agent-session.sh +122 -125
  8. package/.devcontainer/agent-state-json.sh +117 -0
  9. package/.devcontainer/agent-workspace.sh +53 -53
  10. package/.devcontainer/agent.sh +113 -115
  11. package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
  12. package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +4 -4
  13. package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +3 -3
  14. package/.devcontainer/argocd/argocd.sh +8 -8
  15. package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +1 -1
  16. package/.devcontainer/argocd/services-hook.sh +5 -5
  17. package/.devcontainer/{catalogue → catalog}/app.sh +4 -4
  18. package/.devcontainer/{catalogue/catalogue-veilleur.sh → catalog/catalog-watcher.sh} +7 -7
  19. package/.devcontainer/{catalogue → catalog}/mysql/mysql.sh +7 -7
  20. package/.devcontainer/{catalogue.sh → catalog.sh} +13 -13
  21. package/.devcontainer/cluster.sh +8 -8
  22. package/.devcontainer/devcontainer.json +1 -1
  23. package/.devcontainer/devzone +55 -54
  24. package/.devcontainer/{docker-relais.sh → docker-relay.sh} +2 -2
  25. package/.devcontainer/gitlab/argocd.sh +2 -2
  26. package/.devcontainer/gitlab/gitlab.sh +4 -4
  27. package/.devcontainer/gitlab/installation.sh +5 -5
  28. package/.devcontainer/gitlab/secrets.sh +1 -1
  29. package/.devcontainer/help.sh +1 -0
  30. package/.devcontainer/{kind-enveloppe.sh → kind-wrapper.sh} +5 -5
  31. package/.devcontainer/{kube-compte.sh → kube-account.sh} +3 -3
  32. package/.devcontainer/{kube-joignable.sh → kube-reachable.sh} +1 -1
  33. package/.devcontainer/memory.sh +113 -0
  34. package/.devcontainer/metrics-server.sh +52 -51
  35. package/.devcontainer/{paquets.sh → packages.sh} +4 -4
  36. package/.devcontainer/password.sh +88 -87
  37. package/.devcontainer/ports-auto.sh +7 -7
  38. package/.devcontainer/ports.sh +4 -4
  39. package/.devcontainer/post-create.sh +2 -2
  40. package/.devcontainer/postgres/postgres.sh +3 -3
  41. package/.devcontainer/services-admin.sh +5 -5
  42. package/.devcontainer/skills/devzone/SKILL.md +1 -1
  43. package/.devcontainer/{demarrage.sh → startup.sh} +5 -5
  44. package/.devcontainer/state-json.sh +308 -0
  45. package/.devcontainer/state-lock.sh +53 -0
  46. package/.devcontainer/state.sh +219 -0
  47. package/.devcontainer/workspace-init.sh +1 -1
  48. package/Makefile +7 -7
  49. package/README.md +2 -2
  50. package/charts/devzone-workspace/templates/statefulset.yaml +3 -0
  51. package/manage/devzone +3 -3
  52. package/manage/scripts/check-go-layout.sh +40 -0
  53. package/manage/scripts/check-names.sh +60 -0
  54. package/manage/scripts/devzone-create.sh +2 -2
  55. package/manage/scripts/devzone-manifest.sh +2 -2
  56. package/manage/scripts/docker-workstation.sh +2 -2
  57. package/manage/scripts/docker.sh +2 -2
  58. package/manage/scripts/{lancer.sh → launch.sh} +3 -3
  59. package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +1 -1
  60. package/manage/scripts/{migrer.sh → migrate.sh} +1 -1
  61. package/manage/workspace.sh +4 -4
  62. package/package.json +1 -1
  63. package/.devcontainer/agent-erreurs.sh +0 -138
  64. package/.devcontainer/agent-etat-json.sh +0 -115
  65. package/.devcontainer/etat-json.sh +0 -308
  66. package/.devcontainer/etat-verrou.sh +0 -52
  67. package/.devcontainer/etat.sh +0 -220
  68. package/.devcontainer/memoire.sh +0 -113
  69. /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
  70. /package/.devcontainer/{ia → ai}/host-check.message +0 -0
  71. /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
  72. /package/.devcontainer/{ia → ai}/host-models.sh +0 -0
  73. /package/.devcontainer/{catalogue → catalog}/mysql/app.conf +0 -0
  74. /package/.devcontainer/{catalogue/mysql/installer.sh → catalog/mysql/install.sh} +0 -0
  75. /package/.devcontainer/{catalogue → catalog}/mysql/volume.sh +0 -0
  76. /package/.devcontainer/{docker-sans-hote.sh → docker-without-host.sh} +0 -0
  77. /package/.devcontainer/{isolement.sh → isolation.sh} +0 -0
  78. /package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +0 -0
  79. /package/manage/scripts/{desinstaller.sh → uninstall.sh} +0 -0
package/manage/devzone CHANGED
@@ -109,16 +109,16 @@ case "${1:-}" in
109
109
  update_workstation "${@:2}"
110
110
  ;;
111
111
  uninstall)
112
- # Devzone folder (.devcontainer/); an older devzone has its desinstaller.sh
112
+ # Devzone folder (.devcontainer/); an older devzone has its uninstall.sh
113
113
  # in manage/scripts/ (new), core/scripts or scripts/ (old), or at the root
114
114
  uninstaller=""
115
115
  if [ -d .devcontainer ]; then
116
- for f in manage/scripts/desinstaller.sh core/scripts/desinstaller.sh scripts/desinstaller.sh desinstaller.sh; do
116
+ for f in manage/scripts/uninstall.sh core/scripts/uninstall.sh scripts/uninstall.sh uninstall.sh; do
117
117
  if [ -f "$f" ]; then uninstaller="$f" && break; fi
118
118
  done
119
119
  fi
120
120
  if [ -z "$uninstaller" ]; then
121
- echo "✖ À lancer dans un dossier devzone (desinstaller.sh introuvable ici)." >&2
121
+ echo "✖ À lancer dans un dossier devzone (uninstall.sh introuvable ici)." >&2
122
122
  exit 1
123
123
  fi
124
124
  DEVZONE_COMMANDE="devzone uninstall" bash "$uninstaller"
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ # CI check: every Go file has at most 250 lines, tests included (#710). A file
3
+ # that grows beyond it is split into a folder of smaller files, by
4
+ # responsibility. Checked: the Go files tracked by git, plus the new ones not
5
+ # ignored (git ls-files --cached --others --exclude-standard), so the Go
6
+ # projects checked out under workspace/ are never counted. A file too long is
7
+ # printed as "path: N lines (max 250)" and the run exits 1; otherwise it prints
8
+ # "go layout: N files ok" and exits 0. bash 3.2 (macOS).
9
+
10
+ set -u
11
+
12
+ ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
+ ROOT="$(cd "$ICI/../.." && pwd)"
14
+ MAX=250
15
+
16
+ if ! files="$(git -C "$ROOT" ls-files --cached --others --exclude-standard -- '*.go')"; then
17
+ echo "check-go-layout: git ls-files fails in $ROOT" >&2
18
+ exit 1
19
+ fi
20
+
21
+ fails=0
22
+ count=0
23
+ while IFS= read -r f; do
24
+ [ -n "$f" ] || continue
25
+ [ -f "$ROOT/$f" ] || continue
26
+ count=$((count + 1))
27
+ # awk counts the last line too, even without a final newline
28
+ lines="$(awk 'END { print NR }' "$ROOT/$f")"
29
+ if [ "$lines" -gt "$MAX" ]; then
30
+ printf '%s: %s lines (max %s)\n' "$f" "$lines" "$MAX"
31
+ fails=1
32
+ fi
33
+ done <<LISTE
34
+ $files
35
+ LISTE
36
+
37
+ if [ "$fails" -ne 0 ]; then
38
+ exit 1
39
+ fi
40
+ echo "go layout: $count files ok"
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+ # CI check: the names of the files and folders tracked by git are in English
3
+ # (#716). A path fails when one of its words (split on - . _ and /) is in the
4
+ # list of French words below. Each fault is printed as "path: word" and the
5
+ # run exits 1; otherwise it prints "names check: N paths ok" and exits 0.
6
+ # Not checked: .github/ (the workflow names are referenced by the repowarden
7
+ # checks) and the names listed in ALLOWED (files of the user data, kept until
8
+ # their migration). bash 3.2 (macOS).
9
+
10
+ set -u
11
+
12
+ ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
+ ROOT="$(cd "$ICI/../.." && pwd)"
14
+
15
+ # French words that must not appear in a name. Split fragments, so this file
16
+ # does not match its own rules (the check-english convention).
17
+ FRENCH=" cre_er desinst_aller migr_er ret_our et_at demarr_age catalog_ue paqu_ets plate_forme memo_ire rel_ais verr_ou veill_eur dro_its err_eurs mod_ele mod_eles ec_arts chem_ins para_llele ho_te san_s ave_c envel_oppe join_gnable isole_ment comp_te lan_cer rep_arer util_iser garde_ mett_re "
18
+ FRENCH="$(printf '%s' "$FRENCH" | tr -d '_')"
19
+
20
+ # Names of the user data, handled by their own migration ticket
21
+ ALLOWED=" .devzone.paquets .devzone.sauvegarde .devzone.ports-workspace .devzone.modules .devzone.version "
22
+
23
+ if ! paths="$(git -C "$ROOT" ls-files --cached --others --exclude-standard)"; then
24
+ echo "check-names: git ls-files fails in $ROOT" >&2
25
+ exit 1
26
+ fi
27
+
28
+ fails=0
29
+ count=0
30
+ while IFS= read -r path; do
31
+ [ -n "$path" ] || continue
32
+ case "$path" in
33
+ .github/*) continue ;;
34
+ esac
35
+ count=$((count + 1))
36
+ words="$(printf '%s' "$path" | tr '/._-' ' ')"
37
+ for word in $words; do
38
+ case "$FRENCH" in
39
+ *" $word "*)
40
+ skip=0
41
+ for allowed in $ALLOWED; do
42
+ case "$path" in
43
+ "$allowed" | "$allowed"/*) skip=1 ;;
44
+ esac
45
+ done
46
+ if [ "$skip" -eq 0 ]; then
47
+ printf '%s: %s\n' "$path" "$word"
48
+ fails=1
49
+ fi
50
+ ;;
51
+ esac
52
+ done
53
+ done <<LISTE
54
+ $paths
55
+ LISTE
56
+
57
+ if [ "$fails" -ne 0 ]; then
58
+ exit 1
59
+ fi
60
+ echo "names check: $count paths ok"
@@ -72,7 +72,7 @@ create_workstation() {
72
72
  # npm never includes .gitignore: written here
73
73
  : >"$target/.gitignore"
74
74
  complete_gitignore "$target"
75
- chmod +x "$target/manage/scripts/desinstaller.sh" "$target/manage/scripts/lancer.sh"
75
+ chmod +x "$target/manage/scripts/uninstall.sh" "$target/manage/scripts/launch.sh"
76
76
  create_mode_write "$target" "$CREATE_MODE"
77
77
  # The GitOps repository of the new devzone (#539): github, an existing URL,
78
78
  # or none, written in the .argocd.conf of the new devzone (conf.sh writes
@@ -132,7 +132,7 @@ create_workstation() {
132
132
  if command -v make >/dev/null 2>&1; then
133
133
  make -C "$target" up
134
134
  else
135
- bash "$target/manage/scripts/lancer.sh" up "$target"
135
+ bash "$target/manage/scripts/launch.sh" up "$target"
136
136
  fi
137
137
  echo "Ensuite : cd $target && make shell (ou ouvre le dossier dans VS Code : Reopen in Container)."
138
138
  }
@@ -139,10 +139,10 @@ old_tree() {
139
139
  local folder="$1" tree="$2"
140
140
  case "$tree" in
141
141
  core)
142
- [ -f "$folder/core/devzone" ] || [ -f "$folder/core/scripts/desinstaller.sh" ]
142
+ [ -f "$folder/core/devzone" ] || [ -f "$folder/core/scripts/uninstall.sh" ]
143
143
  ;;
144
144
  scripts)
145
- [ -f "$folder/scripts/desinstaller.sh" ] && [ -f "$folder/scripts/lancer.sh" ]
145
+ [ -f "$folder/scripts/uninstall.sh" ] && [ -f "$folder/scripts/launch.sh" ]
146
146
  ;;
147
147
  *) return 1 ;;
148
148
  esac
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # Docker workstation put to sleep when the Kubernetes workspace takes over (#517).
3
- # Sourced by migrer.sh (stop) and migrer-retour.sh (start). Containers of the
3
+ # Sourced by migrate.sh (stop) and migrate-revert.sh (start). Containers of the
4
4
  # workstation folder (label devcontainer.local_folder) and the automatic port
5
5
  # relays of this instance (labels devzone.auto=true, devzone.instance) are
6
6
  # stopped, never removed. Without Docker,
@@ -12,7 +12,7 @@ docker_workstation_ready() {
12
12
  }
13
13
 
14
14
  # Ids, one per line, of the containers of folder $1 and of the automatic relays
15
- # of this instance (DEVZONE_VOLUMES, default devzone, as in desinstaller.sh): the
15
+ # of this instance (DEVZONE_VOLUMES, default devzone, as in uninstall.sh): the
16
16
  # relays of another devzone on the same machine are not touched.
17
17
  # $2 is "running" (docker ps) or "exited" (stopped containers, docker ps -a).
18
18
  docker_workstation_ids() {
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
- # Checks Docker on the host before any call (sourced by lancer.sh,
3
- # desinstaller.sh and the npm command manage/devzone): without it the user
2
+ # Checks Docker on the host before any call (sourced by launch.sh,
3
+ # uninstall.sh and the npm command manage/devzone): without it the user
4
4
  # would only see the raw devcontainers CLI or docker error.
5
5
  # DEVZONE_DOCKER: docker command name (tests: simulate its absence).
6
6
  # Compatible with bash 3.2 (macOS).
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
  # Starts the container on the host without ever staying silent:
3
- # bash manage/scripts/lancer.sh up [folder] (make up)
4
- # bash manage/scripts/lancer.sh rebuild [folder] (make rebuild: rebuild from scratch)
3
+ # bash manage/scripts/launch.sh up [folder] (make up)
4
+ # bash manage/scripts/launch.sh rebuild [folder] (make rebuild: rebuild from scratch)
5
5
  # Full devcontainer CLI output goes to <folder>/.devzone.log; the terminal shows
6
6
  # key steps, a heartbeat at least every DEVZONE_SIGNE_DE_VIE seconds (30), and a
7
7
  # question asked inside the container (last log line left unanswered for
@@ -16,7 +16,7 @@ case "$mode" in
16
16
  up) options=() done_msg="devzone started" ;;
17
17
  rebuild) options=(--remove-existing-container) done_msg="devzone rebuilt" ;;
18
18
  *)
19
- echo "usage: bash manage/scripts/lancer.sh up|rebuild [folder]" >&2
19
+ echo "usage: bash manage/scripts/launch.sh up|rebuild [folder]" >&2
20
20
  exit 2
21
21
  ;;
22
22
  esac
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # Rollback from Kubernetes workspace to Docker workstation (#403): devzone workspace
3
- # revert [--bring-back]. Sourced by manage/workspace.sh after migrer.sh (uses
3
+ # revert [--bring-back]. Sourced by manage/workspace.sh after migrate.sh (uses
4
4
  # copy_from, record_workspace, fail and kc). With --bring-back, the workstation
5
5
  # version of a project is moved to .devzone.sauvegarde/<date>/ before being replaced.
6
6
 
@@ -4,7 +4,7 @@
4
4
  # kubectl_flag, copy_to and copy_from. Nothing is ever deleted except by
5
5
  # clean-docker, after confirmation. Run from the devzone workstation folder.
6
6
 
7
- # Docker workstation sleep on migrate (stop here, start in migrer-retour.sh).
7
+ # Docker workstation sleep on migrate (stop here, start in migrate-revert.sh).
8
8
  # shellcheck source=manage/scripts/docker-workstation.sh
9
9
  . "$(dirname "${BASH_SOURCE[0]}")/docker-workstation.sh"
10
10
 
@@ -175,10 +175,10 @@ copy_from() {
175
175
  . "$HERE/scripts/workspace-clone.sh"
176
176
  # shellcheck source=manage/scripts/workspace-copies.sh
177
177
  . "$HERE/scripts/workspace-copies.sh"
178
- # shellcheck source=manage/scripts/migrer.sh
179
- . "$HERE/scripts/migrer.sh"
180
- # shellcheck source=manage/scripts/migrer-retour.sh
181
- . "$HERE/scripts/migrer-retour.sh"
178
+ # shellcheck source=manage/scripts/migrate.sh
179
+ . "$HERE/scripts/migrate.sh"
180
+ # shellcheck source=manage/scripts/migrate-revert.sh
181
+ . "$HERE/scripts/migrate-revert.sh"
182
182
  # shellcheck source=manage/scripts/ports-workspace.sh
183
183
  . "$HERE/scripts/ports-workspace.sh"
184
184
  # shellcheck source=manage/scripts/services-workspace.sh
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Ton poste de développement Linux, prêt en une commande, identique sur Mac, Windows et Linux.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {
@@ -1,138 +0,0 @@
1
- #!/usr/bin/env bash
2
- # shellcheck disable=SC2034
3
- # Écarts de modèles et attente du réseau du superviseur d'agent (#328).
4
- # Bibliothèque sourcée par agent.sh : aucune commande n'est lancée ici.
5
-
6
- # Textes d'erreur opencode reconnus (grep -E) ; erreur_cause en tire la cause.
7
- ERREURS='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
- LIGNE_ERREUR='(^|[[:space:]])(Error|ERROR|Erreur):'
9
-
10
- # Cause d'un échec : pays (durable), quota, filtre, reseau (aucun écart) ou autre.
11
- erreur_cause() {
12
- local t="$1"
13
- case "$t" in
14
- *"not available in your country"*) echo "pays" ;;
15
- *"Free usage limit"*) echo "quota" ;;
16
- *"content filter"*) echo "filtre" ;;
17
- *"ENOTFOUND"* | *"ECONNREFUSED"* | *"ETIMEDOUT"* | *"EAI_AGAIN"* | *"ECONNRESET"* | *"fetch failed"* | *"network"*)
18
- echo "reseau" ;;
19
- *) echo "autre" ;;
20
- esac
21
- }
22
-
23
- # Durée d'un écart en secondes : pays 7 jours (DEVZONE_AGENT_ECART_PAYS), les autres 1 h.
24
- ecart_duree() {
25
- case "$1" in
26
- pays) echo "${DEVZONE_AGENT_ECART_PAYS:-604800}" ;;
27
- *) echo 3600 ;;
28
- esac
29
- }
30
-
31
- # Durée lisible d'un écart pour le journal : « 7 j », « 1 h » ou « 30 s ».
32
- ecart_libelle() {
33
- local d
34
- d="$(ecart_duree "$1")"
35
- if [ "$d" -ge 86400 ]; then
36
- echo "$(( d / 86400 )) j"
37
- elif [ "$d" -ge 3600 ]; then
38
- echo "$(( d / 3600 )) h"
39
- else
40
- echo "${d} s"
41
- fi
42
- }
43
-
44
- # Écrit l'écart du modèle : « <début> <cause> <durée> » dans $AGENT_ETAT/ecart-<modèle>.
45
- modele_ecarter() {
46
- printf '%s %s %s\n' "$(date +%s)" "$2" "$(ecart_duree "$2")" >"$AGENT_ETAT/ecart-$1"
47
- }
48
-
49
- # Vaut 0 si le modèle est écarté en ce moment. Lit aussi l'ancien format muet-<modèle>
50
- # (horodatage seul, durée 1 h).
51
- modele_ecarte() {
52
- local f e cause d
53
- f="$AGENT_ETAT/ecart-$1"
54
- if [ ! -f "$f" ]; then f="$AGENT_ETAT/muet-$1"; fi
55
- if [ ! -f "$f" ]; then return 1; fi
56
- read -r e cause d <<<"$(cat "$f")"
57
- [ "$(date +%s)" -lt $(( e + ${d:-3600} )) ]
58
- }
59
-
60
- # Vaut 0 si opencode.ai se résout et répond en HTTPS : un seul essai, sans attente.
61
- reseau_joignable() {
62
- getent hosts opencode.ai >/dev/null 2>&1 && curl -sI --max-time 5 https://opencode.ai >/dev/null 2>&1
63
- }
64
-
65
- # Attend le retour du réseau : essai toutes les DEVZONE_AGENT_RESEAU_PAS s, pendant
66
- # DEVZONE_AGENT_RESEAU_MAX s au plus. Rend 0 au retour.
67
- reseau_attendre() {
68
- local fin
69
- fin=$(( $(date +%s) + ${DEVZONE_AGENT_RESEAU_MAX:-1800} ))
70
- echo "=== réseau coupé, attente" >>"$AGENT_JOURNAL"
71
- while [ "$(date +%s)" -lt "$fin" ]; do
72
- if reseau_joignable; then
73
- echo "=== réseau revenu" >>"$AGENT_JOURNAL"
74
- return 0
75
- fi
76
- sleep "${DEVZONE_AGENT_RESEAU_PAS:-30}"
77
- done
78
- return 1
79
- }
80
-
81
- # Liste les écarts en cours pour devzone agent etat (muet- aussi, sans cause).
82
- agent_ecarts() {
83
- local f m e cause d fin maintenant
84
- maintenant="$(date +%s)"
85
- for f in "$AGENT_ETAT"/ecart-*; do
86
- [ -e "$f" ] || continue
87
- m="${f##*/ecart-}"
88
- read -r e cause d <<<"$(cat "$f")"
89
- fin=$(( e + ${d:-3600} ))
90
- [ "$maintenant" -lt "$fin" ] || continue
91
- echo " modèle $m écarté ($cause) jusqu'à $(heure "$fin")"
92
- done
93
- for f in "$AGENT_ETAT"/muet-*; do
94
- [ -e "$f" ] || continue
95
- m="${f##*/muet-}"
96
- e="$(cat "$f" 2>/dev/null || true)"
97
- [ -n "$e" ] || continue
98
- fin=$(( e + 3600 ))
99
- [ "$maintenant" -lt "$fin" ] || continue
100
- echo " modèle $m écarté (muet) jusqu'à $(heure "$fin")"
101
- done
102
- }
103
-
104
- # Lève l'écart d'un modèle, ou de tous (--tous) : devzone agent liberer.
105
- ecart_liberer() {
106
- case "$1" in
107
- --tous) rm -f "$AGENT_ETAT"/ecart-* "$AGENT_ETAT"/muet-* ;;
108
- *) rm -f "$AGENT_ETAT/ecart-$1" "$AGENT_ETAT/muet-$1" ;;
109
- esac
110
- }
111
-
112
- # Filtre le texte de session sur les lignes du journal opencode produites par
113
- # --print-logs : seules les lignes « timestamp=… level=ERROR … » d'un échec
114
- # déclarent un écart, pas le reste du texte lu ou écrit par le modèle.
115
- lignes_erreur() {
116
- printf '%s\n' "$1" | sed -e $'s/\033\[[0-9;]*m//g' | grep -a -E '^timestamp=.* level=ERROR ' || true
117
- }
118
-
119
- # Arrête la session en cours si le journal contient quota, pays ou filtre depuis
120
- # son début : le modèle est écarté et la session est tuée (processus et enfants).
121
- session_erreur_fatale() {
122
- local pid="$1" journal="$2" offset="$3" m="$4" dossier="$5"
123
- local sortie cause
124
- sortie="$(tail -c "+$(( offset + 1 ))" "$journal" 2>/dev/null || true)"
125
- cause="$(erreur_cause "$(lignes_erreur "$sortie")")"
126
- case "$cause" in
127
- quota | pays | filtre) ;;
128
- *) return 1 ;;
129
- esac
130
- pkill -P "$pid" 2>/dev/null || true
131
- kill "$pid" 2>/dev/null || true
132
- wait "$pid" 2>/dev/null || true
133
- droits_verifier "$dossier"
134
- modele_ecarter "$m" "$cause"
135
- modele_demande_ecart "$m" "$cause" "$journal"
136
- printf '%s\n' "=== opencode/$m écarté ($cause) : modèle suivant" >>"$journal"
137
- return 0
138
- }
@@ -1,115 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Sortie machine de devzone agent etat (--json) : sessions, écarts, alertes droits.
3
- set -euo pipefail
4
-
5
- SOURCE="${BASH_SOURCE[0]}"
6
- while [ -L "$SOURCE" ]; do
7
- DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
8
- SOURCE="$(readlink "$SOURCE")"
9
- case "$SOURCE" in
10
- /*) ;;
11
- *) SOURCE="$DIR/$SOURCE" ;;
12
- esac
13
- done
14
- ICI="$(cd -P "$(dirname "$SOURCE")" && pwd)"
15
- RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
16
-
17
- # shellcheck source=agent-erreurs.sh
18
- # shellcheck disable=SC1091
19
- . "$ICI/agent-erreurs.sh"
20
- # shellcheck source=agent-droits.sh
21
- # shellcheck disable=SC1091
22
- . "$ICI/agent-droits.sh"
23
- # shellcheck source=agent-session.sh
24
- # shellcheck disable=SC1091
25
- . "$ICI/agent-session.sh"
26
-
27
- AGENT_ETAT="${DEVZONE_AGENT_ETAT:-$HOME/.local/state/oc-lancer}"
28
-
29
- # Date UTC ISO-8601 d'une époque, GNU puis BSD date : champ `fin` des écarts.
30
- iso() {
31
- if date -u -d "@$1" '+%Y-%m-%dT%H:%M:%SZ' >/dev/null 2>&1; then
32
- date -u -d "@$1" '+%Y-%m-%dT%H:%M:%SZ'
33
- else
34
- date -u -r "$1" '+%Y-%m-%dT%H:%M:%SZ'
35
- fi
36
- }
37
-
38
- # État des sessions d'agent en JSON : réutilise les données d'agent_etat,
39
- # agent_ecarts et droits_alertes, sans recopier leur logique.
40
- agent_etat_json() {
41
- local sessions_json='[]' ecarts_json='[]' alertes_json='[]'
42
- local f journal modele debut dernier project en_cours
43
- local e cause d fin fin_iso maintenant
44
-
45
- for f in "$RACINE"/workspace/.agents/*.log; do
46
- [ -e "$f" ] || continue
47
- journal="$(basename "$f")"
48
- session_modele_debut "$f"
49
- session_demande "$f"
50
- modele="$MODELE_SESSION"
51
- [ -n "$modele" ] || modele="inconnu"
52
- debut="$DEBUT_SESSION"
53
- dernier="$(heure "$(mtime "$f")")"
54
- project="${journal%.log}"
55
- en_cours=false
56
- if session_en_cours "$project"; then en_cours=true; fi
57
- sessions_json="$(jq -c \
58
- --arg journal "$journal" \
59
- --arg modele "$modele" \
60
- --arg debut "$debut" \
61
- --arg dernier "$dernier" \
62
- --arg demande "$DEMANDE_SESSION" \
63
- --argjson en_cours "$en_cours" \
64
- '. + [{journal:$journal,modele:$modele,debut:(if $debut=="" then null else $debut end),dernier_ecrit:(if $dernier=="" then null else $dernier end),demande:(if $demande=="" then null else $demande end),en_cours:$en_cours}]' \
65
- <<<"$sessions_json")"
66
- done
67
-
68
- maintenant="$(date +%s)"
69
- for f in "$AGENT_ETAT"/ecart-*; do
70
- [ -e "$f" ] || continue
71
- modele="${f##*/ecart-}"
72
- read -r e cause d <<<"$(cat "$f" 2>/dev/null || true)"
73
- [ -n "$e" ] || continue
74
- fin=$(( e + ${d:-3600} ))
75
- [ "$maintenant" -lt "$fin" ] || continue
76
- fin_iso="$(iso "$fin")"
77
- ecarts_json="$(jq -c \
78
- --arg modele "$modele" \
79
- --arg cause "${cause:-autre}" \
80
- --arg fin "$fin_iso" \
81
- '. + [{modele:$modele,cause:$cause,fin:$fin}]' \
82
- <<<"$ecarts_json")"
83
- done
84
- for f in "$AGENT_ETAT"/muet-*; do
85
- [ -e "$f" ] || continue
86
- modele="${f##*/muet-}"
87
- e="$(cat "$f" 2>/dev/null || true)"
88
- [ -n "$e" ] || continue
89
- fin=$(( e + 3600 ))
90
- [ "$maintenant" -lt "$fin" ] || continue
91
- fin_iso="$(iso "$fin")"
92
- ecarts_json="$(jq -c \
93
- --arg modele "$modele" \
94
- --arg cause "muet" \
95
- --arg fin "$fin_iso" \
96
- '. + [{modele:$modele,cause:$cause,fin:$fin}]' \
97
- <<<"$ecarts_json")"
98
- done
99
-
100
- for f in "$AGENT_ETAT"/droits-*.alerte; do
101
- [ -e "$f" ] || continue
102
- name="${f##*/droits-}"
103
- name="${name%.alerte}"
104
- alertes_json="$(jq -c --arg n "$name" '. + [$n]' <<<"$alertes_json")"
105
- done
106
-
107
- jq -n \
108
- --argjson schema 1 \
109
- --argjson sessions "$sessions_json" \
110
- --argjson ecarts "$ecarts_json" \
111
- --argjson alertes "$alertes_json" \
112
- '{schema:$schema,sessions:$sessions,ecarts:$ecarts,alertes_droits:$alertes}'
113
- }
114
-
115
- agent_etat_json