@autorag/librarian 2.6.3 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,6 +74,13 @@ AutoRAG Agent orchestrates five integrated subsystems:
74
74
  4. **Direct Evidence Reading (`bash`):** The agent directly opens and inspects promising files with `cat`, `grep`, or `find` to verify facts against ground truth.
75
75
  5. **Curation & Active Feedback:** Structured findings are returned via `emit_autorag_results`. When callers provide feedback on which items were useful, AutoRAG records this to optimize future queries.
76
76
 
77
+ ### Pi host boundary
78
+
79
+ AutoRAG uses `@earendil-works/pi-coding-agent` as the runtime host for model sessions. Pi owns provider credentials and OAuth storage, model-runtime dispatch, session JSONL persistence/resume, extension loading, lifecycle events, and the built-in `read`/`bash`/`edit`/`write`/`grep`/`find`/`ls` tools. AutoRAG registers only its domain tools and keeps orchestration outside the host: datasource authorization, MinSync/Jikji preparation, memory hints, fast-to-verification two-phase search, structured result emission, and remote-session filtering.
80
+
81
+ The CLI TUI (`autorag tui`) is Pi's interactive mode hosted on the AutoRAG librarian: there is no separate AutoRAG renderer. Pi owns the terminal UI and its native in-session commands — `/login`/`/logout`, `/model`, `/resume`, `/new`, `/tree`, `/compact`, and `/settings` — so provider sign-in and model selection work on first launch even when no AutoRAG model is configured. AutoRAG registers its retrieval tools and streams progress, preliminary answers, and final results into the same Pi session, so resume and two-phase search keep working together.
82
+
83
+
77
84
  ---
78
85
 
79
86
  ## 🤖 For AI Agents & LLMs: Setup & Skills
@@ -249,7 +256,7 @@ PDF pages.
249
256
  # Perform a curated search (uses your configured reasoning model)
250
257
  autorag search "What are our primary Q3 deliverables?"
251
258
 
252
- # Launch the interactive Terminal UI (beta)
259
+ # Launch the interactive Terminal UI (Pi host: /login, /model, /resume, …)
253
260
  autorag tui
