@agentknight/client 0.9.47 → 0.9.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,305 +1,324 @@
1
- # AgentKnight
2
-
3
- AgentKnight PC Agent connects local coding-agent sessions to an AgentKnight
4
- Relay Server through Copilot, PI SDK, or ACP adapters.
5
-
6
- ## Embed
7
-
8
- Use `@agentknight/sdk` to embed the PC Agent runtime in a Node.js application
9
- without running the CLI or its local management service.
10
- Call `initialize` with an explicit absolute `dataDirectory` and the connection,
11
- identity and logging options, then manage the returned runtime with `start` and
12
- `stop`. The SDK does not select `~/.ak` or read the CLI configuration for you.
13
- Do not share a data directory between running instances.
14
-
15
- The CLI depends on the SDK; both use the same release version. The SDK can be
16
- published independently through the [npm release workflow](../../.github/workflows/agentknight-npm-publish.yml).
17
- See the [SDK entry point](../../shared/sdk/src/index.ts) for the public API.
18
-
19
- ## Run
20
-
21
- Use the Node.js version required by [package.json](package.json) and authenticate
22
- the coding agents you want to use.
23
-
24
- ```powershell
25
- npx @agentknight/client --env C:\path\to\agentknight.env
26
- ```
27
-
28
- Or install it globally:
29
-
30
- ```powershell
31
- npm install --global @agentknight/client
32
- agentknight --env C:\path\to\agentknight.env
33
- ```
34
-
35
- To switch from the unscoped `agentknight` package, stop the Agent and its service,
36
- run `npm uninstall --global agentknight`, then install `@agentknight/client` as
37
- above. The command remains `agentknight`; keep the existing data home and
38
- configuration. Re-register services that pin the old package path before
39
- restarting. Updating the old package does not migrate it to the new name.
40
-
41
- `AGENTKNIGHT_HOME` selects the PC data home, defaulting to `~/.ak`. Without
42
- `--env`, AgentKnight reads `<home>/agentknight.env`, with process settings taking
43
- precedence. With `--env`, the selected file is authoritative for PC settings:
44
- missing settings use defaults or fail validation, rather than inheriting old
45
- Relay credentials, machine names or data paths. OS and external provider
46
- environment variables are retained; explicitly supplied file values override them.
47
- Set custom `AGENTKNIGHT_HOME` in that file as well so restarts use the same home.
48
-
49
- `COPILOT_REMOTE_HOME` and `AGENTKNIGHT_PI_DIRECTORY` are deprecated input aliases
50
- for `AGENTKNIGHT_HOME` and PI's native `PI_CODING_AGENT_DIR`. Conflicting aliases
51
- in the same source are rejected. New configuration and restart metadata use only
52
- the canonical names. PI's native tilde, file URL and Windows shell path syntax
53
- is preserved; an explicitly empty PI directory selects its native default.
54
-
55
- The first normal startup can import legacy working-directory `.env` files or
56
- the old macOS service configuration into `~/.ak/agentknight.env`. Conflicting
57
- legacy values require selecting or reconciling the correct file; no source
58
- silently wins. A selected custom home does not import another home's settings.
59
- Status and upgrade commands do not import or migrate configuration.
60
-
61
- A legacy `~/.copilot-remote` home is copied only while the old Agent is stopped,
62
- preserving its machine identity, pairing keys and saved state. The stable device
63
- ID now lives in `<home>/device-id` alongside `device.json`; existing identities
64
- are preserved when importing a retired client layout's ID. Fresh custom homes have
65
- independent identities. No retired client directory or compatibility symlink is
66
- created. Conflicting identities or homes require manual resolution, not an
67
- automatic reset. Retained legacy files are rollback copies, never dual-written;
68
- remove them only after verifying the migrated installation while old agents are stopped.
69
-
70
- Diagnostic JSONL files are under `<data-home>/logs/<version>/`. Existing
71
- unversioned logs remain historical files; they are not assigned an invented
72
- version. The local pairing page shows the running version, last successful
73
- upgrade time, configuration location, and Relay URL.
74
-
75
- ## Status and upgrades
76
-
77
- ```powershell
78
- agentknight --version
79
- agentknight status
80
- agentknight status --json
81
- agentknight upgrade --check
82
- agentknight upgrade
83
- ```
84
-
85
- `upgrade` uses the latest published version; `upgrade <version>` selects an exact
86
- newer version. Self-upgrade requires a global npm installation, not an `npx`
87
- cache or source checkout. Install a release containing this command through npm
88
- before using it for subsequent upgrades.
89
-
90
- Package resolution and installation try the official npm registry first, then
91
- the Tencent npm mirror for network failures. Existing npm/proxy configuration
92
- is respected without changing global settings. Archives and dependencies for
93
- both the target and rollback are prepared before stopping the running Agent.
94
-
95
- An independent worker waits for idle and performs the switch. Windows scheduled
96
- tasks and the supplied macOS LaunchAgent retain their existing configuration;
97
- foreground instances restart in the background. Persist their configuration and
98
- provider credentials in the environment file before upgrading; shell-only values
99
- that cannot be restored cause the upgrade to be refused. A stopped installation
100
- remains stopped. User-level installations do not require elevation; protected npm
101
- prefixes or service definitions need their existing permissions.
102
-
103
- The command reports the handoff, not successful completion. Use `status` to see
104
- the persistent result if the initiating connection closes. An Agent that remains
105
- busy is left running. Startup failure triggers an offline rollback; readiness
106
- requires the new instance's registration and initial synchronization, not merely
107
- an HTTP health response. Upgrading briefly interrupts the PC connection and does
108
- not migrate an active model turn between processes.
109
-
110
- Successful upgrades remove their temporary installation materials. Failed jobs
111
- retain their diagnostic files under `<data-home>/upgrades`; the last successful
112
- upgrade timestamp changes only after recovery is confirmed.
113
-
114
- ## Configuration
115
-
116
- Create the environment file from the
117
- [PC Agent example](https://github.com/hydraxman/AgentKnight/blob/main/clients/pc-agent/.env.example).
118
-
119
- `RELAY_URL` is used for HTTP APIs and Socket.IO, so an `https://` URL enables
120
- HTTPS and WSS for the entire PC Agent connection. `AGENTKNIGHT_MACHINE_NAME`
121
- controls the PC name shown to mobile clients. The selection and pairing webpage
122
- listens only on loopback; `PAIRING_PAGE_PORT` changes its local port.
123
-
124
- Repository checkouts also include Windows Scheduled Task and macOS LaunchAgent
125
- installers under `clients/pc-agent/scripts`. Services use the same canonical
126
- configuration as the CLI, not a copied environment file. Service support files
127
- and output logs live under `<home>/service` and `<home>/logs/service`; OS task and
128
- LaunchAgent registrations stay in their required system locations. Reinstall the
129
- service to update an older registration after stopping it and migrating its
130
- configuration. Explicit external environment files remain referenced in place.
131
- Uninstalling the service preserves configuration, identity and logs.
132
- Installers resolve the data home through `agentknight status --json`, so they
133
- must be used with the matching installed CLI. They pin the installation working
134
- directory to preserve relative paths; reinstall after changing the configured
135
- home or moving that directory. A missing canonical configuration must be
136
- created or migrated before installing the default service. Both default and
137
- explicit-file installations refuse a pending legacy-home migration; stop the old
138
- service and complete a normal startup with the selected configuration first.
139
-
140
- Re-register older Windows tasks
141
- that use `-CaCertPath` with `agentknight-service.ps1 install -EnvFile <path>`
142
- (and `-TaskName <name>` for a custom task), omitting `-CaCertPath`.
143
-
144
- ### Microsoft sign-in
145
-
146
- Set `RELAY_URL` and `RELAY_AUTH=microsoft` in the environment file, then start
147
- AgentKnight. Open the printed loopback URL and select **使用 Microsoft 登录**.
148
- Complete Microsoft sign-in and any application consent in a browser on that same
149
- computer. The browser returns to AgentKnight automatically; there is no device
150
- code to copy or enter. The Relay must support browser callback sign-in, have
151
- Microsoft sign-in enabled, and admit your account through its administrator.
152
- An older Relay must be upgraded rather than silently switching to manual codes.
153
-
154
- After approval, AgentKnight saves the machine-bound Relay credential in the
155
- current OS user's credential store, confirms it with Relay, and connects. The
156
- normal local page then provides Android pairing. Android still only scans or
157
- imports the pairing information; Microsoft sign-in does not replace the
158
- PC–phone encryption key or authenticate GitHub Copilot.
159
-
160
- Microsoft sign-in supports Windows Credential Manager and macOS Keychain only.
161
- Other operating systems are not supported for Microsoft sign-in; existing token
162
- authentication is unchanged. There is no plaintext or nonpersistent-keyring fallback.
163
- Run the service as the same OS user who signed in. Restarts reuse the saved
164
- credential; no Microsoft password, browser cookie or client secret is stored by
165
- the PC Agent.
166
-
167
- Microsoft sign-in must remain enabled on Relay so the Agent can verify saved
168
- credentials at startup. Verification failures retain the saved credential and
169
- show an error instead of silently switching accounts.
170
-
171
- To authorize a stopped installation explicitly, including before headless
172
- startup, run:
173
-
174
- ```powershell
175
- agentknight login --env C:\path\to\agentknight.env
176
- ```
177
-
178
- Use the same environment file and data home as the service. Do not delete or
179
- recreate `device.json` to sign in. A running Agent must be stopped before an
180
- explicit login; the command does not stop it for you. Browser logout does not
181
- revoke this PC: use the Relay's `/account` page to revoke its grant.
182
-
183
- ### Existing tokens
184
-
185
- An existing `RELAY_TOKEN` continues to select token authentication unless
186
- `RELAY_AUTH=microsoft` is explicitly set. Microsoft sign-in uses the server's
187
- returned user identity, not `USER_ID`, and never falls back to the old token on
188
- failure. Keep legacy tokens in the environment file, not command-line arguments
189
- or source control.
190
-
191
- The local page shows the Relay account's username, role and authentication
192
- method, separately from coding-agent connections. Generated Microsoft usernames
193
- are displayed as "Microsoft account"; **查看账户** opens the Relay's browser account
194
- page to view the Microsoft name and manage device grants. Account details require the
195
- Relay's PC account endpoint; update Relay as well as the PC client. An older
196
- Relay is reported explicitly instead of guessing a username from `USER_ID`.
197
-
198
- See the [AgentKnight repository](https://github.com/hydraxman/AgentKnight) for
199
- Relay Server and Android client setup.
200
-
201
- ## Coding agents
202
-
203
- The Copilot SDK and bundled CLI are pinned together in the [SDK manifest](../../shared/sdk/package.json).
204
- Keep separately installed Copilot terminals aligned with that CLI when attaching
205
- to their live sessions; restart the terminal after upgrading it. A
206
- `COPILOT_CLI_PATH` override must provide a compatible runtime.
207
-
208
- With `AGENTKNIGHT_CODING_AGENT=managed`, saved agent selections are restored at
209
- startup, including an intentionally empty selection. Without a saved selection,
210
- GitHub Copilot sync is enabled without visiting the local webpage. Use the webpage
211
- to enable agents and select **同步** (Sync), or explicitly show the QR code to pair Android.
212
- Multiple agents share one PC connection. Enabling an agent syncs all of its
213
- current and future locally discoverable sessions; individual sessions need no
214
- selection. Unselected agents remain private. Selections survive PC Agent restarts.
215
-
216
- Use `--agents copilot,pi` to enable agent sync at startup, or `--agents none` to disable
217
- all agent sync. This switches to managed mode and overrides both the saved selection and
218
- `AGENTKNIGHT_CODING_AGENT` for that start without overwriting saved settings.
219
- Native agent configuration still comes from the environment file. Subsequent
220
- webpage Sync actions apply immediately and save the selection; the startup flag takes precedence
221
- again on restart. Managed mode also works with the local webpage disabled.
222
-
223
- PI discovery reads its native session inventory without resuming conversations.
224
- AgentKnight can continue saved PI sessions, but cannot attach to a running PI
225
- terminal. Avoid continuing the same session concurrently in both applications.
226
-
227
- In Android, choose **Rename** from a supported session's menu to change its native
228
- name, not a local display alias. Renaming a group changes only its title, not its
229
- participants' names.
230
-
231
- Use **Agent 群聊** on the local webpage to enable or disable group chat without
232
- restarting the PC Agent. The saved choice takes precedence over the environment
233
- setting in [.env.example](.env.example), including after a restart. Disabling
234
- pauses active groups and keeps their history; enabling does not resume them automatically.
235
- Groups connect two shared Copilot sessions on the same PC, in either managed or
236
- single-engine mode, including sessions created in the CLI or restored after a restart.
237
- Both participants must be idle with no pending input. After restarting, groups remain
238
- paused without replay; send a new group message to continue with the existing members.
239
- Other engines do not support groups.
240
-
241
- For experimental online conversation between Copilot sessions on two PCs, see
242
- the [peer-chat setup](../../docs/remote-sessions/agent-group-chat-design.md#使用).
243
- It is separate from local groups and sends Relay-readable text.
244
- Use only non-sensitive test content.
245
-
246
- Explicit engine values retain single-engine operation without
247
- selection filtering. See [.env.example](.env.example) for configuration.
248
-
249
- | Engine | Setup |
250
- | --- | --- |
251
- | `copilot` | Authenticate the GitHub Copilot CLI as before. |
252
- | `pi` | Install the optional PI dependencies using the Node.js version required by their manifests. Authenticate through PI's CLI or supported provider environment variables. |
253
- | `codex` | Install and authenticate the [official Codex CLI](https://developers.openai.com/codex/cli/); executable overrides are in [.env.example](.env.example). |
254
- | `claude` | Enable optional dependencies and follow the [official Agent SDK setup](https://platform.claude.com/docs/en/agent-sdk/overview) for API-key or cloud-provider authentication. Personal subscription OAuth is not reused. |
255
- | `acp` | Install and authenticate an ACP-compatible agent or bridge. Set `AGENTKNIGHT_ACP_COMMAND` to its executable and `AGENTKNIGHT_ACP_ARGS` to a JSON string array, such as `["--stdio"]` if that agent requires it. |
256
-
257
- PI uses its native directory by default. `PI_CODING_AGENT_DIR` selects an
258
- alternative directory containing PI authentication, model configuration, and
259
- session history; use the same directory when authenticating PI. Install
260
- AgentKnight with optional dependencies enabled to use PI.
261
- Source builds and the complete adapter suite also require the PI-compatible Node
262
- version; Copilot-only operation retains the baseline version in the manifest.
263
-
264
- Codex (App Server) and Claude (Agent SDK) expose only AgentKnight-created
265
- conversations and their saved history, not existing CLI/IDE conversations.
266
- Credentials stay on the PC; discovery does not verify authentication.
267
- Copilot-specific Workbench, group and peer-chat operations remain unsupported.
268
-
269
- The ACP executable must speak the Agent Client Protocol over stdio; an ordinary
270
- Codex or Claude Code CLI is not automatically an ACP endpoint. Arguments are
271
- passed literally, without a shell. AgentKnight does not download or authenticate
272
- the configured executable. Choose a trusted local agent: its own tools execute
273
- with the PC user's privileges. ACP state is kept under the PC data directory,
274
- separately for each executable/argument configuration.
275
-
276
- Adapters expose only supported configuration and operations. PI executes tools
277
- natively, without an added per-tool approval layer. Project resources follow PI's
278
- native project trust decisions, with unresolved trust prompts routed to Android.
279
- Machine-wide features such as uploads and deletion are available only when every
280
- selected engine supports them; session controls use that session's own engine.
281
- ACP approvals use the agent's offered one-time permission option, never an
282
- automatic persistent grant. Unsupported operations return errors rather than
283
- pretending to succeed. Only Copilot exposes its remote-mode toggle.
284
- Generic file uploads remain Copilot-only; PI, Codex and Claude also reject image uploads, while
285
- ACP images require the agent's negotiated image support.
286
-
287
- Optional controls follow the [capability compatibility policy](../../docs/remote-sessions/protocol-compatibility-plan.md);
288
- the historical registration `sdkVersion` is a compatibility marker, while
289
- startup logs record the actual engine and SDK version.
290
-
291
- ## Copilot uploaded files
292
-
293
- Mobile uploads are integrity-checked transport bytes, not model API messages.
294
- The PC Agent keeps generic files in its Copilot session state (`COPILOT_HOME`,
295
- or the default Copilot home) and sends absolute paths through the official
296
- [SDK file attachment contract](https://github.com/github/copilot-sdk/blob/v1.0.11/nodejs/src/types.ts);
297
- images remain blob attachments. The local CLI decides native document handling
298
- versus file-tool access: even [document support](https://github.com/github/copilot-sdk/blob/v1.0.11/docs/features/citations.md#attach-documents-to-a-message)
299
- depends on the model, so an accepted upload does not guarantee every format is readable.
300
- Files remain across acknowledgements, queued turns, failed sends and local restarts/resumes;
301
- they are removed only after successful explicit session deletion, not after each turn.
302
- This requires the runtime to share the PC Agent's filesystem and Copilot home.
303
- The default stdio runtime and the SDK's in-process override are local; unverified
304
- external clients do not advertise file uploads and reject them with an actionable error.
305
- Moving a session to another machine does not transfer these local files.
1
+ # AgentKnight
2
+
3
+ AgentKnight PC Agent connects local coding-agent sessions to an AgentKnight
4
+ Relay Server through Copilot, PI SDK, or ACP adapters.
5
+
6
+ ## Embed
7
+
8
+ Use `@agentknight/sdk` to embed the PC Agent runtime in a Node.js application
9
+ without running the CLI or its local management service.
10
+ Call `initialize` with an explicit absolute `dataDirectory` and the connection,
11
+ identity and logging options, then manage the returned runtime with `start` and
12
+ `stop`. The SDK does not select `~/.ak` or read the CLI configuration for you.
13
+ Do not share a data directory between running instances.
14
+ After starting, `disconnectRelay()` pauses remote access while preserving local
15
+ providers and credentials. Use `reconnectRelay()` to resume and `getStatus()`
16
+ to verify recovery.
17
+
18
+ The CLI depends on the SDK; both use the same release version. The SDK can be
19
+ published independently through the [npm release workflow](../../.github/workflows/agentknight-npm-publish.yml).
20
+ See the [SDK entry point](../../shared/sdk/src/index.ts) for the public API.
21
+
22
+ ## Run
23
+
24
+ Use the Node.js version required by [package.json](package.json) and authenticate
25
+ the coding agents you want to use.
26
+
27
+ ```powershell
28
+ npx @agentknight/client --env C:\path\to\agentknight.env
29
+ ```
30
+
31
+ Or install it globally:
32
+
33
+ ```powershell
34
+ npm install --global @agentknight/client
35
+ agentknight --env C:\path\to\agentknight.env
36
+ ```
37
+
38
+ To switch from the unscoped `agentknight` package, stop the Agent and its service,
39
+ run `npm uninstall --global agentknight`, then install `@agentknight/client` as
40
+ above. The command remains `agentknight`; keep the existing data home and
41
+ configuration. Re-register services that pin the old package path before
42
+ restarting. Updating the old package does not migrate it to the new name.
43
+
44
+ `AGENTKNIGHT_HOME` selects the PC data home, defaulting to `~/.ak`. Without
45
+ `--env`, AgentKnight reads `<home>/agentknight.env`, with process settings taking
46
+ precedence. With `--env`, the selected file is authoritative for PC settings:
47
+ missing settings use defaults or fail validation, rather than inheriting old
48
+ Relay credentials, machine names or data paths. OS and external provider
49
+ environment variables are retained; explicitly supplied file values override them.
50
+ Set custom `AGENTKNIGHT_HOME` in that file as well so restarts use the same home.
51
+
52
+ `COPILOT_REMOTE_HOME` and `AGENTKNIGHT_PI_DIRECTORY` are deprecated input aliases
53
+ for `AGENTKNIGHT_HOME` and PI's native `PI_CODING_AGENT_DIR`. Conflicting aliases
54
+ in the same source are rejected. New configuration and restart metadata use only
55
+ the canonical names. PI's native tilde, file URL and Windows shell path syntax
56
+ is preserved; an explicitly empty PI directory selects its native default.
57
+
58
+ The first normal startup can import legacy working-directory `.env` files or
59
+ the old macOS service configuration into `~/.ak/agentknight.env`. Conflicting
60
+ legacy values require selecting or reconciling the correct file; no source
61
+ silently wins. A selected custom home does not import another home's settings.
62
+ Status and upgrade commands do not import or migrate configuration.
63
+
64
+ A legacy `~/.copilot-remote` home is copied only while the old Agent is stopped,
65
+ preserving its machine identity, pairing keys and saved state. The stable device
66
+ ID now lives in `<home>/device-id` alongside `device.json`; existing identities
67
+ are preserved when importing a retired client layout's ID. Fresh custom homes have
68
+ independent identities. No retired client directory or compatibility symlink is
69
+ created. Conflicting identities or homes require manual resolution, not an
70
+ automatic reset. Retained legacy files are rollback copies, never dual-written;
71
+ remove them only after verifying the migrated installation while old agents are stopped.
72
+
73
+ Diagnostic JSONL files are under `<data-home>/logs/<version>/`. Existing
74
+ unversioned logs remain historical files; they are not assigned an invented
75
+ version. The local pairing page shows the running version, last successful
76
+ upgrade time, configuration location, and Relay URL.
77
+
78
+ ## Status and upgrades
79
+
80
+ ```powershell
81
+ agentknight --version
82
+ agentknight status
83
+ agentknight status --json
84
+ agentknight upgrade --check
85
+ agentknight upgrade
86
+ ```
87
+
88
+ `upgrade` uses the latest published version; `upgrade <version>` selects an exact
89
+ newer version. Self-upgrade requires a global npm installation, not an `npx`
90
+ cache or source checkout. Install a release containing this command through npm
91
+ before using it for subsequent upgrades.
92
+
93
+ Package resolution and installation try the official npm registry first, then
94
+ the Tencent npm mirror for network failures. Existing npm/proxy configuration
95
+ is respected without changing global settings. Archives and dependencies for
96
+ both the target and rollback are prepared before stopping the running Agent.
97
+
98
+ An independent worker waits for idle and performs the switch. Windows scheduled
99
+ tasks and the supplied macOS LaunchAgent retain their existing configuration;
100
+ foreground instances restart in the background. Persist their configuration and
101
+ provider credentials in the environment file before upgrading; shell-only values
102
+ that cannot be restored cause the upgrade to be refused. A stopped installation
103
+ remains stopped. User-level installations do not require elevation; protected npm
104
+ prefixes or service definitions need their existing permissions.
105
+
106
+ The command reports the handoff, not successful completion. Use `status` to see
107
+ the persistent result if the initiating connection closes. An Agent that remains
108
+ busy is left running. Startup failure triggers an offline rollback; readiness
109
+ requires the new instance's registration and initial synchronization, not merely
110
+ an HTTP health response. Upgrading briefly interrupts the PC connection and does
111
+ not migrate an active model turn between processes.
112
+
113
+ Successful upgrades remove their temporary installation materials. Failed jobs
114
+ retain their diagnostic files under `<data-home>/upgrades`; the last successful
115
+ upgrade timestamp changes only after recovery is confirmed.
116
+
117
+ ## Configuration
118
+
119
+ Create the environment file from the
120
+ [PC Agent example](https://github.com/hydraxman/AgentKnight/blob/main/clients/pc-agent/.env.example).
121
+
122
+ `RELAY_URL` is used for HTTP APIs and Socket.IO, so an `https://` URL enables
123
+ HTTPS and WSS for the entire PC Agent connection. `AGENTKNIGHT_MACHINE_NAME`
124
+ controls the PC name shown to mobile clients. The selection and pairing webpage
125
+ listens only on loopback; `PAIRING_PAGE_PORT` changes its local port.
126
+
127
+ Use **重连** on the local page to retry with saved credentials without
128
+ restarting coding agents. Recognized authorization-service outages retry
129
+ automatically; other server-initiated disconnects require user action.
130
+ **断开连接** pauses remote access until **重连** or a PC Client restart,
131
+ without stopping local agents or clearing saved login.
132
+
133
+ Repository checkouts also include Windows Scheduled Task and macOS LaunchAgent
134
+ installers under `clients/pc-agent/scripts`. Services use the same canonical
135
+ configuration as the CLI, not a copied environment file. Service support files
136
+ and output logs live under `<home>/service` and `<home>/logs/service`; OS task and
137
+ LaunchAgent registrations stay in their required system locations. Reinstall the
138
+ service to update an older registration after stopping it and migrating its
139
+ configuration. Explicit external environment files remain referenced in place.
140
+ Uninstalling the service preserves configuration, identity and logs.
141
+ Installers resolve the data home through `agentknight status --json`, so they
142
+ must be used with the matching installed CLI. They pin the installation working
143
+ directory to preserve relative paths; reinstall after changing the configured
144
+ home or moving that directory. A missing canonical configuration must be
145
+ created or migrated before installing the default service. Both default and
146
+ explicit-file installations refuse a pending legacy-home migration; stop the old
147
+ service and complete a normal startup with the selected configuration first.
148
+
149
+ Re-register older Windows tasks
150
+ that use `-CaCertPath` with `agentknight-service.ps1 install -EnvFile <path>`
151
+ (and `-TaskName <name>` for a custom task), omitting `-CaCertPath`.
152
+
153
+ ### Microsoft sign-in
154
+
155
+ Set `RELAY_URL` and `RELAY_AUTH=microsoft` in the environment file, then start
156
+ AgentKnight. Open the printed loopback URL and select **使用 Microsoft 登录**.
157
+ Complete Microsoft sign-in and any application consent in a browser on that same
158
+ computer. The browser returns to AgentKnight automatically; there is no device
159
+ code to copy or enter. The Relay must support browser callback sign-in, have
160
+ Microsoft sign-in enabled, and admit your account through its administrator.
161
+ An older Relay must be upgraded rather than silently switching to manual codes.
162
+
163
+ After approval, AgentKnight saves the machine-bound Relay credential in the
164
+ current OS user's credential store, confirms it with Relay, and connects. The
165
+ normal local page then provides Android pairing. Android still only scans or
166
+ imports the pairing information; Microsoft sign-in does not replace the
167
+ PC–phone encryption key or authenticate GitHub Copilot.
168
+
169
+ Microsoft sign-in supports Windows Credential Manager and macOS Keychain only.
170
+ Other operating systems are not supported for Microsoft sign-in; existing token
171
+ authentication is unchanged. There is no plaintext or nonpersistent-keyring fallback.
172
+ Run the service as the same OS user who signed in. Restarts reuse the saved
173
+ credential; no Microsoft password, browser cookie or client secret is stored by
174
+ the PC Agent.
175
+
176
+ Microsoft sign-in must remain enabled on Relay so the Agent can verify saved
177
+ credentials at startup. Verification failures retain the saved credential and
178
+ show an error instead of silently switching accounts.
179
+
180
+ To authorize a stopped installation explicitly, including before headless
181
+ startup, run:
182
+
183
+ ```powershell
184
+ agentknight login --env C:\path\to\agentknight.env
185
+ ```
186
+
187
+ Use the same environment file and data home as the service. Do not delete or
188
+ recreate `device.json` to sign in. A running Agent must be stopped before an
189
+ explicit login; the command does not stop it for you. Browser logout does not
190
+ revoke this PC: use the Relay's `/account` page to revoke its grant.
191
+
192
+ ### Existing tokens
193
+
194
+ An existing `RELAY_TOKEN` continues to select token authentication unless
195
+ `RELAY_AUTH=microsoft` is explicitly set. Microsoft sign-in uses the server's
196
+ returned user identity, not `USER_ID`, and never falls back to the old token on
197
+ failure. Keep legacy tokens in the environment file, not command-line arguments
198
+ or source control.
199
+
200
+ The local page shows the Relay account's username, role and authentication
201
+ method, separately from coding-agent connections. Generated Microsoft usernames
202
+ are displayed as "Microsoft account"; **查看账户** opens the Relay's browser account
203
+ page to view the Microsoft name and manage device grants. Account details require the
204
+ Relay's PC account endpoint; update Relay as well as the PC client. An older
205
+ Relay is reported explicitly instead of guessing a username from `USER_ID`.
206
+
207
+ See the [AgentKnight repository](https://github.com/hydraxman/AgentKnight) for
208
+ Relay Server and Android client setup.
209
+
210
+ ## Windows app
211
+
212
+ The Windows app's **PC Client** tab downloads and caches the published client;
213
+ it is not bundled with the app. Follow the dependency prompts, then configure
214
+ your Relay connection. Closing the app stops only clients it started;
215
+ an existing client is reused without changing its settings or lifetime.
216
+
217
+ ## Coding agents
218
+
219
+ The Copilot SDK and bundled CLI are pinned together in the [SDK manifest](../../shared/sdk/package.json).
220
+ Keep separately installed Copilot terminals aligned with that CLI when attaching
221
+ to their live sessions; restart the terminal after upgrading it. A
222
+ `COPILOT_CLI_PATH` override must provide a compatible runtime.
223
+
224
+ With `AGENTKNIGHT_CODING_AGENT=managed`, saved agent selections are restored at
225
+ startup, including an intentionally empty selection. Without a saved selection,
226
+ GitHub Copilot sync is enabled without visiting the local webpage. Use the webpage
227
+ to enable agents and select **同步** (Sync), or explicitly show the QR code to pair Android.
228
+ Multiple agents share one PC connection. Enabling an agent syncs all of its
229
+ current and future locally discoverable sessions; individual sessions need no
230
+ selection. Unselected agents remain private. Selections survive PC Agent restarts.
231
+
232
+ Use `--agents copilot,pi` to enable agent sync at startup, or `--agents none` to disable
233
+ all agent sync. This switches to managed mode and overrides both the saved selection and
234
+ `AGENTKNIGHT_CODING_AGENT` for that start without overwriting saved settings.
235
+ Native agent configuration still comes from the environment file. Subsequent
236
+ webpage Sync actions apply immediately and save the selection; the startup flag takes precedence
237
+ again on restart. Managed mode also works with the local webpage disabled.
238
+
239
+ PI discovery reads its native session inventory without resuming conversations.
240
+ AgentKnight can continue saved PI sessions, but cannot attach to a running PI
241
+ terminal. Avoid continuing the same session concurrently in both applications.
242
+
243
+ In Android, choose **Rename** from a supported session's menu to change its native
244
+ name, not a local display alias. Renaming a group changes only its title, not its
245
+ participants' names.
246
+
247
+ Use **Agent 群聊** on the local webpage to enable or disable group chat without
248
+ restarting the PC Agent. The saved choice takes precedence over the environment
249
+ setting in [.env.example](.env.example), including after a restart. Disabling
250
+ pauses active groups and keeps their history; enabling does not resume them automatically.
251
+ Groups connect two shared Copilot sessions on the same PC, in either managed or
252
+ single-engine mode, including sessions created in the CLI or restored after a restart.
253
+ Both participants must be idle with no pending input. After restarting, groups remain
254
+ paused without replay; send a new group message to continue with the existing members.
255
+ Other engines do not support groups.
256
+
257
+ For experimental online conversation between Copilot sessions on two PCs, see
258
+ the [peer-chat setup](../../docs/remote-sessions/agent-group-chat-design.md#使用).
259
+ It is separate from local groups and sends Relay-readable text.
260
+ Use only non-sensitive test content.
261
+
262
+ Explicit engine values retain single-engine operation without
263
+ selection filtering. See [.env.example](.env.example) for configuration.
264
+
265
+ | Engine | Setup |
266
+ | --- | --- |
267
+ | `copilot` | Authenticate the GitHub Copilot CLI as before. |
268
+ | `pi` | Install the optional PI dependencies using the Node.js version required by their manifests. Authenticate through PI's CLI or supported provider environment variables. |
269
+ | `codex` | Install and authenticate the [official Codex CLI](https://developers.openai.com/codex/cli/); executable overrides are in [.env.example](.env.example). |
270
+ | `claude` | Enable optional dependencies and follow the [official Agent SDK setup](https://platform.claude.com/docs/en/agent-sdk/overview) for API-key or cloud-provider authentication. Personal subscription OAuth is not reused. |
271
+ | `acp` | Install and authenticate an ACP-compatible agent or bridge. Set `AGENTKNIGHT_ACP_COMMAND` to its executable and `AGENTKNIGHT_ACP_ARGS` to a JSON string array, such as `["--stdio"]` if that agent requires it. |
272
+
273
+ PI uses its native directory by default. `PI_CODING_AGENT_DIR` selects an
274
+ alternative directory containing PI authentication, model configuration, and
275
+ session history; use the same directory when authenticating PI. Install
276
+ AgentKnight with optional dependencies enabled to use PI.
277
+ Source builds and the complete adapter suite also require the PI-compatible Node
278
+ version; Copilot-only operation retains the baseline version in the manifest.
279
+
280
+ Enabling Codex or Claude synchronizes existing and newly discovered native
281
+ sessions to the phone. Reading history does not start model work; sending resumes
282
+ the original session. Disabling synchronization cancels only AgentKnight's work,
283
+ not an external CLI process. Claude discovery and history do not require provider
284
+ credentials; sending requires the authentication described above.
285
+ Credentials stay on the PC; discovery does not verify authentication.
286
+ Copilot-specific Workbench, group and peer-chat operations remain unsupported.
287
+
288
+ The ACP executable must speak the Agent Client Protocol over stdio; an ordinary
289
+ Codex or Claude Code CLI is not automatically an ACP endpoint. Arguments are
290
+ passed literally, without a shell. AgentKnight does not download or authenticate
291
+ the configured executable. Choose a trusted local agent: its own tools execute
292
+ with the PC user's privileges. ACP state is kept under the PC data directory,
293
+ separately for each executable/argument configuration.
294
+
295
+ Adapters expose only supported configuration and operations. PI executes tools
296
+ natively, without an added per-tool approval layer. Project resources follow PI's
297
+ native project trust decisions, with unresolved trust prompts routed to Android.
298
+ Machine-wide features such as uploads and deletion are available only when every
299
+ selected engine supports them; session controls use that session's own engine.
300
+ ACP approvals use the agent's offered one-time permission option, never an
301
+ automatic persistent grant. Unsupported operations return errors rather than
302
+ pretending to succeed. Only Copilot exposes its remote-mode toggle.
303
+ Generic file uploads remain Copilot-only; PI, Codex and Claude also reject image uploads, while
304
+ ACP images require the agent's negotiated image support.
305
+
306
+ Optional controls follow the [capability compatibility policy](../../docs/remote-sessions/protocol-compatibility-plan.md);
307
+ the historical registration `sdkVersion` is a compatibility marker, while
308
+ startup logs record the actual engine and SDK version.
309
+
310
+ ## Copilot uploaded files
311
+
312
+ Mobile uploads are integrity-checked transport bytes, not model API messages.
313
+ The PC Agent keeps generic files in its Copilot session state (`COPILOT_HOME`,
314
+ or the default Copilot home) and sends absolute paths through the official
315
+ [SDK file attachment contract](https://github.com/github/copilot-sdk/blob/v1.0.11/nodejs/src/types.ts);
316
+ images remain blob attachments. The local CLI decides native document handling
317
+ versus file-tool access: even [document support](https://github.com/github/copilot-sdk/blob/v1.0.11/docs/features/citations.md#attach-documents-to-a-message)
318
+ depends on the model, so an accepted upload does not guarantee every format is readable.
319
+ Files remain across acknowledgements, queued turns, failed sends and local restarts/resumes;
320
+ they are removed only after successful explicit session deletion, not after each turn.
321
+ This requires the runtime to share the PC Agent's filesystem and Copilot home.
322
+ The default stdio runtime and the SDK's in-process override are local; unverified
323
+ external clients do not advertise file uploads and reject them with an actionable error.
324
+ Moving a session to another machine does not transfer these local files.