@claudetools/tools 0.7.2 → 0.7.3
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/dist/helpers/config.d.ts +2 -1
- package/dist/helpers/config.js +35 -17
- package/package.json +1 -1
package/dist/helpers/config.d.ts
CHANGED
|
@@ -34,7 +34,8 @@ export declare function resolveProjectId(): string;
|
|
|
34
34
|
export declare function resolveProjectIdAsync(): Promise<string>;
|
|
35
35
|
/**
|
|
36
36
|
* Gets the default project ID (synchronous version)
|
|
37
|
-
*
|
|
37
|
+
* ALWAYS checks session-context.md first (even if cached), then config, then falls back to cwd resolution
|
|
38
|
+
* This handles race conditions where MCP server starts before session-start hook writes the file
|
|
38
39
|
*/
|
|
39
40
|
export declare function getDefaultProjectId(): string;
|
|
40
41
|
/**
|
package/dist/helpers/config.js
CHANGED
|
@@ -100,11 +100,21 @@ export function resolveProjectId() {
|
|
|
100
100
|
* Should be called during server startup
|
|
101
101
|
*/
|
|
102
102
|
export async function resolveProjectIdAsync() {
|
|
103
|
-
//
|
|
103
|
+
// ALWAYS check session-context.md first (even if cached) - handles race condition
|
|
104
|
+
// where MCP server starts before Claude Code's session-start hook writes the file
|
|
105
|
+
const sessionProjectId = getProjectIdFromSessionContext();
|
|
106
|
+
if (sessionProjectId) {
|
|
107
|
+
if (resolvedProjectId !== sessionProjectId) {
|
|
108
|
+
mcpLogger.info('MEMORY', `Project resolved from session context: ${sessionProjectId} (was: ${resolvedProjectId})`);
|
|
109
|
+
resolvedProjectId = sessionProjectId;
|
|
110
|
+
}
|
|
111
|
+
return resolvedProjectId;
|
|
112
|
+
}
|
|
113
|
+
// Return cached result if available (and no session-context.md)
|
|
104
114
|
if (resolvedProjectId) {
|
|
105
115
|
return resolvedProjectId;
|
|
106
116
|
}
|
|
107
|
-
// Check environment variable
|
|
117
|
+
// Check environment variable
|
|
108
118
|
if (process.env.CLAUDETOOLS_PROJECT_ID) {
|
|
109
119
|
const envProjectId = process.env.CLAUDETOOLS_PROJECT_ID;
|
|
110
120
|
// Validate UUID format
|
|
@@ -116,14 +126,6 @@ export async function resolveProjectIdAsync() {
|
|
|
116
126
|
mcpLogger.debug('MEMORY', `Using project ID from env: ${resolvedProjectId}`);
|
|
117
127
|
return resolvedProjectId;
|
|
118
128
|
}
|
|
119
|
-
// Check session-context.md (written by Claude Code's session-start hook)
|
|
120
|
-
// This is the most reliable source since MCP server's cwd isn't the project dir
|
|
121
|
-
const sessionProjectId = getProjectIdFromSessionContext();
|
|
122
|
-
if (sessionProjectId) {
|
|
123
|
-
resolvedProjectId = sessionProjectId;
|
|
124
|
-
mcpLogger.info('MEMORY', `Project resolved from session context: ${resolvedProjectId}`);
|
|
125
|
-
return resolvedProjectId;
|
|
126
|
-
}
|
|
127
129
|
const cwd = process.cwd();
|
|
128
130
|
// Check projects.json cache
|
|
129
131
|
const binding = findProjectBinding(cwd);
|
|
@@ -165,16 +167,23 @@ export async function resolveProjectIdAsync() {
|
|
|
165
167
|
let _defaultProjectId = null;
|
|
166
168
|
/**
|
|
167
169
|
* Gets the default project ID (synchronous version)
|
|
168
|
-
*
|
|
170
|
+
* ALWAYS checks session-context.md first (even if cached), then config, then falls back to cwd resolution
|
|
171
|
+
* This handles race conditions where MCP server starts before session-start hook writes the file
|
|
169
172
|
*/
|
|
170
173
|
export function getDefaultProjectId() {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
// Check session-context.md first (most reliable for MCP server)
|
|
174
|
+
// ALWAYS check session-context.md first - it may have been written after we cached a fallback value
|
|
175
|
+
// This handles the race condition where MCP server starts before Claude Code's session-start hook runs
|
|
175
176
|
const sessionProjectId = getProjectIdFromSessionContext();
|
|
176
177
|
if (sessionProjectId) {
|
|
177
|
-
|
|
178
|
+
// Update cache if different (session-context.md is authoritative)
|
|
179
|
+
if (_defaultProjectId !== sessionProjectId) {
|
|
180
|
+
mcpLogger.debug('MEMORY', `Updating project ID from session-context: ${sessionProjectId} (was: ${_defaultProjectId})`);
|
|
181
|
+
_defaultProjectId = sessionProjectId;
|
|
182
|
+
}
|
|
183
|
+
return _defaultProjectId;
|
|
184
|
+
}
|
|
185
|
+
// If we have a cached value and no session-context.md, use cache
|
|
186
|
+
if (_defaultProjectId) {
|
|
178
187
|
return _defaultProjectId;
|
|
179
188
|
}
|
|
180
189
|
// Try config second
|
|
@@ -198,10 +207,19 @@ export function getDefaultProjectId() {
|
|
|
198
207
|
* Async version for server startup
|
|
199
208
|
*/
|
|
200
209
|
export async function getDefaultProjectIdAsync() {
|
|
210
|
+
// ALWAYS check session-context.md first - same as sync version
|
|
211
|
+
const sessionProjectId = getProjectIdFromSessionContext();
|
|
212
|
+
if (sessionProjectId) {
|
|
213
|
+
if (_defaultProjectId !== sessionProjectId) {
|
|
214
|
+
mcpLogger.debug('MEMORY', `Updating project ID from session-context (async): ${sessionProjectId} (was: ${_defaultProjectId})`);
|
|
215
|
+
_defaultProjectId = sessionProjectId;
|
|
216
|
+
}
|
|
217
|
+
return _defaultProjectId;
|
|
218
|
+
}
|
|
201
219
|
if (_defaultProjectId) {
|
|
202
220
|
return _defaultProjectId;
|
|
203
221
|
}
|
|
204
|
-
// Try config
|
|
222
|
+
// Try config
|
|
205
223
|
if (config.defaultProjectId) {
|
|
206
224
|
if (!isValidProjectId(config.defaultProjectId)) {
|
|
207
225
|
// Legacy format - convert to local_ format instead of throwing
|