Add per-service database binding and fix single-dash flag detection in svc.sh #182

Merged
weichen merged 6 commits from feature/svc-db-bind into main 2026-10-04 13:44:02 +00:00
Owner

feature/svc-db-bind 任务卡

任务主记录:<PR 链接,task-finish 时填写>;状态:进行中;owner:weichen

基线与授权

  • 权威仓:ssh://git@git-ssh.u1680832.nyat.app:31411/weichen/Agent-System-Dev.git;目标分支:main;R0(initial_base_sha)= 3836ea88e3
  • 工作区:/home/weichen/projects/Agent-System-Dev-wt-feature-svc-db-bind(worktree);分支:feature/svc-db-bind
  • 授权与交付终点:实现"服务↔数据库绑定"(svc.sh 服务级 db 子命令 + info/list 显示绑定)并修复
    adjust_args_for_bin 单横线误判;终点 = PR 合入 main(附 precheck / task-sync / 测试证据)

目标与非目标

目标:

  • agent 服务可绑定/切换/解除数据库:svc.sh <name> db [pg名 [--db X] | --clear] [--no-restart];
    缺省查看当前绑定与可用实例。绑定 = DSN 写入持久化 exec= + dbref=/<库> 登记,实例运行中
    缺库自动建,服务运行中自动重启生效;--clear 回内嵌 SQLite 档。
  • 显示层全链路:list 表新增 DB 列;status 详情新增"数据库"行;info 数据库节新增"绑定服务"
    反向映射;无 dbref 的旧服务按 DSN host:port 反查匹配实例(外部 DSN 显示 外部@host:port)。
  • 修复既有缺陷:adjust_args_for_bin 以 grep '--dsn' 检测旗标支持,Go flag 帮助打印单横线
    -dsn,导致现役二进制的 --dsn/--auth 在 deploy 重建参数时被误删——改为"去横线旗标名 +
    1-2 横线"匹配。
  • record_state 跨重启保留 dbref;svc_del_key 辅助;db create 尾部提示绑定命令;
    usage/usage_short/help(lifecycle/db)/docs/svc.md 同步。

非目标:不改 agent 二进制与部署/生命周期语义;不做 static/postgres 的绑定;不做运行中热切换
(切换经重启生效)。

同步记录

节点 sync_base_sha tested_head_sha checked_at
启动 3836ea88e3 3836ea88e3 2026-10-04T13:23:33Z

结果与验证(完成后填写)

  • 结果:已实现(上列目标全部落地;<name> db 服务级动作与顶层 db 命令并存无冲突)。
  • 验证(worktree runtime 实测,真实 agent 二进制 + PostgreSQL 18,2026-10-04):
    • 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 且提示正确;
    • 显示层:list DB 列(t-app→bpg/agent)、t-app db 查看(掩码 DSN+实例列表)、info 数据库节
      "绑定服务 t-app(agent)";手删 dbref 模拟旧部署 → list 按 DSN host:port 反查仍显示 bpg/agent;
    • adjust 修复:正例(帮助含 -dsn 判支持)与负例(无 dsn 判不支持)均正确;
    • 回归:db dsn(掩码)/ db ls / info / history(新增 set ok db bind → bpg/agent 事件)/
      --help 正常;测试现场(t-app/bpg)已 rm --purge 清除;
    • 正式验收:make test exit 0(test-boundaries/pins/libs/core/backend/frontend/ui/agentcmd 全过)。
  • 影响与剩余项:list 表加宽一列;老脚本无兼容性问题(dbref 缺省视为未绑定);
    发现并修复的 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 主记录)

