codex-agentmemory-windows — 代码代理内存窗口
v1.0.0为 Windows 上的 Codex App 配置、修复和验证 agentmemory 集成。使用时,Codex 需要设置 agentmemory hooks、修复 Windows PowerShell hook 故障、创建 agentmemory-hook.cmd 包装器、更新 ~/.codex/hooks.json 和 trusted_hash 条目,或排除 Codex App agentmemory MCP/hook 配置故障。
运行时依赖
安装命令
点击复制技能文档
为 Codex App 在 Windows 上设置 agentmemory,使用 PowerShell 安全的 hook 命令和可重复的验证。首选使用捆绑的脚本进行确定性的修复。
快速修复 运行帮助程序时,用户想要自动修复: python scripts/configure_agentmemory_windows.py --codex-home "$env:USERPROFILE\.codex" 根据需要使用以下选项: python scripts/configure_agentmemory_windows.py --secret "" python scripts/configure_agentmemory_windows.py --url "http://localhost:3111" --secret "" python scripts/configure_agentmemory_windows.py --preserve-other-hooks python scripts/configure_agentmemory_windows.py --dry-run 该脚本备份 hooks.json 和 config.toml,创建 agentmemory-hook.cmd,写入 Windows 安全的 hook 命令,更新 Codex hook 信任哈希,配置 agentmemory MCP 部分,并验证 hook 命令。
手动工作流 检查 %USERPROFILE%\.codex\hooks.json、%USERPROFILE%\.codex\config.toml 和 %USERPROFILE%\.codex\agentmemory-hook.cmd。 找到安装的 agentmemory 插件根目录,通常为 %USERPROFILE%\.codex\plugins\cache\agentmemory\agentmemory\。 找到 node.exe;首选使用 Get-Command node.exe、C:\Program Files\nodejs\node.exe 或 Codex 捆绑的 node.exe 获取绝对路径。 从现有的配置或环境中读取 AGENTMEMORY_SECRET 和 AGENTMEMORY_URL。不要硬编码其他用户的密钥。 在 %USERPROFILE%\.codex\agentmemory-hook.cmd 创建一个包装器: @echo off set "AGENTMEMORY_URL=http://localhost:3111" set "AGENTMEMORY_SECRET=" set "AGENTMEMORY_INJECT_CONTEXT=true" if "%~1"=="" exit /b 2 "C:\Path\To\node.exe" "C:\Path\To\agentmemory\scripts\%~1" exit /b %ERRORLEVEL% 通过 cmd.exe 写入 hook 命令,而不是直接引用 PowerShell 调用: cmd.exe /d /s /c ""C:\Users\\.codex\agentmemory-hook.cmd" session-start.mjs" 使用此事件到脚本映射: Codex hook 事件 | 脚本 ---------|-------- PreToolUse | pre-tool-use.mjs PostToolUse | post-tool-use.mjs SessionStart | session-start.mjs UserPromptSubmit | prompt-submit.mjs Stop | stop.mjs PreCompact | pre-compact.mjs 更新 config.toml [hooks.state.'...\hooks.json::0:0'] 条目,启用 = true 和 trusted_hash = "sha256:"。 如果使用全局 hooks.json 包装器,禁用 agentmemory@agentmemory:hooks/hooks.codex.json 下的重复插件提供的 hook。 通过 PowerShell 将样本 hook JSON 管道到每个命令,并要求退出代码 0 进行验证。
为什么这可以修复 Windows Hook 错误 PowerShell 将 "C:\path\agentmemory-hook.cmd"视为字符串。如果直接在其后面跟有参数,PowerShell 可能会出现意外的令牌 'session-start.mjs' 错误。 稳定的 Windows 形式是: & "C:\path\agentmemory-hook.cmd" session-start.mjs 或更强大的 Codex hook 运行器: cmd.exe /d /s /c ""C:\path\agentmemory-hook.cmd" session-start.mjs" 在 hooks.json 中使用 cmd.exe 形式。
验证命令 在手动编辑后使用以下命令: $payload = '{"session_id":"test","cwd":"C:\\Temp","prompt":"test"}' $hooks = Get-Content "$env:USERPROFILE\.codex\hooks.json" -Raw | ConvertFrom-Json foreach ($event in $hooks.hooks.PSObject.Properties.Name) { $cmd = $hooks.hooks.$event[0].hooks[0].command $payload | powershell.exe -NoProfile -Command $cmd Write-Host "$event exit=$LASTEXITCODE" } 所有事件都应返回 exit=0。
常见的非阻塞警告 不要将这些与 hook 命令失败混淆: Shell 快照不支持 PowerShell:这是 Codex shell 快照限制,而不是 agentmemory hook 失败。 chatgpt 身份验证需要远程插件目录:这是远程插件同步警告,而不是本地 hook 执行。 GitHub API 限速已超过:这是策划插件同步警告,而不是 agentmemory hook 执行。 资源/列表或资源/模板/列表未知的 agentmemory MCP:这是 MCP 能力警告,而不是 hook 捕获失败。