codecane 1.0.202 → 1.0.204

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 (56) hide show
  1. package/dist/checkpoints/checkpoint-manager.d.ts +35 -13
  2. package/dist/checkpoints/checkpoint-manager.js +77 -41
  3. package/dist/checkpoints/checkpoint-manager.js.map +1 -1
  4. package/dist/checkpoints/file-manager.d.ts +43 -10
  5. package/dist/checkpoints/file-manager.js +129 -58
  6. package/dist/checkpoints/file-manager.js.map +1 -1
  7. package/dist/cli.d.ts +5 -1
  8. package/dist/cli.js +59 -30
  9. package/dist/cli.js.map +1 -1
  10. package/dist/client.d.ts +5 -4
  11. package/dist/client.js +24 -13
  12. package/dist/client.js.map +1 -1
  13. package/dist/code-map/languages.d.ts +1 -1
  14. package/dist/code-map/languages.js +22 -19
  15. package/dist/code-map/languages.js.map +1 -1
  16. package/dist/code-map/parse.d.ts +1 -1
  17. package/dist/code-map/parse.js +1 -2
  18. package/dist/code-map/parse.js.map +1 -1
  19. package/dist/code-map/tsconfig.tsbuildinfo +1 -1
  20. package/dist/common/actions.d.ts +54 -54
  21. package/dist/common/types/agent-state.d.ts +2 -2
  22. package/dist/common/types/message.d.ts +6 -6
  23. package/dist/common/types/usage.d.ts +2 -2
  24. package/dist/common/util/credentials.d.ts +2 -2
  25. package/dist/common/util/saxy.js +1 -1
  26. package/dist/common/util/saxy.js.map +1 -1
  27. package/dist/common/util/string.d.ts +4 -0
  28. package/dist/common/util/string.js +10 -2
  29. package/dist/common/util/string.js.map +1 -1
  30. package/dist/common/websockets/websocket-schema.d.ts +232 -232
  31. package/dist/index.js +1 -1
  32. package/dist/menu.js +1 -1
  33. package/dist/menu.js.map +1 -1
  34. package/dist/project-files.js +2 -0
  35. package/dist/project-files.js.map +1 -1
  36. package/dist/utils/logger.d.ts +2 -0
  37. package/dist/utils/logger.js +33 -0
  38. package/dist/utils/logger.js.map +1 -0
  39. package/dist/utils/terminal.js +1 -1
  40. package/dist/utils/terminal.js.map +1 -1
  41. package/dist/workers/checkpoint-worker.d.ts +1 -0
  42. package/dist/workers/checkpoint-worker.js +47 -0
  43. package/dist/workers/checkpoint-worker.js.map +1 -0
  44. package/package.json +1 -1
  45. package/dist/common/logger.d.ts +0 -1
  46. package/dist/common/logger.js +0 -7
  47. package/dist/common/logger.js.map +0 -1
  48. package/dist/common/util/constants.d.ts +0 -1
  49. package/dist/common/util/constants.js +0 -7
  50. package/dist/common/util/constants.js.map +0 -1
  51. package/dist/common/util/helpers.d.ts +0 -1
  52. package/dist/common/util/helpers.js +0 -6
  53. package/dist/common/util/helpers.js.map +0 -1
  54. package/dist/common/util/token-counter.d.ts +0 -3
  55. package/dist/common/util/token-counter.js +0 -27
  56. package/dist/common/util/token-counter.js.map +0 -1
@@ -4,25 +4,48 @@ import { AgentState } from '../common/types/agent-state';
4
4
  */
5
5
  export interface Checkpoint {
6
6
  agentStateString: string;
7
+ /** Promise resolving to the git commit hash for this checkpoint */
7
8
  fileStateIdPromise: Promise<string>;
9
+ /** Number of messages in the agent's history at checkpoint time */
8
10
  historyLength: number;
9
11
  id: number;
10
12
  timestamp: number;
13
+ /** User input that triggered this checkpoint */
11
14
  userInput: string;
12
15
  }
