No JSDoc comment in source yet.
API
@Component()
export class SessionsRepo implements SessionIndex {
@Use() private readonly db!: Db;
insert(row: SessionRow): void;
insertOrIgnore(row: SessionRow): void;
insertFork(sourceSessionId: string, row: SessionRow): SessionRow;
markOrgClient(sessionIds: readonly string[]): void;
markHasTrace(sessionId: string): void;
markDriven(sessionId: string, at: string): void;
touchLastActive(sessionId: string, at: string): void;
findById(sessionId: string): SessionRow | null;
listByAgent(projectId: string, agentId: string): SessionRow[];
listByProject(projectId: string): SessionRow[];
findBySuffix(projectId: string, suffix: string): SessionRow[];
updateApprovalMode(sessionId: string, mode: ApprovalMode): void;
updateSandbox(sessionId: string, sandbox: SandboxSettings): void;
updateThinkingLevel(sessionId: string, level: ThinkingLevelName): void;
updateTitle(sessionId: string, title: string): void;
updateModel(sessionId: string, provider: string, modelId: string): void;
updateTitleIfNull(sessionId: string, title: string): void;
setListing(sessionIds: readonly string[], listing: "archived" | "kept", at: string): void;
replaceId(oldSessionId: string, newSessionId: string): void;
deleteByAgent(projectId: string, agentId: string): void;
deleteByProject(projectId: string): void;
deleteById(sessionId: string): void;
}Dependencies & Wiring
Extracted from class decoratorsMethods (22)
insert
insert(row: SessionRow): voidSessionRowvoidinsertOrIgnore
insertOrIgnore(row: SessionRow): voidIdempotent insert: used when Trace directory discovery backfills a row (concurrent listing discovering the same Session no longer triggers a UNIQUE violation).
SessionRowvoidinsertFork
insertFork(sourceSessionId: string, row: SessionRow): SessionRowAllocate the source Session's next persistent fork number and insert its fork atomically.
Keeping both writes in one transaction prevents concurrent requests from sharing a number,
while retaining fork_count on the source means deleting an older fork never reuses it.
stringSessionRowSessionRowmarkOrgClient
markOrgClient(sessionIds: readonly string[]): voidStamp client = "org" on the rows an organization's files name, leaving the ones
already stamped alone. The reconcile pass calls it with every session the desk ledger
and the tickets' sessions fields claim, so a row opened before the marker existed
carries the organization's provenance from the next pass on — and keeps it when the
organization is deleted or company mode is switched off, which is exactly when the
organization caches can no longer answer for it. Chunked because the id list is
unbounded while SQLite's parameter count is not.
readonly string[]voidmarkHasTrace
markHasTrace(sessionId: string): voidFlip the has_trace cache once a Trace record exists (discovery hydration); idempotent.
stringvoidmarkDriven
markDriven(sessionId: string, at: string): voidA driven run touched this Session: flip the has_trace cache and stamp last_active_at in
ONE statement (drive's run start — one WAL commit instead of two).
MAX(COALESCE(...)) keeps the stamp monotonic: a backwards clock step (NTP, resume
from suspend) leaves the stored value alone rather than regressing the row.
stringstringvoidtouchLastActive
touchLastActive(sessionId: string, at: string): voidStamp last_active_at alone (drive's run end); monotonic like markDriven.
stringstringvoidfindById
findById(sessionId: string): SessionRow | nullstringSessionRow | nulllistByAgent
listByAgent(projectId: string, agentId: string): SessionRow[]An Agent's rows, newest first (the list order the sidebar shows; served by
idx_sessions_agent_created). Never filtered by client — every row is listed
whichever client created it.
stringstringSessionRow[]listByProject
listByProject(projectId: string): SessionRow[]stringSessionRow[]findBySuffix
findBySuffix(projectId: string, suffix: string): SessionRow[]The Session's original case and punctuation matter; the suffix is literal SQL data.
stringstringSessionRow[]updateApprovalMode
updateApprovalMode(sessionId: string, mode: ApprovalMode): voidstringApprovalModevoidupdateSandbox
updateSandbox(sessionId: string, sandbox: SandboxSettings): voidReplace the Session's sandbox policy snapshot (applies from its next command).
stringSandboxSettingsvoidupdateThinkingLevel
updateThinkingLevel(sessionId: string, level: ThinkingLevelName): voidPin the session's thinking level (runs without one of their own then use it).
stringThinkingLevelNamevoidupdateTitle
updateTitle(sessionId: string, title: string): voidstringstringvoidupdateModel
updateModel(sessionId: string, provider: string, modelId: string): voidThe session's current model after an in-session switch (or a reconcile against its Trace).
stringstringstringvoidupdateTitleIfNull
updateTitleIfNull(sessionId: string, title: string): voidWrites only if the title is still NULL. Subagent-session registration and Trace directory discovery backfill can race on the same row, and both are insert-only: whichever inserts first determines the title. Discovery backfill can only supply NULL, so this method fills the title back in without overwriting an existing one (including a user rename or an already-generated title).
stringstringvoidsetListing
setListing(sessionIds: readonly string[], listing: "archived" | "kept", at: string): voidWrites the user's listing decision on these Sessions: archived stamps archived_at and
clears the keep mark, kept clears archived_at and stamps the keep mark — at most one of
the two is ever set. Chunked like markOrgClient, since a batch names up to 500 ids.
readonly string[]"archived" | "kept"stringvoidreplaceId
replaceId(oldSessionId: string, newSessionId: string): voidSelf-healing: after rebuilding a broken Session with no Trace, update the primary key to the new id.
stringstringvoiddeleteByAgent
deleteByAgent(projectId: string, agentId: string): voidstringstringvoiddeleteByProject
deleteByProject(projectId: string): voidstringvoiddeleteById
deleteById(sessionId: string): voidstringvoid