codebuff 1.0.250 → 1.0.252

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 (62) hide show
  1. package/dist/background-process-manager.d.ts +50 -0
  2. package/dist/browser-runner.d.ts +35 -0
  3. package/dist/chat-storage.d.ts +2 -0
  4. package/dist/checkpoints/checkpoint-manager.d.ts +94 -0
  5. package/dist/checkpoints/file-manager.d.ts +72 -0
  6. package/dist/checkpoints/file-manager.js +311 -0
  7. package/dist/checkpoints/file-manager.js.map +1 -0
  8. package/dist/cli-handlers/api-key.d.ts +25 -0
  9. package/dist/cli-handlers/checkpoint.d.ts +18 -0
  10. package/dist/cli-handlers/diff.d.ts +2 -0
  11. package/dist/cli-handlers/easter-egg.d.ts +1 -0
  12. package/dist/cli-handlers/easter-egg.js +126 -0
  13. package/dist/cli-handlers/easter-egg.js.map +1 -0
  14. package/dist/cli-handlers/inititalization-flow.d.ts +1 -0
  15. package/dist/cli.d.ts +44 -0
  16. package/dist/client.d.ts +157 -0
  17. package/dist/code-map/tsconfig.tsbuildinfo +1 -1
  18. package/dist/config.d.ts +4 -0
  19. package/dist/config.js +12 -0
  20. package/dist/config.js.map +1 -0
  21. package/dist/create-template-project.d.ts +1 -0
  22. package/dist/create-template-project.js +107 -0
  23. package/dist/create-template-project.js.map +1 -0
  24. package/dist/credentials.d.ts +4 -0
  25. package/dist/dev-process-manager.d.ts +10 -0
  26. package/dist/fingerprint.d.ts +1 -0
  27. package/dist/fingerprint.js +48 -0
  28. package/dist/fingerprint.js.map +1 -0
  29. package/dist/index.d.ts +2 -0
  30. package/dist/menu.d.ts +3 -0
  31. package/dist/project-files.d.ts +114 -0
  32. package/dist/startup-process-handler.d.ts +2 -0
  33. package/dist/tool-handlers.d.ts +28 -0
  34. package/dist/types.d.ts +15 -0
  35. package/dist/update-codebuff.d.ts +1 -0
  36. package/dist/update-codebuff.js +160 -0
  37. package/dist/update-codebuff.js.map +1 -0
  38. package/dist/utils/__tests__/background-process-manager.test.d.ts +1 -0
  39. package/dist/utils/__tests__/background-process-manager.test.js +289 -0
  40. package/dist/utils/__tests__/background-process-manager.test.js.map +1 -0
  41. package/dist/utils/__tests__/tool-renderers.test.d.ts +1 -0
  42. package/dist/utils/__tests__/xml-stream-parser.test.d.ts +1 -0
  43. package/dist/utils/analytics.d.ts +6 -0
  44. package/dist/utils/detect-shell.d.ts +1 -0
  45. package/dist/utils/detect-shell.js +60 -0
  46. package/dist/utils/detect-shell.js.map +1 -0
  47. package/dist/utils/logger.d.ts +21 -0
  48. package/dist/utils/spinner.d.ts +11 -0
  49. package/dist/utils/spinner.js +87 -0
  50. package/dist/utils/spinner.js.map +1 -0
  51. package/dist/utils/system-info.d.ts +8 -0
  52. package/dist/utils/system-info.js +22 -0
  53. package/dist/utils/system-info.js.map +1 -0
  54. package/dist/utils/terminal.d.ts +41 -0
  55. package/dist/utils/tool-renderers.d.ts +16 -0
  56. package/dist/utils/xml-stream-parser.d.ts +9 -0
  57. package/dist/web-scraper.d.ts +3 -0
  58. package/dist/workers/checkpoint-worker.d.ts +1 -0
  59. package/dist/workers/checkpoint-worker.js +48 -0
  60. package/dist/workers/checkpoint-worker.js.map +1 -0
  61. package/dist/workers/project-context.d.ts +1 -0
  62. package/package.json +1 -1
