@kya-os/cli 0.1.0-beta.6 → 0.1.0-beta.7
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 +262 -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 +4 -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,165 @@ 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: 4000,
|
|
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
|
+
});
|
|
327
|
+
// Get claim URL if available
|
|
328
|
+
let claimUrl = null;
|
|
295
329
|
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
|
-
}
|
|
330
|
+
const result = await identity.requestEditAccess();
|
|
331
|
+
claimUrl = result.claimUrl;
|
|
302
332
|
}
|
|
303
333
|
catch (error) {
|
|
304
|
-
|
|
305
|
-
|
|
334
|
+
// Ignore errors - claim URL is optional
|
|
335
|
+
}
|
|
336
|
+
// Wait a moment for the effect to finish
|
|
337
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
338
|
+
// Clear screen and show elegant agent identity card
|
|
339
|
+
console.clear();
|
|
340
|
+
// Display elegant agent identity card
|
|
341
|
+
console.log("\n");
|
|
342
|
+
console.log(chalk.cyan("╔═══════════════════════════════════════════════════════════════════════╗"));
|
|
343
|
+
console.log(chalk.cyan("║") + chalk.bold.white(" 🤖 AGENT IDENTITY CREATED ") + chalk.cyan("║"));
|
|
344
|
+
console.log(chalk.cyan("╠═══════════════════════════════════════════════════════════════════════╣"));
|
|
345
|
+
console.log(chalk.cyan("║ ║"));
|
|
346
|
+
console.log(chalk.cyan("║") + chalk.bold(" Agent Name: ") + chalk.yellow(answers.name.padEnd(57)) + chalk.cyan("║"));
|
|
347
|
+
console.log(chalk.cyan("║") + chalk.bold(" Description: ") + chalk.gray((answers.description || "").substring(0, 56).padEnd(56)) + chalk.cyan("║"));
|
|
348
|
+
if (answers.description && answers.description.length > 56) {
|
|
349
|
+
console.log(chalk.cyan("║") + " " + chalk.gray(answers.description.substring(56, 112).padEnd(55)) + chalk.cyan("║"));
|
|
350
|
+
}
|
|
351
|
+
console.log(chalk.cyan("║ ║"));
|
|
352
|
+
console.log(chalk.cyan("║") + chalk.bold(" DID: ") + chalk.green(identity.did.substring(0, 64).padEnd(64)) + chalk.cyan("║"));
|
|
353
|
+
if (identity.did.length > 64) {
|
|
354
|
+
console.log(chalk.cyan("║") + " " + chalk.green(identity.did.substring(64).padEnd(63)) + chalk.cyan("║"));
|
|
355
|
+
}
|
|
356
|
+
console.log(chalk.cyan("║ ║"));
|
|
357
|
+
console.log(chalk.cyan("║") + chalk.bold(" Profile: ") + chalk.blue(`https://knowthat.ai/agents/${envVars.MCP_IDENTITY_AGENT_SLUG}`.padEnd(60)) + chalk.cyan("║"));
|
|
358
|
+
console.log(chalk.cyan("║ ║"));
|
|
359
|
+
if (claimUrl) {
|
|
360
|
+
console.log(chalk.cyan("╠═══════════════════════════════════════════════════════════════════════╣"));
|
|
361
|
+
console.log(chalk.cyan("║ ║"));
|
|
362
|
+
console.log(chalk.cyan("║") + chalk.bold.yellow(" 🎯 CLAIM YOUR AGENT NOW: ") + chalk.cyan("║"));
|
|
363
|
+
console.log(chalk.cyan("║ ║"));
|
|
364
|
+
console.log(chalk.cyan("║") + " " + chalk.cyan.underline(claimUrl.substring(0, 68)) + " " + chalk.cyan("║"));
|
|
365
|
+
if (claimUrl.length > 68) {
|
|
366
|
+
console.log(chalk.cyan("║") + " " + chalk.cyan.underline(claimUrl.substring(68).padEnd(68)) + " " + chalk.cyan("║"));
|
|
306
367
|
}
|
|
368
|
+
console.log(chalk.cyan("║ ║"));
|
|
369
|
+
console.log(chalk.cyan("║") + chalk.gray(" This link lets you manage your agent and add capabilities. ") + chalk.cyan("║"));
|
|
370
|
+
console.log(chalk.cyan("║ ║"));
|
|
371
|
+
}
|
|
372
|
+
console.log(chalk.cyan("╠═══════════════════════════════════════════════════════════════════════╣"));
|
|
373
|
+
console.log(chalk.cyan("║ ║"));
|
|
374
|
+
console.log(chalk.cyan("║") + chalk.bold.green(" ✅ Agent successfully registered on the KYA-OS network ") + chalk.cyan("║"));
|
|
375
|
+
console.log(chalk.cyan("║") + chalk.gray(" Your AI agent now has a verifiable decentralized identity ") + chalk.cyan("║"));
|
|
376
|
+
console.log(chalk.cyan("║ ║"));
|
|
377
|
+
console.log(chalk.cyan("╚═══════════════════════════════════════════════════════════════════════╝"));
|
|
378
|
+
console.log("\n");
|
|
379
|
+
// Interactive prompt
|
|
380
|
+
if (claimUrl) {
|
|
381
|
+
console.log(chalk.yellow(" Press ENTER to open claim URL in browser, or 'x' to skip and continue..."));
|
|
382
|
+
// Wait for user input
|
|
383
|
+
const keypress = await new Promise((resolve) => {
|
|
384
|
+
const readline = require('readline');
|
|
385
|
+
readline.emitKeypressEvents(process.stdin);
|
|
386
|
+
if (process.stdin.isTTY) {
|
|
387
|
+
process.stdin.setRawMode(true);
|
|
388
|
+
}
|
|
389
|
+
const handleKeypress = (str, key) => {
|
|
390
|
+
if (key && key.name === 'return') {
|
|
391
|
+
resolve('enter');
|
|
392
|
+
}
|
|
393
|
+
else if (str === 'x' || str === 'X') {
|
|
394
|
+
resolve('x');
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
process.stdin.once('keypress', handleKeypress);
|
|
398
|
+
process.stdin.resume();
|
|
399
|
+
});
|
|
400
|
+
if (process.stdin.isTTY) {
|
|
401
|
+
process.stdin.setRawMode(false);
|
|
402
|
+
}
|
|
403
|
+
if (keypress === 'enter') {
|
|
404
|
+
// Try to open URL in browser
|
|
405
|
+
try {
|
|
406
|
+
const open = (await import('open')).default;
|
|
407
|
+
await open(claimUrl);
|
|
408
|
+
console.log(chalk.green("\n ✓ Opening claim URL in your browser...\n"));
|
|
409
|
+
}
|
|
410
|
+
catch (err) {
|
|
411
|
+
console.log(chalk.gray("\n Could not open browser. Please visit the URL manually.\n"));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
console.log(chalk.gray("\n You can claim your agent later using the URL above.\n"));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
// If no claim URL, just wait for any key
|
|
420
|
+
console.log(chalk.gray(" Press any key to continue..."));
|
|
421
|
+
await new Promise((resolve) => {
|
|
422
|
+
process.stdin.once('data', () => resolve(undefined));
|
|
423
|
+
process.stdin.resume();
|
|
424
|
+
});
|
|
307
425
|
}
|
|
308
426
|
}
|
|
309
427
|
else {
|
|
310
|
-
console.log(
|
|
311
|
-
answers.confirmEnvCreation = await promptForInit({
|
|
428
|
+
console.log("\nYou can still create the configuration files and register later.");
|
|
429
|
+
answers.confirmEnvCreation = await promptForInit({
|
|
430
|
+
confirmEnvCreation: true,
|
|
431
|
+
}).then((a) => a.confirmEnvCreation);
|
|
312
432
|
}
|
|
313
433
|
}
|
|
314
434
|
}
|
|
315
435
|
// Create environment files
|
|
316
436
|
if (answers.confirmEnvCreation && envVars) {
|
|
317
|
-
console.log(`\n📄 ${chalk.bold(
|
|
437
|
+
console.log(`\n📄 ${chalk.bold("Creating environment files...")}`);
|
|
318
438
|
try {
|
|
319
439
|
// Create actual env file
|
|
320
440
|
const envFile = platformConfig.envFile;
|
|
321
|
-
await envManager.createEnvFile(envFile, envVars, {
|
|
441
|
+
await envManager.createEnvFile(envFile, envVars, {
|
|
442
|
+
force: options.force,
|
|
443
|
+
});
|
|
322
444
|
console.log(` ✓ Created ${chalk.green(envFile)}`);
|
|
323
445
|
// Create example file
|
|
324
446
|
const exampleFile = `${envFile}.example`;
|
|
325
447
|
await envManager.createEnvFile(exampleFile, envVars, { example: true });
|
|
326
448
|
console.log(` ✓ Created ${chalk.green(exampleFile)}`);
|
|
327
449
|
// Check gitignore
|
|
328
|
-
const { missing } = envManager.checkGitignore([
|
|
450
|
+
const { missing } = envManager.checkGitignore([
|
|
451
|
+
envFile,
|
|
452
|
+
".mcp-identity.json",
|
|
453
|
+
]);
|
|
329
454
|
if (missing.length > 0) {
|
|
330
455
|
envManager.addToGitignore(missing);
|
|
331
|
-
console.log(` ✓ Added to ${chalk.green(
|
|
456
|
+
console.log(` ✓ Added to ${chalk.green(".gitignore")}: ${missing.join(", ")}`);
|
|
332
457
|
}
|
|
333
458
|
}
|
|
334
459
|
catch (error) {
|
|
@@ -336,25 +461,26 @@ export async function init(options) {
|
|
|
336
461
|
}
|
|
337
462
|
}
|
|
338
463
|
// Show next steps
|
|
339
|
-
console.log(`\n📋 ${chalk.bold(
|
|
340
|
-
console.log(
|
|
464
|
+
console.log(`\n📋 ${chalk.bold("Next Steps:")}`);
|
|
465
|
+
console.log("\n1. Install the MCP-I package:");
|
|
341
466
|
console.log(` ${chalk.cyan(`${platformInfo.packageManager} install @kya-os/mcp-i`)}`);
|
|
342
|
-
console.log(
|
|
467
|
+
console.log("\n2. Add to your code:");
|
|
343
468
|
console.log(` ${chalk.cyan('import "@kya-os/mcp-i/auto"')}`);
|
|
344
|
-
if (platformInfo.platform ===
|
|
345
|
-
|
|
346
|
-
console.log(
|
|
347
|
-
console.log(
|
|
348
|
-
console.log(
|
|
469
|
+
if (platformInfo.platform === "vercel" ||
|
|
470
|
+
platformInfo.platform === "nextjs") {
|
|
471
|
+
console.log("\n3. For production deployment:");
|
|
472
|
+
console.log(" - Go to Vercel Dashboard → Settings → Environment Variables");
|
|
473
|
+
console.log(" - Add all MCP_IDENTITY_* variables from .env.local");
|
|
474
|
+
console.log(` - Run: ${chalk.cyan("npx kya-os env copy")} to copy them to clipboard`);
|
|
349
475
|
}
|
|
350
|
-
console.log(`\n${chalk.bold(
|
|
476
|
+
console.log(`\n${chalk.bold("Platform-specific notes:")}`);
|
|
351
477
|
platformConfig.instructions.forEach((instruction, i) => {
|
|
352
478
|
console.log(`${i + 1}. ${instruction}`);
|
|
353
479
|
});
|
|
354
|
-
showSuccess(
|
|
480
|
+
showSuccess("MCP-I initialization complete!");
|
|
355
481
|
}
|
|
356
482
|
catch (error) {
|
|
357
|
-
showError(error.message ||
|
|
483
|
+
showError(error.message || "Initialization failed");
|
|
358
484
|
process.exit(1);
|
|
359
485
|
}
|
|
360
486
|
}
|