agentseed-mcp 0.3.0

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 (76) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/LICENSE +202 -0
  3. package/README.ja.md +320 -0
  4. package/README.md +318 -0
  5. package/README.zh.md +306 -0
  6. package/bin/cli.js +37 -0
  7. package/mcp.json +12 -0
  8. package/package.json +30 -0
  9. package/plugin.json +22 -0
  10. package/server/.agentseed/verification-log.jsonl +2 -0
  11. package/server/__pycache__/guard_cli.cpython-313.pyc +0 -0
  12. package/server/__pycache__/guard_engine.cpython-313.pyc +0 -0
  13. package/server/__pycache__/test_cli.cpython-313-pytest-9.1.1.pyc +0 -0
  14. package/server/__pycache__/test_cli.cpython-313.pyc +0 -0
  15. package/server/__pycache__/test_features.cpython-313-pytest-9.1.1.pyc +0 -0
  16. package/server/__pycache__/test_features.cpython-313.pyc +0 -0
  17. package/server/__pycache__/test_guard.cpython-313-pytest-9.1.1.pyc +0 -0
  18. package/server/__pycache__/test_guard.cpython-313.pyc +0 -0
  19. package/server/__pycache__/test_hook.cpython-313-pytest-9.1.1.pyc +0 -0
  20. package/server/__pycache__/test_hook.cpython-313.pyc +0 -0
  21. package/server/__pycache__/test_manifests.cpython-313-pytest-9.1.1.pyc +0 -0
  22. package/server/__pycache__/test_manifests.cpython-313.pyc +0 -0
  23. package/server/__pycache__/test_server.cpython-313-pytest-9.1.1.pyc +0 -0
  24. package/server/__pycache__/test_server.cpython-313.pyc +0 -0
  25. package/server/engine/__init__.py +64 -0
  26. package/server/engine/__pycache__/__init__.cpython-313.pyc +0 -0
  27. package/server/engine/__pycache__/audit.cpython-313.pyc +0 -0
  28. package/server/engine/__pycache__/config.cpython-313.pyc +0 -0
  29. package/server/engine/__pycache__/hallucination.cpython-313.pyc +0 -0
  30. package/server/engine/__pycache__/imports.cpython-313.pyc +0 -0
  31. package/server/engine/__pycache__/plugin.cpython-313.pyc +0 -0
  32. package/server/engine/__pycache__/sandbox.cpython-313.pyc +0 -0
  33. package/server/engine/__pycache__/schema.cpython-313.pyc +0 -0
  34. package/server/engine/__pycache__/symbols.cpython-313.pyc +0 -0
  35. package/server/engine/__pycache__/version.cpython-313.pyc +0 -0
  36. package/server/engine/audit.py +84 -0
  37. package/server/engine/config.py +131 -0
  38. package/server/engine/hallucination.py +254 -0
  39. package/server/engine/imports.py +136 -0
  40. package/server/engine/plugin.py +367 -0
  41. package/server/engine/sandbox.py +287 -0
  42. package/server/engine/schema.py +193 -0
  43. package/server/engine/symbols.py +984 -0
  44. package/server/engine/version.py +17 -0
  45. package/server/guard_cli.py +455 -0
  46. package/server/guard_engine.py +111 -0
  47. package/server/guard_hook.py +404 -0
  48. package/server/guard_server.py +472 -0
  49. package/server/requirements.txt +7 -0
  50. package/server/test_cli.py +132 -0
  51. package/server/test_features.py +426 -0
  52. package/server/test_guard.py +828 -0
  53. package/server/test_hook.py +331 -0
  54. package/server/test_manifests.py +70 -0
  55. package/server/test_server.py +247 -0
  56. package/skills/verify-before-code/SKILL.ja.md +116 -0
  57. package/skills/verify-before-code/SKILL.md +140 -0
  58. package/skills/verify-before-code/SKILL.zh.md +117 -0
  59. package/skills/verify-before-code/references/DEFAULT-NORMS.md +52 -0
  60. package/skills/verify-before-code/references/HALLUCINATION-PATTERNS.ja.md +121 -0
  61. package/skills/verify-before-code/references/HALLUCINATION-PATTERNS.md +166 -0
  62. package/skills/verify-before-code/references/HALLUCINATION-PATTERNS.zh.md +145 -0
  63. package/skills/verify-before-code/references/PROMPT-POOL.ja.md +248 -0
  64. package/skills/verify-before-code/references/PROMPT-POOL.md +282 -0
  65. package/skills/verify-before-code/references/PROMPT-POOL.zh.md +252 -0
  66. package/skills/verify-before-code/references/SDD-CONTRACT.ja.md +61 -0
  67. package/skills/verify-before-code/references/SDD-CONTRACT.md +66 -0
  68. package/skills/verify-before-code/references/SDD-CONTRACT.zh.md +58 -0
  69. package/skills/verify-before-code/references/VENDOR-SOLUTIONS.ja.md +62 -0
  70. package/skills/verify-before-code/references/VENDOR-SOLUTIONS.md +62 -0
  71. package/skills/verify-before-code/references/VENDOR-SOLUTIONS.zh.md +54 -0
  72. package/skills/verify-before-code/references/VERIFICATION-CHECKLIST.ja.md +68 -0
  73. package/skills/verify-before-code/references/VERIFICATION-CHECKLIST.md +73 -0
  74. package/skills/verify-before-code/references/VERIFICATION-CHECKLIST.zh.md +68 -0
  75. package/skills/verify-before-code/scripts/check.ps1 +52 -0
  76. package/skills/verify-before-code/scripts/check.sh +44 -0
