Agent Adapters & Installers
From spec-memo Wiki, the living architecture & domain knowledge base
Feature Overview [edit]
This page covers the interfaces that connect consumer repositories and agent hosts to spec-memo without putting memory in product git:
- The relocatable consumer hub and memory adapter that route read/write memory to the vault or MCP.
- The write-block pre-commit hook that refuses staged workflow artifacts.
- The
install-hooksandinstall-skillsCLIs that write host lifecycle adapters and packaged skills, with a shared interactive wizard and explicit permission gates. - The Codex (GPT) hook adapter.
Skill-only mode remains first-class: an agent using only the autoloaded ws-memo skill gets all 11 MCP tools; hooks are strictly opt-in.
Business Rules & Logic [edit]
Memory adapter (src/adapter.ts, MemoryAdapter):
readMemoryBootstrap(cwd, query)compiles the bootstrap brief throughcompileBootstrapBriefwithin the configured byte budget (default 8192 bytes) and sanitizes output.updateMemoryTrap(cwd, trap)slugstrap-<scenario>, builds a## Scenario / ## DO NOT / ## INSTEAD DObody, and upserts kindtrapwith severity defaultmedium.updateMemoryLog(cwd, message, details)appends a write-only event viaappendEvent.- The adapter delegates storage to the vault/MCP core; when the MCP server is unreachable the deployment layer is fail-open (hybrid) or fail-closed (remote) rather than the adapter caching results in-repo.
Write-block hook (src/hook.ts):
- Blocked patterns:
.agents/plans/,MEMORY.md,memory/*.md. Allowed product docs that are never blocked:README.md,PRODUCT.PRD,FEATURES.md,PLAN.md,AGENTS.md,GEMINI.md,.agents/specs/index.PRD. - The generated
pre-commitscript scansgit diff --cached --name-only; on a match it prints guidance to usespec-memoMCP/CLI and exits 1. - Bypass:
SKIP_MEMO_HOOK=1orgit commit --no-verify. installPreCommitHookwrites.git/hooks/pre-commit(mode0o755) and backs up a foreign existing hook to<hook>.spec-memo.bak. No server-side push hook exists.- Note: current code blocks plans and in-repo memory only; it does not block
.agents/specs/**at large (only.agents/specs/index.PRDis explicitly allowed).
install-hooks (src/hooks-install.ts):
- Supported hook hosts:
antigravity,opencode,cursor,claude,codex, plusall. - Default is preview:
applyfalse (or--applywithout confirmation) yieldsstatus: 'preview'and writes nothing.--applyrequires explicit confirmation (--yes/--confirm) for permission-gated calls. - All generated shell bridges are fail-open:
timeout 1.5 <memo> ... >/dev/null 2>&1 || truewith a 1500 ms ceiling (HOOK_TIMEOUT_MS), and exit 0 even ifmemois missing. - Event mapping: Antigravity
PreInvocation(invocationNum 0) andPostInvocation; CursorsessionStart/beforeSubmitPrompt/sessionEnd(timeout 1); ClaudeSessionStart/UserPromptSubmit/PreCompact/SessionEnd; OpenCode pluginonInit/onPrompt/onExit; Codex managed instruction block. - Templates are stamped
// generated-by: spec-memo@<version>or ageneratedByJSON field.--removerestores the newest timestamped.bakor prunes the spec-memo block/entry.--forceoverwrites with a timestamped.bak. --jsonemits rows{ host, path, status: installed|removed|unchanged|preview|skipped|refused, diff }plusscope,hosts,conflictPolicy,status,productRoot, andpreflight.
Interactive install targets (src/install-wizard.ts):
- Catalog ids:
cursor,antigravity(aliasesgemini,google),codex(aliasesgpt,openai),opencode,claude(aliasclaude-code). Conflict policies:skip|update|force. Scopes:local|global. - On a TTY with missing choices, both installers run the wizard in order: scope, conflict policy, host multi-select (detected hosts pre-checked, never auto-selected), path preview, confirm. Dismiss/EOF/any answer other than
y/yeswrites nothing. - Non-TTY writes require explicit
--yes(or--confirm),--scope, and--host;allis valid only with confirmation. Missing flags exit non-zero with a named-flag message and no writes.--jsondisables the wizard and follows the same fail-closed contract. skip: leave differing destinations, reportskipped; identical destinations reportunchanged.update: overwrite missing/identical destinations and destinations stamped as spec-memo; refuse foreign files (refused) unless policy isforce.force: overwrite with.bakbehavior, subject to the vault-overlap deny.- Scope-relative hook commands: local Cursor/Claude use
.cursor/hooks/or.claude/hooks/; global user hooks use./hooks/(never.cursor/hooks/under$HOME). On win32 shell hooks are prefixed withbash. - Preflight object:
platform, resolvedmemoCommand(PATHmemoelsenode <dist/cli.js>),shellHookPrefix,chmodAttempted,ok, and optionalwarning. Apply is refused when no invocablememo/node is found unless--forceafter confirmation. - Codex: local
.codex/AGENTS.md, global$HOME/.codex/AGENTS.md, wrapped in<!-- spec-memo:start -->/<!-- spec-memo:end -->so re-install replaces the managed block only.
install-skills:
- Allowed skills:
ws-memo,ws-session-tracking. Local target default.agents/skills; global writes$HOME/.agents/skillsplus host-specific roots only for selected hosts (no implicit Antigravity copy). - Conflict policy semantics mirror hooks (
isPackagedSkillTreechecksname: <skill>, aversion:line, andmanagedBy: spec-memo). Vault overlap is denied before any tree removal.
Technical Architecture [edit]
src/adapter.ts:MemoryAdapter(bootstrap/upsert/append wrappers).src/hook.ts:BLOCKED_WORKFLOW_PATTERNS,ALLOWED_PRODUCT_DOCS,isBlockedWorkflowPath,generatePreCommitHookScript,installPreCommitHook.src/hooks-install.ts:SUPPORTED_HOOK_HOSTS,resolveHostHookPaths(host, { global, productRoot, homeDir }), per-host generators (generateAntigravityHooksJson,generateCursorHooksJson,generateClaudeHooksConfig,generateCodexAgents,generateOpenCodePlugin,generateCursorRule),deepMergeJson/stripSpecMemoFromHookConfig,installHooks, andinspectAgentHooks.src/install-wizard.ts:INSTALL_HOSTS,HOST_ALIASES,canonicalInstallHost,normalizeInstallHosts,normalizeConflictPolicy,getInstallPreflight,resolveMemoCommand,runInstallWizard.src/skills-install.ts:ALLOWED_SKILLS,resolveGlobalSkillTargets,resolveSkillInstallTargets,installSkills, vault-overlap default-deny.- MCP:
install_skillsis the only write-capable installer tool; it requiresscope,hosts,conflictPolicy, andconfirm: true. There is no MCP hooks tool. See MCP Tooling. - Doctor integration:
inspectAgentHooksreports installed hosts and outdated templates (Agent Hooks: Not installed (Skill-only mode active via ws-memo)when absent).
Provenance: 0012-relocatable-hub.spec.md, 0016-write-block-hook.spec.md, 0017-memory-adapter-mcp.spec.md, 0041-agent-hooks-install.spec.md, 0048-install-hooks-skills-interactive.spec.md.