Skip to content

P1b: RegimeBrowser 治理结构拓扑图可视化 - #19

Merged
LeoLin990405 merged 4 commits into
mainfrom
feature/p1-topology-visualization
Jul 22, 2026
Merged

LeoLin990405 merged 4 commits into
mainfrom
feature/p1-topology-visualization

Conversation

@LeoLin990405

Copy link
Copy Markdown
Owner

P1b: RegimeBrowser 治理结构拓扑图可视化

基于 #18(政体拓扑类型化),把 topology.json 可视化进前端。Base 设为 feature/p1-regime-topology#18 合并后本 PR 会自动 retarget 到 main。

改动

  • GET /api/regimes/:region/:id/topology(dev server 只读端点):safeResolve 路径校验 → 400;无文件 → 404;校验失败 → 422 带 details;成功 → 200 {topology, metrics},metrics 由引擎 computeMetrics 服务端计算(UI 与 CLI 同一真源)
  • TopologyGraph.tsx(477 行新组件):自绘 SVG 分层布局,零新增依赖
    • 布局:command 边 Kahn 最长路分层(环按出入度盈余破环)+ barycenter 两遍扫描减交叉
    • 视觉:command 实线青 / review 虚线金 / veto 点划线品红加粗 / info 细灰点线;节点按 9 种 functional_role 着色
    • 交互:hover 节点高亮关联边 + 详情条(可点击钉住);hover 边显示 note 出处标注
    • metrics 摘要 chips(nodes/edges/density/depth/checks);未类型化政体优雅占位
  • RegimeBrowser 新增 "Topology" 标签页(与 Org Chart 共享选中态)

验证

  • npm run build(含 tsc -b)通过;根目录 npm test 97 pass / 0 fail;lint 通过
  • API 冒烟:tang 200 / han 404 / 路径穿越 400 / 旧端点不受影响

待决策

  1. topology 端点目前只挂 dev server,生产静态部署需抽独立小服务
  2. 端点暂只有 curl 冒烟,无持久集成测试
  3. 10 节点布局会挤(当前最大 9 节点),后续可加 pan-zoom

  4. Topology 与 Org Chart 标签共享选中态(如需独立可拆)

…etrics, CLI

P1: make governance topology a first-class, computable artifact.

- schemas/regime-topology.schema.json: { schema_version, regime, mode,
  nodes[], edges[] }. nodes carry { id, label, functional_role } with the
  compiler's 9-role vocabulary (coordinator/engineering/review/research/
  data/devops/content/legal/management); edges carry { from, to, kind }
  with kind in command (instructions/reporting) / review (checks) /
  info (sharing) / veto (rejection).
- engine/topology/validate.mjs: zero-dependency hand-written schema
  validation + cross-checks: mode must match metadata orchestrationPattern
  (alias-normalized), and node ids must equal the IDENTITY.md role mapping
  table exactly (no invented or omitted roles).
- engine/topology/metrics.mjs: node/edge counts, density, command-chain
  depth (longest simple command path, cycle-safe), in-degree centrality,
  and checks-cycle count (elementary cycles containing a review/veto edge).
- bin/civagent: new 'civagent topology validate|metrics <regime>'
  subcommand; 'civagent doctor' now validates every regime that has a
  topology.json (regimes without one are skipped silently).
- package.json lint:syntax covers the two new engine files.

regime-to-cc.mjs is untouched: topology.json is a sidecar this iteration.
One hand-written topology.json per orchestration mode, each derived from
the regime's own IDENTITY.md (role mapping table, org chart, decision
flow) — no invented roles or flows:
- china/tang (checks-and-balances): zhongshu-sheren hub, dispatch/report
  spokes to the six ministries
- china/qin (centralized): emperor → three excellencies → ministers,
  yushi-censor review edges over all officials
- global/athens (democratic): boule proposals → ekklesia vote → execution,
  dikasterion post-hoc review
- china/ming (dual-track): shoufu/silijian 票拟-批红 veto cycle + six
  ministries fan-out
- china/zhou (federation): tianzi → zhuhou → qingdafu layered enfeoffment,
  xingren liaison info edges
- china/shang (theocratic): da-wang hub with divination chain
  da-wu → zhen-ren