@@ -0,0 +1,50 @@
1
+ import { ChildProcessByStdio, ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio } from 'child_process';
2
+ import { ToolResult } from './common/types/agent-state';
3
+ /**
4
+ * Interface describing the information stored for each background process.
5
+ */
6
+ export interface BackgroundProcessInfo {
7
+ pid: number;
8
+ toolCallId: string;
9
+ command: string;
10
+ process: ChildProcessByStdio<any, any, any>;
11
+ stdoutBuffer: string[];
12
+ stderrBuffer: string[];
13
+ status: 'running' | 'completed' | 'error';
14
+ startTime: number;
15
+ endTime: number | null;
16
+ lastReportedStdoutLength: number;
17
+ lastReportedStderrLength: number;
18
+ lastReportedStatus: 'running' | 'completed' | 'error' | null;
19
+ stdoutFile?: string;
20
+ stderrFile?: string;
21
+ }
22
+ /**
23
+ * Global map storing information about active and completed background processes.
24
+ * Keyed by the OS-assigned Process ID (PID).
25
+ */
26
+ export declare const backgroundProcesses: Map<number, BackgroundProcessInfo>;
27
+ /**
28
+ * Formats a single background process's info into a string
29
+ */
30
+ export declare function getBackgroundProcessInfoString(info: BackgroundProcessInfo): string;
31
+ /**
32
+ * Gets updates from all background processes and updates tracking info
33
+ */
34
+ export declare function getBackgroundProcessUpdates(): ToolResult[];
35
+ export declare function spawnAndTrack(command: string, args: string[] | undefined, options: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
36
+ export declare function sendKillSignalToAllBackgroundProcesses(): void;
37
+ export declare function killAllBackgroundProcesses(): Promise<void>;
38
+ /**
39
+ * Cleans up stale lock files and attempts to kill orphaned processes found in the lock directory.
40
+ * This function is intended to run on startup to handle cases where the application might have
41
+ * exited uncleanly, leaving orphaned processes or lock files.
42
+ *
43
+ * @returns Object containing:
44
+ * - shouldStartNewProcesses: boolean indicating if it's safe to start new processes
45
+ * - cleanUpPromise: Promise that resolves when cleanup is complete
46
+ */
47
+ export declare function cleanupStoredProcesses(): {
48
+ separateCodebuffInstanceRunning: boolean;
49
+ cleanUpPromise: Promise<any>;
50
+ };
@@ -0,0 +1,35 @@
1
+ import { BrowserAction, BrowserResponse } from './common/browser-actions';
2
+ export declare class BrowserRunner {
3
+ getLogs(): BrowserResponse['logs'];
4
+ getNetworkEvents(): BrowserResponse['networkEvents'];
5
+ private browser;
6
+ private page;
7
+ private logs;
8
+ private jsErrorCount;
9
+ private retryCount;
10
+ private startTime;
11
+ private consecutiveErrors;
12
+ private totalErrors;
13
+ constructor();
14
+ private maxConsecutiveErrors;
15
+ private totalErrorThreshold;
16
+ private performanceMetrics;
17
+ private networkEvents;
18
+ private executeWithRetry;
19
+ private executeAction;
20
+ private logErrorForAnalysis;
21
+ private getBrowser;
22
+ private startBrowser;
23
+ private navigate;
24
+ private typeText;
25
+ private scroll;
26
+ private takeScreenshot;
27
+ private attachPageListeners;
28
+ private collectPerformanceMetrics;
29
+ private collectMetrics;
30
+ private filterLogs;
31
+ execute(action: BrowserAction): Promise<BrowserResponse>;
32
+ shutdown(): Promise<void>;
33
+ }
34
+ export declare const handleBrowserInstruction: (action: BrowserAction) => Promise<BrowserResponse>;
35
+ export declare const activeBrowserRunner: BrowserRunner;
@@ -0,0 +1,2 @@
1
+ import { Message } from './common/types/message';
2
+ export declare function setMessages(messages: Message[]): void;
@@ -0,0 +1,94 @@
1
+ import { AgentState, ToolResult } from '../common/types/agent-state';
2
+ export declare class CheckpointsDisabledError extends Error {
3
+ constructor(message?: string, options?: ErrorOptions);
4
+ }
5
+ /**
6
+ * Interface representing a checkpoint of agent state
7
+ */
8
+ export interface Checkpoint {
9
+ agentStateString: string;
10
+ lastToolResultsString: string;
11
+ /** Promise resolving to the git commit hash for this checkpoint */
12
+ fileStateIdPromise: Promise<string>;
13
+ /** Number of messages in the agent's history at checkpoint time */
14
+ historyLength: number;
15
+ id: number;
16
+ parentId: number;
17
+ timestamp: number;
18
+ /** User input that triggered this checkpoint */
19
+ userInput: string;
20
+ }
21
+ /**
22
+ * Manages checkpoints of agent state and file state using git operations in a worker thread.
23
+ * Each checkpoint contains both the agent's conversation state and a git commit
24
+ * representing the state of all tracked files at that point.
25
+ */
26
+ export declare class CheckpointManager {
27
+ checkpoints: Array<Checkpoint>;
28
+ currentCheckpointId: number;
29
+ disabledReason: string | null;
30
+ private bareRepoPath;
31
+ /** Stores the undo chain (leaf node first, current node last) */
32
+ private undoIds;
33
+ /** Worker thread for git operations */
34
+ private worker;
35
+ /**
36
+ * Initialize or return the existing worker thread
37
+ * @returns The worker thread instance
38
+ */
39
+ private initWorker;
40
+ /**
41
+ * Execute an operation in the worker thread with timeout handling
42
+ * @param message - The message describing the operation to perform
43
+ * @returns A promise that resolves with the operation result
44
+ * @throws {Error} if the operation fails or times out
45
+ */
46
+ private runWorkerOperation;
47
+ /**
48
+ * Get the path to the bare git repository used for storing file states
49
+ * @returns The bare repo path
50
+ */
51
+ private getBareRepoPath;
52
+ /**
53
+ * Add a new checkpoint of the current agent and file state
54
+ * @param agentState - The current agent state to checkpoint
55
+ * @param lastToolResults - The tool results from the last assistant turn
56
+ * @param userInput - The user input that triggered this checkpoint
57
+ * @returns The latest checkpoint and whether that checkpoint was created (or already existed)
58
+ * @throws {Error} If the checkpoint cannot be added
59
+ */
60
+ addCheckpoint(agentState: AgentState, lastToolResults: ToolResult[], userInput: string, saveWithNoChanges?: boolean): Promise<{
61
+ checkpoint: Checkpoint;
62
+ created: boolean;
63
+ }>;
64
+ /**
65
+ * Get the most recent checkpoint
66
+ * @returns The most recent checkpoint or null if none exist
67
+ * @throws {CheckpointsDisabledError} If checkpoints are disabled
68
+ * @throws {ReferenceError} If no checkpoints exist
69
+ */
70
+ getLatestCheckpoint(): Checkpoint;
71
+ /**
72
+ * Restore the file state from a specific checkpoint
73
+ * @param id - The ID of the checkpoint to restore
74
+ * @param resetUndoIds - Whether to reset the chain of undo/redo ids
75
+ * @throws {Error} If the file state cannot be restored
76
+ */
77
+ restoreCheckointFileState({ id, resetUndoIds, }: {
78
+ id: number;
79
+ resetUndoIds?: boolean;
80
+ }): Promise<void>;
81
+ restoreUndoCheckpoint(): Promise<void>;
82
+ restoreRedoCheckpoint(): Promise<void>;
83
+ /**
84
+ * Clear all checkpoints
85
+ */
86
+ clearCheckpoints(resetBareRepoPath?: boolean): void;
87
+ /**
88
+ * Get a formatted string representation of all checkpoints
89
+ * @param detailed Whether to include detailed information about each checkpoint
90
+ * @returns A formatted string representation of all checkpoints
91
+ */
92
+ getCheckpointsAsString(detailed?: boolean): string;
93
+ }
94
+ export declare const checkpointManager: CheckpointManager;
@@ -0,0 +1,72 @@
1
+ import fs from 'fs';
2
+ /**
3
+ * Generates a unique path for storing the bare git repository based on the project directory.
4
+ * Uses SHA-256 hashing to create a unique identifier.
5
+ * @param dir - The project directory path to hash
6
+ * @returns The full path where the bare repo should be stored
7
+ */
8
+ export declare function getBareRepoPath(dir: string): string;
9
+ /**
10
+ * Checks if there are any uncommitted changes in the working directory.
11
+ * First attempts to use native git commands, falling back to isomorphic-git if unavailable.
12
+ * @param projectDir - The working tree directory path
13
+ * @param bareRepoPath - The bare git repository path
14
+ * @param relativeFilepaths - Array of file paths relative to projectDir to check
15
+ * @returns Promise resolving to true if there are uncommitted changes, false otherwise
16
+ */
17
+ export declare function hasUnsavedChanges({ projectDir, bareRepoPath, relativeFilepaths, }: {
18
+ projectDir: string;
19
+ bareRepoPath: string;
20
+ relativeFilepaths: Array<string>;
21
+ }): Promise<boolean>;
22
+ /**
23
+ * Gets the hash of the latest commit in the repository.
24
+ * First attempts to use native git commands, falling back to isomorphic-git if unavailable.
25
+ * @param bareRepoPath - The bare git repository path
26
+ * @returns Promise resolving to the commit hash
27
+ */
28
+ export declare function getLatestCommit({ bareRepoPath, }: {
29
+ bareRepoPath: string;
30
+ }): Promise<string>;
31
+ /**
32
+ * Initializes a bare git repository for tracking file changes.
33
+ * Creates the repository if it doesn't exist, otherwise uses the existing one.
34
+ * Makes an initial commit of the current file state.
35
+ * @param projectDir - The working tree directory path
36
+ * @param relativeFilepaths - Array of file paths relative to projectDir to track
37
+ */
38
+ export declare function initializeCheckpointFileManager({ projectDir, relativeFilepaths, }: {
39
+ projectDir: string;
40
+ relativeFilepaths: Array<string>;
41
+ }): Promise<void>;
42
+ /**
43
+ * Creates a new commit with the current state of all tracked files.
44
+ * Stages all changes and creates a commit with the specified message.
45
+ * @param projectDir - The working tree directory path
46
+ * @param bareRepoPath - The bare git repository path
47
+ * @param message - The commit message
48
+ * @param relativeFilepaths - Array of file paths relative to projectDir to commit
49
+ * @returns Promise resolving to the new commit's hash
50
+ */
51
+ export declare function storeFileState({ projectDir, bareRepoPath, message, relativeFilepaths: relativeFilepaths, }: {
52
+ projectDir: string;
53
+ bareRepoPath: string;
54
+ message: string;
55
+ relativeFilepaths: Array<string>;
56
+ }): Promise<string>;
57
+ /**
58
+ * Restores the working directory and index to match the specified commit.
59
+ * Equivalent to `git reset --hard`
60
+ * First attempts to use native git commands, falling back to isomorphic-git if unavailable.
61
+ * @param projectDir - The working tree directory path
62
+ * @param bareRepoPath - The bare git repository path
63
+ * @param commit - The commit hash to restore to
64
+ * @param relativeFilepaths - Array of file paths relative to projectDir to restore
65
+ */
66
+ export declare function restoreFileState({ projectDir, bareRepoPath, commit, relativeFilepaths, }: {
67
+ projectDir: string;
68
+ bareRepoPath: string;
69
+ commit: string;
70
+ relativeFilepaths: Array<string>;
71
+ }): Promise<void>;
72
+ export { fs };
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fs = void 0;
7
+ exports.getBareRepoPath = getBareRepoPath;
8
+ exports.hasUnsavedChanges = hasUnsavedChanges;
9
+ exports.getLatestCommit = getLatestCommit;
10
+ exports.initializeCheckpointFileManager = initializeCheckpointFileManager;
11
+ exports.storeFileState = storeFileState;
12
+ exports.restoreFileState = restoreFileState;
13
+ const child_process_1 = require("child_process");
14
+ const crypto_1 = require("crypto");
15
+ const fs_1 = __importDefault(require("fs"));
16
+ exports.fs = fs_1.default;
17
+ const os_1 = __importDefault(require("os"));
18
+ const path_1 = require("path");
19
+ const isomorphic_git_1 = require("isomorphic-git");
20
+ const project_files_1 = require("../project-files");
21
+ /**
22
+ * Checks if the native git command is available on the system.
23
+ * Caches the result to avoid repeated checks.
24
+ * @returns boolean indicating if git command is available
25
+ */
26
+ let cachedGitAvailable = null;
27
+ function gitCommandIsAvailable() {
28
+ if (cachedGitAvailable === null) {
29
+ try {
30
+ (0, child_process_1.execFileSync)('git', ['--version'], { stdio: 'ignore' });
31
+ cachedGitAvailable = true;
32
+ }
33
+ catch (error) {
34
+ cachedGitAvailable = false;
35
+ }
36
+ }
37
+ return cachedGitAvailable;
38
+ }
39
+ /**
40
+ * Generates a unique path for storing the bare git repository based on the project directory.
41
+ * Uses SHA-256 hashing to create a unique identifier.
42
+ * @param dir - The project directory path to hash
43
+ * @returns The full path where the bare repo should be stored
44
+ */
45
+ function getBareRepoPath(dir) {
46
+ const bareRepoName = (0, crypto_1.createHash)('sha256').update(dir).digest('hex');
47
+ return (0, path_1.join)((0, project_files_1.getProjectDataDir)(), bareRepoName);
48
+ }
49
+ /**
50
+ * Checks if there are any uncommitted changes in the working directory.
51
+ * First attempts to use native git commands, falling back to isomorphic-git if unavailable.
52
+ * @param projectDir - The working tree directory path
53
+ * @param bareRepoPath - The bare git repository path
54
+ * @param relativeFilepaths - Array of file paths relative to projectDir to check
55
+ * @returns Promise resolving to true if there are uncommitted changes, false otherwise
56
+ */
57
+ async function hasUnsavedChanges({ projectDir, bareRepoPath, relativeFilepaths, }) {
58
+ if (gitCommandIsAvailable()) {
59
+ try {
60
+ const output = (0, child_process_1.execFileSync)('git', [
61
+ '--git-dir',
62
+ bareRepoPath,
63
+ '--work-tree',
64
+ projectDir,
65
+ 'status',
66
+ '--porcelain',
67
+ ], { stdio: ['ignore', 'pipe', 'ignore'] }).toString();
68
+ return output.trim().length > 0;
69
+ }
70
+ catch (error) {
71
+ // error running git
72
+ }
73
+ }
74
+ for (const [, , workdirStatus, stageStatus] of await (0, isomorphic_git_1.statusMatrix)({
75
+ fs: fs_1.default,
76
+ dir: projectDir,
77
+ gitdir: bareRepoPath,
78
+ filepaths: relativeFilepaths,
79
+ })) {
80
+ if (workdirStatus !== stageStatus) {
81
+ return true;
82
+ }
83
+ }
84
+ return false;
85
+ }
86
+ /**
87
+ * Gets the hash of the latest commit in the repository.
88
+ * First attempts to use native git commands, falling back to isomorphic-git if unavailable.
89
+ * @param bareRepoPath - The bare git repository path
90
+ * @returns Promise resolving to the commit hash
91
+ */
92
+ async function getLatestCommit({ bareRepoPath, }) {
93
+ if (gitCommandIsAvailable()) {
94
+ try {
95
+ return (0, child_process_1.execFileSync)('git', ['--git-dir', bareRepoPath, 'rev-parse', 'HEAD'], { stdio: ['ignore', 'pipe', 'ignore'] })
96
+ .toString()
97
+ .trim();
98
+ }
99
+ catch (error) {
100
+ // unable to get head
101
+ }
102
+ }
103
+ return await (0, isomorphic_git_1.resolveRef)({
104
+ fs: fs_1.default,
105
+ gitdir: bareRepoPath,
106
+ ref: 'HEAD',
107
+ });
108
+ }
109
+ /**
110
+ * Initializes a bare git repository for tracking file changes.
111
+ * Creates the repository if it doesn't exist, otherwise uses the existing one.
112
+ * Makes an initial commit of the current file state.
113
+ * @param projectDir - The working tree directory path
114
+ * @param relativeFilepaths - Array of file paths relative to projectDir to track
115
+ */
116
+ async function initializeCheckpointFileManager({ projectDir, relativeFilepaths, }) {
117
+ if (projectDir === os_1.default.homedir()) {
118
+ return;
119
+ }
120
+ const bareRepoPath = getBareRepoPath(projectDir);
121
+ // Create the bare repo directory if it doesn't exist
122
+ fs_1.default.mkdirSync(bareRepoPath, { recursive: true });
123
+ try {
124
+ // Check if it's already a valid Git repo
125
+ await (0, isomorphic_git_1.resolveRef)({ fs: fs_1.default, gitdir: bareRepoPath, ref: 'HEAD' });
126
+ }
127
+ catch (error) {
128
+ // Bare repo doesn't exist yet
129
+ await (0, isomorphic_git_1.init)({
130
+ fs: fs_1.default,
131
+ dir: projectDir,
132
+ gitdir: bareRepoPath,
133
+ bare: true,
134
+ defaultBranch: 'master',
135
+ });
136
+ }
137
+ // Commit the files in the bare repo
138
+ await storeFileState({
139
+ projectDir,
140
+ bareRepoPath,
141
+ message: 'Initial Commit',
142
+ relativeFilepaths,
143
+ });
144
+ }
145
+ /**
146
+ * Stages all changes in the working directory.
147
+ * First attempts to use native git commands, falling back to isomorphic-git if unavailable.
148
+ * @param projectDir - The working tree directory path
149
+ * @param bareRepoPath - The bare git repository path
150
+ * @param relativeFilepaths - Array of file paths relative to projectDir to stage
151
+ */
152
+ async function gitAddAll({ projectDir, bareRepoPath, relativeFilepaths, }) {
153
+ if (gitCommandIsAvailable()) {
154
+ try {
155
+ (0, child_process_1.execFileSync)('git', [
156
+ '--git-dir',
157
+ bareRepoPath,
158
+ '--work-tree',
159
+ projectDir,
160
+ '-C',
161
+ projectDir,
162
+ 'add',
163
+ '.',
164
+ ], { stdio: 'ignore' });
165
+ return;
166
+ }
167
+ catch (error) {
168
+ // Failed to `git add .`
169
+ }
170
+ }
171
+ // Stage files with isomorphic-git
172
+ // Get status of all files in the project directory
173
+ const currStatusMatrix = (await (0, isomorphic_git_1.statusMatrix)({
174
+ fs: fs_1.default,
175
+ dir: projectDir,
176
+ gitdir: bareRepoPath,
177
+ filepaths: relativeFilepaths,
178
+ })) ?? [];
179
+ for (const [filepath, , workdirStatus, stageStatus] of currStatusMatrix) {
180
+ if (workdirStatus === stageStatus) {
181
+ continue;
182
+ }
183
+ if (workdirStatus === 2) {
184
+ // Existing file different from HEAD
185
+ try {
186
+ await (0, isomorphic_git_1.add)({ fs: fs_1.default, dir: projectDir, gitdir: bareRepoPath, filepath });
187
+ }
188
+ catch (error) {
189
+ // error adding files
190
+ }
191
+ }
192
+ else if (workdirStatus === 0) {
193
+ // Deleted file
194
+ try {
195
+ await (0, isomorphic_git_1.remove)({ fs: fs_1.default, dir: projectDir, gitdir: bareRepoPath, filepath });
196
+ }
197
+ catch (error) {
198
+ // error removing file
199
+ }
200
+ }
201
+ }
202
+ }
203
+ async function gitCommit({ projectDir, bareRepoPath, message, }) {
204
+ if (gitCommandIsAvailable()) {
205
+ try {
206
+ (0, child_process_1.execFileSync)('git', [
207
+ '--git-dir',
208
+ bareRepoPath,
209
+ '--work-tree',
210
+ projectDir,
211
+ 'commit',
212
+ '-m',
213
+ message,
214
+ ], { stdio: 'ignore' });
215
+ return await getLatestCommit({ bareRepoPath });
216
+ }
217
+ catch (error) {
218
+ // Failed to commit, continue to isomorphic-git implementation
219
+ }
220
+ }
221
+ const commitHash = await (0, isomorphic_git_1.commit)({
222
+ fs: fs_1.default,
223
+ dir: projectDir,
224
+ gitdir: bareRepoPath,
225
+ author: { name: 'Codebuff' },
226
+ message,
227
+ ref: '/refs/heads/master',
228
+ });
229
+ if (gitCommandIsAvailable()) {
230
+ try {
231
+ (0, child_process_1.execFileSync)('git', [
232
+ '--git-dir',
233
+ bareRepoPath,
234
+ '--work-tree',
235
+ projectDir,
236
+ 'checkout',
237
+ 'master',
238
+ ], { stdio: 'ignore' });
239
+ return commitHash;
240
+ }
241
+ catch (error) {
242
+ // Unable to checkout with git
243
+ }
244
+ }
245
+ await (0, isomorphic_git_1.checkout)({ fs: fs_1.default, dir: projectDir, gitdir: bareRepoPath, ref: 'master' });
246
+ return commitHash;
247
+ }
248
+ /**
249
+ * Creates a new commit with the current state of all tracked files.
250
+ * Stages all changes and creates a commit with the specified message.
251
+ * @param projectDir - The working tree directory path
252
+ * @param bareRepoPath - The bare git repository path
253
+ * @param message - The commit message
254
+ * @param relativeFilepaths - Array of file paths relative to projectDir to commit
255
+ * @returns Promise resolving to the new commit's hash
256
+ */
257
+ async function storeFileState({ projectDir, bareRepoPath, message, relativeFilepaths: relativeFilepaths, }) {
258
+ await gitAddAll({
259
+ projectDir,
260
+ bareRepoPath,
261
+ relativeFilepaths,
262
+ });
263
+ return await gitCommit({ projectDir, bareRepoPath, message });
264
+ }
265
+ /**
266
+ * Restores the working directory and index to match the specified commit.
267
+ * Equivalent to `git reset --hard`
268
+ * First attempts to use native git commands, falling back to isomorphic-git if unavailable.
269
+ * @param projectDir - The working tree directory path
270
+ * @param bareRepoPath - The bare git repository path
271
+ * @param commit - The commit hash to restore to
272
+ * @param relativeFilepaths - Array of file paths relative to projectDir to restore
273
+ */
274
+ async function restoreFileState({ projectDir, bareRepoPath, commit, relativeFilepaths, }) {
275
+ let resetDone = false;
276
+ if (gitCommandIsAvailable()) {
277
+ try {
278
+ (0, child_process_1.execFileSync)('git', [
279
+ '--git-dir',
280
+ bareRepoPath,
281
+ '--work-tree',
282
+ projectDir,
283
+ 'reset',
284
+ '--hard',
285
+ commit,
286
+ ]);
287
+ return;
288
+ }
289
+ catch (error) {
290
+ // Failed to use git, continue to isomorphic-git implementation
291
+ }
292
+ }
293
+ // Update the working directory to reflect the specified commit
294
+ await (0, isomorphic_git_1.checkout)({
295
+ fs: fs_1.default,
296
+ dir: projectDir,
297
+ gitdir: bareRepoPath,
298
+ ref: commit,
299
+ filepaths: relativeFilepaths,
300
+ force: true,
301
+ });
302
+ // Reset the index to match the specified commit
303
+ await Promise.all(relativeFilepaths.map((filepath) => (0, isomorphic_git_1.resetIndex)({
304
+ fs: fs_1.default,
305
+ dir: projectDir,
306
+ gitdir: bareRepoPath,
307
+ filepath,
308
+ ref: commit,
309
+ })));
310
+ }
311
+ //# sourceMappingURL=file-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-manager.js","sourceRoot":"","sources":["../../src/checkpoints/file-manager.ts"],"names":[],"mappings":";;;;;;AA4CA,0CAGC;AAUD,8CAwCC;AAQD,0CAuBC;AASD,0EAoCC;AAmJD,wCAkBC;AAWD,4CAmDC;AAhZD,iDAA4C;AAC5C,mCAAmC;AACnC,4CAAmB;AAiZV,aAjZF,YAAE,CAiZE;AAhZX,4CAAmB;AACnB,+BAA2B;AAE3B,mDASuB;AAEvB,oDAAoD;AAEpD;;;;GAIG;AACH,IAAI,kBAAkB,GAAmB,IAAI,CAAA;AAC7C,SAAS,qBAAqB;IAC5B,IAAI,kBAAkB,KAAK,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC;YACH,IAAA,4BAAY,EAAC,KAAK,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;YACvD,kBAAkB,GAAG,IAAI,CAAA;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,kBAAkB,GAAG,KAAK,CAAA;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,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QACR,GAAG,EAAE,MAAM;KACZ,CAAC,CACH,CACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { Client } from '../client';
2
+ import { ApiKeyType } from '../common/api-keys/constants';
3
+ export type ApiKeyDetectionResult = {
4
+ status: 'found';
5
+ type: ApiKeyType;
6
+ key: string;
7
+ } | {
8
+ status: 'prefix_only';
9
+ type: ApiKeyType;
10
+ prefix: string;
11
+ length: number;
12
+ } | {
13
+ status: 'not_found';
14
+ };
15
+ /**
16
+ * Detects if the user input contains a known API key pattern.
17
+ * Returns information about the detected key or prefix.
18
+ */
19
+ export declare function detectApiKey(userInput: string): ApiKeyDetectionResult;
20
+ /**
21
+ * Handles the result of API key detection.
22
+ */
23
+ export declare function handleApiKeyInput(client: Client, detectionResult: Exclude<ApiKeyDetectionResult, {
24
+ status: 'not_found';
25
+ }>, readyPromise: Promise<any>, returnControlToUser: () => void): Promise<void>;
@@ -0,0 +1,18 @@
1
+ import { Interface as ReadlineInterface } from 'readline';
2
+ import type { Client } from '../client';
3
+ export declare const checkpointCommands: {
4
+ readonly save: readonly [readonly ["checkpoint"], "Save current state as a new checkpoint"];
5
+ readonly list: readonly [readonly ["checkpoint list", "checkpoints"], "List all saved checkpoints"];
6
+ readonly clear: readonly [readonly ["checkpoint clear"], "Clear all checkpoints"];
7
+ readonly undo: readonly [readonly ["undo", "u"], "Undo to previous checkpoint"];
8
+ readonly redo: readonly [readonly ["redo", "r"], "Redo previously undone checkpoint"];
9
+ readonly restore: readonly [readonly [RegExp], "Restore to checkpoint number <n>"];
10
+ };
11
+ export declare function displayCheckpointMenu(): void;
12
+ export declare function isCheckpointCommand(userInput: string, type?: keyof typeof checkpointCommands | null): boolean | RegExpMatchArray;
13
+ export declare function listCheckpoints(): Promise<void>;
14
+ export declare function handleUndo(client: Client, rl: ReadlineInterface): Promise<string>;
15
+ export declare function handleRedo(client: Client, rl: ReadlineInterface): Promise<string>;
16
+ export declare function handleRestoreCheckpoint(id: number, client: Client, rl: ReadlineInterface): Promise<string>;
17
+ export declare function handleClearCheckpoints(): void;
18
+ export declare function saveCheckpoint(userInput: string, client: Client, readyPromise: Promise<any>, saveWithNoChanges?: boolean): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import { FileChange } from '../common/actions';
2
+ export declare function handleDiff(lastChanges: FileChange[]): void;
@@ -0,0 +1 @@
1
+ export declare function showEasterEgg(complete: () => void): Promise<void>;