@ainecto/cli 0.16.0 → 0.16.1

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
@@ -268,7 +268,7 @@ This is the entry `setup --local` and `init --mcp --local` write — you normall
268
268
  "mcpServers": {
269
269
  "ainecto": {
270
270
  "command": "npx",
271
- "args": ["-y", "@ainecto/mcp@0.16.0"]
271
+ "args": ["-y", "@ainecto/mcp@0.16.1"]
272
272
  }
273
273
  }
274
274
  }
@@ -5699,8 +5699,8 @@ function legacyRoleInput(flag, envVars = process.env) {
5699
5699
 
5700
5700
  // src/core/version.ts
5701
5701
  var UNBUNDLED_VERSION = "dev";
5702
- var CLI_VERSION = true ? "0.16.0" : UNBUNDLED_VERSION;
5703
- var CLI_BUILD = true ? "0159129" : void 0;
5702
+ var CLI_VERSION = true ? "0.16.1" : UNBUNDLED_VERSION;
5703
+ var CLI_BUILD = true ? "53ef619" : void 0;
5704
5704
  function cliVersionLabel(version, build, release2) {
5705
5705
  return release2 || build === void 0 ? version : `${version}-dev+${build}`;
5706
5706
  }
@@ -11072,6 +11072,18 @@ async function acquirePcBridgeLock(paths) {
11072
11072
  abstractLockName: paths.abstractLockName.replace(/\.lock$/, "-pc-bridge.lock")
11073
11073
  });
11074
11074
  }
