@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
@@ -2,13 +2,48 @@ import chalk from '../colors.js';
2
2
  import path from 'node:path';
3
3
  import { normalizeProjectRelativePath } from '../artifact-policy.js';
4
4
  import { classifyProjectPath, writeProjectFile } from '../patcher.js';
5
- import { upsertIndexFile } from '../project-index.js';
5
+ import { readFileEditSnapshot } from '../edit-journal.js';
6
6
  import { isTuiMode } from '../runtime-mode.js';
7
7
  import { getCurrentFileHash, hasFreshFullReadCoverage, resolveRedactionTokens, } from '../session-safety.js';
8
- import { invalidateShellDiagnosticsCache, runShellDiagnostics, } from './shell-diagnostics.js';
8
+ import { diagnoseEditedFile } from './shell-diagnostics.js';
9
+ import { ensurePermission } from '../permissions.js';
9
10
  const DOCUMENT_EXTENSIONS = new Set(['.pdf', '.xlsx', '.docx']);
11
+ const MAX_WRITE_PREVIEW_LINES = 400;
12
+ function boundedLines(text, limit) {
13
+ const lines = [];
14
+ let omitted = 0;
15
+ let start = 0;
16
+ for (;;) {
17
+ const newline = text.indexOf('\n', start);
18
+ if (lines.length < limit) {
19
+ lines.push(text.slice(start, newline === -1 ? undefined : newline));
20
+ }
21
+ else {
22
+ omitted += 1;
23
+ }
24
+ if (newline === -1)
25
+ break;
26
+ start = newline + 1;
27
+ }
28
+ return { lines, omitted };
29
+ }
30
+ function buildWritePreview(previous, next) {
31
+ const rows = ['@@ write_file @@'];
32
+ const append = (text, sign, marker) => {
33
+ const { lines, omitted } = boundedLines(text, MAX_WRITE_PREVIEW_LINES);
34
+ for (const line of lines)
35
+ rows.push(`${sign}${line}`);
36
+ if (omitted > 0) {
37
+ rows.push(`@@ ${omitted} more ${marker} line(s) not shown @@`);
38
+ }
39
+ };
40
+ if (previous !== null)
41
+ append(previous, '-', 'removed');
42
+ append(next, '+', 'added');
43
+ return rows.join('\n');
44
+ }
10
45
  export async function writeFile(context, args) {
11
- const { rootDir, projectIndex } = context;
46
+ const { rootDir } = context;
12
47
  const filePath = String(args.filePath ?? '').trim();
13
48
  let content = typeof args.content === 'string' ? args.content : '';
14
49
  if (!filePath) {
@@ -60,18 +95,40 @@ export async function writeFile(context, args) {
60
95
  };
61
96
  }
62
97
  content = resolveRedactionTokens(context.safety, content, coveragePath, currentHash);
63
- const { changed } = writeProjectFile(rootDir, filePath, content);
64
- let indexedChunks = 0;
65
- let retrievalTokensUsed = 0;
66
- if (changed && !scratchPath) {
67
- const indexResult = await upsertIndexFile(projectIndex, filePath);
68
- indexedChunks = indexResult.indexedChunks;
69
- retrievalTokensUsed = indexResult.retrievalTokensUsed ?? 0;
98
+ if (!scratchPath) {
99
+ const before = currentHash === null ? null : readFileEditSnapshot(rootDir, filePath);
100
+ const existing = before && before.contentEncoding === 'utf8' ? before.content : null;
101
+ const denied = await ensurePermission(context, {
102
+ bucket: currentHash === null ? 'create' : 'edit',
103
+ title: currentHash === null ? 'Approve new file?' : 'Approve patch?',
104
+ body: 'Review changes before applying.',
105
+ filePath,
106
+ diff: buildWritePreview(existing, content),
107
+ }, 'write_file', { filePath });
108
+ if (denied) {
109
+ if (!isTuiMode())
110
+ console.log(chalk.dim(` ⏭ write_file skipped: ${filePath}`));
111
+ return denied;
112
+ }
113
+ if (getCurrentFileHash(rootDir, filePath) !== currentHash) {
114
+ return {
115
+ ok: false,
116
+ filePath,
117
+ failureCategory: 'conflict',
118
+ error: `write_file refused: ${filePath} changed on disk while the approval prompt was open.`,
119
+ failureDetails: {
120
+ category: 'conflict',
121
+ tool: 'write_file',
122
+ action: 'Re-read the file to see its current contents, then decide whether the write is still correct and retry.',
123
+ },
124
+ currentHash,
125
+ };
126
+ }
70
127
  }
128
+ const { changed } = writeProjectFile(rootDir, filePath, content);
71
129
  let diagnostics;
72
130
  if (!scratchPath) {
73
- invalidateShellDiagnosticsCache(rootDir, filePath);
74
- diagnostics = runShellDiagnostics(rootDir, filePath);
131
+ diagnostics = await diagnoseEditedFile(rootDir, filePath, 'write_file', context.diagnosticsPlan);
75
132
  }
76
133
  if (!isTuiMode()) {
77
134
  const icon = changed ? '✨' : '📝';
@@ -84,8 +141,6 @@ export async function writeFile(context, args) {
84
141
  changed,
85
142
  operation: 'write',
86
143
  ...(scratchPath ? { scratch: true } : {}),
87
- indexedChunks,
88
- retrievalTokensUsed,
89
144
  bytesWritten: Buffer.byteLength(content, 'utf-8'),
90
145
  diagnostics,
91
146
  };