@agentknight/client 0.9.51 → 0.9.53

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.
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ processExists,
4
+ readRuntimeDescriptor,
5
+ requestRuntime
6
+ } from "./chunk-WZIU4HVH.js";
7
+ import "./chunk-SPZWIFFP.js";
8
+
9
+ // src/stop-client.ts
10
+ import { setTimeout as delay } from "node:timers/promises";
11
+ async function stopClient(dataDirectory, expectedPid) {
12
+ const descriptor = await readRuntimeDescriptor(dataDirectory);
13
+ if (descriptor === void 0 || !processExists(descriptor.pid)) {
14
+ if (expectedPid !== void 0) throw new Error("The selected Agent has exited. Refresh its status.");
15
+ return;
16
+ }
17
+ if (expectedPid !== void 0 && descriptor.pid !== expectedPid) {
18
+ throw new Error("The running Agent changed. Refresh its status before stopping it.");
19
+ }
20
+ const status = await requestRuntime(descriptor, "status");
21
+ if (status === void 0) throw new Error("Could not verify the running Agent.");
22
+ if (status.busy || status.stopping) {
23
+ throw new Error("The Agent is busy or already stopping. Finish pending work and retry.");
24
+ }
25
+ await requestRuntime(descriptor, "stop", 65e3);
26
+ const deadline = Date.now() + 1e4;
27
+ do {
28
+ const current = await readRuntimeDescriptor(dataDirectory);
29
+ if (current === void 0) return;
30
+ if (current.instanceId !== descriptor.instanceId || current.pid !== descriptor.pid) {
31
+ throw new Error("Another Agent started while stopping. Refresh its status.");
32
+ }
33
+ if (!processExists(descriptor.pid)) return;
34
+ await delay(100);
35
+ } while (Date.now() < deadline);
36
+ throw new Error("The Agent has not finished stopping. Check its status before retrying.");
37
+ }
38
+ export {
39
+ stopClient
40
+ };
@@ -9,8 +9,8 @@ import {
9
9
  resolveUpgradeVersion,
10
10
  runNpm,
11
11
  updateJobState
12
- } from "./chunk-KYTI7A5R.js";
13
- import "./chunk-YNKNHR5K.js";
12
+ } from "./chunk-CG5LD6VF.js";
13
+ import "./chunk-CNWBK4LE.js";
14
14
  import {
15
15
  processExists,
16
16
  readRuntimeDescriptor,
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  readAppVersion,
4
4
  toErrorDetails
5
- } from "./chunks/chunk-WS6ISEXX.js";
5
+ } from "./chunks/chunk-HQX6KKVV.js";
6
6
 
7
7
  // src/index.ts
8
8
  import { fileURLToPath } from "node:url";