test/topology.test.mjs (18 cases): schema positive/negative, IDENTITY
cross-check (missing/extra roles), hand-computed metrics on small graphs,
real-regime metric invariants, CLI smoke (validate/metrics exit codes).
- API: new read-only GET /api/regimes/:region/:id/topology in the vite
  dev-server middleware. Path safety reuses the existing safeResolve
  pattern (400 on bad segments, 404 when a regime has no topology.json,
  422 when the file fails validation). The handler imports the engine's
  validate.mjs/metrics.mjs directly, so UI and CLI share one source of
  truth for validation and graph metrics.
- Types: RegimeTopology / TopologyNode / TopologyEdge / TopologyMetrics /
  TopologyResponse added to frontend types (mirror schemas/regime-topology).
- New TopologyGraph component (4th RegimeBrowser tab 'Topology'):
  self-drawn SVG layered layout — Kahn layering over command edges with
  cycle-breaking (largest out−in surplus) + any-kind fallback for liaison
  nodes + two barycenter sweeps for sibling ordering. Edge styles:
  command solid cyan, review dashed gold, veto dashed crimson, info
  dotted gray; arrowheads per kind. Node hover/click pins a detail strip
  (role badge, id, edge list); edge hover shows the provenance note.
  Metrics chips (nodes/edges/density/depth/checks) in the panel header.
  Regimes without topology.json get a graceful '尚未类型化' placeholder.
- Zero new runtime dependencies; no graph library.
@LeoLin990405
LeoLin990405 changed the base branch from feature/p1-regime-topology to main July 22, 2026 09:59
@LeoLin990405
LeoLin990405 merged commit 5651af9 into main Jul 22, 2026
1 check passed
@LeoLin990405
LeoLin990405 deleted the feature/p1-topology-visualization branch July 22, 2026 10:59
LeoLin990405 added a commit that referenced this pull request Jul 29, 2026
Reconciles the two diverged lines: this branch's v6 hardening (constitutional
mechanism engine, Express API server, history-db episodic memory, i18n sweep,
regime audit) with main's P1-P6 features (topology graphs, BT stats pipeline,
skill supply-chain gate, ablation variants, hill-climbing loop, T3
deterministic scoring, anchored blind-judge rubric).

Key resolutions:
- tournament.mjs: main's anchored-rubric blind judge + T3 grading kept as the
  successor; branch's history-db recording, spawn-error handler, and
  markdown --task-file support grafted on top (.json → T3 spec, else plain text)
- run-v5.mjs: mechanism engine + UTF-8-safe line decoding kept, with main's
  withPermissionMode() and per-turn actor attribution folded in
- skill-sediment.mjs: main's writeSkillFile (frontmatter pinning + content
  hash) extended with the branch's random filename suffix + atomic tmp+rename
- API home is the Express server (vite middleware dropped); main-only
  endpoints ported as server/routes/stats.mjs and /api/regimes/:r/:id/topology
- App.tsx keeps the v6 glassmorphism shell; RankingsPanel mounted as a new tab
- china/tang keeps the audited 9-agent 三省 structure; topology.json rewritten
  to match and topology tests updated accordingly
- events schema: union of mechanism event types and the v2 OTel envelope

ci: 213 tests green, 57 regimes validated, frontend tsc/lint/build clean
LeoLin990405 pushed a commit that referenced this pull request Aug 6, 2026
- wanikua#37: Replace static AUTH_TOKEN with dynamic getAuthToken() to fix 401 after login
- #29: Change silijian agent id from 'main' to 'silijian' to avoid conflicts
- #19: Remove deprecated fields (runTimeoutSeconds, maxConcurrent), fix api field, add troubleshooting
- #20: Add --with-gui / --no-gui flag for optional Dashboard installation
- #31: Add comments recommending openclaw CLI over direct config editing
- #26: Add docs/windows-wsl.md for WSL2 setup guide
- #25/#17: Add hanlinyuan (翰林院) agent as optional configuration
LeoLin990405 pushed a commit that referenced this pull request Aug 6, 2026
LeoLin990405 added a commit that referenced this pull request Aug 6, 2026
* feat(topology): explicit regime-as-graph layer — schema, validator, metrics, CLI

P1: make governance topology a first-class, computable artifact.

- schemas/regime-topology.schema.json: { schema_version, regime, mode,
  nodes[], edges[] }. nodes carry { id, label, functional_role } with the
  compiler's 9-role vocabulary (coordinator/engineering/review/research/
  data/devops/content/legal/management); edges carry { from, to, kind }
  with kind in command (instructions/reporting) / review (checks) /
  info (sharing) / veto (rejection).
- engine/topology/validate.mjs: zero-dependency hand-written schema
  validation + cross-checks: mode must match metadata orchestrationPattern
  (alias-normalized), and node ids must equal the IDENTITY.md role mapping
  table exactly (no invented or omitted roles).
