@thegitai/cli 1.0.0-preview.9 → 1.0.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 (99) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +301 -15
  3. package/dist/bin/ai.js +139 -111
  4. package/dist/bin/browser-host.js +284 -0
  5. package/dist/src/agent-mode.js +33 -7
  6. package/dist/src/api/auth.js +8 -2
  7. package/dist/src/api/browser-login.js +77 -34
  8. package/dist/src/api/chat.js +700 -173
  9. package/dist/src/api/contracts.js +55 -1
  10. package/dist/src/api/default-host.js +1 -0
  11. package/dist/src/api/http.js +168 -8
  12. package/dist/src/api/models.js +47 -9
  13. package/dist/src/api/startup-handshake.js +36 -0
  14. package/dist/src/api/turn-recovery.js +189 -0
  15. package/dist/src/background-jobs.js +8 -2
  16. package/dist/src/browser/bridge.js +268 -0
  17. package/dist/src/browser/chrome-profiles.js +73 -0
  18. package/dist/src/browser/framing.js +42 -0
  19. package/dist/src/browser/native-host.js +219 -0
  20. package/dist/src/browser/protocol.js +46 -0
  21. package/dist/src/browser/session-bridge.js +130 -0
  22. package/dist/src/cli-args.js +19 -5
  23. package/dist/src/client-environment.js +2 -0
  24. package/dist/src/core/clipboard.js +8 -14
  25. package/dist/src/core/image-limits.js +56 -0
  26. package/dist/src/core/image-path-extractor.js +70 -3
  27. package/dist/src/core/session-image-store.js +246 -0
  28. package/dist/src/edit-journal.js +33 -2
  29. package/dist/src/executor.js +26 -4
  30. package/dist/src/help-text.js +152 -41
  31. package/dist/src/install-id.js +32 -0
  32. package/dist/src/job-follow-up.js +40 -0
  33. package/dist/src/mcp-client.js +335 -0
  34. package/dist/src/mcp-command.js +176 -0
  35. package/dist/src/mcp-config.js +123 -0
  36. package/dist/src/mcp-sdk.js +3 -0
  37. package/dist/src/mcp-types.js +26 -0
  38. package/dist/src/patcher.js +46 -4
  39. package/dist/src/permissions.js +301 -0
  40. package/dist/src/preferences.js +39 -0
  41. package/dist/src/project-key.js +11 -0
  42. package/dist/src/project-model-preferences.js +74 -0
  43. package/dist/src/quota-notice.js +62 -0
  44. package/dist/src/reasoning-effort.js +27 -0
  45. package/dist/src/session-safety.js +0 -12
  46. package/dist/src/session-store.js +71 -10
  47. package/dist/src/session.js +12 -4
  48. package/dist/src/signin.js +58 -0
  49. package/dist/src/skills/discovery.js +280 -0
  50. package/dist/src/skills/frontmatter.js +192 -0
  51. package/dist/src/skills/install.js +394 -0
  52. package/dist/src/skills/types.js +43 -0
  53. package/dist/src/skills-command.js +71 -0
  54. package/dist/src/tool-executor.js +41 -51
  55. package/dist/src/tools/browser.js +928 -0
  56. package/dist/src/tools/delete-file.js +21 -5
  57. package/dist/src/tools/index.js +34 -10
  58. package/dist/src/tools/patch-file.js +14 -29
  59. package/dist/src/tools/read-file.js +7 -1
  60. package/dist/src/tools/read-image-file.js +85 -0
  61. package/dist/src/tools/replace-document-text.js +28 -18
  62. package/dist/src/tools/restore-checkpoint.js +1 -2
  63. package/dist/src/tools/run-command.js +14 -71
  64. package/dist/src/tools/run-node-script.js +12 -81
  65. package/dist/src/tools/save-generated-image.js +120 -0
  66. package/dist/src/tools/shell-diagnostics.js +246 -72
  67. package/dist/src/tools/str-replace.js +14 -29
  68. package/dist/src/tools/undo-edit.js +2 -7
  69. package/dist/src/tools/use-skill.js +38 -0
  70. package/dist/src/tools/write-file.js +69 -14
  71. package/dist/src/ui/repl.js +1141 -299
  72. package/dist/src/ui/slash-commands.js +140 -0
  73. package/dist/src/ui/tui/attention.js +25 -0
  74. package/dist/src/ui/tui/bridge.js +38 -5
  75. package/dist/src/ui/tui/build-frame.js +858 -303
  76. package/dist/src/ui/tui/composer-layout.js +76 -0
  77. package/dist/src/ui/tui/desktop-notification.js +118 -0
  78. package/dist/src/ui/tui/markdown-render.js +21 -11
  79. package/dist/src/ui/tui/model-label.js +13 -0
  80. package/dist/src/ui/tui/shell-input.js +266 -61
  81. package/dist/src/ui/tui/shortcuts.js +61 -0
  82. package/dist/src/ui/tui/terminal-theme.js +28 -0
  83. package/dist/src/ui/tui/text.js +31 -6
  84. package/dist/src/ui/tui/user-input.js +593 -0
  85. package/dist/src/update-check.js +205 -0
  86. package/dist/src/usage-notice.js +52 -0
  87. package/dist/src/usage.js +25 -2
  88. package/dist/src/utils.js +4 -0
  89. package/dist/src/version.js +52 -2
  90. package/dist/vendor/mcp/LICENSES.txt +414 -0
  91. package/dist/vendor/mcp/client.cjs +82 -0
  92. package/package.json +22 -9
  93. package/dist/src/project-index.js +0 -233
  94. package/dist/src/tools/code-intel.js +0 -472
  95. package/dist/src/tools/find-symbol.js +0 -70
  96. package/dist/src/tools/hover-symbol.js +0 -95
  97. package/dist/src/tools/list-symbols.js +0 -55
  98. package/dist/src/tools/search-code.js +0 -37
  99. package/dist/src/tools/signature-help.js +0 -118
