@kadi.build/core 0.9.0 → 0.11.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.
Files changed (45) hide show
  1. package/README.md +424 -1
  2. package/agent.json +19 -0
  3. package/dist/agent-json.d.ts +231 -0
  4. package/dist/agent-json.d.ts.map +1 -0
  5. package/dist/agent-json.js +554 -0
  6. package/dist/agent-json.js.map +1 -0
  7. package/dist/client.d.ts +34 -0
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +50 -0
  10. package/dist/client.js.map +1 -1
  11. package/dist/errors.d.ts +1 -1
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js.map +1 -1
  14. package/dist/index.d.ts +5 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/process-manager.d.ts +235 -0
  19. package/dist/process-manager.d.ts.map +1 -0
  20. package/dist/process-manager.js +647 -0
  21. package/dist/process-manager.js.map +1 -0
  22. package/dist/stdio-framing.d.ts +88 -0
  23. package/dist/stdio-framing.d.ts.map +1 -0
  24. package/dist/stdio-framing.js +194 -0
  25. package/dist/stdio-framing.js.map +1 -0
  26. package/dist/transports/stdio.d.ts.map +1 -1
  27. package/dist/transports/stdio.js +3 -181
  28. package/dist/transports/stdio.js.map +1 -1
  29. package/dist/types.d.ts +256 -0
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/utils.d.ts +107 -0
  32. package/dist/utils.d.ts.map +1 -0
  33. package/dist/utils.js +212 -0
  34. package/dist/utils.js.map +1 -0
  35. package/package.json +3 -1
  36. package/scripts/symlink.mjs +131 -0
  37. package/src/agent-json.ts +655 -0
  38. package/src/client.ts +56 -0
  39. package/src/errors.ts +15 -0
  40. package/src/index.ts +32 -0
  41. package/src/process-manager.ts +821 -0
  42. package/src/stdio-framing.ts +227 -0
  43. package/src/transports/stdio.ts +4 -221
  44. package/src/types.ts +277 -0
  45. package/src/utils.ts +246 -0
