devzone 0.50.6 → 0.52.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.
@@ -1,36 +1,62 @@
1
1
  #!/usr/bin/env bash
2
2
  # Local model in the rotation of devzone agent (#586), sourced by agent.sh.
3
- # The model devzone-llm/local comes after every online model (never first, never
4
- # when the module llm is off or the server does not answer /health): it is used
5
- # when the online ones are all set aside (quota, network). Its internal name has
6
- # no slash (a file ecart-<name> is written for it); opencode gets the reference.
3
+ # The local slot is first the host model (Ollama answers /api/tags with at
4
+ # least one model, reference devzone-host/<model>), otherwise the llm module's
5
+ # local model (devzone-llm/local, cluster / relay /health). It always comes
6
+ # after every online model; its internal name has no slash (an ecart-<name>
7
+ # file is written for it); opencode gets the reference.
7
8
  LOCAL_NOM=devzone-llm-local
9
+ # Real host model name (Ollama) chosen for this attempt, empty otherwise.
10
+ LOCAL_HOTE_REEL=""
11
+ # Internal (slash-free) name of the host model chosen for this attempt.
12
+ LOCAL_HOTE_INTERNE=""
8
13
 
9
- # Prints LOCAL_NOM when the module is on (in the pod: the cluster answers) and
10
- # the server answers /health
11
- local_pret() {
12
- local url
14
+ # shellcheck source=SCRIPTDIR/ia/host-models.sh
15
+ # shellcheck disable=SC1091
16
+ . "$ICI/ia/host-models.sh"
17
+
18
+ # Sanitizes a model name into an internal name: every character outside
19
+ # [A-Za-z0-9._-] becomes '_'. Used for ecart-<name> files, the journal and
20
+ # the rotation, so a host model such as hf.co/org/model:tag never creates a
21
+ # nested or invalid path.
22
+ nom_interne() {
23
+ printf '%s' "$1" | sed 's/[^A-Za-z0-9._-]/_/g'
24
+ }
25
+
26
+ # Sets LOCAL_MODELE for this attempt, read by modele_au_rang and
27
+ # modeles_total. Also records the real host model name when the host is chosen.
28
+ local_charge() {
29
+ local nom url
30
+ LOCAL_HOTE_REEL=""
31
+ LOCAL_HOTE_INTERNE=""
32
+ nom="$(premier 2>/dev/null || true)"
33
+ if [ -n "$nom" ]; then
34
+ LOCAL_HOTE_REEL="$nom"
35
+ LOCAL_HOTE_INTERNE="$(nom_interne "$nom")"
36
+ LOCAL_MODELE="$LOCAL_HOTE_INTERNE"
37
+ return 0
38
+ fi
39
+ # Fallback: the llm module local model (cluster / relay).
40
+ LOCAL_MODELE=""
13
41
  if [ "${DEVZONE_WORKSPACE:-}" != kubernetes ]; then
14
42
  bash "$ICI/devzone" is-enabled llm >/dev/null 2>&1 || return 0
15
43
  fi
16
44
  url="$(bash "$ICI/llm/opencode.sh" url)" || return 0
17
- curl -fsS --max-time 3 "${url%/v1}/health" >/dev/null 2>&1 && echo "$LOCAL_NOM"
45
+ if curl -fsS --max-time 3 "${url%/v1}/health" >/dev/null 2>&1; then
46
+ LOCAL_MODELE="$LOCAL_NOM"
47
+ fi
18
48
  return 0
19
49
  }
20
50
 
21
- # Sets LOCAL_MODELE for this attempt (local_pret), read by modele_au_rang and
22
- # modeles_total
23
- local_charge() {
24
- LOCAL_MODELE="$(local_pret)"
25
- }
26
-
27
51
  # Model reference given to opencode -m
28
52
  modele_ref() {
29
- if [ "$1" = "$LOCAL_NOM" ]; then echo devzone-llm/local; else echo "opencode/$1"; fi
53
+ if [ "$1" = "$LOCAL_NOM" ]; then echo devzone-llm/local;
54
+ elif [ -n "$LOCAL_HOTE_INTERNE" ] && [ "$1" = "$LOCAL_HOTE_INTERNE" ]; then echo "devzone-host/$LOCAL_HOTE_REEL";
55
+ else echo "opencode/$1"; fi
30
56
  }
31
57
 
32
58
  # Model of rank $1 in the attempt that starts at $2: online ones in rotation,
33
- # then the local one
59
+ # then the local one (host or llm module)
34
60
  modele_au_rang() {
35
61
  if [ "$1" -lt "${#FREE_MODELS[@]}" ]; then
36
62
  echo "${FREE_MODELS[$(( ($2 + $1) % ${#FREE_MODELS[@]} ))]}"
@@ -41,5 +67,7 @@ modele_au_rang() {
41
67
 
42
68
  # Number of models to try: the online ones, plus the local one if ready
43
69
  modeles_total() {
44
- echo $(( ${#FREE_MODELS[@]} + ${#LOCAL_MODELE} / ${#LOCAL_NOM} ))
70
+ local total="${#FREE_MODELS[@]}"
71
+ [ -n "$LOCAL_MODELE" ] && total=$((total + 1))
72
+ echo "$total"
45
73
  }
@@ -16,6 +16,7 @@ command_canonical() {
16
16
  is-enabled) echo actif ;;
17
17
  enable) echo activer ;;
18
18
  disable) echo desactiver ;;
19
+ ai) echo ia ;;
19
20
  help) echo aide ;;
20
21
  apply) echo appliquer ;;
21
22
  catalog) echo catalogue ;;
