@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,489 @@
1
+ /**
2
+ * The plan: a node graph with every step key computed, inert until run.
3
+ *
4
+ * The way a plan is produced is a law: **planning performs no I/O**.
5
+ * Everything in this module is therefore a pure function of declarations plus
6
+ * the injected `Crypto` service: no filesystem, no clock, no network. A node's
7
+ * key is a function of what it consumes, so an edited declaration re-keys that
8
+ * node and everything downstream of it, and nothing else. That is the entire
9
+ * invalidation mechanism. Invalidation is re-keying, which **rejects**
10
+ * Skyframe's reverse-dependency index and invalidating node visitor outright
11
+ * because content addressing subsumes them. Key invalidation never retains a
12
+ * reverse-dependency index; annotation uses only a temporary reachability cache.
13
+ *
14
+ * Growth is append-only: {@link append} adds a pre-keyed subgraph to the same
15
+ * plan and never rewrites a node already in it.
16
+ *
17
+ * @since 0.1.0
18
+ */
19
+ import type * as Crypto from "effect/Crypto";
20
+ import * as Effect from "effect/Effect";
21
+ import * as Schema from "effect/Schema";
22
+ import * as KeyMaterial from "./KeyMaterial.ts";
23
+ import * as StepKey from "./StepKey.ts";
24
+ /**
25
+ * What a node does to the world, declared. Paths only — measuring them is
26
+ * run-time work, so a digest here would break the no-I/O law.
27
+ *
28
+ * Decoding fails with a `SchemaError` when a path is not workspace-relative.
29
+ * {@link compile} also refuses a node whose `removes` overlaps its `writes`
30
+ * with an `invalid_effects` {@link PlanError}.
31
+ *
32
+ * @since 0.1.0
33
+ * @category schemas
34
+ */
35
+ export declare const NodeEffects: Schema.Struct<{
36
+ /** Paths the node reads. A read orders the node after every writer of an overlapping path. */
37
+ readonly reads: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
38
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
39
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
40
+ }>]>, Schema.TaggedStruct<"Filegroup", {
41
+ readonly name: Schema.NonEmptyString;
42
+ readonly entries: Schema.$Array<Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
43
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
44
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
45
+ }>]>>;
46
+ }>]>>;
47
+ /** Paths the node writes. Two writers of an overlapping path form a conflict. */
48
+ readonly writes: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
49
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
50
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
51
+ }>, Schema.TaggedStruct<"TreeArtifact", {
52
+ readonly path: Schema.NonEmptyString;
53
+ }>]>, Schema.TaggedStruct<"Filegroup", {
54
+ readonly name: Schema.NonEmptyString;
55
+ readonly entries: Schema.$Array<Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
56
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
57
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
58
+ }>, Schema.TaggedStruct<"TreeArtifact", {
59
+ readonly path: Schema.NonEmptyString;
60
+ }>]>>;
61
+ }>]>>;
62
+ /**
63
+ * Paths the node declares it will DELETE. A removal mutates the world exactly
64
+ * as a write does, so {@link produces} folds the two together and both the
65
+ * conflict pass and the reader-after-writer pass see them as one set.
66
+ */
67
+ readonly removes: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
68
+ /** How strictly the sandbox enforces these declarations. */
69
+ readonly boundaryMode: Schema.Literals<readonly ["hard", "expected"]>;
70
+ }>;
71
+ /**
72
+ * The value form of {@link NodeEffects}.
73
+ *
74
+ * @since 0.1.0
75
+ * @category models
76
+ */
77
+ export type NodeEffects = typeof NodeEffects.Type;
78
+ /**
79
+ * The plan-time verdict for two writers of an overlapping path:
80
+ * `serialize` gives the later writer an ordering edge, `lane` records a lane
81
+ * annotation on both writers and adds no edge, and `fail` refuses the plan
82
+ * with `overlap_forbidden`. For a pair, `fail` dominates `lane`, which
83
+ * dominates `serialize`. The same schema as `Effects.ConflictStrategy`.
84
+ *
85
+ * @since 0.1.0
86
+ * @category schemas
87
+ */
88
+ export declare const PairStrategy: Schema.Literals<readonly ["serialize", "lane", "fail"]>;
89
+ /**
90
+ * The value form of {@link PairStrategy}.
91
+ *
92
+ * @since 0.1.0
93
+ * @category models
94
+ */
95
+ export type PairStrategy = typeof PairStrategy.Type;
96
+ /**
97
+ * The runtime half of a conflict annotation: what the scheduler
98
+ * does when the overlap the plan predicted actually bites, or when a
99
+ * scheduled node's inputs are invalidated under it. For a pair,
100
+ * `stop-merge` dominates `delay-rebase`.
101
+ *
102
+ * @since 0.1.0
103
+ * @category schemas
104
+ */
105
+ export declare const RuntimeStrategy: Schema.Literals<readonly ["delay-rebase", "stop-merge"]>;
106
+ /**
107
+ * The value form of {@link RuntimeStrategy}.
108
+ *
109
+ * @since 0.1.0
110
+ * @category models
111
+ */
112
+ export type RuntimeStrategy = typeof RuntimeStrategy.Type;
113
+ /**
114
+ * One resolved overlap between two writers that no dependency path already
115
+ * orders. Conflict is a property of the PAIR, not of one declaration.
116
+ *
117
+ * `with` names the other node, `paths` lists the overlapping declarations,
118
+ * and `strategy` and `runtime` are the verdicts resolved for the pair.
119
+ *
120
+ * @since 0.1.0
121
+ * @category schemas
122
+ */
123
+ export declare const ConflictAnnotation: Schema.Struct<{
124
+ readonly with: Schema.NonEmptyString;
125
+ readonly paths: Schema.$Array<Schema.String>;
126
+ readonly strategy: Schema.Literals<readonly ["serialize", "lane", "fail"]>;
127
+ readonly runtime: Schema.Literals<readonly ["delay-rebase", "stop-merge"]>;
128
+ }>;
129
+ /**
130
+ * The value form of {@link ConflictAnnotation}.
131
+ *
132
+ * @since 0.1.0
133
+ * @category models
134
+ */
135
+ export type ConflictAnnotation = typeof ConflictAnnotation.Type;
136
+ /**
137
+ * A keyed node of the plan.
138
+ *
139
+ * `dependsOn` is the *edge* set: material references, any ordering edge a
140
+ * `serialize` verdict added, and the reader-after-writer edges that put a
141
+ * node behind whoever produces the paths it reads. Ordering edges are
142
+ * deliberately NOT part of the key — a node ordered behind another still
143
+ * computes the same result, so re-keying it would throw away a legitimate
144
+ * cache hit.
145
+ *
146
+ * `strategy` and `runtime` are this declaration's own preferences, recorded so
147
+ * a later elaboration can resolve a pair against them without re-reading the
148
+ * flow source.
149
+ *
150
+ * `generation` is 0 for nodes from {@link compile} and grows by one with each
151
+ * {@link append}.
152
+ *
153
+ * @since 0.1.0
154
+ * @category schemas
155
+ */
156
+ export declare const PlanNode: Schema.Struct<{
157
+ readonly id: Schema.NonEmptyString;
158
+ readonly kind: Schema.Literals<readonly ["step", "agent", "merge"]>;
159
+ readonly key: Schema.brand<Schema.String, "@smthrs/keys/Key">;
160
+ readonly material: Schema.Struct<{
161
+ readonly version: Schema.Literal<"flows/key-material/v2">;
162
+ readonly kind: Schema.Literals<readonly ["sealed", "compensable", "irreversible"]>;
163
+ readonly nondeterministic: Schema.optional<Schema.Literal<true>>;
164
+ readonly body: Schema.Unknown;
165
+ readonly inputs: Schema.$Array<Schema.Union<readonly [Schema.TaggedStruct<"Literal", {
166
+ readonly value: Schema.Unknown;
167
+ }>, Schema.TaggedStruct<"Ref", {
168
+ readonly from: Schema.NonEmptyString;
169
+ readonly path: Schema.$Array<Schema.String>;
170
+ }>, Schema.TaggedStruct<"Pending", {
171
+ readonly from: Schema.NonEmptyString;
172
+ }>]>>;
173
+ readonly layers: Schema.$Array<Schema.String>;
174
+ readonly capabilities: Schema.$Array<Schema.String>;
175
+ readonly effects: Schema.optional<Schema.Unknown>;
176
+ readonly placement: Schema.optional<Schema.Unknown>;
177
+ }>;
178
+ readonly effects: Schema.Struct<{
179
+ /** Paths the node reads. A read orders the node after every writer of an overlapping path. */
180
+ readonly reads: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
181
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
182
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
183
+ }>]>, Schema.TaggedStruct<"Filegroup", {
184
+ readonly name: Schema.NonEmptyString;
185
+ readonly entries: Schema.$Array<Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
186
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
187
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
188
+ }>]>>;
189
+ }>]>>;
190
+ /** Paths the node writes. Two writers of an overlapping path form a conflict. */
191
+ readonly writes: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
192
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
193
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
194
+ }>, Schema.TaggedStruct<"TreeArtifact", {
195
+ readonly path: Schema.NonEmptyString;
196
+ }>]>, Schema.TaggedStruct<"Filegroup", {
197
+ readonly name: Schema.NonEmptyString;
198
+ readonly entries: Schema.$Array<Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
199
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
200
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
201
+ }>, Schema.TaggedStruct<"TreeArtifact", {
202
+ readonly path: Schema.NonEmptyString;
203
+ }>]>>;
204
+ }>]>>;
205
+ /**
206
+ * Paths the node declares it will DELETE. A removal mutates the world exactly
207
+ * as a write does, so {@link produces} folds the two together and both the
208
+ * conflict pass and the reader-after-writer pass see them as one set.
209
+ */
210
+ readonly removes: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
211
+ /** How strictly the sandbox enforces these declarations. */
212
+ readonly boundaryMode: Schema.Literals<readonly ["hard", "expected"]>;
213
+ }>;
214
+ readonly dependsOn: Schema.$Array<Schema.NonEmptyString>;
215
+ readonly conflicts: Schema.$Array<Schema.Struct<{
216
+ readonly with: Schema.NonEmptyString;
217
+ readonly paths: Schema.$Array<Schema.String>;
218
+ readonly strategy: Schema.Literals<readonly ["serialize", "lane", "fail"]>;
219
+ readonly runtime: Schema.Literals<readonly ["delay-rebase", "stop-merge"]>;
220
+ }>>;
221
+ readonly strategy: Schema.Literals<readonly ["serialize", "lane", "fail"]>;
222
+ readonly runtime: Schema.Literals<readonly ["delay-rebase", "stop-merge"]>;
223
+ readonly priority: Schema.Int;
224
+ readonly generation: Schema.Int;
225
+ }>;
226
+ /**
227
+ * The value form of {@link PlanNode}.
228
+ *
229
+ * @since 0.1.0
230
+ * @category models
231
+ */
232
+ export type PlanNode = typeof PlanNode.Type;
233
+ /**
234
+ * A plan: the whole keyed graph plus the digest an approval binds to.
235
+ *
236
+ * `nodes` follows material-dependency order within each generation. Inferred
237
+ * edges can point to later entries; schedule from the complete `dependsOn`
238
+ * graph, never by iterating the array alone.
239
+ *
240
+ * `baseDigest` is the digest at generation 0: what a human approved and what
241
+ * a `RUNNING` run pins. `digest` advances with every appended elaboration.
242
+ *
243
+ * Decoding checks only the shape. Use {@link verify} to check that keys,
244
+ * edges, and digests match the declarations.
245
+ *
246
+ * @since 0.1.0
247
+ * @category schemas
248
+ */
249
+ export declare const Plan: Schema.Struct<{
250
+ readonly planId: Schema.NonEmptyString;
251
+ readonly flow: Schema.NonEmptyString;
252
+ readonly generation: Schema.Int;
253
+ readonly baseDigest: Schema.brand<Schema.String, "@smthrs/keys/Key">;
254
+ readonly digest: Schema.brand<Schema.String, "@smthrs/keys/Key">;
255
+ readonly nodes: Schema.$Array<Schema.Struct<{
256
+ readonly id: Schema.NonEmptyString;
257
+ readonly kind: Schema.Literals<readonly ["step", "agent", "merge"]>;
258
+ readonly key: Schema.brand<Schema.String, "@smthrs/keys/Key">;
259
+ readonly material: Schema.Struct<{
260
+ readonly version: Schema.Literal<"flows/key-material/v2">;
261
+ readonly kind: Schema.Literals<readonly ["sealed", "compensable", "irreversible"]>;
262
+ readonly nondeterministic: Schema.optional<Schema.Literal<true>>;
263
+ readonly body: Schema.Unknown;
264
+ readonly inputs: Schema.$Array<Schema.Union<readonly [Schema.TaggedStruct<"Literal", {
265
+ readonly value: Schema.Unknown;
266
+ }>, Schema.TaggedStruct<"Ref", {
267
+ readonly from: Schema.NonEmptyString;
268
+ readonly path: Schema.$Array<Schema.String>;
269
+ }>, Schema.TaggedStruct<"Pending", {
270
+ readonly from: Schema.NonEmptyString;
271
+ }>]>>;
272
+ readonly layers: Schema.$Array<Schema.String>;
273
+ readonly capabilities: Schema.$Array<Schema.String>;
274
+ readonly effects: Schema.optional<Schema.Unknown>;
275
+ readonly placement: Schema.optional<Schema.Unknown>;
276
+ }>;
277
+ readonly effects: Schema.Struct<{
278
+ /** Paths the node reads. A read orders the node after every writer of an overlapping path. */
279
+ readonly reads: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
280
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
281
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
282
+ }>]>, Schema.TaggedStruct<"Filegroup", {
283
+ readonly name: Schema.NonEmptyString;
284
+ readonly entries: Schema.$Array<Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
285
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
286
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
287
+ }>]>>;
288
+ }>]>>;
289
+ /** Paths the node writes. Two writers of an overlapping path form a conflict. */
290
+ readonly writes: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
291
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
292
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
293
+ }>, Schema.TaggedStruct<"TreeArtifact", {
294
+ readonly path: Schema.NonEmptyString;
295
+ }>]>, Schema.TaggedStruct<"Filegroup", {
296
+ readonly name: Schema.NonEmptyString;
297
+ readonly entries: Schema.$Array<Schema.Union<readonly [Schema.NonEmptyString, Schema.TaggedStruct<"Glob", {
298
+ readonly include: Schema.NonEmptyArray<Schema.NonEmptyString>;
299
+ readonly exclude: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
300
+ }>, Schema.TaggedStruct<"TreeArtifact", {
301
+ readonly path: Schema.NonEmptyString;
302
+ }>]>>;
303
+ }>]>>;
304
+ /**
305
+ * Paths the node declares it will DELETE. A removal mutates the world exactly
306
+ * as a write does, so {@link produces} folds the two together and both the
307
+ * conflict pass and the reader-after-writer pass see them as one set.
308
+ */
309
+ readonly removes: Schema.optional<Schema.$Array<Schema.NonEmptyString>>;
310
+ /** How strictly the sandbox enforces these declarations. */
311
+ readonly boundaryMode: Schema.Literals<readonly ["hard", "expected"]>;
312
+ }>;
313
+ readonly dependsOn: Schema.$Array<Schema.NonEmptyString>;
314
+ readonly conflicts: Schema.$Array<Schema.Struct<{
315
+ readonly with: Schema.NonEmptyString;
316
+ readonly paths: Schema.$Array<Schema.String>;
317
+ readonly strategy: Schema.Literals<readonly ["serialize", "lane", "fail"]>;
318
+ readonly runtime: Schema.Literals<readonly ["delay-rebase", "stop-merge"]>;
319
+ }>>;
320
+ readonly strategy: Schema.Literals<readonly ["serialize", "lane", "fail"]>;
321
+ readonly runtime: Schema.Literals<readonly ["delay-rebase", "stop-merge"]>;
322
+ readonly priority: Schema.Int;
323
+ readonly generation: Schema.Int;
324
+ }>>;
325
+ }>;
326
+ /**
327
+ * The value form of {@link Plan}.
328
+ *
329
+ * @since 0.1.0
330
+ * @category models
331
+ */
332
+ export type Plan = typeof Plan.Type;
333
+ /**
334
+ * What a planner hands {@link compile}: a node without its key.
335
+ *
336
+ * @since 0.1.0
337
+ * @category models
338
+ */
339
+ export interface NodeDraft {
340
+ /** A non-empty id, unique within the plan. */
341
+ readonly id: string;
342
+ /** The key inputs. Its `Ref` inputs name the node's material dependencies. */
343
+ readonly material: KeyMaterial.KeyMaterial;
344
+ /** The declared reads, writes, and removals. They replace `material.effects`. */
345
+ readonly effects: NodeEffects;
346
+ /** `step`, `agent`, or `merge`. Defaults to `step`. */
347
+ readonly kind?: PlanNode["kind"] | undefined;
348
+ /** A safe integer scheduling priority. Defaults to 0. */
349
+ readonly priority?: number | undefined;
350
+ /** This declaration's preferred plan-time verdict for a detected overlap. */
351
+ readonly conflictStrategy?: PairStrategy | undefined;
352
+ /** This declaration's preferred runtime response. */
353
+ readonly runtimeStrategy?: RuntimeStrategy | undefined;
354
+ }
355
+ declare const PlanError_base: Schema.Class<PlanError, Schema.TaggedStruct<"@smthrs/plan/PlanError", {
356
+ readonly code: Schema.Literals<readonly ["cycle", "unknown_dependency", "duplicate_node", "overlap_forbidden", "invalid_effects", "invalid_node", "invalid_plan", "graph_too_large"]>;
357
+ readonly message: Schema.String;
358
+ }>, import("effect/Cause").YieldableError>;
359
+ /**
360
+ * A graph the compiler refuses. `code` names the rule:
361
+ *
362
+ * - `cycle`: material or inferred edges form a cycle.
363
+ * - `unknown_dependency`: a `Ref` names a node that is not in the plan.
364
+ * - `duplicate_node`: two nodes share an id.
365
+ * - `overlap_forbidden`: two unordered writers overlap and the pair's
366
+ * strategy is `fail`.
367
+ * - `invalid_effects`: a node both writes and removes one path.
368
+ * - `invalid_node`: a draft field, the plan id, or the flow name is malformed.
369
+ * - `invalid_plan`: {@link verify} found a plan that does not match its
370
+ * declarations.
371
+ * - `graph_too_large`: the plan exceeds {@link maximumPlanNodes} or the
372
+ * effect-analysis work budget.
373
+ *
374
+ * @since 0.1.0
375
+ * @category errors
376
+ */
377
+ export declare class PlanError extends PlanError_base {
378
+ }
379
+ /**
380
+ * Maximum number of nodes retained by one compiled plan.
381
+ *
382
+ * Effect analysis also has a yielding work budget, since a node ceiling alone
383
+ * does not bound dense conflicts to practical work.
384
+ *
385
+ * @since 1.0.0
386
+ * @category limits
387
+ */
388
+ export declare const maximumPlanNodes = 10000;
389
+ /**
390
+ * Compiles drafts into a plan: material-dependency order, dependency-digest
391
+ * substitution, overlap annotation, and the plan digest. No I/O.
392
+ * Inferred edges extend `dependsOn` without reordering the node array.
393
+ *
394
+ * Traversal uses explicit stacks. Because the conflict and reader/writer
395
+ * passes consider a quadratic number of node pairs, plans are bounded by
396
+ * {@link maximumPlanNodes} and fail with `graph_too_large` above that limit
397
+ * or the effect-analysis work budget. Analysis yields periodically.
398
+ *
399
+ * The options and drafts are copied when `compile` is called, so later
400
+ * caller mutation does not reach the plan. The result is deeply frozen.
401
+ *
402
+ * @param options - `planId` and `flow` name the plan; `nodes` are the drafts.
403
+ * @returns The generation-0 plan, whose `baseDigest` equals its `digest`.
404
+ * Fails with {@link PlanError} for a refused graph, `KeyMaterialError` or
405
+ * `SchemaError` when a key cannot be derived.
406
+ * @since 0.1.0
407
+ * @category constructors
408
+ */
409
+ export declare const compile: (options: {
410
+ readonly planId: string;
411
+ readonly flow: string;
412
+ readonly nodes: ReadonlyArray<NodeDraft>;
413
+ }) => Effect.Effect<Plan, PlanError | StepKey.KeyMaterialError | Schema.SchemaError, Crypto.Crypto>;
414
+ /**
415
+ * Appends an elaborated subgraph to an existing plan.
416
+ *
417
+ * The plan GROWS; it is never invalidated. Nodes already in it keep their id,
418
+ * key, edges, and generation byte for byte, and the new nodes arrive pre-keyed
419
+ * against them, so a `hit` shows instantly. New nodes retain their material
420
+ * dependency order; scheduling must honor their complete `dependsOn` graph.
421
+ * Re-ordering after a reconciliation happens by re-keying *future* steps,
422
+ * never by rewriting history.
423
+ *
424
+ * A plan not produced by this module is checked with {@link verify} first.
425
+ *
426
+ * @param plan - The plan to grow.
427
+ * @param drafts - At least one new node. Ids must not repeat existing ones;
428
+ * `Ref` inputs may name existing nodes.
429
+ * @returns The plan with one more generation and a new `digest`. Fails with
430
+ * {@link PlanError} (`invalid_node` for an empty `drafts`, `invalid_plan` for a
431
+ * plan that fails verification), `KeyMaterialError`, or `SchemaError`.
432
+ * @since 0.1.0
433
+ * @category constructors
434
+ */
435
+ export declare const append: (plan: Plan, drafts: ReadonlyArray<NodeDraft>) => Effect.Effect<Plan, PlanError | StepKey.KeyMaterialError | Schema.SchemaError, Crypto.Crypto>;
436
+ /**
437
+ * Verifies an imported plan against the same key and topology rules as the
438
+ * compiler. Valid compiler-owned immutable values need no second compilation.
439
+ *
440
+ * Generation boundaries are replayed when reconstructing conflict annotations:
441
+ * an append may annotate new nodes, but cannot rewrite an earlier generation.
442
+ * Recorded material-dependency order is verified without sorting inferred edges.
443
+ * Keys and approval digests retain their existing format. The returned snapshot
444
+ * is immutable; later caller mutation cannot change the verified value.
445
+ *
446
+ * @since 1.0.0
447
+ * @category validation
448
+ */
449
+ export declare const verify: (input: unknown) => Effect.Effect<Plan, PlanError | StepKey.KeyMaterialError | Schema.SchemaError, Crypto.Crypto>;
450
+ /**
451
+ * The nodes added by the newest generation: what {@link module:PlanStore}
452
+ * appends and what the `subgraph-appended` journal record names.
453
+ *
454
+ * @param plan - A plan.
455
+ * @returns The nodes whose generation equals `plan.generation`, in order.
456
+ * @since 0.1.0
457
+ * @category accessors
458
+ */
459
+ export declare const generationNodes: (plan: Plan) => ReadonlyArray<PlanNode>;
460
+ /**
461
+ * Whether `input` is a compiler-owned immutable snapshot that already passed
462
+ * {@link verify}: such values take verify's trusted fast path and need no
463
+ * second schema validation.
464
+ *
465
+ * @param input - Any value.
466
+ * @returns `true` only for a plan returned by {@link compile},
467
+ * {@link append}, or {@link verify}; a structurally equal copy returns `false`.
468
+ * @since 1.0.0
469
+ * @category guards
470
+ */
471
+ export declare const isVerified: (input: unknown) => input is Plan;
472
+ /**
473
+ * The approval digest of every generation before the newest: the digest this
474
+ * plan carried before its last append. {@link module:PlanStore}'s append
475
+ * matches it against the stored envelope, so an append proves the recorded
476
+ * plan's integrity from the already-verified prefix instead of decoding and
477
+ * re-verifying every stored row.
478
+ *
479
+ * For a generation-0 plan no generation precedes the newest, so this is the
480
+ * digest of an empty node list.
481
+ *
482
+ * @param plan - A plan.
483
+ * @returns The approval digest of the nodes older than `plan.generation`.
484
+ * @since 1.0.0
485
+ * @category accessors
486
+ */
487
+ export declare const prefixDigest: (plan: Plan) => Effect.Effect<StepKey.StepKey, StepKey.KeyMaterialError | Schema.SchemaError, Crypto.Crypto>;
488
+ export {};
489
+ //# sourceMappingURL=Plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plan.d.ts","sourceRoot":"","sources":["../../src/Plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAMvC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW;IACtB,8FAA8F;;;;;;;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