Why: info showed services and postgres instances but no service-to-database
correspondence, and switching an agent service to another database required
redeploying with a hand-built DSN. While wiring this up, adjust_args_for_bin
was found matching Go flag help with '--dsn' although Go prints '-dsn', so
deploy-built --dsn/--auth args were silently dropped on current binaries.
Evidence: full E2E in the task worktree with a real agent binary and a real
PostgreSQL 18 instance -- 't-app db bpg' persisted exec=/dbref, auto-restarted
(dbref survives record_state rewrites), and the agent created 21 tables in the
bound database; 'db bpg --db t2' auto-created and switched databases (21
tables in t2); '--clear' returned the service to embedded SQLite; --no-restart
and error paths behave; list gains a DB column, status a database line, info a
reverse bound-services line; legacy deployments without dbref resolve by DSN
host:port; single-dash detection proven with positive and negative cases;
regressions list/db dsn/db ls/info/history/--help pass; make test exit 0.
Full log in the task card.
Impact: new service-level action 'svc.sh <name> db [pg [--db X] | --clear]
[--no-restart]' for agent services (bind/switch/unbind/view), DB column in
list, binding lines in status/info, dbref persisted in svc.env, auto database
creation when the instance runs, and the adjust_args_for_bin fix restoring
deploy --dsn/--auth on current binaries. No agent binary changes.
Refs: task card .task/feature-svc-db-bind.md (same doc as the PR); docs/svc.md
sections 4.5/6.1/6.2/10.1
Why: beyond database binding, services needed a way to switch the JSON config
file they run with and have the new config take effect promptly; hand-editing
exec= risks restarting a service into an invalid config.
Evidence: in the task worktree with a real agent binary -- a config with an
unknown key is rejected by the binary's strict schema check before any state
change; a valid file binds via --config in exec= + conffile= (survives
record_state rewrites), restarts the running service, and the config's dsn
verifiably drives the process (wrong-password variant failed PG auth in the
log; correct variant connected and created 21 tables); editing the file and
re-running 'config <same file>' re-validates and restarts (pid changes);
'--clear' removes both the flag and conffile; db and config coexist in exec=;
view mode shows masked JSON content plus 'config explain' effective values
with masked dsn; list DB column also resolves dsns that live only inside the
config file. Full log in the task card.
Impact: new service-level action 'svc.sh <name> config [file | --clear]
[--no-restart]' for agent services; config-file content snapshots (masked,
--reveal to show) in info; a config-file line in status; conffile persisted
in svc.env. No agent binary changes.
Refs: task card .task/feature-svc-db-bind.md (same doc as PR #182);
docs/svc.md sections 2/4.5/4.6/6/10.1
Why: completion statement carries precheck/task-sync/test evidence.
Evidence: make test exit 0 at head ecfed7b; functional evidence in the card.
Impact: card-only; PR description mirrors this card.
Refs: .task/feature-svc-db-bind.md
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
feature/svc-db-bind 任务卡
任务主记录:<PR 链接,task-finish 时填写>;状态:进行中;owner:weichen
基线与授权
3836ea88e3adjust_args_for_bin 单横线误判;终点 = PR 合入 main(附 precheck / task-sync / 测试证据)
目标与非目标
目标:
svc.sh <name> db [pg名 [--db X] | --clear] [--no-restart];缺省查看当前绑定与可用实例。绑定 = DSN 写入持久化 exec= + dbref=/<库> 登记,实例运行中
缺库自动建,服务运行中自动重启生效;--clear 回内嵌 SQLite 档。
反向映射;无 dbref 的旧服务按 DSN host:port 反查匹配实例(外部 DSN 显示 外部@host:port)。
-dsn,导致现役二进制的 --dsn/--auth 在 deploy 重建参数时被误删——改为"去横线旗标名 +1-2 横线"匹配。
usage/usage_short/help(lifecycle/db)/docs/svc.md 同步。
非目标:不改 agent 二进制与部署/生命周期语义;不做 static/postgres 的绑定;不做运行中热切换
(切换经重启生效)。
同步记录
3836ea88e33836ea88e3结果与验证(完成后填写)
<name> db服务级动作与顶层db命令并存无冲突)。bash -n通过;t-app db bpg→ exec= 写入 --dsn、dbref=bpg/agent、自动重启生效;record_state重写 svc.env 后 dbref 保留;PG 的 agent 库出现 21 张表(服务真实落库,非仅配置);
t-app db bpg --db t2→ 自动建库 t2、重启、t2 库 21 张表;db --clear→ dbref/--dsn 移除、重启回内嵌档;--no-restart只改登记;错误路径(未登记实例/多余参数/postgres 服务)均 exit 2 且提示正确;t-app db查看(掩码 DSN+实例列表)、info 数据库节"绑定服务 t-app(agent)";手删 dbref 模拟旧部署 → list 按 DSN host:port 反查仍显示 bpg/agent;
-dsn判支持)与负例(无 dsn 判不支持)均正确;set ok db bind → bpg/agent事件)/--help 正常;测试现场(t-app/bpg)已 rm --purge 清除;
make testexit 0(test-boundaries/pins/libs/core/backend/frontend/ui/agentcmd 全过)。发现并修复的 adjust_args_for_bin 缺陷影响既有
deploy --dsn/--auth路径(此前被静默丢弃)。剩余项无。
| 同步前验收 |
3836ea88e3|843495e0d0| 2026-10-04T13:30:59Z |提交主题:Add per-service database binding and fix single-dash flag detection in svc.sh
(body 四段 Why/Evidence/Impact/Refs 见提交说明;本卡即 PR 主记录)