Skip to content

feat: Import Bob transcripts #1872

Closed

Description

@huang195

Part of #1856, which holds the design for all agents. Depends on #1871 (the shared import path). Start this issue after #1871 merges.

Bob source (this issue)

Add a Bob source, so that agentop import --agent bob imports Bob's task history.

  • Store: ~/.bob/db/bob.db, SQLite in WAL mode. Tables tasks (id, parent_id, title, directory, env, costs, created_at, updated_at, task_type) and messages (task_id, role, data JSON, created_at).
  • Read it through sqlite3 -readonly -json <db> <query> as a subprocess. macOS includes sqlite3. When it is missing, fail this agent with an error that names the missing program, and let the other agents continue. Do not add a SQLite driver to the proxy. Put the helper where feat: Import OpenCode transcripts #1874 (OpenCode) can use it too.
  • The session id is tasks.id. This is the X-Task-Id value that live capture files Bob under (checked on a real archive).
  • A child task (task_type = subtask or subagent) files in its ROOT task (follow parent_id to the top), with SessionEvent.Subagent set to the child's own id.
  • messages.data roles: system, user (content, availableTools), assistant (content, toolCalls, reasoning, thinkingBlocks, stop), tool (content, toolUsage).
  • Model: tasks.env → model.id. It is a tier alias such as premium-ide, not a real model. Use it as given.
  • Cost: data._meta.spend.cost on each assistant message is Bob's own price (flat $2/Mtok, matched to Bob's ledger). Write it as the settled cost with Source: transcript, Provenance: authoritative. Do not price Bob through the pricing table. contextTokens is TotalTokens. Bob records no input/output split.
  • Project: tasks.directory. Title: tasks.title.
  • Check first: do Bob Shell sessions also land in bob.db? The older ~/.bob/tmp/*/chats/*.json files and the IDE's globalStorage/ibm.bob-code/tasks are out of scope unless that check says otherwise. Record the answer in the PR body.

Acceptance criteria

  • Bob tasks list in agentop with title, project, tokens and Bob's cost.
  • The Timeline opens a task with its tool calls and its child tasks.
  • A missing sqlite3 fails Bob only, with a clear error.
  • Fixture tests from a scrubbed bob.db (a plain task, tool calls, a child task, one row that does not parse).

The shared part, from #1871

#1871 adds POST /v1/import, agentop import, the importer rules, the archive write, the ledger rows and the imported mark. This issue adds only a source and registers it. A source only parses: it never touches the archive, the store or the ledger. Implement the Source interface as #1871 merged it. Its design shape was:

type Source interface {
    Agent() string               // "claude-code", "bob", ...
    Sessions(since time.Time) iter.Seq2[Session, error]
}
type Session struct {
    ID       string    // the Cortex session id, see this issue
    Updated  time.Time // last activity, for --since and for the replace rule
    Project  string    // cwd
    Title    string    // when the store has one
    Events   []*model.SessionEvent
    Skipped  int       // lines or rows not recognized
}

Events a source builds

For each model turn the source builds a request event and a response event with the
same RequestID, both with Direction outbound and an Inference extension:

  • Request: Model, Messages (the whole conversation up to this turn, as the agent
    sent it), Tools when the store records them, ToolResults for the tool results that
    this turn sends.
  • Response: Completion, ToolCalls, ResponseThinking, FinishReason, and the token
    fields that the store records (InputTokens, CompletionTokens, CacheReadTokens,
    CacheWriteTokens, TotalTokens).
  • At is the store's timestamp for the turn.
  • A subagent's events go in its root session with SessionEvent.Subagent set to the
    subagent's own id, and AgentRole set too. The Timeline tells subagents apart by
    Subagent (timeline.go:412-416). AgentRole alone merges them into one row.

The archive interns on disk the same fields that the store interns, so the repeated
Messages prefix costs about what it costs for a live session.

Cost (Bob: see above, not the pricing table)

Price each turn's tokens through the existing pricing table, at today's rates. The cost record gets Source: transcript. A turn with no usage gets no cost record. It is not priced as zero.

Bad input

  • A line or row that the source does not recognize is skipped and counted. It does not
    stop the import.
  • A session where nothing parsed is not written.
  • A file or database that cannot be opened fails that agent only, with its error in
    the response.

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions