kigumi 0.1.0__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.
- kigumi-0.1.0/.gitignore +9 -0
- kigumi-0.1.0/AGENTS.md +30 -0
- kigumi-0.1.0/CHANGELOG.md +34 -0
- kigumi-0.1.0/DESIGN.md +285 -0
- kigumi-0.1.0/LICENSE +21 -0
- kigumi-0.1.0/PKG-INFO +114 -0
- kigumi-0.1.0/README.md +90 -0
- kigumi-0.1.0/README.zh-CN.md +77 -0
- kigumi-0.1.0/docs/adoption.md +709 -0
- kigumi-0.1.0/docs/contracts/cache-key.md +66 -0
- kigumi-0.1.0/docs/contracts/checkpoint.md +53 -0
- kigumi-0.1.0/docs/contracts/determinism.md +62 -0
- kigumi-0.1.0/docs/contracts/guards.md +54 -0
- kigumi-0.1.0/docs/contracts/retention.md +58 -0
- kigumi-0.1.0/docs/reviews/2026-07-13-design-review.md +71 -0
- kigumi-0.1.0/kigumi/__init__.py +116 -0
- kigumi-0.1.0/kigumi/_execution.py +86 -0
- kigumi-0.1.0/kigumi/artifacts.py +68 -0
- kigumi-0.1.0/kigumi/bench.py +142 -0
- kigumi-0.1.0/kigumi/blobs.py +115 -0
- kigumi-0.1.0/kigumi/calling.py +440 -0
- kigumi-0.1.0/kigumi/cli.py +533 -0
- kigumi-0.1.0/kigumi/config.py +103 -0
- kigumi-0.1.0/kigumi/dag.py +2043 -0
- kigumi-0.1.0/kigumi/enforce.py +255 -0
- kigumi-0.1.0/kigumi/evals.py +161 -0
- kigumi-0.1.0/kigumi/inspect.py +172 -0
- kigumi-0.1.0/kigumi/optimize.py +538 -0
- kigumi-0.1.0/kigumi/prompt.py +240 -0
- kigumi-0.1.0/kigumi/py.typed +0 -0
- kigumi-0.1.0/kigumi/repair.py +228 -0
- kigumi-0.1.0/kigumi/slots.py +160 -0
- kigumi-0.1.0/kigumi/store.py +304 -0
- kigumi-0.1.0/kigumi/testing.py +317 -0
- kigumi-0.1.0/kigumi/transport.py +297 -0
- kigumi-0.1.0/kigumi/views.py +469 -0
- kigumi-0.1.0/pyproject.toml +58 -0
- kigumi-0.1.0/tests/__init__.py +0 -0
- kigumi-0.1.0/tests/goldens/prompt_components.txt +17 -0
- kigumi-0.1.0/tests/goldens/schema_format.txt +23 -0
- kigumi-0.1.0/tests/test_artifacts.py +37 -0
- kigumi-0.1.0/tests/test_bench.py +209 -0
- kigumi-0.1.0/tests/test_blobs.py +33 -0
- kigumi-0.1.0/tests/test_calling.py +370 -0
- kigumi-0.1.0/tests/test_cli.py +522 -0
- kigumi-0.1.0/tests/test_concurrency.py +149 -0
- kigumi-0.1.0/tests/test_config.py +63 -0
- kigumi-0.1.0/tests/test_dag.py +2889 -0
- kigumi-0.1.0/tests/test_enforce.py +132 -0
- kigumi-0.1.0/tests/test_evals.py +107 -0
- kigumi-0.1.0/tests/test_execution.py +70 -0
- kigumi-0.1.0/tests/test_inspect.py +122 -0
- kigumi-0.1.0/tests/test_optimize.py +412 -0
- kigumi-0.1.0/tests/test_prompt.py +162 -0
- kigumi-0.1.0/tests/test_repair.py +218 -0
- kigumi-0.1.0/tests/test_slots.py +178 -0
- kigumi-0.1.0/tests/test_store.py +56 -0
- kigumi-0.1.0/tests/test_testing.py +311 -0
- kigumi-0.1.0/tests/test_transport.py +324 -0
kigumi-0.1.0/.gitignore
ADDED
kigumi-0.1.0/AGENTS.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# kigumi coding-agent 指南
|
|
2
|
+
|
|
3
|
+
kigumi 是给 LLM 内容流水线提供确定性调用、可验证产物与 DAG 编排边界的 Python 库;
|
|
4
|
+
修改时优先保护缓存、重放和人工审批的可观测性。
|
|
5
|
+
|
|
6
|
+
常用命令:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
uv run pytest -q
|
|
10
|
+
uv run ruff check .
|
|
11
|
+
uv run ruff format --check .
|
|
12
|
+
uv run kigumi trace <run_id>
|
|
13
|
+
uv run kigumi call <key_prefix> --field response
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`kigumi` CLI 负责项目运维(guard、runs、approve、diff、gc 等);`dag.cli()` 负责已注册图的 check、plan、graph、explain、describe。
|
|
17
|
+
|
|
18
|
+
硬规矩:
|
|
19
|
+
|
|
20
|
+
- 改动任一缓存键成分就是缓存换族,必须同步更新 `CHANGELOG.md`。
|
|
21
|
+
- `raw-llm-ok` 与 `raw-io-ok` 豁免都必须写清理由,二者不得互相代替。
|
|
22
|
+
- 行为变更先写会失败的测试,再实现到测试转绿;不要以文档替代回归测试。
|
|
23
|
+
- 不绕过 `canonical_json`、`artifacts.sha`、节点声明和审批 payload 绑定。
|
|
24
|
+
|
|
25
|
+
文档地图:
|
|
26
|
+
|
|
27
|
+
- [DESIGN.md](DESIGN.md) 说明设计哲学、边界和止损线。
|
|
28
|
+
- [docs/adoption.md](docs/adoption.md) 说明接入方式与使用约定。
|
|
29
|
+
- [docs/contracts/](docs/contracts/) 是可验证不变式的权威文本;修改实现时先读对应契约。
|
|
30
|
+
- [CHANGELOG.md](CHANGELOG.md) 记录面向使用者的发布变化,不在此重复细节。
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# 变更日志
|
|
2
|
+
|
|
3
|
+
本项目遵循 Keep a Changelog 体例记录面向使用者的变更。
|
|
4
|
+
|
|
5
|
+
## [未发布]
|
|
6
|
+
|
|
7
|
+
### 变更
|
|
8
|
+
|
|
9
|
+
- `kigumi` 键成分改为联合覆盖 `prompt.py` 与 `repair.py` 的 prompt 生成字节,并以
|
|
10
|
+
`CACHE_SCHEMA` 管理显式缓存语义版本;**本版本导致 L3 节点缓存全量失效(键成分
|
|
11
|
+
`kigumi` 换构)。**
|
|
12
|
+
- 执行信封收敛至私有 `kigumi._execution`,并公开 `observe()` 以收集上下文内的
|
|
13
|
+
`LLMCaller` 调用;差分探针已验证键成分与 sidecar 字节不变。
|
|
14
|
+
- 新增 `bench` / `Variant`:以唯一现状对照和显式假设约束结构切法探索,产出可归档的
|
|
15
|
+
变体×样例×种子评估报告、样例级 judgments 与调用成本;不包含胜负裁决或自动接线,
|
|
16
|
+
**不改变任何缓存键成分。**
|
|
17
|
+
- 新增 coding-agent 可观测性 CLI:`kigumi trace` 从 run 直接联接节点/map 项、键成分、
|
|
18
|
+
LLM 调用与 L1 载荷;`kigumi call` 用 key 前缀读取完整输入输出;`kigumi diff` 增加
|
|
19
|
+
键成分差分与 `--json`。新增独立的 `llm_cache_dir` 配置,默认
|
|
20
|
+
`artifacts/_llm`;**不改变任何缓存键或 L1 载荷结构。**
|
|
21
|
+
- `2174f73`:raw-I/O 守卫补齐注册、项目扫描和测试三环;run 目录改为数字感知排序;
|
|
22
|
+
并发失败保留其余失败附注。真实请求标记统一为 `live`,旧 `kigumi_live` 已移除,
|
|
23
|
+
运行 live 测试必须显式设置 `KIGUMI_LIVE=1`。
|
|
24
|
+
- `4ac2b60`:四种 DAG 渲染迁入 `kigumi.views`,运行态渲染数据提取为共用边界,
|
|
25
|
+
缩小 `dag.py` 的职责面。
|
|
26
|
+
- `db87336`:节点键成分收敛到 `Dag._key_components` 单点;run、plan、explain
|
|
27
|
+
分别注入已解析的上游结果,并以差分探针确认键字节不变。
|
|
28
|
+
- `1e40b20`:`libs` 哈希改为剥离 docstring/注释后的 AST 归一化;语法残破文件退回
|
|
29
|
+
原文哈希。**这是 `libs` 成分的缓存换族,所有既有节点缓存必须视为失效。**
|
|
30
|
+
|
|
31
|
+
### 移除
|
|
32
|
+
|
|
33
|
+
- 移除四个兼容入口:`from kigumi.dag import approve_checkpoint` 等存储层转发、
|
|
34
|
+
`FakeTransport.calls`、点分顶层键解析,以及私有 `_next_run_id`。
|
kigumi-0.1.0/DESIGN.md
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# kigumi 设计文档
|
|
2
|
+
|
|
3
|
+
木组(kigumi):无钉咬合的木工工艺。本库是 LLM 内容流水线的承重结构层——
|
|
4
|
+
项目(屋顶)与模型(立柱)之间靠精确咬合连接,不合榫就打回重做。
|
|
5
|
+
|
|
6
|
+
## 定位
|
|
7
|
+
|
|
8
|
+
给"用 coding agent 开发 LLM 流水线"的场景提供地基:上下文注入、结构化校验与
|
|
9
|
+
修复、确定性重放、DAG 编排,以及一套让规矩自动执行的工具链。
|
|
10
|
+
|
|
11
|
+
主要用户是 coding agent:agent 的行为由环境反馈塑形,库必须把"正道"做成
|
|
12
|
+
阻力最小的路径,把"歪路"做成走不通的路径。
|
|
13
|
+
|
|
14
|
+
## 起源与实证依据
|
|
15
|
+
|
|
16
|
+
抽取自三个实战项目的共同模式(comic-script-rewrite / drama2script /
|
|
17
|
+
screen-writer),干净重写,不搬运代码。旧代码注释里的每条 live 教训
|
|
18
|
+
(缓存不动点、回显截断不收敛、extra_forbidden 剥壳、键序漂移换缓存族等)
|
|
19
|
+
转化为本库的 RED 测试用例,而非复制实现。
|
|
20
|
+
|
|
21
|
+
已被否决的路线,不再重走:
|
|
22
|
+
- 重基建编排(Temporal/server/DB):script-factory 实验已证死路。
|
|
23
|
+
- 纯 vendored 模板:漂移成本实证过高(screen-writer 三个修复环变体)。
|
|
24
|
+
- 采用现成 DAG 库:2026-07 调研结论,无一同时提供内容寻址缓存(含代码
|
|
25
|
+
哈希)+ 人工检查点 + 确定性重放;且 helper 哈希与 prompt 文件哈希
|
|
26
|
+
是自研 runtime 独有的领先点。
|
|
27
|
+
|
|
28
|
+
## 包结构
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
kigumi/
|
|
32
|
+
├── _execution.py # 私有执行信封:缓存、审批、物化与 sidecar
|
|
33
|
+
├── __init__.py # 顶层公开 API
|
|
34
|
+
├── artifacts.py # 原子写入、规范 JSON 与 sidecar 基础件
|
|
35
|
+
├── blobs.py # 内容寻址二进制仓
|
|
36
|
+
├── calling.py # L1 调用:内容寻址缓存 / dry-run 熔断 / 溯源 / 预算记账
|
|
37
|
+
├── cli.py # 项目运维 CLI:kigumi
|
|
38
|
+
├── config.py # 项目配置、路径发现与环境装载
|
|
39
|
+
├── dag.py # L3 编排:@node / foreach / checkpoint / 节点缓存
|
|
40
|
+
├── enforce.py # 守卫检查器
|
|
41
|
+
├── evals.py # 评估与进化层的指标、评委与门禁
|
|
42
|
+
├── optimize.py # 评估与进化层的提示词候选演化
|
|
43
|
+
├── prompt.py # L1.5 拼接:inject / 严格渲染 / Section / schema 格式段 / clip
|
|
44
|
+
├── repair.py # L2 修复环:repair_loop + call_validated;rebuild/continue 双模式
|
|
45
|
+
├── slots.py # 跨进程限流与自适应容量
|
|
46
|
+
├── store.py # 存储布局:run、缓存、归档、物化、审批与 GC
|
|
47
|
+
├── testing.py # pytest 插件(面向用户项目)
|
|
48
|
+
└── transport.py # L0 传输:complete(messages);LiteLLM 默认实现,stdlib 后备
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
依赖:pydantic 为内核依赖;litellm 为 optional extra(`kigumi[litellm]`,
|
|
52
|
+
transport 已惰性导入,stdlib 后备保证无 extra 也可用)。L0–L2 不依赖 L3;
|
|
53
|
+
命令式链项目只取底层。pytest11 入口在非 kigumi 项目中必须严格 no-op。
|
|
54
|
+
|
|
55
|
+
## 项目配置约定(`[tool.kigumi]`)
|
|
56
|
+
|
|
57
|
+
库装进 site-packages 后的发现问题统一由项目 pyproject 的 `[tool.kigumi]` 回答,
|
|
58
|
+
全部有默认值,零配置可跑:
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
[tool.kigumi]
|
|
62
|
+
prompts_dir = "prompts" # 严格渲染与 dry-render 测试的模板根
|
|
63
|
+
artifacts_dir = "artifacts" # runs/ 与缓存的根(cache 在其下 _cache/)
|
|
64
|
+
source_dirs = ["nodes", "lib"] # helper 哈希与 guard 扫描的目录集(=同一集合)
|
|
65
|
+
env_file = ".env" # KIGUMI_MODEL_DEFAULT / KIGUMI_MODEL_PRO / api keys
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`kigumi runs list` / `diff` / `gc` / guard / dry-render 全部从这份配置解析路径。
|
|
69
|
+
各层不得自带另一套发现逻辑。
|
|
70
|
+
|
|
71
|
+
## 各层要点
|
|
72
|
+
|
|
73
|
+
### L0 transport
|
|
74
|
+
- 唯一接口 `complete(messages, model, **params) -> Response`
|
|
75
|
+
(text / usage / finish_reason / reasoning / model),外加
|
|
76
|
+
`resolve(model) -> str`(别名 → 具体模型名,供 L1 构缓存键)。
|
|
77
|
+
- 默认实现走 LiteLLM;纯标准库 OpenAI 兼容实现作后备。自愈策略共享,不复制。
|
|
78
|
+
- **params 契约(归一化词汇表,冻结于 P1.1)**:`json_mode=True` →
|
|
79
|
+
`response_format={"type":"json_object"}`;`system="…"` → 前插 system 消息;
|
|
80
|
+
`reasoning_effort` 透传;其余透传。词汇表进缓存键语义,事后扩充只增不改。
|
|
81
|
+
- 故障自愈(全部有界):429/5xx 指数退避、`finish_reason=length` 且调用方
|
|
82
|
+
显式设了 max_tokens → 加倍重试(至多 2 次);未设 max_tokens 的截断 →
|
|
83
|
+
抛 TruncatedResponseError(静默返回残文即下游投毒);空响应 → 退避重试,
|
|
84
|
+
耗尽即抛 EmptyResponseError,**绝不返回空文本**。
|
|
85
|
+
- StdlibTransport 必须带默认超时(300s);所有重试路径都有退避 sleep。
|
|
86
|
+
- 多档模型别名(default/pro)映射到不同模型/供应商,节点只说档位。
|
|
87
|
+
|
|
88
|
+
### L1 calling
|
|
89
|
+
- `LLMCaller(transport, cache_dir, seed, budget, dry)`,依赖注入,测试可替换。
|
|
90
|
+
- 内容寻址缓存:键 = messages + **resolved model**(经 transport.resolve,
|
|
91
|
+
换 .env 模型 = 换缓存键,防跨模型回放旧答案)+ params + seed;
|
|
92
|
+
撕裂缓存按 miss;**空响应拒入缓存**(transport 违约时的第二道闸)。
|
|
93
|
+
- 溯源 meta 同记 model_alias 与 resolved model;**先记 calls 再 budget.record**
|
|
94
|
+
(超限异常不得吞掉最贵那次调用的溯源)。
|
|
95
|
+
- dry-run 熔断:到达真调用即抛错;缓存命中时不熔断继续走(特性,非 bug:
|
|
96
|
+
dry-run 的定义是"不发新请求",不是"不消费历史")。
|
|
97
|
+
- 线程安全:Budget 加锁;calls 加锁;同键 in-flight 去重(并发同键只打一次)。
|
|
98
|
+
- seed 仅是缓存命名空间,不传给 provider,不承诺采样可复现。
|
|
99
|
+
- 大块内容按引用:消息体里的大负载(视频/图像 base64)以
|
|
100
|
+
`{"kigumi_file": 路径}` 内容件表示,缓存键取文件内容哈希,缓存 payload
|
|
101
|
+
存引用不存字节(接口 P1.1 预留,实现随 P6a)。
|
|
102
|
+
- 跨进程限流(fcntl.flock 请求槽,多进程共享 provider 配额)归 P6a。
|
|
103
|
+
- token 预算记账,超限中止 run。
|
|
104
|
+
|
|
105
|
+
### L1.5 prompt(七能力)
|
|
106
|
+
1. `inject(obj)`:材料注入唯一入口——强制 sort_keys、稳定缩进、统一围栏
|
|
107
|
+
与标题定界。保证同数据 → 逐字节同片段(bf06 键序漂移事故的结构性解)。
|
|
108
|
+
有序数据必须用 list;检测到数字串键的 dict 时告警(JSON round-trip 后
|
|
109
|
+
int 键变 str,sort_keys 按字典序 1,10,11,…,2 排乱剧集/场次)。
|
|
110
|
+
2. 严格渲染:prompts/*.md + {{槽位}};缺槽/多槽都报错;模板保持声明式,
|
|
111
|
+
条件逻辑一律在 Python。
|
|
112
|
+
3. `Section`:具名条件段,值为 None 整段(含标题定界)不渲染,
|
|
113
|
+
消灭"为 null 则跳过"式自然语言指令。
|
|
114
|
+
4. schema → 格式说明段:从 pydantic model(含 Field description)自动生成
|
|
115
|
+
输出格式段与示例,prompt 与校验器单一真相源;"只输出 JSON 不解释"类
|
|
116
|
+
固定措辞收编为唯一常量。
|
|
117
|
+
5. 裁剪:`clip(text, limit, boundary="line|sentence")` 安全边界截断;
|
|
118
|
+
领域摘要函数不进库(约定:返回 str 即可作槽值)。
|
|
119
|
+
6. `render_items(items, format="json|bullets")`:列表渲染(table 无使用
|
|
120
|
+
实证,暂缓;有第二个项目要再加)。
|
|
121
|
+
7. 修复段措辞常量(供 L2 引用,全库唯一一份)。
|
|
122
|
+
|
|
123
|
+
贯穿不变式:同输入 → 逐字节同输出(缓存键与确定性重放压在此上)。
|
|
124
|
+
公共 prompt 成分(措辞常量、schema 格式段模板、inject 围栏)以 golden
|
|
125
|
+
snapshot 测试锁字节;任何改动 = 全项目缓存换族,CHANGELOG 必须标注
|
|
126
|
+
"本版本导致缓存失效"。
|
|
127
|
+
|
|
128
|
+
截断三铁律:
|
|
129
|
+
1. 库永不默认截断;上限必须显式写在调用方。
|
|
130
|
+
2. 截断永不无声:prompt 内自动标注"(已截断:原文 N 字,注入前 M 字)",
|
|
131
|
+
事件记入 sidecar `clips: [{slot, from, to}]`。
|
|
132
|
+
3. 修复环默认不截:continue 模式输出天然在对话历史;rebuild 模式
|
|
133
|
+
echo 默认不限。
|
|
134
|
+
|
|
135
|
+
### L2 repair
|
|
136
|
+
- `repair_loop(caller, messages, validate, *, reminder=None,
|
|
137
|
+
mode="rebuild"|"continue", max_repairs=2, sink=None, on_event=None, **params)`。
|
|
138
|
+
- **默认 rebuild**(三个源项目实证过的形态);continue(输出作 assistant
|
|
139
|
+
消息接回对话再追加纠正指令,免回显、前缀缓存友好)标记为实验特性,
|
|
140
|
+
经磁带机 + L3 统计对比跑赢后再转正——库 API 决策同样吃 RED/GREEN 纪律。
|
|
141
|
+
已知风险:失败历史锚定坏输出;部分 OpenAI 兼容代理对
|
|
142
|
+
assistant 消息 + response_format 组合不可靠。
|
|
143
|
+
- validate(raw) 抛 ValueError 即触发修复,返回值即结果——pydantic 解析、
|
|
144
|
+
文本解析+门禁、组装+linter 全部套此签名。
|
|
145
|
+
- 固化学费:轮次编号进 prompt(防缓存不动点)、原样重交检测(stuck)、
|
|
146
|
+
失败现场落盘(经显式 sink 参数,L2 不依赖 L3 的目录结构)、修复事件记录。
|
|
147
|
+
- `call_validated(caller, prompt, model_cls, extra_check=None, ...)`:
|
|
148
|
+
JSON+pydantic 特化 = repair_loop + 确定性剥壳(extra_forbidden 机械删键、
|
|
149
|
+
strict=False 控制字符容错)。
|
|
150
|
+
|
|
151
|
+
### 评估与进化(evals / optimize)
|
|
152
|
+
- `evals.py` 与 `optimize.py` 是库内的评估与进化层,不是独立产品;它们骑在
|
|
153
|
+
L1 caller 之上,评委调用天然复用 L1 缓存。
|
|
154
|
+
- optimize 的 `(候选, 样例)` 判分状态文件只服务断点续跑,不绕过 L1;胜出文本
|
|
155
|
+
不自动落盘,须经人工审阅后才进入 `prompts/`。
|
|
156
|
+
- `bench.py` 为同一流水线的结构切法生产变体×样例×种子的可归档证据,不裁决胜负,
|
|
157
|
+
不自动接线;每个变体独立持有 caller,固定种子仍可复用 L1。
|
|
158
|
+
|
|
159
|
+
### L3 dag
|
|
160
|
+
- 自研 runtime 为底座(screen-writer 771 行思路,干净重写),吸收:
|
|
161
|
+
- redun `File`:外部文件声明为输入、内容进缓存键(prompts_hash 的推广);
|
|
162
|
+
- Hamilton code_version:源码哈希忽略 docstring/注释;
|
|
163
|
+
- LangGraph interrupt():检查点恢复语义(批准数据注回节点);
|
|
164
|
+
- Metaflow foreach:一等公民动态 fan-out 原语(替代 f-string 拼节点名
|
|
165
|
+
+循环闭包注册;episode_chain 的既知压力点)。
|
|
166
|
+
- 缓存键 = 节点源码哈希 + helper/库哈希(source_dirs)+ 上游产物哈希
|
|
167
|
+
+ prompt 文件哈希 + 参数 + **kigumi prompt 相关模块哈希 + pydantic 版本**
|
|
168
|
+
(库现在拥有 prompt 字节的生成权:inject 围栏/格式段/措辞常量变了,
|
|
169
|
+
节点键必须失效,否则升级库后回放陈旧渲染的产物)。
|
|
170
|
+
- 文件物化是一等能力:artifact 带 `files: {相对路径: 内容}` 时落盘到
|
|
171
|
+
项目目录,缓存命中也执行(subprocess 门禁靠磁盘文件工作;
|
|
172
|
+
screen-writer _materialize 的收编硬依赖)。另留 post-node hook。
|
|
173
|
+
- 检查点与 artifact 键的绑定声明式化(旧代码为硬编码)。
|
|
174
|
+
- 链式上文显式化为节点输入(禁止节点闭包携带跨迭代可变状态)。
|
|
175
|
+
- 新增:`diff <runA> <runB>`、缓存 GC(--keep-last N)、历史归档、
|
|
176
|
+
人工检查点、token 预算。
|
|
177
|
+
- **止损线**:若第二个接入项目对 dag 提出 _materialize 级别的特化且
|
|
178
|
+
post-node hook 接不住,dag 退回 vendored 模板,库只保 L0–L2。
|
|
179
|
+
此线现在写下,将来才有勇气执行。
|
|
180
|
+
|
|
181
|
+
### 存储与容量
|
|
182
|
+
- `store.py` 是存储布局层,依赖方向固定为 `dag -> store`;它管理 run、节点缓存、
|
|
183
|
+
归档、物化、审批与 GC,不能反向理解图或调度。
|
|
184
|
+
- `blobs.py` 是内容寻址二进制仓;`slots.py` 负责跨进程限流与自适应容量。
|
|
185
|
+
|
|
186
|
+
### enforce(守卫三环)
|
|
187
|
+
1. 注册环:@node 注册时 AST 检查节点函数体,是精确且权威的边界;循环内裸调
|
|
188
|
+
`.call(`/`.llm(` 或节点体直接 raw-io,且无对应理由豁免 → 拒绝注册。
|
|
189
|
+
**边界诚实声明**:运行环只覆盖 dag 项目;命令式项目(如 drama2script)
|
|
190
|
+
主责在测试环与提交环。
|
|
191
|
+
2. 测试环:pytest 插件自动收集守卫检查 + 全模板 dry-render 测试;
|
|
192
|
+
**新增豁免注释即告警**(waiver 是 agent 的自助逃生通道,必须留痕上报)。
|
|
193
|
+
3. 提交环:`kigumi init` 安装 git hook(core.hooksPath=.githooks,
|
|
194
|
+
pre-commit 跑 `uv run kigumi guard --changed`);guard 输出含 waiver 清单。
|
|
195
|
+
|
|
196
|
+
source_dirs 级扫描只属于 dag check、测试环与提交环。raw-io 在这些环节用
|
|
197
|
+
`@*.node/map/scan/foreach(...)` 装饰器作启发式过滤,只扫匹配函数的最外层函数体:
|
|
198
|
+
这避免 helper 合法读文件的误报,但可能漏报;注册环仍是兜底。
|
|
199
|
+
|
|
200
|
+
### testing(pytest 插件,面向用户项目)
|
|
201
|
+
- 磁带机夹具:FakeTransport 录制/回放——真实模型的畸形输出(幻觉多余键、
|
|
202
|
+
控制字符、原样重交)打真实修复环代码,消灭 fixture 喂养测试的结构性盲区。
|
|
203
|
+
- dry-render 全覆盖:prompts_dir 下每模板自动生成槽位可填满测试。
|
|
204
|
+
- L3 活体采样:@pytest.mark.live + 预算夹具(超限 skip 不烧钱)。
|
|
205
|
+
- `live` 是唯一的真实请求标记:插件激活时还要求 `KIGUMI_LIVE=1`,再与
|
|
206
|
+
`skip_unless_env` 的凭证门叠加,形成显式双确认。
|
|
207
|
+
- 守卫即测试(三环之二)。
|
|
208
|
+
|
|
209
|
+
### 格式化/质量
|
|
210
|
+
复用 ruff(lint+format),脚手架交付 [tool.ruff] 预设;不自造工具。
|
|
211
|
+
|
|
212
|
+
### 契约层
|
|
213
|
+
可验证不变式的权威文本在 [docs/contracts/](docs/contracts/);这里保留设计哲学、模块边界与
|
|
214
|
+
止损线,不复制可由测试锁定的实现细节。改动缓存键、确定性字节、守卫、检查点或保留语义时,
|
|
215
|
+
必须先更新对应契约和锁定测试,再记录发布影响。
|
|
216
|
+
|
|
217
|
+
### CLI
|
|
218
|
+
```
|
|
219
|
+
kigumi init # 脚手架:prompts/ nodes/ tests/ + hooks + ruff/pytest 预设
|
|
220
|
+
kigumi guard [--changed]
|
|
221
|
+
kigumi doctor # API key / 缓存目录 / hooks 体检
|
|
222
|
+
kigumi runs list / show <id>
|
|
223
|
+
kigumi diff <runA> <runB>
|
|
224
|
+
kigumi gc [--keep-last N]
|
|
225
|
+
kigumi render <node> --dry
|
|
226
|
+
```
|
|
227
|
+
`kigumi`(cli.py) 是不需要图注册表的项目运维入口:init、guard、doctor、render、runs、
|
|
228
|
+
approve、diff、gc。`dag.cli()` 是需要注册表的图检查入口:check、plan、graph、explain、
|
|
229
|
+
describe;两者不互相代替。
|
|
230
|
+
`kigumi init` 是 developing-ai-workflows skill 的落地点:新项目起步从
|
|
231
|
+
"复制模板"改为"跑 init"。
|
|
232
|
+
|
|
233
|
+
## 构建顺序
|
|
234
|
+
|
|
235
|
+
1. 仓库 + L0/L1 + artifacts ✅(commit b42bc1b)
|
|
236
|
+
1.1 评审修正包:空响应耗尽即抛+拒缓存、resolved model 进缓存键、
|
|
237
|
+
params 契约、Stdlib 超时、溯源先于记账、线程安全+in-flight 去重、
|
|
238
|
+
litellm 降 extra、File 引用接口预留
|
|
239
|
+
2. prompt.py 七能力 + 截断三铁律 + golden snapshot(先于 repair:
|
|
240
|
+
修复段措辞常量住在这里)
|
|
241
|
+
3. repair.py 双模式(默认 rebuild),验收关 = 在 worktree 里真实移植
|
|
242
|
+
screen-writer 最难的一个循环(lint_fix,含跨轮事件累积与按错误类型
|
|
243
|
+
定制指令),纸面对齐不算过关
|
|
244
|
+
4. enforce.py(纯函数形态 AST 检查器)+ testing.py(磁带机/dry-render);
|
|
245
|
+
与 @node 的接线留给 P5,规格写明防止造假注册表
|
|
246
|
+
5. dag.py(foreach/diff/gc/物化/检查点绑定)+ cli.py + 运行环接线
|
|
247
|
+
6. 前置 6a:跨进程限流 + File 引用实现 + 并发路径验证;然后 drama2script
|
|
248
|
+
试点、screen-writer 收编、skill 更新(不只加红旗判例——skill
|
|
249
|
+
"frameworks are banned" 不变量须重写为"物理层用库,编排逻辑必须
|
|
250
|
+
一屏可读",否则遵循 skill 的 agent 会系统性抵触本库)
|
|
251
|
+
|
|
252
|
+
每步配套:旧项目 live 教训 → 本库 RED 用例,先红后绿。
|
|
253
|
+
每包审查新增机械动作:对照旧实现(llm_client.py / runtime.py /
|
|
254
|
+
progressive_annotation_pipeline.py)的 docstring 与注释提取能力清单逐条
|
|
255
|
+
勾兑——P1 曾带着 4 处对旧实现的退化过审,教训在此。
|
|
256
|
+
|
|
257
|
+
## 修订记录
|
|
258
|
+
|
|
259
|
+
- 2026-07-13 新增 segment bench:以假设和唯一现状对照约束结构探索,生成稳定的
|
|
260
|
+
变体×样例×种子证据报告与按变体归集的调用成本;裁决和接线始终留在库外。
|
|
261
|
+
|
|
262
|
+
- 2026-07-13 新增 agent 可观测层:`inspect.py` 只读联接 run sidecar 与 L1 载荷,
|
|
263
|
+
不导入 DAG、不发请求、不触碰缓存键成分;CLI 因而可完整追溯节点、map 项和调用证据。
|
|
264
|
+
|
|
265
|
+
- 2026-07-13 新增契约层:缓存键、确定性字节、守卫环与豁免、检查点审批、缓存与产物保留
|
|
266
|
+
的可验证不变式统一收敛至 `docs/contracts/`;本设计文档只保留边界、哲学和止损线。
|
|
267
|
+
|
|
268
|
+
- 2026-07-13 libs 哈希对齐 code_version 原则:source_dirs 模块统一剥
|
|
269
|
+
docstring/注释后按 AST 哈希,语法残破文件退回原文;此变更让 libs 成分
|
|
270
|
+
全体换族,既有节点缓存一次性失效(greenfield 内无外部用户,直接执行)。
|
|
271
|
+
|
|
272
|
+
- 2026-07-13 第一轮整改:包结构补齐为实际 16 个模块;明确 evals/optimize、
|
|
273
|
+
store/blobs/slots 的边界;守卫三环如实区分注册环与 source_dirs 启发式 raw-io
|
|
274
|
+
扫描;记录双 CLI 分工与 `live` 标记统一为双确认门。
|
|
275
|
+
|
|
276
|
+
- 2026-07-10 独立评审(18 条)采纳合并:上述 params 契约、resolved model
|
|
277
|
+
进键、空响应双闸、[tool.kigumi] 约定、node key 含库版本、物化一等能力、
|
|
278
|
+
守卫边界诚实化、continue 降实验特性、dag 止损线、litellm 降 extra 等。
|
|
279
|
+
驳回/缓办:table 渲染与 clip 滑窗(无使用实证,砍);多模态 File 引用
|
|
280
|
+
实现与跨进程限流(归 6a,接口先行)。
|
|
281
|
+
|
|
282
|
+
## 命名记录
|
|
283
|
+
|
|
284
|
+
2026-07-10 定名 kigumi(木组)。曾用工作名 scriptkit(否决:不应剧本化)、
|
|
285
|
+
sunmao(PyPI 已占)。候选 dougong/rabbet/treenail 均可用,最终选 kigumi。
|
kigumi-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kigumi contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
kigumi-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kigumi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Load-bearing joinery for LLM content pipelines: context injection, validated repair loops, deterministic replay, DAG orchestration.
|
|
5
|
+
Project-URL: Repository, https://github.com/Oxidane-bot/kigumi
|
|
6
|
+
Project-URL: Changelog, https://github.com/Oxidane-bot/kigumi/blob/master/CHANGELOG.md
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: content-addressed-cache,dag,deterministic-replay,llm,llm-pipelines
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Requires-Dist: pydantic>=2.7
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
21
|
+
Provides-Extra: litellm
|
|
22
|
+
Requires-Dist: litellm>=1.60; extra == 'litellm'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<picture>
|
|
27
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Oxidane-bot/kigumi/master/docs/assets/kigumi-logo.png">
|
|
28
|
+
<img src="https://raw.githubusercontent.com/Oxidane-bot/kigumi/master/docs/assets/kigumi-logo-light.png" alt="kigumi logo" width="220">
|
|
29
|
+
</picture>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
# kigumi (木組)
|
|
33
|
+
|
|
34
|
+
English | [中文](https://github.com/Oxidane-bot/kigumi/blob/master/README.zh-CN.md)
|
|
35
|
+
|
|
36
|
+
Nail-free interlocking joinery. The load-bearing structural layer for LLM
|
|
37
|
+
content pipelines — connecting your project (the roof) to the model (the
|
|
38
|
+
pillars) through precise joints: output that does not fit the mortise gets
|
|
39
|
+
sent back for rework.
|
|
40
|
+
|
|
41
|
+
A foundation for building LLM pipelines with coding agents:
|
|
42
|
+
|
|
43
|
+
- **Injection and assembly**: a single entry point for material injection,
|
|
44
|
+
strict template rendering, format sections auto-generated from schemas
|
|
45
|
+
- **Repair loop**: failed validation turns into corrective instructions,
|
|
46
|
+
model context is preserved, retries are bounded, lessons are locked in
|
|
47
|
+
- **Deterministic replay**: content-addressed caching — same input,
|
|
48
|
+
byte-identical output
|
|
49
|
+
- **DAG orchestration** (optional): per-node caching, dynamic fan-out,
|
|
50
|
+
human checkpoints, run diffs
|
|
51
|
+
- **Three guard rings**: runtime refusal / pytest auto-collection /
|
|
52
|
+
git hooks, so the rules enforce themselves
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from pathlib import Path
|
|
58
|
+
|
|
59
|
+
from pydantic import BaseModel
|
|
60
|
+
|
|
61
|
+
from kigumi import LiteLLMTransport, LLMCaller, call_validated
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Verdict(BaseModel):
|
|
65
|
+
score: int
|
|
66
|
+
reason: str
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
transport = LiteLLMTransport(aliases={"default": "anthropic/claude-sonnet-5"})
|
|
70
|
+
caller = LLMCaller(transport, cache_dir=Path("artifacts/_llm"), seed=20260713)
|
|
71
|
+
|
|
72
|
+
verdict = call_validated(caller, "Score this opening scene and explain why: ...", Verdict)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`call_validated` automatically appends a format section generated from
|
|
76
|
+
`Verdict`; a response that does not fit is sent back with the validation
|
|
77
|
+
errors for a bounded number of retries (2 by default). The whole exchange
|
|
78
|
+
lands in a content-addressed cache, so the same input replays byte-for-byte
|
|
79
|
+
with no further API cost.
|
|
80
|
+
|
|
81
|
+
## Status
|
|
82
|
+
|
|
83
|
+
0.1.0, API not frozen. All four core layers are in place, with 278 tests,
|
|
84
|
+
refined through three clean-room pilots (structured extraction /
|
|
85
|
+
multimodal / DAG orchestration). Not yet published to PyPI.
|
|
86
|
+
|
|
87
|
+
## Install
|
|
88
|
+
|
|
89
|
+
Until the PyPI release, install from Git:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
uv add "kigumi[litellm] @ git+https://github.com/Oxidane-bot/kigumi"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
After release: `uv add "kigumi[litellm]"`. Without the litellm extra you
|
|
96
|
+
can use `StdlibTransport` (pure-stdlib HTTP) or implement your own
|
|
97
|
+
transport.
|
|
98
|
+
|
|
99
|
+
## Documentation map
|
|
100
|
+
|
|
101
|
+
Documentation is currently written in Chinese.
|
|
102
|
+
|
|
103
|
+
| Document | The question it answers |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| [DESIGN.md](https://github.com/Oxidane-bot/kigumi/blob/master/DESIGN.md) | Why it is designed this way; layers, boundaries, settled trade-offs |
|
|
106
|
+
| [docs/adoption.md](https://github.com/Oxidane-bot/kigumi/blob/master/docs/adoption.md) | How to adopt it; the path from a single caller to a DAG, plus troubleshooting |
|
|
107
|
+
| [docs/contracts/](https://github.com/Oxidane-bot/kigumi/blob/master/docs/contracts/) | Which behaviors are promises; invariants, failure behavior, verification coordinates |
|
|
108
|
+
| [docs/reviews/](https://github.com/Oxidane-bot/kigumi/blob/master/docs/reviews/) | What a review found at a point in time; descriptive records, not specs |
|
|
109
|
+
| [CHANGELOG.md](https://github.com/Oxidane-bot/kigumi/blob/master/CHANGELOG.md) | What changed; cache-family rotations and breaking changes are always recorded |
|
|
110
|
+
| [AGENTS.md](https://github.com/Oxidane-bot/kigumi/blob/master/AGENTS.md) | What an agent reads before entering; red lines and verification commands |
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
[MIT](https://github.com/Oxidane-bot/kigumi/blob/master/LICENSE)
|
kigumi-0.1.0/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Oxidane-bot/kigumi/master/docs/assets/kigumi-logo.png">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/Oxidane-bot/kigumi/master/docs/assets/kigumi-logo-light.png" alt="kigumi logo" width="220">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# kigumi (木組)
|
|
9
|
+
|
|
10
|
+
English | [中文](https://github.com/Oxidane-bot/kigumi/blob/master/README.zh-CN.md)
|
|
11
|
+
|
|
12
|
+
Nail-free interlocking joinery. The load-bearing structural layer for LLM
|
|
13
|
+
content pipelines — connecting your project (the roof) to the model (the
|
|
14
|
+
pillars) through precise joints: output that does not fit the mortise gets
|
|
15
|
+
sent back for rework.
|
|
16
|
+
|
|
17
|
+
A foundation for building LLM pipelines with coding agents:
|
|
18
|
+
|
|
19
|
+
- **Injection and assembly**: a single entry point for material injection,
|
|
20
|
+
strict template rendering, format sections auto-generated from schemas
|
|
21
|
+
- **Repair loop**: failed validation turns into corrective instructions,
|
|
22
|
+
model context is preserved, retries are bounded, lessons are locked in
|
|
23
|
+
- **Deterministic replay**: content-addressed caching — same input,
|
|
24
|
+
byte-identical output
|
|
25
|
+
- **DAG orchestration** (optional): per-node caching, dynamic fan-out,
|
|
26
|
+
human checkpoints, run diffs
|
|
27
|
+
- **Three guard rings**: runtime refusal / pytest auto-collection /
|
|
28
|
+
git hooks, so the rules enforce themselves
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from pathlib import Path
|
|
34
|
+
|
|
35
|
+
from pydantic import BaseModel
|
|
36
|
+
|
|
37
|
+
from kigumi import LiteLLMTransport, LLMCaller, call_validated
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Verdict(BaseModel):
|
|
41
|
+
score: int
|
|
42
|
+
reason: str
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
transport = LiteLLMTransport(aliases={"default": "anthropic/claude-sonnet-5"})
|
|
46
|
+
caller = LLMCaller(transport, cache_dir=Path("artifacts/_llm"), seed=20260713)
|
|
47
|
+
|
|
48
|
+
verdict = call_validated(caller, "Score this opening scene and explain why: ...", Verdict)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`call_validated` automatically appends a format section generated from
|
|
52
|
+
`Verdict`; a response that does not fit is sent back with the validation
|
|
53
|
+
errors for a bounded number of retries (2 by default). The whole exchange
|
|
54
|
+
lands in a content-addressed cache, so the same input replays byte-for-byte
|
|
55
|
+
with no further API cost.
|
|
56
|
+
|
|
57
|
+
## Status
|
|
58
|
+
|
|
59
|
+
0.1.0, API not frozen. All four core layers are in place, with 278 tests,
|
|
60
|
+
refined through three clean-room pilots (structured extraction /
|
|
61
|
+
multimodal / DAG orchestration). Not yet published to PyPI.
|
|
62
|
+
|
|
63
|
+
## Install
|
|
64
|
+
|
|
65
|
+
Until the PyPI release, install from Git:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
uv add "kigumi[litellm] @ git+https://github.com/Oxidane-bot/kigumi"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
After release: `uv add "kigumi[litellm]"`. Without the litellm extra you
|
|
72
|
+
can use `StdlibTransport` (pure-stdlib HTTP) or implement your own
|
|
73
|
+
transport.
|
|
74
|
+
|
|
75
|
+
## Documentation map
|
|
76
|
+
|
|
77
|
+
Documentation is currently written in Chinese.
|
|
78
|
+
|
|
79
|
+
| Document | The question it answers |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| [DESIGN.md](https://github.com/Oxidane-bot/kigumi/blob/master/DESIGN.md) | Why it is designed this way; layers, boundaries, settled trade-offs |
|
|
82
|
+
| [docs/adoption.md](https://github.com/Oxidane-bot/kigumi/blob/master/docs/adoption.md) | How to adopt it; the path from a single caller to a DAG, plus troubleshooting |
|
|
83
|
+
| [docs/contracts/](https://github.com/Oxidane-bot/kigumi/blob/master/docs/contracts/) | Which behaviors are promises; invariants, failure behavior, verification coordinates |
|
|
84
|
+
| [docs/reviews/](https://github.com/Oxidane-bot/kigumi/blob/master/docs/reviews/) | What a review found at a point in time; descriptive records, not specs |
|
|
85
|
+
| [CHANGELOG.md](https://github.com/Oxidane-bot/kigumi/blob/master/CHANGELOG.md) | What changed; cache-family rotations and breaking changes are always recorded |
|
|
86
|
+
| [AGENTS.md](https://github.com/Oxidane-bot/kigumi/blob/master/AGENTS.md) | What an agent reads before entering; red lines and verification commands |
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
[MIT](https://github.com/Oxidane-bot/kigumi/blob/master/LICENSE)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/kigumi-logo.png">
|
|
4
|
+
<img src="docs/assets/kigumi-logo-light.png" alt="kigumi logo" width="220">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# kigumi(木組)
|
|
9
|
+
|
|
10
|
+
[English](README.md) | 中文
|
|
11
|
+
|
|
12
|
+
无钉咬合的木工工艺。LLM 内容流水线的承重结构层——项目(屋顶)与模型(立柱)
|
|
13
|
+
之间靠精确咬合连接,不合榫就打回重做。
|
|
14
|
+
|
|
15
|
+
给"用 coding agent 开发 LLM 流水线"提供地基:
|
|
16
|
+
|
|
17
|
+
- **注入与拼接**:材料注入唯一入口,严格模板渲染,schema 自动生成格式说明段
|
|
18
|
+
- **修复环**:校验不达标 → 纠正指令打回,保留模型上文,有界重试,学费固化
|
|
19
|
+
- **确定性重放**:内容寻址缓存,同输入逐字节同输出
|
|
20
|
+
- **DAG 编排**(可选):节点级缓存、动态 fan-out、人工检查点、run diff
|
|
21
|
+
- **守卫三环**:运行时拒载 / pytest 自动收集 / git hook,让规矩自动执行
|
|
22
|
+
|
|
23
|
+
## 快速上手
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
from pydantic import BaseModel
|
|
29
|
+
|
|
30
|
+
from kigumi import LiteLLMTransport, LLMCaller, call_validated
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Verdict(BaseModel):
|
|
34
|
+
score: int
|
|
35
|
+
reason: str
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
transport = LiteLLMTransport(aliases={"default": "anthropic/claude-sonnet-5"})
|
|
39
|
+
caller = LLMCaller(transport, cache_dir=Path("artifacts/_llm"), seed=20260713)
|
|
40
|
+
|
|
41
|
+
verdict = call_validated(caller, "给这段开场白打分并给出理由:……", Verdict)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`call_validated` 自动附上由 `Verdict` 生成的格式说明段;返回若不合榫,
|
|
45
|
+
带着校验错误打回重试(默认至多 2 次)。整次交互内容寻址落缓存,
|
|
46
|
+
同输入重跑逐字节复现,不再计费。
|
|
47
|
+
|
|
48
|
+
## 状态
|
|
49
|
+
|
|
50
|
+
0.1.0,API 未冻结。核心四层齐备,278 项测试,经三个 clean-room
|
|
51
|
+
试点(结构化抽取 / 多模态 / DAG 编排)回写打磨。尚未发布到 PyPI。
|
|
52
|
+
|
|
53
|
+
## 安装
|
|
54
|
+
|
|
55
|
+
发布到 PyPI 前,从 Git 安装:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
uv add "kigumi[litellm] @ git+https://github.com/Oxidane-bot/kigumi"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
发布后:`uv add "kigumi[litellm]"`。不装 litellm extra 时可用
|
|
62
|
+
`StdlibTransport`(纯标准库 HTTP)或自实现 transport。
|
|
63
|
+
|
|
64
|
+
## 文档地图
|
|
65
|
+
|
|
66
|
+
| 文档 | 回答的问题 |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| [DESIGN.md](DESIGN.md) | 为什么这样设计;分层、边界与已裁决的取舍 |
|
|
69
|
+
| [docs/adoption.md](docs/adoption.md) | 怎么接入;从单 caller 到 DAG 的路径与排障 |
|
|
70
|
+
| [docs/contracts/](docs/contracts/) | 哪些行为是承诺;不变式、失效行为与验证坐标 |
|
|
71
|
+
| [docs/reviews/](docs/reviews/) | 某个时点审查出了什么;实然记录,不是规范 |
|
|
72
|
+
| [CHANGELOG.md](CHANGELOG.md) | 什么变了;缓存换族与破坏性变更必录 |
|
|
73
|
+
| [AGENTS.md](AGENTS.md) | agent 进场先读什么;红线与验证命令 |
|
|
74
|
+
|
|
75
|
+
## 许可证
|
|
76
|
+
|
|
77
|
+
[MIT](LICENSE)
|