{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package continuation\n\nPackage continuation is the ONE durable suspend/resume mechanism for an agent turn that stops mid-flight to wait for a human.\n\nIt exists as its own package because two very different callers need it and neither should depend on the other: an interactive session (which already holds the conversation in memory and only needs the missing pair of messages back) and an unattended executive (which keeps no transcript at all — it rebuilds context from durable state each wake, so the continuation must carry the conversation itself). Before this package there were three partial designs: a typed-but-unused one in internal/agent/runtime, a set of declared-but-never-written fields on jobs.Job, and a hand-rolled map\\[string]any in the personal executive that was the only one actually running. Keep it one.\n\nThe invariant that makes resume exact: a suspending tool must be the SOLE tool use in its assistant response (ValidateSingletonSuspension). Otherwise a sibling tool call in the same batch would be silently dropped on resume, or re-executed — both wrong. Save refuses to write a suspension that violates it, so the error surfaces at suspend time rather than as corruption at resume.\n\n## Functions\n\n```go\nfunc MarkResolved(dir, interactionID string) error\n```\nMarkResolved records that a continuation has been consumed without producing resume messages — for a caller that resolved the interaction by another route (cancelled, or a resumed run that itself re-suspended on a new question) and must not leave the old file loadable.\n\n```go\nfunc Resolve(dir string, s Suspension, result wire.Block) ([]wire.Message, error)\n```\nResolve builds the resume messages and marks the continuation resolved in one step, for a caller that can afford to lose the retry (see ResumeMessages).\n\n```go\nfunc Save(dir string, s Suspension) error\n```\nSave writes the continuation atomically. A crash mid-write must not be able to leave a truncated file — that would strand the interaction with no way to resume it.\n\n```go\nfunc SessionDir(root, sessionID string) string\n```\nSessionDir is where an interactive session's continuations live.\n\n```go\nfunc ValidateSingletonSuspension(msg wire.Message, toolUseID string) error\n```\nValidateSingletonSuspension enforces that the suspending tool is the only tool use in its assistant response — see the package comment.\n\n## Types\n\n```go\ntype Suspension struct {\n\tVersion       int             `json:\"version\"`\n\tSessionID     string          `json:\"session_id,omitempty\"`\n\tRunID         string          `json:\"run_id,omitempty\"`\n\tInteractionID string          `json:\"interaction_id\"`\n\tToolUseID     string          `json:\"tool_use_id\"`\n\tToolName      string          `json:\"tool_name,omitempty\"`\n\tToolInput     json.RawMessage `json:\"tool_input,omitempty\"`\n\t// Assistant is the response carrying the suspending tool use.\n\tAssistant wire.Message `json:\"assistant\"`\n\t// Messages is the full transcript up to and including Assistant. Set it\n\t// when the caller keeps no transcript of its own; Resolve then hands back\n\t// the whole conversation plus the answer. Leave it empty when the caller\n\t// still holds the prior turns — Resolve then returns only the two messages\n\t// to append, so the transcript is never duplicated.\n\tMessages  []wire.Message `json:\"messages,omitempty\"`\n\tCreatedAt time.Time      `json:\"created_at\"`\n\tResolved  bool           `json:\"resolved\"`\n}\n```\nSuspension is the exact continuation of a turn paused on a human answer.\n\n```go\nfunc Load(dir, interactionID string) (Suspension, error)\n```\nLoad reads an unresolved continuation. An already-resolved one is an error, not an empty result: resuming it twice would re-execute real side effects.\n\n```go\nfunc (s Suspension) ResumeMessages(result wire.Block) ([]wire.Message, error)\n```\nResumeMessages builds the messages to resume with — the full transcript plus the answer when Messages was recorded, or just the assistant/answer pair when the caller holds the transcript itself — WITHOUT marking the continuation resolved.\n\nSeparated from Resolve because the two callers differ on when it is safe to mark: an interactive session has the human right there and can simply ask again, so it marks immediately; an unattended executive must keep the interaction retryable until the resumed run actually reaches a terminal state, or a transient model error would strand the answer with no way to re-give it.\n\nThe result block must match the suspended tool\\_use\\_id — a mismatched pairing is how a resume silently answers the wrong question.\n\n","path":"github.com/memcode-ai/memcode/internal/agent/continuation","name":"continuation","synopsis":"Package continuation is the ONE durable suspend/resume mechanism for an agent turn that stops mid-flight to wait for a human.","isRedistributable":true}