@@ -0,0 +1,231 @@
1
+ /**
2
+ * AgentJsonManager for kadi-core
3
+ *
4
+ * Provides unified read/write access to agent.json files across the ecosystem.
5
+ * Three target locations:
6
+ *
7
+ * 1. **Project root** — the agent's own config (`/my-agent/agent.json`)
8
+ * 2. **Installed ability** — an ability's config (`/my-agent/abilities/calculator@1.0.0/agent.json`)
9
+ * 3. **KADI home** — global CLI config (`~/.kadi/agent.json`)
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { AgentJsonManager } from '@kadi.build/core';
14
+ *
15
+ * const ajm = new AgentJsonManager();
16
+ *
17
+ * // Read
18
+ * const config = await ajm.readProject();
19
+ * const deploy = await ajm.readProject('deploy.local');
20
+ * const abilityConfig = await ajm.readAbility('calculator');
21
+ *
22
+ * // Write
23
+ * await ajm.writeProject('deploy.staging', { target: 'akash' });
24
+ * await ajm.deleteProject('deploy.staging');
25
+ * ```
26
+ */
27
+ import type { AgentJsonManagerOptions, ReadAbilityOptions, AbilityInfo, AgentJsonPaths } from './types.js';
28
+ export declare class AgentJsonManager {
29
+ private readonly options;
30
+ /** Cached project root (resolved lazily) */
31
+ private resolvedProjectRoot;
32
+ constructor(options?: AgentJsonManagerOptions);
33
+ /**
34
+ * Get the resolved project root path.
35
+ * Auto-detects if not explicitly set.
36
+ */
37
+ private getProjectRoot;
38
+ /**
39
+ * Read the project root agent.json.
40
+ *
41
+ * @param field - Optional dot-notation path to a specific field
42
+ * @returns The full agent.json object, or a specific field value
43
+ * @throws KadiError with code AGENT_JSON_NOT_FOUND, AGENT_JSON_PARSE_ERROR,
44
+ * or AGENT_JSON_FIELD_NOT_FOUND
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const config = await ajm.readProject(); // Full object
49
+ * const name = await ajm.readProject('name'); // 'my-agent'
50
+ * const deploy = await ajm.readProject('deploy.local'); // { target: 'docker', ... }
51
+ * ```
52
+ */
53
+ readProject(field?: string): Promise<unknown>;
54
+ /**
55
+ * Read an installed ability's agent.json.
56
+ *
57
+ * Resolution order for version ambiguity:
58
+ * 1. If `options.version` specified → exact match
59
+ * 2. Prefer `isTopLevel: true` entries (direct dependencies)
60
+ * 3. Use highest semver version
61
+ *
62
+ * @param name - Ability name (without version)
63
+ * @param options - Version targeting and field selection
64
+ * @returns The full agent.json object, or a specific field value
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const config = await ajm.readAbility('calculator');
69
+ * const scripts = await ajm.readAbility('calculator', { field: 'scripts' });
70
+ * const specific = await ajm.readAbility('secret-ability', { version: '0.9.0' });
71
+ * ```
72
+ */
73
+ readAbility(name: string, options?: ReadAbilityOptions): Promise<unknown>;
74
+ /**
75
+ * Read the global KADI home agent.json (~/.kadi/agent.json).
76
+ *
77
+ * @param field - Optional dot-notation path to a specific field
78
+ * @returns The full agent.json object, or a specific field value
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const global = await ajm.readHome();
83
+ * const plugins = await ajm.readHome('cliPlugins');
84
+ * ```
85
+ */
86
+ readHome(field?: string): Promise<unknown>;
87
+ /**
88
+ * Write a value to the project root agent.json.
89
+ *
90
+ * Uses deep-merge semantics for objects (preserves sibling keys).
91
+ * Scalars and arrays are directly replaced.
92
+ *
93
+ * @param path - Dot-notation path to the field to set
94
+ * @param value - The value to write
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * await ajm.writeProject('version', '2.0.0');
99
+ * await ajm.writeProject('deploy.staging', { target: 'akash', network: 'mainnet' });
100
+ * await ajm.writeProject('build.arm64', { from: 'node:22-slim', platform: 'linux/arm64' });
101
+ * ```
102
+ */
103
+ writeProject(path: string, value: unknown): Promise<void>;
104
+ /**
105
+ * Write a value to an installed ability's agent.json.
106
+ *
107
+ * @param name - Ability name
108
+ * @param path - Dot-notation path to the field to set
109
+ * @param value - The value to write
110
+ * @param version - Optional specific version to target
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * await ajm.writeAbility('calculator', 'scripts.dev', 'node dist/index.js --debug');
115
+ * ```
116
+ */
117
+ writeAbility(name: string, path: string, value: unknown, version?: string): Promise<void>;
118
+ /**
119
+ * Write a value to the global KADI home agent.json.
120
+ *
121
+ * @param path - Dot-notation path to the field to set
122
+ * @param value - The value to write
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * await ajm.writeHome('cliPlugins.my-plugin', { version: '1.0.0' });
127
+ * ```
128
+ */
129
+ writeHome(path: string, value: unknown): Promise<void>;
130
+ /**
131
+ * Delete a field from the project root agent.json.
132
+ *
133
+ * @param path - Dot-notation path to the field to delete
134
+ * @returns true if the field was found and deleted
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * await ajm.deleteProject('deploy.staging');
139
+ * ```
140
+ */
141
+ deleteProject(path: string): Promise<boolean>;
142
+ /**
143
+ * Delete a field from an ability's agent.json.
144
+ */
145
+ deleteAbility(name: string, path: string, version?: string): Promise<boolean>;
146
+ /**
147
+ * Delete a field from the global KADI home agent.json.
148
+ */
149
+ deleteHome(path: string): Promise<boolean>;
150
+ /**
151
+ * List all installed abilities with their name, version, and path.
152
+ *
153
+ * @returns Array of AbilityInfo objects
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const abilities = await ajm.listAbilities();
158
+ * // [
159
+ * // { name: 'calculator', version: '1.0.0', path: '/abs/path/abilities/calculator@1.0.0' },
160
+ * // { name: 'secret-ability', version: '0.9.0', path: '/abs/path/abilities/secret-ability@0.9.0' },
161
+ * // ]
162
+ * ```
163
+ */
164
+ listAbilities(): Promise<AbilityInfo[]>;
165
+ /**
166
+ * Check if a specific ability is installed.
167
+ *
168
+ * @param name - Ability name (without version)
169
+ * @returns true if the ability exists in the lock file
170
+ */
171
+ hasAbility(name: string): Promise<boolean>;
172
+ /**
173
+ * Get all installed versions of a specific ability.
174
+ *
175
+ * @param name - Ability name (without version)
176
+ * @returns Array of version strings
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const versions = await ajm.getAbilityVersions('secret-ability');
181
+ * // ['0.7.0', '0.9.0']
182
+ * ```
183
+ */
184
+ getAbilityVersions(name: string): Promise<string[]>;
185
+ /**
186
+ * Get resolved paths for all known agent.json files.
187
+ *
188
+ * @returns Object with project, home, and abilities paths
189
+ */
190
+ getPaths(): Promise<AgentJsonPaths>;
191
+ /**
192
+ * Read and parse a JSON file.
193
+ */
194
+ private readJsonFile;
195
+ /**
196
+ * Resolve a field from a parsed agent.json using dot-path notation.
197
+ */
198
+ private resolveField;
199
+ /**
200
+ * Write a field to a JSON file using dot-path notation.
201
+ * Atomic write: writes to a temp file then renames.
202
+ */
203
+ private writeField;
204
+ /**
205
+ * Delete a field from a JSON file.
206
+ */
207
+ private deleteField;
208
+ /**
209
+ * Write JSON to a file atomically (write temp → rename).
210
+ */
211
+ private atomicWriteJson;
212
+ /**
213
+ * Resolve the directory path for an installed ability.
214
+ * Handles version ambiguity with smart defaults.
215
+ */
216
+ private resolveAbilityDir;
217
+ /**
218
+ * Find all lock file entries matching an ability name.
219
+ */
220
+ private findAbilityEntries;
221
+ /**
222
+ * Pick the entry with the highest semver version.
223
+ * Simple comparison — splits on dots and compares numerically.
224
+ */
225
+ private highestVersion;
226
+ /**
227
+ * Compare two semver strings. Returns > 0 if a > b, < 0 if a < b, 0 if equal.
228
+ */
229
+ private compareSemver;
230
+ }
231
+ //# sourceMappingURL=agent-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-json.d.ts","sourceRoot":"","sources":["../src/agent-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAOH,OAAO,KAAK,EAEV,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,cAAc,EAGf,MAAM,YAAY,CAAC;AAgBpB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAE5D,4CAA4C;IAC5C,OAAO,CAAC,mBAAmB,CAAuB;gBAEtC,OAAO,GAAE,uBAA4B;IAYjD;;;OAGG;YACW,cAAc;IAkB5B;;;;;;;;;;;;;;OAcG;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