@@ -1,10 +1,10 @@
1
1
  import chalk from '../colors.js';
2
2
  import { classifyProjectPath, deleteProjectFile } from '../patcher.js';
3
3
  import { isTuiMode } from '../runtime-mode.js';
4
- import { removeIndexFile } from '../project-index.js';
5
4
  import { invalidateShellDiagnosticsCache, runShellDiagnostics, } from './shell-diagnostics.js';
5
+ import { ensurePermission } from '../permissions.js';
6
6
  export async function deleteFile(context, args) {
7
- const { rootDir, projectIndex } = context;
7
+ const { rootDir } = context;
8
8
  const filePath = String(args.filePath ?? '').trim();
9
9
  if (!filePath) {
10
10
  return { ok: false, error: 'filePath is required' };
@@ -24,10 +24,22 @@ export async function deleteFile(context, args) {
24
24
  };
25
25
  }
26
26
  const scratchPath = pathKind === 'scratch';
27
+ if (!scratchPath) {
28
+ const denied = await ensurePermission(context, {
29
+ bucket: 'delete',
30
+ title: 'Approve file deletion?',
31
+ body: `Delete ${filePath}`,
32
+ filePath,
33
+ }, 'delete_file', { filePath });
34
+ if (denied) {
35
+ if (!isTuiMode())
36
+ console.log(chalk.dim(` ⏭ Delete skipped: ${filePath}`));
37
+ return denied;
38
+ }
39
+ }
27
40
  const result = deleteProjectFile(rootDir, filePath);
28
41
  if (result.deleted) {
29
42
  if (!scratchPath) {
30
- await removeIndexFile(projectIndex, filePath);
31
43
  invalidateShellDiagnosticsCache(rootDir, filePath);
32
44
  }
33
45
  if (!isTuiMode())
@@ -39,7 +51,11 @@ export async function deleteFile(context, args) {
39
51
  changed: result.deleted,
40
52
  deleted: result.deleted,
41
53
  ...(scratchPath ? { scratch: true } : {}),
42
- content: result.content,
43
- diagnostics: result.deleted && !scratchPath ? runShellDiagnostics(rootDir) : undefined,
54
+ ...(result.bytes === undefined ? {} : { bytes: result.bytes }),
55
+ ...(result.contentOmitted === undefined
56
+ ? {}
57
+ : { contentOmitted: result.contentOmitted }),
58
+ ...(result.content === undefined ? {} : { content: result.content }),
59
+ diagnostics: result.deleted && !scratchPath ? await runShellDiagnostics(rootDir) : undefined,
44
60
  };
45
61
  }
@@ -1,14 +1,12 @@
1
+ import { browserBatch, browserComputer, browserConsole, browserDownloads, browserEvaluate, browserFileUpload, browserFind, browserFormInput, browserGateway, browserGetPageText, browserNavigate, browserNetwork, browserReadPage, browserResize, browserTabClose, browserTabNew, browserTabs, } from './browser.js';
1
2
  import { shellJobOutput } from './shell-job-output.js';
2
3
  import { deleteFile } from './delete-file.js';
3
- import { findSymbol } from './find-symbol.js';
4
4
  import { getDiagnostics } from './get-diagnostics.js';
5
5
  import { grepCode } from './grep-code.js';
6
- import { hoverSymbol } from './hover-symbol.js';
7
6
  import { listDirectories } from './list-directories.js';
8
7
  import { listCheckpoints } from './list-checkpoints.js';
9
8
  import { listFiles } from './list-files.js';
10
9
  import { listSessionEdits } from './list-session-edits.js';
11
- import { listSymbols } from './list-symbols.js';
12
10
  import { patchFile } from './patch-file.js';
13
11
  import { readDocument } from './read-document.js';
14
12
  import { readFile } from './read-file.js';
@@ -16,25 +14,21 @@ import { replaceDocumentText } from './replace-document-text.js';
16
14
  import { runShellCommand } from './run-command.js';
17
15
  import { runNodeScript } from './run-node-script.js';
18
16
  import { restoreFilesToCheckpoint, restoreToCheckpoint, } from './restore-checkpoint.js';
19
- import { searchCode } from './search-code.js';
20
- import { getSignatureHelp } from './signature-help.js';
21
17
  import { shellJobKill } from './shell-job-kill.js';
22
18
  import { strReplace } from './str-replace.js';
23
19
  import { undoEdit } from './undo-edit.js';
24
20
  import { updateTodos } from './update-todos.js';
21
+ import { useSkill } from './use-skill.js';
22
+ import { readImageFile } from './read-image-file.js';
23
+ import { saveGeneratedImage } from './save-generated-image.js';
25
24
  import { writeFile } from './write-file.js';
26
25
  export const TOOL_MAP = {
27
- search_code: (context, args) => searchCode(context.projectIndex, args),
28
26
  list_files: (context, args) => listFiles(context, args),
29
27
  list_directories: (context, args) => listDirectories(context, args),
30
28
  read_file: (context, args) => readFile(context, args),
31
29
  read_document: (context, args) => readDocument(context.rootDir, args, context.env),
32
30
  replace_document_text: replaceDocumentText,
33
31
  grep_code: (context, args) => grepCode(context.rootDir, args),
34
- find_symbol: (context, args) => findSymbol(context, args),
35
- list_symbols: (context, args) => listSymbols(context, args),
36
- hover_symbol: (context, args) => hoverSymbol(context, args),
37
- signature_help: (context, args) => getSignatureHelp(context, args),
38
32
  get_diagnostics: (context, args) => getDiagnostics(context, args),
39
33
  list_checkpoints: (context) => listCheckpoints(context),
40
34
  list_session_edits: (context) => listSessionEdits(context),
@@ -50,6 +44,36 @@ export const TOOL_MAP = {
50
44
  shell_job_output: shellJobOutput,
51
45
  shell_job_kill: shellJobKill,
52
46
  update_todos: updateTodos,
47
+ use_skill: (context, args) => useSkill(context, args),
48
+ analyze_image: (context, args) => readImageFile(context, args),
49
+ browser: (context, args) => browserGateway(context, args),
50
+ browser_tabs: browserTabs,
51
+ browser_tab_new: (context, args) => browserTabNew(context, args),
52
+ browser_tab_close: browserTabClose,
53
+ browser_navigate: browserNavigate,
54
+ browser_read_page: browserReadPage,
55
+ browser_get_page_text: browserGetPageText,
56
+ browser_find: browserFind,
57
+ browser_computer: browserComputer,
58
+ browser_screenshot: ((context, args) => browserComputer(context, { ...args, action: 'screenshot' })),
59
+ browser_form_input: browserFormInput,
60
+ browser_evaluate: browserEvaluate,
61
+ browser_console: browserConsole,
62
+ browser_network: browserNetwork,
63
+ browser_resize: browserResize,
64
+ browser_file_upload: browserFileUpload,
65
+ browser_downloads: browserDownloads,
66
+ browser_batch: browserBatch,
67
+ generate_image: (_context, args) => {
68
+ if (!String(args.base64Data ?? '').trim()) {
69
+ return {
70
+ ok: false,
71
+ error: 'This CLI build cannot generate images without server-supplied image bytes. Update TheGitAI CLI.',
72
+ failureCategory: 'tool_exception',
73
+ };
74
+ }
75
+ return saveGeneratedImage(args);
76
+ },
53
77
  };
54
78
  function invalidToolCall(error) {
55
79
  return {
@@ -2,14 +2,14 @@ import chalk from '../colors.js';
2
2
  import path from 'node:path';
3
3
  import { normalizeProjectRelativePath } from '../artifact-policy.js';
4
4
  import { applyUnifiedPatch, classifyProjectPath, readProjectFile, renderDiffPreview, writeProjectFile, } from '../patcher.js';
5
- import { upsertIndexFile } from '../project-index.js';
6
5
  import { repairFilePath } from './path-suggest.js';
7
6
  import { isTuiMode } from '../runtime-mode.js';
8
7
  import { getCurrentFileHash, resolveRedactionTokens } from '../session-safety.js';
9
- import { invalidateShellDiagnosticsCache, runShellDiagnostics, } from './shell-diagnostics.js';
8
+ import { diagnoseEditedFile } from './shell-diagnostics.js';
9
+ import { ensurePermission } from '../permissions.js';
10
10
  const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
11
11
  export async function patchFile(context, args) {
12
- const { rootDir, projectIndex, autoYes, confirmPatch } = context;
12
+ const { rootDir } = context;
13
13
  const filePath = repairFilePath(rootDir, String(args.filePath ?? '').trim());
14
14
  let patch = typeof args.patch === 'string' ? args.patch : '';
15
15
  if (!filePath) {
@@ -74,37 +74,24 @@ export async function patchFile(context, args) {
74
74
  };
75
75
  }
76
76
  renderDiffPreview(filePath, patch);
77
- if (!autoYes && confirmPatch) {
78
- const confirmed = await confirmPatch(filePath, patch);
79
- if (!confirmed) {
77
+ if (!scratchPath) {
78
+ const denied = await ensurePermission(context, {
79
+ bucket: getCurrentFileHash(rootDir, filePath) === null ? 'create' : 'edit',
80
+ title: 'Approve patch?',
81
+ body: 'Review changes before applying.',
82
+ filePath,
83
+ diff: patch,
84
+ }, 'patch_file', { filePath });
85
+ if (denied) {
80
86
  if (!isTuiMode())
81
87
  console.log(chalk.dim(` ⏭ Patch skipped: ${filePath}`));
82
- return {
83
- ok: false,
84
- skipped: true,
85
- filePath,
86
- failureCategory: 'user_declined',
87
- failureDetails: {
88
- category: 'user_declined',
89
- tool: 'patch_file',
90
- action: 'Respect the real user’s decision. Do not retry the same or an equivalent edit; reconsider the approach or ask one specific question if needed.',
91
- },
92
- error: 'The real user rejected this proposed patch. Nothing was changed; this was not a tool failure or an automated system skip.',
93
- };
88
+ return denied;
94
89
  }
95
90
  }
96
91
  const { changed } = writeProjectFile(rootDir, filePath, patchedContent);
97
- let indexedChunks = 0;
98
- let retrievalTokensUsed = 0;
99
- if (changed && !scratchPath) {
100
- const indexResult = await upsertIndexFile(projectIndex, filePath);
101
- indexedChunks = indexResult.indexedChunks;
102
- retrievalTokensUsed = indexResult.retrievalTokensUsed ?? 0;
103
- }
104
92
  let diagnostics;
105
93
  if (!scratchPath) {
106
- invalidateShellDiagnosticsCache(rootDir, filePath);
107
- diagnostics = runShellDiagnostics(rootDir, filePath);
94
+ diagnostics = await diagnoseEditedFile(rootDir, filePath, 'patch_file', context.diagnosticsPlan);
108
95
  }
109
96
  const originalLines = originalContent.split('\n').length;
110
97
  const patchedLines = patchedContent.split('\n').length;
@@ -119,8 +106,6 @@ export async function patchFile(context, args) {
119
106
  changed,
120
107
  operation: 'patch',
121
108
  ...(scratchPath ? { scratch: true } : {}),
122
- indexedChunks,
123
- retrievalTokensUsed,
124
109
  bytesWritten: Buffer.byteLength(patchedContent, 'utf-8'),
125
110
  diagnostics,
126
111
  };
@@ -7,6 +7,9 @@ import { isWithinSessionScratchDir } from '../scratch-dir.js';
7
7
  import { repairFilePath } from './path-suggest.js';
8
8
  import { dotenvFitsRedactionBudget, getCurrentFileHash, recordReadCoverage, redactContentWithStableTokens, redactDotenvWithStableTokens, } from '../session-safety.js';
9
9
  import { readFileRange, truncate } from '../utils.js';
10
+ import { IMAGE_MIME_BY_EXT } from '../core/image-limits.js';
11
+ import { readImageFile } from './read-image-file.js';
12
+ import { isSkillsRelativePath } from '../skills/discovery.js';
10
13
  const MAX_FILE_READ_CHARS = 12000;
11
14
  const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
12
15
  export async function readFile(context, args) {
@@ -24,7 +27,7 @@ export async function readFile(context, args) {
24
27
  error: `Refusing to access path outside the project root: ${filePath}`,
25
28
  };
26
29
  }
27
- if (projectPath && shouldIgnoreArtifactPath(projectPath)) {
30
+ if (projectPath && shouldIgnoreArtifactPath(projectPath) && !isSkillsRelativePath(projectPath)) {
28
31
  return {
29
32
  ok: false,
30
33
  error: 'This path is not permitted.',
@@ -38,6 +41,9 @@ export async function readFile(context, args) {
38
41
  failureCategory: 'invalid_argument',
39
42
  };
40
43
  }
44
+ if (IMAGE_MIME_BY_EXT[documentExt] && typeof context !== 'string') {
45
+ return readImageFile(context, { path: filePath });
46
+ }
41
47
  let content;
42
48
  if (projectPath || scratchPath) {
43
49
  try {
@@ -0,0 +1,85 @@
1
+ import path from 'node:path';
2
+ import { normalizeProjectRelativePath } from '../artifact-policy.js';
3
+ import { SessionImageError, getImageStoreSession, isSessionStorePath, readSessionImage, readSessionImageByIndex, storeSessionImageFromPath, } from '../core/session-image-store.js';
4
+ export async function readImageFile(context, args) {
5
+ const rawPath = String(args.path ?? args.filePath ?? args.file_path ?? '').trim();
6
+ if (!rawPath) {
7
+ const requested = Number(args.imageIndex ?? args.image_index ?? args.index);
8
+ const stored = Number.isInteger(requested)
9
+ ? readSessionImageByIndex(requested)
10
+ : null;
11
+ if (!stored) {
12
+ return {
13
+ ok: false,
14
+ error: Number.isInteger(requested)
15
+ ? `Image #${requested} is not in this session's image store.`
16
+ : 'path is required and must name an image file on this machine.',
17
+ failureCategory: Number.isInteger(requested)
18
+ ? 'not_found'
19
+ : 'missing_required_argument',
20
+ };
21
+ }
22
+ return {
23
+ ok: true,
24
+ imageBytes: {
25
+ base64Data: stored.base64Data,
26
+ mimeType: stored.mimeType,
27
+ cachePath: stored.cachePath,
28
+ index: stored.index,
29
+ },
30
+ };
31
+ }
32
+ let resolved;
33
+ if (path.isAbsolute(rawPath)) {
34
+ resolved = rawPath;
35
+ }
36
+ else if (normalizeProjectRelativePath(context.rootDir, rawPath)) {
37
+ resolved = path.resolve(context.rootDir, rawPath);
38
+ }
39
+ else {
40
+ return {
41
+ ok: false,
42
+ error: `Refusing to access path outside the project root: ${rawPath}`,
43
+ failureCategory: 'permission_denied',
44
+ };
45
+ }
46
+ try {
47
+ const stored = isSessionStorePath(resolved)
48
+ ? readSessionImage(resolved)
49
+ : storeSessionImageFromPath({
50
+ sessionId: getImageStoreSession() ?? 'unbound',
51
+ sourcePath: resolved,
52
+ });
53
+ if (!stored) {
54
+ return {
55
+ ok: false,
56
+ error: `Not a readable image: ${resolved}`,
57
+ failureCategory: 'not_found',
58
+ };
59
+ }
60
+ return {
61
+ ok: true,
62
+ imageBytes: {
63
+ base64Data: stored.base64Data,
64
+ mimeType: stored.mimeType,
65
+ filePath: resolved,
66
+ cachePath: stored.cachePath,
67
+ index: stored.index,
68
+ },
69
+ };
70
+ }
71
+ catch (err) {
72
+ if (err instanceof SessionImageError) {
73
+ return {
74
+ ok: false,
75
+ error: err.message,
76
+ failureCategory: err.code === 'NOT_FOUND' ? 'not_found' : 'invalid_argument',
77
+ };
78
+ }
79
+ return {
80
+ ok: false,
81
+ error: `Could not read image: ${err?.message ?? err}`,
82
+ failureCategory: 'tool_exception',
83
+ };
84
+ }
85
+ }
@@ -6,6 +6,8 @@ import { readCliAuthConfig } from '../api/auth.js';
6
6
  import { resolveProjectPath, writeProjectFileBuffer } from '../patcher.js';
7
7
  import { repairFilePath, suggestClosestPath } from './path-suggest.js';
8
8
  import { isTuiMode } from '../runtime-mode.js';
9
+ import { ensurePermission } from '../permissions.js';
10
+ import { getCurrentFileHash } from '../session-safety.js';
9
11
  function normalizeReplacements(value) {
10
12
  if (!Array.isArray(value))
11
13
  return [];
@@ -178,27 +180,35 @@ export async function replaceDocumentText(context, args) {
178
180
  }
179
181
  const preview = String(serverResult.preview ?? '');
180
182
  renderPreview(targetPath, preview);
181
- if (!context.autoYes && context.confirmPatch) {
182
- const confirmed = await context.confirmPatch(targetPath, preview);
183
- if (!confirmed) {
184
- if (!isTuiMode()) {
185
- console.log(chalk.dim(` replace_document_text skipped: ${targetPath}`));
186
- }
187
- return {
188
- ok: false,
189
- skipped: true,
190
- filePath: targetPath,
191
- failureCategory: 'user_declined',
192
- failureDetails: {
193
- category: 'user_declined',
194
- tool: 'replace_document_text',
195
- action: 'Respect the real user’s decision. Do not retry the same or an equivalent edit; reconsider the approach or ask one specific question if needed.',
196
- },
197
- error: 'The real user rejected this proposed document edit. Nothing was changed; this was not a tool failure or an automated system skip.',
198
- };
183
+ const targetHashBeforeApproval = getCurrentFileHash(context.rootDir, targetPath);
184
+ const documentIsNew = targetHashBeforeApproval === null;
185
+ const denied = await ensurePermission(context, {
186
+ bucket: documentIsNew ? 'create' : 'edit',
187
+ title: documentIsNew ? 'Approve new document?' : 'Approve document edit?',
188
+ body: 'Review changes before applying.',
189
+ filePath: targetPath,
190
+ diff: preview,
191
+ }, 'replace_document_text', { filePath: targetPath });
192
+ if (denied) {
193
+ if (!isTuiMode()) {
194
+ console.log(chalk.dim(` replace_document_text skipped: ${targetPath}`));
199
195
  }
196
+ return denied;
200
197
  }
201
198
  const fileData = String(serverResult.fileData ?? '');
199
+ if (getCurrentFileHash(context.rootDir, targetPath) !== targetHashBeforeApproval) {
200
+ return {
201
+ ok: false,
202
+ filePath: targetPath,
203
+ failureCategory: 'conflict',
204
+ error: `replace_document_text refused: ${targetPath} changed on disk while the approval prompt was open.`,
205
+ failureDetails: {
206
+ category: 'conflict',
207
+ tool: 'replace_document_text',
208
+ action: 'Re-read the document to see its current contents, then rebuild the replacements against it and retry.',
209
+ },
210
+ };
211
+ }
202
212
  const nextData = Buffer.from(fileData, 'base64');
203
213
  const write = writeProjectFileBuffer(context.rootDir, targetPath, nextData);
204
214
  const failedCount = Number(serverResult.failedCount ?? 0);
@@ -54,7 +54,6 @@ export async function restoreToCheckpoint(context, args) {
54
54
  const result = await restoreCheckpointFiles({
55
55
  state: context.safety,
56
56
  rootDir: context.rootDir,
57
- projectIndex: context.projectIndex,
58
57
  checkpointId,
59
58
  filePaths,
60
59
  currentTurnId: context.currentTurnId ?? null,
@@ -81,7 +80,7 @@ export async function restoreToCheckpoint(context, args) {
81
80
  return {
82
81
  ...result,
83
82
  operation: 'restore_to_checkpoint',
84
- diagnostics: runShellDiagnostics(context.rootDir),
83
+ diagnostics: await runShellDiagnostics(context.rootDir),
85
84
  };
86
85
  }
87
86
  export async function restoreFilesToCheckpoint(context, args) {
@@ -1,14 +1,14 @@
1
1
  import chalk from '../colors.js';
2
2
  import { startBackgroundJob } from '../background-jobs.js';
3
3
  import { getBlockedCommandReason, runCommand, } from '../executor.js';
4
- import { syncIndexFromDisk } from '../project-index.js';
4
+ import { ensurePermission } from '../permissions.js';
5
5
  import { isTuiMode } from '../runtime-mode.js';
6
6
  import { redactConnectionStringCredentials } from '../secret-preview.js';
7
7
  import { buildNestedGitHint } from '../session-safety.js';
8
8
  import { buildDeferredShellDiagnostics, invalidateShellDiagnosticsCache, } from './shell-diagnostics.js';
9
9
  const MAX_OUTPUT_CHARS = 4000;
10
10
  export async function runShellCommand(context, args) {
11
- const { rootDir, projectIndex, autoYes, confirmCommand, requestSudoPassword, onStatus, } = context;
11
+ const { rootDir, requestSudoPassword, onStatus, } = context;
12
12
  const command = String(args.command ?? '').trim();
13
13
  if (!command) {
14
14
  return { ok: false, error: 'command is required' };
@@ -31,33 +31,18 @@ export async function runShellCommand(context, args) {
31
31
  }
32
32
  if (!isTuiMode())
33
33
  console.log(chalk.bold.yellow(`\n ⚡ Command: ${command}`));
34
- if (!autoYes) {
35
- if (confirmCommand == null) {
36
- return {
37
- ok: false,
38
- command,
39
- error: 'confirmCommand is required when autoYes is false',
40
- };
41
- }
42
- const approved = await confirmCommand(runInBackground
34
+ const denied = await ensurePermission(context, {
35
+ bucket: 'run',
36
+ title: 'Approve command?',
37
+ body: runInBackground
43
38
  ? `${command}\n\nRuns as a managed background job until it exits or is killed.`
44
- : command);
45
- if (!approved) {
46
- if (!isTuiMode())
47
- console.log(chalk.dim(` ⏭ Skipped: ${command}`));
48
- return {
49
- ok: false,
50
- skipped: true,
51
- command,
52
- failureCategory: 'user_declined',
53
- failureDetails: {
54
- category: 'user_declined',
55
- tool: 'run_command',
56
- action: 'Respect the real user’s decision. Do not retry the same or an equivalent action; reconsider the approach or ask one specific question if needed.',
57
- },
58
- error: 'The real user rejected this proposed command. Nothing was executed; this was not a tool failure or an automated system skip.',
59
- };
60
- }
39
+ : command,
40
+ command,
41
+ }, 'run_command', { command });
42
+ if (denied) {
43
+ if (!isTuiMode())
44
+ console.log(chalk.dim(` ⏭ Skipped: ${command}`));
45
+ return denied;
61
46
  }
62
47
  if (runInBackground) {
63
48
  return runBackgroundCommand(context, command, args.timeout_ms, repoHint);
@@ -66,12 +51,8 @@ export async function runShellCommand(context, args) {
66
51
  requestSudoPassword,
67
52
  timeout: typeof args.timeout_ms === 'number' && args.timeout_ms > 0 ? args.timeout_ms : undefined,
68
53
  });
69
- const repoSync = await syncRepoIndex(projectIndex, onStatus);
70
54
  invalidateShellDiagnosticsCache(rootDir);
71
55
  const diagnostics = buildDeferredShellDiagnostics('run_command');
72
- if (repoSync.added || repoSync.modified || repoSync.removed) {
73
- onStatus(`Synced repo state after command (${repoSync.added} added, ${repoSync.modified} modified, ${repoSync.removed} removed).`);
74
- }
75
56
  const output = typeof result.output === 'string'
76
57
  ? boundCommandOutput(redactConnectionStringCredentials(result.output))
77
58
  : result.output;
@@ -81,8 +62,6 @@ export async function runShellCommand(context, args) {
81
62
  exitCode: result.exitCode,
82
63
  timedOut: result.timedOut,
83
64
  output,
84
- repoSync,
85
- retrievalTokensUsed: repoSync.retrievalTokensUsed,
86
65
  diagnostics,
87
66
  repoHint,
88
67
  };
@@ -96,36 +75,8 @@ export function boundCommandOutput(output) {
96
75
  `\n\n... (${output.length - headSize - tailSize} chars truncated) ...\n\n` +
97
76
  output.slice(-tailSize));
98
77
  }
99
- async function syncRepoIndex(projectIndex, onStatus) {
100
- if (!projectIndex.initialized) {
101
- return {
102
- added: 0,
103
- modified: 0,
104
- removed: 0,
105
- indexedChunks: 0,
106
- retrievalTokensUsed: 0,
107
- };
108
- }
109
- try {
110
- return await syncIndexFromDisk(projectIndex);
111
- }
112
- catch (error) {
113
- const message = error instanceof Error ? error.message : String(error);
114
- onStatus(`Command completed, but local index sync failed: ${message}`);
115
- return {
116
- added: 0,
117
- modified: 0,
118
- removed: 0,
119
- indexedChunks: 0,
120
- retrievalTokensUsed: 0,
121
- skipped: true,
122
- reason: 'local index sync failed after command execution',
123
- error: message,
124
- };
125
- }
126
- }
127
78
  async function runBackgroundCommand(context, command, timeoutMs, repoHint) {
128
- const { rootDir, projectIndex, onStatus } = context;
79
+ const { rootDir, onStatus } = context;
129
80
  const started = await startBackgroundJob(command, rootDir, {
130
81
  startupWaitMs: typeof timeoutMs === 'number' && timeoutMs > 0 ? timeoutMs : undefined,
131
82
  sessionId: context.sessionId,
@@ -142,11 +93,7 @@ async function runBackgroundCommand(context, command, timeoutMs, repoHint) {
142
93
  };
143
94
  }
144
95
  const snapshot = started.snapshot;
145
- const repoSync = await syncRepoIndex(projectIndex, onStatus);
146
96
  invalidateShellDiagnosticsCache(rootDir);
147
- if (repoSync.added || repoSync.modified || repoSync.removed) {
148
- onStatus(`Synced repo state after command (${repoSync.added} added, ${repoSync.modified} modified, ${repoSync.removed} removed).`);
149
- }
150
97
  const output = boundCommandOutput(redactConnectionStringCredentials(started.startupOutput ?? '').trim());
151
98
  if (snapshot.status === 'running') {
152
99
  return {
@@ -158,8 +105,6 @@ async function runBackgroundCommand(context, command, timeoutMs, repoHint) {
158
105
  pid: snapshot.pid,
159
106
  output,
160
107
  note: `Background job ${snapshot.id} is running. Use shell_job_output to poll status and new output, and shell_job_kill to stop it.`,
161
- repoSync,
162
- retrievalTokensUsed: repoSync.retrievalTokensUsed,
163
108
  repoHint,
164
109
  };
165
110
  }
@@ -172,8 +117,6 @@ async function runBackgroundCommand(context, command, timeoutMs, repoHint) {
172
117
  exitCode: snapshot.exitCode,
173
118
  output,
174
119
  note: `Background job ${snapshot.id} finished during the startup window.`,
175
- repoSync,
176
- retrievalTokensUsed: repoSync.retrievalTokensUsed,
177
120
  repoHint,
178
121
  };
179
122
  }