showrunner-agent-staging 0.5.135-staging.2015 → 0.5.135-staging.2016
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Account } from "./account-protocol.js";
|
|
2
|
+
import type { AccountProvider } from "./provider-account-store.js";
|
|
3
|
+
/** Every provider login variable. A managed account's own folder holds its login, so none of these reach it. */
|
|
4
|
+
export declare const providerAuthenticationVariable: RegExp;
|
|
5
|
+
export type AccountCredentials = {
|
|
6
|
+
type: "existing" | "managed";
|
|
7
|
+
billing: Account["billing"];
|
|
8
|
+
};
|
|
9
|
+
/** A sign-in on this Mac: `auth login`, and reading which sign-in is there. */
|
|
10
|
+
export declare const signInCredentials: AccountCredentials;
|
|
11
|
+
/**
|
|
12
|
+
* The environment of every provider process an account starts: the account decides its credentials.
|
|
13
|
+
* Claude Code prefers an exported API key over the person's Claude sign-in, so the key reaches Claude
|
|
14
|
+
* only when the person picked the API key as the account. Codex keeps using its ChatGPT sign-in when
|
|
15
|
+
* an OpenAI key is exported, so its existing accounts inherit everything.
|
|
16
|
+
*/
|
|
17
|
+
export declare function accountEnvironment(provider: AccountProvider, credentials: AccountCredentials, inherited: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Every provider login variable. A managed account's own folder holds its login, so none of these reach it. */
|
|
2
|
+
export const providerAuthenticationVariable = /^(?:OPENAI_|CODEX_|ANTHROPIC_|CLAUDE_)/u;
|
|
3
|
+
/** What makes Claude Code bill an API key or a cloud provider instead of a Claude sign-in. */
|
|
4
|
+
const claudeApiCredentials = new Set([
|
|
5
|
+
"ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "AWS_BEARER_TOKEN_BEDROCK",
|
|
6
|
+
"CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_VERTEX", "CLAUDE_CODE_USE_FOUNDRY", "CLAUDE_CODE_USE_GATEWAY",
|
|
7
|
+
"CLAUDE_CODE_USE_MANTLE", "CLAUDE_CODE_USE_ANTHROPIC_AWS", "CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD",
|
|
8
|
+
]);
|
|
9
|
+
/** A sign-in on this Mac: `auth login`, and reading which sign-in is there. */
|
|
10
|
+
export const signInCredentials = { type: "existing", billing: "account" };
|
|
11
|
+
/**
|
|
12
|
+
* The environment of every provider process an account starts: the account decides its credentials.
|
|
13
|
+
* Claude Code prefers an exported API key over the person's Claude sign-in, so the key reaches Claude
|
|
14
|
+
* only when the person picked the API key as the account. Codex keeps using its ChatGPT sign-in when
|
|
15
|
+
* an OpenAI key is exported, so its existing accounts inherit everything.
|
|
16
|
+
*/
|
|
17
|
+
export function accountEnvironment(provider, credentials, inherited) {
|
|
18
|
+
const excluded = (key) => credentials.type === "managed"
|
|
19
|
+
? providerAuthenticationVariable.test(key)
|
|
20
|
+
: provider === "claude" && credentials.billing !== "api" && claudeApiCredentials.has(key);
|
|
21
|
+
return Object.fromEntries(Object.entries(inherited).filter(([key]) => !excluded(key)));
|
|
22
|
+
}
|
|
@@ -7,6 +7,7 @@ import { FileAdapterStateStore } from "../adapter-state-store.js";
|
|
|
7
7
|
import { withFileMutex } from "../file-mutex.js";
|
|
8
8
|
import { listProcessEnvironments } from "../adapters/codex/codex-run-processes.js";
|
|
9
9
|
import { accountOperationSchema, accountSchema } from "./account-protocol.js";
|
|
10
|
+
import { accountEnvironment, providerAuthenticationVariable } from "./account-environment.js";
|
|
10
11
|
const bindingSchema = z.object({
|
|
11
12
|
account: accountSchema,
|
|
12
13
|
providerAccountId: z.string().min(1).optional(),
|
|
@@ -32,7 +33,6 @@ const registrySchema = z.object({
|
|
|
32
33
|
blocked: z.boolean(),
|
|
33
34
|
resync: z.boolean().default(false),
|
|
34
35
|
});
|
|
35
|
-
const providerAuthenticationVariable = /^(?:OPENAI_|CODEX_|ANTHROPIC_|CLAUDE_)/u;
|
|
36
36
|
// Settings that sign Claude in with something other than this profile's own login.
|
|
37
37
|
const claudeSettingsAuthenticationKeys = ["apiKeyHelper", "awsAuthRefresh", "awsCredentialExport"];
|
|
38
38
|
// Claude's state file keys that say who is signed in.
|
|
@@ -296,9 +296,7 @@ export class ProviderAccountStore {
|
|
|
296
296
|
return directory;
|
|
297
297
|
}
|
|
298
298
|
async environment(profile, inherited) {
|
|
299
|
-
const environment =
|
|
300
|
-
key, profile.type === "managed" && providerAuthenticationVariable.test(key) ? undefined : value,
|
|
301
|
-
]));
|
|
299
|
+
const environment = accountEnvironment(this.provider, { type: profile.type, billing: profile.account.billing }, inherited);
|
|
302
300
|
if (profile.type === "managed") {
|
|
303
301
|
const expected = path.join(this.directory, profile.account.accountProfileId);
|
|
304
302
|
if (profile.directory !== expected)
|
|
@@ -2,6 +2,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { getTeammateToolchain, teammateCredentialPaths } from "../teammate-sandbox.js";
|
|
5
|
+
import { accountEnvironment, signInCredentials } from "./account-environment.js";
|
|
5
6
|
import { clearCandidateCredentials, ProviderSignInError, readProviderIdentity, signInProvider, } from "./provider-account-auth.js";
|
|
6
7
|
import { createCodexHome, sameProviderAccount } from "./provider-account-store.js";
|
|
7
8
|
import { AccountOperationStatus, AccountOperationType, terminalAccountStatuses, unixTicks, } from "./account-protocol.js";
|
|
@@ -671,23 +672,33 @@ export class ProviderAccounts {
|
|
|
671
672
|
await this.#save();
|
|
672
673
|
this.#updateAdmission();
|
|
673
674
|
}
|
|
674
|
-
// The
|
|
675
|
+
// The logins already on this Mac are the owner's accounts, as when running the CLI in Terminal: the
|
|
676
|
+
// sign-in and an exported API key are each an account, and the agent starts on the sign-in.
|
|
675
677
|
async #adoptMacLogin() {
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
let
|
|
680
|
-
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
this.#registry.profiles.
|
|
678
|
+
const directory = this.dependencies.environment[this.kind === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"];
|
|
679
|
+
const signIn = accountEnvironment(this.kind, signInCredentials, this.dependencies.environment);
|
|
680
|
+
const apiKey = accountEnvironment(this.kind, { type: "existing", billing: "api" }, this.dependencies.environment);
|
|
681
|
+
let adopted;
|
|
682
|
+
for (const environment of Object.keys(signIn).length === Object.keys(apiKey).length ? [signIn] : [signIn, apiKey]) {
|
|
683
|
+
const identity = await (this.dependencies.readIdentity ?? readProviderIdentity)(this.kind, environment, AbortSignal.timeout(30_000))
|
|
684
|
+
.catch(() => null);
|
|
685
|
+
if (identity === null)
|
|
686
|
+
continue;
|
|
687
|
+
let profile = this.#registry.profiles.find(saved => matches(saved, identity));
|
|
688
|
+
if (profile === undefined) {
|
|
689
|
+
profile = { type: "existing", directory: directory === undefined ? null : path.resolve(directory),
|
|
690
|
+
providerAccountId: identity.providerAccountId, verificationKey: identity.verificationKey,
|
|
691
|
+
account: { accountProfileId: randomUUID(), email: identity.email, plan: identity.plan, billing: identity.billing, usage: null } };
|
|
692
|
+
this.#registry.profiles.push(profile);
|
|
693
|
+
}
|
|
694
|
+
adopted ??= profile;
|
|
686
695
|
}
|
|
687
|
-
|
|
696
|
+
if (adopted === undefined)
|
|
697
|
+
return undefined;
|
|
698
|
+
this.#registry.currentAccountProfileId = adopted.account.accountProfileId;
|
|
688
699
|
this.#registry.blocked = false;
|
|
689
700
|
await this.#save();
|
|
690
|
-
return
|
|
701
|
+
return adopted;
|
|
691
702
|
}
|
|
692
703
|
#updateAdmission() {
|
|
693
704
|
this.#handler?.setAccountChangePending(this.#isAccountChangePending);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { accountEnvironment, signInCredentials } from "./accounts/account-environment.js";
|
|
2
3
|
export function providerSignIn(provider) {
|
|
3
|
-
const child = spawn(process.env.SHOWRUNNER_AGENT_EXECUTABLE ?? provider, provider === "claude" ? ["auth", "login"] : ["login"], { env: process.env, stdio: "inherit", shell: false });
|
|
4
|
+
const child = spawn(process.env.SHOWRUNNER_AGENT_EXECUTABLE ?? provider, provider === "claude" ? ["auth", "login"] : ["login"], { env: accountEnvironment(provider, signInCredentials, process.env), stdio: "inherit", shell: false });
|
|
4
5
|
// The helper stops sign-in with SIGTERM (Cancel, a newer tap); the provider's login must stop with it.
|
|
5
6
|
const forward = (signal) => { child.kill(signal); };
|
|
6
7
|
process.on("SIGTERM", forward);
|
|
@@ -16,7 +17,8 @@ export function providerSignIn(provider) {
|
|
|
16
17
|
/** What the provider's own status command says; "unknown" when it couldn't run or didn't say. */
|
|
17
18
|
export async function providerSignInStatus(provider, signal) {
|
|
18
19
|
const args = provider === "claude" ? ["auth", "status", "--json"] : ["login", "status"];
|
|
19
|
-
const result = await run(process.env.SHOWRUNNER_AGENT_EXECUTABLE ?? provider, args,
|
|
20
|
+
const result = await run(process.env.SHOWRUNNER_AGENT_EXECUTABLE ?? provider, args, accountEnvironment(provider, signInCredentials, process.env), signal)
|
|
21
|
+
.catch(() => null);
|
|
20
22
|
if (result === null || result.code === null)
|
|
21
23
|
return "unknown";
|
|
22
24
|
if (provider === "codex") {
|
|
@@ -33,9 +35,9 @@ export async function providerSignInStatus(provider, signal) {
|
|
|
33
35
|
return "unknown";
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
|
-
function run(command, args, signal) {
|
|
38
|
+
function run(command, args, env, signal) {
|
|
37
39
|
return new Promise((resolve, reject) => {
|
|
38
|
-
const child = spawn(command, args, { env
|
|
40
|
+
const child = spawn(command, args, { env, stdio: ["ignore", "pipe", "pipe"], shell: false });
|
|
39
41
|
let stdout = "";
|
|
40
42
|
let stderr = "";
|
|
41
43
|
const finish = () => signal.removeEventListener("abort", abort);
|