@autorag/librarian 2.11.0 → 2.13.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.
Files changed (87) hide show
  1. package/NOTICE +6 -0
  2. package/README.md +14 -6
  3. package/dist/agent/agent.d.ts +136 -33
  4. package/dist/agent/answer-citations.d.ts +34 -2
  5. package/dist/agent/answer-guidelines.d.ts +20 -3
  6. package/dist/agent/ask-user.d.ts +8 -0
  7. package/dist/agent/automation-tool.d.ts +45 -0
  8. package/dist/agent/citation-links.d.ts +23 -0
  9. package/dist/agent/citation-numbers.d.ts +68 -0
  10. package/dist/agent/citation-relevance.d.ts +37 -0
  11. package/dist/agent/conversation-queries.d.ts +31 -0
  12. package/dist/agent/convert-tool.d.ts +28 -0
  13. package/dist/agent/current-date.d.ts +10 -0
  14. package/dist/agent/datasource-skill.d.ts +2 -2
  15. package/dist/agent/environment-prompt.d.ts +20 -0
  16. package/dist/agent/evidence-ledger.d.ts +4 -2
  17. package/dist/agent/evidence-persistence.d.ts +17 -11
  18. package/dist/agent/index.d.ts +1 -0
  19. package/dist/agent/intent-tracing.d.ts +33 -0
  20. package/dist/agent/location-claims.d.ts +14 -0
  21. package/dist/agent/packaged-skill.d.ts +19 -0
  22. package/dist/agent/permission-gate.d.ts +78 -0
  23. package/dist/agent/permission-judgment.d.ts +72 -0
  24. package/dist/agent/permission-paths.d.ts +23 -0
  25. package/dist/agent/query-routing.d.ts +78 -27
  26. package/dist/agent/results.d.ts +10 -2
  27. package/dist/agent/search-documents.d.ts +6 -1
  28. package/dist/agent/self-config.d.ts +6 -4
  29. package/dist/agent/skill-invocation.d.ts +17 -0
  30. package/dist/agent/user-requests.d.ts +52 -0
  31. package/dist/automation/config.d.ts +48 -0
  32. package/dist/automation/daemon.d.ts +31 -0
  33. package/dist/automation/dispatch.d.ts +13 -0
  34. package/dist/automation/run-agent.d.ts +22 -0
  35. package/dist/automation/run.d.ts +32 -0
  36. package/dist/automation/service.d.ts +61 -0
  37. package/dist/cli/commands/automate.d.ts +2 -0
  38. package/dist/cli/commands/evidence.d.ts +2 -0
  39. package/dist/cli/config.d.ts +21 -0
  40. package/dist/cli/index.d.ts +1 -1
  41. package/dist/cli/index.js +19531 -14871
  42. package/dist/cli/open-target.d.ts +9 -0
  43. package/dist/cli/setup.d.ts +14 -0
  44. package/dist/convert/cli.d.ts +77 -0
  45. package/dist/convert/index.d.ts +4 -0
  46. package/dist/convert/installer.d.ts +84 -0
  47. package/dist/convert/matrix.d.ts +27 -0
  48. package/dist/convert/relate.d.ts +30 -0
  49. package/dist/core.js +32479 -28141
  50. package/dist/datasource/connector-timeouts.d.ts +6 -2
  51. package/dist/datasource/crawler-skill.d.ts +1 -0
  52. package/dist/datasource/crawler-types.d.ts +1 -1
  53. package/dist/datasource/index.d.ts +1 -1
  54. package/dist/datasource/sidecar/methods.d.ts +8 -1
  55. package/dist/datasource/skills/clawgallery/skill.d.ts +4 -0
  56. package/dist/datasource/skills/discrawl/skill.d.ts +5 -0
  57. package/dist/datasource/skills/factory.d.ts +5 -1
  58. package/dist/datasource/skills/lazykatok/index.d.ts +1 -1
  59. package/dist/datasource/skills/lazykatok/methods.d.ts +5 -5
  60. package/dist/datasource/skills/lazykatok/skill.d.ts +1 -0
  61. package/dist/datasource/skills/lazykatok/types.d.ts +2 -2
  62. package/dist/datasource/skills/mailcrawl/skill.d.ts +1 -0
  63. package/dist/datasource/skills/mailcrawl/types.d.ts +1 -1
  64. package/dist/dupey/cli.d.ts +18 -0
  65. package/dist/index.d.ts +1 -0
  66. package/dist/index.js +32558 -28145
  67. package/dist/mcp/index.js +32651 -28263
  68. package/dist/memory/memory.d.ts +4 -1
  69. package/dist/minsync/installer.d.ts +1 -1
  70. package/dist/mirror/atomic-write.d.ts +16 -1
  71. package/dist/mirror/sync.d.ts +2 -0
  72. package/dist/profiles/agent-factory.d.ts +60 -0
  73. package/dist/profiles/automation-profiles.d.ts +25 -0
  74. package/dist/profiles/loop-guard.d.ts +23 -0
  75. package/dist/profiles/retrieval-tools.d.ts +24 -0
  76. package/dist/profiles/session-model.d.ts +69 -0
  77. package/dist/profiles.d.ts +13 -0
  78. package/dist/profiles.js +35246 -0
  79. package/dist/retrieval/chunk-location.d.ts +28 -0
  80. package/dist/retrieval/fallback.d.ts +24 -0
  81. package/dist/retrieval/index.d.ts +1 -0
  82. package/dist/retrieval/rerank.d.ts +6 -0
  83. package/dist/retrieval/types.d.ts +16 -0
  84. package/internal-skills/organize/SKILL.md +43 -0
  85. package/package.json +9 -2
  86. package/skills/autorag/SKILL.md +89 -7
  87. package/skills/autorag-setup/SKILL.md +10 -4
