claude-use 11.90.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cli.cjs +764 -368
- package/dist/index.cjs +771 -502
- package/dist/index.mjs +739 -469
- package/dist/types/index.d.ts +143 -41
- 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();
|
|
@@ -6691,7 +6691,7 @@ var init_blockingSpawn = __esm({
|
|
|
6691
6691
|
|
|
6692
6692
|
// src/usage/signIn.ts
|
|
6693
6693
|
function claudeCodeKeychainService(configDir) {
|
|
6694
|
-
return `${KEYCHAIN_SERVICE_PREFIX}-${(0,
|
|
6694
|
+
return `${KEYCHAIN_SERVICE_PREFIX}-${(0, import_node_crypto7.createHash)("sha256").update(configDir).digest("hex").slice(0, KEYCHAIN_SERVICE_HASH_DIGITS)}`;
|
|
6695
6695
|
}
|
|
6696
6696
|
function keychainHasItem(run, configDir) {
|
|
6697
6697
|
return run.run("security", ["find-generic-password", "-s", claudeCodeKeychainService(configDir)]).status === 0;
|
|
@@ -6724,11 +6724,11 @@ function identitySignIn(fs17, probe, identity) {
|
|
|
6724
6724
|
platform: probe.platform
|
|
6725
6725
|
});
|
|
6726
6726
|
}
|
|
6727
|
-
var
|
|
6727
|
+
var import_node_crypto7, import_node_path19, CREDENTIALS_FILE, KEYCHAIN_SERVICE_PREFIX, KEYCHAIN_SERVICE_HASH_DIGITS;
|
|
6728
6728
|
var init_signIn = __esm({
|
|
6729
6729
|
"src/usage/signIn.ts"() {
|
|
6730
6730
|
"use strict";
|
|
6731
|
-
|
|
6731
|
+
import_node_crypto7 = require("node:crypto");
|
|
6732
6732
|
import_node_path19 = __toESM(require("node:path"), 1);
|
|
6733
6733
|
CREDENTIALS_FILE = ".credentials.json";
|
|
6734
6734
|
KEYCHAIN_SERVICE_PREFIX = "Claude Code-credentials";
|
|
@@ -6863,7 +6863,7 @@ function serialisedFor(entry, owner) {
|
|
|
6863
6863
|
return JSON.stringify({ owner, ...withoutOwner(entry) });
|
|
6864
6864
|
}
|
|
6865
6865
|
function tempPathFor(target) {
|
|
6866
|
-
return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0,
|
|
6866
|
+
return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0, import_node_crypto8.randomUUID)()}`);
|
|
6867
6867
|
}
|
|
6868
6868
|
function processRuns(pid) {
|
|
6869
6869
|
try {
|
|
@@ -6982,11 +6982,11 @@ function createRealCredentialCache(root, keychain = { run: security, platform: p
|
|
|
6982
6982
|
function realCredentialCacheEnv(paths) {
|
|
6983
6983
|
return { port: createRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
|
|
6984
6984
|
}
|
|
6985
|
-
var
|
|
6985
|
+
var import_node_crypto8, import_node_fs5, import_node_path20, CACHE_DIR_MODE, CACHE_FILE_MODE, TEMP_PREFIX, TEMP_NAME, RELEASED_TEMP_NAME;
|
|
6986
6986
|
var init_realCredentialCache = __esm({
|
|
6987
6987
|
"src/realCredentialCache.ts"() {
|
|
6988
6988
|
"use strict";
|
|
6989
|
-
|
|
6989
|
+
import_node_crypto8 = require("node:crypto");
|
|
6990
6990
|
import_node_fs5 = __toESM(require("node:fs"), 1);
|
|
6991
6991
|
import_node_path20 = __toESM(require("node:path"), 1);
|
|
6992
6992
|
init_blockingSpawn();
|
|
@@ -7143,7 +7143,7 @@ function migrateHeadroomState(fs17, files, isRunning) {
|
|
|
7143
7143
|
fs17.removeRecursive(files.legacyStateFile);
|
|
7144
7144
|
}
|
|
7145
7145
|
function hashAllowlist(allowlist) {
|
|
7146
|
-
return (0,
|
|
7146
|
+
return (0, import_node_crypto9.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
7147
7147
|
}
|
|
7148
7148
|
function formatAllowlistFile(allowlist) {
|
|
7149
7149
|
return allowlist.map((entry) => `${entry}
|
|
@@ -7248,40 +7248,40 @@ function readStartLock(fs17, lockFile) {
|
|
|
7248
7248
|
return void 0;
|
|
7249
7249
|
}
|
|
7250
7250
|
}
|
|
7251
|
-
var
|
|
7251
|
+
var import_node_crypto9, import_node_path21, import_zod14, 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
7252
|
var init_state2 = __esm({
|
|
7253
7253
|
"src/headroom/state.ts"() {
|
|
7254
7254
|
"use strict";
|
|
7255
|
-
|
|
7255
|
+
import_node_crypto9 = require("node:crypto");
|
|
7256
7256
|
import_node_path21 = __toESM(require("node:path"), 1);
|
|
7257
|
-
|
|
7257
|
+
import_zod14 = require("zod");
|
|
7258
7258
|
init_schema();
|
|
7259
|
-
HeadroomStateSchema =
|
|
7259
|
+
HeadroomStateSchema = import_zod14.z.strictObject({
|
|
7260
7260
|
/** The supervisor process owning the daemon. Alive means someone is keeping headroom running. */
|
|
7261
|
-
supervisorPid:
|
|
7261
|
+
supervisorPid: import_zod14.z.number().int().positive().optional(),
|
|
7262
7262
|
/** 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:
|
|
7263
|
+
headroomPid: import_zod14.z.number().int().positive().optional(),
|
|
7264
7264
|
/**
|
|
7265
7265
|
* 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
7266
|
*/
|
|
7267
|
-
socketPath:
|
|
7267
|
+
socketPath: import_zod14.z.string().min(1).optional(),
|
|
7268
7268
|
/** The `headroom --version` output of the running install. */
|
|
7269
|
-
version:
|
|
7269
|
+
version: import_zod14.z.string().optional(),
|
|
7270
7270
|
/**
|
|
7271
7271
|
* 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
7272
|
*/
|
|
7273
|
-
allowlistHash:
|
|
7273
|
+
allowlistHash: import_zod14.z.string().optional(),
|
|
7274
7274
|
/** Hash of the token-saving settings the running proxy was started with, so a settings change is detected as drift. */
|
|
7275
|
-
settingsHash:
|
|
7275
|
+
settingsHash: import_zod14.z.string().optional(),
|
|
7276
7276
|
/** The install spec the running install was last installed from, so a `source` config change is detected as drift. */
|
|
7277
|
-
installedSource:
|
|
7277
|
+
installedSource: import_zod14.z.string().optional(),
|
|
7278
7278
|
/** 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:
|
|
7279
|
+
installing: import_zod14.z.string().optional(),
|
|
7280
7280
|
/** The last fatal error, kept across shutdowns so `headroom status` can explain a daemon that is not running. */
|
|
7281
|
-
lastError:
|
|
7281
|
+
lastError: import_zod14.z.string().optional()
|
|
7282
7282
|
});
|
|
7283
|
-
HeadroomSessionSchema =
|
|
7284
|
-
HeadroomLockSchema =
|
|
7283
|
+
HeadroomSessionSchema = import_zod14.z.strictObject({ pid: import_zod14.z.number().int().positive(), startedAt: import_zod14.z.number(), supervisorPid: import_zod14.z.number().int().positive() });
|
|
7284
|
+
HeadroomLockSchema = import_zod14.z.strictObject({ pid: import_zod14.z.number().int().positive(), at: import_zod14.z.number() });
|
|
7285
7285
|
HEADROOM_ALLOWLIST_FILE_FLAG = "--allowed-base-urls-file";
|
|
7286
7286
|
ALLOWLIST_LINE_BREAKS = "\\n\\r\\u000b\\u000c\\u001c\\u001d\\u001e\\u0085\\u2028\\u2029";
|
|
7287
7287
|
ALLOWLIST_WHITESPACE = "\\t\\n\\u000b\\u000c\\r\\u001c-\\u001f \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
|
|
@@ -7495,13 +7495,13 @@ function settingsEnv(settings) {
|
|
|
7495
7495
|
return settings.rolloutChannel === void 0 ? {} : { HEADROOM_ROLLOUT_CHANNEL: settings.rolloutChannel };
|
|
7496
7496
|
}
|
|
7497
7497
|
function hashSettings(settings) {
|
|
7498
|
-
return (0,
|
|
7498
|
+
return (0, import_node_crypto10.createHash)("sha256").update(JSON.stringify([...settingsArgs(settings), JSON.stringify(settingsEnv(settings))])).digest("hex");
|
|
7499
7499
|
}
|
|
7500
|
-
var
|
|
7500
|
+
var import_node_crypto10;
|
|
7501
7501
|
var init_settings = __esm({
|
|
7502
7502
|
"src/headroom/settings.ts"() {
|
|
7503
7503
|
"use strict";
|
|
7504
|
-
|
|
7504
|
+
import_node_crypto10 = require("node:crypto");
|
|
7505
7505
|
}
|
|
7506
7506
|
});
|
|
7507
7507
|
|
|
@@ -7701,14 +7701,14 @@ function pinnedGitCommit(spec) {
|
|
|
7701
7701
|
const ref = GIT_SPEC_RE.exec(spec)?.[1];
|
|
7702
7702
|
return ref !== void 0 && COMMIT_SHA_RE.test(ref) ? ref.toLowerCase() : void 0;
|
|
7703
7703
|
}
|
|
7704
|
-
var
|
|
7704
|
+
var import_zod15, GIT_SPEC_RE, COMMIT_SHA_RE, DirectUrlSchema;
|
|
7705
7705
|
var init_source = __esm({
|
|
7706
7706
|
"src/headroom/source.ts"() {
|
|
7707
7707
|
"use strict";
|
|
7708
|
-
|
|
7708
|
+
import_zod15 = require("zod");
|
|
7709
7709
|
GIT_SPEC_RE = /git\+[^@\s]+(?:@([^\s#]+))?/;
|
|
7710
7710
|
COMMIT_SHA_RE = /^[0-9a-f]{40}$/i;
|
|
7711
|
-
DirectUrlSchema =
|
|
7711
|
+
DirectUrlSchema = import_zod15.z.object({ vcs_info: import_zod15.z.object({ commit_id: import_zod15.z.string() }) });
|
|
7712
7712
|
}
|
|
7713
7713
|
});
|
|
7714
7714
|
|
|
@@ -8422,14 +8422,14 @@ function realResolveClaudeBinary(isOwnBinary) {
|
|
|
8422
8422
|
function realInstalledClaudeVersions() {
|
|
8423
8423
|
return installedVersions(listVersionsDir(defaultVersionsDir()));
|
|
8424
8424
|
}
|
|
8425
|
-
var import_node_child_process2,
|
|
8425
|
+
var import_node_child_process2, import_node_crypto11, 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
8426
|
var init_realPorts = __esm({
|
|
8427
8427
|
"src/realPorts.ts"() {
|
|
8428
8428
|
"use strict";
|
|
8429
8429
|
init_blockingSpawn();
|
|
8430
8430
|
init_processRole();
|
|
8431
8431
|
import_node_child_process2 = require("node:child_process");
|
|
8432
|
-
|
|
8432
|
+
import_node_crypto11 = require("node:crypto");
|
|
8433
8433
|
import_node_fs6 = __toESM(require("node:fs"), 1);
|
|
8434
8434
|
import_node_os2 = __toESM(require("node:os"), 1);
|
|
8435
8435
|
import_node_path24 = __toESM(require("node:path"), 1);
|
|
@@ -8580,7 +8580,7 @@ var init_realPorts = __esm({
|
|
|
8580
8580
|
},
|
|
8581
8581
|
hashFile(filePath) {
|
|
8582
8582
|
try {
|
|
8583
|
-
return (0,
|
|
8583
|
+
return (0, import_node_crypto11.createHash)("sha256").update(import_node_fs6.default.readFileSync(filePath)).digest("hex");
|
|
8584
8584
|
} catch (error) {
|
|
8585
8585
|
if (isEnoent3(error) || isErrorWithCode(error, "EISDIR")) {
|
|
8586
8586
|
return void 0;
|
|
@@ -9041,24 +9041,24 @@ function planOf(account) {
|
|
|
9041
9041
|
}
|
|
9042
9042
|
return { kind: "subscription", capacity: 1, recognised: BASE_TIER.test(tier), ...tierField };
|
|
9043
9043
|
}
|
|
9044
|
-
var
|
|
9044
|
+
var import_zod16, PlanClassSchema, TIER_MULTIPLIER, ZERO_TIER, BASE_TIER;
|
|
9045
9045
|
var init_plan2 = __esm({
|
|
9046
9046
|
"src/usage/plan.ts"() {
|
|
9047
9047
|
"use strict";
|
|
9048
|
-
|
|
9049
|
-
PlanClassSchema =
|
|
9050
|
-
|
|
9051
|
-
kind:
|
|
9048
|
+
import_zod16 = require("zod");
|
|
9049
|
+
PlanClassSchema = import_zod16.z.union([
|
|
9050
|
+
import_zod16.z.strictObject({
|
|
9051
|
+
kind: import_zod16.z.literal("subscription"),
|
|
9052
9052
|
/** The plan's size as a multiple of the smallest subscription tier (Max is 5, Ultra is 20). */
|
|
9053
|
-
capacity:
|
|
9053
|
+
capacity: import_zod16.z.number().positive(),
|
|
9054
9054
|
/** 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:
|
|
9055
|
+
recognised: import_zod16.z.boolean(),
|
|
9056
9056
|
/** The tier string the classification rests on, when the account had one. */
|
|
9057
|
-
tier:
|
|
9057
|
+
tier: import_zod16.z.string().optional()
|
|
9058
9058
|
}),
|
|
9059
|
-
|
|
9060
|
-
kind:
|
|
9061
|
-
tier:
|
|
9059
|
+
import_zod16.z.strictObject({
|
|
9060
|
+
kind: import_zod16.z.literal("pay-per-use"),
|
|
9061
|
+
tier: import_zod16.z.string().optional()
|
|
9062
9062
|
})
|
|
9063
9063
|
]);
|
|
9064
9064
|
TIER_MULTIPLIER = /(?:^|_)(\d+)x$/;
|
|
@@ -9068,21 +9068,21 @@ var init_plan2 = __esm({
|
|
|
9068
9068
|
});
|
|
9069
9069
|
|
|
9070
9070
|
// src/usage/scan.ts
|
|
9071
|
-
var
|
|
9071
|
+
var import_zod17, AnthropicUsageSchema, ErrorObjectSchema;
|
|
9072
9072
|
var init_scan = __esm({
|
|
9073
9073
|
"src/usage/scan.ts"() {
|
|
9074
9074
|
"use strict";
|
|
9075
|
-
|
|
9076
|
-
AnthropicUsageSchema =
|
|
9077
|
-
input_tokens:
|
|
9078
|
-
output_tokens:
|
|
9079
|
-
cache_creation_input_tokens:
|
|
9080
|
-
cache_read_input_tokens:
|
|
9075
|
+
import_zod17 = require("zod");
|
|
9076
|
+
AnthropicUsageSchema = import_zod17.z.looseObject({
|
|
9077
|
+
input_tokens: import_zod17.z.number().int().nonnegative().nullish(),
|
|
9078
|
+
output_tokens: import_zod17.z.number().int().nonnegative().nullish(),
|
|
9079
|
+
cache_creation_input_tokens: import_zod17.z.number().int().nonnegative().nullish(),
|
|
9080
|
+
cache_read_input_tokens: import_zod17.z.number().int().nonnegative().nullish()
|
|
9081
9081
|
});
|
|
9082
|
-
ErrorObjectSchema =
|
|
9083
|
-
type:
|
|
9084
|
-
code:
|
|
9085
|
-
message:
|
|
9082
|
+
ErrorObjectSchema = import_zod17.z.looseObject({
|
|
9083
|
+
type: import_zod17.z.string().optional(),
|
|
9084
|
+
code: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional(),
|
|
9085
|
+
message: import_zod17.z.string().optional()
|
|
9086
9086
|
});
|
|
9087
9087
|
}
|
|
9088
9088
|
});
|
|
@@ -9732,12 +9732,12 @@ function recordStickyPick(fs17, picksFile, directory, identity, nowMs) {
|
|
|
9732
9732
|
fs17.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
9733
9733
|
`);
|
|
9734
9734
|
}
|
|
9735
|
-
var import_node_path26,
|
|
9735
|
+
var import_node_path26, import_zod18, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
9736
9736
|
var init_poolPick = __esm({
|
|
9737
9737
|
"src/usage/poolPick.ts"() {
|
|
9738
9738
|
"use strict";
|
|
9739
9739
|
import_node_path26 = __toESM(require("node:path"), 1);
|
|
9740
|
-
|
|
9740
|
+
import_zod18 = require("zod");
|
|
9741
9741
|
init_cliError();
|
|
9742
9742
|
init_identity();
|
|
9743
9743
|
init_schema();
|
|
@@ -9754,17 +9754,17 @@ var init_poolPick = __esm({
|
|
|
9754
9754
|
}
|
|
9755
9755
|
};
|
|
9756
9756
|
SCHEMA_VERSION = 1;
|
|
9757
|
-
PickEntrySchema =
|
|
9758
|
-
PicksFileSchema =
|
|
9759
|
-
schemaVersion:
|
|
9760
|
-
picks:
|
|
9757
|
+
PickEntrySchema = import_zod18.z.strictObject({ identity: import_zod18.z.string().min(1), at: import_zod18.z.iso.datetime() });
|
|
9758
|
+
PicksFileSchema = import_zod18.z.strictObject({
|
|
9759
|
+
schemaVersion: import_zod18.z.literal(SCHEMA_VERSION),
|
|
9760
|
+
picks: import_zod18.z.record(import_zod18.z.string().min(1), PickEntrySchema)
|
|
9761
9761
|
});
|
|
9762
9762
|
}
|
|
9763
9763
|
});
|
|
9764
9764
|
|
|
9765
9765
|
// src/identityRenameJournal.ts
|
|
9766
9766
|
function renamePairFileName(from, to, suffix) {
|
|
9767
|
-
return `${(0,
|
|
9767
|
+
return `${(0, import_node_crypto12.createHash)("sha256").update(`${from}\0${to}`).digest("hex").slice(0, FILE_NAME_HASH_DIGITS)}${suffix}`;
|
|
9768
9768
|
}
|
|
9769
9769
|
function readRenameJournal(fs17, file) {
|
|
9770
9770
|
const raw = fs17.readFileUtf8(file);
|
|
@@ -9835,28 +9835,28 @@ function requireNameFreeOfUnfinishedRename(fs17, directory, name, action, sameNa
|
|
|
9835
9835
|
throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
|
|
9836
9836
|
}
|
|
9837
9837
|
}
|
|
9838
|
-
var
|
|
9838
|
+
var import_node_crypto12, import_node_path27, import_zod19, RenameJournalSchema, FILE_NAME_HASH_DIGITS, JOURNAL_SUFFIX, RenameJournalUnreadableError, NameHeldByUnfinishedRenameError;
|
|
9839
9839
|
var init_identityRenameJournal = __esm({
|
|
9840
9840
|
"src/identityRenameJournal.ts"() {
|
|
9841
9841
|
"use strict";
|
|
9842
|
-
|
|
9842
|
+
import_node_crypto12 = require("node:crypto");
|
|
9843
9843
|
import_node_path27 = __toESM(require("node:path"), 1);
|
|
9844
|
-
|
|
9844
|
+
import_zod19 = require("zod");
|
|
9845
9845
|
init_cliError();
|
|
9846
|
-
RenameJournalSchema =
|
|
9847
|
-
version:
|
|
9848
|
-
from:
|
|
9849
|
-
to:
|
|
9850
|
-
startedAt:
|
|
9846
|
+
RenameJournalSchema = import_zod19.z.strictObject({
|
|
9847
|
+
version: import_zod19.z.literal(1),
|
|
9848
|
+
from: import_zod19.z.string().min(1),
|
|
9849
|
+
to: import_zod19.z.string().min(1),
|
|
9850
|
+
startedAt: import_zod19.z.iso.datetime(),
|
|
9851
9851
|
/** 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:
|
|
9852
|
+
pid: import_zod19.z.number().int().positive(),
|
|
9853
|
+
steps: import_zod19.z.array(
|
|
9854
|
+
import_zod19.z.strictObject({
|
|
9855
|
+
description: import_zod19.z.string().min(1),
|
|
9856
9856
|
/** Whether the step has been applied and marked so. */
|
|
9857
|
-
done:
|
|
9857
|
+
done: import_zod19.z.boolean(),
|
|
9858
9858
|
/** 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:
|
|
9859
|
+
started: import_zod19.z.boolean()
|
|
9860
9860
|
})
|
|
9861
9861
|
)
|
|
9862
9862
|
});
|
|
@@ -9961,13 +9961,13 @@ function requireNoInterruptedNameRename(paths, name, action, except) {
|
|
|
9961
9961
|
throw new InterruptedNameRenameError(action, describeInterruptedNameRename(paths, held));
|
|
9962
9962
|
}
|
|
9963
9963
|
}
|
|
9964
|
-
var import_node_fs7, import_node_path28,
|
|
9964
|
+
var import_node_fs7, import_node_path28, import_zod20, NameRenameRecordSchema, RECORD_SUFFIX, InterruptedNameRenameError;
|
|
9965
9965
|
var init_identityNameRenameRecord = __esm({
|
|
9966
9966
|
"src/identityNameRenameRecord.ts"() {
|
|
9967
9967
|
"use strict";
|
|
9968
9968
|
import_node_fs7 = __toESM(require("node:fs"), 1);
|
|
9969
9969
|
import_node_path28 = __toESM(require("node:path"), 1);
|
|
9970
|
-
|
|
9970
|
+
import_zod20 = require("zod");
|
|
9971
9971
|
init_cliError();
|
|
9972
9972
|
init_configProfilesStore();
|
|
9973
9973
|
init_directoryRulesStore();
|
|
@@ -9977,12 +9977,12 @@ var init_identityNameRenameRecord = __esm({
|
|
|
9977
9977
|
init_poolPick();
|
|
9978
9978
|
init_identityRecords();
|
|
9979
9979
|
init_identityRenameJournal();
|
|
9980
|
-
NameRenameRecordSchema =
|
|
9981
|
-
version:
|
|
9982
|
-
id:
|
|
9983
|
-
from:
|
|
9984
|
-
to:
|
|
9985
|
-
startedAt:
|
|
9980
|
+
NameRenameRecordSchema = import_zod20.z.strictObject({
|
|
9981
|
+
version: import_zod20.z.literal(1),
|
|
9982
|
+
id: import_zod20.z.string().min(1),
|
|
9983
|
+
from: import_zod20.z.string().min(1),
|
|
9984
|
+
to: import_zod20.z.string().min(1),
|
|
9985
|
+
startedAt: import_zod20.z.iso.datetime()
|
|
9986
9986
|
});
|
|
9987
9987
|
RECORD_SUFFIX = ".json";
|
|
9988
9988
|
InterruptedNameRenameError = class extends CliError {
|
|
@@ -9996,7 +9996,7 @@ var init_identityNameRenameRecord = __esm({
|
|
|
9996
9996
|
|
|
9997
9997
|
// src/launcher/launchRecords.ts
|
|
9998
9998
|
function recordFile(directory, pid) {
|
|
9999
|
-
return import_node_path29.default.join(directory, `${String(pid)}.${(0,
|
|
9999
|
+
return import_node_path29.default.join(directory, `${String(pid)}.${(0, import_node_crypto13.randomUUID)()}${RECORD_SUFFIX2}`);
|
|
10000
10000
|
}
|
|
10001
10001
|
function readRecord(fs17, directory, name) {
|
|
10002
10002
|
if (!name.endsWith(RECORD_SUFFIX2)) {
|
|
@@ -10037,18 +10037,18 @@ function liveLaunchesOn(fs17, directory, identity, isRunning) {
|
|
|
10037
10037
|
return record?.identity === identity && isRunning(record.pid) ? [record.pid] : [];
|
|
10038
10038
|
}).sort((left, right) => left - right);
|
|
10039
10039
|
}
|
|
10040
|
-
var import_node_path29,
|
|
10040
|
+
var import_node_path29, import_node_crypto13, import_zod21, LaunchRecordSchema, RECORD_SUFFIX2;
|
|
10041
10041
|
var init_launchRecords = __esm({
|
|
10042
10042
|
"src/launcher/launchRecords.ts"() {
|
|
10043
10043
|
"use strict";
|
|
10044
10044
|
import_node_path29 = __toESM(require("node:path"), 1);
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
LaunchRecordSchema =
|
|
10045
|
+
import_node_crypto13 = require("node:crypto");
|
|
10046
|
+
import_zod21 = require("zod");
|
|
10047
|
+
LaunchRecordSchema = import_zod21.z.strictObject({
|
|
10048
10048
|
/** 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:
|
|
10049
|
+
pid: import_zod21.z.number().int().positive(),
|
|
10050
|
+
identity: import_zod21.z.string().min(1),
|
|
10051
|
+
startedAt: import_zod21.z.iso.datetime()
|
|
10052
10052
|
});
|
|
10053
10053
|
RECORD_SUFFIX2 = ".json";
|
|
10054
10054
|
}
|
|
@@ -10519,7 +10519,7 @@ var init_package = __esm({
|
|
|
10519
10519
|
"package.json"() {
|
|
10520
10520
|
package_default = {
|
|
10521
10521
|
name: "claude-use",
|
|
10522
|
-
version: "
|
|
10522
|
+
version: "12.0.0",
|
|
10523
10523
|
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
10524
|
license: "MIT",
|
|
10525
10525
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -11130,14 +11130,14 @@ function requireProviderExists(paths, name) {
|
|
|
11130
11130
|
throw new ProviderNotFoundError(name);
|
|
11131
11131
|
}
|
|
11132
11132
|
}
|
|
11133
|
-
function
|
|
11133
|
+
function isRecord9(value) {
|
|
11134
11134
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11135
11135
|
}
|
|
11136
11136
|
function legacyProviderConversion(raw) {
|
|
11137
|
-
if (!
|
|
11137
|
+
if (!isRecord9(raw) || "credential" in raw) {
|
|
11138
11138
|
return void 0;
|
|
11139
11139
|
}
|
|
11140
|
-
const env =
|
|
11140
|
+
const env = isRecord9(raw.env) ? raw.env : void 0;
|
|
11141
11141
|
const legacyEnvKeys = env === void 0 ? [] : Object.keys(env).filter((key) => LEGACY_ENV_CREDENTIAL_KEYS.includes(key));
|
|
11142
11142
|
const fields = [...LEGACY_PROVIDER_FIELDS.filter((field) => field in raw), ...legacyEnvKeys.map((key) => `env.${key}`)];
|
|
11143
11143
|
if (fields.length === 0) {
|
|
@@ -11624,7 +11624,7 @@ function listKey(list) {
|
|
|
11624
11624
|
return `${list},appended`;
|
|
11625
11625
|
}
|
|
11626
11626
|
function digest2(value) {
|
|
11627
|
-
return (0,
|
|
11627
|
+
return (0, import_node_crypto14.createHash)("sha256").update(value).digest("hex");
|
|
11628
11628
|
}
|
|
11629
11629
|
function recordedDigests(env) {
|
|
11630
11630
|
const raw = env[INJECTED_ENV];
|
|
@@ -11704,11 +11704,11 @@ function withoutInjected(env) {
|
|
|
11704
11704
|
});
|
|
11705
11705
|
return Object.fromEntries(entries);
|
|
11706
11706
|
}
|
|
11707
|
-
var
|
|
11707
|
+
var import_node_crypto14, import_zod26, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
|
|
11708
11708
|
var init_injected = __esm({
|
|
11709
11709
|
"src/launcher/injected.ts"() {
|
|
11710
11710
|
"use strict";
|
|
11711
|
-
|
|
11711
|
+
import_node_crypto14 = require("node:crypto");
|
|
11712
11712
|
import_zod26 = require("zod");
|
|
11713
11713
|
init_headers();
|
|
11714
11714
|
INJECTED_ENV = "AGENT_SHIM_INJECTED";
|
|
@@ -12068,7 +12068,7 @@ function parseCatalogueBinding(raw) {
|
|
|
12068
12068
|
}
|
|
12069
12069
|
}
|
|
12070
12070
|
function catalogueCredentialFingerprint(cli, token, accountId) {
|
|
12071
|
-
return (0,
|
|
12071
|
+
return (0, import_node_crypto15.createHash)("sha256").update(JSON.stringify([cli, token, accountId])).digest("hex");
|
|
12072
12072
|
}
|
|
12073
12073
|
function cliCatalogueFingerprint(raw) {
|
|
12074
12074
|
if (raw === void 0) return void 0;
|
|
@@ -12093,11 +12093,11 @@ function savedCatalogueFingerprint(provider, paths, env, home, read) {
|
|
|
12093
12093
|
const codexHome = configuredHome === void 0 || configuredHome === "" ? import_node_path41.default.join(home, ".codex") : configuredHome;
|
|
12094
12094
|
return cliCatalogueFingerprint(read(import_node_path41.default.join(codexHome, "auth.json")));
|
|
12095
12095
|
}
|
|
12096
|
-
var
|
|
12096
|
+
var import_node_crypto15, import_node_path41, import_zod35, CatalogueBindingSchema;
|
|
12097
12097
|
var init_catalogueCredential = __esm({
|
|
12098
12098
|
"src/codex/catalogueCredential.ts"() {
|
|
12099
12099
|
"use strict";
|
|
12100
|
-
|
|
12100
|
+
import_node_crypto15 = require("node:crypto");
|
|
12101
12101
|
import_node_path41 = __toESM(require("node:path"), 1);
|
|
12102
12102
|
import_zod35 = require("zod");
|
|
12103
12103
|
init_siwcStore();
|
|
@@ -12818,7 +12818,7 @@ function ensureFrontDoor(params) {
|
|
|
12818
12818
|
if (supervisorPid !== void 0 && !distrusted.has(supervisorPid) && ports.isRunning(supervisorPid)) {
|
|
12819
12819
|
if (state?.port !== void 0 && state.connectPort !== void 0) {
|
|
12820
12820
|
if (supervisorPid === params.launcherPid && params.replace === void 0 && ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
12821
|
-
const token = (0,
|
|
12821
|
+
const token = (0, import_node_crypto16.randomUUID)();
|
|
12822
12822
|
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
12823
12823
|
return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
|
|
12824
12824
|
}
|
|
@@ -12839,7 +12839,7 @@ function ensureFrontDoor(params) {
|
|
|
12839
12839
|
continue;
|
|
12840
12840
|
}
|
|
12841
12841
|
if (verdict.ok) {
|
|
12842
|
-
const token = (0,
|
|
12842
|
+
const token = (0, import_node_crypto16.randomUUID)();
|
|
12843
12843
|
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
12844
12844
|
return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
|
|
12845
12845
|
}
|
|
@@ -12892,11 +12892,11 @@ function ensureFrontDoor(params) {
|
|
|
12892
12892
|
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
12893
12893
|
}
|
|
12894
12894
|
}
|
|
12895
|
-
var
|
|
12895
|
+
var import_node_crypto16, FRONTDOOR_START_TIMEOUT_MS, FRONTDOOR_LAUNCHER_POLL_MS, FRONTDOOR_PROBE_ATTEMPTS, FRONTDOOR_EXIT_GRACE_MS, FrontDoorStartError;
|
|
12896
12896
|
var init_ensure2 = __esm({
|
|
12897
12897
|
"src/frontdoor/ensure.ts"() {
|
|
12898
12898
|
"use strict";
|
|
12899
|
-
|
|
12899
|
+
import_node_crypto16 = require("node:crypto");
|
|
12900
12900
|
init_cliError();
|
|
12901
12901
|
init_state2();
|
|
12902
12902
|
init_replacement();
|
|
@@ -13565,7 +13565,7 @@ function withLauncherSettings(passthrough, settings) {
|
|
|
13565
13565
|
}
|
|
13566
13566
|
return [...kept, "--settings", settings, ...tail];
|
|
13567
13567
|
}
|
|
13568
|
-
function
|
|
13568
|
+
function isRecord17(value) {
|
|
13569
13569
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13570
13570
|
}
|
|
13571
13571
|
function mergeSettings(parts) {
|
|
@@ -13576,7 +13576,7 @@ function mergeSettings(parts) {
|
|
|
13576
13576
|
continue;
|
|
13577
13577
|
}
|
|
13578
13578
|
const parsed = JSON.parse(part);
|
|
13579
|
-
if (!
|
|
13579
|
+
if (!isRecord17(parsed)) {
|
|
13580
13580
|
throw new Error("a launch's settings part is not a JSON object");
|
|
13581
13581
|
}
|
|
13582
13582
|
for (const [key, value] of Object.entries(parsed)) {
|
|
@@ -14526,7 +14526,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
|
|
|
14526
14526
|
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
14527
|
proc.exit(1);
|
|
14528
14528
|
}
|
|
14529
|
-
const sessionId = params.supervised?.sessionId ?? (0,
|
|
14529
|
+
const sessionId = params.supervised?.sessionId ?? (0, import_node_crypto17.randomUUID)();
|
|
14530
14530
|
const resolvedModels = decided.models ?? (decided.globalModels === void 0 ? void 0 : {});
|
|
14531
14531
|
const sessionModels = (0, import_node_util2.isDeepStrictEqual)(resolvedModels, decided.globalModels) ? void 0 : resolvedModels;
|
|
14532
14532
|
const session = { sessionId, ...decided.farmIdentity === void 0 ? {} : { identity: decided.farmIdentity }, ...sessionModels === void 0 ? {} : { models: sessionModels } };
|
|
@@ -14634,11 +14634,11 @@ function runLaunchPlan(plan, spawn3) {
|
|
|
14634
14634
|
function runLauncher(params) {
|
|
14635
14635
|
params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
|
|
14636
14636
|
}
|
|
14637
|
-
var
|
|
14637
|
+
var import_node_crypto17, import_node_os8, import_node_util2, import_node_path51;
|
|
14638
14638
|
var init_launcher = __esm({
|
|
14639
14639
|
"src/launcher.ts"() {
|
|
14640
14640
|
"use strict";
|
|
14641
|
-
|
|
14641
|
+
import_node_crypto17 = require("node:crypto");
|
|
14642
14642
|
import_node_os8 = __toESM(require("node:os"), 1);
|
|
14643
14643
|
init_catalogueCredential();
|
|
14644
14644
|
import_node_util2 = require("node:util");
|
|
@@ -14770,18 +14770,18 @@ function resolveTrustBundle(params) {
|
|
|
14770
14770
|
}
|
|
14771
14771
|
const combined = `${inheritedPem.trimEnd()}
|
|
14772
14772
|
${caPem}`;
|
|
14773
|
-
const bundle = import_node_path53.default.join(bundlesDir, `${(0,
|
|
14773
|
+
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
14774
|
if (!fs17.exists(bundle)) {
|
|
14775
14775
|
fs17.mkdirp(bundlesDir);
|
|
14776
14776
|
fs17.writeFileAtomic(bundle, combined);
|
|
14777
14777
|
}
|
|
14778
14778
|
return { path: bundle };
|
|
14779
14779
|
}
|
|
14780
|
-
var
|
|
14780
|
+
var import_node_crypto18, import_node_path53, BUNDLE_NAME_HEX_DIGITS;
|
|
14781
14781
|
var init_trust = __esm({
|
|
14782
14782
|
"src/frontdoor/trust.ts"() {
|
|
14783
14783
|
"use strict";
|
|
14784
|
-
|
|
14784
|
+
import_node_crypto18 = require("node:crypto");
|
|
14785
14785
|
import_node_path53 = __toESM(require("node:path"), 1);
|
|
14786
14786
|
BUNDLE_NAME_HEX_DIGITS = 16;
|
|
14787
14787
|
}
|
|
@@ -14941,7 +14941,7 @@ function buildFarmRuntime(paths, cwd, run = realRunPort) {
|
|
|
14941
14941
|
...cliOverride === void 0 ? {} : { cliOverride }
|
|
14942
14942
|
}).input,
|
|
14943
14943
|
now: () => Date.now(),
|
|
14944
|
-
uniqueSuffix: `${String(process.pid)}.${(0,
|
|
14944
|
+
uniqueSuffix: `${String(process.pid)}.${(0, import_node_crypto19.randomUUID)()}`,
|
|
14945
14945
|
// 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
14946
|
lock: { pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync }
|
|
14947
14947
|
},
|
|
@@ -15029,13 +15029,13 @@ function resolveClaudeLaunch(options, run = realRunPort) {
|
|
|
15029
15029
|
};
|
|
15030
15030
|
return { resolution: resolveLaunch(realPrepareLaunchParams(paths, { proc, log, spawnDaemon, run, farm: buildFarmRuntime(paths, options.cwd, run) })), warnings };
|
|
15031
15031
|
}
|
|
15032
|
-
var import_node_os10, import_node_path54,
|
|
15032
|
+
var import_node_os10, import_node_path54, import_node_crypto19, LaunchRefusedError;
|
|
15033
15033
|
var init_launchWiring = __esm({
|
|
15034
15034
|
"src/launchWiring.ts"() {
|
|
15035
15035
|
"use strict";
|
|
15036
15036
|
import_node_os10 = __toESM(require("node:os"), 1);
|
|
15037
15037
|
import_node_path54 = __toESM(require("node:path"), 1);
|
|
15038
|
-
|
|
15038
|
+
import_node_crypto19 = require("node:crypto");
|
|
15039
15039
|
init_cliError();
|
|
15040
15040
|
init_claudeShim();
|
|
15041
15041
|
init_classify();
|
|
@@ -15553,7 +15553,6 @@ __export(index_exports, {
|
|
|
15553
15553
|
RC_GOAL_CONDITION_MAX_CHARS: () => RC_GOAL_CONDITION_MAX_CHARS,
|
|
15554
15554
|
RC_IDLE_EXPIRY_MS: () => RC_IDLE_EXPIRY_MS,
|
|
15555
15555
|
RC_ORPC_PATH_PREFIX: () => RC_ORPC_PATH_PREFIX,
|
|
15556
|
-
RC_PENDING_DEADLINE_MS: () => RC_PENDING_DEADLINE_MS,
|
|
15557
15556
|
RC_PENDING_RETIRE_REASONS: () => RC_PENDING_RETIRE_REASONS,
|
|
15558
15557
|
RC_PERMISSION_MODES: () => RC_PERMISSION_MODES,
|
|
15559
15558
|
RC_READ_FILE_ENCODINGS: () => RC_READ_FILE_ENCODINGS,
|
|
@@ -15864,6 +15863,9 @@ var HTTP_STATUS = {
|
|
|
15864
15863
|
// src/frontdoor/connectEffects.ts
|
|
15865
15864
|
init_connect();
|
|
15866
15865
|
|
|
15866
|
+
// src/frontdoor/rcSessions.ts
|
|
15867
|
+
var import_node_crypto6 = require("node:crypto");
|
|
15868
|
+
|
|
15867
15869
|
// src/agents/liveTasks.ts
|
|
15868
15870
|
var import_zod9 = require("zod");
|
|
15869
15871
|
|
|
@@ -16122,6 +16124,125 @@ function mergeLiveTasks(tree, live) {
|
|
|
16122
16124
|
return { ...tree, agents, remoteSessions, liveOnly };
|
|
16123
16125
|
}
|
|
16124
16126
|
|
|
16127
|
+
// src/frontdoor/rcQuestions.ts
|
|
16128
|
+
var RC_QUESTION_TOOL_NAME = "AskUserQuestion";
|
|
16129
|
+
var RC_QUESTIONS_MAX = 16;
|
|
16130
|
+
var RC_QUESTION_OPTIONS_MAX = 16;
|
|
16131
|
+
var RC_QUESTION_FIELD_MAX_CHARS = 1024;
|
|
16132
|
+
var MULTI_SELECT_SEPARATOR = ", ";
|
|
16133
|
+
function isRecord4(value) {
|
|
16134
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16135
|
+
}
|
|
16136
|
+
function fits(value) {
|
|
16137
|
+
return value === void 0 || value.length <= RC_QUESTION_FIELD_MAX_CHARS;
|
|
16138
|
+
}
|
|
16139
|
+
function optionOf(value) {
|
|
16140
|
+
if (!isRecord4(value) || typeof value.label !== "string" || value.label === "") {
|
|
16141
|
+
return "an option names no label";
|
|
16142
|
+
}
|
|
16143
|
+
const description = typeof value.description === "string" && value.description !== "" ? value.description : void 0;
|
|
16144
|
+
if (!fits(value.label) || !fits(description)) {
|
|
16145
|
+
return `an option is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
16146
|
+
}
|
|
16147
|
+
return description === void 0 ? { label: value.label } : { label: value.label, description };
|
|
16148
|
+
}
|
|
16149
|
+
function questionOf(value) {
|
|
16150
|
+
if (!isRecord4(value) || typeof value.question !== "string" || value.question === "" || !Array.isArray(value.options) || value.options.length === 0) {
|
|
16151
|
+
return "a question has no text or no options";
|
|
16152
|
+
}
|
|
16153
|
+
if (value.options.length > RC_QUESTION_OPTIONS_MAX) {
|
|
16154
|
+
return `a question has more than ${String(RC_QUESTION_OPTIONS_MAX)} options`;
|
|
16155
|
+
}
|
|
16156
|
+
const options = [];
|
|
16157
|
+
for (const candidate of value.options) {
|
|
16158
|
+
const option = optionOf(candidate);
|
|
16159
|
+
if (typeof option === "string") {
|
|
16160
|
+
return option;
|
|
16161
|
+
}
|
|
16162
|
+
if (options.some((existing) => existing.label === option.label)) {
|
|
16163
|
+
return `a question lists the option ${JSON.stringify(option.label)} twice`;
|
|
16164
|
+
}
|
|
16165
|
+
options.push(option);
|
|
16166
|
+
}
|
|
16167
|
+
const header = typeof value.header === "string" && value.header !== "" ? value.header : void 0;
|
|
16168
|
+
if (!fits(value.question) || !fits(header)) {
|
|
16169
|
+
return `a question is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
16170
|
+
}
|
|
16171
|
+
return { question: value.question, ...header === void 0 ? {} : { header }, multiSelect: value.multiSelect === true, options };
|
|
16172
|
+
}
|
|
16173
|
+
function rcQuestionsOfToolRequest(toolName, input) {
|
|
16174
|
+
if (toolName !== RC_QUESTION_TOOL_NAME) {
|
|
16175
|
+
return void 0;
|
|
16176
|
+
}
|
|
16177
|
+
if (!isRecord4(input) || !Array.isArray(input.questions) || input.questions.length === 0) {
|
|
16178
|
+
return { unanswerable: "the request names no questions" };
|
|
16179
|
+
}
|
|
16180
|
+
if (input.questions.length > RC_QUESTIONS_MAX) {
|
|
16181
|
+
return { unanswerable: `the request asks more than ${String(RC_QUESTIONS_MAX)} questions` };
|
|
16182
|
+
}
|
|
16183
|
+
const questions = [];
|
|
16184
|
+
for (const candidate of input.questions) {
|
|
16185
|
+
const question = questionOf(candidate);
|
|
16186
|
+
if (typeof question === "string") {
|
|
16187
|
+
return { unanswerable: question };
|
|
16188
|
+
}
|
|
16189
|
+
if (questions.some((existing) => existing.question === question.question)) {
|
|
16190
|
+
return { unanswerable: `the request asks ${JSON.stringify(question.question)} twice` };
|
|
16191
|
+
}
|
|
16192
|
+
questions.push(question);
|
|
16193
|
+
}
|
|
16194
|
+
return { questions };
|
|
16195
|
+
}
|
|
16196
|
+
function resolveSelection(question, questionNumber, selection) {
|
|
16197
|
+
if (typeof selection === "number") {
|
|
16198
|
+
const option = Number.isInteger(selection) ? question.options[selection - 1] : void 0;
|
|
16199
|
+
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 };
|
|
16200
|
+
}
|
|
16201
|
+
if (typeof selection === "object") {
|
|
16202
|
+
const text = selection.text.trim();
|
|
16203
|
+
return text === "" ? { error: `question ${String(questionNumber)}'s free-text answer is empty` } : { text };
|
|
16204
|
+
}
|
|
16205
|
+
const exact = question.options.find((option) => option.label === selection);
|
|
16206
|
+
if (exact !== void 0) {
|
|
16207
|
+
return { text: exact.label };
|
|
16208
|
+
}
|
|
16209
|
+
const folded = question.options.filter((option) => option.label.toLowerCase() === selection.toLowerCase());
|
|
16210
|
+
const [only] = folded;
|
|
16211
|
+
if (only !== void 0 && folded.length === 1) {
|
|
16212
|
+
return { text: only.label };
|
|
16213
|
+
}
|
|
16214
|
+
return { error: `question ${String(questionNumber)} has no option labelled ${JSON.stringify(selection)}: its options are ${question.options.map((option) => JSON.stringify(option.label)).join(", ")}` };
|
|
16215
|
+
}
|
|
16216
|
+
function resolveRcQuestionAnswers(questions, choices) {
|
|
16217
|
+
if (choices.length !== questions.length) {
|
|
16218
|
+
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)}` };
|
|
16219
|
+
}
|
|
16220
|
+
const answers = {};
|
|
16221
|
+
for (const [index, question] of questions.entries()) {
|
|
16222
|
+
const questionNumber = index + 1;
|
|
16223
|
+
const selections = choices[index] ?? [];
|
|
16224
|
+
if (selections.length === 0) {
|
|
16225
|
+
return { error: `question ${String(questionNumber)} has no selection` };
|
|
16226
|
+
}
|
|
16227
|
+
if (!question.multiSelect && selections.length > 1) {
|
|
16228
|
+
return { error: `question ${String(questionNumber)} takes one option, but ${String(selections.length)} were chosen` };
|
|
16229
|
+
}
|
|
16230
|
+
const texts = [];
|
|
16231
|
+
for (const selection of selections) {
|
|
16232
|
+
const resolved = resolveSelection(question, questionNumber, selection);
|
|
16233
|
+
if ("error" in resolved) {
|
|
16234
|
+
return resolved;
|
|
16235
|
+
}
|
|
16236
|
+
if (texts.includes(resolved.text)) {
|
|
16237
|
+
return { error: `question ${String(questionNumber)} chose ${JSON.stringify(resolved.text)} twice` };
|
|
16238
|
+
}
|
|
16239
|
+
texts.push(resolved.text);
|
|
16240
|
+
}
|
|
16241
|
+
answers[question.question] = texts.join(MULTI_SELECT_SEPARATOR);
|
|
16242
|
+
}
|
|
16243
|
+
return { answers };
|
|
16244
|
+
}
|
|
16245
|
+
|
|
16125
16246
|
// src/frontdoor/rcSessions.ts
|
|
16126
16247
|
var RC_SESSIONS_PATH_PREFIX = "/v1/code/sessions";
|
|
16127
16248
|
function pathnameOf(url) {
|
|
@@ -16136,7 +16257,12 @@ var RC_IDLE_EXPIRY_MS = 45e3;
|
|
|
16136
16257
|
var RC_CREATE_RESPONSE_CAP_BYTES = 8192;
|
|
16137
16258
|
var CONFLICT_REASON_HEADER = "x-ccr-conflict-reason";
|
|
16138
16259
|
var RC_STREAM_WORKER_SOURCE = "worker";
|
|
16139
|
-
var
|
|
16260
|
+
var HIGH_SURROGATE_FIRST = 55296;
|
|
16261
|
+
var HIGH_SURROGATE_LAST = 56319;
|
|
16262
|
+
var RC_WORKER_IDLE = "idle";
|
|
16263
|
+
var RC_PENDING_PER_SESSION_MAX = 64;
|
|
16264
|
+
var RC_REQUEST_ID_MAX_CHARS = 128;
|
|
16265
|
+
var RC_RETIRED_TOMBSTONES_MAX = 2 * RC_PENDING_PER_SESSION_MAX;
|
|
16140
16266
|
var RC_REQUEST_PARSE_CAP_BYTES = 262144;
|
|
16141
16267
|
var RC_PENDING_SUMMARY_EXCERPT_CHARS = 300;
|
|
16142
16268
|
var SUCCESS_STATUS_MAX_EXCLUSIVE = 300;
|
|
@@ -16169,7 +16295,7 @@ function sessionCreateId(body) {
|
|
|
16169
16295
|
const id = session.id;
|
|
16170
16296
|
return typeof id === "string" && id.startsWith(RC_SESSION_ID_PREFIX) ? id : void 0;
|
|
16171
16297
|
}
|
|
16172
|
-
function
|
|
16298
|
+
function isRecord5(value) {
|
|
16173
16299
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16174
16300
|
}
|
|
16175
16301
|
function parseJsonObject(body) {
|
|
@@ -16179,7 +16305,7 @@ function parseJsonObject(body) {
|
|
|
16179
16305
|
} catch {
|
|
16180
16306
|
return void 0;
|
|
16181
16307
|
}
|
|
16182
|
-
return
|
|
16308
|
+
return isRecord5(parsed) ? parsed : void 0;
|
|
16183
16309
|
}
|
|
16184
16310
|
function nonEmptyString(record, field) {
|
|
16185
16311
|
const value = record === void 0 ? void 0 : record[field];
|
|
@@ -16189,8 +16315,16 @@ function finiteNumber(record, field) {
|
|
|
16189
16315
|
const value = record === void 0 ? void 0 : record[field];
|
|
16190
16316
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
16191
16317
|
}
|
|
16192
|
-
function
|
|
16193
|
-
|
|
16318
|
+
function rcExcerpt(text) {
|
|
16319
|
+
if (text.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS) {
|
|
16320
|
+
return text;
|
|
16321
|
+
}
|
|
16322
|
+
const cut = text.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS);
|
|
16323
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
16324
|
+
return `${isHighSurrogate(last) ? cut.slice(0, -1) : cut}...`;
|
|
16325
|
+
}
|
|
16326
|
+
function isHighSurrogate(unit) {
|
|
16327
|
+
return unit >= HIGH_SURROGATE_FIRST && unit <= HIGH_SURROGATE_LAST;
|
|
16194
16328
|
}
|
|
16195
16329
|
function payloadEventsOf(body) {
|
|
16196
16330
|
const parsed = parseJsonObject(body);
|
|
@@ -16200,11 +16334,11 @@ function payloadEventsOf(body) {
|
|
|
16200
16334
|
}
|
|
16201
16335
|
const payloads = [];
|
|
16202
16336
|
for (const event of events) {
|
|
16203
|
-
if (!
|
|
16337
|
+
if (!isRecord5(event)) {
|
|
16204
16338
|
continue;
|
|
16205
16339
|
}
|
|
16206
16340
|
const payload = event.payload;
|
|
16207
|
-
if (!
|
|
16341
|
+
if (!isRecord5(payload)) {
|
|
16208
16342
|
continue;
|
|
16209
16343
|
}
|
|
16210
16344
|
payloads.push(payload);
|
|
@@ -16212,6 +16346,14 @@ function payloadEventsOf(body) {
|
|
|
16212
16346
|
return payloads;
|
|
16213
16347
|
}
|
|
16214
16348
|
function pendingOfControlRequestPayload(payload) {
|
|
16349
|
+
const parsed = fullPendingOfControlRequestPayload(payload);
|
|
16350
|
+
const isQuestion = parsed !== void 0 && (parsed.questions !== void 0 || parsed.unanswerable !== void 0);
|
|
16351
|
+
if (parsed === void 0 || !isQuestion || Buffer.byteLength(JSON.stringify(payload), "utf8") <= RC_REQUEST_PARSE_CAP_BYTES) {
|
|
16352
|
+
return parsed;
|
|
16353
|
+
}
|
|
16354
|
+
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` };
|
|
16355
|
+
}
|
|
16356
|
+
function fullPendingOfControlRequestPayload(payload) {
|
|
16215
16357
|
if (payload.type !== "control_request") {
|
|
16216
16358
|
return void 0;
|
|
16217
16359
|
}
|
|
@@ -16219,24 +16361,41 @@ function pendingOfControlRequestPayload(payload) {
|
|
|
16219
16361
|
if (requestId === void 0) {
|
|
16220
16362
|
return void 0;
|
|
16221
16363
|
}
|
|
16222
|
-
const request4 =
|
|
16364
|
+
const request4 = isRecord5(payload.request) ? payload.request : void 0;
|
|
16223
16365
|
const subtype = nonEmptyString(request4, "subtype");
|
|
16224
16366
|
const type = subtype ?? "control_request";
|
|
16225
16367
|
let summary = "";
|
|
16368
|
+
let questions;
|
|
16369
|
+
let unanswerable;
|
|
16370
|
+
let toolInput;
|
|
16226
16371
|
if (subtype === "can_use_tool") {
|
|
16227
|
-
const toolName = nonEmptyString(request4, "tool_name")
|
|
16372
|
+
const toolName = nonEmptyString(request4, "tool_name");
|
|
16228
16373
|
const input = request4 === void 0 ? void 0 : request4.input;
|
|
16229
|
-
summary = input === void 0 ? toolName : `${toolName} ${
|
|
16374
|
+
summary = input === void 0 ? toolName ?? "unknown tool" : `${toolName ?? "unknown tool"} ${rcExcerpt(JSON.stringify(input))}`;
|
|
16375
|
+
const parsedQuestions = rcQuestionsOfToolRequest(toolName, input);
|
|
16376
|
+
if (parsedQuestions !== void 0 && "questions" in parsedQuestions) {
|
|
16377
|
+
questions = parsedQuestions.questions;
|
|
16378
|
+
toolInput = isRecord5(input) ? input : void 0;
|
|
16379
|
+
} else if (parsedQuestions !== void 0) {
|
|
16380
|
+
unanswerable = parsedQuestions.unanswerable;
|
|
16381
|
+
}
|
|
16230
16382
|
} else if (request4 !== void 0) {
|
|
16231
|
-
summary =
|
|
16383
|
+
summary = rcExcerpt(JSON.stringify(request4));
|
|
16232
16384
|
}
|
|
16233
|
-
return { requestId, type, summary };
|
|
16385
|
+
return { requestId, type, summary, questions, unanswerable, toolInput, oversized: false };
|
|
16386
|
+
}
|
|
16387
|
+
function withdrawnRequestIdsOfControlCancelPayload(payload) {
|
|
16388
|
+
if (payload.type !== "control_cancel_request") {
|
|
16389
|
+
return [];
|
|
16390
|
+
}
|
|
16391
|
+
const id = nonEmptyString(payload, "request_id");
|
|
16392
|
+
return id === void 0 ? [] : [id];
|
|
16234
16393
|
}
|
|
16235
16394
|
function answeredRequestIdsOfControlResponsePayload(payload) {
|
|
16236
16395
|
if (payload.type !== "control_response") {
|
|
16237
16396
|
return [];
|
|
16238
16397
|
}
|
|
16239
|
-
const response =
|
|
16398
|
+
const response = isRecord5(payload.response) ? payload.response : void 0;
|
|
16240
16399
|
const id = nonEmptyString(response, "request_id") ?? nonEmptyString(payload, "request_id") ?? nonEmptyString(payload, "uuid");
|
|
16241
16400
|
return id === void 0 ? [] : [id];
|
|
16242
16401
|
}
|
|
@@ -16248,44 +16407,74 @@ function initFactsOfPayload(payload) {
|
|
|
16248
16407
|
}
|
|
16249
16408
|
function parseRcRequestBody(kind, body) {
|
|
16250
16409
|
if (kind === "heartbeat") {
|
|
16251
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, payloads: [] };
|
|
16410
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, workerEpoch: void 0, payloads: [] };
|
|
16252
16411
|
}
|
|
16253
16412
|
if (kind === "worker-registration") {
|
|
16254
16413
|
const registration = parseJsonObject(body);
|
|
16255
|
-
const metadata = registration === void 0 || !
|
|
16414
|
+
const metadata = registration === void 0 || !isRecord5(registration.external_metadata) ? void 0 : registration.external_metadata;
|
|
16256
16415
|
const model = nonEmptyString(metadata, "model");
|
|
16257
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
16416
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), workerEpoch: finiteNumber(registration, "worker_epoch"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
16258
16417
|
}
|
|
16259
16418
|
const controlRequests = [];
|
|
16260
16419
|
const answeredRequestIds = [];
|
|
16420
|
+
const withdrawnRequestIds = [];
|
|
16261
16421
|
const payloads = payloadEventsOf(body);
|
|
16262
16422
|
for (const payload of payloads) {
|
|
16263
16423
|
const pending = pendingOfControlRequestPayload(payload);
|
|
16264
16424
|
if (pending !== void 0) {
|
|
16265
|
-
controlRequests.push(
|
|
16425
|
+
controlRequests.push(pending);
|
|
16266
16426
|
continue;
|
|
16267
16427
|
}
|
|
16268
16428
|
answeredRequestIds.push(...answeredRequestIdsOfControlResponsePayload(payload));
|
|
16429
|
+
if (kind === "worker-events") {
|
|
16430
|
+
withdrawnRequestIds.push(...withdrawnRequestIdsOfControlCancelPayload(payload));
|
|
16431
|
+
}
|
|
16269
16432
|
}
|
|
16270
|
-
return { controlRequests, answeredRequestIds, idleSeconds: void 0, workerStatus: void 0, payloads };
|
|
16433
|
+
return { controlRequests, answeredRequestIds, withdrawnRequestIds, idleSeconds: void 0, workerStatus: void 0, workerEpoch: void 0, payloads };
|
|
16434
|
+
}
|
|
16435
|
+
function rememberBounded(record, key) {
|
|
16436
|
+
record.delete(key);
|
|
16437
|
+
record.add(key);
|
|
16438
|
+
if (record.size > RC_RETIRED_TOMBSTONES_MAX) {
|
|
16439
|
+
const [oldest] = record;
|
|
16440
|
+
if (oldest !== void 0) {
|
|
16441
|
+
record.delete(oldest);
|
|
16442
|
+
}
|
|
16443
|
+
}
|
|
16444
|
+
}
|
|
16445
|
+
function droppedKeyOf(requestId) {
|
|
16446
|
+
return requestId.length <= RC_REQUEST_ID_MAX_CHARS ? requestId : (0, import_node_crypto6.createHash)("sha256").update(requestId).digest("hex");
|
|
16271
16447
|
}
|
|
16272
16448
|
function createRcSessionTracker(deps) {
|
|
16273
16449
|
const entries = /* @__PURE__ */ new Map();
|
|
16450
|
+
let observationSequence = 0;
|
|
16451
|
+
const rememberRetired = (entry, requestId) => {
|
|
16452
|
+
rememberBounded(entry.retired, requestId);
|
|
16453
|
+
};
|
|
16274
16454
|
const retirePending = (entry, requestId, reason) => {
|
|
16275
16455
|
if (entry.pending.delete(requestId)) {
|
|
16276
|
-
entry
|
|
16456
|
+
rememberRetired(entry, requestId);
|
|
16277
16457
|
deps.onTransition?.({ kind: "pending-retired", session: entry.id, requestId, reason, at: deps.now() });
|
|
16278
16458
|
}
|
|
16279
16459
|
};
|
|
16280
|
-
const addPending = (entry,
|
|
16281
|
-
|
|
16460
|
+
const addPending = (entry, request4, now) => {
|
|
16461
|
+
const droppedKey = droppedKeyOf(request4.requestId);
|
|
16462
|
+
if (entry.retired.has(request4.requestId) || entry.dropped.has(droppedKey)) {
|
|
16282
16463
|
return;
|
|
16283
16464
|
}
|
|
16284
|
-
const
|
|
16285
|
-
|
|
16286
|
-
|
|
16287
|
-
|
|
16465
|
+
const already = entry.pending.get(request4.requestId);
|
|
16466
|
+
if (already !== void 0) {
|
|
16467
|
+
entry.pending.set(request4.requestId, { ...already, ...request4, observedAt: already.observedAt });
|
|
16468
|
+
return;
|
|
16288
16469
|
}
|
|
16470
|
+
if (request4.requestId.length > RC_REQUEST_ID_MAX_CHARS || entry.pending.size >= RC_PENDING_PER_SESSION_MAX) {
|
|
16471
|
+
entry.droppedPending += 1;
|
|
16472
|
+
rememberBounded(entry.dropped, droppedKey);
|
|
16473
|
+
return;
|
|
16474
|
+
}
|
|
16475
|
+
observationSequence += 1;
|
|
16476
|
+
entry.pending.set(request4.requestId, { sessionId: entry.id, ...request4, observedAt: now, observedSequence: observationSequence });
|
|
16477
|
+
deps.onTransition?.({ kind: "pending-born", session: entry.id, requestId: request4.requestId, type: request4.type, summary: request4.summary, at: now });
|
|
16289
16478
|
};
|
|
16290
16479
|
const expire = (id, reason) => {
|
|
16291
16480
|
const entry = entries.get(id);
|
|
@@ -16298,31 +16487,17 @@ function createRcSessionTracker(deps) {
|
|
|
16298
16487
|
entries.delete(id);
|
|
16299
16488
|
deps.onTransition?.({ kind: "session-ended", session: id, reason, at: deps.now() });
|
|
16300
16489
|
};
|
|
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
16490
|
const sweep = () => {
|
|
16314
16491
|
for (const [id, entry] of entries) {
|
|
16315
16492
|
if (deps.now() - entry.lastSeenAt >= deps.idleMs) {
|
|
16316
16493
|
expire(id, "expired");
|
|
16317
|
-
continue;
|
|
16318
16494
|
}
|
|
16319
|
-
expirePendings(entry, deps.now());
|
|
16320
16495
|
}
|
|
16321
16496
|
};
|
|
16322
|
-
const timer = setInterval(sweep,
|
|
16497
|
+
const timer = setInterval(sweep, deps.idleMs);
|
|
16323
16498
|
timer.unref();
|
|
16324
16499
|
const birth = (id, facts) => {
|
|
16325
|
-
const record = { id, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new
|
|
16500
|
+
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
16501
|
entries.set(id, record);
|
|
16327
16502
|
deps.onTransition?.({ kind: "session-appeared", session: id, at: record.createdAt });
|
|
16328
16503
|
return record;
|
|
@@ -16353,6 +16528,7 @@ function createRcSessionTracker(deps) {
|
|
|
16353
16528
|
return void 0;
|
|
16354
16529
|
}
|
|
16355
16530
|
const tail = pathnameOf(request4.url).slice(RC_SESSIONS_PATH_PREFIX.length);
|
|
16531
|
+
const startedAtSequence = observationSequence;
|
|
16356
16532
|
const facts = {
|
|
16357
16533
|
oauthAuthorization: oauthAuthorizationOf(request4.headers),
|
|
16358
16534
|
anthropicVersion: singleHeader(request4.headers, "anthropic-version"),
|
|
@@ -16426,11 +16602,14 @@ function createRcSessionTracker(deps) {
|
|
|
16426
16602
|
}
|
|
16427
16603
|
const now = deps.now();
|
|
16428
16604
|
for (const controlRequest of factsOfBody.controlRequests) {
|
|
16429
|
-
addPending(entryNow,
|
|
16605
|
+
addPending(entryNow, controlRequest, now);
|
|
16430
16606
|
}
|
|
16431
16607
|
for (const requestId of factsOfBody.answeredRequestIds) {
|
|
16432
16608
|
retirePending(entryNow, requestId, "answered");
|
|
16433
16609
|
}
|
|
16610
|
+
for (const requestId of factsOfBody.withdrawnRequestIds) {
|
|
16611
|
+
retirePending(entryNow, requestId, "withdrawn");
|
|
16612
|
+
}
|
|
16434
16613
|
for (const payload of factsOfBody.payloads) {
|
|
16435
16614
|
entryNow.liveTasks = applyAgentTaskEvent(entryNow.liveTasks, id, payload, now);
|
|
16436
16615
|
noteInit(entryNow, payload);
|
|
@@ -16446,6 +16625,17 @@ function createRcSessionTracker(deps) {
|
|
|
16446
16625
|
deps.onTransition?.({ kind: "worker-state", session: id, state: factsOfBody.workerStatus, ...previous === void 0 ? {} : { previous }, at: now });
|
|
16447
16626
|
}
|
|
16448
16627
|
}
|
|
16628
|
+
const epochChanged = factsOfBody.workerEpoch !== void 0 && entryNow.workerEpoch !== void 0 && factsOfBody.workerEpoch !== entryNow.workerEpoch;
|
|
16629
|
+
if (factsOfBody.workerEpoch !== void 0) {
|
|
16630
|
+
entryNow.workerEpoch = factsOfBody.workerEpoch;
|
|
16631
|
+
}
|
|
16632
|
+
if (epochChanged || factsOfBody.workerStatus === RC_WORKER_IDLE) {
|
|
16633
|
+
for (const [requestId, pending] of entryNow.pending) {
|
|
16634
|
+
if (pending.observedSequence <= startedAtSequence) {
|
|
16635
|
+
retirePending(entryNow, requestId, "worker-stopped");
|
|
16636
|
+
}
|
|
16637
|
+
}
|
|
16638
|
+
}
|
|
16449
16639
|
};
|
|
16450
16640
|
const archiving = method === "POST" && rest === `${id}/archive`;
|
|
16451
16641
|
return {
|
|
@@ -16485,7 +16675,7 @@ function createRcSessionTracker(deps) {
|
|
|
16485
16675
|
};
|
|
16486
16676
|
};
|
|
16487
16677
|
const summaryOf2 = ({ id, createdAt, lastSeenAt }) => ({ id, createdAt, lastSeenAt });
|
|
16488
|
-
const pendingSummaryOf = ({ sessionId, requestId, type, summary, observedAt: observedAt2 }) => ({ sessionId, requestId, type, summary, observedAt: observedAt2 });
|
|
16678
|
+
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
16679
|
const sortedEntries = () => [...entries.values()].sort((left, right) => left.createdAt - right.createdAt || (left.id < right.id ? -1 : 1));
|
|
16490
16680
|
const pendingSorted = (entry) => [...entry.pending.values()].sort((left, right) => left.observedAt - right.observedAt || (left.requestId < right.requestId ? -1 : 1)).map(pendingSummaryOf);
|
|
16491
16681
|
return {
|
|
@@ -16503,7 +16693,8 @@ function createRcSessionTracker(deps) {
|
|
|
16503
16693
|
pending: pendingSorted(entry),
|
|
16504
16694
|
...entry.identity === void 0 ? {} : { identity: entry.identity },
|
|
16505
16695
|
...entry.model === void 0 ? {} : { model: entry.model },
|
|
16506
|
-
...entry.cwd === void 0 ? {} : { cwd: entry.cwd }
|
|
16696
|
+
...entry.cwd === void 0 ? {} : { cwd: entry.cwd },
|
|
16697
|
+
...entry.droppedPending === 0 ? {} : { pendingDropped: entry.droppedPending }
|
|
16507
16698
|
}));
|
|
16508
16699
|
},
|
|
16509
16700
|
pendingOf: (sessionId) => {
|
|
@@ -16541,7 +16732,7 @@ function createRcSessionTracker(deps) {
|
|
|
16541
16732
|
return;
|
|
16542
16733
|
}
|
|
16543
16734
|
entry.sequenceNum = entry.sequenceNum === void 0 || event.sequence_num > entry.sequenceNum ? event.sequence_num : entry.sequenceNum;
|
|
16544
|
-
if (!
|
|
16735
|
+
if (!isRecord5(event.payload)) {
|
|
16545
16736
|
return;
|
|
16546
16737
|
}
|
|
16547
16738
|
entry.liveTasks = applyAgentTaskEvent(entry.liveTasks, sessionId, event.payload, deps.now());
|
|
@@ -16549,13 +16740,18 @@ function createRcSessionTracker(deps) {
|
|
|
16549
16740
|
const pending = pendingOfControlRequestPayload(event.payload);
|
|
16550
16741
|
if (pending !== void 0) {
|
|
16551
16742
|
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
16552
|
-
addPending(entry,
|
|
16743
|
+
addPending(entry, pending, deps.now());
|
|
16553
16744
|
}
|
|
16554
16745
|
return;
|
|
16555
16746
|
}
|
|
16556
16747
|
for (const requestId of answeredRequestIdsOfControlResponsePayload(event.payload)) {
|
|
16557
16748
|
retirePending(entry, requestId, "answered");
|
|
16558
16749
|
}
|
|
16750
|
+
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
16751
|
+
for (const requestId of withdrawnRequestIdsOfControlCancelPayload(event.payload)) {
|
|
16752
|
+
retirePending(entry, requestId, "withdrawn");
|
|
16753
|
+
}
|
|
16754
|
+
}
|
|
16559
16755
|
},
|
|
16560
16756
|
liveTasksOf: (sessionId) => {
|
|
16561
16757
|
sweep();
|
|
@@ -16567,6 +16763,17 @@ function createRcSessionTracker(deps) {
|
|
|
16567
16763
|
retirePending(entry, requestId, "answered");
|
|
16568
16764
|
}
|
|
16569
16765
|
},
|
|
16766
|
+
claimPending: (sessionId, requestId) => {
|
|
16767
|
+
const entry = entries.get(sessionId);
|
|
16768
|
+
if (entry === void 0 || !entry.pending.has(requestId) || entry.answering.has(requestId)) {
|
|
16769
|
+
return void 0;
|
|
16770
|
+
}
|
|
16771
|
+
entry.answering.add(requestId);
|
|
16772
|
+
return () => {
|
|
16773
|
+
entry.answering.delete(requestId);
|
|
16774
|
+
};
|
|
16775
|
+
},
|
|
16776
|
+
pendingToolInputOf: (sessionId, requestId) => entries.get(sessionId)?.pending.get(requestId)?.toolInput,
|
|
16570
16777
|
close: () => {
|
|
16571
16778
|
clearInterval(timer);
|
|
16572
16779
|
deps.onClose?.();
|
|
@@ -16733,8 +16940,8 @@ async function injectRcUserMessage(deps, sessionId, text) {
|
|
|
16733
16940
|
}
|
|
16734
16941
|
return result;
|
|
16735
16942
|
}
|
|
16736
|
-
function buildRcControlResponsePayload(requestId, decision) {
|
|
16737
|
-
const result = decision.approve ? { behavior: "allow" } : { behavior: "deny", message: decision.message ?? "" };
|
|
16943
|
+
function buildRcControlResponsePayload(requestId, decision, updatedInput) {
|
|
16944
|
+
const result = decision.approve ? { behavior: "allow", ...updatedInput === void 0 ? {} : { updatedInput } } : { behavior: "deny", message: decision.message ?? "" };
|
|
16738
16945
|
return { type: "control_response", response: { subtype: "success", request_id: requestId, response: result } };
|
|
16739
16946
|
}
|
|
16740
16947
|
var RC_PERMISSION_MODES = ["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk", "auto"];
|
|
@@ -16791,6 +16998,27 @@ function buildRcMcpOAuthCallbackUrlPayload(requestId, serverName, callbackUrl) {
|
|
|
16791
16998
|
function buildRcKeepAlivePayload() {
|
|
16792
16999
|
return { type: "keep_alive" };
|
|
16793
17000
|
}
|
|
17001
|
+
function questionAnswerInput(deps, sessionId, pending, decision) {
|
|
17002
|
+
const { questions, unanswerable } = pending;
|
|
17003
|
+
if (questions === void 0 && unanswerable === void 0) {
|
|
17004
|
+
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` };
|
|
17005
|
+
}
|
|
17006
|
+
if (!decision.approve) {
|
|
17007
|
+
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" };
|
|
17008
|
+
}
|
|
17009
|
+
if (questions === void 0) {
|
|
17010
|
+
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` };
|
|
17011
|
+
}
|
|
17012
|
+
if (decision.choices === void 0) {
|
|
17013
|
+
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` };
|
|
17014
|
+
}
|
|
17015
|
+
const input = deps.pendingToolInputOf(sessionId, pending.requestId);
|
|
17016
|
+
if (input === void 0) {
|
|
17017
|
+
return { error: `the front door holds no input for question ${pending.requestId} on session ${sessionId}, so it cannot write the answer the worker expects` };
|
|
17018
|
+
}
|
|
17019
|
+
const resolved = resolveRcQuestionAnswers(questions, decision.choices);
|
|
17020
|
+
return "error" in resolved ? resolved : { input: { ...input, answers: resolved.answers } };
|
|
17021
|
+
}
|
|
16794
17022
|
async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
16795
17023
|
const credential = deps.credentialOf(sessionId);
|
|
16796
17024
|
if (credential === void 0) {
|
|
@@ -16799,15 +17027,26 @@ async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
|
16799
17027
|
if (credential.authorization === void 0) {
|
|
16800
17028
|
return noOAuthCredentialResult(sessionId);
|
|
16801
17029
|
}
|
|
16802
|
-
|
|
16803
|
-
|
|
17030
|
+
const pending = deps.pendingOf(sessionId).find((candidate) => candidate.requestId === requestId);
|
|
17031
|
+
if (pending === void 0) {
|
|
17032
|
+
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` };
|
|
17033
|
+
}
|
|
17034
|
+
const updatedInput = questionAnswerInput(deps, sessionId, pending, decision);
|
|
17035
|
+
if (updatedInput !== void 0 && "error" in updatedInput) {
|
|
17036
|
+
return { ok: false, message: updatedInput.error };
|
|
17037
|
+
}
|
|
17038
|
+
const release = deps.claimPending(sessionId, requestId);
|
|
17039
|
+
if (release === void 0) {
|
|
17040
|
+
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
17041
|
}
|
|
16805
|
-
const body = JSON.stringify(buildRcEventWriteBody(buildRcControlResponsePayload(requestId, decision)));
|
|
17042
|
+
const body = JSON.stringify(buildRcEventWriteBody(buildRcControlResponsePayload(requestId, decision, updatedInput?.input)));
|
|
16806
17043
|
let answer;
|
|
16807
17044
|
try {
|
|
16808
17045
|
answer = await deps.dial.writeEvents(sessionId, rcWriteHeaders(credential), body);
|
|
16809
17046
|
} catch (error) {
|
|
16810
17047
|
return { ok: false, message: `the door could not reach the API host to answer on session ${sessionId}: ${error instanceof Error ? error.message : String(error)}` };
|
|
17048
|
+
} finally {
|
|
17049
|
+
release();
|
|
16811
17050
|
}
|
|
16812
17051
|
const result = rcEventWriteResultFromAnswer(answer);
|
|
16813
17052
|
if (result.ok) {
|
|
@@ -16937,6 +17176,198 @@ init_legacy();
|
|
|
16937
17176
|
// src/frontdoor/rcControl.ts
|
|
16938
17177
|
var https = __toESM(require("node:https"), 1);
|
|
16939
17178
|
init_capability();
|
|
17179
|
+
|
|
17180
|
+
// src/frontdoor/rcSchemas.ts
|
|
17181
|
+
var import_zod10 = require("zod");
|
|
17182
|
+
var RcPermissionModeSchema = import_zod10.z.enum(RC_PERMISSION_MODES);
|
|
17183
|
+
var RcSessionSummarySchema = import_zod10.z.strictObject({
|
|
17184
|
+
id: import_zod10.z.string(),
|
|
17185
|
+
createdAt: import_zod10.z.number(),
|
|
17186
|
+
lastSeenAt: import_zod10.z.number()
|
|
17187
|
+
});
|
|
17188
|
+
function workerFactSchema(value) {
|
|
17189
|
+
return import_zod10.z.strictObject({ value, observedAt: import_zod10.z.number() });
|
|
17190
|
+
}
|
|
17191
|
+
var RcQuestionOptionSchema = import_zod10.z.strictObject({
|
|
17192
|
+
label: import_zod10.z.string(),
|
|
17193
|
+
description: import_zod10.z.string().optional()
|
|
17194
|
+
});
|
|
17195
|
+
var RcPendingQuestionSchema = import_zod10.z.strictObject({
|
|
17196
|
+
question: import_zod10.z.string(),
|
|
17197
|
+
header: import_zod10.z.string().optional(),
|
|
17198
|
+
multiSelect: import_zod10.z.boolean(),
|
|
17199
|
+
options: import_zod10.z.readonly(import_zod10.z.array(RcQuestionOptionSchema))
|
|
17200
|
+
});
|
|
17201
|
+
var RcPendingRequestSummarySchema = import_zod10.z.strictObject({
|
|
17202
|
+
sessionId: import_zod10.z.string(),
|
|
17203
|
+
requestId: import_zod10.z.string(),
|
|
17204
|
+
type: import_zod10.z.string(),
|
|
17205
|
+
summary: import_zod10.z.string(),
|
|
17206
|
+
questions: import_zod10.z.readonly(import_zod10.z.array(RcPendingQuestionSchema)).optional(),
|
|
17207
|
+
oversized: import_zod10.z.literal(true).optional(),
|
|
17208
|
+
unanswerable: import_zod10.z.string().optional(),
|
|
17209
|
+
observedAt: import_zod10.z.number()
|
|
17210
|
+
});
|
|
17211
|
+
var RcSessionStatusSchema = import_zod10.z.strictObject({
|
|
17212
|
+
...RcSessionSummarySchema.shape,
|
|
17213
|
+
workerState: workerFactSchema(import_zod10.z.string()).optional(),
|
|
17214
|
+
workerIdleSeconds: workerFactSchema(import_zod10.z.number()).optional(),
|
|
17215
|
+
pending: import_zod10.z.readonly(import_zod10.z.array(RcPendingRequestSummarySchema)),
|
|
17216
|
+
/** The identity the session runs as, when known; absent otherwise. */
|
|
17217
|
+
identity: import_zod10.z.string().optional(),
|
|
17218
|
+
/** The model the session last stated, when the door saw one. */
|
|
17219
|
+
model: import_zod10.z.string().optional(),
|
|
17220
|
+
/** The session's name from the Claude Code session registry, when the registry holds it. */
|
|
17221
|
+
name: import_zod10.z.string().optional(),
|
|
17222
|
+
/** The session process's id from the registry. */
|
|
17223
|
+
pid: import_zod10.z.number().optional(),
|
|
17224
|
+
/** The session's working directory, from its init event or the registry. */
|
|
17225
|
+
cwd: import_zod10.z.string().optional(),
|
|
17226
|
+
pendingDropped: import_zod10.z.int().positive().optional()
|
|
17227
|
+
});
|
|
17228
|
+
var RcStreamEnvelopeSchema = import_zod10.z.looseObject({
|
|
17229
|
+
/** The envelope's own event id, when the host sent one. */
|
|
17230
|
+
event_id: import_zod10.z.string().optional(),
|
|
17231
|
+
/** The envelope's event type, the discriminator a consumer switches on (`control_request`, `user`, and kin). */
|
|
17232
|
+
event_type: import_zod10.z.string(),
|
|
17233
|
+
/** The sequence number the host assigned, the value a resume continues after. */
|
|
17234
|
+
sequence_num: import_zod10.z.int(),
|
|
17235
|
+
/** Who emitted the event (`worker` for the CLI's half, a client id for a client's). */
|
|
17236
|
+
source: import_zod10.z.string(),
|
|
17237
|
+
/** 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. */
|
|
17238
|
+
payload: import_zod10.z.unknown().optional(),
|
|
17239
|
+
/** 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. */
|
|
17240
|
+
created_at: import_zod10.z.unknown().optional()
|
|
17241
|
+
});
|
|
17242
|
+
var RcStreamEventSchema = import_zod10.z.strictObject({
|
|
17243
|
+
session: import_zod10.z.string(),
|
|
17244
|
+
envelope: RcStreamEnvelopeSchema
|
|
17245
|
+
});
|
|
17246
|
+
var RcRateLimitWindowSchema = import_zod10.z.looseObject({
|
|
17247
|
+
/** 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). */
|
|
17248
|
+
utilization: import_zod10.z.number().optional(),
|
|
17249
|
+
/** 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. */
|
|
17250
|
+
resetsAt: import_zod10.z.number().optional()
|
|
17251
|
+
});
|
|
17252
|
+
var RcRateLimitInfoSchema = import_zod10.z.looseObject({
|
|
17253
|
+
/** The limiting window's own status (`allowed`, `allowed_warning`, `rejected`), asserted only as a string because the vocabulary grows with the CLI. */
|
|
17254
|
+
status: import_zod10.z.string(),
|
|
17255
|
+
/** When the limiting window resets, in unix epoch seconds. */
|
|
17256
|
+
resetsAt: import_zod10.z.number().optional(),
|
|
17257
|
+
/** Which window the top-level fields describe (`five_hour`, `seven_day`, and kin), the payload's own name for it. */
|
|
17258
|
+
rateLimitType: import_zod10.z.string().optional(),
|
|
17259
|
+
/** The fraction of the limiting window used, on the same scale the per-window utilizations carry. */
|
|
17260
|
+
utilization: import_zod10.z.number().optional(),
|
|
17261
|
+
/** Whether usage beyond the plan (extra usage) is currently covering the overflow, the payload's own flag for it. */
|
|
17262
|
+
isUsingOverage: import_zod10.z.boolean().optional(),
|
|
17263
|
+
/** The overage's own status, the same vocabulary the limiting window's `status` carries. */
|
|
17264
|
+
overageStatus: import_zod10.z.string().optional(),
|
|
17265
|
+
/** When the overage window resets, in unix epoch seconds. */
|
|
17266
|
+
overageResetsAt: import_zod10.z.number().optional(),
|
|
17267
|
+
/** 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. */
|
|
17268
|
+
unifiedWindows: import_zod10.z.looseObject({ five_hour: RcRateLimitWindowSchema.optional(), seven_day: RcRateLimitWindowSchema.optional(), seven_day_overage_included: RcRateLimitWindowSchema.optional() }).optional()
|
|
17269
|
+
});
|
|
17270
|
+
var RcLiveRateLimitSchema = import_zod10.z.strictObject({
|
|
17271
|
+
session: import_zod10.z.string(),
|
|
17272
|
+
observedAt: import_zod10.z.number(),
|
|
17273
|
+
rateLimit: RcRateLimitInfoSchema
|
|
17274
|
+
});
|
|
17275
|
+
var RcSessionQuerySchema = import_zod10.z.strictObject({
|
|
17276
|
+
session: import_zod10.z.string().min(1).optional()
|
|
17277
|
+
});
|
|
17278
|
+
var RcSendInputSchema = import_zod10.z.strictObject({
|
|
17279
|
+
session: import_zod10.z.string().min(1),
|
|
17280
|
+
text: import_zod10.z.string().min(1)
|
|
17281
|
+
});
|
|
17282
|
+
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" }) })]);
|
|
17283
|
+
var RcQuestionChoicesSchema = import_zod10.z.array(import_zod10.z.array(RcQuestionSelectionSchema).min(1)).min(1);
|
|
17284
|
+
var RcAnswerInputSchema = import_zod10.z.strictObject({
|
|
17285
|
+
session: import_zod10.z.string().min(1),
|
|
17286
|
+
request: import_zod10.z.string().min(1),
|
|
17287
|
+
approve: import_zod10.z.boolean(),
|
|
17288
|
+
text: import_zod10.z.string().optional(),
|
|
17289
|
+
choices: RcQuestionChoicesSchema.optional()
|
|
17290
|
+
}).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" });
|
|
17291
|
+
var RcInterruptInputSchema = import_zod10.z.strictObject({
|
|
17292
|
+
session: import_zod10.z.string().min(1)
|
|
17293
|
+
});
|
|
17294
|
+
var RcSetModelInputSchema = import_zod10.z.strictObject({
|
|
17295
|
+
session: import_zod10.z.string().min(1),
|
|
17296
|
+
model: import_zod10.z.string().min(1)
|
|
17297
|
+
});
|
|
17298
|
+
var RcSetPermissionModeInputSchema = import_zod10.z.strictObject({
|
|
17299
|
+
session: import_zod10.z.string().min(1),
|
|
17300
|
+
mode: RcPermissionModeSchema
|
|
17301
|
+
});
|
|
17302
|
+
var RcEndSessionInputSchema = import_zod10.z.strictObject({
|
|
17303
|
+
session: import_zod10.z.string().min(1),
|
|
17304
|
+
reason: import_zod10.z.string().min(1).optional()
|
|
17305
|
+
});
|
|
17306
|
+
var RcGetUsageInputSchema = import_zod10.z.strictObject({
|
|
17307
|
+
session: import_zod10.z.string().min(1),
|
|
17308
|
+
skipBehaviors: import_zod10.z.boolean().optional()
|
|
17309
|
+
});
|
|
17310
|
+
var RcGetContextUsageInputSchema = import_zod10.z.strictObject({
|
|
17311
|
+
session: import_zod10.z.string().min(1),
|
|
17312
|
+
detail: import_zod10.z.enum(RC_CONTEXT_USAGE_DETAILS).optional()
|
|
17313
|
+
});
|
|
17314
|
+
var RcReadFileInputSchema = import_zod10.z.strictObject({
|
|
17315
|
+
session: import_zod10.z.string().min(1),
|
|
17316
|
+
path: import_zod10.z.string().min(1),
|
|
17317
|
+
maxBytes: import_zod10.z.number().int().positive().optional(),
|
|
17318
|
+
encoding: import_zod10.z.enum(RC_READ_FILE_ENCODINGS).optional()
|
|
17319
|
+
});
|
|
17320
|
+
var RcFileSuggestionsInputSchema = import_zod10.z.strictObject({
|
|
17321
|
+
session: import_zod10.z.string().min(1),
|
|
17322
|
+
query: import_zod10.z.string()
|
|
17323
|
+
});
|
|
17324
|
+
var RcKeepAliveInputSchema = import_zod10.z.strictObject({
|
|
17325
|
+
session: import_zod10.z.string().min(1)
|
|
17326
|
+
});
|
|
17327
|
+
var RcMcpStatusInputSchema = import_zod10.z.strictObject({
|
|
17328
|
+
session: import_zod10.z.string().min(1)
|
|
17329
|
+
});
|
|
17330
|
+
var RcMcpReconnectInputSchema = import_zod10.z.strictObject({
|
|
17331
|
+
session: import_zod10.z.string().min(1),
|
|
17332
|
+
serverName: import_zod10.z.string().min(1)
|
|
17333
|
+
});
|
|
17334
|
+
var RcMcpAuthenticateInputSchema = import_zod10.z.strictObject({
|
|
17335
|
+
session: import_zod10.z.string().min(1),
|
|
17336
|
+
serverName: import_zod10.z.string().min(1),
|
|
17337
|
+
redirectUri: import_zod10.z.string().min(1)
|
|
17338
|
+
});
|
|
17339
|
+
var RcMcpOAuthCallbackUrlInputSchema = import_zod10.z.strictObject({
|
|
17340
|
+
session: import_zod10.z.string().min(1),
|
|
17341
|
+
serverName: import_zod10.z.string().min(1),
|
|
17342
|
+
callbackUrl: import_zod10.z.string().min(1)
|
|
17343
|
+
});
|
|
17344
|
+
var RcTeleportInputSchema = import_zod10.z.strictObject({
|
|
17345
|
+
session: import_zod10.z.string().min(1),
|
|
17346
|
+
marker: import_zod10.z.string().min(1)
|
|
17347
|
+
});
|
|
17348
|
+
var RcListOutputSchema = import_zod10.z.strictObject({ sessions: import_zod10.z.readonly(import_zod10.z.array(RcSessionSummarySchema)) });
|
|
17349
|
+
var RcStatusOutputSchema = import_zod10.z.strictObject({ statuses: import_zod10.z.readonly(import_zod10.z.array(RcSessionStatusSchema)) });
|
|
17350
|
+
var RcPendingOutputSchema = import_zod10.z.strictObject({
|
|
17351
|
+
pending: import_zod10.z.readonly(import_zod10.z.array(RcPendingRequestSummarySchema)),
|
|
17352
|
+
/** 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. */
|
|
17353
|
+
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()
|
|
17354
|
+
});
|
|
17355
|
+
var RcWriteOutputSchema = import_zod10.z.strictObject({
|
|
17356
|
+
session: import_zod10.z.string(),
|
|
17357
|
+
sequenceNums: import_zod10.z.readonly(import_zod10.z.array(import_zod10.z.number()))
|
|
17358
|
+
});
|
|
17359
|
+
var RcControlWriteOutputSchema = import_zod10.z.strictObject({
|
|
17360
|
+
session: import_zod10.z.string(),
|
|
17361
|
+
request: import_zod10.z.string(),
|
|
17362
|
+
sequenceNums: import_zod10.z.readonly(import_zod10.z.array(import_zod10.z.number()))
|
|
17363
|
+
});
|
|
17364
|
+
var RcAnswerOutputSchema = import_zod10.z.strictObject({
|
|
17365
|
+
session: import_zod10.z.string(),
|
|
17366
|
+
request: import_zod10.z.string(),
|
|
17367
|
+
sequenceNums: import_zod10.z.readonly(import_zod10.z.array(import_zod10.z.number()))
|
|
17368
|
+
});
|
|
17369
|
+
|
|
17370
|
+
// src/frontdoor/rcControl.ts
|
|
16940
17371
|
var RC_PERMISSION_MODE_LIST = RC_PERMISSION_MODES.join(", ");
|
|
16941
17372
|
var CONTROL_PATH_PREFIX = "/__agent-shim/rc";
|
|
16942
17373
|
var CONTROL_BODY_CAP_BYTES = 10485760;
|
|
@@ -17193,11 +17624,20 @@ function createRcControlHandler(deps) {
|
|
|
17193
17624
|
return;
|
|
17194
17625
|
}
|
|
17195
17626
|
const text = "text" in parsed && typeof parsed.text === "string" ? parsed.text : void 0;
|
|
17627
|
+
const choices = "choices" in parsed ? RcQuestionChoicesSchema.safeParse(parsed.choices) : void 0;
|
|
17628
|
+
if (choices !== void 0 && !choices.success) {
|
|
17629
|
+
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": ...}' });
|
|
17630
|
+
return;
|
|
17631
|
+
}
|
|
17632
|
+
if (choices !== void 0 && !parsed.approve) {
|
|
17633
|
+
answerJson(response, HTTP_STATUS.badRequest, { error: "choices answer a question, so they come with approve: true; a denial dismisses the question" });
|
|
17634
|
+
return;
|
|
17635
|
+
}
|
|
17196
17636
|
if (parsed.approve && text !== void 0 && text !== "") {
|
|
17197
17637
|
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
17638
|
return;
|
|
17199
17639
|
}
|
|
17200
|
-
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 : text });
|
|
17640
|
+
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
17641
|
if (result.ok) {
|
|
17202
17642
|
answerJson(response, HTTP_STATUS.ok, { session: parsed.session, request: parsed.request, sequenceNums: result.sequenceNums });
|
|
17203
17643
|
return;
|
|
@@ -17319,6 +17759,9 @@ function isRcSessionStatus(value) {
|
|
|
17319
17759
|
if ("workerState" in value && value.workerState !== void 0 && !isRcWorkerFact(value.workerState, (candidate) => typeof candidate === "string")) {
|
|
17320
17760
|
return false;
|
|
17321
17761
|
}
|
|
17762
|
+
if ("pendingDropped" in value && value.pendingDropped !== void 0 && typeof value.pendingDropped !== "number") {
|
|
17763
|
+
return false;
|
|
17764
|
+
}
|
|
17322
17765
|
if ("workerIdleSeconds" in value && value.workerIdleSeconds !== void 0 && !isRcWorkerFact(value.workerIdleSeconds, (candidate) => typeof candidate === "number")) {
|
|
17323
17766
|
return false;
|
|
17324
17767
|
}
|
|
@@ -17328,13 +17771,7 @@ function isRcSessionStatus(value) {
|
|
|
17328
17771
|
return value.pending.every((candidate) => isRcPendingRequestSummary(candidate));
|
|
17329
17772
|
}
|
|
17330
17773
|
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";
|
|
17774
|
+
return RcPendingRequestSummarySchema.safeParse(value).success;
|
|
17338
17775
|
}
|
|
17339
17776
|
function sequenceNumsOfBody(body) {
|
|
17340
17777
|
let parsed;
|
|
@@ -17470,7 +17907,7 @@ function frontDoorRcControl(transport, token) {
|
|
|
17470
17907
|
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
17908
|
answerRequest: async (sessionId, requestId, decision) => await writeOf(
|
|
17472
17909
|
`${CONTROL_PATH_PREFIX}/answer`,
|
|
17473
|
-
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message } }),
|
|
17910
|
+
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
17911
|
(status, message) => `answering control request ${requestId} on ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
17475
17912
|
),
|
|
17476
17913
|
interruptSession: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/interrupt`, JSON.stringify({ session: sessionId }), (status, message) => `interrupting ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -17987,20 +18424,20 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
|
|
|
17987
18424
|
|
|
17988
18425
|
// src/frontdoor/rcSessionRegistry.ts
|
|
17989
18426
|
var import_node_path31 = __toESM(require("node:path"), 1);
|
|
17990
|
-
var
|
|
18427
|
+
var import_zod22 = require("zod");
|
|
17991
18428
|
init_identityStore();
|
|
17992
18429
|
var REGISTRY_BRIDGE_PREFIX = "session_";
|
|
17993
18430
|
var DOOR_SESSION_PREFIX = "cse_";
|
|
17994
18431
|
var REGISTRY_DIR = "sessions";
|
|
17995
18432
|
var ENTRY_SUFFIX = ".json";
|
|
17996
18433
|
var RC_REGISTRY_ENTRY_MAX_BYTES = 8192;
|
|
17997
|
-
var RegistryEntrySchema =
|
|
17998
|
-
sessionId:
|
|
17999
|
-
pid:
|
|
18000
|
-
bridgeSessionId:
|
|
18001
|
-
cwd:
|
|
18002
|
-
name:
|
|
18003
|
-
updatedAt:
|
|
18434
|
+
var RegistryEntrySchema = import_zod22.z.looseObject({
|
|
18435
|
+
sessionId: import_zod22.z.string().min(1),
|
|
18436
|
+
pid: import_zod22.z.int().positive(),
|
|
18437
|
+
bridgeSessionId: import_zod22.z.union([import_zod22.z.string().startsWith(REGISTRY_BRIDGE_PREFIX), import_zod22.z.string().startsWith(DOOR_SESSION_PREFIX)]),
|
|
18438
|
+
cwd: import_zod22.z.string().optional(),
|
|
18439
|
+
name: import_zod22.z.string().optional(),
|
|
18440
|
+
updatedAt: import_zod22.z.number().optional()
|
|
18004
18441
|
});
|
|
18005
18442
|
function supersedes(candidate, kept) {
|
|
18006
18443
|
return candidate.updatedAt > kept.updatedAt || candidate.updatedAt === kept.updatedAt && candidate.session.pid > kept.session.pid;
|
|
@@ -18114,11 +18551,11 @@ var import_node_path32 = __toESM(require("node:path"), 1);
|
|
|
18114
18551
|
function isSafeSessionId(sessionId) {
|
|
18115
18552
|
return /^[A-Za-z0-9_-]+$/.test(sessionId);
|
|
18116
18553
|
}
|
|
18117
|
-
function
|
|
18554
|
+
function isRecord7(value) {
|
|
18118
18555
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18119
18556
|
}
|
|
18120
18557
|
function credentialOfJson(parsed) {
|
|
18121
|
-
if (!
|
|
18558
|
+
if (!isRecord7(parsed)) {
|
|
18122
18559
|
return void 0;
|
|
18123
18560
|
}
|
|
18124
18561
|
const { authorization, anthropicVersion, anthropicClientPlatform } = parsed;
|
|
@@ -18148,7 +18585,7 @@ function createRcCredentialStore(fs17, dir) {
|
|
|
18148
18585
|
} catch {
|
|
18149
18586
|
return void 0;
|
|
18150
18587
|
}
|
|
18151
|
-
return
|
|
18588
|
+
return isRecord7(parsed) ? parsed : void 0;
|
|
18152
18589
|
};
|
|
18153
18590
|
return {
|
|
18154
18591
|
read: (sessionId) => {
|
|
@@ -18206,175 +18643,6 @@ var COMPACT_TIMEOUT_MS = 9e5;
|
|
|
18206
18643
|
// src/frontdoor/rcApi.ts
|
|
18207
18644
|
init_capability();
|
|
18208
18645
|
|
|
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
18646
|
// src/frontdoor/rcSlashCommandSchemas.ts
|
|
18379
18647
|
var import_zod23 = require("zod");
|
|
18380
18648
|
|
|
@@ -18412,26 +18680,26 @@ async function writeRcPersonMessage(deps, sessionId, text) {
|
|
|
18412
18680
|
}
|
|
18413
18681
|
return result;
|
|
18414
18682
|
}
|
|
18415
|
-
function
|
|
18683
|
+
function isRecord8(value) {
|
|
18416
18684
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18417
18685
|
}
|
|
18418
18686
|
function rcLocalCommandAnswerOf(event, command, args) {
|
|
18419
18687
|
const payload = event.envelope.payload;
|
|
18420
|
-
if (!
|
|
18688
|
+
if (!isRecord8(payload) || payload.type !== "assistant" || !isRecord8(payload.local_command_run) || payload.local_command_run.command !== command || payload.local_command_run.args !== args) {
|
|
18421
18689
|
return void 0;
|
|
18422
18690
|
}
|
|
18423
18691
|
const message = payload.message;
|
|
18424
|
-
if (!
|
|
18692
|
+
if (!isRecord8(message) || !Array.isArray(message.content)) {
|
|
18425
18693
|
return void 0;
|
|
18426
18694
|
}
|
|
18427
18695
|
const blocks = message.content;
|
|
18428
|
-
const text = blocks.flatMap((block) =>
|
|
18429
|
-
const outcome =
|
|
18696
|
+
const text = blocks.flatMap((block) => isRecord8(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
|
|
18697
|
+
const outcome = isRecord8(payload.local_command_outcome) && typeof payload.local_command_outcome.kind === "string" ? payload.local_command_outcome.kind : void 0;
|
|
18430
18698
|
return { text, outcome };
|
|
18431
18699
|
}
|
|
18432
18700
|
function rcManualCompactBoundaryOf(event) {
|
|
18433
18701
|
const payload = event.envelope.payload;
|
|
18434
|
-
if (!
|
|
18702
|
+
if (!isRecord8(payload) || payload.type !== "system" || payload.subtype !== "compact_boundary" || !isRecord8(payload.compact_metadata)) {
|
|
18435
18703
|
return void 0;
|
|
18436
18704
|
}
|
|
18437
18705
|
const metadata = payload.compact_metadata;
|
|
@@ -18442,7 +18710,7 @@ function rcManualCompactBoundaryOf(event) {
|
|
|
18442
18710
|
}
|
|
18443
18711
|
function isPeerDelivery(event, text) {
|
|
18444
18712
|
const payload = event.envelope.payload;
|
|
18445
|
-
if (!
|
|
18713
|
+
if (!isRecord8(payload) || payload.type !== "user" || !isRecord8(payload.origin) || payload.origin.kind !== "peer" || !isRecord8(payload.message)) {
|
|
18446
18714
|
return false;
|
|
18447
18715
|
}
|
|
18448
18716
|
return typeof payload.message.content === "string" && payload.message.content.includes(text);
|
|
@@ -18559,7 +18827,7 @@ function createRcClaudeCodeVersions(fanout) {
|
|
|
18559
18827
|
const versions = /* @__PURE__ */ new Map();
|
|
18560
18828
|
fanout.subscribe(void 0, (event) => {
|
|
18561
18829
|
const payload = event.envelope.payload;
|
|
18562
|
-
if (event.envelope.source === "worker" &&
|
|
18830
|
+
if (event.envelope.source === "worker" && isRecord8(payload) && payload.type === "system" && payload.subtype === "init" && typeof payload.claude_code_version === "string") {
|
|
18563
18831
|
versions.set(event.session, payload.claude_code_version);
|
|
18564
18832
|
}
|
|
18565
18833
|
});
|
|
@@ -18865,14 +19133,16 @@ function createRcApiRouter(deps) {
|
|
|
18865
19133
|
}),
|
|
18866
19134
|
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
19135
|
const pending = deps.pendingOf(input.session);
|
|
18868
|
-
|
|
19136
|
+
const statuses = deps.statusOf(input.session);
|
|
19137
|
+
if (input.session !== void 0 && statuses.length === 0) {
|
|
18869
19138
|
throw new import_client.ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input.session) });
|
|
18870
19139
|
}
|
|
18871
|
-
|
|
19140
|
+
const dropped = statuses.flatMap((status) => status.pendingDropped === void 0 ? [] : [{ sessionId: status.id, count: status.pendingDropped }]);
|
|
19141
|
+
return { pending, ...dropped.length === 0 ? {} : { dropped } };
|
|
18872
19142
|
}),
|
|
18873
19143
|
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 };
|
|
19144
|
+
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 }) => {
|
|
19145
|
+
const decision = { approve: input.approve, message: input.approve || input.text === void 0 ? void 0 : input.text, ...input.choices === void 0 ? {} : { choices: input.choices } };
|
|
18876
19146
|
return { session: input.session, request: input.request, sequenceNums: delivered(input.session, await deps.answer(input.session, input.request, decision)) };
|
|
18877
19147
|
}),
|
|
18878
19148
|
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)) })),
|
|
@@ -22277,8 +22547,8 @@ function rcFanoutOnDoorHub(fanout, hub) {
|
|
|
22277
22547
|
|
|
22278
22548
|
// src/frontdoor/rcEventLog.ts
|
|
22279
22549
|
var RC_SESSION_EVENT_TOKEN_MAX_CHARS = 255;
|
|
22280
|
-
var
|
|
22281
|
-
var
|
|
22550
|
+
var HIGH_SURROGATE_FIRST2 = 55296;
|
|
22551
|
+
var HIGH_SURROGATE_LAST2 = 56319;
|
|
22282
22552
|
var LOW_SURROGATE_FIRST = 56320;
|
|
22283
22553
|
var LOW_SURROGATE_LAST = 57343;
|
|
22284
22554
|
var CUT_MARKER = "...";
|
|
@@ -22289,7 +22559,7 @@ var NUMBER_BYTES = Float64Array.BYTES_PER_ELEMENT;
|
|
|
22289
22559
|
var NUMBER_FIELDS = ["at", "sequence"].length;
|
|
22290
22560
|
var BYTES_PER_CODE_UNIT = Uint16Array.BYTES_PER_ELEMENT;
|
|
22291
22561
|
var RC_SESSION_END_REASONS = ["expired", "archived", "conflict"];
|
|
22292
|
-
var RC_PENDING_RETIRE_REASONS = ["answered", "
|
|
22562
|
+
var RC_PENDING_RETIRE_REASONS = ["answered", "withdrawn", "worker-stopped", "session-ended"];
|
|
22293
22563
|
var transitionBase = { session: import_zod43.z.string(), at: import_zod43.z.number() };
|
|
22294
22564
|
var cursorFields = { cursor: import_zod43.z.string(), sequence: import_zod43.z.int().positive() };
|
|
22295
22565
|
var sessionAppearedShape = { kind: import_zod43.z.literal("session-appeared"), ...transitionBase };
|
|
@@ -22350,7 +22620,7 @@ function parseCursor(cursor) {
|
|
|
22350
22620
|
function codePointBoundary(text, at) {
|
|
22351
22621
|
const before = text.charCodeAt(at - 1);
|
|
22352
22622
|
const after = text.charCodeAt(at);
|
|
22353
|
-
const isHigh = before >=
|
|
22623
|
+
const isHigh = before >= HIGH_SURROGATE_FIRST2 && before <= HIGH_SURROGATE_LAST2;
|
|
22354
22624
|
const isLow = after >= LOW_SURROGATE_FIRST && after <= LOW_SURROGATE_LAST;
|
|
22355
22625
|
return isHigh && isLow ? at - 1 : at;
|
|
22356
22626
|
}
|
|
@@ -22828,15 +23098,15 @@ function createQuotaExpiringPublisher(hub, deps) {
|
|
|
22828
23098
|
|
|
22829
23099
|
// src/frontdoor/rcLiveUsage.ts
|
|
22830
23100
|
var RC_RATE_LIMIT_EVENT_TYPE = "rate_limit_event";
|
|
22831
|
-
function
|
|
23101
|
+
function isRecord10(value) {
|
|
22832
23102
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22833
23103
|
}
|
|
22834
23104
|
function rcRateLimitInfoOf(event) {
|
|
22835
23105
|
const payload = event.envelope.payload;
|
|
22836
|
-
if (!
|
|
23106
|
+
if (!isRecord10(payload) || payload.type !== RC_RATE_LIMIT_EVENT_TYPE) {
|
|
22837
23107
|
return void 0;
|
|
22838
23108
|
}
|
|
22839
|
-
if (!
|
|
23109
|
+
if (!isRecord10(payload.rate_limit_info)) {
|
|
22840
23110
|
return void 0;
|
|
22841
23111
|
}
|
|
22842
23112
|
const parsed = RcRateLimitInfoSchema.safeParse(payload.rate_limit_info);
|
|
@@ -22924,7 +23194,7 @@ function createSseParser() {
|
|
|
22924
23194
|
}
|
|
22925
23195
|
};
|
|
22926
23196
|
}
|
|
22927
|
-
function
|
|
23197
|
+
function isRecord11(value) {
|
|
22928
23198
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22929
23199
|
}
|
|
22930
23200
|
function sequenceNumOf(value) {
|
|
@@ -22946,7 +23216,7 @@ function parseRcStreamEnvelope(parsed) {
|
|
|
22946
23216
|
} catch {
|
|
22947
23217
|
return void 0;
|
|
22948
23218
|
}
|
|
22949
|
-
if (!
|
|
23219
|
+
if (!isRecord11(data)) {
|
|
22950
23220
|
return void 0;
|
|
22951
23221
|
}
|
|
22952
23222
|
const eventType = data.event_type;
|
|
@@ -23199,7 +23469,7 @@ function withClientPlatform(payload, headers) {
|
|
|
23199
23469
|
const platform = headers[CLIENT_PLATFORM_HEADER];
|
|
23200
23470
|
return typeof platform === "string" && platform !== "" ? { ...rest, client_platform: platform } : rest;
|
|
23201
23471
|
}
|
|
23202
|
-
function
|
|
23472
|
+
function isRecord12(value) {
|
|
23203
23473
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23204
23474
|
}
|
|
23205
23475
|
function parseJsonObject2(body) {
|
|
@@ -23209,7 +23479,7 @@ function parseJsonObject2(body) {
|
|
|
23209
23479
|
} catch {
|
|
23210
23480
|
return void 0;
|
|
23211
23481
|
}
|
|
23212
|
-
return
|
|
23482
|
+
return isRecord12(parsed) ? parsed : void 0;
|
|
23213
23483
|
}
|
|
23214
23484
|
function nonEmptyString2(record, field) {
|
|
23215
23485
|
const value = record === void 0 ? void 0 : record[field];
|
|
@@ -23283,7 +23553,7 @@ async function serveRcClientChannels(ctx, tail, method, maxBatchEvents) {
|
|
|
23283
23553
|
}
|
|
23284
23554
|
const results = [];
|
|
23285
23555
|
for (const event of events) {
|
|
23286
|
-
if (!
|
|
23556
|
+
if (!isRecord12(event) || !isRecord12(event.payload)) {
|
|
23287
23557
|
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
23558
|
return true;
|
|
23289
23559
|
}
|
|
@@ -23383,7 +23653,7 @@ async function serveRcCompatSessions(ctx, pathname, compatPath) {
|
|
|
23383
23653
|
// src/frontdoor/rcSelfHostConversations.ts
|
|
23384
23654
|
var RC_CONVERSATIONS_PATH_PREFIX = "/v1/code/conversations";
|
|
23385
23655
|
var RC_CONVERSATION_ID_PREFIX = "conv_";
|
|
23386
|
-
function
|
|
23656
|
+
function isRecord13(value) {
|
|
23387
23657
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23388
23658
|
}
|
|
23389
23659
|
function parseJsonObject3(body) {
|
|
@@ -23393,7 +23663,7 @@ function parseJsonObject3(body) {
|
|
|
23393
23663
|
} catch {
|
|
23394
23664
|
return void 0;
|
|
23395
23665
|
}
|
|
23396
|
-
return
|
|
23666
|
+
return isRecord13(parsed) ? parsed : void 0;
|
|
23397
23667
|
}
|
|
23398
23668
|
function nonEmptyString3(record, field) {
|
|
23399
23669
|
const value = record === void 0 ? void 0 : record[field];
|
|
@@ -23447,7 +23717,7 @@ async function serveRcConversations(ctx, pathname, method) {
|
|
|
23447
23717
|
}
|
|
23448
23718
|
const results = [];
|
|
23449
23719
|
for (const event of events) {
|
|
23450
|
-
if (!
|
|
23720
|
+
if (!isRecord13(event) || !isRecord13(event.payload)) {
|
|
23451
23721
|
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
23722
|
return;
|
|
23453
23723
|
}
|
|
@@ -23479,7 +23749,7 @@ var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:
|
|
|
23479
23749
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
23480
23750
|
var MS_PER_SECOND6 = 1e3;
|
|
23481
23751
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
23482
|
-
function
|
|
23752
|
+
function isRecord14(value) {
|
|
23483
23753
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23484
23754
|
}
|
|
23485
23755
|
function parseJsonObject4(body) {
|
|
@@ -23489,7 +23759,7 @@ function parseJsonObject4(body) {
|
|
|
23489
23759
|
} catch {
|
|
23490
23760
|
return void 0;
|
|
23491
23761
|
}
|
|
23492
|
-
return
|
|
23762
|
+
return isRecord14(parsed) ? parsed : void 0;
|
|
23493
23763
|
}
|
|
23494
23764
|
function growthBookFeatures() {
|
|
23495
23765
|
return {
|
|
@@ -23843,7 +24113,7 @@ var RC_SELF_HOST_WORKER_EPOCH = 1;
|
|
|
23843
24113
|
var RC_STREAM_EVENT_NAME2 = "client_event";
|
|
23844
24114
|
var CONFLICT_REASON_HEADER2 = "x-ccr-conflict-reason";
|
|
23845
24115
|
var CONFLICT_REASON_EPOCH_STALE = "epoch_stale";
|
|
23846
|
-
function
|
|
24116
|
+
function isRecord15(value) {
|
|
23847
24117
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23848
24118
|
}
|
|
23849
24119
|
function isWebSearchRefusal(value) {
|
|
@@ -23927,7 +24197,7 @@ function parseJsonObject5(body) {
|
|
|
23927
24197
|
} catch {
|
|
23928
24198
|
return void 0;
|
|
23929
24199
|
}
|
|
23930
|
-
return
|
|
24200
|
+
return isRecord15(parsed) ? parsed : void 0;
|
|
23931
24201
|
}
|
|
23932
24202
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
23933
24203
|
const encode = (value) => Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
|
|
@@ -24187,7 +24457,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24187
24457
|
if (status !== void 0) {
|
|
24188
24458
|
session.workerStatus = status;
|
|
24189
24459
|
}
|
|
24190
|
-
if (
|
|
24460
|
+
if (isRecord15(body?.external_metadata)) {
|
|
24191
24461
|
session.externalMetadata = body.external_metadata;
|
|
24192
24462
|
}
|
|
24193
24463
|
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
@@ -24217,7 +24487,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24217
24487
|
}
|
|
24218
24488
|
const results = [];
|
|
24219
24489
|
for (const event of events) {
|
|
24220
|
-
if (!
|
|
24490
|
+
if (!isRecord15(event) || !isRecord15(event.payload)) {
|
|
24221
24491
|
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
24492
|
return;
|
|
24223
24493
|
}
|
|
@@ -24250,7 +24520,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24250
24520
|
return;
|
|
24251
24521
|
}
|
|
24252
24522
|
for (const event of events) {
|
|
24253
|
-
if (
|
|
24523
|
+
if (isRecord15(event)) {
|
|
24254
24524
|
session.internalEvents.push({ eventId: deps.newUuid(), body: event });
|
|
24255
24525
|
}
|
|
24256
24526
|
}
|
|
@@ -24346,7 +24616,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
24346
24616
|
}
|
|
24347
24617
|
const results = [];
|
|
24348
24618
|
for (const event of events) {
|
|
24349
|
-
if (!
|
|
24619
|
+
if (!isRecord15(event) || !isRecord15(event.payload)) {
|
|
24350
24620
|
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
24621
|
return;
|
|
24352
24622
|
}
|
|
@@ -24484,7 +24754,7 @@ var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
|
24484
24754
|
var RC_SELF_HOST_RECORD_FILE = "credential.json";
|
|
24485
24755
|
var SELF_HOST_EMAIL = "selfhost@agent-shim.invalid";
|
|
24486
24756
|
var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
24487
|
-
function
|
|
24757
|
+
function isRecord16(value) {
|
|
24488
24758
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24489
24759
|
}
|
|
24490
24760
|
function readJsonObject(fs17, file) {
|
|
@@ -24498,7 +24768,7 @@ function readJsonObject(fs17, file) {
|
|
|
24498
24768
|
} catch {
|
|
24499
24769
|
return void 0;
|
|
24500
24770
|
}
|
|
24501
|
-
return
|
|
24771
|
+
return isRecord16(parsed) ? parsed : void 0;
|
|
24502
24772
|
}
|
|
24503
24773
|
function readRcSelfHostRecord(fs17, frontdoorDir) {
|
|
24504
24774
|
const parsed = readJsonObject(fs17, import_node_path45.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
@@ -24526,7 +24796,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
24526
24796
|
const recordFile2 = import_node_path45.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
24527
24797
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
24528
24798
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
24529
|
-
const existingOauth =
|
|
24799
|
+
const existingOauth = isRecord16(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
24530
24800
|
const existingToken = typeof existingOauth?.accessToken === "string" && existingOauth.accessToken !== "" ? existingOauth.accessToken : void 0;
|
|
24531
24801
|
const existingIsOwn = existingToken !== void 0 && previousRecord?.accessToken === existingToken;
|
|
24532
24802
|
if (existingToken !== void 0 && !existingIsOwn && !deps.force) {
|
|
@@ -24543,7 +24813,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
24543
24813
|
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
24814
|
`);
|
|
24545
24815
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
24546
|
-
const existingBlock = (value) =>
|
|
24816
|
+
const existingBlock = (value) => isRecord16(value) ? value : {};
|
|
24547
24817
|
deps.fs.writeFilePrivate(claudeJsonFile, `${JSON.stringify({
|
|
24548
24818
|
...claudeJson,
|
|
24549
24819
|
oauthAccount: {
|
|
@@ -25301,7 +25571,6 @@ init_ownCli();
|
|
|
25301
25571
|
RC_GOAL_CONDITION_MAX_CHARS,
|
|
25302
25572
|
RC_IDLE_EXPIRY_MS,
|
|
25303
25573
|
RC_ORPC_PATH_PREFIX,
|
|
25304
|
-
RC_PENDING_DEADLINE_MS,
|
|
25305
25574
|
RC_PENDING_RETIRE_REASONS,
|
|
25306
25575
|
RC_PERMISSION_MODES,
|
|
25307
25576
|
RC_READ_FILE_ENCODINGS,
|