@sjawhar/claude-envoy 6.5.1 → 6.7.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 +216 -42
- package/dist/dispatch.js +683 -72
- package/dist/envoy-channel.js +220 -46
- package/dist/session-hook.js +216 -42
- package/package.json +1 -1
- package/src/codex/codex-server.ts +1 -1
package/dist/dispatch.js
CHANGED
|
@@ -980,7 +980,7 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// ../envoy-client/src/dispatch-cli.ts
|
|
983
|
-
import { closeSync as closeSync4, constants as
|
|
983
|
+
import { closeSync as closeSync4, constants as constants5, fstatSync as fstatSync3, openSync as openSync4, readFileSync as readFileSync7 } from "fs";
|
|
984
984
|
|
|
985
985
|
// ../envoy-client/src/askgate-marker.ts
|
|
986
986
|
import { createHash, randomBytes } from "crypto";
|
|
@@ -15712,7 +15712,7 @@ var dispatchToolSpecs = [
|
|
|
15712
15712
|
{
|
|
15713
15713
|
name: "dispatch_project_update",
|
|
15714
15714
|
example: { project: "CORE", proven_sessions: "on" },
|
|
15715
|
-
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
|
|
15715
|
+
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.",
|
|
15716
15716
|
arguments: (z) => ({
|
|
15717
15717
|
project: z.string().describe("Project key whose setting to change, such as CORE."),
|
|
15718
15718
|
proven_sessions: z.enum(["on", "off"]).describe("on turns the setting on; off turns it off and needs the person scope.")
|
|
@@ -15765,7 +15765,7 @@ var dispatchToolSpecs = [
|
|
|
15765
15765
|
{
|
|
15766
15766
|
name: "dispatch_whoami",
|
|
15767
15767
|
example: {},
|
|
15768
|
-
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
|
|
15768
|
+
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.",
|
|
15769
15769
|
arguments: () => ({}),
|
|
15770
15770
|
strict: true
|
|
15771
15771
|
},
|
|
@@ -15779,7 +15779,7 @@ var dispatchToolSpecs = [
|
|
|
15779
15779
|
{
|
|
15780
15780
|
name: "dispatch_api",
|
|
15781
15781
|
example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
|
|
15782
|
-
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.",
|
|
15782
|
+
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.",
|
|
15783
15783
|
arguments: (z) => ({
|
|
15784
15784
|
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.'),
|
|
15785
15785
|
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(),
|
|
@@ -20733,7 +20733,186 @@ function fileTextBytes(text) {
|
|
|
20733
20733
|
return encoder2.encode(text);
|
|
20734
20734
|
}
|
|
20735
20735
|
|
|
20736
|
+
// ../envoy-client/src/dispatch-login-command.ts
|
|
20737
|
+
var LOGIN_COMMAND = "login";
|
|
20738
|
+
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.";
|
|
20739
|
+
function loginHelp() {
|
|
20740
|
+
return [
|
|
20741
|
+
"Usage: dispatch login --device [--person <address>]",
|
|
20742
|
+
"",
|
|
20743
|
+
`${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.`,
|
|
20744
|
+
"",
|
|
20745
|
+
"Flags:",
|
|
20746
|
+
" --device",
|
|
20747
|
+
" Log in with the broker's device grant: the only way there is, and required.",
|
|
20748
|
+
" --person <address>",
|
|
20749
|
+
" The person who approves the login, by the address they sign in to Dispatch with; else AGENT_SECRETS_PERSON.",
|
|
20750
|
+
"",
|
|
20751
|
+
"It reads AGENT_SECRETS_URL, the broker, and needs no Dispatch host or session.",
|
|
20752
|
+
"",
|
|
20753
|
+
"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.",
|
|
20754
|
+
"",
|
|
20755
|
+
"Example: dispatch login --device --person ada@example.com",
|
|
20756
|
+
""
|
|
20757
|
+
].join(`
|
|
20758
|
+
`);
|
|
20759
|
+
}
|
|
20760
|
+
|
|
20761
|
+
// ../envoy-client/src/dispatch-proxy-command.ts
|
|
20762
|
+
import { resolve as resolve2 } from "path";
|
|
20763
|
+
var PROXY_COMMAND = "proxy";
|
|
20764
|
+
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.";
|
|
20765
|
+
var SOCKET_PATH_MAX_BYTES = 107;
|
|
20766
|
+
function proxyExitLine(requests, trades, renewed) {
|
|
20767
|
+
return `dispatch proxy: ${requests} requests, ${trades} trades, ${renewed} after BROKER_TOKEN_NOT_ACTIVE`;
|
|
20768
|
+
}
|
|
20769
|
+
function proxyHelp() {
|
|
20770
|
+
return [
|
|
20771
|
+
"Usage: dispatch proxy --socket <path> [--dry-run] -- <command> [<argument>...]",
|
|
20772
|
+
"",
|
|
20773
|
+
PROXY_SENTENCE,
|
|
20774
|
+
"",
|
|
20775
|
+
"The proxy listens on a unix socket at <path> for the whole run of <command>. It sends each",
|
|
20776
|
+
"request it takes to the Dispatch server and the session that a dispatch command resolves in",
|
|
20777
|
+
"the same environment, with this session's broker token and a new DPoP proof. So the tool",
|
|
20778
|
+
"holds no credential and signs nothing. It adds the path of each request to the path of the",
|
|
20779
|
+
"Dispatch URL, and it does not decode the query. The proxy trades for the token once before it",
|
|
20780
|
+
"starts the command, and again only when the token has less than 5 minutes to live, or after",
|
|
20781
|
+
"Dispatch answers 401 BROKER_TOKEN_NOT_ACTIVE. It runs only under DISPATCH_TOKEN_BROKER=1.",
|
|
20782
|
+
"",
|
|
20783
|
+
"What it sends:",
|
|
20784
|
+
" GET /api/... any GET whose path starts with /api/",
|
|
20785
|
+
" POST /api/v1/issues/<key>/comments a comment that carries an Idempotency-Key header",
|
|
20786
|
+
"It sends no other write. A tool reads much and writes little. Where a dispatch command sends a",
|
|
20787
|
+
"write, the write goes through that command, so AskGate reviews it wherever AskGate gates that",
|
|
20788
|
+
"command. The proxy's refusal of the write names that command. Where no other dispatch command",
|
|
20789
|
+
"sends a write under /api/v1, the refusal names dispatch api --method, which sends it outside a",
|
|
20790
|
+
"session whose AskGate reviews Dispatch writes. The comment needs a key so that a resend posts",
|
|
20791
|
+
"it once. The comment POST passes no AskGate review. The proxy is not one of the writes that",
|
|
20792
|
+
"AskGate gates, and the Dispatch server checks no marker. A session that holds a Dispatch token",
|
|
20793
|
+
"can post the same comment with that token already.",
|
|
20794
|
+
"",
|
|
20795
|
+
"It listens on a unix socket only, made with mode 0600, and opens no TCP port. The roles of a",
|
|
20796
|
+
"pod share the pod's network, so a port would let another role act as this one. A socket path",
|
|
20797
|
+
"that exists is refused, so give it a path in a new directory (mktemp -d). A socket that a",
|
|
20798
|
+
"killed proxy left behind refuses the next start.",
|
|
20799
|
+
"",
|
|
20800
|
+
"How a tool calls it: the command runs with DISPATCH_PROXY_SOCKET set to the socket's path.",
|
|
20801
|
+
"The host in a URL is not read. Write the path and the query.",
|
|
20802
|
+
' curl --unix-socket "$DISPATCH_PROXY_SOCKET" http://dispatch/api/v1/issues',
|
|
20803
|
+
" In Python, an http.client.HTTPConnection whose connect opens an AF_UNIX socket:",
|
|
20804
|
+
" import http.client, os, socket",
|
|
20805
|
+
" class ProxyConnection(http.client.HTTPConnection):",
|
|
20806
|
+
" def connect(self):",
|
|
20807
|
+
" self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)",
|
|
20808
|
+
' self.sock.connect(os.environ["DISPATCH_PROXY_SOCKET"])',
|
|
20809
|
+
' connection = ProxyConnection("dispatch")',
|
|
20810
|
+
' connection.request("GET", "/api/v1/issues?project=DSP")',
|
|
20811
|
+
" answer = connection.getresponse()",
|
|
20812
|
+
" print(answer.status, answer.read())",
|
|
20813
|
+
"",
|
|
20814
|
+
"What it answers: Dispatch's status, headers and body as Dispatch sent them. An answer that",
|
|
20815
|
+
"carries Transfer-Encoding as well as Content-Length is the one exception: it comes back",
|
|
20816
|
+
"without that Content-Length (RFC 9112, section 6.3), with its body chunked. It follows no",
|
|
20817
|
+
"redirect. Its own refusals have a JSON body with a code and an error, and each code starts",
|
|
20818
|
+
"with PROXY_. No code of Dispatch's does. It never answers 403 or 404 of its own.",
|
|
20819
|
+
" 400 PROXY_TARGET_REFUSED a target that names a host (http://... or //...)",
|
|
20820
|
+
" 405 PROXY_METHOD_REFUSED each other method or path, and a comment POST with no",
|
|
20821
|
+
" Idempotency-Key. The error names the dispatch command to",
|
|
20822
|
+
" use, where one exists. For a write under /api/v1 that no",
|
|
20823
|
+
" other dispatch command sends, it names dispatch api",
|
|
20824
|
+
" --method. It also refuses a target that holds a # or a",
|
|
20825
|
+
" control character, and a path with a . or .. segment",
|
|
20826
|
+
" (plain or percent-encoded), a backslash, or %2F or %5C in",
|
|
20827
|
+
" either case: each can reach another route than the one the",
|
|
20828
|
+
" target names.",
|
|
20829
|
+
" 502 PROXY_TRADE_REFUSED the token has ended and the broker refused a new one. The",
|
|
20830
|
+
" error is in the broker's words.",
|
|
20831
|
+
" 502 PROXY_DISPATCH_UNREACHABLE Dispatch did not answer",
|
|
20832
|
+
"",
|
|
20833
|
+
"Flags:",
|
|
20834
|
+
" --socket <path>",
|
|
20835
|
+
" The socket to listen on. Also --socket=<path>. A path over 107 bytes is refused.",
|
|
20836
|
+
" --dry-run",
|
|
20837
|
+
" Checks the arguments and the environment, prints the Dispatch server, the session and",
|
|
20838
|
+
" the socket it would use, and starts nothing.",
|
|
20839
|
+
" --help",
|
|
20840
|
+
" Prints this help.",
|
|
20841
|
+
"Every word after -- is the command's, flags included.",
|
|
20842
|
+
"",
|
|
20843
|
+
"It exits with the command's status. A command that a signal ended is 128 plus the signal's",
|
|
20844
|
+
"number. A command that does not exist is 127, and one that cannot run is 126. It exits 2 when",
|
|
20845
|
+
"it cannot start, and runs no command then. It sends SIGTERM, SIGINT and SIGHUP on to the",
|
|
20846
|
+
"command and serves until the command ends. Then it removes its socket. The last line it",
|
|
20847
|
+
"writes on standard error is:",
|
|
20848
|
+
" dispatch proxy: <n> requests, <m> trades, <r> after BROKER_TOKEN_NOT_ACTIVE",
|
|
20849
|
+
"Here n counts the requests sent to Dispatch, m the trades that gave a token, and r those of",
|
|
20850
|
+
"them that followed a BROKER_TOKEN_NOT_ACTIVE answer.",
|
|
20851
|
+
"",
|
|
20852
|
+
'Example: dispatch proxy --socket "$(mktemp -d)/d.sock" -- python3 work-cost.py',
|
|
20853
|
+
""
|
|
20854
|
+
].join(`
|
|
20855
|
+
`);
|
|
20856
|
+
}
|
|
20857
|
+
function parseProxyArgv(rest, cwd) {
|
|
20858
|
+
const separator = rest.indexOf("--");
|
|
20859
|
+
const own = separator === -1 ? rest : rest.slice(0, separator);
|
|
20860
|
+
if (own.includes("--help"))
|
|
20861
|
+
return { kind: "help" };
|
|
20862
|
+
let socket;
|
|
20863
|
+
let dryRun = false;
|
|
20864
|
+
for (let at = 0;at < own.length; at += 1) {
|
|
20865
|
+
const word = own[at] ?? "";
|
|
20866
|
+
if (word === "--dry-run") {
|
|
20867
|
+
dryRun = true;
|
|
20868
|
+
continue;
|
|
20869
|
+
}
|
|
20870
|
+
if (word !== "--socket" && !word.startsWith("--socket=")) {
|
|
20871
|
+
return {
|
|
20872
|
+
kind: "refused",
|
|
20873
|
+
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.`
|
|
20874
|
+
};
|
|
20875
|
+
}
|
|
20876
|
+
if (socket !== undefined)
|
|
20877
|
+
return { kind: "refused", problem: "--socket is given twice." };
|
|
20878
|
+
let value;
|
|
20879
|
+
if (word === "--socket") {
|
|
20880
|
+
at += 1;
|
|
20881
|
+
value = own[at];
|
|
20882
|
+
} else {
|
|
20883
|
+
value = word.slice("--socket=".length);
|
|
20884
|
+
}
|
|
20885
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
20886
|
+
return { kind: "refused", problem: "--socket takes the path of the socket to listen on." };
|
|
20887
|
+
}
|
|
20888
|
+
socket = value;
|
|
20889
|
+
}
|
|
20890
|
+
if (socket === undefined) {
|
|
20891
|
+
return { kind: "refused", problem: "--socket <path> is missing." };
|
|
20892
|
+
}
|
|
20893
|
+
const command = separator === -1 ? [] : rest.slice(separator + 1);
|
|
20894
|
+
if (command.length === 0) {
|
|
20895
|
+
return {
|
|
20896
|
+
kind: "refused",
|
|
20897
|
+
problem: "No command is given: write it after --, as -- <command> [<argument>...]."
|
|
20898
|
+
};
|
|
20899
|
+
}
|
|
20900
|
+
const path = resolve2(cwd, socket);
|
|
20901
|
+
const bytes = Buffer.byteLength(path);
|
|
20902
|
+
if (bytes > SOCKET_PATH_MAX_BYTES) {
|
|
20903
|
+
return {
|
|
20904
|
+
kind: "refused",
|
|
20905
|
+
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.`
|
|
20906
|
+
};
|
|
20907
|
+
}
|
|
20908
|
+
return { kind: "run", socket: path, dryRun, command };
|
|
20909
|
+
}
|
|
20910
|
+
|
|
20736
20911
|
// ../envoy-client/src/dispatch-command.ts
|
|
20912
|
+
var COMMANDS_OUTSIDE_THE_SPECS = [
|
|
20913
|
+
{ name: PROXY_COMMAND, sentence: PROXY_SENTENCE, help: proxyHelp },
|
|
20914
|
+
{ name: LOGIN_COMMAND, sentence: LOGIN_SENTENCE, help: loginHelp }
|
|
20915
|
+
];
|
|
20737
20916
|
var PREFIXED_FLAGS = [
|
|
20738
20917
|
{
|
|
20739
20918
|
tool: "dispatch_comment",
|
|
@@ -21005,7 +21184,10 @@ function parseCommand(argv, io) {
|
|
|
21005
21184
|
return { kind: "help" };
|
|
21006
21185
|
const tool = toolForCommand(command);
|
|
21007
21186
|
if (tool === undefined) {
|
|
21008
|
-
const commands = [
|
|
21187
|
+
const commands = [
|
|
21188
|
+
...toolsByCommand.keys(),
|
|
21189
|
+
...COMMANDS_OUTSIDE_THE_SPECS.map(({ name }) => name)
|
|
21190
|
+
].join(", ");
|
|
21009
21191
|
return {
|
|
21010
21192
|
kind: "refused",
|
|
21011
21193
|
problems: [`unknown command ${quoteWord(command)}; the commands are: ${commands}`]
|
|
@@ -21282,17 +21464,21 @@ function commandHelp(tool) {
|
|
|
21282
21464
|
`);
|
|
21283
21465
|
}
|
|
21284
21466
|
function commandsHelp() {
|
|
21285
|
-
const
|
|
21467
|
+
const rows = [
|
|
21468
|
+
...dispatchToolSpecs.map((spec) => ({
|
|
21469
|
+
name: commandName(spec.name),
|
|
21470
|
+
sentence: /^.*?[.!?](?=\s|$)/s.exec(spec.description)?.[0] ?? spec.description
|
|
21471
|
+
})),
|
|
21472
|
+
...COMMANDS_OUTSIDE_THE_SPECS
|
|
21473
|
+
];
|
|
21474
|
+
const width = Math.max(...rows.map(({ name }) => name.length));
|
|
21286
21475
|
return [
|
|
21287
21476
|
"Usage: dispatch <command> [flags]",
|
|
21288
|
-
...
|
|
21289
|
-
const sentence = /^.*?[.!?](?=\s|$)/s.exec(spec.description)?.[0] ?? spec.description;
|
|
21290
|
-
return ` ${commandName(spec.name).padEnd(width)} ${sentence}`;
|
|
21291
|
-
}),
|
|
21477
|
+
...rows.map(({ name, sentence }) => ` ${name.padEnd(width)} ${sentence}`),
|
|
21292
21478
|
"",
|
|
21293
|
-
"Run dispatch <command> --help for its flags and an example. --dry-run checks
|
|
21479
|
+
"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.",
|
|
21294
21480
|
"",
|
|
21295
|
-
"dispatch login --device
|
|
21481
|
+
"dispatch login --device is no Dispatch call: it needs no host or session.",
|
|
21296
21482
|
""
|
|
21297
21483
|
].join(`
|
|
21298
21484
|
`);
|
|
@@ -23268,7 +23454,8 @@ var POLICY_SENTINELS = {
|
|
|
23268
23454
|
machineNotAllowed: "exchange: the machine is not one the entry allows",
|
|
23269
23455
|
sessionFixed: "exchange: the entry fixes the session name its tokens carry",
|
|
23270
23456
|
projectsFixed: "exchange: the request names projects other than the one its entry gives",
|
|
23271
|
-
projectsNoPerson: "exchange: a token that names no person names no project"
|
|
23457
|
+
projectsNoPerson: "exchange: a token that names no person names no project",
|
|
23458
|
+
restrictedOneProject: "exchange: a restricted member's machine login names exactly one project"
|
|
23272
23459
|
};
|
|
23273
23460
|
function policy(sentinel, format, ...slots) {
|
|
23274
23461
|
return `${escapeRegExp(`The subject token was refused: ${POLICY_SENTINELS[sentinel]}: `)}${formatPattern(format, slots)}\\.`;
|
|
@@ -23306,20 +23493,23 @@ var POLICY_REFUSAL_PATTERNS = [
|
|
|
23306
23493
|
policy("projectsFixed", "%s's entry names no project, and the request named %s", IDENTITY, PROJECT_LIST),
|
|
23307
23494
|
policy("projectsFixed", "%s writes the project %s that its entry names, and the request named %s", IDENTITY, PROJECT_SLOT, PROJECT_LIST),
|
|
23308
23495
|
policy("projectsFixed", "%s's entry gives its token the projects %s, and the request named %s, which that list does not name", IDENTITY, JOB_LIST, PROJECT_SLOT),
|
|
23496
|
+
policy("restrictedOneProject", "%s is a restricted member, who sees only the projects that name them, and the trade asked for %d; set AGENT_SECRETS_PROJECTS to the one project this session works on", PERSON_SLOT, NUMBER),
|
|
23309
23497
|
`${escapeRegExp("The subject token was refused: ")}${formatPattern("the subject token was not minted for %s, which is the audience this broker accepts from %s", [URI, URI])}\\.`
|
|
23310
23498
|
];
|
|
23311
23499
|
var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
23312
23500
|
`${PERSON_SLOT} revoked this machine's sign-in, so the key this proof was signed with trades nothing\\. Sign in again with \`agent-secrets login\`\\.`,
|
|
23313
23501
|
`${PERSON_SLOT}'s sign-in on this box key was made on another machine, and a sign-in belongs to the machine it was made on\\. Sign in again with \`agent-secrets login\`\\.`,
|
|
23502
|
+
`${PERSON_SLOT}'s sign-in on this box key was made by another Google account, and a sign-in belongs to the account that made it\\. Sign in again with \`agent-secrets login\`\\.`,
|
|
23503
|
+
`The Google account this token was minted for no longer holds ${PERSON_SLOT}: another account holds that address now, and the broker takes no sign-in of the account it replaced\\.`,
|
|
23314
23504
|
"The machine login the subject token belongs to has ended\\.",
|
|
23315
23505
|
"The machine login has ended\\.",
|
|
23316
23506
|
"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)\\.",
|
|
23317
23507
|
"A live read token is bound to the key this proof was signed with\\. Make a new key\\.",
|
|
23318
|
-
`${PERSON_SLOT} is a restricted member, whose token names its projects: set AGENT_SECRETS_PROJECTS to the projects this session works on\\.`,
|
|
23319
23508
|
`The token names a project its person cannot see: ${PROJECT_SLOT}\\.`,
|
|
23320
23509
|
`The subject token was refused: its entry names the project ${PROJECT_SLOT}, which its person ${PERSON_SLOT} cannot see\\.`,
|
|
23321
23510
|
`The subject token was refused: its entry names no project, and its person ${PERSON_SLOT} is a restricted member, who sees only the projects that name them\\.`,
|
|
23322
23511
|
"Dispatch could not be asked whether the token's person sees the projects it names; try again\\.",
|
|
23512
|
+
"Dispatch could not be asked what kind of member the machine login's approver is, so this broker cannot tell whether the token is held to one project; try again\\.",
|
|
23323
23513
|
`The session name '${SESSION_SLOT}' belongs to another identity: one the broker's configuration fixes it for, or one that has written under it within the last [0-9]{1,4} days\\. Ask under a name of your own\\.`,
|
|
23324
23514
|
`No registration says this pod may write under the session name '${SESSION_SLOT}'\\. A pod writes under a session name its deployment registered for it\\.`,
|
|
23325
23515
|
`Refused: this pod's registration for session '${SESSION_SLOT}' is bound to another key; a role trades only for its own session\\.`,
|
|
@@ -23329,6 +23519,7 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
|
23329
23519
|
"Only a person's sign-in is traded for the approve capability's proxy placeholder, on a broker that serves it\\.",
|
|
23330
23520
|
"A trade for the approve capability's proxy placeholder asks for the scope read, and a trade narrowed to reading approves nothing: trade for the placeholder without the scope, a cut or a DPoP-Holder proof\\.",
|
|
23331
23521
|
`${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`,
|
|
23522
|
+
`Google's Workspace Directory no longer confirms ${PERSON_SLOT}; their credentials work again once it does`,
|
|
23332
23523
|
"The 'as_of' parameter names a cut, and only a trade that asks for the scope read may name one\\.",
|
|
23333
23524
|
"The 'as_of' parameter is not an RFC 3339 time with at most six fractional digits\\.",
|
|
23334
23525
|
"The 'as_of' parameter names the zero time, which is no cut: a trade that reads the present names no cut\\.",
|
|
@@ -26073,12 +26264,10 @@ var WRITE_ROUTES = [
|
|
|
26073
26264
|
commands: ["architecture-sync"]
|
|
26074
26265
|
}
|
|
26075
26266
|
];
|
|
26267
|
+
var WRITE_ROUTE_SEGMENTS = WRITE_ROUTES.map((row) => ({ row, segments: row.pattern.split("/") }));
|
|
26076
26268
|
function writeRoute(method, path) {
|
|
26077
26269
|
const segments = path.split("/");
|
|
26078
|
-
return
|
|
26079
|
-
const pattern = row.pattern.split("/");
|
|
26080
|
-
return row.method === method && pattern.length === segments.length && pattern.every((part, at) => part.startsWith("{") ? segments[at] !== "" : part === segments[at]);
|
|
26081
|
-
});
|
|
26270
|
+
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;
|
|
26082
26271
|
}
|
|
26083
26272
|
|
|
26084
26273
|
class ApiGateRefusal extends Error {
|
|
@@ -26158,7 +26347,7 @@ function refusalWithCode(error, ...clauses) {
|
|
|
26158
26347
|
const told = joined !== "" && /[.!?]$/.test(error.message) ? `${error.message} ${suffix.charAt(0).toUpperCase()}${suffix.slice(1)}` : `${error.message}${joined}`;
|
|
26159
26348
|
return new DispatchServiceError(error.code, error.status, `${error.code}: ${told}`, error);
|
|
26160
26349
|
}
|
|
26161
|
-
function parentStatusConflictLines(error, tool, args
|
|
26350
|
+
function parentStatusConflictLines(error, tool, args) {
|
|
26162
26351
|
if (!dispatchAnswered(error, 409) || error.code !== "PARENT_STATUS_CONFLICT")
|
|
26163
26352
|
return;
|
|
26164
26353
|
const issues = error.issues ?? [];
|
|
@@ -26169,28 +26358,15 @@ function parentStatusConflictLines(error, tool, args, legionIssue) {
|
|
|
26169
26358
|
return [
|
|
26170
26359
|
messageFor(error),
|
|
26171
26360
|
...issues.map((issue) => `${issue.key} [${issue.status}] ${issue.title}`),
|
|
26172
|
-
...nextSteps(tool, args, parents, children
|
|
26361
|
+
...nextSteps(tool, args, parents, children)
|
|
26173
26362
|
];
|
|
26174
26363
|
}
|
|
26175
26364
|
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.";
|
|
26176
26365
|
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.";
|
|
26177
|
-
function otherProjectSentence(named, keys) {
|
|
26178
|
-
const project = named === undefined ? undefined : issueProject(named);
|
|
26179
|
-
if (project === undefined)
|
|
26180
|
-
return "";
|
|
26181
|
-
const others = keys.filter((key) => {
|
|
26182
|
-
const other = issueProject(key);
|
|
26183
|
-
return other !== undefined && other !== project;
|
|
26184
|
-
});
|
|
26185
|
-
if (others.length === 0)
|
|
26186
|
-
return "";
|
|
26187
|
-
const one = others.length === 1;
|
|
26188
|
-
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.`;
|
|
26189
|
-
}
|
|
26190
26366
|
function includeParentCall(key) {
|
|
26191
26367
|
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`;
|
|
26192
26368
|
}
|
|
26193
|
-
function nextSteps(tool, args, parents, children
|
|
26369
|
+
function nextSteps(tool, args, parents, children) {
|
|
26194
26370
|
if (tool === "dispatch_issue") {
|
|
26195
26371
|
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.`);
|
|
26196
26372
|
}
|
|
@@ -26198,9 +26374,7 @@ function nextSteps(tool, args, parents, children, legionIssue) {
|
|
|
26198
26374
|
const written = issueUpdate ? args : {};
|
|
26199
26375
|
const fields = Object.keys(written).filter((field) => field !== "issue" && written[field] !== undefined);
|
|
26200
26376
|
const issue = optionalString(written, "issue");
|
|
26201
|
-
const named = issueUpdate ? issue ?? legionIssue : undefined;
|
|
26202
26377
|
const childHolds = children.length > 0;
|
|
26203
|
-
const childScope = otherProjectSentence(named, children);
|
|
26204
26378
|
const status = optionalString(written, "status");
|
|
26205
26379
|
const parent = optionalString(written, "parent");
|
|
26206
26380
|
const alone = `--status${status === "done" ? " and --reason" : ""} alone`;
|
|
@@ -26213,7 +26387,7 @@ function nextSteps(tool, args, parents, children, legionIssue) {
|
|
|
26213
26387
|
const afterStatus = childHolds ? ", after the status change," : "";
|
|
26214
26388
|
return [
|
|
26215
26389
|
...childHolds ? [
|
|
26216
|
-
`${CHILD_FLAGS} Each goes with ${alone}, so run the status change first, in a call of its own, and the reparent after it: ${reparent}
|
|
26390
|
+
`${CHILD_FLAGS} Each goes with ${alone}, so run the status change first, in a call of its own, and the reparent after it: ${reparent}.`
|
|
26217
26391
|
] : [],
|
|
26218
26392
|
...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}.`)
|
|
26219
26393
|
];
|
|
@@ -26221,8 +26395,8 @@ function nextSteps(tool, args, parents, children, legionIssue) {
|
|
|
26221
26395
|
const others = ISSUE_UPDATE_PATCH_FIELDS.some((field) => written[field] !== undefined);
|
|
26222
26396
|
const apart = (subject) => others ? ` ${subject} with ${alone}, so send the call's other changes in a call of their own.` : "";
|
|
26223
26397
|
return [
|
|
26224
|
-
...childHolds ? [`${CHILD_FLAGS}${apart("Each goes")}
|
|
26225
|
-
...parents.length > 0 ? [`${PARENT_FLAG}${apart("It goes")}
|
|
26398
|
+
...childHolds ? [`${CHILD_FLAGS}${apart("Each goes")}`] : [],
|
|
26399
|
+
...parents.length > 0 ? [`${PARENT_FLAG}${apart("It goes")}`] : []
|
|
26226
26400
|
];
|
|
26227
26401
|
}
|
|
26228
26402
|
function dispatchAnswered(error, status) {
|
|
@@ -29991,6 +30165,16 @@ function hostSession(hostName, env) {
|
|
|
29991
30165
|
const file = (env.DISPATCH_HOST === undefined ? null : handedConfigFile(env)) ?? sessionConfigFile(host, env);
|
|
29992
30166
|
return { host, sessionId, file };
|
|
29993
30167
|
}
|
|
30168
|
+
function hostSessionDirectory(hostName, env) {
|
|
30169
|
+
const hosted = hostSession(hostName, env);
|
|
30170
|
+
if ("problem" in hosted)
|
|
30171
|
+
return hosted;
|
|
30172
|
+
try {
|
|
30173
|
+
return { ...hosted, dir: sessionDirectory(env, hosted.sessionId) };
|
|
30174
|
+
} catch (error) {
|
|
30175
|
+
return { problem: messageFor(error) };
|
|
30176
|
+
}
|
|
30177
|
+
}
|
|
29994
30178
|
async function hostedDispatch(file, env, options) {
|
|
29995
30179
|
if (file.path === null)
|
|
29996
30180
|
return { problem: `dispatch: ${file.error}`, warnings: [] };
|
|
@@ -35781,23 +35965,6 @@ async function resultsCommand(context) {
|
|
|
35781
35965
|
|
|
35782
35966
|
// ../envoy-client/src/dispatch-commands/login.ts
|
|
35783
35967
|
import { hostname as hostname4 } from "os";
|
|
35784
|
-
var LOGIN_HELP = [
|
|
35785
|
-
"Usage: dispatch login --device [--person <address>]",
|
|
35786
|
-
"",
|
|
35787
|
-
"Logs this machine in at the secrets broker, once per machine, for a machine with no identity of its own, such as a laptop. 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.",
|
|
35788
|
-
"",
|
|
35789
|
-
"Flags:",
|
|
35790
|
-
" --device",
|
|
35791
|
-
" Log in with the broker's device grant: the only way there is, and required.",
|
|
35792
|
-
" --person <address>",
|
|
35793
|
-
` The person who approves the login, by the address they sign in to Dispatch with; else ${PERSON_VAR}.`,
|
|
35794
|
-
"",
|
|
35795
|
-
`It reads ${BROKER_URL_VAR}, the broker, and needs no Dispatch host or session.`,
|
|
35796
|
-
"",
|
|
35797
|
-
`Example: ${DEVICE_LOGIN_COMMAND} --person ada@example.com`,
|
|
35798
|
-
""
|
|
35799
|
-
].join(`
|
|
35800
|
-
`);
|
|
35801
35968
|
function parseLogin(argv) {
|
|
35802
35969
|
let device = false;
|
|
35803
35970
|
let person;
|
|
@@ -35828,7 +35995,7 @@ async function loginCommand(argv, env, io) {
|
|
|
35828
35995
|
};
|
|
35829
35996
|
const parsed = parseLogin(argv);
|
|
35830
35997
|
if (parsed.kind === "help") {
|
|
35831
|
-
io.print(
|
|
35998
|
+
io.print(loginHelp());
|
|
35832
35999
|
return OK;
|
|
35833
36000
|
}
|
|
35834
36001
|
const tokenFiles = tokenFilesSet(env);
|
|
@@ -38529,9 +38696,9 @@ async function whoamiCommand(context) {
|
|
|
38529
38696
|
} else {
|
|
38530
38697
|
acting = `Session ${session} runs under the shared token: ${unowned}`;
|
|
38531
38698
|
}
|
|
38532
|
-
const
|
|
38699
|
+
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." : "";
|
|
38533
38700
|
return {
|
|
38534
|
-
text: acting + elsewhere +
|
|
38701
|
+
text: acting + elsewhere + projectSentence,
|
|
38535
38702
|
details: { session, owner, service, project, project_scope: projectScope }
|
|
38536
38703
|
};
|
|
38537
38704
|
}
|
|
@@ -38868,6 +39035,394 @@ async function executeDispatchTool(input) {
|
|
|
38868
39035
|
return command.origin === "none" ? command.run(session) : command.run(await commandContext(session));
|
|
38869
39036
|
}
|
|
38870
39037
|
|
|
39038
|
+
// ../envoy-client/src/dispatch-proxy.ts
|
|
39039
|
+
import { lstatSync, rmSync as rmSync3 } from "fs";
|
|
39040
|
+
import {
|
|
39041
|
+
createServer
|
|
39042
|
+
} from "http";
|
|
39043
|
+
import { constants as constants4 } from "os";
|
|
39044
|
+
var CANNOT_START = 2;
|
|
39045
|
+
var COMMAND_NOT_FOUND = 127;
|
|
39046
|
+
var COMMAND_CANNOT_RUN = 126;
|
|
39047
|
+
var FORWARDED = ["SIGTERM", "SIGINT", "SIGHUP"];
|
|
39048
|
+
var TARGET_REFUSED = { status: 400, code: "PROXY_TARGET_REFUSED" };
|
|
39049
|
+
var METHOD_REFUSED = { status: 405, code: "PROXY_METHOD_REFUSED" };
|
|
39050
|
+
var TRADE_REFUSED = { status: 502, code: "PROXY_TRADE_REFUSED" };
|
|
39051
|
+
var DISPATCH_UNREACHABLE = { status: 502, code: "PROXY_DISPATCH_UNREACHABLE" };
|
|
39052
|
+
var SENDS = "The proxy sends a GET whose path starts with /api/, and a POST to /api/v1/issues/<key>/comments that carries an Idempotency-Key header, and nothing else.";
|
|
39053
|
+
var HOP_BY_HOP = new Set([
|
|
39054
|
+
"connection",
|
|
39055
|
+
"keep-alive",
|
|
39056
|
+
"proxy-connection",
|
|
39057
|
+
"proxy-authenticate",
|
|
39058
|
+
"proxy-authorization",
|
|
39059
|
+
"te",
|
|
39060
|
+
"trailer",
|
|
39061
|
+
"transfer-encoding",
|
|
39062
|
+
"upgrade"
|
|
39063
|
+
]);
|
|
39064
|
+
var NOT_COPIED = new Set([
|
|
39065
|
+
...HOP_BY_HOP,
|
|
39066
|
+
"host",
|
|
39067
|
+
"expect",
|
|
39068
|
+
"authorization",
|
|
39069
|
+
"dpop",
|
|
39070
|
+
"accept-encoding",
|
|
39071
|
+
"content-length"
|
|
39072
|
+
]);
|
|
39073
|
+
var COMMENT_PATH = /^\/api\/v1\/issues\/[^/]+\/comments$/;
|
|
39074
|
+
|
|
39075
|
+
class Tally {
|
|
39076
|
+
requests = 0;
|
|
39077
|
+
tokens = new Set;
|
|
39078
|
+
renewed = 0;
|
|
39079
|
+
line() {
|
|
39080
|
+
return proxyExitLine(this.requests, this.tokens.size, this.renewed);
|
|
39081
|
+
}
|
|
39082
|
+
}
|
|
39083
|
+
function socketPathTaken(socket) {
|
|
39084
|
+
try {
|
|
39085
|
+
lstatSync(socket);
|
|
39086
|
+
} catch (error) {
|
|
39087
|
+
if (hasErrnoCode(error, "ENOENT"))
|
|
39088
|
+
return;
|
|
39089
|
+
return `dispatch proxy: the socket path ${socket} cannot be read: ${messageFor(error)}`;
|
|
39090
|
+
}
|
|
39091
|
+
return `dispatch proxy: the socket path ${socket} exists. The proxy makes its socket new and refuses a path that exists, a socket a killed proxy left behind included. Give it a path in a new directory (mktemp -d).`;
|
|
39092
|
+
}
|
|
39093
|
+
async function runDispatchProxy(run) {
|
|
39094
|
+
const say = (line) => run.stderr(`${line}
|
|
39095
|
+
`);
|
|
39096
|
+
const tally = new Tally;
|
|
39097
|
+
const beforeStart = new AbortController;
|
|
39098
|
+
let caught;
|
|
39099
|
+
let child;
|
|
39100
|
+
const handlers = FORWARDED.map((signal) => {
|
|
39101
|
+
const handler = () => {
|
|
39102
|
+
if (child === undefined) {
|
|
39103
|
+
caught ??= signal;
|
|
39104
|
+
beforeStart.abort(new Error(`${signal} arrived before the command started`));
|
|
39105
|
+
return;
|
|
39106
|
+
}
|
|
39107
|
+
try {
|
|
39108
|
+
child.kill(signal);
|
|
39109
|
+
} catch {}
|
|
39110
|
+
};
|
|
39111
|
+
process.on(signal, handler);
|
|
39112
|
+
return [signal, handler];
|
|
39113
|
+
});
|
|
39114
|
+
const endedBySignal = (signal) => {
|
|
39115
|
+
say(`dispatch proxy: ${signal} arrived before the command started, so it runs no command.`);
|
|
39116
|
+
return 128 + constants4.signals[signal];
|
|
39117
|
+
};
|
|
39118
|
+
const server = proxyServer(run, tally);
|
|
39119
|
+
let made = false;
|
|
39120
|
+
try {
|
|
39121
|
+
const taken = socketPathTaken(run.socket);
|
|
39122
|
+
if (taken !== undefined) {
|
|
39123
|
+
say(taken);
|
|
39124
|
+
return CANNOT_START;
|
|
39125
|
+
}
|
|
39126
|
+
try {
|
|
39127
|
+
const first = await brokerTokenFor(run.env, run.sessionId)(AbortSignal.any([AbortSignal.timeout(DISPATCH_TOOL_DEADLINE_MS), beforeStart.signal]), true);
|
|
39128
|
+
tally.tokens.add(first.token.accessToken);
|
|
39129
|
+
} catch (error) {
|
|
39130
|
+
if (caught !== undefined)
|
|
39131
|
+
return endedBySignal(caught);
|
|
39132
|
+
say(`dispatch proxy: the secrets broker gave session ${run.sessionId} no Dispatch token, so the proxy starts no command: ${messageFor(error)}`);
|
|
39133
|
+
return CANNOT_START;
|
|
39134
|
+
}
|
|
39135
|
+
if (caught !== undefined)
|
|
39136
|
+
return endedBySignal(caught);
|
|
39137
|
+
try {
|
|
39138
|
+
await listen(server, run.socket);
|
|
39139
|
+
made = true;
|
|
39140
|
+
} catch (error) {
|
|
39141
|
+
say(`dispatch proxy: it cannot listen on ${run.socket}: ${messageFor(error)}`);
|
|
39142
|
+
return CANNOT_START;
|
|
39143
|
+
}
|
|
39144
|
+
server.on("error", (error) => say(`dispatch proxy: its socket failed: ${messageFor(error)}`));
|
|
39145
|
+
if (caught !== undefined)
|
|
39146
|
+
return endedBySignal(caught);
|
|
39147
|
+
let started;
|
|
39148
|
+
try {
|
|
39149
|
+
started = Bun.spawn([...run.command], {
|
|
39150
|
+
cwd: run.cwd,
|
|
39151
|
+
env: { ...run.commandEnv, DISPATCH_PROXY_SOCKET: run.socket },
|
|
39152
|
+
stdin: "inherit",
|
|
39153
|
+
stdout: "inherit",
|
|
39154
|
+
stderr: "inherit"
|
|
39155
|
+
});
|
|
39156
|
+
} catch (error) {
|
|
39157
|
+
say(`dispatch proxy: ${run.command[0]} could not be run: ${messageFor(error)}`);
|
|
39158
|
+
return hasErrnoCode(error, "ENOENT") ? COMMAND_NOT_FOUND : COMMAND_CANNOT_RUN;
|
|
39159
|
+
}
|
|
39160
|
+
child = started;
|
|
39161
|
+
const exited = await started.exited;
|
|
39162
|
+
const signal = started.signalCode;
|
|
39163
|
+
return signal === null ? started.exitCode ?? exited : 128 + constants4.signals[signal];
|
|
39164
|
+
} finally {
|
|
39165
|
+
for (const [signal, handler] of handlers)
|
|
39166
|
+
process.off(signal, handler);
|
|
39167
|
+
if (made) {
|
|
39168
|
+
server.close();
|
|
39169
|
+
server.closeAllConnections();
|
|
39170
|
+
rmSync3(run.socket, { force: true });
|
|
39171
|
+
}
|
|
39172
|
+
say(tally.line());
|
|
39173
|
+
}
|
|
39174
|
+
}
|
|
39175
|
+
async function listen(server, socket) {
|
|
39176
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
39177
|
+
server.once("error", reject);
|
|
39178
|
+
const kept = process.umask(127);
|
|
39179
|
+
try {
|
|
39180
|
+
server.listen(socket, () => resolve());
|
|
39181
|
+
await promise;
|
|
39182
|
+
} finally {
|
|
39183
|
+
process.umask(kept);
|
|
39184
|
+
server.off("error", reject);
|
|
39185
|
+
}
|
|
39186
|
+
}
|
|
39187
|
+
function proxyServer(run, tally) {
|
|
39188
|
+
const dispatch = new URL(run.config.url);
|
|
39189
|
+
dispatch.hash = "";
|
|
39190
|
+
const base = withoutTrailingSlashes(dispatch.pathname);
|
|
39191
|
+
const server = createServer((request, response) => {
|
|
39192
|
+
serve(request, response, run, dispatch, base, tally).catch((error) => {
|
|
39193
|
+
if (!response.headersSent) {
|
|
39194
|
+
answerRefusal(response, DISPATCH_UNREACHABLE, messageFor(error));
|
|
39195
|
+
return;
|
|
39196
|
+
}
|
|
39197
|
+
if (response.socket)
|
|
39198
|
+
response.socket.destroy();
|
|
39199
|
+
else
|
|
39200
|
+
response.destroy();
|
|
39201
|
+
});
|
|
39202
|
+
});
|
|
39203
|
+
server.on("connect", (_request, socket) => {
|
|
39204
|
+
refuseOnSocket(socket, `The proxy opens no tunnel (CONNECT). ${SENDS} Read a route with a GET under /api/, or with dispatch api.`);
|
|
39205
|
+
});
|
|
39206
|
+
server.on("upgrade", (_request, socket) => {
|
|
39207
|
+
refuseOnSocket(socket, `The proxy upgrades no connection (a WebSocket, for one). ${SENDS} Read the route with a plain GET, or with dispatch api.`);
|
|
39208
|
+
});
|
|
39209
|
+
server.on("clientError", (_error, socket) => {
|
|
39210
|
+
refuseOnSocket(socket, `The proxy cannot read this request as one it sends, the asterisk form (OPTIONS *) among them. ${SENDS} Read a route with a GET under /api/, or with dispatch api.`);
|
|
39211
|
+
});
|
|
39212
|
+
return server;
|
|
39213
|
+
}
|
|
39214
|
+
function refuseOnSocket(socket, error) {
|
|
39215
|
+
if (!socket.writable) {
|
|
39216
|
+
socket.destroy();
|
|
39217
|
+
return;
|
|
39218
|
+
}
|
|
39219
|
+
const body = JSON.stringify({ code: METHOD_REFUSED.code, error });
|
|
39220
|
+
socket.end([
|
|
39221
|
+
"HTTP/1.1 405 Method Not Allowed",
|
|
39222
|
+
"Content-Type: application/json",
|
|
39223
|
+
`Content-Length: ${Buffer.byteLength(body)}`,
|
|
39224
|
+
"Connection: close",
|
|
39225
|
+
"",
|
|
39226
|
+
body
|
|
39227
|
+
].join(`\r
|
|
39228
|
+
`));
|
|
39229
|
+
}
|
|
39230
|
+
function answerRefusal(response, refusal, error) {
|
|
39231
|
+
const body = JSON.stringify({ code: refusal.code, error });
|
|
39232
|
+
response.writeHead(refusal.status, {
|
|
39233
|
+
"Content-Type": "application/json",
|
|
39234
|
+
"Content-Length": Buffer.byteLength(body)
|
|
39235
|
+
});
|
|
39236
|
+
response.end(body);
|
|
39237
|
+
}
|
|
39238
|
+
function namesAHost(target) {
|
|
39239
|
+
return /^[A-Za-z][A-Za-z0-9+.-]*:/.test(target) || target.startsWith("//");
|
|
39240
|
+
}
|
|
39241
|
+
function resolvesElsewhere(path) {
|
|
39242
|
+
if (path.includes("\\"))
|
|
39243
|
+
return true;
|
|
39244
|
+
return path.split("/").some((segment) => {
|
|
39245
|
+
const plain = segment.replace(/%2e/gi, ".");
|
|
39246
|
+
return plain === "." || plain === "..";
|
|
39247
|
+
});
|
|
39248
|
+
}
|
|
39249
|
+
var FRAGMENT_OR_CONTROL = /[#\u007f]|[^\u0020-\uffff]/;
|
|
39250
|
+
function elsewhereRefusal(target, path) {
|
|
39251
|
+
if (path.startsWith("/") && !resolvesElsewhere(path) && !FRAGMENT_OR_CONTROL.test(target)) {
|
|
39252
|
+
return;
|
|
39253
|
+
}
|
|
39254
|
+
return `${SENDS} The target ${JSON.stringify(target)} reaches another route than the one it names (a dot segment, a backslash, a # or a control character). Name the route's own path, or read it with dispatch api.`;
|
|
39255
|
+
}
|
|
39256
|
+
function methodRefusal(method, path, key) {
|
|
39257
|
+
const quoted = JSON.stringify(path);
|
|
39258
|
+
if (method === "GET") {
|
|
39259
|
+
return path.startsWith("/api/") ? undefined : `${SENDS} ${quoted} is outside /api/. Read a route of /api/v1 with dispatch api --path <path>.`;
|
|
39260
|
+
}
|
|
39261
|
+
if (method === "POST" && COMMENT_PATH.test(path)) {
|
|
39262
|
+
return (key ?? "").trim() !== "" ? undefined : `${SENDS} This comment POST carries no Idempotency-Key header. Send it with one, so a resend posts the comment once, or post the comment with dispatch comment.`;
|
|
39263
|
+
}
|
|
39264
|
+
if (DISPATCH_API_METHODS.includes(method)) {
|
|
39265
|
+
const row = writeRoute(method, path);
|
|
39266
|
+
if (row !== undefined) {
|
|
39267
|
+
return `${SENDS} ${method} ${quoted} is another write. Send it with dispatch ${row.commands[0]}. AskGate reviews that call if it gates the command.`;
|
|
39268
|
+
}
|
|
39269
|
+
if (!API_ROUTE_PATTERN.test(path)) {
|
|
39270
|
+
return `${SENDS} ${method} ${quoted} is another write, outside /api/v1, and no dispatch command sends it.`;
|
|
39271
|
+
}
|
|
39272
|
+
return `${SENDS} ${method} ${quoted} is another write, and no named dispatch command sends it. Send it with dispatch api --method ${method} --path <path>. In a session whose AskGate reviews Dispatch writes, that command sends only GET, so it refuses this write.`;
|
|
39273
|
+
}
|
|
39274
|
+
return `${SENDS} ${method} is no method it sends. Read the route with a GET, or with dispatch api.`;
|
|
39275
|
+
}
|
|
39276
|
+
var ENCODED_SEPARATOR = /%(?:2f|5c)/i;
|
|
39277
|
+
function outboundRefusal(url, dispatch, base) {
|
|
39278
|
+
if (url.origin === dispatch.origin && url.pathname.startsWith(`${base}/api/`) && !url.href.includes("#") && !ENCODED_SEPARATOR.test(url.pathname)) {
|
|
39279
|
+
return;
|
|
39280
|
+
}
|
|
39281
|
+
return `${SENDS} The URL it would send for ${JSON.stringify(url.pathname.slice(base.length))} is outside /api/ of the Dispatch server, has a fragment, or holds a percent-encoded / or \\ (%2F or %5C, in either case), which Dispatch's server can decode into another route. Name the route's own path, or read it with dispatch api.`;
|
|
39282
|
+
}
|
|
39283
|
+
function connectionNamed(value) {
|
|
39284
|
+
return new Set((value ?? "").split(",").map((name) => name.trim().toLowerCase()).filter((name) => name !== ""));
|
|
39285
|
+
}
|
|
39286
|
+
function forwardedHeaders(incoming) {
|
|
39287
|
+
const named = connectionNamed(incoming.connection);
|
|
39288
|
+
const headers = {};
|
|
39289
|
+
for (const [name, value] of Object.entries(incoming)) {
|
|
39290
|
+
if (value === undefined || NOT_COPIED.has(name) || named.has(name))
|
|
39291
|
+
continue;
|
|
39292
|
+
headers[name] = Array.isArray(value) ? value.join(", ") : value;
|
|
39293
|
+
}
|
|
39294
|
+
headers["accept-encoding"] = "identity";
|
|
39295
|
+
return headers;
|
|
39296
|
+
}
|
|
39297
|
+
function answeredHeaders(headers) {
|
|
39298
|
+
const named = connectionNamed(headers.get("connection"));
|
|
39299
|
+
const transferCoded = headers.has("transfer-encoding");
|
|
39300
|
+
const kept = {};
|
|
39301
|
+
headers.forEach((value, name) => {
|
|
39302
|
+
if (HOP_BY_HOP.has(name) || named.has(name) || name === "set-cookie")
|
|
39303
|
+
return;
|
|
39304
|
+
if (name === "content-length" && transferCoded)
|
|
39305
|
+
return;
|
|
39306
|
+
kept[name] = value;
|
|
39307
|
+
});
|
|
39308
|
+
const cookies = headers.getSetCookie();
|
|
39309
|
+
if (cookies.length > 0)
|
|
39310
|
+
kept["set-cookie"] = cookies;
|
|
39311
|
+
return kept;
|
|
39312
|
+
}
|
|
39313
|
+
async function wholeBody(request) {
|
|
39314
|
+
const chunks = [];
|
|
39315
|
+
for await (const chunk of request) {
|
|
39316
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
39317
|
+
}
|
|
39318
|
+
const body = new Uint8Array(chunks.reduce((length, chunk) => length + chunk.length, 0));
|
|
39319
|
+
let at = 0;
|
|
39320
|
+
for (const chunk of chunks) {
|
|
39321
|
+
body.set(chunk, at);
|
|
39322
|
+
at += chunk.length;
|
|
39323
|
+
}
|
|
39324
|
+
return body;
|
|
39325
|
+
}
|
|
39326
|
+
|
|
39327
|
+
class TradeRefused extends Error {
|
|
39328
|
+
}
|
|
39329
|
+
async function serve(request, response, run, dispatch, base, tally) {
|
|
39330
|
+
const target = request.url ?? "";
|
|
39331
|
+
const method = request.method ?? "";
|
|
39332
|
+
if (namesAHost(target)) {
|
|
39333
|
+
answerRefusal(response, TARGET_REFUSED, `The proxy sends each request to the Dispatch server ${run.config.url} alone, so a target that names a host, ${JSON.stringify(target)}, is refused. Write the path and the query alone.`);
|
|
39334
|
+
return;
|
|
39335
|
+
}
|
|
39336
|
+
const at = target.indexOf("?");
|
|
39337
|
+
const path = at === -1 ? target : target.slice(0, at);
|
|
39338
|
+
const outbound = new URL(dispatch);
|
|
39339
|
+
outbound.pathname = `${base}${path}`;
|
|
39340
|
+
outbound.search = at === -1 ? "" : target.slice(at);
|
|
39341
|
+
const header = request.headers["idempotency-key"];
|
|
39342
|
+
const key = Array.isArray(header) ? header.join(", ") : header;
|
|
39343
|
+
const refusal = elsewhereRefusal(target, path) ?? methodRefusal(method, outbound.pathname.slice(base.length), key) ?? outboundRefusal(outbound, dispatch, base);
|
|
39344
|
+
if (refusal !== undefined) {
|
|
39345
|
+
answerRefusal(response, METHOD_REFUSED, refusal);
|
|
39346
|
+
return;
|
|
39347
|
+
}
|
|
39348
|
+
const body = method === "GET" ? undefined : await wholeBody(request);
|
|
39349
|
+
const url = outbound.href;
|
|
39350
|
+
const headers = forwardedHeaders(request.headers);
|
|
39351
|
+
const upstream = new AbortController;
|
|
39352
|
+
response.once("close", () => {
|
|
39353
|
+
if (!response.writableFinished)
|
|
39354
|
+
upstream.abort();
|
|
39355
|
+
});
|
|
39356
|
+
const send = async () => {
|
|
39357
|
+
let presented;
|
|
39358
|
+
try {
|
|
39359
|
+
presented = await run.config.credential.headers(method, url, undefined, AbortSignal.any([AbortSignal.timeout(DISPATCH_TOOL_DEADLINE_MS), upstream.signal]));
|
|
39360
|
+
} catch (error) {
|
|
39361
|
+
throw new TradeRefused(messageFor(error));
|
|
39362
|
+
}
|
|
39363
|
+
const token = (presented.Authorization ?? "").replace(/^DPoP /, "");
|
|
39364
|
+
const fresh = !tally.tokens.has(token);
|
|
39365
|
+
tally.tokens.add(token);
|
|
39366
|
+
const answer = await fetch(url, {
|
|
39367
|
+
method,
|
|
39368
|
+
headers: { ...headers, ...presented },
|
|
39369
|
+
...body === undefined ? {} : { body },
|
|
39370
|
+
redirect: "manual",
|
|
39371
|
+
decompress: false,
|
|
39372
|
+
signal: upstream.signal
|
|
39373
|
+
});
|
|
39374
|
+
tally.requests += 1;
|
|
39375
|
+
return { presented, answer, fresh };
|
|
39376
|
+
};
|
|
39377
|
+
let sent;
|
|
39378
|
+
try {
|
|
39379
|
+
sent = await send();
|
|
39380
|
+
if (await tokenNotLive(sent.answer)) {
|
|
39381
|
+
run.config.credential.stale?.(undefined, sent.presented);
|
|
39382
|
+
await sent.answer.body?.cancel();
|
|
39383
|
+
sent = await send();
|
|
39384
|
+
if (sent.fresh)
|
|
39385
|
+
tally.renewed += 1;
|
|
39386
|
+
}
|
|
39387
|
+
} catch (error) {
|
|
39388
|
+
if (upstream.signal.aborted)
|
|
39389
|
+
return;
|
|
39390
|
+
if (error instanceof TradeRefused) {
|
|
39391
|
+
answerRefusal(response, TRADE_REFUSED, error.message);
|
|
39392
|
+
return;
|
|
39393
|
+
}
|
|
39394
|
+
answerRefusal(response, DISPATCH_UNREACHABLE, `Dispatch at ${run.config.url} did not answer: ${messageFor(error)}`);
|
|
39395
|
+
return;
|
|
39396
|
+
}
|
|
39397
|
+
await giveBack(sent.answer, response);
|
|
39398
|
+
}
|
|
39399
|
+
async function giveBack(answer, response) {
|
|
39400
|
+
response.writeHead(answer.status, answeredHeaders(answer.headers));
|
|
39401
|
+
if (answer.body === null) {
|
|
39402
|
+
response.end();
|
|
39403
|
+
return;
|
|
39404
|
+
}
|
|
39405
|
+
response.flushHeaders();
|
|
39406
|
+
for await (const chunk of answer.body) {
|
|
39407
|
+
if (response.destroyed)
|
|
39408
|
+
return;
|
|
39409
|
+
if (!response.write(chunk))
|
|
39410
|
+
await drained(response);
|
|
39411
|
+
}
|
|
39412
|
+
response.end();
|
|
39413
|
+
}
|
|
39414
|
+
function drained(response) {
|
|
39415
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
39416
|
+
const done = () => {
|
|
39417
|
+
response.off("drain", done);
|
|
39418
|
+
response.off("close", done);
|
|
39419
|
+
resolve();
|
|
39420
|
+
};
|
|
39421
|
+
response.on("drain", done);
|
|
39422
|
+
response.on("close", done);
|
|
39423
|
+
return promise;
|
|
39424
|
+
}
|
|
39425
|
+
|
|
38871
39426
|
// ../envoy-client/src/dispatch-session-state.ts
|
|
38872
39427
|
import { createHash as createHash3 } from "crypto";
|
|
38873
39428
|
import {
|
|
@@ -38879,7 +39434,7 @@ import {
|
|
|
38879
39434
|
readdirSync as readdirSync2,
|
|
38880
39435
|
readFileSync as readFileSync5,
|
|
38881
39436
|
readSync as readSync2,
|
|
38882
|
-
rmSync as
|
|
39437
|
+
rmSync as rmSync4,
|
|
38883
39438
|
statSync as statSync2,
|
|
38884
39439
|
writeFileSync as writeFileSync3
|
|
38885
39440
|
} from "fs";
|
|
@@ -39004,7 +39559,7 @@ function pruneSessions(root, now) {
|
|
|
39004
39559
|
try {
|
|
39005
39560
|
const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
|
|
39006
39561
|
if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {
|
|
39007
|
-
|
|
39562
|
+
rmSync4(dir, { recursive: true, force: true });
|
|
39008
39563
|
}
|
|
39009
39564
|
} catch (error) {
|
|
39010
39565
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
@@ -39769,6 +40324,65 @@ function commandHost(env, nearest) {
|
|
|
39769
40324
|
return env.DISPATCH_HOST;
|
|
39770
40325
|
return env.CLAUDE_CODE_CHILD_SESSION === "1" ? "claude" : undefined;
|
|
39771
40326
|
}
|
|
40327
|
+
async function runProxyCommand(rest, env, rawEnv, io, hostName) {
|
|
40328
|
+
const say = (text) => io.stderr(`${text}
|
|
40329
|
+
`);
|
|
40330
|
+
const parsed = parseProxyArgv(rest, io.cwd);
|
|
40331
|
+
if (parsed.kind === "help") {
|
|
40332
|
+
io.stdout(proxyHelp());
|
|
40333
|
+
return OK;
|
|
40334
|
+
}
|
|
40335
|
+
if (parsed.kind === "refused") {
|
|
40336
|
+
say(`dispatch proxy: ${parsed.problem} Run dispatch proxy --help.`);
|
|
40337
|
+
return USAGE;
|
|
40338
|
+
}
|
|
40339
|
+
const { dryRun, socket, command } = parsed;
|
|
40340
|
+
const cannotStart = (text) => {
|
|
40341
|
+
say(text);
|
|
40342
|
+
if (!dryRun)
|
|
40343
|
+
say(proxyExitLine(0, 0, 0));
|
|
40344
|
+
return USAGE;
|
|
40345
|
+
};
|
|
40346
|
+
const hosted = hostSessionDirectory(hostName(), env);
|
|
40347
|
+
if ("problem" in hosted)
|
|
40348
|
+
return cannotStart(hosted.problem);
|
|
40349
|
+
const { sessionId, file } = hosted;
|
|
40350
|
+
if ((env.DISPATCH_TOKEN_BROKER ?? "").trim() !== "1") {
|
|
40351
|
+
return cannotStart("dispatch proxy: DISPATCH_TOKEN_BROKER is not 1, so this session holds no broker token for the proxy to serve with. The proxy runs only where the deployment trades this session's Dispatch credential at the secrets broker, and never with a bearer.");
|
|
40352
|
+
}
|
|
40353
|
+
const resolved = await hostedDispatch(file, env, { cwd: io.cwd, session: sessionId });
|
|
40354
|
+
for (const line of resolved.warnings)
|
|
40355
|
+
say(line);
|
|
40356
|
+
if ("problem" in resolved)
|
|
40357
|
+
return cannotStart(resolved.problem);
|
|
40358
|
+
const { config } = resolved;
|
|
40359
|
+
if (config.credential.scheme !== "DPoP") {
|
|
40360
|
+
return cannotStart("dispatch proxy: this session's Dispatch credential is not a DPoP-bound broker token, and the proxy serves only with one.");
|
|
40361
|
+
}
|
|
40362
|
+
if (dryRun) {
|
|
40363
|
+
const taken = socketPathTaken(socket);
|
|
40364
|
+
if (taken !== undefined)
|
|
40365
|
+
return cannotStart(taken);
|
|
40366
|
+
io.stdout([`Dispatch server: ${config.url}`, `Session: ${sessionId}`, `Socket: ${socket}`, ""].join(`
|
|
40367
|
+
`));
|
|
40368
|
+
return OK;
|
|
40369
|
+
}
|
|
40370
|
+
const commandEnv = {};
|
|
40371
|
+
for (const [name, value] of Object.entries(rawEnv)) {
|
|
40372
|
+
if (value !== undefined)
|
|
40373
|
+
commandEnv[name] = value;
|
|
40374
|
+
}
|
|
40375
|
+
return await runDispatchProxy({
|
|
40376
|
+
socket,
|
|
40377
|
+
command,
|
|
40378
|
+
env,
|
|
40379
|
+
commandEnv,
|
|
40380
|
+
cwd: io.cwd,
|
|
40381
|
+
config,
|
|
40382
|
+
sessionId,
|
|
40383
|
+
stderr: (text) => io.stderr(text)
|
|
40384
|
+
});
|
|
40385
|
+
}
|
|
39772
40386
|
async function runDispatchCli(argv, rawEnv, io) {
|
|
39773
40387
|
const held = [];
|
|
39774
40388
|
const print = (text) => {
|
|
@@ -39793,7 +40407,7 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
39793
40407
|
if (value !== undefined && value !== "")
|
|
39794
40408
|
env[name] = value;
|
|
39795
40409
|
}
|
|
39796
|
-
if (argv[0] ===
|
|
40410
|
+
if (argv[0] === LOGIN_COMMAND) {
|
|
39797
40411
|
return await loginCommand(argv.slice(1), env, {
|
|
39798
40412
|
print,
|
|
39799
40413
|
fetchImpl: io.fetchImpl,
|
|
@@ -39824,6 +40438,9 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
39824
40438
|
ledgerRefusal(text, tool, askgate);
|
|
39825
40439
|
return code;
|
|
39826
40440
|
};
|
|
40441
|
+
if (argv[0] === PROXY_COMMAND) {
|
|
40442
|
+
return await runProxyCommand(argv.slice(1), env, rawEnv, io, ledgerHost);
|
|
40443
|
+
}
|
|
39827
40444
|
let parsed;
|
|
39828
40445
|
try {
|
|
39829
40446
|
parsed = parseCommand(argv, io);
|
|
@@ -39900,16 +40517,10 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
39900
40517
|
return REFUSED;
|
|
39901
40518
|
}
|
|
39902
40519
|
}
|
|
39903
|
-
const hosted =
|
|
40520
|
+
const hosted = hostSessionDirectory(ledgerHost(), env);
|
|
39904
40521
|
if ("problem" in hosted)
|
|
39905
40522
|
return refuse(hosted.problem, USAGE, parsed.tool);
|
|
39906
|
-
const { host, sessionId, file } = hosted;
|
|
39907
|
-
let dir;
|
|
39908
|
-
try {
|
|
39909
|
-
dir = sessionDirectory(env, sessionId);
|
|
39910
|
-
} catch (error) {
|
|
39911
|
-
return refuse(messageFor(error), USAGE, parsed.tool);
|
|
39912
|
-
}
|
|
40523
|
+
const { host, sessionId, file, dir } = hosted;
|
|
39913
40524
|
if (parsed.dryRun && !dryRunAsksDispatch(parsed.tool, parsed.args)) {
|
|
39914
40525
|
const resolved = await sessionDispatchSettings(file, env, {
|
|
39915
40526
|
cwd: io.cwd,
|
|
@@ -40012,7 +40623,7 @@ ${result.text}`);
|
|
|
40012
40623
|
for (const file of fileOperands(argv)) {
|
|
40013
40624
|
let bytes;
|
|
40014
40625
|
try {
|
|
40015
|
-
const fd = openSync4(operandPath(io.cwd, file),
|
|
40626
|
+
const fd = openSync4(operandPath(io.cwd, file), constants5.O_RDONLY | constants5.O_NONBLOCK);
|
|
40016
40627
|
try {
|
|
40017
40628
|
if (fstatSync3(fd).isFile())
|
|
40018
40629
|
bytes = readFileSync7(fd);
|
|
@@ -40122,7 +40733,7 @@ ${result.text}`);
|
|
|
40122
40733
|
entry = { tool, details: result.details };
|
|
40123
40734
|
code = result.refused === true ? REFUSED : OK;
|
|
40124
40735
|
} catch (error) {
|
|
40125
|
-
text = (parentStatusConflictLines(error, tool, args
|
|
40736
|
+
text = (parentStatusConflictLines(error, tool, args) ?? [messageFor(error)]).join(`
|
|
40126
40737
|
`);
|
|
40127
40738
|
if (error instanceof DispatchWriteLandedError) {
|
|
40128
40739
|
entry = { tool, details: { landed_without_answer: error.code } };
|