Skip to content

Per-user config path policy + config picker Load mode (#191, #192) - #195

Open
falbany wants to merge 6 commits into
mainfrom
fix/191-192-user-config-and-picker-mode
Open

falbany wants to merge 6 commits into
mainfrom
fix/191-192-user-config-and-picker-mode

Conversation

@falbany

@falbany falbany commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Summary

One PR closing two related configuration-startup issues:

Per-user config path policy (#191)

New profiles.core.paths module — single source of truth for user-level locations:

Helper Behavior
user_data_dir() / user_config_path() ~/.profiles and ~/.profiles/.profiles; default_log_path() now delegates so logs and config can't drift
find_user_config() canonical names (.profiles, .profiles.yaml, .profiles.yml) at depth 0 in the data dir
is_uninformative_directory() None, drive roots, home itself, sys.prefix, the executable's dir, %SystemRoot%/%windir%/%ProgramFiles% when set (env-driven, so tests are portable)
default_config_path(start) uninformative start → per-user path; informative start → start/.profiles, unless that candidate is an existing directory (the CWD == home log-dir collision)
default_search_directory(start) informative start → itself; otherwise home — a starter never scans System32

Wiring:

  • launch/resolution.py: CWD tree search is skipped for uninformative directories (no walking System32 / the whole home profile); per-user config is the final fallback (behaviour matrix from the issue, incl. intentional row 6: terminal launch in a project without a project config loads the user default).
  • app.py: _resolve_startup_config() returns the launch-default target too; _load_configuration() binds the defaults AppConfig to it, so the UI pre-fills ~/.profiles for launcher starts with no server-specific override.
  • core/config/loader.py: load_config() follows the same policy; propose_config_creation() targets the policy default (and creates the data dir first — a bug the new tests caught).
  • launch/creation.py: propose_creation(target, search_dir=...) — creating inside ~/.profiles drafts a starter scanning the home folder, not the data dir.
  • server/state.py: active_config_path() keeps the CWD probe, falls back to default_config_path(), and never returns an existing directory as the config file.
  • server/routes/config.py: /create passes the session's search dir (or the policy default), /template and the empty-config first-paint fallback use default_search_directory() instead of the raw CWD.
  • STARTER_CONFIG_TEMPLATE DISCOVERY comment documents the new order.

Config picker mode (#192)

App.tsx replaces the showConfigPicker boolean with configPickerMode: "load" | "create" | null (null = closed). The caller owns the intent:

Entry point Mode
First-run auto-prompt (config_exists: false) Create (unchanged)
Editor header Load config file… Load
FileList Choose configuration Load

LoadConfigModal takes an explicit mode prop (ConfigPickerMode) and stops inferring from configExists; title, banner and primary button all follow it. onLoaded/onClose behavior unchanged (editor reload key still bumps, issue #101). No server/API change.

Verification

  • Python: pytest 1626 passed, 1 skipped; coverage 88.6% (≥ 85 gate); pylint 9.88/10; ruff check + ruff format --check clean.
    • New tests/core/test_paths.py (29 tests); extensions to tests/launch/{test_context,test_resolution,test_creation}.py, tests/core/config/test_loader.py, tests/server/routes/test_config*.py, tests/test_app_launch_resolution.py — incl. the simulated Start-Menu repro (monkeypatch.chdir to a fake %SystemRoot%\System32, Path.home() → temp): resolution proposes ~/.profiles/.profiles, nothing is written under System32, relaunch loads the user config.
  • Web: vitest 393 passed (32 files) — new LoadConfigModal.test.tsx unit suite (mode prop both ways, disabled-until-selected, create/load actions) + two App.configEditor.test.tsx integration regressions (first-run Create → close → editor entry opens Load; FileList entry opens Load); tsc -b clean; npm run build regenerated dist/ (committed).
  • Real browser (server-only on :8089, no-config session): first-run picker opens Create configuration; Cancel → status-bar Config → editor → Load config file… opens Load configuration with the load primary button and no create banner; picker pre-fill follows the config path's parent.

Notes / decisions

  • The minified web bundle crossed the pre-commit check-added-large-files line (1 MB), so the hook now exempts the tracked src/profiles/web/dist/ build output (generated artifact, not hand-edited source).
  • Docs updated: docs/configuration-profile.{en,fr}.md, docs/installation-guide.en.md (first-launch paragraph), README.md / README.fr.md config sections, CHANGELOG.md, plus the AGENTS.md / core/AGENTS.md / tests/AGENTS.md trees for the new module.
  • Users who already created a config under System32 keep it in place; the app never moves or deletes files, and since System32 is now uninformative it won't be auto-loaded from a Start-Menu launch.

Launcher-style launches (Start Menu, pinned taskbar, .desktop entries)
run with an uninformative CWD — System32, the home folder, or an
install/runtime directory — and used to propose creating .profiles in
that system directory, with a starter scanning it.

New profiles.core.paths module is the single source of truth:

- user_data_dir() / user_config_path(): ~/.profiles shared by logs and
  the per-user default config (default_log_path now delegates).
- find_user_config(): canonical names at depth 0 in the data dir.
- is_uninformative_directory(): None, filesystem roots, home itself,
  sys.prefix, the executable's directory, and %SystemRoot%/%windir% /
  %ProgramFiles% when set (env-driven so tests are portable).
- default_config_path(): uninformative start or a directory collision
  (CWD == home vs the ~/.profiles log dir) falls back to the per-user
  path; informative starts propose in place.
- default_search_directory(): home for launcher starts, never System32.

Wiring: launch resolution skips the CWD tree search for uninformative
directories and falls back to the user config; app startup binds the
defaults AppConfig to the policy-chosen path; load_config() and
propose_config_creation() follow the same policy; ServerState
.active_config_path() never returns an existing directory; the server's
create/template endpoints and empty-config first paint use
default_search_directory. STARTER_CONFIG_TEMPLATE discovery comment
documents the new order.

Closes #191
)

With no active configuration, the editor's "Load config file…" and the
file list's "Choose configuration" buttons opened the picker in Create
mode: App kept a single showConfigPicker boolean with no record of why
the picker opened, and LoadConfigModal inferred its mode from the global
config state (configExists === false), so every entry point rendered
Create whenever the session had no config.

App now carries the intent explicitly: configPickerMode is
"load" | "create" | null (null = closed). The first-run auto-prompt
(initializeFromConfig) is the only entry point that opens "create";
both explicit actions open "load". LoadConfigModal takes that mode as a
prop and stops consulting configExists; title, banner and primary
button follow it.

No server/API change; onLoaded/onClose behavior unchanged (editor
reload key still bumps on pick, issue #101).

Closes #192
Fresh vite build (tsc -b && vite build) serving the Load-mode picker
fix; regenerated PWA precache hashes.

The minified bundle crossed the pre-commit large-file line (1 MB), so
check-added-large-files now exempts the tracked dist/ build output —
it is a generated artifact, not hand-edited source.
CI's pyright flagged Path|None operand/return types in
default_config_path/default_search_directory: the CWD fallback hid the
None case from the type checker. A shared _effective_start() helper
resolves the start (or CWD) once, and the explicit None checks narrow
before use. Behavior unchanged.
macOS user report on this branch: launching the packaged app from a
mounted DMG proposed creating the configuration in
/Volumes/ProFiles <version> — the DMG volume root leaked through as an
informative launch folder. Two mechanisms deliver it, both fixed:

- The macOS Finder probe mirrors the FRONT FINDER WINDOW, which for a
  GUI launch is often the folder the user launched FROM (the DMG
  folder, /Applications, a portable-apps folder). The probe result now
  passes the same uninformative-directory policy as a CWD before being
  trusted; a rejected probe falls back to the plain CWD.
- is_uninformative_directory() gains two rules: volume mount points
  (device id differs from parent — a DMG, USB stick or network share
  top-level is never a project location, consistent with drive roots),
  and any directory hosting the running packaged app bundle
  (Something.app/Contents on macOS). Dev runs are exempt: plain-venv
  interpreter paths carry no .app/Contents component, so a repo
  hosting .venv stays a legitimate project folder.

A DMG launch now falls back to the per-user proposal
(~/.profiles/.profiles) and scans the home folder, matching the
launcher rows of the issue #191 behaviour matrix.
@falbany

falbany commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Follow-up fix pushed (fcfe5aa) for a macOS DMG launch report on this branch's build (0.12.0b1.dev108): running the app from a mounted disk image proposed creating the configuration in /Volumes/ProFiles <version> — the DMG volume root leaked through as an informative launch folder.

Two mechanisms delivered that path, both now fixed:

  1. The Finder probe mirrors the front Finder window — which for a GUI launch is often the folder the user launched from (the DMG folder, /Applications, a portable-apps folder). The probe result now passes the same uninformative-directory policy as a CWD before being trusted; a rejected probe falls back to the plain CWD.
  2. is_uninformative_directory() gains two rules: volume mount points (device id differs from parent — a DMG, USB stick or network share top-level is never a project location, consistent with drive roots), and any directory hosting the running packaged app bundle (Something.app/Contents on macOS). Dev runs are exempt — a plain-venv interpreter path carries no .app/Contents component, so a repo hosting .venv stays a legitimate project folder.

A DMG launch now falls back to the per-user proposal (~/.profiles/.profiles) and scans the home folder, matching the launcher rows of the #191 behaviour matrix. +14 tests (mount points, app-bundle hosting, probe filtering, DMG end-to-end); all local gates re-run green.

Finder and Dock launches on macOS inherit no working directory, so
ProFiles adopts the front Finder window's folder as the launch folder:
a project window proposes its .profiles, while an unrelated ordinary
window (e.g. the folder holding the DMG installer) is proposed instead.
Documented the behavior and the practical escape hatches (close the
window, or use the picker's Home button) in both configuration-profile
guides, both installation guides, and both READMEs; the FR install
guide also gains the per-user first-launch paragraph it was missing.
@falbany

falbany commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

I installed the msi program on windows, then launched the app.
an unexpected error appeared with the following content :

Traceback (most recent call last):
File "\app\profiles_main_.py", line 27, in
from profiles.app import main # noqa: E402
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\app\profiles\app.py", line 17, in
from profiles.core import AppConfig, actions, load_config
File "\app\profiles\core_init_.py", line 16, in
from profiles.core.actions import (
...<7 lines>...
)
File "\app\profiles\core\actions.py", line 20, in
from profiles.core.config.io.yaml_io import write_text_atomic
File "\app\profiles\core\config_init_.py", line 19, in
from profiles.core.config.loader import load_config, propose_config_creation
File "\app\profiles\core\config\loader.py", line 16, in
from profiles.core.config.models import AppConfig
File "\app\profiles\core\config\models.py", line 16, in
from profiles.core.config.schema import MatchCriteriaSchema
File "\app\profiles\core\config\schema.py", line 16, in
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
File "\app_packages\pydantic_init_.py", line 5, in
from .migration import getattr_migration
File "\app_packages\pydantic_migration.py", line 5, in
from pydantic.warnings import PydanticDeprecatedSince20
File "\app_packages\pydantic\warnings.py", line 5, in
from .version import version_short
File "\app_packages\pydantic\version.py", line 7, in
from pydantic_core import version as pydantic_core_version
File "\app_packages\pydantic_core_init
.py", line 6, in
from typing_extensions import Sentinel
File "\app_packages\typing_extensions.py", line 4017, in
_CapsuleType = getattr(_types, "CapsuleType", None)
File "types.py", line 341, in getattr
ModuleNotFoundError: No module named '_socket'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant