@autorag/librarian 2.7.0 → 2.9.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 (98) hide show
  1. package/NOTICE +10 -4
  2. package/README.md +122 -38
  3. package/dist/agent/agent.d.ts +210 -53
  4. package/dist/agent/answer-guidelines.d.ts +19 -0
  5. package/dist/agent/citations.d.ts +43 -0
  6. package/dist/agent/datasource-skill.d.ts +30 -16
  7. package/dist/agent/emit-results-tool.d.ts +37 -2
  8. package/dist/agent/evidence-judgment.d.ts +58 -0
  9. package/dist/agent/evidence-ledger.d.ts +59 -0
  10. package/dist/agent/evidence-origins.d.ts +49 -0
  11. package/dist/agent/fast-answer-tool.d.ts +16 -6
  12. package/dist/agent/index.d.ts +2 -1
  13. package/dist/agent/jev-extension.d.ts +68 -0
  14. package/dist/agent/jikji-find-tool.d.ts +2 -1
  15. package/dist/agent/pi-session.d.ts +28 -1
  16. package/dist/agent/query-decomposition.d.ts +25 -0
  17. package/dist/agent/query-peer-tool.d.ts +3 -0
  18. package/dist/agent/query-routing.d.ts +115 -0
  19. package/dist/agent/search-all-tool.d.ts +5 -5
  20. package/dist/agent/search-documents.d.ts +3 -11
  21. package/dist/agent/search-minsync-tool.d.ts +5 -5
  22. package/dist/agent/search-single-datasource-tool.d.ts +9 -8
  23. package/dist/agent/self-config.d.ts +40 -0
  24. package/dist/agent/system-prompt.d.ts +3 -3
  25. package/dist/agent/web-fetch-tool.d.ts +2 -1
  26. package/dist/agent/web-search-tool.d.ts +2 -1
  27. package/dist/cli/commands/evidence.d.ts +22 -0
  28. package/dist/cli/commands/init.d.ts +2 -1
  29. package/dist/cli/commands/memory.d.ts +1 -1
  30. package/dist/cli/commands/report.d.ts +1 -1
  31. package/dist/cli/commands/update-check.d.ts +8 -0
  32. package/dist/cli/config.d.ts +80 -7
  33. package/dist/cli/index.d.ts +1 -1
  34. package/dist/cli/index.js +3844 -2291
  35. package/dist/cli/output.d.ts +2 -6
  36. package/dist/cli/update-check.d.ts +34 -0
  37. package/dist/cli/version.d.ts +5 -0
  38. package/dist/config/home.d.ts +6 -0
  39. package/dist/core.d.ts +30 -6
  40. package/dist/core.js +7742 -6225
  41. package/dist/datasource/chunk-store.d.ts +2 -6
  42. package/dist/datasource/connector-skill.d.ts +2 -3
  43. package/dist/datasource/index.d.ts +2 -4
  44. package/dist/datasource/registry.d.ts +11 -13
  45. package/dist/datasource/scope.d.ts +19 -0
  46. package/dist/datasource/skills/github-gist/index.d.ts +1 -1
  47. package/dist/datasource/skills/github-gist/semantic.d.ts +3 -44
  48. package/dist/datasource/skills/github-gist/skill.d.ts +3 -3
  49. package/dist/datasource/types.d.ts +14 -28
  50. package/dist/embedding-runtime/gateway-embedder.d.ts +41 -0
  51. package/dist/everything/bundle.d.ts +15 -3
  52. package/dist/everything/client.d.ts +22 -5
  53. package/dist/everything/index.d.ts +1 -1
  54. package/dist/filesystem/name-search.d.ts +57 -0
  55. package/dist/fsearch/client.d.ts +7 -1
  56. package/dist/index.d.ts +2 -1
  57. package/dist/index.js +9139 -6376
  58. package/dist/jikji/client.d.ts +6 -1
  59. package/dist/language.d.ts +2 -1
  60. package/dist/mcp/index.d.ts +2 -0
  61. package/dist/mcp/index.js +30542 -0
  62. package/dist/mcp/server.d.ts +9 -0
  63. package/dist/memory/check-memory-tool.d.ts +8 -4
  64. package/dist/memory/context.d.ts +51 -0
  65. package/dist/memory/index.d.ts +8 -1
  66. package/dist/memory/judged-evidence.d.ts +32 -0
  67. package/dist/memory/memory.d.ts +36 -120
  68. package/dist/memory/renderer.d.ts +16 -7
  69. package/dist/memory/similar-queries.d.ts +40 -0
  70. package/dist/minsync/errors.d.ts +14 -0
  71. package/dist/minsync/index.d.ts +1 -0
  72. package/dist/minsync/method.d.ts +8 -5
  73. package/dist/mirror/index.d.ts +1 -1
  74. package/dist/mirror/paths.d.ts +6 -0
  75. package/dist/mirror/sync.d.ts +5 -2
  76. package/dist/parser/defaults.d.ts +16 -5
  77. package/dist/parser/index.d.ts +1 -1
  78. package/dist/parser/kordoc.d.ts +8 -1
  79. package/dist/parser/ocr-engines.d.ts +19 -0
  80. package/dist/retrieval/bm25.d.ts +19 -0
  81. package/dist/retrieval/engine.d.ts +33 -43
  82. package/dist/retrieval/index.d.ts +3 -1
  83. package/dist/retrieval/merger.d.ts +6 -0
  84. package/dist/retrieval/rerank.d.ts +4 -2
  85. package/dist/retrieval/selection.d.ts +89 -0
  86. package/dist/retrieval/types.d.ts +1 -3
  87. package/dist/web/search/format.d.ts +5 -2
  88. package/dist/web/search/index.d.ts +7 -1
  89. package/package.json +11 -7
  90. package/skills/autorag/SKILL.md +43 -23
  91. package/skills/autorag-doctor/SKILL.md +40 -26
  92. package/skills/autorag-lite-setup/SKILL.md +123 -64
  93. package/skills/autorag-setup/SKILL.md +107 -22
  94. package/dist/cli/commands/feedback.d.ts +0 -8
  95. package/dist/datasource/access-context.d.ts +0 -43
  96. package/dist/datasource/result-filter.d.ts +0 -64
  97. package/dist/parser/ocr.d.ts +0 -31
  98. package/skills/autorag-lite-search/SKILL.md +0 -245
