Repository navigation
Description
Summary
Launching ProFiles from the Windows Start Menu with no configuration proposes creating .profiles in C:\Windows\System32. It must propose ~/.profiles/.profiles — next to ~/.profiles/profiles.log — and a later Start-Menu launch must load that file automatically.
Problem
A Start-Menu shortcut with an empty "Start in" field runs the process with CWD = %SystemRoot%\System32. When no configuration is found:
- the first-run config modal pre-fills its directory field with
C:\Windows\System32; - clicking Create configuration would write
C:\Windows\System32\.profiles(requires elevation, pollutes a system directory); - the generated starter file would also set
search_dir: C:\Windows\System32, because the template substitutes the process CWD; - the app would scan
C:\Windows\System32on first paint.
Logs are already CWD-independent (default_log_path() returns ~/.profiles/profiles.log), but configuration is not.
There is also a latent collision on launchers whose CWD is the home folder (common on Linux .desktop entries): CWD / ".profiles" resolves to ~/.profiles, which is the log directory, not a config file. Creation then reports "already exists", and the app can treat a directory as its active config path.
Reproduction
- Install the Windows MSI; ensure no
.profilesexists in theC:\Windows\System32subtree. - Launch ProFiles from the Start Menu.
- The web UI opens the Create configuration modal with
C:\WINDOWS\system32pre-filled. - Creating a file there either fails (permissions) or writes
C:\Windows\System32\.profilesand builds a starter whosesearch_diris System32.
A simulated reproduction is enough for tests: monkeypatch.chdir() to a directory representing %SystemRoot%\System32, with Path.home() pointed at a temp folder.
Root cause
resolve_config_path()(src/profiles/launch/resolution.py:57-61) searches only the CWD subtree and returnsNone.ProFileApp._load_configuration()callsload_config(None);load_config()builds defaults fromPath.cwd() / ".profiles"(src/profiles/core/config/loader.py:43-44), soAppConfig.config_pathbecomesC:\Windows\System32\.profiles.BackgroundServercopies that config intoServerState;active_config_path()(src/profiles/server/state.py:59-70) and_config_response()(src/profiles/server/routes/config.py:89-136) report it as the active/expected path withconfig_exists: false.LoadConfigModalpre-fills its directory input from the parent of that path (src/profiles/web/src/components/LoadConfigModal.tsx:45-48).write_starter_config()substitutesPath.cwd()intoSTARTER_CONFIG_TEMPLATEassearch_dir(src/profiles/core/actions.py:317-319).ServerState.active_config_path()can also return an existing directory, because it never checks that the fallback path is a file.
Goals
- A launcher-style launch with no config proposes
~/.profiles/.profiles(same folder asprofiles.log). - Once
~/.profiles/.profilesexists, every later launch — Start Menu included — discovers and loads it. - Terminal/project launches keep the current priority: a project
.profilesfound in the CWD tree wins, and a missing-config proposal stays in the project folder. - A generated starter scans a sensible directory (the active project, or the home folder for launcher starts) — never System32.
- The app never proposes or records a path that is an existing directory as its config file.
Non-goals
- Moving or renaming the log directory.
- Migrating existing configs or rewriting installed shortcuts.
- Writing a config without user consent.
- Changing
--initsemantics (still explicitly "generate in CWD"). - Redesigning the config modal.
Approaches considered
| Approach | Verdict | Why |
|---|---|---|
| A. Per-user config path policy + fallback discovery (chosen) | Adopted | Fixes every launcher (Start Menu, pinned taskbar, Finder, .desktop, future shortcuts), works for existing installs and all launch styles, and removes the home/log-dir collision. |
B. Set the MSI shortcut's "Start in" to %USERPROFILE% |
Rejected alone | Does not fix pinned taskbar, already-installed shortcuts, other launchers, or the CWD=home collision; and it would propose ~/.profiles (the log directory) as a file. |
C. Always create configs in ~/.profiles |
Rejected | Breaks the project-local workflow: a terminal launch in a project without a config should still propose project/.profiles. |
| D. Detect the Start Menu specifically from shortcut metadata | Rejected | Platform-specific and fragile; CWD is the only reliable signal the process receives. |
Design
1. One user-path policy in core
New module src/profiles/core/paths.py:
USER_DATA_DIRNAME = ".profiles".user_data_dir() -> Path→Path.home() / USER_DATA_DIRNAME— single source of truth for both logs and the per-user config.user_config_path() -> Path→user_data_dir() / ".profiles".find_user_config() -> Path | None— checks the canonical names in order (.profiles,.profiles.yaml,.profiles.yml) directly insideuser_data_dir()(depth 0, no wildcard search).is_uninformative_directory(path: Path | None) -> bool— true for:Noneor an unresolvable path;- a filesystem/drive root (
path.parent == path); Path.home()itself;- anything inside
Path(sys.prefix); - anything inside the running executable's directory (packaged app install root);
- on Windows: anything inside
%SystemRoot%/%windir%(coversSystem32,SysWOW64) and%ProgramFiles%/%ProgramFiles(x86)%.
default_config_path(start: Path | None = None) -> Path:- uninformative start →
user_config_path(); - informative start →
start / ".profiles"; - if that candidate exists and is a directory →
user_config_path()(log-dir collision guard).
- uninformative start →
default_search_directory(start: Path | None = None) -> Path:- uninformative start →
Path.home(); - informative start →
start(orPath.cwd()when omitted).
- uninformative start →
src/profiles/launch/context.py::cwd_is_uninformative() delegates to is_uninformative_directory() so launch detection and path policy cannot drift. Existing macOS behavior (/, runtime directory) is preserved; System32 and the home folder become uninformative on every platform.
default_log_path() (src/profiles/core/telemetry/diagnostics.py:266-277) delegates to user_data_dir() so config and logs cannot diverge.
2. Launch resolution: per-user config as the final fallback
resolve_config_path(ctx) becomes:
--config— explicit always wins (unchanged).- An OS-delivered
*.profilesdocument (unchanged). - CWD search, 5 levels — only when the CWD is informative. This deliberately skips
System32and home to avoid walking a system tree or the whole user profile looking for a config. find_user_config()under~/.profileswhen it exists.None.
ProFileApp._resolve_startup_config() additionally returns the launch-default target: default_config_path(ctx.working_directory). _load_configuration() loads resolved or launch_default, so the defaults AppConfig carries the correct target path (~/.profiles/.profiles for launcher starts) without any server-specific override. A missing default is not fatal; the existing is_missing rule still applies only to an explicitly provided path that does not exist.
load_config(None) (CLI/library entry point) applies the same policy: skip the CWD search when uninformative, then try find_user_config(), then load defaults bound to default_config_path().
3. Creation writes the right content
src/profiles/launch/creation.py::propose_creation(target, *, search_dir=None):
- still writes
target / ".profiles", skipping an existing file; - passes
search_dirtowrite_starter_config(..., cwd=search_dir); - default
search_dir:targetfor a normal project directory;default_search_directory()whentargetis the per-user data directory (scanning the folder that only holds logs and configs is useless).
src/profiles/server/routes/config.py:
POST /api/config/create: passsearch_dir=state.active_directory or default_search_directory().POST /api/config/template: usedefault_search_directory(state.active_directory)instead ofPath.cwd()._config_response: the empty-config active-directory fallback becomesdefault_search_directory()(currentlyPath.cwd(), which makes the first paint scan System32).
src/profiles/core/config/loader.py::propose_config_creation() (the interactive CLI helper) targets default_config_path() and uses default_search_directory() for the template.
ServerState.active_config_path(): keep the existing CWD probe, then fall back to default_config_path(); never return an existing directory as the config file.
Behaviour matrix
| Launch source | Project config in CWD tree | ~/.profiles/.profiles |
Result |
|---|---|---|---|
--config PATH |
any | any | PATH wins |
Double-clicked *.profiles |
any | any | document wins |
| Start Menu / launcher (uninformative CWD) | — (search skipped) | missing | defaults; proposal in ~/.profiles |
| Start Menu / launcher | — | exists | user config loaded |
| Terminal in a project | exists | any | project config loaded |
| Terminal in a project | missing | exists | user config loaded (global default) |
| Terminal in a project | missing | missing | defaults; proposal in the project folder |
The global fallback (row 6) is intentional: ~/.profiles/.profiles is the user's default configuration, so behaviour does not change based on whether the app was started from a terminal or a launcher.
Implementation checklist
- Add
src/profiles/core/paths.py(+ exports where appropriate, if any). - Make
default_log_path()delegate touser_data_dir(). - Extend
cwd_is_uninformative()viais_uninformative_directory(). - Update
launch/resolution.py(user fallback, uninformative skip, default target). - Update
app.pystartup resolution/loading to carry the launch default. - Update
launch/creation.pyto pass the startersearch_dir. - Update
core/config/loader.py(load_config,propose_config_creation). - Update
server/state.pyandserver/routes/config.py(fallbacks + template search dir). - Update
STARTER_CONFIG_TEMPLATEdiscovery comment. - Update docs:
docs/configuration-profile.{en,fr}.md,docs/installation-guide.en.md(first-launch paragraph),README.md/README.fr.mdconfig section,CHANGELOG.md. - Update
src/profiles/core/AGENTS.mdand rootAGENTS.mdtrees for the new module.
Tests
- New
tests/core/test_paths.py: user dir/config path; uninformativeNone, root, home,sys.prefix, SystemRoot/ProgramFiles (monkeypatched env); informative temp dir; directory-collision guard;default_search_directory. tests/launch/test_context.py: System32 and home are uninformative; existing macOS/runtime cases unchanged.tests/launch/test_resolution.py: user config fallback; project config beats user config; uninformative CWD skips the tree search; explicit/document still win.tests/launch/test_creation.py: startersearch_diris the target for a project dir and home for~/.profiles.tests/core/config/test_loader.py:load_config()user fallback and default path;propose_config_creation()target.tests/test_app_launch_resolution.py: simulated Start-Menu CWD (System32) →AppConfig.config_path == ~/.profiles/.profiles.tests/server/routes/test_config*.py: GET pre-fill path; create in the user dir; template search dir;ServerStatefallback never returns a directory.- Web: no change required for this issue; the picker pre-fill follows
config_pathautomatically. Optional assertion that the directory input shows~/.profiles.
Acceptance criteria
- With
CWD = %SystemRoot%\System32and an empty home, a simulated launch exposes~/.profiles/.profilesas the config path, pre-fills the modal with~/.profiles, and creating writes~/.profiles/.profileswithsearch_dirpointing at the home folder — nothing is written under System32. - Restarting with the same CWD loads
~/.profiles/.profileswithout prompting. - A terminal launch inside a project with a project
.profilesbehaves exactly as before. - A terminal launch in a project without a config still proposes
project/.profiles. - No code path proposes or records an existing directory as the configuration file.
- Existing Python and web test suites remain green.
Risks / notes
Path.home()can raise in exotic service environments; the logger already depends on it, so this is not a new failure mode, but the path helpers should degrade predictably.- The per-user config is a global fallback for terminal launches too (see matrix row 6). This is intentional; it can be revisited if it proves surprising.
- Users who already created a config under System32 keep it in place; the app will not move or delete it. Since the fix makes System32 uninformative, the new code will not auto-load it from a Start-Menu launch.
Related
- server: GET /api/config first-paint directory selection diverges from launch resolution; GET mutates ServerState; phantom config_path for trials #126 — phantom
config_pathand first-paint directory divergence. - Hygiene: tsconfig.tsbuildinfo is tracked and churns every build; stale log files in web source tree; CWD-relative logger defaults; dead ValidateRequest.filename; AGENTS.md utils tree missing path_utils.py #149 — CWD-relative logger defaults / hygiene sweep.
- Installer polish: Windows MSI options (shortcuts, finish page, PATH option, branding) + macOS DMG branding parity #183 — Windows MSI installer polish (shortcuts live here; this issue deliberately does not depend on changing them).
Activity
fix(launch): treat mounted volumes and app-hosting dirs as uninformative
docs: document the macOS front-Finder-window launch folder (#191)
feat(config): per-user config path policy for launcher launches (#191)
fix(launch): treat mounted volumes and app-hosting dirs as uninformative
docs: document the macOS front-Finder-window launch folder (#191)