devzone 7.4.1 → 7.5.1
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 +18 -60
- package/.devcontainer/devzone-modules.sh +8 -3
- package/.devcontainer/devzone-services.sh +20 -20
- package/.devcontainer/devzone-status.sh +14 -11
- package/.devcontainer/services-admin.sh +1 -1
- package/.devcontainer/versions.env +5 -0
- package/README.md +2 -2
- package/bin/SHA256SUMS +6 -6
- package/bin/devzone-darwin-amd64 +0 -0
- package/bin/devzone-darwin-arm64 +0 -0
- package/bin/devzone-linux-amd64 +0 -0
- package/bin/devzone-linux-arm64 +0 -0
- package/bin/devzone-windows-amd64.exe +0 -0
- package/bin/devzone-windows-arm64.exe +0 -0
- package/manage/devzone +8 -7
- package/manage/scripts/create-mode.sh +3 -3
- package/manage/scripts/uninstall.sh +3 -4
- package/manage/scripts/workspace/argocd-services.sh +1 -1
- package/manage/workspace.sh +11 -25
- package/package.json +1 -1
- package/.devcontainer/ai/host-check.sh +0 -173
- package/.devcontainer/ai/host-models.sh +0 -200
- package/.devcontainer/devzone-ai-guard.sh +0 -98
- package/.devcontainer/devzone-ai.sh +0 -201
- package/.devcontainer/devzone-repair.sh +0 -85
- package/.devcontainer/devzone-skill.sh +0 -97
- package/.devcontainer/devzone-version.sh +0 -78
- package/.devcontainer/help.sh +0 -44
- package/manage/scripts/create-cluster.sh +0 -107
- package/manage/scripts/devzone-update.sh +0 -237
- package/manage/scripts/docker.sh +0 -43
- package/manage/scripts/workspace/ports-apps.sh +0 -156
- package/manage/scripts/workspace/ports-workspace.sh +0 -235
- package/manage/scripts/workspace/services-workspace.sh +0 -193
- package/manage/scripts/workspace/workspace-clone.sh +0 -12
- package/manage/scripts/workspace/workspace-copies.sh +0 -44
- package/manage/scripts/workspace/workspace-egress.sh +0 -184
- package/manage/scripts/workspace/workspace-update.sh +0 -106
- package/manage/scripts/workspace/workspace-wait.sh +0 -56
package/package.json
CHANGED
|
@@ -1,173 +0,0 @@
|
|
|
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, a data file outside the code check.
|
|
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 "$MEASURES" ] || return 0
|
|
90
|
-
data="$(cat "$MEASURES" 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,200 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Detection of the models served by Ollama on the host (#665, #668).
|
|
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, else the best
|
|
6
|
-
# measured model, else a deterministic rule
|
|
7
|
-
# host-models.sh set merge the devzone-host provider into ~/.config/opencode/config.json
|
|
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)
|
|
11
|
-
# Default URL: http://host.docker.internal:11434, overridable with DEVZONE_OLLAMA_URL.
|
|
12
|
-
# Measurements: DEVZONE_AI_MEASURES, else ~/.config/devzone/ai-measures.json
|
|
13
|
-
# ({"<model>": {"reussite": 0..1, "tok_s": n, "date": "..."}}).
|
|
14
|
-
# Short timeout; exits 0 and writes nothing when Ollama does not answer.
|
|
15
|
-
# bash 3.2 (macOS). Code and comments in English.
|
|
16
|
-
set -euo pipefail
|
|
17
|
-
|
|
18
|
-
URL="${DEVZONE_OLLAMA_URL:-http://host.docker.internal:11434}"
|
|
19
|
-
URL="${URL%/}"
|
|
20
|
-
FILE="$HOME/.config/opencode/config.json"
|
|
21
|
-
MEASURES="${DEVZONE_AI_MEASURES:-$HOME/.config/devzone/ai-measures.json}"
|
|
22
|
-
|
|
23
|
-
# True when a model is an embedding model (Ollama details.type, or a name
|
|
24
|
-
# containing "embed", case-insensitive).
|
|
25
|
-
is_embedding() {
|
|
26
|
-
local low
|
|
27
|
-
low="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
|
|
28
|
-
case "$low" in
|
|
29
|
-
*embed*) return 0 ;;
|
|
30
|
-
*) return 1 ;;
|
|
31
|
-
esac
|
|
32
|
-
}
|
|
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
|
-
|
|
39
|
-
# Prints the detected model names, one per line. Exits 0 and prints nothing
|
|
40
|
-
# when Ollama does not answer or the payload is not usable.
|
|
41
|
-
modeles() {
|
|
42
|
-
local data
|
|
43
|
-
data="$(json_tags)" || return 0
|
|
44
|
-
[ -n "$data" ] || return 0
|
|
45
|
-
# Ignore embedding models (Ollama details.type, or a name containing "embed").
|
|
46
|
-
printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | .name' 2>/dev/null |
|
|
47
|
-
while IFS= read -r name; do
|
|
48
|
-
is_embedding "$name" || printf '%s\n' "$name"
|
|
49
|
-
done || true
|
|
50
|
-
return 0
|
|
51
|
-
}
|
|
52
|
-
|
|
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 "$MEASURES" ] || return 0
|
|
85
|
-
data="$(cat "$MEASURES" 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
|
|
118
|
-
[ -n "$liste" ] || return 0
|
|
119
|
-
nom="${DEVZONE_HOST_MODEL:-}"
|
|
120
|
-
if [ -n "$nom" ]; then
|
|
121
|
-
printf '%s\n' "$nom"
|
|
122
|
-
return 0
|
|
123
|
-
fi
|
|
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"
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
# jq program $1 applied to the file (or {}), written back atomically.
|
|
141
|
-
# The file is removed when nothing remains but the schema.
|
|
142
|
-
rewrite() {
|
|
143
|
-
local current="{}" out
|
|
144
|
-
[ ! -f "$FILE" ] || current="$(cat "$FILE")"
|
|
145
|
-
mkdir -p "$(dirname "$FILE")"
|
|
146
|
-
out="$(printf '%s' "$current" | jq "$1")" || {
|
|
147
|
-
echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
|
|
148
|
-
return 1
|
|
149
|
-
}
|
|
150
|
-
if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
|
|
151
|
-
rm -f "$FILE"
|
|
152
|
-
else
|
|
153
|
-
printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
|
|
154
|
-
fi
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
# Merges the devzone-host provider (the detected models) into the opencode
|
|
158
|
-
# configuration file, keeping everything else. Does nothing when no model was
|
|
159
|
-
# detected. baseURL = URL + /v1.
|
|
160
|
-
set_provider() {
|
|
161
|
-
local liste current="{}" out models baseurl
|
|
162
|
-
liste="$(modeles)" || return 0
|
|
163
|
-
[ -n "$liste" ] || return 0
|
|
164
|
-
baseurl="${URL%/}/v1"
|
|
165
|
-
models="$(printf '%s\n' "$liste" | jq -R -n '([inputs | select(length > 0)] | map({(.): {name: .}})) | add // {}')" || return 1
|
|
166
|
-
[ ! -f "$FILE" ] || current="$(cat "$FILE")"
|
|
167
|
-
mkdir -p "$(dirname "$FILE")"
|
|
168
|
-
out="$(printf '%s' "$current" | jq --arg baseurl "$baseurl" --argjson models "$models" '
|
|
169
|
-
."$schema" = (."$schema" // "https://opencode.ai/config.json")
|
|
170
|
-
| .provider["devzone-host"] = {npm: "@ai-sdk/openai-compatible", name: "devzone host models (Ollama)", options: {baseURL: $baseurl}, models: $models}
|
|
171
|
-
')" || {
|
|
172
|
-
echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
|
|
173
|
-
return 1
|
|
174
|
-
}
|
|
175
|
-
if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
|
|
176
|
-
rm -f "$FILE"
|
|
177
|
-
else
|
|
178
|
-
printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
|
|
179
|
-
fi
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
# Removes the devzone-host and devzone-llm providers from the opencode
|
|
183
|
-
# configuration file, keeping everything else. No error when the file is absent.
|
|
184
|
-
unset_provider() {
|
|
185
|
-
[ ! -f "$FILE" ] && return 0
|
|
186
|
-
rewrite 'if .provider then del(.provider["devzone-host"]) | del(.provider["devzone-llm"]) | (if .provider == {} then del(.provider) else . end) else . end'
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
# When run directly (not sourced): dispatch the subcommands.
|
|
190
|
-
if [ "${0##*/}" = "host-models.sh" ]; then
|
|
191
|
-
case "${1:-}" in
|
|
192
|
-
first) premier ;;
|
|
193
|
-
set) set_provider ;;
|
|
194
|
-
unset) unset_provider ;;
|
|
195
|
-
check | rapport)
|
|
196
|
-
exec bash "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/host-check.sh" "$@"
|
|
197
|
-
;;
|
|
198
|
-
*) modeles ;;
|
|
199
|
-
esac
|
|
200
|
-
fi
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# shellcheck shell=bash
|
|
3
|
-
# devzone, ai module: guard of the host container tools.
|
|
4
|
-
# Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
|
|
5
|
-
# functions only, shared variables are defined in devzone.
|
|
6
|
-
|
|
7
|
-
# Docker guard for the folders that are not this repository: a Claude Code
|
|
8
|
-
# PreToolUse hook in the global settings and the two opencode plugins in the
|
|
9
|
-
# global plugins folder. Idempotent, other user settings and hooks preserved.
|
|
10
|
-
# Claude Code also receives the limited Kubernetes context via env.KUBECONFIG.
|
|
11
|
-
install_docker_guard() {
|
|
12
|
-
local script="$ICI/ai/docker-guard.sh" config="$HOME/.claude/settings.json"
|
|
13
|
-
local src="$ICI/ai/plugins" dst="$HOME/.config/opencode/plugins"
|
|
14
|
-
local tmp f
|
|
15
|
-
if ! command -v jq >/dev/null 2>&1; then
|
|
16
|
-
echo "devzone : jq missing: docker guard not installed for Claude Code" >&2
|
|
17
|
-
elif [ ! -f "$config" ]; then
|
|
18
|
-
echo "devzone : $config missing: docker guard not installed for Claude Code" >&2
|
|
19
|
-
elif ! jq -e . "$config" >/dev/null 2>&1; then
|
|
20
|
-
echo "devzone : $config unreadable (invalid JSON): docker guard not installed for Claude Code" >&2
|
|
21
|
-
else
|
|
22
|
-
tmp="$(mktemp)"
|
|
23
|
-
if jq --arg cmd "bash \"$script\" --format claude" \
|
|
24
|
-
--arg kube "$HOME/.kube/agent.config" '
|
|
25
|
-
.hooks = (.hooks // {}) |
|
|
26
|
-
.hooks.PreToolUse = (.hooks.PreToolUse // []) |
|
|
27
|
-
if ([.hooks.PreToolUse[]? | .hooks[]? | (.command // "")] | any(contains("docker-guard.sh")))
|
|
28
|
-
then .
|
|
29
|
-
else .hooks.PreToolUse += [{"matcher": "Bash", "hooks": [{"type": "command", "command": $cmd}]}]
|
|
30
|
-
end |
|
|
31
|
-
if (.env | type) == "object" then .env = (.env + {"KUBECONFIG": $kube})
|
|
32
|
-
elif (.env | type) == "null" then .env = {"KUBECONFIG": $kube}
|
|
33
|
-
else . end
|
|
34
|
-
' "$config" >"$tmp" 2>/dev/null; then
|
|
35
|
-
mv "$tmp" "$config"
|
|
36
|
-
else
|
|
37
|
-
rm -f "$tmp"
|
|
38
|
-
echo "devzone : $config unchanged: docker guard not installed for Claude Code" >&2
|
|
39
|
-
fi
|
|
40
|
-
fi
|
|
41
|
-
mkdir -p "$dst"
|
|
42
|
-
for f in devzone-guard.js devzone-guard-v2.js; do
|
|
43
|
-
[ -f "$src/$f" ] || continue
|
|
44
|
-
sed "s|__DEVZONE_DOCKER_GUARD__|$script|g" "$src/$f" >"$dst/$f"
|
|
45
|
-
done
|
|
46
|
-
echo "devzone : docker guard active for Claude Code and opencode"
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
# Removes only the Docker guard entries (commands containing docker-guard.sh)
|
|
50
|
-
# and the two plugins; the rest of settings.json and of the plugins is kept.
|
|
51
|
-
# The Kubernetes context key is removed too, and an empty env object is dropped.
|
|
52
|
-
remove_docker_guard() {
|
|
53
|
-
local config="$HOME/.claude/settings.json" tmp tmp2
|
|
54
|
-
if [ -f "$config" ] && jq -e . "$config" >/dev/null 2>&1; then
|
|
55
|
-
tmp="$(mktemp)"
|
|
56
|
-
if jq '
|
|
57
|
-
if (.hooks.PreToolUse // null) != null then
|
|
58
|
-
.hooks.PreToolUse = [
|
|
59
|
-
.hooks.PreToolUse[] |
|
|
60
|
-
if (.hooks // null) != null then
|
|
61
|
-
.hooks = [ .hooks[] | select(((.command // "") | contains("docker-guard.sh")) | not) ] |
|
|
62
|
-
select((.hooks | length) > 0)
|
|
63
|
-
else
|
|
64
|
-
select(((.command // "") | contains("docker-guard.sh")) | not)
|
|
65
|
-
end
|
|
66
|
-
] |
|
|
67
|
-
if (.hooks.PreToolUse | length) == 0 then del(.hooks.PreToolUse) else . end |
|
|
68
|
-
if ((.hooks // {}) | keys | length) == 0 then del(.hooks) else . end
|
|
69
|
-
else . end
|
|
70
|
-
' "$config" >"$tmp" 2>/dev/null; then
|
|
71
|
-
if [ "$(cat "$tmp")" = "{}" ]; then
|
|
72
|
-
rm -f "$tmp" "$config"
|
|
73
|
-
else
|
|
74
|
-
tmp2="$(mktemp)"
|
|
75
|
-
if jq '
|
|
76
|
-
if (.env | type) == "object" then
|
|
77
|
-
.env = (.env | del(.KUBECONFIG)) |
|
|
78
|
-
if (.env | length) == 0 then del(.env) else . end
|
|
79
|
-
else . end
|
|
80
|
-
' "$tmp" >"$tmp2" 2>/dev/null; then
|
|
81
|
-
if [ "$(cat "$tmp2")" = "{}" ]; then
|
|
82
|
-
rm -f "$tmp2" "$config"
|
|
83
|
-
else
|
|
84
|
-
mv "$tmp2" "$config"
|
|
85
|
-
fi
|
|
86
|
-
else
|
|
87
|
-
rm -f "$tmp2"
|
|
88
|
-
mv "$tmp" "$config"
|
|
89
|
-
fi
|
|
90
|
-
rm -f "$tmp"
|
|
91
|
-
fi
|
|
92
|
-
else
|
|
93
|
-
rm -f "$tmp"
|
|
94
|
-
fi
|
|
95
|
-
fi
|
|
96
|
-
rm -f "$HOME/.config/opencode/plugins/devzone-guard.js" \
|
|
97
|
-
"$HOME/.config/opencode/plugins/devzone-guard-v2.js"
|
|
98
|
-
}
|