devzone 0.50.5 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,62 @@
1
1
  #!/usr/bin/env bash
2
2
  # Local model in the rotation of devzone agent (#586), sourced by agent.sh.
3
- # The model devzone-llm/local comes after every online model (never first, never
4
- # when the module llm is off or the server does not answer /health): it is used
5
- # when the online ones are all set aside (quota, network). Its internal name has
6
- # no slash (a file ecart-<name> is written for it); opencode gets the reference.
3
+ # The local slot is first the host model (Ollama answers /api/tags with at
4
+ # least one model, reference devzone-host/<model>), otherwise the llm module's
5
+ # local model (devzone-llm/local, cluster / relay /health). It always comes
6
+ # after every online model; its internal name has no slash (an ecart-<name>
7
+ # file is written for it); opencode gets the reference.
7
8
  LOCAL_NOM=devzone-llm-local
9
+ # Real host model name (Ollama) chosen for this attempt, empty otherwise.
10
+ LOCAL_HOTE_REEL=""
11
+ # Internal (slash-free) name of the host model chosen for this attempt.
12
+ LOCAL_HOTE_INTERNE=""
8
13
 
9
- # Prints LOCAL_NOM when the module is on (in the pod: the cluster answers) and
10
- # the server answers /health
11
- local_pret() {
12
- local url
14
+ # shellcheck source=SCRIPTDIR/ia/host-models.sh
15
+ # shellcheck disable=SC1091
16
+ . "$ICI/ia/host-models.sh"
17
+
18
+ # Sanitizes a model name into an internal name: every character outside
19
+ # [A-Za-z0-9._-] becomes '_'. Used for ecart-<name> files, the journal and
20
+ # the rotation, so a host model such as hf.co/org/model:tag never creates a
21
+ # nested or invalid path.
22
+ nom_interne() {
23
+ printf '%s' "$1" | sed 's/[^A-Za-z0-9._-]/_/g'
24
+ }
25
+
26
+ # Sets LOCAL_MODELE for this attempt, read by modele_au_rang and
27
+ # modeles_total. Also records the real host model name when the host is chosen.
28
+ local_charge() {
29
+ local nom url
30
+ LOCAL_HOTE_REEL=""
31
+ LOCAL_HOTE_INTERNE=""
32
+ nom="$(premier 2>/dev/null || true)"
33
+ if [ -n "$nom" ]; then
34
+ LOCAL_HOTE_REEL="$nom"
35
+ LOCAL_HOTE_INTERNE="$(nom_interne "$nom")"
36
+ LOCAL_MODELE="$LOCAL_HOTE_INTERNE"
37
+ return 0
38
+ fi
39
+ # Fallback: the llm module local model (cluster / relay).
40
+ LOCAL_MODELE=""
13
41
  if [ "${DEVZONE_WORKSPACE:-}" != kubernetes ]; then
14
42
  bash "$ICI/devzone" is-enabled llm >/dev/null 2>&1 || return 0
15
43
  fi
16
44
  url="$(bash "$ICI/llm/opencode.sh" url)" || return 0
17
- curl -fsS --max-time 3 "${url%/v1}/health" >/dev/null 2>&1 && echo "$LOCAL_NOM"
45
+ if curl -fsS --max-time 3 "${url%/v1}/health" >/dev/null 2>&1; then
46
+ LOCAL_MODELE="$LOCAL_NOM"
47
+ fi
18
48
  return 0
19
49
  }
20
50
 
21
- # Sets LOCAL_MODELE for this attempt (local_pret), read by modele_au_rang and
22
- # modeles_total
23
- local_charge() {
24
- LOCAL_MODELE="$(local_pret)"
25
- }
26
-
27
51
  # Model reference given to opencode -m
28
52
  modele_ref() {
29
- if [ "$1" = "$LOCAL_NOM" ]; then echo devzone-llm/local; else echo "opencode/$1"; fi
53
+ if [ "$1" = "$LOCAL_NOM" ]; then echo devzone-llm/local;
54
+ elif [ -n "$LOCAL_HOTE_INTERNE" ] && [ "$1" = "$LOCAL_HOTE_INTERNE" ]; then echo "devzone-host/$LOCAL_HOTE_REEL";
55
+ else echo "opencode/$1"; fi
30
56
  }
31
57
 
32
58
  # Model of rank $1 in the attempt that starts at $2: online ones in rotation,
33
- # then the local one
59
+ # then the local one (host or llm module)
34
60
  modele_au_rang() {
35
61
  if [ "$1" -lt "${#FREE_MODELS[@]}" ]; then
36
62
  echo "${FREE_MODELS[$(( ($2 + $1) % ${#FREE_MODELS[@]} ))]}"
@@ -41,5 +67,7 @@ modele_au_rang() {
41
67
 
42
68
  # Number of models to try: the online ones, plus the local one if ready
43
69
  modeles_total() {
44
- echo $(( ${#FREE_MODELS[@]} + ${#LOCAL_MODELE} / ${#LOCAL_NOM} ))
70
+ local total="${#FREE_MODELS[@]}"
71
+ [ -n "$LOCAL_MODELE" ] && total=$((total + 1))
72
+ echo "$total"
45
73
  }
@@ -16,6 +16,7 @@ command_canonical() {
16
16
  is-enabled) echo actif ;;
17
17
  enable) echo activer ;;
18
18
  disable) echo desactiver ;;
19
+ ai) echo ia ;;
19
20
  help) echo aide ;;
20
21
  apply) echo appliquer ;;
21
22
  catalog) echo catalogue ;;
