@sjawhar/claude-envoy 5.23.7 → 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 +667 -175
- package/dist/dispatch.js +9662 -9157
- package/dist/envoy-channel.js +1642 -1150
- package/dist/session-hook.js +645 -153
- 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);
|
|
@@ -17522,6 +17574,8 @@ var ASK_OPTIONS_CONTRACT = "Options carry the genuinely different approaches. Ea
|
|
|
17522
17574
|
var ASK_IS_FOR_A_PERSON = "An ask is a question for a person, never a request to another agent. Ask an agent by envoy_send or a comment on the issue.";
|
|
17523
17575
|
var ASK_WAITS_ON_THE_ASSIGNEE = "An ask waits on its asked-of person, else the issue's assignee, else the project's default assignee; no agent hands one on.";
|
|
17524
17576
|
var HUMAN_AGREED_TO_DOCUMENT = "the human has agreed to every point in the document";
|
|
17577
|
+
var DOCUMENT_OWNER_RULE = "Exactly one of issue and project is required; with project, artifact names the document.";
|
|
17578
|
+
var NAMED_DOCUMENT_OWNER_RULE = "Exactly one of issue and project is required; artifact or ref must name the document.";
|
|
17525
17579
|
function documentOwnerValidation(requireArtifact, alwaysRequireArtifact = false) {
|
|
17526
17580
|
return {
|
|
17527
17581
|
check: (value) => {
|
|
@@ -17532,15 +17586,21 @@ function documentOwnerValidation(requireArtifact, alwaysRequireArtifact = false)
|
|
|
17532
17586
|
const hasRef = typeof input.ref === "string";
|
|
17533
17587
|
return (hasIssue !== hasProject || !hasIssue && !hasProject && hasRef) && (!hasProject || !requireArtifact || hasArtifact) && (!alwaysRequireArtifact || hasArtifact || hasRef);
|
|
17534
17588
|
},
|
|
17535
|
-
message: alwaysRequireArtifact ?
|
|
17589
|
+
message: alwaysRequireArtifact ? NAMED_DOCUMENT_OWNER_RULE : DOCUMENT_OWNER_RULE
|
|
17536
17590
|
};
|
|
17537
17591
|
}
|
|
17538
17592
|
var ARTIFACT_SOURCE_RULE = "Give at most one of path and content. A call with neither makes an empty document under the name, which a person or an agent writes in afterwards with dispatch doc-edit.";
|
|
17539
|
-
var ARTIFACT_OWNER_AND_SOURCE_RULE = `${ARTIFACT_SOURCE_RULE}
|
|
17593
|
+
var ARTIFACT_OWNER_AND_SOURCE_RULE = `${ARTIFACT_SOURCE_RULE} ${DOCUMENT_OWNER_RULE}`;
|
|
17540
17594
|
function brokenParts(parts) {
|
|
17541
17595
|
const broken = parts.filter(([kept]) => !kept).map(([, message]) => message);
|
|
17542
17596
|
return broken.length === 0 ? undefined : broken.join(" ");
|
|
17543
17597
|
}
|
|
17598
|
+
function withoutOwnerRule(refusal) {
|
|
17599
|
+
const rule = DISPATCH_OWNER_RULES.find((owner) => refusal === owner || refusal.startsWith(`${owner} `));
|
|
17600
|
+
if (rule === undefined)
|
|
17601
|
+
return refusal;
|
|
17602
|
+
return refusal === rule ? undefined : refusal.slice(rule.length + 1);
|
|
17603
|
+
}
|
|
17544
17604
|
var CONTENT_IS_MARKDOWN = "content is stored as a Markdown document, which rewrites other text (a JSONL file's lines come back joined into one paragraph)";
|
|
17545
17605
|
var DOCUMENT_IS_MARKDOWN = "a document holds Markdown, which rewrites other text (a JSONL file's lines come back joined into one paragraph)";
|
|
17546
17606
|
var PATH_KEEPS_BYTES = "path (--path <file>), which stores a file whose path does not end in .md or .markdown as its bytes, unchanged";
|
|
@@ -17584,18 +17644,13 @@ function pathKeepsBytesOf(name) {
|
|
|
17584
17644
|
var artifactOwner = documentOwnerValidation(false);
|
|
17585
17645
|
function artifactProblem(value) {
|
|
17586
17646
|
const input = value;
|
|
17587
|
-
const
|
|
17647
|
+
const extension = typeof input.path === "string" || typeof input.name !== "string" ? undefined : NAME_EXTENSION.exec(input.name.trim())?.[1];
|
|
17648
|
+
const nameProblem = extension === undefined || MARKDOWN_EXTENSION.test(extension) ? undefined : `${DOCUMENT_IS_MARKDOWN}, and ${JSON.stringify(input.name)} is not a Markdown name. Upload the file under the same name with ${PATH_KEEPS_BYTES}; a document takes a name ending in .md or .markdown or with no extension.`;
|
|
17649
|
+
return brokenParts([
|
|
17588
17650
|
[artifactOwner.check(value), artifactOwner.message],
|
|
17589
|
-
[typeof input.path !== "string" || typeof input.content !== "string", ARTIFACT_SOURCE_RULE]
|
|
17651
|
+
[typeof input.path !== "string" || typeof input.content !== "string", ARTIFACT_SOURCE_RULE],
|
|
17652
|
+
[nameProblem === undefined, nameProblem ?? ""]
|
|
17590
17653
|
]);
|
|
17591
|
-
if (ownerOrSourceProblem !== undefined)
|
|
17592
|
-
return ownerOrSourceProblem;
|
|
17593
|
-
if (typeof input.path === "string" || typeof input.name !== "string")
|
|
17594
|
-
return;
|
|
17595
|
-
const extension = NAME_EXTENSION.exec(input.name.trim())?.[1];
|
|
17596
|
-
if (extension === undefined || MARKDOWN_EXTENSION.test(extension))
|
|
17597
|
-
return;
|
|
17598
|
-
return `${DOCUMENT_IS_MARKDOWN}, and ${JSON.stringify(input.name)} is not a Markdown name. Upload the file under the same name with ${PATH_KEEPS_BYTES}; a document takes a name ending in .md or .markdown or with no extension.`;
|
|
17599
17654
|
}
|
|
17600
17655
|
var documentEditOwner = documentOwnerValidation(true);
|
|
17601
17656
|
var PRECONDITION_RULE = "A precondition selects exactly one of document or blocks.";
|
|
@@ -17690,34 +17745,100 @@ var ISSUE_UPDATE_FIELDS_RULE = "Issue update requires at least one field besides
|
|
|
17690
17745
|
var ISSUE_UPDATE_DONE_RULE = "status done requires reason, a non-empty note saying why the issue is closing, posted on the issue before it closes so the close carries its note";
|
|
17691
17746
|
var ISSUE_UPDATE_REASON_RULE = "reason goes only with status done";
|
|
17692
17747
|
var ISSUE_UPDATE_LABELS_RULE = "labels_add goes without labels";
|
|
17693
|
-
var
|
|
17694
|
-
|
|
17695
|
-
|
|
17748
|
+
var ISSUE_UPDATE_LABELS_REFUSAL = `${ISSUE_UPDATE_LABELS_RULE}: labels replaces every label the issue holds and labels_add adds to them, so name the labels to add in labels_add alone, or the whole set in labels alone.`;
|
|
17749
|
+
var ISSUE_STATUS_OPTIONS = [
|
|
17750
|
+
"include_children",
|
|
17751
|
+
"unlink_children",
|
|
17752
|
+
"include_parent"
|
|
17753
|
+
];
|
|
17754
|
+
function issueStatusOptionsOf(input) {
|
|
17755
|
+
return ISSUE_STATUS_OPTIONS.filter((option) => input[option] === true);
|
|
17756
|
+
}
|
|
17757
|
+
var ISSUE_UPDATE_PATCH_FIELDS = [
|
|
17758
|
+
"title",
|
|
17759
|
+
"labels",
|
|
17760
|
+
"labels_add",
|
|
17761
|
+
"priority",
|
|
17762
|
+
"assignee",
|
|
17763
|
+
"external_links",
|
|
17764
|
+
"route",
|
|
17765
|
+
"parent",
|
|
17766
|
+
"blocked_by",
|
|
17767
|
+
"advances",
|
|
17768
|
+
"advances_revision",
|
|
17769
|
+
"components",
|
|
17770
|
+
"repo",
|
|
17771
|
+
"before",
|
|
17772
|
+
"after"
|
|
17773
|
+
];
|
|
17774
|
+
var ISSUE_UPDATE_OPTIONS_RULE = "include_children, unlink_children and include_parent go with status, and with reason when the status is done, and with no other field. include_children does not go with unlink_children, or with status done.";
|
|
17775
|
+
var ISSUE_UPDATE_RULE = `${ISSUE_UPDATE_FIELDS_RULE} ${ISSUE_UPDATE_DONE_RULE}; ${ISSUE_UPDATE_REASON_RULE}; ${ISSUE_UPDATE_LABELS_RULE}. ${ISSUE_UPDATE_OPTIONS_RULE}`;
|
|
17776
|
+
function issueStatusOptionsProblem(input) {
|
|
17777
|
+
const options = issueStatusOptionsOf(input);
|
|
17778
|
+
if (options.length === 0)
|
|
17779
|
+
return;
|
|
17780
|
+
const named = options.join(", ").replace(/, ([^,]*)$/, " and $1");
|
|
17781
|
+
const others = ISSUE_UPDATE_PATCH_FIELDS.filter((field) => input[field] !== undefined);
|
|
17782
|
+
return brokenParts([
|
|
17783
|
+
[
|
|
17784
|
+
!(input["include_children"] === true && input["unlink_children"] === true),
|
|
17785
|
+
"include_children does not go with unlink_children. The open children move with the issue or leave it, so name one of the two."
|
|
17786
|
+
],
|
|
17787
|
+
[
|
|
17788
|
+
!(input["include_children"] === true && input["status"] === "done"),
|
|
17789
|
+
"include_children does not go with status done. Only a person who is signed in at a browser can close the open issues under an issue together with it, and this call presents a token. That person does it on the issue's page in Dispatch: Close issue, then Move them with it."
|
|
17790
|
+
],
|
|
17791
|
+
[
|
|
17792
|
+
typeof input["status"] === "string",
|
|
17793
|
+
`status is required with ${named}. Add status, or drop ${named}.`
|
|
17794
|
+
],
|
|
17795
|
+
[
|
|
17796
|
+
others.length === 0,
|
|
17797
|
+
`With ${named}, give status alone, and reason when the status is done. This call also names ${others.join(", ")}. Send those fields in a call of their own.`
|
|
17798
|
+
]
|
|
17799
|
+
]);
|
|
17800
|
+
}
|
|
17801
|
+
function issueReasonProblem(input) {
|
|
17696
17802
|
if (input.status === "done") {
|
|
17697
|
-
|
|
17698
|
-
return `${ISSUE_UPDATE_DONE_RULE}.`;
|
|
17699
|
-
}
|
|
17700
|
-
} else if (input.reason !== undefined) {
|
|
17701
|
-
const status = typeof input.status === "string" ? `status ${input.status}` : "an update without status done";
|
|
17702
|
-
return `${ISSUE_UPDATE_REASON_RULE}: it is the note posted on the issue as it closes, and ${status} closes nothing. Drop reason, or set status done to close the issue.`;
|
|
17703
|
-
}
|
|
17704
|
-
if (input.labels !== undefined && input.labels_add !== undefined) {
|
|
17705
|
-
return `${ISSUE_UPDATE_LABELS_RULE}: labels replaces every label the issue holds and labels_add adds to them, so name the labels to add in labels_add alone, or the whole set in labels alone.`;
|
|
17803
|
+
return typeof input.reason !== "string" || input.reason.trim() === "" ? `${ISSUE_UPDATE_DONE_RULE}.` : undefined;
|
|
17706
17804
|
}
|
|
17805
|
+
if (input.reason === undefined)
|
|
17806
|
+
return;
|
|
17807
|
+
const status = typeof input.status === "string" ? `status ${input.status}` : "an update without status done";
|
|
17808
|
+
return `${ISSUE_UPDATE_REASON_RULE}: it is the note posted on the issue as it closes, and ${status} closes nothing. Drop reason, or set status done to close the issue.`;
|
|
17809
|
+
}
|
|
17810
|
+
function issueUpdateProblem(value) {
|
|
17811
|
+
const input = value;
|
|
17812
|
+
const reasonProblem = issueReasonProblem(input);
|
|
17813
|
+
const optionsProblem = issueStatusOptionsProblem(value);
|
|
17814
|
+
const broken = brokenParts([
|
|
17815
|
+
[reasonProblem === undefined, reasonProblem ?? ""],
|
|
17816
|
+
[input.labels === undefined || input.labels_add === undefined, ISSUE_UPDATE_LABELS_REFUSAL],
|
|
17817
|
+
[optionsProblem === undefined, optionsProblem ?? ""]
|
|
17818
|
+
]);
|
|
17819
|
+
if (broken !== undefined)
|
|
17820
|
+
return broken;
|
|
17707
17821
|
const changesAField = typeof input.status === "string" || typeof input.title === "string" || Array.isArray(input.labels) || Array.isArray(input.labels_add) || typeof input.priority === "number" || input.priority === null || typeof input.assignee === "string" || input.assignee === null || Array.isArray(input.external_links) || typeof input.route === "string" || typeof input.parent === "string" || Array.isArray(input.blocked_by) || Array.isArray(input.advances) || typeof input.components === "object" && input.components !== null || typeof input.repo === "string" || typeof input.before === "string" || typeof input.after === "string";
|
|
17708
17822
|
return changesAField ? undefined : ISSUE_UPDATE_FIELDS_RULE;
|
|
17709
17823
|
}
|
|
17824
|
+
var MESSAGE_OWNER_RULE = "issue is required unless in_reply_to names a message delivered to this session, which is the one message with no issue.";
|
|
17710
17825
|
var messageValidation = {
|
|
17711
17826
|
check: (value) => {
|
|
17712
17827
|
const input = value;
|
|
17713
17828
|
return typeof input.issue === "string" || typeof input.in_reply_to === "string";
|
|
17714
17829
|
},
|
|
17715
|
-
message:
|
|
17830
|
+
message: MESSAGE_OWNER_RULE
|
|
17716
17831
|
};
|
|
17717
17832
|
var readOwner = documentOwnerValidation(false);
|
|
17718
17833
|
var READ_OWNER_RULE = "Exactly one of issue and project is required; project alone lists its documents, and with artifact names one.";
|
|
17719
17834
|
var READ_MESSAGE_RULE = "message stands alone: it names the conversation, so name no issue, project, artifact, or ref with it.";
|
|
17720
17835
|
var READ_HISTORY_RULE = "history reads each body an edit or the delete of one post replaced, so it needs a ref naming one comment or one issue message: message stands alone and names a whole conversation, which keeps no history of its own.";
|
|
17836
|
+
var DISPATCH_OWNER_RULES = [
|
|
17837
|
+
DOCUMENT_OWNER_RULE,
|
|
17838
|
+
NAMED_DOCUMENT_OWNER_RULE,
|
|
17839
|
+
READ_OWNER_RULE,
|
|
17840
|
+
MESSAGE_OWNER_RULE
|
|
17841
|
+
];
|
|
17721
17842
|
function readProblem(value) {
|
|
17722
17843
|
const input = value;
|
|
17723
17844
|
const historyKept = input.history !== true || typeof input.ref === "string";
|
|
@@ -17908,11 +18029,14 @@ var dispatchToolSpecs = [
|
|
|
17908
18029
|
priority: 1,
|
|
17909
18030
|
before: "DSP-2"
|
|
17910
18031
|
},
|
|
17911
|
-
description: "Update an existing issue: move its lifecycle status, retitle it, add labels to it or " + "replace its labels, set " + "its priority, set or clear its assignee, link a URL (the pull request that delivers it, a " + "run, a document), set its " + "route, set or clear its parent, replace the issues it is blocked by, replace the " + "priorities it advances, attach it to " + "architecture components, set the repository it targets, or move it on its project's " + "board. Status is one of " + `${ISSUE_STATUSES.join(", ")}; outside Legion, move it yourself as the work advances; inside ` + "Legion the daemon moves it. labels_add adds labels and keeps every label the issue holds; " + "labels replaces the whole set, so a label it does not name is removed, and the two never " + "go together. A non-empty external_links is " + "merged into the issue's existing links by URL, so linking the pull request you just opened " + "keeps every earlier link; an empty external_links removes every link instead. components " + "replaces the issue's own attachment. Closing an issue " + "(status done) requires reason, the note that says why: it is posted on the issue as a " + "message, then the issue closes, so the close carries its note; closing an issue that is " + "already closed is refused (ISSUE_CLOSED) before anything is posted. Reason goes only " + "with status done. Closing an issue withdraws every open ask " + "it holds (resolution kind withdrawn, naming the closer), and reopening it brings exactly " + "those asks back. " + "A closed issue still takes messages and comments, though not asks or artifacts; of this " + "tool's fields it takes only a board move " + "(before, after), components, " + "a reopening status (any status but done), and an external_links write that adds no new " + "link (so a link can move to the issue that replaced it); everything else, priority " + "included, waits for the reopen. " + "priority is yours to set and a human overrides it. assignee is the person who answers " + "this issue's asks, and every ask on it waits on them until a person hands that ask on. " + "Passing null unassigns the issue, and every ask on it then waits on the project's default " + "assignee: a question reaches the person it was handed to, else the issue's assignee, else " + "the project's default assignee, so every question reaches a person. " + "Set the assignee when a person said who owns the work, as you " + "file the issue or hand it over. before and after move the issue on " + "its project's board: before puts it above that issue, after below, and both together " + "land it between them. A project's board order is one agent's to keep; in a Legion " + "deployment that is the controller. Never reassign an issue a person holds to get a " + "faster answer: who holds it is their call. At least one " + `field besides issue is required. ${ISSUE_REFERENCE}`,
|
|
18032
|
+
description: "Update an existing issue: move its lifecycle status, retitle it, add labels to it or " + "replace its labels, set " + "its priority, set or clear its assignee, link a URL (the pull request that delivers it, a " + "run, a document), set its " + "route, set or clear its parent, replace the issues it is blocked by, replace the " + "priorities it advances, attach it to " + "architecture components, set the repository it targets, or move it on its project's " + "board. Status is one of " + `${ISSUE_STATUSES.join(", ")}; outside Legion, move it yourself as the work advances; inside ` + "Legion the daemon moves it. labels_add adds labels and keeps every label the issue holds; " + "labels replaces the whole set, so a label it does not name is removed, and the two never " + "go together. A non-empty external_links is " + "merged into the issue's existing links by URL, so linking the pull request you just opened " + "keeps every earlier link; an empty external_links removes every link instead. components " + "replaces the issue's own attachment. Closing an issue " + "(status done) requires reason, the note that says why: it is posted on the issue as a " + "message, then the issue closes, so the close carries its note; closing an issue that is " + "already closed is refused (ISSUE_CLOSED) before anything is posted. Reason goes only " + "with status done. Closing an issue withdraws every open ask " + "it holds (resolution kind withdrawn, naming the closer), and reopening it brings exactly " + "those asks back. " + "Dispatch puts the statuses in three groups: not started (triage, icebox, backlog), in work " + "(todo, in_progress, testing, needs_review, retro) and done. A parent is done only when each " + "child is done, and while a child is in work its parent is in work. Where Dispatch keeps " + "this rule, it refuses a status or parent change that breaks it with 409 " + "PARENT_STATUS_CONFLICT, which names each issue that holds it. include_children, " + "unlink_children and include_parent tell Dispatch what to do with those issues. Each goes " + "with status alone, and with reason when the status is done. include_children does not go " + "with done: only a person signed in at a browser closes the open issues under an issue " + "together with it, on the issue's page. " + "A closed issue still takes messages and comments, though not asks or artifacts; of this " + "tool's fields it takes only a board move " + "(before, after), components, " + "a reopening status (any status but done), and an external_links write that adds no new " + "link (so a link can move to the issue that replaced it); everything else, priority " + "included, waits for the reopen. " + "priority is yours to set and a human overrides it. assignee is the person who answers " + "this issue's asks, and every ask on it waits on them until a person hands that ask on. " + "Passing null unassigns the issue, and every ask on it then waits on the project's default " + "assignee: a question reaches the person it was handed to, else the issue's assignee, else " + "the project's default assignee, so every question reaches a person. " + "Set the assignee when a person said who owns the work, as you " + "file the issue or hand it over. before and after move the issue on " + "its project's board: before puts it above that issue, after below, and both together " + "land it between them. A project's board order is one agent's to keep; in a Legion " + "deployment that is the controller. Never reassign an issue a person holds to get a " + "faster answer: who holds it is their call. At least one " + `field besides issue is required. ${ISSUE_REFERENCE}`,
|
|
17912
18033
|
arguments: (z) => ({
|
|
17913
18034
|
issue: z.string().describe(ISSUE_REFERENCE),
|
|
17914
18035
|
status: z.enum(ISSUE_STATUSES).describe("New lifecycle status.").optional(),
|
|
17915
18036
|
reason: z.string().describe(`Required with status done, and only with it: why the issue is closing. Posted on the issue as a message before it closes. ${BODY_BLOCK_RULE}`).optional(),
|
|
18037
|
+
include_children: z.boolean().describe("With status, also write that status on each open issue under this issue, at any depth, whose status is in another group. Not with status done, which this tool refuses before anything is sent: only a person who is signed in at a browser can close the open issues under an issue together with it, on the issue's page in Dispatch (Close issue, then Move them with it).").optional(),
|
|
18038
|
+
unlink_children: z.boolean().describe("With status, also remove each open child from this issue, so that it has no parent. Each child keeps its status, and a done child stays.").optional(),
|
|
18039
|
+
include_parent: z.boolean().describe("With status, also move each issue above this issue that is not in work to in_progress, a done one included.").optional(),
|
|
17916
18040
|
title: z.string({ min: 1, max: ISSUE_TITLE_MAX }).describe("Replacement title, at most 1,000 characters.").optional(),
|
|
17917
18041
|
labels: z.array(z.string({ min: 1, max: ISSUE_LABEL_MAX }), { max: MAX_ISSUE_LABELS }).describe(`Replacement label set, at most ${MAX_ISSUE_LABELS} labels of up to ${ISSUE_LABEL_MAX} characters; replaces every existing label, so a label it does not name is removed. To add labels and keep the others, use labels_add. Not with labels_add.`).optional(),
|
|
17918
18042
|
labels_add: z.array(z.string({ min: 1, max: ISSUE_LABEL_MAX }), { max: MAX_ISSUE_LABELS }).describe(`Labels to add, at most ${MAX_ISSUE_LABELS} of up to ${ISSUE_LABEL_MAX} characters: each is added to the labels the issue holds when the write lands, and every label it holds stays; the issue holds at most ${MAX_ISSUE_LABELS} in all. Not with labels.`).optional(),
|
|
@@ -18366,7 +18490,7 @@ var dispatchToolSpecs = [
|
|
|
18366
18490
|
{
|
|
18367
18491
|
name: "dispatch_issues",
|
|
18368
18492
|
example: { project: "PROJ", limit: 250, offset: 250 },
|
|
18369
|
-
description: "List a project's issues for a roadmap or backlog pass: every issue in one project, each carrying " + "its status, priority, parent, labels, open-ask count, progress (its spec's task-list items and " + "its direct children, each done of total, as `tasks 3/7 \xB7 children 2/5`, each only when it has " + "any), and route with whether it reaches anyone, " + "so you can see backlog shape without opening every issue. Optionally filter by status, parent, " + "label, priority, route status, or how recently it changed; priority takes one or more of 0-3 " + "(P0-P3) and null for an issue with no priority, so an owner's P0/P1 audit is priority [0, 1]. " + 'route_status "no_holder" lists every open issue whose route names a role nobody holds or a ' + "session that is not running, as of the server's copy of the listener's session list, at " + "most 5 s old, whatever its priority. A restarting " + "session is absent for minutes, so an issue is unowned only when a read ten minutes later agrees. " + "Do not use it to search by keyword or phrase; dispatch search remains the keyword surface. " + "Dispatch pages the list: limit sets the page size (default " + `${DEFAULT_ISSUE_PAGE_LIMIT}, max ${MAX_ISSUE_PAGE_LIMIT}) and offset selects where it starts ` + "(default 0), and the answer names how many issues match, so repeat with the next offset to " + "walk every matching issue. A walk is exact only while the list does not change: an issue " + "that enters or leaves what the filters match, or whose status or rank changes, between two " + "pages shifts rows across a page boundary, so one issue can come back twice and another never. " + "all takes the whole filtered list in one read instead, for a caller that must not miss or " + "repeat a row while other writers change the list, and especially for one whose own writes " + "move issues out of what it filtered on.",
|
|
18493
|
+
description: "List a project's issues for a roadmap or backlog pass: every issue in one project, each carrying " + "its status, priority, parent, labels, open-ask count, progress (its spec's task-list items and " + "its direct children, each done of total, as `tasks 3/7 \xB7 children 2/5`, each only when it has " + "any), and route with whether it reaches anyone, " + "so you can see backlog shape without opening every issue. Optionally filter by status, parent, " + "label, priority, route status, or how recently it changed; priority takes one or more of 0-3 " + "(P0-P3) and null for an issue with no priority, so an owner's P0/P1 audit is priority [0, 1]. " + 'route_status "no_holder" lists every open issue whose route names a role nobody holds or a ' + "session that is not running, as of the server's copy of the listener's session list, at " + "most 5 s old, whatever its priority. A restarting " + "session is absent for minutes, so an issue is unowned only when a read ten minutes later agrees. " + "Do not use it to search by keyword or phrase; dispatch search remains the keyword surface. " + "Dispatch pages the list: limit sets the page size (default " + `${DEFAULT_ISSUE_PAGE_LIMIT}, max ${MAX_ISSUE_PAGE_LIMIT}) and offset selects where it starts ` + "(default 0), and the answer names how many issues match, so repeat with the next offset to " + "walk every matching issue. A walk is exact only while the list does not change: an issue " + "that enters or leaves what the filters match, or whose status or rank changes, between two " + "pages shifts rows across a page boundary, so one issue can come back twice and another never. " + "all takes the whole filtered list in one read instead, for a caller that must not miss or " + "repeat a row while other writers change the list, and especially for one whose own writes " + "move issues out of what it filtered on. json prints the listing as one JSON object, for a " + "program such as jq to read.",
|
|
18370
18494
|
arguments: (z) => ({
|
|
18371
18495
|
project: z.string().describe("Project key to list issues from."),
|
|
18372
18496
|
status: z.enum(ISSUE_STATUSES).describe("Optional lifecycle status filter.").optional(),
|
|
@@ -18377,7 +18501,8 @@ var dispatchToolSpecs = [
|
|
|
18377
18501
|
route_status: z.enum(ISSUE_ROUTE_STATUSES).describe("Optional: only open issues whose route is in this state. live: a running session holds " + "the role or is the routed session. holder_unresponsive: that session has missed its " + "heartbeats without ending, so the route still reaches it and its messages wait. " + "no_holder: nobody running holds the role, or the session is gone, right now. " + "unknown: the Envoy listener did not answer.").optional(),
|
|
18378
18502
|
limit: z.number({ int: true, min: 1, max: MAX_ISSUE_PAGE_LIMIT }).describe(`Maximum rows, 1-${MAX_ISSUE_PAGE_LIMIT}; default ${DEFAULT_ISSUE_PAGE_LIMIT}.`).optional(),
|
|
18379
18503
|
offset: z.number({ int: true, min: 0 }).describe("Rows to skip before the page; nonnegative integer; default 0.").optional(),
|
|
18380
|
-
all: z.boolean().describe("Take every matching issue in one unpaged read, so no row is missed or repeated while " + "the list changes. Refused with limit or offset.").optional()
|
|
18504
|
+
all: z.boolean().describe("Take every matching issue in one unpaged read, so no row is missed or repeated while " + "the list changes. Refused with limit or offset.").optional(),
|
|
18505
|
+
json: z.boolean().describe("Print the listing as one JSON object and nothing else: {issues, total, offset, limit}, " + "each issue with its status, parent and labels. The dispatch command prints it whole, " + "also on a host that cuts long output.").optional()
|
|
18381
18506
|
})
|
|
18382
18507
|
},
|
|
18383
18508
|
{
|
|
@@ -23958,18 +24083,22 @@ var DISPATCH_URL_SETTING = "the configured Dispatch URL";
|
|
|
23958
24083
|
class DispatchServiceError extends Error {
|
|
23959
24084
|
code;
|
|
23960
24085
|
status;
|
|
24086
|
+
name = "DispatchServiceError";
|
|
24087
|
+
fromDispatch = true;
|
|
23961
24088
|
candidates;
|
|
23962
24089
|
current;
|
|
23963
24090
|
mismatches;
|
|
23964
|
-
|
|
23965
|
-
|
|
23966
|
-
constructor(code, status, message,
|
|
24091
|
+
issues;
|
|
24092
|
+
changed;
|
|
24093
|
+
constructor(code, status, message, details = {}) {
|
|
23967
24094
|
super(message);
|
|
23968
24095
|
this.code = code;
|
|
23969
24096
|
this.status = status;
|
|
23970
|
-
this.candidates = candidates;
|
|
23971
|
-
this.current = current;
|
|
23972
|
-
this.mismatches = mismatches;
|
|
24097
|
+
this.candidates = details.candidates;
|
|
24098
|
+
this.current = details.current;
|
|
24099
|
+
this.mismatches = details.mismatches;
|
|
24100
|
+
this.issues = details.issues;
|
|
24101
|
+
this.changed = details.changed;
|
|
23973
24102
|
}
|
|
23974
24103
|
}
|
|
23975
24104
|
|
|
@@ -24070,6 +24199,9 @@ function reviewNoRouteRefusal(baseUrl, route, version) {
|
|
|
24070
24199
|
function resultDryRunNoRouteRefusal(baseUrl, route) {
|
|
24071
24200
|
return new DispatchServiceError("NOT_FOUND", 404, `Dispatch at ${urlForText(baseUrl, DISPATCH_URL_SETTING)} answered no route for ${route} each ` + "time the dry run was sent: this build is older than a result's dry run, so it cannot show " + "the pull-request body line before the record. Nothing was recorded.");
|
|
24072
24201
|
}
|
|
24202
|
+
function statusChangeNoRouteRefusal(baseUrl, route) {
|
|
24203
|
+
return new DispatchServiceError("NOT_FOUND", 404, `Dispatch at ${urlForText(baseUrl, DISPATCH_URL_SETTING)} answered no route for ${route} each ` + "time the status change was sent. This build is older than that route, so it takes no " + "include_children, unlink_children or include_parent, and nothing changed. No PATCH was " + "sent in its place, since a PATCH would write the status without the option.");
|
|
24204
|
+
}
|
|
24073
24205
|
var ISSUE_EVENTS_PAGE_MAX = 200;
|
|
24074
24206
|
var DISPATCH_TOOL_DEADLINE_MS = 60000;
|
|
24075
24207
|
function requestSignal(signal, deadlineMs) {
|
|
@@ -24388,6 +24520,14 @@ class DispatchClient {
|
|
|
24388
24520
|
async updateIssue(issue, input) {
|
|
24389
24521
|
return this.#json("PATCH", ["api", "v1", "issues", await this.#resolveIssue(issue)], input);
|
|
24390
24522
|
}
|
|
24523
|
+
async changeIssueStatus(issue, input) {
|
|
24524
|
+
const path = ["api", "v1", "issues", await this.#resolveIssue(issue), "status-change"];
|
|
24525
|
+
try {
|
|
24526
|
+
return await this.#json("POST", path, input);
|
|
24527
|
+
} catch (error) {
|
|
24528
|
+
throw this.#refusalOfNoRoute(error, path, (route) => statusChangeNoRouteRefusal(this.#baseUrl, route));
|
|
24529
|
+
}
|
|
24530
|
+
}
|
|
24391
24531
|
async claimIssue(issue, input = {}) {
|
|
24392
24532
|
return this.#json("POST", ["api", "v1", "issues", await this.#resolveIssue(issue), "claim"], input);
|
|
24393
24533
|
}
|
|
@@ -24542,10 +24682,7 @@ class DispatchClient {
|
|
|
24542
24682
|
try {
|
|
24543
24683
|
return await this.#json("POST", path, body);
|
|
24544
24684
|
} catch (error) {
|
|
24545
|
-
|
|
24546
|
-
throw error;
|
|
24547
|
-
const route = `POST /${path.map((segment) => encodeURIComponent(segment)).join("/")}`;
|
|
24548
|
-
throw reviewNoRouteRefusal(this.#baseUrl, route, version);
|
|
24685
|
+
throw this.#refusalOfNoRoute(error, path, (route) => reviewNoRouteRefusal(this.#baseUrl, route, version));
|
|
24549
24686
|
}
|
|
24550
24687
|
}
|
|
24551
24688
|
async recordResult(issue, input) {
|
|
@@ -24556,10 +24693,7 @@ class DispatchClient {
|
|
|
24556
24693
|
try {
|
|
24557
24694
|
return await this.#writingNothing(path, input, { writes: false });
|
|
24558
24695
|
} catch (error) {
|
|
24559
|
-
|
|
24560
|
-
throw error;
|
|
24561
|
-
const route = `POST /${path.map((segment) => encodeURIComponent(segment)).join("/")}`;
|
|
24562
|
-
throw resultDryRunNoRouteRefusal(this.#baseUrl, route);
|
|
24696
|
+
throw this.#refusalOfNoRoute(error, path, (route) => resultDryRunNoRouteRefusal(this.#baseUrl, route));
|
|
24563
24697
|
}
|
|
24564
24698
|
}
|
|
24565
24699
|
async issueResults(issue, at) {
|
|
@@ -24804,6 +24938,11 @@ class DispatchClient {
|
|
|
24804
24938
|
sleep: this.#sleep
|
|
24805
24939
|
});
|
|
24806
24940
|
}
|
|
24941
|
+
#refusalOfNoRoute(error, path, refuse) {
|
|
24942
|
+
if (!(error instanceof DispatchNoRouteError) && !isNoRoute(error))
|
|
24943
|
+
return error;
|
|
24944
|
+
return refuse(`POST /${path.map((segment) => encodeURIComponent(segment)).join("/")}`);
|
|
24945
|
+
}
|
|
24807
24946
|
#writeCall(method, url, key, writes = true) {
|
|
24808
24947
|
if (method !== "POST" && method !== "PATCH")
|
|
24809
24948
|
return;
|
|
@@ -25137,7 +25276,7 @@ class DispatchClient {
|
|
|
25137
25276
|
if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
25138
25277
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
25139
25278
|
}
|
|
25140
|
-
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error
|
|
25279
|
+
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
|
|
25141
25280
|
}
|
|
25142
25281
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
25143
25282
|
}
|
|
@@ -26933,6 +27072,7 @@ var pictureSendingTools = {
|
|
|
26933
27072
|
};
|
|
26934
27073
|
var refGrammarProblem = "ref must be a valid dispatch:// reference such as dispatch://KEY-1, " + "dispatch://KEY-1/ask/<uuid>, dispatch://KEY-1/comment/<uuid>, " + "dispatch://KEY-1/message/<uuid>, dispatch://KEY-1/artifact/<slug>, " + "dispatch://PROJECT/artifact/<document-ref> (an artifact id, slug, or filename), " + "dispatch://KEY-1/spec#b-<block id>, dispatch://KEY-1/artifact/<slug>#b-<block id> or " + "dispatch://PROJECT/artifact/<slug>#b-<block id> (one block of a document, its id " + "percent-encoded, optionally pinned to a version of the document with @v<N> after it; for " + "dispatch read), dispatch://KEY-1/ask/<uuid>#b-<part id> or " + "dispatch://PROJECT/artifact/<slug>/ask/<uuid>#b-<part id> (one part of an ask: its question, " + "one of its options or its answer, optionally pinned to a revision of the ask's parts with " + "@v<N> after it; for dispatch read), dispatch://KEY-1/comment/<uuid>#b-<block id>, " + "dispatch://PROJECT/artifact/<slug>/comment/<uuid>#b-<block id> or " + "dispatch://KEY-1/message/<uuid>#b-<block id> (one block of a comment or message, a " + "comment's optionally pinned to a revision of the comment with @v<N> after it; for dispatch " + "read), or " + "dispatch://agent/<session id>/artifact/<slug> (a picture in a conversation on the Agents page, " + "for dispatch doc-read); a dashboard URL on this Dispatch server is accepted too";
|
|
26935
27074
|
var ownerRequiredProblem = "issue is required; supply issue or set LEGION_ISSUE";
|
|
27075
|
+
var ownerStandInIssue = "OWNER-1";
|
|
26936
27076
|
function argumentProblems(tool, args) {
|
|
26937
27077
|
const problems = [];
|
|
26938
27078
|
switch (tool) {
|
|
@@ -27218,7 +27358,7 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
|
|
|
27218
27358
|
const legionIssue = env.LEGION_ISSUE;
|
|
27219
27359
|
if (!legionIssue) {
|
|
27220
27360
|
problems.push(ownerRequiredProblem);
|
|
27221
|
-
return { args, ref, owner: null };
|
|
27361
|
+
return { args, ref, owner: null, ownerMissing: true };
|
|
27222
27362
|
}
|
|
27223
27363
|
if (nativeIssueKeyPattern.test(legionIssue) || externalIssueRefPattern.test(legionIssue)) {
|
|
27224
27364
|
const issue = canonicalExternalIssueRef(legionIssue);
|
|
@@ -27226,18 +27366,24 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
|
|
|
27226
27366
|
}
|
|
27227
27367
|
if (!bareIssueNumberPattern.test(legionIssue)) {
|
|
27228
27368
|
problems.push("LEGION_ISSUE must be a native issue key (e.g. LEGION-3), an external owner/repo#n reference, or a bare positive issue number");
|
|
27229
|
-
return { args, ref, owner: null };
|
|
27369
|
+
return { args, ref, owner: null, ownerMissing: true };
|
|
27230
27370
|
}
|
|
27231
27371
|
const repo = await resolveCwdRepo(cwd, exec);
|
|
27232
27372
|
if (!repo) {
|
|
27233
27373
|
problems.push("issue is required; LEGION_ISSUE needs a GitHub repository in cwd");
|
|
27234
|
-
return { args, ref, owner: null };
|
|
27374
|
+
return { args, ref, owner: null, ownerMissing: true };
|
|
27235
27375
|
}
|
|
27236
27376
|
const issue = `${repo}#${legionIssue}`;
|
|
27237
27377
|
return { args: { ...args, issue }, ref, owner: { kind: "issue", issue } };
|
|
27238
27378
|
}
|
|
27239
|
-
function
|
|
27240
|
-
|
|
27379
|
+
function withoutMissingOwner(issue) {
|
|
27380
|
+
if (issue.code === "invalid_type" && issue.path.length === 1 && issue.path[0] === "issue" && issue.input === undefined) {
|
|
27381
|
+
return;
|
|
27382
|
+
}
|
|
27383
|
+
if (issue.code !== "custom" || issue.path.length !== 0)
|
|
27384
|
+
return issue;
|
|
27385
|
+
const message = withoutOwnerRule(issue.message);
|
|
27386
|
+
return message === undefined ? undefined : message === issue.message ? issue : { ...issue, message };
|
|
27241
27387
|
}
|
|
27242
27388
|
function dispatchServerUrls(config) {
|
|
27243
27389
|
return config.publicUrl === undefined ? [config.url] : [config.url, config.publicUrl];
|
|
@@ -27248,11 +27394,12 @@ async function checkDispatchCall(input) {
|
|
|
27248
27394
|
const owner = await resolveOwnerArguments(tool, args, cwd, input.env ?? process.env, input.exec ?? defaultExec, input.serverUrls, problems);
|
|
27249
27395
|
const conflicts = issueFreeTools[tool] === true ? [] : ownerConflictProblems(tool, args, owner.ref, optionalString(owner.args, "ref"));
|
|
27250
27396
|
problems.push(...conflicts);
|
|
27251
|
-
const
|
|
27397
|
+
const ownerAlreadySaid = issueFreeTools[tool] !== true && (owner.owner === null || conflicts.length > 0);
|
|
27252
27398
|
const schema = toolSchema(tool);
|
|
27253
|
-
const
|
|
27399
|
+
const standIn = owner.ownerMissing === true;
|
|
27400
|
+
const parsed = schema.safeParse(standIn ? { ...owner.args, issue: ownerStandInIssue } : owner.args, { reportInput: true });
|
|
27254
27401
|
if (!parsed.success) {
|
|
27255
|
-
const issues =
|
|
27402
|
+
const issues = standIn ? parsed.error.issues : ownerAlreadySaid ? parsed.error.issues.flatMap((issue) => withoutMissingOwner(issue) ?? []) : parsed.error.issues;
|
|
27256
27403
|
problems.push(...formatZodIssues(issues, schema, tool));
|
|
27257
27404
|
}
|
|
27258
27405
|
problems.push(...argumentProblems(tool, owner.args));
|
|
@@ -27260,7 +27407,7 @@ async function checkDispatchCall(input) {
|
|
|
27260
27407
|
return {
|
|
27261
27408
|
problems,
|
|
27262
27409
|
owner,
|
|
27263
|
-
args: parsed.success ? parsed.data : owner.args,
|
|
27410
|
+
args: parsed.success && !standIn ? parsed.data : owner.args,
|
|
27264
27411
|
pictures
|
|
27265
27412
|
};
|
|
27266
27413
|
}
|
|
@@ -27278,7 +27425,75 @@ function refusalWithCode(error, ...clauses) {
|
|
|
27278
27425
|
}
|
|
27279
27426
|
if (!(error instanceof DispatchServiceError))
|
|
27280
27427
|
return error;
|
|
27281
|
-
|
|
27428
|
+
const told = joined !== "" && /[.!?]$/.test(error.message) ? `${error.message} ${suffix.charAt(0).toUpperCase()}${suffix.slice(1)}` : `${error.message}${joined}`;
|
|
27429
|
+
return new DispatchServiceError(error.code, error.status, `${error.code}: ${told}`, error);
|
|
27430
|
+
}
|
|
27431
|
+
function parentStatusConflictLines(error, tool, args, legionIssue) {
|
|
27432
|
+
if (!dispatchAnswered(error, 409) || error.code !== "PARENT_STATUS_CONFLICT")
|
|
27433
|
+
return;
|
|
27434
|
+
const issues = error.issues ?? [];
|
|
27435
|
+
if (issues.length === 0)
|
|
27436
|
+
return;
|
|
27437
|
+
const parents = issues.filter((issue) => issue.relation === "parent").map(({ key }) => key);
|
|
27438
|
+
const children = issues.filter((issue) => issue.relation === "child").map(({ key }) => key);
|
|
27439
|
+
return [
|
|
27440
|
+
messageFor(error),
|
|
27441
|
+
...issues.map((issue) => `${issue.key} [${issue.status}] ${issue.title}`),
|
|
27442
|
+
...nextSteps(tool, args, parents, children, legionIssue)
|
|
27443
|
+
];
|
|
27444
|
+
}
|
|
27445
|
+
var CHILD_FLAGS = "dispatch issue-update --status takes --unlink-children, which removes its open children from it, or, with a status other than done, --include-children, which moves the open issues under the issue with it. A person signed in at a browser closes them with it on the issue's page.";
|
|
27446
|
+
var PARENT_FLAG = "dispatch issue-update --status takes --include-parent, which moves each issue above the issue that is not in work to in_progress.";
|
|
27447
|
+
function otherProjectSentence(named, keys) {
|
|
27448
|
+
const project = named === undefined ? undefined : issueProject(named);
|
|
27449
|
+
if (project === undefined)
|
|
27450
|
+
return "";
|
|
27451
|
+
const others = keys.filter((key) => {
|
|
27452
|
+
const other = issueProject(key);
|
|
27453
|
+
return other !== undefined && other !== project;
|
|
27454
|
+
});
|
|
27455
|
+
if (others.length === 0)
|
|
27456
|
+
return "";
|
|
27457
|
+
const one = others.length === 1;
|
|
27458
|
+
return ` ${others.join(", ")} ${one ? "is" : "are"} not in the project of ${named}. A credential scoped to one project is refused a step that writes ${one ? "it" : "them"} (403 PROJECT_SCOPE), so a person, or a credential that names no project, must make that step.`;
|
|
27459
|
+
}
|
|
27460
|
+
function includeParentCall(key) {
|
|
27461
|
+
return `${commandLine("dispatch_issue_update", { issue: key, status: "in_progress", include_parent: true })}, which also moves each issue above ${key} that is not in work`;
|
|
27462
|
+
}
|
|
27463
|
+
function nextSteps(tool, args, parents, children, legionIssue) {
|
|
27464
|
+
if (tool === "dispatch_issue") {
|
|
27465
|
+
return parents.map((key) => `dispatch issue takes no flag that moves a done parent. Reopen ${key} first, with ${includeParentCall(key)}, then run dispatch issue again; or run it with --parent naming an open issue, or with no --parent.`);
|
|
27466
|
+
}
|
|
27467
|
+
const issueUpdate = tool === "dispatch_issue_update";
|
|
27468
|
+
const written = issueUpdate ? args : {};
|
|
27469
|
+
const fields = Object.keys(written).filter((field) => field !== "issue" && written[field] !== undefined);
|
|
27470
|
+
const issue = optionalString(written, "issue");
|
|
27471
|
+
const named = issueUpdate ? issue ?? legionIssue : undefined;
|
|
27472
|
+
const childHolds = children.length > 0;
|
|
27473
|
+
const childScope = otherProjectSentence(named, children);
|
|
27474
|
+
const status = optionalString(written, "status");
|
|
27475
|
+
const parent = optionalString(written, "parent");
|
|
27476
|
+
const alone = `--status${status === "done" ? " and --reason" : ""} alone`;
|
|
27477
|
+
if (parent !== undefined && parent !== "") {
|
|
27478
|
+
const issueFlag = issue === undefined ? "" : ` --issue ${issue}`;
|
|
27479
|
+
const statusFlag = status === undefined || childHolds ? "" : ` --status ${status}`;
|
|
27480
|
+
const kept = fields.filter((field) => field !== "parent" && field !== "status" && !(childHolds && field === "reason"));
|
|
27481
|
+
const otherFlags = kept.length > 0 ? ", with the call's other flags" : "";
|
|
27482
|
+
const reparent = `dispatch issue-update${issueFlag} --parent ${parent}${statusFlag}${otherFlags}`;
|
|
27483
|
+
const afterStatus = childHolds ? ", after the status change," : "";
|
|
27484
|
+
return [
|
|
27485
|
+
...childHolds ? [
|
|
27486
|
+
`${CHILD_FLAGS} Each goes with ${alone}, so run the status change first, in a call of its own, and the reparent after it: ${reparent}.${childScope}`
|
|
27487
|
+
] : [],
|
|
27488
|
+
...parents.map((key) => `dispatch issue-update takes no flag that moves the parent a reparent names. Move ${key} into work first, with ${includeParentCall(key)}; then${afterStatus} run the reparent again: ${reparent}.`)
|
|
27489
|
+
];
|
|
27490
|
+
}
|
|
27491
|
+
const others = ISSUE_UPDATE_PATCH_FIELDS.some((field) => written[field] !== undefined);
|
|
27492
|
+
const apart = (subject) => others ? ` ${subject} with ${alone}, so send the call's other changes in a call of their own.` : "";
|
|
27493
|
+
return [
|
|
27494
|
+
...childHolds ? [`${CHILD_FLAGS}${apart("Each goes")}${childScope}`] : [],
|
|
27495
|
+
...parents.length > 0 ? [`${PARENT_FLAG}${apart("It goes")}${otherProjectSentence(named, parents)}`] : []
|
|
27496
|
+
];
|
|
27282
27497
|
}
|
|
27283
27498
|
function dispatchAnswered(error, status) {
|
|
27284
27499
|
return error instanceof DispatchServiceError && error.fromDispatch && error.status === status;
|
|
@@ -27303,6 +27518,11 @@ function writeMayHaveLanded(error) {
|
|
|
27303
27518
|
return error.mayHaveReachedDispatch;
|
|
27304
27519
|
return !(error instanceof DispatchServiceError) || error.status >= 500;
|
|
27305
27520
|
}
|
|
27521
|
+
function closeAccount(error, closingNote) {
|
|
27522
|
+
const posted = `the reason already landed as message ${closingNote.id} (${closingNote.ref})`;
|
|
27523
|
+
const fix = error instanceof DispatchGatewayError && error.transient ? "" : "fix what refused the close, then ";
|
|
27524
|
+
return writeMayHaveLanded(error) ? `${posted}, and the close may or may not have taken effect. Read the issue's status before retrying: done means it closed; otherwise retry with a reason that points at message ${closingNote.id}, since retrying this call posts its reason again` : `${posted} but the issue did not close. Retrying this call posts its reason again, so ${fix}retry with a reason that points at message ${closingNote.id}`;
|
|
27525
|
+
}
|
|
27306
27526
|
function withAccount(error, account) {
|
|
27307
27527
|
const message = messageFor(error);
|
|
27308
27528
|
const told = /[.!?]$/.test(message) ? `${message} ${account.charAt(0).toUpperCase()}${account.slice(1)}` : `${message}; ${account}`;
|
|
@@ -28656,6 +28876,85 @@ async function followedAskDetails(client, ask, artifact) {
|
|
|
28656
28876
|
return { ...await askOwnerDetails(client, ask, artifact), follows: { ask: ask.id } };
|
|
28657
28877
|
}
|
|
28658
28878
|
|
|
28879
|
+
// ../envoy-client/src/dispatch-commands/status-change.ts
|
|
28880
|
+
async function issuesBeforeStatusChange(client, before, options) {
|
|
28881
|
+
const issues = new Map([
|
|
28882
|
+
[before.key, { status: before.status, parent: before.parent ?? null }]
|
|
28883
|
+
]);
|
|
28884
|
+
for (const child of before.children ?? []) {
|
|
28885
|
+
issues.set(child.key, { status: child.status, parent: before.key });
|
|
28886
|
+
}
|
|
28887
|
+
try {
|
|
28888
|
+
if (options.includes("include_children")) {
|
|
28889
|
+
for (const row of await client.listAllIssues({ project: before.project })) {
|
|
28890
|
+
issues.set(row.key, { status: row.status, parent: row.parent ?? null });
|
|
28891
|
+
}
|
|
28892
|
+
} else if (options.includes("include_parent")) {
|
|
28893
|
+
let parent = before.parent ?? null;
|
|
28894
|
+
while (parent !== null && !issues.has(parent)) {
|
|
28895
|
+
const above = await client.getIssue(parent);
|
|
28896
|
+
issues.set(above.key, { status: above.status, parent: above.parent ?? null });
|
|
28897
|
+
parent = above.parent ?? null;
|
|
28898
|
+
}
|
|
28899
|
+
}
|
|
28900
|
+
} catch (error) {
|
|
28901
|
+
throw refusalWithCode(error);
|
|
28902
|
+
}
|
|
28903
|
+
return issues;
|
|
28904
|
+
}
|
|
28905
|
+
async function statusChangeCommand(context, before, options, issuesBefore, closingNote) {
|
|
28906
|
+
const { args, client, actor, input, issue } = context;
|
|
28907
|
+
const status = stringArg(args, "status");
|
|
28908
|
+
const change = (entry) => {
|
|
28909
|
+
const was = issuesBefore.get(entry.key);
|
|
28910
|
+
if (entry.key !== before.key && entry.parent === null && was?.parent === before.key) {
|
|
28911
|
+
return `unlinked from ${before.key}`;
|
|
28912
|
+
}
|
|
28913
|
+
return was === undefined ? `status -> ${entry.status}` : `status ${was.status} -> ${entry.status}`;
|
|
28914
|
+
};
|
|
28915
|
+
let answer;
|
|
28916
|
+
try {
|
|
28917
|
+
answer = await client.changeIssueStatus(issue(), {
|
|
28918
|
+
status,
|
|
28919
|
+
...options.includes("include_children") ? { include_children: true } : {},
|
|
28920
|
+
...options.includes("unlink_children") ? { unlink_children: true } : {},
|
|
28921
|
+
...options.includes("include_parent") ? { include_parent: true } : {},
|
|
28922
|
+
actor
|
|
28923
|
+
});
|
|
28924
|
+
} catch (error) {
|
|
28925
|
+
if (error instanceof DispatchWriteLandedError)
|
|
28926
|
+
throw error;
|
|
28927
|
+
const committed = error instanceof DispatchServiceError ? error.changed ?? [] : [];
|
|
28928
|
+
const changed = committed.length === 0 ? "" : `the steps before the refusal changed ${committed.map((entry) => `${entry.key} (${change(entry)})`).join(", ")}`;
|
|
28929
|
+
if (closingNote === undefined)
|
|
28930
|
+
throw refusalWithCode(error, changed);
|
|
28931
|
+
const landed = closeAccount(error, closingNote);
|
|
28932
|
+
if (error instanceof DispatchServiceError)
|
|
28933
|
+
throw refusalWithCode(error, changed, landed);
|
|
28934
|
+
throw withAccount(error, landed);
|
|
28935
|
+
}
|
|
28936
|
+
const suffix = await notSubscribed(issueTopic(before.key), input.subscriptions);
|
|
28937
|
+
const namedLine = (after) => `${before.key}: ${[
|
|
28938
|
+
...closingNote === undefined ? [] : [`reason posted as message ${closingNote.id} (${closingNote.ref})`],
|
|
28939
|
+
`status ${before.status} -> ${after}`
|
|
28940
|
+
].join("; ")}${suffix}`;
|
|
28941
|
+
const changed = answer.changed ?? [];
|
|
28942
|
+
const lines = changed.map((entry) => entry.key === before.key ? namedLine(entry.status) : `${entry.key}: ${change(entry)}`);
|
|
28943
|
+
if (!changed.some((entry) => entry.key === before.key))
|
|
28944
|
+
lines.push(namedLine(answer.issue.status));
|
|
28945
|
+
return {
|
|
28946
|
+
text: lines.join(`
|
|
28947
|
+
`),
|
|
28948
|
+
details: {
|
|
28949
|
+
issue: before.key,
|
|
28950
|
+
status: answer.issue.status,
|
|
28951
|
+
external_links: (answer.issue.external_links ?? []).map((link) => link.url),
|
|
28952
|
+
changed: changed.map(({ key, status, parent }) => ({ key, status, parent })),
|
|
28953
|
+
...closingNote === undefined ? {} : { message: closingNote.id }
|
|
28954
|
+
}
|
|
28955
|
+
};
|
|
28956
|
+
}
|
|
28957
|
+
|
|
28659
28958
|
// ../envoy-client/src/dispatch-commands/issues.ts
|
|
28660
28959
|
function componentsChange(input, after) {
|
|
28661
28960
|
switch (input.mode) {
|
|
@@ -28807,6 +29106,7 @@ async function issueUpdateCommand(context) {
|
|
|
28807
29106
|
const advances = optionalStringArray(args, "advances");
|
|
28808
29107
|
const advancesRevision = optionalNumber(args, "advances_revision");
|
|
28809
29108
|
const requestedLinks = Array.isArray(args.external_links) ? [...new Set(args.external_links)] : undefined;
|
|
29109
|
+
const options = issueStatusOptionsOf(args);
|
|
28810
29110
|
let before;
|
|
28811
29111
|
try {
|
|
28812
29112
|
before = await client.getIssue(issueKey);
|
|
@@ -28817,6 +29117,7 @@ async function issueUpdateCommand(context) {
|
|
|
28817
29117
|
if (status === "done" && typeof before.closed_at === "string") {
|
|
28818
29118
|
throw refusalWithCode(new DispatchServiceError("ISSUE_CLOSED", 409, "issue is closed"), `${issueKey} closed at ${before.closed_at}, so the reason was not posted and the close was not sent`);
|
|
28819
29119
|
}
|
|
29120
|
+
const issuesBefore = options.length === 0 ? undefined : await issuesBeforeStatusChange(client, before, options);
|
|
28820
29121
|
let closingNote;
|
|
28821
29122
|
if (reason !== undefined) {
|
|
28822
29123
|
try {
|
|
@@ -28835,6 +29136,9 @@ async function issueUpdateCommand(context) {
|
|
|
28835
29136
|
throw withAccount(error, told);
|
|
28836
29137
|
}
|
|
28837
29138
|
}
|
|
29139
|
+
if (issuesBefore !== undefined) {
|
|
29140
|
+
return statusChangeCommand(context, before, options, issuesBefore, closingNote);
|
|
29141
|
+
}
|
|
28838
29142
|
const existingLinks = before.external_links ?? [];
|
|
28839
29143
|
const linked = existingLinks.map((link) => link.url);
|
|
28840
29144
|
const newLinks = requestedLinks?.filter((url) => !linked.includes(url)) ?? [];
|
|
@@ -28873,9 +29177,7 @@ async function issueUpdateCommand(context) {
|
|
|
28873
29177
|
}
|
|
28874
29178
|
throw refusalWithCode(error, taken);
|
|
28875
29179
|
}
|
|
28876
|
-
const
|
|
28877
|
-
const fix = error instanceof DispatchGatewayError && error.transient ? "" : "fix what refused the close, then ";
|
|
28878
|
-
const landed = writeMayHaveLanded(error) ? `${posted}, and the close may or may not have taken effect. Read the issue's status before retrying: done means it closed; otherwise retry with a reason that points at message ${closingNote.id}, since retrying this call posts its reason again` : `${posted} but the issue did not close. Retrying this call posts its reason again, so ${fix}retry with a reason that points at message ${closingNote.id}`;
|
|
29180
|
+
const landed = closeAccount(error, closingNote);
|
|
28879
29181
|
if (error instanceof DispatchServiceError)
|
|
28880
29182
|
throw refusalWithCode(error, taken, landed);
|
|
28881
29183
|
throw withAccount(error, [taken, landed].filter((clause) => clause !== "").join("; "));
|
|
@@ -28997,8 +29299,11 @@ async function relatedCommand(context) {
|
|
|
28997
29299
|
details: { project, suggestions }
|
|
28998
29300
|
};
|
|
28999
29301
|
}
|
|
29302
|
+
function printsJson(tool, args) {
|
|
29303
|
+
return tool === "dispatch_issues" && args["json"] === true;
|
|
29304
|
+
}
|
|
29000
29305
|
async function issuesCommand(context) {
|
|
29001
|
-
const { args, client } = context;
|
|
29306
|
+
const { args, client, input } = context;
|
|
29002
29307
|
const project = stringArg(args, "project");
|
|
29003
29308
|
const status = optionalString(args, "status");
|
|
29004
29309
|
const parent = optionalString(args, "parent");
|
|
@@ -29041,6 +29346,10 @@ async function issuesCommand(context) {
|
|
|
29041
29346
|
updated_at: row.updated_at,
|
|
29042
29347
|
progress: row.progress
|
|
29043
29348
|
}));
|
|
29349
|
+
const listing = { issues: rows, total, offset, limit };
|
|
29350
|
+
if (printsJson(input.tool, args)) {
|
|
29351
|
+
return { text: JSON.stringify(listing), details: listing };
|
|
29352
|
+
}
|
|
29044
29353
|
const agents = await liveAgents(client, rows.some((row) => holdsSession(row.claim)));
|
|
29045
29354
|
const isPartial = offset !== 0 || rows.length !== total;
|
|
29046
29355
|
const showing = !isPartial ? "" : rows.length === 0 ? `showing 0-0 of ${total}` : pageSummaryText(offset, rows.length, total);
|
|
@@ -29053,7 +29362,7 @@ async function issuesCommand(context) {
|
|
|
29053
29362
|
})
|
|
29054
29363
|
].join(`
|
|
29055
29364
|
`),
|
|
29056
|
-
details:
|
|
29365
|
+
details: listing
|
|
29057
29366
|
};
|
|
29058
29367
|
}
|
|
29059
29368
|
function dryRunAsksDispatch(tool, args) {
|
|
@@ -31765,13 +32074,29 @@ async function whoamiCommand(context) {
|
|
|
31765
32074
|
const service = identity.kind === "agent" ? identity.service ?? null : null;
|
|
31766
32075
|
const proved = identity.kind === "agent" ? identity.session ?? null : null;
|
|
31767
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;
|
|
31768
32079
|
const session = proved ?? sessionId;
|
|
31769
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.";
|
|
31770
32081
|
const answered = identity.kind === "agent" ? identity.sign_in_required : undefined;
|
|
31771
32082
|
const signInNeeded = answered ?? (owner === null && service !== null && proved !== null);
|
|
31772
|
-
const
|
|
31773
|
-
const
|
|
31774
|
-
|
|
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.` : "";
|
|
31775
32100
|
return {
|
|
31776
32101
|
text: acting + elsewhere + writable,
|
|
31777
32102
|
details: { session, owner, service, project }
|
|
@@ -32440,6 +32765,11 @@ async function importDpopKey(pkcs8Pem, name) {
|
|
|
32440
32765
|
// ../cipher-client/src/device-login.ts
|
|
32441
32766
|
var BROKER_SETTING = "AGENT_SECRETS_URL";
|
|
32442
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
|
+
}
|
|
32443
32773
|
var BROKER_REQUEST_MS = TRADE_ATTEMPT_MS / 2;
|
|
32444
32774
|
var DEFAULT_POLL_SECONDS = 5;
|
|
32445
32775
|
var LEAST_POLL_SECONDS = 1;
|
|
@@ -32515,7 +32845,8 @@ function loginOf(key, broker, answered, now) {
|
|
|
32515
32845
|
expiresAt,
|
|
32516
32846
|
broker,
|
|
32517
32847
|
accessToken: holdSecret(answered.access_token, accessExpiresAt),
|
|
32518
|
-
accessExpiresAt
|
|
32848
|
+
accessExpiresAt,
|
|
32849
|
+
accessLifeSeconds: seconds
|
|
32519
32850
|
};
|
|
32520
32851
|
}
|
|
32521
32852
|
async function startDeviceLogin(options) {
|
|
@@ -32647,7 +32978,7 @@ class DeviceLoginIdentity {
|
|
|
32647
32978
|
}
|
|
32648
32979
|
return this.#key;
|
|
32649
32980
|
}
|
|
32650
|
-
async spend(trade, signal) {
|
|
32981
|
+
async spend(trade, signal, leastLifeMs) {
|
|
32651
32982
|
const { thumbprint } = await this.#loaded();
|
|
32652
32983
|
return await withDeviceLoginLock(this.#path, async (held) => {
|
|
32653
32984
|
let login = await readDeviceLogin(this.#path);
|
|
@@ -32659,7 +32990,8 @@ class DeviceLoginIdentity {
|
|
|
32659
32990
|
}
|
|
32660
32991
|
const refresh = () => refreshDeviceLogin(this.#path, login, { describe: this.describe(), held });
|
|
32661
32992
|
const expires = login.accessExpiresAt?.getTime() ?? 0;
|
|
32662
|
-
|
|
32993
|
+
const least = leastAccessLifeMs(leastLifeMs, login.accessLifeSeconds);
|
|
32994
|
+
let refreshed = login.accessToken === "" || expires - Date.now() < least;
|
|
32663
32995
|
if (refreshed)
|
|
32664
32996
|
login = await refresh();
|
|
32665
32997
|
while (true) {
|
|
@@ -33107,13 +33439,15 @@ function tradeProjects(env) {
|
|
|
33107
33439
|
}
|
|
33108
33440
|
return sorted;
|
|
33109
33441
|
}
|
|
33110
|
-
async function brokerTokenClient(env, own = "") {
|
|
33442
|
+
async function brokerTokenClient(env, own = "", read) {
|
|
33111
33443
|
const brokerUrl = value(env, BROKER_URL_VAR);
|
|
33112
33444
|
const machine = machineIdentity(env);
|
|
33113
33445
|
if (brokerUrl === "" || machine === undefined)
|
|
33114
33446
|
return;
|
|
33115
33447
|
if (!isHttpUrl(brokerUrl))
|
|
33116
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() };
|
|
33117
33451
|
if (machine instanceof DeviceLoginIdentity) {
|
|
33118
33452
|
if (personTradeOff(env)) {
|
|
33119
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`);
|
|
@@ -33123,7 +33457,8 @@ async function brokerTokenClient(env, own = "") {
|
|
|
33123
33457
|
key: await machine.key(),
|
|
33124
33458
|
subject: machine,
|
|
33125
33459
|
session: tradeSession(env, own) || deviceLoginSessionName(await machine.thumbprint()),
|
|
33126
|
-
projects: tradeProjects(env)
|
|
33460
|
+
projects: tradeProjects(env),
|
|
33461
|
+
...await heldApart()
|
|
33127
33462
|
});
|
|
33128
33463
|
return { client, signIn: undefined };
|
|
33129
33464
|
}
|
|
@@ -33134,7 +33469,8 @@ async function brokerTokenClient(env, own = "") {
|
|
|
33134
33469
|
key: await newDpopKey(),
|
|
33135
33470
|
subject: machine,
|
|
33136
33471
|
session: tradeSession(env, own),
|
|
33137
|
-
launcherCredential: false
|
|
33472
|
+
launcherCredential: false,
|
|
33473
|
+
...narrowed
|
|
33138
33474
|
});
|
|
33139
33475
|
return { client, signIn: undefined };
|
|
33140
33476
|
}
|
|
@@ -33148,7 +33484,8 @@ async function brokerTokenClient(env, own = "") {
|
|
|
33148
33484
|
subject: personIdentity(record, flow),
|
|
33149
33485
|
actor: machine,
|
|
33150
33486
|
session: own.trim() || signInSessionName(record),
|
|
33151
|
-
projects: tradeProjects(env)
|
|
33487
|
+
projects: tradeProjects(env),
|
|
33488
|
+
...await heldApart()
|
|
33152
33489
|
});
|
|
33153
33490
|
return { client, signIn: { person: record.person, thumbprint: record.thumbprint } };
|
|
33154
33491
|
}
|
|
@@ -33181,11 +33518,11 @@ function forgetBrokerSession(session) {
|
|
|
33181
33518
|
function signInName(record) {
|
|
33182
33519
|
return `${record.person}\x00${record.thumbprint}`;
|
|
33183
33520
|
}
|
|
33184
|
-
function keyOf(env, own) {
|
|
33185
|
-
|
|
33186
|
-
|
|
33187
|
-
|
|
33188
|
-
};
|
|
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) };
|
|
33189
33526
|
}
|
|
33190
33527
|
function entryFor(key) {
|
|
33191
33528
|
let sessions = CLIENTS.get(key.session);
|
|
@@ -33200,13 +33537,13 @@ function entryFor(key) {
|
|
|
33200
33537
|
}
|
|
33201
33538
|
return entry;
|
|
33202
33539
|
}
|
|
33203
|
-
async function make(env, own) {
|
|
33204
|
-
const made = await brokerTokenClient(env, own);
|
|
33540
|
+
async function make(env, own, read) {
|
|
33541
|
+
const made = await brokerTokenClient(env, own, read);
|
|
33205
33542
|
const signIn = made?.signIn;
|
|
33206
33543
|
return { client: made?.client, signIn: signIn === undefined ? "" : signInName(signIn) };
|
|
33207
33544
|
}
|
|
33208
|
-
async function clientFor(env, own) {
|
|
33209
|
-
const key = keyOf(env, own);
|
|
33545
|
+
async function clientFor(env, own, read) {
|
|
33546
|
+
const key = keyOf(env, own, read);
|
|
33210
33547
|
const entry = entryFor(key);
|
|
33211
33548
|
if (entry.refused.size > 0) {
|
|
33212
33549
|
const record = await chooseSignIn(env);
|
|
@@ -33221,7 +33558,7 @@ async function clientFor(env, own) {
|
|
|
33221
33558
|
}
|
|
33222
33559
|
let making = entry.making;
|
|
33223
33560
|
if (making === undefined) {
|
|
33224
|
-
const started = make(env, key.session);
|
|
33561
|
+
const started = make(env, key.session, read);
|
|
33225
33562
|
making = started;
|
|
33226
33563
|
entry.making = started;
|
|
33227
33564
|
started.then((made) => {
|
|
@@ -33251,13 +33588,13 @@ function untilAborted(promise, signal) {
|
|
|
33251
33588
|
});
|
|
33252
33589
|
});
|
|
33253
33590
|
}
|
|
33254
|
-
async function tradedToken(env, own, signal, waitForReady = false) {
|
|
33255
|
-
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);
|
|
33256
33593
|
const { client } = made;
|
|
33257
33594
|
if (client === undefined) {
|
|
33258
33595
|
throw new LoggableError("AGENT_SECRETS_URL and AGENT_SECRETS_MACHINE_IDENTITY no longer name a broker and an identity to trade");
|
|
33259
33596
|
}
|
|
33260
|
-
const { session, variables } = keyOf(env, own);
|
|
33597
|
+
const { session, variables } = keyOf(env, own, read);
|
|
33261
33598
|
try {
|
|
33262
33599
|
return {
|
|
33263
33600
|
token: await client.token(signal, { waitForReady }),
|
|
@@ -33272,7 +33609,7 @@ async function tradedToken(env, own, signal, waitForReady = false) {
|
|
|
33272
33609
|
}
|
|
33273
33610
|
}
|
|
33274
33611
|
function brokerTokenFor(env, session) {
|
|
33275
|
-
return (signal, waitForReady) => tradedToken(env, sessionName(session), signal, waitForReady);
|
|
33612
|
+
return (signal, waitForReady) => tradedToken(env, sessionName(session), { signal, waitForReady });
|
|
33276
33613
|
}
|
|
33277
33614
|
function dropHeld(key, token) {
|
|
33278
33615
|
CLIENTS.get(key.session)?.get(key.variables)?.made?.client?.drop(token);
|
|
@@ -33280,14 +33617,14 @@ function dropHeld(key, token) {
|
|
|
33280
33617
|
function dropTradedToken(env, traded) {
|
|
33281
33618
|
dropHeld(keyOf(env, traded.session), traded.token.accessToken);
|
|
33282
33619
|
}
|
|
33283
|
-
function brokerCredential(env, session) {
|
|
33620
|
+
function brokerCredential(env, session, read) {
|
|
33284
33621
|
let presented = "";
|
|
33285
33622
|
const presentedAs = new WeakMap;
|
|
33286
33623
|
const own = (acting) => (acting ?? "").trim() || sessionName(session);
|
|
33287
33624
|
return {
|
|
33288
33625
|
scheme: "DPoP",
|
|
33289
33626
|
async headers(method, url, acting, signal) {
|
|
33290
|
-
const traded = await tradedToken(env, own(acting), signal);
|
|
33627
|
+
const traded = await tradedToken(env, own(acting), { signal, read });
|
|
33291
33628
|
const { token, key, identity } = traded;
|
|
33292
33629
|
presented = token.accessToken;
|
|
33293
33630
|
const headers = {
|
|
@@ -33296,7 +33633,7 @@ function brokerCredential(env, session) {
|
|
|
33296
33633
|
};
|
|
33297
33634
|
presentedAs.set(headers, {
|
|
33298
33635
|
identity,
|
|
33299
|
-
key: keyOf(env, traded.session),
|
|
33636
|
+
key: keyOf(env, traded.session, read),
|
|
33300
33637
|
token: token.accessToken
|
|
33301
33638
|
});
|
|
33302
33639
|
return headers;
|
|
@@ -33304,12 +33641,65 @@ function brokerCredential(env, session) {
|
|
|
33304
33641
|
identity: (headers) => presentedAs.get(headers)?.identity,
|
|
33305
33642
|
stale(acting, headers) {
|
|
33306
33643
|
const told = headers === undefined ? undefined : presentedAs.get(headers);
|
|
33307
|
-
dropHeld(told?.key ?? keyOf(env, own(acting)), told?.token);
|
|
33644
|
+
dropHeld(told?.key ?? keyOf(env, own(acting), read), told?.token);
|
|
33308
33645
|
},
|
|
33309
33646
|
secret: () => presented
|
|
33310
33647
|
};
|
|
33311
33648
|
}
|
|
33312
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
|
+
|
|
33313
33703
|
// ../envoy-client/src/dispatch-config.ts
|
|
33314
33704
|
var DEFAULT_SERVER_URL = "http://localhost:8766";
|
|
33315
33705
|
function checkoutPair(checkout, serverUrl) {
|
|
@@ -33354,13 +33744,19 @@ function lostDispatchUrlNotice(env, config) {
|
|
|
33354
33744
|
].join("; ");
|
|
33355
33745
|
}
|
|
33356
33746
|
function dispatchSettings(env, config, options = {}) {
|
|
33357
|
-
const target = dispatchTarget(env, config);
|
|
33747
|
+
const target = dispatchTarget(env, config, options.tokenFiles === true);
|
|
33358
33748
|
if (!target.enabled)
|
|
33359
33749
|
return target;
|
|
33360
33750
|
const { url, urlSetting, source } = target;
|
|
33361
33751
|
let credential;
|
|
33362
33752
|
try {
|
|
33363
|
-
|
|
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
|
+
}
|
|
33364
33760
|
} catch (error) {
|
|
33365
33761
|
return offWithError(messageFor(error));
|
|
33366
33762
|
}
|
|
@@ -33383,6 +33779,63 @@ function dispatchUrl(env, config) {
|
|
|
33383
33779
|
const target = dispatchTarget(env, config);
|
|
33384
33780
|
return target.enabled ? target.url : undefined;
|
|
33385
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
|
+
}
|
|
33386
33839
|
function brokerRouteForced(env) {
|
|
33387
33840
|
const written = (env.DISPATCH_TOKEN_BROKER ?? "").trim();
|
|
33388
33841
|
if (written === "")
|
|
@@ -33391,12 +33844,55 @@ function brokerRouteForced(env) {
|
|
|
33391
33844
|
return true;
|
|
33392
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");
|
|
33393
33846
|
}
|
|
33394
|
-
|
|
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) {
|
|
33395
33884
|
if (config.kind === "failed")
|
|
33396
33885
|
return offWithError(config.error);
|
|
33397
|
-
const
|
|
33398
|
-
if (
|
|
33399
|
-
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;
|
|
33400
33896
|
const explicitUrl = nonEmpty(env.DISPATCH_URL);
|
|
33401
33897
|
const checkoutFile = explicitUrl === undefined ? config.checkout : null;
|
|
33402
33898
|
if (checkoutFile?.kind === "invalid")
|
|
@@ -33438,10 +33934,10 @@ function dispatchTarget(env, config) {
|
|
|
33438
33934
|
if (route.traded) {
|
|
33439
33935
|
const brokered = withoutTrailingSlashes(explicitUrl ?? own.serverUrl ?? DEFAULT_SERVER_URL);
|
|
33440
33936
|
const urlSetting = explicitUrl !== undefined ? "DISPATCH_URL" : own.serverUrl !== undefined ? `dispatch.serverUrl in ${config.path}` : DEFAULT_URL_SETTING;
|
|
33441
|
-
return { enabled: true, url: brokered, urlSetting, source: { kind: "broker" } };
|
|
33937
|
+
return { enabled: true, url: brokered, urlSetting, source: { kind: "broker", read } };
|
|
33442
33938
|
}
|
|
33443
33939
|
if (forced) {
|
|
33444
|
-
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`);
|
|
33445
33941
|
}
|
|
33446
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}`);
|
|
33447
33943
|
}
|
|
@@ -33627,7 +34123,6 @@ function brokerNatsCredential(env, session, source = NATS_AUTH_VAR, tradeDeadlin
|
|
|
33627
34123
|
admissions: () => admissions
|
|
33628
34124
|
};
|
|
33629
34125
|
}
|
|
33630
|
-
var RENEW_FLOOR_MS = 1000;
|
|
33631
34126
|
var RETRY_FIRST_MS = 2000;
|
|
33632
34127
|
var RETRY_LAST_MS = 60000;
|
|
33633
34128
|
var WARN_AGAIN_MS = 30 * 60000;
|
|
@@ -33684,11 +34179,7 @@ function warnedEvery(warn) {
|
|
|
33684
34179
|
};
|
|
33685
34180
|
}
|
|
33686
34181
|
function renewDelay(expiry, now) {
|
|
33687
|
-
|
|
33688
|
-
if (remaining <= 0)
|
|
33689
|
-
return 0;
|
|
33690
|
-
const ahead = remaining - Math.min(DEFAULT_RENEW_BEFORE_MS, remaining / 2);
|
|
33691
|
-
return Math.max(Math.min(RENEW_FLOOR_MS, remaining / 2), ahead);
|
|
34182
|
+
return renewalAt(expiry, now, DEFAULT_RENEW_BEFORE_MS) - now;
|
|
33692
34183
|
}
|
|
33693
34184
|
function keepNatsCredential(connection, credential, warn) {
|
|
33694
34185
|
let stopped = false;
|
|
@@ -34127,7 +34618,8 @@ function sessionDispatchSettings(file, env, options) {
|
|
|
34127
34618
|
return {
|
|
34128
34619
|
dispatch: dispatchSettings(env, config, {
|
|
34129
34620
|
commands: options.commands,
|
|
34130
|
-
session: options.session
|
|
34621
|
+
session: options.session,
|
|
34622
|
+
tokenFiles: options.tokenFiles
|
|
34131
34623
|
}),
|
|
34132
34624
|
warnings: config.kind === "read" ? config.warnings : [],
|
|
34133
34625
|
missing: config.kind === "read" ? config.missing : null
|
|
@@ -34337,7 +34829,7 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
34337
34829
|
|
|
34338
34830
|
// src/codex/codex-session-record.ts
|
|
34339
34831
|
import { spawnSync } from "child_process";
|
|
34340
|
-
import { readFileSync as
|
|
34832
|
+
import { readFileSync as readFileSync7, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
|
|
34341
34833
|
import { mkdir as mkdir4, readFile as readFile5, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
34342
34834
|
import { homedir as homedir3 } from "os";
|
|
34343
34835
|
import { basename as basename4, dirname as dirname5, join as join10 } from "path";
|
|
@@ -34347,7 +34839,7 @@ import { readFile as readFile4 } from "fs/promises";
|
|
|
34347
34839
|
import { basename as basename3, join as join9 } from "path";
|
|
34348
34840
|
|
|
34349
34841
|
// src/session-state.ts
|
|
34350
|
-
import { readFileSync as
|
|
34842
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
34351
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";
|
|
34352
34844
|
import { dirname as dirname4, join as join8 } from "path";
|
|
34353
34845
|
async function writeAtomicStateFile(file, contents) {
|
|
@@ -34393,7 +34885,7 @@ async function removeChosenTitle(file) {
|
|
|
34393
34885
|
}
|
|
34394
34886
|
function readChosenTitleSync(file) {
|
|
34395
34887
|
try {
|
|
34396
|
-
return
|
|
34888
|
+
return readFileSync6(file, "utf8");
|
|
34397
34889
|
} catch {
|
|
34398
34890
|
return;
|
|
34399
34891
|
}
|
|
@@ -34586,14 +35078,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
34586
35078
|
}
|
|
34587
35079
|
function procComm(pid) {
|
|
34588
35080
|
try {
|
|
34589
|
-
return
|
|
35081
|
+
return readFileSync7(`/proc/${pid}/comm`, "utf8").trim();
|
|
34590
35082
|
} catch {
|
|
34591
35083
|
return;
|
|
34592
35084
|
}
|
|
34593
35085
|
}
|
|
34594
35086
|
function procParent(pid) {
|
|
34595
35087
|
try {
|
|
34596
|
-
const stat =
|
|
35088
|
+
const stat = readFileSync7(`/proc/${pid}/stat`, "utf8");
|
|
34597
35089
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
34598
35090
|
return Number.isInteger(parent) ? parent : undefined;
|
|
34599
35091
|
} catch {
|
|
@@ -34607,7 +35099,7 @@ var PS_OPTIONS = {
|
|
|
34607
35099
|
};
|
|
34608
35100
|
function procStarted(pid) {
|
|
34609
35101
|
try {
|
|
34610
|
-
const stat =
|
|
35102
|
+
const stat = readFileSync7(`/proc/${pid}/stat`, "utf8");
|
|
34611
35103
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
34612
35104
|
} catch {
|
|
34613
35105
|
return;
|
|
@@ -34628,7 +35120,7 @@ function recordOfProcess(record, pid) {
|
|
|
34628
35120
|
function sharedAppServer(pid) {
|
|
34629
35121
|
let argv;
|
|
34630
35122
|
try {
|
|
34631
|
-
argv =
|
|
35123
|
+
argv = readFileSync7(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
34632
35124
|
} catch {
|
|
34633
35125
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
34634
35126
|
if (ps.status !== 0)
|
|
@@ -34781,7 +35273,7 @@ function singleQuoted(value) {
|
|
|
34781
35273
|
}
|
|
34782
35274
|
function envFileText(envFile) {
|
|
34783
35275
|
try {
|
|
34784
|
-
return
|
|
35276
|
+
return readFileSync8(envFile, "utf8");
|
|
34785
35277
|
} catch (error) {
|
|
34786
35278
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
34787
35279
|
throw error;
|
|
@@ -34907,7 +35399,7 @@ function refreshLockHeld(lock) {
|
|
|
34907
35399
|
let text;
|
|
34908
35400
|
try {
|
|
34909
35401
|
age = Date.now() - statSync2(lock).mtimeMs;
|
|
34910
|
-
text =
|
|
35402
|
+
text = readFileSync8(lock, "utf8");
|
|
34911
35403
|
} catch (error) {
|
|
34912
35404
|
if (hasErrnoCode(error, "ENOENT"))
|
|
34913
35405
|
return false;
|
|
@@ -34943,7 +35435,7 @@ function takeRefreshLock(lock) {
|
|
|
34943
35435
|
function refreshOutcome(file, since) {
|
|
34944
35436
|
let value;
|
|
34945
35437
|
try {
|
|
34946
|
-
value = JSON.parse(
|
|
35438
|
+
value = JSON.parse(readFileSync8(file, "utf8"));
|
|
34947
35439
|
} catch {
|
|
34948
35440
|
return;
|
|
34949
35441
|
}
|