@chaim-tools/chaim 0.1.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 (84) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +211 -0
  3. package/dist/commands/apps/link.d.ts +26 -0
  4. package/dist/commands/apps/link.d.ts.map +1 -0
  5. package/dist/commands/apps/link.js +49 -0
  6. package/dist/commands/apps/link.js.map +1 -0
  7. package/dist/commands/apps/list.d.ts +25 -0
  8. package/dist/commands/apps/list.d.ts.map +1 -0
  9. package/dist/commands/apps/list.js +46 -0
  10. package/dist/commands/apps/list.js.map +1 -0
  11. package/dist/commands/auth/login.d.ts +29 -0
  12. package/dist/commands/auth/login.d.ts.map +1 -0
  13. package/dist/commands/auth/login.js +51 -0
  14. package/dist/commands/auth/login.js.map +1 -0
  15. package/dist/commands/auth/logout.d.ts +26 -0
  16. package/dist/commands/auth/logout.d.ts.map +1 -0
  17. package/dist/commands/auth/logout.js +49 -0
  18. package/dist/commands/auth/logout.js.map +1 -0
  19. package/dist/commands/auth/refresh.d.ts +27 -0
  20. package/dist/commands/auth/refresh.d.ts.map +1 -0
  21. package/dist/commands/auth/refresh.js +47 -0
  22. package/dist/commands/auth/refresh.js.map +1 -0
  23. package/dist/commands/auth/whoami.d.ts +28 -0
  24. package/dist/commands/auth/whoami.d.ts.map +1 -0
  25. package/dist/commands/auth/whoami.js +48 -0
  26. package/dist/commands/auth/whoami.js.map +1 -0
  27. package/dist/commands/clean.d.ts +25 -0
  28. package/dist/commands/clean.d.ts.map +1 -0
  29. package/dist/commands/clean.js +345 -0
  30. package/dist/commands/clean.js.map +1 -0
  31. package/dist/commands/config/show.d.ts +25 -0
  32. package/dist/commands/config/show.d.ts.map +1 -0
  33. package/dist/commands/config/show.js +49 -0
  34. package/dist/commands/config/show.js.map +1 -0
  35. package/dist/commands/configure.d.ts +26 -0
  36. package/dist/commands/configure.d.ts.map +1 -0
  37. package/dist/commands/configure.js +53 -0
  38. package/dist/commands/configure.js.map +1 -0
  39. package/dist/commands/doctor.d.ts +2 -0
  40. package/dist/commands/doctor.d.ts.map +1 -0
  41. package/dist/commands/doctor.js +96 -0
  42. package/dist/commands/doctor.js.map +1 -0
  43. package/dist/commands/generate.d.ts +11 -0
  44. package/dist/commands/generate.d.ts.map +1 -0
  45. package/dist/commands/generate.js +395 -0
  46. package/dist/commands/generate.js.map +1 -0
  47. package/dist/commands/init.d.ts +8 -0
  48. package/dist/commands/init.d.ts.map +1 -0
  49. package/dist/commands/init.js +302 -0
  50. package/dist/commands/init.js.map +1 -0
  51. package/dist/commands/validate.d.ts +2 -0
  52. package/dist/commands/validate.d.ts.map +1 -0
  53. package/dist/commands/validate.js +58 -0
  54. package/dist/commands/validate.js.map +1 -0
  55. package/dist/config/types.d.ts +138 -0
  56. package/dist/config/types.d.ts.map +1 -0
  57. package/dist/config/types.js +48 -0
  58. package/dist/config/types.js.map +1 -0
  59. package/dist/index.d.ts +3 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +114 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/planned-commands.d.ts +51 -0
  64. package/dist/planned-commands.d.ts.map +1 -0
  65. package/dist/planned-commands.js +199 -0
  66. package/dist/planned-commands.js.map +1 -0
  67. package/dist/services/os-cache-paths.d.ts +15 -0
  68. package/dist/services/os-cache-paths.d.ts.map +1 -0
  69. package/dist/services/os-cache-paths.js +57 -0
  70. package/dist/services/os-cache-paths.js.map +1 -0
  71. package/dist/services/snapshot-discovery.d.ts +111 -0
  72. package/dist/services/snapshot-discovery.d.ts.map +1 -0
  73. package/dist/services/snapshot-discovery.js +249 -0
  74. package/dist/services/snapshot-discovery.js.map +1 -0
  75. package/dist/types/index.d.ts +8 -0
  76. package/dist/types/index.d.ts.map +1 -0
  77. package/dist/types/index.js +9 -0
  78. package/dist/types/index.js.map +1 -0
  79. package/dist/types/snapshot-payload.d.ts +205 -0
  80. package/dist/types/snapshot-payload.d.ts.map +1 -0
  81. package/dist/types/snapshot-payload.js +9 -0
  82. package/dist/types/snapshot-payload.js.map +1 -0
  83. package/package.json +65 -0
  84. package/shared/scripts/setup.sh +47 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * chaim auth logout
