agl 43.3.0 → 43.3.2
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 +19 -0
- package/dist_serve/bundle.js +2 -2
- package/dist_serve/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.authstore.d.ts +7 -0
- package/dist_ts/classes.authstore.js +9 -1
- package/dist_ts/classes.claudeharness.d.ts +13 -2
- package/dist_ts/classes.claudeharness.js +12 -5
- package/dist_ts/classes.controller.d.ts +38 -10
- package/dist_ts/classes.controller.js +160 -91
- package/dist_ts/classes.flexservice.d.ts +12 -1
- package/dist_ts/classes.flexservice.js +44 -13
- package/dist_ts/classes.flexstore.d.ts +20 -0
- package/dist_ts/classes.flexstore.js +30 -1
- package/dist_ts/classes.mcpcontrollerhost.js +4 -1
- package/dist_ts/classes.mcptools.js +6 -1
- package/dist_ts/classes.nativesessions.d.ts +12 -0
- package/dist_ts/classes.nativesessions.js +1 -1
- package/dist_ts/classes.workercallers.js +4 -2
- package/dist_ts/driver/classes.directreports.js +19 -19
- package/dist_ts/driver/classes.directreportstore.d.ts +8 -1
- package/dist_ts/driver/classes.directreportstore.js +20 -10
- package/dist_ts/fleet/classes.workers.d.ts +16 -0
- package/dist_ts/fleet/classes.workers.js +73 -39
- package/dist_ts/fleet/classes.workerstore.js +14 -8
- package/dist_ts/fleet/functions.workervalidation.js +10 -3
- package/dist_ts/fleet/interfaces.workers.d.ts +6 -2
- package/dist_ts/fleet/interfaces.workers.js +8 -4
- package/dist_ts/functions.deviceapi.d.ts +50 -3
- package/dist_ts/functions.deviceapi.js +174 -7
- package/dist_ts/functions.exactpersistence.d.ts +3 -0
- package/dist_ts/functions.exactpersistence.js +4 -0
- package/dist_ts/functions.mcpfleetworkertools.js +2 -2
- package/dist_ts/functions.ticketactor.d.ts +17 -1
- package/dist_ts/functions.ticketactor.js +55 -15
- package/dist_ts/interfaces.flexipc.d.ts +17 -9
- package/dist_ts/interfaces.flexipc.js +19 -20
- package/dist_ts_interfaces/devices.d.ts +17 -4
- package/dist_ts_interfaces/devices.js +1 -1
- package/dist_ts_interfaces/fleetworkers.d.ts +32 -7
- package/dist_ts_interfaces/fleetworkers.js +19 -8
- package/dist_ts_interfaces/workercallers.d.ts +2 -0
- package/dist_ts_migration/classes.documentmigrationrunner.d.ts +14 -0
- package/dist_ts_migration/classes.documentmigrationrunner.js +20 -1
- package/dist_ts_migration/index.d.ts +1 -0
- package/dist_ts_migration/index.js +2 -1
- package/dist_ts_migration/v43_ticketactornames.d.ts +32 -0
- package/dist_ts_migration/v43_ticketactornames.js +236 -0
- package/package.json +5 -5
- package/readme.md +35 -4
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.authstore.ts +10 -0
- package/ts/classes.claudeharness.ts +18 -4
- package/ts/classes.controller.ts +169 -96
- package/ts/classes.flexservice.ts +57 -14
- package/ts/classes.flexstore.ts +40 -0
- package/ts/classes.mcpcontrollerhost.ts +3 -0
- package/ts/classes.mcptools.ts +5 -0
- package/ts/classes.nativesessions.ts +13 -0
- package/ts/classes.workercallers.ts +3 -1
- package/ts/driver/classes.directreports.ts +18 -18
- package/ts/driver/classes.directreportstore.ts +20 -9
- package/ts/fleet/classes.workers.ts +66 -39
- package/ts/fleet/classes.workerstore.ts +11 -7
- package/ts/fleet/functions.workervalidation.ts +7 -2
- package/ts/fleet/interfaces.workers.ts +6 -2
- package/ts/functions.deviceapi.ts +227 -6
- package/ts/functions.exactpersistence.ts +5 -0
- package/ts/functions.mcpfleetworkertools.ts +1 -1
- package/ts/functions.ticketactor.ts +58 -14
- package/ts/interfaces.flexipc.ts +43 -27
- package/ts_interfaces/devices.schema.json +5 -2
- package/ts_interfaces/devices.ts +20 -4
- package/ts_interfaces/fleetworkers.ts +33 -7
- package/ts_interfaces/workercallers.ts +2 -0
- package/ts_migration/classes.documentmigrationrunner.ts +21 -0
- package/ts_migration/index.ts +1 -0
- package/ts_migration/v43_ticketactornames.ts +225 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements.fleetworker.ts +4 -2
package/ts/classes.controller.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { flexMessageDeliveryProof, type TFlexDeliveryEvidence, type TFlexDeliver
|
|
|
2
2
|
import { FleetWorkers, fleetNativeSessionNames } from './fleet/classes.workers.js';
|
|
3
3
|
import { FleetTicketEffects } from './fleet/classes.ticketeffects.js';
|
|
4
4
|
import { FleetDispatchError, FleetWorkerError } from './fleet/interfaces.workers.js';
|
|
5
|
-
import
|
|
5
|
+
import { DirectReportError } from './driver/classes.directreportstore.js';
|
|
6
|
+
import type { IFleetWorkerJob, TFleetWorkerAction, TFleetWorkerRequest } from '../ts_interfaces/fleetworkers.js';
|
|
6
7
|
import { ControllerBrowserOperationAuthority } from './classes.browseroperationauthority.js';
|
|
7
8
|
import { ControllerWorkerCallers, type IWorkerCodexCallerOrigin } from './classes.workercallers.js';
|
|
8
9
|
import { WorkerCallerBindingStore } from './classes.workercallerbindings.js';
|
|
@@ -118,6 +119,7 @@ import {
|
|
|
118
119
|
assertDeviceDriverSendRequest,
|
|
119
120
|
assertDeviceDirectReportMessageRequest,
|
|
120
121
|
serveDeviceDriver,
|
|
122
|
+
deviceDirectReportJobRefusal,
|
|
121
123
|
deviceDirectReportMessageRefusal,
|
|
122
124
|
deviceHostAgl,
|
|
123
125
|
deviceHostDevice,
|
|
@@ -134,6 +136,7 @@ import {
|
|
|
134
136
|
deviceTicketDiscussion,
|
|
135
137
|
deviceTicketPlans,
|
|
136
138
|
deviceTicketRefusal,
|
|
139
|
+
deviceContractError,
|
|
137
140
|
readDeviceTicketPlacement,
|
|
138
141
|
type IDeviceTicketViewer,
|
|
139
142
|
} from './functions.deviceapi.js';
|
|
@@ -601,12 +604,12 @@ import { SessionFeed, SessionFeedAcknowledgementError, SessionFeedTranscripts, s
|
|
|
601
604
|
import { SessionFeedAcknowledgementStore } from './classes.sessionfeedacknowledgements.js';
|
|
602
605
|
import { HarnessReleaseNotices, type THarnessReleaseSource } from './classes.harnessreleases.js';
|
|
603
606
|
import { assertSessionFeedAcknowledgeRequest } from './functions.sessionfeedvalidation.js';
|
|
604
|
-
import { NativeSessions, nativeSessionReadOnlyMessages, type IResolvedNativeSession } from './classes.nativesessions.js';
|
|
607
|
+
import { NativeSessions, nativeSessionReadOnlyMessages, type INativeSessionFailedErrorData, type IResolvedNativeSession } from './classes.nativesessions.js';
|
|
605
608
|
import { claudeProfileForHome, fleetAdoptCommand, listUnboundDrivers } from './fleet/functions.unbounddrivers.js';
|
|
606
609
|
import type { IReq_ControllerSessionFeedAcknowledge, IReq_ControllerSessionFeedList } from '../ts_interfaces/sessionfeed.js';
|
|
607
610
|
import { UsageFeed, UsageFeedRefusal } from './classes.usagefeed.js';
|
|
608
611
|
import type { IReq_ControllerUsageUnwatch, IReq_ControllerUsageWatch, TControllerUsageDelta } from '../ts_interfaces/metrics.js';
|
|
609
|
-
import { ticketActorFromCaller } from './functions.ticketactor.js';
|
|
612
|
+
import { ticketActorFromCaller, ticketCallerSessionId } from './functions.ticketactor.js';
|
|
610
613
|
import { ticketOwnerActor, ticketOwnerPrincipalId, resolveTicketOwnerAssignment } from './functions.ticketowner.js';
|
|
611
614
|
import { assertTicketRequest, ticketInputSchemas } from './functions.ticketvalidation.js';
|
|
612
615
|
import { readTicketRevisionConflict, type ITicket, type ITicketActor, type ITicketBoard, type ITicketComment, type ITicketDetail, type TTicketOperation, type TTicketRequest, type TTicketResponse, type TTicketFleetEvent, type ITicketFleetEventResult } from '../ts_interfaces/tickets.js';
|
|
@@ -1097,7 +1100,6 @@ const maxOpenCodeOperationRecoveryFailures = 3;
|
|
|
1097
1100
|
const maxOpenCodeOperationRecoveryPages = 8;
|
|
1098
1101
|
const openCodeFailClosedRetryMs = 1_000;
|
|
1099
1102
|
const openCodeSessionErrorCleanupRetryMs = 1_000;
|
|
1100
|
-
const maxFlexSessionIdentitySnapshotEntries = 2_048;
|
|
1101
1103
|
const sessionIntelligenceOrphanGraceMs = 30 * 60 * 1000;
|
|
1102
1104
|
const sessionIntelligenceCleanupIntervalMs = 15 * 60 * 1000;
|
|
1103
1105
|
const sessionIntelligenceCleanupTimeoutMs = 15_000;
|
|
@@ -3015,6 +3017,70 @@ const asTypedResponseError = (
|
|
|
3015
3017
|
});
|
|
3016
3018
|
};
|
|
3017
3019
|
|
|
3020
|
+
/**
|
|
3021
|
+
* The device error translation of both device scopes: a failure as `asTypedResponseError` reduces it, in the device
|
|
3022
|
+
* contract (`deviceContractError`), so no device method ever answers a code outside `TDeviceRefusalCode`.
|
|
3023
|
+
*/
|
|
3024
|
+
const asDeviceResponseError = (
|
|
3025
|
+
errorArg: unknown,
|
|
3026
|
+
methodArg: string,
|
|
3027
|
+
): plugins.typedrequest.TypedResponseError => deviceContractError(asTypedResponseError(errorArg, methodArg), errorArg, methodArg);
|
|
3028
|
+
|
|
3029
|
+
/**
|
|
3030
|
+
* A direct report operation's failure as the Driver view and a device receive it, decided by the error's class, never
|
|
3031
|
+
* its text: the refusals AGL writes itself keep their message as `direct_report_failed` (`DirectReportError`, the
|
|
3032
|
+
* direct reports' and their store's own, `FleetWorkerError` and `FleetNativeTurnError`, the fleet's), with a failure
|
|
3033
|
+
* journal reference where they stand for a dependency's error (`cause`); every other error, whose message may be a
|
|
3034
|
+
* dependency's (a spawn error, a socket path, a fleet job's recorded failure), is the controller's one generic failure,
|
|
3035
|
+
* `controller_operation_failed`, whose response carries the reference under which the failure journal keeps the cause
|
|
3036
|
+
* and which a device receives as its own (`deviceDirectReportMessageRefusal`, `deviceContractError`).
|
|
3037
|
+
*/
|
|
3038
|
+
const directReportFailure = (errorArg: Error, operationArg: string): plugins.typedrequest.TypedResponseError => {
|
|
3039
|
+
if (errorArg instanceof DirectReportError || errorArg instanceof FleetWorkerError || errorArg instanceof FleetNativeTurnError) {
|
|
3040
|
+
const reference = errorArg.cause === undefined ? undefined : controllerFailureJournal.record({ operation: operationArg, cause: errorArg.cause });
|
|
3041
|
+
return new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 4096), {
|
|
3042
|
+
code: 'direct_report_failed', ...(reference === undefined ? {} : { reference }),
|
|
3043
|
+
});
|
|
3044
|
+
}
|
|
3045
|
+
const reference = controllerFailureJournal.record({ operation: operationArg, cause: errorArg });
|
|
3046
|
+
console.error(`${currentRuntimeName} direct report operation failed (${operationArg}, ref ${reference}):`, errorArg);
|
|
3047
|
+
return new plugins.typedrequest.TypedResponseError('The controller operation failed.', { code: controllerOperationFailedErrorCode, reference });
|
|
3048
|
+
};
|
|
3049
|
+
|
|
3050
|
+
/**
|
|
3051
|
+
* A direct report message's settled fleet job as the Driver view receives it, by the same rule: a failure the fleet
|
|
3052
|
+
* refused itself (`errorCode`) keeps its text; any other job error, which may be a dependency's output (a harness's
|
|
3053
|
+
* own text, a failed delivery), reads "The controller operation failed." with the failure journal's reference, under
|
|
3054
|
+
* which the journal keeps it. The job's `errorOutcome` stays: the Driver view shows a failure that may have delivered
|
|
3055
|
+
* the message as of unknown outcome, never as a message the report did not take. A device's view of the job is
|
|
3056
|
+
* `deviceDirectReportJobRefusal`'s.
|
|
3057
|
+
*/
|
|
3058
|
+
const directReportJobView = (jobArg: IFleetWorkerJob): IFleetWorkerJob => {
|
|
3059
|
+
if (jobArg.state !== 'failed' || jobArg.errorCode !== undefined) return jobArg;
|
|
3060
|
+
const cause = jobArg.error ?? 'The fleet job failed without an error.';
|
|
3061
|
+
const reference = controllerFailureJournal.record({ operation: 'directreport.message', cause });
|
|
3062
|
+
console.error(`${currentRuntimeName} direct report message failed in fleet job ${jobArg.id} (ref ${reference}):`, cause);
|
|
3063
|
+
return { ...jobArg, error: `The controller operation failed. (ref ${reference})` };
|
|
3064
|
+
};
|
|
3065
|
+
|
|
3066
|
+
/** The refusals of a native message's session, every one before its send: no such session, more than one, one it may not wake. */
|
|
3067
|
+
const fleetNativeMessageRefusals: ReadonlySet<string> = new Set(['session_not_found', 'ambiguous_session', 'session_read_only']);
|
|
3068
|
+
|
|
3069
|
+
/**
|
|
3070
|
+
* A failed fleet `native-message` in the fleet's terms, so its job's outcome says whether the message may have arrived
|
|
3071
|
+
* (`IFleetWorkerJob.errorOutcome`): a refusal that proves nothing reached the job, one of the send's own refusals of the
|
|
3072
|
+
* session (`fleetNativeMessageRefusals`, before the send and again under the session's lock) or a native send failure
|
|
3073
|
+
* that says `refused`, is a `FleetDispatchError` that sent nothing, with the same message; any other failure stays as
|
|
3074
|
+
* it is, an unknown outcome.
|
|
3075
|
+
*/
|
|
3076
|
+
export const fleetNativeMessageFailure = (errorArg: unknown): unknown => {
|
|
3077
|
+
if (!(errorArg instanceof plugins.typedrequest.TypedResponseError)) return errorArg;
|
|
3078
|
+
const errorData = errorArg.errorData as Readonly<Record<string, unknown>> | undefined;
|
|
3079
|
+
const refused = typeof errorData?.code === 'string' && fleetNativeMessageRefusals.has(errorData.code)
|
|
3080
|
+
|| errorData?.code === 'native_session_failed' && errorData.outcome === ('refused' satisfies INativeSessionFailedErrorData['outcome']);
|
|
3081
|
+
return refused ? new FleetDispatchError(errorArg.message, false, { cause: errorArg }) : errorArg;
|
|
3082
|
+
};
|
|
3083
|
+
|
|
3018
3084
|
const hashResumeToken = (tokenArg: string): string =>
|
|
3019
3085
|
plugins.crypto.createHash('sha256').update(tokenArg, 'utf8').digest('base64url');
|
|
3020
3086
|
|
|
@@ -3310,7 +3376,7 @@ export class OpenCodeController {
|
|
|
3310
3376
|
this.fleetWorkerLaunches = new FleetWorkerLaunches({ hooks: () => this.workerCallerHooks, overlays: resolveAGLHomePaths().fleetMcpConfigs });
|
|
3311
3377
|
}
|
|
3312
3378
|
this.fleetWorkers = new FleetWorkers({ sample: () => this.systemMetricsSampler.sample(), ticketEffects: this.requireFleetTicketEffects(), sessionBindings: directReports,
|
|
3313
|
-
nativeMessages: { send: (_owner, request, actor) => this.sendFleetNativeMessage(request, actor) },
|
|
3379
|
+
nativeMessages: { send: (_owner, request, actor) => this.sendFleetNativeMessage(request, actor).catch((errorArg: unknown) => { throw fleetNativeMessageFailure(errorArg); }) },
|
|
3314
3380
|
claudeReleases: (releaseArg) => this.observeClaudeRelease(releaseArg, 'fleet'),
|
|
3315
3381
|
// No controller event names a native thread; the Inbox reads the fleet connection's requests again.
|
|
3316
3382
|
onNativeCodexAttention: () => this.inbox?.nativeAttentionChanged('codex'),
|
|
@@ -3342,9 +3408,14 @@ export class OpenCodeController {
|
|
|
3342
3408
|
// The Driver view's owner relaunches unless a driver tool names its driver.
|
|
3343
3409
|
const { job } = await fleetWorkers.execute('adopt', request, configuration, owner, signal, actor ?? ticketOwnerActor(await this.requireAuthStore().getState()));
|
|
3344
3410
|
const settled = await fleetWorkers.settled(owner, job.id, signal);
|
|
3345
|
-
|
|
3411
|
+
// A refusal the fleet wrote itself keeps its text; any other error may be a dependency's output, so it is the
|
|
3412
|
+
// cause the failure journal keeps (`directReportFailure`).
|
|
3413
|
+
if (settled.state !== 'succeeded') {
|
|
3414
|
+
if (settled.errorCode !== undefined) throw new FleetWorkerError(settled.errorCode, settled.error ?? 'The relaunch failed.');
|
|
3415
|
+
throw new Error(settled.error ?? 'The relaunch failed.');
|
|
3416
|
+
}
|
|
3346
3417
|
const worker = (await fleetWorkers.views(owner)).find((view) => view.worker.name === request.name)?.worker;
|
|
3347
|
-
if (!worker?.nativeId) throw new
|
|
3418
|
+
if (!worker?.nativeId) throw new DirectReportError('The relaunched fleet worker is unavailable.');
|
|
3348
3419
|
return worker;
|
|
3349
3420
|
},
|
|
3350
3421
|
nativeSession: async (ref) => await this.nativeSessions.resolve(ref),
|
|
@@ -9590,7 +9661,7 @@ export class OpenCodeController {
|
|
|
9590
9661
|
): Promise<IControllerMcpNativeSessionDetail> {
|
|
9591
9662
|
return this.runAudited(
|
|
9592
9663
|
{ type: 'session.read', peerId: this.auditPeerId(principalArg, 'mcp'), sessionId: requestArg.sessionId },
|
|
9593
|
-
() => this.serveNativeSession(signalArg, async () => {
|
|
9664
|
+
() => this.serveNativeSession(signalArg, 'none', async () => {
|
|
9594
9665
|
const { ref, resolved, session } = await this.requireMcpNativeClaudeTarget(requestArg.projectId, requestArg.sessionId);
|
|
9595
9666
|
const [page, state] = await Promise.all([
|
|
9596
9667
|
this.requireFleetWorkers().nativeHistory('claude', resolved.native, controllerInitialMessageBundleLimit),
|
|
@@ -9799,6 +9870,18 @@ export class OpenCodeController {
|
|
|
9799
9870
|
return currentControllerMcpCaller();
|
|
9800
9871
|
}
|
|
9801
9872
|
|
|
9873
|
+
/**
|
|
9874
|
+
* The owner's active direct report whose session an MCP caller acts in, read once per ticket request: a ticket names
|
|
9875
|
+
* the caller by it (AGL-1686). None for a caller without a session or whose session is no active report.
|
|
9876
|
+
*/
|
|
9877
|
+
private async mcpCallerReportName(callerArg: IControllerMcpCaller): Promise<string | undefined> {
|
|
9878
|
+
const sessionId = ticketCallerSessionId(callerArg);
|
|
9879
|
+
if (sessionId === undefined) return undefined;
|
|
9880
|
+
const authority = this.configurationAuthority;
|
|
9881
|
+
if (!authority) throw new plugins.typedrequest.TypedResponseError('The configuration authority is unavailable.', { code: 'controller_unavailable' });
|
|
9882
|
+
return await this.requireDirectReports().reportOf((await authority.getResource()).resourceId, sessionId);
|
|
9883
|
+
}
|
|
9884
|
+
|
|
9802
9885
|
private mcpIdentityRequired(): plugins.typedrequest.TypedResponseError {
|
|
9803
9886
|
return new plugins.typedrequest.TypedResponseError(
|
|
9804
9887
|
'This operation is available only to an AGL-launched chat; this MCP host has no AGL identity.',
|
|
@@ -10362,7 +10445,7 @@ export class OpenCodeController {
|
|
|
10362
10445
|
// A worker a direct report's session starts, adopts, refreshes or moves reports to it.
|
|
10363
10446
|
const caller = this.mcpCaller();
|
|
10364
10447
|
const reportsTo = ['start', 'adopt', 'refresh', 'move'].includes(action) && caller.subject.kind !== 'anonymous'
|
|
10365
|
-
? await this.requireDirectReports().reportOf(owner.resourceId,
|
|
10448
|
+
? await this.requireDirectReports().reportOf(owner.resourceId, ticketCallerSessionId(caller)) : undefined;
|
|
10366
10449
|
try {
|
|
10367
10450
|
return await this.requireFleetWorkers().execute(action, input as TFleetWorkerRequest<typeof action>, master.fleet ?? {}, owner.resourceId, operationSignal, actor, reportsTo);
|
|
10368
10451
|
} catch (errorArg) {
|
|
@@ -10424,7 +10507,7 @@ export class OpenCodeController {
|
|
|
10424
10507
|
resolveTicketOwnerAssignment(methodArg, request as TTicketRequest<typeof methodArg>, owner.id), actor, operationSignalArg);
|
|
10425
10508
|
}
|
|
10426
10509
|
const caller = this.mcpCaller();
|
|
10427
|
-
const actor = caller.subject.kind === 'anonymous' ? undefined : ticketActorFromCaller(caller);
|
|
10510
|
+
const actor = caller.subject.kind === 'anonymous' ? undefined : ticketActorFromCaller(caller, await this.mcpCallerReportName(caller));
|
|
10428
10511
|
return await this.ticketStore.execute(methodArg, request as TTicketRequest<typeof methodArg>, actor, operationSignalArg);
|
|
10429
10512
|
} catch (errorArg) {
|
|
10430
10513
|
if (errorArg instanceof TicketError) throw new plugins.typedrequest.TypedResponseError(errorArg.message,
|
|
@@ -10750,9 +10833,9 @@ export class OpenCodeController {
|
|
|
10750
10833
|
: await resolveInitialRuntimeConfig(this.options.runtimeOverrides);
|
|
10751
10834
|
this.assertStartActive();
|
|
10752
10835
|
const authDocument = await authStore.resolveOrCreateRuntimeConfig(runtimeConfig);
|
|
10753
|
-
await authStore.
|
|
10754
|
-
const closed = await authStore.migrateTicketClosedColumn();
|
|
10836
|
+
const { closed, renamed } = await authStore.migrateTicketsAtStart();
|
|
10755
10837
|
if (closed.length) console.log(`Moved ${closed.length} tickets released without a release link or any code link to closed (AGL-916): ${closed.join(', ')}.`);
|
|
10838
|
+
if (renamed.length) console.log(`Named the people of ${renamed.length} tickets by their role instead of their session id (AGL-1686): ${renamed.join(', ')}.`);
|
|
10756
10839
|
this.assertStartActive();
|
|
10757
10840
|
this.runtimeConfig = runtimeConfig;
|
|
10758
10841
|
this.controllerId = authDocument.id;
|
|
@@ -11963,62 +12046,32 @@ export class OpenCodeController {
|
|
|
11963
12046
|
) throw new Error('The Flex session identity generation is no longer current.');
|
|
11964
12047
|
}
|
|
11965
12048
|
|
|
12049
|
+
/**
|
|
12050
|
+
* A project's Flex session identities, in one answer the child reads from the project's metadata:
|
|
12051
|
+
* the snapshot is atomic and never waits for a load of the sessions' histories (AGL-1713). The
|
|
12052
|
+
* supervisor has proven the answer: bounded, strictly ordered and generation-bearing.
|
|
12053
|
+
*/
|
|
11966
12054
|
private async readFlexSessionIdentitySnapshot(
|
|
11967
12055
|
supervisorArg: FlexSupervisor,
|
|
11968
12056
|
projectIdArg: string,
|
|
11969
12057
|
signalArg: AbortSignal,
|
|
11970
12058
|
): Promise<IControllerSessionSnapshotEntry[]> {
|
|
11971
|
-
|
|
11972
|
-
const sessions
|
|
11973
|
-
|
|
11974
|
-
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
|
|
11986
|
-
|
|
11987
|
-
) throw new Error('Flex returned an invalid bounded identity session snapshot.');
|
|
11988
|
-
expectedTotal ??= page.total;
|
|
11989
|
-
if (page.sessions.length === 0 && sessions.length < page.total) {
|
|
11990
|
-
throw new Error('Flex returned an incomplete identity session snapshot page.');
|
|
11991
|
-
}
|
|
11992
|
-
sessions.push(...page.sessions);
|
|
11993
|
-
const truncated = sessions.length < page.total;
|
|
11994
|
-
if (page.truncated !== truncated || sessions.length > page.total) {
|
|
11995
|
-
throw new Error('Flex identity session snapshot pagination changed during its fence.');
|
|
11996
|
-
}
|
|
11997
|
-
if (!truncated) break;
|
|
11998
|
-
}
|
|
11999
|
-
return sessions.map((sessionArg) => {
|
|
12000
|
-
if (
|
|
12001
|
-
typeof sessionArg.sessionId !== 'string'
|
|
12002
|
-
|| sessionArg.sessionId.length === 0
|
|
12003
|
-
|| typeof sessionArg.sessionGenerationId !== 'string'
|
|
12004
|
-
|| sessionArg.sessionGenerationId.length === 0
|
|
12005
|
-
|| typeof sessionArg.sessionGenerationSequence !== 'number'
|
|
12006
|
-
|| !Number.isSafeInteger(sessionArg.sessionGenerationSequence)
|
|
12007
|
-
|| sessionArg.sessionGenerationSequence < 1
|
|
12008
|
-
) throw new Error('Flex returned a session without canonical generation metadata.');
|
|
12009
|
-
return {
|
|
12010
|
-
nativeId: sessionArg.sessionId,
|
|
12011
|
-
sessionGenerationId: sessionArg.sessionGenerationId,
|
|
12012
|
-
sessionGenerationSequence: sessionArg.sessionGenerationSequence,
|
|
12013
|
-
providerSessionGeneration: flexSessionProviderGeneration(
|
|
12014
|
-
sessionArg.sessionGenerationId,
|
|
12015
|
-
sessionArg.sessionGenerationSequence,
|
|
12016
|
-
),
|
|
12017
|
-
...(sessionArg.parentSessionId === undefined
|
|
12018
|
-
? {}
|
|
12019
|
-
: { parentNativeId: sessionArg.parentSessionId }),
|
|
12020
|
-
};
|
|
12021
|
-
}).sort((leftArg, rightArg) => leftArg.nativeId.localeCompare(rightArg.nativeId));
|
|
12059
|
+
signalArg.throwIfAborted();
|
|
12060
|
+
const { sessions } = await supervisorArg.request('session.identities', {
|
|
12061
|
+
scopeId: projectIdArg,
|
|
12062
|
+
}, signalArg);
|
|
12063
|
+
return sessions.map((sessionArg) => ({
|
|
12064
|
+
nativeId: sessionArg.sessionId,
|
|
12065
|
+
sessionGenerationId: sessionArg.sessionGenerationId,
|
|
12066
|
+
sessionGenerationSequence: sessionArg.sessionGenerationSequence,
|
|
12067
|
+
providerSessionGeneration: flexSessionProviderGeneration(
|
|
12068
|
+
sessionArg.sessionGenerationId,
|
|
12069
|
+
sessionArg.sessionGenerationSequence,
|
|
12070
|
+
),
|
|
12071
|
+
...(sessionArg.parentSessionId === undefined
|
|
12072
|
+
? {}
|
|
12073
|
+
: { parentNativeId: sessionArg.parentSessionId }),
|
|
12074
|
+
})).sort((leftArg, rightArg) => leftArg.nativeId.localeCompare(rightArg.nativeId));
|
|
12022
12075
|
}
|
|
12023
12076
|
|
|
12024
12077
|
private async captureFlexCleanupCohort(
|
|
@@ -14267,8 +14320,8 @@ export class OpenCodeController {
|
|
|
14267
14320
|
const publicRouter = new plugins.typedrequest.TypedRouter();
|
|
14268
14321
|
const browserAuthRouter = new plugins.typedrequest.TypedRouter();
|
|
14269
14322
|
const protectedRouter = new ControllerProtectedRouter(asTypedResponseError);
|
|
14270
|
-
const devicePairingRouter = new ControllerProtectedRouter(
|
|
14271
|
-
const deviceRouter = new ControllerProtectedRouter(
|
|
14323
|
+
const devicePairingRouter = new ControllerProtectedRouter(asDeviceResponseError);
|
|
14324
|
+
const deviceRouter = new ControllerProtectedRouter(asDeviceResponseError);
|
|
14272
14325
|
rootRouter.addTypedRouter(publicRouter);
|
|
14273
14326
|
rootRouter.addTypedRouter(browserAuthRouter);
|
|
14274
14327
|
rootRouter.addTypedRouter(protectedRouter);
|
|
@@ -14722,9 +14775,7 @@ export class OpenCodeController {
|
|
|
14722
14775
|
throw deviceDirectReportMessageRefusal(errorArg);
|
|
14723
14776
|
}
|
|
14724
14777
|
if (!('job' in answer)) return { delivery: answer.delivery };
|
|
14725
|
-
if (answer.job.state !== 'succeeded')
|
|
14726
|
-
throw deviceRefusal('direct_report_failed', (answer.job.error ?? 'The fleet did not deliver the message.').slice(0, 4096));
|
|
14727
|
-
}
|
|
14778
|
+
if (answer.job.state !== 'succeeded') throw deviceDirectReportJobRefusal(answer.job);
|
|
14728
14779
|
return { delivery: 'fleet' as const };
|
|
14729
14780
|
}), toolsArg?.abortSignal);
|
|
14730
14781
|
});
|
|
@@ -18946,7 +18997,7 @@ export class OpenCodeController {
|
|
|
18946
18997
|
*/
|
|
18947
18998
|
private registerNativeSessionHandlers(protectedRouterArg: ControllerProtectedRouter): void {
|
|
18948
18999
|
const runtimeId = nativeSessionRuntimeId;
|
|
18949
|
-
const serve = <T>(signalArg: AbortSignal, operationArg: () => Promise<T>): Promise<T> => this.serveNativeSession(signalArg, operationArg);
|
|
19000
|
+
const serve = <T>(signalArg: AbortSignal, operationArg: () => Promise<T>): Promise<T> => this.serveNativeSession(signalArg, 'none', operationArg);
|
|
18950
19001
|
|
|
18951
19002
|
protectedRouterArg.addHandler<IReq_ControllerNativeSessionRead>(
|
|
18952
19003
|
'controller.nativesession.read',
|
|
@@ -18989,7 +19040,7 @@ export class OpenCodeController {
|
|
|
18989
19040
|
await this.sendNativeSession(peer.id, ref, text, attachments, signalArg, assertNativeSessionWritable,
|
|
18990
19041
|
{ kind: 'agent', label: 'Owner', subject: agentMessageSubjects.ownerNativeView });
|
|
18991
19042
|
// The session as the send left it, read apart from the audited send.
|
|
18992
|
-
return { session: await this.serveNativeSession(signalArg, async () => (await this.nativeSessions.resolve(ref)).session) };
|
|
19043
|
+
return { session: await this.serveNativeSession(signalArg, 'none', async () => (await this.nativeSessions.resolve(ref)).session) };
|
|
18993
19044
|
}, toolsArg?.abortSignal);
|
|
18994
19045
|
},
|
|
18995
19046
|
);
|
|
@@ -19126,7 +19177,7 @@ export class OpenCodeController {
|
|
|
19126
19177
|
const sessionId = nativeSessionRuntimeId(ref);
|
|
19127
19178
|
return this.runAudited(
|
|
19128
19179
|
{ type: 'session.read', peerId: this.auditPeerId(principalArg, peerIdArg), sessionId },
|
|
19129
|
-
() => this.serveNativeSession(signalArg, async () => {
|
|
19180
|
+
() => this.serveNativeSession(signalArg, 'none', async () => {
|
|
19130
19181
|
const resolved = await this.nativeSessions.resolve(ref);
|
|
19131
19182
|
const [page, attention, state] = await Promise.all([
|
|
19132
19183
|
this.requireFleetWorkers().nativeHistory(ref.harness, resolved.native, limit ?? controllerInitialMessageBundleLimit, before),
|
|
@@ -19169,7 +19220,7 @@ export class OpenCodeController {
|
|
|
19169
19220
|
: ['question', { answers: requestArg.answers }];
|
|
19170
19221
|
return this.runAudited(
|
|
19171
19222
|
{ type: `${kind}.reply`, peerId: this.auditPeerId(principalArg, peerIdArg), sessionId: nativeSessionRuntimeId(ref), requestId },
|
|
19172
|
-
() => this.serveNativeSession(signalArg, async () => {
|
|
19223
|
+
() => this.serveNativeSession(signalArg, 'dispatch', async () => {
|
|
19173
19224
|
const resolved = await this.nativeSessions.resolve(ref);
|
|
19174
19225
|
await this.replyNativeSessionRequest(resolved, requestId.nativeId, reply, kind);
|
|
19175
19226
|
return { success: true };
|
|
@@ -19215,17 +19266,25 @@ export class OpenCodeController {
|
|
|
19215
19266
|
}
|
|
19216
19267
|
}
|
|
19217
19268
|
|
|
19218
|
-
/**
|
|
19219
|
-
|
|
19269
|
+
/**
|
|
19270
|
+
* Native session failures are bounded messages; the session view and the fleet's receipt show them as they are. Each
|
|
19271
|
+
* says what it did (`INativeSessionFailedErrorData`). `effectArg` `none` means the operation sends the session
|
|
19272
|
+
* nothing (a read, the session's resolution, AGL's own scratchpad), so it is `refused`: a scratchpad save under `none`
|
|
19273
|
+
* is safe to repeat because its `expectedRevision` refuses a second write of the same revision. A send or an answer
|
|
19274
|
+
* (`dispatch`) is `refused` only where the fleet proved it never went out, and `unknown` otherwise.
|
|
19275
|
+
*/
|
|
19276
|
+
private async serveNativeSession<T>(signalArg: AbortSignal, effectArg: 'none' | 'dispatch', operationArg: () => Promise<T>): Promise<T> {
|
|
19220
19277
|
try {
|
|
19221
19278
|
return await operationArg();
|
|
19222
19279
|
} catch (errorArg) {
|
|
19223
19280
|
if (signalArg.aborted || errorArg instanceof plugins.typedrequest.TypedResponseError || !(errorArg instanceof Error)) throw errorArg;
|
|
19224
19281
|
// The session state store states its own refusals: a stale scratchpad revision, a missing record.
|
|
19225
19282
|
if (errorArg instanceof AuthError) throw asTypedResponseError(errorArg, 'native session');
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
|
|
19283
|
+
const errorData: INativeSessionFailedErrorData = {
|
|
19284
|
+
code: 'native_session_failed',
|
|
19285
|
+
outcome: effectArg === 'none' || (errorArg instanceof FleetDispatchError && !errorArg.dispatched) ? 'refused' : 'unknown',
|
|
19286
|
+
};
|
|
19287
|
+
throw new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 4096), errorData);
|
|
19229
19288
|
}
|
|
19230
19289
|
}
|
|
19231
19290
|
|
|
@@ -19250,7 +19309,7 @@ export class OpenCodeController {
|
|
|
19250
19309
|
ownerArg?: IControllerPromptSender,
|
|
19251
19310
|
): Promise<{ job?: TControllerNativeJobDelivery }> {
|
|
19252
19311
|
const sessionId = nativeSessionRuntimeId(refArg);
|
|
19253
|
-
return this.runAudited({ type: 'session.send', peerId: peerIdArg, sessionId }, () => this.serveNativeSession(signalArg, async () => {
|
|
19312
|
+
return this.runAudited({ type: 'session.send', peerId: peerIdArg, sessionId }, () => this.serveNativeSession(signalArg, 'dispatch', async () => {
|
|
19254
19313
|
const scope = (await this.nativeSessions.resolve(refArg)).scope;
|
|
19255
19314
|
let job: TControllerNativeJobDelivery | undefined;
|
|
19256
19315
|
await this.withSessionStateMutation(scope, sessionId, async () => {
|
|
@@ -19361,7 +19420,11 @@ export class OpenCodeController {
|
|
|
19361
19420
|
} catch (errorArg) {
|
|
19362
19421
|
if (errorArg instanceof ClaudeHarnessDispatchError && !errorArg.dispatched) {
|
|
19363
19422
|
if (upload) cleanup();
|
|
19364
|
-
|
|
19423
|
+
// Nothing went out: a busy conversation or host says so, which a sender reads as "try again once it ended".
|
|
19424
|
+
const errorData: INativeSessionFailedErrorData = {
|
|
19425
|
+
code: 'native_session_failed', outcome: 'refused', ...(errorArg.refusal === undefined ? {} : { refusal: errorArg.refusal }),
|
|
19426
|
+
};
|
|
19427
|
+
throw new plugins.typedrequest.TypedResponseError(errorArg.message, errorData);
|
|
19365
19428
|
}
|
|
19366
19429
|
// Claude Code may have taken the message: the turn settles as Claude Code reports it, and its upload goes with
|
|
19367
19430
|
// it. A conversation that no longer holds the message lost its process, and with it the turn.
|
|
@@ -19422,15 +19485,15 @@ export class OpenCodeController {
|
|
|
19422
19485
|
}
|
|
19423
19486
|
|
|
19424
19487
|
/**
|
|
19425
|
-
* A direct report operation for the owner's browser or a device, given the owner: its failures
|
|
19426
|
-
*
|
|
19488
|
+
* A direct report operation for the owner's browser or a device, given the owner: its failures reach them as
|
|
19489
|
+
* `directReportFailure` decides, by the error's class.
|
|
19427
19490
|
*/
|
|
19428
19491
|
private async serveDirectReport<T>(signalArg: AbortSignal, operationArg: (ownerArg: string) => Promise<T>): Promise<T> {
|
|
19429
19492
|
try {
|
|
19430
19493
|
return await operationArg((await this.readFleetScope()).owner);
|
|
19431
19494
|
} catch (errorArg) {
|
|
19432
19495
|
if (signalArg.aborted || errorArg instanceof plugins.typedrequest.TypedResponseError || !(errorArg instanceof Error)) throw errorArg;
|
|
19433
|
-
throw
|
|
19496
|
+
throw directReportFailure(errorArg, 'directreport');
|
|
19434
19497
|
}
|
|
19435
19498
|
}
|
|
19436
19499
|
|
|
@@ -19504,9 +19567,10 @@ export class OpenCodeController {
|
|
|
19504
19567
|
async (requestArg, toolsArg) => {
|
|
19505
19568
|
const request = validateRequest(() => assertDirectReportMessageRequest(requestArg));
|
|
19506
19569
|
const peer = peerFromLocalData(toolsArg?.localData);
|
|
19507
|
-
return this.runOperation(peer, (signalArg) => serve(signalArg, async (ownerArg) =>
|
|
19508
|
-
this.messageDirectReportForPrincipal('browser', peer.id, ownerArg, request, signalArg)
|
|
19509
|
-
|
|
19570
|
+
return this.runOperation(peer, (signalArg) => serve(signalArg, async (ownerArg) => {
|
|
19571
|
+
const answer = await this.messageDirectReportForPrincipal('browser', peer.id, ownerArg, request, signalArg);
|
|
19572
|
+
return 'job' in answer ? { job: directReportJobView(answer.job) } : answer;
|
|
19573
|
+
}), toolsArg?.abortSignal);
|
|
19510
19574
|
},
|
|
19511
19575
|
);
|
|
19512
19576
|
}
|
|
@@ -19514,9 +19578,11 @@ export class OpenCodeController {
|
|
|
19514
19578
|
/**
|
|
19515
19579
|
* The owner's own message to the active direct report `name`, from the Driver view or a paired device, audited as
|
|
19516
19580
|
* `session.message` from the `Owner` for the caller. A fleet worker report is steered through the report's driver
|
|
19517
|
-
* ticket, as the driver's `directreport_message` does, and answers with the settled steer job
|
|
19518
|
-
* unless the job succeeded;
|
|
19519
|
-
* `
|
|
19581
|
+
* ticket, as the driver's `directreport_message` does, and answers with the settled steer job as the fleet recorded
|
|
19582
|
+
* it, audited `failed` unless the job succeeded; the caller shows a failed job's error by its code
|
|
19583
|
+
* (`directReportJobView`, `deviceDirectReportJobRefusal`), and one that may have delivered it (`errorOutcome`) as of
|
|
19584
|
+
* unknown outcome. A steer the fleet refused is `direct_report_failed`
|
|
19585
|
+
* (`directReportFailure`), also audited `failed`. A Codex thread takes it as the owner's agent message.
|
|
19520
19586
|
*/
|
|
19521
19587
|
private async messageDirectReportForPrincipal(
|
|
19522
19588
|
principalArg: TControllerOperationPrincipal,
|
|
@@ -19537,7 +19603,10 @@ export class OpenCodeController {
|
|
|
19537
19603
|
const { delivery, turnId } = await this.messageDirectReportSession(channel, 'owner', peerId, text, expectedTurnId);
|
|
19538
19604
|
return { delivery, ...(turnId === undefined ? {} : { turnId }) };
|
|
19539
19605
|
}
|
|
19540
|
-
if (expectedTurnId !== undefined)
|
|
19606
|
+
if (expectedTurnId !== undefined) {
|
|
19607
|
+
throw new plugins.typedrequest.TypedResponseError('expectedTurnId names the turn of a Codex thread; a fleet worker report is steered through its ticket.',
|
|
19608
|
+
{ code: 'invalid_request' });
|
|
19609
|
+
}
|
|
19541
19610
|
return await this.runAudited({ type: 'session.message', peerId, sessionId: directReportRuntimeId(channel.report), senderLabel: 'Owner' }, async () => {
|
|
19542
19611
|
try {
|
|
19543
19612
|
const fleetWorkers = this.requireFleetWorkers();
|
|
@@ -19549,7 +19618,7 @@ export class OpenCodeController {
|
|
|
19549
19618
|
} catch (errorArg) {
|
|
19550
19619
|
// The fleet's own reason, as `serveDirectReport` gives it, before the audit would reduce it to a generic failure.
|
|
19551
19620
|
if (signalArg.aborted || errorArg instanceof plugins.typedrequest.TypedResponseError || !(errorArg instanceof Error)) throw errorArg;
|
|
19552
|
-
throw
|
|
19621
|
+
throw directReportFailure(errorArg, 'directreport.message');
|
|
19553
19622
|
}
|
|
19554
19623
|
}, ({ job }) => job.state === 'succeeded' ? 'succeeded' : 'failed');
|
|
19555
19624
|
}
|
|
@@ -20277,12 +20346,14 @@ export class OpenCodeController {
|
|
|
20277
20346
|
try {
|
|
20278
20347
|
result = await operationArg(operationId);
|
|
20279
20348
|
} catch (error) {
|
|
20280
|
-
// A refused workspace path is a policy decision, recorded as one; a direct report that took no message
|
|
20349
|
+
// A refused workspace path is a policy decision, recorded as one; a direct report that took no message, and a fault
|
|
20350
|
+
// already reduced to the controller's generic failure, are failures.
|
|
20281
20351
|
const outcome = (error instanceof AuthError
|
|
20282
20352
|
|| error instanceof plugins.typedrequest.TypedResponseError
|
|
20283
20353
|
|| error instanceof ControllerWorkspaceError
|
|
20284
20354
|
|| error instanceof ConfigurationError)
|
|
20285
|
-
&& !(error instanceof plugins.typedrequest.TypedResponseError
|
|
20355
|
+
&& !(error instanceof plugins.typedrequest.TypedResponseError
|
|
20356
|
+
&& (error.errorData?.code === 'direct_report_failed' || error.errorData?.code === controllerOperationFailedErrorCode))
|
|
20286
20357
|
? 'denied'
|
|
20287
20358
|
: 'failed';
|
|
20288
20359
|
const suppressUnboundedDenialAudit = error instanceof AuthError
|
|
@@ -29325,10 +29396,12 @@ export class OpenCodeController {
|
|
|
29325
29396
|
/**
|
|
29326
29397
|
* The reversion requests that settle what a Flex session already recorded: a capture's inspection
|
|
29327
29398
|
* and finalization, a pending undo or redo, a release. A project reconciling its session authority
|
|
29328
|
-
* admits them.
|
|
29329
|
-
*
|
|
29330
|
-
*
|
|
29331
|
-
*
|
|
29399
|
+
* admits them. The first full load of the project's sessions in the child (the child's recovery
|
|
29400
|
+
* load once it is ready, a held prompt's settlement or a managed creation's recovery during the
|
|
29401
|
+
* reconciliation, any session read; never `session.identities`) settles each session's pending
|
|
29402
|
+
* capture and apply before it answers; a refused settlement fails that load, and with it a
|
|
29403
|
+
* reconciliation waiting for it, which then never succeeds. The ending turn of a run closes its
|
|
29404
|
+
* capture with the same requests. A new capture
|
|
29332
29405
|
* (`reversion.prepare`) is new work and stays refused while authority is uncertain.
|
|
29333
29406
|
*/
|
|
29334
29407
|
private flexHostMethodSettlesRecordedReversion(methodArg: TFlexHostRequestMethod): boolean {
|
|
@@ -5,7 +5,11 @@ import {
|
|
|
5
5
|
type IFlexModelChoiceDocument,
|
|
6
6
|
assertFlexModelChoiceDocument,
|
|
7
7
|
} from './classes.flexmodels.private.js';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
FlexStore,
|
|
10
|
+
type IFlexProjectManagementHost,
|
|
11
|
+
type IFlexScopeLoadReads,
|
|
12
|
+
} from './classes.flexstore.js';
|
|
9
13
|
import { FlexPersistenceMigrationRunner } from '../ts_migration/classes.flexmigrationrunner.js';
|
|
10
14
|
import {
|
|
11
15
|
assertCanonicalDirectory,
|
|
@@ -46,8 +50,10 @@ import {
|
|
|
46
50
|
type TFlexProjectManagementSessionContext,
|
|
47
51
|
type TFlexRequestMethod,
|
|
48
52
|
type TFlexPromptAdmissionGeneration,
|
|
53
|
+
type TFlexScopeLoadMetrics,
|
|
49
54
|
type TFlexSessionGeneration,
|
|
50
55
|
type TFlexSessionGenerationCohortEntry,
|
|
56
|
+
type TFlexSessionIdentity,
|
|
51
57
|
createFlexServiceError,
|
|
52
58
|
flexGenerationLeaseCleanupTimeoutMs,
|
|
53
59
|
flexIntelligenceInstallationScopeId,
|
|
@@ -64,6 +70,7 @@ import {
|
|
|
64
70
|
flexIpcMaximumPromptQueueEntries,
|
|
65
71
|
flexIpcMaximumQueuedSessionChangeBytes,
|
|
66
72
|
flexIpcMaximumQueuedSessionChanges,
|
|
73
|
+
flexIpcMaximumSessionIdentities,
|
|
67
74
|
flexIpcMaximumDeltaBytes,
|
|
68
75
|
flexIpcProtocolVersion,
|
|
69
76
|
flexIpcReversionMaintenanceTimeoutMs,
|
|
@@ -341,6 +348,26 @@ export const isReadOnlyFlexToolCall = (callArg: { toolName: string; input: unkno
|
|
|
341
348
|
&& callArg.input !== null
|
|
342
349
|
&& (callArg.input as { action?: unknown }).action === 'list');
|
|
343
350
|
|
|
351
|
+
/**
|
|
352
|
+
* The controller log line of one FlexHarness load of a project's sessions (AGL-1713): what FlexHarness
|
|
353
|
+
* measured, with the snapshots the store read and decoded for that load.
|
|
354
|
+
*/
|
|
355
|
+
export const formatFlexScopeLoadLine = (
|
|
356
|
+
metricsArg: TFlexScopeLoadMetrics,
|
|
357
|
+
readsArg: IFlexScopeLoadReads,
|
|
358
|
+
): string => `Flex project load: ${JSON.stringify({
|
|
359
|
+
projectId: metricsArg.scopeId,
|
|
360
|
+
outcome: metricsArg.outcome,
|
|
361
|
+
sessions: metricsArg.sessions,
|
|
362
|
+
snapshotsRead: readsArg.snapshots,
|
|
363
|
+
bytesRead: readsArg.bytes,
|
|
364
|
+
parseMs: Math.round(readsArg.decodeMs),
|
|
365
|
+
storeReadMs: Math.round(metricsArg.storeReadMs),
|
|
366
|
+
agentSessionMs: Math.round(metricsArg.agentSessionMs),
|
|
367
|
+
repairMs: Math.round(metricsArg.repairMs),
|
|
368
|
+
totalMs: Math.round(metricsArg.totalMs),
|
|
369
|
+
})}`;
|
|
370
|
+
|
|
344
371
|
export const createFlexBuiltInTools = (): plugins.flexharness.IFlexBuiltInToolsOptions => ({
|
|
345
372
|
renameSession: true,
|
|
346
373
|
projectManagement: {
|
|
@@ -355,7 +382,7 @@ const projectSerializedMethods: ReadonlySet<TFlexRequestMethod> = new Set([
|
|
|
355
382
|
'project.remove',
|
|
356
383
|
'intelligence.start',
|
|
357
384
|
'intelligence.cancel',
|
|
358
|
-
'session.
|
|
385
|
+
'session.identities',
|
|
359
386
|
'session.create',
|
|
360
387
|
'session.get',
|
|
361
388
|
'session.cache.warm',
|
|
@@ -398,7 +425,7 @@ const projectScopedMethods: ReadonlySet<TFlexRequestMethod> = new Set([
|
|
|
398
425
|
'intelligence.start',
|
|
399
426
|
'intelligence.get',
|
|
400
427
|
'intelligence.cancel',
|
|
401
|
-
'session.
|
|
428
|
+
'session.identities',
|
|
402
429
|
'session.create',
|
|
403
430
|
'session.get',
|
|
404
431
|
'session.metrics',
|
|
@@ -988,6 +1015,7 @@ export class FlexService {
|
|
|
988
1015
|
reversionPolicy: 'workspace-required',
|
|
989
1016
|
slashCommands: [this.worktreeSlashCommand()],
|
|
990
1017
|
stores: store,
|
|
1018
|
+
scopeLoadObserver: (metrics) => this.reportScopeLoad(store, metrics),
|
|
991
1019
|
builtInTools: createFlexBuiltInTools(),
|
|
992
1020
|
toolOutputLimits: { maxDepth: 12, maxBytes: toolOutputBytes },
|
|
993
1021
|
toolCatalog: { codeMode: true },
|
|
@@ -1036,6 +1064,15 @@ export class FlexService {
|
|
|
1036
1064
|
}
|
|
1037
1065
|
}
|
|
1038
1066
|
|
|
1067
|
+
/**
|
|
1068
|
+
* Writes one line per FlexHarness load of a project to stderr, which the supervisor writes to the
|
|
1069
|
+
* controller log, whatever the load's outcome; the store's reads of that load end with it.
|
|
1070
|
+
*/
|
|
1071
|
+
private reportScopeLoad(storeArg: FlexStore, metricsArg: TFlexScopeLoadMetrics): void {
|
|
1072
|
+
const reads = storeArg.takeScopeLoadReads(metricsArg.storageKey);
|
|
1073
|
+
process.stderr.write(`${formatFlexScopeLoadLine(metricsArg, reads)}\n`);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1039
1076
|
/**
|
|
1040
1077
|
* An opaque FlexHarness projection that failed the initialization, restated with the raw failure
|
|
1041
1078
|
* it replaced, and the harness step that met it, as its cause.
|
|
@@ -1246,19 +1283,25 @@ export class FlexService {
|
|
|
1246
1283
|
const payload = payloadArg as IFlexRequestMap['configuration.adapt']['request'];
|
|
1247
1284
|
return { result: await this.adaptConfiguration(payload, signalArg) };
|
|
1248
1285
|
}
|
|
1249
|
-
case 'session.
|
|
1250
|
-
const payload = payloadArg as IFlexRequestMap['session.
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
const limit = payload.limit ?? 50;
|
|
1286
|
+
case 'session.identities': {
|
|
1287
|
+
const payload = payloadArg as IFlexRequestMap['session.identities']['request'];
|
|
1288
|
+
// FlexHarness answers from the project's metadata, before a load of its histories settles.
|
|
1289
|
+
const identities = await harness.listSessionIdentities(payload.scopeId);
|
|
1290
|
+
if (identities.length > flexIpcMaximumSessionIdentities) {
|
|
1291
|
+
throw new FlexServiceError('LIMIT_EXCEEDED');
|
|
1292
|
+
}
|
|
1257
1293
|
return {
|
|
1258
1294
|
result: {
|
|
1259
|
-
sessions:
|
|
1260
|
-
|
|
1261
|
-
|
|
1295
|
+
sessions: identities.map((identity) => ({
|
|
1296
|
+
sessionId: identity.sessionId,
|
|
1297
|
+
sessionGenerationId: identity.sessionGenerationId,
|
|
1298
|
+
sessionGenerationSequence: identity.sessionGenerationSequence,
|
|
1299
|
+
...(identity.parentSessionId === undefined
|
|
1300
|
+
? {}
|
|
1301
|
+
: { parentSessionId: identity.parentSessionId }),
|
|
1302
|
+
})).sort((left, right) => (
|
|
1303
|
+
left.sessionId < right.sessionId ? -1 : left.sessionId > right.sessionId ? 1 : 0
|
|
1304
|
+
)),
|
|
1262
1305
|
},
|
|
1263
1306
|
};
|
|
1264
1307
|
}
|