@autorag/librarian 2.0.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 (110) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +275 -0
  3. package/dist/agent/agent.d.ts +294 -0
  4. package/dist/agent/bash-tool.d.ts +41 -0
  5. package/dist/agent/datasource-skill.d.ts +45 -0
  6. package/dist/agent/emit-results-tool.d.ts +75 -0
  7. package/dist/agent/index.d.ts +11 -0
  8. package/dist/agent/jikji-find-tool.d.ts +73 -0
  9. package/dist/agent/search-all-tool.d.ts +36 -0
  10. package/dist/agent/search-bm25-tool.d.ts +18 -0
  11. package/dist/agent/search-datasource-tool.d.ts +26 -0
  12. package/dist/agent/search-documents.d.ts +56 -0
  13. package/dist/agent/search-minsync-tool.d.ts +24 -0
  14. package/dist/agent/system-prompt.d.ts +13 -0
  15. package/dist/agent/watch-refresh.d.ts +29 -0
  16. package/dist/cli/commands/feedback.d.ts +8 -0
  17. package/dist/cli/commands/health.d.ts +146 -0
  18. package/dist/cli/commands/index.d.ts +9 -0
  19. package/dist/cli/commands/init.d.ts +9 -0
  20. package/dist/cli/commands/memory.d.ts +8 -0
  21. package/dist/cli/commands/refresh.d.ts +19 -0
  22. package/dist/cli/commands/search.d.ts +34 -0
  23. package/dist/cli/commands/status.d.ts +7 -0
  24. package/dist/cli/commands/types.d.ts +10 -0
  25. package/dist/cli/commands/watch.d.ts +8 -0
  26. package/dist/cli/config.d.ts +172 -0
  27. package/dist/cli/index.d.ts +10 -0
  28. package/dist/cli/index.js +10845 -0
  29. package/dist/cli/output.d.ts +32 -0
  30. package/dist/config/home.d.ts +2 -0
  31. package/dist/datasource/access-context.d.ts +49 -0
  32. package/dist/datasource/diagnostics.d.ts +20 -0
  33. package/dist/datasource/index.d.ts +9 -0
  34. package/dist/datasource/polling.d.ts +51 -0
  35. package/dist/datasource/registry.d.ts +52 -0
  36. package/dist/datasource/result-filter.d.ts +63 -0
  37. package/dist/datasource/scope.d.ts +38 -0
  38. package/dist/datasource/skills/katok/client.d.ts +24 -0
  39. package/dist/datasource/skills/katok/index.d.ts +12 -0
  40. package/dist/datasource/skills/katok/methods.d.ts +40 -0
  41. package/dist/datasource/skills/katok/paths.d.ts +40 -0
  42. package/dist/datasource/skills/katok/skill.d.ts +33 -0
  43. package/dist/datasource/skills/katok/types.d.ts +146 -0
  44. package/dist/datasource/types.d.ts +183 -0
  45. package/dist/filesystem/file-lock.d.ts +16 -0
  46. package/dist/filesystem/source-paths.d.ts +38 -0
  47. package/dist/index.d.ts +11 -0
  48. package/dist/index.js +9361 -0
  49. package/dist/jikji/answer-pack.d.ts +31 -0
  50. package/dist/jikji/client.d.ts +18 -0
  51. package/dist/jikji/diagnostics.d.ts +26 -0
  52. package/dist/jikji/index.d.ts +10 -0
  53. package/dist/jikji/installer.d.ts +46 -0
  54. package/dist/jikji/path-map.d.ts +8 -0
  55. package/dist/jikji/types.d.ts +112 -0
  56. package/dist/manifest/index.d.ts +2 -0
  57. package/dist/manifest/loader.d.ts +3 -0
  58. package/dist/manifest/types.d.ts +8 -0
  59. package/dist/memory/check-memory-tool.d.ts +13 -0
  60. package/dist/memory/index.d.ts +5 -0
  61. package/dist/memory/memory.d.ts +179 -0
  62. package/dist/memory/renderer.d.ts +6 -0
  63. package/dist/minsync/client.d.ts +14 -0
  64. package/dist/minsync/embedder-config.d.ts +22 -0
  65. package/dist/minsync/index.d.ts +7 -0
  66. package/dist/minsync/installer.d.ts +27 -0
  67. package/dist/minsync/method.d.ts +37 -0
  68. package/dist/minsync/paths.d.ts +4 -0
  69. package/dist/minsync/process.d.ts +10 -0
  70. package/dist/minsync/types.d.ts +33 -0
  71. package/dist/minsync/workspace.d.ts +14 -0
  72. package/dist/mirror/index-store.d.ts +16 -0
  73. package/dist/mirror/index.d.ts +5 -0
  74. package/dist/mirror/paths.d.ts +6 -0
  75. package/dist/mirror/sync.d.ts +38 -0
  76. package/dist/observability/run-log.d.ts +53 -0
  77. package/dist/parser/defaults.d.ts +6 -0
  78. package/dist/parser/eml.d.ts +6 -0
  79. package/dist/parser/errors.d.ts +5 -0
  80. package/dist/parser/hwp.d.ts +6 -0
  81. package/dist/parser/index.d.ts +10 -0
  82. package/dist/parser/ocr.d.ts +25 -0
  83. package/dist/parser/office.d.ts +16 -0
  84. package/dist/parser/opendataloader-pdf.d.ts +21 -0
  85. package/dist/parser/plain-text.d.ts +6 -0
  86. package/dist/parser/registry.d.ts +8 -0
  87. package/dist/parser/text.d.ts +2 -0
  88. package/dist/parser/types.d.ts +14 -0
  89. package/dist/parser/xml-text.d.ts +2 -0
  90. package/dist/retrieval/evidence-id.d.ts +16 -0
  91. package/dist/retrieval/index.d.ts +7 -0
  92. package/dist/retrieval/merger.d.ts +18 -0
  93. package/dist/retrieval/methods/bm25.d.ts +52 -0
  94. package/dist/retrieval/registry.d.ts +8 -0
  95. package/dist/retrieval/scope.d.ts +4 -0
  96. package/dist/retrieval/types.d.ts +64 -0
  97. package/dist/subagents/contracts.d.ts +90 -0
  98. package/dist/subagents/dispatch-templates.d.ts +104 -0
  99. package/dist/subagents/dispatch-validation.d.ts +169 -0
  100. package/dist/subagents/explorer-tools-extension.d.ts +4 -0
  101. package/dist/subagents/explorer-tools-extension.js +130 -0
  102. package/dist/subagents/local-models.d.ts +14 -0
  103. package/dist/subagents/model-policy.d.ts +31 -0
  104. package/dist/subagents/runtime.d.ts +52 -0
  105. package/dist/tool/index.d.ts +1 -0
  106. package/dist/types/errors.d.ts +4 -0
  107. package/dist/types/index.d.ts +1 -0
  108. package/package.json +66 -0
  109. package/skills/autorag/SKILL.md +149 -0
  110. package/skills/autorag-setup/SKILL.md +396 -0
