@kya-os/cli 0.1.0-beta.1 ā 0.1.0-beta.11
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 +210 -34
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +73 -57
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/claim.js +33 -39
- package/dist/commands/claim.js.map +1 -1
- package/dist/commands/cli-experience-demo-simple.d.ts +14 -0
- package/dist/commands/cli-experience-demo-simple.d.ts.map +1 -0
- package/dist/commands/cli-experience-demo-simple.js +119 -0
- package/dist/commands/cli-experience-demo-simple.js.map +1 -0
- package/dist/commands/cli-experience-demo.d.ts +14 -0
- package/dist/commands/cli-experience-demo.d.ts.map +1 -0
- package/dist/commands/cli-experience-demo.js +172 -0
- package/dist/commands/cli-experience-demo.js.map +1 -0
- package/dist/commands/effects-demo.d.ts +10 -0
- package/dist/commands/effects-demo.d.ts.map +1 -0
- package/dist/commands/effects-demo.js +292 -0
- package/dist/commands/effects-demo.js.map +1 -0
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +55 -51
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +527 -102
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/rotate.d.ts.map +1 -1
- package/dist/commands/rotate.js +81 -60
- package/dist/commands/rotate.js.map +1 -1
- package/dist/dev.d.ts +7 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/dev.js +9 -0
- package/dist/dev.js.map +1 -0
- package/dist/effects/__tests__/effects.test.d.ts +5 -0
- package/dist/effects/__tests__/effects.test.d.ts.map +1 -0
- package/dist/effects/__tests__/effects.test.js +206 -0
- package/dist/effects/__tests__/effects.test.js.map +1 -0
- package/dist/effects/animation-engine.d.ts +173 -0
- package/dist/effects/animation-engine.d.ts.map +1 -0
- package/dist/effects/animation-engine.js +254 -0
- package/dist/effects/animation-engine.js.map +1 -0
- package/dist/effects/cli-integration.d.ts +86 -0
- package/dist/effects/cli-integration.d.ts.map +1 -0
- package/dist/effects/cli-integration.js +309 -0
- package/dist/effects/cli-integration.js.map +1 -0
- package/dist/effects/config.d.ts +95 -0
- package/dist/effects/config.d.ts.map +1 -0
- package/dist/effects/config.js +216 -0
- package/dist/effects/config.js.map +1 -0
- package/dist/effects/effect-runner.d.ts +69 -0
- package/dist/effects/effect-runner.d.ts.map +1 -0
- package/dist/effects/effect-runner.js +255 -0
- package/dist/effects/effect-runner.js.map +1 -0
- package/dist/effects/gradient.d.ts +131 -0
- package/dist/effects/gradient.d.ts.map +1 -0
- package/dist/effects/gradient.js +236 -0
- package/dist/effects/gradient.js.map +1 -0
- package/dist/effects/implementations/beams.d.ts +80 -0
- package/dist/effects/implementations/beams.d.ts.map +1 -0
- package/dist/effects/implementations/beams.js +221 -0
- package/dist/effects/implementations/beams.js.map +1 -0
- package/dist/effects/implementations/binary-path.d.ts +88 -0
- package/dist/effects/implementations/binary-path.d.ts.map +1 -0
- package/dist/effects/implementations/binary-path.js +296 -0
- package/dist/effects/implementations/binary-path.js.map +1 -0
- package/dist/effects/implementations/blackhole.d.ts +98 -0
- package/dist/effects/implementations/blackhole.d.ts.map +1 -0
- package/dist/effects/implementations/blackhole.js +394 -0
- package/dist/effects/implementations/blackhole.js.map +1 -0
- package/dist/effects/implementations/burn.d.ts +74 -0
- package/dist/effects/implementations/burn.d.ts.map +1 -0
- package/dist/effects/implementations/burn.js +234 -0
- package/dist/effects/implementations/burn.js.map +1 -0
- package/dist/effects/implementations/decrypt.d.ts +115 -0
- package/dist/effects/implementations/decrypt.d.ts.map +1 -0
- package/dist/effects/implementations/decrypt.js +394 -0
- package/dist/effects/implementations/decrypt.js.map +1 -0
- package/dist/effects/implementations/test.d.ts +113 -0
- package/dist/effects/implementations/test.d.ts.map +1 -0
- package/dist/effects/implementations/test.js +552 -0
- package/dist/effects/implementations/test.js.map +1 -0
- package/dist/effects/implementations/waves.d.ts +78 -0
- package/dist/effects/implementations/waves.d.ts.map +1 -0
- package/dist/effects/implementations/waves.js +278 -0
- package/dist/effects/implementations/waves.js.map +1 -0
- package/dist/effects/index.d.ts +37 -0
- package/dist/effects/index.d.ts.map +1 -0
- package/dist/effects/index.js +79 -0
- package/dist/effects/index.js.map +1 -0
- package/dist/effects/motion-engine.d.ts +168 -0
- package/dist/effects/motion-engine.d.ts.map +1 -0
- package/dist/effects/motion-engine.js +353 -0
- package/dist/effects/motion-engine.js.map +1 -0
- package/dist/effects/safe-executor.d.ts +55 -0
- package/dist/effects/safe-executor.d.ts.map +1 -0
- package/dist/effects/safe-executor.js +210 -0
- package/dist/effects/safe-executor.js.map +1 -0
- package/dist/effects/template/effect-template.d.ts +97 -0
- package/dist/effects/template/effect-template.d.ts.map +1 -0
- package/dist/effects/template/effect-template.js +208 -0
- package/dist/effects/template/effect-template.js.map +1 -0
- package/dist/effects/types.d.ts +199 -0
- package/dist/effects/types.d.ts.map +1 -0
- package/dist/effects/types.js +80 -0
- package/dist/effects/types.js.map +1 -0
- package/dist/effects/utils.d.ts +104 -0
- package/dist/effects/utils.d.ts.map +1 -0
- package/dist/effects/utils.js +280 -0
- package/dist/effects/utils.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -51
- package/dist/index.js.map +1 -1
- package/dist/utils/env-manager.d.ts +66 -2
- package/dist/utils/env-manager.d.ts.map +1 -1
- package/dist/utils/env-manager.js +355 -65
- package/dist/utils/env-manager.js.map +1 -1
- package/dist/utils/platform-detector.js +15 -19
- package/dist/utils/platform-detector.js.map +1 -1
- package/dist/utils/prompts.js +21 -34
- package/dist/utils/prompts.js.map +1 -1
- package/package.json +10 -5
package/dist/commands/init.js
CHANGED
|
@@ -1,158 +1,583 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
1
|
+
import { enableMCPIdentity } from "@kya-os/mcp-i";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { detectPlatform, getPlatformSpecificConfig, } from "../utils/platform-detector.js";
|
|
5
|
+
import { EnvManager } from "../utils/env-manager.js";
|
|
6
|
+
import { promptForInit, showSuccess, showError, showWarning, } from "../utils/prompts.js";
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { cliEffects } from "../effects/cli-integration.js";
|
|
10
|
+
async function checkRegistryHealth(verbose = false) {
|
|
11
|
+
const healthSpinner = ora("Checking registry status...").start();
|
|
12
|
+
try {
|
|
13
|
+
// Check the new health endpoint
|
|
14
|
+
const healthResponse = await fetch("https://knowthat.ai/api/agents/auto-register/health", {
|
|
15
|
+
method: "GET",
|
|
16
|
+
headers: {
|
|
17
|
+
"User-Agent": "kya-os-cli",
|
|
18
|
+
},
|
|
19
|
+
signal: AbortSignal.timeout(10000), // 10 second timeout
|
|
20
|
+
});
|
|
21
|
+
if (healthResponse.ok) {
|
|
22
|
+
const healthData = await healthResponse.json();
|
|
23
|
+
healthSpinner.succeed("Registry is operational");
|
|
24
|
+
if (verbose && healthData) {
|
|
25
|
+
console.log(chalk.gray(` Service status: ${healthData.status || "healthy"}`));
|
|
26
|
+
}
|
|
27
|
+
return { available: true, shouldProceed: true };
|
|
28
|
+
}
|
|
29
|
+
else if (healthResponse.status === 503) {
|
|
30
|
+
healthSpinner.fail("Registry is temporarily unavailable (maintenance mode)");
|
|
31
|
+
console.log(chalk.yellow("\nā ļø The registry is undergoing maintenance."));
|
|
32
|
+
console.log(chalk.yellow(" This usually takes 5-15 minutes."));
|
|
33
|
+
console.log(chalk.yellow("\nš§ Options:"));
|
|
34
|
+
console.log(" 1. Wait and try again in a few minutes");
|
|
35
|
+
console.log(" 2. Register manually at: https://knowthat.ai/submit-agent");
|
|
36
|
+
console.log(" 3. Create local config only (skip registration for now)");
|
|
37
|
+
return { available: false, shouldProceed: false };
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
healthSpinner.warn("Registry status unknown, proceeding with caution...");
|
|
41
|
+
return { available: false, shouldProceed: true };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error.name === "TimeoutError") {
|
|
46
|
+
healthSpinner.fail("Registry health check timed out");
|
|
47
|
+
console.log(chalk.yellow("\nā ļø Could not reach the registry (network timeout)."));
|
|
48
|
+
console.log(chalk.yellow(" Check your internet connection."));
|
|
49
|
+
}
|
|
50
|
+
else if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED") {
|
|
51
|
+
healthSpinner.fail("Registry is unreachable");
|
|
52
|
+
console.log(chalk.yellow("\nā ļø Cannot connect to knowthat.ai registry."));
|
|
53
|
+
console.log(chalk.yellow(" The service may be down or you may have network issues."));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
healthSpinner.warn("Could not check registry status, proceeding anyway...");
|
|
57
|
+
if (verbose) {
|
|
58
|
+
console.log(chalk.gray(` Error: ${error.message}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
console.log(chalk.yellow("\nš§ Alternatives:"));
|
|
62
|
+
console.log(" 1. Try again in a few minutes");
|
|
63
|
+
console.log(" 2. Register manually at: https://knowthat.ai/submit-agent");
|
|
64
|
+
console.log(" 3. Create local config only (we'll attempt registration anyway)");
|
|
65
|
+
return { available: false, shouldProceed: true };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function sleep(ms) {
|
|
69
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
70
|
+
}
|
|
71
|
+
async function attemptRegistrationWithRetry(config, verbose = false, maxRetries = 3) {
|
|
72
|
+
const baseDelay = 2000; // Start with 2 seconds
|
|
73
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
74
|
+
const isLastAttempt = attempt === maxRetries;
|
|
75
|
+
const spinner = ora(`Registering agent with knowthat.ai... (attempt ${attempt}/${maxRetries})`).start();
|
|
76
|
+
try {
|
|
77
|
+
const identity = await enableMCPIdentity(config);
|
|
78
|
+
spinner.succeed("Creating Agent ID");
|
|
79
|
+
return { success: true, identity };
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
spinner.fail(`Registration attempt ${attempt} failed`);
|
|
83
|
+
const errorInfo = categorizeError(error, verbose);
|
|
84
|
+
if (errorInfo.category === "CRITICAL" || isLastAttempt) {
|
|
85
|
+
// Don't retry for critical errors, or if this was the last attempt
|
|
86
|
+
handleRegistrationError(error, errorInfo, verbose, isLastAttempt);
|
|
87
|
+
return { success: false, error };
|
|
88
|
+
}
|
|
89
|
+
else if (errorInfo.category === "RETRYABLE") {
|
|
90
|
+
// Calculate exponential backoff delay
|
|
91
|
+
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
92
|
+
console.log(chalk.yellow(` ${errorInfo.message}`));
|
|
93
|
+
console.log(chalk.gray(` Retrying in ${delay / 1000} seconds...`));
|
|
94
|
+
if (attempt < maxRetries) {
|
|
95
|
+
await sleep(delay);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Unknown error - try once more but show the error
|
|
100
|
+
if (verbose) {
|
|
101
|
+
console.log(chalk.gray(` ${errorInfo.debugInfo}`));
|
|
102
|
+
}
|
|
103
|
+
console.log(chalk.yellow(` ${errorInfo.message}`));
|
|
104
|
+
if (attempt < maxRetries) {
|
|
105
|
+
console.log(chalk.gray(` Trying again...`));
|
|
106
|
+
await sleep(baseDelay);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { success: false };
|
|
112
|
+
}
|
|
113
|
+
function categorizeError(error, verbose = false) {
|
|
114
|
+
const errorMessage = error.message || "";
|
|
115
|
+
const status = error.response?.status || error.status;
|
|
116
|
+
const responseData = error.response?.data;
|
|
117
|
+
// Build debug info
|
|
118
|
+
let debugInfo = "";
|
|
119
|
+
if (verbose) {
|
|
120
|
+
debugInfo = `Error type: ${error.constructor.name}, Status: ${status}`;
|
|
121
|
+
if (responseData) {
|
|
122
|
+
debugInfo += `, Response: ${JSON.stringify(responseData, null, 2)}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Rate limiting
|
|
126
|
+
if (status === 429 ||
|
|
127
|
+
errorMessage.includes("429") ||
|
|
128
|
+
errorMessage.includes("rate limit")) {
|
|
129
|
+
return {
|
|
130
|
+
category: "RETRYABLE",
|
|
131
|
+
message: "Rate limit exceeded. The registry is busy.",
|
|
132
|
+
debugInfo,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Service temporarily unavailable
|
|
136
|
+
if (status === 503 || errorMessage.includes("503")) {
|
|
137
|
+
return {
|
|
138
|
+
category: "RETRYABLE",
|
|
139
|
+
message: "Registry is temporarily unavailable (maintenance or overload).",
|
|
140
|
+
debugInfo,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Server errors that might be transient
|
|
144
|
+
if (status === 500 ||
|
|
145
|
+
status === 502 ||
|
|
146
|
+
errorMessage.includes("500") ||
|
|
147
|
+
errorMessage.includes("502")) {
|
|
148
|
+
return {
|
|
149
|
+
category: "RETRYABLE",
|
|
150
|
+
message: "Registry server error. This may be temporary.",
|
|
151
|
+
debugInfo,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
// Timeout errors
|
|
155
|
+
if (error.name === "TimeoutError" || errorMessage.includes("timeout")) {
|
|
156
|
+
return {
|
|
157
|
+
category: "RETRYABLE",
|
|
158
|
+
message: "Request timed out. Network or server may be slow.",
|
|
159
|
+
debugInfo,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// Network errors
|
|
163
|
+
if (error.code === "ENOTFOUND" ||
|
|
164
|
+
error.code === "ECONNREFUSED" ||
|
|
165
|
+
errorMessage.includes("ENOTFOUND")) {
|
|
166
|
+
return {
|
|
167
|
+
category: "RETRYABLE",
|
|
168
|
+
message: "Cannot reach the registry. Check your internet connection.",
|
|
169
|
+
debugInfo,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// Client errors that shouldn't be retried
|
|
173
|
+
if (status >= 400 && status < 500 && status !== 429) {
|
|
174
|
+
return {
|
|
175
|
+
category: "CRITICAL",
|
|
176
|
+
message: `Registration was rejected by the registry (${status}).`,
|
|
177
|
+
debugInfo,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// MCP-I specific errors
|
|
181
|
+
if (errorMessage.includes("Failed to auto-register agent")) {
|
|
182
|
+
return {
|
|
183
|
+
category: "CRITICAL",
|
|
184
|
+
message: "The registry rejected the registration request.",
|
|
185
|
+
debugInfo,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// Unknown error
|
|
189
|
+
return {
|
|
190
|
+
category: "UNKNOWN",
|
|
191
|
+
message: errorMessage || "An unexpected error occurred during registration.",
|
|
192
|
+
debugInfo,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function handleRegistrationError(_error, errorInfo, verbose, isFinalAttempt) {
|
|
196
|
+
// Show main error message
|
|
197
|
+
showError(errorInfo.message);
|
|
198
|
+
// Show debug info if verbose
|
|
199
|
+
if (verbose && errorInfo.debugInfo) {
|
|
200
|
+
console.log(chalk.gray("\nDebug information:"));
|
|
201
|
+
console.log(chalk.gray(errorInfo.debugInfo));
|
|
202
|
+
}
|
|
203
|
+
// Show context-specific help
|
|
204
|
+
if (errorInfo.category === "CRITICAL") {
|
|
205
|
+
console.log(chalk.yellow("\nš§ This error cannot be resolved by retrying."));
|
|
206
|
+
console.log(chalk.yellow(" Possible solutions:"));
|
|
207
|
+
console.log(" 1. Register manually at: https://knowthat.ai/submit-agent");
|
|
208
|
+
console.log(" 2. Check if your agent name is already taken");
|
|
209
|
+
console.log(" 3. Verify your repository URL is accessible");
|
|
210
|
+
console.log(" 4. Contact support if the problem persists");
|
|
211
|
+
}
|
|
212
|
+
else if (isFinalAttempt) {
|
|
213
|
+
console.log(chalk.yellow("\nš§ Registration failed after multiple attempts."));
|
|
214
|
+
console.log(chalk.yellow(" Next steps:"));
|
|
215
|
+
console.log(" 1. Wait 5-10 minutes and try again");
|
|
216
|
+
console.log(" 2. Check knowthat.ai status page (if available)");
|
|
217
|
+
console.log(" 3. Register manually at: https://knowthat.ai/submit-agent");
|
|
218
|
+
console.log(" 4. Create local config only: npx kya-os init --skip-registration");
|
|
219
|
+
}
|
|
220
|
+
// Show alternative registration method
|
|
221
|
+
console.log(chalk.cyan("\nš Manual registration process:"));
|
|
222
|
+
console.log(" 1. Visit: https://knowthat.ai/submit-agent");
|
|
223
|
+
console.log(" 2. Fill in your agent details");
|
|
224
|
+
console.log(" 3. Get your DID and run: npx kya-os claim <your-agent-id>");
|
|
225
|
+
}
|
|
226
|
+
export async function init(options) {
|
|
16
227
|
try {
|
|
17
228
|
// Detect platform
|
|
18
|
-
const platformInfo =
|
|
19
|
-
console.log(
|
|
20
|
-
console.log(` Platform: ${
|
|
229
|
+
const platformInfo = detectPlatform();
|
|
230
|
+
console.log(chalk.cyan("\nš Detected environment:"));
|
|
231
|
+
console.log(` Platform: ${chalk.bold(platformInfo.platform)}`);
|
|
21
232
|
if (platformInfo.framework) {
|
|
22
|
-
console.log(` Framework: ${
|
|
233
|
+
console.log(` Framework: ${chalk.bold(platformInfo.framework)}`);
|
|
23
234
|
}
|
|
24
|
-
console.log(` Package Manager: ${
|
|
235
|
+
console.log(` Package Manager: ${chalk.bold(platformInfo.packageManager)}`);
|
|
25
236
|
// Check for existing configuration
|
|
26
|
-
const envManager = new
|
|
27
|
-
const existingIdentityFile =
|
|
237
|
+
const envManager = new EnvManager();
|
|
238
|
+
const existingIdentityFile = existsSync(join(process.cwd(), ".mcp-identity.json"));
|
|
28
239
|
const existingEnvVars = envManager.getFromProcess();
|
|
29
|
-
if ((existingIdentityFile || existingEnvVars.MCP_IDENTITY_DID) &&
|
|
30
|
-
|
|
31
|
-
|
|
240
|
+
if ((existingIdentityFile || existingEnvVars.MCP_IDENTITY_DID) &&
|
|
241
|
+
!options.force) {
|
|
242
|
+
showWarning("MCP-I is already configured in this project.");
|
|
243
|
+
console.log("Use --force to reconfigure.");
|
|
32
244
|
// Show current configuration
|
|
33
245
|
if (existingEnvVars.MCP_IDENTITY_DID) {
|
|
34
|
-
console.log(`\nCurrent DID: ${
|
|
246
|
+
console.log(`\nCurrent DID: ${chalk.green(existingEnvVars.MCP_IDENTITY_DID)}`);
|
|
35
247
|
}
|
|
36
248
|
return;
|
|
37
249
|
}
|
|
38
250
|
// Prompt for configuration
|
|
39
|
-
const answers = await
|
|
251
|
+
const answers = await promptForInit({
|
|
40
252
|
name: options.name,
|
|
41
253
|
description: options.description,
|
|
42
|
-
repository: options.repository
|
|
254
|
+
repository: options.repository,
|
|
43
255
|
});
|
|
44
256
|
// Determine directories configuration
|
|
45
257
|
let directories;
|
|
46
|
-
if (answers.directories ===
|
|
47
|
-
directories =
|
|
258
|
+
if (answers.directories === "verified") {
|
|
259
|
+
directories = "verified";
|
|
48
260
|
}
|
|
49
|
-
else if (answers.directories ===
|
|
50
|
-
directories =
|
|
261
|
+
else if (answers.directories === "none") {
|
|
262
|
+
directories = "none";
|
|
51
263
|
}
|
|
52
264
|
else {
|
|
53
265
|
directories = answers.specificDirectories || [];
|
|
54
266
|
}
|
|
55
267
|
// Get platform-specific config
|
|
56
|
-
const platformConfig =
|
|
268
|
+
const platformConfig = getPlatformSpecificConfig(platformInfo.platform);
|
|
57
269
|
let identity;
|
|
58
270
|
let envVars = null;
|
|
59
271
|
if (!options.skipRegistration && answers.confirmRegistration) {
|
|
60
|
-
//
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
272
|
+
// Check registry health first
|
|
273
|
+
const healthCheck = await checkRegistryHealth(options.verbose);
|
|
274
|
+
if (!healthCheck.available && !healthCheck.shouldProceed) {
|
|
275
|
+
console.log("\nYou can still create the configuration files and register later.");
|
|
276
|
+
answers.confirmEnvCreation = await promptForInit({
|
|
277
|
+
confirmEnvCreation: true,
|
|
278
|
+
}).then((a) => a.confirmEnvCreation);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// Register agent with retry logic
|
|
282
|
+
const registrationResult = await attemptRegistrationWithRetry({
|
|
64
283
|
name: answers.name,
|
|
65
284
|
description: answers.description,
|
|
66
285
|
repository: answers.repository,
|
|
67
286
|
directories: directories,
|
|
68
287
|
storage: platformConfig.storage,
|
|
69
288
|
transport: platformConfig.transport,
|
|
70
|
-
mode:
|
|
71
|
-
logLevel:
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
289
|
+
mode: "production",
|
|
290
|
+
logLevel: "silent",
|
|
291
|
+
}, options.verbose);
|
|
292
|
+
if (registrationResult.success && registrationResult.identity) {
|
|
293
|
+
identity = registrationResult.identity;
|
|
294
|
+
// Extract environment variables
|
|
295
|
+
envVars = {
|
|
296
|
+
MCP_IDENTITY_DID: identity.did,
|
|
297
|
+
MCP_IDENTITY_PUBLIC_KEY: identity.publicKey,
|
|
298
|
+
MCP_IDENTITY_PRIVATE_KEY: identity.privateKey || "",
|
|
299
|
+
MCP_IDENTITY_AGENT_ID: identity.agentId || "",
|
|
300
|
+
MCP_IDENTITY_AGENT_SLUG: identity.agentSlug || "",
|
|
301
|
+
};
|
|
302
|
+
// Clear some space for the effect
|
|
303
|
+
console.log("\n");
|
|
304
|
+
// Show DID generation with Blackhole effect
|
|
305
|
+
const didGenerationText = `š ${chalk.bold("Generating Decentralized Identity")}\n` +
|
|
306
|
+
`\n` +
|
|
307
|
+
`DID: ${chalk.green(identity.did)}`;
|
|
308
|
+
await cliEffects.showCustomEffect("blackhole", didGenerationText, {
|
|
309
|
+
config: {
|
|
310
|
+
duration: 5000, // Increased duration for smoother transition
|
|
311
|
+
blackholeColor: "ffffff",
|
|
312
|
+
starColors: [
|
|
313
|
+
"ffcc0d",
|
|
314
|
+
"ff7326",
|
|
315
|
+
"ff194d",
|
|
316
|
+
"bf2669",
|
|
317
|
+
"702a8c",
|
|
318
|
+
"049dbf",
|
|
319
|
+
],
|
|
320
|
+
finalColor: "00ff00",
|
|
321
|
+
useGradient: true,
|
|
322
|
+
gradientDirection: "diagonal",
|
|
323
|
+
blackholeSize: 0.3,
|
|
324
|
+
},
|
|
325
|
+
persistent: true, // Keep the DID visible after animation
|
|
326
|
+
skipExitPrompt: true, // Don't show "Press any key to exit"
|
|
327
|
+
});
|
|
328
|
+
// Get claim URL if available
|
|
329
|
+
let claimUrl = null;
|
|
330
|
+
try {
|
|
331
|
+
const result = await identity.requestEditAccess();
|
|
332
|
+
claimUrl = result.claimUrl;
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
// Ignore errors - claim URL is optional
|
|
336
|
+
}
|
|
337
|
+
// Wait a moment for the effect to finish and let the user see the DID
|
|
338
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
339
|
+
// Gentle fade by adding some spacing before clearing
|
|
340
|
+
console.log("\n\n\n");
|
|
341
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
342
|
+
// Clear screen and show elegant agent identity card
|
|
343
|
+
console.clear();
|
|
344
|
+
// Display elegant agent identity card
|
|
345
|
+
console.log("\n");
|
|
346
|
+
console.log(chalk.cyan("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"));
|
|
347
|
+
console.log(chalk.cyan("ā") +
|
|
348
|
+
chalk.bold.white(" š¤ AGENT IDENTITY CREATED ") +
|
|
349
|
+
chalk.cyan("ā"));
|
|
350
|
+
console.log(chalk.cyan("ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā£"));
|
|
351
|
+
console.log(chalk.cyan("ā ā"));
|
|
352
|
+
console.log(chalk.cyan("ā") +
|
|
353
|
+
chalk.bold(" Agent Name: ") +
|
|
354
|
+
chalk.yellow(answers.name.padEnd(57)) +
|
|
355
|
+
chalk.cyan("ā"));
|
|
356
|
+
console.log(chalk.cyan("ā") +
|
|
357
|
+
chalk.bold(" Description: ") +
|
|
358
|
+
chalk.gray((answers.description || "").substring(0, 56).padEnd(56)) +
|
|
359
|
+
chalk.cyan("ā"));
|
|
360
|
+
if (answers.description && answers.description.length > 56) {
|
|
361
|
+
console.log(chalk.cyan("ā") +
|
|
362
|
+
" " +
|
|
363
|
+
chalk.gray(answers.description.substring(56, 112).padEnd(55)) +
|
|
364
|
+
chalk.cyan("ā"));
|
|
365
|
+
}
|
|
366
|
+
console.log(chalk.cyan("ā ā"));
|
|
367
|
+
console.log(chalk.cyan("ā") +
|
|
368
|
+
chalk.bold(" DID: ") +
|
|
369
|
+
chalk.green(identity.did.substring(0, 64).padEnd(64)) +
|
|
370
|
+
chalk.cyan("ā"));
|
|
371
|
+
if (identity.did.length > 64) {
|
|
372
|
+
console.log(chalk.cyan("ā") +
|
|
373
|
+
" " +
|
|
374
|
+
chalk.green(identity.did.substring(64).padEnd(63)) +
|
|
375
|
+
chalk.cyan("ā"));
|
|
376
|
+
}
|
|
377
|
+
console.log(chalk.cyan("ā ā"));
|
|
378
|
+
console.log(chalk.cyan("ā") +
|
|
379
|
+
chalk.bold(" Profile: ") +
|
|
380
|
+
chalk.blue(`https://knowthat.ai/agents/${answers.name}`.padEnd(60)) +
|
|
381
|
+
chalk.cyan("ā"));
|
|
382
|
+
console.log(chalk.cyan("ā ā"));
|
|
383
|
+
console.log(chalk.cyan("ā") +
|
|
384
|
+
chalk.bold.red(" š PRIVATE KEY (KEEP SAFE!): ") +
|
|
385
|
+
" " +
|
|
386
|
+
chalk.cyan("ā"));
|
|
387
|
+
console.log(chalk.cyan("ā") +
|
|
388
|
+
" " +
|
|
389
|
+
chalk.red(envVars.MCP_IDENTITY_PRIVATE_KEY.substring(0, 60).padEnd(60)) +
|
|
390
|
+
" " +
|
|
391
|
+
chalk.cyan("ā"));
|
|
392
|
+
if (envVars.MCP_IDENTITY_PRIVATE_KEY.length > 60) {
|
|
393
|
+
console.log(chalk.cyan("ā") +
|
|
394
|
+
" " +
|
|
395
|
+
chalk.red(envVars.MCP_IDENTITY_PRIVATE_KEY.substring(60, 120).padEnd(60)) +
|
|
396
|
+
" " +
|
|
397
|
+
chalk.cyan("ā"));
|
|
398
|
+
}
|
|
399
|
+
if (envVars.MCP_IDENTITY_PRIVATE_KEY.length > 120) {
|
|
400
|
+
console.log(chalk.cyan("ā") +
|
|
401
|
+
" " +
|
|
402
|
+
chalk.red(envVars.MCP_IDENTITY_PRIVATE_KEY.substring(120).padEnd(60)) +
|
|
403
|
+
" " +
|
|
404
|
+
chalk.cyan("ā"));
|
|
405
|
+
}
|
|
406
|
+
console.log(chalk.cyan("ā") +
|
|
407
|
+
chalk.yellow(" ā ļø This key controls your agent - never share it!") +
|
|
408
|
+
" " +
|
|
409
|
+
chalk.cyan("ā"));
|
|
410
|
+
console.log(chalk.cyan("ā ā"));
|
|
88
411
|
if (claimUrl) {
|
|
89
|
-
console.log(
|
|
90
|
-
console.log(
|
|
91
|
-
console.log(
|
|
412
|
+
console.log(chalk.cyan("ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā£"));
|
|
413
|
+
console.log(chalk.cyan("ā ā"));
|
|
414
|
+
console.log(chalk.cyan("ā") +
|
|
415
|
+
chalk.bold.yellow(" šÆ CLAIM YOUR AGENT NOW: ") +
|
|
416
|
+
chalk.cyan("ā"));
|
|
417
|
+
console.log(chalk.cyan("ā ā"));
|
|
418
|
+
// Display the full URL without breaking to keep it clickable
|
|
419
|
+
console.log(chalk.cyan("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"));
|
|
420
|
+
console.log("");
|
|
421
|
+
console.log(chalk.bold.cyan("š Click to claim your agent:"));
|
|
422
|
+
console.log(chalk.cyan.underline(claimUrl));
|
|
423
|
+
console.log("");
|
|
424
|
+
console.log(chalk.cyan("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"));
|
|
425
|
+
console.log(chalk.cyan("ā ā"));
|
|
426
|
+
console.log(chalk.cyan("ā") +
|
|
427
|
+
chalk.gray(" This link lets you manage your agent and add capabilities. ") +
|
|
428
|
+
chalk.cyan("ā"));
|
|
429
|
+
console.log(chalk.cyan("ā ā"));
|
|
430
|
+
}
|
|
431
|
+
console.log(chalk.cyan("ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā£"));
|
|
432
|
+
console.log(chalk.cyan("ā ā"));
|
|
433
|
+
console.log(chalk.cyan("ā") +
|
|
434
|
+
chalk.bold.green(" ā
Agent successfully registered on the KYA-OS network ") +
|
|
435
|
+
chalk.cyan("ā"));
|
|
436
|
+
console.log(chalk.cyan("ā") +
|
|
437
|
+
chalk.gray(" Your AI agent now has a verifiable decentralized identity ") +
|
|
438
|
+
chalk.cyan("ā"));
|
|
439
|
+
console.log(chalk.cyan("ā ā"));
|
|
440
|
+
console.log(chalk.cyan("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"));
|
|
441
|
+
console.log("\n");
|
|
442
|
+
// Interactive prompt
|
|
443
|
+
if (claimUrl) {
|
|
444
|
+
console.log(chalk.yellow(" Press ENTER to open claim URL in browser, or 'x' to skip and continue..."));
|
|
445
|
+
// Wait for user input
|
|
446
|
+
const keypress = await new Promise((resolve) => {
|
|
447
|
+
import("readline").then((readline) => {
|
|
448
|
+
readline.emitKeypressEvents(process.stdin);
|
|
449
|
+
if (process.stdin.isTTY) {
|
|
450
|
+
process.stdin.setRawMode(true);
|
|
451
|
+
}
|
|
452
|
+
const handleKeypress = (str, key) => {
|
|
453
|
+
if (key && key.name === "return") {
|
|
454
|
+
resolve("enter");
|
|
455
|
+
}
|
|
456
|
+
else if (str === "x" || str === "X") {
|
|
457
|
+
resolve("x");
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
process.stdin.once("keypress", handleKeypress);
|
|
461
|
+
process.stdin.resume();
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
if (process.stdin.isTTY) {
|
|
465
|
+
process.stdin.setRawMode(false);
|
|
466
|
+
}
|
|
467
|
+
if (keypress === "enter") {
|
|
468
|
+
// Try to open URL in browser
|
|
469
|
+
try {
|
|
470
|
+
const open = (await import("open")).default;
|
|
471
|
+
await open(claimUrl);
|
|
472
|
+
console.log(chalk.green("\n ā Opening claim URL in your browser...\n"));
|
|
473
|
+
}
|
|
474
|
+
catch (err) {
|
|
475
|
+
console.log(chalk.gray("\n Could not open browser. Please visit the URL manually.\n"));
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
console.log(chalk.gray("\n You can claim your agent later using the URL above.\n"));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
// If no claim URL, just wait for any key
|
|
484
|
+
console.log(chalk.gray(" Press any key to continue..."));
|
|
485
|
+
await new Promise((resolve) => {
|
|
486
|
+
process.stdin.once("data", () => resolve(undefined));
|
|
487
|
+
process.stdin.resume();
|
|
488
|
+
});
|
|
92
489
|
}
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
// Claim URL might fail due to rate limiting
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
spinner.fail('Registration failed');
|
|
100
|
-
if (error.message?.includes('429')) {
|
|
101
|
-
(0, prompts_1.showError)('Rate limit exceeded. Please wait a few minutes and try again.');
|
|
102
|
-
}
|
|
103
|
-
else if (error.message?.includes('500')) {
|
|
104
|
-
(0, prompts_1.showError)('Server error. The registry might be temporarily down.');
|
|
105
490
|
}
|
|
106
491
|
else {
|
|
107
|
-
|
|
492
|
+
console.log("\nYou can still create the configuration files and register later.");
|
|
493
|
+
answers.confirmEnvCreation = await promptForInit({
|
|
494
|
+
confirmEnvCreation: true,
|
|
495
|
+
}).then((a) => a.confirmEnvCreation);
|
|
108
496
|
}
|
|
109
|
-
console.log('\nYou can still create the configuration files and register later.');
|
|
110
|
-
answers.confirmEnvCreation = await (0, prompts_1.promptForInit)({ confirmEnvCreation: true }).then(a => a.confirmEnvCreation);
|
|
111
497
|
}
|
|
112
498
|
}
|
|
113
499
|
// Create environment files
|
|
114
500
|
if (answers.confirmEnvCreation && envVars) {
|
|
115
|
-
console.log(`\nš ${
|
|
501
|
+
console.log(`\nš ${chalk.bold("Creating environment files...")}`);
|
|
116
502
|
try {
|
|
117
|
-
//
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
503
|
+
// Use smart insertion with best practices
|
|
504
|
+
const result = await envManager.smartInsertMcpVariables(envVars, {
|
|
505
|
+
force: options.force,
|
|
506
|
+
});
|
|
507
|
+
if (result.success) {
|
|
508
|
+
// Show operation result
|
|
509
|
+
const operation = result.operation === "created"
|
|
510
|
+
? "Created"
|
|
511
|
+
: result.operation === "updated"
|
|
512
|
+
? "Updated"
|
|
513
|
+
: "Replaced variables in";
|
|
514
|
+
console.log(` ā ${operation} ${chalk.green(result.targetFile)}`);
|
|
515
|
+
// Show warnings if any
|
|
516
|
+
if (result.warnings.length > 0) {
|
|
517
|
+
result.warnings.forEach((warning) => {
|
|
518
|
+
console.log(` ${chalk.yellow("ā ")} ${warning}`);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
// Show conflicts if any
|
|
522
|
+
if (result.conflicts && result.conflicts.length > 0) {
|
|
523
|
+
console.log(` ${chalk.yellow("ā ")} Found conflicting values in other files:`);
|
|
524
|
+
result.conflicts.forEach((conflict) => {
|
|
525
|
+
console.log(` ${conflict.file}: ${conflict.variable}="${conflict.value.substring(0, 20)}..."`);
|
|
526
|
+
});
|
|
527
|
+
console.log(` ${chalk.cyan("ā¹")} Using ${result.targetFile} as authoritative source`);
|
|
528
|
+
}
|
|
529
|
+
// Create backup file with actual values
|
|
530
|
+
const backupFile = `${result.targetFile}.backup`;
|
|
531
|
+
await envManager.updateEnvFile(backupFile, envVars, {
|
|
532
|
+
example: true,
|
|
533
|
+
});
|
|
534
|
+
console.log(` ā Created ${chalk.green(backupFile)} (backup copy)`);
|
|
535
|
+
// Check gitignore
|
|
536
|
+
const filesToIgnore = [
|
|
537
|
+
result.targetFile,
|
|
538
|
+
backupFile,
|
|
539
|
+
".mcp-identity.json",
|
|
540
|
+
// Also add common .env files to gitignore
|
|
541
|
+
".env",
|
|
542
|
+
".env.local",
|
|
543
|
+
".env.development",
|
|
544
|
+
".env.dev",
|
|
545
|
+
];
|
|
546
|
+
const { missing } = envManager.checkGitignore(filesToIgnore);
|
|
547
|
+
if (missing.length > 0) {
|
|
548
|
+
envManager.addToGitignore(missing);
|
|
549
|
+
console.log(` ā Added to ${chalk.green(".gitignore")}: ${missing.join(", ")}`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
showError(`Environment file setup failed: ${result.warnings.join(", ")}`);
|
|
130
554
|
}
|
|
131
555
|
}
|
|
132
556
|
catch (error) {
|
|
133
|
-
|
|
557
|
+
showError(`Failed to create environment files: ${error.message}`);
|
|
134
558
|
}
|
|
135
559
|
}
|
|
136
560
|
// Show next steps
|
|
137
|
-
console.log(`\nš ${
|
|
138
|
-
console.log(
|
|
139
|
-
console.log(` ${
|
|
140
|
-
console.log(
|
|
141
|
-
console.log(` ${
|
|
142
|
-
if (platformInfo.platform ===
|
|
143
|
-
|
|
144
|
-
console.log(
|
|
145
|
-
console.log(
|
|
146
|
-
console.log(
|
|
147
|
-
|
|
148
|
-
|
|
561
|
+
console.log(`\nš ${chalk.bold("Next Steps:")}`);
|
|
562
|
+
console.log("\n1. Install the MCP-I package:");
|
|
563
|
+
console.log(` ${chalk.cyan(`${platformInfo.packageManager} install @kya-os/mcp-i`)}`);
|
|
564
|
+
console.log("\n2. Add to your code:");
|
|
565
|
+
console.log(` ${chalk.cyan('import "@kya-os/mcp-i/auto"')}`);
|
|
566
|
+
if (platformInfo.platform === "vercel" ||
|
|
567
|
+
platformInfo.platform === "nextjs") {
|
|
568
|
+
console.log("\n3. For production deployment:");
|
|
569
|
+
console.log(" - Go to Vercel Dashboard ā Settings ā Environment Variables");
|
|
570
|
+
console.log(" - Add all MCP_IDENTITY_* variables from .env.local");
|
|
571
|
+
console.log(` - Run: ${chalk.cyan("npx kya-os env copy")} to copy them to clipboard`);
|
|
572
|
+
}
|
|
573
|
+
console.log(`\n${chalk.bold("Platform-specific notes:")}`);
|
|
149
574
|
platformConfig.instructions.forEach((instruction, i) => {
|
|
150
575
|
console.log(`${i + 1}. ${instruction}`);
|
|
151
576
|
});
|
|
152
|
-
|
|
577
|
+
showSuccess("MCP-I initialization complete!");
|
|
153
578
|
}
|
|
154
579
|
catch (error) {
|
|
155
|
-
|
|
580
|
+
showError(error.message || "Initialization failed");
|
|
156
581
|
process.exit(1);
|
|
157
582
|
}
|
|
158
583
|
}
|