kaimon-cli 0.1.2 → 0.1.3

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -32
  3. package/bin/index.js +1 -1
  4. package/dist/commands/config.d.ts.map +1 -1
  5. package/dist/commands/config.js +13 -4
  6. package/dist/commands/config.js.map +1 -1
  7. package/dist/commands/pull.d.ts +4 -0
  8. package/dist/commands/pull.d.ts.map +1 -0
  9. package/dist/commands/pull.js +20 -0
  10. package/dist/commands/pull.js.map +1 -0
  11. package/dist/commands/push.d.ts +4 -0
  12. package/dist/commands/push.d.ts.map +1 -0
  13. package/dist/commands/push.js +19 -0
  14. package/dist/commands/push.js.map +1 -0
  15. package/dist/commands/sync.d.ts.map +1 -1
  16. package/dist/commands/sync.js +3 -14
  17. package/dist/commands/sync.js.map +1 -1
  18. package/dist/config/constants.d.ts +1 -1
  19. package/dist/config/constants.d.ts.map +1 -1
  20. package/dist/config/constants.js +7 -3
  21. package/dist/config/constants.js.map +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +4 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/utils/markdown.d.ts +21 -0
  26. package/dist/utils/markdown.d.ts.map +1 -0
  27. package/dist/utils/markdown.js +180 -0
  28. package/dist/utils/markdown.js.map +1 -0
  29. package/dist/utils/projectConfig.d.ts +25 -0
  30. package/dist/utils/projectConfig.d.ts.map +1 -0
  31. package/dist/utils/projectConfig.js +160 -0
  32. package/dist/utils/projectConfig.js.map +1 -0
  33. package/dist/utils/supabaseClient.d.ts +11 -0
  34. package/dist/utils/supabaseClient.d.ts.map +1 -0
  35. package/dist/utils/supabaseClient.js +43 -0
  36. package/dist/utils/supabaseClient.js.map +1 -0
  37. package/dist/utils/syncOperations.d.ts +16 -0
  38. package/dist/utils/syncOperations.d.ts.map +1 -0
  39. package/dist/utils/syncOperations.js +168 -0
  40. package/dist/utils/syncOperations.js.map +1 -0
  41. package/package.json +15 -8
  42. package/src/commands/auth.ts +0 -170
  43. package/src/commands/config.ts +0 -72
  44. package/src/commands/sync.ts +0 -30
  45. package/src/config/constants.ts +0 -27
  46. package/src/index.ts +0 -20
  47. package/src/utils/config.ts +0 -81
  48. package/src/utils/requireAuth.ts +0 -65
  49. package/tsconfig.json +0 -21
