@antasphere/cli-core 0.4.0 → 0.5.0

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.
@@ -5,12 +5,16 @@ import type { ResolvedProfile } from './resolve.js';
5
5
  * Connect-on-demand (binding patterns §7, gcloud model), extracted from the
6
6
  * Slideless CLI so every Antasphere tool CLI inherits "one `antasphere login`
7
7
  * serves every federated tool". When a tool CLI resolves NO credential of its
8
- * own, it calls `connectOnDemand`:
8
+ * own, it calls `connectOnDemand` with the profile it selected
9
+ * (`selectProfile`: the profile IS the instance):
9
10
  *
10
11
  * 0. The cache is consulted FIRST: a key minted earlier for THIS instance
11
12
  * under the active hub profile is USER-scoped (hub ADR 014) — it serves
12
13
  * every subsequent run and every org, with zero network (no probe, no
13
- * hub round-trip, no fresh mint).
14
+ * hub round-trip, no fresh mint). It is read on the selected profile
15
+ * only when that profile is at the resolved instance (its `baseUrl`,
16
+ * else the tool's `cloudUrl` when the profile has none), so a cached
17
+ * key never travels to another origin. `cached: false` skips this step.
14
18
  * 1. On a miss, discovery gates the flow: only an Antasphere-CLOUD
15
19
  * instance can mint keys through the hub (unauthenticated GET
16
20
  * /instance — never guess). Unreachable, foreign, or self-hosted
@@ -21,13 +25,22 @@ import type { ResolvedProfile } from './resolve.js';
21
25
  * never a hardcoded constant here.
22
26
  * 3. `CliConnectClient.exchange` trades it for a tool-local key (one
23
27
  * re-exchange retry when the 120 s JWT dies in transit; a rejected hub
24
- * credential maps to guided `antasphere login` advice).
25
- * 4. The minted key is cached per (tool, HUB PROFILE) — but only onto a
26
- * profile that names THIS instance (a fresh profile gets pinned to it);
27
- * a profile pointing elsewhere never receives it.
28
+ * credential maps to guided `antasphere login` advice on either
29
+ * attempt; a hub REFUSAL, a 403 that is not the scope case, propagates
30
+ * as its `CliConnectError` with the hub's own sentence and `exitCode`
31
+ * 3).
32
+ * 4. The minted key is cached on the SELECTED profile under the hub
33
+ * profile's name. A profile not on disk yet is created with this
34
+ * instance's URL, and made active only when the tool had no profile at
35
+ * all; an existing profile is never renamed or repointed, and one that
36
+ * is at another instance never receives the key.
28
37
  *
29
- * A new tool needs only its namespace, base URL, and copy — the flow itself
30
- * is tool-agnostic.
38
+ * A stranded key recovers: on a 401 with a key that came from the cache,
39
+ * the tool CLI calls `refreshConnectKey` once (evict, exchange again with
40
+ * `cached: false`) and retries its request once; a second 401 fails.
41
+ *
42
+ * A new tool needs only its namespace, its cloud URL, and copy — the flow
43
+ * itself is tool-agnostic.
31
44
  */
32
45
  /** What the unauthenticated discovery probe learned about a tool instance. */
33
46
  export interface ToolInstanceProbe {
@@ -59,12 +72,13 @@ export interface ConnectNoticeFacts {
59
72
  toolBaseUrl: string;
60
73
  /** The signed-in account's email at mint. */
61
74
  email: string;
62
- /** Whether the minted key was persisted for the next run (per
63
- * (tool, hub profile)); false = the profile names another instance. */
75
+ /** Whether the minted key was persisted for the next run (on the
76
+ * selected profile, under the hub profile's name); false = the profile
77
+ * is at another instance. */
64
78
  stored: boolean;
65
79
  /** The tool profile the cache targeted. */
66
80
  profileName: string;
67
- /** When NOT stored: the other instance the profile points at. */
81
+ /** When NOT stored: the other instance the profile is at. */
68
82
  profileBaseUrl?: string;
69
83
  }
70
84
  /**
@@ -86,29 +100,41 @@ export interface ConnectOnDemandOptions {
86
100
  tool: string;
87
101
  /** The resolved tool instance origin the CLI is talking to. */
88
102
  toolBaseUrl: string;
103
+ /** The tool's cloud URL, the same value `selectProfile` got: what a
104
+ * profile with no `baseUrl` of its own is at. Omit only for a tool with
105
+ * no cloud instance. */
106
+ cloudUrl?: string | undefined;
89
107
  /** The exchange resource URL; default = this instance's MCP endpoint,
90
108
  * `${toolBaseUrl}/mcp` (the tool's registered resource URL). */
91
109
  resource?: string;
92
- /** The tool profile the minted key is cached on; default `DEFAULT_PROFILE`. */
93
- profileName?: string;
110
+ /** The tool profile the CLI selected for this run (`selectProfile`), the
111
+ * one the minted key is cached on. Not on disk yet → created with
112
+ * `toolBaseUrl` on first contact; at another instance → the key is
113
+ * returned but never stored. cli-core never guesses it. */
114
+ profileName: string;
94
115
  env: CliEnv;
95
116
  fetch?: typeof globalThis.fetch;
96
117
  /** Receives the human "Connected to …" notice (tools wire their stderr);
97
118
  * omitted = silent. Cache hits are always silent either way. */
98
119
  notify?: (line: string) => void;
99
120
  messages?: ConnectOnDemandMessages;
121
+ /** false = do not read the cache: run the exchange even when a key is
122
+ * cached (the one re-exchange after a 401 on a cached key;
123
+ * `refreshConnectKey` sets it). Default true. */
124
+ cached?: boolean;
100
125
  }