@@ -45,6 +46,7 @@ command_english() {
45
46
  actif) echo is-enabled ;;
46
47
  activer) echo enable ;;
47
48
  desactiver) echo disable ;;
49
+ ia) echo ai ;;
48
50
  aide) echo help ;;
49
51
  appliquer) echo apply ;;
50
52
  catalogue) echo catalog ;;
@@ -50,13 +50,17 @@ fi
50
50
  # shellcheck source=SCRIPTDIR/etat-gitops.sh
51
51
  # shellcheck disable=SC1091
52
52
  . "$ICI/etat-gitops.sh"
53
+ # Detection of the host (Ollama) models and the devzone-host opencode provider (#665).
54
+ # shellcheck source=SCRIPTDIR/ia/host-models.sh
55
+ # shellcheck disable=SC1091
56
+ . "$ICI/ia/host-models.sh"
53
57
 
54
58
  # Assistants IA, versions figées : mettre à jour ici, puis devzone apply
55
59
  # (ou Rebuild Container). Une ligne par paquet, séparées par une ligne qui ne
56
60
  # change pas : deux montées simultanées (workflow versions) se fusionnent sans
57
61
  # conflit, git n'en signalant qu'entre lignes voisines modifiées.
58
62
  # Claude Code
59
- IA_CLAUDE=@anthropic-ai/claude-code@2.1.327
63
+ IA_CLAUDE=@anthropic-ai/claude-code@2.1.328
60
64
  # opencode
61
65
  IA_OPENCODE=opencode-ai@1.19.6
62
66
  IA_PAQUETS=("$IA_CLAUDE" "$IA_OPENCODE")
@@ -397,7 +401,7 @@ installer_ia() {
397
401
  }
398
402
 
