agl 43.3.2 → 43.5.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/changelog.md +33 -0
- package/dist_serve/bundle.js +2248 -2236
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +29 -29
- package/dist_serve/bundle.js.third-party-notices.txt +29 -29
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/interfaces.d.ts +5 -0
- package/dist_ts/aglapi/interfaces.js +2 -1
- package/dist_ts/classes.authstore.js +5 -2
- package/dist_ts/classes.claudeharness.js +4 -3
- package/dist_ts/classes.codexclientadapter.d.ts +5 -0
- package/dist_ts/classes.codexclientadapter.js +12 -6
- package/dist_ts/classes.controller.d.ts +32 -6
- package/dist_ts/classes.controller.js +165 -62
- package/dist_ts/classes.inferencegateway.js +14 -2
- package/dist_ts/classes.inferencerouter.d.ts +9 -1
- package/dist_ts/classes.inferencerouter.js +68 -14
- package/dist_ts/classes.mcpclient.d.ts +2 -2
- package/dist_ts/classes.mcpclient.js +14 -9
- package/dist_ts/classes.mcptools.d.ts +1 -1
- package/dist_ts/classes.mcptools.js +2 -1
- package/dist_ts/classes.opencodeclient.js +20 -4
- package/dist_ts/driver/functions.driverinstructions.d.ts +1 -1
- package/dist_ts/driver/functions.driverinstructions.js +2 -1
- package/dist_ts/fleet/classes.claudeworkers.d.ts +8 -5
- package/dist_ts/fleet/classes.claudeworkers.js +13 -8
- package/dist_ts/fleet/classes.deploymodels.d.ts +58 -1
- package/dist_ts/fleet/classes.deploymodels.js +121 -2
- package/dist_ts/fleet/classes.deploymonitor.d.ts +193 -47
- package/dist_ts/fleet/classes.deploymonitor.js +548 -180
- package/dist_ts/fleet/classes.gitfacts.d.ts +4 -1
- package/dist_ts/fleet/classes.gitfacts.js +13 -10
- package/dist_ts/fleet/classes.service.d.ts +2 -0
- package/dist_ts/fleet/classes.service.js +6 -3
- package/dist_ts/fleet/functions.deployprobes.js +21 -2
- package/dist_ts/fleet/functions.deploystatus.d.ts +26 -0
- package/dist_ts/fleet/functions.deploystatus.js +33 -0
- package/dist_ts/fleet/functions.deployvalidation.d.ts +1 -0
- package/dist_ts/fleet/functions.deployvalidation.js +5 -2
- package/dist_ts/functions.claudecoderelease.d.ts +1 -1
- package/dist_ts/functions.claudecoderelease.js +1 -1
- package/dist_ts/functions.deploycli.js +3 -2
- package/dist_ts/functions.deviceapi.d.ts +7 -6
- package/dist_ts/functions.deviceapi.js +13 -5
- package/dist_ts/functions.inferencecli.js +10 -2
- package/dist_ts/functions.inferencelaunch.d.ts +19 -8
- package/dist_ts/functions.inferencelaunch.js +23 -12
- package/dist_ts/functions.mcpdeploytools.js +3 -1
- package/dist_ts/functions.promptreply.d.ts +13 -0
- package/dist_ts/functions.promptreply.js +17 -0
- package/dist_ts/functions.proxyharnessconfig.d.ts +18 -0
- package/dist_ts/functions.proxyharnessconfig.js +30 -1
- package/dist_ts_authswitch/authority-renewal.d.ts +12 -3
- package/dist_ts_authswitch/authority-renewal.js +14 -5
- package/dist_ts_authswitch/classes.claudenative.d.ts +8 -8
- package/dist_ts_authswitch/classes.claudenative.js +13 -13
- package/dist_ts_interfaces/deployments.d.ts +38 -6
- package/dist_ts_interfaces/deployments.js +7 -3
- package/dist_ts_interfaces/devices.d.ts +2 -1
- package/dist_ts_interfaces/devices.js +1 -1
- package/dist_ts_interfaces/inbox.d.ts +10 -1
- package/dist_ts_interfaces/inbox.js +1 -1
- package/dist_ts_interfaces/mcprequests.d.ts +1 -1
- package/dist_ts_interfaces/requests.accounts.d.ts +5 -0
- package/dist_ts_interfaces/requests.accounts.js +3 -1
- package/docs/authswitch.md +5 -4
- package/package.json +2 -2
- package/readme.md +49 -21
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/interfaces.ts +1 -0
- package/ts/classes.authstore.ts +4 -1
- package/ts/classes.claudeharness.ts +3 -2
- package/ts/classes.codexclientadapter.ts +11 -5
- package/ts/classes.controller.ts +177 -73
- package/ts/classes.inferencegateway.ts +15 -1
- package/ts/classes.inferencerouter.ts +72 -13
- package/ts/classes.mcpclient.ts +14 -5
- package/ts/classes.mcptools.ts +1 -0
- package/ts/classes.opencodeclient.ts +23 -3
- package/ts/driver/functions.driverinstructions.ts +1 -0
- package/ts/fleet/classes.claudeworkers.ts +12 -7
- package/ts/fleet/classes.deploymodels.ts +113 -1
- package/ts/fleet/classes.deploymonitor.ts +565 -179
- package/ts/fleet/classes.gitfacts.ts +10 -8
- package/ts/fleet/classes.service.ts +7 -1
- package/ts/fleet/functions.deployprobes.ts +16 -1
- package/ts/fleet/functions.deploystatus.ts +56 -0
- package/ts/fleet/functions.deployvalidation.ts +4 -1
- package/ts/functions.claudecoderelease.ts +1 -1
- package/ts/functions.deploycli.ts +2 -1
- package/ts/functions.deviceapi.ts +19 -9
- package/ts/functions.inferencecli.ts +7 -1
- package/ts/functions.inferencelaunch.ts +35 -14
- package/ts/functions.mcpdeploytools.ts +2 -0
- package/ts/functions.promptreply.ts +20 -0
- package/ts/functions.proxyharnessconfig.ts +32 -0
- package/ts_authswitch/authority-renewal.ts +14 -4
- package/ts_authswitch/classes.claudenative.ts +12 -12
- package/ts_authswitch/native-contracts.md +250 -28
- package/ts_interfaces/deployments.ts +39 -6
- package/ts_interfaces/devices.schema.json +1 -1
- package/ts_interfaces/devices.ts +2 -1
- package/ts_interfaces/inbox.ts +8 -1
- package/ts_interfaces/requests.accounts.ts +2 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/classes.accountsreadmodel.ts +19 -7
- package/ts_web/elements.accounts.ts +31 -18
- package/ts_web/elements.deployments.ts +20 -4
- package/ts_web/elements.harnesscontrollerapp.ts +43 -13
- package/ts_web/elements.inbox.ts +3 -3
|
@@ -315,17 +315,50 @@ interface ICooldown {
|
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
* The longest `Retry-After` that names a rate limit, which no usage reading shows: five minutes. A longer one names a
|
|
319
|
+
* usage window, which the account service reads and the owner can reset (AGL-1797).
|
|
320
|
+
*/
|
|
321
|
+
const rateLimitRestMs = 300_000;
|
|
322
|
+
|
|
323
|
+
/** Whether the provider's `Retry-After` named a rate limit's short rest, which runs its course whatever a reading says. */
|
|
324
|
+
const rateLimitRest = (cooldownArg: ICooldown): boolean =>
|
|
325
|
+
cooldownArg.explicit && cooldownArg.until - cooldownArg.at <= rateLimitRestMs;
|
|
326
|
+
|
|
327
|
+
/** Whether the account service holds a usage read made after the 429 the cool-down is from. */
|
|
328
|
+
const readSince = (cooldownArg: ICooldown,
|
|
329
|
+
usageArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined): boolean => {
|
|
330
|
+
const readAt = usageArg?.readAt ? Date.parse(usageArg.readAt) : Number.NaN;
|
|
331
|
+
return Number.isFinite(readAt) && readAt > cooldownArg.at;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* When an account's cool-down ends, judged against its held usage: a short one the provider's `Retry-After` named (a
|
|
336
|
+
* rate limit, at most five minutes) runs its course; a default one, and one whose `Retry-After` named a usage window's
|
|
337
|
+
* wait, ends once the account service holds a usage read made after the 429, which then decides -- an exhausted window
|
|
338
|
+
* until its reset, as the shared rule says, and an account whose limit was reset or raised meanwhile routes at once
|
|
339
|
+
* (AGL-1797). While that read is pending the cool-down holds, so sessions still move. Without a reading to judge
|
|
340
|
+
* (an API key) every cool-down runs its course.
|
|
322
341
|
*/
|
|
323
342
|
const cooldownUntil = (cooldownArg: ICooldown | undefined,
|
|
324
343
|
usageArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined): number => {
|
|
325
344
|
if (!cooldownArg) return 0;
|
|
326
|
-
if (cooldownArg
|
|
327
|
-
|
|
328
|
-
|
|
345
|
+
if (rateLimitRest(cooldownArg)) return cooldownArg.until;
|
|
346
|
+
return readSince(cooldownArg, usageArg) ? 0 : cooldownArg.until;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* When one model's rest on a Claude sign-in ends (AGL-1797). A 429 whose `Retry-After` names a usage window's wait may be
|
|
351
|
+
* a feature window's (one model family's weekly use), which the account's limit leaves out as the reading does not say
|
|
352
|
+
* which models it covers: so it rests only the model that met it, and the account's other models keep routing. It ends
|
|
353
|
+
* once a usage read made after the 429 shows no feature window used up -- a reset limit routes at once -- and else at
|
|
354
|
+
* its stated time. An account window used up is the reading's to say, for every model.
|
|
355
|
+
*/
|
|
356
|
+
const modelCooldownUntil = (cooldownArg: ICooldown | undefined,
|
|
357
|
+
usageArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined): number => {
|
|
358
|
+
if (!cooldownArg) return 0;
|
|
359
|
+
if (!readSince(cooldownArg, usageArg)) return cooldownArg.until;
|
|
360
|
+
const windows = usageArg?.reading?.kind === 'anthropic' ? usageArg.reading.status.windows ?? [] : [];
|
|
361
|
+
return windows.some((windowArg) => windowArg.scope === 'feature' && (windowArg.usedPercent ?? 0) >= 100) ? cooldownArg.until : 0;
|
|
329
362
|
};
|
|
330
363
|
|
|
331
364
|
/**
|
|
@@ -959,6 +992,8 @@ export class InferenceRouter {
|
|
|
959
992
|
private readonly noted = new Map<string, { unavailable: IInferenceAccountUnavailable; lastCatalog: boolean }>();
|
|
960
993
|
private readonly active = new Map<string, number>();
|
|
961
994
|
private readonly cooldowns = new Map<string, ICooldown>();
|
|
995
|
+
/** Each Claude sign-in's models resting after a 429 that named a usage window's wait (`modelCooldownUntil`). */
|
|
996
|
+
private readonly modelCooldowns = new Map<string, Map<string, ICooldown>>();
|
|
962
997
|
/**
|
|
963
998
|
* The accounts a payment problem took out of rotation (`reportPaymentProblem`): a Claude account until the account
|
|
964
999
|
* service holds the problem -- one it could not be told of stays here for the proxy's lifetime -- and an API key until
|
|
@@ -1020,6 +1055,7 @@ export class InferenceRouter {
|
|
|
1020
1055
|
for (const cacheKey of cache.keys()) if (!known.has(cacheKey.slice(0, 64))) cache.delete(cacheKey);
|
|
1021
1056
|
}
|
|
1022
1057
|
for (const id of this.cooldowns.keys()) if (!known.has(id)) this.cooldowns.delete(id);
|
|
1058
|
+
for (const id of this.modelCooldowns.keys()) if (!known.has(id)) this.modelCooldowns.delete(id);
|
|
1023
1059
|
for (const id of this.noted.keys()) if (!known.has(id)) this.noted.delete(id);
|
|
1024
1060
|
return { accounts, eligible: new Set(allAccounts.map((account) => account.id)), lapsed, tiers };
|
|
1025
1061
|
}
|
|
@@ -1678,7 +1714,8 @@ export class InferenceRouter {
|
|
|
1678
1714
|
this.noteAccount(accountArg.id, null);
|
|
1679
1715
|
}
|
|
1680
1716
|
if (optionsArg.plans && !optionsArg.plans.includes(limitsArg.plan)) return undefined;
|
|
1681
|
-
const cooldown = cooldownUntil(this.cooldowns.get(accountArg.id), apiKey ? undefined : usageArg)
|
|
1717
|
+
const cooldown = Math.max(cooldownUntil(this.cooldowns.get(accountArg.id), apiKey ? undefined : usageArg),
|
|
1718
|
+
modelCooldownUntil(this.modelCooldowns.get(accountArg.id)?.get(optionsArg.modelId), usageArg));
|
|
1682
1719
|
if (!optionsArg.ignoreLimits && (limitsArg.state !== 'available' || cooldown > this.now())) {
|
|
1683
1720
|
const held = this.heldList(optionsArg.lists, accountArg);
|
|
1684
1721
|
if (held && !held.some((entry) => entry.modelId === optionsArg.modelId)) return refused({ reason: 'model_missing' });
|
|
@@ -1998,8 +2035,8 @@ export class InferenceRouter {
|
|
|
1998
2035
|
: state === 'cooling' ? 'cooling down after a provider 429'
|
|
1999
2036
|
: state === 'unavailable' && refusal ? `unavailable (${unavailableText(refusal)})`
|
|
2000
2037
|
: apiKey ? keyStateText(limits, held, now)
|
|
2001
|
-
: limits.limit ? plugins.authswitchUsageLimit.authSwitchUsageLimitText(limits.limit)
|
|
2002
|
-
: 'available (no usage reported)',
|
|
2038
|
+
: `${limits.limit ? plugins.authswitchUsageLimit.authSwitchUsageLimitText(limits.limit)
|
|
2039
|
+
: 'available (no usage reported)'}${this.modelRestText(account.id, held, now)}`,
|
|
2003
2040
|
plan: limits.plan || null, headroom: limits.limit?.headroom ?? null, crossing: limits.limit?.crossing ?? [],
|
|
2004
2041
|
resetAt: state === 'cooling' ? new Date(cooldown).toISOString() : limits.limit?.resetAt ?? null };
|
|
2005
2042
|
});
|
|
@@ -2027,7 +2064,18 @@ export class InferenceRouter {
|
|
|
2027
2064
|
usageArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined): { lastAt: number | null; restUntil: number } {
|
|
2028
2065
|
const cooldown = this.cooldowns.get(accountArg.id);
|
|
2029
2066
|
const until = cooldownUntil(cooldown, accountArg.credential === 'api_key' ? undefined : usageArg);
|
|
2030
|
-
|
|
2067
|
+
// One model's rest leaves the account's room for other work, so it counts as a 429 the pool met, never as a rest.
|
|
2068
|
+
const lastAt = Math.max(cooldown?.at ?? 0, ...[...this.modelCooldowns.get(accountArg.id)?.values() ?? []].map((rest) => rest.at));
|
|
2069
|
+
return { lastAt: lastAt || null, restUntil: until > this.now() ? until : 0 };
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
/** The models of an account that rest now after a provider 429, as `agl proxy status` adds them to its state. */
|
|
2073
|
+
private modelRestText(accountIdArg: string, usageArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined,
|
|
2074
|
+
nowArg: number): string {
|
|
2075
|
+
const resting = [...this.modelCooldowns.get(accountIdArg) ?? []]
|
|
2076
|
+
.map(([modelId, rest]) => ({ modelId, until: modelCooldownUntil(rest, usageArg) }))
|
|
2077
|
+
.filter((rest) => rest.until > nowArg);
|
|
2078
|
+
return resting.map((rest) => `; ${rest.modelId} rests after a provider 429 until ${new Date(rest.until).toISOString()}`).join('');
|
|
2031
2079
|
}
|
|
2032
2080
|
|
|
2033
2081
|
/** Counts one request on an account until its release, which may be called more than once. */
|
|
@@ -2139,12 +2187,23 @@ export class InferenceRouter {
|
|
|
2139
2187
|
* seconds or until the account service holds a usage read made after the 429 (see `cooldownUntil`), which the 429
|
|
2140
2188
|
* asks it to make at once. An API key, whose spend reading says nothing of the provider's rate limits, cools down
|
|
2141
2189
|
* the 60 seconds.
|
|
2190
|
+
*
|
|
2191
|
+
* `claudeModelIdArg` names the model a Claude sign-in's request asked for. A `Retry-After` beyond five minutes then
|
|
2192
|
+
* rests that model alone (`modelCooldownUntil`): it may be the wait of one model family's weekly window, and the
|
|
2193
|
+
* account's other models keep routing (AGL-1797). A usage read after the 429 ends either rest when it shows room.
|
|
2142
2194
|
*/
|
|
2143
|
-
public reportQuota(accountIdArg: string, retryAfterSecondsArg?: number): void {
|
|
2195
|
+
public reportQuota(accountIdArg: string, retryAfterSecondsArg?: number, claudeModelIdArg?: string): void {
|
|
2144
2196
|
const explicit = Number.isFinite(retryAfterSecondsArg) && retryAfterSecondsArg! > 0;
|
|
2145
2197
|
const delay = explicit ? Math.min(retryAfterSecondsArg!, 86_400) : 60;
|
|
2146
2198
|
const now = this.now();
|
|
2147
|
-
|
|
2199
|
+
const cooldown: ICooldown = { until: now + delay * 1000, at: now, explicit };
|
|
2200
|
+
if (claudeModelIdArg !== undefined && explicit && !rateLimitRest(cooldown) && !this.apiKeyAccounts.has(accountIdArg)) {
|
|
2201
|
+
const models = this.modelCooldowns.get(accountIdArg) ?? new Map<string, ICooldown>();
|
|
2202
|
+
models.set(claudeModelIdArg, cooldown);
|
|
2203
|
+
this.modelCooldowns.set(accountIdArg, models);
|
|
2204
|
+
} else {
|
|
2205
|
+
this.cooldowns.set(accountIdArg, cooldown);
|
|
2206
|
+
}
|
|
2148
2207
|
if (!this.apiKeyAccounts.has(accountIdArg)) this.options.rateLimited?.(accountIdArg);
|
|
2149
2208
|
}
|
|
2150
2209
|
}
|
package/ts/classes.mcpclient.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { readTicketRevisionConflict, ticketErrorMessages, type TTicketClientErro
|
|
|
10
10
|
import { assertMcpTicketRequest, assertTicketResponse } from './functions.ticketvalidation.js';
|
|
11
11
|
import { assertSessionFeedWireRequest, assertSessionFeedWireResponse } from './functions.sessionfeedvalidation.js';
|
|
12
12
|
import { assertFleetDeployResponse, assertFleetDeployWireRequest } from './fleet/functions.deployvalidation.js';
|
|
13
|
-
import type
|
|
13
|
+
import { fleetDeployRefreshClientMarginMs, fleetDeployRefreshWaitMs, type IFleetDeployOperations, type TFleetDeployOperation } from '../ts_interfaces/deployments.js';
|
|
14
14
|
import type { IReq_ControllerMcpSessionFeedAcknowledge, IReq_ControllerMcpSessionFeedList } from '../ts_interfaces/sessionfeed.js';
|
|
15
15
|
import { isProxyCapacityAnswer, type IProxyCapacityAnswer, type IProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
16
16
|
import {
|
|
@@ -83,6 +83,8 @@ import {
|
|
|
83
83
|
} from './functions.jobvalidation.js';
|
|
84
84
|
|
|
85
85
|
const defaultRequestTimeoutMs = 30_000;
|
|
86
|
+
/** A deploy `refresh` waits for its check up to `fleetDeployRefreshWaitMs` on the controller before it answers. */
|
|
87
|
+
const deployRefreshRequestTimeoutMs = fleetDeployRefreshWaitMs + fleetDeployRefreshClientMarginMs;
|
|
86
88
|
const maximumSafeServerErrorBytes = 1024;
|
|
87
89
|
const maximumScratchpadCharacters = 32_768;
|
|
88
90
|
const maximumScratchpadBytes = 128 * 1024;
|
|
@@ -778,13 +780,15 @@ export class ControllerMcpClient {
|
|
|
778
780
|
const wireRequest = assertSessionFeedWireRequest('agl.mcp.sessionfeed.acknowledge', request);
|
|
779
781
|
return this.dispatchAfterHandshake('agl.mcp.sessionfeed.acknowledge', wireRequest as IReq_ControllerMcpSessionFeedAcknowledge['request'], signal, true);
|
|
780
782
|
}
|
|
781
|
-
/** Deploy status, history, a probe now
|
|
783
|
+
/** Deploy status, history, a probe now, release state or a full check now, as the local owner asks (`agl deploy`, `agl release status`, MCP). */
|
|
782
784
|
public async deploy<TOperation extends TFleetDeployOperation>(operation: TOperation,
|
|
783
785
|
request: IFleetDeployOperations[TOperation]['request'] & { ownerToken: string }, signal?: AbortSignal,
|
|
784
786
|
): Promise<IFleetDeployOperations[TOperation]['response']> {
|
|
785
787
|
const method = `agl.mcp.deploy.${operation}` as const;
|
|
786
788
|
const wireRequest = assertFleetDeployWireRequest(method, request);
|
|
787
|
-
return this.dispatchAfterHandshake(method, wireRequest as never, signal, operation === 'probe'
|
|
789
|
+
return this.dispatchAfterHandshake(method, wireRequest as never, signal, operation === 'probe' || operation === 'refresh',
|
|
790
|
+
operation === 'refresh' ? Math.max(this.requestTimeoutMs, deployRefreshRequestTimeoutMs) : undefined,
|
|
791
|
+
) as Promise<IFleetDeployOperations[TOperation]['response']>;
|
|
788
792
|
}
|
|
789
793
|
public async fleetStatus(id: string, ownerToken: string, signal?: AbortSignal, ticketKey?: string): Promise<IFleetOperation> {
|
|
790
794
|
return this.dispatchAfterHandshake('agl.mcp.fleet.status', { id, ownerToken, ...(ticketKey ? { ticketKey } : {}) }, signal, false);
|
|
@@ -818,10 +822,12 @@ export class ControllerMcpClient {
|
|
|
818
822
|
requestArg: TRequestForMethod<TMethod>,
|
|
819
823
|
signalArg: AbortSignal | undefined,
|
|
820
824
|
mutatingArg: boolean,
|
|
825
|
+
/** This request's own deadline, for one the controller answers only after a bounded wait; the client's otherwise. */
|
|
826
|
+
timeoutMsArg?: number,
|
|
821
827
|
): Promise<TResponseForMethod<TMethod>> {
|
|
822
828
|
const descriptor = await this.handshake(signalArg);
|
|
823
829
|
try {
|
|
824
|
-
return await this.dispatch(descriptor, methodArg, requestArg, signalArg, mutatingArg);
|
|
830
|
+
return await this.dispatch(descriptor, methodArg, requestArg, signalArg, mutatingArg, timeoutMsArg);
|
|
825
831
|
} catch (errorArg) {
|
|
826
832
|
if (mutatingArg && errorArg instanceof ControllerMcpClientError
|
|
827
833
|
&& (errorArg.code === 'PROTOCOL_MISMATCH' || errorArg.code === 'RESPONSE_LIMIT')) {
|
|
@@ -906,6 +912,7 @@ export class ControllerMcpClient {
|
|
|
906
912
|
requestArg: TRequestForMethod<TMethod>,
|
|
907
913
|
signalArg: AbortSignal | undefined,
|
|
908
914
|
outcomeMayBeUnknownArg: boolean,
|
|
915
|
+
timeoutMsArg?: number,
|
|
909
916
|
): Promise<TResponseForMethod<TMethod>> {
|
|
910
917
|
const requestInstanceId = plugins.crypto.randomBytes(16).toString('base64url');
|
|
911
918
|
const correlationId = plugins.crypto.randomBytes(16).toString('base64url');
|
|
@@ -931,6 +938,7 @@ export class ControllerMcpClient {
|
|
|
931
938
|
body,
|
|
932
939
|
signalArg,
|
|
933
940
|
() => { dispatchFinished = true; },
|
|
941
|
+
timeoutMsArg,
|
|
934
942
|
);
|
|
935
943
|
} catch (errorArg) {
|
|
936
944
|
if (errorArg instanceof ControllerMcpClientError) throw errorArg;
|
|
@@ -1044,8 +1052,9 @@ export class ControllerMcpClient {
|
|
|
1044
1052
|
bodyArg: Buffer,
|
|
1045
1053
|
signalArg: AbortSignal | undefined,
|
|
1046
1054
|
onDispatchFinishedArg: () => void,
|
|
1055
|
+
timeoutMsArg = this.requestTimeoutMs,
|
|
1047
1056
|
): Promise<Buffer> {
|
|
1048
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
1057
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMsArg);
|
|
1049
1058
|
const signal = signalArg === undefined
|
|
1050
1059
|
? timeoutSignal
|
|
1051
1060
|
: AbortSignal.any([signalArg, timeoutSignal]);
|
package/ts/classes.mcptools.ts
CHANGED
|
@@ -44,6 +44,7 @@ import type {
|
|
|
44
44
|
TOpenCodeSdkClient,
|
|
45
45
|
} from './interfaces.opencode.js';
|
|
46
46
|
import { boundLiveToolExecution } from './functions.livetoolbounding.js';
|
|
47
|
+
import { promptNoLongerPending } from './functions.promptreply.js';
|
|
47
48
|
import {
|
|
48
49
|
openCodeSessionIdentitySnapshotCapability,
|
|
49
50
|
openCodeSessionProviderGeneration,
|
|
@@ -140,6 +141,19 @@ const isOpenCodeNotFoundError = (valueArg: unknown): boolean => {
|
|
|
140
141
|
&& isOpenCodeNotFoundBody(valueArg.cause.body);
|
|
141
142
|
};
|
|
142
143
|
|
|
144
|
+
/**
|
|
145
|
+
* OpenCode's refusal of an answer to a permission or question it no longer holds (answered or withdrawn meanwhile): a
|
|
146
|
+
* 404 with its `PermissionNotFoundError` or `QuestionNotFoundError`, before it applies anything.
|
|
147
|
+
*/
|
|
148
|
+
const isOpenCodePromptNotFoundError = (
|
|
149
|
+
valueArg: unknown,
|
|
150
|
+
tagArg: 'PermissionNotFoundError' | 'QuestionNotFoundError',
|
|
151
|
+
): boolean => isRecord(valueArg)
|
|
152
|
+
&& isRecord(valueArg.cause)
|
|
153
|
+
&& valueArg.cause.status === 404
|
|
154
|
+
&& isRecord(valueArg.cause.body)
|
|
155
|
+
&& valueArg.cause.body._tag === tagArg;
|
|
156
|
+
|
|
143
157
|
const hasExactKeys = (
|
|
144
158
|
valueArg: Record<string, unknown>,
|
|
145
159
|
requiredArg: readonly string[],
|
|
@@ -3312,7 +3326,9 @@ export class OpenCodeClientAdapter implements IOpenCodeSessionIdentitySnapshotCa
|
|
|
3312
3326
|
},
|
|
3313
3327
|
{ signal: requestSignal }
|
|
3314
3328
|
)
|
|
3315
|
-
)
|
|
3329
|
+
).catch((errorArg: unknown) => {
|
|
3330
|
+
throw isOpenCodePromptNotFoundError(errorArg, 'QuestionNotFoundError') ? promptNoLongerPending('question') : errorArg;
|
|
3331
|
+
});
|
|
3316
3332
|
if (typeof response !== 'boolean') {
|
|
3317
3333
|
throw new Error('OpenCode returned an invalid question result.');
|
|
3318
3334
|
}
|
|
@@ -3333,7 +3349,9 @@ export class OpenCodeClientAdapter implements IOpenCodeSessionIdentitySnapshotCa
|
|
|
3333
3349
|
},
|
|
3334
3350
|
{ signal: requestSignal }
|
|
3335
3351
|
)
|
|
3336
|
-
)
|
|
3352
|
+
).catch((errorArg: unknown) => {
|
|
3353
|
+
throw isOpenCodePromptNotFoundError(errorArg, 'QuestionNotFoundError') ? promptNoLongerPending('question') : errorArg;
|
|
3354
|
+
});
|
|
3337
3355
|
if (typeof response !== 'boolean') {
|
|
3338
3356
|
throw new Error('OpenCode returned an invalid question result.');
|
|
3339
3357
|
}
|
|
@@ -3365,7 +3383,9 @@ export class OpenCodeClientAdapter implements IOpenCodeSessionIdentitySnapshotCa
|
|
|
3365
3383
|
},
|
|
3366
3384
|
{ signal: requestSignal }
|
|
3367
3385
|
)
|
|
3368
|
-
)
|
|
3386
|
+
).catch((errorArg: unknown) => {
|
|
3387
|
+
throw isOpenCodePromptNotFoundError(errorArg, 'PermissionNotFoundError') ? promptNoLongerPending('permission') : errorArg;
|
|
3388
|
+
});
|
|
3369
3389
|
if (typeof response !== 'boolean') {
|
|
3370
3390
|
throw new Error('OpenCode returned an invalid permission result.');
|
|
3371
3391
|
}
|
|
@@ -40,6 +40,7 @@ You keep the owner's board true and the work moving. The owner talks to you thro
|
|
|
40
40
|
|
|
41
41
|
## Deployments
|
|
42
42
|
- What runs where is deploy_status, never your notes or memory. release_status says what a repository's next release would ship.
|
|
43
|
+
- deploy_status answers the status AGL checked last (its checkedAt); AGL checks every five minutes. Call deploy_refresh to check now when the answer must be current: after a release or land of your own the board should show at once, when the owner asks about deployments, or when checkedAt looks stale. It waits up to a minute; refreshing means the check runs on.
|
|
43
44
|
- Every deploy needs the owner's word, given on a deploy plan: a ticket whose deployPlan names the target and the release. AGL asks the owner on it (deploy now, in the next window, or hold) and closes the ticket once the target runs the release. The board pump plans one for a target that runs behind a release out for a day; you may plan one yourself (ticket_create or ticket_update deployPlan). Never deploy what waits for the owner's answer or is held.
|
|
44
45
|
- A plan assigned to a direct report is that report's subject: it deploys, and the owner's answer reaches it; route the pump's notices about it to that report. An unassigned plan is yours to deploy.
|
|
45
46
|
- When a deploy may run is the target's (deploy_status deployWhen): any time; only inside a maintenance window planned for it; or, for the AGL controller, when no session is busy. "Deploy now" is the owner's word to deploy at once, outside a window too. "In the next window" waits for the target's next window the owner gave: propose one when none is (a ticket with a maintenanceWindow: from, to, targets), which asks the owner and counts once approved. Only the owner answers a deploy plan's or a window's question. The controller is deployed with agl upgrade, which keeps its own owner gate.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
2
|
import { resolveControllerTerminalAgentTranscript } from '../functions.terminalagents.js';
|
|
3
3
|
import { fleetWorkerPath, resolveClaudeWorkerExecutable } from '../functions.workerprocessproof.js';
|
|
4
|
+
import { dropClaudeHookSwitches } from '../functions.proxyharnessconfig.js';
|
|
4
5
|
import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorkerTurnOutcome, IFleetRelaunchBlocker, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof } from '../../ts_interfaces/fleetworkers.js';
|
|
5
6
|
import { controllerSessionFeedExcerpt, type IControllerMessageBundle, type IControllerNativeWait } from '../../ts_interfaces/index.js';
|
|
6
7
|
import { claudePage, claudeTranscript } from '../classes.claudeprojection.js';
|
|
@@ -53,8 +54,8 @@ export const fleetClaudeVersion = (result: IFleetWorkerCommand): string => {
|
|
|
53
54
|
/** Claude colours its output when FORCE_COLOR is set, through a pipe too; its control sequences are no text. */
|
|
54
55
|
const plain = (text: string): string => text.replace(/\u001b\[[0-?]*[ -/]*[@-~]/gu, '');
|
|
55
56
|
/**
|
|
56
|
-
* The short id of the background job a `claude --bg` start or wake printed (AGL-796). Claude Code 2.1.282
|
|
57
|
-
* print `backgrounded · <id>`, then ` · <name>` only for a named job and ` (idle — …)` for one without a prompt, then
|
|
57
|
+
* The short id of the background job a `claude --bg` start or wake printed (AGL-796). Claude Code 2.1.282, 2.1.306 and
|
|
58
|
+
* 2.1.322 print `backgrounded · <id>`, then ` · <name>` only for a named job and ` (idle — …)` for one without a prompt, then
|
|
58
59
|
* the commands that reach the job, one per line.
|
|
59
60
|
*/
|
|
60
61
|
export const fleetClaudeBackgrounded = (result: IFleetWorkerCommand): string | undefined => /backgrounded\s*·\s*([a-zA-Z0-9]+)(?=\s|$)/u.exec(plain(`${result.stdout}\n${result.stderr}`))?.[1];
|
|
@@ -100,8 +101,8 @@ const claudeObservedTurn = (nativeId: string, agent: TClaudeAgent | undefined, r
|
|
|
100
101
|
return { ...turn, ...(outcome ? { outcome } : {}) };
|
|
101
102
|
};
|
|
102
103
|
/**
|
|
103
|
-
* The permission modes a Claude Code transcript records and `--permission-mode` takes: Claude Code 2.1.282
|
|
104
|
-
* know `acceptEdits`, `auto`, `bypassPermissions`, `default`, `dontAsk` and `plan`, and read `manual` as `default`
|
|
104
|
+
* The permission modes a Claude Code transcript records and `--permission-mode` takes: Claude Code 2.1.282, 2.1.306 and
|
|
105
|
+
* 2.1.322 know `acceptEdits`, `auto`, `bypassPermissions`, `default`, `dontAsk` and `plan`, and read `manual` as `default`
|
|
105
106
|
* (AGL-797).
|
|
106
107
|
*/
|
|
107
108
|
const modes = new Set(['acceptEdits', 'auto', 'bypassPermissions', 'default', 'dontAsk', 'manual', 'plan']);
|
|
@@ -115,8 +116,8 @@ const address = (inventory: TClaudeAgent[], agent: TClaudeAgent): string => {
|
|
|
115
116
|
};
|
|
116
117
|
|
|
117
118
|
/**
|
|
118
|
-
* Version-coupled transcript interpretation stays here. It was verified on Claude Code 2.1.306 and on 2.1.282,
|
|
119
|
-
* fleet's floor, whose output the tests still pin; a newer release is used optimistically and these parsers are its
|
|
119
|
+
* Version-coupled transcript interpretation stays here. It was verified on Claude Code 2.1.322, 2.1.306 and on 2.1.282,
|
|
120
|
+
* the fleet's floor, whose output the tests still pin; a newer release is used optimistically and these parsers are its
|
|
120
121
|
* checks at the point of use, failing visibly where its output changed. An older or unreadable version is refused
|
|
121
122
|
* (`fleetClaudeVersion`).
|
|
122
123
|
*/
|
|
@@ -297,9 +298,13 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
297
298
|
/** Told each release newer than the verified one that a verified executable runs, once per executable identity. */
|
|
298
299
|
private readonly observeRelease?: (releaseArg: string) => void,
|
|
299
300
|
) {}
|
|
300
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* Workers inherit this environment; their tooling finds the controller's own node even when a service manager started it.
|
|
303
|
+
* It holds no hook switch (`dropClaudeHookSwitches`), so the hooks of the profile's user settings run in every worker.
|
|
304
|
+
*/
|
|
301
305
|
private env(profile: Pick<IFleetWorkerProfile, 'home'>): NodeJS.ProcessEnv {
|
|
302
306
|
const env: NodeJS.ProcessEnv = { ...process.env, PATH: fleetWorkerPath() }; delete env.AGL_HOME; if (profile.home) env.CLAUDE_CONFIG_DIR = profile.home;
|
|
307
|
+
dropClaudeHookSwitches(env);
|
|
303
308
|
return env;
|
|
304
309
|
}
|
|
305
310
|
private async supportedExecutable(profile: Pick<IFleetWorkerProfile, 'home'>, cwd: string): Promise<string> {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
fleetDeployTargetIdPattern, type IFleetDeployObservation, type IFleetDeployPlan, type IFleetDeployStatusFailure, type IFleetDeployTargetStatus,
|
|
4
|
+
type IFleetDeployWindow, type IFleetRepositoryReleaseStatus,
|
|
5
|
+
} from '../../ts_interfaces/deployments.js';
|
|
6
|
+
import { ticketColumns } from '../../ts_interfaces/tickets.js';
|
|
3
7
|
|
|
4
8
|
const timestamp = plugins.z.iso.datetime();
|
|
5
9
|
const version = plugins.z.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u);
|
|
@@ -42,3 +46,111 @@ export class DeployObservationModel extends plugins.nosqldb.SmartDataDbDoc<Deplo
|
|
|
42
46
|
@plugins.nosqldb.svDb() public previousVersion?: string;
|
|
43
47
|
@plugins.nosqldb.svDb() public artifacts!: IFleetDeployObservation['artifacts'];
|
|
44
48
|
}
|
|
49
|
+
|
|
50
|
+
/** A maintenance window as stored: where it stands (scheduled, active, done) is derived from the clock when read. */
|
|
51
|
+
export type TDeployStoredWindow = Omit<IFleetDeployWindow, 'state'>;
|
|
52
|
+
/** A deploy plan as stored: the window it is queued into is derived from the clock when read. */
|
|
53
|
+
export type TDeployStoredPlan = Omit<IFleetDeployPlan, 'window'>;
|
|
54
|
+
/** A target's status as stored: whether a deploy may run now, the busy sessions and its windows are derived when read. */
|
|
55
|
+
export type TDeployStoredTarget = Omit<IFleetDeployTargetStatus, 'busySessions' | 'deployOpen' | 'windows' | 'deployPlans'> & {
|
|
56
|
+
deployPlans: TDeployStoredPlan[];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* What one computation of the deploy monitor found (AGL-1704): every target's status, every maintenance window of a
|
|
60
|
+
* ticket that is not done, the release state of the repositories the targets, landed tickets and release plans name,
|
|
61
|
+
* and the tickets the `undeployed` AutoLabel marks. Nothing in it depends on the clock or on the sessions busy now.
|
|
62
|
+
*/
|
|
63
|
+
export type TDeployStatusContent = {
|
|
64
|
+
status: { targets: TDeployStoredTarget[]; windows: TDeployStoredWindow[] };
|
|
65
|
+
release: { repositories: IFleetRepositoryReleaseStatus[] };
|
|
66
|
+
undeployed: string[];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const label = plugins.z.string().max(1024);
|
|
70
|
+
const repoName = plugins.z.string().min(1).max(1024);
|
|
71
|
+
const ticketKey = plugins.z.string().min(1).max(64);
|
|
72
|
+
const deployTicketFields = { key: ticketKey, title: plugins.z.string().max(256), priority: plugins.z.enum(['none', 'low', 'normal', 'high', 'urgent']),
|
|
73
|
+
columnId: plugins.z.enum(ticketColumns), version: label.optional() };
|
|
74
|
+
const deployTicket = plugins.z.object(deployTicketFields).strict();
|
|
75
|
+
const release = plugins.z.object({ version: label, sha: plugins.z.string().regex(/^[a-f0-9]{7,64}$/u), taggedAt: timestamp.optional() }).strict();
|
|
76
|
+
const maintenanceWindow = plugins.z.object({ ...deployTicketFields, from: timestamp, to: timestamp, targets: plugins.z.array(targetId),
|
|
77
|
+
go: plugins.z.enum(['given', 'waiting', 'declined']), questionId: label.optional() }).strict();
|
|
78
|
+
const plan = plugins.z.object({ ...deployTicketFields, target: targetId, version: label, questionId: label,
|
|
79
|
+
go: plugins.z.enum(['waiting', 'now', 'window', 'idle', 'hold']), answeredAt: timestamp.optional(), assignee: label.optional() }).strict();
|
|
80
|
+
const releasePlanTicket = plugins.z.object({ ...deployTicketFields, plannedVersion: label.optional() }).strict();
|
|
81
|
+
const target = plugins.z.object({
|
|
82
|
+
id: targetId, name: label.optional(), environment: label.optional(), repo: repoName, project: label, deploys: label.optional(), downtime: label.optional(),
|
|
83
|
+
deployWhen: plugins.z.enum(['anytime', 'window']).optional(), builtIn: plugins.z.literal(true).optional(),
|
|
84
|
+
probe: plugins.z.discriminatedUnion('kind', [
|
|
85
|
+
plugins.z.object({ kind: plugins.z.literal('controller') }).strict(),
|
|
86
|
+
plugins.z.object({ kind: plugins.z.literal('http'), url: plugins.z.string().max(2048), versionPointer: label.optional(), shaPointer: label.optional() }).strict(),
|
|
87
|
+
]),
|
|
88
|
+
}).strict();
|
|
89
|
+
const storedTarget = plugins.z.object({
|
|
90
|
+
target, repository: repoName.optional(),
|
|
91
|
+
running: plugins.z.object({ version: label, sha: plugins.z.string().regex(/^[a-f0-9]{7,64}$/u).optional(), since: timestamp, previousVersion: label.optional(),
|
|
92
|
+
rolledBack: plugins.z.literal(true).optional(), untagged: plugins.z.literal(true).optional() }).strict().optional(),
|
|
93
|
+
probe: plugins.z.object({ state: plugins.z.enum(['up', 'down', 'unknown']), checkedAt: timestamp.optional(), downSince: timestamp.optional(),
|
|
94
|
+
error: plugins.z.string().max(2048).optional() }).strict(),
|
|
95
|
+
latest: release.optional(),
|
|
96
|
+
notRunning: plugins.z.object({ releases: plugins.z.array(release), tickets: plugins.z.array(deployTicket) }).strict(),
|
|
97
|
+
landedAfterLatest: plugins.z.array(deployTicket),
|
|
98
|
+
openBugs: plugins.z.array(plugins.z.object({ ...deployTicketFields, foundIn: label, fixLandedSha: plugins.z.string().regex(/^[a-f0-9]{7,64}$/u).optional(),
|
|
99
|
+
fixedIn: label.optional() }).strict()),
|
|
100
|
+
plans: plugins.z.array(releasePlanTicket),
|
|
101
|
+
deployWhen: plugins.z.enum(['anytime', 'window', 'idle']),
|
|
102
|
+
deployPlans: plugins.z.array(plan),
|
|
103
|
+
}).strict();
|
|
104
|
+
/**
|
|
105
|
+
* The content of the stored deploy status, parsed as it is loaded. Content this release cannot parse (another release
|
|
106
|
+
* wrote it, or it is damaged) is not served: the controller starts cold and its next computation overwrites it.
|
|
107
|
+
*/
|
|
108
|
+
export const deployStatusContentSchema: plugins.z.ZodType<TDeployStatusContent> = plugins.z.object({
|
|
109
|
+
status: plugins.z.object({ targets: plugins.z.array(storedTarget), windows: plugins.z.array(maintenanceWindow) }).strict(),
|
|
110
|
+
release: plugins.z.object({ repositories: plugins.z.array(plugins.z.object({ repo: repoName, id: label, latest: release.optional(),
|
|
111
|
+
plans: plugins.z.array(releasePlanTicket), landedAfterLatest: plugins.z.array(deployTicket), targets: plugins.z.array(targetId) }).strict()) }).strict(),
|
|
112
|
+
undeployed: plugins.z.array(ticketKey),
|
|
113
|
+
}).strict();
|
|
114
|
+
/** The last computation that failed, as stored beside the content it left standing. */
|
|
115
|
+
export const deployStatusFailureSchema: plugins.z.ZodType<IFleetDeployStatusFailure> = plugins.z.object({
|
|
116
|
+
at: timestamp, message: plugins.z.string().min(1).max(2048), reference: plugins.z.string().min(1).max(128),
|
|
117
|
+
}).strict();
|
|
118
|
+
|
|
119
|
+
/** The one stored deploy status of a controller: `<controllerId>:deployments`. */
|
|
120
|
+
export const deployStatusId = (controllerIdArg: string): string => `${controllerIdArg}:deployments`;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The stored deploy status (AGL-1704): one document per controller, which the deploy monitor writes after each
|
|
124
|
+
* computation and serves every read from. Its top level is fixed for good, since the exact client refuses a stored
|
|
125
|
+
* top-level field its model does not declare: `revision` moves when the content changes, `computedAt` is when the
|
|
126
|
+
* content was last computed (at least once per pass), and `failure` is the last computation that failed while the
|
|
127
|
+
* content stands. `content` and `failure` are plain objects here and parsed by the monitor as it loads them, so a
|
|
128
|
+
* document another release wrote is still read, and overwritten, by this one.
|
|
129
|
+
*/
|
|
130
|
+
export interface IDeployStatusDocument {
|
|
131
|
+
id: string;
|
|
132
|
+
controllerId: string;
|
|
133
|
+
revision: number;
|
|
134
|
+
computedAt: string;
|
|
135
|
+
content: Record<string, unknown>;
|
|
136
|
+
failure?: Record<string, unknown>;
|
|
137
|
+
}
|
|
138
|
+
const statusDocumentSchema = plugins.z.object({
|
|
139
|
+
id: plugins.z.string().min(1).max(512), controllerId: plugins.z.string().min(1).max(256), revision: plugins.z.number().int().nonnegative(),
|
|
140
|
+
computedAt: timestamp, content: plugins.z.record(plugins.z.string(), plugins.z.unknown()), failure: plugins.z.record(plugins.z.string(), plugins.z.unknown()).optional(),
|
|
141
|
+
}).strict();
|
|
142
|
+
|
|
143
|
+
@plugins.nosqldb.managed({ collectionName: 'agl_fleet_deploy_status' })
|
|
144
|
+
@plugins.nosqldb.exactPersistence({ assertDocument: (input: unknown) => {
|
|
145
|
+
const doc = statusDocumentSchema.parse(input);
|
|
146
|
+
if (doc.id !== deployStatusId(doc.controllerId)) throw new Error('Deploy status identity mismatch.');
|
|
147
|
+
} })
|
|
148
|
+
export class DeployStatusModel extends plugins.nosqldb.SmartDataDbDoc<DeployStatusModel, IDeployStatusDocument> {
|
|
149
|
+
declare static exact: plugins.nosqldb.TExact<DeployStatusModel>;
|
|
150
|
+
@plugins.nosqldb.unI() public id!: string;
|
|
151
|
+
@plugins.nosqldb.svDb() public controllerId!: string;
|
|
152
|
+
@plugins.nosqldb.svDb() public revision!: number;
|
|
153
|
+
@plugins.nosqldb.svDb() public computedAt!: string;
|
|
154
|
+
@plugins.nosqldb.svDb() public content!: Record<string, unknown>;
|
|
155
|
+
@plugins.nosqldb.svDb() public failure?: Record<string, unknown>;
|
|
156
|
+
}
|