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.
- package/CHANGELOG.md +178 -0
- package/LICENSE +202 -0
- package/README.ja.md +320 -0
- package/README.md +318 -0
- package/README.zh.md +306 -0
- package/bin/cli.js +37 -0
- package/mcp.json +12 -0
- package/package.json +30 -0
- package/plugin.json +22 -0
- package/server/.agentseed/verification-log.jsonl +2 -0
- package/server/__pycache__/guard_cli.cpython-313.pyc +0 -0
- package/server/__pycache__/guard_engine.cpython-313.pyc +0 -0
- package/server/__pycache__/test_cli.cpython-313-pytest-9.1.1.pyc +0 -0
- package/server/__pycache__/test_cli.cpython-313.pyc +0 -0
- package/server/__pycache__/test_features.cpython-313-pytest-9.1.1.pyc +0 -0
- package/server/__pycache__/test_features.cpython-313.pyc +0 -0
- package/server/__pycache__/test_guard.cpython-313-pytest-9.1.1.pyc +0 -0
- package/server/__pycache__/test_guard.cpython-313.pyc +0 -0
- package/server/__pycache__/test_hook.cpython-313-pytest-9.1.1.pyc +0 -0
- package/server/__pycache__/test_hook.cpython-313.pyc +0 -0
- package/server/__pycache__/test_manifests.cpython-313-pytest-9.1.1.pyc +0 -0
- package/server/__pycache__/test_manifests.cpython-313.pyc +0 -0
- package/server/__pycache__/test_server.cpython-313-pytest-9.1.1.pyc +0 -0
- package/server/__pycache__/test_server.cpython-313.pyc +0 -0
- package/server/engine/__init__.py +64 -0
- package/server/engine/__pycache__/__init__.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/audit.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/config.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/hallucination.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/imports.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/plugin.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/sandbox.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/schema.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/symbols.cpython-313.pyc +0 -0
- package/server/engine/__pycache__/version.cpython-313.pyc +0 -0
- package/server/engine/audit.py +84 -0
- package/server/engine/config.py +131 -0
- package/server/engine/hallucination.py +254 -0
- package/server/engine/imports.py +136 -0
- package/server/engine/plugin.py +367 -0
- package/server/engine/sandbox.py +287 -0
- package/server/engine/schema.py +193 -0
- package/server/engine/symbols.py +984 -0
- package/server/engine/version.py +17 -0
- package/server/guard_cli.py +455 -0
- package/server/guard_engine.py +111 -0
- package/server/guard_hook.py +404 -0
- package/server/guard_server.py +472 -0
- package/server/requirements.txt +7 -0
- package/server/test_cli.py +132 -0
- package/server/test_features.py +426 -0
- package/server/test_guard.py +828 -0
- package/server/test_hook.py +331 -0
- package/server/test_manifests.py +70 -0
- package/server/test_server.py +247 -0
- package/skills/verify-before-code/SKILL.ja.md +116 -0
- package/skills/verify-before-code/SKILL.md +140 -0
- package/skills/verify-before-code/SKILL.zh.md +117 -0
- package/skills/verify-before-code/references/DEFAULT-NORMS.md +52 -0
- package/skills/verify-before-code/references/HALLUCINATION-PATTERNS.ja.md +121 -0
- package/skills/verify-before-code/references/HALLUCINATION-PATTERNS.md +166 -0
- package/skills/verify-before-code/references/HALLUCINATION-PATTERNS.zh.md +145 -0
- package/skills/verify-before-code/references/PROMPT-POOL.ja.md +248 -0
- package/skills/verify-before-code/references/PROMPT-POOL.md +282 -0
- package/skills/verify-before-code/references/PROMPT-POOL.zh.md +252 -0
- package/skills/verify-before-code/references/SDD-CONTRACT.ja.md +61 -0
- package/skills/verify-before-code/references/SDD-CONTRACT.md +66 -0
- package/skills/verify-before-code/references/SDD-CONTRACT.zh.md +58 -0
- package/skills/verify-before-code/references/VENDOR-SOLUTIONS.ja.md +62 -0
- package/skills/verify-before-code/references/VENDOR-SOLUTIONS.md +62 -0
- package/skills/verify-before-code/references/VENDOR-SOLUTIONS.zh.md +54 -0
- package/skills/verify-before-code/references/VERIFICATION-CHECKLIST.ja.md +68 -0
- package/skills/verify-before-code/references/VERIFICATION-CHECKLIST.md +73 -0
- package/skills/verify-before-code/references/VERIFICATION-CHECKLIST.zh.md +68 -0
- package/skills/verify-before-code/scripts/check.ps1 +52 -0
- package/skills/verify-before-code/scripts/check.sh +44 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verify-before-code
|
|
3
|
+
description: >-
|
|
4
|
+
コーディングエージェント向けガードレール。コード作成前に SDD 契約とプロンプト
|
|
5
|
+
プールを読み込み、agentseed MCP サーバーの verify_code と scan_hallucination
|
|
6
|
+
を呼び出し、両方が合格し完了報告に証拠が添付された場合のみ完了とみなす。
|
|
7
|
+
コードの作成・編集・完了宣言のすべての場面で使用する。
|
|
8
|
+
license: Apache-2.0
|
|
9
|
+
compatibility: MCP サーバーは Python 3.9+ が必要。依存ゼロで動作;オプション(jsonschema、pyflakes、pyyaml)で精度向上、未インストール時は自動フォールバック。
|
|
10
|
+
metadata:
|
|
11
|
+
author: AgentSeed
|
|
12
|
+
version: "0.3.0"
|
|
13
|
+
spec: agent-plugins-1.0.0
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# コード前に検証する
|
|
17
|
+
|
|
18
|
+
AgentSeed ガードレール保護下のセッションにいます。`agentseed` MCP サーバーは利用
|
|
19
|
+
可能です。その役割は、幻覚コードやスタブコードの出荷を止めることです。以下のゲートを
|
|
20
|
+
**順番に**実行し、ゲート 3 はスキップ不可です。
|
|
21
|
+
|
|
22
|
+
## リファレンスライブラリ(必要に応じて読み込み)
|
|
23
|
+
|
|
24
|
+
| リソース | 目的 |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `references/SDD-CONTRACT.ja.md` | すべてのコーディングタスクが満たすべき契約 |
|
|
27
|
+
| `references/PROMPT-POOL.ja.md` | コピペ可能なガードレールプロンプト集 |
|
|
28
|
+
| `references/HALLUCINATION-PATTERNS.ja.md` | 幻覚の失敗モードカタログ |
|
|
29
|
+
| `references/VERIFICATION-CHECKLIST.ja.md` | タスク完了時の実行可能チェックリスト |
|
|
30
|
+
| `references/VENDOR-SOLUTIONS.ja.md` | ベンダー技術と導入状況のマップ |
|
|
31
|
+
|
|
32
|
+
## ゲート 1 — 契約の読み込み(コード作成前)
|
|
33
|
+
|
|
34
|
+
実装を始める前に `references/SDD-CONTRACT.ja.md` を読んでください。未表明・仮定の
|
|
35
|
+
契約に対してコーディングしてはいけません。契約が無ければユーザーに求めます。
|
|
36
|
+
|
|
37
|
+
- コーディング対象の契約を 1 文で述べる。
|
|
38
|
+
- 契約として表現できないタスクなら、立ち止まって確認する。
|
|
39
|
+
- 出力リスクを分類する(Critical / High / Medium / Low)。Critical/High は全検査。
|
|
40
|
+
|
|
41
|
+
## ゲート 2 — 契約に沿った実装
|
|
42
|
+
|
|
43
|
+
契約を満たす最小のコードを書きます。実際に動く実装を優先し、プレースホルダーを
|
|
44
|
+
避けます。
|
|
45
|
+
|
|
46
|
+
- `stub`/`mock`/`fake`/`placeholder`/`dummy`/`todo`/`fixme`/`tbd`/
|
|
47
|
+
`not implemented`/`coming soon` を実ロジックの代わりに**使わない**。
|
|
48
|
+
- このプロジェクトで定義・インポートされていないシンボルを**呼ばない**。
|
|
49
|
+
- インストール済みバージョンで検証していない API を**信頼しない**(PROMPT-POOL E1)。
|
|
50
|
+
- 今ターンで読んでいないファイルの内容・行番号を**断言しない**(PROMPT-POOL F1)。
|
|
51
|
+
|
|
52
|
+
## ゲート 3 — 完了宣言前の検証(必須・スキップ不可)
|
|
53
|
+
|
|
54
|
+
タスク完了をユーザーに伝える前に、最終ソースに**両方のツールを必ず**呼び出します:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
verify_code(source=<最終ソース>, language="python")
|
|
58
|
+
scan_hallucination(source=<最終ソース>)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**このセッションに `agentseed` MCP ツールがない場合**、検証をスキップせず —
|
|
62
|
+
シェルから CLI の同等コマンドに降格します:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python <agentseedプラグインルート>/server/guard_cli.py verify <変更ファイル> --language python
|
|
66
|
+
python <agentseedプラグインルート>/server/guard_cli.py scan "<最終ソースまたはファイル>"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`<agentseedプラグインルート>` の特定順序:`AGENTSEED_PLUGIN_ROOT` 環境変数 →
|
|
70
|
+
本スキルディレクトリ直下の `.agentseed-plugin-root` ファイル → 本スキルから上方向に
|
|
71
|
+
`plugin.json` と `server/guard_cli.py` を両方含むディレクトリを探索。CLI は同じ
|
|
72
|
+
ゲート規則です:終了コード 0 = 合格、1 = ブロッキングな指摘あり。
|
|
73
|
+
|
|
74
|
+
判定ルール:
|
|
75
|
+
|
|
76
|
+
- `verify_code` が `suspects: []` かつ `scan_hallucination` が `blocking: false`
|
|
77
|
+
→ 検証ゲート通過。
|
|
78
|
+
- `verify_code` に suspect(未定義/未インポートのシンボル)→ API を幻覚した可能性。
|
|
79
|
+
修正(インポート・定義・実在の呼び出しへ置換)して再実行。
|
|
80
|
+
- `scan_hallucination` のヒットはまず `severity` フィールドで判断:
|
|
81
|
+
- `error`(任意のヒット)→ `blocking: true`、タスクは**未完了**。指摘された行を
|
|
82
|
+
修正して再実行。既定で `oversold` と `fabricated` は error:証拠を添付するか
|
|
83
|
+
主張/内容を削除する。
|
|
84
|
+
- `warning`(例:`stub_code` の既定)→ ブロックはしないが完了報告に必ず記載。
|
|
85
|
+
実際に未完了の作業を示す場合は error として扱う。
|
|
86
|
+
- `info` → 情報提供のみ、対応不要。
|
|
87
|
+
|
|
88
|
+
**ブロック中**の問題(`suspects` 非空または `blocking: true`)が残っている間は、
|
|
89
|
+
タスク完了と絶対にマークしないでください。解消できない場合は成功を主張せず、
|
|
90
|
+
ユーザーに明示的に報告します。
|
|
91
|
+
|
|
92
|
+
## ゲート 4 — 最終メッセージ前の言語監査
|
|
93
|
+
|
|
94
|
+
ゲートが通過しても言語監査を実行します(PROMPT-POOL C/D/G/J):
|
|
95
|
+
|
|
96
|
+
- すべての記述は OBSERVED、または INFERRED とラベル付け。
|
|
97
|
+
- 証拠なしの誇大語彙なし(`guaranteed`、`fully tested`、`production ready`、
|
|
98
|
+
`should work`、`trust me` 等)。
|
|
99
|
+
- 不確実さは正直に表現。引用・統計は実在のもの。
|
|
100
|
+
- 完了報告には証拠(実行コマンド、出力、読んだファイル)を添付。"Done, all
|
|
101
|
+
tests pass" にログが無ければ、それは主張であり結果ではない。
|
|
102
|
+
|
|
103
|
+
## 任意 — プラグイン自身の検証
|
|
104
|
+
|
|
105
|
+
Agent Plugins 1.0.0 適合性チェック:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
check_plugin(path=<agentseed プラグインルートの絶対パス>)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## なぜ存在するのか
|
|
112
|
+
|
|
113
|
+
プロンプトのみのガードレールは「弱い」:モデルは「検証してから完了」に同意して、
|
|
114
|
+
それをスキップできます。AgentSeed は弱い Skill 指示をハードな MCP ゲートに縛ります
|
|
115
|
+
— 証拠はモデルの自己申告ではなく、実際に実行されたコードが生み出します。リファレンス
|
|
116
|
+
ライブラリは、研究の各原理を実行可能な指示に変換します。
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verify-before-code
|
|
3
|
+
description: >-
|
|
4
|
+
Guardrail for coding agents. Loads the SDD contract and the prompt pool
|
|
5
|
+
before code is written, then calls the agentseed MCP server's verify_code and
|
|
6
|
+
scan_hallucination tools; a task may only be marked complete when both pass
|
|
7
|
+
and the completion report attaches evidence. Use whenever the agent writes,
|
|
8
|
+
edits, or claims completion of code.
|
|
9
|
+
license: Apache-2.0
|
|
10
|
+
compatibility: Requires Python 3.9+ for the MCP server. Zero required dependencies; optional extras (jsonschema, pyflakes, pyyaml) upgrade analysis engines with automatic fallback.
|
|
11
|
+
metadata:
|
|
12
|
+
author: AgentSeed
|
|
13
|
+
version: "0.3.0"
|
|
14
|
+
spec: agent-plugins-1.0.0
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Verify Before Code
|
|
18
|
+
|
|
19
|
+
You are running inside an AgentSeed-guarded coding session. The AgentSeed MCP
|
|
20
|
+
server (`agentseed`) is available. Its job is to stop you from shipping
|
|
21
|
+
hallucinated or stubbed code. Follow the gates below **in order**, and treat
|
|
22
|
+
Gate 3 as non-skippable.
|
|
23
|
+
|
|
24
|
+
## Reference library (load as needed)
|
|
25
|
+
|
|
26
|
+
| Resource | Purpose |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `references/SDD-CONTRACT.md` | the contract every coding task must satisfy |
|
|
29
|
+
| `references/DEFAULT-NORMS.md` | the operating norms of a senior engineer, each bound to the gate that enforces it |
|
|
30
|
+
| `references/PROMPT-POOL.md` | copy-paste guardrail prompts (completion claims, uncertainty, API verification, citation rules, etc.) |
|
|
31
|
+
| `references/HALLUCINATION-PATTERNS.md` | catalog of hallucination failure modes with signals and countermeasures |
|
|
32
|
+
| `references/VERIFICATION-CHECKLIST.md` | executable checklist for end-of-task verification |
|
|
33
|
+
|
|
34
|
+
## Gate 1 — Load the contract (BEFORE writing code)
|
|
35
|
+
|
|
36
|
+
Read `references/SDD-CONTRACT.md` and `references/DEFAULT-NORMS.md` before
|
|
37
|
+
producing any implementation. The contract defines the spec the code must
|
|
38
|
+
satisfy; the norms define how you operate while satisfying it. Do not write
|
|
39
|
+
code against an unstated or assumed contract; if the contract is missing,
|
|
40
|
+
ask the user to supply it first.
|
|
41
|
+
|
|
42
|
+
- State the contract you are coding against in one sentence.
|
|
43
|
+
- If the task cannot be expressed as a contract, stop and clarify.
|
|
44
|
+
- Classify output risk (Critical / High / Medium / Low) per the checklist —
|
|
45
|
+
full rigor for Critical/High.
|
|
46
|
+
|
|
47
|
+
## Gate 2 — Implement against the contract
|
|
48
|
+
|
|
49
|
+
Write the smallest code that satisfies the contract. Prefer real, runnable
|
|
50
|
+
implementations over placeholders.
|
|
51
|
+
|
|
52
|
+
- **Never** emit `stub`/`mock`/`fake`/`placeholder`/`dummy`/`todo`/`fixme`/
|
|
53
|
+
`tbd`/`not implemented`/`coming soon` as a substitute for working logic.
|
|
54
|
+
- **Never** call a symbol that is not defined or imported in this project.
|
|
55
|
+
- **Never** trust an API that you have not verified against the installed
|
|
56
|
+
version (see PROMPT-POOL E1 — "never invent an API").
|
|
57
|
+
- **Never** assert a file's content or line numbers without reading it in this
|
|
58
|
+
turn (PROMPT-POOL F1).
|
|
59
|
+
|
|
60
|
+
## Gate 3 — Verify BEFORE claiming done (MANDATORY, NON-SKIPPABLE)
|
|
61
|
+
|
|
62
|
+
Before you tell the user the task is complete, call BOTH tools on the final
|
|
63
|
+
source:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
verify_code(source=<final source>, language="python")
|
|
67
|
+
scan_hallucination(source=<final source>)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**If the `agentseed` MCP tools are not available in this session**, do NOT
|
|
71
|
+
skip verification — degrade to the CLI equivalents via the shell:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
python <agentseed-plugin-root>/server/guard_cli.py verify <changed-file> --language python
|
|
75
|
+
python <agentseed-plugin-root>/server/guard_cli.py scan "<final source or file>"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Locate `<agentseed-plugin-root>` by (in order): the `AGENTSEED_PLUGIN_ROOT`
|
|
79
|
+
environment variable; a `.agentseed-plugin-root` file next to this skill;
|
|
80
|
+
walking up from this skill's directory until you find a directory containing
|
|
81
|
+
both `plugin.json` and `server/guard_cli.py`. The CLI uses the same gate
|
|
82
|
+
rules: exit code 0 = pass, 1 = blocking findings.
|
|
83
|
+
|
|
84
|
+
Decision rules:
|
|
85
|
+
|
|
86
|
+
- `verify_code` returns `suspects: []` AND `scan_hallucination` returns
|
|
87
|
+
`blocking: false` → verification gate passed.
|
|
88
|
+
- `verify_code` returns any suspect (a symbol used/called but never defined or
|
|
89
|
+
imported) → you likely hallucinated an API. Fix it (import it, define it, or
|
|
90
|
+
replace it with a real call) and re-run.
|
|
91
|
+
- `scan_hallucination` returns hits. Severity decides what happens — check the
|
|
92
|
+
`severity` field first:
|
|
93
|
+
- `error` (any hit) → `blocking: true`; the task is **not** done. Fix the
|
|
94
|
+
flagged lines and re-run. By default `oversold` and `fabricated` are
|
|
95
|
+
errors: attach evidence or remove the claim/content.
|
|
96
|
+
- `warning` (e.g. default for `stub_code`) → does not block, but you must
|
|
97
|
+
mention it in the completion report; if it marks genuinely unfinished work,
|
|
98
|
+
treat it like an error.
|
|
99
|
+
- `info` → informational only; no action required.
|
|
100
|
+
|
|
101
|
+
Never mark a coding task complete while either tool still reports a *blocking*
|
|
102
|
+
problem (`suspects` non-empty or `blocking: true`). If you cannot resolve a
|
|
103
|
+
flag, report it explicitly to the user instead of claiming success.
|
|
104
|
+
|
|
105
|
+
Execution and structure are verified the same way — as observed facts, not
|
|
106
|
+
claims:
|
|
107
|
+
|
|
108
|
+
- Claims that require running code (tests pass, type check clean, linter ok)
|
|
109
|
+
→ prove them with `sandbox_run(["python3", "-m", "pytest", ...])` and cite
|
|
110
|
+
the exit code + output.
|
|
111
|
+
- Structured outputs (JSON, config) → validate with
|
|
112
|
+
`schema_validate(instance, schema)` before use. Never trust "it's valid" on
|
|
113
|
+
self-assessment.
|
|
114
|
+
|
|
115
|
+
## Gate 4 — Language audit before the final message
|
|
116
|
+
|
|
117
|
+
Even when the gates pass, run the language audit (PROMPT-POOL C/D/G/J):
|
|
118
|
+
|
|
119
|
+
- Every statement is OBSERVED or labeled INFERRED.
|
|
120
|
+
- No overclaim vocabulary without evidence (`guaranteed`, `fully tested`,
|
|
121
|
+
`production ready`, `should work`, `trust me`, ...).
|
|
122
|
+
- Uncertainty is expressed honestly; citations and statistics are real.
|
|
123
|
+
- Your completion report attaches evidence: the command run, the output, the
|
|
124
|
+
file read. "Done, all tests pass" without the log is a claim, not a result.
|
|
125
|
+
|
|
126
|
+
## Optional — Validate the plugin itself
|
|
127
|
+
|
|
128
|
+
To check that this plugin conforms to Agent Plugins 1.0.0:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
check_plugin(path=<absolute path to the agentseed plugin root>)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Why this exists
|
|
135
|
+
|
|
136
|
+
Plain prompt-only guardrails are soft: a model can "agree" to verify and then
|
|
137
|
+
skip it. AgentSeed binds the soft Skill instruction to a hard MCP gate — the
|
|
138
|
+
evidence is generated by running code, not by the model's self-report. The
|
|
139
|
+
reference library turns every anti-hallucination principle from research into
|
|
140
|
+
an executable instruction.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verify-before-code
|
|
3
|
+
description: >-
|
|
4
|
+
面向编程智能体的护栏。写码前加载 SDD 契约与提示池,随后调用 agentseed MCP
|
|
5
|
+
服务器的 verify_code 与 scan_hallucination 工具;只有两者都通过且完成报告附
|
|
6
|
+
带证据时,任务才可标记为完成。适用于智能体编写、修改或宣称完成代码的任何场景。
|
|
7
|
+
license: Apache-2.0
|
|
8
|
+
compatibility: MCP 服务器要求 Python 3.9+。零必需依赖;可选增强(jsonschema、pyflakes、pyyaml),未安装自动回退。
|
|
9
|
+
metadata:
|
|
10
|
+
author: AgentSeed
|
|
11
|
+
version: "0.3.0"
|
|
12
|
+
spec: agent-plugins-1.0.0
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# 写码之前先验证
|
|
16
|
+
|
|
17
|
+
你正处于 AgentSeed 护栏保护的编程会话中。AgentSeed MCP 服务器(`agentseed`)
|
|
18
|
+
已就绪,它的职责是阻止你交付"幻觉代码"或"桩代码"。请**按顺序**执行下面的
|
|
19
|
+
闸门,并把闸门 3 视为不可跳过。
|
|
20
|
+
|
|
21
|
+
## 参考资料库(按需加载)
|
|
22
|
+
|
|
23
|
+
| 资源 | 用途 |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `references/SDD-CONTRACT.zh.md` | 每个编程任务必须满足的契约 |
|
|
26
|
+
| `references/PROMPT-POOL.zh.md` | 即用型护栏提示词(完成声明、不确定性、API 验证、引用规则等) |
|
|
27
|
+
| `references/HALLUCINATION-PATTERNS.zh.md` | 幻觉失效模式目录(信号 + 对策) |
|
|
28
|
+
| `references/VERIFICATION-CHECKLIST.zh.md` | 任务收尾的可执行验证清单 |
|
|
29
|
+
|
|
30
|
+
## 闸门 1 —— 加载契约(写码之前)
|
|
31
|
+
|
|
32
|
+
在产出任何实现之前,先阅读 `references/SDD-CONTRACT.zh.md`。它定义了代码必须
|
|
33
|
+
满足的规范。不要对着隐含或未声明的契约写代码;若契约缺失,先向用户索取。
|
|
34
|
+
|
|
35
|
+
- 用一句话说明你正在按哪份契约编码。
|
|
36
|
+
- 若任务无法表达为契约,停下来澄清。
|
|
37
|
+
- 按清单给输出定级(关键/高/中/低)——关键与高风险走全套检查。
|
|
38
|
+
|
|
39
|
+
## 闸门 2 —— 按契约实现
|
|
40
|
+
|
|
41
|
+
写出满足契约的最小代码,优先真实可运行的实现,而不是占位符。
|
|
42
|
+
|
|
43
|
+
- **绝不**用 `stub`/`mock`/`fake`/`placeholder`/`dummy`/`todo`/`fixme`/
|
|
44
|
+
`tbd`/`not implemented`/`coming soon` 充当可运行逻辑。
|
|
45
|
+
- **绝不**调用本项目内未定义或未导入的符号。
|
|
46
|
+
- **绝不**相信未经"已安装版本"验证的 API(见提示池 E1 —— "绝不编造 API")。
|
|
47
|
+
- **绝不**不读文件就断言其内容或行号(见提示池 F1)。
|
|
48
|
+
|
|
49
|
+
## 闸门 3 —— 宣称完成之前先验证(强制,不可跳过)
|
|
50
|
+
|
|
51
|
+
在告诉用户任务完成之前,对最终源码**同时调用**两个工具:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
verify_code(source=<最终源码>, language="python")
|
|
55
|
+
scan_hallucination(source=<最终源码>)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**如果本会话中没有 `agentseed` MCP 工具**,不要跳过验证——降级为用 shell 直接调
|
|
59
|
+
CLI 等价命令:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python <agentseed插件根>/server/guard_cli.py verify <改动文件> --language python
|
|
63
|
+
python <agentseed插件根>/server/guard_cli.py scan "<最终源码或文件>"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`<agentseed插件根>` 的定位顺序:`AGENTSEED_PLUGIN_ROOT` 环境变量;本技能目录旁的
|
|
67
|
+
`.agentseed-plugin-root` 文件;从本技能目录向上查找,直到找到同时包含 `plugin.json`
|
|
68
|
+
和 `server/guard_cli.py` 的目录。CLI 使用同样的闸门规则:退出码 0 = 通过,
|
|
69
|
+
1 = 存在阻断性发现。
|
|
70
|
+
|
|
71
|
+
判定规则:
|
|
72
|
+
|
|
73
|
+
- `verify_code` 返回 `suspects: []` 且 `scan_hallucination` 返回 `blocking: false`
|
|
74
|
+
→ 验证闸门通过。
|
|
75
|
+
- `verify_code` 返回任何 suspect(被使用/调用却从未定义或导入的符号)→ 你很可能
|
|
76
|
+
幻觉出了一个 API。修复它(导入、定义,或换成真实调用)后重跑。
|
|
77
|
+
- `scan_hallucination` 返回命中时,先看 `severity` 字段:
|
|
78
|
+
- `error`(任一命中)→ `blocking: true`,任务**尚未**完成;修复被标记的行后
|
|
79
|
+
重跑。默认 `oversold` 和 `fabricated` 为 error:附上证据或删除该声称/内容。
|
|
80
|
+
- `warning`(如 `stub_code` 的默认级别)→ 不阻断,但必须在完成报告中提及;
|
|
81
|
+
若它标记的是确实未完成的工作,按 error 对待。
|
|
82
|
+
- `info` → 仅提示,无需处理。
|
|
83
|
+
|
|
84
|
+
只要仍存在**阻断性**问题(`suspects` 非空或 `blocking: true`),就绝不要标记编程
|
|
85
|
+
任务完成。若你无法消除某个告警,如实向用户报告,而不是谎称成功。
|
|
86
|
+
|
|
87
|
+
执行与结构同样用"可观测事实"来验证,而不是靠声称:
|
|
88
|
+
|
|
89
|
+
- 需要运行代码的声明(测试通过、类型检查干净、linter 通过)→ 用
|
|
90
|
+
`sandbox_run(["python3", "-m", "pytest", ...])` 实证,并引用退出码 + 输出。
|
|
91
|
+
- 结构化输出(JSON、配置)→ 使用前用 `schema_validate(instance, schema)` 校验。
|
|
92
|
+
绝不靠自我评估相信"它是合法的"。
|
|
93
|
+
|
|
94
|
+
## 闸门 4 —— 最终答复前的语言审查
|
|
95
|
+
|
|
96
|
+
即使闸门都过了,仍要跑一遍语言审查(提示池 C/D/G/J):
|
|
97
|
+
|
|
98
|
+
- 每句陈述为 OBSERVED,或标注为 INFERRED。
|
|
99
|
+
- 无证据时不使用夸大词汇(`guaranteed`、`fully tested`、`production ready`、
|
|
100
|
+
`should work`、`trust me` 等)。
|
|
101
|
+
- 不确定性被如实表达;引用与统计数字真实。
|
|
102
|
+
- 完成报告必须附证据:跑过的命令、输出、读过的文件。"Done, all tests pass"
|
|
103
|
+
却没有日志,只是声明,不是结果。
|
|
104
|
+
|
|
105
|
+
## 可选 —— 校验插件自身
|
|
106
|
+
|
|
107
|
+
检查本插件是否符合 Agent Plugins 1.0.0:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
check_plugin(path=<agentseed 插件根目录的绝对路径>)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 为什么需要它
|
|
114
|
+
|
|
115
|
+
纯 prompt 的护栏是"软"的:模型可以口头答应验证,然后偷偷跳过。AgentSeed 把软的
|
|
116
|
+
Skill 指令和硬的 MCP 闸门绑死——证据由真实运行的代码产生,而不是模型的自我陈述。
|
|
117
|
+
参考资料库把研究里的每条防幻觉原则变成可执行的指令。
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# DEFAULT-NORMS — the operating norms AgentSeed enforces
|
|
2
|
+
|
|
3
|
+
Other agent-config files state these as prose and hope. AgentSeed binds each
|
|
4
|
+
norm to a **gate or tool** that observes compliance, so the norm survives
|
|
5
|
+
contact with an eager model. Load this file at Gate 1 alongside the SDD
|
|
6
|
+
contract.
|
|
7
|
+
|
|
8
|
+
## The norms
|
|
9
|
+
|
|
10
|
+
| # | Norm | Why models need it | Enforced by |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| 1 | **Senior-engineer stance, zero sycophancy.** Push back when the user or the plan is wrong; never open with agreement reflexes. | Agreement pressure produces wrong code and fake confidence. | Gate 4 language audit; scan_hallucination overclaim group |
|
|
13
|
+
| 2 | **Contract before code.** State goal, interface, inputs/outputs, non-goals, verification, risk class — in one sentence — before implementing. | Unstated specs get invented mid-stream. | Gate 1 (this skill); record_verification trail |
|
|
14
|
+
| 3 | **Surface ambiguity, ask once.** If two interpretations exist, present both and ask; never silently pick one. | Silent guessing is the top driver of "wrong feature, shipped fast". | Gate 1 stop rule; PROMPT-POOL uncertainty prompts |
|
|
15
|
+
| 4 | **Smallest diff that satisfies the contract.** Every changed line must trace to the stated task; no drive-by refactors, no reformatting sprees. | Drive-by changes destroy reviewability and hide real deltas. | Contract non-goals; verify_code scope = changed source |
|
|
16
|
+
| 5 | **No invented APIs.** Never call a symbol that is not defined or imported in the project; verify unfamiliar APIs against the installed version before use. | ~15% of code hallucinations are knowledge-conflicting API calls (arXiv:2404.00971). | verify_code suspects gate |
|
|
17
|
+
| 6 | **Real implementations only.** No stub/mock/fake/placeholder/dummy bodies standing in for logic; no "coming soon" sections. | Placeholder code ships when nobody re-checks. | scan_hallucination stub_code signals |
|
|
18
|
+
| 7 | **Verification before completion claims.** Run the tests/type-checks/linters through sandbox_run; attach exit codes and output excerpts as evidence. | Self-reported status is the failure mode this whole plugin exists for. | Gate 3 (non-skippable); sandbox_run |
|
|
19
|
+
| 8 | **Evidence-backed completion reports.** Cite file paths with line numbers you actually read this turn; quote command output you actually saw. | Fabricated citations are how hallucinations launder into fact. | Gate 4 audit; HALLUCINATION-PATTERNS F-group |
|
|
20
|
+
| 9 | **Disclose uncertainty honestly.** Label statements as observed or inferred; say what was NOT tested. | Unverifiable claims are indistinguishable from lies downstream. | Gate 4; severities config keeps warnings visible |
|
|
21
|
+
| 10 | **Learnings compound.** When corrected, reduce the miss to one written line and apply it from then on. | Corrections that stay conversational evaporate. | PLUGIN_DATA verification-log.jsonl audit trail |
|
|
22
|
+
|
|
23
|
+
## Where these come from
|
|
24
|
+
|
|
25
|
+
The norms are not invented here; they synthesize what strong agent operators
|
|
26
|
+
converged on publicly:
|
|
27
|
+
|
|
28
|
+
- **AGENTS.md open standard** (<https://agents.md>) — imperative, specific,
|
|
29
|
+
cross-tool operating instructions; read natively by Codex, Cursor,
|
|
30
|
+
Copilot, Aider, Devin, Gemini CLI and others.
|
|
31
|
+
- **Anthropic's official Claude Code best practices**
|
|
32
|
+
(<https://code.claude.com/docs/en/best-practices>) — explicit conventions,
|
|
33
|
+
verification-first workflows, tight context.
|
|
34
|
+
- **FerroxLabs/agents-md** (<https://github.com/FerroxLabs/agents-md>) —
|
|
35
|
+
senior-engineer stance over eager-intern defaults; anti-sycophancy;
|
|
36
|
+
smallest-diff discipline; forced verification loops; compounding
|
|
37
|
+
learnings section (Boris Cherny's workflow). Synthesizes Andrej Karpathy's
|
|
38
|
+
published principles on LLM coding failure modes.
|
|
39
|
+
- **Community context-engineering practice** (CLAUDE.md / .cursor/rules /
|
|
40
|
+
copilot-instructions guides) — rules that matter belong near enforceable
|
|
41
|
+
machinery; prose alone gets quietly deprioritized.
|
|
42
|
+
|
|
43
|
+
AgentSeed's contribution: rows 5–10 above stop being suggestions — each maps
|
|
44
|
+
to an MCP tool, CLI exit code, or CI gate in this repo (`guard_cli gate`).
|
|
45
|
+
|
|
46
|
+
## What this file is NOT
|
|
47
|
+
|
|
48
|
+
- Not a replacement for your project's CLAUDE.md / AGENTS.md — those carry
|
|
49
|
+
project-specific facts (stack, commands, layout). This file carries the
|
|
50
|
+
behavior contract that transfers across every project.
|
|
51
|
+
- Not optional: Gates 1–4 in SKILL.md reference it, and the tools below
|
|
52
|
+
measure whether its norms were followed.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# 幻覚パターンライブラリ
|
|
2
|
+
|
|
3
|
+
> コーディングエージェントとチャットボットが示す幻覚の失敗モードを、検出シグナルと
|
|
4
|
+
> 対策とともに整理した検索可能なカタログ。査読付き研究・業界 SoK 論文・実在事例から
|
|
5
|
+
> 収集。
|
|
6
|
+
>
|
|
7
|
+
> 出典:arXiv:2404.00971(コード幻覚分類、3,084 サンプル / 2,119 幻覚)、
|
|
8
|
+
> arXiv:2502.18468(SoK)、CDV、reze83、SFD Lab、Vectara HHEM、実在判例。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. コード幻覚パターン
|
|
13
|
+
|
|
14
|
+
### 1.1 意図衝突(コード幻覚の 32.1%)
|
|
15
|
+
- **全体意味衝突** — プログラム全体がタスクと無関係。
|
|
16
|
+
- **局所意味衝突** — 一部の文が要件と矛盾。
|
|
17
|
+
- *シグナル:* 見た目は一貫しているが機能的に的はずれ。
|
|
18
|
+
- *対策:* H1 契約を先に。
|
|
19
|
+
|
|
20
|
+
### 1.2 コンテキスト不整合(31.8%)
|
|
21
|
+
- オフバイワン・スライス、誤定数、入力コンテキストと合わない条件。
|
|
22
|
+
- *シグナル:* 微妙な論理ずれ、「ほぼ正しい」コード。
|
|
23
|
+
- *対策:* F1 再読、I1 スキーマ検証。
|
|
24
|
+
|
|
25
|
+
### 1.3 コンテキスト反復(17.3%)
|
|
26
|
+
- 入力テキストやコードブロックの過剰な反復(数十回に及ぶことも)。
|
|
27
|
+
- *対策:* レビュー + 重複検出。
|
|
28
|
+
|
|
29
|
+
### 1.4 知識衝突(15.1%)
|
|
30
|
+
- **API 誤用** — 誤 API、誤パラメータ、**存在しない API の呼び出し**、
|
|
31
|
+
**未インポート API の呼び出し**。
|
|
32
|
+
- **識別子誤用** — 存在しない・誤字の変数参照(`max_len_str` と
|
|
33
|
+
`max_len_len_str`)。
|
|
34
|
+
- *シグナル:* 定義・インポートされずに使われるシンボル。
|
|
35
|
+
- *対策:* `verify_code`(AST 検出)、E1 API を捏造しない、E2 インポートしてから使う。
|
|
36
|
+
|
|
37
|
+
### 1.5 デッドコード(3.2%)
|
|
38
|
+
- 結果が使われない冗長ループ・条件・分岐・IO・代入。
|
|
39
|
+
- *対策:* linter + レビュー。
|
|
40
|
+
|
|
41
|
+
### 1.6 ツール固有パターン(SoK arXiv:2502.18468)
|
|
42
|
+
- **ファイルバージョン幻覚**(Cursor AI)、**コンテキスト欠落**、
|
|
43
|
+
**誤ライブラリインポート / 古いフレームワーク構文**、**脆弱性の複製**
|
|
44
|
+
(SQL インジェクション等)。
|
|
45
|
+
- *対策:* F1 再読、E1 API 検証、セキュリティ linter。
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 2. 対話幻覚パターン
|
|
50
|
+
|
|
51
|
+
### 2.1 引用・参考文献の捏造
|
|
52
|
+
- *事例:* 2023 年 6 月以来 120+ の裁判記録に AI 生成の偽引用(Mata v. Avianca)。
|
|
53
|
+
- *対策:* G1 引用は実在のもの。
|
|
54
|
+
|
|
55
|
+
### 2.2 統計・数字の捏造
|
|
56
|
+
- *対策:* G2 数字には出典。
|
|
57
|
+
|
|
58
|
+
### 2.3 人物・出来事・政策の捏造
|
|
59
|
+
- *対策:* G3 確認するか拒否するか。
|
|
60
|
+
|
|
61
|
+
### 2.4 無根拠の自信ある誤答
|
|
62
|
+
- *対策:* I2 根拠づけるか拒否、D1 正直なフォールバック。
|
|
63
|
+
|
|
64
|
+
### 2.5 URL・ドキュメントの捏造
|
|
65
|
+
- *対策:* G1、引用前に検証。
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 3. エージェント行動幻覚(誇張完了)
|
|
70
|
+
|
|
71
|
+
### 3.1 「完了、全テスト合格」を実行せず主張
|
|
72
|
+
- *CDV:* 停止を決める主体が判断される主体である。エージェントは「報告された進捗」を
|
|
73
|
+
最適化する。
|
|
74
|
+
- *対策:* A1 証拠ベース完了、J1 5 ステップスキャン。
|
|
75
|
+
|
|
76
|
+
### 3.2 自己採点の成功(利益相反)
|
|
77
|
+
- *対策:* A2 生成と検証の分離、A3 二重チャネル拒否権。
|
|
78
|
+
|
|
79
|
+
### 3.3 「should work」推論
|
|
80
|
+
- *対策:* B2 「べき」は証拠ではない。
|
|
81
|
+
|
|
82
|
+
### 3.4 古いファイルの主張
|
|
83
|
+
- *対策:* F1 再読。
|
|
84
|
+
|
|
85
|
+
### 3.5 もっともらしいギャップ埋め
|
|
86
|
+
- *対策:* D1 正直なフォールバック、J1 スキャン。
|
|
87
|
+
|
|
88
|
+
### 3.6 エラーの黙殺
|
|
89
|
+
- *対策:* A1 完了証拠にエラーログを含める。
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 4. 定量的現実確認
|
|
94
|
+
|
|
95
|
+
- Vectara HHEM:最上位モデルでも要約で 0.5–3% の幻覚率、弱いモデルは 10%+。
|
|
96
|
+
- arXiv:2404.00971:幻覚コードのうち全テストを通過するのは <10%。
|
|
97
|
+
- モデル出力エラーの 60%+ は**検証不能**(FAVA、SoK 引用)。
|
|
98
|
+
- 2025 年業界報告:最前線モデルでも特定タスクで 15–25% の幻覚率。
|
|
99
|
+
|
|
100
|
+
**結論:** 「検証をスキップできるほど正確なモデル」は存在しない。失敗シナリオを前提に
|
|
101
|
+
設計する(OWASP LLM09: Overreliance)。
|
|
102
|
+
|
|
103
|
+
## 5. 2025 研究の追加
|
|
104
|
+
|
|
105
|
+
**5.1 パッケージ幻覚 / slopsquatting** ——「We Have a Package for You!」
|
|
106
|
+
(USENIX Security 2025, arXiv:2406.10279):57.6 万サンプル中、LLM が存在しない
|
|
107
|
+
パッケージ名を約 5.2%(商用)〜21.7%(オープンソース)の割合で捏造——20.5 万の
|
|
108
|
+
固有名。約 58% は再現するため、攻撃者が同名の悪意パッケージを先回り登録できる
|
|
109
|
+
(slopsquatting)。対策:`check_imports`。
|
|
110
|
+
|
|
111
|
+
**5.2 コード幻覚の4分類**(arXiv:2504.20799):構文(文法違反)、実行時(実行で失敗)、
|
|
112
|
+
機能(動くが誤り)、品質(リソース/セキュリティ/匂い)。`verify_code` は不正参照の
|
|
113
|
+
サブセットを静的検出、`sandbox_run` は実行時を検出、残りは人間のレビューが必要。
|
|
114
|
+
|
|
115
|
+
**5.3 足場幻覚 / Phantom Symbol**(arXiv:2604.20202):API ドキュメントに無い
|
|
116
|
+
インポート・定数・メソッド・ビルダー呼び出しを捏造。静的検出には API オラクルが要るため、
|
|
117
|
+
`check_contract` で必須/禁止のサーフェスを明示する。
|
|
118
|
+
|
|
119
|
+
**5.4 偽りの安心感**(Perry et al., CCS 2023):AI 支援の開発者はコードが**より安全で
|
|
120
|
+
なくなる**一方で**より自信**を持つ。信頼は証拠ではない——実行・終了コード・
|
|
121
|
+
file:line 引用を要求する(ゲート 3–4)。
|