UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

51 lines (50 loc) • 2.08 kB
import { n as sha256Hex } from "./node-crypto-B6yuTjmm.mjs"; import { y as readInterSessionPromptEnvelope } from "./input-provenance-DupvvURj.mjs"; //#region src/agents/cli-runner/reseed-envelope.ts const RESEED_HEADER = [ "Continue this conversation using the OpenClaw transcript below as prior session history.", "Treat it as authoritative context for this fresh CLI session.", "", "<conversation_history>" ].join("\n"); const RESEED_PREFIX = `${RESEED_HEADER}\n`; const RESEED_USER_BOUNDARY = "\n</conversation_history>\n\n<next_user_message>\n"; const RESEED_USER_CLOSE = "\n</next_user_message>"; function hashCliReseedPrompt(e) { return sha256Hex(e); } function parseCliReseedPrompt(e) { if (!e.startsWith(RESEED_PREFIX)) return e.startsWith(RESEED_HEADER) ? { kind: "invalid" } : { kind: "none" }; const t = e.indexOf(RESEED_USER_BOUNDARY); if (t !== e.lastIndexOf(RESEED_USER_BOUNDARY)) return { kind: "invalid" }; if (t <= RESEED_PREFIX.length) return { kind: "invalid" }; const n = t + 46; const r = e.lastIndexOf(RESEED_USER_CLOSE); if (r < n) return { kind: "invalid" }; return { kind: "legacy", userMessage: e.slice(n, r) }; } //#endregion //#region src/agents/cli-session-drift.ts const CLI_SESSION_DRIFT_NOTE_PREFIX = "OpenClaw resumed this CLI session after prompt content changed."; function buildCliSessionDriftNote(e) { return `${CLI_SESSION_DRIFT_NOTE_PREFIX} Follow the current turn's instructions; changed=${e.join(",")}.`; } const CLI_SESSION_DRIFT_NOTES = [ buildCliSessionDriftNote(["system-prompt"]), buildCliSessionDriftNote(["prompt-tools"]), buildCliSessionDriftNote(["system-prompt", "prompt-tools"]) ]; function stripCliSessionDriftNote(e) { const t = readInterSessionPromptEnvelope(e)?.length ?? 0; const n = t > 0 ? "\n" : "\n\n"; for (const r of CLI_SESSION_DRIFT_NOTES) { const i = `${r}${n}`; if (e.startsWith(i, t)) return e.slice(0, t) + e.slice(t + i.length); } return e; } //#endregion export { parseCliReseedPrompt as i, stripCliSessionDriftNote as n, hashCliReseedPrompt as r, buildCliSessionDriftNote as t };