agl 1.0.17 → 21.0.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.
Files changed (277) hide show
  1. package/.smartconfig.json +55 -0
  2. package/changelog.md +1026 -0
  3. package/cli.js +14 -0
  4. package/dist_serve/bundle.js +44778 -0
  5. package/dist_serve/index.html +13 -0
  6. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  7. package/dist_ts/00_commitinfo_data.js +9 -0
  8. package/dist_ts/classes.authmodels.d.ts +126 -0
  9. package/dist_ts/classes.authmodels.js +1422 -0
  10. package/dist_ts/classes.authstore.d.ts +160 -0
  11. package/dist_ts/classes.authstore.js +2483 -0
  12. package/dist_ts/classes.browserresourcehost.d.ts +85 -0
  13. package/dist_ts/classes.browserresourcehost.js +912 -0
  14. package/dist_ts/classes.cli.d.ts +21 -0
  15. package/dist_ts/classes.cli.js +1082 -0
  16. package/dist_ts/classes.config.d.ts +23 -0
  17. package/dist_ts/classes.config.js +267 -0
  18. package/dist_ts/classes.controller.d.ts +523 -0
  19. package/dist_ts/classes.controller.js +10611 -0
  20. package/dist_ts/classes.controllermanagement.d.ts +32 -0
  21. package/dist_ts/classes.controllermanagement.js +222 -0
  22. package/dist_ts/classes.draftmanager.d.ts +30 -0
  23. package/dist_ts/classes.draftmanager.js +179 -0
  24. package/dist_ts/classes.embeddeddb.d.ts +30 -0
  25. package/dist_ts/classes.embeddeddb.js +159 -0
  26. package/dist_ts/classes.flexframedtransport.d.ts +56 -0
  27. package/dist_ts/classes.flexframedtransport.js +275 -0
  28. package/dist_ts/classes.flexmodels.private.d.ts +231 -0
  29. package/dist_ts/classes.flexmodels.private.js +985 -0
  30. package/dist_ts/classes.flexmodels.public.d.ts +207 -0
  31. package/dist_ts/classes.flexmodels.public.js +885 -0
  32. package/dist_ts/classes.flexprojectionreader.d.ts +89 -0
  33. package/dist_ts/classes.flexprojectionreader.js +580 -0
  34. package/dist_ts/classes.flexservice.d.ts +196 -0
  35. package/dist_ts/classes.flexservice.js +3704 -0
  36. package/dist_ts/classes.flexstore.d.ts +174 -0
  37. package/dist_ts/classes.flexstore.js +3400 -0
  38. package/dist_ts/classes.flexsupervisor.d.ts +105 -0
  39. package/dist_ts/classes.flexsupervisor.js +1191 -0
  40. package/dist_ts/classes.gitreversion.d.ts +431 -0
  41. package/dist_ts/classes.gitreversion.js +10592 -0
  42. package/dist_ts/classes.harnessoperationmanager.d.ts +113 -0
  43. package/dist_ts/classes.harnessoperationmanager.js +602 -0
  44. package/dist_ts/classes.opencodeclient.d.ts +146 -0
  45. package/dist_ts/classes.opencodeclient.js +3003 -0
  46. package/dist_ts/classes.opencodesupervisor.d.ts +60 -0
  47. package/dist_ts/classes.opencodesupervisor.js +1003 -0
  48. package/dist_ts/classes.passkeymanager.d.ts +34 -0
  49. package/dist_ts/classes.passkeymanager.js +456 -0
  50. package/dist_ts/classes.processinspection.d.ts +50 -0
  51. package/dist_ts/classes.processinspection.js +484 -0
  52. package/dist_ts/classes.resourcecoordinator.d.ts +64 -0
  53. package/dist_ts/classes.resourcecoordinator.js +294 -0
  54. package/dist_ts/classes.sessionintelligencereader.d.ts +13 -0
  55. package/dist_ts/classes.sessionintelligencereader.js +40 -0
  56. package/dist_ts/classes.systemmetricssampler.d.ts +53 -0
  57. package/dist_ts/classes.systemmetricssampler.js +168 -0
  58. package/dist_ts/classes.terminalmanager.d.ts +95 -0
  59. package/dist_ts/classes.terminalmanager.js +981 -0
  60. package/dist_ts/classes.terminalresourcehost.d.ts +20 -0
  61. package/dist_ts/classes.terminalresourcehost.js +84 -0
  62. package/dist_ts/classes.upgradecoordinator.d.ts +244 -0
  63. package/dist_ts/classes.upgradecoordinator.js +2155 -0
  64. package/dist_ts/classes.upgradetransaction.d.ts +92 -0
  65. package/dist_ts/classes.upgradetransaction.js +2125 -0
  66. package/dist_ts/classes.uploadmanager.d.ts +24 -0
  67. package/dist_ts/classes.uploadmanager.js +210 -0
  68. package/dist_ts/classes.validation.d.ts +91 -0
  69. package/dist_ts/classes.validation.js +1087 -0
  70. package/dist_ts/flexharness.child.d.ts +1 -0
  71. package/dist_ts/flexharness.child.js +28 -0
  72. package/dist_ts/functions.canonicaldirectory.d.ts +21 -0
  73. package/dist_ts/functions.canonicaldirectory.js +144 -0
  74. package/dist_ts/functions.controllerdataroot.d.ts +15 -0
  75. package/dist_ts/functions.controllerdataroot.js +76 -0
  76. package/dist_ts/functions.embeddeddb.d.ts +2 -0
  77. package/dist_ts/functions.embeddeddb.js +21 -0
  78. package/dist_ts/functions.flexcredentialstore.d.ts +16 -0
  79. package/dist_ts/functions.flexcredentialstore.js +93 -0
  80. package/dist_ts/functions.opencodeauth.d.ts +3 -0
  81. package/dist_ts/functions.opencodeauth.js +31 -0
  82. package/dist_ts/functions.runtimeenvironment.d.ts +2 -0
  83. package/dist_ts/functions.runtimeenvironment.js +79 -0
  84. package/dist_ts/functions.upgradefollower.d.ts +3 -0
  85. package/dist_ts/functions.upgradefollower.js +95 -0
  86. package/dist_ts/index.d.ts +24 -0
  87. package/dist_ts/index.js +25 -0
  88. package/dist_ts/interfaces.auth.d.ts +181 -0
  89. package/dist_ts/interfaces.auth.js +82 -0
  90. package/dist_ts/interfaces.config.d.ts +34 -0
  91. package/dist_ts/interfaces.config.js +2 -0
  92. package/dist_ts/interfaces.flexipc.d.ts +939 -0
  93. package/dist_ts/interfaces.flexipc.js +1492 -0
  94. package/dist_ts/interfaces.gitreversion.d.ts +246 -0
  95. package/dist_ts/interfaces.gitreversion.js +2 -0
  96. package/dist_ts/interfaces.lifecycle.d.ts +37 -0
  97. package/dist_ts/interfaces.lifecycle.js +2 -0
  98. package/dist_ts/interfaces.opencode.d.ts +101 -0
  99. package/dist_ts/interfaces.opencode.js +3 -0
  100. package/dist_ts/interfaces.projects.d.ts +156 -0
  101. package/dist_ts/interfaces.projects.js +5 -0
  102. package/dist_ts/plugins.d.ts +36 -0
  103. package/dist_ts/plugins.js +40 -0
  104. package/dist_ts_interfaces/index.d.ts +2 -0
  105. package/dist_ts_interfaces/index.js +3 -0
  106. package/dist_ts_interfaces/interfaces.d.ts +747 -0
  107. package/dist_ts_interfaces/interfaces.js +47 -0
  108. package/dist_ts_interfaces/plugins.d.ts +4 -0
  109. package/dist_ts_interfaces/plugins.js +3 -0
  110. package/dist_ts_interfaces/requests.d.ts +806 -0
  111. package/dist_ts_interfaces/requests.js +2 -0
  112. package/dist_ts_migration/classes.documentmigrationrunner.d.ts +8 -0
  113. package/dist_ts_migration/classes.documentmigrationrunner.js +24 -0
  114. package/dist_ts_migration/classes.flexmigrationrunner.d.ts +11 -0
  115. package/dist_ts_migration/classes.flexmigrationrunner.js +25 -0
  116. package/dist_ts_migration/classes.flexpostharnessmigrationrunner.d.ts +10 -0
  117. package/dist_ts_migration/classes.flexpostharnessmigrationrunner.js +15 -0
  118. package/dist_ts_migration/classes.migrationrunner.d.ts +8 -0
  119. package/dist_ts_migration/classes.migrationrunner.js +34 -0
  120. package/dist_ts_migration/index.d.ts +12 -0
  121. package/dist_ts_migration/index.js +13 -0
  122. package/dist_ts_migration/v10_flexharnessv3migration.d.ts +11 -0
  123. package/dist_ts_migration/v10_flexharnessv3migration.js +23 -0
  124. package/dist_ts_migration/v13_flexprojectionorder.d.ts +11 -0
  125. package/dist_ts_migration/v13_flexprojectionorder.js +23 -0
  126. package/dist_ts_migration/v16_flexprovidercredentials.d.ts +22 -0
  127. package/dist_ts_migration/v16_flexprovidercredentials.js +149 -0
  128. package/dist_ts_migration/v18_resourcelayout.d.ts +22 -0
  129. package/dist_ts_migration/v18_resourcelayout.js +23 -0
  130. package/dist_ts_migration/v18_resourcelayoutmigration.d.ts +6 -0
  131. package/dist_ts_migration/v18_resourcelayoutmigration.js +61 -0
  132. package/dist_ts_migration/v19_flexprojectmanagement.d.ts +11 -0
  133. package/dist_ts_migration/v19_flexprojectmanagement.js +21 -0
  134. package/dist_ts_migration/v1_embeddeddatabaselocation.d.ts +28 -0
  135. package/dist_ts_migration/v1_embeddeddatabaselocation.js +415 -0
  136. package/dist_ts_migration/v22_projectfilesystemidentitymigration.d.ts +7 -0
  137. package/dist_ts_migration/v22_projectfilesystemidentitymigration.js +105 -0
  138. package/dist_ts_migration/v2_controllerdataroot.d.ts +130 -0
  139. package/dist_ts_migration/v2_controllerdataroot.js +1887 -0
  140. package/dist_ts_migration/v6_protocoldocumentmigration.d.ts +7 -0
  141. package/dist_ts_migration/v6_protocoldocumentmigration.js +100 -0
  142. package/dist_ts_migration/v6_protocoldocuments.d.ts +7 -0
  143. package/dist_ts_migration/v6_protocoldocuments.js +138 -0
  144. package/html/index.html +13 -0
  145. package/{LICENSE → license.md} +2 -2
  146. package/package.json +86 -48
  147. package/readme.md +480 -0
  148. package/readme.plan.md +188 -0
  149. package/ts/00_commitinfo_data.ts +8 -0
  150. package/ts/classes.authmodels.ts +1245 -0
  151. package/ts/classes.authstore.ts +3274 -0
  152. package/ts/classes.browserresourcehost.ts +1205 -0
  153. package/ts/classes.cli.ts +1254 -0
  154. package/ts/classes.config.ts +351 -0
  155. package/ts/classes.controller.ts +14426 -0
  156. package/ts/classes.controllermanagement.ts +330 -0
  157. package/ts/classes.draftmanager.ts +232 -0
  158. package/ts/classes.embeddeddb.ts +166 -0
  159. package/ts/classes.flexframedtransport.ts +283 -0
  160. package/ts/classes.flexmodels.private.ts +823 -0
  161. package/ts/classes.flexmodels.public.ts +732 -0
  162. package/ts/classes.flexprojectionreader.ts +816 -0
  163. package/ts/classes.flexservice.ts +4302 -0
  164. package/ts/classes.flexstore.ts +4565 -0
  165. package/ts/classes.flexsupervisor.ts +1453 -0
  166. package/ts/classes.gitreversion.ts +13353 -0
  167. package/ts/classes.harnessoperationmanager.ts +870 -0
  168. package/ts/classes.opencodeclient.ts +4110 -0
  169. package/ts/classes.opencodesupervisor.ts +1280 -0
  170. package/ts/classes.passkeymanager.ts +570 -0
  171. package/ts/classes.processinspection.ts +623 -0
  172. package/ts/classes.resourcecoordinator.ts +436 -0
  173. package/ts/classes.sessionintelligencereader.ts +52 -0
  174. package/ts/classes.systemmetricssampler.ts +215 -0
  175. package/ts/classes.terminalmanager.ts +1207 -0
  176. package/ts/classes.terminalresourcehost.ts +122 -0
  177. package/ts/classes.upgradecoordinator.ts +2675 -0
  178. package/ts/classes.upgradetransaction.ts +2900 -0
  179. package/ts/classes.uploadmanager.ts +240 -0
  180. package/ts/classes.validation.ts +1409 -0
  181. package/ts/flexharness.child.ts +35 -0
  182. package/ts/functions.canonicaldirectory.ts +213 -0
  183. package/ts/functions.controllerdataroot.ts +107 -0
  184. package/ts/functions.embeddeddb.ts +22 -0
  185. package/ts/functions.flexcredentialstore.ts +128 -0
  186. package/ts/functions.opencodeauth.ts +34 -0
  187. package/ts/functions.runtimeenvironment.ts +90 -0
  188. package/ts/functions.upgradefollower.ts +115 -0
  189. package/ts/index.ts +36 -6
  190. package/ts/interfaces.auth.ts +316 -0
  191. package/ts/interfaces.config.ts +37 -0
  192. package/ts/interfaces.flexipc.ts +2586 -0
  193. package/ts/interfaces.gitreversion.ts +336 -0
  194. package/ts/interfaces.lifecycle.ts +46 -0
  195. package/ts/interfaces.opencode.ts +153 -0
  196. package/ts/interfaces.projects.ts +182 -0
  197. package/ts/plugins.ts +64 -0
  198. package/ts_interfaces/index.ts +2 -0
  199. package/ts_interfaces/interfaces.ts +827 -0
  200. package/ts_interfaces/plugins.ts +15 -0
  201. package/ts_interfaces/requests.ts +1186 -0
  202. package/ts_migration/classes.documentmigrationrunner.ts +32 -0
  203. package/ts_migration/classes.flexmigrationrunner.ts +33 -0
  204. package/ts_migration/classes.flexpostharnessmigrationrunner.ts +22 -0
  205. package/ts_migration/classes.migrationrunner.ts +40 -0
  206. package/ts_migration/index.ts +12 -0
  207. package/ts_migration/v10_flexharnessv3migration.ts +35 -0
  208. package/ts_migration/v13_flexprojectionorder.ts +33 -0
  209. package/ts_migration/v16_flexprovidercredentials.ts +196 -0
  210. package/ts_migration/v18_resourcelayout.ts +55 -0
  211. package/ts_migration/v18_resourcelayoutmigration.ts +68 -0
  212. package/ts_migration/v19_flexprojectmanagement.ts +28 -0
  213. package/ts_migration/v1_embeddeddatabaselocation.ts +560 -0
  214. package/ts_migration/v22_projectfilesystemidentitymigration.ts +121 -0
  215. package/ts_migration/v2_controllerdataroot.ts +2349 -0
  216. package/ts_migration/v6_protocoldocumentmigration.ts +144 -0
  217. package/ts_migration/v6_protocoldocuments.ts +198 -0
  218. package/ts_web/00_commitinfo_data.ts +8 -0
  219. package/ts_web/classes.controllersocketclient.ts +517 -0
  220. package/ts_web/classes.sessiondraftsync.ts +390 -0
  221. package/ts_web/elements.harnesscontrollerapp.ts +11494 -0
  222. package/ts_web/index.ts +2 -0
  223. package/ts_web/plugins.ts +31 -0
  224. package/.gitlab-ci.yml +0 -71
  225. package/.npmignore +0 -5
  226. package/README.md +0 -40
  227. package/dist/cli.js +0 -2
  228. package/dist/index.d.ts +0 -0
  229. package/dist/index.js +0 -9
  230. package/dist/mod_bundle/index.d.ts +0 -1
  231. package/dist/mod_bundle/index.js +0 -18
  232. package/dist/mod_bundle/mod.plugins.d.ts +0 -4
  233. package/dist/mod_bundle/mod.plugins.js +0 -11
  234. package/dist/mod_install/index.d.ts +0 -4
  235. package/dist/mod_install/index.js +0 -21
  236. package/dist/mod_install/mod.plugins.d.ts +0 -1
  237. package/dist/mod_install/mod.plugins.js +0 -7
  238. package/dist/mod_standard/index.d.ts +0 -4
  239. package/dist/mod_standard/index.js +0 -21
  240. package/dist/mod_standard/mod.browser.d.ts +0 -6
  241. package/dist/mod_standard/mod.browser.js +0 -14
  242. package/dist/mod_standard/mod.clean.d.ts +0 -4
  243. package/dist/mod_standard/mod.clean.js +0 -12
  244. package/dist/mod_standard/mod.compile.d.ts +0 -4
  245. package/dist/mod_standard/mod.compile.js +0 -21
  246. package/dist/mod_standard/mod.plugins.d.ts +0 -8
  247. package/dist/mod_standard/mod.plugins.js +0 -19
  248. package/dist/mod_standard/mod.test.d.ts +0 -4
  249. package/dist/mod_standard/mod.test.js +0 -12
  250. package/dist/plr.cli.d.ts +0 -3
  251. package/dist/plr.cli.js +0 -57
  252. package/dist/plr.config.d.ts +0 -11
  253. package/dist/plr.config.js +0 -26
  254. package/dist/plr.mods.d.ts +0 -17
  255. package/dist/plr.mods.js +0 -17
  256. package/dist/plr.paths.d.ts +0 -19
  257. package/dist/plr.paths.js +0 -26
  258. package/dist/plr.plugins.d.ts +0 -8
  259. package/dist/plr.plugins.js +0 -16
  260. package/npmextra.json +0 -10
  261. package/ts/mod_bundle/index.ts +0 -20
  262. package/ts/mod_bundle/mod.plugins.ts +0 -9
  263. package/ts/mod_install/index.ts +0 -20
  264. package/ts/mod_install/mod.plugins.ts +0 -1
  265. package/ts/mod_standard/index.ts +0 -23
  266. package/ts/mod_standard/mod.browser.ts +0 -17
  267. package/ts/mod_standard/mod.clean.ts +0 -13
  268. package/ts/mod_standard/mod.compile.ts +0 -23
  269. package/ts/mod_standard/mod.plugins.ts +0 -17
  270. package/ts/mod_standard/mod.test.ts +0 -13
  271. package/ts/plr.cli.ts +0 -60
  272. package/ts/plr.config.ts +0 -36
  273. package/ts/plr.mods.ts +0 -25
  274. package/ts/plr.paths.ts +0 -29
  275. package/ts/plr.plugins.ts +0 -17
  276. package/tslint.json +0 -3
  277. package/yarn.lock +0 -3464
@@ -0,0 +1,32 @@
1
+ import * as plugins from '../ts/plugins.js';
2
+ import { ProtocolV6DocumentMigration } from './v6_protocoldocumentmigration.js';
3
+ import { ProtocolV18ResourceLayoutMigration } from './v18_resourcelayoutmigration.js';
4
+ import { ProtocolV22ProjectFilesystemIdentityMigration } from './v22_projectfilesystemidentitymigration.js';
5
+
6
+ interface IDocumentMigration {
7
+ run(): Promise<void>;
8
+ }
9
+
10
+ export class PostDatabaseDocumentMigrationRunner {
11
+ private readonly migrations: IDocumentMigration[];
12
+
13
+ constructor(private readonly database: plugins.smartdata.SmartdataDb | undefined) {
14
+ this.migrations = [
15
+ new ProtocolV6DocumentMigration(this.database),
16
+ new ProtocolV18ResourceLayoutMigration(this.database),
17
+ ];
18
+ }
19
+
20
+ public async run(): Promise<void> {
21
+ for (const migration of this.migrations) {
22
+ await migration.run();
23
+ }
24
+ }
25
+
26
+ public async runProjectFilesystemIdentity(controllerIdArg: string): Promise<void> {
27
+ await new ProtocolV22ProjectFilesystemIdentityMigration(
28
+ this.database,
29
+ controllerIdArg,
30
+ ).run();
31
+ }
32
+ }
@@ -0,0 +1,33 @@
1
+ import type { FlexStore } from '../ts/classes.flexstore.js';
2
+ import { FlexHarnessV3MigrationRunner } from './v10_flexharnessv3migration.js';
3
+ import { FlexProjectionOrderMigration } from './v13_flexprojectionorder.js';
4
+
5
+ export interface IFlexPersistenceMigrationOptions {
6
+ store: FlexStore;
7
+ storageKeys: Iterable<string>;
8
+ }
9
+
10
+ export class FlexPersistenceMigrationRunner {
11
+ private readonly store: FlexStore;
12
+ private readonly storageKeys: string[];
13
+
14
+ constructor(optionsArg: IFlexPersistenceMigrationOptions) {
15
+ this.store = optionsArg.store;
16
+ this.storageKeys = [...new Set(optionsArg.storageKeys)].sort();
17
+ }
18
+
19
+ public async run(signalArg?: AbortSignal): Promise<void> {
20
+ await new FlexHarnessV3MigrationRunner({
21
+ store: this.store,
22
+ storageKeys: this.storageKeys,
23
+ }).run(signalArg);
24
+ await new FlexProjectionOrderMigration({
25
+ store: this.store,
26
+ storageKeys: this.storageKeys,
27
+ }).run(signalArg);
28
+ for (const storageKey of this.storageKeys) {
29
+ signalArg?.throwIfAborted();
30
+ await this.store.ensurePublicProjection(storageKey);
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,22 @@
1
+ import * as plugins from '../ts/plugins.js';
2
+ import { FlexProjectManagementMigration } from './v19_flexprojectmanagement.js';
3
+
4
+ export interface IFlexPostHarnessMigrationRunnerOptions<TScope> {
5
+ harness: plugins.flexharness.FlexHarness<TScope>;
6
+ scopeIds: Iterable<string>;
7
+ }
8
+
9
+ export class FlexPostHarnessMigrationRunner<TScope> {
10
+ private readonly migrations: Array<{ run(signalArg?: AbortSignal): Promise<void> }>;
11
+
12
+ constructor(optionsArg: IFlexPostHarnessMigrationRunnerOptions<TScope>) {
13
+ this.migrations = [new FlexProjectManagementMigration(optionsArg)];
14
+ }
15
+
16
+ public async run(signalArg?: AbortSignal): Promise<void> {
17
+ for (const migration of this.migrations) {
18
+ signalArg?.throwIfAborted();
19
+ await migration.run(signalArg);
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,40 @@
1
+ import {
2
+ EmbeddedDatabaseLocationMigration,
3
+ type IEmbeddedDatabaseLocationMigrationOptions,
4
+ type IEmbeddedDatabaseLocationMigrationResult,
5
+ } from './v1_embeddeddatabaselocation.js';
6
+
7
+ export class EmbeddedDatabaseMigrationRunner {
8
+ private readonly migrations: EmbeddedDatabaseLocationMigration[];
9
+
10
+ constructor(optionsArg: IEmbeddedDatabaseLocationMigrationOptions) {
11
+ this.migrations = [new EmbeddedDatabaseLocationMigration(optionsArg)];
12
+ }
13
+
14
+ public get hasOwnedResources(): boolean {
15
+ return this.migrations.some((migration) => migration.hasOwnedResources);
16
+ }
17
+
18
+ public async run(): Promise<IEmbeddedDatabaseLocationMigrationResult | undefined> {
19
+ let result: IEmbeddedDatabaseLocationMigrationResult | undefined;
20
+ for (const migration of this.migrations) {
21
+ result = await migration.run() ?? result;
22
+ }
23
+ return result;
24
+ }
25
+
26
+ public async stop(): Promise<void> {
27
+ const errors: unknown[] = [];
28
+ for (const migration of [...this.migrations].reverse()) {
29
+ try {
30
+ await migration.stop();
31
+ } catch (errorArg) {
32
+ errors.push(errorArg);
33
+ }
34
+ }
35
+ if (errors.length === 1) throw errors[0];
36
+ if (errors.length > 1) {
37
+ throw new AggregateError(errors, 'Embedded database migration runner cleanup failed.');
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,12 @@
1
+ export * from './classes.migrationrunner.js';
2
+ export * from './classes.flexmigrationrunner.js';
3
+ export * from './v1_embeddeddatabaselocation.js';
4
+ export * from './v2_controllerdataroot.js';
5
+ export * from './v10_flexharnessv3migration.js';
6
+ export * from './v13_flexprojectionorder.js';
7
+ export * from './v16_flexprovidercredentials.js';
8
+ export * from './v18_resourcelayout.js';
9
+ export * from './v18_resourcelayoutmigration.js';
10
+ export * from './classes.flexpostharnessmigrationrunner.js';
11
+ export * from './v19_flexprojectmanagement.js';
12
+ export * from './v22_projectfilesystemidentitymigration.js';
@@ -0,0 +1,35 @@
1
+ import * as plugins from '../ts/plugins.js';
2
+ import type { FlexStore } from '../ts/classes.flexstore.js';
3
+
4
+ export interface IFlexHarnessV3MigrationOptions {
5
+ store: FlexStore;
6
+ storageKeys: Iterable<string>;
7
+ }
8
+
9
+ export class FlexHarnessV3MigrationRunner {
10
+ private readonly store: FlexStore;
11
+ private readonly storageKeys: string[];
12
+
13
+ constructor(optionsArg: IFlexHarnessV3MigrationOptions) {
14
+ this.store = optionsArg.store;
15
+ this.storageKeys = [...new Set(optionsArg.storageKeys)].sort();
16
+ }
17
+
18
+ public async run(signalArg?: AbortSignal): Promise<void> {
19
+ const migrationStores = this.store.getLegacyMigrationStores();
20
+ for (const storageKey of this.storageKeys) {
21
+ signalArg?.throwIfAborted();
22
+ if (!await this.store.hasCompletedLegacyMigration(storageKey)) {
23
+ const legacySnapshot = await this.store.loadLegacy(storageKey);
24
+ if (legacySnapshot) {
25
+ await plugins.flexharnessMigration.migrateLegacyFlexHarnessSnapshot(
26
+ storageKey,
27
+ legacySnapshot,
28
+ migrationStores,
29
+ );
30
+ await this.store.completeLegacyMigration(storageKey);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,33 @@
1
+ import type { FlexStore } from '../ts/classes.flexstore.js';
2
+
3
+ export interface IFlexProjectionOrderMigrationOptions {
4
+ store: FlexStore;
5
+ storageKeys: Iterable<string>;
6
+ }
7
+
8
+ export class FlexProjectionOrderMigration {
9
+ private readonly store: FlexStore;
10
+ private readonly storageKeys: string[];
11
+
12
+ constructor(optionsArg: IFlexProjectionOrderMigrationOptions) {
13
+ this.store = optionsArg.store;
14
+ this.storageKeys = [...new Set(optionsArg.storageKeys)].sort();
15
+ }
16
+
17
+ public async run(signalArg?: AbortSignal): Promise<void> {
18
+ for (const storageKey of this.storageKeys) {
19
+ let cursor: Awaited<ReturnType<FlexStore['listProjectionOrderMigrationPage']>>[
20
+ 'nextCursor'
21
+ ];
22
+ do {
23
+ signalArg?.throwIfAborted();
24
+ const page = await this.store.listProjectionOrderMigrationPage(storageKey, cursor);
25
+ for (const sessionId of page.sessionIds) {
26
+ signalArg?.throwIfAborted();
27
+ await this.store.rewriteProjectionSourceOrder(storageKey, sessionId);
28
+ }
29
+ cursor = page.nextCursor;
30
+ } while (cursor);
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,196 @@
1
+ import * as plugins from '../ts/plugins.js';
2
+
3
+ export const flexProviderCredentialStoreId = 'flex-provider-credentials.v1';
4
+ export const flexProviderCredentialConnectionLimit = 512;
5
+
6
+ export interface IFlexProviderCredentialStore {
7
+ getEntry(accountArg: string): Promise<Uint8Array | null>;
8
+ setEntry(accountArg: string, valueArg: Uint8Array): Promise<void>;
9
+ deleteEntry(accountArg: string): Promise<boolean>;
10
+ }
11
+
12
+ export interface IFlexProviderCredentialStorePair<
13
+ TKernelStore extends IFlexProviderCredentialStore = IFlexProviderCredentialStore,
14
+ TSealedStore extends IFlexProviderCredentialStore = IFlexProviderCredentialStore,
15
+ > {
16
+ kernelStore: TKernelStore;
17
+ sealedStore: TSealedStore;
18
+ }
19
+
20
+ export interface IFlexProviderCredentialMigrationOptions<
21
+ TKernelStore extends IFlexProviderCredentialStore,
22
+ TSealedStore extends IFlexProviderCredentialStore,
23
+ > {
24
+ stores: IFlexProviderCredentialStorePair<TKernelStore, TSealedStore>;
25
+ recreateStores: (
26
+ storesArg: IFlexProviderCredentialStorePair<TKernelStore, TSealedStore>,
27
+ ) => Promise<IFlexProviderCredentialStorePair<TKernelStore, TSealedStore>>;
28
+ connectionIds: Iterable<string>;
29
+ }
30
+
31
+ export type TFlexProviderCredentialMigrationErrorCode =
32
+ | 'CONNECTION_LIMIT_EXCEEDED'
33
+ | 'CREDENTIAL_CONFLICT'
34
+ | 'CREDENTIAL_INVALID'
35
+ | 'MUTATION_RECONCILIATION_FAILED';
36
+
37
+ export class FlexProviderCredentialMigrationError extends Error {
38
+ constructor(public readonly code: TFlexProviderCredentialMigrationErrorCode) {
39
+ super(`Flex provider credential migration failed (${code}).`);
40
+ this.name = 'FlexProviderCredentialMigrationError';
41
+ }
42
+ }
43
+
44
+ const maximumMutationAttempts = 2;
45
+
46
+ const credentialAccount = (connectionIdArg: string): string => `provider:${connectionIdArg}`;
47
+
48
+ const isMutationOutcomeUnknown = (errorArg: unknown): boolean => (
49
+ errorArg instanceof plugins.smartsecret.SmartSecretKernelStoreError
50
+ || errorArg instanceof plugins.smartsecret.SmartSecretSealedFileStoreError
51
+ ) && errorArg.code === 'MUTATION_OUTCOME_UNKNOWN';
52
+
53
+ const credentialBytesEqual = (leftArg: Uint8Array, rightArg: Uint8Array): boolean =>
54
+ leftArg.byteLength === rightArg.byteLength
55
+ && plugins.crypto.timingSafeEqual(leftArg, rightArg);
56
+
57
+ const validateCredentialBytes = (bytesArg: Uint8Array): void => {
58
+ try {
59
+ const credential = plugins.smartaiProviders.parseProviderCredential(bytesArg);
60
+ if (credential.kind !== 'chatgptOAuth' || credential.providerId !== 'openai') {
61
+ throw new FlexProviderCredentialMigrationError('CREDENTIAL_INVALID');
62
+ }
63
+ } catch (errorArg) {
64
+ if (errorArg instanceof FlexProviderCredentialMigrationError) throw errorArg;
65
+ throw new FlexProviderCredentialMigrationError('CREDENTIAL_INVALID');
66
+ }
67
+ };
68
+
69
+ const readValidatedCredential = async (
70
+ storeArg: IFlexProviderCredentialStore,
71
+ accountArg: string,
72
+ ): Promise<Uint8Array | null> => {
73
+ const bytes = await storeArg.getEntry(accountArg);
74
+ if (!bytes) return null;
75
+ try {
76
+ validateCredentialBytes(bytes);
77
+ return bytes;
78
+ } catch (errorArg) {
79
+ bytes.fill(0);
80
+ throw errorArg;
81
+ }
82
+ };
83
+
84
+ const deleteLegacyCredentialEntry = async <
85
+ TKernelStore extends IFlexProviderCredentialStore,
86
+ TSealedStore extends IFlexProviderCredentialStore,
87
+ >(
88
+ optionsArg: Pick<
89
+ IFlexProviderCredentialMigrationOptions<TKernelStore, TSealedStore>,
90
+ 'stores' | 'recreateStores'
91
+ >,
92
+ accountArg: string,
93
+ expectedBytesArg: Uint8Array,
94
+ ): Promise<IFlexProviderCredentialStorePair<TKernelStore, TSealedStore>> => {
95
+ let stores = optionsArg.stores;
96
+ let requiresConfirmedRetry = false;
97
+ for (let attempt = 0; attempt < maximumMutationAttempts; attempt += 1) {
98
+ let outcomeWasUnknown = false;
99
+ try {
100
+ await stores.kernelStore.deleteEntry(accountArg);
101
+ } catch (errorArg) {
102
+ if (!isMutationOutcomeUnknown(errorArg)) throw errorArg;
103
+ stores = await optionsArg.recreateStores(stores);
104
+ outcomeWasUnknown = true;
105
+ requiresConfirmedRetry = true;
106
+ }
107
+ const readback = await readValidatedCredential(stores.kernelStore, accountArg);
108
+ try {
109
+ if (!readback) {
110
+ if (!requiresConfirmedRetry || !outcomeWasUnknown) return stores;
111
+ continue;
112
+ }
113
+ if (!credentialBytesEqual(readback, expectedBytesArg)) {
114
+ throw new FlexProviderCredentialMigrationError('CREDENTIAL_CONFLICT');
115
+ }
116
+ if (!outcomeWasUnknown || attempt === maximumMutationAttempts - 1) {
117
+ throw new FlexProviderCredentialMigrationError('MUTATION_RECONCILIATION_FAILED');
118
+ }
119
+ } finally {
120
+ readback?.fill(0);
121
+ }
122
+ }
123
+ throw new FlexProviderCredentialMigrationError('MUTATION_RECONCILIATION_FAILED');
124
+ };
125
+
126
+ export const migrateFlexProviderCredentials = async <
127
+ TKernelStore extends IFlexProviderCredentialStore,
128
+ TSealedStore extends IFlexProviderCredentialStore,
129
+ >(
130
+ optionsArg: IFlexProviderCredentialMigrationOptions<TKernelStore, TSealedStore>,
131
+ signalArg?: AbortSignal,
132
+ ): Promise<IFlexProviderCredentialStorePair<TKernelStore, TSealedStore>> => {
133
+ const connectionIds = [...new Set(optionsArg.connectionIds)].sort();
134
+ if (connectionIds.length > flexProviderCredentialConnectionLimit) {
135
+ throw new FlexProviderCredentialMigrationError('CONNECTION_LIMIT_EXCEEDED');
136
+ }
137
+ let stores = optionsArg.stores;
138
+ for (const connectionId of connectionIds) {
139
+ signalArg?.throwIfAborted();
140
+ const account = credentialAccount(connectionId);
141
+ let sourceBytes: Uint8Array | null = null;
142
+ let sealedBytes: Uint8Array | null = null;
143
+ try {
144
+ sourceBytes = await readValidatedCredential(stores.kernelStore, account);
145
+ sealedBytes = await readValidatedCredential(stores.sealedStore, account);
146
+ if (!sourceBytes) continue;
147
+ if (sealedBytes && !credentialBytesEqual(sourceBytes, sealedBytes)) {
148
+ throw new FlexProviderCredentialMigrationError('CREDENTIAL_CONFLICT');
149
+ }
150
+ if (!sealedBytes) {
151
+ let copied = false;
152
+ let requiresConfirmedRetry = false;
153
+ for (let attempt = 0; attempt < maximumMutationAttempts; attempt += 1) {
154
+ let outcomeWasUnknown = false;
155
+ try {
156
+ await stores.sealedStore.setEntry(account, sourceBytes);
157
+ } catch (errorArg) {
158
+ if (!isMutationOutcomeUnknown(errorArg)) throw errorArg;
159
+ stores = await optionsArg.recreateStores(stores);
160
+ outcomeWasUnknown = true;
161
+ requiresConfirmedRetry = true;
162
+ }
163
+ const readback = await readValidatedCredential(stores.sealedStore, account);
164
+ try {
165
+ if (readback && credentialBytesEqual(readback, sourceBytes)) {
166
+ if (!requiresConfirmedRetry || !outcomeWasUnknown) {
167
+ copied = true;
168
+ break;
169
+ }
170
+ continue;
171
+ }
172
+ if (readback) {
173
+ throw new FlexProviderCredentialMigrationError('CREDENTIAL_CONFLICT');
174
+ }
175
+ if (!outcomeWasUnknown || attempt === maximumMutationAttempts - 1) {
176
+ throw new FlexProviderCredentialMigrationError('MUTATION_RECONCILIATION_FAILED');
177
+ }
178
+ } finally {
179
+ readback?.fill(0);
180
+ }
181
+ }
182
+ if (!copied) {
183
+ throw new FlexProviderCredentialMigrationError('MUTATION_RECONCILIATION_FAILED');
184
+ }
185
+ }
186
+ stores = await deleteLegacyCredentialEntry({
187
+ stores,
188
+ recreateStores: optionsArg.recreateStores,
189
+ }, account, sourceBytes);
190
+ } finally {
191
+ sourceBytes?.fill(0);
192
+ sealedBytes?.fill(0);
193
+ }
194
+ }
195
+ return stores;
196
+ };
@@ -0,0 +1,55 @@
1
+ import type {
2
+ IControllerSessionGroupsDocument,
3
+ } from '../ts/interfaces.projects.js';
4
+ import type { TControllerSessionId } from '../ts_interfaces/index.js';
5
+
6
+ type TObject = Record<string, unknown>;
7
+
8
+ export interface IProtocolV18LayoutMigrationResult {
9
+ document: IControllerSessionGroupsDocument;
10
+ migrated: boolean;
11
+ }
12
+
13
+ export interface IProtocolV18LegacySessionGroup {
14
+ id: string;
15
+ name: string;
16
+ sessionIds: Array<TControllerSessionId | { harnessId: 'controller'; nativeId: string }>;
17
+ }
18
+
19
+ export interface IProtocolV18LegacySessionGroupsDocument
20
+ extends Omit<IControllerSessionGroupsDocument, 'groups' | 'ungroupedSessionIds'> {
21
+ groups: IProtocolV18LegacySessionGroup[];
22
+ ungroupedSessionIds?: Array<TControllerSessionId | { harnessId: 'controller'; nativeId: string }>;
23
+ }
24
+
25
+ const isPlainObject = (valueArg: unknown): valueArg is TObject =>
26
+ typeof valueArg === 'object' && valueArg !== null && !Array.isArray(valueArg);
27
+
28
+ const isLegacyTerminalId = (valueArg: unknown): boolean =>
29
+ isPlainObject(valueArg) && valueArg.harnessId === 'controller';
30
+
31
+ export const migrateProtocolV18SessionLayoutDocument = (
32
+ valueArg: IProtocolV18LegacySessionGroupsDocument,
33
+ ): IProtocolV18LayoutMigrationResult => {
34
+ const groups = valueArg.groups.map((group) => ({
35
+ ...group,
36
+ sessionIds: group.sessionIds.filter(
37
+ (sessionId): sessionId is TControllerSessionId => !isLegacyTerminalId(sessionId),
38
+ ),
39
+ }));
40
+ const ungroupedSessionIds = (valueArg.ungroupedSessionIds ?? [])
41
+ .filter((sessionId): sessionId is TControllerSessionId => !isLegacyTerminalId(sessionId));
42
+ const migrated = groups.some((group, index) => (
43
+ group.sessionIds.length !== valueArg.groups[index].sessionIds.length
44
+ )) || ungroupedSessionIds.length !== (valueArg.ungroupedSessionIds ?? []).length;
45
+ if (!migrated) return { document: valueArg as IControllerSessionGroupsDocument, migrated: false };
46
+ return {
47
+ document: {
48
+ ...valueArg,
49
+ groups,
50
+ ungroupedSessionIds,
51
+ revision: (valueArg.revision ?? 0) + 1,
52
+ },
53
+ migrated: true,
54
+ };
55
+ };
@@ -0,0 +1,68 @@
1
+ import * as plugins from '../ts/plugins.js';
2
+ import {
3
+ assertControllerSessionGroupsDocument,
4
+ ControllerSessionGroupsModel,
5
+ } from '../ts/classes.authmodels.js';
6
+ import { AuthError } from '../ts/interfaces.auth.js';
7
+ import type { IControllerSessionGroupsDocument } from '../ts/interfaces.projects.js';
8
+ import { migrateProtocolV18SessionLayoutDocument } from './v18_resourcelayout.js';
9
+ import type { IProtocolV18LegacySessionGroupsDocument } from './v18_resourcelayout.js';
10
+
11
+ const migrationPageLimit = 128;
12
+
13
+ const persistedBodyFromRawDocument = (
14
+ valueArg: Record<string, unknown>,
15
+ ): IProtocolV18LegacySessionGroupsDocument => {
16
+ const body = { ...valueArg };
17
+ delete body._id;
18
+ delete body._smartdataRevision;
19
+ return body as unknown as IProtocolV18LegacySessionGroupsDocument;
20
+ };
21
+
22
+ export class ProtocolV18ResourceLayoutMigration {
23
+ constructor(private readonly database: plugins.smartdata.SmartdataDb | undefined) {}
24
+
25
+ public async run(): Promise<void> {
26
+ if (!this.database) {
27
+ throw new AuthError('not_initialized', 'The authentication store database is unavailable.');
28
+ }
29
+ const collection = ControllerSessionGroupsModel.collection.mongoDbCollection;
30
+ let lastId: plugins.smartdata.TStoredDocument<IControllerSessionGroupsDocument>['_id'] | undefined;
31
+ while (true) {
32
+ const cursor = collection.find(lastId ? { _id: { $gt: lastId } } : {})
33
+ .sort({ _id: 1 })
34
+ .limit(migrationPageLimit);
35
+ let documents: Awaited<ReturnType<typeof cursor.toArray>>;
36
+ try {
37
+ documents = await cursor.toArray();
38
+ } finally {
39
+ await cursor.close();
40
+ }
41
+ for (const raw of documents) {
42
+ const migration = migrateProtocolV18SessionLayoutDocument(persistedBodyFromRawDocument(raw));
43
+ assertControllerSessionGroupsDocument(migration.document);
44
+ if (!migration.migrated) continue;
45
+ const selector = raw._smartdataRevision === undefined
46
+ ? { _id: raw._id, _smartdataRevision: { $exists: false } }
47
+ : { _id: raw._id, _smartdataRevision: raw._smartdataRevision };
48
+ const replaced = await collection.findOneAndReplace(
49
+ selector,
50
+ { _id: raw._id, ...migration.document, _smartdataRevision: plugins.crypto.randomUUID() },
51
+ { returnDocument: 'after', includeResultMetadata: false, upsert: false },
52
+ );
53
+ if (!replaced) {
54
+ const concurrent = await collection.findOne({ _id: raw._id });
55
+ if (!concurrent) throw new AuthError('concurrent_change', 'The resource layout migration changed concurrently.');
56
+ const remaining = migrateProtocolV18SessionLayoutDocument(persistedBodyFromRawDocument(concurrent));
57
+ assertControllerSessionGroupsDocument(remaining.document);
58
+ if (remaining.migrated) {
59
+ throw new AuthError('concurrent_change', 'The resource layout migration changed concurrently.');
60
+ }
61
+ }
62
+ }
63
+ const last = documents.at(-1);
64
+ if (!last || documents.length < migrationPageLimit) break;
65
+ lastId = last._id;
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,28 @@
1
+ import * as plugins from '../ts/plugins.js';
2
+
3
+ export interface IFlexProjectManagementMigrationOptions<TScope> {
4
+ harness: plugins.flexharness.FlexHarness<TScope>;
5
+ scopeIds: Iterable<string>;
6
+ }
7
+
8
+ export class FlexProjectManagementMigration<TScope> {
9
+ private readonly harness: plugins.flexharness.FlexHarness<TScope>;
10
+ private readonly scopeIds: string[];
11
+
12
+ constructor(optionsArg: IFlexProjectManagementMigrationOptions<TScope>) {
13
+ this.harness = optionsArg.harness;
14
+ this.scopeIds = [...new Set(optionsArg.scopeIds)].sort();
15
+ }
16
+
17
+ public async run(signalArg?: AbortSignal): Promise<void> {
18
+ for (const scopeId of this.scopeIds) {
19
+ signalArg?.throwIfAborted();
20
+ // listSessions durably repairs legacy session generations before PM state is loaded.
21
+ const sessions = await this.harness.listSessions(scopeId);
22
+ for (const session of sessions) {
23
+ signalArg?.throwIfAborted();
24
+ await this.harness.getProjectState(scopeId, session.sessionId);
25
+ }
26
+ }
27
+ }
28
+ }