open-multi-agent-kit 0.90.9 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.md +39 -4
  2. package/README.md +14 -1
  3. package/dist/core/agent-session.d.ts +27 -0
  4. package/dist/core/agent-session.d.ts.map +1 -1
  5. package/dist/core/agent-session.js +196 -32
  6. package/dist/core/agent-session.js.map +1 -1
  7. package/dist/core/command-safety.d.ts.map +1 -1
  8. package/dist/core/command-safety.js +0 -58
  9. package/dist/core/command-safety.js.map +1 -1
  10. package/dist/core/compaction/transaction.d.ts.map +1 -1
  11. package/dist/core/compaction/transaction.js +7 -3
  12. package/dist/core/compaction/transaction.js.map +1 -1
  13. package/dist/core/context-budget-headroom-candidates.d.ts.map +1 -1
  14. package/dist/core/context-budget-headroom-candidates.js +21 -11
  15. package/dist/core/context-budget-headroom-candidates.js.map +1 -1
  16. package/dist/core/context-budget-system-prompt-items.d.ts +1 -0
  17. package/dist/core/context-budget-system-prompt-items.d.ts.map +1 -1
  18. package/dist/core/context-budget-system-prompt-items.js +7 -8
  19. package/dist/core/context-budget-system-prompt-items.js.map +1 -1
  20. package/dist/core/footer-data-provider.d.ts +7 -1
  21. package/dist/core/footer-data-provider.d.ts.map +1 -1
  22. package/dist/core/footer-data-provider.js +12 -0
  23. package/dist/core/footer-data-provider.js.map +1 -1
  24. package/dist/core/index.d.ts +1 -0
  25. package/dist/core/index.d.ts.map +1 -1
  26. package/dist/core/index.js +1 -0
  27. package/dist/core/index.js.map +1 -1
  28. package/dist/core/loadouts.d.ts.map +1 -1
  29. package/dist/core/loadouts.js +27 -48
  30. package/dist/core/loadouts.js.map +1 -1
  31. package/dist/core/metrics-sampler.d.ts +20 -0
  32. package/dist/core/metrics-sampler.d.ts.map +1 -1
  33. package/dist/core/metrics-sampler.js +52 -0
  34. package/dist/core/metrics-sampler.js.map +1 -1
  35. package/dist/core/model-registry.d.ts.map +1 -1
  36. package/dist/core/model-registry.js +4 -1
  37. package/dist/core/model-registry.js.map +1 -1
  38. package/dist/core/model-resolver.d.ts.map +1 -1
  39. package/dist/core/model-resolver.js +15 -6
  40. package/dist/core/model-resolver.js.map +1 -1
  41. package/dist/core/provider-resilience.d.ts +51 -0
  42. package/dist/core/provider-resilience.d.ts.map +1 -0
  43. package/dist/core/provider-resilience.js +86 -0
  44. package/dist/core/provider-resilience.js.map +1 -0
  45. package/dist/core/run-journal.d.ts.map +1 -1
  46. package/dist/core/run-journal.js +14 -22
  47. package/dist/core/run-journal.js.map +1 -1
  48. package/dist/core/session-termination.d.ts +8 -2
  49. package/dist/core/session-termination.d.ts.map +1 -1
  50. package/dist/core/session-termination.js +45 -3
  51. package/dist/core/session-termination.js.map +1 -1
  52. package/dist/core/settings-manager.d.ts +30 -0
  53. package/dist/core/settings-manager.d.ts.map +1 -1
  54. package/dist/core/settings-manager.js +17 -0
  55. package/dist/core/settings-manager.js.map +1 -1
  56. package/dist/core/system-prompt.d.ts.map +1 -1
  57. package/dist/core/system-prompt.js +35 -30
  58. package/dist/core/system-prompt.js.map +1 -1
  59. package/dist/core/tools/grep.d.ts.map +1 -1
  60. package/dist/core/tools/grep.js +47 -0
  61. package/dist/core/tools/grep.js.map +1 -1
  62. package/dist/core/tools/omp-pure-seams.d.ts +41 -0
  63. package/dist/core/tools/omp-pure-seams.d.ts.map +1 -0
  64. package/dist/core/tools/omp-pure-seams.js +142 -0
  65. package/dist/core/tools/omp-pure-seams.js.map +1 -0
  66. package/dist/core/tools/omp-seam-runtime.d.ts +100 -0
  67. package/dist/core/tools/omp-seam-runtime.d.ts.map +1 -0
  68. package/dist/core/tools/omp-seam-runtime.js +40 -0
  69. package/dist/core/tools/omp-seam-runtime.js.map +1 -0
  70. package/dist/core/tools/read.d.ts.map +1 -1
  71. package/dist/core/tools/read.js +34 -1
  72. package/dist/core/tools/read.js.map +1 -1
  73. package/dist/main.d.ts.map +1 -1
  74. package/dist/main.js +112 -11
  75. package/dist/main.js.map +1 -1
  76. package/dist/modes/interactive/components/footer.d.ts +1 -1
  77. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  78. package/dist/modes/interactive/components/footer.js +11 -8
  79. package/dist/modes/interactive/components/footer.js.map +1 -1
  80. package/dist/modes/interactive/theme/omk-aurora-dark.json +80 -0
  81. package/dist/modes/interactive/theme/omk-aurora-light.json +80 -0
  82. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  83. package/dist/modes/interactive/theme/theme.js +5 -0
  84. package/dist/modes/interactive/theme/theme.js.map +1 -1
  85. package/dist/modes/print-mode.d.ts.map +1 -1
  86. package/dist/modes/print-mode.js +9 -0
  87. package/dist/modes/print-mode.js.map +1 -1
  88. package/docs/adaptorch-preview-spec.md +174 -0
  89. package/docs/adaptorch-preview.md +2 -2
  90. package/docs/compaction.md +13 -13
  91. package/docs/correctness-wall.md +13 -5
  92. package/docs/custom-provider.md +8 -8
  93. package/docs/development.md +2 -2
  94. package/docs/extensions.md +8 -8
  95. package/docs/json.md +4 -4
  96. package/docs/provider-resilience.md +87 -0
  97. package/docs/providers.md +1 -1
  98. package/docs/session-format.md +5 -5
  99. package/docs/settings.md +30 -0
  100. package/docs/skills.md +2 -0
  101. package/docs/themes.md +4 -2
  102. package/docs/tui.md +4 -4
  103. package/docs/usage.md +4 -0
  104. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  105. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  106. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  107. package/examples/extensions/gondolin/package-lock.json +2 -2
  108. package/examples/extensions/gondolin/package.json +1 -1
  109. package/examples/extensions/sandbox/package-lock.json +2 -2
  110. package/examples/extensions/sandbox/package.json +1 -1
  111. package/examples/extensions/subagent/README.md +35 -10
  112. package/examples/extensions/subagent/adaptive-agent-runtime.test.ts +234 -0
  113. package/examples/extensions/subagent/adaptive-agent-runtime.ts +240 -0
  114. package/examples/extensions/subagent/adaptive-result.ts +112 -0
  115. package/examples/extensions/subagent/checkpoint-runtime.test.ts +125 -0
  116. package/examples/extensions/subagent/checkpoint-runtime.ts +198 -0
  117. package/examples/extensions/subagent/deadline-budget.test.ts +135 -0
  118. package/examples/extensions/subagent/deadline-budget.ts +242 -0
  119. package/examples/extensions/subagent/deadline-profile-store.test.ts +72 -0
  120. package/examples/extensions/subagent/deadline-profile-store.ts +172 -0
  121. package/examples/extensions/subagent/fixtures/fake-omk-json.mjs +13 -0
  122. package/examples/extensions/subagent/fixtures/hanging-process-tree.mjs +40 -0
  123. package/examples/extensions/subagent/index.ts +253 -137
  124. package/examples/extensions/subagent/managed-process.test.ts +178 -0
  125. package/examples/extensions/subagent/managed-process.ts +236 -0
  126. package/examples/extensions/subagent/subagent-extension-smoke.test.ts +112 -0
  127. package/examples/extensions/subagent/subagent-runtime-types.ts +76 -0
  128. package/examples/extensions/with-deps/package-lock.json +2 -2
  129. package/examples/extensions/with-deps/package.json +1 -1
  130. package/npm-shrinkwrap.json +28 -19
  131. package/package.json +6 -5
