devzone 4.3.0 → 6.0.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/Dockerfile +1 -1
- package/.devcontainer/agent-errors.sh +13 -13
- package/.devcontainer/agent-local.sh +18 -18
- package/.devcontainer/agent-model.messages +7 -7
- package/.devcontainer/agent-model.sh +46 -46
- package/.devcontainer/agent-pod-manifest.sh +1 -1
- package/.devcontainer/agent-pod.sh +7 -7
- package/.devcontainer/agent-rights.sh +31 -31
- package/.devcontainer/agent-session.sh +22 -22
- package/.devcontainer/agent-state-json.sh +21 -21
- package/.devcontainer/agent-workspace.sh +8 -8
- package/.devcontainer/agent.sh +30 -30
- package/.devcontainer/ai/host-check.sh +2 -2
- package/.devcontainer/ai/host-models.sh +4 -4
- package/.devcontainer/ai/plugins/devzone-guard-v2.js +1 -1
- package/.devcontainer/ai/plugins/devzone-guard.js +1 -1
- package/.devcontainer/catalog/mysql/app.conf +1 -1
- package/.devcontainer/cluster.sh +1 -1
- package/.devcontainer/command-aliases.sh +34 -4
- package/.devcontainer/devzone +2 -2
- package/.devcontainer/devzone-ai.sh +4 -4
- package/.devcontainer/devzone-modules.sh +1 -1
- package/.devcontainer/devzone-skill.sh +1 -1
- package/.devcontainer/opencode.jsonc +1 -1
- package/.devcontainer/packages.sh +1 -1
- package/.devcontainer/post-create.sh +2 -0
- package/.devcontainer/rename-legacy-files.sh +71 -14
- package/.devcontainer/skills/devzone/SKILL.md +7 -7
- package/.devcontainer/state-json.sh +1 -1
- package/.devcontainer/state.sh +6 -6
- package/.devcontainer/workspace-init.sh +1 -1
- package/README.md +6 -6
- 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 +17 -11
- package/manage/scripts/devzone-update.sh +4 -4
- package/manage/scripts/workspace/ports-apps.sh +1 -1
- package/manage/scripts/workspace/ports-workspace.sh +15 -15
- package/manage/scripts/workspace/workspace-clone.sh +2 -2
- package/package.json +1 -1
package/.devcontainer/Dockerfile
CHANGED
|
@@ -35,7 +35,7 @@ ARG GO_SHA256_ARM64=3392582988a273a87ab5043ee1b2c9c17a2c3c00580bf9326c47a2e0aaae
|
|
|
35
35
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
|
36
36
|
|
|
37
37
|
# Contrôles shell de repowarden ; jq : lu par son garde-fou des agents IA
|
|
38
|
-
# (repowarden guard, module
|
|
38
|
+
# (repowarden guard, module ai), qui sans lui ne vérifie rien
|
|
39
39
|
# Python 3.12 d Ubuntu 24.04, paquets signés par apt, aucun serveur de clés (#464)
|
|
40
40
|
RUN apt-get -o Acquire::Retries=5 update \
|
|
41
41
|
&& apt-get -o Acquire::Retries=5 install -y --no-install-recommends shellcheck bats jq python3 python3-venv python3-pip python-is-python3 \
|
|
@@ -10,7 +10,7 @@ ERROR_LINE='(^|[[:space:]])(Error|ERROR|Erreur):'
|
|
|
10
10
|
|
|
11
11
|
# Cause of a failure: pays (country, lasting), quota, filtre (filter), reseau
|
|
12
12
|
# (network, no exclusion) or autre (other). The stored names stay as they are:
|
|
13
|
-
# they are written to the state files and to devzone agent
|
|
13
|
+
# they are written to the state files and to devzone agent state --json.
|
|
14
14
|
error_cause() {
|
|
15
15
|
local t="$1"
|
|
16
16
|
case "$t" in
|
|
@@ -56,18 +56,18 @@ exclusion_label() {
|
|
|
56
56
|
fi
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
# Writes the exclusion of the model: "<start> <cause> <duration>" in $
|
|
59
|
+
# Writes the exclusion of the model: "<start> <cause> <duration>" in $AGENT_STATE/ecart-<model>
|
|
60
60
|
# (the state file keeps its name on disk).
|
|
61
61
|
model_exclude() {
|
|
62
|
-
printf '%s %s %s\n' "$(date +%s)" "$2" "$(exclusion_duration "$2")" >"$
|
|
62
|
+
printf '%s %s %s\n' "$(date +%s)" "$2" "$(exclusion_duration "$2")" >"$AGENT_STATE/ecart-$1"
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
# True (0) when the model is excluded right now. Also reads the old muet-<model>
|
|
66
66
|
# format (timestamp only, 1 h).
|
|
67
67
|
model_excluded() {
|
|
68
68
|
local f e cause d
|
|
69
|
-
f="$
|
|
70
|
-
if [ ! -f "$f" ]; then f="$
|
|
69
|
+
f="$AGENT_STATE/ecart-$1"
|
|
70
|
+
if [ ! -f "$f" ]; then f="$AGENT_STATE/muet-$1"; fi
|
|
71
71
|
if [ ! -f "$f" ]; then return 1; fi
|
|
72
72
|
read -r e cause d <<<"$(cat "$f")"
|
|
73
73
|
[ "$(date +%s)" -lt $(( e + ${d:-3600} )) ]
|
|
@@ -94,11 +94,11 @@ network_wait() {
|
|
|
94
94
|
return 1
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
# Lists the current exclusions for devzone agent
|
|
97
|
+
# Lists the current exclusions for devzone agent state (muet- too, without cause).
|
|
98
98
|
agent_exclusions() {
|
|
99
99
|
local f m e cause d end now
|
|
100
100
|
now="$(date +%s)"
|
|
101
|
-
for f in "$
|
|
101
|
+
for f in "$AGENT_STATE"/ecart-*; do
|
|
102
102
|
[ -e "$f" ] || continue
|
|
103
103
|
m="${f##*/ecart-}"
|
|
104
104
|
read -r e cause d <<<"$(cat "$f")"
|
|
@@ -106,7 +106,7 @@ agent_exclusions() {
|
|
|
106
106
|
[ "$now" -lt "$end" ] || continue
|
|
107
107
|
echo " model $m excluded ($(cause_label "$cause")) until $(utc_time "$end")"
|
|
108
108
|
done
|
|
109
|
-
for f in "$
|
|
109
|
+
for f in "$AGENT_STATE"/muet-*; do
|
|
110
110
|
[ -e "$f" ] || continue
|
|
111
111
|
m="${f##*/muet-}"
|
|
112
112
|
e="$(cat "$f" 2>/dev/null || true)"
|
|
@@ -117,11 +117,11 @@ agent_exclusions() {
|
|
|
117
117
|
done
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
# Lifts the exclusion of a model, or of all (--
|
|
120
|
+
# Lifts the exclusion of a model, or of all (--all): devzone agent release.
|
|
121
121
|
exclusion_clear() {
|
|
122
122
|
case "$1" in
|
|
123
|
-
--
|
|
124
|
-
*) rm -f "$
|
|
123
|
+
--all) rm -f "$AGENT_STATE"/ecart-* "$AGENT_STATE"/muet-* ;;
|
|
124
|
+
*) rm -f "$AGENT_STATE/ecart-$1" "$AGENT_STATE/muet-$1" ;;
|
|
125
125
|
esac
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -146,9 +146,9 @@ session_fatal_error() {
|
|
|
146
146
|
pkill -P "$pid" 2>/dev/null || true
|
|
147
147
|
kill "$pid" 2>/dev/null || true
|
|
148
148
|
wait "$pid" 2>/dev/null || true
|
|
149
|
-
|
|
149
|
+
rights_verify "$folder"
|
|
150
150
|
model_exclude "$m" "$cause"
|
|
151
|
-
|
|
151
|
+
model_requested_excluded "$m" "$cause" "$journal"
|
|
152
152
|
printf '%s\n' "=== opencode/$m excluded ($(cause_label "$cause")): next model" >>"$journal"
|
|
153
153
|
return 0
|
|
154
154
|
}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
# model; its internal name has no slash (an ecart-<name> file is written for it);
|
|
6
6
|
# opencode gets the reference.
|
|
7
7
|
# Real host model name (Ollama) chosen for this attempt, empty otherwise.
|
|
8
|
-
|
|
8
|
+
LOCAL_HOST_REAL=""
|
|
9
9
|
# Internal (slash-free) name of the host model chosen for this attempt.
|
|
10
|
-
|
|
10
|
+
LOCAL_HOST_INTERNAL=""
|
|
11
11
|
|
|
12
12
|
# shellcheck source=SCRIPTDIR/ai/host-models.sh
|
|
13
13
|
# shellcheck disable=SC1091
|
|
@@ -17,29 +17,29 @@ LOCAL_HOTE_INTERNE=""
|
|
|
17
17
|
# [A-Za-z0-9._-] becomes '_'. Used for ecart-<name> files, the journal and
|
|
18
18
|
# the rotation, so a host model such as hf.co/org/model:tag never creates a
|
|
19
19
|
# nested or invalid path.
|
|
20
|
-
|
|
20
|
+
internal_name() {
|
|
21
21
|
printf '%s' "$1" | sed 's/[^A-Za-z0-9._-]/_/g'
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
# Sets
|
|
25
|
-
#
|
|
24
|
+
# Sets LOCAL_MODEL for this attempt, read by model_at_rank and
|
|
25
|
+
# models_total. Also records the real host model name when the host is chosen.
|
|
26
26
|
local_charge() {
|
|
27
27
|
local nom
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
LOCAL_MODEL=""
|
|
29
|
+
LOCAL_HOST_REAL=""
|
|
30
|
+
LOCAL_HOST_INTERNAL=""
|
|
31
31
|
nom="$(premier 2>/dev/null || true)"
|
|
32
32
|
[ -n "$nom" ] || return 0
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
LOCAL_HOST_REAL="$nom"
|
|
34
|
+
LOCAL_HOST_INTERNAL="$(internal_name "$nom")"
|
|
35
|
+
LOCAL_MODEL="$LOCAL_HOST_INTERNAL"
|
|
36
36
|
return 0
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
# Model reference given to opencode -m
|
|
40
|
-
|
|
41
|
-
if [ -n "$
|
|
42
|
-
echo "devzone-host/$
|
|
40
|
+
model_ref() {
|
|
41
|
+
if [ -n "$LOCAL_HOST_INTERNAL" ] && [ "$1" = "$LOCAL_HOST_INTERNAL" ]; then
|
|
42
|
+
echo "devzone-host/$LOCAL_HOST_REAL"
|
|
43
43
|
else
|
|
44
44
|
echo "opencode/$1"
|
|
45
45
|
fi
|
|
@@ -47,17 +47,17 @@ modele_ref() {
|
|
|
47
47
|
|
|
48
48
|
# Model of rank $1 in the attempt that starts at $2: online ones in rotation,
|
|
49
49
|
# then the local host model
|
|
50
|
-
|
|
50
|
+
model_at_rank() {
|
|
51
51
|
if [ "$1" -lt "${#FREE_MODELS[@]}" ]; then
|
|
52
52
|
echo "${FREE_MODELS[$(( ($2 + $1) % ${#FREE_MODELS[@]} ))]}"
|
|
53
53
|
else
|
|
54
|
-
echo "$
|
|
54
|
+
echo "$LOCAL_MODEL"
|
|
55
55
|
fi
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
# Number of models to try: the online ones, plus the local host model if ready
|
|
59
|
-
|
|
59
|
+
models_total() {
|
|
60
60
|
local total="${#FREE_MODELS[@]}"
|
|
61
|
-
[ -n "$
|
|
61
|
+
[ -n "$LOCAL_MODEL" ] && total=$((total + 1))
|
|
62
62
|
echo "$total"
|
|
63
63
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# Messages of devzone agent --
|
|
2
|
-
# Sourced by agent-model.sh.
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
# Messages of devzone agent --model (#420), in English like the journal they go to.
|
|
2
|
+
# Sourced by agent-model.sh. Each %s is replaced by a model name or a cause
|
|
3
|
+
# (printf formats).
|
|
4
|
+
MSG_NO_MODEL='no free model available'
|
|
5
|
+
MSG_CHOSEN='=== requested model chosen: %s'
|
|
6
|
+
MSG_EXCLUDED='=== requested model %s excluded (%s), next'
|
|
7
|
+
MSG_UNKNOWN='devzone agent: unknown model: %s ; free models:'
|
|
@@ -1,113 +1,113 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Models asked with devzone agent --
|
|
2
|
+
# Models asked with devzone agent --model (#420): list check, attempt order
|
|
3
3
|
# (requested models first, then the usual rotation) and the shared rank rule.
|
|
4
4
|
# Library sourced by agent.sh: no command is launched here.
|
|
5
5
|
|
|
6
|
-
# Journal and refusal texts
|
|
6
|
+
# Journal and refusal texts, printf formats.
|
|
7
7
|
# shellcheck source=SCRIPTDIR/agent-model.messages disable=SC1091
|
|
8
8
|
. "$ICI/agent-model.messages"
|
|
9
9
|
|
|
10
|
-
# Option --
|
|
11
|
-
|
|
12
|
-
# Requested models, in order, checked by
|
|
13
|
-
|
|
14
|
-
# Attempt order of the session (internal names), set by
|
|
15
|
-
|
|
10
|
+
# Option --model as typed (comma-separated list), empty when absent.
|
|
11
|
+
MODEL_LIST=""
|
|
12
|
+
# Requested models, in order, checked by models_load.
|
|
13
|
+
MODELS_REQUESTED=()
|
|
14
|
+
# Attempt order of the session (internal names), set by model_order.
|
|
15
|
+
ORDER=()
|
|
16
16
|
|
|
17
17
|
# Refuses a name missing from the free models: nothing is launched (code 2).
|
|
18
|
-
|
|
18
|
+
refuse_model() {
|
|
19
19
|
# shellcheck disable=SC2059 # the format comes from agent-model.messages
|
|
20
|
-
printf "$
|
|
20
|
+
printf "$MSG_UNKNOWN\n" "$1" >&2
|
|
21
21
|
printf ' %s\n' "${FREE_MODELS[@]}" >&2
|
|
22
22
|
exit 2
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
# Loads the free models, checks the --
|
|
26
|
-
# journal $1: the last header tells devzone agent
|
|
27
|
-
|
|
25
|
+
# Loads the free models, checks the --model list and writes its header to the
|
|
26
|
+
# journal $1: the last header tells devzone agent state what was asked.
|
|
27
|
+
models_load() {
|
|
28
28
|
local journal="$1" m nom
|
|
29
29
|
FREE_MODELS=()
|
|
30
30
|
while IFS= read -r m; do
|
|
31
31
|
if [ -n "$m" ]; then FREE_MODELS+=("$m"); fi
|
|
32
32
|
done < <(list_models)
|
|
33
|
-
[ "${#FREE_MODELS[@]}" -gt 0 ] || refuse "$
|
|
34
|
-
|
|
35
|
-
if [ -n "$
|
|
33
|
+
[ "${#FREE_MODELS[@]}" -gt 0 ] || refuse "$MSG_NO_MODEL"
|
|
34
|
+
MODELS_REQUESTED=()
|
|
35
|
+
if [ -n "$MODEL_LIST" ]; then
|
|
36
36
|
while IFS= read -r nom; do
|
|
37
37
|
case " ${FREE_MODELS[*]} " in
|
|
38
|
-
*" $nom "*)
|
|
39
|
-
*)
|
|
38
|
+
*" $nom "*) MODELS_REQUESTED+=("$nom") ;;
|
|
39
|
+
*) refuse_model "$nom" ;;
|
|
40
40
|
esac
|
|
41
|
-
done < <(printf '%s\n' "$
|
|
41
|
+
done < <(printf '%s\n' "$MODEL_LIST" | tr ',' '\n')
|
|
42
42
|
fi
|
|
43
|
-
echo "=== --
|
|
43
|
+
echo "=== --model : ${MODEL_LIST:-none}" >>"$journal"
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
# True when model $1 was asked with --
|
|
47
|
-
|
|
48
|
-
case " ${
|
|
46
|
+
# True when model $1 was asked with --model.
|
|
47
|
+
model_requested_p() {
|
|
48
|
+
case " ${MODELS_REQUESTED[*]:-} " in
|
|
49
49
|
*" $1 "*) return 0 ;;
|
|
50
50
|
esac
|
|
51
51
|
return 1
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
# Journal line when requested model $1 starts; other models get no line.
|
|
55
|
-
|
|
56
|
-
if
|
|
55
|
+
model_requested_chosen() {
|
|
56
|
+
if model_requested_p "$1"; then
|
|
57
57
|
# shellcheck disable=SC2059 # the format comes from agent-model.messages
|
|
58
|
-
printf "$
|
|
58
|
+
printf "$MSG_CHOSEN\n" "$1" >>"$2"
|
|
59
59
|
fi
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
# Journal line when requested model $1 is excluded for cause $2, written to the
|
|
63
63
|
# journal $3. Other models keep their own lines.
|
|
64
|
-
|
|
65
|
-
if
|
|
64
|
+
model_requested_excluded() {
|
|
65
|
+
if model_requested_p "$1"; then
|
|
66
66
|
# shellcheck disable=SC2059 # the format comes from agent-model.messages
|
|
67
|
-
printf "$
|
|
67
|
+
printf "$MSG_EXCLUDED\n" "$1" "$2" >>"$3"
|
|
68
68
|
fi
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
# Cause of the current exclusion of model $1: ecart-<model> gives it, muet-<model>
|
|
72
72
|
# has none and counts as muet.
|
|
73
|
-
|
|
73
|
+
model_exclusion_cause() {
|
|
74
74
|
local f cause=""
|
|
75
|
-
f="$
|
|
76
|
-
if [ ! -f "$f" ]; then f="$
|
|
75
|
+
f="$AGENT_STATE/ecart-$1"
|
|
76
|
+
if [ ! -f "$f" ]; then f="$AGENT_STATE/muet-$1"; fi
|
|
77
77
|
if [ -f "$f" ]; then read -r _ cause _ <"$f" || true; fi
|
|
78
78
|
echo "${cause:-muet}"
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
# Adds model $1 to
|
|
82
|
-
|
|
83
|
-
case " ${
|
|
81
|
+
# Adds model $1 to ORDER unless it is already there.
|
|
82
|
+
order_add() {
|
|
83
|
+
case " ${ORDER[*]:-} " in
|
|
84
84
|
*" $1 "*) ;;
|
|
85
|
-
*)
|
|
85
|
+
*) ORDER+=("$1") ;;
|
|
86
86
|
esac
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
# Attempt order of the session from rank $1: requested models in their order,
|
|
90
90
|
# then the usual rotation (online models, then the local one). Each model
|
|
91
91
|
# appears once, so the rotation never tries again a requested model.
|
|
92
|
-
|
|
93
|
-
local
|
|
94
|
-
|
|
95
|
-
for ((k = 0; k < ${#
|
|
96
|
-
|
|
92
|
+
model_order() {
|
|
93
|
+
local start="$1" total i k
|
|
94
|
+
ORDER=()
|
|
95
|
+
for ((k = 0; k < ${#MODELS_REQUESTED[@]}; k++)); do
|
|
96
|
+
order_add "${MODELS_REQUESTED[$k]}"
|
|
97
97
|
done
|
|
98
|
-
total="$(
|
|
98
|
+
total="$(models_total)"
|
|
99
99
|
for ((i = 0; i < total; i++)); do
|
|
100
|
-
|
|
100
|
+
order_add "$(model_at_rank "$i" "$start")"
|
|
101
101
|
done
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
# True when the shared rank may advance: no requested model is available.
|
|
105
105
|
# A requested model that starts leaves the rank alone, so the rotation of the
|
|
106
106
|
# other sessions does not move.
|
|
107
|
-
|
|
107
|
+
model_rank_advance() {
|
|
108
108
|
local k
|
|
109
|
-
for ((k = 0; k < ${#
|
|
110
|
-
if ! model_excluded "${
|
|
109
|
+
for ((k = 0; k < ${#MODELS_REQUESTED[@]}; k++)); do
|
|
110
|
+
if ! model_excluded "${MODELS_REQUESTED[$k]}"; then return 1; fi
|
|
111
111
|
done
|
|
112
112
|
return 0
|
|
113
113
|
}
|
|
@@ -136,7 +136,7 @@ agent_pod_validate_folder() {
|
|
|
136
136
|
# --- Build the session pod manifest ---
|
|
137
137
|
|
|
138
138
|
agent_pod_build_manifest() {
|
|
139
|
-
# $2 (the
|
|
139
|
+
# $2 (the brief) is never written here: it only goes to the ConfigMap.
|
|
140
140
|
local folder="$1" pod_name="$3"
|
|
141
141
|
local ws_image ws_path pvc_workspace pvc_etat manifest_file ticket_block=""
|
|
142
142
|
|
|
@@ -158,9 +158,9 @@ agent_pod_set_trap() {
|
|
|
158
158
|
|
|
159
159
|
# --- Launch a session agent in an ephemeral pod (devzone agent --pod) ---
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
agent_pod_launch() {
|
|
162
162
|
local folder_raw="${1:-}" consigne_raw="${2:-}"
|
|
163
|
-
local folder consigne pod_name journal_file phase manifest_file
|
|
163
|
+
local folder consigne pod_name journal_file phase manifest_file state
|
|
164
164
|
local rc=0
|
|
165
165
|
|
|
166
166
|
if [ "${DEVZONE_WORKSPACE:-}" != "kubernetes" ]; then
|
|
@@ -181,7 +181,7 @@ agent_pod_lancer() {
|
|
|
181
181
|
exit 1
|
|
182
182
|
}
|
|
183
183
|
if [ ! -r "${consigne_raw:-}" ]; then
|
|
184
|
-
echo "devzone agent --pod :
|
|
184
|
+
echo "devzone agent --pod : brief not found : ${consigne_raw:-}" >&2
|
|
185
185
|
exit 1
|
|
186
186
|
fi
|
|
187
187
|
consigne="$(cd "$(dirname "$consigne_raw")" && pwd -P)/$(basename "$consigne_raw")"
|
|
@@ -191,14 +191,14 @@ agent_pod_lancer() {
|
|
|
191
191
|
fi
|
|
192
192
|
# The pod mounts this file read-only: refuse before any object is created.
|
|
193
193
|
if [ ! -f "$AGENT_POD_MODULES_FILE" ]; then
|
|
194
|
-
echo "devzone agent --pod : modules file missing : $AGENT_POD_MODULES_FILE (run devzone enable
|
|
194
|
+
echo "devzone agent --pod : modules file missing : $AGENT_POD_MODULES_FILE (run devzone enable ai on the workspace)" >&2
|
|
195
195
|
exit 1
|
|
196
196
|
fi
|
|
197
197
|
|
|
198
198
|
# The log of the session stays in the agent state directory (shared with the pod).
|
|
199
|
-
|
|
200
|
-
mkdir -p "$
|
|
201
|
-
journal_file="$
|
|
199
|
+
state="${AGENT_STATE:-$HOME/.local/state/oc-lancer}"
|
|
200
|
+
mkdir -p "$state"
|
|
201
|
+
journal_file="$state/${AGENT_POD_SESSION_LABEL}.pod.log"
|
|
202
202
|
: >"$journal_file"
|
|
203
203
|
|
|
204
204
|
pod_name="$(agent_pod_name "$folder")"
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
2
|
+
# Protects the rights files of the agents during a devzone agent session (#361).
|
|
3
|
+
# Library sourced by agent.sh: no command is launched here.
|
|
4
4
|
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# agent-rights.sh
|
|
8
|
-
|
|
5
|
+
# Rights files, paths relative to the root of the working folder. Fixed list: no
|
|
6
|
+
# environment variable changes it, and an agent cannot add to it.
|
|
7
|
+
# agent-rights.sh is in it, otherwise an agent could empty the list.
|
|
8
|
+
RIGHTS_FILES=(
|
|
9
9
|
.devcontainer/opencode/agent.json
|
|
10
10
|
.devcontainer/opencode.jsonc
|
|
11
11
|
.repowarden.conf
|
|
12
12
|
.devcontainer/agent-rights.sh
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
echo "$
|
|
15
|
+
# Snapshot directory of a project's rights files, in the agent state.
|
|
16
|
+
rights_dir() {
|
|
17
|
+
echo "$AGENT_STATE/droits-$(basename "$1")"
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
|
|
20
|
+
# At launch: copies each rights file (or notes its absence) and the starting HEAD,
|
|
21
|
+
# then clears the alert of the previous session on this project.
|
|
22
|
+
rights_snapshot() {
|
|
23
23
|
local d f
|
|
24
|
-
d="$(
|
|
24
|
+
d="$(rights_dir "$1")"
|
|
25
25
|
rm -rf "$d" "$d.alerte"
|
|
26
26
|
mkdir -p "$d/fichiers"
|
|
27
27
|
: >"$d/absents"
|
|
28
|
-
for f in "${
|
|
28
|
+
for f in "${RIGHTS_FILES[@]}"; do
|
|
29
29
|
if [ -f "$1/$f" ]; then
|
|
30
30
|
mkdir -p "$d/fichiers/$(dirname "$f")"
|
|
31
31
|
cp -p "$1/$f" "$d/fichiers/$f"
|
|
@@ -36,10 +36,10 @@ droits_photo() {
|
|
|
36
36
|
git -C "$1" rev-parse HEAD >"$d/head" 2>/dev/null || : >"$d/head"
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
#
|
|
40
|
-
|
|
39
|
+
# Restores a rights file to its snapshot (removed when it did not exist).
|
|
40
|
+
rights_restore() {
|
|
41
41
|
local d f
|
|
42
|
-
d="$(
|
|
42
|
+
d="$(rights_dir "$1")"
|
|
43
43
|
f="$2"
|
|
44
44
|
if grep -qxF "$f" "$d/absents"; then
|
|
45
45
|
rm -f "$1/$f"
|
|
@@ -49,41 +49,41 @@ droits_remettre() {
|
|
|
49
49
|
fi
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
|
|
52
|
+
# After each opencode session: restores the modified files in the tree, reports in
|
|
53
|
+
# the journal any commit that touches them (history is never rewritten), raises the alert.
|
|
54
|
+
rights_verify() {
|
|
55
55
|
local d f depart sha message
|
|
56
|
-
d="$(
|
|
56
|
+
d="$(rights_dir "$1")"
|
|
57
57
|
[ -d "$d" ] || return 0
|
|
58
58
|
depart="$(cat "$d/head" 2>/dev/null || true)"
|
|
59
|
-
for f in "${
|
|
59
|
+
for f in "${RIGHTS_FILES[@]}"; do
|
|
60
60
|
message=""
|
|
61
61
|
if grep -qxF "$f" "$d/absents"; then
|
|
62
|
-
if [ -e "$1/$f" ]; then message="
|
|
62
|
+
if [ -e "$1/$f" ]; then message="change reverted"; fi
|
|
63
63
|
elif ! cmp -s "$d/fichiers/$f" "$1/$f"; then
|
|
64
|
-
message="
|
|
64
|
+
message="change reverted"
|
|
65
65
|
fi
|
|
66
66
|
sha=""
|
|
67
67
|
if [ -n "$depart" ]; then
|
|
68
68
|
if [ -n "$(git -C "$1" diff --name-only "$depart" HEAD -- "$f" 2>/dev/null)" ]; then
|
|
69
69
|
sha="$(git -C "$1" log -1 --format=%h "$depart..HEAD" -- "$f" 2>/dev/null || true)"
|
|
70
|
-
message="
|
|
70
|
+
message="change reverted in the tree, committed in ${sha:-HEAD}: remove this commit before any push"
|
|
71
71
|
fi
|
|
72
72
|
fi
|
|
73
73
|
[ -n "$message" ] || continue
|
|
74
|
-
|
|
75
|
-
echo "=== ⚠
|
|
74
|
+
rights_restore "$1" "$f"
|
|
75
|
+
echo "=== ⚠ rights changed: $f : $message" >>"$AGENT_JOURNAL"
|
|
76
76
|
echo "$f" >>"$d.alerte"
|
|
77
77
|
done
|
|
78
78
|
return 0
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
#
|
|
82
|
-
|
|
81
|
+
# For devzone agent state: one line per project whose rights were changed.
|
|
82
|
+
rights_alerts() {
|
|
83
83
|
local f
|
|
84
|
-
for f in "$
|
|
84
|
+
for f in "$AGENT_STATE"/droits-*.alerte; do
|
|
85
85
|
[ -e "$f" ] || continue
|
|
86
86
|
f="${f##*/droits-}"
|
|
87
|
-
echo " ⚠
|
|
87
|
+
echo " ⚠ rights changed (${f%.alerte}): see the journal"
|
|
88
88
|
done
|
|
89
89
|
}
|
|
@@ -16,7 +16,7 @@ mtime() {
|
|
|
16
16
|
fi
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
# Readable UTC date of an epoch, GNU then BSD date: shown by devzone agent
|
|
19
|
+
# Readable UTC date of an epoch, GNU then BSD date: shown by devzone agent state.
|
|
20
20
|
utc_time() {
|
|
21
21
|
if date -u -d "@$1" '+%Y-%m-%d %H:%M:%S' >/dev/null 2>&1; then
|
|
22
22
|
date -u -d "@$1" '+%Y-%m-%d %H:%M:%S'
|
|
@@ -48,18 +48,18 @@ lock_trace() {
|
|
|
48
48
|
lock_take() {
|
|
49
49
|
local end age lock_pid
|
|
50
50
|
end=$(( $(date +%s) + ${DEVZONE_AGENT_LOCK_MAX:-10} ))
|
|
51
|
-
while ! mkdir "$
|
|
51
|
+
while ! mkdir "$AGENT_STATE/verrou" 2>/dev/null; do
|
|
52
52
|
# A lock is orphaned only by its age: the rank is held for a few milliseconds,
|
|
53
53
|
# 30 s can only be a stop to take over; otherwise wait, then give up (code 1).
|
|
54
54
|
age=""
|
|
55
|
-
if [ -d "$
|
|
56
|
-
age="$(mtime "$
|
|
55
|
+
if [ -d "$AGENT_STATE/verrou" ]; then
|
|
56
|
+
age="$(mtime "$AGENT_STATE/verrou" 2>/dev/null)" || age=""
|
|
57
57
|
fi
|
|
58
|
-
lock_pid="$(cat "$
|
|
58
|
+
lock_pid="$(cat "$AGENT_STATE/verrou/pid" 2>/dev/null)" || lock_pid=""
|
|
59
59
|
lock_trace "mkdir failed" "age=${age:-unknown} lock-pid=${lock_pid:-none}"
|
|
60
60
|
if [ -n "$age" ] && [ "$(( $(date +%s) - age ))" -gt 30 ]; then
|
|
61
|
-
rm -f "$
|
|
62
|
-
if rmdir "$
|
|
61
|
+
rm -f "$AGENT_STATE/verrou/pid"
|
|
62
|
+
if rmdir "$AGENT_STATE/verrou" 2>/dev/null; then
|
|
63
63
|
lock_trace "purged" "age=$age"
|
|
64
64
|
continue
|
|
65
65
|
fi
|
|
@@ -69,18 +69,18 @@ lock_take() {
|
|
|
69
69
|
done
|
|
70
70
|
# pid before flock: the other agent never removes the folder while we wait on
|
|
71
71
|
# rang.lock, otherwise our pid write would fail with ENOENT.
|
|
72
|
-
echo "$$" >"$
|
|
72
|
+
echo "$$" >"$AGENT_STATE/verrou/pid"
|
|
73
73
|
if command -v flock >/dev/null 2>&1; then
|
|
74
74
|
# exec in an if makes a failure a condition instead of killing the shell
|
|
75
75
|
# (bash 3.2 and GNU alike); without flock, mkdir remains the only guard (macOS).
|
|
76
|
-
if { exec 9>"$
|
|
76
|
+
if { exec 9>"$AGENT_STATE/rang.lock"; } && flock -w "${DEVZONE_AGENT_LOCK_MAX:-10}" 9; then
|
|
77
77
|
AGENT_LOCK_FLOCK=1
|
|
78
78
|
else
|
|
79
79
|
lock_release
|
|
80
80
|
return 1
|
|
81
81
|
fi
|
|
82
82
|
fi
|
|
83
|
-
lock_trace taken "path=$
|
|
83
|
+
lock_trace taken "path=$AGENT_STATE/verrou"
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
# Releases the shared rank taken by lock_take: removes the pid, then the folder, only
|
|
@@ -90,10 +90,10 @@ lock_take() {
|
|
|
90
90
|
# rang.lock.
|
|
91
91
|
lock_release() {
|
|
92
92
|
local pid
|
|
93
|
-
pid="$(cat "$
|
|
93
|
+
pid="$(cat "$AGENT_STATE/verrou/pid" 2>/dev/null)" || pid=""
|
|
94
94
|
if [ "$pid" = "$$" ]; then
|
|
95
|
-
rm -f "$
|
|
96
|
-
rmdir "$
|
|
95
|
+
rm -f "$AGENT_STATE/verrou/pid"
|
|
96
|
+
rmdir "$AGENT_STATE/verrou" 2>/dev/null || true
|
|
97
97
|
lock_trace released
|
|
98
98
|
fi
|
|
99
99
|
if [ "${AGENT_LOCK_FLOCK:-0}" = 1 ]; then
|
|
@@ -112,7 +112,7 @@ rank_take() {
|
|
|
112
112
|
lock_take || return 1
|
|
113
113
|
start=$(( $(cat "$state/rang" 2>/dev/null || echo 0) % ${#FREE_MODELS[@]} ))
|
|
114
114
|
if [ "$PAUSE_RANK" -gt 0 ]; then sleep "$PAUSE_RANK"; fi
|
|
115
|
-
if
|
|
115
|
+
if model_rank_advance; then echo $(( start + 1 )) >"$state/rang"; fi
|
|
116
116
|
lock_release
|
|
117
117
|
echo "=== rank $(( start + 1 ))/${#FREE_MODELS[@]}" >>"$journal"
|
|
118
118
|
echo "$start"
|
|
@@ -123,7 +123,7 @@ rank_take() {
|
|
|
123
123
|
rights_edit_deny() {
|
|
124
124
|
local patterns f
|
|
125
125
|
patterns="[]"
|
|
126
|
-
for f in "${
|
|
126
|
+
for f in "${RIGHTS_FILES[@]}"; do
|
|
127
127
|
patterns="$(jq -c --arg f "$f" '. + [$f, "**/" + $f]' <<<"$patterns")"
|
|
128
128
|
done
|
|
129
129
|
jq -ce --argjson patterns "$patterns" '
|
|
@@ -138,8 +138,8 @@ rights_edit_deny() {
|
|
|
138
138
|
# out of the merge, then added back at the end (the key order of a jq object is the
|
|
139
139
|
# insertion order), so the caller can add permissions but never remove a devzone deny.
|
|
140
140
|
# ~/bash32 is always protected: the container's bash 3.2 was already replaced by a
|
|
141
|
-
# link (#210).
|
|
142
|
-
|
|
141
|
+
# link (#210). Also called by agent-rights-gh.bats.
|
|
142
|
+
configure() {
|
|
143
143
|
local def config
|
|
144
144
|
def="$ICI/opencode/agent.json"
|
|
145
145
|
[ -r "$def" ] || refuse "default configuration missing: $def"
|
|
@@ -194,12 +194,12 @@ session_model_start() {
|
|
|
194
194
|
START_SESSION="$(sed -nE 's/.* start ([^ ]+).*/\1/p' <<<"$line")"
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
# Models asked with devzone agent --
|
|
198
|
-
# "=== --
|
|
197
|
+
# Models asked with devzone agent --model (#420): the last header line
|
|
198
|
+
# "=== --model : " of the journal, empty when nothing was asked.
|
|
199
199
|
session_request() {
|
|
200
200
|
local line
|
|
201
|
-
line="$(grep '^=== --
|
|
202
|
-
REQUEST_SESSION="${line#=== --
|
|
201
|
+
line="$(grep '^=== --model : ' "$1" 2>/dev/null | tail -1 || true)"
|
|
202
|
+
REQUEST_SESSION="${line#=== --model : }"
|
|
203
203
|
if [ "$REQUEST_SESSION" = none ]; then REQUEST_SESSION=""; fi
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -238,5 +238,5 @@ agent_state() {
|
|
|
238
238
|
done
|
|
239
239
|
[ "$seen" = 1 ] || echo " no session"
|
|
240
240
|
agent_exclusions
|
|
241
|
-
|
|
241
|
+
rights_alerts
|
|
242
242
|
}
|