3
+ *
4
+ * Purpose:
5
+ * Clear local credentials and optionally revoke tokens server-side.
6
+ * Supports logging out a specific profile or all profiles.
7
+ *
8
+ * Expected Sub-APIs:
9
+ * - Chaim Auth API: Revoke token (optional, if --revoke flag used)
10
+ *
11
+ * Local Config Read/Write:
12
+ * - Reads: ~/.chaim/config.json (profile list)
13
+ * - Writes: ~/.chaim/config.json (remove profile or clear active)
14
+ * - Writes: Platform keychain or ~/.chaim/credentials (delete tokens)
15
+ *
16
+ * Security:
17
+ * - Securely delete tokens from storage
18
+ * - Clear any cached user data
19
+ * - Confirm before logging out all profiles
20
+ */
21
+ import { Command } from 'commander';
22
+ /**
23
+ * Register the `auth logout` command with the CLI program
24
+ */
25
+ export declare function registerAuthLogoutCommand(program: Command): Command;
26
+ //# sourceMappingURL=logout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/logout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAsBnE"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * chaim auth logout
4
+ *
5
+ * Purpose:
6
+ * Clear local credentials and optionally revoke tokens server-side.
7
+ * Supports logging out a specific profile or all profiles.
8
+ *
9
+ * Expected Sub-APIs:
10
+ * - Chaim Auth API: Revoke token (optional, if --revoke flag used)
11
+ *
12
+ * Local Config Read/Write:
13
+ * - Reads: ~/.chaim/config.json (profile list)
14
+ * - Writes: ~/.chaim/config.json (remove profile or clear active)
15
+ * - Writes: Platform keychain or ~/.chaim/credentials (delete tokens)
16
+ *
17
+ * Security:
18
+ * - Securely delete tokens from storage
19
+ * - Clear any cached user data
20
+ * - Confirm before logging out all profiles
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.registerAuthLogoutCommand = void 0;
24
+ /**
25
+ * Register the `auth logout` command with the CLI program
26
+ */
27
+ function registerAuthLogoutCommand(program) {
28
+ const authCmd = program.commands.find((cmd) => cmd.name() === 'auth')
29
+ ?? program.command('auth').description('Authentication commands');
30
+ authCmd
31
+ .command('logout')
32
+ .description('Clear local credentials')
33
+ .option('--profile <name>', 'Logout specific profile (default: active profile)')
34
+ .option('--all', 'Logout all profiles')
35
+ .option('--revoke', 'Also revoke tokens server-side')
36
+ .action(async (options) => {
37
+ console.log('Not implemented yet. See docs/CLI_ROADMAP.md');
38
+ // Future implementation:
39
+ // 1. Determine which profile(s) to logout
40
+ // 2. If --all, confirm with user
41
+ // 3. If --revoke, call API to revoke tokens
42
+ // 4. Delete tokens from secure storage
43
+ // 5. Update config file (remove profile or clear active)
44
+ // 6. Display confirmation
45
+ });
46
+ return program;
47
+ }
48
+ exports.registerAuthLogoutCommand = registerAuthLogoutCommand;
49
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../../src/commands/auth/logout.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAIH;;GAEG;AACH,SAAgB,yBAAyB,CAAC,OAAgB;IACxD,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,MAAM,CAAC;WAChE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;IAEpE,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,yBAAyB,CAAC;SACtC,MAAM,CAAC,kBAAkB,EAAE,mDAAmD,CAAC;SAC/E,MAAM,CAAC,OAAO,EAAE,qBAAqB,CAAC;SACtC,MAAM,CAAC,UAAU,EAAE,gCAAgC,CAAC;SACpD,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,yBAAyB;QACzB,0CAA0C;QAC1C,iCAAiC;QACjC,4CAA4C;QAC5C,uCAAuC;QACvC,yDAAyD;QACzD,0BAA0B;IAC5B,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC;AAtBD,8DAsBC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * chaim auth refresh
3
+ *
4
+ * Purpose:
5
+ * Manually refresh authentication tokens. This is primarily for debugging
6
+ * token issues, as normal operations handle refresh automatically.
7
+ *
8
+ * Expected Sub-APIs:
9
+ * - Chaim Auth API: Refresh token endpoint
10
+ *
11
+ * Local Config Read/Write:
12
+ * - Reads: ~/.chaim/config.json (active profile)
13
+ * - Reads: Platform keychain or ~/.chaim/credentials (refresh token)
14
+ * - Writes: Platform keychain or ~/.chaim/credentials (new access token)
15
+ * - Writes: ~/.chaim/config.json (update token expiry metadata)
16
+ *
17
+ * Security:
18
+ * - NEVER log tokens to console
19
+ * - Store new tokens securely
20
+ * - Clear old tokens from memory
21
+ */
22
+ import { Command } from 'commander';
23
+ /**
24
+ * Register the `auth refresh` command with the CLI program
25
+ */
26
+ export declare function registerAuthRefreshCommand(program: Command): Command;
27
+ //# sourceMappingURL=refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAmBpE"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * chaim auth refresh
4
+ *
5
+ * Purpose:
6
+ * Manually refresh authentication tokens. This is primarily for debugging
7
+ * token issues, as normal operations handle refresh automatically.
8
+ *
9
+ * Expected Sub-APIs:
10
+ * - Chaim Auth API: Refresh token endpoint
11
+ *
12
+ * Local Config Read/Write:
13
+ * - Reads: ~/.chaim/config.json (active profile)
14
+ * - Reads: Platform keychain or ~/.chaim/credentials (refresh token)
15
+ * - Writes: Platform keychain or ~/.chaim/credentials (new access token)
16
+ * - Writes: ~/.chaim/config.json (update token expiry metadata)
17
+ *
18
+ * Security:
19
+ * - NEVER log tokens to console
20
+ * - Store new tokens securely
21
+ * - Clear old tokens from memory
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.registerAuthRefreshCommand = void 0;
25
+ /**
26
+ * Register the `auth refresh` command with the CLI program
27
+ */
28
+ function registerAuthRefreshCommand(program) {
29
+ const authCmd = program.commands.find((cmd) => cmd.name() === 'auth')
30
+ ?? program.command('auth').description('Authentication commands');
31
+ authCmd
32
+ .command('refresh')
33
+ .description('Manually refresh authentication tokens')
34
+ .option('--profile <name>', 'Profile to refresh (default: active profile)')
35
+ .action(async (options) => {
36
+ console.log('Not implemented yet. See docs/CLI_ROADMAP.md');
37
+ // Future implementation:
38
+ // 1. Load profile and refresh token
39
+ // 2. Call auth API to exchange refresh token for new access token
40
+ // 3. Store new access token securely
41
+ // 4. Update token expiry in config metadata
42
+ // 5. Display success with new expiry time
43
+ });
44
+ return program;
45
+ }
46
+ exports.registerAuthRefreshCommand = registerAuthRefreshCommand;
47
+ //# sourceMappingURL=refresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh.js","sourceRoot":"","sources":["../../../src/commands/auth/refresh.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAIH;;GAEG;AACH,SAAgB,0BAA0B,CAAC,OAAgB;IACzD,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,MAAM,CAAC;WAChE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;IAEpE,OAAO;SACJ,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,wCAAwC,CAAC;SACrD,MAAM,CAAC,kBAAkB,EAAE,8CAA8C,CAAC;SAC1E,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,yBAAyB;QACzB,oCAAoC;QACpC,kEAAkE;QAClE,qCAAqC;QACrC,4CAA4C;QAC5C,0CAA0C;IAC5C,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC;AAnBD,gEAmBC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * chaim auth whoami
3
+ *
4
+ * Purpose:
5
+ * Display the current authenticated user/org context and active profile.
6
+ * Helps users verify which identity and context they're operating under.
7
+ *
8
+ * Expected Sub-APIs:
9
+ * - Chaim Auth API: Validate token and get user info
10
+ * - Chaim API: Get organization details (if org context set)
11
+ *
12
+ * Local Config Read/Write:
13
+ * - Reads: ~/.chaim/config.json (active profile, profile metadata)
14
+ * - Reads: Platform keychain or ~/.chaim/credentials (to check token validity)
15
+ * - Reads: ./chaim.json (linked app context)
16
+ * - Writes: None
17
+ *
18
+ * Security:
19
+ * - NEVER display full tokens
20
+ * - May display masked token prefix for identification
21
+ * - Display token expiry time
22
+ */
23
+ import { Command } from 'commander';
24
+ /**
25
+ * Register the `auth whoami` command with the CLI program
26
+ */
27
+ export declare function registerAuthWhoamiCommand(program: Command): Command;
28
+ //# sourceMappingURL=whoami.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/whoami.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAmBnE"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * chaim auth whoami
4
+ *
5
+ * Purpose:
6
+ * Display the current authenticated user/org context and active profile.
7
+ * Helps users verify which identity and context they're operating under.
8
+ *
9
+ * Expected Sub-APIs:
10
+ * - Chaim Auth API: Validate token and get user info
11
+ * - Chaim API: Get organization details (if org context set)
12
+ *
13
+ * Local Config Read/Write:
14
+ * - Reads: ~/.chaim/config.json (active profile, profile metadata)
15
+ * - Reads: Platform keychain or ~/.chaim/credentials (to check token validity)
16
+ * - Reads: ./chaim.json (linked app context)
17
+ * - Writes: None
18
+ *
19
+ * Security:
20
+ * - NEVER display full tokens
21
+ * - May display masked token prefix for identification
22
+ * - Display token expiry time
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.registerAuthWhoamiCommand = void 0;
26
+ /**
27
+ * Register the `auth whoami` command with the CLI program
28
+ */
29
+ function registerAuthWhoamiCommand(program) {
30
+ const authCmd = program.commands.find((cmd) => cmd.name() === 'auth')
31
+ ?? program.command('auth').description('Authentication commands');
32
+ authCmd
33
+ .command('whoami')
34
+ .description('Display current authenticated user and context')
35
+ .option('--profile <name>', 'Check specific profile instead of active')
36
+ .action(async (options) => {
37
+ console.log('Not implemented yet. See docs/CLI_ROADMAP.md');
38
+ // Future implementation:
39
+ // 1. Load active profile (or specified profile)
40
+ // 2. Check if tokens exist and are valid
41
+ // 3. Call API to get current user info
42
+ // 4. Display: email, user ID, org context, token expiry
43
+ // 5. If repo has linked app, show that context too
44
+ });
45
+ return program;
46
+ }
47
+ exports.registerAuthWhoamiCommand = registerAuthWhoamiCommand;
48
+ //# sourceMappingURL=whoami.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whoami.js","sourceRoot":"","sources":["../../../src/commands/auth/whoami.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAIH;;GAEG;AACH,SAAgB,yBAAyB,CAAC,OAAgB;IACxD,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,MAAM,CAAC;WAChE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;IAEpE,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,gDAAgD,CAAC;SAC7D,MAAM,CAAC,kBAAkB,EAAE,0CAA0C,CAAC;SACtE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,yBAAyB;QACzB,gDAAgD;QAChD,yCAAyC;QACzC,uCAAuC;QACvC,wDAAwD;QACxD,mDAAmD;IACrD,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC;AAnBD,8DAmBC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Options for clean command.
3
+ */
4
+ export interface CleanOptions {
5
+ /** Stack name to clean (if specified, only clean this stack) */
6
+ stack?: string;
7
+ /** Delete all snapshots */
8
+ all?: boolean;
9
+ /** Delete snapshots older than N days */
10
+ olderThan?: number;
11
+ /** Dry run - show what would be deleted without actually deleting */
12
+ dryRun?: boolean;
13
+ /** Verbose output */
14
+ verbose?: boolean;
15
+ }
16
+ /**
17
+ * Clean snapshot cache command.
18
+ *
19
+ * Provides options for:
20
+ * - Cleaning specific stack snapshots
21
+ * - Cleaning all snapshots
22
+ * - TTL-based cleanup (snapshots older than N days)
23
+ */
24
+ export declare function cleanCommand(options: CleanOptions): Promise<void>;
25
+ //# sourceMappingURL=clean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,2BAA2B;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,qEAAqE;IACrE,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,qBAAqB;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA6DvE"}
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.cleanCommand = void 0;
30
+ const chalk_1 = __importDefault(require("chalk"));
31
+ const fs = __importStar(require("fs"));
32
+ const path = __importStar(require("path"));
33
+ const os_cache_paths_1 = require("../services/os-cache-paths");
34
+ /**
35
+ * Clean snapshot cache command.
36
+ *
37
+ * Provides options for:
38
+ * - Cleaning specific stack snapshots
39
+ * - Cleaning all snapshots
40
+ * - TTL-based cleanup (snapshots older than N days)
41
+ */
42
+ async function cleanCommand(options) {
43
+ const { stack, all = false, olderThan, dryRun = false, verbose = false, } = options;
44
+ const baseDir = (0, os_cache_paths_1.getSnapshotBaseDir)();
45
+ console.log(chalk_1.default.cyan('Chaim Snapshot Cache Cleanup'));
46
+ console.log('');
47
+ if (dryRun) {
48
+ console.log(chalk_1.default.yellow('DRY RUN - no files will be deleted'));
49
+ console.log('');
50
+ }
51
+ // Validate options
52
+ if (all && stack) {
53
+ console.error(chalk_1.default.red('Error: Cannot specify both --all and --stack'));
54
+ process.exit(1);
55
+ }
56
+ if (all && olderThan) {
57
+ console.error(chalk_1.default.red('Error: Cannot specify both --all and --older-than'));
58
+ process.exit(1);
59
+ }
60
+ if (!all && !stack && !olderThan) {
61
+ console.error(chalk_1.default.red('Error: Must specify one of: --all, --stack, or --older-than'));
62
+ console.error('');
63
+ console.error(chalk_1.default.white('Examples:'));
64
+ console.error(chalk_1.default.gray(' chaim clean --stack ProductCatalogStack'));
65
+ console.error(chalk_1.default.gray(' chaim clean --older-than 30'));
66
+ console.error(chalk_1.default.gray(' chaim clean --all'));
67
+ process.exit(1);
68
+ }
69
+ // Check if snapshot directory exists
70
+ if (!fs.existsSync(baseDir)) {
71
+ console.log(chalk_1.default.yellow('Snapshot cache directory does not exist:'));
72
+ console.log(chalk_1.default.gray(` ${baseDir}`));
73
+ console.log('');
74
+ console.log(chalk_1.default.green('Nothing to clean'));
75
+ return;
76
+ }
77
+ try {
78
+ if (all) {
79
+ await cleanAllSnapshots(baseDir, dryRun, verbose);
80
+ }
81
+ else if (stack) {
82
+ await cleanStackSnapshots(baseDir, stack, dryRun, verbose);
83
+ }
84
+ else if (olderThan !== undefined) {
85
+ await cleanOldSnapshots(baseDir, olderThan, dryRun, verbose);
86
+ }
87
+ }
88
+ catch (error) {
89
+ console.error(chalk_1.default.red('Cleanup failed:'), error instanceof Error ? error.message : error);
90
+ process.exit(1);
91
+ }
92
+ }
93
+ exports.cleanCommand = cleanCommand;
94
+ /**
95
+ * Clean all snapshots.
96
+ */
97
+ async function cleanAllSnapshots(baseDir, dryRun, verbose) {
98
+ console.log(chalk_1.default.white('Cleaning all snapshots...'));
99
+ console.log(chalk_1.default.gray(`Base directory: ${baseDir}`));
100
+ console.log('');
101
+ const result = collectAllSnapshots(baseDir);
102
+ if (result.count === 0) {
103
+ console.log(chalk_1.default.yellow('No snapshots found'));
104
+ return;
105
+ }
106
+ console.log(chalk_1.default.white(`Found ${result.count} snapshot(s)`));
107
+ if (verbose) {
108
+ console.log('');
109
+ result.files.forEach(file => {
110
+ console.log(chalk_1.default.gray(` ${path.relative(baseDir, file)}`));
111
+ });
112
+ }
113
+ console.log('');
114
+ if (dryRun) {
115
+ console.log(chalk_1.default.yellow(`Would delete ${result.count} snapshot(s)`));
116
+ }
117
+ else {
118
+ // Delete files
119
+ let deleted = 0;
120
+ let failed = 0;
121
+ for (const file of result.files) {
122
+ try {
123
+ fs.unlinkSync(file);
124
+ deleted++;
125
+ }
126
+ catch (error) {
127
+ failed++;
128
+ if (verbose) {
129
+ console.error(chalk_1.default.red(`Failed to delete: ${file}`));
130
+ }
131
+ }
132
+ }
133
+ // Clean up empty directories
134
+ cleanEmptyDirectories(baseDir);
135
+ console.log(chalk_1.default.green(`Deleted ${deleted} snapshot(s)`));
136
+ if (failed > 0) {
137
+ console.log(chalk_1.default.yellow(`Failed to delete ${failed} snapshot(s)`));
138
+ }
139
+ }
140
+ }
141
+ /**
142
+ * Clean snapshots for a specific stack.
143
+ */
144
+ async function cleanStackSnapshots(baseDir, stackName, dryRun, verbose) {
145
+ console.log(chalk_1.default.white(`Cleaning snapshots for stack: ${stackName}`));
146
+ console.log('');
147
+ const stackDirs = findStackDirectories(baseDir, stackName);
148
+ if (stackDirs.length === 0) {
149
+ console.log(chalk_1.default.yellow(`No snapshots found for stack: ${stackName}`));
150
+ return;
151
+ }
152
+ let totalCount = 0;
153
+ let deleted = 0;
154
+ let failed = 0;
155
+ for (const stackDir of stackDirs) {
156
+ const result = collectAllSnapshots(stackDir);
157
+ totalCount += result.count;
158
+ console.log(chalk_1.default.gray(`Found ${result.count} snapshot(s) in ${path.relative(baseDir, stackDir)}`));
159
+ if (verbose && result.count > 0) {
160
+ result.files.forEach(file => {
161
+ console.log(chalk_1.default.gray(` ${path.basename(file)}`));
162
+ });
163
+ }
164
+ if (!dryRun) {
165
+ for (const file of result.files) {
166
+ try {
167
+ fs.unlinkSync(file);
168
+ deleted++;
169
+ }
170
+ catch (error) {
171
+ failed++;
172
+ if (verbose) {
173
+ console.error(chalk_1.default.red(`Failed to delete: ${file}`));
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ console.log('');
180
+ if (dryRun) {
181
+ console.log(chalk_1.default.yellow(`Would delete ${totalCount} snapshot(s)`));
182
+ }
183
+ else {
184
+ // Clean up empty directories
185
+ cleanEmptyDirectories(baseDir);
186
+ console.log(chalk_1.default.green(`Deleted ${deleted} snapshot(s)`));
187
+ if (failed > 0) {
188
+ console.log(chalk_1.default.yellow(`Failed to delete ${failed} snapshot(s)`));
189
+ }
190
+ }
191
+ }
192
+ /**
193
+ * Clean snapshots older than specified days.
194
+ */
195
+ async function cleanOldSnapshots(baseDir, days, dryRun, verbose) {
196
+ console.log(chalk_1.default.white(`Cleaning snapshots older than ${days} days...`));
197
+ console.log('');
198
+ const now = Date.now();
199
+ const cutoffMs = days * 24 * 60 * 60 * 1000;
200
+ const allSnapshots = collectAllSnapshots(baseDir);
201
+ if (allSnapshots.count === 0) {
202
+ console.log(chalk_1.default.yellow('No snapshots found'));
203
+ return;
204
+ }
205
+ let oldCount = 0;
206
+ let deleted = 0;
207
+ let failed = 0;
208
+ const oldFiles = [];
209
+ for (const file of allSnapshots.files) {
210
+ try {
211
+ const stats = fs.statSync(file);
212
+ const ageMs = now - stats.mtimeMs;
213
+ if (ageMs > cutoffMs) {
214
+ const ageDays = Math.floor(ageMs / (24 * 60 * 60 * 1000));
215
+ oldCount++;
216
+ oldFiles.push({ path: file, ageDays });
217
+ }
218
+ }
219
+ catch (error) {
220
+ if (verbose) {
221
+ console.error(chalk_1.default.red(`Failed to stat: ${file}`));
222
+ }
223
+ }
224
+ }
225
+ if (oldCount === 0) {
226
+ console.log(chalk_1.default.yellow(`No snapshots older than ${days} days found`));
227
+ return;
228
+ }
229
+ console.log(chalk_1.default.white(`Found ${oldCount} snapshot(s) older than ${days} days`));
230
+ if (verbose) {
231
+ console.log('');
232
+ oldFiles.slice(0, 10).forEach(({ path: filePath, ageDays }) => {
233
+ console.log(chalk_1.default.gray(` ${path.relative(baseDir, filePath)} (${ageDays} days old)`));
234
+ });
235
+ if (oldFiles.length > 10) {
236
+ console.log(chalk_1.default.gray(` ... and ${oldFiles.length - 10} more`));
237
+ }
238
+ }
239
+ console.log('');
240
+ if (dryRun) {
241
+ console.log(chalk_1.default.yellow(`Would delete ${oldCount} snapshot(s)`));
242
+ }
243
+ else {
244
+ for (const { path: file } of oldFiles) {
245
+ try {
246
+ fs.unlinkSync(file);
247
+ deleted++;
248
+ }
249
+ catch (error) {
250
+ failed++;
251
+ if (verbose) {
252
+ console.error(chalk_1.default.red(`Failed to delete: ${file}`));
253
+ }
254
+ }
255
+ }
256
+ // Clean up empty directories
257
+ cleanEmptyDirectories(baseDir);
258
+ console.log(chalk_1.default.green(`Deleted ${deleted} snapshot(s)`));
259
+ if (failed > 0) {
260
+ console.log(chalk_1.default.yellow(`Failed to delete ${failed} snapshot(s)`));
261
+ }
262
+ }
263
+ }
264
+ /**
265
+ * Collect all snapshot files in a directory.
266
+ */
267
+ function collectAllSnapshots(dir) {
268
+ const files = [];
269
+ if (!fs.existsSync(dir)) {
270
+ return { count: 0, files: [] };
271
+ }
272
+ function walk(currentDir) {
273
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
274
+ for (const entry of entries) {
275
+ const fullPath = path.join(currentDir, entry.name);
276
+ if (entry.isDirectory()) {
277
+ walk(fullPath);
278
+ }
279
+ else if (entry.isFile() && entry.name.endsWith('.json')) {
280
+ files.push(fullPath);
281
+ }
282
+ }
283
+ }
284
+ walk(dir);
285
+ return { count: files.length, files };
286
+ }
287
+ /**
288
+ * Find all directories for a given stack name.
289
+ */
290
+ function findStackDirectories(baseDir, stackName) {
291
+ const stackDirs = [];
292
+ if (!fs.existsSync(baseDir)) {
293
+ return stackDirs;
294
+ }
295
+ const awsDir = path.join(baseDir, 'aws');
296
+ if (!fs.existsSync(awsDir)) {
297
+ return stackDirs;
298
+ }
299
+ function walk(currentDir, depth) {
300
+ if (depth > 4)
301
+ return; // aws/account/region/stack/datastore
302
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
303
+ for (const entry of entries) {
304
+ if (!entry.isDirectory())
305
+ continue;
306
+ const fullPath = path.join(currentDir, entry.name);
307
+ // Check if this is a stack directory
308
+ if (entry.name === stackName) {
309
+ stackDirs.push(fullPath);
310
+ }
311
+ else {
312
+ walk(fullPath, depth + 1);
313
+ }
314
+ }
315
+ }
316
+ walk(awsDir, 0);
317
+ return stackDirs;
318
+ }
319
+ /**
320
+ * Recursively remove empty directories.
321
+ */
322
+ function cleanEmptyDirectories(dir) {
323
+ if (!fs.existsSync(dir)) {
324
+ return;
325
+ }
326
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
327
+ // First, recursively clean subdirectories
328
+ for (const entry of entries) {
329
+ if (entry.isDirectory()) {
330
+ const fullPath = path.join(dir, entry.name);
331
+ cleanEmptyDirectories(fullPath);
332
+ }
333
+ }
334
+ // Now check if directory is empty and remove it
335
+ const remainingEntries = fs.readdirSync(dir);
336
+ if (remainingEntries.length === 0) {
337
+ try {
338
+ fs.rmdirSync(dir);
339
+ }
340
+ catch {
341
+ // Ignore errors
342
+ }
343
+ }
344
+ }
345
+ //# sourceMappingURL=clean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clean.js","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,uCAAyB;AACzB,2CAA6B;AAC7B,+DAAgE;AAsBhE;;;;;;;GAOG;AACI,KAAK,UAAU,YAAY,CAAC,OAAqB;IACtD,MAAM,EACJ,KAAK,EACL,GAAG,GAAG,KAAK,EACX,SAAS,EACT,MAAM,GAAG,KAAK,EACd,OAAO,GAAG,KAAK,GAChB,GAAG,OAAO,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAA,mCAAkB,GAAE,CAAC;IAErC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEhB,IAAI,MAAM,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,oCAAoC,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KACjB;IAED,mBAAmB;IACnB,IAAI,GAAG,IAAI,KAAK,EAAE;QAChB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC,CAAC;QACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,IAAI,GAAG,IAAI,SAAS,EAAE;QACpB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC,CAAC;QAC9E,OAAO,CAAC,IAAI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