@@ -2,28 +2,20 @@
2
2
  * RetrievalEngine — standalone typed seam for model-free retrieval.
3
3
  *
4
4
  * Wraps the existing retrieval pipeline (registry, parallel retriever,
5
- * datasource result filter, and merger) into a single public entry point.
5
+ * datasource scope filter, and merger) into a single public entry point.
6
6
  * Exposes a deterministic, self-contained retrieval API with diagnostics.
7
7
  *
8
- * Security invariants (delegated to {@link DatasourceAccessContext} and
9
- * {@link DatasourceResultFilter}):
10
- * - Access is default-deny: when no trusted allow-tags are configured,
11
- * every datasource method result is dropped.
12
- * - Deny is always an explicit empty result array, never `undefined`.
13
- * - Model/tool arguments (`allowedTags`, `allowedScopes`) cannot widen the
14
- * trusted access context constructed during engine creation.
8
+ * Every configured/connected datasource is searchable without permission
9
+ * setup. The ordinary query `scope` narrows scope-capable datasource results
10
+ * after retrieval; local (non-datasource) methods and datasources without
11
+ * source-scope support pass through untouched.
15
12
  */
16
- import { DatasourceAccessContext, type DatasourceAccessContextOptions } from "../datasource/access-context.js";
17
13
  import { RetrievalMethodRegistry } from "./registry.js";
18
- import type { Reranker } from "./rerank.js";
14
+ import { type Reranker } from "./rerank.js";
15
+ import { type RetrievalSelection } from "./selection.js";
19
16
  import type { RetrievalDiagnostic, RetrievalMethod, RetrievalOptions, RetrievalResult, RetrievalUnsearchedSurface } from "./types.js";
20
17
  /** Options for constructing a standalone {@link RetrievalEngine}. */
21
18
  export interface RetrievalEngineOptions {
22
- /**
23
- * Datasource access configuration. Default-deny when omitted.
24
- * @default { allowedTags: undefined, allowedScopes: undefined }
25
- */
26
- readonly datasourceAccess?: DatasourceAccessContextOptions;
27
19
  /**
28
20
  * Default `topK` when the caller omits it. This is a safety ceiling on
29
21
  * merged evidence, not a relevance cut: the merger returns every distinct
@@ -34,13 +26,13 @@ export interface RetrievalEngineOptions {
34
26
  /** Default deduplication flag. @default true */
35
27
  readonly defaultDedup?: boolean;
36
28
  /**
37
- * Optional predicate that returns `true` when the MinSync binary is missing.
38
- * When set, the engine checks every method named `"minsync"`: if the binary
39
- * is unavailable the method returns empty results without throwing, the engine
40
- * emits a `minsync-unavailable` diagnostic with full method-agnostic path
41
- * preservation — matching the existing {@link AutoRAGAgent} behavior.
29
+ * Configured datasource ids from the skill catalog, including datasources
30
+ * that expose no retrieval methods. {@link retrieveSelected} uses this to
31
+ * tell an unknown datasource id from a known one. When omitted, the engine
32
+ * derives ids from its registered methods; method-less datasources are then
33
+ * treated as unknown.
42
34
  */
43
- readonly isMinSyncBinaryMissing?: () => boolean;
35
+ readonly datasourceIds?: () => readonly string[];
44
36
  /**
45
37
  * Optional post-merge reranker. When set, merged results are reordered by
46
38
  * the reranker after dedup and score normalization. A reranker failure is
@@ -48,6 +40,11 @@ export interface RetrievalEngineOptions {
48
40
  * the engine never silently drops evidence because a reranker was down.
49
41
  */
50
42
  readonly reranker?: Reranker;
43
+ /**
44
+ * Number of merged results kept after reranking when the caller omits `topK`.
45
+ * Only applies when {@link reranker} is set. @default DEFAULT_RERANK_TOP_N
46
+ */
47
+ readonly rerankTopN?: number;
51
48
  }
52
49
  /**
53
50
  * Model-free retrieval pipeline.
@@ -56,7 +53,7 @@ export interface RetrievalEngineOptions {
56
53
  * ```
57
54
  * methods = registry.list()
58
55
  * byMethod = retriever.retrieveWithDiagnostics(methods, query, options)
59
- * filtered = filter.filter(byMethod, methods, ctx, options.scope)
56
+ * filtered = filterDatasourceScope(byMethod, methods, options.scope)
60
57
  * merged = merger.merge(filtered, { topK, dedup: true }) // distinct chunks, pure duplicates dropped
61
58
  * → { results: merged, diagnostics }
62
59
  * ```
@@ -73,18 +70,15 @@ export interface RetrievalEngineOptions {
73
70
  export declare class RetrievalEngine {
74
71
  private readonly registry;
75
72
  private readonly retriever;
76
- private readonly filter;
77
73
  private readonly merger;
78
- private readonly accessContext;
79
74
  private readonly defaultTopK;
80
75
  private readonly defaultDedup;
81
- private readonly isMinSyncBinaryMissing;
76
+ private readonly datasourceIdsProvider;
82
77
  private readonly reranker;
78
+ private readonly rerankTopN;
83
79
  constructor(options?: RetrievalEngineOptions);
84
80
  /** The underlying method registry. Intentionally public for tooling. */
85
81
  getMethodRegistry(): RetrievalMethodRegistry;
86
- /** The underlying datasource access context. Read-only for inspection. */
87
- getAccessContext(): DatasourceAccessContext;
88
82
  /**
89
83
  * Register a retrieval method. Overrides the registered-once check from
90
84
  * {@link RetrievalMethodRegistry} per caller requirement.
@@ -125,22 +119,18 @@ export declare class RetrievalEngine {
125
119
  unsearched: RetrievalUnsearchedSurface[];
126
120
  }>;
127
121
  /**
128
- * Post-check for MinSync binary-missing diagnostic.
122
+ * Run a selected subset of the registered methods — parallel retrieve,
123
+ * scope filter, merge — and return merged results with diagnostics.
129
124
  *
130
- * When a registered method named `"minsync"` fails to throw (the method returns
131
- * `[]` because the binary is missing), {@link ParallelRetriever} cannot record
132
- * a diagnostic. This method checks whether the minsync binary is unavailable
133
- * and emits a `minsync-unavailable` diagnostic when every minsync method's
134
- * result set is empty, exactly matching the existing {@link AutoRAGAgent}
135
- * behavior (see `agent.src/agent/agent.ts` `retrieveWithDiagnostics`). The
136
- * same check reports the MinSync surface as unsearched, so a caller reading
137
- * only the skip report still learns that local sources were not queried.
138
- */
139
- private appendMinSyncUnavailable;
140
- /**
141
- * Build a datasource access context scoped to the caller's options.
142
- * Model/tool arguments (allowedTags, allowedScopes) from options can only
143
- * further restrict the trusted context, never widen it.
125
+ * Unlike {@link retrieve}, selection happens BEFORE any backend is invoked:
126
+ * the eligible method list is reduced first, so an unselected datasource
127
+ * backend is never spawned. Unknown method or datasource selections throw
128
+ * {@link RetrievalSelectionError}. The ordinary query `scope` still narrows
129
+ * results after retrieval.
144
130
  */
145
- private accessContextFor;
131
+ retrieveSelected(query: string, selection?: RetrievalSelection, options?: RetrievalOptions): Promise<{
132
+ results: RetrievalResult[];
133
+ diagnostics: RetrievalDiagnostic[];
134
+ unsearched: RetrievalUnsearchedSurface[];
135
+ }>;
146
136
  }
@@ -1,8 +1,10 @@
1
+ export { bm25Scores, tokenize } from "./bm25.js";
1
2
  export { RetrievalEngine, type RetrievalEngineOptions } from "./engine.js";
2
3
  export type { MergeOptions } from "./merger.js";
3
4
  export { ParallelRetriever, ResultMerger } from "./merger.js";
4
5
  export { RetrievalMethodRegistry } from "./registry.js";
5
- export { type CreateRerankerOptions, createReranker, DEFAULT_RERANK_API_KEY_ENV, DEFAULT_RERANK_MODEL, DEFAULT_RERANK_PROVIDER, OpenRouterReranker, type OpenRouterRerankerOptions, type Reranker, type RerankerDescriptor, type RerankOptions, SUPPORTED_RERANK_PROVIDERS, } from "./rerank.js";
6
+ export { type CreateRerankerOptions, createReranker, DEFAULT_RERANK_API_KEY_ENV, DEFAULT_RERANK_MODEL, DEFAULT_RERANK_PROVIDER, DEFAULT_RERANK_TOP_N, OpenRouterReranker, type OpenRouterRerankerOptions, type Reranker, type RerankerDescriptor, type RerankOptions, SUPPORTED_RERANK_PROVIDERS, } from "./rerank.js";
6
7
  export { matchesVirtualPathScope, normalizeVirtualPath, normalizeVirtualPathScope, virtualPathScopeToRegExp, } from "./scope.js";
8
+ export { type DatasourceCatalogEntry, derivedDatasourceIds, type RetrievalSelection, RetrievalSelectionError, type RetrievalSelectionErrorCode, resolveSelectedMethods, } from "./selection.js";
7
9
  export { describeRetrievalError, groupUnsearchedSurfaces, MINSYNC_SURFACE, type RetrievalSkip, retrievalSurfaceFor, } from "./skip.js";
8
10
  export type { CuratedResult, NumberedResult, RetrievalDiagnostic, RetrievalDiagnosticCode, RetrievalMethod, RetrievalMethodDescriptor, RetrievalOptions, RetrievalResult, RetrievalUnsearchedSurface, RetrievalWithDiagnostics, } from "./types.js";
