kontexted 0.1.5

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 (78) hide show
  1. package/README.md +75 -0
  2. package/dist/commands/login.d.ts +2 -0
  3. package/dist/commands/login.js +48 -0
  4. package/dist/commands/logout.d.ts +5 -0
  5. package/dist/commands/logout.js +33 -0
  6. package/dist/commands/mcp.d.ts +15 -0
  7. package/dist/commands/mcp.js +65 -0
  8. package/dist/commands/server/doctor.d.ts +4 -0
  9. package/dist/commands/server/doctor.js +33 -0
  10. package/dist/commands/server/index.d.ts +6 -0
  11. package/dist/commands/server/index.js +125 -0
  12. package/dist/commands/server/init.d.ts +6 -0
  13. package/dist/commands/server/init.js +112 -0
  14. package/dist/commands/server/logs.d.ts +7 -0
  15. package/dist/commands/server/logs.js +39 -0
  16. package/dist/commands/server/migrate.d.ts +4 -0
  17. package/dist/commands/server/migrate.js +29 -0
  18. package/dist/commands/server/show-invite.d.ts +4 -0
  19. package/dist/commands/server/show-invite.js +29 -0
  20. package/dist/commands/server/start.d.ts +6 -0
  21. package/dist/commands/server/start.js +44 -0
  22. package/dist/commands/server/status.d.ts +4 -0
  23. package/dist/commands/server/status.js +23 -0
  24. package/dist/commands/server/stop.d.ts +6 -0
  25. package/dist/commands/server/stop.js +32 -0
  26. package/dist/commands/show-config.d.ts +5 -0
  27. package/dist/commands/show-config.js +19 -0
  28. package/dist/commands/skill.d.ts +5 -0
  29. package/dist/commands/skill.js +211 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +25 -0
  32. package/dist/lib/api-client.d.ts +36 -0
  33. package/dist/lib/api-client.js +130 -0
  34. package/dist/lib/config.d.ts +17 -0
  35. package/dist/lib/config.js +46 -0
  36. package/dist/lib/index.d.ts +6 -0
  37. package/dist/lib/index.js +6 -0
  38. package/dist/lib/logger.d.ts +24 -0
  39. package/dist/lib/logger.js +76 -0
  40. package/dist/lib/mcp-client.d.ts +14 -0
  41. package/dist/lib/mcp-client.js +62 -0
  42. package/dist/lib/oauth.d.ts +42 -0
  43. package/dist/lib/oauth.js +383 -0
  44. package/dist/lib/profile.d.ts +37 -0
  45. package/dist/lib/profile.js +49 -0
  46. package/dist/lib/proxy-server.d.ts +12 -0
  47. package/dist/lib/proxy-server.js +131 -0
  48. package/dist/lib/server/binary.d.ts +32 -0
  49. package/dist/lib/server/binary.js +127 -0
  50. package/dist/lib/server/config.d.ts +57 -0
  51. package/dist/lib/server/config.js +136 -0
  52. package/dist/lib/server/constants.d.ts +29 -0
  53. package/dist/lib/server/constants.js +35 -0
  54. package/dist/lib/server/daemon.d.ts +34 -0
  55. package/dist/lib/server/daemon.js +199 -0
  56. package/dist/lib/server/index.d.ts +5 -0
  57. package/dist/lib/server/index.js +5 -0
  58. package/dist/lib/server/migrate.d.ts +9 -0
  59. package/dist/lib/server/migrate.js +51 -0
  60. package/dist/lib/server-url.d.ts +8 -0
  61. package/dist/lib/server-url.js +25 -0
  62. package/dist/skill-init/index.d.ts +3 -0
  63. package/dist/skill-init/index.js +3 -0
  64. package/dist/skill-init/providers/base.d.ts +26 -0
  65. package/dist/skill-init/providers/base.js +1 -0
  66. package/dist/skill-init/providers/index.d.ts +13 -0
  67. package/dist/skill-init/providers/index.js +17 -0
  68. package/dist/skill-init/providers/opencode.d.ts +5 -0
  69. package/dist/skill-init/providers/opencode.js +48 -0
  70. package/dist/skill-init/templates/index.d.ts +3 -0
  71. package/dist/skill-init/templates/index.js +3 -0
  72. package/dist/skill-init/templates/kontexted-cli.d.ts +2 -0
  73. package/dist/skill-init/templates/kontexted-cli.js +169 -0
  74. package/dist/skill-init/utils.d.ts +66 -0
  75. package/dist/skill-init/utils.js +122 -0
  76. package/dist/types/index.d.ts +67 -0
  77. package/dist/types/index.js +4 -0
  78. package/package.json +50 -0
