devzone 0.46.1 → 0.48.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.
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/env bash
2
+ # Manifest and validation helpers for the ephemeral session pod (#222).
3
+ # Sourced by agent-pod.sh.
4
+ # bash 3.2 compatible ; shellcheck -x clean.
5
+
6
+ # --- Defaults ---
7
+
8
+ DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS="${DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS:-1800}"
9
+ DEVZONE_AGENT_POD_CPU_LIMIT="${DEVZONE_AGENT_POD_CPU_LIMIT:-2}"
10
+ DEVZONE_AGENT_POD_MEM_LIMIT="${DEVZONE_AGENT_POD_MEM_LIMIT:-4Gi}"
11
+ DEVZONE_AGENT_POD_TIMEOUT="${DEVZONE_AGENT_POD_TIMEOUT:-$((DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS + 120))}"
12
+ # Projects root, read by the launcher only (no trailing slash). The pod keeps
13
+ # /workspaces/projets in its own environment (DEVZONE_RACINE in the manifest).
14
+ AGENT_POD_ROOT="${DEVZONE_RACINE:-/workspaces/projets}"
15
+ # Module state file on the workspace volume (subPath .devzone.modules, read-only in the pod).
16
+ # shellcheck disable=SC2034 # read by agent-pod.sh
17
+ AGENT_POD_MODULES_FILE="${DEVZONE_AGENT_POD_MODULES_FILE:-${AGENT_POD_ROOT}/.devzone.modules}"
18
+
19
+ # --- Path check : under AGENT_POD_ROOT, only [A-Za-z0-9._/-], no . or .. part ---
20
+
21
+ agent_pod_path_ok() {
22
+ printf '%s' "$AGENT_POD_ROOT" | grep -Eq '^/[A-Za-z0-9._/-]*[A-Za-z0-9._-]$' || return 1
23
+ case "$1" in "$AGENT_POD_ROOT"/*) ;; *) return 1 ;; esac
24
+ printf '%s' "$1" | grep -Eq '^[A-Za-z0-9._/-]+$' || return 1
25
+ case "$1/" in */./* | */../* | *//*) return 1 ;; esac
26
+ return 0
27
+ }
28
+
29
+ # --- State filled by agent_pod_validate_folder ---
30
+
31
+ AGENT_POD_WORKTREE_SUBPATH=""
32
+ AGENT_POD_WORKTREE_MOUNTPATH=""
33
+ AGENT_POD_GIT_SUBPATH=""
34
+ AGENT_POD_GIT_MOUNTPATH=""
35
+ AGENT_POD_SESSION_LABEL=""
36
+ AGENT_POD_TICKET=""
37
+
38
+ # --- Helpers : read the workspace pod (devzone-workspace-0, container workspace) ---
39
+
40
+ agent_pod_image_workspace() {
41
+ local result
42
+ result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.containers[?(@.name=="workspace")].image}' 2>/dev/null)" || true
43
+ echo "${result:-ghcr.io/simbienvenuehoulboumi/devzone-workspace:latest}"
44
+ }
45
+
46
+ agent_pod_path_workspace() {
47
+ local result
48
+ result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.containers[?(@.name=="workspace")].env[?(@.name=="PATH")].value}' 2>/dev/null)" || true
49
+ echo "${result:-/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin}"
50
+ }
51
+
52
+ agent_pod_pvc_workspace() {
53
+ local result
54
+ result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.volumes[?(@.name=="workspace")].persistentVolumeClaim.claimName}' 2>/dev/null)" || true
55
+ echo "${result:-workspace-devzone-workspace-0}"
56
+ }
57
+
58
+ agent_pod_pvc_etat() {
59
+ local result
60
+ result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.volumes[?(@.name=="etat")].persistentVolumeClaim.claimName}' 2>/dev/null)" || true
61
+ echo "${result:-etat-devzone-workspace-0}"
62
+ }
63
+
64
+ # --- Validation of the folder to session ---
65
+
66
+ agent_pod_validate_folder() {
67
+ local folder="$1" gitfile gitdir common base
68
+ if [ -z "$folder" ]; then
69
+ echo "devzone agent --pod : folder missing" >&2
70
+ return 1
71
+ fi
72
+ case "$folder" in
73
+ "$AGENT_POD_ROOT"/*) ;;
74
+ *)
75
+ echo "devzone agent --pod : folder outside the projects root $AGENT_POD_ROOT : $folder" >&2
76
+ return 1
77
+ ;;
78
+ esac
79
+ if ! agent_pod_path_ok "$folder"; then
80
+ echo "devzone agent --pod : invalid folder path : $folder" >&2
81
+ return 1
82
+ fi
83
+ gitfile="$folder/.git"
84
+ if [ ! -f "$gitfile" ]; then
85
+ echo "devzone agent --pod : no .git file (not a git worktree) : $folder" >&2
86
+ return 1
87
+ fi
88
+ gitdir="$(grep '^gitdir:' "$gitfile" 2>/dev/null | head -1 | sed 's/^gitdir:[[:space:]]*//;s/[[:space:]]*$//')"
89
+ if [ -z "$gitdir" ]; then
90
+ echo "devzone agent --pod : .git without gitdir line : $folder" >&2
91
+ return 1
92
+ fi
93
+ case "$gitdir" in
94
+ */worktrees/*) common="${gitdir%/worktrees/*}" ;;
95
+ *)
96
+ echo "devzone agent --pod : gitdir is not a worktree : $gitdir" >&2
97
+ return 1
98
+ ;;
99
+ esac
100
+ case "$common" in
101
+ "$AGENT_POD_ROOT"/*) ;;
102
+ *)
103
+ echo "devzone agent --pod : worktree depot outside the projects root $AGENT_POD_ROOT : $common" >&2
104
+ return 1
105
+ ;;
106
+ esac
107
+ if ! agent_pod_path_ok "$common"; then
108
+ echo "devzone agent --pod : invalid depot path : $common" >&2
109
+ return 1
110
+ fi
111
+ base="$(basename "$folder")"
112
+ if ! printf '%s' "$base" | grep -Eq '^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$'; then
113
+ echo "devzone agent --pod : invalid label value : $base" >&2
114
+ return 1
115
+ fi
116
+ if [ "${#base}" -gt 63 ]; then
117
+ echo "devzone agent --pod : label value too long : $base" >&2
118
+ return 1
119
+ fi
120
+ AGENT_POD_WORKTREE_MOUNTPATH="$folder"
121
+ AGENT_POD_WORKTREE_SUBPATH="${folder#"$AGENT_POD_ROOT"/}"
122
+ AGENT_POD_GIT_MOUNTPATH="$common"
123
+ AGENT_POD_GIT_SUBPATH="${common#"$AGENT_POD_ROOT"/}"
124
+ AGENT_POD_SESSION_LABEL="$base"
125
+ # Keep the ticket only for an exact dz-<number> name.
126
+ if ! printf '%s' "$base" | grep -Eq '^dz-[0-9]+$'; then
127
+ AGENT_POD_TICKET=""
128
+ else
129
+ AGENT_POD_TICKET="${base#dz-}"
130
+ fi
131
+ return 0
132
+ }
133
+
134
+ # --- Build the session pod manifest ---
135
+
136
+ agent_pod_build_manifest() {
137
+ # $2 (the consigne) is never written here: it only goes to the ConfigMap.
138
+ local folder="$1" pod_name="$3"
139
+ local ws_image ws_path pvc_workspace pvc_etat manifest_file ticket_block=""
140
+
141
+ ws_image="$(agent_pod_image_workspace)"
142
+ ws_path="$(agent_pod_path_workspace)"
143
+ pvc_workspace="$(agent_pod_pvc_workspace)"
144
+ pvc_etat="$(agent_pod_pvc_etat)"
145
+
146
+ if [ -n "$AGENT_POD_TICKET" ]; then
147
+ ticket_block=" devzone.io/agent-ticket: \"${AGENT_POD_TICKET}\""
148
+ fi
149
+
150
+ manifest_file="$(mktemp "${TMPDIR:-/tmp}/devzone-agent-pod-manifest.XXXXXX.yaml")"
151
+
152
+ {
153
+ printf '%s\n' "apiVersion: v1"
154
+ printf '%s\n' "kind: Pod"
155
+ printf '%s\n' "metadata:"
156
+ printf '%s\n' " name: ${pod_name}"
157
+ printf '%s\n' " labels:"
158
+ printf '%s\n' " devzone.io/agent-session: ${AGENT_POD_SESSION_LABEL}"
159
+ if [ -n "$ticket_block" ]; then
160
+ printf '%s\n' "$ticket_block"
161
+ fi
162
+ printf '%s\n' "spec:"
163
+ printf '%s\n' " restartPolicy: Never"
164
+ printf '%s\n' " activeDeadlineSeconds: ${DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS}"
165
+ printf '%s\n' " automountServiceAccountToken: false"
166
+ printf '%s\n' " securityContext:"
167
+ printf '%s\n' " runAsUser: 1000"
168
+ printf '%s\n' " runAsGroup: 1000"
169
+ printf '%s\n' " runAsNonRoot: true"
170
+ printf '%s\n' " fsGroup: 1000"
171
+ printf '%s\n' " affinity:"
172
+ printf '%s\n' " podAffinity:"
173
+ printf '%s\n' " requiredDuringSchedulingIgnoredDuringExecution:"
174
+ printf '%s\n' " - labelSelector:"
175
+ printf '%s\n' " matchExpressions:"
176
+ printf '%s\n' " - key: statefulset.kubernetes.io/pod-name"
177
+ printf '%s\n' " operator: In"
178
+ printf '%s\n' " values:"
179
+ printf '%s\n' " - devzone-workspace-0"
180
+ printf '%s\n' " topologyKey: kubernetes.io/hostname"
181
+ printf '%s\n' " containers:"
182
+ printf '%s\n' " - name: agent"
183
+ printf '%s\n' " image: ${ws_image}"
184
+ printf '%s\n' " env:"
185
+ printf '%s\n' " - name: HOME"
186
+ printf '%s\n' " value: \"/home/vscode\""
187
+ printf '%s\n' " - name: NPM_CONFIG_PREFIX"
188
+ printf '%s\n' " value: \"/home/vscode/.local/npm\""
189
+ printf '%s\n' " - name: PATH"
190
+ printf '%s\n' " value: \"${ws_path}\""
191
+ printf '%s\n' " - name: DEVZONE_WORKSPACE"
192
+ printf '%s\n' " value: \"kubernetes\""
193
+ printf '%s\n' " - name: DEVZONE_RACINE"
194
+ printf '%s\n' " value: \"/workspaces/projets\""
195
+ printf '%s\n' " resources:"
196
+ printf '%s\n' " limits:"
197
+ printf '%s\n' " cpu: ${DEVZONE_AGENT_POD_CPU_LIMIT}"
198
+ printf '%s\n' " memory: ${DEVZONE_AGENT_POD_MEM_LIMIT}"
199
+ printf '%s\n' " volumeMounts:"
200
+ printf '%s\n' " - name: workspace"
201
+ printf '%s\n' " mountPath: ${AGENT_POD_WORKTREE_MOUNTPATH}"
202
+ printf '%s\n' " subPath: ${AGENT_POD_WORKTREE_SUBPATH}"
203
+ printf '%s\n' " - name: workspace"
204
+ printf '%s\n' " mountPath: ${AGENT_POD_GIT_MOUNTPATH}"
205
+ printf '%s\n' " subPath: ${AGENT_POD_GIT_SUBPATH}"
206
+ printf '%s\n' " - name: workspace"
207
+ printf '%s\n' " mountPath: /workspaces/projets/.devzone.modules"
208
+ printf '%s\n' " subPath: .devzone.modules"
209
+ printf '%s\n' " readOnly: true"
210
+ printf '%s\n' " - name: etat"
211
+ printf '%s\n' " mountPath: /home/vscode/.config/opencode"
212
+ printf '%s\n' " subPath: .config/opencode"
213
+ printf '%s\n' " - name: etat"
214
+ printf '%s\n' " mountPath: /home/vscode/.local/share/opencode"
215
+ printf '%s\n' " subPath: .local/share/opencode"
216
+ printf '%s\n' " - name: etat"
217
+ printf '%s\n' " mountPath: /home/vscode/.local/state/oc-lancer"
218
+ printf '%s\n' " subPath: .local/state/oc-lancer"
219
+ printf '%s\n' " - name: etat"
220
+ printf '%s\n' " mountPath: /home/vscode/.local/npm"
221
+ printf '%s\n' " subPath: .local/npm"
222
+ printf '%s\n' " readOnly: true"
223
+ printf '%s\n' " - name: consigne"
224
+ printf '%s\n' " mountPath: /agent-consigne"
225
+ printf '%s\n' " readOnly: true"
226
+ printf '%s\n' " - name: session-workspace"
227
+ printf '%s\n' " mountPath: /workspaces/projets/workspace"
228
+ printf '%s\n' " command: [\"/bin/bash\", \"-lc\"]"
229
+ printf '%s\n' " args:"
230
+ printf '%s\n' " - 'devzone agent --local ${folder} /agent-consigne/consigne.md; code=\$?; cat \"\$DEVZONE_RACINE/workspace/.agents/${AGENT_POD_SESSION_LABEL}.log\" 2>/dev/null; exit \$code'"
231
+ printf '%s\n' " volumes:"
232
+ printf '%s\n' " - name: workspace"
233
+ printf '%s\n' " persistentVolumeClaim:"
234
+ printf '%s\n' " claimName: ${pvc_workspace}"
235
+ printf '%s\n' " - name: etat"
236
+ printf '%s\n' " persistentVolumeClaim:"
237
+ printf '%s\n' " claimName: ${pvc_etat}"
238
+ printf '%s\n' " - name: consigne"
239
+ printf '%s\n' " configMap:"
240
+ printf '%s\n' " name: ${pod_name}-consigne"
241
+ printf '%s\n' " - name: session-workspace"
242
+ printf '%s\n' " emptyDir:"
243
+ printf '%s\n' " sizeLimit: 256Mi"
244
+ } >"$manifest_file"
245
+
246
+ echo "$manifest_file"
247
+ }
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env bash
2
+ # Ephemeral session pod for devzone agent (#222).
3
+ # Sourced by agent.sh: launches the session pod (devzone agent --pod), waits for
4
+ # its end, keeps its log, deletes the pod and its ConfigMap, lists session pods (status).
5
+ #
6
+ # Constraints:
7
+ # - bash 3.2 compatible
8
+ # - shellcheck -x clean
9
+ # - no real cluster: kubectl is faked in tests
10
+ # - the pod and its ConfigMap are always deleted (EXIT, INT, TERM trap)
11
+
12
+ ICI="${ICI:-$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
13
+ # shellcheck source=agent-pod-manifest.sh disable=SC1091
14
+ . "${ICI}/agent-pod-manifest.sh"
15
+
16
+ # Resources of the current launch, read by the cleanup trap.
17
+ AGENT_POD_ACTIVE_NAME=""
18
+ AGENT_POD_ACTIVE_MANIFEST=""
19
+ AGENT_POD_CLEANED=0
20
+
21
+ # --- Pod and ConfigMap names ---
22
+
23
+ agent_pod_name() {
24
+ local base="${1:-}"
25
+ if [ -z "$base" ]; then
26
+ base="${AGENT_POD_SESSION_LABEL:-session}"
27
+ else
28
+ base="$(basename "$base")"
29
+ fi
30
+ # Kubernetes object names must be lowercase.
31
+ base="$(printf '%s' "$base" | tr '[:upper:]' '[:lower:]')"
32
+ echo "agent-${base}-$RANDOM"
33
+ }
34
+
35
+ agent_pod_configmap_name() {
36
+ echo "$1-consigne"
37
+ }
38
+
39
+ agent_pod_create_configmap() {
40
+ local pod_name="$1" consigne_file="$2"
41
+ kubectl create configmap "$(agent_pod_configmap_name "$pod_name")" \
42
+ --from-file=consigne.md="$consigne_file" >/dev/null 2>&1
43
+ }
44
+
45
+ agent_pod_delete_configmap() {
46
+ local pod_name="$1"
47
+ kubectl delete configmap "$(agent_pod_configmap_name "$pod_name")" >/dev/null 2>&1 || true
48
+ }
49
+
50
+ # --- Create the pod ---
51
+
52
+ agent_pod_create() {
53
+ local manifest_file="$1"
54
+ kubectl create -f "$manifest_file" >/dev/null 2>&1
55
+ }
56
+
57
+ # --- Wait for the pod to finish ---
58
+
59
+ agent_pod_wait() {
60
+ local pod_name="$1"
61
+ local elapsed=0
62
+ local max_wait="$DEVZONE_AGENT_POD_TIMEOUT"
63
+ local phase=""
64
+
65
+ while [ "$elapsed" -lt "$max_wait" ]; do
66
+ phase="$(kubectl get pod "$pod_name" -o jsonpath='{.status.phase}' 2>/dev/null)" || true
67
+ if [ "$phase" = "Succeeded" ] || [ "$phase" = "Failed" ]; then
68
+ echo "$phase"
69
+ return 0
70
+ fi
71
+ sleep 1
72
+ elapsed=$((elapsed + 1))
73
+ done
74
+
75
+ phase="$(kubectl get pod "$pod_name" -o jsonpath='{.status.phase}' 2>/dev/null)" || true
76
+ echo "${phase:-Unknown}"
77
+ return 1
78
+ }
79
+
80
+ # --- Keep the log of the session ---
81
+
82
+ agent_pod_fetch_logs() {
83
+ local pod_name="$1" journal_file="$2"
84
+ kubectl logs "$pod_name" >>"$journal_file" 2>/dev/null || true
85
+ }
86
+
87
+ # Last lines of the log on stderr: the cause of a failure is there.
88
+ agent_pod_show_tail() {
89
+ local journal_file="$1"
90
+ tail -n 15 "$journal_file" >&2 || true
91
+ }
92
+
93
+ # --- Delete the pod ---
94
+
95
+ agent_pod_delete() {
96
+ local pod_name="$1"
97
+ kubectl delete pod "$pod_name" >/dev/null 2>&1 || true
98
+ }
99
+
100
+ # --- Status : list session pods with their limits ---
101
+
102
+ agent_pod_status() {
103
+ kubectl get pods -l "devzone.io/agent-session" \
104
+ -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].resources.limits.cpu}{"\t"}{.spec.containers[0].resources.limits.memory}{"\n"}{end}' 2>/dev/null || true
105
+ }
106
+
107
+ # --- Cleanup trap: pod, ConfigMap, temporary manifest (not the log) ---
108
+
109
+ agent_pod_cleanup() {
110
+ if [ "$AGENT_POD_CLEANED" = 1 ]; then
111
+ return 0
112
+ fi
113
+ AGENT_POD_CLEANED=1
114
+ if [ -n "$AGENT_POD_ACTIVE_NAME" ]; then
115
+ agent_pod_delete "$AGENT_POD_ACTIVE_NAME"
116
+ agent_pod_delete_configmap "$AGENT_POD_ACTIVE_NAME"
117
+ fi
118
+ if [ -n "$AGENT_POD_ACTIVE_MANIFEST" ]; then
119
+ rm -f "$AGENT_POD_ACTIVE_MANIFEST"
120
+ fi
121
+ return 0
122
+ }
123
+
124
+ # Set before any object is created. INT and TERM leave with 130 / 143;
125
+ # EXIT keeps the exit code of the script.
126
+ agent_pod_set_trap() {
127
+ trap 'agent_pod_cleanup' EXIT
128
+ trap 'agent_pod_cleanup; exit 130' INT
129
+ trap 'agent_pod_cleanup; exit 143' TERM
130
+ }
131
+
132
+ # --- Launch a session agent in an ephemeral pod (devzone agent --pod) ---
133
+
134
+ agent_pod_lancer() {
135
+ local folder_raw="${1:-}" consigne_raw="${2:-}"
136
+ local folder consigne pod_name journal_file phase manifest_file etat
137
+ local rc=0
138
+
139
+ if [ "${DEVZONE_WORKSPACE:-}" != "kubernetes" ]; then
140
+ echo "devzone agent --pod : must be called from the workspace pod (DEVZONE_WORKSPACE=kubernetes)" >&2
141
+ exit 1
142
+ fi
143
+
144
+ if ! agent_pod_path_ok "$folder_raw"; then
145
+ echo "devzone agent --pod : invalid folder path : ${folder_raw:-}" >&2
146
+ exit 1
147
+ fi
148
+ if [ ! -d "$folder_raw" ]; then
149
+ echo "devzone agent --pod : folder not found : $folder_raw" >&2
150
+ exit 1
151
+ fi
152
+ folder="$(cd "$folder_raw" && pwd -P)" || {
153
+ echo "devzone agent --pod : folder not found : $folder_raw" >&2
154
+ exit 1
155
+ }
156
+ if [ ! -r "${consigne_raw:-}" ]; then
157
+ echo "devzone agent --pod : consigne not found : ${consigne_raw:-}" >&2
158
+ exit 1
159
+ fi
160
+ consigne="$(cd "$(dirname "$consigne_raw")" && pwd -P)/$(basename "$consigne_raw")"
161
+
162
+ if ! agent_pod_validate_folder "$folder"; then
163
+ exit 1
164
+ fi
165
+ # The pod mounts this file read-only: refuse before any object is created.
166
+ if [ ! -f "$AGENT_POD_MODULES_FILE" ]; then
167
+ echo "devzone agent --pod : modules file missing : $AGENT_POD_MODULES_FILE (run devzone enable ia on the workspace)" >&2
168
+ exit 1
169
+ fi
170
+
171
+ # The log of the session stays in the agent state directory (shared with the pod).
172
+ etat="${AGENT_ETAT:-$HOME/.local/state/oc-lancer}"
173
+ mkdir -p "$etat"
174
+ journal_file="$etat/${AGENT_POD_SESSION_LABEL}.pod.log"
175
+ : >"$journal_file"
176
+
177
+ pod_name="$(agent_pod_name "$folder")"
178
+ AGENT_POD_ACTIVE_NAME="$pod_name"
179
+ agent_pod_set_trap
180
+
181
+ if ! agent_pod_create_configmap "$pod_name" "$consigne"; then
182
+ echo "devzone agent --pod : unable to create the configmap" >&2
183
+ exit 1
184
+ fi
185
+
186
+ manifest_file="$(agent_pod_build_manifest "$folder" "$consigne" "$pod_name")" || {
187
+ echo "devzone agent --pod : unable to build the manifest" >&2
188
+ exit 1
189
+ }
190
+ AGENT_POD_ACTIVE_MANIFEST="$manifest_file"
191
+
192
+ if ! agent_pod_create "$manifest_file"; then
193
+ echo "devzone agent --pod : unable to create the pod (kubectl create -f)" >&2
194
+ echo "devzone agent --pod : try again without --pod" >&2
195
+ exit 1
196
+ fi
197
+
198
+ phase="$(agent_pod_wait "$pod_name")" || rc=$?
199
+ agent_pod_fetch_logs "$pod_name" "$journal_file"
200
+ echo "=== end of agent session in pod (phase: ${phase:-Unknown})" >>"$journal_file"
201
+ agent_pod_show_tail "$journal_file"
202
+
203
+ if [ "$rc" -ne 0 ]; then
204
+ echo "devzone agent --pod : pod did not finish in time (phase: ${phase:-Unknown}) ; log : $journal_file" >&2
205
+ exit 1
206
+ fi
207
+ if [ "$phase" = "Failed" ]; then
208
+ echo "devzone agent --pod : session ended in failure ; log : $journal_file" >&2
209
+ exit 1
210
+ fi
211
+ echo "devzone agent --pod : session ended (phase: $phase) ; log : $journal_file" >&2
212
+ exit 0
213
+ }
@@ -1,12 +1,6 @@
1
1
  #!/usr/bin/env bash
2
- # Dirige opencode sur une consigne : rotation des modèles gratuits (quota,
3
- # filtre de contenu, modèle indisponible), silence au départ, session figée
4
- # reprise sur une session neuve, permissions sûres. Module ia (#221).
5
- # devzone agent <dossier> <fichier-consigne>
6
- # devzone agent etat
7
- # devzone agent liberer [<modèle>|--tous]
8
- # Au premier plan ; & ou nohup pour plusieurs sessions en parallèle, une par
9
- # dossier (le journal et le rang des modèles sont partagés par instance).
2
+ # Dirige opencode sur une consigne : rotation, silence au depart, reprise.
3
+ # Module ia (#221). devzone agent <dossier> <consigne> | etat | liberer.
10
4
  set -euo pipefail
11
5
  # Dossier du script, liens symboliques suivis à la main : readlink -f n'existe
12
6
  # pas sur macOS (tests sous bash 3.2).
@@ -22,25 +16,21 @@ done
22
16
  ICI="$(cd -P "$(dirname "$SOURCE")" && pwd)"
23
17
  # shellcheck disable=SC2034 # lue par agent-session.sh
24
18
  RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
25
- # Écarts de modèles et attente du réseau (#328)
26
19
  # shellcheck source=agent-erreurs.sh disable=SC1091
27
20
  . "$ICI/agent-erreurs.sh"
28
- # Fichiers de droits des agents protégés (#361)
29
21
  # shellcheck source=agent-droits.sh disable=SC1091
30
22
  . "$ICI/agent-droits.sh"
31
- # Configuration, rang partagé, journal et état (#328)
32
23
  # shellcheck source=agent-session.sh disable=SC1091
33
24
  . "$ICI/agent-session.sh"
34
- # Workspace Kubernetes : projet et journal dans le pod (#431)
35
25
  # shellcheck source=agent-workspace.sh disable=SC1091
36
26
  . "$ICI/agent-workspace.sh"
37
- # Modèle local en dernier de la rotation (#586)
38
27
  # shellcheck source=agent-local.sh disable=SC1091
39
28
  . "$ICI/agent-local.sh"
40
- # Liste de secours si « opencode models opencode » ne répond pas : même ordre
41
- # que la configuration opencode livrée par devzone.
42
29
  FREE_MODELS=(big-pickle deepseek-v4.1-flash-free glm-5.3-flash-free nemotron-3.5-super-vl-free
43
30
  nemotron-3.5-lightning-free mimo-v2.6-flash-free beam-free flint-40b-free nemotron-3-ultra-free)
31
+ # Session pod ephemere (#222)
32
+ # shellcheck source=agent-pod.sh disable=SC1091
33
+ . "$ICI/agent-pod.sh"
44
34
  SILENCE="${DEVZONE_AGENT_SILENCE:-45}"
45
35
  FIGEE="${DEVZONE_AGENT_FIGEE:-600}"
46
36
  AGENT_ETAT="${DEVZONE_AGENT_ETAT:-$HOME/.local/state/oc-lancer}"
@@ -220,6 +210,7 @@ agent_lancer() {
220
210
  exit 3
221
211
  }
222
212
  case "${1:-}" in
213
+ status) agent_pod_status ;;
223
214
  etat) if [ "${2:-}" = "--json" ]; then exec bash "$ICI/agent-etat-json.sh"; else agent_etat; fi ;;
224
215
  liberer)
225
216
  [ -n "${2:-}" ] || { agent_aide >&2; exit 2; }
@@ -231,6 +222,14 @@ case "${1:-}" in
231
222
  exit 2
232
223
  ;;
233
224
  *)
225
+ if [ "${1:-}" = "--pod" ]; then
226
+ shift
227
+ if [ -z "${1:-}" ] || [ -z "${2:-}" ]; then
228
+ agent_aide >&2
229
+ exit 2
230
+ fi
231
+ agent_pod_lancer "$1" "$2"
232
+ fi
234
233
  mode_local=0
235
234
  if [ "${1:-}" = "--local" ]; then
236
235
  mode_local=1
@@ -52,7 +52,7 @@ fi
52
52
  # change pas : deux montées simultanées (workflow versions) se fusionnent sans
53
53
  # conflit, git n'en signalant qu'entre lignes voisines modifiées.
54
54
  # Claude Code
55
- IA_CLAUDE=@anthropic-ai/claude-code@2.1.325
55
+ IA_CLAUDE=@anthropic-ai/claude-code@2.1.326
56
56
  # opencode
57
57
  IA_OPENCODE=opencode-ai@1.19.5
58
58
  IA_PAQUETS=("$IA_CLAUDE" "$IA_OPENCODE")
package/README.md CHANGED
@@ -254,6 +254,8 @@ Dans le conteneur, le récapitulatif `devzone` signale une version publiée plus
254
254
 
255
255
  **Module `argocd`** : Argo CD sur le cluster de devzone, interface sur https://127.0.0.1:8443 dans le conteneur (voir [Argo CD](manage/docs/reference.md#argo-cd)). Pour l'activer : `devzone enable argocd`.
256
256
 
257
+ **Option `devzone agent --pod`** : lance une session agent dans un pod éphémère isolé (ticket #222). Le pod est créé avec des ressources limitées (2 CPU, 4 Gi mémoire), des montages restreints du workspace et de l'état, et une affinité obligatoire vers le pod workspace. Isole : worktree du ticket au même chemin que dans le workspace, .git du dépôt, et sous-dossiers d'état (.config/opencode, .local/share/opencode, .local/state/oc-lancer, .local/npm en lecture seule). N'isole pas : le réseau (non filtré, c'est #220), le kubeconfig de l'hôte, `~/.config/gh`, `~/.claude`, les autres worktrees, et, comme le `.git` du dépôt est monté, les références git des autres branches y restent lisibles et modifiables. Sans `--pod`, le comportement `devzone agent` actuel est strictement inchangé.
258
+
257
259
  Ces modules sont désactivés par défaut, activables à la demande depuis le conteneur (sans rebuild), et leur choix est conservé d'un démarrage à l'autre.
258
260
 
259
261
  La commande `devzone` s'écrit en anglais, sous-commandes et options comprises (`enable`, `disable`, `platform`, `packages`, `update`, `uninstall`, `status`, `use` ; `postgres create`, `packages add`, `gitlab new-password`, `port --close`, `cluster --yes`). Les anciens noms français restent acceptés et écrivent un avertissement ; la table complète est dans [Anciens noms des commandes](manage/docs/reference.md#anciens-noms-des-commandes).
@@ -361,7 +363,7 @@ L'utilisateur d'un projet possède **sa** base (il y crée tables, index, donné
361
363
 
362
364
  ## Voir mon application dans le navigateur
363
365
 
364
- Sur le poste Kubernetes, `devzone workspace start` lance un veilleur de ports : chaque port TCP ≥ 1024 qui écoute dans le pod est relayé sur `127.0.0.1` du poste, au même numéro, par `kubectl port-forward`. Un serveur lancé dans le pod (`npm run dev`, port 5173) répond donc sur `http://localhost:5173`, sans commande. Les services activés (PostgreSQL, MySQL, Argo CD) sont relayés aussi, sur leur port habituel. Le veilleur se pilote avec `devzone workspace ports start|stop|status` ; détails dans la [référence](manage/docs/reference.md#applications-et-services-sur-localhost-du-poste).
366
+ Sur le poste Kubernetes, `devzone workspace start` lance un veilleur de ports : chaque port TCP ≥ 1024 qui écoute dans le pod est relayé sur `127.0.0.1` du poste, au même numéro, par `kubectl port-forward`. Un serveur lancé dans le pod (`npm run dev`, port 5173) répond donc sur `http://localhost:5173`, sans commande. Les services activés (PostgreSQL, MySQL, Argo CD) sont relayés aussi, sur leur port habituel. Les Services des applications déployées dans le cluster sont relayés de la même façon, chacun sur un port local (80 → 8080 ; un port déjà pris ailleurs devient un autre port) : `devzone workspace ports status` affiche leur URL `http://127.0.0.1:<port>`. Un Service peut être exclu avec l'annotation `devzone.io/relay: "false"`. Le veilleur se pilote avec `devzone workspace ports start|stop|status` ; détails dans la [référence](manage/docs/reference.md#applications-et-services-sur-localhost-du-poste).
365
367
 
366
368
  Sur le poste Docker, une application lancée **dans** le conteneur (par exemple un Spring Boot avec `./gradlew bootRun` sur le port 8080) n'est pas joignable depuis le poste : le conteneur devzone ne publie aucun port. Dès qu'elle écoute dans le conteneur, le **veilleur de ports automatiques** (`.devcontainer/ports-auto.sh`) pose un relais `alpine/socat` (version figée) sur le Docker de l'hôte, de `127.0.0.1:<port>` du poste vers le port du conteneur : `http://localhost:<port>` **sans commande**. Le relais disparaît quand l'application s'arrête.
367
369
 
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env bash
2
+ # Applications of the Kubernetes workspace relayed on workstation localhost (#611).
3
+ # Sourced by ports-workspace.sh, never run alone. One kubectl get svc -A per
4
+ # round: each TCP port of each Service gets a local port, kept stable in
5
+ # .devzone.ports-workspace/apps/<namespace>.<service>.<port> while the Service
6
+ # exists. Output lines: "portlocal|namespace|svc/name|remoteport", as pw_services.
7
+
8
+ PA_MAX=30
9
+ # Namespaces never relayed: system ones, and those of the devzone modules
10
+ # (relayed by pw_services, or without any interface).
11
+ PA_NS_SKIP=" kube-system kube-public kube-node-lease local-path-storage devzone-system devzone-workspace devzone-postgres devzone-mysql devzone-argocd devzone-gitlab devzone-llm "
12
+
13
+ # Services of the cluster, one "namespace|name|clusterIP|type|relay annotation|port/proto," line each.
14
+ pa_discover() {
15
+ pw_kubectl get svc -A -o 'jsonpath={range .items[*]}{.metadata.namespace}|{.metadata.name}|{.spec.clusterIP}|{.spec.type}|{.metadata.annotations.devzone\.io/relay}|{range .spec.ports[*]}{.port}/{.protocol},{end}{"\n"}{end}' 2>/dev/null
16
+ }
17
+
18
+ # Is the Service excluded? $1 namespace, $2 name, $3 clusterIP, $4 type, $5 relay annotation.
19
+ pa_excluded() {
20
+ case "$PA_NS_SKIP" in *" $1 "*) return 0 ;; esac
21
+ [ "$1/$2" != default/kubernetes ] || return 0
22
+ [ "$5" != false ] || return 0
23
+ case "$4" in ExternalName) return 0 ;; esac
24
+ case "$3" in '' | None) return 0 ;; esac
25
+ return 1
26
+ }
27
+
28
+ # Is local port $1 free for an application? Not in the list "$2" (" p p "), not taken on the workstation.
29
+ pa_free() {
30
+ case "$2" in *" $1 "*) return 1 ;; esac
31
+ ! pw_taken "$1"
32
+ }
33
+
34
+ # First free local port for Service port $1, given the ports in use "$2": the port itself
35
+ # when >= 1024, else $1 + 8000 (80 -> 8080), then incrementing; past 65000, from 20000.
36
+ pa_new() {
37
+ local c=$(($1 + 8000)) i=0
38
+ if [ "$1" -ge 1024 ] && pa_free "$1" "$2"; then
39
+ echo "$1"
40
+ return 0
41
+ fi
42
+ [ "$c" -le 65000 ] || c=20000
43
+ while [ "$i" -lt 60000 ]; do
44
+ if pa_free "$c" "$2"; then
45
+ echo "$c"
46
+ return 0
47
+ fi
48
+ c=$((c + 1))
49
+ i=$((i + 1))
50
+ [ "$c" -le 65000 ] || c=20000
51
+ done
52
+ return 1
53
+ }
54
+
55
+ # One round of applications, from the ports already wanted "$1" (services, pod).
56
+ # Prints the relay lines; writes apps/ (stable local port) and plafond/ (cap marker),
57
+ # removes the state of Services gone, warns once per port over the cap of PA_MAX.
58
+ pa_round() {
59
+ local d used excl ns name ip type annot ports pp port key stored loc n=0 seen="" f
60
+ d="$(pw_dir)"
61
+ mkdir -p "$d/apps" "$d/plafond"
62
+ excl="$(grep -E '^ports_exclus=' .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2- | tr ',' ' ')"
63
+ used=" $1 $excl "
64
+ while IFS='|' read -r ns name ip type annot ports; do
65
+ [ -n "$ns" ] || continue
66
+ pa_excluded "$ns" "$name" "$ip" "$type" "$annot" && continue
67
+ for pp in ${ports//,/ }; do
68
+ case "$pp" in */TCP) ;; *) continue ;; esac
69
+ port="${pp%/*}"
70
+ case "$port" in '' | *[!0-9]*) continue ;; esac
71
+ key="$ns.$name.$port"
72
+ seen="$seen $key "
73
+ stored="$(cat "$d/apps/$key" 2>/dev/null || true)"
74
+ loc=""
75
+ case "$stored" in '' | *[!0-9]*) ;; *) case "$used" in *" $stored "*) ;; *) loc="$stored" ;; esac ;; esac
76
+ if [ -z "$loc" ]; then
77
+ loc="$(pa_new "$port" "$used")" || { echo "⚠ no free local port for $ns/$name:$port" >&2; continue; }
78
+ fi
79
+ used="$used $loc "
80
+ [ "$loc" = "$stored" ] || printf '%s' "$loc" >"$d/apps/$key"
81
+ if [ "$n" -lt "$PA_MAX" ]; then
82
+ n=$((n + 1))
83
+ rm -f "$d/plafond/$key"
84
+ echo "$loc|$ns|svc/$name|$port"
85
+ elif [ ! -e "$d/plafond/$key" ]; then
86
+ : >"$d/plafond/$key"
87
+ echo "⚠ cap of $PA_MAX application relays reached, $ns/$name:$port not relayed" >&2
88
+ fi
89
+ done
90
+ done <<<"$(pa_discover)"
91
+ for f in "$d"/apps/* "$d"/plafond/*; do
92
+ [ -e "$f" ] || continue
93
+ case "$seen" in *" $(basename "$f") "*) ;; *) rm -f "$f" ;; esac
94
+ done
95
+ }
96
+
97
+ # Status lines of relayed applications: local URL, then namespace/service:port.
98
+ pa_status() {
99
+ local d f key rest loc
100
+ d="$(pw_dir)"
101
+ for f in "$d"/apps/*; do
102
+ [ -e "$f" ] || continue
103
+ loc="$(cat "$f")"
104
+ pw_alive "$(cat "$d/relais/$loc" 2>/dev/null)" || continue
105
+ key="$(basename "$f")"
106
+ rest="${key#*.}"
107
+ echo " http://127.0.0.1:$loc ${key%%.*}/${rest%%.*}:${rest#*.}"
108
+ done
109
+ }
@@ -13,6 +13,9 @@ PW_NS="devzone-workspace"
13
13
  PW_INTERNAL=" 2475 1234 "
14
14
  # pgAdmin service port: read from the service, without it nothing is relayed.
15
15
  PW_JSONPATH='jsonpath={.spec.ports[0].port}'
16
+ # Cluster Services relayed as applications (#611).
17
+ # shellcheck source=manage/scripts/ports-apps.sh
18
+ . "$(dirname "${BASH_SOURCE[0]}")/ports-apps.sh"
16
19
 
17
20
  # Watcher state folder: lock, pid, relays, reported ports, log.
18
21
  pw_dir() { printf '%s' "${DEVZONE_PORTS_WORKSPACE_DIR:-$PWD/.devzone.ports-workspace}"; }
@@ -125,6 +128,11 @@ pw_round() {
125
128
  wanted="$wanted $p "
126
129
  pw_relay "$p" "$PW_NS" "pod/$PW_POD"
127
130
  done
131
+ while IFS='|' read -r p ns target remote; do
132
+ [ -n "$p" ] || continue
133
+ wanted="$wanted $p "
134
+ pw_relay "$p" "$ns" "$target" "$remote"
135
+ done <<<"$(pa_round "$wanted")"
128
136
  for f in "$d"/relais/* "$d"/pris/*; do
129
137
  [ -e "$f" ] || continue
130
138
  l="$(basename "$f")"
@@ -197,6 +205,7 @@ ports_status() {
197
205
  for f in "$d"/pris/*; do
198
206
  if [ -e "$f" ]; then echo " ⚠ port $(basename "$f") already in use on the workstation, not relayed"; fi
199
207
  done
208
+ pa_status
200
209
  return 0
201
210
  }
202
211
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "0.46.1",
3
+ "version": "0.48.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": {