pi-readseek 0.4.14 → 0.4.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-readseek",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "description": "Pi extension for readseek-backed hash-anchored read/edit/grep, structural code maps, structural search, and file exploration",
5
5
  "type": "module",
6
6
  "exports": {
@@ -39,7 +39,7 @@
39
39
  "node": ">=20.0.0"
40
40
  },
41
41
  "dependencies": {
42
- "@jarkkojs/readseek": "^0.4.19",
42
+ "@jarkkojs/readseek": "^0.4.20",
43
43
  "diff": "^8.0.3",
44
44
  "ignore": "^7.0.5",
45
45
  "picomatch": "^4.0.4",
package/src/read.ts CHANGED
@@ -169,7 +169,7 @@ export async function executeRead(opts: ExecuteReadOptions): Promise<AgentToolRe
169
169
  } catch {
170
170
  // detect unavailable — fall through to binary-as-text handling below
171
171
  }
172
- if (detection?.image) {
172
+ if (detection?.type === "image") {
173
173
  const builtinRead = createReadTool(cwd);
174
174
  const builtinResult = await builtinRead.execute(toolCallId, p, signal, onUpdate);
175
175
  const ocrText = detection.ocr?.text?.trim();
@@ -108,13 +108,6 @@ export interface ReadSeekCheckOutput {
108
108
  diagnostics: ReadSeekDiagnostic[];
109
109
  }
110
110
 
111
- export interface ReadSeekImageInfo {
112
- format: string;
113
- width: number;
114
- height: number;
115
- animated: boolean;
116
- }
117
-
118
111
  export interface ReadSeekOcrLine {
119
112
  text: string;
120
113
  bbox: [number, number, number, number];
@@ -125,17 +118,36 @@ export interface ReadSeekOcrText {
125
118
  lines: ReadSeekOcrLine[];
126
119
  }
127
120
 
128
- export interface ReadSeekDetection {
129
- file: string;
130
- language: string;
131
- engine: string | null;
132
- supported: boolean;
133
- binary: boolean;
134
- mime: string | null;
135
- syntax: string | null;
136
- image: ReadSeekImageInfo | null;
137
- ocr?: ReadSeekOcrText;
138
- }
121
+ export type ReadSeekDetection =
122
+ | {
123
+ type: "source";
124
+ file: string;
125
+ language: string;
126
+ engine?: string;
127
+ supported: boolean;
128
+ mime?: string;
129
+ syntax?: string;
130
+ }
131
+ | {
132
+ type: "image";
133
+ file: string;
134
+ mime?: string;
135
+ format: string;
136
+ width: number;
137
+ height: number;
138
+ animated: boolean;
139
+ ocr?: ReadSeekOcrText;
140
+ }
141
+ | {
142
+ type: "binary";
143
+ file: string;
144
+ mime?: string;
145
+ }
146
+ | {
147
+ type: "text";
148
+ file: string;
149
+ mime?: string;
150
+ };
139
151
 
140
152
  interface ReadSeekSearchOptions {
141
153
  language?: string;
@@ -554,11 +566,6 @@ function optionalString(value: unknown, field: string): string | undefined {
554
566
  return requireString(value, field);
555
567
  }
556
568
 
557
- function nullableString(value: unknown, field: string): string | null {
558
- if (value === undefined || value === null) return null;
559
- return requireString(value, field);
560
- }
561
-
562
569
  function parseRefsOutput(value: unknown): ReadSeekRefsOutput {
563
570
  if (!value || typeof value !== "object") throw new Error("invalid readseek refs output");
564
571
  const output = value as Record<string, unknown>;
@@ -634,18 +641,6 @@ export async function readseekCheck(
634
641
  );
635
642
  }
636
643
 
637
- function parseImageInfo(value: unknown): ReadSeekImageInfo | null {
638
- if (value === undefined || value === null) return null;
639
- if (typeof value !== "object") throw new Error("invalid readseek detect image");
640
- const image = value as Record<string, unknown>;
641
- return {
642
- format: requireString(image.format, "image.format"),
643
- width: requireNumber(image.width, "image.width"),
644
- height: requireNumber(image.height, "image.height"),
645
- animated: requireBoolean(image.animated, "image.animated"),
646
- };
647
- }
648
-
649
644
  function parseOcrText(value: unknown): ReadSeekOcrText | undefined {
650
645
  if (value === undefined || value === null) return undefined;
651
646
  if (typeof value !== "object") throw new Error("invalid readseek detect ocr");
@@ -669,17 +664,37 @@ function parseOcrText(value: unknown): ReadSeekOcrText | undefined {
669
664
  function parseDetectOutput(value: unknown): ReadSeekDetection {
670
665
  if (!value || typeof value !== "object") throw new Error("invalid readseek detect output");
671
666
  const output = value as Record<string, unknown>;
672
- return {
673
- file: requireString(output.file, "file"),
674
- language: requireString(output.language, "language"),
675
- engine: nullableString(output.engine, "engine"),
676
- supported: requireBoolean(output.supported, "supported"),
677
- binary: requireBoolean(output.binary, "binary"),
678
- mime: nullableString(output.mime, "mime"),
679
- syntax: nullableString(output.syntax, "syntax"),
680
- image: parseImageInfo(output.image),
681
- ocr: parseOcrText(output.ocr),
682
- };
667
+ const type = requireString(output.type, "type");
668
+ const file = requireString(output.file, "file");
669
+ const mime = optionalString(output.mime, "mime");
670
+ switch (type) {
671
+ case "source":
672
+ return {
673
+ type,
674
+ file,
675
+ language: requireString(output.language, "language"),
676
+ engine: optionalString(output.engine, "engine"),
677
+ supported: requireBoolean(output.supported, "supported"),
678
+ mime,
679
+ syntax: optionalString(output.syntax, "syntax"),
680
+ };
681
+ case "image":
682
+ return {
683
+ type,
684
+ file,
685
+ mime,
686
+ format: requireString(output.format, "format"),
687
+ width: requireNumber(output.width, "width"),
688
+ height: requireNumber(output.height, "height"),
689
+ animated: requireBoolean(output.animated, "animated"),
690
+ ocr: parseOcrText(output.ocr),
691
+ };
692
+ case "binary":
693
+ case "text":
694
+ return { type, file, mime };
695
+ default:
696
+ throw new Error(`invalid readseek detect type: ${type}`);
697
+ }
683
698
  }
684
699
 
685
700
  export async function readseekDetect(