Elffuss BraidHub

kikocis/continue public

main · 5.2 KiBRenderedRawPermalink
1# Configuration Loading Behavior Specification
2
3## Overview
4
5This document specifies the behavior of the CLI's configuration loading system, including precedence rules, authentication interactions, and error handling.
6
7## Authentication Precedence
8
9**Authentication Source Priority:**
10
111. **Environment Variable**: `CONTINUE_API_KEY` environment variable
122. **File-Based Auth**: `~/.continue/auth.json` file
133. **No Authentication**: Unauthenticated mode
14
15**Authentication Effects:**
16
17- **Environment Auth**: Always uses personal organization, no config URI persistence
18- **File Auth**: Supports organizations, persists config URIs, token refresh
19- **No Auth**: Limited to default assistant, no personalization
20
21## Configuration Source Precedence
22
23**When CLI is invoked, config source is determined in this order:**
24
251. **CLI `--config` Flag** (highest priority)
26
27 - File path (starts with `.`, `/`, `~`): Loads local YAML file
28 - Assistant slug (`owner/package`): Fetches from Continue platform
29 - Overrides any saved preferences
30
312. **Saved Config URI** (if no `--config` flag)
32
33 - Retrieved from authentication config
34 - Converts `file://` URIs back to file paths
35 - Converts `slug://` URIs back to assistant slugs
36
373. **Default Resolution** (if no flag and no saved URI)
38 - **Authenticated**: First user assistant from `listAssistants()`
39 - **config.yaml**: The saved config file at `~/.continue/config.yaml`
40 - **Unauthenticated**: Falls back to `continuedev/default-agent`
41
42## Authentication State Interactions
43
44### Authenticated Users
45
46**Available Options:**
47
48- Personal assistants
49- Organization assistants (if organization selected)
50- Local YAML files
51- Public assistants
52
53**Behavior:**
54
55- `listAssistants()` returns personalized results
56- Config selections are saved as URIs in auth config
57- Organization context affects available assistants
58
59### Unauthenticated Users
60
61**Available Options:**
62
63- Local YAML files only
64- Default assistant (`continuedev/default-agent`)
65
66**Behavior:**
67
68- No access to personal or organization assistants
69- No config URI persistence
70- Direct fallback to default when no config specified
71
72### Environment Variable Auth (`CONTINUE_API_KEY`)
73
74**Behavior:**
75
76- Treated as authenticated for API access
77- Always uses personal organization context
78- No persistence of config URIs
79- Cannot switch organizations
80
81## Organization Context
82
83**Organization Selection:**
84
85- **Interactive Mode**: Auto-selects first available organization
86- **Headless Mode**: Defaults to personal organization
87- **Environment Auth**: Always personal organization
88
89**Effects on Config Loading:**
90
91- Organization ID passed to all API calls
92- Affects which assistants appear in `listAssistants()`
93- Organization changes trigger complete config reload
94
95## Error Handling Behavior
96
97### Config Loading Errors
98
99**File Not Found:**
100
101- Local file specified but doesn't exist
102- **Result**: Error thrown, CLI exits
103
104**Invalid YAML:**
105
106- Local file exists but has syntax errors
107- **Result**: Parsing error thrown, CLI exits
108
109**Network Failures:**
110
111- API calls fail for assistant slugs
112- **Result**: Network error bubbled up, CLI exits
113
114**Assistant Not Found:**
115
116- Valid slug format but assistant doesn't exist
117- **Result**: 404 error from API, CLI exits
118
119### Fallback Scenarios
120
121**No User Assistants:**
122
123- Authenticated user has no personal assistants
124- **Result**: Falls back to `continuedev/default-agent`
125
126**Default Agent Unavailable:**
127
128- Fallback to default agent fails
129- **Result**: Error thrown, CLI cannot start
130
131**Token Expired:**
132
133- Saved auth token is expired
134- **Result**: Automatic refresh attempted, re-auth required if refresh fails
135
136## Config URI Persistence
137
138**When URIs are Saved:**
139
140- Any successful config load via service layer
141- File paths converted to `file://path/to/config.yaml`
142- Assistant slugs converted to `slug://owner/package`
143
144**When URIs are NOT Saved:**
145
146- Environment variable authentication in use
147- Config loading failures
148- Unauthenticated sessions
149
150## Rule Integration
151
152**Rule Processing:**
153
154- `--rule` flags processed independently of config loading
155- Multiple rules supported, injected into system message
156- Rule failures are warnings, don't prevent config loading
157- Rule sources: file paths, hub slugs, direct strings
158
159## Session Continuity
160
161**Next Session Behavior:**
162
163- **With Saved URI**: Uses saved config automatically
164- **CLI Override**: `--config` flag overrides saved URI and updates it
165- **Config Switching**: UI actions update saved URI for future sessions
166
167**Cross-Session State:**
168
169- Authentication persists until logout
170- Organization selection persists
171- Config URI persists (except for environment auth)
172
173## Complete Decision Flow
174
175```
1761. Parse CLI arguments
1772. Load authentication state (env var > file > none)
1783. Determine config source:
179 - CLI --config flag provided? Use it
180 - Saved config URI exists? Use it
181 - Default resolution based on auth state
1824. Load configuration:
183 - File path? Parse YAML locally
184 - Assistant slug? Fetch from API
185 - Default resolution? List assistants or use default
1865. Process and inject rules
1876. Save config URI (if authenticated via file)
1887. Initialize services with loaded config
189```
190
191This behavior ensures users get predictable config loading with clear precedence rules while maintaining session continuity and graceful fallbacks.