@thegitai/cli 1.0.0-beta.1 → 1.0.0-beta.10

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 (45) hide show
  1. package/README.md +4 -3
  2. package/dist/bin/ai.js +18 -61
  3. package/dist/parsers/NOTICE +18 -0
  4. package/dist/src/api/auth.js +4 -2
  5. package/dist/src/api/browser-login.js +10 -28
  6. package/dist/src/api/chat.js +20 -9
  7. package/dist/src/api/http.js +32 -3
  8. package/dist/src/api/models.js +4 -2
  9. package/dist/src/artifact-policy.js +9 -0
  10. package/dist/src/cli-args.js +65 -0
  11. package/dist/src/client-environment.js +127 -0
  12. package/dist/src/colors.js +59 -0
  13. package/dist/src/core/clipboard.js +56 -0
  14. package/dist/src/edit-journal.js +39 -6
  15. package/dist/src/executor.js +28 -5
  16. package/dist/src/help-text.js +15 -1
  17. package/dist/src/markdown-renderer.js +1 -1
  18. package/dist/src/patcher.js +18 -1
  19. package/dist/src/scanner.js +67 -17
  20. package/dist/src/session-safety.js +64 -12
  21. package/dist/src/tool-executor.js +8 -0
  22. package/dist/src/tools/delete-file.js +1 -1
  23. package/dist/src/tools/index.js +2 -0
  24. package/dist/src/tools/patch-file.js +14 -1
  25. package/dist/src/tools/path-suggest.js +66 -0
  26. package/dist/src/tools/read-document.js +14 -3
  27. package/dist/src/tools/read-file.js +9 -0
  28. package/dist/src/tools/replace-document-text.js +242 -0
  29. package/dist/src/tools/restore-checkpoint.js +1 -1
  30. package/dist/src/tools/run-command.js +1 -1
  31. package/dist/src/tools/run-node-script.js +1 -1
  32. package/dist/src/tools/str-replace.js +14 -1
  33. package/dist/src/tools/undo-edit.js +7 -5
  34. package/dist/src/tools/write-file.js +14 -1
  35. package/dist/src/tree-sitter-runtime.js +14 -1
  36. package/dist/src/ui/repl.js +13 -1
  37. package/dist/src/ui/tui/bridge.js +2 -2
  38. package/dist/src/ui/tui/build-frame.js +18 -2
  39. package/dist/src/ui/tui/shell-input.js +9 -1
  40. package/dist/src/version.js +35 -0
  41. package/dist/vendor/web-tree-sitter/LICENSE +21 -0
  42. package/dist/vendor/web-tree-sitter/NOTICE +13 -0
  43. package/dist/vendor/web-tree-sitter/web-tree-sitter.cjs +4063 -0
  44. package/dist/vendor/web-tree-sitter/web-tree-sitter.wasm +0 -0
  45. package/package.json +15 -16
@@ -2,14 +2,14 @@ import { execFileSync } from 'node:child_process';
2
2
  import { lstatSync, readdirSync } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { ARTIFACT_IGNORE_DIRS, normalizeProjectRelativePath, shouldIgnoreArtifactPath, } from './artifact-policy.js';
5
- import { hashContent, readFileEditSnapshot } from './edit-journal.js';
6
- import { deleteProjectFile, resolveProjectPath, writeProjectFile } from './patcher.js';
5
+ import { hashBytes, readFileEditSnapshot, storedContentBuffer, } from './edit-journal.js';
6
+ import { deleteProjectFile, resolveProjectPath, writeProjectFile, writeProjectFileBuffer, } from './patcher.js';
7
7
  import { removeIndexFile, upsertIndexFile } from './project-index.js';
8
8
  const MAX_CHECKPOINTS = 20;
9
9
  const MAX_SESSION_EDITS = 500;
10
10
  const MAX_READ_RECORDS = 200;
11
11
  const MAX_REDACTION_TOKENS = 500;
12
- const MAX_SNAPSHOT_CONTENT_CHARS = 1_000_000;
12
+ const MAX_SNAPSHOT_CONTENT_CHARS = 8_000_000;
13
13
  const MAX_MUTATION_SCAN_FILES = 2000;
14
14
  const MAX_BASELINE_CONTENT_BYTES = 50 * 1024 * 1024;
