devzone 0.56.0 → 0.58.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.
@@ -179,11 +179,11 @@ set_provider() {
179
179
  fi
180
180
  }
181
181
 
182
- # Removes the devzone-host provider from the opencode configuration file,
183
- # keeping everything else. No error when the file is absent.
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
184
  unset_provider() {
185
185
  [ ! -f "$FILE" ] && return 0
186
- rewrite 'if .provider then del(.provider["devzone-host"]) | (if .provider == {} then del(.provider) else . end) else . end'
186
+ rewrite 'if .provider then del(.provider["devzone-host"]) | del(.provider["devzone-llm"]) | (if .provider == {} then del(.provider) else . end) else . end'
187
187
  }
188
188
 
189
189
  # When run directly (not sourced): dispatch the subcommands.
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env bash
2
- # Installs or removes a devzone service (gitlab, postgres, argocd, llm) from inside
2
+ # Installs or removes a devzone service (gitlab, postgres, argocd) from inside
3
3
  # the Kubernetes workspace pod, with a temporary administrator token (#528).
4
4
  # services-admin.sh enable|disable <service> [options of devzone enable]
5
5
  # services-admin.sh seed gitlab data of gitlab seeded again, in the pod (#538)
6
- # services-admin.sh bench llm [options] speed of the model (#593)
7
6
  # Run by the workstation (manage/scripts/services-workspace.sh) through
8
7
  # kubectl exec -i: the token comes on stdin, is never printed and lives only
9
8
  # in a temporary kubeconfig removed at the end.
@@ -44,20 +43,17 @@ service="${2:-}"
44
43
  case "$action" in
45
44
  enable | activer) action=enable ;;
46
45
  disable | desactiver) action=disable ;;
47
- seed | bench) ;;
48
- *) refuse "usage: services-admin.sh enable|disable|seed|bench gitlab|postgres|argocd|llm [options]" ;;
46
+ seed) ;;
47
+ *) refuse "usage: services-admin.sh enable|disable|seed gitlab|postgres|argocd [options]" ;;
49
48
  esac
50
49
  case "$service" in
51
- gitlab | postgres | argocd | llm) ;;
52
- *) refuse "unknown service: ${service:-(none)} (gitlab, postgres, argocd, llm)" ;;
50
+ gitlab | postgres | argocd) ;;
51
+ *) refuse "unknown service: ${service:-(none)} (gitlab, postgres, argocd)" ;;
53
52
  esac
54
53
  # The seed of the data (group, demo project, dev user, runner) is gitlab's (#538)
55
54
  if [ "$action" = seed ] && [ "$service" != gitlab ]; then
56
55
  refuse "seed: only gitlab"
57
56
  fi
58
- if [ "$action" = bench ] && [ "$service" != llm ]; then
59
- refuse "bench: only llm"
60
- fi
61
57
  [ "${DEVZONE_WORKSPACE:-}" = kubernetes ] || refuse "only in the Kubernetes workspace pod"
62
58
  [ -f "$SA_DIR/ca.crt" ] || refuse "cluster CA not found: $SA_DIR/ca.crt"
63
59
  if [ -t 0 ]; then
@@ -118,6 +114,5 @@ echo "devzone services: $action $service in the cluster of the pod (temporary ad
118
114
  case "$action" in
119
115
  # The seed is a module command: devzone gitlab seed (#538)
120
116
  seed) "$DEVZONE_CMD" gitlab seed "${@:3}" ;;
121
- bench) "$DEVZONE_CMD" llm bench "${@:3}" ;;
122
117
  *) "$DEVZONE_CMD" "$action" "$service" "${@:3}" ;;
123
118
  esac
