guarantee-based-coding 0.2.1__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.
Files changed (73) hide show
  1. guarantee_based_coding-0.2.1/LICENSE +202 -0
  2. guarantee_based_coding-0.2.1/PKG-INFO +108 -0
  3. guarantee_based_coding-0.2.1/README.md +87 -0
  4. guarantee_based_coding-0.2.1/gbc/__init__.py +21 -0
  5. guarantee_based_coding-0.2.1/gbc/app/__init__.py +14 -0
  6. guarantee_based_coding-0.2.1/gbc/app/assets.py +38 -0
  7. guarantee_based_coding-0.2.1/gbc/app/config/__init__.py +14 -0
  8. guarantee_based_coding-0.2.1/gbc/app/config/backups.py +28 -0
  9. guarantee_based_coding-0.2.1/gbc/app/config/base.py +29 -0
  10. guarantee_based_coding-0.2.1/gbc/app/config/executor.py +132 -0
  11. guarantee_based_coding-0.2.1/gbc/app/config/project.py +48 -0
  12. guarantee_based_coding-0.2.1/gbc/app/core/__init__.py +14 -0
  13. guarantee_based_coding-0.2.1/gbc/app/core/env.py +64 -0
  14. guarantee_based_coding-0.2.1/gbc/app/core/executor.py +116 -0
  15. guarantee_based_coding-0.2.1/gbc/app/core/guarantee.py +338 -0
  16. guarantee_based_coding-0.2.1/gbc/app/i18n/__init__.py +43 -0
  17. guarantee_based_coding-0.2.1/gbc/app/i18n/lang.py +166 -0
  18. guarantee_based_coding-0.2.1/gbc/app/i18n/translate.py +80 -0
  19. guarantee_based_coding-0.2.1/gbc/app/intent/__init__.py +20 -0
  20. guarantee_based_coding-0.2.1/gbc/app/intent/base.py +308 -0
  21. guarantee_based_coding-0.2.1/gbc/app/intent/cli.py +124 -0
  22. guarantee_based_coding-0.2.1/gbc/app/intent/editor.py +93 -0
  23. guarantee_based_coding-0.2.1/gbc/app/interface/__init__.py +14 -0
  24. guarantee_based_coding-0.2.1/gbc/app/interface/base.py +877 -0
  25. guarantee_based_coding-0.2.1/gbc/app/interface/cli.py +629 -0
  26. guarantee_based_coding-0.2.1/gbc/app/interface/mcp.py +630 -0
  27. guarantee_based_coding-0.2.1/gbc/app/models/__init__.py +14 -0
  28. guarantee_based_coding-0.2.1/gbc/app/models/errors.py +179 -0
  29. guarantee_based_coding-0.2.1/gbc/app/models/meta.py +92 -0
  30. guarantee_based_coding-0.2.1/gbc/app/models/verify.py +63 -0
  31. guarantee_based_coding-0.2.1/gbc/app/utils/__init__.py +14 -0
  32. guarantee_based_coding-0.2.1/gbc/app/utils/file_utils.py +24 -0
  33. guarantee_based_coding-0.2.1/gbc/app/utils/gbc_md.py +121 -0
  34. guarantee_based_coding-0.2.1/gbc/app/utils/json_model_operator.py +85 -0
  35. guarantee_based_coding-0.2.1/gbc/app/utils/safe_file_writer.py +158 -0
  36. guarantee_based_coding-0.2.1/gbc/assets/editor/index.html +299 -0
  37. guarantee_based_coding-0.2.1/gbc/assets/i18n/catalog/en.json +98 -0
  38. guarantee_based_coding-0.2.1/gbc/assets/i18n/catalog/zh.json +97 -0
  39. guarantee_based_coding-0.2.1/gbc/assets/i18n/texts/rules.en.md +65 -0
  40. guarantee_based_coding-0.2.1/gbc/assets/i18n/texts/rules.zh.md +42 -0
  41. guarantee_based_coding-0.2.1/gbc/assets/i18n/texts/setup.en.md +87 -0
  42. guarantee_based_coding-0.2.1/gbc/assets/i18n/texts/setup.zh.md +78 -0
  43. guarantee_based_coding-0.2.1/gbc/assets/skills/README.md +16 -0
  44. guarantee_based_coding-0.2.1/gbc/assets/skills/gbc-cli/SKILL.md +143 -0
  45. guarantee_based_coding-0.2.1/gbc/entry.py +162 -0
  46. guarantee_based_coding-0.2.1/guarantee_based_coding.egg-info/PKG-INFO +108 -0
  47. guarantee_based_coding-0.2.1/guarantee_based_coding.egg-info/SOURCES.txt +71 -0
  48. guarantee_based_coding-0.2.1/guarantee_based_coding.egg-info/dependency_links.txt +1 -0
  49. guarantee_based_coding-0.2.1/guarantee_based_coding.egg-info/entry_points.txt +2 -0
  50. guarantee_based_coding-0.2.1/guarantee_based_coding.egg-info/requires.txt +3 -0
  51. guarantee_based_coding-0.2.1/guarantee_based_coding.egg-info/top_level.txt +1 -0
  52. guarantee_based_coding-0.2.1/pyproject.toml +50 -0
  53. guarantee_based_coding-0.2.1/setup.cfg +4 -0
  54. guarantee_based_coding-0.2.1/tests/test_assets.py +43 -0
  55. guarantee_based_coding-0.2.1/tests/test_cli_commands.py +582 -0
  56. guarantee_based_coding-0.2.1/tests/test_config_project.py +93 -0
  57. guarantee_based_coding-0.2.1/tests/test_core_executor.py +106 -0
  58. guarantee_based_coding-0.2.1/tests/test_env_actions.py +124 -0
  59. guarantee_based_coding-0.2.1/tests/test_errors_i18n.py +71 -0
  60. guarantee_based_coding-0.2.1/tests/test_executor_externalized.py +74 -0
  61. guarantee_based_coding-0.2.1/tests/test_gbc_md.py +124 -0
  62. guarantee_based_coding-0.2.1/tests/test_guarantee_crud.py +216 -0
  63. guarantee_based_coding-0.2.1/tests/test_guarantee_deps.py +199 -0
  64. guarantee_based_coding-0.2.1/tests/test_guarantee_verify.py +126 -0
  65. guarantee_based_coding-0.2.1/tests/test_i18n.py +183 -0
  66. guarantee_based_coding-0.2.1/tests/test_intent_base.py +75 -0
  67. guarantee_based_coding-0.2.1/tests/test_interface_base_crud.py +380 -0
  68. guarantee_based_coding-0.2.1/tests/test_interface_base_deps.py +278 -0
  69. guarantee_based_coding-0.2.1/tests/test_interface_base_query.py +145 -0
  70. guarantee_based_coding-0.2.1/tests/test_interface_base_refactor.py +330 -0
  71. guarantee_based_coding-0.2.1/tests/test_json_model_and_file_utils.py +129 -0
  72. guarantee_based_coding-0.2.1/tests/test_mcp_doc_tools.py +49 -0
  73. guarantee_based_coding-0.2.1/tests/test_safe_file_writer.py +136 -0
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: guarantee-based-coding
3
+ Version: 0.2.1
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,87 @@
1
+ # Guarantee-Based Coding (GBC)
2
+
3
+ **与其指望 AI 更聪明,不如让再笨的 agent 也改不坏你的代码。**
4
+
5
+ **English version: [docs/en/README.md](docs/en/README.md)**
6
+
7
+ GBC 把「这次改动会不会悄悄碰坏别处」从一种担心,变成可以当场验证的事实:你在意的行为被登记成
8
+ 一条条带测试的**保证(guarantee)**,每次改完一跑——全绿就安心,有红就精确告诉你碰坏了谁、谁在
9
+ 依赖它。
10
+
11
+ ---
12
+
13
+ ## 🚀 快速开始
14
+
15
+ ```bash
16
+ pipx install guarantee-based-coding
17
+ gbc setup # 打印本地化接线指南:怎么把 MCP / skills 接入你的 agent
18
+ ```
19
+
20
+ 装好后 `gbc` 命令即在 PATH 上。完整上手(安装 → 接入 agent → 冒烟验证)见
21
+ **[docs/zh/quick-start.md](./docs/zh/quick-start.md)**。
22
+
23
+ 想让 agent 替你接入?把 **[docs/zh/onboarding-agent.md](./docs/zh/onboarding-agent.md)** 交给它。
24
+
25
+ ---
26
+
27
+ > 🚧 **交互式 demo 施工中**:旧的演示套件已废弃,新的交互式演示正在筹备。目前请直接读文档上手。
28
+
29
+ ---
30
+
31
+ ## 📚 文档
32
+
33
+ | 你想 | 看这里 |
34
+ |------|--------|
35
+ | 装好并跑起来 | [快速开始](./docs/zh/quick-start.md) |
36
+ | 懂 GBC 在保护什么 | [核心概念](./docs/zh/concepts.md) |
37
+ | 在 GBC 下安全改代码 | [工作流](./docs/zh/workflow.md) |
38
+ | 查命令 / 工具 / executor | [参考手册](./docs/zh/reference.md) |
39
+ | 你是 agent,被要求接入 GBC | [Agent 上手](./docs/zh/onboarding-agent.md) |
40
+
41
+ English docs: [docs/en/](./docs/en/)。
42
+
43
+ ---
44
+
45
+ ## 核心想法
46
+
47
+ 代码之间的依赖本质上是一组**保证**。模块 A 依赖模块 B,不是依赖它的实现细节,而是依赖它的某些
48
+ 行为承诺——返回值的类型、格式、语义。把这些保证从隐含变成**显式、可执行、可验证**,正确性的判定
49
+ 就从「AI 觉得自己改对了」变成「所有被依赖的保证仍通过」——一个可机械验证的布尔条件。
50
+
51
+ ![无 GBC vs 有 GBC](docs/assets/workflow-comparison.svg)
52
+
53
+ GBC **不是**另一个要挑战 Cursor / Aider 的 AI 编程助手,而是填补它们在大型项目里缺的一环:
54
+ **机器可判定的变更边界**。它与那些 agent 配合——改前查依赖树,改后必须跑通所有相关保证;也区别
55
+ 于 CI——CI 是事后的,GBC 是准入制的门禁,错误在落地前就被拦在 agent 的上下文里。
56
+
57
+ 完整概念、架构图、与已有概念(Design by Contract / 测试)的区别,见
58
+ [核心概念](./docs/zh/concepts.md)。
59
+
60
+ ---
61
+
62
+ ## 当前状态
63
+
64
+ GBC 目前是一个可用的 Python 分发包(`pipx install guarantee-based-coding`),自身用 GBC 管理自己的
65
+ `.gbc/`(dogfooding):
66
+
67
+ - ✅ 核心保证机制(具名 id、多对一、出生即绿、退休保护、反查)
68
+ - ✅ 多语言 executor 配置
69
+ - ✅ CLI + MCP 双接口(含意图文档 `gbc doc` 全进 MCP)
70
+ - ✅ 意图文档子系统(`gbc doc` / web 编辑器)
71
+ - ✅ 随包分发的接线指南(`gbc setup`)与 CLI-only agent 的 skill 包
72
+ - ✅ 原子文件写入 + 备份
73
+
74
+
75
+ **诚实的局限**:保护能力上限 = 测试质量(测试只走 happy path 就是虚假安全感);依赖需主动登记,
76
+ 覆盖率随项目增长需持续投入;每次验证真实跑测试,有一定延迟。详见
77
+ [核心概念 · 局限性](./docs/zh/concepts.md#局限性诚实地说)。
78
+
79
+ ---
80
+
81
+ ## 许可
82
+
83
+ 本项目采用 [Apache-2.0](./LICENSE) 许可证。
84
+
85
+ ## 联系
86
+
87
+ 如果你对这个方向感兴趣,欢迎 star、issue 或者直接联系我。
@@ -0,0 +1,21 @@
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 — Guarantee-Based Coding.
16
+
17
+ 让代码在不被完全理解的情况下也能被安全修改:把模块间依赖从隐含变成
18
+ 显式、可执行、可验证的保证。本包是该方法的实现,也是它的第一个使用者。
19
+ """
20
+
21
+ __version__ = "0.2.1"
@@ -0,0 +1,14 @@
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
+
@@ -0,0 +1,38 @@
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
+ """静态资源定位的单一入口。
16
+
17
+ 所有随包分发的**数据**(i18n catalog/texts、editor 前端)集中在 `gbc/assets/`
18
+ 下,与**代码**彻底分离。任何模块要读资源都从这里取路径,不各自
19
+ `Path(__file__).parent` ——加一类资源只需在此登记一处 + 打包声明一条。
20
+
21
+ 打包:`pyproject.toml` 的 `[tool.setuptools.package-data]` 以 `"gbc" = ["assets/**"]`
22
+ 把整个 assets 树纳入 wheel(散在各子包时易漏声明,这正是集中的理由)。
23
+ """
24
+ from pathlib import Path
25
+
26
+ # assets 根:本文件在 gbc/app/assets.py,上溯到 gbc/ 再进 assets/。
27
+ ASSETS_DIR = Path(__file__).resolve().parent.parent / "assets"
28
+
29
+ # i18n 短消息查表 与 长文本资源。
30
+ I18N_CATALOG_DIR = ASSETS_DIR / "i18n" / "catalog"
31
+ I18N_TEXTS_DIR = ASSETS_DIR / "i18n" / "texts"
32
+
33
+ # 意图编辑器 web 前端静态页。
34
+ EDITOR_FRONTEND_DIR = ASSETS_DIR / "editor"
35
+
36
+ # 给 CLI-only agent 的预组 skills(教 agent 怎么调 gbc 子命令,等价于 MCP 工具描述)。
37
+ # gbc setup 只告知此目录坐标,由用户自行放到其 agent 读 skill 的位置。
38
+ SKILLS_DIR = ASSETS_DIR / "skills"
@@ -0,0 +1,14 @@
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
+
@@ -0,0 +1,28 @@
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
+ import os
16
+ from pathlib import Path
17
+
18
+ from gbc.app.config.base import PROJECT_ROOT
19
+
20
+ # 初始化备份数量
21
+ def _init_meta_backups() -> int:
22
+ var = os.environ.get("GBC_META_BACKUPS", None)
23
+ if var and var.isdigit():
24
+ return int(var)
25
+
26
+ return 0
27
+
28
+ META_BACKUPS = _init_meta_backups()
@@ -0,0 +1,29 @@
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
+ import os
16
+ from pathlib import Path
17
+
18
+
19
+ def get_project_root() -> Path:
20
+ """获取工具仓根目录。
21
+
22
+ 注意:文件已迁入 `gbc/app/config/base.py`,比旧布局(`app/config/base.py`)多一层
23
+ `gbc/`,故上溯四层(base.py -> config -> app -> gbc -> 仓根)。
24
+ """
25
+ return Path(__file__).resolve().parent.parent.parent.parent
26
+
27
+
28
+ PROJECT_ROOT = get_project_root()
29
+ CONFIG_DIR = PROJECT_ROOT / "config"