13
16
  /**
14
- * Simple in-memory checkpoint manager for agent states
17
+ * Manages checkpoints of agent state and file state using git operations in a worker thread.
18
+ * Each checkpoint contains both the agent's conversation state and a git commit
19
+ * representing the state of all tracked files at that point.
15
20
  */
16
21
  export declare class CheckpointManager {
17
22
  checkpoints: Array<Checkpoint>;
18
23
  private bareRepoPath;
19
- enabled: boolean;
20
- getBareRepoPath(): string;
24
+ disabledReason: string | null;
25
+ /** Worker thread for git operations */
26
+ private worker;
21
27
  /**
22
- * Add a new checkpoint
23
- * @param agentState - The agent state to checkpoint
24
- * @param userInput - The user input associated with this checkpoint
25
- * @returns The ID of the created checkpoint
28
+ * Initialize or return the existing worker thread
29
+ * @returns The worker thread instance
30
+ */
31
+ private initWorker;
32
+ /**
33
+ * Execute an operation in the worker thread with timeout handling
34
+ * @param message - The message describing the operation to perform
35
+ * @returns A promise that resolves with the operation result
36
+ * @throws Error if the operation fails or times out
37
+ */
38
+ private runWorkerOperation;
39
+ /**
40
+ * Get the path to the bare git repository used for storing file states
41
+ * @returns The bare repo path
42
+ */
43
+ private getBareRepoPath;
44
+ /**
45
+ * Add a new checkpoint of the current agent and file state
46
+ * @param agentState - The current agent state to checkpoint
47
+ * @param userInput - The user input that triggered this checkpoint
48
+ * @returns The created checkpoint, or null if checkpointing is disabled
26
49
  */
27
50
  addCheckpoint(agentState: AgentState, userInput: string): Promise<Checkpoint | null>;
28
51
  /**
@@ -30,6 +53,11 @@ export declare class CheckpointManager {
30
53
  * @returns The most recent checkpoint or null if none exist
31
54
  */
32
55
  getLatestCheckpoint(): Checkpoint | null;
56
+ /**
57
+ * Restore the file state from a specific checkpoint
58
+ * @param id - The ID of the checkpoint to restore
59
+ * @returns True if restoration succeeded, false if checkpoint not found
60
+ */
33
61
  restoreCheckointFileState(id: number): Promise<boolean>;
34
62
  /**
35
63
  * Clear all checkpoints
@@ -41,11 +69,5 @@ export declare class CheckpointManager {
41
69
  * @returns A formatted string representation of all checkpoints
42
70
  */
43
71
  getCheckpointsAsString(detailed?: boolean): string;
44
- /**
45
- * Get detailed information about a specific checkpoint
46
- * @param id The checkpoint ID
47
- * @returns A formatted string with detailed information about the checkpoint, or an error message if not found
48
- */
49
- getCheckpointDetails(id: number): string;
50
72
  }
51
73
  export declare const checkpointManager: CheckpointManager;
@@ -1,17 +1,70 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkpointManager = exports.CheckpointManager = void 0;
4
+ const path_1 = require("path");
4
5
  const picocolors_1 = require("picocolors");
6
+ const worker_threads_1 = require("worker_threads");
5
7
  const project_file_tree_1 = require("../common/project-file-tree");
6
8
  const file_manager_1 = require("./file-manager");
7
9
  const project_files_1 = require("../project-files");
8
10
  /**
9
- * Simple in-memory checkpoint manager for agent states
11
+ * Manages checkpoints of agent state and file state using git operations in a worker thread.
12
+ * Each checkpoint contains both the agent's conversation state and a git commit
13
+ * representing the state of all tracked files at that point.
10
14
  */
