devzone 0.51.0 → 0.53.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.
- package/.devcontainer/devzone +102 -12
- package/.devcontainer/ia/docker-garde.message +1 -0
- package/.devcontainer/ia/docker-garde.sh +227 -0
- package/.devcontainer/ia/host-check.message +12 -0
- package/.devcontainer/ia/host-check.sh +173 -0
- package/.devcontainer/ia/host-models.sh +98 -11
- package/.devcontainer/ia/plugins/devzone-garde-v2.js +45 -0
- package/.devcontainer/ia/plugins/devzone-garde.js +38 -0
- package/.devcontainer/skills/devzone/SKILL.md +8 -0
- package/package.json +1 -1
package/.devcontainer/devzone
CHANGED
|
@@ -54,6 +54,10 @@ fi
|
|
|
54
54
|
# shellcheck source=SCRIPTDIR/ia/host-models.sh
|
|
55
55
|
# shellcheck disable=SC1091
|
|
56
56
|
. "$ICI/ia/host-models.sh"
|
|
57
|
+
# Update check and report for the host (Ollama) models (#668).
|
|
58
|
+
# shellcheck source=SCRIPTDIR/ia/host-check.sh
|
|
59
|
+
# shellcheck disable=SC1091
|
|
60
|
+
. "$ICI/ia/host-check.sh"
|
|
57
61
|
|
|
58
62
|
# Assistants IA, versions figées : mettre à jour ici, puis devzone apply
|
|
59
63
|
# (ou Rebuild Container). Une ligne par paquet, séparées par une ligne qui ne
|
|
@@ -400,6 +404,77 @@ installer_ia() {
|
|
|
400
404
|
[ "${#IA_FAILED[@]}" -eq 0 ]
|
|
401
405
|
}
|
|
402
406
|
|
|
407
|
+
# Docker guard for the folders that are not this repository: a Claude Code
|
|
408
|
+
# PreToolUse hook in the global settings and the two opencode plugins in the
|
|
409
|
+
# global plugins folder. Idempotent, other user settings and hooks preserved.
|
|
410
|
+
poser_garde_docker() {
|
|
411
|
+
local script="$ICI/ia/docker-garde.sh" config="$HOME/.claude/settings.json"
|
|
412
|
+
local src="$ICI/ia/plugins" dst="$HOME/.config/opencode/plugins"
|
|
413
|
+
local tmp f
|
|
414
|
+
if ! command -v jq >/dev/null 2>&1; then
|
|
415
|
+
echo "devzone : jq absent : garde-fou docker non posé pour Claude Code" >&2
|
|
416
|
+
elif [ ! -f "$config" ]; then
|
|
417
|
+
echo "devzone : $config absent : garde-fou docker non posé pour Claude Code" >&2
|
|
418
|
+
elif ! jq -e . "$config" >/dev/null 2>&1; then
|
|
419
|
+
echo "devzone : $config illisible (JSON invalide) : garde-fou docker non posé pour Claude Code" >&2
|
|
420
|
+
else
|
|
421
|
+
tmp="$(mktemp)"
|
|
422
|
+
if jq --arg cmd "bash \"$script\" --format claude" '
|
|
423
|
+
.hooks = (.hooks // {}) |
|
|
424
|
+
.hooks.PreToolUse = (.hooks.PreToolUse // []) |
|
|
425
|
+
if ([.hooks.PreToolUse[]? | .hooks[]? | (.command // "")] | any(contains("docker-garde.sh")))
|
|
426
|
+
then .
|
|
427
|
+
else .hooks.PreToolUse += [{"matcher": "Bash", "hooks": [{"type": "command", "command": $cmd}]}]
|
|
428
|
+
end
|
|
429
|
+
' "$config" >"$tmp" 2>/dev/null; then
|
|
430
|
+
mv "$tmp" "$config"
|
|
431
|
+
else
|
|
432
|
+
rm -f "$tmp"
|
|
433
|
+
echo "devzone : $config inchangé : garde-fou docker non posé pour Claude Code" >&2
|
|
434
|
+
fi
|
|
435
|
+
fi
|
|
436
|
+
mkdir -p "$dst"
|
|
437
|
+
for f in devzone-garde.js devzone-garde-v2.js; do
|
|
438
|
+
[ -f "$src/$f" ] || continue
|
|
439
|
+
sed "s|__DEVZONE_DOCKER_GARDE__|$script|g" "$src/$f" >"$dst/$f"
|
|
440
|
+
done
|
|
441
|
+
echo "devzone : garde-fou docker actif pour Claude Code et opencode"
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
# Removes only the Docker guard entries (commands containing docker-garde.sh)
|
|
445
|
+
# and the two plugins; the rest of settings.json and of the plugins is kept.
|
|
446
|
+
retirer_garde_docker() {
|
|
447
|
+
local config="$HOME/.claude/settings.json" tmp
|
|
448
|
+
if [ -f "$config" ] && jq -e . "$config" >/dev/null 2>&1; then
|
|
449
|
+
tmp="$(mktemp)"
|
|
450
|
+
if jq '
|
|
451
|
+
if (.hooks.PreToolUse // null) != null then
|
|
452
|
+
.hooks.PreToolUse = [
|
|
453
|
+
.hooks.PreToolUse[] |
|
|
454
|
+
if (.hooks // null) != null then
|
|
455
|
+
.hooks = [ .hooks[] | select(((.command // "") | contains("docker-garde.sh")) | not) ] |
|
|
456
|
+
select((.hooks | length) > 0)
|
|
457
|
+
else
|
|
458
|
+
select(((.command // "") | contains("docker-garde.sh")) | not)
|
|
459
|
+
end
|
|
460
|
+
] |
|
|
461
|
+
if (.hooks.PreToolUse | length) == 0 then del(.hooks.PreToolUse) else . end |
|
|
462
|
+
if ((.hooks // {}) | keys | length) == 0 then del(.hooks) else . end
|
|
463
|
+
else . end
|
|
464
|
+
' "$config" >"$tmp" 2>/dev/null; then
|
|
465
|
+
if [ "$(cat "$tmp")" = "{}" ]; then
|
|
466
|
+
rm -f "$tmp" "$config"
|
|
467
|
+
else
|
|
468
|
+
mv "$tmp" "$config"
|
|
469
|
+
fi
|
|
470
|
+
else
|
|
471
|
+
rm -f "$tmp"
|
|
472
|
+
fi
|
|
473
|
+
fi
|
|
474
|
+
rm -f "$HOME/.config/opencode/plugins/devzone-garde.js" \
|
|
475
|
+
"$HOME/.config/opencode/plugins/devzone-garde-v2.js"
|
|
476
|
+
}
|
|
477
|
+
|
|
403
478
|
appliquer_ia() {
|
|
404
479
|
local journal tmp detectes
|
|
405
480
|
if [ "$1" = on ]; then
|
|
@@ -421,6 +496,7 @@ appliquer_ia() {
|
|
|
421
496
|
else
|
|
422
497
|
echo "devzone : garde-fou repowarden non branché (repowarden 4.10 ou plus requis) : repowarden agents init --global" >&2
|
|
423
498
|
fi
|
|
499
|
+
poser_garde_docker
|
|
424
500
|
config_opencode
|
|
425
501
|
# Provider opencode des modèles de l'hôte (Ollama), détection à chaud :
|
|
426
502
|
# silencieux et sans effet si Ollama ne répond pas.
|
|
@@ -471,6 +547,8 @@ appliquer_ia() {
|
|
|
471
547
|
# Plugin opencode du garde-fou (retiré aussi par repowarden ci-dessus)
|
|
472
548
|
rm -f "$HOME/.config/opencode/plugins/repowarden-garde.js" \
|
|
473
549
|
"$HOME/.config/opencode/plugins/repowarden-garde-v2.js"
|
|
550
|
+
# Garde-fou docker : seules ses entrées et ses plugins sont retirés.
|
|
551
|
+
retirer_garde_docker
|
|
474
552
|
# Configuration opencode : retirée seulement si elle porte le repère devzone
|
|
475
553
|
# et n'a pas été modifiée ; personnalisée → gardée.
|
|
476
554
|
retirer_config_opencode
|
|
@@ -1458,18 +1536,30 @@ case "${1:-}" in
|
|
|
1458
1536
|
bash "$ICI/agent.sh" "${@:2}"
|
|
1459
1537
|
;;
|
|
1460
1538
|
ia)
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1539
|
+
case "${2:-}" in
|
|
1540
|
+
check)
|
|
1541
|
+
# Read-only: update state of each detected host model (#668).
|
|
1542
|
+
check
|
|
1543
|
+
;;
|
|
1544
|
+
rapport)
|
|
1545
|
+
# Read-only: sizes, update state, measurements, chosen model (#668).
|
|
1546
|
+
rapport
|
|
1547
|
+
;;
|
|
1548
|
+
*)
|
|
1549
|
+
# Read-only: lists the host (Ollama) models detected and the default model.
|
|
1550
|
+
liste="$(modeles)"
|
|
1551
|
+
def="$(premier)"
|
|
1552
|
+
if [ -z "$liste" ]; then
|
|
1553
|
+
echo "devzone : aucun modèle Ollama détecté sur ${URL} (répondez sur /api/tags)"
|
|
1554
|
+
else
|
|
1555
|
+
echo "devzone : modèles détectés sur l'hôte (Ollama) :"
|
|
1556
|
+
while IFS= read -r m; do
|
|
1557
|
+
[ -n "$m" ] && printf ' %s\n' "$m"
|
|
1558
|
+
done <<<"$liste"
|
|
1559
|
+
echo "modèle par défaut : ${def:-aucun}"
|
|
1560
|
+
fi
|
|
1561
|
+
;;
|
|
1562
|
+
esac
|
|
1473
1563
|
;;
|
|
1474
1564
|
ticket) bash "$ICI/ticket.sh" "${@:2}" ;;
|
|
1475
1565
|
build)
|
|
@@ -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,12 @@
|
|
|
1
|
+
MSG_TITRE="modèles détectés sur l'hôte (Ollama) :"
|
|
2
|
+
MSG_AUCUN="devzone : aucun modèle Ollama détecté sur {url} (répondez sur /api/tags)"
|
|
3
|
+
MSG_TAILLE="taille"
|
|
4
|
+
MSG_A_JOUR="à jour"
|
|
5
|
+
MSG_MAJ="mise à jour disponible"
|
|
6
|
+
MSG_NON="non vérifiable"
|
|
7
|
+
MSG_PULL="sur l'hôte : ollama pull {modele}"
|
|
8
|
+
MSG_MESURE="mesure : reussite {reussite}, tok_s {tok_s}"
|
|
9
|
+
MSG_RETENU="modèle retenu : {modele} ({raison})"
|
|
10
|
+
MSG_RAISON_VAR="variable DEVZONE_HOST_MODEL"
|
|
11
|
+
MSG_RAISON_MESURE="mesure"
|
|
12
|
+
MSG_RAISON_REGLE="règle"
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Update check and report for the host (Ollama) models (#668).
|
|
3
|
+
# host-check.sh check per detected model: up to date, update available,
|
|
4
|
+
# or not verifiable; never downloads anything
|
|
5
|
+
# host-check.sh rapport sizes, update state, measurements and the chosen
|
|
6
|
+
# default model with its reason
|
|
7
|
+
# The registry manifest digest is compared with the local /api/tags digest: one
|
|
8
|
+
# GET per model, no download, no "ollama pull" executed (the command is only
|
|
9
|
+
# printed for the host). The registry is DEVZONE_OLLAMA_REGISTRY, else
|
|
10
|
+
# https://registry.ollama.ai.
|
|
11
|
+
# bash 3.2 (macOS). Code and comments in English; the user messages are French
|
|
12
|
+
# and live in host-check.message (not listed in .english).
|
|
13
|
+
set -euo pipefail
|
|
14
|
+
|
|
15
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
16
|
+
# shellcheck source=SCRIPTDIR/host-models.sh
|
|
17
|
+
# shellcheck disable=SC1091
|
|
18
|
+
. "$SCRIPT_DIR/host-models.sh"
|
|
19
|
+
|
|
20
|
+
REG="${DEVZONE_OLLAMA_REGISTRY:-https://registry.ollama.ai}"
|
|
21
|
+
REG="${REG%/}"
|
|
22
|
+
MESSAGE_FILE="$SCRIPT_DIR/host-check.message"
|
|
23
|
+
|
|
24
|
+
# English fallbacks, overridden by the French message file.
|
|
25
|
+
MSG_TITRE="host (Ollama) models detected:"
|
|
26
|
+
MSG_AUCUN="devzone: no Ollama model detected on {url} (answer on /api/tags)"
|
|
27
|
+
MSG_TAILLE="size"
|
|
28
|
+
MSG_A_JOUR="up to date"
|
|
29
|
+
MSG_MAJ="update available"
|
|
30
|
+
MSG_NON="not verifiable"
|
|
31
|
+
MSG_PULL="on the host: ollama pull {modele}"
|
|
32
|
+
MSG_MESURE="measurement reussite {reussite}, tok_s {tok_s}"
|
|
33
|
+
MSG_RETENU="chosen model: {modele} ({raison})"
|
|
34
|
+
MSG_RAISON_VAR="DEVZONE_HOST_MODEL"
|
|
35
|
+
MSG_RAISON_MESURE="measurement"
|
|
36
|
+
MSG_RAISON_REGLE="rule"
|
|
37
|
+
|
|
38
|
+
if [ -r "$MESSAGE_FILE" ]; then
|
|
39
|
+
# shellcheck source=/dev/null
|
|
40
|
+
. "$MESSAGE_FILE"
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
# Lowercase hex sha256 of a file (sha256sum on Linux, shasum on macOS).
|
|
44
|
+
sha256_fichier() {
|
|
45
|
+
if command -v sha256sum >/dev/null 2>&1; then
|
|
46
|
+
sha256sum "$1" | cut -d' ' -f1
|
|
47
|
+
else
|
|
48
|
+
shasum -a 256 "$1" | cut -d' ' -f1
|
|
49
|
+
fi
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Prints the update state of one model: MSG_A_JOUR, MSG_MAJ or MSG_NON.
|
|
53
|
+
# A name with a slash (hf.co/...), a 404, an unreachable registry or a missing
|
|
54
|
+
# digest is not verifiable.
|
|
55
|
+
etat_modele() {
|
|
56
|
+
local nom="$1" digest="$2" court tag somme tmp
|
|
57
|
+
case "$nom" in
|
|
58
|
+
*/*) printf '%s\n' "$MSG_NON"; return 0 ;;
|
|
59
|
+
esac
|
|
60
|
+
case "$nom" in
|
|
61
|
+
*:*) court="${nom%:*}"; tag="${nom##*:}" ;;
|
|
62
|
+
*) court="$nom"; tag="latest" ;;
|
|
63
|
+
esac
|
|
64
|
+
tmp="$(mktemp "${TMPDIR:-/tmp}/devzone-manifest.XXXXXX")"
|
|
65
|
+
if ! curl -fsS --max-time 5 \
|
|
66
|
+
-H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
|
|
67
|
+
-o "$tmp" "${REG}/v2/library/${court}/manifests/${tag}" 2>/dev/null; then
|
|
68
|
+
rm -f "$tmp"
|
|
69
|
+
printf '%s\n' "$MSG_NON"
|
|
70
|
+
return 0
|
|
71
|
+
fi
|
|
72
|
+
somme="$(sha256_fichier "$tmp")"
|
|
73
|
+
rm -f "$tmp"
|
|
74
|
+
if [ -z "$digest" ]; then
|
|
75
|
+
printf '%s\n' "$MSG_NON"
|
|
76
|
+
return 0
|
|
77
|
+
fi
|
|
78
|
+
if [ "$(printf '%s' "$somme" | tr '[:upper:]' '[:lower:]')" = \
|
|
79
|
+
"$(printf '%s' "${digest#sha256:}" | tr '[:upper:]' '[:lower:]')" ]; then
|
|
80
|
+
printf '%s\n' "$MSG_A_JOUR"
|
|
81
|
+
else
|
|
82
|
+
printf '%s\n' "$MSG_MAJ"
|
|
83
|
+
fi
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Prints "reussite tok_s" for a model, empty when it has no measurement.
|
|
87
|
+
mesure_pour() {
|
|
88
|
+
local nom="$1" data
|
|
89
|
+
[ -f "$MESURES" ] || return 0
|
|
90
|
+
data="$(cat "$MESURES" 2>/dev/null)" || return 0
|
|
91
|
+
[ -n "$data" ] || return 0
|
|
92
|
+
printf '%s' "$data" | jq -r --arg nom "$nom" '
|
|
93
|
+
.[$nom] | if . == null then empty else "\(.reussite // 0) \(.tok_s // 0)" end
|
|
94
|
+
' 2>/dev/null || return 0
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Why the model is chosen: variable, measurement or rule.
|
|
98
|
+
raison_choix() {
|
|
99
|
+
local liste="$1" m
|
|
100
|
+
if [ -n "${DEVZONE_HOST_MODEL:-}" ]; then
|
|
101
|
+
printf '%s\n' "$MSG_RAISON_VAR"
|
|
102
|
+
return 0
|
|
103
|
+
fi
|
|
104
|
+
m="$(mesure_choix "$liste")" || true
|
|
105
|
+
if [ -n "$m" ]; then
|
|
106
|
+
printf '%s\n' "$MSG_RAISON_MESURE"
|
|
107
|
+
else
|
|
108
|
+
printf '%s\n' "$MSG_RAISON_REGLE"
|
|
109
|
+
fi
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# Update check of every detected model. Nothing is downloaded, nothing changes.
|
|
113
|
+
check() {
|
|
114
|
+
local data ligne nom taille digest etat
|
|
115
|
+
data="$(infos)" || true
|
|
116
|
+
if [ -z "$data" ]; then
|
|
117
|
+
printf '%s\n' "${MSG_AUCUN//\{url\}/$URL}"
|
|
118
|
+
return 0
|
|
119
|
+
fi
|
|
120
|
+
printf '%s\n' "$data" | while IFS=$'\t' read -r nom taille digest; do
|
|
121
|
+
[ -n "$nom" ] || continue
|
|
122
|
+
etat="$(etat_modele "$nom" "$digest")"
|
|
123
|
+
printf '%s : %s\n' "$nom" "$etat"
|
|
124
|
+
if [ "$etat" = "$MSG_MAJ" ]; then
|
|
125
|
+
printf '%s\n' "${MSG_PULL//\{modele\}/$nom}"
|
|
126
|
+
fi
|
|
127
|
+
done
|
|
128
|
+
return 0
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
# Report: sizes, update state, measurements and the chosen model with its
|
|
132
|
+
# reason. Proposes, changes nothing.
|
|
133
|
+
rapport() {
|
|
134
|
+
local data liste ligne nom taille digest etat mes r t def raison
|
|
135
|
+
data="$(infos)" || true
|
|
136
|
+
if [ -z "$data" ]; then
|
|
137
|
+
printf '%s\n' "${MSG_AUCUN//\{url\}/$URL}"
|
|
138
|
+
return 0
|
|
139
|
+
fi
|
|
140
|
+
liste="$(printf '%s\n' "$data" | cut -f1)"
|
|
141
|
+
printf '%s\n' "$MSG_TITRE"
|
|
142
|
+
printf '%s\n' "$data" | while IFS=$'\t' read -r nom taille digest; do
|
|
143
|
+
[ -n "$nom" ] || continue
|
|
144
|
+
etat="$(etat_modele "$nom" "$digest")"
|
|
145
|
+
printf ' %s : %s ; %s %s\n' "$nom" "$etat" "$MSG_TAILLE" "$taille"
|
|
146
|
+
mes="$(mesure_pour "$nom")"
|
|
147
|
+
if [ -n "$mes" ]; then
|
|
148
|
+
r="${mes%% *}"
|
|
149
|
+
t="${mes#* }"
|
|
150
|
+
ligne="${MSG_MESURE//\{reussite\}/$r}"
|
|
151
|
+
ligne="${ligne//\{tok_s\}/$t}"
|
|
152
|
+
printf ' %s\n' "$ligne"
|
|
153
|
+
fi
|
|
154
|
+
if [ "$etat" = "$MSG_MAJ" ]; then
|
|
155
|
+
printf '%s\n' "${MSG_PULL//\{modele\}/$nom}"
|
|
156
|
+
fi
|
|
157
|
+
done
|
|
158
|
+
def="$(choix "$liste")" || true
|
|
159
|
+
raison="$(raison_choix "$liste")" || true
|
|
160
|
+
ligne="${MSG_RETENU//\{modele\}/${def:-}}"
|
|
161
|
+
ligne="${ligne//\{raison\}/$raison}"
|
|
162
|
+
printf '%s\n' "$ligne"
|
|
163
|
+
return 0
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# When run directly (not sourced): dispatch the subcommands.
|
|
167
|
+
if [ "${0##*/}" = "host-check.sh" ]; then
|
|
168
|
+
case "${1:-}" in
|
|
169
|
+
check) check ;;
|
|
170
|
+
rapport) rapport ;;
|
|
171
|
+
*) check ;;
|
|
172
|
+
esac
|
|
173
|
+
fi
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Detection of the models served by Ollama on the host (#665).
|
|
2
|
+
# Detection of the models served by Ollama on the host (#665, #668).
|
|
3
3
|
# devzone hosts no model: models live on the host (Ollama) and are detected here.
|
|
4
4
|
# host-models.sh list the detected model names, one per line
|
|
5
|
-
# host-models.sh first the model to use
|
|
5
|
+
# host-models.sh first the model to use: DEVZONE_HOST_MODEL, else the best
|
|
6
|
+
# measured model, else a deterministic rule
|
|
6
7
|
# host-models.sh set merge the devzone-host provider into ~/.config/opencode/config.json
|
|
7
8
|
# host-models.sh unset remove the devzone-host provider from that file
|
|
9
|
+
# host-models.sh check update check of each model (delegates to host-check.sh)
|
|
10
|
+
# host-models.sh rapport report (delegates to host-check.sh)
|
|
8
11
|
# Default URL: http://host.docker.internal:11434, overridable with DEVZONE_OLLAMA_URL.
|
|
12
|
+
# Measurements: DEVZONE_IA_MESURES, else ~/.config/devzone/ia-mesures.json
|
|
13
|
+
# ({"<model>": {"reussite": 0..1, "tok_s": n, "date": "..."}}).
|
|
9
14
|
# Short timeout; exits 0 and writes nothing when Ollama does not answer.
|
|
10
15
|
# bash 3.2 (macOS). Code and comments in English.
|
|
11
16
|
set -euo pipefail
|
|
@@ -13,6 +18,7 @@ set -euo pipefail
|
|
|
13
18
|
URL="${DEVZONE_OLLAMA_URL:-http://host.docker.internal:11434}"
|
|
14
19
|
URL="${URL%/}"
|
|
15
20
|
FILE="$HOME/.config/opencode/config.json"
|
|
21
|
+
MESURES="${DEVZONE_IA_MESURES:-$HOME/.config/devzone/ia-mesures.json}"
|
|
16
22
|
|
|
17
23
|
# True when a model is an embedding model (Ollama details.type, or a name
|
|
18
24
|
# containing "embed", case-insensitive).
|
|
@@ -25,11 +31,16 @@ is_embedding() {
|
|
|
25
31
|
esac
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
# Raw /api/tags payload, empty when Ollama does not answer.
|
|
35
|
+
json_tags() {
|
|
36
|
+
curl -fsS --max-time 3 "${URL}/api/tags" 2>/dev/null || return 0
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
# Prints the detected model names, one per line. Exits 0 and prints nothing
|
|
29
40
|
# when Ollama does not answer or the payload is not usable.
|
|
30
41
|
modeles() {
|
|
31
42
|
local data
|
|
32
|
-
data="$(
|
|
43
|
+
data="$(json_tags)" || return 0
|
|
33
44
|
[ -n "$data" ] || return 0
|
|
34
45
|
# Ignore embedding models (Ollama details.type, or a name containing "embed").
|
|
35
46
|
printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | .name' 2>/dev/null |
|
|
@@ -39,18 +50,91 @@ modeles() {
|
|
|
39
50
|
return 0
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
# Prints the detected models as "name<TAB>size" (bytes), one per line.
|
|
54
|
+
tailles() {
|
|
55
|
+
local data line name
|
|
56
|
+
data="$(json_tags)" || return 0
|
|
57
|
+
[ -n "$data" ] || return 0
|
|
58
|
+
printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | "\(.name)\t\(.size // 0)"' 2>/dev/null |
|
|
59
|
+
while IFS= read -r line; do
|
|
60
|
+
name="${line%%$'\t'*}"
|
|
61
|
+
is_embedding "$name" || printf '%s\n' "$line"
|
|
62
|
+
done || true
|
|
63
|
+
return 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# Prints the detected models as "name<TAB>size<TAB>digest", one per line.
|
|
67
|
+
infos() {
|
|
68
|
+
local data line name
|
|
69
|
+
data="$(json_tags)" || return 0
|
|
70
|
+
[ -n "$data" ] || return 0
|
|
71
|
+
printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | "\(.name)\t\(.size // 0)\t\(.digest // "")"' 2>/dev/null |
|
|
72
|
+
while IFS= read -r line; do
|
|
73
|
+
name="${line%%$'\t'*}"
|
|
74
|
+
is_embedding "$name" || printf '%s\n' "$line"
|
|
75
|
+
done || true
|
|
76
|
+
return 0
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Best measured model among the detected names ($1, one per line): highest
|
|
80
|
+
# reussite, then highest tok_s. Prints nothing when the file is absent, invalid
|
|
81
|
+
# or no detected model is measured.
|
|
82
|
+
mesure_choix() {
|
|
83
|
+
local liste="$1" data
|
|
84
|
+
[ -f "$MESURES" ] || return 0
|
|
85
|
+
data="$(cat "$MESURES" 2>/dev/null)" || return 0
|
|
86
|
+
[ -n "$data" ] || return 0
|
|
87
|
+
printf '%s' "$data" | jq -r --arg liste "$liste" '
|
|
88
|
+
($liste | split("\n") | map(select(length > 0))) as $d
|
|
89
|
+
| [to_entries[] | select(.key as $k | $d | index($k))]
|
|
90
|
+
| sort_by([-(.value.reussite // 0), -(.value.tok_s // 0)])
|
|
91
|
+
| .[0].key // empty
|
|
92
|
+
' 2>/dev/null || return 0
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
# Deterministic fallback: a name containing "coder" first, then the smallest
|
|
96
|
+
# size, then the name order.
|
|
97
|
+
regle_choix() {
|
|
98
|
+
tailles | LC_ALL=C awk -F'\t' '
|
|
99
|
+
{
|
|
100
|
+
low = tolower($1)
|
|
101
|
+
coder = (index(low, "coder") > 0) ? 0 : 1
|
|
102
|
+
size = ($2 + 0)
|
|
103
|
+
if (best == "" || coder < bc || (coder == bc && size < bs) || (coder == bc && size == bs && $1 < bn)) {
|
|
104
|
+
best = $1
|
|
105
|
+
bc = coder
|
|
106
|
+
bs = size
|
|
107
|
+
bn = $1
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
END { if (best != "") print best }
|
|
111
|
+
'
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# The model to use among the detected names: DEVZONE_HOST_MODEL when set, else
|
|
115
|
+
# the best measured model, else the deterministic rule.
|
|
116
|
+
choix() {
|
|
117
|
+
local liste="$1" nom mesure
|
|
47
118
|
[ -n "$liste" ] || return 0
|
|
119
|
+
nom="${DEVZONE_HOST_MODEL:-}"
|
|
48
120
|
if [ -n "$nom" ]; then
|
|
49
121
|
printf '%s\n' "$nom"
|
|
50
|
-
|
|
51
|
-
printf '%s\n' "${liste%%$'\n'*}"
|
|
122
|
+
return 0
|
|
52
123
|
fi
|
|
53
|
-
|
|
124
|
+
mesure="$(mesure_choix "$liste")" || true
|
|
125
|
+
if [ -n "$mesure" ]; then
|
|
126
|
+
printf '%s\n' "$mesure"
|
|
127
|
+
return 0
|
|
128
|
+
fi
|
|
129
|
+
regle_choix
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# The model to use. Empty when Ollama did not answer or no model was detected.
|
|
133
|
+
premier() {
|
|
134
|
+
local liste
|
|
135
|
+
liste="$(modeles)" || true
|
|
136
|
+
[ -n "$liste" ] || return 0
|
|
137
|
+
choix "$liste"
|
|
54
138
|
}
|
|
55
139
|
|
|
56
140
|
# jq program $1 applied to the file (or {}), written back atomically.
|
|
@@ -108,6 +192,9 @@ if [ "${0##*/}" = "host-models.sh" ]; then
|
|
|
108
192
|
first) premier ;;
|
|
109
193
|
set) set_provider ;;
|
|
110
194
|
unset) unset_provider ;;
|
|
195
|
+
check | rapport)
|
|
196
|
+
exec bash "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/host-check.sh" "$@"
|
|
197
|
+
;;
|
|
111
198
|
*) modeles ;;
|
|
112
199
|
esac
|
|
113
200
|
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.
|