# feature/svc-db-bind 任务卡 任务主记录:<PR 链接,task-finish 时填写>;状态:进行中;owner:weichen ## 基线与授权 - 权威仓:ssh://git@git-ssh.u1680832.nyat.app:31411/weichen/Agent-System-Dev.git;目标分支:main;R0(initial_base_sha)= 3836ea88e3954878f257b7708ae5ccef947ccd79 - 工作区:/home/weichen/projects/Agent-System-Dev-wt-feature-svc-db-bind(worktree);分支:feature/svc-db-bind - 授权与交付终点:实现"服务↔数据库绑定"(svc.sh 服务级 db 子命令 + info/list 显示绑定)并修复 adjust_args_for_bin 单横线误判;终点 = PR 合入 main(附 precheck / task-sync / 测试证据) ## 目标与非目标 目标: - agent 服务可绑定/切换/解除数据库:`svc.sh <name> db [pg名 [--db X] | --clear] [--no-restart]`; 缺省查看当前绑定与可用实例。绑定 = DSN 写入持久化 exec= + dbref=<pg>/<库> 登记,实例运行中 缺库自动建,服务运行中自动重启生效;--clear 回内嵌 SQLite 档。 - 显示层全链路:list 表新增 DB 列;status 详情新增"数据库"行;info 数据库节新增"绑定服务" 反向映射;无 dbref 的旧服务按 DSN host:port 反查匹配实例(外部 DSN 显示 外部@host:port)。 - 修复既有缺陷:adjust_args_for_bin 以 grep '--dsn' 检测旗标支持,Go flag 帮助打印单横线 `-dsn`,导致现役二进制的 --dsn/--auth 在 deploy 重建参数时被误删——改为"去横线旗标名 + 1-2 横线"匹配。 - record_state 跨重启保留 dbref;svc_del_key 辅助;db create 尾部提示绑定命令; usage/usage_short/help(lifecycle/db)/docs/svc.md 同步。 非目标:不改 agent 二进制与部署/生命周期语义;不做 static/postgres 的绑定;不做运行中热切换 (切换经重启生效)。 ## 同步记录 | 节点 | sync_base_sha | tested_head_sha | checked_at | |---|---|---|---| | 启动 | 3836ea88e3954878f257b7708ae5ccef947ccd79 | 3836ea88e3954878f257b7708ae5ccef947ccd79 | 2026-10-04T13:23:33Z | ## 结果与验证(完成后填写) - 结果:已实现(上列目标全部落地;`<name> db` 服务级动作与顶层 `db` 命令并存无冲突)。 - 验证(worktree runtime 实测,真实 agent 二进制 + PostgreSQL 18,2026-10-04): - `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 且提示正确; - 显示层:list DB 列(t-app→bpg/agent)、`t-app db` 查看(掩码 DSN+实例列表)、info 数据库节 "绑定服务 t-app(agent)";手删 dbref 模拟旧部署 → list 按 DSN host:port 反查仍显示 bpg/agent; - adjust 修复:正例(帮助含 `-dsn` 判支持)与负例(无 dsn 判不支持)均正确; - 回归:db dsn(掩码)/ db ls / info / history(新增 `set ok db bind → bpg/agent` 事件)/ --help 正常;测试现场(t-app/bpg)已 rm --purge 清除; - 正式验收:`make test` exit 0(test-boundaries/pins/libs/core/backend/frontend/ui/agentcmd 全过)。 - 影响与剩余项:list 表加宽一列;老脚本无兼容性问题(dbref 缺省视为未绑定); 发现并修复的 adjust_args_for_bin 缺陷影响既有 `deploy --dsn/--auth` 路径(此前被静默丢弃)。 剩余项无。 | 同步前验收 | 3836ea88e3954878f257b7708ae5ccef947ccd79 | 843495e0d0618b900d727e38570ff61451068c9b | 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 主记录)
weichen added 3 commits 2026-10-04 13:31:06 +00:00
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
Record the sync checkpoint
ci / test (pull_request) Successful in 2m2s
73bca5e749
weichen added 3 commits 2026-10-04 13:43:46 +00:00
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
Record the sync checkpoint
ci / test (pull_request) Successful in 1m56s
83fd6f5f35
weichen merged commit 5a791fd1c3 into main 2026-10-04 13:44:02 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-System-Dev#182