@@ -30,6 +30,12 @@ export interface MergeOptions {
30
30
  export declare class ResultMerger {
31
31
  merge(results: Map<string, RetrievalResult[]>, options: MergeOptions): RetrievalResult[];
32
32
  }
33
+ /**
34
+ * Runs every method in parallel. A method that throws is skipped and the
35
+ * others still answer, with one exception: {@link MinSyncRequiredError} means
36
+ * the required MinSync is absent, so the whole retrieval fails instead of
37
+ * returning an answer that silently lacks its content search.
38
+ */
33
39
  export declare class ParallelRetriever {
34
40
  retrieve(methods: RetrievalMethod[], query: string, options: RetrievalOptions): Promise<Map<string, RetrievalResult[]>>;
35
41
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Reranker seam — a post-retrieval reordering stage over merged evidence.
3
3
  *
4
- * The retrieval pipeline (registry → ParallelRetriever → DatasourceResultFilter
4
+ * The retrieval pipeline (registry → ParallelRetriever → filterDatasourceScope
5
5
  * → ResultMerger) produces a scored candidate list. A reranker reorders that
6
6
  * list with a dedicated relevance model. The default implementation talks to
7
7
  * OpenRouter's rerank router through the OpenRouter TypeScript SDK.
@@ -18,6 +18,8 @@ export declare const DEFAULT_RERANK_MODEL = "voyageai/rerank-3-lite";
18
18
  export declare const DEFAULT_RERANK_PROVIDER = "openrouter";
19
19
  /** Default environment variable holding the OpenRouter API key. */
20
20
  export declare const DEFAULT_RERANK_API_KEY_ENV = "OPENROUTER_API_KEY";
21
+ /** Default number of merged chunks kept after reranking. */
22
+ export declare const DEFAULT_RERANK_TOP_N = 25;
21
23
  /** Rerank providers {@link createReranker} can build. */
22
24
  export declare const SUPPORTED_RERANK_PROVIDERS: readonly string[];
23
25
  /** Static description of a reranker, used for diagnostics and inspection. */
@@ -26,7 +28,7 @@ export interface RerankerDescriptor {
26
28
  readonly name: string;
27
29
  /** Provider id (e.g. `openrouter`). */
28
30
  readonly provider: string;
29
- /** Wire model id (e.g. `cohere/rerank-4-fast`). */
31
+ /** Wire model id (e.g. `voyageai/rerank-3`). */
30
32
  readonly model: string;
31
33
  /** Whether the reranker has everything it needs to run (credentials, config). */
32
34
  readonly available: boolean;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Selection gating for the retrieval pipeline.
3
+ *
4
+ * `searchSelected` lets a caller narrow a search to specific datasources,
5
+ * specific methods, or the local (non-datasource) surfaces *before* any backend
6
+ * is invoked. This module owns that narrowing so the engine can reuse its
7
+ * existing parallel-retrieve / scope-filter / merge chain on the reduced
8
+ * method list instead of fanning out to every backend and filtering afterwards.
9
+ *
10
+ * Every configured datasource is searchable without permission setup. A
11
+ * caller-supplied selection can only *narrow* the registered method set: it can
12
+ * never add a method that is not registered. Unknown method or datasource names
13
+ * are rejected with a typed error, never silently resolved.
14
+ */
15
+ import type { RetrievalMethod } from "./types.js";
16
+ /**
17
+ * Model-free, credential-free descriptor of one configured datasource, for
18
+ * catalog/listing surfaces. Carries no credentials, config paths, or raw
19
+ * instance metadata — only the identity, descriptive tags, and the opaque
20
+ * source scope strings the datasource exposes.
21
+ */
22
+ export interface DatasourceCatalogEntry {
23
+ /** Stable datasource id, e.g. `"kakao"`. */
24
+ readonly datasourceId: string;
25
+ /** Skill name, e.g. `"kakao"`. */
26
+ readonly name: string;
27
+ /** Skill kind, e.g. `"chat"` or `"chat-export"`. */
28
+ readonly type: string;
29
+ /** Human-readable description. */
30
+ readonly description: string;
31
+ /** Descriptive tags (metadata only). */
32
+ readonly tags: readonly string[];
33
+ /** Capability names such as `"keyword"`, `"scoped"`, `"polling"`. */
34
+ readonly capabilities: readonly string[];
35
+ readonly status: "active" | "stub";
36
+ /**
37
+ * Slash-hierarchical source scope strings discovered for this datasource.
38
+ * Scope-capable datasources expose their instance source scopes; unscoped
39
+ * datasources expose their opaque sources.
40
+ */
41
+ readonly sourceScopes: readonly string[];
42
+ }
43
+ /**
44
+ * Caller request narrowing which retrieval methods run.
45
+ *
46
+ * Semantics (unambiguous, narrowing-only):
47
+ * - `datasourceIds` omitted ⇒ every datasource method is eligible.
48
+ * - `datasourceIds` present ⇒ ONLY methods of those datasources are eligible,
49
+ * plus the local (non-datasource) methods only when `local === true`.
50
+ * - `local === false` ⇒ no local method is ever eligible.
51
+ * - `methods` present ⇒ intersected with the eligible set; every named method
52
+ * must exist.
53
+ */
54
+ export interface RetrievalSelection {
55
+ /** Datasource ids to run. Omit to run all configured datasources. */
56
+ readonly datasourceIds?: readonly string[];
57
+ /** Method names to run, intersected with the datasource/local selection. */
58
+ readonly methods?: readonly string[];
59
+ /** Whether local (non-datasource) methods run. See the semantics above. */
60
+ readonly local?: boolean;
61
+ }
62
+ export type RetrievalSelectionErrorCode = "unknown-method" | "unknown-datasource";
63
+ /** Thrown when a caller selection names an unknown method or datasource. */
64
+ export declare class RetrievalSelectionError extends Error {
65
+ readonly code: RetrievalSelectionErrorCode;
66
+ constructor(code: RetrievalSelectionErrorCode, message: string);
67
+ }
68
+ /**
69
+ * Reduce the registered methods to the ones a selection authorizes to run.
70
+ *
71
+ * The returned list is built entirely from `methods`; a caller cannot conjure a
72
+ * method that is not registered. Explicit selections that name an unknown
73
+ * method or an unknown datasource throw {@link RetrievalSelectionError} rather
74
+ * than degrading silently.
75
+ *
76
+ * @param methods Every registered retrieval method.
77
+ * @param selection Caller narrowing request.
78
+ * @param datasourceIds Configured datasource ids (from the catalog), used to
79
+ * distinguish a known datasource from an unknown one. Method-less
80
+ * datasources belong here and select cleanly (yielding nothing).
81
+ */
82
+ export declare function resolveSelectedMethods(methods: readonly RetrievalMethod[], selection: RetrievalSelection, datasourceIds: readonly string[]): RetrievalMethod[];
83
+ /**
84
+ * Configured datasource ids derived directly from a method set. Used as the
85
+ * fallback catalog for a standalone engine that has no datasource-skill catalog
86
+ * wired in; method-less datasources are unknowable here and therefore treated
87
+ * as unknown.
88
+ */
89
+ export declare function derivedDatasourceIds(methods: readonly RetrievalMethod[]): string[];
@@ -18,15 +18,13 @@ export interface RetrievalOptions {
18
18
  topK?: number;
19
19
  scope?: string;
20
20
  filters?: Record<string, unknown>;
21
- allowedTags?: readonly string[];
22
- allowedScopes?: readonly string[];
23
21
  signal?: AbortSignal;
24
22
  }
25
23
  export interface RetrievalMethod {
26
24
  describe(): RetrievalMethodDescriptor;
27
25
  retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
28
26
  }
29
- export type RetrievalDiagnosticCode = "retrieval-method-failed" | "minsync-unavailable" | "rerank-failed";
27
+ export type RetrievalDiagnosticCode = "retrieval-method-failed" | "rerank-failed";
30
28
  /**
31
29
  * A retrieval surface (local MinSync files or one datasource) that was not
32
30
  * searched for this query. Reported next to partial results so a caller that
@@ -18,8 +18,11 @@ export declare const WEB_SEARCH_SYSTEM_PROMPT = "Web research assistant: accurat
18
18
  export declare const WEB_SEARCH_TOOL_DESCRIPTION = "Web search: current information beyond knowledge cutoff.\n\n- SHOULD prefer primary sources (papers, official docs); corroborate key claims with multiple sources.\n- MUST link cited sources in final response.\n- NEVER use for programmatically accessible content or known URLs (GitHub repos/issues, known arXiv papers, Wikipedia pages, official docs) \u2014 use web_fetch on the URL directly.\n- `query`: every provider supports Google-style `site:`/`-site:`, `after:`/`before:` (YYYY-MM-DD), `inurl:`, `intitle:`, `filetype:`, `\"exact phrase\"`, `-term`, `OR`. Map constraints to native filters when available; otherwise results are filtered leniently. If a constraint matches nothing, it is relaxed and reported; zero results are never forced.";
19
19
  /** Format an age in seconds as a compact relative string ("45s", "2h", "3d"). */
20
20
  export declare function formatAge(ageSeconds: number | undefined): string;
21
- /** Format response for LLM consumption. `notes` lead the output (e.g. relaxed-constraint warnings). */
22
- export declare function formatForLLM(response: SearchResponse, notes?: readonly string[]): string;
21
+ /**
22
+ * Format response for LLM consumption. `notes` lead the output (e.g. relaxed-constraint warnings).
23
+ * `sourceLabels` replaces the positional `[n]` of each source (e.g. `e3`) so the model can cite it by id.
24
+ */
25
+ export declare function formatForLLM(response: SearchResponse, notes?: readonly string[], sourceLabels?: readonly string[]): string;
23
26
  /**
24
27
  * `true` when the response carries an actual result the caller can read: an
25
28
  * answer, a source, or a citation. Search-attempt metadata (`searchQueries`,
@@ -1,5 +1,5 @@
1
1
  import type { ModelNativeSearchAuth } from "./model-auth.js";
2
- import { type SearchProviderId, type SearchResponse } from "./types.js";
2
+ import { type SearchProviderId, type SearchResponse, type SearchSource } from "./types.js";
3
3
  export interface WebSearchQueryParams {
4
4
  query: string;
5
5
  recency?: "day" | "week" | "month" | "year";
@@ -38,6 +38,12 @@ export interface WebSearchExecuteOptions {
38
38
  modelAuth?: ModelNativeSearchAuth;
39
39
  /** Transport injection for tests/proxies; forwarded to providers that accept it. */
40
40
  fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
41
+ /**
42
+ * Called with the sources that survived filtering, just before formatting.
43
+ * Returns one label per source (e.g. an evidence id) that replaces its
44
+ * positional `[n]` in the output the model reads.
45
+ */
46
+ labelSources?: (sources: readonly SearchSource[]) => readonly string[];
41
47
  }
42
48
  /** Execute a web search through the provider fallback chain. */
43
49
  export declare function executeWebSearch(params: WebSearchQueryParams, options?: WebSearchExecuteOptions): Promise<WebSearchExecuteResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorag/librarian",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "description": "Self-evolving librarian agent on Pi framework with pluggable retrieval methods",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,7 +21,8 @@
21
21
  }
22
22
  },
23
23
  "bin": {
24
- "autorag": "dist/cli/index.js"
24
+ "autorag": "dist/cli/index.js",
25
+ "autorag-mcp": "dist/mcp/index.js"
25
26
  },
26
27
  "files": [
27
28
  "dist",
@@ -35,7 +36,7 @@
35
36
  "access": "public"
36
37
  },
37
38
  "scripts": {
38
- "build": "bun build src/index.ts src/core.ts src/cli/index.ts --outdir dist --target node --packages external && tsc -p tsconfig.build.json && node scripts/fixup-dts.mjs",
39
+ "build": "bun build src/index.ts src/core.ts src/cli/index.ts src/mcp/index.ts --outdir dist --target node --packages external && tsc -p tsconfig.build.json && node scripts/fixup-dts.mjs",
39
40
  "prepublishOnly": "bun run typecheck && bun run build",
40
41
  "prepare": "bun run build",
41
42
  "test": "node scripts/run-test-files.mjs",
@@ -50,14 +51,16 @@
50
51
  "node": ">=24.0.0"
51
52
  },
52
53
  "dependencies": {
53
- "@earendil-works/pi-agent-core": "^0.86.1",
54
- "@earendil-works/pi-ai": "^0.86.1",
55
- "@earendil-works/pi-coding-agent": "0.86.1",
56
- "@earendil-works/pi-tui": "0.86.1",
54
+ "@earendil-works/pi-agent-core": "^1.1.0",
55
+ "@earendil-works/pi-ai": "^1.1.0",
56
+ "@earendil-works/pi-coding-agent": "1.1.0",
57
+ "@earendil-works/pi-tui": "1.1.0",
58
+ "@modelcontextprotocol/server": "^2.3.0",
57
59
  "@openrouter/sdk": "^1.4.21",
58
60
  "chardet": "^2.2.0",
59
61
  "fast-xml-parser": "^5.11.1",
60
62
  "iconv-lite": "^0.7.3",
63
+ "jev-use": "^0.8.0",
61
64
  "jszip": "^3.10.1",
62
65
  "kordoc": "^4.15.7",
63
66
  "mailparser": "^3.9.20",
@@ -71,6 +74,7 @@
71
74
  },
72
75
  "devDependencies": {
73
76
  "@biomejs/biome": "2.5.14",
77
+ "@modelcontextprotocol/client": "^2.3.0",
74
78
  "@types/mailparser": "^3.4.6",
75
79
  "@types/node": "^26.4.1",
76
80
  "@types/ws": "^8.18.1",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: autorag
3
- description: Search, summarize, compare, and answer questions from an already configured AutoRAG librarian over local documents and authorized datasources. Use when the user asks AutoRAG to search PDFs, wikis, notes, or a knowledge base. Use autorag-setup for install, model, roots, indexing, or datasource changes.
3
+ description: Search, summarize, compare, and answer questions from an already configured AutoRAG librarian over local documents and configured datasources. Use when the user asks AutoRAG to search PDFs, wikis, notes, or a knowledge base. Use autorag-setup for install, model, roots, indexing, or datasource changes.
4
4
  license: MIT
5
5
  ---
6
6
 
@@ -8,7 +8,7 @@ license: MIT
8
8
 
9
9
  Use this skill when AutoRAG is already configured and the user asks to search,
10
10
  summarize, compare, or answer questions from local PDFs, wikis, notes, research
11
- papers, knowledge bases, or authorized datasources.
11
+ papers, knowledge bases, or configured datasources.
12
12
 
13
13
  AutoRAG is the specialized librarian agent. One configured model plans the
14
14
  search, calls MinSync, Jikji, datasource, and filesystem tools, reads
@@ -47,31 +47,39 @@ refresh is enabled by default and can be disabled with
47
47
  to `workspacePath`) that refresh keeps out of the parsed mirror and MinSync.
48
48
  A folder entry excludes everything under it. Removing an entry and running
49
49
  `autorag refresh --method minsync` indexes the file again. Excluded sources are
50
- recorded as `user-excluded` skips, so they are not reported as stale.
50
+ recorded as `user-excluded` skips, so they are not reported as stale. Jikji
51
+ indexes the source folders directly and is not refreshed here, so AutoRAG also
52
+ drops excluded paths from the `jikji_find` answer pack and the baseline prefetch
53
+ at retrieval time; the on-disk `.jikji_agent_map.md` stays complete, and direct
54
+ file reads remain available.
51
55
 
52
56
  `status` is model-free and path-opaque. `health` resolves the single model,
53
57
  checks credential presence, and normally probes one live completion. If the
54
58
  model, authentication, configuration, or indexes are unhealthy, use
55
59
  `autorag-setup` rather than guessing private provider details.
56
60
 
57
- MinSync and Jikji should normally be healthy. MinSync and Jikji
58
- auto-install on first use by default. If they are missing or stale, run a full
61
+ MinSync and Jikji should normally be healthy. Answering a question never
62
+ builds or installs them: `autorag refresh` auto-installs both by default and
63
+ builds their indexes incrementally. If they are missing or stale, run a full
59
64
  `autorag refresh` or return to setup rather than silently degrading to
60
65
  lexical-only search.
61
66
 
62
67
  ## Search
63
68
 
64
- Prefer `--json --debug` when another agent will consume the result or record
65
- feedback. `--json` alone omits `sessionId`. `--debug` adds session/diagnostics
66
- fields and does not print filesystem paths.
69
+ Prefer `--json --debug` when another agent will consume the result.
70
+ `--json` alone omits `sessionId`. `--debug` adds session/diagnostics fields and
71
+ does not print filesystem paths.
67
72
 
68
73
  ```bash
69
74
  autorag search "what were the key findings in the Q3 report" --top-k 5 --json --debug
70
75
  ```
71
76
 
72
77
  `--json --debug` includes `answer`, numbered `results` (`number`, `title`,
73
- `summary`, optional `source`), and `sessionId`. Use that `sessionId` for
74
- feedback. `--json` without `--debug` is only `answer` plus `results`.
78
+ `summary`, optional `source`), and `sessionId`. `--json` without `--debug` is
79
+ only `answer` plus `results`. Every
80
+ bracketed `[n]` citation in `answer` resolves to a `results[].number` of the
81
+ same response; an unmatched citation is removed and reported as a
82
+ `citation-without-result` diagnostic.
75
83
 