@@ -0,0 +1,142 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ /**
10
+ * Flag-gated loader for the vendored oh-my-pi "pure" read/search/hashline seams.
11
+ *
12
+ * These seams are pure data/proposal-only functions (planning + presentation +
13
+ * hashline parsing). They do NOT touch edit/write/file-mutation paths. The
14
+ * loader is enabled by default and opts out via OMK_OMP_SEAMS=0 (ADR-OMP-009);
15
+ * when disabled it throws DISABLED and tool behavior falls back to the
16
+ * pre-seam implementation byte-identically.
17
+ *
18
+ * The file is erasable TypeScript: no `enum`, no parameter properties, no `as`,
19
+ * no non-null assertions, no `any` annotations, and no runtime dependencies
20
+ * beyond the Node.js standard library.
21
+ */
22
+ import { existsSync } from "node:fs";
23
+ import { dirname, isAbsolute, join, resolve } from "node:path";
24
+ import { fileURLToPath, pathToFileURL } from "node:url";
25
+ /** Typed error thrown by {@link loadOmpPureSeams}. */
26
+ export class OmpSeamsError extends Error {
27
+ code;
28
+ constructor(code, message) {
29
+ super(message);
30
+ this.name = "OmpSeamsError";
31
+ this.code = code;
32
+ }
33
+ }
34
+ /**
35
+ * Returns true unless the seams feature is explicitly disabled
36
+ * (OMK_OMP_SEAMS === "0"). Enabled by default per ADR-OMP-009.
37
+ * Reads `process.env` when no record is supplied.
38
+ */
39
+ export function isOmpSeamsEnabled(env) {
40
+ const source = env ?? process.env;
41
+ return source.OMK_OMP_SEAMS !== "0";
42
+ }
43
+ const VENDOR_SEGMENT = join("vendor", "oh-my-pi");
44
+ const VENDOR_MARKER = join(VENDOR_SEGMENT, "packages", "coding-agent", "src", "pure", "read.ts");
45
+ const MAX_WALK_UP_LEVELS = 8;
46
+ /**
47
+ * Walks up from `startDir` (inclusive) looking for a `vendor/oh-my-pi`
48
+ * directory that contains the pure read seam marker file. Returns the absolute
49
+ * vendor directory path, or `undefined` when none is found within the level cap.
50
+ */
51
+ export function resolveOmpVendorDir(startDir) {
52
+ let dir = isAbsolute(startDir) ? startDir : resolve(startDir);
53
+ for (let level = 0; level <= MAX_WALK_UP_LEVELS; level += 1) {
54
+ if (existsSync(join(dir, VENDOR_MARKER))) {
55
+ return join(dir, VENDOR_SEGMENT);
56
+ }
57
+ const parent = dirname(dir);
58
+ if (parent === dir)
59
+ break;
60
+ dir = parent;
61
+ }
62
+ return undefined;
63
+ }
64
+ function isSeamFn(member) {
65
+ return typeof member === "function";
66
+ }
67
+ function isSeamAsyncStrFn(member) {
68
+ return typeof member === "function";
69
+ }
70
+ function expectFn(member, guard, name) {
71
+ if (guard(member))
72
+ return member;
73
+ throw new OmpSeamsError("INVALID_SEAM", `OMP seam missing or non-function: ${name}`);
74
+ }
75
+ const READ_SEAM = join("packages", "coding-agent", "src", "pure", "read.ts");
76
+ const SEARCH_SEAM = join("packages", "coding-agent", "src", "pure", "search.ts");
77
+ const PROPOSAL_SEAM = join("packages", "hashline", "src", "proposal.ts");
78
+ /**
79
+ * Loads and validates the three pure seam modules from the vendored oh-my-pi
80
+ * tree and returns a frozen {@link OmpPureSeams} record. Throws
81
+ * {@link OmpSeamsError} with code DISABLED when the feature is off,
82
+ * VENDOR_NOT_FOUND when the vendor tree cannot be located, or INVALID_SEAM when
83
+ * any expected export is missing or not a function.
84
+ */
85
+ export async function loadOmpPureSeams(options) {
86
+ const env = options?.env ?? process.env;
87
+ if (!isOmpSeamsEnabled(env)) {
88
+ throw new OmpSeamsError("DISABLED", "OMP pure seams are disabled (OMK_OMP_SEAMS=0; unset or set to any other value to enable).");
89
+ }
90
+ let vendorDir = options?.vendorDir ?? env.OMK_OMP_VENDOR_DIR;
91
+ if (!vendorDir) {
92
+ const moduleUrl = new URL(".", import.meta.url);
93
+ if (moduleUrl.protocol !== "file:") {
94
+ throw new OmpSeamsError("VENDOR_NOT_FOUND", "OMP vendor dir was not provided and the module is not a file URL.");
95
+ }
96
+ const found = resolveOmpVendorDir(fileURLToPath(moduleUrl));
97
+ if (!found) {
98
+ throw new OmpSeamsError("VENDOR_NOT_FOUND", "OMP vendor dir not found by walking up from the module directory.");
99
+ }
100
+ vendorDir = found;
101
+ }
102
+ if (!existsSync(vendorDir)) {
103
+ throw new OmpSeamsError("VENDOR_NOT_FOUND", `OMP vendor dir does not exist: ${vendorDir}`);
104
+ }
105
+ const readUrl = pathToFileURL(join(vendorDir, READ_SEAM)).href;
106
+ const searchUrl = pathToFileURL(join(vendorDir, SEARCH_SEAM)).href;
107
+ const proposalUrl = pathToFileURL(join(vendorDir, PROPOSAL_SEAM)).href;
108
+ const readMod = await import(__rewriteRelativeImportExtension(readUrl));
109
+ const searchMod = await import(__rewriteRelativeImportExtension(searchUrl));
110
+ const proposalMod = await import(__rewriteRelativeImportExtension(proposalUrl));
111
+ // Validate every expected member up front so the INVALID_SEAM error lists
112
+ // ALL missing/non-function exports, not just the first one encountered.
113
+ const expected = [
114
+ [readMod.planRead, "planRead"],
115
+ [readMod.presentRead, "presentRead"],
116
+ [searchMod.planSearch, "planSearch"],
117
+ [searchMod.presentSearch, "presentSearch"],
118
+ [proposalMod.parseHashlineProposal, "parseHashlineProposal"],
119
+ [proposalMod.hashProposalLine, "hashProposalLine"],
120
+ [proposalMod.hashProposalSource, "hashProposalSource"],
121
+ ];
122
+ const missing = [];
123
+ for (const [member, name] of expected) {
124
+ if (typeof member !== "function")
125
+ missing.push(name);
126
+ }
127
+ if (missing.length > 0) {
128
+ throw new OmpSeamsError("INVALID_SEAM", `OMP seams missing or non-function: ${missing.join(", ")}`);
129
+ }
130
+ const rec = {
131
+ planRead: expectFn(readMod.planRead, isSeamFn, "planRead"),
132
+ presentRead: expectFn(readMod.presentRead, isSeamFn, "presentRead"),
133
+ planSearch: expectFn(searchMod.planSearch, isSeamFn, "planSearch"),
134
+ presentSearch: expectFn(searchMod.presentSearch, isSeamFn, "presentSearch"),
135
+ parseHashlineProposal: expectFn(proposalMod.parseHashlineProposal, isSeamFn, "parseHashlineProposal"),
136
+ hashProposalLine: expectFn(proposalMod.hashProposalLine, isSeamAsyncStrFn, "hashProposalLine"),
137
+ hashProposalSource: expectFn(proposalMod.hashProposalSource, isSeamAsyncStrFn, "hashProposalSource"),
138
+ };
139
+ Object.freeze(rec);
140
+ return rec;
141
+ }
142
+ //# sourceMappingURL=omp-pure-seams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omp-pure-seams.js","sourceRoot":"","sources":["../../../src/core/tools/omp-pure-seams.ts"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EA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E,gBAAgB,EAAE,oBAAoB,CAAC;KACpG,CAAC;IACF,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,GAAG,CAAC;AAAA,CACX","sourcesContent":["/**\n * Flag-gated loader for the vendored oh-my-pi \"pure\" read/search/hashline seams.\n *\n * These seams are pure data/proposal-only functions (planning + presentation +\n * hashline parsing). They do NOT touch edit/write/file-mutation paths. The\n * loader is enabled by default and opts out via OMK_OMP_SEAMS=0 (ADR-OMP-009);\n * when disabled it throws DISABLED and tool behavior falls back to the\n * pre-seam implementation byte-identically.\n *\n * The file is erasable TypeScript: no `enum`, no parameter properties, no `as`,\n * no non-null assertions, no `any` annotations, and no runtime dependencies\n * beyond the Node.js standard library.\n */\nimport { existsSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\n/** Error categories raised by the OMP pure-seam loader. */\nexport type OmpSeamsErrorCode = \"DISABLED\" | \"VENDOR_NOT_FOUND\" | \"INVALID_SEAM\";\n\n/** Typed error thrown by {@link loadOmpPureSeams}. */\nexport class OmpSeamsError extends Error {\n\treadonly code: OmpSeamsErrorCode;\n\n\tconstructor(code: OmpSeamsErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"OmpSeamsError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** The validated set of pure oh-my-pi seams (data/proposal-only). */\nexport interface OmpPureSeams {\n\tplanRead(input: unknown): unknown;\n\tpresentRead(plan: unknown, file: unknown): unknown;\n\tplanSearch(input: unknown): unknown;\n\tpresentSearch(plan: unknown, matches: unknown, sourceDigests?: unknown): unknown;\n\tparseHashlineProposal(text: string): unknown;\n\thashProposalLine(text: string): Promise<string>;\n\thashProposalSource(text: string): Promise<string>;\n}\n\n/**\n * Returns true unless the seams feature is explicitly disabled\n * (OMK_OMP_SEAMS === \"0\"). Enabled by default per ADR-OMP-009.\n * Reads `process.env` when no record is supplied.\n */\nexport function isOmpSeamsEnabled(env?: Record<string, string | undefined>): boolean {\n\tconst source: Record<string, string | undefined> = env ?? process.env;\n\treturn source.OMK_OMP_SEAMS !== \"0\";\n}\n\nconst VENDOR_SEGMENT = join(\"vendor\", \"oh-my-pi\");\nconst VENDOR_MARKER = join(VENDOR_SEGMENT, \"packages\", \"coding-agent\", \"src\", \"pure\", \"read.ts\");\nconst MAX_WALK_UP_LEVELS = 8;\n\n/**\n * Walks up from `startDir` (inclusive) looking for a `vendor/oh-my-pi`\n * directory that contains the pure read seam marker file. Returns the absolute\n * vendor directory path, or `undefined` when none is found within the level cap.\n */\nexport function resolveOmpVendorDir(startDir: string): string | undefined {\n\tlet dir = isAbsolute(startDir) ? startDir : resolve(startDir);\n\tfor (let level = 0; level <= MAX_WALK_UP_LEVELS; level += 1) {\n\t\tif (existsSync(join(dir, VENDOR_MARKER))) {\n\t\t\treturn join(dir, VENDOR_SEGMENT);\n\t\t}\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\treturn undefined;\n}\n\n// --- internal narrowing helpers (no `as`; type guards carry the signatures) ---\n\ntype SeamFn = (...args: never[]) => unknown;\ntype SeamAsyncStrFn = (...args: never[]) => Promise<string>;\n\nfunction isSeamFn(member: unknown): member is SeamFn {\n\treturn typeof member === \"function\";\n}\n\nfunction isSeamAsyncStrFn(member: unknown): member is SeamAsyncStrFn {\n\treturn typeof member === \"function\";\n}\n\nfunction expectFn<T extends SeamFn>(member: unknown, guard: (m: unknown) => m is T, name: string): T {\n\tif (guard(member)) return member;\n\tthrow new OmpSeamsError(\"INVALID_SEAM\", `OMP seam missing or non-function: ${name}`);\n}\n\nconst READ_SEAM = join(\"packages\", \"coding-agent\", \"src\", \"pure\", \"read.ts\");\nconst SEARCH_SEAM = join(\"packages\", \"coding-agent\", \"src\", \"pure\", \"search.ts\");\nconst PROPOSAL_SEAM = join(\"packages\", \"hashline\", \"src\", \"proposal.ts\");\n\n/**\n * Loads and validates the three pure seam modules from the vendored oh-my-pi\n * tree and returns a frozen {@link OmpPureSeams} record. Throws\n * {@link OmpSeamsError} with code DISABLED when the feature is off,\n * VENDOR_NOT_FOUND when the vendor tree cannot be located, or INVALID_SEAM when\n * any expected export is missing or not a function.\n */\nexport async function loadOmpPureSeams(options?: {\n\tvendorDir?: string;\n\tenv?: Record<string, string | undefined>;\n}): Promise<OmpPureSeams> {\n\tconst env: Record<string, string | undefined> = options?.env ?? process.env;\n\tif (!isOmpSeamsEnabled(env)) {\n\t\tthrow new OmpSeamsError(\n\t\t\t\"DISABLED\",\n\t\t\t\"OMP pure seams are disabled (OMK_OMP_SEAMS=0; unset or set to any other value to enable).\",\n\t\t);\n\t}\n\n\tlet vendorDir: string | undefined = options?.vendorDir ?? env.OMK_OMP_VENDOR_DIR;\n\tif (!vendorDir) {\n\t\tconst moduleUrl = new URL(\".\", import.meta.url);\n\t\tif (moduleUrl.protocol !== \"file:\") {\n\t\t\tthrow new OmpSeamsError(\n\t\t\t\t\"VENDOR_NOT_FOUND\",\n\t\t\t\t\"OMP vendor dir was not provided and the module is not a file URL.\",\n\t\t\t);\n\t\t}\n\t\tconst found = resolveOmpVendorDir(fileURLToPath(moduleUrl));\n\t\tif (!found) {\n\t\t\tthrow new OmpSeamsError(\n\t\t\t\t\"VENDOR_NOT_FOUND\",\n\t\t\t\t\"OMP vendor dir not found by walking up from the module directory.\",\n\t\t\t);\n\t\t}\n\t\tvendorDir = found;\n\t}\n\tif (!existsSync(vendorDir)) {\n\t\tthrow new OmpSeamsError(\"VENDOR_NOT_FOUND\", `OMP vendor dir does not exist: ${vendorDir}`);\n\t}\n\n\tconst readUrl = pathToFileURL(join(vendorDir, READ_SEAM)).href;\n\tconst searchUrl = pathToFileURL(join(vendorDir, SEARCH_SEAM)).href;\n\tconst proposalUrl = pathToFileURL(join(vendorDir, PROPOSAL_SEAM)).href;\n\n\tconst readMod = await import(readUrl);\n\tconst searchMod = await import(searchUrl);\n\tconst proposalMod = await import(proposalUrl);\n\n\t// Validate every expected member up front so the INVALID_SEAM error lists\n\t// ALL missing/non-function exports, not just the first one encountered.\n\tconst expected: ReadonlyArray<readonly [unknown, string]> = [\n\t\t[readMod.planRead, \"planRead\"],\n\t\t[readMod.presentRead, \"presentRead\"],\n\t\t[searchMod.planSearch, \"planSearch\"],\n\t\t[searchMod.presentSearch, \"presentSearch\"],\n\t\t[proposalMod.parseHashlineProposal, \"parseHashlineProposal\"],\n\t\t[proposalMod.hashProposalLine, \"hashProposalLine\"],\n\t\t[proposalMod.hashProposalSource, \"hashProposalSource\"],\n\t];\n\tconst missing: string[] = [];\n\tfor (const [member, name] of expected) {\n\t\tif (typeof member !== \"function\") missing.push(name);\n\t}\n\tif (missing.length > 0) {\n\t\tthrow new OmpSeamsError(\"INVALID_SEAM\", `OMP seams missing or non-function: ${missing.join(\", \")}`);\n\t}\n\n\tconst rec: OmpPureSeams = {\n\t\tplanRead: expectFn(readMod.planRead, isSeamFn, \"planRead\"),\n\t\tpresentRead: expectFn(readMod.presentRead, isSeamFn, \"presentRead\"),\n\t\tplanSearch: expectFn(searchMod.planSearch, isSeamFn, \"planSearch\"),\n\t\tpresentSearch: expectFn(searchMod.presentSearch, isSeamFn, \"presentSearch\"),\n\t\tparseHashlineProposal: expectFn(proposalMod.parseHashlineProposal, isSeamFn, \"parseHashlineProposal\"),\n\t\thashProposalLine: expectFn(proposalMod.hashProposalLine, isSeamAsyncStrFn, \"hashProposalLine\"),\n\t\thashProposalSource: expectFn(proposalMod.hashProposalSource, isSeamAsyncStrFn, \"hashProposalSource\"),\n\t};\n\tObject.freeze(rec);\n\treturn rec;\n}\n"]}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Typed runtime facade over the flag-gated OMP pure-seam loader.
3
+ *
4
+ * Wiring boundary for I2 (ADR-OMP-008/009): the read and grep tools delegate
5
+ * request validation and output presentation to the vendored OMP pure seams.
6
+ * Enabled by default; `OMK_OMP_SEAMS=0` opts out and tool behavior falls back
7
+ * byte-identically to the pre-seam implementation.
8
+ *
9
+ * The loader exposes unknown-in/unknown-out signatures; all structural
10
+ * assertions live in this single file so tool code stays clean.
11
+ */
12
+ import { type OmpPureSeams } from "./omp-pure-seams.ts";
13
+ export interface OmpIssue {
14
+ readonly field: string;
15
+ readonly code: string;
16
+ readonly message: string;
17
+ }
18
+ export interface OmpReadPlan {
19
+ readonly path: string;
20
+ readonly offset: number;
21
+ readonly limit: number;
22
+ }
23
+ export type OmpReadPlanResult = {
24
+ readonly ok: true;
25
+ readonly plan: OmpReadPlan;
26
+ } | {
27
+ readonly ok: false;
28
+ readonly issues: readonly OmpIssue[];
29
+ };
30
+ export interface OmpReadPresentation {
31
+ readonly text: string;
32
+ readonly window: {
33
+ readonly startLine: number;
34
+ readonly endLine: number;
35
+ readonly totalLines: number;
36
+ readonly truncated: boolean;
37
+ };
38
+ }
39
+ export type OmpReadPresentResult = {
40
+ readonly ok: true;
41
+ readonly presentation: OmpReadPresentation;
42
+ } | {
43
+ readonly ok: false;
44
+ readonly conflicts: readonly unknown[];
45
+ };
46
+ export interface OmpSearchPlan {
47
+ readonly pattern: string;
48
+ readonly path: string;
49
+ readonly glob?: string;
50
+ readonly ignoreCase: boolean;
51
+ readonly literal: boolean;
52
+ readonly context: number;
53
+ readonly limit: number;
54
+ }
55
+ export type OmpSearchPlanResult = {
56
+ readonly ok: true;
57
+ readonly plan: OmpSearchPlan;
58
+ } | {
59
+ readonly ok: false;
60
+ readonly issues: readonly OmpIssue[];
61
+ };
62
+ export interface OmpSearchHostMatch {
63
+ readonly file: string;
64
+ readonly line: number;
65
+ readonly column?: number;
66
+ readonly text: string;
67
+ readonly expectedLineHash?: string;
68
+ }
69
+ export interface OmpSearchPresentation {
70
+ readonly text: string;
71
+ readonly totalMatches: number;
72
+ readonly omittedMatches: number;
73
+ readonly truncated: boolean;
74
+ }
75
+ export type OmpSearchPresentResult = {
76
+ readonly ok: true;
77
+ readonly presentation: OmpSearchPresentation;
78
+ } | {
79
+ readonly ok: false;
80
+ readonly conflicts: readonly unknown[];
81
+ };
82
+ /**
83
+ * Returns the memoized seam set unless `OMK_OMP_SEAMS=0`; `undefined` when
84
+ * opted out. Loader errors (VENDOR_NOT_FOUND, INVALID_SEAM) propagate to
85
+ * the caller of the returned promise.
86
+ */
87
+ export declare function getOmpSeams(): Promise<OmpPureSeams> | undefined;
88
+ export declare function planRead(seams: OmpPureSeams, input: unknown): OmpReadPlanResult;
89
+ export declare function presentRead(seams: OmpPureSeams, plan: OmpReadPlan, file: {
90
+ text: string;
91
+ sourceDigest?: string;
92
+ lineDigests?: readonly {
93
+ line: number;
94
+ digest: string;
95
+ }[];
96
+ }): OmpReadPresentResult;
97
+ export declare function planSearch(seams: OmpPureSeams, input: unknown): OmpSearchPlanResult;
98
+ export declare function presentSearch(seams: OmpPureSeams, plan: OmpSearchPlan, matches: readonly OmpSearchHostMatch[]): OmpSearchPresentResult;
99
+ export declare function formatOmpIssues(issues: readonly OmpIssue[]): string;
100
+ //# sourceMappingURL=omp-seam-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omp-seam-runtime.d.ts","sourceRoot":"","sources":["../../../src/core/tools/omp-seam-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAuC,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE7F,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,iBAAiB,GAC1B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ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AED,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAEnF;AAED,wBAAgB,aAAa,CAC5B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,SAAS,kBAAkB,EAAE,GACpC,sBAAsB,CAExB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,CAEnE","sourcesContent":["/**\n * Typed runtime facade over the flag-gated OMP pure-seam loader.\n *\n * Wiring boundary for I2 (ADR-OMP-008/009): the read and grep tools delegate\n * request validation and output presentation to the vendored OMP pure seams.\n * Enabled by default; `OMK_OMP_SEAMS=0` opts out and tool behavior falls back\n * byte-identically to the pre-seam implementation.\n *\n * The loader exposes unknown-in/unknown-out signatures; all structural\n * assertions live in this single file so tool code stays clean.\n */\nimport { isOmpSeamsEnabled, loadOmpPureSeams, type OmpPureSeams } from \"./omp-pure-seams.ts\";\n\nexport interface OmpIssue {\n\treadonly field: string;\n\treadonly code: string;\n\treadonly message: string;\n}\n\nexport interface OmpReadPlan {\n\treadonly path: string;\n\treadonly offset: number;\n\treadonly limit: number;\n}\n\nexport type OmpReadPlanResult =\n\t| { readonly ok: true; readonly plan: OmpReadPlan }\n\t| { readonly ok: false; readonly issues: readonly OmpIssue[] };\n\nexport interface OmpReadPresentation {\n\treadonly text: string;\n\treadonly window: {\n\t\treadonly startLine: number;\n\t\treadonly endLine: number;\n\t\treadonly totalLines: number;\n\t\treadonly truncated: boolean;\n\t};\n}\n\nexport type OmpReadPresentResult =\n\t| { readonly ok: true; readonly presentation: OmpReadPresentation }\n\t| { readonly ok: false; readonly conflicts: readonly unknown[] };\n\nexport interface OmpSearchPlan {\n\treadonly pattern: string;\n\treadonly path: string;\n\treadonly glob?: string;\n\treadonly ignoreCase: boolean;\n\treadonly literal: boolean;\n\treadonly context: number;\n\treadonly limit: number;\n}\n\nexport type OmpSearchPlanResult =\n\t| { readonly ok: true; readonly plan: OmpSearchPlan }\n\t| { readonly ok: false; readonly issues: readonly OmpIssue[] };\n\nexport interface OmpSearchHostMatch {\n\treadonly file: string;\n\treadonly line: number;\n\treadonly column?: number;\n\treadonly text: string;\n\treadonly expectedLineHash?: string;\n}\n\nexport interface OmpSearchPresentation {\n\treadonly text: string;\n\treadonly totalMatches: number;\n\treadonly omittedMatches: number;\n\treadonly truncated: boolean;\n}\n\nexport type OmpSearchPresentResult =\n\t| { readonly ok: true; readonly presentation: OmpSearchPresentation }\n\t| { readonly ok: false; readonly conflicts: readonly unknown[] };\n\nlet cached: Promise<OmpPureSeams> | undefined;\n\n/**\n * Returns the memoized seam set unless `OMK_OMP_SEAMS=0`; `undefined` when\n * opted out. Loader errors (VENDOR_NOT_FOUND, INVALID_SEAM) propagate to\n * the caller of the returned promise.\n */\nexport function getOmpSeams(): Promise<OmpPureSeams> | undefined {\n\tif (!isOmpSeamsEnabled()) return undefined;\n\tcached ??= loadOmpPureSeams();\n\treturn cached;\n}\n\nexport function planRead(seams: OmpPureSeams, input: unknown): OmpReadPlanResult {\n\treturn seams.planRead(input) as OmpReadPlanResult;\n}\n\nexport function presentRead(\n\tseams: OmpPureSeams,\n\tplan: OmpReadPlan,\n\tfile: { text: string; sourceDigest?: string; lineDigests?: readonly { line: number; digest: string }[] },\n): OmpReadPresentResult {\n\treturn seams.presentRead(plan, file) as OmpReadPresentResult;\n}\n\nexport function planSearch(seams: OmpPureSeams, input: unknown): OmpSearchPlanResult {\n\treturn seams.planSearch(input) as OmpSearchPlanResult;\n}\n\nexport function presentSearch(\n\tseams: OmpPureSeams,\n\tplan: OmpSearchPlan,\n\tmatches: readonly OmpSearchHostMatch[],\n): OmpSearchPresentResult {\n\treturn seams.presentSearch(plan, matches) as OmpSearchPresentResult;\n}\n\nexport function formatOmpIssues(issues: readonly OmpIssue[]): string {\n\treturn issues.map((issue) => `${issue.field}: ${issue.message}`).join(\"; \");\n}\n"]}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Typed runtime facade over the flag-gated OMP pure-seam loader.
3
+ *
4
+ * Wiring boundary for I2 (ADR-OMP-008/009): the read and grep tools delegate
5
+ * request validation and output presentation to the vendored OMP pure seams.
6
+ * Enabled by default; `OMK_OMP_SEAMS=0` opts out and tool behavior falls back
7
+ * byte-identically to the pre-seam implementation.
8
+ *
9
+ * The loader exposes unknown-in/unknown-out signatures; all structural
10
+ * assertions live in this single file so tool code stays clean.
11
+ */
12
+ import { isOmpSeamsEnabled, loadOmpPureSeams } from "./omp-pure-seams.js";
13
+ let cached;
14
+ /**
15
+ * Returns the memoized seam set unless `OMK_OMP_SEAMS=0`; `undefined` when
16
+ * opted out. Loader errors (VENDOR_NOT_FOUND, INVALID_SEAM) propagate to
17
+ * the caller of the returned promise.
18
+ */
19
+ export function getOmpSeams() {
20
+ if (!isOmpSeamsEnabled())
21
+ return undefined;
22
+ cached ??= loadOmpPureSeams();
23
+ return cached;
24
+ }
25
+ export function planRead(seams, input) {
26
+ return seams.planRead(input);
27
+ }
28
+ export function presentRead(seams, plan, file) {
29
+ return seams.presentRead(plan, file);
30
+ }
31
+ export function planSearch(seams, input) {
32
+ return seams.planSearch(input);
33
+ }
34
+ export function presentSearch(seams, plan, matches) {
35
+ return seams.presentSearch(plan, matches);
36
+ }
37
+ export function formatOmpIssues(issues) {
38
+ return issues.map((issue) => `${issue.field}: ${issue.message}`).join("; ");
39
+ }
40
+ //# sourceMappingURL=omp-seam-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omp-seam-runtime.js","sourceRoot":"","sources":["../../../src/core/tools/omp-seam-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAqB,MAAM,qBAAqB,CAAC;AAiE7F,IAAI,MAAyC,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,WAAW,GAAsC;IAChE,IAAI,CAAC,iBAAiB,EAAE;QAAE,OAAO,SAAS,CAAC;IAC3C,MAAM,KAAK,gBAAgB,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC;AAAA,CACd;AAED,MAAM,UAAU,QAAQ,CAAC,KAAmB,EAAE,KAAc,EAAqB;IAChF,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAsB,CAAC;AAAA,CAClD;AAED,MAAM,UAAU,WAAW,CAC1B,KAAmB,EACnB,IAAiB,EACjB,IAAwG,EACjF;IACvB,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAyB,CAAC;AAAA,CAC7D;AAED,MAAM,UAAU,UAAU,CAAC,KAAmB,EAAE,KAAc,EAAuB;IACpF,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAwB,CAAC;AAAA,CACtD;AAED,MAAM,UAAU,aAAa,CAC5B,KAAmB,EACnB,IAAmB,EACnB,OAAsC,EACb;IACzB,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAA2B,CAAC;AAAA,CACpE;AAED,MAAM,UAAU,eAAe,CAAC,MAA2B,EAAU;IACpE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CAC5E","sourcesContent":["/**\n * Typed runtime facade over the flag-gated OMP pure-seam loader.\n *\n * Wiring boundary for I2 (ADR-OMP-008/009): the read and grep tools delegate\n * request validation and output presentation to the vendored OMP pure seams.\n * Enabled by default; `OMK_OMP_SEAMS=0` opts out and tool behavior falls back\n * byte-identically to the pre-seam implementation.\n *\n * The loader exposes unknown-in/unknown-out signatures; all structural\n * assertions live in this single file so tool code stays clean.\n */\nimport { isOmpSeamsEnabled, loadOmpPureSeams, type OmpPureSeams } from \"./omp-pure-seams.ts\";\n\nexport interface OmpIssue {\n\treadonly field: string;\n\treadonly code: string;\n\treadonly message: string;\n}\n\nexport interface OmpReadPlan {\n\treadonly path: string;\n\treadonly offset: number;\n\treadonly limit: number;\n}\n\nexport type OmpReadPlanResult =\n\t| { readonly ok: true; readonly plan: OmpReadPlan }\n\t| { readonly ok: false; readonly issues: readonly OmpIssue[] };\n\nexport interface OmpReadPresentation {\n\treadonly text: string;\n\treadonly window: {\n\t\treadonly startLine: number;\n\t\treadonly endLine: number;\n\t\treadonly totalLines: number;\n\t\treadonly truncated: boolean;\n\t};\n}\n\nexport type OmpReadPresentResult =\n\t| { readonly ok: true; readonly presentation: OmpReadPresentation }\n\t| { readonly ok: false; readonly conflicts: readonly unknown[] };\n\nexport interface OmpSearchPlan {\n\treadonly pattern: string;\n\treadonly path: string;\n\treadonly glob?: string;\n\treadonly ignoreCase: boolean;\n\treadonly literal: boolean;\n\treadonly context: number;\n\treadonly limit: number;\n}\n\nexport type OmpSearchPlanResult =\n\t| { readonly ok: true; readonly plan: OmpSearchPlan }\n\t| { readonly ok: false; readonly issues: readonly OmpIssue[] };\n\nexport interface OmpSearchHostMatch {\n\treadonly file: string;\n\treadonly line: number;\n\treadonly column?: number;\n\treadonly text: string;\n\treadonly expectedLineHash?: string;\n}\n\nexport interface OmpSearchPresentation {\n\treadonly text: string;\n\treadonly totalMatches: number;\n\treadonly omittedMatches: number;\n\treadonly truncated: boolean;\n}\n\nexport type OmpSearchPresentResult =\n\t| { readonly ok: true; readonly presentation: OmpSearchPresentation }\n\t| { readonly ok: false; readonly conflicts: readonly unknown[] };\n\nlet cached: Promise<OmpPureSeams> | undefined;\n\n/**\n * Returns the memoized seam set unless `OMK_OMP_SEAMS=0`; `undefined` when\n * opted out. Loader errors (VENDOR_NOT_FOUND, INVALID_SEAM) propagate to\n * the caller of the returned promise.\n */\nexport function getOmpSeams(): Promise<OmpPureSeams> | undefined {\n\tif (!isOmpSeamsEnabled()) return undefined;\n\tcached ??= loadOmpPureSeams();\n\treturn cached;\n}\n\nexport function planRead(seams: OmpPureSeams, input: unknown): OmpReadPlanResult {\n\treturn seams.planRead(input) as OmpReadPlanResult;\n}\n\nexport function presentRead(\n\tseams: OmpPureSeams,\n\tplan: OmpReadPlan,\n\tfile: { text: string; sourceDigest?: string; lineDigests?: readonly { line: number; digest: string }[] },\n): OmpReadPresentResult {\n\treturn seams.presentRead(plan, file) as OmpReadPresentResult;\n}\n\nexport function planSearch(seams: OmpPureSeams, input: unknown): OmpSearchPlanResult {\n\treturn seams.planSearch(input) as OmpSearchPlanResult;\n}\n\nexport function presentSearch(\n\tseams: OmpPureSeams,\n\tplan: OmpSearchPlan,\n\tmatches: readonly OmpSearchHostMatch[],\n): OmpSearchPresentResult {\n\treturn seams.presentSearch(plan, matches) as OmpSearchPresentResult;\n}\n\nexport function formatOmpIssues(issues: readonly OmpIssue[]): string {\n\treturn issues.map((issue) => `${issue.field}: ${issue.message}`).join(\"; \");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAItF,OAAO,EAAoD,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEtH,QAAA,MAAM,UAAU;;;;EAId,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AASD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,+CAA+C;IAC/C,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACnF;AAQD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC;CAChD;AA4ID,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA2JhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { basename, dirname, isAbsolute, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport type { AgentTool } from \"omk-agent-core\";\nimport type { Api, ImageContent, Model, TextContent } from \"omk-ai\";\nimport { Text } from \"omk-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.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\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n\tcanReadPath?: (absolutePath: string) => boolean;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getOmkDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getOmkDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\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). 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\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (options?.canReadPath && !options.canReadPath(absolutePath)) {\n\t\t\t\t\t\t\t\tthrow new Error(`Read blocked by active loadout policy: ${path}`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\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\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\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\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAUtF,OAAO,EAAoD,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEtH,QAAA,MAAM,UAAU;;;;EAId,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AASD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,+CAA+C;IAC/C,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACnF;AAQD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC;CAChD;AA4ID,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAyLhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { basename, dirname, isAbsolute, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport type { AgentTool } from \"omk-agent-core\";\nimport type { Api, ImageContent, Model, TextContent } from \"omk-ai\";\nimport { Text } from \"omk-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport {\n\tformatOmpIssues,\n\tgetOmpSeams,\n\tplanRead as ompPlanRead,\n\tpresentRead as ompPresentRead,\n} from \"./omp-seam-runtime.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.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\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n\tcanReadPath?: (absolutePath: string) => boolean;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getOmkDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getOmkDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\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). 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\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (options?.canReadPath && !options.canReadPath(absolutePath)) {\n\t\t\t\t\t\t\t\tthrow new Error(`Read blocked by active loadout policy: ${path}`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tconst ompSeamsPromise = mimeType ? undefined : getOmpSeams();\n\t\t\t\t\t\t\tif (ompSeamsPromise) {\n\t\t\t\t\t\t\t\t// OMP seam path (OMK_OMP_SEAMS=1): validation and presentation are\n\t\t\t\t\t\t\t\t// delegated to the vendored pure read seam (ADR-OMP-008). The host\n\t\t\t\t\t\t\t\t// still performs path resolution, policy checks, and file I/O.\n\t\t\t\t\t\t\t\tconst seams = await ompSeamsPromise;\n\t\t\t\t\t\t\t\tconst planned = ompPlanRead(seams, { path, offset, limit });\n\t\t\t\t\t\t\t\tif (!planned.ok) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Invalid read request: ${formatOmpIssues(planned.issues)}`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst plan = planned.plan;\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst normLines = textContent.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n\t\t\t\t\t\t\t\tconst endLine = Math.min(plan.offset + plan.limit - 1, normLines.length);\n\t\t\t\t\t\t\t\tconst windowTexts: string[] = [];\n\t\t\t\t\t\t\t\tfor (let n = plan.offset; n <= endLine; n += 1) windowTexts.push(normLines[n - 1] ?? \"\");\n\t\t\t\t\t\t\t\tconst [sourceDigest, ...lineHashes] = await Promise.all([\n\t\t\t\t\t\t\t\t\tseams.hashProposalSource(textContent),\n\t\t\t\t\t\t\t\t\t...windowTexts.map((lineText) => seams.hashProposalLine(lineText)),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst presented = ompPresentRead(seams, plan, {\n\t\t\t\t\t\t\t\t\ttext: textContent,\n\t\t\t\t\t\t\t\t\tsourceDigest,\n\t\t\t\t\t\t\t\t\tlineDigests: lineHashes.map((digest, i) => ({ line: plan.offset + i, digest })),\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!presented.ok) {\n\t\t\t\t\t\t\t\t\tthrow new Error(\"OMP read presentation failed: conflicting line digests\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: presented.presentation.text }];\n\t\t\t\t\t\t\t} else if (mimeType) {\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\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\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\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\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
@@ -9,6 +9,7 @@ import { getLanguageFromPath, highlightCode } from "../../modes/interactive/them
9
9
  import { formatDimensionNote, resizeImage } from "../../utils/image-resize.js";
