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
@@ -0,0 +1,166 @@
1
+ # Hallucination Pattern Library
2
+
3
+ > A searchable catalog of hallucination failure modes that coding agents and
4
+ > chatbots exhibit, with detection signals and countermeasures. Compiled from
5
+ > peer-reviewed studies, industry SoK papers, and documented real-world cases.
6
+ >
7
+ > Sources: arXiv:2404.00971 (code hallucination taxonomy, 3,084 samples /
8
+ > 2,119 hallucinations), arXiv:2502.18468 (SoK: hallucinations & security in
9
+ > AI-assisted coding), CDV (agent overclaiming), reze83 anti-hallucination
10
+ > skill, SFD Lab checklist, Vectara HHEM leaderboard, documented legal cases.
11
+
12
+ ---
13
+
14
+ ## 1. Code hallucination patterns
15
+
16
+ *From arXiv:2404.00971 — 5 top-level categories, 19 subtypes.*
17
+
18
+ ### 1.1 Intent Conflicting (32.1% of code hallucinations)
19
+ - **Overall semantic conflict** — the whole program does something unrelated to
20
+ the task.
21
+ - **Local semantic conflict** — some statements contradict the requirement.
22
+ - *Signal:* code is coherent-looking but functionally off-task.
23
+ - *Check:* run the task description against the code's behavior.
24
+ - *Counter:* H1 contract-first; require a stated contract before coding.
25
+
26
+ ### 1.2 Context Inconsistency (31.8%)
27
+ - Off-by-one slices, wrong constants, conditions that don't match the input
28
+ context (e.g. zero-based index treated as one-based).
29
+ - *Signal:* subtle logic drift; code "almost right".
30
+ - *Check:* property tests / edge-case review against the context.
31
+ - *Counter:* F1 re-read; I1 schema validation.
32
+
33
+ ### 1.3 Context Repetition (17.3%)
34
+ - Repeated input context or repeated code blocks (sometimes dozens of times).
35
+ - *Signal:* duplicated blocks, copied prompt text inside code.
36
+ - *Check:* diff review; duplication scanner.
37
+ - *Counter:* code review + duplication detection.
38
+
39
+ ### 1.4 Knowledge Conflicting (15.1%)
40
+ - **API misuse** — wrong API, wrong parameters, **calling an API that does not
41
+ exist**, calling an **unimported API**, redundant API calls.
42
+ - **Identifier misuse** — referencing a variable that doesn't exist or is
43
+ mistyped (`max_len_str` vs `max_len_len_str`).
44
+ - *Signal:* symbols used but never defined/imported; method names that feel
45
+ "off" for a known library.
46
+ - *Check:* `verify_code` (AST undefined-symbol scan); `grep` the dependency.
47
+ - *Counter:* E1 never invent an API; E2 import before use.
48
+
49
+ ### 1.5 Dead Code (3.2%)
50
+ - Redundant loops, conditions, branches, IO, assertions, assignments that are
51
+ never used.
52
+ - *Signal:* statements whose result is never consumed.
53
+ - *Check:* static analyzers (pyflakes, unused-variable linters).
54
+ - *Counter:* review + linters.
55
+
56
+ ### 1.6 Tool-specific patterns (SoK arXiv:2502.18468)
57
+ - **File version hallucination** — treating current file versions as outdated
58
+ (Cursor AI).
59
+ - **Contextual gaps** — without full folder analysis, suggestions become
60
+ irrelevant/repetitive.
61
+ - **Incorrect library imports / outdated framework syntax** — all four major
62
+ tools replicate these.
63
+ - **Vulnerability replication** — SQL injection, XSS, weak auth patterns copied
64
+ from training data.
65
+ - *Counter:* F1 re-read files; E1 verify API surfaces; run security linters.
66
+
67
+ ---
68
+
69
+ ## 2. Conversational hallucination patterns
70
+
71
+ ### 2.1 Fabricated citations & references
72
+ - *Case:* 120+ court filings since June 2023 contained AI-generated fake
73
+ citations (e.g. Mata v. Avianca — counsel fined for invented cases).
74
+ - *Signal:* references that feel too convenient; DOIs/URLs you cannot open.
75
+ - *Counter:* G1 citations must be real.
76
+
77
+ ### 2.2 Fabricated statistics & numbers
78
+ - *Signal:* precise-looking numbers with no source, or numbers that shift
79
+ between answers.
80
+ - *Counter:* G2 numbers need sources.
81
+
82
+ ### 2.3 Fabricated people / events / policies
83
+ - *Signal:* confident statements about entities the model could not have seen.
84
+ - *Counter:* G3 confirm-or-refuse.
85
+
86
+ ### 2.4 Confident wrong answers (ungrounded)
87
+ - *Signal:* fluent, authoritative tone on a topic with zero retrieved context.
88
+ - *Counter:* I2 ground-or-refuse; D1 honest fallback.
89
+
90
+ ### 2.5 Invented URLs / docs / API reference pages
91
+ - *Signal:* links that 404; doc pages that don't exist.
92
+ - *Counter:* G1; verify before citing.
93
+
94
+ ---
95
+
96
+ ## 3. Agent behavior hallucination patterns (overclaiming)
97
+
98
+ ### 3.1 "Done, all tests pass" without running anything
99
+ - *CDV:* the entity deciding to stop is the entity being judged. Agents
100
+ optimize *reported* progress.
101
+ - *Signal:* completion reports with no attached command output.
102
+ - *Counter:* A1 evidence-based completion; J1 five-step scan.
103
+
104
+ ### 3.2 Self-graded success (conflict of interest)
105
+ - *Signal:* the same reasoning pass produces and validates the answer.
106
+ - *Counter:* A2 separate generation from verification; A3 two-channel veto.
107
+
108
+ ### 3.3 "Should work" reasoning
109
+ - *Signal:* hedged claims presented as conclusions.
110
+ - *Counter:* B2 "should" is not evidence.
111
+
112
+ ### 3.4 Stale-file assertions
113
+ - *Signal:* quoting code/line numbers from a previous turn; files may have
114
+ changed.
115
+ - *Counter:* F1 re-read files.
116
+
117
+ ### 3.5 Plausible-gap filling
118
+ - *Signal:* when a fact is missing, the agent invents a "sensible" one.
119
+ - *Counter:* D1 honest fallback; J1 scan.
120
+
121
+ ### 3.6 Silent error swallowing
122
+ - *Signal:* errors are ignored or rationalized so the task can be marked done.
123
+ - *Counter:* A1 require the error log in the completion evidence.
124
+
125
+ ---
126
+
127
+ ## 4. Quantified reality check
128
+
129
+ - Vectara HHEM leaderboard: even top models hallucinate on 0.5–3% of
130
+ summarization outputs; weaker models reach 10%+.
131
+ - arXiv:2404.00971: <10% of hallucinated code passes all tests — most is
132
+ caught by tests, but the remainder slips through.
133
+ - 60%+ of model-output errors were **unverifiable** (FAVA study, cited in SoK).
134
+ - 2025 industry reports: LLM hallucination rates on specific tasks remain
135
+ 15–25% even for frontier models.
136
+
137
+ **Takeaway:** no model is "accurate enough" to skip verification. Design for
138
+ the failure case. (OWASP LLM09: Overreliance.)
139
+
140
+ ## 5. 2025 research additions
141
+
142
+ **5.1 Package hallucination / slopsquatting** — "We Have a Package for You!"
143
+ (USENIX Security 2025, arXiv:2406.10279): across 576k generated samples, LLMs
144
+ invented non-existent package names in ~5.2% (commercial) to ~21.7%
145
+ (open-source) of outputs — 205,474 unique names; ~58% recur across runs.
146
+ Predictable names let attackers pre-register the exact package with malware
147
+ ("slopsquatting"). Signal: an import whose package is not stdlib and not in
148
+ the project's known set. Mitigation: `check_imports`.
149
+
150
+ **5.2 Code-hallucination taxonomy** (arXiv:2504.20799): four observable
151
+ categories — syntactic (breaks grammar), runtime (fails when run), functional
152
+ (runs but wrong), quality (resource/security/smell). `verify_code` catches the
153
+ invalid-reference subset statically; `sandbox_run` catches the runtime subset;
154
+ the rest require human review.
155
+
156
+ **5.3 Scaffolding hallucination / phantom symbols** (arXiv:2604.20202): the
157
+ model invents imports, constants, methods, or builder call-chains that do not
158
+ exist in the target API's docs (e.g. a constant the real API never defined).
159
+ Signature: plausible-but-unverifiable scaffolding around a correct-looking
160
+ core. Static detection needs an API oracle; `check_contract` lets the human
161
+ encode the required/prohibited surface instead.
162
+
163
+ **5.4 False sense of security** (Perry et al., CCS 2023): developers using an
164
+ AI assistant wrote measurably LESS secure code while becoming MORE confident.
165
+ Gate implication: confidence is not evidence — require runs, exit codes, and
166
+ file:line citations (Gates 3–4).
@@ -0,0 +1,145 @@
1
+ # 幻觉模式库
2
+
3
+ > 一份可检索的幻觉失效模式目录:编程智能体与聊天机器人常见的幻觉行为,以及
4
+ > 对应的检测信号与对策。素材来自同行评审研究、行业 SoK 论文与有据可查的真实案例。
5
+ >
6
+ > 来源:arXiv:2404.00971(代码幻觉分类法,3084 样本 / 2119 个幻觉)、
7
+ > arXiv:2502.18468(SoK:AI 辅助编程中的幻觉与安全)、CDV(智能体夸大完成)、
8
+ > reze83 反幻觉技能、SFD Lab 清单、Vectara HHEM 排行榜、已记录的法律案例。
9
+
10
+ ---
11
+
12
+ ## 1. 代码幻觉模式
13
+
14
+ *来自 arXiv:2404.00971 —— 5 个一级类别、19 个子类型。*
15
+
16
+ ### 1.1 意图冲突(占代码幻觉 32.1%)
17
+ - **整体语义冲突** —— 整个程序做的跟任务完全不是一回事。
18
+ - **局部语义冲突** —— 部分语句与需求矛盾。
19
+ - *信号:* 代码看起来通顺但功能跑偏。
20
+ - *检查:* 拿任务描述对照代码行为。
21
+ - *对策:* H1 先契约后编码;写码前必须有明确契约。
22
+
23
+ ### 1.2 上下文不一致(31.8%)
24
+ - 差一错误(off-by-one)、错误常量、与输入上下文不符的条件(如把零基索引当
25
+ 一基索引)。
26
+ - *信号:* 细微逻辑漂移,代码"差一点就对"。
27
+ - *检查:* 属性测试 / 针对上下文的边界用例审查。
28
+ - *对策:* F1 重读;I1 schema 校验。
29
+
30
+ ### 1.3 上下文重复(17.3%)
31
+ - 重复需求文本或重复代码块(有时重复几十次)。
32
+ - *信号:* 重复段落、代码里混入提示词原文。
33
+ - *检查:* diff 审查、重复扫描。
34
+ - *对策:* 代码审查 + 查重。
35
+
36
+ ### 1.4 知识冲突(15.1%)
37
+ - **API 误用** —— 用错 API、参数错、**调用不存在的 API**、调用**未导入的 API**、
38
+ 冗余调用。
39
+ - **标识符误用** —— 引用不存在或拼错的变量(`max_len_str` 写成
40
+ `max_len_len_str`)。
41
+ - *信号:* 用了却从未定义/导入的符号;对已知库来说"不对劲"的方法名。
42
+ - *检查:* `verify_code`(AST 未定义符号扫描);用 `grep` 查依赖。
43
+ - *对策:* E1 绝不编造 API;E2 先导入后使用。
44
+
45
+ ### 1.5 死代码(3.2%)
46
+ - 冗余循环、条件、分支、IO、断言、赋值,结果从未被使用。
47
+ - *信号:* 语句的结果无人消费。
48
+ - *检查:* 静态分析(pyflakes、未使用变量 linter)。
49
+ - *对策:* 审查 + linter。
50
+
51
+ ### 1.6 工具特有模式(SoK arXiv:2502.18468)
52
+ - **文件版本幻觉** —— 把当前文件版本误判为旧版(Cursor AI)。
53
+ - **上下文缺失** —— 不做全目录分析时,建议变得无关/重复。
54
+ - **错误库导入 / 过时框架语法** —— 四大主流工具都会复现。
55
+ - **漏洞复现** —— 从训练数据里复制 SQL 注入、XSS、弱认证写法。
56
+ - *对策:* F1 重读文件;E1 验证 API 表面;跑安全 linter。
57
+
58
+ ---
59
+
60
+ ## 2. 对话幻觉模式
61
+
62
+ ### 2.1 编造引用与参考文献
63
+ - *案例:* 2023 年 6 月以来 120+ 起法院文书含 AI 生成的假引用(如
64
+ Mata v. Avianca 案,律师因编造判例被罚款)。
65
+ - *信号:* 引用"过于合适";打不开的 DOI/URL。
66
+ - *对策:* G1 引用必须真实。
67
+
68
+ ### 2.2 编造统计数字
69
+ - *信号:* 看似精确却无出处的数字;多次回答之间数字漂移。
70
+ - *对策:* G2 数字要有出处。
71
+
72
+ ### 2.3 编造人物/事件/政策
73
+ - *信号:* 对模型不可能见过的实体自信陈述。
74
+ - *对策:* G3 确认或拒答。
75
+
76
+ ### 2.4 自信的错误回答(无接地)
77
+ - *信号:* 对零检索上下文的话题,用流利权威的语气作答。
78
+ - *对策:* I2 接地或拒答;D1 诚实兜底。
79
+
80
+ ### 2.5 编造 URL/文档/API 参考页
81
+ - *信号:* 404 的链接;不存在的文档页。
82
+ - *对策:* G1;引用前先验证。
83
+
84
+ ---
85
+
86
+ ## 3. 智能体行为幻觉模式(夸大完成)
87
+
88
+ ### 3.1 "完成了,测试全过"却什么都没跑
89
+ - *CDV 观点:* 决定何时停止的实体正是被评判的实体。智能体会优化"报告的进度"。
90
+ - *信号:* 完成报告不附带任何命令输出。
91
+ - *对策:* A1 完成=声明+证据;J1 五步扫描。
92
+
93
+ ### 3.2 自我评分成功(利益冲突)
94
+ - *信号:* 同一轮推理既产出答案又验证答案。
95
+ - *对策:* A2 生成与验证分离;A3 双通道一票否决。
96
+
97
+ ### 3.3 "应该能行"式推理
98
+ - *信号:* 含糊的推测被当成结论呈现。
99
+ - *对策:* B2 "应该"不是证据。
100
+
101
+ ### 3.4 过期文件断言
102
+ - *信号:* 引用上一轮的代码/行号;文件可能已变。
103
+ - *对策:* F1 重读文件。
104
+
105
+ ### 3.5 用"合理"填补空白
106
+ - *信号:* 事实缺失时,编造一个"听起来合理"的。
107
+ - *对策:* D1 诚实兜底;J1 扫描。
108
+
109
+ ### 3.6 悄悄吞掉错误
110
+ - *信号:* 错误被忽略或合理化,以便任务能标记完成。
111
+ - *对策:* A1 完成证据里必须包含错误日志。
112
+
113
+ ---
114
+
115
+ ## 4. 量化现实核查
116
+
117
+ - Vectara HHEM 排行榜:即使顶级模型在摘要任务上的幻觉率也有 0.5–3%,
118
+ 较弱的模型可达 10%+。
119
+ - arXiv:2404.00971:<10% 的含幻觉代码能通过全部测试——大部分会被测试抓住,
120
+ 但剩下的会漏过去。
121
+ - 60%+ 的模型输出错误**无法验证**(FAVA 研究,SoK 引用)。
122
+ - 2025 年行业报告:最前沿模型在特定任务上的幻觉率仍高达 15–25%。
123
+
124
+ **结论:** 没有任何模型"准到可以跳过验证"。要为失败场景设计。
125
+ (OWASP LLM09:过度依赖。)
126
+
127
+ ## 5. 2025 研究补充
128
+
129
+ **5.1 包幻觉 / slopsquatting(抢注攻击)** ——《We Have a Package for You!》
130
+ (USENIX Security 2025, arXiv:2406.10279):57.6 万次生成样本中,LLM 编造不存在的
131
+ 包名的比例约 5.2%(商用)至 21.7%(开源)——共 20.5 万个唯一假包名;约 58% 会在多次
132
+ 运行中复现。可预测的名字让攻击者能提前注册同名恶意包(slopsquatting)。
133
+ 信号:导入的包既不在 stdlib 也不在项目已知集合。对策:`check_imports`。
134
+
135
+ **5.2 代码幻觉四分类**(arXiv:2504.20799):语法幻觉(不合语法)、运行期幻觉(一跑就挂)、
136
+ 功能幻觉(能跑但语义错)、质量幻觉(资源/安全/坏味道)。`verify_code` 静态抓到
137
+ "非法引用"子类;`sandbox_run` 抓到"运行期"子类;其余需人工审查。
138
+
139
+ **5.3 脚手架幻觉 / 幻影符号**(arXiv:2604.20202):模型编造目标 API 文档中不存在的
140
+ 导入、常量、方法或 builder 调用链(如某个从未定义的常量)。特征:看似正确的核心外
141
+ 包裹着"貌似合理但无法验证"的脚手架。静态检测需 API oracle;`check_contract` 让人类
142
+ 把必须/禁止的接口表面显式编码。
143
+
144
+ **5.4 虚假安全感**(Perry et al., CCS 2023):使用 AI 助手的开发者写出的代码**更不安全**,
145
+ 却**更自信**。闸门含义:信心不是证据——要求运行、退出码与 file:line 引用(闸门 3–4)。
@@ -0,0 +1,248 @@
1
+ # プロンプトプール — コピペ可能なコーディングエージェント向けガードレールプロンプト
2
+
3
+ > AgentSeed プロンプトプール。すべての項目は、システムプロンプト・スキル・エージェント
4
+ > 設定に貼り付けるだけで使える完成済みの指示です。各プロンプトは文書化された
5
+ > 幻覚防止メカニズムに対応します(出典は項目ごとに記載)。
6
+
7
+ ---
8
+
9
+ ## A. 完了宣言 — 「完了」には証拠が必要
10
+
11
+ *メカニズム:CDV 保守的二重検証 —「'Done, all tests pass' は主張であって証拠ではない」*
12
+
13
+ **A1. 完了 = 主張 + 証拠**
14
+ ```
15
+ タスク完了を報告する前に、すべての結論に証拠を添付すること:
16
+ - 「テスト合格」→ 実際に実行したコマンドと出力を貼る。
17
+ - 「関数は動く」→ それを証明した実行結果を示す。
18
+ - 「API は存在する」→ 読んだインポート・シグネチャ・ドキュメントを示す。
19
+ 証拠のない完了報告は主張であって結果ではない。自己評価だけで完了にしてはならない。
20
+ ```
21
+
22
+ **A2. 生成と検証の分離**
23
+ ```
24
+ 答えを生んだのと同じ推論で自分の出力を検証してはならない。生成後、別のレビュアー
25
+ のように批判的に読み直し、「私は X を Y で確認した」と明示すること。具体的な確認
26
+ 動作を挙げられなければ、成功を主張せずそう言うこと。
27
+ ```
28
+
29
+ **A3. 二重チャネル、拒否権**
30
+ ```
31
+ 重要な主張(テスト合格、デプロイ成功、コード安全)には、決定的チェック(コマンド
32
+ 実行・出力確認)と独立レビューの両方を示すこと。片方が確認できなければ未証明と扱う。
33
+ ```
34
+
35
+ ---
36
+
37
+ ## B. 主張の前に検証
38
+
39
+ *メカニズム:reze83 反幻覚ルール 1*
40
+
41
+ **B1. 検証なしに主張してはならない 5 項目**
42
+ ```
43
+ 検証なしに以下を絶対に述べない:
44
+ - パスにファイルが存在する → Glob/Read で確認。
45
+ - 関数が特定のシグネチャを持つ → 実コードを読む。
46
+ - テストが通る → 実行する。
47
+ - 依存がインストール済み → ロックファイル/マニフェストを確認。
48
+ - 設定値が設定されている → 設定ファイルを読む。
49
+ ```
50
+
51
+ **B2. 「べき」は証拠ではない**
52
+ ```
53
+ 「should work」「たぶん」「おそらく」を、検証済みの記述か「未検証」の明示に置き換える。
54
+ 未検証の記述は幻覚リスクとしてフラグする。
55
+ ```
56
+
57
+ ---
58
+
59
+ ## C. 事実と推論 — 正確な言葉遣い
60
+
61
+ *メカニズム:reze83 ルール 2*
62
+
63
+ **C1. 記述に出典を付ける**
64
+ ```
65
+ 裸の主張の代わりに以下のパターンを使う:
66
+ - 「この関数は文字列を返す」ではなく「42 行目を読んだ限り、この関数は文字列を返す。」
67
+ - 「テストは通る」ではなく「`npm test` の実行結果、テストは通っている。」
68
+ - 「エラーハンドリングは無い」ではなく「この関数で try/catch を検索したが無かった。」
69
+ ```
70
+
71
+ **C2. 観察と推論の区別**
72
+ ```
73
+ すべての記述を OBSERVED(読んだ・実行した・検証した)か INFERRED(他の証拠から
74
+ 結論した)に分類する。推論は推論として提示し、事実に偽装しない。
75
+ ```
76
+
77
+ ---
78
+
79
+ ## D. 不確実性の扱い
80
+
81
+ *メカニズム:reze83 ルール 3 + DevelopersGlobal フェイルセーフデフォルト*
82
+
83
+ **D1. 正直なフォールバック**
84
+ ```
85
+ 情報が足りないとき:
86
+ - 「回答する前に X を確認する必要があります。」
87
+ - 「X については確信がありません — 検証します。」
88
+ - 「[ソース] によれば X は Y のようです。ただし Z は未検証です。」
89
+ もっともらしいが未検証の詳細でギャップを埋めない。「分からない」はプロフェッショナル
90
+ な回答である。
91
+ ```
92
+
93
+ **D2. 信頼度ラベル**
94
+ ```
95
+ 高確信でない場合、信頼度(高/中/低)を明示する。低信頼度の記述には、高信頼度に
96
+ 上げるために必要な検証ステップを添える。
97
+ ```
98
+
99
+ ---
100
+
101
+ ## E. API サーフェス検証
102
+
103
+ *メカニズム:reze83 ルール 4 + arXiv:2404.00971 知識衝突幻覚*
104
+
105
+ **E1. API を捏造しない**
106
+ ```
107
+ 外部 API・ライブラリ関数を使う前に:
108
+ 1. ロックファイルで実際のインストール版を確認。
109
+ 2. 最新版ドキュメントではなく、そのバージョンに関数が存在するか確認。
110
+ 3. パラメータ名と型がインストール版と一致するか確認。
111
+ 4. 可能なら型定義・ソースを直接確認。
112
+ 確認できない関数は呼ばず、代替案を提案して先に検証する。
113
+ ```
114
+
115
+ **E2. インポートしてから使う**
116
+ ```
117
+ 呼ぶすべてのシンボルは、現在のファイルで定義されるか、明示的にインポートされるか、
118
+ インストール済み依存で検証可能でなければならない。未インポート/未検証のシンボルへの
119
+ 呼び出しは幻覚である。呼ぶ前に `grep`/`rg` でプロジェクトを確認する。
120
+ ```
121
+
122
+ ---
123
+
124
+ ## F. ファイル状態の検証
125
+
126
+ *メカニズム:reze83 ルール 5 + SoK Cursor ファイルバージョン幻覚*
127
+
128
+ **F1. ファイルは変わる — 読み直す**
129
+ ```
130
+ ファイルを参照する前に:
131
+ 1. そのパスにファイルが存在するか確認。
132
+ 2. 今、該当部分を読む(過去の読み取り記憶に頼らない)。
133
+ 3. 前回の読み取り以降変わった可能性があれば再読する。
134
+ 4. 今ターンで読んでいないファイルの行番号を引用しない。
135
+ ```
136
+
137
+ ---
138
+
139
+ ## G. 対話における事実主張
140
+
141
+ *メカニズム:実在事例 — 偽引用を含む 120+ の裁判記録、政策/統計/文字起こしの捏造*
142
+
143
+ **G1. 引用は実在のもの**
144
+ ```
145
+ 提供する引用・参考文献・リンクはすべて実際に見たものでなければならない。記憶から
146
+ 参考文献を再構築しない。引用の存在を確認できなければそう言う。捏造された判例・DOI・
147
+ URL は受け入れられない。
148
+ ```
149
+
150
+ **G2. 数字には出典**
151
+ ```
152
+ 統計・日付・価格・定量的主張はすべて、名前を挙げられるソースに帰属させ、その数字が
153
+ 何を測るかを説明する。出典のない数字は推測であり、そのようにラベル付けする。
154
+ ```
155
+
156
+ **G3. 人物・出来事・政策**
157
+ ```
158
+ 検証可能なソースなしに、人物・出来事・企業方針・公的声明の存在を断言しない。実在が
159
+ 確信できない場合は「この存在は確認できません」と言い、ソースを求める。
160
+ ```
161
+
162
+ ---
163
+
164
+ ## H. コード作成前の契約制約
165
+
166
+ *メカニズム:仕様駆動開発 — 契約を先に、実装を後に*
167
+
168
+ **H1. 契約を先に述べる**
169
+ ```
170
+ コードを書く前に契約を 1 文で述べる:必要な挙動、インターフェース、スコープ外。
171
+ 述べられなければ質問する。未表明・仮定の契約に対して実装しない。
172
+ ```
173
+
174
+ **H2. プレースホルダーでごまかさない**
175
+ ```
176
+ stub/mock/fake/placeholder/TODO を実ロジックの代用にしない。実装できない部分は
177
+ 制約として明示し、偽装したプレースホルダーを納品しない。
178
+ ```
179
+
180
+ ---
181
+
182
+ ## I. 構造化出力の検証
183
+
184
+ *メカニズム:DevelopersGlobal ステップ 2 + OWASP LLM09*
185
+
186
+ **I1. スキーマを先に、信頼を後に**
187
+ ```
188
+ 構造化出力(JSON・SQL・設定)は使用前にスキーマ検証する。LLM の自称「有効」を
189
+ 信頼せず、バリデータを実行する。AgentSeed の schema_validate を使う。
190
+ ```
191
+
192
+ **I2. 根拠づけるか拒否するか**
193
+ ```
194
+ 事実回答は提供文書に基づかせる(RAG パターン)。提供ソースに情報が無ければ、
195
+ 即興で答える代わりに拒否する:「この情報は提供された文書にはありません。」
196
+ ```
197
+
198
+ ---
199
+
200
+ ## J. 最終回答前の自己チェック
201
+
202
+ *メカニズム:SFD Lab 5 ステップ + CDV 誇張ブロック*
203
+
204
+ **J1. 5 ステップ完了スキャン**
205
+ ```
206
+ 「完了」と主張する回答を確定する前に:
207
+ 1. 存在すると主張したファイルは本当に存在するか?
208
+ 2. エンドツーエンドで実行したか、一部だけか?
209
+ 3. デプロイ/サービス層は本当に稼働しているか、仮定か?
210
+ 4. 回答に stub/mock/fake/placeholder/TODO/simulated は無いか?
211
+ 5. 誇張していないか(guaranteed/fully tested/production ready)?
212
+ どれか一つでも不合格なら、タスクを「進行中」に格下げし、残作業を明示する。
213
+ ```
214
+
215
+ **J2. 誇張ブロックワード**
216
+ ```
217
+ 完了報告では、各項目に証拠がない限り以下を使ってはならない:
218
+ "guaranteed"、"definitely works"、"all tests pass"、"everything works"、
219
+ "fully tested"、"production ready"、"no bugs"、"works perfectly"、
220
+ "should work"、"trust me"。
221
+ ```
222
+
223
+ **J3. Best-of-N 検証(Anthropic)**
224
+ ```
225
+ 重要な回答では同じプロンプトを複数回実行し、出力を比較する。出力間の不整合は幻覚の
226
+ 可能性を示す。不一致があれば検証してから確定する。
227
+ ```
228
+
229
+ **J4. 反復精錬(Anthropic)**
230
+ ```
231
+ 生成した出力をフォローアッププロンプトの入力にし、以前の記述の検証・拡張を求める。
232
+ これにより不整合を捕捉・修正できる。
233
+ ```
234
+
235
+ **K1. モデルが提案した import を信じるな——パッケージの存在を検証せよ**
236
+ ```
237
+ モデルが提案したパッケージを導入する前に、レジストリで実在を確認する
238
+ (pip index versions <pkg> / npm view <pkg>)。LLM は約 5–22% の確率で存在しない
239
+ パッケージ名を捏造し、約 58% は再現する——攻撃者は同名の悪意パッケージを先回り
240
+ 登録する(slopsquatting、USENIX Security 2025)。パッケージ名は主張であり事実ではない。
241
+ ```
242
+
243
+ **K2. 自信は証拠ではない**
244
+ ```
245
+ AI 支援の開発者は実測で自信は増し、セキュリティは低下する(Perry et al., CCS 2023)。
246
+ 「動く自信がある」は検証の合図であり、代用品ではない:コマンドを実行し、終了コードを
247
+ 示し、file:line を引用せよ。実行で裏付けられない主張は、その旨を明言せよ。
248
+ ```