siwpan-agent 1.0.2__tar.gz
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.
- siwpan_agent-1.0.2/LICENSE +16 -0
- siwpan_agent-1.0.2/PKG-INFO +8 -0
- siwpan_agent-1.0.2/README.md +142 -0
- siwpan_agent-1.0.2/agent/__init__.py +3 -0
- siwpan_agent-1.0.2/agent/__main__.py +264 -0
- siwpan_agent-1.0.2/agent/assembly.py +27 -0
- siwpan_agent-1.0.2/agent/audit.py +215 -0
- siwpan_agent-1.0.2/agent/bridges/__init__.py +84 -0
- siwpan_agent-1.0.2/agent/brief.py +157 -0
- siwpan_agent-1.0.2/agent/capabilities.py +235 -0
- siwpan_agent-1.0.2/agent/chain.py +117 -0
- siwpan_agent-1.0.2/agent/check.py +191 -0
- siwpan_agent-1.0.2/agent/contracts/__init__.py +13 -0
- siwpan_agent-1.0.2/agent/facts.py +116 -0
- siwpan_agent-1.0.2/agent/flow.py +62 -0
- siwpan_agent-1.0.2/agent/guide.py +305 -0
- siwpan_agent-1.0.2/agent/home.py +101 -0
- siwpan_agent-1.0.2/agent/hosts.py +195 -0
- siwpan_agent-1.0.2/agent/kb.py +196 -0
- siwpan_agent-1.0.2/agent/ledger.py +664 -0
- siwpan_agent-1.0.2/agent/rollout.py +424 -0
- siwpan_agent-1.0.2/agent/roots.py +33 -0
- siwpan_agent-1.0.2/agent/wiring.py +321 -0
- siwpan_agent-1.0.2/pyproject.toml +17 -0
- siwpan_agent-1.0.2/setup.cfg +4 -0
- siwpan_agent-1.0.2/siwpan_agent.egg-info/PKG-INFO +8 -0
- siwpan_agent-1.0.2/siwpan_agent.egg-info/SOURCES.txt +39 -0
- siwpan_agent-1.0.2/siwpan_agent.egg-info/dependency_links.txt +1 -0
- siwpan_agent-1.0.2/siwpan_agent.egg-info/entry_points.txt +2 -0
- siwpan_agent-1.0.2/siwpan_agent.egg-info/top_level.txt +1 -0
- siwpan_agent-1.0.2/tests/test_audit.py +47 -0
- siwpan_agent-1.0.2/tests/test_brain_parity.py +53 -0
- siwpan_agent-1.0.2/tests/test_capabilities.py +70 -0
- siwpan_agent-1.0.2/tests/test_check.py +55 -0
- siwpan_agent-1.0.2/tests/test_facts_brief.py +126 -0
- siwpan_agent-1.0.2/tests/test_guide.py +108 -0
- siwpan_agent-1.0.2/tests/test_hosts.py +42 -0
- siwpan_agent-1.0.2/tests/test_kb.py +32 -0
- siwpan_agent-1.0.2/tests/test_ledger.py +267 -0
- siwpan_agent-1.0.2/tests/test_rollout.py +213 -0
- siwpan_agent-1.0.2/tests/test_wiring.py +56 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT No Attribution
|
|
2
|
+
|
|
3
|
+
Copyright 2026 siwpan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
6
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
7
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
8
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
permit persons to whom the Software is furnished to do so.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
12
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
13
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
14
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
15
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
16
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# agent —— 总控 / 总入口
|
|
2
|
+
|
|
3
|
+
> **定位**:agent 是这套体系的**控制面与唯一入口**。它不持有各机事实,不写被治理仓的数据,
|
|
4
|
+
> 也不替代 govrule 做判据;它负责**选路、编排、把需求分派给能力层、把产物交给判据层**。
|
|
5
|
+
>
|
|
6
|
+
> 这个仓独立存在,是因为 agent 逻辑此前散落在被治理仓的角落(gate 脚本、审计日志、
|
|
7
|
+
> 上下文文件),导致「谁在总控」随会话摇摆,事实源也被控制逻辑污染。
|
|
8
|
+
> **总控必须有一个唯一、可版本化、可被别仓引用的家**。
|
|
9
|
+
|
|
10
|
+
## 四仓分工
|
|
11
|
+
|
|
12
|
+
| 仓 | 职责 | 不做什么 |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| `agent` | 总控、总入口、选路、会话编排 | 不持有机器事实、不写 registry |
|
|
15
|
+
| `allin` | 面向**各机事实源**:分区、月账、机器事实、项目登记 | 不做通用扫描能力、不自定义判据 |
|
|
16
|
+
| `allin-governance` | 面向 **allin** 的能力层:`scan --catalog`、`facts`、20 道门禁 | 不替消费仓决定人工语义 |
|
|
17
|
+
| `govrule` | **桥接**:判据 DSL、审批与交付、影子证据 | 不做会话编排、不持有运行时状态 |
|
|
18
|
+
|
|
19
|
+
## 总入口(选路与核对)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
python -m agent entry --list # 被治理仓与各自入口
|
|
23
|
+
python -m agent entry --repo allin # 选路到 allin 的入口
|
|
24
|
+
python -m agent verify # 核对三个仓的 agent.contract.yml
|
|
25
|
+
python -m agent check # 四仓例行判据:逐仓跑 govrule,任一 fail 即 exit 1
|
|
26
|
+
python -m agent check --json # 机读:逐仓 verdict / blocking / detail
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`agent` **不重新实现**任何被治理仓的能力;它只读取各仓的 `agent.contract.yml` 并校验,
|
|
30
|
+
然后给出「该走哪个仓、哪个命令」的确定答案。
|
|
31
|
+
|
|
32
|
+
## 接线与能力盘点
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
python -m agent wiring # 四仓接线静态自检:契约/证据/目标,逐边判定
|
|
36
|
+
python -m agent capabilities # 能力目录:四仓清单(按组分栏)
|
|
37
|
+
python -m agent capabilities --check # 逐条探活,死的报 FAIL(exit 1)
|
|
38
|
+
python -m agent capabilities --group governance # 只查某一组
|
|
39
|
+
python -m agent hosts # 四仓在 gitee/GitHub/PyPI 的位置与拓扑缺口
|
|
40
|
+
python -m agent doctor # 各仓虚拟环境体检(委派 governance 能力)
|
|
41
|
+
python -m agent status # 链条视图:order → run → flow → receipt(只读)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`hosts` 与 `doctor` 调子仓 CLI 做**现场核对**,不做缓存;`status` 看链条通不通(永远 exit 0)。
|
|
45
|
+
|
|
46
|
+
## 事实与简报
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python -m agent facts # 三处事实源的联邦读(转发 allin,不搬运/不缓存)
|
|
50
|
+
python -m agent facts --strict # 交叉校验有不一致即 exit 1
|
|
51
|
+
python -m agent brief # 一段式上下文:事实 + 知识 + 链条 + 契约(只读)
|
|
52
|
+
python -m agent brief --topic "轮换 吊销" --json # --json:一份 payload 拿全四段
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 知识库
|
|
56
|
+
|
|
57
|
+
`kb` 是本仓的大脑:跨仓知识库索引自建自检,索引由四仓文档派生、不另存事实。
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m agent kb build # 重建索引
|
|
61
|
+
python -m agent kb check # 源文档漂移(索引过期)即 exit 1
|
|
62
|
+
python -m agent kb stats # 条数与各仓分布
|
|
63
|
+
python -m agent kb --query "轮换 吊销" --budget 900 # 检索:命中带 id/摘要/路径,可回读原文再下结论
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`brief` 的知识段只给指针:直接问 govrule 的 kb search,本仓不重排它的结果——
|
|
67
|
+
口径重排过一次,就会和 `govrule kb search` 说的不一样。
|
|
68
|
+
|
|
69
|
+
## 例行复验
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
python -m agent audit --record # 用 trust/keys 核对 run/receipt 签名,结果入 log
|
|
73
|
+
python -m agent audit --freshness-days 7 # 最近一次成功 audit 超过 7 天 → exit 1(停摆)
|
|
74
|
+
python -m agent audit --ca-review-days 30 # CA 锚 30 天内到期提示;已过期 → exit 1
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`audit` 看签名成不成立(失败 exit 1);`--legacy` 兼容旧记录,`--limit N` 截取最近 N 条。
|
|
78
|
+
未签名的历史记录单列 `UNSIGNED`——不可验证不等于被篡改,但也不假装通过。
|
|
79
|
+
|
|
80
|
+
## 月账、掌权与全流程
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python -m agent ledger status # 本机月账差额(有未入账即 exit 1)
|
|
84
|
+
python -m agent ledger tick # 按日追加落账(幂等、只增不改)
|
|
85
|
+
python -m agent ledger push # 推送月账
|
|
86
|
+
python -m agent ledger install-automation # 安装定时任务
|
|
87
|
+
python -m agent rollout show|advance|guard|reverse|validate # 掌权比例状态机(判定/状态/锁全内嵌)
|
|
88
|
+
python -m agent flow --quick # allin 全流程巡检(转发 auto_flow;绝不 push)
|
|
89
|
+
python -m agent guide build|check|run|versions # 新人指南(docs/guide/)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`flow` 有 `--no-fetch`(离线)与 `--with-platform`(额外跑 platform 三件套);绝不 push。
|
|
93
|
+
`guide run --scope cleanroom` 在干净环境复跑指南命令,`--full` 包含慢命令。
|
|
94
|
+
|
|
95
|
+
## 退出码约定
|
|
96
|
+
|
|
97
|
+
- **只读视图**(entry / status / facts / brief / kb stats / guide versions)不判失败,永远 exit 0;
|
|
98
|
+
- **判据类**(check / verify / wiring / audit / capabilities --check / hosts /
|
|
99
|
+
facts --strict / kb check / ledger status)失败即 exit 1;
|
|
100
|
+
- `agent check` 内置 `agent-contract` 判据:**manifest.yml 版本必须等于打包版本**(pyproject 单源对齐)。
|
|
101
|
+
|
|
102
|
+
## 布局(参考 superengine)
|
|
103
|
+
|
|
104
|
+
只做四件事:**契约、桥接、装配、门禁**,不含任何算法。
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
agent/contracts/ 契约版本(不跟随任何一仓发版)
|
|
108
|
+
agent/bridges/ 唯一定读各仓契约的地方
|
|
109
|
+
agent/assembly.py 装配:三仓 + 契约 → 一张可校验的表(fail-loud)
|
|
110
|
+
agent/__main__.py CLI 总线:17 个子命令,每个子命令一个同各模块
|
|
111
|
+
(check / brief / facts / capabilities / kb / hosts / wiring /
|
|
112
|
+
ledger / rollout / flow / audit / chain / guide / home …)
|
|
113
|
+
tools/gate 仓级门禁
|
|
114
|
+
tools/ci CI 配置
|
|
115
|
+
tools/orchestration 编排路由(routes.yaml)
|
|
116
|
+
config/rollout.yml rollout 状态机配置
|
|
117
|
+
preset/allin allin 骨架预设
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 信任根
|
|
121
|
+
|
|
122
|
+
`trust/keys/` 放**公钥登记表**(一个指纹一个文件),验证方用它核对 run/receipt 签名:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
govrule identity verify --record <file> --trust trust/keys
|
|
126
|
+
govrule receipt verify --receipt <file> --trust trust/keys
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
签名者仓内的 `evidence/identity/public.json` 只用于自证;验证者应持有本目录的副本。
|
|
130
|
+
约定见 `trust/README.md`。
|
|
131
|
+
|
|
132
|
+
## 契约
|
|
133
|
+
|
|
134
|
+
- `manifest.yml`:本仓的身份、职责边界、消费的三个仓;
|
|
135
|
+
- 各被治理仓根下的 `agent.contract.yml`:声明角色、入口、拥有的面与禁止的面;
|
|
136
|
+
- `govrule` 的 `agent.entrypoint` 判据:核对契约不漂移。
|
|
137
|
+
|
|
138
|
+
消费者写契约、提供方实现能力、govrule 审批——沿用三仓已经验证的分工。
|
|
139
|
+
|
|
140
|
+
## 许可
|
|
141
|
+
|
|
142
|
+
MIT —— 与四仓中其他仓一致。详见 [LICENSE](LICENSE)。
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"""agent —— 总控入口(控制面,不持有事实、不写被治理仓)。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .assembly import MANAGED, assemble
|
|
11
|
+
from .roots import REPOS
|
|
12
|
+
|
|
13
|
+
# 根定位见 roots.py(单一事实来源);REPOS 已含 AGENT_REPOS_ROOT 安装态回退。
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
17
|
+
"""把 parser 造出来,而不是在 main() 里顺手造。
|
|
18
|
+
|
|
19
|
+
分开的理由不是好看:能力目录要能**反查真实子命令**(capabilities 的 C4,
|
|
20
|
+
「活着的都登记了吗」)。反查必须问 parser 本身,不能正则扫源码——
|
|
21
|
+
扫源码会漏掉变量拼出来的子命令,也会把注释里的 `sub.add_parser(` 算进去。
|
|
22
|
+
"""
|
|
23
|
+
ap = argparse.ArgumentParser(prog="agent")
|
|
24
|
+
sub = ap.add_subparsers(dest="cmd", required=False)
|
|
25
|
+
ck = sub.add_parser("check", help="四仓例行判据:逐个跑 govrule,任一 fail 即 exit 1")
|
|
26
|
+
ck.add_argument("--json", action="store_true")
|
|
27
|
+
entry = sub.add_parser("entry", help="总入口:选路到被治理仓")
|
|
28
|
+
entry.add_argument("--repo", choices=MANAGED, help="要进入的仓")
|
|
29
|
+
entry.add_argument("--list", action="store_true", help="列出被治理仓与入口")
|
|
30
|
+
sub.add_parser("verify", help="核对三个仓的 agent.contract.yml")
|
|
31
|
+
au = sub.add_parser("audit", help="用验证者信任根核对 run/receipt 签名(失败即 exit 1)")
|
|
32
|
+
au.add_argument("--trust", default="trust/keys")
|
|
33
|
+
au.add_argument("--json", action="store_true")
|
|
34
|
+
au.add_argument("--limit", type=int, default=20)
|
|
35
|
+
au.add_argument("--legacy", action="store_true")
|
|
36
|
+
au.add_argument("--record", action="store_true")
|
|
37
|
+
au.add_argument("--freshness-days", type=int, default=0)
|
|
38
|
+
au.add_argument("--ca-review-days", type=int, default=0)
|
|
39
|
+
wr = sub.add_parser("wiring", help="四仓接线静态自检(契约/证据/目标)")
|
|
40
|
+
wr.add_argument("--json", action="store_true")
|
|
41
|
+
br = sub.add_parser("brief", help="一段式上下文:事实 + 知识 + 链条 + 契约(只读)")
|
|
42
|
+
br.add_argument("--topic", help="知识检索主题(不给则跳过知识段)")
|
|
43
|
+
br.add_argument("--budget", type=int, default=1200)
|
|
44
|
+
br.add_argument("--json", action="store_true", help="机读:一份 payload 拿全四段")
|
|
45
|
+
fx = sub.add_parser("facts", help="三处事实源的联邦读(转发 allin,不搬运/不缓存)")
|
|
46
|
+
fx.add_argument("--json", action="store_true", help="机读(payload 原样透传)")
|
|
47
|
+
fx.add_argument("--strict", action="store_true", help="交叉校验有不一致即 exit 1")
|
|
48
|
+
kb = sub.add_parser("kb", help="agent 大脑:跨仓知识库 build/check/search/stats")
|
|
49
|
+
kb.add_argument("action", nargs="?", default="search",
|
|
50
|
+
choices=["build", "check", "search", "stats"])
|
|
51
|
+
kb.add_argument("--query", default="")
|
|
52
|
+
kb.add_argument("--budget", type=int, default=4000)
|
|
53
|
+
kb.add_argument("--json", action="store_true")
|
|
54
|
+
cap = sub.add_parser("capabilities", help="能力目录:四仓清单 + 逐条探活")
|
|
55
|
+
cap.add_argument("--check", action="store_true", help="逐条跑 --help,死的报 FAIL")
|
|
56
|
+
cap.add_argument("--group", help="只查某一组")
|
|
57
|
+
cap.add_argument("--json", action="store_true")
|
|
58
|
+
st = sub.add_parser("status", help="链条视图:order → run → flow → receipt(只读,调子仓 CLI)")
|
|
59
|
+
st.add_argument("--json", action="store_true")
|
|
60
|
+
doc = sub.add_parser("doctor", help="总入口自检:各仓虚拟环境体检(委派 governance 能力)")
|
|
61
|
+
doc.add_argument("--repo", choices=MANAGED, help="只查一个仓")
|
|
62
|
+
doc.add_argument("--json", action="store_true")
|
|
63
|
+
lg = sub.add_parser("ledger", help="本机月账:status 看差 / tick 按日追加(幂等、只增不改)")
|
|
64
|
+
lg.add_argument("action", nargs="?", default="status",
|
|
65
|
+
choices=["status", "tick", "push", "install-automation"])
|
|
66
|
+
lg.add_argument("--month", help="YYYY-MM(默认本月)")
|
|
67
|
+
lg.add_argument("--host", help="机器标识(默认 hostname)")
|
|
68
|
+
lg.add_argument("--source", help="WorkBuddy 根(默认 ~/WorkBuddy 或 ALLIN_WORKBUDDY_ROOT)")
|
|
69
|
+
lg.add_argument("--ledger", help="账本路径(默认 docs/事实源/机器/<host>/月账/<月>.md)")
|
|
70
|
+
lg.add_argument("--dry-run", action="store_true", help="tick 只打印将追加的内容")
|
|
71
|
+
lg.add_argument("--max", type=int, default=31, help="tick 一次最多补几天(默认 31)")
|
|
72
|
+
lg.add_argument("--today", action="store_true", help="tick 也结当天(默认留到明天)")
|
|
73
|
+
lg.add_argument("--commit", action="store_true", help="tick 后本地提交(推送另见 ledger push)")
|
|
74
|
+
lg.add_argument("--all", action="store_true", help="只读汇总各机最新入账日期")
|
|
75
|
+
lg.add_argument("--json", action="store_true")
|
|
76
|
+
hs = sub.add_parser("hosts", help="四仓在 gitee/GitHub/PyPI 的位置与拓扑缺口(只读)")
|
|
77
|
+
hs.add_argument("--json", action="store_true")
|
|
78
|
+
ro = sub.add_parser("rollout", help="掌权比例状态机(判定/状态/锁全内嵌)")
|
|
79
|
+
ro.add_argument("--config", default="config/rollout.yml")
|
|
80
|
+
ro.add_argument("action", nargs="?", default="validate",
|
|
81
|
+
choices=["show", "advance", "guard", "reverse", "validate"])
|
|
82
|
+
ro.add_argument("--rule", help="被掌权的 rule_id(validate 不需要)")
|
|
83
|
+
ro.add_argument("--new-divergence", action="store_true")
|
|
84
|
+
ro.add_argument("--void-rate", type=float, default=0.0)
|
|
85
|
+
ro.add_argument("--ref-unavailable", action="store_true")
|
|
86
|
+
ro.add_argument("--json", action="store_true")
|
|
87
|
+
fl = sub.add_parser("flow", help="allin 全流程巡检(转发 auto_flow;绝不 push)")
|
|
88
|
+
fl.add_argument("--quick", action="store_true", help="只做同步核对 + 状态汇总")
|
|
89
|
+
fl.add_argument("--no-fetch", action="store_true", help="跳过 git fetch(离线)")
|
|
90
|
+
fl.add_argument("--with-platform", action="store_true", help="门禁额外跑 platform check/test/harness")
|
|
91
|
+
fl.add_argument("--json", action="store_true")
|
|
92
|
+
gd = sub.add_parser("guide", help="新人指南:构建 / 校验 / 跑命令(docs/guide)")
|
|
93
|
+
gd.add_argument("action", nargs="?", default="check",
|
|
94
|
+
choices=["build", "check", "run", "versions"])
|
|
95
|
+
gd.add_argument("--full", action="store_true", help="run 时包含慢命令")
|
|
96
|
+
gd.add_argument("--scope", choices=["repo", "cleanroom"], default="repo",
|
|
97
|
+
help="run 时读哪一册:repo=开发册,cleanroom=使用册")
|
|
98
|
+
return ap
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def subcommands() -> list[str]:
|
|
102
|
+
"""真实注册的子命令名(能力目录 C4 反查用)。
|
|
103
|
+
|
|
104
|
+
用鸭子类型找 `_SubParsersAction`(它的 `choices` 就是 `{名字: parser}`),
|
|
105
|
+
不去碰 `argparse._SubParsersAction` 这个私有名——它在 3.11 与 3.13 都存在,
|
|
106
|
+
但私有名不是契约,`choices` 是。
|
|
107
|
+
"""
|
|
108
|
+
for act in _build_parser()._actions: # noqa: SLF001
|
|
109
|
+
choices = getattr(act, "choices", None)
|
|
110
|
+
if isinstance(choices, dict):
|
|
111
|
+
return sorted(choices)
|
|
112
|
+
return []
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def main(argv: list[str] | None = None) -> int:
|
|
116
|
+
ap = _build_parser()
|
|
117
|
+
args = ap.parse_args(argv)
|
|
118
|
+
|
|
119
|
+
if not args.cmd:
|
|
120
|
+
from .home import main as home_main
|
|
121
|
+
return home_main(REPOS)
|
|
122
|
+
|
|
123
|
+
if args.cmd == "check":
|
|
124
|
+
from .check import run as check_run
|
|
125
|
+
return check_run(REPOS, as_json=args.json)
|
|
126
|
+
|
|
127
|
+
if args.cmd == "hosts":
|
|
128
|
+
from .hosts import main as hosts_main
|
|
129
|
+
return hosts_main(REPOS, ["--json"] if args.json else [])
|
|
130
|
+
|
|
131
|
+
if args.cmd == "flow":
|
|
132
|
+
from .flow import main as flow_main
|
|
133
|
+
return flow_main(REPOS, (["--quick"] if args.quick else [])
|
|
134
|
+
+ (["--no-fetch"] if args.no_fetch else [])
|
|
135
|
+
+ (["--with-platform"] if args.with_platform else [])
|
|
136
|
+
+ (["--json"] if args.json else []))
|
|
137
|
+
|
|
138
|
+
if args.cmd == "ledger":
|
|
139
|
+
from .ledger import main as ledger_main
|
|
140
|
+
return ledger_main(REPOS, args)
|
|
141
|
+
|
|
142
|
+
if args.cmd == "rollout":
|
|
143
|
+
from .rollout import main as rollout_main
|
|
144
|
+
return rollout_main([
|
|
145
|
+
"--config", args.config, args.action,
|
|
146
|
+
*(["--rule", args.rule] if args.rule else []),
|
|
147
|
+
*(["--new-divergence"] if args.new_divergence else []),
|
|
148
|
+
"--void-rate", str(args.void_rate),
|
|
149
|
+
*(["--ref-unavailable"] if args.ref_unavailable else []),
|
|
150
|
+
*(["--json"] if args.json else []),
|
|
151
|
+
])
|
|
152
|
+
|
|
153
|
+
if args.cmd == "audit":
|
|
154
|
+
from .audit import main as audit_main
|
|
155
|
+
return audit_main((["--trust", args.trust] if args.trust else []) +
|
|
156
|
+
(["--json"] if args.json else []) +
|
|
157
|
+
["--limit", str(args.limit)] +
|
|
158
|
+
(["--record"] if args.record else []) +
|
|
159
|
+
(["--freshness-days", str(args.freshness_days)]
|
|
160
|
+
if args.freshness_days else []) +
|
|
161
|
+
(["--ca-review-days", str(args.ca_review_days)]
|
|
162
|
+
if args.ca_review_days else []) +
|
|
163
|
+
(["--legacy"] if getattr(args, "legacy", False) else []))
|
|
164
|
+
|
|
165
|
+
if args.cmd == "guide":
|
|
166
|
+
from . import guide as guide_mod
|
|
167
|
+
return guide_mod.main([args.action]
|
|
168
|
+
+ (["--full"] if args.full else [])
|
|
169
|
+
+ ["--scope", args.scope])
|
|
170
|
+
|
|
171
|
+
if args.cmd == "wiring":
|
|
172
|
+
from .wiring import main as wiring_main
|
|
173
|
+
return wiring_main(["--json"] if args.json else [])
|
|
174
|
+
|
|
175
|
+
if args.cmd == "brief":
|
|
176
|
+
from .brief import main as brief_main
|
|
177
|
+
return brief_main((["--topic", args.topic] if args.topic else [])
|
|
178
|
+
+ ["--budget", str(args.budget)]
|
|
179
|
+
+ (["--json"] if args.json else []))
|
|
180
|
+
|
|
181
|
+
if args.cmd == "facts":
|
|
182
|
+
from .facts import main as facts_main
|
|
183
|
+
return facts_main((["--json"] if args.json else [])
|
|
184
|
+
+ (["--strict"] if args.strict else []))
|
|
185
|
+
|
|
186
|
+
if args.cmd == "kb":
|
|
187
|
+
from .kb import main as kb_main
|
|
188
|
+
return kb_main([args.action, "--budget", str(args.budget)]
|
|
189
|
+
+ (["--query", args.query] if args.query else [])
|
|
190
|
+
+ (["--json"] if args.json else []))
|
|
191
|
+
|
|
192
|
+
if args.cmd == "capabilities":
|
|
193
|
+
from .capabilities import main as cap_main
|
|
194
|
+
# 括号必须包住整个条件表达式:`A if c else [] + B` 的 `+` 只粘在 `[]` 上,
|
|
195
|
+
# 于是 `--check` 一旦为真,`--group` / `--json` 全被丢掉(实测:分组探活仍跑 59 条)。
|
|
196
|
+
return cap_main((["--check"] if args.check else [])
|
|
197
|
+
+ (["--group", args.group] if args.group else [])
|
|
198
|
+
+ (["--json"] if args.json else []))
|
|
199
|
+
|
|
200
|
+
if args.cmd == "status":
|
|
201
|
+
from .chain import render, snapshot
|
|
202
|
+
state = snapshot(REPOS / "govrule")
|
|
203
|
+
print(json.dumps(state, ensure_ascii=False, indent=2) if args.json else render(state))
|
|
204
|
+
return 0
|
|
205
|
+
|
|
206
|
+
report = assemble(REPOS)
|
|
207
|
+
|
|
208
|
+
if args.cmd == "doctor":
|
|
209
|
+
import subprocess
|
|
210
|
+
targets = [args.repo] if args.repo else list(MANAGED)
|
|
211
|
+
rc_all = 0
|
|
212
|
+
for name in targets:
|
|
213
|
+
root = REPOS / name
|
|
214
|
+
py = root / ".venv" / ("Scripts/python.exe" if sys.platform == "win32" else "bin/python")
|
|
215
|
+
exe = str(py) if py.is_file() else sys.executable
|
|
216
|
+
proc = subprocess.run(
|
|
217
|
+
[exe, "-m", "allin_governance", "venv", "check",
|
|
218
|
+
"--root", str(root)] + (["--json"] if args.json else []),
|
|
219
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
220
|
+
out = (proc.stdout or "") + (proc.stderr or "")
|
|
221
|
+
if "No module named allin_governance" in out or "invalid choice: 'venv'" in out:
|
|
222
|
+
probe = subprocess.run([exe, "-c", "import sys; print(sys.version.split()[0])"],
|
|
223
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
224
|
+
pip = subprocess.run([exe, "-m", "pip", "--version"],
|
|
225
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
226
|
+
ok = probe.returncode == 0
|
|
227
|
+
print(f"== {name}: {'fallback' if ok else 'BROKEN'}(该仓无公共核,仅解释器/pip)"
|
|
228
|
+
f" python={(probe.stdout or '-').strip()} pip={'ok' if pip.returncode == 0 else 'MISSING'}")
|
|
229
|
+
rc_all = rc_all or (0 if ok else 1)
|
|
230
|
+
continue
|
|
231
|
+
print(f"== {name} (exit {proc.returncode})")
|
|
232
|
+
print(out.rstrip())
|
|
233
|
+
rc_all = rc_all or proc.returncode
|
|
234
|
+
return rc_all
|
|
235
|
+
|
|
236
|
+
if args.cmd == "entry" and args.list:
|
|
237
|
+
for row in report["repos"]:
|
|
238
|
+
state = "OK" if row["ok"] else "MISSING/INVALID"
|
|
239
|
+
print(f"{row['repo']:<20} {state:<16} {(row.get('contract') or {}).get('entrypoint', '-')}")
|
|
240
|
+
return 0 if report["ok"] else 1
|
|
241
|
+
|
|
242
|
+
if args.cmd == "entry":
|
|
243
|
+
row = next(r for r in report["repos"] if r["repo"] == args.repo)
|
|
244
|
+
if not row["ok"]:
|
|
245
|
+
print(f"CONTRACT FAIL: {args.repo} {row.get('reason') or row.get('problems')}", file=sys.stderr)
|
|
246
|
+
return 2
|
|
247
|
+
c = row["contract"]
|
|
248
|
+
print(f"[{args.repo}] role={c.get('role', '-')} entry={c.get('entrypoint', '-')}")
|
|
249
|
+
return 0
|
|
250
|
+
|
|
251
|
+
for row in report["repos"]:
|
|
252
|
+
if row["ok"]:
|
|
253
|
+
print(f"OK {row['repo']}: {row['contract']['role']}")
|
|
254
|
+
else:
|
|
255
|
+
print(f"FAIL {row['repo']}: {row.get('reason') or row.get('problems')}")
|
|
256
|
+
if not report["ok"]:
|
|
257
|
+
print(f"== agent verify: 契约版本 {report['contract_versions']},存在不合规仓", file=sys.stderr)
|
|
258
|
+
return 1
|
|
259
|
+
print(f"== agent verify: 三仓契约齐备(entry v{report['contract_versions']['entry']})")
|
|
260
|
+
return 0
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
if __name__ == "__main__":
|
|
264
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""装配:把「三个被治理仓 + 各自契约」装成一张可校验的表。
|
|
2
|
+
|
|
3
|
+
借鉴 superengine:装配期校验(fail-loud),运行期只读装配结果。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .bridges import contract_state
|
|
11
|
+
from .contracts import CONTRACT_VERSIONS, SUPPORTED_ENTRY
|
|
12
|
+
|
|
13
|
+
MANAGED = ("allin", "allin-governance", "govrule")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def assemble(repos_root: Path) -> dict:
|
|
17
|
+
rows = []
|
|
18
|
+
for name in MANAGED:
|
|
19
|
+
state = contract_state(Path(repos_root) / name, Path(repos_root) / "govrule")
|
|
20
|
+
rows.append({"repo": name, **state})
|
|
21
|
+
ok = all(r["ok"] for r in rows)
|
|
22
|
+
return {
|
|
23
|
+
"contract_versions": dict(CONTRACT_VERSIONS),
|
|
24
|
+
"supported_entry": list(SUPPORTED_ENTRY),
|
|
25
|
+
"ok": ok,
|
|
26
|
+
"repos": rows,
|
|
27
|
+
}
|