399
403
  appliquer_ia() {
400
- local journal tmp
404
+ local journal tmp detectes
401
405
  if [ "$1" = on ]; then
402
406
  echo "devzone : installation de Claude Code et opencode (quelques minutes)…"
403
407
  if ! installer_ia; then
@@ -418,6 +422,16 @@ appliquer_ia() {
418
422
  echo "devzone : garde-fou repowarden non branché (repowarden 4.10 ou plus requis) : repowarden agents init --global" >&2
419
423
  fi
420
424
  config_opencode
425
+ # Provider opencode des modèles de l'hôte (Ollama), détection à chaud :
426
+ # silencieux et sans effet si Ollama ne répond pas.
427
+ set_provider || true
428
+ # Signale l'état de la détection (succès dans les deux cas).
429
+ detectes="$(modeles 2>/dev/null || true)"
430
+ if [ -n "$detectes" ]; then
431
+ printf "devzone : %s modèle(s) de l'hôte (Ollama) branché(s)\n" "$(printf '%s\n' "$detectes" | grep -c .)"
432
+ else
433
+ printf "devzone : aucun modèle Ollama détecté sur %s (modèles de l'hôte non branchés)\n" "$URL"
434
+ fi
421
435
  # Skill devzone : posée si absente, mise à jour si inchangée, gardée si personnalisée.
422
436
  poser_skill_devzone
423
437
  echo "devzone : ia actif : claude (puis /login), opencode auth login"
@@ -460,6 +474,8 @@ appliquer_ia() {
460
474
  # Configuration opencode : retirée seulement si elle porte le repère devzone
461
475
  # et n'a pas été modifiée ; personnalisée → gardée.
462
476
  retirer_config_opencode
477
+ # Retire le fournisseur opencode des modèles de l'hôte, garde le reste du fichier.
478
+ unset_provider || true
463
479
  # Skill devzone : retirée seulement si non modifiée ; personnalisée → gardée.
464
480
  retirer_skill_devzone
465
481
  # État de devzone agent : gardé dans le volume partagé (désactivation
@@ -1441,6 +1457,20 @@ case "${1:-}" in
1441
1457
  agent)
1442
1458
  bash "$ICI/agent.sh" "${@:2}"
1443
1459
  ;;
1460
+ ia)
1461
+ # Read-only: lists the host (Ollama) models detected and the default model.
1462
+ liste="$(modeles)"
1463
+ def="$(premier)"
1464
+ if [ -z "$liste" ]; then
1465
+ echo "devzone : aucun modèle Ollama détecté sur ${URL} (répondez sur /api/tags)"
1466
+ else
1467
+ echo "devzone : modèles détectés sur l'hôte (Ollama) :"
1468
+ while IFS= read -r m; do
1469
+ [ -n "$m" ] && printf ' %s\n' "$m"
1470
+ done <<<"$liste"
1471
+ echo "modèle par défaut : ${def:-aucun}"
1472
+ fi
1473
+ ;;
1444
1474
  ticket) bash "$ICI/ticket.sh" "${@:2}" ;;
1445
1475
  build)
1446
1476
  bash "$ICI/workspace-build.sh" "${@:2}"
