@autorag/librarian 2.12.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 (43) hide show
  1. package/README.md +8 -3
  2. package/dist/agent/agent.d.ts +84 -44
  3. package/dist/agent/answer-guidelines.d.ts +18 -1
  4. package/dist/agent/current-date.d.ts +10 -0
  5. package/dist/agent/datasource-skill.d.ts +2 -2
  6. package/dist/agent/environment-prompt.d.ts +20 -0
  7. package/dist/agent/evidence-ledger.d.ts +4 -2
  8. package/dist/agent/location-claims.d.ts +14 -0
  9. package/dist/agent/packaged-skill.d.ts +19 -0
  10. package/dist/agent/query-routing.d.ts +80 -26
  11. package/dist/agent/results.d.ts +10 -2
  12. package/dist/agent/search-documents.d.ts +6 -1
  13. package/dist/agent/self-config.d.ts +4 -4
  14. package/dist/agent/skill-invocation.d.ts +17 -0
  15. package/dist/agent/user-requests.d.ts +2 -2
  16. package/dist/cli/commands/evidence.d.ts +2 -0
  17. package/dist/cli/index.js +10572 -9994
  18. package/dist/cli/setup.d.ts +2 -0
  19. package/dist/core.js +21531 -21024
  20. package/dist/datasource/crawler-skill.d.ts +1 -0
  21. package/dist/datasource/index.d.ts +1 -1
  22. package/dist/datasource/sidecar/methods.d.ts +8 -1
  23. package/dist/datasource/skills/clawgallery/skill.d.ts +4 -0
  24. package/dist/datasource/skills/discrawl/skill.d.ts +5 -0
  25. package/dist/datasource/skills/factory.d.ts +5 -1
  26. package/dist/datasource/skills/lazykatok/index.d.ts +1 -1
  27. package/dist/datasource/skills/lazykatok/methods.d.ts +5 -5
  28. package/dist/datasource/skills/lazykatok/skill.d.ts +1 -0
  29. package/dist/datasource/skills/mailcrawl/skill.d.ts +1 -0
  30. package/dist/index.js +21621 -21063
  31. package/dist/mcp/index.js +21618 -21061
  32. package/dist/memory/memory.d.ts +4 -1
  33. package/dist/mirror/atomic-write.d.ts +16 -1
  34. package/dist/mirror/sync.d.ts +2 -0
  35. package/dist/profiles.js +11311 -10804
  36. package/dist/retrieval/chunk-location.d.ts +28 -0
  37. package/dist/retrieval/fallback.d.ts +24 -0
  38. package/dist/retrieval/index.d.ts +1 -0
  39. package/dist/retrieval/types.d.ts +16 -0
  40. package/internal-skills/organize/SKILL.md +43 -0
  41. package/package.json +2 -1
  42. package/skills/autorag/SKILL.md +18 -7
  43. package/skills/autorag-setup/SKILL.md +7 -5
