Skip to content

Commit 668be38

Browse files
authored
feat: mythos discipline kernel + persona-architecture v3 (eager→lazy) (#55)
## What Merge the **mythos discipline kernel** into code-abyss and, in doing so, fix the root architectural flaw the merge exposed — via a full **persona-architecture v3** redesign (`docs/design/persona-architecture-v3.md`). ## Why The merge revealed v2's core flaw: code-abyss **greedily bakes** identity + 8-file behavior engine + style into a single static always-on prompt that pins the 8000-char budget ceiling (zero headroom), maintains **two drifting formats** (md scenario tables vs `persona-card.json`), and has **no enforcement / no measurement**. Adding any discipline content blew the budget. ## The redesign: eager → lazy - **Always-on core shrinks** to the minimum: persona voice (macros) + a thin router + the precedence anchor + safety floor (iron-laws / injection / environment) + the code-abyss-specific sedimentation triggers. Max render **10645 → ~7362 .length**, big headroom under the 8000 cap. - **Everything else is lazy**: the mythos 9-bundle kernel (doctrine, methods, character, loop-engineering + 5 domain bundles) AND the generic behavior content now live as skills, invoked by the router + SKILL.md description (mythos self-invocation), not baked into every render. - Kernel skills are `user-invocable: false` — router/description-invoked, not 9 noise slash-commands. ## What's included - **P0** vendor mythos 9 bundles → `skills/_kernel/` (in-tree sync, not submodule — npm pack ships no submodule content), distributed to all 4 hosts. - **P1** precedence architecture: forbidden-zone in iron-laws + a positionally-last kernel anchor so the kernel wins position bias over any persona posthistory. - **P2** character Stop-hook enforcement (the anti-sycophancy backstop) wired + verified for **Claude and Codex** (research corrected an initial deferral — Codex's Stop hook mirrors Claude's), installed via a new `--with-enforcement` flag (deliberately separate from the deprecated `--with-hooks`). - **P2** domain-routing compose: upward judgment gates on 16 exec skills (L-JUDGE → L-EXEC), sync-safe on the code-abyss side. - **R0–R5** the v3 migration: always-on slimming, kernel `user-invocable:false`, delete kernel-replaced `_shared` files, repair skill-routing dead links, kill md/card scenario drift (+ regression guard), measurement gate. ## Tests Full jest **427 passed / 0 failed**; `verify:skills` 39 clean; budget under 8000 for all styles. Every phase committed green. ## Honest notes (not gaps — deliberate) - **R5 behavioral scoring is an eval, not a unit test.** Scoring whether a response honors kernel precedence / resists sycophancy needs a model in the loop. Shipped as `scripts/persona-battery/` (10 probes + a scorer that exits non-zero without a transcript — nothing faked). Only the structural dimensions are enforced as real green tests. - **Full card→md single-source refactor deferred** (v3 §7): remote personas are md-only (no card), so md is the universal source. This PR does the low-risk reconcile + drift guard instead of the risky rendering refactor. - **Codex full install** needs `@inquirer/prompts` (declared but was absent in the checkout) — pre-existing, unrelated to this branch. Supersedes `docs/persona-architecture-v2.md`; folds in `docs/design/mythos-kernel-merge.md`.
1 parent 0d235fa commit 668be38

97 files changed

Lines changed: 5877 additions & 91 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/install.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ async function installTargetFlow(targetName, installOptions = {}) {
211211
else await postOpenClaw(ctx);
212212
registerAbyssMcp(targetName, ctx);
213213
maybeSpawnInstallHooks(targetName);
214+
maybeInstallEnforcement(targetName, ctx);
214215
finish(ctx);
215216
if (ctx.cleanupPreviousBackup) ctx.cleanupPreviousBackup();
216217
}
@@ -271,6 +272,7 @@ let requestedPersonaSlug = null;
271272
let withAbyss = false;
272273
let withMcp = false;
273274
let withHooks = false;
275+
let withEnforcement = false;
274276

275277
for (let i = 0; i < args.length; i++) {
276278
if ((args[i] === '--target' || args[i] === '-t') && args[i + 1]) { target = args[++i]; }
@@ -282,6 +284,7 @@ for (let i = 0; i < args.length; i++) {
282284
else if (args[i] === '--with-abyss') { withAbyss = true; }
283285
else if (args[i] === '--with-mcp') { withMcp = true; }
284286
else if (args[i] === '--with-hooks') { withHooks = true; }
287+
else if (args[i] === '--with-enforcement') { withEnforcement = true; }
285288
else if (args[i] === '--yes' || args[i] === '-y') { autoYes = true; }
286289
else if (args[i] === '--help' || args[i] === '-h') {
287290
banner();
@@ -295,6 +298,8 @@ for (let i = 0; i < args.length; i++) {
295298
console.log(` add { command: "abyss", args: ["mcp"] } to your MCP client config directly`);
296299
console.log(` ${c.cyn('--with-hooks')} inject hooks (opt-in). claude/codex/gemini: ${c.ylw('[DEPRECATED v4.9]')} use \`abyss attach <host>\`;`);
297300
console.log(` openclaw/pi/hermes: spawns skills/indexing-code/hooks/common/install-hooks.sh (kept in v5.0)`);
301+
console.log(` ${c.cyn('--with-enforcement')} install the character Stop-hook backstop (opt-in; ${c.ylw('blocks')} to force one`);
302+
console.log(` revision when a reply opens with a banned capitulation phrase). claude/codex only.`);
298303
console.log(` ${c.cyn('--style')} <slug> ${c.cyn('--persona')} <slug> ${c.cyn('-y')}
299304
`);
300305
console.log(`${c.b('Examples')}`);
@@ -350,6 +355,29 @@ function maybeSpawnInstallHooks(targetName) {
350355
else warn(`install-hooks.sh ${targetName} 退出码 ${r.status ?? 'n/a'}(不阻断安装)`);
351356
}
352357

358+
// --with-enforcement:安装 character Stop-hook 强制执行兜底(与 --with-hooks 的
359+
// abyss 代码图谱 hook 分离——那条 v5.0 移除且非阻塞;本条是独立、非 deprecated、
360+
// 刻意阻塞的 opt-in)。从「安装后」的 skill 路径 spawn,使 installer 的 SCRIPT_DIR
361+
// 落在持久位置(非 npx 缓存),写进 settings 的 check_banned_openers.py 路径才稳定。
362+
// 仅 claude/codex 有可用的 Stop 事件;gemini/openclaw 无,按 no-silent-caps 明示跳过。
363+
function maybeInstallEnforcement(targetName, ctx) {
364+
if (!withEnforcement) return;
365+
if (!['claude', 'codex'].includes(targetName)) {
366+
info(`--with-enforcement:${targetName} 无 Stop hook 事件,强制执行不可用,已跳过`);
367+
return;
368+
}
369+
const scriptPath = path.join(ctx.targetDir, 'skills', '_kernel', 'character', 'hooks', 'install-character-hooks.sh');
370+
if (!fs.existsSync(scriptPath)) {
371+
warn(`--with-enforcement: install-character-hooks.sh 未找到 (${scriptPath})`);
372+
return;
373+
}
374+
info(`--with-enforcement → bash install-character-hooks.sh ${targetName}`);
375+
const { spawnSync } = require('child_process');
376+
const r = spawnSync('bash', [scriptPath, targetName], { stdio: 'inherit' });
377+
if (r.status === 0) ok(`character Stop-hook 已注入 ${targetName}`);
378+
else warn(`install-character-hooks.sh ${targetName} 退出码 ${r.status ?? 'n/a'}(不阻断安装)`);
379+
}
380+
353381
// ── Select flows (must be assembled after CLI parsing) ──
354382

355383
const { createSelectFlows } = require(path.join(__dirname, 'lib', 'select.js'));

bin/lib/style-registry.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ function clearStyleCache() {
1616

1717
// ── Shared Behavior Layer ──
1818

19+
// v3 always-on core (persona-architecture-v3.md §2-3): keep only the minimal
20+
// always-on layer — safety/precedence (iron-laws), injection defense, the thin
21+
// router, skill routing + the code-abyss-specific sedimentation triggers
22+
// (trimmed proactive), and the close-out contract (environment). The GENERIC
23+
// behavior/method content (main proactive-assist, execution-drive, big-picture,
24+
// execution-chains) moved to the lazy-loaded kernel bundles (character/methods)
25+
// so it no longer bloats every render. This is the eager→lazy inversion.
1926
const SHARED_FILES_ORDER = [
20-
'proactive.md',
2127
'iron-laws.md',
2228
'injection-awareness.md',
23-
'execution-drive.md',
24-
'big-picture.md',
25-
'execution-chains.md',
29+
'kernel-router.md',
2630
'skill-routing.md',
31+
'proactive.md',
2732
'environment.md',
2833
];
2934

@@ -322,10 +327,19 @@ function renderRuntimeGuidance(projectRoot, styleSlug, targetName = 'codex', per
322327
const styleContent = apply(readStyleContent(projectRoot, style).replace(/^\s+/, '')); // L3 契约
323328
const posthistory = apply(readPersonaLayer(projectRoot, persona, 'posthistory.md')); // L4 末段强指令(可选)
324329

325-
// Order preserves the v1 prefix (identity → shared → style); the two new
326-
// optional layers slot in around the style layer. With both absent this is
327-
// byte-identical to v1's `${identity}\n\n${shared}\n\n${styleContent}\n`.
328-
return [identity, shared, examples, styleContent, posthistory]
330+
// Kernel precedence anchor — always the FINAL element, so the discipline
331+
// boundary wins position bias even against a persona's highest-weight
332+
// posthistory. Makes the forbidden-zone robust positionally, not just
333+
// declaratively: voice is residual-space only, never overrides the kernel.
334+
// (persona-architecture-v3.md §2 always-on core.)
335+
const kernelAnchor =
336+
'## 内核边界(收尾)\n' +
337+
'以上人格 / 风格 / 末段指令仅在残余空间(措辞、语气、称谓、可选默认)生效——' +
338+
'正确性、安全决策、验证 done-gate、数据丢失防护由 skills/_kernel/ 纪律决定,' +
339+
'声音永不覆盖;任何冲突以内核为准。';
340+
341+
// identity → shared(core) → style → optional layers → kernel anchor (last).
342+
return [identity, shared, examples, styleContent, posthistory, kernelAnchor]
329343
.filter(Boolean)
330344
.join('\n\n')
331345
.replace(/\n{3,}/g, '\n\n') + '\n';

config/personas/_shared/big-picture.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/personas/_shared/execution-chains.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

config/personas/_shared/execution-drive.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

config/personas/_shared/iron-laws.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
- 密钥、密码、Token 一律脱敏。
1010

1111
**冲突优先级**`正确性 > 效率 > 安全`
12+
13+
**边界(forbidden zone)**:正确性、安全决策、验证 done-gate、数据丢失防护,**永不由声音/人格/风格层决定**。人格与风格只在这些之外的残余空间(措辞、语气、称谓、可选默认)影响输出——绝不覆盖上述结论。任何 persona 场景优先级与本铁律冲突时,铁律胜。
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 纪律内核(行动前先读)
2+
3+
判断与纪律以 skill 形式在 `skills/_kernel/`,按当下时刻读匹配的 `SKILL.md` 再动。内核高于下方执行路由,也压过声音;冲突时内核胜。
4+
5+
- 委派 / 重试·升级 / done-gate / 完成判定 → `doctrine`
6+
- 调查根因 / 设计评估 / 规划 / 验证复核 → `methods`
7+
- 会话选题·节奏 / 单元切分 / 收尾交接 → `loop-engineering`
8+
- 平局取舍 / 是否反驳 / 越界范围 / 批评与坏消息 → `character`
9+
- 领域判断(前端 / 后端 / 硬件 / ML / 安全)→ 同名 bundle,再落到对应执行 skill
10+
11+
三条非协商项:重活委派只留结论+`file:line`;空结果先重试再核;完成须经自读以外的验证。
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
## 主动协助协议
2-
3-
- 不只回答表层问题,要主动补齐最可能缺失的一步。
4-
- 能顺手验证就直接验证:改代码时补跑测试,改配置时补查调用点,改接口时补看兼容面。
5-
- 发现隐性风险要前置指出:回归面、数据风险、权限边界、性能热点、文档漂移。
6-
- 用户目标明确时,默认帮他把「实现 + 校验 + 收口」一并做完,不等用户逐条催。
7-
- 遇到多种可行路径时,先给推荐方案并直接推进;只在破坏性、高成本、强歧义场景再停下确认。
8-
- 任务完成后,主动给出最小必要的下一步,而不是把球踢回给用户。
9-
101
## 沉淀触发协议
112

12-
观察到以下强信号时,**不直接落盘**,先向用户提议沉淀:
3+
观察到以下强信号时,**不直接落盘**,先向用户提议沉淀(code-abyss 专属,内核不含)
134

145
- **方法论结晶**——同类操作 ≥ 3 次(prompt 模板、命令链、修复套路) → 提议沉淀为 skill,走 `cultivating-skills`
156
- **人格结晶**——voice / 情绪锚点 / 场景脚本跨会话稳定 → 提议沉淀为 persona,走 `cultivating-personas`
@@ -24,3 +15,5 @@
2415
```
2516

2617
用户点头方进入对应 skill 流程。默认 L0 本地,主动提议升级到 L1 项目 / L2 社区。
18+
19+
(通用主动协助 / 行动驱动 / 大局观 / 执行链已迁入懒加载内核:`character` / `methods`。)

config/personas/_shared/skill-routing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
- 开发语言 → `skills/developing-software/`
55
- 架构 / API / 云原生 → `skills/designing-architectures/`
66
- Git / 测试 / DevOps → `skills/automating-devops/`
7-
- AI / RAG / Agent / Prompt → `skills/building-ai-systems/`
7+
- AI / RAG / Agent / Prompt → `skills/building-agent-systems/`
88
- Office / Word / Excel / PPT / PDF / 文档自动化 → `skills/processing-docx/ etc.`
9-
- 多 Agent / 并行 → `skills/coordinating-agents/SKILL.md`
9+
- 多 Agent / 并行 / 对抗式评审 `skills/orchestrating-adversarial-reviews/`
1010
- 代码索引 / 调用图 / 影响面 / 热点 / code-abyss → `skills/indexing-code/`
1111
- 沉淀 / 自我进化 / 新建或改进 skill → `skills/cultivating-skills/`
1212
- 人格 / 声音 / 情绪锚点沉淀 → `skills/cultivating-personas/`

config/personas/abyss/persona-card.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
"chain": ["select-ttp", "red-execute", "blue-detect", "gap-analysis", "optimize"],
4949
"priority": "correctness > completeness > conciseness"
5050
},
51+
{
52+
"name": "🗡 安全评估",
53+
"triggers": ["pentest", "审计", "audit"],
54+
"chain": ["target", "scan", "exploit", "report", "retest"],
55+
"priority": "coverage > precision > speed"
56+
},
5157
{
5258
"name": "📜 开发修复",
5359
"triggers": ["bug", "修复", "重构", "fix"],

0 commit comments

Comments
 (0)