@@ -7,16 +7,17 @@ import {
77 type ClientConfigurationDocument ,
88} from "./ClientConfigurationDocument.js" ;
99import { access } from "node:fs/promises" ;
10- import { resolve } from "node:path" ;
10+ import { isAbsolute , resolve } from "node:path" ;
1111
1212import { z } from "zod" ;
1313import { valid } from "semver" ;
1414
1515import { PRODUCT_IDENTITY } from "../identity.js" ;
16+ import { CURRENT_ENTRYPOINT_PATH } from "../process/CurrentEntrypointPath.js" ;
1617import { MCP_STARTUP_POLICY } from "../mcpStartupPolicy.js" ;
1718import {
1819 clientRegistrationPackageReference ,
19- isOwnedClientRegistrationCommand ,
20+ classifyClientRegistrationCommand ,
2021 packageRunnerRegistrationCommand ,
2122} from "./ClientRegistrationIdentity.js" ;
2223import {
@@ -50,6 +51,11 @@ export type ClientRegistrationStatus = ClientRegistrationStatusBase &
5051 readonly state : "stale" ;
5152 readonly remediation : string ;
5253 }
54+ | {
55+ readonly command : RegistrationCommand ;
56+ readonly state : "unknown" ;
57+ readonly remediation : string ;
58+ }
5359 | {
5460 readonly command : readonly [ ] ;
5561 readonly state : "missing" | "invalid" | "manual" ;
@@ -93,7 +99,7 @@ export interface ClientRegistrationInspection {
9399/** Project diagnostics from the same inspection used to select maintenance. */
94100export const readClientRegistrationStatuses = async (
95101 home : string ,
96- currentCommandPath : string = resolve ( process . argv [ 1 ] ?? "unknown" ) ,
102+ currentCommandPath : string | undefined = CURRENT_ENTRYPOINT_PATH ,
97103 options : ClientRegistrationReadOptions = { } ,
98104) : Promise < readonly ClientRegistrationStatus [ ] > =>
99105 (
@@ -103,7 +109,7 @@ export const readClientRegistrationStatuses = async (
103109/** Parse effective registrations and their client-specific activation once. */
104110export const readClientRegistrationInspections = async (
105111 home : string ,
106- currentCommandPath : string = resolve ( process . argv [ 1 ] ?? "unknown" ) ,
112+ currentCommandPath : string | undefined = CURRENT_ENTRYPOINT_PATH ,
107113 options : ClientRegistrationReadOptions = { } ,
108114) : Promise < readonly ClientRegistrationInspection [ ] > => {
109115 const inspections : ClientRegistrationInspection [ ] = [ ] ;
@@ -219,26 +225,32 @@ export const readClientRegistrationInspections = async (
219225 const packageVersionDrift =
220226 packageVersion !== undefined &&
221227 packageVersion !== PRODUCT_IDENTITY . packageVersion ;
228+ const alignment = registrationAligned (
229+ registration ,
230+ effectiveClient ,
231+ currentCommandPath ,
232+ options . platform ?? process . platform ,
233+ ) ;
222234 record (
223235 configuredStatus (
224236 effectiveClient ,
225237 command ,
226- activation === "enabled" &&
227- ! packageVersionDrift &&
228- registrationAligned (
229- registration ,
230- effectiveClient ,
231- currentCommandPath ,
232- options . platform ?? process . platform ,
233- ) &&
234- ( parsed . dialect !== "dsh" || dshDocument ( parsed . document ) . ready ) &&
235- policyBlock === undefined
236- ? "aligned"
237- : "stale" ,
238+ alignment === "unknown"
239+ ? "unknown"
240+ : activation === "enabled" &&
241+ ! packageVersionDrift &&
242+ alignment === "aligned" &&
243+ ( parsed . dialect !== "dsh" ||
244+ dshDocument ( parsed . document ) . ready ) &&
245+ policyBlock === undefined
246+ ? "aligned"
247+ : "stale" ,
238248 policyBlock ??
239249 ( packageVersionDrift
240250 ? packageVersionRemediation ( packageReference ?? "" , client )
241- : undefined ) ,
251+ : alignment === "unknown"
252+ ? unknownEntryPointRemediation ( )
253+ : undefined ) ,
242254 packageReference ,
243255 ) ,
244256 activation ,
@@ -275,71 +287,85 @@ const registrationActivation = (
275287const registrationAligned = (
276288 registration : z . output < typeof registrationSchema > ,
277289 client : SetupClient ,
278- currentCommandPath : string ,
290+ currentCommandPath : string | undefined ,
279291 platform : NodeJS . Platform ,
280- ) : boolean => {
292+ ) : "aligned" | "stale" | "unknown" => {
281293 const command = [ registration . command , ...registration . args ] ;
282- if ( ! isOwnedClientRegistrationCommand ( command , currentCommandPath ) )
283- return false ;
294+ const identity = classifyClientRegistrationCommand (
295+ command ,
296+ currentCommandPath ,
297+ ) ;
298+ if ( identity === "unknown" ) return "unknown" ;
299+ if ( identity === "foreign" ) return "stale" ;
284300 if (
285301 ( client . name === "codex" || client . name === "grok_build" ) &&
286302 registration . startup_timeout_sec !==
287303 MCP_STARTUP_POLICY . codexStartupTimeoutSeconds
288304 )
289- return false ;
305+ return "stale" ;
290306 if (
291307 client . name === "kimi" &&
292308 ( registration . startupTimeoutMs !==
293309 MCP_STARTUP_POLICY . kimiStartupTimeoutMs ||
294310 registration . toolTimeoutMs !== MCP_STARTUP_POLICY . kimiToolTimeoutMs )
295311 )
296- return false ;
312+ return "stale" ;
297313 if (
298314 ( client . format === "kimi" ||
299315 client . format === "omp" ||
300316 client . format === "pi" ) &&
301317 registration . type !== undefined &&
302318 registration . type !== "stdio"
303319 )
304- return false ;
305- if ( client . format === "vscode" && registration . type !== "stdio" ) return false ;
320+ return "stale" ;
321+ if ( client . format === "vscode" && registration . type !== "stdio" )
322+ return "stale" ;
306323 // A Harness registration only connects as the rea stdio server; another
307324 // server name or transport leaves the session without REA tools.
308325 if (
309326 client . format === "dsh" &&
310327 ( registration . serverName !== "rea" || registration . transport !== "stdio" )
311328 )
312- return false ;
329+ return "stale" ;
313330 if (
314331 client . format === "copilot_cli" &&
315332 ( registration . type !== "stdio" ||
316333 JSON . stringify ( registration . tools ) !== JSON . stringify ( [ "*" ] ) )
317334 )
318- return false ;
335+ return "stale" ;
319336 if ( client . format === "commandcode" && registration . transport !== "stdio" )
320- return false ;
337+ return "stale" ;
321338 if (
339+ ( [ "npx" , "bunx" ] as const ) . some ( ( runner ) => {
340+ const expected = packageRunnerRegistrationCommand ( runner , platform ) ;
341+ return (
342+ command . length === expected . length &&
343+ command . every ( ( argument , index ) => argument === expected [ index ] )
344+ ) ;
345+ } )
346+ )
347+ return "aligned" ;
348+ if (
349+ currentCommandPath !== undefined &&
350+ currentCommandPath . length > 0 &&
322351 command . length === 3 &&
323352 command [ 2 ] === "mcp" &&
353+ isAbsolute ( command [ 0 ] ?? "" ) &&
354+ isAbsolute ( command [ 1 ] ?? "" ) &&
324355 resolve ( command [ 0 ] ?? "" ) === resolve ( process . execPath ) &&
325356 resolve ( command [ 1 ] ?? "" ) === currentCommandPath
326357 )
327- return true ;
358+ return "aligned" ;
328359 if (
329- ( [ "npx" , "bunx" ] as const ) . some ( ( runner ) => {
330- const runnerCommand = packageRunnerRegistrationCommand ( runner , platform ) ;
331- return (
332- command . length === runnerCommand . length &&
333- command . every ( ( argument , index ) => argument === runnerCommand [ index ] )
334- ) ;
335- } )
336- )
337- return true ;
338- return (
360+ currentCommandPath !== undefined &&
361+ currentCommandPath . length > 0 &&
339362 command . length === 2 &&
340363 command [ 1 ] === "mcp" &&
364+ isAbsolute ( command [ 0 ] ?? "" ) &&
341365 resolve ( command [ 0 ] ?? "" ) === currentCommandPath
342- ) ;
366+ )
367+ return "aligned" ;
368+ return "stale" ;
343369} ;
344370
345371const parseRegistration = (
@@ -400,10 +426,13 @@ const remediation = (client: SetupClient): string => {
400426 return `Quit ${ name } fully, run rea setup to refresh this registration, then start ${ name } again. A running ${ name } can rewrite its configuration from memory and drop the registration.` ;
401427} ;
402428
429+ const unknownEntryPointRemediation = ( ) : string =>
430+ "The existing registration was retained because its executable identity cannot be verified. Run the installed REA CLI or a supported package runner, then rerun rea doctor; no registration was changed." ;
431+
403432const configuredStatus = (
404433 client : SetupClient ,
405434 command : RegistrationCommand ,
406- state : "aligned" | "stale" ,
435+ state : "aligned" | "stale" | "unknown" ,
407436 policyRemediation ?: string ,
408437 packageReference ?: string ,
409438) : ClientRegistrationStatus =>
0 commit comments