76
84
  To inspect the exact persisted evidence behind numbered results, use:
77
85
 
@@ -85,10 +93,8 @@ ID, raw excerpt/content, and any available `chunkIndex`, `lineNumber`,
85
93
  the session. Prefer this command whenever the caller wants detailed chunk text
86
94
  rather than only the curated summary.
87
95
 
88
- - `--scope` narrows datasource retrieval to a requested sub-path; it cannot
89
- grant access.
90
- - `--tags` further narrows already-authorized datasource results and never
91
- grants new access.
96
+ - `--scope` narrows datasource retrieval to a requested sub-path (ordinary
97
+ per-query filtering).
92
98
  - `--json` is required for programmatic consumption.
93
99
  - `--debug` is required for `sessionId` and diagnostics in search output.
94
100
  - `autorag evidence` is the detailed source/chunk inspection path.
@@ -98,12 +104,27 @@ AutoRAG. The search loop can use Jikji, MinSync lexical/vector/hybrid retrieval,
98
104
  direct source reading as appropriate. If search fails because of model,
99
105
  provider, auth, or timeout problems, diagnose with `autorag health --json`.
100
106
 
101
- Record feedback so retrieval memory can learn. Numbers refer to the returned
102
- knowledge units. Supply at least one feedback list:
103
-
104
- ```bash
105
- autorag feedback <sessionId> --useful 1,3 --not-useful 2 --json
106
- ```
107
+ Every search is two-phase: a fast answer, then verification. With Jev on (the
108
+ default, OpenRouter), Jev first routes the question:
109
+
110
+ - General knowledge or small talk is answered directly.
111
+ - A request to view or change AutoRAG's own settings (model, providers,
112
+ datasources) is handled by the agent itself: it loads the setup skill, edits
113
+ the active config, verifies it, and reports what changed. The running agent
114
+ keeps its startup model; changes apply to the next `autorag` launch.
115
+ - Private-data questions use local search; public current facts use web search.
116
+ - A multi-part question is split into up to five parallel search queries.
117
+ - On local search, Jev also picks which registered datasources (Slack,
118
+ Discord, KakaoTalk, email, ...) to search before the fast answer, from each
119
+ datasource's description and where similar past questions were answered;
120
+ their chunks are reranked together with local file evidence.
121
+
122
+ After the fast answer, Jev ends the run if the answer is complete and
123
+ evidence-backed. So `results` may come straight from the fast answer, with no
124
+ verification phase. `--debug` diagnostics show the decision: `query-routed`
125
+ (branch and queries), `datasources-selected` (datasources searched or skipped,
126
+ with probabilities), `follow-up-skipped` (fast answer final), or
127
+ `query-route-fallback` (Jev unavailable, single local search).
107
128
 
