@codeworksh/schema 0.0.0-stage → 0.1.0-canary.165.2.g336229f9

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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -2
  3. package/common.d.mts +86 -0
  4. package/common.mjs +88 -0
  5. package/common.mjs.map +1 -0
  6. package/daemon.d.mts +12 -0
  7. package/daemon.mjs +22 -0
  8. package/daemon.mjs.map +1 -0
  9. package/door.d.mts +33 -0
  10. package/door.mjs +52 -0
  11. package/door.mjs.map +1 -0
  12. package/event.d.mts +79 -0
  13. package/event.mjs +35 -0
  14. package/event.mjs.map +1 -0
  15. package/forwarded.d.mts +13 -0
  16. package/forwarded.mjs +25 -0
  17. package/forwarded.mjs.map +1 -0
  18. package/host/envelope.d.mts +36 -0
  19. package/host/envelope.mjs +35 -0
  20. package/host/envelope.mjs.map +1 -0
  21. package/host/part.d.mts +2 -0
  22. package/host/part.mjs +60 -0
  23. package/host/part.mjs.map +1 -0
  24. package/host/principal.d.mts +36 -0
  25. package/host/principal.mjs +24 -0
  26. package/host/principal.mjs.map +1 -0
  27. package/host/records.d.mts +1051 -0
  28. package/host/records.mjs +494 -0
  29. package/host/records.mjs.map +1 -0
  30. package/host.d.mts +2224 -0
  31. package/host.mjs +812 -0
  32. package/host.mjs.map +1 -0
  33. package/ids.d.mts +53 -0
  34. package/ids.mjs +60 -0
  35. package/ids.mjs.map +1 -0
  36. package/jws.d.mts +84 -0
  37. package/jws.mjs +119 -0
  38. package/jws.mjs.map +1 -0
  39. package/location.d.mts +55 -0
  40. package/location.mjs +51 -0
  41. package/location.mjs.map +1 -0
  42. package/machine.d.mts +77 -0
  43. package/machine.mjs +48 -0
  44. package/machine.mjs.map +1 -0
  45. package/mcp.d.mts +24 -0
  46. package/mcp.mjs +36 -0
  47. package/mcp.mjs.map +1 -0
  48. package/model.d.mts +18 -0
  49. package/model.mjs +35 -0
  50. package/model.mjs.map +1 -0
  51. package/package.json +182 -5
  52. package/pairing.d.mts +67 -0
  53. package/pairing.mjs +67 -0
  54. package/pairing.mjs.map +1 -0
  55. package/part-Bzm-yNax.d.mts +69 -0
  56. package/project.d.mts +30 -0
  57. package/project.mjs +27 -0
  58. package/project.mjs.map +1 -0
  59. package/records-316ZUpKX.mjs +127 -0
  60. package/records-316ZUpKX.mjs.map +1 -0
  61. package/relay.d.mts +285 -0
  62. package/relay.mjs +115 -0
  63. package/relay.mjs.map +1 -0
  64. package/repo.d.mts +42 -0
  65. package/repo.mjs +46 -0
  66. package/repo.mjs.map +1 -0
  67. package/rolldown-runtime-D7D4PA-g.mjs +13 -0
  68. package/sandbox/driver.d.mts +10 -0
  69. package/sandbox/driver.mjs +13 -0
  70. package/sandbox/driver.mjs.map +1 -0
  71. package/sandbox/errors.d.mts +130 -0
  72. package/sandbox/errors.mjs +112 -0
  73. package/sandbox/errors.mjs.map +1 -0
  74. package/sandbox/instance.d.mts +152 -0
  75. package/sandbox/instance.mjs +150 -0
  76. package/sandbox/instance.mjs.map +1 -0
  77. package/session.d.mts +59 -0
  78. package/session.mjs +69 -0
  79. package/session.mjs.map +1 -0
  80. package/settings.d.mts +22 -0
  81. package/settings.mjs +32 -0
  82. package/settings.mjs.map +1 -0
  83. package/shell.d.mts +5 -0
  84. package/shell.mjs +7 -0
  85. package/shell.mjs.map +1 -0
  86. package/space-CR-9UxdT.d.mts +25 -0
  87. package/space.d.mts +2 -0
  88. package/space.mjs +33 -0
  89. package/space.mjs.map +1 -0
  90. package/thread.d.mts +50 -0
  91. package/thread.mjs +69 -0
  92. package/thread.mjs.map +1 -0
  93. package/usage-B_TDmpKC.d.mts +15 -0
  94. package/usage.d.mts +2 -0
  95. package/usage.mjs +43 -0
  96. package/usage.mjs.map +1 -0
package/repo.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo.mjs","names":[],"sources":["../../src/repo.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport { AbsolutePath } from \"./common.ts\";\n\n// Identified vcs type and its shared storage path.\n// Example: `{ type: \"git\", store: \"/app/code/.git\" }`\nexport const Vcs = Schema.Union([\n\tSchema.Struct({\n\t\ttype: Schema.Literal(\"git\"),\n\t\tstore: AbsolutePath,\n\t}),\n]);\nexport type Vcs = typeof Vcs.Type;\n\n// A discovered git repository. Every path is realpath'd.\nexport const Info = Schema.Struct({\n\t/**\n\t * The root directory of the working tree that contains the input path\n\t * (`rev-parse --show-toplevel`).\n\t *\n\t * For `/home/me/app/src/file.ts` in a normal clone, this is `/home/me/app`.\n\t * For `/home/me/app-feature/src/file.ts` in a linked worktree, this is\n\t * `/home/me/app-feature`.\n\t */\n\tdirectory: AbsolutePath,\n\t/**\n\t * This checkout's own git directory (`rev-parse --git-dir`).\n\t *\n\t * For a normal clone at `/home/me/app`, this is `/home/me/app/.git`. For a\n\t * linked worktree it lives under the store, e.g.\n\t * `/home/me/app/.git/worktrees/app-feature`. `gitDir === store` iff this is\n\t * the main checkout.\n\t */\n\tgitDir: AbsolutePath,\n\t/**\n\t * The shared Git storage directory used by this repo and any linked\n\t * worktrees (`rev-parse --git-common-dir`).\n\t *\n\t * For a normal clone at `/home/me/app`, this is usually `/home/me/app/.git`.\n\t * For a linked worktree at `/home/me/app-feature` whose main checkout is\n\t * `/home/me/app`, this is usually `/home/me/app/.git`.\n\t */\n\tstore: AbsolutePath,\n});\nexport type Info = typeof Info.Type;\n\nexport * as RepoSchema from \"./repo.ts\";\n"],"mappings":";;;;;;;;;AAKA,MAAa,MAAM,OAAO,MAAM,CAC/B,OAAO,OAAO;CACb,MAAM,OAAO,QAAQ,KAAK;CAC1B,OAAO;AACR,CAAC,CACF,CAAC;AAID,MAAa,OAAO,OAAO,OAAO;;;;;;;;;CASjC,WAAW;;;;;;;;;CASX,QAAQ;;;;;;;;;CASR,OAAO;AACR,CAAC"}
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };
@@ -0,0 +1,10 @@
1
+ import { Schema } from "effect";
2
+ declare namespace driver_d_exports {
3
+ export { Name, driver_d_exports as SandboxDriver };
4
+ }
5
+ /** Open driver identity. Adding a driver never extends a union in core. */
6
+ export declare const Name: Schema.brand<Schema.String, "SandboxDriver.Name">;
7
+ export type Name = typeof Name.Type;
8
+ //#endregion
9
+ export { driver_d_exports as SandboxDriver };
10
+ //# sourceMappingURL=driver.d.mts.map
@@ -0,0 +1,13 @@
1
+ import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Schema } from "effect";
3
+ //#region src/sandbox/driver.ts
4
+ var driver_exports = /* @__PURE__ */ __exportAll({
5
+ Name: () => Name,
6
+ SandboxDriver: () => driver_exports
7
+ });
8
+ /** Open driver identity. Adding a driver never extends a union in core. */
9
+ const Name = Schema.String.check(Schema.isNonEmpty()).pipe(Schema.brand("SandboxDriver.Name"));
10
+ //#endregion
11
+ export { Name, driver_exports as SandboxDriver };
12
+
13
+ //# sourceMappingURL=driver.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.mjs","names":[],"sources":["../../../src/sandbox/driver.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n/** Open driver identity. Adding a driver never extends a union in core. */\nexport const Name = Schema.String.check(Schema.isNonEmpty()).pipe(Schema.brand(\"SandboxDriver.Name\"));\nexport type Name = typeof Name.Type;\n\nexport * as SandboxDriver from \"./driver.ts\";\n"],"mappings":";;;;;;;;AAGA,MAAa,OAAO,OAAO,OAAO,MAAM,OAAO,WAAW,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,130 @@
1
+ import { Schema } from "effect";
2
+ declare namespace errors_d_exports {
3
+ export { SandboxBusyError, SandboxCreateError, SandboxDestroyError, SandboxDriverLoadError, SandboxDriverLoadPhase, SandboxDriverNotRegisteredError, SandboxDriverRegistrationError, errors_d_exports as SandboxError, SandboxMountError, SandboxMustBeStoppedError, SandboxNotFoundError, SandboxNotHeldError, SandboxProviderError, SandboxReadError, SandboxRefreshError, SandboxRegisterError, SandboxRemovedError, SandboxStopError, SandboxTransitionConflictError, SandboxUnavailError, SandboxUnsupportedError, SandboxWakeError };
4
+ }
5
+ declare const SandboxNotFoundError_base: Schema.Class<SandboxNotFoundError, Schema.TaggedStruct<"SandboxNotFoundError", {
6
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
7
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
8
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
9
+ };
10
+ }>, import("effect/Cause").YieldableError>;
11
+ /**
12
+ * Lifecycle errors are confined to the control plane. Once a mount succeeds,
13
+ * consumers continue to see only FileSystemError and ShellError.
14
+ */
15
+ export declare class SandboxNotFoundError extends SandboxNotFoundError_base {
16
+ get message(): string;
17
+ }
18
+ declare const SandboxDriverNotRegisteredError_base: Schema.Class<SandboxDriverNotRegisteredError, Schema.TaggedStruct<"SandboxDriverNotRegisteredError", {
19
+ readonly driver: Schema.String;
20
+ readonly registered: Schema.optional<Schema.$Array<Schema.String>>;
21
+ }>, import("effect/Cause").YieldableError>;
22
+ export declare class SandboxDriverNotRegisteredError extends SandboxDriverNotRegisteredError_base {
23
+ get message(): string;
24
+ }
25
+ declare const SandboxDriverRegistrationError_base: Schema.Class<SandboxDriverRegistrationError, Schema.TaggedStruct<"SandboxDriverRegistrationError", {
26
+ readonly driver: Schema.String;
27
+ readonly reason: Schema.String;
28
+ }>, import("effect/Cause").YieldableError>;
29
+ export declare class SandboxDriverRegistrationError extends SandboxDriverRegistrationError_base {}
30
+ export declare const SandboxDriverLoadPhase: Schema.Literals<readonly ["resolve", "import", "module", "api-version", "options", "factory", "registration"]>;
31
+ export type SandboxDriverLoadPhase = typeof SandboxDriverLoadPhase.Type;
32
+ declare const SandboxDriverLoadError_base: Schema.Class<SandboxDriverLoadError, Schema.TaggedStruct<"SandboxDriverLoadError", {
33
+ readonly specifier: Schema.String;
34
+ readonly phase: Schema.Literals<readonly ["resolve", "import", "module", "api-version", "options", "factory", "registration"]>;
35
+ readonly driver: Schema.optional<Schema.String>;
36
+ readonly reason: Schema.String;
37
+ }>, import("effect/Cause").YieldableError>;
38
+ export declare class SandboxDriverLoadError extends SandboxDriverLoadError_base {}
39
+ declare const SandboxBusyError_base: Schema.Class<SandboxBusyError, Schema.TaggedStruct<"SandboxBusyError", {
40
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
41
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
42
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
43
+ };
44
+ readonly refCount: Schema.Int;
45
+ }>, import("effect/Cause").YieldableError>;
46
+ export declare class SandboxBusyError extends SandboxBusyError_base {}
47
+ declare const SandboxNotHeldError_base: Schema.Class<SandboxNotHeldError, Schema.TaggedStruct<"SandboxNotHeldError", {
48
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
49
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
50
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
51
+ };
52
+ }>, import("effect/Cause").YieldableError>;
53
+ /** No drain holds the sandbox and no handover is open: borrowing its I/O would have to attach, which can wake it. */
54
+ export declare class SandboxNotHeldError extends SandboxNotHeldError_base {}
55
+ declare const SandboxMustBeStoppedError_base: Schema.Class<SandboxMustBeStoppedError, Schema.TaggedStruct<"SandboxMustBeStoppedError", {
56
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
57
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
58
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
59
+ };
60
+ readonly status: Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>;
61
+ }>, import("effect/Cause").YieldableError>;
62
+ export declare class SandboxMustBeStoppedError extends SandboxMustBeStoppedError_base {}
63
+ declare const SandboxRemovedError_base: Schema.Class<SandboxRemovedError, Schema.TaggedStruct<"SandboxRemovedError", {
64
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
65
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
66
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
67
+ };
68
+ readonly removedAt: Schema.optional<Schema.DateTimeUtc>;
69
+ }>, import("effect/Cause").YieldableError>;
70
+ export declare class SandboxRemovedError extends SandboxRemovedError_base {
71
+ get message(): string;
72
+ }
73
+ declare const SandboxUnavailError_base: Schema.Class<SandboxUnavailError, Schema.TaggedStruct<"SandboxUnavailError", {
74
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
75
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
76
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
77
+ };
78
+ readonly reason: Schema.String;
79
+ }>, import("effect/Cause").YieldableError>;
80
+ export declare class SandboxUnavailError extends SandboxUnavailError_base {
81
+ get message(): string;
82
+ }
83
+ declare const SandboxUnsupportedError_base: Schema.Class<SandboxUnsupportedError, Schema.TaggedStruct<"SandboxUnsupportedError", {
84
+ readonly id: Schema.optional<Schema.brand<Schema.String, "SandboxInstance.ID"> & {
85
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
86
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
87
+ }>;
88
+ readonly driver: Schema.String;
89
+ readonly operation: Schema.String;
90
+ }>, import("effect/Cause").YieldableError>;
91
+ export declare class SandboxUnsupportedError extends SandboxUnsupportedError_base {}
92
+ declare const SandboxTransitionConflictError_base: Schema.Class<SandboxTransitionConflictError, Schema.TaggedStruct<"SandboxTransitionConflictError", {
93
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
94
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
95
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
96
+ };
97
+ readonly expected: Schema.$Array<Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>>;
98
+ readonly actual: Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>;
99
+ }>, import("effect/Cause").YieldableError>;
100
+ export declare class SandboxTransitionConflictError extends SandboxTransitionConflictError_base {}
101
+ declare const SandboxProviderError_base: Schema.Class<SandboxProviderError, Schema.TaggedStruct<"SandboxProviderError", {
102
+ readonly driver: Schema.String;
103
+ readonly operation: Schema.String;
104
+ readonly sanitized: Schema.Struct<{
105
+ readonly name: Schema.String;
106
+ readonly message: Schema.String;
107
+ readonly code: Schema.optional<Schema.String>;
108
+ }>;
109
+ }>, import("effect/Cause").YieldableError>;
110
+ /**
111
+ * A lifecycle failure safe to serialize, persist, or log.
112
+ *
113
+ * The raw SDK defect is deliberately absent from the schema. It is retained on
114
+ * a non-enumerable symbol by `providerError` in `@codeworksh/plugin/sandbox/errors`, so Effect's
115
+ * default formatting and JSON serialization cannot expose credentials nested in it.
116
+ */
117
+ export declare class SandboxProviderError extends SandboxProviderError_base {
118
+ get message(): string;
119
+ }
120
+ export type SandboxMountError = SandboxNotFoundError | SandboxDriverNotRegisteredError | SandboxUnavailError | SandboxRemovedError | SandboxProviderError;
121
+ export type SandboxCreateError = SandboxDriverNotRegisteredError | SandboxDriverRegistrationError | SandboxProviderError;
122
+ export type SandboxRegisterError = SandboxDriverNotRegisteredError | SandboxDriverRegistrationError | SandboxUnsupportedError | SandboxProviderError;
123
+ export type SandboxReadError = never;
124
+ export type SandboxRefreshError = SandboxNotFoundError | SandboxDriverNotRegisteredError | SandboxUnavailError | SandboxUnsupportedError | SandboxProviderError;
125
+ export type SandboxWakeError = SandboxRefreshError | SandboxRemovedError;
126
+ export type SandboxStopError = SandboxWakeError | SandboxBusyError | SandboxTransitionConflictError;
127
+ export type SandboxDestroyError = SandboxStopError | SandboxMustBeStoppedError;
128
+ //#endregion
129
+ export { errors_d_exports as SandboxError };
130
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1,112 @@
1
+ import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
2
+ import { ID, PersistedError, Status } from "./instance.mjs";
3
+ import { Schema } from "effect";
4
+ //#region src/sandbox/errors.ts
5
+ var errors_exports = /* @__PURE__ */ __exportAll({
6
+ SandboxBusyError: () => SandboxBusyError,
7
+ SandboxDriverLoadError: () => SandboxDriverLoadError,
8
+ SandboxDriverLoadPhase: () => SandboxDriverLoadPhase,
9
+ SandboxDriverNotRegisteredError: () => SandboxDriverNotRegisteredError,
10
+ SandboxDriverRegistrationError: () => SandboxDriverRegistrationError,
11
+ SandboxError: () => errors_exports,
12
+ SandboxMustBeStoppedError: () => SandboxMustBeStoppedError,
13
+ SandboxNotFoundError: () => SandboxNotFoundError,
14
+ SandboxNotHeldError: () => SandboxNotHeldError,
15
+ SandboxProviderError: () => SandboxProviderError,
16
+ SandboxRemovedError: () => SandboxRemovedError,
17
+ SandboxTransitionConflictError: () => SandboxTransitionConflictError,
18
+ SandboxUnavailError: () => SandboxUnavailError,
19
+ SandboxUnsupportedError: () => SandboxUnsupportedError
20
+ });
21
+ /**
22
+ * Lifecycle errors are confined to the control plane. Once a mount succeeds,
23
+ * consumers continue to see only FileSystemError and ShellError.
24
+ */
25
+ var SandboxNotFoundError = class extends Schema.TaggedError()("SandboxNotFoundError", { id: ID }) {
26
+ get message() {
27
+ return `Sandbox ${this.id} does not exist.`;
28
+ }
29
+ };
30
+ var SandboxDriverNotRegisteredError = class extends Schema.TaggedError()("SandboxDriverNotRegisteredError", {
31
+ driver: Schema.String,
32
+ registered: Schema.optional(Schema.Array(Schema.String))
33
+ }) {
34
+ get message() {
35
+ return `No sandbox driver named "${this.driver}" is registered.`;
36
+ }
37
+ };
38
+ var SandboxDriverRegistrationError = class extends Schema.TaggedError()("SandboxDriverRegistrationError", {
39
+ driver: Schema.String,
40
+ reason: Schema.String
41
+ }) {};
42
+ const SandboxDriverLoadPhase = Schema.Literals([
43
+ "resolve",
44
+ "import",
45
+ "module",
46
+ "api-version",
47
+ "options",
48
+ "factory",
49
+ "registration"
50
+ ]);
51
+ var SandboxDriverLoadError = class extends Schema.TaggedError()("SandboxDriverLoadError", {
52
+ specifier: Schema.String,
53
+ phase: SandboxDriverLoadPhase,
54
+ driver: Schema.optional(Schema.String),
55
+ reason: Schema.String
56
+ }) {};
57
+ var SandboxBusyError = class extends Schema.TaggedError()("SandboxBusyError", {
58
+ id: ID,
59
+ refCount: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))
60
+ }) {};
61
+ /** No drain holds the sandbox and no handover is open: borrowing its I/O would have to attach, which can wake it. */
62
+ var SandboxNotHeldError = class extends Schema.TaggedError()("SandboxNotHeldError", { id: ID }) {};
63
+ var SandboxMustBeStoppedError = class extends Schema.TaggedError()("SandboxMustBeStoppedError", {
64
+ id: ID,
65
+ status: Status
66
+ }) {};
67
+ var SandboxRemovedError = class extends Schema.TaggedError()("SandboxRemovedError", {
68
+ id: ID,
69
+ removedAt: Schema.optional(Schema.DateTimeUtc)
70
+ }) {
71
+ get message() {
72
+ return `Sandbox ${this.id} was removed.`;
73
+ }
74
+ };
75
+ var SandboxUnavailError = class extends Schema.TaggedError()("SandboxUnavailError", {
76
+ id: ID,
77
+ reason: Schema.String
78
+ }) {
79
+ get message() {
80
+ return `Sandbox ${this.id} is unavailable: ${this.reason}`;
81
+ }
82
+ };
83
+ var SandboxUnsupportedError = class extends Schema.TaggedError()("SandboxUnsupportedError", {
84
+ id: Schema.optional(ID),
85
+ driver: Schema.String,
86
+ operation: Schema.String
87
+ }) {};
88
+ var SandboxTransitionConflictError = class extends Schema.TaggedError()("SandboxTransitionConflictError", {
89
+ id: ID,
90
+ expected: Schema.Array(Status),
91
+ actual: Status
92
+ }) {};
93
+ /**
94
+ * A lifecycle failure safe to serialize, persist, or log.
95
+ *
96
+ * The raw SDK defect is deliberately absent from the schema. It is retained on
97
+ * a non-enumerable symbol by `providerError` in `@codeworksh/plugin/sandbox/errors`, so Effect's
98
+ * default formatting and JSON serialization cannot expose credentials nested in it.
99
+ */
100
+ var SandboxProviderError = class extends Schema.TaggedError()("SandboxProviderError", {
101
+ driver: Schema.String,
102
+ operation: Schema.String,
103
+ sanitized: PersistedError
104
+ }) {
105
+ get message() {
106
+ return `The ${this.driver} sandbox failed to ${this.operation}: ${this.sanitized.message}`;
107
+ }
108
+ };
109
+ //#endregion
110
+ export { SandboxBusyError, SandboxDriverLoadError, SandboxDriverLoadPhase, SandboxDriverNotRegisteredError, SandboxDriverRegistrationError, errors_exports as SandboxError, SandboxMustBeStoppedError, SandboxNotFoundError, SandboxNotHeldError, SandboxProviderError, SandboxRemovedError, SandboxTransitionConflictError, SandboxUnavailError, SandboxUnsupportedError };
111
+
112
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","names":["SandboxInstance.ID","SandboxInstance.Status","SandboxInstance.PersistedError"],"sources":["../../../src/sandbox/errors.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport { SandboxInstance } from \"./instance.ts\";\n\n/**\n * Lifecycle errors are confined to the control plane. Once a mount succeeds,\n * consumers continue to see only FileSystemError and ShellError.\n */\nexport class SandboxNotFoundError extends Schema.TaggedError<SandboxNotFoundError>()(\"SandboxNotFoundError\", {\n\tid: SandboxInstance.ID,\n}) {\n\toverride get message(): string {\n\t\treturn `Sandbox ${this.id} does not exist.`;\n\t}\n}\n\nexport class SandboxDriverNotRegisteredError extends Schema.TaggedError<SandboxDriverNotRegisteredError>()(\n\t\"SandboxDriverNotRegisteredError\",\n\t{\n\t\tdriver: Schema.String,\n\t\tregistered: Schema.optional(Schema.Array(Schema.String)),\n\t},\n) {\n\toverride get message(): string {\n\t\treturn `No sandbox driver named \"${this.driver}\" is registered.`;\n\t}\n}\n\nexport class SandboxDriverRegistrationError extends Schema.TaggedError<SandboxDriverRegistrationError>()(\n\t\"SandboxDriverRegistrationError\",\n\t{\n\t\tdriver: Schema.String,\n\t\treason: Schema.String,\n\t},\n) {}\n\nexport const SandboxDriverLoadPhase = Schema.Literals([\n\t\"resolve\",\n\t\"import\",\n\t\"module\",\n\t\"api-version\",\n\t\"options\",\n\t\"factory\",\n\t\"registration\",\n]);\nexport type SandboxDriverLoadPhase = typeof SandboxDriverLoadPhase.Type;\n\nexport class SandboxDriverLoadError extends Schema.TaggedError<SandboxDriverLoadError>()(\"SandboxDriverLoadError\", {\n\tspecifier: Schema.String,\n\tphase: SandboxDriverLoadPhase,\n\tdriver: Schema.optional(Schema.String),\n\treason: Schema.String,\n}) {}\n\nexport class SandboxBusyError extends Schema.TaggedError<SandboxBusyError>()(\"SandboxBusyError\", {\n\tid: SandboxInstance.ID,\n\trefCount: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n}) {}\n\n/** No drain holds the sandbox and no handover is open: borrowing its I/O would have to attach, which can wake it. */\nexport class SandboxNotHeldError extends Schema.TaggedError<SandboxNotHeldError>()(\"SandboxNotHeldError\", {\n\tid: SandboxInstance.ID,\n}) {}\n\nexport class SandboxMustBeStoppedError extends Schema.TaggedError<SandboxMustBeStoppedError>()(\n\t\"SandboxMustBeStoppedError\",\n\t{\n\t\tid: SandboxInstance.ID,\n\t\tstatus: SandboxInstance.Status,\n\t},\n) {}\n\nexport class SandboxRemovedError extends Schema.TaggedError<SandboxRemovedError>()(\"SandboxRemovedError\", {\n\tid: SandboxInstance.ID,\n\tremovedAt: Schema.optional(Schema.DateTimeUtc),\n}) {\n\toverride get message(): string {\n\t\treturn `Sandbox ${this.id} was removed.`;\n\t}\n}\n\nexport class SandboxUnavailError extends Schema.TaggedError<SandboxUnavailError>()(\"SandboxUnavailError\", {\n\tid: SandboxInstance.ID,\n\treason: Schema.String,\n}) {\n\toverride get message(): string {\n\t\treturn `Sandbox ${this.id} is unavailable: ${this.reason}`;\n\t}\n}\n\nexport class SandboxUnsupportedError extends Schema.TaggedError<SandboxUnsupportedError>()(\"SandboxUnsupportedError\", {\n\tid: Schema.optional(SandboxInstance.ID),\n\tdriver: Schema.String,\n\toperation: Schema.String,\n}) {}\n\nexport class SandboxTransitionConflictError extends Schema.TaggedError<SandboxTransitionConflictError>()(\n\t\"SandboxTransitionConflictError\",\n\t{\n\t\tid: SandboxInstance.ID,\n\t\texpected: Schema.Array(SandboxInstance.Status),\n\t\tactual: SandboxInstance.Status,\n\t},\n) {}\n\n/**\n * A lifecycle failure safe to serialize, persist, or log.\n *\n * The raw SDK defect is deliberately absent from the schema. It is retained on\n * a non-enumerable symbol by `providerError` in `@codeworksh/plugin/sandbox/errors`, so Effect's\n * default formatting and JSON serialization cannot expose credentials nested in it.\n */\nexport class SandboxProviderError extends Schema.TaggedError<SandboxProviderError>()(\"SandboxProviderError\", {\n\tdriver: Schema.String,\n\toperation: Schema.String,\n\tsanitized: SandboxInstance.PersistedError,\n}) {\n\toverride get message(): string {\n\t\treturn `The ${this.driver} sandbox failed to ${this.operation}: ${this.sanitized.message}`;\n\t}\n}\n\nexport type SandboxMountError =\n\t| SandboxNotFoundError\n\t| SandboxDriverNotRegisteredError\n\t| SandboxUnavailError\n\t| SandboxRemovedError\n\t| SandboxProviderError;\n\nexport type SandboxCreateError =\n\t| SandboxDriverNotRegisteredError\n\t| SandboxDriverRegistrationError\n\t| SandboxProviderError;\n\nexport type SandboxRegisterError =\n\t| SandboxDriverNotRegisteredError\n\t| SandboxDriverRegistrationError\n\t| SandboxUnsupportedError\n\t| SandboxProviderError;\n\nexport type SandboxReadError = never;\n\nexport type SandboxRefreshError =\n\t| SandboxNotFoundError\n\t| SandboxDriverNotRegisteredError\n\t| SandboxUnavailError\n\t| SandboxUnsupportedError\n\t| SandboxProviderError;\n\nexport type SandboxWakeError = SandboxRefreshError | SandboxRemovedError;\n\nexport type SandboxStopError = SandboxWakeError | SandboxBusyError | SandboxTransitionConflictError;\n\nexport type SandboxDestroyError = SandboxStopError | SandboxMustBeStoppedError;\n\nexport * as SandboxError from \"./errors.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAAC,wBAAwB,EAC5G,IAAIA,GACL,CAAC,CAAC,CAAC;CACF,IAAa,UAAkB;EAC9B,OAAO,WAAW,KAAK,GAAG;CAC3B;AACD;AAEA,IAAa,kCAAb,cAAqD,OAAO,YAA6C,CAAC,CACzG,mCACA;CACC,QAAQ,OAAO;CACf,YAAY,OAAO,SAAS,OAAO,MAAM,OAAO,MAAM,CAAC;AACxD,CACD,CAAC,CAAC;CACD,IAAa,UAAkB;EAC9B,OAAO,4BAA4B,KAAK,OAAO;CAChD;AACD;AAEA,IAAa,iCAAb,cAAoD,OAAO,YAA4C,CAAC,CACvG,kCACA;CACC,QAAQ,OAAO;CACf,QAAQ,OAAO;AAChB,CACD,CAAC,CAAC,CAAC;AAEH,MAAa,yBAAyB,OAAO,SAAS;CACrD;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AAGD,IAAa,yBAAb,cAA4C,OAAO,YAAoC,CAAC,CAAC,0BAA0B;CAClH,WAAW,OAAO;CAClB,OAAO;CACP,QAAQ,OAAO,SAAS,OAAO,MAAM;CACrC,QAAQ,OAAO;AAChB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAAC,oBAAoB;CAChG,IAAIA;CACJ,UAAU,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAAC,uBAAuB,EACzG,IAAIA,GACL,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,4BAAb,cAA+C,OAAO,YAAuC,CAAC,CAC7F,6BACA;CACC,IAAIA;CACJ,QAAQC;AACT,CACD,CAAC,CAAC,CAAC;AAEH,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAAC,uBAAuB;CACzG,IAAID;CACJ,WAAW,OAAO,SAAS,OAAO,WAAW;AAC9C,CAAC,CAAC,CAAC;CACF,IAAa,UAAkB;EAC9B,OAAO,WAAW,KAAK,GAAG;CAC3B;AACD;AAEA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAAC,uBAAuB;CACzG,IAAIA;CACJ,QAAQ,OAAO;AAChB,CAAC,CAAC,CAAC;CACF,IAAa,UAAkB;EAC9B,OAAO,WAAW,KAAK,GAAG,mBAAmB,KAAK;CACnD;AACD;AAEA,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CAAC,2BAA2B;CACrH,IAAI,OAAO,SAASA,EAAkB;CACtC,QAAQ,OAAO;CACf,WAAW,OAAO;AACnB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,iCAAb,cAAoD,OAAO,YAA4C,CAAC,CACvG,kCACA;CACC,IAAIA;CACJ,UAAU,OAAO,MAAMC,MAAsB;CAC7C,QAAQA;AACT,CACD,CAAC,CAAC,CAAC;;;;;;;;AASH,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAAC,wBAAwB;CAC5G,QAAQ,OAAO;CACf,WAAW,OAAO;CAClB,WAAWC;AACZ,CAAC,CAAC,CAAC;CACF,IAAa,UAAkB;EAC9B,OAAO,OAAO,KAAK,OAAO,qBAAqB,KAAK,UAAU,IAAI,KAAK,UAAU;CAClF;AACD"}
@@ -0,0 +1,152 @@
1
+ import { Name, SandboxDriver as driver_d_exports } from "./driver.mjs";
2
+ import { Option, Schema } from "effect";
3
+ declare namespace instance_d_exports {
4
+ export { ID, Info, Kind, Ownership, PersistedError, instance_d_exports as SandboxInstance, Selection, Status, Usage, fromColumn, fromField, isMountable, mountable, toColumn, toField };
5
+ }
6
+ /**
7
+ * A Sandbox instance is a **durable filesystem namespace** plus whatever compute
8
+ * acts on it — a device in Unix terms, which exists whether or not anything has
9
+ * it mounted. `Sandbox.Controller` is the only thing that creates,
10
+ * stops, or destroys one; this module is just its identity and state model.
11
+ *
12
+ * The application ID is deliberately separate from the driver's own resource
13
+ * locator: callers never parse a Vercel name or a Daytona ID, driver formats may
14
+ * change, and a destroyed resource must stay identifiable in Project/Session
15
+ * history. A missing resource is never recreated under an existing ID — a new
16
+ * resource is a new namespace and therefore a new ID.
17
+ */
18
+ export declare const ID: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
19
+ /**
20
+ * The host. Reserved, and never written to a column — see {@link toColumn}.
21
+ * It exists at runtime so nothing has to branch on "is this the host": it is
22
+ * what identity reads, what logs show, and what the transport cache keys on.
23
+ */
24
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
25
+ /** A fresh identity for a namespace nothing has named yet. */
26
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
27
+ };
28
+ export type ID = typeof ID.Type;
29
+ /**
30
+ * The storage boundary for namespace references, in one place.
31
+ *
32
+ * The host filesystem exists whether or not a row describes it, so it gets no
33
+ * row and `NULL` is the only spelling of it — the Unix analogue is exact, since
34
+ * `/` has no entry in the mount table you consult to find other mounts. That
35
+ * makes a session or directory writable before any namespace is registered (the
36
+ * foreign key is skipped on NULL), makes `SET sandbox_instance_id = NULL` a
37
+ * meaningful "revert to the host", and leaves the host impossible to tombstone,
38
+ * collect, or destroy, because there is nothing to point at.
39
+ *
40
+ * Two SQLite consequences ride on this and break correctness silently if missed:
41
+ * unique indexes treat NULLs as distinct, so every uniqueness constraint
42
+ * spanning a namespace column coalesces to `'local'`; and `= NULL` never
43
+ * matches, so namespace-scoped reads use `IS`.
44
+ */
45
+ export declare const toColumn: (id: ID) => string | null;
46
+ export declare const fromColumn: (value: string | null) => ID;
47
+ /**
48
+ * The same mapping for row models, whose optional columns are `Option` rather
49
+ * than `null`. Kept beside {@link toColumn} so the boundary stays one place:
50
+ * `toColumn`/`fromColumn` for SQL parameters, these for `Model.FieldOption`.
51
+ */
52
+ export declare const toField: (id: ID) => Option.Option<ID>;
53
+ export declare const fromField: (value: Option.Option<ID>) => ID;
54
+ /**
55
+ * Filesystem-class taxonomy, mirroring Unix: disk, tmpfs/procfs, NFS/CIFS.
56
+ * Stored on the row rather than derived from the registered driver, so reading
57
+ * an instance never depends on the registry — which matters most when a driver
58
+ * is *not* configured and you need to list or clean up its rows.
59
+ */
60
+ export declare const Kind: Schema.Literals<readonly ["local", "virtual", "remote"]>;
61
+ export type Kind = typeof Kind.Type;
62
+ export declare const Ownership: Schema.Literals<readonly ["managed", "external"]>;
63
+ export type Ownership = typeof Ownership.Type;
64
+ /**
65
+ * Lifecycle state, in ZFS pool vocabulary. This is the **last observed** value,
66
+ * not live driver truth: Daytona auto-stops and auto-archives, Vercel sandboxes
67
+ * expire on their own timeout, so drift is normal. `stateObservedAt` carries the
68
+ * freshness and `Controller.refresh` updates it without waking anything.
69
+ *
70
+ * `removed` and `unavail` are deliberately distinct. `removed` means we deleted
71
+ * it; `unavail` means the driver claims it is gone. A "not found" is frequently a
72
+ * misclassification — wrong region, wrong API url, a revoked key answering 404,
73
+ * eventual consistency right after create — so it must never be recorded as if we
74
+ * had destroyed the resource ourselves.
75
+ */
76
+ export declare const Status: Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>;
77
+ export type Status = typeof Status.Type;
78
+ /**
79
+ * The statuses a `mount` may proceed from. This is the predicate every
80
+ * conditional write depends on, so it is enumerated once here rather than
81
+ * restated as prose at each call site.
82
+ *
83
+ * `offline` qualifies because mounting wakes.
84
+ * `faulted` qualifies because a fault is a *usability* condition, not an identity one — see {@link Status}.
85
+ *
86
+ * There is no `resuming`: it would exist to be observed by nothing, since
87
+ * mounting wakes, `offline` is already mountable, and waking is not destructive
88
+ * so it needs no claim. `suspending` and `removing` stay because they *are*
89
+ * compare-and-set claims, blocking a concurrent mount mid-destruction.
90
+ */
91
+ export declare const mountable: ReadonlySet<Status>;
92
+ export declare const isMountable: (status: Status) => boolean;
93
+ /**
94
+ * Reference state, derived — never stored. `busy` carries its `umount` meaning:
95
+ * something holds this and destruction must not proceed unforced.
96
+ *
97
+ * `pinned` is the kernel sense of the word: never reclaimable. It short-circuits
98
+ * counting entirely for instances that cannot be stopped or destroyed (the local
99
+ * host), which is what keeps them out of any future collector by construction
100
+ * rather than by an ownership check happening to catch them.
101
+ */
102
+ export declare const Usage: Schema.Literals<readonly ["idle", "busy", "pinned"]>;
103
+ export type Usage = typeof Usage.Type;
104
+ /** Sanitized driver failure. The only error shape allowed to be persisted or logged. */
105
+ export declare const PersistedError: Schema.Struct<{
106
+ readonly name: Schema.String;
107
+ readonly message: Schema.String;
108
+ readonly code: Schema.optional<Schema.String>;
109
+ }>;
110
+ export type PersistedError = typeof PersistedError.Type;
111
+ /** Durable metadata, safe to return and persist. Assembled by the control plane. */
112
+ export interface Info {
113
+ readonly id: ID;
114
+ readonly driver: Name;
115
+ readonly kind: Kind;
116
+ readonly providerResourceId: Option.Option<string>;
117
+ readonly ownership: Ownership;
118
+ readonly status: Status;
119
+ readonly usage: Usage;
120
+ /** References held by *this* control plane. Process-local; see the transport cache. */
121
+ readonly refCount: number;
122
+ readonly providerStatus: Option.Option<string>;
123
+ readonly metadata: Readonly<Record<string, string>>;
124
+ readonly lastError: Option.Option<PersistedError>;
125
+ readonly createdAt: Date;
126
+ readonly updatedAt: Date;
127
+ readonly stateObservedAt: Date;
128
+ readonly lastMountedAt: Option.Option<Date>;
129
+ readonly lastUnmountedAt: Option.Option<Date>;
130
+ readonly lastUsedAt: Option.Option<Date>;
131
+ readonly removedAt: Option.Option<Date>;
132
+ }
133
+ /** Coordinates for either reusing an instance or provisioning/registering one. */
134
+ export declare const Selection: Schema.Union<readonly [Schema.Struct<{
135
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
136
+ /**
137
+ * The host. Reserved, and never written to a column — see {@link toColumn}.
138
+ * It exists at runtime so nothing has to branch on "is this the host": it is
139
+ * what identity reads, what logs show, and what the transport cache keys on.
140
+ */
141
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
142
+ /** A fresh identity for a namespace nothing has named yet. */
143
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
144
+ };
145
+ }>, Schema.Struct<{
146
+ readonly driver: Schema.String;
147
+ readonly providerResourceId: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
148
+ }>]>;
149
+ export type Selection = typeof Selection.Type;
150
+ //#endregion
151
+ export { instance_d_exports as SandboxInstance };
152
+ //# sourceMappingURL=instance.d.mts.map
@@ -0,0 +1,150 @@
1
+ import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
2
+ import { optional, withStatics } from "../common.mjs";
3
+ import { Option, Schema } from "effect";
4
+ import { uuidv7 } from "uuidv7";
5
+ //#region src/sandbox/instance.ts
6
+ var instance_exports = /* @__PURE__ */ __exportAll({
7
+ ID: () => ID,
8
+ Kind: () => Kind,
9
+ Ownership: () => Ownership,
10
+ PersistedError: () => PersistedError,
11
+ SandboxInstance: () => instance_exports,
12
+ Selection: () => Selection,
13
+ Status: () => Status,
14
+ Usage: () => Usage,
15
+ fromColumn: () => fromColumn,
16
+ fromField: () => fromField,
17
+ isMountable: () => isMountable,
18
+ mountable: () => mountable,
19
+ toColumn: () => toColumn,
20
+ toField: () => toField
21
+ });
22
+ /**
23
+ * A Sandbox instance is a **durable filesystem namespace** plus whatever compute
24
+ * acts on it — a device in Unix terms, which exists whether or not anything has
25
+ * it mounted. `Sandbox.Controller` is the only thing that creates,
26
+ * stops, or destroys one; this module is just its identity and state model.
27
+ *
28
+ * The application ID is deliberately separate from the driver's own resource
29
+ * locator: callers never parse a Vercel name or a Daytona ID, driver formats may
30
+ * change, and a destroyed resource must stay identifiable in Project/Session
31
+ * history. A missing resource is never recreated under an existing ID — a new
32
+ * resource is a new namespace and therefore a new ID.
33
+ */
34
+ const ID = Schema.String.pipe(Schema.brand("SandboxInstance.ID"), withStatics((schema) => ({
35
+ /**
36
+ * The host. Reserved, and never written to a column — see {@link toColumn}.
37
+ * It exists at runtime so nothing has to branch on "is this the host": it is
38
+ * what identity reads, what logs show, and what the transport cache keys on.
39
+ */
40
+ local: schema.make("local"),
41
+ /** A fresh identity for a namespace nothing has named yet. */
42
+ create: () => schema.make(`sbx_${uuidv7()}`)
43
+ })));
44
+ /**
45
+ * The storage boundary for namespace references, in one place.
46
+ *
47
+ * The host filesystem exists whether or not a row describes it, so it gets no
48
+ * row and `NULL` is the only spelling of it — the Unix analogue is exact, since
49
+ * `/` has no entry in the mount table you consult to find other mounts. That
50
+ * makes a session or directory writable before any namespace is registered (the
51
+ * foreign key is skipped on NULL), makes `SET sandbox_instance_id = NULL` a
52
+ * meaningful "revert to the host", and leaves the host impossible to tombstone,
53
+ * collect, or destroy, because there is nothing to point at.
54
+ *
55
+ * Two SQLite consequences ride on this and break correctness silently if missed:
56
+ * unique indexes treat NULLs as distinct, so every uniqueness constraint
57
+ * spanning a namespace column coalesces to `'local'`; and `= NULL` never
58
+ * matches, so namespace-scoped reads use `IS`.
59
+ */
60
+ const toColumn = (id) => id === ID.local ? null : id;
61
+ const fromColumn = (value) => value === null ? ID.local : ID.make(value);
62
+ /**
63
+ * The same mapping for row models, whose optional columns are `Option` rather
64
+ * than `null`. Kept beside {@link toColumn} so the boundary stays one place:
65
+ * `toColumn`/`fromColumn` for SQL parameters, these for `Model.FieldOption`.
66
+ */
67
+ const toField = (id) => id === ID.local ? Option.none() : Option.some(id);
68
+ const fromField = (value) => Option.getOrElse(value, () => ID.local);
69
+ /**
70
+ * Filesystem-class taxonomy, mirroring Unix: disk, tmpfs/procfs, NFS/CIFS.
71
+ * Stored on the row rather than derived from the registered driver, so reading
72
+ * an instance never depends on the registry — which matters most when a driver
73
+ * is *not* configured and you need to list or clean up its rows.
74
+ */
75
+ const Kind = Schema.Literals([
76
+ "local",
77
+ "virtual",
78
+ "remote"
79
+ ]);
80
+ const Ownership = Schema.Literals(["managed", "external"]);
81
+ /**
82
+ * Lifecycle state, in ZFS pool vocabulary. This is the **last observed** value,
83
+ * not live driver truth: Daytona auto-stops and auto-archives, Vercel sandboxes
84
+ * expire on their own timeout, so drift is normal. `stateObservedAt` carries the
85
+ * freshness and `Controller.refresh` updates it without waking anything.
86
+ *
87
+ * `removed` and `unavail` are deliberately distinct. `removed` means we deleted
88
+ * it; `unavail` means the driver claims it is gone. A "not found" is frequently a
89
+ * misclassification — wrong region, wrong API url, a revoked key answering 404,
90
+ * eventual consistency right after create — so it must never be recorded as if we
91
+ * had destroyed the resource ourselves.
92
+ */
93
+ const Status = Schema.Literals([
94
+ "provisioning",
95
+ "online",
96
+ "offline",
97
+ "suspending",
98
+ "removing",
99
+ "removed",
100
+ "unavail",
101
+ "faulted"
102
+ ]);
103
+ /**
104
+ * The statuses a `mount` may proceed from. This is the predicate every
105
+ * conditional write depends on, so it is enumerated once here rather than
106
+ * restated as prose at each call site.
107
+ *
108
+ * `offline` qualifies because mounting wakes.
109
+ * `faulted` qualifies because a fault is a *usability* condition, not an identity one — see {@link Status}.
110
+ *
111
+ * There is no `resuming`: it would exist to be observed by nothing, since
112
+ * mounting wakes, `offline` is already mountable, and waking is not destructive
113
+ * so it needs no claim. `suspending` and `removing` stay because they *are*
114
+ * compare-and-set claims, blocking a concurrent mount mid-destruction.
115
+ */
116
+ const mountable = /* @__PURE__ */ new Set([
117
+ "online",
118
+ "offline",
119
+ "faulted"
120
+ ]);
121
+ const isMountable = (status) => mountable.has(status);
122
+ /**
123
+ * Reference state, derived — never stored. `busy` carries its `umount` meaning:
124
+ * something holds this and destruction must not proceed unforced.
125
+ *
126
+ * `pinned` is the kernel sense of the word: never reclaimable. It short-circuits
127
+ * counting entirely for instances that cannot be stopped or destroyed (the local
128
+ * host), which is what keeps them out of any future collector by construction
129
+ * rather than by an ownership check happening to catch them.
130
+ */
131
+ const Usage = Schema.Literals([
132
+ "idle",
133
+ "busy",
134
+ "pinned"
135
+ ]);
136
+ /** Sanitized driver failure. The only error shape allowed to be persisted or logged. */
137
+ const PersistedError = Schema.Struct({
138
+ name: Schema.String,
139
+ message: Schema.String,
140
+ code: Schema.optional(Schema.String)
141
+ });
142
+ /** Coordinates for either reusing an instance or provisioning/registering one. */
143
+ const Selection = Schema.Union([Schema.Struct({ id: ID }), Schema.Struct({
144
+ driver: Schema.String,
145
+ providerResourceId: optional(Schema.String)
146
+ })]);
147
+ //#endregion
148
+ export { ID, Kind, Ownership, PersistedError, instance_exports as SandboxInstance, Selection, Status, Usage, fromColumn, fromField, isMountable, mountable, toColumn, toField };
149
+
150
+ //# sourceMappingURL=instance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.mjs","names":[],"sources":["../../../src/sandbox/instance.ts"],"sourcesContent":["import { Option, Schema } from \"effect\";\nimport { uuidv7 } from \"uuidv7\";\nimport { optional, withStatics } from \"../common.ts\";\nimport type { SandboxDriver } from \"./driver.ts\";\n\n/**\n * A Sandbox instance is a **durable filesystem namespace** plus whatever compute\n * acts on it — a device in Unix terms, which exists whether or not anything has\n * it mounted. `Sandbox.Controller` is the only thing that creates,\n * stops, or destroys one; this module is just its identity and state model.\n *\n * The application ID is deliberately separate from the driver's own resource\n * locator: callers never parse a Vercel name or a Daytona ID, driver formats may\n * change, and a destroyed resource must stay identifiable in Project/Session\n * history. A missing resource is never recreated under an existing ID — a new\n * resource is a new namespace and therefore a new ID.\n */\n\nexport const ID = Schema.String.pipe(\n\tSchema.brand(\"SandboxInstance.ID\"),\n\twithStatics((schema) => ({\n\t\t/**\n\t\t * The host. Reserved, and never written to a column — see {@link toColumn}.\n\t\t * It exists at runtime so nothing has to branch on \"is this the host\": it is\n\t\t * what identity reads, what logs show, and what the transport cache keys on.\n\t\t */\n\t\tlocal: schema.make(\"local\"),\n\t\t/** A fresh identity for a namespace nothing has named yet. */\n\t\tcreate: () => schema.make(`sbx_${uuidv7()}`),\n\t})),\n);\nexport type ID = typeof ID.Type;\n\n/**\n * The storage boundary for namespace references, in one place.\n *\n * The host filesystem exists whether or not a row describes it, so it gets no\n * row and `NULL` is the only spelling of it — the Unix analogue is exact, since\n * `/` has no entry in the mount table you consult to find other mounts. That\n * makes a session or directory writable before any namespace is registered (the\n * foreign key is skipped on NULL), makes `SET sandbox_instance_id = NULL` a\n * meaningful \"revert to the host\", and leaves the host impossible to tombstone,\n * collect, or destroy, because there is nothing to point at.\n *\n * Two SQLite consequences ride on this and break correctness silently if missed:\n * unique indexes treat NULLs as distinct, so every uniqueness constraint\n * spanning a namespace column coalesces to `'local'`; and `= NULL` never\n * matches, so namespace-scoped reads use `IS`.\n */\nexport const toColumn = (id: ID): string | null => (id === ID.local ? null : id);\nexport const fromColumn = (value: string | null): ID => (value === null ? ID.local : ID.make(value));\n\n/**\n * The same mapping for row models, whose optional columns are `Option` rather\n * than `null`. Kept beside {@link toColumn} so the boundary stays one place:\n * `toColumn`/`fromColumn` for SQL parameters, these for `Model.FieldOption`.\n */\nexport const toField = (id: ID): Option.Option<ID> => (id === ID.local ? Option.none() : Option.some(id));\nexport const fromField = (value: Option.Option<ID>): ID => Option.getOrElse(value, () => ID.local);\n\n/**\n * Filesystem-class taxonomy, mirroring Unix: disk, tmpfs/procfs, NFS/CIFS.\n * Stored on the row rather than derived from the registered driver, so reading\n * an instance never depends on the registry — which matters most when a driver\n * is *not* configured and you need to list or clean up its rows.\n */\nexport const Kind = Schema.Literals([\"local\", \"virtual\", \"remote\"]);\nexport type Kind = typeof Kind.Type;\n\nexport const Ownership = Schema.Literals([\"managed\", \"external\"]);\nexport type Ownership = typeof Ownership.Type;\n\n/**\n * Lifecycle state, in ZFS pool vocabulary. This is the **last observed** value,\n * not live driver truth: Daytona auto-stops and auto-archives, Vercel sandboxes\n * expire on their own timeout, so drift is normal. `stateObservedAt` carries the\n * freshness and `Controller.refresh` updates it without waking anything.\n *\n * `removed` and `unavail` are deliberately distinct. `removed` means we deleted\n * it; `unavail` means the driver claims it is gone. A \"not found\" is frequently a\n * misclassification — wrong region, wrong API url, a revoked key answering 404,\n * eventual consistency right after create — so it must never be recorded as if we\n * had destroyed the resource ourselves.\n */\nexport const Status = Schema.Literals([\n\t\"provisioning\",\n\t\"online\",\n\t\"offline\",\n\t\"suspending\",\n\t\"removing\",\n\t\"removed\",\n\t\"unavail\",\n\t\"faulted\",\n]);\nexport type Status = typeof Status.Type;\n\n/**\n * The statuses a `mount` may proceed from. This is the predicate every\n * conditional write depends on, so it is enumerated once here rather than\n * restated as prose at each call site.\n *\n * `offline` qualifies because mounting wakes.\n * `faulted` qualifies because a fault is a *usability* condition, not an identity one — see {@link Status}.\n *\n * There is no `resuming`: it would exist to be observed by nothing, since\n * mounting wakes, `offline` is already mountable, and waking is not destructive\n * so it needs no claim. `suspending` and `removing` stay because they *are*\n * compare-and-set claims, blocking a concurrent mount mid-destruction.\n */\nexport const mountable: ReadonlySet<Status> = new Set<Status>([\"online\", \"offline\", \"faulted\"]);\n\nexport const isMountable = (status: Status): boolean => mountable.has(status);\n\n/**\n * Reference state, derived — never stored. `busy` carries its `umount` meaning:\n * something holds this and destruction must not proceed unforced.\n *\n * `pinned` is the kernel sense of the word: never reclaimable. It short-circuits\n * counting entirely for instances that cannot be stopped or destroyed (the local\n * host), which is what keeps them out of any future collector by construction\n * rather than by an ownership check happening to catch them.\n */\nexport const Usage = Schema.Literals([\"idle\", \"busy\", \"pinned\"]);\nexport type Usage = typeof Usage.Type;\n\n/** Sanitized driver failure. The only error shape allowed to be persisted or logged. */\nexport const PersistedError = Schema.Struct({\n\tname: Schema.String,\n\tmessage: Schema.String,\n\tcode: Schema.optional(Schema.String),\n});\nexport type PersistedError = typeof PersistedError.Type;\n\n/** Durable metadata, safe to return and persist. Assembled by the control plane. */\nexport interface Info {\n\treadonly id: ID;\n\treadonly driver: SandboxDriver.Name;\n\treadonly kind: Kind;\n\treadonly providerResourceId: Option.Option<string>;\n\treadonly ownership: Ownership;\n\treadonly status: Status;\n\treadonly usage: Usage;\n\t/** References held by *this* control plane. Process-local; see the transport cache. */\n\treadonly refCount: number;\n\treadonly providerStatus: Option.Option<string>;\n\treadonly metadata: Readonly<Record<string, string>>;\n\treadonly lastError: Option.Option<PersistedError>;\n\treadonly createdAt: Date;\n\treadonly updatedAt: Date;\n\treadonly stateObservedAt: Date;\n\treadonly lastMountedAt: Option.Option<Date>;\n\treadonly lastUnmountedAt: Option.Option<Date>;\n\treadonly lastUsedAt: Option.Option<Date>;\n\treadonly removedAt: Option.Option<Date>;\n}\n\n/** Coordinates for either reusing an instance or provisioning/registering one. */\nexport const Selection = Schema.Union([\n\tSchema.Struct({ id: ID }),\n\tSchema.Struct({ driver: Schema.String, providerResourceId: optional(Schema.String) }),\n]);\nexport type Selection = typeof Selection.Type;\n\nexport * as SandboxInstance from \"./instance.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa,KAAK,OAAO,OAAO,KAC/B,OAAO,MAAM,oBAAoB,GACjC,aAAa,YAAY;;;;;;CAMxB,OAAO,OAAO,KAAK,OAAO;;CAE1B,cAAc,OAAO,KAAK,OAAO,OAAO,GAAG;AAC5C,EAAE,CACH;;;;;;;;;;;;;;;;;AAmBA,MAAa,YAAY,OAA2B,OAAO,GAAG,QAAQ,OAAO;AAC7E,MAAa,cAAc,UAA8B,UAAU,OAAO,GAAG,QAAQ,GAAG,KAAK,KAAK;;;;;;AAOlG,MAAa,WAAW,OAA+B,OAAO,GAAG,QAAQ,OAAO,KAAK,IAAI,OAAO,KAAK,EAAE;AACvG,MAAa,aAAa,UAAiC,OAAO,UAAU,aAAa,GAAG,KAAK;;;;;;;AAQjG,MAAa,OAAO,OAAO,SAAS;CAAC;CAAS;CAAW;AAAQ,CAAC;AAGlE,MAAa,YAAY,OAAO,SAAS,CAAC,WAAW,UAAU,CAAC;;;;;;;;;;;;;AAehE,MAAa,SAAS,OAAO,SAAS;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;;;;;;AAgBD,MAAa,4BAAiC,IAAI,IAAY;CAAC;CAAU;CAAW;AAAS,CAAC;AAE9F,MAAa,eAAe,WAA4B,UAAU,IAAI,MAAM;;;;;;;;;;AAW5E,MAAa,QAAQ,OAAO,SAAS;CAAC;CAAQ;CAAQ;AAAQ,CAAC;;AAI/D,MAAa,iBAAiB,OAAO,OAAO;CAC3C,MAAM,OAAO;CACb,SAAS,OAAO;CAChB,MAAM,OAAO,SAAS,OAAO,MAAM;AACpC,CAAC;;AA2BD,MAAa,YAAY,OAAO,MAAM,CACrC,OAAO,OAAO,EAAE,IAAI,GAAG,CAAC,GACxB,OAAO,OAAO;CAAE,QAAQ,OAAO;CAAQ,oBAAoB,SAAS,OAAO,MAAM;AAAE,CAAC,CACrF,CAAC"}