1use std::collections::BTreeMap;
2use std::path::PathBuf;
3
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7use crate::physical_identity::RetainedPhysicalIdentity;
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
10pub struct TemplateDescriptor {
11 pub(crate) id: String,
12 pub(crate) version: String,
13 pub(crate) name: String,
14}
15
16impl TemplateDescriptor {
17 pub fn id(&self) -> &str {
18 &self.id
19 }
20
21 pub fn version(&self) -> &str {
22 &self.version
23 }
24
25 pub fn name(&self) -> &str {
26 &self.name
27 }
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
31pub struct TemplatePackage {
32 #[serde(rename = "$schema")]
33 pub(crate) schema: Option<String>,
34 pub(crate) protocol_version: String,
35 pub(crate) id: String,
36 pub(crate) version: String,
37 pub(crate) name: String,
38 pub(crate) description: Option<String>,
39 pub(crate) suggested_folderbase_kind: FolderbaseKind,
40 #[serde(default)]
41 pub(crate) questions: Vec<TemplateQuestion>,
42 pub(crate) artifacts: Vec<TemplateArtifact>,
43 #[serde(default)]
44 pub(crate) upgrade_edges: Vec<TemplateUpgradeEdge>,
45 #[serde(flatten)]
46 pub(crate) extensions: BTreeMap<String, Value>,
47}
48
49impl TemplatePackage {
50 pub fn protocol_version(&self) -> &str {
51 &self.protocol_version
52 }
53
54 pub fn id(&self) -> &str {
55 &self.id
56 }
57
58 pub fn version(&self) -> &str {
59 &self.version
60 }
61
62 pub fn name(&self) -> &str {
63 &self.name
64 }
65
66 pub fn questions(&self) -> &[TemplateQuestion] {
67 &self.questions
68 }
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
72pub struct TemplateQuestion {
73 pub(crate) id: String,
74 pub(crate) prompt: String,
75 #[serde(default)]
76 pub(crate) answer_type: TemplateAnswerType,
77 #[serde(default)]
78 pub(crate) required: bool,
79 #[serde(flatten)]
80 pub(crate) extensions: BTreeMap<String, Value>,
81}
82
83impl TemplateQuestion {
84 pub fn id(&self) -> &str {
85 &self.id
86 }
87
88 pub fn prompt(&self) -> &str {
89 &self.prompt
90 }
91
92 pub fn answer_type(&self) -> TemplateAnswerType {
93 self.answer_type
94 }
95
96 pub fn required(&self) -> bool {
97 self.required
98 }
99}
100
101#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
102#[serde(rename_all = "snake_case")]
103pub enum TemplateAnswerType {
104 #[default]
105 Text,
106 Boolean,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
110#[serde(untagged)]
111pub enum TemplateAnswerValue {
112 Text(String),
113 Boolean(bool),
114}
115
116#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
117#[serde(rename_all = "snake_case")]
118pub enum TemplateArtifactKind {
119 Directory,
120 Text,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
124pub(crate) struct TemplateArtifact {
125 pub(crate) target: PathBuf,
126 pub(crate) kind: TemplateArtifactKind,
127 pub(crate) content: Option<String>,
128 pub(crate) install: String,
129 #[serde(flatten)]
130 pub(crate) extensions: BTreeMap<String, Value>,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
134pub(crate) struct TemplateUpgradeEdge {
135 pub(crate) from: String,
136 pub(crate) to: String,
137 pub(crate) notes: Option<String>,
138 #[serde(flatten)]
139 pub(crate) extensions: BTreeMap<String, Value>,
140}
141
142#[derive(Debug, Serialize)]
143pub struct TemplateRenderPlan {
144 pub(crate) template_id: String,
145 pub(crate) template_version: String,
146 pub(crate) additions: Vec<PlannedTemplateAddition>,
147 pub(crate) existing_paths: Vec<PathBuf>,
148}
149
150impl TemplateRenderPlan {
151 pub fn template_id(&self) -> &str {
152 &self.template_id
153 }
154
155 pub fn template_version(&self) -> &str {
156 &self.template_version
157 }
158
159 pub fn additions(&self) -> &[PlannedTemplateAddition] {
160 &self.additions
161 }
162
163 pub fn existing_paths(&self) -> &[PathBuf] {
164 &self.existing_paths
165 }
166}
167
168#[derive(Debug, Serialize)]
169pub struct PlannedTemplateAddition {
170 pub(crate) path: PathBuf,
171 pub(crate) kind: TemplateArtifactKind,
172 pub(crate) content: Option<String>,
173}
174
175impl PlannedTemplateAddition {
176 pub fn path(&self) -> &std::path::Path {
177 &self.path
178 }
179
180 pub fn kind(&self) -> TemplateArtifactKind {
181 self.kind
182 }
183
184 pub fn content(&self) -> Option<&str> {
185 self.content.as_deref()
186 }
187}
188
189#[derive(Debug, Serialize)]
194pub struct TemplateExpansionPlan {
195 pub(crate) root: PathBuf,
196 pub(crate) folderbase_id: String,
197 pub(crate) template_id: String,
198 pub(crate) comparison_version: String,
199 pub(crate) comparison_source: TemplateComparisonSource,
200 pub(crate) comparison_application_id: Option<String>,
201 pub(crate) comparison_package_digest: TemplatePlanDigest,
202 pub(crate) template_version: String,
203 pub(crate) template_package_digest: TemplatePlanDigest,
204 pub(crate) additions: Vec<PlannedTemplateAddition>,
205 pub(crate) preserved_paths: Vec<PathBuf>,
206 pub(crate) blocked_paths: Vec<PathBuf>,
207 pub(crate) structural_changes: Vec<TemplateStructuralChange>,
208 pub(crate) plan_digest: TemplatePlanDigest,
209 pub(crate) manifest_sha256: String,
210 pub(crate) history_sha256: String,
211 pub(crate) preserved_preconditions: Vec<TemplateExpansionPrecondition>,
212 #[serde(skip_serializing)]
213 pub(crate) root_identity_sha256: String,
214 #[serde(skip_serializing)]
215 pub(crate) root_identity: RetainedPhysicalIdentity,
216}
217
218impl TemplateExpansionPlan {
219 pub fn root(&self) -> &std::path::Path {
220 &self.root
221 }
222
223 pub fn folderbase_id(&self) -> &str {
224 &self.folderbase_id
225 }
226
227 pub fn template_id(&self) -> &str {
228 &self.template_id
229 }
230
231 pub fn comparison_source(&self) -> TemplateComparisonSource {
232 self.comparison_source
233 }
234
235 pub fn comparison_application_id(&self) -> Option<&str> {
236 self.comparison_application_id.as_deref()
237 }
238
239 pub fn comparison_version(&self) -> &str {
240 &self.comparison_version
241 }
242
243 pub fn template_version(&self) -> &str {
244 &self.template_version
245 }
246
247 pub fn template_package_digest(&self) -> &TemplatePlanDigest {
248 &self.template_package_digest
249 }
250
251 pub fn additions(&self) -> &[PlannedTemplateAddition] {
252 &self.additions
253 }
254
255 pub fn preserved_paths(&self) -> &[PathBuf] {
256 &self.preserved_paths
257 }
258
259 pub fn blocked_paths(&self) -> &[PathBuf] {
260 &self.blocked_paths
261 }
262
263 pub fn structural_changes(&self) -> &[TemplateStructuralChange] {
264 &self.structural_changes
265 }
266
267 pub fn plan_digest(&self) -> &TemplatePlanDigest {
268 &self.plan_digest
269 }
270
271 pub fn is_noop(&self) -> bool {
272 self.template_version == self.comparison_version
273 && self.additions.is_empty()
274 && self.blocked_paths.is_empty()
275 && self.structural_changes.is_empty()
276 }
277}
278
279#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
280#[serde(rename_all = "snake_case")]
281pub enum TemplateStructuralChangeKind {
282 Downgrade,
283 Lineage,
284 UnsupportedTransition,
285}
286
287#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
288pub struct TemplateStructuralChange {
289 pub(crate) kind: TemplateStructuralChangeKind,
290 pub(crate) path: Option<PathBuf>,
291 pub(crate) reason: String,
292}
293
294impl TemplateStructuralChange {
295 pub fn kind(&self) -> TemplateStructuralChangeKind {
296 self.kind
297 }
298
299 pub fn path(&self) -> Option<&std::path::Path> {
300 self.path.as_deref()
301 }
302
303 pub fn reason(&self) -> &str {
304 &self.reason
305 }
306}
307
308#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
309pub struct TemplatePlanDigest {
310 pub(crate) algorithm: String,
311 pub(crate) digest: String,
312}
313
314impl TemplatePlanDigest {
315 pub fn algorithm(&self) -> &str {
316 &self.algorithm
317 }
318
319 pub fn digest(&self) -> &str {
320 &self.digest
321 }
322}
323
324#[derive(Debug, Serialize)]
325pub(crate) struct TemplateExpansionPrecondition {
326 pub(crate) path: PathBuf,
327 pub(crate) kind: TemplateArtifactKind,
328 pub(crate) sha256: Option<String>,
329 #[serde(skip_serializing)]
330 pub(crate) identity: RetainedPhysicalIdentity,
331}
332
333#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
334pub struct TemplateApplicationRecord {
335 #[serde(rename = "$schema")]
336 pub(crate) schema: String,
337 pub(crate) protocol_version: String,
338 pub(crate) id: String,
339 pub(crate) folderbase_id: String,
340 pub(crate) state: TemplateApplicationState,
341 pub(crate) template: AppliedTemplate,
342 pub(crate) comparison: TemplateApplicationComparison,
343 pub(crate) applied_at: String,
344 pub(crate) created_paths: Vec<TemplateApplicationCreatedPath>,
345 pub(crate) preserved_targets: Vec<TemplateApplicationPreservedTarget>,
346 pub(crate) plan_digest: TemplatePlanDigest,
347 pub(crate) record_digest: TemplatePlanDigest,
348}
349
350impl TemplateApplicationRecord {
351 pub fn id(&self) -> &str {
352 &self.id
353 }
354
355 pub fn folderbase_id(&self) -> &str {
356 &self.folderbase_id
357 }
358
359 pub fn state(&self) -> TemplateApplicationState {
360 self.state
361 }
362
363 pub fn template_id(&self) -> &str {
364 &self.template.id
365 }
366
367 pub fn template_version(&self) -> &str {
368 &self.template.version
369 }
370
371 pub fn comparison_version(&self) -> &str {
372 &self.comparison.version
373 }
374
375 pub fn applied_at(&self) -> &str {
376 &self.applied_at
377 }
378
379 pub fn created_paths(&self) -> &[TemplateApplicationCreatedPath] {
380 &self.created_paths
381 }
382
383 pub fn preserved_targets(&self) -> &[TemplateApplicationPreservedTarget] {
384 &self.preserved_targets
385 }
386
387 pub fn plan_digest(&self) -> &TemplatePlanDigest {
388 &self.plan_digest
389 }
390
391 pub fn record_digest(&self) -> &TemplatePlanDigest {
392 &self.record_digest
393 }
394}
395
396#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
397pub(crate) struct AppliedTemplate {
398 pub(crate) id: String,
399 pub(crate) version: String,
400 pub(crate) package_digest: TemplatePlanDigest,
401}
402
403#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
404#[serde(rename_all = "snake_case")]
405pub enum TemplateApplicationState {
406 Verified,
407}
408
409#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
410#[serde(rename_all = "snake_case")]
411pub enum TemplateComparisonSource {
412 Unmanaged,
413 Origin,
414 Application,
415}
416
417#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
418pub(crate) struct TemplateApplicationComparison {
419 pub(crate) source: TemplateComparisonSource,
420 pub(crate) version: String,
421 pub(crate) application_id: Option<String>,
422}
423
424#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
425pub struct TemplateApplicationCreatedPath {
426 pub(crate) path: PathBuf,
427 pub(crate) kind: TemplateArtifactKind,
428 pub(crate) bytes: Option<u64>,
429 pub(crate) sha256: Option<String>,
430}
431
432impl TemplateApplicationCreatedPath {
433 pub fn path(&self) -> &std::path::Path {
434 &self.path
435 }
436
437 pub fn kind(&self) -> TemplateArtifactKind {
438 self.kind
439 }
440
441 pub fn bytes(&self) -> Option<u64> {
442 self.bytes
443 }
444
445 pub fn sha256(&self) -> Option<&str> {
446 self.sha256.as_deref()
447 }
448}
449
450impl AsRef<std::path::Path> for TemplateApplicationCreatedPath {
451 fn as_ref(&self) -> &std::path::Path {
452 &self.path
453 }
454}
455
456#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
457pub struct TemplateApplicationPreservedTarget {
458 pub(crate) path: PathBuf,
459 pub(crate) kind: TemplateArtifactKind,
460 pub(crate) bytes: Option<u64>,
461 pub(crate) sha256: Option<String>,
462}
463
464impl TemplateApplicationPreservedTarget {
465 pub fn path(&self) -> &std::path::Path {
466 &self.path
467 }
468
469 pub fn kind(&self) -> TemplateArtifactKind {
470 self.kind
471 }
472
473 pub fn bytes(&self) -> Option<u64> {
474 self.bytes
475 }
476
477 pub fn sha256(&self) -> Option<&str> {
478 self.sha256.as_deref()
479 }
480}
481
482impl AsRef<std::path::Path> for TemplateApplicationPreservedTarget {
483 fn as_ref(&self) -> &std::path::Path {
484 &self.path
485 }
486}
487
488#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
489pub struct TemplateApplicationResult {
490 pub(crate) created_paths: Vec<PathBuf>,
491 pub(crate) preserved_paths: Vec<PathBuf>,
492 pub(crate) application_record: Option<PathBuf>,
493}
494
495impl TemplateApplicationResult {
496 pub fn created_paths(&self) -> &[PathBuf] {
497 &self.created_paths
498 }
499
500 pub fn preserved_paths(&self) -> &[PathBuf] {
501 &self.preserved_paths
502 }
503
504 pub fn application_record(&self) -> Option<&std::path::Path> {
505 self.application_record.as_deref()
506 }
507}
508
509#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
510pub struct InspectionReport {
511 pub root: PathBuf,
512 pub inventory: InventorySummary,
513 pub classified_paths: Vec<ClassifiedPath>,
514 pub git_repositories: Vec<PathBuf>,
515 pub context_files: Vec<PathBuf>,
516 pub boundary_hints: Vec<BoundaryHint>,
517 #[serde(default)]
518 pub reconstructable_trees: Vec<ReconstructableTree>,
519 #[serde(default)]
520 pub nested_folderbases: Vec<NestedFolderbaseBoundary>,
521 pub warnings: Vec<String>,
522}
523
524#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
525pub struct InventorySummary {
526 pub file_count: u64,
527 pub total_bytes: u64,
528 pub generated_file_count: u64,
529 #[serde(default)]
530 pub reconstructable_tree_count: u64,
531 pub secret_shaped_file_count: u64,
532 pub temporary_file_count: u64,
533 pub large_file_count: u64,
534 pub versioned_file_count: u64,
535}
536
537#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
538pub struct ClassifiedPath {
539 pub path: PathBuf,
540 pub classification: Classification,
541 pub reason: String,
542 pub bytes: u64,
543}
544
545#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
546#[serde(rename_all = "snake_case")]
547pub enum Classification {
548 Generated,
549 SecretShaped,
550 Temporary,
551 Large,
552 Versioned,
553}
554
555#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
556pub struct BoundaryHint {
557 pub path: PathBuf,
558 pub kind: String,
559 pub reason: String,
560}
561
562#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
563pub struct ReconstructableTree {
564 #[serde(with = "crate::portable_wire_path::relative")]
565 pub path: PathBuf,
566}
567
568#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
569pub struct NestedFolderbaseBoundary {
570 #[serde(with = "crate::portable_wire_path::relative")]
571 pub path: PathBuf,
572 pub state: NestedFolderbaseState,
573}
574
575#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
576#[serde(rename_all = "snake_case")]
577pub enum NestedFolderbaseState {
578 Unchecked,
579}
580
581#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
582#[serde(rename_all = "snake_case")]
583pub enum FolderbaseKind {
584 Person,
585 Organization,
586 Engagement,
587 #[default]
588 Project,
589 Customer,
590 Temporary,
591 Custom,
592}
593
594#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
595pub struct InitializationOptions {
596 pub name: Option<String>,
597 pub kind: FolderbaseKind,
598 pub create_agent_adapters: bool,
599}
600
601impl Default for InitializationOptions {
602 fn default() -> Self {
603 Self {
604 name: None,
605 kind: FolderbaseKind::Project,
606 create_agent_adapters: false,
607 }
608 }
609}
610
611#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
614pub struct InitializationPlanDigest {
615 pub(crate) algorithm: String,
616 pub(crate) digest: String,
617}
618
619impl InitializationPlanDigest {
620 pub fn parse_sha256(digest: impl Into<String>) -> crate::Result<Self> {
621 let digest = digest.into();
622 if !Self::is_valid_sha256(&digest) {
623 return Err(crate::FolderbaseError::InvalidInitializationPlanDigest);
624 }
625 Ok(Self {
626 algorithm: "sha256".to_owned(),
627 digest,
628 })
629 }
630
631 pub fn algorithm(&self) -> &str {
632 &self.algorithm
633 }
634
635 pub fn digest(&self) -> &str {
636 &self.digest
637 }
638
639 pub(crate) fn validate(&self) -> crate::Result<()> {
640 if self.algorithm != "sha256" || !Self::is_valid_sha256(&self.digest) {
641 return Err(crate::FolderbaseError::InvalidInitializationPlanDigest);
642 }
643 Ok(())
644 }
645
646 fn is_valid_sha256(digest: &str) -> bool {
647 digest.len() == 64
648 && digest
649 .bytes()
650 .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))
651 }
652}
653
654#[derive(Clone)]
655pub(crate) enum InitializationRequest {
656 Ordinary {
657 options: InitializationOptions,
658 },
659 Template {
660 options: InitializationOptions,
661 package: Box<TemplatePackage>,
662 answers: BTreeMap<String, TemplateAnswerValue>,
663 },
664}
665
666impl std::fmt::Debug for InitializationRequest {
667 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
668 match self {
669 Self::Ordinary { options } => formatter
670 .debug_struct("Ordinary")
671 .field("options", options)
672 .finish(),
673 Self::Template {
674 options,
675 package,
676 answers,
677 } => formatter
678 .debug_struct("Template")
679 .field("options", options)
680 .field("template_id", &package.id)
681 .field("template_version", &package.version)
682 .field("answer_ids", &answers.keys().collect::<Vec<_>>())
683 .finish(),
684 }
685 }
686}
687
688#[derive(Debug, Clone, PartialEq, Eq)]
689pub(crate) struct InitializationDestinationEntry {
690 pub(crate) path: PathBuf,
691 pub(crate) kind: InitializationDestinationKind,
692}
693
694#[derive(Debug, Clone, Copy, PartialEq, Eq)]
695pub(crate) enum InitializationDestinationKind {
696 Directory,
697 File,
698 Symlink,
699 ReconstructableDirectory,
700 GitMetadata,
701 NestedFolderbase,
702 Other,
703}
704
705#[derive(Debug, Serialize)]
710pub struct InitializationPlan {
711 pub(crate) root: PathBuf,
712 pub(crate) folderbase_id: String,
713 pub(crate) folderbase_name: String,
714 pub(crate) folderbase_kind: FolderbaseKind,
715 pub(crate) directories: Vec<PlannedDirectory>,
716 pub(crate) writes: Vec<PlannedWrite>,
717 pub(crate) template_preconditions: Vec<TemplateArtifactPrecondition>,
718 pub(crate) preserved_paths: Vec<PreservedPath>,
719 pub(crate) warnings: Vec<String>,
720 pub(crate) plan_digest: InitializationPlanDigest,
721 #[serde(skip_serializing)]
722 pub(crate) root_identity: RetainedPhysicalIdentity,
723 #[serde(skip_serializing)]
724 pub(crate) destination_inventory: Vec<InitializationDestinationEntry>,
725}
726
727impl InitializationPlan {
728 pub fn root(&self) -> &std::path::Path {
729 &self.root
730 }
731
732 pub fn folderbase_id(&self) -> &str {
733 &self.folderbase_id
734 }
735
736 pub fn folderbase_name(&self) -> &str {
737 &self.folderbase_name
738 }
739
740 pub fn folderbase_kind(&self) -> FolderbaseKind {
741 self.folderbase_kind
742 }
743
744 pub fn writes(&self) -> &[PlannedWrite] {
745 &self.writes
746 }
747
748 pub fn directories(&self) -> &[PlannedDirectory] {
749 &self.directories
750 }
751
752 pub fn template_preconditions(&self) -> &[TemplateArtifactPrecondition] {
753 &self.template_preconditions
754 }
755
756 pub fn preserved_paths(&self) -> &[PreservedPath] {
757 &self.preserved_paths
758 }
759
760 pub fn warnings(&self) -> &[String] {
761 &self.warnings
762 }
763
764 pub fn plan_digest(&self) -> &InitializationPlanDigest {
765 &self.plan_digest
766 }
767}
768
769#[derive(Debug, Serialize)]
770pub struct TemplateArtifactPrecondition {
771 pub(crate) path: PathBuf,
772 pub(crate) kind: TemplateArtifactKind,
773 #[serde(skip_serializing)]
774 pub(crate) identity: RetainedPhysicalIdentity,
775}
776
777impl TemplateArtifactPrecondition {
778 pub fn path(&self) -> &std::path::Path {
779 &self.path
780 }
781
782 pub fn kind(&self) -> TemplateArtifactKind {
783 self.kind
784 }
785}
786
787#[derive(Debug, Serialize)]
788pub struct PlannedDirectory {
789 pub(crate) path: PathBuf,
790 pub(crate) purpose: String,
791}
792
793impl PlannedDirectory {
794 pub fn path(&self) -> &std::path::Path {
795 &self.path
796 }
797
798 pub fn purpose(&self) -> &str {
799 &self.purpose
800 }
801}
802
803#[derive(Debug, Serialize)]
804pub struct PlannedWrite {
805 pub(crate) path: PathBuf,
806 pub(crate) purpose: String,
807 pub(crate) content: String,
808}
809
810impl PlannedWrite {
811 pub fn path(&self) -> &std::path::Path {
812 &self.path
813 }
814
815 pub fn purpose(&self) -> &str {
816 &self.purpose
817 }
818}
819
820#[derive(Debug, Serialize)]
821pub struct PreservedPath {
822 pub(crate) path: PathBuf,
823}
824
825impl PreservedPath {
826 pub fn path(&self) -> &std::path::Path {
827 &self.path
828 }
829}
830
831#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
832pub struct InitializationResult {
833 pub root: PathBuf,
834 pub folderbase_id: String,
835 pub created_paths: Vec<PathBuf>,
836 pub preserved_paths: Vec<PathBuf>,
837 pub applied_plan_digest: InitializationPlanDigest,
838}
839
840#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
841#[serde(rename_all = "snake_case")]
842pub enum ValidationLevel {
843 Shallow,
844 ContentIntegrity,
845}
846
847#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
848pub struct ValidationReport {
849 pub root: PathBuf,
850 pub level: ValidationLevel,
851 pub valid: bool,
852 pub findings: Vec<ValidationFinding>,
853}
854
855#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
856pub struct ValidationFinding {
857 pub code: String,
858 pub severity: ValidationSeverity,
859 pub path: Option<PathBuf>,
860 pub message: String,
861}
862
863#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
864#[serde(rename_all = "snake_case")]
865pub enum ValidationSeverity {
866 Error,
867 Warning,
868}