@quantiya/codevibe-codex-plugin 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.
- package/.env.example +29 -0
- package/README.md +155 -0
- package/bin/codevibe-codex +187 -0
- package/dist/approval-detector.d.ts +38 -0
- package/dist/approval-detector.d.ts.map +1 -0
- package/dist/approval-detector.js +174 -0
- package/dist/approval-detector.js.map +1 -0
- package/dist/appsync-client.d.ts +69 -0
- package/dist/appsync-client.d.ts.map +1 -0
- package/dist/appsync-client.js +937 -0
- package/dist/appsync-client.js.map +1 -0
- package/dist/auth-cli.d.ts +11 -0
- package/dist/auth-cli.d.ts.map +1 -0
- package/dist/auth-cli.js +241 -0
- package/dist/auth-cli.js.map +1 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +116 -0
- package/dist/config.js.map +1 -0
- package/dist/crypto-service.d.ts +115 -0
- package/dist/crypto-service.d.ts.map +1 -0
- package/dist/crypto-service.js +278 -0
- package/dist/crypto-service.js.map +1 -0
- package/dist/event-mapper.d.ts +24 -0
- package/dist/event-mapper.d.ts.map +1 -0
- package/dist/event-mapper.js +268 -0
- package/dist/event-mapper.js.map +1 -0
- package/dist/key-manager.d.ts +87 -0
- package/dist/key-manager.d.ts.map +1 -0
- package/dist/key-manager.js +287 -0
- package/dist/key-manager.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +18 -0
- package/dist/logger.js.map +1 -0
- package/dist/prompt-parser.d.ts +3 -0
- package/dist/prompt-parser.d.ts.map +1 -0
- package/dist/prompt-parser.js +8 -0
- package/dist/prompt-parser.js.map +1 -0
- package/dist/prompt-responder.d.ts +18 -0
- package/dist/prompt-responder.d.ts.map +1 -0
- package/dist/prompt-responder.js +78 -0
- package/dist/prompt-responder.js.map +1 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1045 -0
- package/dist/server.js.map +1 -0
- package/dist/session-id-cache.d.ts +16 -0
- package/dist/session-id-cache.d.ts.map +1 -0
- package/dist/session-id-cache.js +90 -0
- package/dist/session-id-cache.js.map +1 -0
- package/dist/session-log-watcher.d.ts +61 -0
- package/dist/session-log-watcher.d.ts.map +1 -0
- package/dist/session-log-watcher.js +372 -0
- package/dist/session-log-watcher.js.map +1 -0
- package/dist/tmux-pane-observer.d.ts +39 -0
- package/dist/tmux-pane-observer.d.ts.map +1 -0
- package/dist/tmux-pane-observer.js +255 -0
- package/dist/tmux-pane-observer.js.map +1 -0
- package/dist/token-storage.d.ts +39 -0
- package/dist/token-storage.d.ts.map +1 -0
- package/dist/token-storage.js +169 -0
- package/dist/token-storage.js.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// crypto-service.ts
|
|
4
|
+
// CodeVibe Codex Plugin
|
|
5
|
+
//
|
|
6
|
+
// End-to-end encryption service using ECDH P-256 and AES-256-GCM
|
|
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.cryptoService = exports.CryptoService = exports.ENCRYPTION_VERSION = exports.CryptoError = void 0;
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
// Errors that can occur during cryptographic operations
|
|
45
|
+
class CryptoError extends Error {
|
|
46
|
+
constructor(message) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = 'CryptoError';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.CryptoError = CryptoError;
|
|
52
|
+
// Current encryption version for future algorithm upgrades
|
|
53
|
+
exports.ENCRYPTION_VERSION = 1;
|
|
54
|
+
// HKDF info string for key derivation
|
|
55
|
+
const HKDF_INFO = 'CodeVibe E2E v1';
|
|
56
|
+
/**
|
|
57
|
+
* Service for end-to-end encryption operations
|
|
58
|
+
*/
|
|
59
|
+
class CryptoService {
|
|
60
|
+
constructor() { }
|
|
61
|
+
static getInstance() {
|
|
62
|
+
if (!CryptoService.instance) {
|
|
63
|
+
CryptoService.instance = new CryptoService();
|
|
64
|
+
}
|
|
65
|
+
return CryptoService.instance;
|
|
66
|
+
}
|
|
67
|
+
// MARK: - Key Generation
|
|
68
|
+
/**
|
|
69
|
+
* Generate a new ECDH P-256 key pair
|
|
70
|
+
* @returns Object with privateKey (PEM), publicKey (base64 raw)
|
|
71
|
+
*/
|
|
72
|
+
generateKeyPair() {
|
|
73
|
+
const ecdh = crypto.createECDH('prime256v1');
|
|
74
|
+
ecdh.generateKeys();
|
|
75
|
+
// Get raw public key (uncompressed format without 0x04 prefix for compatibility)
|
|
76
|
+
const publicKeyRaw = ecdh.getPublicKey();
|
|
77
|
+
const publicKeyBase64 = publicKeyRaw.subarray(1).toString('base64'); // Skip 0x04 prefix
|
|
78
|
+
// Get private key as raw bytes
|
|
79
|
+
const privateKeyRaw = ecdh.getPrivateKey();
|
|
80
|
+
const privateKeyBase64 = privateKeyRaw.toString('base64');
|
|
81
|
+
return {
|
|
82
|
+
privateKey: privateKeyBase64,
|
|
83
|
+
publicKey: publicKeyBase64,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Generate a random 256-bit session key
|
|
88
|
+
* @returns Base64-encoded session key
|
|
89
|
+
*/
|
|
90
|
+
generateSessionKey() {
|
|
91
|
+
const keyData = crypto.randomBytes(32); // 256 bits
|
|
92
|
+
return keyData.toString('base64');
|
|
93
|
+
}
|
|
94
|
+
// MARK: - Key Derivation
|
|
95
|
+
/**
|
|
96
|
+
* Derive a shared secret using ECDH and HKDF
|
|
97
|
+
* @param privateKeyBase64 Our private key (base64)
|
|
98
|
+
* @param publicKeyBase64 Other party's public key (base64)
|
|
99
|
+
* @returns 256-bit derived key as Buffer
|
|
100
|
+
*/
|
|
101
|
+
deriveSharedKey(privateKeyBase64, publicKeyBase64) {
|
|
102
|
+
try {
|
|
103
|
+
const ecdh = crypto.createECDH('prime256v1');
|
|
104
|
+
const privateKeyRaw = Buffer.from(privateKeyBase64, 'base64');
|
|
105
|
+
ecdh.setPrivateKey(privateKeyRaw);
|
|
106
|
+
// Add 0x04 prefix for uncompressed public key format
|
|
107
|
+
const publicKeyRaw = Buffer.concat([
|
|
108
|
+
Buffer.from([0x04]),
|
|
109
|
+
Buffer.from(publicKeyBase64, 'base64'),
|
|
110
|
+
]);
|
|
111
|
+
const sharedSecret = ecdh.computeSecret(publicKeyRaw);
|
|
112
|
+
// Derive key using HKDF-SHA256
|
|
113
|
+
const derivedKey = crypto.hkdfSync('sha256', sharedSecret, Buffer.alloc(0), // Empty salt
|
|
114
|
+
Buffer.from(HKDF_INFO, 'utf8'), 32 // 256 bits
|
|
115
|
+
);
|
|
116
|
+
return Buffer.from(derivedKey);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new CryptoError(`Failed to derive shared key: ${error}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// MARK: - Session Key Encryption
|
|
123
|
+
/**
|
|
124
|
+
* Encrypt a session key for a target device using ECDH
|
|
125
|
+
* @param sessionKeyBase64 The session key to encrypt (base64)
|
|
126
|
+
* @param targetPublicKeyBase64 Target device's public key (base64)
|
|
127
|
+
* @returns EncryptedSessionKey containing encrypted key and ephemeral public key
|
|
128
|
+
*/
|
|
129
|
+
encryptSessionKey(sessionKeyBase64, targetPublicKeyBase64) {
|
|
130
|
+
// Generate ephemeral key pair for this encryption
|
|
131
|
+
const ephemeralKeyPair = this.generateKeyPair();
|
|
132
|
+
// Derive shared key using ephemeral private + target public
|
|
133
|
+
const sharedKey = this.deriveSharedKey(ephemeralKeyPair.privateKey, targetPublicKeyBase64);
|
|
134
|
+
// Encrypt session key with derived key
|
|
135
|
+
const sessionKeyData = Buffer.from(sessionKeyBase64, 'base64');
|
|
136
|
+
const encryptedData = this.encrypt(sessionKeyData, sharedKey);
|
|
137
|
+
return {
|
|
138
|
+
encryptedKey: encryptedData.toString('base64'),
|
|
139
|
+
ephemeralPublicKey: ephemeralKeyPair.publicKey,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Decrypt a session key using our private key
|
|
144
|
+
* @param encryptedSessionKey The encrypted session key data
|
|
145
|
+
* @param privateKeyBase64 Our device's private key (base64)
|
|
146
|
+
* @returns Decrypted session key (base64)
|
|
147
|
+
*/
|
|
148
|
+
decryptSessionKey(encryptedSessionKey, privateKeyBase64) {
|
|
149
|
+
// Derive shared key using our private + ephemeral public
|
|
150
|
+
const sharedKey = this.deriveSharedKey(privateKeyBase64, encryptedSessionKey.ephemeralPublicKey);
|
|
151
|
+
// Decrypt session key
|
|
152
|
+
const encryptedData = Buffer.from(encryptedSessionKey.encryptedKey, 'base64');
|
|
153
|
+
const decryptedData = this.decrypt(encryptedData, sharedKey);
|
|
154
|
+
return decryptedData.toString('base64');
|
|
155
|
+
}
|
|
156
|
+
// MARK: - Content Encryption/Decryption
|
|
157
|
+
/**
|
|
158
|
+
* Encrypt content using AES-256-GCM
|
|
159
|
+
* @param content String content to encrypt
|
|
160
|
+
* @param sessionKeyBase64 Session key (base64)
|
|
161
|
+
* @returns Base64-encoded ciphertext (nonce + ciphertext + tag)
|
|
162
|
+
*/
|
|
163
|
+
encryptContent(content, sessionKeyBase64) {
|
|
164
|
+
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
165
|
+
const contentData = Buffer.from(content, 'utf8');
|
|
166
|
+
const encryptedData = this.encrypt(contentData, sessionKey);
|
|
167
|
+
return encryptedData.toString('base64');
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Decrypt content using AES-256-GCM
|
|
171
|
+
* @param encryptedContent Base64-encoded ciphertext
|
|
172
|
+
* @param sessionKeyBase64 Session key (base64)
|
|
173
|
+
* @returns Decrypted string content
|
|
174
|
+
*/
|
|
175
|
+
decryptContent(encryptedContent, sessionKeyBase64) {
|
|
176
|
+
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
177
|
+
const encryptedData = Buffer.from(encryptedContent, 'base64');
|
|
178
|
+
const decryptedData = this.decrypt(encryptedData, sessionKey);
|
|
179
|
+
return decryptedData.toString('utf8');
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Encrypt JSON-serializable metadata
|
|
183
|
+
* @param metadata Object to encrypt
|
|
184
|
+
* @param sessionKeyBase64 Session key (base64)
|
|
185
|
+
* @returns Base64-encoded encrypted JSON
|
|
186
|
+
*/
|
|
187
|
+
encryptMetadata(metadata, sessionKeyBase64) {
|
|
188
|
+
const jsonString = JSON.stringify(metadata);
|
|
189
|
+
return this.encryptContent(jsonString, sessionKeyBase64);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Decrypt encrypted metadata
|
|
193
|
+
* @param encryptedMetadata Base64-encoded encrypted JSON
|
|
194
|
+
* @param sessionKeyBase64 Session key (base64)
|
|
195
|
+
* @returns Decrypted object
|
|
196
|
+
*/
|
|
197
|
+
decryptMetadata(encryptedMetadata, sessionKeyBase64) {
|
|
198
|
+
const jsonString = this.decryptContent(encryptedMetadata, sessionKeyBase64);
|
|
199
|
+
return JSON.parse(jsonString);
|
|
200
|
+
}
|
|
201
|
+
// MARK: - Binary Data Encryption (for attachments)
|
|
202
|
+
/**
|
|
203
|
+
* Encrypt binary data using AES-256-GCM
|
|
204
|
+
* @param data Binary data to encrypt (Buffer)
|
|
205
|
+
* @param sessionKeyBase64 Session key (base64)
|
|
206
|
+
* @returns Encrypted data (Buffer containing nonce + ciphertext + tag)
|
|
207
|
+
*/
|
|
208
|
+
encryptData(data, sessionKeyBase64) {
|
|
209
|
+
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
210
|
+
return this.encrypt(data, sessionKey);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Decrypt binary data using AES-256-GCM
|
|
214
|
+
* @param encryptedData Encrypted data (Buffer containing nonce + ciphertext + tag)
|
|
215
|
+
* @param sessionKeyBase64 Session key (base64)
|
|
216
|
+
* @returns Decrypted binary data (Buffer)
|
|
217
|
+
*/
|
|
218
|
+
decryptData(encryptedData, sessionKeyBase64) {
|
|
219
|
+
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
220
|
+
return this.decrypt(encryptedData, sessionKey);
|
|
221
|
+
}
|
|
222
|
+
// MARK: - Low-level Encryption
|
|
223
|
+
/**
|
|
224
|
+
* Encrypt data using AES-256-GCM
|
|
225
|
+
* @param data Data to encrypt
|
|
226
|
+
* @param key Symmetric key (32 bytes)
|
|
227
|
+
* @returns Combined nonce + ciphertext + tag
|
|
228
|
+
*/
|
|
229
|
+
encrypt(data, key) {
|
|
230
|
+
// Generate random 12-byte nonce (IV)
|
|
231
|
+
const nonce = crypto.randomBytes(12);
|
|
232
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', key, nonce);
|
|
233
|
+
const ciphertext = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
234
|
+
const tag = cipher.getAuthTag();
|
|
235
|
+
// Combine: nonce (12 bytes) + ciphertext + tag (16 bytes)
|
|
236
|
+
return Buffer.concat([nonce, ciphertext, tag]);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Decrypt data using AES-256-GCM
|
|
240
|
+
* @param data Combined nonce + ciphertext + tag
|
|
241
|
+
* @param key Symmetric key (32 bytes)
|
|
242
|
+
* @returns Decrypted data
|
|
243
|
+
*/
|
|
244
|
+
decrypt(data, key) {
|
|
245
|
+
// Extract: nonce (12 bytes) + ciphertext + tag (16 bytes)
|
|
246
|
+
const nonce = data.subarray(0, 12);
|
|
247
|
+
const tag = data.subarray(data.length - 16);
|
|
248
|
+
const ciphertext = data.subarray(12, data.length - 16);
|
|
249
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', key, nonce);
|
|
250
|
+
decipher.setAuthTag(tag);
|
|
251
|
+
try {
|
|
252
|
+
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
253
|
+
return decrypted;
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
throw new CryptoError('Decryption failed: Invalid ciphertext or authentication tag');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// MARK: - Key Serialization
|
|
260
|
+
/**
|
|
261
|
+
* Serialize a private key for storage
|
|
262
|
+
* Note: Private key is already base64 from generateKeyPair
|
|
263
|
+
*/
|
|
264
|
+
serializePrivateKey(privateKeyBase64) {
|
|
265
|
+
return privateKeyBase64;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Deserialize a private key from storage
|
|
269
|
+
* Note: Private key is already base64
|
|
270
|
+
*/
|
|
271
|
+
deserializePrivateKey(base64) {
|
|
272
|
+
return base64;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.CryptoService = CryptoService;
|
|
276
|
+
// Export singleton instance
|
|
277
|
+
exports.cryptoService = CryptoService.getInstance();
|
|
278
|
+
//# sourceMappingURL=crypto-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-service.js","sourceRoot":"","sources":["../src/crypto-service.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,oBAAoB;AACpB,wBAAwB;AACxB,EAAE;AACF,iEAAiE;AACjE,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,+CAAiC;AAGjC,wDAAwD;AACxD,MAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AALD,kCAKC;AAED,2DAA2D;AAC9C,QAAA,kBAAkB,GAAG,CAAC,CAAC;AAEpC,sCAAsC;AACtC,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEpC;;GAEG;AACH,MAAa,aAAa;IAGxB,gBAAuB,CAAC;IAExB,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,E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O,CAAC,IAAY,EAAE,GAAW;QACvC,0DAA0D;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;QAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;QAEvD,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACpE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAEzB,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACjF,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,WAAW,CAAC,6DAA6D,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;IAED,4BAA4B;IAE5B;;;OAGG;IACH,mBAAmB,CAAC,gBAAwB;QAC1C,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,qBAAqB,CAAC,MAAc;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AApRD,sCAoRC;AAED,4BAA4B;AACf,QAAA,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CreateEventInput } from '@quantiya/codevibe-core';
|
|
2
|
+
import { CodexLogEntry } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Map a Codex log entry to a CodeVibe event
|
|
5
|
+
* Returns null if the entry should not be synced
|
|
6
|
+
*/
|
|
7
|
+
export declare function mapLogEntryToEvent(entry: CodexLogEntry, sessionId: string): CreateEventInput | null;
|
|
8
|
+
/**
|
|
9
|
+
* Clear pending calls (call on session end)
|
|
10
|
+
*/
|
|
11
|
+
export declare function clearPendingCalls(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Get count of pending calls (for approval detection)
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPendingCallsCount(): number;
|
|
16
|
+
/**
|
|
17
|
+
* Get pending call info by ID
|
|
18
|
+
*/
|
|
19
|
+
export declare function getPendingCall(callId: string): {
|
|
20
|
+
name: string;
|
|
21
|
+
input: string;
|
|
22
|
+
eventId: string;
|
|
23
|
+
} | undefined;
|
|
24
|
+
//# sourceMappingURL=event-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-mapper.d.ts","sourceRoot":"","sources":["../src/event-mapper.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAexC;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,MAAM,GAChB,gBAAgB,GAAG,IAAI,CA0LzB;AAoED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAE3G"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapLogEntryToEvent = mapLogEntryToEvent;
|
|
4
|
+
exports.clearPendingCalls = clearPendingCalls;
|
|
5
|
+
exports.getPendingCallsCount = getPendingCallsCount;
|
|
6
|
+
exports.getPendingCall = getPendingCall;
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const codevibe_core_1 = require("@quantiya/codevibe-core");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
/**
|
|
11
|
+
* Maps Codex JSONL log entries to CodeVibe events
|
|
12
|
+
*
|
|
13
|
+
* Codex log entry types:
|
|
14
|
+
* - session_meta: Session metadata (handled by watcher)
|
|
15
|
+
* - event_msg: User/agent messages, reasoning, token counts
|
|
16
|
+
* - response_item: Function calls and outputs
|
|
17
|
+
* - turn_context: Turn metadata (ignored)
|
|
18
|
+
*/
|
|
19
|
+
// Track pending function calls to match with outputs
|
|
20
|
+
const pendingCalls = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* Map a Codex log entry to a CodeVibe event
|
|
23
|
+
* Returns null if the entry should not be synced
|
|
24
|
+
*/
|
|
25
|
+
function mapLogEntryToEvent(entry, sessionId) {
|
|
26
|
+
const base = {
|
|
27
|
+
sessionId,
|
|
28
|
+
source: codevibe_core_1.EventSource.DESKTOP,
|
|
29
|
+
};
|
|
30
|
+
// Handle event_msg types
|
|
31
|
+
if (entry.type === 'event_msg' && entry.payload) {
|
|
32
|
+
const payloadType = entry.payload.type;
|
|
33
|
+
switch (payloadType) {
|
|
34
|
+
case 'user_message':
|
|
35
|
+
return {
|
|
36
|
+
...base,
|
|
37
|
+
type: codevibe_core_1.EventType.USER_PROMPT,
|
|
38
|
+
content: entry.payload.message || '',
|
|
39
|
+
metadata: {
|
|
40
|
+
images: entry.payload.images || [],
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
case 'agent_message':
|
|
44
|
+
return {
|
|
45
|
+
...base,
|
|
46
|
+
type: codevibe_core_1.EventType.ASSISTANT_RESPONSE,
|
|
47
|
+
content: entry.payload.message || '',
|
|
48
|
+
};
|
|
49
|
+
case 'agent_reasoning':
|
|
50
|
+
// Send as REASONING event type for visual indicator in iOS
|
|
51
|
+
return {
|
|
52
|
+
...base,
|
|
53
|
+
type: codevibe_core_1.EventType.REASONING,
|
|
54
|
+
content: entry.payload.text || '',
|
|
55
|
+
};
|
|
56
|
+
case 'token_count':
|
|
57
|
+
// Skip token counts - could be used for metadata updates
|
|
58
|
+
logger_1.logger.debug('Skipping token_count entry');
|
|
59
|
+
return null;
|
|
60
|
+
default:
|
|
61
|
+
logger_1.logger.debug('Unknown event_msg type', { type: payloadType });
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Handle response_item types (tool calls)
|
|
66
|
+
if (entry.type === 'response_item' && entry.payload) {
|
|
67
|
+
const itemType = entry.payload.type;
|
|
68
|
+
// Function call start (shell commands, etc.)
|
|
69
|
+
if (itemType === 'function_call') {
|
|
70
|
+
const { name, arguments: args, call_id } = entry.payload;
|
|
71
|
+
// Parse arguments
|
|
72
|
+
let parsedArgs = {};
|
|
73
|
+
try {
|
|
74
|
+
parsedArgs = JSON.parse(args || '{}');
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
parsedArgs = { raw: args };
|
|
78
|
+
}
|
|
79
|
+
// Generate event ID so we can update it later
|
|
80
|
+
const eventId = (0, uuid_1.v4)();
|
|
81
|
+
// Store for matching with output
|
|
82
|
+
pendingCalls.set(call_id, {
|
|
83
|
+
name,
|
|
84
|
+
input: args,
|
|
85
|
+
eventId,
|
|
86
|
+
});
|
|
87
|
+
// Map tool name to friendly name
|
|
88
|
+
const toolName = mapToolName(name);
|
|
89
|
+
const content = formatToolCallContent(name, parsedArgs);
|
|
90
|
+
return {
|
|
91
|
+
...base,
|
|
92
|
+
type: codevibe_core_1.EventType.TOOL_USE,
|
|
93
|
+
content,
|
|
94
|
+
metadata: {
|
|
95
|
+
toolName,
|
|
96
|
+
toolInput: parsedArgs,
|
|
97
|
+
callId: call_id,
|
|
98
|
+
status: 'running',
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// Function call output
|
|
103
|
+
if (itemType === 'function_call_output') {
|
|
104
|
+
const { call_id, output } = entry.payload;
|
|
105
|
+
const pending = pendingCalls.get(call_id);
|
|
106
|
+
pendingCalls.delete(call_id);
|
|
107
|
+
const toolName = pending?.name ? mapToolName(pending.name) : 'Tool';
|
|
108
|
+
const truncatedOutput = truncateOutput(output, 500);
|
|
109
|
+
return {
|
|
110
|
+
...base,
|
|
111
|
+
type: codevibe_core_1.EventType.TOOL_USE,
|
|
112
|
+
content: `${toolName} completed:\n${truncatedOutput}`,
|
|
113
|
+
metadata: {
|
|
114
|
+
toolName,
|
|
115
|
+
toolOutput: output,
|
|
116
|
+
callId: call_id,
|
|
117
|
+
status: 'completed',
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// Custom tool call (file edits with apply_patch)
|
|
122
|
+
if (itemType === 'custom_tool_call') {
|
|
123
|
+
const { name, call_id, input, status } = entry.payload;
|
|
124
|
+
// Store for matching with output
|
|
125
|
+
pendingCalls.set(call_id, {
|
|
126
|
+
name,
|
|
127
|
+
input,
|
|
128
|
+
eventId: (0, uuid_1.v4)(),
|
|
129
|
+
});
|
|
130
|
+
// Parse the patch to extract file info
|
|
131
|
+
const fileInfo = extractFileFromPatch(input);
|
|
132
|
+
const content = fileInfo
|
|
133
|
+
? `Editing: ${fileInfo.filePath}`
|
|
134
|
+
: `Applying patch`;
|
|
135
|
+
return {
|
|
136
|
+
...base,
|
|
137
|
+
type: codevibe_core_1.EventType.TOOL_USE,
|
|
138
|
+
content,
|
|
139
|
+
metadata: {
|
|
140
|
+
toolName: 'Edit',
|
|
141
|
+
toolInput: input,
|
|
142
|
+
callId: call_id,
|
|
143
|
+
status: status || 'running',
|
|
144
|
+
filePath: fileInfo?.filePath,
|
|
145
|
+
diff: input,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Custom tool call output
|
|
150
|
+
if (itemType === 'custom_tool_call_output') {
|
|
151
|
+
const { call_id, output } = entry.payload;
|
|
152
|
+
const pending = pendingCalls.get(call_id);
|
|
153
|
+
pendingCalls.delete(call_id);
|
|
154
|
+
// Parse output JSON
|
|
155
|
+
let parsedOutput = {};
|
|
156
|
+
try {
|
|
157
|
+
parsedOutput = JSON.parse(output || '{}');
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
parsedOutput = { raw: output };
|
|
161
|
+
}
|
|
162
|
+
const success = parsedOutput.output?.includes('Success') || !parsedOutput.error;
|
|
163
|
+
return {
|
|
164
|
+
...base,
|
|
165
|
+
type: codevibe_core_1.EventType.TOOL_USE,
|
|
166
|
+
content: success ? 'File edit applied successfully' : `Edit failed: ${parsedOutput.error || 'Unknown error'}`,
|
|
167
|
+
metadata: {
|
|
168
|
+
toolName: 'Edit',
|
|
169
|
+
toolOutput: parsedOutput,
|
|
170
|
+
callId: call_id,
|
|
171
|
+
status: 'completed',
|
|
172
|
+
success,
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
logger_1.logger.debug('Unknown response_item type', { type: itemType });
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
// Skip turn_context and other types
|
|
180
|
+
if (entry.type === 'turn_context') {
|
|
181
|
+
logger_1.logger.debug('Skipping turn_context entry');
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
logger_1.logger.debug('Unhandled log entry type', { type: entry.type });
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Map Codex tool names to friendly display names
|
|
189
|
+
*/
|
|
190
|
+
function mapToolName(name) {
|
|
191
|
+
const mapping = {
|
|
192
|
+
'shell_command': 'Bash',
|
|
193
|
+
'shell': 'Bash',
|
|
194
|
+
'apply_patch': 'Edit',
|
|
195
|
+
'write_file': 'Write',
|
|
196
|
+
'read_file': 'Read',
|
|
197
|
+
'list_files': 'Glob',
|
|
198
|
+
'search_files': 'Grep',
|
|
199
|
+
'web_search': 'WebSearch',
|
|
200
|
+
'web_fetch': 'WebFetch',
|
|
201
|
+
};
|
|
202
|
+
return mapping[name] || name;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Format tool call content for display
|
|
206
|
+
*/
|
|
207
|
+
function formatToolCallContent(name, args) {
|
|
208
|
+
switch (name) {
|
|
209
|
+
case 'shell_command':
|
|
210
|
+
case 'shell':
|
|
211
|
+
return `Running: ${args.command || 'command'}`;
|
|
212
|
+
case 'read_file':
|
|
213
|
+
return `Reading: ${args.file_path || args.path || 'file'}`;
|
|
214
|
+
case 'write_file':
|
|
215
|
+
return `Writing: ${args.file_path || args.path || 'file'}`;
|
|
216
|
+
case 'list_files':
|
|
217
|
+
return `Listing: ${args.path || '.'}`;
|
|
218
|
+
case 'search_files':
|
|
219
|
+
return `Searching for: ${args.pattern || args.query || 'pattern'}`;
|
|
220
|
+
case 'web_search':
|
|
221
|
+
return `Searching web: ${args.query || 'query'}`;
|
|
222
|
+
default:
|
|
223
|
+
return `Running ${mapToolName(name)}`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Extract file path from patch content
|
|
228
|
+
* Patch format: *** Begin Patch\n*** Update File: path\n...
|
|
229
|
+
*/
|
|
230
|
+
function extractFileFromPatch(input) {
|
|
231
|
+
if (!input)
|
|
232
|
+
return null;
|
|
233
|
+
// Match "*** Update File: path" or "*** Add File: path"
|
|
234
|
+
const match = input.match(/\*\*\* (?:Update|Add|Delete) File: (.+)/);
|
|
235
|
+
if (match) {
|
|
236
|
+
return { filePath: match[1].trim() };
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Truncate output for display
|
|
242
|
+
*/
|
|
243
|
+
function truncateOutput(output, maxLength) {
|
|
244
|
+
if (!output)
|
|
245
|
+
return '';
|
|
246
|
+
if (output.length <= maxLength)
|
|
247
|
+
return output;
|
|
248
|
+
return output.substring(0, maxLength) + '...';
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Clear pending calls (call on session end)
|
|
252
|
+
*/
|
|
253
|
+
function clearPendingCalls() {
|
|
254
|
+
pendingCalls.clear();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get count of pending calls (for approval detection)
|
|
258
|
+
*/
|
|
259
|
+
function getPendingCallsCount() {
|
|
260
|
+
return pendingCalls.size;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Get pending call info by ID
|
|
264
|
+
*/
|
|
265
|
+
function getPendingCall(callId) {
|
|
266
|
+
return pendingCalls.get(callId);
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=event-mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-mapper.js","sourceRoot":"","sources":["../src/event-mapper.ts"],"names":[],"mappings":";;AAsBA,gDA6LC;AAuED,8CAEC;AAKD,oDAEC;AAKD,wCAEC;AA1SD,+BAAoC;AACpC,2DAAmF;AACnF,qCAAkC;AAGlC;;;;;;;;GAQG;AAEH,qDAAqD;AACrD,MAAM,YAAY,GAAG,IAAI,GAAG,EAA4D,CAAC;AAEzF;;;GAGG;AACH,SAAgB,kBAAkB,CAChC,KAAoB,EACpB,SAAiB;IAEjB,MAAM,IAAI,GAAG;QACX,SAAS;QACT,MAAM,EAAE,2BAAW,CAAC,OAAO;KAC5B,CAAC;IAEF,yBAAyB;IACzB,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAChD,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAEvC,QAAQ,WAAW,EAAE,CAAC;YACpB,KAAK,cAAc;gBACjB,OAAO;oBACL,GAAG,IAAI;oBACP,IAAI,EAAE,yBAAS,CAAC,WAAW;oBAC3B,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE;oBACpC,QAAQ,E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AAE,CAAC;IACvB,IAAI,MAAM,CAAC,MAAM,IAAI,SAAS;QAAE,OAAO,MAAM,CAAC;IAC9C,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,YAAY,CAAC,KAAK,EAAE,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB;IAClC,OAAO,YAAY,CAAC,IAAI,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,OAAO,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { EncryptedSessionKey } from './types';
|
|
2
|
+
export declare class KeyManagerError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Manages device and session encryption keys
|
|
7
|
+
*/
|
|
8
|
+
export declare class KeyManager {
|
|
9
|
+
private static instance;
|
|
10
|
+
private deviceKey;
|
|
11
|
+
private sessionKeyCache;
|
|
12
|
+
private isRegistered;
|
|
13
|
+
private constructor();
|
|
14
|
+
static getInstance(): KeyManager;
|
|
15
|
+
/**
|
|
16
|
+
* Get or generate the device ID
|
|
17
|
+
*/
|
|
18
|
+
getDeviceId(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Get the current device's key pair, generating if needed
|
|
21
|
+
*/
|
|
22
|
+
getOrCreateDeviceKeyPair(): {
|
|
23
|
+
privateKey: string;
|
|
24
|
+
publicKey: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get the device's public key (base64)
|
|
28
|
+
*/
|
|
29
|
+
getDevicePublicKey(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Check if we have a device key
|
|
32
|
+
*/
|
|
33
|
+
hasDeviceKey(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if device key is registered with backend
|
|
36
|
+
*/
|
|
37
|
+
getIsRegistered(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Set registration status
|
|
40
|
+
*/
|
|
41
|
+
setIsRegistered(registered: boolean): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get session key for a session, decrypting from encryptedKeys if needed
|
|
44
|
+
*/
|
|
45
|
+
getSessionKey(sessionId: string, encryptedKeys?: EncryptedSessionKey[]): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Generate and encrypt a new session key for all devices
|
|
48
|
+
*/
|
|
49
|
+
createSessionKey(devicePublicKeys: Array<{
|
|
50
|
+
deviceId: string;
|
|
51
|
+
publicKey: string;
|
|
52
|
+
}>): {
|
|
53
|
+
sessionKey: string;
|
|
54
|
+
encryptedKeys: EncryptedSessionKey[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Cache a session key (after successfully decrypting or creating)
|
|
58
|
+
*/
|
|
59
|
+
cacheSessionKey(sessionId: string, sessionKey: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Clear cached session key (on session end)
|
|
62
|
+
*/
|
|
63
|
+
clearSessionKey(sessionId: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Clear all cached session keys (on sign out)
|
|
66
|
+
*/
|
|
67
|
+
clearAllSessionKeys(): void;
|
|
68
|
+
private ensureConfigDir;
|
|
69
|
+
private getKeyFilePath;
|
|
70
|
+
private loadDeviceKey;
|
|
71
|
+
private saveDeviceKey;
|
|
72
|
+
private generateAndStoreDeviceKey;
|
|
73
|
+
/**
|
|
74
|
+
* Get device name for registration
|
|
75
|
+
*/
|
|
76
|
+
getDeviceName(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Get platform for registration
|
|
79
|
+
*/
|
|
80
|
+
getDevicePlatform(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Clear all encryption data (on sign out)
|
|
83
|
+
*/
|
|
84
|
+
clearAllData(): void;
|
|
85
|
+
}
|
|
86
|
+
export declare const keyManager: KeyManager;
|
|
87
|
+
//# sourceMappingURL=key-manager.d.ts.map
|