agl 43.2.0 → 43.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +29 -0
- package/dist_serve/bundle.js +2845 -2638
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +1 -1
- package/dist_serve/bundle.js.third-party-notices.txt +1 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +197 -17
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +21 -3
- package/dist_ts/classes.authstore.d.ts +7 -0
- package/dist_ts/classes.authstore.js +9 -1
- package/dist_ts/classes.claudeharness.d.ts +29 -2
- package/dist_ts/classes.claudeharness.js +35 -6
- package/dist_ts/classes.codexclientadapter.d.ts +11 -0
- package/dist_ts/classes.codexclientadapter.js +14 -2
- package/dist_ts/classes.controller.d.ts +187 -12
- package/dist_ts/classes.controller.js +1208 -186
- package/dist_ts/classes.controllerdevices.d.ts +2 -0
- package/dist_ts/classes.controllerdevices.js +6 -1
- package/dist_ts/classes.inbox.d.ts +72 -0
- package/dist_ts/classes.inbox.js +231 -0
- package/dist_ts/classes.inferencerouter.d.ts +10 -0
- package/dist_ts/classes.inferencerouter.js +5 -3
- package/dist_ts/classes.inferenceservice.js +2 -2
- package/dist_ts/classes.mcpclient.d.ts +1 -1
- package/dist_ts/classes.mcpclient.js +24 -6
- package/dist_ts/classes.mcpcontrollerhost.js +6 -1
- package/dist_ts/classes.mcptools.js +18 -8
- package/dist_ts/classes.mcpvalidation.d.ts +5 -0
- package/dist_ts/classes.mcpvalidation.js +32 -2
- package/dist_ts/classes.nativesessions.d.ts +29 -4
- package/dist_ts/classes.nativesessions.js +41 -9
- package/dist_ts/classes.opencodeclient.d.ts +23 -2
- package/dist_ts/classes.opencodeclient.js +47 -3
- package/dist_ts/classes.publishedset.d.ts +38 -0
- package/dist_ts/classes.publishedset.js +50 -0
- package/dist_ts/classes.sessionfeed.d.ts +3 -3
- package/dist_ts/classes.sessionfeed.js +18 -26
- package/dist_ts/classes.systemmetricssampler.d.ts +6 -0
- package/dist_ts/classes.systemmetricssampler.js +15 -3
- package/dist_ts/classes.ticketstore.d.ts +50 -3
- package/dist_ts/classes.ticketstore.js +45 -8
- package/dist_ts/classes.workercallers.js +4 -2
- package/dist_ts/driver/classes.directreports.d.ts +14 -4
- package/dist_ts/driver/classes.directreports.js +42 -23
- package/dist_ts/driver/classes.directreportstore.d.ts +8 -1
- package/dist_ts/driver/classes.directreportstore.js +20 -10
- package/dist_ts/driver/classes.driverservice.d.ts +44 -3
- package/dist_ts/driver/classes.driverservice.js +50 -16
- package/dist_ts/fleet/classes.claudeworkers.d.ts +21 -5
- package/dist_ts/fleet/classes.claudeworkers.js +142 -46
- package/dist_ts/fleet/classes.codexworkers.d.ts +16 -4
- package/dist_ts/fleet/classes.codexworkers.js +22 -5
- package/dist_ts/fleet/classes.workercommand.d.ts +6 -1
- package/dist_ts/fleet/classes.workercommand.js +15 -4
- package/dist_ts/fleet/classes.workers.d.ts +21 -1
- package/dist_ts/fleet/classes.workers.js +80 -40
- package/dist_ts/fleet/classes.workerstore.js +14 -8
- package/dist_ts/fleet/functions.unbounddrivers.js +2 -2
- package/dist_ts/fleet/functions.workervalidation.js +11 -4
- package/dist_ts/fleet/interfaces.workers.d.ts +27 -5
- package/dist_ts/fleet/interfaces.workers.js +8 -4
- package/dist_ts/functions.agentmessage.d.ts +3 -0
- package/dist_ts/functions.agentmessage.js +4 -1
- package/dist_ts/functions.deviceapi.d.ts +198 -4
- package/dist_ts/functions.deviceapi.js +1060 -38
- package/dist_ts/functions.exactpersistence.d.ts +3 -0
- package/dist_ts/functions.exactpersistence.js +4 -0
- package/dist_ts/functions.fleetworkercli.d.ts +1 -1
- package/dist_ts/functions.fleetworkercli.js +11 -8
- package/dist_ts/functions.inferencecli.js +3 -1
- package/dist_ts/functions.mcpfleetworkertools.js +3 -3
- package/dist_ts/functions.ticketactor.d.ts +17 -1
- package/dist_ts/functions.ticketactor.js +55 -15
- package/dist_ts/functions.ticketvalidation.js +11 -2
- package/dist_ts/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +9 -1
- package/dist_ts/plugins.d.ts +3 -1
- package/dist_ts/plugins.js +7 -2
- package/dist_ts_authswitch/authority-contract.d.ts +25 -0
- package/dist_ts_authswitch/authority-contract.js +1 -1
- package/dist_ts_authswitch/authority-overview.d.ts +8 -0
- package/dist_ts_authswitch/authority-overview.js +17 -6
- package/dist_ts_authswitch/authority-placement.d.ts +20 -16
- package/dist_ts_authswitch/authority-placement.js +17 -10
- package/dist_ts_authswitch/authority-renewal.d.ts +34 -0
- package/dist_ts_authswitch/authority-renewal.js +56 -0
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +8 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +35 -2
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +44 -3
- package/dist_ts_authswitch/classes.authorityclient.d.ts +6 -1
- package/dist_ts_authswitch/classes.authorityclient.js +12 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +8 -1
- package/dist_ts_authswitch/classes.authoritydatabase.js +6 -2
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +21 -5
- package/dist_ts_interfaces/devices.d.ts +1027 -7
- package/dist_ts_interfaces/devices.js +68 -2
- package/dist_ts_interfaces/fleetworkers.d.ts +37 -10
- package/dist_ts_interfaces/fleetworkers.js +19 -8
- package/dist_ts_interfaces/inbox.d.ts +234 -0
- package/dist_ts_interfaces/inbox.js +101 -0
- package/dist_ts_interfaces/index.d.ts +1 -0
- package/dist_ts_interfaces/index.js +2 -1
- package/dist_ts_interfaces/interfaces.d.ts +10 -3
- package/dist_ts_interfaces/interfaces.js +4 -2
- package/dist_ts_interfaces/mcprequests.d.ts +34 -4
- package/dist_ts_interfaces/mcprequests.js +11 -1
- package/dist_ts_interfaces/mcpworkspacerequests.d.ts +4 -1
- package/dist_ts_interfaces/mcpworkspacerequests.js +1 -1
- package/dist_ts_interfaces/nativesessions.d.ts +16 -3
- package/dist_ts_interfaces/plugins.d.ts +2 -1
- package/dist_ts_interfaces/plugins.js +4 -2
- package/dist_ts_interfaces/requests.accounts.d.ts +21 -0
- package/dist_ts_interfaces/requests.accounts.js +3 -1
- package/dist_ts_interfaces/requests.d.ts +3 -2
- package/dist_ts_interfaces/requests.js +1 -1
- 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/docs/authswitch.md +20 -1
- package/package.json +3 -3
- package/readme.md +144 -27
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +196 -16
- package/ts/classes.accountsactions.ts +30 -3
- package/ts/classes.authstore.ts +10 -0
- package/ts/classes.claudeharness.ts +45 -5
- package/ts/classes.codexclientadapter.ts +14 -1
- package/ts/classes.controller.ts +1412 -262
- package/ts/classes.controllerdevices.ts +6 -0
- package/ts/classes.inbox.ts +239 -0
- package/ts/classes.inferencerouter.ts +15 -2
- package/ts/classes.inferenceservice.ts +1 -1
- package/ts/classes.mcpclient.ts +24 -3
- package/ts/classes.mcpcontrollerhost.ts +5 -0
- package/ts/classes.mcptools.ts +17 -7
- package/ts/classes.mcpvalidation.ts +27 -1
- package/ts/classes.nativesessions.ts +63 -12
- package/ts/classes.opencodeclient.ts +55 -4
- package/ts/classes.publishedset.ts +56 -0
- package/ts/classes.sessionfeed.ts +17 -20
- package/ts/classes.systemmetricssampler.ts +13 -2
- package/ts/classes.ticketstore.ts +73 -12
- package/ts/classes.workercallers.ts +3 -1
- package/ts/driver/classes.directreports.ts +42 -23
- package/ts/driver/classes.directreportstore.ts +20 -9
- package/ts/driver/classes.driverservice.ts +75 -14
- package/ts/fleet/classes.claudeworkers.ts +112 -39
- package/ts/fleet/classes.codexworkers.ts +21 -6
- package/ts/fleet/classes.workercommand.ts +14 -4
- package/ts/fleet/classes.workers.ts +75 -41
- package/ts/fleet/classes.workerstore.ts +11 -7
- package/ts/fleet/functions.unbounddrivers.ts +1 -1
- package/ts/fleet/functions.workervalidation.ts +8 -3
- package/ts/fleet/interfaces.workers.ts +26 -7
- package/ts/functions.agentmessage.ts +3 -0
- package/ts/functions.deviceapi.ts +1292 -34
- package/ts/functions.exactpersistence.ts +5 -0
- package/ts/functions.fleetworkercli.ts +10 -7
- package/ts/functions.inferencecli.ts +2 -0
- package/ts/functions.mcpfleetworkertools.ts +2 -2
- package/ts/functions.ticketactor.ts +58 -14
- package/ts/functions.ticketvalidation.ts +11 -1
- package/ts/interfaces.auth.ts +8 -0
- package/ts/plugins.ts +7 -0
- package/ts_authswitch/authority-contract.ts +20 -0
- package/ts_authswitch/authority-overview.ts +28 -6
- package/ts_authswitch/authority-placement.ts +25 -17
- package/ts_authswitch/authority-renewal.ts +64 -0
- package/ts_authswitch/classes.authoritybroker.ts +34 -1
- package/ts_authswitch/classes.authoritycli.ts +49 -2
- package/ts_authswitch/classes.authorityclient.ts +14 -4
- package/ts_authswitch/classes.authoritydaemon.ts +9 -1
- package/ts_authswitch/classes.authoritydatabase.ts +5 -1
- package/ts_authswitch/classes.authoritymodels.ts +23 -3
- package/ts_authswitch/native-contracts.md +21 -0
- package/ts_authswitch/readme.md +1 -1
- package/ts_interfaces/devices.schema.json +3576 -603
- package/ts_interfaces/devices.ts +1111 -6
- package/ts_interfaces/fleetworkers.ts +38 -10
- package/ts_interfaces/inbox.ts +287 -0
- package/ts_interfaces/index.ts +1 -0
- package/ts_interfaces/interfaces.ts +9 -2
- package/ts_interfaces/mcprequests.ts +43 -4
- package/ts_interfaces/mcpworkspacerequests.ts +4 -2
- package/ts_interfaces/nativesessions.ts +17 -3
- package/ts_interfaces/plugins.ts +3 -1
- package/ts_interfaces/requests.accounts.ts +20 -0
- package/ts_interfaces/requests.ts +4 -0
- 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/accounts.plugins.ts +4 -2
- package/ts_web/classes.accountsreadmodel.ts +33 -0
- package/ts_web/classes.browserpresentation.ts +10 -5
- package/ts_web/classes.inboxfeed.ts +329 -0
- package/ts_web/classes.nativesessionstate.ts +9 -23
- package/ts_web/elements.accounts.ts +81 -0
- package/ts_web/elements.deployments.ts +66 -2
- package/ts_web/elements.fleetworker.ts +4 -2
- package/ts_web/elements.harnesscontrollerapp.ts +107 -37
- package/ts_web/elements.inbox.ts +808 -0
- package/ts_web/functions.inbox.ts +95 -0
- package/ts_web/functions.sessioncards.ts +40 -0
- package/ts_web/plugins.ts +2 -0
|
@@ -97,6 +97,8 @@ export interface IWorkerCallerSubject {
|
|
|
97
97
|
nativeSessionId: string;
|
|
98
98
|
sessionIdentityId: string;
|
|
99
99
|
ticketSessionId: string;
|
|
100
|
+
/** The fleet worker's name: what a ticket calls the worker, unless it is an active direct report. */
|
|
101
|
+
workerName: string;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
export type TWorkerCallerEnrollment = { bridgePid: number } & (
|
|
@@ -14,6 +14,7 @@ import { ClaudeGatewayRetirementV38Migration } from './v38_claudegatewayretireme
|
|
|
14
14
|
import { TicketOwnerPrincipalV38Migration } from './v38_ticketownerprincipal.js';
|
|
15
15
|
import { TicketClosedColumnV41Migration } from './v41_ticketclosedcolumn.js';
|
|
16
16
|
import { TicketLinkReposV41Migration } from './v41_ticketlinkrepos.js';
|
|
17
|
+
import { TicketActorNamesV43Migration } from './v43_ticketactornames.js';
|
|
17
18
|
import type { IControllerIssuerIdentity } from '../ts/interfaces.identity.js';
|
|
18
19
|
|
|
19
20
|
interface IDocumentMigration {
|
|
@@ -54,6 +55,18 @@ export class PostDatabaseDocumentMigrationRunner {
|
|
|
54
55
|
).run();
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* The ticket migrations of a controller start, in their order; a new one goes last. v38 gives owner assignments the
|
|
60
|
+
* store's principal, v41 moves tickets released by hand without a release link to closed, and v43 names ticket actors
|
|
61
|
+
* by their role (AGL-1686). Answers the keys v41 moved and those whose revision v43 moved.
|
|
62
|
+
*/
|
|
63
|
+
public async runTicketStart(principalIdArg: string): Promise<{ closed: string[]; renamed: string[] }> {
|
|
64
|
+
await this.runTicketOwnerPrincipal(principalIdArg);
|
|
65
|
+
const closed = await this.runTicketClosedColumn();
|
|
66
|
+
const renamed = await this.runTicketActorNames();
|
|
67
|
+
return { closed, renamed };
|
|
68
|
+
}
|
|
69
|
+
|
|
57
70
|
public async runTicketOwnerPrincipal(principalIdArg: string): Promise<void> {
|
|
58
71
|
await new TicketOwnerPrincipalV38Migration(this.database, principalIdArg).run();
|
|
59
72
|
}
|
|
@@ -63,6 +76,14 @@ export class PostDatabaseDocumentMigrationRunner {
|
|
|
63
76
|
return await new TicketClosedColumnV41Migration(this.database).run();
|
|
64
77
|
}
|
|
65
78
|
|
|
79
|
+
/**
|
|
80
|
+
* AGL-1686: once, every person and actor a ticket stores under its session id is named by its harness's label, and the
|
|
81
|
+
* OpenCode runtime's `runtime` actor "OpenCode"; answers the keys whose revision it moved.
|
|
82
|
+
*/
|
|
83
|
+
public async runTicketActorNames(): Promise<string[]> {
|
|
84
|
+
return await new TicketActorNamesV43Migration(this.database).run();
|
|
85
|
+
}
|
|
86
|
+
|
|
66
87
|
/**
|
|
67
88
|
* AGL-909: once, links and release plans name each repository `resolveArg` resolves as `org/name`; answers the keys it
|
|
68
89
|
* changed. With no repository discovered (`discoveredArg` 0) it waits for a later start.
|
package/ts_migration/index.ts
CHANGED
|
@@ -28,4 +28,5 @@ export * from './v39_flexpublicheadpointers.js';
|
|
|
28
28
|
export * from './v41_ticketmigrationmarkers.js';
|
|
29
29
|
export * from './v41_ticketclosedcolumn.js';
|
|
30
30
|
export * from './v41_ticketlinkrepos.js';
|
|
31
|
+
export * from './v43_ticketactornames.js';
|
|
31
32
|
export * from './v43_flexpostharnessmigrationmarkers.js';
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { TicketActivityModel, TicketBoardModel, TicketCommentModel, TicketModel, TicketQuestionModel } from '../ts/classes.ticketmodels.js';
|
|
3
|
+
import { AuthError } from '../ts/interfaces.auth.js';
|
|
4
|
+
import type { ITicketComment } from '../ts_interfaces/tickets.js';
|
|
5
|
+
import { TicketMigrationMarkerModel } from './v41_ticketmigrationmarkers.js';
|
|
6
|
+
|
|
7
|
+
export const ticketActorNamesMigrationId = 'v43_ticketactornames';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The names this migration writes, as AGL-1686 chose them: a session's harness label, keyed by the harness prefix of
|
|
11
|
+
* its session id, and the OpenCode runtime's name. This is the migration's own copy, never the runtime's table: what it
|
|
12
|
+
* wrote stays what it wrote when the runtime's labels change.
|
|
13
|
+
*/
|
|
14
|
+
const sessionLabels = new Map<string, string>([
|
|
15
|
+
['claude', 'Claude Code session'], ['codex', 'Codex session'], ['opencode', 'OpenCode session'], ['flex', 'Flex session'],
|
|
16
|
+
]);
|
|
17
|
+
const openCodeRuntimeName = 'OpenCode';
|
|
18
|
+
/** The keys of a stored person (`ITicketPerson`) or actor (`ITicketActor`, which adds `role`). */
|
|
19
|
+
const personKeys = new Set(['id', 'name', 'kind', 'sessionId', 'role']);
|
|
20
|
+
|
|
21
|
+
/** History records one query reads. */
|
|
22
|
+
const pageRecords = 64;
|
|
23
|
+
/**
|
|
24
|
+
* A transaction's bound. It stops taking a ticket's history records once it has read 256 of them or rewritten 4 MiB
|
|
25
|
+
* of their JSON, and the next transaction goes on after the last one it took. Every transaction that rewrites any of
|
|
26
|
+
* a ticket's records moves that ticket's revision, and the one that takes its last record renames its document. The schema bounds one record (an activity entry holds a ticket's
|
|
27
|
+
* 64 Ki-character texts at most twice, before and after, about 1 MiB in the worst case; a comment 64 KiB of JSON), so a
|
|
28
|
+
* transaction rewrites at most about 6 MiB (the bound, one more record and the comment it holds a copy of, and the
|
|
29
|
+
* ticket's document) and reads at most 256 history records, whatever a ticket's history holds, far inside the engine's
|
|
30
|
+
* 60 s transaction lifetime.
|
|
31
|
+
*/
|
|
32
|
+
const sliceRecords = 256;
|
|
33
|
+
const sliceBytes = 4 * 1024 * 1024;
|
|
34
|
+
|
|
35
|
+
/** What a stored person or actor is named now, or undefined when it keeps its name. */
|
|
36
|
+
const renamedTo = (valueArg: Record<string, unknown>): string | undefined => {
|
|
37
|
+
if (typeof valueArg.id !== 'string' || typeof valueArg.name !== 'string'
|
|
38
|
+
|| !Object.keys(valueArg).every((keyArg) => personKeys.has(keyArg))) return undefined;
|
|
39
|
+
if (valueArg.sessionId !== undefined) {
|
|
40
|
+
if (typeof valueArg.sessionId !== 'string' || valueArg.name !== valueArg.sessionId) return undefined;
|
|
41
|
+
const separator = valueArg.sessionId.indexOf(':');
|
|
42
|
+
return separator > 0 ? sessionLabels.get(valueArg.sessionId.slice(0, separator)) : undefined;
|
|
43
|
+
}
|
|
44
|
+
// The OpenCode runtime's caller was named by its subject kind; no other actor was ever named so.
|
|
45
|
+
return valueArg.name === 'runtime' && valueArg.kind === 'worker' && valueArg.role === 'worker' ? openCodeRuntimeName : undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** `valueArg` with every person and actor in it renamed, at any depth; `valueArg` itself when none is. */
|
|
49
|
+
const renamed = <T>(valueArg: T): T => {
|
|
50
|
+
if (Array.isArray(valueArg)) {
|
|
51
|
+
const items = valueArg.map((itemArg: unknown) => renamed(itemArg));
|
|
52
|
+
return items.some((itemArg, indexArg) => itemArg !== valueArg[indexArg]) ? items as T : valueArg;
|
|
53
|
+
}
|
|
54
|
+
if (typeof valueArg !== 'object' || valueArg === null) return valueArg;
|
|
55
|
+
const record = valueArg as Record<string, unknown>;
|
|
56
|
+
const name = renamedTo(record);
|
|
57
|
+
if (name !== undefined) return { ...record, name } as T;
|
|
58
|
+
const entries = Object.entries(record).map(([keyArg, itemArg]) => [keyArg, renamed(itemArg)] as const);
|
|
59
|
+
return entries.some(([keyArg, itemArg]) => itemArg !== record[keyArg]) ? Object.fromEntries(entries) as T : valueArg;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const jsonBytes = (valueArg: unknown): number => Buffer.byteLength(JSON.stringify(valueArg));
|
|
63
|
+
|
|
64
|
+
/** A ticket's history is taken in this order; `ticket` is its document, taken last. */
|
|
65
|
+
const phases = ['activity', 'questions', 'comments', 'ticket'] as const;
|
|
66
|
+
interface ICursor { phase: (typeof phases)[number]; after?: string }
|
|
67
|
+
interface ISliceResult { cursor: ICursor; moved: boolean }
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* AGL-1686: tickets named the sessions acting on them by their session id (`claude:<uuid>`), and the OpenCode
|
|
71
|
+
* runtime's caller by its subject kind (`runtime`). Once, every person and actor stored in a ticket (its source,
|
|
72
|
+
* creator, last editor and assignee), its comments (author), its questions (asker and answerer) and its activity (actor,
|
|
73
|
+
* and every person in the snapshots its changes hold, the copy of a comment included) whose name is its session id
|
|
74
|
+
* takes its harness's label, and an actor named `runtime` with no session, kind and role `worker` is "OpenCode". Only
|
|
75
|
+
* those names change: ids, session ids and every other value stay, so a 41.1.0 controller reads the result.
|
|
76
|
+
*
|
|
77
|
+
* It works ticket by ticket. A ticket's history, the copy of a comment in its `commented` entry with the comment, and
|
|
78
|
+
* last its document move in one transaction, or, for a history larger than the bound above, in several. Every one of
|
|
79
|
+
* them that rewrites anything of the ticket moves its revision too: the board pump re-reads a ticket only when its
|
|
80
|
+
* revision moved, and no transaction depends on what an earlier one renamed, so a run cut short between them leaves
|
|
81
|
+
* nothing renamed under an unmoved revision. Each transaction that writes fences the board's revision first; none adds history, tells anyone or moves a ticket's
|
|
82
|
+
* column. The marker goes in the transaction that completes the last ticket (alone on an empty board), so a later start
|
|
83
|
+
* does nothing; a run cut short starts again and finds what it renamed already renamed.
|
|
84
|
+
*/
|
|
85
|
+
export class TicketActorNamesV43Migration {
|
|
86
|
+
constructor(private readonly database: plugins.nosqldb.SmartdataDb | undefined) {}
|
|
87
|
+
|
|
88
|
+
/** Runs once; answers the keys of the tickets whose revision it moved. */
|
|
89
|
+
public async run(): Promise<string[]> {
|
|
90
|
+
if (!this.database) throw new AuthError('not_initialized', 'The authentication store database is unavailable.');
|
|
91
|
+
if (await TicketMigrationMarkerModel.exact.findStoredOne({ id: ticketActorNamesMigrationId })) return [];
|
|
92
|
+
const changed: string[] = [];
|
|
93
|
+
const session = this.database.createSession();
|
|
94
|
+
try {
|
|
95
|
+
let after: string | undefined;
|
|
96
|
+
while (true) {
|
|
97
|
+
// Ids only matter here: each ticket is read again inside the transaction that rewrites it.
|
|
98
|
+
const page = await TicketModel.exact.findStored({ filter: after === undefined ? {} : { id: { $gt: after } }, sort: { id: 1 },
|
|
99
|
+
limit: pageRecords + 1 });
|
|
100
|
+
const more = page.length > pageRecords;
|
|
101
|
+
const tickets = page.slice(0, pageRecords).map((recordArg) => recordArg.id);
|
|
102
|
+
if (!tickets.length) {
|
|
103
|
+
// An empty board: the marker alone.
|
|
104
|
+
await this.transaction(session, (transactionArg) => this.slice(transactionArg, undefined, { phase: 'ticket' }, changed));
|
|
105
|
+
return changed;
|
|
106
|
+
}
|
|
107
|
+
for (const [index, ticketId] of tickets.entries()) {
|
|
108
|
+
const last = !more && index === tickets.length - 1;
|
|
109
|
+
let cursor: ICursor = { phase: phases[0] };
|
|
110
|
+
while (true) {
|
|
111
|
+
const result = await this.transaction(session, (transactionArg) => this.slice(transactionArg, ticketId, cursor,
|
|
112
|
+
last ? changed : undefined));
|
|
113
|
+
// A ticket whose history takes several transactions may move its revision in each: it is named once.
|
|
114
|
+
if (result.moved && changed.at(-1) !== ticketId) changed.push(ticketId);
|
|
115
|
+
if (result.cursor.phase === 'ticket') break;
|
|
116
|
+
cursor = result.cursor;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!more) return changed;
|
|
120
|
+
after = tickets.at(-1);
|
|
121
|
+
}
|
|
122
|
+
} finally {
|
|
123
|
+
await session.close();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private async transaction(sessionArg: plugins.nosqldb.SmartdataSession,
|
|
128
|
+
sliceArg: (transactionArg: plugins.nosqldb.SmartdataSession) => Promise<ISliceResult>): Promise<ISliceResult> {
|
|
129
|
+
const result = await sessionArg.withTransaction(sliceArg, { timeoutMS: 60_000 });
|
|
130
|
+
if (!result) throw new AuthError('concurrent_change', 'A transaction of the actor-name migration did not complete.');
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* One transaction: the ticket's history records after `cursorArg` up to the bound, and, once its history is taken,
|
|
136
|
+
* its document. The ticket's revision moves when this transaction rewrote any of its records or renames its document,
|
|
137
|
+
* never because of an earlier one. With `markerArg` (the keys moved so far) the slice that completes the ticket writes the marker; with
|
|
138
|
+
* no ticket it writes the marker alone. Nothing outside the transaction changes here: the driver may run it again.
|
|
139
|
+
*/
|
|
140
|
+
private async slice(sessionArg: plugins.nosqldb.SmartdataSession, ticketIdArg: string | undefined, cursorArg: ICursor,
|
|
141
|
+
markerArg: string[] | undefined): Promise<ISliceResult> {
|
|
142
|
+
const options = { session: sessionArg };
|
|
143
|
+
const board = await TicketBoardModel.exact.findStoredOne({ id: 'global' }, options);
|
|
144
|
+
if (!board) throw new AuthError('not_initialized', 'The ticket board is unavailable.');
|
|
145
|
+
let fenced = false;
|
|
146
|
+
const fence = async (): Promise<void> => {
|
|
147
|
+
if (fenced) return;
|
|
148
|
+
const transitioned = await TicketBoardModel.exact.transition({ current: board, change: (modelArg) => { modelArg.revision += 1; } }, options);
|
|
149
|
+
if (transitioned.status !== 'transitioned') throw new AuthError('concurrent_change', 'The ticket board changed during the actor-name migration.');
|
|
150
|
+
fenced = true;
|
|
151
|
+
};
|
|
152
|
+
let cursor = cursorArg;
|
|
153
|
+
let wrote = false;
|
|
154
|
+
let read = 0;
|
|
155
|
+
let bytes = 0;
|
|
156
|
+
const full = (): boolean => read >= sliceRecords || bytes >= sliceBytes;
|
|
157
|
+
/** Writes one renamed record after fencing the board, and counts it against the bound. */
|
|
158
|
+
const rewrite = async (writeArg: () => Promise<{ status: string }>, nextArg: unknown): Promise<void> => {
|
|
159
|
+
await fence();
|
|
160
|
+
if ((await writeArg()).status !== 'transitioned') throw new AuthError('concurrent_change', 'A ticket changed during the actor-name migration.');
|
|
161
|
+
bytes += jsonBytes(nextArg);
|
|
162
|
+
wrote = true;
|
|
163
|
+
};
|
|
164
|
+
/** Takes a page's records in order until the bound; answers whether the page completed the phase. */
|
|
165
|
+
const take = async <TRecord extends { id: string }>(pageArg: TRecord[], renameArg: (recordArg: TRecord) => Promise<void>): Promise<boolean> => {
|
|
166
|
+
let taken = 0;
|
|
167
|
+
for (const record of pageArg) {
|
|
168
|
+
await renameArg(record);
|
|
169
|
+
read += 1; taken += 1;
|
|
170
|
+
cursor = { phase: cursor.phase, after: record.id };
|
|
171
|
+
if (full()) break;
|
|
172
|
+
}
|
|
173
|
+
return taken === pageArg.length && pageArg.length < pageRecords;
|
|
174
|
+
};
|
|
175
|
+
while (ticketIdArg !== undefined && cursor.phase !== 'ticket' && !full()) {
|
|
176
|
+
const phase = cursor.phase;
|
|
177
|
+
const query = { filter: { ticketId: ticketIdArg, ...(cursor.after === undefined ? {} : { id: { $gt: cursor.after } }) },
|
|
178
|
+
sort: { id: 1 as const }, limit: pageRecords, ...options };
|
|
179
|
+
const complete = phase === 'activity' ? await take(await TicketActivityModel.exact.findStored(query), async (current) => {
|
|
180
|
+
const next = renamed(current.activity);
|
|
181
|
+
if (next === current.activity) return;
|
|
182
|
+
await rewrite(() => TicketActivityModel.exact.transition({ current, change: (modelArg) => { modelArg.activity = next; } }, options), next);
|
|
183
|
+
// A comment and the copy its `commented` entry holds are one: both move in this transaction.
|
|
184
|
+
const copy = next.action === 'commented' ? next.changes.comment?.after as ITicketComment | undefined : undefined;
|
|
185
|
+
if (!copy || copy === current.activity.changes.comment?.after) return;
|
|
186
|
+
const stored = await TicketCommentModel.exact.findStoredOne({ id: copy.id, ticketId: ticketIdArg }, options);
|
|
187
|
+
if (!stored) return;
|
|
188
|
+
const comment = renamed(stored.comment);
|
|
189
|
+
if (comment === stored.comment) return;
|
|
190
|
+
await rewrite(() => TicketCommentModel.exact.transition({ current: stored, change: (modelArg) => { modelArg.comment = comment; } }, options), comment);
|
|
191
|
+
}) : phase === 'questions' ? await take(await TicketQuestionModel.exact.findStored(query), async (current) => {
|
|
192
|
+
const next = renamed(current.question);
|
|
193
|
+
if (next !== current.question) {
|
|
194
|
+
await rewrite(() => TicketQuestionModel.exact.transition({ current, change: (modelArg) => { modelArg.question = next; } }, options), next);
|
|
195
|
+
}
|
|
196
|
+
}) : await take(await TicketCommentModel.exact.findStored(query), async (current) => {
|
|
197
|
+
// A comment whose copy needed no renaming, or that has none: the activity renamed every other one with its copy.
|
|
198
|
+
const next = renamed(current.comment);
|
|
199
|
+
if (next !== current.comment) {
|
|
200
|
+
await rewrite(() => TicketCommentModel.exact.transition({ current, change: (modelArg) => { modelArg.comment = next; } }, options), next);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (complete) cursor = { phase: phases[phases.indexOf(phase) + 1]! };
|
|
204
|
+
}
|
|
205
|
+
let moved = false;
|
|
206
|
+
if (ticketIdArg !== undefined && (wrote || cursor.phase === 'ticket')) {
|
|
207
|
+
const current = await TicketModel.exact.findStoredOne({ id: ticketIdArg }, options);
|
|
208
|
+
if (!current) throw new AuthError('concurrent_change', 'A ticket changed during the actor-name migration.');
|
|
209
|
+
// The document is renamed once its history is; a transaction that rewrote any of its records moves its revision.
|
|
210
|
+
const next = cursor.phase === 'ticket' ? renamed(current.ticket) : current.ticket;
|
|
211
|
+
if (next !== current.ticket || wrote) {
|
|
212
|
+
await rewrite(() => TicketModel.exact.transition({ current, change: (modelArg) => {
|
|
213
|
+
modelArg.ticket = { ...next, revision: (modelArg.ticket.revision ?? 0) + 1 };
|
|
214
|
+
} }, options), next);
|
|
215
|
+
moved = true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (markerArg && cursor.phase === 'ticket') {
|
|
219
|
+
const inserted = await TicketMigrationMarkerModel.exact.insert({ id: ticketActorNamesMigrationId, completedAt: new Date().toISOString(),
|
|
220
|
+
tickets: [...markerArg, ...(moved && markerArg.at(-1) !== ticketIdArg ? [ticketIdArg!] : [])] }, options);
|
|
221
|
+
if (inserted.status !== 'inserted') throw new AuthError('concurrent_change', 'The actor-name migration ran twice.');
|
|
222
|
+
}
|
|
223
|
+
return { cursor, moved };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -13,9 +13,11 @@ import * as authswitchUsageLimit from '../ts_authswitch/authority-usagelimit.js'
|
|
|
13
13
|
import * as authswitchSubscription from '../ts_authswitch/authority-subscription.js';
|
|
14
14
|
// An API key's month: the spend limit rule and dollar amounts, as the command line states them; it imports nothing.
|
|
15
15
|
import * as authswitchSpend from '../ts_authswitch/authority-spend.js';
|
|
16
|
+
// A Claude sign-in's monthly renewal: its next one, rolled forward as placement rolls it; it imports nothing.
|
|
17
|
+
import * as authswitchRenewal from '../ts_authswitch/authority-renewal.js';
|
|
16
18
|
// The service's contract, which the controller's interfaces load already: the processes holding a Claude sign-in, in
|
|
17
19
|
// the words the command line uses.
|
|
18
20
|
import * as authswitchAuthority from '../ts_authswitch/authority-contract.js';
|
|
19
21
|
|
|
20
|
-
export { authswitchAuthority, authswitchPreuseText, authswitchSpend, authswitchSubscription,
|
|
21
|
-
authswitchUsageWindows };
|
|
22
|
+
export { authswitchAuthority, authswitchPreuseText, authswitchRenewal, authswitchSpend, authswitchSubscription,
|
|
23
|
+
authswitchUsageLimit, authswitchUsageWindows };
|
|
@@ -147,6 +147,8 @@ export type TAccountActionId =
|
|
|
147
147
|
| 'spendLimit'
|
|
148
148
|
| 'clearSpendLimit'
|
|
149
149
|
| 'claudeCode'
|
|
150
|
+
| 'renewal'
|
|
151
|
+
| 'clearRenewal'
|
|
150
152
|
| 'addApiKey'
|
|
151
153
|
| 'remove'
|
|
152
154
|
| 'usage'
|
|
@@ -356,6 +358,11 @@ export interface IAccountRow {
|
|
|
356
358
|
spendLimitMicroUsd: number | null;
|
|
357
359
|
/** Whether the account may serve Claude Code (AGL-1146); always `true` for a sign-in. */
|
|
358
360
|
claudeCode: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* The anchor of a Claude sign-in's monthly renewal as its owner set it (ISO 8601 UTC, AGL-1644), or `null` without
|
|
363
|
+
* one and for every other account.
|
|
364
|
+
*/
|
|
365
|
+
renewsAt: string | null;
|
|
359
366
|
/** What a removal does that the owner must know, said with the removal; empty for a sign-in. */
|
|
360
367
|
removeNote: string;
|
|
361
368
|
label: string;
|
|
@@ -1353,6 +1360,27 @@ const identityText = (emailArg: string | null | undefined, planArg: string | nul
|
|
|
1353
1360
|
`${emailArg || 'No email reported'} · ${planArg ? `${planArg} plan` : 'plan not reported'}`
|
|
1354
1361
|
);
|
|
1355
1362
|
|
|
1363
|
+
/**
|
|
1364
|
+
* What the Details say of a Claude sign-in's renewal: the next one, rolled forward from the anchor its owner set as
|
|
1365
|
+
* placement rolls it, or that none is set. AGL derives no renewal from what Claude states.
|
|
1366
|
+
*/
|
|
1367
|
+
export const renewalFact = (renewsAtArg: string | null, nowArg: number): string => {
|
|
1368
|
+
const renewal = plugins.authswitchRenewal.authSwitchRenewal(renewsAtArg, nowArg);
|
|
1369
|
+
return renewal === null ? 'Not set'
|
|
1370
|
+
: `${plugins.authswitchPreuseText.localDateTime(renewal.at)}, monthly (set by you)`;
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* Why a renewal draft cannot be saved yet, or `''` when it can: a date and time the service's own rule reads, other
|
|
1375
|
+
* than the renewal the account has. A past one is valid: the next renewal is a whole number of months after it.
|
|
1376
|
+
*/
|
|
1377
|
+
export const renewalReason = (draftArg: string, currentArg: string | null): string => {
|
|
1378
|
+
const draft = draftArg.trim();
|
|
1379
|
+
if (draft.length === 0) return 'Enter a date and time.';
|
|
1380
|
+
if (!interfaces.isControllerRenewsAt(draft)) return 'Enter a date and time, year first, such as 2026-11-20 09:30.';
|
|
1381
|
+
return currentArg !== null && Date.parse(draft) === Date.parse(currentArg) ? 'The renewal is unchanged.' : '';
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1356
1384
|
/** What the Details say of an account's usage threshold. */
|
|
1357
1385
|
const maxUsageFact = (maxUsagePercentArg: number | null): string => maxUsagePercentArg === null
|
|
1358
1386
|
? 'Not set'
|
|
@@ -1530,6 +1558,7 @@ const serviceRow = (
|
|
|
1530
1558
|
const payment = accountArg.removed || usageRead?.state !== 'read' ? null
|
|
1531
1559
|
: paymentView(accountArg, usageRead.usage, contextArg.now);
|
|
1532
1560
|
const apiKey = isApiKeyAccount(accountArg);
|
|
1561
|
+
const claudeSignIn = !apiKey && accountArg.providerId === 'anthropic';
|
|
1533
1562
|
const provider = keyProvider(accountArg.providerId);
|
|
1534
1563
|
const identity = apiKey ? keyIdentityText(accountArg) : identityText(accountArg.email, accountArg.plan);
|
|
1535
1564
|
const liftedUntil = !accountArg.removed && accountArg.maxUsagePercent !== null
|
|
@@ -1545,6 +1574,7 @@ const serviceRow = (
|
|
|
1545
1574
|
apiKey,
|
|
1546
1575
|
spendLimitMicroUsd: apiKey ? accountArg.spendLimitMicroUsd : null,
|
|
1547
1576
|
claudeCode: accountArg.claudeCode,
|
|
1577
|
+
renewsAt: claudeSignIn ? accountArg.renewsAt : null,
|
|
1548
1578
|
removeNote: apiKey
|
|
1549
1579
|
? `AGL stops using the key. It stays valid at ${provider.name} until you revoke it in ${provider.console}.`
|
|
1550
1580
|
: '',
|
|
@@ -1599,6 +1629,8 @@ const serviceRow = (
|
|
|
1599
1629
|
: [serviceSlot('maxUsage', 'Max usage', 'lucide:SlidersHorizontal', contextArg.service, removed)]),
|
|
1600
1630
|
...(!apiKey && accountArg.maxUsagePercent !== null && accountArg.maxUsagePercent < 100
|
|
1601
1631
|
? [serviceSlot('liftReserve', 'Lift reserve', 'lucide:Clock', contextArg.service, removed)] : []),
|
|
1632
|
+
// A renewal is a Claude subscription's: neither a key nor a ChatGPT account has one to set.
|
|
1633
|
+
...(claudeSignIn ? [serviceSlot('renewal', 'Renewal', 'lucide:CalendarClock', contextArg.service, removed)] : []),
|
|
1602
1634
|
serviceSlot('remove', 'Remove', 'lucide:Trash2', contextArg.service, removed),
|
|
1603
1635
|
...(usageLogin ? [serviceSlot('usage', 'Show latest usage', 'lucide:Gauge', contextArg.service)] : []),
|
|
1604
1636
|
...(usageLogin && payment ? [serviceSlot('recheck', 'Re-check', 'lucide:RotateCcw', contextArg.service)] : []),
|
|
@@ -1616,6 +1648,7 @@ const serviceRow = (
|
|
|
1616
1648
|
apiKey ? { label: 'Monthly spend limit', value: spendLimitText(accountArg.spendLimitMicroUsd) }
|
|
1617
1649
|
: { label: 'Max usage', value: maxUsageFact(accountArg.maxUsagePercent) },
|
|
1618
1650
|
...(apiKey ? [{ label: 'Claude Code', value: claudeCodeText(accountArg.claudeCode) }] : []),
|
|
1651
|
+
...(claudeSignIn ? [{ label: 'Renews', value: renewalFact(accountArg.renewsAt, contextArg.now) }] : []),
|
|
1619
1652
|
{ label: 'Account reference', value: accountArg.id },
|
|
1620
1653
|
],
|
|
1621
1654
|
accountId: accountArg.id,
|
|
@@ -11,6 +11,8 @@ type TPaintOpen = interfaces.IReq_ControllerBrowserPaintOpen['response'];
|
|
|
11
11
|
|
|
12
12
|
/** Original-video route requests kept while a Paint stream is still opening; it binds at most four. */
|
|
13
13
|
const maximumPendingVideoRoutes = 4;
|
|
14
|
+
/** The operation a failed original-video route of the run on screen reports. */
|
|
15
|
+
const pageVideoOperation = 'Show the page\'s video in Paint';
|
|
14
16
|
|
|
15
17
|
/** The controller requests this presentation issues, with the socket client's fire options. */
|
|
16
18
|
export interface IBrowserPresentationSocket {
|
|
@@ -214,7 +216,7 @@ export class ControllerBrowserPresentation {
|
|
|
214
216
|
const paint = this.paint;
|
|
215
217
|
if (paint && paint.response.paintId === eventArg.paintId) {
|
|
216
218
|
void this.openVideoRoute(paint, eventArg.routeId).catch((errorArg) => {
|
|
217
|
-
if (this.isCurrentPaint(paint)) this.options.onError(
|
|
219
|
+
if (this.isCurrentPaint(paint)) this.options.onError(pageVideoOperation, errorArg);
|
|
218
220
|
});
|
|
219
221
|
return;
|
|
220
222
|
}
|
|
@@ -330,7 +332,7 @@ export class ControllerBrowserPresentation {
|
|
|
330
332
|
for (const pending of this.pendingVideoRoutes.splice(0)) {
|
|
331
333
|
if (pending.paintId === opened.paintId) {
|
|
332
334
|
void this.openVideoRoute(paint, pending.routeId).catch((errorArg) => {
|
|
333
|
-
if (this.isCurrentPaint(paint)) this.options.onError(
|
|
335
|
+
if (this.isCurrentPaint(paint)) this.options.onError(pageVideoOperation, errorArg);
|
|
334
336
|
});
|
|
335
337
|
}
|
|
336
338
|
}
|
|
@@ -435,10 +437,13 @@ export class ControllerBrowserPresentation {
|
|
|
435
437
|
// keeps running and the next route mounts on it.
|
|
436
438
|
onEnded: () => { paintArg.routes.delete(mount); },
|
|
437
439
|
// A broken route closes only its own decoders; the renderer keeps running. A route of a
|
|
438
|
-
// stopping, replaced or closed run is not this view's fault.
|
|
439
|
-
|
|
440
|
+
// stopping, replaced or closed run is not this view's fault. Every reason of the run on
|
|
441
|
+
// screen is reported: SmartBrowser never reports this view's own close of a route (its
|
|
442
|
+
// abort signal or `close()`), so `fenced` is the host's revocation or a pair broken
|
|
443
|
+
// underneath it, `protocol` a broken route and `worker` a failed worker request.
|
|
444
|
+
onFailure: (errorArg: plugins.PaintVideoRouteError) => {
|
|
440
445
|
paintArg.routes.delete(mount);
|
|
441
|
-
if (this.isCurrentPaint(paintArg)) this.options.onError(
|
|
446
|
+
if (this.isCurrentPaint(paintArg)) this.options.onError(pageVideoOperation, errorArg);
|
|
442
447
|
},
|
|
443
448
|
});
|
|
444
449
|
paintArg.routes.add(mount);
|