101
126
  export type ConnectOnDemandOutcome = {
102
127
  outcome: 'connected';
103
128
  /** The tool-local key — this invocation's credential. */
104
129
  key: string;
105
- /** true = served from the (tool, hub profile) config cache: zero
106
- * network, nothing minted. false = a fresh exchange ran. */
130
+ /** true = served from the (tool profile, hub profile) config cache:
131
+ * zero network, nothing minted. false = a fresh exchange ran. A 401
132
+ * on a `cached: true` key is what warrants `refreshConnectKey`. */
107
133
  cached: boolean;
108
134
  /** Fresh exchanges only: the full result (user, key meta). */
109
135
  result?: CliConnectResult;
110
136
  /** Fresh exchanges only: whether the minted key was persisted for
111
- * the next run (false = the profile names another instance). */
137
+ * the next run (false = the profile is at another instance). */
112
138
  stored?: boolean;
113
139
  } | {
114
140
  /** Not an Antasphere-cloud instance (or unreachable): the caller
@@ -118,10 +144,24 @@ export type ConnectOnDemandOutcome = {
118
144
  /**
119
145
  * The hub → tool exchange fallback a tool CLI runs when no direct credential
120
146
  * resolved. Serves the cached user-scoped key when one exists for this
121
- * (instance, hub profile); otherwise returns `not_cloud` when the instance
122
- * is not an Antasphere-cloud one (or unreachable). Throws a guided
123
- * `CliUsageError` when the instance IS cloud but the hub login is missing or
124
- * rejected; every other exchange failure propagates as its `CliConnectError`.
147
+ * (instance, hub profile) on the selected profile; otherwise returns
148
+ * `not_cloud` when the instance is not an Antasphere-cloud one (or
149
+ * unreachable). Throws a guided `CliUsageError` when the instance IS cloud
150
+ * but the hub login is missing or rejected; a refusal and every other
151
+ * exchange failure propagate as their `CliConnectError` (`exitCode` says 3
152
+ * for the refusal, `message` is the server's own sentence).
125
153
  */
126
154
  export declare function connectOnDemand(opts: ConnectOnDemandOptions): Promise<ConnectOnDemandOutcome>;
155
+ /**
156
+ * The stranded-key recovery: what a tool CLI calls once when a request
157
+ * answered 401 with a key that `connectOnDemand` served from the cache
158
+ * (`cached: true`). Evicts that key from the selected profile (the hub
159
+ * revoked it, or a membership was swept), only when that profile is at
160
+ * this instance (a key of another instance is never touched), and runs the
161
+ * exchange again with the cache skipped. The caller retries its request
162
+ * once with the new key and fails on a second 401; `not_cloud` means there
163
+ * is nothing to recover with, and the caller fails with its 401 as it
164
+ * stands.
165
+ */
166
+ export declare function refreshConnectKey(opts: ConnectOnDemandOptions): Promise<ConnectOnDemandOutcome>;
127
167
  //# sourceMappingURL=connect-on-demand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connect-on-demand.d.ts","sourceRoot":"","sources":["../src/connect-on-demand.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC;4EACwE;IACxE,KAAK,EAAE,OAAO,CAAC;IACf,gEAAgE;IAChE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,sEAAsE;IACtE,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAClC,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAsBnC;AAED;;;;GAIG;AACH,wB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AiB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAOrG"}
@@ -1,6 +1,6 @@
1
- import { assertToolNamespace, HUB_TOOL, loadConfig, lookupConnectKey, saveConfig, storeConnectKey } from './config.js';
1
+ import { assertToolNamespace, HUB_TOOL, loadConfig, lookupConnectKey, removeConnectKey, storeConnectKey } from './config.js';
2
2
  import { CliConnectClient, CliConnectError } from './connect.js';
3
- import { CliUsageError, DEFAULT_PROFILE, resolveProfile } from './resolve.js';
3
+ import { CliUsageError, firstSet, normalizeUrl, profileUrl, resolveProfile, sameInstance } from './resolve.js';
4
4
  /**
5
5
  * Probe a tool instance's unauthenticated discovery endpoint
6
6
  * (`GET {toolBaseUrl}/api/v1/instance`). Returns what it advertises, or
@@ -51,28 +51,45 @@ function defaultConnected(facts) {
51
51
  : ` — key NOT cached: profile '${facts.profileName}' points at ${facts.profileBaseUrl}`) +
52
52
  '.\n');
53
53
  }
54
+ /**
55
+ * Where the selected profile stands with respect to the resolved instance:
56
+ * `here` (its `baseUrl`, else the tool's cloud URL, is this instance),
57
+ * `elsewhere` (it is at another instance), or `free` (absent, or with no
58
+ * instance at all: no `baseUrl` and no cloud URL known). The cache is read
59
+ * only when `here`; a key is stored unless `elsewhere`; a key is evicted
60
+ * only when `here`.
61
+ */
62
+ function placeOf(existing, toolBaseUrl, cloudUrl) {
63
+ const at = existing ? profileUrl(existing, cloudUrl) : undefined;
64
+ if (!existing || at === undefined)
65
+ return { place: 'free' };
66
+ return sameInstance(at, toolBaseUrl) ? { place: 'here', at } : { place: 'elsewhere', at };
67
+ }
54
68
  /**
55
69
  * The hub → tool exchange fallback a tool CLI runs when no direct credential
56
70
  * resolved. Serves the cached user-scoped key when one exists for this
57
- * (instance, hub profile); otherwise returns `not_cloud` when the instance
58
- * is not an Antasphere-cloud one (or unreachable). Throws a guided
59
- * `CliUsageError` when the instance IS cloud but the hub login is missing or
60
- * rejected; every other exchange failure propagates as its `CliConnectError`.
71
+ * (instance, hub profile) on the selected profile; otherwise returns
72
+ * `not_cloud` when the instance is not an Antasphere-cloud one (or
73
+ * unreachable). Throws a guided `CliUsageError` when the instance IS cloud
74
+ * but the hub login is missing or rejected; a refusal and every other
75
+ * exchange failure propagate as their `CliConnectError` (`exitCode` says 3
76
+ * for the refusal, `message` is the server's own sentence).
61
77
  */
62
78
  export async function connectOnDemand(opts) {
63
79
  assertToolNamespace(opts.tool);
64
- const toolBaseUrl = opts.toolBaseUrl.replace(/\/+$/, '');
80
+ const toolBaseUrl = normalizeUrl(opts.toolBaseUrl);
65
81
  const messages = opts.messages ?? {};
66
- const profileName = opts.profileName ?? DEFAULT_PROFILE;
82
+ const { profileName } = opts;
67
83
  // 0. The cache: a key minted earlier by the active hub profile is
68
84
  // user-scoped — it serves every run and every org (hub ADR 014; the
69
85
  // org is a per-request parameter, never part of the credential). Only
70
- // a profile that names THIS instance is trusted: a cached key never
71
- // travels to a different instance. A hit costs zero network.
86
+ // the selected profile is read, and only when it is at THIS instance:
87
+ // a cached key never travels to a different instance. A hit costs zero
88
+ // network. `cached: false` (the re-exchange after a 401) skips it.
72
89
  const hub = activeHubProfile(opts.env);
73
90
  const existing = loadConfig(opts.env, opts.tool).profiles[profileName];
74
- const pinnedHere = existing?.baseUrl?.replace(/\/+$/, '') === toolBaseUrl;
75
- if (pinnedHere && hub.name) {
91
+ const { place, at } = placeOf(existing, toolBaseUrl, opts.cloudUrl);
92
+ if (opts.cached !== false && place === 'here' && hub.name) {
76
93
  const cachedKey = lookupConnectKey(existing, hub.name);
77
94
  if (cachedKey)
78
95
  return { outcome: 'connected', key: cachedKey, cached: true };
@@ -85,8 +102,9 @@ export async function connectOnDemand(opts) {
85
102
  // 2. The hub credential is what `antasphere login` stored on the hub
86
103
  // profile (HUB_TOOL namespace) — one login for the whole tool family.
87
104
  // The hub URL comes from that same profile, never from a constant here.
88
- const hubKey = hub.profile?.apiKey;
89
- const hubBaseUrl = hub.profile?.baseUrl;
105
+ // A blank field is no field (the package's one blank rule, firstSet).
106
+ const hubKey = firstSet(hub.profile?.apiKey);
107
+ const hubBaseUrl = firstSet(hub.profile?.baseUrl);
90
108
  if (!hubKey || !hubBaseUrl || !hub.name) {
91
109
  throw new CliUsageError(messages.missingHubLogin ?? defaultMissingHubLogin(opts.tool));
92
110
  }
@@ -100,50 +118,69 @@ export async function connectOnDemand(opts) {
100
118
  ...(opts.fetch ? { fetch: opts.fetch } : {})
101
119
  });
102
120
  const body = { resource };
121
+ // One attempt, with the hub's verdict on the KEY mapped to the guided
122
+ // login error whichever attempt it comes on. A refusal (403 that is not
123
+ // the scope case) and every wire error propagate as they are: the error
124
+ // carries the server's own sentence and its exit code.
125
+ const attempt = async () => {
126
+ try {
127
+ return await connect.exchange(hubKey, body);
128
+ }
129
+ catch (e) {
130
+ if (e instanceof CliConnectError && e.needsHubLogin) {
131
+ throw new CliUsageError(messages.hubLoginRejected ?? DEFAULT_HUB_LOGIN_REJECTED);
132
+ }
133
+ throw e;
134
+ }
135
+ };
103
136
  let result;
104
137
  try {
105
- result = await connect.exchange(hubKey, body);
138
+ result = await attempt();
106
139
  }
107
140
  catch (e) {
108
- if (e instanceof CliConnectError && e.needsReExchange) {
109
- // The 120 s JWT died in transit (expired/replayed) — one fresh
110
- // exchange; a second rejection propagates.
111
- result = await connect.exchange(hubKey, body);
112
- }
113
- else if (e instanceof CliConnectError && e.needsHubLogin) {
114
- throw new CliUsageError(messages.hubLoginRejected ?? DEFAULT_HUB_LOGIN_REJECTED);
115
- }
116
- else {
141
+ if (!(e instanceof CliConnectError && e.needsReExchange))
117
142
  throw e;
118
- }
143
+ // The 120 s JWT died in transit (expired/replayed) — one fresh
144
+ // exchange; a second rejection propagates.
145
+ result = await attempt();
119
146
  }
120
- // 4. Cache the minted key per (tool, hub profile) — but only onto a
121
- // profile that names THIS instance (or a fresh one, which gets pinned
122
- // to it), never onto a profile pointing somewhere else.
123
- const stored = !existing?.baseUrl || pinnedHere;
147
+ // 4. Cache the minted key on the SELECTED profile under the hub profile's
148
+ // name. A profile not on disk yet, or one with no instance of its own,
149
+ // takes this instance's URL; a profile at another instance never
150
+ // receives the key and is never repointed.
151
+ const stored = place !== 'elsewhere';
124
152
  if (stored) {
125
- storeConnectKey(opts.env, opts.tool, profileName, hub.name, {
126
- apiKey: result.key,
127
- email: result.user.email,
128
- mintedAt: new Date().toISOString()
129
- });
130
- if (!existing?.baseUrl) {
131
- // First contact: pin the profile to this instance so the next
132
- // invocation resolves the URL and the cached key with no flags.
133
- const cfg = loadConfig(opts.env, opts.tool);
134
- cfg.profiles[profileName] = { ...cfg.profiles[profileName], baseUrl: toolBaseUrl };
135
- saveConfig(opts.env, opts.tool, cfg);
136
- }
153
+ storeConnectKey(opts.env, opts.tool, profileName, hub.name, { apiKey: result.key, email: result.user.email, mintedAt: new Date().toISOString() }, { baseUrl: toolBaseUrl });
137
154
  }
138
155
  const facts = {
139
156
  toolBaseUrl,
140
157
  email: result.user.email,
141
158
  stored,
142
159
  profileName,
143
- // `stored` is false only when the profile names another instance.
144
- ...(stored ? {} : { profileBaseUrl: existing?.baseUrl })
160
+ // `stored` is false only when the profile is at another instance.
161
+ ...(stored ? {} : { profileBaseUrl: at })
145
162
  };
146
163
  opts.notify?.((messages.connected ?? defaultConnected)(facts));
147
164
  return { outcome: 'connected', key: result.key, result, cached: false, stored };
148
165
  }
166
+ /**
167
+ * The stranded-key recovery: what a tool CLI calls once when a request
168
+ * answered 401 with a key that `connectOnDemand` served from the cache
169
+ * (`cached: true`). Evicts that key from the selected profile (the hub
170
+ * revoked it, or a membership was swept), only when that profile is at
171
+ * this instance (a key of another instance is never touched), and runs the
172
+ * exchange again with the cache skipped. The caller retries its request
173
+ * once with the new key and fails on a second 401; `not_cloud` means there
174
+ * is nothing to recover with, and the caller fails with its 401 as it
175
+ * stands.
176
+ */
177
+ export async function refreshConnectKey(opts) {
178
+ assertToolNamespace(opts.tool);
179
+ const hub = activeHubProfile(opts.env);
180
+ const existing = loadConfig(opts.env, opts.tool).profiles[opts.profileName];
181
+ const { place } = placeOf(existing, normalizeUrl(opts.toolBaseUrl), opts.cloudUrl);
182
+ if (hub.name && place === 'here')
183
+ removeConnectKey(opts.env, opts.tool, opts.profileName, hub.name);
184
+ return connectOnDemand({ ...opts, cached: false });
185
+ }
149
186
  //# sourceMappingURL=connect-on-demand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connect-on-demand.js","sourceRoot":"","sources":["../src/connect-on-demand.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,eAAe,EAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA2C9E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,WAAmB,EACnB,SAAmC;IAEnC,MAAM,CAAC,GAAG,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,EAAE;YACxE,MAAM,EAAE,KAAK;YACb,mEAAmE;YACnE,+DAA+D;YAC/D,KAAK,EAAE,UAAU;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACzB,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAGxC,CAAC;QACT,MAAM,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC;QACpC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO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AAE,EAAE,CAAC;KAC1C,CAAC;IACF,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,IAAI,gBAAgB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAE/D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAClF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAA4B;IAClE,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC5E,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnF,IAAI,GAAG,CAAC,IAAI,IAAI,KAAK,KAAK,MAAM;QAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACpG,OAAO,eAAe,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AACrD,CAAC"}
package/dist/connect.d.ts CHANGED
@@ -10,7 +10,9 @@ import { CliAuthError, type CliAuthMintedKey } from './auth.js';
10
10
  * offline grant for live as-the-user hub reads). Both are OPAQUE to
11
11
  * this client: relayed hub → tool, never inspected or stored. The
12
12
  * exchange names NO organization (hub ADR 014): the credential
13
- * identifies the user; any org is a per-request selection tool-side.
13
+ * identifies the user; the organization is a per-request parameter
14
+ * tool-side, the hub's server-side default unless `--org` says
15
+ * otherwise.
14
16
  * 2. POST {tool}/api/v1/sso/cli-connect — NO auth header (the JWT is
15
17
  * the credential), body `{ token, hubRefreshToken }` → the tool
16
18
  * verifies, JIT-provisions, stores the grant, and mints an ordinary
@@ -19,9 +21,10 @@ import { CliAuthError, type CliAuthMintedKey } from './auth.js';
19
21
  * The hub key is sent to the HUB only — it never reaches the tool. The
20
22
  * hubRefreshToken is sent to the TOOL only (it is that tool's own grant;
21
23
  * redeeming it needs the tool client's credentials) and never persisted by
22
- * the CLI. The minted key is cached per (tool, hub profile) in the tool's
23
- * config namespace (config.ts `connectKeys`); day-to-day tool CLI calls
24
- * then take the ordinary local API-key path with the hub out of the loop.
24
+ * the CLI. The minted key is cached per (tool profile, hub profile) in the
25
+ * tool's config namespace (config.ts `connectKeys`), on the profile of the
26
+ * instance it was minted for; day-to-day tool CLI calls then take the
27
+ * ordinary local API-key path with the hub out of the loop.
25
28
  */
26
29
  export type CliConnectStage = 'hub' | 'tool';
27
30
  /**
@@ -31,6 +34,8 @@ export type CliConnectStage = 'hub' | 'tool';
31
34
  * - hub 400 `unknown_resource` — the resource URL is not in the registry.
32
35
  * - `needsHubLogin` — the hub rejected the KEY itself; re-run
33
36
  * `antasphere login`.
37
+ * - `refusal` — the account was refused (403), not the key: print the
38
+ * server's own sentence and exit 3. No login fixes it.
34
39
  * - `needsReExchange` — the tool rejected the 120 s JWT (expired/replayed
35
40
  * in transit); run the exchange again.
36
41
  * - tool 429 `rate_limited` — back off and retry.
@@ -46,6 +51,16 @@ export declare class CliConnectError extends CliAuthError {
46
51
  get needsHubLogin(): boolean;
47
52
  /** The tool rejected the JWT (expired/replayed) — run the exchange again. */
48
53
  get needsReExchange(): boolean;
54
+ /**
55
+ * The person was refused, not the credential: a 403 that is not the
56
+ * scope case, from either side (`tool_access_denied` on a restricted
57
+ * tool, `unverified_email`, a grant the tool will not take). `message`
58
+ * is the server's own sentence; a runner prints it as is and exits
59
+ * `exitCode`, 3, the code the tool docs promise for a refusal.
60
+ */
61
+ get refusal(): boolean;
62
+ /** The exit code a runner uses for this error: 3 for a refusal, 1 otherwise. */
63
+ get exitCode(): number;
49
64
  }
50
65
  export interface CliToolTokenBody {
51
66
  /** The tool's registry resource URL (e.g. `https://app.slideless.ai/mcp`).
@@ -81,7 +96,7 @@ export interface CliConnected {
81
96
  }
82
97
  /** The flattened outcome of a full exchange. */
83
98
  export interface CliConnectResult {
84
- /** Full tool-local key — user-scoped: ONE per (tool, hub profile),
99
+ /** Full tool-local key — user-scoped: ONE per (tool profile, hub profile),
85
100
  * valid for every org the user can select per request (config.ts). */
86
101
  key: string;
87
102
  apiKey: CliAuthMintedKey;
@@ -106,7 +121,7 @@ export declare class CliConnectClient {
106
121
  private readonly toolBaseUrl;
107
122
  private readonly fetchImpl;
108
123
  constructor(options: CliConnectClientOptions);
109
- /** Step 1 — the hub mints the 120 s single-org JWT for the tool's resource. */
124
+ /** Step 1 — the hub mints the 120 s user-scoped JWT for the tool's resource. */
110
125
  toolToken(hubApiKey: string, body: CliToolTokenBody): Promise<CliToolTokenMinted>;
111
126
  /**
112
127
  * Step 2 — the tool verifies the JWT (its only credential) and mints its
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,qBAAa,eAAgB,SAAQ,YAAY;aAE7B,KAAK,EAAE,eAAe;gBAAtB,KAAK,EAAE,eAAe,EACtC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,OAAO;IAM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AK,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAO1E;gFAC4E;IACtE,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAWpF,wFAAwF;YAC1E,IAAI;CAkBnB"}
package/dist/connect.js CHANGED
@@ -6,6 +6,8 @@ import { CliAuthError } from './auth.js';
6
6
  * - hub 400 `unknown_resource` — the resource URL is not in the registry.
7
7
  * - `needsHubLogin` — the hub rejected the KEY itself; re-run
8
8
  * `antasphere login`.
9
+ * - `refusal` — the account was refused (403), not the key: print the
10
+ * server's own sentence and exit 3. No login fixes it.
9
11
  * - `needsReExchange` — the tool rejected the 120 s JWT (expired/replayed
10
12
  * in transit); run the exchange again.
11
13
  * - tool 429 `rate_limited` — back off and retry.
@@ -30,6 +32,20 @@ export class CliConnectError extends CliAuthError {
30
32
  get needsReExchange() {
31
33
  return this.stage === 'tool' && this.status === 401;
32
34
  }
35
+ /**
36
+ * The person was refused, not the credential: a 403 that is not the
37
+ * scope case, from either side (`tool_access_denied` on a restricted
38
+ * tool, `unverified_email`, a grant the tool will not take). `message`
39
+ * is the server's own sentence; a runner prints it as is and exits
40
+ * `exitCode`, 3, the code the tool docs promise for a refusal.
41
+ */
42
+ get refusal() {
43
+ return this.status === 403 && !this.needsHubLogin;
44
+ }
45
+ /** The exit code a runner uses for this error: 3 for a refusal, 1 otherwise. */
46
+ get exitCode() {
47
+ return this.refusal ? 3 : 1;
48
+ }
33
49
  }
34
50
  export class CliConnectClient {
35
51
  hubBaseUrl;
@@ -40,7 +56,7 @@ export class CliConnectClient {
40
56
  this.toolBaseUrl = options.toolBaseUrl.replace(/\/+$/, '');
41
57
  this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
42
58
  }
43
- /** Step 1 — the hub mints the 120 s single-org JWT for the tool's resource. */
59
+ /** Step 1 — the hub mints the 120 s user-scoped JWT for the tool's resource. */
44
60
  toolToken(hubApiKey, body) {
45
61
  return this.call('hub', `${this.hubBaseUrl}/api/v1/sso/tool-token`, body, hubApiKey);
46
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,WAAW,CAAC;AA6BhE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAE7B;IADlB,YACkB,KAAsB,EACtC,MAAc,EACd,IAAY,EACZ,OAAe,EACf,OAAiB;QAEjB,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QANtB,UAAK,GAAL,KAAK,CAAiB;QAOtC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,IAAI,aAAa;QACf,OAAO,CACL,IAAI,CAAC,KAAK,KAAK,KAAK;YACpB,CAAC,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,IAAI,KAAK,oBAAoB,CAAC,CAAC,CACrF,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC;IACtD,CAAC;CACF;AAqDD,MAAM,OAAO,gBAAgB;IACV,UAAU,CAAS;IACnB,WAAW,CAAS;IACpB,SAAS,CAA0B;IAEpD,YAAY,OAAgC;QAC1C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,GAAG,O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,MAAM,EACV,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,eAAe,EACtC,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,uBAAuB,GAAG,CAAC,MAAM,EAAE,EAC7D,OAAO,CAAC,KAAK,EAAE,OAAO,CACvB,CAAC;QACJ,CAAC;QACD,OAAO,IAAS,CAAC;IACnB,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,29 +1,31 @@
1
1
  /**
2
2
  * @antasphere/cli-core — the shared foundation every Antasphere tool CLI
3
3
  * builds on (hub-architecture §8): the `~/.config/antasphere/` config home
4
- * with tool-namespaced profiles, the flag → env → profile → default URL
5
- * resolution order, the instance email-OTP auth client, the hub→tool
6
- * cross-tool connect exchange (+ its per-(tool, hub profile) user-scoped
7
- * key cache, the hub-profile org context, and the connect-on-demand seam a
8
- * tool CLI runs when no direct credential resolved), and the CliIo prompt
9
- * seam. Tool
4
+ * with tool-namespaced profiles where A PROFILE IS AN INSTANCE (named for
5
+ * its host, the implicit `cloud` profile at the tool's cloud URL), the
6
+ * profile selection rule (--profile → instance URL → active → cloud), the
7
+ * flag → env → profile → cloud URL resolution order, the per-command
8
+ * organization override (`resolveOrg`; the hub's server-side default
9
+ * organization applies otherwise), the instance email-OTP auth client, the
10
+ * hub→tool cross-tool connect exchange (user-scoped, no org in the
11
+ * exchange) with its per-(tool profile, hub profile) key cache, the
12
+ * connect-on-demand seam a tool CLI runs when no direct credential
13
+ * resolved, the stranded-key recovery, and the CliIo prompt seam. Tool
10
14
  * commands, wire types, and API surfaces live in the tools; this package
11
15
  * carries only config/login plumbing, never secrets.
12
16
  */
13
- export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
14
- export type { CliConfig, CliConnectKey, CliEnv, CliProfile } from './config.js';
17
+ export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, profileCredential, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
18
+ export type { CliConfig, CliConnectKey, CliEnv, CliProfile, ProfileCredential, StoreConnectKeyOptions } from './config.js';
15
19
  export { ask, printJson } from './io.js';
16
20
  export type { CliIo } from './io.js';
17
- export { CliUsageError, DEFAULT_PROFILE, resolveApiKey, resolveBaseUrl, resolveProfile } from './resolve.js';
18
- export type { ResolveApiKeyOptions, ResolveBaseUrlOptions, ResolvedProfile } from './resolve.js';
21
+ export { CLOUD_PROFILE, CliUsageError, firstSet, normalizeUrl, profileNameFor, profileUrl, resolveApiKey, resolveBaseUrl, resolveOrg, resolveProfile, sameInstance, selectProfile } from './resolve.js';
22
+ export type { ProfileSource, ResolveApiKeyOptions, ResolveBaseUrlOptions, ResolveOrgOptions, ResolvedProfile, SelectProfileOptions, SelectedProfile } from './resolve.js';
19
23
  export { CliAuthClient, CliAuthError } from './auth.js';
20
24
  export type { CliAuthClientOptions, CliAuthCompleteBody, CliAuthCompleted, CliAuthMintedKey, CliAuthRequestBody, CliAuthRequested, CliAuthRevoked } from './auth.js';
21
25
  export { CliConnectClient, CliConnectError } from './connect.js';
22
26
  export type { CliConnectClientOptions, CliConnected, CliConnectResult, CliConnectStage, CliToolTokenBody, CliToolTokenMinted } from './connect.js';
23
- export { activeHubProfile, connectOnDemand, probeToolInstance } from './connect-on-demand.js';
27
+ export { activeHubProfile, connectOnDemand, probeToolInstance, refreshConnectKey } from './connect-on-demand.js';
24
28
  export type { ConnectNoticeFacts, ConnectOnDemandMessages, ConnectOnDemandOptions, ConnectOnDemandOutcome, ToolInstanceProbe } from './connect-on-demand.js';
25
- export { getActiveWorkspace, resolveTargetWorkspace, setActiveWorkspace } from './org.js';
26
- export type { OrgContextOptions, ResolveTargetWorkspaceOptions } from './org.js';
27
29
  export { migrateLegacyConfig } from './migrate.js';
28
30
  export type { LegacyMigrationSpec, MigrationResult } from './migrate.js';
29
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3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B,EAAE,MAAM,UAAU,CAAC;AAC1F,YAAY,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAEjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,SAAS,EACT,aAAa,EACb,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EACL,aAAa,EACb,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EACV,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,21 +1,24 @@
1
1
  /**
2
2
  * @antasphere/cli-core — the shared foundation every Antasphere tool CLI
3
3
  * builds on (hub-architecture §8): the `~/.config/antasphere/` config home
4
- * with tool-namespaced profiles, the flag → env → profile → default URL
5
- * resolution order, the instance email-OTP auth client, the hub→tool
6
- * cross-tool connect exchange (+ its per-(tool, hub profile) user-scoped
7
- * key cache, the hub-profile org context, and the connect-on-demand seam a
8
- * tool CLI runs when no direct credential resolved), and the CliIo prompt
9
- * seam. Tool
4
+ * with tool-namespaced profiles where A PROFILE IS AN INSTANCE (named for
5
+ * its host, the implicit `cloud` profile at the tool's cloud URL), the
6
+ * profile selection rule (--profile → instance URL → active → cloud), the
7
+ * flag → env → profile → cloud URL resolution order, the per-command
8
+ * organization override (`resolveOrg`; the hub's server-side default
9
+ * organization applies otherwise), the instance email-OTP auth client, the
10
+ * hub→tool cross-tool connect exchange (user-scoped, no org in the
11
+ * exchange) with its per-(tool profile, hub profile) key cache, the
12
+ * connect-on-demand seam a tool CLI runs when no direct credential
13
+ * resolved, the stranded-key recovery, and the CliIo prompt seam. Tool
10
14
  * commands, wire types, and API surfaces live in the tools; this package
11
15
  * carries only config/login plumbing, never secrets.
12
16
  */
13
- export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
17
+ export { assertToolNamespace, clearConfig, configPath, HUB_TOOL, loadConfig, lookupConnectKey, parseConfig, profileCredential, redactKey, removeConnectKey, saveConfig, storeConnectKey } from './config.js';
14
18
  export { ask, printJson } from './io.js';
15
- export { CliUsageError, DEFAULT_PROFILE, resolveApiKey, resolveBaseUrl, resolveProfile } from './resolve.js';
19
+ export { CLOUD_PROFILE, CliUsageError, firstSet, normalizeUrl, profileNameFor, profileUrl, resolveApiKey, resolveBaseUrl, resolveOrg, resolveProfile, sameInstance, selectProfile } from './resolve.js';
16
20
  export { CliAuthClient, CliAuthError } from './auth.js';
17
21
  export { CliConnectClient, CliConnectError } from './connect.js';
18
- export { activeHubProfile, connectOnDemand, probeToolInstance } from './connect-on-demand.js';
19
- export { getActiveWorkspace, resolveTargetWorkspace, setActiveWorkspace } from './org.js';
22
+ export { activeHubProfile, connectOnDemand, probeToolInstance, refreshConnectKey } from './connect-on-demand.js';
20
23
  export { migrateLegacyConfig } from './migrate.js';
21
24
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,eAAe,EAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG7G,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC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