package/README.md CHANGED
@@ -461,7 +461,9 @@ mirrored are kept and not re-parsed on the next run. `onProgress` reports `parse
461
461
  (`processed`/`total` are files, `currentVirtualPath` is the file about to be processed) and
462
462
  `datasources` (`processed`/`total` are datasource skills). During the parse phase
463
463
  `.autorag/refresh-progress.json` also carries the running `sourceFiles.total` and
464
- `parsedCounts`. Without these options a refresh behaves as before.
464
+ `parsedCounts`, refreshed every 25 files rather than per file. The marker is replaced with a
465
+ retried rename (an in-place overwrite if a reader keeps the destination held, as on Windows).
466
+ Without these options a refresh behaves as before.
465
467
 
466
468
  ---
467
469
 
@@ -601,7 +603,10 @@ and `skills/autorag-setup` only when the agent should also drive the
601
603
  model-backed librarian, and `skills/autorag-doctor` for diagnostics. Other
602
604
  agents read their own skill directories; copy the same setup folder there and
603
605
  reload the agent session so it picks up the MCP registration instructions.
604
- Do not copy or retain the removed `autorag-lite-search` skill.
606
+ Do not copy or retain the removed `autorag-lite-search` skill. The package also
607
+ ships `internal-skills/`, which holds the librarian's own turn rules (for
608
+ example `internal-skills/organize/`) — those are never parent-agent skills, so
609
+ do not copy them into another agent.
605
610
 
606
611
  ### Quick Agent Workflow
607
612
 
@@ -730,7 +735,7 @@ Deep dive into AutoRAG Agent's architecture, security, and integration guides:
730
735
  - **[Telegram Remote Control](docs/telegram.md):** Ask the librarian from a Telegram chat through a running `autorag tui --telegram` session: setup, commands, and keeping it alive.
731
736
  - **[Datasource Skills Reference](docs/datasource-skills.md):** Full configuration contracts, connection aliases, and connector options.
732
737
  - **[Apple Calendar & Reminders via EventKit MCP](docs/eventkit-mcp.md):** macOS-only: read Calendar events and Reminders (Google/iCloud/Exchange accounts already in Calendar.app) by running `mcp-server-apple-events` beside `autorag-mcp`. Live, read-only; not indexed.
733
- - **[Jev Decisions](docs/jev-decisions.md):** Jev query pipeline, **on by default** via Dazzi Models when signed in (OpenRouter otherwise): it routes each question to a direct answer (intrinsic knowledge), local search (everything needing more information; web search is left to the agent after the fast answer), `organize` (move, rename, convert, or sort files and folders), or `extra` (any other action such as committing code; no retrieval), splits multi-part questions into up to five parallel searches (`dazzi/openai/gpt-6-luna` when signed in, else `openrouter/qwen/qwen3.7-flash`), picks which registered datasources to search before the fast answer, and ends the run after the fast answer when that answer is complete. Also covers the `jev` judgment tool, backends (OpenRouter, TypeSafe, Vercel AI Gateway), and how to opt out.
738
+ - **[Jev Decisions](docs/jev-decisions.md):** Jev query pipeline, **on by default** via Dazzi Models when signed in (OpenRouter otherwise): it routes each question to local search (everything needing more information, including the public web when the question needs recent public facts), `extra` (a knowledge answer or any other action such as committing code; one turn with every tool, no retrieval), `organize` (move, rename, convert, or sort files and folders), or its own `config` branch, and keeps a weakly-favored non-local verdict on local search through a 0.75 confidence floor. It also splits multi-part questions into up to five parallel searches (`dazzi/openai/gpt-6-luna` when signed in, else `openrouter/qwen/qwen3.7-flash`), picks which registered datasources to search before the fast answer, and ends the run after the fast answer when that answer is complete. Also covers the `jev` judgment tool, backends (OpenRouter, TypeSafe, Vercel AI Gateway), and how to opt out.
734
739
  - **[Manual QA & Datasource Test Harnesses](docs/manual-qa-datasources.md):** Real-world testing guides for Discord, KakaoTalk, Slack, Notion, and email.
735
740
  - **[Supply Chain Security & License Audits](docs/supply-chain.md):** Software bill of materials (SBOM) and dependency gate policies.
736
741
  - **[Competitive Landscape Study](docs/competitive-landscape-2026-09.md):** In-depth analysis of why in-place federation outperforms centralized RAG.
@@ -21,6 +21,7 @@ import { type DatasourceAgentSkill } from "./datasource-skill.js";
21
21
  import { type ScanDuplicateDocumentsDetails } from "./dupey-tool.js";
22
22
  import { type JevToolOptions } from "./jev-extension.js";
23
23
  import { type JikjiFindProviderResult } from "./jikji-find-tool.js";
24
+ import { type PackagedAgentSkill } from "./packaged-skill.js";
24
25
  import { PermissionController, type PermissionMode } from "./permission-gate.js";
25
26
  import { type AutoRAGPiInteractiveRuntime, type AutoRAGPiSession } from "./pi-session.js";
26
27
  import { type RefreshProgressCounts, type RefreshProgressPhase } from "./refresh-progress.js";
@@ -268,8 +269,9 @@ export interface AutoRAGAgentOptions {
268
269
  /**
269
270
  * Jev (TypeSafe's judgment model: typed questions in, calibrated
270
271
  * probabilities out). When set, the two-phase search asks Jev before the
271
- * fast answer whether the question is answerable from intrinsic knowledge
272
- * (direct answer) or needs local search, and whether to decompose it; after the fast answer, whether
272
+ * fast answer which branch handles the question (local search, file
273
+ * organization, an extra task, or — in a local host — its own configuration)
274
+ * and whether to decompose it; after the fast answer, whether
273
275
  * verification is needed. It also exposes the `jev` tool.
274
276
  *
275
277
  * The CLI config enables this by default on OpenRouter (`buildAgentOptions`
@@ -297,6 +299,12 @@ export interface AutoRAGAgentOptions {
297
299
  * message.
298
300
  */
299
301
  selfConfig?: SelfConfigOptions;
302
+ /**
303
+ * Override for the packaged `organize` skill file that the Jev `organize`
304
+ * branch loads into its turn; defaults to the packaged skill. Present for a
305
+ * host that ships its own organize rules, and for tests.
306
+ */
307
+ organizeSkillPath?: string;
300
308
  /**
301
309
  * Question decomposition used by the Jev query pipeline. `model` (with its
302
310
  * `apiKey`) is the LLM that splits one question into at most five search
@@ -494,6 +502,8 @@ export declare class AutoRAGAgent {
494
502
  private readonly permissionGate;
495
503
  /** Self-configuration, enabled only with Jev on a local session. */
496
504
  private readonly selfConfig;
505
+ /** Override for the packaged organize skill the `organize` branch loads; undefined keeps the packaged one. */
506
+ private readonly organizeSkillPath;
497
507
  private readonly queryDecompositionModel;
498
508
  /** Web search options for the agent's `web_search` / `web_fetch` tools; undefined when web tools are off. */
499
509
  private readonly webSearchOptions;
@@ -716,39 +726,52 @@ export declare class AutoRAGAgent {
716
726
  private shouldFollowUp;
717
727
  /**
718
728
  * Jev query pipeline, run before the fast answer. Jev picks the branch
719
- * (direct answer or local search) and whether the question
720
- * needs decomposition; a "yes" splits it into at most five search queries
721
- * with the configured decomposition model (default: the session model). On
722
- * the local branch, Jev also judges, per registered datasource, whether it
723
- * must be searched (in parallel with decomposition). Without Jev, and on any
724
- * routing failure, this is today's single local search for the original
725
- * question with no datasource search.
729
+ * (local search, file organization, an extra task, AutoRAG configuration)
730
+ * and whether the question needs decomposition; a "yes" splits it into at
731
+ * most five search queries with the configured decomposition model
732
+ * (default: the session model). On the local branch, Jev also judges, per
733
+ * registered datasource, whether it must be searched (in parallel with
734
+ * decomposition). Without Jev, and on any routing failure, this is today's
735
+ * single local search for the original question with no datasource search.
736
+ * A non-local branch that misses the confidence floor is not a failure: it
737
+ * becomes a full local plan, decomposition and datasource check included.
726
738
  */
727
739
  private planQuery;
728
740
  /**
729
741
  * Jev datasource check for the local branch: one `noul` per configured
730
- * datasource that has retrieval methods, with where similar past questions
731
- * were answered (from retrieval memory) in the state. Returns the ids to
732
- * search with every query before the rerank; a failed check searches none.
742
+ * datasource that has retrieval methods, plus the public web when its tools
743
+ * are enabled, with where similar past questions were answered (from
744
+ * retrieval memory) in the state. Returns the datasource ids and whether the
745
+ * web is to be searched with every query before the rerank; a failed check
746
+ * searches neither.
733
747
  */
734
748
  private selectSearchDatasources;
735
749
  /**
736
- * Baseline local evidence for the fast answer. Jikji, MinSync, and every
737
- * Jev-selected datasource run for every search query in parallel (MinSync
738
- * itself queues per workspace), the per-query hits are interleaved and
739
- * deduplicated into one pool, and that pool is reranked against the
740
- * original question.
750
+ * Baseline local evidence for the fast answer. Jikji, MinSync, every
751
+ * Jev-selected datasource, and (when Jev selected it) one web search run for
752
+ * every search query in parallel (MinSync itself queues per workspace), the
753
+ * per-query hits are interleaved and deduplicated into one pool, and that
754
+ * pool is reranked against the original question.
741
755
  */
742
756
  private prefetchInitialRetrievalContext;
757
+ /**
758
+ * One web search for the baseline, on the same provider chain, ordering, and
759
+ * credentials as the `web_search` tool. Hits carry the URL as their source
760
+ * and the title plus snippet as their content, so they merge, rerank, and
761
+ * register like any other candidate. A failure contributes no evidence and
762
+ * is reported by the caller; a steer abort is the user stopping the search,
763
+ * not a failure.
764
+ */
765
+ private prefetchWebSearch;
743
766
  /**
744
767
  * Rerank the pre-fast-answer baseline pool — Jikji answer paths, MinSync
745
- * chunks, and Jev-selected datasource chunks — down to the configured
746
- * `rerank.topN`. With decomposition the pool merges every search query's
747
- * hits (interleaved), capped at the same per-source sizes as a single query
748
- * so the rerank request does not grow with the query count. Returns
749
- * `undefined` when reranking is disabled or the pool is empty. A configured
750
- * reranker that is unavailable, throws, or returns nothing for a non-empty
751
- * pool throws, so the caller can report it and fall back.
768
+ * chunks, Jev-selected datasource chunks, and prefetched web hits — down to
769
+ * the configured `rerank.topN`. With decomposition the pool merges every
770
+ * search query's hits (interleaved), capped at the same per-source sizes as a
771
+ * single query so the rerank request does not grow with the query count.
772
+ * Returns `undefined` when reranking is disabled or the pool is empty. A
773
+ * configured reranker that is unavailable, throws, or returns nothing for a
774
+ * non-empty pool throws, so the caller can report it and fall back.
752
775
  */
753
776
  private rerankPrefetchPool;
754
777
  /**
@@ -763,10 +786,17 @@ export declare class AutoRAGAgent {
763
786
  * not offer the tool.
764
787
  */
765
788
  private askUserException;
789
+ /**
790
+ * Fast-phase exception to the no-tools rule, naming only the web tools this
791
+ * session actually registered. Empty when web tools are off, so the prompt
792
+ * never mentions a tool the model does not have.
793
+ */
794
+ private fastPhaseWebHint;
766
795
  /**
767
796
  * Fast-phase prompt for two-phase searches. The baseline retrieval context
768
797
  * is already gathered, so the model answers immediately with minimal thinking,
769
- * as plain text, without any further tool calls.
798
+ * as plain text, without further retrieval; the web tools are the only
799
+ * exception, for public facts the baseline cannot settle.
770
800
  */
771
801
  buildFastAnswerPrompt(query: string, options: RetrievalOptions, baseline: string): string;
772
802
  /**
@@ -776,35 +806,45 @@ export declare class AutoRAGAgent {
776
806
  */
777
807
  private isConversationTurn;
778
808
  /**
779
- * Prompt for a question Jev routed to a direct answer: general knowledge or
780
- * small talk. No retrieval ran and no verification phase follows, so the
781
- * reply is the final answer.
809
+ * Prompt for a request Jev routed to `organize`: act on files and folders
810
+ * (move, rename, convert, sort). No route changes the active tools any more,
811
+ * so the prompt names the tools the task uses and the ones it must not, and
812
+ * carries the loaded organize skill with the rules. No retrieval ran and no
813
+ * verification follows; the model's plain final message is the answer.
782
814
  */
783
- buildDirectAnswerPrompt(query: string): string;
815
+ buildOrganizePrompt(query: string, skill: PackagedAgentSkill): string;
784
816
  /**
785
- * Tools an `organize` turn keeps: pi's file tools plus the converter, the
786
- * duplicate scan, and file-name discovery, whichever this agent registered.
787
- * The retrieval, datasource, and web tools stay out: the turn acts on files.
817
+ * The tool-scope sentence of an `organize` turn: the tools the task uses and
818
+ * the content-retrieval and web tools it must not call. Every route keeps the
819
+ * whole tool set now, so the prompt is what scopes the turn; both lists name
820
+ * only tools this agent actually registered, so the prompt never points the
821
+ * model at a tool the session does not have.
788
822
  */
789
- private organizeToolNames;
823
+ private organizeToolScope;
790
824
  /**
791
- * Prompt for a request Jev routed to `organize`: act on files and folders
792
- * (move, rename, convert, sort). No retrieval ran and no verification
793
- * follows; the model's plain final message is the answer.
825
+ * Prompt for a request Jev routed to `extra`: no branch had a confident
826
+ * non-local verdict, and handling it needs no search of the user's records
827
+ * first. Nothing was retrieved and nothing follows this turn — no fast
828
+ * answer, follow-up check, or verification — so the single tool-capable
829
+ * turn either answers the question or carries the task out. No tool is
830
+ * forbidden: the model looks facts up itself when they are not its own.
794
831
  */
795
- buildOrganizePrompt(query: string): string;
832
+ buildExtraPrompt(query: string): string;
796
833
  /**
797
- * Prompt for a request Jev routed to `extra`: a task that is neither
798
- * knowledge, the user's records, file organization, nor configuration.
799
- * The model acts with every tool it has; there is no retrieval or verification phase.
834
+ * One tool-capable turn for an action route (`organize`, `extra`): the model
835
+ * carries the request out with the tools it has and reports through its plain
836
+ * final message. No retrieval, no fast answer, no verification — and no route
837
+ * changes the session's active tools, so the turn prompt is what scopes the
838
+ * work. Returns the report, or `undefined` when the user stopped the run or
839
+ * the turn ended without one.
800
840
  */
801
- buildExtraPrompt(query: string): string;
841
+ private runActionTurn;
802
842
  /** Discovery-tool hint naming only the registered discovery tools; empty when none. */
803
843
  private discoveryHint;
804
844
  /**
805
- * Verification-phase nudge toward the internet. Jev no longer routes to web
806
- * search, so the agent decides after the fast answer: when local evidence is
807
- * missing, thin, or possibly stale, it searches the web. Empty when web tools are off.
845
+ * Verification-phase nudge toward the internet, for when the web was not
846
+ * selected before the fast answer or its evidence fell short: when local
847
+ * evidence is missing, thin, or possibly stale, the agent searches the web. Empty when web tools are off.
808
848
  */
809
849
  private webFallbackHint;
810
850
  /**
@@ -31,13 +31,30 @@ export declare const ANSWER_EMPHASIS_RULE = "**Emphasis**: put the values a read
31
31
  export declare const ANSWER_LANGUAGE_RULE = "**Answer language**: write the answer in the language of the user's question (a Korean question gets a Korean answer) even when the sources are in another language; if the user asks for a specific language, use that one. Keep proper nouns, identifiers, code, and terms quoted from sources in their original form.";
32
32
  /** Uncertainty goes last so it never buries the conclusion. */
33
33
  export declare const ANSWER_UNCERTAINTY_RULE = "**Uncertainty placement**: when the answer is incomplete or uncertain, state that in one short sentence on the last line of the answer, never before or ahead of the conclusion. Do not hedge the conclusion itself.";
34
+ /**
35
+ * Every sentence answers the question. Models that find nothing on point tend to
36
+ * prove the search was thorough by listing what they found instead and why it
37
+ * does not match; the caller never asked for that, so it is left out for every
38
+ * phase, delta included.
39
+ */
40
+ export declare const ANSWER_RELEVANCE_RULE = "**Answer only what was asked**: every sentence must answer the user's question. Never list retrieved items, topics, documents, or figures that do not answer it, never describe how or where you searched, and never explain why something was left out or how it differs from what was asked (no \"I also found X, but it is not what you asked\", no near-miss lists, no \"nothing about Y, only Z\", no inventory of the sources that lacked it). Unrelated or merely adjacent material is omitted entirely unless the user asked for related items or alternatives.";
41
+ /**
42
+ * Fast phase, no supporting evidence: park the question in one line. The
43
+ * verification phase that follows keeps searching, so the line is true.
44
+ */
45
+ export declare const ANSWER_UNCONFIRMED_FAST_RULE = "**When the evidence does not answer the question yet**: do not build an answer out of what was found instead, and do not argue that the answer is absent by naming what the sources did contain (no \"only X exists\" contrast). The whole answer is then one short line saying it is not confirmed yet and that you are searching further (the verification phase that follows does the searching), with no bullets and no citations. A different subject, place, year, or party is unrelated evidence, not part of the answer. If a part the user actually asked for is answered, answer that part normally and say on the last line what is still being searched.";
46
+ /**
47
+ * Phases that can end the run: search before giving up, and when the search
48
+ * still finds nothing the answer is one line, not an inventory of the corpus.
49
+ */
50
+ export declare const ANSWER_UNCONFIRMED_FINAL_RULE = "**When the answer cannot be found**: keep searching first (different terms, synonyms, other retrieval methods or datasources) instead of answering from unrelated results. If it still cannot be confirmed, the whole answer is one short line saying so, with no bullets, no citations, no mention of what was found instead (no \"only X exists\" contrast), and no account of where you looked or what the documents do contain. A different subject, place, year, or party is unrelated evidence, not part of the answer. If a part the user actually asked for is answered, answer that part normally and say on the last line what is still unconfirmed.";
34
51
  /**
35
52
  * Inline evidence citations. The model writes the id the retrieval tools print
36
53
  * next to each result; the harness resolves it to the recorded source and
37
54
  * renumbers the markers `[1]`, `[2]`, ... (a source keeps its number for the whole
38
55
  * conversation), so the caller only ever sees numbered citations backed by recorded evidence.
39
56
  */
40
- export declare const ANSWER_CITATION_RULE = "**Citations**: cite supporting evidence inline with the evidence id shown next to each retrieved result, in square brackets (e.g. [e3], or [e3][e7] for two). Copy ids exactly; never invent one. For a local file you opened yourself with `bash`, cite `[file:<absolute path>]`. Cite the evidence that backs a sentence at the end of that sentence. Do not cite numbers, paths, or anything else.";
57
+ export declare const ANSWER_CITATION_RULE = "**Citations**: cite supporting evidence inline with the evidence id shown next to each retrieved result, in square brackets (e.g. [e3], or [e3][e7] for two). Copy ids exactly; never invent one. For a local file you opened yourself with `bash`, cite `[file:<absolute path>]`. Cite the evidence that backs a sentence at the end of that sentence. Do not cite numbers, paths, or anything else. A retrieved result may carry a measured location note such as `(lines 7-8, section \"\uC81C5\uC870(\uD68C\uC6D0\uC758 \uC758\uBB34)\")` next to its id: when you state a line number, line range, or article/section of a passage, copy it from that note, and when no note is printed give none. Never count or infer line numbers yourself, and never state how many items (paragraphs, articles, results) there are unless you counted them in the quoted text.";
41
58
  /**
42
59
  * Deliverable/artifact rule (issue #1832). The 5-bullet cap and direct-answer
43
60
  * format remain the default unless the user explicitly asks otherwise; when the
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The prompt block that tells the model what "now" is. AutoRAG replaces pi's whole
3
+ * system prompt, so nothing else gives the model a clock; without it "last month",
4
+ * "this year", "is the deadline past", and "the most recent" have no anchor.
5
+ *
6
+ * Built per turn from the host's local clock and time zone, so a session left open
7
+ * for days never shows yesterday's date. It sits last in the prompt so the stable
8
+ * part before it keeps its prompt-cache prefix.
9
+ */
10
+ export declare function currentDateAddendum(now?: Date): string;
@@ -36,8 +36,8 @@ export declare function toDatasourceAgentSkill(manifest: DatasourceSkillManifest
36
36
  */
37
37
  export declare function buildDatasourceSkillsPrompt(skills: readonly DatasourceAgentSkill[]): string;
38
38
  /**
39
- * Format the full instructions for a loaded datasource skill, matching pi's
40
- * `<skill …>` invocation shape but with a path-opaque location (no real
39
+ * Format the full instructions for a loaded datasource skill in the shared
40
+ * `<skill …>` invocation shape, with a path-opaque location (no real
41
41
  * filesystem reference, so no "references are relative to …" line).
42
42
  */
43
43
  export declare function formatDatasourceSkillInvocation(skill: DatasourceAgentSkill): string;
@@ -0,0 +1,20 @@
1
+ export interface EnvironmentInfo {
2
+ readonly cwd: string;
3
+ readonly platform: string;
4
+ readonly arch: string;
5
+ readonly release: string;
6
+ /** The shell the `bash` tool runs commands in; undefined when pi found none. */
7
+ readonly shell: string | undefined;
8
+ }
9
+ /**
10
+ * Where the agent runs: OS, shell, and working directory. AutoRAG replaces pi's whole
11
+ * system prompt, so without this the model writes POSIX commands for a Windows host
12
+ * and relative paths against an unknown directory. Fixed for the life of a session.
13
+ */
14
+ export declare function environmentAddendum(info: EnvironmentInfo): string;
15
+ /**
16
+ * Everything the host appends after AutoRAG's own prompt. Ordered most stable first:
17
+ * the environment never changes in a session, the date changes every minute, so the
18
+ * longest possible prefix of the prompt stays identical between turns for prompt caching.
19
+ */
20
+ export declare function runtimeContextAddendum(cwd: string, now?: Date): string;
@@ -8,11 +8,12 @@ export interface LedgerEvidenceInput {
8
8
  readonly retrievalResultId?: string;
9
9
  readonly chunkIndex?: number;
10
10
  readonly lineNumber?: number;
11
+ readonly lineEnd?: number;
12
+ readonly section?: string;
11
13
  readonly parserType?: string;
12
14
  readonly documentType?: string;
13
15
  readonly documentArea?: string;
14
16
  readonly evidenceType?: string;
15
- readonly evidenceLocation?: string;
16
17
  }
17
18
  /** Custom session entry type under which a conversation persists its evidence ledger. */
18
19
  export declare const EVIDENCE_ENTRY_TYPE = "autorag.evidence";
@@ -27,11 +28,12 @@ declare const ledgerEntrySchema: Type.TObject<{
27
28
  retrievalResultId: Type.TOptional<Type.TString>;
28
29
  chunkIndex: Type.TOptional<Type.TNumber>;
29
30
  lineNumber: Type.TOptional<Type.TNumber>;
31
+ lineEnd: Type.TOptional<Type.TNumber>;
32
+ section: Type.TOptional<Type.TString>;
30
33
  parserType: Type.TOptional<Type.TString>;
31
34
  documentType: Type.TOptional<Type.TString>;
32
35
  documentArea: Type.TOptional<Type.TString>;
33
36
  evidenceType: Type.TOptional<Type.TString>;
34
- evidenceLocation: Type.TOptional<Type.TString>;
35
37
  }>;
36
38
  /** One recorded piece of evidence: what a retrieval tool returned, under the id it printed. */
37
39
  export type LedgerEntry = Static<typeof ledgerEntrySchema>;
@@ -0,0 +1,14 @@
1
+ /** A line range a cited chunk occupies in its parsed document. */
2
+ export interface CitedLineRange {
3
+ readonly lineStart?: number;
4
+ readonly lineEnd?: number;
5
+ }
6
+ /**
7
+ * Line numbers `prose` states that no cited chunk covers, each once, in order of
8
+ * appearance. The line range of a chunk is measured from the parsed document,
9
+ * so a number outside every cited range is one the model made up or miscounted.
10
+ *
11
+ * Nothing can be checked when no cited chunk carries a line range, so that
12
+ * yields no claims rather than flagging every number.
13
+ */
14
+ export declare function findUnverifiedLineClaims(prose: string, cited: readonly CitedLineRange[]): number[];
@@ -0,0 +1,19 @@
1
+ import type { SkillInvocation } from "./skill-invocation.js";
2
+ /** The packaged `autorag-setup` skill, loaded for the Jev `config` branch. */
3
+ export declare const SETUP_SKILL_NAME = "autorag-setup";
4
+ /** The packaged `organize` skill, loaded for the Jev `organize` branch. */
5
+ export declare const ORGANIZE_SKILL_NAME = "organize";
6
+ /** A packaged skill as a turn prompt needs it: name, opaque location, body. */
7
+ export type PackagedAgentSkill = SkillInvocation;
8
+ /**
9
+ * Opaque, path-free location used for a packaged agent skill. Packaged skills
10
+ * live on disk, but AutoRAG never exposes real filesystem paths to the model.
11
+ */
12
+ export declare function packagedSkillLocation(name: string): string;
13
+ /**
14
+ * Load one packaged agent skill: the file at `path` when given (the host's
15
+ * override), otherwise the packaged skill named `name`. The body is returned
16
+ * with its YAML front matter removed, so the model sees only instructions.
17
+ * Throws when the skill cannot be found or read; callers fall back to `local`.
18
+ */
19
+ export declare function loadPackagedSkill(name: string, path?: string): PackagedAgentSkill;
@@ -2,21 +2,25 @@ import type { JevJudge } from "./jev-extension.js";
2
2
  /**
3
3
  * Where a user question is answered from:
4
4
  * - `local`: anything needing information beyond the model's own knowledge —
5
- * the user's files, chats, mail, or any fact the model cannot reliably recall.
6
- * Local retrieval runs first; web search is left to the agent after the fast
7
- * answer, when local evidence falls short.
8
- * - `direct`: intrinsic knowledge or small talk the model answers on its own.
5
+ * the user's files, chats, mail, or any fact the model cannot reliably recall,
6
+ * recent, specific, or changing public facts included. Local retrieval runs
7
+ * first, together with every datasource Jev selects, the public web among
8
+ * them when web tools are enabled.
9
9
  * - `organize`: the user wants files or folders acted on — move, rename in
10
10
  * bulk, rename by content, convert, sort, tidy — rather than information
11
11
  * found. No retrieval and no verification: one tool-capable turn does it.
12
- * - `extra`: none of the other branches (committing code, opening a pull
13
- * request, running a build, any other task for the agent's tools). The Jev
14
- * gate is skipped: no retrieval, no verification, tools stay available.
12
+ * - `extra`: neither of the other branches, and no search of the user's own
13
+ * records is needed first: the request is answerable from the model's own
14
+ * knowledge (stable general knowledge, definitions, simple reasoning, small
15
+ * talk), or it is a task for the agent's tools that is not file organization
16
+ * and not AutoRAG configuration (commit, PR, build, write code, run a
17
+ * script). No retrieval, decomposition, fast answer, follow-up check, or
18
+ * verification: one tool-capable turn does it, with every tool available.
15
19
  * - `config`: the user wants to inspect or change AutoRAG's own settings
16
20
  * (model, providers, datasources). Offered only when the host enables
17
21
  * agent self-configuration.
18
22
  */
19
- export type QueryRoute = "local" | "direct" | "organize" | "extra" | "config";
23
+ export type QueryRoute = "local" | "organize" | "extra" | "config";
20
24
  /** Jev question id of the intrinsic-knowledge / local branch. */
21
25
  export declare const QUERY_ROUTE_QUESTION_ID = "route";
22
26
  /** Jev question id of the "does this need decomposition?" check. */
@@ -29,10 +33,36 @@ export declare const FALLBACK_QUERY_ROUTE: QueryRoute;
29
33
  export declare const DECOMPOSE_PROBABILITY_THRESHOLD = 0.5;
30
34
  /** A `noul` probability at or above this sends the fast answer on to verification. */
31
35
  export declare const FOLLOW_UP_PROBABILITY_THRESHOLD = 0.5;
36
+ /**
37
+ * Minimum Jev branch probability required to leave local search. A non-local
38
+ * branch (`organize`, `extra`, `config`) at or below this floor — or one Jev
39
+ * reported without a probability — keeps the run on local search, the
40
+ * corpus-grounded default, with a `query-route-fallback` diagnostic naming the
41
+ * floor as the reason (the rejected branch's probability is still reported as
42
+ * `routeProbability`). Without the floor a weakly-favored non-local verdict
43
+ * skips retrieval entirely, so a question that depends on the user's own
44
+ * records can be answered from general knowledge instead.
45
+ *
46
+ * The floor does not weaken a real non-local verdict: the fallback is a
47
+ * full local plan (datasource selection and decomposition still run). Removed
48
+ * by #1995 (982e464d) together with the intrinsic-knowledge branch, restored
49
+ * here because the reasons above did not go away.
50
+ */
51
+ export declare const NON_LOCAL_ROUTE_PROBABILITY_THRESHOLD = 0.75;
32
52
  /** A `noul` probability at or above this searches that datasource before the fast answer. */
33
53
  export declare const DATASOURCE_PROBABILITY_THRESHOLD = 0.5;
34
54
  /** Jev question id of the "search this datasource?" check for one datasource. */
35
55
  export declare function datasourceQuestionId(datasourceId: string): string;
56
+ /**
57
+ * Reserved candidate id of the public web in the datasource gate.
58
+ *
59
+ * Datasource ids come from the config's `datasources` keys, which are only
60
+ * required to be non-empty (see `DatasourceSkillRegistry.register`), so a
61
+ * configured datasource *can* be called `web`. When one is, the web candidate
62
+ * is withheld and {@link DatasourceSelection.webIdTaken} says so, so the
63
+ * question id `datasource:web` always names exactly one candidate.
64
+ */
65
+ export declare const WEB_DATASOURCE_ID = "web";
36
66
  export interface FollowUpDecision {
37
67
  /** True when the run continues into the verification phase. */
38
68
  readonly followUp: boolean;
@@ -49,27 +79,37 @@ export interface FollowUpDecision {
49
79
  */
50
80
  export declare function needsFollowUp(judge: JevJudge, query: string, answer: string): Promise<FollowUpDecision>;
51
81
  export interface QueryRouteDecision {
52
- /** Most probable branch; {@link FALLBACK_QUERY_ROUTE} when Jev gave none. */
82
+ /** Most probable branch; {@link FALLBACK_QUERY_ROUTE} when Jev gave none or its non-local branch missed {@link NON_LOCAL_ROUTE_PROBABILITY_THRESHOLD}. */
53
83
  readonly route: QueryRoute;
54
- /** True when Jev judged the question needs decomposition (only ever for `local`). */
84
+ /** True when Jev judged the question needs decomposition; only a `local` route acts on it. */
55
85
  readonly decompose: boolean;
56
- /** Probability Jev gave the winning branch; absent when Jev reported none. */
86
+ /** Probability Jev gave the winning branch, including a rejected non-local branch whose floor moved the route to local. */
57
87
  readonly routeProbability?: number;
58
88
  /** Jev's P(decomposition needed), when it answered. */
59
89
  readonly decomposeProbability?: number;
60
90
  /** Why the decision fell back instead of following Jev; absent when Jev decided. */
61
91
  readonly fallbackReason?: string;
92
+ /**
93
+ * True when a non-local branch won but did not clear
94
+ * {@link NON_LOCAL_ROUTE_PROBABILITY_THRESHOLD}: `route` is `local` and the
95
+ * full local plan still runs (datasource selection and decomposition),
96
+ * unlike a fallback from an unavailable or unusable verdict, which keeps a
97
+ * bare single-query local search.
98
+ */
99
+ readonly floorApplied?: boolean;
62
100
  }
63
101
  export interface RouteQueryOptions {
64
102
  /** Offer the `config` branch: the agent may change its own settings. */
65
103
  readonly selfConfig?: boolean;
66
104
  }
67
105
  /**
68
- * Ask Jev, in one batched call about the user question, which branch answers
69
- * it and whether it needs decomposition. The most probable branch wins, with
70
- * no confidence floor. Never throws: a missing credential, an unreachable
71
- * backend, or an unusable verdict falls back to a single local search, with
72
- * the reason recorded.
106
+ * Ask Jev, in one batched call about the user question, which branch handles it
107
+ * and whether it needs decomposition. The most probable branch wins once it
108
+ * clears {@link NON_LOCAL_ROUTE_PROBABILITY_THRESHOLD}: a weakly-favored or
109
+ * probability-less `organize`, `extra`, or `config` verdict keeps the local
110
+ * default and still runs the full local plan (`floorApplied`). Never throws: a
111
+ * missing credential, an unreachable backend, or an unusable verdict falls back
112
+ * to a single local search, with the reason recorded.
73
113
  */
74
114
  export declare function routeQuery(judge: JevJudge, query: string, options?: RouteQueryOptions): Promise<QueryRouteDecision>;
75
115
  /** One configured datasource Jev may send the question to. */
@@ -81,12 +121,23 @@ export interface DatasourceCandidate {
81
121
  readonly description: string;
82
122
  }
83
123
  export interface DatasourceSelection {
84
- /** Datasource ids to search, in registration order. */
124
+ /** Datasource ids to search, in registration order; the web candidate's id is {@link WEB_DATASOURCE_ID}. */
85
125
  readonly selected: readonly string[];
86
- /** Jev's P(search needed) per datasource id, for every datasource it answered. */
126
+ /** Jev's P(search needed) per candidate id, for every candidate it answered. */
87
127
  readonly probabilities: Readonly<Record<string, number>>;
88
128
  /** Why no datasource is searched instead of following Jev; absent when Jev decided. */
89
129
  readonly fallbackReason?: string;
130
+ /**
131
+ * True when the web candidate was withheld because a configured datasource
132
+ * already uses {@link WEB_DATASOURCE_ID}: `datasource:web` then names that
133
+ * configured datasource, and the run searches no web before the fast answer.
134
+ */
135
+ readonly webIdTaken?: boolean;
136
+ }
137
+ /** Options of {@link selectDatasources}. */
138
+ export interface SelectDatasourcesOptions {
139
+ /** Offer the public web as one more candidate (the host has web tools enabled). */
140
+ readonly web?: boolean;
90
141
  }
91
142
  /** A similar question asked before, its results, and where each was found. */
92
143
  export interface PastSearchHint {
@@ -101,12 +152,15 @@ export interface PastSearchHint {
101
152
  }[];
102
153
  }
103
154
  /**
104
- * Ask Jev, in one batched call, one `noul` per registered datasource: does
105
- * answering the question need that datasource searched? The state describes
106
- * every datasource (descriptions are flagged as non-exhaustive summaries), so
107
- * Jev judges each one against the others, plus where similar past questions
108
- * were answered, when retrieval memory has any. Never throws: a missing
109
- * credential or an unreachable backend searches no datasource, which is the
110
- * behavior without Jev.
155
+ * Ask Jev, in one batched call, one `noul` per candidate: does answering the
156
+ * question need that datasource searched? The state describes every candidate
157
+ * (descriptions are flagged as non-exhaustive summaries), so Jev judges each
158
+ * one against the others, plus where similar past questions were answered,
159
+ * when retrieval memory has any. With `options.web`, the public web is one
160
+ * more candidate, under the reserved id {@link WEB_DATASOURCE_ID}; it is
161
+ * withheld when a configured datasource already uses that id
162
+ * ({@link DatasourceSelection.webIdTaken}), so a question id never names two
163
+ * candidates. Never throws: a missing credential or an unreachable backend
164
+ * searches nothing, which is the behavior without Jev.
111
165
  */
112
- export declare function selectDatasources(judge: JevJudge, query: string, datasources: readonly DatasourceCandidate[], pastSearches?: readonly PastSearchHint[]): Promise<DatasourceSelection>;
166
+ export declare function selectDatasources(judge: JevJudge, query: string, datasources: readonly DatasourceCandidate[], pastSearches?: readonly PastSearchHint[], options?: SelectDatasourcesOptions): Promise<DatasourceSelection>;
@@ -16,6 +16,8 @@ export declare const reportSchema: Type.TObject<{
16
16
  evidence: Type.TArray<Type.TObject<{
17
17
  excerpt: Type.TString;
18
18
  lineNumber: Type.TOptional<Type.TInteger>;
19
+ lineEnd: Type.TOptional<Type.TInteger>;
20
+ section: Type.TOptional<Type.TString>;
19
21
  }>>;
20
22
  confidence: Type.TNumber;
21
23
  }>>;
@@ -38,7 +40,8 @@ export declare const reportSchema: Type.TObject<{
38
40
  documentType: Type.TOptional<Type.TString>;
39
41
  documentArea: Type.TOptional<Type.TString>;
40
42
  evidenceType: Type.TOptional<Type.TString>;
41
- evidenceLocation: Type.TOptional<Type.TString>;
43
+ lineEnd: Type.TOptional<Type.TInteger>;
44
+ section: Type.TOptional<Type.TString>;
42
45
  confidence: Type.TOptional<Type.TNumber>;
43
46
  }>>>;
44
47
  }>>;
@@ -47,6 +50,10 @@ export declare const reportSchema: Type.TObject<{
47
50
  export interface AutoRAGEmittedEvidence {
48
51
  readonly excerpt: string;
49
52
  readonly lineNumber?: number;
53
+ /** Last line of the chunk; with {@link lineNumber} the exact range in the parsed document. */
54
+ readonly lineEnd?: number;
55
+ /** Article or heading the chunk sits in. */
56
+ readonly section?: string;
50
57
  }
51
58
  export interface AutoRAGEmittedResult {
52
59
  readonly number: number;
@@ -64,13 +71,14 @@ export interface AutoRAGEvidenceRef {
64
71
  readonly retrievalResultId?: string;
65
72
  readonly chunkIndex?: number;
66
73
  readonly lineNumber?: number;
74
+ readonly lineEnd?: number;
75
+ readonly section?: string;
67
76
  readonly stableEvidenceId?: string;
68
77
  readonly retrieverMix?: readonly string[];
69
78
  readonly parserType?: string;
70
79
  readonly documentType?: string;
71
80
  readonly documentArea?: string;
72
81
  readonly evidenceType?: string;
73
- readonly evidenceLocation?: string;
74
82
  readonly confidence?: number;
75
83
  }
76
84
  export interface AutoRAGMappingEntry {