agentic-knowledge-mcp 0.0.1

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 (77) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +530 -0
  3. package/package.json +94 -0
  4. package/packages/cli/dist/cli.d.ts +5 -0
  5. package/packages/cli/dist/cli.js +21 -0
  6. package/packages/cli/dist/commands/create.d.ts +5 -0
  7. package/packages/cli/dist/commands/create.js +90 -0
  8. package/packages/cli/dist/commands/init.d.ts +5 -0
  9. package/packages/cli/dist/commands/init.js +182 -0
  10. package/packages/cli/dist/commands/refresh.d.ts +5 -0
  11. package/packages/cli/dist/commands/refresh.js +322 -0
  12. package/packages/cli/dist/commands/status.d.ts +5 -0
  13. package/packages/cli/dist/commands/status.js +268 -0
  14. package/packages/cli/dist/index.d.ts +6 -0
  15. package/packages/cli/dist/index.js +6 -0
  16. package/packages/cli/package.json +57 -0
  17. package/packages/content-loader/dist/__tests__/debug-filtering.d.ts +1 -0
  18. package/packages/content-loader/dist/__tests__/debug-filtering.js +17 -0
  19. package/packages/content-loader/dist/__tests__/test-filtering.d.ts +1 -0
  20. package/packages/content-loader/dist/__tests__/test-filtering.js +19 -0
  21. package/packages/content-loader/dist/content/api-documentation-loader.d.ts +26 -0
  22. package/packages/content-loader/dist/content/api-documentation-loader.js +45 -0
  23. package/packages/content-loader/dist/content/content-processor.d.ts +44 -0
  24. package/packages/content-loader/dist/content/content-processor.js +86 -0
  25. package/packages/content-loader/dist/content/documentation-site-loader.d.ts +26 -0
  26. package/packages/content-loader/dist/content/documentation-site-loader.js +45 -0
  27. package/packages/content-loader/dist/content/git-repo-loader.d.ts +79 -0
  28. package/packages/content-loader/dist/content/git-repo-loader.js +368 -0
  29. package/packages/content-loader/dist/content/index.d.ts +9 -0
  30. package/packages/content-loader/dist/content/index.js +9 -0
  31. package/packages/content-loader/dist/content/loader.d.ts +47 -0
  32. package/packages/content-loader/dist/content/loader.js +8 -0
  33. package/packages/content-loader/dist/content/metadata-manager.d.ts +65 -0
  34. package/packages/content-loader/dist/content/metadata-manager.js +160 -0
  35. package/packages/content-loader/dist/index.d.ts +5 -0
  36. package/packages/content-loader/dist/index.js +5 -0
  37. package/packages/content-loader/dist/types.d.ts +127 -0
  38. package/packages/content-loader/dist/types.js +48 -0
  39. package/packages/content-loader/package.json +50 -0
  40. package/packages/core/dist/config/discovery.d.ts +15 -0
  41. package/packages/core/dist/config/discovery.js +65 -0
  42. package/packages/core/dist/config/loader.d.ts +22 -0
  43. package/packages/core/dist/config/loader.js +236 -0
  44. package/packages/core/dist/config/manager.d.ts +55 -0
  45. package/packages/core/dist/config/manager.js +180 -0
  46. package/packages/core/dist/content/api-documentation-loader.d.ts +26 -0
  47. package/packages/core/dist/content/api-documentation-loader.js +45 -0
  48. package/packages/core/dist/content/content-processor.d.ts +44 -0
  49. package/packages/core/dist/content/content-processor.js +81 -0
  50. package/packages/core/dist/content/documentation-site-loader.d.ts +26 -0
  51. package/packages/core/dist/content/documentation-site-loader.js +45 -0
  52. package/packages/core/dist/content/git-repo-loader.d.ts +54 -0
  53. package/packages/core/dist/content/git-repo-loader.js +264 -0
  54. package/packages/core/dist/content/index.d.ts +9 -0
  55. package/packages/core/dist/content/index.js +9 -0
  56. package/packages/core/dist/content/loader.d.ts +50 -0
  57. package/packages/core/dist/content/loader.js +7 -0
  58. package/packages/core/dist/content/metadata-manager.d.ts +65 -0
  59. package/packages/core/dist/content/metadata-manager.js +160 -0
  60. package/packages/core/dist/index.d.ts +12 -0
  61. package/packages/core/dist/index.js +30 -0
  62. package/packages/core/dist/paths/calculator.d.ts +46 -0
  63. package/packages/core/dist/paths/calculator.js +166 -0
  64. package/packages/core/dist/templates/processor.d.ts +40 -0
  65. package/packages/core/dist/templates/processor.js +111 -0
  66. package/packages/core/dist/types.d.ts +129 -0
  67. package/packages/core/dist/types.js +79 -0
  68. package/packages/core/package.json +50 -0
  69. package/packages/mcp-server/dist/bin.d.ts +5 -0
  70. package/packages/mcp-server/dist/bin.js +10 -0
  71. package/packages/mcp-server/dist/cli.d.ts +7 -0
  72. package/packages/mcp-server/dist/cli.js +17 -0
  73. package/packages/mcp-server/dist/index.d.ts +8 -0
  74. package/packages/mcp-server/dist/index.js +9 -0
  75. package/packages/mcp-server/dist/server.d.ts +35 -0
  76. package/packages/mcp-server/dist/server.js +244 -0
  77. package/packages/mcp-server/package.json +54 -0
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Metadata manager for tracking web source downloads
3
+ */
4
+ import { promises as fs } from "node:fs";
5
+ import * as path from "node:path";
6
+ import { METADATA_FILENAME } from "../types.js";
7
+ /**
8
+ * Manager for docset metadata files
9
+ */
10
+ export class MetadataManager {
11
+ /**
12
+ * Load metadata from a docset directory
13
+ * @param docsetPath - Path to the docset directory
14
+ * @returns Metadata object or null if not found
15
+ */
16
+ async loadMetadata(docsetPath) {
17
+ const metadataPath = path.join(docsetPath, METADATA_FILENAME);
18
+ try {
19
+ const content = await fs.readFile(metadataPath, "utf-8");
20
+ return JSON.parse(content);
21
+ } catch (error) {
22
+ if (error.code === "ENOENT") {
23
+ return null; // File doesn't exist
24
+ }
25
+ throw error; // Other errors should be propagated
26
+ }
27
+ }
28
+ /**
29
+ * Save metadata to a docset directory
30
+ * @param docsetPath - Path to the docset directory
31
+ * @param metadata - Metadata to save
32
+ */
33
+ async saveMetadata(docsetPath, metadata) {
34
+ await fs.mkdir(docsetPath, { recursive: true });
35
+ const metadataPath = path.join(docsetPath, METADATA_FILENAME);
36
+ const content = JSON.stringify(metadata, null, 2);
37
+ await fs.writeFile(metadataPath, content, "utf-8");
38
+ }
39
+ /**
40
+ * Create initial metadata for a docset
41
+ * @param docsetId - ID of the docset
42
+ * @returns Initial metadata structure
43
+ */
44
+ createInitialMetadata(docsetId) {
45
+ return {
46
+ version: "1.0",
47
+ docset_id: docsetId,
48
+ sources: [],
49
+ last_refresh: new Date().toISOString(),
50
+ };
51
+ }
52
+ /**
53
+ * Update metadata for a specific web source
54
+ * @param metadata - Current metadata
55
+ * @param sourceUrl - URL of the web source
56
+ * @param sourceMetadata - New metadata for the source
57
+ * @returns Updated metadata
58
+ */
59
+ updateSourceMetadata(metadata, sourceUrl, sourceMetadata) {
60
+ const updatedMetadata = { ...metadata };
61
+ updatedMetadata.last_refresh = new Date().toISOString();
62
+ // Find existing source or create new one
63
+ const existingIndex = updatedMetadata.sources.findIndex(
64
+ (s) => s.url === sourceUrl,
65
+ );
66
+ if (existingIndex >= 0) {
67
+ // Update existing source - TypeScript knows it exists here
68
+ const existing = updatedMetadata.sources[existingIndex];
69
+ updatedMetadata.sources[existingIndex] = {
70
+ url: existing.url,
71
+ type: existing.type,
72
+ status: sourceMetadata.status ?? existing.status,
73
+ };
74
+ // Update optional fields if provided, preserve existing if not
75
+ const updated = updatedMetadata.sources[existingIndex];
76
+ if (sourceMetadata.last_fetched !== undefined) {
77
+ updated.last_fetched = sourceMetadata.last_fetched;
78
+ } else if (existing.last_fetched !== undefined) {
79
+ updated.last_fetched = existing.last_fetched;
80
+ }
81
+ if (sourceMetadata.content_hash !== undefined) {
82
+ updated.content_hash = sourceMetadata.content_hash;
83
+ } else if (existing.content_hash !== undefined) {
84
+ updated.content_hash = existing.content_hash;
85
+ }
86
+ if (sourceMetadata.files_created !== undefined) {
87
+ updated.files_created = sourceMetadata.files_created;
88
+ } else if (existing.files_created !== undefined) {
89
+ updated.files_created = existing.files_created;
90
+ }
91
+ if (sourceMetadata.error_message !== undefined) {
92
+ updated.error_message = sourceMetadata.error_message;
93
+ } else if (existing.error_message !== undefined) {
94
+ updated.error_message = existing.error_message;
95
+ }
96
+ } else {
97
+ // Add new source - ensure required fields are present
98
+ if (!sourceMetadata.type) {
99
+ throw new Error("Source type is required for new metadata entries");
100
+ }
101
+ const newSource = {
102
+ url: sourceUrl,
103
+ type: sourceMetadata.type,
104
+ status: sourceMetadata.status || "pending",
105
+ };
106
+ // Add optional fields if provided
107
+ if (sourceMetadata.last_fetched !== undefined) {
108
+ newSource.last_fetched = sourceMetadata.last_fetched;
109
+ }
110
+ if (sourceMetadata.content_hash !== undefined) {
111
+ newSource.content_hash = sourceMetadata.content_hash;
112
+ }
113
+ if (sourceMetadata.files_created !== undefined) {
114
+ newSource.files_created = sourceMetadata.files_created;
115
+ }
116
+ if (sourceMetadata.error_message !== undefined) {
117
+ newSource.error_message = sourceMetadata.error_message;
118
+ }
119
+ updatedMetadata.sources.push(newSource);
120
+ }
121
+ return updatedMetadata;
122
+ }
123
+ /**
124
+ * Get metadata for a specific web source
125
+ * @param metadata - Metadata to search
126
+ * @param sourceUrl - URL of the web source
127
+ * @returns Source metadata or null if not found
128
+ */
129
+ getSourceMetadata(metadata, sourceUrl) {
130
+ return metadata.sources.find((s) => s.url === sourceUrl) || null;
131
+ }
132
+ /**
133
+ * Check if metadata file exists
134
+ * @param docsetPath - Path to the docset directory
135
+ * @returns True if metadata file exists
136
+ */
137
+ async metadataExists(docsetPath) {
138
+ const metadataPath = path.join(docsetPath, METADATA_FILENAME);
139
+ try {
140
+ await fs.access(metadataPath);
141
+ return true;
142
+ } catch {
143
+ return false;
144
+ }
145
+ }
146
+ /**
147
+ * Remove metadata for a specific web source
148
+ * @param metadata - Current metadata
149
+ * @param sourceUrl - URL of the web source to remove
150
+ * @returns Updated metadata
151
+ */
152
+ removeSourceMetadata(metadata, sourceUrl) {
153
+ const updatedMetadata = { ...metadata };
154
+ updatedMetadata.last_refresh = new Date().toISOString();
155
+ updatedMetadata.sources = updatedMetadata.sources.filter(
156
+ (s) => s.url !== sourceUrl,
157
+ );
158
+ return updatedMetadata;
159
+ }
160
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Content loading and metadata management for agentic knowledge system
3
+ */
4
+ export * from "./types.js";
5
+ export * from "./content/index.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Content loading and metadata management for agentic knowledge system
3
+ */
4
+ export * from "./types.js";
5
+ export * from "./content/index.js";
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Types and interfaces for web content loading and management
3
+ */
4
+ /**
5
+ * Basic docset configuration (subset needed for web loading)
6
+ */
7
+ export interface DocsetConfig {
8
+ /** Unique identifier for the docset */
9
+ id: string;
10
+ /** Human-readable name of the docset */
11
+ name: string;
12
+ /** Description of what this docset contains */
13
+ description?: string;
14
+ /** Path to the documentation (relative to .knowledge folder or absolute) */
15
+ local_path: string;
16
+ /** Optional custom instruction template for this docset */
17
+ template?: string;
18
+ }
19
+ /**
20
+ * Types of web sources supported
21
+ */
22
+ export declare enum WebSourceType {
23
+ GIT_REPO = "git_repo",
24
+ DOCUMENTATION_SITE = "documentation_site",
25
+ API_DOCUMENTATION = "api_documentation"
26
+ }
27
+ /**
28
+ * Configuration for Git repository web sources
29
+ */
30
+ export interface GitRepoOptions {
31
+ /** Specific paths to extract from the repository */
32
+ paths?: string[];
33
+ /** Branch or tag to checkout (defaults to main/master) */
34
+ branch?: string;
35
+ /** Optional authentication token for private repos */
36
+ token?: string;
37
+ }
38
+ /**
39
+ * Configuration for documentation site web sources (STUB - not implemented yet)
40
+ */
41
+ export interface DocumentationSiteOptions {
42
+ /** Maximum depth to crawl */
43
+ max_depth?: number;
44
+ /** File patterns to include */
45
+ include_patterns?: string[];
46
+ /** File patterns to exclude */
47
+ exclude_patterns?: string[];
48
+ }
49
+ /**
50
+ * Configuration for API documentation web sources (STUB - not implemented yet)
51
+ */
52
+ export interface ApiDocumentationOptions {
53
+ /** Format of the API documentation */
54
+ doc_format?: string;
55
+ /** Packages or modules to include */
56
+ include_packages?: string[];
57
+ }
58
+ /**
59
+ * Configuration for a single web source
60
+ */
61
+ export interface WebSourceConfig {
62
+ /** URL of the web source */
63
+ url: string;
64
+ /** Type of web source */
65
+ type: WebSourceType;
66
+ /** Type-specific options */
67
+ options?: GitRepoOptions | DocumentationSiteOptions | ApiDocumentationOptions;
68
+ }
69
+ /**
70
+ * Metadata for a single web source download
71
+ */
72
+ export interface WebSourceMetadata {
73
+ /** URL of the web source */
74
+ url: string;
75
+ /** Type of web source */
76
+ type: WebSourceType;
77
+ /** Timestamp of last successful fetch */
78
+ last_fetched?: string;
79
+ /** Hash of content for change detection */
80
+ content_hash?: string;
81
+ /** Files created during this fetch */
82
+ files_created?: string[];
83
+ /** Status of last fetch attempt */
84
+ status: "success" | "error" | "pending";
85
+ /** Error message if status is error */
86
+ error_message?: string;
87
+ }
88
+ /**
89
+ * Metadata file stored in each docset's local_path
90
+ */
91
+ export interface DocsetMetadata {
92
+ /** Version of metadata format */
93
+ version: string;
94
+ /** Docset identifier */
95
+ docset_id: string;
96
+ /** Metadata for each web source */
97
+ sources: WebSourceMetadata[];
98
+ /** Timestamp of last refresh attempt */
99
+ last_refresh: string;
100
+ }
101
+ /**
102
+ * Metadata file name pattern
103
+ */
104
+ export declare const METADATA_FILENAME = ".agentic-metadata.json";
105
+ /**
106
+ * Web source specific error types
107
+ */
108
+ export declare enum WebSourceErrorType {
109
+ WEB_SOURCE_ERROR = "WEB_SOURCE_ERROR",
110
+ GIT_REPO_ERROR = "GIT_REPO_ERROR",
111
+ NOT_IMPLEMENTED = "NOT_IMPLEMENTED"
112
+ }
113
+ /**
114
+ * Custom error class for web source errors
115
+ */
116
+ export declare class WebSourceError extends Error {
117
+ type: WebSourceErrorType;
118
+ context?: Record<string, unknown> | undefined;
119
+ constructor(type: WebSourceErrorType, message: string, context?: Record<string, unknown> | undefined);
120
+ }
121
+ /**
122
+ * Extended docset config that includes web sources
123
+ */
124
+ export interface DocsetConfigWithWebSources extends DocsetConfig {
125
+ /** Optional web sources to load content from */
126
+ web_sources?: WebSourceConfig[];
127
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Types and interfaces for web content loading and management
3
+ */
4
+ /**
5
+ * Types of web sources supported
6
+ */
7
+ export var WebSourceType;
8
+ (function (WebSourceType) {
9
+ // eslint-disable-next-line no-unused-vars
10
+ WebSourceType["GIT_REPO"] = "git_repo";
11
+ // eslint-disable-next-line no-unused-vars
12
+ WebSourceType["DOCUMENTATION_SITE"] = "documentation_site";
13
+ // eslint-disable-next-line no-unused-vars
14
+ WebSourceType["API_DOCUMENTATION"] = "api_documentation";
15
+ })(WebSourceType || (WebSourceType = {}));
16
+ /**
17
+ * Metadata file name pattern
18
+ */
19
+ export const METADATA_FILENAME = ".agentic-metadata.json";
20
+ /**
21
+ * Web source specific error types
22
+ */
23
+ export var WebSourceErrorType;
24
+ (function (WebSourceErrorType) {
25
+ // eslint-disable-next-line no-unused-vars
26
+ WebSourceErrorType["WEB_SOURCE_ERROR"] = "WEB_SOURCE_ERROR";
27
+ // eslint-disable-next-line no-unused-vars
28
+ WebSourceErrorType["GIT_REPO_ERROR"] = "GIT_REPO_ERROR";
29
+ // eslint-disable-next-line no-unused-vars
30
+ WebSourceErrorType["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
31
+ })(WebSourceErrorType || (WebSourceErrorType = {}));
32
+ /**
33
+ * Custom error class for web source errors
34
+ */
35
+ export class WebSourceError extends Error {
36
+ type;
37
+ context;
38
+ constructor(
39
+ // eslint-disable-next-line no-unused-vars
40
+ type, message,
41
+ // eslint-disable-next-line no-unused-vars
42
+ context) {
43
+ super(message);
44
+ this.type = type;
45
+ this.context = context;
46
+ this.name = "WebSourceError";
47
+ }
48
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@codemcp/knowledge-content-loader",
3
+ "version": "0.0.1",
4
+ "description": "Web content loading and metadata management for agentic knowledge system",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.build.json",
19
+ "build:watch": "tsc -p tsconfig.build.json --watch",
20
+ "clean": "rimraf dist",
21
+ "dev": "tsc -p tsconfig.build.json --watch",
22
+ "lint": "oxlint && eslint .",
23
+ "lint:fix": "oxlint --fix && eslint . --fix",
24
+ "format:check": "prettier --check .",
25
+ "format:fix": "prettier --write .",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
28
+ "test:coverage": "vitest run --coverage",
29
+ "typecheck": "tsc --noEmit"
30
+ },
31
+ "dependencies": {
32
+ "simple-git": "^3.22.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^24.3.0",
36
+ "rimraf": "^6.0.1",
37
+ "typescript": "^5.9.2",
38
+ "vitest": "^3.2.4"
39
+ },
40
+ "keywords": [
41
+ "agentic",
42
+ "knowledge",
43
+ "content-loading",
44
+ "web-sources",
45
+ "git",
46
+ "metadata"
47
+ ],
48
+ "author": "Oliver Jägle <github@beimir.net>",
49
+ "license": "MIT"
50
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Configuration discovery functionality
3
+ */
4
+ /**
5
+ * Find the configuration path by walking up the directory tree
6
+ * @param startPath - Starting directory path (defaults to current working directory)
7
+ * @returns Path to config file or null if not found
8
+ */
9
+ export declare function findConfigPath(startPath?: string): Promise<string | null>;
10
+ /**
11
+ * Synchronous version of findConfigPath for cases where async is not suitable
12
+ * @param startPath - Starting directory path (defaults to current working directory)
13
+ * @returns Path to config file or null if not found
14
+ */
15
+ export declare function findConfigPathSync(startPath?: string): string | null;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Configuration discovery functionality
3
+ */
4
+ import { promises as fs } from "node:fs";
5
+ import * as fsSync from "node:fs";
6
+ import { resolve, dirname, join } from "node:path";
7
+ import { CONFIG_DIR, CONFIG_FILENAME } from "../types.js";
8
+ /**
9
+ * Find the configuration path by walking up the directory tree
10
+ * @param startPath - Starting directory path (defaults to current working directory)
11
+ * @returns Path to config file or null if not found
12
+ */
13
+ export async function findConfigPath(startPath = process.cwd()) {
14
+ let currentDir = resolve(startPath);
15
+ while (true) {
16
+ const configDir = join(currentDir, CONFIG_DIR);
17
+ const configPath = join(configDir, CONFIG_FILENAME);
18
+ try {
19
+ const stats = await fs.stat(configPath);
20
+ if (stats.isFile()) {
21
+ return configPath;
22
+ }
23
+ }
24
+ catch {
25
+ // File doesn't exist, continue searching
26
+ }
27
+ // Move up one directory
28
+ const parentDir = dirname(currentDir);
29
+ if (parentDir === currentDir) {
30
+ // Reached filesystem root
31
+ break;
32
+ }
33
+ currentDir = parentDir;
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * Synchronous version of findConfigPath for cases where async is not suitable
39
+ * @param startPath - Starting directory path (defaults to current working directory)
40
+ * @returns Path to config file or null if not found
41
+ */
42
+ export function findConfigPathSync(startPath = process.cwd()) {
43
+ let currentDir = resolve(startPath);
44
+ while (true) {
45
+ const configDir = join(currentDir, CONFIG_DIR);
46
+ const configPath = join(configDir, CONFIG_FILENAME);
47
+ try {
48
+ const stats = fsSync.statSync(configPath);
49
+ if (stats.isFile()) {
50
+ return configPath;
51
+ }
52
+ }
53
+ catch {
54
+ // File doesn't exist, continue searching
55
+ }
56
+ // Move up one directory
57
+ const parentDir = dirname(currentDir);
58
+ if (parentDir === currentDir) {
59
+ // Reached filesystem root
60
+ break;
61
+ }
62
+ currentDir = parentDir;
63
+ }
64
+ return null;
65
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Configuration loading and validation
3
+ */
4
+ import type { KnowledgeConfig } from "../types.js";
5
+ /**
6
+ * Load configuration from a YAML file with strict template validation
7
+ * @param configPath - Path to the configuration file
8
+ * @returns Parsed configuration object
9
+ */
10
+ export declare function loadConfig(configPath: string): Promise<KnowledgeConfig>;
11
+ /**
12
+ * Synchronous version of loadConfig with strict template validation
13
+ * @param configPath - Path to the configuration file
14
+ * @returns Parsed configuration object
15
+ */
16
+ export declare function loadConfigSync(configPath: string): KnowledgeConfig;
17
+ /**
18
+ * Validate a configuration object
19
+ * @param config - Configuration to validate
20
+ * @returns True if valid, false if invalid
21
+ */
22
+ export declare function validateConfig(config: unknown): config is KnowledgeConfig;