/**
 * Shadow phase-event ledger for the phase-aware runtime.
 *
 * Slice 1 records events only. No gate or nudge reads these events yet, so this
 * module must stay append-only and behavior-neutral.
 */
export function recordPhaseEvent(taskState, args) {
    const event = {
        iter: args.iter,
        kind: args.kind,
        ts: Date.now(),
    };
    if (args.tool !== undefined)
        event.tool = args.tool;
    if (args.detail !== undefined)
        event.detail = args.detail;
    if (args.evidenceKind !== undefined)
        event.evidenceKind = args.evidenceKind;
    if (args.phaseHint !== undefined)
        event.phaseHint = args.phaseHint;
    taskState.phaseEvents.push(event);
    return event;
}
export function recordAssistantTextPhaseEvent(taskState, iter, text) {
    if (!text.trim())
        return null;
    return recordPhaseEvent(taskState, {
        iter,
        kind: 'assistant_text',
        detail: text.slice(0, 240),
        phaseHint: 'report',
    });
}
export function recordRuntimeNudgePhaseEvent(taskState, iter, nudgeKind) {
    return recordPhaseEvent(taskState, {
        iter,
        kind: 'runtime_nudge',
        detail: nudgeKind,
    });
}
export function recordToolPhaseEvent(taskState, iter, kind, tool, detail) {
    const args = {
        iter,
        kind,
        tool,
        phaseHint: phaseHintForTool(tool, kind),
    };
    if (detail !== undefined)
        args.detail = detail;
    return recordPhaseEvent(taskState, args);
}
export function recordPermissionPhaseEvent(taskState, iter, kind, tool) {
    return recordPhaseEvent(taskState, {
        iter,
        kind,
        tool,
    });
}
export function recordPostGrantEvidencePhaseEvent(taskState, iter, evidenceKind, detail) {
    return recordPhaseEvent(taskState, {
        iter,
        kind: 'post_grant_evidence',
        evidenceKind,
        detail,
        phaseHint: 'execute',
    });
}
export function recordVerificationEvidencePhaseEvent(taskState, iter, tool, detail) {
    return recordPhaseEvent(taskState, {
        iter,
        kind: 'verification_evidence',
        tool,
        detail,
        phaseHint: 'verify',
    });
}
export function recordCompletionClaimPhaseEvent(taskState, iter, text) {
    return recordPhaseEvent(taskState, {
        iter,
        kind: 'completion_claim',
        detail: text.slice(0, 240),
        phaseHint: 'report',
    });
}
function phaseHintForTool(tool, kind) {
    if (tool === 'DeliveryAudit' || tool === 'TaskVerify' || tool === 'ArtifactVerify')
        return 'verify';
    if (tool === 'Read' || tool === 'read' || tool === 'Grep' || tool === 'grep' || tool === 'Glob' || tool === 'glob')
        return 'explore';
    if (tool === 'TaskCreate' || tool === 'TaskUpdate' || tool === 'TodoWrite')
        return 'plan';
    if (kind === 'tool_completed')
        return 'execute';
    return 'execute';
}
//# sourceMappingURL=phase-event-state.js.map