@dench.com/cli 2.7.2 → 2.7.3

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 (3) hide show
  1. package/dench.ts +11 -4
  2. package/package.json +1 -1
  3. package/session.ts +20 -0
package/dench.ts CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  type StoredSessionEntry,
41
41
  selectStoredSession,
42
42
  selectStoredSessionEntry,
43
+ usesInjectedAgentSession,
43
44
  withCurrentSessionSelection,
44
45
  withSavedSession,
45
46
  } from "./session";
@@ -2392,7 +2393,13 @@ async function getRuntime() {
2392
2393
  if (!hasFlag("--dev")) {
2393
2394
  const config = await loadConfig();
2394
2395
  const host = resolveHost(config, scope);
2395
- const stored = await getStoredSession(host, scope);
2396
+
2397
+ // An injected agent-session token outranks whatever `dench signin` last
2398
+ // saved here — see `usesInjectedAgentSession` for why the API key does not
2399
+ // get the same treatment.
2400
+ const stored = usesInjectedAgentSession()
2401
+ ? ({ status: "missing" } as const)
2402
+ : await getStoredSession(host, scope);
2396
2403
  if (stored.status === "found") {
2397
2404
  return {
2398
2405
  mode: "session" as const,
@@ -2451,9 +2458,9 @@ async function getRuntime() {
2451
2458
  };
2452
2459
  }
2453
2460
 
2454
- // Fallback: no API key present (older sandbox images / custom setups)
2455
- // use the agent-session token. Still subject to expiry, but it's the
2456
- // only credential available in this branch.
2461
+ // No API key present: an older sandbox image, a custom setup, or Dench
2462
+ // Code, which injects only this token. Still subject to expiry, but it is
2463
+ // the only credential available in this branch.
2457
2464
  const sandboxAgentToken = process.env.DENCH_AGENT_SESSION_TOKEN?.trim();
2458
2465
  if (sandboxAgentToken && sandboxConvexUrl) {
2459
2466
  const apiHost = resolveApiHost(host);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "2.7.2",
3
+ "version": "2.7.3",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/session.ts CHANGED
@@ -208,6 +208,26 @@ export function resolveSessionScope({
208
208
  };
209
209
  }
210
210
 
211
+ /**
212
+ * Whether an injected agent-session token should stand in for a saved
213
+ * `dench signin` session.
214
+ *
215
+ * `DENCH_AGENT_SESSION_TOKEN` names which identity to act as, so it outranks
216
+ * whatever was last saved on the host. Only sandboxes and Dench Code set it —
217
+ * nobody exports it by hand — and without this a host with any saved session
218
+ * silently ignores it, or fails as `session_ambiguous` when several are saved.
219
+ *
220
+ * `DENCH_API_KEY` deliberately does not qualify. People export that one
221
+ * manually for unrelated reasons, and quietly swapping their identity would be
222
+ * a surprise. Sandboxes set both and have no saved session anyway, so they
223
+ * keep landing on the API key, which is what they want: the key has no TTL
224
+ * while the agent-session token expires.
225
+ */
226
+ export function usesInjectedAgentSession(env: Env = process.env) {
227
+ if (env.DENCH_API_KEY?.trim()) return false;
228
+ return Boolean(env.DENCH_AGENT_SESSION_TOKEN?.trim());
229
+ }
230
+
211
231
  export function sessionConfigKey(host: string, scope: SessionScope) {
212
232
  return `${normalizeHostValue(host)}#${scope.key}`;
213
233
  }