@quantiya/codevibe-claude-plugin 1.0.11 → 1.0.12
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.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/server.js +16 -1162
- package/node_modules/@quantiya/codevibe-core/README.md +15 -6
- package/node_modules/@quantiya/codevibe-core/bin/codevibe.js +1 -1
- package/node_modules/@quantiya/codevibe-core/dist/index.js +216 -67
- package/node_modules/@quantiya/codevibe-core/package.json +12 -9
- package/node_modules/node-abi/abi_registry.json +7 -0
- package/node_modules/node-abi/package.json +1 -1
- package/package.json +6 -13
- package/dist/appsync-client.js +0 -858
- package/dist/auth-cli.js +0 -472
- package/dist/command-executor.js +0 -127
- package/dist/config.js +0 -106
- package/dist/crypto-service.js +0 -278
- package/dist/http-api.js +0 -334
- package/dist/key-manager.js +0 -287
- package/dist/logger.js +0 -18
- package/dist/prompt-responder.js +0 -132
- package/dist/token-storage.js +0 -169
- package/dist/types.js +0 -17
- package/node_modules/@quantiya/codevibe-core/dist/appsync/appsync-client.js +0 -576
- package/node_modules/@quantiya/codevibe-core/dist/appsync/index.js +0 -10
- package/node_modules/@quantiya/codevibe-core/dist/appsync/queries.js +0 -189
- package/node_modules/@quantiya/codevibe-core/dist/auth/auth-cli.js +0 -217
- package/node_modules/@quantiya/codevibe-core/dist/auth/auth-service.js +0 -464
- package/node_modules/@quantiya/codevibe-core/dist/auth/fetch-helpers.js +0 -165
- package/node_modules/@quantiya/codevibe-core/dist/auth/index.js +0 -9
- package/node_modules/@quantiya/codevibe-core/dist/config/config.js +0 -123
- package/node_modules/@quantiya/codevibe-core/dist/config/index.js +0 -8
- package/node_modules/@quantiya/codevibe-core/dist/crypto/crypto-service.js +0 -284
- package/node_modules/@quantiya/codevibe-core/dist/crypto/index.js +0 -9
- package/node_modules/@quantiya/codevibe-core/dist/keychain/index.js +0 -8
- package/node_modules/@quantiya/codevibe-core/dist/keychain/keychain-manager.js +0 -375
- package/node_modules/@quantiya/codevibe-core/dist/logger/index.js +0 -8
- package/node_modules/@quantiya/codevibe-core/dist/logger/logger.js +0 -142
- package/node_modules/@quantiya/codevibe-core/dist/prompt-parser.js +0 -236
- package/node_modules/@quantiya/codevibe-core/dist/session/index.js +0 -7
- package/node_modules/@quantiya/codevibe-core/dist/session/session-resume.js +0 -151
- package/node_modules/@quantiya/codevibe-core/dist/types/auth.js +0 -3
- package/node_modules/@quantiya/codevibe-core/dist/types/encryption.js +0 -3
- package/node_modules/@quantiya/codevibe-core/dist/types/events.js +0 -28
- package/node_modules/@quantiya/codevibe-core/dist/types/index.js +0 -22
- package/node_modules/@quantiya/codevibe-core/dist/types/session.js +0 -22
package/dist/http-api.js
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.HttpApi = void 0;
|
|
40
|
-
const express_1 = __importDefault(require("express"));
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const path = __importStar(require("path"));
|
|
43
|
-
const os = __importStar(require("os"));
|
|
44
|
-
const codevibe_core_1 = require("@quantiya/codevibe-core");
|
|
45
|
-
const logger_1 = require("./logger");
|
|
46
|
-
const types_1 = require("./types");
|
|
47
|
-
class HttpApi {
|
|
48
|
-
constructor() {
|
|
49
|
-
this.assignedPort = 0;
|
|
50
|
-
this.app = (0, express_1.default)();
|
|
51
|
-
this.setupMiddleware();
|
|
52
|
-
this.setupRoutes();
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Set the session ID for this server instance (used for port file naming)
|
|
56
|
-
*/
|
|
57
|
-
setSessionId(sessionId) {
|
|
58
|
-
this.sessionId = sessionId;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get the assigned port after server starts
|
|
62
|
-
*/
|
|
63
|
-
getPort() {
|
|
64
|
-
return this.assignedPort;
|
|
65
|
-
}
|
|
66
|
-
setupMiddleware() {
|
|
67
|
-
// Parse JSON bodies
|
|
68
|
-
this.app.use(express_1.default.json({ limit: '1mb' }));
|
|
69
|
-
// Request logging
|
|
70
|
-
this.app.use((req, res, next) => {
|
|
71
|
-
logger_1.logger.debug(`${req.method} ${req.path}`, {
|
|
72
|
-
body: req.body,
|
|
73
|
-
query: req.query,
|
|
74
|
-
});
|
|
75
|
-
next();
|
|
76
|
-
});
|
|
77
|
-
// Error handling middleware
|
|
78
|
-
this.app.use((err, req, res, next) => {
|
|
79
|
-
logger_1.logger.error('Express error:', err);
|
|
80
|
-
const response = {
|
|
81
|
-
success: false,
|
|
82
|
-
error: err.message || 'Internal server error',
|
|
83
|
-
};
|
|
84
|
-
res.status(500).json(response);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
setupRoutes() {
|
|
88
|
-
// Health check endpoint
|
|
89
|
-
this.app.get('/health', this.handleHealth.bind(this));
|
|
90
|
-
// Event endpoint for hooks
|
|
91
|
-
this.app.post('/event', this.handleEvent.bind(this));
|
|
92
|
-
// Development testing endpoint
|
|
93
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
94
|
-
this.app.post('/test/execute', this.handleTestExecute.bind(this));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
handleHealth(req, res) {
|
|
98
|
-
const response = {
|
|
99
|
-
success: true,
|
|
100
|
-
data: {
|
|
101
|
-
status: 'healthy',
|
|
102
|
-
uptime: process.uptime(),
|
|
103
|
-
version: '0.1.0',
|
|
104
|
-
timestamp: new Date().toISOString(),
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
res.json(response);
|
|
108
|
-
}
|
|
109
|
-
async handleEvent(req, res) {
|
|
110
|
-
try {
|
|
111
|
-
const hookInput = req.body;
|
|
112
|
-
// Validate required fields
|
|
113
|
-
if (!hookInput.session_id) {
|
|
114
|
-
const response = {
|
|
115
|
-
success: false,
|
|
116
|
-
error: 'Missing required field: session_id',
|
|
117
|
-
};
|
|
118
|
-
res.status(400).json(response);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (!hookInput.hook_event_name) {
|
|
122
|
-
const response = {
|
|
123
|
-
success: false,
|
|
124
|
-
error: 'Missing required field: hook_event_name',
|
|
125
|
-
};
|
|
126
|
-
res.status(400).json(response);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
// Transform hook input to event payload
|
|
130
|
-
const eventPayload = this.transformHookToEvent(hookInput);
|
|
131
|
-
logger_1.logger.info('Received event from hook', {
|
|
132
|
-
sessionId: hookInput.session_id,
|
|
133
|
-
hookEvent: hookInput.hook_event_name,
|
|
134
|
-
type: eventPayload.type,
|
|
135
|
-
});
|
|
136
|
-
// Call event handler if registered
|
|
137
|
-
if (this.eventHandler) {
|
|
138
|
-
await this.eventHandler(eventPayload);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
logger_1.logger.warn('No event handler registered');
|
|
142
|
-
}
|
|
143
|
-
const response = {
|
|
144
|
-
success: true,
|
|
145
|
-
message: 'Event processed successfully',
|
|
146
|
-
};
|
|
147
|
-
res.json(response);
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
logger_1.logger.error('Error handling event:', error);
|
|
151
|
-
const response = {
|
|
152
|
-
success: false,
|
|
153
|
-
error: error instanceof Error ? error.message : 'Unknown error',
|
|
154
|
-
};
|
|
155
|
-
res.status(500).json(response);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
async handleTestExecute(req, res) {
|
|
159
|
-
try {
|
|
160
|
-
const { sessionId, prompt } = req.body;
|
|
161
|
-
if (!sessionId || !prompt) {
|
|
162
|
-
const response = {
|
|
163
|
-
success: false,
|
|
164
|
-
error: 'Missing required fields: sessionId, prompt',
|
|
165
|
-
};
|
|
166
|
-
res.status(400).json(response);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
logger_1.logger.info('Test execute request', { sessionId, prompt });
|
|
170
|
-
const response = {
|
|
171
|
-
success: true,
|
|
172
|
-
message: 'Test execution endpoint - not implemented yet',
|
|
173
|
-
data: { sessionId, prompt },
|
|
174
|
-
};
|
|
175
|
-
res.json(response);
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
logger_1.logger.error('Error in test execute:', error);
|
|
179
|
-
const response = {
|
|
180
|
-
success: false,
|
|
181
|
-
error: error instanceof Error ? error.message : 'Unknown error',
|
|
182
|
-
};
|
|
183
|
-
res.status(500).json(response);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
transformHookToEvent(hookInput) {
|
|
187
|
-
let type;
|
|
188
|
-
let content;
|
|
189
|
-
const metadata = {
|
|
190
|
-
cwd: hookInput.cwd,
|
|
191
|
-
hook_event_name: hookInput.hook_event_name,
|
|
192
|
-
...(hookInput.metadata || {}), // Merge any metadata from hook
|
|
193
|
-
};
|
|
194
|
-
// Check if hook explicitly provides type and content (from Stop hook transcript parsing)
|
|
195
|
-
if (hookInput.type && hookInput.content !== undefined) {
|
|
196
|
-
type = hookInput.type;
|
|
197
|
-
content = hookInput.content;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
// Determine event type and content based on hook event name
|
|
201
|
-
switch (hookInput.hook_event_name) {
|
|
202
|
-
case 'SessionStart':
|
|
203
|
-
type = types_1.EventType.NOTIFICATION;
|
|
204
|
-
content = 'Session started';
|
|
205
|
-
metadata.source = hookInput.source;
|
|
206
|
-
break;
|
|
207
|
-
case 'SessionEnd':
|
|
208
|
-
type = types_1.EventType.NOTIFICATION;
|
|
209
|
-
content = `Session ended: ${hookInput.reason || 'unknown'}`;
|
|
210
|
-
metadata.reason = hookInput.reason;
|
|
211
|
-
break;
|
|
212
|
-
case 'UserPromptSubmit':
|
|
213
|
-
type = types_1.EventType.USER_PROMPT;
|
|
214
|
-
content = hookInput.prompt || '';
|
|
215
|
-
break;
|
|
216
|
-
case 'PostToolUse':
|
|
217
|
-
type = types_1.EventType.TOOL_USE;
|
|
218
|
-
content = JSON.stringify({
|
|
219
|
-
tool_name: hookInput.tool_name,
|
|
220
|
-
tool_input: hookInput.tool_input,
|
|
221
|
-
tool_response: hookInput.tool_response,
|
|
222
|
-
});
|
|
223
|
-
metadata.tool_name = hookInput.tool_name;
|
|
224
|
-
break;
|
|
225
|
-
case 'Notification':
|
|
226
|
-
type = types_1.EventType.NOTIFICATION;
|
|
227
|
-
content = hookInput.message || '';
|
|
228
|
-
metadata.notification_type = hookInput.notification_type;
|
|
229
|
-
break;
|
|
230
|
-
default:
|
|
231
|
-
type = types_1.EventType.NOTIFICATION;
|
|
232
|
-
content = `Hook event: ${hookInput.hook_event_name}`;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
session_id: hookInput.session_id,
|
|
237
|
-
hook_event_name: hookInput.hook_event_name,
|
|
238
|
-
type,
|
|
239
|
-
source: types_1.EventSource.DESKTOP, // Events from hooks are always from desktop
|
|
240
|
-
content,
|
|
241
|
-
metadata,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
// Register event handler
|
|
245
|
-
onEvent(handler) {
|
|
246
|
-
this.eventHandler = handler;
|
|
247
|
-
}
|
|
248
|
-
// Start the HTTP server with dynamic port allocation
|
|
249
|
-
async start(sessionId) {
|
|
250
|
-
// Use provided sessionId or the one set earlier
|
|
251
|
-
const sid = sessionId || this.sessionId;
|
|
252
|
-
if (sid) {
|
|
253
|
-
this.sessionId = sid;
|
|
254
|
-
}
|
|
255
|
-
return new Promise((resolve, reject) => {
|
|
256
|
-
try {
|
|
257
|
-
const config = (0, codevibe_core_1.getConfig)();
|
|
258
|
-
// Use port 0 for dynamic allocation, or configured port as fallback
|
|
259
|
-
const requestedPort = config.server.dynamicPort ? 0 : config.server.port;
|
|
260
|
-
this.server = this.app.listen(requestedPort, config.server.host, () => {
|
|
261
|
-
const address = this.server.address();
|
|
262
|
-
this.assignedPort = address.port;
|
|
263
|
-
logger_1.logger.info(`HTTP API listening on http://${config.server.host}:${this.assignedPort}`);
|
|
264
|
-
// Write port to session-specific file for hooks to discover
|
|
265
|
-
if (this.sessionId) {
|
|
266
|
-
this.writePortFile(this.sessionId, this.assignedPort);
|
|
267
|
-
}
|
|
268
|
-
resolve(this.assignedPort);
|
|
269
|
-
});
|
|
270
|
-
this.server.on('error', (error) => {
|
|
271
|
-
logger_1.logger.error('HTTP server error:', error);
|
|
272
|
-
reject(error);
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
reject(error);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Write port to a session-specific file for hooks to discover
|
|
282
|
-
*/
|
|
283
|
-
writePortFile(sessionId, port) {
|
|
284
|
-
const portFilePath = path.join(os.tmpdir(), `codevibe-claude-${sessionId}.port`);
|
|
285
|
-
try {
|
|
286
|
-
fs.writeFileSync(portFilePath, port.toString());
|
|
287
|
-
logger_1.logger.info(`Port file written: ${portFilePath} -> ${port}`);
|
|
288
|
-
}
|
|
289
|
-
catch (error) {
|
|
290
|
-
logger_1.logger.error(`Failed to write port file: ${portFilePath}`, error);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Remove the port file on shutdown
|
|
295
|
-
*/
|
|
296
|
-
removePortFile() {
|
|
297
|
-
if (this.sessionId) {
|
|
298
|
-
const portFilePath = path.join(os.tmpdir(), `codevibe-claude-${this.sessionId}.port`);
|
|
299
|
-
try {
|
|
300
|
-
if (fs.existsSync(portFilePath)) {
|
|
301
|
-
fs.unlinkSync(portFilePath);
|
|
302
|
-
logger_1.logger.info(`Port file removed: ${portFilePath}`);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
catch (error) {
|
|
306
|
-
logger_1.logger.warn(`Failed to remove port file: ${portFilePath}`, error);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
// Stop the HTTP server
|
|
311
|
-
async stop() {
|
|
312
|
-
return new Promise((resolve, reject) => {
|
|
313
|
-
// Remove port file first
|
|
314
|
-
this.removePortFile();
|
|
315
|
-
if (this.server) {
|
|
316
|
-
this.server.close((err) => {
|
|
317
|
-
if (err) {
|
|
318
|
-
logger_1.logger.error('Error stopping HTTP server:', err);
|
|
319
|
-
reject(err);
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
logger_1.logger.info('HTTP API stopped');
|
|
323
|
-
resolve();
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
resolve();
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
exports.HttpApi = HttpApi;
|
|
334
|
-
//# sourceMappingURL=http-api.js.map
|
package/dist/key-manager.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// key-manager.ts
|
|
4
|
-
// CodeVibe Claude Plugin
|
|
5
|
-
//
|
|
6
|
-
// Manages device encryption keys and session keys for E2E encryption
|
|
7
|
-
//
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.keyManager = exports.KeyManager = exports.KeyManagerError = void 0;
|
|
43
|
-
const fs = __importStar(require("fs"));
|
|
44
|
-
const path = __importStar(require("path"));
|
|
45
|
-
const os = __importStar(require("os"));
|
|
46
|
-
const uuid_1 = require("uuid");
|
|
47
|
-
const crypto_service_1 = require("./crypto-service");
|
|
48
|
-
const logger_1 = require("./logger");
|
|
49
|
-
// Errors that can occur during key management
|
|
50
|
-
class KeyManagerError extends Error {
|
|
51
|
-
constructor(message) {
|
|
52
|
-
super(message);
|
|
53
|
-
this.name = 'KeyManagerError';
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.KeyManagerError = KeyManagerError;
|
|
57
|
-
// Storage directory for keys
|
|
58
|
-
const CONFIG_DIR = path.join(os.homedir(), '.codevibe-claude');
|
|
59
|
-
const DEVICE_KEY_FILE = 'device-key.json';
|
|
60
|
-
/**
|
|
61
|
-
* Manages device and session encryption keys
|
|
62
|
-
*/
|
|
63
|
-
class KeyManager {
|
|
64
|
-
constructor() {
|
|
65
|
-
this.deviceKey = null;
|
|
66
|
-
this.sessionKeyCache = new Map(); // sessionId -> base64 session key
|
|
67
|
-
this.isRegistered = false;
|
|
68
|
-
this.ensureConfigDir();
|
|
69
|
-
this.loadDeviceKey();
|
|
70
|
-
}
|
|
71
|
-
static getInstance() {
|
|
72
|
-
if (!KeyManager.instance) {
|
|
73
|
-
KeyManager.instance = new KeyManager();
|
|
74
|
-
}
|
|
75
|
-
return KeyManager.instance;
|
|
76
|
-
}
|
|
77
|
-
// MARK: - Device Key Management
|
|
78
|
-
/**
|
|
79
|
-
* Get or generate the device ID
|
|
80
|
-
*/
|
|
81
|
-
getDeviceId() {
|
|
82
|
-
if (this.deviceKey) {
|
|
83
|
-
return this.deviceKey.deviceId;
|
|
84
|
-
}
|
|
85
|
-
// Generate and store new device key if none exists
|
|
86
|
-
this.generateAndStoreDeviceKey();
|
|
87
|
-
return this.deviceKey.deviceId;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get the current device's key pair, generating if needed
|
|
91
|
-
*/
|
|
92
|
-
getOrCreateDeviceKeyPair() {
|
|
93
|
-
if (!this.deviceKey) {
|
|
94
|
-
this.generateAndStoreDeviceKey();
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
privateKey: this.deviceKey.privateKey,
|
|
98
|
-
publicKey: this.deviceKey.publicKey,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Get the device's public key (base64)
|
|
103
|
-
*/
|
|
104
|
-
getDevicePublicKey() {
|
|
105
|
-
const keyPair = this.getOrCreateDeviceKeyPair();
|
|
106
|
-
return keyPair.publicKey;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Check if we have a device key
|
|
110
|
-
*/
|
|
111
|
-
hasDeviceKey() {
|
|
112
|
-
return this.deviceKey !== null;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Check if device key is registered with backend
|
|
116
|
-
*/
|
|
117
|
-
getIsRegistered() {
|
|
118
|
-
return this.isRegistered;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Set registration status
|
|
122
|
-
*/
|
|
123
|
-
setIsRegistered(registered) {
|
|
124
|
-
this.isRegistered = registered;
|
|
125
|
-
}
|
|
126
|
-
// MARK: - Session Key Management
|
|
127
|
-
/**
|
|
128
|
-
* Get session key for a session, decrypting from encryptedKeys if needed
|
|
129
|
-
*/
|
|
130
|
-
getSessionKey(sessionId, encryptedKeys) {
|
|
131
|
-
// Check cache first
|
|
132
|
-
const cachedKey = this.sessionKeyCache.get(sessionId);
|
|
133
|
-
if (cachedKey) {
|
|
134
|
-
return cachedKey;
|
|
135
|
-
}
|
|
136
|
-
// Try to decrypt from encrypted keys
|
|
137
|
-
if (!encryptedKeys || encryptedKeys.length === 0) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const deviceId = this.getDeviceId();
|
|
141
|
-
const ourEncryptedKey = encryptedKeys.find((k) => k.deviceId === deviceId);
|
|
142
|
-
if (!ourEncryptedKey) {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
// Load our private key
|
|
146
|
-
if (!this.deviceKey) {
|
|
147
|
-
throw new KeyManagerError('Device key not found');
|
|
148
|
-
}
|
|
149
|
-
// Decrypt session key
|
|
150
|
-
const sessionKey = crypto_service_1.cryptoService.decryptSessionKey(ourEncryptedKey, this.deviceKey.privateKey);
|
|
151
|
-
// Cache for future use
|
|
152
|
-
this.sessionKeyCache.set(sessionId, sessionKey);
|
|
153
|
-
return sessionKey;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Generate and encrypt a new session key for all devices
|
|
157
|
-
*/
|
|
158
|
-
createSessionKey(devicePublicKeys) {
|
|
159
|
-
// Generate random session key
|
|
160
|
-
const sessionKey = crypto_service_1.cryptoService.generateSessionKey();
|
|
161
|
-
// Encrypt for each device
|
|
162
|
-
const encryptedKeys = devicePublicKeys.map((device) => {
|
|
163
|
-
const encrypted = crypto_service_1.cryptoService.encryptSessionKey(sessionKey, device.publicKey);
|
|
164
|
-
return {
|
|
165
|
-
deviceId: device.deviceId,
|
|
166
|
-
encryptedKey: encrypted.encryptedKey,
|
|
167
|
-
ephemeralPublicKey: encrypted.ephemeralPublicKey,
|
|
168
|
-
};
|
|
169
|
-
});
|
|
170
|
-
return { sessionKey, encryptedKeys };
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Cache a session key (after successfully decrypting or creating)
|
|
174
|
-
*/
|
|
175
|
-
cacheSessionKey(sessionId, sessionKey) {
|
|
176
|
-
this.sessionKeyCache.set(sessionId, sessionKey);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Clear cached session key (on session end)
|
|
180
|
-
*/
|
|
181
|
-
clearSessionKey(sessionId) {
|
|
182
|
-
this.sessionKeyCache.delete(sessionId);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Clear all cached session keys (on sign out)
|
|
186
|
-
*/
|
|
187
|
-
clearAllSessionKeys() {
|
|
188
|
-
this.sessionKeyCache.clear();
|
|
189
|
-
}
|
|
190
|
-
// MARK: - Key Storage
|
|
191
|
-
ensureConfigDir() {
|
|
192
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
193
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
getKeyFilePath() {
|
|
197
|
-
return path.join(CONFIG_DIR, DEVICE_KEY_FILE);
|
|
198
|
-
}
|
|
199
|
-
loadDeviceKey() {
|
|
200
|
-
const keyFilePath = this.getKeyFilePath();
|
|
201
|
-
if (!fs.existsSync(keyFilePath)) {
|
|
202
|
-
this.deviceKey = null;
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
try {
|
|
206
|
-
const data = fs.readFileSync(keyFilePath, 'utf8');
|
|
207
|
-
const stored = JSON.parse(data);
|
|
208
|
-
this.deviceKey = stored.device;
|
|
209
|
-
logger_1.logger.info(`[KeyManager] Loaded device key: ${this.deviceKey.deviceId}`);
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
logger_1.logger.error(`[KeyManager] Failed to load device key: ${error}`);
|
|
213
|
-
this.deviceKey = null;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
saveDeviceKey() {
|
|
217
|
-
if (!this.deviceKey) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const keyFilePath = this.getKeyFilePath();
|
|
221
|
-
const stored = {
|
|
222
|
-
device: this.deviceKey,
|
|
223
|
-
};
|
|
224
|
-
try {
|
|
225
|
-
fs.writeFileSync(keyFilePath, JSON.stringify(stored, null, 2), {
|
|
226
|
-
mode: 0o600, // Owner read/write only
|
|
227
|
-
});
|
|
228
|
-
logger_1.logger.info(`[KeyManager] Saved device key: ${this.deviceKey.deviceId}`);
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
logger_1.logger.error(`[KeyManager] Failed to save device key: ${error}`);
|
|
232
|
-
throw new KeyManagerError(`Failed to save device key: ${error}`);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
generateAndStoreDeviceKey() {
|
|
236
|
-
const keyPair = crypto_service_1.cryptoService.generateKeyPair();
|
|
237
|
-
const deviceId = (0, uuid_1.v4)().toUpperCase();
|
|
238
|
-
this.deviceKey = {
|
|
239
|
-
deviceId,
|
|
240
|
-
privateKey: keyPair.privateKey,
|
|
241
|
-
publicKey: keyPair.publicKey,
|
|
242
|
-
createdAt: new Date().toISOString(),
|
|
243
|
-
};
|
|
244
|
-
this.saveDeviceKey();
|
|
245
|
-
logger_1.logger.info(`[KeyManager] Generated new device key: ${deviceId}`);
|
|
246
|
-
}
|
|
247
|
-
// MARK: - Helpers
|
|
248
|
-
/**
|
|
249
|
-
* Get device name for registration
|
|
250
|
-
*/
|
|
251
|
-
getDeviceName() {
|
|
252
|
-
return os.hostname() || 'CLI Client';
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Get platform for registration
|
|
256
|
-
*/
|
|
257
|
-
getDevicePlatform() {
|
|
258
|
-
const platform = os.platform();
|
|
259
|
-
if (platform === 'darwin') {
|
|
260
|
-
return 'MACOS';
|
|
261
|
-
}
|
|
262
|
-
else if (platform === 'linux') {
|
|
263
|
-
return 'LINUX';
|
|
264
|
-
}
|
|
265
|
-
else if (platform === 'win32') {
|
|
266
|
-
return 'WINDOWS';
|
|
267
|
-
}
|
|
268
|
-
return 'CLI';
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Clear all encryption data (on sign out)
|
|
272
|
-
*/
|
|
273
|
-
clearAllData() {
|
|
274
|
-
const keyFilePath = this.getKeyFilePath();
|
|
275
|
-
if (fs.existsSync(keyFilePath)) {
|
|
276
|
-
fs.unlinkSync(keyFilePath);
|
|
277
|
-
}
|
|
278
|
-
this.deviceKey = null;
|
|
279
|
-
this.sessionKeyCache.clear();
|
|
280
|
-
this.isRegistered = false;
|
|
281
|
-
logger_1.logger.info('[KeyManager] Cleared all encryption data');
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
exports.KeyManager = KeyManager;
|
|
285
|
-
// Export singleton instance
|
|
286
|
-
exports.keyManager = KeyManager.getInstance();
|
|
287
|
-
//# sourceMappingURL=key-manager.js.map
|
package/dist/logger.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logger = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Plugin-specific logger for CodeVibe Claude Plugin
|
|
9
|
-
*/
|
|
10
|
-
const os_1 = __importDefault(require("os"));
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const codevibe_core_1 = require("@quantiya/codevibe-core");
|
|
13
|
-
exports.logger = (0, codevibe_core_1.createLogger)({
|
|
14
|
-
name: 'codevibe-claude',
|
|
15
|
-
logFile: path_1.default.join(os_1.default.tmpdir(), 'codevibe-claude-mcp.log'),
|
|
16
|
-
level: 'info',
|
|
17
|
-
});
|
|
18
|
-
//# sourceMappingURL=logger.js.map
|