pi-readseek 0.9.15 → 0.9.16
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 +176 -0
- package/README.md +4 -2
- package/dist/index.ts +108 -27
- package/package.json +2 -3
- package/prompts/digest.md +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ and document inspection.
|
|
|
9
9
|
pi install npm:pi-readseek
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
The extension uses the native binary supplied by `@jarkkojs/readseek`. Set
|
|
12
|
+
The extension uses the native binary supplied by `@jarkkojs/readseek-api`. Set
|
|
13
13
|
`READSEEK_BINARY` to an absolute executable path to override it.
|
|
14
14
|
|
|
15
15
|
## Tools
|
|
@@ -53,4 +53,6 @@ npm run typecheck
|
|
|
53
53
|
|
|
54
54
|
## Licensing
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
`pi-readseek` is licensed under the Apache 2.0 license. See [LICENSE](LICENSE)
|
|
57
|
+
for more information.
|
|
58
|
+
|
package/dist/index.ts
CHANGED
|
@@ -70,6 +70,7 @@ var PARAM_DESCRIPTIONS = {
|
|
|
70
70
|
at: "Location: line:N[:COLUMN], hash:HASH[:COLUMN], or symbol:NAME",
|
|
71
71
|
end: "Last line to include",
|
|
72
72
|
limit: "Maximum number of lines to include",
|
|
73
|
+
digestDepth: "Maximum structural depth for map output; defaults to 1 in agent tools",
|
|
73
74
|
offset: "One-based starting line",
|
|
74
75
|
readLimit: "Maximum lines to return",
|
|
75
76
|
symbolRead: "Symbol name to read",
|
|
@@ -119,7 +120,7 @@ var PARAM_DESCRIPTIONS = {
|
|
|
119
120
|
scopeContext: "Context lines within each symbol"
|
|
120
121
|
};
|
|
121
122
|
var TOOL_DESCRIPTIONS = {
|
|
122
|
-
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
|
|
123
|
+
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 shallow maps for structural overviews, diagnostics for syntax checks, and identity for cursor context.",
|
|
123
124
|
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":"..."}}`.',
|
|
124
125
|
write: "Create or replace a complete text file and return `LINE:HASH` anchors. Use `edit` for small changes to an existing file.",
|
|
125
126
|
grep: "Search text or regex in files and return edit-ready `LINE:HASH` anchors. Use for identifiers, strings, configuration, errors, comments, and documentation.",
|
|
@@ -223,6 +224,7 @@ var TOOL_CONTRACTS = [
|
|
|
223
224
|
at: { type: "string", description: PARAM_DESCRIPTIONS.at },
|
|
224
225
|
end: { type: "integer", minimum: 1, description: PARAM_DESCRIPTIONS.end },
|
|
225
226
|
limit: { type: "integer", minimum: 1, description: PARAM_DESCRIPTIONS.limit },
|
|
227
|
+
depth: { type: "integer", minimum: 0, description: PARAM_DESCRIPTIONS.digestDepth },
|
|
226
228
|
language: { type: "string", description: PARAM_DESCRIPTIONS.languageOverride },
|
|
227
229
|
visionMode: {
|
|
228
230
|
type: "string",
|
|
@@ -433,7 +435,7 @@ var REPLACEABLE_TOOLS = [
|
|
|
433
435
|
];
|
|
434
436
|
var TOOL_COMPACT_GUIDELINES = {
|
|
435
437
|
digest: [
|
|
436
|
-
"Use `digest` for
|
|
438
|
+
"Use `digest` for shallow maps, diagnostics, and identity; use `def`, `refs`, or `search` for targeted symbol questions."
|
|
437
439
|
],
|
|
438
440
|
edit: [
|
|
439
441
|
"Prefer set_line, replace_lines, and insert_after; use replace only when anchors are impractical."
|
|
@@ -474,7 +476,7 @@ function renderToolRoutingPolicy(options = {}) {
|
|
|
474
476
|
if (options.style === "server") {
|
|
475
477
|
return [
|
|
476
478
|
"Structural code navigation, document viewing, and hash-verified edits with readseek.",
|
|
477
|
-
"For structural questions, prefer these tools to text Grep/Bash: definitions, references, AST search
|
|
479
|
+
"For structural questions, prefer these tools to text Grep/Bash: targeted definitions, references, and AST search; shallow digest maps; diagnostics and identity; and document views.",
|
|
478
480
|
`Use ${edit} for LINE:HASH-anchored mutations (preview with apply=false; apply defaults to true and re-checks plan_hash).`,
|
|
479
481
|
"Paths resolve against CLAUDE_PROJECT_DIR. Native Read/Grep/Edit hooks provide passive context;",
|
|
480
482
|
"call MCP tools for active navigation, document questions, or anchored edits."
|
|
@@ -485,7 +487,7 @@ function renderToolRoutingPolicy(options = {}) {
|
|
|
485
487
|
if (options.preferOverBuiltIns) {
|
|
486
488
|
bullets.push("- Prefer ReadSeek tools over built-ins when they can do the job.");
|
|
487
489
|
}
|
|
488
|
-
bullets.push(`- Read with ${digest} first; ${edit} needs fresh LINE:HASH anchors.`, `- Use ${grep} for text/regex, ${search} for AST patterns,
|
|
490
|
+
bullets.push(`- Read with ${digest} first; ${edit} needs fresh LINE:HASH anchors.`, `- Use ${grep} for text/regex, ${search} for AST patterns, ${def}/${refs} for targeted symbols, and shallow ${digest} maps only for file overviews.`, `- 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.`);
|
|
489
491
|
if (options.demoteBuiltIns && options.demoteBuiltIns.length > 0) {
|
|
490
492
|
bullets.push(`- Do not use built-in ${options.demoteBuiltIns.join(", ")} when a ReadSeek tool can do the job.`);
|
|
491
493
|
}
|
|
@@ -610,6 +612,7 @@ function validateExactlyOneEditVariant(edits) {
|
|
|
610
612
|
var MIN_SAFE_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
|
|
611
613
|
var MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
|
|
612
614
|
// ../readseek-api/src/argv.ts
|
|
615
|
+
var DEFAULT_DIGEST_MAP_DEPTH = 1;
|
|
613
616
|
function buildLineLocation(line, column) {
|
|
614
617
|
return column === undefined ? `line:${line}` : `line:${line}:${column}`;
|
|
615
618
|
}
|
|
@@ -652,6 +655,10 @@ function selectArg(select) {
|
|
|
652
655
|
return;
|
|
653
656
|
return Array.isArray(select) ? select.join(",") : select;
|
|
654
657
|
}
|
|
658
|
+
function selectsDigestMap(select) {
|
|
659
|
+
const value = selectArg(select);
|
|
660
|
+
return value?.split(",").some((facet) => facet.trim() === "map") ?? false;
|
|
661
|
+
}
|
|
655
662
|
function buildDigestArgs(input) {
|
|
656
663
|
const vision = validateVisionLevelVsMode({
|
|
657
664
|
visionMode: input.visionMode,
|
|
@@ -659,6 +666,14 @@ function buildDigestArgs(input) {
|
|
|
659
666
|
});
|
|
660
667
|
if (!vision.ok)
|
|
661
668
|
throw new Error(vision.error);
|
|
669
|
+
const selectsMap = selectsDigestMap(input.select);
|
|
670
|
+
if (input.depth !== undefined) {
|
|
671
|
+
if (!Number.isInteger(input.depth) || input.depth < 0) {
|
|
672
|
+
throw new Error("depth must be a non-negative integer");
|
|
673
|
+
}
|
|
674
|
+
if (!selectsMap)
|
|
675
|
+
throw new Error("depth requires the map facet");
|
|
676
|
+
}
|
|
662
677
|
const args = [];
|
|
663
678
|
if (input.readseekDir !== undefined)
|
|
664
679
|
args.push("--readseek-dir", input.readseekDir);
|
|
@@ -669,6 +684,7 @@ function buildDigestArgs(input) {
|
|
|
669
684
|
pushOptionalString(args, "--at", input.at);
|
|
670
685
|
pushOptionalNumber(args, "--end", input.end);
|
|
671
686
|
pushOptionalNumber(args, "--limit", input.limit);
|
|
687
|
+
pushOptionalNumber(args, "--depth", input.depth);
|
|
672
688
|
pushOptionalString(args, "--language", input.language);
|
|
673
689
|
pushOptionalString(args, "--vision-mode", input.visionMode);
|
|
674
690
|
pushOptionalString(args, "--vision-level", input.visionLevel);
|
|
@@ -800,9 +816,9 @@ function resolveReadSeekBinaryFromPackages(resolver = resolveFromPackage, option
|
|
|
800
816
|
const platformPackage = READSEEK_PLATFORM_PACKAGES[key];
|
|
801
817
|
if (!platformPackage) {
|
|
802
818
|
const supported = Object.keys(READSEEK_PLATFORM_PACKAGES).join(", ");
|
|
803
|
-
throw new Error(`@jarkkojs/readseek ships no binary for ${key}; it supports ${supported}`);
|
|
819
|
+
throw new Error(`@jarkkojs/readseek-api ships no binary for ${key}; it supports ${supported}`);
|
|
804
820
|
}
|
|
805
|
-
const metaPackage = options.metaPackage ?? "@jarkkojs/readseek";
|
|
821
|
+
const metaPackage = options.metaPackage ?? "@jarkkojs/readseek-api";
|
|
806
822
|
const metaPackageJson = resolve(`${metaPackage}/package.json`);
|
|
807
823
|
const metaPackageDir = path.dirname(metaPackageJson);
|
|
808
824
|
let packageJsonPath;
|
|
@@ -1039,6 +1055,22 @@ function parseReadOutput(value) {
|
|
|
1039
1055
|
hashlines: hashlines.map((line) => parseHashline(line, "hashline"))
|
|
1040
1056
|
};
|
|
1041
1057
|
}
|
|
1058
|
+
function parseMapNode(value) {
|
|
1059
|
+
if (!value || typeof value !== "object")
|
|
1060
|
+
throw new Error("invalid readseek map node");
|
|
1061
|
+
const node = value;
|
|
1062
|
+
if (!Array.isArray(node.children))
|
|
1063
|
+
throw new Error("invalid readseek map node children");
|
|
1064
|
+
return {
|
|
1065
|
+
kind: requireString(node.kind, "map node.kind"),
|
|
1066
|
+
name: requireString(node.name, "map node.name"),
|
|
1067
|
+
start_line: requireNumber(node.start_line, "map node.start_line"),
|
|
1068
|
+
end_line: requireNumber(node.end_line, "map node.end_line"),
|
|
1069
|
+
start_anchor: requireString(node.start_anchor, "map node.start_anchor"),
|
|
1070
|
+
end_anchor: requireString(node.end_anchor, "map node.end_anchor"),
|
|
1071
|
+
children: node.children.map(parseMapNode)
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1042
1074
|
function parseMapOutput(value) {
|
|
1043
1075
|
if (!value || typeof value !== "object")
|
|
1044
1076
|
throw new Error("invalid readseek map output");
|
|
@@ -1051,6 +1083,7 @@ function parseMapOutput(value) {
|
|
|
1051
1083
|
language: requireString(output.language, "language"),
|
|
1052
1084
|
line_count: requireNumber(output.line_count, "line_count"),
|
|
1053
1085
|
file_hash: requireString(output.file_hash, "file_hash"),
|
|
1086
|
+
root: parseMapNode(output.root),
|
|
1054
1087
|
symbols: symbols.map((symbol) => {
|
|
1055
1088
|
if (!symbol || typeof symbol !== "object")
|
|
1056
1089
|
throw new Error("invalid readseek symbol");
|
|
@@ -1442,6 +1475,7 @@ function createReadSeekClient(runner) {
|
|
|
1442
1475
|
at: options.at,
|
|
1443
1476
|
end: options.end,
|
|
1444
1477
|
limit: options.limit,
|
|
1478
|
+
depth: options.depth,
|
|
1445
1479
|
language: options.language,
|
|
1446
1480
|
visionMode: options.visionMode,
|
|
1447
1481
|
visionLevel: options.visionLevel,
|
|
@@ -2570,7 +2604,11 @@ var readSeekDetect = client.detect;
|
|
|
2570
2604
|
var readSeekEdit = client.edit;
|
|
2571
2605
|
var readSeekRename = client.rename;
|
|
2572
2606
|
async function readSeekMap(filePath, options = {}) {
|
|
2573
|
-
const envelope = await client.digest(filePath, {
|
|
2607
|
+
const envelope = await client.digest(filePath, {
|
|
2608
|
+
select: "map",
|
|
2609
|
+
depth: DEFAULT_DIGEST_MAP_DEPTH,
|
|
2610
|
+
signal: options.signal
|
|
2611
|
+
});
|
|
2574
2612
|
const map = envelope.map;
|
|
2575
2613
|
if (!map || map.language === "unknown" && map.symbols.length === 0)
|
|
2576
2614
|
return null;
|
|
@@ -3004,28 +3042,53 @@ import { Text as Text2, visibleWidth as visibleWidth3 } from "@earendil-works/pi
|
|
|
3004
3042
|
|
|
3005
3043
|
// src/tui-diff-renderer.ts
|
|
3006
3044
|
import { visibleWidth as visibleWidth2 } from "@earendil-works/pi-tui";
|
|
3007
|
-
function
|
|
3008
|
-
|
|
3045
|
+
function isDiffEntry(value) {
|
|
3046
|
+
if (typeof value !== "object" || value === null)
|
|
3047
|
+
return false;
|
|
3048
|
+
const entry = value;
|
|
3049
|
+
if (typeof entry.text !== "string")
|
|
3050
|
+
return false;
|
|
3051
|
+
if (entry.kind === "meta")
|
|
3052
|
+
return true;
|
|
3053
|
+
if (entry.kind === "add")
|
|
3054
|
+
return Number.isInteger(entry.newLine) && Number(entry.newLine) > 0;
|
|
3055
|
+
if (entry.kind === "remove")
|
|
3056
|
+
return Number.isInteger(entry.oldLine) && Number(entry.oldLine) > 0;
|
|
3057
|
+
return entry.kind === "context" && Number.isInteger(entry.oldLine) && Number(entry.oldLine) > 0 && Number.isInteger(entry.newLine) && Number(entry.newLine) > 0;
|
|
3058
|
+
}
|
|
3059
|
+
function indexedDiffEntries(data) {
|
|
3060
|
+
if (!Array.isArray(data.entries))
|
|
3061
|
+
return [];
|
|
3062
|
+
const entries = [];
|
|
3063
|
+
for (const [index, entry] of data.entries.entries()) {
|
|
3064
|
+
if (isDiffEntry(entry))
|
|
3065
|
+
entries.push([index, entry]);
|
|
3066
|
+
}
|
|
3067
|
+
return entries;
|
|
3068
|
+
}
|
|
3069
|
+
function hasOldSide(entries) {
|
|
3070
|
+
return entries.some(([, entry]) => entry.kind === "remove" || entry.kind === "context");
|
|
3009
3071
|
}
|
|
3010
|
-
function chooseMode(width,
|
|
3072
|
+
function chooseMode(width, entries) {
|
|
3011
3073
|
if (width < 24)
|
|
3012
3074
|
return "summary";
|
|
3013
3075
|
if (width < 50)
|
|
3014
3076
|
return "compact";
|
|
3015
|
-
if (width >= 100 && hasOldSide(
|
|
3077
|
+
if (width >= 100 && hasOldSide(entries))
|
|
3016
3078
|
return "split";
|
|
3017
3079
|
return "unified";
|
|
3018
3080
|
}
|
|
3019
|
-
function hunkCount(data) {
|
|
3020
|
-
|
|
3081
|
+
function hunkCount(data, entries) {
|
|
3082
|
+
const blockRangeCount = Array.isArray(data.blockRanges) ? data.blockRanges.length : undefined;
|
|
3083
|
+
return Math.max(1, blockRangeCount ?? (entries.some(([, entry]) => entry.kind === "add" || entry.kind === "remove") ? 1 : 0));
|
|
3021
3084
|
}
|
|
3022
3085
|
function compactHeader(data) {
|
|
3023
3086
|
return `↳ diff +${data.stats.added} -${data.stats.removed}`;
|
|
3024
3087
|
}
|
|
3025
|
-
function header(data, mode, width) {
|
|
3088
|
+
function header(data, mode, width, entries) {
|
|
3026
3089
|
if (mode === "summary" && width <= 10)
|
|
3027
3090
|
return `↳ diff +${data.stats.added}`;
|
|
3028
|
-
const full = `${compactHeader(data)} • ${hunkCount(data)} hunk • 1 file • ${mode === "split" ? "split" : "unified"}`;
|
|
3091
|
+
const full = `${compactHeader(data)} • ${hunkCount(data, entries)} hunk • 1 file • ${mode === "split" ? "split" : "unified"}`;
|
|
3029
3092
|
return visibleWidth2(full) <= width ? full : clampLineToWidth(compactHeader(data), width);
|
|
3030
3093
|
}
|
|
3031
3094
|
function lineNo(entry) {
|
|
@@ -3048,14 +3111,14 @@ function spans(theme, spans2, fallback) {
|
|
|
3048
3111
|
return spans2?.map((s) => s.kind === "add" ? theme.fg("success", s.text) : s.kind === "remove" ? theme.fg("error", s.text) : s.text).join("") ?? fallback;
|
|
3049
3112
|
}
|
|
3050
3113
|
function inlineText(input, index, entry) {
|
|
3051
|
-
const pair = input.diffData.inlineDiffs
|
|
3114
|
+
const pair = Array.isArray(input.diffData.inlineDiffs) ? input.diffData.inlineDiffs.find((d) => entry.kind === "remove" ? d.removeLineIndex === index : entry.kind === "add" ? d.addLineIndex === index : false) : undefined;
|
|
3052
3115
|
if (!pair)
|
|
3053
3116
|
return textOf(entry);
|
|
3054
3117
|
return entry.kind === "remove" ? spans(input.theme, pair.removeSpans, textOf(entry)) : entry.kind === "add" ? spans(input.theme, pair.addSpans, textOf(entry)) : textOf(entry);
|
|
3055
3118
|
}
|
|
3056
|
-
function unifiedRows(input, width) {
|
|
3119
|
+
function unifiedRows(input, width, entries) {
|
|
3057
3120
|
const rows = [];
|
|
3058
|
-
for (const [i, e] of
|
|
3121
|
+
for (const [i, e] of entries) {
|
|
3059
3122
|
if (e.kind === "meta")
|
|
3060
3123
|
continue;
|
|
3061
3124
|
const prefix = `▌${gutterMarker(e)} ${lineNo(e)} │ `;
|
|
@@ -3064,9 +3127,9 @@ function unifiedRows(input, width) {
|
|
|
3064
3127
|
}
|
|
3065
3128
|
return rows;
|
|
3066
3129
|
}
|
|
3067
|
-
function compactRows(input, width) {
|
|
3130
|
+
function compactRows(input, width, entries) {
|
|
3068
3131
|
const rows = [];
|
|
3069
|
-
for (const [i, e] of
|
|
3132
|
+
for (const [i, e] of entries) {
|
|
3070
3133
|
if (e.kind !== "add" && e.kind !== "remove")
|
|
3071
3134
|
continue;
|
|
3072
3135
|
const prefix = `▌${gutterMarker(e)} ${lineNo(e)} `;
|
|
@@ -3075,11 +3138,11 @@ function compactRows(input, width) {
|
|
|
3075
3138
|
}
|
|
3076
3139
|
return rows;
|
|
3077
3140
|
}
|
|
3078
|
-
function splitRows(input, width) {
|
|
3141
|
+
function splitRows(input, width, entries) {
|
|
3079
3142
|
const pane = Math.max(10, Math.floor((width - 3) / 2));
|
|
3080
3143
|
const rows = [`${padRightVisual("old", pane)} │ new`];
|
|
3081
3144
|
const blankPane = " ".repeat(pane);
|
|
3082
|
-
for (const [i, e] of
|
|
3145
|
+
for (const [i, e] of entries) {
|
|
3083
3146
|
if (e.kind === "remove") {
|
|
3084
3147
|
const left = wrapWithHangingIndent(`▌- ${e.oldLine} │ `, inlineText(input, i, e), pane, { tint: (text) => tint(input.theme, e, text) });
|
|
3085
3148
|
for (const line of left)
|
|
@@ -3107,13 +3170,18 @@ function hiddenHint(hiddenLines, hiddenHunks, width) {
|
|
|
3107
3170
|
}
|
|
3108
3171
|
function renderTuiDiff(input) {
|
|
3109
3172
|
const width = normalizeWidth(input.width);
|
|
3110
|
-
const
|
|
3111
|
-
const
|
|
3173
|
+
const entries = indexedDiffEntries(input.diffData);
|
|
3174
|
+
const rawEntryCount = Array.isArray(input.diffData.entries) ? input.diffData.entries.length : input.diffData.stats.added + input.diffData.stats.removed + input.diffData.stats.context;
|
|
3175
|
+
const truncated = !Array.isArray(input.diffData.entries) || entries.length !== rawEntryCount;
|
|
3176
|
+
const mode = chooseMode(width, entries);
|
|
3177
|
+
const lines = [header(input.diffData, mode, width, entries)];
|
|
3112
3178
|
if (!input.expanded)
|
|
3113
|
-
return { mode, width, lines: clampLinesToWidth([...lines, hiddenHint(
|
|
3179
|
+
return { mode, width, lines: clampLinesToWidth([...lines, hiddenHint(rawEntryCount, hunkCount(input.diffData, entries), width)], width) };
|
|
3114
3180
|
if (mode === "summary")
|
|
3115
3181
|
return { mode, width, lines: clampLinesToWidth(lines, width) };
|
|
3116
|
-
const rows = mode === "split" ? splitRows(input, width) : mode === "compact" ? compactRows(input, width) : unifiedRows(input, width);
|
|
3182
|
+
const rows = mode === "split" ? splitRows(input, width, entries) : mode === "compact" ? compactRows(input, width, entries) : unifiedRows(input, width, entries);
|
|
3183
|
+
if (truncated)
|
|
3184
|
+
rows.push(clampLineToWidth("… diff preview truncated", width));
|
|
3117
3185
|
return { mode, width, lines: [...lines, ...rows] };
|
|
3118
3186
|
}
|
|
3119
3187
|
|
|
@@ -5359,6 +5427,7 @@ var digestSchema = Type10.Object({
|
|
|
5359
5427
|
})),
|
|
5360
5428
|
end: optionalIntOrString(PARAM_DESCRIPTIONS.end),
|
|
5361
5429
|
limit: optionalIntOrString(PARAM_DESCRIPTIONS.limit),
|
|
5430
|
+
depth: optionalIntOrString(PARAM_DESCRIPTIONS.digestDepth),
|
|
5362
5431
|
language: Type10.Optional(Type10.String({ description: PARAM_DESCRIPTIONS.languageOverride })),
|
|
5363
5432
|
visionMode: Type10.Optional(Type10.Union(VISION_MODES.map((mode) => Type10.Literal(mode)), { description: PARAM_DESCRIPTIONS.visionModeDigest })),
|
|
5364
5433
|
visionLevel: Type10.Optional(Type10.Union(VISION_LEVELS.map((level) => Type10.Literal(level)), { description: PARAM_DESCRIPTIONS.visionLevel }))
|
|
@@ -5472,6 +5541,14 @@ async function executeDigest(opts) {
|
|
|
5472
5541
|
const message = limit.ok ? `Invalid limit: expected a positive integer, received ${limit.value}.` : limit.message;
|
|
5473
5542
|
return buildToolErrorResult("digest", "invalid-parameter", message, { path: p.path });
|
|
5474
5543
|
}
|
|
5544
|
+
const depth = coerceObviousBase10Int2(p.depth, "depth");
|
|
5545
|
+
if (!depth.ok || depth.value !== undefined && depth.value < 0) {
|
|
5546
|
+
const message = depth.ok ? `Invalid depth: expected a non-negative integer, received ${depth.value}.` : depth.message;
|
|
5547
|
+
return buildToolErrorResult("digest", "invalid-parameter", message, { path: p.path });
|
|
5548
|
+
}
|
|
5549
|
+
if (depth.value !== undefined && !facets.includes("map")) {
|
|
5550
|
+
return buildToolErrorResult("digest", "invalid-parameter", "depth requires the map facet.", { path: p.path });
|
|
5551
|
+
}
|
|
5475
5552
|
const at = typeof p.at === "string" ? p.at.trim() : undefined;
|
|
5476
5553
|
if (p.at !== undefined && !at) {
|
|
5477
5554
|
return buildToolErrorResult("digest", "invalid-parameter", "Invalid at: expected a non-empty location.", {
|
|
@@ -5484,7 +5561,11 @@ async function executeDigest(opts) {
|
|
|
5484
5561
|
});
|
|
5485
5562
|
}
|
|
5486
5563
|
const filePath = resolveToCwd2(p.path, cwd);
|
|
5487
|
-
const commonOptions = {
|
|
5564
|
+
const commonOptions = {
|
|
5565
|
+
select,
|
|
5566
|
+
signal,
|
|
5567
|
+
depth: depth.value ?? (facets.includes("map") ? DEFAULT_DIGEST_MAP_DEPTH : undefined)
|
|
5568
|
+
};
|
|
5488
5569
|
const textOptions = {
|
|
5489
5570
|
...commonOptions,
|
|
5490
5571
|
at,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-readseek",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.16",
|
|
4
4
|
"description": "Pi extension for LINE:HASH-anchored file operations and structural code navigation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"node": ">=20.0.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@jarkkojs/readseek": "^0.9.
|
|
43
|
-
"@jarkkojs/readseek-api": "^0.9.15",
|
|
42
|
+
"@jarkkojs/readseek-api": "^0.9.16",
|
|
44
43
|
"diff": "^9.0.0",
|
|
45
44
|
"xxhash-wasm": "^1.1.0"
|
|
46
45
|
},
|
package/prompts/digest.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Digest source content and images into the native CLI envelope. Returns `metadata` plus requested facets unchanged from `readseek digest`.
|
|
2
2
|
|
|
3
|
-
Use this
|
|
4
|
-
|
|
3
|
+
Use this for anchored content, diagnostics, cursor identity, or a shallow structural
|
|
4
|
+
map. Prefer `def`, `refs`, or `search` when the question targets a symbol.
|
|
5
5
|
|
|
6
6
|
## Parameters
|
|
7
7
|
|
|
@@ -11,6 +11,7 @@ diagnostics after edits, or a structural map.
|
|
|
11
11
|
- `at` — location: `line:N[:COLUMN]`, `hash:HASH[:COLUMN]`, or `symbol:NAME`.
|
|
12
12
|
- `end` — last line to include (with content).
|
|
13
13
|
- `limit` — maximum lines to include (with content).
|
|
14
|
+
- `depth` — maximum structural depth for `map`; agent tools default to `1`.
|
|
14
15
|
- `language` — language override when detection is ambiguous.
|
|
15
16
|
- `visionMode` — standalone image mode: `none`, `all`, `ocr`, `caption`, or
|
|
16
17
|
`objects`.
|
|
@@ -23,7 +24,7 @@ diagnostics after edits, or a structural map.
|
|
|
23
24
|
| -------------- | ---------------------------------------------------- |
|
|
24
25
|
| `metadata` | File kind, language, and engine |
|
|
25
26
|
| `content` | Anchored text or prepared/analyzed image payload |
|
|
26
|
-
| `map` | Structural
|
|
27
|
+
| `map` | Structural outline; start shallow and deepen as needed |
|
|
27
28
|
| `diagnostics` | Parser errors and missing syntax nodes |
|
|
28
29
|
| `identity` | Token and enclosing symbol at `at` |
|
|
29
30
|
|