108
129
  ## Maintenance
109
130
 
@@ -144,9 +165,8 @@ Never target source documents. `memory inspect` is read-only and path-opaque.
144
165
  - Never expose provider credentials or authentication payloads.
145
166
  - Never invent provider identities or model ids.
146
167
  - A Pi-usable subscription is valid; a subscription Pi cannot invoke is not.
147
- - Preserve real source mapping and numbered feedback identifiers.
148
- - Prefer `--json --debug` when another agent consumes search output or will
149
- call `autorag feedback`.
168
+ - Preserve real source mapping.
169
+ - Prefer `--json --debug` when another agent consumes search output.
150
170
  - Do not invent CLI commands. `autorag --help` is the command list of record,
151
171
  including the shipped `setup`, `gateway`, `models`, `serve`, `p2p`, `tui`, and `lite`
152
172
  commands. `autorag <command> --help` prints that command's own flags, and
@@ -43,7 +43,7 @@ autorag gateway status --format json
43
43
 
44
44
  Config lives at `--config`, `AUTORAG_CONFIG`, `$AUTORAG_HOME/config.json`, or
45
45
  `~/.autorag/config.json`. Read `searchPaths`, `workspacePath`, `minSync`,
46
- `jikji`, `datasources`, and `datasourceAccess` before changing anything.
46
+ `jikji`, and `datasources` before changing anything.
47
47
 
