@jarkkojs/readseek-api 0.9.5 → 0.9.7
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/README.md +4 -3
- package/dist/contract.d.ts +6 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +169 -46
- package/dist/policy.d.ts +25 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @jarkkojs/readseek-api
|
|
2
2
|
|
|
3
|
-
Shared, host-agnostic ReadSeek API pieces for CLI contract metadata,
|
|
4
|
-
validation, pure argv builders, platform package
|
|
5
|
-
or Bun process invocation.
|
|
3
|
+
Shared, host-agnostic ReadSeek API pieces for CLI contract metadata, agent
|
|
4
|
+
routing policy, parameter validation, pure argv builders, platform package
|
|
5
|
+
resolution, and bounded Node or Bun process invocation.
|
|
6
6
|
|
|
7
7
|
This package intentionally excludes host permissions, cache management, install
|
|
8
8
|
flows, session state, and TUI rendering.
|
|
@@ -22,6 +22,7 @@ npm install @jarkkojs/readseek-api
|
|
|
22
22
|
## Exports
|
|
23
23
|
|
|
24
24
|
- Contract: tool descriptions, shared parameter text, and enums
|
|
25
|
+
- Policy: host-agnostic tool routing, preference/fallback lead-ins, and compact guidelines
|
|
25
26
|
- Validation: git selection, refs name/scope, vision level/mode, edit variants
|
|
26
27
|
- Argv builders: `digest`, `view`, `search`, `def`, `refs`, `edit`, `rename`, line locations
|
|
27
28
|
- Platform: binary name, platform package map, and default or caller-injected module resolution
|
package/dist/contract.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ export declare const EDIT_VARIANTS: readonly ["set_line", "replace_lines", "inse
|
|
|
12
12
|
export type EditVariant = (typeof EDIT_VARIANTS)[number];
|
|
13
13
|
export declare const GIT_SELECTION_FLAGS: readonly ["cached", "others", "ignored"];
|
|
14
14
|
export type GitSelectionFlag = (typeof GIT_SELECTION_FLAGS)[number];
|
|
15
|
-
export declare const TOOL_NAMES: readonly ["
|
|
15
|
+
export declare const TOOL_NAMES: readonly ["digest", "edit", "write", "grep", "view", "search", "def", "refs", "rename"];
|
|
16
16
|
export type ToolName = (typeof TOOL_NAMES)[number];
|
|
17
17
|
export declare const PARAM_DESCRIPTIONS: {
|
|
18
18
|
readonly path: "Absolute or relative file path";
|
|
19
|
+
readonly projectPath: "Path relative to the project directory";
|
|
20
|
+
readonly projectSearchPath: "File or directory to search; defaults to the project directory";
|
|
19
21
|
readonly searchPath: "File or directory to search; defaults to the current directory";
|
|
20
22
|
readonly language: "Language override when auto-detection is ambiguous";
|
|
21
23
|
readonly languageOverride: "Language override";
|
|
@@ -69,6 +71,7 @@ export declare const PARAM_DESCRIPTIONS: {
|
|
|
69
71
|
readonly symbol: "Mapped symbol name";
|
|
70
72
|
readonly newBody: "Complete replacement body for the symbol";
|
|
71
73
|
readonly apply: "When supported by the host, apply the verified plan instead of previewing only";
|
|
74
|
+
readonly applyDefaultTrue: "Apply the verified edits; defaults to true";
|
|
72
75
|
readonly planHash: "Require the apply plan to match this dry-run plan hash";
|
|
73
76
|
readonly workspace: "Rename across the project";
|
|
74
77
|
readonly to: "New symbol name";
|
|
@@ -84,11 +87,10 @@ export declare const PARAM_DESCRIPTIONS: {
|
|
|
84
87
|
readonly scopeContext: "Context lines within each symbol";
|
|
85
88
|
};
|
|
86
89
|
export declare const TOOL_DESCRIPTIONS: {
|
|
87
|
-
readonly
|
|
90
|
+
readonly digest: "Digest source content and images into the native CLI envelope. Returns metadata plus requested facets unchanged from `readseek digest`. Use it before edits to obtain fresh `LINE:HASH` anchors; use for structural maps, diagnostics, and cursor identity.";
|
|
88
91
|
readonly edit: "Edit existing text files with fresh `LINE:HASH` anchors. Read or search first when no fresh anchors are available. Each `edits[]` item must use exactly one nested object: `{\"set_line\":{\"anchor\":\"LINE:HASH\",\"new_text\":\"...\"}}`, `{\"replace_lines\":{\"start_anchor\":\"LINE:HASH\",\"end_anchor\":\"LINE:HASH\",\"new_text\":\"...\"}}`, `{\"insert_after\":{\"anchor\":\"LINE:HASH\",\"new_text\":\"...\"}}`, `{\"replace_symbol\":{\"symbol\":\"name\",\"new_body\":\"...\"}}`, or `{\"replace\":{\"old_text\":\"...\",\"new_text\":\"...\"}}`.";
|
|
89
92
|
readonly write: "Create or replace a complete text file and return `LINE:HASH` anchors. Use `edit` for small changes to an existing file.";
|
|
90
93
|
readonly grep: "Search text or regex in files and return edit-ready `LINE:HASH` anchors. Use for identifiers, strings, configuration, errors, comments, and documentation.";
|
|
91
|
-
readonly digest: "Digest source content and images into the native CLI envelope. Returns metadata plus requested facets unchanged from `readseek digest`; use for structural maps, diagnostics, and cursor identity.";
|
|
92
94
|
readonly view: "Digest a document's structure or selected content. Start with the overview, then narrow by page, node, kind, or depth instead of reading the whole document. PDF is the first supported document format.";
|
|
93
95
|
readonly search: "Search code by AST structure using ast-grep-style patterns. Results include line hashes usable as `LINE:HASH` anchors. Use `grep` for identifiers, strings, comments, configuration, documentation, or other plain text and regex.";
|
|
94
96
|
readonly def: "Go to a symbol definition or declaration by name. Accepts qualified or unqualified names; use this instead of text search for functions, methods, classes, types, and other declarations.";
|
|
@@ -109,3 +111,4 @@ export type ToolContract = {
|
|
|
109
111
|
inputSchema: JsonSchema;
|
|
110
112
|
};
|
|
111
113
|
export declare const TOOL_CONTRACTS: readonly ToolContract[];
|
|
114
|
+
export declare function getToolContract(name: ToolName): ToolContract;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { DIGEST_FACETS, DOCUMENT_NODE_KINDS, EDIT_VARIANTS, GIT_SELECTION_FLAGS, PARAM_DESCRIPTIONS, TOOL_CONTRACTS, TOOL_DESCRIPTIONS, TOOL_NAMES, renderToolDescription, VISION_ANALYSIS_MODES, VISION_LEVELS, VISION_MODES, type DigestFacet, type DocumentNodeKind, type EditVariant, type GitSelectionFlag, type JsonSchema, type ToolContract, type ToolName, type VisionAnalysisMode, type VisionLevel, type VisionMode, } from "./contract.ts";
|
|
1
|
+
export { DIGEST_FACETS, DOCUMENT_NODE_KINDS, EDIT_VARIANTS, GIT_SELECTION_FLAGS, PARAM_DESCRIPTIONS, TOOL_CONTRACTS, getToolContract, TOOL_DESCRIPTIONS, TOOL_NAMES, renderToolDescription, VISION_ANALYSIS_MODES, VISION_LEVELS, VISION_MODES, type DigestFacet, type DocumentNodeKind, type EditVariant, type GitSelectionFlag, type JsonSchema, type ToolContract, type ToolName, type VisionAnalysisMode, type VisionLevel, type VisionMode, } from "./contract.ts";
|
|
2
|
+
export { BUILTIN_FALLBACKS, REPLACEABLE_TOOLS, TOOL_COMPACT_GUIDELINES, fallbackToolDescriptionMap, preferredToolDescriptionMap, renderCompactGuidelines, renderFallbackToolDescription, renderPreferredToolDescription, renderToolRoutingPolicy, resolveToolName, rewriteBacktickedToolNames, type ReplaceableTool, type ToolAliasMap, type ToolRoutingPolicyOptions, } from "./policy.ts";
|
|
2
3
|
export { validateExactlyOneEditVariant, validateGitSelection, validateRefsNameVsScope, validateVisionLevelVsMode, type EditObject, type GitSelectionInput, type RefsScopeInput, type ValidationResult, type VisionInput, } from "./validation.ts";
|
|
3
4
|
export { appendApplyAndPlanHash, appendGitSelectionArgs, buildDefArgs, buildDigestArgs, buildEditArgs, buildLineLocation, buildRefsArgs, buildRenameArgs, buildSearchArgs, buildViewArgs, type ApplyPlanHashInput, type ApplyPlanHashOrder, type DefArgsInput, type DigestArgsInput, type EditArgsInput, type RefsArgsInput, type RenameArgsInput, type SearchArgsInput, type ViewArgsInput, } from "./argv.ts";
|
|
4
5
|
export { READSEEK_PLATFORM_PACKAGES, readSeekBinaryName, readSeekPlatformKey, resolveReadSeekBinaryFromPackages, type ModuleResolver, } from "./platform.ts";
|
package/dist/index.js
CHANGED
|
@@ -30,11 +30,10 @@ var EDIT_VARIANTS = [
|
|
|
30
30
|
];
|
|
31
31
|
var GIT_SELECTION_FLAGS = ["cached", "others", "ignored"];
|
|
32
32
|
var TOOL_NAMES = [
|
|
33
|
-
"
|
|
33
|
+
"digest",
|
|
34
34
|
"edit",
|
|
35
35
|
"write",
|
|
36
36
|
"grep",
|
|
37
|
-
"digest",
|
|
38
37
|
"view",
|
|
39
38
|
"search",
|
|
40
39
|
"def",
|
|
@@ -43,6 +42,8 @@ var TOOL_NAMES = [
|
|
|
43
42
|
];
|
|
44
43
|
var PARAM_DESCRIPTIONS = {
|
|
45
44
|
path: "Absolute or relative file path",
|
|
45
|
+
projectPath: "Path relative to the project directory",
|
|
46
|
+
projectSearchPath: "File or directory to search; defaults to the project directory",
|
|
46
47
|
searchPath: "File or directory to search; defaults to the current directory",
|
|
47
48
|
language: "Language override when auto-detection is ambiguous",
|
|
48
49
|
languageOverride: "Language override",
|
|
@@ -96,6 +97,7 @@ var PARAM_DESCRIPTIONS = {
|
|
|
96
97
|
symbol: "Mapped symbol name",
|
|
97
98
|
newBody: "Complete replacement body for the symbol",
|
|
98
99
|
apply: "When supported by the host, apply the verified plan instead of previewing only",
|
|
100
|
+
applyDefaultTrue: "Apply the verified edits; defaults to true",
|
|
99
101
|
planHash: "Require the apply plan to match this dry-run plan hash",
|
|
100
102
|
workspace: "Rename across the project",
|
|
101
103
|
to: "New symbol name",
|
|
@@ -111,11 +113,10 @@ var PARAM_DESCRIPTIONS = {
|
|
|
111
113
|
scopeContext: "Context lines within each symbol"
|
|
112
114
|
};
|
|
113
115
|
var TOOL_DESCRIPTIONS = {
|
|
114
|
-
|
|
116
|
+
digest: "Digest source content and images into the native CLI envelope. Returns metadata plus requested facets unchanged from `readseek digest`. Use it before edits to obtain fresh `LINE:HASH` anchors; use for structural maps, diagnostics, and cursor identity.",
|
|
115
117
|
edit: 'Edit existing text files with fresh `LINE:HASH` anchors. Read or search first when no fresh anchors are available. Each `edits[]` item must use exactly one nested object: `{"set_line":{"anchor":"LINE:HASH","new_text":"..."}}`, `{"replace_lines":{"start_anchor":"LINE:HASH","end_anchor":"LINE:HASH","new_text":"..."}}`, `{"insert_after":{"anchor":"LINE:HASH","new_text":"..."}}`, `{"replace_symbol":{"symbol":"name","new_body":"..."}}`, or `{"replace":{"old_text":"...","new_text":"..."}}`.',
|
|
116
118
|
write: "Create or replace a complete text file and return `LINE:HASH` anchors. Use `edit` for small changes to an existing file.",
|
|
117
119
|
grep: "Search text or regex in files and return edit-ready `LINE:HASH` anchors. Use for identifiers, strings, configuration, errors, comments, and documentation.",
|
|
118
|
-
digest: "Digest source content and images into the native CLI envelope. Returns metadata plus requested facets unchanged from `readseek digest`; use for structural maps, diagnostics, and cursor identity.",
|
|
119
120
|
view: "Digest a document's structure or selected content. Start with the overview, then narrow by page, node, kind, or depth instead of reading the whole document. PDF is the first supported document format.",
|
|
120
121
|
search: "Search code by AST structure using ast-grep-style patterns. Results include line hashes usable as `LINE:HASH` anchors. Use `grep` for identifiers, strings, comments, configuration, documentation, or other plain text and regex.",
|
|
121
122
|
def: "Go to a symbol definition or declaration by name. Accepts qualified or unqualified names; use this instead of text search for functions, methods, classes, types, and other declarations.",
|
|
@@ -123,7 +124,10 @@ var TOOL_DESCRIPTIONS = {
|
|
|
123
124
|
rename: "Rename a symbol at a source location. Resolvable same-named bindings are preserved; verified edits apply by default. Set `apply: false` to preview the plan before changing files."
|
|
124
125
|
};
|
|
125
126
|
function renderToolDescription(name, aliases = {}) {
|
|
126
|
-
|
|
127
|
+
const desc = TOOL_DESCRIPTIONS[name];
|
|
128
|
+
if (!desc)
|
|
129
|
+
throw new Error(`Missing TOOL_DESCRIPTIONS for ${name}`);
|
|
130
|
+
return TOOL_NAMES.reduce((description, toolName) => description.replaceAll(`\`${toolName}\``, `\`${aliases[toolName] ?? toolName}\``), desc);
|
|
127
131
|
}
|
|
128
132
|
var gitFlagsSchema = {
|
|
129
133
|
cached: {
|
|
@@ -202,25 +206,27 @@ var editItemSchema = {
|
|
|
202
206
|
};
|
|
203
207
|
var TOOL_CONTRACTS = [
|
|
204
208
|
{
|
|
205
|
-
name: "
|
|
206
|
-
title: "
|
|
207
|
-
description: TOOL_DESCRIPTIONS.
|
|
209
|
+
name: "digest",
|
|
210
|
+
title: "Digest source",
|
|
211
|
+
description: TOOL_DESCRIPTIONS.digest,
|
|
208
212
|
inputSchema: {
|
|
209
213
|
type: "object",
|
|
210
214
|
properties: {
|
|
211
215
|
path: { type: "string", description: PARAM_DESCRIPTIONS.path },
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
select: { type: "string", description: PARAM_DESCRIPTIONS.select },
|
|
217
|
+
at: { type: "string", description: PARAM_DESCRIPTIONS.at },
|
|
218
|
+
end: { type: "integer", minimum: 1, description: PARAM_DESCRIPTIONS.end },
|
|
219
|
+
limit: { type: "integer", minimum: 1, description: PARAM_DESCRIPTIONS.limit },
|
|
220
|
+
language: { type: "string", description: PARAM_DESCRIPTIONS.languageOverride },
|
|
221
|
+
visionMode: {
|
|
216
222
|
type: "string",
|
|
217
|
-
enum: [
|
|
218
|
-
description: PARAM_DESCRIPTIONS.
|
|
223
|
+
enum: [...VISION_MODES],
|
|
224
|
+
description: PARAM_DESCRIPTIONS.visionModeDigest
|
|
219
225
|
},
|
|
220
|
-
|
|
226
|
+
visionLevel: {
|
|
221
227
|
type: "string",
|
|
222
|
-
enum: [...
|
|
223
|
-
description: PARAM_DESCRIPTIONS.
|
|
228
|
+
enum: [...VISION_LEVELS],
|
|
229
|
+
description: PARAM_DESCRIPTIONS.visionLevel
|
|
224
230
|
}
|
|
225
231
|
},
|
|
226
232
|
required: ["path"],
|
|
@@ -294,34 +300,6 @@ var TOOL_CONTRACTS = [
|
|
|
294
300
|
additionalProperties: false
|
|
295
301
|
}
|
|
296
302
|
},
|
|
297
|
-
{
|
|
298
|
-
name: "digest",
|
|
299
|
-
title: "Digest source",
|
|
300
|
-
description: TOOL_DESCRIPTIONS.digest,
|
|
301
|
-
inputSchema: {
|
|
302
|
-
type: "object",
|
|
303
|
-
properties: {
|
|
304
|
-
path: { type: "string", description: PARAM_DESCRIPTIONS.path },
|
|
305
|
-
select: { type: "string", description: PARAM_DESCRIPTIONS.select },
|
|
306
|
-
at: { type: "string", description: PARAM_DESCRIPTIONS.at },
|
|
307
|
-
end: { type: "integer", minimum: 1, description: PARAM_DESCRIPTIONS.end },
|
|
308
|
-
limit: { type: "integer", minimum: 1, description: PARAM_DESCRIPTIONS.limit },
|
|
309
|
-
language: { type: "string", description: PARAM_DESCRIPTIONS.languageOverride },
|
|
310
|
-
visionMode: {
|
|
311
|
-
type: "string",
|
|
312
|
-
enum: [...VISION_MODES],
|
|
313
|
-
description: PARAM_DESCRIPTIONS.visionModeDigest
|
|
314
|
-
},
|
|
315
|
-
visionLevel: {
|
|
316
|
-
type: "string",
|
|
317
|
-
enum: [...VISION_LEVELS],
|
|
318
|
-
description: PARAM_DESCRIPTIONS.visionLevel
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
required: ["path"],
|
|
322
|
-
additionalProperties: false
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
303
|
{
|
|
326
304
|
name: "view",
|
|
327
305
|
title: "View document",
|
|
@@ -424,6 +402,139 @@ var TOOL_CONTRACTS = [
|
|
|
424
402
|
}
|
|
425
403
|
}
|
|
426
404
|
];
|
|
405
|
+
function getToolContract(name) {
|
|
406
|
+
const contract = TOOL_CONTRACTS.find((entry) => entry.name === name);
|
|
407
|
+
if (!contract)
|
|
408
|
+
throw new Error(`missing tool contract: ${name}`);
|
|
409
|
+
return contract;
|
|
410
|
+
}
|
|
411
|
+
// src/policy.ts
|
|
412
|
+
var REPLACEABLE_TOOLS = [
|
|
413
|
+
{
|
|
414
|
+
tool: "digest",
|
|
415
|
+
builtIn: "read",
|
|
416
|
+
benefit: "it returns LINE:HASH anchors for safe edits."
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
tool: "edit",
|
|
420
|
+
builtIn: "edit",
|
|
421
|
+
benefit: "it verifies fresh LINE:HASH anchors."
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
tool: "grep",
|
|
425
|
+
builtIn: "grep",
|
|
426
|
+
benefit: "it returns LINE:HASH anchors."
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
tool: "write",
|
|
430
|
+
builtIn: "write",
|
|
431
|
+
benefit: "it returns LINE:HASH anchors."
|
|
432
|
+
}
|
|
433
|
+
];
|
|
434
|
+
var TOOL_COMPACT_GUIDELINES = {
|
|
435
|
+
digest: [
|
|
436
|
+
"Use `digest` for map, diagnostics, and identity facets instead of separate tools."
|
|
437
|
+
],
|
|
438
|
+
edit: [
|
|
439
|
+
"Prefer set_line, replace_lines, and insert_after; use replace only when anchors are impractical."
|
|
440
|
+
],
|
|
441
|
+
grep: [
|
|
442
|
+
"Use `grep` with summary first for broad searches, then narrow by path, glob, or pattern."
|
|
443
|
+
],
|
|
444
|
+
write: [
|
|
445
|
+
"Use anchored edits rather than `write` for small changes or appends."
|
|
446
|
+
],
|
|
447
|
+
search: [
|
|
448
|
+
"Use `search` for AST patterns; use `grep` for plain text."
|
|
449
|
+
],
|
|
450
|
+
refs: [
|
|
451
|
+
"Use `refs` before changing a symbol; add scope plus line/column to follow one binding."
|
|
452
|
+
]
|
|
453
|
+
};
|
|
454
|
+
var BUILTIN_FALLBACKS = {
|
|
455
|
+
read: "digest",
|
|
456
|
+
edit: "edit",
|
|
457
|
+
write: "write",
|
|
458
|
+
grep: "grep",
|
|
459
|
+
apply_patch: "edit"
|
|
460
|
+
};
|
|
461
|
+
var PREFERENCE_LEADS = {
|
|
462
|
+
digest: "Preferred for reading source with anchors and facets.",
|
|
463
|
+
edit: "Preferred for editing existing text files with fresh LINE:HASH anchors.",
|
|
464
|
+
write: "Preferred for creating or replacing a complete text file; returns LINE:HASH anchors.",
|
|
465
|
+
grep: "Preferred text/regex search; returns edit-ready LINE:HASH anchors.",
|
|
466
|
+
search: "Preferred for AST or structural code search with ast-grep-style patterns.",
|
|
467
|
+
def: "Preferred for go-to-definition or declaration lookup by name.",
|
|
468
|
+
refs: "Preferred for finding identifier-name matches or binding-specific references before rename or delete.",
|
|
469
|
+
rename: "Preferred for renaming a symbol with binding-aware, verified edits.",
|
|
470
|
+
view: "Preferred for digesting document structure or selected content."
|
|
471
|
+
};
|
|
472
|
+
var FALLBACK_TEMPLATES = {
|
|
473
|
+
read: "Fallback only. Prefer `digest` with fresh LINE:HASH anchors.",
|
|
474
|
+
edit: "Fallback only. Prefer `edit` with fresh LINE:HASH anchors.",
|
|
475
|
+
write: "Fallback only. Prefer `write` so the result returns LINE:HASH anchors.",
|
|
476
|
+
grep: "Fallback only. Prefer `grep` for text/regex search with edit-ready anchors.",
|
|
477
|
+
apply_patch: "Fallback only. Prefer `edit` for existing text files."
|
|
478
|
+
};
|
|
479
|
+
function resolveToolName(name, aliases = {}) {
|
|
480
|
+
return aliases[name] ?? name;
|
|
481
|
+
}
|
|
482
|
+
function rewriteBacktickedToolNames(text, aliases = {}) {
|
|
483
|
+
return TOOL_NAMES.reduce((rewritten, toolName) => rewritten.replaceAll(`\`${toolName}\``, `\`${resolveToolName(toolName, aliases)}\``), text);
|
|
484
|
+
}
|
|
485
|
+
function renderCompactGuidelines(name, aliases = {}) {
|
|
486
|
+
return (TOOL_COMPACT_GUIDELINES[name] ?? []).map((guideline) => rewriteBacktickedToolNames(guideline, aliases));
|
|
487
|
+
}
|
|
488
|
+
function renderPreferredToolDescription(name, aliases = {}) {
|
|
489
|
+
return rewriteBacktickedToolNames(PREFERENCE_LEADS[name], aliases);
|
|
490
|
+
}
|
|
491
|
+
function renderFallbackToolDescription(builtIn, aliases = {}) {
|
|
492
|
+
const template = FALLBACK_TEMPLATES[builtIn];
|
|
493
|
+
if (!template)
|
|
494
|
+
return;
|
|
495
|
+
return rewriteBacktickedToolNames(template, aliases);
|
|
496
|
+
}
|
|
497
|
+
function renderToolRoutingPolicy(options = {}) {
|
|
498
|
+
const aliases = options.aliases ?? {};
|
|
499
|
+
const digest = resolveToolName("digest", aliases);
|
|
500
|
+
const edit = resolveToolName("edit", aliases);
|
|
501
|
+
const write = resolveToolName("write", aliases);
|
|
502
|
+
const grep = resolveToolName("grep", aliases);
|
|
503
|
+
const search = resolveToolName("search", aliases);
|
|
504
|
+
const def = resolveToolName("def", aliases);
|
|
505
|
+
const refs = resolveToolName("refs", aliases);
|
|
506
|
+
const rename = resolveToolName("rename", aliases);
|
|
507
|
+
const view = resolveToolName("view", aliases);
|
|
508
|
+
if (options.style === "server") {
|
|
509
|
+
return [
|
|
510
|
+
"Structural code navigation, document viewing, and hash-verified edits with readseek.",
|
|
511
|
+
"For structural questions, prefer these tools to text Grep/Bash: definitions, references, AST search, multi-facet digest (content/map/diagnostics/identity), and document views.",
|
|
512
|
+
`Use ${edit} for LINE:HASH-anchored mutations (preview with apply=false; apply defaults to true and re-checks plan_hash).`,
|
|
513
|
+
"Paths resolve against CLAUDE_PROJECT_DIR. Native Read/Grep/Edit hooks provide passive context;",
|
|
514
|
+
"call MCP tools for active navigation, document questions, or anchored edits."
|
|
515
|
+
].join(" ");
|
|
516
|
+
}
|
|
517
|
+
const title = options.title ?? "ReadSeek tool policy:";
|
|
518
|
+
const bullets = [];
|
|
519
|
+
if (options.preferOverBuiltIns) {
|
|
520
|
+
bullets.push("- Prefer ReadSeek tools over built-ins when they can do the job.");
|
|
521
|
+
}
|
|
522
|
+
bullets.push(`- Read with ${digest} first; ${edit} needs fresh LINE:HASH anchors.`, `- Use ${grep} for text/regex, ${search} for AST patterns, and ${digest}/${def}/${refs} for symbol navigation.`, `- Use ${edit} for existing files, ${write} for whole-file creation or replacement, and ${rename} for symbol renames.`, `- Use ${view} for document structure; run ${digest} with select diagnostics after source edits for a quick syntax check.`);
|
|
523
|
+
if (options.demoteBuiltIns && options.demoteBuiltIns.length > 0) {
|
|
524
|
+
bullets.push(`- Do not use built-in ${options.demoteBuiltIns.join(", ")} when a ReadSeek tool can do the job.`);
|
|
525
|
+
}
|
|
526
|
+
return [title, ...bullets].join(`
|
|
527
|
+
`);
|
|
528
|
+
}
|
|
529
|
+
function preferredToolDescriptionMap(aliases = {}) {
|
|
530
|
+
return Object.fromEntries(TOOL_NAMES.map((name) => [resolveToolName(name, aliases), renderPreferredToolDescription(name, aliases)]));
|
|
531
|
+
}
|
|
532
|
+
function fallbackToolDescriptionMap(builtIns = Object.keys(BUILTIN_FALLBACKS), aliases = {}) {
|
|
533
|
+
return Object.fromEntries(builtIns.flatMap((builtIn) => {
|
|
534
|
+
const description = renderFallbackToolDescription(builtIn, aliases);
|
|
535
|
+
return description ? [[builtIn, description]] : [];
|
|
536
|
+
}));
|
|
537
|
+
}
|
|
427
538
|
// src/validation.ts
|
|
428
539
|
function validateGitSelection(input) {
|
|
429
540
|
if (input.ignored && !input.others) {
|
|
@@ -915,13 +1026,22 @@ export {
|
|
|
915
1026
|
runReadSeekBunText,
|
|
916
1027
|
runReadSeekBunJson,
|
|
917
1028
|
runReadSeekBun,
|
|
1029
|
+
rewriteBacktickedToolNames,
|
|
1030
|
+
resolveToolName,
|
|
918
1031
|
resolveReadSeekBinaryFromPackages,
|
|
919
1032
|
resolveProcessLimits,
|
|
1033
|
+
renderToolRoutingPolicy,
|
|
920
1034
|
renderToolDescription,
|
|
1035
|
+
renderPreferredToolDescription,
|
|
1036
|
+
renderFallbackToolDescription,
|
|
1037
|
+
renderCompactGuidelines,
|
|
921
1038
|
readSeekPlatformKey,
|
|
922
1039
|
readSeekBinaryName,
|
|
1040
|
+
preferredToolDescriptionMap,
|
|
923
1041
|
parseSuccessfulJson,
|
|
924
1042
|
parseReadSeekJson,
|
|
1043
|
+
getToolContract,
|
|
1044
|
+
fallbackToolDescriptionMap,
|
|
925
1045
|
failureFromProcessResult,
|
|
926
1046
|
ensureSuccessfulStdout,
|
|
927
1047
|
cleanReadSeekErrorText,
|
|
@@ -941,6 +1061,8 @@ export {
|
|
|
941
1061
|
TOOL_NAMES,
|
|
942
1062
|
TOOL_DESCRIPTIONS,
|
|
943
1063
|
TOOL_CONTRACTS,
|
|
1064
|
+
TOOL_COMPACT_GUIDELINES,
|
|
1065
|
+
REPLACEABLE_TOOLS,
|
|
944
1066
|
READSEEK_PLATFORM_PACKAGES,
|
|
945
1067
|
PARAM_DESCRIPTIONS,
|
|
946
1068
|
GIT_SELECTION_FLAGS,
|
|
@@ -948,5 +1070,6 @@ export {
|
|
|
948
1070
|
DOCUMENT_NODE_KINDS,
|
|
949
1071
|
DIGEST_FACETS,
|
|
950
1072
|
DEFAULT_READSEEK_TIMEOUT_MS,
|
|
951
|
-
DEFAULT_MAX_OUTPUT_BYTES
|
|
1073
|
+
DEFAULT_MAX_OUTPUT_BYTES,
|
|
1074
|
+
BUILTIN_FALLBACKS
|
|
952
1075
|
};
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ToolName } from "./contract.ts";
|
|
2
|
+
export type ToolAliasMap = Readonly<Partial<Record<ToolName, string>>>;
|
|
3
|
+
export type ReplaceableTool = {
|
|
4
|
+
tool: ToolName;
|
|
5
|
+
builtIn: string;
|
|
6
|
+
benefit: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const REPLACEABLE_TOOLS: readonly ReplaceableTool[];
|
|
9
|
+
export declare const TOOL_COMPACT_GUIDELINES: Readonly<Partial<Record<ToolName, readonly string[]>>>;
|
|
10
|
+
export declare const BUILTIN_FALLBACKS: Readonly<Record<string, ToolName>>;
|
|
11
|
+
export declare function resolveToolName(name: ToolName, aliases?: ToolAliasMap): string;
|
|
12
|
+
export declare function rewriteBacktickedToolNames(text: string, aliases?: ToolAliasMap): string;
|
|
13
|
+
export declare function renderCompactGuidelines(name: ToolName, aliases?: ToolAliasMap): string[];
|
|
14
|
+
export declare function renderPreferredToolDescription(name: ToolName, aliases?: ToolAliasMap): string;
|
|
15
|
+
export declare function renderFallbackToolDescription(builtIn: string, aliases?: ToolAliasMap): string | undefined;
|
|
16
|
+
export type ToolRoutingPolicyOptions = {
|
|
17
|
+
aliases?: ToolAliasMap;
|
|
18
|
+
title?: string;
|
|
19
|
+
preferOverBuiltIns?: boolean;
|
|
20
|
+
demoteBuiltIns?: readonly string[];
|
|
21
|
+
style?: "bullets" | "server";
|
|
22
|
+
};
|
|
23
|
+
export declare function renderToolRoutingPolicy(options?: ToolRoutingPolicyOptions): string;
|
|
24
|
+
export declare function preferredToolDescriptionMap(aliases?: ToolAliasMap): Readonly<Record<string, string>>;
|
|
25
|
+
export declare function fallbackToolDescriptionMap(builtIns?: readonly string[], 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.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "Shared ReadSeek CLI contract, validation, argv builders, and bounded process runners",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"hashline"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@jarkkojs/readseek": "^0.9.
|
|
48
|
+
"@jarkkojs/readseek": "^0.9.7"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.0.0",
|