claude-use 11.90.0 → 12.0.1
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/README.md +1 -0
- package/dist/cli.cjs +1058 -620
- package/dist/index.cjs +1091 -780
- package/dist/index.mjs +1060 -748
- package/dist/types/index.d.ts +152 -42
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5341,46 +5341,46 @@ function acceptsNull(path55) {
|
|
|
5341
5341
|
return StatuslineSchema.safeParse(layer).success;
|
|
5342
5342
|
}
|
|
5343
5343
|
function keyOf(path55, declared) {
|
|
5344
|
-
const optional = declared instanceof
|
|
5344
|
+
const optional = declared instanceof import_zod11.z.ZodOptional;
|
|
5345
5345
|
const leaf = optional ? declared.unwrap() : declared;
|
|
5346
5346
|
const common = { path: path55.join("."), description: declared.description ?? "", defaultValue: valueAt(STATUSLINE_DEFAULTS, path55), optional, unsettable: acceptsNull(path55) };
|
|
5347
|
-
if (leaf instanceof
|
|
5347
|
+
if (leaf instanceof import_zod11.z.ZodNumber) {
|
|
5348
5348
|
return { ...common, kind: "integer", choices: [] };
|
|
5349
5349
|
}
|
|
5350
|
-
if (leaf instanceof
|
|
5350
|
+
if (leaf instanceof import_zod11.z.ZodBoolean) {
|
|
5351
5351
|
return { ...common, kind: "boolean", choices: [] };
|
|
5352
5352
|
}
|
|
5353
|
-
if (leaf instanceof
|
|
5353
|
+
if (leaf instanceof import_zod11.z.ZodString) {
|
|
5354
5354
|
return { ...common, kind: "text", choices: [] };
|
|
5355
5355
|
}
|
|
5356
|
-
if (leaf instanceof
|
|
5356
|
+
if (leaf instanceof import_zod11.z.ZodUnion) {
|
|
5357
5357
|
return { ...common, kind: "colour", choices: [...STATUSLINE_COLOUR_NAMES] };
|
|
5358
5358
|
}
|
|
5359
|
-
if (leaf instanceof
|
|
5359
|
+
if (leaf instanceof import_zod11.z.ZodEnum) {
|
|
5360
5360
|
return { ...common, kind: "choice", choices: Object.values(leaf.enum).map(String) };
|
|
5361
5361
|
}
|
|
5362
|
-
if (leaf instanceof
|
|
5362
|
+
if (leaf instanceof import_zod11.z.ZodArray && leaf.element instanceof import_zod11.z.ZodEnum) {
|
|
5363
5363
|
return { ...common, kind: "list", choices: Object.values(leaf.element.enum).map(String) };
|
|
5364
5364
|
}
|
|
5365
|
-
if (leaf instanceof
|
|
5365
|
+
if (leaf instanceof import_zod11.z.ZodArray && leaf.element instanceof import_zod11.z.ZodArray && leaf.element.element instanceof import_zod11.z.ZodEnum) {
|
|
5366
5366
|
return { ...common, kind: "groups", choices: Object.values(leaf.element.element.enum).map(String) };
|
|
5367
5367
|
}
|
|
5368
|
-
if (leaf instanceof
|
|
5368
|
+
if (leaf instanceof import_zod11.z.ZodArray && leaf.element instanceof import_zod11.z.ZodString) {
|
|
5369
5369
|
return { ...common, kind: "textList", choices: [] };
|
|
5370
5370
|
}
|
|
5371
5371
|
throw new TypeError(`statusline setting ${path55.join(".")} has a kind the key listing does not describe`);
|
|
5372
5372
|
}
|
|
5373
5373
|
function walk(shape, prefix) {
|
|
5374
|
-
return Object.entries(shape).flatMap(([name, schema]) => schema instanceof
|
|
5374
|
+
return Object.entries(shape).flatMap(([name, schema]) => schema instanceof import_zod11.z.ZodObject ? walk(schema.shape, [...prefix, name]) : [keyOf([...prefix, name], schema)]);
|
|
5375
5375
|
}
|
|
5376
5376
|
function statuslineKeys() {
|
|
5377
5377
|
return walk(ResolvedStatuslineSchema.shape, []);
|
|
5378
5378
|
}
|
|
5379
|
-
var
|
|
5379
|
+
var import_zod11;
|
|
5380
5380
|
var init_keys = __esm({
|
|
5381
5381
|
"src/statusline/keys.ts"() {
|
|
5382
5382
|
"use strict";
|
|
5383
|
-
|
|
5383
|
+
import_zod11 = require("zod");
|
|
5384
5384
|
init_statusline();
|
|
5385
5385
|
}
|
|
5386
5386
|
});
|
|
@@ -5788,164 +5788,164 @@ var init_poolStore = __esm({
|
|
|
5788
5788
|
});
|
|
5789
5789
|
|
|
5790
5790
|
// src/usage/schema.ts
|
|
5791
|
-
var
|
|
5791
|
+
var import_zod12, USAGE_SCHEMA_VERSION, VersionSchema, InstantSchema, CLIENT_SESSION_ID_PATTERN, TokenCountSchema, TokenUsageSchema, LIMIT_KINDS, LimitClassificationSchema, UsageRecordSchema, QuotaWindowSchema, ExtraUsageSpendSchema, UnifiedRateLimitSchema, RateLimitStateSchema, LimitEventSchema, ProviderQuotaWindowSchema, ProviderAccountSchema, ProviderQuotaSchema, ProviderUsageStateSchema, AccountMetadataSchema, UsageSnapshotSchema;
|
|
5792
5792
|
var init_schema2 = __esm({
|
|
5793
5793
|
"src/usage/schema.ts"() {
|
|
5794
5794
|
"use strict";
|
|
5795
|
-
|
|
5795
|
+
import_zod12 = require("zod");
|
|
5796
5796
|
USAGE_SCHEMA_VERSION = 1;
|
|
5797
|
-
VersionSchema =
|
|
5798
|
-
InstantSchema =
|
|
5797
|
+
VersionSchema = import_zod12.z.literal(USAGE_SCHEMA_VERSION);
|
|
5798
|
+
InstantSchema = import_zod12.z.iso.datetime();
|
|
5799
5799
|
CLIENT_SESSION_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
5800
|
-
TokenCountSchema =
|
|
5801
|
-
TokenUsageSchema =
|
|
5800
|
+
TokenCountSchema = import_zod12.z.number().int().nonnegative();
|
|
5801
|
+
TokenUsageSchema = import_zod12.z.strictObject({
|
|
5802
5802
|
inputTokens: TokenCountSchema.optional(),
|
|
5803
5803
|
outputTokens: TokenCountSchema.optional(),
|
|
5804
5804
|
cacheCreationInputTokens: TokenCountSchema.optional(),
|
|
5805
5805
|
cacheReadInputTokens: TokenCountSchema.optional()
|
|
5806
5806
|
});
|
|
5807
5807
|
LIMIT_KINDS = ["rate-limited", "quota-exhausted"];
|
|
5808
|
-
LimitClassificationSchema =
|
|
5809
|
-
kind:
|
|
5808
|
+
LimitClassificationSchema = import_zod12.z.strictObject({
|
|
5809
|
+
kind: import_zod12.z.enum(LIMIT_KINDS),
|
|
5810
5810
|
/** Seconds to wait before retrying, from the response's `retry-after`. */
|
|
5811
|
-
retryAfterSeconds:
|
|
5811
|
+
retryAfterSeconds: import_zod12.z.number().nonnegative().optional(),
|
|
5812
5812
|
/** When the limiting window resets, from the upstream's own reset header. */
|
|
5813
5813
|
resetAt: InstantSchema.optional(),
|
|
5814
5814
|
/** The window the upstream named as the binding one (`anthropic-ratelimit-unified-representative-claim`), such as `five_hour` or `seven_day`. */
|
|
5815
|
-
window:
|
|
5815
|
+
window: import_zod12.z.string().optional(),
|
|
5816
5816
|
/** The signals the classification rests on, each `<name>=<value>` from a response header or the error body's `type` or `code`. Never the error message. */
|
|
5817
|
-
evidence:
|
|
5817
|
+
evidence: import_zod12.z.array(import_zod12.z.string())
|
|
5818
5818
|
});
|
|
5819
|
-
UsageRecordSchema =
|
|
5819
|
+
UsageRecordSchema = import_zod12.z.strictObject({
|
|
5820
5820
|
schemaVersion: VersionSchema,
|
|
5821
5821
|
/** When the front door received the request. */
|
|
5822
5822
|
at: InstantSchema,
|
|
5823
5823
|
/** The id of the launching identity (the directory it is stored in, which a rename of its name keeps), when the launch resolved one: what the session's identity header carries. */
|
|
5824
|
-
identity:
|
|
5824
|
+
identity: import_zod12.z.string().optional(),
|
|
5825
5825
|
/** `anthropic` for an OAuth session's request to Claude Code's own API, otherwise the provider's name. */
|
|
5826
|
-
provider:
|
|
5826
|
+
provider: import_zod12.z.string(),
|
|
5827
5827
|
/** The launch's session id, generated per launch. */
|
|
5828
|
-
sessionId:
|
|
5828
|
+
sessionId: import_zod12.z.string().optional(),
|
|
5829
5829
|
/** The client's own id for the conversation, from the request's `x-claude-code-session-id` header: it changes when the conversation is cleared inside one launch, which `sessionId` does not, so it is what ties a request to the client's per-conversation figures. Absent when the client sent none. */
|
|
5830
|
-
clientSessionId:
|
|
5830
|
+
clientSessionId: import_zod12.z.string().regex(CLIENT_SESSION_ID_PATTERN).optional(),
|
|
5831
5831
|
/** The project the launch ran in (its git repository root), when the launch sent one: headroom launches do. */
|
|
5832
|
-
project:
|
|
5832
|
+
project: import_zod12.z.string().optional(),
|
|
5833
5833
|
/** Whether the request crossed headroom on its way upstream. Absent on a record written before the door recorded it, and false when the request went direct. */
|
|
5834
|
-
viaHeadroom:
|
|
5834
|
+
viaHeadroom: import_zod12.z.boolean().optional(),
|
|
5835
5835
|
/** The front-door route that served the request. */
|
|
5836
|
-
route:
|
|
5837
|
-
method:
|
|
5836
|
+
route: import_zod12.z.string(),
|
|
5837
|
+
method: import_zod12.z.string(),
|
|
5838
5838
|
/** The API path as the upstream sees it (`/v1/messages`), without the provider prefix or a query string. */
|
|
5839
|
-
endpoint:
|
|
5839
|
+
endpoint: import_zod12.z.string(),
|
|
5840
5840
|
/** The model the response named. */
|
|
5841
|
-
model:
|
|
5841
|
+
model: import_zod12.z.string().optional(),
|
|
5842
5842
|
/** The model the session requested when a routing layer chose a different model, or when no response model was available to compare it with. Absent when the response confirms that the requested name was served unchanged. */
|
|
5843
|
-
requestedModel:
|
|
5843
|
+
requestedModel: import_zod12.z.string().optional(),
|
|
5844
5844
|
/** The distinct providers the choice could have landed on, present only when there was more than one, so a reader can tell a choice that crossed providers from one that stayed inside a single provider's lineup. */
|
|
5845
|
-
candidateProviders:
|
|
5846
|
-
status:
|
|
5845
|
+
candidateProviders: import_zod12.z.array(import_zod12.z.string()).optional(),
|
|
5846
|
+
status: import_zod12.z.number().int(),
|
|
5847
5847
|
/** Milliseconds from the request's arrival to its response head. */
|
|
5848
|
-
latencyMs:
|
|
5848
|
+
latencyMs: import_zod12.z.number().int().nonnegative(),
|
|
5849
5849
|
/** Milliseconds from the request's arrival to the end of its response body. */
|
|
5850
|
-
durationMs:
|
|
5850
|
+
durationMs: import_zod12.z.number().int().nonnegative(),
|
|
5851
5851
|
/** Whether the client received the whole body. */
|
|
5852
|
-
outcome:
|
|
5852
|
+
outcome: import_zod12.z.enum(["completed", "aborted"]),
|
|
5853
5853
|
usage: TokenUsageSchema.optional(),
|
|
5854
5854
|
/** The response's quota and rate-limit headers, by name (see `isRateLimitHeader`). */
|
|
5855
|
-
rateLimitHeaders:
|
|
5855
|
+
rateLimitHeaders: import_zod12.z.record(import_zod12.z.string(), import_zod12.z.string()).optional(),
|
|
5856
5856
|
limit: LimitClassificationSchema.optional(),
|
|
5857
5857
|
/** The upstream's request id (`request-id`), for matching a record to the provider's own logs. */
|
|
5858
|
-
requestId:
|
|
5858
|
+
requestId: import_zod12.z.string().optional()
|
|
5859
5859
|
});
|
|
5860
|
-
QuotaWindowSchema =
|
|
5860
|
+
QuotaWindowSchema = import_zod12.z.strictObject({
|
|
5861
5861
|
/** The fraction of the window used, as the upstream reports it (0 to 1). */
|
|
5862
|
-
utilization:
|
|
5862
|
+
utilization: import_zod12.z.number().nonnegative().optional(),
|
|
5863
5863
|
resetsAt: InstantSchema.optional(),
|
|
5864
5864
|
/** The window's own status (`allowed`, `allowed_warning`, `rejected`). */
|
|
5865
|
-
status:
|
|
5865
|
+
status: import_zod12.z.string().optional(),
|
|
5866
5866
|
/** The fraction of the window's grace allowance used, while the upstream reports the window in grace (the five-hour window only). Requests are served beyond the window's own full mark while it grows, but refusals have been seen at a small value, so nothing ranks on it. */
|
|
5867
|
-
graceUtilization:
|
|
5867
|
+
graceUtilization: import_zod12.z.number().nonnegative().optional()
|
|
5868
5868
|
});
|
|
5869
|
-
ExtraUsageSpendSchema =
|
|
5869
|
+
ExtraUsageSpendSchema = import_zod12.z.strictObject({
|
|
5870
5870
|
/** Spent so far in the allowance's period, in the currency's minor units (pence, cents). */
|
|
5871
|
-
usedMinor:
|
|
5871
|
+
usedMinor: import_zod12.z.number().nonnegative(),
|
|
5872
5872
|
/** The allowance's cap in the same units, when it has one. */
|
|
5873
|
-
limitMinor:
|
|
5873
|
+
limitMinor: import_zod12.z.number().nonnegative().optional(),
|
|
5874
5874
|
/** The ISO 4217 currency code. */
|
|
5875
|
-
currency:
|
|
5875
|
+
currency: import_zod12.z.string()
|
|
5876
5876
|
});
|
|
5877
|
-
UnifiedRateLimitSchema =
|
|
5877
|
+
UnifiedRateLimitSchema = import_zod12.z.strictObject({
|
|
5878
5878
|
/** The overall status: `allowed`, `allowed_warning` or `rejected`. */
|
|
5879
|
-
status:
|
|
5879
|
+
status: import_zod12.z.string().optional(),
|
|
5880
5880
|
fiveHour: QuotaWindowSchema.optional(),
|
|
5881
5881
|
sevenDay: QuotaWindowSchema.optional(),
|
|
5882
5882
|
/** The weekly window of the models whose usage may continue as extra usage (`7d_oi`), reported by some plans beside the all-models weekly window. */
|
|
5883
5883
|
sevenDayOverageIncluded: QuotaWindowSchema.optional(),
|
|
5884
5884
|
/** The window that currently binds. */
|
|
5885
|
-
representativeClaim:
|
|
5885
|
+
representativeClaim: import_zod12.z.string().optional(),
|
|
5886
5886
|
/** When the binding window resets. */
|
|
5887
5887
|
resetAt: InstantSchema.optional(),
|
|
5888
5888
|
/** Whether usage beyond the plan (extra usage) is available: `allowed` or `rejected`. */
|
|
5889
|
-
overageStatus:
|
|
5889
|
+
overageStatus: import_zod12.z.string().optional(),
|
|
5890
5890
|
/** The fraction of the extra-usage allowance used, as the upstream reports it (0 to 1). An account with no plan windows, such as an Enterprise one, is metered by this alone. */
|
|
5891
|
-
overageUtilization:
|
|
5891
|
+
overageUtilization: import_zod12.z.number().nonnegative().optional(),
|
|
5892
5892
|
/** When the extra-usage allowance resets. */
|
|
5893
5893
|
overageResetsAt: InstantSchema.optional(),
|
|
5894
5894
|
/** Why extra usage is unavailable, as the upstream names it (`out_of_credits`, for one). */
|
|
5895
|
-
overageDisabledReason:
|
|
5895
|
+
overageDisabledReason: import_zod12.z.string().optional(),
|
|
5896
5896
|
/** Whether the response was served on extra usage, as the upstream states it. */
|
|
5897
|
-
overageInUse:
|
|
5897
|
+
overageInUse: import_zod12.z.boolean().optional(),
|
|
5898
5898
|
/** The allowance in money, from the usage endpoint (the response headers state only the fraction). */
|
|
5899
5899
|
extraUsageSpend: ExtraUsageSpendSchema.optional(),
|
|
5900
5900
|
/** True when the upstream offers a fallback while a window is rejected: some requests, by model, are still served, though the rest are refused. */
|
|
5901
|
-
fallbackAvailable:
|
|
5901
|
+
fallbackAvailable: import_zod12.z.boolean().optional()
|
|
5902
5902
|
});
|
|
5903
|
-
RateLimitStateSchema =
|
|
5903
|
+
RateLimitStateSchema = import_zod12.z.strictObject({
|
|
5904
5904
|
observedAt: InstantSchema,
|
|
5905
5905
|
/** Every quota and rate-limit header on that response, by name. */
|
|
5906
|
-
headers:
|
|
5906
|
+
headers: import_zod12.z.record(import_zod12.z.string(), import_zod12.z.string()),
|
|
5907
5907
|
unified: UnifiedRateLimitSchema.optional(),
|
|
5908
5908
|
/** When the usage endpoint last answered that it has no plan windows for the account, which a later response replaces. Its answer leaves the recorded `unified` state alone (a response's headers may be the only source of it), so this alone says the question was asked. */
|
|
5909
5909
|
planWindowsUnavailableAt: InstantSchema.optional()
|
|
5910
5910
|
});
|
|
5911
5911
|
LimitEventSchema = LimitClassificationSchema.extend({
|
|
5912
5912
|
observedAt: InstantSchema,
|
|
5913
|
-
status:
|
|
5913
|
+
status: import_zod12.z.number().int()
|
|
5914
5914
|
});
|
|
5915
|
-
ProviderQuotaWindowSchema =
|
|
5915
|
+
ProviderQuotaWindowSchema = import_zod12.z.strictObject({
|
|
5916
5916
|
/** What the window measures, in the provider's terms (`tokens`, `tool-calls`). */
|
|
5917
|
-
measures:
|
|
5917
|
+
measures: import_zod12.z.string(),
|
|
5918
5918
|
/** The window's length in milliseconds, when the provider's unit is one this project knows; absent for an unrecognised unit, with `period` carrying the raw code. */
|
|
5919
|
-
periodMs:
|
|
5919
|
+
periodMs: import_zod12.z.number().int().positive().optional(),
|
|
5920
5920
|
/** The provider's own description of the period when `periodMs` could not be derived, such as `unit 4 x 1`. */
|
|
5921
|
-
period:
|
|
5921
|
+
period: import_zod12.z.string().optional(),
|
|
5922
5922
|
/** The fraction of the window used (0 to 1). */
|
|
5923
|
-
utilization:
|
|
5923
|
+
utilization: import_zod12.z.number().nonnegative(),
|
|
5924
5924
|
resetsAt: InstantSchema.optional(),
|
|
5925
5925
|
/** Absolute counts, when the provider reports them for this window. */
|
|
5926
|
-
limit:
|
|
5927
|
-
used:
|
|
5928
|
-
remaining:
|
|
5926
|
+
limit: import_zod12.z.number().nonnegative().optional(),
|
|
5927
|
+
used: import_zod12.z.number().nonnegative().optional(),
|
|
5928
|
+
remaining: import_zod12.z.number().nonnegative().optional()
|
|
5929
5929
|
});
|
|
5930
|
-
ProviderAccountSchema =
|
|
5931
|
-
email:
|
|
5932
|
-
accountId:
|
|
5930
|
+
ProviderAccountSchema = import_zod12.z.strictObject({
|
|
5931
|
+
email: import_zod12.z.string().optional(),
|
|
5932
|
+
accountId: import_zod12.z.string().optional()
|
|
5933
5933
|
});
|
|
5934
|
-
ProviderQuotaSchema =
|
|
5934
|
+
ProviderQuotaSchema = import_zod12.z.strictObject({
|
|
5935
5935
|
observedAt: InstantSchema,
|
|
5936
5936
|
/** Which usage endpoint produced it (`z.ai`). */
|
|
5937
|
-
source:
|
|
5937
|
+
source: import_zod12.z.string(),
|
|
5938
5938
|
/** The subscription level the endpoint reports, when it does. */
|
|
5939
|
-
level:
|
|
5939
|
+
level: import_zod12.z.string().optional(),
|
|
5940
5940
|
/** The account the provider's credential belongs to, when its endpoint reports it. */
|
|
5941
5941
|
account: ProviderAccountSchema.optional(),
|
|
5942
|
-
windows:
|
|
5942
|
+
windows: import_zod12.z.array(ProviderQuotaWindowSchema)
|
|
5943
5943
|
});
|
|
5944
|
-
ProviderUsageStateSchema =
|
|
5944
|
+
ProviderUsageStateSchema = import_zod12.z.strictObject({
|
|
5945
5945
|
/** When the provider last served a request for the identity through the front door. Absent while the state holds only a rate-limit state fetched from the provider's usage endpoint, for an identity that has made no request. */
|
|
5946
5946
|
lastRequestAt: InstantSchema.optional(),
|
|
5947
|
-
lastStatus:
|
|
5948
|
-
lastModel:
|
|
5947
|
+
lastStatus: import_zod12.z.number().int().optional(),
|
|
5948
|
+
lastModel: import_zod12.z.string().optional(),
|
|
5949
5949
|
/** The latest rate-limit state, from the last response that carried any rate-limit header. */
|
|
5950
5950
|
rateLimit: RateLimitStateSchema.optional(),
|
|
5951
5951
|
/** The latest classified refusal. It stays after later successes, so a reader compares its `resetAt` (or `observedAt` plus `retryAfterSeconds`) with the current time. */
|
|
@@ -5953,31 +5953,31 @@ var init_schema2 = __esm({
|
|
|
5953
5953
|
/** The latest quota the provider's usage endpoint reported, for providers whose quota is not visible in response headers. */
|
|
5954
5954
|
quota: ProviderQuotaSchema.optional()
|
|
5955
5955
|
});
|
|
5956
|
-
AccountMetadataSchema =
|
|
5957
|
-
accountUuid:
|
|
5958
|
-
emailAddress:
|
|
5959
|
-
displayName:
|
|
5960
|
-
organizationUuid:
|
|
5961
|
-
organizationName:
|
|
5962
|
-
organizationType:
|
|
5963
|
-
organizationRole:
|
|
5964
|
-
workspaceRole:
|
|
5965
|
-
billingType:
|
|
5966
|
-
seatTier:
|
|
5967
|
-
organizationRateLimitTier:
|
|
5968
|
-
userRateLimitTier:
|
|
5969
|
-
hasExtraUsageEnabled:
|
|
5970
|
-
subscriptionCreatedAt:
|
|
5971
|
-
accountCreatedAt:
|
|
5956
|
+
AccountMetadataSchema = import_zod12.z.strictObject({
|
|
5957
|
+
accountUuid: import_zod12.z.string().optional(),
|
|
5958
|
+
emailAddress: import_zod12.z.string().optional(),
|
|
5959
|
+
displayName: import_zod12.z.string().optional(),
|
|
5960
|
+
organizationUuid: import_zod12.z.string().optional(),
|
|
5961
|
+
organizationName: import_zod12.z.string().optional(),
|
|
5962
|
+
organizationType: import_zod12.z.string().optional(),
|
|
5963
|
+
organizationRole: import_zod12.z.string().optional(),
|
|
5964
|
+
workspaceRole: import_zod12.z.string().optional(),
|
|
5965
|
+
billingType: import_zod12.z.string().optional(),
|
|
5966
|
+
seatTier: import_zod12.z.string().optional(),
|
|
5967
|
+
organizationRateLimitTier: import_zod12.z.string().optional(),
|
|
5968
|
+
userRateLimitTier: import_zod12.z.string().optional(),
|
|
5969
|
+
hasExtraUsageEnabled: import_zod12.z.boolean().optional(),
|
|
5970
|
+
subscriptionCreatedAt: import_zod12.z.string().optional(),
|
|
5971
|
+
accountCreatedAt: import_zod12.z.string().optional()
|
|
5972
5972
|
});
|
|
5973
|
-
UsageSnapshotSchema =
|
|
5973
|
+
UsageSnapshotSchema = import_zod12.z.strictObject({
|
|
5974
5974
|
schemaVersion: VersionSchema,
|
|
5975
|
-
identity:
|
|
5975
|
+
identity: import_zod12.z.string(),
|
|
5976
5976
|
updatedAt: InstantSchema,
|
|
5977
5977
|
/** The identity's account metadata as of `updatedAt`. */
|
|
5978
5978
|
account: AccountMetadataSchema.optional(),
|
|
5979
5979
|
/** Latest state per provider, keyed by provider name (`anthropic` for OAuth sessions). */
|
|
5980
|
-
providers:
|
|
5980
|
+
providers: import_zod12.z.record(import_zod12.z.string(), ProviderUsageStateSchema)
|
|
5981
5981
|
});
|
|
5982
5982
|
}
|
|
5983
5983
|
});
|
|
@@ -6412,19 +6412,19 @@ function formatCachedCredentialState(state) {
|
|
|
6412
6412
|
}
|
|
6413
6413
|
return state.status === "fresh" ? `${age}, expires in ${formatAge(state.expiresInMs)}` : `${age}, expired ${formatAge(-state.expiresInMs)} ago`;
|
|
6414
6414
|
}
|
|
6415
|
-
var
|
|
6415
|
+
var import_zod13, MS_PER_UNIT, CachedCredentialSchema, KEYCHAIN_CACHE_SERVICE, KEYCHAIN_ITEM_NOT_FOUND_STATUS;
|
|
6416
6416
|
var init_credentialCache = __esm({
|
|
6417
6417
|
"src/credentialCache.ts"() {
|
|
6418
6418
|
"use strict";
|
|
6419
|
-
|
|
6419
|
+
import_zod13 = require("zod");
|
|
6420
6420
|
init_schema();
|
|
6421
6421
|
init_preflight();
|
|
6422
6422
|
MS_PER_UNIT = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
|
|
6423
|
-
CachedCredentialSchema =
|
|
6424
|
-
token:
|
|
6425
|
-
fetchedAt:
|
|
6423
|
+
CachedCredentialSchema = import_zod13.z.strictObject({
|
|
6424
|
+
token: import_zod13.z.string().min(1),
|
|
6425
|
+
fetchedAt: import_zod13.z.number().int().nonnegative(),
|
|
6426
6426
|
source: CredentialSourceSchema,
|
|
6427
|
-
owner:
|
|
6427
|
+
owner: import_zod13.z.string().min(1).optional()
|
|
6428
6428
|
});
|
|
6429
6429
|
KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
|
|
6430
6430
|
KEYCHAIN_ITEM_NOT_FOUND_STATUS = 44;
|
|
@@ -6511,7 +6511,7 @@ function describeCredential(credential) {
|
|
|
6511
6511
|
function cacheKeyOf(params) {
|
|
6512
6512
|
return params.cacheKey ?? params.subject;
|
|
6513
6513
|
}
|
|
6514
|
-
function
|
|
6514
|
+
function isRecord6(value) {
|
|
6515
6515
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6516
6516
|
}
|
|
6517
6517
|
function unpackKeyringToken(raw) {
|
|
@@ -6523,7 +6523,7 @@ function unpackKeyringToken(raw) {
|
|
|
6523
6523
|
const base64Str = trimmed.slice(GO_KEYRING_BASE64_PREFIX.length);
|
|
6524
6524
|
const decoded = Buffer.from(base64Str, "base64").toString("utf8");
|
|
6525
6525
|
const parsed = JSON.parse(decoded);
|
|
6526
|
-
if (
|
|
6526
|
+
if (isRecord6(parsed) && isRecord6(parsed.token)) {
|
|
6527
6527
|
const accessToken = parsed.token.access_token;
|
|
6528
6528
|
if (typeof accessToken === "string" && accessToken.trim() !== "") {
|
|
6529
6529
|
return accessToken.trim();
|
|
@@ -6689,9 +6689,224 @@ var init_blockingSpawn = __esm({
|
|
|
6689
6689
|
}
|
|
6690
6690
|
});
|
|
6691
6691
|
|
|
6692
|
+
// src/headroom/headers.ts
|
|
6693
|
+
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
6694
|
+
const merged = /* @__PURE__ */ new Map();
|
|
6695
|
+
for (const block of existing) {
|
|
6696
|
+
if (block === void 0) {
|
|
6697
|
+
continue;
|
|
6698
|
+
}
|
|
6699
|
+
for (const line of block.split("\n")) {
|
|
6700
|
+
const entry = parseCustomHeaderLine(line);
|
|
6701
|
+
if (entry === void 0) {
|
|
6702
|
+
continue;
|
|
6703
|
+
}
|
|
6704
|
+
merged.set(entry.name, entry.value);
|
|
6705
|
+
}
|
|
6706
|
+
}
|
|
6707
|
+
for (const entry of additions) {
|
|
6708
|
+
merged.set(entry.name, entry.value);
|
|
6709
|
+
}
|
|
6710
|
+
return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
|
|
6711
|
+
}
|
|
6712
|
+
function parseAnthropicCustomHeaders(block) {
|
|
6713
|
+
return block.split("\n").flatMap((line) => {
|
|
6714
|
+
const entry = parseCustomHeaderLine(line);
|
|
6715
|
+
return entry === void 0 ? [] : [entry];
|
|
6716
|
+
});
|
|
6717
|
+
}
|
|
6718
|
+
function withoutAnthropicCustomHeaders(block, remove) {
|
|
6719
|
+
const lines = block.split("\n");
|
|
6720
|
+
const kept = lines.filter((line) => {
|
|
6721
|
+
const entry = parseCustomHeaderLine(line);
|
|
6722
|
+
return entry === void 0 || !remove(entry);
|
|
6723
|
+
});
|
|
6724
|
+
return kept.length === lines.length ? block : kept.join("\n");
|
|
6725
|
+
}
|
|
6726
|
+
function parseCustomHeaderLine(line) {
|
|
6727
|
+
const trimmed = line.trim();
|
|
6728
|
+
if (trimmed === "") {
|
|
6729
|
+
return void 0;
|
|
6730
|
+
}
|
|
6731
|
+
const colon = trimmed.indexOf(":");
|
|
6732
|
+
if (colon <= 0) {
|
|
6733
|
+
return void 0;
|
|
6734
|
+
}
|
|
6735
|
+
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
6736
|
+
}
|
|
6737
|
+
var init_headers = __esm({
|
|
6738
|
+
"src/headroom/headers.ts"() {
|
|
6739
|
+
"use strict";
|
|
6740
|
+
}
|
|
6741
|
+
});
|
|
6742
|
+
|
|
6743
|
+
// src/launcher/injected.ts
|
|
6744
|
+
function listKey(list) {
|
|
6745
|
+
return `${list},appended`;
|
|
6746
|
+
}
|
|
6747
|
+
function digest2(value) {
|
|
6748
|
+
return (0, import_node_crypto7.createHash)("sha256").update(value).digest("hex");
|
|
6749
|
+
}
|
|
6750
|
+
function recordedDigests(env) {
|
|
6751
|
+
const raw = env[INJECTED_ENV];
|
|
6752
|
+
if (raw === void 0 || raw === "") {
|
|
6753
|
+
return {};
|
|
6754
|
+
}
|
|
6755
|
+
let parsed;
|
|
6756
|
+
try {
|
|
6757
|
+
parsed = JSON.parse(raw);
|
|
6758
|
+
} catch {
|
|
6759
|
+
return {};
|
|
6760
|
+
}
|
|
6761
|
+
const result = InjectedSchema.safeParse(parsed);
|
|
6762
|
+
return result.success ? result.data : {};
|
|
6763
|
+
}
|
|
6764
|
+
function recordInjections(base) {
|
|
6765
|
+
const env = { ...base };
|
|
6766
|
+
const digests = new Map(Object.entries(recordedDigests(env)));
|
|
6767
|
+
return {
|
|
6768
|
+
env,
|
|
6769
|
+
set: (name, value) => {
|
|
6770
|
+
env[name] = value;
|
|
6771
|
+
digests.set(name, digest2(value));
|
|
6772
|
+
},
|
|
6773
|
+
unset: (name) => {
|
|
6774
|
+
env[name] = void 0;
|
|
6775
|
+
digests.delete(name);
|
|
6776
|
+
},
|
|
6777
|
+
recordHeaders: (names) => {
|
|
6778
|
+
const block = env[CUSTOM_HEADERS_ENV];
|
|
6779
|
+
for (const entry of block === void 0 ? [] : parseAnthropicCustomHeaders(block)) {
|
|
6780
|
+
if (names.includes(entry.name)) {
|
|
6781
|
+
digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
|
|
6782
|
+
}
|
|
6783
|
+
}
|
|
6784
|
+
},
|
|
6785
|
+
recordBypassHosts: (list, hosts) => {
|
|
6786
|
+
const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
|
|
6787
|
+
if (recordedHosts.length > 0) {
|
|
6788
|
+
digests.set(listKey(list), recordedHosts.join(","));
|
|
6789
|
+
}
|
|
6790
|
+
},
|
|
6791
|
+
finish: () => {
|
|
6792
|
+
if (digests.size > 0) {
|
|
6793
|
+
env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
|
|
6794
|
+
}
|
|
6795
|
+
}
|
|
6796
|
+
};
|
|
6797
|
+
}
|
|
6798
|
+
function withoutRecordedHosts(list, value, digests) {
|
|
6799
|
+
const recordedHosts = new Set(digests[listKey(list)]?.split(","));
|
|
6800
|
+
const entries = value.split(",");
|
|
6801
|
+
const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
|
|
6802
|
+
return kept.length === entries.length ? value : kept.join(",");
|
|
6803
|
+
}
|
|
6804
|
+
function launchEnvironment(env, configDirEscapeHatch) {
|
|
6805
|
+
return configDirEscapeHatch ? env : withoutInjected(env);
|
|
6806
|
+
}
|
|
6807
|
+
function withoutInjected(env) {
|
|
6808
|
+
const digests = recordedDigests(env);
|
|
6809
|
+
const entries = Object.entries(env).flatMap(([name, value]) => {
|
|
6810
|
+
if (name === INJECTED_ENV) {
|
|
6811
|
+
return [];
|
|
6812
|
+
}
|
|
6813
|
+
if (value === void 0) {
|
|
6814
|
+
return [[name, value]];
|
|
6815
|
+
}
|
|
6816
|
+
if (name === CUSTOM_HEADERS_ENV) {
|
|
6817
|
+
const remaining = withoutAnthropicCustomHeaders(value, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
|
|
6818
|
+
return remaining !== value && remaining.trim() === "" ? [] : [[name, remaining]];
|
|
6819
|
+
}
|
|
6820
|
+
if (name === "NO_PROXY" || name === "no_proxy") {
|
|
6821
|
+
const remaining = withoutRecordedHosts(name, value, digests);
|
|
6822
|
+
return remaining !== value && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
|
|
6823
|
+
}
|
|
6824
|
+
return digests[name] === digest2(value) ? [] : [[name, value]];
|
|
6825
|
+
});
|
|
6826
|
+
return Object.fromEntries(entries);
|
|
6827
|
+
}
|
|
6828
|
+
var import_node_crypto7, import_zod14, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
|
|
6829
|
+
var init_injected = __esm({
|
|
6830
|
+
"src/launcher/injected.ts"() {
|
|
6831
|
+
"use strict";
|
|
6832
|
+
import_node_crypto7 = require("node:crypto");
|
|
6833
|
+
import_zod14 = require("zod");
|
|
6834
|
+
init_headers();
|
|
6835
|
+
INJECTED_ENV = "AGENT_SHIM_INJECTED";
|
|
6836
|
+
CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
|
|
6837
|
+
HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
|
|
6838
|
+
InjectedSchema = import_zod14.z.record(import_zod14.z.string(), import_zod14.z.string());
|
|
6839
|
+
}
|
|
6840
|
+
});
|
|
6841
|
+
|
|
6842
|
+
// src/launcher/guard.ts
|
|
6843
|
+
function detectAmbientCredential(env, injected) {
|
|
6844
|
+
for (const variable of AMBIENT_CREDENTIAL_VARS) {
|
|
6845
|
+
const value = env[variable];
|
|
6846
|
+
if (value === void 0 || value === "") {
|
|
6847
|
+
continue;
|
|
6848
|
+
}
|
|
6849
|
+
if (injected?.variable === variable && value === injected.token) {
|
|
6850
|
+
continue;
|
|
6851
|
+
}
|
|
6852
|
+
return { variable };
|
|
6853
|
+
}
|
|
6854
|
+
return void 0;
|
|
6855
|
+
}
|
|
6856
|
+
function formatAmbientCredentialGuardMessage(variable, identityName) {
|
|
6857
|
+
const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
|
|
6858
|
+
return [
|
|
6859
|
+
`error: ${variable} is set in the environment. This identity's isolated`,
|
|
6860
|
+
"credential would be bypassed \u2014 every identity authenticates as this same key",
|
|
6861
|
+
"while it's set. Unset it, or if this is deliberate, opt in per-launch with",
|
|
6862
|
+
"AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
|
|
6863
|
+
`\`${identitySetCommand}\`.`
|
|
6864
|
+
].join("\n");
|
|
6865
|
+
}
|
|
6866
|
+
function evaluateAmbientCredentialGuard(params) {
|
|
6867
|
+
const detected = detectAmbientCredential(params.env, params.injectedCredential);
|
|
6868
|
+
if (detected === void 0) {
|
|
6869
|
+
return { ok: true };
|
|
6870
|
+
}
|
|
6871
|
+
if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
|
|
6872
|
+
return { ok: true };
|
|
6873
|
+
}
|
|
6874
|
+
return {
|
|
6875
|
+
ok: false,
|
|
6876
|
+
variable: detected.variable,
|
|
6877
|
+
message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
|
|
6878
|
+
};
|
|
6879
|
+
}
|
|
6880
|
+
function ambientCredentialFinding(env) {
|
|
6881
|
+
const named = detectAmbientCredential(launchEnvironment(env, false));
|
|
6882
|
+
if (named !== void 0) {
|
|
6883
|
+
return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
|
|
6884
|
+
}
|
|
6885
|
+
const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
|
|
6886
|
+
if (bare !== void 0) {
|
|
6887
|
+
return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
|
|
6888
|
+
}
|
|
6889
|
+
return { severity: "pass", message: "No ambient-credential environment variable is set." };
|
|
6890
|
+
}
|
|
6891
|
+
var AMBIENT_CREDENTIAL_VARS;
|
|
6892
|
+
var init_guard = __esm({
|
|
6893
|
+
"src/launcher/guard.ts"() {
|
|
6894
|
+
"use strict";
|
|
6895
|
+
init_injected();
|
|
6896
|
+
AMBIENT_CREDENTIAL_VARS = [
|
|
6897
|
+
"ANTHROPIC_API_KEY",
|
|
6898
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
6899
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
6900
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
6901
|
+
"CLAUDE_CODE_USE_VERTEX",
|
|
6902
|
+
"CLAUDE_CODE_USE_FOUNDRY"
|
|
6903
|
+
];
|
|
6904
|
+
}
|
|
6905
|
+
});
|
|
6906
|
+
|
|
6692
6907
|
// src/usage/signIn.ts
|
|
6693
6908
|
function claudeCodeKeychainService(configDir) {
|
|
6694
|
-
return `${KEYCHAIN_SERVICE_PREFIX}-${(0,
|
|
6909
|
+
return `${KEYCHAIN_SERVICE_PREFIX}-${(0, import_node_crypto8.createHash)("sha256").update(configDir).digest("hex").slice(0, KEYCHAIN_SERVICE_HASH_DIGITS)}`;
|
|
6695
6910
|
}
|
|
6696
6911
|
function keychainHasItem(run, configDir) {
|
|
6697
6912
|
return run.run("security", ["find-generic-password", "-s", claudeCodeKeychainService(configDir)]).status === 0;
|
|
@@ -6724,15 +6939,35 @@ function identitySignIn(fs17, probe, identity) {
|
|
|
6724
6939
|
platform: probe.platform
|
|
6725
6940
|
});
|
|
6726
6941
|
}
|
|
6727
|
-
|
|
6942
|
+
function storedLoginUsable(run, claudeBin, configDir, env) {
|
|
6943
|
+
const childEnv = { ...env, CLAUDE_CONFIG_DIR: configDir };
|
|
6944
|
+
for (const variable of AMBIENT_CREDENTIAL_VARS) {
|
|
6945
|
+
childEnv[variable] = void 0;
|
|
6946
|
+
}
|
|
6947
|
+
const result = run.run(claudeBin, ["auth", "status"], void 0, { env: childEnv, timeoutMs: AUTH_STATUS_TIMEOUT_MS });
|
|
6948
|
+
if (result.status === null) {
|
|
6949
|
+
return void 0;
|
|
6950
|
+
}
|
|
6951
|
+
try {
|
|
6952
|
+
const status = JSON.parse(result.stdout);
|
|
6953
|
+
if (typeof status === "object" && status !== null && "loggedIn" in status && typeof status.loggedIn === "boolean") {
|
|
6954
|
+
return status.loggedIn;
|
|
6955
|
+
}
|
|
6956
|
+
} catch {
|
|
6957
|
+
}
|
|
6958
|
+
return void 0;
|
|
6959
|
+
}
|
|
6960
|
+
var import_node_crypto8, import_node_path19, CREDENTIALS_FILE, KEYCHAIN_SERVICE_PREFIX, KEYCHAIN_SERVICE_HASH_DIGITS, AUTH_STATUS_TIMEOUT_MS;
|
|
6728
6961
|
var init_signIn = __esm({
|
|
6729
6962
|
"src/usage/signIn.ts"() {
|
|
6730
6963
|
"use strict";
|
|
6731
|
-
|
|
6964
|
+
import_node_crypto8 = require("node:crypto");
|
|
6732
6965
|
import_node_path19 = __toESM(require("node:path"), 1);
|
|
6966
|
+
init_guard();
|
|
6733
6967
|
CREDENTIALS_FILE = ".credentials.json";
|
|
6734
6968
|
KEYCHAIN_SERVICE_PREFIX = "Claude Code-credentials";
|
|
6735
6969
|
KEYCHAIN_SERVICE_HASH_DIGITS = 8;
|
|
6970
|
+
AUTH_STATUS_TIMEOUT_MS = 1e4;
|
|
6736
6971
|
}
|
|
6737
6972
|
});
|
|
6738
6973
|
|
|
@@ -6863,7 +7098,7 @@ function serialisedFor(entry, owner) {
|
|
|
6863
7098
|
return JSON.stringify({ owner, ...withoutOwner(entry) });
|
|
6864
7099
|
}
|
|
6865
7100
|
function tempPathFor(target) {
|
|
6866
|
-
return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0,
|
|
7101
|
+
return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0, import_node_crypto9.randomUUID)()}`);
|
|
6867
7102
|
}
|
|
6868
7103
|
function processRuns(pid) {
|
|
6869
7104
|
try {
|
|
@@ -6982,11 +7217,11 @@ function createRealCredentialCache(root, keychain = { run: security, platform: p
|
|
|
6982
7217
|
function realCredentialCacheEnv(paths) {
|
|
6983
7218
|
return { port: createRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
|
|
6984
7219
|
}
|
|
6985
|
-
var
|
|
7220
|
+
var import_node_crypto9, import_node_fs5, import_node_path20, CACHE_DIR_MODE, CACHE_FILE_MODE, TEMP_PREFIX, TEMP_NAME, RELEASED_TEMP_NAME;
|
|
6986
7221
|
var init_realCredentialCache = __esm({
|
|
6987
7222
|
"src/realCredentialCache.ts"() {
|
|
6988
7223
|
"use strict";
|
|
6989
|
-
|
|
7224
|
+
import_node_crypto9 = require("node:crypto");
|
|
6990
7225
|
import_node_fs5 = __toESM(require("node:fs"), 1);
|
|
6991
7226
|
import_node_path20 = __toESM(require("node:path"), 1);
|
|
6992
7227
|
init_blockingSpawn();
|
|
@@ -7143,7 +7378,7 @@ function migrateHeadroomState(fs17, files, isRunning) {
|
|
|
7143
7378
|
fs17.removeRecursive(files.legacyStateFile);
|
|
7144
7379
|
}
|
|
7145
7380
|
function hashAllowlist(allowlist) {
|
|
7146
|
-
return (0,
|
|
7381
|
+
return (0, import_node_crypto10.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
7147
7382
|
}
|
|
7148
7383
|
function formatAllowlistFile(allowlist) {
|
|
7149
7384
|
return allowlist.map((entry) => `${entry}
|
|
@@ -7248,40 +7483,40 @@ function readStartLock(fs17, lockFile) {
|
|
|
7248
7483
|
return void 0;
|
|
7249
7484
|
}
|
|
7250
7485
|
}
|
|
7251
|
-
var
|
|
7486
|
+
var import_node_crypto10, import_node_path21, import_zod15, HeadroomStateSchema, HeadroomSessionSchema, HeadroomLockSchema, HEADROOM_ALLOWLIST_FILE_FLAG, ALLOWLIST_LINE_BREAKS, ALLOWLIST_WHITESPACE, ALLOWLIST_FILE_SEPARATORS, ALLOWLIST_FILE_COMMENT, ALLOWLIST_ENTRY_WHITESPACE, ALLOWLIST_SURROUNDING_WHITESPACE, ALLOWLIST_SAFE_SCHEMES;
|
|
7252
7487
|
var init_state2 = __esm({
|
|
7253
7488
|
"src/headroom/state.ts"() {
|
|
7254
7489
|
"use strict";
|
|
7255
|
-
|
|
7490
|
+
import_node_crypto10 = require("node:crypto");
|
|
7256
7491
|
import_node_path21 = __toESM(require("node:path"), 1);
|
|
7257
|
-
|
|
7492
|
+
import_zod15 = require("zod");
|
|
7258
7493
|
init_schema();
|
|
7259
|
-
HeadroomStateSchema =
|
|
7494
|
+
HeadroomStateSchema = import_zod15.z.strictObject({
|
|
7260
7495
|
/** The supervisor process owning the daemon. Alive means someone is keeping headroom running. */
|
|
7261
|
-
supervisorPid:
|
|
7496
|
+
supervisorPid: import_zod15.z.number().int().positive().optional(),
|
|
7262
7497
|
/** The headroom proxy process itself, recorded as soon as it is spawned (before it is ready, which `socketPath` signals) so a successor can find a daemon whose supervisor died during its start. Absent while the supervisor is between restarts. */
|
|
7263
|
-
headroomPid:
|
|
7498
|
+
headroomPid: import_zod15.z.number().int().positive().optional(),
|
|
7264
7499
|
/**
|
|
7265
7500
|
* The unix socket the proxy serves on, inside the owner-only socket directory. Absent until the proxy has passed its readiness check, so "socketPath is set" is itself the ready signal a launcher polls for. The front door reads it on every hop, so a restart (which keeps the generation's path) is followed without anything being relaunched.
|
|
7266
7501
|
*/
|
|
7267
|
-
socketPath:
|
|
7502
|
+
socketPath: import_zod15.z.string().min(1).optional(),
|
|
7268
7503
|
/** The `headroom --version` output of the running install. */
|
|
7269
|
-
version:
|
|
7504
|
+
version: import_zod15.z.string().optional(),
|
|
7270
7505
|
/**
|
|
7271
7506
|
* Hash of the allowlist the running proxy serves. The supervisor records it in the same tick it writes that allowlist to `LayoutPaths.headroomAllowlistFile`, which the proxy re-reads on its next request, so a provider launch, whose requests come back through its front door's direct origin, waits until this names an allowlist holding that origin. A supervisor from an earlier release records here the hash of the allowlist its daemon was started with instead (see `earlierRelease.ts`).
|
|
7272
7507
|
*/
|
|
7273
|
-
allowlistHash:
|
|
7508
|
+
allowlistHash: import_zod15.z.string().optional(),
|
|
7274
7509
|
/** Hash of the token-saving settings the running proxy was started with, so a settings change is detected as drift. */
|
|
7275
|
-
settingsHash:
|
|
7510
|
+
settingsHash: import_zod15.z.string().optional(),
|
|
7276
7511
|
/** The install spec the running install was last installed from, so a `source` config change is detected as drift. */
|
|
7277
|
-
installedSource:
|
|
7512
|
+
installedSource: import_zod15.z.string().optional(),
|
|
7278
7513
|
/** The install spec the supervisor is installing right now, present only while `uv tool install` runs, so a launcher that finds a live supervisor with no daemon yet keeps waiting for the install instead of counting it against its start bound. Cleared by the write that follows the install, whatever its outcome. */
|
|
7279
|
-
installing:
|
|
7514
|
+
installing: import_zod15.z.string().optional(),
|
|
7280
7515
|
/** The last fatal error, kept across shutdowns so `headroom status` can explain a daemon that is not running. */
|
|
7281
|
-
lastError:
|
|
7516
|
+
lastError: import_zod15.z.string().optional()
|
|
7282
7517
|
});
|
|
7283
|
-
HeadroomSessionSchema =
|
|
7284
|
-
HeadroomLockSchema =
|
|
7518
|
+
HeadroomSessionSchema = import_zod15.z.strictObject({ pid: import_zod15.z.number().int().positive(), startedAt: import_zod15.z.number(), supervisorPid: import_zod15.z.number().int().positive() });
|
|
7519
|
+
HeadroomLockSchema = import_zod15.z.strictObject({ pid: import_zod15.z.number().int().positive(), at: import_zod15.z.number() });
|
|
7285
7520
|
HEADROOM_ALLOWLIST_FILE_FLAG = "--allowed-base-urls-file";
|
|
7286
7521
|
ALLOWLIST_LINE_BREAKS = "\\n\\r\\u000b\\u000c\\u001c\\u001d\\u001e\\u0085\\u2028\\u2029";
|
|
7287
7522
|
ALLOWLIST_WHITESPACE = "\\t\\n\\u000b\\u000c\\r\\u001c-\\u001f \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
|
|
@@ -7495,13 +7730,13 @@ function settingsEnv(settings) {
|
|
|
7495
7730
|
return settings.rolloutChannel === void 0 ? {} : { HEADROOM_ROLLOUT_CHANNEL: settings.rolloutChannel };
|
|
7496
7731
|
}
|
|
7497
7732
|
function hashSettings(settings) {
|
|
7498
|
-
return (0,
|
|
7733
|
+
return (0, import_node_crypto11.createHash)("sha256").update(JSON.stringify([...settingsArgs(settings), JSON.stringify(settingsEnv(settings))])).digest("hex");
|
|
7499
7734
|
}
|
|
7500
|
-
var
|
|
7735
|
+
var import_node_crypto11;
|
|
7501
7736
|
var init_settings = __esm({
|
|
7502
7737
|
"src/headroom/settings.ts"() {
|
|
7503
7738
|
"use strict";
|
|
7504
|
-
|
|
7739
|
+
import_node_crypto11 = require("node:crypto");
|
|
7505
7740
|
}
|
|
7506
7741
|
});
|
|
7507
7742
|
|
|
@@ -7701,14 +7936,14 @@ function pinnedGitCommit(spec) {
|
|
|
7701
7936
|
const ref = GIT_SPEC_RE.exec(spec)?.[1];
|
|
7702
7937
|
return ref !== void 0 && COMMIT_SHA_RE.test(ref) ? ref.toLowerCase() : void 0;
|
|
7703
7938
|
}
|
|
7704
|
-
var
|
|
7939
|
+
var import_zod16, GIT_SPEC_RE, COMMIT_SHA_RE, DirectUrlSchema;
|
|
7705
7940
|
var init_source = __esm({
|
|
7706
7941
|
"src/headroom/source.ts"() {
|
|
7707
7942
|
"use strict";
|
|
7708
|
-
|
|
7943
|
+
import_zod16 = require("zod");
|
|
7709
7944
|
GIT_SPEC_RE = /git\+[^@\s]+(?:@([^\s#]+))?/;
|
|
7710
7945
|
COMMIT_SHA_RE = /^[0-9a-f]{40}$/i;
|
|
7711
|
-
DirectUrlSchema =
|
|
7946
|
+
DirectUrlSchema = import_zod16.z.object({ vcs_info: import_zod16.z.object({ commit_id: import_zod16.z.string() }) });
|
|
7712
7947
|
}
|
|
7713
7948
|
});
|
|
7714
7949
|
|
|
@@ -8214,6 +8449,9 @@ function realFrontDoorLiveness(pids) {
|
|
|
8214
8449
|
return { status: result.status, stdout: result.stdout, stderr: result.stderr, ...result.error === void 0 ? {} : { error: result.error } };
|
|
8215
8450
|
});
|
|
8216
8451
|
}
|
|
8452
|
+
function definedEntries(env) {
|
|
8453
|
+
return Object.fromEntries(Object.entries(env).filter((entry) => entry[1] !== void 0));
|
|
8454
|
+
}
|
|
8217
8455
|
function realRunAsyncWithin(timeoutMs) {
|
|
8218
8456
|
return async (command, args) => await new Promise((resolve) => {
|
|
8219
8457
|
(0, import_node_child_process2.execFile)(command, [...args], { encoding: "utf8", timeout: timeoutMs }, (error, stdout, stderr) => {
|
|
@@ -8422,14 +8660,14 @@ function realResolveClaudeBinary(isOwnBinary) {
|
|
|
8422
8660
|
function realInstalledClaudeVersions() {
|
|
8423
8661
|
return installedVersions(listVersionsDir(defaultVersionsDir()));
|
|
8424
8662
|
}
|
|
8425
|
-
var import_node_child_process2,
|
|
8663
|
+
var import_node_child_process2, import_node_crypto12, import_node_fs6, import_node_os2, import_node_path24, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS2, DIRECTORY_FLUSH_UNSUPPORTED_CODES, realFarmFs, INT32_BYTE_LENGTH, KEY_POLL_MS, CTRL_C_BYTE, realHoldPort, PS_TIMEOUT_MS, RUN_OUTPUT_LIMIT_MIB, BYTES_PER_MIB2, RUN_OUTPUT_LIMIT_BYTES, realRunPort, ASYNC_RUN_TIMEOUT_MS, realRunAsync, MACOS_GUI_SESSION_MANAGER, realCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, realLogPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
|
|
8426
8664
|
var init_realPorts = __esm({
|
|
8427
8665
|
"src/realPorts.ts"() {
|
|
8428
8666
|
"use strict";
|
|
8429
8667
|
init_blockingSpawn();
|
|
8430
8668
|
init_processRole();
|
|
8431
8669
|
import_node_child_process2 = require("node:child_process");
|
|
8432
|
-
|
|
8670
|
+
import_node_crypto12 = require("node:crypto");
|
|
8433
8671
|
import_node_fs6 = __toESM(require("node:fs"), 1);
|
|
8434
8672
|
import_node_os2 = __toESM(require("node:os"), 1);
|
|
8435
8673
|
import_node_path24 = __toESM(require("node:path"), 1);
|
|
@@ -8580,7 +8818,7 @@ var init_realPorts = __esm({
|
|
|
8580
8818
|
},
|
|
8581
8819
|
hashFile(filePath) {
|
|
8582
8820
|
try {
|
|
8583
|
-
return (0,
|
|
8821
|
+
return (0, import_node_crypto12.createHash)("sha256").update(import_node_fs6.default.readFileSync(filePath)).digest("hex");
|
|
8584
8822
|
} catch (error) {
|
|
8585
8823
|
if (isEnoent3(error) || isErrorWithCode(error, "EISDIR")) {
|
|
8586
8824
|
return void 0;
|
|
@@ -8620,8 +8858,14 @@ var init_realPorts = __esm({
|
|
|
8620
8858
|
BYTES_PER_MIB2 = 1048576;
|
|
8621
8859
|
RUN_OUTPUT_LIMIT_BYTES = RUN_OUTPUT_LIMIT_MIB * BYTES_PER_MIB2;
|
|
8622
8860
|
realRunPort = {
|
|
8623
|
-
run(command, args, input) {
|
|
8624
|
-
const result = spawnSyncBlocking("an external command", command, args, {
|
|
8861
|
+
run(command, args, input, options) {
|
|
8862
|
+
const result = spawnSyncBlocking("an external command", command, args, {
|
|
8863
|
+
encoding: "utf8",
|
|
8864
|
+
maxBuffer: RUN_OUTPUT_LIMIT_BYTES,
|
|
8865
|
+
...input === void 0 ? {} : { input },
|
|
8866
|
+
...options?.env === void 0 ? {} : { env: definedEntries(options.env) },
|
|
8867
|
+
...options?.timeoutMs === void 0 ? {} : { timeout: options.timeoutMs }
|
|
8868
|
+
});
|
|
8625
8869
|
return { status: result.status, stdout: result.stdout, stderr: result.stderr };
|
|
8626
8870
|
}
|
|
8627
8871
|
};
|
|
@@ -9041,24 +9285,24 @@ function planOf(account) {
|
|
|
9041
9285
|
}
|
|
9042
9286
|
return { kind: "subscription", capacity: 1, recognised: BASE_TIER.test(tier), ...tierField };
|
|
9043
9287
|
}
|
|
9044
|
-
var
|
|
9288
|
+
var import_zod17, PlanClassSchema, TIER_MULTIPLIER, ZERO_TIER, BASE_TIER;
|
|
9045
9289
|
var init_plan2 = __esm({
|
|
9046
9290
|
"src/usage/plan.ts"() {
|
|
9047
9291
|
"use strict";
|
|
9048
|
-
|
|
9049
|
-
PlanClassSchema =
|
|
9050
|
-
|
|
9051
|
-
kind:
|
|
9292
|
+
import_zod17 = require("zod");
|
|
9293
|
+
PlanClassSchema = import_zod17.z.union([
|
|
9294
|
+
import_zod17.z.strictObject({
|
|
9295
|
+
kind: import_zod17.z.literal("subscription"),
|
|
9052
9296
|
/** The plan's size as a multiple of the smallest subscription tier (Max is 5, Ultra is 20). */
|
|
9053
|
-
capacity:
|
|
9297
|
+
capacity: import_zod17.z.number().positive(),
|
|
9054
9298
|
/** False when the tier string named no multiplier and no tier this project knows, so `capacity` is the neutral 1 rather than a reading. */
|
|
9055
|
-
recognised:
|
|
9299
|
+
recognised: import_zod17.z.boolean(),
|
|
9056
9300
|
/** The tier string the classification rests on, when the account had one. */
|
|
9057
|
-
tier:
|
|
9301
|
+
tier: import_zod17.z.string().optional()
|
|
9058
9302
|
}),
|
|
9059
|
-
|
|
9060
|
-
kind:
|
|
9061
|
-
tier:
|
|
9303
|
+
import_zod17.z.strictObject({
|
|
9304
|
+
kind: import_zod17.z.literal("pay-per-use"),
|
|
9305
|
+
tier: import_zod17.z.string().optional()
|
|
9062
9306
|
})
|
|
9063
9307
|
]);
|
|
9064
9308
|
TIER_MULTIPLIER = /(?:^|_)(\d+)x$/;
|
|
@@ -9068,21 +9312,21 @@ var init_plan2 = __esm({
|
|
|
9068
9312
|
});
|
|
9069
9313
|
|
|
9070
9314
|
// src/usage/scan.ts
|
|
9071
|
-
var
|
|
9315
|
+
var import_zod18, AnthropicUsageSchema, ErrorObjectSchema;
|
|
9072
9316
|
var init_scan = __esm({
|
|
9073
9317
|
"src/usage/scan.ts"() {
|
|
9074
9318
|
"use strict";
|
|
9075
|
-
|
|
9076
|
-
AnthropicUsageSchema =
|
|
9077
|
-
input_tokens:
|
|
9078
|
-
output_tokens:
|
|
9079
|
-
cache_creation_input_tokens:
|
|
9080
|
-
cache_read_input_tokens:
|
|
9319
|
+
import_zod18 = require("zod");
|
|
9320
|
+
AnthropicUsageSchema = import_zod18.z.looseObject({
|
|
9321
|
+
input_tokens: import_zod18.z.number().int().nonnegative().nullish(),
|
|
9322
|
+
output_tokens: import_zod18.z.number().int().nonnegative().nullish(),
|
|
9323
|
+
cache_creation_input_tokens: import_zod18.z.number().int().nonnegative().nullish(),
|
|
9324
|
+
cache_read_input_tokens: import_zod18.z.number().int().nonnegative().nullish()
|
|
9081
9325
|
});
|
|
9082
|
-
ErrorObjectSchema =
|
|
9083
|
-
type:
|
|
9084
|
-
code:
|
|
9085
|
-
message:
|
|
9326
|
+
ErrorObjectSchema = import_zod18.z.looseObject({
|
|
9327
|
+
type: import_zod18.z.string().optional(),
|
|
9328
|
+
code: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional(),
|
|
9329
|
+
message: import_zod18.z.string().optional()
|
|
9086
9330
|
});
|
|
9087
9331
|
}
|
|
9088
9332
|
});
|
|
@@ -9732,12 +9976,12 @@ function recordStickyPick(fs17, picksFile, directory, identity, nowMs) {
|
|
|
9732
9976
|
fs17.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
9733
9977
|
`);
|
|
9734
9978
|
}
|
|
9735
|
-
var import_node_path26,
|
|
9979
|
+
var import_node_path26, import_zod19, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
9736
9980
|
var init_poolPick = __esm({
|
|
9737
9981
|
"src/usage/poolPick.ts"() {
|
|
9738
9982
|
"use strict";
|
|
9739
9983
|
import_node_path26 = __toESM(require("node:path"), 1);
|
|
9740
|
-
|
|
9984
|
+
import_zod19 = require("zod");
|
|
9741
9985
|
init_cliError();
|
|
9742
9986
|
init_identity();
|
|
9743
9987
|
init_schema();
|
|
@@ -9754,17 +9998,17 @@ var init_poolPick = __esm({
|
|
|
9754
9998
|
}
|
|
9755
9999
|
};
|
|
9756
10000
|
SCHEMA_VERSION = 1;
|
|
9757
|
-
PickEntrySchema =
|
|
9758
|
-
PicksFileSchema =
|
|
9759
|
-
schemaVersion:
|
|
9760
|
-
picks:
|
|
10001
|
+
PickEntrySchema = import_zod19.z.strictObject({ identity: import_zod19.z.string().min(1), at: import_zod19.z.iso.datetime() });
|
|
10002
|
+
PicksFileSchema = import_zod19.z.strictObject({
|
|
10003
|
+
schemaVersion: import_zod19.z.literal(SCHEMA_VERSION),
|
|
10004
|
+
picks: import_zod19.z.record(import_zod19.z.string().min(1), PickEntrySchema)
|
|
9761
10005
|
});
|
|
9762
10006
|
}
|
|
9763
10007
|
});
|
|
9764
10008
|
|
|
9765
10009
|
// src/identityRenameJournal.ts
|
|
9766
10010
|
function renamePairFileName(from, to, suffix) {
|
|
9767
|
-
return `${(0,
|
|
10011
|
+
return `${(0, import_node_crypto13.createHash)("sha256").update(`${from}\0${to}`).digest("hex").slice(0, FILE_NAME_HASH_DIGITS)}${suffix}`;
|
|
9768
10012
|
}
|
|
9769
10013
|
function readRenameJournal(fs17, file) {
|
|
9770
10014
|
const raw = fs17.readFileUtf8(file);
|
|
@@ -9835,28 +10079,28 @@ function requireNameFreeOfUnfinishedRename(fs17, directory, name, action, sameNa
|
|
|
9835
10079
|
throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
|
|
9836
10080
|
}
|
|
9837
10081
|
}
|
|
9838
|
-
var
|
|
10082
|
+
var import_node_crypto13, import_node_path27, import_zod20, RenameJournalSchema, FILE_NAME_HASH_DIGITS, JOURNAL_SUFFIX, RenameJournalUnreadableError, NameHeldByUnfinishedRenameError;
|
|
9839
10083
|
var init_identityRenameJournal = __esm({
|
|
9840
10084
|
"src/identityRenameJournal.ts"() {
|
|
9841
10085
|
"use strict";
|
|
9842
|
-
|
|
10086
|
+
import_node_crypto13 = require("node:crypto");
|
|
9843
10087
|
import_node_path27 = __toESM(require("node:path"), 1);
|
|
9844
|
-
|
|
10088
|
+
import_zod20 = require("zod");
|
|
9845
10089
|
init_cliError();
|
|
9846
|
-
RenameJournalSchema =
|
|
9847
|
-
version:
|
|
9848
|
-
from:
|
|
9849
|
-
to:
|
|
9850
|
-
startedAt:
|
|
10090
|
+
RenameJournalSchema = import_zod20.z.strictObject({
|
|
10091
|
+
version: import_zod20.z.literal(1),
|
|
10092
|
+
from: import_zod20.z.string().min(1),
|
|
10093
|
+
to: import_zod20.z.string().min(1),
|
|
10094
|
+
startedAt: import_zod20.z.iso.datetime(),
|
|
9851
10095
|
/** The process that began the rename, for a person reading the file. Whether it is still running is told by the locks, not by this. */
|
|
9852
|
-
pid:
|
|
9853
|
-
steps:
|
|
9854
|
-
|
|
9855
|
-
description:
|
|
10096
|
+
pid: import_zod20.z.number().int().positive(),
|
|
10097
|
+
steps: import_zod20.z.array(
|
|
10098
|
+
import_zod20.z.strictObject({
|
|
10099
|
+
description: import_zod20.z.string().min(1),
|
|
9856
10100
|
/** Whether the step has been applied and marked so. */
|
|
9857
|
-
done:
|
|
10101
|
+
done: import_zod20.z.boolean(),
|
|
9858
10102
|
/** Whether the step was begun: written ahead of the step, before it runs, so a process that dies after the step took effect and before `done` was written still leaves a record that it may have. */
|
|
9859
|
-
started:
|
|
10103
|
+
started: import_zod20.z.boolean()
|
|
9860
10104
|
})
|
|
9861
10105
|
)
|
|
9862
10106
|
});
|
|
@@ -9961,13 +10205,13 @@ function requireNoInterruptedNameRename(paths, name, action, except) {
|
|
|
9961
10205
|
throw new InterruptedNameRenameError(action, describeInterruptedNameRename(paths, held));
|
|
9962
10206
|
}
|
|
9963
10207
|
}
|
|
9964
|
-
var import_node_fs7, import_node_path28,
|
|
10208
|
+
var import_node_fs7, import_node_path28, import_zod21, NameRenameRecordSchema, RECORD_SUFFIX, InterruptedNameRenameError;
|
|
9965
10209
|
var init_identityNameRenameRecord = __esm({
|
|
9966
10210
|
"src/identityNameRenameRecord.ts"() {
|
|
9967
10211
|
"use strict";
|
|
9968
10212
|
import_node_fs7 = __toESM(require("node:fs"), 1);
|
|
9969
10213
|
import_node_path28 = __toESM(require("node:path"), 1);
|
|
9970
|
-
|
|
10214
|
+
import_zod21 = require("zod");
|
|
9971
10215
|
init_cliError();
|
|
9972
10216
|
init_configProfilesStore();
|
|
9973
10217
|
init_directoryRulesStore();
|
|
@@ -9977,12 +10221,12 @@ var init_identityNameRenameRecord = __esm({
|
|
|
9977
10221
|
init_poolPick();
|
|
9978
10222
|
init_identityRecords();
|
|
9979
10223
|
init_identityRenameJournal();
|
|
9980
|
-
NameRenameRecordSchema =
|
|
9981
|
-
version:
|
|
9982
|
-
id:
|
|
9983
|
-
from:
|
|
9984
|
-
to:
|
|
9985
|
-
startedAt:
|
|
10224
|
+
NameRenameRecordSchema = import_zod21.z.strictObject({
|
|
10225
|
+
version: import_zod21.z.literal(1),
|
|
10226
|
+
id: import_zod21.z.string().min(1),
|
|
10227
|
+
from: import_zod21.z.string().min(1),
|
|
10228
|
+
to: import_zod21.z.string().min(1),
|
|
10229
|
+
startedAt: import_zod21.z.iso.datetime()
|
|
9986
10230
|
});
|
|
9987
10231
|
RECORD_SUFFIX = ".json";
|
|
9988
10232
|
InterruptedNameRenameError = class extends CliError {
|
|
@@ -9996,7 +10240,7 @@ var init_identityNameRenameRecord = __esm({
|
|
|
9996
10240
|
|
|
9997
10241
|
// src/launcher/launchRecords.ts
|
|
9998
10242
|
function recordFile(directory, pid) {
|
|
9999
|
-
return import_node_path29.default.join(directory, `${String(pid)}.${(0,
|
|
10243
|
+
return import_node_path29.default.join(directory, `${String(pid)}.${(0, import_node_crypto14.randomUUID)()}${RECORD_SUFFIX2}`);
|
|
10000
10244
|
}
|
|
10001
10245
|
function readRecord(fs17, directory, name) {
|
|
10002
10246
|
if (!name.endsWith(RECORD_SUFFIX2)) {
|
|
@@ -10037,18 +10281,18 @@ function liveLaunchesOn(fs17, directory, identity, isRunning) {
|
|
|
10037
10281
|
return record?.identity === identity && isRunning(record.pid) ? [record.pid] : [];
|
|
10038
10282
|
}).sort((left, right) => left - right);
|
|
10039
10283
|
}
|
|
10040
|
-
var import_node_path29,
|
|
10284
|
+
var import_node_path29, import_node_crypto14, import_zod22, LaunchRecordSchema, RECORD_SUFFIX2;
|
|
10041
10285
|
var init_launchRecords = __esm({
|
|
10042
10286
|
"src/launcher/launchRecords.ts"() {
|
|
10043
10287
|
"use strict";
|
|
10044
10288
|
import_node_path29 = __toESM(require("node:path"), 1);
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
LaunchRecordSchema =
|
|
10289
|
+
import_node_crypto14 = require("node:crypto");
|
|
10290
|
+
import_zod22 = require("zod");
|
|
10291
|
+
LaunchRecordSchema = import_zod22.z.strictObject({
|
|
10048
10292
|
/** The launcher's process id, which is what tells a launch in progress from a record a crashed launcher left behind. */
|
|
10049
|
-
pid:
|
|
10050
|
-
identity:
|
|
10051
|
-
startedAt:
|
|
10293
|
+
pid: import_zod22.z.number().int().positive(),
|
|
10294
|
+
identity: import_zod22.z.string().min(1),
|
|
10295
|
+
startedAt: import_zod22.z.iso.datetime()
|
|
10052
10296
|
});
|
|
10053
10297
|
RECORD_SUFFIX2 = ".json";
|
|
10054
10298
|
}
|
|
@@ -10519,7 +10763,7 @@ var init_package = __esm({
|
|
|
10519
10763
|
"package.json"() {
|
|
10520
10764
|
package_default = {
|
|
10521
10765
|
name: "claude-use",
|
|
10522
|
-
version: "
|
|
10766
|
+
version: "12.0.1",
|
|
10523
10767
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
10524
10768
|
license: "MIT",
|
|
10525
10769
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -10898,15 +11142,15 @@ function aliasFindings(aliases, providerNames) {
|
|
|
10898
11142
|
return { level: "pass", alias, message: `${alias} is a former name of ${target}, still honoured for sessions launched under it. Run \`agent-shim provider unalias ${alias}\` once none is running.` };
|
|
10899
11143
|
});
|
|
10900
11144
|
}
|
|
10901
|
-
var
|
|
11145
|
+
var import_zod26, ProviderAliasesSchema;
|
|
10902
11146
|
var init_providerAliases = __esm({
|
|
10903
11147
|
"src/providerAliases.ts"() {
|
|
10904
11148
|
"use strict";
|
|
10905
|
-
|
|
11149
|
+
import_zod26 = require("zod");
|
|
10906
11150
|
init_cliError();
|
|
10907
11151
|
init_load();
|
|
10908
11152
|
init_store();
|
|
10909
|
-
ProviderAliasesSchema =
|
|
11153
|
+
ProviderAliasesSchema = import_zod26.z.record(import_zod26.z.string().min(1), import_zod26.z.string().min(1));
|
|
10910
11154
|
}
|
|
10911
11155
|
});
|
|
10912
11156
|
|
|
@@ -11130,14 +11374,14 @@ function requireProviderExists(paths, name) {
|
|
|
11130
11374
|
throw new ProviderNotFoundError(name);
|
|
11131
11375
|
}
|
|
11132
11376
|
}
|
|
11133
|
-
function
|
|
11377
|
+
function isRecord9(value) {
|
|
11134
11378
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11135
11379
|
}
|
|
11136
11380
|
function legacyProviderConversion(raw) {
|
|
11137
|
-
if (!
|
|
11381
|
+
if (!isRecord9(raw) || "credential" in raw) {
|
|
11138
11382
|
return void 0;
|
|
11139
11383
|
}
|
|
11140
|
-
const env =
|
|
11384
|
+
const env = isRecord9(raw.env) ? raw.env : void 0;
|
|
11141
11385
|
const legacyEnvKeys = env === void 0 ? [] : Object.keys(env).filter((key) => LEGACY_ENV_CREDENTIAL_KEYS.includes(key));
|
|
11142
11386
|
const fields = [...LEGACY_PROVIDER_FIELDS.filter((field) => field in raw), ...legacyEnvKeys.map((key) => `env.${key}`)];
|
|
11143
11387
|
if (fields.length === 0) {
|
|
@@ -11568,221 +11812,6 @@ var init_claudeVersion = __esm({
|
|
|
11568
11812
|
}
|
|
11569
11813
|
});
|
|
11570
11814
|
|
|
11571
|
-
// src/headroom/headers.ts
|
|
11572
|
-
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
11573
|
-
const merged = /* @__PURE__ */ new Map();
|
|
11574
|
-
for (const block of existing) {
|
|
11575
|
-
if (block === void 0) {
|
|
11576
|
-
continue;
|
|
11577
|
-
}
|
|
11578
|
-
for (const line of block.split("\n")) {
|
|
11579
|
-
const entry = parseCustomHeaderLine(line);
|
|
11580
|
-
if (entry === void 0) {
|
|
11581
|
-
continue;
|
|
11582
|
-
}
|
|
11583
|
-
merged.set(entry.name, entry.value);
|
|
11584
|
-
}
|
|
11585
|
-
}
|
|
11586
|
-
for (const entry of additions) {
|
|
11587
|
-
merged.set(entry.name, entry.value);
|
|
11588
|
-
}
|
|
11589
|
-
return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
|
|
11590
|
-
}
|
|
11591
|
-
function parseAnthropicCustomHeaders(block) {
|
|
11592
|
-
return block.split("\n").flatMap((line) => {
|
|
11593
|
-
const entry = parseCustomHeaderLine(line);
|
|
11594
|
-
return entry === void 0 ? [] : [entry];
|
|
11595
|
-
});
|
|
11596
|
-
}
|
|
11597
|
-
function withoutAnthropicCustomHeaders(block, remove) {
|
|
11598
|
-
const lines = block.split("\n");
|
|
11599
|
-
const kept = lines.filter((line) => {
|
|
11600
|
-
const entry = parseCustomHeaderLine(line);
|
|
11601
|
-
return entry === void 0 || !remove(entry);
|
|
11602
|
-
});
|
|
11603
|
-
return kept.length === lines.length ? block : kept.join("\n");
|
|
11604
|
-
}
|
|
11605
|
-
function parseCustomHeaderLine(line) {
|
|
11606
|
-
const trimmed = line.trim();
|
|
11607
|
-
if (trimmed === "") {
|
|
11608
|
-
return void 0;
|
|
11609
|
-
}
|
|
11610
|
-
const colon = trimmed.indexOf(":");
|
|
11611
|
-
if (colon <= 0) {
|
|
11612
|
-
return void 0;
|
|
11613
|
-
}
|
|
11614
|
-
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
11615
|
-
}
|
|
11616
|
-
var init_headers = __esm({
|
|
11617
|
-
"src/headroom/headers.ts"() {
|
|
11618
|
-
"use strict";
|
|
11619
|
-
}
|
|
11620
|
-
});
|
|
11621
|
-
|
|
11622
|
-
// src/launcher/injected.ts
|
|
11623
|
-
function listKey(list) {
|
|
11624
|
-
return `${list},appended`;
|
|
11625
|
-
}
|
|
11626
|
-
function digest2(value) {
|
|
11627
|
-
return (0, import_node_crypto13.createHash)("sha256").update(value).digest("hex");
|
|
11628
|
-
}
|
|
11629
|
-
function recordedDigests(env) {
|
|
11630
|
-
const raw = env[INJECTED_ENV];
|
|
11631
|
-
if (raw === void 0 || raw === "") {
|
|
11632
|
-
return {};
|
|
11633
|
-
}
|
|
11634
|
-
let parsed;
|
|
11635
|
-
try {
|
|
11636
|
-
parsed = JSON.parse(raw);
|
|
11637
|
-
} catch {
|
|
11638
|
-
return {};
|
|
11639
|
-
}
|
|
11640
|
-
const result = InjectedSchema.safeParse(parsed);
|
|
11641
|
-
return result.success ? result.data : {};
|
|
11642
|
-
}
|
|
11643
|
-
function recordInjections(base) {
|
|
11644
|
-
const env = { ...base };
|
|
11645
|
-
const digests = new Map(Object.entries(recordedDigests(env)));
|
|
11646
|
-
return {
|
|
11647
|
-
env,
|
|
11648
|
-
set: (name, value) => {
|
|
11649
|
-
env[name] = value;
|
|
11650
|
-
digests.set(name, digest2(value));
|
|
11651
|
-
},
|
|
11652
|
-
unset: (name) => {
|
|
11653
|
-
env[name] = void 0;
|
|
11654
|
-
digests.delete(name);
|
|
11655
|
-
},
|
|
11656
|
-
recordHeaders: (names) => {
|
|
11657
|
-
const block = env[CUSTOM_HEADERS_ENV];
|
|
11658
|
-
for (const entry of block === void 0 ? [] : parseAnthropicCustomHeaders(block)) {
|
|
11659
|
-
if (names.includes(entry.name)) {
|
|
11660
|
-
digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
|
|
11661
|
-
}
|
|
11662
|
-
}
|
|
11663
|
-
},
|
|
11664
|
-
recordBypassHosts: (list, hosts) => {
|
|
11665
|
-
const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
|
|
11666
|
-
if (recordedHosts.length > 0) {
|
|
11667
|
-
digests.set(listKey(list), recordedHosts.join(","));
|
|
11668
|
-
}
|
|
11669
|
-
},
|
|
11670
|
-
finish: () => {
|
|
11671
|
-
if (digests.size > 0) {
|
|
11672
|
-
env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
|
|
11673
|
-
}
|
|
11674
|
-
}
|
|
11675
|
-
};
|
|
11676
|
-
}
|
|
11677
|
-
function withoutRecordedHosts(list, value, digests) {
|
|
11678
|
-
const recordedHosts = new Set(digests[listKey(list)]?.split(","));
|
|
11679
|
-
const entries = value.split(",");
|
|
11680
|
-
const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
|
|
11681
|
-
return kept.length === entries.length ? value : kept.join(",");
|
|
11682
|
-
}
|
|
11683
|
-
function launchEnvironment(env, configDirEscapeHatch) {
|
|
11684
|
-
return configDirEscapeHatch ? env : withoutInjected(env);
|
|
11685
|
-
}
|
|
11686
|
-
function withoutInjected(env) {
|
|
11687
|
-
const digests = recordedDigests(env);
|
|
11688
|
-
const entries = Object.entries(env).flatMap(([name, value]) => {
|
|
11689
|
-
if (name === INJECTED_ENV) {
|
|
11690
|
-
return [];
|
|
11691
|
-
}
|
|
11692
|
-
if (value === void 0) {
|
|
11693
|
-
return [[name, value]];
|
|
11694
|
-
}
|
|
11695
|
-
if (name === CUSTOM_HEADERS_ENV) {
|
|
11696
|
-
const remaining = withoutAnthropicCustomHeaders(value, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
|
|
11697
|
-
return remaining !== value && remaining.trim() === "" ? [] : [[name, remaining]];
|
|
11698
|
-
}
|
|
11699
|
-
if (name === "NO_PROXY" || name === "no_proxy") {
|
|
11700
|
-
const remaining = withoutRecordedHosts(name, value, digests);
|
|
11701
|
-
return remaining !== value && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
|
|
11702
|
-
}
|
|
11703
|
-
return digests[name] === digest2(value) ? [] : [[name, value]];
|
|
11704
|
-
});
|
|
11705
|
-
return Object.fromEntries(entries);
|
|
11706
|
-
}
|
|
11707
|
-
var import_node_crypto13, import_zod26, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
|
|
11708
|
-
var init_injected = __esm({
|
|
11709
|
-
"src/launcher/injected.ts"() {
|
|
11710
|
-
"use strict";
|
|
11711
|
-
import_node_crypto13 = require("node:crypto");
|
|
11712
|
-
import_zod26 = require("zod");
|
|
11713
|
-
init_headers();
|
|
11714
|
-
INJECTED_ENV = "AGENT_SHIM_INJECTED";
|
|
11715
|
-
CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
|
|
11716
|
-
HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
|
|
11717
|
-
InjectedSchema = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.string());
|
|
11718
|
-
}
|
|
11719
|
-
});
|
|
11720
|
-
|
|
11721
|
-
// src/launcher/guard.ts
|
|
11722
|
-
function detectAmbientCredential(env, injected) {
|
|
11723
|
-
for (const variable of AMBIENT_CREDENTIAL_VARS) {
|
|
11724
|
-
const value = env[variable];
|
|
11725
|
-
if (value === void 0 || value === "") {
|
|
11726
|
-
continue;
|
|
11727
|
-
}
|
|
11728
|
-
if (injected?.variable === variable && value === injected.token) {
|
|
11729
|
-
continue;
|
|
11730
|
-
}
|
|
11731
|
-
return { variable };
|
|
11732
|
-
}
|
|
11733
|
-
return void 0;
|
|
11734
|
-
}
|
|
11735
|
-
function formatAmbientCredentialGuardMessage(variable, identityName) {
|
|
11736
|
-
const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
|
|
11737
|
-
return [
|
|
11738
|
-
`error: ${variable} is set in the environment. This identity's isolated`,
|
|
11739
|
-
"credential would be bypassed \u2014 every identity authenticates as this same key",
|
|
11740
|
-
"while it's set. Unset it, or if this is deliberate, opt in per-launch with",
|
|
11741
|
-
"AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
|
|
11742
|
-
`\`${identitySetCommand}\`.`
|
|
11743
|
-
].join("\n");
|
|
11744
|
-
}
|
|
11745
|
-
function evaluateAmbientCredentialGuard(params) {
|
|
11746
|
-
const detected = detectAmbientCredential(params.env, params.injectedCredential);
|
|
11747
|
-
if (detected === void 0) {
|
|
11748
|
-
return { ok: true };
|
|
11749
|
-
}
|
|
11750
|
-
if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
|
|
11751
|
-
return { ok: true };
|
|
11752
|
-
}
|
|
11753
|
-
return {
|
|
11754
|
-
ok: false,
|
|
11755
|
-
variable: detected.variable,
|
|
11756
|
-
message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
|
|
11757
|
-
};
|
|
11758
|
-
}
|
|
11759
|
-
function ambientCredentialFinding(env) {
|
|
11760
|
-
const named = detectAmbientCredential(launchEnvironment(env, false));
|
|
11761
|
-
if (named !== void 0) {
|
|
11762
|
-
return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
|
|
11763
|
-
}
|
|
11764
|
-
const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
|
|
11765
|
-
if (bare !== void 0) {
|
|
11766
|
-
return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
|
|
11767
|
-
}
|
|
11768
|
-
return { severity: "pass", message: "No ambient-credential environment variable is set." };
|
|
11769
|
-
}
|
|
11770
|
-
var AMBIENT_CREDENTIAL_VARS;
|
|
11771
|
-
var init_guard = __esm({
|
|
11772
|
-
"src/launcher/guard.ts"() {
|
|
11773
|
-
"use strict";
|
|
11774
|
-
init_injected();
|
|
11775
|
-
AMBIENT_CREDENTIAL_VARS = [
|
|
11776
|
-
"ANTHROPIC_API_KEY",
|
|
11777
|
-
"ANTHROPIC_AUTH_TOKEN",
|
|
11778
|
-
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
11779
|
-
"CLAUDE_CODE_USE_BEDROCK",
|
|
11780
|
-
"CLAUDE_CODE_USE_VERTEX",
|
|
11781
|
-
"CLAUDE_CODE_USE_FOUNDRY"
|
|
11782
|
-
];
|
|
11783
|
-
}
|
|
11784
|
-
});
|
|
11785
|
-
|
|
11786
11815
|
// src/usage/resets.ts
|
|
11787
11816
|
function formatPeriod(window) {
|
|
11788
11817
|
if (window.periodMs === void 0) {
|
|
@@ -12068,7 +12097,7 @@ function parseCatalogueBinding(raw) {
|
|
|
12068
12097
|
}
|
|
12069
12098
|
}
|
|
12070
12099
|
function catalogueCredentialFingerprint(cli, token, accountId) {
|
|
12071
|
-
return (0,
|
|
12100
|
+
return (0, import_node_crypto15.createHash)("sha256").update(JSON.stringify([cli, token, accountId])).digest("hex");
|
|
12072
12101
|
}
|
|
12073
12102
|
function cliCatalogueFingerprint(raw) {
|
|
12074
12103
|
if (raw === void 0) return void 0;
|
|
@@ -12093,11 +12122,11 @@ function savedCatalogueFingerprint(provider, paths, env, home, read) {
|
|
|
12093
12122
|
const codexHome = configuredHome === void 0 || configuredHome === "" ? import_node_path41.default.join(home, ".codex") : configuredHome;
|
|
12094
12123
|
return cliCatalogueFingerprint(read(import_node_path41.default.join(codexHome, "auth.json")));
|
|
12095
12124
|
}
|
|
12096
|
-
var
|
|
12125
|
+
var import_node_crypto15, import_node_path41, import_zod35, CatalogueBindingSchema;
|
|
12097
12126
|
var init_catalogueCredential = __esm({
|
|
12098
12127
|
"src/codex/catalogueCredential.ts"() {
|
|
12099
12128
|
"use strict";
|
|
12100
|
-
|
|
12129
|
+
import_node_crypto15 = require("node:crypto");
|
|
12101
12130
|
import_node_path41 = __toESM(require("node:path"), 1);
|
|
12102
12131
|
import_zod35 = require("zod");
|
|
12103
12132
|
init_siwcStore();
|
|
@@ -12818,7 +12847,7 @@ function ensureFrontDoor(params) {
|
|
|
12818
12847
|
if (supervisorPid !== void 0 && !distrusted.has(supervisorPid) && ports.isRunning(supervisorPid)) {
|
|
12819
12848
|
if (state?.port !== void 0 && state.connectPort !== void 0) {
|
|
12820
12849
|
if (supervisorPid === params.launcherPid && params.replace === void 0 && ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
12821
|
-
const token = (0,
|
|
12850
|
+
const token = (0, import_node_crypto16.randomUUID)();
|
|
12822
12851
|
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
12823
12852
|
return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
|
|
12824
12853
|
}
|
|
@@ -12839,7 +12868,7 @@ function ensureFrontDoor(params) {
|
|
|
12839
12868
|
continue;
|
|
12840
12869
|
}
|
|
12841
12870
|
if (verdict.ok) {
|
|
12842
|
-
const token = (0,
|
|
12871
|
+
const token = (0, import_node_crypto16.randomUUID)();
|
|
12843
12872
|
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
12844
12873
|
return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
|
|
12845
12874
|
}
|
|
@@ -12892,11 +12921,11 @@ function ensureFrontDoor(params) {
|
|
|
12892
12921
|
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
12893
12922
|
}
|
|
12894
12923
|
}
|
|
12895
|
-
var
|
|
12924
|
+
var import_node_crypto16, FRONTDOOR_START_TIMEOUT_MS, FRONTDOOR_LAUNCHER_POLL_MS, FRONTDOOR_PROBE_ATTEMPTS, FRONTDOOR_EXIT_GRACE_MS, FrontDoorStartError;
|
|
12896
12925
|
var init_ensure2 = __esm({
|
|
12897
12926
|
"src/frontdoor/ensure.ts"() {
|
|
12898
12927
|
"use strict";
|
|
12899
|
-
|
|
12928
|
+
import_node_crypto16 = require("node:crypto");
|
|
12900
12929
|
init_cliError();
|
|
12901
12930
|
init_state2();
|
|
12902
12931
|
init_replacement();
|
|
@@ -13565,7 +13594,7 @@ function withLauncherSettings(passthrough, settings) {
|
|
|
13565
13594
|
}
|
|
13566
13595
|
return [...kept, "--settings", settings, ...tail];
|
|
13567
13596
|
}
|
|
13568
|
-
function
|
|
13597
|
+
function isRecord17(value) {
|
|
13569
13598
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13570
13599
|
}
|
|
13571
13600
|
function mergeSettings(parts) {
|
|
@@ -13576,7 +13605,7 @@ function mergeSettings(parts) {
|
|
|
13576
13605
|
continue;
|
|
13577
13606
|
}
|
|
13578
13607
|
const parsed = JSON.parse(part);
|
|
13579
|
-
if (!
|
|
13608
|
+
if (!isRecord17(parsed)) {
|
|
13580
13609
|
throw new Error("a launch's settings part is not a JSON object");
|
|
13581
13610
|
}
|
|
13582
13611
|
for (const [key, value] of Object.entries(parsed)) {
|
|
@@ -14331,10 +14360,22 @@ function decideLaunch(params, readOnly, onRecorded) {
|
|
|
14331
14360
|
...parsedArgv.delay === void 0 ? {} : { delay: parsedArgv.delay }
|
|
14332
14361
|
}
|
|
14333
14362
|
});
|
|
14334
|
-
const loginlessProvider =
|
|
14363
|
+
const loginlessProvider = (() => {
|
|
14364
|
+
if (!requestedFlags.remoteControl || selectedProvider === void 0 || farmIdentity === void 0 || identityDecision.name === void 0) {
|
|
14365
|
+
return void 0;
|
|
14366
|
+
}
|
|
14367
|
+
const stored = params.hasStoredLogin?.(farmIdentity);
|
|
14368
|
+
if (stored === false) {
|
|
14369
|
+
return { identity: identityDecision.name, provider: selectedProvider.name, why: "has no stored login" };
|
|
14370
|
+
}
|
|
14371
|
+
if (stored === true && params.hasUsableLogin?.(farmIdentity, discovered.path) === false) {
|
|
14372
|
+
return { identity: identityDecision.name, provider: selectedProvider.name, why: "has a stored login that is no longer usable" };
|
|
14373
|
+
}
|
|
14374
|
+
return void 0;
|
|
14375
|
+
})();
|
|
14335
14376
|
const notes = [];
|
|
14336
14377
|
if (loginlessProvider !== void 0) {
|
|
14337
|
-
notes.push(`${loginlessProvider.identity}
|
|
14378
|
+
notes.push(`${loginlessProvider.identity} ${loginlessProvider.why}, so Remote Control is off; provider ${loginlessProvider.provider} runs without it`);
|
|
14338
14379
|
}
|
|
14339
14380
|
const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
|
|
14340
14381
|
const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
|
|
@@ -14526,7 +14567,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
|
|
|
14526
14567
|
log.error("agent-shim: this launch routes through the front-door daemon, but this launcher has no front-door port wired; refusing to launch without it.");
|
|
14527
14568
|
proc.exit(1);
|
|
14528
14569
|
}
|
|
14529
|
-
const sessionId = params.supervised?.sessionId ?? (0,
|
|
14570
|
+
const sessionId = params.supervised?.sessionId ?? (0, import_node_crypto17.randomUUID)();
|
|
14530
14571
|
const resolvedModels = decided.models ?? (decided.globalModels === void 0 ? void 0 : {});
|
|
14531
14572
|
const sessionModels = (0, import_node_util2.isDeepStrictEqual)(resolvedModels, decided.globalModels) ? void 0 : resolvedModels;
|
|
14532
14573
|
const session = { sessionId, ...decided.farmIdentity === void 0 ? {} : { identity: decided.farmIdentity }, ...sessionModels === void 0 ? {} : { models: sessionModels } };
|
|
@@ -14634,11 +14675,11 @@ function runLaunchPlan(plan, spawn3) {
|
|
|
14634
14675
|
function runLauncher(params) {
|
|
14635
14676
|
params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
|
|
14636
14677
|
}
|
|
14637
|
-
var
|
|
14678
|
+
var import_node_crypto17, import_node_os8, import_node_util2, import_node_path51;
|
|
14638
14679
|
var init_launcher = __esm({
|
|
14639
14680
|
"src/launcher.ts"() {
|
|
14640
14681
|
"use strict";
|
|
14641
|
-
|
|
14682
|
+
import_node_crypto17 = require("node:crypto");
|
|
14642
14683
|
import_node_os8 = __toESM(require("node:os"), 1);
|
|
14643
14684
|
init_catalogueCredential();
|
|
14644
14685
|
import_node_util2 = require("node:util");
|
|
@@ -14770,18 +14811,18 @@ function resolveTrustBundle(params) {
|
|
|
14770
14811
|
}
|
|
14771
14812
|
const combined = `${inheritedPem.trimEnd()}
|
|
14772
14813
|
${caPem}`;
|
|
14773
|
-
const bundle = import_node_path53.default.join(bundlesDir, `${(0,
|
|
14814
|
+
const bundle = import_node_path53.default.join(bundlesDir, `${(0, import_node_crypto18.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
14774
14815
|
if (!fs17.exists(bundle)) {
|
|
14775
14816
|
fs17.mkdirp(bundlesDir);
|
|
14776
14817
|
fs17.writeFileAtomic(bundle, combined);
|
|
14777
14818
|
}
|
|
14778
14819
|
return { path: bundle };
|
|
14779
14820
|
}
|
|
14780
|
-
var
|
|
14821
|
+
var import_node_crypto18, import_node_path53, BUNDLE_NAME_HEX_DIGITS;
|
|
14781
14822
|
var init_trust = __esm({
|
|
14782
14823
|
"src/frontdoor/trust.ts"() {
|
|
14783
14824
|
"use strict";
|
|
14784
|
-
|
|
14825
|
+
import_node_crypto18 = require("node:crypto");
|
|
14785
14826
|
import_node_path53 = __toESM(require("node:path"), 1);
|
|
14786
14827
|
BUNDLE_NAME_HEX_DIGITS = 16;
|
|
14787
14828
|
}
|
|
@@ -14941,7 +14982,7 @@ function buildFarmRuntime(paths, cwd, run = realRunPort) {
|
|
|
14941
14982
|
...cliOverride === void 0 ? {} : { cliOverride }
|
|
14942
14983
|
}).input,
|
|
14943
14984
|
now: () => Date.now(),
|
|
14944
|
-
uniqueSuffix: `${String(process.pid)}.${(0,
|
|
14985
|
+
uniqueSuffix: `${String(process.pid)}.${(0, import_node_crypto19.randomUUID)()}`,
|
|
14945
14986
|
// Zombie-aware on purpose: a previous launcher that crashed out of a resync without releasing the lock may sit unreaped, still answering signal 0 as alive, and must read as a dead holder so this launch takes the lock over instead of timing out.
|
|
14946
14987
|
lock: { pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync }
|
|
14947
14988
|
},
|
|
@@ -14969,6 +15010,7 @@ function realPrepareLaunchParams(paths, options) {
|
|
|
14969
15010
|
credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
|
|
14970
15011
|
hold: realHoldPort,
|
|
14971
15012
|
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: import_node_path54.default.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
|
|
15013
|
+
hasUsableLogin: (identity, claudeBin) => storedLoginUsable(options.run ?? realRunPort, claudeBin, import_node_path54.default.join(paths.identitiesDir, identity), options.proc.env),
|
|
14972
15014
|
...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
|
|
14973
15015
|
...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
|
|
14974
15016
|
...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },
|
|
@@ -15029,13 +15071,13 @@ function resolveClaudeLaunch(options, run = realRunPort) {
|
|
|
15029
15071
|
};
|
|
15030
15072
|
return { resolution: resolveLaunch(realPrepareLaunchParams(paths, { proc, log, spawnDaemon, run, farm: buildFarmRuntime(paths, options.cwd, run) })), warnings };
|
|
15031
15073
|
}
|
|
15032
|
-
var import_node_os10, import_node_path54,
|
|
15074
|
+
var import_node_os10, import_node_path54, import_node_crypto19, LaunchRefusedError;
|
|
15033
15075
|
var init_launchWiring = __esm({
|
|
15034
15076
|
"src/launchWiring.ts"() {
|
|
15035
15077
|
"use strict";
|
|
15036
15078
|
import_node_os10 = __toESM(require("node:os"), 1);
|
|
15037
15079
|
import_node_path54 = __toESM(require("node:path"), 1);
|
|
15038
|
-
|
|
15080
|
+
import_node_crypto19 = require("node:crypto");
|
|
15039
15081
|
init_cliError();
|
|
15040
15082
|
init_claudeShim();
|
|
15041
15083
|
init_classify();
|
|
@@ -15553,7 +15595,6 @@ __export(index_exports, {
|
|
|
15553
15595
|
RC_GOAL_CONDITION_MAX_CHARS: () => RC_GOAL_CONDITION_MAX_CHARS,
|
|
15554
15596
|
RC_IDLE_EXPIRY_MS: () => RC_IDLE_EXPIRY_MS,
|
|
15555
15597
|
RC_ORPC_PATH_PREFIX: () => RC_ORPC_PATH_PREFIX,
|
|
15556
|
-
RC_PENDING_DEADLINE_MS: () => RC_PENDING_DEADLINE_MS,
|
|
15557
15598
|
RC_PENDING_RETIRE_REASONS: () => RC_PENDING_RETIRE_REASONS,
|
|
15558
15599
|
RC_PERMISSION_MODES: () => RC_PERMISSION_MODES,
|
|
15559
15600
|
RC_READ_FILE_ENCODINGS: () => RC_READ_FILE_ENCODINGS,
|
|
@@ -15864,6 +15905,9 @@ var HTTP_STATUS = {
|
|
|
15864
15905
|
// src/frontdoor/connectEffects.ts
|
|
15865
15906
|
init_connect();
|
|
15866
15907
|
|
|
15908
|
+
// src/frontdoor/rcSessions.ts
|
|
15909
|
+
var import_node_crypto6 = require("node:crypto");
|
|
15910
|
+
|
|
15867
15911
|
// src/agents/liveTasks.ts
|
|
15868
15912
|
var import_zod9 = require("zod");
|
|
15869
15913
|
|
|
@@ -16122,6 +16166,125 @@ function mergeLiveTasks(tree, live) {
|
|
|
16122
16166
|
return { ...tree, agents, remoteSessions, liveOnly };
|
|
16123
16167
|
}
|
|
16124
16168
|
|
|
16169
|
+
// src/frontdoor/rcQuestions.ts
|
|
16170
|
+
var RC_QUESTION_TOOL_NAME = "AskUserQuestion";
|
|
16171
|
+
var RC_QUESTIONS_MAX = 16;
|
|
16172
|
+
var RC_QUESTION_OPTIONS_MAX = 16;
|
|
16173
|
+
var RC_QUESTION_FIELD_MAX_CHARS = 1024;
|
|
16174
|
+
var MULTI_SELECT_SEPARATOR = ", ";
|
|
16175
|
+
function isRecord4(value) {
|
|
16176
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16177
|
+
}
|
|
16178
|
+
function fits(value) {
|
|
16179
|
+
return value === void 0 || value.length <= RC_QUESTION_FIELD_MAX_CHARS;
|
|
16180
|
+
}
|
|
16181
|
+
function optionOf(value) {
|
|
16182
|
+
if (!isRecord4(value) || typeof value.label !== "string" || value.label === "") {
|
|
16183
|
+
return "an option names no label";
|
|
16184
|
+
}
|
|
16185
|
+
const description = typeof value.description === "string" && value.description !== "" ? value.description : void 0;
|
|
16186
|
+
if (!fits(value.label) || !fits(description)) {
|
|
16187
|
+
return `an option is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
16188
|
+
}
|
|
16189
|
+
return description === void 0 ? { label: value.label } : { label: value.label, description };
|
|
16190
|
+
}
|
|
16191
|
+
function questionOf(value) {
|
|
16192
|
+
if (!isRecord4(value) || typeof value.question !== "string" || value.question === "" || !Array.isArray(value.options) || value.options.length === 0) {
|
|
16193
|
+
return "a question has no text or no options";
|
|
16194
|
+
}
|
|
16195
|
+
if (value.options.length > RC_QUESTION_OPTIONS_MAX) {
|
|
16196
|
+
return `a question has more than ${String(RC_QUESTION_OPTIONS_MAX)} options`;
|
|
16197
|
+
}
|
|
16198
|
+
const options = [];
|
|
16199
|
+
for (const candidate of value.options) {
|
|
16200
|
+
const option = optionOf(candidate);
|
|
16201
|
+
if (typeof option === "string") {
|
|
16202
|
+
return option;
|
|
16203
|
+
}
|
|
16204
|
+
if (options.some((existing) => existing.label === option.label)) {
|
|
16205
|
+
return `a question lists the option ${JSON.stringify(option.label)} twice`;
|
|
16206
|
+
}
|
|
16207
|
+
options.push(option);
|
|
16208
|
+
}
|
|
16209
|
+
const header = typeof value.header === "string" && value.header !== "" ? value.header : void 0;
|
|
16210
|
+
if (!fits(value.question) || !fits(header)) {
|
|
16211
|
+
return `a question is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
16212
|
+
}
|
|
16213
|
+
return { question: value.question, ...header === void 0 ? {} : { header }, multiSelect: value.multiSelect === true, options };
|
|
16214
|
+
}
|
|
16215
|
+
function rcQuestionsOfToolRequest(toolName, input) {
|
|
16216
|
+
if (toolName !== RC_QUESTION_TOOL_NAME) {
|
|
16217
|
+
return void 0;
|
|
16218
|
+
}
|
|
16219
|
+
if (!isRecord4(input) || !Array.isArray(input.questions) || input.questions.length === 0) {
|
|
16220
|
+
return { unanswerable: "the request names no questions" };
|
|
16221
|
+
}
|
|
16222
|
+
if (input.questions.length > RC_QUESTIONS_MAX) {
|
|
16223
|
+
return { unanswerable: `the request asks more than ${String(RC_QUESTIONS_MAX)} questions` };
|
|
16224
|
+
}
|
|
16225
|
+
const questions = [];
|
|
16226
|
+
for (const candidate of input.questions) {
|
|
16227
|
+
const question = questionOf(candidate);
|
|
16228
|
+
if (typeof question === "string") {
|
|
16229
|
+
return { unanswerable: question };
|
|
16230
|
+
}
|
|
16231
|
+
if (questions.some((existing) => existing.question === question.question)) {
|
|
16232
|
+
return { unanswerable: `the request asks ${JSON.stringify(question.question)} twice` };
|
|
16233
|
+
}
|
|
16234
|
+
questions.push(question);
|
|
16235
|
+
}
|
|
16236
|
+
return { questions };
|
|
16237
|
+
}
|
|
16238
|
+
function resolveSelection(question, questionNumber, selection) {
|
|
16239
|
+
if (typeof selection === "number") {
|
|
16240
|
+
const option = Number.isInteger(selection) ? question.options[selection - 1] : void 0;
|
|
16241
|
+
return option === void 0 ? { error: `question ${String(questionNumber)} has no option ${String(selection)}: its options are numbered 1 to ${String(question.options.length)}` } : { text: option.label };
|
|
16242
|
+
}
|
|
16243
|
+
if (typeof selection === "object") {
|
|
16244
|
+
const text = selection.text.trim();
|
|
16245
|
+
return text === "" ? { error: `question ${String(questionNumber)}'s free-text answer is empty` } : { text };
|
|
16246
|
+
}
|
|
16247
|
+
const exact = question.options.find((option) => option.label === selection);
|
|
16248
|
+
if (exact !== void 0) {
|
|
16249
|
+
return { text: exact.label };
|
|
16250
|
+
}
|
|
16251
|
+
const folded = question.options.filter((option) => option.label.toLowerCase() === selection.toLowerCase());
|
|
16252
|
+
const [only] = folded;
|
|
16253
|
+
if (only !== void 0 && folded.length === 1) {
|
|
16254
|
+
return { text: only.label };
|
|
16255
|
+
}
|
|
16256
|
+
return { error: `question ${String(questionNumber)} has no option labelled ${JSON.stringify(selection)}: its options are ${question.options.map((option) => JSON.stringify(option.label)).join(", ")}` };
|
|
16257
|
+
}
|
|
16258
|
+
function resolveRcQuestionAnswers(questions, choices) {
|
|
16259
|
+
if (choices.length !== questions.length) {
|
|
16260
|
+
return { error: `the request asks ${String(questions.length)} question(s), so the answer must choose for each of them in order, but it chose for ${String(choices.length)}` };
|
|
16261
|
+
}
|
|
16262
|
+
const answers = {};
|
|
16263
|
+
for (const [index, question] of questions.entries()) {
|
|
16264
|
+
const questionNumber = index + 1;
|
|
16265
|
+
const selections = choices[index] ?? [];
|
|
16266
|
+
if (selections.length === 0) {
|
|
16267
|
+
return { error: `question ${String(questionNumber)} has no selection` };
|
|
16268
|
+
}
|
|
16269
|
+
if (!question.multiSelect && selections.length > 1) {
|
|
16270
|
+
return { error: `question ${String(questionNumber)} takes one option, but ${String(selections.length)} were chosen` };
|
|
16271
|
+
}
|
|
16272
|
+
const texts = [];
|
|
16273
|
+
for (const selection of selections) {
|
|
16274
|
+
const resolved = resolveSelection(question, questionNumber, selection);
|
|
16275
|
+
if ("error" in resolved) {
|
|
16276
|
+
return resolved;
|
|
16277
|
+
}
|
|
16278
|
+
if (texts.includes(resolved.text)) {
|
|
16279
|
+
return { error: `question ${String(questionNumber)} chose ${JSON.stringify(resolved.text)} twice` };
|
|
16280
|
+
}
|
|
16281
|
+
texts.push(resolved.text);
|
|
16282
|
+
}
|
|
16283
|
+
answers[question.question] = texts.join(MULTI_SELECT_SEPARATOR);
|
|
16284
|
+
}
|
|
16285
|
+
return { answers };
|
|
16286
|
+
}
|
|
16287
|
+
|
|
16125
16288
|
// src/frontdoor/rcSessions.ts
|
|
16126
16289
|
var RC_SESSIONS_PATH_PREFIX = "/v1/code/sessions";
|
|
16127
16290
|
function pathnameOf(url) {
|
|
@@ -16136,7 +16299,12 @@ var RC_IDLE_EXPIRY_MS = 45e3;
|
|
|
16136
16299
|
var RC_CREATE_RESPONSE_CAP_BYTES = 8192;
|
|
16137
16300
|
var CONFLICT_REASON_HEADER = "x-ccr-conflict-reason";
|
|
16138
16301
|
var RC_STREAM_WORKER_SOURCE = "worker";
|
|
16139
|
-
var
|
|
16302
|
+
var HIGH_SURROGATE_FIRST = 55296;
|
|
16303
|
+
var HIGH_SURROGATE_LAST = 56319;
|
|
16304
|
+
var RC_WORKER_IDLE = "idle";
|
|
16305
|
+
var RC_PENDING_PER_SESSION_MAX = 64;
|
|
16306
|
+
var RC_REQUEST_ID_MAX_CHARS = 128;
|
|
16307
|
+
var RC_RETIRED_TOMBSTONES_MAX = 2 * RC_PENDING_PER_SESSION_MAX;
|
|
16140
16308
|
var RC_REQUEST_PARSE_CAP_BYTES = 262144;
|
|
16141
16309
|
var RC_PENDING_SUMMARY_EXCERPT_CHARS = 300;
|
|
16142
16310
|
var SUCCESS_STATUS_MAX_EXCLUSIVE = 300;
|
|
@@ -16169,7 +16337,7 @@ function sessionCreateId(body) {
|
|
|
16169
16337
|
const id = session.id;
|
|
16170
16338
|
return typeof id === "string" && id.startsWith(RC_SESSION_ID_PREFIX) ? id : void 0;
|
|
16171
16339
|
}
|
|
16172
|
-
function
|
|
16340
|
+
function isRecord5(value) {
|
|
16173
16341
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16174
16342
|
}
|
|
16175
16343
|
function parseJsonObject(body) {
|
|
@@ -16179,7 +16347,7 @@ function parseJsonObject(body) {
|
|
|
16179
16347
|
} catch {
|
|
16180
16348
|
return void 0;
|
|
16181
16349
|
}
|
|
16182
|
-
return
|
|
16350
|
+
return isRecord5(parsed) ? parsed : void 0;
|
|
16183
16351
|
}
|
|
16184
16352
|
function nonEmptyString(record, field) {
|
|
16185
16353
|
const value = record === void 0 ? void 0 : record[field];
|
|
@@ -16189,8 +16357,16 @@ function finiteNumber(record, field) {
|
|
|
16189
16357
|
const value = record === void 0 ? void 0 : record[field];
|
|
16190
16358
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
16191
16359
|
}
|
|
16192
|
-
function
|
|
16193
|
-
|
|
16360
|
+
function rcExcerpt(text) {
|
|
16361
|
+
if (text.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS) {
|
|
16362
|
+
return text;
|
|
16363
|
+
}
|
|
16364
|
+
const cut = text.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS);
|
|
16365
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
16366
|
+
return `${isHighSurrogate(last) ? cut.slice(0, -1) : cut}...`;
|
|
16367
|
+
}
|
|
16368
|
+
function isHighSurrogate(unit) {
|
|
16369
|
+
return unit >= HIGH_SURROGATE_FIRST && unit <= HIGH_SURROGATE_LAST;
|
|
16194
16370
|
}
|
|
16195
16371
|
function payloadEventsOf(body) {
|
|
16196
16372
|
const parsed = parseJsonObject(body);
|
|
@@ -16200,11 +16376,11 @@ function payloadEventsOf(body) {
|
|
|
16200
16376
|
}
|
|
16201
16377
|
const payloads = [];
|
|
16202
16378
|
for (const event of events) {
|
|
16203
|
-
if (!
|
|
16379
|
+
if (!isRecord5(event)) {
|
|
16204
16380
|
continue;
|
|
16205
16381
|
}
|
|
16206
16382
|
const payload = event.payload;
|
|
16207
|
-
if (!
|
|
16383
|
+
if (!isRecord5(payload)) {
|
|
16208
16384
|
continue;
|
|
16209
16385
|
}
|
|
16210
16386
|
payloads.push(payload);
|
|
@@ -16212,6 +16388,14 @@ function payloadEventsOf(body) {
|
|
|
16212
16388
|
return payloads;
|
|
16213
16389
|
}
|
|
16214
16390
|
function pendingOfControlRequestPayload(payload) {
|
|
16391
|
+
const parsed = fullPendingOfControlRequestPayload(payload);
|
|
16392
|
+
const isQuestion = parsed !== void 0 && (parsed.questions !== void 0 || parsed.unanswerable !== void 0);
|
|
16393
|
+
if (parsed === void 0 || !isQuestion || Buffer.byteLength(JSON.stringify(payload), "utf8") <= RC_REQUEST_PARSE_CAP_BYTES) {
|
|
16394
|
+
return parsed;
|
|
16395
|
+
}
|
|
16396
|
+
return { ...parsed, questions: void 0, toolInput: void 0, oversized: true, unanswerable: parsed.unanswerable ?? `the request is past the door's parse cap of ${String(RC_REQUEST_PARSE_CAP_BYTES)} bytes` };
|
|
16397
|
+
}
|
|
16398
|
+
function fullPendingOfControlRequestPayload(payload) {
|
|
16215
16399
|
if (payload.type !== "control_request") {
|
|
16216
16400
|
return void 0;
|
|
16217
16401
|
}
|
|
@@ -16219,24 +16403,41 @@ function pendingOfControlRequestPayload(payload) {
|
|
|
16219
16403
|
if (requestId === void 0) {
|
|
16220
16404
|
return void 0;
|
|
16221
16405
|
}
|
|
16222
|
-
const request4 =
|
|
16406
|
+
const request4 = isRecord5(payload.request) ? payload.request : void 0;
|
|
16223
16407
|
const subtype = nonEmptyString(request4, "subtype");
|
|
16224
16408
|
const type = subtype ?? "control_request";
|
|
16225
16409
|
let summary = "";
|
|
16410
|
+
let questions;
|
|
16411
|
+
let unanswerable;
|
|
16412
|
+
let toolInput;
|
|
16226
16413
|
if (subtype === "can_use_tool") {
|
|
16227
|
-
const toolName = nonEmptyString(request4, "tool_name")
|
|
16414
|
+
const toolName = nonEmptyString(request4, "tool_name");
|
|
16228
16415
|
const input = request4 === void 0 ? void 0 : request4.input;
|
|
16229
|
-
summary = input === void 0 ? toolName : `${toolName} ${
|
|
16416
|
+
summary = input === void 0 ? toolName ?? "unknown tool" : `${toolName ?? "unknown tool"} ${rcExcerpt(JSON.stringify(input))}`;
|
|
16417
|
+
const parsedQuestions = rcQuestionsOfToolRequest(toolName, input);
|
|
16418
|
+
if (parsedQuestions !== void 0 && "questions" in parsedQuestions) {
|
|
16419
|
+
questions = parsedQuestions.questions;
|
|
16420
|
+
toolInput = isRecord5(input) ? input : void 0;
|
|
16421
|
+
} else if (parsedQuestions !== void 0) {
|
|
16422
|
+
unanswerable = parsedQuestions.unanswerable;
|
|
16423
|
+
}
|
|
16230
16424
|
} else if (request4 !== void 0) {
|
|
16231
|
-
summary =
|
|
16425
|
+
summary = rcExcerpt(JSON.stringify(request4));
|
|
16232
16426
|
}
|
|
16233
|
-
return { requestId, type, summary };
|
|
16427
|
+
return { requestId, type, summary, questions, unanswerable, toolInput, oversized: false };
|
|
16428
|
+
}
|
|
16429
|
+
function withdrawnRequestIdsOfControlCancelPayload(payload) {
|
|
16430
|
+
if (payload.type !== "control_cancel_request") {
|
|
16431
|
+
return [];
|
|
16432
|
+
}
|
|
16433
|
+
const id = nonEmptyString(payload, "request_id");
|
|
16434
|
+
return id === void 0 ? [] : [id];
|
|
16234
16435
|
}
|
|
16235
16436
|
function answeredRequestIdsOfControlResponsePayload(payload) {
|
|
16236
16437
|
if (payload.type !== "control_response") {
|
|
16237
16438
|
return [];
|
|
16238
16439
|
}
|
|
16239
|
-
const response =
|
|
16440
|
+
const response = isRecord5(payload.response) ? payload.response : void 0;
|
|
16240
16441
|
const id = nonEmptyString(response, "request_id") ?? nonEmptyString(payload, "request_id") ?? nonEmptyString(payload, "uuid");
|
|
16241
16442
|
return id === void 0 ? [] : [id];
|
|
16242
16443
|
}
|
|
@@ -16248,44 +16449,74 @@ function initFactsOfPayload(payload) {
|
|
|
16248
16449
|
}
|
|
16249
16450
|
function parseRcRequestBody(kind, body) {
|
|
16250
16451
|
if (kind === "heartbeat") {
|
|
16251
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, payloads: [] };
|
|
16452
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, workerEpoch: void 0, payloads: [] };
|
|
16252
16453
|
}
|
|
16253
16454
|
if (kind === "worker-registration") {
|
|
16254
16455
|
const registration = parseJsonObject(body);
|
|
16255
|
-
const metadata = registration === void 0 || !
|
|
16456
|
+
const metadata = registration === void 0 || !isRecord5(registration.external_metadata) ? void 0 : registration.external_metadata;
|
|
16256
16457
|
const model = nonEmptyString(metadata, "model");
|
|
16257
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
16458
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), workerEpoch: finiteNumber(registration, "worker_epoch"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
16258
16459
|
}
|
|
16259
16460
|
const controlRequests = [];
|
|
16260
16461
|
const answeredRequestIds = [];
|
|
16462
|
+
const withdrawnRequestIds = [];
|
|
16261
16463
|
const payloads = payloadEventsOf(body);
|
|
16262
16464
|
for (const payload of payloads) {
|
|
16263
16465
|
const pending = pendingOfControlRequestPayload(payload);
|
|
16264
16466
|
if (pending !== void 0) {
|
|
16265
|
-
controlRequests.push(
|
|
16467
|
+
controlRequests.push(pending);
|
|
16266
16468
|
continue;
|
|
16267
16469
|
}
|
|
16268
16470
|
answeredRequestIds.push(...answeredRequestIdsOfControlResponsePayload(payload));
|
|
16471
|
+
if (kind === "worker-events") {
|
|
16472
|
+
withdrawnRequestIds.push(...withdrawnRequestIdsOfControlCancelPayload(payload));
|
|
16473
|
+
}
|
|
16474
|
+
}
|
|
16475
|
+
return { controlRequests, answeredRequestIds, withdrawnRequestIds, idleSeconds: void 0, workerStatus: void 0, workerEpoch: void 0, payloads };
|
|
16476
|
+
}
|
|
16477
|
+
function rememberBounded(record, key) {
|
|
16478
|
+
record.delete(key);
|
|
16479
|
+
record.add(key);
|
|
16480
|
+
if (record.size > RC_RETIRED_TOMBSTONES_MAX) {
|
|
16481
|
+
const [oldest] = record;
|
|
16482
|
+
if (oldest !== void 0) {
|
|
16483
|
+
record.delete(oldest);
|
|
16484
|
+
}
|
|
16269
16485
|
}
|
|
16270
|
-
|
|
16486
|
+
}
|
|
16487
|
+
function droppedKeyOf(requestId) {
|
|
16488
|
+
return requestId.length <= RC_REQUEST_ID_MAX_CHARS ? requestId : (0, import_node_crypto6.createHash)("sha256").update(requestId).digest("hex");
|
|
16271
16489
|
}
|
|
16272
16490
|
function createRcSessionTracker(deps) {
|
|
16273
16491
|
const entries = /* @__PURE__ */ new Map();
|
|
16492
|
+
let observationSequence = 0;
|
|
16493
|
+
const rememberRetired = (entry, requestId) => {
|
|
16494
|
+
rememberBounded(entry.retired, requestId);
|
|
16495
|
+
};
|
|
16274
16496
|
const retirePending = (entry, requestId, reason) => {
|
|
16275
16497
|
if (entry.pending.delete(requestId)) {
|
|
16276
|
-
entry
|
|
16498
|
+
rememberRetired(entry, requestId);
|
|
16277
16499
|
deps.onTransition?.({ kind: "pending-retired", session: entry.id, requestId, reason, at: deps.now() });
|
|
16278
16500
|
}
|
|
16279
16501
|
};
|
|
16280
|
-
const addPending = (entry,
|
|
16281
|
-
|
|
16502
|
+
const addPending = (entry, request4, now) => {
|
|
16503
|
+
const droppedKey = droppedKeyOf(request4.requestId);
|
|
16504
|
+
if (entry.retired.has(request4.requestId) || entry.dropped.has(droppedKey)) {
|
|
16505
|
+
return;
|
|
16506
|
+
}
|
|
16507
|
+
const already = entry.pending.get(request4.requestId);
|
|
16508
|
+
if (already !== void 0) {
|
|
16509
|
+
entry.pending.set(request4.requestId, { ...already, ...request4, observedAt: already.observedAt });
|
|
16282
16510
|
return;
|
|
16283
16511
|
}
|
|
16284
|
-
|
|
16285
|
-
|
|
16286
|
-
|
|
16287
|
-
|
|
16512
|
+
if (request4.requestId.length > RC_REQUEST_ID_MAX_CHARS || entry.pending.size >= RC_PENDING_PER_SESSION_MAX) {
|
|
16513
|
+
entry.droppedPending += 1;
|
|
16514
|
+
rememberBounded(entry.dropped, droppedKey);
|
|
16515
|
+
return;
|
|
16288
16516
|
}
|
|
16517
|
+
observationSequence += 1;
|
|
16518
|
+
entry.pending.set(request4.requestId, { sessionId: entry.id, ...request4, observedAt: now, observedSequence: observationSequence });
|
|
16519
|
+
deps.onTransition?.({ kind: "pending-born", session: entry.id, requestId: request4.requestId, type: request4.type, summary: request4.summary, at: now });
|
|
16289
16520
|
};
|
|
16290
16521
|
const expire = (id, reason) => {
|
|
16291
16522
|
const entry = entries.get(id);
|
|
@@ -16298,31 +16529,17 @@ function createRcSessionTracker(deps) {
|
|
|
16298
16529
|
entries.delete(id);
|
|
16299
16530
|
deps.onTransition?.({ kind: "session-ended", session: id, reason, at: deps.now() });
|
|
16300
16531
|
};
|
|
16301
|
-
const expirePendings = (entry, now) => {
|
|
16302
|
-
for (const [requestId, pending] of entry.pending) {
|
|
16303
|
-
if (now - pending.observedAt >= RC_PENDING_DEADLINE_MS) {
|
|
16304
|
-
retirePending(entry, requestId, "expired");
|
|
16305
|
-
}
|
|
16306
|
-
}
|
|
16307
|
-
for (const [requestId, retiredAt] of entry.retired) {
|
|
16308
|
-
if (now - retiredAt >= RC_PENDING_DEADLINE_MS) {
|
|
16309
|
-
entry.retired.delete(requestId);
|
|
16310
|
-
}
|
|
16311
|
-
}
|
|
16312
|
-
};
|
|
16313
16532
|
const sweep = () => {
|
|
16314
16533
|
for (const [id, entry] of entries) {
|
|
16315
16534
|
if (deps.now() - entry.lastSeenAt >= deps.idleMs) {
|
|
16316
16535
|
expire(id, "expired");
|
|
16317
|
-
continue;
|
|
16318
16536
|
}
|
|
16319
|
-
expirePendings(entry, deps.now());
|
|
16320
16537
|
}
|
|
16321
16538
|
};
|
|
16322
|
-
const timer = setInterval(sweep,
|
|
16539
|
+
const timer = setInterval(sweep, deps.idleMs);
|
|
16323
16540
|
timer.unref();
|
|
16324
16541
|
const birth = (id, facts) => {
|
|
16325
|
-
const record = { id, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new
|
|
16542
|
+
const record = { id, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new Set(), dropped: /* @__PURE__ */ new Set(), workerState: void 0, workerIdleSeconds: void 0, model: void 0, cwd: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map(), workerEpoch: void 0, droppedPending: 0, answering: /* @__PURE__ */ new Set() };
|
|
16326
16543
|
entries.set(id, record);
|
|
16327
16544
|
deps.onTransition?.({ kind: "session-appeared", session: id, at: record.createdAt });
|
|
16328
16545
|
return record;
|
|
@@ -16353,6 +16570,7 @@ function createRcSessionTracker(deps) {
|
|
|
16353
16570
|
return void 0;
|
|
16354
16571
|
}
|
|
16355
16572
|
const tail = pathnameOf(request4.url).slice(RC_SESSIONS_PATH_PREFIX.length);
|
|
16573
|
+
const startedAtSequence = observationSequence;
|
|
16356
16574
|
const facts = {
|
|
16357
16575
|
oauthAuthorization: oauthAuthorizationOf(request4.headers),
|
|
16358
16576
|
anthropicVersion: singleHeader(request4.headers, "anthropic-version"),
|
|
@@ -16426,11 +16644,14 @@ function createRcSessionTracker(deps) {
|
|
|
16426
16644
|
}
|
|
16427
16645
|
const now = deps.now();
|
|
16428
16646
|
for (const controlRequest of factsOfBody.controlRequests) {
|
|
16429
|
-
addPending(entryNow,
|
|
16647
|
+
addPending(entryNow, controlRequest, now);
|
|
16430
16648
|
}
|
|
16431
16649
|
for (const requestId of factsOfBody.answeredRequestIds) {
|
|
16432
16650
|
retirePending(entryNow, requestId, "answered");
|
|
16433
16651
|
}
|
|
16652
|
+
for (const requestId of factsOfBody.withdrawnRequestIds) {
|
|
16653
|
+
retirePending(entryNow, requestId, "withdrawn");
|
|
16654
|
+
}
|
|
16434
16655
|
for (const payload of factsOfBody.payloads) {
|
|
16435
16656
|
entryNow.liveTasks = applyAgentTaskEvent(entryNow.liveTasks, id, payload, now);
|
|
16436
16657
|
noteInit(entryNow, payload);
|
|
@@ -16446,6 +16667,17 @@ function createRcSessionTracker(deps) {
|
|
|
16446
16667
|
deps.onTransition?.({ kind: "worker-state", session: id, state: factsOfBody.workerStatus, ...previous === void 0 ? {} : { previous }, at: now });
|
|
16447
16668
|
}
|
|
16448
16669
|
}
|
|
16670
|
+
const epochChanged = factsOfBody.workerEpoch !== void 0 && entryNow.workerEpoch !== void 0 && factsOfBody.workerEpoch !== entryNow.workerEpoch;
|
|
16671
|
+
if (factsOfBody.workerEpoch !== void 0) {
|
|
16672
|
+
entryNow.workerEpoch = factsOfBody.workerEpoch;
|
|
16673
|
+
}
|
|
16674
|
+
if (epochChanged || factsOfBody.workerStatus === RC_WORKER_IDLE) {
|
|
16675
|
+
for (const [requestId, pending] of entryNow.pending) {
|
|
16676
|
+
if (pending.observedSequence <= startedAtSequence) {
|
|
16677
|
+
retirePending(entryNow, requestId, "worker-stopped");
|
|
16678
|
+
}
|
|
16679
|
+
}
|
|
16680
|
+
}
|
|
16449
16681
|
};
|
|
16450
16682
|
const archiving = method === "POST" && rest === `${id}/archive`;
|
|
16451
16683
|
return {
|
|
@@ -16485,7 +16717,7 @@ function createRcSessionTracker(deps) {
|
|
|
16485
16717
|
};
|
|
16486
16718
|
};
|
|
16487
16719
|
const summaryOf2 = ({ id, createdAt, lastSeenAt }) => ({ id, createdAt, lastSeenAt });
|
|
16488
|
-
const pendingSummaryOf = ({ sessionId, requestId, type, summary, observedAt: observedAt2 }) => ({ sessionId, requestId, type, summary, observedAt: observedAt2 });
|
|
16720
|
+
const pendingSummaryOf = ({ sessionId, requestId, type, summary, questions, unanswerable, oversized, observedAt: observedAt2 }) => ({ sessionId, requestId, type, summary, ...questions === void 0 ? {} : { questions }, ...oversized ? { oversized: true } : {}, ...unanswerable === void 0 ? {} : { unanswerable }, observedAt: observedAt2 });
|
|
16489
16721
|
const sortedEntries = () => [...entries.values()].sort((left, right) => left.createdAt - right.createdAt || (left.id < right.id ? -1 : 1));
|
|
16490
16722
|
const pendingSorted = (entry) => [...entry.pending.values()].sort((left, right) => left.observedAt - right.observedAt || (left.requestId < right.requestId ? -1 : 1)).map(pendingSummaryOf);
|
|
16491
16723
|
return {
|
|
@@ -16503,7 +16735,8 @@ function createRcSessionTracker(deps) {
|
|
|
16503
16735
|
pending: pendingSorted(entry),
|
|
16504
16736
|
...entry.identity === void 0 ? {} : { identity: entry.identity },
|
|
16505
16737
|
...entry.model === void 0 ? {} : { model: entry.model },
|
|
16506
|
-
...entry.cwd === void 0 ? {} : { cwd: entry.cwd }
|
|
16738
|
+
...entry.cwd === void 0 ? {} : { cwd: entry.cwd },
|
|
16739
|
+
...entry.droppedPending === 0 ? {} : { pendingDropped: entry.droppedPending }
|
|
16507
16740
|
}));
|
|
16508
16741
|
},
|
|
16509
16742
|
pendingOf: (sessionId) => {
|
|
@@ -16541,7 +16774,7 @@ function createRcSessionTracker(deps) {
|
|
|
16541
16774
|
return;
|
|
16542
16775
|
}
|
|
16543
16776
|
entry.sequenceNum = entry.sequenceNum === void 0 || event.sequence_num > entry.sequenceNum ? event.sequence_num : entry.sequenceNum;
|
|
16544
|
-
if (!
|
|
16777
|
+
if (!isRecord5(event.payload)) {
|
|
16545
16778
|
return;
|
|
16546
16779
|
}
|
|
16547
16780
|
entry.liveTasks = applyAgentTaskEvent(entry.liveTasks, sessionId, event.payload, deps.now());
|
|
@@ -16549,13 +16782,18 @@ function createRcSessionTracker(deps) {
|
|
|
16549
16782
|
const pending = pendingOfControlRequestPayload(event.payload);
|
|
16550
16783
|
if (pending !== void 0) {
|
|
16551
16784
|
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
16552
|
-
addPending(entry,
|
|
16785
|
+
addPending(entry, pending, deps.now());
|
|
16553
16786
|
}
|
|
16554
16787
|
return;
|
|
16555
16788
|
}
|
|
16556
16789
|
for (const requestId of answeredRequestIdsOfControlResponsePayload(event.payload)) {
|
|
16557
16790
|
retirePending(entry, requestId, "answered");
|
|
16558
16791
|
}
|
|
16792
|
+
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
16793
|
+
for (const requestId of withdrawnRequestIdsOfControlCancelPayload(event.payload)) {
|
|
16794
|
+
retirePending(entry, requestId, "withdrawn");
|
|
16795
|
+
}
|
|
16796
|
+
}
|
|
16559
16797
|
},
|
|
16560
16798
|
liveTasksOf: (sessionId) => {
|
|
16561
16799
|
sweep();
|
|
@@ -16567,6 +16805,17 @@ function createRcSessionTracker(deps) {
|
|
|
16567
16805
|
retirePending(entry, requestId, "answered");
|
|
16568
16806
|
}
|
|
16569
16807
|
},
|
|
16808
|
+
claimPending: (sessionId, requestId) => {
|
|
16809
|
+
const entry = entries.get(sessionId);
|
|
16810
|
+
if (entry === void 0 || !entry.pending.has(requestId) || entry.answering.has(requestId)) {
|
|
16811
|
+
return void 0;
|
|
16812
|
+
}
|
|
16813
|
+
entry.answering.add(requestId);
|
|
16814
|
+
return () => {
|
|
16815
|
+
entry.answering.delete(requestId);
|
|
16816
|
+
};
|
|
16817
|
+
},
|
|
16818
|
+
pendingToolInputOf: (sessionId, requestId) => entries.get(sessionId)?.pending.get(requestId)?.toolInput,
|
|
16570
16819
|
close: () => {
|
|
16571
16820
|
clearInterval(timer);
|
|
16572
16821
|
deps.onClose?.();
|
|
@@ -16733,8 +16982,8 @@ async function injectRcUserMessage(deps, sessionId, text) {
|
|
|
16733
16982
|
}
|
|
16734
16983
|
return result;
|
|
16735
16984
|
}
|
|
16736
|
-
function buildRcControlResponsePayload(requestId, decision) {
|
|
16737
|
-
const result = decision.approve ? { behavior: "allow" } : { behavior: "deny", message: decision.message ?? "" };
|
|
16985
|
+
function buildRcControlResponsePayload(requestId, decision, updatedInput) {
|
|
16986
|
+
const result = decision.approve ? { behavior: "allow", ...updatedInput === void 0 ? {} : { updatedInput } } : { behavior: "deny", message: decision.message ?? "" };
|
|
16738
16987
|
return { type: "control_response", response: { subtype: "success", request_id: requestId, response: result } };
|
|
16739
16988
|
}
|
|
16740
16989
|
var RC_PERMISSION_MODES = ["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk", "auto"];
|
|
@@ -16791,6 +17040,27 @@ function buildRcMcpOAuthCallbackUrlPayload(requestId, serverName, callbackUrl) {
|
|
|
16791
17040
|
function buildRcKeepAlivePayload() {
|
|
16792
17041
|
return { type: "keep_alive" };
|
|
16793
17042
|
}
|
|
17043
|
+
function questionAnswerInput(deps, sessionId, pending, decision) {
|
|
17044
|
+
const { questions, unanswerable } = pending;
|
|
17045
|
+
if (questions === void 0 && unanswerable === void 0) {
|
|
17046
|
+
return decision.choices === void 0 ? void 0 : { error: `control request ${pending.requestId} is not a question (it is ${pending.type}${pending.summary === "" ? "" : `: ${pending.summary}`}), so it has no options to choose; approve or deny it instead` };
|
|
17047
|
+
}
|
|
17048
|
+
if (!decision.approve) {
|
|
17049
|
+
return decision.choices === void 0 ? void 0 : { error: "a denial dismisses the question and carries no choices; choose options to answer it, or deny it without them" };
|
|
17050
|
+
}
|
|
17051
|
+
if (questions === void 0) {
|
|
17052
|
+
return { error: `control request ${pending.requestId} is a question the door cannot answer (${String(unanswerable)}), so it cannot write an answer the worker would read correctly; answer it in the session itself, or deny it to dismiss it` };
|
|
17053
|
+
}
|
|
17054
|
+
if (decision.choices === void 0) {
|
|
17055
|
+
return { error: `control request ${pending.requestId} is a question, so answering it means choosing an option for each of its ${String(questions.length)} question(s); deny it to dismiss it` };
|
|
17056
|
+
}
|
|
17057
|
+
const input = deps.pendingToolInputOf(sessionId, pending.requestId);
|
|
17058
|
+
if (input === void 0) {
|
|
17059
|
+
return { error: `the front door holds no input for question ${pending.requestId} on session ${sessionId}, so it cannot write the answer the worker expects` };
|
|
17060
|
+
}
|
|
17061
|
+
const resolved = resolveRcQuestionAnswers(questions, decision.choices);
|
|
17062
|
+
return "error" in resolved ? resolved : { input: { ...input, answers: resolved.answers } };
|
|
17063
|
+
}
|
|
16794
17064
|
async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
16795
17065
|
const credential = deps.credentialOf(sessionId);
|
|
16796
17066
|
if (credential === void 0) {
|
|
@@ -16799,15 +17069,26 @@ async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
|
16799
17069
|
if (credential.authorization === void 0) {
|
|
16800
17070
|
return noOAuthCredentialResult(sessionId);
|
|
16801
17071
|
}
|
|
16802
|
-
|
|
16803
|
-
|
|
17072
|
+
const pending = deps.pendingOf(sessionId).find((candidate) => candidate.requestId === requestId);
|
|
17073
|
+
if (pending === void 0) {
|
|
17074
|
+
return { ok: false, message: `the front door has not observed control request ${requestId} pending on session ${sessionId}: it was answered already (by this door, by an attached client or in the session's own terminal), the worker withdrew it, or it never passed through this door` };
|
|
17075
|
+
}
|
|
17076
|
+
const updatedInput = questionAnswerInput(deps, sessionId, pending, decision);
|
|
17077
|
+
if (updatedInput !== void 0 && "error" in updatedInput) {
|
|
17078
|
+
return { ok: false, message: updatedInput.error };
|
|
17079
|
+
}
|
|
17080
|
+
const release = deps.claimPending(sessionId, requestId);
|
|
17081
|
+
if (release === void 0) {
|
|
17082
|
+
return { ok: false, message: `another answer to control request ${requestId} on session ${sessionId} is being written right now; the worker takes only one, so this one was not sent` };
|
|
16804
17083
|
}
|
|
16805
|
-
const body = JSON.stringify(buildRcEventWriteBody(buildRcControlResponsePayload(requestId, decision)));
|
|
17084
|
+
const body = JSON.stringify(buildRcEventWriteBody(buildRcControlResponsePayload(requestId, decision, updatedInput?.input)));
|
|
16806
17085
|
let answer;
|
|
16807
17086
|
try {
|
|
16808
17087
|
answer = await deps.dial.writeEvents(sessionId, rcWriteHeaders(credential), body);
|
|
16809
17088
|
} catch (error) {
|
|
16810
17089
|
return { ok: false, message: `the door could not reach the API host to answer on session ${sessionId}: ${error instanceof Error ? error.message : String(error)}` };
|
|
17090
|
+
} finally {
|
|
17091
|
+
release();
|
|
16811
17092
|
}
|
|
16812
17093
|
const result = rcEventWriteResultFromAnswer(answer);
|
|
16813
17094
|
if (result.ok) {
|
|
@@ -16937,6 +17218,198 @@ init_legacy();
|
|
|
16937
17218
|
// src/frontdoor/rcControl.ts
|
|
16938
17219
|
var https = __toESM(require("node:https"), 1);
|
|
16939
17220
|
init_capability();
|
|
17221
|
+
|
|
17222
|
+
// src/frontdoor/rcSchemas.ts
|
|
17223
|
+
var import_zod10 = require("zod");
|
|
17224
|
+
var RcPermissionModeSchema = import_zod10.z.enum(RC_PERMISSION_MODES);
|
|
17225
|
+
var RcSessionSummarySchema = import_zod10.z.strictObject({
|
|
17226
|
+
id: import_zod10.z.string(),
|
|
17227
|
+
createdAt: import_zod10.z.number(),
|
|
17228
|
+
lastSeenAt: import_zod10.z.number()
|
|
17229
|
+
});
|
|
17230
|
+
function workerFactSchema(value) {
|
|
17231
|
+
return import_zod10.z.strictObject({ value, observedAt: import_zod10.z.number() });
|
|
17232
|
+
}
|
|
17233
|
+
var RcQuestionOptionSchema = import_zod10.z.strictObject({
|
|
17234
|
+
label: import_zod10.z.string(),
|
|
17235
|
+
description: import_zod10.z.string().optional()
|
|
17236
|
+
});
|
|
17237
|
+
var RcPendingQuestionSchema = import_zod10.z.strictObject({
|
|
17238
|
+
question: import_zod10.z.string(),
|
|
17239
|
+
header: import_zod10.z.string().optional(),
|
|
17240
|
+
multiSelect: import_zod10.z.boolean(),
|
|
17241
|
+
options: import_zod10.z.readonly(import_zod10.z.array(RcQuestionOptionSchema))
|
|
17242
|
+
});
|
|
17243
|
+
var RcPendingRequestSummarySchema = import_zod10.z.strictObject({
|
|
17244
|
+
sessionId: import_zod10.z.string(),
|
|
17245
|
+
requestId: import_zod10.z.string(),
|
|
17246
|
+
type: import_zod10.z.string(),
|
|
17247
|
+
summary: import_zod10.z.string(),
|
|
17248
|
+
questions: import_zod10.z.readonly(import_zod10.z.array(RcPendingQuestionSchema)).optional(),
|
|
17249
|
+
oversized: import_zod10.z.literal(true).optional(),
|
|
17250
|
+
unanswerable: import_zod10.z.string().optional(),
|
|
17251
|
+
observedAt: import_zod10.z.number()
|
|
17252
|
+
});
|
|
17253
|
+
var RcSessionStatusSchema = import_zod10.z.strictObject({
|
|
17254
|
+
...RcSessionSummarySchema.shape,
|
|
17255
|
+
workerState: workerFactSchema(import_zod10.z.string()).optional(),
|
|
17256
|
+
workerIdleSeconds: workerFactSchema(import_zod10.z.number()).optional(),
|
|
17257
|
+
pending: import_zod10.z.readonly(import_zod10.z.array(RcPendingRequestSummarySchema)),
|
|
17258
|
+
/** The identity the session runs as, when known; absent otherwise. */
|
|
17259
|
+
identity: import_zod10.z.string().optional(),
|
|
17260
|
+
/** The model the session last stated, when the door saw one. */
|
|
17261
|
+
model: import_zod10.z.string().optional(),
|
|
17262
|
+
/** The session's name from the Claude Code session registry, when the registry holds it. */
|
|
17263
|
+
name: import_zod10.z.string().optional(),
|
|
17264
|
+
/** The session process's id from the registry. */
|
|
17265
|
+
pid: import_zod10.z.number().optional(),
|
|
17266
|
+
/** The session's working directory, from its init event or the registry. */
|
|
17267
|
+
cwd: import_zod10.z.string().optional(),
|
|
17268
|
+
pendingDropped: import_zod10.z.int().positive().optional()
|
|
17269
|
+
});
|
|
17270
|
+
var RcStreamEnvelopeSchema = import_zod10.z.looseObject({
|
|
17271
|
+
/** The envelope's own event id, when the host sent one. */
|
|
17272
|
+
event_id: import_zod10.z.string().optional(),
|
|
17273
|
+
/** The envelope's event type, the discriminator a consumer switches on (`control_request`, `user`, and kin). */
|
|
17274
|
+
event_type: import_zod10.z.string(),
|
|
17275
|
+
/** The sequence number the host assigned, the value a resume continues after. */
|
|
17276
|
+
sequence_num: import_zod10.z.int(),
|
|
17277
|
+
/** Who emitted the event (`worker` for the CLI's half, a client id for a client's). */
|
|
17278
|
+
source: import_zod10.z.string(),
|
|
17279
|
+
/** The event's payload, carried verbatim: its shape is the payload family's, narrowed by whichever consumer needs it. Optional in the schema's own type because the door forwards the host's envelope as it arrived, asserting only the fields it relies on itself. */
|
|
17280
|
+
payload: import_zod10.z.unknown().optional(),
|
|
17281
|
+
/** When the host created the event; the protocol's own type for this field is not established here, so it is forwarded rather than asserted. */
|
|
17282
|
+
created_at: import_zod10.z.unknown().optional()
|
|
17283
|
+
});
|
|
17284
|
+
var RcStreamEventSchema = import_zod10.z.strictObject({
|
|
17285
|
+
session: import_zod10.z.string(),
|
|
17286
|
+
envelope: RcStreamEnvelopeSchema
|
|
17287
|
+
});
|
|
17288
|
+
var RcRateLimitWindowSchema = import_zod10.z.looseObject({
|
|
17289
|
+
/** The fraction of the window used, usually between 0 and 1, above 1 when usage legitimately runs past the window's cap (the CLI's own field description states both). */
|
|
17290
|
+
utilization: import_zod10.z.number().optional(),
|
|
17291
|
+
/** When the window resets, in unix epoch seconds: the unit is the CLI's own field description, stated in the 2.1.289 bundle's schema. */
|
|
17292
|
+
resetsAt: import_zod10.z.number().optional()
|
|
17293
|
+
});
|
|
17294
|
+
var RcRateLimitInfoSchema = import_zod10.z.looseObject({
|
|
17295
|
+
/** The limiting window's own status (`allowed`, `allowed_warning`, `rejected`), asserted only as a string because the vocabulary grows with the CLI. */
|
|
17296
|
+
status: import_zod10.z.string(),
|
|
17297
|
+
/** When the limiting window resets, in unix epoch seconds. */
|
|
17298
|
+
resetsAt: import_zod10.z.number().optional(),
|
|
17299
|
+
/** Which window the top-level fields describe (`five_hour`, `seven_day`, and kin), the payload's own name for it. */
|
|
17300
|
+
rateLimitType: import_zod10.z.string().optional(),
|
|
17301
|
+
/** The fraction of the limiting window used, on the same scale the per-window utilizations carry. */
|
|
17302
|
+
utilization: import_zod10.z.number().optional(),
|
|
17303
|
+
/** Whether usage beyond the plan (extra usage) is currently covering the overflow, the payload's own flag for it. */
|
|
17304
|
+
isUsingOverage: import_zod10.z.boolean().optional(),
|
|
17305
|
+
/** The overage's own status, the same vocabulary the limiting window's `status` carries. */
|
|
17306
|
+
overageStatus: import_zod10.z.string().optional(),
|
|
17307
|
+
/** When the overage window resets, in unix epoch seconds. */
|
|
17308
|
+
overageResetsAt: import_zod10.z.number().optional(),
|
|
17309
|
+
/** Each subscription window the account's response headers carried: the session (five-hour), weekly (seven-day), and overage-included weekly windows, each present only when the account's responses carry it. */
|
|
17310
|
+
unifiedWindows: import_zod10.z.looseObject({ five_hour: RcRateLimitWindowSchema.optional(), seven_day: RcRateLimitWindowSchema.optional(), seven_day_overage_included: RcRateLimitWindowSchema.optional() }).optional()
|
|
17311
|
+
});
|
|
17312
|
+
var RcLiveRateLimitSchema = import_zod10.z.strictObject({
|
|
17313
|
+
session: import_zod10.z.string(),
|
|
17314
|
+
observedAt: import_zod10.z.number(),
|
|
17315
|
+
rateLimit: RcRateLimitInfoSchema
|
|
17316
|
+
});
|
|
17317
|
+
var RcSessionQuerySchema = import_zod10.z.strictObject({
|
|
17318
|
+
session: import_zod10.z.string().min(1).optional()
|
|
17319
|
+
});
|
|
17320
|
+
var RcSendInputSchema = import_zod10.z.strictObject({
|
|
17321
|
+
session: import_zod10.z.string().min(1),
|
|
17322
|
+
text: import_zod10.z.string().min(1)
|
|
17323
|
+
});
|
|
17324
|
+
var RcQuestionSelectionSchema = import_zod10.z.union([import_zod10.z.string().min(1), import_zod10.z.int().positive(), import_zod10.z.strictObject({ text: import_zod10.z.string().refine((text) => text.trim() !== "", { message: "free text must not be blank" }) })]);
|
|
17325
|
+
var RcQuestionChoicesSchema = import_zod10.z.array(import_zod10.z.array(RcQuestionSelectionSchema).min(1)).min(1);
|
|
17326
|
+
var RcAnswerInputSchema = import_zod10.z.strictObject({
|
|
17327
|
+
session: import_zod10.z.string().min(1),
|
|
17328
|
+
request: import_zod10.z.string().min(1),
|
|
17329
|
+
approve: import_zod10.z.boolean(),
|
|
17330
|
+
text: import_zod10.z.string().optional(),
|
|
17331
|
+
choices: RcQuestionChoicesSchema.optional()
|
|
17332
|
+
}).refine((input) => !input.approve || input.text === void 0 || input.text === "", { message: "an approval carries no text (the protocol's allow result has no message field); text is the denial message" }).refine((input) => input.approve || input.choices === void 0, { message: "choices answer a question, so they come with approve: true; a denial dismisses the question" });
|
|
17333
|
+
var RcInterruptInputSchema = import_zod10.z.strictObject({
|
|
17334
|
+
session: import_zod10.z.string().min(1)
|
|
17335
|
+
});
|
|
17336
|
+
var RcSetModelInputSchema = import_zod10.z.strictObject({
|
|
17337
|
+
session: import_zod10.z.string().min(1),
|
|
17338
|
+
model: import_zod10.z.string().min(1)
|
|
17339
|
+
});
|
|
17340
|
+
var RcSetPermissionModeInputSchema = import_zod10.z.strictObject({
|
|
17341
|
+
session: import_zod10.z.string().min(1),
|
|
17342
|
+
mode: RcPermissionModeSchema
|
|
17343
|
+
});
|
|
17344
|
+
var RcEndSessionInputSchema = import_zod10.z.strictObject({
|
|
17345
|
+
session: import_zod10.z.string().min(1),
|
|
17346
|
+
reason: import_zod10.z.string().min(1).optional()
|
|
17347
|
+
});
|
|
17348
|
+
var RcGetUsageInputSchema = import_zod10.z.strictObject({
|
|
17349
|
+
session: import_zod10.z.string().min(1),
|
|
17350
|
+
skipBehaviors: import_zod10.z.boolean().optional()
|
|
17351
|
+
});
|
|
17352
|
+
var RcGetContextUsageInputSchema = import_zod10.z.strictObject({
|
|
17353
|
+
session: import_zod10.z.string().min(1),
|
|
17354
|
+
detail: import_zod10.z.enum(RC_CONTEXT_USAGE_DETAILS).optional()
|
|
17355
|
+
});
|
|
17356
|
+
var RcReadFileInputSchema = import_zod10.z.strictObject({
|
|
17357
|
+
session: import_zod10.z.string().min(1),
|
|
17358
|
+
path: import_zod10.z.string().min(1),
|
|
17359
|
+
maxBytes: import_zod10.z.number().int().positive().optional(),
|
|
17360
|
+
encoding: import_zod10.z.enum(RC_READ_FILE_ENCODINGS).optional()
|
|
17361
|
+
});
|
|
17362
|
+
var RcFileSuggestionsInputSchema = import_zod10.z.strictObject({
|
|
17363
|
+
session: import_zod10.z.string().min(1),
|
|
17364
|
+
query: import_zod10.z.string()
|
|
17365
|
+
});
|
|
17366
|
+
var RcKeepAliveInputSchema = import_zod10.z.strictObject({
|
|
17367
|
+
session: import_zod10.z.string().min(1)
|
|
17368
|
+
});
|
|
17369
|
+
var RcMcpStatusInputSchema = import_zod10.z.strictObject({
|
|
17370
|
+
session: import_zod10.z.string().min(1)
|
|
17371
|
+
});
|
|
17372
|
+
var RcMcpReconnectInputSchema = import_zod10.z.strictObject({
|
|
17373
|
+
session: import_zod10.z.string().min(1),
|
|
17374
|
+
serverName: import_zod10.z.string().min(1)
|
|
17375
|
+
});
|
|
17376
|
+
var RcMcpAuthenticateInputSchema = import_zod10.z.strictObject({
|
|
17377
|
+
session: import_zod10.z.string().min(1),
|
|
17378
|
+
serverName: import_zod10.z.string().min(1),
|
|
17379
|
+
redirectUri: import_zod10.z.string().min(1)
|
|
17380
|
+
});
|
|
17381
|
+
var RcMcpOAuthCallbackUrlInputSchema = import_zod10.z.strictObject({
|
|
17382
|
+
session: import_zod10.z.string().min(1),
|
|
17383
|
+
serverName: import_zod10.z.string().min(1),
|
|
17384
|
+
callbackUrl: import_zod10.z.string().min(1)
|
|
17385
|
+
});
|
|
17386
|
+
var RcTeleportInputSchema = import_zod10.z.strictObject({
|
|
17387
|
+
session: import_zod10.z.string().min(1),
|
|
17388
|
+
marker: import_zod10.z.string().min(1)
|
|
17389
|
+
});
|
|
17390
|
+
var RcListOutputSchema = import_zod10.z.strictObject({ sessions: import_zod10.z.readonly(import_zod10.z.array(RcSessionSummarySchema)) });
|
|
17391
|
+
var RcStatusOutputSchema = import_zod10.z.strictObject({ statuses: import_zod10.z.readonly(import_zod10.z.array(RcSessionStatusSchema)) });
|
|
17392
|
+
var RcPendingOutputSchema = import_zod10.z.strictObject({
|
|
17393
|
+
pending: import_zod10.z.readonly(import_zod10.z.array(RcPendingRequestSummarySchema)),
|
|
17394
|
+
/** The sessions that had requests the door did not list (past the per-session cap, or with an id the protocol does not mint), each with how many: a question the caller expects may be among them. Absent when none did. */
|
|
17395
|
+
dropped: import_zod10.z.readonly(import_zod10.z.array(import_zod10.z.strictObject({ sessionId: import_zod10.z.string(), count: import_zod10.z.int().positive() }))).optional()
|
|
17396
|
+
});
|
|
17397
|
+
var RcWriteOutputSchema = import_zod10.z.strictObject({
|
|
17398
|
+
session: import_zod10.z.string(),
|
|
17399
|
+
sequenceNums: import_zod10.z.readonly(import_zod10.z.array(import_zod10.z.number()))
|
|
17400
|
+
});
|
|
17401
|
+
var RcControlWriteOutputSchema = import_zod10.z.strictObject({
|
|
17402
|
+
session: import_zod10.z.string(),
|
|
17403
|
+
request: import_zod10.z.string(),
|
|
17404
|
+
sequenceNums: import_zod10.z.readonly(import_zod10.z.array(import_zod10.z.number()))
|
|
17405
|
+
});
|
|
17406
|
+
var RcAnswerOutputSchema = import_zod10.z.strictObject({
|
|
17407
|
+
session: import_zod10.z.string(),
|
|
17408
|
+
request: import_zod10.z.string(),
|
|
17409
|
+
sequenceNums: import_zod10.z.readonly(import_zod10.z.array(import_zod10.z.number()))
|
|
17410
|
+
});
|
|
17411
|
+
|
|
17412
|
+
// src/frontdoor/rcControl.ts
|
|
16940
17413
|
var RC_PERMISSION_MODE_LIST = RC_PERMISSION_MODES.join(", ");
|
|
16941
17414
|
var CONTROL_PATH_PREFIX = "/__agent-shim/rc";
|
|
16942
17415
|
var CONTROL_BODY_CAP_BYTES = 10485760;
|
|
@@ -17193,11 +17666,20 @@ function createRcControlHandler(deps) {
|
|
|
17193
17666
|
return;
|
|
17194
17667
|
}
|
|
17195
17668
|
const text = "text" in parsed && typeof parsed.text === "string" ? parsed.text : void 0;
|
|
17669
|
+
const choices = "choices" in parsed ? RcQuestionChoicesSchema.safeParse(parsed.choices) : void 0;
|
|
17670
|
+
if (choices !== void 0 && !choices.success) {
|
|
17671
|
+
answerJson(response, HTTP_STATUS.badRequest, { error: 'choices must be one non-empty list per question of selections, each an option label, a one-based option number or {"text": ...}' });
|
|
17672
|
+
return;
|
|
17673
|
+
}
|
|
17674
|
+
if (choices !== void 0 && !parsed.approve) {
|
|
17675
|
+
answerJson(response, HTTP_STATUS.badRequest, { error: "choices answer a question, so they come with approve: true; a denial dismisses the question" });
|
|
17676
|
+
return;
|
|
17677
|
+
}
|
|
17196
17678
|
if (parsed.approve && text !== void 0 && text !== "") {
|
|
17197
17679
|
answerJson(response, HTTP_STATUS.badRequest, { error: "an approval carries no text (the protocol's allow result has no message field); text is the denial message" });
|
|
17198
17680
|
return;
|
|
17199
17681
|
}
|
|
17200
|
-
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 : text });
|
|
17682
|
+
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 : text, ...choices === void 0 ? {} : { choices: choices.data } });
|
|
17201
17683
|
if (result.ok) {
|
|
17202
17684
|
answerJson(response, HTTP_STATUS.ok, { session: parsed.session, request: parsed.request, sequenceNums: result.sequenceNums });
|
|
17203
17685
|
return;
|
|
@@ -17319,6 +17801,9 @@ function isRcSessionStatus(value) {
|
|
|
17319
17801
|
if ("workerState" in value && value.workerState !== void 0 && !isRcWorkerFact(value.workerState, (candidate) => typeof candidate === "string")) {
|
|
17320
17802
|
return false;
|
|
17321
17803
|
}
|
|
17804
|
+
if ("pendingDropped" in value && value.pendingDropped !== void 0 && typeof value.pendingDropped !== "number") {
|
|
17805
|
+
return false;
|
|
17806
|
+
}
|
|
17322
17807
|
if ("workerIdleSeconds" in value && value.workerIdleSeconds !== void 0 && !isRcWorkerFact(value.workerIdleSeconds, (candidate) => typeof candidate === "number")) {
|
|
17323
17808
|
return false;
|
|
17324
17809
|
}
|
|
@@ -17328,13 +17813,7 @@ function isRcSessionStatus(value) {
|
|
|
17328
17813
|
return value.pending.every((candidate) => isRcPendingRequestSummary(candidate));
|
|
17329
17814
|
}
|
|
17330
17815
|
function isRcPendingRequestSummary(value) {
|
|
17331
|
-
|
|
17332
|
-
return false;
|
|
17333
|
-
}
|
|
17334
|
-
if (!("sessionId" in value) || !("requestId" in value) || !("type" in value) || !("summary" in value) || !("observedAt" in value)) {
|
|
17335
|
-
return false;
|
|
17336
|
-
}
|
|
17337
|
-
return typeof value.sessionId === "string" && typeof value.requestId === "string" && typeof value.type === "string" && typeof value.summary === "string" && typeof value.observedAt === "number";
|
|
17816
|
+
return RcPendingRequestSummarySchema.safeParse(value).success;
|
|
17338
17817
|
}
|
|
17339
17818
|
function sequenceNumsOfBody(body) {
|
|
17340
17819
|
let parsed;
|
|
@@ -17470,7 +17949,7 @@ function frontDoorRcControl(transport, token) {
|
|
|
17470
17949
|
sendPrompt: async (sessionId, text) => await writeOf(`${CONTROL_PATH_PREFIX}/inject`, JSON.stringify({ session: sessionId, text }), (status, message) => `injecting into ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
17471
17950
|
answerRequest: async (sessionId, requestId, decision) => await writeOf(
|
|
17472
17951
|
`${CONTROL_PATH_PREFIX}/answer`,
|
|
17473
|
-
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message } }),
|
|
17952
|
+
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message }, ...decision.choices === void 0 ? {} : { choices: decision.choices } }),
|
|
17474
17953
|
(status, message) => `answering control request ${requestId} on ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
17475
17954
|
),
|
|
17476
17955
|
interruptSession: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/interrupt`, JSON.stringify({ session: sessionId }), (status, message) => `interrupting ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -17987,20 +18466,20 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
|
|
|
17987
18466
|
|
|
17988
18467
|
// src/frontdoor/rcSessionRegistry.ts
|
|
17989
18468
|
var import_node_path31 = __toESM(require("node:path"), 1);
|
|
17990
|
-
var
|
|
18469
|
+
var import_zod23 = require("zod");
|
|
17991
18470
|
init_identityStore();
|
|
17992
18471
|
var REGISTRY_BRIDGE_PREFIX = "session_";
|
|
17993
18472
|
var DOOR_SESSION_PREFIX = "cse_";
|
|
17994
18473
|
var REGISTRY_DIR = "sessions";
|
|
17995
18474
|
var ENTRY_SUFFIX = ".json";
|
|
17996
18475
|
var RC_REGISTRY_ENTRY_MAX_BYTES = 8192;
|
|
17997
|
-
var RegistryEntrySchema =
|
|
17998
|
-
sessionId:
|
|
17999
|
-
pid:
|
|
18000
|
-
bridgeSessionId:
|
|
18001
|
-
cwd:
|
|
18002
|
-
name:
|
|
18003
|
-
updatedAt:
|
|
18476
|
+
var RegistryEntrySchema = import_zod23.z.looseObject({
|
|
18477
|
+
sessionId: import_zod23.z.string().min(1),
|
|
18478
|
+
pid: import_zod23.z.int().positive(),
|
|
18479
|
+
bridgeSessionId: import_zod23.z.union([import_zod23.z.string().startsWith(REGISTRY_BRIDGE_PREFIX), import_zod23.z.string().startsWith(DOOR_SESSION_PREFIX)]),
|
|
18480
|
+
cwd: import_zod23.z.string().optional(),
|
|
18481
|
+
name: import_zod23.z.string().optional(),
|
|
18482
|
+
updatedAt: import_zod23.z.number().optional()
|
|
18004
18483
|
});
|
|
18005
18484
|
function supersedes(candidate, kept) {
|
|
18006
18485
|
return candidate.updatedAt > kept.updatedAt || candidate.updatedAt === kept.updatedAt && candidate.session.pid > kept.session.pid;
|
|
@@ -18114,11 +18593,11 @@ var import_node_path32 = __toESM(require("node:path"), 1);
|
|
|
18114
18593
|
function isSafeSessionId(sessionId) {
|
|
18115
18594
|
return /^[A-Za-z0-9_-]+$/.test(sessionId);
|
|
18116
18595
|
}
|
|
18117
|
-
function
|
|
18596
|
+
function isRecord7(value) {
|
|
18118
18597
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18119
18598
|
}
|
|
18120
18599
|
function credentialOfJson(parsed) {
|
|
18121
|
-
if (!
|
|
18600
|
+
if (!isRecord7(parsed)) {
|
|
18122
18601
|
return void 0;
|
|
18123
18602
|
}
|
|
18124
18603
|
const { authorization, anthropicVersion, anthropicClientPlatform } = parsed;
|
|
@@ -18148,7 +18627,7 @@ function createRcCredentialStore(fs17, dir) {
|
|
|
18148
18627
|
} catch {
|
|
18149
18628
|
return void 0;
|
|
18150
18629
|
}
|
|
18151
|
-
return
|
|
18630
|
+
return isRecord7(parsed) ? parsed : void 0;
|
|
18152
18631
|
};
|
|
18153
18632
|
return {
|
|
18154
18633
|
read: (sessionId) => {
|
|
@@ -18206,177 +18685,8 @@ var COMPACT_TIMEOUT_MS = 9e5;
|
|
|
18206
18685
|
// src/frontdoor/rcApi.ts
|
|
18207
18686
|
init_capability();
|
|
18208
18687
|
|
|
18209
|
-
// src/frontdoor/rcSchemas.ts
|
|
18210
|
-
var import_zod22 = require("zod");
|
|
18211
|
-
var RcPermissionModeSchema = import_zod22.z.enum(RC_PERMISSION_MODES);
|
|
18212
|
-
var RcSessionSummarySchema = import_zod22.z.strictObject({
|
|
18213
|
-
id: import_zod22.z.string(),
|
|
18214
|
-
createdAt: import_zod22.z.number(),
|
|
18215
|
-
lastSeenAt: import_zod22.z.number()
|
|
18216
|
-
});
|
|
18217
|
-
function workerFactSchema(value) {
|
|
18218
|
-
return import_zod22.z.strictObject({ value, observedAt: import_zod22.z.number() });
|
|
18219
|
-
}
|
|
18220
|
-
var RcPendingRequestSummarySchema = import_zod22.z.strictObject({
|
|
18221
|
-
sessionId: import_zod22.z.string(),
|
|
18222
|
-
requestId: import_zod22.z.string(),
|
|
18223
|
-
type: import_zod22.z.string(),
|
|
18224
|
-
summary: import_zod22.z.string(),
|
|
18225
|
-
observedAt: import_zod22.z.number()
|
|
18226
|
-
});
|
|
18227
|
-
var RcSessionStatusSchema = import_zod22.z.strictObject({
|
|
18228
|
-
...RcSessionSummarySchema.shape,
|
|
18229
|
-
workerState: workerFactSchema(import_zod22.z.string()).optional(),
|
|
18230
|
-
workerIdleSeconds: workerFactSchema(import_zod22.z.number()).optional(),
|
|
18231
|
-
pending: import_zod22.z.readonly(import_zod22.z.array(RcPendingRequestSummarySchema)),
|
|
18232
|
-
/** The identity the session runs as, when known; absent otherwise. */
|
|
18233
|
-
identity: import_zod22.z.string().optional(),
|
|
18234
|
-
/** The model the session last stated, when the door saw one. */
|
|
18235
|
-
model: import_zod22.z.string().optional(),
|
|
18236
|
-
/** The session's name from the Claude Code session registry, when the registry holds it. */
|
|
18237
|
-
name: import_zod22.z.string().optional(),
|
|
18238
|
-
/** The session process's id from the registry. */
|
|
18239
|
-
pid: import_zod22.z.number().optional(),
|
|
18240
|
-
/** The session's working directory, from its init event or the registry. */
|
|
18241
|
-
cwd: import_zod22.z.string().optional()
|
|
18242
|
-
});
|
|
18243
|
-
var RcStreamEnvelopeSchema = import_zod22.z.looseObject({
|
|
18244
|
-
/** The envelope's own event id, when the host sent one. */
|
|
18245
|
-
event_id: import_zod22.z.string().optional(),
|
|
18246
|
-
/** The envelope's event type, the discriminator a consumer switches on (`control_request`, `user`, and kin). */
|
|
18247
|
-
event_type: import_zod22.z.string(),
|
|
18248
|
-
/** The sequence number the host assigned, the value a resume continues after. */
|
|
18249
|
-
sequence_num: import_zod22.z.int(),
|
|
18250
|
-
/** Who emitted the event (`worker` for the CLI's half, a client id for a client's). */
|
|
18251
|
-
source: import_zod22.z.string(),
|
|
18252
|
-
/** The event's payload, carried verbatim: its shape is the payload family's, narrowed by whichever consumer needs it. Optional in the schema's own type because the door forwards the host's envelope as it arrived, asserting only the fields it relies on itself. */
|
|
18253
|
-
payload: import_zod22.z.unknown().optional(),
|
|
18254
|
-
/** When the host created the event; the protocol's own type for this field is not established here, so it is forwarded rather than asserted. */
|
|
18255
|
-
created_at: import_zod22.z.unknown().optional()
|
|
18256
|
-
});
|
|
18257
|
-
var RcStreamEventSchema = import_zod22.z.strictObject({
|
|
18258
|
-
session: import_zod22.z.string(),
|
|
18259
|
-
envelope: RcStreamEnvelopeSchema
|
|
18260
|
-
});
|
|
18261
|
-
var RcRateLimitWindowSchema = import_zod22.z.looseObject({
|
|
18262
|
-
/** The fraction of the window used, usually between 0 and 1, above 1 when usage legitimately runs past the window's cap (the CLI's own field description states both). */
|
|
18263
|
-
utilization: import_zod22.z.number().optional(),
|
|
18264
|
-
/** When the window resets, in unix epoch seconds: the unit is the CLI's own field description, stated in the 2.1.289 bundle's schema. */
|
|
18265
|
-
resetsAt: import_zod22.z.number().optional()
|
|
18266
|
-
});
|
|
18267
|
-
var RcRateLimitInfoSchema = import_zod22.z.looseObject({
|
|
18268
|
-
/** The limiting window's own status (`allowed`, `allowed_warning`, `rejected`), asserted only as a string because the vocabulary grows with the CLI. */
|
|
18269
|
-
status: import_zod22.z.string(),
|
|
18270
|
-
/** When the limiting window resets, in unix epoch seconds. */
|
|
18271
|
-
resetsAt: import_zod22.z.number().optional(),
|
|
18272
|
-
/** Which window the top-level fields describe (`five_hour`, `seven_day`, and kin), the payload's own name for it. */
|
|
18273
|
-
rateLimitType: import_zod22.z.string().optional(),
|
|
18274
|
-
/** The fraction of the limiting window used, on the same scale the per-window utilizations carry. */
|
|
18275
|
-
utilization: import_zod22.z.number().optional(),
|
|
18276
|
-
/** Whether usage beyond the plan (extra usage) is currently covering the overflow, the payload's own flag for it. */
|
|
18277
|
-
isUsingOverage: import_zod22.z.boolean().optional(),
|
|
18278
|
-
/** The overage's own status, the same vocabulary the limiting window's `status` carries. */
|
|
18279
|
-
overageStatus: import_zod22.z.string().optional(),
|
|
18280
|
-
/** When the overage window resets, in unix epoch seconds. */
|
|
18281
|
-
overageResetsAt: import_zod22.z.number().optional(),
|
|
18282
|
-
/** Each subscription window the account's response headers carried: the session (five-hour), weekly (seven-day), and overage-included weekly windows, each present only when the account's responses carry it. */
|
|
18283
|
-
unifiedWindows: import_zod22.z.looseObject({ five_hour: RcRateLimitWindowSchema.optional(), seven_day: RcRateLimitWindowSchema.optional(), seven_day_overage_included: RcRateLimitWindowSchema.optional() }).optional()
|
|
18284
|
-
});
|
|
18285
|
-
var RcLiveRateLimitSchema = import_zod22.z.strictObject({
|
|
18286
|
-
session: import_zod22.z.string(),
|
|
18287
|
-
observedAt: import_zod22.z.number(),
|
|
18288
|
-
rateLimit: RcRateLimitInfoSchema
|
|
18289
|
-
});
|
|
18290
|
-
var RcSessionQuerySchema = import_zod22.z.strictObject({
|
|
18291
|
-
session: import_zod22.z.string().min(1).optional()
|
|
18292
|
-
});
|
|
18293
|
-
var RcSendInputSchema = import_zod22.z.strictObject({
|
|
18294
|
-
session: import_zod22.z.string().min(1),
|
|
18295
|
-
text: import_zod22.z.string().min(1)
|
|
18296
|
-
});
|
|
18297
|
-
var RcAnswerInputSchema = import_zod22.z.strictObject({
|
|
18298
|
-
session: import_zod22.z.string().min(1),
|
|
18299
|
-
request: import_zod22.z.string().min(1),
|
|
18300
|
-
approve: import_zod22.z.boolean(),
|
|
18301
|
-
text: import_zod22.z.string().optional()
|
|
18302
|
-
}).refine((input) => !input.approve || input.text === void 0 || input.text === "", { message: "an approval carries no text (the protocol's allow result has no message field); text is the denial message" });
|
|
18303
|
-
var RcInterruptInputSchema = import_zod22.z.strictObject({
|
|
18304
|
-
session: import_zod22.z.string().min(1)
|
|
18305
|
-
});
|
|
18306
|
-
var RcSetModelInputSchema = import_zod22.z.strictObject({
|
|
18307
|
-
session: import_zod22.z.string().min(1),
|
|
18308
|
-
model: import_zod22.z.string().min(1)
|
|
18309
|
-
});
|
|
18310
|
-
var RcSetPermissionModeInputSchema = import_zod22.z.strictObject({
|
|
18311
|
-
session: import_zod22.z.string().min(1),
|
|
18312
|
-
mode: RcPermissionModeSchema
|
|
18313
|
-
});
|
|
18314
|
-
var RcEndSessionInputSchema = import_zod22.z.strictObject({
|
|
18315
|
-
session: import_zod22.z.string().min(1),
|
|
18316
|
-
reason: import_zod22.z.string().min(1).optional()
|
|
18317
|
-
});
|
|
18318
|
-
var RcGetUsageInputSchema = import_zod22.z.strictObject({
|
|
18319
|
-
session: import_zod22.z.string().min(1),
|
|
18320
|
-
skipBehaviors: import_zod22.z.boolean().optional()
|
|
18321
|
-
});
|
|
18322
|
-
var RcGetContextUsageInputSchema = import_zod22.z.strictObject({
|
|
18323
|
-
session: import_zod22.z.string().min(1),
|
|
18324
|
-
detail: import_zod22.z.enum(RC_CONTEXT_USAGE_DETAILS).optional()
|
|
18325
|
-
});
|
|
18326
|
-
var RcReadFileInputSchema = import_zod22.z.strictObject({
|
|
18327
|
-
session: import_zod22.z.string().min(1),
|
|
18328
|
-
path: import_zod22.z.string().min(1),
|
|
18329
|
-
maxBytes: import_zod22.z.number().int().positive().optional(),
|
|
18330
|
-
encoding: import_zod22.z.enum(RC_READ_FILE_ENCODINGS).optional()
|
|
18331
|
-
});
|
|
18332
|
-
var RcFileSuggestionsInputSchema = import_zod22.z.strictObject({
|
|
18333
|
-
session: import_zod22.z.string().min(1),
|
|
18334
|
-
query: import_zod22.z.string()
|
|
18335
|
-
});
|
|
18336
|
-
var RcKeepAliveInputSchema = import_zod22.z.strictObject({
|
|
18337
|
-
session: import_zod22.z.string().min(1)
|
|
18338
|
-
});
|
|
18339
|
-
var RcMcpStatusInputSchema = import_zod22.z.strictObject({
|
|
18340
|
-
session: import_zod22.z.string().min(1)
|
|
18341
|
-
});
|
|
18342
|
-
var RcMcpReconnectInputSchema = import_zod22.z.strictObject({
|
|
18343
|
-
session: import_zod22.z.string().min(1),
|
|
18344
|
-
serverName: import_zod22.z.string().min(1)
|
|
18345
|
-
});
|
|
18346
|
-
var RcMcpAuthenticateInputSchema = import_zod22.z.strictObject({
|
|
18347
|
-
session: import_zod22.z.string().min(1),
|
|
18348
|
-
serverName: import_zod22.z.string().min(1),
|
|
18349
|
-
redirectUri: import_zod22.z.string().min(1)
|
|
18350
|
-
});
|
|
18351
|
-
var RcMcpOAuthCallbackUrlInputSchema = import_zod22.z.strictObject({
|
|
18352
|
-
session: import_zod22.z.string().min(1),
|
|
18353
|
-
serverName: import_zod22.z.string().min(1),
|
|
18354
|
-
callbackUrl: import_zod22.z.string().min(1)
|
|
18355
|
-
});
|
|
18356
|
-
var RcTeleportInputSchema = import_zod22.z.strictObject({
|
|
18357
|
-
session: import_zod22.z.string().min(1),
|
|
18358
|
-
marker: import_zod22.z.string().min(1)
|
|
18359
|
-
});
|
|
18360
|
-
var RcListOutputSchema = import_zod22.z.strictObject({ sessions: import_zod22.z.readonly(import_zod22.z.array(RcSessionSummarySchema)) });
|
|
18361
|
-
var RcStatusOutputSchema = import_zod22.z.strictObject({ statuses: import_zod22.z.readonly(import_zod22.z.array(RcSessionStatusSchema)) });
|
|
18362
|
-
var RcPendingOutputSchema = import_zod22.z.strictObject({ pending: import_zod22.z.readonly(import_zod22.z.array(RcPendingRequestSummarySchema)) });
|
|
18363
|
-
var RcWriteOutputSchema = import_zod22.z.strictObject({
|
|
18364
|
-
session: import_zod22.z.string(),
|
|
18365
|
-
sequenceNums: import_zod22.z.readonly(import_zod22.z.array(import_zod22.z.number()))
|
|
18366
|
-
});
|
|
18367
|
-
var RcControlWriteOutputSchema = import_zod22.z.strictObject({
|
|
18368
|
-
session: import_zod22.z.string(),
|
|
18369
|
-
request: import_zod22.z.string(),
|
|
18370
|
-
sequenceNums: import_zod22.z.readonly(import_zod22.z.array(import_zod22.z.number()))
|
|
18371
|
-
});
|
|
18372
|
-
var RcAnswerOutputSchema = import_zod22.z.strictObject({
|
|
18373
|
-
session: import_zod22.z.string(),
|
|
18374
|
-
request: import_zod22.z.string(),
|
|
18375
|
-
sequenceNums: import_zod22.z.readonly(import_zod22.z.array(import_zod22.z.number()))
|
|
18376
|
-
});
|
|
18377
|
-
|
|
18378
18688
|
// src/frontdoor/rcSlashCommandSchemas.ts
|
|
18379
|
-
var
|
|
18689
|
+
var import_zod24 = require("zod");
|
|
18380
18690
|
|
|
18381
18691
|
// src/frontdoor/rcSessionCommands.ts
|
|
18382
18692
|
var import_promises = require("node:timers/promises");
|
|
@@ -18412,26 +18722,26 @@ async function writeRcPersonMessage(deps, sessionId, text) {
|
|
|
18412
18722
|
}
|
|
18413
18723
|
return result;
|
|
18414
18724
|
}
|
|
18415
|
-
function
|
|
18725
|
+
function isRecord8(value) {
|
|
18416
18726
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18417
18727
|
}
|
|
18418
18728
|
function rcLocalCommandAnswerOf(event, command, args) {
|
|
18419
18729
|
const payload = event.envelope.payload;
|
|
18420
|
-
if (!
|
|
18730
|
+
if (!isRecord8(payload) || payload.type !== "assistant" || !isRecord8(payload.local_command_run) || payload.local_command_run.command !== command || payload.local_command_run.args !== args) {
|
|
18421
18731
|
return void 0;
|
|
18422
18732
|
}
|
|
18423
18733
|
const message = payload.message;
|
|
18424
|
-
if (!
|
|
18734
|
+
if (!isRecord8(message) || !Array.isArray(message.content)) {
|
|
18425
18735
|
return void 0;
|
|
18426
18736
|
}
|
|
18427
18737
|
const blocks = message.content;
|
|
18428
|
-
const text = blocks.flatMap((block) =>
|
|
18429
|
-
const outcome =
|
|
18738
|
+
const text = blocks.flatMap((block) => isRecord8(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
|
|
18739
|
+
const outcome = isRecord8(payload.local_command_outcome) && typeof payload.local_command_outcome.kind === "string" ? payload.local_command_outcome.kind : void 0;
|
|
18430
18740
|
return { text, outcome };
|
|
18431
18741
|
}
|
|
18432
18742
|
function rcManualCompactBoundaryOf(event) {
|
|
18433
18743
|
const payload = event.envelope.payload;
|
|
18434
|
-
if (!
|
|
18744
|
+
if (!isRecord8(payload) || payload.type !== "system" || payload.subtype !== "compact_boundary" || !isRecord8(payload.compact_metadata)) {
|
|
18435
18745
|
return void 0;
|
|
18436
18746
|
}
|
|
18437
18747
|
const metadata = payload.compact_metadata;
|
|
@@ -18442,7 +18752,7 @@ function rcManualCompactBoundaryOf(event) {
|
|
|
18442
18752
|
}
|
|
18443
18753
|
function isPeerDelivery(event, text) {
|
|
18444
18754
|
const payload = event.envelope.payload;
|
|
18445
|
-
if (!
|
|
18755
|
+
if (!isRecord8(payload) || payload.type !== "user" || !isRecord8(payload.origin) || payload.origin.kind !== "peer" || !isRecord8(payload.message)) {
|
|
18446
18756
|
return false;
|
|
18447
18757
|
}
|
|
18448
18758
|
return typeof payload.message.content === "string" && payload.message.content.includes(text);
|
|
@@ -18559,7 +18869,7 @@ function createRcClaudeCodeVersions(fanout) {
|
|
|
18559
18869
|
const versions = /* @__PURE__ */ new Map();
|
|
18560
18870
|
fanout.subscribe(void 0, (event) => {
|
|
18561
18871
|
const payload = event.envelope.payload;
|
|
18562
|
-
if (event.envelope.source === "worker" &&
|
|
18872
|
+
if (event.envelope.source === "worker" && isRecord8(payload) && payload.type === "system" && payload.subtype === "init" && typeof payload.claude_code_version === "string") {
|
|
18563
18873
|
versions.set(event.session, payload.claude_code_version);
|
|
18564
18874
|
}
|
|
18565
18875
|
});
|
|
@@ -18764,47 +19074,47 @@ function createRcSessionCommands(deps) {
|
|
|
18764
19074
|
}
|
|
18765
19075
|
|
|
18766
19076
|
// src/frontdoor/rcSlashCommandSchemas.ts
|
|
18767
|
-
var WaitMsSchema =
|
|
18768
|
-
var RcGoalSessionInputSchema =
|
|
18769
|
-
session:
|
|
19077
|
+
var WaitMsSchema = import_zod24.z.int().positive().max(RC_SESSION_COMMAND_MAX_WAIT_MS).optional();
|
|
19078
|
+
var RcGoalSessionInputSchema = import_zod24.z.strictObject({
|
|
19079
|
+
session: import_zod24.z.string().min(1),
|
|
18770
19080
|
waitMs: WaitMsSchema
|
|
18771
19081
|
});
|
|
18772
|
-
var RcGoalSetInputSchema =
|
|
18773
|
-
session:
|
|
18774
|
-
condition:
|
|
19082
|
+
var RcGoalSetInputSchema = import_zod24.z.strictObject({
|
|
19083
|
+
session: import_zod24.z.string().min(1),
|
|
19084
|
+
condition: import_zod24.z.string().trim().min(1).max(RC_GOAL_CONDITION_MAX_CHARS).regex(/^[^\r\n]*$/u, "a goal condition is one line"),
|
|
18775
19085
|
waitMs: WaitMsSchema
|
|
18776
19086
|
});
|
|
18777
|
-
var RcCompactInputSchema =
|
|
18778
|
-
session:
|
|
19087
|
+
var RcCompactInputSchema = import_zod24.z.strictObject({
|
|
19088
|
+
session: import_zod24.z.string().min(1),
|
|
18779
19089
|
waitMs: WaitMsSchema
|
|
18780
19090
|
});
|
|
18781
|
-
var RcCompactWithInstructionsInputSchema =
|
|
18782
|
-
session:
|
|
18783
|
-
instructions:
|
|
19091
|
+
var RcCompactWithInstructionsInputSchema = import_zod24.z.strictObject({
|
|
19092
|
+
session: import_zod24.z.string().min(1),
|
|
19093
|
+
instructions: import_zod24.z.string().trim().min(1).max(RC_COMPACT_INSTRUCTIONS_MAX_CHARS),
|
|
18784
19094
|
waitMs: WaitMsSchema
|
|
18785
19095
|
});
|
|
18786
19096
|
var commandAnswerShape = {
|
|
18787
|
-
session:
|
|
18788
|
-
route:
|
|
19097
|
+
session: import_zod24.z.string(),
|
|
19098
|
+
route: import_zod24.z.enum(["supervised", "self-hosted"])
|
|
18789
19099
|
};
|
|
18790
|
-
var RcGoalGetOutputSchema =
|
|
19100
|
+
var RcGoalGetOutputSchema = import_zod24.z.strictObject({
|
|
18791
19101
|
...commandAnswerShape,
|
|
18792
|
-
goal:
|
|
19102
|
+
goal: import_zod24.z.strictObject({ condition: import_zod24.z.string(), iterations: import_zod24.z.int().nonnegative(), lastCheck: import_zod24.z.string().optional() }).nullable()
|
|
18793
19103
|
});
|
|
18794
|
-
var RcGoalSetOutputSchema =
|
|
19104
|
+
var RcGoalSetOutputSchema = import_zod24.z.strictObject({
|
|
18795
19105
|
...commandAnswerShape,
|
|
18796
|
-
condition:
|
|
18797
|
-
superseded:
|
|
19106
|
+
condition: import_zod24.z.string(),
|
|
19107
|
+
superseded: import_zod24.z.string().nullable()
|
|
18798
19108
|
});
|
|
18799
|
-
var RcGoalClearOutputSchema =
|
|
19109
|
+
var RcGoalClearOutputSchema = import_zod24.z.strictObject({
|
|
18800
19110
|
...commandAnswerShape,
|
|
18801
|
-
cleared:
|
|
19111
|
+
cleared: import_zod24.z.string().nullable()
|
|
18802
19112
|
});
|
|
18803
|
-
var RcCompactOutputSchema =
|
|
19113
|
+
var RcCompactOutputSchema = import_zod24.z.strictObject({
|
|
18804
19114
|
...commandAnswerShape,
|
|
18805
|
-
trigger:
|
|
18806
|
-
preTokens:
|
|
18807
|
-
postTokens:
|
|
19115
|
+
trigger: import_zod24.z.string(),
|
|
19116
|
+
preTokens: import_zod24.z.number().optional(),
|
|
19117
|
+
postTokens: import_zod24.z.number().optional()
|
|
18808
19118
|
});
|
|
18809
19119
|
|
|
18810
19120
|
// src/frontdoor/rcApi.ts
|
|
@@ -18865,14 +19175,16 @@ function createRcApiRouter(deps) {
|
|
|
18865
19175
|
}),
|
|
18866
19176
|
pending: authed.meta((0, import_openapi.openapi)({ method: "GET", path: "/rest/rc/pending", summary: "Read the control requests awaiting an answer", tags: [RC_API_TAG] })).input(RcSessionQuerySchema).output(RcPendingOutputSchema).handler(({ input }) => {
|
|
18867
19177
|
const pending = deps.pendingOf(input.session);
|
|
18868
|
-
|
|
19178
|
+
const statuses = deps.statusOf(input.session);
|
|
19179
|
+
if (input.session !== void 0 && statuses.length === 0) {
|
|
18869
19180
|
throw new import_client.ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input.session) });
|
|
18870
19181
|
}
|
|
18871
|
-
|
|
19182
|
+
const dropped = statuses.flatMap((status) => status.pendingDropped === void 0 ? [] : [{ sessionId: status.id, count: status.pendingDropped }]);
|
|
19183
|
+
return { pending, ...dropped.length === 0 ? {} : { dropped } };
|
|
18872
19184
|
}),
|
|
18873
19185
|
send: authed.meta((0, import_openapi.openapi)({ method: "POST", path: "/rest/rc/send", summary: "Send one message into a session", tags: [RC_API_TAG] })).input(RcSendInputSchema).output(RcWriteOutputSchema).handler(async ({ input }) => ({ session: input.session, sequenceNums: delivered(input.session, await deps.inject(input.session, input.text)) })),
|
|
18874
|
-
answer: authed.meta((0, import_openapi.openapi)({ method: "POST", path: "/rest/rc/answer", summary: "Answer one pending control request", tags: [RC_API_TAG] })).input(RcAnswerInputSchema).output(RcAnswerOutputSchema).handler(async ({ input }) => {
|
|
18875
|
-
const decision = { approve: input.approve, message: input.approve || input.text === void 0 ? void 0 : input.text };
|
|
19186
|
+
answer: authed.meta((0, import_openapi.openapi)({ method: "POST", path: "/rest/rc/answer", summary: "Answer one pending control request: approve or deny it, or choose the options of a pending question", tags: [RC_API_TAG] })).input(RcAnswerInputSchema).output(RcAnswerOutputSchema).handler(async ({ input }) => {
|
|
19187
|
+
const decision = { approve: input.approve, message: input.approve || input.text === void 0 ? void 0 : input.text, ...input.choices === void 0 ? {} : { choices: input.choices } };
|
|
18876
19188
|
return { session: input.session, request: input.request, sequenceNums: delivered(input.session, await deps.answer(input.session, input.request, decision)) };
|
|
18877
19189
|
}),
|
|
18878
19190
|
interrupt: authed.meta((0, import_openapi.openapi)({ method: "POST", path: "/rest/rc/interrupt", summary: "Interrupt a session's running turn", tags: [RC_API_TAG] })).input(RcInterruptInputSchema).output(RcControlWriteOutputSchema).handler(async ({ input }) => ({ session: input.session, ...deliveredControl(input.session, await deps.interrupt(input.session)) })),
|
|
@@ -19023,48 +19335,48 @@ init_cliError();
|
|
|
19023
19335
|
init_package();
|
|
19024
19336
|
|
|
19025
19337
|
// src/codex/appServerSchemas.ts
|
|
19026
|
-
var
|
|
19338
|
+
var import_zod25 = require("zod");
|
|
19027
19339
|
var CODEX_APP_SERVER_GENERATED_AGAINST = "0.160.0";
|
|
19028
|
-
var RateLimitWindowSchema =
|
|
19029
|
-
usedPercent:
|
|
19030
|
-
resetsAt:
|
|
19031
|
-
windowDurationMins:
|
|
19032
|
-
});
|
|
19033
|
-
var RateLimitSnapshotSchema =
|
|
19034
|
-
limitId:
|
|
19035
|
-
limitName:
|
|
19036
|
-
planType:
|
|
19340
|
+
var RateLimitWindowSchema = import_zod25.z.object({
|
|
19341
|
+
usedPercent: import_zod25.z.number(),
|
|
19342
|
+
resetsAt: import_zod25.z.number().nullish(),
|
|
19343
|
+
windowDurationMins: import_zod25.z.number().nullish()
|
|
19344
|
+
});
|
|
19345
|
+
var RateLimitSnapshotSchema = import_zod25.z.object({
|
|
19346
|
+
limitId: import_zod25.z.string().nullish(),
|
|
19347
|
+
limitName: import_zod25.z.string().nullish(),
|
|
19348
|
+
planType: import_zod25.z.string().nullish(),
|
|
19037
19349
|
primary: RateLimitWindowSchema.nullish(),
|
|
19038
19350
|
secondary: RateLimitWindowSchema.nullish(),
|
|
19039
|
-
rateLimitReachedType:
|
|
19040
|
-
spendControlReached:
|
|
19041
|
-
});
|
|
19042
|
-
var RateLimitResetCreditSchema =
|
|
19043
|
-
id:
|
|
19044
|
-
grantedAt:
|
|
19045
|
-
expiresAt:
|
|
19046
|
-
resetType:
|
|
19047
|
-
status:
|
|
19048
|
-
title:
|
|
19049
|
-
description:
|
|
19050
|
-
});
|
|
19051
|
-
var CodexAccountSchema =
|
|
19052
|
-
|
|
19053
|
-
|
|
19054
|
-
|
|
19351
|
+
rateLimitReachedType: import_zod25.z.string().nullish(),
|
|
19352
|
+
spendControlReached: import_zod25.z.boolean().nullish()
|
|
19353
|
+
});
|
|
19354
|
+
var RateLimitResetCreditSchema = import_zod25.z.object({
|
|
19355
|
+
id: import_zod25.z.string(),
|
|
19356
|
+
grantedAt: import_zod25.z.number(),
|
|
19357
|
+
expiresAt: import_zod25.z.number().nullish(),
|
|
19358
|
+
resetType: import_zod25.z.string(),
|
|
19359
|
+
status: import_zod25.z.string(),
|
|
19360
|
+
title: import_zod25.z.string().nullish(),
|
|
19361
|
+
description: import_zod25.z.string().nullish()
|
|
19362
|
+
});
|
|
19363
|
+
var CodexAccountSchema = import_zod25.z.discriminatedUnion("type", [
|
|
19364
|
+
import_zod25.z.object({ type: import_zod25.z.literal("apiKey") }),
|
|
19365
|
+
import_zod25.z.object({ type: import_zod25.z.literal("chatgpt"), email: import_zod25.z.string().nullable(), planType: import_zod25.z.string() }),
|
|
19366
|
+
import_zod25.z.object({ type: import_zod25.z.literal("amazonBedrock"), usesCodexManagedCredentials: import_zod25.z.boolean().default(false) })
|
|
19055
19367
|
]);
|
|
19056
|
-
var CodexAccountReadSchema =
|
|
19368
|
+
var CodexAccountReadSchema = import_zod25.z.object({
|
|
19057
19369
|
account: CodexAccountSchema.nullable(),
|
|
19058
|
-
requiresOpenaiAuth:
|
|
19370
|
+
requiresOpenaiAuth: import_zod25.z.boolean()
|
|
19059
19371
|
});
|
|
19060
|
-
var CodexRateLimitsReadSchema =
|
|
19372
|
+
var CodexRateLimitsReadSchema = import_zod25.z.object({
|
|
19061
19373
|
rateLimits: RateLimitSnapshotSchema,
|
|
19062
|
-
rateLimitsByLimitId:
|
|
19063
|
-
rateLimitResetCredits:
|
|
19064
|
-
accountId:
|
|
19065
|
-
ordinaryUsageAllowed:
|
|
19374
|
+
rateLimitsByLimitId: import_zod25.z.record(import_zod25.z.string(), RateLimitSnapshotSchema).nullish(),
|
|
19375
|
+
rateLimitResetCredits: import_zod25.z.object({ availableCount: import_zod25.z.number(), credits: import_zod25.z.array(RateLimitResetCreditSchema).nullish() }).nullish(),
|
|
19376
|
+
accountId: import_zod25.z.string().nullish(),
|
|
19377
|
+
ordinaryUsageAllowed: import_zod25.z.boolean().nullish()
|
|
19066
19378
|
});
|
|
19067
|
-
var CodexInitializeResultSchema =
|
|
19379
|
+
var CodexInitializeResultSchema = import_zod25.z.object({ userAgent: import_zod25.z.string() });
|
|
19068
19380
|
|
|
19069
19381
|
// src/codex/appServer.ts
|
|
19070
19382
|
var CodexAppServerUnavailableError = class extends CliError {
|
|
@@ -22277,8 +22589,8 @@ function rcFanoutOnDoorHub(fanout, hub) {
|
|
|
22277
22589
|
|
|
22278
22590
|
// src/frontdoor/rcEventLog.ts
|
|
22279
22591
|
var RC_SESSION_EVENT_TOKEN_MAX_CHARS = 255;
|
|
22280
|
-
var
|
|
22281
|
-
var
|
|
22592
|
+
var HIGH_SURROGATE_FIRST2 = 55296;
|
|
22593
|
+
var HIGH_SURROGATE_LAST2 = 56319;
|
|
22282
22594
|
var LOW_SURROGATE_FIRST = 56320;
|
|
22283
22595
|
var LOW_SURROGATE_LAST = 57343;
|
|
22284
22596
|
var CUT_MARKER = "...";
|
|
@@ -22289,7 +22601,7 @@ var NUMBER_BYTES = Float64Array.BYTES_PER_ELEMENT;
|
|
|
22289
22601
|
var NUMBER_FIELDS = ["at", "sequence"].length;
|
|
22290
22602
|
var BYTES_PER_CODE_UNIT = Uint16Array.BYTES_PER_ELEMENT;
|
|
22291
22603
|
var RC_SESSION_END_REASONS = ["expired", "archived", "conflict"];
|
|
22292
|
-
var RC_PENDING_RETIRE_REASONS = ["answered", "
|
|
22604
|
+
var RC_PENDING_RETIRE_REASONS = ["answered", "withdrawn", "worker-stopped", "session-ended"];
|
|
22293
22605
|
var transitionBase = { session: import_zod43.z.string(), at: import_zod43.z.number() };
|
|
22294
22606
|
var cursorFields = { cursor: import_zod43.z.string(), sequence: import_zod43.z.int().positive() };
|
|
22295
22607
|
var sessionAppearedShape = { kind: import_zod43.z.literal("session-appeared"), ...transitionBase };
|
|
@@ -22350,7 +22662,7 @@ function parseCursor(cursor) {
|
|
|
22350
22662
|
function codePointBoundary(text, at) {
|
|
22351
22663
|
const before = text.charCodeAt(at - 1);
|
|
22352
22664
|
const after = text.charCodeAt(at);
|
|
22353
|
-
const isHigh = before >=
|
|
22665
|
+
const isHigh = before >= HIGH_SURROGATE_FIRST2 && before <= HIGH_SURROGATE_LAST2;
|
|
22354
22666
|
const isLow = after >= LOW_SURROGATE_FIRST && after <= LOW_SURROGATE_LAST;
|
|
22355
22667
|
return isHigh && isLow ? at - 1 : at;
|
|
22356
22668
|
}
|
|
@@ -22828,15 +23140,15 @@ function createQuotaExpiringPublisher(hub, deps) {
|
|
|
22828
23140
|
|
|
22829
23141
|
// src/frontdoor/rcLiveUsage.ts
|
|
22830
23142
|
var RC_RATE_LIMIT_EVENT_TYPE = "rate_limit_event";
|
|
22831
|
-
function
|
|
23143
|
+
function isRecord10(value) {
|
|
22832
23144
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22833
23145
|
}
|
|
22834
23146
|
function rcRateLimitInfoOf(event) {
|
|
22835
23147
|
const payload = event.envelope.payload;
|
|
22836
|
-
if (!
|
|
23148
|
+
if (!isRecord10(payload) || payload.type !== RC_RATE_LIMIT_EVENT_TYPE) {
|
|
22837
23149
|
return void 0;
|
|
22838
23150
|
}
|
|
22839
|
-
if (!
|
|
23151
|
+
if (!isRecord10(payload.rate_limit_info)) {
|
|
22840
23152
|
return void 0;
|
|
22841
23153
|
}
|
|
22842
23154
|
const parsed = RcRateLimitInfoSchema.safeParse(payload.rate_limit_info);
|
|
@@ -22924,7 +23236,7 @@ function createSseParser() {
|
|
|
22924
23236
|
}
|
|
22925
23237
|
};
|
|
22926
23238
|
}
|
|
22927
|
-
function
|
|
23239
|
+
function isRecord11(value) {
|
|
22928
23240
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22929
23241
|
}
|
|
22930
23242
|
function sequenceNumOf(value) {
|
|
@@ -22946,7 +23258,7 @@ function parseRcStreamEnvelope(parsed) {
|
|
|
22946
23258
|
} catch {
|
|
22947
23259
|
return void 0;
|
|
22948
23260
|
}
|
|
22949
|
-
if (!
|
|
23261
|
+
if (!isRecord11(data)) {
|
|
22950
23262
|
return void 0;
|
|
22951
23263
|
}
|
|
22952
23264
|
const eventType = data.event_type;
|
|
@@ -23199,7 +23511,7 @@ function withClientPlatform(payload, headers) {
|
|
|
23199
23511
|
const platform = headers[CLIENT_PLATFORM_HEADER];
|
|
23200
23512
|
return typeof platform === "string" && platform !== "" ? { ...rest, client_platform: platform } : rest;
|
|
23201
23513
|
}
|
|
23202
|
-
function
|
|
23514
|
+
function isRecord12(value) {
|
|
23203
23515
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23204
23516
|
}
|
|
23205
23517
|
function parseJsonObject2(body) {
|
|
@@ -23209,7 +23521,7 @@ function parseJsonObject2(body) {
|
|
|
23209
23521
|
} catch {
|
|
23210
23522
|
return void 0;
|
|
23211
23523
|
}
|
|
23212
|
-
return
|
|
23524
|
+
return isRecord12(parsed) ? parsed : void 0;
|
|
23213
23525
|
}
|
|
23214
23526
|
function nonEmptyString2(record, field) {
|
|
23215
23527
|
const value = record === void 0 ? void 0 : record[field];
|
|
@@ -23283,7 +23595,7 @@ async function serveRcClientChannels(ctx, tail, method, maxBatchEvents) {
|
|
|
23283
23595
|
}
|
|
23284
23596
|
const results = [];
|
|
23285
23597
|
for (const event of events) {
|
|
23286
|
-
if (!
|
|
23598
|
+
if (!isRecord12(event) || !isRecord12(event.payload)) {
|
|
23287
23599
|
await ctx.answerJson(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a teleport write is an object carrying one payload object" } });
|
|
23288
23600
|
return true;
|
|
23289
23601
|
}
|
|
@@ -23383,7 +23695,7 @@ async function serveRcCompatSessions(ctx, pathname, compatPath) {
|
|
|
23383
23695
|
// src/frontdoor/rcSelfHostConversations.ts
|
|
23384
23696
|
var RC_CONVERSATIONS_PATH_PREFIX = "/v1/code/conversations";
|
|
23385
23697
|
var RC_CONVERSATION_ID_PREFIX = "conv_";
|
|
23386
|
-
function
|
|
23698
|
+
function isRecord13(value) {
|
|
23387
23699
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23388
23700
|
}
|
|
23389
23701
|
function parseJsonObject3(body) {
|
|
@@ -23393,7 +23705,7 @@ function parseJsonObject3(body) {
|
|
|
23393
23705
|
} catch {
|
|
23394
23706
|
return void 0;
|
|
23395
23707
|
}
|
|
23396
|
-
return
|
|
23708
|
+
return isRecord13(parsed) ? parsed : void 0;
|
|
23397
23709
|
}
|
|
23398
23710
|
function nonEmptyString3(record, field) {
|
|
23399
23711
|
const value = record === void 0 ? void 0 : record[field];
|
|
@@ -23447,7 +23759,7 @@ async function serveRcConversations(ctx, pathname, method) {
|
|
|
23447
23759
|
}
|
|
23448
23760
|
const results = [];
|
|
23449
23761
|
for (const event of events) {
|
|
23450
|
-
if (!
|
|
23762
|
+
if (!isRecord13(event) || !isRecord13(event.payload)) {
|
|
23451
23763
|
await ctx.answerJson(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a write is an object carrying one payload object" } });
|
|
23452
23764
|
return;
|
|
23453
23765
|
}
|
|
@@ -23479,7 +23791,7 @@ var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:
|
|
|
23479
23791
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
23480
23792
|
var MS_PER_SECOND6 = 1e3;
|
|
23481
23793
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
23482
|
-
function
|
|
23794
|
+
function isRecord14(value) {
|
|
23483
23795
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23484
23796
|
}
|
|
23485
23797
|
function parseJsonObject4(body) {
|
|
@@ -23489,7 +23801,7 @@ function parseJsonObject4(body) {
|
|
|
23489
23801
|
} catch {
|
|
23490
23802
|
return void 0;
|
|
23491
23803
|
}
|
|
23492
|
-
return
|
|
23804
|
+
return isRecord14(parsed) ? parsed : void 0;
|
|
23493
23805
|
}
|
|
23494
23806
|
function growthBookFeatures() {
|
|
23495
23807
|
return {
|
|
@@ -23843,7 +24155,7 @@ var RC_SELF_HOST_WORKER_EPOCH = 1;
|
|
|
23843
24155
|
var RC_STREAM_EVENT_NAME2 = "client_event";
|
|
23844
24156
|
var CONFLICT_REASON_HEADER2 = "x-ccr-conflict-reason";
|
|
23845
24157
|
var CONFLICT_REASON_EPOCH_STALE = "epoch_stale";
|
|
23846
|
-
function
|
|
24158
|
+
function isRecord15(value) {
|
|
23847
24159
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23848
24160
|
}
|
|
23849
24161
|
function isWebSearchRefusal(value) {
|
|
@@ -23927,7 +24239,7 @@ function parseJsonObject5(body) {
|
|
|
23927
24239
|
} catch {
|
|
23928
24240
|
return void 0;
|
|
23929
24241
|
}
|
|
23930
|
-
return
|
|
24242
|
+
return isRecord15(parsed) ? parsed : void 0;
|
|
23931
24243
|
}
|
|
23932
24244
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
23933
24245
|
const encode = (value) => Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
|
|
@@ -24187,7 +24499,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24187
24499
|
if (status !== void 0) {
|
|
24188
24500
|
session.workerStatus = status;
|
|
24189
24501
|
}
|
|
24190
|
-
if (
|
|
24502
|
+
if (isRecord15(body?.external_metadata)) {
|
|
24191
24503
|
session.externalMetadata = body.external_metadata;
|
|
24192
24504
|
}
|
|
24193
24505
|
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
@@ -24217,7 +24529,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24217
24529
|
}
|
|
24218
24530
|
const results = [];
|
|
24219
24531
|
for (const event of events) {
|
|
24220
|
-
if (!
|
|
24532
|
+
if (!isRecord15(event) || !isRecord15(event.payload)) {
|
|
24221
24533
|
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a batch is an object carrying one payload object" } });
|
|
24222
24534
|
return;
|
|
24223
24535
|
}
|
|
@@ -24250,7 +24562,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24250
24562
|
return;
|
|
24251
24563
|
}
|
|
24252
24564
|
for (const event of events) {
|
|
24253
|
-
if (
|
|
24565
|
+
if (isRecord15(event)) {
|
|
24254
24566
|
session.internalEvents.push({ eventId: deps.newUuid(), body: event });
|
|
24255
24567
|
}
|
|
24256
24568
|
}
|
|
@@ -24346,7 +24658,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24346
24658
|
}
|
|
24347
24659
|
const results = [];
|
|
24348
24660
|
for (const event of events) {
|
|
24349
|
-
if (!
|
|
24661
|
+
if (!isRecord15(event) || !isRecord15(event.payload)) {
|
|
24350
24662
|
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a write is an object carrying one payload object" } });
|
|
24351
24663
|
return;
|
|
24352
24664
|
}
|
|
@@ -24484,7 +24796,7 @@ var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
|
24484
24796
|
var RC_SELF_HOST_RECORD_FILE = "credential.json";
|
|
24485
24797
|
var SELF_HOST_EMAIL = "selfhost@agent-shim.invalid";
|
|
24486
24798
|
var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
24487
|
-
function
|
|
24799
|
+
function isRecord16(value) {
|
|
24488
24800
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24489
24801
|
}
|
|
24490
24802
|
function readJsonObject(fs17, file) {
|
|
@@ -24498,7 +24810,7 @@ function readJsonObject(fs17, file) {
|
|
|
24498
24810
|
} catch {
|
|
24499
24811
|
return void 0;
|
|
24500
24812
|
}
|
|
24501
|
-
return
|
|
24813
|
+
return isRecord16(parsed) ? parsed : void 0;
|
|
24502
24814
|
}
|
|
24503
24815
|
function readRcSelfHostRecord(fs17, frontdoorDir) {
|
|
24504
24816
|
const parsed = readJsonObject(fs17, import_node_path45.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
@@ -24526,7 +24838,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
24526
24838
|
const recordFile2 = import_node_path45.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
24527
24839
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
24528
24840
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
24529
|
-
const existingOauth =
|
|
24841
|
+
const existingOauth = isRecord16(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
24530
24842
|
const existingToken = typeof existingOauth?.accessToken === "string" && existingOauth.accessToken !== "" ? existingOauth.accessToken : void 0;
|
|
24531
24843
|
const existingIsOwn = existingToken !== void 0 && previousRecord?.accessToken === existingToken;
|
|
24532
24844
|
if (existingToken !== void 0 && !existingIsOwn && !deps.force) {
|
|
@@ -24543,7 +24855,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
24543
24855
|
deps.fs.writeFilePrivate(credentialsFile, `${JSON.stringify({ ...existingCredentials, claudeAiOauth: { accessToken, refreshToken, expiresAt: null, scopes: [...RC_SELF_HOST_SCOPE_LIST], subscriptionType: SELF_HOST_SUBSCRIPTION_TYPE, rateLimitTier: null } }, null, 2)}
|
|
24544
24856
|
`);
|
|
24545
24857
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
24546
|
-
const existingBlock = (value) =>
|
|
24858
|
+
const existingBlock = (value) => isRecord16(value) ? value : {};
|
|
24547
24859
|
deps.fs.writeFilePrivate(claudeJsonFile, `${JSON.stringify({
|
|
24548
24860
|
...claudeJson,
|
|
24549
24861
|
oauthAccount: {
|
|
@@ -25301,7 +25613,6 @@ init_ownCli();
|
|
|
25301
25613
|
RC_GOAL_CONDITION_MAX_CHARS,
|
|
25302
25614
|
RC_IDLE_EXPIRY_MS,
|
|
25303
25615
|
RC_ORPC_PATH_PREFIX,
|
|
25304
|
-
RC_PENDING_DEADLINE_MS,
|
|
25305
25616
|
RC_PENDING_RETIRE_REASONS,
|
|
25306
25617
|
RC_PERMISSION_MODES,
|
|
25307
25618
|
RC_READ_FILE_ENCODINGS,
|