@kadi.build/core 0.0.1-alpha.11 → 0.0.1-alpha.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/dist/abilities/AbilityLoader.d.ts +8 -8
- package/dist/abilities/AbilityLoader.d.ts.map +1 -1
- package/dist/abilities/AbilityLoader.js +101 -44
- package/dist/abilities/AbilityLoader.js.map +1 -1
- package/dist/utils/LockfileResolver.d.ts +108 -0
- package/dist/utils/LockfileResolver.d.ts.map +1 -0
- package/dist/utils/LockfileResolver.js +230 -0
- package/dist/utils/LockfileResolver.js.map +1 -0
- package/package.json +1 -1
|
@@ -174,29 +174,29 @@ export declare class AbilityLoader {
|
|
|
174
174
|
*/
|
|
175
175
|
private createBrokerTransport;
|
|
176
176
|
/**
|
|
177
|
-
* Create native transport with path
|
|
177
|
+
* Create native transport with path auto-resolution
|
|
178
178
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
179
|
+
* If path is provided, uses it directly (backwards compatible).
|
|
180
|
+
* If path is NOT provided, auto-resolves from agent-lock.json.
|
|
181
181
|
*
|
|
182
182
|
* @param name - Ability name
|
|
183
183
|
* @param options - Load options (native-specific)
|
|
184
184
|
* @returns Native transport instance
|
|
185
185
|
*
|
|
186
|
-
* @throws {KadiError} If path is missing
|
|
186
|
+
* @throws {KadiError} If path is missing and auto-resolution fails
|
|
187
187
|
*/
|
|
188
188
|
private createNativeTransport;
|
|
189
189
|
/**
|
|
190
|
-
* Create stdio transport with command
|
|
190
|
+
* Create stdio transport with command auto-resolution
|
|
191
191
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
192
|
+
* If command is provided, uses it directly (backwards compatible).
|
|
193
|
+
* If command is NOT provided, auto-resolves from agent-lock.json.
|
|
194
194
|
*
|
|
195
195
|
* @param name - Ability name
|
|
196
196
|
* @param options - Load options (stdio-specific)
|
|
197
197
|
* @returns Stdio transport instance
|
|
198
198
|
*
|
|
199
|
-
* @throws {KadiError} If command is missing
|
|
199
|
+
* @throws {KadiError} If command is missing and auto-resolution fails
|
|
200
200
|
*/
|
|
201
201
|
private createStdioTransport;
|
|
202
202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbilityLoader.d.ts","sourceRoot":"","sources":["../../src/abilities/AbilityLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAC;AAGlG,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGvF,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"AbilityLoader.d.ts","sourceRoot":"","sources":["../../src/abilities/AbilityLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAC;AAGlG,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGvF,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAa;IACxB;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK,CAAsB;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,aAAa,EACxB,OAAO,GAAE,WAAgB,EACzB,YAAY,CAAC,EAAE,aAAa,GAC3B,OAAO,CAAC,aAAa,CAAC;IAwCzB;;;;;;;;;OASG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBhC;;;;;;;;;;OAUG;IACH,MAAM,IAAI,aAAa,EAAE;IAIzB;;;;;;;;;;;;OAYG;IACH,QAAQ,IAAI;QACV,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;KAC5C;IAID;;;;;;;;;;;;OAYG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,eAAe;IA6BvB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,qBAAqB;IAiD7B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,qBAAqB;IA4D7B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,oBAAoB;CA8E7B"}
|
|
@@ -16,6 +16,8 @@ import { StdioTransport } from '../transports/StdioTransport.js';
|
|
|
16
16
|
import { AbilityProxy } from './AbilityProxy.js';
|
|
17
17
|
import { AbilityCache } from './AbilityCache.js';
|
|
18
18
|
import { AbilityValidator } from './AbilityValidator.js';
|
|
19
|
+
import { resolveAbilityConfig } from '../utils/LockfileResolver.js';
|
|
20
|
+
import path from 'path';
|
|
19
21
|
/**
|
|
20
22
|
* Ability Loader
|
|
21
23
|
*
|
|
@@ -260,83 +262,138 @@ export class AbilityLoader {
|
|
|
260
262
|
}, brokerClient);
|
|
261
263
|
}
|
|
262
264
|
/**
|
|
263
|
-
* Create native transport with path
|
|
265
|
+
* Create native transport with path auto-resolution
|
|
264
266
|
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
+
* If path is provided, uses it directly (backwards compatible).
|
|
268
|
+
* If path is NOT provided, auto-resolves from agent-lock.json.
|
|
267
269
|
*
|
|
268
270
|
* @param name - Ability name
|
|
269
271
|
* @param options - Load options (native-specific)
|
|
270
272
|
* @returns Native transport instance
|
|
271
273
|
*
|
|
272
|
-
* @throws {KadiError} If path is missing
|
|
274
|
+
* @throws {KadiError} If path is missing and auto-resolution fails
|
|
273
275
|
*/
|
|
274
276
|
createNativeTransport(name, options) {
|
|
275
277
|
// Step 1: Extract native-specific options (type-safe!)
|
|
276
278
|
const nativeOptions = options;
|
|
277
|
-
// Step 2:
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
279
|
+
// Step 2: Determine ability path
|
|
280
|
+
let abilityPath;
|
|
281
|
+
let abilityVersion = options.version;
|
|
282
|
+
if (nativeOptions.path) {
|
|
283
|
+
// Explicit path provided - use it (backwards compatible)
|
|
284
|
+
abilityPath = nativeOptions.path;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
// No path provided - auto-resolve from lockfile
|
|
288
|
+
try {
|
|
289
|
+
const config = resolveAbilityConfig(name);
|
|
290
|
+
abilityPath = config.path;
|
|
291
|
+
abilityVersion = config.version;
|
|
292
|
+
// Log for debugging (if needed)
|
|
293
|
+
// console.debug(`Auto-resolved ${name} to ${abilityPath}`);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
// Re-throw lockfile resolution errors with context
|
|
297
|
+
if (error instanceof KadiError) {
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
throw new KadiError(`Failed to auto-resolve ability '${name}'`, ErrorCode.ABILITY_NOT_FOUND, 404, {
|
|
301
|
+
abilityName: name,
|
|
302
|
+
transport: 'native',
|
|
303
|
+
reason: 'Could not auto-resolve path from lockfile',
|
|
304
|
+
originalError: error instanceof Error ? error.message : String(error),
|
|
305
|
+
suggestion: 'Provide explicit path or run `kadi install`',
|
|
306
|
+
example: 'await client.load("calculator", "native", { path: "./abilities/calculator" })',
|
|
307
|
+
alternatives: [
|
|
308
|
+
'Install ability: kadi install ' + name,
|
|
309
|
+
'Provide explicit path in options',
|
|
310
|
+
'Check that agent-lock.json exists'
|
|
311
|
+
]
|
|
312
|
+
});
|
|
313
|
+
}
|
|
291
314
|
}
|
|
292
|
-
// Step 3: Create NativeTransport with
|
|
315
|
+
// Step 3: Create NativeTransport with resolved/provided path
|
|
293
316
|
return new NativeTransport({
|
|
294
317
|
abilityName: name,
|
|
295
|
-
abilityPath
|
|
296
|
-
abilityVersion
|
|
318
|
+
abilityPath,
|
|
319
|
+
abilityVersion,
|
|
297
320
|
timeout: options.timeout
|
|
298
321
|
// entryPoint defaults to 'index.js' in NativeTransport constructor
|
|
299
322
|
});
|
|
300
323
|
}
|
|
301
324
|
/**
|
|
302
|
-
* Create stdio transport with command
|
|
325
|
+
* Create stdio transport with command auto-resolution
|
|
303
326
|
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
327
|
+
* If command is provided, uses it directly (backwards compatible).
|
|
328
|
+
* If command is NOT provided, auto-resolves from agent-lock.json.
|
|
306
329
|
*
|
|
307
330
|
* @param name - Ability name
|
|
308
331
|
* @param options - Load options (stdio-specific)
|
|
309
332
|
* @returns Stdio transport instance
|
|
310
333
|
*
|
|
311
|
-
* @throws {KadiError} If command is missing
|
|
334
|
+
* @throws {KadiError} If command is missing and auto-resolution fails
|
|
312
335
|
*/
|
|
313
336
|
createStdioTransport(name, options) {
|
|
314
337
|
// Step 1: Extract stdio-specific options (type-safe!)
|
|
315
338
|
const stdioOptions = options;
|
|
316
|
-
// Step 2:
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
339
|
+
// Step 2: Determine command and args
|
|
340
|
+
let command;
|
|
341
|
+
let args = stdioOptions.args;
|
|
342
|
+
let cwd = stdioOptions.cwd;
|
|
343
|
+
let abilityVersion = options.version;
|
|
344
|
+
if (stdioOptions.command) {
|
|
345
|
+
// Explicit command provided - use it (backwards compatible)
|
|
346
|
+
command = stdioOptions.command;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
// No command provided - auto-resolve from lockfile
|
|
350
|
+
try {
|
|
351
|
+
const config = resolveAbilityConfig(name);
|
|
352
|
+
// TODO: Runtime detection - currently assumes Node.js
|
|
353
|
+
// In the future, detect runtime from ability manifest:
|
|
354
|
+
// - runtime: "node" | "python" | "go" | "binary"
|
|
355
|
+
// - Or auto-detect from entry file extension (.js, .py, .go)
|
|
356
|
+
// For now, we assume Node.js for all abilities
|
|
357
|
+
command = 'node';
|
|
358
|
+
// Construct entry point path
|
|
359
|
+
const entryPath = path.join(config.path, config.entry);
|
|
360
|
+
args = [entryPath];
|
|
361
|
+
// Set working directory to ability directory
|
|
362
|
+
cwd = config.path;
|
|
363
|
+
// Use version from lockfile
|
|
364
|
+
abilityVersion = config.version;
|
|
365
|
+
// Log for debugging (if needed)
|
|
366
|
+
// console.debug(`Auto-resolved ${name} stdio command: node ${entryPath}`);
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
// Re-throw lockfile resolution errors with context
|
|
370
|
+
if (error instanceof KadiError) {
|
|
371
|
+
throw error;
|
|
372
|
+
}
|
|
373
|
+
throw new KadiError(`Failed to auto-resolve ability '${name}' for stdio`, ErrorCode.ABILITY_NOT_FOUND, 404, {
|
|
374
|
+
abilityName: name,
|
|
375
|
+
transport: 'stdio',
|
|
376
|
+
reason: 'Could not auto-resolve command from lockfile',
|
|
377
|
+
originalError: error instanceof Error ? error.message : String(error),
|
|
378
|
+
suggestion: 'Provide explicit command or run `kadi install`',
|
|
379
|
+
example: 'await client.load("calculator", "stdio", { command: "node", args: ["./service.js"] })',
|
|
380
|
+
alternatives: [
|
|
381
|
+
'Install ability: kadi install ' + name,
|
|
382
|
+
'Provide explicit command in options',
|
|
383
|
+
'Check that agent-lock.json exists'
|
|
384
|
+
]
|
|
385
|
+
});
|
|
386
|
+
}
|
|
330
387
|
}
|
|
331
|
-
// Step 3: Create StdioTransport with
|
|
388
|
+
// Step 3: Create StdioTransport with resolved/provided config
|
|
332
389
|
return new StdioTransport({
|
|
333
390
|
abilityName: name,
|
|
334
|
-
command
|
|
335
|
-
args
|
|
336
|
-
cwd
|
|
391
|
+
command,
|
|
392
|
+
args,
|
|
393
|
+
cwd,
|
|
337
394
|
env: stdioOptions.env,
|
|
338
395
|
timeout: options.timeout,
|
|
339
|
-
abilityVersion
|
|
396
|
+
abilityVersion
|
|
340
397
|
});
|
|
341
398
|
}
|
|
342
399
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbilityLoader.js","sourceRoot":"","sources":["../../src/abilities/AbilityLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAsB,MAAM,kCAAkC,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"AbilityLoader.js","sourceRoot":"","sources":["../../src/abilities/AbilityLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAsB,MAAM,kCAAkC,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MA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ACtD,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;oBACrE,UAAU,EAAE,gDAAgD;oBAC5D,OAAO,EAAE,uFAAuF;oBAChG,YAAY,EAAE;wBACZ,gCAAgC,GAAG,IAAI;wBACvC,qCAAqC;wBACrC,mCAAmC;qBACpC;iBACF,CACF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,8DAA8D;QAC9D,OAAO,IAAI,cAAc,CAAC;YACxB,WAAW,EAAE,IAAI;YACjB,OAAO;YACP,IAAI;YACJ,GAAG;YACH,GAAG,EAAE,YAAY,CAAC,GAAG;YACrB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,cAAc;SACf,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lockfile Resolver
|
|
3
|
+
*
|
|
4
|
+
* Utilities for resolving ability paths from agent-lock.json
|
|
5
|
+
* Integrates kadi-core with kadi-install's global cache architecture
|
|
6
|
+
*
|
|
7
|
+
* @module utils/LockfileResolver
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Minimal lockfile types (only what kadi-core needs)
|
|
11
|
+
*
|
|
12
|
+
* These types are a subset of the full lockfile format from kadi-install.
|
|
13
|
+
* We only include fields needed for ability path resolution.
|
|
14
|
+
*/
|
|
15
|
+
export interface LockfileAbilityEntry {
|
|
16
|
+
version: string;
|
|
17
|
+
kind: 'plugin' | 'ability';
|
|
18
|
+
resolved: string;
|
|
19
|
+
integrity: string;
|
|
20
|
+
installStrategy: 'hardlink' | 'clonefile' | 'copyfile' | 'symlink';
|
|
21
|
+
detached: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface AgentLockfile {
|
|
24
|
+
lockfileVersion: number;
|
|
25
|
+
abilities: Record<string, LockfileAbilityEntry>;
|
|
26
|
+
agent: {
|
|
27
|
+
name: string;
|
|
28
|
+
version: string;
|
|
29
|
+
};
|
|
30
|
+
generated: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Minimal ability manifest (agent.json)
|
|
34
|
+
*
|
|
35
|
+
* Only fields needed for loading abilities
|
|
36
|
+
*/
|
|
37
|
+
export interface AbilityManifest {
|
|
38
|
+
name: string;
|
|
39
|
+
version: string;
|
|
40
|
+
kind?: 'plugin' | 'ability';
|
|
41
|
+
entry?: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Find project root by looking for agent.json
|
|
47
|
+
*
|
|
48
|
+
* Walks up directory tree from cwd until finding agent.json
|
|
49
|
+
*
|
|
50
|
+
* @param startDir - Directory to start search from (defaults to cwd)
|
|
51
|
+
* @returns Absolute path to project root
|
|
52
|
+
* @throws {KadiError} If no project root found
|
|
53
|
+
*/
|
|
54
|
+
export declare function findProjectRoot(startDir?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Read agent-lock.json from project root
|
|
57
|
+
*
|
|
58
|
+
* @param projectRoot - Project root directory
|
|
59
|
+
* @returns Parsed lockfile
|
|
60
|
+
* @throws {KadiError} If lockfile not found or invalid
|
|
61
|
+
*/
|
|
62
|
+
export declare function readLockfile(projectRoot: string): AgentLockfile;
|
|
63
|
+
/**
|
|
64
|
+
* Resolve ability path from lockfile
|
|
65
|
+
*
|
|
66
|
+
* @param abilityName - Name of ability to resolve
|
|
67
|
+
* @param projectRoot - Project root directory
|
|
68
|
+
* @returns Resolved ability entry from lockfile
|
|
69
|
+
* @throws {KadiError} If ability not found in lockfile or path doesn't exist
|
|
70
|
+
*/
|
|
71
|
+
export declare function resolveAbilityPath(abilityName: string, projectRoot: string): LockfileAbilityEntry;
|
|
72
|
+
/**
|
|
73
|
+
* Read ability's agent.json manifest
|
|
74
|
+
*
|
|
75
|
+
* @param abilityPath - Path to ability directory
|
|
76
|
+
* @returns Parsed ability manifest
|
|
77
|
+
* @throws {KadiError} If manifest not found or invalid
|
|
78
|
+
*/
|
|
79
|
+
export declare function readAbilityManifest(abilityPath: string): AbilityManifest;
|
|
80
|
+
/**
|
|
81
|
+
* Auto-resolve ability configuration for loading
|
|
82
|
+
*
|
|
83
|
+
* Combines lockfile lookup with manifest reading to provide
|
|
84
|
+
* all information needed to load an ability.
|
|
85
|
+
*
|
|
86
|
+
* @param abilityName - Name of ability
|
|
87
|
+
* @param projectRoot - Project root directory (optional, will search if not provided)
|
|
88
|
+
* @returns Resolved ability configuration
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const config = resolveAbilityConfig('math-lib');
|
|
93
|
+
* // Returns:
|
|
94
|
+
* // {
|
|
95
|
+
* // path: '/path/to/project/abilities/math-lib@1.0.0',
|
|
96
|
+
* // version: '1.0.0',
|
|
97
|
+
* // entry: 'service.js',
|
|
98
|
+
* // manifest: { ... }
|
|
99
|
+
* // }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function resolveAbilityConfig(abilityName: string, projectRoot?: string): {
|
|
103
|
+
path: string;
|
|
104
|
+
version: string;
|
|
105
|
+
entry: string;
|
|
106
|
+
manifest: AbilityManifest;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=LockfileResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LockfileResolver.d.ts","sourceRoot":"","sources":["../../src/utils/LockfileResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC;IACnE,QAAQ,EAAE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
|
+
* Utilities for resolving ability paths from agent-lock.json
|
|
5
|
+
* Integrates kadi-core with kadi-install's global cache architecture
|
|
6
|
+
*
|
|
7
|
+
* @module utils/LockfileResolver
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { KadiError, ErrorCode } from '../errors/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Find project root by looking for agent.json
|
|
14
|
+
*
|
|
15
|
+
* Walks up directory tree from cwd until finding agent.json
|
|
16
|
+
*
|
|
17
|
+
* @param startDir - Directory to start search from (defaults to cwd)
|
|
18
|
+
* @returns Absolute path to project root
|
|
19
|
+
* @throws {KadiError} If no project root found
|
|
20
|
+
*/
|
|
21
|
+
export function findProjectRoot(startDir = process.cwd()) {
|
|
22
|
+
let current = path.resolve(startDir);
|
|
23
|
+
const root = path.parse(current).root;
|
|
24
|
+
while (current !== root) {
|
|
25
|
+
const agentJsonPath = path.join(current, 'agent.json');
|
|
26
|
+
if (fs.existsSync(agentJsonPath)) {
|
|
27
|
+
return current;
|
|
28
|
+
}
|
|
29
|
+
// Move up one directory
|
|
30
|
+
current = path.dirname(current);
|
|
31
|
+
}
|
|
32
|
+
throw new KadiError('No KADI project found - could not locate agent.json', ErrorCode.INVALID_CONFIG, 404, {
|
|
33
|
+
searchedFrom: startDir,
|
|
34
|
+
reason: 'No agent.json found in current directory or parent directories',
|
|
35
|
+
suggestion: 'Make sure you are running from within a KADI project',
|
|
36
|
+
alternatives: [
|
|
37
|
+
'Run from a directory containing agent.json',
|
|
38
|
+
'Initialize a new KADI project: kadi init',
|
|
39
|
+
'Provide explicit path when loading ability'
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Read agent-lock.json from project root
|
|
45
|
+
*
|
|
46
|
+
* @param projectRoot - Project root directory
|
|
47
|
+
* @returns Parsed lockfile
|
|
48
|
+
* @throws {KadiError} If lockfile not found or invalid
|
|
49
|
+
*/
|
|
50
|
+
export function readLockfile(projectRoot) {
|
|
51
|
+
const lockfilePath = path.join(projectRoot, 'agent-lock.json');
|
|
52
|
+
// Check if lockfile exists
|
|
53
|
+
if (!fs.existsSync(lockfilePath)) {
|
|
54
|
+
throw new KadiError('No agent-lock.json found - cannot auto-resolve ability paths', ErrorCode.INVALID_CONFIG, 404, {
|
|
55
|
+
projectRoot,
|
|
56
|
+
lockfilePath,
|
|
57
|
+
reason: 'agent-lock.json not found in project root',
|
|
58
|
+
suggestion: 'Run `kadi install` to generate lockfile',
|
|
59
|
+
alternatives: [
|
|
60
|
+
'Run: kadi install (to install all abilities from agent.json)',
|
|
61
|
+
'Run: kadi install <ability-name> (to install specific ability)',
|
|
62
|
+
'Provide explicit path: client.load("ability", "native", { path: "./abilities/..." })'
|
|
63
|
+
],
|
|
64
|
+
hint: 'agent-lock.json is created by running `kadi install`'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Read and parse lockfile
|
|
68
|
+
try {
|
|
69
|
+
const content = fs.readFileSync(lockfilePath, 'utf-8');
|
|
70
|
+
const lockfile = JSON.parse(content);
|
|
71
|
+
// Basic validation
|
|
72
|
+
if (!lockfile.abilities || typeof lockfile.abilities !== 'object') {
|
|
73
|
+
throw new Error('Invalid lockfile format: missing or invalid "abilities" field');
|
|
74
|
+
}
|
|
75
|
+
return lockfile;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof SyntaxError) {
|
|
79
|
+
throw new KadiError('Invalid agent-lock.json - malformed JSON', ErrorCode.INVALID_CONFIG, 400, {
|
|
80
|
+
lockfilePath,
|
|
81
|
+
parseError: error.message,
|
|
82
|
+
suggestion: 'Delete agent-lock.json and run `kadi install` to regenerate'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
throw new KadiError('Failed to read agent-lock.json', ErrorCode.INTERNAL_ERROR, 500, {
|
|
86
|
+
lockfilePath,
|
|
87
|
+
error: error instanceof Error ? error.message : String(error)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve ability path from lockfile
|
|
93
|
+
*
|
|
94
|
+
* @param abilityName - Name of ability to resolve
|
|
95
|
+
* @param projectRoot - Project root directory
|
|
96
|
+
* @returns Resolved ability entry from lockfile
|
|
97
|
+
* @throws {KadiError} If ability not found in lockfile or path doesn't exist
|
|
98
|
+
*/
|
|
99
|
+
export function resolveAbilityPath(abilityName, projectRoot) {
|
|
100
|
+
const lockfile = readLockfile(projectRoot);
|
|
101
|
+
// Check if ability exists in lockfile
|
|
102
|
+
const abilityEntry = lockfile.abilities[abilityName];
|
|
103
|
+
if (!abilityEntry) {
|
|
104
|
+
// Ability not in lockfile - show helpful error
|
|
105
|
+
const installedAbilities = Object.keys(lockfile.abilities);
|
|
106
|
+
throw new KadiError(`Ability '${abilityName}' not found in agent-lock.json`, ErrorCode.ABILITY_NOT_FOUND, 404, {
|
|
107
|
+
abilityName,
|
|
108
|
+
projectRoot,
|
|
109
|
+
installedAbilities,
|
|
110
|
+
installedCount: installedAbilities.length,
|
|
111
|
+
reason: `'${abilityName}' is not installed in this project`,
|
|
112
|
+
suggestion: `Run: kadi install ${abilityName}`,
|
|
113
|
+
alternatives: [
|
|
114
|
+
`Install ability: kadi install ${abilityName}`,
|
|
115
|
+
'View installed abilities in agent-lock.json',
|
|
116
|
+
'Provide explicit path when loading ability'
|
|
117
|
+
],
|
|
118
|
+
hint: installedAbilities.length === 0
|
|
119
|
+
? 'No abilities installed yet. Run `kadi install` to install from agent.json'
|
|
120
|
+
: `Currently installed: ${installedAbilities.slice(0, 5).join(', ')}${installedAbilities.length > 5 ? '...' : ''}`
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// Resolve path (may be relative to project root)
|
|
124
|
+
const absolutePath = path.isAbsolute(abilityEntry.resolved)
|
|
125
|
+
? abilityEntry.resolved
|
|
126
|
+
: path.resolve(projectRoot, abilityEntry.resolved);
|
|
127
|
+
// Verify the resolved path exists
|
|
128
|
+
if (!fs.existsSync(absolutePath)) {
|
|
129
|
+
throw new KadiError(`Ability '${abilityName}@${abilityEntry.version}' is in lockfile but directory not found`, ErrorCode.ABILITY_NOT_FOUND, 404, {
|
|
130
|
+
abilityName,
|
|
131
|
+
version: abilityEntry.version,
|
|
132
|
+
expectedPath: absolutePath,
|
|
133
|
+
reason: 'Directory listed in lockfile does not exist',
|
|
134
|
+
possibleCauses: [
|
|
135
|
+
'Ability was manually deleted',
|
|
136
|
+
'Project was moved without abilities/ folder',
|
|
137
|
+
'File system error or permissions issue'
|
|
138
|
+
],
|
|
139
|
+
suggestion: `Run: kadi install --force ${abilityName}`,
|
|
140
|
+
alternatives: [
|
|
141
|
+
`Reinstall ability: kadi install --force ${abilityName}`,
|
|
142
|
+
'Check if abilities/ folder exists',
|
|
143
|
+
'Run `kadi install` to restore all abilities'
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// Return entry with absolute path
|
|
148
|
+
return {
|
|
149
|
+
...abilityEntry,
|
|
150
|
+
resolved: absolutePath
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Read ability's agent.json manifest
|
|
155
|
+
*
|
|
156
|
+
* @param abilityPath - Path to ability directory
|
|
157
|
+
* @returns Parsed ability manifest
|
|
158
|
+
* @throws {KadiError} If manifest not found or invalid
|
|
159
|
+
*/
|
|
160
|
+
export function readAbilityManifest(abilityPath) {
|
|
161
|
+
const manifestPath = path.join(abilityPath, 'agent.json');
|
|
162
|
+
if (!fs.existsSync(manifestPath)) {
|
|
163
|
+
throw new KadiError('Ability agent.json not found', ErrorCode.INVALID_CONFIG, 404, {
|
|
164
|
+
abilityPath,
|
|
165
|
+
manifestPath,
|
|
166
|
+
reason: 'agent.json not found in ability directory',
|
|
167
|
+
suggestion: 'Reinstall the ability: kadi install --force <ability-name>'
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const content = fs.readFileSync(manifestPath, 'utf-8');
|
|
172
|
+
const manifest = JSON.parse(content);
|
|
173
|
+
// Basic validation
|
|
174
|
+
if (!manifest.name || !manifest.version) {
|
|
175
|
+
throw new Error('Invalid manifest: missing name or version');
|
|
176
|
+
}
|
|
177
|
+
return manifest;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error instanceof SyntaxError) {
|
|
181
|
+
throw new KadiError('Invalid ability agent.json - malformed JSON', ErrorCode.INVALID_CONFIG, 400, {
|
|
182
|
+
manifestPath,
|
|
183
|
+
parseError: error.message
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
throw new KadiError('Failed to read ability agent.json', ErrorCode.INTERNAL_ERROR, 500, {
|
|
187
|
+
manifestPath,
|
|
188
|
+
error: error instanceof Error ? error.message : String(error)
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Auto-resolve ability configuration for loading
|
|
194
|
+
*
|
|
195
|
+
* Combines lockfile lookup with manifest reading to provide
|
|
196
|
+
* all information needed to load an ability.
|
|
197
|
+
*
|
|
198
|
+
* @param abilityName - Name of ability
|
|
199
|
+
* @param projectRoot - Project root directory (optional, will search if not provided)
|
|
200
|
+
* @returns Resolved ability configuration
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const config = resolveAbilityConfig('math-lib');
|
|
205
|
+
* // Returns:
|
|
206
|
+
* // {
|
|
207
|
+
* // path: '/path/to/project/abilities/math-lib@1.0.0',
|
|
208
|
+
* // version: '1.0.0',
|
|
209
|
+
* // entry: 'service.js',
|
|
210
|
+
* // manifest: { ... }
|
|
211
|
+
* // }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export function resolveAbilityConfig(abilityName, projectRoot) {
|
|
215
|
+
// Find project root if not provided
|
|
216
|
+
const root = projectRoot || findProjectRoot();
|
|
217
|
+
// Resolve ability from lockfile
|
|
218
|
+
const entry = resolveAbilityPath(abilityName, root);
|
|
219
|
+
// Read ability manifest
|
|
220
|
+
const manifest = readAbilityManifest(entry.resolved);
|
|
221
|
+
// Get entry point (default to 'index.js' if not specified)
|
|
222
|
+
const entryPoint = manifest.entry || 'index.js';
|
|
223
|
+
return {
|
|
224
|
+
path: entry.resolved,
|
|
225
|
+
version: entry.version,
|
|
226
|
+
entry: entryPoint,
|
|
227
|
+
manifest
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=LockfileResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LockfileResolver.js","sourceRoot":"","sources":["../../src/utils/LockfileResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAyC1D;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB,OAAO,CAAC,GAAG,EAAE;IAC9D,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;IAEtC,OAAO,OAAO,KAAK,IAAI,EAAE,CAAC;QACxB,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAEvD,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YACjC,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,wBAAwB;QACxB,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,IAAI,SAAS,CACjB,qDAAqD,EACrD,SAAS,CAAC,cAAc,EACxB,GAAG,EACH;Q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D;IAC3D,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,IAAI,UAAU,CAAC;IAEhD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,QAAQ;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,UAAU;QACjB,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kadi.build/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.12",
|
|
4
4
|
"description": "A module that is a comprehensive toolkit for developers integrating with the KADI infrastructure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|