@thegitai/cli 1.0.0-preview.2 → 1.0.0-preview.20

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 (38) hide show
  1. package/README.md +32 -4
  2. package/dist/bin/ai.js +57 -291
  3. package/dist/src/agent-mode.js +1 -1
  4. package/dist/src/api/auth.js +2 -2
  5. package/dist/src/api/browser-login.js +72 -3
  6. package/dist/src/api/chat.js +232 -33
  7. package/dist/src/api/contracts.js +55 -1
  8. package/dist/src/api/http.js +16 -3
  9. package/dist/src/api/models.js +9 -4
  10. package/dist/src/executor.js +1 -1
  11. package/dist/src/help-text.js +51 -11
  12. package/dist/src/permissions.js +243 -0
  13. package/dist/src/project-index.js +13 -1
  14. package/dist/src/session-store.js +57 -20
  15. package/dist/src/session.js +14 -3
  16. package/dist/src/tool-executor.js +2 -2
  17. package/dist/src/tools/delete-file.js +14 -0
  18. package/dist/src/tools/patch-file.js +12 -16
  19. package/dist/src/tools/replace-document-text.js +28 -18
  20. package/dist/src/tools/run-command.js +13 -27
  21. package/dist/src/tools/run-node-script.js +11 -26
  22. package/dist/src/tools/str-replace.js +12 -16
  23. package/dist/src/tools/write-file.js +66 -0
  24. package/dist/src/turn-failure-marker.js +11 -0
  25. package/dist/src/ui/prompt-history-store.js +1 -1
  26. package/dist/src/ui/repl.js +569 -151
  27. package/dist/src/ui/tui/bridge.js +10 -0
  28. package/dist/src/ui/tui/build-frame.js +535 -159
  29. package/dist/src/ui/tui/markdown-render.js +81 -73
  30. package/dist/src/ui/tui/shell-input.js +155 -45
  31. package/dist/src/ui/tui/terminal-theme.js +28 -0
  32. package/dist/src/ui/tui/terminal-title.js +3 -0
  33. package/dist/src/ui/tui/terminal-writes.js +48 -0
  34. package/dist/src/ui/tui/text.js +158 -4
  35. package/dist/src/ui/tui/user-input.js +568 -0
  36. package/dist/src/utils.js +9 -0
  37. package/package.json +18 -6
  38. package/dist/src/markdown-renderer.js +0 -112
@@ -1,112 +0,0 @@
1
- import chalk from './colors.js';
2
- function renderInline(text) {
3
- const parts = String(text ?? '').split(/(`[^`]+`)/g);
4
- return parts
5
- .map((part) => part.startsWith('`') && part.endsWith('`') && part.length > 1
6
- ? chalk.cyan(part.slice(1, -1))
7
- : part)
8
- .join('');
9
- }
10
- function isTableSeparator(line) {
11
- const cells = splitTableRow(line);
12
- return (cells.length > 1 &&
13
- cells.every((cell) => /^:?-{3,}:?$/.test(cell.trim())));
14
- }
15
- function splitTableRow(line) {
16
- const trimmed = String(line ?? '').trim();
17
- if (!trimmed.includes('|'))
18
- return [];
19
- return trimmed
20
- .replace(/^\|/, '')
21
- .replace(/\|$/, '')
22
- .split('|')
23
- .map((cell) => cell.trim());
24
- }
25
- function tableWidth(text) {
26
- return text.replace(/\x1b\[[0-9;]*m/g, '').length;
27
- }
28
- function padCell(text, width) {
29
- return `${text}${' '.repeat(Math.max(0, width - tableWidth(text)))}`;
30
- }
31
- function renderTable(rows) {
32
- if (rows.length < 2 || !isTableSeparator(rows[1].join('|')))
33
- return [];
34
- const headers = rows[0];
35
- const body = rows.slice(2).filter((row) => row.length > 0);
36
- const columnCount = Math.max(headers.length, ...body.map((row) => row.length));
37
- const normalizedRows = [headers, ...body].map((row) => Array.from({ length: columnCount }, (_, index) => renderInline(row[index] ?? '')));
38
- const widths = Array.from({ length: columnCount }, (_, index) => Math.max(...normalizedRows.map((row) => tableWidth(row[index] ?? '')), 3));
39
- const border = `+${widths.map((width) => '-'.repeat(width + 2)).join('+')}+`;
40
- const renderRow = (row) => `| ${row.map((cell, index) => padCell(cell, widths[index])).join(' | ')} |`;
41
- return [
42
- border,
43
- renderRow(normalizedRows[0].map((cell) => chalk.bold(cell))),
44
- border,
45
- ...normalizedRows.slice(1).map(renderRow),
46
- border,
47
- ];
48
- }
49
- function readTableBlock(lines, startIndex) {
50
- if (startIndex + 1 >= lines.length)
51
- return null;
52
- const header = splitTableRow(lines[startIndex]);
53
- const separator = splitTableRow(lines[startIndex + 1]);
54
- if (header.length < 2 || separator.length < 2 || !isTableSeparator(lines[startIndex + 1])) {
55
- return null;
56
- }
57
- const rows = [header, separator];
58
- let index = startIndex + 2;
59
- while (index < lines.length) {
60
- const row = splitTableRow(lines[index]);
61
- if (row.length < 2)
62
- break;
63
- rows.push(row);
64
- index += 1;
65
- }
66
- const rendered = renderTable(rows);
67
- return rendered.length ? { rendered, nextIndex: index } : null;
68
- }
69
- export function renderMarkdownForTerminal(markdown) {
70
- const lines = String(markdown ?? '').replace(/\r\n?/g, '\n').split('\n');
71
- const output = [];
72
- let inCodeBlock = false;
73
- for (let index = 0; index < lines.length; index++) {
74
- const line = lines[index];
75
- if (/^\s*```/.test(line)) {
76
- inCodeBlock = !inCodeBlock;
77
- continue;
78
- }
79
- if (inCodeBlock) {
80
- output.push(chalk.dim(` ${line}`));
81
- continue;
82
- }
83
- const table = readTableBlock(lines, index);
84
- if (table) {
85
- output.push(...table.rendered);
86
- index = table.nextIndex - 1;
87
- continue;
88
- }
89
- const heading = line.match(/^\s{0,3}#{1,6}\s+(.+)$/);
90
- if (heading) {
91
- output.push(chalk.bold(renderInline(heading[1].trim())));
92
- continue;
93
- }
94
- const bullet = line.match(/^(\s*)[-*]\s+(.+)$/);
95
- if (bullet) {
96
- output.push(`${bullet[1]}- ${renderInline(bullet[2].trim())}`);
97
- continue;
98
- }
99
- const numbered = line.match(/^(\s*)\d+[.)]\s+(.+)$/);
100
- if (numbered) {
101
- output.push(`${numbered[1]}- ${renderInline(numbered[2].trim())}`);
102
- continue;
103
- }
104
- const quote = line.match(/^\s*>\s?(.+)$/);
105
- if (quote) {
106
- output.push(chalk.dim(`> ${renderInline(quote[1].trim())}`));
107
- continue;
108
- }
109
- output.push(renderInline(line));
110
- }
111
- return output.join('\n').trimEnd();
112
- }