@dench.com/cli 3.11.42-staging.870 → 3.11.44-staging.887

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/dench.ts CHANGED
@@ -133,6 +133,7 @@ type AgentStatus = {
133
133
  agent?: { id?: string } & JsonRecord;
134
134
  counts?: JsonRecord;
135
135
  rules?: JsonRecord[];
136
+ activeAgents?: JsonRecord[];
136
137
  };
137
138
 
138
139
  const api = {
@@ -165,6 +166,9 @@ const api = {
165
166
  pollSignInRequest: makeFunctionReference<"mutation">(
166
167
  "functions/agentWorkspace:pollSignInRequest",
167
168
  ),
169
+ revokeOwnAgentSession: makeFunctionReference<"mutation">(
170
+ "functions/agentWorkspace:revokeOwnAgentSession",
171
+ ),
168
172
  whatCanIDoHere: makeFunctionReference<"query">(
169
173
  "functions/agentWorkspace:whatCanIDoHere",
170
174
  ),
@@ -831,6 +835,7 @@ Usage:
831
835
 
832
836
  Notes:
833
837
  dench logout removes only the current selected session for this local agent context.
838
+ It also ends that sign-in on the Dench server, so its token stops working everywhere.
834
839
  Other saved sessions can still be reused by future chats until removed.
835
840
  Use dench logout --all to clear every saved Dench session on this machine.
836
841
  `);
@@ -1477,6 +1482,50 @@ async function selectSession() {
1477
1482
  );
1478
1483
  }
1479
1484
 
1485
+ const LOGOUT_REVOKE_TIMEOUT_MS = 10_000;
1486
+
1487
+ /**
1488
+ * End saved sign-ins on the server before they are removed locally, so the
1489
+ * token stops working everywhere, not just on this machine (DEN-247). Best
1490
+ * effort: a server that cannot be reached (offline, or one that predates
1491
+ * `revokeOwnAgentSession`) never blocks the local logout; it is reported as
1492
+ * `serverRevokeFailed` and the session still expires on its own.
1493
+ */
1494
+ async function revokeSessionsOnServer(sessions: StoredSession[]) {
1495
+ let revoked = 0;
1496
+ let failed = 0;
1497
+ for (const session of sessions) {
1498
+ if (!session.convexUrl || !session.sessionToken) continue;
1499
+ let timer: ReturnType<typeof setTimeout> | undefined;
1500
+ try {
1501
+ const result = (await Promise.race([
1502
+ createCliConvexClient(session.convexUrl).mutation(
1503
+ api.functions.agentWorkspace.revokeOwnAgentSession,
1504
+ { sessionToken: session.sessionToken },
1505
+ ),
1506
+ new Promise((_, reject) => {
1507
+ timer = setTimeout(
1508
+ () => reject(new Error("timed out")),
1509
+ LOGOUT_REVOKE_TIMEOUT_MS,
1510
+ );
1511
+ }),
1512
+ ])) as { revoked?: boolean } | null;
1513
+ if (result?.revoked) revoked += 1;
1514
+ } catch {
1515
+ failed += 1;
1516
+ } finally {
1517
+ if (timer) clearTimeout(timer);
1518
+ }
1519
+ }
1520
+ return { serverRevoked: revoked, serverRevokeFailed: failed };
1521
+ }
1522
+
1523
+ function serverRevokeNote(result: { serverRevokeFailed: number }) {
1524
+ const failed = result.serverRevokeFailed;
1525
+ if (failed === 0) return "";
1526
+ return `\nCould not reach Dench to end ${plural(failed, "session")} on the server; ${failed === 1 ? "it stays" : "they stay"} valid until expiry.`;
1527
+ }
1528
+
1480
1529
  async function logout() {
1481
1530
  const config = await loadConfig();
1482
1531
  const scope = resolveSessionScope({ args: filteredArgs });
@@ -1489,6 +1538,9 @@ async function logout() {
1489
1538
  }
1490
1539
  const entries = listStoredSessionEntries(config, host);
1491
1540
  const removed = entries.length;
1541
+ const server = await revokeSessionsOnServer(
1542
+ entries.map((entry) => entry.session),
1543
+ );
1492
1544
  const nextConfig = host
1493
1545
  ? removeSessionEntries(config, entries)
1494
1546
  : removeAllStoredSessions(config);
@@ -1509,13 +1561,14 @@ async function logout() {
1509
1561
  removed,
1510
1562
  all: true,
1511
1563
  host: host ?? null,
1564
+ ...server,
1512
1565
  remainingSessions: remaining.total,
1513
1566
  remainingHostSessions: remaining.forHost ?? null,
1514
1567
  nextActions: logoutNextActions(remaining, host),
1515
1568
  }
1516
1569
  : removed > 0
1517
1570
  ? formatLogoutMessage(
1518
- `Logged out of ${plural(removed, "Dench session")}.`,
1571
+ `Logged out of ${plural(removed, "Dench session")}.${serverRevokeNote(server)}`,
1519
1572
  remaining,
1520
1573
  host,
1521
1574
  )
@@ -1539,6 +1592,7 @@ async function logout() {
1539
1592
  );
1540
1593
  }
1541
1594
 
1595
+ const server = await revokeSessionsOnServer([matches[0].session]);
1542
1596
  const nextConfig = removeSessionEntries(config, matches);
1543
1597
  const remaining = logoutRemainingSummary(nextConfig, matches[0].host);
1544
1598
  await saveConfig(nextConfig);
@@ -1549,12 +1603,13 @@ async function logout() {
1549
1603
  removed: 1,
1550
1604
  all: false,
1551
1605
  sessionKey: matches[0].key,
1606
+ ...server,
1552
1607
  remainingSessions: remaining.total,
1553
1608
  remainingHostSessions: remaining.forHost ?? null,
1554
1609
  nextActions: logoutNextActions(remaining, matches[0].host),
1555
1610
  }
1556
1611
  : formatLogoutMessage(
1557
- `Logged out of Dench session ${matches[0].key}.`,
1612
+ `Logged out of Dench session ${matches[0].key}.${serverRevokeNote(server)}`,
1558
1613
  remaining,
1559
1614
  matches[0].host,
1560
1615
  ),
@@ -1584,6 +1639,7 @@ async function logout() {
1584
1639
  return;
1585
1640
  }
1586
1641
 
1642
+ const server = await revokeSessionsOnServer([result.session]);
1587
1643
  await saveConfig(result.config);
1588
1644
  const remaining = logoutRemainingSummary(result.config, resolvedHost);
1589
1645
  print(
@@ -1595,12 +1651,13 @@ async function logout() {
1595
1651
  host: resolvedHost,
1596
1652
  sessionScope: scope.label,
1597
1653
  sessionKey: result.removedKey,
1654
+ ...server,
1598
1655
  remainingSessions: remaining.total,
1599
1656
  remainingHostSessions: remaining.forHost ?? null,
1600
1657
  nextActions: logoutNextActions(remaining, resolvedHost),
1601
1658
  }
1602
1659
  : formatLogoutMessage(
1603
- `Logged out of Dench session ${result.removedKey}.`,
1660
+ `Logged out of Dench session ${result.removedKey}.${serverRevokeNote(server)}`,
1604
1661
  remaining,
1605
1662
  resolvedHost,
1606
1663
  ),
@@ -5583,13 +5640,14 @@ async function main() {
5583
5640
 
5584
5641
  if (command === "agents") {
5585
5642
  if (runtime.mode === "session" || runtime.mode === "apiKey") {
5586
- const status = await runtime.client.query(
5643
+ const status = (await runtime.client.query(
5587
5644
  api.functions.agentWorkspace.whatCanIDoHere,
5588
5645
  {
5589
5646
  sessionToken: runtime.sessionToken,
5590
5647
  },
5591
- );
5592
- print(status.agents);
5648
+ )) as AgentStatus;
5649
+ // `whatCanIDoHere` names the list `activeAgents`; it has no `agents`.
5650
+ print(status.activeAgents ?? []);
5593
5651
  return;
5594
5652
  }
5595
5653
  const data = await devOverview(runtime);
@@ -810,7 +810,8 @@ const rawApiOperations = [
810
810
  op({
811
811
  id: "sessions.local.logout",
812
812
  group: "local",
813
- summary: "Remove local CLI sessions.",
813
+ summary:
814
+ "Sign out: end CLI sessions on the server and remove them locally.",
814
815
  cli: "dench logout",
815
816
  method: "POST",
816
817
  path: "/local/logout",