@mnemom/mnemom 0.17.0-next.5 → 0.17.0-next.6

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.
@@ -29,6 +29,14 @@
29
29
  * "user" when no email is available (API-key auth / opaque OAuth token).
30
30
  */
31
31
  export declare function defaultAgentSlug(): string;
32
+ /**
33
+ * The default slug resolved from the authenticated IDENTITY: `code-<handle>` from
34
+ * the login email fetched via `/v1/auth/me`. The CLI's stored OAuth token carries
35
+ * no email, so the sync `defaultAgentSlug()` alone falls back to "code-user";
36
+ * this fetches the real email once a session exists. Falls back to
37
+ * `defaultAgentSlug()` on any failure. Call it AFTER the session is ensured.
38
+ */
39
+ export declare function resolveDefaultSlug(): Promise<string>;
32
40
  export interface EnsureAgentOptions {
33
41
  /** The already-resolved final agent slug (what rides as x-mnemom-agent). */
34
42
  slug: string;
@@ -23,7 +23,7 @@
23
23
  * birthThroughGateway (wrap.ts), deriveHashProof (agents.ts), claimAgent +
24
24
  * putAlignmentCard/putProtectionCard (lib/api.ts) — rather than reinventing it.
25
25
  */
26
- import { claimAgent, getAgentByName, getMuBalance, getMyPersonalOrg, MnemomApiError, mintProtectionCapability, putAlignmentCard, putProtectionCard, } from "../lib/api.js";
26
+ import { claimAgent, getAgentByName, getMe, getMuBalance, getMyPersonalOrg, MnemomApiError, mintProtectionCapability, putAlignmentCard, putProtectionCard, } from "../lib/api.js";
27
27
  import { getAuthInfo, isLoggedIn, loginWithBrowser, loginWithDeviceFlow, resolveAuth, } from "../lib/auth.js";
28
28
  import { getActiveOrg } from "../lib/cli-config.js";
29
29
  import { getWebsiteUrl } from "../lib/config.js";
@@ -47,6 +47,25 @@ export function defaultAgentSlug() {
47
47
  const handle = sanitizeAgentName(local) || "user";
48
48
  return `code-${handle}`;
49
49
  }
50
+ /**
51
+ * The default slug resolved from the authenticated IDENTITY: `code-<handle>` from
52
+ * the login email fetched via `/v1/auth/me`. The CLI's stored OAuth token carries
53
+ * no email, so the sync `defaultAgentSlug()` alone falls back to "code-user";
54
+ * this fetches the real email once a session exists. Falls back to
55
+ * `defaultAgentSlug()` on any failure. Call it AFTER the session is ensured.
56
+ */
57
+ export async function resolveDefaultSlug() {
58
+ try {
59
+ const email = (await getMe()).email ?? "";
60
+ const handle = sanitizeAgentName(email.split("@")[0] ?? "");
61
+ if (handle)
62
+ return `code-${handle}`;
63
+ }
64
+ catch {
65
+ // fall through to the token-based best-effort
66
+ }
67
+ return defaultAgentSlug();
68
+ }
50
69
  /**
51
70
  * Ensure `slug` is a usable governed agent in the customer's org. Returns
52
71
  * {provisioned:false} when it is already usable, when provisioning is not
@@ -190,7 +209,8 @@ export async function codeSetupCommand(opts = {}) {
190
209
  throw err;
191
210
  }
192
211
  const anthropicKey = await resolveAnthropicKey(process.env, { allowPrompt: true });
193
- const slug = opts.agent?.trim() ? sanitizeAgentName(opts.agent.trim()) : defaultAgentSlug();
212
+ // Session exists now, so derive the real handle from /v1/auth/me (not "code-user").
213
+ const slug = opts.agent?.trim() ? sanitizeAgentName(opts.agent.trim()) : await resolveDefaultSlug();
194
214
  if (!slug)
195
215
  throw new Error("mnemom code setup: agent slug sanitised to empty — pass --agent <slug>.");
196
216
  const result = await ensureGovernedAgent({ slug, anthropicKey, setup: true, gatewayHost });
@@ -35,7 +35,7 @@ import { configKeySpec, loadCodeConfig, writeCodeConfig } from "../lib/code-conf
35
35
  import { fmt } from "../lib/format.js";
36
36
  import { askInput, askYesNo, isInteractive } from "../lib/prompt.js";
37
37
  import { goalAlignmentLine, resolveSessionSetup } from "./code-session.js";
38
- import { defaultAgentSlug, ensureGovernedAgent, ensureSessionAndBalance, isQuietPreambleExit, } from "./code-setup.js";
38
+ import { defaultAgentSlug, ensureGovernedAgent, ensureSessionAndBalance, isQuietPreambleExit, resolveDefaultSlug, } from "./code-setup.js";
39
39
  import { assembleContract, buildCustomHeaders, isProdGateway, launchPreferenceExplicit, resolveAnthropicDoor, resolveConversationId, resolveGatewayHost, resolveLaunchShape, sanitizeAgentName, } from "../lib/code.js";
40
40
  /** The CLI's own provider-key store (zero 1Password): ~/.mnemom/code.json, 0600. */
41
41
  const CODE_STORE = join(MNEMOM_DIR, "code.json");
@@ -148,10 +148,11 @@ export async function codeCommand(scenarioArg, options = {}) {
148
148
  process.exit(1); // guidance already printed
149
149
  throw err;
150
150
  }
151
- // Now that a session exists, a defaulted slug can use the real login handle
152
- // (a first-ever run computed it before sign-in, when only "code-user" was known).
151
+ // Now that a session exists, a defaulted slug uses the real login handle from
152
+ // /v1/auth/me (the stored token has no email, so the pre-sign-in value was the
153
+ // "code-user" fallback). Only when the caller didn't name an agent.
153
154
  if (!options.agent?.trim()) {
154
- const refreshed = sanitizeAgentName(defaultAgentSlug());
155
+ const refreshed = sanitizeAgentName(await resolveDefaultSlug());
155
156
  if (refreshed)
156
157
  agent = refreshed;
157
158
  }
package/dist/lib/api.d.ts CHANGED
@@ -377,6 +377,18 @@ export declare function moveAgent(agentId: string, destOrgId: string, opts?: {
377
377
  * mnemom-api migration 161 backfill.
378
378
  */
379
379
  export declare function getMyPersonalOrg(): Promise<PersonalOrgRef>;
380
+ /** The authenticated user's identity — `GET /v1/auth/me`. Carries the email the
381
+ * stored OAuth token does not, so the CLI can derive a real `code-<handle>`. */
382
+ export interface MeResponse {
383
+ user_id: string;
384
+ email?: string | null;
385
+ org?: {
386
+ org_id?: string;
387
+ name?: string;
388
+ slug?: string;
389
+ } | null;
390
+ }
391
+ export declare function getMe(): Promise<MeResponse>;
380
392
  /**
381
393
  * The org's Mnemom Units (MU) balance — `GET /v1/billing/mu` (the frozen mu
382
394
  * v0.1 balance, values as decimal strings). Amounts come in both whole MU
package/dist/lib/api.js CHANGED
@@ -375,6 +375,9 @@ export async function moveAgent(agentId, destOrgId, opts = {}) {
375
375
  export async function getMyPersonalOrg() {
376
376
  return gFetch("/v1/auth/me/personal-org", {}, { fallback: "API request failed" });
377
377
  }
378
+ export async function getMe() {
379
+ return gFetch("/v1/auth/me", {}, { fallback: "Could not read your identity" });
380
+ }
378
381
  export async function getMuBalance(orgId) {
379
382
  const q = orgId ? `?org_id=${encodeURIComponent(orgId)}` : "";
380
383
  return gFetch(`/v1/billing/mu${q}`, {}, { fallback: "Could not read MU balance" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnemom/mnemom",
3
- "version": "0.17.0-next.5",
3
+ "version": "0.17.0-next.6",
4
4
  "description": "Transparent AI agent tracing",
5
5
  "type": "module",
6
6
  "bin": {