Skip to content

Commit 87bfde1

Browse files
committed
feat: add Codex guidance install tool
1 parent 5276123 commit 87bfde1

5 files changed

Lines changed: 141 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ codex plugin add evolver@evomap
2424

2525
Start a new Codex thread after installation so the bundled skill is loaded.
2626

27+
To inject or refresh the global Codex guidance section from the plugin itself,
28+
ask Codex to call `evolver_install_codex_guidance`. The tool updates
29+
`~/.codex/AGENTS.md` with marker-delimited Evolver instructions and creates a
30+
timestamped backup before changing an existing file.
31+
2732
Optional, but recommended when you want the same machine-wide workflow in every
2833
Codex project:
2934

plugins/evolver/.codex-plugin/plugin.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"interface": {
2424
"displayName": "Evolver",
2525
"shortDescription": "Use Evolver GEP workflows and Proxy tools from Codex.",
26-
"longDescription": "Evolver is EvoMap's GEP-powered self-evolution engine for AI agents. This Codex Desktop plugin bundles a skill plus an MCP bridge to the local Evolver Proxy mailbox, helping Codex reuse Genes and Capsules, check Proxy status, run review-oriented evolution workflows in git workspaces, configure Codex hooks, and keep local evolution memory auditable.",
26+
"longDescription": "Evolver is EvoMap's GEP-powered self-evolution engine for AI agents. This Codex Desktop plugin bundles a skill plus an MCP bridge to the local Evolver Proxy mailbox, helping Codex reuse Genes and Capsules, check Proxy status, install global Codex AGENTS.md guidance on request, run review-oriented evolution workflows in git workspaces, configure Codex hooks, and keep local evolution memory auditable.",
2727
"developerName": "EvoMap",
2828
"category": "Productivity",
2929
"capabilities": [
@@ -35,6 +35,7 @@
3535
"defaultPrompt": [
3636
"Check Evolver Proxy status for this workspace.",
3737
"Search EvoMap Genes before changing this repo.",
38+
"Install or refresh global Codex Evolver guidance.",
3839
"Run Evolver review mode and explain the GEP output."
3940
],
4041
"brandColor": "#2F855A",

plugins/evolver/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This plugin packages Evolver as a Codex-ready workflow: a model-invoked skill, a
1212
| --- | --- | --- |
1313
| Passive recall | Skill guidance | Prompts Codex to look for past outcomes, local memory, and relevant Genes before starting substantive work. |
1414
| Network bridge | MCP server `evolver-proxy` | Exposes `evolver_status`, `evolver_search_assets`, `evolver_fetch_asset`, `evolver_publish_asset`, and `evolver_poll` through the local EvoMap Proxy mailbox. |
15+
| Codex guidance | MCP tool `evolver_install_codex_guidance` | Installs or refreshes the global `~/.codex/AGENTS.md` Evolver guidance section when the user explicitly asks. It makes a timestamped backup before writing. |
1516
| Active control | CLI workflow | Guides Codex through `evolver`, `evolver --review`, `evolver --loop`, strategy presets, and Codex hook setup. |
1617
| Safety boundary | Git + review | Evolver emits protocol-bound GEP prompts and auditable events; Codex should not auto-apply generated output unless the user asks. |
1718

@@ -55,7 +56,11 @@ Start the Proxy by running `evolver` once inside a git repo.
5556

5657
## Optional Codex hooks
5758

58-
The plugin gives Codex the `evolver_*` MCP tools. To also install Codex hooks
59+
The plugin gives Codex the `evolver_*` MCP tools. To add global Codex guidance
60+
without installing hooks, ask Codex to call `evolver_install_codex_guidance`.
61+
Use `dry_run: true` first if you want to preview the AGENTS.md section.
62+
63+
To also install Codex hooks
5964
that inject local evolution memory at session start and record local outcomes at
6065
session end, install the CLI and run:
6166

plugins/evolver/mcp/evolver-proxy.mjs

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,126 @@
1212
* This bridge never spawns it; when it is down, tools return a helpful error.
1313
*/
1414

15-
import { readFileSync } from 'node:fs';
15+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
1616
import { homedir } from 'node:os';
1717
import { join } from 'node:path';
1818
import { createInterface } from 'node:readline';
1919

2020
const SERVER = { name: 'evolver-proxy', version: '0.1.0' };
2121
const DEFAULT_PROTOCOL = '2025-06-18';
22+
const CODEX_GUIDANCE_START = '<!-- evolver-codex-guidance:start -->';
23+
const CODEX_GUIDANCE_END = '<!-- evolver-codex-guidance:end -->';
2224

2325
function log(...a) { process.stderr.write('[evolver-proxy-mcp] ' + a.join(' ') + '\n'); }
2426

27+
function codexGuidanceSection(language) {
28+
if (language === 'zh') {
29+
return `${CODEX_GUIDANCE_START}
30+
## Evolver 全局指令
31+
32+
- 开始实质性工作前,先调用 \`evolver_status\`;如果 Proxy 正常,再用简短任务信号调用 \`evolver_search_assets\`,优先复用已有 Genes/Capsules。
33+
- 如果召回到相关资产,用 \`evolver_fetch_asset\` 获取候选内容;只采用与当前任务匹配、可验证的部分。
34+
- 任务结束后,只有当产出确实可复用为 Gene/Capsule 时才调用 \`evolver_publish_asset\`;普通本地结果由已安装的 Evolver hooks 在 Stop 阶段记录。
35+
- 如果 MCP 工具不可用、Proxy token 过期或 transport 断开,重启/启动 Evolver Proxy,或在插件/Proxy 更新后开启一个新的 Codex 线程。
36+
${CODEX_GUIDANCE_END}`;
37+
}
38+
39+
return `${CODEX_GUIDANCE_START}
40+
## Evolver Global Guidance
41+
42+
- Before substantive work, call \`evolver_status\`; if the Proxy is running, call \`evolver_search_assets\` with concise task signals before designing or editing.
43+
- If assets match, call \`evolver_fetch_asset\` for promising IDs and apply only the relevant, verifiable guidance.
44+
- At task end, call \`evolver_publish_asset\` only for genuinely reusable Genes/Capsules; ordinary local outcomes are recorded by installed Evolver hooks when present.
45+
- If MCP tools are unavailable, the Proxy token is stale, or transport is closed, start/restart the Evolver Proxy or open a new Codex thread after plugin/Proxy changes.
46+
${CODEX_GUIDANCE_END}`;
47+
}
48+
49+
function updateCodexGuidanceContent(before, section) {
50+
const start = before.indexOf(CODEX_GUIDANCE_START);
51+
const end = before.indexOf(CODEX_GUIDANCE_END);
52+
if ((start === -1) !== (end === -1) || (start !== -1 && end < start)) {
53+
return {
54+
ok: false,
55+
error: `Malformed Evolver guidance markers in ~/.codex/AGENTS.md. Expected both ${CODEX_GUIDANCE_START} and ${CODEX_GUIDANCE_END}.`,
56+
};
57+
}
58+
59+
if (start !== -1) {
60+
const replaceEnd = end + CODEX_GUIDANCE_END.length;
61+
const next = before.slice(0, start) + section + before.slice(replaceEnd);
62+
return { ok: true, content: next, action: 'updated' };
63+
}
64+
65+
const trimmed = before.trimEnd();
66+
const prefix = trimmed ? trimmed + '\n\n' : '';
67+
return { ok: true, content: prefix + section + '\n', action: 'inserted' };
68+
}
69+
70+
function installCodexGuidance(args = {}) {
71+
const language = args.language === 'zh' ? 'zh' : 'en';
72+
const dryRun = args.dry_run === true;
73+
const codexDir = join(homedir(), '.codex');
74+
const agentsPath = join(codexDir, 'AGENTS.md');
75+
let before = '';
76+
let existed = true;
77+
try {
78+
before = readFileSync(agentsPath, 'utf8');
79+
} catch {
80+
existed = false;
81+
}
82+
83+
const section = codexGuidanceSection(language);
84+
const updated = updateCodexGuidanceContent(before, section);
85+
if (!updated.ok) return { ok: false, error: updated.error };
86+
87+
const content = updated.content.endsWith('\n') ? updated.content : updated.content + '\n';
88+
const changed = content !== before;
89+
if (dryRun) {
90+
return {
91+
ok: true,
92+
data: {
93+
dry_run: true,
94+
changed,
95+
action: changed ? updated.action : 'unchanged',
96+
agents_path: agentsPath,
97+
language,
98+
section,
99+
},
100+
};
101+
}
102+
103+
if (!changed) {
104+
return {
105+
ok: true,
106+
data: {
107+
changed: false,
108+
action: 'unchanged',
109+
agents_path: agentsPath,
110+
language,
111+
},
112+
};
113+
}
114+
115+
mkdirSync(codexDir, { recursive: true });
116+
let backupPath = null;
117+
if (existed) {
118+
backupPath = agentsPath + `.bak.${Math.floor(Date.now() / 1000)}`;
119+
writeFileSync(backupPath, before, 'utf8');
120+
}
121+
writeFileSync(agentsPath, content, 'utf8');
122+
return {
123+
ok: true,
124+
data: {
125+
changed: true,
126+
action: updated.action,
127+
agents_path: agentsPath,
128+
backup_path: backupPath,
129+
language,
130+
restart_recommended: true,
131+
},
132+
};
133+
}
134+
25135
/**
26136
* Resolve the live Proxy connection. ~/.evolver/settings.json is authoritative:
27137
* the running Proxy writes both its url and a per-instance auth token there.
@@ -152,6 +262,19 @@ const TOOLS = [
152262
},
153263
handler: (a) => proxyFetch('POST', '/mailbox/poll', { type: a.type, limit: a.limit || 10 }),
154264
},
265+
{
266+
name: 'evolver_install_codex_guidance',
267+
description: 'Install or update the global Codex ~/.codex/AGENTS.md Evolver guidance section. Creates a timestamped backup before writing. Use only when the user explicitly wants global Codex guidance installed or refreshed.',
268+
inputSchema: {
269+
type: 'object',
270+
properties: {
271+
language: { type: 'string', enum: ['en', 'zh'], default: 'en', description: 'Language for the injected AGENTS.md section.' },
272+
dry_run: { type: 'boolean', default: false, description: 'Preview the section and change action without writing files.' },
273+
},
274+
additionalProperties: false,
275+
},
276+
handler: installCodexGuidance,
277+
},
155278
];
156279

157280
const TOOL_BY_NAME = Object.fromEntries(TOOLS.map(t => [t.name, t]));
@@ -185,7 +308,7 @@ async function dispatch(req) {
185308
protocolVersion: params?.protocolVersion || DEFAULT_PROTOCOL,
186309
capabilities: { tools: {} },
187310
serverInfo: SERVER,
188-
instructions: 'Evolver Proxy bridge. Use evolver_search_assets before substantive work to reuse proven genes/capsules; evolver_status to check the Proxy; evolver_publish_asset to contribute new ones.',
311+
instructions: 'Evolver Proxy bridge. Use evolver_search_assets before substantive work to reuse proven genes/capsules; evolver_status to check the Proxy; evolver_publish_asset to contribute new ones. Use evolver_install_codex_guidance only when the user explicitly wants global Codex AGENTS.md guidance installed or refreshed.',
189312
});
190313
case 'notifications/initialized':
191314
case 'initialized':

plugins/evolver/skills/evolver/SKILL.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Useful MCP tools from this plugin:
4242
- `evolver_fetch_asset`: fetch full asset content by ID.
4343
- `evolver_publish_asset`: submit reusable Genes or Capsules to the Hub for review.
4444
- `evolver_poll`: poll local mailbox messages such as `asset_submit_result` or `hub_event`.
45+
- `evolver_install_codex_guidance`: install or refresh the global `~/.codex/AGENTS.md` Evolver guidance section, with a timestamped backup. Use only when the user explicitly asks to add global Codex guidance.
4546

4647
Never print Proxy bearer tokens from `~/.evolver/settings.json`.
4748

@@ -110,6 +111,8 @@ Explain generated GEP output in terms of:
110111

111112
## Codex Integration
112113

114+
If the user only wants global Codex guidance, call `evolver_install_codex_guidance` instead of editing `~/.codex/AGENTS.md` by hand. Prefer `dry_run: true` first when the user asks to preview the prompt. The tool writes a marker-delimited section and creates a timestamped backup before changing an existing file.
115+
113116
For Codex hook integration, run:
114117

115118
```bash

0 commit comments

Comments
 (0)