@kadi.build/core 0.0.1-alpha.13 → 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 +169 -28
  38. package/dist/utils/LockfileResolver.d.ts.map +1 -1
  39. package/dist/utils/LockfileResolver.js +325 -71
  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
@@ -7,27 +7,86 @@
7
7
  * @module utils/LockfileResolver
8
8
  */
9
9
  /**
10
- * Minimal lockfile types (only what kadi-core needs)
10
+ * Agent Lockfile Types (v0 Structure)
11
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.
12
+ * These types define the structure of agent-lock.json files.
13
+ * The lockfile ensures reproducible installs and tracks exact ability versions.
14
+ *
15
+ * **Key Design Decisions:**
16
+ * - Use `name@version` as keys for future multi-version support
17
+ * - Track dependencies to enable resolution of transitive dependencies
18
+ * - Store integrity hashes for verification
19
+ * - Include metadata for debugging and compatibility checks
20
+ */
21
+ /**
22
+ * Metadata about the lockfile generation
23
+ */
24
+ export interface LockfileMetadata {
25
+ /** Version of KADI that generated this lockfile */
26
+ kadiVersion: string;
27
+ /** ISO 8601 timestamp when lockfile was generated */
28
+ generated: string;
29
+ }
30
+ /**
31
+ * Single ability entry in the lockfile
32
+ *
33
+ * **Key is**: `name@version` (e.g., "secret-ability@0.0.1")
34
+ * **Value contains**: All information needed to locate and verify the ability
14
35
  */
15
36
  export interface LockfileAbilityEntry {
37
+ /** Semantic version of this ability */
16
38
  version: string;
17
- kind: 'plugin' | 'ability';
39
+ /** Type of ability - determines how it's used */
40
+ kind?: 'plugin' | 'ability';
41
+ /** Relative path from project root to installed ability directory */
18
42
  resolved: string;
43
+ /** Integrity hash (sha512) of the ability package for verification */
19
44
  integrity: string;
20
- installStrategy: 'hardlink' | 'clonefile' | 'copyfile' | 'symlink';
21
- detached: boolean;
45
+ /** Strategy used to install this ability on disk */
46
+ installStrategy?: 'hardlink' | 'clonefile' | 'copyfile' | 'symlink';
47
+ /**
48
+ * Dependencies of this ability
49
+ *
50
+ * Maps ability name to required version.
51
+ * When this ability loads a dependency, we verify it gets the correct version.
52
+ *
53
+ * Example: { "secret-ability": "0.0.1", "crypto-utils": "1.2.0" }
54
+ */
55
+ dependencies?: Record<string, string>;
22
56
  }
57
+ /**
58
+ * Complete agent-lock.json structure (v0)
59
+ *
60
+ * **Purpose**: Ensure reproducible ability installations across environments
61
+ *
62
+ * **Structure:**
63
+ * - `lockfileVersion`: Format version for future migrations
64
+ * - `metadata`: Context about generation
65
+ * - `agent`: The project/CLI that owns this lockfile
66
+ * - `abilities`: All installed abilities (direct + transitive dependencies)
67
+ */
23
68
  export interface AgentLockfile {
69
+ /** Lockfile format version - increment when structure changes */
24
70
  lockfileVersion: number;
25
- abilities: Record<string, LockfileAbilityEntry>;
71
+ /** Metadata about lockfile generation */
72
+ metadata: LockfileMetadata;
73
+ /** The project or CLI that owns this lockfile */
26
74
  agent: {
75
+ /** Project/CLI name */
27
76
  name: string;
77
+ /** Project/CLI version */
28
78
  version: string;
29
79
  };
30
- generated: string;
80
+ /**
81
+ * All installed abilities, indexed by `name@version`
82
+ *
83
+ * Includes both:
84
+ * - Direct dependencies (explicitly installed)
85
+ * - Transitive dependencies (pulled in by other abilities)
86
+ *
87
+ * Example keys: "kadi-secret@0.0.1", "secret-ability@0.0.1"
88
+ */
89
+ abilities: Record<string, LockfileAbilityEntry>;
31
90
  }
