dahrk-node 0.1.15 → 0.1.16

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/dist/main.js +63 -20
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1354,7 +1354,9 @@ async function defaultCreatePiSession(ctx) {
1354
1354
  let model;
1355
1355
  if (ctx.config.model) {
1356
1356
  const resolved = resolveCliModel({ cliModel: ctx.config.model, modelRegistry });
1357
- if (!resolved?.error) model = resolved?.model;
1357
+ if (!resolved?.error) {
1358
+ model = pickAuthedModel(resolved?.model, modelRegistry.getAvailable());
1359
+ }
1358
1360
  }
1359
1361
  const stageComplete = defineTool({
1360
1362
  name: PI_STAGE_COMPLETE_TOOL,
@@ -1379,6 +1381,17 @@ var PROVIDER_BY_ENV = {
1379
1381
  GEMINI_API_KEY: "google",
1380
1382
  GOOGLE_API_KEY: "google"
1381
1383
  };
1384
+ function modelFamily(id) {
1385
+ const last = id.split(".").pop() ?? id;
1386
+ return last.replace(/-v\d+:\d+$/, "").toLowerCase();
1387
+ }
1388
+ function pickAuthedModel(resolved, available) {
1389
+ if (!resolved || !available?.length) return resolved;
1390
+ const providers = new Set(available.map((m) => m.provider));
1391
+ if (providers.has(resolved.provider)) return resolved;
1392
+ const family = modelFamily(resolved.id);
1393
+ return available.find((m) => modelFamily(m.id) === family) ?? resolved;
1394
+ }
1382
1395
 
1383
1396
  // ../../packages/executor-worktree/src/git-service.ts
1384
1397
  import { execFileSync } from "child_process";
@@ -6265,6 +6278,7 @@ async function runUpdate(inputs, deps = {}) {
6265
6278
  d.out(hint(`You are on ${current}. See https://www.npmjs.com/package/dahrk-node for releases.`));
6266
6279
  return 1;
6267
6280
  }
6281
+ d.saveResult({ updateCheckedAt: new Date(d.now()).toISOString(), updateLatest: latest });
6268
6282
  if (!isNewer(latest, current)) {
6269
6283
  d.out(verdict("ok", `Already on the latest version (${current}).`));
6270
6284
  return 0;
@@ -6352,6 +6366,10 @@ var defaultDeps4 = () => ({
6352
6366
  binPath: process.argv[1],
6353
6367
  fetchLatest: fetchLatestVersion,
6354
6368
  runUpgrade: spawnUpgrade,
6369
+ // The same cache the daemon's periodic check writes (`updateCheckDeps` in main.ts), so both writers agree
6370
+ // on where "what the registry last said" lives and `status` has one place to read it from.
6371
+ saveResult: (patch) => writeState(process.env, patch),
6372
+ now: () => Date.now(),
6355
6373
  nodeRunning: nodeIsRunning,
6356
6374
  interactive: isInteractive,
6357
6375
  confirm,
@@ -6367,7 +6385,8 @@ var defaultDeps4 = () => ({
6367
6385
  });
6368
6386
 
6369
6387
  // src/update-check.ts
6370
- var DEFAULT_INTERVAL_MS = 24 * 60 * 60 * 1e3;
6388
+ var DEFAULT_INTERVAL_MS = 6 * 60 * 60 * 1e3;
6389
+ var STALE_AFTER_INTERVALS = 4;
6371
6390
  var FETCH_TIMEOUT_MS = 1500;
6372
6391
  function checkSuppressed(env) {
6373
6392
  return Boolean(env.DAHRK_NO_UPDATE_CHECK || env.NO_UPDATE_NOTIFIER || env.CI);
@@ -6400,7 +6419,8 @@ async function checkForUpdate(currentVersion, deps) {
6400
6419
  if (checkSuppressed(deps.env)) return void 0;
6401
6420
  const state = deps.readState();
6402
6421
  if (!shouldCheck(deps.now(), state.updateCheckedAt, checkIntervalMs(deps.env), deps.env)) {
6403
- return cachedUpdate(state, currentVersion, deps.binPath);
6422
+ const cached = cachedUpdate(state, currentVersion, deps.binPath);
6423
+ return cached.kind === "available" ? cached : void 0;
6404
6424
  }
6405
6425
  let latest;
6406
6426
  try {
@@ -6412,10 +6432,12 @@ async function checkForUpdate(currentVersion, deps) {
6412
6432
  if (!isNewer(latest, currentVersion)) return void 0;
6413
6433
  return { current: currentVersion, latest, channel: detectChannel(deps.binPath) };
6414
6434
  }
6435
+ var isStale = (checkedAt, now, intervalMs) => now - checkedAt >= intervalMs * STALE_AFTER_INTERVALS;
6415
6436
  function cachedUpdate(state, currentVersion, binPath) {
6416
- const latest = state.updateLatest;
6417
- if (!latest || !isNewer(latest, currentVersion)) return void 0;
6418
- return { current: currentVersion, latest, channel: detectChannel(binPath) };
6437
+ const { updateLatest: latest, updateCheckedAt } = state;
6438
+ const checkedAt = updateCheckedAt ? Date.parse(updateCheckedAt) : NaN;
6439
+ if (!latest || !Number.isFinite(checkedAt)) return { kind: "unknown" };
6440
+ return isNewer(latest, currentVersion) ? { kind: "available", checkedAt, current: currentVersion, latest, channel: detectChannel(binPath) } : { kind: "current", checkedAt };
6419
6441
  }
6420
6442
 
6421
6443
  // src/status.ts
@@ -6454,7 +6476,13 @@ function presenceHints(f) {
6454
6476
  }
6455
6477
  function renderStatus(f) {
6456
6478
  const v = presenceVerdict(f);
6457
- const lines = ["", verdict(v.level, v.text), ""];
6479
+ const lines = ["", verdict(v.level, v.text)];
6480
+ if (f.update?.kind === "available") {
6481
+ lines.push(
6482
+ verdict("warn", `Update available: ${f.clientVersion} ${arrow()} ${f.update.latest}`) + ` ${dim("run `dahrk update`")}`
6483
+ );
6484
+ }
6485
+ lines.push("");
6458
6486
  const { nodeId, name, tenantId, enrolToken } = f.state;
6459
6487
  if (enrolToken) {
6460
6488
  const who = name ? name : "yes";
@@ -6465,12 +6493,7 @@ function renderStatus(f) {
6465
6493
  lines.push(kv("Enrolled", `no ${dim("run `dahrk start --token <token>` once to enrol")}`));
6466
6494
  }
6467
6495
  lines.push(kv("Node id", nodeId ?? dim("not yet minted (first `dahrk start` mints one)")));
6468
- lines.push(
6469
- kv(
6470
- "Client",
6471
- f.update ? `${f.clientVersion} ${dim(`(update available: ${f.update.latest} - run \`dahrk update\`)`)}` : f.clientVersion
6472
- )
6473
- );
6496
+ lines.push(kv("Client", `${f.clientVersion}${currency(f)}`));
6474
6497
  const conn = f.connection ? ` ${dim(`(${f.connection.event} ${ago(f.now - f.connection.at)}${f.connection.detail ? `, ${f.connection.detail}` : ""})`)}` : "";
6475
6498
  lines.push(kv("Hub", `${f.hubUrl}${conn}`));
6476
6499
  const installed = f.runtimes.filter((r) => r.installed);
@@ -6491,6 +6514,19 @@ function renderStatus(f) {
6491
6514
  lines.push("", dim(` State file: ${f.stateFile}`));
6492
6515
  return lines;
6493
6516
  }
6517
+ function currency(f) {
6518
+ const u = f.update;
6519
+ if (!u) return "";
6520
+ if (u.kind === "unknown") {
6521
+ return ` ${dim("update status unknown - run `dahrk update --check`")}`;
6522
+ }
6523
+ const age = ago(f.now - u.checkedAt);
6524
+ if (isStale(u.checkedAt, f.now, f.updateIntervalMs)) {
6525
+ return ` ${dim(`as of ${age} - run \`dahrk update --check\` to refresh`)}`;
6526
+ }
6527
+ if (u.kind === "available") return ` ${dim(`(checked ${age})`)}`;
6528
+ return ` ${symbol("ok")} ${dim(`up to date (checked ${age})`)}`;
6529
+ }
6494
6530
  function jobLine(j, now) {
6495
6531
  const where = j.stageId ? `${j.runId} ${dim("/")} ${j.stageId}` : `${j.runId} ${dim(`(${j.kind})`)}`;
6496
6532
  return `${where} ${dim(humanDuration(now - j.startedAt))}`;
@@ -6530,6 +6566,7 @@ async function gatherFacts(inputs, deps) {
6530
6566
  runtimes: await deps.probeRuntimes(),
6531
6567
  presence,
6532
6568
  jobs,
6569
+ updateIntervalMs: checkIntervalMs(deps.env),
6533
6570
  now: deps.now(),
6534
6571
  ...service ? { service } : {},
6535
6572
  ...connection ? { connection } : {},
@@ -6567,7 +6604,7 @@ async function runStatus(inputs, deps) {
6567
6604
  }
6568
6605
 
6569
6606
  // src/main.ts
6570
- var CLIENT_VERSION = "0.1.15";
6607
+ var CLIENT_VERSION = "0.1.16";
6571
6608
  var DEFAULT_HUB_URL = "wss://api.dahrk.ai";
6572
6609
  var list = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
6573
6610
  var RUNTIMES2 = ["claude-code", "codex", "pi"];
@@ -6757,6 +6794,9 @@ async function stop(env, force) {
6757
6794
  if (code === 0 || code === STOP_FOREIGN_NODE) setDesired(env, "stopped");
6758
6795
  return code;
6759
6796
  }
6797
+ var updateStateDeps = (env) => ({
6798
+ saveResult: (patch) => writeState(env, patch)
6799
+ });
6760
6800
  function updateCheckDeps(env) {
6761
6801
  return {
6762
6802
  env,
@@ -6774,7 +6814,7 @@ async function offerUpdate(env) {
6774
6814
  out(renderUpdateNotice(available));
6775
6815
  if (!isInteractive()) return;
6776
6816
  if (!await confirm("Update now?")) return;
6777
- const code = await runUpdate({ currentVersion: CLIENT_VERSION, check: false });
6817
+ const code = await runUpdate({ currentVersion: CLIENT_VERSION, check: false }, updateStateDeps(env));
6778
6818
  if (code !== 0) out(hint("Update failed; starting the node on the current version anyway."));
6779
6819
  }
6780
6820
  function scheduleUpdateChecks(env) {
@@ -6924,11 +6964,14 @@ async function main() {
6924
6964
  break;
6925
6965
  }
6926
6966
  case "update":
6927
- process.exitCode = await runUpdate({
6928
- currentVersion: CLIENT_VERSION,
6929
- check: parsed.flags.check,
6930
- verbose: parsed.flags.verbose
6931
- });
6967
+ process.exitCode = await runUpdate(
6968
+ {
6969
+ currentVersion: CLIENT_VERSION,
6970
+ check: parsed.flags.check,
6971
+ verbose: parsed.flags.verbose
6972
+ },
6973
+ updateStateDeps(applyEnvAliases(process.env))
6974
+ );
6932
6975
  break;
6933
6976
  case "start":
6934
6977
  process.exitCode = await start(parsed.flags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dahrk-node",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",