opencode-readseek 0.9.13 → 0.9.14
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 +13 -46
- package/dist/index.js +173 -80
- package/package.json +4 -5
- package/LICENSE +0 -176
package/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# opencode-readseek
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`opencode-readseek` adds anchored file operations, structural search, symbol
|
|
6
|
-
navigation, and document tools to OpenCode.
|
|
3
|
+
OpenCode plugin for anchored edits, structural search, symbol navigation, and
|
|
4
|
+
document inspection.
|
|
7
5
|
|
|
8
6
|
## Install
|
|
9
7
|
|
|
10
|
-
Add the
|
|
8
|
+
Add the plugin to `opencode.json`:
|
|
11
9
|
|
|
12
10
|
```json
|
|
13
11
|
{
|
|
@@ -15,38 +13,16 @@ Add the package to `opencode.json`:
|
|
|
15
13
|
}
|
|
16
14
|
```
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
The plugin uses the native binary supplied by `@jarkkojs/readseek`. Set
|
|
17
|
+
`READSEEK_BINARY` to an absolute executable path to override it.
|
|
20
18
|
|
|
21
19
|
## Tools
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
| `readseek_write` | Create or replace a complete text file |
|
|
27
|
-
| `readseek_grep` | Search text or regex and return anchors |
|
|
28
|
-
| `readseek_digest` | Native digest envelope: metadata, content, map, diagnostics, identity |
|
|
29
|
-
| `readseek_search` | Search AST patterns |
|
|
30
|
-
| `readseek_def` | Find symbol definitions |
|
|
31
|
-
| `readseek_refs` | Find identifier usages, optionally scoped to a cursor binding |
|
|
32
|
-
| `readseek_rename` | Apply a binding-aware rename; set `apply: false` for a dry run |
|
|
33
|
-
| `readseek_view` | View or narrow a structural document index |
|
|
34
|
-
|
|
35
|
-
The plugin requests read, grep, external-directory, and edit permissions as
|
|
36
|
-
needed. Mutations invalidate remembered anchors; compaction preserves fresh
|
|
37
|
-
paths and pending rename plans. Text reads return at most 2,000 lines by
|
|
38
|
-
default.
|
|
39
|
-
|
|
40
|
-
OpenCode is instructed to prefer ReadSeek over the built-in `read`, `edit`,
|
|
41
|
-
`write`, `grep`, and `apply_patch` tools when ReadSeek can do the job. Built-ins
|
|
42
|
-
remain available as fallbacks.
|
|
43
|
-
|
|
44
|
-
Documents such as PDFs are owned by `readseek_view`. Calling `readseek_digest`
|
|
45
|
-
on a document returns a cache receipt and directs the caller to `readseek_view`.
|
|
21
|
+
`readseek_edit`, `readseek_write`, `readseek_grep`, `readseek_digest`,
|
|
22
|
+
`readseek_search`, `readseek_def`, `readseek_refs`, `readseek_rename`, and
|
|
23
|
+
`readseek_view`.
|
|
46
24
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Pass options with OpenCode's plugin tuple syntax:
|
|
25
|
+
To control image handling:
|
|
50
26
|
|
|
51
27
|
```json
|
|
52
28
|
{
|
|
@@ -54,15 +30,7 @@ Pass options with OpenCode's plugin tuple syntax:
|
|
|
54
30
|
}
|
|
55
31
|
```
|
|
56
32
|
|
|
57
|
-
`imageMode`
|
|
58
|
-
|
|
59
|
-
- `"auto"` (default): expose `none`, `all`, `ocr`, `caption`, and `objects`.
|
|
60
|
-
- `"on"`: expose local analysis modes and omit `none`.
|
|
61
|
-
- `"off"`: skip image reads.
|
|
62
|
-
|
|
63
|
-
Omitting `image` from a read also skips image files. Document asset analysis
|
|
64
|
-
uses `readseek_view` with optional `visionMode` (`all` | `ocr` | `caption` |
|
|
65
|
-
`objects`) and `visionLevel` (`low` | `medium` | `high`).
|
|
33
|
+
`imageMode` is `auto` (default), `on`, or `off`.
|
|
66
34
|
|
|
67
35
|
## Development
|
|
68
36
|
|
|
@@ -72,8 +40,7 @@ bun test
|
|
|
72
40
|
bun run typecheck
|
|
73
41
|
```
|
|
74
42
|
|
|
75
|
-
## License
|
|
76
43
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Apache
|
|
44
|
+
## Licensing
|
|
45
|
+
|
|
46
|
+
[Apache 2.0](../../LICENSE-APACHE-2.0).
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,6 @@ import path7 from "node:path";
|
|
|
3
3
|
|
|
4
4
|
// src/client.ts
|
|
5
5
|
import { createRequire as createRequire2 } from "node:module";
|
|
6
|
-
import { homedir } from "node:os";
|
|
7
|
-
import path3 from "node:path";
|
|
8
6
|
import { stat } from "node:fs/promises";
|
|
9
7
|
|
|
10
8
|
// ../readseek-api/src/contract.ts
|
|
@@ -23,6 +21,13 @@ var DOCUMENT_NODE_KINDS = [
|
|
|
23
21
|
"section",
|
|
24
22
|
"structural_section"
|
|
25
23
|
];
|
|
24
|
+
var EDIT_VARIANTS = [
|
|
25
|
+
"set_line",
|
|
26
|
+
"replace_lines",
|
|
27
|
+
"insert_after",
|
|
28
|
+
"replace",
|
|
29
|
+
"replace_symbol"
|
|
30
|
+
];
|
|
26
31
|
var TOOL_NAMES = [
|
|
27
32
|
"digest",
|
|
28
33
|
"edit",
|
|
@@ -478,6 +483,24 @@ function fallbackToolDescriptionMap(builtIns = Object.keys(BUILTIN_FALLBACKS), a
|
|
|
478
483
|
return description ? [[builtIn, description]] : [];
|
|
479
484
|
}));
|
|
480
485
|
}
|
|
486
|
+
// ../readseek-api/src/hashline.ts
|
|
487
|
+
var LINE_ANCHOR_RE = /^(\d+):([0-9a-fA-F]{6})$/;
|
|
488
|
+
function tryParseLineAnchor(anchor) {
|
|
489
|
+
const match = LINE_ANCHOR_RE.exec(anchor.trim());
|
|
490
|
+
if (!match) {
|
|
491
|
+
return { ok: false, error: `invalid LINE:HASH anchor: ${anchor}` };
|
|
492
|
+
}
|
|
493
|
+
const digits = match[1];
|
|
494
|
+
const line = Number.parseInt(digits, 10);
|
|
495
|
+
if (!Number.isSafeInteger(line)) {
|
|
496
|
+
return { ok: false, error: `Line number must be a safe integer, got ${digits} in "${anchor}".` };
|
|
497
|
+
}
|
|
498
|
+
if (line < 1) {
|
|
499
|
+
return { ok: false, error: `Line number must be >= 1, got ${line} in "${anchor}".` };
|
|
500
|
+
}
|
|
501
|
+
return { ok: true, anchor: { line, hash: match[2].toLowerCase() } };
|
|
502
|
+
}
|
|
503
|
+
|
|
481
504
|
// ../readseek-api/src/validation.ts
|
|
482
505
|
function validateGitSelection(input) {
|
|
483
506
|
if (input.ignored && !input.others) {
|
|
@@ -509,6 +532,73 @@ function validateVisionLevelVsMode(input) {
|
|
|
509
532
|
}
|
|
510
533
|
return { ok: true };
|
|
511
534
|
}
|
|
535
|
+
var VARIANT_FIELDS = {
|
|
536
|
+
set_line: ["anchor", "new_text"],
|
|
537
|
+
replace_lines: ["start_anchor", "end_anchor", "new_text"],
|
|
538
|
+
insert_after: ["anchor", "new_text"],
|
|
539
|
+
replace: ["old_text", "new_text"],
|
|
540
|
+
replace_symbol: ["symbol", "new_body"]
|
|
541
|
+
};
|
|
542
|
+
function isEditVariant(value) {
|
|
543
|
+
return EDIT_VARIANTS.includes(value);
|
|
544
|
+
}
|
|
545
|
+
function parseEditItem(item, index) {
|
|
546
|
+
const keys = Object.keys(item);
|
|
547
|
+
const variant = keys[0];
|
|
548
|
+
if (keys.length !== 1 || variant === undefined || !isEditVariant(variant)) {
|
|
549
|
+
return {
|
|
550
|
+
ok: false,
|
|
551
|
+
error: `edits[${index}] must contain exactly one of: ${EDIT_VARIANTS.join(", ")}. Got: [${keys.join(", ")}]`
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
const payload = item[variant];
|
|
555
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
556
|
+
return { ok: false, error: `edits[${index}].${variant} must be an object` };
|
|
557
|
+
}
|
|
558
|
+
const expected = VARIANT_FIELDS[variant];
|
|
559
|
+
const allowed = variant === "replace" ? [...expected, "all"] : [...expected];
|
|
560
|
+
const actual = Object.keys(payload);
|
|
561
|
+
if (actual.some((field) => !allowed.includes(field)) || expected.some((field) => !actual.includes(field))) {
|
|
562
|
+
return { ok: false, error: `edits[${index}].${variant} contains invalid fields` };
|
|
563
|
+
}
|
|
564
|
+
const values = payload;
|
|
565
|
+
for (const field of expected) {
|
|
566
|
+
if (typeof values[field] !== "string") {
|
|
567
|
+
return { ok: false, error: `edits[${index}].${variant}.${field} must be a string` };
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (variant === "replace" && values.all !== undefined && typeof values.all !== "boolean") {
|
|
571
|
+
return { ok: false, error: `edits[${index}].replace.all must be a boolean` };
|
|
572
|
+
}
|
|
573
|
+
for (const field of expected) {
|
|
574
|
+
if (!field.endsWith("anchor"))
|
|
575
|
+
continue;
|
|
576
|
+
const parsed = tryParseLineAnchor(values[field]);
|
|
577
|
+
if (!parsed.ok) {
|
|
578
|
+
return { ok: false, error: `edits[${index}].${variant}.${field}: ${parsed.error}` };
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return { ok: true, edit: item };
|
|
582
|
+
}
|
|
583
|
+
function validateExactlyOneEditVariant(edits) {
|
|
584
|
+
if (!Array.isArray(edits) || edits.length === 0) {
|
|
585
|
+
return { ok: false, error: "edits must contain at least one edit" };
|
|
586
|
+
}
|
|
587
|
+
const normalized = [];
|
|
588
|
+
for (let index = 0;index < edits.length; index++) {
|
|
589
|
+
const item = edits[index];
|
|
590
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
591
|
+
return { ok: false, error: `edits[${index}] must be an edit object` };
|
|
592
|
+
}
|
|
593
|
+
const parsed = parseEditItem(item, index);
|
|
594
|
+
if (!parsed.ok)
|
|
595
|
+
return parsed;
|
|
596
|
+
normalized.push(parsed.edit);
|
|
597
|
+
}
|
|
598
|
+
return { ok: true, edits: normalized };
|
|
599
|
+
}
|
|
600
|
+
var MIN_SAFE_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
|
|
601
|
+
var MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
|
|
512
602
|
// ../readseek-api/src/argv.ts
|
|
513
603
|
function buildLineLocation(line, column) {
|
|
514
604
|
return column === undefined ? `line:${line}` : `line:${line}:${column}`;
|
|
@@ -518,14 +608,12 @@ function appendGitSelectionArgs(args, input) {
|
|
|
518
608
|
if (!validated.ok) {
|
|
519
609
|
throw new Error(validated.error);
|
|
520
610
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
args.push("--git", selection.join(","));
|
|
528
|
-
}
|
|
611
|
+
if (input.cached)
|
|
612
|
+
args.push("--cached");
|
|
613
|
+
if (input.others)
|
|
614
|
+
args.push("--others");
|
|
615
|
+
if (input.ignored)
|
|
616
|
+
args.push("--ignored");
|
|
529
617
|
return args;
|
|
530
618
|
}
|
|
531
619
|
function pushOptionalString(args, flag, value) {
|
|
@@ -602,15 +690,17 @@ function buildViewArgs(input) {
|
|
|
602
690
|
return args;
|
|
603
691
|
}
|
|
604
692
|
function buildSearchArgs(input) {
|
|
605
|
-
const args = ["search", input.
|
|
693
|
+
const args = ["search", input.pattern];
|
|
694
|
+
pushOptionalString(args, "--path", input.path);
|
|
606
695
|
pushOptionalString(args, "--language", input.language);
|
|
696
|
+
pushOptionalNumber(args, "--limit", input.limit);
|
|
607
697
|
return appendGitSelectionArgs(args, input);
|
|
608
698
|
}
|
|
609
699
|
function buildDefArgs(input) {
|
|
610
|
-
const args = ["def", input.
|
|
700
|
+
const args = ["def", input.name];
|
|
701
|
+
pushOptionalString(args, "--path", input.path);
|
|
611
702
|
if (input.format !== undefined)
|
|
612
703
|
args.push("--format", input.format);
|
|
613
|
-
args.push(input.name);
|
|
614
704
|
pushOptionalString(args, "--language", input.language);
|
|
615
705
|
return appendGitSelectionArgs(args, input);
|
|
616
706
|
}
|
|
@@ -618,11 +708,14 @@ function buildRefsArgs(input) {
|
|
|
618
708
|
const validated = validateRefsNameVsScope(input);
|
|
619
709
|
if (!validated.ok)
|
|
620
710
|
throw new Error(validated.error);
|
|
621
|
-
const args = ["refs"
|
|
622
|
-
if (input.
|
|
623
|
-
args.push("--at", buildLineLocation(input.line, input.column));
|
|
624
|
-
} else if (input.name !== undefined) {
|
|
711
|
+
const args = ["refs"];
|
|
712
|
+
if (input.name !== undefined)
|
|
625
713
|
args.push(input.name);
|
|
714
|
+
pushOptionalString(args, "--path", input.path);
|
|
715
|
+
if (input.scope) {
|
|
716
|
+
args.push("--scope");
|
|
717
|
+
pushOptionalNumber(args, "--line", input.line);
|
|
718
|
+
pushOptionalNumber(args, "--column", input.column);
|
|
626
719
|
}
|
|
627
720
|
if (input.format !== undefined)
|
|
628
721
|
args.push("--format", input.format);
|
|
@@ -638,13 +731,13 @@ function buildEditArgs(input) {
|
|
|
638
731
|
});
|
|
639
732
|
pushOptionalString(args, "--language", input.language);
|
|
640
733
|
if (input.requestFromStdin)
|
|
641
|
-
args.push("--
|
|
734
|
+
args.push("--edits", "-");
|
|
642
735
|
return args;
|
|
643
736
|
}
|
|
644
737
|
function buildRenameArgs(input) {
|
|
645
738
|
const args = ["rename", input.path, "--at", buildLineLocation(input.line, input.column), "--to", input.to];
|
|
646
739
|
if (input.workspace !== undefined)
|
|
647
|
-
args.push(
|
|
740
|
+
args.push(`--workspace=${input.workspace}`);
|
|
648
741
|
appendApplyAndPlanHash(args, {
|
|
649
742
|
apply: input.apply,
|
|
650
743
|
planHash: input.planHash,
|
|
@@ -654,9 +747,11 @@ function buildRenameArgs(input) {
|
|
|
654
747
|
return appendGitSelectionArgs(args, input);
|
|
655
748
|
}
|
|
656
749
|
// ../readseek-api/src/platform.ts
|
|
657
|
-
import { accessSync, constants as fsConstants } from "node:fs";
|
|
750
|
+
import { accessSync, constants as fsConstants, existsSync, statSync } from "node:fs";
|
|
658
751
|
import { createRequire } from "node:module";
|
|
752
|
+
import { homedir } from "node:os";
|
|
659
753
|
import path from "node:path";
|
|
754
|
+
var READSEEK_BINARY_ENV = "READSEEK_BINARY";
|
|
660
755
|
var READSEEK_PLATFORM_PACKAGES = {
|
|
661
756
|
"darwin-arm64": "@jarkkojs/readseek-darwin-arm64",
|
|
662
757
|
"linux-arm64": "@jarkkojs/readseek-linux-arm64",
|
|
@@ -670,6 +765,24 @@ function readSeekBinaryName(platform = process.platform) {
|
|
|
670
765
|
function readSeekPlatformKey(platform = process.platform, arch = process.arch) {
|
|
671
766
|
return `${platform}-${arch}`;
|
|
672
767
|
}
|
|
768
|
+
function resolveReadSeekBinaryOverride(environment = process.env) {
|
|
769
|
+
const binaryPath = environment[READSEEK_BINARY_ENV];
|
|
770
|
+
if (binaryPath === undefined)
|
|
771
|
+
return null;
|
|
772
|
+
if (!path.isAbsolute(binaryPath)) {
|
|
773
|
+
throw new Error(`${READSEEK_BINARY_ENV} must be an absolute path to the readseek executable`);
|
|
774
|
+
}
|
|
775
|
+
try {
|
|
776
|
+
if (!statSync(binaryPath).isFile())
|
|
777
|
+
throw new Error("not a regular file");
|
|
778
|
+
accessSync(binaryPath, fsConstants.X_OK);
|
|
779
|
+
} catch (error) {
|
|
780
|
+
throw new Error(`${READSEEK_BINARY_ENV} does not point to an executable file: ${binaryPath}`, {
|
|
781
|
+
cause: error
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
return binaryPath;
|
|
785
|
+
}
|
|
673
786
|
function resolveReadSeekBinaryFromPackages(resolver = resolveFromPackage, options = {}) {
|
|
674
787
|
const resolve = typeof resolver === "function" ? resolver : resolver.resolve.bind(resolver);
|
|
675
788
|
const platform = options.platform ?? process.platform;
|
|
@@ -695,6 +808,37 @@ function resolveReadSeekBinaryFromPackages(resolver = resolveFromPackage, option
|
|
|
695
808
|
accessSync(binaryPath, fsConstants.X_OK);
|
|
696
809
|
return binaryPath;
|
|
697
810
|
}
|
|
811
|
+
function resolveReadSeekCacheDir(subPath, options = {}) {
|
|
812
|
+
const env = options.environment ?? process.env;
|
|
813
|
+
const platform = options.platform ?? process.platform;
|
|
814
|
+
const home = options.homedir ? options.homedir() : homedir();
|
|
815
|
+
const cwd = options.cwd ?? process.cwd();
|
|
816
|
+
const localDirName = options.localDirName ?? ".readseek";
|
|
817
|
+
if (localDirName && localDirName.length > 0) {
|
|
818
|
+
const local = path.join(cwd, localDirName);
|
|
819
|
+
if (existsSync(local))
|
|
820
|
+
return local;
|
|
821
|
+
}
|
|
822
|
+
let base;
|
|
823
|
+
if (platform === "win32") {
|
|
824
|
+
base = env.LOCALAPPDATA ?? path.join(home, "AppData", "Local");
|
|
825
|
+
} else {
|
|
826
|
+
const xdg = env.XDG_CACHE_HOME?.trim();
|
|
827
|
+
base = xdg && path.isAbsolute(xdg) ? xdg : path.join(home, ".cache");
|
|
828
|
+
}
|
|
829
|
+
const pathModule = platform === "win32" ? path.win32 : path;
|
|
830
|
+
if (subPath === undefined) {
|
|
831
|
+
return pathModule.join(base, "readseek");
|
|
832
|
+
}
|
|
833
|
+
const parts = Array.isArray(subPath) ? subPath : [subPath];
|
|
834
|
+
return pathModule.join(base, ...parts);
|
|
835
|
+
}
|
|
836
|
+
// ../readseek-api/src/path.ts
|
|
837
|
+
import path2 from "node:path";
|
|
838
|
+
function isSubPath(parent, candidate) {
|
|
839
|
+
const relative = path2.relative(parent, candidate);
|
|
840
|
+
return relative === "" || !relative.startsWith(`..${path2.sep}`) && relative !== ".." && !path2.isAbsolute(relative);
|
|
841
|
+
}
|
|
698
842
|
// ../readseek-api/src/json.ts
|
|
699
843
|
var READSEEK_USAGE_HINT = /\n\s*Run readseek(?: [\w-]+)* --help for more information\.?\s*$/;
|
|
700
844
|
function cleanReadSeekErrorText(stderr) {
|
|
@@ -847,7 +991,7 @@ var VISION_LEVEL_VALUES = [...VISION_LEVELS];
|
|
|
847
991
|
var DOCUMENT_NODE_KIND_VALUES = [...DOCUMENT_NODE_KINDS];
|
|
848
992
|
|
|
849
993
|
// src/util.ts
|
|
850
|
-
import
|
|
994
|
+
import path3 from "node:path";
|
|
851
995
|
function render(value) {
|
|
852
996
|
return JSON.stringify(value, null, 2);
|
|
853
997
|
}
|
|
@@ -885,11 +1029,11 @@ function renameFiles(value) {
|
|
|
885
1029
|
const output = record(value);
|
|
886
1030
|
const files = [];
|
|
887
1031
|
if (typeof output.file === "string" && items(output.edits).length > 0)
|
|
888
|
-
files.push(
|
|
1032
|
+
files.push(path3.resolve(output.file));
|
|
889
1033
|
for (const other of items(output.others)) {
|
|
890
1034
|
const item = record(other);
|
|
891
1035
|
if (typeof item.file === "string" && items(item.edits).length > 0)
|
|
892
|
-
files.push(
|
|
1036
|
+
files.push(path3.resolve(item.file));
|
|
893
1037
|
}
|
|
894
1038
|
return files;
|
|
895
1039
|
}
|
|
@@ -960,7 +1104,7 @@ function readRangeArgs(filePath, start, end) {
|
|
|
960
1104
|
return digestArgs(filePath, "content", extra);
|
|
961
1105
|
}
|
|
962
1106
|
function readSeekBinaryPath() {
|
|
963
|
-
return resolveReadSeekBinaryFromPackages(resolveFromHost);
|
|
1107
|
+
return resolveReadSeekBinaryOverride() ?? resolveReadSeekBinaryFromPackages(resolveFromHost);
|
|
964
1108
|
}
|
|
965
1109
|
async function preserveAbortReason(signal, cancelable, invoke) {
|
|
966
1110
|
try {
|
|
@@ -1015,9 +1159,7 @@ async function postMutationPreview(context, args, filePath, changed) {
|
|
|
1015
1159
|
}
|
|
1016
1160
|
var readSeekCacheInit;
|
|
1017
1161
|
function readSeekCacheDir() {
|
|
1018
|
-
|
|
1019
|
-
const cacheHome = xdgCacheHome || path3.join(homedir(), ".cache");
|
|
1020
|
-
return path3.join(cacheHome, "opencode", "readseek");
|
|
1162
|
+
return resolveReadSeekCacheDir(["opencode", "readseek"], { localDirName: "" });
|
|
1021
1163
|
}
|
|
1022
1164
|
async function ensureReadSeekCache(context) {
|
|
1023
1165
|
const cacheDir = readSeekCacheDir();
|
|
@@ -1154,55 +1296,10 @@ async function withFileMutationQueue(filePath, operation) {
|
|
|
1154
1296
|
fileMutationTails.delete(key);
|
|
1155
1297
|
}
|
|
1156
1298
|
}
|
|
1157
|
-
function parseAnchor(anchor) {
|
|
1158
|
-
const match = /^(\d+):([0-9a-fA-F]{3})$/.exec(anchor.trim());
|
|
1159
|
-
if (!match)
|
|
1160
|
-
throw new Error(`invalid LINE:HASH anchor: ${anchor}`);
|
|
1161
|
-
const line = Number(match[1]);
|
|
1162
|
-
if (line === 0)
|
|
1163
|
-
throw new Error(`anchor line must be greater than zero: ${anchor}`);
|
|
1164
|
-
return { line, hash: match[2].toLowerCase() };
|
|
1165
|
-
}
|
|
1166
1299
|
function validateEdits(value) {
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
set_line: ["anchor", "new_text"],
|
|
1171
|
-
replace_lines: ["end_anchor", "new_text", "start_anchor"],
|
|
1172
|
-
insert_after: ["anchor", "new_text"],
|
|
1173
|
-
replace: ["new_text", "old_text"],
|
|
1174
|
-
replace_symbol: ["new_body", "symbol"]
|
|
1175
|
-
};
|
|
1176
|
-
for (const [index, item] of value.entries()) {
|
|
1177
|
-
if (!item || typeof item !== "object")
|
|
1178
|
-
throw new Error(`edits[${index}] must be an edit object`);
|
|
1179
|
-
const keys = Object.keys(item);
|
|
1180
|
-
const variant = keys[0];
|
|
1181
|
-
if (keys.length !== 1 || !Object.hasOwn(requiredFields, variant)) {
|
|
1182
|
-
throw new Error(`edits[${index}] must contain exactly one of: set_line, replace_lines, insert_after, replace, replace_symbol`);
|
|
1183
|
-
}
|
|
1184
|
-
const payload = item[variant];
|
|
1185
|
-
if (!payload || typeof payload !== "object")
|
|
1186
|
-
throw new Error(`edits[${index}].${variant} must be an object`);
|
|
1187
|
-
const expectedFields = requiredFields[variant];
|
|
1188
|
-
const allowedFields = variant === "replace" ? [...expectedFields, "all"] : expectedFields;
|
|
1189
|
-
const actualFields = Object.keys(payload).sort();
|
|
1190
|
-
if (actualFields.some((field) => !allowedFields.includes(field)) || expectedFields.some((field) => !actualFields.includes(field))) {
|
|
1191
|
-
throw new Error(`edits[${index}].${variant} contains invalid fields`);
|
|
1192
|
-
}
|
|
1193
|
-
const values = payload;
|
|
1194
|
-
for (const field of expectedFields) {
|
|
1195
|
-
if (typeof values[field] !== "string") {
|
|
1196
|
-
throw new Error(`edits[${index}].${variant}.${field} must be a string`);
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
if (variant === "replace" && values.all !== undefined && typeof values.all !== "boolean") {
|
|
1200
|
-
throw new Error(`edits[${index}].replace.all must be a boolean`);
|
|
1201
|
-
}
|
|
1202
|
-
for (const field of expectedFields.filter((field2) => field2.endsWith("anchor"))) {
|
|
1203
|
-
parseAnchor(values[field]);
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1300
|
+
const parsed = validateExactlyOneEditVariant(value);
|
|
1301
|
+
if (!parsed.ok)
|
|
1302
|
+
throw new Error(parsed.error);
|
|
1206
1303
|
}
|
|
1207
1304
|
function firstChangedLine(before, after) {
|
|
1208
1305
|
const beforeLines = normalizeToLf(before).split(`
|
|
@@ -1373,10 +1470,6 @@ import path6 from "node:path";
|
|
|
1373
1470
|
function resolvePath(directory, filePath) {
|
|
1374
1471
|
return path6.resolve(directory, filePath);
|
|
1375
1472
|
}
|
|
1376
|
-
function containsPath(directory, filePath) {
|
|
1377
|
-
const relative = path6.relative(directory, filePath);
|
|
1378
|
-
return relative === "" || !relative.startsWith(`..${path6.sep}`) && relative !== ".." && !path6.isAbsolute(relative);
|
|
1379
|
-
}
|
|
1380
1473
|
async function resolveSymlinks(filePath) {
|
|
1381
1474
|
let unresolved = path6.resolve(filePath);
|
|
1382
1475
|
let symlinks = 0;
|
|
@@ -1439,7 +1532,7 @@ async function authorizeExternal(context, filePath) {
|
|
|
1439
1532
|
canonicalPath(context.directory),
|
|
1440
1533
|
context.worktree === "/" ? Promise.resolve("/") : canonicalPath(context.worktree)
|
|
1441
1534
|
]);
|
|
1442
|
-
if (
|
|
1535
|
+
if (isSubPath(directory, accessPath) || worktree !== "/" && isSubPath(worktree, accessPath)) {
|
|
1443
1536
|
return;
|
|
1444
1537
|
}
|
|
1445
1538
|
const info = await stat2(accessPath).catch(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-readseek",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.14",
|
|
4
4
|
"description": "OpenCode plugin for anchored file operations and structural code navigation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"files": [
|
|
23
23
|
"dist/",
|
|
24
|
-
"README.md"
|
|
25
|
-
"LICENSE"
|
|
24
|
+
"README.md"
|
|
26
25
|
],
|
|
27
26
|
"scripts": {
|
|
28
27
|
"build": "bun build ./index.ts --outfile dist/index.js --target=node --format=esm --packages=external",
|
|
@@ -33,11 +32,11 @@
|
|
|
33
32
|
"node": ">=20.0.0"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
|
-
"@jarkkojs/readseek": "^0.9.
|
|
35
|
+
"@jarkkojs/readseek": "^0.9.14",
|
|
37
36
|
"@opencode-ai/plugin": "^1.17.20"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@types/bun": "^1.3.14",
|
|
41
|
-
"typescript": "^
|
|
40
|
+
"typescript": "^5.9.3"
|
|
42
41
|
}
|
|
43
42
|
}
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
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
|