@jarkkojs/readseek-api 0.11.1 → 0.11.3
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/dist/contract.d.ts +2 -6
- package/dist/index.js +12 -26
- package/dist/policy.d.ts +1 -2
- package/package.json +2 -2
package/dist/contract.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare const PARAM_DESCRIPTIONS: {
|
|
|
12
12
|
readonly projectSearchPath: "File or directory to search; defaults to the project directory";
|
|
13
13
|
readonly searchPath: "File or directory to search; defaults to the current directory";
|
|
14
14
|
readonly language: "Language override when auto-detection is ambiguous";
|
|
15
|
-
readonly languageOverride: "Language override";
|
|
16
15
|
readonly languageSymbol: "Language override for symbol replacement";
|
|
17
16
|
readonly pattern: "AST pattern (ast-grep style), such as console.log($$$ARGS)";
|
|
18
17
|
readonly patternContext: "Surrounding code context for sub-statement patterns";
|
|
@@ -29,14 +28,10 @@ export declare const PARAM_DESCRIPTIONS: {
|
|
|
29
28
|
readonly end: "Last line to include";
|
|
30
29
|
readonly limit: "Maximum number of lines to include";
|
|
31
30
|
readonly depth: "Maximum structural depth for structure output; defaults to 1 in agent tools";
|
|
32
|
-
readonly offset: "One-based starting line";
|
|
33
|
-
readonly readLimit: "Maximum lines to return";
|
|
34
|
-
readonly symbolRead: "Symbol name to read";
|
|
35
|
-
readonly bundle: "Include related symbols from the same file; requires symbol";
|
|
36
31
|
readonly level: "Explicit inference level: low (default), medium, or high";
|
|
37
32
|
readonly include: "Additional caption tasks: text and/or objects";
|
|
38
33
|
readonly kind: "Restrict structure to this node kind";
|
|
39
|
-
readonly outline: "
|
|
34
|
+
readonly outline: "Show outline of document hierarchy or source symbols";
|
|
40
35
|
readonly noAnchors: "Omit source line anchors";
|
|
41
36
|
readonly text: "Literal native text query; adapter find_text also supports regex via pattern";
|
|
42
37
|
readonly edits: "Use set_line, replace_lines, insert_after, replace_symbol, or replace";
|
|
@@ -92,6 +87,7 @@ export declare const TOOL_DESCRIPTIONS: {
|
|
|
92
87
|
readonly rename_symbol: "Rename a symbol at a line or hash cursor with binding-aware edits and stale-plan protection.";
|
|
93
88
|
readonly write_file: "Create or replace a complete text file and return `LINE:HASH` anchors. Use `edit_text` for small changes.";
|
|
94
89
|
};
|
|
90
|
+
export declare function rewriteBacktickedToolNames(text: string, aliases?: Readonly<Partial<Record<ToolName, string>>>): string;
|
|
95
91
|
export declare function renderToolDescription(name: ToolName, aliases?: Readonly<Partial<Record<ToolName, string>>>): string;
|
|
96
92
|
export type JsonSchema = {
|
|
97
93
|
type: "object";
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,6 @@ var PARAM_DESCRIPTIONS = {
|
|
|
32
32
|
projectSearchPath: "File or directory to search; defaults to the project directory",
|
|
33
33
|
searchPath: "File or directory to search; defaults to the current directory",
|
|
34
34
|
language: "Language override when auto-detection is ambiguous",
|
|
35
|
-
languageOverride: "Language override",
|
|
36
35
|
languageSymbol: "Language override for symbol replacement",
|
|
37
36
|
pattern: "AST pattern (ast-grep style), such as console.log($$$ARGS)",
|
|
38
37
|
patternContext: "Surrounding code context for sub-statement patterns",
|
|
@@ -49,14 +48,10 @@ var PARAM_DESCRIPTIONS = {
|
|
|
49
48
|
end: "Last line to include",
|
|
50
49
|
limit: "Maximum number of lines to include",
|
|
51
50
|
depth: "Maximum structural depth for structure output; defaults to 1 in agent tools",
|
|
52
|
-
offset: "One-based starting line",
|
|
53
|
-
readLimit: "Maximum lines to return",
|
|
54
|
-
symbolRead: "Symbol name to read",
|
|
55
|
-
bundle: "Include related symbols from the same file; requires symbol",
|
|
56
51
|
level: "Explicit inference level: low (default), medium, or high",
|
|
57
52
|
include: "Additional caption tasks: text and/or objects",
|
|
58
53
|
kind: "Restrict structure to this node kind",
|
|
59
|
-
outline: "
|
|
54
|
+
outline: "Show outline of document hierarchy or source symbols",
|
|
60
55
|
noAnchors: "Omit source line anchors",
|
|
61
56
|
text: "Literal native text query; adapter find_text also supports regex via pattern",
|
|
62
57
|
edits: "Use set_line, replace_lines, insert_after, replace_symbol, or replace",
|
|
@@ -112,11 +107,14 @@ var TOOL_DESCRIPTIONS = {
|
|
|
112
107
|
rename_symbol: "Rename a symbol at a line or hash cursor with binding-aware edits and stale-plan protection.",
|
|
113
108
|
write_file: "Create or replace a complete text file and return `LINE:HASH` anchors. Use `edit_text` for small changes."
|
|
114
109
|
};
|
|
110
|
+
function rewriteBacktickedToolNames(text, aliases = {}) {
|
|
111
|
+
return TOOL_NAMES.reduce((rewritten, toolName) => rewritten.replaceAll(`\`${toolName}\``, `\`${aliases[toolName] ?? toolName}\``), text);
|
|
112
|
+
}
|
|
115
113
|
function renderToolDescription(name, aliases = {}) {
|
|
116
114
|
const desc = TOOL_DESCRIPTIONS[name];
|
|
117
115
|
if (!desc)
|
|
118
116
|
throw new Error(`Missing TOOL_DESCRIPTIONS for ${name}`);
|
|
119
|
-
return
|
|
117
|
+
return rewriteBacktickedToolNames(desc, aliases);
|
|
120
118
|
}
|
|
121
119
|
var gitScopeSchema = {
|
|
122
120
|
gitScope: {
|
|
@@ -205,7 +203,7 @@ var TOOL_CONTRACTS = [
|
|
|
205
203
|
tool("show_metadata", "Show metadata", { ...path, ...lang, ...stdin }, ["path"]),
|
|
206
204
|
tool("show_assets", "Show assets", { ...path, at: string(PARAM_DESCRIPTIONS.assetAt), ...stdin }, ["path"]),
|
|
207
205
|
tool("check_syntax", "Check syntax", { ...path, ...lang, ...stdin }, ["path"]),
|
|
208
|
-
tool("check_rules", "Check rules", {
|
|
206
|
+
tool("check_rules", "Check rules", { path: string(PARAM_DESCRIPTIONS.searchPath), ...gitScopeSchema, rules: string(PARAM_DESCRIPTIONS.rules) }, ["rules"]),
|
|
209
207
|
tool("generate_caption", "Generate caption", { ...path, ...at, ...stdin, ...level, include: { type: "array", items: { type: "string", enum: ["text", "objects"] }, minItems: 1, uniqueItems: true, description: PARAM_DESCRIPTIONS.include } }, ["path"]),
|
|
210
208
|
tool("detect_objects", "Detect objects", { ...path, ...at, ...stdin, ...level }, ["path"]),
|
|
211
209
|
tool("recognize_text", "Recognize text", { ...path, ...at, ...stdin, ...level }, ["path"]),
|
|
@@ -277,12 +275,12 @@ var PREFERENCE_LEADS = {
|
|
|
277
275
|
show_content: "Preferred for reading source with anchors.",
|
|
278
276
|
edit_text: "Preferred for editing existing text files with fresh LINE:HASH anchors.",
|
|
279
277
|
write_file: "Preferred for creating or replacing a complete text file; returns LINE:HASH anchors.",
|
|
280
|
-
find_text: "Preferred text/regex
|
|
281
|
-
find_nodes: "Preferred for AST or structural code
|
|
278
|
+
find_text: "Preferred text/regex search; returns edit-ready LINE:HASH anchors.",
|
|
279
|
+
find_nodes: "Preferred for AST or structural code search with ast-grep-style patterns.",
|
|
282
280
|
find_definitions: "Preferred for go-to-definition or declaration lookup by name.",
|
|
283
281
|
find_references: "Preferred for finding identifier-name matches or binding-specific references before rename_symbol or delete.",
|
|
284
282
|
rename_symbol: "Preferred for renaming a symbol with binding-aware, verified edits.",
|
|
285
|
-
show_assets: "Preferred for
|
|
283
|
+
show_assets: "Preferred for materializing selected document assets with usable cached paths."
|
|
286
284
|
};
|
|
287
285
|
var FALLBACK_TEMPLATES = {
|
|
288
286
|
read: "Prefer `show_content` with fresh LINE:HASH anchors.",
|
|
@@ -294,9 +292,6 @@ var FALLBACK_TEMPLATES = {
|
|
|
294
292
|
function resolveToolName(name, aliases = {}) {
|
|
295
293
|
return aliases[name] ?? name;
|
|
296
294
|
}
|
|
297
|
-
function rewriteBacktickedToolNames(text, aliases = {}) {
|
|
298
|
-
return TOOL_NAMES.reduce((rewritten, toolName) => rewritten.replaceAll(`\`${toolName}\``, `\`${resolveToolName(toolName, aliases)}\``), text);
|
|
299
|
-
}
|
|
300
295
|
function renderCompactGuidelines(name, aliases = {}) {
|
|
301
296
|
return (TOOL_COMPACT_GUIDELINES[name] ?? []).map((guideline) => rewriteBacktickedToolNames(guideline, aliases));
|
|
302
297
|
}
|
|
@@ -320,15 +315,6 @@ function renderToolRoutingPolicy(options = {}) {
|
|
|
320
315
|
const find_references = resolveToolName("find_references", aliases);
|
|
321
316
|
const rename_symbol = resolveToolName("rename_symbol", aliases);
|
|
322
317
|
const show_assets = resolveToolName("show_assets", aliases);
|
|
323
|
-
if (options.style === "server") {
|
|
324
|
-
return [
|
|
325
|
-
"Structural code navigation, document inspection, and hash-verified edits with readseek.",
|
|
326
|
-
"For structural questions, prefer these tools to text Grep/Bash: targeted definitions, references, and AST patterns; shallow show_structure views; check_syntax diagnostics and show_content cursor context; and document inspection.",
|
|
327
|
-
`Use ${edit_text} for LINE:HASH-anchored mutations (preview with apply=false; apply defaults to true and re-checks plan_hash).`,
|
|
328
|
-
"Paths resolve against CLAUDE_PROJECT_DIR. Native Read/Grep/Edit hooks provide passive context;",
|
|
329
|
-
"call MCP tools for active navigation, document questions, or anchored edits."
|
|
330
|
-
].join(" ");
|
|
331
|
-
}
|
|
332
318
|
const title = options.title ?? "ReadSeek tool policy:";
|
|
333
319
|
const bullets = [];
|
|
334
320
|
if (options.preferOverBuiltIns) {
|
|
@@ -1363,10 +1349,10 @@ function text(value) {
|
|
|
1363
1349
|
function count(value) {
|
|
1364
1350
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
1365
1351
|
}
|
|
1366
|
-
function safe(value) {
|
|
1352
|
+
function safe(value, preserveTabs = false) {
|
|
1367
1353
|
return value.replace(/[\x00-\x09\x0b-\x1f\x7f-\x9f]/g, (char) => {
|
|
1368
1354
|
if (char === "\t")
|
|
1369
|
-
return "\\t";
|
|
1355
|
+
return preserveTabs ? char : "\\t";
|
|
1370
1356
|
if (char === "\r")
|
|
1371
1357
|
return "\\r";
|
|
1372
1358
|
return `\\x${char.charCodeAt(0).toString(16).padStart(2, "0")}`;
|
|
@@ -1526,7 +1512,7 @@ ${assetList(assets)}`);
|
|
|
1526
1512
|
const lang = text(metadata.language || content.language);
|
|
1527
1513
|
if (lang)
|
|
1528
1514
|
summary.push(inline(lang));
|
|
1529
|
-
const rows = lines.map((line) => `${line.line}${options.noAnchors ? "" : `:${text(line.hash)}`} | ${safe(text(line.text)
|
|
1515
|
+
const rows = lines.map((line) => `${line.line}${options.noAnchors ? "" : `:${text(line.hash)}`} | ${safe(text(line.text), true)}`);
|
|
1530
1516
|
const identifier = record(cursor.identifier);
|
|
1531
1517
|
if (count(cursor.line) !== undefined)
|
|
1532
1518
|
result.metadata.line = cursor.line;
|
package/dist/policy.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ToolName } from "./contract.ts";
|
|
2
|
+
export { rewriteBacktickedToolNames } from "./contract.ts";
|
|
2
3
|
export type ToolAliasMap = Readonly<Partial<Record<ToolName, string>>>;
|
|
3
4
|
export type ReplaceableTool = {
|
|
4
5
|
tool: ToolName;
|
|
@@ -9,7 +10,6 @@ export declare const REPLACEABLE_TOOLS: readonly ReplaceableTool[];
|
|
|
9
10
|
export declare const TOOL_COMPACT_GUIDELINES: Readonly<Partial<Record<ToolName, readonly string[]>>>;
|
|
10
11
|
export declare const BUILTIN_FALLBACKS: Readonly<Record<string, ToolName>>;
|
|
11
12
|
export declare function resolveToolName(name: ToolName, aliases?: ToolAliasMap): string;
|
|
12
|
-
export declare function rewriteBacktickedToolNames(text: string, aliases?: ToolAliasMap): string;
|
|
13
13
|
export declare function renderCompactGuidelines(name: ToolName, aliases?: ToolAliasMap): string[];
|
|
14
14
|
export declare function renderPreferredToolDescription(name: ToolName, aliases?: ToolAliasMap): string;
|
|
15
15
|
export declare function renderFallbackToolDescription(builtIn: string, aliases?: ToolAliasMap): string | undefined;
|
|
@@ -18,7 +18,6 @@ export type ToolRoutingPolicyOptions = {
|
|
|
18
18
|
title?: string;
|
|
19
19
|
preferOverBuiltIns?: boolean;
|
|
20
20
|
demoteBuiltIns?: readonly string[];
|
|
21
|
-
style?: "bullets" | "server";
|
|
22
21
|
};
|
|
23
22
|
export declare function renderToolRoutingPolicy(options?: ToolRoutingPolicyOptions): string;
|
|
24
23
|
export declare function preferredToolDescriptionMap(aliases?: ToolAliasMap): Readonly<Record<string, string>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jarkkojs/readseek-api",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "Shared ReadSeek CLI contract, validation, argv builders, and bounded process runners",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"vitest": "^4.1.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@jarkkojs/readseek": "^0.11.
|
|
54
|
+
"@jarkkojs/readseek": "^0.11.3",
|
|
55
55
|
"@bgotink/kdl": "0.4.0",
|
|
56
56
|
"@sinclair/typebox": "0.34.52"
|
|
57
57
|
}
|