- engine/topology/metrics.mjs: node/edge counts, density, command-chain
  depth (longest simple command path, cycle-safe), in-degree centrality,
  and checks-cycle count (elementary cycles containing a review/veto edge).
- bin/civagent: new 'civagent topology validate|metrics <regime>'
  subcommand; 'civagent doctor' now validates every regime that has a
  topology.json (regimes without one are skipped silently).
- package.json lint:syntax covers the two new engine files.

regime-to-cc.mjs is untouched: topology.json is a sidecar this iteration.

* feat(topology): 6 representative regime topologies + test suite

One hand-written topology.json per orchestration mode, each derived from
the regime's own IDENTITY.md (role mapping table, org chart, decision
flow) — no invented roles or flows:
- china/tang (checks-and-balances): zhongshu-sheren hub, dispatch/report
  spokes to the six ministries
- china/qin (centralized): emperor → three excellencies → ministers,
  yushi-censor review edges over all officials
- global/athens (democratic): boule proposals → ekklesia vote → execution,
  dikasterion post-hoc review
- china/ming (dual-track): shoufu/silijian 票拟-批红 veto cycle + six
  ministries fan-out
- china/zhou (federation): tianzi → zhuhou → qingdafu layered enfeoffment,
  xingren liaison info edges
- china/shang (theocratic): da-wang hub with divination chain
  da-wu → zhen-ren

test/topology.test.mjs (18 cases): schema positive/negative, IDENTITY
cross-check (missing/extra roles), hand-computed metrics on small graphs,
real-regime metric invariants, CLI smoke (validate/metrics exit codes).

* feat(frontend): governance topology visualization in RegimeBrowser

- API: new read-only GET /api/regimes/:region/:id/topology in the vite
  dev-server middleware. Path safety reuses the existing safeResolve
  pattern (400 on bad segments, 404 when a regime has no topology.json,
  422 when the file fails validation). The handler imports the engine's
  validate.mjs/metrics.mjs directly, so UI and CLI share one source of
  truth for validation and graph metrics.
- Types: RegimeTopology / TopologyNode / TopologyEdge / TopologyMetrics /
  TopologyResponse added to frontend types (mirror schemas/regime-topology).
- New TopologyGraph component (4th RegimeBrowser tab 'Topology'):
  self-drawn SVG layered layout — Kahn layering over command edges with
  cycle-breaking (largest out−in surplus) + any-kind fallback for liaison
  nodes + two barycenter sweeps for sibling ordering. Edge styles:
  command solid cyan, review dashed gold, veto dashed crimson, info
  dotted gray; arrowheads per kind. Node hover/click pins a detail strip
  (role badge, id, edge list); edge hover shows the provenance note.
  Metrics chips (nodes/edges/density/depth/checks) in the panel header.
  Regimes without topology.json get a graceful '尚未类型化' placeholder.
- Zero new runtime dependencies; no graph library.
LeoLin990405 added a commit that referenced this pull request Aug 6, 2026
Reconciles the two diverged lines: this branch's v6 hardening (constitutional
mechanism engine, Express API server, history-db episodic memory, i18n sweep,
regime audit) with main's P1-P6 features (topology graphs, BT stats pipeline,
skill supply-chain gate, ablation variants, hill-climbing loop, T3
deterministic scoring, anchored blind-judge rubric).

Key resolutions:
- tournament.mjs: main's anchored-rubric blind judge + T3 grading kept as the
  successor; branch's history-db recording, spawn-error handler, and
  markdown --task-file support grafted on top (.json → T3 spec, else plain text)
- run-v5.mjs: mechanism engine + UTF-8-safe line decoding kept, with main's
  withPermissionMode() and per-turn actor attribution folded in
- skill-sediment.mjs: main's writeSkillFile (frontmatter pinning + content
  hash) extended with the branch's random filename suffix + atomic tmp+rename
- API home is the Express server (vite middleware dropped); main-only
  endpoints ported as server/routes/stats.mjs and /api/regimes/:r/:id/topology
- App.tsx keeps the v6 glassmorphism shell; RankingsPanel mounted as a new tab
- china/tang keeps the audited 9-agent 三省 structure; topology.json rewritten
  to match and topology tests updated accordingly
- events schema: union of mechanism event types and the v2 OTel envelope

ci: 213 tests green, 57 regimes validated, frontend tsc/lint/build clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant