@sjawhar/claude-envoy 5.24.0 → 5.25.0
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/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/dist/codex-hook.js +352 -117
- package/dist/dispatch.js +648 -407
- package/dist/envoy-channel.js +2404 -2169
- package/dist/session-hook.js +330 -95
- package/package.json +1 -1
package/dist/session-hook.js
CHANGED
|
@@ -980,7 +980,7 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// hooks/session-hook.ts
|
|
983
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync2, readFileSync as
|
|
983
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync8, rmSync as rmSync3, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
984
984
|
import { join as join11 } from "path";
|
|
985
985
|
|
|
986
986
|
// ../cipher-client/src/device-login-file.ts
|
|
@@ -2933,6 +2933,10 @@ var FORM_SESSION = "session";
|
|
|
2933
2933
|
var FORM_LAUNCHER_CREDENTIAL = "launcher_credential";
|
|
2934
2934
|
var FORM_LAUNCHER_CREDENTIAL_DECLINED = "false";
|
|
2935
2935
|
var FORM_PROJECTS = "projects";
|
|
2936
|
+
var FORM_SCOPE = "scope";
|
|
2937
|
+
var SCOPE_READ = "read";
|
|
2938
|
+
var FORM_AS_OF = "as_of";
|
|
2939
|
+
var HEADER_DPOP_HOLDER = "DPoP-Holder";
|
|
2936
2940
|
var SUBJECT_TOKEN_TYPE_KUBERNETES = "urn:envoy:params:oauth:token-type:kubernetes-service-account";
|
|
2937
2941
|
var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identity";
|
|
2938
2942
|
var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
|
|
@@ -3045,6 +3049,7 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
|
3045
3049
|
"The machine login the subject token belongs to has ended\\.",
|
|
3046
3050
|
"The machine login has ended\\.",
|
|
3047
3051
|
"Another live machine login holds the key this proof was signed with\\. A (?:machine makes a key of its own|sign-in makes a box key of its own)\\.",
|
|
3052
|
+
"A live read token is bound to the key this proof was signed with\\. Make a new key\\.",
|
|
3048
3053
|
`${PERSON_SLOT} is a restricted member, whose token names its projects: set AGENT_SECRETS_PROJECTS to the projects this session works on\\.`,
|
|
3049
3054
|
`The token names a project its person cannot see: ${PROJECT_SLOT}\\.`,
|
|
3050
3055
|
`The subject token was refused: its entry names the project ${PROJECT_SLOT}, which its person ${PERSON_SLOT} cannot see\\.`,
|
|
@@ -3057,6 +3062,19 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
|
3057
3062
|
`The session name '${SESSION_SLOT}' belongs to another daemon: a pod trades only under a session name the daemon that registered it holds\\.`,
|
|
3058
3063
|
`The session name '${SESSION_SLOT}' is bound to no daemon: a pod trades only under a session name the daemon that registered it holds\\.`,
|
|
3059
3064
|
`${PERSON_SLOT}'s credentials are held by Dispatch; they work again when \\k<person> signs in to Dispatch, or when Dispatch can confirm \\k<person> with Google again`,
|
|
3065
|
+
"The 'as_of' parameter names a cut, and only a trade that asks for the scope read may name one\\.",
|
|
3066
|
+
"The 'as_of' parameter is not an RFC 3339 time with at most six fractional digits\\.",
|
|
3067
|
+
"The 'as_of' parameter names the zero time, which is no cut: a trade that reads the present names no cut\\.",
|
|
3068
|
+
"The 'as_of' parameter names a time later than this trade, and a cut is a time that has passed\\.",
|
|
3069
|
+
"A read trade makes or moves no launcher credential, so it cannot send launcher_credential=true\\. Trade for read without the parameter\\.",
|
|
3070
|
+
`${PERSON_SLOT}'s sign-in on this machine holds no launcher credential yet, and a read trade makes none\\. Sign in with \`agent-secrets login\` first\\.`,
|
|
3071
|
+
`${PERSON_SLOT}'s sign-in on this machine holds a launcher credential that has lapsed, and a read trade renews none\\. One ordinary trade of the sign-in renews it, as \`agent-secrets\` makes; then trade for read again\\.`,
|
|
3072
|
+
"A person's read trade sends a DPoP-Holder proof: the box key proves the sign-in and is bound to no read token, so the token is bound to a key made for its holder\\.",
|
|
3073
|
+
"The DPoP-Holder header binds a read token to its holder's key, and this trade does not ask for the scope read\\. Ask for it, or send no DPoP-Holder header\\.",
|
|
3074
|
+
"The DPoP-Holder proof was refused: a trade sends one, a DPoP proof of this request signed with the key it embeds, spent nowhere before\\.",
|
|
3075
|
+
"The DPoP-Holder proof is signed with the key the DPoP proof is signed with, and the holder's key is a key of its own\\.",
|
|
3076
|
+
"The key this read token would be bound to signs launcher proofs: a live launcher credential is bound to it, and no read token is bound to such a key\\. Send a DPoP-Holder proof by a key made for the token's holder, and the token is bound to that key\\.",
|
|
3077
|
+
"The key this proof was signed with signs launcher proofs: a live launcher credential is bound to it, and no read token is bound to such a key\\. Ask for the scope read with a DPoP-Holder proof by a key made for the token's holder, or trade with a key that holds no launcher credential\\.",
|
|
3060
3078
|
...POLICY_REFUSAL_PATTERNS
|
|
3061
3079
|
].map((source) => new RegExp(`^${source}$`));
|
|
3062
3080
|
var LIBRARY_DESCRIPTIONS = [
|
|
@@ -3352,32 +3370,8 @@ function isFinalRefusal(error) {
|
|
|
3352
3370
|
return error instanceof BrokerRefusedError && error.permanent || error instanceof SignInEndedError || error instanceof DeviceLoginEndedError;
|
|
3353
3371
|
}
|
|
3354
3372
|
|
|
3355
|
-
// ../cipher-client/src/
|
|
3356
|
-
var DEFAULT_RENEW_BEFORE_MS = 5 * 60000;
|
|
3373
|
+
// ../cipher-client/src/broker-request.ts
|
|
3357
3374
|
var BROKER_URL_SETTING = "the broker URL";
|
|
3358
|
-
var RETRY_FIRST_WAIT_MS = 15000;
|
|
3359
|
-
var RETRY_MAX_WAIT_MS = 5 * 60000;
|
|
3360
|
-
var PENDING_FIRST_WAIT_MS = 2000;
|
|
3361
|
-
var PENDING_MAX_WAIT_MS = 30000;
|
|
3362
|
-
var UNREGISTERED_LOG_EVERY_MS = 30 * 60000;
|
|
3363
|
-
var TRADE_ATTEMPT_MS = 30000;
|
|
3364
|
-
function sleep(ms, signal, holdsProcess = false) {
|
|
3365
|
-
const { promise, resolve } = Promise.withResolvers();
|
|
3366
|
-
if (signal?.aborted) {
|
|
3367
|
-
resolve();
|
|
3368
|
-
return promise;
|
|
3369
|
-
}
|
|
3370
|
-
const done = () => {
|
|
3371
|
-
clearTimeout(timer);
|
|
3372
|
-
signal?.removeEventListener("abort", done);
|
|
3373
|
-
resolve();
|
|
3374
|
-
};
|
|
3375
|
-
const timer = setTimeout(done, ms);
|
|
3376
|
-
if (!holdsProcess)
|
|
3377
|
-
timer.unref();
|
|
3378
|
-
signal?.addEventListener("abort", done, { once: true });
|
|
3379
|
-
return promise;
|
|
3380
|
-
}
|
|
3381
3375
|
function statusOf(error) {
|
|
3382
3376
|
let cause = error;
|
|
3383
3377
|
for (let depth = 0;depth < 4; depth += 1) {
|
|
@@ -3414,7 +3408,11 @@ function requestInit(options, signal, headers) {
|
|
|
3414
3408
|
async function sendWithProof(proved, url, options, signal) {
|
|
3415
3409
|
const send = async () => {
|
|
3416
3410
|
const headers = new Headers(options.headers);
|
|
3417
|
-
|
|
3411
|
+
const request = { method: options.method, url, nonce: proved.nonce.value };
|
|
3412
|
+
headers.set("DPoP", await proved.key.proof(request));
|
|
3413
|
+
if (proved.holderKey !== undefined) {
|
|
3414
|
+
headers.set(HEADER_DPOP_HOLDER, await proved.holderKey.proof(request));
|
|
3415
|
+
}
|
|
3418
3416
|
return await proved.fetch(url, requestInit(options, signal, headers));
|
|
3419
3417
|
};
|
|
3420
3418
|
let answer = await send();
|
|
@@ -3430,14 +3428,50 @@ async function sendWithProof(proved, url, options, signal) {
|
|
|
3430
3428
|
return answer;
|
|
3431
3429
|
}
|
|
3432
3430
|
|
|
3431
|
+
// ../cipher-client/src/token-client.ts
|
|
3432
|
+
var DEFAULT_RENEW_BEFORE_MS = 5 * 60000;
|
|
3433
|
+
function renewalAt(expiresAt, now, renewBeforeMs) {
|
|
3434
|
+
const left = expiresAt - now;
|
|
3435
|
+
if (left <= 0)
|
|
3436
|
+
return now;
|
|
3437
|
+
return Math.max(expiresAt - renewBeforeMs, now + left / 2);
|
|
3438
|
+
}
|
|
3439
|
+
var EXPIRES_IN_STEP_MS = 1000;
|
|
3440
|
+
var RETRY_FIRST_WAIT_MS = 15000;
|
|
3441
|
+
var RETRY_MAX_WAIT_MS = 5 * 60000;
|
|
3442
|
+
var PENDING_FIRST_WAIT_MS = 2000;
|
|
3443
|
+
var PENDING_MAX_WAIT_MS = 30000;
|
|
3444
|
+
var UNREGISTERED_LOG_EVERY_MS = 30 * 60000;
|
|
3445
|
+
var TRADE_ATTEMPT_MS = 30000;
|
|
3446
|
+
function sleep(ms, signal, holdsProcess = false) {
|
|
3447
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
3448
|
+
if (signal?.aborted) {
|
|
3449
|
+
resolve();
|
|
3450
|
+
return promise;
|
|
3451
|
+
}
|
|
3452
|
+
const done = () => {
|
|
3453
|
+
clearTimeout(timer);
|
|
3454
|
+
signal?.removeEventListener("abort", done);
|
|
3455
|
+
resolve();
|
|
3456
|
+
};
|
|
3457
|
+
const timer = setTimeout(done, ms);
|
|
3458
|
+
if (!holdsProcess)
|
|
3459
|
+
timer.unref();
|
|
3460
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
3461
|
+
return promise;
|
|
3462
|
+
}
|
|
3463
|
+
|
|
3433
3464
|
class BrokerTokenClient {
|
|
3434
3465
|
#brokerUrl;
|
|
3435
3466
|
#key;
|
|
3467
|
+
#holderKey;
|
|
3436
3468
|
#subject;
|
|
3437
3469
|
#actor;
|
|
3438
3470
|
#session;
|
|
3439
3471
|
#projects;
|
|
3440
3472
|
#launcherCredential;
|
|
3473
|
+
#scope;
|
|
3474
|
+
#asOf;
|
|
3441
3475
|
#renewBeforeMs;
|
|
3442
3476
|
#now;
|
|
3443
3477
|
#attemptMs;
|
|
@@ -3466,11 +3500,14 @@ class BrokerTokenClient {
|
|
|
3466
3500
|
throw new Error("broker client: the broker URL is not an http or https URL");
|
|
3467
3501
|
this.#brokerUrl = holdUrlUserinfo(brokerUrl);
|
|
3468
3502
|
this.#key = options.key;
|
|
3503
|
+
this.#holderKey = options.holderKey;
|
|
3469
3504
|
this.#subject = options.subject;
|
|
3470
3505
|
this.#actor = options.actor;
|
|
3471
3506
|
this.#session = options.session ?? "";
|
|
3472
3507
|
this.#projects = [...options.projects ?? []];
|
|
3473
3508
|
this.#launcherCredential = options.launcherCredential ?? true;
|
|
3509
|
+
this.#scope = options.scope ?? "";
|
|
3510
|
+
this.#asOf = options.asOf ?? "";
|
|
3474
3511
|
this.#renewBeforeMs = options.renewBeforeMs ?? DEFAULT_RENEW_BEFORE_MS;
|
|
3475
3512
|
this.#now = options.now ?? Date.now;
|
|
3476
3513
|
this.#attemptMs = options.attemptMs ?? TRADE_ATTEMPT_MS;
|
|
@@ -3480,7 +3517,7 @@ class BrokerTokenClient {
|
|
|
3480
3517
|
this.#random = options.random ?? Math.random;
|
|
3481
3518
|
}
|
|
3482
3519
|
get key() {
|
|
3483
|
-
return this.#key;
|
|
3520
|
+
return this.#holderKey ?? this.#key;
|
|
3484
3521
|
}
|
|
3485
3522
|
describe() {
|
|
3486
3523
|
return this.#subject.describe();
|
|
@@ -3489,10 +3526,11 @@ class BrokerTokenClient {
|
|
|
3489
3526
|
const waitForReady = options.waitForReady === true;
|
|
3490
3527
|
const now = this.#now();
|
|
3491
3528
|
const held = this.#held;
|
|
3492
|
-
if (held !== null && now < held.
|
|
3493
|
-
return held;
|
|
3494
|
-
if (held !== null && now < held.expiresAt.getTime() && this.#last !== null)
|
|
3495
|
-
return held;
|
|
3529
|
+
if (held !== null && now < held.renewsAt)
|
|
3530
|
+
return held.token;
|
|
3531
|
+
if (held !== null && now < held.token.expiresAt.getTime() && this.#last !== null) {
|
|
3532
|
+
return held.token;
|
|
3533
|
+
}
|
|
3496
3534
|
const closed = this.#closed.signal;
|
|
3497
3535
|
if (closed.aborted)
|
|
3498
3536
|
throw closed.reason;
|
|
@@ -3526,8 +3564,8 @@ class BrokerTokenClient {
|
|
|
3526
3564
|
const stop = () => {
|
|
3527
3565
|
this.#waiters.delete(waiter);
|
|
3528
3566
|
const held = this.#held;
|
|
3529
|
-
if (held !== null && this.#now() < held.expiresAt.getTime())
|
|
3530
|
-
resolve(held);
|
|
3567
|
+
if (held !== null && this.#now() < held.token.expiresAt.getTime())
|
|
3568
|
+
resolve(held.token);
|
|
3531
3569
|
else
|
|
3532
3570
|
reject(this.#stopped(signal?.reason));
|
|
3533
3571
|
};
|
|
@@ -3567,7 +3605,7 @@ class BrokerTokenClient {
|
|
|
3567
3605
|
});
|
|
3568
3606
|
}
|
|
3569
3607
|
drop(accessToken) {
|
|
3570
|
-
if (accessToken !== undefined && this.#held?.accessToken !== accessToken)
|
|
3608
|
+
if (accessToken !== undefined && this.#held?.token.accessToken !== accessToken)
|
|
3571
3609
|
return;
|
|
3572
3610
|
this.#held = null;
|
|
3573
3611
|
}
|
|
@@ -3598,7 +3636,10 @@ class BrokerTokenClient {
|
|
|
3598
3636
|
if (this.#pendingSaid !== null && this.#since !== null) {
|
|
3599
3637
|
this.#log(`the secrets broker answered this pod's session ${this.#session} once it was registered, ${Math.round((this.#now() - this.#since) / 1000)} s and ${this.#failed} failed trades after the first`);
|
|
3600
3638
|
}
|
|
3601
|
-
this.#held =
|
|
3639
|
+
this.#held = {
|
|
3640
|
+
token,
|
|
3641
|
+
renewsAt: renewalAt(token.expiresAt.getTime(), this.#now(), this.#renewBeforeMs)
|
|
3642
|
+
};
|
|
3602
3643
|
this.#last = null;
|
|
3603
3644
|
this.#since = null;
|
|
3604
3645
|
this.#failed = 0;
|
|
@@ -3638,8 +3679,8 @@ class BrokerTokenClient {
|
|
|
3638
3679
|
this.#since ??= now;
|
|
3639
3680
|
this.#failed += 1;
|
|
3640
3681
|
const held = this.#held;
|
|
3641
|
-
if (held !== null && now < held.expiresAt.getTime()) {
|
|
3642
|
-
this.#tell((waiter) => waiter.resolve(held));
|
|
3682
|
+
if (held !== null && now < held.token.expiresAt.getTime()) {
|
|
3683
|
+
this.#tell((waiter) => waiter.resolve(held.token));
|
|
3643
3684
|
} else {
|
|
3644
3685
|
this.#held = null;
|
|
3645
3686
|
if (failure.kind !== "pending") {
|
|
@@ -3691,7 +3732,8 @@ class BrokerTokenClient {
|
|
|
3691
3732
|
async#trade(signal) {
|
|
3692
3733
|
const source = this.#subject;
|
|
3693
3734
|
if (source.spend !== undefined) {
|
|
3694
|
-
|
|
3735
|
+
const leastLifeMs = this.#scope === SCOPE_READ ? this.#renewBeforeMs + EXPIRES_IN_STEP_MS : undefined;
|
|
3736
|
+
return await source.spend((subject) => this.#exchange(subject, signal), signal, leastLifeMs);
|
|
3695
3737
|
}
|
|
3696
3738
|
return await this.#exchange(await source.read(signal), signal);
|
|
3697
3739
|
}
|
|
@@ -3705,6 +3747,10 @@ class BrokerTokenClient {
|
|
|
3705
3747
|
form[FORM_SESSION] = this.#session;
|
|
3706
3748
|
if (this.#projects.length > 0)
|
|
3707
3749
|
form[FORM_PROJECTS] = this.#projects.join(" ");
|
|
3750
|
+
if (this.#scope !== "")
|
|
3751
|
+
form[FORM_SCOPE] = this.#scope;
|
|
3752
|
+
if (this.#asOf !== "")
|
|
3753
|
+
form[FORM_AS_OF] = this.#asOf;
|
|
3708
3754
|
if (!this.#launcherCredential) {
|
|
3709
3755
|
form[FORM_LAUNCHER_CREDENTIAL] = FORM_LAUNCHER_CREDENTIAL_DECLINED;
|
|
3710
3756
|
}
|
|
@@ -3737,7 +3783,7 @@ class BrokerTokenClient {
|
|
|
3737
3783
|
return this.#read(urlForText(endpoint, BROKER_URL_SETTING), answered, raw.body);
|
|
3738
3784
|
}
|
|
3739
3785
|
async#send(url, options, signal, raw) {
|
|
3740
|
-
const answer = await sendWithProof({ key: this.#key, fetch: this.#fetch, nonce: this.#nonce }, url, options, signal);
|
|
3786
|
+
const answer = await sendWithProof({ key: this.#key, holderKey: this.#holderKey, fetch: this.#fetch, nonce: this.#nonce }, url, options, signal);
|
|
3741
3787
|
raw.body = await answer.clone().json().catch(() => {
|
|
3742
3788
|
return;
|
|
3743
3789
|
});
|
|
@@ -4000,6 +4046,10 @@ function member(json, name) {
|
|
|
4000
4046
|
const value = json[name];
|
|
4001
4047
|
return typeof value === "string" ? value : "";
|
|
4002
4048
|
}
|
|
4049
|
+
function wholeMember(json, name) {
|
|
4050
|
+
const value = json[name];
|
|
4051
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : null;
|
|
4052
|
+
}
|
|
4003
4053
|
function checkPrivate(info, what, forbidden, opens, notOwned) {
|
|
4004
4054
|
const mode = info.mode & 511;
|
|
4005
4055
|
if ((mode & forbidden) !== 0) {
|
|
@@ -4357,7 +4407,8 @@ async function readDeviceLogin(path) {
|
|
|
4357
4407
|
expiresAt,
|
|
4358
4408
|
broker,
|
|
4359
4409
|
accessToken: accessUsable ? holdSecret(accessToken, accessExpiresAt) : "",
|
|
4360
|
-
accessExpiresAt: accessUsable ? accessExpiresAt : null
|
|
4410
|
+
accessExpiresAt: accessUsable ? accessExpiresAt : null,
|
|
4411
|
+
accessLifeSeconds: accessUsable ? wholeMember(json, "access_life_seconds") : null
|
|
4361
4412
|
};
|
|
4362
4413
|
}
|
|
4363
4414
|
function lockLost(then = "this trade refreshes and keeps nothing, and the next one reads the login again") {
|
|
@@ -4390,7 +4441,8 @@ async function saveDeviceLogin(path, login, held, keep = false) {
|
|
|
4390
4441
|
broker: login.broker,
|
|
4391
4442
|
...login.accessToken === "" || login.accessExpiresAt === null ? {} : {
|
|
4392
4443
|
access_token: login.accessToken,
|
|
4393
|
-
access_expires_at: login.accessExpiresAt.toISOString()
|
|
4444
|
+
access_expires_at: login.accessExpiresAt.toISOString(),
|
|
4445
|
+
...login.accessLifeSeconds === null ? {} : { access_life_seconds: login.accessLifeSeconds }
|
|
4394
4446
|
}
|
|
4395
4447
|
});
|
|
4396
4448
|
await deviceLoginPlace(path);
|
|
@@ -32022,13 +32074,29 @@ async function whoamiCommand(context) {
|
|
|
32022
32074
|
const service = identity.kind === "agent" ? identity.service ?? null : null;
|
|
32023
32075
|
const proved = identity.kind === "agent" ? identity.session ?? null : null;
|
|
32024
32076
|
const project = identity.kind === "agent" ? identity.project ?? null : null;
|
|
32077
|
+
const readOnly = identity.scopes?.includes("read") === true;
|
|
32078
|
+
const cut = identity.kind === "agent" ? identity.cut ?? null : null;
|
|
32025
32079
|
const session = proved ?? sessionId;
|
|
32026
32080
|
const unowned = "no owner, so an issue you create without an assignee takes its parent's assignee when the parent is in the same project, else the project's default assignee, which every project names, so the issue always has one.";
|
|
32027
32081
|
const answered = identity.kind === "agent" ? identity.sign_in_required : undefined;
|
|
32028
32082
|
const signInNeeded = answered ?? (owner === null && service !== null && proved !== null);
|
|
32029
|
-
const
|
|
32030
|
-
const
|
|
32031
|
-
|
|
32083
|
+
const who = owner !== null ? `acts for ${owner}` : service !== null ? `runs as service ${serviceSubjectLabel(service)}` : "runs";
|
|
32084
|
+
const named = proved !== null && proved !== sessionId ? ` Your credential names session ${proved}, which is not this host session (${sessionId})` : "";
|
|
32085
|
+
let acting;
|
|
32086
|
+
let elsewhere = named === "" ? "" : `${named}: Dispatch records every write you make as ${proved}.`;
|
|
32087
|
+
if (readOnly) {
|
|
32088
|
+
acting = `Session ${session} ${who} with a read-only credential: it may read, and Dispatch refuses every write it makes.${cut === null ? "" : ` Its cut is ${cut}, the past time it reads Dispatch at.`}`;
|
|
32089
|
+
elsewhere = named === "" ? "" : `${named}.`;
|
|
32090
|
+
} else if (owner !== null) {
|
|
32091
|
+
acting = `Session ${session} ${who}: issues you create without an assignee are assigned to ${owner}.`;
|
|
32092
|
+
} else if (signInNeeded) {
|
|
32093
|
+
acting = `Session ${session} ${who} and no person, so it may read but Dispatch refuses every write it makes: run \`agent-secrets login\` on this machine to write as yourself.`;
|
|
32094
|
+
} else if (service !== null) {
|
|
32095
|
+
acting = `Session ${session} ${who}: ${unowned}`;
|
|
32096
|
+
} else {
|
|
32097
|
+
acting = `Session ${session} runs under the shared token: ${unowned}`;
|
|
32098
|
+
}
|
|
32099
|
+
const writable = project !== null && !readOnly ? ` It may write project ${project} and no other.` : "";
|
|
32032
32100
|
return {
|
|
32033
32101
|
text: acting + elsewhere + writable,
|
|
32034
32102
|
details: { session, owner, service, project }
|
|
@@ -32697,6 +32765,11 @@ async function importDpopKey(pkcs8Pem, name) {
|
|
|
32697
32765
|
// ../cipher-client/src/device-login.ts
|
|
32698
32766
|
var BROKER_SETTING = "AGENT_SECRETS_URL";
|
|
32699
32767
|
var ACCESS_MARGIN_MS = 2 * TRADE_ATTEMPT_MS;
|
|
32768
|
+
function leastAccessLifeMs(leastLifeMs, lifeSeconds) {
|
|
32769
|
+
if (leastLifeMs === undefined || lifeSeconds === null)
|
|
32770
|
+
return ACCESS_MARGIN_MS;
|
|
32771
|
+
return Math.max(ACCESS_MARGIN_MS, Math.min(leastLifeMs, lifeSeconds * 1000 / 2));
|
|
32772
|
+
}
|
|
32700
32773
|
var BROKER_REQUEST_MS = TRADE_ATTEMPT_MS / 2;
|
|
32701
32774
|
var DEFAULT_POLL_SECONDS = 5;
|
|
32702
32775
|
var LEAST_POLL_SECONDS = 1;
|
|
@@ -32772,7 +32845,8 @@ function loginOf(key, broker, answered, now) {
|
|
|
32772
32845
|
expiresAt,
|
|
32773
32846
|
broker,
|
|
32774
32847
|
accessToken: holdSecret(answered.access_token, accessExpiresAt),
|
|
32775
|
-
accessExpiresAt
|
|
32848
|
+
accessExpiresAt,
|
|
32849
|
+
accessLifeSeconds: seconds
|
|
32776
32850
|
};
|
|
32777
32851
|
}
|
|
32778
32852
|
async function startDeviceLogin(options) {
|
|
@@ -32904,7 +32978,7 @@ class DeviceLoginIdentity {
|
|
|
32904
32978
|
}
|
|
32905
32979
|
return this.#key;
|
|
32906
32980
|
}
|
|
32907
|
-
async spend(trade, signal) {
|
|
32981
|
+
async spend(trade, signal, leastLifeMs) {
|
|
32908
32982
|
const { thumbprint } = await this.#loaded();
|
|
32909
32983
|
return await withDeviceLoginLock(this.#path, async (held) => {
|
|
32910
32984
|
let login = await readDeviceLogin(this.#path);
|
|
@@ -32916,7 +32990,8 @@ class DeviceLoginIdentity {
|
|
|
32916
32990
|
}
|
|
32917
32991
|
const refresh = () => refreshDeviceLogin(this.#path, login, { describe: this.describe(), held });
|
|
32918
32992
|
const expires = login.accessExpiresAt?.getTime() ?? 0;
|
|
32919
|
-
|
|
32993
|
+
const least = leastAccessLifeMs(leastLifeMs, login.accessLifeSeconds);
|
|
32994
|
+
let refreshed = login.accessToken === "" || expires - Date.now() < least;
|
|
32920
32995
|
if (refreshed)
|
|
32921
32996
|
login = await refresh();
|
|
32922
32997
|
while (true) {
|
|
@@ -33364,13 +33439,15 @@ function tradeProjects(env) {
|
|
|
33364
33439
|
}
|
|
33365
33440
|
return sorted;
|
|
33366
33441
|
}
|
|
33367
|
-
async function brokerTokenClient(env, own = "") {
|
|
33442
|
+
async function brokerTokenClient(env, own = "", read) {
|
|
33368
33443
|
const brokerUrl = value(env, BROKER_URL_VAR);
|
|
33369
33444
|
const machine = machineIdentity(env);
|
|
33370
33445
|
if (brokerUrl === "" || machine === undefined)
|
|
33371
33446
|
return;
|
|
33372
33447
|
if (!isHttpUrl(brokerUrl))
|
|
33373
33448
|
throw new Error(`${BROKER_URL_VAR} is not an http or https URL`);
|
|
33449
|
+
const narrowed = read === undefined ? {} : { scope: SCOPE_READ, asOf: read.asOf };
|
|
33450
|
+
const heldApart = async () => read === undefined ? {} : { ...narrowed, holderKey: await newDpopKey() };
|
|
33374
33451
|
if (machine instanceof DeviceLoginIdentity) {
|
|
33375
33452
|
if (personTradeOff(env)) {
|
|
33376
33453
|
throw new Error(`${PERSON_TRADE_VAR}=off turns off every trade made as a person, and ${IDENTITY_VAR}=${IDENTITY_DEVICE_LOGIN} trades this machine's device login as the person who approved it; unset one of them`);
|
|
@@ -33380,7 +33457,8 @@ async function brokerTokenClient(env, own = "") {
|
|
|
33380
33457
|
key: await machine.key(),
|
|
33381
33458
|
subject: machine,
|
|
33382
33459
|
session: tradeSession(env, own) || deviceLoginSessionName(await machine.thumbprint()),
|
|
33383
|
-
projects: tradeProjects(env)
|
|
33460
|
+
projects: tradeProjects(env),
|
|
33461
|
+
...await heldApart()
|
|
33384
33462
|
});
|
|
33385
33463
|
return { client, signIn: undefined };
|
|
33386
33464
|
}
|
|
@@ -33391,7 +33469,8 @@ async function brokerTokenClient(env, own = "") {
|
|
|
33391
33469
|
key: await newDpopKey(),
|
|
33392
33470
|
subject: machine,
|
|
33393
33471
|
session: tradeSession(env, own),
|
|
33394
|
-
launcherCredential: false
|
|
33472
|
+
launcherCredential: false,
|
|
33473
|
+
...narrowed
|
|
33395
33474
|
});
|
|
33396
33475
|
return { client, signIn: undefined };
|
|
33397
33476
|
}
|
|
@@ -33405,7 +33484,8 @@ async function brokerTokenClient(env, own = "") {
|
|
|
33405
33484
|
subject: personIdentity(record, flow),
|
|
33406
33485
|
actor: machine,
|
|
33407
33486
|
session: own.trim() || signInSessionName(record),
|
|
33408
|
-
projects: tradeProjects(env)
|
|
33487
|
+
projects: tradeProjects(env),
|
|
33488
|
+
...await heldApart()
|
|
33409
33489
|
});
|
|
33410
33490
|
return { client, signIn: { person: record.person, thumbprint: record.thumbprint } };
|
|
33411
33491
|
}
|
|
@@ -33438,11 +33518,11 @@ function forgetBrokerSession(session) {
|
|
|
33438
33518
|
function signInName(record) {
|
|
33439
33519
|
return `${record.person}\x00${record.thumbprint}`;
|
|
33440
33520
|
}
|
|
33441
|
-
function keyOf(env, own) {
|
|
33442
|
-
|
|
33443
|
-
|
|
33444
|
-
|
|
33445
|
-
};
|
|
33521
|
+
function keyOf(env, own, read) {
|
|
33522
|
+
const values = BROKER_VARIABLES.map((name) => env[name]);
|
|
33523
|
+
if (read !== undefined)
|
|
33524
|
+
values.push({ read: true, asOf: read.asOf ?? "" });
|
|
33525
|
+
return { session: own.trim(), variables: JSON.stringify(values) };
|
|
33446
33526
|
}
|
|
33447
33527
|
function entryFor(key) {
|
|
33448
33528
|
let sessions = CLIENTS.get(key.session);
|
|
@@ -33457,13 +33537,13 @@ function entryFor(key) {
|
|
|
33457
33537
|
}
|
|
33458
33538
|
return entry;
|
|
33459
33539
|
}
|
|
33460
|
-
async function make(env, own) {
|
|
33461
|
-
const made = await brokerTokenClient(env, own);
|
|
33540
|
+
async function make(env, own, read) {
|
|
33541
|
+
const made = await brokerTokenClient(env, own, read);
|
|
33462
33542
|
const signIn = made?.signIn;
|
|
33463
33543
|
return { client: made?.client, signIn: signIn === undefined ? "" : signInName(signIn) };
|
|
33464
33544
|
}
|
|
33465
|
-
async function clientFor(env, own) {
|
|
33466
|
-
const key = keyOf(env, own);
|
|
33545
|
+
async function clientFor(env, own, read) {
|
|
33546
|
+
const key = keyOf(env, own, read);
|
|
33467
33547
|
const entry = entryFor(key);
|
|
33468
33548
|
if (entry.refused.size > 0) {
|
|
33469
33549
|
const record = await chooseSignIn(env);
|
|
@@ -33478,7 +33558,7 @@ async function clientFor(env, own) {
|
|
|
33478
33558
|
}
|
|
33479
33559
|
let making = entry.making;
|
|
33480
33560
|
if (making === undefined) {
|
|
33481
|
-
const started = make(env, key.session);
|
|
33561
|
+
const started = make(env, key.session, read);
|
|
33482
33562
|
making = started;
|
|
33483
33563
|
entry.making = started;
|
|
33484
33564
|
started.then((made) => {
|
|
@@ -33508,13 +33588,13 @@ function untilAborted(promise, signal) {
|
|
|
33508
33588
|
});
|
|
33509
33589
|
});
|
|
33510
33590
|
}
|
|
33511
|
-
async function tradedToken(env, own, signal, waitForReady = false) {
|
|
33512
|
-
const { entry, made } = await untilAborted(clientFor(env, own), signal);
|
|
33591
|
+
async function tradedToken(env, own, { signal, waitForReady = false, read }) {
|
|
33592
|
+
const { entry, made } = await untilAborted(clientFor(env, own, read), signal);
|
|
33513
33593
|
const { client } = made;
|
|
33514
33594
|
if (client === undefined) {
|
|
33515
33595
|
throw new LoggableError("AGENT_SECRETS_URL and AGENT_SECRETS_MACHINE_IDENTITY no longer name a broker and an identity to trade");
|
|
33516
33596
|
}
|
|
33517
|
-
const { session, variables } = keyOf(env, own);
|
|
33597
|
+
const { session, variables } = keyOf(env, own, read);
|
|
33518
33598
|
try {
|
|
33519
33599
|
return {
|
|
33520
33600
|
token: await client.token(signal, { waitForReady }),
|
|
@@ -33529,7 +33609,7 @@ async function tradedToken(env, own, signal, waitForReady = false) {
|
|
|
33529
33609
|
}
|
|
33530
33610
|
}
|
|
33531
33611
|
function brokerTokenFor(env, session) {
|
|
33532
|
-
return (signal, waitForReady) => tradedToken(env, sessionName(session), signal, waitForReady);
|
|
33612
|
+
return (signal, waitForReady) => tradedToken(env, sessionName(session), { signal, waitForReady });
|
|
33533
33613
|
}
|
|
33534
33614
|
function dropHeld(key, token) {
|
|
33535
33615
|
CLIENTS.get(key.session)?.get(key.variables)?.made?.client?.drop(token);
|
|
@@ -33537,14 +33617,14 @@ function dropHeld(key, token) {
|
|
|
33537
33617
|
function dropTradedToken(env, traded) {
|
|
33538
33618
|
dropHeld(keyOf(env, traded.session), traded.token.accessToken);
|
|
33539
33619
|
}
|
|
33540
|
-
function brokerCredential(env, session) {
|
|
33620
|
+
function brokerCredential(env, session, read) {
|
|
33541
33621
|
let presented = "";
|
|
33542
33622
|
const presentedAs = new WeakMap;
|
|
33543
33623
|
const own = (acting) => (acting ?? "").trim() || sessionName(session);
|
|
33544
33624
|
return {
|
|
33545
33625
|
scheme: "DPoP",
|
|
33546
33626
|
async headers(method, url, acting, signal) {
|
|
33547
|
-
const traded = await tradedToken(env, own(acting), signal);
|
|
33627
|
+
const traded = await tradedToken(env, own(acting), { signal, read });
|
|
33548
33628
|
const { token, key, identity } = traded;
|
|
33549
33629
|
presented = token.accessToken;
|
|
33550
33630
|
const headers = {
|
|
@@ -33553,7 +33633,7 @@ function brokerCredential(env, session) {
|
|
|
33553
33633
|
};
|
|
33554
33634
|
presentedAs.set(headers, {
|
|
33555
33635
|
identity,
|
|
33556
|
-
key: keyOf(env, traded.session),
|
|
33636
|
+
key: keyOf(env, traded.session, read),
|
|
33557
33637
|
token: token.accessToken
|
|
33558
33638
|
});
|
|
33559
33639
|
return headers;
|
|
@@ -33561,12 +33641,65 @@ function brokerCredential(env, session) {
|
|
|
33561
33641
|
identity: (headers) => presentedAs.get(headers)?.identity,
|
|
33562
33642
|
stale(acting, headers) {
|
|
33563
33643
|
const told = headers === undefined ? undefined : presentedAs.get(headers);
|
|
33564
|
-
dropHeld(told?.key ?? keyOf(env, own(acting)), told?.token);
|
|
33644
|
+
dropHeld(told?.key ?? keyOf(env, own(acting), read), told?.token);
|
|
33565
33645
|
},
|
|
33566
33646
|
secret: () => presented
|
|
33567
33647
|
};
|
|
33568
33648
|
}
|
|
33569
33649
|
|
|
33650
|
+
// ../envoy-client/src/file-token-credential.ts
|
|
33651
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
33652
|
+
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
33653
|
+
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
33654
|
+
var PKCS8_LABEL = "PRIVATE KEY";
|
|
33655
|
+
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
33656
|
+
function readNamed(variable, filePath) {
|
|
33657
|
+
try {
|
|
33658
|
+
return readFileSync5(filePath, "utf8");
|
|
33659
|
+
} catch (error) {
|
|
33660
|
+
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
33661
|
+
}
|
|
33662
|
+
}
|
|
33663
|
+
function tokenIn(filePath) {
|
|
33664
|
+
const token = readNamed(TOKEN_FILE_VAR, filePath).trim();
|
|
33665
|
+
if (token === "") {
|
|
33666
|
+
throw new Error(`${TOKEN_FILE_VAR} names ${filePath}, which holds no token: it is empty or blank`);
|
|
33667
|
+
}
|
|
33668
|
+
if (!sendable(token)) {
|
|
33669
|
+
throw new Error(`${TOKEN_FILE_VAR} names ${filePath}, which holds whitespace or a control character inside its token`);
|
|
33670
|
+
}
|
|
33671
|
+
return holdSecret(token);
|
|
33672
|
+
}
|
|
33673
|
+
async function keyIn(filePath) {
|
|
33674
|
+
const pem = readNamed(DPOP_KEY_FILE_VAR, filePath).trim();
|
|
33675
|
+
if (!PKCS8_PEM.test(pem)) {
|
|
33676
|
+
throw new Error(`${DPOP_KEY_FILE_VAR} names ${filePath}, which does not hold one P-256 private key in PKCS#8 PEM`);
|
|
33677
|
+
}
|
|
33678
|
+
return await importDpopKey(pem, `${DPOP_KEY_FILE_VAR}'s key ${filePath}`);
|
|
33679
|
+
}
|
|
33680
|
+
function fileTokenCredential(files, dispatchUrl) {
|
|
33681
|
+
const origin = httpUrl2(dispatchUrl)?.origin;
|
|
33682
|
+
let presented = "";
|
|
33683
|
+
return {
|
|
33684
|
+
scheme: "DPoP",
|
|
33685
|
+
async headers(method, url) {
|
|
33686
|
+
const target = httpUrl2(url)?.origin;
|
|
33687
|
+
if (origin === undefined || target !== origin) {
|
|
33688
|
+
throw new Error(`the token ${TOKEN_FILE_VAR} names goes to DISPATCH_URL's origin (${origin}) alone, and this request is for ${target ?? "a URL that is not http or https"}`);
|
|
33689
|
+
}
|
|
33690
|
+
const token = tokenIn(files.tokenFile);
|
|
33691
|
+
const key = await keyIn(files.keyFile);
|
|
33692
|
+
presented = token;
|
|
33693
|
+
return {
|
|
33694
|
+
Authorization: `DPoP ${token}`,
|
|
33695
|
+
DPoP: await key.proof({ method, url, accessToken: token })
|
|
33696
|
+
};
|
|
33697
|
+
},
|
|
33698
|
+
stale() {},
|
|
33699
|
+
secret: () => presented
|
|
33700
|
+
};
|
|
33701
|
+
}
|
|
33702
|
+
|
|
33570
33703
|
// ../envoy-client/src/dispatch-config.ts
|
|
33571
33704
|
var DEFAULT_SERVER_URL = "http://localhost:8766";
|
|
33572
33705
|
function checkoutPair(checkout, serverUrl) {
|
|
@@ -33611,13 +33744,19 @@ function lostDispatchUrlNotice(env, config) {
|
|
|
33611
33744
|
].join("; ");
|
|
33612
33745
|
}
|
|
33613
33746
|
function dispatchSettings(env, config, options = {}) {
|
|
33614
|
-
const target = dispatchTarget(env, config);
|
|
33747
|
+
const target = dispatchTarget(env, config, options.tokenFiles === true);
|
|
33615
33748
|
if (!target.enabled)
|
|
33616
33749
|
return target;
|
|
33617
33750
|
const { url, urlSetting, source } = target;
|
|
33618
33751
|
let credential;
|
|
33619
33752
|
try {
|
|
33620
|
-
|
|
33753
|
+
if (source.kind === "broker")
|
|
33754
|
+
credential = brokerCredential(env, options.session, source.read);
|
|
33755
|
+
else if (source.kind === "files")
|
|
33756
|
+
credential = fileTokenCredential(source, url);
|
|
33757
|
+
else {
|
|
33758
|
+
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "DISPATCH", env, options.commands));
|
|
33759
|
+
}
|
|
33621
33760
|
} catch (error) {
|
|
33622
33761
|
return offWithError(messageFor(error));
|
|
33623
33762
|
}
|
|
@@ -33640,6 +33779,63 @@ function dispatchUrl(env, config) {
|
|
|
33640
33779
|
const target = dispatchTarget(env, config);
|
|
33641
33780
|
return target.enabled ? target.url : undefined;
|
|
33642
33781
|
}
|
|
33782
|
+
var BESIDE_TOKEN_FILES = [
|
|
33783
|
+
"DISPATCH_TOKEN_BROKER",
|
|
33784
|
+
"DISPATCH_TOKEN_BROKER_READ",
|
|
33785
|
+
"DISPATCH_TOKEN_BROKER_AS_OF",
|
|
33786
|
+
"DISPATCH_TOKEN",
|
|
33787
|
+
"DISPATCH_TOKEN_FILE",
|
|
33788
|
+
BROKER_URL_VAR,
|
|
33789
|
+
IDENTITY_VAR
|
|
33790
|
+
];
|
|
33791
|
+
function tokenFilesSet(env) {
|
|
33792
|
+
const set = [
|
|
33793
|
+
...nonEmpty(env.DISPATCH_BROKER_TOKEN_FILE) === undefined ? [] : [TOKEN_FILE_VAR],
|
|
33794
|
+
...nonEmpty(env.DISPATCH_BROKER_DPOP_KEY_FILE) === undefined ? [] : [DPOP_KEY_FILE_VAR]
|
|
33795
|
+
];
|
|
33796
|
+
if (set.length === 0)
|
|
33797
|
+
return;
|
|
33798
|
+
return `${set.join(" and ")} ${set.length === 1 ? "is" : "are"} set`;
|
|
33799
|
+
}
|
|
33800
|
+
function settingsBesideTokenFiles(env) {
|
|
33801
|
+
return BESIDE_TOKEN_FILES.filter((name) => nonEmpty(env[name]) !== undefined).map((name) => `${name} is set`);
|
|
33802
|
+
}
|
|
33803
|
+
function tokenFilesTarget(env, config, taken) {
|
|
33804
|
+
const set = tokenFilesSet(env);
|
|
33805
|
+
if (set === undefined)
|
|
33806
|
+
return;
|
|
33807
|
+
if (!taken) {
|
|
33808
|
+
return offWithError(`${set}, and only the dispatch command reads the token files: Dispatch is off here rather than written with another credential beside them`);
|
|
33809
|
+
}
|
|
33810
|
+
const tokenFile = nonEmpty(env.DISPATCH_BROKER_TOKEN_FILE);
|
|
33811
|
+
const keyFile = nonEmpty(env.DISPATCH_BROKER_DPOP_KEY_FILE);
|
|
33812
|
+
const explicitUrl = nonEmpty(env.DISPATCH_URL);
|
|
33813
|
+
const { checkout } = config;
|
|
33814
|
+
const problems = [
|
|
33815
|
+
...tokenFile === undefined ? [`${TOKEN_FILE_VAR} is not set`] : [],
|
|
33816
|
+
...keyFile === undefined ? [`${DPOP_KEY_FILE_VAR} is not set`] : [],
|
|
33817
|
+
...explicitUrl === undefined ? ["DISPATCH_URL is not set"] : [],
|
|
33818
|
+
...settingsBesideTokenFiles(env),
|
|
33819
|
+
...config.dispatch.token === undefined ? [] : [`dispatch.token is set in ${config.path}`],
|
|
33820
|
+
...checkout?.kind === "valid" && checkout.dispatch.token !== undefined ? [`dispatch.token is set in ${checkout.path}`] : [],
|
|
33821
|
+
...checkout?.kind === "invalid" ? [`${checkout.error}, so whether it sets dispatch.token cannot be told`] : []
|
|
33822
|
+
];
|
|
33823
|
+
if (problems.length > 0 || tokenFile === undefined || keyFile === undefined || explicitUrl === undefined) {
|
|
33824
|
+
return offWithError(`${TOKEN_FILE_VAR} and ${DPOP_KEY_FILE_VAR} go together, with DISPATCH_URL, as the dispatch command's only Dispatch credential: ${problems.join("; ")}`);
|
|
33825
|
+
}
|
|
33826
|
+
if (config.dispatch.enabled === false) {
|
|
33827
|
+
return offWithNotice(`${config.path} sets dispatch.enabled to false: Dispatch is off`);
|
|
33828
|
+
}
|
|
33829
|
+
if (httpUrl2(explicitUrl) === undefined) {
|
|
33830
|
+
return offWithError("DISPATCH_URL must be an http or https URL");
|
|
33831
|
+
}
|
|
33832
|
+
return {
|
|
33833
|
+
enabled: true,
|
|
33834
|
+
url: withoutTrailingSlashes(explicitUrl),
|
|
33835
|
+
urlSetting: "DISPATCH_URL",
|
|
33836
|
+
source: { kind: "files", tokenFile, keyFile }
|
|
33837
|
+
};
|
|
33838
|
+
}
|
|
33643
33839
|
function brokerRouteForced(env) {
|
|
33644
33840
|
const written = (env.DISPATCH_TOKEN_BROKER ?? "").trim();
|
|
33645
33841
|
if (written === "")
|
|
@@ -33648,12 +33844,55 @@ function brokerRouteForced(env) {
|
|
|
33648
33844
|
return true;
|
|
33649
33845
|
return offWithError("DISPATCH_TOKEN_BROKER takes 1: set it to 1 where this session's Dispatch credential is traded at the secrets broker (the person signed in on this machine, else the machine's own identity), and leave it unset where a bearer is read as usual");
|
|
33650
33846
|
}
|
|
33651
|
-
|
|
33847
|
+
var CUT_FORM = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
|
|
33848
|
+
var ZERO_TIME = Date.parse("0001-01-01T00:00:00.000Z");
|
|
33849
|
+
function isCut(text) {
|
|
33850
|
+
const parts = CUT_FORM.exec(text);
|
|
33851
|
+
if (parts === null)
|
|
33852
|
+
return false;
|
|
33853
|
+
const [year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0] = parts.slice(1, 7).map((part) => Number(part ?? "0"));
|
|
33854
|
+
const [zoneHour = 0, zoneMinute = 0] = parts.slice(9, 11).map((part) => Number(part ?? "0"));
|
|
33855
|
+
const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
33856
|
+
const exists = month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth && hour <= 23 && minute <= 59 && second <= 59 && zoneHour <= 23 && zoneMinute <= 59;
|
|
33857
|
+
if (!exists)
|
|
33858
|
+
return false;
|
|
33859
|
+
const offset = (parts[8] === "-" ? -1 : 1) * (zoneHour * 60 + zoneMinute);
|
|
33860
|
+
const instant = new Date(0);
|
|
33861
|
+
instant.setUTCFullYear(year, month - 1, day);
|
|
33862
|
+
instant.setUTCHours(hour, minute - offset, second, 0);
|
|
33863
|
+
return Number(parts[7] ?? "0") !== 0 || instant.getTime() !== ZERO_TIME;
|
|
33864
|
+
}
|
|
33865
|
+
function readTradeSetting(env) {
|
|
33866
|
+
const read = (env.DISPATCH_TOKEN_BROKER_READ ?? "").trim();
|
|
33867
|
+
const cut = (env.DISPATCH_TOKEN_BROKER_AS_OF ?? "").trim();
|
|
33868
|
+
if (read !== "" && read !== "1") {
|
|
33869
|
+
return offWithError("DISPATCH_TOKEN_BROKER_READ takes 1: set it to 1 where this session's Dispatch credential is a broker token that only reads, and leave it unset where it writes");
|
|
33870
|
+
}
|
|
33871
|
+
if (read === "") {
|
|
33872
|
+
if (cut === "")
|
|
33873
|
+
return;
|
|
33874
|
+
return offWithError("DISPATCH_TOKEN_BROKER_AS_OF names the cut a read-only token reads at, and goes only beside DISPATCH_TOKEN_BROKER_READ=1: set DISPATCH_TOKEN_BROKER_READ to 1 beside it, or unset DISPATCH_TOKEN_BROKER_AS_OF");
|
|
33875
|
+
}
|
|
33876
|
+
if (cut === "")
|
|
33877
|
+
return {};
|
|
33878
|
+
if (!isCut(cut)) {
|
|
33879
|
+
return offWithError("DISPATCH_TOKEN_BROKER_AS_OF is not an RFC 3339 time with at most six fractional digits and Z or a numeric offset, such as 1999-12-31T23:59:59Z");
|
|
33880
|
+
}
|
|
33881
|
+
return { asOf: cut };
|
|
33882
|
+
}
|
|
33883
|
+
function dispatchTarget(env, config, tokenFiles = false) {
|
|
33652
33884
|
if (config.kind === "failed")
|
|
33653
33885
|
return offWithError(config.error);
|
|
33654
|
-
const
|
|
33655
|
-
if (
|
|
33656
|
-
return
|
|
33886
|
+
const files = tokenFilesTarget(env, config, tokenFiles);
|
|
33887
|
+
if (files !== undefined)
|
|
33888
|
+
return files;
|
|
33889
|
+
const brokerOnly = brokerRouteForced(env);
|
|
33890
|
+
if (typeof brokerOnly !== "boolean")
|
|
33891
|
+
return brokerOnly;
|
|
33892
|
+
const read = readTradeSetting(env);
|
|
33893
|
+
if (read !== undefined && "enabled" in read)
|
|
33894
|
+
return read;
|
|
33895
|
+
const forced = brokerOnly || read !== undefined;
|
|
33657
33896
|
const explicitUrl = nonEmpty(env.DISPATCH_URL);
|
|
33658
33897
|
const checkoutFile = explicitUrl === undefined ? config.checkout : null;
|
|
33659
33898
|
if (checkoutFile?.kind === "invalid")
|
|
@@ -33695,10 +33934,10 @@ function dispatchTarget(env, config) {
|
|
|
33695
33934
|
if (route.traded) {
|
|
33696
33935
|
const brokered = withoutTrailingSlashes(explicitUrl ?? own.serverUrl ?? DEFAULT_SERVER_URL);
|
|
33697
33936
|
const urlSetting = explicitUrl !== undefined ? "DISPATCH_URL" : own.serverUrl !== undefined ? `dispatch.serverUrl in ${config.path}` : DEFAULT_URL_SETTING;
|
|
33698
|
-
return { enabled: true, url: brokered, urlSetting, source: { kind: "broker" } };
|
|
33937
|
+
return { enabled: true, url: brokered, urlSetting, source: { kind: "broker", read } };
|
|
33699
33938
|
}
|
|
33700
33939
|
if (forced) {
|
|
33701
|
-
return offWithError(
|
|
33940
|
+
return offWithError(`${read === undefined ? "DISPATCH_TOKEN_BROKER" : "DISPATCH_TOKEN_BROKER_READ"} is set, so this session's Dispatch credential is traded at the secrets broker (the person signed in on this machine, else the machine's own identity), and ${route.gap}: Dispatch is off rather than written with whatever bearer this box holds`);
|
|
33702
33941
|
}
|
|
33703
33942
|
return offWithError(explicitUrl === undefined ? `${config.path}: dispatch is enabled and no token is: set dispatch.token, or DISPATCH_TOKEN or DISPATCH_TOKEN_FILE` : `DISPATCH_URL is set and no token is: set DISPATCH_TOKEN or DISPATCH_TOKEN_FILE, or dispatch.token in ${config.path}`);
|
|
33704
33943
|
}
|
|
@@ -33884,7 +34123,6 @@ function brokerNatsCredential(env, session, source = NATS_AUTH_VAR, tradeDeadlin
|
|
|
33884
34123
|
admissions: () => admissions
|
|
33885
34124
|
};
|
|
33886
34125
|
}
|
|
33887
|
-
var RENEW_FLOOR_MS = 1000;
|
|
33888
34126
|
var RETRY_FIRST_MS = 2000;
|
|
33889
34127
|
var RETRY_LAST_MS = 60000;
|
|
33890
34128
|
var WARN_AGAIN_MS = 30 * 60000;
|
|
@@ -33941,11 +34179,7 @@ function warnedEvery(warn) {
|
|
|
33941
34179
|
};
|
|
33942
34180
|
}
|
|
33943
34181
|
function renewDelay(expiry, now) {
|
|
33944
|
-
|
|
33945
|
-
if (remaining <= 0)
|
|
33946
|
-
return 0;
|
|
33947
|
-
const ahead = remaining - Math.min(DEFAULT_RENEW_BEFORE_MS, remaining / 2);
|
|
33948
|
-
return Math.max(Math.min(RENEW_FLOOR_MS, remaining / 2), ahead);
|
|
34182
|
+
return renewalAt(expiry, now, DEFAULT_RENEW_BEFORE_MS) - now;
|
|
33949
34183
|
}
|
|
33950
34184
|
function keepNatsCredential(connection, credential, warn) {
|
|
33951
34185
|
let stopped = false;
|
|
@@ -34384,7 +34618,8 @@ function sessionDispatchSettings(file, env, options) {
|
|
|
34384
34618
|
return {
|
|
34385
34619
|
dispatch: dispatchSettings(env, config, {
|
|
34386
34620
|
commands: options.commands,
|
|
34387
|
-
session: options.session
|
|
34621
|
+
session: options.session,
|
|
34622
|
+
tokenFiles: options.tokenFiles
|
|
34388
34623
|
}),
|
|
34389
34624
|
warnings: config.kind === "read" ? config.warnings : [],
|
|
34390
34625
|
missing: config.kind === "read" ? config.missing : null
|
|
@@ -34594,7 +34829,7 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
34594
34829
|
|
|
34595
34830
|
// src/codex/codex-session-record.ts
|
|
34596
34831
|
import { spawnSync } from "child_process";
|
|
34597
|
-
import { readFileSync as
|
|
34832
|
+
import { readFileSync as readFileSync7, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
|
|
34598
34833
|
import { mkdir as mkdir4, readFile as readFile5, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
34599
34834
|
import { homedir as homedir3 } from "os";
|
|
34600
34835
|
import { basename as basename4, dirname as dirname5, join as join10 } from "path";
|
|
@@ -34604,7 +34839,7 @@ import { readFile as readFile4 } from "fs/promises";
|
|
|
34604
34839
|
import { basename as basename3, join as join9 } from "path";
|
|
34605
34840
|
|
|
34606
34841
|
// src/session-state.ts
|
|
34607
|
-
import { readFileSync as
|
|
34842
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
34608
34843
|
import { mkdir as mkdir3, readdir as readdir3, rename as rename4, rm as rm3, stat as stat3, utimes as utimes2, writeFile as writeFile2 } from "fs/promises";
|
|
34609
34844
|
import { dirname as dirname4, join as join8 } from "path";
|
|
34610
34845
|
async function writeAtomicStateFile(file, contents) {
|
|
@@ -34650,7 +34885,7 @@ async function removeChosenTitle(file) {
|
|
|
34650
34885
|
}
|
|
34651
34886
|
function readChosenTitleSync(file) {
|
|
34652
34887
|
try {
|
|
34653
|
-
return
|
|
34888
|
+
return readFileSync6(file, "utf8");
|
|
34654
34889
|
} catch {
|
|
34655
34890
|
return;
|
|
34656
34891
|
}
|
|
@@ -34843,14 +35078,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
34843
35078
|
}
|
|
34844
35079
|
function procComm(pid) {
|
|
34845
35080
|
try {
|
|
34846
|
-
return
|
|
35081
|
+
return readFileSync7(`/proc/${pid}/comm`, "utf8").trim();
|
|
34847
35082
|
} catch {
|
|
34848
35083
|
return;
|
|
34849
35084
|
}
|
|
34850
35085
|
}
|
|
34851
35086
|
function procParent(pid) {
|
|
34852
35087
|
try {
|
|
34853
|
-
const stat =
|
|
35088
|
+
const stat = readFileSync7(`/proc/${pid}/stat`, "utf8");
|
|
34854
35089
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
34855
35090
|
return Number.isInteger(parent) ? parent : undefined;
|
|
34856
35091
|
} catch {
|
|
@@ -34864,7 +35099,7 @@ var PS_OPTIONS = {
|
|
|
34864
35099
|
};
|
|
34865
35100
|
function procStarted(pid) {
|
|
34866
35101
|
try {
|
|
34867
|
-
const stat =
|
|
35102
|
+
const stat = readFileSync7(`/proc/${pid}/stat`, "utf8");
|
|
34868
35103
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
34869
35104
|
} catch {
|
|
34870
35105
|
return;
|
|
@@ -34885,7 +35120,7 @@ function recordOfProcess(record, pid) {
|
|
|
34885
35120
|
function sharedAppServer(pid) {
|
|
34886
35121
|
let argv;
|
|
34887
35122
|
try {
|
|
34888
|
-
argv =
|
|
35123
|
+
argv = readFileSync7(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
34889
35124
|
} catch {
|
|
34890
35125
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
34891
35126
|
if (ps.status !== 0)
|
|
@@ -35038,7 +35273,7 @@ function singleQuoted(value) {
|
|
|
35038
35273
|
}
|
|
35039
35274
|
function envFileText(envFile) {
|
|
35040
35275
|
try {
|
|
35041
|
-
return
|
|
35276
|
+
return readFileSync8(envFile, "utf8");
|
|
35042
35277
|
} catch (error) {
|
|
35043
35278
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
35044
35279
|
throw error;
|
|
@@ -35164,7 +35399,7 @@ function refreshLockHeld(lock) {
|
|
|
35164
35399
|
let text;
|
|
35165
35400
|
try {
|
|
35166
35401
|
age = Date.now() - statSync2(lock).mtimeMs;
|
|
35167
|
-
text =
|
|
35402
|
+
text = readFileSync8(lock, "utf8");
|
|
35168
35403
|
} catch (error) {
|
|
35169
35404
|
if (hasErrnoCode(error, "ENOENT"))
|
|
35170
35405
|
return false;
|
|
@@ -35200,7 +35435,7 @@ function takeRefreshLock(lock) {
|
|
|
35200
35435
|
function refreshOutcome(file, since) {
|
|
35201
35436
|
let value;
|
|
35202
35437
|
try {
|
|
35203
|
-
value = JSON.parse(
|
|
35438
|
+
value = JSON.parse(readFileSync8(file, "utf8"));
|
|
35204
35439
|
} catch {
|
|
35205
35440
|
return;
|
|
35206
35441
|
}
|