48
48
  If the CLI itself is missing or the config does not exist, stop and run the
49
49
  `autorag-setup` skill first — doctor repairs an existing install, it does not
@@ -87,36 +87,42 @@ Rules:
87
87
 
88
88
  ## 3. Prove searchability
89
89
 
90
- Indexing without retrieval is a failed run. Probe retrieval per datasource with
91
- the model-free path, then once end to end:
90
+ Indexing without retrieval is a failed run. Probe retrieval per datasource
91
+ through the model-free MCP tools, then once end to end:
92
+
93
+ ```text
94
+ autorag.status {}
95
+ autorag.search {"query":"a word that certainly appears","topK":3}
96
+ autorag.search {"query":"recent topic","datasourceIds":["discord"],"topK":3}
97
+ autorag.search {"query":"recent mail subject","scope":"/mailcrawl/**","topK":3}
98
+ ```
92
99
 
93
100
  ```bash
94
- autorag lite retrieve "a word that certainly appears" --top-k 3 --json --debug
95
- autorag lite retrieve "recent topic" --tags discord --top-k 3 --json --debug
96
- autorag lite retrieve "recent mail subject" --scope "/mailcrawl/**" --top-k 3 --json --debug
97
101
  autorag search "summarize the collection" --top-k 3 --json --debug
98
102
  ```
99
103
 
100
- - **Always pass `--debug` when diagnosing, and read the diagnostics.** A run
104
+ - **Always read the `diagnostics` returned by MCP `autorag.search`.** A run
101
105
  that silently dropped a whole retrieval method still looks successful, just
102
- with fewer results; only the diagnostics name it (`minsync-unavailable`,
103
- `retrieval-method-failed`). `autorag search --json` hides `diagnostics`,
104
- `sessionId`, and per-result evidence unless `--debug` is set. `lite retrieve
105
- --json` always carries the `diagnostics` array, but its human-readable output
106
- hides it without `--debug`.
106
+ with fewer results; only the diagnostics name it (`retrieval-method-failed`).
107
+ The model-backed CLI `autorag search --json`
108
+ hides `diagnostics`, `sessionId`, and per-result evidence unless `--debug` is
109
+ set, so pass `--debug` when diagnosing that path.
107
110
  - A method missing from the returned `method` values means that method
