fix(daemon): carry user_projects.modelPref through to launch

/api/agent/projects already returned model = project.modelPref for
every project, but the daemon's sync script only wrote 3 columns
(tab|dir|agent), so the model field was silently discarded between
cloud DB and local conf. _agent_launch_cmd accepts a model arg and
passes it through (codex --model, gemini -m, etc.), but the
auto-launch path in execute_inject was hardcoded to empty string.
End result: a Codex project pinned to gpt-5 still launched gpt-5.4,
a Gemini project pinned to flash launched 1.5-pro.

Three-file fix:
- sync-agent-runtime-config.py: write tab|dir|agent|model. Header
  comment updated.
- agent-hook-lib.sh: _conf_agent_for_tab IFS read adds a 4th field
  variable (legacy 3-col lines still work, unread field is empty).
  Add _conf_model_for_tab mirror that reads the 4th column.
- cockpit-daemon.sh execute_inject auto-launch branch: look up the
  conf model and pass it to _agent_launch_cmd.

Verified against a synthetic 4-col conf:
  DemoProj   → agent=claude model=opus
  AOZ        → agent=gemini model=flash
  Legacy     → agent=grok   model=<none>   (3-col line, no break)
  NonExist   → agent=<none> model=<none>

Not yet wired: launch_agent / switch_agent paths still take model
from queue payload only. Cloud /api/inject doesn't pass model in
payload yet either — those are the next iterations.
This commit is contained in:
g-but committed 2026-05-31 01:43:17 +02:00
1 parent 46398144e1
commit 501a6e715b
3 files changed
+38 -6

No files matched your search

+26 -3
View File
@@ -48,13 +48,15 @@ resolve_adapter() {
# Look up the third (agent) column for a tab in agent-projects.conf. Empty
# output means either the conf is unreadable, the tab isn't registered, or
# the agent column is blank.
# the agent column is blank. Handles legacy 3-col lines and current 4-col
# (tab|dir|agent|model) lines transparently — the unused 4th field is just
# ignored.
_conf_agent_for_tab() {
local tab="$1" conf
conf="${AGENT_PROJECTS_CONF:-${CLAUDE_PROJECTS_CONF:-$HOME/.config/agent-projects.conf}}"
[ -r "$conf" ] || return 1
local t _d a
while IFS='|' read -r t _d a || [ -n "$t" ]; do
local t _d a _m
while IFS='|' read -r t _d a _m || [ -n "$t" ]; do
[[ "$t" =~ ^[[:space:]]*# ]] && continue
t=$(echo "$t" | xargs 2>/dev/null)
[ -z "$t" ] && continue
@@ -67,6 +69,27 @@ _conf_agent_for_tab() {
return 1
}
# Look up the fourth (model) column. Same shape as _conf_agent_for_tab.
# Returns 1 (no output) for legacy 3-col conf lines or blank model field —
# callers should default to the agent's built-in model in that case.
_conf_model_for_tab() {
local tab="$1" conf
conf="${AGENT_PROJECTS_CONF:-${CLAUDE_PROJECTS_CONF:-$HOME/.config/agent-projects.conf}}"
[ -r "$conf" ] || return 1
local t _d _a m
while IFS='|' read -r t _d _a m || [ -n "$t" ]; do
[[ "$t" =~ ^[[:space:]]*# ]] && continue
t=$(echo "$t" | xargs 2>/dev/null)
[ -z "$t" ] && continue
if [ "${t,,}" = "${tab,,}" ]; then
m=$(echo "$m" | xargs 2>/dev/null)
[ -n "$m" ] && { printf '%s\n' "$m"; return 0; }
return 1
fi
done < "$conf"
return 1
}
# Resolve the adapter actually running in a tab — not just the conf default.
# Priority: /proc scan for project dir → current-prompt JSON adapter →
# agent-projects.conf agent column → tab suffix → legacy resolve_adapter →
+9 -1
View File
@@ -243,8 +243,16 @@ execute_inject() {
# before injecting. Otherwise the prompt gets typed into a bare shell.
if [ -n "$project_dir" ] && type _is_agent_running_in_dir >/dev/null 2>&1 \
&& ! _is_agent_running_in_dir "$adapter" "$project_dir"; then
# Honor user_projects.modelPref via the 4th column of agent-projects.conf
# (synced from /api/agent/projects). Without this the launch always used
# the agent's built-in default, so a Codex project pinned to gpt-5 still
# launched as gpt-5.4 and a Gemini project pinned to flash launched 1.5-pro.
local _model=""
if type _conf_model_for_tab >/dev/null 2>&1; then
_model=$(_conf_model_for_tab "$tab" 2>/dev/null || true)
fi
local _launch_cmd
_launch_cmd=$(_agent_launch_cmd "$adapter" "$project_dir" "" 2>/dev/null)
_launch_cmd=$(_agent_launch_cmd "$adapter" "$project_dir" "$_model" 2>/dev/null)
if [ -n "$_launch_cmd" ]; then
log "inject: no $adapter in $tab — auto-launching"
# Fresh agent → fresh session → re-deliver the handoff template once.
+3 -2
View File
@@ -56,7 +56,7 @@ def sync_projects_from_cloud(target: Path, env: dict[str, str]) -> bool:
lines = [
"# Managed by Cockpit. Edit projects in the web Control page; the daemon syncs this file.",
"# Format: tab_name|/absolute/path/to/project|agent",
"# Format: tab_name|/absolute/path/to/project|agent|model",
]
for project in projects:
if not isinstance(project, dict):
@@ -64,8 +64,9 @@ def sync_projects_from_cloud(target: Path, env: dict[str, str]) -> bool:
name = clean_field(project.get("name"))
dir_path = clean_field(project.get("dirPath"))
agent = clean_field(project.get("agent"))
model = clean_field(project.get("model"))
if name and dir_path:
lines.append(f"{name}|{dir_path}|{agent}")
lines.append(f"{name}|{dir_path}|{agent}|{model}")
target.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile("w", encoding="utf-8", dir=str(target.parent), delete=False) as tmp: