@happyvertical/smrt-cli 0.53.2 → 0.53.4

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 (65) hide show
  1. package/AGENTS.md +1 -0
  2. package/README.md +40 -0
  3. package/agents/app-commands.md +93 -0
  4. package/bin/smrt-web.mjs +19 -0
  5. package/bin/smrt.js +18 -12
  6. package/dist/{ApiKey-BZmbOTnL-nvcrCRDQ.js → ApiKey-BZmbOTnL-DPPF6Swn.js} +2 -2
  7. package/dist/ApiKeyCollection-Bfb_nw81-B1-2YKj8.js +2 -0
  8. package/dist/AuditLogCollection-B1YonCAP-DP4PCCw-.js +2 -0
  9. package/dist/{NostrIdentity-n70E0vck-BYlxfKXV.js → NostrIdentity-n70E0vck-D60BSg6H.js} +3 -3
  10. package/dist/NostrIdentityCollection-Ca74dkaL-C-v57o9N.js +2 -0
  11. package/dist/{OidcIdentity-Cb1bxreM-DDXZ2ULx.js → OidcIdentity-Cb1bxreM-B2eV2ahq.js} +2 -2
  12. package/dist/OidcIdentityCollection-TV8VdK69-BodvOtPJ.js +2 -0
  13. package/dist/ProfileAssetCollection-B9hacUJa-B7PLe0ld.js +2 -0
  14. package/dist/{ProfileCollection-DuJT7Mum-CEPfbh20.js → ProfileCollection-DuJT7Mum-B3Uhqphs.js} +26 -26
  15. package/dist/ProfileLinkCollection-4uNURz32-CLY1cBnn.js +2 -0
  16. package/dist/ProfileMetadataCollection-DQhbfEfa-Bzv-E4ep.js +2 -0
  17. package/dist/{ProfileMetafieldCollection-CoBuM_5G-DiMAQiDg.js → ProfileMetafieldCollection-CoBuM_5G-D-VqQuY1.js} +1 -1
  18. package/dist/{ProfileRelationshipCollection-DUVgaIqf-CUh6lQdy.js → ProfileRelationshipCollection-DUVgaIqf-gEkDBmkh.js} +1 -1
  19. package/dist/{ProfileRelationshipTermCollection-DtA9OM23-Sn18A9Vz.js → ProfileRelationshipTermCollection-DtA9OM23-DI_awdol.js} +1 -1
  20. package/dist/{ProfileRelationshipType-BRiRka6t-C0Sh1CTk.js → ProfileRelationshipType-BRiRka6t-Ci-qvFhm.js} +1 -1
  21. package/dist/{ProfileRelationshipTypeCollection-BdXwd7Kf-DEnQtZuK.js → ProfileRelationshipTypeCollection-BdXwd7Kf-CaQMLH9f.js} +1 -1
  22. package/dist/app/cli.d.ts +44 -0
  23. package/dist/app/cli.d.ts.map +1 -0
  24. package/dist/app/errors.d.ts +22 -0
  25. package/dist/app/errors.d.ts.map +1 -0
  26. package/dist/app/identity.d.ts +24 -0
  27. package/dist/app/identity.d.ts.map +1 -0
  28. package/dist/app/index.d.ts +19 -0
  29. package/dist/app/index.d.ts.map +1 -0
  30. package/dist/app/launchers.d.ts +40 -0
  31. package/dist/app/launchers.d.ts.map +1 -0
  32. package/dist/app/operations.d.ts +28 -0
  33. package/dist/app/operations.d.ts.map +1 -0
  34. package/dist/app/portability-assets.d.ts +151 -0
  35. package/dist/app/portability-assets.d.ts.map +1 -0
  36. package/dist/app/portability.d.ts +117 -0
  37. package/dist/app/portability.d.ts.map +1 -0
  38. package/dist/app/process-record.d.ts +54 -0
  39. package/dist/app/process-record.d.ts.map +1 -0
  40. package/dist/app/runtime.d.ts +83 -0
  41. package/dist/app/runtime.d.ts.map +1 -0
  42. package/dist/app.d.ts +1 -0
  43. package/dist/app.js +4 -0
  44. package/dist/cli-BRFsobey.js +1275 -0
  45. package/dist/cli-generator.d.ts.map +1 -1
  46. package/dist/commands/utilities.d.ts.map +1 -1
  47. package/dist/{commands-D6UUd6cJ.js → commands-dFz1e9A6.js} +17 -288
  48. package/dist/{dist-BwlARYH5.js → dist-Berwe80z.js} +4 -4
  49. package/dist/{dist-vvYmwpFv.js → dist-C2BqYVu7.js} +27 -27
  50. package/dist/{dist-BCAkEXaz.js → dist-D4BNILLN.js} +3 -3
  51. package/dist/{dist-BGsb09DN.js → dist-EJ63xUEp.js} +2 -2
  52. package/dist/index.js +14 -9
  53. package/dist/mcp-apps-packaging-CixRnxz_.js +286 -0
  54. package/dist/{oidcProvisioningPrimitives-D9OYu5-F-D5PxeL32.js → oidcProvisioningPrimitives-D9OYu5-F-B-kYsBTM.js} +4 -4
  55. package/dist/portability-DmQWSSXA.js +859 -0
  56. package/dist/resolveIdentity-B-PK6RwU-BmAU1Kse.js +2 -0
  57. package/package.json +14 -9
  58. package/dist/ApiKeyCollection-Bfb_nw81-CZVWaFPV.js +0 -2
  59. package/dist/AuditLogCollection-B1YonCAP-CnMHEquA.js +0 -2
  60. package/dist/NostrIdentityCollection-Ca74dkaL-C1Q9BNQc.js +0 -2
  61. package/dist/OidcIdentityCollection-TV8VdK69-RZ2ocmoN.js +0 -2
  62. package/dist/ProfileAssetCollection-B9hacUJa-C1qMe0_q.js +0 -2
  63. package/dist/ProfileLinkCollection-4uNURz32-GWzU0-kb.js +0 -2
  64. package/dist/ProfileMetadataCollection-DQhbfEfa-Dog-9nKM.js +0 -2
  65. package/dist/resolveIdentity-B-PK6RwU-CkUCBn4e.js +0 -2
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `@happyvertical/smrt-cli/app` — the application operations behind
3
+ * `smrt app <operation>`, plus the shared lock, lease, identity, process,
4
+ * readiness, and portability primitives they are built from.
5
+ *
6
+ * Importing this entry has no side effects (unlike the package root, which
7
+ * runs the CLI).
8
+ */
9
+ export { type AcquireWriterLeaseOptions, acquireWriterLease, createProviderReadinessProbe, findInstalledPackage, isStaleOperationLock, lockOwnerPid, type OperationLock, PROVIDER_READINESS_SETTINGS, type ProviderReadinessOptions, processExists, RECLAIM_MUTEX_FILE, type ReadinessComponent, type ReadinessContext, type ReclaimOutcome, readActiveWriterLease, reclaimStaleRecord, resolveReadinessModule, type WriterLease, type WriterLeaseRecord, withOperationLock, } from '@happyvertical/smrt-app-runtime';
10
+ export { APP_COMMANDS, APP_RECOVERY, type AppErrorEnvelope, errorEnvelope, type RunAppCommandOptions, renderAppHelp, runAppCommand, } from './cli.js';
11
+ export { AppCommandError, redactSecrets } from './errors.js';
12
+ export { type ApplicationStateRootOptions, assertExternalArtifactPath, type ExternalArtifactPathOptions, type FingerprintRuntime, prepareApplicationStateRoot, type ResolveApplicationIdOptions, resolveApplicationId, resolveApplicationStateRoot, runtimeConfigurationFingerprint, type StateCustodyOptions, } from './identity.js';
13
+ export { launchVite, prepareMigration, resolveViteEntry, runWorker, ViteLauncherError, validateMcpAppsIfPresent, type WorkerKind, } from './launchers.js';
14
+ export { APP_OPERATIONS, type AppOperation, type PortabilityAdapter, runApplicationOperation, } from './operations.js';
15
+ export { type ExportResult, executeImportPlan, exportApplication, type ImportExecutor, type ImportResult, importApplication, importedRowsMatchBundle, type LogicalExportBundle, type ManifestTable, manifestTables, type PlannedImportTable, type PortabilityContext, type PortabilityRuntime, planImportTables, serializeExportBundle, validateImportBundle, } from './portability.js';
16
+ export { ASSET_MANIFEST_SCHEMA_VERSION, type AssetBundle, type AssetImportJournal, type AssetManifestEntry, type AssetPayload, AssetPortabilityError, assertAssetRoot, bundleContentDigest, collectFilesystemAssets, digestBytes, finishFilesystemAssets, hasCommittedImportJournal, MAX_ASSET_BYTES, MAX_ASSET_COUNT, MAX_BUNDLE_BYTES, MAX_TOTAL_ASSET_BYTES, markFilesystemAssetsCommitted, type PortableRow, type PortableTable, publishFilesystemAssets, readSensitiveBundle, recoverFilesystemAssets, rollbackFilesystemAssets, type StagedAssets, stageFilesystemAssets, type VerifiedAsset, type VerifiedAssets, verifyFilesystemAssets, verifyPublishedFilesystemAssets, } from './portability-assets.js';
17
+ export { type ApplicationProcessRecord, checkOwnedProcess, matchesApplicationProcess, type OwnedProcessState, readOwnedProcess, sendTerminationSignal, verifyOwnedProcess, WEB_LAUNCHER_NAME, writeProcessRecord, } from './process-record.js';
18
+ export { type AppCommandDependencies, type AppCommandIo, type AppContext, type CommandRunner, cliExecutablePath, type RunOptions, type RuntimeEnvironment, runtimeEnvironment, webLauncherPath, } from './runtime.js';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,4BAA4B,EAC5B,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,KAAK,aAAa,EAClB,2BAA2B,EAC3B,KAAK,wBAAwB,EAC7B,aAAa,EACb,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,KAAK,gBAAgB,EACrB,aAAa,EACb,KAAK,oBAAoB,EACzB,aAAa,EACb,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,KAAK,2BAA2B,EAChC,0BAA0B,EAC1B,KAAK,2BAA2B,EAChC,KAAK,kBAAkB,EACvB,2BAA2B,EAC3B,KAAK,2BAA2B,EAChC,oBAAoB,EACpB,2BAA2B,EAC3B,+BAA+B,EAC/B,KAAK,mBAAmB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,UAAU,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,YAAY,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,6BAA6B,EAC7B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,WAAW,EACX,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,6BAA6B,EAC7B,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,KAAK,YAAY,EACjB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,sBAAsB,EACtB,+BAA+B,GAChC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,yBAAyB,EACzB,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,kBAAkB,EAClB,eAAe,GAChB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Process wrappers: explicit schema preparation (`migrate`), deployed job
3
+ * workers (`worker`), and the Vite launcher (`dev`, `build`, `vite`).
4
+ *
5
+ * Ported from the template's `scripts/smrt-prepare-migration.mjs`,
6
+ * `scripts/smrt-worker.mjs`, `scripts/smrt-vite.mjs`, and
7
+ * `scripts/smrt-mcp-apps.mjs`.
8
+ */
9
+ import { type AppContext } from './runtime.js';
10
+ /**
11
+ * Prepare the schema explicitly: under the operation lock, refuse while a
12
+ * local writer is live, establish local storage custody without creating
13
+ * schema or bootstrap records, then run `smrt db:migrate`.
14
+ */
15
+ export declare function prepareMigration(context: AppContext): Promise<number>;
16
+ /** Worker kinds. `task` when omitted; anything else is a usage error. */
17
+ export type WorkerKind = 'task' | 'schedule';
18
+ /** Parse `smrt app worker [kind]`, refusing anything but `task`/`schedule`. */
19
+ export declare function parseWorkerKind(args: readonly string[]): WorkerKind;
20
+ /**
21
+ * Start a deployed job worker. Resolves once the runner is started; the
22
+ * process stays alive until SIGINT/SIGTERM closes the runtime.
23
+ */
24
+ export declare function runWorker(context: AppContext, args: string[]): Promise<number>;
25
+ /** Failure of the Vite launcher; rendered as `s-m-r-t Vite launcher: …`. */
26
+ export declare class ViteLauncherError extends Error {
27
+ }
28
+ /** Resolve the application's installed Vite CLI entry, refusing unsafe paths. */
29
+ export declare function resolveViteEntry(sourceRoot: string): string;
30
+ /**
31
+ * Run the application's Vite CLI in this process with `args` verbatim. The
32
+ * caller has already loaded `.env` without overriding the shell.
33
+ */
34
+ export declare function launchVite(context: AppContext, args: string[]): Promise<number>;
35
+ /**
36
+ * Validate opt-in portable MCP Apps metadata (`./mcp-apps`) when present.
37
+ * Returns the exit code; findings go to stderr.
38
+ */
39
+ export declare function validateMcpAppsIfPresent(context: AppContext): Promise<number>;
40
+ //# sourceMappingURL=launchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launchers.d.ts","sourceRoot":"","sources":["../../src/app/launchers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,cAAc,CAAC;AAElE;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAyC3E;AAED,yEAAyE;AACzE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;AAI7C,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAOnE;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,MAAM,CAAC,CA2GjB;AAED,4EAA4E;AAC5E,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAE/C,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAyC3D;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,MAAM,CAAC,CAkBjB"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Local/deployed application operations: install, setup, recover, start,
3
+ * stop, doctor, open, backup, export, import.
4
+ *
5
+ * Ported from the template's `scripts/smrt-app.mjs`. Output JSON, exit
6
+ * codes, state files, and environment variables are unchanged so the
7
+ * template's `pnpm app:*` scripts can become `smrt app <operation>`.
8
+ */
9
+ import type { ResolvedApplicationRuntime } from '@happyvertical/smrt-config';
10
+ import type { ExportResult, ImportResult, PortabilityContext } from './portability.js';
11
+ import { type AppContext } from './runtime.js';
12
+ /** Operations implemented by this module. */
13
+ export declare const APP_OPERATIONS: readonly ["install", "setup", "recover", "start", "stop", "doctor", "open", "backup", "export", "import"];
14
+ /** One of {@link APP_OPERATIONS}. */
15
+ export type AppOperation = (typeof APP_OPERATIONS)[number];
16
+ /** Throw unless the configured profile is `local`. */
17
+ export declare function assertLocalOperation(context: AppContext, operation: string): Promise<ResolvedApplicationRuntime>;
18
+ /** Portability adapter contract (built-in or an application override). */
19
+ export interface PortabilityAdapter {
20
+ exportApplication(context: PortabilityContext): Promise<ExportResult>;
21
+ importApplication(context: PortabilityContext): Promise<ImportResult>;
22
+ }
23
+ /**
24
+ * Run one application operation. Resolves to the process exit code; throws
25
+ * on failure (the caller renders the error envelope).
26
+ */
27
+ export declare function runApplicationOperation(context: AppContext, operation: AppOperation, args: string[]): Promise<number>;
28
+ //# sourceMappingURL=operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/app/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuBH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAO7E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAO1B,OAAO,EACL,KAAK,UAAU,EAIhB,MAAM,cAAc,CAAC;AAEtB,6CAA6C;AAC7C,eAAO,MAAM,cAAc,2GAWjB,CAAC;AAEX,qCAAqC;AACrC,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AA+G3D,sDAAsD;AACtD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,0BAA0B,CAAC,CAQrC;AAijBD,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACtE,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACvE;AAkFD;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,MAAM,CAAC,CA+DjB"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Filesystem asset portability for logical export/import bundles.
3
+ *
4
+ * Ported unchanged from the template's `scripts/smrt-portability-assets.mjs`:
5
+ * the bundle format, limits, sanitized failure codes, staging journal, and
6
+ * crash-recovery rules are a persisted contract.
7
+ */
8
+ export declare const ASSET_MANIFEST_SCHEMA_VERSION = 1;
9
+ export declare const MAX_ASSET_COUNT = 1000;
10
+ export declare const MAX_ASSET_BYTES: number;
11
+ export declare const MAX_TOTAL_ASSET_BYTES: number;
12
+ export declare const MAX_BUNDLE_BYTES: number;
13
+ /** Row shape of an exported table. */
14
+ export type PortableRow = Record<string, unknown>;
15
+ /** Exported table as it appears in a bundle. */
16
+ export interface PortableTable {
17
+ name: string;
18
+ columns: string[];
19
+ rows: PortableRow[];
20
+ }
21
+ /** One asset entry of the bundle manifest. */
22
+ export interface AssetManifestEntry {
23
+ key: string;
24
+ byteLength: number;
25
+ contentDigest: string;
26
+ payloadPath: string;
27
+ }
28
+ /** One embedded asset payload. */
29
+ export interface AssetPayload {
30
+ path: string;
31
+ encoding: 'base64';
32
+ data: string;
33
+ }
34
+ /** Asset section of a bundle. */
35
+ export interface AssetBundle {
36
+ schemaVersion: number;
37
+ adapter: 'filesystem';
38
+ entries: AssetManifestEntry[];
39
+ payloads: AssetPayload[];
40
+ }
41
+ /** Verified asset ready to stage. */
42
+ export interface VerifiedAsset {
43
+ key: string;
44
+ bytes: Buffer;
45
+ contentDigest: string;
46
+ relativePath: string;
47
+ }
48
+ /** Result of {@link verifyFilesystemAssets}. */
49
+ export interface VerifiedAssets {
50
+ root: string | null;
51
+ entries: VerifiedAsset[];
52
+ }
53
+ /** Persisted asset-import journal. */
54
+ export interface AssetImportJournal {
55
+ schemaVersion: 1;
56
+ application: string;
57
+ bundleDigest: string;
58
+ assetRoot: string;
59
+ stageRoot: string;
60
+ phase: 'staging' | 'publishing' | 'published';
61
+ rootExisted: boolean;
62
+ entries: Array<{
63
+ relativePath: string;
64
+ contentDigest: string;
65
+ }>;
66
+ /**
67
+ * Set once the database transaction for this bundle committed (additive;
68
+ * journals written by the template scripts never carry it, and those
69
+ * scripts ignore it). Recovery treats it as proof the rows are this
70
+ * bundle's; without it, recovery verifies row content instead.
71
+ */
72
+ committedAt?: string;
73
+ }
74
+ /** A staged import: journal path plus its in-memory journal. */
75
+ export interface StagedAssets {
76
+ path: string;
77
+ journal: AssetImportJournal;
78
+ }
79
+ /** Sanitized asset-portability failure with a stable kebab-case `code`. */
80
+ export declare class AssetPortabilityError extends Error {
81
+ readonly code: string;
82
+ constructor(code: string);
83
+ }
84
+ /** `sha256:<hex>` digest of bytes. */
85
+ export declare function digestBytes(value: string | Buffer): string;
86
+ /** Validate an asset root: absolute, outside the source tree, real directory. */
87
+ export declare function assertAssetRoot({ sourceRoot, assetRoot, allowMissing, }: {
88
+ sourceRoot: string;
89
+ assetRoot: unknown;
90
+ allowMissing?: boolean;
91
+ }): string;
92
+ /** Replace provider paths with logical keys while collecting verified payloads. */
93
+ export declare function collectFilesystemAssets({ tables, sourceRoot, assetRoot, onSourceOpened, }: {
94
+ tables: PortableTable[];
95
+ sourceRoot: string;
96
+ assetRoot: string | null | undefined;
97
+ onSourceOpened?: () => void;
98
+ }): AssetBundle;
99
+ /** Validate every manifest/payload relationship and hydrate destination URIs. */
100
+ export declare function verifyFilesystemAssets({ assetBundle, tables, sourceRoot, assetRoot, }: {
101
+ assetBundle: unknown;
102
+ tables: PortableTable[];
103
+ sourceRoot: string;
104
+ assetRoot: string | null | undefined;
105
+ }): VerifiedAssets;
106
+ /** Stage verified bytes without publishing anything into the destination root. */
107
+ export declare function stageFilesystemAssets({ verified, stateRoot, appId, bundleDigest, }: {
108
+ verified: VerifiedAssets;
109
+ stateRoot: string;
110
+ appId: string;
111
+ bundleDigest: string;
112
+ }): StagedAssets | null;
113
+ /** Publish the complete verified tree with one rename that never follows the target. */
114
+ export declare function publishFilesystemAssets(staged: StagedAssets | null, options?: {
115
+ beforeRename?: () => void;
116
+ }): void;
117
+ /** Re-verify the published tree against the staged journal. */
118
+ export declare function verifyPublishedFilesystemAssets(staged: StagedAssets | null): void;
119
+ /** Record in the journal that this bundle's database transaction committed. */
120
+ export declare function markFilesystemAssetsCommitted(staged: StagedAssets | null): void;
121
+ /**
122
+ * True when an import journal for `appId` exists, belongs to `bundleDigest`,
123
+ * and records a committed database transaction.
124
+ */
125
+ export declare function hasCommittedImportJournal({ stateRoot, appId, bundleDigest, }: {
126
+ stateRoot: string;
127
+ appId: string;
128
+ bundleDigest: string;
129
+ }): boolean;
130
+ /** Verify the published tree and drop the journal. */
131
+ export declare function finishFilesystemAssets(staged: StagedAssets | null): void;
132
+ /** Undo a staged or published import, restoring an empty target. */
133
+ export declare function rollbackFilesystemAssets(staged: StagedAssets | null): void;
134
+ /** Recover a prior crash only when the same bundle and exact target state prove ownership. */
135
+ export declare function recoverFilesystemAssets({ stateRoot, appId, bundleDigest, assetRoot, targetState, }: {
136
+ stateRoot: string;
137
+ appId: string;
138
+ bundleDigest: string;
139
+ assetRoot: string | null;
140
+ targetState: 'empty' | 'complete' | 'dirty';
141
+ }): 'none' | 'complete' | 'retry';
142
+ /**
143
+ * Read an import bundle only when it is a private (mode 0600), regular,
144
+ * non-symlinked file that does not change while it is read.
145
+ */
146
+ export declare function readSensitiveBundle(path: string, options?: {
147
+ onOpened?: () => void;
148
+ }): string;
149
+ /** Digest identifying one serialized bundle for crash recovery. */
150
+ export declare function bundleContentDigest(serialized: string): string;
151
+ //# sourceMappingURL=portability-assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portability-assets.d.ts","sourceRoot":"","sources":["../../src/app/portability-assets.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwBH,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAC/C,eAAO,MAAM,eAAe,OAAQ,CAAC;AACrC,eAAO,MAAM,eAAe,QAAmB,CAAC;AAChD,eAAO,MAAM,qBAAqB,QAAoB,CAAC;AACvD,eAAO,MAAM,gBAAgB,QAAoB,CAAC;AAQlD,sCAAsC;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d,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;CAC7C,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAiDhC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CAAO,GACtC,MAAM,CAgER;AAED,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE9D"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Logical application export/import (schemaVersion 2 bundles).
3
+ *
4
+ * Ported unchanged from the template's `scripts/smrt-portability.mjs`: the
5
+ * bundle shape, non-portable table/column rules, parent-first import plan,
6
+ * empty-target rule, and asset staging/recovery are a persisted contract.
7
+ */
8
+ import type { DatabaseInterface } from '@happyvertical/sql';
9
+ import { type AssetBundle, type PortableRow, type PortableTable } from './portability-assets.js';
10
+ /** Column definition fields the import planner reads from the manifest. */
11
+ export interface PortableColumnDefinition {
12
+ primaryKey?: boolean;
13
+ notNull?: boolean;
14
+ foreignKey?: {
15
+ table?: string;
16
+ };
17
+ [key: string]: unknown;
18
+ }
19
+ /** Manifest-derived application table. */
20
+ export interface ManifestTable {
21
+ name: string;
22
+ columns: string[];
23
+ columnDefinitions: Record<string, PortableColumnDefinition>;
24
+ foreignKeys: Array<{
25
+ column: string;
26
+ referencesTable: string;
27
+ }>;
28
+ primaryKeys: string[];
29
+ }
30
+ /** Planned import step; `deferredColumns` are filled by a later UPDATE. */
31
+ export interface PlannedImportTable extends ManifestTable {
32
+ deferredColumns: Set<string>;
33
+ }
34
+ /** A schemaVersion-2 logical bundle. */
35
+ export interface LogicalExportBundle {
36
+ schemaVersion: 2;
37
+ application: string;
38
+ profile: string;
39
+ exportedAt: string;
40
+ tables: PortableTable[];
41
+ assets: AssetBundle;
42
+ }
43
+ /** Runtime selection the adapter needs. */
44
+ export interface PortabilityRuntime {
45
+ profile: string;
46
+ providers: {
47
+ database: {
48
+ engine: string;
49
+ };
50
+ };
51
+ }
52
+ /** Context for {@link exportApplication} / {@link importApplication}. */
53
+ export interface PortabilityContext {
54
+ appId: string;
55
+ sourceRoot: string;
56
+ stateRoot: string;
57
+ runtime: PortabilityRuntime;
58
+ env: Record<string, string | undefined>;
59
+ paths: {
60
+ root: string;
61
+ assets: string;
62
+ } | null;
63
+ assetRoot: string | null;
64
+ path?: string;
65
+ /** Test seam: observe import phases (`assets-staged`, …). */
66
+ onImportPhase?: (phase: string) => Promise<void> | void;
67
+ /** Test seam: replace the database opener. */
68
+ openDatabase?: (options: Record<string, unknown>) => Promise<DatabaseInterface>;
69
+ }
70
+ /** Read the application tables from `<sourceRoot>/.smrt/manifest.json`. */
71
+ export declare function manifestTables(sourceRoot: string): ManifestTable[];
72
+ /** Parent-first insertion plan with nullable cycle edges deferred to updates. */
73
+ export declare function planImportTables(tables: ManifestTable[]): PlannedImportTable[];
74
+ /** Reject bundles that do not exactly match the generated schema. */
75
+ export declare function validateImportBundle(bundle: {
76
+ tables: unknown[];
77
+ }, expected: Map<string, Pick<ManifestTable, 'name' | 'columns'>>): void;
78
+ /** JSON cannot represent SQLite's lossless BigInt results; decimal strings do. */
79
+ export declare function serializeExportBundle(bundle: unknown): string;
80
+ /** Result reported by `smrt app export`. */
81
+ export interface ExportResult {
82
+ path: string;
83
+ tableCount: number;
84
+ assetsIncluded: true;
85
+ assetCount: number;
86
+ }
87
+ /** Write a logical export bundle without replacing an existing file. */
88
+ export declare function exportApplication(context: PortabilityContext): Promise<ExportResult>;
89
+ /** Minimal query surface the import plan needs (a transaction handle). */
90
+ export interface ImportExecutor {
91
+ query(sql: string, ...params: unknown[]): Promise<{
92
+ rows: Array<Record<string, unknown>>;
93
+ }>;
94
+ }
95
+ /** Execute a prevalidated parent-first import against one database transaction. */
96
+ export declare function executeImportPlan(tx: ImportExecutor, plan: PlannedImportTable[], exportedByName: Map<string, {
97
+ rows: PortableRow[];
98
+ }>): Promise<number>;
99
+ /**
100
+ * True when every planned table holds exactly the bundle's rows (as a
101
+ * multiset over the bundle's columns). This is the evidence an interrupted
102
+ * import's recovery needs when no commit marker was recorded: matching
103
+ * per-table counts alone do not prove the rows are this bundle's.
104
+ */
105
+ export declare function importedRowsMatchBundle(db: ImportExecutor, plan: PlannedImportTable[], exportedByName: Map<string, {
106
+ rows: PortableRow[];
107
+ }>): Promise<boolean>;
108
+ /** Result reported by `smrt app import`. */
109
+ export interface ImportResult {
110
+ path: string;
111
+ rowCount: number;
112
+ assetsIncluded: true;
113
+ assetCount: number;
114
+ }
115
+ /** Import a logical bundle into an empty application database. */
116
+ export declare function importApplication(context: PortabilityContext): Promise<ImportResult>;
117
+ //# sourceMappingURL=portability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portability.d.ts","sourceRoot":"","sources":["../../src/app/portability.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,OAAO,EACL,KAAK,WAAW,EAOhB,KAAK,WAAW,EAChB,KAAK,aAAa,EAQnB,MAAM,yBAAyB,CAAC;AAQjC,2EAA2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,0CAA0C;AAC1C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IAC5D,WAAW,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;CAAE,CAAC,GACnD,OAAO,CAAC,MAAM,CAAC,CA+CjB;AA+CD;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,cAAc,EAClB,IAAI,EAAE,kBAAkB,EAAE,EAC1B,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,GACnD,OAAO,CAAC,OAAO,CAAC,CAelB;AAED,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,kEAAkE;AAClE,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAmJvB"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Managed web-process record (`<state>/app.pid`).
3
+ *
4
+ * Ported from the template's `scripts/smrt-process.mjs`. A recorded pid is
5
+ * only trusted when the live process's command line proves it is the web
6
+ * launcher with this record's instance nonce, so a recycled pid is never
7
+ * signalled.
8
+ */
9
+ /** Persisted web-process identity. */
10
+ export interface ApplicationProcessRecord {
11
+ pid: number;
12
+ instance: string;
13
+ }
14
+ /** File name of the web launcher; part of the process-identity proof. */
15
+ export declare const WEB_LAUNCHER_NAME = "smrt-web.mjs";
16
+ /** Write the private (mode 0600) process record. */
17
+ export declare function writeProcessRecord(path: string, record: ApplicationProcessRecord): void;
18
+ /**
19
+ * Send SIGTERM. Returns `false` when the process had already exited; any
20
+ * other failure (e.g. EPERM) is rethrown.
21
+ */
22
+ export declare function sendTerminationSignal(pid: number, killProcess?: (pid: number, signal: NodeJS.Signals) => unknown): boolean;
23
+ /**
24
+ * True when `command` is exactly the web launcher started with this record's
25
+ * nonce: the final argument is `--smrt-instance=<instance>` and the argument
26
+ * before it is a path whose basename is `smrt-web.mjs` (the CLI's
27
+ * `bin/smrt-web.mjs`, or the template's `scripts/smrt-web.mjs`). Substring
28
+ * matches such as `evil-smrt-web.mjs` or a nonce with a suffix are rejected.
29
+ */
30
+ export declare function matchesApplicationProcess(record: Pick<ApplicationProcessRecord, 'instance'>, command: unknown): boolean;
31
+ /** Result of re-checking a recorded web process. */
32
+ export type OwnedProcessState =
33
+ /** Live and provably the recorded launcher. */
34
+ 'owned'
35
+ /** The pid no longer exists. */
36
+ | 'gone'
37
+ /** The pid is live but runs something else (recycled pid). */
38
+ | 'mismatched'
39
+ /** The pid is live but its command line could not be read. */
40
+ | 'unverifiable';
41
+ /**
42
+ * Re-check `record` against the live process table. Only `gone` and
43
+ * `mismatched` justify dropping the record; `unverifiable` (the process
44
+ * query failed or returned nothing) must keep it and must not signal.
45
+ */
46
+ export declare function checkOwnedProcess(record: ApplicationProcessRecord): OwnedProcessState;
47
+ /** True only when {@link checkOwnedProcess} proves the record still owned. */
48
+ export declare function verifyOwnedProcess(record: ApplicationProcessRecord): boolean;
49
+ /**
50
+ * Return the recorded web process when it is live and provably ours;
51
+ * otherwise remove the stale record and return `null`.
52
+ */
53
+ export declare function readOwnedProcess(path: string): ApplicationProcessRecord | null;
54
+ //# sourceMappingURL=process-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-record.d.ts","sourceRoot":"","sources":["../../src/app/process-record.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,sCAAsC;AACtC,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAsBhD,oDAAoD;AACpD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,wBAAwB,GAC/B,IAAI,CAEN;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,OAAsB,GAC3E,OAAO,CAQT;AAWD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,IAAI,CAAC,wBAAwB,EAAE,UAAU,CAAC,EAClD,OAAO,EAAE,OAAO,GACf,OAAO,CAST;AAED,oDAAoD;AACpD,MAAM,MAAM,iBAAiB;AAC3B,+CAA+C;AAC7C,OAAO;AACT,gCAAgC;GAC9B,MAAM;AACR,8DAA8D;GAC5D,YAAY;AACd,8DAA8D;GAC5D,cAAc,CAAC;AAYnB;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,wBAAwB,GAC/B,iBAAiB,CAOnB;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAE5E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,GACX,wBAAwB,GAAG,IAAI,CAoCjC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Shared per-invocation context for the `smrt app` command group: source
3
+ * root, application identity, I/O, child-process runners, and the
4
+ * profile-aware runtime environment.
5
+ */
6
+ import { type SpawnSyncReturns } from 'node:child_process';
7
+ import type * as AppRuntime from '@happyvertical/smrt-app-runtime';
8
+ import type { ResolvedApplicationRuntime } from '@happyvertical/smrt-config';
9
+ /** Output sinks. Each call receives complete text including the newline. */
10
+ export interface AppCommandIo {
11
+ stdout(text: string): void;
12
+ stderr(text: string): void;
13
+ }
14
+ /** Options for a child command run. */
15
+ export interface RunOptions {
16
+ env?: NodeJS.ProcessEnv;
17
+ /** Capture stdout/stderr instead of inheriting the terminal. */
18
+ capture?: boolean;
19
+ /** Return a failed result instead of throwing. */
20
+ allowFailure?: boolean;
21
+ /** Secret-free name used in the failure message. */
22
+ label?: string;
23
+ shell?: boolean;
24
+ }
25
+ /** Child-process runner signature. */
26
+ export type CommandRunner = (args: string[], options?: RunOptions) => SpawnSyncReturns<string>;
27
+ /** Replaceable collaborators. Production values are filled in by default. */
28
+ export interface AppCommandDependencies {
29
+ /** `@happyvertical/smrt-app-runtime` entry points. */
30
+ runtime: Pick<typeof AppRuntime, 'initializeLocalApplicationRuntime' | 'initializeDeployedApplicationRuntime' | 'prepareLocalDatabaseStorage' | 'resolveLocalRuntimePaths' | 'validateLocalDatabaseStorage'>;
31
+ /** Resolve the configured runtime after (re)loading `smrt.config`. */
32
+ resolveRuntime(sourceRoot: string): Promise<ResolvedApplicationRuntime>;
33
+ /** Run the application's package manager (`pnpm <args>`). */
34
+ runPackageManager: CommandRunner;
35
+ /** Run this CLI (`smrt <args>`) as a child process. */
36
+ runSmrt: CommandRunner;
37
+ /** Open a URL in the operator's browser. */
38
+ openBrowser(url: string): void;
39
+ /** Health probe transport for `start`. */
40
+ fetch: typeof fetch;
41
+ /** Delay between readiness polls. */
42
+ sleep(milliseconds: number): Promise<void>;
43
+ /** Signal a process (`start` cleanup). */
44
+ signal(pid: number, signal: NodeJS.Signals): void;
45
+ }
46
+ /** Per-invocation context. */
47
+ export interface AppContext {
48
+ readonly sourceRoot: string;
49
+ readonly appId: string;
50
+ readonly io: AppCommandIo;
51
+ readonly deps: AppCommandDependencies;
52
+ }
53
+ /** Locate this package's root (`…/smrt-cli`) from the running module. */
54
+ export declare function cliPackageRoot(): string;
55
+ /** Absolute path of the `smrt` executable shipped with this package. */
56
+ export declare function cliExecutablePath(): string;
57
+ /** Absolute path of the web launcher `start` spawns. */
58
+ export declare function webLauncherPath(): string;
59
+ /** Load `<sourceRoot>/.env` without overriding the shell; a missing file is fine. */
60
+ export declare function loadSourceEnvironment(sourceRoot: string): void;
61
+ /** Default package-manager runner: honours a pnpm `npm_execpath`. */
62
+ export declare function createPackageManagerRunner(sourceRoot: string): CommandRunner;
63
+ /** Default self-runner: this package's own `smrt` executable. */
64
+ export declare function createSmrtRunner(sourceRoot: string): CommandRunner;
65
+ /** Default browser opener (`SMRT_OPEN_STUB` writes the URL to a file instead). */
66
+ export declare function createBrowserOpener(sourceRoot: string): (url: string) => void;
67
+ /** Default runtime resolver: reload `smrt.config` without the cache. */
68
+ export declare function resolveConfiguredRuntime(sourceRoot: string): Promise<ResolvedApplicationRuntime>;
69
+ /** Build the default dependency set for `sourceRoot`. */
70
+ export declare function defaultDependencies(sourceRoot: string): Promise<AppCommandDependencies>;
71
+ /** Resolve the application id from `<sourceRoot>/package.json` and `SMRT_APP_ID`. */
72
+ export declare function resolveContextApplicationId(sourceRoot: string): string;
73
+ /** Create or verify the private state root for this invocation. */
74
+ export declare function preparedStateRoot(context: AppContext): string;
75
+ /** Profile-aware child environment, with local storage paths when local. */
76
+ export interface RuntimeEnvironment {
77
+ env: NodeJS.ProcessEnv;
78
+ paths: AppRuntime.LocalRuntimePaths | null;
79
+ assetRoot: string | null;
80
+ }
81
+ /** Compute the environment a web/migration child of this app runs with. */
82
+ export declare function runtimeEnvironment(context: AppContext, runtime: ResolvedApplicationRuntime): RuntimeEnvironment;
83
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/app/runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,oBAAoB,CAAC;AAKtE,OAAO,KAAK,KAAK,UAAU,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAQ7E,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,uCAAuC;AACvC,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,gEAAgE;IAChE,OAAO,CAAC,EAA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4 @@
1
+ import { A as AppCommandError, C as runtimeEnvironment, D as resolveApplicationId, E as prepareApplicationStateRoot, M as redactSecrets, O as resolveApplicationStateRoot, S as cliExecutablePath, T as assertExternalArtifactPath, _ as launchVite, a as renderAppHelp, b as runWorker, c as runApplicationOperation, d as matchesApplicationProcess, f as readOwnedProcess, g as ViteLauncherError, h as writeProcessRecord, i as errorEnvelope, k as runtimeConfigurationFingerprint, l as WEB_LAUNCHER_NAME, m as verifyOwnedProcess, n as APP_RECOVERY, o as runAppCommand, p as sendTerminationSignal, s as APP_OPERATIONS, t as APP_COMMANDS, u as checkOwnedProcess, v as prepareMigration, w as webLauncherPath, x as validateMcpAppsIfPresent, y as resolveViteEntry } from "./cli-BRFsobey.js";
2
+ import { C as publishFilesystemAssets, D as stageFilesystemAssets, E as rollbackFilesystemAssets, O as verifyFilesystemAssets, S as markFilesystemAssetsCommitted, T as recoverFilesystemAssets, _ as bundleContentDigest, a as manifestTables, b as finishFilesystemAssets, c as serializeExportBundle, d as AssetPortabilityError, f as MAX_ASSET_BYTES, g as assertAssetRoot, h as MAX_TOTAL_ASSET_BYTES, i as importedRowsMatchBundle, k as verifyPublishedFilesystemAssets, l as validateImportBundle, m as MAX_BUNDLE_BYTES, n as exportApplication, o as planImportTables, p as MAX_ASSET_COUNT, r as importApplication, t as executeImportPlan, u as ASSET_MANIFEST_SCHEMA_VERSION, v as collectFilesystemAssets, w as readSensitiveBundle, x as hasCommittedImportJournal, y as digestBytes } from "./portability-DmQWSSXA.js";
3
+ import { PROVIDER_READINESS_SETTINGS, RECLAIM_MUTEX_FILE, acquireWriterLease, createProviderReadinessProbe, findInstalledPackage, isStaleOperationLock, lockOwnerPid, processExists, readActiveWriterLease, reclaimStaleRecord, resolveReadinessModule, withOperationLock } from "@happyvertical/smrt-app-runtime";
4
+ export { APP_COMMANDS, APP_OPERATIONS, APP_RECOVERY, ASSET_MANIFEST_SCHEMA_VERSION, AppCommandError, AssetPortabilityError, MAX_ASSET_BYTES, MAX_ASSET_COUNT, MAX_BUNDLE_BYTES, MAX_TOTAL_ASSET_BYTES, PROVIDER_READINESS_SETTINGS, RECLAIM_MUTEX_FILE, ViteLauncherError, WEB_LAUNCHER_NAME, acquireWriterLease, assertAssetRoot, assertExternalArtifactPath, bundleContentDigest, checkOwnedProcess, cliExecutablePath, collectFilesystemAssets, createProviderReadinessProbe, digestBytes, errorEnvelope, executeImportPlan, exportApplication, findInstalledPackage, finishFilesystemAssets, hasCommittedImportJournal, importApplication, importedRowsMatchBundle, isStaleOperationLock, launchVite, lockOwnerPid, manifestTables, markFilesystemAssetsCommitted, matchesApplicationProcess, planImportTables, prepareApplicationStateRoot, prepareMigration, processExists, publishFilesystemAssets, readActiveWriterLease, readOwnedProcess, readSensitiveBundle, reclaimStaleRecord, recoverFilesystemAssets, redactSecrets, renderAppHelp, resolveApplicationId, resolveApplicationStateRoot, resolveReadinessModule, resolveViteEntry, rollbackFilesystemAssets, runAppCommand, runApplicationOperation, runWorker, runtimeConfigurationFingerprint, runtimeEnvironment, sendTerminationSignal, serializeExportBundle, stageFilesystemAssets, validateImportBundle, validateMcpAppsIfPresent, verifyFilesystemAssets, verifyOwnedProcess, verifyPublishedFilesystemAssets, webLauncherPath, withOperationLock, writeProcessRecord };