guarantee-based-coding 0.2.0__py3-none-any.whl

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.
Files changed (48) hide show
  1. gbc/__init__.py +21 -0
  2. gbc/app/__init__.py +14 -0
  3. gbc/app/assets.py +38 -0
  4. gbc/app/config/__init__.py +14 -0
  5. gbc/app/config/backups.py +28 -0
  6. gbc/app/config/base.py +29 -0
  7. gbc/app/config/executor.py +132 -0
  8. gbc/app/config/project.py +35 -0
  9. gbc/app/core/__init__.py +14 -0
  10. gbc/app/core/env.py +64 -0
  11. gbc/app/core/executor.py +116 -0
  12. gbc/app/core/guarantee.py +338 -0
  13. gbc/app/i18n/__init__.py +43 -0
  14. gbc/app/i18n/lang.py +88 -0
  15. gbc/app/i18n/translate.py +80 -0
  16. gbc/app/intent/__init__.py +20 -0
  17. gbc/app/intent/base.py +308 -0
  18. gbc/app/intent/cli.py +124 -0
  19. gbc/app/intent/editor.py +93 -0
  20. gbc/app/interface/__init__.py +14 -0
  21. gbc/app/interface/base.py +851 -0
  22. gbc/app/interface/cli.py +585 -0
  23. gbc/app/interface/mcp.py +616 -0
  24. gbc/app/models/__init__.py +14 -0
  25. gbc/app/models/errors.py +179 -0
  26. gbc/app/models/meta.py +92 -0
  27. gbc/app/models/verify.py +63 -0
  28. gbc/app/utils/__init__.py +14 -0
  29. gbc/app/utils/file_utils.py +24 -0
  30. gbc/app/utils/gbc_md.py +121 -0
  31. gbc/app/utils/json_model_operator.py +85 -0
  32. gbc/app/utils/safe_file_writer.py +158 -0
  33. gbc/assets/editor/index.html +299 -0
  34. gbc/assets/i18n/catalog/en.json +52 -0
  35. gbc/assets/i18n/catalog/zh.json +52 -0
  36. gbc/assets/i18n/texts/rules.en.md +30 -0
  37. gbc/assets/i18n/texts/rules.zh.md +24 -0
  38. gbc/assets/i18n/texts/setup.en.md +74 -0
  39. gbc/assets/i18n/texts/setup.zh.md +69 -0
  40. gbc/assets/skills/README.md +16 -0
  41. gbc/assets/skills/gbc-cli/SKILL.md +143 -0
  42. gbc/entry.py +126 -0
  43. guarantee_based_coding-0.2.0.dist-info/METADATA +108 -0
  44. guarantee_based_coding-0.2.0.dist-info/RECORD +48 -0
  45. guarantee_based_coding-0.2.0.dist-info/WHEEL +5 -0
  46. guarantee_based_coding-0.2.0.dist-info/entry_points.txt +2 -0
  47. guarantee_based_coding-0.2.0.dist-info/licenses/LICENSE +202 -0
  48. guarantee_based_coding-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,74 @@
