@smthrs/plan 0.0.0-stage → 1.0.0-rc.13

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 (209) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/LICENSE +21 -0
  3. package/README.md +230 -2
  4. package/THIRD_PARTY_NOTICES.md +48 -0
  5. package/dist/cjs/CachePolicy.d.ts +131 -0
  6. package/dist/cjs/CachePolicy.d.ts.map +1 -0
  7. package/dist/cjs/CachePolicy.js +50 -0
  8. package/dist/cjs/CachePolicy.js.map +7 -0
  9. package/dist/cjs/Effects.d.ts +258 -0
  10. package/dist/cjs/Effects.d.ts.map +1 -0
  11. package/dist/cjs/Effects.js +76 -0
  12. package/dist/cjs/Effects.js.map +7 -0
  13. package/dist/cjs/FileSet.d.ts +366 -0
  14. package/dist/cjs/FileSet.d.ts.map +1 -0
  15. package/dist/cjs/FileSet.js +196 -0
  16. package/dist/cjs/FileSet.js.map +7 -0
  17. package/dist/cjs/GraphBuildError.d.ts +120 -0
  18. package/dist/cjs/GraphBuildError.d.ts.map +1 -0
  19. package/dist/cjs/GraphBuildError.js +71 -0
  20. package/dist/cjs/GraphBuildError.js.map +7 -0
  21. package/dist/cjs/KeyMaterial.d.ts +107 -0
  22. package/dist/cjs/KeyMaterial.d.ts.map +1 -0
  23. package/dist/cjs/KeyMaterial.js +64 -0
  24. package/dist/cjs/KeyMaterial.js.map +7 -0
  25. package/dist/cjs/Node.d.ts +685 -0
  26. package/dist/cjs/Node.d.ts.map +1 -0
  27. package/dist/cjs/Node.js +230 -0
  28. package/dist/cjs/Node.js.map +7 -0
  29. package/dist/cjs/Placement.d.ts +117 -0
  30. package/dist/cjs/Placement.d.ts.map +1 -0
  31. package/dist/cjs/Placement.js +46 -0
  32. package/dist/cjs/Placement.js.map +7 -0
  33. package/dist/cjs/Plan.d.ts +489 -0
  34. package/dist/cjs/Plan.d.ts.map +1 -0
  35. package/dist/cjs/Plan.js +511 -0
  36. package/dist/cjs/Plan.js.map +7 -0
  37. package/dist/cjs/PlanDiff.d.ts +77 -0
  38. package/dist/cjs/PlanDiff.d.ts.map +1 -0
  39. package/dist/cjs/PlanDiff.js +149 -0
  40. package/dist/cjs/PlanDiff.js.map +7 -0
  41. package/dist/cjs/Planned.d.ts +121 -0
  42. package/dist/cjs/Planned.d.ts.map +1 -0
  43. package/dist/cjs/Planned.js +72 -0
  44. package/dist/cjs/Planned.js.map +7 -0
  45. package/dist/cjs/Repetition.d.ts +31 -0
  46. package/dist/cjs/Repetition.d.ts.map +1 -0
  47. package/dist/cjs/Repetition.js +36 -0
  48. package/dist/cjs/Repetition.js.map +7 -0
  49. package/dist/cjs/Scheduling.d.ts +89 -0
  50. package/dist/cjs/Scheduling.d.ts.map +1 -0
  51. package/dist/cjs/Scheduling.js +76 -0
  52. package/dist/cjs/Scheduling.js.map +7 -0
  53. package/dist/cjs/StepKey.d.ts +354 -0
  54. package/dist/cjs/StepKey.d.ts.map +1 -0
  55. package/dist/cjs/StepKey.js +313 -0
  56. package/dist/cjs/StepKey.js.map +7 -0
  57. package/dist/cjs/index.d.ts +91 -0
  58. package/dist/cjs/index.d.ts.map +1 -0
  59. package/dist/cjs/index.js +59 -0
  60. package/dist/cjs/index.js.map +7 -0
  61. package/dist/cjs/internal/ConflictAnnotation.d.ts +59 -0
  62. package/dist/cjs/internal/ConflictAnnotation.d.ts.map +1 -0
  63. package/dist/cjs/internal/ConflictAnnotation.js +247 -0
  64. package/dist/cjs/internal/ConflictAnnotation.js.map +7 -0
  65. package/dist/cjs/internal/EffectCandidates.d.ts +19 -0
  66. package/dist/cjs/internal/EffectCandidates.d.ts.map +1 -0
  67. package/dist/cjs/internal/EffectCandidates.js +92 -0
  68. package/dist/cjs/internal/EffectCandidates.js.map +7 -0
  69. package/dist/cjs/internal/JsonMirror.d.ts +34 -0
  70. package/dist/cjs/internal/JsonMirror.d.ts.map +1 -0
  71. package/dist/cjs/internal/JsonMirror.js +195 -0
  72. package/dist/cjs/internal/JsonMirror.js.map +7 -0
  73. package/dist/cjs/internal/SchemaIdentity.d.ts +140 -0
  74. package/dist/cjs/internal/SchemaIdentity.d.ts.map +1 -0
  75. package/dist/cjs/internal/SchemaIdentity.js +718 -0
  76. package/dist/cjs/internal/SchemaIdentity.js.map +7 -0
  77. package/dist/cjs/internal/effects.d.ts +245 -0
  78. package/dist/cjs/internal/effects.d.ts.map +1 -0
  79. package/dist/cjs/internal/effects.js +290 -0
  80. package/dist/cjs/internal/effects.js.map +7 -0
  81. package/dist/cjs/internal/node.d.ts +526 -0
  82. package/dist/cjs/internal/node.d.ts.map +1 -0
  83. package/dist/cjs/internal/node.js +313 -0
  84. package/dist/cjs/internal/node.js.map +7 -0
  85. package/dist/cjs/package.json +1 -0
  86. package/dist/cjs/test/PlanFixtures.d.ts +127 -0
  87. package/dist/cjs/test/PlanFixtures.d.ts.map +1 -0
  88. package/dist/cjs/test/PlanFixtures.js +59 -0
  89. package/dist/cjs/test/PlanFixtures.js.map +7 -0
  90. package/dist/esm/CachePolicy.d.ts +131 -0
  91. package/dist/esm/CachePolicy.d.ts.map +1 -0
  92. package/dist/esm/CachePolicy.js +117 -0
  93. package/dist/esm/CachePolicy.js.map +1 -0
  94. package/dist/esm/Effects.d.ts +258 -0
  95. package/dist/esm/Effects.d.ts.map +1 -0
  96. package/dist/esm/Effects.js +178 -0
  97. package/dist/esm/Effects.js.map +1 -0
  98. package/dist/esm/FileSet.d.ts +366 -0
  99. package/dist/esm/FileSet.d.ts.map +1 -0
  100. package/dist/esm/FileSet.js +398 -0
  101. package/dist/esm/FileSet.js.map +1 -0
  102. package/dist/esm/GraphBuildError.d.ts +120 -0
  103. package/dist/esm/GraphBuildError.d.ts.map +1 -0
  104. package/dist/esm/GraphBuildError.js +145 -0
  105. package/dist/esm/GraphBuildError.js.map +1 -0
  106. package/dist/esm/KeyMaterial.d.ts +107 -0
  107. package/dist/esm/KeyMaterial.d.ts.map +1 -0
  108. package/dist/esm/KeyMaterial.js +92 -0
  109. package/dist/esm/KeyMaterial.js.map +1 -0
  110. package/dist/esm/Node.d.ts +685 -0
  111. package/dist/esm/Node.d.ts.map +1 -0
  112. package/dist/esm/Node.js +591 -0
  113. package/dist/esm/Node.js.map +1 -0
  114. package/dist/esm/Placement.d.ts +117 -0
  115. package/dist/esm/Placement.d.ts.map +1 -0
  116. package/dist/esm/Placement.js +65 -0
  117. package/dist/esm/Placement.js.map +1 -0
  118. package/dist/esm/Plan.d.ts +489 -0
  119. package/dist/esm/Plan.d.ts.map +1 -0
  120. package/dist/esm/Plan.js +718 -0
  121. package/dist/esm/Plan.js.map +1 -0
  122. package/dist/esm/PlanDiff.d.ts +77 -0
  123. package/dist/esm/PlanDiff.d.ts.map +1 -0
  124. package/dist/esm/PlanDiff.js +205 -0
  125. package/dist/esm/PlanDiff.js.map +1 -0
  126. package/dist/esm/Planned.d.ts +121 -0
  127. package/dist/esm/Planned.d.ts.map +1 -0
  128. package/dist/esm/Planned.js +147 -0
  129. package/dist/esm/Planned.js.map +1 -0
  130. package/dist/esm/Repetition.d.ts +31 -0
  131. package/dist/esm/Repetition.d.ts.map +1 -0
  132. package/dist/esm/Repetition.js +24 -0
  133. package/dist/esm/Repetition.js.map +1 -0
  134. package/dist/esm/Scheduling.d.ts +89 -0
  135. package/dist/esm/Scheduling.d.ts.map +1 -0
  136. package/dist/esm/Scheduling.js +82 -0
  137. package/dist/esm/Scheduling.js.map +1 -0
  138. package/dist/esm/StepKey.d.ts +354 -0
  139. package/dist/esm/StepKey.d.ts.map +1 -0
  140. package/dist/esm/StepKey.js +503 -0
  141. package/dist/esm/StepKey.js.map +1 -0
  142. package/dist/esm/index.d.ts +91 -0
  143. package/dist/esm/index.d.ts.map +1 -0
  144. package/dist/esm/index.js +91 -0
  145. package/dist/esm/index.js.map +1 -0
  146. package/dist/esm/internal/ConflictAnnotation.d.ts +59 -0
  147. package/dist/esm/internal/ConflictAnnotation.d.ts.map +1 -0
  148. package/dist/esm/internal/ConflictAnnotation.js +332 -0
  149. package/dist/esm/internal/ConflictAnnotation.js.map +1 -0
  150. package/dist/esm/internal/EffectCandidates.d.ts +19 -0
  151. package/dist/esm/internal/EffectCandidates.d.ts.map +1 -0
  152. package/dist/esm/internal/EffectCandidates.js +86 -0
  153. package/dist/esm/internal/EffectCandidates.js.map +1 -0
  154. package/dist/esm/internal/JsonMirror.d.ts +34 -0
  155. package/dist/esm/internal/JsonMirror.d.ts.map +1 -0
  156. package/dist/esm/internal/JsonMirror.js +204 -0
  157. package/dist/esm/internal/JsonMirror.js.map +1 -0
  158. package/dist/esm/internal/SchemaIdentity.d.ts +140 -0
  159. package/dist/esm/internal/SchemaIdentity.d.ts.map +1 -0
  160. package/dist/esm/internal/SchemaIdentity.js +1002 -0
  161. package/dist/esm/internal/SchemaIdentity.js.map +1 -0
  162. package/dist/esm/internal/effects.d.ts +245 -0
  163. package/dist/esm/internal/effects.d.ts.map +1 -0
  164. package/dist/esm/internal/effects.js +459 -0
  165. package/dist/esm/internal/effects.js.map +1 -0
  166. package/dist/esm/internal/node.d.ts +526 -0
  167. package/dist/esm/internal/node.d.ts.map +1 -0
  168. package/dist/esm/internal/node.js +565 -0
  169. package/dist/esm/internal/node.js.map +1 -0
  170. package/dist/esm/test/PlanFixtures.d.ts +127 -0
  171. package/dist/esm/test/PlanFixtures.d.ts.map +1 -0
  172. package/dist/esm/test/PlanFixtures.js +60 -0
  173. package/dist/esm/test/PlanFixtures.js.map +1 -0
  174. package/docs/README.md +167 -0
  175. package/docs/api.md +1485 -0
  176. package/docs/concepts/authoring-ast.md +204 -0
  177. package/docs/concepts/effects-and-conflicts.md +135 -0
  178. package/docs/concepts/plan-value.md +168 -0
  179. package/docs/concepts/step-keys.md +179 -0
  180. package/docs/guides/author-a-node-graph.md +182 -0
  181. package/docs/guides/compile-a-plan.md +146 -0
  182. package/docs/guides/declare-file-effects.md +143 -0
  183. package/docs/guides/diff-two-plans.md +310 -0
  184. package/docs/installation.md +75 -0
  185. package/docs/quickstart.md +128 -0
  186. package/docs/testing.md +73 -0
  187. package/docs/troubleshooting.md +314 -0
  188. package/package.json +255 -3
  189. package/src/CachePolicy.ts +143 -0
  190. package/src/Effects.ts +302 -0
  191. package/src/FileSet.ts +493 -0
  192. package/src/GraphBuildError.ts +156 -0
  193. package/src/KeyMaterial.ts +111 -0
  194. package/src/Node.ts +974 -0
  195. package/src/Placement.ts +99 -0
  196. package/src/Plan.ts +911 -0
  197. package/src/PlanDiff.ts +244 -0
  198. package/src/Planned.ts +208 -0
  199. package/src/Repetition.ts +33 -0
  200. package/src/Scheduling.ts +154 -0
  201. package/src/StepKey.ts +736 -0
  202. package/src/index.ts +103 -0
  203. package/src/internal/ConflictAnnotation.ts +374 -0
  204. package/src/internal/EffectCandidates.ts +89 -0
  205. package/src/internal/JsonMirror.ts +255 -0
  206. package/src/internal/SchemaIdentity.ts +1096 -0
  207. package/src/internal/effects.ts +543 -0
  208. package/src/internal/node.ts +859 -0
  209. package/src/test/PlanFixtures.ts +76 -0
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var StepKey_exports = {};
30
+ __export(StepKey_exports, {
31
+ EnvironmentIdentity: () => EnvironmentIdentity,
32
+ KeyMaterialError: () => KeyMaterialError,
33
+ content: () => content,
34
+ digestInput: () => digestInput,
35
+ dispatchIdentity: () => dispatchIdentity,
36
+ environmentIdentity: () => environmentIdentity,
37
+ fromKeyMaterial: () => fromKeyMaterial,
38
+ isDigestInput: () => isDigestInput,
39
+ makeDigestMemo: () => makeDigestMemo,
40
+ ordinal: () => ordinal,
41
+ planIdentity: () => planIdentity,
42
+ project: () => project
43
+ });
44
+ module.exports = __toCommonJS(StepKey_exports);
45
+ var import_keys = require("@smthrs/keys");
46
+ var Cause = __toESM(require("effect/Cause"), 1);
47
+ var Deferred = __toESM(require("effect/Deferred"), 1);
48
+ var Effect = __toESM(require("effect/Effect"), 1);
49
+ var Exit = __toESM(require("effect/Exit"), 1);
50
+ var Schema = __toESM(require("effect/Schema"), 1);
51
+ const DigestInputTypeId = /* @__PURE__ */ Symbol.for("@smthrs/plan/StepKey/DigestInput");
52
+ const digestInput = (digest, reference) => ({
53
+ [DigestInputTypeId]: DigestInputTypeId,
54
+ digest,
55
+ ...reference === void 0 ? {} : { reference: reference.reference },
56
+ ...reference?.path === void 0 ? {} : { path: reference.path }
57
+ });
58
+ const isDigestInput = (value) => typeof value === "object" && value !== null && DigestInputTypeId in value && value[DigestInputTypeId] === DigestInputTypeId;
59
+ const EnvironmentIdentity = Schema.Union([
60
+ Schema.Struct({
61
+ declared: Schema.Literal(true),
62
+ layers: Schema.Array(Schema.String),
63
+ capabilities: Schema.Record(Schema.String, Schema.Array(Schema.String)),
64
+ runScope: Schema.optionalKey(Schema.Undefined)
65
+ }),
66
+ Schema.Struct({
67
+ declared: Schema.Literal(false),
68
+ layers: Schema.Array(Schema.String),
69
+ capabilities: Schema.Record(Schema.String, Schema.Array(Schema.String)),
70
+ runScope: Schema.NonEmptyString
71
+ })
72
+ ]);
73
+ const makeDigestMemo = () => {
74
+ const entries = /* @__PURE__ */ new Map();
75
+ const digest = (from, path, compute) => Effect.uninterruptibleMask(
76
+ (restore) => Effect.suspend(() => {
77
+ const address = JSON.stringify([from, path]);
78
+ const existing = entries.get(address);
79
+ if (existing !== void 0) {
80
+ return restore(Effect.flatMap(Effect.exit(Deferred.await(existing)), (exit) => {
81
+ if (Exit.isSuccess(exit)) return Effect.succeed(exit.value);
82
+ return Cause.hasInterrupts(exit.cause) ? digest(from, path, compute) : Effect.failCause(exit.cause);
83
+ }));
84
+ }
85
+ const pending = Deferred.makeUnsafe();
86
+ entries.set(address, pending);
87
+ return restore(compute).pipe(
88
+ Effect.onExit(
89
+ (exit) => Effect.gen(function* () {
90
+ if (Exit.isFailure(exit) && entries.get(address) === pending) {
91
+ entries.delete(address);
92
+ }
93
+ yield* Deferred.done(pending, exit);
94
+ })
95
+ )
96
+ );
97
+ })
98
+ );
99
+ return { digest };
100
+ };
101
+ class KeyMaterialError extends Schema.TaggedError()("@smthrs/plan/KeyMaterialError", {
102
+ code: Schema.Literals(["invalid_environment", "missing_dependency", "non_content_material"]),
103
+ message: Schema.String
104
+ }) {
105
+ }
106
+ const validateEnvironment = (environment) => {
107
+ const candidate = environment;
108
+ if (candidate.declared === false) {
109
+ if (typeof candidate.runScope !== "string" || candidate.runScope.length === 0) {
110
+ return new KeyMaterialError({
111
+ code: "invalid_environment",
112
+ message: "Undeclared environment identity requires a non-empty runScope"
113
+ });
114
+ }
115
+ return void 0;
116
+ }
117
+ if (candidate.declared === true) {
118
+ return candidate.runScope === void 0 ? void 0 : new KeyMaterialError({
119
+ code: "invalid_environment",
120
+ message: "Declared environment identity must not include runScope"
121
+ });
122
+ }
123
+ return new KeyMaterialError({
124
+ code: "invalid_environment",
125
+ message: "Environment identity requires a boolean declared field"
126
+ });
127
+ };
128
+ const decodeEnvironment = (environment) => Effect.try({
129
+ try: () => {
130
+ const invalid = validateEnvironment(environment);
131
+ if (invalid !== void 0) throw invalid;
132
+ return Schema.decodeUnknownSync(EnvironmentIdentity)(environment, { onExcessProperty: "error" });
133
+ },
134
+ catch: (cause) => cause instanceof KeyMaterialError ? cause : new KeyMaterialError({
135
+ code: "invalid_environment",
136
+ message: "Environment identity must contain only its declared fields, string layers, and string capability patterns"
137
+ })
138
+ });
139
+ const sortStrings = (values) => [...new Set(values.map((value) => value.normalize("NFC")))].sort();
140
+ const normalizeInputs = (inputs) => Object.fromEntries(
141
+ Object.entries(inputs).map(([name, value]) => [
142
+ name,
143
+ isDigestInput(value) ? {
144
+ kind: "digest",
145
+ digest: value.digest,
146
+ ...value.reference === void 0 ? {} : { reference: value.reference },
147
+ ...value.path === void 0 ? {} : { path: value.path }
148
+ } : { kind: "literal", value }
149
+ ])
150
+ );
151
+ const normalizeCapabilities = (capabilities) => Object.fromEntries(Object.entries(capabilities).map(([group, patterns]) => [group, sortStrings(patterns)]));
152
+ const normalizeEnvironment = (environment) => ({
153
+ declared: environment.declared,
154
+ layers: environment.layers.map((layer) => layer.normalize("NFC")),
155
+ capabilities: normalizeCapabilities(environment.capabilities),
156
+ ...environment.runScope === void 0 ? {} : { runScope: environment.runScope }
157
+ });
158
+ const compareCodeUnits = (left, right) => left < right ? -1 : 1;
159
+ const writeEntryKey = (entry) => typeof entry === "string" ? JSON.stringify(["Path", entry]) : entry._tag === "TreeArtifact" ? JSON.stringify([entry._tag, entry.path]) : JSON.stringify([entry._tag, entry.include, entry.exclude ?? null]);
160
+ const normalizeHermetic = (hermetic) => {
161
+ const readSet = [...hermetic.readSet].map((entry) => ({ path: entry.path.normalize("NFC"), digest: entry.digest })).sort((left, right) => {
162
+ if (left.path !== right.path) return left.path < right.path ? -1 : 1;
163
+ return left.digest < right.digest ? -1 : left.digest > right.digest ? 1 : 0;
164
+ }).filter(
165
+ (entry, index, entries) => index === 0 || entry.path !== entries[index - 1].path || entry.digest !== entries[index - 1].digest
166
+ );
167
+ const normalizedWrites = [...hermetic.writeSet].map((entry) => {
168
+ if (typeof entry === "string") return entry.normalize("NFC");
169
+ if (entry._tag === "TreeArtifact") return { ...entry, path: entry.path.normalize("NFC") };
170
+ return {
171
+ ...entry,
172
+ include: sortStrings(entry.include),
173
+ ...entry.exclude === void 0 ? {} : { exclude: sortStrings(entry.exclude) }
174
+ };
175
+ });
176
+ const writeSet = [...new Map(normalizedWrites.map((entry) => [writeEntryKey(entry), entry])).entries()].sort(([left], [right]) => compareCodeUnits(left, right)).map(([, entry]) => entry);
177
+ return {
178
+ readSet,
179
+ writeSet,
180
+ ...hermetic.removes === void 0 ? {} : { removes: sortStrings(hermetic.removes) },
181
+ boundaryMode: hermetic.boundaryMode
182
+ };
183
+ };
184
+ const decodeKey = Schema.decodeUnknownEffect(import_keys.DerivedKey);
185
+ const environmentIdentity = (environment) => Effect.gen(function* () {
186
+ const captured = environment === void 0 ? void 0 : yield* decodeEnvironment(environment);
187
+ return yield* decodeKey({
188
+ kind: "execution-environment/v1",
189
+ environment: captured === void 0 ? null : normalizeEnvironment(captured)
190
+ });
191
+ });
192
+ const content = (identity) => Effect.gen(function* () {
193
+ const environment = identity.environment === void 0 ? void 0 : yield* decodeEnvironment(identity.environment);
194
+ return yield* decodeKey({
195
+ kind: "content",
196
+ body: identity.body,
197
+ inputs: normalizeInputs(identity.inputs),
198
+ layers: sortStrings(identity.layers),
199
+ capabilities: normalizeCapabilities(identity.capabilities),
200
+ ...environment === void 0 ? {} : { environment: normalizeEnvironment(environment) },
201
+ ...identity.hermetic === void 0 ? {} : { hermetic: normalizeHermetic(identity.hermetic) }
202
+ });
203
+ });
204
+ const ordinal = (identity) => decodeKey({ kind: "ordinal", ...identity });
205
+ const fromKeyMaterial = (material, dependencyDigests) => {
206
+ if (material.kind !== "sealed") {
207
+ return Effect.fail(
208
+ new KeyMaterialError({
209
+ code: "non_content_material",
210
+ message: `Cannot create a content key for ${material.kind} material`
211
+ })
212
+ );
213
+ }
214
+ return materialIdentity(material, dependencyDigests).pipe(Effect.flatMap(content));
215
+ };
216
+ const planIdentity = (material, dependencyDigests) => material.kind === "sealed" ? fromKeyMaterial(material, dependencyDigests) : materialIdentity(material, dependencyDigests).pipe(Effect.flatMap(
217
+ (identity) => decodeKey({
218
+ kind: "plan-declaration",
219
+ tier: material.kind,
220
+ body: identity.body,
221
+ inputs: normalizeInputs(identity.inputs),
222
+ layers: sortStrings(identity.layers),
223
+ capabilities: normalizeCapabilities(identity.capabilities)
224
+ })
225
+ ));
226
+ const ownDataProperty = (record, from, label) => {
227
+ const descriptor = Object.getOwnPropertyDescriptor(record, from);
228
+ if (descriptor === void 0) {
229
+ return Effect.fail(
230
+ new KeyMaterialError({
231
+ code: "missing_dependency",
232
+ message: `Missing ${label.toLowerCase()} for graph dependency ${from}`
233
+ })
234
+ );
235
+ }
236
+ if (!("value" in descriptor)) {
237
+ return Effect.fail(
238
+ new KeyMaterialError({
239
+ code: "missing_dependency",
240
+ message: `${label} for graph dependency ${from} must be a data property`
241
+ })
242
+ );
243
+ }
244
+ return Effect.succeed(descriptor.value);
245
+ };
246
+ const resolveInputs = (material, resolve) => Effect.gen(function* () {
247
+ const inputs = {};
248
+ for (let index = 0; index < material.inputs.length; index++) {
249
+ const input = material.inputs[index];
250
+ if (input._tag === "Literal") {
251
+ inputs[String(index)] = input.value;
252
+ continue;
253
+ }
254
+ const digest = yield* resolve(input);
255
+ inputs[String(index)] = input._tag === "Pending" ? digestInput(digest, { reference: "pending" }) : input.path.length > 0 ? digestInput(digest, { reference: "ref-projected", path: input.path }) : digestInput(digest, { reference: "ref" });
256
+ }
257
+ return inputs;
258
+ });
259
+ const materialIdentity = (material, dependencyDigests) => resolveInputs(
260
+ material,
261
+ (reference) => Effect.flatMap(ownDataProperty(dependencyDigests, reference.from, "Digest"), (digest) => typeof digest === "string" ? Effect.succeed(digest) : Effect.fail(
262
+ new KeyMaterialError({
263
+ code: "missing_dependency",
264
+ message: `Digest for graph dependency ${reference.from} must be a string`
265
+ })
266
+ ))
267
+ ).pipe(Effect.map((inputs) => ({
268
+ body: materialBody(material),
269
+ inputs,
270
+ layers: material.layers,
271
+ capabilities: { declared: material.capabilities }
272
+ })));
273
+ const materialBody = (material) => ({
274
+ version: material.version,
275
+ declaration: material.body,
276
+ ...material.nondeterministic === void 0 ? {} : { nondeterministic: material.nondeterministic },
277
+ ...material.effects === void 0 ? {} : { effects: material.effects },
278
+ ...material.placement === void 0 ? {} : { placement: material.placement }
279
+ });
280
+ const orderingOnly = "ordering-only";
281
+ const project = (value, path) => {
282
+ let current = value;
283
+ for (const segment of path) {
284
+ if (typeof current !== "object" || current === null) return void 0;
285
+ const descriptor = Object.getOwnPropertyDescriptor(current, segment);
286
+ if (descriptor === void 0 || !("value" in descriptor)) return void 0;
287
+ current = descriptor.value;
288
+ }
289
+ return current;
290
+ };
291
+ const dispatchIdentity = (options) => Effect.gen(function* () {
292
+ const material = options.material;
293
+ if (material.kind !== "sealed") {
294
+ return yield* new KeyMaterialError({
295
+ code: "non_content_material",
296
+ message: `Cannot create a dispatch key for ${material.kind} material`
297
+ });
298
+ }
299
+ const environment = options.environment === void 0 ? void 0 : yield* decodeEnvironment(options.environment);
300
+ const inputs = yield* resolveInputs(material, (reference) => reference._tag === "Pending" ? Effect.succeed(orderingOnly) : Effect.flatMap(ownDataProperty(options.results, reference.from, "Settled result"), (settled) => {
301
+ const compute = decodeKey({ kind: "input-value", value: project(settled, reference.path) });
302
+ return options.digestMemo === void 0 ? compute : options.digestMemo.digest(reference.from, reference.path, compute);
303
+ }));
304
+ return yield* content({
305
+ body: materialBody(material),
306
+ inputs,
307
+ layers: material.layers,
308
+ capabilities: { declared: material.capabilities },
309
+ environment,
310
+ hermetic: options.hermetic
311
+ });
312
+ });
313
+ //# sourceMappingURL=StepKey.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/StepKey.ts"],
4
+ "sourcesContent": ["/**\n * The KeyMaterial \u2192 step-key compiler.\n *\n * Revived from the deleted `packages/smithers/flows/keys/src/StepKey.ts`. Two\n * deliberate deviations from the original:\n *\n * 1. **It lives here, not in `@smthrs/keys`.** That package owns generic\n * derivation and stored-key validation; a compiler that understands plan\n * material belongs above it.\n * 2. **It produces `@smthrs/keys` `StoredKey` values, not a second `sk1_` digest\n * format.** The original minted its own prefix over a private `Digest`\n * module. The engine dispatches under `StoredKey` (`FlowEngine/ActionKey.ts`),\n * so a plan whose node keys were a *different* string format could never be\n * the thing the cache is consulted against, and that is the whole point of\n * a `Plan`. One key format, one hashing\n * chokepoint (canonical JSON + injected `Crypto`), one namespace field\n * (`kind`) distinguishing content keys from ordinal ones.\n *\n * Everything the original earned is kept: nominally branded digest inputs (a\n * literal that merely *looks* like `{digest}` hashes as a literal), set\n * normalization, the separate environment namespace, per-variant tagging of\n * resolved references, and the hashed `version`.\n *\n * Governing contract: the step-key rules at\n * https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/plan/docs/concepts/step-keys.md.\n *\n * @since 0.1.0\n */\n\nimport { DerivedKey, type StoredKey } from \"@smthrs/keys\"\nimport * as Cause from \"effect/Cause\"\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Deferred from \"effect/Deferred\"\nimport * as Effect from \"effect/Effect\"\nimport * as Exit from \"effect/Exit\"\nimport * as Schema from \"effect/Schema\"\nimport type * as FileSet from \"./FileSet.ts\"\nimport type * as KeyMaterial from \"./KeyMaterial.ts\"\n\n/**\n * A computed step key. Identical in representation to any other flow key \u2014\n * `key1_` plus a SHA-256 digest of the canonical serialization of the material.\n *\n * @since 0.1.0\n * @category models\n */\nexport type StepKey = StoredKey\n\n/**\n * The nominal brand carried by every {@link DigestInput}. Kept private: the\n * only way to produce a value bearing it is {@link digestInput}, so a plain\n * value that merely happens to look like `{ digest: \"...\" }` \u2014 actions pass\n * content hashes around as ordinary data \u2014 can never be mistaken for a genuine\n * upstream-result digest reference. This closes a step-key collision where\n * shape-sniffing (`\"digest\" in value`) hashed the two identically.\n *\n * @since 0.1.0\n * @category symbols\n */\nconst DigestInputTypeId: unique symbol = Symbol.for(\"@smthrs/plan/StepKey/DigestInput\")\n\n/**\n * Which kind of graph reference a {@link DigestInput} stands for. Declared\n * once here so the field on `DigestInput` and the parameter of\n * {@link digestInput} name one set and cannot drift apart.\n */\ntype GraphReference = \"ref\" | \"pending\" | \"ref-projected\"\n\n/**\n * A precomputed digest supplied as a step input rather than a literal value.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface DigestInput {\n readonly [DigestInputTypeId]: typeof DigestInputTypeId\n readonly digest: string\n /**\n * Which kind of graph reference resolved to this digest.\n *\n * Carrying the discriminator on the digest input keeps `normalizeInputs` the\n * single normalizer: it wraps every variant once, and the variants stay\n * mutually distinct because they differ in this field rather than in a\n * hand-built object a second wrap would hide.\n */\n readonly reference?: GraphReference\n /** The projection applied to the referenced result, for `ref-projected`. */\n readonly path?: ReadonlyArray<string>\n}\n\n/**\n * Nominally tags a precomputed digest so it is hashed as a digest reference\n * rather than a literal value.\n *\n * @param digest - The precomputed digest.\n * @param reference - Which graph reference resolved to the digest, and the\n * projection path for `ref-projected`. Omit for a plain digest.\n * @returns The tagged digest input.\n * @since 0.1.0\n * @category constructors\n */\nexport const digestInput = (\n digest: string,\n reference?: {\n readonly reference: GraphReference\n readonly path?: ReadonlyArray<string>\n }\n): DigestInput => ({\n [DigestInputTypeId]: DigestInputTypeId,\n digest,\n ...(reference === undefined ? {} : { reference: reference.reference }),\n ...(reference?.path === undefined ? {} : { path: reference.path })\n})\n\n/**\n * Type guard for values produced by {@link digestInput}. A plain object\n * shaped like `{ digest: \"...\" }` is not one.\n *\n * @param value - Any value.\n * @returns `true` only for a value carrying the private digest-input brand.\n * @since 0.1.0\n * @category guards\n */\nexport const isDigestInput = (value: unknown): value is DigestInput =>\n typeof value === \"object\" && value !== null && DigestInputTypeId in value &&\n (value as Record<PropertyKey, unknown>)[DigestInputTypeId] === DigestInputTypeId\n\n/**\n * The engine-resolved execution environment a content key is computed under,\n * hashed in its OWN namespace rather than merged into the caller's `layers`\n * and `capabilities`.\n *\n * Three properties matter and none survives a merge:\n *\n * 1. **Non-aliasing.** Concatenating environment material onto the caller's\n * made `caller{fs:[\"a\"]} + env{fs:[\"b\"]}` hash identically to\n * `caller{fs:[\"a\",\"b\"]} + env{}` \u2014 a cross-run collision in the very\n * material whose purpose is preventing one.\n * 2. **Declared vs undeclared.** `declared: false` is not the same value as\n * `declared: true` with empty sets.\n * 3. **Composition order.** Environment layers retain declaration order,\n * because plugin and service composition order can change behavior. The\n * caller-owned `ContentIdentity.layers` stays set-normalized.\n *\n * `runScope` is set only when `declared` is `false`: it pins the key to one\n * run, so a step whose environment identity is unknown can never serve a\n * cross-run hit. The union enforces this for typed callers; both\n * {@link content} and {@link dispatchIdentity} validate it at run time.\n *\n * @since 0.1.0\n * @category models\n */\nexport type EnvironmentIdentity = typeof EnvironmentIdentity.Type\n\n/**\n * Validated, copyable runtime environment identity. Layer order matters;\n * capability patterns are set-like. Unknown fields are not identity material.\n * @since 1.0.0\n * @category schemas\n */\nexport const EnvironmentIdentity = Schema.Union([\n Schema.Struct({\n declared: Schema.Literal(true),\n layers: Schema.Array(Schema.String),\n capabilities: Schema.Record(Schema.String, Schema.Array(Schema.String)),\n runScope: Schema.optionalKey(Schema.Undefined)\n }),\n Schema.Struct({\n declared: Schema.Literal(false),\n layers: Schema.Array(Schema.String),\n capabilities: Schema.Record(Schema.String, Schema.Array(Schema.String)),\n runScope: Schema.NonEmptyString\n })\n])\n\n/**\n * Caller-owned memoization context for projected dependency-value digests.\n *\n * This is the flows counterpart of Bazel's `ActionKeyContext`: one context is\n * passed through related key computations so shared input material is hashed\n * once. Concurrent requests for the same projection share the in-flight\n * digest. Entries are sound only while each settled `from` value is immutable;\n * callers must create a fresh memo when those values can change.\n *\n * `digest(from, path, compute)` runs `compute` once per address and shares its\n * result with concurrent callers. A failed or interrupted computation is not\n * kept: the next caller recomputes, and a waiter whose leader was interrupted\n * becomes the new leader instead of inheriting the interrupt.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface DigestMemo {\n readonly digest: (\n from: string,\n path: ReadonlyArray<string>,\n compute: Effect.Effect<StepKey, Schema.SchemaError, Crypto.Crypto>\n ) => Effect.Effect<StepKey, Schema.SchemaError, Crypto.Crypto>\n}\n\n/**\n * Creates an empty projected-value digest memo. Projection addresses are\n * JSON-encoded `[from, path]` tuples so segment boundaries are unambiguous.\n *\n * @returns A memo with no entries.\n * @since 0.1.0\n * @category constructors\n */\nexport const makeDigestMemo = (): DigestMemo => {\n const entries = new Map<string, Deferred.Deferred<StepKey, Schema.SchemaError>>()\n // Registering the entry and installing its exit handler run uninterruptibly,\n // so an interrupt can never land between them and strand a Deferred that no\n // fiber will complete. The wait and the computation stay interruptible.\n const digest: DigestMemo[\"digest\"] = (from, path, compute) =>\n Effect.uninterruptibleMask((restore) =>\n Effect.suspend(() => {\n const address = JSON.stringify([from, path])\n const existing = entries.get(address)\n if (existing !== undefined) {\n return restore(Effect.flatMap(Effect.exit(Deferred.await(existing)), (exit) => {\n if (Exit.isSuccess(exit)) return Effect.succeed(exit.value)\n // A waiter did not request the leader's cancellation. It competes to\n // become the replacement leader instead of inheriting that interrupt.\n return Cause.hasInterrupts(exit.cause) ? digest(from, path, compute) : Effect.failCause(exit.cause)\n }))\n }\n const pending = Deferred.makeUnsafe<StepKey, Schema.SchemaError>()\n entries.set(address, pending)\n return restore(compute).pipe(\n Effect.onExit((exit) =>\n Effect.gen(function*() {\n if (Exit.isFailure(exit) && entries.get(address) === pending) {\n entries.delete(address)\n }\n yield* Deferred.done(pending, exit)\n })\n )\n )\n })\n )\n return { digest }\n}\n\n/**\n * Material describing a sealed or hermetic content-addressed step.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface ContentIdentity {\n readonly body: unknown\n readonly inputs: Readonly<Record<string, unknown | DigestInput>>\n readonly layers: ReadonlyArray<string>\n readonly capabilities: Readonly<Record<string, ReadonlyArray<string>>>\n readonly environment?: EnvironmentIdentity | undefined\n readonly hermetic?: {\n readonly readSet: ReadonlyArray<{ readonly path: string; readonly digest: string }>\n readonly writeSet: ReadonlyArray<FileSet.Entry>\n readonly removes?: ReadonlyArray<string> | undefined\n readonly boundaryMode: FileSet.BoundaryMode\n } | undefined\n}\n\n/**\n * Material describing the run-local identity of a non-cacheable step.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface OrdinalIdentity {\n readonly runId: string\n readonly parentScope?: string | undefined\n readonly ordinal: number\n readonly tier: \"compensable\" | \"irreversible\" | \"unsealed\"\n}\n\n/**\n * Stable failures while deriving a key. `code` names the rule:\n *\n * - `invalid_environment`: an {@link EnvironmentIdentity} that is neither\n * declared nor run-scoped.\n * - `missing_dependency`: a `Ref` or `Pending` input names a node with no\n * recorded digest, or, at dispatch, a `Ref` names one with no settled\n * result.\n * - `non_content_material`: a content-key constructor received material whose\n * tier is not `sealed`.\n *\n * @since 0.1.0\n * @category errors\n */\nexport class KeyMaterialError extends Schema.TaggedError<KeyMaterialError>()(\"@smthrs/plan/KeyMaterialError\", {\n code: Schema.Literals([\"invalid_environment\", \"missing_dependency\", \"non_content_material\"]),\n message: Schema.String\n}) {}\n\nconst validateEnvironment = (environment: EnvironmentIdentity): KeyMaterialError | undefined => {\n const candidate = environment as { readonly declared?: unknown; readonly runScope?: unknown }\n if (candidate.declared === false) {\n if (typeof candidate.runScope !== \"string\" || candidate.runScope.length === 0) {\n return new KeyMaterialError({\n code: \"invalid_environment\",\n message: \"Undeclared environment identity requires a non-empty runScope\"\n })\n }\n return undefined\n }\n if (candidate.declared === true) {\n return candidate.runScope === undefined\n ? undefined\n : new KeyMaterialError({\n code: \"invalid_environment\",\n message: \"Declared environment identity must not include runScope\"\n })\n }\n return new KeyMaterialError({\n code: \"invalid_environment\",\n message: \"Environment identity requires a boolean declared field\"\n })\n}\n\nconst decodeEnvironment = (environment: EnvironmentIdentity) =>\n Effect.try({\n try: () => {\n const invalid = validateEnvironment(environment)\n if (invalid !== undefined) throw invalid\n return Schema.decodeUnknownSync(EnvironmentIdentity)(environment, { onExcessProperty: \"error\" })\n },\n catch: (cause) =>\n cause instanceof KeyMaterialError ? cause : new KeyMaterialError({\n code: \"invalid_environment\",\n message:\n \"Environment identity must contain only its declared fields, string layers, and string capability patterns\"\n })\n })\n\nconst sortStrings = (values: ReadonlyArray<string>): Array<string> =>\n [...new Set(values.map((value) => value.normalize(\"NFC\")))].sort()\n\nconst normalizeInputs = (inputs: ContentIdentity[\"inputs\"]): Record<string, unknown> =>\n Object.fromEntries(\n Object.entries(inputs).map(([name, value]) => [\n name,\n isDigestInput(value)\n ? {\n kind: \"digest\",\n digest: value.digest,\n ...(value.reference === undefined ? {} : { reference: value.reference }),\n ...(value.path === undefined ? {} : { path: value.path })\n }\n : { kind: \"literal\", value }\n ])\n )\n\nconst normalizeCapabilities = (capabilities: ContentIdentity[\"capabilities\"]): Record<string, Array<string>> =>\n Object.fromEntries(Object.entries(capabilities).map(([group, patterns]) => [group, sortStrings(patterns)]))\n\nconst normalizeEnvironment = (environment: EnvironmentIdentity) => ({\n declared: environment.declared,\n layers: environment.layers.map((layer) => layer.normalize(\"NFC\")),\n capabilities: normalizeCapabilities(environment.capabilities),\n ...(environment.runScope === undefined ? {} : { runScope: environment.runScope })\n})\n\nconst compareCodeUnits = (left: string, right: string): number => left < right ? -1 : 1\n\ntype NormalizedWriteEntry =\n | string\n | { readonly _tag: \"TreeArtifact\"; readonly path: string }\n | {\n readonly _tag: \"Glob\"\n readonly include: ReadonlyArray<string>\n readonly exclude?: ReadonlyArray<string> | undefined\n }\n\nconst writeEntryKey = (entry: NormalizedWriteEntry): string =>\n typeof entry === \"string\"\n ? JSON.stringify([\"Path\", entry])\n : entry._tag === \"TreeArtifact\"\n ? JSON.stringify([entry._tag, entry.path])\n : JSON.stringify([entry._tag, entry.include, entry.exclude ?? null])\n\nconst normalizeHermetic = (hermetic: NonNullable<ContentIdentity[\"hermetic\"]>) => {\n const readSet = [...hermetic.readSet]\n .map((entry) => ({ path: entry.path.normalize(\"NFC\"), digest: entry.digest }))\n .sort((left, right) => {\n if (left.path !== right.path) return left.path < right.path ? -1 : 1\n return left.digest < right.digest ? -1 : left.digest > right.digest ? 1 : 0\n })\n .filter((entry, index, entries) =>\n index === 0 || entry.path !== entries[index - 1]!.path || entry.digest !== entries[index - 1]!.digest\n )\n const normalizedWrites = [...hermetic.writeSet].map((entry) => {\n if (typeof entry === \"string\") return entry.normalize(\"NFC\")\n if (entry._tag === \"TreeArtifact\") return { ...entry, path: entry.path.normalize(\"NFC\") }\n return {\n ...entry,\n include: sortStrings(entry.include),\n ...(entry.exclude === undefined ? {} : { exclude: sortStrings(entry.exclude) })\n }\n })\n const writeSet = [...new Map(normalizedWrites.map((entry) => [writeEntryKey(entry), entry])).entries()]\n .sort(([left], [right]) => compareCodeUnits(left, right))\n .map(([, entry]) => entry)\n return {\n readSet,\n writeSet,\n ...(hermetic.removes === undefined ? {} : { removes: sortStrings(hermetic.removes) }),\n boundaryMode: hermetic.boundaryMode\n }\n}\n\nconst decodeKey = Schema.decodeUnknownEffect(DerivedKey)\n\n/**\n * Fingerprint for binding one execution to its runtime environment, not an\n * action dispatch key. Uses the same normalization as content/dispatch keys.\n * An omitted environment is distinct from declared-empty and run-scoped ones.\n * @since 1.0.0\n * @category constructors\n */\nexport const environmentIdentity = (\n environment?: EnvironmentIdentity\n): Effect.Effect<StoredKey, KeyMaterialError | Schema.SchemaError, Crypto.Crypto> =>\n Effect.gen(function*() {\n const captured = environment === undefined ? undefined : yield* decodeEnvironment(environment)\n return yield* decodeKey({\n kind: \"execution-environment/v1\",\n environment: captured === undefined ? null : normalizeEnvironment(captured)\n })\n })\n\n/**\n * Produces a cross-run reusable key for a sealed or hermetic step. Set-like\n * declarations are normalized before serialization; write declarations remain\n * part of the identity even when the step writes nothing.\n *\n * @param identity - The step's content material.\n * @returns The content key. Fails with `invalid_environment` for a malformed\n * environment, or `SchemaError` when the material cannot be serialized.\n * @since 0.1.0\n * @category constructors\n */\nexport const content = (\n identity: ContentIdentity\n): Effect.Effect<StepKey, KeyMaterialError | Schema.SchemaError, Crypto.Crypto> =>\n Effect.gen(function*() {\n const environment = identity.environment === undefined ? undefined : yield* decodeEnvironment(identity.environment)\n return yield* decodeKey({\n kind: \"content\",\n body: identity.body,\n inputs: normalizeInputs(identity.inputs),\n layers: sortStrings(identity.layers),\n capabilities: normalizeCapabilities(identity.capabilities),\n ...(environment === undefined ? {} : { environment: normalizeEnvironment(environment) }),\n ...(identity.hermetic === undefined ? {} : { hermetic: normalizeHermetic(identity.hermetic) })\n })\n })\n\n/**\n * Produces a run-local ordinal key for compensable, irreversible, or unsealed\n * work. These keys intentionally cannot be reused across runs.\n *\n * @param identity - The run id, optional parent scope, ordinal, and tier.\n * @returns The ordinal key.\n * @since 0.1.0\n * @category constructors\n */\nexport const ordinal = (\n identity: OrdinalIdentity\n): Effect.Effect<StepKey, Schema.SchemaError, Crypto.Crypto> => decodeKey({ kind: \"ordinal\", ...identity })\n\n/**\n * Resolves graph-local references to dependency digests and constructs a\n * sealed content key. Use {@link planIdentity} to compile any effect tier.\n *\n * This is the handoff the Flow Builder Brief describes: the planner hands over\n * a topologically ordered sequence of `{ nodeId, material }`, and for each one\n * the compiler substitutes every `Ref`/`Pending` with the *already computed\n * key of the referenced node*. Structural node ids are lookup addresses only\n * and never enter the hashed value \u2014 rename a node and nothing re-keys; change\n * what a node consumes and everything downstream of it does.\n *\n * @param material - The node's key material; its tier must be `sealed`.\n * @param dependencyDigests - The key of every node the material references,\n * by node id.\n * @returns The content key. Fails with `non_content_material` for a\n * non-sealed tier and `missing_dependency` for an unresolved reference.\n * @since 0.1.0\n * @category constructors\n */\nexport const fromKeyMaterial = (\n material: KeyMaterial.KeyMaterial,\n dependencyDigests: Readonly<Record<string, string>>\n): Effect.Effect<StepKey, KeyMaterialError | Schema.SchemaError, Crypto.Crypto> => {\n if (material.kind !== \"sealed\") {\n return Effect.fail(\n new KeyMaterialError({\n code: \"non_content_material\",\n message: `Cannot create a content key for ${material.kind} material`\n })\n )\n }\n return materialIdentity(material, dependencyDigests).pipe(Effect.flatMap(content))\n}\n\n/**\n * Identifies a declaration in a plan, independently of whether its execution\n * can be cached. Sealed material retains its existing content-key format;\n * compensable and irreversible material use a distinct, tier-bearing plan\n * namespace. These fingerprints bind approvals, not cross-run result reuse.\n * Dispatch non-cacheable work under a run-local {@link ordinal} instead.\n *\n * @since 1.0.0\n * @category constructors\n */\nexport const planIdentity = (\n material: KeyMaterial.KeyMaterial,\n dependencyDigests: Readonly<Record<string, string>>\n): Effect.Effect<StepKey, KeyMaterialError | Schema.SchemaError, Crypto.Crypto> =>\n material.kind === \"sealed\" ?\n fromKeyMaterial(material, dependencyDigests) :\n materialIdentity(material, dependencyDigests).pipe(Effect.flatMap((identity) =>\n decodeKey({\n kind: \"plan-declaration\",\n tier: material.kind,\n body: identity.body,\n inputs: normalizeInputs(identity.inputs),\n layers: sortStrings(identity.layers),\n capabilities: normalizeCapabilities(identity.capabilities)\n })\n ))\n\n/**\n * Reads the entry a graph reference names. Only an own data property counts:\n * an absent name or an accessor is a missing dependency, and no getter runs.\n * `label` names what the record holds, as each refusal says it.\n *\n * @private\n */\nconst ownDataProperty = (\n record: Readonly<Record<string, unknown>>,\n from: string,\n label: \"Digest\" | \"Settled result\"\n): Effect.Effect<unknown, KeyMaterialError> => {\n const descriptor = Object.getOwnPropertyDescriptor(record, from)\n if (descriptor === undefined) {\n return Effect.fail(\n new KeyMaterialError({\n code: \"missing_dependency\",\n message: `Missing ${label.toLowerCase()} for graph dependency ${from}`\n })\n )\n }\n if (!(\"value\" in descriptor)) {\n return Effect.fail(\n new KeyMaterialError({\n code: \"missing_dependency\",\n message: `${label} for graph dependency ${from} must be a data property`\n })\n )\n }\n return Effect.succeed(descriptor.value)\n}\n\n/**\n * The positional inputs both identities hash. A `Literal` contributes its raw\n * value, so `normalizeInputs` applies the one literal wrap; `resolve` supplies\n * the digest for each `Ref` and `Pending`, tagged with the reference variant.\n *\n * @private\n */\nconst resolveInputs = <E, R>(\n material: KeyMaterial.KeyMaterial,\n resolve: (reference: Exclude<KeyMaterial.InputRef, { readonly _tag: \"Literal\" }>) => Effect.Effect<string, E, R>\n): Effect.Effect<Record<string, unknown>, E, R> =>\n Effect.gen(function*() {\n const inputs: Record<string, unknown> = {}\n for (let index = 0; index < material.inputs.length; index++) {\n const input = material.inputs[index]!\n if (input._tag === \"Literal\") {\n inputs[String(index)] = input.value\n continue\n }\n const digest = yield* resolve(input)\n inputs[String(index)] = input._tag === \"Pending\"\n ? digestInput(digest, { reference: \"pending\" })\n : input.path.length > 0\n ? digestInput(digest, { reference: \"ref-projected\", path: input.path })\n : digestInput(digest, { reference: \"ref\" })\n }\n return inputs\n })\n\n/** Resolves plan references once for both content and non-cacheable declarations. */\nconst materialIdentity = (\n material: KeyMaterial.KeyMaterial,\n dependencyDigests: Readonly<Record<string, string>>\n): Effect.Effect<ContentIdentity, KeyMaterialError> =>\n resolveInputs(\n material,\n (reference) =>\n Effect.flatMap(ownDataProperty(dependencyDigests, reference.from, \"Digest\"), (digest) =>\n typeof digest === \"string\" ? Effect.succeed(digest) : Effect.fail(\n new KeyMaterialError({\n code: \"missing_dependency\",\n message: `Digest for graph dependency ${reference.from} must be a string`\n })\n ))\n ).pipe(Effect.map((inputs) => ({\n body: materialBody(material),\n inputs,\n layers: material.layers,\n capabilities: { declared: material.capabilities }\n })))\n\n/**\n * The node's own declaration, hashed. Shared by {@link planIdentity},\n * {@link fromKeyMaterial}, and {@link dispatchIdentity} so derivations cannot drift about what\n * \"the node itself\" means.\n *\n * @private\n */\nconst materialBody = (material: KeyMaterial.KeyMaterial) => ({\n version: material.version,\n declaration: material.body,\n ...(material.nondeterministic === undefined ? {} : { nondeterministic: material.nondeterministic }),\n ...(material.effects === undefined ? {} : { effects: material.effects }),\n ...(material.placement === undefined ? {} : { placement: material.placement })\n})\n\n/**\n * The digest a `Pending` input contributes to a dispatch key. It is a\n * constant, and that is the point: `Pending` is an ordering reference, and\n * ordering does not change what a node consumes, so it must not change what\n * the node caches under. The string is self-describing, so a reader of a\n * hashed payload can see that no upstream value was folded.\n *\n * @private\n */\nconst orderingOnly = \"ordering-only\"\n\n/**\n * Projects a settled result along a `Ref` path. Only own data properties\n * resolve, so a missing, inherited, or accessor segment yields `undefined`\n * without invoking a getter. This is a stable, distinct value: a projection that\n * walks off the end of a result is a fact about the graph, not a failure.\n * `undefined` drops out of the canonical form, so it hashes distinctly from\n * every JSON value including `null`.\n *\n * Exported because it is the ONE projection semantics for the value channel:\n * {@link dispatchIdentity} digests what this returns, so every consumer that\n * resolves a `Ref` at execution time must resolve it the same way, or two\n * inputs that key identically could be consumed differently \u2014 a stale-hit\n * vector.\n *\n * @since 0.1.0\n * @category utilities\n */\nexport const project = (value: unknown, path: ReadonlyArray<string>): unknown => {\n let current = value\n for (const segment of path) {\n if (typeof current !== \"object\" || current === null) return undefined\n const descriptor = Object.getOwnPropertyDescriptor(current, segment)\n if (descriptor === undefined || !(\"value\" in descriptor)) return undefined\n current = descriptor.value\n }\n return current\n}\n\n/**\n * The key a dispatch is *cached* under, as distinct from the plan key a node\n * is *identified* by.\n *\n * A plan key folds the resolved keys of every upstream node, transitively, so\n * an edit anywhere upstream re-keys everything below it \u2014 even when the edited\n * node's output value is byte for byte what it was before. Bazel does not work\n * that way: `ActionCacheChecker` keys an action by the *content* of its\n * inputs, so an unchanged output stops invalidation dead. The file channel in\n * flows already had that property through the measured boundary digests; the\n * JSON value channel did not, and this is what gives it one.\n *\n * The derivation folds the node's OWN material \u2014 body, version, effects,\n * placement, layers, capabilities \u2014 and never an upstream key. Each material\n * input contributes content instead: a `Literal` its value, a `Ref` the digest\n * of the settled result of `from` projected along `path`, and a `Pending`\n * nothing beyond its tag. The measured hermetic boundary is folded unchanged.\n *\n * `results` must hold every dependency the material names. The scheduler's\n * halt rule guarantees it: a dependent of failed or skipped work never\n * dispatches, so a `Ref` always resolves against a success.\n *\n * @param options - The material, the dependencies' settled results, the\n * measured hermetic boundary, and an optional environment and memo.\n * @returns The dispatch key. Fails with `non_content_material` for a\n * non-sealed tier, `missing_dependency` for a `Ref` absent from `results`,\n * or `invalid_environment` for a malformed environment.\n * @since 0.1.0\n * @category constructors\n */\nexport const dispatchIdentity = (options: {\n readonly material: KeyMaterial.KeyMaterial\n /** The settled output value of each dependency, by node id. */\n readonly results: Readonly<Record<string, unknown>>\n readonly hermetic: NonNullable<ContentIdentity[\"hermetic\"]>\n /** The engine-resolved execution environment this dispatch runs under. */\n readonly environment?: EnvironmentIdentity | undefined\n /** Reuses projected-value digests while the corresponding settled values remain immutable. */\n readonly digestMemo?: DigestMemo | undefined\n}): Effect.Effect<StepKey, KeyMaterialError | Schema.SchemaError, Crypto.Crypto> =>\n Effect.gen(function*() {\n const material = options.material\n if (material.kind !== \"sealed\") {\n return yield* new KeyMaterialError({\n code: \"non_content_material\",\n message: `Cannot create a dispatch key for ${material.kind} material`\n })\n }\n const environment = options.environment === undefined ? undefined : yield* decodeEnvironment(options.environment)\n const inputs = yield* resolveInputs(material, (reference) =>\n reference._tag === \"Pending\"\n ? Effect.succeed(orderingOnly)\n : Effect.flatMap(ownDataProperty(options.results, reference.from, \"Settled result\"), (settled) => {\n const compute = decodeKey({ kind: \"input-value\", value: project(settled, reference.path) })\n return options.digestMemo === undefined\n ? compute\n : options.digestMemo.digest(reference.from, reference.path, compute)\n }))\n return yield* content({\n body: materialBody(material),\n inputs,\n layers: material.layers,\n capabilities: { declared: material.capabilities },\n environment,\n hermetic: options.hermetic\n })\n })\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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Q,SAAS;AAAA,IACjB,cAAc,EAAE,UAAU,SAAS,aAAa;AAAA,IAChD;AAAA,IACA,UAAU,QAAQ;AAAA,EACpB,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * The plan value: a keyed action graph, its diff, and the step-key compiler
3
+ * that gives every node its identity.
4
+ *
5
+ * A plan is a `Node` graph with every key computed, produced by the plan phase
6
+ * and inert until run. This package is that value and nothing more: it
7
+ * performs no I/O at all and never executes anything. Persisting a plan is
8
+ * `@smthrs/plan-store`; driving one is `@smthrs/engine-store`'s
9
+ * `PlanScheduler`.
10
+ *
11
+ * Above the persisted form sits the authoring AST: `Node` describes a plan as
12
+ * pure data, and `Planned` is the placeholder a body sees where a step result
13
+ * will be. Both build plans; neither runs one.
14
+ *
15
+ * @since 0.1.0
16
+ */
17
+ /**
18
+ * @since 0.1.0
19
+ * @category errors
20
+ * @slop
21
+ */
22
+ export * as GraphBuildError from "./GraphBuildError.ts";
23
+ /**
24
+ * @since 1.0.0-rc.0
25
+ * @category models
26
+ */
27
+ export * as CachePolicy from "./CachePolicy.ts";
28
+ /**
29
+ * @since 1.0.0-rc.0
30
+ * @category models
31
+ */
32
+ export * as Repetition from "./Repetition.ts";
33
+ /**
34
+ * @since 0.1.0
35
+ * @category models
36
+ * @slop
37
+ */
38
+ export * as KeyMaterial from "./KeyMaterial.ts";
39
+ /**
40
+ * @since 0.1.0
41
+ * @category models
42
+ * @slop
43
+ */
44
+ export * as FileSet from "./FileSet.ts";
45
+ /**
46
+ * @since 0.1.0
47
+ * @category models
48
+ * @slop
49
+ */
50
+ export * as Effects from "./Effects.ts";
51
+ /**
52
+ * @since 0.1.0
53
+ * @category models
54
+ * @slop
55
+ */
56
+ export * as Node from "./Node.ts";
57
+ /**
58
+ * @since 0.1.0
59
+ * @category models
60
+ * @slop
61
+ */
62
+ export * as Plan from "./Plan.ts";
63
+ /**
64
+ * @since 0.1.0
65
+ * @category constructors
66
+ * @slop
67
+ */
68
+ export * as PlanDiff from "./PlanDiff.ts";
69
+ /**
70
+ * @since 1.0.0
71
+ * @category models
72
+ */
73
+ export * as Placement from "./Placement.ts";
74
+ /**
75
+ * @since 0.1.0
76
+ * @category models
77
+ * @slop
78
+ */
79
+ export * as Planned from "./Planned.ts";
80
+ /**
81
+ * @since 0.1.0
82
+ * @category constructors
83
+ * @slop
84
+ */
85
+ export * as StepKey from "./StepKey.ts";
86
+ /**
87
+ * @since 1.0.0
88
+ * @category constructors
89
+ */
90
+ export * as Scheduling from "./Scheduling.ts";
91
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;GAIG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AAEvD;;;GAGG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C;;;GAGG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;;;GAIG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C;;;;GAIG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;GAIG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;GAIG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;GAIG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;GAIG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;;;GAIG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;GAIG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;GAGG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var index_exports = {};
30
+ __export(index_exports, {
31
+ CachePolicy: () => CachePolicy,
32
+ Effects: () => Effects,
33
+ FileSet: () => FileSet,
34
+ GraphBuildError: () => GraphBuildError,
35
+ KeyMaterial: () => KeyMaterial,
36
+ Node: () => Node,
37
+ Placement: () => Placement,
38
+ Plan: () => Plan,
39
+ PlanDiff: () => PlanDiff,
40
+ Planned: () => Planned,
41
+ Repetition: () => Repetition,
42
+ Scheduling: () => Scheduling,
43
+ StepKey: () => StepKey
44
+ });
45
+ module.exports = __toCommonJS(index_exports);
46
+ var GraphBuildError = __toESM(require("./GraphBuildError.js"), 1);
47
+ var CachePolicy = __toESM(require("./CachePolicy.js"), 1);
48
+ var Repetition = __toESM(require("./Repetition.js"), 1);
49
+ var KeyMaterial = __toESM(require("./KeyMaterial.js"), 1);
50
+ var FileSet = __toESM(require("./FileSet.js"), 1);
51
+ var Effects = __toESM(require("./Effects.js"), 1);
52
+ var Node = __toESM(require("./Node.js"), 1);
53
+ var Plan = __toESM(require("./Plan.js"), 1);
54
+ var PlanDiff = __toESM(require("./PlanDiff.js"), 1);
55
+ var Placement = __toESM(require("./Placement.js"), 1);
56
+ var Planned = __toESM(require("./Planned.js"), 1);
57
+ var StepKey = __toESM(require("./StepKey.js"), 1);
58
+ var Scheduling = __toESM(require("./Scheduling.js"), 1);
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["/**\n * The plan value: a keyed action graph, its diff, and the step-key compiler\n * that gives every node its identity.\n *\n * A plan is a `Node` graph with every key computed, produced by the plan phase\n * and inert until run. This package is that value and nothing more: it\n * performs no I/O at all and never executes anything. Persisting a plan is\n * `@smthrs/plan-store`; driving one is `@smthrs/engine-store`'s\n * `PlanScheduler`.\n *\n * Above the persisted form sits the authoring AST: `Node` describes a plan as\n * pure data, and `Planned` is the placeholder a body sees where a step result\n * will be. Both build plans; neither runs one.\n *\n * @since 0.1.0\n */\n\n/**\n * @since 0.1.0\n * @category errors\n * @slop\n */\nexport * as GraphBuildError from \"./GraphBuildError.ts\"\n\n/**\n * @since 1.0.0-rc.0\n * @category models\n */\nexport * as CachePolicy from \"./CachePolicy.ts\"\n\n/**\n * @since 1.0.0-rc.0\n * @category models\n */\nexport * as Repetition from \"./Repetition.ts\"\n\n/**\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport * as KeyMaterial from \"./KeyMaterial.ts\"\n\n/**\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport * as FileSet from \"./FileSet.ts\"\n\n/**\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport * as Effects from \"./Effects.ts\"\n\n/**\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport * as Node from \"./Node.ts\"\n\n/**\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport * as Plan from \"./Plan.ts\"\n\n/**\n * @since 0.1.0\n * @category constructors\n * @slop\n */\nexport * as PlanDiff from \"./PlanDiff.ts\"\n\n/**\n * @since 1.0.0\n * @category models\n */\nexport * as Placement from \"./Placement.ts\"\n\n/**\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport * as Planned from \"./Planned.ts\"\n\n/**\n * @since 0.1.0\n * @category constructors\n * @slop\n */\nexport * as StepKey from \"./StepKey.ts\"\n\n/**\n * @since 1.0.0\n * @category constructors\n */\nexport * as Scheduling from \"./Scheduling.ts\"\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,sBAAiC;AAMjC,kBAA6B;AAM7B,iBAA4B;AAO5B,kBAA6B;AAO7B,cAAyB;AAOzB,cAAyB;AAOzB,WAAsB;AAOtB,WAAsB;AAOtB,eAA0B;AAM1B,gBAA2B;AAO3B,cAAyB;AAOzB,cAAyB;AAMzB,iBAA4B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The compiler's effect analysis: which writers conflict, and which readers
3
+ * must wait for a producer. Its vocabulary is pairs of declared effects; it
4
+ * never re-keys a node, because ordering is not key material.
5
+ *
6
+ * @since 0.1.0
7
+ * @private
8
+ */
9
+ import * as Effect from "effect/Effect";
10
+ import type * as Plan from "../Plan.ts";
11
+ /**
12
+ * What {@link annotate} found, by node id and in discovery order: the conflict
13
+ * annotations a node carries and the ordering edges it gains. A frozen node
14
+ * never appears, because its row is never rewritten.
15
+ *
16
+ * @private
17
+ */
18
+ interface Annotations {
19
+ readonly conflicts: ReadonlyMap<string, ReadonlyArray<Plan.ConflictAnnotation>>;
20
+ readonly ordering: ReadonlyMap<string, ReadonlyArray<string>>;
21
+ }
22
+ /**
23
+ * A graph the analysis refuses, in the fields a `PlanError` carries.
24
+ *
25
+ * @private
26
+ */
27
+ interface Refusal {
28
+ readonly code: "cycle" | "graph_too_large" | "overlap_forbidden";
29
+ readonly message: string;
30
+ }
31
+ /**
32
+ * Two passes over the graph.
33
+ *
34
+ * The first detects write overlaps and annotates the conflicting pair, adding
35
+ * the ordering edge a `serialize` verdict implies. Nodes already ordered by a
36
+ * dependency path are not conflicts.
37
+ *
38
+ * The second adds reader-after-writer edges: a node that reads a path another
39
+ * node writes is ordered behind its producer. That pair is not a conflict,
40
+ * because nothing needs annotating and no strategy applies. It is a missing
41
+ * edge, so only `dependsOn` grows. When the graph already orders the producer
42
+ * behind its reader by explicit material dependencies, the reader consumes
43
+ * the earlier version. An opposing inferred ordering still fails with `cycle`.
44
+ *
45
+ * Nodes are visited in plan order, so a `serialize` edge always points from
46
+ * the earlier declaration to the later one and can never close a cycle. The
47
+ * first `frozen` nodes were recorded by an earlier generation: append-only
48
+ * means their rows are never rewritten, so a pair discovered during
49
+ * elaboration is annotated on the NEW node only — which is also the node the
50
+ * ordering edge lands on, and the annotation names the other side either way.
51
+ * `replayGenerations` re-derives a recorded plan one generation at a time
52
+ * under that same rule.
53
+ *
54
+ * @since 0.1.0
55
+ * @private
56
+ */
57
+ export declare const annotate: (nodes: ReadonlyArray<Plan.PlanNode>, frozen: number, replayGenerations: boolean) => Effect.Effect<Annotations, Refusal>;
58
+ export {};
59
+ //# sourceMappingURL=ConflictAnnotation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConflictAnnotation.d.ts","sourceRoot":"","sources":["../../../src/internal/ConflictAnnotation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAA;AAGvC;;;;;;GAMG;AACH,UAAU,WAAW;IACnB,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAA;IAC/E,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;CAC9D;AAED;;;;GAIG;AACH,UAAU,OAAO;IACf,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,GAAG,mBAAmB,CAAA;IAChE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAoED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,QAAQ,GACnB,OAAO,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,EACnC,QAAQ,MAAM,EACd,mBAAmB,OAAO,KACzB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAgPjC,CAAA"}