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
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env bash
2
- # Session du superviseur d'agent : configuration opencode, rang partagé, journal,
3
- # état (#328). Bibliothèque sourcée par agent.sh : aucune commande n'est lancée ici.
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
- # Chemin du journal d'un dossier dans workspace/.agents/ : hors dépôt, ignoré par git.
6
- journal_de() {
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
- # Époque de dernière écriture, GNU (stat -c) ou BSD/macOS (stat -f).
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
- # Date UTC lisible d'une époque, GNU puis BSD date : affichée par devzone agent etat.
20
- heure() {
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
- # Trace de verrou dans le journal de l'agent ($AGENT_JOURNAL, défini par
29
- # agent.sh) : une ligne à la prise et une au rendu, avec l'horloge et le pid,
30
- # pour le diagnostic des lancements simultanés du rang en CI (#421). Sans
31
- # journal, rien n'est écrit. Une mention optionnelle (second argument) précise
32
- # le chemin, l'âge ou le pid lu.
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 "=== verrou $1 $d pid $$${2:+ $2}" >>"$AGENT_JOURNAL"
37
+ echo "=== lock $1 $d pid $$${2:+ $2}" >>"$AGENT_JOURNAL"
39
38
  }
40
39
 
41
- # Rang partagé : deux lancements simultanés ne doivent pas partir sur le même
42
- # modèle. mkdir est atomique et présent partout (flock manque sur macOS) ; seul
43
- # l'âge du verrou décide (#377), le pid écrit n'étant qu'un détail de
44
- # diagnostic : un pid lu dans un autre conteneur du volume n'existe pas ici.
45
- # Quand flock existe, la section rang est en outre prise sous son verrou sur
46
- # rang.lock (#421) : si deux mkdir réussissaient, flock sérialise quand même
47
- # la lecture et l'écriture du rang. Chaque branche est tracée (échec mkdir,
48
- # purge, prise) pour établir en CI lequel des deux lancements a réussi mkdir.
49
- verrou_prendre() {
50
- local fin age vpid
51
- fin=$(( $(date +%s) + ${DEVZONE_AGENT_VERROU_MAX:-10} ))
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
- # Un verrou n'est orphelin que par son âge : le rang n'est tenu que
54
- # quelques millisecondes, 30 s ne peut être qu'un arrêt à reprendre,
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
- vpid="$(cat "$AGENT_ETAT/verrou/pid" 2>/dev/null)" || vpid=""
61
- verrou_tracer "échec mkdir" "age=${age:-inconnue} pid-verrou=${vpid:-aucun}"
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
- verrou_tracer "purgé" "age=$age"
63
+ lock_trace "purged" "age=$age"
66
64
  continue
67
65
  fi
68
66
  fi
69
- if [ "$(date +%s)" -ge "$fin" ]; then return 1; fi
67
+ if [ "$(date +%s)" -ge "$end" ]; then return 1; fi
70
68
  sleep 1
71
69
  done
72
- # pid avant flock : l'autre agent ne retire jamais le dossier pendant notre
73
- # attente sur rang.lock, sinon notre écriture de pid tomberait sur ENOENT.
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 dans un if conditionne l'échec au lieu de tuer le shell (bash
77
- # 3.2 comme GNU) ; sans flock, mkdir reste le seul garde-fou (macOS).
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
- AGENT_VERROU_FLOCK=1
77
+ AGENT_LOCK_FLOCK=1
80
78
  else
81
- verrou_lacher
79
+ lock_release
82
80
  return 1
83
81
  fi
84
82
  fi
85
- verrou_tracer pris "chemin=$AGENT_ETAT/verrou"
83
+ lock_trace taken "path=$AGENT_ETAT/verrou"
86
84
  }
87
85
 
88
- # Libère le rang partagé pris par verrou_prendre : retire le pid, puis le dossier,
89
- # mais seulement si ce verrou appartient à l'agent appelant (pid du fichier == $$).
90
- # Un verrou détenu par un autre agent n'est jamais supprimé ici. flock (#421)
91
- # est libéré dans tous les cas, même si le pid lu ne correspond pas : sinon le
92
- # prochain appelant resterait bloqué sur rang.lock.
93
- verrou_lacher() {
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
- verrou_tracer rendu
97
+ lock_trace released
100
98
  fi
101
- if [ "${AGENT_VERROU_FLOCK:-0}" = 1 ]; then
99
+ if [ "${AGENT_LOCK_FLOCK:-0}" = 1 ]; then
102
100
  flock -u 9 2>/dev/null || true
103
101
  exec 9>&-
104
- AGENT_VERROU_FLOCK=0
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 « === rang »
110
- # line is written to the journal in every case. Called in a command
111
- # substitution: the lock is taken and released in that same process.
112
- rang_prendre() {
113
- local etat="$1" journal="$2" debut
114
- verrou_prendre || return 1
115
- debut=$(( $(cat "$etat/rang" 2>/dev/null || echo 0) % ${#FREE_MODELS[@]} ))
116
- if [ "$PAUSE_RANG" -gt 0 ]; then sleep "$PAUSE_RANG"; fi
117
- if modele_rang_avance; then echo $(( debut + 1 )) >"$etat/rang"; fi
118
- verrou_lacher
119
- echo "=== rang $(( debut + 1 ))/${#FREE_MODELS[@]}" >>"$journal"
120
- echo "$debut"
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
- # Passe permission.edit en objet et ajoute en dernier un deny par fichier de droits
124
- # (#361) : la dernière règle qui correspond l'emporte, l'appelant ne peut pas le retirer.
125
- droits_edit_deny() {
126
- local motifs f
127
- motifs="[]"
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
- motifs="$(jq -c --arg f "$f" '. + [$f, "**/" + $f]' <<<"$motifs")"
127
+ patterns="$(jq -c --arg f "$f" '. + [$f, "**/" + $f]' <<<"$patterns")"
130
128
  done
131
- jq -ce --argjson m "$motifs" '
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 $m[] as $k ($o; del(.[$k])) + ($m | map({(.): "deny"}) | add))
132
+ .permission.edit = (reduce $patterns[] as $k ($o; del(.[$k])) + ($patterns | map({(.): "deny"}) | add))
135
133
  ' <<<"$1"
136
134
  }
137
135
 
138
- # Configuration sûre : agent.json par défaut, complétée par
139
- # OPENCODE_CONFIG_CONTENT s'il est défini. opencode applique la dernière règle
140
- # qui correspond : les deny de devzone sont donc retirés de la fusion puis
141
- # ré-ajoutés à la fin (l'ordre des clés d'un objet jq est l'ordre d'insertion),
142
- # si bien que l'appelant peut ajouter des permissions, jamais retirer un interdit
143
- # de devzone. ~/bash32 est toujours protégé : le bash 3.2 du conteneur a déjà
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 par défaut absente : $def"
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 "configuration opencode illisible : rien lancé"
156
+ refuse "opencode configuration unreadable: nothing launched"
160
157
  else
161
- config="$(jq -ce . "$def")" || refuse "configuration opencode illisible : rien lancé"
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 "configuration opencode illisible : rien lancé"
172
- config="$(droits_edit_deny "$config")" || refuse "configuration opencode illisible : rien lancé"
173
- grep -q '"git push\*":"deny"' <<<"$config" || refuse "git push non interdit : rien lancé"
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
- # Modèles gratuits de la version installée, préfixe « opencode/ » retiré :
178
- # « opencode models opencode » peut rendre « opencode/big-pickle ».
179
- liste_modeles() {
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 && !vu[$0]++' || true)"
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
- # Modèle et début d'une session (#308) : lus uniquement sur la dernière ligne
191
- # « === modèle opencode/? début » du superviseur ; le texte écrit par le
192
- # modèle dans le journal (un « opencode/agent.json » possible) n'est pas lu.
193
- session_modele_debut() {
194
- local ligne
195
- ligne="$(grep '^=== modèle opencode/' "$1" 2>/dev/null | tail -1 || true)"
196
- MODELE_SESSION="$(sed -nE 's/^=== modèle opencode\/([^ ]+) début .*/\1/p' <<<"$ligne")"
197
- DEBUT_SESSION="$(sed -nE 's/.* début ([^ ]+).*/\1/p' <<<"$ligne")"
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
- # « === --modele : » of the journal, empty when nothing was asked.
202
- session_demande() {
203
- local ligne
204
- ligne="$(grep '^=== --modele : ' "$1" 2>/dev/null | tail -1 || true)"
205
- DEMANDE_SESSION="${ligne#=== --modele : }"
206
- if [ "$DEMANDE_SESSION" = aucun ]; then DEMANDE_SESSION=""; fi
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
- # Une session est en cours (#308) si un processus agent.sh vivant a pour
210
- # premier argument (le dossier, absolu depuis #287) un chemin dont le nom est
211
- # exactement le journal sans « .log » ; un simple dossier contenant ce nom ne
212
- # suffit pas, ni un chemin qui ne serait pas le dossier d'un agent.
213
- session_en_cours() {
214
- local ligne dossier
215
- while IFS= read -r ligne; do
216
- case "$ligne" in
217
- *agent.sh\ *) dossier="${ligne#*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
- dossier="${dossier%% *}"
221
- [ -n "$dossier" ] || continue
222
- if [ "$(basename "$dossier")" = "$1" ]; then return 0; fi
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
- # Sessions connues (journal, dernier modèle, début, dernier écrit) et modèles
228
- # écartés par le superviseur, avec l'heure de fin d'écart.
229
- agent_etat() {
230
- local f m debut dernier vu=0
231
- echo "devzone agent : état"
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
- vu=1
235
- session_modele_debut "$f"
236
- m="${MODELE_SESSION:+opencode/$MODELE_SESSION}"
237
- debut="$DEBUT_SESSION"
238
- dernier="$(heure "$(mtime "$f")")"
239
- session_demande "$f"
240
- echo " session $(basename "$f") : modèle ${m:-inconnu}${DEMANDE_SESSION:+ (demandé : $DEMANDE_SESSION)}, depuis ${debut:-inconnu}, dernier écrit $dernier"
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
- [ "$vu" = 1 ] || echo " aucune session"
243
- agent_ecarts
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