44using System . Text ;
55using System . Text . Json ;
66using System . Text . RegularExpressions ;
7+ using OpenClaw . Shared ;
78using OpenClaw . Shared . Mcp ;
89
910namespace OpenClaw . WinNode . Cli ;
@@ -19,6 +20,7 @@ internal sealed class WinNodeOptions
1920 public string ? McpUrlOverride { get ; set ; }
2021 public int ? McpPortOverride { get ; set ; }
2122 public string ? McpTokenOverride { get ; set ; }
23+ public string ? Identity { get ; set ; }
2224 public bool Verbose { get ; set ; }
2325}
2426
@@ -151,6 +153,16 @@ public static async Task<int> RunAsync(
151153 return 2 ;
152154 }
153155
156+ try
157+ {
158+ options . Identity = OpenClawAppIdentity . ResolveIdentity ( envLookup , options . Identity ) ;
159+ }
160+ catch ( ArgumentException ex )
161+ {
162+ stderr . WriteLine ( $ "Argument error: { ex . Message } ") ;
163+ return 2 ;
164+ }
165+
154166 var token = ResolveAuthToken ( options , envLookup , stderr ) ;
155167 if ( token . Source == "error" )
156168 {
@@ -533,7 +545,9 @@ private static int ResolveEnvPort(Func<string, string?> envLookup, bool verbose,
533545 /// per-tool secret env-var convention — same shape as <c>GITHUB_TOKEN</c>,
534546 /// <c>ANTHROPIC_API_KEY</c>, <c>NUGET_API_KEY</c>.</item>
535547 /// <item>The on-disk token file the tray writes when MCP is enabled —
536- /// <c>%APPDATA%\OpenClawTray\mcp-token.txt</c> by default, or
548+ /// <c>%APPDATA%\OpenClawTray\mcp-token.txt</c> by default,
549+ /// <c>%APPDATA%\OpenClawTray-Dev\mcp-token.txt</c> when
550+ /// <c>--identity dev</c> or <c>OPENCLAW_APP_IDENTITY=dev</c> is set, or
537551 /// <c>$OPENCLAW_TRAY_DATA_DIR\mcp-token.txt</c> when the tray was launched
538552 /// with that sandbox override (the integration test fixture uses it).</item>
539553 /// </list>
@@ -559,7 +573,7 @@ internal static AuthTokenResult ResolveAuthToken(
559573 return new AuthTokenResult ( envToken , "OPENCLAW_MCP_TOKEN" ) ;
560574 }
561575
562- var path = ResolveTokenPath ( envLookup ) ;
576+ var path = ResolveTokenPath ( envLookup , options . Identity ) ;
563577
564578 // F-08: resolve to canonical form and require the result still live
565579 // under the requested directory tree. Defeats a same-user attacker
@@ -697,21 +711,15 @@ private static bool PathStartsWith(string candidate, string prefix)
697711 || normCandidate . StartsWith ( normPrefix + Path . DirectorySeparatorChar , cmp ) ;
698712 }
699713
700- internal static string ResolveTokenPath ( Func < string , string ? > envLookup )
714+ internal static string ResolveTokenPath ( Func < string , string ? > envLookup , string ? identity = null )
701715 {
702716 // Mirror SettingsManager.SettingsDirectoryPath: when the tray was
703717 // launched with OPENCLAW_TRAY_DATA_DIR, settings (including the token
704718 // file) live under that directory. The same env var is honored here
705719 // so a CLI invoked in the same shell as a sandboxed tray Just Works,
706720 // and the integration test fixture can redirect both the producer
707721 // (tray) and the consumer (CLI) with one env var.
708- var dataDirOverride = envLookup ( "OPENCLAW_TRAY_DATA_DIR" ) ;
709- var dir = ! string . IsNullOrWhiteSpace ( dataDirOverride )
710- ? dataDirOverride !
711- : Path . Combine (
712- Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ,
713- "OpenClawTray" ) ;
714- return Path . Combine ( dir , "mcp-token.txt" ) ;
722+ return OpenClawAppIdentity . ResolveMcpTokenPath ( envLookup , identity ) ;
715723 }
716724
717725 /// <summary>
@@ -774,6 +782,9 @@ internal static WinNodeOptions ParseArgs(string[] args)
774782 case "--mcp-token" :
775783 options . McpTokenOverride = RequireValue ( args , ref i , arg ) ;
776784 break ;
785+ case "--identity" :
786+ options . Identity = OpenClawAppIdentity . NormalizeIdentity ( RequireValue ( args , ref i , arg ) ) ;
787+ break ;
777788 case "--verbose" :
778789 options . Verbose = true ;
779790 break ;
@@ -830,6 +841,8 @@ internal static void PrintUsage(TextWriter stdout)
830841 stdout . WriteLine ( " --mcp-token <token> Bearer token (testing/explicit overrides only - visible to" ) ;
831842 stdout . WriteLine ( " other processes via the OS process listing). Prefer" ) ;
832843 stdout . WriteLine ( " $OPENCLAW_MCP_TOKEN or %APPDATA%\\ OpenClawTray\\ mcp-token.txt" ) ;
844+ stdout . WriteLine ( " --identity <release|dev> Select tray profile for default token lookup" ) ;
845+ stdout . WriteLine ( " (default: $OPENCLAW_APP_IDENTITY or release)" ) ;
833846 stdout . WriteLine ( " --verbose Print endpoint + ignored flags to stderr" ) ;
834847 stdout . WriteLine ( " --help, -h Show this help" ) ;
835848 stdout . WriteLine ( ) ;
0 commit comments