11075
+ async function waitForDaemonLockFree(paths, ms) {
11076
+ const until = Date.now() + ms;
11077
+ for (; ; ) {
11078
+ const lock = await acquireProcessLock(paths);
11079
+ if (lock) {
11080
+ lock.release();
11081
+ return true;
11082
+ }
11083
+ if (Date.now() >= until) return false;
11084
+ await new Promise((resolve4) => setTimeout(resolve4, 100));
11085
+ }
11086
+ }
11075
11087
  async function acquireProcessLock(paths) {
11076
11088
  assertTermRuntime();
11077
11089
  const fileLock = FILE_LOCK[process.platform];
@@ -11734,14 +11746,6 @@ function readDaemonInfo(paths) {
11734
11746
  function daemonPid(paths) {
11735
11747
  return readDaemonInfo(paths)?.pid;
11736
11748
  }
11737
- async function waitForPidGone(pid, ms) {
11738
- const until = Date.now() + ms;
11739
- while (isAlive(pid)) {
11740
- if (Date.now() >= until) return false;
11741
- await new Promise((resolve4) => setTimeout(resolve4, 100));
11742
- }
11743
- return true;
11744
- }
11745
11749
  function notListening(paths) {
11746
11750
  const pid = daemonPid(paths);
11747
11751
  const holder = pid !== void 0 && isAlive(pid) ? `Daemon pid ${pid} holds the lock but is not listening on ${paths.socket} \u2014 it may be stopped or hung. ${stuckProcessHint(pid)}` : "No running daemon answered.";
@@ -16232,23 +16236,39 @@ var DeviceManager = class {
16232
16236
  deps;
16233
16237
  slot = new ApprovalSlot();
16234
16238
  running;
16239
+ /** 진행 중에 온 새 요청 — 앞 작업이 끝나면 이어서 받는다(마지막 것 하나). */
16240
+ next;
16235
16241
  quietUntil = 0;
16236
16242
  /** keyId → 지운 시각(ms). 그보다 먼저 시작한 등록은 그 키를 쓰지 못한다(다시 요청하면 새 등록이라 쓸 수 있다). */
16237
16243
  removedAt = /* @__PURE__ */ new Map();
16238
16244
  now;
16239
16245
  /** poll 의 pair-request — 받을 수 있으면 등록 작업을 백그라운드로 시작한다(기다리지 않는다). */
16240
16246
  async onPairRequest(requestId) {
16241
- const refuse = (reason) => this.deps.log({ event: "pc_device", step: "request", requestId, result: "ignored", reason });
16242
- if (!this.deps.remoteOn()) return refuse("remote-off");
16243
- if (this.running) return refuse("busy");
16244
- if (this.now().getTime() < this.quietUntil) return refuse("quiet");
16247
+ const refuse = async (reason) => {
16248
+ this.deps.log({ event: "pc_device", step: "request", requestId, result: "refused", reason });
16249
+ await this.deps.relay(requestId).refuse(reason);
16250
+ };
16251
+ if (!this.deps.remoteOn()) return await refuse("remote-off");
16252
+ if (this.running) {
16253
+ this.deps.log({ event: "pc_device", step: "request", requestId, result: "replacing", reason: this.running.requestId });
16254
+ this.next = requestId;
16255
+ this.running.replaced = true;
16256
+ this.running.stop.abort();
16257
+ return;
16258
+ }
16259
+ if (this.now().getTime() < this.quietUntil) return await refuse("quiet");
16245
16260
  const account2 = await this.account();
16246
- if (!account2 || account2.browsers.length === 0) return refuse("no-trusted-browser");
16247
- const stop = new AbortController();
16248
- this.running = { requestId, stop };
16261
+ if (!account2 || account2.browsers.length === 0) return await refuse("no-trusted-browser");
16262
+ const running = { requestId, stop: new AbortController(), replaced: false };
16263
+ this.running = running;
16249
16264
  this.deps.log({ event: "pc_device", step: "request", requestId, result: "started" });
16250
- void this.pair(requestId, account2.pcKey, stop).finally(() => {
16251
- if (this.running?.requestId === requestId) this.running = void 0;
16265
+ void this.pair(requestId, account2.pcKey, running).finally(() => {
16266
+ if (this.running === running) this.running = void 0;
16267
+ const next = this.next;
16268
+ if (next !== void 0 && this.running === void 0) {
16269
+ this.next = void 0;
16270
+ void this.onPairRequest(next);
16271
+ }
16252
16272
  });
16253
16273
  }
16254
16274
  /** 다리 끝·원격 꺼짐·링크 다시 열기 — 진행 중 등록을 끝낸다(abort 를 보낸다). */
@@ -16299,7 +16319,8 @@ var DeviceManager = class {
16299
16319
  }
16300
16320
  }
16301
16321
  }
16302
- async pair(requestId, pcKey, stop) {
16322
+ async pair(requestId, pcKey, running) {
16323
+ const stop = running.stop;
16303
16324
  let outcome;
16304
16325
  let reason;
16305
16326
  const startedAt = this.now().getTime();
@@ -16326,7 +16347,7 @@ var DeviceManager = class {
16326
16347
  }
16327
16348
  if (outcome?.kind === "paired" && outcome.doneError !== void 0) reason = outcome.doneError;
16328
16349
  const result = outcome === void 0 ? "error" : outcome.kind === "paired" && outcome.doneError !== void 0 ? "done-failed" : outcome.kind;
16329
- if (result !== "paired" && result !== "timeout") this.quietUntil = this.now().getTime() + NOTIFY_BATCH_MS;
16350
+ if (result !== "paired" && result !== "timeout" && !running.replaced) this.quietUntil = this.now().getTime() + NOTIFY_BATCH_MS;
16330
16351
  this.deps.log({
16331
16352
  event: "pc_device",
16332
16353
  step: "finished",
@@ -17538,8 +17559,8 @@ async function upgradeDaemon(deps, note) {
17538
17559
  }
17539
17560
  note("Updating the AiNecto terminal service on this PC\u2026");
17540
17561
  await termRequest(deps.paths, { op: "kill-server" }, { start: false });
17541
- if (!await waitForPidGone(info.pid, deps.stopDeadlineMs)) {
17542
- throw new CliCommandError("PC_START_FAILED", `The old terminal service (pid ${info.pid}) did not stop. Restart this PC, then run \`npx -y ainecto@latest\` again.`);
17562
+ if (!await waitForDaemonLockFree(deps.paths, deps.stopDeadlineMs)) {
17563
+ throw new CliCommandError("PC_START_FAILED", `The old AiNecto terminal service (${info.version}, started as pid ${info.pid}) is still running and did not stop within ${Math.round(deps.stopDeadlineMs / 1e3)} s. End it \u2014 on Windows: Task Manager \u203A Details \u203A the node.exe whose command line has "term daemon"; on macOS/Linux: \`kill ${info.pid}\` if that pid is still the daemon \u2014 or restart this PC, then run \`npx -y ainecto@latest\` again.`);
17543
17564
  }
17544
17565
  }
17545
17566
  async function withRegistration(deps, key, userId, code) {
@@ -17974,6 +17995,16 @@ function createPairRelay(input) {
17974
17995
  await send({ type: "done", signature: b64u3(signature) }, signal);
17975
17996
  finished = true;
17976
17997
  },
17998
+ async refuse(reason) {
17999
+ try {
18000
+ const opened = await http.call("pair/open", { pcId: input.pcId, ...input.requestId ? { requestId: input.requestId } : {} });
18001
+ if (typeof opened.attemptId !== "string" || opened.attemptId === "") return;
18002
+ attemptId = opened.attemptId;
18003
+ finished = true;
18004
+ await http.call("pair/send", { attemptId, msg: { type: "abort", reason } });
18005
+ } catch {
18006
+ }
18007
+ },
17977
18008
  async abort(reason) {
17978
18009
  if (!attemptId || finished) return;
17979
18010
  finished = true;