{
  "_comment": [
    "ai-memory lifecycle hooks for DeepSeek Harness — EXAMPLE / TEMPLATE.",
    "",
    "This file is a starting point, not something the plugin installs for you.",
    "Replace every <PLACEHOLDER> below with your own paths, then point a row in",
    "your profile's cordis.patch.yml at it (INSERT form — a bare `- id:` row only",
    "overrides an existing loader and would be ignored for a new one):",
    "",
    "  - insert:",
    "      - id: hooks-ai-memory",
    "        name: '@deepseek-ai/dsh-hooks-claude-code'",
    "        config:",
    "          configPath: <ABSOLUTE PATH TO THIS FILE>",
    "          defaultTimeoutMs: 30000",
    "",
    "The bridge reads this file ONCE at startup, so a change takes effect only",
    "after DSH restarts.",
    "",
    "WHY THIS LEGACY FILE IS HAND-WRITTEN:",
    "Older ai-memory presets emit exec form - the binary in `command` and every flag",
    "in a sibling `args` array. dsh-hooks-claude-code does not read `args` at",
    "all: it keeps only `typeof hook.command === 'string'` and discards the rest.",
    "Running the generated snippet therefore spawns ai-memory with no arguments,",
    "which prints its help text and exits 1 - capture silently does nothing.",
    "This is the LEGACY template: every capture command uses `claude-code`.",
    "ai-memory >=3.2.0 now has a native `dsh` kind and first-party DSH support.",
    "For native capture on those releases, replace --agent claude-code with",
    "--agent dsh in ALL seven commands and restart DSH before a new session.",
    "Do not use dsh with older ai-memory. Leave the plugin agentKind unset:",
    "it reads each stored session's actual kind, preserving legacy backlog.",
    "The manual commands below remain single strings for the bridge API.",
    "",
    "DSH runs each command as:",
    "  pwsh -NoLogo -NoProfile -NonInteractive -Command <string>",
    "which means ordinary PowerShell quoting works. On Windows, keep the `&`",
    "call operator.",
    "",
    "EVENTS: exactly the ones dsh-hooks-claude-code supports - SessionStart,",
    "UserPromptSubmit, PreToolUse, PostToolUse, Stop, SubagentStart,",
    "SubagentStop. ai-memory's own Claude Code preset also lists PreCompact and",
    "SessionEnd; DSH fires neither, so they are omitted rather than registered as",
    "dead entries. That missing SessionEnd is precisely why this plugin exists:",
    "without `dsh-ai-memory`, a DSH session stays open in ai-memory forever and",
    "never becomes a wiki page or a handoff.",
    "",
    "PreToolUse is INCLUDED here (it records tool intent as its own observation),",
    "but it is the first thing to delete if latency hurts: DSH awaits every hook",
    "synchronously and has no async hook option (unlike Codex, whose `async: true`",
    "takes a multi-second hook off the response path). ai-memory's claude-code",
    "dialect answers `{}` for pre-tool-use, so it never grants or blocks a tool.",
    "Measured on DSH 0.2.1-rc.2 / Windows: one hook costs ~0.5 s of shell startup",
    "in isolation, but ~3 s end-to-end through DSH's subprocess runner, so",
    "PreToolUse + PostToolUse add roughly 6 s per tool call. Remove PreToolUse to",
    "halve that; PostToolUse is what actually records the tool result.",
    "",
    "WHY Stop CHAINS `hook-drain`: ai-memory buffers each event into a spool file",
    "and delivers it in a background drainer it spawns itself. Its native presets",
    "trigger that drain on SessionEnd, and DSH never fires SessionEnd - so events",
    "sat in the spool until the next SessionStart. Chaining the hidden but",
    "documented-for-hooks `hook-drain` command makes delivery happen at the end of",
    "every turn instead. Without it, recall in a new session is always one session",
    "behind. Measured cost of the drain itself: ~40-80 ms.",
    "",
    "SANDBOX: DSH runs hook commands through ctx.shell WITHOUT a session, so they",
    "use the deployment-default policy rather than the session's mode. On DSH",
    "0.2.1-rc.2 / Windows that default is `workspace-write`, whose ACL runner is",
    "broken in the Electron build: every child dies STATUS_DLL_INIT_FAILED",
    "(0xC0000142) after 6-9 s, capture records nothing, and the failure is silent.",
    "Two working responses, either is enough:",
    "  a) set the deployment default to `danger-full-access` (the sandbox is then",
    "     skipped entirely: `pwsh-sandbox` returns before confinement), or",
    "  b) grant write on ai-memory's data directory to Everyone, which is what",
    "     ai-memory's own Windows launcher does for its spool.",
    "Verify capture with `ai-memory status` - observations must rise while you",
    "work. Do not trust \"the hook is registered\" as evidence of capture.",
    "",
    "REPLACE <AI_MEMORY_EXE> with the full path to ai-memory.exe (Windows) or",
    "ai-memory (Linux/macOS), and <AI_MEMORY_DATA_DIR> with your data directory:",
    "  Windows: %LOCALAPPDATA%\\ai-memory",
    "  Linux:   ~/.local/share/ai-memory",
    "  macOS:   ~/Library/Application Support/ai-memory",
    "",
    "On Linux/macOS the command string must use POSIX quoting instead, e.g.",
    "  \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event stop ..."
  ],
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "& \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event session-start --agent claude-code --server-url http://127.0.0.1:49374",
            "timeout": 30
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "& \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event user-prompt-submit --agent claude-code --server-url http://127.0.0.1:49374",
            "timeout": 30
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "& \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event pre-tool-use --agent claude-code --server-url http://127.0.0.1:49374",
            "timeout": 30
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "& \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event post-tool-use --agent claude-code --server-url http://127.0.0.1:49374",
            "timeout": 30
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "& \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event stop --agent claude-code --server-url http://127.0.0.1:49374; & \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook-drain",
            "timeout": 30
          }
        ]
      }
    ],
    "SubagentStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "& \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event subagent-start --agent claude-code --server-url http://127.0.0.1:49374",
            "timeout": 30
          }
        ]
      }
    ],
    "SubagentStop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "& \"<AI_MEMORY_EXE>\" --data-dir \"<AI_MEMORY_DATA_DIR>\" hook --event subagent-stop --agent claude-code --server-url http://127.0.0.1:49374",
            "timeout": 30
          }
        ]
      }
    ]
  }
}