1
+ # Wiring GBC into your agent
2
+
3
+ GBC is installed. This is the wiring guide: it tells you **where the endpoints and
4
+ files are** so your agent can reach them. It does **not** dictate *how* to wire them —
5
+ that depends on how your particular agent framework loads MCP servers and skills.
6
+ GBC only hands you the coordinates; you (or your agent) do the connecting.
7
+
8
+ There are two independent ways to give an agent GBC's abilities. Use whichever your
9
+ agent supports; you may use both.
10
+
11
+ ---
12
+
13
+ ## Option A — MCP (recommended when your agent speaks MCP)
14
+
15
+ GBC ships a stdio MCP server exposing both subsystems: the guarantee engine
16
+ (guarantee / dep / verify / refactor / tree / consistency / executor) **and** the
17
+ intent documents (doc show / check / set-* / sync / migrate).
18
+
19
+ **The endpoint** — start the server with:
20
+
21
+ ```
22
+ gbc mcp up <ABSOLUTE_PATH_TO_YOUR_PROJECT>
23
+ ```
24
+
25
+ Register that command as an MCP server wherever your framework keeps its MCP config.
26
+ A typical stdio entry looks like (adapt to your framework's schema):
27
+
28
+ ```
29
+ {{
30
+ "command": "gbc",
31
+ "args": ["mcp", "up", "/abs/path/to/your/project"]
32
+ }}
33
+ ```
34
+
35
+ Notes:
36
+ - The project root is passed as that argument; the server keeps all mutable state
37
+ under your project's `.gbc/` (created on first write — you do not need to pre-make it).
38
+ - If `gbc` is not on PATH for your launcher, use the interpreter form:
39
+ `<python> -m gbc.entry mcp up <project-root>`.
40
+ - After registering, reload / reconnect MCP so your agent picks up the tools.
41
+
42
+ ---
43
+
44
+ ## Option B — Skills (for agents that don't use MCP, or where MCP is inconvenient)
45
+
46
+ Because every GBC ability is also a plain `gbc ...` command, an agent that can run
47
+ shell commands can use GBC through a set of **pre-authored skills** that teach it
48
+ which commands to run. This is the CLI-side equivalent of MCP tool descriptions.
49
+
50
+ **The files** — the bundled skills live here:
51
+
52
+ ```
53
+ {skills_dir}
54
+ ```
55
+
56
+ Copy (or symlink) those skill files into wherever your agent discovers skills. GBC
57
+ does not place them for you, because every framework reads skills from a different
58
+ location — materializing the files is ours, placing them is yours.
59
+
60
+ ---
61
+
62
+ ## Verify it works
63
+
64
+ Once wired, have your agent run a read-only call — e.g. the `tree` tool over MCP, or
65
+ `gbc tree` on the CLI. If it returns your project's dependency tree (or an empty one
66
+ for a fresh project), GBC is reachable.
67
+
68
+ ## One thing GBC does NOT do for you
69
+
70
+ GBC gives abilities, not restraint. The safety rules (who may edit `.gbc/`, when
71
+ intent changes need human sign-off) are printed by `gbc rules`, and their
72
+ **enforcement** must come from your agent framework (e.g. a pre-tool-use hook) — the
73
+ same hook applies whether the ability arrived via MCP or CLI. Installing GBC does not
74
+ make you automatically safe; read `gbc rules` and wire the enforcement yourself.
@@ -0,0 +1,69 @@
1
+ # 把 GBC 接入你的 agent
2
+
3
+ GBC 已经装好了。这是一份**接线指南**:它告诉你**端点和文件在哪**,好让你的 agent
4
+ 够得着它们。它**不**规定*具体怎么接*——那取决于你所用的 agent 框架如何加载 MCP
5
+ server 和 skill。GBC 只给你坐标,接线由你(或你的 agent)来做。
6
+
7
+ 给 agent 赋予 GBC 能力有两条彼此独立的路。你的 agent 支持哪条就用哪条,也可以都用。
8
+
9
+ ---
10
+
11
+ ## 方案 A —— MCP(你的 agent 会说 MCP 时推荐)
12
+
13
+ GBC 自带一个 stdio MCP server,暴露两个子系统:保证引擎(guarantee / dep / verify /
14
+ refactor / tree / consistency / executor)**以及**意图文档(doc show / check / set-* /
15
+ sync / migrate)。
16
+
17
+ **端点** —— 用下面的命令启动 server:
18
+
19
+ ```
20
+ gbc mcp up <你项目根的绝对路径>
21
+ ```
22
+
23
+ 把这条命令注册为 MCP server,注册位置在你框架存放 MCP 配置的地方。一个典型的 stdio
24
+ 条目形如(按你框架的 schema 调整):
25
+
26
+ ```
27
+ {{
28
+ "command": "gbc",
29
+ "args": ["mcp", "up", "/abs/path/to/your/project"]
30
+ }}
31
+ ```
32
+
33
+ 说明:
34
+ - 项目根作为那个参数传入;server 把一切可变状态放在你项目的 `.gbc/` 下(首次写入时
35
+ 自动创建——你不必预先建它)。
36
+ - 如果启动器的 PATH 上没有 `gbc`,改用解释器形式:
37
+ `<python> -m gbc.entry mcp up <项目根>`。
38
+ - 注册后重新加载 / 重连 MCP,让你的 agent 拉到这些工具。
39
+
40
+ ---
41
+
42
+ ## 方案 B —— Skills(给不用 MCP、或 MCP 不方便的 agent)
43
+
44
+ 因为 GBC 的每一项能力同时也是一条普通的 `gbc ...` 命令,一个能跑 shell 的 agent 可以
45
+ 通过一套**预组 skill** 来使用 GBC——这些 skill 教它该敲哪些命令,等价于 CLI 侧的 MCP
46
+ 工具描述。
47
+
48
+ **文件** —— 随包分发的 skill 在这里:
49
+
50
+ ```
51
+ {skills_dir}
52
+ ```
53
+
54
+ 把这些 skill 文件拷贝(或软链)到你的 agent 发现 skill 的位置。GBC 不替你放置它们,
55
+ 因为每个框架读 skill 的位置都不同——把文件准备好是我们的事,放到哪由你决定。
56
+
57
+ ---
58
+
59
+ ## 验证是否接通
60
+
61
+ 接好后,让你的 agent 跑一次只读调用——比如经 MCP 调 `tree` 工具,或在 CLI 敲
62
+ `gbc tree`。如果它返回了你项目的依赖树(新项目则是一棵空树),说明 GBC 已经够得着了。
63
+
64
+ ## 有一件事 GBC 不替你做
65
+
66
+ GBC 给的是能力,不是约束。安全规则(谁能改 `.gbc/`、意图变更何时需人类签字)由
67
+ `gbc rules` 打印,而它们的**强制执行**必须来自你的 agent 框架(例如 pre-tool-use
68
+ hook)——无论能力是经 MCP 还是 CLI 到达,同一个 hook 都适用。装了 GBC 并不会让你自动
69
+ 安全;请读 `gbc rules`,并自己把强制执行接上。
@@ -0,0 +1,16 @@
1
+ # GBC pre-authored skills (for CLI-only agents)
2
+
3
+ This directory ships **pre-authored skills** that teach an agent how to drive GBC
4
+ through its plain `gbc ...` commands — the CLI-side equivalent of the MCP tool
5
+ descriptions. They exist for agents that don't speak MCP, or where MCP is
6
+ inconvenient.
7
+
8
+ `gbc setup` points users here by absolute path; copying the skill files into
9
+ wherever their agent discovers skills is up to them (every framework reads skills
10
+ from a different place — GBC materializes the files, the user places them).
11
+
12
+ ## What's here
13
+
14
+ - **`gbc-cli/`** — teaches an agent to drive GBC through its `gbc ...` commands
15
+ (the CLI-side equivalent of the MCP tool descriptions). Point your agent at
16
+ `gbc-cli/SKILL.md`.
@@ -0,0 +1,143 @@
1
+ ---
2
+ name: gbc-cli
3
+ description: Drive GBC (Guarantee-Based Coding) through its `gbc` command-line interface. Use this whenever you need to register/verify/inspect guarantees, dependencies, or intent docs and MCP is not available to you (or you prefer the CLI). This is the CLI-side equivalent of GBC's MCP tools — every ability is a `gbc ...` subcommand. Assumes the `gbc` command is already installed and on PATH.
4
+ ---
5
+
6
+ # gbc-cli: using GBC from the command line
7
+
8
+ GBC turns implicit inter-module dependencies into **named, executable guarantees**: a guarantee
9
+ is a named behavior a file promises, backed by a test. Change code → re-run the affected
10
+ guarantees → green means every dependent's promise still holds. This skill tells you which `gbc`
11
+ commands realize those abilities, so you can use GBC without an MCP connection.
12
+
13
+ Everything here is a plain shell command. If `gbc` is not on PATH, substitute
14
+ `python -m gbc.entry` for `gbc` (same subcommands).
15
+
16
+ > **Which project am I acting on?** Commands act on the current GBC target project, which
17
+ > defaults to the directory you run `gbc` from (its cwd) — no environment variable needed. Just
18
+ > `cd` into the project root before running commands. All paths you pass to commands are
19
+ > **project-relative** (e.g. `app/core/config.py`).
20
+
21
+ ---
22
+
23
+ ## The core loop (register once, verify forever)
24
+
25
+ 1. **Register an executor** (how tests run) — once per project, by name.
26
+ 2. **Create a guarantee** on a provider file — born-green: the test runs immediately, and
27
+ creation is refused if it fails.
28
+ 3. **Register dependencies** — record that a consumer relies on a provider's symbol/guarantee.
29
+ 4. **Verify** after changes — run a provider's guarantees; green iff nothing failed.
30
+
31
+ ---
32
+
33
+ ## Guarantees — `gbc guarantee`
34
+
35
+ | Command | What it does |
36
+ |---------|--------------|
37
+ | `gbc guarantee create <provider> <id> <test> <executor> <desc>` | Create a named guarantee. **Born-green**: runs the test now, refuses if it fails. Add `--heavy N` (cost rank; `>=1` is skipped in batch verify), `--timeout S`, or `--disabled` (placeholder that skips born-green — only to break a circular dependency; enable it later). |
38
+ | `gbc guarantee update <provider> <id>` | Change fields: `--desc`, `--test`, `--executor`, `--heavy`, `--timeout`. Changing the test/executor re-runs born-green. |
39
+ | `gbc guarantee retire <provider> <id>` | Delete a guarantee. **Refused if it still has dependents** — migrate them first. |
40
+ | `gbc guarantee disable <provider> <id>` | Suspend born-green/batch verify for it while keeping its id and all edges. Escape hatch for refactors; **not** a delete. |
41
+ | `gbc guarantee enable <provider> <id>` | Re-run born-green now; clears disabled only if the test passes. |
42
+ | `gbc guarantee list <provider>` | List every guarantee a provider offers, with state and dependent count. |
43
+
44
+ **Id convention**: `<symbol>.<behavior>`, e.g. `get_config.never_none`. Do **not** encode the
45
+ provider path in the id — the path is carried by the `<provider>` argument. Ids need only be
46
+ unique per provider.
47
+
48
+ ---
49
+
50
+ ## Dependencies — `gbc dep`
51
+
52
+ | Command | What it does |
53
+ |---------|--------------|
54
+ | `gbc dep add <consumer> <provider> <symbol>` | Register a **free** symbol-level dependency (depends on the symbol existing, not on a specific behavior; no test, no reverse edge). |
55
+ | `gbc dep add <consumer> <provider> <symbol> -g <guarantee_id>` | Register a **behavior** dependency on an existing guarantee. The reverse edge (provider's dependents) is written automatically. Multiple consumers may share one guarantee. |
56
+ | `gbc dep remove <consumer> <provider> <symbol> [-g <id>]` | Remove one guarantee from the edge (`-g`), or the whole symbol edge (no `-g`). |
57
+ | `gbc dep of <consumer>` | List every dependency edge a file declares. |
58
+ | `gbc dep who <provider> [-s <symbol>] [-g <id>]` | Reverse lookup: who depends on this provider. Replaces ad-hoc grep. |
59
+
60
+ ---
61
+
62
+ ## Verify — `gbc verify`
63
+
64
+ | Command | What it does |
65
+ |---------|--------------|
66
+ | `gbc verify provider <provider>` | Run all of a provider's guarantees. Heavy guarantees above the threshold are skipped and reported (not failed). Add `--max-heavy N` to run heavier ones. **GREEN iff nothing failed.** |
67
+ | `gbc verify single <provider> <id>` | Run one guarantee by id — always runs, ignoring the heavy threshold. Add `-v` for full stdout/stderr. |
68
+
69
+ **Gate semantics**: a test that ran is either pass or fail; a test that was *skipped* (heavy) is
70
+ reported loudly but does **not** turn the gate red. Green = no failures.
71
+
72
+ ---
73
+
74
+ ## Inspect — `gbc tree` / `gbc doctor`
75
+
76
+ | Command | What it does |
77
+ |---------|--------------|
78
+ | `gbc tree` | Render the whole `.gbc` tree as one AI-readable dependency document (intent backbone + dependency edges + provided guarantees). Add `--detail` for guarantee desc/test/heavy, `--gaps` for registration gaps. **Start here for a whole-project overview.** |
79
+ | `gbc doctor check` | Global consistency lint: dangling references, two-way edge drift, and disabled guarantees (reported loudly, not as errors). |
80
+
81
+ ---
82
+
83
+ ## Executors — `gbc executor`
84
+
85
+ An executor is a named recipe for running tests, stored per project. Register it once, then
86
+ guarantees reference it by name.
87
+
88
+ ```bash
89
+ gbc executor upsert <name> --json '{"command": ["pytest", "{file}", "-x", "-q"], "cwd": "/abs/project", "timeout": 30, "env_ops": [{"key": "PYTHONPATH", "action": "prepend", "value": "/abs/project"}]}'
90
+ ```
91
+
92
+ - `command`: argv parts; `{file}` is substituted with the test selector.
93
+ - Or pass a JSON file with `--file <path>` instead of `--json`.
94
+ - Give it a **project-scoped name** (e.g. `pytest-<project>`) so it won't collide with another
95
+ project's executor.
96
+
97
+ ---
98
+
99
+ ## Move / rename — `gbc refactor` (never hand-fix the graph)
100
+
101
+ Relocating a file or renaming a symbol desyncs every path-addressed reference. Use these instead
102
+ of editing `.gbc` by hand:
103
+
104
+ | Command | What it does |
105
+ |---------|--------------|
106
+ | `gbc refactor file <old> <new>` | Move a file/dir + its `.gbc` metadata, rewrite all references graph-wide, auto-disable the moved file's guarantees (their tests break until you fix imports). Ids are unchanged (path-free). Idempotent. |
107
+ | `gbc refactor func <provider> <old_symbol> <new_symbol>` | Rename a symbol: rewrite consumers' edges + the guarantee ids under that symbol, auto-disable them. You rename `def`/call sites in source, then `enable`. |
108
+ | `gbc refactor rename-id <provider> <old_id> <new_id>` | Rename a guarantee id, keeping both directions consistent. |
109
+
110
+ After any refactor: fix imports, move the test files and `gbc guarantee update <p> <id> --test ...`,
111
+ then `gbc guarantee enable <p> <id>` for each disabled id.
112
+
113
+ ---
114
+
115
+ ## Intent docs — `gbc doc`
116
+
117
+ `gbc.md` files hold the project's architectural intent. `gbc doc` is the compliant read/write
118
+ entry — it keeps each doc's three-section structure and parent/child consistency for you.
119
+
120
+ | Command | What it does |
121
+ |---------|--------------|
122
+ | `gbc doc show <folder>` | View a folder's intent / constraints / entries. Root folder is `""` or `.`. |
123
+ | `gbc doc check` | Whole-tree intent consistency lint (DRIFT/ORPHAN are errors, STUB is a note). |
124
+ | `gbc doc set-intent <folder> "<text>"` | Set a folder's intent (auto-projected into the parent entry). |
125
+ | `gbc doc set-constraints <folder> "<text>"` | Set internal constraints (local only). |
126
+ | `gbc doc set-file <folder> <name> "<desc>"` | Add/update a file entry (name without `/`). |
127
+ | `gbc doc rm-entry <folder> <name>` | Remove a doc entry (does not delete the file on disk). |
128
+ | `gbc doc sync` | Deterministically repair parent/child drift. |
129
+
130
+ > If a `<text>` argument begins with `-`, put `--` before it so it isn't parsed as an option:
131
+ > `gbc doc set-intent app -- "- a line starting with a dash"`.
132
+
133
+ **Writing intent is changing human-held architecture truth.** Whether it needs your human's
134
+ sign-off is set by your agent framework's rules/hooks, not by this tool. Never hand-edit `gbc.md`.
135
+
136
+ ---
137
+
138
+ ## The boundary (read `gbc rules`)
139
+
140
+ GBC gives abilities, not restraint. Who may edit `.gbc/`, when intent needs human sign-off — those
141
+ rules are printed by `gbc rules`, and their **enforcement** must come from your agent framework
142
+ (e.g. a pre-tool-use hook). The same enforcement applies whether you reach GBC via CLI or MCP.
143
+ Run `gbc rules` and follow what your human has adopted.
gbc/entry.py ADDED
@@ -0,0 +1,126 @@
1
+ # Copyright 2026 Jesse-x86
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """`gbc` 的唯一入口 —— 纯分发器。
16
+
17
+ 不实现任何业务:只把两个子系统的表面**组合**成一棵命令树,再挂上跨子系统的
18
+ 服务/初始化命令。各表面自己是薄的、只调各自的 base。
19
+
20
+ gbc guarantee|dep|verify|doctor|executor|refactor|tree → 保证引擎(interface.cli)
21
+ gbc doc <...> → 意图文档(intent.cli)
22
+ gbc mcp up [root] → 保证引擎的 MCP 表面(interface.mcp)
23
+ gbc editor up → 意图文档的 web 表面(intent.editor)
24
+ gbc rules / setup → 跨子系统的辅助命令
25
+
26
+ [project.scripts] 的 `gbc` 指向本模块的 app。
27
+ """
28
+ from typing import Optional
29
+
30
+ import typer
31
+
32
+ from gbc.app.interface.cli import app as guarantee_cli
33
+ from gbc.app.intent.cli import doc_app
34
+
35
+ # 顶层命令树 = 保证引擎的 cli(含 guarantee/dep/verify/doctor/executor/refactor/tree
36
+ # 与全局 --lang callback),再往上挂 doc 子树与服务/辅助命令。
37
+ app = guarantee_cli
38
+ app.add_typer(doc_app, name="doc")
39
+
40
+ mcp_app = typer.Typer(help="cli.mcp.help")
41
+ editor_app = typer.Typer(help="cli.editor.help")
42
+ app.add_typer(mcp_app, name="mcp")
43
+ app.add_typer(editor_app, name="editor")
44
+
45
+
46
+ @mcp_app.command("up")
47
+ def mcp_up(
48
+ project_root: Optional[str] = typer.Argument(None, help="cli.mcp_up.arg.project_root"),
49
+ ):
50
+ """启动 GBC 的 stdio MCP server(常驻)。由 MCP 表面自己的启动器承载。"""
51
+ from gbc.app.interface.mcp import run_server
52
+ run_server(project_root)
53
+
54
+
55
+ @editor_app.command("up")
56
+ def editor_up(
57
+ root: Optional[str] = typer.Option(None, "--root", "-r", help="默认项目路径,前端预填并自动加载"),
58
+ host: str = typer.Option("127.0.0.1", "--host", help="监听地址"),
59
+ port: int = typer.Option(8765, "--port", "-p", help="监听端口"),
60
+ lang: Optional[str] = typer.Option(None, "--lang", help="界面语言 zh/en"),
61
+ ):
62
+ """启动意图编辑器 web 服务(常驻)。"""
63
+ from gbc.app.i18n import set_lang, resolve_lang, t
64
+ from gbc.app.intent.editor import run_editor
65
+ set_lang(resolve_lang(lang))
66
+ typer.echo(t("editor.starting", host=host, port=port))
67
+ run_editor(host=host, port=port, root=root or "")
68
+
69
+
70
+ @app.command("rules", help="cli.rules.help")
71
+ def rules_cmd(
72
+ lang: Optional[str] = typer.Option(None, "--lang", help="cli.option.lang.help"),
73
+ ):
74
+ """打印作者推荐的围栏规则集到 stdout(推荐默认,非强制沙箱)。"""
75
+ from gbc.app.i18n import set_lang, resolve_lang, load_text
76
+ set_lang(resolve_lang(lang))
77
+ # 纯文本发射器:用 print 而非 rich,便于管道/复制。
78
+ print(load_text("rules"))
79
+
80
+
81
+ @app.command("setup", help="cli.setup.help")
82
+ def setup_cmd(
83
+ lang: Optional[str] = typer.Option(None, "--lang", help="cli.option.lang.help"),
84
+ ):
85
+ """打印本地化的接线指南到 stdout:怎么把 MCP / skills 接入你的 agent。"""
86
+ from gbc.app.i18n import set_lang, resolve_lang, load_text
87
+ from gbc.app.assets import SKILLS_DIR
88
+ set_lang(resolve_lang(lang))
89
+ # 与 rules 同构:纯文本发射器。只给坐标(skills 目录/MCP 入口),
90
+ # 具体怎么接入取决于用户 agent——{skills_dir} 填入随包 skills 的真实路径。
91
+ print(load_text("setup").format(skills_dir=str(SKILLS_DIR)))
92
+
93
+
94
+ def get_wrapped_app():
95
+ """返回经 i18n 完整包装的 Click Group(供 main_cli/main + CliRunner 共用)。
96
+
97
+ GBC 不在 typer.main.get_group 上做全局 monkey-patch——只在 GBC 自己的
98
+ 命令树上做局部包装,不污染同一进程内其他 Typer 应用。
99
+ """
100
+ from gbc.app.interface.cli import i18n_wrap_click_tree
101
+ root = typer.main.get_command(app)
102
+ i18n_wrap_click_tree(root)
103
+ return root
104
+
105
+
106
+ def main_cli() -> None:
107
+ """GBC console_scripts 入口:i18n 包装后交给 Click(含 sys.exit)。
108
+
109
+ 这是 pyproject.toml [project.scripts] gbc 指向的入口。
110
+ pipx 安装后 PATH 上的 `gbc` 命令经此路径执行,与 main() 共用 get_wrapped_app()。
111
+ """
112
+ get_wrapped_app()(standalone_mode=True)
113
+
114
+
115
+ def main() -> None:
116
+ """GBC 唯一入口(python -m):组合命令树 → i18n 包裹 → 交给 Click 执行。
117
+
118
+ 与 main_cli 共用 get_wrapped_app(),差异只在 standalone_mode:
119
+ - main_cli(standalone_mode=True) → sys.exit,给 pipx/setuptools console_scripts
120
+ - main(standalone_mode=False) → 返 exit code,给 python -m 调用链
121
+ """
122
+ get_wrapped_app()(standalone_mode=False)
123
+
124
+
125
+ if __name__ == "__main__":
126
+ main()
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: guarantee-based-coding
3
+ Version: 0.2.0
4
+ Summary: Make code safely modifiable even when not fully understood — turn implicit inter-module dependencies into explicit, executable, verifiable guarantees.
5
+ Author: Jesse-x86
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Jesse-x86/guarantee-based-coding
8
+ Project-URL: Repository, https://github.com/Jesse-x86/guarantee-based-coding
9
+ Keywords: guarantee,testing,ai-coding,mcp,code-safety
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Software Development :: Testing
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: typer[all]
18
+ Requires-Dist: pydantic
19
+ Requires-Dist: mcp<2.0,>=1.0
20
+ Dynamic: license-file
21
+
22
+ # Guarantee-Based Coding (GBC)
23
+
24
+ **与其指望 AI 更聪明,不如让再笨的 agent 也改不坏你的代码。**
25
+
26
+ **English version: [docs/en/README.md](docs/en/README.md)**
27
+
28
+ GBC 把「这次改动会不会悄悄碰坏别处」从一种担心,变成可以当场验证的事实:你在意的行为被登记成
29
+ 一条条带测试的**保证(guarantee)**,每次改完一跑——全绿就安心,有红就精确告诉你碰坏了谁、谁在
30
+ 依赖它。
31
+
32
+ ---
33
+
34
+ ## 🚀 快速开始
35
+
36
+ ```bash
37
+ pipx install guarantee-based-coding
38
+ gbc setup # 打印本地化接线指南:怎么把 MCP / skills 接入你的 agent
39
+ ```
40
+
41
+ 装好后 `gbc` 命令即在 PATH 上。完整上手(安装 → 接入 agent → 冒烟验证)见
42
+ **[docs/zh/quick-start.md](./docs/zh/quick-start.md)**。
43
+
44
+ 想让 agent 替你接入?把 **[docs/zh/onboarding-agent.md](./docs/zh/onboarding-agent.md)** 交给它。
45
+
46
+ ---
47
+
48
+ > 🚧 **交互式 demo 施工中**:旧的演示套件已废弃,新的交互式演示正在筹备。目前请直接读文档上手。
49
+
50
+ ---
51
+
52
+ ## 📚 文档
53
+
54
+ | 你想 | 看这里 |
55
+ |------|--------|
56
+ | 装好并跑起来 | [快速开始](./docs/zh/quick-start.md) |
57
+ | 懂 GBC 在保护什么 | [核心概念](./docs/zh/concepts.md) |
58
+ | 在 GBC 下安全改代码 | [工作流](./docs/zh/workflow.md) |
59
+ | 查命令 / 工具 / executor | [参考手册](./docs/zh/reference.md) |
60
+ | 你是 agent,被要求接入 GBC | [Agent 上手](./docs/zh/onboarding-agent.md) |
61
+
62
+ English docs: [docs/en/](./docs/en/)。
63
+
64
+ ---
65
+
66
+ ## 核心想法
67
+
68
+ 代码之间的依赖本质上是一组**保证**。模块 A 依赖模块 B,不是依赖它的实现细节,而是依赖它的某些
69
+ 行为承诺——返回值的类型、格式、语义。把这些保证从隐含变成**显式、可执行、可验证**,正确性的判定
70
+ 就从「AI 觉得自己改对了」变成「所有被依赖的保证仍通过」——一个可机械验证的布尔条件。
71
+
72
+ ![无 GBC vs 有 GBC](docs/assets/workflow-comparison.svg)
73
+
74
+ GBC **不是**另一个要挑战 Cursor / Aider 的 AI 编程助手,而是填补它们在大型项目里缺的一环:
75
+ **机器可判定的变更边界**。它与那些 agent 配合——改前查依赖树,改后必须跑通所有相关保证;也区别
76
+ 于 CI——CI 是事后的,GBC 是准入制的门禁,错误在落地前就被拦在 agent 的上下文里。
77
+
78
+ 完整概念、架构图、与已有概念(Design by Contract / 测试)的区别,见
79
+ [核心概念](./docs/zh/concepts.md)。
80
+
81
+ ---
82
+
83
+ ## 当前状态
84
+
85
+ GBC 目前是一个可用的 Python 分发包(`pipx install guarantee-based-coding`),自身用 GBC 管理自己的
86
+ `.gbc/`(dogfooding):
87
+
88
+ - ✅ 核心保证机制(具名 id、多对一、出生即绿、退休保护、反查)
89
+ - ✅ 多语言 executor 配置
90
+ - ✅ CLI + MCP 双接口(含意图文档 `gbc doc` 全进 MCP)
91
+ - ✅ 意图文档子系统(`gbc doc` / web 编辑器)
92
+ - ✅ 随包分发的接线指南(`gbc setup`)与 CLI-only agent 的 skill 包
93
+ - ✅ 原子文件写入 + 备份
94
+
95
+
96
+ **诚实的局限**:保护能力上限 = 测试质量(测试只走 happy path 就是虚假安全感);依赖需主动登记,
97
+ 覆盖率随项目增长需持续投入;每次验证真实跑测试,有一定延迟。详见
98
+ [核心概念 · 局限性](./docs/zh/concepts.md#局限性诚实地说)。
99
+
100
+ ---
101
+
102
+ ## 许可
103
+
104
+ 本项目采用 [Apache-2.0](./LICENSE) 许可证。
105
+
106
+ ## 联系
107
+
108
+ 如果你对这个方向感兴趣,欢迎 star、issue 或者直接联系我。
@@ -0,0 +1,48 @@
1
+ gbc/__init__.py,sha256=IWieHkgW4RyX8FMHea6qZ35p3uOSQhu2M8CltlZ_V-Q,843
2
+ gbc/entry.py,sha256=B0-xUnLWBEVgayHvwIazvh-k6aOywlXTS1Yv-zxiO8s,5218
3
+ gbc/app/__init__.py,sha256=I4xqrxoGB8PldKRIqY5lMGQzPhiZOqpJRa0PtjBVagI,574
4
+ gbc/app/assets.py,sha256=GHD-AhfRPXqKhNYS9aH93J6kUnKkXBDVrLm5nLDGTAQ,1730
5
+ gbc/app/config/__init__.py,sha256=I4xqrxoGB8PldKRIqY5lMGQzPhiZOqpJRa0PtjBVagI,574
6
+ gbc/app/config/backups.py,sha256=rNM-Fal4PuARasNKTUYUjVt3JCd9uXoAgAeGlVA9li4,868
7
+ gbc/app/config/base.py,sha256=6qcjh4xQ36uLCX_rod5QvNwDgHfBr51AVxPNbaqL7Zk,993
8
+ gbc/app/config/executor.py,sha256=STfgDhA48-KL9hEyImHVZ5yIEJUtTHfOltRFtB7ipww,5186
9
+ gbc/app/config/project.py,sha256=CWuAo4tvwWO39uBlfBpwoHx5TAyFbbydwle1Q2anr5w,1265
10
+ gbc/app/core/__init__.py,sha256=I4xqrxoGB8PldKRIqY5lMGQzPhiZOqpJRa0PtjBVagI,574
11
+ gbc/app/core/env.py,sha256=9ixnfXGDSzoI7gMK5F3n-DHqVr--wc0n0PF5qmG8iR0,1917
12
+ gbc/app/core/executor.py,sha256=eFfxVcOkvtKy9Tg1TPLfh403NHYxS5-63CiYM3F8tZU,3334
13
+ gbc/app/core/guarantee.py,sha256=hDoltUPQleNXMxyAfx13G-tctTLGBP9jf_EWRjBv7Kw,13226
14
+ gbc/app/i18n/__init__.py,sha256=5vrC6Z2wuCBTmKP11PafV6fY2C7SxN4HW9ZK63z_Ku0,1447
15
+ gbc/app/i18n/lang.py,sha256=NZucZuA3Hh3DSiTJSQw32mpzV8LlT8hgwqmfaAM1dDU,2985
16
+ gbc/app/i18n/translate.py,sha256=NA-vBEQ3Pc2YeRsA_xX-kFeZT6fHfXonlkDqNkTVwy4,2957
17
+ gbc/app/intent/__init__.py,sha256=v96XUU2CyukyXD_W526-13Fjqt83UtExblMxMX6MZXY,868
18
+ gbc/app/intent/base.py,sha256=0HtFih8o_hT4Ml9txMUZ_kr9vBI1iTx8PORdVwxWKfE,12706
19
+ gbc/app/intent/cli.py,sha256=nH8K_ug0kkJnTi8gaWv8y38icCxfpwRWiOUGK_y-B0E,4436
20
+ gbc/app/intent/editor.py,sha256=kjWzvXNMsQDTMf5GfyPxfB-6pE_g_lXhnwRzA3NAlm8,4183
21
+ gbc/app/interface/__init__.py,sha256=I4xqrxoGB8PldKRIqY5lMGQzPhiZOqpJRa0PtjBVagI,574
22
+ gbc/app/interface/base.py,sha256=aaNSZls0DP67Eh9Ishgqgo-mWCTEWAg5fGuqNya7eeE,36648
23
+ gbc/app/interface/cli.py,sha256=bF56LuONiUk049Zz2G7bQkY3FrG_BQJvlv6asSpl_MI,24057
24
+ gbc/app/interface/mcp.py,sha256=gWBZDfhgbQETREC_-a5GzCx-lXm81Q9n1n83yOkrwCk,23077
25
+ gbc/app/models/__init__.py,sha256=I4xqrxoGB8PldKRIqY5lMGQzPhiZOqpJRa0PtjBVagI,574
26
+ gbc/app/models/errors.py,sha256=ZATZC0fK5RBCSkE3Jf-SMBdtBrgLV_qoeg-Sm3hWkXo,5734
27
+ gbc/app/models/meta.py,sha256=edRIt5JVRBNKHiqplE8r5ex8_-U2iFEuY6BxgRp54Cc,4753
28
+ gbc/app/models/verify.py,sha256=2i6hBRymYyU8bntxdcCJ-r-wT0uUR0yfy0iZc0JO_k4,2439
29
+ gbc/app/utils/__init__.py,sha256=I4xqrxoGB8PldKRIqY5lMGQzPhiZOqpJRa0PtjBVagI,574
30
+ gbc/app/utils/file_utils.py,sha256=njUkbhPELGDmSTbwjMnbLsGggDOcT-3C6DI2fieP8Gw,925
31
+ gbc/app/utils/gbc_md.py,sha256=G-tVcFxl0YGXzjwT_PqQ0G6qr5-3XKkm27DWq4EnCwQ,4370
32
+ gbc/app/utils/json_model_operator.py,sha256=xVv1WLfytLRT98G_JGHT_hB_orVXvifgWz6PPHROxXw,2501
33
+ gbc/app/utils/safe_file_writer.py,sha256=57_5sUa6dhEyE_wOkJFfPwmMm6gypS04xPw-zAC3qJE,6944
34
+ gbc/assets/editor/index.html,sha256=sqiwu6Gx4ShQBcJpegBVfaXzWC8ET4xTaOLHfEPohfA,13441
35
+ gbc/assets/i18n/catalog/en.json,sha256=u2Ium5ZNzZu4sfrrb6ia5iq_0MHHB8A65mqy3YTPYRY,3608
36
+ gbc/assets/i18n/catalog/zh.json,sha256=iVjfJ3b7gLtWFFD7UKJzn4utFq69FRtRhHR5fEZ1LvM,3651
37
+ gbc/assets/i18n/texts/rules.en.md,sha256=ZF8z_yirFkH2gsRmhNfHP6LVDHGKwtb7T21MEU2qFbc,1656
38
+ gbc/assets/i18n/texts/rules.zh.md,sha256=LdV225wwelzLYckAU6bskU3ePGLrahpbtDSE1Lav-Us,1377
39
+ gbc/assets/i18n/texts/setup.en.md,sha256=_bl3jnulNaWOOKcDhv7pwXphDAL_690TCredRcjYjq0,2817
40
+ gbc/assets/i18n/texts/setup.zh.md,sha256=FMAxeKUXPh-UuMMdW5gq8Bp-YF_TAFf4E0u8KLI-Kyg,2775
41
+ gbc/assets/skills/README.md,sha256=R0D3Uub-QIt6AfygbL5dgdZoVidrtr5Nb4x228zxWZA,737
42
+ gbc/assets/skills/gbc-cli/SKILL.md,sha256=fyXIM-ZefWQ1fH1l1iJurAHAsgTl9PXfYesRIrqEcSs,8355
43
+ guarantee_based_coding-0.2.0.dist-info/licenses/LICENSE,sha256=yVuuHRzgI17MzTVgt3LsHvuX80innw--CmNPDCzO_iw,11358
44
+ guarantee_based_coding-0.2.0.dist-info/METADATA,sha256=dt4vycGpi3LJQ4wUUE6Q-GFNaRIe3wHnKU7LVXiKxqU,4385
45
+ guarantee_based_coding-0.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
46
+ guarantee_based_coding-0.2.0.dist-info/entry_points.txt,sha256=f2j8lLb4FYNVhs8sWlZiH5B81fTmnjhN_aC06E2gxtk,43
47
+ guarantee_based_coding-0.2.0.dist-info/top_level.txt,sha256=oxAntW6an4vJFFPhygPs75vQlezyyttPbBDS_5W3Ltg,4
48
+ guarantee_based_coding-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gbc = gbc.entry:main_cli