@autorag/librarian 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +6 -0
- package/README.md +14 -6
- package/dist/agent/agent.d.ts +136 -33
- package/dist/agent/answer-citations.d.ts +34 -2
- package/dist/agent/answer-guidelines.d.ts +20 -3
- package/dist/agent/ask-user.d.ts +8 -0
- package/dist/agent/automation-tool.d.ts +45 -0
- package/dist/agent/citation-links.d.ts +23 -0
- package/dist/agent/citation-numbers.d.ts +68 -0
- package/dist/agent/citation-relevance.d.ts +37 -0
- package/dist/agent/conversation-queries.d.ts +31 -0
- package/dist/agent/convert-tool.d.ts +28 -0
- package/dist/agent/current-date.d.ts +10 -0
- package/dist/agent/datasource-skill.d.ts +2 -2
- package/dist/agent/environment-prompt.d.ts +20 -0
- package/dist/agent/evidence-ledger.d.ts +4 -2
- package/dist/agent/evidence-persistence.d.ts +17 -11
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/intent-tracing.d.ts +33 -0
- package/dist/agent/location-claims.d.ts +14 -0
- package/dist/agent/packaged-skill.d.ts +19 -0
- package/dist/agent/permission-gate.d.ts +78 -0
- package/dist/agent/permission-judgment.d.ts +72 -0
- package/dist/agent/permission-paths.d.ts +23 -0
- package/dist/agent/query-routing.d.ts +78 -27
- package/dist/agent/results.d.ts +10 -2
- package/dist/agent/search-documents.d.ts +6 -1
- package/dist/agent/self-config.d.ts +6 -4
- package/dist/agent/skill-invocation.d.ts +17 -0
- package/dist/agent/user-requests.d.ts +52 -0
- package/dist/automation/config.d.ts +48 -0
- package/dist/automation/daemon.d.ts +31 -0
- package/dist/automation/dispatch.d.ts +13 -0
- package/dist/automation/run-agent.d.ts +22 -0
- package/dist/automation/run.d.ts +32 -0
- package/dist/automation/service.d.ts +61 -0
- package/dist/cli/commands/automate.d.ts +2 -0
- package/dist/cli/commands/evidence.d.ts +2 -0
- package/dist/cli/config.d.ts +21 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +19531 -14871
- package/dist/cli/open-target.d.ts +9 -0
- package/dist/cli/setup.d.ts +14 -0
- package/dist/convert/cli.d.ts +77 -0
- package/dist/convert/index.d.ts +4 -0
- package/dist/convert/installer.d.ts +84 -0
- package/dist/convert/matrix.d.ts +27 -0
- package/dist/convert/relate.d.ts +30 -0
- package/dist/core.js +32479 -28141
- package/dist/datasource/connector-timeouts.d.ts +6 -2
- package/dist/datasource/crawler-skill.d.ts +1 -0
- package/dist/datasource/crawler-types.d.ts +1 -1
- package/dist/datasource/index.d.ts +1 -1
- package/dist/datasource/sidecar/methods.d.ts +8 -1
- package/dist/datasource/skills/clawgallery/skill.d.ts +4 -0
- package/dist/datasource/skills/discrawl/skill.d.ts +5 -0
- package/dist/datasource/skills/factory.d.ts +5 -1
- package/dist/datasource/skills/lazykatok/index.d.ts +1 -1
- package/dist/datasource/skills/lazykatok/methods.d.ts +5 -5
- package/dist/datasource/skills/lazykatok/skill.d.ts +1 -0
- package/dist/datasource/skills/lazykatok/types.d.ts +2 -2
- package/dist/datasource/skills/mailcrawl/skill.d.ts +1 -0
- package/dist/datasource/skills/mailcrawl/types.d.ts +1 -1
- package/dist/dupey/cli.d.ts +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32558 -28145
- package/dist/mcp/index.js +32651 -28263
- package/dist/memory/memory.d.ts +4 -1
- package/dist/minsync/installer.d.ts +1 -1
- package/dist/mirror/atomic-write.d.ts +16 -1
- package/dist/mirror/sync.d.ts +2 -0
- package/dist/profiles/agent-factory.d.ts +60 -0
- package/dist/profiles/automation-profiles.d.ts +25 -0
- package/dist/profiles/loop-guard.d.ts +23 -0
- package/dist/profiles/retrieval-tools.d.ts +24 -0
- package/dist/profiles/session-model.d.ts +69 -0
- package/dist/profiles.d.ts +13 -0
- package/dist/profiles.js +35246 -0
- package/dist/retrieval/chunk-location.d.ts +28 -0
- package/dist/retrieval/fallback.d.ts +24 -0
- package/dist/retrieval/index.d.ts +1 -0
- package/dist/retrieval/rerank.d.ts +6 -0
- package/dist/retrieval/types.d.ts +16 -0
- package/internal-skills/organize/SKILL.md +43 -0
- package/package.json +9 -2
- package/skills/autorag/SKILL.md +89 -7
- package/skills/autorag-setup/SKILL.md +10 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
/** Custom session entry type under which a conversation persists its result numbers. */
|
|
3
|
+
export declare const CITATION_NUMBERS_ENTRY_TYPE = "autorag.citation-numbers";
|
|
4
|
+
declare const citationNumberEntrySchema: Type.TObject<{
|
|
5
|
+
source: Type.TString;
|
|
6
|
+
number: Type.TInteger;
|
|
7
|
+
}>;
|
|
8
|
+
/** One source and the result number (`[n]`) the user was shown for it. */
|
|
9
|
+
export type CitationNumberEntry = Static<typeof citationNumberEntrySchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Entries a session persisted under {@link CITATION_NUMBERS_ENTRY_TYPE}. A
|
|
12
|
+
* malformed entry is skipped: its source is then numbered afresh, never
|
|
13
|
+
* under a number it was not shown with.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseCitationNumberEntries(data: unknown): CitationNumberEntry[];
|
|
16
|
+
/** Highest result number among `entries`; 0 when there are none. */
|
|
17
|
+
export declare function highestCitationNumber(entries: readonly CitationNumberEntry[]): number;
|
|
18
|
+
/**
|
|
19
|
+
* The result numbers (`[1]`, `[2]`, ...) one conversation has shown the user.
|
|
20
|
+
*
|
|
21
|
+
* A source keeps the number it was first shown with in every later answer of
|
|
22
|
+
* the conversation, and a new source gets the next unused number. Numbers are
|
|
23
|
+
* never reissued, mirroring the `e<N>` ordinals of the `EvidenceLedger`: the
|
|
24
|
+
* quick and verification answers of one turn, and every turn after them,
|
|
25
|
+
* share one numbering, so a `[n]` a user saw never names a different source.
|
|
26
|
+
*
|
|
27
|
+
* The hosting session persists what {@link takeUnsaved} returns (through the
|
|
28
|
+
* sink installed with {@link setSink}) and rebuilds the numbers with
|
|
29
|
+
* {@link restore} when a conversation is resumed.
|
|
30
|
+
*/
|
|
31
|
+
export declare class CitationNumbers {
|
|
32
|
+
private readonly bySource;
|
|
33
|
+
/** Entries issued since the last {@link takeUnsaved}. */
|
|
34
|
+
private unsaved;
|
|
35
|
+
private sink;
|
|
36
|
+
/**
|
|
37
|
+
* The last number issued. Survives {@link clear} and {@link restore}: a
|
|
38
|
+
* conversation keeps earlier answers in view, so restarting at 1 would let
|
|
39
|
+
* an old `[n]` silently name a different source.
|
|
40
|
+
*/
|
|
41
|
+
private lastNumber;
|
|
42
|
+
/** The number for `source`: the one it already has, else the next unused number. */
|
|
43
|
+
numberFor(source: string): number;
|
|
44
|
+
/** Forget every source. Numbers are never reissued, so a previous conversation's `[n]` stays unused. */
|
|
45
|
+
clear(): void;
|
|
46
|
+
/** Forget every source and restart at 1: for a run that owns no conversation, where no earlier `[n]` is in view. */
|
|
47
|
+
reset(): void;
|
|
48
|
+
/** Numbers issued since the last call, for the hosting session to persist. */
|
|
49
|
+
takeUnsaved(): CitationNumberEntry[];
|
|
50
|
+
/** Where {@link flush} writes numbers: the hosting session. Replaces any earlier sink. */
|
|
51
|
+
setSink(sink: ((entries: CitationNumberEntry[]) => void) | undefined): void;
|
|
52
|
+
/**
|
|
53
|
+
* Persist numbers issued since the last save right now. Answers are derived
|
|
54
|
+
* after a turn's last session event, so without this the final answer's new
|
|
55
|
+
* numbers would not reach the session file until the next turn. With no
|
|
56
|
+
* sink installed the numbers stay unsaved for the next save.
|
|
57
|
+
*/
|
|
58
|
+
flush(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Rebuild the numbers from persisted entries, such as the ones on the
|
|
61
|
+
* resumed conversation branch; a later entry for the same source replaces an
|
|
62
|
+
* earlier one. Numbers keep counting past every restored number and past
|
|
63
|
+
* `numberFloor`, the highest number issued anywhere in the conversation
|
|
64
|
+
* (other branches included).
|
|
65
|
+
*/
|
|
66
|
+
restore(entries: readonly CitationNumberEntry[], numberFloor?: number): void;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CitedChunk } from "./answer-citations.js";
|
|
2
|
+
import type { JevJudge } from "./jev-extension.js";
|
|
3
|
+
/**
|
|
4
|
+
* The model sometimes cites a chunk that has nothing to do with the sentence it
|
|
5
|
+
* backs or with what the user asked: a table of contents, a navigation bar, a
|
|
6
|
+
* copyright footer, a generic introduction. Before the answer is returned,
|
|
7
|
+
* every cited chunk is put to Jev as one relevance question, and a chunk Jev
|
|
8
|
+
* finds unrelated is removed from the answer's citations.
|
|
9
|
+
*
|
|
10
|
+
* This is deliberately weaker than the memory judgment in `evidence-judgment.ts`
|
|
11
|
+
* ("does it directly support, and is it needed"): that gate decides what is
|
|
12
|
+
* worth remembering and rejects any chunk that does not state the claim. Here a
|
|
13
|
+
* chunk that is merely on topic, or backs only part of the claim, must stay, so
|
|
14
|
+
* the only thing rejected is evidence with no information on the subject at all.
|
|
15
|
+
*/
|
|
16
|
+
/** A chunk is kept when Jev's P(relevant) is at or above this; below it the chunk is rejected. */
|
|
17
|
+
export declare const CITATION_RELEVANCE_FLOOR = 0.3;
|
|
18
|
+
/** Jev question id prefix of one citation relevance check. */
|
|
19
|
+
export declare const CITATION_QUESTION_ID_PREFIX = "citation:";
|
|
20
|
+
export interface CitationRelevanceInput {
|
|
21
|
+
/** Everything the user typed in the conversation, oldest first; the last is the question being answered. */
|
|
22
|
+
readonly userMessages: readonly string[];
|
|
23
|
+
/** The chunks the answer cites, with the sentences citing each. */
|
|
24
|
+
readonly chunks: readonly CitedChunk[];
|
|
25
|
+
}
|
|
26
|
+
export interface CitationRelevance {
|
|
27
|
+
/** {@link CitedChunk.key} of every chunk Jev found unrelated. */
|
|
28
|
+
readonly rejected: ReadonlySet<string>;
|
|
29
|
+
/** Set when Jev gave no usable verdict for ANY chunk; nothing was rejected. Absent when Jev decided. */
|
|
30
|
+
readonly fallbackReason?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Ask Jev, in one batched call, whether each cited chunk is relevant to the
|
|
34
|
+
* sentences that cite it and to what the user asked. Never throws: a rejecting
|
|
35
|
+
* judge rejects nothing and reports why, and a chunk Jev left unanswered is kept.
|
|
36
|
+
*/
|
|
37
|
+
export declare function judgeCitationRelevance(judge: JevJudge, input: CitationRelevanceInput): Promise<CitationRelevance>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Custom session entry type under which a conversation persists what the user typed. */
|
|
2
|
+
export declare const CONVERSATION_QUERIES_ENTRY_TYPE = "autorag.queries";
|
|
3
|
+
/** The queries a session persisted under {@link CONVERSATION_QUERIES_ENTRY_TYPE}; a malformed entry is skipped. */
|
|
4
|
+
export declare function parseQueryEntries(data: unknown): string[];
|
|
5
|
+
/**
|
|
6
|
+
* Everything the user typed in one conversation: each question and each
|
|
7
|
+
* steer, as typed. The transcript cannot stand in for it, because the first
|
|
8
|
+
* turn's user message there is the harness prompt that wraps the question
|
|
9
|
+
* with baseline evidence and formatting rules.
|
|
10
|
+
*
|
|
11
|
+
* The hosting session persists what {@link flush} hands to the sink and
|
|
12
|
+
* rebuilds the list with {@link restore} when a conversation is resumed or
|
|
13
|
+
* a new one starts, the way the evidence ledger and result numbers are.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConversationQueries {
|
|
16
|
+
private queries;
|
|
17
|
+
/** Queries added since the last {@link flush}. */
|
|
18
|
+
private unsaved;
|
|
19
|
+
private sink;
|
|
20
|
+
add(query: string): void;
|
|
21
|
+
/** Every query of the conversation, oldest first. */
|
|
22
|
+
all(): readonly string[];
|
|
23
|
+
/** Where {@link flush} writes queries: the hosting session. Replaces any earlier sink. */
|
|
24
|
+
setSink(sink: ((entries: string[]) => void) | undefined): void;
|
|
25
|
+
/** Persist queries added since the last save. With no sink installed they stay unsaved for the next save. */
|
|
26
|
+
flush(): void;
|
|
27
|
+
/** Replace the conversation's queries with already-persisted ones; an empty list forgets everything. */
|
|
28
|
+
restore(queries: readonly string[]): void;
|
|
29
|
+
/** Forget every query, saved or not: a run that owns no conversation starts over. */
|
|
30
|
+
reset(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import type { ConvertAndRelateResult, FileeConvertRequest } from "../convert/index.js";
|
|
4
|
+
export declare const CONVERT_FILES_TOOL_NAME = "convert_files";
|
|
5
|
+
export declare const LIST_FILE_CONVERSIONS_TOOL_NAME = "list_file_conversions";
|
|
6
|
+
export type ConvertFilesDetails = ConvertAndRelateResult;
|
|
7
|
+
export interface FileConversionProvider {
|
|
8
|
+
convertFiles(request: FileeConvertRequest, signal?: AbortSignal): Promise<ConvertFilesDetails>;
|
|
9
|
+
listFileConversions(from?: string, signal?: AbortSignal): Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
declare const convertFilesSchema: Type.TObject<{
|
|
12
|
+
inputs: Type.TArray<Type.TString>;
|
|
13
|
+
to: Type.TString;
|
|
14
|
+
outputDir: Type.TOptional<Type.TString>;
|
|
15
|
+
recursive: Type.TOptional<Type.TBoolean>;
|
|
16
|
+
quality: Type.TOptional<Type.TInteger>;
|
|
17
|
+
overwrite: Type.TOptional<Type.TBoolean>;
|
|
18
|
+
skipExisting: Type.TOptional<Type.TBoolean>;
|
|
19
|
+
keepDates: Type.TOptional<Type.TBoolean>;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function createConvertFilesTool(provider: FileConversionProvider): AgentTool<typeof convertFilesSchema, ConvertFilesDetails>;
|
|
22
|
+
declare const listConversionsSchema: Type.TObject<{
|
|
23
|
+
from: Type.TOptional<Type.TString>;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function createListFileConversionsTool(provider: FileConversionProvider): AgentTool<typeof listConversionsSchema, {
|
|
26
|
+
readonly from?: string;
|
|
27
|
+
}>;
|
|
28
|
+
export {};
|
|
@@ -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
|
|
40
|
-
* `<skill …>` invocation shape
|
|
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>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ExtensionFactory, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type CitationNumbers } from "./citation-numbers.js";
|
|
3
|
+
import { type ConversationQueries } from "./conversation-queries.js";
|
|
2
4
|
import { type EvidenceLedger } from "./evidence-ledger.js";
|
|
3
5
|
/** The part of pi's session manager the ledger is rebuilt from. */
|
|
4
6
|
interface SessionEntries {
|
|
@@ -6,19 +8,23 @@ interface SessionEntries {
|
|
|
6
8
|
getEntries(): SessionEntry[];
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
|
-
* Rebuild `ledger` for the conversation branch `session` is on.
|
|
10
|
-
* other branches
|
|
11
|
-
*
|
|
12
|
-
* conversation.
|
|
11
|
+
* Rebuild `ledger`, `numbers`, and `queries` for the conversation branch `session` is on.
|
|
12
|
+
* Evidence and result numbers from other branches stay out of reach (their
|
|
13
|
+
* transcripts are not in context), but their ids and numbers still count: new
|
|
14
|
+
* evidence and new results never reuse one issued anywhere in the conversation.
|
|
15
|
+
* What the user typed follows the branch exactly: a query typed on a branch the
|
|
16
|
+
* user left is not part of the conversation in view.
|
|
13
17
|
*/
|
|
14
|
-
export declare function
|
|
18
|
+
export declare function restoreConversationState(ledger: EvidenceLedger, numbers: CitationNumbers, queries: ConversationQueries, session: SessionEntries): void;
|
|
15
19
|
/**
|
|
16
|
-
* pi extension that keeps the conversation's evidence ledger
|
|
17
|
-
* file, next to the transcript that shows the
|
|
18
|
-
*
|
|
19
|
-
* the
|
|
20
|
-
*
|
|
20
|
+
* pi extension that keeps the conversation's evidence ledger, result numbers,
|
|
21
|
+
* and typed queries in the session file, next to the transcript that shows the
|
|
22
|
+
* model its `[eN]` ids and the user its `[n]` results. Evidence is appended as
|
|
23
|
+
* the tools return it, result numbers as answers are derived, and queries as
|
|
24
|
+
* they are typed; switching, resuming, forking, or navigating the session tree
|
|
25
|
+
* rebuilds all three from the branch now in view. An id the model saw therefore
|
|
26
|
+
* resolves, and an id or result number is never reissued, whatever turns, tool
|
|
21
27
|
* calls, resumes, or restarts happened in between.
|
|
22
28
|
*/
|
|
23
|
-
export declare function createEvidencePersistence(ledger: EvidenceLedger): ExtensionFactory;
|
|
29
|
+
export declare function createEvidencePersistence(ledger: EvidenceLedger, numbers: CitationNumbers, queries: ConversationQueries): ExtensionFactory;
|
|
24
30
|
export {};
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { AutoRAGAgentOptions, AutoRefreshOptions } from "./agent.js";
|
|
2
2
|
export { AutoRAGAgent } from "./agent.js";
|
|
3
|
+
export { CONVERT_FILES_TOOL_NAME, type ConvertFilesDetails, createConvertFilesTool, createListFileConversionsTool, type FileConversionProvider, LIST_FILE_CONVERSIONS_TOOL_NAME, } from "./convert-tool.js";
|
|
3
4
|
export { buildDatasourceSkillsPrompt, createLoadDatasourceSkillTool, type DatasourceSkillProvider, datasourceSkillLocation, formatDatasourceSkillInvocation, LOAD_DATASOURCE_SKILL_TOOL_NAME, type LoadDatasourceSkillDetails, toDatasourceAgentSkill, } from "./datasource-skill.js";
|
|
4
5
|
export { createScanDuplicateDocumentsTool, SCAN_DUPLICATE_DOCUMENTS_TOOL_NAME, type ScanDuplicateDocumentsDetails, type ScanDuplicateDocumentsProvider, } from "./dupey-tool.js";
|
|
5
6
|
export { createJevExtension, JEV_TOOL_NAME, type JevBackendName, type JevToolOptions, } from "./jev-extension.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
/**
|
|
3
|
+
* Intent tracing: every tool the model can call also takes a short `i` argument, one line saying
|
|
4
|
+
* what that call is for. The text is shown while the model works (pi's `Working` loader in the TUI,
|
|
5
|
+
* `progress` events of `searchDocumentsStream` for the CLI and the desktop app), so a long search
|
|
6
|
+
* says what it is doing without the model writing separate progress notes.
|
|
7
|
+
*
|
|
8
|
+
* Pi has no such feature; this mirrors oh-my-pi's. The field exists only on the wire: it is added to
|
|
9
|
+
* the tool declarations of each model request and removed again before the tool validates and runs,
|
|
10
|
+
* so no tool ever sees it.
|
|
11
|
+
*/
|
|
12
|
+
export declare const INTENT_FIELD = "i";
|
|
13
|
+
/** The text to show for a model-written intent, or `undefined` when it is not a usable label. */
|
|
14
|
+
export declare function normalizeIntent(value: unknown): string | undefined;
|
|
15
|
+
/** The intent of the last tool call in an assistant message that carries one, or `undefined`. */
|
|
16
|
+
export declare function intentOfMessage(message: {
|
|
17
|
+
readonly role?: string;
|
|
18
|
+
readonly content?: unknown;
|
|
19
|
+
}): string | undefined;
|
|
20
|
+
/** Whether the tool schema already has its own `i` parameter, which then belongs to the tool. */
|
|
21
|
+
export declare function schemaDefinesIntent(schema: unknown): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The wire schema of a tool with the required `i` field first. A schema that is not an object, that
|
|
24
|
+
* already defines `i`, or that rejects unknown properties comes back unchanged: the tool would
|
|
25
|
+
* refuse the field once the model filled it in.
|
|
26
|
+
*/
|
|
27
|
+
export declare function withIntentField(schema: unknown): unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Wires intent tracing into a pi session: declares `i` on every tool, takes it off the arguments
|
|
30
|
+
* before the tool runs, and, when the session has a terminal UI, shows the newest intent as the
|
|
31
|
+
* working message. Register it in every session whose model calls AutoRAG's tools.
|
|
32
|
+
*/
|
|
33
|
+
export declare function registerIntentTracing(pi: ExtensionAPI): void;
|
|
@@ -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;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ExtensionFactory } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { JevJudge } from "./jev-extension.js";
|
|
3
|
+
import { type PermissionKind } from "./permission-judgment.js";
|
|
4
|
+
import { type UserRequestLog } from "./user-requests.js";
|
|
5
|
+
export { AUTO_APPROVE_MIN_CONFIDENCE, DEFAULT_MAX_STATE_CHARS, PERMISSION_GATE_QUESTION_ID, } from "./permission-judgment.js";
|
|
6
|
+
/**
|
|
7
|
+
* How much the agent may do to the user's files without asking.
|
|
8
|
+
*
|
|
9
|
+
* - `full`: no gate; the agent does everything on its own, and Jev is never asked.
|
|
10
|
+
* - `ask`: every `bash`, `write`, `edit`, and saved automation is put to the user. Jev is not used.
|
|
11
|
+
* - `auto` (default): Jev classifies each of those calls first. One it finds safe runs; one it flags is approved
|
|
12
|
+
* by Jev when the user's request clearly covers it, and only what Jev will not approve confidently reaches
|
|
13
|
+
* the user.
|
|
14
|
+
*/
|
|
15
|
+
export type PermissionMode = "full" | "ask" | "auto";
|
|
16
|
+
/** Order Shift+Tab cycles through. */
|
|
17
|
+
export declare const PERMISSION_MODES: readonly PermissionMode[];
|
|
18
|
+
/** Mode a fresh interactive or CLI session starts in. */
|
|
19
|
+
export declare const DEFAULT_PERMISSION_MODE: PermissionMode;
|
|
20
|
+
export declare function parsePermissionMode(value: unknown): PermissionMode | undefined;
|
|
21
|
+
export declare function cyclePermissionMode(mode: PermissionMode): PermissionMode;
|
|
22
|
+
type ModeListener = (mode: PermissionMode) => void;
|
|
23
|
+
/** What a session grant covers: one category of change, every call Jev could not classify, or (`ask`) every call. */
|
|
24
|
+
export type GrantKey = PermissionKind | "unclassified" | "all";
|
|
25
|
+
/**
|
|
26
|
+
* Session-wide permission state: the mode, and what the user allowed for the rest of the session. One
|
|
27
|
+
* controller is shared by every pi session of an agent.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PermissionController {
|
|
30
|
+
private current;
|
|
31
|
+
private readonly listeners;
|
|
32
|
+
private readonly granted;
|
|
33
|
+
private readonly created;
|
|
34
|
+
constructor(mode?: PermissionMode);
|
|
35
|
+
get mode(): PermissionMode;
|
|
36
|
+
/** Switches mode. Session grants end with the mode they were given in. */
|
|
37
|
+
set(mode: PermissionMode): void;
|
|
38
|
+
cycle(): PermissionMode;
|
|
39
|
+
subscribe(listener: ModeListener): () => void;
|
|
40
|
+
isGranted(key: GrantKey): boolean;
|
|
41
|
+
grant(keys: readonly GrantKey[]): void;
|
|
42
|
+
/** Records paths a successful call brought into existence: the agent's own files, not the user's originals. */
|
|
43
|
+
markCreated(paths: readonly string[]): void;
|
|
44
|
+
/** Whether the agent created this path, or a folder it lies in, earlier in this session. */
|
|
45
|
+
isCreated(path: string): boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface PermissionGateOptions {
|
|
48
|
+
readonly controller: PermissionController;
|
|
49
|
+
/**
|
|
50
|
+
* Jev, which classifies every gated call. Without one the gate cannot classify, so in `ask` and `auto` it
|
|
51
|
+
* asks the user about every `bash`, `write`, and `edit` call.
|
|
52
|
+
*/
|
|
53
|
+
readonly judge?: JevJudge;
|
|
54
|
+
/**
|
|
55
|
+
* What the user has said in this conversation: the first question, every follow-up, every steer. Jev judges
|
|
56
|
+
* the call against all of it. The host feeds it from the user's own input, so AutoRAG's internal phase
|
|
57
|
+
* prompts are never in it.
|
|
58
|
+
*/
|
|
59
|
+
readonly requests?: UserRequestLog;
|
|
60
|
+
/** Cap on the state shown to Jev, in characters. Default: Jev's context ceiling with a safety margin. */
|
|
61
|
+
readonly maxStateChars?: number;
|
|
62
|
+
/** Files the agent may always write and edit without Jev being asked (the config its self-configuration turn edits). */
|
|
63
|
+
readonly trustedPaths?: readonly string[];
|
|
64
|
+
}
|
|
65
|
+
/** Appended to the system prompt while a gate is active, so the model stays on the happy path. */
|
|
66
|
+
export declare const PERMISSION_PROMPT_ADDENDUM: string;
|
|
67
|
+
/** `ask` addendum: the user sees every call, so the model should batch work and still not refuse requests. */
|
|
68
|
+
export declare const ASK_PROMPT_ADDENDUM: string;
|
|
69
|
+
/**
|
|
70
|
+
* pi extension that gates what the agent does to existing files.
|
|
71
|
+
*
|
|
72
|
+
* Every `bash`, `write`, `edit`, and `manage_automations save` call is gated (reads, searches, and other tools
|
|
73
|
+
* never touch originals and are not asked about). In `ask` each one is put to the user. In `auto` Jev
|
|
74
|
+
* classifies it first: a call it finds safe runs, one it flags is approved by Jev when the user's request
|
|
75
|
+
* clearly covers it, and otherwise put to the user. Shift+Tab and `/permissions` switch the mode; the footer
|
|
76
|
+
* shows it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createPermissionGate(options: PermissionGateOptions): ExtensionFactory;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { JevJudge } from "./jev-extension.js";
|
|
3
|
+
import { type ProposedCall } from "./permission-paths.js";
|
|
4
|
+
import { type UserRequest } from "./user-requests.js";
|
|
5
|
+
/**
|
|
6
|
+
* What a tool call does to the user's existing files, as Jev judges it. A call can be several at once
|
|
7
|
+
* (`mkdir x && mv a x/ && rm b` is a move and a delete).
|
|
8
|
+
*
|
|
9
|
+
* `unclear` is for code whose effect cannot be told from what is shown: an unseen script file, `make clean`,
|
|
10
|
+
* an encoded command. It is asked about like any other category.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PERMISSION_KINDS: readonly ["delete", "move", "rename", "overwrite", "edit", "unclear"];
|
|
13
|
+
export type PermissionKind = (typeof PERMISSION_KINDS)[number];
|
|
14
|
+
export declare function permissionKindQuestionId(kind: PermissionKind): string;
|
|
15
|
+
/** Jev question id of the "may this run without asking?" check that `auto` mode adds to the same batch. */
|
|
16
|
+
export declare const PERMISSION_GATE_QUESTION_ID = "permission_gate";
|
|
17
|
+
/** Jev must be at least this sure before `auto` skips the user. Stricter than jev-use's own 0.5 default. */
|
|
18
|
+
export declare const AUTO_APPROVE_MIN_CONFIDENCE = 0.8;
|
|
19
|
+
/**
|
|
20
|
+
* Largest state the gate shows Jev, in characters. jev-use hands every question back ("oversized") once the
|
|
21
|
+
* state passes {@link DEFAULT_MAX_STATE_TOKENS} estimated tokens (about 4 characters each), and then the gate
|
|
22
|
+
* could not classify anything. The ceiling is read from jev-use so it cannot drift, and 10% is left for
|
|
23
|
+
* jev-use's own estimate being rough.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_MAX_STATE_CHARS: number;
|
|
26
|
+
/** The tool calls the gate classifies. Everything else (reads, searches, MCP tools) never touches originals. */
|
|
27
|
+
export declare function isGatedCall(toolName: string, input: Readonly<Record<string, unknown>>): boolean;
|
|
28
|
+
/** One line (or the command) naming what a call does, for the approval dialog and the notice. */
|
|
29
|
+
export declare function summarizeCall(call: ProposedCall): string;
|
|
30
|
+
/** The earlier calls of this session that ran and succeeded, oldest first. */
|
|
31
|
+
export declare function successfulCalls(branch: readonly SessionEntry[]): ProposedCall[];
|
|
32
|
+
export interface JudgedState {
|
|
33
|
+
readonly call: ProposedCall;
|
|
34
|
+
readonly requests: readonly UserRequest[];
|
|
35
|
+
readonly history: readonly ProposedCall[];
|
|
36
|
+
readonly maxStateChars: number;
|
|
37
|
+
/** Whether the agent itself brought this path into existence earlier in the session. */
|
|
38
|
+
readonly isCreated?: (path: string) => boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The state Jev judges, within `maxStateChars`: how to judge, what the user said, what the agent already did,
|
|
42
|
+
* and the call itself. The call and the history are cut first (the call to 40% of the budget, the history to
|
|
43
|
+
* 20%, each keeping the start and end), and the conversation gets whatever is left, so the whole stays under
|
|
44
|
+
* the ceiling however long any one part is.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildJudgedState({ call, requests, history, maxStateChars, isCreated }: JudgedState): string;
|
|
47
|
+
export interface FlaggedKind {
|
|
48
|
+
readonly kind: PermissionKind;
|
|
49
|
+
/** Jev's probability that the call is in this category; undefined when Jev was unsure and gave none. */
|
|
50
|
+
readonly probability: number | undefined;
|
|
51
|
+
}
|
|
52
|
+
export interface Approval {
|
|
53
|
+
readonly approved: boolean;
|
|
54
|
+
/** Why not, when it was not approved. */
|
|
55
|
+
readonly why: string;
|
|
56
|
+
}
|
|
57
|
+
/** Jev's reading of one call, or the reason it could not give one. */
|
|
58
|
+
export type Classification = {
|
|
59
|
+
readonly status: "classified";
|
|
60
|
+
readonly flagged: readonly FlaggedKind[];
|
|
61
|
+
readonly approval: Approval;
|
|
62
|
+
} | {
|
|
63
|
+
readonly status: "failed";
|
|
64
|
+
readonly why: string;
|
|
65
|
+
};
|
|
66
|
+
export type ClassifyOptions = JudgedState;
|
|
67
|
+
/**
|
|
68
|
+
* Asks Jev what `options.call` does to existing files, in one batched request. Never throws: no answer
|
|
69
|
+
* (unreachable, timed out, oversized, a missing verdict) is a `failed` classification, and the gate then
|
|
70
|
+
* asks the user instead of letting the call through.
|
|
71
|
+
*/
|
|
72
|
+
export declare function classifyCall(judge: JevJudge, options: ClassifyOptions): Promise<Classification>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** A tool call the gate is about to judge. */
|
|
2
|
+
export interface ProposedCall {
|
|
3
|
+
readonly tool: string;
|
|
4
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
}
|
|
7
|
+
/** `raw` as an absolute path: relative to `cwd`, with `~` expanded. */
|
|
8
|
+
export declare function resolveToolPath(raw: string, cwd: string): string;
|
|
9
|
+
export interface NamedPath {
|
|
10
|
+
readonly path: string;
|
|
11
|
+
/**
|
|
12
|
+
* True when the word is certainly a path (absolute, `~/`, `./`, `../`, a file name with an extension) or
|
|
13
|
+
* names something that exists. A plain word that exists nowhere (`fresh` in `mkdir fresh`) is only a
|
|
14
|
+
* candidate: the gate watches whether the call brings it into existence, and shows it to Jev only then.
|
|
15
|
+
*/
|
|
16
|
+
readonly always: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The paths a call names, for the facts Jev is shown (does each exist, did the agent make it). This does not
|
|
20
|
+
* decide anything and does not understand the command: it picks out the words that look like paths. A word it
|
|
21
|
+
* misses is a fact Jev lacks; a word it wrongly takes is a harmless "does not exist" line.
|
|
22
|
+
*/
|
|
23
|
+
export declare function pathsNamedBy(call: ProposedCall): NamedPath[];
|