@dccxx/auggiegw 1.0.18 → 1.0.19

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.
@@ -0,0 +1,70 @@
1
+ ================================================================================
2
+ [2025-11-27T21:14:57.407Z]
3
+ Refactor the delete session logic in `src/cli.ts` at lines 564-570. Currently it calls `auggie session delete` command, but we need a completely new implementation.
4
+
5
+ **New Logic Requirements:**
6
+
7
+ 1. Read all JSON files from the directory: `~\.augment\sessions` (use os.homedir() to get home directory)
8
+
9
+ 2. Sort files by their modified time (use fs.stat or similar to get mtime)
10
+
11
+ 3. Delete ALL files EXCEPT the most recently modified one
12
+
13
+ 4. For the most recently modified file that is kept:
14
+ - Generate a new random UUID v4
15
+ - Update the `sessionId` field inside the JSON content to this new UUID
16
+ - Replace ALL occurrences of the key `"request_id"` with `"request_id_temp"` by:
17
+ - Converting JSON to string
18
+ - Using string replace (text replacement)
19
+ - Converting back to JSON
20
+ - Rename the file to match the new UUID (e.g., `{new-uuid}.json`)
21
+
22
+ **Example:**
23
+ If there are files:
24
+ - `C:\Users\0x317\.augment\sessions\3ac2b36f-7328-444a-a1ec-a1d5cb81c0f1.json`
25
+ - `C:\Users\0x317\.augment\sessions\3ac2b36f-7328-444a-a1ec-a1d5cb81c0f2.json`
26
+
27
+ Keep only the most recently modified one, change its sessionId to a new UUID, replace all "request_id" keys with "request_id_temp", and rename the file to the new UUID.
28
+
29
+ Make sure to:
30
+ - Use the `uuid` package for generating UUID v4 (check if already imported, if not add it)
31
+ - Handle edge cases (no files, only one file, directory doesn't exist)
32
+ - Keep the try-catch wrapper for silent error handling
33
+ - Use async/await properly with fs/promises
34
+
35
+ After implementation, run `bun run lint` and `bun run build` to verify the code quality and build.
36
+
37
+ Do not create or modify any markdown document files or code examples.
38
+
39
+ ================================================================================
40
+ [2025-11-27T21:18:39.385Z]
41
+ In `src/cli.ts`, modify the catch block at lines 629-631 to add a fallback to the old logic.
42
+
43
+ Currently:
44
+ ```
45
+ } catch {
46
+ // Silently ignore session management errors
47
+ }
48
+ ```
49
+
50
+ Change it to:
51
+ ```
52
+ } catch {
53
+ // Fallback to old logic if new session management fails
54
+ try {
55
+ await execAsync('auggie session delete');
56
+ } catch {
57
+ // Silently ignore fallback errors
58
+ }
59
+ }
60
+ ```
61
+
62
+ This requires re-adding the `execAsync` utility that was previously removed. Add back:
63
+ - Import `exec` from `node:child_process`
64
+ - Import `promisify` from `node:util`
65
+ - Create `const execAsync = promisify(exec);`
66
+
67
+ After changes, run `bun run lint` and `bun run build` to verify.
68
+
69
+ Do not create or modify any markdown document files or code examples.
70
+
@@ -0,0 +1,29 @@
1
+ In `src/cli.ts`, modify the catch block at lines 629-631 to add a fallback to the old logic.
2
+
3
+ Currently:
4
+ ```
5
+ } catch {
6
+ // Silently ignore session management errors
7
+ }
8
+ ```
9
+
10
+ Change it to:
11
+ ```
12
+ } catch {
13
+ // Fallback to old logic if new session management fails
14
+ try {
15
+ await execAsync('auggie session delete');
16
+ } catch {
17
+ // Silently ignore fallback errors
18
+ }
19
+ }
20
+ ```
21
+
22
+ This requires re-adding the `execAsync` utility that was previously removed. Add back:
23
+ - Import `exec` from `node:child_process`
24
+ - Import `promisify` from `node:util`
25
+ - Create `const execAsync = promisify(exec);`
26
+
27
+ After changes, run `bun run lint` and `bun run build` to verify.
28
+
29
+ Do not create or modify any markdown document files or code examples.
package/dist/cli.js CHANGED
@@ -7,6 +7,7 @@ import * as path from 'node:path';
7
7
  import * as readline from 'node:readline/promises';
8
8
  import { promisify } from 'node:util';
9
9
  import { Command } from 'commander';
10
+ import { v4 as uuidv4 } from 'uuid';
10
11
  const require = createRequire(import.meta.url);
11
12
  const ora = require('ora');
12
13
  const execAsync = promisify(exec);
@@ -341,13 +342,70 @@ async function handleFetch(options) {
341
342
  scopes: ['read', 'write'],
342
343
  };
343
344
  await saveAugmentSession(augmentSession);
344
- // Check if session deletion is enabled
345
+ // Check if session deletion is enabled - delete old sessions and reset the most recent one
345
346
  if (shouldDeleteSession(options)) {
346
347
  try {
347
- await execAsync('auggie session delete');
348
+ const sessionsDir = path.join(os.homedir(), '.augment', 'sessions');
349
+ // Check if directory exists
350
+ try {
351
+ await fs.access(sessionsDir);
352
+ }
353
+ catch {
354
+ // Directory doesn't exist, nothing to do
355
+ throw new Error('Sessions directory does not exist');
356
+ }
357
+ // Read all JSON files from the sessions directory
358
+ const files = await fs.readdir(sessionsDir);
359
+ const jsonFiles = files.filter((file) => file.endsWith('.json'));
360
+ if (jsonFiles.length === 0) {
361
+ // No files to process
362
+ throw new Error('No session files found');
363
+ }
364
+ // Get file stats and sort by mtime (most recent first)
365
+ const fileStats = await Promise.all(jsonFiles.map(async (file) => {
366
+ const filePath = path.join(sessionsDir, file);
367
+ const stats = await fs.stat(filePath);
368
+ return { file, filePath, mtime: stats.mtime };
369
+ }));
370
+ fileStats.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
371
+ // Delete all files except the most recently modified one
372
+ for (let i = 1; i < fileStats.length; i++) {
373
+ const fileStat = fileStats[i];
374
+ if (fileStat) {
375
+ await fs.unlink(fileStat.filePath);
376
+ }
377
+ }
378
+ // Process the most recently modified file
379
+ const mostRecent = fileStats[0];
380
+ if (!mostRecent) {
381
+ throw new Error('No most recent file found');
382
+ }
383
+ // Read the file content
384
+ const content = await fs.readFile(mostRecent.filePath, 'utf-8');
385
+ // Generate a new UUID
386
+ const newUuid = uuidv4();
387
+ // Parse JSON, update sessionId, replace request_id keys, and save
388
+ const jsonData = JSON.parse(content);
389
+ jsonData.sessionId = newUuid;
390
+ // Convert to string and replace all "request_id" keys with "request_id_temp"
391
+ let jsonString = JSON.stringify(jsonData, null, 2);
392
+ jsonString = jsonString.replace(/"request_id"/g, '"request_id_temp"');
393
+ // Write the modified content
394
+ const newFilePath = path.join(sessionsDir, `${newUuid}.json`);
395
+ await fs.writeFile(newFilePath, jsonString, 'utf-8');
396
+ // Delete the old file if it has a different name
397
+ if (mostRecent.filePath !== newFilePath) {
398
+ await fs.unlink(mostRecent.filePath);
399
+ }
348
400
  }
349
401
  catch {
350
- // Silently ignore auggie session delete errors
402
+ // Fallback to old logic if new session management fails
403
+ try {
404
+ await execAsync('auggie session delete');
405
+ }
406
+ catch {
407
+ // Silently ignore fallback errors
408
+ }
351
409
  }
352
410
  }
353
411
  // Skip prompt fetching if authOnly flag is set
@@ -443,7 +501,7 @@ async function handleSwitchAccount() {
443
501
  spinner.succeed(`Successfully switched to account: ${activateResponse.data.activatedAccount.email}`);
444
502
  // Execute account fetch logic again (auth only, preserve session)
445
503
  console.log('Refreshing authentication...');
446
- await handleFetch({ authOnly: true, deleteSession: false });
504
+ await handleFetch({ authOnly: true, deleteSession: true });
447
505
  }
448
506
  catch (error) {
449
507
  spinner.fail(`Account switch failed: ${error}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dccxx/auggiegw",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "A Node.js TypeScript package",
5
5
  "main": "./dist/cli.js",
6
6
  "types": "./dist/cli.d.ts",
@@ -19,6 +19,7 @@
19
19
  "devDependencies": {
20
20
  "@biomejs/biome": "2.2.5",
21
21
  "@types/node": "^24.7.0",
22
+ "@types/uuid": "^11.0.0",
22
23
  "typescript": "^5.9.3"
23
24
  },
24
25
  "engines": {
@@ -26,6 +27,7 @@
26
27
  },
27
28
  "dependencies": {
28
29
  "commander": "^14.0.1",
29
- "ora": "^5.4.1"
30
+ "ora": "^5.4.1",
31
+ "uuid": "^13.0.0"
30
32
  }
31
33
  }