@contextstream/mcp-server 0.2.6 → 0.2.8

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.
@@ -1,150 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
-
4
- export interface WorkspaceConfig {
5
- workspace_id: string;
6
- workspace_name?: string;
7
- project_id?: string;
8
- project_name?: string;
9
- associated_at?: string;
10
- }
11
-
12
- export interface ParentMapping {
13
- pattern: string; // e.g., "/home/escott/dev/maker/*"
14
- workspace_id: string;
15
- workspace_name: string;
16
- }
17
-
18
- const CONFIG_DIR = '.contextstream';
19
- const CONFIG_FILE = 'config.json';
20
- const GLOBAL_MAPPINGS_FILE = '.contextstream-mappings.json';
21
-
22
- /**
23
- * Read workspace config from a repo's .contextstream/config.json
24
- */
25
- export function readLocalConfig(repoPath: string): WorkspaceConfig | null {
26
- const configPath = path.join(repoPath, CONFIG_DIR, CONFIG_FILE);
27
- try {
28
- if (fs.existsSync(configPath)) {
29
- const content = fs.readFileSync(configPath, 'utf-8');
30
- return JSON.parse(content) as WorkspaceConfig;
31
- }
32
- } catch (e) {
33
- console.error(`Failed to read config from ${configPath}:`, e);
34
- }
35
- return null;
36
- }
37
-
38
- /**
39
- * Write workspace config to a repo's .contextstream/config.json
40
- */
41
- export function writeLocalConfig(repoPath: string, config: WorkspaceConfig): boolean {
42
- const configDir = path.join(repoPath, CONFIG_DIR);
43
- const configPath = path.join(configDir, CONFIG_FILE);
44
- try {
45
- if (!fs.existsSync(configDir)) {
46
- fs.mkdirSync(configDir, { recursive: true });
47
- }
48
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
49
- return true;
50
- } catch (e) {
51
- console.error(`Failed to write config to ${configPath}:`, e);
52
- return false;
53
- }
54
- }
55
-
56
- /**
57
- * Read global parent folder mappings from user's home directory
58
- */
59
- export function readGlobalMappings(): ParentMapping[] {
60
- const homeDir = process.env.HOME || process.env.USERPROFILE || '';
61
- const mappingsPath = path.join(homeDir, GLOBAL_MAPPINGS_FILE);
62
- try {
63
- if (fs.existsSync(mappingsPath)) {
64
- const content = fs.readFileSync(mappingsPath, 'utf-8');
65
- return JSON.parse(content) as ParentMapping[];
66
- }
67
- } catch (e) {
68
- console.error(`Failed to read global mappings:`, e);
69
- }
70
- return [];
71
- }
72
-
73
- /**
74
- * Write global parent folder mappings to user's home directory
75
- */
76
- export function writeGlobalMappings(mappings: ParentMapping[]): boolean {
77
- const homeDir = process.env.HOME || process.env.USERPROFILE || '';
78
- const mappingsPath = path.join(homeDir, GLOBAL_MAPPINGS_FILE);
79
- try {
80
- fs.writeFileSync(mappingsPath, JSON.stringify(mappings, null, 2));
81
- return true;
82
- } catch (e) {
83
- console.error(`Failed to write global mappings:`, e);
84
- return false;
85
- }
86
- }
87
-
88
- /**
89
- * Add a new parent folder mapping
90
- */
91
- export function addGlobalMapping(mapping: ParentMapping): boolean {
92
- const mappings = readGlobalMappings();
93
- // Remove any existing mapping with same pattern
94
- const filtered = mappings.filter(m => m.pattern !== mapping.pattern);
95
- filtered.push(mapping);
96
- return writeGlobalMappings(filtered);
97
- }
98
-
99
- /**
100
- * Check if a repo path matches any parent folder mapping
101
- */
102
- export function findMatchingMapping(repoPath: string): ParentMapping | null {
103
- const mappings = readGlobalMappings();
104
- const normalizedRepo = path.normalize(repoPath);
105
-
106
- for (const mapping of mappings) {
107
- // Handle wildcard patterns like "/home/escott/dev/maker/*"
108
- if (mapping.pattern.endsWith('/*')) {
109
- const parentDir = mapping.pattern.slice(0, -2);
110
- if (normalizedRepo.startsWith(parentDir + path.sep)) {
111
- return mapping;
112
- }
113
- } else if (normalizedRepo === path.normalize(mapping.pattern)) {
114
- return mapping;
115
- }
116
- }
117
- return null;
118
- }
119
-
120
- /**
121
- * Resolve workspace for a given repo path using the discovery chain:
122
- * 1. Local .contextstream/config.json
123
- * 2. Parent folder heuristic mappings
124
- * 3. Return null (ambiguous - needs user selection)
125
- */
126
- export function resolveWorkspace(repoPath: string): {
127
- config: WorkspaceConfig | null;
128
- source: 'local_config' | 'parent_mapping' | 'ambiguous';
129
- } {
130
- // Step 1: Check local config
131
- const localConfig = readLocalConfig(repoPath);
132
- if (localConfig) {
133
- return { config: localConfig, source: 'local_config' };
134
- }
135
-
136
- // Step 2: Check parent folder mappings
137
- const mapping = findMatchingMapping(repoPath);
138
- if (mapping) {
139
- return {
140
- config: {
141
- workspace_id: mapping.workspace_id,
142
- workspace_name: mapping.workspace_name,
143
- },
144
- source: 'parent_mapping',
145
- };
146
- }
147
-
148
- // Step 3: Ambiguous - needs user selection
149
- return { config: null, source: 'ambiguous' };
150
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "moduleResolution": "Node",
6
- "outDir": "dist",
7
- "rootDir": "src",
8
- "esModuleInterop": true,
9
- "resolveJsonModule": true,
10
- "skipLibCheck": true,
11
- "strict": true
12
- },
13
- "include": ["src/**/*"]
14
- }