32
91
  /**
33
92
  * Minimal ability manifest (agent.json)
@@ -39,7 +98,21 @@ export interface AbilityManifest {
39
98
  version: string;
40
99
  kind?: 'plugin' | 'ability';
41
100
  entry?: string;
101
+ entrypoint?: string;
42
102
  description?: string;
103
+ /**
104
+ * Lifecycle scripts
105
+ *
106
+ * Shell commands for different execution stages.
107
+ * Primarily used by stdio transport for auto-resolution.
108
+ */
109
+ scripts?: {
110
+ preflight?: string;
111
+ setup?: string;
112
+ start?: string;
113
+ stop?: string;
114
+ [key: string]: string | undefined;
115
+ };
43
116
  [key: string]: unknown;
44
117
  }
45
118
  /**
@@ -53,15 +126,63 @@ export interface AbilityManifest {
53
126
  */
54
127
  export declare function findInGlobalCache(abilityName: string): string | null;
55
128
  /**
56
- * Find project root by looking for agent.json
129
+ * Find sibling abilities directory
130
+ *
131
+ * TEMPORARY: This function detects if we're running inside an ability
132
+ * (e.g., kadi-secret) and finds its sibling abilities.
133
+ *
134
+ * When kadi-secret loads secret-ability, both are installed in the same
135
+ * parent abilities/ directory. This function walks up the directory tree
136
+ * to find the abilities/ folder we're running from.
137
+ *
138
+ * Example: If running from:
139
+ * /opt/homebrew/.../cli/abilities/kadi-secret/0.0.1/dist/index.js
140
+ * Returns:
141
+ * /opt/homebrew/.../cli/abilities/
57
142
  *
58
- * Walks up directory tree from cwd until finding agent.json
143
+ * TODO: Replace with config.json approach (see CLI-REVAMP-PLAN.md)
144
+ * Future: abilities will reference ~/.kadi/config.json for discovery
59
145
  *
60
- * @param startDir - Directory to start search from (defaults to cwd)
61
- * @returns Absolute path to project root
146
+ * @returns Sibling abilities directory path, or null if not running from an ability
147
+ */
148
+ export declare function findSiblingAbilitiesDir(): string | null;
149
+ /**
150
+ * Find ability in a specific abilities directory
151
+ *
152
+ * Generic function to search for an ability in any abilities folder.
153
+ * Scans {baseDir}/{abilityName}/ for version directories and returns the highest version.
154
+ *
155
+ * @param abilityName - Name of the ability to find
156
+ * @param baseDir - Base abilities directory to search in
157
+ * @returns Object with path and version, or null if not found
158
+ */
159
+ export declare function findInAbilitiesDir(abilityName: string, baseDir: string): {
160
+ path: string;
161
+ version: string;
162
+ } | null;
163
+ /**
164
+ * Find the true project root by intelligently searching for agent.json
165
+ *
166
+ * This function distinguishes between:
167
+ * - **Ability manifests**: agent.json files inside abilities/name/version/
168
+ * - **Project roots**: agent.json files that represent actual projects (CLI or user projects)
169
+ *
170
+ * **Algorithm:**
171
+ * 1. Walk up directory tree from startPath
172
+ * 2. For each agent.json found, check if it's inside an abilities/ structure
173
+ * 3. If inside abilities/ → skip (it's an ability manifest, not a project root)
174
+ * 4. If NOT inside abilities/ → return (it's a true project root)
175
+ *
176
+ * **Example paths:**
177
+ * - `/opt/homebrew/.../cli/abilities/kadi-secret/0.0.1/agent.json` → SKIP (ability manifest)
178
+ * - `/opt/homebrew/.../cli/agent.json` → RETURN (CLI root)
179
+ * - `/Users/alice/my-project/agent.json` → RETURN (user project root)
180
+ *
181
+ * @param startPath - File or directory path to start searching from (defaults to cwd)
182
+ * @returns Absolute path to the true project root
62
183
  * @throws {KadiError} If no project root found
63
184
  */
