@kya-os/cli 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/commands/build.d.ts +5 -0
  2. package/dist/commands/build.d.ts.map +1 -0
  3. package/dist/commands/build.js +173 -0
  4. package/dist/commands/build.js.map +1 -0
  5. package/dist/commands/check.d.ts.map +1 -1
  6. package/dist/commands/check.js +9 -31
  7. package/dist/commands/check.js.map +1 -1
  8. package/dist/commands/claim.d.ts +7 -1
  9. package/dist/commands/claim.d.ts.map +1 -1
  10. package/dist/commands/claim.js +196 -44
  11. package/dist/commands/claim.js.map +1 -1
  12. package/dist/commands/demo.d.ts +10 -0
  13. package/dist/commands/demo.d.ts.map +1 -0
  14. package/dist/commands/demo.js +584 -0
  15. package/dist/commands/demo.js.map +1 -0
  16. package/dist/commands/dev.d.ts +5 -0
  17. package/dist/commands/dev.d.ts.map +1 -0
  18. package/dist/commands/dev.js +111 -0
  19. package/dist/commands/dev.js.map +1 -0
  20. package/dist/commands/doctor.d.ts +11 -0
  21. package/dist/commands/doctor.d.ts.map +1 -0
  22. package/dist/commands/doctor.js +530 -0
  23. package/dist/commands/doctor.js.map +1 -0
  24. package/dist/commands/env.d.ts +1 -1
  25. package/dist/commands/env.d.ts.map +1 -1
  26. package/dist/commands/env.js +113 -15
  27. package/dist/commands/env.js.map +1 -1
  28. package/dist/commands/identity.d.ts +14 -0
  29. package/dist/commands/identity.d.ts.map +1 -0
  30. package/dist/commands/identity.js +204 -0
  31. package/dist/commands/identity.js.map +1 -0
  32. package/dist/commands/init.d.ts +6 -2
  33. package/dist/commands/init.d.ts.map +1 -1
  34. package/dist/commands/init.js +86 -670
  35. package/dist/commands/init.js.map +1 -1
  36. package/dist/commands/receipts.d.ts +11 -0
  37. package/dist/commands/receipts.d.ts.map +1 -0
  38. package/dist/commands/receipts.js +179 -0
  39. package/dist/commands/receipts.js.map +1 -0
  40. package/dist/commands/register.d.ts +15 -0
  41. package/dist/commands/register.d.ts.map +1 -0
  42. package/dist/commands/register.js +220 -0
  43. package/dist/commands/register.js.map +1 -0
  44. package/dist/commands/rotate.d.ts +7 -1
  45. package/dist/commands/rotate.d.ts.map +1 -1
  46. package/dist/commands/rotate.js +149 -109
  47. package/dist/commands/rotate.js.map +1 -1
  48. package/dist/commands/start.d.ts +5 -0
  49. package/dist/commands/start.d.ts.map +1 -0
  50. package/dist/commands/start.js +129 -0
  51. package/dist/commands/start.js.map +1 -0
  52. package/dist/commands/status.d.ts +9 -0
  53. package/dist/commands/status.d.ts.map +1 -0
  54. package/dist/commands/status.js +177 -0
  55. package/dist/commands/status.js.map +1 -0
  56. package/dist/commands/verify.d.ts +22 -0
  57. package/dist/commands/verify.d.ts.map +1 -0
  58. package/dist/commands/verify.js +491 -0
  59. package/dist/commands/verify.js.map +1 -0
  60. package/dist/components/claim-experience.d.ts +21 -0
  61. package/dist/components/claim-experience.d.ts.map +1 -0
  62. package/dist/components/claim-experience.js +138 -0
  63. package/dist/components/claim-experience.js.map +1 -0
  64. package/dist/effects/animation-engine.d.ts +173 -0
  65. package/dist/effects/animation-engine.d.ts.map +1 -0
  66. package/dist/effects/animation-engine.js +254 -0
  67. package/dist/effects/animation-engine.js.map +1 -0
  68. package/dist/effects/cli-integration.js +8 -8
  69. package/dist/effects/cli-integration.js.map +1 -1
  70. package/dist/effects/config.d.ts +86 -10
  71. package/dist/effects/config.d.ts.map +1 -1
  72. package/dist/effects/config.js +201 -18
  73. package/dist/effects/config.js.map +1 -1
  74. package/dist/effects/effect-runner.d.ts +69 -0
  75. package/dist/effects/effect-runner.d.ts.map +1 -0
  76. package/dist/effects/effect-runner.js +255 -0
  77. package/dist/effects/effect-runner.js.map +1 -0
  78. package/dist/effects/gradient.d.ts +131 -0
  79. package/dist/effects/gradient.d.ts.map +1 -0
  80. package/dist/effects/gradient.js +236 -0
  81. package/dist/effects/gradient.js.map +1 -0
  82. package/dist/effects/implementations/beams.d.ts +80 -0
  83. package/dist/effects/implementations/beams.d.ts.map +1 -0
  84. package/dist/effects/implementations/beams.js +221 -0
  85. package/dist/effects/implementations/beams.js.map +1 -0
  86. package/dist/effects/implementations/blackhole.d.ts +98 -0
  87. package/dist/effects/implementations/blackhole.d.ts.map +1 -0
  88. package/dist/effects/implementations/blackhole.js +421 -0
  89. package/dist/effects/implementations/blackhole.js.map +1 -0
  90. package/dist/effects/implementations/burn.d.ts +74 -0
  91. package/dist/effects/implementations/burn.d.ts.map +1 -0
  92. package/dist/effects/implementations/burn.js +234 -0
  93. package/dist/effects/implementations/burn.js.map +1 -0
  94. package/dist/effects/implementations/decrypt.d.ts +115 -0
  95. package/dist/effects/implementations/decrypt.d.ts.map +1 -0
  96. package/dist/effects/implementations/decrypt.js +394 -0
  97. package/dist/effects/implementations/decrypt.js.map +1 -0
  98. package/dist/effects/implementations/waves.d.ts +78 -0
  99. package/dist/effects/implementations/waves.d.ts.map +1 -0
  100. package/dist/effects/implementations/waves.js +278 -0
  101. package/dist/effects/implementations/waves.js.map +1 -0
  102. package/dist/effects/index.d.ts +34 -0
  103. package/dist/effects/index.d.ts.map +1 -0
  104. package/dist/effects/index.js +114 -0
  105. package/dist/effects/index.js.map +1 -0
  106. package/dist/effects/motion-engine.d.ts +168 -0
  107. package/dist/effects/motion-engine.d.ts.map +1 -0
  108. package/dist/effects/motion-engine.js +353 -0
  109. package/dist/effects/motion-engine.js.map +1 -0
  110. package/dist/effects/safe-executor.d.ts +55 -0
  111. package/dist/effects/safe-executor.d.ts.map +1 -0
  112. package/dist/effects/safe-executor.js +210 -0
  113. package/dist/effects/safe-executor.js.map +1 -0
  114. package/dist/effects/types.d.ts +199 -0
  115. package/dist/effects/types.d.ts.map +1 -0
  116. package/dist/effects/types.js +80 -0
  117. package/dist/effects/types.js.map +1 -0
  118. package/dist/effects/utils.d.ts +104 -0
  119. package/dist/effects/utils.d.ts.map +1 -0
  120. package/dist/effects/utils.js +280 -0
  121. package/dist/effects/utils.js.map +1 -0
  122. package/dist/index.js +154 -19
  123. package/dist/utils/env-manager.d.ts +6 -7
  124. package/dist/utils/env-manager.d.ts.map +1 -1
  125. package/dist/utils/env-manager.js +52 -40
  126. package/dist/utils/env-manager.js.map +1 -1
  127. package/dist/utils/identity-manager.d.ts +41 -0
  128. package/dist/utils/identity-manager.d.ts.map +1 -0
  129. package/dist/utils/identity-manager.js +159 -0
  130. package/dist/utils/identity-manager.js.map +1 -0
  131. package/dist/utils/kta-api.d.ts +67 -0
  132. package/dist/utils/kta-api.d.ts.map +1 -0
  133. package/dist/utils/kta-api.js +137 -0
  134. package/dist/utils/kta-api.js.map +1 -0
  135. package/package.json +8 -7
  136. package/dist/utils/validation.d.ts +0 -101
  137. package/dist/utils/validation.d.ts.map +0 -1
  138. package/dist/utils/validation.js +0 -109
  139. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1,111 @@
