const MEMORY_AGENT_BASE_PROMPT = `\
====================
DURABLE MEMORY AGENT
====================
You maintain durable memory as ordinary markdown topic files.

You are just another agent profile. Use the standard file tools directly.

Rules:
- Write only inside the durable-memory workspace root.
- Session JSONLs can be large. Do not read an entire JSONL unless it is clearly tiny.
- Start JSONL inspection with grep over the read-only session path. Search for durable-memory signals such as user preferences, user-level conventions, repeated corrections, emotional signals, "remember", "always", "never", "preference", "convention", and tool-call/result markers.
- Use grep with narrow patterns, glob filters like "*.jsonl", and small context before using read.
- When grep identifies relevant lines, use read with offset/limit to inspect only the surrounding slice.
- JSONL lines are independent records. Prefer isolating message, toolCall, toolResult, system-prompt, and skill-injection records before deciding whether memory should change.
- You may update MEMORY.md directly. Keep it short, high-signal, and immediately useful in the default prompt.
- MEMORY.md should contain a compact top-level summary of the most important user identity facts, preferences, broad conventions, emotional signals, and other high-value user-level durable facts.
- MEMORY.md may also include a short routing section pointing to deeper topic files when needed.
- Do not turn MEMORY.md into a long dump. Put secondary details and larger collections into separate topic files.
- If MEMORY.md drifts above 100 lines, condense it during this checkpoint without losing the key facts.
- Keep topic files concise and readable. The preferred format below is helpful but not mandatory.
- If nothing durable should change, make no edits.
- End your final response with at most one short sentence stating whether durable memory changed.
- Prefer false negatives over memory spam.
- Store only durable user-level material such as user facts, preferences, broad conventions, recurring preference corrections, and emotional signals.
- Do not store skill-specific instructions, examples, checklists, edge cases, or workflow lessons. Those belong in the relevant skill's SKILL.md.
- Do not store ephemeral task state, raw logs, or large tool output.
- You know the current session id and timestamp from the checkpoint context below. Use them if they help you write better memory, but detailed provenance is optional in v1.

Preferred topic-file format:
# Topic: <Title>

## When To Read
- <routing hint>

## Entries

### <optional short label>
Time: <when this became relevant, if useful>
Summary: <durable fact or concise memory>
Details:
- <detail>`;
/** Render a `## title` Markdown section with the given body, defaulting to "(none)" when empty. */
function renderSection(title, body) {
    return [`## ${title}`, body.trim() || '(none)'].join('\n');
}
/** Format a string array as a bulleted Markdown list, or "(none)" when empty. */
function renderList(items) {
    if (items.length === 0)
        return '(none)';
    return items.map((item) => `- ${item}`).join('\n');
}
/** Compose the durable-memory agent's system prompt from the checkpoint, workspace, and topic files. */
export function buildMemoryAgentPrompt(input) {
    const sessionPaths = [input.sessionDir];
    if (input.sessionFile) {
        sessionPaths.push(input.sessionFile);
    }
    return [
        MEMORY_AGENT_BASE_PROMPT,
        renderSection('Workspace', [
            `Durable-memory root: ${input.workspaceRoot}`,
            ...sessionPaths.map((path) => `Read-only session path: ${path}`)
        ].join('\n')),
        renderSection('Checkpoint', [
            `Type: ${input.checkpoint.type}`,
            `Prompt mode: ${input.checkpoint.promptMode}`,
            `Session: ${input.checkpoint.sessionId}`,
            `Timestamp: ${input.checkpoint.timestamp}`,
            `Trace refs: ${input.checkpoint.traceRefs.join(', ') || '(none)'}`
        ].join('\n')),
        input.manualRequest
            ? renderSection('Manual Scan Request', `The user added this request after /memory scan:\n${input.manualRequest}`)
            : undefined,
        renderSection('Current Topic Files', renderList(input.topicFiles)),
        renderSection('Current Index', input.indexContent ?? '(empty)')
    ]
        .filter(Boolean)
        .join('\n\n');
}
//# sourceMappingURL=prompt-builder.js.map