@kadi.build/core 0.0.1-alpha.12 → 0.0.1-alpha.14

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 (45) hide show
  1. package/dist/abilities/AbilityLoader.d.ts +136 -12
  2. package/dist/abilities/AbilityLoader.d.ts.map +1 -1
  3. package/dist/abilities/AbilityLoader.js +432 -64
  4. package/dist/abilities/AbilityLoader.js.map +1 -1
  5. package/dist/abilities/types.d.ts +119 -4
  6. package/dist/abilities/types.d.ts.map +1 -1
  7. package/dist/api/index.d.ts +1 -40
  8. package/dist/api/index.d.ts.map +1 -1
  9. package/dist/api/index.js +0 -57
  10. package/dist/api/index.js.map +1 -1
  11. package/dist/client/KadiClient.d.ts.map +1 -1
  12. package/dist/client/KadiClient.js +65 -4
  13. package/dist/client/KadiClient.js.map +1 -1
  14. package/dist/config/ConfigLoader.d.ts.map +1 -1
  15. package/dist/config/ConfigLoader.js +1 -0
  16. package/dist/config/ConfigLoader.js.map +1 -1
  17. package/dist/config/ConfigResolver.d.ts.map +1 -1
  18. package/dist/config/ConfigResolver.js +1 -0
  19. package/dist/config/ConfigResolver.js.map +1 -1
  20. package/dist/index.d.ts +2 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/transports/NativeTransport.d.ts.map +1 -1
  25. package/dist/transports/NativeTransport.js +22 -0
  26. package/dist/transports/NativeTransport.js.map +1 -1
  27. package/dist/transports/StdioTransport.d.ts +17 -2
  28. package/dist/transports/StdioTransport.d.ts.map +1 -1
  29. package/dist/transports/StdioTransport.js +45 -10
  30. package/dist/transports/StdioTransport.js.map +1 -1
  31. package/dist/types/config.d.ts +48 -33
  32. package/dist/types/config.d.ts.map +1 -1
  33. package/dist/types/config.js.map +1 -1
  34. package/dist/types/index.d.ts +1 -1
  35. package/dist/types/index.d.ts.map +1 -1
  36. package/dist/types/index.js.map +1 -1
  37. package/dist/utils/LockfileResolver.d.ts +179 -28
  38. package/dist/utils/LockfileResolver.d.ts.map +1 -1
  39. package/dist/utils/LockfileResolver.js +380 -39
  40. package/dist/utils/LockfileResolver.js.map +1 -1
  41. package/dist/utils/legacyHelpers.d.ts +82 -0
  42. package/dist/utils/legacyHelpers.d.ts.map +1 -0
  43. package/dist/utils/legacyHelpers.js +226 -0
  44. package/dist/utils/legacyHelpers.js.map +1 -0
  45. package/package.json +1 -1
@@ -53,6 +53,38 @@ export declare class AbilityLoader {
53
53
  * - Same name, different brokers
54
54
  */
55
55
  private cache;
56
+ /**
57
+ * Explicit project root (provided by KadiClient)
58
+ *
59
+ * This is the directory where KADI will look for abilities.
60
+ * - If provided: use this directory
61
+ * - If not provided: default to process.cwd()
62
+ *
63
+ * This makes context explicit instead of inferred.
64
+ */
65
+ private readonly explicitProjectRoot?;
66
+ /**
67
+ * Create an AbilityLoader
68
+ *
69
+ * **AbilityLoader** is responsible for finding, loading, and caching abilities.
70
+ *
71
+ * @param options - Loader options
72
+ * @param options.projectRoot - Explicit project root (overrides detection)
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // With explicit project root (CLI plugin)
77
+ * const loader = new AbilityLoader({
78
+ * projectRoot: '/opt/homebrew/lib/node_modules/@kadi.build/cli'
79
+ * });
80
+ *
81
+ * // Without explicit project root (user project)
82
+ * const loader = new AbilityLoader({});
83
+ * ```
84
+ */
85
+ constructor(options?: {
86
+ projectRoot?: string;
87
+ });
56
88
  /**
57
89
  * Load an ability with explicit transport
58
90
  *
@@ -145,16 +177,59 @@ export declare class AbilityLoader {
145
177
  * ```
146
178
  */
147
179
  cleanup(): number;
180
+ /**
181
+ * Detect project root directory
182
+ *
183
+ * **Strategy** (simple and explicit):
184
+ * 1. Use explicit override (constructor option or env var)
185
+ * 2. Fall back to process.cwd() (default behavior, like professor's approach)
186
+ *
187
+ * **Why This Approach?**
188
+ * - **Explicit over implicit**: Plugins tell us where to load from
189
+ * - **Simple**: No stack parsing, no complex inference
190
+ * - **Reliable**: Works in all environments (dev, prod, bundlers, etc.)
191
+ * - **Escape hatch**: Env var for edge cases
192
+ *
193
+ * **How It's Used**:
194
+ * - CLI plugins: Pass `ctx.core.getKadiInstallPath()` via constructor
195
+ * - User projects: Don't pass anything, uses process.cwd()
196
+ * - Edge cases: Set KADI_PROJECT_ROOT env var
197
+ *
198
+ * @returns Detected project root directory
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * // Example 1: CLI plugin (explicit)
203
+ * const loader = new AbilityLoader({
204
+ * projectRoot: '/opt/homebrew/lib/node_modules/@kadi.build/cli'
205
+ * });
206
+ * const root = loader.detectProjectRoot();
207
+ * // Returns: '/opt/homebrew/lib/node_modules/@kadi.build/cli'
208
+ *
209
+ * // Example 2: User project (default)
210
+ * const loader = new AbilityLoader({});
211
+ * const root = loader.detectProjectRoot();
212
+ * // Returns: process.cwd() (e.g., '/Users/kassi/Repositories/KADI/gateway-agent')
213
+ *
214
+ * // Example 3: Env var override (escape hatch)
215
+ * process.env.KADI_PROJECT_ROOT = '/app';
216
+ * const loader = new AbilityLoader({});
217
+ * const root = loader.detectProjectRoot();
218
+ * // Returns: '/app'
219
+ * ```
220
+ */
221
+ private detectProjectRoot;
148
222
  /**
149
223
  * Create appropriate transport instance
150
224
  *
151
- * Clean factory pattern - delegates to specialized creation methods.
152
- * Each transport type has its own dedicated method with proper validation.
225
+ * Factory pattern that creates the right transport based on type.
226
+ * Each transport type (native, stdio, broker) has its own creation method.
153
227
  *
154
228
  * @param name - Ability name
155
- * @param transport - Transport type (from inference)
156
- * @param options - Load options
229
+ * @param transport - Transport type (native, stdio, or broker)
230
+ * @param options - Load options (transport-specific)
157
231
  * @param brokerClient - Broker client (for broker transport)
232
+ * @param projectRoot - Project root directory (where to find abilities)
158
233
  * @returns Transport instance ready to connect
159
234
  *
160
235
  * @throws {KadiError} If transport creation fails
@@ -174,29 +249,78 @@ export declare class AbilityLoader {
174
249
  */
175
250
  private createBrokerTransport;
176
251
  /**
177
- * Create native transport with path auto-resolution
252
+ * Create native transport with project root context
178
253
  *
179
- * If path is provided, uses it directly (backwards compatible).
180
- * If path is NOT provided, auto-resolves from agent-lock.json.
254
+ * Native transport loads abilities directly from the filesystem.
255
+ *
256
+ * Resolution strategy:
257
+ * 1. If explicit path provided → use it directly
258
+ * 2. Otherwise → auto-resolve from projectRoot using lockfile
181
259
  *
182
260
  * @param name - Ability name
183
261
  * @param options - Load options (native-specific)
262
+ * @param projectRoot - Project root directory (from detectProjectRoot)
184
263
  * @returns Native transport instance
185
264
  *
186
- * @throws {KadiError} If path is missing and auto-resolution fails
265
+ * @throws {KadiError} If path cannot be resolved
187
266
  */
188
267
  private createNativeTransport;
189
268
  /**
190
- * Create stdio transport with command auto-resolution
269
+ * Create stdio transport with context-aware command resolution
270
+ *
271
+ * Resolution strategy:
272
+ * 1. If explicit command provided → use it directly
273
+ * 2. Otherwise → auto-resolve from caller's project context
191
274
  *
192
- * If command is provided, uses it directly (backwards compatible).
193
- * If command is NOT provided, auto-resolves from agent-lock.json.
275
+ * **Context-Aware Resolution:**
276
+ * - Uses callerFilePath to find the correct project root
277
+ * - CLI plugins resolve from CLI's abilities/
278
+ * - User projects resolve from project's abilities/
194
279
  *
195
280
  * @param name - Ability name
196
281
  * @param options - Load options (stdio-specific)
282
+ * @param callerFilePath - File path where load() was called from
197
283
  * @returns Stdio transport instance
198
284
  *
199
- * @throws {KadiError} If command is missing and auto-resolution fails
285
+ * @throws {KadiError} If command cannot be resolved
286
+ */
287
+ /**
288
+ * Create stdio transport with auto-resolution support
289
+ *
290
+ * **Two modes of operation**:
291
+ *
292
+ * 1. **Auto-resolution** (no command provided):
293
+ * - Resolves ability path using resolveAbilityConfig()
294
+ * - Reads ability's agent.json
295
+ * - Extracts scripts.start command
296
+ * - Spawns child process with shell: true
297
+ * - Sets cwd to ability directory
298
+ * - Injects KADI_* environment variables
299
+ *
300
+ * 2. **Explicit command** (command provided):
301
+ * - Uses provided command/args directly
302
+ * - Developer has full control
303
+ * - Still injects KADI_* environment variables
304
+ *
305
+ * @param name - Ability name
306
+ * @param options - Load options (stdio-specific)
307
+ * @param projectRoot - Project root directory (from detectProjectRoot)
308
+ * @returns Stdio transport instance
309
+ *
310
+ * @throws {KadiError} If command cannot be resolved or scripts.start missing
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * // Auto-resolution mode
315
+ * const transport = this.createStdioTransport('calculator', {}, '/project/root');
316
+ * // Resolves path, reads agent.json, uses scripts.start
317
+ *
318
+ * // Explicit mode
319
+ * const transport = this.createStdioTransport('calculator', {
320
+ * command: 'node',
321
+ * args: ['dist/index.js']
322
+ * }, '/project/root');
323
+ * ```
200
324
  */
201
325
  private createStdioTransport;
202
326
  }
@@ -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;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,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