64
- export declare function findProjectRoot(startDir?: string): string;
185
+ export declare function findProjectRoot(startPath?: string): string;
65
186
  /**
66
187
  * Read agent-lock.json from project root
67
188
  *
@@ -88,28 +209,48 @@ export declare function resolveAbilityPath(abilityName: string, projectRoot: str
88
209
  */
89
210
  export declare function readAbilityManifest(abilityPath: string): AbilityManifest;
90
211
  /**
91
- * Auto-resolve ability configuration for loading
212
+ * Resolve ability configuration from project root
213
+ *
214
+ * **New Explicit Strategy:**
215
+ * Uses explicit project root instead of inferring from stack traces:
216
+ * 1. Use provided projectRoot directly (no inference needed)
217
+ * 2. Look in `{projectRoot}/abilities/{abilityName}/`
218
+ * 3. If not found → clear error with exact path searched
219
+ *
220
+ * **Why This Works:**
221
+ * - CLI plugins: Get projectRoot from `ctx.core.getKadiInstallPath()`
222
+ * - projectRoot: `/opt/homebrew/.../cli/`
223
+ * - Searches: `/opt/homebrew/.../cli/abilities/secret-ability/`
92
224
  *
93
- * Combines lockfile lookup with manifest reading to provide
94
- * all information needed to load an ability.
225
+ * - User projects: Get projectRoot from `process.cwd()` (default)
226
+ * - projectRoot: `/Users/alice/my-project/`
227
+ * - Searches: `/Users/alice/my-project/abilities/my-ability/`
95
228
  *
96
- * @param abilityName - Name of ability
97
- * @param projectRoot - Project root directory (optional, will search if not provided)
98
- * @returns Resolved ability configuration
229
+ * **Resolution Strategy:**
230
+ * 1. Check agent-lock.json (if exists) for exact version
231
+ * 2. Fall back to scanning abilities/ folder if no lockfile
232
+ * 3. Return highest version if multiple exist
233
+ *
234
+ * @param abilityName - Name of ability to resolve
235
+ * @param projectRoot - Project root directory (from detectProjectRoot or explicit config)
236
+ * @returns Resolved ability configuration with path, version, entry point, and manifest
237
+ *
238
+ * @throws {KadiError} If ability not found
99
239
  *
100
240
  * @example
101
241
  * ```typescript
102
- * const config = resolveAbilityConfig('math-lib');
103
- * // Returns:
104
- * // {
105
- * // path: '/path/to/project/abilities/math-lib@1.0.0',
106
- * // version: '1.0.0',
107
- * // entry: 'service.js',
108
- * // manifest: { ... }
109
- * // }
242
+ * // Called from CLI plugin (with explicit project root):
243
+ * const projectRoot = '/opt/homebrew/.../cli';
244
+ * const config = resolveAbilityConfig('secret-ability', projectRoot);
245
+ * // Searches: /opt/homebrew/.../cli/abilities/secret-ability/
246
+ *
247
+ * // Called from user project (with default project root):
248
+ * const projectRoot = process.cwd();
249
+ * const config = resolveAbilityConfig('my-ability', projectRoot);
250
+ * // Searches: {cwd}/abilities/my-ability/
110
251
  * ```
111
252
  */
112
- export declare function resolveAbilityConfig(abilityName: string, projectRoot?: string): {
253
+ export declare function resolveAbilityConfig(abilityName: string, projectRoot: string): {
113
254
  path: string;
114
255
  version: string;
115
256
  entry: string;
@@ -1 +1 @@
1
- {"version":3,"file":"LockfileResolver.d.ts","sourceRoot":"","sources":["../../src/utils/LockfileResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH;;;;;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,OAAO,CAAC;CACnB;AAED,MAAM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