@@ -6,7 +6,10 @@ export interface EvidenceContext {
6
6
  readonly documentType?: string;
7
7
  readonly documentArea?: string;
8
8
  readonly evidenceType?: string;
9
- readonly evidenceLocation?: string;
9
+ /** Last line of the chunk in its parsed document; the first line is the ref's `lineNumber`. */
10
+ readonly lineEnd?: number;
11
+ /** Article or heading the chunk sits in. */
12
+ readonly section?: string;
10
13
  readonly confidence?: number;
11
14
  }
12
15
  export interface EvidenceChunkRecord extends NormalizedEvidenceRef, EvidenceContext {
@@ -1,4 +1,4 @@
1
- export declare const MINSYNC_VERSION = "0.4.11";
1
+ export declare const MINSYNC_VERSION = "0.4.12";
2
2
  export declare const MINSYNC_CARGO_INSTALL_TIMEOUT_MS: number;
3
3
  export interface MinSyncReleaseAsset {
4
4
  readonly name: string;
@@ -1,6 +1,21 @@
1
+ export interface RenameRetryOptions {
2
+ /** Retries after the first attempt. Default 5, so six attempts in total. */
3
+ readonly retries?: number;
4
+ /** First wait in milliseconds; it doubles each retry (25/50/100/200/400 by default). */
5
+ readonly backoffMs?: number;
6
+ }
7
+ /** True for a rename error that a short wait can clear (`EPERM`, `EACCES`, `EBUSY`). */
8
+ export declare function isRetryableRenameError(error: unknown): boolean;
9
+ /**
10
+ * `renameSync` that waits and retries while the destination is transiently held (see
11
+ * {@link RETRYABLE_RENAME_CODES}). Any other error, and the last retryable one, is rethrown unchanged.
12
+ */
13
+ export declare function renameWithRetry(from: string, to: string, options?: RenameRetryOptions): void;
1
14
  /**
2
15
  * Write `content` to `path` through a sibling temp file and an atomic rename.
3
- * On any failure the temp file is removed before the error is rethrown, so a full
16
+ * A destination that stays held through every rename retry is overwritten in place instead: replacing by
17
+ * rename needs delete rights on the destination, writing to an existing file does not.
18
+ * On any other failure the temp file is removed before the error is rethrown, so a full
4
19
  * disk or an I/O error never leaves `*.tmp` orphans in the mirror.
5
20
  */
6
21
  export declare function writeFileAtomic(path: string, content: string): void;
@@ -2,6 +2,8 @@ import { type DefaultParserRegistryOptions } from "../parser/defaults.js";
2
2
  import type { ParserRegistry } from "../parser/registry.js";
3
3
  /** Refuse to fully load/parse sources larger than this. Keeps Node heap stable on home folders. */
4
4
  export declare const DEFAULT_MAX_SOURCE_BYTES: number;
5
+ /** Persist partial mirror progress this often so an OOM mid-run still restarts incrementally. */
6
+ export declare const MIRROR_CHECKPOINT_EVERY = 25;
5
7
  /** A refresh may delete at most this share of the indexed documents (above {@link MASS_DELETE_FLOOR}). */
6
8
  export declare const DEFAULT_MAX_DELETE_RATIO = 0.3;
7
9
  /** Directory entries examined per search root before the walk stops. */
@@ -0,0 +1,60 @@
1
+ import type { Api, Model } from "@earendil-works/pi-ai";
2
+ import { type AgentSession, type CreateAgentSessionOptions, type ToolDefinition } from "@earendil-works/pi-coding-agent";
3
+ /**
4
+ * Plain pi agent sessions for helper features, one per {@link AgentProfile}.
5
+ *
6
+ * The AutoRAG agent (`AutoRAGAgent`) answers searches and is not touched here.
7
+ * Every other helper agent (smart indexing in the desktop app, file-triggered
8
+ * automations, and whatever follows) is a vanilla pi session: its own system
9
+ * prompt, its own tool set, and its own choice of what pi would otherwise load
10
+ * on its own (AGENTS.md, skills, extensions). What the profiles share is the
11
+ * account: the model the AutoRAG agent runs on, and the credential store under
12
+ * the same agent dir (`auth.json`, `models.json`), so a sign-in or key change
13
+ * reaches them without a second login.
14
+ *
15
+ * A session lives in memory and is gone with `dispose()`: nothing is written
16
+ * under the agent dir or the working directory, and the user's own pi settings
17
+ * (default tools, themes, ...) never apply. A profile session never reads or
18
+ * writes AutoRAG's retrieval memory.
19
+ */
20
+ /** How hard the model thinks; the same levels pi's session takes. */
21
+ export type ProfileThinking = NonNullable<CreateAgentSessionOptions["thinkingLevel"]>;
22
+ /** What pi loads on its own besides the profile's prompt and tools. Everything is off unless a profile turns it on. */
23
+ export interface ProfileContext {
24
+ /** AGENTS.md style instruction files from the agent dir and the working directory. */
25
+ readonly projectFiles?: boolean;
26
+ readonly skills?: boolean;
27
+ /** Extensions from the agent dir and the working directory. An extension's tools still have to be named in {@link AgentProfile.tools}. */
28
+ readonly extensions?: boolean;
29
+ }
30
+ export interface AgentProfile {
31
+ readonly id: string;
32
+ readonly systemPrompt: string;
33
+ /**
34
+ * Names of the pi tools the model may call (`read`, `ls`, `find`, `grep`, and
35
+ * `bash`/`edit`/`write` for a profile that may change things; an extension's
36
+ * tool when {@link ProfileContext.extensions} is on). Tools in
37
+ * {@link customTools} are always allowed and need no entry here.
38
+ */
39
+ readonly tools: readonly string[];
40
+ readonly customTools?: readonly ToolDefinition[];
41
+ readonly thinking: ProfileThinking;
42
+ readonly context?: ProfileContext;
43
+ }
44
+ /** The model a session runs on and the credentials resolved for it; see `resolveSessionModel`. */
45
+ export interface ProfileModel {
46
+ readonly model: Model<Api>;
47
+ readonly apiKey?: string;
48
+ readonly providerApiKeys?: Readonly<Record<string, string>>;
49
+ }
50
+ export interface ProfileSessionOptions {
51
+ readonly profile: AgentProfile;
52
+ /** Working directory of the session: relative paths and project context resolve against it. */
53
+ readonly cwd: string;
54
+ /** pi's agent dir; `auth.json` and `models.json` in it are the shared credential store. */
55
+ readonly agentDir: string;
56
+ readonly env: NodeJS.ProcessEnv;
57
+ readonly model: ProfileModel;
58
+ }
59
+ /** Builds a ready session for `profile`; the caller prompts it and disposes it. */
60
+ export declare function createProfileSession(options: ProfileSessionOptions): Promise<AgentSession>;
@@ -0,0 +1,25 @@
1
+ import type { AgentProfile } from "./agent-factory.js";
2
+ /**
3
+ * Agent profiles an automation rule can name (`"agent": { "profile": "<id>" }`).
4
+ *
5
+ * A rule only carries the id, never a prompt or a tool list: what an agent may
6
+ * do is decided here, in code, so a rules file (which the librarian agent can
7
+ * itself edit) cannot grant `bash` or `write` to an agent that was meant to read.
8
+ * The runner appends the mandatory loop guard (`loop-guard.ts`) to every
9
+ * profile's prompt, writing profiles included.
10
+ */
11
+ /** What a profile builder is told about the run it serves. */
12
+ export interface AutomationProfileInput {
13
+ /** The rule's own instruction for this run; a profile folds it into its prompt. */
14
+ readonly task: string;
15
+ }
16
+ export interface AutomationProfileDefinition {
17
+ readonly id: string;
18
+ readonly description: string;
19
+ /** True when the profile may change files (offers `bash`, `edit` or `write`). */
20
+ readonly writes: boolean;
21
+ build(input: AutomationProfileInput): AgentProfile;
22
+ }
23
+ export declare function registerAutomationProfile(definition: AutomationProfileDefinition): void;
24
+ export declare function getAutomationProfile(id: string): AutomationProfileDefinition | undefined;
25
+ export declare function listAutomationProfiles(): readonly AutomationProfileDefinition[];
@@ -0,0 +1,23 @@
1
+ /** The part of an automation rule the loop guard describes to the agent. */
2
+ export interface LoopGuardRule {
3
+ readonly id: string;
4
+ readonly paths: readonly string[];
5
+ readonly events: readonly string[];
6
+ readonly include: readonly string[];
7
+ readonly exclude: readonly string[];
8
+ }
9
+ /**
10
+ * File extensions a rule's include globs name (`**\/*.pdf`, `*.{md,txt}`), lower-case with the dot.
11
+ * Empty when some glob names no extension (`**`, `docs/**`): the rule then fires on every file type.
12
+ */
13
+ export declare function includedExtensions(include: readonly string[]): readonly string[];
14
+ /**
15
+ * The system-prompt section every agent run started by an automation carries.
16
+ *
17
+ * The automation runner appends it to the profile's own prompt; a profile cannot
18
+ * leave it out. An agent that may write files could otherwise change a file the
19
+ * rule watches, which fires the rule again and starts another run of the agent:
20
+ * an endless loop. The section names the rule's folders, file types, and events,
21
+ * and forbids every change that would fire the rule.
22
+ */
23
+ export declare function loopGuardPrompt(rule: LoopGuardRule): string;
@@ -0,0 +1,24 @@
1
+ import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
2
+ import { type CliConfig } from "../cli/config.js";
3
+ /** Which of AutoRAG's retrieval tools a profile session is offered, on top of its own tools. */
4
+ export interface RetrievalToolOptions {
5
+ /** `search_all_documents`: fan-out across every configured retrieval method. */
6
+ readonly searchAll?: boolean;
7
+ /** Datasource ids to offer one `search_datasource_<id>` tool for each. */
8
+ readonly datasources?: readonly string[];
9
+ }
10
+ export interface RetrievalToolkit {
11
+ readonly tools: readonly ToolDefinition[];
12
+ dispose(): Promise<void>;
13
+ }
14
+ export declare function hasRetrievalTools(options: RetrievalToolOptions | undefined): boolean;
15
+ /**
16
+ * Retrieval tools for a profile session, backed by the configured indexes.
17
+ *
18
+ * Retrieval memory is never connected: the backing agent is pointed at a
19
+ * throwaway memory file with the memory embedder off, so nothing the profile
20
+ * searches is read from or recorded into the user's real `memory.json`. Only
21
+ * the search tools are handed out; the backing agent's other surfaces (web,
22
+ * Everything, FSearch, Jev, duplicate scan) stay off.
23
+ */
24
+ export declare function createRetrievalToolkit(config: CliConfig, options: RetrievalToolOptions): Promise<RetrievalToolkit>;
@@ -0,0 +1,69 @@
1
+ import { ModelRuntime } from "@earendil-works/pi-coding-agent";
2
+ import { type CliConfig } from "../cli/config.js";
3
+ import type { ProfileModel } from "./agent-factory.js";
4
+ /**
5
+ * Why the hosted plan's key must not ride along as a session API key.
6
+ *
7
+ * The `dazzi` provider is OAuth-only: its credential is the `/login` entry in
8
+ * Pi's `auth.json`. Handing the resolved key to `ModelRuntime.setRuntimeApiKey`
9
+ * replaces that OAuth credential with an `api_key` one, and an OAuth-only
10
+ * provider accepts no API key, so the session stops with "No API key found for
11
+ * dazzi" even though the user is signed in. That only happens when the
12
+ * session's runtime already lists the model (the persisted catalog snapshot the
13
+ * sign-in writes); a model the runtime does not list is registered from the key
14
+ * instead and works.
15
+ *
16
+ * So for a plan model the runtime lists, the key is dropped and Pi resolves the
17
+ * stored OAuth credential itself. A model it does not list keeps the key.
18
+ */
19
+ /** The slice of Pi's `ModelRuntime` this module reads. */
20
+ export interface PlanRuntime {
21
+ getModel(provider: string, id: string): unknown;
22
+ refresh(options: {
23
+ readonly allowNetwork: boolean;
24
+ readonly providers: readonly string[];
25
+ readonly force: boolean;
26
+ }): Promise<unknown>;
27
+ }
28
+ /** A resolved agent model with the credentials a session receives. */
29
+ export interface SessionModelAuth {
30
+ readonly model: {
31
+ readonly provider: string;
32
+ readonly id: string;
33
+ };
34
+ readonly apiKey?: string;
35
+ readonly providerApiKeys?: Readonly<Record<string, string>>;
36
+ }
37
+ /** Open Pi's runtime on `agentDir` with the plan provider registered, offline until asked. */
38
+ export declare function openPlanRuntime(agentDir: string, env: NodeJS.ProcessEnv): Promise<ModelRuntime>;
39
+ /**
40
+ * Drop the plan's API key from a resolved model when Pi can authenticate it
41
+ * from the stored OAuth credential. Any other model, or a plan model Pi cannot
42
+ * list (offline, unknown id), is returned unchanged.
43
+ */
44
+ export declare function preferPlanOAuth<T extends SessionModelAuth>(resolved: T, openRuntime: () => Promise<PlanRuntime>): Promise<T>;
45
+ /**
46
+ * The Dazzi `/v1/models` catalog omits `thinkingLevelMap` for its OpenRouter-backed
47
+ * model ids (e.g. `z-ai/glm-5.3-flash`, `anthropic/claude-haiku-5.5`). Without it,
48
+ * Pi's `clampThinkingLevel(model, "off")` keeps `"off"` and `openai-responses`
49
+ * sends `reasoning: { effort: "none" }`, which mandatory-reasoning endpoints
50
+ * reject with HTTP 400 (`Reasoning is mandatory for this endpoint and cannot be
51
+ * disabled`). Inherit the upstream OpenRouter `thinkingLevelMap` when present so
52
+ * `"off"` clamps to `"low"` for those models.
53
+ */
54
+ export declare function applyDazziThinkingLevels<T extends {
55
+ readonly provider: string;
56
+ readonly id: string;
57
+ readonly thinkingLevelMap?: unknown;
58
+ }>(model: T): T;
59
+ /**
60
+ * The model every profile agent runs on: the one the shared AutoRAG config names
61
+ * for the AutoRAG agent, with its credentials. AI Search and the profile agents
62
+ * both resolve it, so there is one answer to "which model, which key".
63
+ *
64
+ * Credentials are read fresh on every call, so a login or key change reaches the
65
+ * next session without a restart.
66
+ */
67
+ export declare function resolveSessionModel(config: CliConfig, env: NodeJS.ProcessEnv, cwd: string, agentDir: string): Promise<ProfileModel>;
68
+ /** {@link resolveSessionModel} for the config file the app and the CLI share. */
69
+ export declare function resolveConfiguredSessionModel(env: NodeJS.ProcessEnv, cwd: string, agentDir: string): Promise<ProfileModel>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `@autorag/librarian/profiles`: agent profiles for helper features.
3
+ *
4
+ * A profile is a system prompt, a tool set, and a thinking level; the factory turns
5
+ * one into a plain in-memory pi session on the AutoRAG agent's own model and
6
+ * credentials. The desktop app's smart indexing and file-triggered automations
7
+ * are built on it. No profile session touches AutoRAG's retrieval memory.
8
+ */
9
+ export { type AgentProfile, createProfileSession, type ProfileContext, type ProfileModel, type ProfileSessionOptions, type ProfileThinking, } from "./profiles/agent-factory.js";
10
+ export { type AutomationProfileDefinition, type AutomationProfileInput, getAutomationProfile, listAutomationProfiles, registerAutomationProfile, } from "./profiles/automation-profiles.js";
11
+ export { includedExtensions, type LoopGuardRule, loopGuardPrompt } from "./profiles/loop-guard.js";
12
+ export { createRetrievalToolkit, hasRetrievalTools, type RetrievalToolkit, type RetrievalToolOptions, } from "./profiles/retrieval-tools.js";
13
+ export { applyDazziThinkingLevels, openPlanRuntime, type PlanRuntime, preferPlanOAuth, resolveConfiguredSessionModel, resolveSessionModel, type SessionModelAuth, } from "./profiles/session-model.js";