@jarkkojs/readseek-api 0.9.6 → 0.9.8
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 +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +149 -1
- 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
|
@@ -16,6 +16,8 @@ export declare const TOOL_NAMES: readonly ["digest", "edit", "write", "grep", "v
|
|
|
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";
|
|
@@ -108,3 +111,4 @@ export type ToolContract = {
|
|
|
108
111
|
inputSchema: JsonSchema;
|
|
109
112
|
};
|
|
110
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
|
@@ -42,6 +42,8 @@ var TOOL_NAMES = [
|
|
|
42
42
|
];
|
|
43
43
|
var PARAM_DESCRIPTIONS = {
|
|
44
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",
|
|
45
47
|
searchPath: "File or directory to search; defaults to the current directory",
|
|
46
48
|
language: "Language override when auto-detection is ambiguous",
|
|
47
49
|
languageOverride: "Language override",
|
|
@@ -95,6 +97,7 @@ var PARAM_DESCRIPTIONS = {
|
|
|
95
97
|
symbol: "Mapped symbol name",
|
|
96
98
|
newBody: "Complete replacement body for the symbol",
|
|
97
99
|
apply: "When supported by the host, apply the verified plan instead of previewing only",
|
|
100
|
+
applyDefaultTrue: "Apply the verified edits; defaults to true",
|
|
98
101
|
planHash: "Require the apply plan to match this dry-run plan hash",
|
|
99
102
|
workspace: "Rename across the project",
|
|
100
103
|
to: "New symbol name",
|
|
@@ -399,6 +402,139 @@ var TOOL_CONTRACTS = [
|
|
|
399
402
|
}
|
|
400
403
|
}
|
|
401
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
|
+
}
|
|
402
538
|
// src/validation.ts
|
|
403
539
|
function validateGitSelection(input) {
|
|
404
540
|
if (input.ignored && !input.others) {
|
|
@@ -890,13 +1026,22 @@ export {
|
|
|
890
1026
|
runReadSeekBunText,
|
|
891
1027
|
runReadSeekBunJson,
|
|
892
1028
|
runReadSeekBun,
|
|
1029
|
+
rewriteBacktickedToolNames,
|
|
1030
|
+
resolveToolName,
|
|
893
1031
|
resolveReadSeekBinaryFromPackages,
|
|
894
1032
|
resolveProcessLimits,
|
|
1033
|
+
renderToolRoutingPolicy,
|
|
895
1034
|
renderToolDescription,
|
|
1035
|
+
renderPreferredToolDescription,
|
|
1036
|
+
renderFallbackToolDescription,
|
|
1037
|
+
renderCompactGuidelines,
|
|
896
1038
|
readSeekPlatformKey,
|
|
897
1039
|
readSeekBinaryName,
|
|
1040
|
+
preferredToolDescriptionMap,
|
|
898
1041
|
parseSuccessfulJson,
|
|
899
1042
|
parseReadSeekJson,
|
|
1043
|
+
getToolContract,
|
|
1044
|
+
fallbackToolDescriptionMap,
|
|
900
1045
|
failureFromProcessResult,
|
|
901
1046
|
ensureSuccessfulStdout,
|
|
902
1047
|
cleanReadSeekErrorText,
|
|
@@ -916,6 +1061,8 @@ export {
|
|
|
916
1061
|
TOOL_NAMES,
|
|
917
1062
|
TOOL_DESCRIPTIONS,
|
|
918
1063
|
TOOL_CONTRACTS,
|
|
1064
|
+
TOOL_COMPACT_GUIDELINES,
|
|
1065
|
+
REPLACEABLE_TOOLS,
|
|
919
1066
|
READSEEK_PLATFORM_PACKAGES,
|
|
920
1067
|
PARAM_DESCRIPTIONS,
|
|
921
1068
|
GIT_SELECTION_FLAGS,
|
|
@@ -923,5 +1070,6 @@ export {
|
|
|
923
1070
|
DOCUMENT_NODE_KINDS,
|
|
924
1071
|
DIGEST_FACETS,
|
|
925
1072
|
DEFAULT_READSEEK_TIMEOUT_MS,
|
|
926
|
-
DEFAULT_MAX_OUTPUT_BYTES
|
|
1073
|
+
DEFAULT_MAX_OUTPUT_BYTES,
|
|
1074
|
+
BUILTIN_FALLBACKS
|
|
927
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.8",
|
|
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.8"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.0.0",
|