@quantiya/codevibe-core 1.0.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 (49) hide show
  1. package/README.md +178 -0
  2. package/bin/codevibe.js +7 -0
  3. package/dist/appsync/appsync-client.d.ts +132 -0
  4. package/dist/appsync/appsync-client.js +568 -0
  5. package/dist/appsync/index.d.ts +2 -0
  6. package/dist/appsync/index.js +10 -0
  7. package/dist/appsync/queries.d.ts +16 -0
  8. package/dist/appsync/queries.js +189 -0
  9. package/dist/auth/auth-cli.d.ts +5 -0
  10. package/dist/auth/auth-cli.js +217 -0
  11. package/dist/auth/auth-service.d.ts +53 -0
  12. package/dist/auth/auth-service.js +310 -0
  13. package/dist/auth/index.d.ts +2 -0
  14. package/dist/auth/index.js +9 -0
  15. package/dist/config/config.d.ts +53 -0
  16. package/dist/config/config.js +123 -0
  17. package/dist/config/index.d.ts +2 -0
  18. package/dist/config/index.js +8 -0
  19. package/dist/crypto/crypto-service.d.ts +118 -0
  20. package/dist/crypto/crypto-service.js +284 -0
  21. package/dist/crypto/index.d.ts +1 -0
  22. package/dist/crypto/index.js +9 -0
  23. package/dist/index.d.ts +14 -0
  24. package/dist/index.js +68 -0
  25. package/dist/keychain/index.d.ts +1 -0
  26. package/dist/keychain/index.js +8 -0
  27. package/dist/keychain/keychain-manager.d.ts +125 -0
  28. package/dist/keychain/keychain-manager.js +375 -0
  29. package/dist/logger/index.d.ts +1 -0
  30. package/dist/logger/index.js +8 -0
  31. package/dist/logger/logger.d.ts +35 -0
  32. package/dist/logger/logger.js +142 -0
  33. package/dist/prompt-parser.d.ts +39 -0
  34. package/dist/prompt-parser.js +236 -0
  35. package/dist/session/index.d.ts +2 -0
  36. package/dist/session/index.js +7 -0
  37. package/dist/session/session-resume.d.ts +55 -0
  38. package/dist/session/session-resume.js +151 -0
  39. package/dist/types/auth.d.ts +15 -0
  40. package/dist/types/auth.js +3 -0
  41. package/dist/types/encryption.d.ts +54 -0
  42. package/dist/types/encryption.js +3 -0
  43. package/dist/types/events.d.ts +74 -0
  44. package/dist/types/events.js +28 -0
  45. package/dist/types/index.d.ts +4 -0
  46. package/dist/types/index.js +22 -0
  47. package/dist/types/session.d.ts +59 -0
  48. package/dist/types/session.js +22 -0
  49. package/package.json +51 -0
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # @quantiya/codevibe-core
2
+
3
+ Core library for CodeVibe plugins - shared keychain, crypto, AppSync, and authentication functionality.
4
+
5
+ ## Installation
6
+
7
+ ### Development (Private GitHub repo)
8
+
9
+ ```bash
10
+ npm install git+ssh://git@github.com:hendryyeh/quantiya-codevibe-core.git
11
+ ```
12
+
13
+ ### Production (npm public)
14
+
15
+ ```bash
16
+ npm install @quantiya/codevibe-core
17
+ ```
18
+
19
+ ## Features
20
+
21
+ - **Keychain Management** - Secure storage for device keys and OAuth tokens using native keychain (macOS Keychain, Linux libsecret, Windows Credential Manager)
22
+ - **Cryptographic Services** - E2E encryption using ECDH P-256 and AES-256-GCM
23
+ - **AppSync Client** - GraphQL API and WebSocket subscriptions for AWS AppSync
24
+ - **Authentication CLI** - Browser-based OAuth login/logout commands
25
+ - **Shared Types** - TypeScript interfaces for events, sessions, encryption
26
+
27
+ ## CLI Usage
28
+
29
+ ```bash
30
+ # Sign in via browser (opens Cognito Hosted UI)
31
+ codevibe login
32
+
33
+ # Sign out
34
+ codevibe logout
35
+
36
+ # Check authentication status
37
+ codevibe status
38
+
39
+ # Reset device identity (destructive - old sessions become inaccessible)
40
+ codevibe reset-device
41
+
42
+ # Use specific environment
43
+ codevibe --env development login
44
+ ```
45
+
46
+ ## API Usage
47
+
48
+ ### Keychain Manager
49
+
50
+ ```typescript
51
+ import { keychainManager, DeviceIdentity } from '@quantiya/codevibe-core';
52
+
53
+ // Get or create device identity (stored in native keychain)
54
+ const identity = await keychainManager.getOrCreateDeviceIdentity();
55
+ console.log(identity.deviceId, identity.publicKey);
56
+
57
+ // Get OAuth tokens
58
+ const tokens = await keychainManager.getTokens('production');
59
+ if (tokens) {
60
+ console.log(tokens.email, tokens.userId);
61
+ }
62
+ ```
63
+
64
+ ### Crypto Service
65
+
66
+ ```typescript
67
+ import { cryptoService } from '@quantiya/codevibe-core';
68
+
69
+ // Generate key pair
70
+ const keyPair = cryptoService.generateKeyPair();
71
+
72
+ // Generate session key
73
+ const sessionKey = cryptoService.generateSessionKey();
74
+
75
+ // Encrypt content
76
+ const encrypted = cryptoService.encryptContent('Hello World', sessionKey);
77
+
78
+ // Decrypt content
79
+ const decrypted = cryptoService.decryptContent(encrypted, sessionKey);
80
+ ```
81
+
82
+ ### AppSync Client
83
+
84
+ ```typescript
85
+ import { AppSyncClient, loadConfig } from '@quantiya/codevibe-core';
86
+
87
+ // Load environment configuration
88
+ loadConfig('production');
89
+
90
+ // Create client
91
+ const client = new AppSyncClient('production');
92
+
93
+ // Authenticate with stored tokens
94
+ const authenticated = await client.authenticateWithStoredTokens();
95
+ if (!authenticated) {
96
+ console.log('Run "codevibe login" first');
97
+ process.exit(1);
98
+ }
99
+
100
+ // Create session
101
+ const session = await client.createSession({
102
+ userId: client.getCurrentUserId(),
103
+ agentType: 'CLAUDE',
104
+ projectPath: '/path/to/project',
105
+ });
106
+
107
+ // Subscribe to events
108
+ const unsubscribe = client.subscribeToEvents(session.sessionId, (event) => {
109
+ console.log('Event received:', event);
110
+ });
111
+
112
+ // Clean up
113
+ unsubscribe();
114
+ ```
115
+
116
+ ### Auth Service
117
+
118
+ ```typescript
119
+ import { authService, loadConfig } from '@quantiya/codevibe-core';
120
+
121
+ // Set environment
122
+ loadConfig('production');
123
+ authService.setEnvironment('production');
124
+
125
+ // Login (opens browser)
126
+ const tokens = await authService.login();
127
+
128
+ // Check status
129
+ const status = await authService.getStatus();
130
+ console.log(status.authenticated, status.tokens?.email);
131
+
132
+ // Logout
133
+ await authService.logout();
134
+ ```
135
+
136
+ ## Keychain Storage
137
+
138
+ All sensitive data is stored in the native system keychain:
139
+
140
+ - **Service Name:** `ai.quantiya.app.codevibe`
141
+ - **Device Identity:** Stored as `device-identity` account
142
+ - **Tokens:** Stored as `tokens-{environment}` accounts (e.g., `tokens-production`)
143
+
144
+ This ensures:
145
+ - Data persists across terminal sessions
146
+ - Data is encrypted at rest by the OS
147
+ - Data survives plugin reinstalls/updates
148
+ - Device identity is shared across all CodeVibe plugins
149
+
150
+ ## Security
151
+
152
+ - Device keys are ECDH P-256 key pairs
153
+ - Session keys are 256-bit AES keys
154
+ - Content is encrypted with AES-256-GCM
155
+ - Session keys are encrypted per-device using ECDH
156
+ - OAuth tokens are stored securely in native keychain
157
+
158
+ ## Development
159
+
160
+ ```bash
161
+ # Install dependencies
162
+ npm install
163
+
164
+ # Build
165
+ npm run build
166
+
167
+ # Watch mode
168
+ npm run watch
169
+
170
+ # Local development with plugin
171
+ npm link
172
+ cd ../codevibe-claude-plugin
173
+ npm link @quantiya/codevibe-core
174
+ ```
175
+
176
+ ## License
177
+
178
+ MIT
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ //
3
+ // codevibe CLI entry point
4
+ // @quantiya/codevibe-core
5
+ //
6
+
7
+ require('../dist/auth/auth-cli').runAuthCli(process.argv);
@@ -0,0 +1,132 @@
1
+ import { CreateEventInput, CreateSessionInput, UpdateSessionInput, UpdateEventStatusInput, Event, Session, EventSource, DeviceKey } from '../types';
2
+ /**
3
+ * Download URL response
4
+ */
5
+ export interface DownloadUrlResponse {
6
+ downloadUrl: string;
7
+ expiresAt: string;
8
+ }
9
+ /**
10
+ * AppSync GraphQL client with WebSocket subscriptions
11
+ */
12
+ export declare class AppSyncClient {
13
+ private authenticated;
14
+ private currentUserId;
15
+ private currentEmail;
16
+ private tokens;
17
+ private activeSubscriptions;
18
+ private environment;
19
+ constructor();
20
+ /**
21
+ * Get the current authenticated user ID
22
+ */
23
+ getCurrentUserId(): string;
24
+ /**
25
+ * Get the current authenticated user email
26
+ */
27
+ getCurrentUserEmail(): string | null;
28
+ /**
29
+ * Authenticate using stored OAuth tokens from keychain
30
+ */
31
+ authenticateWithStoredTokens(): Promise<boolean>;
32
+ /**
33
+ * Refresh expired tokens
34
+ */
35
+ private refreshTokens;
36
+ /**
37
+ * Check if authenticated
38
+ */
39
+ isAuthenticated(): boolean;
40
+ /**
41
+ * Sign out
42
+ */
43
+ signOut(): void;
44
+ /**
45
+ * Make a GraphQL request
46
+ */
47
+ private graphqlRequest;
48
+ /**
49
+ * Create a session
50
+ */
51
+ createSession(input: CreateSessionInput): Promise<Session>;
52
+ /**
53
+ * Update a session
54
+ */
55
+ updateSession(input: UpdateSessionInput): Promise<Session>;
56
+ /**
57
+ * Get a session
58
+ */
59
+ getSession(sessionId: string): Promise<Session | null>;
60
+ /**
61
+ * Create an event
62
+ */
63
+ createEvent(input: CreateEventInput): Promise<Event>;
64
+ /**
65
+ * Update event status
66
+ */
67
+ updateEventStatus(input: UpdateEventStatusInput): Promise<Event>;
68
+ /**
69
+ * List events for a session
70
+ */
71
+ listEvents(sessionId: string, source?: EventSource, limit?: number): Promise<Event[]>;
72
+ /**
73
+ * List user device keys
74
+ */
75
+ listUserDeviceKeys(): Promise<DeviceKey[]>;
76
+ /**
77
+ * Register device key
78
+ */
79
+ registerDeviceKey(deviceId: string, publicKey: string, platform: string, deviceName: string): Promise<void>;
80
+ /**
81
+ * Get attachment download URL
82
+ */
83
+ getAttachmentDownloadUrl(s3Key: string): Promise<DownloadUrlResponse>;
84
+ /**
85
+ * Subscribe to events for a session
86
+ */
87
+ subscribeToEvents(sessionId: string, onEvent: (event: Event) => void, onError?: (error: Error) => void): () => void;
88
+ /**
89
+ * Build WebSocket URL
90
+ */
91
+ private buildRealtimeUrl;
92
+ /**
93
+ * Create WebSocket subscription
94
+ */
95
+ private createSubscription;
96
+ /**
97
+ * Send subscription start message
98
+ */
99
+ private sendSubscriptionStart;
100
+ /**
101
+ * Reset keep-alive timer
102
+ */
103
+ private resetKeepAliveTimer;
104
+ /**
105
+ * Handle subscription error with two-phase reconnection:
106
+ * Phase 1 (urgent): Exponential backoff for first N attempts
107
+ * Phase 2 (persistent): Fixed interval retry indefinitely
108
+ */
109
+ private handleSubscriptionError;
110
+ /**
111
+ * Cleanup subscription state
112
+ */
113
+ private cleanupSubscriptionState;
114
+ private heartbeatTimers;
115
+ /**
116
+ * Start periodic heartbeat for a session.
117
+ * Updates lastHeartbeatAt on the session every intervalMs (default 2 minutes).
118
+ */
119
+ startHeartbeat(sessionId: string, intervalMs?: number): void;
120
+ /**
121
+ * Stop heartbeat for a session.
122
+ */
123
+ stopHeartbeat(sessionId: string): void;
124
+ /**
125
+ * Send a single heartbeat update.
126
+ */
127
+ private sendHeartbeat;
128
+ /**
129
+ * Cleanup all subscriptions and heartbeats
130
+ */
131
+ cleanupSubscriptions(): void;
132
+ }