package/README.md CHANGED
@@ -49,7 +49,7 @@ Sous Windows : il est recommandé de cloner avec Git for Windows (les scripts re
49
49
 
50
50
  #### Mémoire minimale par module
51
51
 
52
- Mesures du 16/11/2026. Le chiffre LLM vient des valeurs du chart (non mesuré en service).
52
+ Mesures du 16/11/2026.
53
53
 
54
54
  | Module | Consommation mesurée | Mémoire allouable exigée par devzone |
55
55
  |---|---|---|
@@ -57,8 +57,6 @@ Mesures du 16/11/2026. Le chiffre LLM vient des valeurs du chart (non mesuré en
57
57
  | GitLab | ~3,6 Go | 8 Go |
58
58
  | MySQL | ~0,5 Go | aucune |
59
59
  | Argo CD | ~0,6 Go | 1 Go |
60
- | LLM modèle 7B (7 milliards de paramètres, fichier Q4_K_M) | 6 Gi | 12 Go |
61
- | LLM --preset light (modèle 3B) | 3 Gi demandés, 4 Gi en limite | 8 Go |
62
60
 
63
61
  Sur Docker Desktop (kind), le contrôle compare le minimum à la mémoire d'un seul nœud, donc à la VM ; sur un cluster de vraies machines, à la somme des nœuds.
64
62
 
@@ -245,7 +243,7 @@ Dans le conteneur, le récapitulatif `devzone` signale une version publiée plus
245
243
 
246
244
  **Module `ia`** : active Claude Code et opencode (versions figées), avec le garde-fou repowarden qui les arrête avant de modifier `main` ou `develop` ou de commiter sans `repowarden cc` (voir [manage/docs/reference.md](manage/docs/reference.md#garde-fou-des-assistants-ia)). Pour l'activer : `devzone enable ia`. Ils sont désinstallés quand le module est désactivé, mais tes connexions restent dans leurs volumes. Le module pose aussi un garde-fou qui arrête les commandes `docker` des agents : devzone est Kubernetes d'abord, seuls les pods sont des conteneurs (`kubectl`, ou un pod jetable, à la place).
247
245
 
248
- **Modèles de ton ordinateur** : devzone n'héberge aucun modèle. Si Ollama tourne sur ta machine, `devzone enable ia` détecte ses modèles et les branche à opencode (rien n'est installé ni téléchargé). `devzone ai` les liste avec le modèle par défaut, `devzone ai check` dit si chacun est à jour sans rien télécharger, et `devzone ai rapport` détaille le modèle retenu et pourquoi (la variable `DEVZONE_HOST_MODEL`, une mesure, ou la règle « un modèle de code d'abord, puis le plus petit »). Détails dans [manage/docs/reference.md](manage/docs/reference.md#configuration-dopencode).
246
+ **Modèles de ton ordinateur** : devzone n'héberge aucun modèle. Si Ollama tourne sur ta machine, `devzone enable ia` détecte ses modèles et les branche à opencode (rien n'est installé ni téléchargé). `devzone ai` les liste avec le modèle par défaut, `devzone ai check` dit si chacun est à jour sans rien télécharger, et `devzone ai rapport` détaille le modèle retenu et pourquoi (la variable `DEVZONE_HOST_MODEL`, une mesure, ou la règle « un modèle de code d'abord, puis le plus petit »). Détails dans [manage/docs/reference.md](manage/docs/reference.md#configuration-dopencode). Le module `llm` (modèle hébergé dans le cluster) a été retiré : devzone n'héberge aucun modèle.
249
247
 
250
248
  **Module `kubernetes`** : active à chaque démarrage la connexion au cluster de l'hôte et l'installation de metrics-server sur les clusters locaux (pour voir le CPU et la RAM dans k9s). Pour l'activer : `devzone enable kubernetes`. Sans ce module, kubectl, helm, k9s et kind restent installés.
251
249
 
@@ -253,8 +251,6 @@ Dans le conteneur, le récapitulatif `devzone` signale une version publiée plus
253
251
 
254
252
  **Module `postgres`** : un PostgreSQL partagé, une base par projet (voir [Accéder à PostgreSQL](#accéder-à-postgresql)). Pour l'activer : `devzone enable postgres`.
255
253
 
256
- **Module `llm`** : un modèle de code local (Qwen2.5-Coder, sur CPU) dans le cluster de devzone, utilisé par opencode quand les modèles en ligne sont épuisés ou injoignables ; premier téléchargement de plusieurs Go (voir [manage/docs/reference.md](manage/docs/reference.md#modèle-de-code-local)). Pour l'activer : `devzone enable llm` (`--preset light` sur une machine juste en mémoire).
257
-
258
254
  **Module `argocd`** : Argo CD sur le cluster de devzone, interface sur https://127.0.0.1:8443 dans le conteneur (voir [Argo CD](manage/docs/reference.md#argo-cd)). Pour l'activer : `devzone enable argocd`.
259
255
 
260
256
  **Option `devzone agent --pod`** : lance une session agent dans un pod éphémère isolé (ticket #222). Le pod est créé avec des ressources limitées (2 CPU, 4 Gi mémoire), des montages restreints du workspace et de l'état, et une affinité obligatoire vers le pod workspace. Isole : worktree du ticket au même chemin que dans le workspace, .git du dépôt, et sous-dossiers d'état (.config/opencode, .local/share/opencode, .local/state/oc-lancer, .local/npm en lecture seule). N'isole pas : le réseau (non filtré, c'est #220), le kubeconfig de l'hôte, `~/.config/gh`, `~/.claude`, les autres worktrees, et, comme le `.git` du dépôt est monté, les références git des autres branches y restent lisibles et modifiables. Sans `--pod`, le comportement `devzone agent` actuel est strictement inchangé.
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  # devzone workspace services (#528): installs or removes the devzone services
3
- # (gitlab, postgres, mysql, argocd, llm) of a Kubernetes workspace from the workstation.
3
+ # (gitlab, postgres, mysql, argocd) of a Kubernetes workspace from the workstation.
4
4
  # Sourced by manage/workspace.sh (drapeau_kubectl, POD, NAMESPACE).
5
5
  # devzone workspace services enable <service> [options]
6
6
  # devzone workspace services disable <service> [--yes]
7
- # devzone workspace services bench llm [--apply] [--threads …] [--prompt …] [--gen …]
8
7
  # devzone workspace services status
9
8
  # Why: the pod has no administrator access to the cluster (#430), while the
10
9
  # installers need one. The workstation creates a ServiceAccount bound to
@@ -20,12 +19,12 @@ SERVICES_ADMIN_SCRIPT="${DEVZONE_SERVICES_ADMIN_SCRIPT:-/usr/local/share/devzone
20
19
  SERVICES_TOKEN_DURATION="${DEVZONE_SERVICES_TOKEN_DURATION:-1h}"
21
20
 
22
21
  services_usage() {
23
- echo "devzone workspace services enable|disable <gitlab|postgres|mysql|argocd|llm> [options] | seed gitlab | bench llm [--apply] [--threads …] [--prompt …] [--gen …] | status"
22
+ echo "devzone workspace services enable|disable <gitlab|postgres|mysql|argocd> [options] | seed gitlab | status"
24
23
  }
25
24
 
26
25
  services_known() {
27
26
  case "${1:-}" in
28
- gitlab | postgres | mysql | argocd | llm) return 0 ;;
27
+ gitlab | postgres | mysql | argocd) return 0 ;;
29
28
  esac
30
29
  return 1
31
30
  }
@@ -47,7 +46,6 @@ services_namespace() {
47
46
  postgres) echo devzone-postgres ;;
48
47
  mysql) echo devzone-mysql ;;
49
48
  argocd) echo devzone-argocd ;;
50
- llm) echo devzone-llm ;;
51
49
  esac
52
50
  }
53
51
 
@@ -113,10 +111,10 @@ services_run() {
113
111
  services_state_note "$action" "$service"
114
112
  return 0
115
113
  fi
116
- # bench is a measure, not a change of state: never taken by Argo CD
114
+ # postgres and mysql are held by Argo CD when it holds the charts
117
115
  case "$service" in
118
- postgres | mysql | llm)
119
- if [ "$action" != bench ] && argocd_holds_charts; then
116
+ postgres | mysql)
117
+ if argocd_holds_charts; then
120
118
  services_argocd_toggle "$service" "$action" "$@"
121
119
  code=$?
122
120
  [ "$code" -eq 0 ] || return "$code"
@@ -161,7 +159,7 @@ services_run() {
161
159
  # One line per service: installed (namespace present) or not
162
160
  services_status() {
163
161
  local s ns
164
- for s in gitlab postgres mysql argocd llm; do
162
+ for s in gitlab postgres mysql argocd; do
165
163
  ns="$(services_namespace "$s")"
166
164
  # shellcheck disable=SC2046
167
165
  if kubectl $(drapeau_kubectl) get namespace "$ns" >/dev/null 2>&1; then
@@ -186,14 +184,6 @@ services() {
186
184
  fi
187
185
  services_run seed gitlab
188
186
  ;;
189
- # The speed of the model measured from the workstation, in the pod (#593)
190
- bench)
191
- if [ "${2:-}" != llm ]; then
192
- echo "✖ bench: only llm ($(services_usage))" >&2
193
- return 1
194
- fi
195
- services_run bench llm "${@:3}"
196
- ;;
197
187
  status | etat | '') services_status ;;
198
188
  *)
199
189
  echo "✖ unknown subcommand: $sub ($(services_usage))" >&2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "0.56.0",
3
+ "version": "0.58.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": {
@@ -1,171 +0,0 @@
1
- #!/usr/bin/env bash
2
- # devzone llm bench (#593), sourced by llm.sh (uses its NS, k, preset_read
3
- # and refuse): llama-bench of the model in a Kubernetes Job of the
4
- # namespace devzone-llm (image full-<llamaBuild> of the chart, same build as the
5
- # server, pulled only here), then a table, a threads recommendation and whether
6
- # the speed is enough for opencode.
7
- # devzone llm bench [--apply] [--threads LIST] [--prompt N] [--gen N]
8
- # --apply sets threads=<best> on the release llm (helm upgrade, values kept).
9
- # Env: LLM_BENCH_ATTENTE (seconds, 1800: wait limit and activeDeadlineSeconds of
10
- # the Job, which stops by itself if the call is interrupted), LLM_BENCH_POLL
11
- # (seconds, 5), LLM_BENCH_SIGNE (seconds, 30: a progress line at least this
12
- # often, so that the connection of kubectl exec is not cut), LLM_BENCH_MIN_PP (50 tok/s, prompt reading), LLM_BENCH_MIN_TG (8 tok/s,
13
- # generation). The Job is deleted at the end, even on failure. bash 3.2 (macOS).
14
-
15
- BENCH_JOB=llm-bench
16
-
17
- # Server present, read with the rights of the namespace (the account of the pod
18
- # cannot read a namespace, a cluster resource: installed would fail for it)
19
- bench_present() { k get deployment llm >/dev/null 2>&1; }
20
-
21
- # Job deleted (no error when it is already gone)
22
- bench_cleanup() { k delete job "$BENCH_JOB" --ignore-not-found --wait=false >/dev/null 2>&1 || true; }
23
-
24
- # Phase of the Job for the progress line, read from the state of the container
25
- # (not the phase of the pod): waiting (ContainerCreating, PullImage...) is
26
- # pulling, running or terminated is measuring. The caller keeps the phase
27
- # monotone: once measuring, it never goes back to pulling.
28
- bench_phase() {
29
- local etat
30
- etat="$(k get pods -l app=llm-bench -o jsonpath='{.items[0].status.containerStatuses[0].state.running.startedAt}|{.items[0].status.containerStatuses[0].state.terminated.reason}' 2>/dev/null || true)"
31
- case "$etat" in
32
- "|" | "") echo "pulling the image" ;;
33
- *) echo "measuring" ;;
34
- esac
35
- }
36
-
37
- # Waits for the Job: 0 done, 1 failed, 2 timeout. Writes a line (phase,
38
- # elapsed time) at least every LLM_BENCH_SIGNE seconds
39
- bench_wait() {
40
- local waited=0 poll="${LLM_BENCH_POLL:-5}" limit="${LLM_BENCH_ATTENTE:-1800}" beat="${LLM_BENCH_SIGNE:-30}" st last="" phase="pulling the image"
41
- while [ "$waited" -lt "$limit" ]; do
42
- st="$(k get job "$BENCH_JOB" -o jsonpath='{.status.succeeded}/{.status.failed}' 2>/dev/null || true)"
43
- case "$st" in
44
- 1/*) return 0 ;;
45
- */[1-9]*) return 1 ;;
46
- esac
47
- if [ -z "$last" ] || [ $((waited - last)) -ge "$beat" ]; then
48
- # Monotone: once measuring, the phase is not read again
49
- [ "$phase" = measuring ] || phase="$(bench_phase)"
50
- echo " … $phase, ${waited}s elapsed"
51
- last=$waited
52
- fi
53
- sleep "$poll"
54
- waited=$((waited + poll))
55
- done
56
- return 2
57
- }
58
-
59
- # Table "threads pp tg" (tok/s) from the JSON of llama-bench (logs of the Job:
60
- # the array is the part between the line "[" and the line "]")
61
- bench_rows() {
62
- sed -n '/^\[/,/^\]/p' | jq -r '
63
- group_by(.n_threads)[]
64
- | [.[0].n_threads,
65
- (map(select(.n_prompt > 0 and .n_gen == 0)) | .[0].avg_ts // 0),
66
- (map(select(.n_gen > 0 and .n_prompt == 0)) | .[0].avg_ts // 0)]
67
- | @tsv' 2>/dev/null
68
- }
69
-
70
- # Best row (generation speed, then fewer threads) and the verdict, from the
71
- # rows on stdin: prints the table then "best=<n>" and "ok=0|1"
72
- bench_report() {
73
- awk -v mpp="${LLM_BENCH_MIN_PP:-50}" -v mtg="${LLM_BENCH_MIN_TG:-8}" '
74
- { t[NR] = $1; pp[NR] = $2; tg[NR] = $3 }
75
- END {
76
- printf "%-8s %-22s %s\n", "threads", "prompt (tok/s)", "generation (tok/s)"
77
- b = 0
78
- for (i = 1; i <= NR; i++) {
79
- printf "%-8s %-22.1f %.1f\n", t[i], pp[i], tg[i]
80
- if (b == 0 || tg[i] > tg[b] || (tg[i] == tg[b] && t[i] + 0 < t[b] + 0)) b = i
81
- }
82
- if (b == 0) exit 1
83
- print "best=" t[b]
84
- print "ok=" ((pp[b] >= mpp && tg[b] >= mtg) ? 1 : 0)
85
- }'
86
- }
87
-
88
- # Commands proposed to the user, by place: the Kubernetes workspace runs the
89
- # bench through devzone workspace services (DEVZONE_SERVICES_ADMIN, set by
90
- # services-admin.sh); the Docker container keeps devzone llm
91
- bench_cmds() {
92
- if [ -n "${DEVZONE_SERVICES_ADMIN:-}" ]; then
93
- CMD_APPLY="devzone workspace services bench llm --apply"
94
- CMD_LIGHT="devzone workspace services disable llm && devzone workspace services enable llm --preset light"
95
- else
96
- CMD_APPLY="devzone llm bench --apply"
97
- CMD_LIGHT="devzone disable llm && devzone enable llm --preset light"
98
- fi
99
- }
100
-
101
- bench_apply() {
102
- helm --kube-context devzone upgrade llm "$CHART_CODE/charts/devzone-llm" -n "$NS" --reset-then-reuse-values --set "threads=$1" >/dev/null || return 1
103
- wait_ready
104
- }
105
-
106
- bench() {
107
- local apply="" want="" arg threads="" prompt="" gen="" sets logs rows report best ok
108
- local -a args
109
- for arg in "$@"; do
110
- if [ -n "$want" ]; then
111
- case "$want" in
112
- threads) threads="$arg" ;;
113
- prompt) prompt="$arg" ;;
114
- gen) gen="$arg" ;;
115
- esac
116
- want=""
117
- continue
118
- fi
119
- case "$arg" in
120
- --apply) apply=1 ;;
121
- --threads | --prompt | --gen) want="${arg#--}" ;;
122
- *) refuse "unknown argument: $arg (devzone llm bench [--apply] [--threads 4,8] [--prompt 128] [--gen 32])" ;;
123
- esac
124
- done
125
- [ -z "$want" ] || refuse "--$want needs a value"
126
- # In the pod only devzone workspace services (DEVZONE_SERVICES_ADMIN) has rights on the namespace
127
- if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ] && [ -z "${DEVZONE_SERVICES_ADMIN:-}" ]; then
128
- echo "devzone: llm bench runs from your computer: devzone workspace services bench llm" >&2
129
- exit 2
130
- fi
131
- bench_present || refuse "bench: the module is not enabled (devzone enable llm)"
132
- sets="$(llm_preset_sets "$(preset_read)") bench.enabled=true"
133
- [ -z "$threads" ] || sets="$sets bench.threads=${threads//,/\\,}" # helm --set: a comma separates keys
134
- [ -z "$prompt" ] || sets="$sets bench.prompt=$prompt"
135
- [ -z "$gen" ] || sets="$sets bench.gen=$gen"
136
- sets="$sets bench.deadline=${LLM_BENCH_ATTENTE:-1800}"
137
- args=()
138
- for arg in $sets; do args+=(--set "$arg"); done
139
- trap bench_cleanup EXIT INT TERM
140
- bench_cleanup
141
- echo "▶ llama-bench in the namespace $NS (image full-<build>: larger than the server image, pulled on first use; the server keeps running, so the numbers are a bit low)…"
142
- helm template llm "$CHART_CODE/charts/devzone-llm" -n "$NS" "${args[@]}" --show-only templates/bench-job.yaml | k apply -f - >/dev/null || return 1
143
- bench_wait || {
144
- echo "devzone: llm: bench Job failed or timed out (LLM_BENCH_ATTENTE=${LLM_BENCH_ATTENTE:-1800}s): kubectl --context devzone -n $NS logs job/$BENCH_JOB" >&2
145
- k logs "job/$BENCH_JOB" --tail=5 >&2 2>/dev/null || true
146
- return 1
147
- }
148
- logs="$(k logs "job/$BENCH_JOB" 2>/dev/null || true)"
149
- rows="$(printf '%s\n' "$logs" | bench_rows)"
150
- [ -n "$rows" ] || { echo "devzone: llm: no llama-bench result in the logs of the Job" >&2; return 1; }
151
- report="$(printf '%s\n' "$rows" | bench_report)"
152
- printf '%s\n' "$report" | grep -v '^best=\|^ok='
153
- best="$(printf '%s\n' "$report" | sed -n 's/^best=//p')"
154
- ok="$(printf '%s\n' "$report" | sed -n 's/^ok=//p')"
155
- echo "▶ Recommended: threads=$best"
156
- bench_cmds
157
- if [ "$ok" = 1 ]; then
158
- echo "✔ Fast enough for opencode (prompt >= ${LLM_BENCH_MIN_PP:-50} tok/s, generation >= ${LLM_BENCH_MIN_TG:-8} tok/s)"
159
- else
160
- echo "⚠ Too slow for opencode (needs prompt >= ${LLM_BENCH_MIN_PP:-50} tok/s and generation >= ${LLM_BENCH_MIN_TG:-8} tok/s)"
161
- if [ "$(preset_read)" != light ]; then
162
- echo " Lighter model (3B, context 16k, 2.1 GB download): $CMD_LIGHT"
163
- fi
164
- fi
165
- if [ -n "$apply" ]; then
166
- bench_apply "$best" || return 1
167
- echo "✔ threads=$best applied to the release llm"
168
- else
169
- echo " $CMD_APPLY sets threads=$best on the release"
170
- fi
171
- }
@@ -1,262 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Module llm (#586): local code model (llama.cpp llama-server, CPU) in the
3
- # cluster of the services, namespace devzone-llm, chart charts/devzone-llm.
4
- # llm.sh install [--preset default|light] [--context CTX]
5
- # llm.sh uninstall release removed, the volume llm-models is kept
6
- # llm.sh status | relay-start | relay-stop | policy (ingress from devzone-workspace)
7
- # llm.sh preset [--preset P] preset stored for the next install (Argo CD path)
8
- # llm.sh apply on|off [...] what `devzone enable|disable llm` runs
9
- # llm.sh delete-data [--yes] namespace and volume removed (the model is downloaded again)
10
- # llm.sh bench [--apply] llama-bench Job and threads recommendation (bench.sh)
11
- # First start = model download: LLM_ATTENTE (seconds, default 1800) is the wait.
12
- # Relay LLM_PORT (default 8089); opencode provider: opencode.sh. bash 3.2 (macOS).
13
- set -euo pipefail
14
-
15
- ICI="$(cd "$(dirname "$0")" && pwd)"
16
- RACINE="${DEVZONE_RACINE:-$(dirname "$(dirname "$ICI")")}"
17
- # shellcheck disable=SC2034 # read by cluster.sh (sourced library)
18
- ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
19
- # shellcheck source=SCRIPTDIR/../cluster.sh
20
- # shellcheck disable=SC1091
21
- . "$ICI/../cluster.sh"
22
- # shellcheck source=SCRIPTDIR/../chart-direct.sh
23
- # shellcheck disable=SC1091
24
- . "$ICI/../chart-direct.sh"
25
- # shellcheck source=SCRIPTDIR/../isolement.sh
26
- # shellcheck disable=SC1091
27
- . "$ICI/../isolement.sh"
28
- # shellcheck source=SCRIPTDIR/presets.sh
29
- # shellcheck disable=SC1091
30
- . "$ICI/presets.sh"
31
- # shellcheck source=SCRIPTDIR/bench.sh
32
- # shellcheck disable=SC1091
33
- . "$ICI/bench.sh"
34
- # Memory check of the services cluster, shared with the other modules (#608)
35
- # shellcheck source=SCRIPTDIR/../memoire.sh
36
- # shellcheck disable=SC1091
37
- . "$ICI/../memoire.sh"
38
-
39
- NS=devzone-llm
40
- STATE_DIR="$RACINE/workspace/.llm"
41
- LLM_PORT="${LLM_PORT:-8089}"
42
- LLM_ATTENTE="${LLM_ATTENTE:-1800}"
43
- LLM_SIZE="${LLM_SIZE:-8Gi}"
44
-
45
- refuse() { echo "devzone: llm: $*" >&2; exit 2; }
46
-
47
- k() { kubectl --context devzone -n "$NS" "$@"; }
48
-
49
- installed() { compte_admin "$(compte_ctx)" get namespace "$NS" >/dev/null 2>&1; }
50
-
51
- # Preset stored by the last install, "default" without one
52
- preset_read() {
53
- local p
54
- p="$(cat "$STATE_DIR/preset" 2>/dev/null || true)"
55
- llm_preset_name "$p" 2>/dev/null || echo default
56
- }
57
-
58
- # --preset P and --context C of the arguments: PRESET and WANTED_CTX are set
59
- parse_args() {
60
- local want="" arg
61
- PRESET=""
62
- WANTED_CTX=""
63
- for arg in "$@"; do
64
- if [ -n "$want" ]; then
65
- case "$want" in
66
- preset) PRESET="$arg" ;;
67
- context) WANTED_CTX="$arg" ;;
68
- esac
69
- want=""
70
- continue
71
- fi
72
- case "$arg" in
73
- --preset) want=preset ;;
74
- --context) want=context ;;
75
- *) refuse "unknown argument: $arg (devzone enable llm [--preset light] [--context CTX])" ;;
76
- esac
77
- done
78
- [ -z "$want" ] || refuse "--$want needs a value"
79
- if [ -n "$PRESET" ]; then
80
- PRESET="$(llm_preset_name "$PRESET")" || refuse "unknown preset (default or light)"
81
- fi
82
- }
83
-
84
- # Stores the preset: the explicit one, else the one already stored
85
- preset_store() {
86
- parse_args "$@"
87
- [ -n "$PRESET" ] || PRESET="$(preset_read)"
88
- mkdir -p "$STATE_DIR"
89
- printf '%s\n' "$PRESET" >"$STATE_DIR/preset"
90
- }
91
-
92
- # Ingress from the workspace namespace (the pod of the workspace reaches
93
- # llm:8080), next to the same-namespace rule of namespace_isoler
94
- policy() {
95
- kubectl --context devzone -n "$NS" apply -f - >/dev/null <<YAML
96
- apiVersion: networking.k8s.io/v1
97
- kind: NetworkPolicy
98
- metadata:
99
- name: devzone-llm-workspace
100
- labels:
101
- app.kubernetes.io/managed-by: devzone
102
- spec:
103
- podSelector: {}
104
- ingress:
105
- - from:
106
- - namespaceSelector:
107
- matchLabels:
108
- kubernetes.io/metadata.name: devzone-workspace
109
- YAML
110
- }
111
-
112
- # Waits for the deployment, a progress line each minute (the model is
113
- # downloaded on the first start)
114
- wait_ready() {
115
- local waited=0 step=60
116
- echo "▶ Waiting for the model (first start: download, several minutes; timeout ${LLM_ATTENTE}s, LLM_ATTENTE)…"
117
- while [ "$waited" -lt "$LLM_ATTENTE" ]; do
118
- if k rollout status deployment/llm --timeout="${step}s" >/dev/null 2>&1; then
119
- return 0
120
- fi
121
- waited=$((waited + step))
122
- echo " … ${waited}s/${LLM_ATTENTE}s: model not ready yet"
123
- done
124
- echo "devzone: llm: not ready after ${LLM_ATTENTE}s: kubectl --context devzone -n $NS logs deploy/llm -c fetch-model" >&2
125
- return 1
126
- }
127
-
128
- install() {
129
- local ctx sets minimum_go=12 astuce=""
130
- local -a args
131
-
132
- preset_store "$@"
133
- # The light preset (3B) asks for 8 Gi, the 7B model for 12 Gi
134
- if [ "$(preset_read)" = light ]; then
135
- minimum_go=8
136
- else
137
- astuce="--preset light (8 Go)"
138
- fi
139
- verifier_memoire_module llm "$minimum_go" "$astuce" || return 2
140
-
141
- ctx="$(cluster_lu)"
142
- if [ -z "$ctx" ]; then
143
- ctx="$(cluster_choisir "$WANTED_CTX")" || return 2
144
- cluster_ecrire "$ctx"
145
- fi
146
- cluster_preparer "$ctx"
147
- contexte_devzone_poser "$ctx" || { echo "devzone: llm: cannot set the devzone context on $ctx" >&2; return 1; }
148
- echo "▶ Local model on the cluster $ctx (namespace $NS, preset $(preset_read))…"
149
- compte_namespace "$ctx" "$NS"
150
- namespace_isoler "$NS" >/dev/null
151
- policy
152
- sets="$(llm_preset_sets "$(preset_read)") size=$LLM_SIZE"
153
- read -r -a args <<<"$sets"
154
- chart_install llm "$NS" "${args[@]}" || return 1
155
- wait_ready || return 1
156
- relais_arreter llm
157
- relais_lancer llm "$ctx" "$NS" svc/llm "$LLM_PORT:8080"
158
- bash "$ICI/opencode.sh" set
159
- echo "✔ Local model ready: http://llm.$NS.svc.cluster.local:8080/v1 (127.0.0.1:$LLM_PORT here)"
160
- }
161
-
162
- # The release leaves, the volume (model) and the namespace stay
163
- uninstall() {
164
- local ctx
165
- ctx="$(cluster_lu)"
166
- relais_arreter llm
167
- bash "$ICI/opencode.sh" unset
168
- if [ -n "$ctx" ] && installed; then
169
- contexte_devzone_poser "$ctx" || true
170
- helm --kube-context devzone uninstall llm -n "$NS" >/dev/null 2>&1 || true
171
- echo "✔ llm removed from $ctx; volume llm-models kept (devzone llm delete-data removes it)"
172
- fi
173
- }
174
-
175
- delete_data() {
176
- local ctx yes="" answer
177
- ctx="$(cluster_lu)"
178
- [ "${1:-}" != --yes ] || yes=1
179
- installed || { echo "devzone: llm: nothing to delete"; return 0; }
180
- if [ -z "$yes" ]; then
181
- cluster_interactif || refuse "no terminal: devzone llm delete-data --yes"
182
- printf 'Delete the namespace %s and the downloaded model? [y/N] ' "$NS" >&2
183
- read -r answer || answer=""
184
- case "$answer" in y | Y | yes | o | O | oui) ;; *) echo "Aborted: nothing deleted."; return 0 ;; esac
185
- fi
186
- uninstall
187
- compte_retirer "$ctx" "$NS" >/dev/null 2>&1 || true
188
- compte_admin "$ctx" delete namespace "$NS" --wait=true >/dev/null
189
- cluster_liberer "$ctx"
190
- echo "✔ namespace $NS and model volume deleted"
191
- }
192
-
193
- status() {
194
- local ctx mem
195
- ctx="$(cluster_lu)"
196
- if [ -z "$ctx" ] || ! installed; then
197
- echo "disabled"
198
- return 0
199
- fi
200
- if [ "$(k get deployment llm -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
201
- echo "not ready on $ctx: starting (first download) or failed, devzone apply"
202
- return 0
203
- fi
204
- mem="$(k get deployment llm -o jsonpath='{.spec.template.spec.containers[0].resources.limits.memory}' 2>/dev/null || true)"
205
- if relais_actif llm; then
206
- echo "ready on $ctx: $(llm_preset_file "$(preset_read)"), memory limit ${mem:-?}, reachable 127.0.0.1:$LLM_PORT"
207
- else
208
- echo "ready on $ctx: $(llm_preset_file "$(preset_read)"), memory limit ${mem:-?}, relay stopped: devzone apply"
209
- fi
210
- }
211
-
212
- relay_start() {
213
- local ctx
214
- ctx="$(cluster_lu)"
215
- [ -z "$ctx" ] || ! installed || relais_lancer llm "$ctx" "$NS" svc/llm "$LLM_PORT:8080"
216
- }
217
-
218
- # Writes llm=off in the state file (bad argument, no cluster)
219
- state_off() {
220
- [ -f "$ETAT" ] || return 0
221
- grep -v '^llm=' "$ETAT" >"$ETAT.tmp" || true
222
- echo "llm=off" >>"$ETAT.tmp"
223
- mv "$ETAT.tmp" "$ETAT"
224
- }
225
-
226
- # What `devzone enable|disable llm` runs: on installs (or restarts the relay),
227
- # off removes the release; a failure leaves a marker read by devzone status
228
- apply() {
229
- local action="${1:-}" current marker="$ETAT-echec-llm"
230
- shift || true
231
- if [ "$action" = on ]; then
232
- current="$(status)"
233
- if [[ "$current" == *"relay stopped"* ]]; then
234
- relay_start
235
- echo "devzone: llm: relay restarted"
236
- elif [[ "$current" == "ready on"* ]]; then
237
- bash "$ICI/opencode.sh" set && echo "devzone: llm already active, nothing to do."
238
- elif ! bash "${BASH_SOURCE[0]}" install "$@"; then
239
- state_off
240
- echo llm >"$marker"
241
- return 1
242
- fi
243
- rm -f "$marker"
244
- else
245
- uninstall
246
- rm -f "$marker"
247
- fi
248
- }
249
-
250
- case "${1:-}" in
251
- install) install "${@:2}" ;;
252
- uninstall) uninstall ;;
253
- status) status ;;
254
- preset) preset_store "${@:2}" ;;
255
- policy) policy ;;
256
- apply) apply "${@:2}" ;;
257
- delete-data) delete_data "${2:-}" ;;
258
- bench) bench "${@:2}" ;;
259
- relay-start) relay_start ;;
260
- relay-stop) relais_arreter llm ;;
261
- *) echo "devzone llm: status | bench [--apply] | delete-data [--yes]" >&2; exit 1 ;;
262
- esac
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env bash
2
- # opencode provider of the local model (#586), in a file apart managed by devzone:
3
- # opencode.sh set provider devzone-llm (model local) put in the config
4
- # opencode.sh unset provider removed (the rest of the file is kept)
5
- # opencode.sh url base URL of the model seen from here
6
- # File: ~/.config/opencode/config.json. opencode (1.19) reads it on its own, for
7
- # the interactive session and for `opencode run`, with no environment variable,
8
- # before opencode.json(c) (devzone enable ia) and OPENCODE_CONFIG_CONTENT (devzone
9
- # agent), which keep the priority; providers merge, nothing of ia is replaced.
10
- # URL: cluster DNS in the Kubernetes workspace pod, the relay of the container
11
- # (127.0.0.1:LLM_PORT) elsewhere. bash 3.2 (macOS).
12
- set -euo pipefail
13
-
14
- FILE="$HOME/.config/opencode/config.json"
15
-
16
- base_url() {
17
- if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
18
- echo "http://llm.devzone-llm.svc.cluster.local:8080/v1"
19
- else
20
- echo "http://127.0.0.1:${LLM_PORT:-8089}/v1"
21
- fi
22
- }
23
-
24
- # jq program $1 applied to the file (or {}), written back atomically
25
- rewrite() {
26
- local current="{}" out
27
- [ ! -f "$FILE" ] || current="$(cat "$FILE")"
28
- mkdir -p "$(dirname "$FILE")"
29
- out="$(printf '%s' "$current" | jq --arg url "$(base_url)" "$1")" || {
30
- echo "devzone: llm: $FILE is not valid JSON: provider not touched" >&2
31
- return 1
32
- }
33
- # Nothing left but the schema: the file was ours, it goes
34
- if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ] && [ "$1" != "$SET" ]; then
35
- rm -f "$FILE"
36
- else
37
- printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
38
- fi
39
- }
40
-
41
- # shellcheck disable=SC2016 # jq programs, $url is a jq variable
42
- SET='."$schema" = (."$schema" // "https://opencode.ai/config.json")
43
- | .provider["devzone-llm"] = {npm: "@ai-sdk/openai-compatible", name: "devzone local model",
44
- options: {baseURL: $url}, models: {local: {name: "Local code model"}}}'
45
- # shellcheck disable=SC2016
46
- UNSET='if .provider then del(.provider["devzone-llm"]) | (if .provider == {} then del(.provider) else . end) else . end'
47
-
48
- case "${1:-}" in
49
- set) rewrite "$SET" ;;
50
- unset) [ ! -f "$FILE" ] || rewrite "$UNSET" ;;
51
- url) base_url ;;
52
- *)
53
- echo "usage: opencode.sh set|unset|url" >&2
54
- exit 1
55
- ;;
56
- esac