@mnemom/mnemom 0.17.9-next.0 → 0.17.10

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.
@@ -6,22 +6,24 @@
6
6
  * governed identity `agent-<handle>`. This module makes that identity REAL in
7
7
  * their Mnemom org: it births the agent through the gateway, claims it (so the
8
8
  * customer owns it), and publishes a sane default coding posture. The CARDS are
9
- * observe-only (visibility, no active intervention); the goal contract is what
10
- * nudges (re-anchor on drift). Specifically:
11
- * - alignment card: autonomy_mode + integrity_mode = observe,
9
+ * OFF by default (operator 2026-10-02: alignment and protection analysis are
10
+ * billed, so nobody pays for them until they turn them on); the goal contract is
11
+ * what nudges (re-anchor on drift). Specifically:
12
+ * - alignment card: autonomy_mode + integrity_mode = off,
12
13
  * principal.relationship = delegated_authority, coding bounded/forbidden
13
14
  * actions, escalate-on-irreversible;
14
- * - protection card: mode = observe, thresholds 0.60/0.80/0.95, all four
15
- * screen_surfaces on (screened for observation).
15
+ * - protection card: mode = off, thresholds 0.60/0.80/0.95 and all four
16
+ * screen_surfaces declared, ready for when it is turned on.
16
17
  * - goal-alignment: nudge — sealed per-conversation via the goal contract
17
18
  * (--goal …), graded and re-anchored by the gateway.
18
19
  *
19
- * All account writes are gated: interactive runs show the plan and confirm;
20
- * non-interactive runs provision only with an explicit `--setup`, and otherwise
21
- * launch under the unclaimed (fail-open) identity with a clear warning. A
22
- * provisioning failure never blocks the launch. Reuses the existing machinery —
23
- * birthThroughGateway (wrap.ts), deriveHashProof (agents.ts), claimAgent +
24
- * putAlignmentCard/putProtectionCard (lib/api.ts) — rather than reinventing it.
20
+ * A launch never runs on an unclaimed agent (operator 2026-10-03): an unclaimed agent lands in
21
+ * the sandbox org and bills nobody. ensureClaimedServedAgent asks the gateway which agent it
22
+ * serves for this launch's credential + name, claims it into the org the launch bills when it
23
+ * is not claimed yet, and refuses otherwise — interactive or not, there is no unclaimed
24
+ * fallback. Reuses the existing machinery — birthThroughGateway (wrap.ts), deriveHashProof
25
+ * (agents.ts), claimAgent + putAlignmentCard/putProtectionCard (lib/api.ts) — rather than
26
+ * reinventing it.
25
27
  */
26
28
  import { type CodeEntitlement } from "../lib/api.js";
27
29
  /**
@@ -47,58 +49,75 @@ export declare function resolveDefaultSlug(opts?: {
47
49
  strict?: boolean;
48
50
  }): Promise<string>;
49
51
  /**
50
- * Thrown when a name-matched agent in the caller's org is NOT the agent the
51
- * gateway serves for (credential, name). Both ids are in the message; the
52
- * launcher treats it as fatal on an explicit `--setup` (MNE-7650).
52
+ * `mnemom agent` refuses to launch: the agent the gateway would serve is not claimed and could
53
+ * not be claimed here (or could not be identified at all). An unclaimed agent lands in the
54
+ * sandbox org and bills nobody, so there is no fallback — the message says what to do.
53
55
  */
