@kya-os/cli 0.1.0-beta.6 → 0.1.0-beta.8
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 +28 -6
- package/dist/commands/check.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 +12 -2
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +295 -136
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/rotate.d.ts.map +1 -1
- package/dist/commands/rotate.js +19 -3
- 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 +48 -42
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/dist/commands/init.js
CHANGED
|
@@ -1,71 +1,72 @@
|
|
|
1
|
-
import { enableMCPIdentity } from
|
|
2
|
-
import chalk from
|
|
3
|
-
import ora from
|
|
4
|
-
import { detectPlatform, getPlatformSpecificConfig } from
|
|
5
|
-
import { EnvManager } from
|
|
6
|
-
import { promptForInit, showSuccess, showError, showWarning } from
|
|
7
|
-
import { existsSync } from
|
|
8
|
-
import { join } from
|
|
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";
|
|
9
10
|
async function checkRegistryHealth(verbose = false) {
|
|
10
|
-
const healthSpinner = ora(
|
|
11
|
+
const healthSpinner = ora("Checking registry status...").start();
|
|
11
12
|
try {
|
|
12
13
|
// Check the new health endpoint
|
|
13
|
-
const healthResponse = await fetch(
|
|
14
|
-
method:
|
|
14
|
+
const healthResponse = await fetch("https://knowthat.ai/api/agents/auto-register/health", {
|
|
15
|
+
method: "GET",
|
|
15
16
|
headers: {
|
|
16
|
-
|
|
17
|
+
"User-Agent": "kya-os-cli",
|
|
17
18
|
},
|
|
18
|
-
signal: AbortSignal.timeout(10000) // 10 second timeout
|
|
19
|
+
signal: AbortSignal.timeout(10000), // 10 second timeout
|
|
19
20
|
});
|
|
20
21
|
if (healthResponse.ok) {
|
|
21
22
|
const healthData = await healthResponse.json();
|
|
22
|
-
healthSpinner.succeed(
|
|
23
|
+
healthSpinner.succeed("Registry is operational");
|
|
23
24
|
if (verbose && healthData) {
|
|
24
|
-
console.log(chalk.gray(` Service status: ${healthData.status ||
|
|
25
|
+
console.log(chalk.gray(` Service status: ${healthData.status || "healthy"}`));
|
|
25
26
|
}
|
|
26
27
|
return { available: true, shouldProceed: true };
|
|
27
28
|
}
|
|
28
29
|
else if (healthResponse.status === 503) {
|
|
29
|
-
healthSpinner.fail(
|
|
30
|
-
console.log(chalk.yellow(
|
|
31
|
-
console.log(chalk.yellow(
|
|
32
|
-
console.log(chalk.yellow(
|
|
33
|
-
console.log(
|
|
34
|
-
console.log(
|
|
35
|
-
console.log(
|
|
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)");
|
|
36
37
|
return { available: false, shouldProceed: false };
|
|
37
38
|
}
|
|
38
39
|
else {
|
|
39
|
-
healthSpinner.warn(
|
|
40
|
+
healthSpinner.warn("Registry status unknown, proceeding with caution...");
|
|
40
41
|
return { available: false, shouldProceed: true };
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
catch (error) {
|
|
44
|
-
if (error.name ===
|
|
45
|
-
healthSpinner.fail(
|
|
46
|
-
console.log(chalk.yellow(
|
|
47
|
-
console.log(chalk.yellow(
|
|
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."));
|
|
48
49
|
}
|
|
49
|
-
else if (error.code ===
|
|
50
|
-
healthSpinner.fail(
|
|
51
|
-
console.log(chalk.yellow(
|
|
52
|
-
console.log(chalk.yellow(
|
|
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."));
|
|
53
54
|
}
|
|
54
55
|
else {
|
|
55
|
-
healthSpinner.warn(
|
|
56
|
+
healthSpinner.warn("Could not check registry status, proceeding anyway...");
|
|
56
57
|
if (verbose) {
|
|
57
58
|
console.log(chalk.gray(` Error: ${error.message}`));
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
console.log(chalk.yellow(
|
|
61
|
-
console.log(
|
|
62
|
-
console.log(
|
|
63
|
-
console.log(
|
|
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)");
|
|
64
65
|
return { available: false, shouldProceed: true };
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
async function sleep(ms) {
|
|
68
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
69
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
69
70
|
}
|
|
70
71
|
async function attemptRegistrationWithRetry(config, verbose = false, maxRetries = 3) {
|
|
71
72
|
const baseDelay = 2000; // Start with 2 seconds
|
|
@@ -74,18 +75,18 @@ async function attemptRegistrationWithRetry(config, verbose = false, maxRetries
|
|
|
74
75
|
const spinner = ora(`Registering agent with knowthat.ai... (attempt ${attempt}/${maxRetries})`).start();
|
|
75
76
|
try {
|
|
76
77
|
const identity = await enableMCPIdentity(config);
|
|
77
|
-
spinner.succeed(
|
|
78
|
+
spinner.succeed("Creating Agent ID");
|
|
78
79
|
return { success: true, identity };
|
|
79
80
|
}
|
|
80
81
|
catch (error) {
|
|
81
82
|
spinner.fail(`Registration attempt ${attempt} failed`);
|
|
82
83
|
const errorInfo = categorizeError(error, verbose);
|
|
83
|
-
if (errorInfo.category ===
|
|
84
|
+
if (errorInfo.category === "CRITICAL" || isLastAttempt) {
|
|
84
85
|
// Don't retry for critical errors, or if this was the last attempt
|
|
85
86
|
handleRegistrationError(error, errorInfo, verbose, isLastAttempt);
|
|
86
87
|
return { success: false, error };
|
|
87
88
|
}
|
|
88
|
-
else if (errorInfo.category ===
|
|
89
|
+
else if (errorInfo.category === "RETRYABLE") {
|
|
89
90
|
// Calculate exponential backoff delay
|
|
90
91
|
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
91
92
|
console.log(chalk.yellow(` ${errorInfo.message}`));
|
|
@@ -110,11 +111,11 @@ async function attemptRegistrationWithRetry(config, verbose = false, maxRetries
|
|
|
110
111
|
return { success: false };
|
|
111
112
|
}
|
|
112
113
|
function categorizeError(error, verbose = false) {
|
|
113
|
-
const errorMessage = error.message ||
|
|
114
|
+
const errorMessage = error.message || "";
|
|
114
115
|
const status = error.response?.status || error.status;
|
|
115
116
|
const responseData = error.response?.data;
|
|
116
117
|
// Build debug info
|
|
117
|
-
let debugInfo =
|
|
118
|
+
let debugInfo = "";
|
|
118
119
|
if (verbose) {
|
|
119
120
|
debugInfo = `Error type: ${error.constructor.name}, Status: ${status}`;
|
|
120
121
|
if (responseData) {
|
|
@@ -122,66 +123,73 @@ function categorizeError(error, verbose = false) {
|
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
// Rate limiting
|
|
125
|
-
if (status === 429 ||
|
|
126
|
+
if (status === 429 ||
|
|
127
|
+
errorMessage.includes("429") ||
|
|
128
|
+
errorMessage.includes("rate limit")) {
|
|
126
129
|
return {
|
|
127
|
-
category:
|
|
128
|
-
message:
|
|
129
|
-
debugInfo
|
|
130
|
+
category: "RETRYABLE",
|
|
131
|
+
message: "Rate limit exceeded. The registry is busy.",
|
|
132
|
+
debugInfo,
|
|
130
133
|
};
|
|
131
134
|
}
|
|
132
|
-
// Service temporarily unavailable
|
|
133
|
-
if (status === 503 || errorMessage.includes(
|
|
135
|
+
// Service temporarily unavailable
|
|
136
|
+
if (status === 503 || errorMessage.includes("503")) {
|
|
134
137
|
return {
|
|
135
|
-
category:
|
|
136
|
-
message:
|
|
137
|
-
debugInfo
|
|
138
|
+
category: "RETRYABLE",
|
|
139
|
+
message: "Registry is temporarily unavailable (maintenance or overload).",
|
|
140
|
+
debugInfo,
|
|
138
141
|
};
|
|
139
142
|
}
|
|
140
143
|
// Server errors that might be transient
|
|
141
|
-
if (status === 500 ||
|
|
144
|
+
if (status === 500 ||
|
|
145
|
+
status === 502 ||
|
|
146
|
+
errorMessage.includes("500") ||
|
|
147
|
+
errorMessage.includes("502")) {
|
|
142
148
|
return {
|
|
143
|
-
category:
|
|
144
|
-
message:
|
|
145
|
-
debugInfo
|
|
149
|
+
category: "RETRYABLE",
|
|
150
|
+
message: "Registry server error. This may be temporary.",
|
|
151
|
+
debugInfo,
|
|
146
152
|
};
|
|
147
153
|
}
|
|
148
154
|
// Timeout errors
|
|
149
|
-
if (error.name ===
|
|
155
|
+
if (error.name === "TimeoutError" || errorMessage.includes("timeout")) {
|
|
150
156
|
return {
|
|
151
|
-
category:
|
|
152
|
-
message:
|
|
153
|
-
debugInfo
|
|
157
|
+
category: "RETRYABLE",
|
|
158
|
+
message: "Request timed out. Network or server may be slow.",
|
|
159
|
+
debugInfo,
|
|
154
160
|
};
|
|
155
161
|
}
|
|
156
162
|
// Network errors
|
|
157
|
-
if (error.code ===
|
|
163
|
+
if (error.code === "ENOTFOUND" ||
|
|
164
|
+
error.code === "ECONNREFUSED" ||
|
|
165
|
+
errorMessage.includes("ENOTFOUND")) {
|
|
158
166
|
return {
|
|
159
|
-
category:
|
|
160
|
-
message:
|
|
161
|
-
debugInfo
|
|
167
|
+
category: "RETRYABLE",
|
|
168
|
+
message: "Cannot reach the registry. Check your internet connection.",
|
|
169
|
+
debugInfo,
|
|
162
170
|
};
|
|
163
171
|
}
|
|
164
172
|
// Client errors that shouldn't be retried
|
|
165
173
|
if (status >= 400 && status < 500 && status !== 429) {
|
|
166
174
|
return {
|
|
167
|
-
category:
|
|
175
|
+
category: "CRITICAL",
|
|
168
176
|
message: `Registration was rejected by the registry (${status}).`,
|
|
169
|
-
debugInfo
|
|
177
|
+
debugInfo,
|
|
170
178
|
};
|
|
171
179
|
}
|
|
172
180
|
// MCP-I specific errors
|
|
173
|
-
if (errorMessage.includes(
|
|
181
|
+
if (errorMessage.includes("Failed to auto-register agent")) {
|
|
174
182
|
return {
|
|
175
|
-
category:
|
|
176
|
-
message:
|
|
177
|
-
debugInfo
|
|
183
|
+
category: "CRITICAL",
|
|
184
|
+
message: "The registry rejected the registration request.",
|
|
185
|
+
debugInfo,
|
|
178
186
|
};
|
|
179
187
|
}
|
|
180
188
|
// Unknown error
|
|
181
189
|
return {
|
|
182
|
-
category:
|
|
183
|
-
message: errorMessage ||
|
|
184
|
-
debugInfo
|
|
190
|
+
category: "UNKNOWN",
|
|
191
|
+
message: errorMessage || "An unexpected error occurred during registration.",
|
|
192
|
+
debugInfo,
|
|
185
193
|
};
|
|
186
194
|
}
|
|
187
195
|
function handleRegistrationError(_error, errorInfo, verbose, isFinalAttempt) {
|
|
@@ -189,37 +197,37 @@ function handleRegistrationError(_error, errorInfo, verbose, isFinalAttempt) {
|
|
|
189
197
|
showError(errorInfo.message);
|
|
190
198
|
// Show debug info if verbose
|
|
191
199
|
if (verbose && errorInfo.debugInfo) {
|
|
192
|
-
console.log(chalk.gray(
|
|
200
|
+
console.log(chalk.gray("\nDebug information:"));
|
|
193
201
|
console.log(chalk.gray(errorInfo.debugInfo));
|
|
194
202
|
}
|
|
195
203
|
// Show context-specific help
|
|
196
|
-
if (errorInfo.category ===
|
|
197
|
-
console.log(chalk.yellow(
|
|
198
|
-
console.log(chalk.yellow(
|
|
199
|
-
console.log(
|
|
200
|
-
console.log(
|
|
201
|
-
console.log(
|
|
202
|
-
console.log(
|
|
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");
|
|
203
211
|
}
|
|
204
212
|
else if (isFinalAttempt) {
|
|
205
|
-
console.log(chalk.yellow(
|
|
206
|
-
console.log(chalk.yellow(
|
|
207
|
-
console.log(
|
|
208
|
-
console.log(
|
|
209
|
-
console.log(
|
|
210
|
-
console.log(
|
|
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");
|
|
211
219
|
}
|
|
212
220
|
// Show alternative registration method
|
|
213
|
-
console.log(chalk.cyan(
|
|
214
|
-
console.log(
|
|
215
|
-
console.log(
|
|
216
|
-
console.log(
|
|
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>");
|
|
217
225
|
}
|
|
218
226
|
export async function init(options) {
|
|
219
227
|
try {
|
|
220
228
|
// Detect platform
|
|
221
229
|
const platformInfo = detectPlatform();
|
|
222
|
-
console.log(chalk.cyan(
|
|
230
|
+
console.log(chalk.cyan("\n🔍 Detected environment:"));
|
|
223
231
|
console.log(` Platform: ${chalk.bold(platformInfo.platform)}`);
|
|
224
232
|
if (platformInfo.framework) {
|
|
225
233
|
console.log(` Framework: ${chalk.bold(platformInfo.framework)}`);
|
|
@@ -227,11 +235,12 @@ export async function init(options) {
|
|
|
227
235
|
console.log(` Package Manager: ${chalk.bold(platformInfo.packageManager)}`);
|
|
228
236
|
// Check for existing configuration
|
|
229
237
|
const envManager = new EnvManager();
|
|
230
|
-
const existingIdentityFile = existsSync(join(process.cwd(),
|
|
238
|
+
const existingIdentityFile = existsSync(join(process.cwd(), ".mcp-identity.json"));
|
|
231
239
|
const existingEnvVars = envManager.getFromProcess();
|
|
232
|
-
if ((existingIdentityFile || existingEnvVars.MCP_IDENTITY_DID) &&
|
|
233
|
-
|
|
234
|
-
|
|
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.");
|
|
235
244
|
// Show current configuration
|
|
236
245
|
if (existingEnvVars.MCP_IDENTITY_DID) {
|
|
237
246
|
console.log(`\nCurrent DID: ${chalk.green(existingEnvVars.MCP_IDENTITY_DID)}`);
|
|
@@ -242,15 +251,15 @@ export async function init(options) {
|
|
|
242
251
|
const answers = await promptForInit({
|
|
243
252
|
name: options.name,
|
|
244
253
|
description: options.description,
|
|
245
|
-
repository: options.repository
|
|
254
|
+
repository: options.repository,
|
|
246
255
|
});
|
|
247
256
|
// Determine directories configuration
|
|
248
257
|
let directories;
|
|
249
|
-
if (answers.directories ===
|
|
250
|
-
directories =
|
|
258
|
+
if (answers.directories === "verified") {
|
|
259
|
+
directories = "verified";
|
|
251
260
|
}
|
|
252
|
-
else if (answers.directories ===
|
|
253
|
-
directories =
|
|
261
|
+
else if (answers.directories === "none") {
|
|
262
|
+
directories = "none";
|
|
254
263
|
}
|
|
255
264
|
else {
|
|
256
265
|
directories = answers.specificDirectories || [];
|
|
@@ -263,8 +272,10 @@ export async function init(options) {
|
|
|
263
272
|
// Check registry health first
|
|
264
273
|
const healthCheck = await checkRegistryHealth(options.verbose);
|
|
265
274
|
if (!healthCheck.available && !healthCheck.shouldProceed) {
|
|
266
|
-
console.log(
|
|
267
|
-
answers.confirmEnvCreation = await promptForInit({
|
|
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);
|
|
268
279
|
}
|
|
269
280
|
else {
|
|
270
281
|
// Register agent with retry logic
|
|
@@ -275,8 +286,8 @@ export async function init(options) {
|
|
|
275
286
|
directories: directories,
|
|
276
287
|
storage: platformConfig.storage,
|
|
277
288
|
transport: platformConfig.transport,
|
|
278
|
-
mode:
|
|
279
|
-
logLevel:
|
|
289
|
+
mode: "production",
|
|
290
|
+
logLevel: "silent",
|
|
280
291
|
}, options.verbose);
|
|
281
292
|
if (registrationResult.success && registrationResult.identity) {
|
|
282
293
|
identity = registrationResult.identity;
|
|
@@ -284,51 +295,198 @@ export async function init(options) {
|
|
|
284
295
|
envVars = {
|
|
285
296
|
MCP_IDENTITY_DID: identity.did,
|
|
286
297
|
MCP_IDENTITY_PUBLIC_KEY: identity.publicKey,
|
|
287
|
-
MCP_IDENTITY_PRIVATE_KEY: identity.privateKey ||
|
|
288
|
-
MCP_IDENTITY_AGENT_ID: identity.agentId ||
|
|
289
|
-
MCP_IDENTITY_AGENT_SLUG: identity.agentSlug ||
|
|
298
|
+
MCP_IDENTITY_PRIVATE_KEY: identity.privateKey || "",
|
|
299
|
+
MCP_IDENTITY_AGENT_ID: identity.agentId || "",
|
|
300
|
+
MCP_IDENTITY_AGENT_SLUG: identity.agentSlug || "",
|
|
290
301
|
};
|
|
291
|
-
|
|
292
|
-
console.log(
|
|
293
|
-
|
|
294
|
-
|
|
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;
|
|
295
330
|
try {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
console.log(`\n🎯 ${chalk.bold('Claim your agent:')}`);
|
|
299
|
-
console.log(` ${chalk.cyan(claimUrl)}`);
|
|
300
|
-
console.log(` ${chalk.gray('(This link lets you manage your agent)')}`);
|
|
301
|
-
}
|
|
331
|
+
const result = await identity.requestEditAccess();
|
|
332
|
+
claimUrl = result.claimUrl;
|
|
302
333
|
}
|
|
303
334
|
catch (error) {
|
|
304
|
-
|
|
305
|
-
|
|
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("║") + chalk.bold.white(" 🤖 AGENT IDENTITY CREATED ") + chalk.cyan("║"));
|
|
348
|
+
console.log(chalk.cyan("╠═══════════════════════════════════════════════════════════════════════╣"));
|
|
349
|
+
console.log(chalk.cyan("║ ║"));
|
|
350
|
+
console.log(chalk.cyan("║") + chalk.bold(" Agent Name: ") + chalk.yellow(answers.name.padEnd(57)) + chalk.cyan("║"));
|
|
351
|
+
console.log(chalk.cyan("║") + chalk.bold(" Description: ") + chalk.gray((answers.description || "").substring(0, 56).padEnd(56)) + chalk.cyan("║"));
|
|
352
|
+
if (answers.description && answers.description.length > 56) {
|
|
353
|
+
console.log(chalk.cyan("║") + " " + chalk.gray(answers.description.substring(56, 112).padEnd(55)) + chalk.cyan("║"));
|
|
354
|
+
}
|
|
355
|
+
console.log(chalk.cyan("║ ║"));
|
|
356
|
+
console.log(chalk.cyan("║") + chalk.bold(" DID: ") + chalk.green(identity.did.substring(0, 64).padEnd(64)) + chalk.cyan("║"));
|
|
357
|
+
if (identity.did.length > 64) {
|
|
358
|
+
console.log(chalk.cyan("║") + " " + chalk.green(identity.did.substring(64).padEnd(63)) + chalk.cyan("║"));
|
|
359
|
+
}
|
|
360
|
+
console.log(chalk.cyan("║ ║"));
|
|
361
|
+
console.log(chalk.cyan("║") + chalk.bold(" Profile: ") + chalk.blue(`https://knowthat.ai/agents/${envVars.MCP_IDENTITY_AGENT_SLUG}`.padEnd(60)) + chalk.cyan("║"));
|
|
362
|
+
console.log(chalk.cyan("║ ║"));
|
|
363
|
+
if (claimUrl) {
|
|
364
|
+
console.log(chalk.cyan("╠═══════════════════════════════════════════════════════════════════════╣"));
|
|
365
|
+
console.log(chalk.cyan("║ ║"));
|
|
366
|
+
console.log(chalk.cyan("║") + chalk.bold.yellow(" 🎯 CLAIM YOUR AGENT NOW: ") + chalk.cyan("║"));
|
|
367
|
+
console.log(chalk.cyan("║ ║"));
|
|
368
|
+
// Break URL into chunks that fit within the box
|
|
369
|
+
const maxUrlLength = 65; // Leave some padding
|
|
370
|
+
const urlChunks = [];
|
|
371
|
+
let remainingUrl = claimUrl;
|
|
372
|
+
while (remainingUrl.length > 0) {
|
|
373
|
+
if (remainingUrl.length <= maxUrlLength) {
|
|
374
|
+
urlChunks.push(remainingUrl);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
// Try to break at a good spot (& or %)
|
|
378
|
+
let breakPoint = maxUrlLength;
|
|
379
|
+
const lastAmpersand = remainingUrl.lastIndexOf('&', maxUrlLength);
|
|
380
|
+
const lastPercent = remainingUrl.lastIndexOf('%', maxUrlLength);
|
|
381
|
+
if (lastAmpersand > maxUrlLength * 0.7) {
|
|
382
|
+
breakPoint = lastAmpersand + 1;
|
|
383
|
+
}
|
|
384
|
+
else if (lastPercent > maxUrlLength * 0.7) {
|
|
385
|
+
breakPoint = lastPercent + 3; // Include %XX
|
|
386
|
+
}
|
|
387
|
+
urlChunks.push(remainingUrl.substring(0, breakPoint));
|
|
388
|
+
remainingUrl = remainingUrl.substring(breakPoint);
|
|
306
389
|
}
|
|
390
|
+
// Display URL chunks
|
|
391
|
+
urlChunks.forEach((chunk, index) => {
|
|
392
|
+
const paddedChunk = chunk.padEnd(68);
|
|
393
|
+
if (index === 0) {
|
|
394
|
+
console.log(chalk.cyan("║") + " " + chalk.cyan.underline(paddedChunk) + " " + chalk.cyan("║"));
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
console.log(chalk.cyan("║") + " " + chalk.cyan.underline(paddedChunk.substring(0, 66)) + " " + chalk.cyan("║"));
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
console.log(chalk.cyan("║ ║"));
|
|
401
|
+
console.log(chalk.cyan("║") + chalk.gray(" This link lets you manage your agent and add capabilities. ") + chalk.cyan("║"));
|
|
402
|
+
console.log(chalk.cyan("║ ║"));
|
|
403
|
+
}
|
|
404
|
+
console.log(chalk.cyan("╠═══════════════════════════════════════════════════════════════════════╣"));
|
|
405
|
+
console.log(chalk.cyan("║ ║"));
|
|
406
|
+
console.log(chalk.cyan("║") + chalk.bold.green(" ✅ Agent successfully registered on the KYA-OS network ") + chalk.cyan("║"));
|
|
407
|
+
console.log(chalk.cyan("║") + chalk.gray(" Your AI agent now has a verifiable decentralized identity ") + chalk.cyan("║"));
|
|
408
|
+
console.log(chalk.cyan("║ ║"));
|
|
409
|
+
console.log(chalk.cyan("╚═══════════════════════════════════════════════════════════════════════╝"));
|
|
410
|
+
console.log("\n");
|
|
411
|
+
// Interactive prompt
|
|
412
|
+
if (claimUrl) {
|
|
413
|
+
console.log(chalk.yellow(" Press ENTER to open claim URL in browser, or 'x' to skip and continue..."));
|
|
414
|
+
// Wait for user input
|
|
415
|
+
const keypress = await new Promise((resolve) => {
|
|
416
|
+
import('readline').then((readline) => {
|
|
417
|
+
readline.emitKeypressEvents(process.stdin);
|
|
418
|
+
if (process.stdin.isTTY) {
|
|
419
|
+
process.stdin.setRawMode(true);
|
|
420
|
+
}
|
|
421
|
+
const handleKeypress = (str, key) => {
|
|
422
|
+
if (key && key.name === 'return') {
|
|
423
|
+
resolve('enter');
|
|
424
|
+
}
|
|
425
|
+
else if (str === 'x' || str === 'X') {
|
|
426
|
+
resolve('x');
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
process.stdin.once('keypress', handleKeypress);
|
|
430
|
+
process.stdin.resume();
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
if (process.stdin.isTTY) {
|
|
434
|
+
process.stdin.setRawMode(false);
|
|
435
|
+
}
|
|
436
|
+
if (keypress === 'enter') {
|
|
437
|
+
// Try to open URL in browser
|
|
438
|
+
try {
|
|
439
|
+
const open = (await import('open')).default;
|
|
440
|
+
await open(claimUrl);
|
|
441
|
+
console.log(chalk.green("\n ✓ Opening claim URL in your browser...\n"));
|
|
442
|
+
}
|
|
443
|
+
catch (err) {
|
|
444
|
+
console.log(chalk.gray("\n Could not open browser. Please visit the URL manually.\n"));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
console.log(chalk.gray("\n You can claim your agent later using the URL above.\n"));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
// If no claim URL, just wait for any key
|
|
453
|
+
console.log(chalk.gray(" Press any key to continue..."));
|
|
454
|
+
await new Promise((resolve) => {
|
|
455
|
+
process.stdin.once('data', () => resolve(undefined));
|
|
456
|
+
process.stdin.resume();
|
|
457
|
+
});
|
|
307
458
|
}
|
|
308
459
|
}
|
|
309
460
|
else {
|
|
310
|
-
console.log(
|
|
311
|
-
answers.confirmEnvCreation = await promptForInit({
|
|
461
|
+
console.log("\nYou can still create the configuration files and register later.");
|
|
462
|
+
answers.confirmEnvCreation = await promptForInit({
|
|
463
|
+
confirmEnvCreation: true,
|
|
464
|
+
}).then((a) => a.confirmEnvCreation);
|
|
312
465
|
}
|
|
313
466
|
}
|
|
314
467
|
}
|
|
315
468
|
// Create environment files
|
|
316
469
|
if (answers.confirmEnvCreation && envVars) {
|
|
317
|
-
console.log(`\n📄 ${chalk.bold(
|
|
470
|
+
console.log(`\n📄 ${chalk.bold("Creating environment files...")}`);
|
|
318
471
|
try {
|
|
319
472
|
// Create actual env file
|
|
320
473
|
const envFile = platformConfig.envFile;
|
|
321
|
-
await envManager.createEnvFile(envFile, envVars, {
|
|
474
|
+
await envManager.createEnvFile(envFile, envVars, {
|
|
475
|
+
force: options.force,
|
|
476
|
+
});
|
|
322
477
|
console.log(` ✓ Created ${chalk.green(envFile)}`);
|
|
323
478
|
// Create example file
|
|
324
479
|
const exampleFile = `${envFile}.example`;
|
|
325
480
|
await envManager.createEnvFile(exampleFile, envVars, { example: true });
|
|
326
481
|
console.log(` ✓ Created ${chalk.green(exampleFile)}`);
|
|
327
482
|
// Check gitignore
|
|
328
|
-
const { missing } = envManager.checkGitignore([
|
|
483
|
+
const { missing } = envManager.checkGitignore([
|
|
484
|
+
envFile,
|
|
485
|
+
".mcp-identity.json",
|
|
486
|
+
]);
|
|
329
487
|
if (missing.length > 0) {
|
|
330
488
|
envManager.addToGitignore(missing);
|
|
331
|
-
console.log(` ✓ Added to ${chalk.green(
|
|
489
|
+
console.log(` ✓ Added to ${chalk.green(".gitignore")}: ${missing.join(", ")}`);
|
|
332
490
|
}
|
|
333
491
|
}
|
|
334
492
|
catch (error) {
|
|
@@ -336,25 +494,26 @@ export async function init(options) {
|
|
|
336
494
|
}
|
|
337
495
|
}
|
|
338
496
|
// Show next steps
|
|
339
|
-
console.log(`\n📋 ${chalk.bold(
|
|
340
|
-
console.log(
|
|
497
|
+
console.log(`\n📋 ${chalk.bold("Next Steps:")}`);
|
|
498
|
+
console.log("\n1. Install the MCP-I package:");
|
|
341
499
|
console.log(` ${chalk.cyan(`${platformInfo.packageManager} install @kya-os/mcp-i`)}`);
|
|
342
|
-
console.log(
|
|
500
|
+
console.log("\n2. Add to your code:");
|
|
343
501
|
console.log(` ${chalk.cyan('import "@kya-os/mcp-i/auto"')}`);
|
|
344
|
-
if (platformInfo.platform ===
|
|
345
|
-
|
|
346
|
-
console.log(
|
|
347
|
-
console.log(
|
|
348
|
-
console.log(
|
|
502
|
+
if (platformInfo.platform === "vercel" ||
|
|
503
|
+
platformInfo.platform === "nextjs") {
|
|
504
|
+
console.log("\n3. For production deployment:");
|
|
505
|
+
console.log(" - Go to Vercel Dashboard → Settings → Environment Variables");
|
|
506
|
+
console.log(" - Add all MCP_IDENTITY_* variables from .env.local");
|
|
507
|
+
console.log(` - Run: ${chalk.cyan("npx kya-os env copy")} to copy them to clipboard`);
|
|
349
508
|
}
|
|
350
|
-
console.log(`\n${chalk.bold(
|
|
509
|
+
console.log(`\n${chalk.bold("Platform-specific notes:")}`);
|
|
351
510
|
platformConfig.instructions.forEach((instruction, i) => {
|
|
352
511
|
console.log(`${i + 1}. ${instruction}`);
|
|
353
512
|
});
|
|
354
|
-
showSuccess(
|
|
513
|
+
showSuccess("MCP-I initialization complete!");
|
|
355
514
|
}
|
|
356
515
|
catch (error) {
|
|
357
|
-
showError(error.message ||
|
|
516
|
+
showError(error.message || "Initialization failed");
|
|
358
517
|
process.exit(1);
|
|
359
518
|
}
|
|
360
519
|
}
|