1
+ import chalk from "chalk";
2
+ import { spawn } from "child_process";
3
+ import { existsSync, readFileSync } from "fs";
4
+ import { join } from "path";
5
+ import { showError, showInfo } from "../utils/prompts.js";
6
+ /**
7
+ * Start development server with hot reloading
8
+ */
9
+ export async function dev() {
10
+ console.log(chalk.cyan("\nšŸš€ Starting Development Server\n"));
11
+ // Check if we're in a valid XMCP-I project
12
+ const packageJsonPath = join(process.cwd(), "package.json");
13
+ if (!existsSync(packageJsonPath)) {
14
+ showError("No package.json found. Are you in a valid project directory?");
15
+ process.exit(1);
16
+ }
17
+ // Check for mcpi dependency
18
+ try {
19
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
20
+ const hasmcpi = packageJson.dependencies?.mcpi ||
21
+ packageJson.devDependencies?.mcpi ||
22
+ packageJson.dependencies?.["@kya-os/mcp-i"] ||
23
+ packageJson.devDependencies?.["@kya-os/mcp-i"] ||
24
+ packageJson.dependencies?.["@kya-os/mcpi"] ||
25
+ packageJson.devDependencies?.["@kya-os/mcpi"];
26
+ if (!hasmcpi) {
27
+ showError("This doesn't appear to be an XMCP-I project. Missing mcpi dependency.");
28
+ console.log(`\n${chalk.gray("To create a new XMCP-I project:")}`);
29
+ console.log(`${chalk.cyan("npx @kya-os/create-mcpi-app my-agent")}`);
30
+ process.exit(1);
31
+ }
32
+ }
33
+ catch (error) {
34
+ showError("Failed to read package.json");
35
+ process.exit(1);
36
+ }
37
+ // Check for identity
38
+ const identityPath = join(process.cwd(), ".mcpi", "identity.json");
39
+ if (!existsSync(identityPath)) {
40
+ showInfo("No identity found. Run 'mcpi init' to set up identity first.");
41
+ console.log(`\n${chalk.gray("Setting up identity...")}`);
42
+ // Import and run init command
43
+ const { init } = await import("./init.js");
44
+ await init({});
45
+ console.log(`\n${chalk.gray("Continuing with development server...")}`);
46
+ }
47
+ // Look for common dev scripts or entry points
48
+ let command = "npm";
49
+ let args = ["run", "dev"];
50
+ // Check if there's a dev script in package.json
51
+ try {
52
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
53
+ if (!packageJson.scripts?.dev) {
54
+ // Try alternative approaches
55
+ if (packageJson.scripts?.start) {
56
+ args = ["run", "start"];
57
+ }
58
+ else if (existsSync(join(process.cwd(), "src", "server.ts"))) {
59
+ // Use tsx directly if available
60
+ command = "npx";
61
+ args = ["tsx", "src/server.ts"];
62
+ }
63
+ else if (existsSync(join(process.cwd(), "src", "index.ts"))) {
64
+ command = "npx";
65
+ args = ["tsx", "src/index.ts"];
66
+ }
67
+ else {
68
+ showError("No dev script found and no obvious entry point detected.");
69
+ console.log(`\n${chalk.gray("Expected one of:")}`);
70
+ console.log(`${chalk.gray("• npm script 'dev' in package.json")}`);
71
+ console.log(`${chalk.gray("• src/server.ts file")}`);
72
+ console.log(`${chalk.gray("• src/index.ts file")}`);
73
+ process.exit(1);
74
+ }
75
+ }
76
+ }
77
+ catch (error) {
78
+ showError("Failed to parse package.json");
79
+ process.exit(1);
80
+ }
81
+ console.log(`${chalk.gray("Running:")} ${chalk.cyan(`${command} ${args.join(" ")}`)}`);
82
+ console.log(`${chalk.gray("Press Ctrl+C to stop")}\n`);
83
+ // Spawn the development process
84
+ const child = spawn(command, args, {
85
+ stdio: "inherit",
86
+ shell: true,
87
+ env: {
88
+ ...process.env,
89
+ NODE_ENV: "development",
90
+ },
91
+ });
92
+ // Handle process termination
93
+ process.on("SIGINT", () => {
94
+ console.log(chalk.yellow("\n\nšŸ›‘ Stopping development server..."));
95
+ child.kill("SIGINT");
96
+ });
97
+ process.on("SIGTERM", () => {
98
+ child.kill("SIGTERM");
99
+ });
100
+ child.on("error", (error) => {
101
+ showError(`Failed to start development server: ${error.message}`);
102
+ process.exit(1);
103
+ });
104
+ child.on("exit", (code) => {
105
+ if (code !== 0 && code !== null) {
106
+ showError(`Development server exited with code ${code}`);
107
+ process.exit(code);
108
+ }
109
+ });
110
+ }
111
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG;IACvB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC,CAAC;IAE9D,2CAA2C;IAC3C,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAC5D,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjC,SAAS,CAAC,8DAA8D,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACl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GAAG,EAAE;QACzB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QAC1B,SAAS,CAAC,uCAAuC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAChC,SAAS,CAAC,uCAAuC,IAAI,EAAE,CAAC,CAAC;YACzD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,11 @@
1
+ interface DoctorOptions {
2
+ json?: boolean;
3
+ verbose?: boolean;
4
+ }
5
+ /**
6
+ * Comprehensive system health check for XMCP-I
7
+ * Implements Requirements 16.2, 16.3, 16.4, 16.5, 16.6
8
+ */
9
+ export declare function doctor(options?: DoctorOptions): Promise<void>;
10
+ export {};
11
+ //# sourceMappingURL=doctor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AA0BA,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAAC,OAAO,GAAE,aAAkB,iBAiFvD"}
@@ -0,0 +1,530 @@
1
+ import chalk from "chalk";
2
+ import ora from "ora";
3
+ import { existsSync, readFileSync } from "fs";
4
+ import { join } from "path";
5
+ import { exec } from "child_process";
6
+ import { promisify } from "util";
7
+ import { EnvManager } from "../utils/env-manager.js";
8
+ import { detectPlatform } from "../utils/platform-detector.js";
9
+ import { ktaApi, isKTAAvailable } from "../utils/kta-api.js";
10
+ import { showSuccess, showError, showWarning, } from "../utils/prompts.js";
11
+ const execAsync = promisify(exec);
12
+ /**
13
+ * Comprehensive system health check for XMCP-I
14
+ * Implements Requirements 16.2, 16.3, 16.4, 16.5, 16.6
15
+ */
16
+ export async function doctor(options = {}) {
17
+ const { json = false, verbose = false } = options;
18
+ if (!json) {
19
+ console.log(chalk.cyan("\n🩺 XMCP-I Doctor - System Health Check\n"));
20
+ }
21
+ const spinner = json ? null : ora("Running diagnostics...").start();
22
+ try {
23
+ // Run all diagnostic checks
24
+ const [packages, xmcpUpstream, environment, kta, cache] = await Promise.all([
25
+ checkPackageVersions(verbose),
26
+ checkXMCPUpstreamCompatibility(verbose),
27
+ checkEnvironmentConfiguration(verbose),
28
+ checkKTAConnectivity(verbose),
29
+ checkNonceCacheConfiguration(verbose),
30
+ ]);
31
+ if (spinner) {
32
+ spinner.succeed("Diagnostics complete");
33
+ }
34
+ const result = {
35
+ packages,
36
+ xmcpUpstream,
37
+ environment,
38
+ kta,
39
+ cache,
40
+ };
41
+ if (json) {
42
+ const output = {
43
+ success: true,
44
+ result,
45
+ schemaId: "https://schemas.kya-os.ai/mcpi/doctor-result/v1.0.0.json",
46
+ timestamp: new Date().toISOString(),
47
+ };
48
+ console.log(JSON.stringify(output, null, 2));
49
+ }
50
+ else {
51
+ displayDoctorResults(result, verbose);
52
+ }
53
+ // Determine exit code based on critical issues
54
+ const hasCriticalIssues = !environment.valid ||
55
+ packages.some((p) => !p.compatible) ||
56
+ !xmcpUpstream.compatible;
57
+ if (hasCriticalIssues && process.env.NODE_ENV !== "test") {
58
+ process.exit(1);
59
+ }
60
+ }
61
+ catch (error) {
62
+ if (spinner) {
63
+ spinner.fail("Diagnostics failed");
64
+ }
65
+ const errorMessage = error.message || "Failed to run diagnostics";
66
+ if (json) {
67
+ console.log(JSON.stringify({
68
+ success: false,
69
+ error: errorMessage,
70
+ code: "XMCP_I_EDOCTOR",
71
+ }, null, 2));
72
+ }
73
+ else {
74
+ showError(`Doctor check failed: ${errorMessage}`);
75
+ }
76
+ if (process.env.NODE_ENV !== "test") {
77
+ process.exit(1);
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * Check all package versions for compatibility (R16.2)
83
+ */
84
+ async function checkPackageVersions(verbose) {
85
+ const packages = [];
86
+ const packageJsonPath = join(process.cwd(), "package.json");
87
+ if (!existsSync(packageJsonPath)) {
88
+ return [
89
+ {
90
+ name: "package.json",
91
+ version: "not found",
92
+ compatible: false,
93
+ issues: ["No package.json found in current directory"],
94
+ },
95
+ ];
96
+ }
97
+ try {
98
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
99
+ const allDeps = {
100
+ ...packageJson.dependencies,
101
+ ...packageJson.devDependencies,
102
+ ...packageJson.peerDependencies,
103
+ };
104
+ // Check XMCP-I related packages
105
+ const xmcpPackages = [
106
+ "mcpi",
107
+ "@kya-os/cli",
108
+ "@kya-os/contracts",
109
+ "@kya-os/create-mcpi-app",
110
+ "create-mcpi-app",
111
+ "@kya-os/mcp-i", // deprecated
112
+ ];
113
+ for (const pkgName of xmcpPackages) {
114
+ const version = allDeps[pkgName];
115
+ if (version) {
116
+ const compatible = await checkPackageCompatibility(pkgName, version, verbose);
117
+ packages.push({
118
+ name: pkgName,
119
+ version,
120
+ compatible: compatible.compatible,
121
+ issues: compatible.issues,
122
+ });
123
+ }
124
+ }
125
+ // Check for deprecated packages
126
+ if (allDeps["@kya-os/mcp-i"]) {
127
+ const mcpIPackage = packages.find((p) => p.name === "@kya-os/mcp-i");
128
+ if (mcpIPackage) {
129
+ mcpIPackage.issues = mcpIPackage.issues || [];
130
+ mcpIPackage.issues.push("This package is deprecated. Migrate to 'mcpi'");
131
+ }
132
+ }
133
+ }
134
+ catch (error) {
135
+ packages.push({
136
+ name: "package.json",
137
+ version: "error",
138
+ compatible: false,
139
+ issues: [`Failed to parse package.json: ${error.message}`],
140
+ });
141
+ }
142
+ return packages;
143
+ }
144
+ /**
145
+ * Check individual package compatibility
146
+ */
147
+ async function checkPackageCompatibility(name, version, verbose) {
148
+ const issues = [];
149
+ let compatible = true;
150
+ try {
151
+ // Check if package is installed
152
+ const { stdout } = await execAsync(`npm list ${name} --depth=0 --json`, {
153
+ cwd: process.cwd(),
154
+ });
155
+ const listResult = JSON.parse(stdout);
156
+ const installedVersion = listResult.dependencies?.[name]?.version;
157
+ if (!installedVersion) {
158
+ compatible = false;
159
+ issues.push(`Package ${name} is not installed`);
160
+ return { compatible, issues };
161
+ }
162
+ // Version compatibility checks
163
+ if (name === "mcpi" ||
164
+ name === "@kya-os/cli" ||
165
+ name === "@kya-os/contracts") {
166
+ // These should be on compatible versions (1.x.x)
167
+ if (!installedVersion.startsWith("1.")) {
168
+ compatible = false;
169
+ issues.push(`Expected version 1.x.x, found ${installedVersion}`);
170
+ }
171
+ }
172
+ if (verbose) {
173
+ issues.push(`Installed version: ${installedVersion}`);
174
+ }
175
+ }
176
+ catch (error) {
177
+ if (verbose) {
178
+ issues.push(`Could not verify installation: ${error.message}`);
179
+ }
180
+ }
181
+ return { compatible, issues };
182
+ }
183
+ /**
184
+ * Verify XMCP upstream version compatibility (R16.3)
185
+ */
186
+ async function checkXMCPUpstreamCompatibility(verbose) {
187
+ const issues = [];
188
+ let compatible = true;
189
+ let version = "unknown";
190
+ try {
191
+ // Check if XMCP is installed
192
+ const { stdout } = await execAsync("npm list xmcp --depth=0 --json", {
193
+ cwd: process.cwd(),
194
+ });
195
+ const listResult = JSON.parse(stdout);
196
+ const installedVersion = listResult.dependencies?.xmcp?.version;
197
+ if (installedVersion) {
198
+ version = installedVersion;
199
+ // Check compatibility with known versions
200
+ // Based on design doc: default caret ^0.3.1
201
+ const majorVersion = installedVersion.split(".")[0];
202
+ const minorVersion = installedVersion.split(".")[1];
203
+ if (majorVersion !== "0" || parseInt(minorVersion) < 3) {
204
+ compatible = false;
205
+ issues.push(`XMCP version ${installedVersion} may not be compatible. Expected ^0.3.1`);
206
+ }
207
+ if (verbose) {
208
+ issues.push(`Found XMCP version: ${installedVersion}`);
209
+ }
210
+ }
211
+ else {
212
+ compatible = false;
213
+ issues.push("XMCP package not found. This is required for XMCP-I runtime");
214
+ }
215
+ // Check for latest version availability
216
+ if (verbose) {
217
+ try {
218
+ const { stdout: viewOutput } = await execAsync("npm view xmcp version");
219
+ const latestVersion = viewOutput.trim();
220
+ if (latestVersion !== installedVersion) {
221
+ issues.push(`Latest available version: ${latestVersion}`);
222
+ }
223
+ }
224
+ catch (error) {
225
+ if (verbose) {
226
+ issues.push("Could not check latest version");
227
+ }
228
+ }
229
+ }
230
+ }
231
+ catch (error) {
232
+ compatible = false;
233
+ version = "not found";
234
+ issues.push("XMCP package not installed");
235
+ if (verbose) {
236
+ issues.push(`Error: ${error.message}`);
237
+ }
238
+ }
239
+ return { version, compatible, issues };
240
+ }
241
+ /**
242
+ * Validate platform environment variables and identity configuration (R16.4)
243
+ */
244
+ async function checkEnvironmentConfiguration(verbose) {
245
+ const envManager = new EnvManager();
246
+ const issues = [];
247
+ // Check process environment
248
+ const processVars = envManager.getFromProcess();
249
+ const { valid, missing } = envManager.validateVariables(processVars);
250
+ // Check environment files
251
+ const envFiles = envManager.scanEnvFiles();
252
+ const hasValidEnvFile = envFiles.some((f) => f.hasmcpidentity && f.exists);
253
+ // Platform-specific checks
254
+ const platform = detectPlatform();
255
+ if (verbose) {
256
+ issues.push(`Detected platform: ${platform.platform}`);
257
+ issues.push(`Package manager: ${platform.packageManager}`);
258
+ }
259
+ // Environment validation
260
+ if (!valid && !hasValidEnvFile) {
261
+ issues.push("No valid environment configuration found");
262
+ issues.push("Run 'mcpi init' to set up identity");
263
+ }
264
+ if (missing.length > 0) {
265
+ issues.push(`Missing environment variables: ${missing.join(", ")}`);
266
+ }
267
+ // Platform-specific environment checks
268
+ if (platform.platform === "vercel" && process.env.VERCEL) {
269
+ if (!valid) {
270
+ issues.push("Running on Vercel but environment variables not configured");
271
+ issues.push("Add variables to Vercel Dashboard → Settings → Environment Variables");
272
+ }
273
+ }
274
+ // Check .gitignore for security
275
+ const sensitiveFiles = [".env", ".env.local", ".mcpi/identity.json"];
276
+ const { missing: notIgnored } = envManager.checkGitignore(sensitiveFiles);
277
+ if (notIgnored.length > 0) {
278
+ issues.push(`Sensitive files not in .gitignore: ${notIgnored.join(", ")}`);
279
+ }
280
+ // Check identity file in development
281
+ const identityPath = join(process.cwd(), ".mcpi", "identity.json");
282
+ if (existsSync(identityPath)) {
283
+ if (verbose) {
284
+ issues.push("Development identity file found");
285
+ }
286
+ try {
287
+ const identity = JSON.parse(readFileSync(identityPath, "utf-8"));
288
+ if (!identity.did || !identity.keyId || !identity.privateKey) {
289
+ issues.push("Identity file is incomplete or corrupted");
290
+ }
291
+ }
292
+ catch (error) {
293
+ issues.push("Identity file is corrupted or unreadable");
294
+ }
295
+ }
296
+ return {
297
+ valid: valid || hasValidEnvFile,
298
+ missing,
299
+ issues,
300
+ };
301
+ }
302
+ /**
303
+ * Test KTA connectivity and authentication (R16.5)
304
+ */
305
+ async function checkKTAConnectivity(verbose) {
306
+ const issues = [];
307
+ let reachable = false;
308
+ let authenticated = false;
309
+ try {
310
+ // Test basic connectivity
311
+ reachable = await isKTAAvailable();
312
+ if (reachable) {
313
+ if (verbose) {
314
+ issues.push("KTA endpoint is reachable");
315
+ }
316
+ // Test authentication if we have an API key
317
+ const apiKey = process.env.KYA_VOUCHED_API_KEY || process.env.VOUCHED_API_KEY;
318
+ if (apiKey) {
319
+ try {
320
+ // Try to make an authenticated request
321
+ const envManager = new EnvManager();
322
+ const processVars = envManager.getFromProcess();
323
+ if (processVars.AGENT_DID) {
324
+ await ktaApi.getAgentStatus(processVars.AGENT_DID);
325
+ authenticated = true;
326
+ if (verbose) {
327
+ issues.push("KTA authentication successful");
328
+ }
329
+ }
330
+ else {
331
+ issues.push("Cannot test authentication without AGENT_DID");
332
+ }
333
+ }
334
+ catch (error) {
335
+ if (error.message.includes("404")) {
336
+ // Agent not found is OK for auth test
337
+ authenticated = true;
338
+ if (verbose) {
339
+ issues.push("KTA authentication successful (agent not registered)");
340
+ }
341
+ }
342
+ else if (error.message.includes("401") ||
343
+ error.message.includes("403")) {
344
+ issues.push("KTA authentication failed - check API key");
345
+ }
346
+ else {
347
+ issues.push(`KTA authentication test failed: ${error.message}`);
348
+ }
349
+ }
350
+ }
351
+ else {
352
+ issues.push("No KTA API key found - cannot test authentication");
353
+ }
354
+ }
355
+ else {
356
+ issues.push("KTA endpoint is not reachable");
357
+ issues.push("Check internet connection and firewall settings");
358
+ }
359
+ }
360
+ catch (error) {
361
+ issues.push(`KTA connectivity check failed: ${error.message}`);
362
+ }
363
+ return { reachable, authenticated, issues };
364
+ }
365
+ /**
366
+ * Check nonce cache configuration (R16.5)
367
+ */
368
+ async function checkNonceCacheConfiguration(verbose) {
369
+ const issues = [];
370
+ let type = "memory";
371
+ let functional = true;
372
+ try {
373
+ // Detect cache type based on environment
374
+ if (process.env.REDIS_URL) {
375
+ type = "redis";
376
+ // Test Redis connectivity if available
377
+ try {
378
+ // This is a basic check - in a real implementation we'd test the actual connection
379
+ if (verbose) {
380
+ issues.push("Redis URL detected");
381
+ }
382
+ }
383
+ catch (error) {
384
+ functional = false;
385
+ issues.push("Redis connection failed");
386
+ }
387
+ }
388
+ else if (process.env.AWS_REGION) {
389
+ type = "dynamodb";
390
+ if (verbose) {
391
+ issues.push("AWS region detected - will use DynamoDB cache");
392
+ }
393
+ }
394
+ else if (typeof globalThis !== "undefined" && "caches" in globalThis) {
395
+ type = "cloudflare-kv";
396
+ if (verbose) {
397
+ issues.push("Cloudflare Workers environment detected");
398
+ }
399
+ }
400
+ else {
401
+ type = "memory";
402
+ // Memory cache warnings for production
403
+ if (process.env.NODE_ENV === "production") {
404
+ issues.push("Using memory cache in production - not suitable for multi-instance deployments");
405
+ issues.push("Consider configuring Redis, DynamoDB, or Cloudflare KV");
406
+ }
407
+ if (verbose) {
408
+ issues.push("Using in-memory cache (suitable for single-instance only)");
409
+ }
410
+ }
411
+ // Platform-specific cache recommendations
412
+ const platform = detectPlatform();
413
+ if (platform.platform === "vercel" && type === "memory") {
414
+ issues.push("Vercel deployment detected - consider using external cache for multi-region");
415
+ }
416
+ if (platform.platform === "lambda" && type === "memory") {
417
+ issues.push("Lambda deployment detected - consider DynamoDB for persistence");
418
+ }
419
+ }
420
+ catch (error) {
421
+ functional = false;
422
+ issues.push(`Cache configuration check failed: ${error.message}`);
423
+ }
424
+ return { type, functional, issues };
425
+ }
426
+ /**
427
+ * Display doctor results in human-readable format
428
+ */
429
+ function displayDoctorResults(result, verbose) {
430
+ console.log(chalk.bold("šŸ“¦ Package Compatibility:"));
431
+ if (result.packages.length === 0) {
432
+ console.log(` ${chalk.yellow("āš ļø No XMCP-I packages found")}`);
433
+ }
434
+ else {
435
+ for (const pkg of result.packages) {
436
+ const status = pkg.compatible ? chalk.green("āœ“") : chalk.red("āœ—");
437
+ console.log(` ${status} ${pkg.name}@${pkg.version}`);
438
+ if (pkg.issues && (verbose || !pkg.compatible)) {
439
+ pkg.issues.forEach((issue) => {
440
+ const color = pkg.compatible ? chalk.gray : chalk.red;
441
+ console.log(` ${color(`• ${issue}`)}`);
442
+ });
443
+ }
444
+ }
445
+ }
446
+ console.log(chalk.bold("\nšŸ”— XMCP Upstream:"));
447
+ const xmcpStatus = result.xmcpUpstream.compatible
448
+ ? chalk.green("āœ“")
449
+ : chalk.red("āœ—");
450
+ console.log(` ${xmcpStatus} XMCP ${result.xmcpUpstream.version}`);
451
+ if (result.xmcpUpstream.issues &&
452
+ (verbose || !result.xmcpUpstream.compatible)) {
453
+ result.xmcpUpstream.issues.forEach((issue) => {
454
+ const color = result.xmcpUpstream.compatible ? chalk.gray : chalk.red;
455
+ console.log(` ${color(`• ${issue}`)}`);
456
+ });
457
+ }
458
+ console.log(chalk.bold("\nšŸ” Environment Configuration:"));
459
+ const envStatus = result.environment.valid
460
+ ? chalk.green("āœ“")
461
+ : chalk.red("āœ—");
462
+ console.log(` ${envStatus} Environment variables`);
463
+ if (result.environment.missing.length > 0) {
464
+ console.log(` ${chalk.red(`• Missing: ${result.environment.missing.join(", ")}`)}`);
465
+ }
466
+ if (result.environment.issues && (verbose || !result.environment.valid)) {
467
+ result.environment.issues.forEach((issue) => {
468
+ const color = result.environment.valid ? chalk.gray : chalk.yellow;
469
+ console.log(` ${color(`• ${issue}`)}`);
470
+ });
471
+ }
472
+ console.log(chalk.bold("\n🌐 KTA Connectivity:"));
473
+ const ktaStatus = result.kta.reachable ? chalk.green("āœ“") : chalk.red("āœ—");
474
+ const authStatus = result.kta.authenticated
475
+ ? chalk.green("authenticated")
476
+ : chalk.yellow("not authenticated");
477
+ console.log(` ${ktaStatus} KTA reachable (${authStatus})`);
478
+ if (result.kta.issues && (verbose || !result.kta.reachable)) {
479
+ result.kta.issues.forEach((issue) => {
480
+ const color = result.kta.reachable ? chalk.gray : chalk.red;
481
+ console.log(` ${color(`• ${issue}`)}`);
482
+ });
483
+ }
484
+ console.log(chalk.bold("\nšŸ’¾ Nonce Cache:"));
485
+ const cacheStatus = result.cache.functional
486
+ ? chalk.green("āœ“")
487
+ : chalk.red("āœ—");
488
+ console.log(` ${cacheStatus} ${result.cache.type} cache`);
489
+ if (result.cache.issues && (verbose || !result.cache.functional)) {
490
+ result.cache.issues.forEach((issue) => {
491
+ const color = result.cache.functional ? chalk.gray : chalk.yellow;
492
+ console.log(` ${color(`• ${issue}`)}`);
493
+ });
494
+ }
495
+ // Overall summary
496
+ const hasIssues = !result.environment.valid ||
497
+ result.packages.some((p) => !p.compatible) ||
498
+ !result.xmcpUpstream.compatible ||
499
+ !result.kta.reachable;
500
+ console.log(chalk.bold("\nšŸ“Š Summary:"));
501
+ if (!hasIssues) {
502
+ showSuccess("All systems operational! šŸŽ‰");
503
+ }
504
+ else {
505
+ showWarning("Issues detected that may affect functionality");
506
+ console.log(chalk.bold("\nšŸ’” Recommended Actions:"));
507
+ if (!result.environment.valid) {
508
+ console.log(` • Run ${chalk.cyan("mcpi init")} to set up identity`);
509
+ }
510
+ if (result.packages.some((p) => !p.compatible)) {
511
+ console.log(` • Update incompatible packages to latest versions`);
512
+ }
513
+ if (!result.xmcpUpstream.compatible) {
514
+ console.log(` • Update XMCP to version ^0.3.1 or later`);
515
+ }
516
+ if (!result.kta.reachable) {
517
+ console.log(` • Check internet connection and firewall settings`);
518
+ }
519
+ if (result.cache.type === "memory" &&
520
+ process.env.NODE_ENV === "production") {
521
+ console.log(` • Configure external cache (Redis/DynamoDB/KV) for production`);
522
+ }
523
+ }
524
+ console.log(chalk.bold("\nšŸ”§ Additional Commands:"));
525
+ console.log(` ${chalk.cyan("mcpi status")} - Check agent registration status`);
526
+ console.log(` ${chalk.cyan("mcpi env verify")} - Verify environment configuration`);
527
+ console.log(` ${chalk.cyan("mcpi keys rotate")} - Rotate identity keys`);
528
+ console.log(` ${chalk.cyan("mcpi --help")} - Show all available commands`);
529
+ }
530
+ //# sourceMappingURL=doctor.js.map