@code-yeongyu/senpi-agent-core 2026.9.16 → 2026.9.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/assets/tree-sitter/javascript.wasm +0 -0
- package/assets/tree-sitter/provenance.json +22 -0
- package/assets/tree-sitter/web-tree-sitter.wasm +0 -0
- package/dist/harness/tools/read.d.ts.map +1 -1
- package/dist/harness/tools/read.js +4 -1
- package/dist/harness/tools/read.js.map +1 -1
- package/dist/harness/utils/read-folders/compose.d.ts +6 -0
- package/dist/harness/utils/read-folders/compose.d.ts.map +1 -0
- package/dist/harness/utils/read-folders/compose.js +34 -0
- package/dist/harness/utils/read-folders/compose.js.map +1 -0
- package/dist/harness/utils/read-folders/index.d.ts +14 -8
- package/dist/harness/utils/read-folders/index.d.ts.map +1 -1
- package/dist/harness/utils/read-folders/index.js +24 -40
- package/dist/harness/utils/read-folders/index.js.map +1 -1
- package/dist/harness/utils/read-folders/prepare.d.ts +11 -0
- package/dist/harness/utils/read-folders/prepare.d.ts.map +1 -0
- package/dist/harness/utils/read-folders/prepare.js +22 -0
- package/dist/harness/utils/read-folders/prepare.js.map +1 -0
- package/dist/harness/utils/read-folders/tree-sitter/engine.d.ts +25 -0
- package/dist/harness/utils/read-folders/tree-sitter/engine.d.ts.map +1 -0
- package/dist/harness/utils/read-folders/tree-sitter/engine.js +97 -0
- package/dist/harness/utils/read-folders/tree-sitter/engine.js.map +1 -0
- package/dist/harness/utils/read-folders/tree-sitter/grammar-assets.d.ts +20 -0
- package/dist/harness/utils/read-folders/tree-sitter/grammar-assets.d.ts.map +1 -0
- package/dist/harness/utils/read-folders/tree-sitter/grammar-assets.js +67 -0
- package/dist/harness/utils/read-folders/tree-sitter/grammar-assets.js.map +1 -0
- package/dist/harness/utils/read-folders/tree-sitter/syntax.d.ts +24 -0
- package/dist/harness/utils/read-folders/tree-sitter/syntax.d.ts.map +1 -0
- package/dist/harness/utils/read-folders/tree-sitter/syntax.js +181 -0
- package/dist/harness/utils/read-folders/tree-sitter/syntax.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"note": "Vendored WebAssembly artifacts for the structural read fold-boundary engine (#1685). Shipped grammars are limited to languages the frozen read selection binds to `wasm`; every other evaluated grammar is resolved from the pinned measurement dependency at bake-off time only.",
|
|
3
|
+
"runtime": {
|
|
4
|
+
"file": "web-tree-sitter.wasm",
|
|
5
|
+
"package": "web-tree-sitter",
|
|
6
|
+
"version": "0.27.0",
|
|
7
|
+
"source": "web-tree-sitter.wasm",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"sha256": "c03bccdc3b448a32848f5ae327e209c982bbb0840d43eec8bc2d5759544a1ed3"
|
|
10
|
+
},
|
|
11
|
+
"grammars": [
|
|
12
|
+
{
|
|
13
|
+
"language": "js",
|
|
14
|
+
"file": "javascript.wasm",
|
|
15
|
+
"package": "@vscode/tree-sitter-wasm",
|
|
16
|
+
"version": "0.3.1",
|
|
17
|
+
"source": "wasm/tree-sitter-javascript.wasm",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"sha256": "5fb488d0cabb4775a594bab85682de5ad6ce83c0d6ac997a9f82dd084d571240"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/read.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,KAAK,UAAU,E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GAAmG;IACnG,MAAM,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,wBAAgB,cAAc,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,EAC1F,OAAO,GAAE,eAAgD,GACvD,gBAAgB,CAAC,QAAQ,EAAE,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAiH5E"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { FileError, getOrThrow } from "../types.js";
|
|
3
3
|
import { selectedReadFolder } from "../utils/read-folders/index.js";
|
|
4
|
+
import { prepareReadFolder } from "../utils/read-folders/prepare.js";
|
|
4
5
|
import { createDefaultReadSummary } from "../utils/segmented-read-view.js";
|
|
5
6
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, } from "../utils/truncate.js";
|
|
6
7
|
import { detectSupportedImageMimeType, encodeBase64 } from "./image.js";
|
|
@@ -78,12 +79,14 @@ export function createReadTool(options = { folder: selectedReadFolder }) {
|
|
|
78
79
|
selectedContent = allLines.slice(startLine).join("\n");
|
|
79
80
|
}
|
|
80
81
|
const truncation = truncateHead(selectedContent);
|
|
82
|
+
// A selected grammar loads lazily here, on the first structural read for its language.
|
|
83
|
+
const folder = await prepareReadFolder(absolutePath, options.folder);
|
|
81
84
|
const summary = createDefaultReadSummary({
|
|
82
85
|
path: absolutePath,
|
|
83
86
|
text: textContent,
|
|
84
87
|
offset,
|
|
85
88
|
limit,
|
|
86
|
-
folder
|
|
89
|
+
folder,
|
|
87
90
|
truncated: truncation.truncated,
|
|
88
91
|
});
|
|
89
92
|
let outputText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/harness/tools/read.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,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AAc,gBAAgB,UAAU,gBAAgB,CAAC;gBACvI,CAAC;qBAAM,CAAC;oBACP,UAAU,IAAI,sBAAsB,gBAAgB,IAAI,cAAc,OAAO,cAAc,KAAK,UAAU,CAAC,iBAAiB,CAAC,uBAAuB,UAAU,gBAAgB,CAAC;gBAChL,CAAC;gBACD,OAAO,GAAG,EAAE,UAAU,EAAE,CAAC;YAC1B,CAAC;iBAAM,IAAI,gBAAgB,KAAK,SAAS,IAAI,SAAS,GAAG,gBAAgB,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;gBAC7F,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,SAAS,GAAG,gBAAgB,CAAC,CAAC;gBACnE,MAAM,UAAU,GAAG,SAAS,GAAG,gBAAgB,GAAG,CAAC,CAAC;gBACpD,UAAU,GAAG,GAAG,UAAU,CAAC,OAAO,QAAQ,SAAS,mCAAmC,UAAU,gBAAgB,CAAC;YAClH,CAAC;iBAAM,CAAC;gBACP,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC;YACjC,CAAC;YAED,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;QACnE,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { type Static, Type } from \"typebox\";\nimport type { Context } from \"../context.ts\";\nimport type { AgentHarnessTool } from \"../types.ts\";\nimport { FileError, getOrThrow } from \"../types.ts\";\nimport { type ReadFolder, selectedReadFolder } from \"../utils/read-folders/index.ts\";\nimport { createDefaultReadSummary } from \"../utils/segmented-read-view.ts\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"../utils/truncate.ts\";\nimport { detectSupportedImageMimeType, encodeBase64 } from \"./image.ts\";\nimport { resolveReadToolPath } from \"./path-utils.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\nexport type ReadImageProcessorResult =\n\t| { ok: true; data: string; mimeType: string; hints: string[] }\n\t| { ok: false; message: string };\n\nexport type ReadImageProcessor = (\n\tbytes: Uint8Array,\n\tmimeType: string,\n\toptions: { autoResizeImages: boolean },\n\tcontext: Context,\n) => Promise<ReadImageProcessorResult>;\n\nexport interface ReadToolOptions {\n\t/** Whether an injected image processor should resize images. Default: true. */\n\tautoResizeImages?: boolean;\n\t/** Optional image conversion/resizing implementation. */\n\timageProcessor?: ReadImageProcessor;\n\t/** Structural folder. Default options select the measured folder; omit here for verbatim reads. */\n\tfolder?: ReadFolder;\n}\n\nexport function createReadTool<TContext extends ExecutionToolContext = ExecutionToolContext>(\n\toptions: ReadToolOptions = { folder: selectedReadFolder },\n): AgentHarnessTool<TContext, typeof readSchema, ReadToolDetails | undefined> {\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tparameters: readSchema,\n\t\tasync execute(_toolCallId, { path, offset, limit }, _onUpdate, { env }, _invocation, context) {\n\t\t\tconst absolutePath = await resolveReadToolPath(env, path, context);\n\t\t\tconst bytes = getOrThrow(await env.readBinaryFile(absolutePath, context));\n\t\t\tif (context.abortSignal?.aborted) throw new FileError(\"aborted\", \"Operation aborted\", absolutePath);\n\t\t\tconst mimeType = detectSupportedImageMimeType(bytes);\n\t\t\tif (mimeType) {\n\t\t\t\tif (options?.imageProcessor) {\n\t\t\t\t\tconst processed = await options.imageProcessor(\n\t\t\t\t\t\tbytes,\n\t\t\t\t\t\tmimeType,\n\t\t\t\t\t\t{ autoResizeImages: options.autoResizeImages ?? true },\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t);\n\t\t\t\t\tif (!processed.ok) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Read image file [${mimeType}]\\n${processed.message}` }],\n\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst hints = processed.hints.length > 0 ? `\\n${processed.hints.join(\"\\n\")}` : \"\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\", text: `Read image file [${processed.mimeType}]${hints}` },\n\t\t\t\t\t\t\t{ type: \"image\", data: processed.data, mimeType: processed.mimeType },\n\t\t\t\t\t\t] satisfies Array<TextContent | ImageContent>,\n\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (mimeType === \"image/bmp\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: \"Read image file [image/bmp]\\n[Image omitted: configure an imageProcessor to convert BMP images.]\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{ type: \"text\", text: `Read image file [${mimeType}]` },\n\t\t\t\t\t\t{ type: \"image\", data: encodeBase64(bytes), mimeType },\n\t\t\t\t\t] satisfies Array<TextContent | ImageContent>,\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst textContent = new TextDecoder().decode(bytes);\n\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\tconst totalFileLines = allLines.length;\n\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\tif (startLine >= allLines.length) {\n\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t}\n\n\t\t\tlet selectedContent: string;\n\t\t\tlet userLimitedLines: number | undefined;\n\t\t\tif (limit !== undefined) {\n\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t} else {\n\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t}\n\n\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\tconst summary = createDefaultReadSummary({\n\t\t\t\tpath: absolutePath,\n\t\t\t\ttext: textContent,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tfolder: options.folder,\n\t\t\t\ttruncated: truncation.truncated,\n\t\t\t});\n\t\t\tlet outputText: string;\n\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\tif (summary) {\n\t\t\t\toutputText = summary.text;\n\t\t\t} else if (truncation.firstLineExceedsLimit) {\n\t\t\t\tconst firstLineSize = formatSize(new TextEncoder().encode(allLines[startLine]).byteLength);\n\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\tdetails = { truncation };\n\t\t\t} else if (truncation.truncated) {\n\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\toutputText = truncation.content;\n\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t} else {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t}\n\t\t\t\tdetails = { truncation };\n\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t} else {\n\t\t\t\toutputText = truncation.content;\n\t\t\t}\n\n\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/harness/tools/read.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAmB,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAEV,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtD,MAAM,UAAU,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AM,IAAI,gBAAgB,KAAK,SAAS,IAAI,SAAS,GAAG,gBAAgB,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;gBAC7F,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,SAAS,GAAG,gBAAgB,CAAC,CAAC;gBACnE,MAAM,UAAU,GAAG,SAAS,GAAG,gBAAgB,GAAG,CAAC,CAAC;gBACpD,UAAU,GAAG,GAAG,UAAU,CAAC,OAAO,QAAQ,SAAS,mCAAmC,UAAU,gBAAgB,CAAC;YAClH,CAAC;iBAAM,CAAC;gBACP,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC;YACjC,CAAC;YAED,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;QACnE,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { type Static, Type } from \"typebox\";\nimport type { Context } from \"../context.ts\";\nimport type { AgentHarnessTool } from \"../types.ts\";\nimport { FileError, getOrThrow } from \"../types.ts\";\nimport { type ReadFolder, selectedReadFolder } from \"../utils/read-folders/index.ts\";\nimport { prepareReadFolder } from \"../utils/read-folders/prepare.ts\";\nimport { createDefaultReadSummary } from \"../utils/segmented-read-view.ts\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"../utils/truncate.ts\";\nimport { detectSupportedImageMimeType, encodeBase64 } from \"./image.ts\";\nimport { resolveReadToolPath } from \"./path-utils.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\nexport type ReadImageProcessorResult =\n\t| { ok: true; data: string; mimeType: string; hints: string[] }\n\t| { ok: false; message: string };\n\nexport type ReadImageProcessor = (\n\tbytes: Uint8Array,\n\tmimeType: string,\n\toptions: { autoResizeImages: boolean },\n\tcontext: Context,\n) => Promise<ReadImageProcessorResult>;\n\nexport interface ReadToolOptions {\n\t/** Whether an injected image processor should resize images. Default: true. */\n\tautoResizeImages?: boolean;\n\t/** Optional image conversion/resizing implementation. */\n\timageProcessor?: ReadImageProcessor;\n\t/** Structural folder. Default options select the measured folder; omit here for verbatim reads. */\n\tfolder?: ReadFolder;\n}\n\nexport function createReadTool<TContext extends ExecutionToolContext = ExecutionToolContext>(\n\toptions: ReadToolOptions = { folder: selectedReadFolder },\n): AgentHarnessTool<TContext, typeof readSchema, ReadToolDetails | undefined> {\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tparameters: readSchema,\n\t\tasync execute(_toolCallId, { path, offset, limit }, _onUpdate, { env }, _invocation, context) {\n\t\t\tconst absolutePath = await resolveReadToolPath(env, path, context);\n\t\t\tconst bytes = getOrThrow(await env.readBinaryFile(absolutePath, context));\n\t\t\tif (context.abortSignal?.aborted) throw new FileError(\"aborted\", \"Operation aborted\", absolutePath);\n\t\t\tconst mimeType = detectSupportedImageMimeType(bytes);\n\t\t\tif (mimeType) {\n\t\t\t\tif (options?.imageProcessor) {\n\t\t\t\t\tconst processed = await options.imageProcessor(\n\t\t\t\t\t\tbytes,\n\t\t\t\t\t\tmimeType,\n\t\t\t\t\t\t{ autoResizeImages: options.autoResizeImages ?? true },\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t);\n\t\t\t\t\tif (!processed.ok) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Read image file [${mimeType}]\\n${processed.message}` }],\n\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst hints = processed.hints.length > 0 ? `\\n${processed.hints.join(\"\\n\")}` : \"\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\", text: `Read image file [${processed.mimeType}]${hints}` },\n\t\t\t\t\t\t\t{ type: \"image\", data: processed.data, mimeType: processed.mimeType },\n\t\t\t\t\t\t] satisfies Array<TextContent | ImageContent>,\n\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (mimeType === \"image/bmp\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: \"Read image file [image/bmp]\\n[Image omitted: configure an imageProcessor to convert BMP images.]\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{ type: \"text\", text: `Read image file [${mimeType}]` },\n\t\t\t\t\t\t{ type: \"image\", data: encodeBase64(bytes), mimeType },\n\t\t\t\t\t] satisfies Array<TextContent | ImageContent>,\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst textContent = new TextDecoder().decode(bytes);\n\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\tconst totalFileLines = allLines.length;\n\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\tif (startLine >= allLines.length) {\n\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t}\n\n\t\t\tlet selectedContent: string;\n\t\t\tlet userLimitedLines: number | undefined;\n\t\t\tif (limit !== undefined) {\n\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t} else {\n\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t}\n\n\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t// A selected grammar loads lazily here, on the first structural read for its language.\n\t\t\tconst folder = await prepareReadFolder(absolutePath, options.folder);\n\t\t\tconst summary = createDefaultReadSummary({\n\t\t\t\tpath: absolutePath,\n\t\t\t\ttext: textContent,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tfolder,\n\t\t\t\ttruncated: truncation.truncated,\n\t\t\t});\n\t\t\tlet outputText: string;\n\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\tif (summary) {\n\t\t\t\toutputText = summary.text;\n\t\t\t} else if (truncation.firstLineExceedsLimit) {\n\t\t\t\tconst firstLineSize = formatSize(new TextEncoder().encode(allLines[startLine]).byteLength);\n\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\tdetails = { truncation };\n\t\t\t} else if (truncation.truncated) {\n\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\toutputText = truncation.content;\n\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t} else {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t}\n\t\t\t\tdetails = { truncation };\n\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t} else {\n\t\t\t\toutputText = truncation.content;\n\t\t\t}\n\n\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReadBraceScan, ReadFolderResult, ReadFoldRange, ReadLineRange } from "./types.ts";
|
|
2
|
+
/** Hierarchical omitted interiors from a flat scan. Ambiguous nesting is a parse failure, not a guess. */
|
|
3
|
+
export declare function hierarchy(ranges: readonly ReadLineRange[]): readonly ReadFoldRange[] | undefined;
|
|
4
|
+
/** The single scan-to-result composition shared by every fold-boundary engine. */
|
|
5
|
+
export declare function composeFoldResult(text: string, scan: ReadBraceScan): ReadFolderResult;
|
|
6
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhG,0GAA0G;AAC1G,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,aAAa,EAAE,GAAG,SAAS,CAehG;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,gBAAgB,CAarF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Hierarchical omitted interiors from a flat scan. Ambiguous nesting is a parse failure, not a guess. */
|
|
2
|
+
export function hierarchy(ranges) {
|
|
3
|
+
const roots = [];
|
|
4
|
+
const stack = [];
|
|
5
|
+
for (const range of [...ranges].sort((a, b) => a.startLine - b.startLine || b.endLine - a.endLine)) {
|
|
6
|
+
while (stack.length && range.startLine > stack[stack.length - 1].endLine)
|
|
7
|
+
stack.pop();
|
|
8
|
+
const parent = stack[stack.length - 1];
|
|
9
|
+
if (parent && range.startLine === parent.startLine && range.endLine === parent.endLine)
|
|
10
|
+
continue;
|
|
11
|
+
if (parent && (range.startLine <= parent.startLine || range.endLine >= parent.endLine))
|
|
12
|
+
return undefined;
|
|
13
|
+
const node = { ...range, children: [] };
|
|
14
|
+
(parent ? parent.children : roots).push(node);
|
|
15
|
+
stack.push(node);
|
|
16
|
+
}
|
|
17
|
+
return roots;
|
|
18
|
+
}
|
|
19
|
+
/** The single scan-to-result composition shared by every fold-boundary engine. */
|
|
20
|
+
export function composeFoldResult(text, scan) {
|
|
21
|
+
switch (scan.status) {
|
|
22
|
+
case "parse_failure":
|
|
23
|
+
return scan;
|
|
24
|
+
case "parsed": {
|
|
25
|
+
const ranges = hierarchy(scan.ranges);
|
|
26
|
+
return ranges
|
|
27
|
+
? { status: "parsed", text, ranges }
|
|
28
|
+
: { status: "parse_failure", reason: "ambiguous_line_boundaries" };
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
return scan;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=compose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/compose.ts"],"names":[],"mappings":"AAEA,0GAA0G;AAC1G,MAAM,U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AAC;QACrB,KAAK,eAAe;YACnB,OAAO,IAAI,CAAC;QACb,KAAK,QAAQ,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACtC,OAAO,MAAM;gBACZ,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE;gBACpC,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,2BAA2B,EAAE,CAAC;QACrE,CAAC;QACD;YACC,OAAO,IAAoB,CAAC;IAC9B,CAAC;AACF,CAAC","sourcesContent":["import type { ReadBraceScan, ReadFolderResult, ReadFoldRange, ReadLineRange } from \"./types.ts\";\n\n/** Hierarchical omitted interiors from a flat scan. Ambiguous nesting is a parse failure, not a guess. */\nexport function hierarchy(ranges: readonly ReadLineRange[]): readonly ReadFoldRange[] | undefined {\n\t// Builder-owned arrays; no caller-owned ranges are sorted or mutated.\n\ttype Node = ReadLineRange & { readonly children: Node[] };\n\tconst roots: Node[] = [];\n\tconst stack: Node[] = [];\n\tfor (const range of [...ranges].sort((a, b) => a.startLine - b.startLine || b.endLine - a.endLine)) {\n\t\twhile (stack.length && range.startLine > stack[stack.length - 1].endLine) stack.pop();\n\t\tconst parent = stack[stack.length - 1];\n\t\tif (parent && range.startLine === parent.startLine && range.endLine === parent.endLine) continue;\n\t\tif (parent && (range.startLine <= parent.startLine || range.endLine >= parent.endLine)) return undefined;\n\t\tconst node: Node = { ...range, children: [] };\n\t\t(parent ? parent.children : roots).push(node);\n\t\tstack.push(node);\n\t}\n\treturn roots;\n}\n\n/** The single scan-to-result composition shared by every fold-boundary engine. */\nexport function composeFoldResult(text: string, scan: ReadBraceScan): ReadFolderResult {\n\tswitch (scan.status) {\n\t\tcase \"parse_failure\":\n\t\t\treturn scan;\n\t\tcase \"parsed\": {\n\t\t\tconst ranges = hierarchy(scan.ranges);\n\t\t\treturn ranges\n\t\t\t\t? { status: \"parsed\", text, ranges }\n\t\t\t\t: { status: \"parse_failure\", reason: \"ambiguous_line_boundaries\" };\n\t\t}\n\t\tdefault:\n\t\t\treturn scan satisfies never;\n\t}\n}\n"]}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { ReadFolder } from "./types.ts";
|
|
2
2
|
export * from "./types.ts";
|
|
3
|
-
/** Frozen
|
|
3
|
+
/** Frozen measured selection, not a runtime registry that can enable unmeasured grammars. */
|
|
4
4
|
export declare const READ_FOLDER_SELECTION: Readonly<{
|
|
5
|
-
readonly head: "
|
|
6
|
-
readonly selectionSha256: "
|
|
7
|
-
readonly wasm:
|
|
5
|
+
readonly head: "ec63eb5ee999da83b9e5d3e37b83d1998707f44c";
|
|
6
|
+
readonly selectionSha256: "07388b6a393cc05c78533fa701d536d5e617a38e2293b10c0a281a55395cc8a3";
|
|
7
|
+
readonly wasm: true;
|
|
8
8
|
readonly rawReasons: Readonly<{
|
|
9
|
-
readonly ts: "
|
|
10
|
-
readonly
|
|
9
|
+
readonly ts: "wasm_candidate_below_threshold";
|
|
10
|
+
readonly tsx: "wasm_candidate_below_threshold";
|
|
11
11
|
}>;
|
|
12
12
|
readonly languages: Readonly<{
|
|
13
13
|
readonly ts: "raw";
|
|
14
|
-
readonly js: "
|
|
14
|
+
readonly js: "wasm";
|
|
15
15
|
readonly json: "heuristic";
|
|
16
|
-
readonly tsx: "
|
|
16
|
+
readonly tsx: "raw";
|
|
17
17
|
readonly python: "unsupported";
|
|
18
18
|
readonly rust: "unsupported";
|
|
19
19
|
readonly go: "unsupported";
|
|
@@ -21,6 +21,12 @@ export declare const READ_FOLDER_SELECTION: Readonly<{
|
|
|
21
21
|
readonly txt: "prose_exempt";
|
|
22
22
|
}>;
|
|
23
23
|
}>;
|
|
24
|
+
export type ReadSummaryLanguage = keyof typeof READ_FOLDER_SELECTION.languages;
|
|
25
|
+
/** Every engine a frozen selection may name, independent of which ones the current receipt uses. */
|
|
26
|
+
export type ReadSummaryEngine = "raw" | "heuristic" | "wasm" | "unsupported" | "prose_exempt";
|
|
27
|
+
export declare function languageForPath(path: string): ReadSummaryLanguage | undefined;
|
|
28
|
+
/** The frozen engine for a path's language, independent of which folder object a caller supplies. */
|
|
29
|
+
export declare function readSummaryEngineForPath(path: string): ReadSummaryEngine | undefined;
|
|
24
30
|
/** Reader eligibility stays bound to the frozen selection even with a custom folder. */
|
|
25
31
|
export declare function isReadSummaryPath(path: string): boolean;
|
|
26
32
|
export declare const selectedReadFolder: ReadFolder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAqC,MAAM,YAAY,CAAC;AAEhF,cAAc,YAAY,CAAC;AAE3B,6FAA6F;AAC7F,eAAO,MAAM,qBAAqB;mBAC3B,0CAA0C;8BAC/B,kEAAkE;;;qBAG9E,gCAAgC;sBAC/B,gCAAgC;;;qBAGjC,KAAK;qBACL,MAAM;uBACJ,WAAW;sBACZ,KAAK;yBACF,aAAa;uBACf,aAAa;qBACf,aAAa;2BACP,cAAc;sBACnB,cAAc;;EAEV,CAAC;AAEZ,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,qBAAqB,CAAC,SAAS,CAAC;AAC/E,oGAAoG;AACpG,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,WAAW,GAAG,MAAM,GAAG,aAAa,GAAG,cAAc,CAAC;AAC9F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CA6B7E;AAED,qGAAqG;AACrG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAKpF;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGvD;AAgCD,eAAO,MAAM,kBAAkB,EAAE,UAAwE,CAAC"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { scanBraces } from "./brace-scanner.js";
|
|
2
|
+
import { composeFoldResult } from "./compose.js";
|
|
2
3
|
export * from "./types.js";
|
|
3
|
-
/** Frozen
|
|
4
|
+
/** Frozen measured selection, not a runtime registry that can enable unmeasured grammars. */
|
|
4
5
|
export const READ_FOLDER_SELECTION = Object.freeze({
|
|
5
|
-
head: "
|
|
6
|
-
selectionSha256: "
|
|
7
|
-
wasm:
|
|
8
|
-
rawReasons: Object.freeze({
|
|
6
|
+
head: "ec63eb5ee999da83b9e5d3e37b83d1998707f44c",
|
|
7
|
+
selectionSha256: "07388b6a393cc05c78533fa701d536d5e617a38e2293b10c0a281a55395cc8a3",
|
|
8
|
+
wasm: true,
|
|
9
|
+
rawReasons: Object.freeze({
|
|
10
|
+
ts: "wasm_candidate_below_threshold",
|
|
11
|
+
tsx: "wasm_candidate_below_threshold",
|
|
12
|
+
}),
|
|
9
13
|
languages: Object.freeze({
|
|
10
14
|
ts: "raw",
|
|
11
|
-
js: "
|
|
15
|
+
js: "wasm",
|
|
12
16
|
json: "heuristic",
|
|
13
|
-
tsx: "
|
|
17
|
+
tsx: "raw",
|
|
14
18
|
python: "unsupported",
|
|
15
19
|
rust: "unsupported",
|
|
16
20
|
go: "unsupported",
|
|
@@ -18,7 +22,7 @@ export const READ_FOLDER_SELECTION = Object.freeze({
|
|
|
18
22
|
txt: "prose_exempt",
|
|
19
23
|
}),
|
|
20
24
|
});
|
|
21
|
-
function languageForPath(path) {
|
|
25
|
+
export function languageForPath(path) {
|
|
22
26
|
const name = path.split(/[\\/]/).pop()?.toLowerCase() ?? "";
|
|
23
27
|
if (!name.includes("."))
|
|
24
28
|
return undefined;
|
|
@@ -49,27 +53,18 @@ function languageForPath(path) {
|
|
|
49
53
|
return undefined;
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
|
-
/**
|
|
53
|
-
export function
|
|
56
|
+
/** The frozen engine for a path's language, independent of which folder object a caller supplies. */
|
|
57
|
+
export function readSummaryEngineForPath(path) {
|
|
54
58
|
const language = languageForPath(path);
|
|
55
|
-
|
|
59
|
+
if (language === undefined)
|
|
60
|
+
return undefined;
|
|
61
|
+
const engine = READ_FOLDER_SELECTION.languages[language];
|
|
62
|
+
return engine;
|
|
56
63
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
while (stack.length && range.startLine > stack[stack.length - 1].endLine)
|
|
62
|
-
stack.pop();
|
|
63
|
-
const parent = stack[stack.length - 1];
|
|
64
|
-
if (parent && range.startLine === parent.startLine && range.endLine === parent.endLine)
|
|
65
|
-
continue;
|
|
66
|
-
if (parent && (range.startLine <= parent.startLine || range.endLine >= parent.endLine))
|
|
67
|
-
return undefined;
|
|
68
|
-
const node = { ...range, children: [] };
|
|
69
|
-
(parent ? parent.children : roots).push(node);
|
|
70
|
-
stack.push(node);
|
|
71
|
-
}
|
|
72
|
-
return roots;
|
|
64
|
+
/** Reader eligibility stays bound to the frozen selection even with a custom folder. */
|
|
65
|
+
export function isReadSummaryPath(path) {
|
|
66
|
+
const engine = readSummaryEngineForPath(path);
|
|
67
|
+
return engine === "heuristic" || engine === "wasm";
|
|
73
68
|
}
|
|
74
69
|
function fold({ path, text, settings }) {
|
|
75
70
|
const language = languageForPath(path);
|
|
@@ -83,6 +78,7 @@ function fold({ path, text, settings }) {
|
|
|
83
78
|
return { status: "unsupported", reason: "prose_exempt" };
|
|
84
79
|
case "raw": // Retain the pure candidate for safety/quality measurement, never default-read eligibility.
|
|
85
80
|
case "heuristic":
|
|
81
|
+
case "wasm": // The heuristic scan is the tree-sitter engine's fallback, so it stays callable here.
|
|
86
82
|
break;
|
|
87
83
|
default:
|
|
88
84
|
return engine;
|
|
@@ -100,19 +96,7 @@ function fold({ path, text, settings }) {
|
|
|
100
96
|
throw error;
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
|
-
|
|
104
|
-
switch (scan.status) {
|
|
105
|
-
case "parse_failure":
|
|
106
|
-
return scan;
|
|
107
|
-
case "parsed": {
|
|
108
|
-
const ranges = hierarchy(scan.ranges);
|
|
109
|
-
return ranges
|
|
110
|
-
? { status: "parsed", text, ranges }
|
|
111
|
-
: { status: "parse_failure", reason: "ambiguous_line_boundaries" };
|
|
112
|
-
}
|
|
113
|
-
default:
|
|
114
|
-
return scan;
|
|
115
|
-
}
|
|
99
|
+
return composeFoldResult(text, scanBraces(text, language, settings));
|
|
116
100
|
}
|
|
117
101
|
export const selectedReadFolder = Object.freeze({ id: "measured-brace", version: "3", fold });
|
|
118
102
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,cAAc,YAAY,CAAC;AAE3B,6FAA6F;AAC7F,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IAClD,IAAI,EAAE,0CAA0C;IAChD,eAAe,EAAE,kEAAkE;IACnF,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC;QACzB,EAAE,EAAE,gCAAgC;QACpC,GAAG,EAAE,gCAAgC;KAC5B,CAAC;IACX,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;QACxB,EAAE,EAAE,KAAK;QACT,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,WAAW;QACjB,GAAG,EAAE,KAA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,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;YAC7F,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC","sourcesContent":["import { scanBraces } from \"./brace-scanner.ts\";\nimport { composeFoldResult } from \"./compose.ts\";\nimport type { ReadFolder, ReadFolderInput, ReadFolderResult } from \"./types.ts\";\n\nexport * from \"./types.ts\";\n\n/** Frozen measured selection, not a runtime registry that can enable unmeasured grammars. */\nexport const READ_FOLDER_SELECTION = Object.freeze({\n\thead: \"ec63eb5ee999da83b9e5d3e37b83d1998707f44c\",\n\tselectionSha256: \"07388b6a393cc05c78533fa701d536d5e617a38e2293b10c0a281a55395cc8a3\",\n\twasm: true,\n\trawReasons: Object.freeze({\n\t\tts: \"wasm_candidate_below_threshold\",\n\t\ttsx: \"wasm_candidate_below_threshold\",\n\t} as const),\n\tlanguages: Object.freeze({\n\t\tts: \"raw\",\n\t\tjs: \"wasm\",\n\t\tjson: \"heuristic\",\n\t\ttsx: \"raw\",\n\t\tpython: \"unsupported\",\n\t\trust: \"unsupported\",\n\t\tgo: \"unsupported\",\n\t\tmarkdown: \"prose_exempt\",\n\t\ttxt: \"prose_exempt\",\n\t} as const),\n} as const);\n\nexport type ReadSummaryLanguage = keyof typeof READ_FOLDER_SELECTION.languages;\n/** Every engine a frozen selection may name, independent of which ones the current receipt uses. */\nexport type ReadSummaryEngine = \"raw\" | \"heuristic\" | \"wasm\" | \"unsupported\" | \"prose_exempt\";\nexport function languageForPath(path: string): ReadSummaryLanguage | undefined {\n\tconst name = path.split(/[\\\\/]/).pop()?.toLowerCase() ?? \"\";\n\tif (!name.includes(\".\")) return undefined;\n\tswitch (name.slice(name.lastIndexOf(\".\") + 1)) {\n\t\tcase \"ts\":\n\t\t\treturn \"ts\";\n\t\tcase \"js\":\n\t\t\treturn \"js\";\n\t\tcase \"json\":\n\t\t\treturn \"json\";\n\t\tcase \"tsx\":\n\t\t\treturn \"tsx\";\n\t\tcase \"py\":\n\t\t\treturn \"python\";\n\t\tcase \"rs\":\n\t\t\treturn \"rust\";\n\t\tcase \"go\":\n\t\t\treturn \"go\";\n\t\tcase \"md\":\n\t\tcase \"markdown\":\n\t\tcase \"mdown\":\n\t\tcase \"mkd\":\n\t\tcase \"mkdn\":\n\t\t\treturn \"markdown\";\n\t\tcase \"txt\":\n\t\t\treturn \"txt\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/** The frozen engine for a path's language, independent of which folder object a caller supplies. */\nexport function readSummaryEngineForPath(path: string): ReadSummaryEngine | undefined {\n\tconst language = languageForPath(path);\n\tif (language === undefined) return undefined;\n\tconst engine: ReadSummaryEngine = READ_FOLDER_SELECTION.languages[language];\n\treturn engine;\n}\n\n/** Reader eligibility stays bound to the frozen selection even with a custom folder. */\nexport function isReadSummaryPath(path: string): boolean {\n\tconst engine = readSummaryEngineForPath(path);\n\treturn engine === \"heuristic\" || engine === \"wasm\";\n}\n\nfunction fold({ path, text, settings }: ReadFolderInput): ReadFolderResult {\n\tconst language = languageForPath(path);\n\tif (!language) return { status: \"unsupported\", reason: \"unsupported_language\" };\n\tconst engine: ReadSummaryEngine = READ_FOLDER_SELECTION.languages[language];\n\tswitch (engine) {\n\t\tcase \"unsupported\":\n\t\t\treturn { status: \"unsupported\", reason: \"unsupported_language\" };\n\t\tcase \"prose_exempt\":\n\t\t\treturn { status: \"unsupported\", reason: \"prose_exempt\" };\n\t\tcase \"raw\": // Retain the pure candidate for safety/quality measurement, never default-read eligibility.\n\t\tcase \"heuristic\":\n\t\tcase \"wasm\": // The heuristic scan is the tree-sitter engine's fallback, so it stays callable here.\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn engine satisfies never;\n\t}\n\t// Narrow the language independently: the manifest is the sole enablement authority.\n\tif (language !== \"ts\" && language !== \"js\" && language !== \"json\")\n\t\treturn { status: \"unsupported\", reason: \"unsupported_language\" };\n\tif (language === \"json\") {\n\t\ttry {\n\t\t\tJSON.parse(text);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) return { status: \"parse_failure\", reason: \"invalid_json\" };\n\t\t\tthrow error;\n\t\t}\n\t}\n\treturn composeFoldResult(text, scanBraces(text, language, settings));\n}\n\nexport const selectedReadFolder: ReadFolder = Object.freeze({ id: \"measured-brace\", version: \"3\", fold });\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TreeSitterFolderOptions } from "./tree-sitter/engine.ts";
|
|
2
|
+
import type { ReadFolder } from "./types.ts";
|
|
3
|
+
export type PrepareReadFolderOptions = Omit<TreeSitterFolderOptions, "fallback">;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the folder a default read must use for this path. Only a language the frozen selection
|
|
6
|
+
* binds to `wasm` loads a grammar, lazily and once; every other language keeps the folder it was
|
|
7
|
+
* given, and a grammar that is absent or unusable keeps it too. A caller that supplies its own
|
|
8
|
+
* folder keeps exactly that folder: the selection decides eligibility, never someone else's engine.
|
|
9
|
+
*/
|
|
10
|
+
export declare function prepareReadFolder(path: string, folder: ReadFolder | undefined, options?: PrepareReadFolderOptions): Promise<ReadFolder | undefined>;
|
|
11
|
+
//# sourceMappingURL=prepare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/prepare.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAC;AAEjF;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,OAAO,GAAE,wBAA6B,GACpC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAUjC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { languageForPath, readSummaryEngineForPath, selectedReadFolder } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the folder a default read must use for this path. Only a language the frozen selection
|
|
4
|
+
* binds to `wasm` loads a grammar, lazily and once; every other language keeps the folder it was
|
|
5
|
+
* given, and a grammar that is absent or unusable keeps it too. A caller that supplies its own
|
|
6
|
+
* folder keeps exactly that folder: the selection decides eligibility, never someone else's engine.
|
|
7
|
+
*/
|
|
8
|
+
export async function prepareReadFolder(path, folder, options = {}) {
|
|
9
|
+
if (!folder || folder !== selectedReadFolder)
|
|
10
|
+
return folder;
|
|
11
|
+
const language = languageForPath(path);
|
|
12
|
+
if (!language || readSummaryEngineForPath(path) !== "wasm")
|
|
13
|
+
return folder;
|
|
14
|
+
try {
|
|
15
|
+
const { loadTreeSitterFolder } = await import("./tree-sitter/engine.js");
|
|
16
|
+
return (await loadTreeSitterFolder(language, { ...options, fallback: folder })) ?? folder;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return folder;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=prepare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../../../src/harness/utils/read-folders/prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAO3F;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,IAAY,EACZ,MAA8B,EAC9B,OAAO,GAA6B,EAAE;IAEtC,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,kBAAkB;QAAE,OAAO,MAAM,CAAC;IAC5D,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,CAAC,QAAQ,IAAI,wBAAwB,CAAC,IAAI,CAAC,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1E,IAAI,CAAC;QACJ,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAC;QACzE,OAAO,CAAC,MAAM,oBAAoB,CAAC,QAA8B,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC;IACjH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC","sourcesContent":["import { languageForPath, readSummaryEngineForPath, selectedReadFolder } from \"./index.ts\";\nimport type { TreeSitterFolderOptions } from \"./tree-sitter/engine.ts\";\nimport type { TreeSitterLanguage } from \"./tree-sitter/syntax.ts\";\nimport type { ReadFolder } from \"./types.ts\";\n\nexport type PrepareReadFolderOptions = Omit<TreeSitterFolderOptions, \"fallback\">;\n\n/**\n * Resolve the folder a default read must use for this path. Only a language the frozen selection\n * binds to `wasm` loads a grammar, lazily and once; every other language keeps the folder it was\n * given, and a grammar that is absent or unusable keeps it too. A caller that supplies its own\n * folder keeps exactly that folder: the selection decides eligibility, never someone else's engine.\n */\nexport async function prepareReadFolder(\n\tpath: string,\n\tfolder: ReadFolder | undefined,\n\toptions: PrepareReadFolderOptions = {},\n): Promise<ReadFolder | undefined> {\n\tif (!folder || folder !== selectedReadFolder) return folder;\n\tconst language = languageForPath(path);\n\tif (!language || readSummaryEngineForPath(path) !== \"wasm\") return folder;\n\ttry {\n\t\tconst { loadTreeSitterFolder } = await import(\"./tree-sitter/engine.ts\");\n\t\treturn (await loadTreeSitterFolder(language as TreeSitterLanguage, { ...options, fallback: folder })) ?? folder;\n\t} catch {\n\t\treturn folder;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReadFolder } from "../types.ts";
|
|
2
|
+
import { type GrammarResolver } from "./grammar-assets.ts";
|
|
3
|
+
import { type TreeSitterLanguage } from "./syntax.ts";
|
|
4
|
+
/** A structural read must never outlast this budget: an exhausted parse falls back, it does not stall. */
|
|
5
|
+
export declare const TREE_SITTER_PARSE_BUDGET_MS = 250;
|
|
6
|
+
export declare const TREE_SITTER_FOLDER_ID = "tree-sitter-wasm";
|
|
7
|
+
export declare const TREE_SITTER_FOLDER_VERSION = "1";
|
|
8
|
+
export type TreeSitterFolderOptions = {
|
|
9
|
+
/** Used verbatim when a grammar is absent, the parse fails or the budget is exhausted. */
|
|
10
|
+
readonly fallback: ReadFolder;
|
|
11
|
+
readonly parseBudgetMs?: number;
|
|
12
|
+
readonly resolveGrammar?: GrammarResolver;
|
|
13
|
+
readonly resolveRuntime?: () => Promise<string | undefined>;
|
|
14
|
+
/** Off for tests that inject resolvers; the shipped read path always shares one loaded grammar. */
|
|
15
|
+
readonly cache?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Load the grammar for one language and return a folder that produces the same fold-boundary
|
|
19
|
+
* output the heuristic produces, with the heuristic itself as the fallback. Grammars load lazily,
|
|
20
|
+
* on the first structural read for their language.
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadTreeSitterFolder(language: TreeSitterLanguage, options: TreeSitterFolderOptions): Promise<ReadFolder | undefined>;
|
|
23
|
+
/** Test seam: drop the memoized runtime/grammars so a resolver change is observable. */
|
|
24
|
+
export declare function resetTreeSitterGrammars(): void;
|
|
25
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../../../src/harness/utils/read-folders/tree-sitter/engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAqC,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,KAAK,eAAe,EAA0C,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAyC,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE7F,0GAA0G;AAC1G,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAC/C,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AACxD,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,MAAM,MAAM,uBAAuB,GAAG;IACrC,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC;IAC1C,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC5D,mGAAmG;IACnG,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAoEF;;;;GAIG;AACH,wBAAsB,oBAAoB,CACzC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAiBjC;AAED,wFAAwF;AACxF,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { composeFoldResult } from "../compose.js";
|
|
2
|
+
import { resolveGrammarPath, resolveRuntimePath } from "./grammar-assets.js";
|
|
3
|
+
import { foldRangesFromSyntax } from "./syntax.js";
|
|
4
|
+
/** A structural read must never outlast this budget: an exhausted parse falls back, it does not stall. */
|
|
5
|
+
export const TREE_SITTER_PARSE_BUDGET_MS = 250;
|
|
6
|
+
export const TREE_SITTER_FOLDER_ID = "tree-sitter-wasm";
|
|
7
|
+
export const TREE_SITTER_FOLDER_VERSION = "1";
|
|
8
|
+
let runtime;
|
|
9
|
+
const grammars = new Map();
|
|
10
|
+
async function loadRuntime(resolveRuntime) {
|
|
11
|
+
try {
|
|
12
|
+
const module = await import("web-tree-sitter");
|
|
13
|
+
const wasm = await resolveRuntime();
|
|
14
|
+
await module.Parser.init(wasm ? { locateFile: () => wasm } : undefined);
|
|
15
|
+
return module;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function loadParser(language, options) {
|
|
22
|
+
const resolveGrammar = options.resolveGrammar ?? resolveGrammarPath;
|
|
23
|
+
const resolveRuntime = options.resolveRuntime ?? resolveRuntimePath;
|
|
24
|
+
const grammar = await resolveGrammar(language);
|
|
25
|
+
if (!grammar)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (options.cache === false) {
|
|
28
|
+
const module = await loadRuntime(resolveRuntime);
|
|
29
|
+
return module && instantiate(module, grammar, language);
|
|
30
|
+
}
|
|
31
|
+
runtime ??= loadRuntime(resolveRuntime);
|
|
32
|
+
const module = await runtime;
|
|
33
|
+
return module && instantiate(module, grammar, language);
|
|
34
|
+
}
|
|
35
|
+
async function instantiate(module, grammar, language) {
|
|
36
|
+
try {
|
|
37
|
+
const loaded = await module.Language.load(grammar);
|
|
38
|
+
const parser = new module.Parser();
|
|
39
|
+
parser.setLanguage(loaded);
|
|
40
|
+
return { parser, language };
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function foldWith(loaded, budgetMs, input, fallback) {
|
|
47
|
+
const deadline = performance.now() + budgetMs;
|
|
48
|
+
let tree = null;
|
|
49
|
+
try {
|
|
50
|
+
tree = loaded.parser.parse(input.text, null, { progressCallback: () => performance.now() > deadline });
|
|
51
|
+
if (!tree)
|
|
52
|
+
return fallback.fold(input);
|
|
53
|
+
const scan = foldRangesFromSyntax(tree.rootNode, input.settings);
|
|
54
|
+
if (scan.status === "parse_failure")
|
|
55
|
+
return fallback.fold(input);
|
|
56
|
+
return composeFoldResult(input.text, scan);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// A grammar/runtime fault is a fallback condition, never a failed read.
|
|
60
|
+
return fallback.fold(input);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
tree?.delete();
|
|
64
|
+
// Parsing resumes mid-document after a cancelled parse unless the parser is reset.
|
|
65
|
+
loaded.parser.reset();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Load the grammar for one language and return a folder that produces the same fold-boundary
|
|
70
|
+
* output the heuristic produces, with the heuristic itself as the fallback. Grammars load lazily,
|
|
71
|
+
* on the first structural read for their language.
|
|
72
|
+
*/
|
|
73
|
+
export async function loadTreeSitterFolder(language, options) {
|
|
74
|
+
const load = () => loadParser(language, options);
|
|
75
|
+
const loaded = await (options.cache === false
|
|
76
|
+
? load()
|
|
77
|
+
: (grammars.get(language) ??
|
|
78
|
+
(() => {
|
|
79
|
+
const pending = load();
|
|
80
|
+
grammars.set(language, pending);
|
|
81
|
+
return pending;
|
|
82
|
+
})()));
|
|
83
|
+
if (!loaded)
|
|
84
|
+
return undefined;
|
|
85
|
+
const budgetMs = options.parseBudgetMs ?? TREE_SITTER_PARSE_BUDGET_MS;
|
|
86
|
+
return Object.freeze({
|
|
87
|
+
id: TREE_SITTER_FOLDER_ID,
|
|
88
|
+
version: TREE_SITTER_FOLDER_VERSION,
|
|
89
|
+
fold: (input) => foldWith(loaded, budgetMs, input, options.fallback),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** Test seam: drop the memoized runtime/grammars so a resolver change is observable. */
|
|
93
|
+
export function resetTreeSitterGrammars() {
|
|
94
|
+
runtime = undefined;
|
|
95
|
+
grammars.clear();
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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A0B;QACnC,IAAI,EAAE,CAAC,KAAsB,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC;KACrF,CAAC,CAAC;AACJ,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,uBAAuB;IACtC,OAAO,GAAG,SAAS,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { Language, Parser as ParserType } from \"web-tree-sitter\";\nimport { composeFoldResult } from \"../compose.ts\";\nimport type { ReadFolder, ReadFolderInput, ReadFolderResult } from \"../types.ts\";\nimport { type GrammarResolver, resolveGrammarPath, resolveRuntimePath } from \"./grammar-assets.ts\";\nimport { foldRangesFromSyntax, type SyntaxNode, type TreeSitterLanguage } from \"./syntax.ts\";\n\n/** A structural read must never outlast this budget: an exhausted parse falls back, it does not stall. */\nexport const TREE_SITTER_PARSE_BUDGET_MS = 250;\nexport const TREE_SITTER_FOLDER_ID = \"tree-sitter-wasm\";\nexport const TREE_SITTER_FOLDER_VERSION = \"1\";\n\nexport type TreeSitterFolderOptions = {\n\t/** Used verbatim when a grammar is absent, the parse fails or the budget is exhausted. */\n\treadonly fallback: ReadFolder;\n\treadonly parseBudgetMs?: number;\n\treadonly resolveGrammar?: GrammarResolver;\n\treadonly resolveRuntime?: () => Promise<string | undefined>;\n\t/** Off for tests that inject resolvers; the shipped read path always shares one loaded grammar. */\n\treadonly cache?: boolean;\n};\n\ntype Loaded = { readonly parser: ParserType; readonly language: TreeSitterLanguage };\n\nlet runtime: Promise<typeof import(\"web-tree-sitter\") | undefined> | undefined;\nconst grammars = new Map<TreeSitterLanguage, Promise<Loaded | undefined>>();\n\nasync function loadRuntime(\n\tresolveRuntime: () => Promise<string | undefined>,\n): Promise<typeof import(\"web-tree-sitter\") | undefined> {\n\ttry {\n\t\tconst module = await import(\"web-tree-sitter\");\n\t\tconst wasm = await resolveRuntime();\n\t\tawait module.Parser.init(wasm ? { locateFile: () => wasm } : undefined);\n\t\treturn module;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function loadParser(language: TreeSitterLanguage, options: TreeSitterFolderOptions): Promise<Loaded | undefined> {\n\tconst resolveGrammar = options.resolveGrammar ?? resolveGrammarPath;\n\tconst resolveRuntime = options.resolveRuntime ?? resolveRuntimePath;\n\tconst grammar = await resolveGrammar(language);\n\tif (!grammar) return undefined;\n\tif (options.cache === false) {\n\t\tconst module = await loadRuntime(resolveRuntime);\n\t\treturn module && instantiate(module, grammar, language);\n\t}\n\truntime ??= loadRuntime(resolveRuntime);\n\tconst module = await runtime;\n\treturn module && instantiate(module, grammar, language);\n}\n\nasync function instantiate(\n\tmodule: typeof import(\"web-tree-sitter\"),\n\tgrammar: string,\n\tlanguage: TreeSitterLanguage,\n): Promise<Loaded | undefined> {\n\ttry {\n\t\tconst loaded: Language = await module.Language.load(grammar);\n\t\tconst parser = new module.Parser();\n\t\tparser.setLanguage(loaded);\n\t\treturn { parser, language };\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction foldWith(loaded: Loaded, budgetMs: number, input: ReadFolderInput, fallback: ReadFolder): ReadFolderResult {\n\tconst deadline = performance.now() + budgetMs;\n\tlet tree: ReturnType<ParserType[\"parse\"]> = null;\n\ttry {\n\t\ttree = loaded.parser.parse(input.text, null, { progressCallback: () => performance.now() > deadline });\n\t\tif (!tree) return fallback.fold(input);\n\t\tconst scan = foldRangesFromSyntax(tree.rootNode as unknown as SyntaxNode, input.settings);\n\t\tif (scan.status === \"parse_failure\") return fallback.fold(input);\n\t\treturn composeFoldResult(input.text, scan);\n\t} catch {\n\t\t// A grammar/runtime fault is a fallback condition, never a failed read.\n\t\treturn fallback.fold(input);\n\t} finally {\n\t\ttree?.delete();\n\t\t// Parsing resumes mid-document after a cancelled parse unless the parser is reset.\n\t\tloaded.parser.reset();\n\t}\n}\n\n/**\n * Load the grammar for one language and return a folder that produces the same fold-boundary\n * output the heuristic produces, with the heuristic itself as the fallback. Grammars load lazily,\n * on the first structural read for their language.\n */\nexport async function loadTreeSitterFolder(\n\tlanguage: TreeSitterLanguage,\n\toptions: TreeSitterFolderOptions,\n): Promise<ReadFolder | undefined> {\n\tconst load = () => loadParser(language, options);\n\tconst loaded = await (options.cache === false\n\t\t? load()\n\t\t: (grammars.get(language) ??\n\t\t\t(() => {\n\t\t\t\tconst pending = load();\n\t\t\t\tgrammars.set(language, pending);\n\t\t\t\treturn pending;\n\t\t\t})()));\n\tif (!loaded) return undefined;\n\tconst budgetMs = options.parseBudgetMs ?? TREE_SITTER_PARSE_BUDGET_MS;\n\treturn Object.freeze({\n\t\tid: TREE_SITTER_FOLDER_ID,\n\t\tversion: TREE_SITTER_FOLDER_VERSION,\n\t\tfold: (input: ReadFolderInput) => foldWith(loaded, budgetMs, input, options.fallback),\n\t});\n}\n\n/** Test seam: drop the memoized runtime/grammars so a resolver change is observable. */\nexport function resetTreeSitterGrammars(): void {\n\truntime = undefined;\n\tgrammars.clear();\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TreeSitterLanguage } from "./syntax.ts";
|
|
2
|
+
/** Vendored grammar file names, resolved identically from `src`, published `dist` and the compiled binary. */
|
|
3
|
+
export declare const GRAMMAR_FILES: Readonly<{
|
|
4
|
+
readonly ts: "typescript.wasm";
|
|
5
|
+
readonly tsx: "tsx.wasm";
|
|
6
|
+
readonly js: "javascript.wasm";
|
|
7
|
+
}>;
|
|
8
|
+
export declare const TREE_SITTER_RUNTIME_FILE = "web-tree-sitter.wasm";
|
|
9
|
+
/** `src/harness/utils/read-folders/tree-sitter` and `dist/harness/utils/read-folders/tree-sitter` share this depth. */
|
|
10
|
+
export declare const packagedAssetDirectory: string;
|
|
11
|
+
export type GrammarResolver = (language: TreeSitterLanguage) => Promise<string | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Packaged grammars ship with the package and the compiled binary; the pinned measurement
|
|
14
|
+
* dependency only backs languages that are evaluated but not shipped. A missing grammar is a
|
|
15
|
+
* normal outcome: the caller keeps the heuristic folder.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveGrammarPath(language: TreeSitterLanguage): Promise<string | undefined>;
|
|
18
|
+
/** The emscripten runtime module the grammars are instantiated against. */
|
|
19
|
+
export declare function resolveRuntimePath(): Promise<string | undefined>;
|
|
20
|
+
//# sourceMappingURL=grammar-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar-assets.d.ts","sourceRoot":"","sources":["../../../../../src/harness/utils/read-folders/tree-sitter/grammar-assets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,8GAA8G;AAC9G,eAAO,MAAM,aAAa;iBACrB,iBAAiB;kBAChB,UAAU;iBACX,iBAAiB;EACkC,CAAC;AASzD,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,uHAAuH;AACvH,eAAO,MAAM,sBAAsB,QAAgF,CAAC;AA+BpH,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,kBAAkB,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAE5F;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAOlG;AAED,2EAA2E;AAC3E,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAItE"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
/** Vendored grammar file names, resolved identically from `src`, published `dist` and the compiled binary. */
|
|
6
|
+
export const GRAMMAR_FILES = Object.freeze({
|
|
7
|
+
ts: "typescript.wasm",
|
|
8
|
+
tsx: "tsx.wasm",
|
|
9
|
+
js: "javascript.wasm",
|
|
10
|
+
});
|
|
11
|
+
/** Upstream grammar file names inside the pinned measurement dependency. */
|
|
12
|
+
const UPSTREAM_FILES = Object.freeze({
|
|
13
|
+
ts: "tree-sitter-typescript.wasm",
|
|
14
|
+
tsx: "tree-sitter-tsx.wasm",
|
|
15
|
+
js: "tree-sitter-javascript.wasm",
|
|
16
|
+
});
|
|
17
|
+
export const TREE_SITTER_RUNTIME_FILE = "web-tree-sitter.wasm";
|
|
18
|
+
/** `src/harness/utils/read-folders/tree-sitter` and `dist/harness/utils/read-folders/tree-sitter` share this depth. */
|
|
19
|
+
export const packagedAssetDirectory = fileURLToPath(new URL("../../../../../assets/tree-sitter/", import.meta.url));
|
|
20
|
+
/**
|
|
21
|
+
* Bun's compiler embeds a literal `type: "file"` import and hands back an extracted path.
|
|
22
|
+
* Only shipped grammars may appear here: every specifier must resolve at compile time.
|
|
23
|
+
*/
|
|
24
|
+
const embeddedGrammars = {
|
|
25
|
+
js: () => import("../../../../../assets/tree-sitter/javascript.wasm", { with: { type: "file" } }),
|
|
26
|
+
};
|
|
27
|
+
const embeddedRuntime = () => import("../../../../../assets/tree-sitter/web-tree-sitter.wasm", { with: { type: "file" } });
|
|
28
|
+
async function embeddedPath(load) {
|
|
29
|
+
if (!load || !process.versions.bun)
|
|
30
|
+
return undefined;
|
|
31
|
+
try {
|
|
32
|
+
const module = await load();
|
|
33
|
+
return existsSync(module.default) ? module.default : undefined;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function installedPath(specifier) {
|
|
40
|
+
try {
|
|
41
|
+
const path = createRequire(import.meta.url).resolve(specifier);
|
|
42
|
+
return existsSync(path) ? path : undefined;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Packaged grammars ship with the package and the compiled binary; the pinned measurement
|
|
50
|
+
* dependency only backs languages that are evaluated but not shipped. A missing grammar is a
|
|
51
|
+
* normal outcome: the caller keeps the heuristic folder.
|
|
52
|
+
*/
|
|
53
|
+
export async function resolveGrammarPath(language) {
|
|
54
|
+
const packaged = join(packagedAssetDirectory, GRAMMAR_FILES[language]);
|
|
55
|
+
if (existsSync(packaged))
|
|
56
|
+
return packaged;
|
|
57
|
+
return ((await embeddedPath(embeddedGrammars[language])) ??
|
|
58
|
+
installedPath(`@vscode/tree-sitter-wasm/wasm/${UPSTREAM_FILES[language]}`));
|
|
59
|
+
}
|
|
60
|
+
/** The emscripten runtime module the grammars are instantiated against. */
|
|
61
|
+
export async function resolveRuntimePath() {
|
|
62
|
+
const packaged = join(packagedAssetDirectory, TREE_SITTER_RUNTIME_FILE);
|
|
63
|
+
if (existsSync(packaged))
|
|
64
|
+
return packaged;
|
|
65
|
+
return (await embeddedPath(embeddedRuntime)) ?? installedPath("web-tree-sitter/web-tree-sitter.wasm");
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=grammar-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar-assets.js","sourceRoot":"","sources":["../../../../../src/harness/utils/read-folders/tree-sitter/grammar-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,8GAA8G;AAC9G,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,EAAE,EAAE,iBAAiB;IACrB,GAAG,EAAE,UAAU;IACf,EAAE,EAAE,iBAAiB;CACiC,CAAC,CAAC;AAEzD,4EAA4E;AAC5E,MAAM,cAAc,GAAG,MAAM,C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,CAAC,SAAS,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAID;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,QAA4B;IACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,IAAI,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1C,OAAO,CACN,CAAC,MAAM,YAAY,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAChD,aAAa,CAAC,iCAAiC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAC1E,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,EAAE,wBAAwB,CAAC,CAAC;IACxE,IAAI,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1C,OAAO,CAAC,MAAM,YAAY,CAAC,eAAe,CAAC,CAAC,IAAI,aAAa,CAAC,sCAAsC,CAAC,CAAC;AACvG,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { TreeSitterLanguage } from \"./syntax.ts\";\n\n/** Vendored grammar file names, resolved identically from `src`, published `dist` and the compiled binary. */\nexport const GRAMMAR_FILES = Object.freeze({\n\tts: \"typescript.wasm\",\n\ttsx: \"tsx.wasm\",\n\tjs: \"javascript.wasm\",\n} as const satisfies Record<TreeSitterLanguage, string>);\n\n/** Upstream grammar file names inside the pinned measurement dependency. */\nconst UPSTREAM_FILES = Object.freeze({\n\tts: \"tree-sitter-typescript.wasm\",\n\ttsx: \"tree-sitter-tsx.wasm\",\n\tjs: \"tree-sitter-javascript.wasm\",\n} as const satisfies Record<TreeSitterLanguage, string>);\n\nexport const TREE_SITTER_RUNTIME_FILE = \"web-tree-sitter.wasm\";\n\n/** `src/harness/utils/read-folders/tree-sitter` and `dist/harness/utils/read-folders/tree-sitter` share this depth. */\nexport const packagedAssetDirectory = fileURLToPath(new URL(\"../../../../../assets/tree-sitter/\", import.meta.url));\n\n/**\n * Bun's compiler embeds a literal `type: \"file\"` import and hands back an extracted path.\n * Only shipped grammars may appear here: every specifier must resolve at compile time.\n */\nconst embeddedGrammars: Partial<Record<TreeSitterLanguage, () => Promise<{ default: string }>>> = {\n\tjs: () => import(\"../../../../../assets/tree-sitter/javascript.wasm\", { with: { type: \"file\" } }),\n};\nconst embeddedRuntime = () =>\n\timport(\"../../../../../assets/tree-sitter/web-tree-sitter.wasm\", { with: { type: \"file\" } });\n\nasync function embeddedPath(load: (() => Promise<{ default: string }>) | undefined): Promise<string | undefined> {\n\tif (!load || !process.versions.bun) return undefined;\n\ttry {\n\t\tconst module = await load();\n\t\treturn existsSync(module.default) ? module.default : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction installedPath(specifier: string): string | undefined {\n\ttry {\n\t\tconst path = createRequire(import.meta.url).resolve(specifier);\n\t\treturn existsSync(path) ? path : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport type GrammarResolver = (language: TreeSitterLanguage) => Promise<string | undefined>;\n\n/**\n * Packaged grammars ship with the package and the compiled binary; the pinned measurement\n * dependency only backs languages that are evaluated but not shipped. A missing grammar is a\n * normal outcome: the caller keeps the heuristic folder.\n */\nexport async function resolveGrammarPath(language: TreeSitterLanguage): Promise<string | undefined> {\n\tconst packaged = join(packagedAssetDirectory, GRAMMAR_FILES[language]);\n\tif (existsSync(packaged)) return packaged;\n\treturn (\n\t\t(await embeddedPath(embeddedGrammars[language])) ??\n\t\tinstalledPath(`@vscode/tree-sitter-wasm/wasm/${UPSTREAM_FILES[language]}`)\n\t);\n}\n\n/** The emscripten runtime module the grammars are instantiated against. */\nexport async function resolveRuntimePath(): Promise<string | undefined> {\n\tconst packaged = join(packagedAssetDirectory, TREE_SITTER_RUNTIME_FILE);\n\tif (existsSync(packaged)) return packaged;\n\treturn (await embeddedPath(embeddedRuntime)) ?? installedPath(\"web-tree-sitter/web-tree-sitter.wasm\");\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReadBraceScan, ReadFoldSettings } from "../types.ts";
|
|
2
|
+
/** Structural subset of a web-tree-sitter node: the fold rule stays pure and grammar-runtime free. */
|
|
3
|
+
export interface SyntaxNode {
|
|
4
|
+
readonly id: number;
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly startPosition: {
|
|
8
|
+
readonly row: number;
|
|
9
|
+
};
|
|
10
|
+
readonly endPosition: {
|
|
11
|
+
readonly row: number;
|
|
12
|
+
};
|
|
13
|
+
readonly children: readonly (SyntaxNode | null)[];
|
|
14
|
+
readonly hasError: boolean;
|
|
15
|
+
readonly isMissing: boolean;
|
|
16
|
+
childForFieldName(field: string): SyntaxNode | null;
|
|
17
|
+
}
|
|
18
|
+
export type TreeSitterLanguage = "ts" | "tsx" | "js";
|
|
19
|
+
/**
|
|
20
|
+
* Fold boundaries from a parsed syntax tree, produced under the same rules the compiler oracle
|
|
21
|
+
* uses to annotate safe interiors: value containers only, never a line of a declaration header.
|
|
22
|
+
*/
|
|
23
|
+
export declare function foldRangesFromSyntax(root: SyntaxNode, settings: ReadFoldSettings): ReadBraceScan;
|
|
24
|
+
//# sourceMappingURL=syntax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../../../../../src/harness/utils/read-folders/tree-sitter/syntax.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAiB,MAAM,aAAa,CAAC;AAElF,sGAAsG;AACtG,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,QAAQ,CAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC;IAClD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;CACpD;AAED,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;AA8FrD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,GAAG,aAAa,CA4EhG"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/** Implementation/value containers, mirroring the compiler oracle's whitelist. Class bodies are excluded. */
|
|
2
|
+
const bodyKinds = new Set(["statement_block", "object", "array", "switch_body"]);
|
|
3
|
+
const functionKinds = new Set([
|
|
4
|
+
"function_declaration",
|
|
5
|
+
"function_expression",
|
|
6
|
+
"function",
|
|
7
|
+
"generator_function",
|
|
8
|
+
"generator_function_declaration",
|
|
9
|
+
"arrow_function",
|
|
10
|
+
"method_definition",
|
|
11
|
+
"function_signature",
|
|
12
|
+
"method_signature",
|
|
13
|
+
"abstract_method_signature",
|
|
14
|
+
]);
|
|
15
|
+
const classKinds = new Set(["class", "class_declaration", "abstract_class_declaration"]);
|
|
16
|
+
/** Header material: a fold overlapping any of these lines is rejected, exactly as the oracle rejects it. */
|
|
17
|
+
const opaqueKinds = new Set([
|
|
18
|
+
"type_annotation",
|
|
19
|
+
"type_arguments",
|
|
20
|
+
"type_parameters",
|
|
21
|
+
"type_alias_declaration",
|
|
22
|
+
"interface_declaration",
|
|
23
|
+
"type_predicate_annotation",
|
|
24
|
+
"omitting_type_annotation",
|
|
25
|
+
"opting_type_annotation",
|
|
26
|
+
"asserts_annotation",
|
|
27
|
+
"type_identifier",
|
|
28
|
+
"predefined_type",
|
|
29
|
+
"nested_type_identifier",
|
|
30
|
+
"formal_parameters",
|
|
31
|
+
"class_heritage",
|
|
32
|
+
"extends_clause",
|
|
33
|
+
"extends_type_clause",
|
|
34
|
+
"implements_clause",
|
|
35
|
+
"decorator",
|
|
36
|
+
"import_statement",
|
|
37
|
+
"object_pattern",
|
|
38
|
+
"array_pattern",
|
|
39
|
+
"computed_property_name",
|
|
40
|
+
"ambient_declaration",
|
|
41
|
+
]);
|
|
42
|
+
function isOpaque(node) {
|
|
43
|
+
return opaqueKinds.has(node.type) || node.type.endsWith("_type") || node.type.endsWith("_type_annotation");
|
|
44
|
+
}
|
|
45
|
+
function childNodes(node) {
|
|
46
|
+
const children = [];
|
|
47
|
+
for (const child of node.children)
|
|
48
|
+
if (child)
|
|
49
|
+
children.push(child);
|
|
50
|
+
return children;
|
|
51
|
+
}
|
|
52
|
+
function openBrace(node) {
|
|
53
|
+
for (const child of childNodes(node))
|
|
54
|
+
if (child.type === "{" || child.type === "[")
|
|
55
|
+
return child;
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function closeBrace(node) {
|
|
59
|
+
const children = childNodes(node);
|
|
60
|
+
for (let index = children.length - 1; index >= 0; index--) {
|
|
61
|
+
const child = children[index];
|
|
62
|
+
if (child.type === "}" || child.type === "]")
|
|
63
|
+
return child;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
function exportsOnlyBindings(node) {
|
|
68
|
+
// `export { a } from "b"` / `export * from "b"` is a declaration header; `export const x = {}` is not.
|
|
69
|
+
for (const child of childNodes(node))
|
|
70
|
+
if (child.type === "export_clause" || child.type === "*" || child.type === "namespace_export")
|
|
71
|
+
return true;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
/** `x as const` / `x satisfies T`: everything from the operator on is type material. */
|
|
75
|
+
function typeOperator(node) {
|
|
76
|
+
if (node.type !== "as_expression" && node.type !== "satisfies_expression")
|
|
77
|
+
return undefined;
|
|
78
|
+
return childNodes(node).find((child) => child.type === "as" || child.type === "satisfies");
|
|
79
|
+
}
|
|
80
|
+
function assignmentTarget(node) {
|
|
81
|
+
if (node.type !== "assignment_expression" && node.type !== "for_in_statement")
|
|
82
|
+
return undefined;
|
|
83
|
+
const left = node.childForFieldName("left");
|
|
84
|
+
if (!left)
|
|
85
|
+
return undefined;
|
|
86
|
+
let target = left;
|
|
87
|
+
while (target.type === "parenthesized_expression") {
|
|
88
|
+
const inner = childNodes(target).find((child) => child.type !== "(" && child.type !== ")");
|
|
89
|
+
if (!inner)
|
|
90
|
+
break;
|
|
91
|
+
target = inner;
|
|
92
|
+
}
|
|
93
|
+
return target.type === "object" || target.type === "array" ? left : undefined;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Fold boundaries from a parsed syntax tree, produced under the same rules the compiler oracle
|
|
97
|
+
* uses to annotate safe interiors: value containers only, never a line of a declaration header.
|
|
98
|
+
*/
|
|
99
|
+
export function foldRangesFromSyntax(root, settings) {
|
|
100
|
+
if (root.hasError || root.isMissing)
|
|
101
|
+
return { status: "parse_failure", reason: "tree_sitter_parse_error" };
|
|
102
|
+
const candidates = [];
|
|
103
|
+
const guarded = [];
|
|
104
|
+
const protect = (startLine, endLine) => {
|
|
105
|
+
if (endLine >= startLine)
|
|
106
|
+
guarded.push({ startLine, endLine });
|
|
107
|
+
};
|
|
108
|
+
const line = (row) => row + 1;
|
|
109
|
+
const visit = (node) => {
|
|
110
|
+
if (isOpaque(node) || (node.type === "export_statement" && exportsOnlyBindings(node))) {
|
|
111
|
+
protect(line(node.startPosition.row), line(node.endPosition.row));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (node.type === "comment") {
|
|
115
|
+
const lines = node.endPosition.row - node.startPosition.row + 1;
|
|
116
|
+
if (node.text.startsWith("/**") || node.text.startsWith("/*!"))
|
|
117
|
+
protect(line(node.startPosition.row), line(node.endPosition.row));
|
|
118
|
+
else if (lines >= settings.minCommentLines)
|
|
119
|
+
candidates.push({ startLine: line(node.startPosition.row) + 1, endLine: line(node.endPosition.row) - 1 });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const operator = typeOperator(node);
|
|
123
|
+
if (operator) {
|
|
124
|
+
protect(line(operator.startPosition.row), line(node.endPosition.row));
|
|
125
|
+
for (const child of childNodes(node)) {
|
|
126
|
+
if (child.id === operator.id)
|
|
127
|
+
break;
|
|
128
|
+
visit(child);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const target = assignmentTarget(node);
|
|
133
|
+
if (target) {
|
|
134
|
+
protect(line(target.startPosition.row), line(target.endPosition.row));
|
|
135
|
+
for (const child of childNodes(node))
|
|
136
|
+
if (child.id !== target.id)
|
|
137
|
+
visit(child);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (functionKinds.has(node.type)) {
|
|
141
|
+
const body = node.childForFieldName("body");
|
|
142
|
+
if (!body) {
|
|
143
|
+
protect(line(node.startPosition.row), line(node.endPosition.row));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// The header owns every line through the line that opens the body.
|
|
147
|
+
protect(line(node.startPosition.row), line(body.startPosition.row));
|
|
148
|
+
visit(body);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (classKinds.has(node.type)) {
|
|
152
|
+
const body = node.childForFieldName("body");
|
|
153
|
+
const open = body ? openBrace(body) : undefined;
|
|
154
|
+
if (!body || !open) {
|
|
155
|
+
protect(line(node.startPosition.row), line(node.endPosition.row));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
protect(line(node.startPosition.row), line(open.startPosition.row));
|
|
159
|
+
for (const member of childNodes(body))
|
|
160
|
+
visit(member);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (bodyKinds.has(node.type)) {
|
|
164
|
+
const open = openBrace(node);
|
|
165
|
+
const close = closeBrace(node);
|
|
166
|
+
if (open && close) {
|
|
167
|
+
const startLine = line(open.startPosition.row) + 1;
|
|
168
|
+
const endLine = line(close.startPosition.row) - 1;
|
|
169
|
+
if (endLine - startLine + 1 >= settings.minBodyLines)
|
|
170
|
+
candidates.push({ startLine, endLine });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const child of childNodes(node))
|
|
174
|
+
visit(child);
|
|
175
|
+
};
|
|
176
|
+
visit(root);
|
|
177
|
+
const ranges = candidates.filter((range) => !guarded.some((header) => range.startLine <= header.endLine && range.endLine >= header.startLine) &&
|
|
178
|
+
range.endLine >= range.startLine);
|
|
179
|
+
return { status: "parsed", ranges };
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=syntax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../../../../../src/harness/utils/read-folders/tree-sitter/syntax.ts"],"names":[],"mappings":"AAiBA,6GAA6G;AAC7G,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;AACjF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC7B,sBAAsB;IACtB,qBAAqB;IACrB,UAAU;IACV,oBAAoB;IACpB,gCAAgC;IAChC,gBAAgB;IAChB,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;IAClB,2BAA2B;CAC3B,CAAC,CAAC;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,mBAA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AC,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC;QACjG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,CACjC,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACrC,CAAC","sourcesContent":["import type { ReadBraceScan, ReadFoldSettings, ReadLineRange } from \"../types.ts\";\n\n/** Structural subset of a web-tree-sitter node: the fold rule stays pure and grammar-runtime free. */\nexport interface SyntaxNode {\n\treadonly id: number;\n\treadonly type: string;\n\treadonly text: string;\n\treadonly startPosition: { readonly row: number };\n\treadonly endPosition: { readonly row: number };\n\treadonly children: readonly (SyntaxNode | null)[];\n\treadonly hasError: boolean;\n\treadonly isMissing: boolean;\n\tchildForFieldName(field: string): SyntaxNode | null;\n}\n\nexport type TreeSitterLanguage = \"ts\" | \"tsx\" | \"js\";\n\n/** Implementation/value containers, mirroring the compiler oracle's whitelist. Class bodies are excluded. */\nconst bodyKinds = new Set([\"statement_block\", \"object\", \"array\", \"switch_body\"]);\nconst functionKinds = new Set([\n\t\"function_declaration\",\n\t\"function_expression\",\n\t\"function\",\n\t\"generator_function\",\n\t\"generator_function_declaration\",\n\t\"arrow_function\",\n\t\"method_definition\",\n\t\"function_signature\",\n\t\"method_signature\",\n\t\"abstract_method_signature\",\n]);\nconst classKinds = new Set([\"class\", \"class_declaration\", \"abstract_class_declaration\"]);\n/** Header material: a fold overlapping any of these lines is rejected, exactly as the oracle rejects it. */\nconst opaqueKinds = new Set([\n\t\"type_annotation\",\n\t\"type_arguments\",\n\t\"type_parameters\",\n\t\"type_alias_declaration\",\n\t\"interface_declaration\",\n\t\"type_predicate_annotation\",\n\t\"omitting_type_annotation\",\n\t\"opting_type_annotation\",\n\t\"asserts_annotation\",\n\t\"type_identifier\",\n\t\"predefined_type\",\n\t\"nested_type_identifier\",\n\t\"formal_parameters\",\n\t\"class_heritage\",\n\t\"extends_clause\",\n\t\"extends_type_clause\",\n\t\"implements_clause\",\n\t\"decorator\",\n\t\"import_statement\",\n\t\"object_pattern\",\n\t\"array_pattern\",\n\t\"computed_property_name\",\n\t\"ambient_declaration\",\n]);\n\nfunction isOpaque(node: SyntaxNode): boolean {\n\treturn opaqueKinds.has(node.type) || node.type.endsWith(\"_type\") || node.type.endsWith(\"_type_annotation\");\n}\n\nfunction childNodes(node: SyntaxNode): SyntaxNode[] {\n\tconst children: SyntaxNode[] = [];\n\tfor (const child of node.children) if (child) children.push(child);\n\treturn children;\n}\n\nfunction openBrace(node: SyntaxNode): SyntaxNode | undefined {\n\tfor (const child of childNodes(node)) if (child.type === \"{\" || child.type === \"[\") return child;\n\treturn undefined;\n}\n\nfunction closeBrace(node: SyntaxNode): SyntaxNode | undefined {\n\tconst children = childNodes(node);\n\tfor (let index = children.length - 1; index >= 0; index--) {\n\t\tconst child = children[index];\n\t\tif (child.type === \"}\" || child.type === \"]\") return child;\n\t}\n\treturn undefined;\n}\n\nfunction exportsOnlyBindings(node: SyntaxNode): boolean {\n\t// `export { a } from \"b\"` / `export * from \"b\"` is a declaration header; `export const x = {}` is not.\n\tfor (const child of childNodes(node))\n\t\tif (child.type === \"export_clause\" || child.type === \"*\" || child.type === \"namespace_export\") return true;\n\treturn false;\n}\n\n/** `x as const` / `x satisfies T`: everything from the operator on is type material. */\nfunction typeOperator(node: SyntaxNode): SyntaxNode | undefined {\n\tif (node.type !== \"as_expression\" && node.type !== \"satisfies_expression\") return undefined;\n\treturn childNodes(node).find((child) => child.type === \"as\" || child.type === \"satisfies\");\n}\n\nfunction assignmentTarget(node: SyntaxNode): SyntaxNode | undefined {\n\tif (node.type !== \"assignment_expression\" && node.type !== \"for_in_statement\") return undefined;\n\tconst left = node.childForFieldName(\"left\");\n\tif (!left) return undefined;\n\tlet target = left;\n\twhile (target.type === \"parenthesized_expression\") {\n\t\tconst inner = childNodes(target).find((child) => child.type !== \"(\" && child.type !== \")\");\n\t\tif (!inner) break;\n\t\ttarget = inner;\n\t}\n\treturn target.type === \"object\" || target.type === \"array\" ? left : undefined;\n}\n\n/**\n * Fold boundaries from a parsed syntax tree, produced under the same rules the compiler oracle\n * uses to annotate safe interiors: value containers only, never a line of a declaration header.\n */\nexport function foldRangesFromSyntax(root: SyntaxNode, settings: ReadFoldSettings): ReadBraceScan {\n\tif (root.hasError || root.isMissing) return { status: \"parse_failure\", reason: \"tree_sitter_parse_error\" };\n\tconst candidates: ReadLineRange[] = [];\n\tconst guarded: ReadLineRange[] = [];\n\tconst protect = (startLine: number, endLine: number) => {\n\t\tif (endLine >= startLine) guarded.push({ startLine, endLine });\n\t};\n\tconst line = (row: number) => row + 1;\n\tconst visit = (node: SyntaxNode): void => {\n\t\tif (isOpaque(node) || (node.type === \"export_statement\" && exportsOnlyBindings(node))) {\n\t\t\tprotect(line(node.startPosition.row), line(node.endPosition.row));\n\t\t\treturn;\n\t\t}\n\t\tif (node.type === \"comment\") {\n\t\t\tconst lines = node.endPosition.row - node.startPosition.row + 1;\n\t\t\tif (node.text.startsWith(\"/**\") || node.text.startsWith(\"/*!\"))\n\t\t\t\tprotect(line(node.startPosition.row), line(node.endPosition.row));\n\t\t\telse if (lines >= settings.minCommentLines)\n\t\t\t\tcandidates.push({ startLine: line(node.startPosition.row) + 1, endLine: line(node.endPosition.row) - 1 });\n\t\t\treturn;\n\t\t}\n\t\tconst operator = typeOperator(node);\n\t\tif (operator) {\n\t\t\tprotect(line(operator.startPosition.row), line(node.endPosition.row));\n\t\t\tfor (const child of childNodes(node)) {\n\t\t\t\tif (child.id === operator.id) break;\n\t\t\t\tvisit(child);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst target = assignmentTarget(node);\n\t\tif (target) {\n\t\t\tprotect(line(target.startPosition.row), line(target.endPosition.row));\n\t\t\tfor (const child of childNodes(node)) if (child.id !== target.id) visit(child);\n\t\t\treturn;\n\t\t}\n\t\tif (functionKinds.has(node.type)) {\n\t\t\tconst body = node.childForFieldName(\"body\");\n\t\t\tif (!body) {\n\t\t\t\tprotect(line(node.startPosition.row), line(node.endPosition.row));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The header owns every line through the line that opens the body.\n\t\t\tprotect(line(node.startPosition.row), line(body.startPosition.row));\n\t\t\tvisit(body);\n\t\t\treturn;\n\t\t}\n\t\tif (classKinds.has(node.type)) {\n\t\t\tconst body = node.childForFieldName(\"body\");\n\t\t\tconst open = body ? openBrace(body) : undefined;\n\t\t\tif (!body || !open) {\n\t\t\t\tprotect(line(node.startPosition.row), line(node.endPosition.row));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprotect(line(node.startPosition.row), line(open.startPosition.row));\n\t\t\tfor (const member of childNodes(body)) visit(member);\n\t\t\treturn;\n\t\t}\n\t\tif (bodyKinds.has(node.type)) {\n\t\t\tconst open = openBrace(node);\n\t\t\tconst close = closeBrace(node);\n\t\t\tif (open && close) {\n\t\t\t\tconst startLine = line(open.startPosition.row) + 1;\n\t\t\t\tconst endLine = line(close.startPosition.row) - 1;\n\t\t\t\tif (endLine - startLine + 1 >= settings.minBodyLines) candidates.push({ startLine, endLine });\n\t\t\t}\n\t\t}\n\t\tfor (const child of childNodes(node)) visit(child);\n\t};\n\tvisit(root);\n\tconst ranges = candidates.filter(\n\t\t(range) =>\n\t\t\t!guarded.some((header) => range.startLine <= header.endLine && range.endLine >= header.startLine) &&\n\t\t\trange.endLine >= range.startLine,\n\t);\n\treturn { status: \"parsed\", ranges };\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./harness/tools/index.ts";
|
|
|
21
21
|
export { type AgentHarnessResources, type AgentHarnessStreamOptions, type AgentHarnessStreamOptionsPatch, type AgentHarnessTool, type AgentHarnessToolContextSource, type AgentHarnessToolInvocation, type AgentHarnessToolUpdateCallback, type AgentHarnessToolUpdateOptions, BranchSummaryError, type BranchSummaryErrorCode, CompactionError, type CompactionErrorCode, type ExecutionEnv, ExecutionError, type ExecutionErrorCode, err, FileError, type FileErrorCode, type FileInfo, type FileKind, type FileSystem, getOrThrow, getOrUndefined, ok, type PromptTemplate, type Shell, type ShellExecOptions, type ShellExecResult, type ShellOutputCaptureOptions, type ShellOutputLimits, type ShellOutputMetadata, type ShellOutputRetention, type ShellOutputTruncation, type ShellOutputUpdate, type ShellOutputView, type Skill, toError, } from "./harness/types.ts";
|
|
22
22
|
export { applyShellOutputUpdate } from "./harness/utils/output-capture.ts";
|
|
23
23
|
export * from "./harness/utils/read-folders/index.ts";
|
|
24
|
+
export * from "./harness/utils/read-folders/prepare.ts";
|
|
24
25
|
export * from "./harness/utils/segmented-read-view.ts";
|
|
25
26
|
export * from "./harness/utils/shell-output.ts";
|
|
26
27
|
export * from "./harness/utils/truncate.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,YAAY,EACX,cAAc,EACd,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,kCAAkC,EAClC,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,cAAc,IAAI,uBAAuB,EACzC,WAAW,EACX,UAAU,EACV,4BAA4B,EAC5B,0BAA0B,EAC1B,sBAAsB,EACtB,gBAAgB,EAChB,iCAAiC,EACjC,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,aAAa,EACb,uBAAuB,EACvB,iCAAiC,EACjC,gBAAgB,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,O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AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export * from "./harness/tools/index.js";
|
|
|
19
19
|
export { BranchSummaryError, CompactionError, ExecutionError, err, FileError, getOrThrow, getOrUndefined, ok, toError, } from "./harness/types.js";
|
|
20
20
|
export { applyShellOutputUpdate } from "./harness/utils/output-capture.js";
|
|
21
21
|
export * from "./harness/utils/read-folders/index.js";
|
|
22
|
+
export * from "./harness/utils/read-folders/prepare.js";
|
|
22
23
|
export * from "./harness/utils/segmented-read-view.js";
|
|
23
24
|
export * from "./harness/utils/shell-output.js";
|
|
24
25
|
export * from "./harness/utils/truncate.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAkC/C,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,kCAAkC,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AACpH,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAKN,8BAA8B,EAG9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAIN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAA8B,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC9F,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAmB3C,OAAO,EACN,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EASN,kBAAkB,EAElB,eAAe,EAGf,cAAc,EAEd,GAAG,EACH,SAAS,EAKT,UAAU,EACV,cAAc,EACd,EAAE,EAaF,OAAO,GACP,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,cAAc,YAAY,CAAC","sourcesContent":["export { uuidv7 } from \"@earendil-works/pi-ai\";\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tInferEventAttributes,\n\tInferOptionalAttributes,\n\tInferRequiredAndOptionalAttributes,\n\tInferStartAttributes,\n\tRecordedTelemetryEvent,\n\tRecordedTelemetrySpan,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanAttributes as TelemetrySpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\nexport {\n\tcreateTypedSpanStarter,\n\tdefineTelemetrySchema,\n\tInMemoryTelemetryContext,\n\tNOOP_TELEMETRY_CONTEXT,\n} from \"@earendil-works/pi-telemetry\";\nexport * from \"./agent.ts\";\nexport * from \"./agent-loop.ts\";\nexport { EMPTY_TOOL_USE_DEMOTION_DIAGNOSTIC, ProviderRetryWatchdogAbortError } from \"./assistant-terminal-state.ts\";\nexport * from \"./harness/agent-harness.ts\";\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryDetails,\n\ttype BranchSummaryResult,\n\ttype CollectEntriesResult,\n\tcollectEntriesForBranchSummary,\n\ttype FileOperations,\n\ttype GenerateBranchSummaryOptions,\n\tgenerateBranchSummary,\n\tprepareBranchEntries,\n} from \"./harness/compaction/branch-summarization.ts\";\nexport {\n\ttype CompactionPreparation,\n\ttype CompactionSettings,\n\ttype CompactResult,\n\tcalculateContextTokens,\n\tcompact,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateContextTokens,\n\testimateTokens,\n\tfindCutPoint,\n\tfindTurnStartIndex,\n\tgenerateSummary,\n\tgenerateSummaryWithUsage,\n\tgetLastAssistantUsage,\n\tprepareCompaction,\n\tserializeConversation,\n\tshouldCompact,\n} from \"./harness/compaction/compaction.ts\";\nexport * from \"./harness/context.ts\";\nexport * from \"./harness/messages.ts\";\nexport * from \"./harness/prompt-templates.ts\";\nexport * from \"./harness/result.ts\";\nexport { type LaneSnapshotReduction, reduceLaneSnapshot } from \"./harness/runtime/reducer.ts\";\nexport * from \"./harness/session/index.ts\";\nexport * from \"./harness/skills.ts\";\nexport * from \"./harness/system-prompt.ts\";\nexport type {\n\tAiSpan,\n\tAiSpanAttributes,\n\tAiSpanEndAttributes,\n\tAiSpanEventAttributes,\n\tAiSpanEventName,\n\tAiSpanName,\n\tAiSpanStartAttributes,\n\tAiTelemetrySpan,\n\tHarnessSpan,\n\tHarnessSpanAttributes,\n\tHarnessSpanEndAttributes,\n\tHarnessSpanEventAttributes,\n\tHarnessSpanEventName,\n\tHarnessSpanName,\n\tHarnessSpanStartAttributes,\n\tHarnessTelemetrySpan,\n} from \"./harness/telemetry.ts\";\nexport {\n\tAGENT_TELEMETRY_SCHEMAS,\n\tAI_TELEMETRY_SCHEMA,\n\tHARNESS_TELEMETRY_SCHEMA,\n\tstartAiSpan,\n\tstartHarnessSpan,\n} from \"./harness/telemetry.ts\";\nexport * from \"./harness/tools/index.ts\";\nexport {\n\ttype AgentHarnessResources,\n\ttype AgentHarnessStreamOptions,\n\ttype AgentHarnessStreamOptionsPatch,\n\ttype AgentHarnessTool,\n\ttype AgentHarnessToolContextSource,\n\ttype AgentHarnessToolInvocation,\n\ttype AgentHarnessToolUpdateCallback,\n\ttype AgentHarnessToolUpdateOptions,\n\tBranchSummaryError,\n\ttype BranchSummaryErrorCode,\n\tCompactionError,\n\ttype CompactionErrorCode,\n\ttype ExecutionEnv,\n\tExecutionError,\n\ttype ExecutionErrorCode,\n\terr,\n\tFileError,\n\ttype FileErrorCode,\n\ttype FileInfo,\n\ttype FileKind,\n\ttype FileSystem,\n\tgetOrThrow,\n\tgetOrUndefined,\n\tok,\n\ttype PromptTemplate,\n\ttype Shell,\n\ttype ShellExecOptions,\n\ttype ShellExecResult,\n\ttype ShellOutputCaptureOptions,\n\ttype ShellOutputLimits,\n\ttype ShellOutputMetadata,\n\ttype ShellOutputRetention,\n\ttype ShellOutputTruncation,\n\ttype ShellOutputUpdate,\n\ttype ShellOutputView,\n\ttype Skill,\n\ttoError,\n} from \"./harness/types.ts\";\nexport { applyShellOutputUpdate } from \"./harness/utils/output-capture.ts\";\nexport * from \"./harness/utils/read-folders/index.ts\";\nexport * from \"./harness/utils/segmented-read-view.ts\";\nexport * from \"./harness/utils/shell-output.ts\";\nexport * from \"./harness/utils/truncate.ts\";\nexport * from \"./proxy.ts\";\nexport * from \"./search/index.ts\";\nexport { setDefaultStreamFn } from \"./stream-fn.ts\";\nexport * from \"./types.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAkC/C,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,GACtB,MAAM,8BAA8B,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,kCAAkC,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AACpH,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAKN,8BAA8B,EAG9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAIN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAA8B,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC9F,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAmB3C,OAAO,EACN,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EASN,kBAAkB,EAElB,eAAe,EAGf,cAAc,EAEd,GAAG,EACH,SAAS,EAKT,UAAU,EACV,cAAc,EACd,EAAE,EAaF,OAAO,GACP,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,cAAc,YAAY,CAAC","sourcesContent":["export { uuidv7 } from \"@earendil-works/pi-ai\";\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tInferEventAttributes,\n\tInferOptionalAttributes,\n\tInferRequiredAndOptionalAttributes,\n\tInferStartAttributes,\n\tRecordedTelemetryEvent,\n\tRecordedTelemetrySpan,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanAttributes as TelemetrySpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\nexport {\n\tcreateTypedSpanStarter,\n\tdefineTelemetrySchema,\n\tInMemoryTelemetryContext,\n\tNOOP_TELEMETRY_CONTEXT,\n} from \"@earendil-works/pi-telemetry\";\nexport * from \"./agent.ts\";\nexport * from \"./agent-loop.ts\";\nexport { EMPTY_TOOL_USE_DEMOTION_DIAGNOSTIC, ProviderRetryWatchdogAbortError } from \"./assistant-terminal-state.ts\";\nexport * from \"./harness/agent-harness.ts\";\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryDetails,\n\ttype BranchSummaryResult,\n\ttype CollectEntriesResult,\n\tcollectEntriesForBranchSummary,\n\ttype FileOperations,\n\ttype GenerateBranchSummaryOptions,\n\tgenerateBranchSummary,\n\tprepareBranchEntries,\n} from \"./harness/compaction/branch-summarization.ts\";\nexport {\n\ttype CompactionPreparation,\n\ttype CompactionSettings,\n\ttype CompactResult,\n\tcalculateContextTokens,\n\tcompact,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateContextTokens,\n\testimateTokens,\n\tfindCutPoint,\n\tfindTurnStartIndex,\n\tgenerateSummary,\n\tgenerateSummaryWithUsage,\n\tgetLastAssistantUsage,\n\tprepareCompaction,\n\tserializeConversation,\n\tshouldCompact,\n} from \"./harness/compaction/compaction.ts\";\nexport * from \"./harness/context.ts\";\nexport * from \"./harness/messages.ts\";\nexport * from \"./harness/prompt-templates.ts\";\nexport * from \"./harness/result.ts\";\nexport { type LaneSnapshotReduction, reduceLaneSnapshot } from \"./harness/runtime/reducer.ts\";\nexport * from \"./harness/session/index.ts\";\nexport * from \"./harness/skills.ts\";\nexport * from \"./harness/system-prompt.ts\";\nexport type {\n\tAiSpan,\n\tAiSpanAttributes,\n\tAiSpanEndAttributes,\n\tAiSpanEventAttributes,\n\tAiSpanEventName,\n\tAiSpanName,\n\tAiSpanStartAttributes,\n\tAiTelemetrySpan,\n\tHarnessSpan,\n\tHarnessSpanAttributes,\n\tHarnessSpanEndAttributes,\n\tHarnessSpanEventAttributes,\n\tHarnessSpanEventName,\n\tHarnessSpanName,\n\tHarnessSpanStartAttributes,\n\tHarnessTelemetrySpan,\n} from \"./harness/telemetry.ts\";\nexport {\n\tAGENT_TELEMETRY_SCHEMAS,\n\tAI_TELEMETRY_SCHEMA,\n\tHARNESS_TELEMETRY_SCHEMA,\n\tstartAiSpan,\n\tstartHarnessSpan,\n} from \"./harness/telemetry.ts\";\nexport * from \"./harness/tools/index.ts\";\nexport {\n\ttype AgentHarnessResources,\n\ttype AgentHarnessStreamOptions,\n\ttype AgentHarnessStreamOptionsPatch,\n\ttype AgentHarnessTool,\n\ttype AgentHarnessToolContextSource,\n\ttype AgentHarnessToolInvocation,\n\ttype AgentHarnessToolUpdateCallback,\n\ttype AgentHarnessToolUpdateOptions,\n\tBranchSummaryError,\n\ttype BranchSummaryErrorCode,\n\tCompactionError,\n\ttype CompactionErrorCode,\n\ttype ExecutionEnv,\n\tExecutionError,\n\ttype ExecutionErrorCode,\n\terr,\n\tFileError,\n\ttype FileErrorCode,\n\ttype FileInfo,\n\ttype FileKind,\n\ttype FileSystem,\n\tgetOrThrow,\n\tgetOrUndefined,\n\tok,\n\ttype PromptTemplate,\n\ttype Shell,\n\ttype ShellExecOptions,\n\ttype ShellExecResult,\n\ttype ShellOutputCaptureOptions,\n\ttype ShellOutputLimits,\n\ttype ShellOutputMetadata,\n\ttype ShellOutputRetention,\n\ttype ShellOutputTruncation,\n\ttype ShellOutputUpdate,\n\ttype ShellOutputView,\n\ttype Skill,\n\ttoError,\n} from \"./harness/types.ts\";\nexport { applyShellOutputUpdate } from \"./harness/utils/output-capture.ts\";\nexport * from \"./harness/utils/read-folders/index.ts\";\nexport * from \"./harness/utils/read-folders/prepare.ts\";\nexport * from \"./harness/utils/segmented-read-view.ts\";\nexport * from \"./harness/utils/shell-output.ts\";\nexport * from \"./harness/utils/truncate.ts\";\nexport * from \"./proxy.ts\";\nexport * from \"./search/index.ts\";\nexport { setDefaultStreamFn } from \"./stream-fn.ts\";\nexport * from \"./types.ts\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-agent-core",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.17",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"dist",
|
|
41
|
+
"assets",
|
|
41
42
|
"README.md"
|
|
42
43
|
],
|
|
43
44
|
"scripts": {
|
|
@@ -56,11 +57,12 @@
|
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
59
|
"@earendil-works/chord": "0.85.1",
|
|
59
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.
|
|
60
|
-
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.
|
|
60
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.17",
|
|
61
|
+
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.17",
|
|
61
62
|
"diff": "9.0.0",
|
|
62
63
|
"ignore": "7.0.8",
|
|
63
64
|
"typebox": "1.3.27",
|
|
65
|
+
"web-tree-sitter": "0.27.0",
|
|
64
66
|
"yaml": "2.9.0"
|
|
65
67
|
},
|
|
66
68
|
"keywords": [
|
|
@@ -82,6 +84,7 @@
|
|
|
82
84
|
},
|
|
83
85
|
"devDependencies": {
|
|
84
86
|
"@types/node": "26.2.0",
|
|
87
|
+
"@vscode/tree-sitter-wasm": "0.3.1",
|
|
85
88
|
"@vitest/coverage-v8": "4.1.11",
|
|
86
89
|
"typescript": "7.0.2",
|
|
87
90
|
"vitest": "4.1.11"
|