54
- export declare class AgentIdentityMismatchError extends Error {
55
- readonly slug: string;
56
- /** The agent the org lookup found by name. */
57
- readonly namedId: string;
58
- /** The agent the gateway answered with on x-mnemom-agent. */
59
- readonly servedId: string;
60
- constructor(slug: string,
61
- /** The agent the org lookup found by name. */
62
- namedId: string,
63
- /** The agent the gateway answered with on x-mnemom-agent. */
64
- servedId: string);
56
+ export declare class UnclaimedAgentError extends Error {
57
+ constructor(message: string);
65
58
  }
66
- export interface EnsureAgentOptions {
59
+ export interface ClaimedAgentOptions {
67
60
  /** The already-resolved final agent slug (what rides as x-mnemom-agent). */
68
61
  slug: string;
69
- /** The customer's Anthropic key (for the birth call + hash-proof). Never logged. */
70
- anthropicKey: string;
71
- /** undefined = auto, true = force (--setup), false handled by the caller (skip). */
72
- setup?: boolean;
73
- /** Gateway host the launch targets (birth goes to the same cell). */
62
+ /** Anthropic-key launch: the key that anchors the gateway identity. Never logged. */
63
+ anthropicKey?: string;
64
+ /** Subscription launch: the Mnemom API key that anchors the gateway identity. Never logged. */
65
+ mnemomKey?: string;
66
+ /** Gateway host the launch targets (the probe goes to the same cell). */
74
67
  gatewayHost: string;
75
- /** Override interactivity (defaults to isInteractive()). */
76
- interactive?: boolean;
68
+ /**
69
+ * The org this launch bills — the one ensureSessionAndBalance resolved and checked the µ of.
70
+ * A claim lands here. The active/default org is never changed.
71
+ */
72
+ orgId: string;
73
+ orgLabel: string;
74
+ /** true = --setup (re-ask the gateway, refresh the cards); false = --no-setup (no card writes). */
75
+ setup?: boolean;
77
76
  /** Where the served-agent cache lives (defaults to ~/.mnemom). */
78
77
  cacheDir?: string;
79
78
  }
80
79
  /** A bare launch never waits on the served-agent probe longer than this. */
81
80
  export declare const SERVED_PROBE_TIMEOUT_MS = 10000;
82
- export interface EnsureAgentResult {
81
+ /**
82
+ * The waits between the tries of a call that failed transiently (network, timeout, 429, 5xx):
83
+ * three tries, about four seconds of backoff. Exported so tests can zero it.
84
+ */
85
+ export declare const CONFIRM_RETRY_DELAYS_MS: number[];
86
+ export interface ClaimedAgentResult {
83
87
  slug: string;
84
- /** true only when this call actually birthed/claimed/published. */
85
- provisioned: boolean;
86
- /**
87
- * The mnm- id the gateway serves for (key, slug), when this call learned it (a verified name
88
- * match, a mismatch, or a fresh birth). Absent when it never asked the gateway.
89
- */
90
- agentId?: string;
88
+ /** The mnm- id the gateway serves for (credential, slug) — claimed when this returns. */
89
+ agentId: string;
90
+ /** true only when this call claimed it. */
91
+ claimedNow: boolean;
91
92
  }
92
93
  /**
93
- * Ensure `slug` is a usable governed agent in the customer's org. Returns
94
- * {provisioned:false} when it is already usable, when provisioning is not
95
- * allowed here (non-interactive without --setup, or not logged in), or when the
96
- * customer declines the confirm — in all those cases the launch continues under
97
- * the given slug. THROWS only on an actual provisioning failure (birth/claim/
98
- * card write) so the caller can decide whether that is fatal (`mnemom agent
99
- * setup`) or a warn-and-continue (a bare launch).
94
+ * A failure worth retrying, and that an outage fallback may cover: no answer at all (network,
95
+ * timeout, an unparseable reply) or a 408/429/5xx. A 4xx, a missing route, or a refusal is a
96
+ * definite answer.
97
+ */
98
+ export declare function isTransient(err: unknown): boolean;
99
+ /**
100
+ * The one invariant behind every `mnemom agent` launch: the coding CLI never starts unless the
101
+ * agent the gateway serves for THIS launch's credential + name is claimed.
102
+ *
103
+ * 1. Ask which agent the gateway serves (an Anthropic-key launch: the birth probe, cached per
104
+ * key + name + gateway; a subscription launch: the gateway's identity route).
105
+ * 2. Read its claim state. Claimed ⇒ launch, and never claim it again: a re-claim by its owner
106
+ * MOVES it to the requested org.
107
+ * 3. Unclaimed ⇒ claim it into `orgId` with the hash proof of the key that anchors it. Another
108
+ * account owns it ⇒ refuse; any other claim failure ⇒ refuse.
109
+ *
110
+ * A definite answer (unclaimed and can't be claimed, owned by another account, the identity
111
+ * route missing, a rejected key) always refuses. A transient failure is retried; if Mnemom still
112
+ * can't be reached, the launch uses the agent this machine last confirmed claimed for the same
113
+ * credential + name — and only when the gateway hasn't since named a different one — or
114
+ * refuses. There is deliberately no switch that launches unclaimed (operator ruling 2026-10-03).
115
+ *
116
+ * Interactive and non-interactive runs behave the same: there is no prompt to decline.
117
+ * MNE-7650: the name is client-controlled, so a same-named org agent proves nothing — only the
118
+ * served id counts.
100
119
  */
101
- export declare function ensureGovernedAgent(opts: EnsureAgentOptions): Promise<EnsureAgentResult>;
120
+ export declare function ensureClaimedServedAgent(opts: ClaimedAgentOptions): Promise<ClaimedAgentResult>;
102
121
  /**
103
122
  * One line for an api failure that keeps the parts an operator can act on: the
104
123
  * message, the error code, and the scope the endpoint said it needed