@sjawhar/claude-envoy 6.5.0 → 6.6.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/README.md +6 -3
- package/dist/codex-hook.js +337 -126
- package/dist/dispatch.js +804 -156
- package/dist/envoy-channel.js +341 -130
- package/dist/session-hook.js +337 -126
- package/dist/session-title-hook.js +0 -3
- package/package.json +1 -1
- package/src/codex/codex-server.ts +1 -1
package/dist/codex-hook.js
CHANGED
|
@@ -14323,21 +14323,22 @@ var ISSUE_UPDATE_OPTIONS_RULE = "include_children, unlink_children and include_p
|
|
|
14323
14323
|
var ISSUE_UPDATE_RULE = `${ISSUE_UPDATE_FIELDS_RULE} ${ISSUE_UPDATE_DONE_RULE}; ${ISSUE_UPDATE_REASON_RULE}; ${ISSUE_UPDATE_LABELS_RULE}. ${ISSUE_UPDATE_OPTIONS_RULE}`;
|
|
14324
14324
|
function issueStatusOptionsProblem(input) {
|
|
14325
14325
|
const options = issueStatusOptionsOf(input);
|
|
14326
|
+
const optionInput = input;
|
|
14326
14327
|
if (options.length === 0)
|
|
14327
14328
|
return;
|
|
14328
14329
|
const named = options.join(", ").replace(/, ([^,]*)$/, " and $1");
|
|
14329
14330
|
const others = ISSUE_UPDATE_PATCH_FIELDS.filter((field) => input[field] !== undefined);
|
|
14330
14331
|
return brokenParts([
|
|
14331
14332
|
[
|
|
14332
|
-
!(
|
|
14333
|
+
!(optionInput.include_children === true && optionInput.unlink_children === true),
|
|
14333
14334
|
"include_children does not go with unlink_children. The open children move with the issue or leave it, so name one of the two."
|
|
14334
14335
|
],
|
|
14335
14336
|
[
|
|
14336
|
-
!(
|
|
14337
|
+
!(optionInput.include_children === true && optionInput.status === "done"),
|
|
14337
14338
|
"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."
|
|
14338
14339
|
],
|
|
14339
14340
|
[
|
|
14340
|
-
typeof
|
|
14341
|
+
typeof optionInput.status === "string",
|
|
14341
14342
|
`status is required with ${named}. Add status, or drop ${named}.`
|
|
14342
14343
|
],
|
|
14343
14344
|
[
|
|
@@ -14490,8 +14491,8 @@ var RESULT_SHAPE_RULE = `${RESULT_RETRACT_RULE} A call with retract takes reason
|
|
|
14490
14491
|
function resultProblem(value) {
|
|
14491
14492
|
const input = value;
|
|
14492
14493
|
const carried = RESULT_RECORD_FIELDS.filter((field) => input[field] !== undefined);
|
|
14493
|
-
if (typeof input
|
|
14494
|
-
const reason = input
|
|
14494
|
+
if (typeof input.retract === "string") {
|
|
14495
|
+
const reason = input.reason;
|
|
14495
14496
|
if (typeof reason !== "string" || reason.trim() === "") {
|
|
14496
14497
|
return "retract needs reason, the words that say why the result is wrong.";
|
|
14497
14498
|
}
|
|
@@ -14500,7 +14501,7 @@ function resultProblem(value) {
|
|
|
14500
14501
|
}
|
|
14501
14502
|
return;
|
|
14502
14503
|
}
|
|
14503
|
-
if (input
|
|
14504
|
+
if (input.reason !== undefined) {
|
|
14504
14505
|
return "reason goes with retract, and this call carries no retract. Name the result to retract, or drop reason.";
|
|
14505
14506
|
}
|
|
14506
14507
|
const missing = RESULT_REQUIRED_FIELDS.filter((field) => input[field] === undefined);
|
|
@@ -15111,7 +15112,7 @@ var dispatchToolSpecs = [
|
|
|
15111
15112
|
{
|
|
15112
15113
|
name: "dispatch_project_update",
|
|
15113
15114
|
example: { project: "CORE", proven_sessions: "on" },
|
|
15114
|
-
description: "Turn a project's proven-sessions setting on or off. With it on, an architect's write of an " + "issue's spec or Verification document passes only on a credential that proves the " + "architect's session. A role-holder publication then passes only on a credential that " + "proves legion-daemon:<project
|
|
15115
|
+
description: "Turn a project's proven-sessions setting on or off. With it on, an architect's write of an " + "issue's spec or Verification document passes only on a credential that proves the " + "architect's session. A role-holder publication then passes only on a credential that " + "proves legion-daemon:<project>, or legion-daemon:<P> of another project's daemon on a " + "broker token that names P. on sends PUT /api/v1/projects/{key}/proven-sessions, which " + "any credential that may write the project's issues may send. off sends DELETE on the same " + "path, which needs the person scope: a credential without it is refused with 403 " + "OAUTH_SCOPE_REQUIRED, and the shared token and a pod's token hold none. A token scoped to " + "another project turns the setting on, as the shared token does, and off only with the " + "person scope. A token scoped to one project gets 403 PROJECT_SCOPE for a project that " + "does not exist and for a private project that it does not name. Only the project's " + "roll-out issue turns it on, once the project's daemon and pods write with their own " + "tokens. Turned on before that, it stops every architect write and every role-holder " + "publication on the shared token, until a person turns it off. The answer names the " + "project and the setting as Dispatch stored it.",
|
|
15115
15116
|
arguments: (z) => ({
|
|
15116
15117
|
project: z.string().describe("Project key whose setting to change, such as CORE."),
|
|
15117
15118
|
proven_sessions: z.enum(["on", "off"]).describe("on turns the setting on; off turns it off and needs the person scope.")
|
|
@@ -15164,7 +15165,7 @@ var dispatchToolSpecs = [
|
|
|
15164
15165
|
{
|
|
15165
15166
|
name: "dispatch_whoami",
|
|
15166
15167
|
example: {},
|
|
15167
|
-
description: "Who Dispatch takes this session for: {session, owner, service, project, project_scope}. session is the session Dispatch records your writes as. It is the session your credential proved, and the tool says so when that is not the session you run in. owner is the lowercase email of the person you act for, and is the first choice of assignee for issues you create. owner is null under the shared token and under a broker token that names a service and no person. With a null owner, a create with no assignee falls back to the parent's assignee, when the parent is in the issue's own project, and then to the project's default assignee, which every project names, so every issue you create has an assignee. A question on an issue reaches the person it was handed to, else the issue's assignee, else the project's default assignee. service is the subject of the verified service-account token that authenticated you, or the service a broker token naming no person names: a job's identity as its job entry lists it, the Kubernetes account an exchange entry lists, or the fleet of a machine nobody has signed in on; else null. project_scope is a broker token's project scope, and null for every other credential. A job's broker token has the project scope named or public, holds no OAuth scope and writes as its service: a route that needs an OAuth scope refuses it with 403 OAUTH_SCOPE_REQUIRED before Dispatch's project check runs. named
|
|
15168
|
+
description: "Who Dispatch takes this session for: {session, owner, service, project, project_scope}. session is the session Dispatch records your writes as. It is the session your credential proved, and the tool says so when that is not the session you run in. owner is the lowercase email of the person you act for, and is the first choice of assignee for issues you create. owner is null under the shared token and under a broker token that names a service and no person. With a null owner, a create with no assignee falls back to the parent's assignee, when the parent is in the issue's own project, and then to the project's default assignee, which every project names, so every issue you create has an assignee. A question on an issue reaches the person it was handed to, else the issue's assignee, else the project's default assignee. service is the subject of the verified service-account token that authenticated you, or the service a broker token naming no person names: a job's identity as its job entry lists it, the Kubernetes account an exchange entry lists, or the fleet of a machine nobody has signed in on; else null. project_scope is a broker token's project scope, and null for every other credential. A job's broker token has the project scope named or public, holds no OAuth scope and writes as its service: a route that needs an OAuth scope refuses it with 403 OAUTH_SCOPE_REQUIRED before Dispatch's project check runs. named names one project, and that check judges its writes as it judges a person's named token's for the same project: it refuses a write that belongs to the deployment, such as a project create, with 403 PROJECT_SCOPE_DEPLOYMENT. public names no one project, so it may write wherever a token that names no project may. An exchange entry's broker token that names its account has the project scope named and no project, and writes as that account wherever a token that names no project may. A machine's broker token that names a service has the project scope person; it may read and is refused every write with SIGN_IN_REQUIRED, which names the command a person signs in on that machine with. project is the project your credential's token names, or null when it names none. A token that names a project also writes other projects' objects, as a credential that names none does. The one exception is a private project that the token does not name.",
|
|
15168
15169
|
arguments: () => ({}),
|
|
15169
15170
|
strict: true
|
|
15170
15171
|
},
|
|
@@ -15178,7 +15179,7 @@ var dispatchToolSpecs = [
|
|
|
15178
15179
|
{
|
|
15179
15180
|
name: "dispatch_api",
|
|
15180
15181
|
example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
|
|
15181
|
-
description: "Send one request of a route of Dispatch's HTTP API under /api/v1, with this session's own credential, and print the answer's body: Dispatch's JSON, indented, for jq to read; any other body of a 2xx, such as a file version's bytes or a document version's Markdown, as it came. It sends a GET of path unless method names another: path is a route beginning /api/v1, with its query after ?; dispatch api --path /api/v1 lists every route. With method it sends POST, PUT, PATCH or DELETE instead, and body, when given, as the request's JSON body (Content-Type: application/json), read from a file with --body-file <file> or from stdin with --body-file -; a body goes only with a method. A write that a named dispatch command makes goes through that command (dispatch --help lists them): dispatch api is for a route no command sends. In a session whose AskGate reviews Dispatch writes it sends GET alone, and refuses each method, naming the dispatch command that makes that write, and exits 1. It sends the request once, and once more only after Dispatch answers that the token it presented is not live (Dispatch then authenticated nothing, so nothing ran), with no redirect followed and no Idempotency-Key. On a 2xx answer it exits 0 and prints Dispatch's JSON as above, and any other body unchanged, with nothing added: an answer with Content-Disposition: attachment (a file version, a ?download=true read) is stored content, printed byte for byte whatever its type, JSON included. A 2xx whose body holds a credential the command presented (its token or its request's DPoP proof) is not printed: it exits 1 with CREDENTIAL_ECHOED, naming the status and saying a write may have been made. Any other answer exits 1 with its code: when Dispatch refuses the request, the command prints Dispatch's error with its code and, where Dispatch gives one, its hint; an answer that is neither a 2xx nor Dispatch's JSON, such as a proxy's page, is named by its status. A usage error, such as a path outside /api/v1 or a body with no method, exits 2. Where no host runs the command, as in a GitHub Actions job, it reads Dispatch from the environment alone, and a broker trade names the session of DISPATCH_SESSION_ID, else of AGENT_SECRETS_SESSION. Under Claude Code, a JSON answer longer than the output limit is written to a file the output names; a body printed as it came is written whole.",
|
|
15182
|
+
description: "Send one request of a route of Dispatch's HTTP API under /api/v1, with this session's own credential, and print the answer's body: Dispatch's JSON, indented, for jq to read; any other body of a 2xx, such as a file version's bytes or a document version's Markdown, as it came. It sends a GET of path unless method names another: path is a route beginning /api/v1, with its query after ?; dispatch api --path /api/v1 lists every route. With method it sends POST, PUT, PATCH or DELETE instead, and body, when given, as the request's JSON body (Content-Type: application/json), read from a file with --body-file <file> or from stdin with --body-file -; a body goes only with a method. A write that a named dispatch command makes goes through that command (dispatch --help lists them), or, for an issue comment POST that carries an Idempotency-Key, through dispatch proxy: dispatch api is for a route no command sends. In a session whose AskGate reviews Dispatch writes it sends GET alone, and refuses each method, naming the dispatch command that makes that write, and exits 1. It sends the request once, and once more only after Dispatch answers that the token it presented is not live (Dispatch then authenticated nothing, so nothing ran), with no redirect followed and no Idempotency-Key. On a 2xx answer it exits 0 and prints Dispatch's JSON as above, and any other body unchanged, with nothing added: an answer with Content-Disposition: attachment (a file version, a ?download=true read) is stored content, printed byte for byte whatever its type, JSON included. A 2xx whose body holds a credential the command presented (its token or its request's DPoP proof) is not printed: it exits 1 with CREDENTIAL_ECHOED, naming the status and saying a write may have been made. Any other answer exits 1 with its code: when Dispatch refuses the request, the command prints Dispatch's error with its code and, where Dispatch gives one, its hint; an answer that is neither a 2xx nor Dispatch's JSON, such as a proxy's page, is named by its status. A usage error, such as a path outside /api/v1 or a body with no method, exits 2. Where no host runs the command, as in a GitHub Actions job, it reads Dispatch from the environment alone, and a broker trade names the session of DISPATCH_SESSION_ID, else of AGENT_SECRETS_SESSION. Under Claude Code, a JSON answer longer than the output limit is written to a file the output names; a body printed as it came is written whole.",
|
|
15182
15183
|
arguments: (z) => ({
|
|
15183
15184
|
path: z.string({ min: 1 }).describe('The route, beginning /api/v1, with its query after ?, such as /api/v1/issues/ACME-12/events?limit=200. No scheme or host, no . or .. segment, and no ", <, >, ^, `, { or } before the query: percent-encode them.'),
|
|
15184
15185
|
method: z.enum(DISPATCH_API_METHODS).describe("The method sent in place of GET: POST, PUT, PATCH or DELETE. Omit it to send a GET.").optional(),
|
|
@@ -15969,6 +15970,52 @@ var DispatchTargetedDeliverySchema = union([
|
|
|
15969
15970
|
DispatchTargetedCommentDeliverySchema,
|
|
15970
15971
|
DispatchTargetedMessageDeliverySchema
|
|
15971
15972
|
]);
|
|
15973
|
+
function isCommentTargetedDelivery(delivery) {
|
|
15974
|
+
return "comment_id" in delivery;
|
|
15975
|
+
}
|
|
15976
|
+
var DispatchTargetedFrameSchema = object({
|
|
15977
|
+
event: DispatchEventSchema,
|
|
15978
|
+
delivery: DispatchTargetedDeliverySchema
|
|
15979
|
+
}).superRefine(({ event, delivery }, context) => {
|
|
15980
|
+
if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
|
|
15981
|
+
return;
|
|
15982
|
+
}
|
|
15983
|
+
if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
|
|
15984
|
+
return;
|
|
15985
|
+
}
|
|
15986
|
+
context.addIssue({
|
|
15987
|
+
code: "custom",
|
|
15988
|
+
message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
|
|
15989
|
+
});
|
|
15990
|
+
});
|
|
15991
|
+
var RecoverableDispatchDeliveryFailureSchema = object({
|
|
15992
|
+
event: object({
|
|
15993
|
+
type: _enum2(["message.created", "comment.created"]),
|
|
15994
|
+
issue_key: string2().nullable(),
|
|
15995
|
+
payload: object({ id: string2(), body: string2().optional() }).passthrough()
|
|
15996
|
+
}).passthrough(),
|
|
15997
|
+
delivery: DispatchTargetedDeliverySchema
|
|
15998
|
+
}).refine(({ event, delivery }) => event.type === "comment.created" ? isCommentTargetedDelivery(delivery) : !isCommentTargetedDelivery(delivery) && DispatchTargetedResourceIDSchema.safeParse(event.payload.id).success, { message: "delivery resource must match its event type" });
|
|
15999
|
+
function readDispatchPayload(value) {
|
|
16000
|
+
if (typeof value === "object" && value !== null && "delivery" in value) {
|
|
16001
|
+
const targeted = DispatchTargetedFrameSchema.safeParse(value);
|
|
16002
|
+
if (targeted.success) {
|
|
16003
|
+
const { event: wireEvent } = value;
|
|
16004
|
+
return {
|
|
16005
|
+
kind: "event",
|
|
16006
|
+
event: targeted.data.event,
|
|
16007
|
+
wireEvent,
|
|
16008
|
+
delivery: targeted.data.delivery
|
|
16009
|
+
};
|
|
16010
|
+
}
|
|
16011
|
+
const recovered = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
|
|
16012
|
+
if (recovered.success)
|
|
16013
|
+
return { kind: "recovered", failure: recovered.data };
|
|
16014
|
+
return { kind: "raw", targeted: true };
|
|
16015
|
+
}
|
|
16016
|
+
const parsed = DispatchEventSchema.safeParse(value);
|
|
16017
|
+
return parsed.success ? { kind: "event", event: parsed.data, wireEvent: value } : { kind: "raw", targeted: false };
|
|
16018
|
+
}
|
|
15972
16019
|
// ../contracts/src/dispatch-api-user.ts
|
|
15973
16020
|
var UserIssueStateSchema = strictObject({
|
|
15974
16021
|
pinned: boolean2(),
|
|
@@ -19315,6 +19362,181 @@ function fileTextBytes(text) {
|
|
|
19315
19362
|
return encoder2.encode(text);
|
|
19316
19363
|
}
|
|
19317
19364
|
|
|
19365
|
+
// ../envoy-client/src/dispatch-login-command.ts
|
|
19366
|
+
var LOGIN_COMMAND = "login";
|
|
19367
|
+
var LOGIN_SENTENCE = "Logs this machine in at the secrets broker, once per machine, for a machine with no identity of its own, such as a laptop.";
|
|
19368
|
+
function loginHelp() {
|
|
19369
|
+
return [
|
|
19370
|
+
"Usage: dispatch login --device [--person <address>]",
|
|
19371
|
+
"",
|
|
19372
|
+
`${LOGIN_SENTENCE} It prints a code and the page to type it into; the person the login names approves it there, signed in to Dispatch. The login is then kept in the file AGENT_SECRETS_DEVICE_LOGIN_FILE names (default ~/.config/legion/device-login.json), mode 0600, and every session that sets AGENT_SECRETS_MACHINE_IDENTITY=device-login trades it for its broker token.`,
|
|
19373
|
+
"",
|
|
19374
|
+
"Flags:",
|
|
19375
|
+
" --device",
|
|
19376
|
+
" Log in with the broker's device grant: the only way there is, and required.",
|
|
19377
|
+
" --person <address>",
|
|
19378
|
+
" The person who approves the login, by the address they sign in to Dispatch with; else AGENT_SECRETS_PERSON.",
|
|
19379
|
+
"",
|
|
19380
|
+
"It reads AGENT_SECRETS_URL, the broker, and needs no Dispatch host or session.",
|
|
19381
|
+
"",
|
|
19382
|
+
"It exits 0 once the login is kept; 1 when the broker could not be reached or refused it, the person denied it, its code expired, or the login could not be kept; and 2 on a usage error, before any request.",
|
|
19383
|
+
"",
|
|
19384
|
+
"Example: dispatch login --device --person ada@example.com",
|
|
19385
|
+
""
|
|
19386
|
+
].join(`
|
|
19387
|
+
`);
|
|
19388
|
+
}
|
|
19389
|
+
|
|
19390
|
+
// ../envoy-client/src/dispatch-proxy-command.ts
|
|
19391
|
+
import { resolve } from "path";
|
|
19392
|
+
var PROXY_COMMAND = "proxy";
|
|
19393
|
+
var PROXY_SENTENCE = "Runs a command with a proxy on a unix socket that sends the command's Dispatch reads, and its comment POSTs that carry an Idempotency-Key, with this session's broker token.";
|
|
19394
|
+
var SOCKET_PATH_MAX_BYTES = 107;
|
|
19395
|
+
function proxyExitLine(requests, trades, renewed) {
|
|
19396
|
+
return `dispatch proxy: ${requests} requests, ${trades} trades, ${renewed} after BROKER_TOKEN_NOT_ACTIVE`;
|
|
19397
|
+
}
|
|
19398
|
+
function proxyHelp() {
|
|
19399
|
+
return [
|
|
19400
|
+
"Usage: dispatch proxy --socket <path> [--dry-run] -- <command> [<argument>...]",
|
|
19401
|
+
"",
|
|
19402
|
+
PROXY_SENTENCE,
|
|
19403
|
+
"",
|
|
19404
|
+
"The proxy listens on a unix socket at <path> for the whole run of <command>. It sends each",
|
|
19405
|
+
"request it takes to the Dispatch server and the session that a dispatch command resolves in",
|
|
19406
|
+
"the same environment, with this session's broker token and a new DPoP proof. So the tool",
|
|
19407
|
+
"holds no credential and signs nothing. It adds the path of each request to the path of the",
|
|
19408
|
+
"Dispatch URL, and it does not decode the query. The proxy trades for the token once before it",
|
|
19409
|
+
"starts the command, and again only when the token has less than 5 minutes to live, or after",
|
|
19410
|
+
"Dispatch answers 401 BROKER_TOKEN_NOT_ACTIVE. It runs only under DISPATCH_TOKEN_BROKER=1.",
|
|
19411
|
+
"",
|
|
19412
|
+
"What it sends:",
|
|
19413
|
+
" GET /api/... any GET whose path starts with /api/",
|
|
19414
|
+
" POST /api/v1/issues/<key>/comments a comment that carries an Idempotency-Key header",
|
|
19415
|
+
"It sends no other write. A tool reads much and writes little. Where a dispatch command sends a",
|
|
19416
|
+
"write, the write goes through that command, so AskGate reviews it wherever AskGate gates that",
|
|
19417
|
+
"command. The proxy's refusal of the write names that command. Where no other dispatch command",
|
|
19418
|
+
"sends a write under /api/v1, the refusal names dispatch api --method, which sends it outside a",
|
|
19419
|
+
"session whose AskGate reviews Dispatch writes. The comment needs a key so that a resend posts",
|
|
19420
|
+
"it once. The comment POST passes no AskGate review. The proxy is not one of the writes that",
|
|
19421
|
+
"AskGate gates, and the Dispatch server checks no marker. A session that holds a Dispatch token",
|
|
19422
|
+
"can post the same comment with that token already.",
|
|
19423
|
+
"",
|
|
19424
|
+
"It listens on a unix socket only, made with mode 0600, and opens no TCP port. The roles of a",
|
|
19425
|
+
"pod share the pod's network, so a port would let another role act as this one. A socket path",
|
|
19426
|
+
"that exists is refused, so give it a path in a new directory (mktemp -d). A socket that a",
|
|
19427
|
+
"killed proxy left behind refuses the next start.",
|
|
19428
|
+
"",
|
|
19429
|
+
"How a tool calls it: the command runs with DISPATCH_PROXY_SOCKET set to the socket's path.",
|
|
19430
|
+
"The host in a URL is not read. Write the path and the query.",
|
|
19431
|
+
' curl --unix-socket "$DISPATCH_PROXY_SOCKET" http://dispatch/api/v1/issues',
|
|
19432
|
+
" In Python, an http.client.HTTPConnection whose connect opens an AF_UNIX socket:",
|
|
19433
|
+
" import http.client, os, socket",
|
|
19434
|
+
" class ProxyConnection(http.client.HTTPConnection):",
|
|
19435
|
+
" def connect(self):",
|
|
19436
|
+
" self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)",
|
|
19437
|
+
' self.sock.connect(os.environ["DISPATCH_PROXY_SOCKET"])',
|
|
19438
|
+
' connection = ProxyConnection("dispatch")',
|
|
19439
|
+
' connection.request("GET", "/api/v1/issues?project=DSP")',
|
|
19440
|
+
" answer = connection.getresponse()",
|
|
19441
|
+
" print(answer.status, answer.read())",
|
|
19442
|
+
"",
|
|
19443
|
+
"What it answers: Dispatch's status, headers and body as Dispatch sent them. An answer that",
|
|
19444
|
+
"carries Transfer-Encoding as well as Content-Length is the one exception: it comes back",
|
|
19445
|
+
"without that Content-Length (RFC 9112, section 6.3), with its body chunked. It follows no",
|
|
19446
|
+
"redirect. Its own refusals have a JSON body with a code and an error, and each code starts",
|
|
19447
|
+
"with PROXY_. No code of Dispatch's does. It never answers 403 or 404 of its own.",
|
|
19448
|
+
" 400 PROXY_TARGET_REFUSED a target that names a host (http://... or //...)",
|
|
19449
|
+
" 405 PROXY_METHOD_REFUSED each other method or path, and a comment POST with no",
|
|
19450
|
+
" Idempotency-Key. The error names the dispatch command to",
|
|
19451
|
+
" use, where one exists. For a write under /api/v1 that no",
|
|
19452
|
+
" other dispatch command sends, it names dispatch api",
|
|
19453
|
+
" --method. It also refuses a target that holds a # or a",
|
|
19454
|
+
" control character, and a path with a . or .. segment",
|
|
19455
|
+
" (plain or percent-encoded), a backslash, or %2F or %5C in",
|
|
19456
|
+
" either case: each can reach another route than the one the",
|
|
19457
|
+
" target names.",
|
|
19458
|
+
" 502 PROXY_TRADE_REFUSED the token has ended and the broker refused a new one. The",
|
|
19459
|
+
" error is in the broker's words.",
|
|
19460
|
+
" 502 PROXY_DISPATCH_UNREACHABLE Dispatch did not answer",
|
|
19461
|
+
"",
|
|
19462
|
+
"Flags:",
|
|
19463
|
+
" --socket <path>",
|
|
19464
|
+
" The socket to listen on. Also --socket=<path>. A path over 107 bytes is refused.",
|
|
19465
|
+
" --dry-run",
|
|
19466
|
+
" Checks the arguments and the environment, prints the Dispatch server, the session and",
|
|
19467
|
+
" the socket it would use, and starts nothing.",
|
|
19468
|
+
" --help",
|
|
19469
|
+
" Prints this help.",
|
|
19470
|
+
"Every word after -- is the command's, flags included.",
|
|
19471
|
+
"",
|
|
19472
|
+
"It exits with the command's status. A command that a signal ended is 128 plus the signal's",
|
|
19473
|
+
"number. A command that does not exist is 127, and one that cannot run is 126. It exits 2 when",
|
|
19474
|
+
"it cannot start, and runs no command then. It sends SIGTERM, SIGINT and SIGHUP on to the",
|
|
19475
|
+
"command and serves until the command ends. Then it removes its socket. The last line it",
|
|
19476
|
+
"writes on standard error is:",
|
|
19477
|
+
" dispatch proxy: <n> requests, <m> trades, <r> after BROKER_TOKEN_NOT_ACTIVE",
|
|
19478
|
+
"Here n counts the requests sent to Dispatch, m the trades that gave a token, and r those of",
|
|
19479
|
+
"them that followed a BROKER_TOKEN_NOT_ACTIVE answer.",
|
|
19480
|
+
"",
|
|
19481
|
+
'Example: dispatch proxy --socket "$(mktemp -d)/d.sock" -- python3 work-cost.py',
|
|
19482
|
+
""
|
|
19483
|
+
].join(`
|
|
19484
|
+
`);
|
|
19485
|
+
}
|
|
19486
|
+
function parseProxyArgv(rest, cwd) {
|
|
19487
|
+
const separator = rest.indexOf("--");
|
|
19488
|
+
const own = separator === -1 ? rest : rest.slice(0, separator);
|
|
19489
|
+
if (own.includes("--help"))
|
|
19490
|
+
return { kind: "help" };
|
|
19491
|
+
let socket;
|
|
19492
|
+
let dryRun = false;
|
|
19493
|
+
for (let at = 0;at < own.length; at += 1) {
|
|
19494
|
+
const word = own[at] ?? "";
|
|
19495
|
+
if (word === "--dry-run") {
|
|
19496
|
+
dryRun = true;
|
|
19497
|
+
continue;
|
|
19498
|
+
}
|
|
19499
|
+
if (word !== "--socket" && !word.startsWith("--socket=")) {
|
|
19500
|
+
return {
|
|
19501
|
+
kind: "refused",
|
|
19502
|
+
problem: separator === -1 ? `${JSON.stringify(word)} is no flag of dispatch proxy, and the command goes after --.` : `${JSON.stringify(word)} is no flag of dispatch proxy.`
|
|
19503
|
+
};
|
|
19504
|
+
}
|
|
19505
|
+
if (socket !== undefined)
|
|
19506
|
+
return { kind: "refused", problem: "--socket is given twice." };
|
|
19507
|
+
let value;
|
|
19508
|
+
if (word === "--socket") {
|
|
19509
|
+
at += 1;
|
|
19510
|
+
value = own[at];
|
|
19511
|
+
} else {
|
|
19512
|
+
value = word.slice("--socket=".length);
|
|
19513
|
+
}
|
|
19514
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
19515
|
+
return { kind: "refused", problem: "--socket takes the path of the socket to listen on." };
|
|
19516
|
+
}
|
|
19517
|
+
socket = value;
|
|
19518
|
+
}
|
|
19519
|
+
if (socket === undefined) {
|
|
19520
|
+
return { kind: "refused", problem: "--socket <path> is missing." };
|
|
19521
|
+
}
|
|
19522
|
+
const command = separator === -1 ? [] : rest.slice(separator + 1);
|
|
19523
|
+
if (command.length === 0) {
|
|
19524
|
+
return {
|
|
19525
|
+
kind: "refused",
|
|
19526
|
+
problem: "No command is given: write it after --, as -- <command> [<argument>...]."
|
|
19527
|
+
};
|
|
19528
|
+
}
|
|
19529
|
+
const path = resolve(cwd, socket);
|
|
19530
|
+
const bytes = Buffer.byteLength(path);
|
|
19531
|
+
if (bytes > SOCKET_PATH_MAX_BYTES) {
|
|
19532
|
+
return {
|
|
19533
|
+
kind: "refused",
|
|
19534
|
+
problem: `The socket path ${JSON.stringify(path)} is ${bytes} bytes, over the ${SOCKET_PATH_MAX_BYTES} a unix socket path holds. Give a shorter path, such as one in a new directory of mktemp -d.`
|
|
19535
|
+
};
|
|
19536
|
+
}
|
|
19537
|
+
return { kind: "run", socket: path, dryRun, command };
|
|
19538
|
+
}
|
|
19539
|
+
|
|
19318
19540
|
// ../contracts/src/held-secrets.ts
|
|
19319
19541
|
var WITHHELD = "<withheld>";
|
|
19320
19542
|
var SCRUB_RUN = 10;
|
|
@@ -19545,9 +19767,6 @@ function reachedNothing(error) {
|
|
|
19545
19767
|
}
|
|
19546
19768
|
|
|
19547
19769
|
class LoggableError extends Error {
|
|
19548
|
-
constructor(message) {
|
|
19549
|
-
super(message);
|
|
19550
|
-
}
|
|
19551
19770
|
}
|
|
19552
19771
|
var SERVER_REFUSALS = [
|
|
19553
19772
|
"Authorization Violation",
|
|
@@ -19582,6 +19801,10 @@ function natsFailureReason(error) {
|
|
|
19582
19801
|
}
|
|
19583
19802
|
|
|
19584
19803
|
// ../envoy-client/src/dispatch-command.ts
|
|
19804
|
+
var COMMANDS_OUTSIDE_THE_SPECS = [
|
|
19805
|
+
{ name: PROXY_COMMAND, sentence: PROXY_SENTENCE, help: proxyHelp },
|
|
19806
|
+
{ name: LOGIN_COMMAND, sentence: LOGIN_SENTENCE, help: loginHelp }
|
|
19807
|
+
];
|
|
19585
19808
|
var PREFIXED_FLAGS = [
|
|
19586
19809
|
{
|
|
19587
19810
|
tool: "dispatch_comment",
|
|
@@ -19853,7 +20076,10 @@ function parseCommand(argv, io) {
|
|
|
19853
20076
|
return { kind: "help" };
|
|
19854
20077
|
const tool = toolForCommand(command);
|
|
19855
20078
|
if (tool === undefined) {
|
|
19856
|
-
const commands = [
|
|
20079
|
+
const commands = [
|
|
20080
|
+
...toolsByCommand.keys(),
|
|
20081
|
+
...COMMANDS_OUTSIDE_THE_SPECS.map(({ name }) => name)
|
|
20082
|
+
].join(", ");
|
|
19857
20083
|
return {
|
|
19858
20084
|
kind: "refused",
|
|
19859
20085
|
problems: [`unknown command ${quoteWord(command)}; the commands are: ${commands}`]
|
|
@@ -20130,17 +20356,21 @@ function commandHelp(tool) {
|
|
|
20130
20356
|
`);
|
|
20131
20357
|
}
|
|
20132
20358
|
function commandsHelp() {
|
|
20133
|
-
const
|
|
20359
|
+
const rows = [
|
|
20360
|
+
...dispatchToolSpecs.map((spec) => ({
|
|
20361
|
+
name: commandName(spec.name),
|
|
20362
|
+
sentence: /^.*?[.!?](?=\s|$)/s.exec(spec.description)?.[0] ?? spec.description
|
|
20363
|
+
})),
|
|
20364
|
+
...COMMANDS_OUTSIDE_THE_SPECS
|
|
20365
|
+
];
|
|
20366
|
+
const width = Math.max(...rows.map(({ name }) => name.length));
|
|
20134
20367
|
return [
|
|
20135
20368
|
"Usage: dispatch <command> [flags]",
|
|
20136
|
-
...
|
|
20137
|
-
const sentence = /^.*?[.!?](?=\s|$)/s.exec(spec.description)?.[0] ?? spec.description;
|
|
20138
|
-
return ` ${commandName(spec.name).padEnd(width)} ${sentence}`;
|
|
20139
|
-
}),
|
|
20369
|
+
...rows.map(({ name, sentence }) => ` ${name.padEnd(width)} ${sentence}`),
|
|
20140
20370
|
"",
|
|
20141
|
-
"Run dispatch <command> --help for its flags and an example. --dry-run checks
|
|
20371
|
+
"Run dispatch <command> --help for its flags and an example. Every command but dispatch login takes --dry-run, which checks its arguments as the call would and prints them as given. It stores nothing. A command whose dry run asks Dispatch something past that check (dispatch artifact: how Dispatch would store its text; dispatch result: the pull-request body line the record would print) says so in its --help. dispatch proxy's dry run also checks its environment and prints the Dispatch server, the session and the socket it would use, and starts nothing.",
|
|
20142
20372
|
"",
|
|
20143
|
-
"dispatch login --device
|
|
20373
|
+
"dispatch login --device is no Dispatch call: it needs no host or session.",
|
|
20144
20374
|
""
|
|
20145
20375
|
].join(`
|
|
20146
20376
|
`);
|
|
@@ -26569,7 +26799,7 @@ function parseFrameJSON(text) {
|
|
|
26569
26799
|
const containers = typeof value === "object" && value !== null ? [value] : [];
|
|
26570
26800
|
for (let next = containers.pop();next !== undefined; next = containers.pop()) {
|
|
26571
26801
|
const members = next;
|
|
26572
|
-
|
|
26802
|
+
Reflect.deleteProperty(members, "__proto__");
|
|
26573
26803
|
let names = Object.keys(members);
|
|
26574
26804
|
if (names.some((name) => name.search(LONE_SURROGATE) !== -1)) {
|
|
26575
26805
|
const held = names.map((name) => members[name]);
|
|
@@ -26801,32 +27031,6 @@ function createDeliveryDedupe(now = Date.now) {
|
|
|
26801
27031
|
}
|
|
26802
27032
|
};
|
|
26803
27033
|
}
|
|
26804
|
-
function isCommentTargetedDelivery(delivery) {
|
|
26805
|
-
return "comment_id" in delivery;
|
|
26806
|
-
}
|
|
26807
|
-
var DispatchTargetedFrameSchema = object({
|
|
26808
|
-
event: DispatchEventSchema,
|
|
26809
|
-
delivery: DispatchTargetedDeliverySchema
|
|
26810
|
-
}).superRefine(({ event, delivery }, context) => {
|
|
26811
|
-
if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
|
|
26812
|
-
return;
|
|
26813
|
-
}
|
|
26814
|
-
if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
|
|
26815
|
-
return;
|
|
26816
|
-
}
|
|
26817
|
-
context.addIssue({
|
|
26818
|
-
code: "custom",
|
|
26819
|
-
message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
|
|
26820
|
-
});
|
|
26821
|
-
});
|
|
26822
|
-
var RecoverableDispatchDeliveryFailureSchema = object({
|
|
26823
|
-
event: object({
|
|
26824
|
-
type: _enum2(["message.created", "comment.created"]),
|
|
26825
|
-
issue_key: string2().nullable(),
|
|
26826
|
-
payload: object({ id: string2(), body: string2().optional() }).passthrough()
|
|
26827
|
-
}).passthrough(),
|
|
26828
|
-
delivery: DispatchTargetedDeliverySchema
|
|
26829
|
-
}).refine(({ event, delivery }) => event.type === "comment.created" ? isCommentTargetedDelivery(delivery) : !isCommentTargetedDelivery(delivery) && DispatchTargetedResourceIDSchema.safeParse(event.payload.id).success, { message: "delivery resource must match its event type" });
|
|
26830
27034
|
function eventPictures(event) {
|
|
26831
27035
|
let text;
|
|
26832
27036
|
if (event.type.startsWith("message.")) {
|
|
@@ -26858,16 +27062,22 @@ function carriedItem(event) {
|
|
|
26858
27062
|
const resource = event.type.startsWith("comment.") || event.type.startsWith("suggestion.") ? "comment" : event.type.startsWith("message.") ? "message" : undefined;
|
|
26859
27063
|
if (resource === undefined || !isObject3(event.payload))
|
|
26860
27064
|
return;
|
|
26861
|
-
const id = event.payload
|
|
27065
|
+
const { id } = event.payload;
|
|
26862
27066
|
if (typeof id !== "string" || id === "")
|
|
26863
27067
|
return;
|
|
26864
27068
|
return { resource, id, issueKey: event.issue_key };
|
|
26865
27069
|
}
|
|
26866
27070
|
function payloadWasOmitted(payload) {
|
|
26867
|
-
|
|
27071
|
+
if (!isObject3(payload))
|
|
27072
|
+
return false;
|
|
27073
|
+
const { payload_omitted } = payload;
|
|
27074
|
+
return payload_omitted === true;
|
|
26868
27075
|
}
|
|
26869
27076
|
function bodyWasCut(payload) {
|
|
26870
|
-
|
|
27077
|
+
if (!isObject3(payload))
|
|
27078
|
+
return false;
|
|
27079
|
+
const { body_truncated } = payload;
|
|
27080
|
+
return body_truncated === true || payloadWasOmitted(payload);
|
|
26871
27081
|
}
|
|
26872
27082
|
function wholeItemRoute(item) {
|
|
26873
27083
|
return `GET /api/v1/${item.resource === "comment" ? "comments" : "messages"}/${item.id}`;
|
|
@@ -27112,7 +27322,10 @@ var DISPATCH_BOOKKEEPING = new Set([
|
|
|
27112
27322
|
]);
|
|
27113
27323
|
function dispatchPayloadForReader(event, sessionID, issuedAt, toReader) {
|
|
27114
27324
|
const whole = dispatchPayload(event);
|
|
27115
|
-
|
|
27325
|
+
let changedField;
|
|
27326
|
+
if (event.type !== "issue.created" && isObject3(whole))
|
|
27327
|
+
({ changed: changedField } = whole);
|
|
27328
|
+
const changed = Array.isArray(changedField) ? changedField : [];
|
|
27116
27329
|
const payload = withoutEmptyFields(whole, (key, item) => changed.includes(key) || (key === "suggestion" || key === "forced") && item !== null && item !== undefined);
|
|
27117
27330
|
if (!isObject3(payload) || Array.isArray(payload))
|
|
27118
27331
|
return payload;
|
|
@@ -27227,27 +27440,25 @@ function parseDispatchFrame(rawPayload, wholeBody) {
|
|
|
27227
27440
|
try {
|
|
27228
27441
|
value = parseFrameJSON(rawPayload);
|
|
27229
27442
|
} catch {
|
|
27230
|
-
return {
|
|
27443
|
+
return {};
|
|
27231
27444
|
}
|
|
27232
|
-
|
|
27233
|
-
|
|
27234
|
-
|
|
27235
|
-
const
|
|
27445
|
+
const reading = readDispatchPayload(value);
|
|
27446
|
+
switch (reading.kind) {
|
|
27447
|
+
case "event": {
|
|
27448
|
+
const { notify, quiet } = reading.wireEvent;
|
|
27236
27449
|
return {
|
|
27237
|
-
event: withWholeBody(
|
|
27238
|
-
notify
|
|
27239
|
-
quiet
|
|
27240
|
-
delivery:
|
|
27450
|
+
event: withWholeBody(reading.event, wholeBody),
|
|
27451
|
+
notify,
|
|
27452
|
+
quiet,
|
|
27453
|
+
delivery: reading.delivery
|
|
27241
27454
|
};
|
|
27242
27455
|
}
|
|
27243
|
-
|
|
27244
|
-
|
|
27245
|
-
const delivery = recoverable.data.delivery;
|
|
27456
|
+
case "recovered": {
|
|
27457
|
+
const { delivery, event } = reading.failure;
|
|
27246
27458
|
const commentDelivery = isCommentTargetedDelivery(delivery);
|
|
27247
27459
|
const resource = commentDelivery ? "comment" : "message";
|
|
27248
|
-
const id = commentDelivery ? delivery.comment_id :
|
|
27460
|
+
const id = commentDelivery ? delivery.comment_id : event.payload.id;
|
|
27249
27461
|
return {
|
|
27250
|
-
raw: value,
|
|
27251
27462
|
rejectedDelivery: {
|
|
27252
27463
|
resource,
|
|
27253
27464
|
id,
|
|
@@ -27255,24 +27466,15 @@ function parseDispatchFrame(rawPayload, wholeBody) {
|
|
|
27255
27466
|
mode: delivery.mode,
|
|
27256
27467
|
replyPath: dispatchReplyPath(resource, id),
|
|
27257
27468
|
replyFields: commentDelivery ? { target: delivery.target } : {},
|
|
27258
|
-
issueKey:
|
|
27259
|
-
body:
|
|
27469
|
+
issueKey: event.issue_key,
|
|
27470
|
+
body: event.payload.body ?? ""
|
|
27260
27471
|
},
|
|
27261
27472
|
malformedDelivery: true
|
|
27262
27473
|
};
|
|
27263
27474
|
}
|
|
27264
|
-
|
|
27475
|
+
case "raw":
|
|
27476
|
+
return reading.targeted ? { malformedDelivery: true } : {};
|
|
27265
27477
|
}
|
|
27266
|
-
const parsed = DispatchEventSchema.safeParse(value);
|
|
27267
|
-
if (!parsed.success)
|
|
27268
|
-
return { raw: value };
|
|
27269
|
-
const wireEvent = value;
|
|
27270
|
-
return {
|
|
27271
|
-
event: withWholeBody(parsed.data, wholeBody),
|
|
27272
|
-
notify: wireEvent.notify,
|
|
27273
|
-
quiet: wireEvent.quiet,
|
|
27274
|
-
delivery: undefined
|
|
27275
|
-
};
|
|
27276
27478
|
}
|
|
27277
27479
|
var INBOUND_CARD_MAX_BYTES = 1 << 20;
|
|
27278
27480
|
function encodeWithin(value, maxBytes) {
|
|
@@ -27287,6 +27489,28 @@ function encodeWithin(value, maxBytes) {
|
|
|
27287
27489
|
return lines.join(`
|
|
27288
27490
|
`);
|
|
27289
27491
|
}
|
|
27492
|
+
function headerActor(actor) {
|
|
27493
|
+
const { kind, id, act, service } = actor;
|
|
27494
|
+
return {
|
|
27495
|
+
kind,
|
|
27496
|
+
...id === undefined ? {} : { id },
|
|
27497
|
+
...act === undefined ? {} : { act: ActorActSchema.safeParse(act).data ?? "not shown" },
|
|
27498
|
+
...kind !== "session" || service === undefined ? {} : { service: typeof service === "string" ? service : "not shown" }
|
|
27499
|
+
};
|
|
27500
|
+
}
|
|
27501
|
+
function dispatchCardAsText(rendered, event, reason, bound) {
|
|
27502
|
+
let text;
|
|
27503
|
+
try {
|
|
27504
|
+
text = JSON.stringify(event);
|
|
27505
|
+
} catch {}
|
|
27506
|
+
const asText = text === undefined ? undefined : encodeWithin({ envoy: { ...rendered, dispatch: text } }, bound);
|
|
27507
|
+
if (asText !== undefined)
|
|
27508
|
+
return asText;
|
|
27509
|
+
const notShown = `not shown: ${reason}`;
|
|
27510
|
+
const owner = event.owner === undefined ? {} : { owner: event.owner };
|
|
27511
|
+
const header = { type: event.type, actor: headerActor(event.actor), payload: notShown };
|
|
27512
|
+
return encodeWithin({ envoy: { ...rendered, dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: header } }, bound) ?? encode3({ envoy: { dispatch: { payload: notShown } } });
|
|
27513
|
+
}
|
|
27290
27514
|
function inboundTimestamp(milliseconds) {
|
|
27291
27515
|
if (milliseconds === undefined)
|
|
27292
27516
|
return "unknown";
|
|
@@ -27394,13 +27618,13 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27394
27618
|
dispatchReply = dispatchCommentReplyWith(frame.event, topic, commentPayload);
|
|
27395
27619
|
if (frame.event.type === "message.created") {
|
|
27396
27620
|
const message = DispatchTargetedMessagePayloadSchema.safeParse(frame.event.payload);
|
|
27397
|
-
const requested =
|
|
27398
|
-
if (message.success && requested
|
|
27621
|
+
const requested = frame.delivery;
|
|
27622
|
+
if (message.success && requested !== undefined && !isCommentTargetedDelivery(requested)) {
|
|
27399
27623
|
delivery = {
|
|
27400
27624
|
resource: "message",
|
|
27401
27625
|
id: message.data.id,
|
|
27402
|
-
attempt: requested.
|
|
27403
|
-
mode: requested.
|
|
27626
|
+
attempt: requested.attempt,
|
|
27627
|
+
mode: requested.mode,
|
|
27404
27628
|
replyPath: dispatchReplyPath("message", message.data.id),
|
|
27405
27629
|
replyFields: {},
|
|
27406
27630
|
issueKey: frame.event.issue_key,
|
|
@@ -27418,15 +27642,15 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27418
27642
|
}
|
|
27419
27643
|
} else if (frame.event.type === "comment.created") {
|
|
27420
27644
|
const comment = DispatchTargetedCommentPayloadSchema.safeParse(frame.event.payload);
|
|
27421
|
-
const requested =
|
|
27422
|
-
if (comment.success && requested
|
|
27645
|
+
const requested = frame.delivery;
|
|
27646
|
+
if (comment.success && requested !== undefined && isCommentTargetedDelivery(requested)) {
|
|
27423
27647
|
delivery = {
|
|
27424
27648
|
resource: "comment",
|
|
27425
|
-
id: requested.
|
|
27426
|
-
attempt: requested.
|
|
27427
|
-
mode: requested.
|
|
27428
|
-
replyPath: dispatchReplyPath("comment", requested.
|
|
27429
|
-
replyFields: { target: requested.
|
|
27649
|
+
id: requested.comment_id,
|
|
27650
|
+
attempt: requested.attempt,
|
|
27651
|
+
mode: requested.mode,
|
|
27652
|
+
replyPath: dispatchReplyPath("comment", requested.comment_id),
|
|
27653
|
+
replyFields: { target: requested.target },
|
|
27430
27654
|
issueKey: frame.event.issue_key,
|
|
27431
27655
|
body: comment.data.body,
|
|
27432
27656
|
...comment.data.body_truncated === true ? { bodyTruncated: true } : {}
|
|
@@ -27445,7 +27669,9 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27445
27669
|
let actor = frame.event.actor;
|
|
27446
27670
|
if ("origin" in frame.event.actor) {
|
|
27447
27671
|
const { origin, ...rest } = frame.event.actor;
|
|
27448
|
-
|
|
27672
|
+
let title;
|
|
27673
|
+
if (isObject3(origin))
|
|
27674
|
+
({ session_title: title } = origin);
|
|
27449
27675
|
actor = typeof title === "string" && title !== "" ? { ...rest, origin: { session_title: title } } : rest;
|
|
27450
27676
|
}
|
|
27451
27677
|
const owner = dispatchOwner(frame.event, topic);
|
|
@@ -27467,7 +27693,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27467
27693
|
trailer = humanEditDiffBlock(edit.data.diff, edit.data.diff_truncated);
|
|
27468
27694
|
}
|
|
27469
27695
|
} else {
|
|
27470
|
-
|
|
27696
|
+
dispatchIssue = "payload";
|
|
27471
27697
|
rejectedDelivery = frame.rejectedDelivery;
|
|
27472
27698
|
malformedDelivery = frame.malformedDelivery === true;
|
|
27473
27699
|
}
|
|
@@ -27522,7 +27748,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27522
27748
|
args: { topic: `notifications.role.${role}`, message: "..." }
|
|
27523
27749
|
}
|
|
27524
27750
|
},
|
|
27525
|
-
...dispatchRendered ? { dispatch: dispatchEvent } : {
|
|
27751
|
+
...dispatchRendered ? dispatchEvent === undefined ? {} : { dispatch: dispatchEvent } : {
|
|
27526
27752
|
...summaryIsHead ? {} : { summary: payloadSummary },
|
|
27527
27753
|
...message === undefined ? {} : { message }
|
|
27528
27754
|
},
|
|
@@ -27532,7 +27758,6 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27532
27758
|
},
|
|
27533
27759
|
...unrecognised === undefined ? {} : { unrecognised }
|
|
27534
27760
|
};
|
|
27535
|
-
const payloadKey = dispatchRendered ? "dispatch" : "message";
|
|
27536
27761
|
const payloadValue = dispatchRendered ? dispatchEvent : message;
|
|
27537
27762
|
const cardBound = Math.max(INBOUND_CARD_MAX_BYTES, 2 * (Buffer.byteLength(raw) + (wholeBody === undefined ? 0 : Buffer.byteLength(escapeString(wholeBody)))));
|
|
27538
27763
|
let card;
|
|
@@ -27546,7 +27771,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27546
27771
|
}
|
|
27547
27772
|
if (card === undefined) {
|
|
27548
27773
|
payloadShownAsText ??= `its layout is larger than the ${cardBound} bytes a card holds`;
|
|
27549
|
-
card = encode3({ envoy: { ...rendered,
|
|
27774
|
+
card = dispatchEvent === undefined ? encode3({ envoy: { ...rendered, message: envelope.payload } }) : dispatchCardAsText(rendered, dispatchEvent, payloadShownAsText, cardBound);
|
|
27550
27775
|
}
|
|
27551
27776
|
return {
|
|
27552
27777
|
skip: false,
|
|
@@ -28640,7 +28865,8 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
|
|
|
28640
28865
|
if (tool === "dispatch_read" && typeof args.message === "string") {
|
|
28641
28866
|
return { args, ref, owner: null };
|
|
28642
28867
|
}
|
|
28643
|
-
|
|
28868
|
+
const { retract } = args;
|
|
28869
|
+
if (tool === "dispatch_result" && typeof retract === "string") {
|
|
28644
28870
|
return { args, ref, owner: null };
|
|
28645
28871
|
}
|
|
28646
28872
|
const legionIssue = env.LEGION_ISSUE;
|
|
@@ -28716,7 +28942,7 @@ function refusalWithCode(error, ...clauses) {
|
|
|
28716
28942
|
const told = joined !== "" && /[.!?]$/.test(error.message) ? `${error.message} ${suffix.charAt(0).toUpperCase()}${suffix.slice(1)}` : `${error.message}${joined}`;
|
|
28717
28943
|
return new DispatchServiceError(error.code, error.status, `${error.code}: ${told}`, error);
|
|
28718
28944
|
}
|
|
28719
|
-
function parentStatusConflictLines(error, tool, args
|
|
28945
|
+
function parentStatusConflictLines(error, tool, args) {
|
|
28720
28946
|
if (!dispatchAnswered(error, 409) || error.code !== "PARENT_STATUS_CONFLICT")
|
|
28721
28947
|
return;
|
|
28722
28948
|
const issues = error.issues ?? [];
|
|
@@ -28727,28 +28953,15 @@ function parentStatusConflictLines(error, tool, args, legionIssue) {
|
|
|
28727
28953
|
return [
|
|
28728
28954
|
messageFor(error),
|
|
28729
28955
|
...issues.map((issue) => `${issue.key} [${issue.status}] ${issue.title}`),
|
|
28730
|
-
...nextSteps(tool, args, parents, children
|
|
28956
|
+
...nextSteps(tool, args, parents, children)
|
|
28731
28957
|
];
|
|
28732
28958
|
}
|
|
28733
28959
|
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.";
|
|
28734
28960
|
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.";
|
|
28735
|
-
function otherProjectSentence(named, keys) {
|
|
28736
|
-
const project = named === undefined ? undefined : issueProject(named);
|
|
28737
|
-
if (project === undefined)
|
|
28738
|
-
return "";
|
|
28739
|
-
const others = keys.filter((key) => {
|
|
28740
|
-
const other = issueProject(key);
|
|
28741
|
-
return other !== undefined && other !== project;
|
|
28742
|
-
});
|
|
28743
|
-
if (others.length === 0)
|
|
28744
|
-
return "";
|
|
28745
|
-
const one = others.length === 1;
|
|
28746
|
-
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.`;
|
|
28747
|
-
}
|
|
28748
28961
|
function includeParentCall(key) {
|
|
28749
28962
|
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`;
|
|
28750
28963
|
}
|
|
28751
|
-
function nextSteps(tool, args, parents, children
|
|
28964
|
+
function nextSteps(tool, args, parents, children) {
|
|
28752
28965
|
if (tool === "dispatch_issue") {
|
|
28753
28966
|
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.`);
|
|
28754
28967
|
}
|
|
@@ -28756,9 +28969,7 @@ function nextSteps(tool, args, parents, children, legionIssue) {
|
|
|
28756
28969
|
const written = issueUpdate ? args : {};
|
|
28757
28970
|
const fields = Object.keys(written).filter((field) => field !== "issue" && written[field] !== undefined);
|
|
28758
28971
|
const issue = optionalString(written, "issue");
|
|
28759
|
-
const named = issueUpdate ? issue ?? legionIssue : undefined;
|
|
28760
28972
|
const childHolds = children.length > 0;
|
|
28761
|
-
const childScope = otherProjectSentence(named, children);
|
|
28762
28973
|
const status = optionalString(written, "status");
|
|
28763
28974
|
const parent = optionalString(written, "parent");
|
|
28764
28975
|
const alone = `--status${status === "done" ? " and --reason" : ""} alone`;
|
|
@@ -28771,7 +28982,7 @@ function nextSteps(tool, args, parents, children, legionIssue) {
|
|
|
28771
28982
|
const afterStatus = childHolds ? ", after the status change," : "";
|
|
28772
28983
|
return [
|
|
28773
28984
|
...childHolds ? [
|
|
28774
|
-
`${CHILD_FLAGS} Each goes with ${alone}, so run the status change first, in a call of its own, and the reparent after it: ${reparent}
|
|
28985
|
+
`${CHILD_FLAGS} Each goes with ${alone}, so run the status change first, in a call of its own, and the reparent after it: ${reparent}.`
|
|
28775
28986
|
] : [],
|
|
28776
28987
|
...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}.`)
|
|
28777
28988
|
];
|
|
@@ -28779,8 +28990,8 @@ function nextSteps(tool, args, parents, children, legionIssue) {
|
|
|
28779
28990
|
const others = ISSUE_UPDATE_PATCH_FIELDS.some((field) => written[field] !== undefined);
|
|
28780
28991
|
const apart = (subject) => others ? ` ${subject} with ${alone}, so send the call's other changes in a call of their own.` : "";
|
|
28781
28992
|
return [
|
|
28782
|
-
...childHolds ? [`${CHILD_FLAGS}${apart("Each goes")}
|
|
28783
|
-
...parents.length > 0 ? [`${PARENT_FLAG}${apart("It goes")}
|
|
28993
|
+
...childHolds ? [`${CHILD_FLAGS}${apart("Each goes")}`] : [],
|
|
28994
|
+
...parents.length > 0 ? [`${PARENT_FLAG}${apart("It goes")}`] : []
|
|
28784
28995
|
];
|
|
28785
28996
|
}
|
|
28786
28997
|
function dispatchAnswered(error, status) {
|
|
@@ -30599,7 +30810,8 @@ async function relatedCommand(context) {
|
|
|
30599
30810
|
};
|
|
30600
30811
|
}
|
|
30601
30812
|
function printsJson(tool, args) {
|
|
30602
|
-
|
|
30813
|
+
const { json } = args;
|
|
30814
|
+
return tool === "dispatch_issues" && json === true;
|
|
30603
30815
|
}
|
|
30604
30816
|
async function issuesCommand(context) {
|
|
30605
30817
|
const { args, client, input } = context;
|
|
@@ -30665,7 +30877,8 @@ async function issuesCommand(context) {
|
|
|
30665
30877
|
};
|
|
30666
30878
|
}
|
|
30667
30879
|
function dryRunAsksDispatch(tool, args) {
|
|
30668
|
-
|
|
30880
|
+
const { retract } = args;
|
|
30881
|
+
return tool === "dispatch_result" && retract === undefined;
|
|
30669
30882
|
}
|
|
30670
30883
|
async function resultCommand(context) {
|
|
30671
30884
|
const { args, client, actor } = context;
|
|
@@ -30772,7 +30985,7 @@ import {
|
|
|
30772
30985
|
utimesSync,
|
|
30773
30986
|
writeFileSync
|
|
30774
30987
|
} from "fs";
|
|
30775
|
-
import { isAbsolute as isAbsolute2, join as join3, resolve as
|
|
30988
|
+
import { isAbsolute as isAbsolute2, join as join3, resolve as resolve3 } from "path";
|
|
30776
30989
|
var ASKGATE_RECORD = "askgate";
|
|
30777
30990
|
var MARKER_MAX_AGE_MS = 2 * 60 * 60000;
|
|
30778
30991
|
var STORE_BEAT_MS = 10 * 60000;
|
|
@@ -30830,7 +31043,7 @@ function fileOperands(argv) {
|
|
|
30830
31043
|
}
|
|
30831
31044
|
function operandPath(cwd, file) {
|
|
30832
31045
|
if (file.flag === "--path")
|
|
30833
|
-
return
|
|
31046
|
+
return resolve3(cwd, file.operand);
|
|
30834
31047
|
return isAbsolute2(file.operand) ? file.operand : `${cwd}/${file.operand}`;
|
|
30835
31048
|
}
|
|
30836
31049
|
function bytesDigest(bytes) {
|
|
@@ -31204,12 +31417,10 @@ var WRITE_ROUTES = [
|
|
|
31204
31417
|
commands: ["architecture-sync"]
|
|
31205
31418
|
}
|
|
31206
31419
|
];
|
|
31420
|
+
var WRITE_ROUTE_SEGMENTS = WRITE_ROUTES.map((row) => ({ row, segments: row.pattern.split("/") }));
|
|
31207
31421
|
function writeRoute(method, path) {
|
|
31208
31422
|
const segments = path.split("/");
|
|
31209
|
-
return
|
|
31210
|
-
const pattern = row.pattern.split("/");
|
|
31211
|
-
return row.method === method && pattern.length === segments.length && pattern.every((part, at) => part.startsWith("{") ? segments[at] !== "" : part === segments[at]);
|
|
31212
|
-
});
|
|
31423
|
+
return WRITE_ROUTE_SEGMENTS.find((route) => route.row.method === method && route.segments.length === segments.length && route.segments.every((part, at) => part.startsWith("{") ? segments[at] !== "" : part === segments[at]))?.row;
|
|
31213
31424
|
}
|
|
31214
31425
|
|
|
31215
31426
|
class ApiGateRefusal extends Error {
|
|
@@ -34073,9 +34284,9 @@ async function whoamiCommand(context) {
|
|
|
34073
34284
|
} else {
|
|
34074
34285
|
acting = `Session ${session} runs under the shared token: ${unowned}`;
|
|
34075
34286
|
}
|
|
34076
|
-
const
|
|
34287
|
+
const projectSentence = readOnly ? "" : project !== null ? ` Its token names project ${project}.` : writesAsService ? " It names no one project, so it may write wherever a token that names no project may." : "";
|
|
34077
34288
|
return {
|
|
34078
|
-
text: acting + elsewhere +
|
|
34289
|
+
text: acting + elsewhere + projectSentence,
|
|
34079
34290
|
details: { session, owner, service, project, project_scope: projectScope }
|
|
34080
34291
|
};
|
|
34081
34292
|
}
|