@agimon-ai/po-read 0.0.0-alpha.0

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.
@@ -0,0 +1,26 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_readTool = require("../readTool-DjM6DFYl.cjs");
6
+ let _agimon_ai_po_core_serverFacet = require("@agimon-ai/po-core/serverFacet");
7
+ //#region src/extensions/workspaces/sessions/(backend)/tool/read.server.ts
8
+ var read_server_default = (0, require("@agimon-ai/po-core/extensionFile").defineServerTool)(require_readTool.createHeadlessReadTool);
9
+ //#endregion
10
+ //#region generated/server.ts
11
+ const at = (value, context) => typeof value === "function" ? value(context) : value;
12
+ const via = (identity, value) => value === void 0 ? void 0 : {
13
+ ...identity,
14
+ ...value
15
+ };
16
+ const facet = (0, _agimon_ai_po_core_serverFacet.defineServerPlugin)({
17
+ name: "@agimon-ai/po-read",
18
+ session: (context) => ({ get tools() {
19
+ return [via({ name: "read" }, at(read_server_default, context))];
20
+ } })
21
+ });
22
+ //#endregion
23
+ exports.default = facet;
24
+ exports.facet = facet;
25
+
26
+ //# sourceMappingURL=server.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.cjs","names":["defineServerTool","createHeadlessReadTool","defineServerPlugin","toolRead"],"sources":["../../src/extensions/workspaces/sessions/(backend)/tool/read.server.ts","../../generated/server.ts"],"sourcesContent":["import { defineServerTool } from '@agimon-ai/po-core/extensionFile';\n\nimport { createHeadlessReadTool } from '../../../../../services/readTool';\n\nexport default defineServerTool(createHeadlessReadTool);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type DoomServerSessionPlugin } from '@agimon-ai/po-core/serverFacet';\n\nimport toolRead from '../src/extensions/workspaces/sessions/(backend)/tool/read.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const facet = defineServerPlugin({\n name: '@agimon-ai/po-read',\n session: (context) => ({\n get tools(): DoomServerSessionPlugin['tools'] { return [via({ name: 'read' }, at(toolRead, context))]; },\n }),\n});\n\nexport default facet;\n"],"mappings":";;;;;;;AAIA,IAAA,uBAAA,6CAAeA,CAAAA,CAAAA,iBAAAA,CAAiBC,iBAAAA,sBAAsB;;;ACEtD,MAAM,MAAY,OAA0B,YAC1C,OAAO,UAAU,aAAc,MAAwB,OAAO,IAAI;AACpE,MAAM,OAAU,UAAmC,UAChD,UAAU,KAAA,IAAY,KAAA,IAAY;CAAE,GAAG;CAAU,GAAI;AAAiB;AAEzE,MAAa,SAAA,GAAQC,+BAAAA,mBAAAA,CAAmB;CACtC,MAAM;CACN,UAAU,aAAa,EACrB,IAAI,QAA0C;EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,OAAO,GAAG,GAAGC,qBAAU,OAAO,CAAC,CAAC;CAAG,EACzG;AACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ //#region generated/server.d.ts
2
+ export declare const facet: import("@agimon-ai/po-core/serverFacet").DoomServerFacet;
3
+ //#endregion
4
+ export { facet as default };
5
+ //# sourceMappingURL=server.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.mts","names":[],"sources":["../../generated/server.ts"],"mappings":";qBAWa,gDAAK"}
@@ -0,0 +1,22 @@
1
+ import { t as createHeadlessReadTool } from "../readTool-epk_n4AS.mjs";
2
+ import { defineServerPlugin } from "@agimon-ai/po-core/serverFacet";
3
+ import { defineServerTool } from "@agimon-ai/po-core/extensionFile";
4
+ //#region src/extensions/workspaces/sessions/(backend)/tool/read.server.ts
5
+ var read_server_default = defineServerTool(createHeadlessReadTool);
6
+ //#endregion
7
+ //#region generated/server.ts
8
+ const at = (value, context) => typeof value === "function" ? value(context) : value;
9
+ const via = (identity, value) => value === void 0 ? void 0 : {
10
+ ...identity,
11
+ ...value
12
+ };
13
+ const facet = defineServerPlugin({
14
+ name: "@agimon-ai/po-read",
15
+ session: (context) => ({ get tools() {
16
+ return [via({ name: "read" }, at(read_server_default, context))];
17
+ } })
18
+ });
19
+ //#endregion
20
+ export { facet as default, facet };
21
+
22
+ //# sourceMappingURL=server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.mjs","names":["toolRead"],"sources":["../../src/extensions/workspaces/sessions/(backend)/tool/read.server.ts","../../generated/server.ts"],"sourcesContent":["import { defineServerTool } from '@agimon-ai/po-core/extensionFile';\n\nimport { createHeadlessReadTool } from '../../../../../services/readTool';\n\nexport default defineServerTool(createHeadlessReadTool);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type DoomServerSessionPlugin } from '@agimon-ai/po-core/serverFacet';\n\nimport toolRead from '../src/extensions/workspaces/sessions/(backend)/tool/read.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const facet = defineServerPlugin({\n name: '@agimon-ai/po-read',\n session: (context) => ({\n get tools(): DoomServerSessionPlugin['tools'] { return [via({ name: 'read' }, at(toolRead, context))]; },\n }),\n});\n\nexport default facet;\n"],"mappings":";;;;AAIA,IAAA,sBAAe,iBAAiB,sBAAsB;;;ACEtD,MAAM,MAAY,OAA0B,YAC1C,OAAO,UAAU,aAAc,MAAwB,OAAO,IAAI;AACpE,MAAM,OAAU,UAAmC,UAChD,UAAU,KAAA,IAAY,KAAA,IAAY;CAAE,GAAG;CAAU,GAAI;AAAiB;AAEzE,MAAa,QAAQ,mBAAmB;CACtC,MAAM;CACN,UAAU,aAAa,EACrB,IAAI,QAA0C;EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,OAAO,GAAG,GAAGA,qBAAU,OAAO,CAAC,CAAC;CAAG,EACzG;AACF,CAAC"}
@@ -0,0 +1,134 @@
1
+ import { defineToolRenderer, defineWebPlugin } from "@agimon-ai/po-core/web";
2
+ import { HashlineLines, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, ToolPathLink, compactDetails, hashlineBody, resultTextLines, toolTone } from "@agimon-ai/po-web-components";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/readToolView.ts
5
+ function optionalNumber(value) {
6
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
7
+ }
8
+ /** What the read call heading shows: the path, then the offset and limit when given. */
9
+ function readCallView(args) {
10
+ const offset = optionalNumber(args.offset);
11
+ const limit = optionalNumber(args.limit);
12
+ return {
13
+ path: typeof args.path === "string" ? args.path : "",
14
+ details: compactDetails([offset === void 0 ? void 0 : `from ${offset}`, limit === void 0 ? void 0 : `${limit} lines`])
15
+ };
16
+ }
17
+ //#endregion
18
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/ReadToolMessage.tsx
19
+ const IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
20
+ "image/png",
21
+ "image/jpeg",
22
+ "image/gif",
23
+ "image/webp"
24
+ ]);
25
+ function resultImages(content) {
26
+ return content.flatMap((block) => {
27
+ if (typeof block !== "object" || block === null || Array.isArray(block)) return [];
28
+ const value = block;
29
+ return value.type === "image" && typeof value.data === "string" && typeof value.mimeType === "string" && IMAGE_MIME_TYPES.has(value.mimeType) ? [{
30
+ data: value.data,
31
+ mimeType: value.mimeType
32
+ }] : [];
33
+ });
34
+ }
35
+ /**
36
+ * The read tool's timeline item, the web half of its renderCall and
37
+ * renderResult: the call summary in the header and, when expanded, the
38
+ * anchored lines with a line-number gutter in the body. A failure shows the
39
+ * tool's message in red inside the expanded body instead.
40
+ */
41
+ function ReadToolMessage({ args, result, output, running, isError, fileTabFor, openTransientTab }) {
42
+ const view = readCallView(args);
43
+ const images = resultImages(result?.content ?? []);
44
+ const tab = fileTabFor(view.path);
45
+ const body = result === null || isError ? null : hashlineBody(result, output, "read", true);
46
+ return /* @__PURE__ */ jsx(MessageItem, {
47
+ tone: toolTone({
48
+ running,
49
+ isError
50
+ }),
51
+ expandable: true,
52
+ defaultExpanded: false,
53
+ children: ({ expanded }) => {
54
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
55
+ title: "read",
56
+ children: /* @__PURE__ */ jsxs("span", {
57
+ "data-testid": "tool-call-read",
58
+ className: "flex min-w-0 flex-1 items-center gap-2",
59
+ children: [/* @__PURE__ */ jsx(ToolPathLink, {
60
+ path: view.path,
61
+ ...tab === void 0 ? {} : { onOpen: () => openTransientTab(tab) }
62
+ }), view.details.length > 0 ? /* @__PURE__ */ jsxs("span", {
63
+ className: "shrink-0 text-doom-faint",
64
+ children: ["· ", view.details.join(" · ")]
65
+ }) : null]
66
+ })
67
+ }), expanded ? isError ? /* @__PURE__ */ jsxs(MessageItemBody, {
68
+ "data-testid": "tool-result-read",
69
+ className: "flex flex-col",
70
+ children: [/* @__PURE__ */ jsx(MessageItemStatus, {
71
+ tone: "error",
72
+ children: "failed"
73
+ }), resultTextLines(result, output).map((line, index) => /* @__PURE__ */ jsx("span", {
74
+ className: "whitespace-pre-wrap break-words text-doom-red",
75
+ children: line
76
+ }, `${String(index)}-${line}`))]
77
+ }) : body === null ? running ? /* @__PURE__ */ jsx(MessageItemBody, {
78
+ "data-testid": "tool-result-read",
79
+ children: /* @__PURE__ */ jsx(MessageItemStatus, {
80
+ tone: "running",
81
+ children: "running"
82
+ })
83
+ }) : null : body.shown.length === 0 && body.notice === void 0 && images.length === 0 ? null : /* @__PURE__ */ jsxs(MessageItemBody, {
84
+ "data-testid": "tool-result-read",
85
+ className: "flex flex-col gap-1",
86
+ children: [
87
+ /* @__PURE__ */ jsx(HashlineLines, {
88
+ lines: body.shown,
89
+ gutter: body.gutter,
90
+ path: view.path
91
+ }),
92
+ images.map((image, index) => {
93
+ const url = `data:${image.mimeType};base64,${image.data}`;
94
+ return /* @__PURE__ */ jsx("a", {
95
+ href: url,
96
+ target: "_blank",
97
+ rel: "noreferrer",
98
+ className: "self-start",
99
+ children: /* @__PURE__ */ jsx("img", {
100
+ src: url,
101
+ alt: `Read result ${String(index + 1)}`,
102
+ "data-testid": "tool-result-read-image",
103
+ className: "h-auto max-h-96 max-w-full rounded-md border border-doom-border-soft object-contain"
104
+ })
105
+ }, `${image.mimeType}:${String(index)}`);
106
+ }),
107
+ body.notice !== void 0 ? /* @__PURE__ */ jsx("span", {
108
+ className: "text-doom-faint",
109
+ children: body.notice
110
+ }) : null
111
+ ]
112
+ }) : null] });
113
+ }
114
+ });
115
+ }
116
+ //#endregion
117
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/read.web.tsx
118
+ var read_web_default = defineToolRenderer({ message: ReadToolMessage });
119
+ //#endregion
120
+ //#region generated/web.ts
121
+ const via = (identity, value) => value === void 0 ? void 0 : {
122
+ ...identity,
123
+ ...value
124
+ };
125
+ const webPlugin = defineWebPlugin({
126
+ id: "read",
127
+ session: { get toolRenderers() {
128
+ return [via({ tools: ["read"] }, read_web_default)];
129
+ } }
130
+ });
131
+ //#endregion
132
+ export { webPlugin };
133
+
134
+ //# sourceMappingURL=web.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.mjs","names":["toolRead"],"sources":["../../src/extensions/workspaces/sessions/(frontend)/tool/_lib/readToolView.ts","../../src/extensions/workspaces/sessions/(frontend)/tool/_components/ReadToolMessage.tsx","../../src/extensions/workspaces/sessions/(frontend)/tool/read.web.tsx","../../generated/web.ts"],"sourcesContent":["import { compactDetails } from '@agimon-ai/po-web-components';\n\nexport interface ReadCallView {\n readonly path: string;\n /** `from N` and `N lines`, as the TUI's call heading lists them. */\n readonly details: readonly string[];\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\n/** What the read call heading shows: the path, then the offset and limit when given. */\nexport function readCallView(args: Readonly<Record<string, unknown>>): ReadCallView {\n const offset = optionalNumber(args.offset);\n const limit = optionalNumber(args.limit);\n return {\n path: typeof args.path === 'string' ? args.path : '',\n details: compactDetails([\n offset === undefined ? undefined : `from ${offset}`,\n limit === undefined ? undefined : `${limit} lines`,\n ]),\n };\n}\n","import type { ToolMessageRenderProps } from '@agimon-ai/po-core/web';\nimport {\n HashlineLines,\n hashlineBody,\n MessageItem,\n MessageItemBody,\n MessageItemHeader,\n MessageItemStatus,\n resultTextLines,\n ToolPathLink,\n toolTone,\n} from '@agimon-ai/po-web-components';\n\nimport { readCallView } from '../_lib/readToolView';\n\nconst IMAGE_MIME_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);\n\nfunction resultImages(content: readonly unknown[]): Array<{ data: string; mimeType: string }> {\n return content.flatMap((block) => {\n if (typeof block !== 'object' || block === null || Array.isArray(block)) return [];\n const value = block as Record<string, unknown>;\n return value.type === 'image' &&\n typeof value.data === 'string' &&\n typeof value.mimeType === 'string' &&\n IMAGE_MIME_TYPES.has(value.mimeType)\n ? [{ data: value.data, mimeType: value.mimeType }]\n : [];\n });\n}\n/**\n * The read tool's timeline item, the web half of its renderCall and\n * renderResult: the call summary in the header and, when expanded, the\n * anchored lines with a line-number gutter in the body. A failure shows the\n * tool's message in red inside the expanded body instead.\n */\nexport function ReadToolMessage({\n args,\n result,\n output,\n running,\n isError,\n fileTabFor,\n openTransientTab,\n}: ToolMessageRenderProps) {\n const view = readCallView(args);\n const images = resultImages(result?.content ?? []);\n // A read is the one call whose file the session usually has not changed, so\n // this is the link that opens it read-only rather than in its history.\n const tab = fileTabFor(view.path);\n const body = result === null || isError ? null : hashlineBody(result, output, 'read', true);\n return (\n <MessageItem tone={toolTone({ running, isError })} expandable defaultExpanded={false}>\n {({ expanded }) => {\n return (\n <>\n <MessageItemHeader title=\"read\">\n <span data-testid=\"tool-call-read\" className=\"flex min-w-0 flex-1 items-center gap-2\">\n <ToolPathLink\n path={view.path}\n {...(tab === undefined ? {} : { onOpen: () => openTransientTab(tab) })}\n />\n {view.details.length > 0 ? (\n <span className=\"shrink-0 text-doom-faint\">· {view.details.join(' · ')}</span>\n ) : null}\n </span>\n </MessageItemHeader>\n {expanded ? (\n isError ? (\n <MessageItemBody data-testid=\"tool-result-read\" className=\"flex flex-col\">\n <MessageItemStatus tone=\"error\">failed</MessageItemStatus>\n {resultTextLines(result, output).map((line, index) => (\n <span key={`${String(index)}-${line}`} className=\"whitespace-pre-wrap break-words text-doom-red\">\n {line}\n </span>\n ))}\n </MessageItemBody>\n ) : body === null ? (\n running ? (\n <MessageItemBody data-testid=\"tool-result-read\">\n <MessageItemStatus tone=\"running\">running</MessageItemStatus>\n </MessageItemBody>\n ) : null\n ) : body.shown.length === 0 && body.notice === undefined && images.length === 0 ? null : (\n <MessageItemBody data-testid=\"tool-result-read\" className=\"flex flex-col gap-1\">\n {/* A read body is one file with no heading of its own, so the\n call's path is what names the grammar for it. */}\n <HashlineLines lines={body.shown} gutter={body.gutter} path={view.path} />\n {images.map((image, index) => {\n const url = `data:${image.mimeType};base64,${image.data}`;\n return (\n <a\n key={`${image.mimeType}:${String(index)}`}\n href={url}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"self-start\"\n >\n <img\n src={url}\n alt={`Read result ${String(index + 1)}`}\n data-testid=\"tool-result-read-image\"\n className=\"h-auto max-h-96 max-w-full rounded-md border border-doom-border-soft object-contain\"\n />\n </a>\n );\n })}\n {body.notice !== undefined ? <span className=\"text-doom-faint\">{body.notice}</span> : null}\n </MessageItemBody>\n )\n ) : null}\n </>\n );\n }}\n </MessageItem>\n );\n}\n","import { defineToolRenderer } from '@agimon-ai/po-core/web';\n\nimport { ReadToolMessage } from './_components/ReadToolMessage';\n\nexport default defineToolRenderer({ message: ReadToolMessage });\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineWebPlugin, type WebPluginContributions } from '@agimon-ai/po-core/web';\n\nimport toolRead from '../src/extensions/workspaces/sessions/(frontend)/tool/read.web';\n\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const webPlugin = defineWebPlugin({\n id: 'read',\n session: {\n get toolRenderers(): WebPluginContributions['toolRenderers'] { return [via({ tools: ['read'] }, toolRead)]; },\n },\n});\n"],"mappings":";;;;AAQA,SAAS,eAAe,OAAoC;CAC1D,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ,KAAA;AACvE;;AAGA,SAAgB,aAAa,MAAuD;CAClF,MAAM,SAAS,eAAe,KAAK,MAAM;CACzC,MAAM,QAAQ,eAAe,KAAK,KAAK;CACvC,OAAO;EACL,MAAM,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;EAClD,SAAS,eAAe,CACtB,WAAW,KAAA,IAAY,KAAA,IAAY,QAAQ,UAC3C,UAAU,KAAA,IAAY,KAAA,IAAY,GAAG,MAAM,OAC7C,CAAC;CACH;AACF;;;ACRA,MAAM,mCAAmB,IAAI,IAAI;CAAC;CAAa;CAAc;CAAa;AAAY,CAAC;AAEvF,SAAS,aAAa,SAAwE;CAC5F,OAAO,QAAQ,SAAS,UAAU;EAChC,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;EACjF,MAAM,QAAQ;EACd,OAAO,MAAM,SAAS,WACpB,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,aAAa,YAC1B,iBAAiB,IAAI,MAAM,QAAQ,IACjC,CAAC;GAAE,MAAM,MAAM;GAAM,UAAU,MAAM;EAAS,CAAC,IAC/C,CAAC;CACP,CAAC;AACH;;;;;;;AAOA,SAAgB,gBAAgB,EAC9B,MACA,QACA,QACA,SACA,SACA,YACA,oBACyB;CACzB,MA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IAAiB,eAAY;IAAmB,WAAU;IAA1D,UAAA;KAGE,oBAAC,eAAD;MAAe,OAAO,KAAK;MAAO,QAAQ,KAAK;MAAQ,MAAM,KAAK;KAAO,CAAA;KACxE,OAAO,KAAK,OAAO,UAAU;MAC5B,MAAM,MAAM,QAAQ,MAAM,SAAS,UAAU,MAAM;MACnD,OACE,oBAAC,KAAD;OAEE,MAAM;OACN,QAAO;OACP,KAAI;OACJ,WAAU;OAEV,UAAA,oBAAC,OAAD;QACE,KAAK;QACL,KAAK,eAAe,OAAO,QAAQ,CAAC;QACpC,eAAY;QACZ,WAAU;OACX,CAAA;MACA,GAZI,GAAG,MAAM,SAAS,GAAG,OAAO,KAAK,GAYrC;KAEP,CAAC;KACA,KAAK,WAAW,KAAA,IAAY,oBAAC,QAAD;MAAM,WAAU;MAAmB,UAAA,KAAK;KAAa,CAAA,IAAI;IACvE;GAEjB,CAAA,IAAA,IACJ,EAAA,CAAA;EAEN;CACW,CAAA;AAEjB;;;AC/GA,IAAA,mBAAe,mBAAmB,EAAE,SAAS,gBAAgB,CAAC;;;ACC9D,MAAM,OAAU,UAAmC,UAChD,UAAU,KAAA,IAAY,KAAA,IAAY;CAAE,GAAG;CAAU,GAAI;AAAiB;AAEzE,MAAa,YAAY,gBAAgB;CACvC,IAAI;CACJ,SAAS,EACP,IAAI,gBAAyD;EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,GAAGA,gBAAQ,CAAC;CAAG,EAC9G;AACF,CAAC"}
package/dist/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_readTool = require("./readTool-DjM6DFYl.cjs");
3
+ exports.ReadParamsSchema = require_readTool.ReadParamsSchema;
4
+ exports.createHeadlessReadTool = require_readTool.createHeadlessReadTool;
5
+ exports.executeHeadlessRead = require_readTool.executeHeadlessRead;
@@ -0,0 +1,34 @@
1
+ import { ReadToolDetails } from "@earendil-works/pi-coding-agent";
2
+ import { Static, Type } from "typebox";
3
+ import "@agimon-ai/po-config/piConfig";
4
+ import { DoomHeadlessTool } from "@agimon-ai/po-core/headless";
5
+ //#region src/schemas/readTool.d.ts
6
+ export declare const ReadParamsSchema: Type.TObject<{
7
+ path: Type.TString;
8
+ offset: Type.TOptional<Type.TInteger>;
9
+ limit: Type.TOptional<Type.TInteger>;
10
+ }>;
11
+ type ReadParams = Static<typeof ReadParamsSchema>;
12
+ //#endregion
13
+ //#region src/services/readImage/index.d.ts
14
+ interface ReadTextPart {
15
+ type: 'text';
16
+ text: string;
17
+ }
18
+ interface ReadImagePart {
19
+ type: 'image';
20
+ data: string;
21
+ mimeType: string;
22
+ }
23
+ type ReadContentPart = ReadTextPart | ReadImagePart;
24
+ //#endregion
25
+ //#region src/services/readTool/index.d.ts
26
+ interface ReadToolResult {
27
+ content: ReadContentPart[];
28
+ details?: ReadToolDetails;
29
+ }
30
+ export declare function executeHeadlessRead(params: ReadParams, cwd: string, signal: AbortSignal | undefined): Promise<ReadToolResult>;
31
+ export declare function createHeadlessReadTool(): DoomHeadlessTool<typeof ReadParamsSchema>;
32
+ //#endregion
33
+ export type { ReadParams };
34
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/schemas/readTool.ts","../src/services/readImage/index.ts","../src/services/readTool/index.ts"],"mappings":";;;;;qBAEa,kBAAgB,KAAA;;;;;KAMjB,aAAa,cAAc;;;UCJtB;EACf;EACA;;UAGe;EACf;EACA;EACA;;KAGU,kBAAkB,eAAe;;;UCwB5B;EACf,SAAS;EACT,UAAU;;wBA0BU,oBACpB,QAAQ,YACR,aACA,QAAQ,0BACP,QAAQ;wBAkEK,0BAA0B,wBAAwB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { n as executeHeadlessRead, r as ReadParamsSchema, t as createHeadlessReadTool } from "./readTool-epk_n4AS.mjs";
2
+ export { ReadParamsSchema, createHeadlessReadTool, executeHeadlessRead };
@@ -0,0 +1,169 @@
1
+ let node_fs_promises = require("node:fs/promises");
2
+ let _agimon_ai_po_hashline = require("@agimon-ai/po-hashline");
3
+ let _agimon_ai_po_hashline_files = require("@agimon-ai/po-hashline/files");
4
+ let _earendil_works_pi_coding_agent = require("@earendil-works/pi-coding-agent");
5
+ let typebox = require("typebox");
6
+ let _agimon_ai_po_config_piConfig = require("@agimon-ai/po-config/piConfig");
7
+ //#region src/schemas/readTool.ts
8
+ const ReadParamsSchema = typebox.Type.Object({
9
+ path: typebox.Type.String({ description: "Path to the file to read." }),
10
+ offset: typebox.Type.Optional(typebox.Type.Integer({
11
+ minimum: 1,
12
+ description: "One-based line offset."
13
+ })),
14
+ limit: typebox.Type.Optional(typebox.Type.Integer({
15
+ minimum: 1,
16
+ description: "Maximum number of lines to return."
17
+ }))
18
+ });
19
+ //#endregion
20
+ //#region src/services/readImage/index.ts
21
+ const OMITTED_NOTE = "[Image omitted: could not be resized below the inline image size limit.]";
22
+ function imageLimits() {
23
+ return (0, _agimon_ai_po_config_piConfig.loadPiImageSettings)();
24
+ }
25
+ async function applyImageLimits(content, limits, operations) {
26
+ if (!limits.autoResize || !content.some((part) => part.type === "image")) return content;
27
+ const resolved = [];
28
+ for (const part of content) {
29
+ if (part.type !== "image") {
30
+ resolved.push(part);
31
+ continue;
32
+ }
33
+ const resized = await operations.resize(Buffer.from(part.data, "base64"), part.mimeType, {
34
+ maxWidth: limits.maxDimension,
35
+ maxHeight: limits.maxDimension
36
+ });
37
+ if (!resized) {
38
+ resolved.push({
39
+ type: "text",
40
+ text: OMITTED_NOTE
41
+ });
42
+ continue;
43
+ }
44
+ resolved.push({
45
+ type: "image",
46
+ data: resized.data,
47
+ mimeType: resized.mimeType
48
+ });
49
+ const note = operations.formatDimensionNote(resized);
50
+ if (note) resolved.push({
51
+ type: "text",
52
+ text: note
53
+ });
54
+ }
55
+ return resolved;
56
+ }
57
+ //#endregion
58
+ //#region src/services/readTool/index.ts
59
+ const resizeOperations = {
60
+ resize: _earendil_works_pi_coding_agent.resizeImage,
61
+ formatDimensionNote: (result) => (0, _earendil_works_pi_coding_agent.formatDimensionNote)(result)
62
+ };
63
+ function assertNotAborted(signal) {
64
+ if (signal?.aborted) throw new Error("Operation aborted");
65
+ }
66
+ function isImagePath(filePath) {
67
+ const extension = filePath.toLowerCase().match(/\.([a-z0-9]+)$/u)?.[1];
68
+ if (!extension) return void 0;
69
+ return {
70
+ avif: "image/avif",
71
+ gif: "image/gif",
72
+ jpeg: "image/jpeg",
73
+ jpg: "image/jpeg",
74
+ png: "image/png",
75
+ webp: "image/webp"
76
+ }[extension];
77
+ }
78
+ async function executeHeadlessRead(params, cwd, signal) {
79
+ assertNotAborted(signal);
80
+ const absolutePath = await (0, _agimon_ai_po_hashline_files.resolveReadInputPath)(params.path, cwd);
81
+ const bytes = await (0, node_fs_promises.readFile)(absolutePath);
82
+ assertNotAborted(signal);
83
+ const mimeType = isImagePath(absolutePath);
84
+ if (mimeType) return { content: await applyImageLimits([{
85
+ type: "text",
86
+ text: `Read image file ${(0, _agimon_ai_po_hashline_files.displayPath)(absolutePath, cwd)} [${mimeType}]`
87
+ }, {
88
+ type: "image",
89
+ data: bytes.toString("base64"),
90
+ mimeType
91
+ }], imageLimits(), resizeOperations) };
92
+ if (!await (0, _agimon_ai_po_hashline_files.isWritableFile)(absolutePath)) return { content: [{
93
+ type: "text",
94
+ text: (0, _agimon_ai_po_hashline_files.decodeUtf8)(bytes, (0, _agimon_ai_po_hashline_files.displayPath)(absolutePath, cwd))
95
+ }] };
96
+ return createTaggedReadResult(bytes, (0, _agimon_ai_po_hashline_files.displayPath)(absolutePath, cwd), params);
97
+ }
98
+ function createTaggedReadResult(bytes, path, params) {
99
+ const lines = (0, _agimon_ai_po_hashline.splitLines)((0, _agimon_ai_po_hashline_files.decodeUtf8)(bytes, path));
100
+ const startIndex = params.offset === void 0 ? 0 : params.offset - 1;
101
+ if (startIndex >= lines.length) throw new Error(`Offset ${params.offset} is beyond end of file (${lines.length} lines total).`);
102
+ const endIndex = params.limit === void 0 ? lines.length : Math.min(lines.length, startIndex + params.limit);
103
+ const selected = lines.slice(startIndex, endIndex);
104
+ const header = (0, _agimon_ai_po_hashline.formatFileHeader)(path, (0, _agimon_ai_po_hashline_files.computeFileTag)(bytes));
105
+ const compactedLines = [];
106
+ const headerBytes = Buffer.byteLength(header, "utf8") + 1;
107
+ const tagged = selected.map((line, index) => {
108
+ const lineNumber = startIndex + index + 1;
109
+ const full = (0, _agimon_ai_po_hashline.formatTaggedLine)(line, lineNumber);
110
+ if (Buffer.byteLength(full, "utf8") <= _earendil_works_pi_coding_agent.DEFAULT_MAX_BYTES - headerBytes) return full;
111
+ compactedLines.push(lineNumber);
112
+ return (0, _agimon_ai_po_hashline.formatTaggedLine)((0, _earendil_works_pi_coding_agent.truncateLine)(line).text, lineNumber, "", line);
113
+ });
114
+ const truncation = (0, _earendil_works_pi_coding_agent.truncateHead)([header, ...tagged].join("\n"));
115
+ let text = truncation.content;
116
+ let details;
117
+ if (truncation.truncated) {
118
+ const shownLines = Math.max(0, truncation.outputLines - 1);
119
+ const nextOffset = startIndex + shownLines + 1;
120
+ const reason = truncation.truncatedBy === "bytes" ? `, ${(0, _earendil_works_pi_coding_agent.formatSize)(_earendil_works_pi_coding_agent.DEFAULT_MAX_BYTES)} limit` : "";
121
+ text += `\n\n[Showing ${shownLines} anchored lines${reason}. Use offset=${nextOffset} to continue.]`;
122
+ details = { truncation };
123
+ } else {
124
+ const notices = [];
125
+ if (compactedLines.length > 0) notices.push(`Lines ${compactedLines.join(", ")} shown compactly. Their anchors hash the full original lines`);
126
+ if (endIndex < lines.length) notices.push(`${lines.length - endIndex} more lines in file. Use offset=${endIndex + 1} to continue`);
127
+ if (notices.length > 0) text += `\n\n[${notices.join(". ")}.]`;
128
+ }
129
+ return {
130
+ content: [{
131
+ type: "text",
132
+ text
133
+ }],
134
+ details
135
+ };
136
+ }
137
+ function createHeadlessReadTool() {
138
+ return {
139
+ name: "read",
140
+ label: "read",
141
+ description: "Read a writable text file with an exact-byte file tag and stable line anchors. Non-writable files and images return native-compatible content. Text is truncated to 50.0KB.",
142
+ promptSnippet: "Read file contents with snapshot-bound line anchors",
143
+ promptGuidelines: ["Use read before edit. When hashline metadata is present, preserve the @file hash and anchors such as 5#abc exactly.", "Continue large reads with offset until the required anchored lines are visible."],
144
+ parameters: ReadParamsSchema,
145
+ executionMode: "parallel",
146
+ execute: async (_toolCallId, params, signal, _onUpdate, context) => executeHeadlessRead(params, context.cwd, signal)
147
+ };
148
+ }
149
+ //#endregion
150
+ Object.defineProperty(exports, "ReadParamsSchema", {
151
+ enumerable: true,
152
+ get: function() {
153
+ return ReadParamsSchema;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "createHeadlessReadTool", {
157
+ enumerable: true,
158
+ get: function() {
159
+ return createHeadlessReadTool;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, "executeHeadlessRead", {
163
+ enumerable: true,
164
+ get: function() {
165
+ return executeHeadlessRead;
166
+ }
167
+ });
168
+
169
+ //# sourceMappingURL=readTool-DjM6DFYl.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readTool-DjM6DFYl.cjs","names":["Type","loadPiImageSettings","resizeImage","formatDimensionNote","resolveReadInputPath","readFile","displayPath","isWritableFile","decodeUtf8","splitLines","formatFileHeader","computeFileTag","formatTaggedLine","DEFAULT_MAX_BYTES","truncateLine","truncateHead","formatSize"],"sources":["../src/schemas/readTool.ts","../src/services/readImage/index.ts","../src/services/readTool/index.ts"],"sourcesContent":["import { type Static, Type } from 'typebox';\n\nexport const ReadParamsSchema = Type.Object({\n path: Type.String({ description: 'Path to the file to read.' }),\n offset: Type.Optional(Type.Integer({ minimum: 1, description: 'One-based line offset.' })),\n limit: Type.Optional(Type.Integer({ minimum: 1, description: 'Maximum number of lines to return.' })),\n});\n\nexport type ReadParams = Static<typeof ReadParamsSchema>;\n","import { loadPiImageSettings, type PiImageSettings } from '@agimon-ai/po-config/piConfig';\n\nconst OMITTED_NOTE = '[Image omitted: could not be resized below the inline image size limit.]';\n\nexport interface ReadTextPart {\n type: 'text';\n text: string;\n}\n\nexport interface ReadImagePart {\n type: 'image';\n data: string;\n mimeType: string;\n}\n\nexport type ReadContentPart = ReadTextPart | ReadImagePart;\n\nexport interface ReadImageResizeResult {\n readonly data: string;\n readonly mimeType: string;\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly width: number;\n readonly height: number;\n readonly wasResized: boolean;\n}\n\nexport interface ReadImageResizeOperations {\n resize(\n inputBytes: Uint8Array,\n mimeType: string,\n options: { readonly maxWidth: number; readonly maxHeight: number },\n ): Promise<ReadImageResizeResult | null>;\n formatDimensionNote(result: ReadImageResizeResult): string | undefined;\n}\n\nexport function imageLimits(): PiImageSettings {\n return loadPiImageSettings();\n}\n\nexport async function applyImageLimits(\n content: ReadContentPart[],\n limits: PiImageSettings,\n operations: ReadImageResizeOperations,\n): Promise<ReadContentPart[]> {\n if (!limits.autoResize || !content.some((part) => part.type === 'image')) return content;\n const resolved: ReadContentPart[] = [];\n for (const part of content) {\n if (part.type !== 'image') {\n resolved.push(part);\n continue;\n }\n const resized = await operations.resize(Buffer.from(part.data, 'base64'), part.mimeType, {\n maxWidth: limits.maxDimension,\n maxHeight: limits.maxDimension,\n });\n if (!resized) {\n resolved.push({ type: 'text', text: OMITTED_NOTE });\n continue;\n }\n resolved.push({ type: 'image', data: resized.data, mimeType: resized.mimeType });\n const note = operations.formatDimensionNote(resized);\n if (note) resolved.push({ type: 'text', text: note });\n }\n return resolved;\n}\n","import { readFile } from 'node:fs/promises';\n\nimport type {\n DoomHeadlessExecutionContext,\n DoomHeadlessTool,\n DoomHeadlessToolResult,\n} from '@agimon-ai/po-core/headless';\nimport { formatFileHeader, formatTaggedLine, splitLines } from '@agimon-ai/po-hashline';\nimport {\n computeFileTag,\n decodeUtf8,\n displayPath,\n isWritableFile,\n resolveReadInputPath,\n} from '@agimon-ai/po-hashline/files';\nimport {\n DEFAULT_MAX_BYTES,\n formatDimensionNote,\n formatSize,\n resizeImage,\n truncateHead,\n truncateLine,\n type ReadToolDetails,\n} from '@earendil-works/pi-coding-agent';\n\nimport { ReadParamsSchema, type ReadParams } from '../../schemas/readTool';\nimport {\n applyImageLimits,\n imageLimits,\n type ReadContentPart,\n type ReadImageResizeOperations,\n type ReadTextPart,\n} from '../readImage';\n\nconst resizeOperations: ReadImageResizeOperations = {\n resize: resizeImage,\n formatDimensionNote: (result) => formatDimensionNote(result),\n};\n\nexport interface ReadToolResult {\n content: ReadContentPart[];\n details?: ReadToolDetails;\n}\n\ninterface ReadTextToolResult {\n content: ReadTextPart[];\n details?: ReadToolDetails;\n}\n\nexport function assertNotAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted) throw new Error('Operation aborted');\n}\n\nexport function isImagePath(filePath: string): string | undefined {\n const extension = filePath.toLowerCase().match(/\\.([a-z0-9]+)$/u)?.[1];\n if (!extension) return undefined;\n const mimeTypes: Record<string, string> = {\n avif: 'image/avif',\n gif: 'image/gif',\n jpeg: 'image/jpeg',\n jpg: 'image/jpeg',\n png: 'image/png',\n webp: 'image/webp',\n };\n return mimeTypes[extension];\n}\n\nexport async function executeHeadlessRead(\n params: ReadParams,\n cwd: string,\n signal: AbortSignal | undefined,\n): Promise<ReadToolResult> {\n assertNotAborted(signal);\n const absolutePath = await resolveReadInputPath(params.path, cwd);\n const bytes = await readFile(absolutePath);\n assertNotAborted(signal);\n const mimeType = isImagePath(absolutePath);\n if (mimeType) {\n const content: ReadContentPart[] = [\n { type: 'text', text: `Read image file ${displayPath(absolutePath, cwd)} [${mimeType}]` },\n { type: 'image', data: bytes.toString('base64'), mimeType },\n ];\n return { content: await applyImageLimits(content, imageLimits(), resizeOperations) };\n }\n if (!(await isWritableFile(absolutePath))) {\n return { content: [{ type: 'text', text: decodeUtf8(bytes, displayPath(absolutePath, cwd)) }] };\n }\n return createTaggedReadResult(bytes, displayPath(absolutePath, cwd), params);\n}\n\nexport function createTaggedReadResult(bytes: Buffer, path: string, params: ReadParams): ReadTextToolResult {\n const lines = splitLines(decodeUtf8(bytes, path));\n const startIndex = params.offset === undefined ? 0 : params.offset - 1;\n if (startIndex >= lines.length) {\n throw new Error(`Offset ${params.offset} is beyond end of file (${lines.length} lines total).`);\n }\n\n const endIndex = params.limit === undefined ? lines.length : Math.min(lines.length, startIndex + params.limit);\n const selected = lines.slice(startIndex, endIndex);\n const header = formatFileHeader(path, computeFileTag(bytes));\n const compactedLines: number[] = [];\n const headerBytes = Buffer.byteLength(header, 'utf8') + 1;\n const tagged = selected.map((line, index) => {\n const lineNumber = startIndex + index + 1;\n const full = formatTaggedLine(line, lineNumber);\n if (Buffer.byteLength(full, 'utf8') <= DEFAULT_MAX_BYTES - headerBytes) return full;\n compactedLines.push(lineNumber);\n return formatTaggedLine(truncateLine(line).text, lineNumber, '', line);\n });\n const truncation = truncateHead([header, ...tagged].join('\\n'));\n let text = truncation.content;\n let details: ReadToolDetails | undefined;\n\n if (truncation.truncated) {\n const shownLines = Math.max(0, truncation.outputLines - 1);\n const nextOffset = startIndex + shownLines + 1;\n const reason = truncation.truncatedBy === 'bytes' ? `, ${formatSize(DEFAULT_MAX_BYTES)} limit` : '';\n text += `\\n\\n[Showing ${shownLines} anchored lines${reason}. Use offset=${nextOffset} to continue.]`;\n details = { truncation };\n } else {\n const notices: string[] = [];\n if (compactedLines.length > 0) {\n notices.push(`Lines ${compactedLines.join(', ')} shown compactly. Their anchors hash the full original lines`);\n }\n if (endIndex < lines.length) {\n notices.push(`${lines.length - endIndex} more lines in file. Use offset=${endIndex + 1} to continue`);\n }\n if (notices.length > 0) text += `\\n\\n[${notices.join('. ')}.]`;\n }\n\n return { content: [{ type: 'text', text }], details };\n}\n\nexport function isImageRead(content: readonly { readonly type: string; readonly text?: string }[]): boolean {\n return content.some((part) => part.type === 'image' || part.text?.startsWith('Read image file') === true);\n}\n\nexport function createHeadlessReadTool(): DoomHeadlessTool<typeof ReadParamsSchema> {\n return {\n name: 'read',\n label: 'read',\n description:\n 'Read a writable text file with an exact-byte file tag and stable line anchors. Non-writable files and images return native-compatible content. Text is truncated to 50.0KB.',\n promptSnippet: 'Read file contents with snapshot-bound line anchors',\n promptGuidelines: [\n 'Use read before edit. When hashline metadata is present, preserve the @file hash and anchors such as 5#abc exactly.',\n 'Continue large reads with offset until the required anchored lines are visible.',\n ],\n parameters: ReadParamsSchema,\n executionMode: 'parallel',\n execute: async (\n _toolCallId: string,\n params: ReadParams,\n signal: AbortSignal | undefined,\n _onUpdate: ((result: DoomHeadlessToolResult) => void) | undefined,\n context: DoomHeadlessExecutionContext,\n ) => executeHeadlessRead(params, context.cwd, signal),\n };\n}\n"],"mappings":";;;;;;;AAEA,MAAa,mBAAmBA,QAAAA,KAAK,OAAO;CAC1C,MAAMA,QAAAA,KAAK,OAAO,EAAE,aAAa,4BAA4B,CAAC;CAC9D,QAAQA,QAAAA,KAAK,SAASA,QAAAA,KAAK,QAAQ;EAAE,SAAS;EAAG,aAAa;CAAyB,CAAC,CAAC;CACzF,OAAOA,QAAAA,KAAK,SAASA,QAAAA,KAAK,QAAQ;EAAE,SAAS;EAAG,aAAa;CAAqC,CAAC,CAAC;AACtG,CAAC;;;ACJD,MAAM,eAAe;AAkCrB,SAAgB,cAA+B;CAC7C,QAAA,GAAOC,8BAAAA,oBAAAA,CAAoB;AAC7B;AAEA,eAAsB,iBACpB,SACA,QACA,YAC4B;CAC5B,IAAI,CAAC,OAAO,cAAc,CAAC,QAAQ,MAAM,SAAS,KAAK,SAAS,OAAO,GAAG,OAAO;CACjF,MAAM,WAA8B,CAAC;CACrC,KAAK,MAAM,QAAQ,SAAS;EAC1B,IAAI,KAAK,SAAS,SAAS;GACzB,SAAS,KAAK,IAAI;GAClB;EACF;EACA,MAAM,UAAU,MAAM,WAAW,OAAO,OAAO,KAAK,KAAK,MAAM,QAAQ,GAAG,KAAK,UAAU;GACvF,UAAU,OAAO;GACjB,WAAW,OAAO;EACp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AAM,YAAY,IAAI,IAAI;CACvE,CAAC;CACD,MAAM,cAAA,GAAaC,gCAAAA,aAAAA,CAAa,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC,KAAK,IAAI,CAAC;CAC9D,IAAI,OAAO,WAAW;CACtB,IAAI;CAEJ,IAAI,WAAW,WAAW;EACxB,MAAM,aAAa,KAAK,IAAI,GAAG,WAAW,cAAc,CAAC;EACzD,MAAM,aAAa,aAAa,aAAa;EAC7C,MAAM,SAAS,WAAW,gBAAgB,UAAU,MAAA,GAAKC,gCAAAA,WAAAA,CAAWH,gCAAAA,iBAAiB,EAAE,UAAU;EACjG,QAAQ,gBAAgB,WAAW,iBAAiB,OAAO,eAAe,WAAW;EACrF,UAAU,EAAE,WAAW;CACzB,OAAO;EACL,MAAM,UAAoB,CAAC;EAC3B,IAAI,eAAe,SAAS,GAC1B,QAAQ,KAAK,SAAS,eAAe,KAAK,IAAI,EAAE,6DAA6D;EAE/G,IAAI,WAAW,MAAM,QACnB,QAAQ,KAAK,GAAG,MAAM,SAAS,SAAS,kCAAkC,WAAW,EAAE,aAAa;EAEtG,IAAI,QAAQ,SAAS,GAAG,QAAQ,QAAQ,QAAQ,KAAK,IAAI,EAAE;CAC7D;CAEA,OAAO;EAAE,SAAS,CAAC;GAAE,MAAM;GAAQ;EAAK,CAAC;EAAG;CAAQ;AACtD;AAMA,SAAgB,yBAAoE;CAClF,OAAO;EACL,MAAM;EACN,OAAO;EACP,aACE;EACF,eAAe;EACf,kBAAkB,CAChB,uHACA,iFACF;EACA,YAAY;EACZ,eAAe;EACf,SAAS,OACP,aACA,QACA,QACA,WACA,YACG,oBAAoB,QAAQ,QAAQ,KAAK,MAAM;CACtD;AACF"}
@@ -0,0 +1,152 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { formatFileHeader, formatTaggedLine, splitLines } from "@agimon-ai/po-hashline";
3
+ import { computeFileTag, decodeUtf8, displayPath, isWritableFile, resolveReadInputPath } from "@agimon-ai/po-hashline/files";
4
+ import { DEFAULT_MAX_BYTES, formatDimensionNote, formatSize, resizeImage, truncateHead, truncateLine } from "@earendil-works/pi-coding-agent";
5
+ import { Type } from "typebox";
6
+ import { loadPiImageSettings } from "@agimon-ai/po-config/piConfig";
7
+ //#region src/schemas/readTool.ts
8
+ const ReadParamsSchema = Type.Object({
9
+ path: Type.String({ description: "Path to the file to read." }),
10
+ offset: Type.Optional(Type.Integer({
11
+ minimum: 1,
12
+ description: "One-based line offset."
13
+ })),
14
+ limit: Type.Optional(Type.Integer({
15
+ minimum: 1,
16
+ description: "Maximum number of lines to return."
17
+ }))
18
+ });
19
+ //#endregion
20
+ //#region src/services/readImage/index.ts
21
+ const OMITTED_NOTE = "[Image omitted: could not be resized below the inline image size limit.]";
22
+ function imageLimits() {
23
+ return loadPiImageSettings();
24
+ }
25
+ async function applyImageLimits(content, limits, operations) {
26
+ if (!limits.autoResize || !content.some((part) => part.type === "image")) return content;
27
+ const resolved = [];
28
+ for (const part of content) {
29
+ if (part.type !== "image") {
30
+ resolved.push(part);
31
+ continue;
32
+ }
33
+ const resized = await operations.resize(Buffer.from(part.data, "base64"), part.mimeType, {
34
+ maxWidth: limits.maxDimension,
35
+ maxHeight: limits.maxDimension
36
+ });
37
+ if (!resized) {
38
+ resolved.push({
39
+ type: "text",
40
+ text: OMITTED_NOTE
41
+ });
42
+ continue;
43
+ }
44
+ resolved.push({
45
+ type: "image",
46
+ data: resized.data,
47
+ mimeType: resized.mimeType
48
+ });
49
+ const note = operations.formatDimensionNote(resized);
50
+ if (note) resolved.push({
51
+ type: "text",
52
+ text: note
53
+ });
54
+ }
55
+ return resolved;
56
+ }
57
+ //#endregion
58
+ //#region src/services/readTool/index.ts
59
+ const resizeOperations = {
60
+ resize: resizeImage,
61
+ formatDimensionNote: (result) => formatDimensionNote(result)
62
+ };
63
+ function assertNotAborted(signal) {
64
+ if (signal?.aborted) throw new Error("Operation aborted");
65
+ }
66
+ function isImagePath(filePath) {
67
+ const extension = filePath.toLowerCase().match(/\.([a-z0-9]+)$/u)?.[1];
68
+ if (!extension) return void 0;
69
+ return {
70
+ avif: "image/avif",
71
+ gif: "image/gif",
72
+ jpeg: "image/jpeg",
73
+ jpg: "image/jpeg",
74
+ png: "image/png",
75
+ webp: "image/webp"
76
+ }[extension];
77
+ }
78
+ async function executeHeadlessRead(params, cwd, signal) {
79
+ assertNotAborted(signal);
80
+ const absolutePath = await resolveReadInputPath(params.path, cwd);
81
+ const bytes = await readFile(absolutePath);
82
+ assertNotAborted(signal);
83
+ const mimeType = isImagePath(absolutePath);
84
+ if (mimeType) return { content: await applyImageLimits([{
85
+ type: "text",
86
+ text: `Read image file ${displayPath(absolutePath, cwd)} [${mimeType}]`
87
+ }, {
88
+ type: "image",
89
+ data: bytes.toString("base64"),
90
+ mimeType
91
+ }], imageLimits(), resizeOperations) };
92
+ if (!await isWritableFile(absolutePath)) return { content: [{
93
+ type: "text",
94
+ text: decodeUtf8(bytes, displayPath(absolutePath, cwd))
95
+ }] };
96
+ return createTaggedReadResult(bytes, displayPath(absolutePath, cwd), params);
97
+ }
98
+ function createTaggedReadResult(bytes, path, params) {
99
+ const lines = splitLines(decodeUtf8(bytes, path));
100
+ const startIndex = params.offset === void 0 ? 0 : params.offset - 1;
101
+ if (startIndex >= lines.length) throw new Error(`Offset ${params.offset} is beyond end of file (${lines.length} lines total).`);
102
+ const endIndex = params.limit === void 0 ? lines.length : Math.min(lines.length, startIndex + params.limit);
103
+ const selected = lines.slice(startIndex, endIndex);
104
+ const header = formatFileHeader(path, computeFileTag(bytes));
105
+ const compactedLines = [];
106
+ const headerBytes = Buffer.byteLength(header, "utf8") + 1;
107
+ const tagged = selected.map((line, index) => {
108
+ const lineNumber = startIndex + index + 1;
109
+ const full = formatTaggedLine(line, lineNumber);
110
+ if (Buffer.byteLength(full, "utf8") <= DEFAULT_MAX_BYTES - headerBytes) return full;
111
+ compactedLines.push(lineNumber);
112
+ return formatTaggedLine(truncateLine(line).text, lineNumber, "", line);
113
+ });
114
+ const truncation = truncateHead([header, ...tagged].join("\n"));
115
+ let text = truncation.content;
116
+ let details;
117
+ if (truncation.truncated) {
118
+ const shownLines = Math.max(0, truncation.outputLines - 1);
119
+ const nextOffset = startIndex + shownLines + 1;
120
+ const reason = truncation.truncatedBy === "bytes" ? `, ${formatSize(DEFAULT_MAX_BYTES)} limit` : "";
121
+ text += `\n\n[Showing ${shownLines} anchored lines${reason}. Use offset=${nextOffset} to continue.]`;
122
+ details = { truncation };
123
+ } else {
124
+ const notices = [];
125
+ if (compactedLines.length > 0) notices.push(`Lines ${compactedLines.join(", ")} shown compactly. Their anchors hash the full original lines`);
126
+ if (endIndex < lines.length) notices.push(`${lines.length - endIndex} more lines in file. Use offset=${endIndex + 1} to continue`);
127
+ if (notices.length > 0) text += `\n\n[${notices.join(". ")}.]`;
128
+ }
129
+ return {
130
+ content: [{
131
+ type: "text",
132
+ text
133
+ }],
134
+ details
135
+ };
136
+ }
137
+ function createHeadlessReadTool() {
138
+ return {
139
+ name: "read",
140
+ label: "read",
141
+ description: "Read a writable text file with an exact-byte file tag and stable line anchors. Non-writable files and images return native-compatible content. Text is truncated to 50.0KB.",
142
+ promptSnippet: "Read file contents with snapshot-bound line anchors",
143
+ promptGuidelines: ["Use read before edit. When hashline metadata is present, preserve the @file hash and anchors such as 5#abc exactly.", "Continue large reads with offset until the required anchored lines are visible."],
144
+ parameters: ReadParamsSchema,
145
+ executionMode: "parallel",
146
+ execute: async (_toolCallId, params, signal, _onUpdate, context) => executeHeadlessRead(params, context.cwd, signal)
147
+ };
148
+ }
149
+ //#endregion
150
+ export { executeHeadlessRead as n, ReadParamsSchema as r, createHeadlessReadTool as t };
151
+
152
+ //# sourceMappingURL=readTool-epk_n4AS.mjs.map