@@ -21,6 +21,7 @@ devzone_aide() {
21
21
  devzone test-bash32 run the bats tests under bash 3.2 (Docker container)
22
22
  devzone test-gitlab end-to-end test of the GitLab module and platform
23
23
  devzone agent <folder> <instructions> drive opencode with the instructions file
24
+ devzone ai | ia list the host (Ollama) models detected and the default model
24
25
  devzone ticket <n> [--repo devzone|repowarden] ticket worktree (ticket done <n> removes it)
25
26
  devzone build <folder> [--tag <name>] build an image in the Kubernetes workspace (BuildKit)
26
27
  devzone enable postgres [--context CTX] [--confirm CTX] shared PostgreSQL, cluster of choice
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env bash
2
+ # Detection of the models served by Ollama on the host (#665).
3
+ # devzone hosts no model: models live on the host (Ollama) and are detected here.
4
+ # host-models.sh list the detected model names, one per line
5
+ # host-models.sh first the model to use (DEVZONE_HOST_MODEL or first detected)
6
+ # host-models.sh set merge the devzone-host provider into ~/.config/opencode/config.json
7
+ # host-models.sh unset remove the devzone-host provider from that file
8
+ # Default URL: http://host.docker.internal:11434, overridable with DEVZONE_OLLAMA_URL.
9
+ # Short timeout; exits 0 and writes nothing when Ollama does not answer.
10
+ # bash 3.2 (macOS). Code and comments in English.
11
+ set -euo pipefail
12
+
13
+ URL="${DEVZONE_OLLAMA_URL:-http://host.docker.internal:11434}"
14
+ URL="${URL%/}"
15
+ FILE="$HOME/.config/opencode/config.json"
16
+
17
+ # True when a model is an embedding model (Ollama details.type, or a name
18
+ # containing "embed", case-insensitive).
19
+ is_embedding() {
20
+ local low
21
+ low="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
22
+ case "$low" in
23
+ *embed*) return 0 ;;
24
+ *) return 1 ;;
25
+ esac
26
+ }
27
+
28
+ # Prints the detected model names, one per line. Exits 0 and prints nothing
29
+ # when Ollama does not answer or the payload is not usable.
30
+ modeles() {
31
+ local data
32
+ data="$(curl -fsS --max-time 3 "${URL}/api/tags" 2>/dev/null)" || return 0
33
+ [ -n "$data" ] || return 0
34
+ # Ignore embedding models (Ollama details.type, or a name containing "embed").
35
+ printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | .name' 2>/dev/null |
36
+ while IFS= read -r name; do
37
+ is_embedding "$name" || printf '%s\n' "$name"
38
+ done || true
39
+ return 0
40
+ }
41
+
42
+ # The model to use: DEVZONE_HOST_MODEL when set, else the first detected.
43
+ # Empty when Ollama did not answer or no model was detected.
44
+ premier() {
45
+ local liste nom="${DEVZONE_HOST_MODEL:-}"
46
+ liste="$(modeles)" || true
47
+ [ -n "$liste" ] || return 0
48
+ if [ -n "$nom" ]; then
49
+ printf '%s\n' "$nom"
50
+ else
51
+ printf '%s\n' "${liste%%$'\n'*}"
52
+ fi
53
+ return 0
54
+ }
55
+
56
+ # jq program $1 applied to the file (or {}), written back atomically.
57
+ # The file is removed when nothing remains but the schema.
58
+ rewrite() {
59
+ local current="{}" out
60
+ [ ! -f "$FILE" ] || current="$(cat "$FILE")"
61
+ mkdir -p "$(dirname "$FILE")"
62
+ out="$(printf '%s' "$current" | jq "$1")" || {
63
+ echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
64
+ return 1
65
+ }
66
+ if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
67
+ rm -f "$FILE"
68
+ else
69
+ printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
70
+ fi
71
+ }
72
+
73
+ # Merges the devzone-host provider (the detected models) into the opencode
74
+ # configuration file, keeping everything else. Does nothing when no model was
75
+ # detected. baseURL = URL + /v1.
76
+ set_provider() {
77
+ local liste current="{}" out models baseurl
78
+ liste="$(modeles)" || return 0
79
+ [ -n "$liste" ] || return 0
80
+ baseurl="${URL%/}/v1"
81
+ models="$(printf '%s\n' "$liste" | jq -R -n '([inputs | select(length > 0)] | map({(.): {name: .}})) | add // {}')" || return 1
82
+ [ ! -f "$FILE" ] || current="$(cat "$FILE")"
83
+ mkdir -p "$(dirname "$FILE")"
84
+ out="$(printf '%s' "$current" | jq --arg baseurl "$baseurl" --argjson models "$models" '
85
+ ."$schema" = (."$schema" // "https://opencode.ai/config.json")
86
+ | .provider["devzone-host"] = {npm: "@ai-sdk/openai-compatible", name: "devzone host models (Ollama)", options: {baseURL: $baseurl}, models: $models}
87
+ ')" || {
88
+ echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
89
+ return 1
90
+ }
91
+ if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
92
+ rm -f "$FILE"
93
+ else
94
+ printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
95
+ fi
96
+ }
97
+
98
+ # Removes the devzone-host provider from the opencode configuration file,
99
+ # keeping everything else. No error when the file is absent.
100
+ unset_provider() {
101
+ [ ! -f "$FILE" ] && return 0
102
+ rewrite 'if .provider then del(.provider["devzone-host"]) | (if .provider == {} then del(.provider) else . end) else . end'
103
+ }
104
+
105
+ # When run directly (not sourced): dispatch the subcommands.
106
+ if [ "${0##*/}" = "host-models.sh" ]; then
107
+ case "${1:-}" in
108
+ first) premier ;;
109
+ set) set_provider ;;
110
+ unset) unset_provider ;;
111
+ *) modeles ;;
112
+ esac
113
+ fi
package/manage/devzone CHANGED
@@ -582,10 +582,10 @@ commande_du_conteneur() {
582
582
  case "$1" in
583
583
  actif | activer | agent | appliquer | argocd | build | catalogue | cluster | clusters | \
584
584
  demarrer | desactiver | etat | gitlab | metrics | modules | mots-de-passe | \
585
- llm | mysql | paquets | plateforme | port | postgres | reparer | test-bash32 | \
585
+ ia | llm | mysql | paquets | plateforme | port | postgres | reparer | test-bash32 | \
586
586
  test-gitlab | ticket | utiliser) return 0 ;;
587
587
  # English names of the container commands (#502)
588
- is-enabled | enable | disable | apply | catalog | start | status | \
588
+ ai | is-enabled | enable | disable | apply | catalog | start | status | \
589
589
  passwords | packages | platform | repair | use) return 0 ;;
590
590
  *) return 1 ;;
591
591
  esac
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "0.50.5",
3
+ "version": "0.51.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": {