feat: add windows launch service - #1441
Conversation
| if result.returncode != 0: | ||
| return ManagerState.UNKNOWN | ||
| values = _list_output(result.stdout) | ||
| status = values.get("status", "").casefold() |
There was a problem hiding this comment.
[P1] On localized Windows installations, /FO LIST localizes the field names as well as the values, but these lookups only accept the English keys status and last result. For example, 状态: 正在运行 is stored under 状态, so manager_state() returns UNKNOWN; the first install then aborts in start(reload_definition=True) before /Run. Please use a locale-independent Task Scheduler state API and add a non-English regression test.
There was a problem hiding this comment.
fixed, now use PowerShell Task Scheduler API
| principal = _child(principals, "Principal") if principals is not None else None | ||
| settings = _child(root, "Settings") | ||
| actions = _child(root, "Actions") | ||
| execute = _child(actions, "Exec") if actions is not None else None |
There was a problem hiding this comment.
[P1] This validates only the first Exec action. Appending a second Exec (for example, cmd.exe) still makes loaded_registration() return OWNED, so a modified task can execute extra commands while passing the status/install/uninstall ownership checks. Please require exactly the expected action, trigger, and principal structure, reject any extras as FOREIGN, and add regression tests for additional elements.
There was a problem hiding this comment.
fixed, now check action、trigger、principal only
| def _validate_windows_protection(path: Path) -> None: | ||
| """Require a Windows ACL limited to the interactive user and trusted OS admins.""" | ||
|
|
||
| account, sid = _windows_user_identity() |
There was a problem hiding this comment.
[P1] This ACL check never verifies the file owner SID. On Windows st_uid is recorded as 0, so a file owned by another account can pass as long as its current DACL contains the allowed principals; that owner can later change the DACL and regain access to the credential file. Please require the current user's owner SID, persist it in the installed identity, and revalidate it on launch.
There was a problem hiding this comment.
fixed, now Windows recheck owner SID
|
|
||
| if start_on_login is None: | ||
| start_on_login = ( | ||
| typer.confirm("Enable automatic Server startup when you log in?", default=False) |
There was a problem hiding this comment.
[P2] Pressing Enter here installs without login auto-start, while the README and English RFC still document bare powercontext service install as enabling startup for future logins; only the Chinese RFC describes this prompt and opt-out. Please choose one default and keep the implementation and both locales in sync.
Which issue or RFC does this PR close?
Closes #1298
Implements RFC 1299.
Rationale for this change
Complete the Windows implementation of the personal Server service lifecycle defined by RFC 1299. Windows users can run PowerContext as a persistent current-user service without administrator privileges or a visible console window.
What changes are included in this PR?
pythonw.exeto avoid opening a visible CMD window.Are there any user-facing changes?
Windows is now supported by
powercontext service install,status, anduninstall.The service runs as the current user through Task Scheduler and does not install a Windows Service or require administrator privileges. Existing service definitions remain compatible.
How was this change tested?
make checkmake docs-testuv run pytest -q tests/test_service.py tests/test_service_environment.py tests/test_system_cli.py4 passed, 1 skippedpowercontext service install --helpAI usage statement
OpenAI Codex