Skip to content

Commit 9b68f7d

Browse files
committed
docs: Initial docs for the configuration system
1 parent b93cade commit 9b68f7d

File tree

1 file changed

+219
-0
lines changed

1 file changed

+219
-0
lines changed

docs/configuration.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
## Configuration System Specification for Blocksense Agents-Workflow
2+
3+
### Overview and Goals
4+
5+
The Blocksense Agents-Workflow project uses a layered configuration system to manage settings. Multiple configuration sources (from built-in defaults to user overrides) are merged in priority order to offer flexibility while enabling enterprise control.
6+
7+
- **Multi-layered configuration**: Support settings from defaults, system administrators, user preferences, project-specific configs, environment variables, and command-line flags. Higher-priority layers override lower-priority ones.
8+
- **Admin enforceability**: Allow system administrators to enforce settings that users cannot override.
9+
- **Cross-platform consistency**: Provide a uniform configuration interface across Linux, Windows, macOS, and mobile, while leveraging platform conventions.
10+
- **Declarative, user-friendly format**: Use TOML for config files; validate against a schema.
11+
- **Proven patterns**: Inspired by tools like Git and Visual Studio Code with layered config models ([Git](https://git-scm.com/docs/git-config), [VS Code](https://code.visualstudio.com/docs/getstarted/settings)).
12+
13+
### Configuration Layers and Precedence
14+
15+
Configuration values are loaded from multiple sources in a specific order of precedence (later wins unless enforced):
16+
17+
- **Built-in Defaults**: Safe fallback values baked into the application.
18+
19+
- **System (OS-Level) Configuration**: System-wide/administrator settings for all users on a machine. Example paths:
20+
- Linux: `/etc/xdg/agents-workflow/config.toml` (per [XDG Base Directory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html))
21+
- Windows: `%ProgramData%\\Blocksense\\AgentsWorkflow\\config.toml` (and optionally registry)
22+
- macOS: `/Library/Application Support/Blocksense/AgentsWorkflow/config.toml`
23+
By default, user and project configs can override system config unless marked enforced.
24+
25+
- **User Profile Configuration**: User-specific global preferences:
26+
- Linux/macOS: `~/.config/agents-workflow/config.toml` (XDG)
27+
- Windows: support both `%APPDATA%\\Blocksense\\AgentsWorkflow\\config.toml` and `~/.config/agents-workflow/config.toml`. If both exist, `~/.config/...` takes precedence for consistency.
28+
This layer overrides any non-enforced system settings. This mirrors Git’s global config ([git-config](https://git-scm.com/docs/git-config)).
29+
30+
- **Project Repository Configuration**: Project-provided settings stored in the repository. Agents-Workflow already uses an `.agents` folder; per-project configuration lives in:
31+
- Repository path: `.agents/config.toml`
32+
These settings override user-global preferences because they are more specific.
33+
34+
- **Per-Project User Overrides**: A user may override a project’s settings without changing the repo. Store in the repo but outside version control:
35+
- Repository path: `.agents/local/config.toml` (recommended to be gitignored)
36+
This layer has higher priority than project repository config.
37+
38+
- **Environment Variables**: Session-scoped overrides with the highest non-admin priority. All environment variables are prefixed with `AGENTS_WORKFLOW_`. See Environment Variables below for mapping.
39+
40+
- **Command-Line Arguments (per-setting flags)**: Highest priority. Each setting has its own flag (for example, `--log-level debug`). There is no generic `--config` flag.
41+
42+
**Precedence rule**: Higher-priority layers override lower-priority ones. Composite structures follow schema-defined merge/replace rules; by default a higher layer replaces lower-layer lists/tables.
43+
44+
**Exception — Admin Enforced Settings**: System-level config values can be marked enforced so no lower-priority source (including environment or CLI) can override them. If a user attempts an override, the application warns and retains the enforced value.
45+
46+
### Administrative Enforcement Mechanism
47+
48+
- **Marking values as enforced**: The system config file supports tagging keys as enforced (syntax TBD). Enforced keys are treated as read-only by the app.
49+
- **Override blocking**: Overrides for enforced keys are ignored with a clear message similar to “This setting is enforced by your administrator.”
50+
- **File system protections**: System config paths (e.g., `/etc/xdg`, `%ProgramData%`) require elevated permissions, preventing tampering at the source. Application logic further blocks runtime overrides.
51+
- **Optional policy integration**: Optionally read platform-native policies (Windows Group Policy/Registry, macOS configuration profiles) as system-level enforced config.
52+
53+
### Cross-Platform Considerations
54+
55+
- **Linux/Unix**: Follow XDG conventions. System config in `$XDG_CONFIG_DIRS/agents-workflow/config.toml` (default `/etc/xdg`), user config in `$XDG_CONFIG_HOME/agents-workflow/config.toml` (default `~/.config/agents-workflow/config.toml`). Project config discovery traverses parents to find `.agents/config.toml` (inspired by [Cargo config discovery](https://doc.rust-lang.org/cargo/reference/config.html)).
56+
57+
- **Windows**: Primary user config may be either `%APPDATA%\\Blocksense\\AgentsWorkflow\\config.toml` or `~/.config/agents-workflow/config.toml`. For users who prefer consistency, `~/.config/...` is supported on Windows and takes precedence if both exist. System-wide config lives under `%ProgramData%\\Blocksense\\AgentsWorkflow\\config.toml`. Optional registry integration (e.g., `HKLM\\Software\\Blocksense\\AgentsWorkflow\\...`) can supply policies.
58+
59+
- **macOS**: Support XDG when set, otherwise use `~/Library/Application Support/Blocksense/AgentsWorkflow/config.toml` for user and `/Library/Application Support/Blocksense/AgentsWorkflow/config.toml` for system. Managed profiles are treated as system enforced.
60+
61+
- **Mobile (iOS/Android)**: No filesystem/env/CLI. Defaults compiled in, managed config via MDM, user preferences via in-app settings. The conceptual precedence remains the same.
62+
63+
### Configuration File Format (TOML) and Schema
64+
65+
All persistent configuration files use TOML. Configuration is validated against a versioned schema.
66+
67+
- **Example**:
68+
69+
```toml
70+
[core]
71+
projectRoot = "/home/user/myproj"
72+
timeout = 30
73+
74+
[features]
75+
enableX = true
76+
enableY = false
77+
78+
[network]
79+
apiUrl = "https://api.example.com"
80+
```
81+
82+
- **Merging logic**:
83+
- Simple values: higher-priority value overwrites lower.
84+
- Tables/arrays: higher-priority replaces by default; selective merging may be defined per key in the schema.
85+
- **Validation and errors**: Files with invalid types/keys are rejected with helpful messages.
86+
87+
### Command-Line Interface for Settings (no generic --config)
88+
89+
There is no `--config` key=value flag. Each setting has a dedicated flag. Mapping rules:
90+
91+
- **Mapping**: TOML key `a.b.c` → CLI flag `--a-b-c`.
92+
- **Booleans**: `--feature-x` to enable, `--no-feature-x` to disable (if applicable).
93+
- **Examples**:
94+
- `--log-level debug`
95+
- `--timeout 45`
96+
- `--network-api-url https://corp.example.com`
97+
98+
CLI flags have the highest priority (unless an admin-enforced value exists).
99+
100+
### Environment Variables (prefix: AGENTS_WORKFLOW_)
101+
102+
All environment variables are prefixed with `AGENTS_WORKFLOW_` for clarity in scripts and CI.
103+
104+
- **Mapping**: TOML key `a.b.c` → env var `AGENTS_WORKFLOW_A_B_C`.
105+
- **Characters**: Dots and hyphens become underscores; names are uppercased.
106+
- **Examples**:
107+
- `AGENTS_WORKFLOW_LOG_LEVEL=debug`
108+
- `AGENTS_WORKFLOW_TIMEOUT=45`
109+
- `AGENTS_WORKFLOW_NETWORK_API_URL=https://corp.example.com`
110+
111+
Environment variables override file-based configuration for that process (unless enforced).
112+
113+
### Project and Per-Project User Configuration
114+
115+
Agents-Workflow stores per-project configuration under the repository’s `.agents` directory:
116+
117+
- **Project config (shared)**: `.agents/config.toml` (committed to VCS).
118+
- **User override (local)**: `.agents/local/config.toml` (gitignored), higher priority than project config.
119+
120+
This replaces earlier proposals like `.agents-workflow.toml` to consolidate project settings in one folder already used by the tool.
121+
122+
### Configuration Discovery, Provenance, and Debugging
123+
124+
The configuration loader records the origin of every setting (file path, environment variable name, CLI flag) and whether it is enforced.
125+
126+
- **Debug logging**: When log level is `debug`, CLI tools report which config files/directories they attempt to read and which were found/loaded, in precedence order.
127+
- **Explain resolution**: When querying a setting, a detailed report shows all occurrences across layers and explains which source won and why (including enforcement).
128+
129+
### Git-like Configuration Command
130+
131+
Provide a dedicated command to read and modify configuration, inspired by `git config`. Example interface (command name illustrative):
132+
133+
```bash
134+
agents-workflow config get core.timeout --explain
135+
agents-workflow config set core.timeout 45 --scope user
136+
agents-workflow config set network.apiUrl https://corp.example.com --scope system --enforced
137+
agents-workflow config list --scope project --show-origin
138+
agents-workflow config unset features.enableY --scope project-user
139+
```
140+
141+
- **Scopes**: `system`, `user`, `project` (repo `.agents/config.toml`), `project-user` (repo `.agents/local/config.toml`).
142+
- **Show origin**: `--show-origin` displays file paths or `ENV/CLI` for values; `--explain` prints a merge trace and enforcement notes.
143+
- **Windows behavior**: For `--scope user` on Windows, reads both `%APPDATA%` and `~/.config`; writes default to `~/.config/agents-workflow/config.toml` unless `--win-appdata` is specified.
144+
145+
### Editor experience in `agent-task`
146+
147+
The `agent-task` command opens an editor for the task description. The loaded buffer contains commented guidance and indicates the action to be executed after the editor closes. This action depends on configuration, and the template must include the configuration source responsible for it.
148+
149+
Example template (comments start with `#`):
150+
151+
```text
152+
# Blocksense Agents-Workflow: Describe the task to perform below the separator.
153+
# Lines starting with '#' are ignored.
154+
#
155+
# After you save and close, the following action will run:
156+
# start-work
157+
# (source: project config at .agents/config.toml)
158+
#
159+
# You can change the default action via either:
160+
# - CLI: --action <start-work|get-task|...>
161+
# - Config key: core.defaultAction (see agents-workflow config --help)
162+
---
163+
164+
```
165+
166+
This requires configuration provenance to be preserved so the editor can display the setting’s origin.
167+
168+
### User Experience and Examples
169+
170+
- **Out-of-the-box defaults**: The internal defaults are used when no config is present.
171+
172+
- **User-level customization**: Add preferences to `~/.config/agents-workflow/config.toml`. Example:
173+
174+
```toml
175+
[core]
176+
editor = "vim"
177+
maxAgents = 10
178+
```
179+
180+
- **Project-specific config (maintainer)**: Commit `.agents/config.toml`:
181+
182+
```toml
183+
[features]
184+
enableY = true
185+
```
186+
187+
- **Project-specific user override**: Create `.agents/local/config.toml` (gitignored):
188+
189+
```toml
190+
[features]
191+
enableY = false
192+
```
193+
194+
- **Admin enforcement**: In `/etc/xdg/agents-workflow/config.toml`, set and enforce:
195+
196+
```toml
197+
[network]
198+
apiUrl = "https://corporate-proxy.example.com"
199+
enforced = true # syntax illustrative
200+
```
201+
202+
CLI attempts like `--network-api-url https://other.example.com` or `AGENTS_WORKFLOW_NETWORK_API_URL=...` are ignored with a clear message.
203+
204+
- **One-off overrides**:
205+
- Environment: `AGENTS_WORKFLOW_LOG_LEVEL=debug agent-task ...`
206+
- CLI: `agent-task --log-level debug ...`
207+
208+
### Inspiration and Analogous Systems
209+
210+
- **Git**: hierarchical config ([docs](https://git-scm.com/docs/git-config)).
211+
- **VS Code**: user/workspace settings with precedence ([docs](https://code.visualstudio.com/docs/getstarted/settings)).
212+
- **Cargo**: TOML config, discovery, env var overrides ([docs](https://doc.rust-lang.org/cargo/reference/config.html)).
213+
- **XDG Base Directory & FHS**: standard file locations ([spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)).
214+
215+
### Conclusion
216+
217+
Agents-Workflow provides a layered, schema-validated configuration system with clear precedence, robust admin enforcement, and full provenance. Environment variables use the `AGENTS_WORKFLOW_` prefix; CLI uses per-setting flags only. Windows supports `~/.config` alongside `%APPDATA%`, with `~/.config` taking precedence when both are present. Project configuration is consolidated under `.agents/`. A Git-like configuration command and debug logging make configuration behavior transparent and explainable.
218+
219+

0 commit comments

Comments
 (0)