@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.
- package/README.md +424 -1
- package/agent.json +19 -0
- package/dist/agent-json.d.ts +231 -0
- package/dist/agent-json.d.ts.map +1 -0
- package/dist/agent-json.js +554 -0
- package/dist/agent-json.js.map +1 -0
- package/dist/client.d.ts +34 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +50 -0
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/process-manager.d.ts +235 -0
- package/dist/process-manager.d.ts.map +1 -0
- package/dist/process-manager.js +647 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/stdio-framing.d.ts +88 -0
- package/dist/stdio-framing.d.ts.map +1 -0
- package/dist/stdio-framing.js +194 -0
- package/dist/stdio-framing.js.map +1 -0
- package/dist/transports/stdio.d.ts.map +1 -1
- package/dist/transports/stdio.js +3 -181
- package/dist/transports/stdio.js.map +1 -1
- package/dist/types.d.ts +256 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +107 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +212 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -1
- package/scripts/symlink.mjs +131 -0
- package/src/agent-json.ts +655 -0
- package/src/client.ts +56 -0
- package/src/errors.ts +15 -0
- package/src/index.ts +32 -0
- package/src/process-manager.ts +821 -0
- package/src/stdio-framing.ts +227 -0
- package/src/transports/stdio.ts +4 -221
- package/src/types.ts +277 -0
- package/src/utils.ts +246 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* kadi-core postinstall symlink script
|
|
5
|
+
*
|
|
6
|
+
* When kadi-core is installed as an ability (via `kadi install`), it ends up in:
|
|
7
|
+
* <project>/abilities/kadi-core@x.y.z/
|
|
8
|
+
*
|
|
9
|
+
* This script creates a symlink so that regular Node.js imports work seamlessly:
|
|
10
|
+
* <project>/node_modules/@kadi.build/core → <project>/abilities/kadi-core@x.y.z/
|
|
11
|
+
*
|
|
12
|
+
* This means users can do:
|
|
13
|
+
* import { KadiClient } from '@kadi.build/core';
|
|
14
|
+
*
|
|
15
|
+
* without needing to know the ability install path or version number.
|
|
16
|
+
*
|
|
17
|
+
* The script is idempotent — safe to run multiple times.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, mkdirSync, symlinkSync, lstatSync, readlinkSync, unlinkSync } from 'fs';
|
|
21
|
+
import { join, dirname, resolve, relative } from 'path';
|
|
22
|
+
import { fileURLToPath } from 'url';
|
|
23
|
+
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = dirname(__filename);
|
|
26
|
+
|
|
27
|
+
// This script lives at <ability>/scripts/symlink.mjs
|
|
28
|
+
// The ability root is one level up
|
|
29
|
+
const abilityRoot = resolve(__dirname, '..');
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Walk up from the ability directory to find the project root.
|
|
33
|
+
* The project root is the parent of the "abilities" directory.
|
|
34
|
+
*
|
|
35
|
+
* Expected structure:
|
|
36
|
+
* <project>/abilities/kadi-core@0.10.0/scripts/symlink.mjs
|
|
37
|
+
* <project>/node_modules/@kadi.build/core ← symlink target
|
|
38
|
+
*/
|
|
39
|
+
function findProjectRoot() {
|
|
40
|
+
let current = abilityRoot;
|
|
41
|
+
|
|
42
|
+
// Walk up looking for the abilities/ parent
|
|
43
|
+
for (let i = 0; i < 5; i++) {
|
|
44
|
+
const parent = dirname(current);
|
|
45
|
+
const dirName = current.split('/').pop() || current.split('\\').pop();
|
|
46
|
+
|
|
47
|
+
// Check if we're inside an "abilities" directory
|
|
48
|
+
if (parent && dirname(current).endsWith('abilities')) {
|
|
49
|
+
// Parent of abilities/ is the project root
|
|
50
|
+
return dirname(dirname(current));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Also check if the parent directory name starts with "abilities"
|
|
54
|
+
const parentDirName = dirname(current).split('/').pop() || dirname(current).split('\\').pop();
|
|
55
|
+
if (parentDirName === 'abilities') {
|
|
56
|
+
return dirname(dirname(current));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
current = parent;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Fallback: if abilities/ directory exists as a sibling pattern,
|
|
63
|
+
// the project root is likely 2 levels up from where the ability is installed
|
|
64
|
+
// e.g., <project>/abilities/kadi-core@x.y.z → <project>
|
|
65
|
+
const twoUp = resolve(abilityRoot, '..', '..');
|
|
66
|
+
if (existsSync(join(twoUp, 'agent.json'))) {
|
|
67
|
+
return twoUp;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function main() {
|
|
74
|
+
const projectRoot = findProjectRoot();
|
|
75
|
+
|
|
76
|
+
if (!projectRoot) {
|
|
77
|
+
// Not installed as an ability (maybe running from source) — skip silently
|
|
78
|
+
console.log('[kadi-core] Not installed as an ability, skipping symlink creation.');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const symlinkDir = join(projectRoot, 'node_modules', '@kadi.build');
|
|
83
|
+
const symlinkPath = join(symlinkDir, 'core');
|
|
84
|
+
|
|
85
|
+
// Compute relative path from symlink location to ability root
|
|
86
|
+
const relativeTarget = relative(symlinkDir, abilityRoot);
|
|
87
|
+
|
|
88
|
+
// Create the @kadi.build/ directory in node_modules
|
|
89
|
+
if (!existsSync(symlinkDir)) {
|
|
90
|
+
mkdirSync(symlinkDir, { recursive: true });
|
|
91
|
+
console.log(`[kadi-core] Created ${symlinkDir}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Check if symlink already exists and points to the right place
|
|
95
|
+
if (existsSync(symlinkPath)) {
|
|
96
|
+
try {
|
|
97
|
+
const stats = lstatSync(symlinkPath);
|
|
98
|
+
if (stats.isSymbolicLink()) {
|
|
99
|
+
const currentTarget = readlinkSync(symlinkPath);
|
|
100
|
+
if (resolve(symlinkDir, currentTarget) === abilityRoot) {
|
|
101
|
+
console.log(`[kadi-core] Symlink already exists and is correct: ${symlinkPath}`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// Wrong target — remove and recreate
|
|
105
|
+
console.log(`[kadi-core] Updating symlink (was pointing to ${currentTarget})`);
|
|
106
|
+
unlinkSync(symlinkPath);
|
|
107
|
+
} else {
|
|
108
|
+
// It's a real directory/file — don't touch it
|
|
109
|
+
console.log(`[kadi-core] ${symlinkPath} exists and is not a symlink — skipping.`);
|
|
110
|
+
console.log('[kadi-core] If you want the symlink, remove the existing directory first.');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
// Can't read — try to remove
|
|
115
|
+
try { unlinkSync(symlinkPath); } catch { /* ignore */ }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Create the symlink
|
|
120
|
+
try {
|
|
121
|
+
symlinkSync(relativeTarget, symlinkPath, 'dir');
|
|
122
|
+
console.log(`[kadi-core] Created symlink: ${symlinkPath} → ${relativeTarget}`);
|
|
123
|
+
console.log('[kadi-core] You can now: import { KadiClient } from \'@kadi.build/core\'');
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(`[kadi-core] Failed to create symlink: ${error.message}`);
|
|
126
|
+
console.error(`[kadi-core] You can create it manually:`);
|
|
127
|
+
console.error(` ln -s ${relativeTarget} ${symlinkPath}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
main();
|