@agentknight/client 0.9.44 → 0.9.45
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/LICENSE +201 -201
- package/README.md +305 -305
- package/dist/cli.js +835 -814
- package/dist/upgrade-worker.js +20 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,305 +1,305 @@
|
|
|
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
|
+
|
|
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.
|