@@ -20,6 +20,7 @@ function parseCliOptions(args) {
20
20
  let json = false;
21
21
  let check = false;
22
22
  let targetVersion;
23
+ let expectedPid;
23
24
  const peerChat = {};
24
25
  for (let index = 0; index < args.length; index += 1) {
25
26
  const argument = args[index];
@@ -31,7 +32,7 @@ function parseCliOptions(args) {
31
32
  version = true;
32
33
  continue;
33
34
  }
34
- if (argument === "status" || argument === "upgrade" || argument === "login" || argument === "peer-chat") {
35
+ if (argument === "status" || argument === "stop" || argument === "upgrade" || argument === "login" || argument === "peer-chat") {
35
36
  if (command !== void 0) throw new Error("Specify only one command.");
36
37
  command = argument;
37
38
  continue;
@@ -44,6 +45,15 @@ function parseCliOptions(args) {
44
45
  check = true;
45
46
  continue;
46
47
  }
48
+ if (argument === "--pid") {
49
+ const value = args[index + 1];
50
+ if (expectedPid !== void 0 || value === void 0 || !/^[1-9]\d*$/u.test(value) || !Number.isSafeInteger(Number(value)) || Number(value) > 2147483647) {
51
+ throw new Error("--pid requires one positive process ID.");
52
+ }
53
+ expectedPid = Number(value);
54
+ index += 1;
55
+ continue;
56
+ }
47
57
  if (argument === "--session" || argument === "--peer-machine" || argument === "--peer-session" || argument === "--prompt") {
48
58
  const value = args[index + 1];
49
59
  if (value === void 0 || value.trim() === "" || value.startsWith("--")) {
@@ -86,7 +96,8 @@ function parseCliOptions(args) {
86
96
  }
87
97
  throw new Error(`Unknown option: ${argument}`);
88
98
  }
89
- if (json && command !== "status" && command !== "peer-chat") throw new Error("--json requires status or peer-chat.");
99
+ if (json && command !== "status" && command !== "stop" && command !== "peer-chat") throw new Error("--json requires status, stop or peer-chat.");
100
+ if (expectedPid !== void 0 && command !== "stop") throw new Error("--pid requires stop.");
90
101
  if (noEnv && envFile !== void 0) throw new Error("--no-env cannot be combined with --env.");
91
102
  if (check && command !== "upgrade") throw new Error("--check requires upgrade.");
92
103
  if (agents !== void 0 && (command !== void 0 || version)) throw new Error("--agents is only valid when starting the Agent.");
@@ -108,6 +119,7 @@ function parseCliOptions(args) {
108
119
  ...json ? { json } : {},
109
120
  ...check ? { check } : {},
110
121
  ...targetVersion === void 0 ? {} : { targetVersion },
122
+ ...expectedPid === void 0 ? {} : { expectedPid },
111
123
  ...parsedPeerChat?.success ? { peerChat: parsedPeerChat.data } : {}
112
124
  };
113
125
  }
@@ -118,6 +130,7 @@ Usage:
118
130
  agentknight [--env <path>] [--agents <list|none>]
119
131
  npx @agentknight/client [--env <path>] [--agents <list|none>]
120
132
  agentknight status [--json] [--env <path>]
133
+ agentknight stop [--pid <id>] [--json] [--env <path>]
121
134
  agentknight upgrade [version] [--check] [--env <path>]
122
135
  agentknight login [--env <path>]
123
136
  agentknight peer-chat --session <id> --peer-machine <id> --peer-session <id> --prompt <text> [--json] [--env <path>]
@@ -132,9 +145,10 @@ Options:
132
145
 
133
146
  AGENTKNIGHT_HOME defaults to ~/.ak; configuration is <home>/agentknight.env.
134
147
  --env ignores inherited PC settings; external provider/OS variables are retained.
135
- COPILOT_REMOTE_HOME is a deprecated input alias for AGENTKNIGHT_HOME.
136
148
  Upgrade prepares both versions before stopping the Agent and restores the
137
149
  previous version if startup fails. Busy agents are not interrupted.
150
+ stop requests a safe shutdown without deleting configuration or pairing.
151
+ --pid refuses to stop a different Agent if the selected process has changed.
138
152
 
139
153
  --agents uses managed mode and overrides saved selection and
140
154
  AGENTKNIGHT_CODING_AGENT for this start; it does not overwrite saved settings.
@@ -168,7 +182,7 @@ async function main() {
168
182
  `);
169
183
  return;
170
184
  }
171
- const { resolveClientEnvironment } = await import("./chunks/client-home-LAKFDPXO.js");
185
+ const { resolveClientEnvironment } = await import("./chunks/client-home-GPFY7NJP.js");
172
186
  const resolved = await resolveClientEnvironment({
173
187
  ...cliOptions.envFile === void 0 ? {} : { envFile: cliOptions.envFile },
174
188
  ...cliOptions.noEnv ? { noEnv: true } : {},
@@ -199,6 +213,13 @@ async function main() {
199
213
  }
200
214
  return;
201
215
  }
216
+ if (cliOptions.command === "stop") {
217
+ const { stopClient } = await import("./chunks/stop-client-PHRAMW5R.js");
218
+ await stopClient(resolved.dataDirectory, cliOptions.expectedPid);
219
+ process.stdout.write(cliOptions.json ? `${JSON.stringify({ state: "stopped" })}
220
+ ` : "PC Agent stopped.\n");
221
+ return;
222
+ }
202
223
  if (cliOptions.command === "status") {
203
224
  const [{ processExists, readRuntimeDescriptor, requestRuntime }, { readLastUpgrade, readUpgradeState }] = await Promise.all([import("./chunks/runtime-CTACRJCK.js"), import("./chunks/upgrade-state-QXZT3TTS.js")]);
204
225
  const descriptor = await readRuntimeDescriptor(resolved.dataDirectory);
@@ -214,7 +235,6 @@ async function main() {
214
235
  configPath: runtime?.configPath ?? resolved.envFile ?? null,
215
236
  relayUrl: runtime?.relayUrl ?? null,
216
237
  dataDirectory: resolved.dataDirectory,
217
- migrationPending: resolved.migrationPending ?? false,
218
238
  upgradedAt: lastUpgrade?.upgradedAt ?? null,
219
239
  upgrade: state ?? null
220
240
  };
@@ -224,7 +244,7 @@ async function main() {
224
244
  return;
225
245
  }
226
246
  if (cliOptions.command === "upgrade") {
227
- const { upgrade } = await import("./chunks/upgrade-T32WY4HC.js");
247
+ const { upgrade } = await import("./chunks/upgrade-4IKPYFYS.js");
228
248
  await upgrade({
229
249
  dataDirectory: resolved.dataDirectory,
230
250
  currentVersion: appVersion,
@@ -235,7 +255,7 @@ async function main() {
235
255
  });
236
256
  return;
237
257
  }
238
- const { startClient } = await import("./chunks/start-client-XMBDUDJZ.js");
258
+ const { startClient } = await import("./chunks/start-client-YUTN4EXF.js");
239
259
  await startClient(appVersion, cliOptions, resolved, fileURLToPath(import.meta.url));
240
260
  }
241
261
  await main().catch((error) => {
@@ -19699,7 +19699,6 @@ import { homedir } from "node:os";
19699
19699
  import { join, resolve } from "node:path";
19700
19700
  import { fileURLToPath } from "node:url";
19701
19701
  var directoryAliases = [
19702
- ["COPILOT_REMOTE_HOME", "AGENTKNIGHT_HOME"],
19703
19702
  ["AGENTKNIGHT_PI_DIRECTORY", "PI_CODING_AGENT_DIR"]
19704
19703
  ];
19705
19704
  function sameClientPath(left, right, cwd = process.cwd()) {
@@ -20193,17 +20192,27 @@ async function installPreparedPackage(options) {
20193
20192
  import { createConnection, createServer } from "node:net";
20194
20193
  import { join as join5, resolve as resolve3 } from "node:path";
20195
20194
 
20196
- // ../../shared/sdk/dist/chunks/chunk-BMMKEB6V.js
20195
+ // ../../shared/sdk/dist/chunks/chunk-UZFIXIAS.js
20197
20196
  var IdSchema = external_exports.string().trim().min(1).max(256);
20198
20197
  var IsoDateSchema = external_exports.iso.datetime({ offset: true });
20199
20198
  var Base64UrlKeyIdSchema = external_exports.string().regex(/^[A-Za-z0-9_-]{22}$/u, "Expected a 16-byte base64url key ID");
20200
20199
  var UsernameSchema = external_exports.string().trim().min(1).max(120);
20200
+ var SessionImageTransferModeSchema = external_exports.enum(["direct", "proxy"]);
20201
+ var SessionImageStorageSchema = external_exports.object({
20202
+ mode: SessionImageTransferModeSchema,
20203
+ storageAccount: external_exports.string().regex(/^[a-z0-9]{3,24}$/u),
20204
+ storageContainer: external_exports.string().min(3).max(63).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u)
20205
+ }).strict();
20201
20206
  var ProtocolFailureSchema = external_exports.object({
20202
20207
  code: IdSchema,
20203
20208
  message: external_exports.string().min(1).max(1024)
20204
20209
  });
20205
20210
  var OperationAckSchema = external_exports.discriminatedUnion("ok", [
20206
- external_exports.object({ ok: external_exports.literal(true), capabilities: external_exports.array(IdSchema).max(64).optional() }),
20211
+ external_exports.object({
20212
+ ok: external_exports.literal(true),
20213
+ capabilities: external_exports.array(IdSchema).max(64).optional(),
20214
+ sessionImageStorage: SessionImageStorageSchema.optional()
20215
+ }),
20207
20216
  external_exports.object({
20208
20217
  ok: external_exports.literal(false),
20209
20218
  code: IdSchema,
@@ -21870,7 +21879,8 @@ var MachineListResultSchema = external_exports.object({
21870
21879
  requestId: IdSchema,
21871
21880
  machines: external_exports.array(MachinePresenceSchema),
21872
21881
  // Absent on older relays; PC presence capabilities alone do not negotiate routing.
21873
- relayCapabilities: external_exports.array(IdSchema).max(64).optional()
21882
+ relayCapabilities: external_exports.array(IdSchema).max(64).optional(),
21883
+ sessionImageStorage: SessionImageStorageSchema.optional()
21874
21884
  });
21875
21885
  var PeerTextSchema = external_exports.string().max(16e3).refine((value) => value.trim().length > 0);
21876
21886
  var PeerMessageBaseShape = {
@@ -22194,7 +22204,6 @@ var SessionResourceReadResultDataSchema = external_exports.object({
22194
22204
  var SESSION_IMAGE_MAX_BYTES = 3 * 1024 * 1024;
22195
22205
  var SESSION_IMAGE_MAX_PIXELS = 16 * 1024 * 1024;
22196
22206
  var SessionImageIdSchema = external_exports.uuid();
22197
- var SessionImageTransferModeSchema = external_exports.enum(["direct", "proxy"]);
22198
22207
  var DirectUrlSchema = external_exports.string().regex(/^https:\/\/[^/?#@\\\s\x00-\x1f\x7f]+(?:[/?][^#\\\s\x00-\x1f\x7f]*)?$/u).refine((raw) => {
22199
22208
  if (!URL.canParse(raw))
22200
22209
  return false;
@@ -22838,6 +22847,7 @@ var RelayFeaturesSchema = external_exports.object({
22838
22847
  }).strict();
22839
22848
  var RelayFeatureAndroidSchemas = { RelayFeatures: RelayFeaturesSchema };
22840
22849
  var AndroidProtocolSchemas = {
22850
+ SessionImageStorage: SessionImageStorageSchema,
22841
22851
  MobileIdentityProof: MobileIdentityProofSchema,
22842
22852
  MobileAuthorizationClaim: MobileAuthorizationClaimSchema,
22843
22853
  MobileAuthorizationPoll: MobileAuthorizationPollSchema,
@@ -22961,7 +22971,7 @@ var AndroidProtocolSchemas = {
22961
22971
  ProtocolError: ProtocolErrorSchema
22962
22972
  };
22963
22973
 
22964
- // ../../shared/sdk/dist/chunks/chunk-SNKTDPG5.js
22974
+ // ../../shared/sdk/dist/chunks/chunk-6DYWE5PL.js
22965
22975
  var OwnerSchema = external_exports.object({ pid: external_exports.number().int().positive(), instanceId: external_exports.uuid().optional() });
22966
22976
  var PeerChatRequestSchema = external_exports.object({
22967
22977
  sessionId: IdSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentknight/client",
3
- "version": "0.9.51",
3
+ "version": "0.9.53",
4
4
  "description": "AgentKnight PC Agent CLI for remote coding sessions",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -45,7 +45,7 @@
45
45
  "qrcode": "1.5.4",
46
46
  "qrcode-terminal": "0.12.0",
47
47
  "zod": "4.6.5",
48
- "@agentknight/sdk": "0.9.51"
48
+ "@agentknight/sdk": "0.9.53"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@tailwindcss/node": "4.3.3",