@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.
- package/LICENSE +27 -0
- package/README.md +275 -0
- package/dist/agent/agent.d.ts +294 -0
- package/dist/agent/bash-tool.d.ts +41 -0
- package/dist/agent/datasource-skill.d.ts +45 -0
- package/dist/agent/emit-results-tool.d.ts +75 -0
- package/dist/agent/index.d.ts +11 -0
- package/dist/agent/jikji-find-tool.d.ts +73 -0
- package/dist/agent/search-all-tool.d.ts +36 -0
- package/dist/agent/search-bm25-tool.d.ts +18 -0
- package/dist/agent/search-datasource-tool.d.ts +26 -0
- package/dist/agent/search-documents.d.ts +56 -0
- package/dist/agent/search-minsync-tool.d.ts +24 -0
- package/dist/agent/system-prompt.d.ts +13 -0
- package/dist/agent/watch-refresh.d.ts +29 -0
- package/dist/cli/commands/feedback.d.ts +8 -0
- package/dist/cli/commands/health.d.ts +146 -0
- package/dist/cli/commands/index.d.ts +9 -0
- package/dist/cli/commands/init.d.ts +9 -0
- package/dist/cli/commands/memory.d.ts +8 -0
- package/dist/cli/commands/refresh.d.ts +19 -0
- package/dist/cli/commands/search.d.ts +34 -0
- package/dist/cli/commands/status.d.ts +7 -0
- package/dist/cli/commands/types.d.ts +10 -0
- package/dist/cli/commands/watch.d.ts +8 -0
- package/dist/cli/config.d.ts +172 -0
- package/dist/cli/index.d.ts +10 -0
- package/dist/cli/index.js +10845 -0
- package/dist/cli/output.d.ts +32 -0
- package/dist/config/home.d.ts +2 -0
- package/dist/datasource/access-context.d.ts +49 -0
- package/dist/datasource/diagnostics.d.ts +20 -0
- package/dist/datasource/index.d.ts +9 -0
- package/dist/datasource/polling.d.ts +51 -0
- package/dist/datasource/registry.d.ts +52 -0
- package/dist/datasource/result-filter.d.ts +63 -0
- package/dist/datasource/scope.d.ts +38 -0
- package/dist/datasource/skills/katok/client.d.ts +24 -0
- package/dist/datasource/skills/katok/index.d.ts +12 -0
- package/dist/datasource/skills/katok/methods.d.ts +40 -0
- package/dist/datasource/skills/katok/paths.d.ts +40 -0
- package/dist/datasource/skills/katok/skill.d.ts +33 -0
- package/dist/datasource/skills/katok/types.d.ts +146 -0
- package/dist/datasource/types.d.ts +183 -0
- package/dist/filesystem/file-lock.d.ts +16 -0
- package/dist/filesystem/source-paths.d.ts +38 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +9361 -0
- package/dist/jikji/answer-pack.d.ts +31 -0
- package/dist/jikji/client.d.ts +18 -0
- package/dist/jikji/diagnostics.d.ts +26 -0
- package/dist/jikji/index.d.ts +10 -0
- package/dist/jikji/installer.d.ts +46 -0
- package/dist/jikji/path-map.d.ts +8 -0
- package/dist/jikji/types.d.ts +112 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/loader.d.ts +3 -0
- package/dist/manifest/types.d.ts +8 -0
- package/dist/memory/check-memory-tool.d.ts +13 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/memory.d.ts +179 -0
- package/dist/memory/renderer.d.ts +6 -0
- package/dist/minsync/client.d.ts +14 -0
- package/dist/minsync/embedder-config.d.ts +22 -0
- package/dist/minsync/index.d.ts +7 -0
- package/dist/minsync/installer.d.ts +27 -0
- package/dist/minsync/method.d.ts +37 -0
- package/dist/minsync/paths.d.ts +4 -0
- package/dist/minsync/process.d.ts +10 -0
- package/dist/minsync/types.d.ts +33 -0
- package/dist/minsync/workspace.d.ts +14 -0
- package/dist/mirror/index-store.d.ts +16 -0
- package/dist/mirror/index.d.ts +5 -0
- package/dist/mirror/paths.d.ts +6 -0
- package/dist/mirror/sync.d.ts +38 -0
- package/dist/observability/run-log.d.ts +53 -0
- package/dist/parser/defaults.d.ts +6 -0
- package/dist/parser/eml.d.ts +6 -0
- package/dist/parser/errors.d.ts +5 -0
- package/dist/parser/hwp.d.ts +6 -0
- package/dist/parser/index.d.ts +10 -0
- package/dist/parser/ocr.d.ts +25 -0
- package/dist/parser/office.d.ts +16 -0
- package/dist/parser/opendataloader-pdf.d.ts +21 -0
- package/dist/parser/plain-text.d.ts +6 -0
- package/dist/parser/registry.d.ts +8 -0
- package/dist/parser/text.d.ts +2 -0
- package/dist/parser/types.d.ts +14 -0
- package/dist/parser/xml-text.d.ts +2 -0
- package/dist/retrieval/evidence-id.d.ts +16 -0
- package/dist/retrieval/index.d.ts +7 -0
- package/dist/retrieval/merger.d.ts +18 -0
- package/dist/retrieval/methods/bm25.d.ts +52 -0
- package/dist/retrieval/registry.d.ts +8 -0
- package/dist/retrieval/scope.d.ts +4 -0
- package/dist/retrieval/types.d.ts +64 -0
- package/dist/subagents/contracts.d.ts +90 -0
- package/dist/subagents/dispatch-templates.d.ts +104 -0
- package/dist/subagents/dispatch-validation.d.ts +169 -0
- package/dist/subagents/explorer-tools-extension.d.ts +4 -0
- package/dist/subagents/explorer-tools-extension.js +130 -0
- package/dist/subagents/local-models.d.ts +14 -0
- package/dist/subagents/model-policy.d.ts +31 -0
- package/dist/subagents/runtime.d.ts +52 -0
- package/dist/tool/index.d.ts +1 -0
- package/dist/types/errors.d.ts +4 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +66 -0
- package/skills/autorag/SKILL.md +149 -0
- package/skills/autorag-setup/SKILL.md +396 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
export type DispatchRejectionCode = "DISPATCH_MALFORMED" | "DISPATCH_ACTION_UNKNOWN" | "DISPATCH_ADMIN_MUTATION_FORBIDDEN" | "DISPATCH_CONTROL_FORBIDDEN" | "DISPATCH_SCHEDULE_FORBIDDEN" | "DISPATCH_ARTIFACTS_INVALID" | "DISPATCH_AGENT_SCOPE_INVALID" | "DISPATCH_AGENT_IDENTITY" | "DISPATCH_MODEL_MISMATCH" | "DISPATCH_ASSIGNMENT_INVALID" | "DISPATCH_QUERY_MISMATCH" | "DISPATCH_CWD_MISSING" | "DISPATCH_CWD_OUTSIDE_ROOTS" | "DISPATCH_NO_ACTIVE_QUERY";
|
|
2
|
+
export type DispatchKind = "launch" | "admin" | "control" | "mutation" | "schedule" | "hybrid" | "unknown";
|
|
3
|
+
export interface DispatchRejection {
|
|
4
|
+
readonly code: DispatchRejectionCode;
|
|
5
|
+
readonly field: string;
|
|
6
|
+
readonly dispatchKind: DispatchKind;
|
|
7
|
+
}
|
|
8
|
+
export declare class DispatchRejectionError extends Error {
|
|
9
|
+
readonly code: DispatchRejectionCode;
|
|
10
|
+
readonly field: string;
|
|
11
|
+
readonly exactFix: string;
|
|
12
|
+
readonly forceCorrectable: boolean;
|
|
13
|
+
readonly skeleton: string;
|
|
14
|
+
readonly dispatchKind: DispatchKind;
|
|
15
|
+
constructor(rejection: DispatchRejection, exactFix: string, forceCorrectable: boolean, skeleton: string);
|
|
16
|
+
}
|
|
17
|
+
export declare const EXACT_FIX_MAP: Readonly<Record<DispatchRejectionCode, string>>;
|
|
18
|
+
export declare const FORCE_CORRECTABLE_MAP: Readonly<Record<DispatchRejectionCode, boolean>>;
|
|
19
|
+
/** Backward-compatible aliases for the shared skeleton literals from dispatch-templates.ts. */
|
|
20
|
+
export declare const SKELETON_ADMIN = "{\"action\":\"list\"}";
|
|
21
|
+
export declare const SKELETON_SINGLE = "{\"agentScope\":\"user\",\"artifacts\":false,\"agent\":\"autorag-explorer\",\"model\":\"<configured-model>\",\"cwd\":\"<allowed-root>\",\"task\":\"<Assignment V1 block>\"}";
|
|
22
|
+
export declare const SKELETON_FANOUT = "{\"agentScope\":\"user\",\"artifacts\":false,\"tasks\":[{\"agent\":\"autorag-explorer\",\"model\":\"<configured-model>\",\"cwd\":\"<allowed-root>\",\"task\":\"<Assignment V1 block>\"}]}";
|
|
23
|
+
export declare function formatBlockReason(code: DispatchRejectionCode, field: string, exactFix: string, skeleton: string): string;
|
|
24
|
+
export declare function classifyAction(action: unknown): DispatchKind;
|
|
25
|
+
/**
|
|
26
|
+
* Classify a full dispatch invocation into a dispatch kind.
|
|
27
|
+
*
|
|
28
|
+
* Classification happens BEFORE any defaults or autofill.
|
|
29
|
+
* - If `action` is present and is a mutation/control/schedule → that kind (forbidden-action precedence).
|
|
30
|
+
* - If `action` is present and is a diagnostic (exact lowercase) → admin.
|
|
31
|
+
* - If `action` is present and is an explicit execution alias (exact lowercase: single/parallel/tasks) with launch shape → launch.
|
|
32
|
+
* - If `action` is present but is non-string, unknown, or a non-exact-lowercase value
|
|
33
|
+
* (e.g. "Create", "LIST", "Interrupt", 42) → unknown, regardless of launch fields.
|
|
34
|
+
* - If no `action` property but launch shape fields present (agent/task/tasks/chain/parallel) → launch.
|
|
35
|
+
* - Otherwise → unknown.
|
|
36
|
+
*/
|
|
37
|
+
export declare function classifyDispatch(args: unknown): DispatchKind;
|
|
38
|
+
/**
|
|
39
|
+
* Validate a diagnostic invocation against its exact allowed field set.
|
|
40
|
+
* Returns a DispatchRejection if invalid, undefined if valid.
|
|
41
|
+
* Diagnostics bypass explorer assignment/root/model launch gates.
|
|
42
|
+
*/
|
|
43
|
+
export declare function validateDiagnostic(args: Record<string, unknown>, action: string): DispatchRejection | undefined;
|
|
44
|
+
export declare function rejectForbiddenAction(action: string): DispatchRejection;
|
|
45
|
+
export interface PrepareContext {
|
|
46
|
+
/** Configured explorer model wire id (e.g. "provider/model-id"). */
|
|
47
|
+
readonly configuredModel: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
export interface PrepareResult {
|
|
50
|
+
/** Normalized args (defaults filled for launch, null-deleted). */
|
|
51
|
+
readonly args: Record<string, unknown>;
|
|
52
|
+
/** Whether any field was autofilled. */
|
|
53
|
+
readonly autofilled: {
|
|
54
|
+
readonly artifacts: boolean;
|
|
55
|
+
readonly agentScope: boolean;
|
|
56
|
+
readonly leafModelFillCount: number;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Composed prepareArguments for the subagent tool.
|
|
61
|
+
*
|
|
62
|
+
* Classifies first, then applies launch-only normalization (null-delete + missing defaults).
|
|
63
|
+
* Diagnostics never receive artifacts/agentScope/model defaults.
|
|
64
|
+
* Throws DispatchRejectionError on any validation failure.
|
|
65
|
+
*/
|
|
66
|
+
export declare function autoragPrepare(rawArgs: unknown, ctx: PrepareContext): Record<string, unknown>;
|
|
67
|
+
export declare function readAutofilled(args: Record<string, unknown>): {
|
|
68
|
+
readonly artifacts: boolean;
|
|
69
|
+
readonly agentScope: boolean;
|
|
70
|
+
readonly leafModelFillCount: number;
|
|
71
|
+
} | undefined;
|
|
72
|
+
interface LaunchLeaf {
|
|
73
|
+
readonly record: Record<string, unknown>;
|
|
74
|
+
readonly path: string;
|
|
75
|
+
}
|
|
76
|
+
export declare function getLaunchLeaves(args: Record<string, unknown>): readonly LaunchLeaf[];
|
|
77
|
+
/**
|
|
78
|
+
* Create a DispatchRejectionError from a DispatchRejection with proper
|
|
79
|
+
* exactFix, forceCorrectable, and skeleton selection.
|
|
80
|
+
* Used by beforeToolCall for post-schema rejections.
|
|
81
|
+
*
|
|
82
|
+
* When `args` is provided and the rejection is a launch kind, the skeleton is
|
|
83
|
+
* selected from the args shape: fanout if `tasks`/`chain`/`parallel` are
|
|
84
|
+
* present, single otherwise. When `args` is omitted, launch rejections default
|
|
85
|
+
* to the single skeleton. Non-launch kinds always use the admin skeleton.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createDispatchRejectionError(rejection: DispatchRejection, args?: Record<string, unknown>): DispatchRejectionError;
|
|
88
|
+
/** Backward-compatible aliases for shared V1 sentinel constants. */
|
|
89
|
+
export declare const AUTORAG_ASSIGNMENT_V1_START = "<<<AUTORAG_ASSIGNMENT_V1>>>";
|
|
90
|
+
export declare const AUTORAG_ASSIGNMENT_V1_END = "<<<END_AUTORAG_ASSIGNMENT_V1>>>";
|
|
91
|
+
export interface ParsedAssignment {
|
|
92
|
+
readonly originalQuery: string;
|
|
93
|
+
readonly method: string;
|
|
94
|
+
readonly queryVariants: readonly string[];
|
|
95
|
+
/** Whether V1 (true) or legacy (false) format was used. */
|
|
96
|
+
readonly isV1: boolean;
|
|
97
|
+
}
|
|
98
|
+
/** Backward-compatible aliases for shared role line constants. */
|
|
99
|
+
export declare const ROLE_LINE_RETRIEVED_AT = "Required handoff: include retrievedAt.";
|
|
100
|
+
export declare const ROLE_LINE_TEMPORAL_METADATA = "Required handoff: include temporal metadata.";
|
|
101
|
+
export declare function canonicalRoleLines(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Parse a task string as an Assignment V1 block.
|
|
104
|
+
*
|
|
105
|
+
* V1 sentinels:
|
|
106
|
+
* - Start line (after stripping single trailing CR) must equal <<<AUTORAG_ASSIGNMENT_V1>>>
|
|
107
|
+
* - End line (after stripping single trailing CR) must equal <<<END_AUTORAG_ASSIGNMENT_V1>>>
|
|
108
|
+
* - End sentinel at EOF valid
|
|
109
|
+
* - Exactly one V1 block; duplicate/malformed/unterminated → reject
|
|
110
|
+
* - Body: one JSON object with exactly keys originalQuery, method, queryVariants
|
|
111
|
+
* - originalQuery: string, trimmed nonempty
|
|
112
|
+
* - method: string, trimmed nonempty
|
|
113
|
+
* - queryVariants: nonempty array of nonempty strings
|
|
114
|
+
* - Extra/missing keys/wrong types → reject
|
|
115
|
+
*
|
|
116
|
+
* Returns undefined if no V1 sentinel found (caller should try legacy).
|
|
117
|
+
* Returns ParsedAssignment on success.
|
|
118
|
+
* Throws DispatchRejectionError on malformed V1.
|
|
119
|
+
*/
|
|
120
|
+
export declare function parseAssignmentV1(task: string): ParsedAssignment | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Parse a task string as a legacy prose assignment.
|
|
123
|
+
*
|
|
124
|
+
* Legacy (n4 retained):
|
|
125
|
+
* - Full logical lines; optional leading whitespace; optional `- ` bullet; optional matching `**` around label.
|
|
126
|
+
* - Case/space normalize labels; value = remainder of same line only.
|
|
127
|
+
* - Labels: Original query; Selected retrieval method | Retrieval method; Query variants | Query variant.
|
|
128
|
+
* - Reorder OK; exactly once each; Query variants split on `;`, trim, reject empty segments.
|
|
129
|
+
* - Later label-looking line → reject.
|
|
130
|
+
* - Prefix/suffix outside three lines preserved.
|
|
131
|
+
* - Multiline / special / label-looking content inside values → V1 required, not legacy.
|
|
132
|
+
*
|
|
133
|
+
* Returns undefined if no legacy labels found.
|
|
134
|
+
* Throws DispatchRejectionError on malformed legacy.
|
|
135
|
+
*/
|
|
136
|
+
export declare function parseLegacyAssignment(task: string): ParsedAssignment | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Parse a task string as either V1 or legacy assignment.
|
|
139
|
+
* Tries V1 first; if no V1 sentinels, tries legacy.
|
|
140
|
+
* Returns undefined if neither format is found.
|
|
141
|
+
* Throws DispatchRejectionError on malformed input.
|
|
142
|
+
*/
|
|
143
|
+
export declare function parseAssignment(task: string): ParsedAssignment | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Insert canonical role lines into a task string, byte-idempotent.
|
|
146
|
+
*
|
|
147
|
+
* 1. Remove all existing exact canonical role lines (the two literals after CR-strip).
|
|
148
|
+
* 2. Insert exactly one of each immediately after end sentinel (V1) or
|
|
149
|
+
* immediately after the last of the three recognized legacy label lines.
|
|
150
|
+
* 3. Preserve all other suffix bytes and original newline style.
|
|
151
|
+
* 4. Repeat rendering is byte-idempotent.
|
|
152
|
+
*/
|
|
153
|
+
export declare function ensureRoleLines(task: string): string;
|
|
154
|
+
export interface PostSchemaContext {
|
|
155
|
+
readonly configuredModel: string | undefined;
|
|
156
|
+
readonly currentQuery: string | undefined;
|
|
157
|
+
readonly allowedRoots: readonly string[];
|
|
158
|
+
readonly workspaceRoot: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Post-schema validation for launch invocations.
|
|
162
|
+
* Checks: assignment parse, structural query equality, role lines,
|
|
163
|
+
* cwd realpath/allowed roots, model match.
|
|
164
|
+
*
|
|
165
|
+
* Returns a DispatchRejection if invalid, undefined if valid.
|
|
166
|
+
* Also normalizes cwd to canonical realpath on success.
|
|
167
|
+
*/
|
|
168
|
+
export declare function validateLaunchPostSchema(args: Record<string, unknown>, ctx: PostSchemaContext): DispatchRejection | undefined;
|
|
169
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
18
|
+
|
|
19
|
+
// src/subagents/explorer-tools-extension.ts
|
|
20
|
+
import { realpath, stat } from "node:fs/promises";
|
|
21
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
22
|
+
import {
|
|
23
|
+
createFindToolDefinition,
|
|
24
|
+
createGrepToolDefinition,
|
|
25
|
+
createLsToolDefinition,
|
|
26
|
+
createReadToolDefinition
|
|
27
|
+
} from "@earendil-works/pi-coding-agent";
|
|
28
|
+
var PARENT_TRAVERSAL_SEGMENT = /(^|[/\\])\.\.($|[/\\])/;
|
|
29
|
+
var TOOL_METADATA_CWD = "/";
|
|
30
|
+
|
|
31
|
+
class ExplorerPathContainmentError extends Error {
|
|
32
|
+
code;
|
|
33
|
+
requestedPath;
|
|
34
|
+
root;
|
|
35
|
+
constructor(message, requestedPath, root) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "ExplorerPathContainmentError";
|
|
38
|
+
this.code = "EXPLORER_PATH_CONTAINMENT";
|
|
39
|
+
this.requestedPath = requestedPath;
|
|
40
|
+
this.root = root;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function isMissingPathError(error) {
|
|
44
|
+
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
45
|
+
}
|
|
46
|
+
function isEqualOrDescendant(root, target) {
|
|
47
|
+
const pathFromRoot = relative(root, target);
|
|
48
|
+
return pathFromRoot === "" || pathFromRoot !== ".." && !pathFromRoot.startsWith(`..${sep}`) && !isAbsolute(pathFromRoot);
|
|
49
|
+
}
|
|
50
|
+
async function resolveExistingTargetOrNearestParent(target) {
|
|
51
|
+
try {
|
|
52
|
+
return await realpath(target);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (!isMissingPathError(error))
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
let candidateParent = dirname(target);
|
|
58
|
+
while (true) {
|
|
59
|
+
try {
|
|
60
|
+
const realParent = await realpath(candidateParent);
|
|
61
|
+
return resolve(realParent, relative(candidateParent, target));
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (!isMissingPathError(error))
|
|
64
|
+
throw error;
|
|
65
|
+
const nextParent = dirname(candidateParent);
|
|
66
|
+
if (nextParent === candidateParent)
|
|
67
|
+
throw error;
|
|
68
|
+
candidateParent = nextParent;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function resolveExplorerRoot(cwd) {
|
|
73
|
+
const root = await realpath(cwd);
|
|
74
|
+
if (!(await stat(root)).isDirectory()) {
|
|
75
|
+
throw new Error(`Explorer assigned cwd is not a directory: ${cwd}`);
|
|
76
|
+
}
|
|
77
|
+
return root;
|
|
78
|
+
}
|
|
79
|
+
async function resolveContainedPath(root, requestedPath) {
|
|
80
|
+
if (PARENT_TRAVERSAL_SEGMENT.test(requestedPath)) {
|
|
81
|
+
throw new ExplorerPathContainmentError(`Explorer filesystem containment rejected parent traversal path: ${requestedPath}`, requestedPath, root);
|
|
82
|
+
}
|
|
83
|
+
const target = await resolveExistingTargetOrNearestParent(resolve(root, requestedPath));
|
|
84
|
+
if (!isEqualOrDescendant(root, target)) {
|
|
85
|
+
throw new ExplorerPathContainmentError(`Explorer filesystem containment rejected path outside assigned cwd: ${requestedPath}`, requestedPath, root);
|
|
86
|
+
}
|
|
87
|
+
return { root, target };
|
|
88
|
+
}
|
|
89
|
+
function registerExplorerTools(pi) {
|
|
90
|
+
let pinnedRoot;
|
|
91
|
+
const getPinnedRoot = (cwd) => {
|
|
92
|
+
pinnedRoot ??= resolveExplorerRoot(cwd);
|
|
93
|
+
return pinnedRoot;
|
|
94
|
+
};
|
|
95
|
+
const readTool = createReadToolDefinition(TOOL_METADATA_CWD);
|
|
96
|
+
pi.registerTool({
|
|
97
|
+
...readTool,
|
|
98
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
99
|
+
const { root, target } = await resolveContainedPath(await getPinnedRoot(ctx.cwd), params.path);
|
|
100
|
+
return createReadToolDefinition(root).execute(toolCallId, { ...params, path: target }, signal, onUpdate, ctx);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const grepTool = createGrepToolDefinition(TOOL_METADATA_CWD);
|
|
104
|
+
pi.registerTool({
|
|
105
|
+
...grepTool,
|
|
106
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
107
|
+
const { root, target } = await resolveContainedPath(await getPinnedRoot(ctx.cwd), params.path ?? ".");
|
|
108
|
+
return createGrepToolDefinition(root).execute(toolCallId, { ...params, path: target }, signal, onUpdate, ctx);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const findTool = createFindToolDefinition(TOOL_METADATA_CWD);
|
|
112
|
+
pi.registerTool({
|
|
113
|
+
...findTool,
|
|
114
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
115
|
+
const { root, target } = await resolveContainedPath(await getPinnedRoot(ctx.cwd), params.path ?? ".");
|
|
116
|
+
return createFindToolDefinition(root).execute(toolCallId, { ...params, path: target }, signal, onUpdate, ctx);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const lsTool = createLsToolDefinition(TOOL_METADATA_CWD);
|
|
120
|
+
pi.registerTool({
|
|
121
|
+
...lsTool,
|
|
122
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
123
|
+
const { root, target } = await resolveContainedPath(await getPinnedRoot(ctx.cwd), params.path ?? ".");
|
|
124
|
+
return createLsToolDefinition(root).execute(toolCallId, { ...params, path: target }, signal, onUpdate, ctx);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
registerExplorerTools as default
|
|
130
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Model } from "@earendil-works/pi-ai";
|
|
2
|
+
export interface LocalAutoRAGModels {
|
|
3
|
+
readonly provider: string;
|
|
4
|
+
readonly apiKey: string;
|
|
5
|
+
readonly orchestrator: Model<"openai-responses">;
|
|
6
|
+
readonly explorer: Model<"openai-responses">;
|
|
7
|
+
}
|
|
8
|
+
export interface LoadLocalAutoRAGModelsOptions {
|
|
9
|
+
readonly configPath?: string;
|
|
10
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
11
|
+
readonly orchestratorModelId?: string;
|
|
12
|
+
readonly explorerModelId?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function loadLocalAutoRAGModels(options?: LoadLocalAutoRAGModelsOptions): LocalAutoRAGModels;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const ORCHESTRATOR_MODEL_ID: "gpt-5.6-sol";
|
|
2
|
+
export declare const EXPLORER_MODEL_ID: "gpt-5.6-luna";
|
|
3
|
+
export declare const REQUIRED_MODEL_IDS: Readonly<{
|
|
4
|
+
orchestrator: "gpt-5.6-sol";
|
|
5
|
+
explorer: "gpt-5.6-luna";
|
|
6
|
+
}>;
|
|
7
|
+
export type ModelRole = keyof typeof REQUIRED_MODEL_IDS;
|
|
8
|
+
export interface ModelReference {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly provider?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ValidatedModelPolicy {
|
|
13
|
+
readonly orchestrator: ModelReference;
|
|
14
|
+
readonly explorer: ModelReference;
|
|
15
|
+
}
|
|
16
|
+
export type ModelPolicyErrorCode = "INVALID_POLICY_OBJECT" | "MISSING_REQUIRED_MODEL" | "INVALID_MODEL_REFERENCE";
|
|
17
|
+
export declare class ModelPolicyError extends Error {
|
|
18
|
+
readonly code: ModelPolicyErrorCode;
|
|
19
|
+
readonly role?: ModelRole;
|
|
20
|
+
readonly expected?: string;
|
|
21
|
+
readonly actual?: string;
|
|
22
|
+
constructor(code: ModelPolicyErrorCode, message: string, options?: {
|
|
23
|
+
readonly role?: ModelRole;
|
|
24
|
+
readonly expected?: string;
|
|
25
|
+
readonly actual?: string;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export declare function validateModelPolicy(value: unknown): ValidatedModelPolicy;
|
|
29
|
+
export declare function assertModelPolicy(value: unknown): asserts value is ValidatedModelPolicy;
|
|
30
|
+
export declare function isModelPolicy(value: unknown): value is ValidatedModelPolicy;
|
|
31
|
+
export declare function requiredModelId(role: ModelRole): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { type Api, type Model } from "@earendil-works/pi-ai";
|
|
3
|
+
import { type AgentSession } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
export declare const EXPLORER_TOOLS_EXTENSION_PATH: string;
|
|
5
|
+
export declare const AUTORAG_EXPLORER_AGENT_MANAGED_VERSION = 2;
|
|
6
|
+
export declare const AUTORAG_EXPLORER_AGENT_DEFINITION: string;
|
|
7
|
+
export interface MandatorySubagentSessionOptions {
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly model: Model<Api>;
|
|
10
|
+
readonly explorerModel?: Model<Api>;
|
|
11
|
+
readonly systemPrompt: string;
|
|
12
|
+
readonly tools: readonly AgentTool[];
|
|
13
|
+
readonly extensionPath?: string;
|
|
14
|
+
readonly apiKey?: string;
|
|
15
|
+
readonly providerApiKeys?: Readonly<Record<string, string>>;
|
|
16
|
+
readonly agentDir?: string;
|
|
17
|
+
readonly sessionDir?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface MandatorySubagentSession {
|
|
20
|
+
readonly session: AgentSession;
|
|
21
|
+
readonly extensionPath: string;
|
|
22
|
+
}
|
|
23
|
+
export interface HealthSubagentProbeSessionOptions {
|
|
24
|
+
readonly cwd: string;
|
|
25
|
+
readonly model: Model<Api>;
|
|
26
|
+
readonly explorerModel?: Model<Api>;
|
|
27
|
+
readonly systemPrompt: string;
|
|
28
|
+
readonly tools: readonly AgentTool[];
|
|
29
|
+
readonly extensionPath?: string;
|
|
30
|
+
readonly apiKey?: string;
|
|
31
|
+
readonly providerApiKeys?: Readonly<Record<string, string>>;
|
|
32
|
+
readonly agentDir: string;
|
|
33
|
+
readonly sessionDir: string;
|
|
34
|
+
}
|
|
35
|
+
export interface HealthSubagentProbeSession {
|
|
36
|
+
readonly session: AgentSession;
|
|
37
|
+
readonly extensionPath: string;
|
|
38
|
+
readonly dispose: () => void;
|
|
39
|
+
}
|
|
40
|
+
export declare function createMandatorySubagentSession(options: MandatorySubagentSessionOptions): Promise<MandatorySubagentSession>;
|
|
41
|
+
/**
|
|
42
|
+
* Create a short-lived subagent session for the `autorag health` explorer probe.
|
|
43
|
+
*
|
|
44
|
+
* Unlike {@link createMandatorySubagentSession}, this requires absolute
|
|
45
|
+
* `agentDir` and `sessionDir` (typically under a caller-created temp
|
|
46
|
+
* directory) so the probe never touches durable home state. On a lease
|
|
47
|
+
* conflict — i.e. when another live session holds a different child
|
|
48
|
+
* environment/registry routing — the error is rethrown with a stable
|
|
49
|
+
* "concurrent AutoRAG session busy" message so the health command can map
|
|
50
|
+
* it to `subagent_failed`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createHealthSubagentProbeSession(options: HealthSubagentProbeSessionOptions): Promise<HealthSubagentProbeSession>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NotImplementedError } from "./errors.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autorag/librarian",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Self-evolving librarian agent on Pi framework with pluggable retrieval methods",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Marker-Inc-Korea/AutoRAG.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"autorag": "./dist/cli/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"skills",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "bun build src/index.ts src/cli/index.ts src/subagents/explorer-tools-extension.ts --outdir dist --target node --packages external && tsc -p tsconfig.build.json && node scripts/fixup-dts.mjs",
|
|
32
|
+
"prepublishOnly": "bun run typecheck && bun run build",
|
|
33
|
+
"prepare": "bun run build",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"check": "biome check --write .",
|
|
36
|
+
"typecheck": "tsc --noEmit"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=24.0.0"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@earendil-works/pi-agent-core": "^0.80.10",
|
|
43
|
+
"@earendil-works/pi-ai": "^0.80.10",
|
|
44
|
+
"@earendil-works/pi-coding-agent": "0.80.10",
|
|
45
|
+
"@opendataloader/pdf": "^2.4.7",
|
|
46
|
+
"@pngwasi/node-tantivy-binding": "^0.3.4",
|
|
47
|
+
"chardet": "^2.2.0",
|
|
48
|
+
"fast-xml-parser": "^5.9.3",
|
|
49
|
+
"iconv-lite": "^0.7.2",
|
|
50
|
+
"jszip": "^3.10.1",
|
|
51
|
+
"mailparser": "^3.9.12",
|
|
52
|
+
"pi-subagents": "0.35.1",
|
|
53
|
+
"slides-grab": "^1.3.1",
|
|
54
|
+
"smol-toml": "1.7.0",
|
|
55
|
+
"tesseract.js": "^7.0.0",
|
|
56
|
+
"typebox": "^1.1.24",
|
|
57
|
+
"yaml": "^2.8.2"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@biomejs/biome": "2.3.5",
|
|
61
|
+
"@types/mailparser": "^3.4.6",
|
|
62
|
+
"@types/node": "^24.3.0",
|
|
63
|
+
"typescript": "^5.7.3",
|
|
64
|
+
"vitest": "^4.1.10"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: autorag
|
|
3
|
+
description: Use an already configured AutoRAG librarian agent to search, summarize, compare, and answer questions from local document collections. Use autorag-setup instead for provider/model discovery, first-time configuration, or selecting folders to index.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AutoRAG Librarian Skill
|
|
7
|
+
|
|
8
|
+
Use this skill when AutoRAG is already configured and the user asks to search,
|
|
9
|
+
summarize, compare, or answer questions from local PDFs, wikis, notes, research
|
|
10
|
+
papers, or knowledge bases. For first-time configuration, missing model/provider
|
|
11
|
+
settings, subscription or API-provider detection, or changing indexed folders,
|
|
12
|
+
use the `autorag-setup` skill instead.
|
|
13
|
+
|
|
14
|
+
AutoRAG is invoked through the `autorag` CLI. It is non-destructive: it reads
|
|
15
|
+
source files and writes indexes under the configured workspace's `.autorag/`
|
|
16
|
+
directory and, when enabled, Jikji's per-source `.jikji/` caches. Never move,
|
|
17
|
+
rename, or delete source files.
|
|
18
|
+
|
|
19
|
+
## Preflight
|
|
20
|
+
|
|
21
|
+
Confirm that `~/.autorag/config.json` exists (or an explicit `--config` /
|
|
22
|
+
`AUTORAG_CONFIG` path). Inspect that non-secret config for usable
|
|
23
|
+
`searchPaths`/`agents` without printing credentials. Then run:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
autorag status
|
|
27
|
+
autorag health
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`status` is model-free and path-opaque: it reports corpus freshness and index
|
|
31
|
+
health, not absolute filesystem paths or role-model auth. `health` checks
|
|
32
|
+
model/provider auth and explorer subagent setup: it resolves both role models,
|
|
33
|
+
verifies credential presence, and (unless `--skip-probes`) probes a completion
|
|
34
|
+
call per role. Use `health` to diagnose model, provider, auth, timeout, or
|
|
35
|
+
subagent dispatch failures before searching. If configuration, authentication,
|
|
36
|
+
role models, or indexes are missing or unhealthy, stop this workflow and use
|
|
37
|
+
`autorag-setup`; do not guess private providers or model IDs.
|
|
38
|
+
|
|
39
|
+
## Searching
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
autorag search "what were the key findings in the Q3 report" --top-k 5
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
AutoRAG returns curated, numbered knowledge units grounded in sources plus a
|
|
46
|
+
`sessionId` needed for feedback. Use:
|
|
47
|
+
|
|
48
|
+
- `--scope` to narrow to a configured virtual sub-path
|
|
49
|
+
- `--tags tag1,tag2` only when trusted datasource access is already configured
|
|
50
|
+
server-side; tags narrow already-allowed results and never grant new access
|
|
51
|
+
- `--json` for structured output (`sessionId`, numbered `results`, `answer`)
|
|
52
|
+
- `--debug` only when diagnostics are needed
|
|
53
|
+
|
|
54
|
+
Do not bypass AutoRAG with ad hoc raw search when the user explicitly requested
|
|
55
|
+
the librarian agent. Search requires a resolvable orchestrator/explorer model
|
|
56
|
+
pair from config, flags, env, or the authenticated local runtime. When `autorag
|
|
57
|
+
search` fails for a model, provider, auth, timeout, or subagent reason, the
|
|
58
|
+
error output includes a hint pointing to `autorag health` for diagnosis.
|
|
59
|
+
|
|
60
|
+
Record feedback so retrieval memory learns which results were useful:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
autorag feedback <sessionId> --useful 1,3 --not-useful 2
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Supply at least one of `--useful` or `--not-useful`. Numbers refer to the
|
|
67
|
+
numbered knowledge units from that session's search output.
|
|
68
|
+
|
|
69
|
+
## Maintenance
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
autorag status
|
|
73
|
+
autorag health
|
|
74
|
+
autorag refresh
|
|
75
|
+
autorag refresh --method bm25,minsync
|
|
76
|
+
autorag watch --once
|
|
77
|
+
autorag watch
|
|
78
|
+
autorag refresh --force
|
|
79
|
+
autorag index rebuild --yes
|
|
80
|
+
autorag index reset --method bm25 --yes
|
|
81
|
+
autorag memory inspect
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Use `refresh` after source documents change (parses sources and resyncs BM25 /
|
|
85
|
+
MinSync / datasources / optional Jikji prepare). Prefer bounded refresh over
|
|
86
|
+
reset. `watch --once` is the preferred single tick for scheduled jobs; long-running
|
|
87
|
+
`watch` keeps an fs event loop open for interactive sessions.
|
|
88
|
+
`--method <csv>` (e.g. `--method bm25,minsync,parsed`) restricts which methods
|
|
89
|
+
refresh/index run; when omitted all methods run. BM25 and MinSync are enabled
|
|
90
|
+
by default — no explicit configuration is needed for standard lexical + semantic
|
|
91
|
+
retrieval. MinSync uses a pre-installed binary (`autoInstall: false`); configure
|
|
92
|
+
`minSync.embedder` via `autorag init --embedder-*` flags for remote embedding.
|
|
93
|
+
|
|
94
|
+
### Keep indexes fresh on a schedule (agent responsibility)
|
|
95
|
+
|
|
96
|
+
There is **no always-on network service** in the CLI. Agents and operators must
|
|
97
|
+
install an OS-appropriate periodic job that runs a model-free index tick:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Preferred scheduled command (single non-daemon refresh)
|
|
101
|
+
NODE_OPTIONS=--max-old-space-size=16384 autorag watch --once
|
|
102
|
+
# Equivalent one-shot refresh
|
|
103
|
+
NODE_OPTIONS=--max-old-space-size=16384 autorag refresh
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Schedule guidance by OS (typical interval: every 15–30 minutes; never more often
|
|
107
|
+
than the corpus can finish refreshing):
|
|
108
|
+
|
|
109
|
+
| OS | Preferred scheduler | Pattern |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| macOS | `cron` or `launchd` (`~/Library/LaunchAgents`) | `*/30 * * * * ... autorag watch --once` or a KeepAlive=false StartInterval plist |
|
|
112
|
+
| Linux | `cron` / `systemd --user` timer | crontab `*/30 * * * *` or a oneshot service + timer |
|
|
113
|
+
| Windows | Task Scheduler | repeating task every 30 minutes running `autorag watch --once` under the user profile |
|
|
114
|
+
|
|
115
|
+
Rules for scheduled watch:
|
|
116
|
+
|
|
117
|
+
1. Prefer `autorag watch --once` (or `autorag refresh`) over a permanent
|
|
118
|
+
long-running `autorag watch` daemon in user agents — daemons die on reboot
|
|
119
|
+
and are harder to supervise from skill workflows.
|
|
120
|
+
2. Use the same config the search path uses (`~/.autorag/config.json` or an
|
|
121
|
+
explicit `--config` / `AUTORAG_CONFIG`).
|
|
122
|
+
3. Raise Node heap for large home trees: `NODE_OPTIONS=--max-old-space-size=16384`.
|
|
123
|
+
4. Redirect logs somewhere under the home/user temp tree, never into source
|
|
124
|
+
document folders.
|
|
125
|
+
5. After install/setup, **create or verify** the scheduled job before claiming
|
|
126
|
+
ongoing indexing is covered. Re-check with `crontab -l`, `systemctl --user list-timers`,
|
|
127
|
+
or Task Scheduler inspection when the user asks about freshness.
|
|
128
|
+
6. Do not schedule concurrent overlapping ticks; if a prior refresh is still
|
|
129
|
+
running, skip or wait (lock/log rather than stampeding MiniSync/BM25 writers).
|
|
130
|
+
|
|
131
|
+
Destructive index commands:
|
|
132
|
+
|
|
133
|
+
- `autorag index reset --yes` removes parsed, BM25, and MinSync directories under
|
|
134
|
+
workspace `.autorag` only. Add `--method bm25|minsync|parsed` to scope which
|
|
135
|
+
indexes are removed (e.g. `--method bm25` removes only the BM25 index).
|
|
136
|
+
- `autorag index rebuild --yes` resets those indexes then forced-refreshes.
|
|
137
|
+
`--method` scopes both the reset and the rebuild refresh.
|
|
138
|
+
|
|
139
|
+
Never run reset/rebuild against source documents. `memory inspect` is
|
|
140
|
+
read-only and path-opaque.
|
|
141
|
+
|
|
142
|
+
## Rules
|
|
143
|
+
|
|
144
|
+
- Use only configured and approved search paths.
|
|
145
|
+
- Never expose provider credentials or authentication payloads.
|
|
146
|
+
- Never invent or reveal private provider names or model IDs.
|
|
147
|
+
- Never treat a consumer subscription as API access without runtime evidence.
|
|
148
|
+
- Preserve real source mapping and numbered feedback identifiers.
|
|
149
|
+
- Prefer `--json` when another agent must consume the result programmatically.
|