devzone 0.51.0 → 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.
@@ -400,6 +400,77 @@ installer_ia() {
400
400
  [ "${#IA_FAILED[@]}" -eq 0 ]
401
401
  }
402
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
+
403
474
  appliquer_ia() {
404
475
  local journal tmp detectes
405
476
  if [ "$1" = on ]; then
@@ -421,6 +492,7 @@ appliquer_ia() {
421
492
  else
422
493
  echo "devzone : garde-fou repowarden non branché (repowarden 4.10 ou plus requis) : repowarden agents init --global" >&2
423
494
  fi
495
+ poser_garde_docker
424
496
  config_opencode
425
497
  # Provider opencode des modèles de l'hôte (Ollama), détection à chaud :
426
498
  # silencieux et sans effet si Ollama ne répond pas.
@@ -471,6 +543,8 @@ appliquer_ia() {
471
543
  # Plugin opencode du garde-fou (retiré aussi par repowarden ci-dessus)
472
544
  rm -f "$HOME/.config/opencode/plugins/repowarden-garde.js" \
473
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
474
548
  # Configuration opencode : retirée seulement si elle porte le repère devzone
475
549
  # et n'a pas été modifiée ; personnalisée → gardée.
476
550
  retirer_config_opencode
@@ -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,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "0.51.0",
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": {