@@ -0,0 +1,66 @@
1
+ import type { SkillDefinition, SkillProvider } from '../skill-init/providers/base.js';
2
+ /**
3
+ * Options for initializing a skill
4
+ */
5
+ export interface InitSkillOptions {
6
+ /** The skill to initialize */
7
+ skill: SkillDefinition;
8
+ /** The provider to use */
9
+ provider: SkillProvider;
10
+ /** Base directory (defaults to current working directory) */
11
+ basePath?: string;
12
+ }
13
+ /**
14
+ * Result of initializing a skill
15
+ */
16
+ export interface InitSkillResult {
17
+ /** Path where the skill was written */
18
+ path: string;
19
+ /** Whether the skill was newly created or overwritten */
20
+ created: boolean;
21
+ /** Name of the skill */
22
+ name: string;
23
+ }
24
+ /**
25
+ * Creates a directory (and parent directories) if it doesn't exist.
26
+ * Uses `fs/promises` with `mkdir` and `recursive: true`.
27
+ *
28
+ * @param dirPath - The directory path to ensure exists
29
+ * @returns Promise that resolves when the directory is ready
30
+ * @throws Error if the directory cannot be created
31
+ */
32
+ export declare function ensureDirectory(dirPath: string): Promise<void>;
33
+ /**
34
+ * Checks if a file exists at the given path.
35
+ *
36
+ * @param filePath - The file path to check
37
+ * @returns Promise that resolves to true if the file exists, false otherwise
38
+ */
39
+ export declare function fileExists(filePath: string): Promise<boolean>;
40
+ /**
41
+ * Writes content to a file, creating parent directories if needed.
42
+ *
43
+ * @param filePath - The path of the file to write
44
+ * @param content - The content to write to the file
45
+ * @returns Promise that resolves when the file has been written
46
+ * @throws Error if the file cannot be written
47
+ */
48
+ export declare function writeFile(filePath: string, content: string): Promise<void>;
49
+ /**
50
+ * Validates a skill definition and returns an array of error messages.
51
+ * Returns an empty array if the skill is valid.
52
+ *
53
+ * @param skill - The skill definition to validate
54
+ * @param provider - The skill provider to use for name validation
55
+ * @returns Array of error messages (empty if valid)
56
+ */
57
+ export declare function validateSkill(skill: SkillDefinition, provider: SkillProvider): string[];
58
+ /**
59
+ * Initializes a skill by creating the necessary directory structure
60
+ * and writing the skill file.
61
+ *
62
+ * @param options - The options for initializing the skill
63
+ * @returns Promise that resolves to the initialization result
64
+ * @throws Error if validation fails or if the skill cannot be written
65
+ */
66
+ export declare function initSkill(options: InitSkillOptions): Promise<InitSkillResult>;
@@ -0,0 +1,122 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ /**
4
+ * Creates a directory (and parent directories) if it doesn't exist.
5
+ * Uses `fs/promises` with `mkdir` and `recursive: true`.
6
+ *
7
+ * @param dirPath - The directory path to ensure exists
8
+ * @returns Promise that resolves when the directory is ready
9
+ * @throws Error if the directory cannot be created
10
+ */
11
+ export async function ensureDirectory(dirPath) {
12
+ try {
13
+ await fs.mkdir(dirPath, { recursive: true });
14
+ }
15
+ catch (error) {
16
+ if (error instanceof Error) {
17
+ throw new Error(`Failed to create directory "${dirPath}": ${error.message}`);
18
+ }
19
+ throw new Error(`Failed to create directory "${dirPath}": Unknown error`);
20
+ }
21
+ }
22
+ /**
23
+ * Checks if a file exists at the given path.
24
+ *
25
+ * @param filePath - The file path to check
26
+ * @returns Promise that resolves to true if the file exists, false otherwise
27
+ */
28
+ export async function fileExists(filePath) {
29
+ try {
30
+ await fs.access(filePath);
31
+ return true;
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ }
37
+ /**
38
+ * Writes content to a file, creating parent directories if needed.
39
+ *
40
+ * @param filePath - The path of the file to write
41
+ * @param content - The content to write to the file
42
+ * @returns Promise that resolves when the file has been written
43
+ * @throws Error if the file cannot be written
44
+ */
45
+ export async function writeFile(filePath, content) {
46
+ const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(process.cwd(), filePath);
47
+ const dirPath = path.dirname(absolutePath);
48
+ // Ensure parent directory exists
49
+ await ensureDirectory(dirPath);
50
+ try {
51
+ await fs.writeFile(absolutePath, content, 'utf-8');
52
+ }
53
+ catch (error) {
54
+ if (error instanceof Error) {
55
+ throw new Error(`Failed to write file "${absolutePath}": ${error.message}`);
56
+ }
57
+ throw new Error(`Failed to write file "${absolutePath}": Unknown error`);
58
+ }
59
+ }
60
+ /**
61
+ * Validates a skill definition and returns an array of error messages.
62
+ * Returns an empty array if the skill is valid.
63
+ *
64
+ * @param skill - The skill definition to validate
65
+ * @param provider - The skill provider to use for name validation
66
+ * @returns Array of error messages (empty if valid)
67
+ */
68
+ export function validateSkill(skill, provider) {
69
+ const errors = [];
70
+ // Validate skill name using provider rules
71
+ if (!skill.name || skill.name.trim().length === 0) {
72
+ errors.push('Skill name is required');
73
+ }
74
+ else if (!provider.validateSkillName(skill.name)) {
75
+ errors.push(`Invalid skill name "${skill.name}". Names must match provider rules (lowercase alphanumeric with hyphens).`);
76
+ }
77
+ // Validate description length
78
+ if (!skill.description || skill.description.trim().length === 0) {
79
+ errors.push('Skill description is required');
80
+ }
81
+ else if (skill.description.length < 1 || skill.description.length > 1024) {
82
+ errors.push(`Skill description must be between 1 and 1024 characters (currently ${skill.description.length})`);
83
+ }
84
+ // Validate content is not empty
85
+ if (!skill.content || skill.content.trim().length === 0) {
86
+ errors.push('Skill content is required and cannot be empty');
87
+ }
88
+ return errors;
89
+ }
90
+ /**
91
+ * Initializes a skill by creating the necessary directory structure
92
+ * and writing the skill file.
93
+ *
94
+ * @param options - The options for initializing the skill
95
+ * @returns Promise that resolves to the initialization result
96
+ * @throws Error if validation fails or if the skill cannot be written
97
+ */
98
+ export async function initSkill(options) {
99
+ const { skill, provider } = options;
100
+ const basePath = options.basePath || process.cwd();
101
+ // Validate the skill definition
102
+ const validationErrors = validateSkill(skill, provider);
103
+ if (validationErrors.length > 0) {
104
+ throw new Error(`Skill validation failed:\n${validationErrors.join('\n')}`);
105
+ }
106
+ // Get the skill path from the provider
107
+ const relativeSkillPath = provider.getSkillPath(skill.name);
108
+ const absoluteSkillPath = path.isAbsolute(relativeSkillPath)
109
+ ? relativeSkillPath
110
+ : path.resolve(basePath, relativeSkillPath);
111
+ // Check if file already exists
112
+ const alreadyExists = await fileExists(absoluteSkillPath);
113
+ // Generate the skill content
114
+ const skillContent = provider.generateSkillContent(skill);
115
+ // Write the skill file
116
+ await writeFile(absoluteSkillPath, skillContent);
117
+ return {
118
+ path: absoluteSkillPath,
119
+ created: !alreadyExists,
120
+ name: skill.name,
121
+ };
122
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Type definitions for Kontexted CLI
3
+ */
4
+ /** OAuth token data */
5
+ export interface OAuthTokens {
6
+ access_token: string;
7
+ token_type: string;
8
+ refresh_token?: string;
9
+ expires_in?: number;
10
+ expires_at?: number;
11
+ scope?: string;
12
+ id_token?: string;
13
+ }
14
+ /** OAuth client information - matches SDK's OAuthClientInformationMixed */
15
+ export interface OAuthClientInfo {
16
+ client_id: string;
17
+ client_secret?: string;
18
+ client_id_issued_at?: number;
19
+ client_secret_expires_at?: number;
20
+ redirect_uris?: URL[];
21
+ token_endpoint_auth_method?: string;
22
+ grant_types?: string[];
23
+ response_types?: string[];
24
+ client_name?: string;
25
+ client_uri?: URL;
26
+ logo_uri?: string;
27
+ scope?: string;
28
+ contacts?: string[];
29
+ tos_uri?: string;
30
+ policy_uri?: string;
31
+ jwks_uri?: URL;
32
+ jwks?: unknown;
33
+ software_id?: string;
34
+ software_version?: string;
35
+ software_statement?: string;
36
+ }
37
+ /** OAuth state stored in profile */
38
+ export interface OAuthState {
39
+ clientInformation?: OAuthClientInfo;
40
+ tokens?: OAuthTokens;
41
+ codeVerifier?: string;
42
+ redirectUrl?: string;
43
+ clientMetadata?: Record<string, unknown>;
44
+ serverUrl?: string;
45
+ }
46
+ /** Stored profile configuration */
47
+ export interface Profile {
48
+ serverUrl: string;
49
+ workspace: string;
50
+ write: boolean;
51
+ oauth: OAuthState;
52
+ }
53
+ /** Configuration file structure */
54
+ export interface Config {
55
+ profiles: Record<string, Profile>;
56
+ }
57
+ /** MCP Tool from server */
58
+ export interface McpTool {
59
+ name: string;
60
+ title?: string;
61
+ description?: string;
62
+ inputSchema?: Record<string, unknown>;
63
+ }
64
+ /** MCP Tool list response */
65
+ export interface McpToolList {
66
+ tools: McpTool[];
67
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Type definitions for Kontexted CLI
3
+ */
4
+ export {};
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "kontexted",
3
+ "version": "0.1.5",
4
+ "description": "CLI tool for Kontexted - MCP proxy, workspaces management, and local server",
5
+ "type": "module",
6
+ "bin": {
7
+ "kontexted": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist/",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc && tsc-alias -f && node -e \"const fs=require('fs'),path=require('path');const src='dist/index.js';const content=fs.readFileSync(src,'utf8');fs.writeFileSync(src,'#!/usr/bin/env node\\n'+content);fs.chmodSync(src,0o755);console.log('Added shebang and set executable');\"",
15
+ "dev": "tsx src/index.ts",
16
+ "prepublishOnly": "npm run build",
17
+ "lint": "tsc --noEmit"
18
+ },
19
+ "keywords": [
20
+ "kontexted",
21
+ "mcp",
22
+ "cli",
23
+ "notes",
24
+ "workspace"
25
+ ],
26
+ "author": "Kontexted",
27
+ "license": "MIT",
28
+ "engines": {
29
+ "node": ">=18.0.0"
30
+ },
31
+ "dependencies": {
32
+ "@modelcontextprotocol/sdk": "^1.25.3",
33
+ "commander": "^12.1.0",
34
+ "yargs": "^17.7.2",
35
+ "zod": "^3.23.8"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^20.0.0",
39
+ "@types/yargs": "^17.0.35",
40
+ "tsc-alias": "^1.8.10",
41
+ "tsup": "^8.3.5",
42
+ "tsx": "^4.19.2",
43
+ "typescript": "^5.6.0"
44
+ },
45
+ "optionalDependencies": {
46
+ "@kontexted/darwin-arm64": "0.1.5",
47
+ "@kontexted/linux-x64": "0.1.5",
48
+ "@kontexted/windows-x64": "0.1.5"
49
+ }
50
+ }