11
15
  class CheckpointManager {
12
16
  checkpoints = [];
13
17
  bareRepoPath = null;
14
- enabled = true;
18
+ disabledReason = null;
19
+ /** Worker thread for git operations */
20
+ worker = null;
21
+ /**
22
+ * Initialize or return the existing worker thread
23
+ * @returns The worker thread instance
24
+ */
25
+ initWorker() {
26
+ if (!this.worker) {
27
+ // NOTE: Uses the built worker-script-project-context.js within dist.
28
+ // So you need to run `bun run build` before running locally.
29
+ const workerPath = __filename.endsWith('.ts')
30
+ ? (0, path_1.join)(__dirname, '../../dist', 'workers/checkpoint-worker.js')
31
+ : (0, path_1.join)(__dirname, '../workers/checkpoint-worker.js');
32
+ this.worker = new worker_threads_1.Worker(workerPath);
33
+ }
34
+ return this.worker;
35
+ }
36
+ /**
37
+ * Execute an operation in the worker thread with timeout handling
38
+ * @param message - The message describing the operation to perform
39
+ * @returns A promise that resolves with the operation result
40
+ * @throws Error if the operation fails or times out
41
+ */
42
+ async runWorkerOperation(message) {
43
+ const worker = this.initWorker();
44
+ return new Promise((resolve, reject) => {
45
+ const timeoutMs = 30000; // 30 seconds timeout
46
+ const handler = (response) => {
47
+ if (response.success) {
48
+ resolve(response.result);
49
+ }
50
+ else {
51
+ reject(new Error(response.error));
52
+ }
53
+ worker.off('message', handler);
54
+ };
55
+ worker.on('message', handler);
56
+ worker.postMessage(message);
57
+ // Add timeout
58
+ setTimeout(() => {
59
+ worker.off('message', handler);
60
+ reject(new Error('Worker operation timed out'));
61
+ }, timeoutMs);
62
+ });
63
+ }
64
+ /**
65
+ * Get the path to the bare git repository used for storing file states
66
+ * @returns The bare repo path
67
+ */
15
68
  getBareRepoPath() {
16
69
  if (!this.bareRepoPath) {
17
70
  this.bareRepoPath = (0, file_manager_1.getBareRepoPath)((0, project_files_1.getProjectRoot)());
@@ -19,22 +72,21 @@ class CheckpointManager {
19
72
  return this.bareRepoPath;
20
73
  }
21
74
  /**
22
- * Add a new checkpoint
23
- * @param agentState - The agent state to checkpoint
24
- * @param userInput - The user input associated with this checkpoint
25
- * @returns The ID of the created checkpoint
75
+ * Add a new checkpoint of the current agent and file state
76
+ * @param agentState - The current agent state to checkpoint
77
+ * @param userInput - The user input that triggered this checkpoint
78
+ * @returns The created checkpoint, or null if checkpointing is disabled
26
79
  */
27
80
  async addCheckpoint(agentState, userInput) {
28
- if (!this.enabled) {
81
+ if (this.disabledReason !== null) {
29
82
  return null;
30
83
  }
31
- // Use incremental ID starting at 1
32
84
  const id = this.checkpoints.length + 1;
33
85
  const projectDir = (0, project_files_1.getProjectRoot)();
34
86
  const bareRepoPath = this.getBareRepoPath();
35
87
  const relativeFilepaths = (0, project_file_tree_1.getAllFilePaths)(agentState.fileContext.fileTree);
36
88
  if (relativeFilepaths.length >= project_file_tree_1.DEFAULT_MAX_FILES) {
37
- this.enabled = false;
89
+ this.disabledReason = 'Project too large';
38
90
  return null;
39
91
  }
40
92
  const needToStage = await (0, file_manager_1.hasUnsavedChanges)({
@@ -46,7 +98,8 @@ class CheckpointManager {
46
98
  return null;
47
99
  }
48
100
  const fileStateIdPromise = needToStage
49
- ? (0, file_manager_1.storeFileState)({
101
+ ? this.runWorkerOperation({
102
+ type: 'store',
50
103
  projectDir,
51
104
  bareRepoPath,
52
105
  message: `Checkpoint ${id}`,
@@ -54,14 +107,13 @@ class CheckpointManager {
54
107
  })
55
108
  : (0, file_manager_1.getLatestCommit)({ bareRepoPath });
56
109
  const checkpoint = {
57
- agentStateString: JSON.stringify(agentState), // Deep clone to prevent reference issues
110
+ agentStateString: JSON.stringify(agentState),
58
111
  fileStateIdPromise,
59
112
  historyLength: agentState.messageHistory.length,
60
113
  id,
61
114
  timestamp: Date.now(),
62
115
  userInput,
63
116
  };
64
- // Add to map
65
117
  this.checkpoints.push(checkpoint);
66
118
  return checkpoint;
67
119
  }
@@ -70,10 +122,18 @@ class CheckpointManager {
70
122
  * @returns The most recent checkpoint or null if none exist
71
123
  */
72
124
  getLatestCheckpoint() {
125
+ if (this.disabledReason !== null) {
126
+ return null;
127
+ }
73
128
  return this.checkpoints.length === 0
74
129
  ? null
75
130
  : this.checkpoints[this.checkpoints.length - 1];
76
131
  }
132
+ /**
133
+ * Restore the file state from a specific checkpoint
134
+ * @param id - The ID of the checkpoint to restore
135
+ * @returns True if restoration succeeded, false if checkpoint not found
136
+ */
77
137
  async restoreCheckointFileState(id) {
78
138
  const checkpoint = this.checkpoints[id - 1];
79
139
  if (!checkpoint) {
@@ -81,7 +141,8 @@ class CheckpointManager {
81
141
  }
82
142
  const relativeFilepaths = (0, project_file_tree_1.getAllFilePaths)(JSON.parse(checkpoint.agentStateString).fileContext
83
143
  .fileTree);
84
- await (0, file_manager_1.restoreFileState)({
144
+ await this.runWorkerOperation({
145
+ type: 'restore',
85
146
  projectDir: (0, project_files_1.getProjectRoot)(),
86
147
  bareRepoPath: this.getBareRepoPath(),
87
148
  commit: await checkpoint.fileStateIdPromise,
@@ -101,6 +162,9 @@ class CheckpointManager {
101
162
  * @returns A formatted string representation of all checkpoints
102
163
  */
103
164
  getCheckpointsAsString(detailed = false) {
165
+ if (this.disabledReason !== null) {
166
+ return (0, picocolors_1.red)(`Checkpoints not enabled: ${this.disabledReason}`);
167
+ }
104
168
  if (this.checkpoints.length === 0) {
105
169
  return (0, picocolors_1.yellow)('No checkpoints available.');
106
170
  }
@@ -115,41 +179,13 @@ class CheckpointManager {
115
179
  lines.push(`${(0, picocolors_1.cyan)((0, picocolors_1.bold)(`#${checkpoint.id}`))} ${(0, picocolors_1.gray)(`[${formattedDate}]`)}:`);
116
180
  lines.push(` ${(0, picocolors_1.blue)('Input')}: ${userInput}`);
117
181
  if (detailed) {
118
- // Add more details about the agent state if needed
119
182
  const messageCount = checkpoint.historyLength;
120
183
  lines.push(` ${(0, picocolors_1.blue)('Messages')}: ${messageCount}`);
121
- // You can add more detailed information here as needed
122
- // For example, file context information, etc.
123
184
  }
124
185
  lines.push(''); // Empty line between checkpoints
125
186
  });
126
187
  return lines.join('\n');
127
188
  }
128
- /**
129
- * Get detailed information about a specific checkpoint
130
- * @param id The checkpoint ID
131
- * @returns A formatted string with detailed information about the checkpoint, or an error message if not found
132
- */
133
- getCheckpointDetails(id) {
134
- const checkpoint = this.checkpoints[id - 1];
135
- if (!checkpoint) {
136
- return (0, picocolors_1.cyan)(`\nCheckpoint #${id} not found.`);
137
- }
138
- const lines = [
139
- (0, picocolors_1.cyan)(`Detailed information for checkpoint #${id}:`),
140
- ];
141
- const date = new Date(checkpoint.timestamp);
142
- const formattedDate = date.toLocaleString();
143
- lines.push(`${(0, picocolors_1.blue)('Created at')}: ${formattedDate}`);
144
- if (checkpoint.userInput) {
145
- lines.push(`${(0, picocolors_1.blue)('User input')}: ${checkpoint.userInput}`);
146
- }
147
- // Display more detailed information about the agent state
148
- const messageCount = checkpoint.historyLength;
149
- lines.push(`${(0, picocolors_1.blue)('Message history')}: ${messageCount} messages`);
150
- // You could add more detailed information here as needed
151
- return lines.join('\n');
152
- }
153
189
  }
154
190
  exports.CheckpointManager = CheckpointManager;
155
191
  // Export a singleton instance for use throughout the application
@@ -1 +1 @@
1
- {"version":3,"file":"checkpoint-manager.js","sourceRoot":"","sources":["../../src/checkpoints/checkpoint-manager.ts"],"names":[],"mappings":";;;AAAA,2CAAsE;AAEtE,gEAA6E;AAE7E,iDAMuB;AACvB,oDAAiD;AAcjD;;GAEG;AACH,MAAa,iBAAiB;IAC5B,WAAW,GAAsB,EAAE,CAAA;IAC3B,YAAY,GAAkB,IAAI,CAAA;IAC1C,OAAO,GAAY,IAAI,CAAA;IAEvB,eAAe;QACb,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,YAAY,GAAG,IAAA,8BAAe,EAAC,IAAA,8BAAc,GAAE,CAAC,CAAA;QACvD,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CA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AA,iBAAI,EAAC,IAAA,iBAAI,EAAC,IAAI,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAA,iBAAI,EAAC,IAAI,aAAa,GAAG,CAAC,GAAG,CACpE,CAAA;YAED,KAAK,CAAC,IAAI,CAAC,KAAK,IAAA,iBAAI,EAAC,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC,CAAA;YAE9C,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,YAAY,GAAG,UAAU,CAAC,aAAa,CAAA;gBAC7C,KAAK,CAAC,IAAI,CAAC,KAAK,IAAA,iBAAI,EAAC,UAAU,CAAC,KAAK,YAAY,EAAE,CAAC,CAAA;YACtD,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA,CAAC,iCAAiC;QAClD,CAAC,CAAC,CAAA;QAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;CACF;AAlND,8CAkNC;AAED,iEAAiE;AACpD,QAAA,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAA"}
@@ -1,21 +1,52 @@
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
+ */
1
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
+ */
2
17
  export declare function hasUnsavedChanges({ projectDir, bareRepoPath, relativeFilepaths, }: {
3
18
  projectDir: string;
4
19
  bareRepoPath: string;
5
20
  relativeFilepaths: Array<string>;
6
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
+ */
7
28
  export declare function getLatestCommit({ bareRepoPath, }: {
8
29
  bareRepoPath: string;
9
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
+ */
10
38
  export declare function initializeCheckpointFileManager({ projectDir, relativeFilepaths, }: {
11
39
  projectDir: string;
12
40
  relativeFilepaths: Array<string>;
13
41
  }): Promise<void>;
14
42
  /**
15
- * Stores the current state of all files in the project as a git commit
16
- * (git add . && git commit)
17
- * @param message The commit message to use for this file state
18
- * @returns A promise that resolves to the id hash that can be used to restore this file state
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
19
50
  */
20
51
  export declare function storeFileState({ projectDir, bareRepoPath, message, relativeFilepaths: relativeFilepaths, }: {
21
52
  projectDir: string;
@@ -24,12 +55,13 @@ export declare function storeFileState({ projectDir, bareRepoPath, message, rela
24
55
  relativeFilepaths: Array<string>;
25
56
  }): Promise<string>;
26
57
  /**
27
- * Resets the index and working directory to the specified commit.
28
- * (git reset --hard)
29
- * TODO redo this jsdoc
30
- * @param dir - The working tree directory path.
31
- * @param gitdir - The git directory path (typically the .git folder).
32
- * @param commit - The commit hash to reset to.
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
33
65
  */
34
66
  export declare function restoreFileState({ projectDir, bareRepoPath, commit, relativeFilepaths, }: {
35
67
  projectDir: string;
@@ -37,3 +69,4 @@ export declare function restoreFileState({ projectDir, bareRepoPath, commit, rel
37
69
  commit: string;
38
70
  relativeFilepaths: Array<string>;
39
71
  }): Promise<void>;
72
+ export { fs };