10
10
  import { detectSupportedImageMimeTypeFromFile } from "../../utils/mime.js";
11
11
  import { formatPathRelativeToCwdOrAbsolute } from "../../utils/paths.js";
12
+ import { formatOmpIssues, getOmpSeams, planRead as ompPlanRead, presentRead as ompPresentRead, } from "./omp-seam-runtime.js";
12
13
  import { resolveReadPathAsync, resolveToCwd } from "./path-utils.js";
13
14
  import { getTextOutput, renderToolPath, replaceTabs, str } from "./render-utils.js";
14
15
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
@@ -165,7 +166,39 @@ export function createReadToolDefinition(cwd, options) {
165
166
  let content;
166
167
  let details;
167
168
  const nonVisionImageNote = getNonVisionImageNote(ctx?.model);
168
- if (mimeType) {
169
+ const ompSeamsPromise = mimeType ? undefined : getOmpSeams();
170
+ if (ompSeamsPromise) {
171
+ // OMP seam path (OMK_OMP_SEAMS=1): validation and presentation are
172
+ // delegated to the vendored pure read seam (ADR-OMP-008). The host
173
+ // still performs path resolution, policy checks, and file I/O.
174
+ const seams = await ompSeamsPromise;
175
+ const planned = ompPlanRead(seams, { path, offset, limit });
176
+ if (!planned.ok) {
177
+ throw new Error(`Invalid read request: ${formatOmpIssues(planned.issues)}`);
178
+ }
179
+ const plan = planned.plan;
180
+ const buffer = await ops.readFile(absolutePath);
181
+ const textContent = buffer.toString("utf-8");
182
+ const normLines = textContent.replace(/\r\n?/g, "\n").split("\n");
183
+ const endLine = Math.min(plan.offset + plan.limit - 1, normLines.length);
184
+ const windowTexts = [];
185
+ for (let n = plan.offset; n <= endLine; n += 1)
186
+ windowTexts.push(normLines[n - 1] ?? "");
187
+ const [sourceDigest, ...lineHashes] = await Promise.all([
188
+ seams.hashProposalSource(textContent),
189
+ ...windowTexts.map((lineText) => seams.hashProposalLine(lineText)),
190
+ ]);
191
+ const presented = ompPresentRead(seams, plan, {
192
+ text: textContent,
193
+ sourceDigest,
194
+ lineDigests: lineHashes.map((digest, i) => ({ line: plan.offset + i, digest })),
195
+ });
196
+ if (!presented.ok) {
197
+ throw new Error("OMP read presentation failed: conflicting line digests");
198
+ }
199
+ content = [{ type: "text", text: presented.presentation.text }];
200
+ }
201
+ else if (mimeType) {
169
202
  // Read image as binary.
170
203
  const buffer = await ops.readFile(absolutePath);
171
204
  if (autoResizeImages) {