108
111
  contributed nothing. During a full MinSync re-sync this is expected: the
109
112
  store is being rebuilt, `minsync status` reports `NotSynced`, and local-file
110
113
  hits stay absent until it finishes. Confirm with `minsync status` before
111
114
  treating it as a failure, and never kill a running sync to "fix" it.
112
- - `lite retrieve` needs no model, so it isolates retrieval from model failures.
113
- - Use `--tags` / `--scope` to force one datasource; they can only narrow
114
- trusted access, never grant it. A datasource absent from `datasourceAccess`
115
- returns nothing no matter how healthy its store is — fix the config, not the
116
- store.
117
- - `autorag evidence SESSION --json` (session id comes from `--json --debug`)
118
- shows the exact chunk behind a numbered result; use it to confirm a hit is
119
- real and its source is readable.
115
+ - MCP `autorag.search` needs no model, so it isolates retrieval from model
116
+ failures.
117
+ - Use MCP `datasourceIds` to select configured connections before retrieval;
118
+ `scope` narrows results within scope-capable datasources. Discover connection
119
+ IDs with `autorag.datasources.list`; descriptor tags are metadata only, not
120
+ search filters. Every configured connection is searchable — if one returns
121
+ nothing, investigate its native store, connector, or the query itself.
122
+ - `autorag.evidence {"sessionId":"...","resultNumber":N}` shows the exact chunk
123
+ behind a numbered result; use it to confirm a hit is real and its source is
124
+ readable. The CLI `autorag evidence SESSION --json` remains for terminal
125
+ repair.
120
126
  - Local-file hits must map to an absolute, existing path. Datasource hits keep
121
127
  source-native identities such as `/kakao/personal/chunks/42`; those are not
122
128
  filesystem paths and must never be passed to `cat`.
@@ -192,13 +198,16 @@ timer, or Task Scheduler).
192
198
  no `"type"`. It is skipped, not fatal — fix the name or add `"type"`.
193
199
  - `datasource-index-failed` / `sync-failed`: the backing CLI errored. Run that
194
200
  CLI's own check from the table above and fix it there.
195
- - `minsync-unavailable` / `jikji-unavailable`: the binary is missing and
196
- auto-install failed. Both install through cargo; verify the Rust toolchain,
197
- then `autorag refresh --method minsync` to retry.
201
+ - A missing MinSync binary is not a diagnostic: `autorag search`, `autorag refresh`
202
+ and MCP tools fail with `MinSync is required ...` and a non-zero exit. Install it
203
+ (`cargo install minsync`) or leave `minSync.autoInstall` on, then retry.
204
+ - `jikji-unavailable`: the binary is missing and auto-install failed. It
205
+ installs through cargo; verify the Rust toolchain, then `autorag refresh --method jikji` to retry.
198
206
  - `auth-error` / `rate-limited`: model or datasource credentials. Report the
199
207
  missing environment-variable **name** and let the user supply it.
200
- - A datasource configured but not listed in `datasourceAccess.allowedTags` /
201
- `allowedScopes` is default-denied and invisible to search. Add it there.
208
+ - A configured datasource that returns nothing is a native store, connector, or
209
+ query problem — every configured connection is searchable. Run its native
210
+ check from the table above and fix it there.
202
211
 
203
212
  ## Diagnostic codes
204
213
 
@@ -206,7 +215,7 @@ timer, or Task Scheduler).
206
215
  |---|---|---|
207
216
  | `stale-index` | Sources changed since last refresh | `autorag refresh --method parsed,minsync` |
208
217
  | `index-not-ready` | Index missing or never built | `autorag refresh --json` |
209
- | `minsync-unavailable` | MinSync binary missing or install failed | Check cargo, retry refresh |
218
+ | `minsync-sync-failed` | MinSync indexing failed; the message carries MinSync's own reason | Fix the reported cause, then `autorag refresh --method minsync` |
210
219
  | `jikji-unavailable` | Jikji binary missing or install failed | Check cargo, retry refresh |
211
220
  | `everything-index-failed` | Windows Everything instance could not start or index; message carries ES exit code and stderr | Fix the reported cause, `autorag refresh --method everything --json` |
212
221
  | `embedding-identity-mismatch` | Indexed vectors use a different embedder | `autorag index rebuild --method minsync` |
@@ -217,6 +226,11 @@ timer, or Task Scheduler).
217
226
  | `unknown-datasource-skill` | Config name is not a known template | Fix the name or add `"type"` |
218
227
  | `retrieval-method-failed` | One method errored during the query | Read `--debug` diagnostics |
219
228
  | `auth-error` | Credentials missing or rejected | Report the env var name |
229
+ | `query-route-fallback` | Jev routing unavailable (often `OPENROUTER_API_KEY` unset); searched local with the original question | `test -n "$OPENROUTER_API_KEY"`; report the env var name, never its value |
230
+ | `query-decomposition-failed` | Decomposition model call failed; searched the original question | Check `queryDecomposition.model` resolves (`autorag models list --provider openrouter`) |
231
+ | `follow-up-check-fallback` | Jev post-fast-answer check unavailable; the run verified | Same as `query-route-fallback` |
232
+ | `datasource-selection-fallback` | Jev datasource check unavailable; no datasource was searched before the fast answer | Same as `query-route-fallback` |
233
+ | `query-routed` / `datasources-selected` / `follow-up-skipped` | Info: Jev's branch and queries / datasources searched and skipped / fast answer judged final | None; working as intended. A datasource that is never selected usually needs a clearer `description` in the config |
220
234
 
221
235
  ## Report
222
236