@@ -45,6 +46,7 @@ command_english() {
45
46
  actif) echo is-enabled ;;
46
47
  activer) echo enable ;;
47
48
  desactiver) echo disable ;;
49
+ ia) echo ai ;;
48
50
  aide) echo help ;;
49
51
  appliquer) echo apply ;;
50
52
  catalogue) echo catalog ;;
@@ -9,8 +9,7 @@
9
9
  "jdkDistro": "tem",
10
10
  "installMaven": true,
11
11
  "installGradle": true,
12
- "gradleVersion": "9.8.2",
13
- "mavenVersion": "3.9.8"
12
+ "gradleVersion": "9.8.2"
14
13
  },
15
14
  "ghcr.io/devcontainers/features/node:1": {
16
15
  "version": "lts",
@@ -50,6 +50,10 @@ fi
50
50
  # shellcheck source=SCRIPTDIR/etat-gitops.sh
51
51
  # shellcheck disable=SC1091
52
52
  . "$ICI/etat-gitops.sh"
53
+ # Detection of the host (Ollama) models and the devzone-host opencode provider (#665).
54
+ # shellcheck source=SCRIPTDIR/ia/host-models.sh
55
+ # shellcheck disable=SC1091
56
+ . "$ICI/ia/host-models.sh"
53
57
 
54
58
  # Assistants IA, versions figées : mettre à jour ici, puis devzone apply
55
59
  # (ou Rebuild Container). Une ligne par paquet, séparées par une ligne qui ne
@@ -396,8 +400,79 @@ installer_ia() {
396
400
  [ "${#IA_FAILED[@]}" -eq 0 ]
397
401
  }
398
402
 
403
+ # Docker guard for the folders that are not this repository: a Claude Code
404
+ # PreToolUse hook in the global settings and the two opencode plugins in the
405
+ # global plugins folder. Idempotent, other user settings and hooks preserved.
406
+ poser_garde_docker() {
407
+ local script="$ICI/ia/docker-garde.sh" config="$HOME/.claude/settings.json"
408
+ local src="$ICI/ia/plugins" dst="$HOME/.config/opencode/plugins"
409
+ local tmp f
410
+ if ! command -v jq >/dev/null 2>&1; then
411
+ echo "devzone : jq absent : garde-fou docker non posé pour Claude Code" >&2
412
+ elif [ ! -f "$config" ]; then
413
+ echo "devzone : $config absent : garde-fou docker non posé pour Claude Code" >&2
414
+ elif ! jq -e . "$config" >/dev/null 2>&1; then
415
+ echo "devzone : $config illisible (JSON invalide) : garde-fou docker non posé pour Claude Code" >&2
416
+ else
417
+ tmp="$(mktemp)"
418
+ if jq --arg cmd "bash \"$script\" --format claude" '
419
+ .hooks = (.hooks // {}) |
420
+ .hooks.PreToolUse = (.hooks.PreToolUse // []) |
421
+ if ([.hooks.PreToolUse[]? | .hooks[]? | (.command // "")] | any(contains("docker-garde.sh")))
422
+ then .
423
+ else .hooks.PreToolUse += [{"matcher": "Bash", "hooks": [{"type": "command", "command": $cmd}]}]
424
+ end
425
+ ' "$config" >"$tmp" 2>/dev/null; then
426
+ mv "$tmp" "$config"
427
+ else
428
+ rm -f "$tmp"
429
+ echo "devzone : $config inchangé : garde-fou docker non posé pour Claude Code" >&2
430
+ fi
431
+ fi
432
+ mkdir -p "$dst"
433
+ for f in devzone-garde.js devzone-garde-v2.js; do
434
+ [ -f "$src/$f" ] || continue
435
+ sed "s|__DEVZONE_DOCKER_GARDE__|$script|g" "$src/$f" >"$dst/$f"
436
+ done
437
+ echo "devzone : garde-fou docker actif pour Claude Code et opencode"
438
+ }
439
+
440
+ # Removes only the Docker guard entries (commands containing docker-garde.sh)
441
+ # and the two plugins; the rest of settings.json and of the plugins is kept.
442
+ retirer_garde_docker() {
443
+ local config="$HOME/.claude/settings.json" tmp
444
+ if [ -f "$config" ] && jq -e . "$config" >/dev/null 2>&1; then
445
+ tmp="$(mktemp)"
446
+ if jq '
447
+ if (.hooks.PreToolUse // null) != null then
448
+ .hooks.PreToolUse = [
449
+ .hooks.PreToolUse[] |
450
+ if (.hooks // null) != null then
451
+ .hooks = [ .hooks[] | select(((.command // "") | contains("docker-garde.sh")) | not) ] |
452
+ select((.hooks | length) > 0)
453
+ else
454
+ select(((.command // "") | contains("docker-garde.sh")) | not)
455
+ end
456
+ ] |
457
+ if (.hooks.PreToolUse | length) == 0 then del(.hooks.PreToolUse) else . end |
458
+ if ((.hooks // {}) | keys | length) == 0 then del(.hooks) else . end
459
+ else . end
460
+ ' "$config" >"$tmp" 2>/dev/null; then
461
+ if [ "$(cat "$tmp")" = "{}" ]; then
462
+ rm -f "$tmp" "$config"
463
+ else
464
+ mv "$tmp" "$config"
465
+ fi
466
+ else
467
+ rm -f "$tmp"
468
+ fi
469
+ fi
470
+ rm -f "$HOME/.config/opencode/plugins/devzone-garde.js" \
471
+ "$HOME/.config/opencode/plugins/devzone-garde-v2.js"
472
+ }
473
+
399
474
  appliquer_ia() {
400
- local journal tmp
475
+ local journal tmp detectes
401
476
  if [ "$1" = on ]; then
402
477
  echo "devzone : installation de Claude Code et opencode (quelques minutes)…"
403
478
  if ! installer_ia; then
@@ -417,7 +492,18 @@ appliquer_ia() {
417
492
  else
418
493
  echo "devzone : garde-fou repowarden non branché (repowarden 4.10 ou plus requis) : repowarden agents init --global" >&2
419
494
  fi
495
+ poser_garde_docker
420
496
  config_opencode
497
+ # Provider opencode des modèles de l'hôte (Ollama), détection à chaud :
498
+ # silencieux et sans effet si Ollama ne répond pas.
499
+ set_provider || true
500
+ # Signale l'état de la détection (succès dans les deux cas).
501
+ detectes="$(modeles 2>/dev/null || true)"
502
+ if [ -n "$detectes" ]; then
503
+ printf "devzone : %s modèle(s) de l'hôte (Ollama) branché(s)\n" "$(printf '%s\n' "$detectes" | grep -c .)"
504
+ else
505
+ printf "devzone : aucun modèle Ollama détecté sur %s (modèles de l'hôte non branchés)\n" "$URL"
506
+ fi
421
507
  # Skill devzone : posée si absente, mise à jour si inchangée, gardée si personnalisée.
422
508
  poser_skill_devzone
423
509
  echo "devzone : ia actif : claude (puis /login), opencode auth login"
@@ -457,9 +543,13 @@ appliquer_ia() {
457
543
  # Plugin opencode du garde-fou (retiré aussi par repowarden ci-dessus)
458
544
  rm -f "$HOME/.config/opencode/plugins/repowarden-garde.js" \
459
545
  "$HOME/.config/opencode/plugins/repowarden-garde-v2.js"
546
+ # Garde-fou docker : seules ses entrées et ses plugins sont retirés.
547
+ retirer_garde_docker
460
548
  # Configuration opencode : retirée seulement si elle porte le repère devzone
461
549
  # et n'a pas été modifiée ; personnalisée → gardée.
462
550
  retirer_config_opencode
551
+ # Retire le fournisseur opencode des modèles de l'hôte, garde le reste du fichier.
552
+ unset_provider || true
463
553
  # Skill devzone : retirée seulement si non modifiée ; personnalisée → gardée.
464
554
  retirer_skill_devzone
465
555
  # État de devzone agent : gardé dans le volume partagé (désactivation
@@ -1441,6 +1531,20 @@ case "${1:-}" in
1441
1531
  agent)
1442
1532
  bash "$ICI/agent.sh" "${@:2}"
1443
1533
  ;;
1534
+ ia)
1535
+ # Read-only: lists the host (Ollama) models detected and the default model.
1536
+ liste="$(modeles)"
1537
+ def="$(premier)"
1538
+ if [ -z "$liste" ]; then
1539
+ echo "devzone : aucun modèle Ollama détecté sur ${URL} (répondez sur /api/tags)"
1540
+ else
1541
+ echo "devzone : modèles détectés sur l'hôte (Ollama) :"
1542
+ while IFS= read -r m; do
1543
+ [ -n "$m" ] && printf ' %s\n' "$m"
1544
+ done <<<"$liste"
1545
+ echo "modèle par défaut : ${def:-aucun}"
1546
+ fi
1547
+ ;;
1444
1548
  ticket) bash "$ICI/ticket.sh" "${@:2}" ;;
1445
1549
  build)
1446
1550
  bash "$ICI/workspace-build.sh" "${@:2}"
@@ -21,6 +21,7 @@ devzone_aide() {
21
21
  devzone test-bash32 run the bats tests under bash 3.2 (Docker container)
22
22
  devzone test-gitlab end-to-end test of the GitLab module and platform
23
23
  devzone agent <folder> <instructions> drive opencode with the instructions file
24
+ devzone ai | ia list the host (Ollama) models detected and the default model
24
25
  devzone ticket <n> [--repo devzone|repowarden] ticket worktree (ticket done <n> removes it)
25
26
  devzone build <folder> [--tag <name>] build an image in the Kubernetes workspace (BuildKit)
26
27
  devzone enable postgres [--context CTX] [--confirm CTX] shared PostgreSQL, cluster of choice
@@ -0,0 +1 @@
1
+ devzone est Kubernetes d'abord : seuls les pods sont des conteneurs. Utilise kubectl, ou un pod ou un namespace jetable (kubectl run, kubectl create ns, puis suppression). Action sur l'hôte lui-même : DEVZONE_ALLOW_DOCKER=1.
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env bash
2
+ # Guard: block Docker commands run by agents (Kubernetes-first). #670
3
+ # Reads tool call JSON on stdin (opencode, or --format claude) and exits 2 on
4
+ # stderr when a shell command runs docker/docker-compose as the command word.
5
+ # With python3, one program parses the JSON and detects. Otherwise jq extracts
6
+ # the tool and command and a best-effort shell detection runs. Without either,
7
+ # nothing is blocked.
8
+
9
+ set -u
10
+
11
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+ MESSAGE_FILE="$SCRIPT_DIR/docker-garde.message"
13
+ FALLBACK="devzone is Kubernetes-first: only pods are containers. Use kubectl, or a throwaway pod or namespace. Host action: set DEVZONE_ALLOW_DOCKER to 1."
14
+ MESSAGE="$FALLBACK"
15
+ if [ -r "$MESSAGE_FILE" ]; then
16
+ MESSAGE="$(cat "$MESSAGE_FILE" 2>/dev/null)" || MESSAGE="$FALLBACK"
17
+ fi
18
+
19
+ [ "${DEVZONE_ALLOW_DOCKER:-}" = "1" ] && exit 0
20
+
21
+ FORMAT="opencode"
22
+ [ "${1:-}" = "--format" ] && [ "${2:-}" = "claude" ] && FORMAT="claude"
23
+
24
+ INPUT="$(cat 2>/dev/null)" || exit 0
25
+ [ -n "$INPUT" ] || exit 0
26
+
27
+ block() { printf '%s\n' "$MESSAGE" >&2; exit 2; }
28
+
29
+ if command -v python3 >/dev/null 2>&1; then
30
+ __DG_INPUT="$INPUT" __DG_FORMAT="$FORMAT" __DG_MESSAGE="$MESSAGE" python3 <<'PYTHON'
31
+ import json, os, re, sys
32
+
33
+ try:
34
+ data = json.loads(os.environ.get("__DG_INPUT", ""))
35
+ except Exception:
36
+ sys.exit(0)
37
+ if not isinstance(data, dict):
38
+ sys.exit(0)
39
+ if os.environ.get("__DG_FORMAT", "opencode") == "claude":
40
+ tool = data.get("tool_name") or ""
41
+ inner = data.get("tool_input")
42
+ else:
43
+ tool = data.get("tool") or ""
44
+ inner = data.get("args")
45
+ cmd = (inner.get("command") if isinstance(inner, dict) else "") or ""
46
+ if tool not in ("bash", "shell", "Bash") or not isinstance(cmd, str) or not cmd:
47
+ sys.exit(0)
48
+
49
+ def is_word(seg, i):
50
+ return re.match(r"docker-compose\b|docker\b", seg[i:]) is not None
51
+
52
+ def at_pos(seg):
53
+ i = 0
54
+ while True:
55
+ while i < len(seg) and seg[i] in " \t\n\r(": i += 1
56
+ while i < len(seg) and seg[i] == "`": i += 1
57
+ changed = True
58
+ while changed:
59
+ changed = False
60
+ m = re.match(r"[A-Za-z_]\w*=", seg[i:])
61
+ if m:
62
+ i += m.end()
63
+ if i < len(seg) and seg[i] in "\"'":
64
+ q = seg[i]; i += 1
65
+ while i < len(seg) and seg[i] != q:
66
+ if q == '"' and seg[i] == '\\': i += 2
67
+ else: i += 1
68
+ if i < len(seg): i += 1
69
+ else:
70
+ while i < len(seg) and seg[i] not in " \t\n\r;&|)`": i += 1
71
+ while i < len(seg) and seg[i] in " \t\n\r": i += 1
72
+ changed = True
73
+ if seg.startswith("sudo", i) and (i + 4 == len(seg) or not (seg[i + 4].isalnum() or seg[i + 4] in "_-")):
74
+ i += 4
75
+ while i < len(seg) and seg[i] in " \t\n\r": i += 1
76
+ while i < len(seg) and seg[i] == "-":
77
+ while i < len(seg) and seg[i] not in " \t\n\r": i += 1
78
+ while i < len(seg) and seg[i] in " \t\n\r": i += 1
79
+ continue
80
+ return i
81
+
82
+ def split_segs(s):
83
+ parts, i, start, n, q, d = [], 0, 0, len(s), None, 0
84
+ while i < n:
85
+ c = s[i]
86
+ if q:
87
+ if q == "'":
88
+ if c == "'": q = None
89
+ elif q == '"':
90
+ if c == '\\': i += 2; continue
91
+ if c == '"': q = None
92
+ else:
93
+ if c == "`": q = None
94
+ i += 1; continue
95
+ if c == '\\': i += 2; continue
96
+ if c in "\"'`": q = c; i += 1; continue
97
+ if c == "$" and i + 1 < n and s[i + 1] == "(": d += 1; i += 2; continue
98
+ if c == "(": d += 1; i += 1; continue
99
+ if c == ")" and d > 0: d -= 1; i += 1; continue
100
+ if d == 0:
101
+ if c in ";\n":
102
+ parts.append(s[start:i]); start = i + 1; i += 1; continue
103
+ if c == "&" and i + 1 < n and s[i + 1] == "&":
104
+ parts.append(s[start:i]); start = i + 2; i += 2; continue
105
+ if c == "|" and i + 1 < n and s[i + 1] == "|":
106
+ parts.append(s[start:i]); start = i + 2; i += 2; continue
107
+ if c == "|":
108
+ parts.append(s[start:i]); start = i + 1; i += 1; continue
109
+ i += 1
110
+ parts.append(s[start:])
111
+ return parts
112
+
113
+ def subshells(s):
114
+ out, i, n, q = [], 0, len(s), None
115
+ while i < n:
116
+ c = s[i]
117
+ if q == "'":
118
+ if c == "'": q = None
119
+ i += 1; continue
120
+ if q == '"':
121
+ if c == '\\': i += 2; continue
122
+ if c == '"': q = None; i += 1; continue
123
+ if c == "`":
124
+ j = i + 1
125
+ while j < n and s[j] != "`": j += 1
126
+ out.append(s[i + 1:j]); i = j + 1; continue
127
+ if c == "$" and i + 1 < n and s[i + 1] == "(": pass
128
+ else: i += 1; continue
129
+ if c == '\\' and q != "'": i += 2; continue
130
+ if c == "'" and q is None: q = "'"; i += 1; continue
131
+ if c == '"' and q is None: q = '"'; i += 1; continue
132
+ if c == "`" and q != "'":
133
+ j = i + 1
134
+ while j < n and s[j] != "`": j += 1
135
+ out.append(s[i + 1:j]); i = j + 1; continue
136
+ if c == "$" and i + 1 < n and s[i + 1] == "(" and q != "'":
137
+ j, depth, q2 = i + 2, 1, None
138
+ while j < n and depth > 0:
139
+ ch = s[j]
140
+ if q2:
141
+ if q2 == "'":
142
+ if ch == "'": q2 = None
143
+ elif q2 == '"':
144
+ if ch == '\\': j += 2; continue
145
+ if ch == '"': q2 = None
146
+ j += 1; continue
147
+ if ch == '\\': j += 2; continue
148
+ if ch in "\"'": q2 = ch; j += 1; continue
149
+ if ch == "$" and j + 1 < n and s[j + 1] == "(": depth += 1; j += 2; continue
150
+ if ch == "(": depth += 1; j += 1; continue
151
+ if ch == ")": depth -= 1; j += 1; continue
152
+ j += 1
153
+ out.append(s[i + 2:j - 1] if j > i + 2 else ""); i = j; continue
154
+ if q == '"': i += 1; continue
155
+ i += 1
156
+ return out
157
+
158
+ def c_args(s):
159
+ out = []
160
+ for m in re.finditer(r"(^|\s)-c\s+(['\"])(.*?)\2", s, re.DOTALL):
161
+ out.append(m.group(3))
162
+ return out
163
+
164
+ def check(s, depth=0):
165
+ if depth > 4: return False
166
+ for seg in split_segs(s):
167
+ if is_word(seg, at_pos(seg)): return True
168
+ for inner in c_args(s):
169
+ if check(inner, depth + 1): return True
170
+ for sub in subshells(s):
171
+ if check(sub, depth + 1): return True
172
+ return False
173
+
174
+ if check(cmd):
175
+ sys.stderr.write(os.environ.get("__DG_MESSAGE", "") + "\n")
176
+ sys.exit(2)
177
+ sys.exit(0)
178
+ PYTHON
179
+ exit $?
180
+ fi
181
+
182
+ if command -v jq >/dev/null 2>&1; then
183
+ if [ "$FORMAT" = "claude" ]; then
184
+ TOOL="$(printf '%s' "$INPUT" | jq -r '.tool_name // ""' 2>/dev/null)" || exit 0
185
+ COMMAND="$(printf '%s' "$INPUT" | jq -r '.tool_input.command // ""' 2>/dev/null)" || exit 0
186
+ else
187
+ TOOL="$(printf '%s' "$INPUT" | jq -r '.tool // ""' 2>/dev/null)" || exit 0
188
+ COMMAND="$(printf '%s' "$INPUT" | jq -r '.args.command // ""' 2>/dev/null)" || exit 0
189
+ fi
190
+
191
+ shell_fallback_detect() {
192
+ # Best-effort fallback when python3 is unavailable (jq-only path).
193
+ local c="$COMMAND" segs s
194
+ segs="$(printf '%s' "$c" | sed -E 's/&&/\n/g; s/\|\|/\n/g; s/[;|]/\n/g; s/\$\(/\n/g; s/`/\n/g')"
195
+ while IFS= read -r s; do
196
+ s="$(printf '%s' "$s" | sed 's/^[[:space:]()]*//')"
197
+ while printf '%s' "$s" | grep -qE '^[A-Za-z_][A-Za-z0-9_]*='; do
198
+ s="$(printf '%s' "$s" | sed -E 's/^[A-Za-z_][A-Za-z0-9_]*=([^[:space:]]*)[[:space:]]*//; s/^[A-Za-z_][A-Za-z0-9_]*=[[:space:]]*//')"
199
+ done
200
+ if printf '%s' "$s" | grep -qE '^sudo([[:space:]]|$)'; then
201
+ s="$(printf '%s' "$s" | sed -E 's/^sudo[[:space:]]+//')"
202
+ while printf '%s' "$s" | grep -qE '^-[^[:space:]]*'; do
203
+ s="$(printf '%s' "$s" | sed -E 's/^-[^[:space:]]*[[:space:]]*//')"
204
+ done
205
+ while printf '%s' "$s" | grep -qE '^[A-Za-z_][A-Za-z0-9_]*='; do
206
+ s="$(printf '%s' "$s" | sed -E 's/^[A-Za-z_][A-Za-z0-9_]*=([^[:space:]]*)[[:space:]]*//; s/^[A-Za-z_][A-Za-z0-9_]*=[[:space:]]*//')"
207
+ done
208
+ fi
209
+ if printf '%s' "$s" | grep -qE '^(docker-compose|docker)([[:space:]]|$)'; then
210
+ return 0
211
+ fi
212
+ done <<EOF
213
+ $segs
214
+ EOF
215
+ if printf '%s' "$c" | grep -qE -- "-c[[:space:]]+['\"]?[[:space:]]*(sudo[[:space:]]+)?(docker-compose|docker)([[:space:]]|['\"]|$)"; then
216
+ return 0
217
+ fi
218
+ return 1
219
+ }
220
+
221
+ case "$TOOL" in bash|shell|Bash) ;; *) exit 0 ;; esac
222
+ [ -n "$COMMAND" ] || exit 0
223
+ shell_fallback_detect && block
224
+ exit 0
225
+ fi
226
+
227
+ exit 0
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env bash
2
+ # Detection of the models served by Ollama on the host (#665).
3
+ # devzone hosts no model: models live on the host (Ollama) and are detected here.
4
+ # host-models.sh list the detected model names, one per line
5
+ # host-models.sh first the model to use (DEVZONE_HOST_MODEL or first detected)
6
+ # host-models.sh set merge the devzone-host provider into ~/.config/opencode/config.json
7
+ # host-models.sh unset remove the devzone-host provider from that file
8
+ # Default URL: http://host.docker.internal:11434, overridable with DEVZONE_OLLAMA_URL.
9
+ # Short timeout; exits 0 and writes nothing when Ollama does not answer.
10
+ # bash 3.2 (macOS). Code and comments in English.
11
+ set -euo pipefail
12
+
13
+ URL="${DEVZONE_OLLAMA_URL:-http://host.docker.internal:11434}"
14
+ URL="${URL%/}"
15
+ FILE="$HOME/.config/opencode/config.json"
16
+
17
+ # True when a model is an embedding model (Ollama details.type, or a name
18
+ # containing "embed", case-insensitive).
19
+ is_embedding() {
20
+ local low
21
+ low="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
22
+ case "$low" in
23
+ *embed*) return 0 ;;
24
+ *) return 1 ;;
25
+ esac
26
+ }
27
+
28
+ # Prints the detected model names, one per line. Exits 0 and prints nothing
29
+ # when Ollama does not answer or the payload is not usable.
30
+ modeles() {
31
+ local data
32
+ data="$(curl -fsS --max-time 3 "${URL}/api/tags" 2>/dev/null)" || return 0
33
+ [ -n "$data" ] || return 0
34
+ # Ignore embedding models (Ollama details.type, or a name containing "embed").
35
+ printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | .name' 2>/dev/null |
36
+ while IFS= read -r name; do
37
+ is_embedding "$name" || printf '%s\n' "$name"
38
+ done || true
39
+ return 0
40
+ }
41
+
42
+ # The model to use: DEVZONE_HOST_MODEL when set, else the first detected.
43
+ # Empty when Ollama did not answer or no model was detected.
44
+ premier() {
45
+ local liste nom="${DEVZONE_HOST_MODEL:-}"
46
+ liste="$(modeles)" || true
47
+ [ -n "$liste" ] || return 0
48
+ if [ -n "$nom" ]; then
49
+ printf '%s\n' "$nom"
50
+ else
51
+ printf '%s\n' "${liste%%$'\n'*}"
52
+ fi
53
+ return 0
54
+ }
55
+
56
+ # jq program $1 applied to the file (or {}), written back atomically.
57
+ # The file is removed when nothing remains but the schema.
58
+ rewrite() {
59
+ local current="{}" out
60
+ [ ! -f "$FILE" ] || current="$(cat "$FILE")"
61
+ mkdir -p "$(dirname "$FILE")"
62
+ out="$(printf '%s' "$current" | jq "$1")" || {
63
+ echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
64
+ return 1
65
+ }
66
+ if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
67
+ rm -f "$FILE"
68
+ else
69
+ printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
70
+ fi
71
+ }
72
+
73
+ # Merges the devzone-host provider (the detected models) into the opencode
74
+ # configuration file, keeping everything else. Does nothing when no model was
75
+ # detected. baseURL = URL + /v1.
76
+ set_provider() {
77
+ local liste current="{}" out models baseurl
78
+ liste="$(modeles)" || return 0
79
+ [ -n "$liste" ] || return 0
80
+ baseurl="${URL%/}/v1"
81
+ models="$(printf '%s\n' "$liste" | jq -R -n '([inputs | select(length > 0)] | map({(.): {name: .}})) | add // {}')" || return 1
82
+ [ ! -f "$FILE" ] || current="$(cat "$FILE")"
83
+ mkdir -p "$(dirname "$FILE")"
84
+ out="$(printf '%s' "$current" | jq --arg baseurl "$baseurl" --argjson models "$models" '
85
+ ."$schema" = (."$schema" // "https://opencode.ai/config.json")
86
+ | .provider["devzone-host"] = {npm: "@ai-sdk/openai-compatible", name: "devzone host models (Ollama)", options: {baseURL: $baseurl}, models: $models}
87
+ ')" || {
88
+ echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
89
+ return 1
90
+ }
91
+ if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
92
+ rm -f "$FILE"
93
+ else
94
+ printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
95
+ fi
96
+ }
97
+
98
+ # Removes the devzone-host provider from the opencode configuration file,
99
+ # keeping everything else. No error when the file is absent.
100
+ unset_provider() {
101
+ [ ! -f "$FILE" ] && return 0
102
+ rewrite 'if .provider then del(.provider["devzone-host"]) | (if .provider == {} then del(.provider) else . end) else . end'
103
+ }
104
+
105
+ # When run directly (not sourced): dispatch the subcommands.
106
+ if [ "${0##*/}" = "host-models.sh" ]; then
107
+ case "${1:-}" in
108
+ first) premier ;;
109
+ set) set_provider ;;
110
+ unset) unset_provider ;;
111
+ *) modeles ;;
112
+ esac
113
+ fi
@@ -0,0 +1,45 @@
1
+ // Guard for opencode 2.x: blocks Docker commands in devzone (Kubernetes-first).
2
+ // Each shell tool call is checked by docker-garde.sh. Exit code 2: error shown
3
+ // to the agent with stderr message. Script absent or failing: nothing blocked.
4
+ // The installed copy (devzone enable ia) replaces the placeholder below with
5
+ // the script path; DEVZONE_DOCKER_GARDE overrides it. The script is resolved
6
+ // from the plugin location itself (.devcontainer/ia/plugins -> ../docker-garde.sh).
7
+ // opencode 1.x also loads default exports with an id; without ctx.tool.hook the
8
+ // 1.x guard in devzone-garde.js remains active.
9
+ import { spawnSync } from "node:child_process"
10
+ import { existsSync } from "node:fs"
11
+ import { fileURLToPath } from "node:url"
12
+ import { dirname, join } from "node:path"
13
+
14
+ const INSTALLED = process.env.DEVZONE_DOCKER_GARDE || "__DEVZONE_DOCKER_GARDE__"
15
+
16
+ function guardScript() {
17
+ if (INSTALLED && INSTALLED.indexOf("__DEVZONE_DOCKER_GARDE__") !== 0 && existsSync(INSTALLED)) {
18
+ return INSTALLED
19
+ }
20
+ const script = join(dirname(fileURLToPath(import.meta.url)), "..", "docker-garde.sh")
21
+ if (existsSync(script)) {
22
+ return script
23
+ }
24
+ return null
25
+ }
26
+
27
+ function garde(script, tool, args, cwd) {
28
+ if (!script || !existsSync(script)) return
29
+ const r = spawnSync("bash", [script], {
30
+ input: JSON.stringify({ tool, args, cwd }),
31
+ encoding: "utf8",
32
+ })
33
+ if (r.status === 2) throw new Error((r.stderr || "").trim())
34
+ }
35
+
36
+ export default {
37
+ id: "devzone-garde",
38
+ setup: (ctx) => {
39
+ if (typeof ctx?.tool?.hook !== "function") return
40
+ const dir = ctx.location?.directory || process.cwd()
41
+ const script = guardScript()
42
+ return ctx.tool.hook("execute.before", (call) => garde(script, call.tool, call.input, dir))
43
+ },
44
+ server: async () => ({}),
45
+ }
@@ -0,0 +1,38 @@
1
+ // Guard for opencode 1.x: blocks Docker commands in devzone (Kubernetes-first).
2
+ // Each shell tool call is checked by docker-garde.sh. Exit code 2: error shown
3
+ // to the agent with stderr message. Script absent or failing: nothing blocked.
4
+ // The installed copy (devzone enable ia) replaces the placeholder below with
5
+ // the script path; DEVZONE_DOCKER_GARDE overrides it. The script is resolved
6
+ // from the plugin location itself (.devcontainer/ia/plugins -> ../docker-garde.sh).
7
+ import { spawnSync } from "node:child_process"
8
+ import { existsSync } from "node:fs"
9
+ import { fileURLToPath } from "node:url"
10
+ import { dirname, join } from "node:path"
11
+
12
+ const INSTALLED = process.env.DEVZONE_DOCKER_GARDE || "__DEVZONE_DOCKER_GARDE__"
13
+
14
+ function guardScript() {
15
+ if (INSTALLED && INSTALLED.indexOf("__DEVZONE_DOCKER_GARDE__") !== 0 && existsSync(INSTALLED)) {
16
+ return INSTALLED
17
+ }
18
+ const script = join(dirname(fileURLToPath(import.meta.url)), "..", "docker-garde.sh")
19
+ if (existsSync(script)) {
20
+ return script
21
+ }
22
+ return null
23
+ }
24
+
25
+ export const DevzoneGarde = async (ctx) => {
26
+ const cwd = ctx?.directory || ctx?.location?.directory || process.cwd()
27
+ const script = guardScript()
28
+ return {
29
+ "tool.execute.before": async (input, output) => {
30
+ if (!script || !existsSync(script)) return
31
+ const r = spawnSync("bash", [script], {
32
+ input: JSON.stringify({ tool: input.tool, args: output.args, cwd }),
33
+ encoding: "utf8",
34
+ })
35
+ if (r.status === 2) throw new Error((r.stderr || "").trim())
36
+ },
37
+ }
38
+ }
@@ -54,6 +54,14 @@ Avec `ia` actif, le garde-fou repowarden est branché pour Claude Code et openco
54
54
 
55
55
  Fichiers de droits protégés (jamais écrits par un agent, listés fixes, qu'aucune variable ne change) : `.devcontainer/opencode/agent.json`, `.devcontainer/opencode.jsonc`, `.repowarden.conf`, `.devcontainer/agent-droits.sh`. Un agent qui les touche est refusé et le changement est annulé dans l'arbre.
56
56
 
57
+ ## Kubernetes seulement
58
+
59
+ devzone se décrit avec **le cluster**, **le pod** et **les nœuds** ; jamais « Docker » pour décrire devzone. Seuls les **pods** sont des conteneurs.
60
+
61
+ Pour un essai jetable, crée un **pod** ou un **namespace** jetable (`kubectl run`, `kubectl create ns`), puis supprime-le. Ne lance pas `docker`.
62
+
63
+ Un garde-fou arrête les agents qui lancent `docker` ou `docker-compose` ; `DEVZONE_ALLOW_DOCKER=1` est réservé à une action sur l'**hôte** lui-même, jamais au cluster.
64
+
57
65
  ## Services Kubernetes et workspace
58
66
 
59
67
  Les services (PostgreSQL, MySQL, GitLab, Argo CD) vivent sur le **cluster des services de devzone**, choisi une fois (`devzone cluster CTX`) et gardé dans l'état. Le contexte `devzone` de kubectl est posé sur ce cluster. Namespaces des services : `devzone-*`. `devzone cluster` affiche le cluster et les possibles, `devzone clusters` donne la vue travail/services ; le module `kubernetes` actif relie au cluster de la machine et installe metrics-server au démarrage.
package/manage/devzone CHANGED
@@ -582,10 +582,10 @@ commande_du_conteneur() {
582
582
  case "$1" in
583
583
  actif | activer | agent | appliquer | argocd | build | catalogue | cluster | clusters | \
584
584
  demarrer | desactiver | etat | gitlab | metrics | modules | mots-de-passe | \
585
- llm | mysql | paquets | plateforme | port | postgres | reparer | test-bash32 | \
585
+ ia | llm | mysql | paquets | plateforme | port | postgres | reparer | test-bash32 | \
586
586
  test-gitlab | ticket | utiliser) return 0 ;;
587
587
  # English names of the container commands (#502)
588
- is-enabled | enable | disable | apply | catalog | start | status | \
588
+ ai | is-enabled | enable | disable | apply | catalog | start | status | \
589
589
  passwords | packages | platform | repair | use) return 0 ;;
590
590
  *) return 1 ;;
591
591
  esac
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "0.50.6",
3
+ "version": "0.52.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": {