core: add self-hosted weekly dashboard and machine workers
Reuse the existing weekly pace, reset history and daily budgets across multiple machines without multiplying shared account quota. Coordinate profile-bound official CLI logins through transient authorization responses while keeping provider credentials local to each CLI. Release as version 1.2.0. Refs #19
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System.Text.Json;
|
||||
|
||||
// Test-only CLI. identity.txt contains a synthetic email, never a provider credential.
|
||||
var home=Environment.GetEnvironmentVariable("CLAUDE_CONFIG_DIR") ?? Environment.GetEnvironmentVariable("CODEX_HOME");
|
||||
if(home is null) return 2;
|
||||
Directory.CreateDirectory(home);
|
||||
var identity=Path.Combine(home,"identity.txt");
|
||||
if(args is ["auth","login",..])
|
||||
{
|
||||
if(File.Exists(Path.Combine(home,"overflow-login")))
|
||||
{
|
||||
Console.Write(new string('x',128*1024));Console.Out.Flush();
|
||||
_=Console.ReadLine();return 1;
|
||||
}
|
||||
Console.Write("https://claude.ai/oauth/authorize?state=fixture-state\nPaste code here if prompted: ");
|
||||
Console.Out.Flush();
|
||||
var response=Console.ReadLine();
|
||||
if(response is not ("fixture-code#fixture-state" or "wrong-code#fixture-state")) return 1;
|
||||
File.WriteAllText(identity,response.StartsWith("wrong",StringComparison.Ordinal)?"[email protected]":"[email protected]");
|
||||
Console.WriteLine("Login successful");return 0;
|
||||
}
|
||||
if(args is ["auth","status",..])
|
||||
{
|
||||
if(!File.Exists(identity)){Console.WriteLine("{\"loggedIn\":false}");return 1;}
|
||||
var email=File.ReadAllText(identity);
|
||||
Console.WriteLine(email=="[email protected]"?"{\"loggedIn\":true,\"email\":\"[email protected]\"}":"{\"loggedIn\":true,\"email\":\"[email protected]\"}");return 0;
|
||||
}
|
||||
if(args is ["login","--device-auth"])
|
||||
{
|
||||
Console.WriteLine("\u001b[94mhttps://auth.openai.com/codex/device\u001b[0m\n\u001b[94mABCD-12345\u001b[0m");
|
||||
while(!File.Exists(Path.Combine(home,"authorize-device")))await Task.Delay(50);
|
||||
File.WriteAllText(identity,"[email protected]");return 0;
|
||||
}
|
||||
if(args is ["app-server"])
|
||||
{
|
||||
while(Console.ReadLine() is {} line)
|
||||
{
|
||||
using var json=JsonDocument.Parse(line);
|
||||
var root=json.RootElement;
|
||||
if(!root.TryGetProperty("id",out var id))continue;
|
||||
var number=id.GetInt32();
|
||||
var method=root.GetProperty("method").GetString();
|
||||
if(method=="initialize")Console.WriteLine("{\"id\":1,\"result\":{}}");
|
||||
else if(method=="account/read")
|
||||
Console.WriteLine(File.Exists(identity)?"{\"id\":2,\"result\":{\"account\":{\"type\":\"chatgpt\",\"email\":\"[email protected]\"}}}":"{\"id\":2,\"result\":{\"account\":null}}");
|
||||
else if(method=="account/rateLimits/read")
|
||||
{
|
||||
var reset=DateTimeOffset.UtcNow.AddDays(3).ToUnixTimeSeconds();
|
||||
Console.WriteLine($"{{\"id\":{number},\"result\":{{\"rateLimits\":{{\"limitId\":\"codex\",\"secondary\":{{\"usedPercent\":65,\"windowDurationMins\":10080,\"resetsAt\":{reset}}}}}}}}}");
|
||||
}
|
||||
else return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
Reference in New Issue
Block a user