@@ -0,0 +1,45 @@
1
+ import type { AgentTool, Skill } from "@earendil-works/pi-agent-core";
2
+ import { Type } from "typebox";
3
+ import type { DatasourceSkillManifest } from "../datasource/types.js";
4
+ export declare const LOAD_DATASOURCE_SKILL_TOOL_NAME = "load_datasource_skill";
5
+ /**
6
+ * Opaque, path-free location used as the Pi `Skill.filePath` for a datasource
7
+ * skill. Datasource skills have no real backing file, and AutoRAG must never
8
+ * expose real filesystem paths, so we use a `datasource://<name>` scheme.
9
+ */
10
+ export declare function datasourceSkillLocation(name: string): string;
11
+ /**
12
+ * Map a datasource skill manifest onto the Pi agent-skill layer. The resulting
13
+ * `Skill` is injected into the system prompt (name/description/location) for
14
+ * progressive disclosure and its `content` is loaded on demand.
15
+ */
16
+ export declare function toDatasourceAgentSkill(manifest: DatasourceSkillManifest): Skill;
17
+ /**
18
+ * Render the Pi `<available_skills>` progressive-disclosure block for the
19
+ * authorized datasource skills using Pi's own formatter, so datasource skills
20
+ * sit on the exact same layer as file-backed agent skills.
21
+ */
22
+ export declare function buildDatasourceSkillsPrompt(skills: readonly Skill[]): string;
23
+ /**
24
+ * Format the full instructions for a loaded datasource skill, matching Pi's
25
+ * `<skill …>` invocation shape but with a path-opaque location (no real
26
+ * filesystem reference, so no "references are relative to …" line).
27
+ */
28
+ export declare function formatDatasourceSkillInvocation(skill: Skill): string;
29
+ export interface LoadDatasourceSkillDetails {
30
+ readonly skill: string;
31
+ readonly loaded: boolean;
32
+ }
33
+ export interface DatasourceSkillProvider {
34
+ /**
35
+ * Resolve an authorized datasource skill by model-visible name. Returns
36
+ * `undefined` when the name is unknown or not authorized by the trusted,
37
+ * server-bound access context (default-deny).
38
+ */
39
+ loadDatasourceSkill(name: string): Skill | undefined;
40
+ }
41
+ declare const loadDatasourceSkillSchema: Type.TObject<{
42
+ name: Type.TString;
43
+ }>;
44
+ export declare function createLoadDatasourceSkillTool(provider: DatasourceSkillProvider): AgentTool<typeof loadDatasourceSkillSchema, LoadDatasourceSkillDetails>;
45
+ export {};
@@ -0,0 +1,75 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
+ import { Type } from "typebox";
3
+ export declare const EMIT_AUTORAG_RESULTS_TOOL_NAME = "emit_autorag_results";
4
+ declare const emitResultsSchema: Type.TObject<{
5
+ answer: Type.TString;
6
+ results: Type.TArray<Type.TObject<{
7
+ number: Type.TInteger;
8
+ title: Type.TString;
9
+ summary: Type.TString;
10
+ evidence: Type.TArray<Type.TObject<{
11
+ excerpt: Type.TString;
12
+ lineNumber: Type.TOptional<Type.TInteger>;
13
+ }>>;
14
+ confidence: Type.TNumber;
15
+ }>>;
16
+ mapping: Type.TArray<Type.TObject<{
17
+ number: Type.TInteger;
18
+ source: Type.TString;
19
+ method: Type.TString;
20
+ content: Type.TString;
21
+ evidenceRefs: Type.TOptional<Type.TArray<Type.TObject<{
22
+ method: Type.TString;
23
+ source: Type.TString;
24
+ excerpt: Type.TOptional<Type.TString>;
25
+ content: Type.TOptional<Type.TString>;
26
+ retrievalResultId: Type.TOptional<Type.TString>;
27
+ chunkIndex: Type.TOptional<Type.TInteger>;
28
+ lineNumber: Type.TOptional<Type.TInteger>;
29
+ stableEvidenceId: Type.TOptional<Type.TString>;
30
+ }>>>;
31
+ }>>;
32
+ warnings: Type.TOptional<Type.TArray<Type.TString>>;
33
+ }>;
34
+ export interface AutoRAGEmittedEvidence {
35
+ readonly excerpt: string;
36
+ readonly lineNumber?: number;
37
+ }
38
+ export interface AutoRAGEmittedResult {
39
+ readonly number: number;
40
+ readonly title: string;
41
+ readonly summary: string;
42
+ readonly evidence: readonly AutoRAGEmittedEvidence[];
43
+ readonly confidence: number;
44
+ }
45
+ export interface AutoRAGEvidenceRef {
46
+ readonly method: string;
47
+ readonly source: string;
48
+ readonly excerpt?: string;
49
+ readonly content?: string;
50
+ readonly retrievalResultId?: string;
51
+ readonly chunkIndex?: number;
52
+ readonly lineNumber?: number;
53
+ readonly stableEvidenceId?: string;
54
+ }
55
+ export interface AutoRAGMappingEntry {
56
+ readonly number: number;
57
+ readonly source: string;
58
+ readonly method: string;
59
+ readonly content: string;
60
+ readonly evidenceRefs: readonly AutoRAGEvidenceRef[];
61
+ }
62
+ export interface AutoRAGResultsDetails {
63
+ readonly answer: string;
64
+ readonly results: readonly AutoRAGEmittedResult[];
65
+ readonly mapping: readonly AutoRAGMappingEntry[];
66
+ readonly warnings: readonly string[];
67
+ }
68
+ /**
69
+ * Builds the terminating structured-result tool. The model calls this exactly
70
+ * once as its final action; the typed `details` plus `terminate: true` end the
71
+ * Pi Agent run and hand the curated results back through `capture` — no
72
+ * assistant-text parsing involved.
73
+ */
74
+ export declare function createEmitResultsTool(capture: (details: AutoRAGResultsDetails) => void): AgentTool<typeof emitResultsSchema, AutoRAGResultsDetails>;
75
+ export {};
@@ -0,0 +1,11 @@
1
+ export type { AutoRAGAgentOptions, AutoRefreshOptions } from "./agent.js";
2
+ export { AutoRAGAgent } from "./agent.js";
3
+ export { buildDatasourceSkillsPrompt, createLoadDatasourceSkillTool, type DatasourceSkillProvider, datasourceSkillLocation, formatDatasourceSkillInvocation, LOAD_DATASOURCE_SKILL_TOOL_NAME, type LoadDatasourceSkillDetails, toDatasourceAgentSkill, } from "./datasource-skill.js";
4
+ export type { AutoRAGEmittedResult, AutoRAGMappingEntry, AutoRAGResultsDetails, } from "./emit-results-tool.js";
5
+ export { createEmitResultsTool, EMIT_AUTORAG_RESULTS_TOOL_NAME } from "./emit-results-tool.js";
6
+ export { createJikjiFindTool, JIKJI_FIND_TOOL_NAME, type JikjiFindDetails, type JikjiFindPerRootPolicy, type JikjiFindProvider, type JikjiFindProviderResult, type MergedJikjiPolicy, } from "./jikji-find-tool.js";
7
+ export { createSearchAllDocumentsTool, SEARCH_ALL_DOCUMENTS_TOOL_NAME, type SearchAllDocumentsDetails, type SearchAllDocumentsProvider, type SearchAllDocumentsResult, } from "./search-all-tool.js";
8
+ export { createSearchDatasourceDocumentsTool, type DatasourceSearchProvider, SEARCH_DATASOURCE_DOCUMENTS_TOOL_NAME, type SearchDatasourceDocumentsDetails, } from "./search-datasource-tool.js";
9
+ export type { SearchDocumentDiagnostic, SearchDocumentDiagnosticCode, SearchDocumentDiagnosticSeverity, SearchDocumentEvidence, SearchDocumentResult, SearchDocumentsResponse, SearchDocumentWarning, } from "./search-documents.js";
10
+ export { createSearchMinSyncDocumentsTool, SEARCH_MINSYNC_DOCUMENTS_TOOL_NAME, type SearchMinSyncDocumentsDetails, } from "./search-minsync-tool.js";
11
+ export { buildSystemPrompt, type SystemPromptConfig } from "./system-prompt.js";
@@ -0,0 +1,73 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
+ import { Type } from "typebox";
3
+ import type { JikjiAnswerPack, JikjiCandidate, JikjiDiagnostic, JikjiEvidence, JikjiHandoffAction } from "../jikji/index.js";
4
+ export declare const JIKJI_FIND_TOOL_NAME = "jikji_find";
5
+ /**
6
+ * Run-scoped merged policy assembled from per-root Jikji answer packs using
7
+ * least-privilege (restrictive-wins) semantics. Set on the agent after each
8
+ * `findJikji` call and consumed by the bash gate.
9
+ */
10
+ export interface MergedJikjiPolicy {
11
+ readonly handoffAction: JikjiHandoffAction;
12
+ readonly stopAfterFind: boolean;
13
+ readonly forbiddenTools: readonly string[];
14
+ readonly allowedFollowups: readonly string[];
15
+ readonly agentShouldNotRerank: boolean;
16
+ readonly rawFallbackAllowed: boolean;
17
+ }
18
+ /**
19
+ * Per-root policy summary for one successful (ok) root, captured BEFORE the
20
+ * least-privilege merge. `root` is the configured search path string.
21
+ */
22
+ export interface JikjiFindPerRootPolicy {
23
+ readonly root: string;
24
+ readonly handoffAction: JikjiHandoffAction;
25
+ readonly stopAfterFind: boolean;
26
+ readonly forbiddenTools: readonly string[];
27
+ readonly allowedFollowups: readonly string[];
28
+ readonly agentShouldNotRerank: boolean;
29
+ }
30
+ /** Result returned by the agent's `findJikji` provider method. */
31
+ export interface JikjiFindProviderResult {
32
+ /** Merged answer pack with normalized paths, or undefined when unavailable. */
33
+ readonly answerPack: JikjiAnswerPack | undefined;
34
+ /** Merged policy, or undefined when jikji is unavailable (bash allowed). */
35
+ readonly policy: MergedJikjiPolicy | undefined;
36
+ readonly diagnostics: readonly JikjiDiagnostic[];
37
+ /** Search roots that were queried. */
38
+ readonly roots: readonly string[];
39
+ /** Per-root policy summaries for ok roots, before the merge. */
40
+ readonly perRoot: readonly JikjiFindPerRootPolicy[];
41
+ }
42
+ export interface JikjiFindProvider {
43
+ findJikji(query: string, opts?: {
44
+ readonly topK?: number;
45
+ readonly first?: boolean;
46
+ }): Promise<JikjiFindProviderResult>;
47
+ }
48
+ export interface JikjiFindDetails {
49
+ readonly method: "jikji_find";
50
+ readonly answerCount: number;
51
+ readonly handoffAction: JikjiHandoffAction | undefined;
52
+ readonly stopAfterFind: boolean | undefined;
53
+ readonly rawFallbackAllowed: boolean | undefined;
54
+ readonly sources: readonly string[];
55
+ readonly candidates: readonly JikjiCandidate[];
56
+ readonly evidencePack: readonly JikjiEvidence[];
57
+ readonly forbiddenTools: readonly string[];
58
+ readonly allowedFollowups: readonly string[];
59
+ readonly perRoot: readonly JikjiFindPerRootPolicy[];
60
+ }
61
+ declare const jikjiFindSchema: Type.TObject<{
62
+ query: Type.TString;
63
+ topK: Type.TOptional<Type.TInteger>;
64
+ first: Type.TOptional<Type.TBoolean>;
65
+ }>;
66
+ /**
67
+ * LLM-facing tool that calls Jikji `find` for local file discovery. The schema
68
+ * is model-safe and exposes no root paths: `{ query, topK?, first? }`. When
69
+ * Jikji is unavailable or all roots failed, the tool returns a short fallback
70
+ * message so the agent falls back to bash, and no policy is set.
71
+ */
72
+ export declare function createJikjiFindTool(provider: JikjiFindProvider): AgentTool<typeof jikjiFindSchema, JikjiFindDetails>;
73
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
+ import { Type } from "typebox";
3
+ import type { RetrievalDiagnostic, RetrievalResult } from "../retrieval/types.js";
4
+ export declare const SEARCH_ALL_DOCUMENTS_TOOL_NAME = "search_all_documents";
5
+ declare const searchAllSchema: Type.TObject<{
6
+ query: Type.TString;
7
+ topK: Type.TOptional<Type.TInteger>;
8
+ scope: Type.TOptional<Type.TString>;
9
+ }>;
10
+ export interface SearchAllDocumentsResult {
11
+ readonly results: readonly RetrievalResult[];
12
+ readonly diagnostics: readonly RetrievalDiagnostic[];
13
+ readonly perMethodCounts?: Readonly<Record<string, number>>;
14
+ }
15
+ export interface SearchAllDocumentsProvider {
16
+ searchAllDocuments(query: string, options?: {
17
+ readonly topK?: number;
18
+ readonly scope?: string;
19
+ }): Promise<SearchAllDocumentsResult>;
20
+ }
21
+ export interface SearchAllDocumentsDetails {
22
+ readonly method: "search_all_documents";
23
+ readonly resultCount: number;
24
+ readonly sources: readonly string[];
25
+ readonly diagnostics: readonly RetrievalDiagnostic[];
26
+ readonly perMethodCounts?: Readonly<Record<string, number>>;
27
+ }
28
+ /**
29
+ * LLM-facing wrapper around multi-method merged retrieval. The
30
+ * schema accepts only `{ query, topK?, scope? }`; datasource trust fields such
31
+ * as `allowedTags`/`allowedScopes` are not part of the schema and are never
32
+ * forwarded to the provider — only `query`, `topK`, and `scope` are passed
33
+ * through, so model-provided extra properties cannot widen datasource access.
34
+ */
35
+ export declare function createSearchAllDocumentsTool(provider: SearchAllDocumentsProvider): AgentTool<typeof searchAllSchema, SearchAllDocumentsDetails>;
36
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
+ import { Type } from "typebox";
3
+ import type { BM25Method, BM25Status } from "../retrieval/methods/bm25.js";
4
+ export declare const SEARCH_BM25_DOCUMENTS_TOOL_NAME = "search_bm25_documents";
5
+ declare const searchBM25Schema: Type.TObject<{
6
+ query: Type.TString;
7
+ topK: Type.TOptional<Type.TInteger>;
8
+ scope: Type.TOptional<Type.TString>;
9
+ }>;
10
+ export interface SearchBM25DocumentsDetails {
11
+ readonly method: "bm25";
12
+ readonly resultCount: number;
13
+ readonly sources: readonly string[];
14
+ readonly readiness: BM25Status["readiness"];
15
+ readonly engine: BM25Status["engine"];
16
+ }
17
+ export declare function createSearchBM25DocumentsTool(getMethod: () => BM25Method | undefined): AgentTool<typeof searchBM25Schema, SearchBM25DocumentsDetails>;
18
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
+ import { Type } from "typebox";
3
+ import type { RetrievalDiagnostic, RetrievalResult } from "../retrieval/types.js";
4
+ export declare const SEARCH_DATASOURCE_DOCUMENTS_TOOL_NAME = "search_datasource_documents";
5
+ declare const searchDatasourceSchema: Type.TObject<{
6
+ query: Type.TString;
7
+ topK: Type.TOptional<Type.TInteger>;
8
+ scope: Type.TOptional<Type.TString>;
9
+ }>;
10
+ export interface SearchDatasourceDocumentsDetails {
11
+ readonly method: "datasource";
12
+ readonly resultCount: number;
13
+ readonly sources: readonly string[];
14
+ readonly diagnostics: readonly RetrievalDiagnostic[];
15
+ }
16
+ export interface DatasourceSearchProvider {
17
+ searchDatasourceDocuments(query: string, options?: {
18
+ readonly topK?: number;
19
+ readonly scope?: string;
20
+ }): Promise<{
21
+ readonly results: readonly RetrievalResult[];
22
+ readonly diagnostics: readonly RetrievalDiagnostic[];
23
+ }>;
24
+ }
25
+ export declare function createSearchDatasourceDocumentsTool(provider: DatasourceSearchProvider): AgentTool<typeof searchDatasourceSchema, SearchDatasourceDocumentsDetails>;
26
+ export {};
@@ -0,0 +1,56 @@
1
+ import { type RetrievalMemory } from "../memory/memory.js";
2
+ import type { CuratedResult } from "../retrieval/types.js";
3
+ import type { AutoRAGResultsDetails } from "./emit-results-tool.js";
4
+ export type SearchDocumentWarning = "empty-query";
5
+ export type SearchDocumentDiagnosticSeverity = "info" | "warning" | "error";
6
+ /**
7
+ * Stable diagnostic codes surfaced through the public search
8
+ * response. The union is intentionally broad so later degraded-mode wiring
9
+ * (#21/#22) does not require another source-breaking type change; codes not yet
10
+ * emitted are still valid members.
11
+ */
12
+ export type SearchDocumentDiagnosticCode = "empty-query" | "unknown-warning" | "caller-tool-dropped" | "bm25-unavailable" | "bm25-degraded-fallback" | "minsync-unavailable" | "parser-skipped" | "parser-failed" | "unsupported-file" | "stale-index" | "deleted-mirror" | "retrieval-method-failed" | "jikji-unavailable" | "jikji-prepare-failed" | "jikji-find-failed" | "refresh-failed" | "watch-failed" | "watch-limited";
13
+ export interface SearchDocumentDiagnostic {
14
+ readonly code: SearchDocumentDiagnosticCode;
15
+ readonly severity: SearchDocumentDiagnosticSeverity;
16
+ readonly message: string;
17
+ /** Component label (e.g. "sanitizer", "bm25") or opaque virtual path — never a real filesystem path. */
18
+ readonly source?: string;
19
+ }
20
+ export interface SearchDocumentEvidence {
21
+ readonly excerpt: string;
22
+ readonly lineNumber?: number;
23
+ }
24
+ export interface SearchDocumentResult {
25
+ readonly number: number;
26
+ readonly title: string;
27
+ readonly summary: string;
28
+ readonly evidence: readonly SearchDocumentEvidence[];
29
+ readonly confidence: number;
30
+ readonly feedbackId: string;
31
+ }
32
+ export interface SearchDocumentsResponse {
33
+ readonly sessionId: string;
34
+ readonly query: string;
35
+ readonly results: readonly SearchDocumentResult[];
36
+ readonly answer: string;
37
+ readonly searched: number;
38
+ readonly warnings: readonly SearchDocumentWarning[];
39
+ /**
40
+ * Structured degraded-mode diagnostics. Typed optional for the compatibility
41
+ * window, but ALWAYS populated at runtime (defaults to an empty array).
42
+ */
43
+ readonly diagnostics?: readonly SearchDocumentDiagnostic[];
44
+ }
45
+ type SearchSessions = Map<string, {
46
+ query: string;
47
+ registry: Map<number, CuratedResult>;
48
+ }>;
49
+ type ReadonlySearchSessions = ReadonlyMap<string, {
50
+ query: string;
51
+ registry: ReadonlyMap<number, CuratedResult>;
52
+ }>;
53
+ export declare function createEmptySearchDocumentsResponse(sessionId: string, query: string, sessions: SearchSessions): SearchDocumentsResponse;
54
+ export declare function recordStructuredResultsSession(sessionId: string, query: string, details: AutoRAGResultsDetails, sessions: SearchSessions, memory: RetrievalMemory, componentDiagnostics?: readonly SearchDocumentDiagnostic[]): SearchDocumentsResponse;
55
+ export declare function recordNumberedFeedback(sessions: ReadonlySearchSessions, memory: RetrievalMemory, sessionId: string, usefulNumbers: readonly number[], notUsefulNumbers: readonly number[]): void;
56
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
+ import { Type } from "typebox";
3
+ import type { MinSyncVectorMethod } from "../minsync/method.js";
4
+ export declare const SEARCH_MINSYNC_DOCUMENTS_TOOL_NAME = "search_minsync_documents";
5
+ declare const searchMinSyncSchema: Type.TObject<{
6
+ query: Type.TString;
7
+ topK: Type.TOptional<Type.TInteger>;
8
+ scope: Type.TOptional<Type.TString>;
9
+ }>;
10
+ export interface SearchMinSyncDocumentsDetails {
11
+ readonly method: "search_minsync_documents";
12
+ readonly resultCount: number;
13
+ readonly sources: readonly string[];
14
+ readonly available: boolean;
15
+ }
16
+ /**
17
+ * LLM-facing wrapper around the {@link MinSyncVectorMethod} vector
18
+ * retrieval. The model can only supply `query`, `topK`, and an opaque `scope`.
19
+ * When the method is missing, the binary is missing, or retrieval errors, the
20
+ * tool returns a path-free unavailable message with `available: false` and a
21
+ * zero result count — never a real binary or workspace path.
22
+ */
23
+ export declare function createSearchMinSyncDocumentsTool(getMethod: () => MinSyncVectorMethod | undefined): AgentTool<typeof searchMinSyncSchema, SearchMinSyncDocumentsDetails>;
24
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { Skill } from "@earendil-works/pi-agent-core";
2
+ import type { StoreManifest } from "../manifest/types.js";
3
+ export interface SystemPromptConfig {
4
+ toolNames: string[];
5
+ orchestratorModelId?: string;
6
+ explorerModelId?: string;
7
+ memorySignalCount?: number;
8
+ memoryEntries?: readonly unknown[];
9
+ manifests: StoreManifest[];
10
+ jikjiIndexingEnabled?: boolean;
11
+ datasourceSkills?: readonly Skill[];
12
+ }
13
+ export declare function buildSystemPrompt(config: SystemPromptConfig): string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Filesystem watch scheduler for incremental refresh. Deliberately dependency-
3
+ * injected (via {@link WatcherFactory}) so it is unit-testable without real
4
+ * filesystem timing, and so the agent can pass a real `fs.watch`-backed factory.
5
+ *
6
+ * Invariants:
7
+ * - Debounced: a burst of change events collapses into one refresh.
8
+ * - Backpressure: at most one refresh in flight plus at most one pending rerun.
9
+ * - Stoppable: after stop() no further refresh is scheduled and every watcher
10
+ * is closed; late events are ignored.
11
+ * - Bounded: never creates more than `maxWatchers` watchers.
12
+ */
13
+ export interface WatchWatcher {
14
+ close(): void;
15
+ }
16
+ export type WatcherFactory = (dir: string, onChange: (filename: string | null) => void) => WatchWatcher;
17
+ export interface WatchRefreshDeps {
18
+ readonly dirs: readonly string[];
19
+ readonly debounceMs: number;
20
+ readonly maxWatchers: number;
21
+ readonly watcherFactory: WatcherFactory;
22
+ readonly runRefresh: () => Promise<void>;
23
+ /** Called once when the number of directories exceeds `maxWatchers`. */
24
+ readonly onLimit?: () => void;
25
+ }
26
+ export interface WatchRefreshHandle {
27
+ stop(): void;
28
+ }
29
+ export declare function createWatchRefresh(deps: WatchRefreshDeps): WatchRefreshHandle;
@@ -0,0 +1,8 @@
1
+ import type { CommandContext } from "./types.js";
2
+ /**
3
+ * Run the `autorag feedback` command. Records per-result useful/not-useful
4
+ * signals against an existing curated-results session. Returns 0 when at least
5
+ * one feedback signal was applied, 2 for usage errors or an unknown session,
6
+ * 1 for runtime/IO errors.
7
+ */
8
+ export declare function runFeedback(ctx: CommandContext): Promise<number>;
@@ -0,0 +1,146 @@
1
+ import type { Api, Model } from "@earendil-works/pi-ai";
2
+ import type { LoadLocalAutoRAGModelsOptions } from "../../subagents/local-models.js";
3
+ import { type CliConfig } from "../config.js";
4
+ import type { CommandContext } from "./types.js";
5
+ export type HealthCategory = "config" | "model_resolution" | "auth_missing" | "provider_unreachable" | "completion_failed" | "subagent_failed" | "timeout" | "ok";
6
+ export type HealthRole = "orchestrator" | "explorer";
7
+ export interface HealthCoverage {
8
+ modelProvider: boolean;
9
+ subagentDispatch: boolean;
10
+ retrievalTools: false;
11
+ searchCuration: false;
12
+ indexHealth: false;
13
+ }
14
+ export interface HealthRoleAuth {
15
+ present: boolean;
16
+ source: "env" | "local_runtime" | "pi_auth" | "catalog" | "none" | "unknown";
17
+ envName?: string;
18
+ }
19
+ export interface HealthRoleReport {
20
+ role: HealthRole;
21
+ provider: string;
22
+ modelId: string;
23
+ displayName?: string;
24
+ api: string;
25
+ routeFamily?: string;
26
+ baseUrl?: string;
27
+ contextWindow?: number;
28
+ maxTokens?: number;
29
+ capabilities: {
30
+ text: boolean;
31
+ image: boolean;
32
+ reasoning?: boolean;
33
+ };
34
+ auth: HealthRoleAuth;
35
+ resolutionSource: "config" | "flags" | "env" | "local_runtime" | "catalog" | "configured_alias" | "mixed";
36
+ }
37
+ export interface HealthProbeReport {
38
+ role: HealthRole;
39
+ skipped: boolean;
40
+ ok: boolean;
41
+ category: HealthCategory;
42
+ durationMs?: number;
43
+ message?: string;
44
+ }
45
+ export interface HealthConfigReport {
46
+ ok: boolean;
47
+ source: "explicit" | "home" | "legacy" | "defaults";
48
+ message?: string;
49
+ }
50
+ export interface HealthReportV1 {
51
+ healthSchemaVersion: 1;
52
+ ok: boolean;
53
+ category: HealthCategory;
54
+ command: "health";
55
+ probesSkipped: boolean;
56
+ coverage: HealthCoverage;
57
+ config: HealthConfigReport;
58
+ models: {
59
+ orchestrator?: HealthRoleReport;
60
+ explorer?: HealthRoleReport;
61
+ };
62
+ probes: {
63
+ orchestrator?: HealthProbeReport;
64
+ explorer?: HealthProbeReport;
65
+ };
66
+ indexHealth: {
67
+ separate: true;
68
+ command: "autorag status";
69
+ included: false;
70
+ };
71
+ }
72
+ /**
73
+ * Probe input passed to injected orchestrator/explorer probes. Credential
74
+ * values are present for the probe to use but must never be surfaced in
75
+ * rendered output.
76
+ */
77
+ export interface ProbeInput {
78
+ role: HealthRole;
79
+ model: Model<Api>;
80
+ apiKey?: string;
81
+ providerApiKeys?: Readonly<Record<string, string>>;
82
+ timeoutMs: number;
83
+ cwd: string;
84
+ }
85
+ /**
86
+ * Probe outcome returned by injected probes. `category` is the per-role
87
+ * health category; `message` is already sanitized (no secrets/paths/stacks).
88
+ */
89
+ export interface ProbeOutput {
90
+ ok: boolean;
91
+ category: HealthCategory;
92
+ message?: string;
93
+ }
94
+ /**
95
+ * Detailed role metadata produced by the model resolver. The default
96
+ * adapter derives this from {@link resolveAgentModel}; when config exports a
97
+ * dedicated `resolveAgentModelDetailed`, the health command prefers it.
98
+ */
99
+ export interface ResolvedHealthRole {
100
+ readonly provider: string;
101
+ readonly modelId: string;
102
+ readonly displayName?: string;
103
+ readonly api: Api;
104
+ readonly baseUrl?: string;
105
+ readonly contextWindow?: number;
106
+ readonly maxTokens?: number;
107
+ readonly capabilities: {
108
+ input: readonly string[];
109
+ reasoning: boolean;
110
+ };
111
+ readonly auth: {
112
+ present: boolean;
113
+ source: "env" | "local_runtime" | "pi_auth" | "catalog" | "none" | "unknown";
114
+ envName?: string;
115
+ };
116
+ readonly resolutionSource: "config" | "flags" | "env" | "local_runtime" | "catalog" | "configured_alias" | "mixed";
117
+ }
118
+ export interface ResolvedHealthModel {
119
+ readonly model: Model<Api>;
120
+ readonly explorerModel: Model<Api>;
121
+ readonly apiKey?: string;
122
+ readonly providerApiKeys?: Readonly<Record<string, string>>;
123
+ readonly roles: {
124
+ orchestrator: ResolvedHealthRole;
125
+ explorer: ResolvedHealthRole;
126
+ };
127
+ }
128
+ export interface HealthDeps {
129
+ configResolver?: (input: {
130
+ flags: Record<string, string | boolean | undefined>;
131
+ cwd?: string;
132
+ env?: NodeJS.ProcessEnv;
133
+ }) => CliConfig;
134
+ modelResolver?: (config: CliConfig, localOptions?: LoadLocalAutoRAGModelsOptions) => ResolvedHealthModel;
135
+ orchestratorProbe?: (input: ProbeInput, signal: AbortSignal) => Promise<ProbeOutput>;
136
+ explorerProbe?: (input: ProbeInput, signal: AbortSignal) => Promise<ProbeOutput>;
137
+ now?: () => number;
138
+ }
139
+ /**
140
+ * Run the `autorag health` command. Returns an exit code and writes the
141
+ * rendered health report to `ctx.stdout` (or an error to `ctx.stderr`).
142
+ *
143
+ * All network/runtime behavior is injectable via `deps`; unit tests inject
144
+ * fake resolvers/probes and never touch live networks.
145
+ */
146
+ export declare function runHealth(ctx: CommandContext, deps?: HealthDeps): Promise<number>;
@@ -0,0 +1,9 @@
1
+ import type { CommandContext } from "./types.js";
2
+ /**
3
+ * Run the `autorag index` command. `reset` removes the parsed mirror, BM25,
4
+ * and MinSync index directories under `.autorag` (preserving `bin`,
5
+ * `datasources`, and the memory file). `rebuild` resets then re-runs a forced
6
+ * refresh. Returns 0 on success, 2 for usage/decline errors, 1 for runtime
7
+ * errors including path-escape guard violations.
8
+ */
9
+ export declare function runIndex(ctx: CommandContext): Promise<number>;
@@ -0,0 +1,9 @@
1
+ import type { CommandContext } from "./types.js";
2
+ /**
3
+ * `autorag init` writes the default config to `~/.autorag/config.json`.
4
+ * Role-specific model flags are folded into the generated config. A legacy
5
+ * `autorag.config.json` in the current working directory may be migrated
6
+ * non-destructively. An existing home config is not overwritten without
7
+ * `--force`.
8
+ */
9
+ export declare function runInit(ctx: CommandContext): Promise<number>;
@@ -0,0 +1,8 @@
1
+ import type { CommandContext } from "./types.js";
2
+ /**
3
+ * `autorag memory inspect` — render a path-opaque snapshot of the retrieval
4
+ * memory (curated results, feedback signals, insights, signal defaults).
5
+ * Model-free. The memory file is resolved from config and loaded read-only;
6
+ * only the rendered schema is emitted, never the storage path.
7
+ */
8
+ export declare function runMemory(ctx: CommandContext): Promise<number>;
@@ -0,0 +1,19 @@
1
+ import { type RefreshMethod } from "../../agent/agent.js";
2
+ import type { CommandContext } from "./types.js";
3
+ /**
4
+ * `autorag refresh` — parse configured search paths and resync every active
5
+ * index (parsed mirror, BM25, MinSync, datasources, jikji). Model-free: no LLM
6
+ * is constructed. Output is rendered through the path-opaque refresh renderer;
7
+ * the raw result (which carries absolute `indexPath`) is never printed.
8
+ *
9
+ * `--method bm25,minsync,parsed` restricts which methods run. When omitted, all
10
+ * methods run. Parsed mirrors are always synced when BM25 or MinSync is selected
11
+ * (they index over the parsed mirrors).
12
+ */
13
+ export declare function runRefresh(ctx: CommandContext): Promise<number>;
14
+ /**
15
+ * Parse a `--method` CSV flag into a sorted set of `RefreshMethod` values.
16
+ * Returns `undefined` when the flag is missing (meaning "all methods").
17
+ * `all` expands to every method. Unknown values throw.
18
+ */
19
+ export declare function parseMethodFlag(flag: string | boolean | undefined): readonly RefreshMethod[] | undefined;
@@ -0,0 +1,34 @@
1
+ import { AutoRAGAgent, type AutoRAGAgentOptions } from "../../agent/agent.js";
2
+ import { type CliConfig, type ResolvedAgentModel } from "../config.js";
3
+ import type { CommandContext } from "./types.js";
4
+ /**
5
+ * A recoverable health hint surfaced when `autorag search` fails for a reason
6
+ * that `autorag health` can diagnose. The classifier only produces hints for
7
+ * model/provider/subagent failures — never for retrieval, index, datasource,
8
+ * or empty-query errors.
9
+ */
10
+ export interface SearchHealthHint {
11
+ command: "autorag health";
12
+ reason: "model_resolution" | "subagent_failed" | "auth_missing" | "provider_unreachable" | "timeout";
13
+ message: string;
14
+ }
15
+ /**
16
+ * Classify a search error into an optional {@link SearchHealthHint}.
17
+ * Returns `undefined` for errors outside the allowlist (empty query,
18
+ * retrieval/index/datasource failures, generic errors).
19
+ */
20
+ export declare function classifySearchHealthHint(error: unknown): SearchHealthHint | undefined;
21
+ /**
22
+ * Search-command dependencies. Tests inject `agentFactory` to bypass real
23
+ * model construction and AutoRAGAgent instantiation, returning a stub whose
24
+ * `searchDocuments` resolves a canned {@link SearchDocumentsResponse}.
25
+ */
26
+ export interface SearchDeps {
27
+ agentFactory?: (opts: AutoRAGAgentOptions) => Pick<AutoRAGAgent, "searchDocuments">;
28
+ modelResolver?: (config: CliConfig) => ResolvedAgentModel;
29
+ }
30
+ /**
31
+ * Run the `autorag search` command. Returns exit code 0 on success, 2 for
32
+ * usage/config errors (empty query, missing model), 1 for runtime errors.
33
+ */
34
+ export declare function runSearch(ctx: CommandContext, deps?: SearchDeps): Promise<number>;