@kya-os/cli 0.1.0-beta.8 ā 1.0.0-beta
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 +24 -26
- package/dist/commands/claim.d.ts.map +1 -1
- package/dist/commands/claim.js +29 -29
- package/dist/commands/claim.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +240 -212
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/rotate.d.ts.map +1 -1
- package/dist/commands/rotate.js +63 -52
- package/dist/commands/rotate.js.map +1 -1
- package/dist/components/agent-card.d.ts +14 -0
- package/dist/components/agent-card.d.ts.map +1 -0
- package/dist/components/agent-card.js +170 -0
- package/dist/components/agent-card.js.map +1 -0
- package/dist/components/agent-table.d.ts +20 -0
- package/dist/components/agent-table.d.ts.map +1 -0
- package/dist/components/agent-table.js +201 -0
- package/dist/components/agent-table.js.map +1 -0
- package/dist/components/box.d.ts +14 -0
- package/dist/components/box.d.ts.map +1 -0
- package/dist/components/box.js +222 -0
- package/dist/components/box.js.map +1 -0
- package/dist/components/index.d.ts +16 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +17 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/messages.d.ts +62 -0
- package/dist/components/messages.d.ts.map +1 -0
- package/dist/components/messages.js +146 -0
- package/dist/components/messages.js.map +1 -0
- package/dist/components/types.d.ts +51 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/types.js +5 -0
- package/dist/components/types.js.map +1 -0
- package/dist/components/welcome.d.ts +34 -0
- package/dist/components/welcome.d.ts.map +1 -0
- package/dist/components/welcome.js +115 -0
- package/dist/components/welcome.js.map +1 -0
- package/dist/effects/cli-integration.js +3 -3
- package/dist/effects/cli-integration.js.map +1 -1
- package/dist/effects/index.d.ts +9 -12
- package/dist/effects/index.d.ts.map +1 -1
- package/dist/effects/index.js +69 -34
- package/dist/effects/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -19
- 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 +381 -56
- package/dist/utils/env-manager.js.map +1 -1
- package/dist/utils/screen-manager.d.ts +10 -0
- package/dist/utils/screen-manager.d.ts.map +1 -0
- package/dist/utils/screen-manager.js +50 -0
- package/dist/utils/screen-manager.js.map +1 -0
- package/dist/utils/validation.d.ts +92 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +102 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +24 -9
- package/dist/commands/cli-experience-demo-simple.d.ts +0 -14
- package/dist/commands/cli-experience-demo-simple.d.ts.map +0 -1
- package/dist/commands/cli-experience-demo-simple.js +0 -119
- package/dist/commands/cli-experience-demo-simple.js.map +0 -1
- package/dist/commands/cli-experience-demo.d.ts +0 -14
- package/dist/commands/cli-experience-demo.d.ts.map +0 -1
- package/dist/commands/cli-experience-demo.js +0 -172
- package/dist/commands/cli-experience-demo.js.map +0 -1
- package/dist/commands/effects-demo.d.ts +0 -10
- package/dist/commands/effects-demo.d.ts.map +0 -1
- package/dist/commands/effects-demo.js +0 -292
- package/dist/commands/effects-demo.js.map +0 -1
- package/dist/dev.d.ts +0 -7
- package/dist/dev.d.ts.map +0 -1
- package/dist/dev.js +0 -9
- package/dist/dev.js.map +0 -1
- package/dist/effects/__tests__/effects.test.d.ts +0 -5
- package/dist/effects/__tests__/effects.test.d.ts.map +0 -1
- package/dist/effects/__tests__/effects.test.js +0 -206
- package/dist/effects/__tests__/effects.test.js.map +0 -1
- package/dist/effects/implementations/binary-path.d.ts +0 -88
- package/dist/effects/implementations/binary-path.d.ts.map +0 -1
- package/dist/effects/implementations/binary-path.js +0 -296
- package/dist/effects/implementations/binary-path.js.map +0 -1
- package/dist/effects/implementations/test.d.ts +0 -113
- package/dist/effects/implementations/test.d.ts.map +0 -1
- package/dist/effects/implementations/test.js +0 -552
- package/dist/effects/implementations/test.js.map +0 -1
- package/dist/effects/template/effect-template.d.ts +0 -97
- package/dist/effects/template/effect-template.d.ts.map +0 -1
- package/dist/effects/template/effect-template.js +0 -208
- package/dist/effects/template/effect-template.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/commands/init.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { enableMCPIdentityCLI } from "@kya-os/mcp-i/cli-internal";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import { detectPlatform, getPlatformSpecificConfig, } from "../utils/platform-detector.js";
|
|
5
5
|
import { EnvManager } from "../utils/env-manager.js";
|
|
6
|
-
import { promptForInit,
|
|
6
|
+
import { promptForInit, showError, showWarning, } from "../utils/prompts.js";
|
|
7
7
|
import { existsSync } from "fs";
|
|
8
8
|
import { join } from "path";
|
|
9
9
|
import { cliEffects } from "../effects/cli-integration.js";
|
|
10
|
+
import { createAgentTable, createClaimTable, createWelcomeBanner, createGradientBox, createSuccessBox } from "../components/index.js";
|
|
11
|
+
import { showScreen } from "../utils/screen-manager.js";
|
|
12
|
+
import { validateInput, initOptionsSchema } from "../utils/validation.js";
|
|
10
13
|
async function checkRegistryHealth(verbose = false) {
|
|
11
14
|
const healthSpinner = ora("Checking registry status...").start();
|
|
12
15
|
try {
|
|
@@ -68,15 +71,44 @@ async function checkRegistryHealth(verbose = false) {
|
|
|
68
71
|
async function sleep(ms) {
|
|
69
72
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
70
73
|
}
|
|
71
|
-
async function attemptRegistrationWithRetry(config, verbose = false, maxRetries = 3) {
|
|
74
|
+
async function attemptRegistrationWithRetry(config, verbose = false, maxRetries = 3, onProgress) {
|
|
72
75
|
const baseDelay = 2000; // Start with 2 seconds
|
|
73
76
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
74
77
|
const isLastAttempt = attempt === maxRetries;
|
|
75
|
-
const spinner = ora(`
|
|
78
|
+
const spinner = ora(`Connecting to KYA-OS network... (attempt ${attempt}/${maxRetries})`).start();
|
|
76
79
|
try {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
const result = await enableMCPIdentityCLI({
|
|
81
|
+
...config,
|
|
82
|
+
onProgress: async (event) => {
|
|
83
|
+
// Update spinner based on progress
|
|
84
|
+
switch (event.stage) {
|
|
85
|
+
case 'checking_existing':
|
|
86
|
+
spinner.text = 'Checking for existing identity...';
|
|
87
|
+
break;
|
|
88
|
+
case 'generating_keys':
|
|
89
|
+
spinner.text = 'Generating cryptographic keys...';
|
|
90
|
+
break;
|
|
91
|
+
case 'registering':
|
|
92
|
+
spinner.text = 'Registering with KYA-OS network...';
|
|
93
|
+
break;
|
|
94
|
+
case 'saving':
|
|
95
|
+
spinner.text = 'Saving identity...';
|
|
96
|
+
break;
|
|
97
|
+
case 'complete':
|
|
98
|
+
spinner.succeed('Agent registered successfully!');
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
// Call the provided callback if any
|
|
102
|
+
if (onProgress) {
|
|
103
|
+
await onProgress(event);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
success: true,
|
|
109
|
+
identity: result.identity,
|
|
110
|
+
metadata: result.metadata
|
|
111
|
+
};
|
|
80
112
|
}
|
|
81
113
|
catch (error) {
|
|
82
114
|
spinner.fail(`Registration attempt ${attempt} failed`);
|
|
@@ -225,6 +257,17 @@ function handleRegistrationError(_error, errorInfo, verbose, isFinalAttempt) {
|
|
|
225
257
|
}
|
|
226
258
|
export async function init(options) {
|
|
227
259
|
try {
|
|
260
|
+
// Validate options
|
|
261
|
+
const validatedOptions = validateInput(initOptionsSchema, options, "init options");
|
|
262
|
+
// Show welcome banner
|
|
263
|
+
try {
|
|
264
|
+
const banner = await createWelcomeBanner("KYA-OS");
|
|
265
|
+
console.log(banner);
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
// Fallback if figlet fails
|
|
269
|
+
console.log(chalk.cyan.bold("\nš MCP-I Initialization\n"));
|
|
270
|
+
}
|
|
228
271
|
// Detect platform
|
|
229
272
|
const platformInfo = detectPlatform();
|
|
230
273
|
console.log(chalk.cyan("\nš Detected environment:"));
|
|
@@ -238,7 +281,7 @@ export async function init(options) {
|
|
|
238
281
|
const existingIdentityFile = existsSync(join(process.cwd(), ".mcp-identity.json"));
|
|
239
282
|
const existingEnvVars = envManager.getFromProcess();
|
|
240
283
|
if ((existingIdentityFile || existingEnvVars.MCP_IDENTITY_DID) &&
|
|
241
|
-
!
|
|
284
|
+
!validatedOptions.force) {
|
|
242
285
|
showWarning("MCP-I is already configured in this project.");
|
|
243
286
|
console.log("Use --force to reconfigure.");
|
|
244
287
|
// Show current configuration
|
|
@@ -249,9 +292,9 @@ export async function init(options) {
|
|
|
249
292
|
}
|
|
250
293
|
// Prompt for configuration
|
|
251
294
|
const answers = await promptForInit({
|
|
252
|
-
name:
|
|
253
|
-
description:
|
|
254
|
-
repository:
|
|
295
|
+
name: validatedOptions.name,
|
|
296
|
+
description: validatedOptions.description,
|
|
297
|
+
repository: validatedOptions.repository,
|
|
255
298
|
});
|
|
256
299
|
// Determine directories configuration
|
|
257
300
|
let directories;
|
|
@@ -268,9 +311,9 @@ export async function init(options) {
|
|
|
268
311
|
const platformConfig = getPlatformSpecificConfig(platformInfo.platform);
|
|
269
312
|
let identity;
|
|
270
313
|
let envVars = null;
|
|
271
|
-
if (!
|
|
314
|
+
if (!validatedOptions.skipRegistration && answers.confirmRegistration) {
|
|
272
315
|
// Check registry health first
|
|
273
|
-
const healthCheck = await checkRegistryHealth(
|
|
316
|
+
const healthCheck = await checkRegistryHealth(validatedOptions.verbose);
|
|
274
317
|
if (!healthCheck.available && !healthCheck.shouldProceed) {
|
|
275
318
|
console.log("\nYou can still create the configuration files and register later.");
|
|
276
319
|
answers.confirmEnvCreation = await promptForInit({
|
|
@@ -278,19 +321,56 @@ export async function init(options) {
|
|
|
278
321
|
}).then((a) => a.confirmEnvCreation);
|
|
279
322
|
}
|
|
280
323
|
else {
|
|
281
|
-
// Register agent with retry logic
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
324
|
+
// Register agent with retry logic and enhanced error handling
|
|
325
|
+
let registrationResult;
|
|
326
|
+
try {
|
|
327
|
+
registrationResult = await attemptRegistrationWithRetry({
|
|
328
|
+
name: answers.name,
|
|
329
|
+
description: answers.description,
|
|
330
|
+
repository: answers.repository,
|
|
331
|
+
directories: directories,
|
|
332
|
+
storage: platformConfig.storage,
|
|
333
|
+
transport: platformConfig.transport,
|
|
334
|
+
mode: "production",
|
|
335
|
+
logLevel: "silent",
|
|
336
|
+
}, validatedOptions.verbose, 3, // maxRetries
|
|
337
|
+
async (event) => {
|
|
338
|
+
// Handle progress events for spinner updates
|
|
339
|
+
// The blackhole effect will be shown after successful registration
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
catch (registrationError) {
|
|
343
|
+
// Enhanced error handling for common scenarios
|
|
344
|
+
if (registrationError.message?.includes("already exists") ||
|
|
345
|
+
registrationError.message?.includes("name taken") ||
|
|
346
|
+
registrationError.response?.status === 409) {
|
|
347
|
+
showError("Agent name already exists in the registry.");
|
|
348
|
+
console.log(chalk.yellow("\nš This usually means:"));
|
|
349
|
+
console.log(" 1. You previously registered this agent name");
|
|
350
|
+
console.log(" 2. Your .env file was deleted/missing");
|
|
351
|
+
console.log(" 3. Someone else is using this name\n");
|
|
352
|
+
console.log(chalk.cyan("š” Solutions:"));
|
|
353
|
+
console.log(" 1. If this is YOUR agent, restore your .env file:");
|
|
354
|
+
console.log(` ${chalk.green('MCP_IDENTITY_DID="did:web:knowthat.ai:agents:' +
|
|
355
|
+
answers.name +
|
|
356
|
+
'"')}`);
|
|
357
|
+
console.log(` ${chalk.green('MCP_IDENTITY_PUBLIC_KEY="your-public-key"')}`);
|
|
358
|
+
console.log(` ${chalk.green('MCP_IDENTITY_PRIVATE_KEY="your-private-key"')}`);
|
|
359
|
+
console.log("\n 2. Or choose a different agent name");
|
|
360
|
+
console.log(` 3. Or visit: ${chalk.blue("https://knowthat.ai/agents/claim")}\n`);
|
|
361
|
+
process.exit(1);
|
|
362
|
+
}
|
|
363
|
+
// For other errors, show them and continue with config creation option
|
|
364
|
+
showError(`Registration failed: ${registrationError.message}`);
|
|
365
|
+
console.log("\nYou can still create the configuration files and register later.");
|
|
366
|
+
answers.confirmEnvCreation = await promptForInit({
|
|
367
|
+
confirmEnvCreation: true,
|
|
368
|
+
}).then((a) => a.confirmEnvCreation);
|
|
369
|
+
registrationResult = { success: false };
|
|
370
|
+
}
|
|
292
371
|
if (registrationResult.success && registrationResult.identity) {
|
|
293
372
|
identity = registrationResult.identity;
|
|
373
|
+
const metadata = registrationResult.metadata;
|
|
294
374
|
// Extract environment variables
|
|
295
375
|
envVars = {
|
|
296
376
|
MCP_IDENTITY_DID: identity.did,
|
|
@@ -299,218 +379,166 @@ export async function init(options) {
|
|
|
299
379
|
MCP_IDENTITY_AGENT_ID: identity.agentId || "",
|
|
300
380
|
MCP_IDENTITY_AGENT_SLUG: identity.agentSlug || "",
|
|
301
381
|
};
|
|
302
|
-
//
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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;
|
|
382
|
+
// Show blackhole effect for successful registrations
|
|
383
|
+
if (validatedOptions.verbose) {
|
|
384
|
+
console.log(chalk.gray(`[DEBUG] metadata.isNewIdentity: ${metadata?.isNewIdentity}`));
|
|
385
|
+
console.log(chalk.gray(`[DEBUG] Full metadata: ${JSON.stringify(metadata)}`));
|
|
333
386
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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);
|
|
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
|
-
}
|
|
387
|
+
// Always show effect for successful registrations
|
|
388
|
+
const shouldShowEffect = true;
|
|
389
|
+
if (shouldShowEffect && metadata?.did) {
|
|
390
|
+
// Clear some space for the effect
|
|
391
|
+
console.log("\n");
|
|
392
|
+
// Show DID generation with Blackhole effect
|
|
393
|
+
const didGenerationText = `š ${chalk.bold("Generating Decentralized Identity")}\n` +
|
|
394
|
+
`\n` +
|
|
395
|
+
`DID: ${chalk.green(metadata.did)}`;
|
|
396
|
+
await cliEffects.showCustomEffect("blackhole", didGenerationText, {
|
|
397
|
+
config: {
|
|
398
|
+
duration: 5000, // Increased duration for smoother transition
|
|
399
|
+
blackholeColor: "ffffff",
|
|
400
|
+
starColors: [
|
|
401
|
+
"ffcc0d",
|
|
402
|
+
"ff7326",
|
|
403
|
+
"ff194d",
|
|
404
|
+
"bf2669",
|
|
405
|
+
"702a8c",
|
|
406
|
+
"049dbf",
|
|
407
|
+
],
|
|
408
|
+
finalColor: "00ff00",
|
|
409
|
+
useGradient: true,
|
|
410
|
+
gradientDirection: "diagonal",
|
|
411
|
+
blackholeSize: 0.3,
|
|
412
|
+
},
|
|
413
|
+
persistent: true, // Keep the DID visible after animation
|
|
414
|
+
skipExitPrompt: true, // Don't show "Press any key to exit"
|
|
399
415
|
});
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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();
|
|
416
|
+
// Wait a moment for the effect to finish and let the user see the DID
|
|
417
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
418
|
+
// 1. Claim Your Agent screen (FIRST)
|
|
419
|
+
if (metadata?.claimUrl) {
|
|
420
|
+
await showScreen(createClaimTable({ claimUrl: metadata.claimUrl }), {
|
|
421
|
+
requireInput: true,
|
|
422
|
+
clearBefore: true,
|
|
423
|
+
prompt: "Press Enter to continue...",
|
|
431
424
|
});
|
|
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
425
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
426
|
+
// 2. Agent Identity Created screen (SECOND)
|
|
427
|
+
const agentTable = createAgentTable({
|
|
428
|
+
name: answers.name,
|
|
429
|
+
description: answers.description,
|
|
430
|
+
did: metadata?.did || envVars.MCP_IDENTITY_DID,
|
|
431
|
+
privateKey: envVars.MCP_IDENTITY_PRIVATE_KEY,
|
|
432
|
+
agentSlug: answers.name,
|
|
433
|
+
profileUrl: `https://knowthat.ai/agents/${answers.name}`,
|
|
434
|
+
});
|
|
435
|
+
await showScreen(agentTable, {
|
|
436
|
+
requireInput: true,
|
|
437
|
+
clearBefore: true,
|
|
438
|
+
prompt: "Press Enter to continue...",
|
|
457
439
|
});
|
|
458
440
|
}
|
|
459
441
|
}
|
|
460
|
-
else {
|
|
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);
|
|
465
|
-
}
|
|
466
442
|
}
|
|
467
443
|
}
|
|
468
444
|
// Create environment files
|
|
469
445
|
if (answers.confirmEnvCreation && envVars) {
|
|
470
446
|
console.log(`\nš ${chalk.bold("Creating environment files...")}`);
|
|
471
447
|
try {
|
|
472
|
-
//
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
force: options.force,
|
|
448
|
+
// Use smart insertion with best practices
|
|
449
|
+
const result = await envManager.smartInsertMcpVariables(envVars, {
|
|
450
|
+
force: validatedOptions.force,
|
|
476
451
|
});
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
452
|
+
if (result.success) {
|
|
453
|
+
// Show operation result
|
|
454
|
+
const operation = result.operation === "created"
|
|
455
|
+
? "Created"
|
|
456
|
+
: result.operation === "updated"
|
|
457
|
+
? "Updated"
|
|
458
|
+
: "Replaced variables in";
|
|
459
|
+
console.log(` ā ${operation} ${chalk.green(result.targetFile)}`);
|
|
460
|
+
// Show warnings if any
|
|
461
|
+
if (result.warnings.length > 0) {
|
|
462
|
+
result.warnings.forEach((warning) => {
|
|
463
|
+
console.log(` ${chalk.yellow("ā ")} ${warning}`);
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
// Show conflicts if any
|
|
467
|
+
if (result.conflicts && result.conflicts.length > 0) {
|
|
468
|
+
console.log(` ${chalk.yellow("ā ")} Found conflicting values in other files:`);
|
|
469
|
+
result.conflicts.forEach((conflict) => {
|
|
470
|
+
console.log(` ${conflict.file}: ${conflict.variable}="${conflict.value.substring(0, 20)}..."`);
|
|
471
|
+
});
|
|
472
|
+
console.log(` ${chalk.cyan("ā¹")} Using ${result.targetFile} as authoritative source`);
|
|
473
|
+
}
|
|
474
|
+
// Check gitignore
|
|
475
|
+
const filesToIgnore = [
|
|
476
|
+
result.targetFile,
|
|
477
|
+
".mcp-identity.json",
|
|
478
|
+
// Also add common .env files to gitignore
|
|
479
|
+
".env",
|
|
480
|
+
".env.local",
|
|
481
|
+
".env.development",
|
|
482
|
+
".env.dev",
|
|
483
|
+
];
|
|
484
|
+
const { missing } = envManager.checkGitignore(filesToIgnore);
|
|
485
|
+
if (missing.length > 0) {
|
|
486
|
+
envManager.addToGitignore(missing);
|
|
487
|
+
console.log(` ā Added to ${chalk.green(".gitignore")}: ${missing.join(", ")}`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
showError(`Environment file setup failed: ${result.warnings.join(", ")}`);
|
|
490
492
|
}
|
|
491
493
|
}
|
|
492
494
|
catch (error) {
|
|
493
495
|
showError(`Failed to create environment files: ${error.message}`);
|
|
494
496
|
}
|
|
495
497
|
}
|
|
496
|
-
//
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
498
|
+
// 3. Combined Environment Configuration & Success screen
|
|
499
|
+
const envConfigContent = [
|
|
500
|
+
"š Created files:",
|
|
501
|
+
"",
|
|
502
|
+
" ⢠.env.local (for local development)",
|
|
503
|
+
" ⢠Added to .gitignore automatically",
|
|
504
|
+
];
|
|
505
|
+
const combinedScreen = `${createGradientBox(envConfigContent, {
|
|
506
|
+
title: "Environment Configuration",
|
|
507
|
+
gradientStyle: "cool",
|
|
508
|
+
})}
|
|
509
|
+
|
|
510
|
+
${createSuccessBox("MCP-I initialization complete!", "Your AI agent now has a verifiable decentralized identity on the KYA-OS network.")}`;
|
|
511
|
+
await showScreen(combinedScreen, {
|
|
512
|
+
requireInput: true,
|
|
513
|
+
clearBefore: true,
|
|
514
|
+
prompt: "Press Enter to continue...",
|
|
515
|
+
});
|
|
516
|
+
// 4. Integration Guide (no rainbow colors)
|
|
517
|
+
const integrationContent = [
|
|
518
|
+
"š Next Steps:",
|
|
519
|
+
"",
|
|
520
|
+
"1. Install the MCP-I package:",
|
|
521
|
+
` ${chalk.cyan(`${platformInfo.packageManager} install @kya-os/mcp-i`)}`,
|
|
522
|
+
"",
|
|
523
|
+
"2. Add to your code:",
|
|
524
|
+
` ${chalk.cyan('import "@kya-os/mcp-i/auto"')}`,
|
|
525
|
+
"",
|
|
526
|
+
];
|
|
502
527
|
if (platformInfo.platform === "vercel" ||
|
|
503
528
|
platformInfo.platform === "nextjs") {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
529
|
+
integrationContent.push("3. For production deployment:", " ⢠Go to Vercel Dashboard ā Settings ā Environment Variables", " ⢠Add all MCP_IDENTITY_* variables from .env.local", ` ⢠Run: ${chalk.cyan("npx kya-os env copy")} to copy them to clipboard`, "");
|
|
530
|
+
}
|
|
531
|
+
// Add platform-specific instructions if any
|
|
532
|
+
if (platformConfig.instructions.length > 0) {
|
|
533
|
+
integrationContent.push(`${chalk.bold("Platform-specific notes:")}`, ...platformConfig.instructions.map((instruction, i) => `${i + 1}. ${instruction}`));
|
|
508
534
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
535
|
+
await showScreen(createGradientBox(integrationContent, {
|
|
536
|
+
title: "Integration Guide",
|
|
537
|
+
gradientStyle: "cool", // Changed from rainbow to cool
|
|
538
|
+
}), {
|
|
539
|
+
requireInput: false,
|
|
540
|
+
clearBefore: true,
|
|
512
541
|
});
|
|
513
|
-
showSuccess("MCP-I initialization complete!");
|
|
514
542
|
}
|
|
515
543
|
catch (error) {
|
|
516
544
|
showError(error.message || "Initialization failed");
|