254
261
  ```
255
262
 
@@ -287,7 +294,8 @@ agent.recordFeedbackByNumbers(response.sessionId, [1], [2]);
287
294
  | `autorag search "<query>"` | Run the librarian agent to curate structured answers |
288
295
  | `autorag status` | Inspect corpus freshness, indexing status, and vector readiness |
289
296
  | `autorag health` | Check model provider authentication, token validity, and API reachability |
290
- | `autorag tui` | Open the interactive librarian terminal UI |
297
+ | `autorag models list` | List chat models the pi runtime can resolve (built-ins, `models.json`, custom/extension providers) with provider auth status; never prints credential values |
298
+ | `autorag tui` | Open Pi's interactive librarian TUI (`/login`, `/model`, `/resume`, …) |
291
299
  | `autorag duplicates [DIR]` | Read-only scan for exact and near-duplicate document families with `dupey` |
292
300
  | `autorag lite ...` | Model-free indexing, retrieval, report generation, and status |
293
301
  | `autorag feedback <session>` | Record useful / not-useful feedback by item number |
@@ -1,4 +1,4 @@
1
- import { Agent, type AgentTool, type Skill } from "@earendil-works/pi-agent-core";
1
+ import type { Agent, AgentTool, Skill } from "@earendil-works/pi-agent-core";
2
2
  import type { Api, Model } from "@earendil-works/pi-ai";
3
3
  import { type DatasourceAccessContextOptions } from "../datasource/access-context.js";
4
4
  import type { DatasourceIndexResult, DatasourceSkill } from "../datasource/types.js";
@@ -21,6 +21,7 @@ import type { CuratedResult, RetrievalDiagnostic, RetrievalOptions, RetrievalRes
21
21
  import { type ScanDuplicateDocumentsDetails } from "./dupey-tool.js";
22
22
  import { type AutoRAGFastAnswerDetails } from "./fast-answer-tool.js";
23
23
  import { type JikjiFindProviderResult } from "./jikji-find-tool.js";
24
+ import { type AutoRAGPiInteractiveRuntime, type AutoRAGPiSession } from "./pi-session.js";
24
25
  import { type RefreshProgressCounts, type RefreshProgressPhase } from "./refresh-progress.js";
25
26
  import { type SearchDocumentDiagnostic, type SearchDocumentsResponse, type SearchDocumentsStreamEvent } from "./search-documents.js";
26
27
  import { type WatcherFactory, type WatchRefreshHandle } from "./watch-refresh.js";
@@ -257,6 +258,12 @@ export interface AutoRAGAgentOptions {
257
258
  remoteSession?: boolean;
258
259
  /** Two-phase progressive answers with per-phase thinking control. Default enabled. */
259
260
  thinking?: AutoRAGThinkingOptions | false;
261
+ /** pi agent directory for auth/models/extensions. Defaults to ~/.pi/agent. */
262
+ piAgentDir?: string;
263
+ /** Optional persistent pi session directory. */
264
+ piSessionDir?: string;
265
+ /** Persist one pi session transcript per AutoRAG search. Defaults true. */
266
+ persistPiSessions?: boolean;
260
267
  }
261
268
  /** Post-merge reranking options. Mirrors the CLI `RerankConfig` (secrets via env). */
262
269
  export interface RerankAgentOptions {
@@ -277,6 +284,7 @@ export interface RerankAgentOptions {
277
284
  }
278
285
  export interface AutoRAGSearchSession {
279
286
  readonly agent: Agent;
287
+ readonly piSession?: AutoRAGPiSession["session"];
280
288
  prompt(text: string): Promise<void>;
281
289
  abort(): Promise<void> | void;
282
290
  dispose(): void;
@@ -308,7 +316,7 @@ export declare class AutoRAGAgent {
308
316
  private readonly sessions;
309
317
  private activeRun;
310
318
  private resultCapture;
311
- /** This agent's model credential for model-native web search (per instance, never shared). */
319
+ private interactiveFastAnswerCallback;
312
320
  private modelNativeSearchAuth;
313
321
  private retrievalTrace;
314
322
  private preliminaryCallback;
@@ -350,6 +358,10 @@ export declare class AutoRAGAgent {
350
358
  private readonly droppedCallerToolNames;
351
359
  private readonly searchTimeoutMs;
352
360
  private readonly maxSearchToolCalls;
361
+ private readonly piAgentDir;
362
+ private readonly piSessionDir;
363
+ private readonly persistPiSessions;
364
+ private boundPiRuntime;
353
365
  /** True when this agent was constructed for an untrusted remote peer. */
354
366
  readonly remoteSession: boolean;
355
367
  private activeRetrievalOptions;
@@ -364,6 +376,8 @@ export declare class AutoRAGAgent {
364
376
  private recordSearchToolEvent;
365
377
  private currentSystemPromptConfig;
366
378
  subscribe(listener: Parameters<Agent["subscribe"]>[0]): () => void;
379
+ createPiInteractiveRuntime(): Promise<AutoRAGPiInteractiveRuntime>;
380
+ private runInteractivePiQuery;
367
381
  abort(): void;
368
382
  /**
369
383
  * Periodically re-runs the incremental {@link refresh} so parsed mirrors and
@@ -0,0 +1,35 @@
1
+ import type { AgentMessage, AgentTool } from "@earendil-works/pi-agent-core";
2
+ import type { Api, Model } from "@earendil-works/pi-ai";
3
+ import { type AgentSession, type AgentSessionRuntime, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+ export declare const PI_BUILTIN_TOOL_NAMES: readonly ["read", "bash", "edit", "write", "grep", "find", "ls"];
5
+ export interface AutoRAGPiSessionOptions {
6
+ readonly cwd: string;
7
+ readonly agentDir?: string;
8
+ readonly sessionDir?: string;
9
+ readonly sessionPath?: string;
10
+ readonly persistSession?: boolean;
11
+ readonly model: Model<Api>;
12
+ readonly apiKey?: string;
13
+ readonly providerApiKeys?: Readonly<Record<string, string>>;
14
+ readonly getSystemPrompt: () => string;
15
+ readonly customTools: readonly AgentTool[];
16
+ readonly remoteSession?: boolean;
17
+ readonly contextTransform?: (messages: AgentMessage[]) => Promise<AgentMessage[]>;
18
+ }
19
+ export interface AutoRAGPiInteractiveRuntimeOptions extends Omit<AutoRAGPiSessionOptions, "model"> {
20
+ readonly model?: Model<Api>;
21
+ readonly inactiveToolNames?: readonly string[];
22
+ readonly onQuery: (query: string, pi: ExtensionAPI) => void | Promise<void>;
23
+ }
24
+ export interface AutoRAGPiSession {
25
+ readonly session: AgentSession;
26
+ readonly baseToolNames: readonly string[];
27
+ readonly sessionFile: string | undefined;
28
+ }
29
+ /** Creates a pi session with AutoRAG's tools and prompt. */
30
+ export declare function createAutoRAGPiSession(options: AutoRAGPiSessionOptions): Promise<AutoRAGPiSession>;
31
+ export interface AutoRAGPiInteractiveRuntime {
32
+ readonly runtime: AgentSessionRuntime;
33
+ readonly dispose: () => Promise<void>;
34
+ }
35
+ export declare function createAutoRAGPiInteractiveRuntime(options: AutoRAGPiInteractiveRuntimeOptions): Promise<AutoRAGPiInteractiveRuntime>;
@@ -1,6 +1,5 @@
1
1
  import type { Api, Model } from "@earendil-works/pi-ai";
2
- import type { LoadLocalAutoRAGModelOptions } from "../../agent/local-model.js";
3
- import { type CliConfig, type ResolvedAgentModelDetailed } from "../config.js";
2
+ import { type CliConfig, type ResolveAgentModelOptions, type ResolvedAgentModelDetailed } from "../config.js";
4
3
  import type { CommandContext } from "./types.js";
5
4
  export type HealthCategory = "config" | "model_resolution" | "auth_missing" | "provider_unreachable" | "completion_failed" | "timeout" | "ok";
6
5
  export interface HealthCoverage {
@@ -83,7 +82,7 @@ export interface HealthDeps {
83
82
  cwd?: string;
84
83
  env?: NodeJS.ProcessEnv;
85
84
  }) => CliConfig;
86
- modelResolver?: (config: CliConfig, localOptions?: LoadLocalAutoRAGModelOptions) => ResolvedHealthModel;
85
+ modelResolver?: (config: CliConfig, options?: ResolveAgentModelOptions) => ResolvedHealthModel | Promise<ResolvedHealthModel>;
87
86
  probe?: (input: ProbeInput, signal: AbortSignal) => Promise<ProbeOutput>;
88
87
  now?: () => number;
89
88
  }
@@ -1,5 +1,24 @@
1
1
  import type { ProfileId } from "../../embedding-runtime/types.js";
2
2
  import type { CommandContext } from "./types.js";
3
+ /**
4
+ * One chat model discovered through the pi model runtime (built-in catalog plus
5
+ * `models.json`, custom, and extension providers). `available` reports whether
6
+ * the provider has complete auth configuration, including stored `auth.json`
7
+ * credentials (api-key or OAuth).
8
+ */
9
+ export interface ModelCatalogEntry {
10
+ readonly provider: string;
11
+ readonly id: string;
12
+ readonly name: string;
13
+ readonly api: string;
14
+ readonly available: boolean;
15
+ }
16
+ export interface ModelCatalogOptions {
17
+ readonly provider?: string;
18
+ /** Only list models whose provider has complete auth configuration. */
19
+ readonly available?: boolean;
20
+ readonly agentDir?: string;
21
+ }
3
22
  export interface ModelsCommandDeps {
4
23
  prefetchModel?: (profileId?: ProfileId) => Promise<{
5
24
  profileId: ProfileId;
@@ -14,5 +33,6 @@ export interface ModelsCommandDeps {
14
33
  path: string;
15
34
  hash: string;
16
35
  }>;
36
+ listModels?: (options: ModelCatalogOptions) => Promise<readonly ModelCatalogEntry[]>;
17
37
  }
18
38
  export declare function runModels(ctx: CommandContext, deps?: ModelsCommandDeps): Promise<number>;
@@ -1,5 +1,5 @@
1
1
  import { AutoRAGAgent, type AutoRAGAgentOptions } from "../../agent/agent.js";
2
- import { type CliConfig, type ResolvedAgentModel } from "../config.js";
2
+ import { type CliConfig, type ResolveAgentModelOptions, type ResolvedAgentModel } from "../config.js";
3
3
  import type { CommandContext } from "./types.js";
4
4
  /**
5
5
  * A recoverable health hint surfaced when `autorag search` fails for a reason
@@ -25,7 +25,7 @@ export declare function classifySearchHealthHint(error: unknown): SearchHealthHi
25
25
  */
26
26
  export interface SearchDeps {
27
27
  agentFactory?: (opts: AutoRAGAgentOptions) => Pick<AutoRAGAgent, "searchDocumentsStream">;
28
- modelResolver?: (config: CliConfig) => ResolvedAgentModel;
28
+ modelResolver?: (config: CliConfig, options?: ResolveAgentModelOptions) => ResolvedAgentModel | Promise<ResolvedAgentModel>;
29
29
  /**
30
30
  * Stops the on-demand embedding gateway so the process can exit. Without
31
31
  * this the semantic MinSync path's loopback gateway keeps the event loop
@@ -1,14 +1,14 @@
1
1
  import type { InjectionClassifierModel } from "../../p2p/injection-classifier.js";
2
2
  import { type SimplexPeerServer, startSimplexPeerServer, syncSimplexPeers } from "../../p2p/simplex-server.js";
3
3
  import { type SimplexTransport, type StartSimplexOptions } from "../../p2p/simplex-transport.js";
4
- import { type ResolvedAgentModel, resolveAgentModel } from "../config.js";
4
+ import { type CliConfig, type ResolveAgentModelOptions, type ResolvedAgentModel } from "../config.js";
5
5
  import type { CommandContext } from "./types.js";
6
6
  export interface ServeCommandDeps {
7
7
  readonly startSimplexPeerServer?: typeof startSimplexPeerServer;
8
8
  readonly startSimplexChat?: (options: StartSimplexOptions) => Promise<SimplexTransport>;
9
9
  readonly syncSimplexPeers?: typeof syncSimplexPeers;
10
10
  readonly waitUntilStopped?: (server: SimplexPeerServer) => Promise<void>;
11
- readonly modelResolver?: typeof resolveAgentModel;
11
+ readonly modelResolver?: (config: CliConfig, options?: ResolveAgentModelOptions) => ResolvedAgentModel | Promise<ResolvedAgentModel>;
12
12
  }
13
13
  export declare function createInjectionClassifierModel(resolved: ResolvedAgentModel): InjectionClassifierModel;
14
14
  /**
@@ -1,36 +1,13 @@
1
- import type { AgentEvent } from "@earendil-works/pi-agent-core";
2
- import { AutoRAGAgent, type AutoRAGAgentOptions } from "../../agent/agent.js";
3
- import { type CliConfig, type ResolvedAgentModel } from "../config.js";
4
- import { type TuiSessionRecord, type TuiSessionStore } from "../tui-session-store.js";
5
1
  import type { CommandContext } from "./types.js";
6
- export { parseSlashCommand } from "../tui-commands.js";
7
- export interface TuiDriver {
8
- submissions: string[];
9
- rendered: string[];
10
- started: boolean;
11
- stopped: boolean;
12
- onSubmit?: (text: string) => void | Promise<void>;
13
- onExit?: () => void;
14
- onEvent?: (event: AgentEvent) => void;
15
- onInput?: (data: string) => void;
16
- }
17
- export interface TuiPresenter {
18
- handle(event: AgentEvent): void;
19
- lines(): readonly string[];
20
- working(): boolean;
21
- setWorking(active: boolean): void;
22
- beginRun(): void;
23
- interrupt(): void;
24
- status(): string;
25
- reset(): void;
26
- }
27
- type TuiAgent = Pick<AutoRAGAgent, "searchDocumentsStream"> & Partial<Pick<AutoRAGAgent, "subscribe" | "abort">>;
28
- export interface TuiDeps {
29
- agentFactory?: (opts?: Partial<AutoRAGAgentOptions>) => TuiAgent;
30
- modelResolver?: (config: CliConfig) => ResolvedAgentModel;
31
- tuiFactory?: (ctx: CommandContext) => TuiDriver;
32
- sessionStore?: TuiSessionStore;
33
- }
34
- export declare function createTuiPresenter(): TuiPresenter;
35
- export declare function renderTuiSessionView(session: TuiSessionRecord | undefined, input: string): string;
36
- export declare function runTui(ctx: CommandContext, deps?: TuiDeps): Promise<number>;
2
+ /**
3
+ * Run `autorag tui`: Pi's interactive mode over the AutoRAG librarian.
4
+ *
5
+ * Pi owns the terminal UI, `read`/`bash`/`edit`/`write`/`grep`/`find`/`ls`
6
+ * tools, provider credentials/OAuth, model selection, session persistence and
7
+ * resume/fork/compaction, settings, and extension loading. AutoRAG registers
8
+ * its domain tools and streams progress, preliminary answers, and final results
9
+ * into the same session through the agent's interactive runtime. The native
10
+ * `/login`, `/model`, `/resume`, `/new`, `/tree`, `/compact`, and `/settings`
11
+ * commands are therefore always available.
12
+ */
13
+ export declare function runTui(ctx: CommandContext): Promise<number>;
@@ -1,4 +1,5 @@
1
1
  import type { Api, Model } from "@earendil-works/pi-ai";
2
+ import { ModelRuntime } from "@earendil-works/pi-coding-agent";
2
3
  import type { AutoRAGAgentOptions, AutoRAGRetrievalLimits } from "../agent/agent.js";
3
4
  import { type LoadLocalAutoRAGModelOptions } from "../agent/local-model.js";
4
5
  import type { DatasourceAccessContextOptions } from "../datasource/access-context.js";
@@ -207,7 +208,18 @@ export declare function resolveConfigReadOnly(input: ResolveConfigInput): CliCon
207
208
  /** Normalize and validate the `rerank` config section, filling in defaults. */
208
209
  export declare function normalizeRerankConfig(raw: unknown, path: string): RerankConfig | false;
209
210
  export declare function buildAgentOptions(config: CliConfig): Omit<AutoRAGAgentOptions, "model">;
210
- export declare function resolveModel(config: CliConfig): Model<Api>;
211
+ /**
212
+ * Extra resolution inputs beyond the local codex-runtime options. `agentDir`
213
+ * points at the pi agent home (`~/.pi/agent` by default) that owns
214
+ * `auth.json`, `models.json`, and `settings.json`.
215
+ */
216
+ export interface ResolveAgentModelOptions extends LoadLocalAutoRAGModelOptions {
217
+ readonly agentDir?: string;
218
+ readonly cwd?: string;
219
+ /** Pre-built pi model runtime, for callers that already own one (and tests). */
220
+ readonly runtime?: ModelRuntime;
221
+ }
222
+ export declare function resolveModel(config: CliConfig, options?: ResolveAgentModelOptions): Promise<Model<Api>>;
211
223
  export interface ResolvedAgentModel {
212
224
  readonly model: Model<Api>;
213
225
  readonly apiKey?: string;
@@ -216,7 +228,7 @@ export interface ResolvedAgentModel {
216
228
  export type AgentModelResolutionSource = "config" | "flags" | "env" | "local_runtime" | "catalog" | "configured_alias" | "mixed";
217
229
  export interface AgentModelAuth {
218
230
  readonly present: boolean;
219
- readonly source: "env" | "local_runtime" | "catalog" | "none" | "unknown";
231
+ readonly source: "env" | "local_runtime" | "pi_auth" | "catalog" | "none" | "unknown";
220
232
  readonly envName?: string;
221
233
  }
222
234
  export interface ResolvedAgentModelRole {
@@ -240,8 +252,8 @@ export interface ResolvedAgentModelDetailed {
240
252
  readonly providerApiKeys?: Readonly<Record<string, string>>;
241
253
  readonly role: ResolvedAgentModelRole;
242
254
  }
243
- export declare function resolveAgentModel(config: CliConfig, localOptions?: LoadLocalAutoRAGModelOptions): ResolvedAgentModel;
244
- export declare function resolveAgentModelDetailed(config: CliConfig, localOptions?: LoadLocalAutoRAGModelOptions): ResolvedAgentModelDetailed;
255
+ export declare function resolveAgentModel(config: CliConfig, options?: ResolveAgentModelOptions): Promise<ResolvedAgentModel>;
256
+ export declare function resolveAgentModelDetailed(config: CliConfig, options?: ResolveAgentModelOptions): Promise<ResolvedAgentModelDetailed>;
245
257
  export declare function readRawConfigObject(path: string): Record<string, unknown>;
246
258
  /** Atomically replace a config file, preserving the caller's JSON object. */
247
259
  export declare function writeConfigObject(path: string, config: unknown): void;