@proagentstore/cli 0.4.64 → 0.4.65

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/index.js +15 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1298,6 +1298,13 @@ function partitionByPin(instances, thisNode, alsoKnownAs = []) {
1298
1298
  for (const inst of instances) (isEligible(inst, thisNode, alsoKnownAs) ? here : elsewhere).push(inst);
1299
1299
  return { here, elsewhere };
1300
1300
  }
1301
+ function pinnedAway(held, instances, thisNode, alsoKnownAs = []) {
1302
+ const pins = new Map(instances.map((i) => [i.id, i.config?.runnerNode]));
1303
+ return [...held].filter((id) => {
1304
+ const pin = pins.get(id);
1305
+ return !!pin && pin !== thisNode && !alsoKnownAs.includes(pin);
1306
+ });
1307
+ }
1301
1308
  function registrationStatus(attached, registered) {
1302
1309
  const ids = [...attached];
1303
1310
  const have = ids.filter((id) => registered.has(id)).length;
@@ -1311,6 +1318,7 @@ function instanceLabel(inst) {
1311
1318
  function reattachPlan(request, state) {
1312
1319
  const target = typeof request?.attach === "string" && request.attach ? request.attach : null;
1313
1320
  const force = target !== null && request?.force === true;
1321
+ if (!state.watching && !target) return { target, unblock: false, detach: false, force: false, release: true };
1314
1322
  if (!state.watching && !(target && state.scope.includes(target))) {
1315
1323
  return {
1316
1324
  target,
@@ -1459,6 +1467,13 @@ async function connectViaRelay(instanceIds, localUrl, runnerToken, opts, force =
1459
1467
  const named = typeof request?.attach === "string" ? request.attach : "";
1460
1468
  const plan = reattachPlan(request, { held: attached.has(named), blocked: blocked.has(named), watching: watchInstances, scope: instanceIds });
1461
1469
  if (plan.refuse) return { status: 409, result: { error: plan.refuse } };
1470
+ if (plan.release) {
1471
+ const res = await requestPags("GET", "/v1/instances/my/instances", { ...opts, pagsToken });
1472
+ const released = pinnedAway(attached.keys(), res.instances ?? [], runnerNode, machine.names);
1473
+ for (const id of released) detach(id, `${id.slice(0, 8)}\u2026 (pinned to another machine now)`);
1474
+ if (released.length && attached.size === 0) writeLine("This `pags up --instance` holds no agent now \u2014 close it, or restart it without --instance.");
1475
+ return { status: 200, result: { attached: [...attached.keys()], released } };
1476
+ }
1462
1477
  if (plan.target) {
1463
1478
  if (plan.unblock) blocked.delete(plan.target);
1464
1479
  if (plan.detach) detach(plan.target);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proagentstore/cli",
3
- "version": "0.4.64",
3
+ "version": "0.4.65",
4
4
  "description": "CLI for creating, publishing, and running ProAgentStore agents",
5
5
  "license": "MIT",
6
6
  "type": "module",