Skip to content

Session

Defined in: src/session.ts:266

A Session manages a conversation with an AI model about a code repository.

Sessions provide:

  • Multi-turn conversations with message history
  • Tool execution (file reading, code search, etc.)
  • Progress callbacks for streaming UI updates
  • Automatic cleanup of git worktrees on close

Example

const session = await connect(repoUrl);
const result = await session.ask("What does this repo do?");
console.log(result.response);
session.close();

Properties

id

readonly id: string

Defined in: src/session.ts:268

Unique identifier for this session


repo

readonly repo: Repo

Defined in: src/session.ts:270

The repository this session is connected to

Methods

ask()

ask(question, options?): Promise<AskResult>

Defined in: src/session.ts:338

Ask a question about the repository.

The model will use available tools to explore the codebase and formulate an answer. Concurrent calls are serialized (queued) to maintain conversation coherence.

Parameters

question

string

The question to ask

options?

AskOptions

Optional settings including progress callback

Returns

Promise<AskResult>

Result containing the response, tool calls made, and usage statistics

Throws

Error if the session has been closed


askStream()

askStream(prompt, options?): AskStream

Defined in: src/session.ts:364

Ask a question and get a streaming response (new API).

Returns an AskStream synchronously. The stream starts producing events when consumed (iterated or .result() awaited). Concurrent calls are serialized — the second stream won’t produce events until the first completes.

Parameters

prompt

string

options?

NewAskOptions

Returns

AskStream

Throws

Error (synchronous) if the session is closed


close()

close(): Promise<void>

Defined in: src/session.ts:418

Close the session and clean up resources.

This removes the git worktree associated with the session. The session cannot be used after closing. Safe to call multiple times.

Returns

Promise<void>


getMessages()

getMessages(): Message[]

Defined in: src/session.ts:397

Get all messages in the conversation history. Includes user messages, assistant responses, and tool results.

Returns

Message[]


getTurn()

getTurn(id): TurnResult | null

Defined in: src/session.ts:435

Get a specific turn by ID. Returns null if not found.

Parameters

id

string

Returns

TurnResult | null


getTurns()

getTurns(): readonly TurnResult[]

Defined in: src/session.ts:430

Get all completed turns in chronological order.

Returns

readonly TurnResult[]


replaceMessages()

replaceMessages(messages): void

Defined in: src/session.ts:407

Replace the entire conversation history. Useful for restoring a previous session state.

Parameters

messages

Message[]

The new message history

Returns

void