@@ -1,72 +0,0 @@
1
- import { Command } from 'commander';
2
- import chalk from 'chalk';
3
- import { loadConfig, getConfigPath } from '../utils/config.js';
4
-
5
- const config = new Command('config')
6
- .description('Manage Kaimon CLI configuration');
7
-
8
- config
9
- .command('init')
10
- .description('Initialize .kaimon config in current directory')
11
- .action(async () => {
12
- console.log(chalk.blue('⚙️ Config init - coming soon!'));
13
- console.log(chalk.yellow('\n⚠️ Project-level config not yet implemented'));
14
- console.log(chalk.dim('For now, all config is stored globally at:'));
15
- console.log(chalk.dim(` ${getConfigPath()}\n`));
16
- });
17
-
18
- config
19
- .command('show')
20
- .description('Show current configuration')
21
- .action(async () => {
22
- try {
23
- const configData = loadConfig();
24
- const configPath = getConfigPath();
25
-
26
- console.log(chalk.blue('🔍 Current Configuration\n'));
27
- console.log(chalk.gray(`Location: ${configPath}\n`));
28
-
29
- if (Object.keys(configData).length === 0) {
30
- console.log(chalk.yellow('No configuration found'));
31
- console.log(chalk.dim('Run "kaimon auth login" to authenticate\n'));
32
- return;
33
- }
34
-
35
- // Show config (mask sensitive data)
36
- console.log(chalk.cyan('Settings:'));
37
-
38
- if (configData.access_token) {
39
- const masked = configData.access_token.substring(0, 10) + '...';
40
- console.log(chalk.gray(` access_token: ${masked}`));
41
- }
42
-
43
- if (configData.refresh_token) {
44
- const masked = configData.refresh_token.substring(0, 10) + '...';
45
- console.log(chalk.gray(` refresh_token: ${masked}`));
46
- }
47
-
48
- if (configData.user_email) {
49
- console.log(chalk.gray(` user_email: ${configData.user_email}`));
50
- }
51
-
52
- if (configData.expires_at) {
53
- console.log(chalk.gray(` expires_at: ${configData.expires_at}`));
54
- }
55
-
56
- console.log();
57
-
58
- } catch (error: any) {
59
- console.error(chalk.red('❌ Failed to show config:'), error.message);
60
- process.exit(1);
61
- }
62
- });
63
-
64
- config
65
- .command('set <key> <value>')
66
- .description('Set a configuration value')
67
- .action(async (key, value) => {
68
- console.log(chalk.yellow(`⚠️ Manual config editing not yet supported`));
69
- console.log(chalk.dim('Use "kaimon auth login" to authenticate\n'));
70
- });
71
-
72
- export { config };
@@ -1,30 +0,0 @@
1
- import { Command } from 'commander';
2
- import chalk from 'chalk';
3
- import { requireAuth } from '../utils/requireAuth.js';
4
-
5
- const sync = new Command('sync')
6
- .description('Sync Kaimon documentation with your codebase')
7
- .option('--pull', 'Pull docs from Kaimon to local')
8
- .option('--push', 'Push local docs to Kaimon')
9
- .option('--diff', 'Show differences without syncing')
10
- .option('--config <path>', 'Path to sync config file')
11
- .action(async (options) => {
12
- try {
13
- // Validate authentication first
14
- const token = await requireAuth();
15
-
16
- console.log(chalk.blue('📁 Sync command - coming soon!'));
17
- console.log(chalk.gray(`Authenticated with token: ${token.substring(0, 10)}...`));
18
- console.log(chalk.gray('Options:'), options);
19
-
20
- // TODO: Implement sync logic
21
- console.log(chalk.yellow('\n⚠️ Sync functionality not yet implemented'));
22
- console.log(chalk.dim('This will sync your documents with Kaimon in the future\n'));
23
-
24
- } catch (error: any) {
25
- console.error(chalk.red('❌ Sync failed:'), error.message);
26
- process.exit(1);
27
- }
28
- });
29
-
30
- export { sync };
@@ -1,27 +0,0 @@
1
- // Configuration constants for Kaimon CLI
2
-
3
- // Determine the base URL based on environment
4
- // In development, use localhost
5
- // In production, use the actual domain
6
- export const BASE_URL = process.env.KAIMON_API_URL || 'https://kaimon.ai';
7
-
8
- // For local development testing
9
- export const DEV_URL = 'http://localhost:5173';
10
-
11
- // Determine which URL to use
12
- export const getAuthUrl = (): string => {
13
- // Check if we're in development mode
14
- const isDev = process.env.NODE_ENV === 'development' || process.env.KAIMON_DEV === 'true';
15
- return isDev ? DEV_URL : BASE_URL;
16
- };
17
-
18
- // CLI auth endpoint
19
- export const CLI_AUTH_PATH = '/cli-auth';
20
-
21
- // Config file location
22
- export const CONFIG_DIR = '.kaimon';
23
- export const CONFIG_FILE = 'config.json';
24
-
25
- // Supabase config (will be same as web app)
26
- export const SUPABASE_URL = process.env.KAIMON_SUPABASE_URL || 'https://your-project.supabase.co';
27
- export const SUPABASE_ANON_KEY = process.env.KAIMON_SUPABASE_ANON_KEY || '';
package/src/index.ts DELETED
@@ -1,20 +0,0 @@
1
- import { Command } from 'commander';
2
- import { auth } from './commands/auth.js';
3
- import { sync } from './commands/sync.js';
4
- import { config } from './commands/config.js';
5
-
6
- const program = new Command();
7
-
8
- program
9
- .name('kaimon')
10
- .description('Sync Kaimon documentation with your codebase')
11
- .version('0.1.0');
12
-
13
- // Register commands
14
- program.addCommand(auth);
15
- program.addCommand(sync);
16
- program.addCommand(config);
17
-
18
- export async function main() {
19
- await program.parseAsync(process.argv);
20
- }
@@ -1,81 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import os from 'os';
4
- import { CONFIG_DIR, CONFIG_FILE } from '../config/constants.js';
5
-
6
- export interface CLIConfig {
7
- access_token?: string;
8
- refresh_token?: string;
9
- expires_at?: string;
10
- user_email?: string;
11
- }
12
-
13
- // Get config directory path
14
- export function getConfigDir(): string {
15
- return path.join(os.homedir(), CONFIG_DIR);
16
- }
17
-
18
- // Get config file path
19
- export function getConfigPath(): string {
20
- return path.join(getConfigDir(), CONFIG_FILE);
21
- }
22
-
23
- // Ensure config directory exists
24
- export function ensureConfigDir(): void {
25
- const configDir = getConfigDir();
26
- if (!fs.existsSync(configDir)) {
27
- fs.mkdirSync(configDir, { recursive: true, mode: 0o700 }); // Only user can read/write
28
- }
29
- }
30
-
31
- // Load config from file
32
- export function loadConfig(): CLIConfig {
33
- const configPath = getConfigPath();
34
-
35
- if (!fs.existsSync(configPath)) {
36
- return {};
37
- }
38
-
39
- try {
40
- const content = fs.readFileSync(configPath, 'utf-8');
41
- return JSON.parse(content);
42
- } catch (error) {
43
- console.error('Failed to load config:', error);
44
- return {};
45
- }
46
- }
47
-
48
- // Save config to file
49
- export function saveConfig(config: CLIConfig): void {
50
- ensureConfigDir();
51
- const configPath = getConfigPath();
52
-
53
- try {
54
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2), {
55
- mode: 0o600 // Only user can read/write
56
- });
57
- } catch (error) {
58
- throw new Error(`Failed to save config: ${error}`);
59
- }
60
- }
61
-
62
- // Clear config (logout)
63
- export function clearConfig(): void {
64
- const configPath = getConfigPath();
65
-
66
- if (fs.existsSync(configPath)) {
67
- fs.unlinkSync(configPath);
68
- }
69
- }
70
-
71
- // Check if user is authenticated
72
- export function isAuthenticated(): boolean {
73
- const config = loadConfig();
74
- return !!config.access_token;
75
- }
76
-
77
- // Get access token
78
- export function getAccessToken(): string | null {
79
- const config = loadConfig();
80
- return config.access_token || null;
81
- }
@@ -1,65 +0,0 @@
1
- import chalk from 'chalk';
2
- import { loadConfig } from './config.js';
3
-
4
- /**
5
- * Validates authentication and returns the access token.
6
- * Exits the process with helpful error message if not authenticated or token expired.
7
- */
8
- export async function requireAuth(): Promise<string> {
9
- const config = loadConfig();
10
-
11
- // Check if token exists
12
- if (!config.access_token) {
13
- console.log(chalk.red('\n❌ Not authenticated'));
14
- console.log(chalk.yellow('Please login first:'));
15
- console.log(chalk.cyan(' kaimon auth login\n'));
16
- process.exit(1);
17
- }
18
-
19
- // Check if token is expired
20
- if (config.expires_at) {
21
- const expiresAt = new Date(config.expires_at);
22
- const now = new Date();
23
-
24
- if (expiresAt < now) {
25
- console.log(chalk.red('\n❌ Authentication expired'));
26
- console.log(chalk.yellow('Your session has expired. Please login again:'));
27
- console.log(chalk.cyan(' kaimon auth login\n'));
28
- process.exit(1);
29
- }
30
-
31
- // Warn if expiring soon (within 5 minutes)
32
- const fiveMinutes = 5 * 60 * 1000;
33
- const timeUntilExpiry = expiresAt.getTime() - now.getTime();
34
-
35
- if (timeUntilExpiry < fiveMinutes && timeUntilExpiry > 0) {
36
- console.log(chalk.yellow(`⚠️ Token expires in ${Math.floor(timeUntilExpiry / 60000)} minutes`));
37
- console.log(chalk.dim('Consider re-authenticating soon\n'));
38
- }
39
- }
40
-
41
- return config.access_token;
42
- }
43
-
44
- /**
45
- * Checks if user is authenticated without exiting.
46
- * Returns true if authenticated and token is valid.
47
- */
48
- export function checkAuth(): boolean {
49
- const config = loadConfig();
50
-
51
- if (!config.access_token) {
52
- return false;
53
- }
54
-
55
- if (config.expires_at) {
56
- const expiresAt = new Date(config.expires_at);
57
- const now = new Date();
58
-
59
- if (expiresAt < now) {
60
- return false;
61
- }
62
- }
63
-
64
- return true;
65
- }
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "lib": ["ES2020"],
6
- "moduleResolution": "node",
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "resolveJsonModule": true,
14
- "declaration": true,
15
- "declarationMap": true,
16
- "sourceMap": true,
17
- "allowSyntheticDefaultImports": true
18
- },
19
- "include": ["src"],
20
- "exclude": ["node_modules", "dist", "tests"]
21
- }