@agimon-ai/doompi-read 0.0.1-alpha.15 → 0.0.1-alpha.17
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 +9 -9
- package/web/ReadToolMessage.tsx +3 -2
- package/web/readToolView.ts +1 -1
- package/web/HashlineLines.tsx +0 -47
- package/web/hashlineView.ts +0 -138
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/doompi-read",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.17",
|
|
4
4
|
"description": "Snapshot-bound hashline read tool for Pi and DoomPi.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -50,20 +50,20 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@deepseek-ai/cordis": "4.0.1",
|
|
53
|
-
"typebox": "1.3.
|
|
54
|
-
"@agimon-ai/doompi-
|
|
55
|
-
"@agimon-ai/doompi-
|
|
56
|
-
"@agimon-ai/doompi-
|
|
57
|
-
"@agimon-ai/doompi-web-
|
|
58
|
-
"@agimon-ai/doompi-
|
|
53
|
+
"typebox": "1.3.19",
|
|
54
|
+
"@agimon-ai/doompi-extension-contracts": "0.0.1-alpha.44",
|
|
55
|
+
"@agimon-ai/doompi-web-components": "0.0.1-alpha.5",
|
|
56
|
+
"@agimon-ai/doompi-hashline": "0.0.1-alpha.16",
|
|
57
|
+
"@agimon-ai/doompi-web-contracts": "0.0.1-alpha.8",
|
|
58
|
+
"@agimon-ai/doompi-ui": "0.0.1-alpha.45"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@earendil-works/pi-coding-agent": "0.84.4",
|
|
62
62
|
"@earendil-works/pi-tui": "0.84.4",
|
|
63
63
|
"@tanstack/react-store": "0.11.1",
|
|
64
64
|
"@tanstack/store": "0.11.1",
|
|
65
|
-
"@types/node": "26.
|
|
66
|
-
"@types/react": "19.2.
|
|
65
|
+
"@types/node": "26.4.0",
|
|
66
|
+
"@types/react": "19.2.18",
|
|
67
67
|
"@vitest/coverage-v8": "4.1.11",
|
|
68
68
|
"react": "19.2.8",
|
|
69
69
|
"tsdown": "0.22.14",
|
package/web/ReadToolMessage.tsx
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
+
HashlineLines,
|
|
3
|
+
hashlineBody,
|
|
2
4
|
MessageItem,
|
|
3
5
|
MessageItemBody,
|
|
4
6
|
MessageItemHeader,
|
|
5
7
|
MessageItemStatus,
|
|
8
|
+
resultTextLines,
|
|
6
9
|
toolTone,
|
|
7
10
|
} from '@agimon-ai/doompi-web-components';
|
|
8
11
|
import type { ToolMessageRenderProps } from '@agimon-ai/doompi-web-contracts';
|
|
9
12
|
import { readCallView } from './readToolView.ts';
|
|
10
|
-
import { HashlineLines } from './HashlineLines.tsx';
|
|
11
|
-
import { hashlineBody, resultTextLines } from './hashlineView.ts';
|
|
12
13
|
|
|
13
14
|
const IMAGE_MIME_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
|
|
14
15
|
|
package/web/readToolView.ts
CHANGED
package/web/HashlineLines.tsx
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { PresentedLine } from './hashlineView.ts';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The anchored body shared by hashline results: a file heading per group, a
|
|
5
|
-
* right-aligned line-number gutter, and a `>>` marker on grep matches. The
|
|
6
|
-
* gutter width is a style, not a class, because it follows the widest number.
|
|
7
|
-
*/
|
|
8
|
-
export function HashlineLines({ lines, gutter }: { lines: readonly PresentedLine[]; gutter: number }) {
|
|
9
|
-
return (
|
|
10
|
-
<div className="flex flex-col font-mono">
|
|
11
|
-
{lines.map((line, index) => {
|
|
12
|
-
if (line.type === 'file') {
|
|
13
|
-
return (
|
|
14
|
-
<span key={index} className="mt-1 truncate text-doom-faint first:mt-0">
|
|
15
|
-
{line.path}
|
|
16
|
-
</span>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
if (line.type === 'plain') {
|
|
20
|
-
return (
|
|
21
|
-
<span key={index} className="whitespace-pre-wrap break-words text-doom-dim">
|
|
22
|
-
{line.text}
|
|
23
|
-
</span>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
const { value } = line;
|
|
27
|
-
return (
|
|
28
|
-
<span key={index} className="flex gap-2">
|
|
29
|
-
{value.marker !== undefined ? (
|
|
30
|
-
<span className={`w-4 shrink-0 ${value.marker === 'match' ? 'text-doom-blue' : 'text-doom-faint'}`}>
|
|
31
|
-
{value.marker === 'match' ? '>>' : ''}
|
|
32
|
-
</span>
|
|
33
|
-
) : null}
|
|
34
|
-
<span className="shrink-0 text-right text-doom-faint" style={{ width: `${gutter}ch` }}>
|
|
35
|
-
{value.line}
|
|
36
|
-
</span>
|
|
37
|
-
<span
|
|
38
|
-
className={`min-w-0 whitespace-pre-wrap break-words ${value.marker === 'match' ? 'text-doom-hi' : 'text-doom-text'}`}
|
|
39
|
-
>
|
|
40
|
-
{value.content}
|
|
41
|
-
</span>
|
|
42
|
-
</span>
|
|
43
|
-
);
|
|
44
|
-
})}
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
}
|
package/web/hashlineView.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { ToolResultView } from '@agimon-ai/doompi-web-contracts';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The hashline wire format, parsed the way the TUI's hashlineRendering does:
|
|
5
|
-
* `@file path#tag` opens a file, `N#abc|content` is an anchored line, and a
|
|
6
|
-
* `>> ` or three-space prefix marks grep matches and their context. The
|
|
7
|
-
* patterns are copied from doompi-hashline because a cockpit plugin may only
|
|
8
|
-
* import its own pure modules and the web contract.
|
|
9
|
-
*/
|
|
10
|
-
const FILE_HEADER_PATTERN = /^@file (.+)#([A-Za-z0-9_-]{8})$/u;
|
|
11
|
-
const TAGGED_LINE_PATTERN = /^(>> | {3})?(\d+)#[a-z]{3}\|(.*)$/u;
|
|
12
|
-
const MATCH_PREFIX = '>> ';
|
|
13
|
-
const CONTEXT_PREFIX = ' ';
|
|
14
|
-
const IMAGE_PLACEHOLDER = '[Image attached]';
|
|
15
|
-
|
|
16
|
-
export const READ_COLLAPSED_LINES = 10;
|
|
17
|
-
export const GREP_COLLAPSED_LINES = 15;
|
|
18
|
-
|
|
19
|
-
export type HashlineResultKind = 'read' | 'grep';
|
|
20
|
-
export type TaggedLineMarker = 'match' | 'context';
|
|
21
|
-
|
|
22
|
-
export interface TaggedLine {
|
|
23
|
-
readonly line: number;
|
|
24
|
-
readonly content: string;
|
|
25
|
-
readonly marker: TaggedLineMarker | undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type PresentedLine =
|
|
29
|
-
| { readonly type: 'file'; readonly path: string }
|
|
30
|
-
| { readonly type: 'tagged'; readonly value: TaggedLine }
|
|
31
|
-
| { readonly type: 'plain'; readonly text: string };
|
|
32
|
-
|
|
33
|
-
export interface HashlineBody {
|
|
34
|
-
readonly shown: readonly PresentedLine[];
|
|
35
|
-
/** Lines the collapsed view holds back; zero once expanded. */
|
|
36
|
-
readonly hidden: number;
|
|
37
|
-
/** The bracketed pagination or compaction note the tool appends after its lines. */
|
|
38
|
-
readonly notice: string | undefined;
|
|
39
|
-
/** Widest line number among the shown anchored lines, in characters. */
|
|
40
|
-
readonly gutter: number;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface TextBlock {
|
|
44
|
-
readonly type: string;
|
|
45
|
-
readonly text?: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isTextBlock(block: unknown): block is TextBlock {
|
|
49
|
-
return typeof block === 'object' && block !== null && typeof (block as TextBlock).type === 'string';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The result's text as lines: tabs widened, CRLF folded, trailing blanks
|
|
54
|
-
* dropped. A result with no text but an image block reads as the TUI's
|
|
55
|
-
* placeholder. The joined `output` stands in when no result view exists.
|
|
56
|
-
*/
|
|
57
|
-
export function resultTextLines(result: ToolResultView | null, output: string): string[] {
|
|
58
|
-
const blocks = result?.content.filter(isTextBlock) ?? [];
|
|
59
|
-
const text =
|
|
60
|
-
result === null ? output : blocks.flatMap((block) => (block.type === 'text' ? [block.text ?? ''] : [])).join('\n');
|
|
61
|
-
if (text.length === 0) {
|
|
62
|
-
return blocks.some((block) => block.type === 'image') ? [IMAGE_PLACEHOLDER] : [];
|
|
63
|
-
}
|
|
64
|
-
const lines = text.replaceAll('\t', ' ').replaceAll('\r\n', '\n').split('\n');
|
|
65
|
-
while (lines.at(-1) === '') lines.pop();
|
|
66
|
-
return lines;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Detaches the tool's trailing `[...]` note so the body numbers file content only. */
|
|
70
|
-
export function takeTrailingNotice(lines: string[]): string | undefined {
|
|
71
|
-
const last = lines.at(-1);
|
|
72
|
-
if (last === undefined || !last.startsWith('[') || !last.endsWith(']')) return undefined;
|
|
73
|
-
lines.pop();
|
|
74
|
-
while (lines.at(-1) === '') lines.pop();
|
|
75
|
-
return last;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function parseTaggedLine(value: string): TaggedLine | undefined {
|
|
79
|
-
const match = TAGGED_LINE_PATTERN.exec(value);
|
|
80
|
-
const lineText = match?.[2];
|
|
81
|
-
const content = match?.[3];
|
|
82
|
-
if (lineText === undefined || content === undefined) return undefined;
|
|
83
|
-
const line = Number.parseInt(lineText, 10);
|
|
84
|
-
if (!Number.isSafeInteger(line) || line < 1) return undefined;
|
|
85
|
-
const prefix = match?.[1];
|
|
86
|
-
const marker = prefix === MATCH_PREFIX ? 'match' : prefix === CONTEXT_PREFIX ? 'context' : undefined;
|
|
87
|
-
return { line, content, marker };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function parseFileHeader(value: string): string | undefined {
|
|
91
|
-
return FILE_HEADER_PATTERN.exec(value)?.[1];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Lines as the card presents them. A read shows one file, so its header is
|
|
96
|
-
* dropped; a grep groups anchored matches under each file's path.
|
|
97
|
-
*/
|
|
98
|
-
export function presentHashlineLines(lines: readonly string[], kind: HashlineResultKind): PresentedLine[] {
|
|
99
|
-
const presented: PresentedLine[] = [];
|
|
100
|
-
for (const line of lines) {
|
|
101
|
-
const path = parseFileHeader(line);
|
|
102
|
-
if (path !== undefined) {
|
|
103
|
-
if (kind !== 'read') presented.push({ type: 'file', path });
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const tagged = parseTaggedLine(line);
|
|
107
|
-
if (tagged !== undefined) {
|
|
108
|
-
presented.push({ type: 'tagged', value: tagged });
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
presented.push({ type: 'plain', text: line });
|
|
112
|
-
}
|
|
113
|
-
return presented;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** The body a card shows for one result, collapsed to the kind's line budget unless expanded. */
|
|
117
|
-
export function hashlineBody(
|
|
118
|
-
result: ToolResultView | null,
|
|
119
|
-
output: string,
|
|
120
|
-
kind: HashlineResultKind,
|
|
121
|
-
expanded: boolean,
|
|
122
|
-
): HashlineBody {
|
|
123
|
-
const lines = resultTextLines(result, output);
|
|
124
|
-
const notice = takeTrailingNotice(lines);
|
|
125
|
-
const presented = presentHashlineLines(lines, kind);
|
|
126
|
-
const budget = kind === 'read' ? READ_COLLAPSED_LINES : GREP_COLLAPSED_LINES;
|
|
127
|
-
const shown = expanded ? presented : presented.slice(0, budget);
|
|
128
|
-
const gutter = shown.reduce(
|
|
129
|
-
(widest, line) => (line.type === 'tagged' ? Math.max(widest, String(line.value.line).length) : widest),
|
|
130
|
-
1,
|
|
131
|
-
);
|
|
132
|
-
return { shown, hidden: presented.length - shown.length, notice, gutter };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** The `key · key` detail list beside a call's primary argument, with absent values dropped. */
|
|
136
|
-
export function compactDetails(values: ReadonlyArray<string | undefined>): string[] {
|
|
137
|
-
return values.filter((value): value is string => value !== undefined && value.length > 0);
|
|
138
|
-
}
|