@onklave/agent-cli 0.1.42 → 0.1.44

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.
Files changed (2) hide show
  1. package/main.js +216 -45
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -577,10 +577,19 @@ var PlatformClient = class {
577
577
  * Create a new agent session on the platform.
578
578
  */
579
579
  async spawnSession(config) {
580
+ const body = {
581
+ task: config.task,
582
+ context: config.context,
583
+ model: config.model,
584
+ timeout: config.timeout
585
+ };
586
+ if (config.persona) body.personaName = config.persona;
587
+ if (config.workflow) body.workflowName = config.workflow;
588
+ if (config.machineId) body.machineId = config.machineId;
580
589
  return this.request(
581
590
  "POST",
582
591
  "/api/v1/agent/spawn",
583
- config
592
+ body
584
593
  );
585
594
  }
586
595
  /*
@@ -659,7 +668,7 @@ var PlatformClient = class {
659
668
  async registerMachine(linkingToken, metadata) {
660
669
  return this.request("POST", "/api/v1/runner/register", {
661
670
  linkingToken,
662
- metadata
671
+ ...metadata
663
672
  });
664
673
  }
665
674
  /*
@@ -695,10 +704,13 @@ var PlatformClient = class {
695
704
  );
696
705
  }
697
706
  /*
698
- * Unregister this machine.
707
+ * Unregister this machine. The backend exposes this as DELETE on the
708
+ * register route and identifies the machine via the `x-machine-id` header.
699
709
  */
700
- async unregisterMachine() {
701
- await this.request("POST", "/api/v1/runner/unregister");
710
+ async unregisterMachine(machineId) {
711
+ await this.request("DELETE", "/api/v1/runner/register", void 0, {
712
+ "x-machine-id": machineId
713
+ });
702
714
  }
703
715
  /*
704
716
  * Update an already-registered machine's configuration. Used by
@@ -735,8 +747,8 @@ var PlatformClient = class {
735
747
  /*
736
748
  * Make an authenticated HTTP request to the platform.
737
749
  */
738
- async request(method, path8, body, extraHeaders) {
739
- const url = `${this.baseUrl}${GATEWAY_SERVICE_PREFIX}${path8}`;
750
+ async request(method, path10, body, extraHeaders) {
751
+ const url = `${this.baseUrl}${GATEWAY_SERVICE_PREFIX}${path10}`;
740
752
  const headers = {
741
753
  Authorization: `Bearer ${this.token}`,
742
754
  "Content-Type": "application/json",
@@ -3009,7 +3021,7 @@ async function logsCommand(args) {
3009
3021
  }
3010
3022
 
3011
3023
  // _apps/@onklave/agent-cli/src/commands/daemon.command.ts
3012
- import * as fs7 from "fs";
3024
+ import * as fs8 from "fs";
3013
3025
 
3014
3026
  // _apps/@onklave/agent-cli/src/services/daemon-comms.service.ts
3015
3027
  var DaemonCommsService = class {
@@ -3436,8 +3448,8 @@ var PlatformBrokerClient = class {
3436
3448
  params
3437
3449
  );
3438
3450
  }
3439
- async request(method, path8, body) {
3440
- const url = `${this.baseUrl}/agent-orchestration${path8}`;
3451
+ async request(method, path10, body) {
3452
+ const url = `${this.baseUrl}/agent-orchestration${path10}`;
3441
3453
  const response = await fetch(url, {
3442
3454
  method,
3443
3455
  headers: {
@@ -3969,9 +3981,37 @@ function parseSemverNumeric(v) {
3969
3981
  ];
3970
3982
  }
3971
3983
 
3984
+ // _apps/@onklave/agent-cli/src/services/cli-version.ts
3985
+ import * as fs6 from "node:fs";
3986
+ import * as path7 from "node:path";
3987
+ import { fileURLToPath } from "node:url";
3988
+ function readPackageVersion() {
3989
+ try {
3990
+ const moduleDir = path7.dirname(fileURLToPath(import.meta.url));
3991
+ const candidates = [
3992
+ path7.join(moduleDir, "package.json"),
3993
+ // bundled: dist root
3994
+ path7.join(moduleDir, "..", "package.json"),
3995
+ path7.join(moduleDir, "..", "..", "package.json"),
3996
+ // dev: src/services -> root
3997
+ path7.join(moduleDir, "..", "..", "..", "package.json")
3998
+ ];
3999
+ for (const p of candidates) {
4000
+ if (!fs6.existsSync(p)) continue;
4001
+ const pkg = JSON.parse(fs6.readFileSync(p, "utf8"));
4002
+ if (pkg.name === PACKAGE_NAME && pkg.version) return pkg.version;
4003
+ }
4004
+ } catch {
4005
+ }
4006
+ return null;
4007
+ }
4008
+ function getCurrentVersion() {
4009
+ return readPackageVersion() ?? "0.0.0";
4010
+ }
4011
+
3972
4012
  // _apps/@onklave/agent-cli/src/services/daemon-state.service.ts
3973
- import * as fs6 from "fs";
3974
- import * as path7 from "path";
4013
+ import * as fs7 from "fs";
4014
+ import * as path8 from "path";
3975
4015
  import * as os6 from "os";
3976
4016
  var VALID_TRANSITIONS = {
3977
4017
  installing: ["registered"],
@@ -3983,10 +4023,10 @@ var VALID_TRANSITIONS = {
3983
4023
  stopped: ["starting"]
3984
4024
  };
3985
4025
  function defaultStateFilePath() {
3986
- return path7.join(os6.homedir(), ".config", "onklave", "daemon.state.json");
4026
+ return path8.join(os6.homedir(), ".config", "onklave", "daemon.state.json");
3987
4027
  }
3988
4028
  function defaultPidFilePath() {
3989
- return path7.join(os6.homedir(), ".config", "onklave", "daemon.pid");
4029
+ return path8.join(os6.homedir(), ".config", "onklave", "daemon.pid");
3990
4030
  }
3991
4031
  var DaemonStateError = class extends Error {
3992
4032
  constructor(message) {
@@ -4010,8 +4050,8 @@ var DaemonStateService = class {
4010
4050
  */
4011
4051
  static readPersisted(stateFile = defaultStateFilePath()) {
4012
4052
  try {
4013
- if (!fs6.existsSync(stateFile)) return null;
4014
- const raw = fs6.readFileSync(stateFile, "utf8");
4053
+ if (!fs7.existsSync(stateFile)) return null;
4054
+ const raw = fs7.readFileSync(stateFile, "utf8");
4015
4055
  const parsed = JSON.parse(raw);
4016
4056
  if (!parsed.state || !parsed.enteredAt) return null;
4017
4057
  return parsed;
@@ -4061,8 +4101,8 @@ var DaemonStateService = class {
4061
4101
  }
4062
4102
  }
4063
4103
  persist(reason) {
4064
- const dir = path7.dirname(this.stateFile);
4065
- fs6.mkdirSync(dir, { recursive: true });
4104
+ const dir = path8.dirname(this.stateFile);
4105
+ fs7.mkdirSync(dir, { recursive: true });
4066
4106
  const payload = {
4067
4107
  state: this.current,
4068
4108
  enteredAt: this.enteredAt.toISOString(),
@@ -4072,8 +4112,8 @@ var DaemonStateService = class {
4072
4112
  ...this.latestRuntime ? { runtime: this.latestRuntime } : {}
4073
4113
  };
4074
4114
  const tmp = `${this.stateFile}.tmp`;
4075
- fs6.writeFileSync(tmp, JSON.stringify(payload, null, 2));
4076
- fs6.renameSync(tmp, this.stateFile);
4115
+ fs7.writeFileSync(tmp, JSON.stringify(payload, null, 2));
4116
+ fs7.renameSync(tmp, this.stateFile);
4077
4117
  }
4078
4118
  /**
4079
4119
  * Publish the latest runtime snapshot. Persists to the state file
@@ -4091,7 +4131,7 @@ var DaemonStateService = class {
4091
4131
  */
4092
4132
  clearPersisted() {
4093
4133
  try {
4094
- fs6.unlinkSync(this.stateFile);
4134
+ fs7.unlinkSync(this.stateFile);
4095
4135
  } catch {
4096
4136
  }
4097
4137
  }
@@ -4547,7 +4587,7 @@ function transitionToAction(next) {
4547
4587
  }
4548
4588
  function readPid(pidFile) {
4549
4589
  try {
4550
- const raw = fs7.readFileSync(pidFile, "utf8").trim();
4590
+ const raw = fs8.readFileSync(pidFile, "utf8").trim();
4551
4591
  const parsed = Number.parseInt(raw, 10);
4552
4592
  return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
4553
4593
  } catch {
@@ -4556,12 +4596,12 @@ function readPid(pidFile) {
4556
4596
  }
4557
4597
  function writePid(pidFile) {
4558
4598
  const dir = pidFile.replace(/\/[^/]+$/, "");
4559
- fs7.mkdirSync(dir, { recursive: true });
4560
- fs7.writeFileSync(pidFile, String(process.pid), { mode: 384 });
4599
+ fs8.mkdirSync(dir, { recursive: true });
4600
+ fs8.writeFileSync(pidFile, String(process.pid), { mode: 384 });
4561
4601
  }
4562
4602
  function removePid(pidFile) {
4563
4603
  try {
4564
- fs7.unlinkSync(pidFile);
4604
+ fs8.unlinkSync(pidFile);
4565
4605
  } catch {
4566
4606
  }
4567
4607
  }
@@ -4570,25 +4610,6 @@ function isPidAlive(pidFile) {
4570
4610
  if (pid == null) return false;
4571
4611
  return isProcessAlive(pid);
4572
4612
  }
4573
- function readPackageVersion() {
4574
- try {
4575
- const candidates = [
4576
- // dist layout (bin/onklave.js → ../package.json)
4577
- `${__dirname}/../../package.json`,
4578
- // src layout during dev
4579
- `${__dirname}/../../../package.json`
4580
- ];
4581
- for (const p of candidates) {
4582
- if (fs7.existsSync(p)) {
4583
- const pkg = JSON.parse(fs7.readFileSync(p, "utf8"));
4584
- if (pkg.name === "@onklave/agent-cli" && pkg.version)
4585
- return pkg.version;
4586
- }
4587
- }
4588
- } catch {
4589
- }
4590
- return null;
4591
- }
4592
4613
  function isProcessAlive(pid) {
4593
4614
  try {
4594
4615
  process.kill(pid, 0);
@@ -4623,8 +4644,157 @@ var COMMANDS = {
4623
4644
  daemon: daemonCommand
4624
4645
  };
4625
4646
 
4647
+ // _apps/@onklave/agent-cli/src/services/update-notifier.service.ts
4648
+ import * as fs9 from "node:fs";
4649
+ import * as path9 from "node:path";
4650
+ import * as os7 from "node:os";
4651
+ import { createInterface } from "node:readline/promises";
4652
+ import { spawnSync } from "node:child_process";
4653
+ var CHECK_TTL_MS = 24 * 60 * 60 * 1e3;
4654
+ var FETCH_DEADLINE_MS = 1500;
4655
+ var CACHE_PATH = path9.join(
4656
+ os7.homedir(),
4657
+ ".config",
4658
+ "onklave",
4659
+ "update-check.json"
4660
+ );
4661
+ function shouldPromptForUpdate(current, latest, dismissedVersion) {
4662
+ if (!latest) return false;
4663
+ if (!isNewerVersion(latest, current)) return false;
4664
+ if (dismissedVersion && dismissedVersion === latest) return false;
4665
+ return true;
4666
+ }
4667
+ async function maybeNotifyUpdate(deps = {}) {
4668
+ const log = deps.log ?? ((m) => console.error(m));
4669
+ try {
4670
+ const isInteractive = deps.isInteractive ?? defaultIsInteractive;
4671
+ if (!isInteractive()) return;
4672
+ const now = deps.now ?? Date.now;
4673
+ const read = deps.readCache ?? readCache;
4674
+ const write = deps.writeCache ?? writeCache;
4675
+ const current = deps.currentVersion ?? "0.0.0";
4676
+ let cache = read();
4677
+ if (!isCacheFresh(cache, now())) {
4678
+ const fetchLatest = deps.fetchLatest ?? (() => defaultRegistryFetcher(PACKAGE_NAME));
4679
+ try {
4680
+ const latestVersion = await withTimeout(
4681
+ fetchLatest(),
4682
+ FETCH_DEADLINE_MS
4683
+ );
4684
+ cache = {
4685
+ ...cache,
4686
+ latestVersion,
4687
+ lastCheckedAt: new Date(now()).toISOString()
4688
+ };
4689
+ write(cache);
4690
+ } catch {
4691
+ write({ ...cache, lastCheckedAt: new Date(now()).toISOString() });
4692
+ return;
4693
+ }
4694
+ }
4695
+ if (!shouldPromptForUpdate(
4696
+ current,
4697
+ cache.latestVersion,
4698
+ cache.dismissedVersion
4699
+ )) {
4700
+ return;
4701
+ }
4702
+ const latest = cache.latestVersion;
4703
+ log(
4704
+ `
4705
+ \u2B06 A new version of the Onklave CLI is available: ${current} \u2192 ${latest}`
4706
+ );
4707
+ const promptYesNo = deps.promptYesNo ?? defaultPromptYesNo;
4708
+ const accepted = await promptYesNo(
4709
+ ` Update now (npm i -g ${PACKAGE_NAME}@latest)? [y/N] `
4710
+ );
4711
+ if (!accepted) {
4712
+ write({ ...cache, dismissedVersion: latest });
4713
+ log(
4714
+ ` Skipped. Run \`npm i -g ${PACKAGE_NAME}@latest\` whenever you're ready.`
4715
+ );
4716
+ return;
4717
+ }
4718
+ const runUpdate = deps.runUpdate ?? defaultRunUpdate;
4719
+ const ok = runUpdate();
4720
+ if (ok) {
4721
+ write({ ...cache, dismissedVersion: latest });
4722
+ log(
4723
+ `
4724
+ \u2705 Updated to ${latest}. Re-run your command to use the new version.`
4725
+ );
4726
+ (deps.exit ?? ((code) => process.exit(code)))(0);
4727
+ return;
4728
+ }
4729
+ log(`
4730
+ \u26A0 Update failed. Try manually: npm i -g ${PACKAGE_NAME}@latest`);
4731
+ } catch {
4732
+ }
4733
+ }
4734
+ function withTimeout(promise, ms) {
4735
+ return new Promise((resolve3, reject) => {
4736
+ const timer = setTimeout(
4737
+ () => reject(new Error("update check timed out")),
4738
+ ms
4739
+ );
4740
+ if (typeof timer.unref === "function") timer.unref();
4741
+ promise.then(
4742
+ (value) => {
4743
+ clearTimeout(timer);
4744
+ resolve3(value);
4745
+ },
4746
+ (err) => {
4747
+ clearTimeout(timer);
4748
+ reject(err);
4749
+ }
4750
+ );
4751
+ });
4752
+ }
4753
+ function defaultIsInteractive() {
4754
+ if (process.env.NO_UPDATE_NOTIFIER) return false;
4755
+ if (process.env.CI) return false;
4756
+ return Boolean(process.stdout.isTTY && process.stdin.isTTY);
4757
+ }
4758
+ function isCacheFresh(cache, nowMs) {
4759
+ if (!cache.lastCheckedAt) return false;
4760
+ const last = new Date(cache.lastCheckedAt).getTime();
4761
+ if (Number.isNaN(last)) return false;
4762
+ return nowMs - last < CHECK_TTL_MS;
4763
+ }
4764
+ function readCache() {
4765
+ try {
4766
+ if (!fs9.existsSync(CACHE_PATH)) return {};
4767
+ return JSON.parse(fs9.readFileSync(CACHE_PATH, "utf8"));
4768
+ } catch {
4769
+ return {};
4770
+ }
4771
+ }
4772
+ function writeCache(cache) {
4773
+ try {
4774
+ fs9.mkdirSync(path9.dirname(CACHE_PATH), { recursive: true, mode: 448 });
4775
+ fs9.writeFileSync(CACHE_PATH, JSON.stringify(cache, null, 2), "utf8");
4776
+ } catch {
4777
+ }
4778
+ }
4779
+ async function defaultPromptYesNo(question) {
4780
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
4781
+ try {
4782
+ const answer = (await rl.question(question)).trim().toLowerCase();
4783
+ return answer === "y" || answer === "yes";
4784
+ } finally {
4785
+ rl.close();
4786
+ }
4787
+ }
4788
+ function defaultRunUpdate() {
4789
+ const result = spawnSync("npm", ["install", "-g", `${PACKAGE_NAME}@latest`], {
4790
+ stdio: "inherit",
4791
+ shell: process.platform === "win32"
4792
+ });
4793
+ return result.status === 0;
4794
+ }
4795
+
4626
4796
  // _apps/@onklave/agent-cli/src/main.ts
4627
- var VERSION = "0.1.0";
4797
+ var VERSION = getCurrentVersion();
4628
4798
  function showHelp() {
4629
4799
  console.log(
4630
4800
  `
@@ -4681,6 +4851,7 @@ async function main() {
4681
4851
  process.exitCode = 1;
4682
4852
  return;
4683
4853
  }
4854
+ await maybeNotifyUpdate({ currentVersion: VERSION });
4684
4855
  const commandArgs = args.slice(1);
4685
4856
  if (commandArgs.includes("--help") || commandArgs.includes("-h")) {
4686
4857
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onklave/agent-cli",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "Onklave Agent CLI — local agent runner with cloud orchestration",
5
5
  "bin": {
6
6
  "onklave": "./main.js"