diff --git a/README.md b/README.md index 76910e0..1cb76b8 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,8 @@ The install script verifies the release archive's sha256 and installs `sctl` int 1. **Start the daemon** and leave it running: ```bash - sctl serve + sctl serve # in a terminal, or + sctl service install # in the background, starting at login ``` 2. **Pair the extensions.** `sctl connect` prints a one-time code; each code pairs one extension, so run it once @@ -119,6 +120,7 @@ browser's logins; see [`docs/cli.md`](./docs/cli.md#endpoint-for-playwright-and- | Group | What it does | |---|---| | `sctl serve` / `connect` / `status` / `mcp` | Run the daemon, pair an extension, show connection status, serve MCP over stdio. | +| `sctl service` | Run the daemon in the background as a user service (launchd, systemd, Task Scheduler). | | `sctl get` / `grep` / `install` / `edit` / `enable` / `disable` / `delete` | Manage ScriptCat userscripts. | | `sctl browsers` | List paired sctl Browser instances, or forget one. | | `sctl tabs` / `windows` / `groups` | Tabs, windows, and tab groups. | diff --git a/docs/README_zh-CN.md b/docs/README_zh-CN.md index 5ccdd8d..8dad2b8 100644 --- a/docs/README_zh-CN.md +++ b/docs/README_zh-CN.md @@ -58,7 +58,8 @@ irm https://raw.githubusercontent.com/scriptscat/sctl/main/scripts/install.ps1 | 1. **启动 daemon** 并保持运行: ```bash - sctl serve + sctl serve # 在终端里运行,或者 + sctl service install # 在后台运行,登录后自动启动 ``` 2. **配对扩展。** `sctl connect` 打印一次性配对码;一个码只能配对一个扩展,每个扩展各运行一次。 @@ -109,6 +110,7 @@ ln -s "$PWD/skills/sctl" ~/.claude/skills/sctl | 命令组 | 用途 | |---|---| | `sctl serve` / `connect` / `status` / `mcp` | 运行 daemon、配对扩展、查看连接状态、通过 stdio 提供 MCP。 | +| `sctl service` | 以用户服务的形式在后台运行 daemon(launchd、systemd、任务计划程序)。 | | `sctl get` / `grep` / `install` / `edit` / `enable` / `disable` / `delete` | 管理 ScriptCat 用户脚本。 | | `sctl browsers` | 列出已配对的 sctl Browser 实例,或忘记其中一个。 | | `sctl tabs` / `windows` / `groups` | 标签页、窗口和标签组。 | diff --git a/docs/architecture.md b/docs/architecture.md index ce616b7..6c5cdaf 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -18,7 +18,9 @@ CLI verbs (sctl get / edit / install / browsers / tabs / windows / page / debug `/control/*` HTTP/JSON control API on the daemon's listener — same port as the extensions' WS surface, separate path, authenticated with the control token described in [threat-model.md](./threat-model.md#4-the-control-channel-internal-local-connection-in-detail). Frontends never start `serve`: run it -explicitly in the foreground or let an external system service manager own its lifecycle. +explicitly in the foreground or let the user's system service manager own its lifecycle — `sctl service` +(`internal/client/service`) writes that service definition and drives the manager's own commands; it talks to the +daemon only through the health check and the control token, to tell whether the service's daemon came up. The daemon accepts two kinds of extension connection at once: exactly one active ScriptCat connection (a new one replaces the previous one), and any number of paired `sctl Browser` instances connecting simultaneously, @@ -140,6 +142,7 @@ cmd/sctl/main.go # cobra entry point (unwraps ExitError → os.Exit) internal/cli/ # subcommand definitions; spans both sides, hence top level cli.go # root command, global flags (-o/--output, --log-level), output helpers serve.go # bootstraps the cago app and mounts the daemon Component + service.go # sctl service install|uninstall|start|stop|restart|enable|disable|status mcp.go # sctl mcp (serves all tools; --name is an audit label) connect.go status.go version.go get.go grep.go # read verbs @@ -175,13 +178,14 @@ internal/daemon/ # ── sctl serve side ── internal/client/ # ── sctl mcp / CLI verb side ── control/ # control API client, shared DTOs, control token mcpserver/ # go-sdk stdio MCP server: all tools (flat trust), progress while waiting + service/ # user service definitions (launchd, systemd --user, Task Scheduler) and their commands internal/pkg/ # ── shared by both sides ── protocol/ # protocol.json authority plus generated language and business-schema artifacts protocolschema/ # JSON-RPC parsing and business-schema validation at the untrusted WS boundary audit/ # daemon-side security events (the Event type crosses the control API, hence shared) paths/ # data directory and derived paths - logging/ # unified zap logging (stderr + /logs/*.log, never stdout) + logging/ # unified zap logging (stderr + /logs/*.log; files only under sctl service; never stdout) fsutil/ # atomic file writes extension/ # ── sctl Browser, the second extension kind (MV3, pnpm/Vite/React) ── diff --git a/docs/cli.md b/docs/cli.md index 98089f4..5a5045c 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -11,7 +11,8 @@ command line can use the skill in [`../skills/sctl/`](../skills/sctl/SKILL.md). | Command | Purpose | |---|---| -| `sctl serve` | Run the local bridge daemon. | +| `sctl serve` | Run the local bridge daemon in the foreground. | +| `sctl service install\|uninstall\|start\|stop\|restart\|enable\|disable\|status` | Run `sctl serve` in the background as a user service; see [Background service](#background-service-sctl-service). | | `sctl connect` | Open a one-time enrollment window for ScriptCat or sctl Browser. | | `sctl mcp [--name