1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! User configuration schema and validation.
use std::collections::BTreeMap;
use std::path::Path;
use serde::{Deserialize, Serialize};
use crate::source::{SourceConfig, SourceKind};
/// Current persisted config schema version.
pub const CONFIG_VERSION: u32 = 2;
/// User-authored dalo configuration.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct UserConfig {
/// Persisted schema version.
pub version: u32,
/// User-level settings.
pub settings: Settings,
/// Configured sources in priority order.
pub sources: Vec<SourceConfig>,
/// Direct user plugin selections.
#[serde(default)]
pub plugins: PluginConfig,
/// Explicit local plugin policy decisions.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub plugin_policy: Vec<PluginPolicy>,
/// Declared skill selectors of the project this store belongs to, keyed by
/// source ID. `Some` marks a project store, identified by its ownership
/// receipt when the store is read; the selectors come from the adjacent
/// `dalo-project.toml`. Never persisted.
///
/// Project resolution ignores every plugin selection and delivers no
/// catalog skill beyond these selectors and their required closure,
/// whatever approvals or source trust exist in that store.
#[serde(skip)]
pub project_selections: Option<BTreeMap<String, ProjectSelection>>,
}
/// One source's selectors and optional path root from a project declaration.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectSelection {
/// Selectors exactly as written in the declaration.
pub skills: Vec<String>,
/// Explicit repository-relative root for path selectors.
pub path: Option<String>,
}
/// Local plugin selection settings.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct PluginConfig {
/// Sorted set of canonical `<source-id>:<selector>` references.
pub direct: Vec<String>,
}
/// Explicit user-local plugin policy decision.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PluginPolicy {
/// Policy layer; version 2 accepts only `user_local`.
pub layer: PluginPolicyLayer,
/// Stable lower-kebab rule identity.
pub rule_id: String,
/// Canonical source-qualified plugin reference.
pub plugin: String,
/// Version 2 accepts only decline.
pub decision: PluginPolicyDecision,
/// Required human audit context.
pub reason: String,
}
/// Supported plugin policy layer.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PluginPolicyLayer {
/// Policy authored in the local user config.
UserLocal,
}
/// Supported plugin policy decision.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PluginPolicyDecision {
/// Keep intent and origins visible but suppress plugin activation.
Decline,
}
/// User-level settings.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Settings {
/// Whether scheduled autosync is enabled.
pub autosync: bool,
/// Optional sync interval label.
#[serde(skip_serializing_if = "Option::is_none")]
pub sync_interval: Option<String>,
}
impl UserConfig {
/// Build the default config for a newly initialized store.
#[must_use]
pub fn default_for_store(store_root: &Path) -> Self {
let local_path = store_root.join("local");
Self {
version: CONFIG_VERSION,
settings: Settings {
autosync: false,
sync_interval: None,
},
sources: vec![SourceConfig {
id: "local".to_owned(),
kind: SourceKind::Local,
path: local_path,
subpath: None,
priority: 0,
namespace: None,
enabled: true,
trusted: true,
url: None,
branch: None,
update_policy: None,
selection: Vec::new(),
declared_by: None,
declared_ref: None,
}],
plugins: PluginConfig::default(),
plugin_policy: Vec::new(),
project_selections: None,
}
}
/// Whether this configuration was read from a project store.
#[must_use]
pub const fn is_project_store(&self) -> bool {
self.project_selections.is_some()
}
}