15
15
  export function createSessionSafetyState() {
@@ -34,6 +34,14 @@ function normalizeEditOperation(value) {
34
34
  ? text
35
35
  : null;
36
36
  }
37
+ function normalizeStoredContentEncoding(value) {
38
+ return value === 'base64' ? 'base64' : 'utf8';
39
+ }
40
+ function writeStoredProjectFile(rootDir, filePath, content, encoding) {
41
+ return encoding === 'base64'
42
+ ? writeProjectFileBuffer(rootDir, filePath, storedContentBuffer(content, encoding))
43
+ : writeProjectFile(rootDir, filePath, content);
44
+ }
37
45
  export function normalizeSessionSafetyState(value) {
38
46
  const raw = value && typeof value === 'object' ? value : {};
39
47
  const safety = createSessionSafetyState();
@@ -57,6 +65,7 @@ export function normalizeSessionSafetyState(value) {
57
65
  exists: file.exists === true,
58
66
  hash: typeof file.hash === 'string' ? file.hash : null,
59
67
  content: typeof file.content === 'string' ? file.content : null,
68
+ contentEncoding: normalizeStoredContentEncoding(file.contentEncoding),
60
69
  skipped: typeof file.skipped === 'string' && file.skipped.trim()
61
70
  ? file.skipped.trim()
62
71
  : undefined,
@@ -143,6 +152,7 @@ export function normalizeSessionSafetyState(value) {
143
152
  beforeHash: typeof item.beforeHash === 'string' ? item.beforeHash : null,
144
153
  afterHash: typeof item.afterHash === 'string' ? item.afterHash : null,
145
154
  beforeContent: typeof item.beforeContent === 'string' ? item.beforeContent : null,
155
+ beforeContentEncoding: normalizeStoredContentEncoding(item.beforeContentEncoding),
146
156
  createdAt: typeof item.createdAt === 'string' && item.createdAt
147
157
  ? item.createdAt
148
158
  : new Date().toISOString(),
@@ -242,7 +252,10 @@ export function mergeLocalSessionSafetyState(local, incoming) {
242
252
  for (const file of checkpoint.files) {
243
253
  if (file.content == null)
244
254
  continue;
245
- localCheckpointContent.set(`${checkpoint.id}\0${file.filePath}\0${file.hash ?? ''}`, file.content);
255
+ localCheckpointContent.set(`${checkpoint.id}\0${file.filePath}\0${file.hash ?? ''}`, {
256
+ content: file.content,
257
+ contentEncoding: file.contentEncoding,
258
+ });
246
259
  }
247
260
  }
248
261
  next.checkpoints = next.checkpoints.map((checkpoint) => ({
@@ -251,17 +264,35 @@ export function mergeLocalSessionSafetyState(local, incoming) {
251
264
  if (file.content != null)
252
265
  return file;
253
266
  const content = localCheckpointContent.get(`${checkpoint.id}\0${file.filePath}\0${file.hash ?? ''}`);
254
- return content == null ? file : { ...file, content };
267
+ return content == null
268
+ ? file
269
+ : {
270
+ ...file,
271
+ content: content.content,
272
+ contentEncoding: content.contentEncoding,
273
+ };
255
274
  }),
256
275
  }));
257
276
  const localBeforeContent = new Map(localState.sessionEdits
258
277
  .filter((edit) => edit.beforeContent != null)
259
- .map((edit) => [edit.id, edit.beforeContent]));
278
+ .map((edit) => [
279
+ edit.id,
280
+ {
281
+ beforeContent: edit.beforeContent,
282
+ beforeContentEncoding: edit.beforeContentEncoding,
283
+ },
284
+ ]));
260
285
  next.sessionEdits = next.sessionEdits.map((edit) => {
261
286
  if (edit.beforeContent != null)
262
287
  return edit;
263
288
  const beforeContent = localBeforeContent.get(edit.id);
264
- return beforeContent == null ? edit : { ...edit, beforeContent };
289
+ return beforeContent == null
290
+ ? edit
291
+ : {
292
+ ...edit,
293
+ beforeContent: beforeContent.beforeContent,
294
+ beforeContentEncoding: beforeContent.beforeContentEncoding,
295
+ };
265
296
  });
266
297
  return next;
267
298
  }
@@ -279,6 +310,7 @@ function readCheckpointSnapshot(rootDir, filePath) {
279
310
  exists: false,
280
311
  hash: null,
281
312
  content: null,
313
+ contentEncoding: 'utf8',
282
314
  skipped: `Refusing to checkpoint ignored or out-of-project path: ${filePath}`,
283
315
  };
284
316
  }
@@ -289,6 +321,7 @@ function readCheckpointSnapshot(rootDir, filePath) {
289
321
  exists: snapshot.exists,
290
322
  hash: snapshot.hash,
291
323
  content: null,
324
+ contentEncoding: snapshot.contentEncoding,
292
325
  skipped: snapshot.error,
293
326
  };
294
327
  }
@@ -298,6 +331,7 @@ function readCheckpointSnapshot(rootDir, filePath) {
298
331
  exists: snapshot.exists,
299
332
  hash: snapshot.hash,
300
333
  content: null,
334
+ contentEncoding: snapshot.contentEncoding,
301
335
  skipped: `File is too large to checkpoint (${snapshot.content.length} chars).`,
302
336
  };
303
337
  }
@@ -306,6 +340,7 @@ function readCheckpointSnapshot(rootDir, filePath) {
306
340
  exists: snapshot.exists,
307
341
  hash: snapshot.hash,
308
342
  content: snapshot.content,
343
+ contentEncoding: snapshot.contentEncoding,
309
344
  };
310
345
  }
311
346
  export function createPromptCheckpoint(state, label, turnId) {
@@ -661,7 +696,7 @@ export async function restoreCheckpointFiles(args) {
661
696
  const before = readFileEditSnapshot(args.rootDir, snapshot.filePath);
662
697
  try {
663
698
  if (snapshot.exists) {
664
- const result = writeProjectFile(args.rootDir, snapshot.filePath, snapshot.content ?? '');
699
+ const result = writeStoredProjectFile(args.rootDir, snapshot.filePath, snapshot.content ?? '', snapshot.contentEncoding);
665
700
  if (result.changed)
666
701
  changed = true;
667
702
  if (syncPolicy)
@@ -693,7 +728,7 @@ export async function restoreCheckpointFiles(args) {
693
728
  if (item.before.content == null) {
694
729
  throw new Error('previous file content is unavailable');
695
730
  }
696
- writeProjectFile(args.rootDir, item.snapshot.filePath, item.before.content);
731
+ writeStoredProjectFile(args.rootDir, item.snapshot.filePath, item.before.content, item.before.contentEncoding);
697
732
  if (syncPolicy) {
698
733
  await upsertIndexFile(args.projectIndex, item.snapshot.filePath);
699
734
  }
@@ -749,6 +784,7 @@ export async function restoreCheckpointFiles(args) {
749
784
  beforeHash: item.before.hash,
750
785
  afterHash: item.after.hash,
751
786
  beforeContent: item.before.content,
787
+ beforeContentEncoding: item.before.contentEncoding,
752
788
  checkpointId: checkpoint.id,
753
789
  });
754
790
  restored.push({
@@ -777,6 +813,18 @@ function git(args, cwd) {
777
813
  return null;
778
814
  }
779
815
  }
816
+ function gitBuffer(args, cwd) {
817
+ try {
818
+ return execFileSync('git', args, {
819
+ cwd,
820
+ stdio: ['ignore', 'pipe', 'ignore'],
821
+ timeout: 10_000,
822
+ });
823
+ }
824
+ catch {
825
+ return null;
826
+ }
827
+ }
780
828
  export function findGitRoot(startDir) {
781
829
  const root = git(['rev-parse', '--show-toplevel'], startDir);
782
830
  return root ? path.resolve(root) : null;
@@ -897,14 +945,15 @@ function readGitHeadSnapshot(rootDir, filePath) {
897
945
  return null;
898
946
  const abs = resolveProjectPath(rootDir, filePath);
899
947
  const relToGit = path.relative(gitRoot, abs).split(path.sep).join('/');
900
- const content = git(['show', `HEAD:${relToGit}`], gitRoot);
948
+ const content = gitBuffer(['show', `HEAD:${relToGit}`], gitRoot);
901
949
  if (content == null)
902
950
  return null;
903
951
  return {
904
952
  filePath,
905
953
  exists: true,
906
- hash: hashContent(content),
907
- content,
954
+ hash: hashBytes(content),
955
+ content: content.toString('base64'),
956
+ contentEncoding: 'base64',
908
957
  };
909
958
  }
910
959
  export function captureMutationBaseline(rootDir, options) {
@@ -932,6 +981,7 @@ export function captureMutationBaseline(rootDir, options) {
932
981
  exists: true,
933
982
  hash: null,
934
983
  content: null,
984
+ contentEncoding: 'utf8',
935
985
  skipped: `Pre-command snapshot skipped: project baseline content budget exceeded (${contentBudget} bytes). Restore for this file is not available.`,
936
986
  });
937
987
  continue;
@@ -978,6 +1028,7 @@ export function collectCommandMutations(args) {
978
1028
  exists: false,
979
1029
  hash: null,
980
1030
  content: null,
1031
+ contentEncoding: 'utf8',
981
1032
  };
982
1033
  if (before.hash === after.hash && !before.skipped)
983
1034
  continue;
@@ -1000,6 +1051,7 @@ export function collectCommandMutations(args) {
1000
1051
  beforeHash: before.hash,
1001
1052
  afterHash: after.hash,
1002
1053
  beforeContent: before.content,
1054
+ beforeContentEncoding: before.contentEncoding,
1003
1055
  checkpointId: args.checkpointId,
1004
1056
  });
1005
1057
  records.push(record);
@@ -32,6 +32,12 @@ export function formatToolCallForStatus(call) {
32
32
  }
33
33
  function getEditToolFilePath(call) {
34
34
  const args = call.args && typeof call.args === 'object' ? call.args : {};
35
+ if (call.name === 'replace_document_text') {
36
+ const outputPath = args.outputPath ?? args.output_path;
37
+ if (typeof outputPath === 'string' && outputPath.trim()) {
38
+ return outputPath.trim();
39
+ }
40
+ }
35
41
  for (const key of EDIT_FILE_PATH_ARG_ALIASES) {
36
42
  const value = args[key];
37
43
  if (typeof value === 'string' && value.trim())
@@ -79,6 +85,7 @@ function recordAssistantEdit(session, call, result, before) {
79
85
  beforeHash: before.hash,
80
86
  afterHash: after.hash,
81
87
  beforeContent: operation === 'create' ? null : before.content,
88
+ beforeContentEncoding: before.contentEncoding,
82
89
  createdAt: new Date().toISOString(),
83
90
  revertedAt: null,
84
91
  revertedByToolCallId: null,
@@ -98,6 +105,7 @@ function recordAssistantEdit(session, call, result, before) {
98
105
  beforeHash: before.hash,
99
106
  afterHash: after.hash,
100
107
  beforeContent: operation === 'create' ? null : before.content,
108
+ beforeContentEncoding: before.contentEncoding,
101
109
  checkpointId: checkpoint.id,
102
110
  });
103
111
  clearEditFailure(session.clientState.safety, filePath);
@@ -1,4 +1,4 @@
1
- import chalk from 'chalk';
1
+ import chalk from '../colors.js';
2
2
  import { deleteProjectFile } from '../patcher.js';
3
3
  import { isTuiMode } from '../runtime-mode.js';
4
4
  import { removeIndexFile } from '../project-index.js';
@@ -11,6 +11,7 @@ import { listSymbols } from './list-symbols.js';
11
11
  import { patchFile } from './patch-file.js';
12
12
  import { readDocument } from './read-document.js';
13
13
  import { readFile } from './read-file.js';
14
+ import { replaceDocumentText } from './replace-document-text.js';
14
15
  import { runShellCommand } from './run-command.js';
15
16
  import { runNodeScript } from './run-node-script.js';
16
17
  import { restoreFilesToCheckpoint, restoreToCheckpoint, } from './restore-checkpoint.js';
@@ -25,6 +26,7 @@ export const TOOL_MAP = {
25
26
  list_directories: (context, args) => listDirectories(context, args),
26
27
  read_file: (context, args) => readFile(context, args),
27
28
  read_document: (context, args) => readDocument(context.rootDir, args, context.env),
29
+ replace_document_text: replaceDocumentText,
28
30
  grep_code: (context, args) => grepCode(context.rootDir, args),
29
31
  find_symbol: (context, args) => findSymbol(context, args),
30
32
  list_symbols: (context, args) => listSymbols(context, args),
@@ -1,10 +1,12 @@
1
- import chalk from 'chalk';
1
+ import chalk from '../colors.js';
2
+ import path from 'node:path';
2
3
  import { normalizeProjectRelativePath } from '../artifact-policy.js';
3
4
  import { applyUnifiedPatch, readProjectFile, renderDiffPreview, writeProjectFile, } from '../patcher.js';
4
5
  import { upsertIndexFile } from '../project-index.js';
5
6
  import { isTuiMode } from '../runtime-mode.js';
6
7
  import { getCurrentFileHash, resolveRedactionTokens } from '../session-safety.js';
7
8
  import { invalidateShellDiagnosticsCache, runShellDiagnostics, } from './shell-diagnostics.js';
9
+ const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
8
10
  export async function patchFile(context, args) {
9
11
  const { rootDir, projectIndex, autoYes, confirmPatch } = context;
10
12
  const filePath = String(args.filePath ?? '').trim();
@@ -15,6 +17,17 @@ export async function patchFile(context, args) {
15
17
  if (!patch.trim()) {
16
18
  return { ok: false, error: 'patch is required' };
17
19
  }
20
+ const ext = path.extname(filePath).toLowerCase();
21
+ if (DOCUMENT_EXTENSIONS.has(ext)) {
22
+ return {
23
+ ok: false,
24
+ filePath,
25
+ error: ext === '.docx'
26
+ ? 'Use replace_document_text for .docx files.'
27
+ : `Use read_document for ${ext} files; patching is not supported.`,
28
+ failureCategory: 'invalid_argument',
29
+ };
30
+ }
18
31
  let originalContent;
19
32
  try {
20
33
  originalContent = readProjectFile(rootDir, filePath);
@@ -0,0 +1,66 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { isSensitiveProjectPath } from '../artifact-policy.js';
4
+ // "File not found" recovery hint: when a model mistypes a filename (most
5
+ // often Unicode punctuation — a straight ' for a curly ’ — or a small typo),
6
+ // suggest the closest real file from the same directory.
7
+ function foldName(name) {
8
+ return name
9
+ .normalize('NFC')
10
+ .replace(/[‘’ʼ]/g, "'")
11
+ .replace(/[“”]/g, '"')
12
+ .replace(/ /g, ' ')
13
+ .toLowerCase();
14
+ }
15
+ function levenshtein(a, b) {
16
+ if (a === b)
17
+ return 0;
18
+ const rows = a.length + 1;
19
+ const cols = b.length + 1;
20
+ let prev = Array.from({ length: cols }, (_, j) => j);
21
+ for (let i = 1; i < rows; i++) {
22
+ const current = [i, ...new Array(cols - 1).fill(0)];
23
+ for (let j = 1; j < cols; j++) {
24
+ current[j] = Math.min(prev[j] + 1, current[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
25
+ }
26
+ prev = current;
27
+ }
28
+ return prev[cols - 1];
29
+ }
30
+ export function suggestClosestPath(rootDir, missingPath) {
31
+ const resolved = path.isAbsolute(missingPath)
32
+ ? missingPath
33
+ : path.resolve(rootDir, missingPath);
34
+ const directory = path.dirname(resolved);
35
+ const wantedBase = foldName(path.basename(resolved));
36
+ if (!wantedBase)
37
+ return null;
38
+ let candidates;
39
+ try {
40
+ candidates = readdirSync(directory);
41
+ }
42
+ catch {
43
+ return null;
44
+ }
45
+ const threshold = Math.max(2, Math.floor(wantedBase.length * 0.25));
46
+ let best = null;
47
+ let bestDistance = Number.POSITIVE_INFINITY;
48
+ for (const candidate of candidates) {
49
+ // Never suggest a file the caller would refuse to read/write directly:
50
+ // probing a near-miss like `.enx` or `credential.docx` must not leak the
51
+ // existence of `.env`/credentials through the recovery hint.
52
+ const candidateRelative = path.relative(rootDir, path.join(directory, candidate));
53
+ if (isSensitiveProjectPath(candidateRelative))
54
+ continue;
55
+ const distance = levenshtein(wantedBase, foldName(candidate));
56
+ if (distance < bestDistance) {
57
+ bestDistance = distance;
58
+ best = candidate;
59
+ }
60
+ }
61
+ if (!best || bestDistance > threshold)
62
+ return null;
63
+ const suggested = path.join(directory, best);
64
+ const relative = path.relative(rootDir, suggested);
65
+ return relative && !relative.startsWith('..') ? relative : suggested;
66
+ }
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { isSensitiveProjectPath, normalizeProjectRelativePath, } from '../artifact-policy.js';
4
+ import { suggestClosestPath } from './path-suggest.js';
4
5
  import { readCliAuthConfig } from '../api/auth.js';
5
6
  export function normalizeDocumentText(raw) {
6
7
  const text = String(raw ?? '').replace(/\r\n?/g, '\n');
@@ -36,6 +37,7 @@ export function normalizeDocumentText(raw) {
36
37
  }
37
38
  async function parseDocumentOnServer(config, fileName, fileData, ext, args) {
38
39
  const includePageArgs = ext === '.pdf';
40
+ const includeParagraphArgs = ext === '.docx';
39
41
  const response = await globalThis.fetch(`${config.serverUrl.replace(/\/+$/, '')}/v1/document/parse`, {
40
42
  method: 'POST',
41
43
  headers: {
@@ -51,6 +53,12 @@ async function parseDocumentOnServer(config, fileName, fileData, ext, args) {
51
53
  ...(includePageArgs && args.lastPage !== undefined
52
54
  ? { lastPage: args.lastPage }
53
55
  : {}),
56
+ ...(includeParagraphArgs && args.firstParagraph !== undefined
57
+ ? { firstParagraph: args.firstParagraph }
58
+ : {}),
59
+ ...(includeParagraphArgs && args.lastParagraph !== undefined
60
+ ? { lastParagraph: args.lastParagraph }
61
+ : {}),
54
62
  }),
55
63
  });
56
64
  const data = await response.json().catch(() => null);
@@ -76,17 +84,20 @@ export async function readDocument(rootDir, args, env) {
76
84
  };
77
85
  }
78
86
  if (!existsSync(resolvedPath)) {
87
+ const suggestion = suggestClosestPath(rootDir, resolvedPath);
79
88
  return {
80
89
  ok: false,
81
- error: `File not found: ${resolvedPath}`,
90
+ error: suggestion
91
+ ? `File not found: ${resolvedPath}. Did you mean "${suggestion}"? Note the exact punctuation (e.g. curly apostrophe ’ vs straight ').`
92
+ : `File not found: ${resolvedPath}`,
82
93
  failureCategory: 'not_found',
83
94
  };
84
95
  }
85
96
  const ext = path.extname(resolvedPath).toLowerCase();
86
- if (ext !== '.pdf' && ext !== '.xlsx') {
97
+ if (ext !== '.pdf' && ext !== '.xlsx' && ext !== '.docx') {
87
98
  return {
88
99
  ok: false,
89
- error: `Unsupported file type: "${ext}". read_document only supports .pdf and .xlsx.`,
100
+ error: `Unsupported file type: "${ext}". read_document only supports .pdf, .xlsx, and .docx.`,
90
101
  };
91
102
  }
92
103
  const authConfig = readCliAuthConfig(env);
@@ -6,6 +6,7 @@ import { readProjectFile } from '../patcher.js';
6
6
  import { dotenvFitsRedactionBudget, getCurrentFileHash, recordReadCoverage, redactContentWithStableTokens, redactDotenvWithStableTokens, } from '../session-safety.js';
7
7
  import { readFileRange, truncate } from '../utils.js';
8
8
  const MAX_FILE_READ_CHARS = 12000;
9
+ const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
9
10
  export async function readFile(context, args) {
10
11
  const rootDir = typeof context === 'string' ? context : context.rootDir;
11
12
  const safety = typeof context === 'string' ? undefined : context.safety;
@@ -26,6 +27,14 @@ export async function readFile(context, args) {
26
27
  error: 'This path is not permitted.',
27
28
  };
28
29
  }
30
+ const documentExt = path.extname(projectPath ?? filePath).toLowerCase();
31
+ if (DOCUMENT_EXTENSIONS.has(documentExt)) {
32
+ return {
33
+ ok: false,
34
+ error: `Use read_document for ${documentExt} files.`,
35
+ failureCategory: 'invalid_argument',
36
+ };
37
+ }
29
38
  let content;
30
39
  if (projectPath) {
31
40
  try {