package/README.ja.md ADDED
@@ -0,0 +1,320 @@
1
+ <div align="center">
2
+
3
+ <img src="docs/logo.png" width="96" alt="AgentSeed logo">
4
+
5
+ # AgentSeed
6
+
7
+ **AI コーディングエージェントのための反幻覚ゲート。**
8
+
9
+ AI は存在しない API を捏造し、何も実行せずに「テスト全部通った」と言い、
10
+ 自信満々に偽のコードを納品します。**AgentSeed は「完了」と宣言する前に
11
+ それを止めるゲート**——ゼロ依存のプラグインで、コードを検証してから
12
+ 「完了」にします。「完了」= **観測された事実**であり、自己申告ではありません。
13
+
14
+ [![License](https://img.shields.io/badge/license-Apache_2.0-green)](LICENSE)
15
+ [![Version](https://img.shields.io/badge/version-0.3.0-blue)](https://gitcode.com/badhope/AgentSeed/releases)
16
+ [![CI](https://github.com/Morningstar202604/AgentSeed/actions/workflows/ci.yml/badge.svg)](https://github.com/Morningstar202604/AgentSeed/actions/workflows/ci.yml)
17
+ [![Platforms](https://img.shields.io/badge/platform-Cursor%20%7C%20VS%20Code%20%7C%20Claude%20Code%20%7C%20Copilot-blue)](https://agent-plugins.org)
18
+
19
+ [English](./README.md) · [中文](./README.zh.md) · **日本語**
20
+
21
+ ⭐ **気に入ったら Star を——幻覚コードを出荷する前に、開発者がガードレールに
22
+ 出会える最良のシグナルです。**
23
+
24
+ </div>
25
+
26
+ ---
27
+
28
+ ## なぜ必要か
29
+
30
+ LLM は幻覚を起こします——コードではそれは**捏造 API・未定義の識別子・
31
+ 偽のテスト合格・過剰な宣言**を意味します:
32
+
33
+ - **15.1%** のコード幻覚は、存在しない・インポートされていない API を呼ぶこと
34
+ ([arXiv:2404.00971](https://arxiv.org/abs/2404.00971))。
35
+ - **10% 未満**の幻覚コードしかテストを落とさない——**約 90% は CI をすり抜ける**
36
+ ([arXiv:2404.00971](https://arxiv.org/abs/2404.00971))。
37
+ - **60%+** のモデル出力エラーは**見た目では検証不能**(FAVA、[SoK](https://arxiv.org/abs/2502.18468))。
38
+
39
+ プロンプトだけのガードレールは「柔らかい」:モデルは検証に同意したふりをして
40
+ スキップできます。**AgentSeed は指示を「硬いゲート」に結びつけます**——
41
+ 証拠はモデルの自己申告ではなく、実行されたコードから来ます。
42
+
43
+ ## 30 秒でわかる AgentSeed
44
+
45
+ ドロップインの [Agent Plugins](https://agent-plugins.org) 1.0.0 プラグイン
46
+ (Skill + MCP サーバー + 任意のクライアント Hook + CI ゲート)が約束する
47
+ 3 つのこと:
48
+
49
+ | 約束 | 実現方法 |
50
+ | --- | --- |
51
+ | **🚫 API を捏造しない** | `verify_code` が **12+ 言語**のコードを解析し、「呼ばれたのに定義もインポートもされていない」シンボルを検出 |
52
+ | **🚫 偽の「完了」を出さない** | `scan_hallucination` がスタブ・過剰宣言・捏造主張を(**英語+中国語+CJK**)検出;`sandbox_run` が実行時主張を実際に実行して証明 |
53
+ | **🚫 検証をスキップさせない** | Skill がワークフローを制約、**クライアント Hook** が `Write`/`Edit` を未検証ファイルでブロック、`guard_cli gate` が CI で同じルールを終了コードで強制 |
54
+
55
+ 1.0.0 仕様が意図的に残した 2 つの穴も埋めます:
56
+
57
+ | Agent Plugins 1.0.0 の穴 | AgentSeed の答え |
58
+ | --- | --- |
59
+ | 強制メカニズムがない(skill は任意) | `verify-before-code` skill + 任意の**クライアント強制 Hook** で検証をスキップ不可に |
60
+ | 公式 linter がない | `check_plugin` は**最初の厳格な 1.0.0 linter**——しかも AgentSeed 自身が自分の linter を通る(`ok: true`) |
61
+
62
+ ## 幻覚を捕まえる現場を見る
63
+
64
+ ```python
65
+ # エージェントが「書き終えた」コード。magic_unknown() を呼ぶ——
66
+ # 存在せず、インポートもされていない API:
67
+
68
+ def f():
69
+ return magic_unknown() # ← 幻覚 API
70
+
71
+ # タスクが「完了」になる前に:
72
+ $ verify_code(source=..., language="python")
73
+ {
74
+ "language": "python",
75
+ "suspects": ["magic_unknown"] # ← 検出、ブロック
76
+ }
77
+ ```
78
+
79
+ ```text
80
+ # 「完了」宣言も生き残れない:
81
+ "The feature is production ready, all tests pass. Trust me."
82
+
83
+ $ scan_hallucination(source=...)
84
+ {
85
+ "hits": [
86
+ {"word": "all tests pass", "group": "oversold", "line": 1},
87
+ {"word": "production ready", "group": "oversold", "line": 1},
88
+ {"word": "trust me", "group": "oversold", "line": 1}
89
+ ],
90
+ "clean": false # ← 検出、ブロック
91
+ }
92
+ ```
93
+
94
+ 判定は**約束ではなく計測値**:シード固定の合成コーパス(5 欠陥クラス、
95
+ 欠陥 100 + クリーン 40 モジュール)で **precision 1.0 · recall 1.0**
96
+ (tp=100, fp=0, fn=0)——回帰テストでロックイン済み。
97
+ 方法と正直な限界は [docs/BENCHMARK.md](./docs/BENCHMARK.md)。
98
+
99
+ ## ゲートの仕組み
100
+
101
+ 1. **コーディング前** — SDD 契約を読み、一文で宣言する。
102
+ 2. **実装** — 本物のコードだけ:プレースホルダーも捏造 API も禁止。
103
+ 3. **「完了」の前** — `verify_code` + `scan_hallucination` を実行;実行時主張は
104
+ `sandbox_run` で証明;構造は `schema_validate` で検証。
105
+ 4. **言語監査** — 完了報告に証拠を添付;過剰語彙は禁止。
106
+ 5. **すべてのチェックが通った時だけ**「完了」を許す。
107
+
108
+ ## クイックスタート
109
+
110
+ **A — リリースをダウンロード(git 不要):**
111
+
112
+ ```bash
113
+ # https://gitcode.com/badhope/AgentSeed/releases から最新アセットを取得
114
+ # またはインストーラーでクライアントに配線:
115
+ bash install.sh --client auto --hooks # macOS / Linux
116
+ ./install.ps1 -Client auto -Hooks # Windows PowerShell
117
+ # --client: claude | opencode | cursor | manual
118
+ # --hooks / -Hooks: Claude Code 強制 Hook も登録
119
+ ```
120
+
121
+ **B — クローン:**
122
+
123
+ ```bash
124
+ git clone https://gitcode.com/badhope/AgentSeed.git
125
+ # ミラー:https://gitcode.com/badhope/AgentSeed · https://gitee.com/badhope/AgentSeed
126
+ ```
127
+
128
+ 1. `AgentSeed/` ディレクトリを Agent Plugins 対応クライアント(Cursor、
129
+ VS Code、Claude Code、Copilot…)に**ドロップ**する。ビルドもインストールも不要。
130
+ 2. クライアントが `plugin.json` + `mcp.json` から `verify-before-code` skill と
131
+ `agentseed` MCP サーバーを自動発見。
132
+ 3. **これだけ。** 以降すべてのコーディングタスクがゲートされます:
133
+ 契約 → 実装 → 検証 → 証拠。
134
+
135
+ 単体実行、または人間の PR にも同じ CI ゲート:
136
+
137
+ ```bash
138
+ python3 server/guard_engine.py # セルフチェック
139
+ python3 -m unittest discover -s server # 160+ ユニットテスト
140
+ python3 server/guard_cli.py gate --root . # CI 相当のハードゲート
141
+ python3 server/guard_cli.py check . --ci # プラグイン適合のみ
142
+ python3 server/guard_cli.py scan src/ --strict
143
+ ```
144
+
145
+ > **Windows 注記:** `mcp.json` は `python3` でサーバーを起動します。多くの
146
+ > Windows 環境ではそのエイリアスは Microsoft Store のスタブです。`command` を
147
+ > `["python", "server/guard_server.py"]` に変更するか、インタプリタの絶対パスを
148
+ > 指定してください。
149
+
150
+ ## 8 つの MCP ツール
151
+
152
+ 必須依存**ゼロ**——純 Python 標準ライブラリ。オプション拡張で 2 ツールが
153
+ 業界標準エンジンにアップグレードされます(下記)。
154
+
155
+ | ツール | ブロックするもの | 技術 |
156
+ | --- | --- | --- |
157
+ | `verify_code` | 捏造 API / 未定義シンボル | Python AST + 設定駆動の汎用語彙パス(12+ 言語) |
158
+ | `check_contract` | 仕様に違反するコード | requires/prohibits 契約チェック |
159
+ | `check_imports` | 幻覚パッケージ(slopsquatting) | stdlib + known_packages ホワイトリスト検証 |
160
+ | `scan_hallucination` | プレースホルダー、誇張、捏造 | 3 グループ 28+ シグナル、EN + CJK |
161
+ | `check_plugin` | 不適合なプラグイン | 厳格 1.0.0 linter |
162
+ | `sandbox_run` | 実行せずに「テスト合格」 | 決定的実行チャネル(メモリ有界出力) |
163
+ | `schema_validate` | 不正な構造化出力 | JSON Schema 検証 |
164
+ | `record_verification` | 証跡の永続化欠如 | `PLUGIN_DATA` 配下の JSONL 監査トレイル |
165
+
166
+ ### 言語カバレッジ(正直な範囲)
167
+
168
+ | 言語 | `verify_code` 解析 |
169
+ | --- | --- |
170
+ | Python | フル AST スコープウォーク(pyflakes 時はマージ)、行番号付き |
171
+ | TypeScript / JavaScript | 語彙正規表現パス(誤検出クラスを明記) |
172
+ | Go · Rust · Java · C · C++ · C# · PHP · Ruby · Kotlin · Swift | 設定駆動の汎用語彙パス |
173
+ | その他の言語 | `LangSpec` レジストリに追加するだけ——エンジン変更不要 |
174
+
175
+ 正直な限界:属性呼び出し(`obj.m()`)、マクロ、ファイル横断シンボルは解析しません。
176
+ Ruby の括弧なし呼び出しは対応済み。
177
+
178
+ 正直な限界:属性呼び出し(`obj.m()`)、マクロ、ファイル横断シンボルは解析しません。
179
+
180
+ ### 他の言語も本当に検出する——実測済み
181
+
182
+ 同じルールが全登録言語に適用されます:「未定義のシンボルの裸呼び出し」は、構文が何であれ
183
+ 幻覚です:
184
+
185
+ ```python
186
+ # Go detect_undefined_symbols("func main() { process_data() }", "go") -> ["process_data"]
187
+ # Rust fn main() { let x = load_config() } -> ["load_config"]
188
+ # Java class A { void m() { connect_db() } } -> ["connect_db"]
189
+ # C int main() { ghost(); return 0; } -> ["ghost"]
190
+ # Kotlin fun main() { fetch_users() } -> ["fetch_users"]
191
+ # Swift func run() { connect() } -> ["connect"]
192
+ # Ruby def run; authenticate; end -> ["authenticate"]
193
+ # TypeScript function run() { connectDb() } -> ["connectDb"]
194
+ ```
195
+
196
+ Go · Rust · Java · C · C++ · C# · PHP · Ruby · Kotlin · Swift · TypeScript で実測——
197
+ 全言語が捏造呼び出しを検出し、各言語のクリーンコードは**誤検出ゼロ**。
198
+
199
+
200
+ ## クライアント強制 Hook モード
201
+
202
+ Skill は「説得」、**Hook はクライアント境界で「強制」**します。AgentSeed を
203
+ Claude Code hook として登録すると、すべての `Write`/`Edit`/`MultiEdit` が
204
+ 自動スキャンされます——どのプロンプトもスキップできません:
205
+
206
+ ```bash
207
+ python3 server/guard_hook.py register --client claude # 冪等、settings にマージ
208
+ python3 server/guard_hook.py --file path/to/source.py # 任意のファイルを直接スキャン
209
+ ```
210
+
211
+ - **PreToolUse** は内容がディスクに書かれる**前**に検査。ブロック検出は終了コード
212
+ `2` で、エージェントは指摘された行を直す必要があります。
213
+ - **PostToolUse** はインライン内容のない書き込みパスで保存後ファイルを再検査。
214
+ - **失敗ポリシー(正直な範囲):** インフラ問題(stdin 不正・ファイル不可読・
215
+ 未知のツール形状)は決して作業をブロックしません(fail-open)。ブロックするのは
216
+ 検出結果だけです。
217
+
218
+ ## プラットフォーム対応
219
+
220
+ | クライアント | 状態 | 備考 |
221
+ | --- | --- | --- |
222
+ | Claude Code | ✅ 検証済み | skills + MCP + 任意の強制 Hook |
223
+ | opencode | ✅ 検証済み | `~/.config/opencode/opencode.json` |
224
+ | Cursor | ⚪ 仕様互換* | プロジェクトへコピー;安定プラグインディレクトリ未確定 |
225
+ | VS Code (+Copilot) | ⚪ 仕様互換* | MCP サポートは展開中 |
226
+ | Cline / Windsurf | ⚪ 仕様互換* | stdio サーバーエントリをそのままマッピング |
227
+
228
+ \* 正直な注記:形式は仕様互換・動作見込みですが、メンテナー未実測。
229
+ 検証できたら PR でこの表を更新してください。
230
+
231
+ ## オプション依存
232
+
233
+ ```bash
234
+ pip install -r server/requirements.txt
235
+ ```
236
+
237
+ | 拡張 | アップグレード内容 | 未導入時 |
238
+ | --- | --- | --- |
239
+ | `jsonschema` | `schema_validate` → 完全 Draft 2020-12 | 内蔵サブセット検証 |
240
+ | `pyflakes` | `verify_code` → pyflakes F821 解析 | 内蔵 AST ウォーク |
241
+ | `pyyaml` | SKILL.md frontmatter → 完全 YAML | 内蔵ライトパーサー |
242
+
243
+ ## 設定(`agentseed.config.json`)
244
+
245
+ | キー | 効果 |
246
+ | --- | --- |
247
+ | `allowlist` | スキャン除外(内蔵のテスト慣用句リストを置換) |
248
+ | `severities` | グループ別の重大度上書き(`error` \| `warning` \| `info`) |
249
+ | `timeout` | デフォルト `sandbox_run` タイムアウト(秒、1–120) |
250
+ | `extra_tokens` | 実行時に幻覚ワードプールを拡張 |
251
+ | `suppress_symbols` | `verify_code` が決してフラグしない名前(`suppressed` に表示) |
252
+ | `known_packages` | `check_imports` が既知とするパッケージ(stdlib + 一般的 + このリスト) |
253
+ | `sandbox_allowed_prefixes` | `sandbox_run` が起動できる**実行ファイルのホワイトリスト**;PATH 解決・区切り境界強制(省略=無制限) |
254
+ | `sandbox_env` | `"inherit"` \| `"scrub"` —— `scrub` は認証情報らしき環境変数を起動前に除去 |
255
+
256
+ 未知キーは stderr に警告——タイポは決して黙殺されません。
257
+
258
+ > ⚠️ **セキュリティ注記:** `sandbox_run` はユーザーの権限で実プロセスを実行します。
259
+ > クライアントはユーザー承認の後ろに置いてください。共有/CI 環境では
260
+ > `sandbox_allowed_prefixes` を設定。コマンドは実行前に `PATH` 解決され、悪意ある
261
+ > `cwd` がホワイトリスト名を偽装できません。未解決・未一致のコマンドは実行せず
262
+ > 拒否(終了コード -10)。
263
+
264
+ ## 互換性とグレースフルデグラデーション
265
+
266
+ | ホスト能力 | 得られるもの |
267
+ | --- | --- |
268
+ | フル Agent Plugins | ドロップイン:skill + MCP 自動発見、`${PLUGIN_DATA}` 設定尊重 |
269
+ | MCP 対応クライアント | 登録で 8 ツールすべて |
270
+ | skill のみのクライアント | skill ワークフロー;検証は `guard_cli.py` を shell 経由で実行 |
271
+ | ターミナル / CI | 終了コード付き CLI ゲート |
272
+
273
+ ## 内蔵ガードレールライブラリ(EN / 中文 / 日本語)
274
+
275
+ `PROMPT-POOL`(20+ のコピペ即使用プロンプト)· `HALLUCINATION-PATTERNS`
276
+ (5 クラス失敗モードカタログ)· `VERIFICATION-CHECKLIST`(実行可能な完了
277
+ チェックリスト)· `SDD-CONTRACT`(全タスクが満たすべき契約)·
278
+ `VENDOR-SOLUTIONS`(ベンダー手法の導入マップ)。
279
+
280
+ ## 代替案との比較
281
+
282
+ | | プロンプト専用 skill | 静的 import linter(MCP) | **AgentSeed** |
283
+ | --- | --- | --- | --- |
284
+ | コードに触れる | ❌ プロンプトのみ | ✅ import グラフ | ✅ AST + 語彙(12+ 言語) |
285
+ | 検証ツールを実行 | ❌ | lint ゲート | ✅ 8 MCP ツール(sandbox 含む) |
286
+ | 幻覚言語スキャン | ❌ | ❌ | ✅ stub/oversold/fabricated、EN + CJK |
287
+ | 強制力 | 軟(skill 文面) | CI ゲート | **硬**:skill + MCP + hook + CLI 終了コード |
288
+ | 1.0.0 適合 linter | ❌ | ❌ | ✅ 最初 |
289
+
290
+ ## FAQ
291
+
292
+ **特定の LLM が必要?** いいえ——クライアント非依存・モデル非依存。ゲートは
293
+ skill + MCP + hook + CI が実行するもので、モデルには依存しません。
294
+
295
+ **ゼロ依存?** はい。MCP サーバーは純 Python 標準ライブラリです。
296
+
297
+ **既存の AGENTS.md / CLAUDE.md と共存できる?** できます——補完関係です。
298
+ あちらはプロジェクト事実(散文・説得力)、AgentSeed は行動契約とハード強制を
299
+ 担います。
300
+
301
+ **新しい言語にどう拡張する?** `server/engine/symbols.py` に `LangSpec` を
302
+ 1 件追加するだけ——設定のみ、エンジン変更なし。
303
+
304
+ ## コントリビューション
305
+
306
+ Issue・PR・アイデア歓迎——未収録の幻覚パターンも issue でどうぞ。
307
+ 詳細は [CONTRIBUTING.md](./CONTRIBUTING.md)。
308
+
309
+ ## ライセンス
310
+
311
+ Apache-2.0 © AgentSeed。 [LICENSE](./LICENSE)。
312
+
313
+ ---
314
+
315
+ <div align="center">
316
+
317
+ ⭐ **AgentSeed が幻覚コードの出荷を防いだなら、Star を——それは「ガードレールは
318
+ 役に立つ」という最良のシグナルです。**
319
+
320
+ </div>
package/README.md ADDED
@@ -0,0 +1,318 @@
1
+ <div align="center">
2
+
3
+ <img src="docs/logo.png" width="96" alt="AgentSeed logo">
4
+
5
+ # AgentSeed
6
+
7
+ **The anti-hallucination gate for AI coding agents.**
8
+
9
+ AI agents invent APIs. They claim "all tests pass" without running anything.
10
+ They ship confident, fabricated code. **AgentSeed is the gate that stops it** —
11
+ a zero-dependency plugin that verifies code *before* it is marked done, so
12
+ "done" means *observed fact*, not self-report.
13
+
14
+ [![License](https://img.shields.io/badge/license-Apache_2.0-green)](LICENSE)
15
+ [![Version](https://img.shields.io/badge/version-0.3.0-blue)](https://gitcode.com/badhope/AgentSeed/releases)
16
+ [![CI](https://github.com/Morningstar202604/AgentSeed/actions/workflows/ci.yml/badge.svg)](https://github.com/Morningstar202604/AgentSeed/actions/workflows/ci.yml)
17
+ [![Platforms](https://img.shields.io/badge/platform-Cursor%20%7C%20VS%20Code%20%7C%20Claude%20Code%20%7C%20Copilot-blue)](https://agent-plugins.org)
18
+
19
+ **English** · [中文](./README.zh.md) · [日本語](./README.ja.md)
20
+
21
+ ⭐ **Like this project? Star it — it helps developers find guardrails before they ship hallucinated code.**
22
+
23
+ </div>
24
+
25
+ ---
26
+
27
+ ## Why you need this
28
+
29
+ LLMs hallucinate — and in code that means **invented APIs, undefined
30
+ identifiers, fake test passes, and confident overclaims**:
31
+
32
+ - **15.1%** of code hallucinations call APIs that don't exist or were never imported ([arXiv:2404.00971](https://arxiv.org/abs/2404.00971)).
33
+ - **<10%** of hallucinated code fails tests — **~90% slips past CI** ([arXiv:2404.00971](https://arxiv.org/abs/2404.00971)).
34
+ - **60%+** of model-output errors are *unverifiable* on their face (FAVA, [SoK](https://arxiv.org/abs/2502.18468)).
35
+
36
+ Prompt-only guardrails are soft: a model can *agree* to verify and then skip
37
+ it. **AgentSeed binds the instruction to a hard gate** — the evidence comes
38
+ from running code, not from the model's own word.
39
+
40
+ ## What AgentSeed is — in 30 seconds
41
+
42
+ A drop-in [Agent Plugins](https://agent-plugins.org) 1.0.0 plugin
43
+ (Skill + MCP server + optional client hook + CI gate) that makes three
44
+ promises:
45
+
46
+ | Promise | How it's kept |
47
+ | --- | --- |
48
+ | **🚫 No invented APIs** | `verify_code` parses your code in **12+ languages** and flags any symbol that is called but never defined or imported |
49
+ | **🚫 No fake "done"** | `scan_hallucination` catches stubs, overclaims, and fabricated claims in **English and CJK**; `sandbox_run` proves runtime claims by actually running them |
50
+ | **🚫 No skipped verification** | the Skill gates the workflow, the **client hook** blocks `Write`/`Edit` on files that don't pass, and `guard_cli gate` enforces the same rules in CI with exit codes |
51
+
52
+ It also fills the two gaps the 1.0.0 spec deliberately leaves open:
53
+
54
+ | Gap in Agent Plugins 1.0.0 | AgentSeed's answer |
55
+ | --- | --- |
56
+ | No enforcement mechanism (skills are optional to follow) | `verify-before-code` skill + optional **client-enforced hook** make verification non-skippable |
57
+ | No official conformance linter | `check_plugin` is the **first strict 1.0.0 linter** — and AgentSeed passes its own linter (`ok: true`) |
58
+
59
+ ## See it catch a hallucination
60
+
61
+ ```python
62
+ # Your coding agent just "finished" this — it calls magic_unknown(),
63
+ # an API that doesn't exist and was never imported:
64
+
65
+ def f():
66
+ return magic_unknown() # ← hallucinated API
67
+
68
+ # AgentSeed, before the task can be marked done:
69
+ $ verify_code(source=..., language="python")
70
+ {
71
+ "language": "python",
72
+ "suspects": ["magic_unknown"] # ← caught, blocking
73
+ }
74
+ ```
75
+
76
+ ```text
77
+ # And the agent's completion claim doesn't survive either:
78
+ "The feature is production ready, all tests pass. Trust me."
79
+
80
+ $ scan_hallucination(source=...)
81
+ {
82
+ "hits": [
83
+ {"word": "all tests pass", "group": "oversold", "line": 1},
84
+ {"word": "production ready", "group": "oversold", "line": 1},
85
+ {"word": "trust me", "group": "oversold", "line": 1}
86
+ ],
87
+ "clean": false # ← caught, blocking
88
+ }
89
+ ```
90
+
91
+ The verdict is **measured, not promised**: on a seeded synthetic corpus
92
+ (5 defect classes, 100 defective + 40 clean modules) AgentSeed scores
93
+ **precision 1.0 · recall 1.0** (tp=100, fp=0, fn=0) — locked in by a
94
+ regression test. Methodology and honest limits:
95
+ [docs/BENCHMARK.md](./docs/BENCHMARK.md).
96
+
97
+ ## How the gate works
98
+
99
+ 1. **Before coding** — load the SDD contract and state it in one sentence.
100
+ 2. **Implement** — real code only: no placeholders, no invented APIs.
101
+ 3. **Before "done"** — run `verify_code` + `scan_hallucination`; prove runtime
102
+ claims with `sandbox_run`; validate structure with `schema_validate`.
103
+ 4. **Language audit** — completion reports attach evidence; overclaim
104
+ vocabulary is banned.
105
+ 5. Only when **all checks pass** may the task be marked complete.
106
+
107
+ ## Quick start
108
+
109
+ **Option A — download a release (no git needed):**
110
+
111
+ ```bash
112
+ # grab the latest asset from https://gitcode.com/badhope/AgentSeed/releases
113
+ # or use the installer, which wires it into your client:
114
+ bash install.sh --client auto --hooks # macOS / Linux
115
+ ./install.ps1 -Client auto -Hooks # Windows PowerShell
116
+ # --client: claude | opencode | cursor | manual
117
+ # --hooks / -Hooks: also register the Claude Code enforcement hook
118
+ ```
119
+
120
+ **Option B — clone:**
121
+
122
+ ```bash
123
+ git clone https://gitcode.com/badhope/AgentSeed.git
124
+ # mirrors: https://gitcode.com/badhope/AgentSeed · https://gitee.com/badhope/AgentSeed
125
+ ```
126
+
127
+ 1. **Drop** the `AgentSeed/` directory into any Agent Plugins–capable client
128
+ (Cursor, VS Code, Claude Code, Copilot…). No build, no install.
129
+ 2. The client auto-discovers the `verify-before-code` skill and the
130
+ `agentseed` MCP server from `plugin.json` + `mcp.json`.
131
+ 3. **That's it.** Every coding task is now gated: contract → implement →
132
+ verify → evidence.
133
+
134
+ Run it standalone or gate a human PR with the same rules:
135
+
136
+ ```bash
137
+ python3 server/guard_engine.py # self-check demo
138
+ python3 -m unittest discover -s server # 160+ unit tests
139
+ python3 server/guard_cli.py gate --root . # CI-equivalent hard gate
140
+ python3 server/guard_cli.py check . --ci # plugin conformance only
141
+ python3 server/guard_cli.py scan src/ --strict
142
+ ```
143
+
144
+ > **Windows note:** `mcp.json` launches the server via `python3`. On many
145
+ > Windows installs that alias is a Microsoft Store stub; change `command` to
146
+ > `["python", "server/guard_server.py"]` or use your interpreter's absolute path.
147
+
148
+ ## The 8 MCP tools
149
+
150
+ Zero *required* dependencies — pure Python standard library; optional extras
151
+ upgrade two tools to industry-standard engines (see below).
152
+
153
+ | Tool | Catches | Technique |
154
+ | --- | --- | --- |
155
+ | `verify_code` | Invented APIs / undefined symbols | Python AST + config-driven lexical passes (12+ languages) |
156
+ | `check_contract` | Code violates a written spec | requires/prohibits contract check |
157
+ | `check_imports` | Hallucinated packages (slopsquatting) | stdlib + known-packages allowlist check |
158
+ | `scan_hallucination` | Placeholder code, overclaims, fabricated content | 28+ signals in 3 groups, EN + CJK |
159
+ | `check_plugin` | Non-conformant plugin packaging | Strict 1.0.0 linter |
160
+ | `sandbox_run` | "Tests pass" without running anything | Deterministic execution channel (bounded-memory output) |
161
+ | `schema_validate` | Invalid structured output | JSON Schema validation |
162
+ | `record_verification` | No persistent evidence trail | JSONL audit trail under `PLUGIN_DATA` |
163
+
164
+ ### Language coverage (honest scope)
165
+
166
+ | Language | `verify_code` analysis |
167
+ | --- | --- |
168
+ | Python | full AST scope walk (+ pyflakes when installed), line numbers |
169
+ | TypeScript / JavaScript | lexical regex pass (documented false-positive classes) |
170
+ | Go · Rust · Java · C · C++ · C# · PHP · Ruby · Kotlin · Swift | config-driven generic lexical pass |
171
+ | any other language | add a `LangSpec` registry entry — no engine change |
172
+
173
+ Honest limits: attribute calls (`obj.m()`), macros, and cross-file symbols
174
+ are not analyzed; Ruby's paren-less calls are supported.
175
+
176
+ Honest limits: attribute calls (`obj.m()`), macros, and cross-file symbols
177
+ are not analyzed; Ruby's paren-less calls are supported.
178
+
179
+ ### It really catches other languages — live-tested
180
+
181
+ The same rule applies to every registered language: a bare call to a symbol
182
+ that is never defined is a hallucination, whatever the syntax:
183
+
184
+ ```python
185
+ # Go detect_undefined_symbols("func main() { process_data() }", "go") -> ["process_data"]
186
+ # Rust fn main() { let x = load_config() } -> ["load_config"]
187
+ # Java class A { void m() { connect_db() } } -> ["connect_db"]
188
+ # C int main() { ghost(); return 0; } -> ["ghost"]
189
+ # Kotlin fun main() { fetch_users() } -> ["fetch_users"]
190
+ # Swift func run() { connect() } -> ["connect"]
191
+ # Ruby def run; authenticate; end -> ["authenticate"]
192
+ # TypeScript function run() { connectDb() } -> ["connectDb"]
193
+ ```
194
+
195
+ Verified across Go · Rust · Java · C · C++ · C# · PHP · Ruby · Kotlin ·
196
+ Swift · TypeScript — every language flags its invented call, and clean
197
+ code in each language reports **zero false positives**.
198
+
199
+
200
+ ## Client-enforced hook mode
201
+
202
+ Skills persuade; **hooks enforce at the client boundary**. Register AgentSeed
203
+ as a Claude Code hook and every `Write`/`Edit`/`MultiEdit` is scanned
204
+ automatically — no prompt can skip it:
205
+
206
+ ```bash
207
+ python3 server/guard_hook.py register --client claude # idempotent, merges settings
208
+ python3 server/guard_hook.py --file path/to/source.py # scan any file directly
209
+ ```
210
+
211
+ - **PreToolUse** inspects the incoming content *before* it lands on disk; a
212
+ blocking finding exits `2`, and the agent must fix the flagged lines.
213
+ - **PostToolUse** re-checks saved files on write paths without inline content.
214
+ - **Failure policy (honest):** infrastructure problems (bad stdin, unreadable
215
+ files) never block work — fail-open; only positive scan findings block.
216
+
217
+ ## Platform support
218
+
219
+ | Client | Status | Notes |
220
+ | --- | --- | --- |
221
+ | Claude Code | ✅ verified | skills + MCP + optional enforcement hook |
222
+ | opencode | ✅ verified | `~/.config/opencode/opencode.json` |
223
+ | Cursor | ⚪ spec-compatible* | copy into project; no stable plugin dir yet |
224
+ | VS Code (+Copilot) | ⚪ spec-compatible* | MCP support rolling out |
225
+ | Cline / Windsurf | ⚪ spec-compatible* | stdio server entry maps directly |
226
+
227
+ \* honest states: formats are spec-compatible and expected to work, but not yet
228
+ exercised by the maintainers. If you verify one, open a PR updating this table.
229
+
230
+ ## Optional dependencies
231
+
232
+ ```bash
233
+ pip install -r server/requirements.txt
234
+ ```
235
+
236
+ | Extra | Upgrades | Without it |
237
+ | --- | --- | --- |
238
+ | `jsonschema` | `schema_validate` → full Draft 2020-12 | built-in subset validator |
239
+ | `pyflakes` | `verify_code` → pyflakes F821 analysis | built-in AST walk |
240
+ | `pyyaml` | SKILL.md frontmatter → full YAML | built-in lite parser |
241
+
242
+ ## Configuration (`agentseed.config.json`)
243
+
244
+ | Key | Effect |
245
+ | --- | --- |
246
+ | `allowlist` | scan exclusions (replaces built-in test-idiom list) |
247
+ | `severities` | per-group severity override (`error` \| `warning` \| `info`) |
248
+ | `timeout` | default `sandbox_run` timeout, seconds (1–120) |
249
+ | `extra_tokens` | extend the hallucination word pool at runtime |
250
+ | `suppress_symbols` | names `verify_code` never flags (reported in `suppressed`) |
251
+ | `known_packages` | packages `check_imports` treats as known (stdlib + common + this list) |
252
+ | `sandbox_allowed_prefixes` | **allowlist of executables** `sandbox_run` may launch; PATH-resolved, separator-boundary enforced (absent = unrestricted) |
253
+ | `sandbox_env` | `"inherit"` \| `"scrub"` — `scrub` drops credential-looking env vars |
254
+
255
+ Unknown keys are warned on stderr — a typo is never silently ignored.
256
+
257
+ > ⚠️ **Security note:** `sandbox_run` executes real processes with your user's
258
+ > permissions. Gate it behind user approval; set `sandbox_allowed_prefixes` in
259
+ > shared/CI environments. Commands resolve through `PATH` to absolute paths
260
+ > before execution, so a hostile `cwd` cannot shadow an allowlisted binary;
261
+ > unmatched commands are refused (exit -10) without running.
262
+
263
+ ## Compatibility & graceful degradation
264
+
265
+ | Host capability | What you get |
266
+ | --- | --- |
267
+ | Full Agent Plugins | drop-in: skill + MCP auto-discovered, `${PLUGIN_DATA}` config honored |
268
+ | MCP-capable client | all 8 tools via registration |
269
+ | Skills-only client | skill workflow; verification degrades to `guard_cli.py` via shell |
270
+ | Plain terminal / CI | CLI gates with exit codes |
271
+
272
+ ## Built-in guardrail library (EN / 中文 / 日本語)
273
+
274
+ `PROMPT-POOL` (20+ copy-paste guardrail prompts) · `HALLUCINATION-PATTERNS`
275
+ (5-class failure-mode catalog) · `VERIFICATION-CHECKLIST` (executable
276
+ end-of-task checklist) · `SDD-CONTRACT` (the contract every task must
277
+ satisfy) · `VENDOR-SOLUTIONS` (adoption map of vendor techniques).
278
+
279
+ ## Why AgentSeed vs. alternatives
280
+
281
+ | | Prompt-only guardrail skills | Static import linters (MCP) | **AgentSeed** |
282
+ | --- | --- | --- | --- |
283
+ | Touches code | ❌ prompt only | ✅ import graphs | ✅ AST + lexical (12+ langs) |
284
+ | Runs verification tools | ❌ | lint gates | ✅ 8 MCP tools incl. sandbox |
285
+ | Hallucination-language scan | ❌ | ❌ | ✅ stub/oversold/fabricated, EN + CJK |
286
+ | Enforcement | soft (skill text) | CI gate | **hard**: skill + MCP + hook + CLI exit codes |
287
+ | 1.0.0 conformance linter | ❌ | ❌ | ✅ first |
288
+
289
+ ## FAQ
290
+
291
+ **Does it need a specific LLM?** No — client-agnostic and model-agnostic; the
292
+ gate is enforced by skill + MCP + hooks + CI, not by any model.
293
+
294
+ **Zero dependencies?** Yes. The MCP server is pure Python standard library.
295
+
296
+ **Does it work with our existing AGENTS.md / CLAUDE.md?** Yes — it
297
+ complements them. Those files carry project facts (prose, persuasive);
298
+ AgentSeed carries the behavior contract and the hard enforcement.
299
+
300
+ **How do I extend it to another language?** Add a `LangSpec` registry entry in
301
+ `server/engine/symbols.py` — one config, no engine change.
302
+
303
+ ## Contributing
304
+
305
+ Issues, PRs and ideas welcome — or open an issue for a hallucination pattern
306
+ we haven't catalogued yet. See [CONTRIBUTING.md](./CONTRIBUTING.md).
307
+
308
+ ## License
309
+
310
+ Apache-2.0 © AgentSeed. See [LICENSE](./LICENSE).
311
+
312
+ ---
313
+
314
+ <div align="center">
315
+
316
+ ⭐ **If AgentSeed saved you from shipping hallucinated code, star the repo — it's the best signal that guardrails matter.**
317
+
318
+ </div>